(()=>{"use strict";let e;var t;t=function(){const t=new Event("newspack-newsletters-subscribe-success");document.querySelectorAll(".newspack-newsletters-subscribe").forEach(s=>{const n=s.querySelector("form");if(!n)return;const i=s.querySelector(".newspack-newsletters-subscribe__response"),a=s.querySelector(".newspack-newsletters-subscribe__message"),o=s.querySelector('input[type="email"]'),r=s.querySelector('button[type="submit"]'),c=document.createElement("span");c.classList.add("spinner"),n.endFlow=(e,d=500,l=!1,p={})=>{s.setAttribute("data-status",d);const u=document.createElement("p");if(o.removeAttribute("disabled"),r.removeChild(c),r.removeAttribute("disabled"),n.classList.remove("in-progress"),u.innerHTML=l?s.getAttribute("data-success-message"):e,a.appendChild(u),u.className=`message status-${d}`,200===d){s.replaceChild(i,n),n.dispatchEvent(t),window.newspackRAS=window.newspackRAS||[];const e=new FormData(n).getAll("lists[]"),a={email:o.value};p?.newspack_popup_id&&(a.newspack_popup_id=p.newspack_popup_id),p?.gate_post_id&&(a.gate_post_id=p.gate_post_id),e.length&&l&&window.newspackRAS.push(function(t){t.dispatchActivity("newsletter_signup",{...a,lists:e,newsletters_subscription_method:p?.newsletters_subscription_method||"newsletters-subscription-block"})}),p?.registered&&window.newspackRAS.push(function(e){e.dispatchActivity("reader_registered",{...a,registration_method:p?.registration_method||"newsletters-subscription"})})}},n.addEventListener("submit",t=>{if(t.preventDefault(),a.innerHTML="",n.classList.add("in-progress"),r.disabled=!0,r.appendChild(c),!n.npe?.value)return n.endFlow(newspack_newsletters_subscribe_block.invalid_email,400);const s=new FormData(n);if(!s.has("npe")||!s.get("npe"))return n.endFlow(newspack_newsletters_subscribe_block.invalid_email,400);e&&s.set("newspack_newsletters_subscribe",e),o.setAttribute("disabled","true"),r.setAttribute("disabled","true"),fetch(n.getAttribute("action")||window.location.pathname,{method:"POST",headers:{Accept:"application/json"},body:s}).then(t=>{t.json().then(s=>{const{message:i,newspack_newsletters_subscribed:a,newspack_newsletters_subscribe:o,metadata:r}=s;e=o,n.endFlow(i,t.status,a,r),200===t.status&&s?.registered&&!0!==s?.verified&&s?.verification_nonce&&(window.newspackRAS=window.newspackRAS||[],window.newspackRAS.push(e=>{"function"==typeof e?.openVerificationModal&&e.openVerificationModal({email:s.email,verificationNonce:s.verification_nonce,onSendCode:()=>{"function"==typeof e?.openAuthModal&&e.openAuthModal({skipAuthenticatedCheck:!0,skipNewslettersSignup:!0,backButtonClosesModal:!0,initialState:"otp",closeOnSuccess:!0,onClose:null})}})}))})})})})},"undefined"!=typeof document&&("complete"!==document.readyState&&"interactive"!==document.readyState?document.addEventListener("DOMContentLoaded",t):t())})();