import j from"./D8_G3sZS.js";import q from"./Ce1Sjjn1.js";import G from"./C2lb8vfu.js";import{d as K,u as U,K as z,a as M,k as Q,q as V,l as X,p as J,r as S,e as W,j as Y,bE as Z,aF as ee,t as d,g as o,H as oe,o as m,cc as h,n as k}from"./BxiWQxwE.js";const ce=K({__name:"index",setup(te){const _=U(),{isBasketPage:p}=z(_),{$toast:v,$gtm:w,$messages:c}=M(),{loggedIn:y,getLoginUrl:C}=Q(),L=V(`${oe}-basket-id`),{openListDialog:I,productForShoppingList:r,hasShoppingLists:N,getShoppingListData:T,addProductToShoppingList:x,triggerView:i,newlyCreatedShoppingListId:E}=X(),{createShoppingList:b,mergeShoppingListProducts:A}=J(),t=S(!1),n=S({shoppingListName:"",login:""}),P=W(()=>!N.value||i.value===h.CREATE),R=async e=>{t.value=!0;try{if(!L.value){v.add({id:3,text:c("error.common")}),console.error("Basket ID not found");return}return await A(L.value,String(e))}catch(s){console.error(s),v.add({id:3,text:c("error.common")})}finally{t.value=!1}},B=async e=>{var s;t.value=!0,n.value.shoppingListName="";try{const a=await b({name:e});if((s=a.createShoppingList)!=null&&s.isSuccess){w("shoppingList.save",{name:e}),E.value=a.createShoppingList.shoppingListId;const u=a.createShoppingList.shoppingListId;(p.value?await R(u):await x(String(u)))&&(await T(),t.value=!1,D())}}catch(a){t.value=!1,n.value.shoppingListName=c("error.common")??"",console.error("Error creating shopping list",a)}},D=()=>{i.value===h.CREATE&&(i.value=null,F())},F=()=>{setTimeout(()=>{const e=document.querySelector(".dialog-list__content");e&&e.scroll({top:e.scrollHeight,behavior:"smooth"})},100)};Y(()=>{var e;i.value=null,((e=Object.keys(l.value))==null?void 0:e.length)>0&&(r.value=l.value,l.value=null)}),ee(()=>{r.value=null,g()});const l=Z("productForList",{}),$=async()=>{t.value=!0,n.value.login="",l.value=r.value,await H()},H=async()=>{try{return g(),await k(C(_.fullPath,"list=1"),{external:!0})}catch(e){console.info("Failed to navigate to login",e),n.value.login=c("error.common")??""}},O=async()=>{g(),await k("/registreren")},g=()=>{I.value=!1};return(e,s)=>{const a=j,u=q,f=G;return o(y)?o(P)?(m(),d(u,{key:1,loading:o(t),error:o(n).shoppingListName,"product-to-add":o(r),"triggered-from-basket":o(p),onCreateNewList:B},null,8,["loading","error","product-to-add","triggered-from-basket"])):(m(),d(f,{key:2,loading:o(t),error:o(n).shoppingListName,"product-to-add":o(r),"triggered-from-basket":o(p),onOpenCreateNewList:s[0]||(s[0]=se=>i.value=o(h).CREATE)},null,8,["loading","error","product-to-add","triggered-from-basket"])):(m(),d(a,{key:0,error:String(o(n).login),onRedirectToLogin:$,onCreateAccount:O},null,8,["error"]))}}});export{ce as _};
