import{m as e,n as t,t as n}from"./useMutation-DvG2_Fq3.js";function r(e){return`local-cart-${e}`}function i(e){try{let t=localStorage.getItem(r(e));return t?JSON.parse(t):[]}catch{return[]}}function a(e,t){localStorage.setItem(r(e),JSON.stringify(t))}function o(e=`regular`){return t({queryKey:[r(e)],queryFn:()=>{let t=i(e);return{items:t,totalItems:t.reduce((e,t)=>e+t.quantity,0),totalAmount:0}}})}function s(t=`regular`){let o=e();return n({mutationFn:async({productId:e,quantity:n,storeId:r,slotId:o,deliveryDate:s})=>{let c=i(t),l=c.find(t=>t.productId===e);l?(l.quantity+=n,o&&(l.slotId=o),s&&(l.deliveryDate=s)):c.push({id:Date.now(),productId:e,quantity:n,storeId:r,addedAt:Date.now(),slotId:o??null,deliveryDate:s??null}),a(t,c)},onSuccess:()=>{o.invalidateQueries({queryKey:[r(t)]})}})}function c(t=`regular`){let o=e();return n({mutationFn:async({productId:e,quantity:n,slotId:r,deliveryDate:o})=>{let s=i(t),c=s.find(t=>t.productId===e);c&&(c.quantity=n,r!==void 0&&(c.slotId=r),o!==void 0&&(c.deliveryDate=o)),a(t,s)},onSuccess:()=>{o.invalidateQueries({queryKey:[r(t)]})}})}function l(t=`regular`){let o=e();return n({mutationFn:async e=>{let n=i(t);n=n.filter(t=>t.productId!==e),a(t,n)},onSuccess:()=>{o.invalidateQueries({queryKey:[r(t)]})}})}function u(e=`regular`){localStorage.removeItem(r(e))}export{c as a,l as i,s as n,o as r,u as t};