1import{R as e,Tt as t,V as n,l as r,p as i,st as a,u as o,vt as s,x as c,y as l}from"./Dw33plwm.js";import{t as u}from"./DlVb8YNB.js";import{i as d}from"./DK-5hDCP.js";import{n as f}from"./Bvhm9SRq.js";import{tt as p}from"./B-EOieCo.js";import{n as m}from"./WX6epeCT.js";import{n as h}from"./B35lLJ6p.js";import{t as g}from"./DsatCiQQ.js";var _={class:`flex h-9 w-9 items-center justify-center`},v=c({__name:`cart-button`,props:{count:{}},emits:[`click`],setup(c,{emit:u}){let d=u,f=s(!1);e(()=>{f.value=!0});let h=r(()=>f.value?c.count:0);return(e,r)=>(n(),i(`button`,{class:`hover:bg-midnight-100 flex h-9 w-9 cursor-pointer items-center justify-center rounded-full transition-all duration-320 ease-out hover:shadow-xs`,onClick:r[0]||=e=>d(`click`)},[l(t(p),{type:`number`,color:`basil`,label:t(h),size:`3xl`,inset:``},{default:a(()=>[o(`span`,_,[l(t(m),{name:`i-lucide:shopping-cart`,size:24,"stroke-width":2})])]),_:1},8,[`label`])]))}}),y=async({code:e})=>await u(`/api/cart/discount-code`,{method:`POST`,body:{code:e}}),b=({cart:e,error:t,isLoading:n,isFetched:r})=>({addDiscountCode:async({code:i})=>{n.value=!0,t.value=null;try{return e.value=(await y({code:i})).data??null,r.value=!0,e.value}catch(e){throw t.value=e instanceof Error?e.message:`Failed to apply discount code`,e}finally{n.value=!1}}}),x=async({code:e})=>await u(`/api/cart/discount-code`,{method:`DELETE`,body:{code:e}}),S=({cart:e,error:t,isLoading:n,isFetched:r})=>({removeDiscountCode:async({code:i})=>{n.value=!0,t.value=null;try{return e.value=(await x({code:i})).data??null,r.value=!0,e.value}catch(e){return t.value=e instanceof Error?e.message:`Failed to remove discount code`,null}finally{n.value=!1}}}),C=async({productId:e,quantity:t})=>await u(`/api/cart`,{method:`POST`,body:{productId:e,quantity:t}}),w=({cart:e,error:t,isLoading:n,isFetched:r})=>({addItem:async({productId:i,quantity:a})=>{let o=g();n.value=!0,t.value=null;try{return e.value=(await C({productId:i,quantity:a})).data??null,r.value=!0,o.success({title:`Added to Cart`,description:`Your item is in the cart. Check out whenever you're ready`,icon:`cart:shopping-cart-check`}),e.value}catch(e){return t.value=e instanceof Error?e.message:`Failed to add cart item`,o.error({title:`Something went wrong`,description:t.value}),null}finally{n.value=!1}}}),T=async({itemId:e})=>{let t=`/api/cart/${e}`;return await u(t,{method:`DELETE`})},E=({cart:e,error:t,isLoading:n,isFetched:r})=>({removeItem:async({itemId:i})=>{n.value=!0,t.value=null;try{return e.value=(await T({itemId:i})).data??null,r.value=!0,e.value}catch(e){return t.value=e instanceof Error?e.message:`Failed to remove cart item`,null}finally{n.value=!1}}}),D=()=>d(`/api/cart`,{method:`GET`,server:!1},`$RlRCGasJ67`),O=async()=>await u(`/api/cart`,{method:`GET`}),k=({cart:e,error:t,isLoading:n,isFetched:r})=>({fetchCart:async({mode:i=`use-fetch`}={})=>{n.value=!0,t.value=null;try{if(i===`use-fetch`){let{data:t,error:n}=await D();if(n.value)throw n.value;e.value=t.value?.data??null}return i===`request`&&(e.value=(await O()).data??null),r.value=!0,e.value}catch(n){return e.value=null,r.value=!0,t.value=n instanceof Error?n.message:`Failed to load cart`,null}finally{n.value=!1}}}),A=async({itemId:e,quantity:t})=>{let n=`/api/cart/${e}/quantity`;return await u(n,{method:`PATCH`,body:{quantity:t}})},j=({cart:e,error:t,isLoading:n,isFetched:r})=>({changeItemQuantity:async({itemId:i,quantity:a})=>{n.value=!0,t.value=null;try{return e.value=(await A({itemId:i,quantity:a})).data??null,r.value=!0,e.value}catch(e){return t.value=e instanceof Error?e.message:`Failed to update cart item quantity`,null}finally{n.value=!1}}}),M=async({specialInstructions:e})=>await u(`/api/cart`,{method:`PATCH`,body:{specialInstructions:e}}),N=({cart:e,error:t,isLoading:n,isFetched:r})=>({changeSpecialInstructions:async({specialInstructions:i})=>{n.value=!0,t.value=null;try{return e.value=(await M({specialInstructions:i})).data??null,r.value=!0,e.value}catch(e){return t.value=e instanceof Error?e.message:`Failed to update special instructions`,null}finally{n.value=!1}}}),P=async()=>await u(`/api/cart`,{method:`DELETE`}),F=({cart:e,error:t,isLoading:n,isFetched:r})=>({clearCart:async()=>{n.value=!0,t.value=null;try{return e.value=(await P()).data??null,r.value=!0,e.value}catch(e){return t.value=e instanceof Error?e.message:`Failed to clear cart`,null}finally{n.value=!1}}}),I=async()=>await u(`/api/cart/merge`,{method:`POST`}),L=({cart:e,error:t,isLoading:n,isFetched:r})=>({merge:async()=>{n.value=!0,t.value=null;try{return e.value=(await I()).data??null,r.value=!0,e.value}catch(e){return t.value=e instanceof Error?e.message:`Failed to merge cart`,null}finally{n.value=!1}}}),R=f(`cart`,()=>{let e=s(null),t=s(!1),n=s(null),i=s(!1),a=r(()=>e.value?.items??[]),o=e=>e.itemStatus===`HIDDEN`||e.itemStatus===`OUT_OF_STOCK`||e.itemStatus===`PRODUCT_REMOVED`,c=r(()=>a.value.some(e=>o(e))),l=r(()=>a.value.reduce((e,t)=>
1t.itemStatus===`OUT_OF_STOCK`?e:e+t.quantity,0)),u=r(()=>a.value.length),d=r(()=>e.value?.subtotal??0),f=r(()=>e.value?.total??0),p=r(()=>e.value?.savingsTotal??0),m=r(()=>e.value?.specialInstructions??``),g=r(()=>a.value.length>0),_=r(()=>i.value&&!g.value),{currency:v}=h(),y=r(()=>g.value?((v.value===`USD`?e.value?.usdTotal:e.value?.total)??0)<=50:!1),x=t=>{e.value=t},C=()=>{n.value=null},T=()=>{e.value=null,n.value=null,t.value=!1,i.value=!1},{fetchCart:D}=k({cart:e,error:n,isLoading:t,isFetched:i}),{addItem:O}=w({cart:e,error:n,isLoading:t,isFetched:i}),{removeItem:A}=E({cart:e,error:n,isLoading:t,isFetched:i}),{changeItemQuantity:M}=j({cart:e,error:n,isLoading:t,isFetched:i}),{changeSpecialInstructions:P}=N({cart:e,error:n,isLoading:t,isFetched:i}),{addDiscountCode:I}=b({cart:e,error:n,isLoading:t,isFetched:i}),{removeDiscountCode:R}=S({cart:e,error:n,isLoading:t,isFetched:i}),{clearCart:z}=F({cart:e,error:n,isLoading:t,isFetched:i}),{merge:B}=L({cart:e,error:n,isLoading:t,isFetched:i});return{cart:e,isLoading:t,error:n,isFetched:i,items:a,itemsCount:l,uniqueItemsCount:u,hasUnavailableItems:c,isBelowCheckoutMinimum:y,subtotal:d,total:f,savingsTotal:p,specialInstructions:m,hasItems:g,isEmpty:_,setCart:x,clearError:C,resetCart:T,fetchCart:D,addItem:O,removeItem:A,changeItemQuantity:M,changeSpecialInstructions:P,addDiscountCode:I,removeDiscountCode:R,clearCart:z,merge:B,isItemUnavailable:o}});export{v as n,R as t};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.