import{dt as e}from"./runtime-core.esm-bundler.v79eHMSw.js";import{t}from"./api.CmRvD1II.js";function n(n){let r=t(n),i=e([]),a=e(!1),o=e(!1),s=e(!1);async function c(){a.value=!0;try{let e=await r(`/storefront/purchase-lists`);i.value=e.data.lists||[],s.value=!!e.data.can_share,o.value=!0}finally{a.value=!1}}async function l(e,t){let n=await r(`/storefront/purchase-lists`,{method:`POST`,body:JSON.stringify({name:e,items:t})});return i.value.unshift(n.data.list),n}async function u(e,t){let n=await r(`/storefront/purchase-lists/`+e,{method:`PUT`,body:JSON.stringify({name:t})}),a=i.value.findIndex(t=>t.id===e);return a!==-1&&(i.value[a]=n.data.list),n}async function d(e){await r(`/storefront/purchase-lists/`+e,{method:`DELETE`}),i.value=i.value.filter(t=>t.id!==e)}async function f(e){return r(`/storefront/purchase-lists/`+e+`/reorder`,{method:`POST`})}async function p(e,t){let n=await r(`/storefront/purchase-lists/`+e+`/share`,{method:`POST`,body:JSON.stringify({shared:t})}),a=i.value.findIndex(t=>t.id===e);return a!==-1&&(i.value[a]=n.data.list),n}return{lists:i,loading:a,loaded:o,canShare:s,fetchLists:c,saveList:l,renameList:u,removeList:d,reorder:f,shareList:p}}export{n as t};