!function(){"use strict";class t{constructor(){"undefined"!=typeof eddVerification?(this.config=eddVerification,this.modal=null,this.pollInterval=null,this.countdownInterval=null,this.secondsRemaining=0,this.init()):console.error("UserVerification: eddVerification is not defined.")}init(){this.modal=new globalThis.EDDModal("edd-verification-modal");const t=document.getElementById("edd-verification-resend");t?.addEventListener("click",(()=>this.handleResendClick()))}handleResendClick(){this.modal.open("<p>"+this.config.strings.sending+"</p>"),this.modal.showLoading(),this.sendResendRequest()}sendResendRequest(){const t=new FormData;t.append("action","edd_resend_verification_email"),t.append("nonce",this.config.nonce),fetch(this.config.ajax_url,{method:"POST",body:t,credentials:"same-origin"}).then((t=>t.json())).then((t=>{this.modal.hideLoading(),t.success?(this.showSuccessState(t.data.message),this.startCountdown()):this.showErrorState(t.data.message,t.data.seconds_remain)})).catch((t=>{this.modal.hideLoading(),this.showErrorState(this.config.strings.error),console.error("UserVerification error:",t)}))}showSuccessState(t){const n=`\n\t\t\t\t<div class="edd-modal__message--success">\n\t\t\t\t\t<p>${t}</p>\n\t\t\t\t</div>\n\t\t\t\t<p>${this.config.strings.check_email}</p>\n\t\t\t\t<div class="edd-modal__countdown edd-countdown__seconds">\n\t\t\t\t\t${this.config.countdown}\n\t\t\t\t</div>\n\t\t\t\t<p class="edd-modal__verifying">\n\t\t\t\t\t${this.config.strings.verifying}\n\t\t\t\t</p>\n\t\t\t`;this.modal.setContent(n)}showErrorState(t,n){let e=`\n\t\t\t<div class="edd-modal__message--error">\n\t\t\t\t<p id="edd-verification-error-message">${t}</p>\n\t\t\t</div>\n\t\t`;e+=`\n\t\t\t<button type="button" class="button edd-modal__close-button" id="edd-modal__close-button">\n\t\t\t\t${this.config.strings.close}\n\t\t\t</button>\n\t\t`,this.modal.setContent(e),n&&n>0&&(this.secondsRemaining=n,this.startErrorCountdown())}startCountdownTimer(t,n){this.stopCountdown(),this.secondsRemaining=t,this.countdownInterval=setInterval((()=>{this.secondsRemaining--;const t=this.modal.querySelector(".edd-countdown__seconds");t&&(t.textContent=this.secondsRemaining),this.secondsRemaining<=0&&(this.stopCountdown(),n&&n())}),1e3)}startErrorCountdown(){this.startCountdownTimer(this.secondsRemaining,(()=>this.modal.close()))}startCountdown(){this.startCountdownTimer(this.config.countdown,(()=>this.showResendButton())),this.startPolling()}stopCountdown(){this.countdownInterval&&(clearInterval(this.countdownInterval),this.countdownInterval=null)}showResendButton(){const t=`\n\t\t\t\t<p>${this.config.strings.check_email}</p>\n\t\t\t\t<button type="button" class="button" id="edd-resend-again-button">\n\t\t\t\t\t${this.config.strings.resend_email}\n\t\t\t\t</button>\n\t\t\t`;this.modal.setContent(t),setTimeout((()=>{const t=this.modal.querySelector("#edd-resend-again-button");t?.addEventListener("click",(()=>{this.handleResendClick()}))}),100)}startPolling(){this.pollInterval=setInterval((()=>{this.checkVerificationStatus()}),1e3*this.config.poll_interval)}stopPolling(){this.pollInterval&&(clearInterval(this.pollInterval),this.pollInterval=null)}checkVerificationStatus(){const t=new FormData;t.append("action","edd_check_verification_status"),t.append("nonce",this.config.nonce),fetch(this.config.ajax_url,{method:"POST",body:t,credentials:"same-origin"}).then((t=>t.json())).then((t=>{t.success&&t.data.is_verified&&(this.stopPolling(),this.stopCountdown(),this.showVerifiedState())})).catch((t=>{console.error("Verification status check error:",t)}))}showVerifiedState(){const t=`\n\t\t\t\t<div class="edd-modal__message--success">\n\t\t\t\t\t<p>${this.config.strings.verified}</p>\n\t\t\t\t</div>\n\t\t\t`;this.modal.setContent(t),setTimeout((()=>{globalThis.location.reload()}),2e3)}}"loading"===document.readyState?document.addEventListener("DOMContentLoaded",(()=>{new t})):new t}();