!function(t){"use strict";function e(){t("#bdthemes-templates-builder-modal").show()}function a(){t("#bdthemes-templates-builder-modal form")[0].reset(),t("#bdthemes-templates-builder-modal form .template_id").val("")}function o(e){t("#bdthemes-templates-builder-modal form .bdt-modal-submit-btn").val(e)}function i(e){t(".input-error").removeClass("input-error")}function n(e){var a=e.val();if(t(".bdt-ultimate-store-kit-promotion").remove(),["product|cart","product|checkout","product|myaccount","product|thankyou"].includes(a)){var o=a.split("|")[1];({cart:"Cart Page",checkout:"Checkout Page",myaccount:"My Account Page",thankyou:"Thank You Page"})[o]||(o.charAt(0).toUpperCase(),o.slice(1));t("body").append('
'),t("#bdt-popup-close, #bdt-ultimate-store-kit-popup").on("click",(function(e){e.target===this&&t("#bdt-ultimate-store-kit-popup").remove()})),t(document).on("keyup.ultimateStoreKitPopup",(function(e){27===e.keyCode&&(t("#bdt-ultimate-store-kit-popup").remove(),t(document).off("keyup.ultimateStoreKitPopup"))})),e.val("")}else t("#template_name").prop("disabled",!1),t(".bdt-modal-submit-btn").prop("disabled",!1),""===t(".template_id").val()&&(t("#template_name").val(""),t(".bdt-modal-submit-btn").val("Create Template"))}t(document).on("click","#bdthemes-templates-builder-modal .bdt-modal-close-button",(function(e){t("#bdthemes-templates-builder-modal").hide()})),t(document).on("click","body.post-type-bdt-template-builder a.page-title-action",(function(t){t.preventDefault(),a(),o("Create Template"),e()})),t(document).on("submit","#bdthemes-templates-builder-modal form",(function(e){e.preventDefault();var a=t(this).serialize();i(),t.ajax({url:ajaxurl,dataType:"json",method:"post",cache:!1,data:{action:"bdthemes_builder_create_template",data:a},success:function(t){window.location.href=t.data.redirect},error:function(e){422==e.status&&t.each(e.responseJSON.data.errors_arr,(function(e,a){t("#bdthemes-templates-builder-modal #"+e).addClass("input-error")}))}})})),t(document).on("click","body.post-type-bdt-template-builder .row-actions .bdt-edit-action a",(function(n){n.preventDefault(),i(),a(),o("Update Template");var d=t(this).parents(".column-title");t.ajax({url:ajaxurl,dataType:"json",method:"post",data:{action:"bdthemes_builder_get_edit_template",template_id:t(this).data("id"),nonce:window.ElementPackConfigBuilder.nonce},success:function(a){a.success&&(t("#bdthemes-templates-builder-modal form .template_id").val(a.data.id).change(),t("#bdthemes-templates-builder-modal form #template_name").val(a.data.name).change(),t("#bdthemes-templates-builder-modal form #template_type").val(a.data.type).change(),t("#bdthemes-templates-builder-modal form #template_status").val(a.data.status).change(),"themes|header"!==a.data.type&&"themes|footer"!==a.data.type||(t(".bdt-header-footer-option-container").show(),t(".bdt-template-modalinput-condition_a").val(a.data.condition_a).change(),t(".bdt-template-modalinput-condition_singular").val(a.data.condition_singular).change())),d.find(".hidden").attr("id").split("_")[1];var o=t(".bdt-template-modalinput-condition_singular_id");t.ajax({url:window.ElementPackConfigBuilder.resturl+"get-singular-list",dataType:"json",data:{ids:String(a.data.condition_singular_id)||""}}).then((function(e){null!==e&&e.results.length>0&&(o.html(" "),t.each(e.results,(function(t,e){var a=new Option(e.text,e.id,!0,!0);o.append(a).trigger("change")})))})),e()},error:function(t){}})})),t(document).ready((function(){t("#bdthemes-templates-builder-modal form #template_type").on("change",(function(){"themes|header"===t(this).val()||"themes|footer"===t(this).val()?t(".bdt-header-footer-option-container").show():t(".bdt-header-footer-option-container").hide(),n(t(this))})),t(".bdt-template-modalinput-condition_singular_id").select2({ajax:{url:window.ElementPackConfigBuilder.resturl+"get-singular-list",dataType:"json",data:function(t){return{s:t.term}}},cache:!0,placeholder:"--",dropdownParent:t(".bdt-template-modalinput-condition_singular-container")}),t(document).on("change",".bdt-template-modalinput-condition_a",(function(e){var a=t(this).val(),o=t(".bdt-template-modalinput-condition_singular-container");"singular"===a?o.show():o.hide()})),t(".bdt-template-modalinput-condition_singular").on("change",(function(){var e=t(this).val(),a=t(".bdt-template-modalinput-condition_singular_id-container");"selective"===e?a.show():a.hide()}))}))}(jQuery);