(()=>{"use strict";var e={n:r=>{var s=r&&r.__esModule?()=>r.default:()=>r;return e.d(s,{a:s}),s},d:(r,s)=>{for(var t in s)e.o(s,t)&&!e.o(r,t)&&Object.defineProperty(r,t,{enumerable:!0,get:s[t]})},o:(e,r)=>Object.prototype.hasOwnProperty.call(e,r)};const r=window.wp.domReady;e.n(r)()(()=>{document.querySelectorAll(".gkit-mailchimp-form-wrap").forEach(e=>{(e=>{const r=e.querySelector(".gkit-mailchimp-response"),s=e.querySelector(".gkit-mailchimp-form"),t=e.querySelector(".gkit-mailchimp-loader"),i=e.querySelector(".gkit-mailchimp-form__submit-btn");s.addEventListener("submit",a=>{a.preventDefault(),r.classList.remove("success"),r.classList.remove("error"),r.innerHTML="",t&&(t.style.display="block",i.disabled=!0);let o=s.getAttribute("data-double-optin-message"),l=s.getAttribute("data-success-message");const c=new FormData(s),n={list_id:s.getAttribute("data-listed-id")};c.forEach((e,r)=>{n[r]=e}),fetch(s.action,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(n)}).then(e=>{if(!e.ok)throw new Error("Network response was not ok");return e.json()}).then(e=>{if(Object.keys(e?.error).length>0){let s=e?.error,t="";if("Member Exists"==s.title){const r=/([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}) is already a list member./,s=e?.error?.detail.match(r);s&&(t=s[0])}else"Invalid Resource"==s?.title&&Array.isArray(s?.errors)&&(t=s.errors.map(e=>`${e?.message}`).join(" "));r.innerHTML=t||"There was an error. Please try again.",r.classList.add("error"),r.classList.remove("success")}else"subscribed"===e.status?(s.reset(),r.innerHTML=l||"You have successfully subscribed to our mailing list.",r.classList.add("success"),r.classList.remove("error")):"pending"===e.status&&(s.reset(),r.innerHTML=o||"Please check your email to confirm your subscription.",r.classList.add("success"),r.classList.remove("error"))}).catch(r=>{const s=e.querySelector(".gkit-mailchimp-response");s.innerHTML="There was an error. Please try again.",s.classList.add("error"),s.classList.remove("success"),console.error("Fetch error:",r)}).finally(()=>{t&&(t.style.display="none",i.disabled=!1)})}),e.querySelectorAll(".gkit-mailchimp-form__input").forEach(e=>{e.addEventListener("change",()=>{const r=e.closest(".gkit-mailchimp-form__input-wrap");e.value.trim()?r.classList.add("filled"):r.classList.remove("filled")})})})(e)})})})();