import{x as O,r as v,w as D,o as P,l as i,j as k,k as _,z as p,i as j,as as C,B as z,E as T,q as G}from"./BGddUaGe.js";const H={class:"relative max-w-full mx-8 group max-h-1/3"},W=["href","target"],q=["src","alt"],B=O({__name:"index",props:{config:{}},async setup(S){var y,w;let a,m;const b=S,f=v(),d=new Date,r=v(!1),N=`https://promo-overlays.cms.web.gc.${b.config.public.servicesURL}/v1/promo-overlays/?channel=Web`,o=v();try{const e=([a,m]=D(()=>fetch(N)),a=await a,m(),a);f.value=((y=([a,m]=D(()=>e==null?void 0:e.json()),a=await a,m(),a))==null?void 0:y.body)||[]}catch{console.error("Failed to fetch promo overlays"),r.value=!1}const c=(w=f.value)==null?void 0:w.filter(e=>{const t=new Date(e.startDateTime),s=new Date(e.endDateTime);return td});P(()=>{if(!(c!=null&&c.length))return;J();const e=localStorage.getItem("overlayPromos");if(e===null)return o.value=c[0],void(r.value=!0);const t=JSON.parse(e||""),s=t.map(n=>n.promoID),u=c.filter(n=>!s.includes(n.promoID));if(o.value=u[0],u.length)return o.value=u[0],void(r.value=!0);const l=new Date;l.setHours(l.getHours()-4);const g=t.filter(n=>l>new Date(n.date));if(!g.length)return;const x=t.findIndex(n=>n.promoID===g[0].promoID),I=[...t];x!==-1&&I.splice(x,1),localStorage.setItem("overlayPromos",JSON.stringify(I)),o.value=g[0],r.value=!0});const J=()=>{const e=localStorage.getItem("overlayPromos");if(!e)return;const t=JSON.parse(e),s=c.map(l=>l.promoID),u=t.filter(l=>s.includes(l.promoID));localStorage.setItem("overlayPromos",JSON.stringify(u))},h=()=>{const e=localStorage.getItem("overlayPromos");if(e===null)return localStorage.setItem("overlayPromos",JSON.stringify([{...o.value,date:new Date}])),void(r.value=!1);const t=JSON.parse(e);t.push({...o.value,date:new Date}),localStorage.setItem("overlayPromos",JSON.stringify(t)),r.value=!1};return(e,t)=>{const s=T;return i(r)&&i(o)?(k(),_("div",{key:0,class:"w-screen h-screen fixed left-0 top-0 bg-primary-950/60 z-[150] flex items-center justify-center",onClick:h},[p("div",H,[p("a",{href:i(o).url,target:i(o).webNewWindow==1?"_blank":"_self"},[p("img",{src:("useGCImage"in e?e.useGCImage:i(j))(!0,720,720,i(o).imageKey),alt:i(o).imageAltText,class:"transition duration-150 group-hover:brightness-90"},null,8,q)],8,W),p("div",{class:"absolute -top-[25px] -right-[25px] sm:-top-[16px] sm:-right-[16px] text-white bg-slate-800 rounded-full flex items-center justify-center w-[50px] h-[50px] sm:w-[32px] sm:h-[32px] shadow hover:bg-slate-700 cursor-pointer transition duration-150",onClick:C(h,["stop"])},[z(s,{pack:"navigation",icon:"close",size:"16"})])])])):G("",!0)}}});export{B as _};