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