!function(i){"use strict";const t={init:function(){"undefined"!=typeof lbaicDeactivation&&(this.deactivateLink=i('tr[data-plugin="'+lbaicDeactivation.pluginBasename+'"] .deactivate a'),this.modal=i("#lbaic-deactivation-modal"),this.form=i("#lbaic-deactivation-form"),this.submitBtn=i("#lbaic-deactivation-submit"),this.skipBtn=i("#lbaic-deactivation-skip"),this.closeBtn=i(".lbaic-deactivation-modal-close"),this.deactivateUrl="",this.clickedButton=null,this.bindEvents())},bindEvents:function(){const t=this;this.deactivateLink.on("click",(function(a){a.preventDefault(),t.deactivateUrl=i(this).attr("href"),t.openModal()})),this.submitBtn.on("click",(function(i){i.preventDefault(),t.clickedButton="submit",t.submitFeedback()})),this.skipBtn.on("click",(function(i){i.preventDefault(),t.clickedButton="skip",t.submitFeedback(!0)})),this.closeBtn.on("click",(function(i){i.preventDefault(),t.closeModal()})),this.form.on("change",'input[name="lbaic_deactivation_reason"]',(function(){const a=i(this).closest(".lbaic-primary-reason");t.form.find(".lbaic-primary-reason").removeClass("active"),t.form.find('input[name="lbaic_deactivation_sub_reason"]').prop("checked",!1),t.form.find(".lbaic-sub-reasons textarea").val(""),a.addClass("active")})),this.form.on("change",'input[name="lbaic_deactivation_sub_reason"]',(function(){})),this.form.on("input",".lbaic-sub-reasons textarea",(function(){const t=i(this).closest(".lbaic-sub-reason").find('input[name="lbaic_deactivation_sub_reason"]');t.is(":checked")||t.prop("checked",!0).trigger("change")})),this.modal.on("click",(function(a){i(a.target).hasClass("lbaic-deactivation-modal-overlay")&&t.closeModal()})),i(document).on("keyup",(function(i){"Escape"===i.key&&t.modal.is(":visible")&&t.closeModal()}))},openModal:function(){this.modal.show(),this.form.find('input[type="radio"]').prop("checked",!1),this.form.find(".lbaic-primary-reason").removeClass("active"),this.form.find("textarea").val("")},closeModal:function(){this.modal.hide()},submitFeedback:function(t=!1){const a=this;let e="no_reason",n="",o="";if(t){const i=this.form.find('input[name="lbaic_deactivation_reason"]:checked').val();i&&(e=i);const t=this.form.find('input[name="lbaic_deactivation_sub_reason"]:checked').val();t&&(n=t),"other"===n&&(o=this.form.find(".lbaic-primary-reason.active .lbaic-sub-reasons textarea").val())}else{const i=this.form.find('input[name="lbaic_deactivation_reason"]:checked').val();i&&(e=i);const t=this.form.find('input[name="lbaic_deactivation_sub_reason"]:checked').val();t&&(n=t),"other"===n&&(o=this.form.find(".lbaic-primary-reason.active .lbaic-sub-reasons textarea").val())}const s={site_url:lbaicDeactivation.siteUrl,site_mode:lbaicDeactivation.siteMode,reason:e,sub_reason:n,additional_details:o,date:(new Date).toISOString()};this.submitBtn.prop("disabled",!0),this.skipBtn.prop("disabled",!0),"submit"===this.clickedButton?this.submitBtn.addClass("updating-message"):"skip"===this.clickedButton&&this.skipBtn.addClass("updating-message"),i.ajax({url:lbaicDeactivation.restUrl+"plugin/deactivation",method:"POST",data:JSON.stringify(s),contentType:"application/json",beforeSend:function(i){i.setRequestHeader("X-WP-Nonce",lbaicDeactivation.nonce)},timeout:5e3,complete:function(){window.location.href=a.deactivateUrl}})}};i(document).ready((function(){t.init()}))}(jQuery);