1import{r as m,j as e,q as D,v as U,a as W,C as I,B as N,ao as O,t as z,ag as S}from"./index-Dfl_tZFa.js";import{P as G}from"./page-header-D__eZnyz.js";import{u as J}from"./useQuery-KzlpSEsd.js";import{B as P}from"./badge-DCqXXUkv.js";import{S as X,a as Z,b as ee,c as se,d as te}from"./sheet-BQLFU2yD.js";import{h as ae}from"./design-cart.functions-BdSdYWTa.js";import{a as re}from"./analytics.functions-ClPOV4ye.js";import{o as ne,r as R,s as B,a as ie,b as le,f as A}from"./design-cart-D1FACkPr.js";import{M as ce}from"./ModuleGate-wnte8da8.js";import{S as q}from"./shopping-cart-Dt8O9T0D.js";import{S as oe}from"./sparkles--mIrhW7F.js";import{C as de}from"./clock-UIYPS8XK.js";import{L as E}from"./loader-circle-x9hSsoJE.js";import{M as F}from"./minus-D8s8aGkW.js";import{P as V}from"./plus-B7fM6kZ8.js";import{T as H}from"./trash-2-0u1zIQQb.js";import{C as me}from"./circle-alert-hVKoNRYZ.js";import{L as ue}from"./lock-Ru62KPkz.js";import"./use-platform-modules-BmVs-Era.js";const xe=U("relative w-full rounded-xl border px-4 py-3 text-sm [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground [&>svg~*]:pl-7",{variants:{variant:{default:"bg-background text-foreground",destructive:"border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive"}},defaultVariants:{variant:"default"}}),Q=m.forwardRef(({className:r,variant:s,...o},d)=>e.jsx("div",{ref:d,role:"alert",className:D(xe({variant:s}),r),...o}));Q.displayName="Alert";const he=m.forwardRef(({className:r,...s},o)=>e.jsx("h5",{ref:o,className:D("mb-1 font-medium leading-none tracking-tight",r),...s}));he.displayName="AlertTitle";const K=m.forwardRef(({className:r,...s},o)=>e.jsx("div",{ref:o,className:D("text-sm [&_p]:leading-relaxed",r),...s}));K.displayName="AlertDescription";const Y="cs.design-cart.return",$="data-cart-section",pe=1800*1e3;function L(){try{return typeof sessionStorage>"u"?null:sessionStorage}catch{return null}}function fe(r,s=L()){if(!s)return null;const o={path:r.path,scrollY:Math.max(0,Math.round(r.scrollY||0)),sectionId:r.sectionId??null,savedAt:r.savedAt??Date.now()};try{s.setItem(Y,JSON.stringify(o))}catch{return null}return o}function ge(r=L(),s=Date.now()){if(!r)return null;let o=null;try{o=r.getItem(Y)}catch{return null}if(!o)return null;let d;try{d=JSON.parse(o)}catch{return null}if(!d||typeof d!="object")return null;const n=d;return typeof n.path!="string"||!n.path.startsWith("/")||typeof n.savedAt!="number"||s-n.savedAt>pe?null:{path:n.path,scrollY:typeof n.scrollY=="number"&&n.scrollY>0?Math.round(n.scrollY):0,sectionId:typeof n.sectionId=="string"&&n.sectionId?n.sectionId:null,savedAt:n.savedAt}}function je(r=L()){try{r?.removeItem(Y)}catch{}}function Ne(r,s){if(!r.length)return null;const o=s/2;let d=null;for(const n of r)n.top<=o&&(d=n.id);return d??r[0].id}function ye(r=document,s=window.innerHeight){const d=Array.from(r.querySelectorAll(`[${$}]`)).map(n=>({id:n.getAttribute($)||"",top:n.getBoundingClientRect().top})).filter(n=>n.id);return Ne(d,s)}function be(r){if(typeof window>"u")return null;const s=r;return s.startsWith("/design-cart/cart")?null:fe({path:s,scrollY:window.scrollY,sectionId:ye()})}function ve(r){m.useEffect(()=>{if(!r||typeof window>"u")return;const s=ge();if(!s||!(`${window.location.pathname}${window.location.search}`.split("?")[0]===s.path.split("?")[0]))return;je();const n=requestAnimationFrame(()=>{if(window.scrollTo({top:s.scrollY,behavior:"auto"}),!s.sectionId)return;const p=document.querySelector(`[${$}="${CSS.escape(s.sectionId)}"]`);p&&(p.scrollIntoView({block:"center",behavior:"auto"}),p.classList.add("cart-return-highlight"),window.setTimeout(()=>p.classList.remove("cart-return-highlight"),2200))});return()=>cancelAnimationFrame(n)},[r])}const we=350;function Ce(){const[r,s]=m.useState([]),[o,d]=m.useState({}),[n,p]=m.useState(null),g=m.useRef({}),w=m.useRef(!0);m.useEffect(()=>{const t=()=>{w.current&&s(R())};return t(),ne(t)},[]),m.useEffect(()=>{const t=g.current;return()=>Object.values(t).forEach(i=>clearTimeout(i.timer))},[]);const k=(t,i)=>d(l=>{if(i)return{...l,[t]:!0};const c={...l};return delete c[t],c}),y=m.useCallback((t,i)=>{try{i(),p(null),s(R())}catch(l){p(l instanceof Error?l.message:"We couldn't update your cart. Please try again."),s(R())}finally{k(t,!1),w.current=!0}},[]),b=m.useCallback((t,i)=>{w.current=!1,k(t,!0);const l=g.current[t];l&&clearTimeout(l.timer);const c=setTimeout(()=>{delete g.current[t],y(t,i)},we);g.current[t]={timer:c,run:i}},[y]),f=m.useCallback((t,i)=>{const l=Math.min(20,Math.max(0,i));s(c=>{const _=c.some(v=>v.slug===t);return l===0?c.filter(v=>v.slug!==t):_?c.map(v=>v.slug===t?{...v,quantity:l}:v):[...c,{slug:t,quantity:l}]}),b(t,()=>B(t,l))},[b]),x=m.useCallback((t,i=1)=>{s(l=>l.some(c=>
1c.slug===t)?l.map(c=>c.slug===t?{...c,quantity:Math.min(20,c.quantity+i)}:c):[...l,{slug:t,quantity:i}]),b(t,()=>{R().some(c=>c.slug===t)?B(t,Math.min(20,(R().find(c=>c.slug===t)?.quantity??0)+i)):ie(t,i)})},[b]),C=m.useCallback(t=>{s(i=>i.filter(l=>l.slug!==t)),b(t,()=>le(t))},[b]),j=m.useCallback(()=>{Object.entries(g.current).forEach(([t,i])=>{clearTimeout(i.timer),delete g.current[t],y(t,i.run)})},[y]);return{lines:r,pending:o,error:n,changeQuantity:f,add:x,remove:C,flush:j,clearError:()=>p(null)}}function Ke(){return e.jsx(ce,{moduleKey:"design_cart",children:e.jsx(qe,{})})}function M(){return e.jsx(G,{title:"Design Cart",description:"One-time projects, ready to buy."})}function ke(){return e.jsx("div",{className:"grid gap-6 md:grid-cols-2 xl:grid-cols-3",children:Array.from({length:6}).map((r,s)=>e.jsxs(I,{className:"flex flex-col gap-4 p-6",children:[e.jsx(S,{className:"h-8 w-28"}),e.jsx(S,{className:"h-5 w-2/3"}),e.jsx(S,{className:"h-4 w-full"}),e.jsx(S,{className:"h-4 w-5/6"}),e.jsxs("div",{className:"space-y-2 pt-2",children:[e.jsx(S,{className:"h-3 w-3/4"}),e.jsx(S,{className:"h-3 w-2/3"})]}),e.jsx(S,{className:"mt-2 h-10 w-full"})]},s))})}function Se({lines:r,products:s,pending:o,error:d,totalItems:n,subtotalCents:p,currency:g,checkingOut:w,onQuantity:k,onRemove:y,onCheckout:b}){return e.jsxs("div",{className:"flex flex-col",children:[d&&e.jsxs(Q,{variant:"destructive",className:"mb-4",children:[e.jsx(me,{className:"h-4 w-4"}),e.jsx(K,{children:d})]}),n===0?e.jsxs("div",{className:"rounded-panel border border-dashed px-4 py-8 text-center",children:[e.jsx(q,{"aria-hidden":"true",className:"mx-auto mb-2 h-6 w-6 text-muted-foreground"}),e.jsx("p",{className:"text-sm font-medium",children:"Your cart is empty"}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Add a project and it will show up here."})]}):e.jsxs(e.Fragment,{children:[e.jsx("ul",{className:"space-y-3",children:r.map(f=>{const x=s.find(j=>j.slug===f.slug);if(!x)return null;const C=!!o[f.slug];return e.jsxs("li",{className:"flex items-start justify-between gap-3 text-sm",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate font-medium",children:x.name}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[A(x.price_cents,x.currency)," each · one-time project"]}),e.jsxs("div",{className:"mt-1 flex items-center gap-1",children:[e.jsx(N,{variant:"ghost",size:"icon",className:"h-6 w-6",disabled:C,"aria-label":`Decrease quantity of ${x.name}`,onClick:()=>k(x.slug,f.quantity-1),children:e.jsx(F,{className:"h-3 w-3"})}),e.jsx("span",{className:"w-5 text-center text-xs font-semibold tabular-nums",children:C?e.jsx(E,{className:"mx-auto h-3 w-3 animate-spin"}):f.quantity}),e.jsx(N,{variant:"ghost",size:"icon",className:"h-6 w-6",disabled:C,"aria-label":`Increase quantity of ${x.name}`,onClick:()=>k(x.slug,f.quantity+1),children:e.jsx(V,{className:"h-3 w-3"})}),e.jsx(N,{variant:"ghost",size:"icon",className:"h-6 w-6 text-muted-foreground hover:text-destructive",disabled:C,"aria-label":`Remove ${x.name} from cart`,onClick:()=>y(x.slug),children:e.jsx(H,{className:"h-3 w-3"})})]})]}),e.jsx("span",{className:"whitespace-nowrap font-medium",children:A(x.price_cents*f.quantity,x.currency)})]},f.slug)})}),e.jsxs("div",{className:"mt-4 space-y-2 border-t pt-4 text-sm",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:"Order summary"}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Items"}),e.jsx("span",{className:"tabular-nums",children:n})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Subtotal"}),e.jsx("span",{className:"tabular-nums",children:A(p,g)})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"One-time project pricing"}),e.jsx("span",{className:"text-muted-foreground",children:"No subscription"})]}),e.jsxs("div",{className:"mt-2 flex items-center justify-between rounded-panel bg-muted/60 px-3 py-2.5 text-base",children:[e.jsx("span",{className:"font-semibold",children:"Total due today"}),e.jsx("span",{className:"font-bold tabular-nums",children:A(p,g)})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Taxes, if applicable, are calculated at checkout."})]})]}),e.jsxs(N,{className:"mt-4 w-full gap-2 rounded-full",size:"lg",disabled:n===0||w,onClick:b,children:[w?e.jsx(E,{className:"h-4 w-4 animate-spin"}):e.jsx(q,{className:"h-4 w-4"}),e.jsx("span",{children:w?"Opening checkoutâ¦":"Proceed to checkout"})]}),e.jsxs("p",{className:"mt-3 flex items-center justify-center gap-1.5 text-xs text-muted-foreground",children:[e.jsx(ue,{"aria-hidden":"true",className:"h-3 w-3"}),"Secure payment via Stripe"]})]})}function qe(){const r=W(),{lines:s,pending:o,error:d,changeQuantity:n,add:p,remove:g,flush:w}=Ce(),[k,y]=m.useState(!1),[b,f]=m.useState(!1),{data:x,isLoading:C}=J({queryKey:["design-cart-products"],queryFn:()=>ae()}),j=x?.products??[];ve(!C&&j.length>0);const t=a=>s.find(u=>u.slug===a)?.quantity??0,i=s.reduce((a,u)=>a+u.quantity,0),l=s.reduce((a,u)=>{const h=j.find(T=>T.slug===u.slug);return a+(h?h.price_cents*u.quantity:0)},0),c=j[0]?.currency??"usd",_=async()=>{w(),f(!0);const a=s.map(u=>{const h=j.find(T=>T.slug===u.slug);return h?{slug:h.slug,name:h.name,quantity:u.quantity,unitPriceCents:h.price_cents}:null}).filter(u=>u!==null);if(a.length===0){f(!1);return}try{await re({data:{itemCount:i,subtotalCents:l,currency:c,items:a}})}catch{}y(!1),be("/design-cart"),r({to:"/design-cart/cart"}).finally(()=>f(!1))};if(C)return e.jsxs("div",{className:"space-y-8",children:[e.jsx(M,{}),e.jsx(ke,{})]});if(j.length===0)return e.jsxs("div",{className:"space-y-8",children:[e.jsx(M,{}),e.jsxs(I,{className:"flex flex-col items-center gap-3 px-6 py-20 text-center",children:[e.jsx(q,{"aria-hidden":"true",className:"h-10 w-10 text-muted-foreground"}),e.jsx("p",{className:"text-base font-semibold",children:"No one-time projects available yet"}),e.jsx("p",{className:"max-w-md text-sm text-muted-foreground",children:"The Design Cart menu is empty right now. Browse our monthly plans, or ask your project manager to open a custom request."}),e.jsx(N,{className:"mt-2",onClick:()=>r({to:"/projects",search:{q:"",brand:""}}),children:"Start a project request"})]})]});const v=e.jsx(Se,{lines:s,products:j,pending:o,error:d,totalItems:i,subtotalCents:l,currency:c,checkingOut:b,onQuantity:n,onRemove:g,onCheckout:_});return e.jsxs("div",{className:"space-y-8 pb-24 lg:pb-0",children:[e.jsxs("header",{className:"relative overflow-hidden rounded-surface border bg-card p-6 sm:p-8",children:[e.jsx("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-0 opacity-70",style:{background:"radial-gradient(circle at 8% 0%, c
1olor-mix(in oklab, var(--brand-purple) 12%, transparent) 0, transparent 45%), radial-gradient(circle at 92% 8%, color-mix(in oklab, var(--brand-yellow) 14%, transparent) 0, transparent 50%)"}}),e.jsxs("div",{className:"relative grid grid-cols-[minmax(0,1fr)_auto] items-start gap-4",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("span",{className:"inline-flex items-center gap-2 rounded-full bg-primary/10 px-3 py-1 text-xs font-medium text-primary",children:[e.jsx(oe,{"aria-hidden":"true",className:"h-3.5 w-3.5"}),"One-time projects"]}),e.jsx(M,{}),e.jsx("ul",{className:"flex flex-wrap gap-2 pt-1",children:["Fixed scope","Fixed price","No subscription"].map(a=>e.jsxs("li",{className:"inline-flex items-center gap-1.5 rounded-full border bg-background px-3 py-1 text-xs text-muted-foreground",children:[e.jsx(O,{"aria-hidden":"true",className:"h-3 w-3 text-primary"}),a]},a))})]}),e.jsxs(X,{open:k,onOpenChange:y,children:[e.jsx(Z,{asChild:!0,children:e.jsxs(N,{variant:"outline",className:"gap-2 rounded-full lg:hidden",children:[e.jsx(q,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Cart"}),i>0&&e.jsx(P,{variant:"secondary",children:i})]})}),e.jsxs(ee,{side:"right",className:"flex w-full flex-col gap-0 overflow-y-auto p-6 sm:max-w-sm",children:[e.jsx(se,{className:"p-0 text-left",children:e.jsx(te,{className:"text-base",children:"Your cart"})}),e.jsx("div",{className:"mt-4",children:v})]})]})]})]}),e.jsxs("div",{className:"grid gap-8 lg:grid-cols-[minmax(0,1fr)_320px] lg:items-start",children:[e.jsx("div",{className:"grid gap-6 md:grid-cols-2",children:j.map(a=>{const u=t(a.slug),h=!!o[a.slug];return e.jsxs(I,{"data-cart-section":a.slug,className:`relative flex flex-col gap-4 p-6 transition-all hover:-translate-y-0.5 hover:shadow-md ${u>0?"border-primary/40 ring-1 ring-primary/20":""}`,children:[a.badge&&e.jsx(P,{className:"absolute -top-3 left-6 bg-primary px-3 py-1 text-primary-foreground",children:a.badge}),u>0&&e.jsxs("span",{className:"absolute right-5 top-5 inline-flex items-center gap-1 rounded-full bg-primary/10 px-2.5 py-1 text-xs font-medium text-primary",children:[e.jsx(O,{"aria-hidden":"true",className:"h-3 w-3"}),"In cart"]}),e.jsx("h3",{className:"pr-20 text-lg font-semibold leading-snug",children:a.name}),e.jsxs("div",{className:"flex flex-wrap items-baseline gap-3",children:[e.jsx("span",{className:"text-3xl font-bold tracking-tight",children:A(a.price_cents,a.currency)}),a.turnaround&&e.jsxs("span",{className:"inline-flex items-center gap-1.5 rounded-full bg-muted px-2.5 py-1 text-xs text-muted-foreground",children:[e.jsx(de,{"aria-hidden":"true",className:"h-3 w-3"}),a.turnaround]})]}),a.description&&e.jsx("p",{className:"text-sm leading-relaxed text-muted-foreground",children:a.description}),a.bullets?.length>0&&e.jsx("ul",{className:"space-y-1.5 text-sm text-muted-foreground",children:a.bullets.map(T=>e.jsxs("li",{className:"flex min-w-0 gap-2",children:[e.jsx(O,{className:"mt-0.5 h-4 w-4 shrink-0 text-primary"}),e.jsx("span",{className:"min-w-0",children:T})]},T))}),e.jsx("div",{className:"mt-auto pt-2",children:u===0?e.jsxs(N,{className:"w-full gap-2 rounded-full",disabled:h,onClick:()=>{p(a.slug,1),z.success(`${a.name} added to cart`)},children:[h?e.jsx(E,{className:"h-4 w-4 animate-spin"}):e.jsx(q,{className:"h-4 w-4"}),e.jsx("span",{children:"Add to cart"})]}):e.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-surface border p-1.5",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(N,{variant:"ghost",size:"icon",className:"h-8 w-8",disabled:h,"aria-label":`Decrease quantity of ${a.name}`,onClick:()=>n(a.slug,u-1),children:e.jsx(F,{className:"h-4 w-4"})}),e.jsx("span",{className:"w-8 text-center text-sm font-semibold tabular-nums",children:h?e.jsx(E,{className:"mx-auto h-4 w-4 animate-spin"}):u}),e.jsx(N,{variant:"ghost",size:"icon",className:"h-8 w-8",disabled:h,"aria-label":`Increase quantity of ${a.name}`,onClick:()=>n(a.slug,u+1),children:e.jsx(V,{className:"h-4 w-4"})})]}),e.jsxs(N,{variant:"ghost",size:"sm",className:"gap-1.5 text-muted-foreground hover:text-destructive",disabled:h,"aria-label":`Remove ${a.name} from cart`,onClick:()=>{g(a.slug),z.success(`${a.name} removed from cart`)},children:[e.jsx(H,{className:"h-4 w-4"}),e.jsx("span",{children:"Remove"})]})]})})]},a.slug)})}),e.jsxs(I,{className:"hidden p-5 lg:sticky lg:top-6 lg:block",children:[e.jsxs("div",{className:"mb-4 flex items-center gap-2",children:[e.jsx(q,{"aria-hidden":"true",className:"h-4 w-4 text-muted-foreground"}),e.jsx("h2",{className:"text-sm font-semibold",children:"Your cart"}),i>0&&e.jsx(P,{variant:"secondary",children:i})]}),v]})]}),i>0&&e.jsx("div",{className:"fixed inset-x-0 bottom-0 z-30 border-t bg-background/95 p-3 backdrop-blur lg:hidden",children:e.jsxs(N,{className:"w-full gap-2",onClick:()=>y(!0),children:[e.jsx(q,{className:"h-4 w-4"}),e.jsxs("span",{children:["View cart · ",i," ",i===1?"item":"items"," ·"," ",A(l,c)]})]})})]})}export{Ke as component};
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.