import{_ as k}from"./HVPAq58b.js";import{_ as C}from"./DYcGBEAc.js";import{cu as R,aM as V,ar as D,a as l,d as E,cr as N,bI as A,s as M,I as O,M as F,e as d,o as T,b as B,t as L,O as q,v,g as G,q as Q}from"./BNf5twDP.js";(function(){try{var t=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},o=new t.Error().stack;o&&(t._sentryDebugIds=t._sentryDebugIds||{},t._sentryDebugIds[o]="eca53484-0cd1-486a-9d00-e7346a89114e",t._sentryDebugIdIdentifier="sentry-dbid-eca53484-0cd1-486a-9d00-e7346a89114e")}catch{}})();const z="recentProducts",b=10,K=6048e5,U=t=>{const o=R(z,[]);return V(()=>{const s=new Date().getTime();o.value=o.value.filter(n=>s-n.viewedAt<=K)}),D(()=>{if(!(t!=null&&t.value))return;let s=[...o.value];const n=s.findIndex(u=>u.productId===t.value);n>-1&&s.splice(n,1),s.unshift({productId:t.value,viewedAt:new Date().getTime()}),s=s.slice(0,b+1),o.value=s}),l(()=>o.value.filter(s=>s.productId!==(t==null?void 0:t.value)).map(s=>s.productId).slice(0,b))},W={key:0,class:"col-span-12 mt-8 mb-4 md:col-span-10 md:col-start-2"},$={class:"text-xl uppercase font-bold px-4 mb-4 md:px-0"},X=E({__name:"RecentlyViewedProducts",props:{currentProductId:{}},setup(t){const o=t,s=l(()=>o.currentProductId),n=U(s),u=l(()=>n.value.length>0),h=l(()=>({productIds:n.value})),{data:f,isLoading:_,refetch:w}=N({filters:h,pageSize:20},{enabled:u,select:r=>{const e=n.value;return r.sort((a,c)=>e.indexOf(a.id)-e.indexOf(c.id))}}),g=A(w,1e3),{addRecentlyViewedProductClick:I}=M(),P=O(),x=F(),S=l(()=>x.getPlatformConfiguration.platformId),y=async r=>{var a,c;const e=(c=(a=f.value)==null?void 0:a.data)==null?void 0:c.find(i=>i.id===r);if(e!=null&&e.eventId){const i=await P.fetchQuery(Q.events.details(e.eventId,S));I({productPrices:e.prices,productId:e.id,productName:e.name,productSlug:e.slug,labels:e.labels.map(p=>p.text),event:i})}};return(r,e)=>{var i,p;const a=k,c=C;return d(u)?(T(),B("div",W,[L("h3",$,q(r.$t("product.recentlyViewed")),1),v(a,{class:"hidden md:block",products:((i=d(f))==null?void 0:i.data)??[],"show-skeleton":d(_),"has-margin":!1,onProductClicked:e[0]||(e[0]=m=>y(m.id)),onProductFinished:d(g)},null,8,["products","show-skeleton","onProductFinished"]),v(c,{class:"md:hidden",products:(p=d(f))==null?void 0:p.data,"is-loading":d(_),"has-padding":!1,onProductClicked:e[1]||(e[1]=m=>y(m.id)),onProductFinished:d(g)},null,8,["products","is-loading","onProductFinished"])])):G("",!0)}}});export{X as _};