!function(e,t){"use strict";var o;if("undefined"==typeof window.parent)return;let r=window.parent,n="",i=!1;o={init:function(){t=t||window.elementorFrontend,i||(i=!0,r.addEventListener("metformPickerConfirm",function(t){console.log(" Event received:",t.detail);var o=t.detail&&t.detail.formId,i=t.detail&&t.detail.mode,m=t.detail&&t.detail.widgetId;if("select"===i){if(!o||!m)return;const t=e(`.elementor-element[data-id="${m}"]`);if(0===t.length)return;if(console.log("Save & Return - applying form",o,"to widget",m),t.find(".formpicker_warper, .formpicker_warper_edit").attr("data-metform-formpicker-key",o),t.attr("data-metform-formpicker-key",o),r.jQuery("body").attr("data-metform-template-key",o),r.elementor&&r.elementor.getContainer)try{const e=r.elementor.getContainer(m);if(e&&e.model){e.model.get("settings").set("mf_form_id",o),e.model.trigger("change"),r.elementor.saver&&r.elementor.saver.setFlagEditorChange(!0),e&&e.render?e.render():r.elementor.reloadPreview(),console.log(" Model updated and change marked")}}catch(d){console.error("Model update failed:",d)}return}o&&function(e){var t=r.jQuery(".metform-dynamic-content-modal"),o=t.find("#formpicker-control-iframe"),i=t.find(".dialog-lightbox-loading"),m=t.find(".dialog-type-lightbox"),d=n+"metform/v1/forms/builder/"+e;r.jQuery("body").attr("data-metform-template-key",e),r.jQuery("body").attr("data-metform-template-load","false"),m.show(),t.show(),i.show(),o.contents().find("#elementor-loading").show(),o.css("z-index","-1"),o.attr("src",d),o.on("load",function(){i.hide(),o.show(),o.contents().find("#elementor-loading").hide(),o.css("z-index","1")})}(o)})),t.hooks.addAction("frontend/element_ready/metform.default",function(o){function i(e){e.jQuery("body").attr("data-metform-template-load","true"),e.jQuery(".metform-dynamic-content-modal").hide(),e.jQuery("#metform-open-content-editor").hide()}t.isEditMode()&&(o.find(".formpicker_warper_edit").off("click.metform").on("click.metform",function(){var t=e(this),i=t.attr("data-metform-formpicker-key")||"",m=t.attr("data-nonce"),d=t.attr("resturl");n=d.replace(/metform\/v1\/forms\/templates\/?$/,"");t.closest(".elementor-element");var a=o.data("id");console.log("✅ Correct Widget ID:",a),"undefined"!=typeof r.metformFormPicker&&r.metformFormPicker.open({currentFormId:i,nonce:m,restUrl:n,widgetId:a})}),r.jQuery("#elementor-editor-wrapper").on("click","#metform-inspactor-edit-button",function(){}),"undefined"!=typeof r.jQuery&&r.jQuery(".metform-close-editor-modals").off("click.metform").on("click.metform",function(){if(e(this).hasClass("metform-editor-close")){var t=r.jQuery(".metform-dynamic-content-modal").find("#formpicker-control-iframe"),o=t[0].contentWindow||t[0].contentDocument;o.jQuery("#elementor-panel-saver-button-publish").hasClass("elementor-disabled")?i(r):confirm("Leaving? Changes you made may not be saved.")?(o.jQuery(o).off("beforeunload"),i(r)):o.jQuery(o).off("beforeunload")}else i(r)}),r.jQuery(".metform-form-update-close-btn").off("click.metform").on("click.metform",function(){var e,t=r.jQuery(".metform-dynamic-content-modal").find("#formpicker-control-iframe"),o=t[0].contentWindow||t[0].contentDocument;o.jQuery("#elementor-panel-saver-button-publish:not([disabled])").hasClass("elementor-disabled")?r.jQuery(".metform-close-editor-modals").trigger("click.metform"):(o.jQuery("#elementor-panel-saver-button-publish:not([disabled])").trigger("click"),e=setInterval(function(){o.jQuery("#elementor-panel-saver-button-publish:not([disabled])").hasClass("elementor-disabled")&&(r.jQuery(".metform-close-editor-modals").trigger("click.metform"),clearInterval(e))},100))}))})}},e(window).on("elementor/frontend/init",o.init)}(jQuery,window.elementorFrontend);