import{e,u as t,g as n,h as r,i as o,j as a}from"./vendor-DH-HcC7C.js";import{s as l,g as i}from"./cookies-Btke1V1y.js";const s=e({name:"vanilla",initialState:{isArticle:!1},reducers:{setIsArticle:(e,t)=>{e.isArticle=t.payload}}}),c={pageChange:!1,page:{title:null,url:null,region:"",type:null,category:null,tags:[],number:null,countryCode:null,index:null},site:{region:"",brand:null,countryCode:null},content:{article:{verticals:null,subVerticals:null,language:null,authors:null,id:null,publishDate:{year:null,month:null,day:null},updateDate:{year:null,month:null,day:null},cmsCategory:null,cmsChildcategory:null,cmsGrandchildCategory:null}},product:{primary:{name:null,brand:null,category:null},secondary:{products:[],brands:[]},source:""}};function d(e,t){const n=structuredClone(e);return u(n,t),n}function u(e,t){if(t)for(const n of Object.keys(t)){const r=t[n];r&&"object"==typeof r&&!Array.isArray(r)?(e[n]||(e[n]={}),u(e[n],r)):e[n]=r}}const g=e({name:"analytics",initialState:{freyrData:c},reducers:{setFreyrData(e,t){e.freyrData=d(c,t.payload)},updateCountryCode(e,t){e.freyrData.page.countryCode=t.payload,e.freyrData.site.countryCode=t.payload},addFreyrTags(e,t){const n=e.freyrData.page.tags,r=t.payload,o=Array.from(new Set([...n,...r]));e.freyrData.page.tags=o},updateDfpData(e,t){const{cmsCategory:n,cmsChildcategory:r,cmsGrandchildCategory:o}=t.payload;e.freyrData.content.article={...e.freyrData.content.article,cmsCategory:n,cmsChildcategory:r,cmsGrandchildCategory:o}}}}),{setFreyrData:p,addFreyrTags:v,updateCountryCode:y,updateDfpData:m}=g.actions,w=e({name:"sponsoredScroll",initialState:{articleUrl:"",articleDocumentTitle:"",sponsorArticleID:"",articlesData:{}},reducers:{setArticleUrl:(e,t)=>{e.articleUrl=t.payload},setArticleDocumentTitle:(e,t)=>{e.articleDocumentTitle=t.payload},setSponsorArticleID:(e,t)=>{e.sponsorArticleID=t.payload},setArticlesData:(e,t)=>{e.articlesData={...e.articlesData,...t.payload}}}});let f={vanillaSession:null,loggedIn:!1,hybridId:null,kiosqId:null,userGrantStatus:null,blueConicId:null,gaClientId:null,gclid:null,sha256_email_address:null,screenWidth:null,browser:{type:null,family:null,version:null,major_version:null},os:{name:null,version:null},device:{model:null,vendor:null},cpu:{architecture:null}};const h=()=>{const e=(new Date).getTime()+18e5;return new Date(e)},C=()=>{const e=i("FTR_Vanilla_Session_ID"),n=i("FTR_Vanilla_User_Is_Active");if(e&&n)return e;const r=t();return l({name:"FTR_Vanilla_Session_ID",value:r,path:"/",secure:!0}),r},b=n("freyr/sendEventToFreyr"),T=e=>e=>t=>{if(b.match(t)){const{name:e,eventObject:n}=t.payload;window.freyr?(window.freyr.cmd.push((()=>{window.freyr.pushAndUpdate(e,{...n})})),l({name:"FTR_Vanilla_User_Is_Active",value:"is_active",expireDate:h(),path:"/",secure:!0})):console.warn("[Freyr Middleware] Freyr is not initialized yet. Cannot send event.")}return e(t)},D=e=>t=>n=>{var r,o;const a=t(n);if(p.match(n)){const t=i("FTR_Country_Code")??i("FTR_User_Defined_Country_Code")??"";if(t&&e.dispatch(y(t)),window.dfp_config){const t=e=>{var t;return(null==(t=window.dfp_config)?void 0:t[e])||null},n={cmsCategory:t("category"),cmsChildcategory:t("child_category"),cmsGrandchildCategory:t("grandchild_category")};e.dispatch(m(n))}const a=!!(null==(o=null==(r=null==window?void 0:window.FUTR)?void 0:r.Kiosq)?void 0:o.User);(()=>{let e=C();(e=>{window.bordeaux&&window.bordeaux.cmd.push((()=>{window.bordeaux.setTargeting({vanillaSession:e})}))})(e),f.vanillaSession=e})();const{pageChange:l,...s}=n.payload;e.dispatch(A.freyr.sendEventToFreyr({name:l?"pageChangedEvent":"pageLoadEvent",eventObject:{...s,user:{loggedIn:a}}}))}return a},S=e({name:"player",initialState:{players:{}},reducers:{markJWEventOccurred:(e,t)=>{const{divID:n,event:r}=t.payload;e.players[n]={...e.players[n],[r]:!0}}}}),L=e({name:"tabNotifications",initialState:{count:0},reducers:{incrementCount:e=>{e.count++},decrementCount:e=>{e.count--},setCount(e,t){e.count=t.payload}}}),_=e({name:"viafouraComments",initialState:{useRestrictedCommentWidgetHeight:!1},reducers:{setUseRestrictedCommentWidgetHeight(e,t){e.useRestrictedCommentWidgetHeight=t.payload}}}),A={vanilla:s.actions,analytics:g.actions,tabNotifications:L.actions,sponsoredScroll:w.actions,viafouraComments:_.actions,player:S.actions,freyr:{sendEventToFreyr:b}};function I(e){const[t,n]=e.split(".");return function(e){return e in A}(t)?function(e,t){return t in A[e]}(t,n)?A[t][n]:(console.warn(`Unknown action: ${e}`),null):(console.warn(`Unknown reducer: ${t}`),null)}const F={},E={LCP:{needsImprovement:2500,poor:4e3},INP:{needsImprovement:200,poor:500},CLS:{needsImprovement:.1,poor:.25}},P=(e,t)=>{const n=E[e];return t>n.poor?"poor":t>n.needsImprovement?"needs-improvement":null},R=(...e)=>{console.log("[CWV]",...e)},N=r();let U=!1;N.startListening({matcher:o(g.actions.setFreyrData),effect:async(e,t)=>{if(U)return;U=!0;const n=(()=>{var e,t,n,r,o,a,l,i,s;const c=new URLSearchParams(location.search),d="1"===c.get("cwvLog")||Boolean(null==(n=null==(t=null==(e=null==window?void 0:window.vanilla)?void 0:e.featureFlags)?void 0:t.coreWebVitalsThresholdMonitoring)?void 0:n.logger),u=c.get("cwvLogMode");return{enabled:d,mode:"all"===u||"violations"===u?u:"all",metrics:((e,t)=>{if(!e)return["LCP","INP","CLS"];const n=e.split(",").map((e=>e.trim().toUpperCase())),r=["LCP","INP","CLS"];return n.filter((e=>r.includes(e)))})(c.get("cwvLogMetrics")),showAttribution:"1"===c.get("cwvLogAttr")||Boolean(null==(a=null==(o=null==(r=null==window?void 0:window.vanilla)?void 0:r.featureFlags)?void 0:o.coreWebVitalsThresholdMonitoring)?void 0:a.loggerAttr),showEmits:"1"===c.get("cwvLogEvent")||Boolean(null==(s=null==(i=null==(l=null==window?void 0:window.vanilla)?void 0:l.featureFlags)?void 0:i.coreWebVitalsThresholdMonitoring)?void 0:s.loggerEvent)}})(),r=Boolean(null==(l=null==(a=null==(o=window.vanilla)?void 0:o.featureFlags)?void 0:a.coreWebVitalsThresholdMonitoring)?void 0:l.enabled);var o,a,l;const i=(()=>{const e=navigator.userAgent.toLowerCase();return/bot|crawler|spider|lighthouse|pagespeed|speedcurve|headless/.test(e)})(),s=(()=>{var e;const t=(null==(e=window.PerformanceObserver)?void 0:e.supportedEntryTypes)||[];return{types:t,lcp:t.includes("largest-contentful-paint"),cls:t.includes("layout-shift"),inp:t.includes("event")}})();if(!r&&!n.enabled)return;if(i&&r&&!n.enabled)return;if(r){const e=(()=>{var e,t,n;const r=null==(n=null==(t=null==(e=null==window?void 0:window.vanilla)?void 0:e.featureFlags)?void 0:t.coreWebVitalsThresholdMonitoring)?void 0:n.sampleRate,o=Number(r);return Number.isFinite(o)?o:1})();if(Math.random()>e)return;n.enabled&&R("listener start",{flagOn:r,sampleRate:e,bot:i,support:s,cfg:n})}else n.enabled&&R("listener start",{flagOn:r,sampleRate:1,bot:i,support:s,cfg:n});const c=r;try{const{onLCP:e,onINP:t,onCLS:r}=await function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){document.getElementsByTagName("link");const e=document.querySelector("meta[property=csp-nonce]"),n=(null==e?void 0:e.nonce)||(null==e?void 0:e.getAttribute("nonce"));r=Promise.allSettled(t.map((e=>{if((e=function(e){return"/"+e}(e))in F)return;F[e]=!0;const t=e.endsWith(".css"),r=t?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${e}"]${r}`))return;const o=document.createElement("link");return o.rel=t?"stylesheet":"modulepreload",t||(o.as="script"),o.crossOrigin="",o.href=e,n&&o.setAttribute("nonce",n),document.head.appendChild(o),t?new Promise(((t,n)=>{o.addEventListener("load",t),o.addEventListener("error",(()=>n(new Error(`Unable to preload CSS for ${e}`))))})):void 0})))}function o(e){const t=new Event("vite:preloadError",{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then((e=>{for(const t of e||[])"rejected"===t.status&&o(t.reason);return(async()=>{const{onLCP:e,onINP:t,onCLS:n}=await import("./vendor-DH-HcC7C.js").then((e=>e.w));return{onLCP:e,onINP:t,onCLS:n}})().catch(o)}))}(0,[]),o={LCP:null,INP:null,CLS:null},a=(e,t)=>{const n=e.name,r={metric:n,value:e.value,rating:e.rating,threshold:t,id:e.id,delta:e.delta,navigationType:e.navigationType,pageUrl:location.href,userAgent:navigator.userAgent,thresholds:E[n]};if("LCP"===n){const t=(e=>{if(!e)return;const{target:t,url:n,timeToFirstByte:r,resourceLoadDelay:o,resourceLoadDuration:a,elementRenderDelay:l}=e;return{target:t,element:t,url:n,timeToFirstByte:r,resourceLoadDelay:o,resourceLoadDuration:a,elementRenderDelay:l}})(e.attribution),n={...t,lcpElement:(null==t?void 0:t.target)??(null==t?void 0:t.element)};return{...r,metric:"LCP",attribution:n}}if("INP"===n){const t=(e=>{if(!e)return;const{interactionTarget:t,eventType:n}=e;return{interactionTarget:t,eventType:n,loadState:e.loadState??e.interactionLoadState}})(e.attribution),n={...t,inpEventTarget:null==t?void 0:t.interactionTarget};return{...r,metric:"INP",attribution:n}}const o=(e=>{if(!e)return;const{largestShiftTarget:t}=e;return{largestShiftTarget:t}})(e.attribution);return{...r,metric:"CLS",attribution:o}},l=e=>{var t;const r=e.name;((e,t,n,r,o)=>{if(!((e,t,n)=>!(!e.enabled||!e.metrics.includes(t)||"all"!==e.mode&&null===P(t,n)))(e,t,n))return;const a=P(t,n),l=E[t],i="LCP"===t?{target:null==o?void 0:o.target,url:null==o?void 0:o.url}:"INP"===t?{interactionTarget:null==o?void 0:o.interactionTarget,eventType:null==o?void 0:o.eventType}:{largestShiftTarget:null==o?void 0:o.largestShiftTarget},s=`${t} value=${((e,t)=>"CLS"===e?t.toFixed(3):Math.round(t).toString())(t,n)} rating=${r} label=${a??"good"}`;R(s,l),e.showAttribution&&o&&R("attribution",i)})(n,r,e.value,e.rating,e.attribution);const l=P(r,e.value);if(!l)return;if(o[r]===e.value)return;o[r]=e.value;const i=a(e,l);((e,t,n)=>{e.enabled&&e.showEmits&&R("[emit]",t,n)})(n,r,i),c&&(null==(t=window.dispatchOrQueueAction)||t.call(window,"freyr.sendEventToFreyr",{name:"coreWebVitalsThresholdEvent",eventObject:i}))},i=1e3;let s,d=null;const u=()=>{d&&(s&&(window.clearTimeout(s),s=void 0),l(d))};e((e=>l(e)),{reportAllChanges:!0}),t((e=>l(e)),{reportAllChanges:!0,durationThreshold:0}),r((e=>{d=e,s&&window.clearTimeout(s),s=window.setTimeout((()=>l(e)),i)}),{reportAllChanges:!0}),document.addEventListener("visibilitychange",(()=>{"hidden"===document.visibilityState&&u()})),window.addEventListener("pagehide",u)}catch(e){console.warn("[webVitalsListener] Failed to init web-vitals/attribution",e)}}});const V=e=>e=>t=>e(t),W=a({reducer:{vanilla:s.reducer,analytics:g.reducer,tabNotifications:L.reducer,sponsoredScroll:w.reducer,viafouraComments:_.reducer,player:S.reducer},middleware:e=>e().concat(V,N.middleware,T,D)});if("undefined"!=typeof window&&(window.reduxStore=W,window.Actions=A,window.actionQueue&&window.actionQueue.length)){for(const e of window.actionQueue){const t=I(e.action);if(t)try{const n=t(e.payload);window.reduxStore.dispatch(n),"analytics.setFreyrData"===e.action&&delete window.freyrData}catch(t){console.error(`Error dispatching action ${e.action}:`,t)}}window.actionQueue=[]}export{W as r};