window.addEventListener("DOMContentLoaded",(()=>{const e=document.querySelectorAll('[data-component="newsletter-builder-signup"]'),{newsletterBuilderSignupForm:{nonce:r=""}={}}=window;e.forEach((e=>{const n=e.querySelector("button");n&&n.addEventListener("click",(n=>{n.preventDefault();const t=e.querySelector('input[type="email"]'),s=e.querySelectorAll('input[type="checkbox"]:checked'),o=e.querySelector('input[name="newsletter-builder-hidden"]'),a=e.querySelector(".wp-block-newsletter-builder-signup-form__response");if(!a||!t)return;if(a.innerHTML="",a.classList.remove("success","error"),!t.value)return a.classList.add("error"),a.innerHTML="Email is required",void t.focus();if(!s.length&&!o)return a.classList.add("error"),void(a.innerHTML="Please select a newsletter");const l=new URLSearchParams;var c;l.append("email",t.value),o?l.append("listIds",o.value):l.append("listIds",(null!==(c=Array.from(s).map((e=>e.value)))&&void 0!==c?c:[]).join(","));const i=grecaptcha.getResponse();i.length>0?(l.append("captcha",i),fetch("/wp-json/newsletter-builder/v1/subscribe",{method:"POST",body:l,headers:{"Content-Type":"application/x-www-form-urlencoded","X-WP-Nonce":r}}).then((e=>e.json())).then((e=>{const{success:r,message:n}=e;a.classList.add(r?"success":"error"),a.innerHTML=n}))):(a.classList.add("error"),a.innerHTML="Please verify that you are not a robot")}))}))}));