(()=>{const r={init:function(){this.isInitialized||(this.bindEvents(),this.isInitialized=!0)},bindEvents:function(){const t=this,e=document.getElementById("notifal-deactivation-overlay");document.addEventListener("click",function(i){const a=i.target.closest("a");if(a&&a.href&&a.href.includes("action=deactivate")&&(a.href.includes("plugin=notifal%2Fnotifal.php")||a.href.includes("plugin=notifal/notifal.php")))return i.preventDefault(),t.show(),!1}),e&&e.addEventListener("click",function(i){i.target===this&&t.hide()});const o=document.getElementById("notifal-deactivation-close");o&&o.addEventListener("click",function(){t.hide()}),document.addEventListener("change",function(i){i.target&&i.target.classList.contains("notifal-deactivation-reason-input")&&t.onReasonChange(i.target)}),document.addEventListener("input",function(i){i.target&&(i.target.classList.contains("notifal-deactivation-input")||i.target.classList.contains("notifal-deactivation-textarea"))&&t.updateSubmitButton()}),document.addEventListener("keyup",function(i){i.target&&(i.target.classList.contains("notifal-deactivation-input")||i.target.classList.contains("notifal-deactivation-textarea"))&&t.updateSubmitButton()}),document.addEventListener("change",function(i){i.target&&(i.target.classList.contains("notifal-deactivation-input")||i.target.classList.contains("notifal-deactivation-textarea"))&&t.updateSubmitButton()});const n=document.getElementById("notifal-submit-deactivate");n&&n.addEventListener("click",function(){t.submitFeedback()});const s=document.getElementById("notifal-skip-deactivate");s&&s.addEventListener("click",function(){t.skipFeedback()}),document.addEventListener("keydown",function(i){t.overlay&&t.overlay.classList.contains("show")&&i.key==="Escape"&&t.hide()}),this.interceptDeactivationLinks()},interceptDeactivationLinks:function(){const t=this;document.addEventListener("click",function(e){const o=e.target.closest('a[href*="action=deactivate"]');o&&(o.href.includes("plugin=notifal%2Fnotifal.php")||o.href.includes("plugin=notifal/notifal.php"))&&(e.preventDefault(),t.show())})},onReasonChange:function(t){t.value;const e=t.closest(".notifal-deactivation-reason");document.querySelectorAll(".notifal-deactivation-input-container").forEach(a=>a.style.display="none"),document.querySelectorAll(".notifal-deactivation-help-text").forEach(a=>a.style.display="none");const s=e.querySelector(".notifal-deactivation-input-container");s&&(s.style.display="block",setTimeout(()=>{this.updateSubmitButton()},10));const i=e.querySelector(".notifal-deactivation-help-text");i&&(i.style.display="block"),this.updateSubmitButton()},updateSubmitButton:function(){const t=document.getElementById("notifal-submit-deactivate"),e=document.getElementById("notifal-skip-deactivate"),o=document.querySelector('input[name="notifal_deactivation_reason"]:checked');if(!o){t&&(t.disabled=!0),e&&(e.textContent=notifalDeactivationPopup.i18n.skipButton);return}const n=o.value;let s=!0;const a=o.closest(".notifal-deactivation-reason").querySelector(".notifal-deactivation-input-container");if(a&&a.style.display!=="none"){const c=a.querySelector(".notifal-deactivation-input, .notifal-deactivation-textarea");c&&(c.value.trim()||(s=!1))}if(n==="has_notifal_pro"){t&&(t.style.display="none"),e&&(e.style.display="none"),this.showPreventionMessage();return}else t&&(t.style.display=""),e&&(e.textContent=notifalDeactivationPopup.i18n.skipButton,e.style.display="");n==="has_notifal_pro"?(this.showPreventionMessage(),s=!1):this.hidePreventionMessage(),t&&(t.disabled=!s)},showPreventionMessage:function(){if(document.querySelector(".notifal-deactivation-prevention-message"))return;const t=`
                <div class="notifal-deactivation-prevention-message">
                    <strong>${notifalDeactivationPopup.i18n.preventionMessage}</strong>
                </div>
            `,e=document.querySelector(".notifal-deactivation-buttons");e&&e.insertAdjacentHTML("beforebegin",t)},hidePreventionMessage:function(){const t=document.querySelector(".notifal-deactivation-prevention-message");t&&t.remove()},submitFeedback:function(){this.setLoadingState(!0);const e=document.getElementById("notifal-deactivation-form").querySelector('input[name="notifal_deactivation_reason"]:checked'),o=e?e.value:"",n=new FormData;n.append("action","notifal_process_deactivation_feedback"),n.append("nonce",notifalDeactivationPopup.nonce),n.append("reason",o);const i=e.closest(".notifal-deactivation-reason").querySelector(".notifal-deactivation-input-container");if(i&&i.style.display!=="none"){const a=i.querySelector(".notifal-deactivation-input, .notifal-deactivation-textarea");if(a){const c=a.name,l=a.value.trim();n.append(c,l)}}fetch(notifalDeactivationPopup.ajaxUrl,{method:"POST",body:n,signal:AbortSignal.timeout(15e3)}).then(a=>a.json()).then(a=>{a.success?a.data.prevent_deactivation?(this.showError(a.data.message),this.setLoadingState(!1)):(a.data.api_success===!1&&this.showApiWarning(),this.proceedWithDeactivation()):(this.showError(a.data||notifalDeactivationPopup.i18n.errorMessage),this.setLoadingState(!1))}).catch(a=>{this.showNetworkWarning(),this.proceedWithDeactivation()})},skipFeedback:function(){this.setLoadingState(!0,!0),document.getElementById("notifal-deactivation-form");const t=new FormData;t.append("action","notifal_skip_deactivation_feedback"),t.append("nonce",notifalDeactivationPopup.skipNonce),fetch(notifalDeactivationPopup.ajaxUrl,{method:"POST",body:t}).then(e=>e.json()).then(e=>{e.success?this.proceedWithDeactivation():this.proceedWithDeactivation()}).catch(e=>{this.proceedWithDeactivation()})},proceedWithDeactivation:function(){const t=document.querySelector('a[href*="action=deactivate"][href*="plugin=notifal%2Fnotifal.php"]');t?setTimeout(()=>{window.location.href=t.href},500):window.location.href="plugins.php"},setLoadingState:function(t,e=!1){const o=document.getElementById("notifal-submit-deactivate"),n=document.getElementById("notifal-skip-deactivate");t?e?(n&&(n.disabled=!0,n.innerHTML=`<span class="notifal-deactivation-loading"></span>${notifalDeactivationPopup.i18n.deactivating}`),o&&(o.disabled=!0)):(o&&(o.disabled=!0,o.innerHTML=`<span class="notifal-deactivation-loading"></span>${notifalDeactivationPopup.i18n.deactivating}`),n&&(n.disabled=!0)):(o&&(o.disabled=!1,o.textContent=notifalDeactivationPopup.i18n.submitButton),n&&(n.disabled=!1,n.textContent=notifalDeactivationPopup.i18n.skipButton),this.updateSubmitButton())},showError:function(t){document.querySelectorAll(".notifal-deactivation-error, .notifal-deactivation-warning").forEach(s=>s.remove());const o=`<div class="notifal-deactivation-error">${t}</div>`,n=document.querySelector(".notifal-deactivation-buttons");n&&n.insertAdjacentHTML("beforebegin",o),setTimeout(()=>{const s=document.querySelector(".notifal-deactivation-error");s&&(s.style.opacity="0",setTimeout(()=>s.remove(),300))},5e3)},showApiWarning:function(){document.querySelectorAll(".notifal-deactivation-error, .notifal-deactivation-warning").forEach(n=>n.remove());const e=`<div class="notifal-deactivation-warning">
${notifalDeactivationPopup.i18n.apiWarning}
            </div>`,o=document.querySelector(".notifal-deactivation-buttons");o&&o.insertAdjacentHTML("beforebegin",e),setTimeout(()=>{const n=document.querySelector(".notifal-deactivation-warning");n&&(n.style.opacity="0",setTimeout(()=>n.remove(),300))},3e3)},showNetworkWarning:function(){document.querySelectorAll(".notifal-deactivation-error, .notifal-deactivation-warning").forEach(n=>n.remove());const e=`<div class="notifal-deactivation-warning">
${notifalDeactivationPopup.i18n.networkWarning}
            </div>`,o=document.querySelector(".notifal-deactivation-buttons");o&&o.insertAdjacentHTML("beforebegin",e),setTimeout(()=>{const n=document.querySelector(".notifal-deactivation-warning");n&&(n.style.opacity="0",setTimeout(()=>n.remove(),300))},3e3)},show:function(){const t=document.getElementById("notifal-deactivation-overlay"),e=document.getElementById("notifal-deactivation-modal");t&&(t.style.display="block",t.classList.add("show")),e&&(e.style.display="block",e.classList.add("show"),e.setAttribute("tabindex","-1"),e.focus()),document.body.classList.add("notifal-modal-open")},hide:function(){const t=document.getElementById("notifal-deactivation-overlay"),e=document.getElementById("notifal-deactivation-modal");t&&(t.classList.remove("show"),setTimeout(()=>{t.style.display="none"},300)),e&&(e.classList.remove("show"),e.classList.add("hide"),setTimeout(()=>{e.style.display="none",e.classList.remove("hide")},300)),document.body.classList.remove("notifal-modal-open"),this.resetForm()},resetForm:function(){const t=document.getElementById("notifal-deactivation-form");t&&t.reset(),document.querySelectorAll(".notifal-deactivation-input-container").forEach(i=>i.style.display="none"),document.querySelectorAll(".notifal-deactivation-help-text").forEach(i=>i.style.display="none");const n=document.querySelector(".notifal-deactivation-prevention-message");n&&n.remove();const s=document.querySelector(".notifal-deactivation-error");s&&s.remove(),this.updateSubmitButton()},currentReason:null,isInitialized:!1,overlay:null,modal:null};document.addEventListener("DOMContentLoaded",function(){r.init()})})();
