import Oe from"./6EfHtELg.js";import{_ as Ie}from"./m5zQ9WEL.js";import xe from"./CR9r3yd4.js";import Te from"./DRcdeDYN.js";import De from"./Bc79wfWL.js";import ke from"./axcvKtZU.js";import Ce from"./DyCHKxtu.js";import{d as Be,u as $e,a as Ee,ba as Ne,b as Se,r as D,j as k,e as v,q as z,V as G,w as Fe,s as Ae,b8 as Me,R as Pe,f as l,h as c,x as y,t as C,i as f,C as X,g as r,A as Le,v as b,F as Q,y as Ve,B as J,T as He,G as Re,H as We,bb as je,c as qe,o as i,aW as Ke,a6 as Y,bc as Ue,bd as ze,n as Z,_ as Ge}from"./BxiWQxwE.js";import{u as Xe}from"./RCUkGZbE.js";import{u as Qe}from"./C0u-A3aK.js";import{u as Je}from"./BuMsBOrl.js";import"./CAp4q4jQ.js";import"./Dl6s6BfE.js";import"./Bo9XA6rV.js";import"./Ci7sx34z.js";import"./BtFqvK5V.js";import"./DXn7UZRN.js";import"./4HfP1VOY.js";import"./QMEN6lyk.js";import"./CxeYIrhH.js";import"./CMsHgkl0.js";const Ye={class:"container"},Ze={class:"offers__folder"},et={key:0,class:"banners"},tt={class:"banners__container"},ot={class:"offers"},nt={class:"offers__products"},rt={key:0},st={key:1,class:"offers__no-results"},at={key:1,class:"error"},it="offers_extra_section",ct=Be({__name:"overview",props:{offerType:{type:String,required:!0}},async setup(B){var H;let g,$;const p=B,ee=["imageWithLink","bannerXl","bannerM"],E=$e(),{$gtm:te,$messages:d}=Ee(),{hide:oe}=Ne(),{getSectionByName:N}=Xe(),{mapOfferToProductCard:ne,filterOffersOnProducts:S,mapOfferToListItem:re}=Se(),{listOffersByDate:se,listOffersBySectionByDate:ae}=Qe(),{handleMultiProduct:ie,currentMultiProduct:ce}=Je(),m=D(!1),F=N("header"),le=e=>{var o;let t=null;return(o=u.value)==null||o.forEach(n=>{n.forEach(s=>{s.offerId===e&&(t=s)})}),t};k(async()=>{const e=E.query.aanbieding;if(O.value&&(m.value=!0),typeof e=="string"){const t=e==null?void 0:e.split(/[?&]/)[0],[o,n]=(t==null?void 0:t.split("-"))??[];if(o&&n&&!isNaN(Number(o))&&!isNaN(Number(n))){const h=document.getElementById(o);h&&scrollTo({top:h.getBoundingClientRect().top-120-60});const T=le(Number(n));ce.value=ne(T),setTimeout(()=>document.body.classList.add("locked"),50)}else console.warn("Invalid aanbieding format, expected `departmentId-productId`.")}});const fe=async e=>{e==="currentOffers"?await Z("/aanbiedingen"):await Z("/aanbiedingen/volgende-week")},de=e=>ee.includes(e),A=v(()=>{var e;return((e=N("uitgelicht"))==null?void 0:e.items.map((t,o)=>{const n=de(String(t.alias))?t:Ue(t);return{index:o,controls:n,itemId:t.id,alias:t.alias,type:t.alias?ze(t.alias):void 0,isDepartment:!!(n!=null&&n.department),isTopOffer:t.alias===it}}))??[]}),w=((H=A.value)==null?void 0:H.filter(e=>{var t,o;return!!((o=(t=e.controls)==null?void 0:t.title)!=null&&o.value)}))??[],M=z(`${We}-storeId`),P=z(je),ue=G().public.defaultStoreId,L=v(()=>{var e;return((e=M.value)==null?void 0:e.storeId)??ue}),pe=async e=>{var t;try{const o=(t=P.value)==null?void 0:t.dateTime.split("T")[0],n=await me(e,o);return n?n.listOffersByDate||n.listOffersBySectionByDate||[]:[]}catch(o){throw console.error("Failed to fetch future offers:",o),new Error(d("offers.cmsFutureDialog.error"))}},me=async(e,t)=>{var n,s;const o=Number((s=(n=e.controls)==null?void 0:n.department)==null?void 0:s.associatedValue);return o?await se(o,t,p.offerType):await ae(e.itemId,t,p.offerType)},_e=async e=>{var n,s;const t=Number((s=(n=e.controls)==null?void 0:n.department)==null?void 0:s.associatedValue);return t?await $fetch(`/api/offers/${L.value}/${p.offerType}/department/${t}`,{headers:Y()}):await $fetch(`/api/offers/${L.value}/${p.offerType}/section/${e.itemId}`,{headers:Y()})},{data:u,error:O,refresh:ve}=([g,$]=Fe(async()=>qe(`offers-overview-${E.path}`,async()=>{const e=await Promise.all(w.map(n=>P.value?pe(n):_e(n)));return(Array.isArray(e)?e.filter(Boolean):[]).map(n=>S(n[p.offerType]))})),g=await g,$(),g);Ae(()=>M.value,async()=>await ve(),{deep:!0});const I=v(()=>w.filter((e,t)=>{var o,n;return!!((n=(o=u.value)==null?void 0:o[t])!=null&&n.length)>0})??[]),_=D(null),V=D("");k(()=>setTimeout(()=>ge(),0)),Me(()=>{var e;return(e=_.value)==null?void 0:e.disconnect()});const ge=()=>{_.value&&_.value.disconnect();const e=window.innerWidth<=768?"-144px 0px -30% 0px":window.innerWidth<=1024?"-144px 0px -50% 0px":"0px 0px -50% 0px";_.value=new IntersectionObserver(he,{root:null,rootMargin:e,threshold:.1}),w.forEach(t=>{const o=document.getElementById(String(t.itemId));o&&_.value.observe(o)})},he=e=>{e.forEach(t=>{var o;t.isIntersecting&&(V.value=(o=t.target)==null?void 0:o.id)})},ye=G(),x=v(()=>{var e;return(e=u.value)!=null&&e.length?u.value.map(t=>{const o=S(t??[]).filter(n=>{var s;return((s=n.products)==null?void 0:s.length)===1});return re(o,ye)}).flat():[]}),be=v(()=>{if(!x.value)return[];const e="https://www.dekamarkt.nl/aanbiedingen";return[{type:"application/ld+json",innerHTML:{"@context":"https://schema.org","@graph":[{"@type":"ItemList","@id":`${e}#mainEntityOfPage`,name:"Aanbiedingen",description:"Bekijk hier de aanbiedingen van DekaMarkt. Bespaar op je boodschappen in onze winkels.",url:e,itemListElement:x.value}]}}]});return Pe({script:be}),k(()=>{var e;te("offers.sd_itemlist",{name:"Aanbiedingen",aantal:((e=x.value)==null?void 0:e.length)??0})}),(e,t)=>{var j,q;const o=Oe,n=Ie,s=xe,h=Te,T=De,R=ke,W=Ce,we=Re;return i(),l("div",Ye,[c("div",Ze,[f(o,{link:"/meer/folder",icon:"arrow-right"},{default:X(()=>[c("span",null,b(r(d)("offers.showFolder")),1)]),_:1})]),r(F)?(i(),l("div",et,[c("div",tt,[f(n,{section:r(F)},null,8,["section"])])])):y("",!0),c("div",ot,[c("div",{class:Le(["offers__nav",{"header--hide":r(oe)}])},[f(s,{departments:r(I),"active-department":r(V),disabled:!((j=r(I))!=null&&j.length)},null,8,["departments","active-department","disabled"])],2),c("div",nt,[c("h2",null,b(r(d)("offers.title")),1),f(h,{"offer-type":B.offerType,onHandleOfferDate:fe},null,8,["offer-type"]),((q=r(I))==null?void 0:q.length)>0?(i(),l("div",rt,[(i(!0),l(Q,null,Ve(r(A),(a,K)=>{var U;return i(),l(Q,{key:a.itemId},[(a.isDepartment||a.isTopOffer)&&((U=r(u))!=null&&U[K])?(i(),C(T,{id:a.itemId,key:`department-${a.itemId}`,department:a,offers:r(u)[K],onHandleMultiProduct:r(ie)},null,8,["id","department","offers","onHandleMultiProduct"])):y("",!0),a.type&&!a.isTopOffer?(i(),C(Ke(`items-${a.type}`),{key:1,item:a.controls},null,8,["item"])):y("",!0)],64)}),128))])):(i(),l("div",st,[f(R)]))])]),r(O)?(i(),l("p",at,[J(b(r(O))+" ",1),t[3]||(t[3]=c("br",null,null,-1)),J(" "+b(r(d)("offers.error")),1)])):y("",!0),(i(),C(He,{to:"body"},[f(we,{id:"offers-department__dialog",open:r(m),onClose:t[2]||(t[2]=a=>m.value=!1)},{default:X(()=>[f(W,{title:r(d)("offers.cmsFutureDialog.title")??"",description:r(d)("offers.cmsFutureDialog.description")??"","confirm-text":"offers.cmsFutureDialog.confirmText","cancel-text":"offers.cmsFutureDialog.cancelText",onConfirm:t[0]||(t[0]=a=>m.value=!1),onCancel:t[1]||(t[1]=a=>m.value=!1)},null,8,["title","description"])]),_:1},8,["open"])]))])}}}),$t=Ge(ct,[["__scopeId","data-v-18212f1e"]]);export{$t as default};
