1import{j as e,b as $,a as V,u as oe}from"./vendor-query-CniT1WJL.js";import{r as g,f as me,u as ue,L as U}from"./vendor-react-69GsFwrV.js";import{f as R,$ as pe,a0 as xe,a1 as he,a2 as fe,a3 as ye,a4 as T,N as be,a5 as F,u as ge,a6 as je,a7 as ke,Y as Ne,a8 as ve,a9 as Z,F as q,q as L,V as P,M,G as S,aa as Ce,ab as we,t as N,ac as Se,ad as J,_ as Pe,ae as Ae,af as te,ag as se,ah as Te,Z as ae,ai as Q,aj as G,ak as W,al as H,am as ie,an as Y,ao as _e,m as z,ap as $e}from"./index-KjAD5lCC.js";import{u as ne,A as ze}from"./AddressFormFields-Byy1VLUa.js";import{ag as Oe,a3 as re,aO as Ee,a$ as Le,Z as I,a7 as de,a5 as le,aR as ce,T as De,f as Re,_ as Me,d as Ie,aj as Fe}from"./vendor-ui-Ad3ANzF6.js";import{A as qe}from"./AccountNav-CGK2802V.js";import{O as Ke}from"./OrderStatusPill-CBg1Ze7d.js";import{u as Ue}from"./api-BP6hRV2j.js";import{NEW_REQUEST_HREF as Ve}from"./AccountSupport-BGHEdJsR.js";import"./vendor-forms-q6h4WU-p.js";import"./AccountSection-B7Ueu1lP.js";import"./supportApi-DX1gvRrR.js";const Qe={unpaid:{label:"Unpaid",className:"text-muted-foreground bg-muted"},awaiting_payment:{label:"Awaiting payment",className:"text-amber bg-amber-tint dark:text-amber-bright dark:bg-amber/15"},paid:{label:"Paid",className:"text-vida-green-800 bg-vida-mint-soft dark:text-vida-mint dark:bg-vida-green-700"},refunded:{label:"Refunded",className:"text-muted-foreground bg-muted"}};function Ge({status:t,className:a}){const l=Qe[t]??{label:t.replace(/_/g," "),className:"text-muted-foreground bg-muted"};return e.jsx("span",{className:R("inline-flex items-center text-[10px] px-1.5 py-0.5 rounded font-medium",l.className,a),"data-testid":`chip-payment-status-${t}`,children:l.label})}function X(t){return{line1:t.line1,line2:t.line2??void 0,city:t.city,state:t.state,zip:t.zip}}function We(t){return t.label||t.fullName||t.line1}function K(t){return!!(t.line1.trim()&&t.city.trim()&&t.state.trim()&&t.zip.trim())}function He({onChange:t,initialNew:a,check:l}){const{data:n}=pe(),u=g.useMemo(()=>xe(n??[]),[n]),r=u.length>0,[s,m]=g.useState("saved"),[f,h]=g.useState(null),[i,b]=g.useState({line1:a?.line1??"",line2:a?.line2??"",city:a?.city??"",state:he(a?.state)??a?.state??"",zip:a?.zip??""}),[p,j]=g.useState(!1),[o,w]=g.useState(!1),k=ne(),v=l??k;g.useEffect(()=>{if(!(p||n===void 0)&&(j(!0),!o))if(r){const x=fe(u,"shipping")??u[0];m("saved"),h(x.id),t(X(x))}else m("new"),K(i)&&t(i)},[p,n,r,u,i,t,o]);const A=x=>{w(!0),m("saved"),h(x.id),t(X(x))},c=()=>{w(!0),m("new"),h(null),t(K(i)?i:null)},_=x=>{w(!0),b(x),t(K(x)?x:null)},y=s==="new"||!r;return e.jsxs("div",{className:"space-y-2.5",children:[r&&e.jsxs("fieldset",{className:"space-y-2",children:[u.map(x=>{const d=s==="saved"&&f===x.id;return e.jsxs("button",{type:"button",onClick:()=>A(x),"aria-pressed":d,"data-testid":`switch-saved-address-${x.id}`,className:R("flex w-full items-start gap-3 rounded-card border p-3 text-left transition-colors",d?"border-primary bg-primary/5":"border-card-border bg-card hover:border-primary/40"),children:[e.jsx("span",{className:R("mt-0.5 flex size-4 shrink-0 items-center justify-center rounded-full border",d?"border-primary":"border-ink-3"),"aria-hidden":"true",children:d&&e.jsx("span",{className:"size-2 rounded-full bg-primary"})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-semibold text-ink",children:We(x)}),ye(x,"shipping")&&e.jsx("span",{className:"rounded-pill bg-muted px-2 py-0.5 text-[10px] font-medium text-muted-foreground",children:"Default"})]}),e.jsxs("span",{className:"mt-0.5 block text-xs text-muted-foreground",children:[x.line1,x.line2?`, ${x.line2}`:""," · ",x.city,", ",x.state," ",x.zip]})]})]},x.id)}),e.jsxs("button",{type:"button",onClick:c,"aria-pressed":s==="new","data-testid":"switch-address-enter-new",className:R("flex w-full items-center gap-2 rounded-card border p-3 text-left text-sm font-medium transition-colors",s==="new"?"border-primary bg-primary/5 text-ink":"border-card-border bg-card text-ink-2 hover:border-primary/40"),children:[e.jsx(Oe,{className:"size-4 shrink-0","aria-hidden":"true"}),"Enter a new address"]})]}),y&&e.jsxs("div",{className:"space-y-2.5","data-testid":"switch-new-address-fields",children:[r&&e.jsxs("p",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[e.jsx(re,{className:"size-3.5 shrink-0","aria-hidden":"true"}),"Enter a new address below."]}),e.jsx(ze,{idPrefix:"address-picker",value:i,onChange:x=>_({...i,...x}),check:v})]})]})}const Ye=["unpaid","awaiting_payment"],Be=["shipped","delivered","completed","cancelled","refunded"];function Ze(t){return Be.includes(t.status)?!1:Ye.includes(t.paymentStatus??"")}function Je(){const t=$();return V({mutationFn:async({id:a})=>F(`/api/orders/${a}/cancel`,{method:"POST"}),onSuccess:(a,{id:l})=>{t.invalidateQueries({queryKey:T(l)}),t.invalidateQueries({queryKey:be()})}})}const Xe=[{value:"not_received",label:"It never arrived"},{value:"damaged",label:"It arrived damaged"},{value:"missing_items",label:"Something was missing"},{value:"wrong_items",label:"I received the wrong items"}],et=["in_transit","out_for_delivery","delivered","lost"];function tt(t){return t.trackingNumber?et.includes(t.status):!1}function st(t,a){return oe({queryKey:["my-shipment-issues",t],enabled:a,queryFn:async()=>F(`/api/orders/${t}/shipment-issues`)})}function at(t){const a=$();return V({mutationFn:async l=>F(`/api/orders/${t}/shipment-issues`,{method:"POST",body:JSON.stringify(l),headers:{"content-type":"application/json"}}),onSuccess:()=>{a.invalidateQueries({queryKey:["my-shipment-issues",t]}),a.invalidateQueries({queryKey:T(t)})}})}function it(t){const a=$();return V({mutationFn:async({reportId:l})=>F(`/api/orders/${t}/shipment-issues/${l}/withdraw`,{method:"POST"}),onSuccess:()=>{a.invalidateQueries({queryKey:["my-shipment-issues",t]})}})}const nt={scheduled:"Scheduled",ready:"Ready for pickup",picked_up:"Picked up",no_show:"Missed",cancelled:"Cancelled"};function rt(t){const a=t.paymentMethodType?.replaceAll("_"," "),l=t.paymentMethodBrand?.replaceAll("_"," "),n=t.paymentMethodLast4?` ending ${t.paymentMethodLast4}`:"";return l?`${l}${n}`:a?`${a}${n}`:t.railKey.replaceAll("_"," ")}function dt(t){const a=t.shipments??[],l={created:1,in_transit:2,out_for_delivery:3,delivered:4,return_to_sender:0,cancelled:0,refund_requested:0,lost:0},n=a.reduce((o,w)=>Math.max(o,l[w.status]??0),0),u=a.find(o=>o.lastTrackingAt)??a[a.length-1],r=a.some(o=>o.status==="return_to_sender"),s=a.some(o=>
1o.status!=="cancelled"&&o.status!=="refund_requested"),m=t.status==="delivered"||n>=4,f=!m&&n>=3,h=!m&&!f&&n>=2,i=t.status==="shipped"||t.status==="delivered"||s||m,b=t.paymentStatus==="paid"||i,p=(o,w,k,v,A,c)=>({key:o,label:w,state:k?v?"current":"done":"upcoming",at:A,detail:c}),j=[p("placed","Order placed",!0,!1,t.createdAt),p("paid","Payment confirmed",b,b&&!i,b?t.createdAt:null),p("shipped","Shipped",i,i&&!h&&!f&&!m&&!r)];return r?(j.push({key:"return_to_sender",label:"Returned to sender - contact support",state:"current",variant:"exception",at:u?.lastTrackingAt}),j):(j.push(p("in_transit","In transit",h||f||m,h),p("out_for_delivery","Out for delivery",f||m,f),p("delivered","Delivered",m,m,m?u?.lastTrackingAt:null)),j)}function lt(t){if(!t)return!1;const a=Date.parse(t);return Number.isFinite(a)&&a<=Date.now()}function _t(){const{orderId:t}=me(),{isAuthenticated:a,isLoading:l}=ge(),[,n]=ue(),u=$();g.useEffect(()=>{!l&&!a&&n("/login")},[l,a,n]);const r=Number(t),{data:s,isLoading:m}=je(r,{query:{enabled:a&&!!t,queryKey:T(r)}}),f=s?.paymentStatus,h=f==="awaiting_payment"||f==="unpaid",{data:i}=ke(r,void 0,{query:{enabled:a&&!!r,queryKey:J(r)}}),b=i?.paymentHistory??[],p=Ne(i?.payment?.waitState??null),j=ve(s?.orderNumber),o=h&&i?.payment&&Z(i.payment.railKey)&&i.payment.status!=="paid"&&i.payment.status!=="failed"&&i.payment.status!=="expired"&&i.payment.status!=="cancelled"?i.payment:null,w=i?.payment?.paymentUrl??null,k=h&&i?.payment&&w&&!Z(i.payment.railKey)&&(i.payment.status==="created"||i.payment.status==="pending")&&!lt(i.payment.expiresAt)?i.payment:null,v=h&&i?.payment&&(i.payment.status==="created"||i.payment.status==="pending")?i.payment:null,A=!i?.payment||["expired","failed","cancelled"].includes(i.payment.status),c=h&&!!i&&A&&s?.status==="pending"&&(s?.totalCents??0)>0;if(m)return e.jsxs(q,{width:"narrow",padY:!0,className:"space-y-4",children:[e.jsx(L,{className:"h-4 w-28"}),e.jsx(L,{className:"h-8 w-48"}),e.jsx(L,{className:"h-48 w-full rounded-card"}),e.jsx(L,{className:"h-32 w-full rounded-card"})]});if(!s)return e.jsxs(q,{width:"narrow",className:"py-12 text-center",children:[e.jsx("p",{className:"mb-4 text-ink-2",children:"Order not found."}),e.jsx(P,{asChild:!0,variant:"ghost",size:"sm",children:e.jsx(U,{href:"/account",children:"Back to account"})})]});const _=s,y=_.shippingSelection??null,x=y!==null||_.shippingSelectionError!=null;return e.jsxs(e.Fragment,{children:[e.jsx(qe,{}),e.jsxs(q,{width:"narrow",padY:!0,children:[e.jsxs(U,{href:"/account/orders","data-testid":"back-to-orders",className:"mb-3 inline-flex items-center gap-1.5 text-caption font-medium text-ink-2 transition-colors hover:text-primary",children:[e.jsx(Ee,{className:"size-4","aria-hidden":"true"})," Back to orders"]}),e.jsxs("div",{className:"mb-6 flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"font-mono text-t2 font-bold text-ink tabular-nums","data-testid":"text-order-id",children:["Order ",s.orderNumber??`#${s.id}`]}),e.jsx("p",{className:"mt-0.5 text-caption text-ink-3",children:M(s.createdAt)})]}),e.jsxs("div",{className:"flex flex-col items-end gap-1.5",children:[e.jsx(Ke,{status:s.status}),s.paymentStatus&&e.jsx(Ge,{status:s.paymentStatus})]})]}),s.status!=="cancelled"&&s.status!=="refunded"?e.jsx(ot,{order:s}):e.jsxs(S,{className:"mb-4",children:[e.jsxs("p",{className:"text-sm font-semibold text-ink capitalize",children:["Order ",s.status]}),e.jsx("p",{className:"mt-0.5 text-caption text-ink-3",children:s.status==="refunded"?"This order has been refunded.":"This order has been cancelled."})]}),p&&e.jsxs(S,{className:"mb-4","data-testid":`card-payment-wait-${p.state}`,children:[e.jsx("p",{className:"text-sm font-semibold text-ink",children:p.label}),e.jsx("p",{className:"mt-0.5 text-caption text-ink-3",children:p.customerDetail}),p.shippingNote&&e.jsx("p",{className:"mt-1.5 text-caption text-ink-3",children:p.shippingNote})]}),o&&e.jsx("div",{className:"mb-4",children:e.jsx(Ce,{railKey:o.railKey,amountCents:o.amountCents,discountCents:o.discountCents,referenceCode:o.referenceCode,expiresAt:o.expiresAt,memoDocumentNo:j,instructions:o.instructions,reportPayer:we(d=>$e(r,d))})}),k&&e.jsxs(S,{className:"mb-4","data-testid":"card-resume-payment",children:[e.jsx("h2",{className:"mb-1 text-sm font-semibold text-ink",children:"Finish paying for this order"}),e.jsx("p",{className:"mb-3 text-caption text-ink-3",children:"Your secure checkout is still open. Pick up where you left off to pay by card, Apple Pay, Google Pay, or a pay-over-time plan."}),e.jsx(P,{asChild:!0,size:"sm","data-testid":"button-resume-payment",children:e.jsxs("a",{href:w??"#",rel:"noopener noreferrer",children:["Complete payment · ",N(k.amountCents)]})}),k.expiresAt?e.jsxs("p",{className:"mt-2 text-caption text-ink-3",children:["This checkout link expires ",M(k.expiresAt),". After that you can still choose another payment method below."]}):null]}),(v||c)&&e.jsx(Se,{className:"mb-4",orderId:s.id,currentRailKey:v?.railKey??"",baseAmountCents:v?v.amountCents+v.discountCents:s.totalCents,onSwitched:()=>
1{u.invalidateQueries({queryKey:J(s.id)}),u.invalidateQueries({queryKey:T(s.id)})}}),b.length>0?e.jsxs(S,{className:"mb-4","data-testid":"payment-history",children:[e.jsxs("h2",{className:"mb-3 flex items-center gap-1.5 text-sm font-semibold text-ink",children:[e.jsx(Le,{className:"size-4 text-primary","aria-hidden":"true"})," Payment history"]}),e.jsx("div",{className:"divide-y divide-[--vp-hairline]",children:b.map(d=>e.jsxs("div",{className:"flex items-start justify-between gap-3 py-2.5 first:pt-0 last:pb-0",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-medium capitalize text-ink",children:rt(d)}),e.jsxs("p",{className:"text-caption text-ink-3",children:[M(d.confirmedAt??d.createdAt)," ·"," ",e.jsx("span",{className:"capitalize",children:d.status.replaceAll("_"," ")})]}),d.referenceCode?e.jsxs("p",{className:"mt-0.5 font-mono text-[11px] text-ink-3",children:["Ref ",d.referenceCode]}):null]}),e.jsxs("div",{className:"shrink-0 text-right",children:[e.jsx("p",{className:"font-mono text-sm font-semibold tabular-nums text-ink",children:N(d.paidAmountCents??d.amountCents)}),d.discountCents>
10?e.jsxs("p",{className:"text-[11px] text-primary",children:[N(d.discountCents)," discount"]}):null]})]},d.id))})]}):null,e.jsx(yt,{orderId:s.id}),s.fulfillmentMethod==="pickup"&&s.pickup&&e.jsx(mt,{order:s}),s.status==="pending"&&x?e.jsxs(S,{className:"mb-4","data-testid":"customer-shipping-selection-locked",children:[e.jsxs("h2",{className:"mb-1 flex items-center gap-1.5 text-sm font-semibold text-ink",children:[e.jsx(I,{className:"size-4 text-primary","aria-hidden":"true"})," Shipping confirmed"]}),e.jsx("p",{className:"text-caption text-ink-3",children:y?`${y.carrier} ${y.service} was selected at checkout${y.customerChargeCents>0?` for ${N(y.customerChargeCents)}`:" with shipping included"}. The delivery method is locked for this order.`:"This order's shipping choice is locked. Please contact support if it needs correction."})]}):s.status==="pending"?e.jsx(xt,{order:s}):null,(s.shipments??[]).map(d=>e.jsx(pt,{shipment:d,fallbackTrackingUrl:s.tracking?.trackingUrl??null},d.id)),(s.shipments??[]).length===0&&s.tracking&&e.jsxs(S,{className:"mb-4 flex items-start gap-3",children:[e.jsx("span",{className:"mt-0.5 flex size-10 shrink-0 items-center justify-center rounded-xl bg-vida-mint-soft text-vida-green-700 dark:bg-vida-green-800 dark:text-vida-mint",children:e.jsx(I,{className:"size-4.5","aria-hidden":"true"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-ink",children:"Tracking information"}),s.tracking.carrier&&e.jsxs("p",{className:"text-caption text-ink-3",children:[s.tracking.carrier,s.tracking.trackingNumber?e.jsxs("span",{className:"font-mono tabular-nums",children:[" ","· ",s.tracking.trackingNumber]}):""]}),s.tracking.trackingUrl&&e.jsx("a",{href:s.tracking.trackingUrl,target:"_blank",rel:"noopener noreferrer",className:"mt-0.5 block text-caption font-semibold text-primary hover:text-primary/80","data-testid":"link-tracking",children:"Track shipment â"})]})]}),e.jsxs(S,{className:"mb-4",children:[e.jsxs("h2",{className:"mb-3 flex items-center gap-1.5 text-sm font-semibold text-ink",children:[e.jsx(de,{className:"size-4 text-primary","aria-hidden":"true"})," Order items"]}),s.items.map(d=>{const C=d.productSnapshot,O=typeof C?.name=="string"?C.name:`Variant #${d.variantId}`,B=typeof C?.size=="number"&&C.size>0?`${C.size}${typeof C.unit=="string"?C.unit:""}`:null,E=typeof C?.gift=="string"?C.gift:null;return e.jsxs("div",{className:"flex justify-between gap-3 border-b border-[--vp-hairline] py-2.5 text-sm last:border-0","data-testid":`row-orderitem-${d.id}`,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"font-medium text-ink",children:[O,E&&e.jsxs("span",{className:"ml-1.5 inline-flex items-center gap-1 rounded-pill bg-primary/10 px-1.5 py-0.5 align-middle text-[10px] font-semibold uppercase text-primary",children:[e.jsx(le,{className:"size-3","aria-hidden":"true"}),E==="promo"?"Promo":"Gift"]})]}),e.jsxs("p",{className:"text-caption text-ink-3 tabular-nums",children:[B?`${B} · `:"","Qty: ",d.quantity,E?" · On us":` · ${N(d.unitPriceCents)} each`]})]}),e.jsx("p",{className:"font-mono font-medium text-ink tabular-nums",children:E?"Free":N(d.unitPriceCents*d.quantity)})]},d.id)}),e.jsxs("div",{className:"mt-3 space-y-1.5 pt-2 text-sm",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-ink-3",children:"Subtotal"}),e.jsx("span",{className:"font-mono text-ink tabular-nums",children:N(s.subtotalCents)})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-ink-3",children:"Shipping"}),e.jsx("span",{className:"font-mono text-ink tabular-nums",children:s.shippingCents>0?N(s.shippingCents):"Free"})]}),(s.discounts?.length??0)>0?s.discounts?.map((d,C)=>e.jsxs("div",{className:"flex justify-between","data-testid":"row-promo-discount",children:[e.jsxs("span",{className:"text-ink-3",children:[d.label,d.code?` (${d.code})`:""]}),e.jsxs("span",{className:"font-mono text-primary tabular-nums",children:["â",N(d.discountCents)]})]},`${d.label}-${d.code??"auto"}-${C}`)):(s.promoDiscountCents??0)>0&&e.jsxs("div",{className:"flex justify-between","data-testid":"row-promo-discount",children:[e.jsx("span",{className:"text-ink-3",children:"Discount"}),e.jsxs("span",{className:"font-mono text-primary tabular-nums",children:["â",N(s.promoDiscountCents)]})]}),(()=>{const d=s.storeCreditAppliedCents??0,C=Math.min(s.storeCreditCashAppliedCents??0,d),O=d-C;return e.jsxs(e.Fragment,{children:[C>0&&e.jsxs("div",{className:"flex justify-between","data-testid":"row-vidapay-paid",children:[e.jsx("span",{className:"text-ink-3",children:"Paid via VidaPay"}),e.jsxs("span",{className:"font-mono tabular-nums text-ink",children:["â",N(C)]})]}),O>0&&e.jsxs("div",{className:"flex justify-between","data-testid":"row-store-credit",children:[e.jsx("span",{className:"text-ink-3",children:"Vida Points"}),e.jsxs("span",{className:"font-mono text-primary tabular-nums",children:["â",N(O)]})]})]})})(),e.jsxs("div",{className:"flex justify-between border-t border-[--vp-hairline] pt-2 font-bold",children:[e.jsx("span",{className:"text-ink",children:"Total"}),e.jsx("span",{className:"font-mono text-ink tabular-nums",children:N(s.totalCents)})]}),(()=>{const d=Math.min(s.storeCreditCashAppliedCents??0,s.storeCreditAppliedCents??0);return d<=0?null:e.jsxs("div",{className:"flex justify-between pt-1 text-sm font-semibold","data-testid":"row-paid-via-vidapay",children:[e.jsx("span",{className:"text-ink-2",children:"You paid (VidaPay + other)"}),e.jsx("span",{className:"font-mono tabular-nums text-ink",children:N(s.totalCents+d)})]})})()]})]}),s.shippingAddress&&e.jsxs(S,{className:"mb-4",children:[e.jsx("h2",{className:"mb-2 text-sm font-semibold text-ink",children:"Shipped to"}),e.jsxs("address",{className:"text-sm not-italic text-ink-2",children:[s.shippingAddress.firstName," ",s.shippingAddress.lastName,e.jsx("br",{}),s.shippingAddress.line1,s.shippingAddress.line2?`, ${s.shippingAddress.line2}`:"",e.jsx("br",{}),s.shippingAddress.city,", ",s.shippingAddress.state," ",s.shippingAddress.zip,e.jsx("br",{}),s.shippingAddress.country]})]}),Ze(s)&&e.jsx(ft,{order:s}),e.jsx(ht,{order:s}),e.jsx("p",{className:"text-caption text-ink-3",children:"All compounds in this order are supplied strictly for laboratory research use only, not for human or veterinary use."})]})]})}function ct(t){const a=t.pickup,l=a?.status,n=l==="picked_up"||t.status==="delivered",u=l==="ready"||n,r=t.paymentStatus==="paid"||u||n,s=(m,f,h,i,b,p)=>({key:m,label:f,state:h?i?"current":"done":"upcoming",at:b,detail
1:p});return[s("placed","Order placed",!0,!1,t.createdAt),s("paid","Payment confirmed",r,r&&!u,r?t.createdAt:null),s("ready","Ready for pickup",u,u&&!n,null,a?`Scheduled ${ae(a.slotStart,a.timezone)}`:null),s("picked_up","Picked up",n,n)]}function ot({order:t}){const a=t.fulfillmentMethod==="pickup",l=a?ct(t):dt(t),n=t.shipments??[],u=n.find(i=>i.lastTrackingAt)??n[n.length-1],r=t.status==="delivered"||n.some(i=>i.status==="delivered"),s=n.some(i=>i.status==="return_to_sender"),m=!a&&!r&&!s?u?.estDeliveryDate??null:null,f=a?null:u?.lastTrackingSummary??null,h=a?null:u?.lastTrackingAt??null;return e.jsxs(S,{className:"mb-4","data-testid":"order-timeline",children:[e.jsxs("h2",{className:"mb-3 flex items-center gap-1.5 text-sm font-semibold text-ink",children:[a?e.jsx(ce,{className:"size-4 text-primary","aria-hidden":"true"}):e.jsx(I,{className:"size-4 text-primary","aria-hidden":"true"})," ",a?"Pickup status":"Order status"]}),m||f?e.jsxs("div",{className:"mb-3 space-y-1 rounded-xl bg-muted/60 px-3 py-2","data-testid":"tracking-summary",children:[m?e.jsxs("p",{className:"text-caption text-ink-2","data-testid":"est-delivery",children:[e.jsx("span",{className:"font-semibold text-ink",children:"Estimated delivery:"})," ",e.jsx("span",{className:"tabular-nums",children:Pe(m)})]}):null,f?e.jsxs("p",{className:"text-caption text-ink-3","data-testid":"last-scan",children:[f,h?e.jsxs("span",{className:"tabular-nums",children:[" ","· ",Ae(h,{suffix:!0})]}):null]}):null]}):null,e.jsx("ol",{className:"space-y-0",children:l.map((i,b)=>{const p=b===l.length-1,j=i.state!=="upcoming",o=i.variant==="exception";return e.jsxs("li",{className:"flex gap-3","data-testid":`timeline-step-${i.key}`,"data-state":i.state,children:[e.jsxs("div",{className:"flex flex-col items-center",children:[o?e.jsx(De,{className:"size-5 shrink-0 text-danger","aria-hidden":"true"}):i.state==="upcoming"?e.jsx(Re,{className:"size-5 shrink-0 text-ink-3/40","aria-hidden":"true"}):e.jsx(Me,{className:`size-5 shrink-0 ${i.state==="current"?"text-primary":"text-vida-green-700"}`,"aria-hidden":"true"}),!p&&e.jsx("span",{className:`my-0.5 w-px flex-1 ${j?"bg-vida-mint":"bg-[--vp-hairline]"}`,"aria-hidden":"true"})]}),e.jsxs("div",{className:`min-w-0 pb-4 ${p?"pb-0":""}`,children:[e.jsxs("p",{className:`text-sm font-medium ${o?"text-danger":i.state==="upcoming"?"text-ink-3":"text-ink"}`,children:[i.label,i.state==="current"&&!o&&e.jsx("span",{className:"ml-2 text-caption font-semibold text-primary",children:"Current"})]}),i.at&&e.jsx("p",{className:"mt-0.5 text-caption text-ink-3 tabular-nums",children:M(i.at)}),i.detail&&e.jsx("p",{className:"mt-0.5 text-caption text-ink-2",children:i.detail})]})]},i.key)})})]})}function mt({order:t}){const a=t.pickup,l=$(),{toast:n}=z(),[u,r]=g.useState(!1),[s,m]=g.useState(null),{data:f}=te(),{data:h}=se(),i=Te();if(!a)return null;const b=f?.find(o=>o.id===a.locationId)??null,p=(a.status==="scheduled"||a.status==="ready")&&!!b&&!!h,j=()=>{s&&i.mutate({id:t.id,data:{slotStart:s}},{onSuccess:o=>{l.setQueryData(T(t.id),o),r(!1),m(null),n({title:"Pickup time updated"})},onError:o=>{n({title:"Couldn't reschedule",description:o.data?.error??"That time is no longer available. Try another.",variant:"destructive"})}})};return e.jsxs(S,{className:"mb-4","data-testid":"pickup-card",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("h2",{className:"mb-2 flex items-center gap-1.5 text-sm font-semibold text-ink",children:[e.jsx(ce,{className:"size-4 text-primary","aria-hidden":"true"})," Local pickup"]}),e.jsx("span",{className:"rounded-pill bg-vida-mint-soft px-2 py-0.5 text-caption font-medium text-vida-green-700 dark:bg-vida-green-800 dark:text-vida-mint",children:nt[a.status]??a.status})]}),e.jsx("p",{className:"text-sm font-medium text-ink",children:ae(a.slotStart,a.timezone)}),e.jsxs("p",{className:"mt-1 flex items-start gap-1.5 text-caption text-ink-2",children:[e.jsx(re,{className:"mt-0.5 size-3.5 shrink-0 text-ink-3","aria-hidden":"true"}),e.jsxs("span",{children:[e.jsx("span",{className:"font-medium text-ink",children:a.locationName}),a.address?e.jsxs(e.Fragment,{children:[e.jsx("br",{}),a.address]}):null]})]}),a.instructions&&e.jsx("p",{className:"mt-1.5 text-caption text-ink-3",children:a.instructions}),p&&e.jsx(P,{variant:"ghost",size:"sm",className:"mt-3",onClick:()=>{m(null),r(!0)},"data-testid":"button-reschedule-pickup",children:"Change pickup time"}),e.jsx(Q,{open:u,onOpenChange:r,children:e.jsxs(G,{className:"w-[calc(100vw-2rem)] max-w-md",children:[e.jsx(W,{children:e.jsx(H,{children:"Change pickup time"})}),b&&h?e.jsx(ie,{location:b,settings:h,value:s,onChange:m}):e.jsx("p",{className:"text-sm text-ink-3",children:"Pickup scheduling is unavailable right now."}),e.jsxs(Y,{children:[e.jsx(P,{variant:"ghost",onClick:()=>r(!1),children:"Cancel"}),e.jsx(P,{onClick:j,disabled:!s||i.isPending,children:i.isPending?"Savingâ¦":"Confirm new time"})]})]})})]})}const ut={created:"Label created",in_transit:"In transit",out_for_delivery:"Out for delivery",delivered:"Delivered",return_to_sender:"Return to
1sender",cancelled:"Cancelled",refund_requested:"Refund requested",lost:"Did not arrive"};function pt({shipment:t,fallbackTrackingUrl:a}){const l=t.trackingUrl??a??null;return e.jsxs(S,{className:"mb-4 flex items-start gap-3","data-testid":`shipment-${t.id}`,children:[e.jsx("span",{className:"mt-0.5 flex size-10 shrink-0 items-center justify-center rounded-xl bg-vida-mint-soft text-vida-green-700 dark:bg-vida-green-800 dark:text-vida-mint",children:e.jsx(de,{className:"size-4.5","aria-hidden":"true"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"text-sm font-semibold text-ink",children:[t.carrier,e.jsx("span",{className:"ml-2 text-caption font-medium text-ink-3",children:ut[t.status]??t.status})]}),t.trackingNumber&&e.jsx("p",{className:"text-caption text-ink-3 font-mono tabular-nums",children:t.trackingNumber}),t.lastTrackingSummary&&e.jsx("p",{className:"mt-0.5 text-caption text-ink-2",children:t.lastTrackingSummary}),l&&e.jsx("a",{href:l,target:"_blank",rel:"noopener noreferrer",className:"mt-0.5 inline-block text-caption font-semibold text-primary hover:text-primary/80","data-testid":`link-tracking-${t.id}`,children:"Track shipment â"})]})]})}const D={ship:"Shipping",pickup:"Local pickup",delivery:"Local delivery"};function xt({order:t}){const a=$(),{toast:l}=z(),[n,u]=g.useState(null),r=_e(),{data:s}=te(),{data:m}=se(),f=t.shippingAddress??null,[h,i]=g.useState(null),[b,p]=g.useState(null),[j,o]=g.useState(null),w=ne(),k=s??[],v=k.find(y=>y.id===h)??k[0]??null,A=["ship","pickup","delivery"].filter(y=>y!==t.fulfillmentMethod),c=()=>{u(null),p(null),o(null)},_=async()=>{if(!n)return;if((n==="ship"||n==="delivery")&&j&&!await w.ensureResolvedForSubmit(j)){l
1({title:"USPS suggested a different address",description:"Choose Use suggested or Keep mine, then switch."});return}const y=n==="pickup"?{method:n,pickup:{locationId:v?.id,slotStart:b??void 0}}:{method:n,shippingAddress:j??void 0};r.mutate({id:t.id,data:y},{onSuccess:x=>{a.setQueryData(T(t.id),x),a.invalidateQueries({queryKey:T(t.id)});const d=x.conversion,C=d?.refundedToCreditCents?` ${N(d.refundedToCreditCents)} was credited to your VidaCredit.`:d?.balanceDueCents?` ${N(d.balanceDueCents)} is now due. We'll send a payment link.`:"";l({title:`Switched to ${D[n]}`,description:C||void 0}),c()},onError:x=>l({title:"Couldn't switch",description:x.data?.error??"Please try again.",variant:"destructive"})})};return e.jsxs(S,{className:"mb-4",children:[e.jsxs("h2",{className:"mb-1 flex items-center gap-1.5 text-sm font-semibold text-ink",children:[e.jsx(I,{className:"size-4 text-primary","aria-hidden":"true"})," Delivery method"]}),e.jsxs("p",{className:"text-caption text-ink-3",children:["Currently"," ",e.jsx("span",{className:"font-medium text-ink",children:D[t.fulfillmentMethod??"ship"]}),". You can change it while the order is still being prepared."]}),e.jsx("div",{className:"mt-2.5 flex flex-wrap gap-2",children:A.map(y=>e.jsxs(P,{variant:"ghost",size:"sm",onClick:()=>{u(y),p(null)},children:["Switch to ",D[y]]},y))}),e.jsx(Q,{open:n!==null,onOpenChange:y=>!y&&c(),children:e.jsxs(G,{className:"w-[calc(100vw-2rem)] max-w-md",children:[e.jsx(W,{children:e.jsxs(H,{children:["Switch to ",n?D[n]:""]})}),n==="pickup"?m&&v?e.jsxs("div",{className:"min-w-0 space-y-3",children:[k.length>1&&e.jsx("div",{className:"flex flex-wrap gap-1.5",children:k.map(y=>e.jsx("button",{type:"button",onClick:()=>{i(y.id),p(null)},className:`rounded-card border px-2 py-1 text-xs ${v.id===y.id?"border-primary bg-primary text-primary-foreground":"border-card-border"}`,children:y.name},y.id))}),e.jsx(ie,{location:v,settings:m,value:b,onChange:p})]}):e.jsx("p",{className:"text-sm text-ink-3",children:"Pickup isn't available right now."}):e.jsxs("div",{className:"space-y-2.5",children:[e.jsx(He,{onChange:o,initialNew:f,check:w}),n==="delivery"&&e.jsx("p",{className:"text-caption text-ink-3",children:"We'll confirm your address is within our local delivery area. A delivery fee may apply."})]}),e.jsxs(Y,{children:[e.jsx(P,{variant:"ghost",onClick:c,children:"Cancel"}),e.jsx(P,{onClick:()=>{_()},disabled:r.isPending||n==="pickup"&&!b||(n==="ship"||n==="delivery")&&!j,children:r.isPending?"Switchingâ¦":"Confirm"})]})]})})]})}function ht({order:t}){const{toast:a}=z(),l=t.shipments??[],n=l.filter(tt),u=st(t.id,l.length>0),r=at(t.id),s=it(t.id),[m,f]=g.useState(!1),[h,i]=g.useState("not_received"),[b,p]=g.useState(""),[j,o]=g.useState(null),w=(u.data?.reports??[]).filter(c=>!["approved","denied","withdrawn"].includes(c.status));if(l.length===0)return null;const k=j??n[0]?.id??null,v=b.trim().length<10,A=()=>{k==null||v||r.mutate({shipmentId:k,kind:h,description:b.trim()},{onSuccess:c=>{f(!1),p(""),a({title:c.alreadyOpen?"You have already told us":"Report received",description:c.alreadyOpen?"We are already looking into this parcel and will be in touch.":"A member of our team will look into this and get back to you."})},onError:c=>{f(!1),a({title:"Could not send that",description:c.message,variant:"destructive"})}})};return e.jsxs(S,{className:"mb-4","data-testid":"shipment-issue-card",children:[e.jsx("h2",{className:"text-h4 mb-1",children:"Problem with your delivery?"}),w.length>0?e.jsx("div",{className:"space-y-2","data-testid":"shipment-issue-open",children:w.map(c=>e.jsxs("div",{className:"text-body-sm",children:[e.jsxs("p",{children:["We are looking into your report about this order."," ",e.jsxs("span",{className:"text-ink-3",children:["(",c.status==="needs_customer"?"we need something from you":"in progress",")"]})]}),c.staffNote&&e.jsx("p",{className:"mt-1 text-ink-2",children:c.staffNote}),e.jsx(P,{variant:"ghost",size:"sm",className:"mt-1 px-0","data-testid":`withdraw-issue-${c.id}`,onClick:()=>s.mutate({reportId:c.id},{onSuccess:()=>a({title:"Thanks for letting us know",description:"We have closed the report."})}),children:"I found it - close this"})]},c.id))}):n.length===0?e.jsx("p",{className:"text-body-sm text-ink-2","data-testid":"shipment-issue-not-yet",children:"This order has not shipped far enough for us to trace it yet. Once it is moving with the carrier you will be able to report a problem here."}):m?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-caption text-ink-2",htmlFor:`issue-kind-${t.id}`,children:"What happened?"}),e.jsx("select",{id:`issue-kind-${t.id}`,className:"w-full rounded-md border border-line-2 bg-transparent px-3 py-2 text-body-sm",value:h,onChange:c=>i(c.target.value),"data-testid":"issue-kind",children:Xe.map(c=>e.jsx("option",{value:c.value,children:c.label},c.value))})]}),n.length>1&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-caption text-ink-2",htmlFor:`issue-parcel-${t.id}`,children:"Which parcel?"}),e.jsx("select",{id:`issue-parcel-${t.id}`,className:"w-full rounded-md border border-line-2 bg-transparent px-3 py-2 text-body-sm",value:k??"",onChange:c=>o(Number(c.target.value)),"data-testid":"issue-parcel",children:n.map(c=>e.jsx("option",{value:c.id,children:c.trackingNumber??`Parcel #${c.id}`},c.id))})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-caption text-ink-2",htmlFor:`issue-desc-${t.id}`,children:"Tell us what happened"}),e.jsx("textarea",{id:`issue-desc-${t.id}`,rows:4,className:"w-full rounded-md border border-line-2 bg-transparent px-3 py-2 text-body-sm",value:b,onChange:c=>p(c.target.value),placeholder:"When did you expect it? Has anyone else at your address checked?","data-testid":"issue-description"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(P,{disabled:v||k==null||r.isPending,onClick:A,"data-testid":"submit-shipment-issue",children:"Send report"}),e.jsx(P,{variant:"ghost",onClick:()=>f(!1),children:"Cancel"})]})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-body-sm text-ink-2 mb-2",children:"Tell us what happened and we will look into it. Every report is reviewed by a person."}),e.jsx(P,{variant:"light","data-testid":"open-shipment-issue",onClick:()=>f(!0),children:"Report a problem"})]})]})}function ft({order:t}){const{toast:a}=z(),[l,n]=g.useState(!1),u=Je(),r=()=>{u.mutate({id:t.id},{onSuccess:()=>{n(!1),a({title:"Order cancelled",description:"Any value on this order is back in your VidaCredit balance."})},onError:s=>{n(!1),a({title:"Couldn't cancel",description:s.message,variant:"destructive"})}})};return e.jsxs(S,{className:"mb-4","data-testid":"cancel-order-card",children:[e.jsx("h2",{className:"mb-1 text-sm font-semibold text-ink",children:"Need to make a change?"}),e.jsx("p",{className:"text-caption text-ink-3",children:"Changed your mind? You can cancel while this order is still unpaid and hasn't shipped."}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-3",children:[e.jsx(P,{variant:"destructive",size:"sm",onClick:()=>n(!0),"data-testid":"button-cancel-order",children:"Cancel order"}),e.jsx(U,{href:Ve,className:"text-caption font-medium text-ink-3 underline-offset-2 hover:text-primary hover:underline","data-testid":"link-contact-support",children:"Contact us about this order"})]}),e.jsx(Q,{open:l,onOpenChange:n,children:e.jsxs(G,{className:"w-[calc(100vw-2rem)] max-w-md",children:[e.jsx(W,{children:e.jsx(H,{children:"Cancel this order?"})}),e.jsxs("p",{className:"text-sm text-ink-2",children:["This will cancel order ",t.orderNumber??`#${t.id}`,". Anything you have already paid is returned as VidaCredit, not to your original payment method, and any VidaCredit you applied goes back to your balance. This can't be und
1one."]}),e.jsxs(Y,{children:[e.jsx(P,{variant:"ghost",onClick:()=>n(!1),children:"Keep order"}),e.jsx(P,{variant:"destructive",onClick:r,disabled:u.isPending,"data-testid":"confirm-cancel-order",children:u.isPending?"Cancellingâ¦":"Cancel order"})]})]})})]})}const ee={active:{label:"Active",className:"bg-vida-mint-soft text-vida-green-700 dark:bg-vida-green-800 dark:text-vida-mint"},redeemed:{label:"Redeemed",className:"bg-blue-100 text-blue-700 dark:bg-blue-400/10 dark:text-blue-300"},expired:{label:"Expired",className:"bg-amber-tint text-amber dark:bg-amber/15 dark:text-amber-bright"},disabled:{label:"Disabled",className:"bg-red-100 text-red-700 dark:bg-red-400/10 dark:text-red-300"},pending:{label:"Payment pending",className:"bg-muted text-ink-3"}};function yt({orderId:t}){const{toast:a}=z(),[l,n]=g.useState(!1),{data:u}=Ue(),r=u?.find(h=>h.orderId===t);if(!r)return null;const s=ee[r.status]??ee.pending,m=r.deliverTo==="recipient",f=async()=>{if(r.code)try{await navigator.clipboard.writeText(r.code),n(!0),setTimeout(()=>n(!1),2e3)}catch{a({title:"Copy failed",description:"Select the code to copy it.",variant:"destructive"})}};return e.jsxs(S,{className:"mb-4","data-testid":"vidagrant-card",children:[e.jsxs("div",{className:"mb-2 flex items-start justify-between gap-3",children:[e.jsxs("h2",{className:"flex items-center gap-1.5 text-sm font-semibold text-ink",children:[e.jsx(le,{className:"size-4 text-vida-gold-700","aria-hidden":"true"})," VidaGrant"]}),e.jsx("span",{className:`rounded-pill px-2 py-0.5 text-caption font-medium ${s.className}`,"data-testid":"vidagrant-status",children:s.label})]}),e.jsxs("div",{className:"space-y-1.5 text-sm",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-ink-3",children:"Value"}),e.jsx("span",{className:"font-mono font-medium text-ink tabular-nums",children:N(r.valueCents)})]}),r.remainingCents!=null&&r.remainingCents!==r.valueCents&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-ink-3",children:"Remaining"}),e.jsx("span",{className:"font-mono font-medium text-ink tabular-nums",children:N(r.remainingCents)})]}),m&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-ink-3",children:"Gift to"}),e.jsx("span",{className:"font-medium text-ink",children:r.recipientName||r.recipientEmail||"Recipient"})]})]}),r.code?e.jsxs("div",{className:"mt-3",children:[e.jsx("p",{className:"mb-1 text-caption uppercase tracking-wide text-ink-3",children:"Your VidaCode"}),e.jsxs("div",{className:"flex items-center gap-2 rounded-card border border-vida-gold-500/40 bg-vida-gold-soft px-3 py-2.5",children:[e.jsx("code",{className:"min-w-0 flex-1 truncate font-mono text-base font-bold text-vida-gold-700",children:r.code}),e.jsxs("button",{type:"button",onClick:f,"aria-label":"Copy VidaCode","data-testid":"vidagrant-copy",className:"inline-flex items-center gap-1 rounded-md px-2 py-1 text-caption font-medium text-vida-gold-700 hover:bg-white/40",children:[l?e.jsx(Ie,{className:"size-3.5"}):e.jsx(Fe,{className:"size-3.5"}),l?"Copied":"Copy"]})]}),e.jsx("p",{className:"mt-2 text-caption text-ink-3",children:m?"We emailed this VidaCode to your recipient. Redeem it from any VidaPeps account.":"Redeem this VidaCode from your account to add the credit to your VidaCredit balance."})]}):e.jsx("p",{className:"mt-3 rounded-card bg-muted/60 px-3 py-2 text-caption text-ink-3",children:"Your VidaCode will appear here once your payment clears."})]})}export{_t 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.