!function(t){"use strict";var __=wp.i18n.__;function e(){t("#ultimate-builder-kit-builder-modal").show()}function a(){t("#ultimate-builder-kit-builder-modal form")[0].reset(),t("#ultimate-builder-kit-builder-modal form .template_id").val(""),l(1)}function i(e){t("#ultimate-builder-kit-builder-modal form .usk-modal-submit-btn").val(e)}function u(e){t(".input-error").removeClass("input-error")}function l(e){var a="1"===String(e),i=t("#ultimate-builder-kit-builder-modal"),u=i.find("#usk_template_status_switcher");i.find("#usk_template_status").val(a?"1":"0"),a?u.addClass("usk-active"):u.removeClass("usk-active"),u.attr("aria-checked",a?"true":"false"),i.find(".usk-switcher-status-text").text(__(a?"Active":"Inactive","ultimate-store-kit"))}t(document).on("click","#ultimate-builder-kit-builder-modal .usk-modal-close-button",function(e){t("#ultimate-builder-kit-builder-modal").hide()}),t(document).on("click","body.post-type-usk-template-builder a.page-title-action",function(t){t.preventDefault(),a(),i(__("Create Template","ultimate-store-kit")),e()}),t(document).on("submit","#ultimate-builder-kit-builder-modal form",function(e){e.preventDefault();var a=t(this).serialize();u(),t.ajax({url:ajaxurl,dataType:"json",method:"post",cache:!1,data:{action:"ultimate_store_kit_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("#ultimate-builder-kit-builder-modal #"+e).addClass("input-error")})}})}),t(document).on("click","body.post-type-usk-template-builder .row-actions .usk-edit-action a",function(r){r.preventDefault(),u(),a(),i(__("Update Template","ultimate-store-kit")),t.ajax({url:ajaxurl,dataType:"json",method:"post",data:{action:"ultimate_store_kit_builder_get_edit_template",template_id:t(this).data("id"),nonce:UltimateStoreKitConfigBuilder.nonce},success:function(a){a.success&&(t("#ultimate-builder-kit-builder-modal form .template_id").val(a.data.id).change(),t("#ultimate-builder-kit-builder-modal form #template_name").val(a.data.name).change(),t("#ultimate-builder-kit-builder-modal form #template_type").val(a.data.type).change(),l(a.data.status)),e()},error:function(t){console.log(t),422!=t.status&&403!=t.status||alert(__("Permission denied or invalid request","ultimate-store-kit"))}})}),t(document).ready(function(){t("#ultimate-builder-kit-builder-modal").on("click","#usk_template_status_switcher",function(){l("1"===t("#usk_template_status").val()?0:1)}).on("keydown","#usk_template_status_switcher",function(e){" "!==e.key&&"Enter"!==e.key||(e.preventDefault(),l("1"===t("#usk_template_status").val()?0:1))})})}(jQuery);