1import{j as e,hG as z,hH as P,hI as R,hJ as _}from"./vendor-data-eBPZki-Z.js";import{L as f,f as E,r as d}from"./vendor-react-BgtJhS2O.js";import{fa as v,fb as L,aA as O,eY as y,fc as N,u as T,fd as q,at as A}from"./index-DTQGL8n8.js";import{u as B}from"./useTrackScreen-BLOOZkQ_.js";import{eu as m,ev as j,gy as H,gz as Q}from"./vendor-zod-Bei2Z9MS.js";import{S as $}from"./ShopHeader-FNfC5L9p.js";function D({item:t,showMerchant:c,fallbackMerchantName:o,isUpdating:r,isRemoving:l,onUpdateQuantity:s,onRemove:a}){const x=t.offer_id!=null?`/shop/product/${t.offer_id}`:null,b=t.merchant?.business_name||o,n=t.quantity??1,u=()=>s(t.id,n-1),k=()=>s(t.id,n+1),h=()=>a(t.id),p=e.jsx(e.Fragment,{children:t.thumbnail?e.jsx("img",{src:t.thumbnail,alt:m(t.name),className:"w-full h-full object-cover"}):e.jsx("div",{className:"w-full h-full flex items-center justify-center",children:e.jsx(v,{size:24,className:"text-text-secondary dark:text-text-secondary-dark"})})});return e.jsxs("div",{className:"flex gap-4 py-5",children:[x?e.jsx(f,{to:x,className:"w-24 h-24 rounded-lg overflow-hidden bg-bg-elevated dark:bg-bg-elevated-dark flex-shrink-0",children:p}):e.jsx("div",{className:"w-24 h-24 rounded-lg overflow-hidden bg-bg-elevated dark:bg-bg-elevated-dark flex-shrink-0",children:p}),e.jsxs("div",{className:"flex-1 min-w-0",children:[x?e.jsx(f,{to:x,className:"text-sm font-medium text-text dark:text-text-dark hover:text-brand transition-colors line-clamp-2",children:m(t.name)}):e.jsx("p",{className:"text-sm font-medium text-text dark:text-text-dark line-clamp-2",children:m(t.name)}),c&&b&&e.jsx("p",{className:"text-xs text-text-secondary dark:text-text-secondary-dark mt-0.5",children:b}),t.variant_display&&e.jsx("p",{className:"text-xs text-text-secondary dark:text-text-secondary-dark mt-0.5",children:t.variant_display}),e.jsx("p",{className:"text-base font-bold text-text dark:text-text-dark mt-2",children:j(t.price??0)}),e.jsxs("div",{className:"flex items-center gap-3 mt-3",children:[e.jsxs("div",{className:"flex items-center border border-border-light/60 dark:border-border-dark/60 rounded-full",children:[e.jsx("button",{type:"button",onClick:u,disabled:r||n<=1,"aria-label":`Decrease quantity of ${m(t.name)}`,className:"w-8 h-8 flex items-center justify-center hover:bg-bg-elevated dark:hover:bg-bg-elevated-dark rounded-l-full transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:e.jsx(L,{size:14})}),e.jsx("span",{className:"w-8 text-center text-sm font-medium text-text dark:text-text-dark","aria-live":"polite",children:n}),e.jsx("button",{type:"button",onClick:k,disabled:r,"aria-label":`Increase quantity of ${m(t.name)}`,className:"w-8 h-8 flex items-center justify-center hover:bg-bg-elevated dark:hover:bg-bg-elevated-dark rounded-r-full transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:e.jsx(O,{size:14})})]}),e.jsx("button",{type:"button",onClick:h,disabled:l,"aria-label":`Remove ${m(t.name)} from cart`,className:"p-2 text-text-secondary dark:text-text-secondary-dark hover:text-error transition-colors disabled:opacity-50",children:e.jsx(y,{size:18})})]})]}),e.jsx("div",{className:"text-right flex-shrink-0",children:e.jsx("span",{className:"text-sm font-bold text-text dark:text-text-dark",children:j((t.price??0)*n)})})]})}function G({group:t,hasMultipleMerchants:c,isUpdating:o,isRemoving:r,onUpdateQuantity:l,onRemove:s}){return e.jsxs("div",{children:[c&&e.jsxs("div",{className:"flex items-center gap-2 py-2 mb-1 border-b border-border-light/60 dark:border-border-dark/60",children:[e.jsx(N,{size:15,className:"text-text-secondary dark:text-text-secondary-dark"}),e.jsx("span",{className:"text-sm font-semibold text-text dark:text-text-dark",children:t.merchant_name})]}),e.jsx("div",{className:"divide-y divide-border-light/60 dark:divide-border-dark/60",children:t.items.filter(a=>typeof a.id=="string"&&a.id.length>0).map(a=>e.jsx(D,{item:a,showMerchant:!c,fallbackMerchantName:t.merchant_name,isUpdating:o,isRemoving:r,onUpdateQuantity:l,onRemove:s},a.id))})]})}function Y(){return e.jsx("div",{className:"px-4 py-6",children:[1,2,3].map(t=>e.jsxs("div",{className:"flex gap-4 py-4 animate-pulse border-b border-border-light/60 dark:border-border-dark/60",children:[e.jsx("div",{className:"w-24 h-24 rounded-lg bg-bg-elevated dark:bg-bg-elevated-dark flex-shrink-0"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx("div",{className:"h-4 bg-bg-elevated dark:bg-bg-elevated-dark rounded w-3/4"}),e.jsx("div",{className:"h-3 bg-bg-elevated dark:bg-bg-elevated-dark rounded w-1/3"}),e.jsx("div",{className:"h-4 bg-bg-elevated dark:bg-bg-elevated-dark rounded w-1/4"})]})]},t))})}function F(){return e.jsxs("div",{className:"px-4 py-20 text-center",children:[e.jsx(v,{size:64,className:"mx-auto text-text-secondary dark:text-text-secondary-dark mb-4"}),e.jsx("h2",{className:"text-xl font-medium text-text dark:text-text-dark mb-2",children:"Your cart is empty"}),e.jsx("p",{className:"text-sm text-text-secondary dark:text-text-secondary-dark mb-6",children:"Browse the shop and add some products!"}),e.jsx(f,{to:"/shop",className:"inline-flex items-center gap-2 px-6 py-2.5 bg-brand text-text-on-brand rounded-full font-medium text-sm hover:bg-brand/90 transition-colors",children:"Start Shopping"})]})}function Z(){B("Cart");const t=E(),c=T(i=>i.isLoggedIn),o=z({enabled:c}),r=P(),l=R(),s=_(),a=d.useMemo(()=>o.data?.items??[],[o.data?.items]),x=o.data?.count??0,b=d.useMemo(()=>H(a),[a]),n=d.useMemo(()=>Q(a),[a]),u=n.length>1,[k,h]=d.useState(!1),p=d.useCallback((i,M)=>{r.mutate({itemId:i,quantity:Math.max(1,M)})},[r]),C=d.useCallback(i=>{l.mutate(i)},[l]),w=d.useCallback(()=>{s.mutate(void 0,{onSuccess:()=>h(!1)})},[s]),S=d.useCallback(()=>{t("/shop/checkout")},[t]),I=d.useCallback(()=>{t("/shop")},[t]),g=e.jsx($,{cartCount:x,onBack:I,title:"Cart",showSearch:!1});return o.isLoading?e.jsxs("div",{children:[g,e.jsx(Y,{})]}):a.length===0?e.jsxs("div",{children:[g,e.jsx(F,{})]}):e.jsxs("div",{children:[g,e.jsxs("div",{className:"px-4 pb-6 pt-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("h1",{className:"text-2xl font-bold text-text dark:text-text-dark",children:["Shopping Cart (",a.length," item",a.length!==1?"s":"",")"]}),e.jsxs("button",{type:"button",onClick:()=>h(!0),disabled:s.isPending,className:"flex items-center gap-1.5 text-sm text-text-secondary dark:text-text-secondary-dark hover:text-error transition-colors disabled:opacity-50","aria-label":"Clear cart",children:[e.jsx(y,{size:16}),"Clear"]})]}),u&&e.jsxs("div",{className:"flex items-center gap-2 mb-4 text-sm text-text-secondary dark:text-text-secondary-dark",children:[e.jsx(N,{size:16}),e.jsxs("span",{children:["Shopping from ",n.length," creators"]})]}),e.jsx("div",{className:"space-y-6",children:n.map(i=>e.jsx(G,{group:i,hasMultipleMerchants:u,isUpdating:r.isPending,isRemoving:l.isPending,onUpdateQuantity:p,onRemove:C},i.merchant_id))}),e.jsxs("div",{className:"mt-6 pt-6 border-t border-border-light/60 dark:border-border-dark/60",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsx("span",{className:"text-lg font-semibold text-text dark:text-text-dark",children:"Subtotal"}),e.jsx("span",{className:"text-2xl font-bold text-text dark:text-text-dark",children:j(b)})]}),e.jsxs("button",{type:"button",onClick:S,className:"w-full flex items-center justify-center gap-2 py-3.5 bg-brand hover:bg-brand/90 text-text-on-brand rounded-full font-semibold text-base transition-colors",children:["Proceed to Checkout",e.jsx(q,{size:18})]}),e.jsx(f,{to:"/shop",className:"block text-center text-sm text-brand hover:underline mt-4",children:"Continue Shopping"})]}),(r.isError||l.isError||s.isError)&&e.jsx("p",{className:"mt-4 text-sm text-error text-center",role:"alert",children:"Something went wrong updating your cart. Please try again."})]}),e.jsx(A,{open:k,onOpenChange:h,title:"Clear cart?",description:"This removes every item from your cart. You can always add them back.",confirmLabel:"Clear",onConfirm:w,isPending:s.isPending})]})}
1export{Z as default};
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.