import wt from"./_6A4EL4o.js";import{d as xt,a as kt,k as Tt,l as Pt,m as bt,p as G,b as Dt,r as v,u as Ct,w as Bt,e as F,q as At,s as Nt,f as I,i as f,h as l,g as s,t as D,v as C,x as H,F as J,y as K,z as $t,A as Ft,B as Et,C as X,T as Ot,D as Ut,E as Rt,G as Vt,c as zt,n as Y,H as Mt,o as c,I as Z,J as Wt,U as Qt,_ as jt}from"./BxiWQxwE.js";import qt from"./jjvREr30.js";import Gt from"./Bwpvg42O.js";import Ht from"./DEYamrem.js";import Jt from"./uQu5og1w.js";import{u as Kt}from"./82sW_ACQ.js";import"./9mcJnkzw.js";import"./B4lq0tGA.js";import"./BMc5KkT2.js";import"./4HfP1VOY.js";import"./QMEN6lyk.js";import"./CxeYIrhH.js";import"./DXn7UZRN.js";import"./BpaGfDpb.js";import"./CCb6Ii9b.js";import"./DKUQAchG.js";import"./C4s7dVXj.js";const Xt={class:"container"},Yt={class:"header"},Zt={class:"list__options"},te={class:"list__content"},ee={class:"list__content--products"},se={key:0,class:"list__content--actions"},oe=["aria-label"],ne=xt({__name:"[listId]",async setup(ie){let S,E;const{$messages:p,$toast:y}=kt(),{loggedIn:tt}=Tt(),{userShoppingLists:et,openListDialogUpdate:O,getShoppingListData:U,productsOnShoppingList:st,deleteProductFromShoppingList:ot,productExistInSpecificShoppingList:nt,productForShoppingList:B,shoppingListToDelete:it,toggleListDialog:at}=Pt(),{openConfirmationDialog:rt}=bt(),{mergeShoppingListProducts:lt}=G(),{shoppingListItems:pt}=G(),{getProducts:ut}=Kt(),{mapProductAssortmentToProductCard:ct}=Dt(),L=v(""),A=v(""),N=v(!1),u=v(null),w=v(!1),h=v(),x=Ct(),{data:a,refresh:k}=([S,E]=Bt(async()=>zt(`shoppinglistItems-${x.params.listId}`,async()=>{var i,r,g,d,T,P;tt.value||await Y("/boodschappenlijsten");const t=await pt(String((i=x.params)==null?void 0:i.listId));let e=[];if(!(t!=null&&t.shoppingListItems))return{shoppinglist:[],products:e};try{e=await ut((g=(r=t.shoppingListItems)==null?void 0:r.shoppingListItems)==null?void 0:g.map(m=>Number(m.productId)))}catch(m){console.error(m)}const o={...t.shoppingListItems,shoppingListId:String((d=x.params)==null?void 0:d.listId)},n=(P=(T=e==null?void 0:e.productsAssortment)==null?void 0:T.filter(Boolean))==null?void 0:P.map(m=>ct(m));return{shoppingList:o,filteredProducts:n}})),S=await S,E(),S),R=F(()=>{var e,o;return(e=a.value)!=null&&e.filteredProducts?(o=[...a.value.filteredProducts].sort((n,i)=>{var r;return(r=n==null?void 0:n.headerText)==null?void 0:r.localeCompare(i==null?void 0:i.headerText)}).reduce((n,i)=>{const r=i.department,g=n.find(d=>(d==null?void 0:d.department)===r);return g?g.products.push(i):n.push({department:r,webgroup:i.webgroup,products:[i]}),n},[]))==null?void 0:o.sort((n,i)=>{var r;return(r=n.department)==null?void 0:r.localeCompare(i.department)}):[]}),dt=async()=>await k(),mt=async()=>{var e,o;if(!u.value)return;if(L.value=String(u.value.productId),await ot(Number(u.value.productId),String((o=(e=a.value)==null?void 0:e.shoppingList)==null?void 0:o.shoppingListId))){await U(),await k(),L.value="";return}A.value=String(u.value.productId)},_t=()=>{var t;(t=a.value)!=null&&t.shoppingList&&(it.value=a.value.shoppingList,rt.value=!0)},gt=async t=>{var e;A.value="",h.value&&u.value&&(clearTimeout(h.value),await V()),u.value=t,(e=a.value)!=null&&e.filteredProducts&&(a.value.filteredProducts=[...a.value.filteredProducts.filter(o=>o.productId!==t.productId)],w.value=!0,h.value=setTimeout(async()=>{await V()},Qt))},V=async()=>{await mt(),w.value=!1,u.value=null,L.value=""},z=At(`${Mt}-basket-id`),ht=async()=>{var t,e,o,n;N.value=!0;try{if(!z.value){y.add({id:3,text:p("error.common")}),console.error("Basket ID not found");return}if(!((e=(t=a.value)==null?void 0:t.shoppingList)!=null&&e.shoppingListId)){y.add({id:3,text:p("error.common")}),console.error("Shopping list ID not found");return}await lt((n=(o=a.value)==null?void 0:o.shoppingList)==null?void 0:n.shoppingListId,z.value)&&(await U(),window.scrollTo({top:0,behavior:"smooth"}),y.add({id:1,title:p("shoppinglist.popup.mergedWithBasket.title"),text:p("shoppinglist.popup.mergedWithBasket.description")}))}catch(i){y.add({id:3,text:p("error.common")}),console.error(i)}finally{N.value=!1}},$=F(()=>{var e;const t=(e=et.value)==null?void 0:e.find(o=>{var n;return o.shoppingListId===String((n=x.params)==null?void 0:n.listId)});return t!=null&&t.noItems?t.noItems>0:!1}),vt=()=>{var t;h.value&&clearTimeout(h.value),(t=a.value)==null||t.filteredProducts.push(u.value),u.value=null,w.value=!1,L.value=""},ft=t=>{B.value=t,at()},Lt=async()=>await k(),It=async()=>{},St=F(()=>{var t;return!$.value||h.value&&((t=R.value)==null?void 0:t.length)===0});return Nt(st,async()=>{var e,o;if(!B.value)return!1;nt(Number(B.value.productId),String((o=(e=a.value)==null?void 0:e.shoppingList)==null?void 0:o.shoppingListId))||await k()}),(t,e)=>{var m,M,W,Q,j;const o=wt,n=Rt,i=qt,r=Gt,g=Wt,d=Ht,T=Vt,P=Jt;return c(),I("div",null,[f(o,{"last-bread-crumb":{name:s(Z)(String((M=(m=s(a))==null?void 0:m.shoppingList)==null?void 0:M.name))}},null,8,["last-bread-crumb"]),l("section",null,[l("div",Xt,[l("div",Yt,[l("h2",null,C(s(Z)(String((Q=(W=s(a))==null?void 0:W.shoppingList)==null?void 0:Q.name))),1),l("div",Zt,[f(n,{mode:"dropdown",list:(j=s(a))==null?void 0:j.shoppingList,onDeleteList:_t},null,8,["list"])])]),l("div",te,[l("p",null,C(s(p)(s($)?"shoppinglist.containsProducts":"shoppinglist.containsNoProducts")),1),l("div",ee,[s(St)?(c(),D(i,{key:0,onCtaClick:e[0]||(e[0]=_=>("navigateTo"in t?t.navigateTo:s(Y))("/producten"))})):(c(!0),I(J,{key:1},K(s(R),_=>(c(),I("div",{key:_.productId,class:"department"},[l("h3",null,C(_.department),1),(c(!0),I(J,null,K(_.products,(b,yt)=>{var q;return c(),D(r,{key:`${yt}__${b.productId}`,"strike-option":!1,product:b,list:(q=s(a))==null?void 0:q.shoppingList,error:s(A)===String(b.productId),loading:s(L)===String(b.productId),onRemoveFromList:gt,onItemObserved:It,onStriked:Lt,onToggleList:ft},null,8,["product","list","error","loading"])}),128))]))),128))]),s($)?(c(),I("div",se,[l("button",{"aria-label":s(p)("aria.ctaAddToBasket"),class:Ft(["button button-green",{loading:s(N)}]),onClick:$t(ht,["prevent"])},[f(g),Et(" "+C(s(p)("shoppinglist.ctaAddToBasket")),1)],10,oe)])):H("",!0)])]),(c(),D(Ot,{to:"body"},[f(T,{id:"list__dialog--update",open:s(O),onClose:e[1]||(e[1]=_=>O.value=!1)},{default:X(()=>{var _;return[f(d,{list:(_=s(a))==null?void 0:_.shoppingList,onDone:dt},null,8,["list"])]}),_:1},8,["open"])])),f(Ut,{name:"slide-up-full"},{default:X(()=>[s(w)?(c(),D(P,{key:0,text:s(p)("undoBar.deletedShoppingListItem"),onUndo:vt},null,8,["text"])):H("",!0)]),_:1})])])}}}),xe=jt(ne,[["__scopeId","data-v-9a545873"]]);export{xe as default};
