(()=>{"use strict";const e="__DEBUG__",t="_pc_showpaywall";const n=(e,t=null)=>{var n,r;const o=`; ${document.cookie}`.split(`; ${e}=`);return 2===o.length?decodeURIComponent(null!==(n=null===(r=o.pop())||void 0===r?void 0:r.split(";").shift())&&void 0!==n?n:""):t};function r(e){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r(e)}function o(e){var t=function(e,t){if("object"!=r(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var o=n.call(e,t||"default");if("object"!=r(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==r(t)?t:t+""}function i(e,t,n){return(t=o(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}const s="/login",c=["Registration is a free and easy way to support our truly independent journalism"];const a="ssr-auth-state",l={foreground:31,background:41,light:"#AA0000",dark:"#ed4e4c"},u={foreground:33,background:43,light:"#AA5500",dark:"#d2c057"},d="light",g="dark",p=t=>t===e?"":`[${t.replace(/^_+|_+$/g,"")}]`,m=e=>`color: ${e};`,f=e=>("undefined"==typeof window||"function"!=typeof window.matchMedia?d:window.matchMedia("(prefers-color-scheme: dark)").matches?g:d)===g?e.dark:e.light,w=new Map,b=e=>{if("undefined"==typeof window)return"prod"!=={NODE_ENV:"production",npm_config_domain:""}.SERVER;if(!w.has(e)){var t;const n=new URLSearchParams(null===(t=window)||void 0===t||null===(t=t.location)||void 0===t?void 0:t.search);w.set(e,n.has(e))}return w.get(e)||"true"===n(e)};function h(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}let y;let v=0;const E=()=>{return"undefined"!=typeof window&&(void 0===y&&(y=!0===(null===(e=window.JSGlobals)||void 0===e||null===(e=e.featureFlags)||void 0===e?void 0:e.feat__sentry)),y);var e},O=(t,n)=>{const r=()=>b(e)||b(t),o=(e,t)=>{const r=n.filter(({tag:e})=>""!==e);if(0===r.length)return e;const o=r.map(({tag:e,color:n})=>{const r=null!=t?t:n,o=void 0!==r;return function(e){for(var t=1;te+t,""),u=o.filter(e=>"style"in e).map(({style:e})=>e);if("string"==typeof s){return"string"==typeof c&&c.includes("color")&&s.startsWith("%c")?[`${l} ${s}`,...u.concat(c),...a]:[l,...u,s,...e.slice(1)]}return[l,...u,...e]};return{log:(...e)=>{r()&&console.log(...v>0?e:o(e))},info:(...e)=>{r()&&console.info(...v>0?e:o(e))},group:(...e)=>{r()&&(console.group(...o(e)),v+=1)},groupCollapsed:(...e)=>{r()&&(console.groupCollapsed(...o(e)),v+=1)},groupEnd:(...e)=>{r()&&(v=Math.max(0,v-1),console.groupEnd(...e))},table:(...e)=>{r()&&console.table(...e)},warn:(...e)=>{var t;r()&&console.warn(...o(e,f(u))),E()&&(null===(t=window.Sentry)||void 0===t||t.captureException(...e))},error:(...e)=>{var t;r()&&console.error(...o(e,f(l))),E()&&(null===(t=window.Sentry)||void 0===t||t.captureException(...e))},extend:(e,r)=>O(t,[...n,{tag:e,color:r}]),logDate:e=>e.toLocaleString("en-GB",{timeZone:"UTC"})}},S=(({flagName:e,tagSegment:t={}})=>{const{tag:n,color:r}=t;return O(e,[{tag:null!=n?n:p(e),color:r}])})({flagName:e}),{log:_,info:P,warn:j,error:x,group:A,groupEnd:N,logDate:R}=S;let U;function T(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function D(e){for(var t=1;t{try{const t=e.split(".")[1].replace(/-/g,"+").replace(/_/g,"/"),n=decodeURIComponent(atob(t));return JSON.parse(n)}catch(e){return null}};function $(){if(void 0===globalThis.window)return null;const e=(()=>{var e;const t=null!==(e=n("esi_auth"))&&void 0!==e?e:"";return k(t)})();if(!e)return null;const{email:t,given_name:r,family_name:o,userStatus:i,pUid:s,exp:c,isAdFreeUser:a,isActiveRecurringDonator:l,adFreeExpiryTimestamp:u,recurringDonatorExpiryTimestamp:d,permutiveId:g}=e;return{email:t,givenName:r,familyName:o,userStatus:i,uid:s,exp:c,isAdFreeUser:a,isActiveRecurringDonator:l,adFreeExpiryTimestamp:u,recurringDonatorExpiryTimestamp:d,permutiveId:g}}const C="AUTHENTICATED";var G;function I(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}const L=Math.random().toString(36).slice(2),M={status:"ANONYMOUS",loading:!1,__id__:L},W=function(e){let t=e;const n=new Set;return{get:()=>t,set:e=>{t=e,n.forEach(e=>e(t))},patch:e=>{t=D(D({},t),e),n.forEach(e=>e(t))},subscribe:e=>(n.add(e),()=>n.delete(e))}}(null!==(G="undefined"!=typeof window?function(e=document){if(void 0===e)return null;if(void 0!==U)return U;const t=e.getElementById(a),n=null==t?void 0:t.textContent;let r=null;try{if(!n)throw new Error("No auth snapshot found in DOM");r=JSON.parse(atob(n))}catch(e){_(e)}finally{var o;null===(o=document.getElementById(a))||void 0===o||o.remove()}return U=r,r}(document):void 0)&&void 0!==G?G:M),F={__id__:L,get:W.get,subscribe:W.subscribe,actions:{set:W.set,patch:W.patch,login:e=>{W.patch({loading:!0});const t=new URL(s,window.location.origin);e&&t.searchParams.set("returnPath",e),window.location.href=t.toString()},logout:async()=>{W.patch({loading:!0});try{await fetch("/user/logout",{credentials:"include"})}finally{W.set(M)}},loadProfile:()=>{const e=$();e?W.patch(function(e){for(var t=1;t{const{status:e}=F.get();return e===C};const B=(e,{async:t=!0,defer:n=document.location.search.includes("___FORCE_DEFER___"),parent:r=document.body,attributes:o}={})=>{window.JSGlobals=window.JSGlobals||{};const i=window.JSGlobals.loadedJS=[];return new Promise((s,c)=>{const a=(e instanceof Array?e:[e]).map(e=>i.includes(e)?Promise.resolve():new Promise((s,c)=>{const a=((e,{id:t,async:n,defer:r,ok:o,error:i,attributes:s})=>{const c=document.createElement("script");return c.onload=o,c.onerror=i,t&&"undefined"!==t&&(c.id=t),n&&!r&&c.setAttribute("async",""),r&&c.setAttribute("defer",""),s&&s.forEach(([e,t])=>{c.setAttribute(e,t)}),c.src=e,c})(e,{async:t,defer:n,ok:s,error:c,attributes:o});r.appendChild(a),i.push(e)}));return Promise.all(a).then(s,c)})},V=(e,t={})=>{const n=JSON.stringify(t,null,2),r=n.split("\n").reduce((e,t)=>t.length>=e?t.length:e,0),o=e.length,i=Math.max(o,r),s=` ${e.padEnd(i)} `,c=n.split("\n").map(e=>` ${e.padEnd(i)} `),a=c.length>1?`%c${c.slice(0,1)}\n%c${c.slice(1,-1).join("\n")}\n%c${c.slice(-1)}\n`:`%c${c[0]}\n`,l=c.length>1?["font-family:monospace; background: #333; color: #eee; padding-top: 5px;","font-family:monospace; background: #333; color: #eee;","font-family:monospace; background: #333; color: #eee; padding-bottom: 10px; border-radius: 0 0 6px 6px"]:["font-family:monospace; background: #333; color: #eee; padding-top: 5px; padding-bottom: 10px; border-radius: 0 0 6px 6px"];console.log(`%c${s}\n${a}`,"font-family:monospace; background: #333; color: #eee; border-bottom: 1px solid #666; padding: 5px 0; border-radius: 6px 6px 0 0",...l)},H=(e,t,n={})=>{const r=new URLSearchParams;return r.set("__amp_source_origin",window.location.origin),Object.keys(n).forEach(e=>{r.set(e,n[e])}),fetch(`/internal-api/${e}?${r.toString()}`,t)},Y=(e,t)=>H(e,{method:"GET"},t),q={};q.promise=new Promise(e=>{q.resolve=e});const K=(e,t,n)=>(e=>{const t=document.createElement("a");return t.href=e,"https:"===t.protocol&&/(^|\.)google\.(com?|[a-z]{2}|com?\.[a-z]{2}|cat)$/.test(t.hostname)})(e)&&((e,t)=>{if(!(e.gaa_at&&e.gaa_n&&e.gaa_sig&&e.gaa_ts))return!1;const n=Number.parseInt(e.gaa_ts,16);return!(!Number.isFinite(n)||n{const t={};return new URLSearchParams(e).forEach((e,n)=>{t[n]=e}),t})(t),n),z=e=>{try{const e=new URL(window.location.href);e.searchParams.set("referrer",document.referrer),sessionStorage.setItem("cb",encodeURIComponent(e.toString()))}catch(e){_("signinOrRegisterUser: failed to set sessionStorage cb",e)}const t=null!=e?e:`${window.location.origin}/google-auth`;window.location.href=t};"true"===n(t)?(_("entitlement: ","EVENT_SHOWCASE_NO_ENTITLEMENTS_PAYWALL"," , isUserRegistered: ",!0),Promise.resolve()):new Promise(e=>{if(!K(document.referrer,window.location.search,Date.now()))return e();const r=`${window.location.origin}/iframe/registration_widget`;B(["https://accounts.google.com/gsi/client"]);const o=B(["https://news.google.com/swg/js/v1/swg.js"],{attributes:[["subscriptions-control","manual"]]}),i=(async()=>{try{await o,await B(["https://news.google.com/swg/js/v1/swg-gaa.js"])}catch(t){V("[extendedAccess] Failed to load SWG scripts — resolving",{error:t}),e()}})();(window.SWG=window.SWG||[]).push(async o=>{var s,c;const a=({entitlement:e,isUserRegistered:t})=>{o.setShowcaseEntitlement({entitlement:e,isUserRegistered:t}),_("entitlement",{entitlement:e,isUserRegistered:t})};if(o.init(null===(s=window.JSGlobals)||void 0===s?void 0:s.showcaseProductId),o.setOnNativeSubscribeRequest(()=>{V("[extendedAccess] Native subscribe action triggered"),localStorage.setItem("returnUrl",window.location.href),window.location.href="/subscribe"}),null===(c=window.JSGlobals)||void 0===c||null===(c=c.article)||void 0===c||!c.premium)return a({entitlement:"EVENT_SHOWCASE_UNLOCKED_FREE_PAGE",isUserRegistered:J()}),e();const l=await(async()=>{try{const e=await Y("fetch-user-state");return await e.json()}catch(e){return{}}})();if(l.metering)V("[extendedAccess] Piano user state received"),o.setOnEntitlementsResponse(async r=>{const o=await Promise.race([q.promise,new Promise(e=>setTimeout(()=>{V("[extendedAccess] Piano meter timed out — treating as expired"),e(!0)},5e3))]),{hasAccess:i,subscribed:s}=(e=>{const t="true"===n("subscriber");return{hasAccess:t||!1===e,subscribed:t}})(o);if(i)a(s?{entitlement:"EVENT_SHOWCASE_UNLOCKED_BY_SUBSCRIPTION",isUserRegistered:!0}:{entitlement:"EVENT_SHOWCASE_UNLOCKED_BY_METER",isUserRegistered:!0}),V("[extendedAccess] Publisher grants access — skipping Google intervention"),e();else{V("[extendedAccess] No publisher access — checking Google entitlements");const n=await r;n.enablesThisWithGoogleMetering()?(V("[extendedAccess] Google metering entitlement active — consuming"),n.consume(()=>{})):(((e,t,n)=>{const r=new Date;if(n&&(n.days||n.hours)){const e=n.days?24*n.days*60*60*1e3:60*n.hours*60*1e3;r.setTime(r.getTime()+e)}const o=[];o.push(`${e}=${encodeURIComponent(t)}`),o.push("path=/"),o.push("secure"),n&&o.push(`expires=${r.toUTCString()}`),document.cookie=o.join(";")})(t,"true",{hours:1}),a({entitlement:"EVENT_SHOWCASE_NO_ENTITLEMENTS_PAYWALL",isUserRegistered:!0}),V("[extendedAccess] No entitlements — showing paywall"),window.location.reload()),e()}}),o.getEntitlements(l);else{var u;if(V("[extendedAccess] No Piano user state — user not signed in"),await i,!window.GaaMeteringRegwall)return V("[extendedAccess] GaaMeteringRegwall not available — skipping regwall"),e();const t=()=>{V("[extendedAccess] Regwall login request — redirecting to /login"),z("/login")};setTimeout(()=>{var e;null===(e=document.getElementById("swg-publisher-sign-in-button"))||void 0===e||e.addEventListener("click",e=>{e.preventDefault(),t()})},0),null===(u=document.getElementById("footerPrompt"))||void 0===u||u.classList.add("hide"),window.GaaMeteringRegwall.show({iframeUrl:r,onLoginRequest:t}).then(()=>{z()}).catch(t=>{V("[extendedAccess] Error showing GaaMeteringRegwall",{error:t}),e()})}})})})();