(()=>{"use strict";const e={n:r=>{const s=r&&r.__esModule?()=>r.default:()=>r;return e.d(s,{a:s}),s},d:(r,s)=>{if(Array.isArray(s))for(var t=0;t<s.length;){var i=s[t++],a=s[t++];e.o(r,i)?0===a&&t++:0===a?Object.defineProperty(r,i,{enumerable:!0,value:s[t++]}):Object.defineProperty(r,i,{enumerable:!0,get:a})}else for(var i in s)e.o(s,i)&&!e.o(r,i)&&Object.defineProperty(r,i,{enumerable:!0,get:s[i]})},o:(e,r)=>Object.hasOwn(e,r)},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)})})})();