/*! For license information please see trigger.eb1025d99b22ab7f9095.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,(()=>(()=>{var e,t=new Map,n=document.getElementById("recent_configs");function r(){for(var n=document.getElementById("json_start").value,r=JSON.parse(n),a=document.getElementById("trigger_form"),l=0;l<a.length;l+=1)if(a[l].name&&a[l].name.startsWith("element_")){var i=a[l].name.substr(8);if("checkbox"===a[l].type)r[i]=a[l].checked;else if(a[l].attributes.valuetype&&"array"===a[l].attributes.valuetype.value){for(var o=a[l].value.split("\n"),u=[],s=0;s<o.length;s+=1)o[s].trim().length>0&&(u[u.length]=o[s].trim());r[i]=0===u.length?r[i]:u}else if(0===a[l].value.length)r[i]=null;else if(a[l].attributes.valuetype&&"object"===a[l].attributes.valuetype.value)try{var c=t.get(a[l].name).getValue();if(c.length>0){var f=JSON.parse(c);r[i]=f,t.get(a[l].name).setValue(JSON.stringify(f,null,4))}else r[i]=null}catch(e){}else Number.isNaN(a[l].value)?r[i]=a[l].value:a[l].attributes.valuetype&&"number"===a[l].attributes.valuetype.value?r[i]=Number(a[l].value):r[i]=a[l].value}e.setValue(JSON.stringify(r,null,4))}return function(){var n=document.getElementById("form_sections"),a=null!=n,l=(a?window.innerHeight/2:window.innerHeight)-550,i=l>300?l:300;if((e=CodeMirror.fromTextArea(document.getElementById("json"),{lineNumbers:!0,mode:{name:"javascript",json:!0},gutters:["CodeMirror-lint-markers"],lint:!0})).setSize(null,i),a){for(var o=document.getElementById("trigger_form"),u=0;u<o.length;u+=1)if(o[u].name&&o[u].name.startsWith("element_"))if(o[u].attributes.valuetype&&"object"===o[u].attributes.valuetype.value){var s=CodeMirror.fromTextArea(o[u],{lineNumbers:!0,mode:{name:"javascript",json:!0},gutters:["CodeMirror-lint-markers"],lint:!0});s.on("blur",r),t.set(o[u].name,s)}else"checkbox"===o[u].type?o[u].addEventListener("change",r):o[u].addEventListener("blur",r);for(var c=n.value.split(","),f=0;f<c.length;f+=1){var m=document.getElementById("".concat(c[f],"_toggle"));m&&m.addEventListener("click",(function(){setTimeout((function(){t.forEach((function(e){e.refresh()}))}),300)}))}o.addEventListener("submit",(function(e){r(),t.forEach((function(t){var n=t.getValue();try{n.trim().length>0&&JSON.parse(n)}catch(r){window.alert("Invalid JSON entered, please correct:\n\n".concat(n)),t.focus(),e.preventDefault()}}))})),document.getElementById("generated_json_toggle").addEventListener("click",(function(){setTimeout((function(){e.refresh()}),300)})),setTimeout(r,100)}}(),window.updateJSONconf=r,n&&n.addEventListener("change",(function(n){var r,a,l=n.target.value;try{r=JSON.parse(l),a=JSON.stringify(r,null,4)}catch(e){console.error("config is not valid JSON format: ".concat(l))}for(var i=Object.keys(r),o=0;o<i.length;o+=1){var u=document.getElementById("element_".concat(i[o]));if(u){var s=r[i[o]];"checkbox"===u.type?u.checked=s:""===s||null==s?u.value="":u.attributes.valuetype&&"array"===u.attributes.valuetype.value?u.value=s.join("\n"):u.attributes.valuetype&&"object"===u.attributes.valuetype.value?t.get("element_".concat(i[o])).setValue(JSON.stringify(s,null,4)):u.value=s}}e.setValue(a)})),{}})()));