!function(e){"use strict";var n="open",i={modal:null,form:null,deactivateLink:null,isProcessing:!1,deactivateLinkHref:null,init:function(){"undefined"!=typeof ShopEngineDeactivation&&!1===ShopEngineDeactivation.show_modal||(this.cacheElements(),this.bindEvents(),this.syncFeedbackState())},cacheElements:function(){this.modal=e("#shopengine-deactivation-modal"),this.form=e("#shopengine-deactivation-form"),this.deactivateLink=e('#deactivate-shopengine, tr[data-slug="shopengine"] .deactivate a, a[href*="plugin=shopengine/shopengine.php"][href*="deactivate"], a[href*="shopengine.php"][href*="deactivate"]')},bindEvents:function(){var i=this;this.deactivateLink.length&&this.deactivateLink.on("click.shopengineModal",(function(n){n.preventDefault(),i.deactivateLinkHref=e(this).attr("href"),e(".shopengine-deactivation-skip").data("deactivate-link",i.deactivateLinkHref),i.openModal()})),this.form.on("submit.shopengineModal",(function(e){e.preventDefault(),i.submitForm()})),e(".shopengine-deactivation-close").on("click.shopengineModal",(function(){i.closeModal()})),e(".shopengine-deactivation-skip").on("click.shopengineModal",(function(){var n=e(this).data("deactivate-link");n&&(window.location.href=n)})),this.form.on("change.shopengineModal",'input[name="reason"]',(function(){i.hideAllFeedbacks(),i.showFeedbackForReason(e(this).closest(".shopengine-deactivation-radio-item").data("reason-key"))})),this.modal.on("click.shopengineModal",(function(n){e(n.target).is(i.modal)&&i.closeModal()})),e(document).on("keydown.shopengineModal",(function(e){"Escape"===e.key&&i.modal.hasClass(n)&&i.closeModal()}))},openModal:function(){this.modal.addClass(n),e("body").css("overflow","hidden"),this.hideErrorMessage(),this.syncFeedbackState()},closeModal:function(){this.modal.removeClass(n),e("body").css("overflow",""),this.form[0].reset(),this.hideErrorMessage(),this.hideAllFeedbacks()},syncFeedbackState:function(){var e=this.form.find('input[name="reason"]:checked');e.length&&(this.hideAllFeedbacks(),this.showFeedbackForReason(e.closest(".shopengine-deactivation-radio-item").data("reason-key")))},submitForm:function(){var n=this;if(!this.isProcessing){var i=this.form.find('input[name="reason"]:checked'),a=i.val();if(a){var o=i.closest(".shopengine-deactivation-radio-item"),t=o.data("reason-key"),s={action:"shopengine_deactivation_feedback",shopengine_nonce:this.form.find('input[name="shopengine_nonce"]').val(),reason:a,reason_key:o.find(".shopengine-reason-key").val()||"",reason_label:o.find(".shopengine-reason-label").val()||a,feedback:o.find('textarea[name="feedback_'+t+'"]').val()||""};this.setProcessing(!0),e.ajax({type:"POST",url:ShopEngineDeactivation.ajaxurl,data:s,success:function(){},error:function(e,n,i){window.console.error("ShopEngine: deactivation feedback error —",i)},complete:function(){n.setProcessing(!1);var i=e(".shopengine-deactivation-skip").data("deactivate-link");i&&(window.location.href=i)}})}else this.showErrorMessage("Please select a reason first.")}},hideAllFeedbacks:function(){e(".shopengine-deactivation-radio-feedback").removeClass("active")},showFeedbackForReason:function(n){n&&e('.shopengine-deactivation-radio-item[data-reason-key="'+n+'"] .shopengine-deactivation-radio-feedback').addClass("active")},showErrorMessage:function(n){e("#shopengine-deactivation-error-message").html(n).slideDown(300)},hideErrorMessage:function(){var n=e("#shopengine-deactivation-error-message");n.slideUp(300,(function(){n.html("")}))},setProcessing:function(n){this.isProcessing=n,e(".shopengine-deactivation-submit").prop("disabled",n).toggleClass("loading",n)}};e(document).ready((function(){i.init()})),window.ShopEngineDeactivationModal=i}(jQuery);