!function(){"use strict";class e{static overlay(){if(!document.querySelector(".wcp-aws-overlay")){const e=document.createElement("div");e.classList.add("wcp-aws-overlay"),document.body.append(e),document.body.classList.add("no-scroll")}return this}}async function t(e,t){if(!t)return;const s=t.querySelector(".wcp-aws__input"),r=t.querySelectorAll(".wcp-aws__error"),n=t.closest(".wcp-aws__content"),a=t.parentNode.parentNode.querySelector(".wcp-aws__form"),o=t.parentNode.parentNode.querySelector(".wcp-aws__heading"),c=t.parentNode.parentNode.querySelector(".wcp-aws__subheading"),i=t.parentNode.parentNode.querySelector(".wcp-aws__submit"),l=t.parentNode.parentNode.querySelector('.wcp-aws-checkbox input[type="checkbox"]:checked');if(a.classList.contains("loading"))return;s.classList.contains("wcp-aws__error")&&s.classList.remove("wcp-aws__error"),r&&r.forEach((e=>{e.remove()})),a.classList.add("loading");let d=new FormData;d.append("action","wcp_aws_handle_subscribe_form"),d.append("fields",new URLSearchParams(new FormData(t)).toString()),(await fetch(AWEBER_SUBSCRIBERS.ajaxurl,{method:"POST",credentials:"same-origin",headers:{"Cache-Control":"no-cache"},body:d})).text().then((e=>{try{const s=JSON.parse(e);let r=l?1:0;if(a.classList.remove("loading"),"error"===s.status){if(s.errors)for(let e in s.errors){const r=t.querySelector('input[name="'+e+'"]').closest(".wcp-aws__input"),n=document.createElement("span");n.classList.add("wcp-aws__error"),n.textContent=s.errors[e],r.classList.add("wcp-aws__error--inline"),r.append(n)}else{const e=document.createElement("div");e.classList.add("wcp-aws__error"),e.textContent=s.message,t.append(e)}r=0}else"success"===s.status&&(n.classList.add("wcp-aws__content-success"),a.innerHTML=s.message,null!=s&&s.heading&&(o.innerHTML=s.heading),r=1);null!=s&&s.error&&console.log(s.error);const d={event:"GAevent",eventName:"clickEmailForm",formTitle:null!=o&&o.innerHTML?o.innerHTML:"",formSubTitle:null!=c&&c.innerHTML?c.innerHTML:"",buttonLabel:null!=i&&i.innerHTML?i.innerHTML:"",validation:r};dataLayer.push(d)}catch(e){a.classList.remove("loading"),console.warn("Wrong response from Aweber")}}))}const s=document.querySelectorAll(".wcp-aweber-subscribers form");s&&s.forEach((e=>{e.addEventListener("submit",(async s=>{s.preventDefault(),t(0,e)}))})),document.addEventListener("click",(e=>{if(e.target.closest(".wcp-aweber-subscribers .wcp-aws__input > input")){const e=document.querySelectorAll(".wcp-aweber-subscribers .wcp-aws__input"),t=document.querySelectorAll(".wcp-aweber-subscribers .wcp-aws__error");e&&e.forEach((e=>{e.classList.remove("wcp-aws__error--inline")})),t&&t.forEach((e=>{e.remove()}))}}));const r=document.querySelectorAll(".wcp-aws__spin"),n=e=>{const t=e.target.closest(".wcp-aws__fortune-wheel"),s=t.closest(".wcp-aws__wof"),r=t.querySelector(".wcp-aws__content-inner"),n=t.querySelector(".wcp-aws__wheel"),o=t.querySelector(".wcp-aws__wheel div");let c="true"===t.getAttribute("data-spinning"),i=n.getAttribute("data-wheel-angle-offset-desktop")?parseInt(n.getAttribute("data-wheel-angle-offset-desktop")):0,l=n.getAttribute("data-wheel-angle-offset-mobile")?parseInt(n.getAttribute("data-wheel-angle-offset-mobile")):0;if(c)return;c=!0,t.setAttribute("data-spinning",c);let d=1800;window.innerWidth>768?d+=i:d+=l,o.style.transition="none",o.style.transform="rotate(".concat(0,"deg)"),setTimeout((()=>{o.style.transition="transform 5s cubic-bezier(0.25, 0.1, 0.25, 1)",o.style.transform="rotate(".concat(d,"deg)")}),0),setTimeout((async()=>{c=!1,t.setAttribute("data-spinning",c),s.classList.add("loading");const e=await async function(){let e=new FormData;e.append("action","wcp_aws_get_default_form");const t=await fetch(AWEBER_SUBSCRIBERS.ajaxurl,{method:"POST",credentials:"same-origin",headers:{"Cache-Control":"no-cache"},body:e}),s=await t.text(),r=JSON.parse(s);return"success"===r.status&&r.message}();if(e){r.innerHTML=e;const t=r.querySelector("form");t&&a(t)}s.classList.remove("loading"),s.classList.add("spin-complete")}),5e3)},a=e=>{e.addEventListener("submit",(async s=>{s.preventDefault(),await t(0,e)}))};r.forEach((e=>{e.addEventListener("click",n)}));class o{constructor(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.callback=e,this.options={root:null,rootMargin:"0px",threshold:.5,isTest:this.isTest(),...t},this.observer=new IntersectionObserver(this._handleIntersect.bind(this),this.options)}_handleIntersect(e,t){e.forEach((e=>{e.isIntersecting&&(this.callback(e.target),this.unobserve(e.target))}))}observe(e){this.observer.observe(e)}unobserve(e){this.observer.unobserve(e)}disconnect(){this.observer.disconnect()}isTest(){return"1"===new URLSearchParams(window.location.search).get("logvisibility")}sendEvent(e){let t={event:"GAevent",eventName:e.getAttribute("data-ga-aweber-subscribers"),formTitle:e.getAttribute("data-form-title"),formSubTitle:e.getAttribute("data-form-sub-title"),buttonLabel:e.getAttribute("data-button-label")};dataLayer.push(t),this.options.isTest&&this.logEvent(t)}logEvent(e){console.info(e)}}window.addEventListener("load",(function(){new e,function(){const e=document.querySelectorAll("[data-ga-aweber-subscribers]");e&&function(e){var t;if(null!==(t=AWEBER_SUBSCRIBERS)&&void 0!==t&&t.gtm_track_view&&"enabled"!==AWEBER_SUBSCRIBERS.gtm_track_view)return!1;const s=new o((e=>{s.sendEvent(e)}));e.forEach((e=>s.observe(e)))}(e)}()}))}();