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