1import{C as p,d as s}from"./site.B0Uxz9u8.js";import{N as n}from"./notification.3iRQkJDw.js";import"./password-strength.AqUmoxgQ.js";const o=class o extends p{constructor(){super(...arguments),this.v2CaptchaResolver=null,this.v2CaptchaPromise=null}connect(){var t;const a=((t=this.submitButtonTarget)==null?void 0:t.dataset.recaptchaBranding)??"";a&&this.createBranding(a)}async subscribe(a=""){let t=!0;const i=new FormData(this.element);a&&i.append("g-recaptcha-response",a);try{const r=await fetch(this.element.getAttribute("action"),{method:"POST",body:i});r.ok||(s("notifications:show",n.Error),t=!1);const e=await r.json();if(e!=null&&e.message){s("notifications:hideAll"),s("notifications:show",n.ErrorPlaceholder),this.element.querySelector(".notification--error.notification--placeholder .message").innerText=e.message;return}if(!t)return;if(this.element.querySelectorAll(".form-group, .btn").forEach(c=>{c.classList.add("hidden")}),e.exists){s("notifications:show",n.Notice);return}this.element.classList.add("success"),s("notifications:show",n.Success)}catch{s("notifications:show",n.Error)}}async handleSubmit(a){var r,e;a.preventDefault(),a.stopPropagation(),dataLayer.push({event:"form_submit",eventCategory:"newsletter_subscribe"});const t=((r=this.submitButtonTarget)==null?void 0:r.dataset.recaptchaKey)??"",i=((e=this.submitButtonTarget)==null?void 0:e.dataset.recaptchaVersion)??"3";if(t){try{await this.ensureRecaptchaLoaded(t,i)}catch{s("notifications:show",n.Error);return}if(i==="3")grecaptcha.ready(async()=>{try{const c=await grecaptcha.execute(t,{action:"submit"})??"";c&&await this.subscribe(c)}catch{s("notifications:show",n.Error)}});else if(i==="2"){if(!this.v2CaptchaPromise)throw new Error("reCAPTCHA v2 was not initialized");const c=await this.v2CaptchaPromise;await this.subscribe(c)}}else await this.subscribe()}createBranding(a){const t=document.createElement("div");t.classList.add("grecaptcha-branding"),t.innerHTML=a,this.element.parentNode.appendChild(t)}ensureRecaptchaLoaded(a,t){return t==="3"?this.loadRecaptchaV3(a):t==="2"?this.loadRecaptchaV2(a):Promise.resolve()}loadRecaptchaV3(a){return new Promise((t,i)=>{if(typeof grecaptcha<"u"&&typeof grecaptcha.execute=="function"){t();return}const r=document.querySelector('script[src*="recaptcha/api.js"]');if(r){r.getAttribute("data-loaded")==="true"?t():(r.addEventListener("load",()=>t()),r.addEventListener("error",()=>i()));return}const e=document.createElement("script");e.src=`https://www.google.com/recaptcha/api.js?render=${a}`,e.async=!0,e.defer=!0,e.addEventListener("load",()=>{e.setAttribute("data-loaded","true"),t()}),e.addEventListener("error",()=>i()),document.head.appendChild(e)})}loadRecaptchaV2(a){return new Promise((t,i)=>{var d;if(typeof grecaptcha<"u"&&typeof grecaptcha.render=="function"){this.renderRecaptchaV2(a),t();return}const r=document.createElement("div");r.classList.add("g-recaptcha"),(d=this.submitButtonTarget.parentNode)==null||d.insertBefore(r,this.submitButtonTarget),window.recaptchaCallback=()=>{try{this.renderRecaptchaV2(a,r),t()}catch(u){i(u)}};const e=document.querySelector('script[src*="recaptcha/api.js"]');if(e){e.getAttribute("data-loaded")==="true"?window.recaptchaCallback():(e.addEventListener("load",()=>window.recaptchaCallback()),e.addEventListener("error",()=>i()));return}const c=document.createElement("script");c.async=!0,c.defer=!0,c.src="https://www.google.com/recaptcha/api.js?hl="+document.documentElement.lang+"&onload=recaptchaCallback&render=explicit",c.addEventListener("load",()=>{c.setAttribute("data-loaded","true")}),c.addEventListener("error",()=>i()),document.head.appendChild(c)})}renderRecaptchaV2(a,t){const i=t??document.querySelector(".g-recaptcha");if(!i)throw new Error("reCAPTCHA container not found");this.v2CaptchaPromise=new Promise(r=>{this.v2CaptchaResolver=r}),grecaptcha.render(i,{sitekey:a,theme:"light",callback:r=>{this.submitButtonTarget.disabled=!1,this.v2CaptchaResolver&&(this.v2CaptchaResolver(r),this.v2CaptchaResolver=null)}})}};o.targets=["submitButton"];let h=o;export{h as default}; 2//# sourceMappingURL=newsletter_signup_form_controller.CsGB0LPg.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.