import F from"./BtFqvK5V.js";import{a3 as $,u as T,e as D,b4 as j,d as H,a as Q,l as W,ab as Y,Z as K,O as V,k as Z,f as z,y as G,F as J,o as f,t as X,g as v,b5 as y,n as tt}from"./BxiWQxwE.js";import{u as et}from"./CMsHgkl0.js";const ot=()=>{const o=$(),i=T(),d="aanbieding",l=D(()=>!!o.currentRoute.value.query[d]&&!!n.value),n=j("currentMultiProduct",()=>null);return{showDrawer:l,currentMultiProduct:n,handleMultiProduct:async r=>{var s,c;await o.replace({query:{...i.query,aanbieding:`${(s=r.department)==null?void 0:s.itemId}-${(c=r.offer)==null?void 0:c.productId}`}}),n.value=r.offer}}},at=200,ct=H({__name:"index",props:{products:{type:Array,required:!0},department:{type:Object,required:!1,default:null},listName:{type:String,required:!1,default:""},options:{type:Object,required:!1,default:()=>({border:!0,color:"var(--black-color)",direction:null,parent_has_background_color:!1})}},setup(o){const{$toast:i,$messages:d}=Q(),{handleMultiProduct:l}=ot(),{productSaved:n,productInMultiProductSaved:g,toggleListDialog:r,productForShoppingList:s}=W(),{add:c,remove:P,update:R}=Y(),{getTerm:w,lastItemRemoved:E,termReplaceWithProduct:I}=K(),{deleteShoppingListTerm:S}=V(),u=o,m=T(),{clearRouteParamByKey:q}=Z(),L=async t=>{const e={product:t.product,quantity:t.quantity,listName:u.listName};await c(e),m.query[y.TERM.REPLACE]&&M()},_=async t=>{const e={product:t,listName:u.listName};await P(e)},b=async t=>{const e={product:t.product,quantity:t.quantity,listName:u.listName};await R(e)},M=()=>{setTimeout(()=>{k().catch(h)},at)},k=async()=>{try{const t=m.query[y.TERM.REPLACE],e=w(t);if(!e)return;await N(e),A(e),await q(y.TERM.REPLACE,m.query),await B()}catch(t){h(t)}},N=async t=>{var a;if(!((a=(await S(t.id)).deleteShoppingListItem)!=null&&a.isSuccess))throw new Error("Failed to delete shopping list item")},A=t=>{E.value=t,I.value=!0},B=async()=>await tt("/mijn-winkelmand"),h=t=>{i.add({id:4,text:d("error.common")}),console.error("Failed to replace Term",t)},O=t=>{var e;return t.multi?g(((e=t.multiProducts)==null?void 0:e.map(a=>a.productId))??[]):n(t.productId)},C=t=>{s.value=t,r()},{listItemObserved:U}=et(u.products.filter(t=>!t.multi).length);return(t,e)=>{const a=F;return f(!0),z(J,null,G(o.products,(p,x)=>(f(),X(a,{key:`${p.productId}--${x}`,product:p,department:o.department,options:o.options,"list-name":o.listName,"saved-product":O(p),onHandleMultiProduct:v(l),onAdd:L,onRemove:_,onUpdate:b,onObserved:v(U),onToggleList:C},null,8,["product","department","options","list-name","saved-product","onHandleMultiProduct","onObserved"]))),128)}}});export{ct as _,ot as u};
