(()=>{"use strict";var e,t,n,i={59897(e,t,n){var i=n(72397),r=n(34357),o=n(712),a=n(16082),s=n(36267);window.newspackRAS=window.newspackRAS||[],window.newspackRAS.push(function(e){const t=(e="otp",t={})=>{(0,r.eK)({skipAuthenticatedCheck:!0,skipNewslettersSignup:!0,backButtonClosesModal:!0,initialState:e,closeOnSuccess:!0,skipSuccess:!1,onClose:()=>window.location.reload(),...t})},n=()=>{(0,s.au)({onSuccess:()=>window.location.reload(),onDismiss:()=>window.location.reload(),closeOnSuccess:!0,signupMethod:"reader-registration"})},c=()=>{t("otp",{onClose:null,onSuccess:n,onDismiss:n})};(0,i.Qc)(function(){[...document.querySelectorAll(".newspack__reader-verification")].filter(e=>!e.querySelector(".newspack-ui__modal-container")).forEach(n=>{const i=n.querySelector("[data-send-otp]");i&&i.addEventListener("click",()=>{i.disabled=!0,(()=>{const t=new FormData;return t.set("action","newspack_reader_registration_verification"),t.set("nonce",reader_registration_block_config.verification_nonce),fetch(reader_registration_block_config.verification_url,{method:"POST",headers:{Accept:"application/json"},body:t}).then(t=>{if(!t.ok)throw new Error(t.statusText);return e.setOTPTimer(),t.json()})})().then(()=>{t("otp")}).catch(()=>{i.disabled=!1,i.textContent=i.textContent.trim();const e=n.querySelector("p:not(:has(button))");e&&(e.textContent="Something went wrong. Please try again.")})})}),document.querySelectorAll(".newspack-registration").forEach(i=>{const r=i.querySelector("form");if(!r)return;let s=new FormData(r),l=!1;const d=i.querySelector(".newspack-registration__response"),p=r.querySelector('button[type="submit"]'),u=document.createElement("span");u.classList.add("spinner"),r.startLoginFlow=()=>{d.classList.add("newspack-registration--hidden"),d.innerHTML="",p.disabled=!0,p.appendChild(u),i.classList.add("newspack-registration--in-progress")},r.endLoginFlow=(a=null,g=500,h=null)=>{if(l)return;let f;if(h?.existing_user&&!h?.authenticated&&h?.action){const n=h.email||r.npe?.value;if(p.contains(u)&&p.removeChild(u),p.disabled=!1,i.classList.remove("newspack-registration--in-progress"),e.setReaderEmail(n),"otp"===h.action){if(e.getOTPHash())e.setOTPTimer(),t("otp");else{const i=new FormData;i.set("reader-activation-auth-form","1"),i.set("npe",n),i.set("action","link"),fetch(r.getAttribute("action")||window.location.pathname,{method:"POST",headers:{Accept:"application/json"},body:i}).then(n=>{200===n.status?(e.setOTPTimer(),t("otp")):t("signin")}).catch(()=>t("signin"))}return}return void t(h.action)}const m=!h?.existing_user&&newspack_ras_config.verify_new_reader_accounts&&!0!==h?.verified,_=i.querySelector(".newspack-registration__registration-success");if(_?.classList.add("newspack-registration--hidden"),a){f=document.createElement("p"),f.textContent=a;const e=_?.querySelector("p");e&&h?.sso&&e.replaceWith(f)}const w=200===g;if(i.classList.add("newspack-registration--"+(w?"success":"error")),w){if(l=!0,m||h?.existing_user||(r.remove(),_.classList.remove("newspack-registration--hidden")),h?.email&&(s=new FormData(r),e.setReaderEmail(h.email),e.setAuthenticated(h?.authenticated),m&&(h.verification_nonce&&(reader_registration_block_config.verification_nonce=h.verification_nonce),(0,o.F)({email:h.email,verificationNonce:reader_registration_block_config.verification_nonce,setOTPTimer:e.setOTPTimer,onSendCode:c,onDismiss:n})),h.authenticated&&!m)){const t={email:h.email},n=s.getAll("lists[]");s.has("newspack_popup_id")&&(t.newspack_popup_id=s.get("newspack_popup_id")),s.has("gate_post_id")&&(t.gate_post_id=s.get("gate_post_id")),h?.sso&&(t.sso=!0),n?.length&&e.dispatchActivity("newsletter_signup",{...t,newsletters_subscription_method:"reader-registration",lists:n}),h?.existing_user?e.dispatchActivity("reader_logged_in",{...t,login_method:h?.metadata?.login_method||"registration-block"}):e.dispatchActivity("reader_registered",{...t,registration_method:h?.metadata?.registration_method||"registration-block"})}}else f&&(d.appendChild(f),d.classList.remove("newspack-registration--hidden"));p.contains(u)&&p.removeChild(u),p.disabled=!1,i.classList.remove("newspack-registration--in-progress")},r.addEventListener("submit",e=>(e.preventDefault(),r.startLoginFlow(),r.npe?.value?(s=new FormData(r),s.has("npe")&&s.get("npe")?void(0,a.E)({email:s.get("npe"),onProceed:()=>{fetch(r.getAttribute("action")||window.location.pathname,{method:"POST",headers:{Accept:"application/json"},body:s}).then(e=>{e.json().then(({message:t,data:n})=>r.endLoginFlow(t,e.status,n)).catch(()=>r.endLoginFlow("An error occurred.",e.status||400))}).catch(e=>{r.endLoginFlow(e?.message||"An error occurred.",400)})},onCancel:()=>{l=!1,p.contains(u)&&p.removeChild(u),p.disabled=!1,i.classList.remove("newspack-registration--in-progress")}}):r.endLoginFlow("Please enter a valid email address.",400)):r.endLoginFlow("Please enter a valid email address.",400))),e.on("reader",({detail:e})=>{e.authenticated&&!l&&r.endLoginFlow(null,200,{existing_user:!0})})})})})}},r={};function o(e){var t=r[e];if(void 0!==t)return t.exports;var n=r[e]={id:e,loaded:!1,exports:{}};return i[e](n,n.exports,o),n.loaded=!0,n.exports}o.m=i,e=[],o.O=(t,n,i,r)=>{if(!n){var a=1/0;for(d=0;d=r)&&Object.keys(o.O).every(e=>o.O[e](n[c]))?n.splice(c--,1):(s=!1,r0&&e[d-1][2]>r;d--)e[d]=e[d-1];e[d]=[n,i,r]},o.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return o.d(t,{a:t}),t},n=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__,o.t=function(e,i){if(1&i&&(e=this(e)),8&i)return e;if("object"==typeof e&&e){if(4&i&&e.__esModule)return e;if(16&i&&"function"==typeof e.then)return e}var r=Object.create(null);o.r(r);var a={};t=t||[null,n({}),n([]),n(n)];for(var s=2&i&&e;("object"==typeof s||"function"==typeof s)&&!~t.indexOf(s);s=n(s))Object.getOwnPropertyNames(s).forEach(t=>a[t]=()=>e[t]);return a.default=()=>e,o.d(r,a),r},o.d=(e,t)=>{for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),o.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},o.nmd=e=>(e.paths=[],e.children||(e.children=[]),e),o.j=2636,(()=>{var e;globalThis.importScripts&&(e=globalThis.location+"");var t=globalThis.document;if(!e&&t&&(t.currentScript&&"SCRIPT"===t.currentScript.tagName.toUpperCase()&&(e=t.currentScript.src),!e)){var n=t.getElementsByTagName("script");if(n.length)for(var i=n.length-1;i>-1&&(!e||!/^http(s?):/.test(e));)e=n[i--].src}if(!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),o.p=e})(),(()=>{var e={2636:0};o.O.j=t=>0===e[t];var t=(t,n)=>{var i,r,[a,s,c]=n,l=0;if(a.some(t=>0!==e[t])){for(i in s)o.o(s,i)&&(o.m[i]=s[i]);if(c)var d=c(o)}for(t&&t(n);lo(59897));a=o.O(a)})();