/*! For license information please see trigger.a8d3dd9a742461b1210a.js.LICENSE.txt */
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Airflow=t():(e.Airflow=e.Airflow||{},e.Airflow.trigger=t())}(self,(()=>(()=>{let e;const t=new Map,n=document.getElementById("recent_configs");function l(){const n=document.getElementById("json_start").value,l=JSON.parse(n),a=document.getElementById("trigger_form");for(let e=0;e<a.length;e+=1)if(a[e].name&&a[e].name.startsWith("element_")){const n=a[e].name.substr(8);if("checkbox"===a[e].type)l[n]=a[e].checked;else if(a[e].attributes.valuetype&&"array"===a[e].attributes.valuetype.value){const t=a[e].value.split("\n"),r=[];for(let e=0;e<t.length;e+=1)t[e].trim().length>0&&(r[r.length]=t[e].trim());l[n]=0===r.length?null:r}else if(a[e].attributes.valuetype&&"multiselect"===a[e].attributes.valuetype.value){const{options:t}=a[e],r=[];for(let e=0;e<t.length;e+=1)t[e].selected&&(r[r.length]=t[e].value);l[n]=0===r.length?null:r}else if(0===a[e].value.length)l[n]=null;else if(!a[e].attributes.valuetype||"object"!==a[e].attributes.valuetype.value&&"advancedarray"!==a[e].attributes.valuetype.value)Number.isNaN(a[e].value)?l[n]=a[e].value:a[e].attributes.valuetype&&"number"===a[e].attributes.valuetype.value?l[n]=Number(a[e].value):l[n]=a[e].value;else try{const r=t.get(a[e].name).getValue();if(r.length>0){const o=JSON.parse(r);l[n]=o,t.get(a[e].name).setValue(JSON.stringify(o,null,4))}else l[n]=null}catch(e){}}e.setValue(JSON.stringify(l,null,4))}return $(document).ready((()=>{!function(){const n=document.getElementById("form_sections"),a=null!=n,r=(a?window.innerHeight/2:window.innerHeight)-550,o=r>300?r:300;if(e=CodeMirror.fromTextArea(document.getElementById("json"),{lineNumbers:!0,mode:{name:"javascript",json:!0},gutters:["CodeMirror-lint-markers"],lint:!0,indentUnit:4}),e.setSize(null,o),a){const a=document.getElementById("trigger_form");for(let e=0;e<a.length;e+=1)if(a[e].name&&a[e].name.startsWith("element_"))if(!a[e].attributes.valuetype||"object"!==a[e].attributes.valuetype.value&&"advancedarray"!==a[e].attributes.valuetype.value)if("SELECT"===a[e].nodeName){const t=`#${a[e].name}`;$(t).select2({placeholder:"Select Values",allowClear:!0}),a[e].addEventListener("blur",l)}else"checkbox"===a[e].type?a[e].addEventListener("change",l):a[e].addEventListener("blur",l);else{const n=CodeMirror.fromTextArea(a[e],{lineNumbers:!0,mode:{name:"javascript",json:!0},gutters:["CodeMirror-lint-markers"],lint:!0,indentUnit:4});n.on("blur",l),t.set(a[e].name,n)}const r=n.value.split(",");for(let e=0;e<r.length;e+=1){const n=document.getElementById(`${r[e]}_toggle`);n&&n.addEventListener("click",(()=>{setTimeout((()=>{t.forEach((e=>{e.refresh()}))}),300)}))}a.addEventListener("submit",(e=>{l(),t.forEach((t=>{const n=t.getValue();try{n.trim().length>0&&JSON.parse(n)}catch(l){window.alert(`Invalid JSON entered, please correct:\n\n${n}`),t.focus(),e.preventDefault()}}))})),document.getElementById("generated_json_toggle").addEventListener("click",(()=>{setTimeout((()=>{e.refresh()}),300)})),setTimeout(l,100)}}()})),window.updateJSONconf=l,n&&n.addEventListener("change",(function(n){const l=n.target.value;let a,r;try{a=JSON.parse(l),r=JSON.stringify(a,null,4)}catch(e){console.error(`config is not valid JSON format: ${l}`)}const o=Object.keys(a);for(let e=0;e<o.length;e+=1){const n=document.getElementById(`element_${o[e]}`);if(n){const l=a[o[e]];"checkbox"===n.type?n.checked=l:""===l||null==l?n.value="":n.attributes.valuetype&&"array"===n.attributes.valuetype.value?n.value=l.join("\n"):!n.attributes.valuetype||"object"!==n.attributes.valuetype.value&&"advancedarray"!==n.attributes.valuetype.value?"SELECT"===n.nodeName?$(`#${n.name}`).select2("val",[l]):n.value=l:t.get(`element_${o[e]}`).setValue(JSON.stringify(l,null,4))}}e.setValue(r)})),{}})()));