!function(e){function t(t){e.each(t,(function(t,a){var n=e(a);0===n.data("index")&&(n.prop("disabled",0),n.hasClass("ff_el-chained-select-smart-search")&&(a.choices=new Choices(a)))}))}function a(t){var a=e(this),r=n(a);if(r){if(a.val())return function(t,a){var r,c,s={params:i(t),name:t.attr("data-name"),type:null!==(r=t.attr("data-source-type"))&&void 0!==r?r:"url",url:null!==(c=t.attr("data-source-url"))&&void 0!==c?c:"",meta_key:t.attr("data-meta_key"),target_field:a.attr("data-key"),form_id:t.closest("form").attr("data-form_id"),action:"fluentform_get_chained_select_options"};a.html("<option>Loading...</option>"),e.getJSON(fluentFormVars.ajaxUrl,s).then((function(t){o(a,0),function(t,a){var n,i=a.hasClass("ff_el-chained-select-smart-search");i&&(n=new Choices(a[0]),a[0].choices=n);var o=[];e.each(t.data,(function(t,n){i?o.push({value:n,label:n}):a.append(e("<option />",{value:n,text:n}))})),i&&n.setChoices(o)}(t,a),(a=n(a))&&o(a,1).trigger("change")}))}(a,r);o(r,1).trigger("change")}}function n(e){var t=e.data("index")+1,a=e.closest(".ff-chained-select-field-wrapper").find("select[data-index='"+t+"']");return a.length?a:void 0}function i(e){var t,a,n,i=[{value:e.val(),key:e.attr("data-key")}];if(e.attr("data-index"))for(;$previousElement=(a=void 0,n=void 0,a=(t=e).data("index")-1,(n=t.closest(".ff-chained-select-field-wrapper").find("select[data-index='"+a+"']")).length?n:void 0);)e=$previousElement,i.push({value:e.val(),key:e.attr("data-key")});return i}function o(t,a){if(t)return t.hasClass("ff_el-chained-select-smart-search")&&t[0].choices&&t[0].choices.destroy(),t.empty().prop("disabled",a).append(e("<option />",{value:"",text:t.attr("data-key")}))}var r=function(){e.each(e(".frm-fluent-form"),(function(n,i){var o=e(i).find("select.el-chained-select");o.on("change",a),t(o),e(document).on("reInitExtras","#formId",(function(){o.on("change",a),t(o)}))}))};setTimeout((function(){e(".frm-fluent-form")&&r()}),100),e(document).on("elementor/popup/show",(function(){r()}))}(jQuery);