document.addEventListener("DOMContentLoaded",function(){const e=document.querySelectorAll(".wp-block-zolo-newsletter"),t=(e,t,n)=>{e?.nextElementSibling?.classList.contains("zolo-newsletter-message")&&e.nextElementSibling.remove();const o=document.createElement("div");o.className="zolo-newsletter-message",o.innerHTML=`<span id="zolo-newsletter-info-text" class="zolo-newsletter-info-text status-${n}">${t}</span>`,e.append(o)};e.length>0&&e.forEach(e=>{e.addEventListener("submit",function(n){n.preventDefault();const o=e.querySelector("#zolo-newsletter-email-field"),s=o?o.value.trim():"";let r="";const a=e.querySelector("#zolo-newsletter-name-field");if(a&&(r=a.value.trim()),!s)return void t(e,"Please enter a valid email address.","error");const l=e.querySelector(".zolo-newsletter-form")?.dataset.settings||"",i=new FormData;i.append("email",s),i.append("fname",r),i.append("action","zolo_subscribe_newsletter"),i.append("nonce",zoloSettings.zolo_nonce),i.append("data",l),fetch(zoloSettings.ajaxurl,{method:"POST",body:i,credentials:"same-origin",headers:{"X-Requested-With":"XMLHttpRequest"}}).then(e=>{if(!e.ok)throw new Error("Network response was not ok");return e.json()}).then(n=>{"success"===n.status?(o.value="",a&&(a.value=""),t(e,n.message,"success")):t(e,n.message,"error")}).catch(n=>{t(e,`An error occurred: ${n.message}`,"error")})})})});