(()=>{"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"),r=s.querySelector(".newspack-newsletters-subscribe__message"),a=s.querySelector('input[type="email"]'),c=s.querySelector('button[type="submit"]'),o=document.createElement("span");o.classList.add("spinner"),n.endFlow=(e,d=500,l=!1,p={})=>{s.setAttribute("data-status",d);const u=document.createElement("p");if(a.removeAttribute("disabled"),c.removeChild(o),c.removeAttribute("disabled"),n.classList.remove("in-progress"),u.innerHTML=l?s.getAttribute("data-success-message"):e,r.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[]"),r={email:a.value};p?.newspack_popup_id&&(r.newspack_popup_id=p.newspack_popup_id),p?.gate_post_id&&(r.gate_post_id=p.gate_post_id),e.length&&l&&window.newspackRAS.push(function(t){t.dispatchActivity("newsletter_signup",{...r,lists:e,newsletters_subscription_method:p?.newsletters_subscription_method||"newsletters-subscription-block"})}),p?.registered&&window.newspackRAS.push(function(e){e.dispatchActivity("reader_registered",{...r,registration_method:p?.registration_method||"newsletters-subscription"})})}},n.addEventListener("submit",t=>{if(t.preventDefault(),r.innerHTML="",n.classList.add("in-progress"),c.disabled=!0,c.appendChild(o),!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),a.setAttribute("disabled","true"),c.setAttribute("disabled","true"),fetch(n.getAttribute("action")||window.location.pathname,{method:"POST",headers:{Accept:"application/json"},body:s}).then(t=>{t.json().then(({message:s,newspack_newsletters_subscribed:i,newspack_newsletters_subscribe:r,metadata:a})=>{e=r,n.endFlow(s,t.status,i,a)})})})})},"undefined"!=typeof document&&("complete"!==document.readyState&&"interactive"!==document.readyState?document.addEventListener("DOMContentLoaded",t):t())})();