1(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,97051,156075,524198,51819,102283,186855,490108,284864,867074,445799,e=>{"use strict";var t=e.i(695886),r=e.i(708828),n=e.i(500999),s=e.i(888926),a=e.i(497333);let i=(0,a.default)("chevron-up",[["path",{d:"m18 15-6-6-6 6",key:"153udz"}]]);var l=e.i(624678),o=e.i(443523),d=e.i(64794),c=e.i(974623),u=e.i(418769),x=e.i(422496);let m=/<\/?br\s*\/?>|[\s,;/]+/gi;function p(e){return e?String(e).split(m).map(e=>e.replace(/<[^>]*>/g,"").trim()).filter(e=>e.length>=5):[]}function h(e){let t=new Set,r=[];for(let n of e)for(let e of p(n)){let n=e.toUpperCase();t.has(n)||(t.add(n),r.push(e))}return r}var f=e.i(892976);function g(e){return Math.abs(Number(e??0))}function b(e){let t=String(e??"");return t.includes(",")||t.includes('"')||t.includes("\n")?'"'+t.replace(/"/g,'""')+'"':t}let y=["ship","discount","other charge","othcharge","markup","subtotal","payment"],v=/\b(ups|fedex|usps|dhl|shipping|freight|discount)\b/i;function j(e){if(e.itemType){let t=e.itemType.toLowerCase();if(y.some(e=>t.includes(e)))return!0}let t=`${e.itemName||""} ${e.description||""}`;return!!t&&v.test(t)}function N(e){return e.description&&e.description.trim()||function(e){if(!e)return"";let t=e.split(" : ");return t.length>1?t[t.length-1].trim():e.trim()}(e.itemName||"")||""}function w(e,t){let r=new Blob([e],{type:"application/vnd.ms-excel;charset=utf-8;"}),n=URL.createObjectURL(r),s=document.createElement("a");s.href=n,s.download=t,s.click(),URL.revokeObjectURL(n)}function k(e,t){(0,f.downloadCsv)(e,t)}let S={canPayInvoices:!1,modernXlsxEnabled:!1,onPayInvoice:null,loadModernXlsxExporter:null,cart:null,invoiceApiBase:"/api/customer/invoices",ordersApiBase:"/api/customer/orders",paymentsApiBase:"/api/customer/payments",returnsPdfBase:"/api/customer/returns",refundsApiBase:"/api/customer/refunds",showBuyAgain:!1,showAddLine:!1,renderLineExtras:null,approval:null},C=(0,r.createContext)(S);function $({value:e,children:r}){let n={...S,...e};return(0,t.jsx)(C.Provider,{value:n,children:r})}function I(){return(0,r.useContext)(C).cart}function D(){return(0,r.useContext)(C).canPayInvoices}function T(){return(0,r.useContext)(C).onPayInvoice}function P(){return(0,r.useContext)(C).invoiceApiBase}function L(){return(0,r.useContext)(C).paymentsApiBase}function E(){return(0,r.useContext)(C).refundsApiBase}let O=(0,a.default)("file-spreadsheet",[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M8 13h2",key:"yr2amv"}],["path",{d:"M14 13h2",key:"un5t4a"}],["path",{d:"M8 17h2",key:"2yhykz"}],["path",{d:"M14 17h2",key:"10kma7"}]]);var A=e.i(318479);function M({isDropShip:e,fallbackOrigin:r}){let n=null;return(!0===e?n="TN":!1===e?n="CA":("CA"===r||"TN"===r)&&(n=r),n)?(0,t.jsx)("span",{title:`Ships from ${n}`,className:"mr-1.5 inline-flex items-center rounded border border-border-subtle bg-surface px-1 py-px align-middle text-[9px] font-medium text-text-tertiary",children:n}):null}var U=e.i(538867),R=e.i(745533),F=e.i(787401),q=e.i(90605),B=e.i(928730),_=e.i(210997);function z({value:e,label:n,size:s="sm",className:a=""}){let[i,l]=(0,r.useState)(!1),o=(0,r.useRef)(null);async function d(t){t.stopPropagation(),t.preventDefault();try{await navigator.clipboard.writeText(e),l(!0),o.current&&clearTimeout(o.current),o.current=setTimeout(()=>l(!1),1500)}catch{}}(0,r.useEffect)(()=>()=>{o.current&&clearTimeout(o.current)},[]);let c="md"===s?"h-3.5 w-3.5":"h-3 w-3";return(0,t.jsx)("span",{role:"button",tabIndex:0,"aria-label":i?`${e} copied`:`Copy ${n} ${e}`,title:i?"Copied!":`Copy ${n}`,onClick:d,onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&d(e)},className:`inline-flex shrink-0 cursor-pointer items-center justify-center rounded text-text-tertiary transition-colors hover:bg-surface-elevated hover:text-text-primary focus:outline-none focus-visible:ring-2 focus-visible:ring-accent ${"md"===s?"h-10 w-10 -m-2.5":"h-6 w-6 -my-1"} ${a}`,children:i?(0,t.jsx)(R.Check,{className:`${c} text-success`}):(0,t.jsx)(_.Copy,{className:c})})}var H=e.i(991834),W=e.i(56266),K=e.i(895206),V=e.i(605259);function Q(e){if(!e)return null;let t=/^(\d{4})-(\d{2})-(\d{2})/.exec(e),r=t?Date.UTC(Number(t[1]),Number(t[2])-1,Number(t[3])):Date.parse(e);return Number.isNaN(r)?null:r}function X(e,t){return Math.floor((t-e)/864e5)}let Z={state:"delivered",label:"Delivered"};function G(e){return/\b(picked|packed)\b(?!\s*up)/.test((e??"").toLowerCase())}function Y(e){return G(e)?"Created":"Shipped"}function J(e,t){let r=Q(t)??Date.parse(t),n=(e.upsTrackingStatus||e.status||"").toLowerCase();if(e.deliveryEvidence?.state==="delivered")return{...Z,date:e.deliveryEvidence.deliveredDay??void 0};if(e.deliveryEvidence?.state==="partially-delivered")return{state:"partially-delivered",label:"Partially delivered"};let s=e.deliveryEvidence?.packages.some(e=>e.evidence?.correction)??!1,a=e.deliveryEvidence?.packages.some(e=>null!=e.evidence)??!1;if(a){let t=e.deliveryEvidence.packages.map(e=>e.evidence?.state);n=t.includes("exception")?"exception":t.includes("out-for-delivery")?"out for delivery":t.includes("in-transit")?"in transit":t.includes("label-created")?"label created":"shipped"}if(s&&e.deliveryEvidence?.state==="unconfirmed")return{state:"shipped",label:"Shipped"};let i=(e.trackingNumbers??[]).filter(e=>e&&e.length>=5).length>0,l=!!e.containerRef||(e.containerTracking??[]).filter(e=>e&&e.length>=5).length>0,o=Q(e.date),d=n.includes("label")||n.includes("created")||n.includes("ready");if(!a&&/^(?:delivered|delivered\s+(?:on|at|to)\b[^\n]*)$/i.test(n.trim()))return/sender|shipper|return/i.test(n)?{state:"exception",label:"Exception",issue:"exception"}:e.containerArrived?{...Z,date:e.containerArrived}:Z;if(/exception|action needed|returned to sender|customs hold|address correction/.test(n))return{state:"exception",label:"Exception",issue:"exception"};if(l){if(e.containerDelivered&&!s)return{...Z,date:e.containerArrived??void 0};let t=Q(e.containerEta),n=null!=t&&null!=r&&t<r;if(d){let t=null!=o&&null!=r?X(o,r):0;return{state:"pending-pickup",label:"Label created â no carrier scan",date:e.containerEta??void 0,dateIsEta:!!e.containerEta,issue:t>=3?"no-carrier-scan":void 0}}return{state:"in-transit",label:"In transit",date:e.containerEta??void 0,dateIsEta:!0,issue:n?"past-eta":void 0}}if(G(n))return{state:"pending",label:n.includes("packed")?"Packed â not shipped yet":"Picked â not shipped yet"};if(n.includes("out for delivery"))return{state:"out-for-delivery",label:"Out for delivery"};if(n.includes("exception")||n.includes("action needed")||n.includes("returned to sender"))return{state:"exception",label:"Exception",issue:"exception"};if(n.includes("transit")||n.includes("picked up")){let t=Q(e.deliveryDate),n=null!=t&&null!=r&&t<r,s=null!=o&&null!=r?X(o,r):0;return{state:"in-transit",label:"In transit",date:e.deliveryDate??void 0,dateIsEta:!!e.deliveryDate,issue:n||null==t&&s>=7?"stalled-in-transit":void 0}}if(d)return{state:"pending-pickup",label:"Label created â awaiting carrier pickup",issue:(null!=o&&null!=r?X(o,r):0)>=3?"no-carrier-scan":void 0};if(i){let t=Q(e.deliveryDate),n=null!=t&&null!=r&&t<r;return{state:"shipped",label:e.deliveryEvidence?.historyUnavailable?"Shipped - tracking history unavailable":"Shipped",date:e.deliveryDate??void 0,dateIsEta:!!e.deliveryDate,issue:n?"stalled-in-transit":void 0}}return/\bshipped\b/.test(n)?{state:"shipped",label:"Shipped"}:{state:"pending",label:"Pending pickup"}}var ee=e.i(279392),et=e.i(180422);function er(e){if(!e)return"";let t=/^(\d{4})-(\d{2})-(\d{2})/.exec(e);return t?`${t[2]}/${t[3]}/${t[1].slice(2)}`:""}function en(e){let t=(e.trackingNumbers??[]).filter(e=>e&&e.length>=5);return t.length>0?t:(e.containerTracking??[]).filter(e=>e&&e.length>=5)}let es={shipped:{cls:"bg-surface text-text-secondary",word:"Shipped"}
1,"partially-delivered":{cls:"bg-info-bg text-info",word:"Partially delivered"},delivered:{cls:"bg-success-bg text-success",word:"Delivered"},"out-for-delivery":{cls:"bg-warning-bg text-warning",word:"Out for delivery"},"in-transit":{cls:"bg-info-bg text-info",word:"In transit"},"pending-pickup":{cls:"bg-surface text-text-secondary",word:"Label created"},pending:{cls:"bg-surface text-text-secondary",word:"Pending"},exception:{cls:"bg-error-bg text-error",word:"Exception"}};function ea({s:e,leg:r,onClick:n,canOpenInbound:s}){let a="air"===e.mode?"â":"ocean"===e.mode?"ð¢":e.containerRef?"â":"CA"===e.origin||"TN"===e.origin?e.origin:"",i=en(e),l=es[r.state],o=er(r.date),d=!!(s&&e.containerRef),c=[];e.date&&c.push(`${Y(e.status)} ${er(e.date)}`),0===i.length&&e.freightRef&&c.push(`Ref ${e.freightRef}`),e.containerRef&&!d&&c.push(`shipment ${e.containerRef}`),e.inboundShipmentId&&!d&&c.push(`IS #${e.inboundShipmentId}`),o&&c.push(r.dateIsEta?`ETA ${o}`:`arrived ${o}`);let u=d?`shipment ${e.containerRef}${e.inboundShipmentId?` \xb7 IS #${e.inboundShipmentId}`:""}`:null,x="no-carrier-scan"===r.issue?"No carrier scan since the label was created":"past-eta"===r.issue?"Past its ETA â not delivered yet":"exception"===r.issue?"Carrier exception â needs a look":null,m=(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("span",{className:"flex w-full items-center gap-1.5",children:[a&&(0,t.jsx)("span",{className:"inline-flex h-4 min-w-[18px] items-center justify-center rounded bg-surface px-1 text-[9px] font-semibold text-text-secondary",children:a}),(0,t.jsx)("span",{className:"font-mono text-[11px] font-semibold text-text-primary",children:e.ref||"Shipment"}),"number"==typeof e.qty&&e.qty>0&&(0,t.jsxs)("span",{className:"text-[10.5px] text-text-secondary",children:[e.qty.toLocaleString("en-US")," units","number"==typeof e.cartons&&e.cartons>0&&(0,t.jsxs)(t.Fragment,{children:[" · ",e.cartonsApprox?"~":"",e.cartons.toLocaleString("en-US")," cartons"]})]}),(0,t.jsx)("span",{className:(0,et.cn)("ml-auto inline-flex shrink-0 items-center rounded-full px-1.5 py-px text-[9.5px] font-semibold",l.cls),children:l.word})]}),i.length>0&&(0,t.jsx)("span",{className:"mt-0.5 flex flex-wrap items-center gap-x-2 gap-y-0.5 font-mono text-[10.5px] text-accent",children:i.map(e=>(0,t.jsxs)("span",{className:"inline-flex items-center gap-1",children:[e,(0,t.jsx)(z,{value:e,label:"tracking number"})]},e))}),(c.length>0||u)&&(0,t.jsxs)("span",{className:"mt-0.5 block text-[10px] text-text-tertiary",children:[c.join(" · "),u&&(0,t.jsxs)(t.Fragment,{children:[c.length>0&&" · ",(0,t.jsxs)("span",{role:"link",tabIndex:0,onClick:t=>{t.stopPropagation(),(0,ee.openInboundShipment)({ref:e.containerRef,isId:e.inboundShipmentId,highlightSku:e.sku})},onKeyDown:t=>{"Enter"===t.key&&(t.stopPropagation(),(0,ee.openInboundShipment)({ref:e.containerRef,highlightSku:e.sku}))},className:"cursor-pointer text-accent hover:underline",title:"Open the inbound shipment record",children:[u," âº"]})]})]}),x&&(0,t.jsxs)("span",{className:"mt-0.5 block text-[10px] font-medium text-warning",children:["â ",x]})]});return n?(0,t.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),n()},className:"block w-full border-b border-border-subtle/60 px-3 py-2 text-left transition-colors last:border-0 hover:bg-surface",children:m}):(0,t.jsx)("div",{className:"border-b border-border-subtle/60 px-3 py-2 last:border-0",children:m})}function ei({shipments:e,label:n}){var s;let a,[i,l]=(0,r.useState)(!1),o=(0,ee.useInboundHostPresent)(),[d,c]=(0,r.useState)(null),[u,x]=(0,r.useState)(null),m=(0,r.useRef)(null),p=(0,r.useRef)(null),h=(0,r.useRef)(null),f=(0,r.useRef)(null);(0,r.useEffect)(()=>{if(!u)return;let e=e=>{"Escape"===e.key&&x(null)};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[u]);let g=!!u?.pinned;if((0,r.useEffect)(()=>{if(!g)return;let e=e=>{let t=e.target;f.current?.contains(t)||h.current?.contains(t)||x(null)};return document.addEventListener("mousedown",e,!0),()=>document.removeEventListener("mousedown",e,!0)},[g]),(0,r.useEffect)(()=>
1{if(!u)return;let e=e=>{f.current?.contains(e.target)||x(null)};return window.addEventListener("scroll",e,{capture:!0,passive:!0}),()=>window.removeEventListener("scroll",e,{capture:!0})},[u]),(0,r.useEffect)(()=>()=>{m.current&&clearTimeout(m.current),p.current&&clearTimeout(p.current)},[]),!e||0===e.length)return null;let b=new Date().toISOString().slice(0,10),y=e=>J({trackingNumbers:e.trackingNumbers,upsTrackingStatus:e.status,date:e.date,deliveryDate:e.deliveryDate,containerRef:e.containerRef,containerTracking:e.containerTracking,containerDelivered:e.containerDelivered,deliveryEvidence:e.deliveryEvidence,containerEta:e.containerEta,containerArrived:e.containerArrived},b),v=e.map(y),j=e=>{let t,r,n,s,a=en(e)[0];if(!a)return;let i=(t=[e.ref||"Shipment"],"number"==typeof e.qty&&e.qty>0&&t.push(`${e.qty.toLocaleString("en-US")} units`),e.containerRef&&t.push(`shipment ${e.containerRef}`),e.inboundShipmentId&&t.push(`IS #${e.inboundShipmentId}`),t.join(" · ")),o=e.containerRef?{ref:e.containerRef,isId:e.inboundShipmentId,highlightSku:e.sku}:void 0,d=(n=er((r=y(e)).date),{status:r.label||void 0,eta:r.dateIsEta&&n?n:void 0,shipped:e.date&&"Shipped"===Y(e.status)?er(e.date):void 0}),u=e.carrier??"",x=0===(e.trackingNumbers??[]).filter(e=>e&&e.length>=5).length;if((0,H.isUpsShipment)(u,a))return void c({tn:a,carrier:"ups",context:i,inbound:o,fallback:d});if((0,K.isUspsShipment)(u,a))return void c({tn:a,carrier:"usps",context:i,inbound:o,fallback:d});if((0,V.isTForceShipment)(u,a))return void c({tn:a,carrier:"tforce",context:i,inbound:o,fallback:d});let m=(s=(u||"").toLowerCase()).includes("fedex")||s.includes("federal")?`https://www.fedex.com/fedextrack/?trknbr=${encodeURIComponent(a)}`:s.includes("dhl")?`https://www.dhl.com/us-en/home/tracking.html?tracking-id=${encodeURIComponent(a)}`:null;m?window.open(m,"_blank","noopener,noreferrer"):x?c({tn:a,carrier:"ups",context:i,inbound:o,fallback:d}):navigator.clipboard?.writeText(a).then(()=>{l(!0),setTimeout(()=>l(!1),1200)},()=>{})},N=e.filter(e=>en(e).length>0),w=N[0]??null,k=e.reduce((e,t)=>e+("number"==typeof t.qty&&t.qty>0?t.qty:0),0),S=v.filter(e=>"delivered"===e.state).length,C=e.some(e=>"number"!=typeof e.qty),$=[];k>0&&$.push(`${k.toLocaleString("en-US")}${C?"+":""} units`),$.push(`${e.length} shipment${1!==e.length?"s":""}`),e.length>1?$.push(`${S} of ${e.length} delivered`):1===S&&$.push("delivered");let I=w?N.length>1?"Click a shipment to track it":"Click to track":"Tracking pending",D={title:(a=Math.max(0,Math.floor((s={pinned:!!u?.byClick,trackableCount:N.length}).trackableCount)||0))>0?"Track a shipment":"Shipments",showHint:!s.pinned||0===a},T=(t,r)=>{var n;let s,a,i,l,o,d,c=t.getBoundingClientRect(),u=(s=26+68*Math.max(0,Math.floor((n={rect:{left:c.left,top:c.top,bottom:c.bottom},viewport:{width:window.innerWidth,height:window.innerHeight},legCount:e.length,hasHint:D.showHint}).legCount)||0)+22*!!n.hasHint,a=n.viewport.height-n.rect.bottom-4-8,i=n.rect.top-4-8,o=Math.max(120,"below"==(l=s>a&&i>a?"above":"below")?a:i),d=Math.max(8,Math.min(n.rect.left-120,n.viewport.width-360-8)),"below"===l?{x:d,top:n.rect.bottom+4,maxHeight:o,placement:l}:{x:d,bottom:n.viewport.height-n.rect.top+4,maxHeight:o,placement:l});x({x:u.x,top:u.top,bottom:u.bottom,maxHeight:u.maxHeight,pinned:r,byClick:r})},P=()=>{m.current&&clearTimeout(m.current),m.current=setTimeout(()=>x(null),160)},L=()=>{m.current&&clearTimeout(m.current)};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("button",{ref:h,type:"button","aria-label":I,onMouseEnter:e=>{L();let t=e.currentTarget;p.current&&clearTimeout(p.current),p.current=setTimeout(()=>T(t,!1),120)},onMouseLeave:()=>{p.current&&clearTimeout(p.current),P()},onClick:e=>{let t;(e.stopPropagation(),p.current&&clearTimeout(p.current),L(),u?.pinned)?x(null):"track-primary"!=(0===(t=Math.max(0,Math.floor(N.length)||0))?"pin-info":t>1?"pin-pick":"track-primary")?T(e.currentTarget,!0):(x(null),w&&j(w))},className:(0,et.cn)("inline-flex shrink-0 items-center justify-center rounded p-0.5 align-middle transition-colors hover:bg-surface-elevated",i?"text-success":"text-text-tertiary hover:text-accent",!w&&"opacity-50",n&&"group gap-1.5 px-1 py-0.5"),children:[i?(0,t.jsx)(R.Check,{className:"h-3.5 w-3.5","aria-hidden":"true"}
1):(0,t.jsx)(F.Truck,{className:"h-3.5 w-3.5","aria-hidden":"true"}),n&&(0,t.jsx)("span",{className:"font-mono text-[15px] font-semibold text-text-primary group-hover:underline",children:n})]}),u&&(0,U.createPortal)((0,t.jsx)("div",{className:"pointer-events-none fixed inset-0 z-[2200]",children:(0,t.jsxs)("div",{ref:f,className:"pointer-events-auto absolute w-[360px] max-w-[92vw] overflow-y-auto rounded-lg border border-border-default bg-surface-elevated shadow-xl",style:{left:u.x,top:u.top,bottom:u.bottom,maxHeight:u.maxHeight},onClick:e=>e.stopPropagation(),onMouseEnter:()=>{L(),x(e=>e&&!e.pinned?{...e,pinned:!0}:e)},onMouseLeave:u.pinned?void 0:P,children:[(0,t.jsxs)("div",{className:"flex items-center justify-between gap-2 border-b border-border-default px-3 py-1.5",children:[(0,t.jsx)("span",{className:"text-[10px] font-semibold uppercase tracking-wide text-text-tertiary",children:D.title}),(0,t.jsx)("span",{className:"ml-auto text-[10px] text-text-secondary",children:$.join(" · ")}),(0,t.jsx)("button",{type:"button","aria-label":"Close",onClick:e=>{e.stopPropagation(),x(null)},className:"-mr-1 inline-flex shrink-0 items-center justify-center rounded p-0.5 text-text-tertiary transition-colors hover:bg-surface hover:text-text-primary",children:(0,t.jsx)(q.X,{className:"h-3 w-3","aria-hidden":"true"})})]}),e.map((e,r)=>(0,t.jsx)(ea,{s:e,leg:v[r],canOpenInbound:o,onClick:en(e).length>0?()=>{x(null),j(e)}:void 0},e.ref||r)),D.showHint&&(0,t.jsx)("p",{className:"px-3 py-1.5 text-[10px] text-text-tertiary",children:I})]})}),document.body),d&&(0,t.jsx)(B.default,{trackingNumber:d.tn,carrier:d.carrier,context:d.context,inbound:d.inbound,fallback:d.fallback,onClose:()=>c(null)})]})}function el(e){return{ref:e.ref,qty:e.units>0?e.units:void 0,trackingNumbers:e.trackingNumbers,carrier:e.carrier??void 0,status:e.status??void 0,date:e.shipDate,deliveryDate:e.deliveryDate,deliveryEvidence:e.deliveryEvidence,containerRef:e.containerRef??void 0,containerEta:e.containerEta??void 0,containerDelivered:e.containerDelivered,containerArrived:e.containerArrived??void 0,inboundShipmentId:e.inboundShipmentId??void 0,mode:e.inboundMode??void 0}}function eo({bundle:e,error:r,showCustomer:n,onOpenOrder:s,onOpenCustomer:a,exportRows:i,packingListsHref:l}){if(r)return(0,t.jsxs)("div",{role:"alert",className:"overflow-hidden rounded-xl border border-error bg-surface-elevated",children:[(0,t.jsx)("div",{className:"h-[3px] bg-error"}),(0,t.jsxs)("div",{className:"px-4 py-4",children:[(0,t.jsx)("div",{className:"text-[10px] font-semibold uppercase tracking-wider text-text-tertiary",children:"Shipment lookup"}),(0,t.jsx)("div",{className:"mt-1 text-[13px] font-semibold text-text-primary",children:"Could not load this shipment"}),(0,t.jsx)("div",{className:"mt-0.5 text-[12px] text-text-secondary",children:"This is a problem on our side, not an empty result â the orders below are still filtered by your search."})]})]});let d=e?.tracking;if(!e||!d)return null;let{rows:c,legs:u,totals:x}=e,m=u.length>1,p=new Set(c.map(e=>e.invoiceId).filter(e=>null!=e)).size,h=7+ +!!m+ +!!n;return(0,t.jsxs)("div",{className:"overflow-hidden rounded-xl border border-border-default bg-surface-elevated",children:[(0,t.jsx)("div",{className:"h-[3px] bg-accent"}),(0,t.jsxs)("div",{className:"flex items-start gap-4 px-4 pb-3 pt-4",children:[(0,t.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,t.jsx)("div",{className:"text-[10px] font-semibold uppercase tracking-wider text-text-tertiary",children:"Tracking match"}),(0,t.jsx)("div",{className:"flex flex-wrap items-center gap-2",children:u.length>0?(0,t.jsx)(ei,{shipments:u.map(el),label:d.matchedNumbers[0]??d.query}):(0,t.jsx)("span",{className:"font-mono text-[15px] font-semibold text-text-primary",children:d.matchedNumbers[0]??d.query})}),(0,t.jsxs)("div",{className:"mt-1.5 flex flex-wrap items-center gap-2",children:[d.carrier&&(0,t.jsx)("span",{className:"inline-flex items-center rounded-full border border-border-subtle bg-surface px-2 py-0.5 text-[10px] font-bold uppercase tracking-wide text-text-secondary",children:d.carrier}),d.status&&(0,t.jsx)("span",{className:"text-[11.5px] text-text-secondary",children:d.status}),d.shipDate&&(0,t.jsxs)("span",{className:"text-[11px] text-text-tertiary",children:["Shipped ",(0,A.formatDate)(d.shipDate)]}),d.deliveryDate&&(0,t.jsxs)("span",{className:"text-[11px] text-text-tertiary",children:["Est. delivery ",(0,A.formatDate)(d.deliveryDate)]})]}),("bol"===d.matchedOn||!d.exact)&&(0,t.jsx)("div",{className:"mt-1 text-[11px] text-text-tertiary",children:"bol"===d.matchedOn?"Matched on the shipment's bill of lading.":`Partial match on "${d.query}" â no shipment carries that exact number.`})]}),(0,t.jsxs)("div",{className:"flex flex-none items-start gap-2",children:[l&&p>0&&(0,t.jsxs)("a",{href:l,title:`Download the packing list for all ${p} invoice${1===p?"":"s"} in this shipment (.zip)`,className:"inline-flex items-center gap-1.5 rounded-lg border border-border-default bg-surface px-2.5 py-1.5 text-[11px] font-semibold text-text-secondary transition-colors hover:bg-surface-elevated hover:text-text-primary",children:[(0,t.jsx)(o.Package,{className:"h-4 w-4"}),"All PLs",(0,t.jsx)("span",{className:"tabular-nums text-text-tertiary",children:p})]}),i&&c.length>0&&(0,t.jsxs)("button",{type:"button",onClick:()=>
1i(c,d,u,n),title:`Download ${c.length.toLocaleString("en-US")} line(s) as Excel (.xlsx)`,className:"inline-flex items-center gap-1.5 rounded-lg border border-border-default bg-surface px-2.5 py-1.5 text-[11px] font-semibold text-text-secondary transition-colors hover:bg-surface-elevated hover:text-text-primary",children:[(0,t.jsx)(O,{className:"h-4 w-4"}),"Excel"]})]})]}),(0,t.jsxs)("div",{className:"flex flex-wrap gap-x-6 gap-y-2 px-4 pb-1",children:[(0,t.jsx)(ed,{label:"Shipments",value:x.shipments,sub:x.shipments>1?"same tracking number":void 0}),(0,t.jsx)(ed,{label:"Orders",value:x.orders}),(0,t.jsx)(ed,{label:"Units shipped",value:x.units}),(0,t.jsx)(ec,{label:"Value shipped",value:x.amount,partial:x.amountPartial})]}),(0,t.jsx)("div",{className:"px-3 pb-3 pt-1.5",children:0===c.length?(0,t.jsx)("div",{className:"px-2 py-6 text-center text-xs text-text-tertiary",children:"This shipment has no item lines in the mirror yet."}):(0,t.jsx)("div",{className:"-mx-1 overflow-x-auto",children:(0,t.jsxs)("table",{className:"w-full min-w-[720px] text-[12.5px]",children:[(0,t.jsx)("thead",{children:(0,t.jsxs)("tr",{className:"border-b border-border-default text-left text-[10px] font-medium uppercase tracking-wider text-text-tertiary",children:[m&&(0,t.jsx)("th",{className:"px-2.5 py-2 font-medium",children:"Shipment"}),(0,t.jsx)("th",{className:"px-2.5 py-2 font-medium",children:"SO #"}),n&&(0,t.jsx)("th",{className:"px-2.5 py-2 font-medium",children:"Customer"}),(0,t.jsx)("th",{className:"px-2.5 py-2 font-medium",children:"Item"}),(0,t.jsx)("th",{className:"px-2.5 py-2 text-center font-medium",children:"Qty"}),(0,t.jsx)("th",{className:"px-2.5 py-2 text-right font-medium",children:"Rate"}),(0,t.jsx)("th",{className:"px-2.5 py-2 text-right font-medium",children:"Amount"}),(0,t.jsx)("th",{className:"px-2.5 py-2 font-medium",children:"Invoice"})]})}),(0,t.jsx)("tbody",{children:c.map(e=>(0,t.jsx)(eu,{row:e,showShipment:m,showCustomer:n,onOpenOrder:s,onOpenCustomer:a},e.rowKey))}),(0,t.jsx)("tfoot",{children:(0,t.jsxs)("tr",{className:"border-t border-border-subtle text-text-tertiary",children:[(0,t.jsx)("td",{colSpan:h-4,className:"px-2.5 py-2 text-right",children:"Totals"}),(0,t.jsx)("td",{className:"px-2.5 py-2 text-center font-semibold tabular-nums text-text-primary",children:x.units.toLocaleString("en-US")}),(0,t.jsx)("td",{}),(0,t.jsxs)("td",{className:"px-2.5 py-2 text-right font-semibold tabular-nums text-text-primary",children:[(0,A.formatCurrency)(x.amount),x.amountPartial&&(0,t.jsx)("span",{className:"ml-1 font-normal text-text-tertiary",title:"Some lines have no resolvable price, so this is the value of the priced lines only.",children:"+"})]}),(0,t.jsx)("td",{})]})})]})})})]})}function ed({label:e,value:r,sub:n}){return(0,t.jsxs)("div",{className:"border-r border-border-subtle pr-6 last:border-r-0 last:pr-0",children:[(0,t.jsx)("div",{className:"text-[10px] font-semibold uppercase tracking-wide text-text-tertiary",children:e}),(0,t.jsx)("div",{className:"text-lg font-bold tabular-nums text-text-primary",children:r.toLocaleString("en-US")}),n&&(0,t.jsx)("div",{className:"text-[11px] text-text-tertiary",children:n})]})}function ec({label:e,value:r,partial:n}){return(0,t.jsxs)("div",{className:"border-r border-border-subtle pr-6 last:border-r-0 last:pr-0",children:[(0,t.jsx)("div",{className:"text-[10px] font-semibold uppercase tracking-wide text-text-tertiary",children:e}),(0,t.jsx)("div",{className:"text-lg font-bold tabular-nums text-text-primary",children:(0,A.formatCurrency)(r)}),n&&(0,t.jsx)("div",{className:"text-[11px] text-text-tertiary",children:"priced lines only"})]})}function eu({row:e,showShipment:r,showCustomer:n,onOpenOrder:s,onOpenCustomer:a}){let i=null!=e.ordered&&e.ordered>0&&e.quantity<e.ordered;return(0,t.jsxs)("tr",{className:"border-b border-border-subtle/60 hover:bg-surface",children:[r&&(0,t.jsxs)("td",{className:"px-2.5 py-2.5 align-middle",children:[(0,t.jsx)("div",{className:"font-mono text-[11.5px] text-text-secondary",children:e.fulfillmentRef}),e.shipDate&&(0,t.jsx)("div",{className:"text-[11px] text-text-tertiary",children:(0,A.formatDate)(e.shipDate)})]}),(0,t.jsxs)("td",{className:"px-2.5 py-2.5 align-middle",children:[(0,t.jsx)("button",{type:"button",onClick:()=>s(e.orderId),title:`Open ${e.orderNumber}`,className:"font-mono text-[12.5px] font-semibold text-accent hover:underline",children:e.orderNumber}),e.poNumber&&e.poNumber.trim()&&(0,t.jsx)("div",{className:"truncate text-[10.5px] text-text-tertiary",title:`Customer PO ${e.poNumber}`,children:(0,A.formatPoNumber)(e.poNumber,{withLabel:!0})}),e.orderDate&&(0,t.jsx)("div",{className:"text-[11px] text-text-tertiary",children:(0,A.formatDate)(e.orderDate)})]}),n&&(0,t.jsx)("td",{className:"px-2.5 py-2.5 align-middle text-xs",children:e.customerName&&null!=e.customerId?(0,t.jsx)("button",{type:"button",onClick:()=>a(e.customerId,e.orderId,e.itemId),title:`Open ${e.customerName} â ${e.orderNumber}`,className:"text-left text-accent hover:underline",children:e.customerName}):(0,t.jsx)("span",{className:"text-text-muted",children:"â"})}),(0,t.jsxs)("td",{className:"px-2.5 py-2.5 align-middle",children:[(0,t.jsxs)("div",{className:"flex items-center",children:[(0,t.jsx)(M,{fallbackOrigin:e.origin??void 0}),(0,t.jsx)("span",{className:"font-mono text-[11px] text-text-secondary",children:e.sku})]}),e.bpn&&(0,t.jsxs)("div",{className:"mt-0.5 font-mono text-[10px] font-semibold",style:{color:"#7c3aed"},children:["BPN: ",e.bpn]}),e.description&&(0,t.jsx)("div",{className:"mt-0.5 text-[11px] text-text-tertiary",children:e.description})]}),(0,t.jsxs)("td",{className:"px-2.5 py-2.5 text-center align-middle tabular-nums",children:[(0,t.jsx)("div",{className:"font-medium text-text-primary",children:e.quantity.toLocaleStr
1ing("en-US")}),i&&(0,t.jsxs)("div",{className:"text-[10.5px] text-text-tertiary",title:"Units ordered on the sales-order line",children:["of ",e.ordered.toLocaleString("en-US")]})]}),(0,t.jsx)("td",{className:"px-2.5 py-2.5 text-right align-middle tabular-nums text-text-secondary",children:null==e.rate?(0,t.jsx)("span",{className:"text-text-muted",children:"â"}):(0,A.formatCurrency)(e.rate)}),(0,t.jsx)("td",{className:"px-2.5 py-2.5 text-right align-middle font-medium tabular-nums",children:null==e.amount?(0,t.jsx)("span",{className:"text-text-muted",title:"No price on the sales-order line for this item",children:"â"}):(0,A.formatCurrency)(e.amount)}),(0,t.jsx)("td",{className:"px-2.5 py-2.5 align-middle",children:(0,t.jsx)(ex,{row:e})})]})}function ex({row:e}){let r=P();if(!e.invoiceId||!e.invoiceNumber)return(0,t.jsx)("span",{className:"text-[11.5px] text-text-muted",title:"Not invoiced yet â the invoice and packing list appear once NetSuite bills this line",children:"Not invoiced"});let n=`${r}?action=pdf&invoiceId=${e.invoiceId}`;return(0,t.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,t.jsxs)("div",{className:"min-w-0",children:[(0,t.jsx)("div",{className:"truncate font-mono text-[11.5px] text-text-secondary",children:e.invoiceNumber}),e.invoiceDate&&(0,t.jsx)("div",{className:"text-[10.5px] text-text-tertiary",children:(0,A.formatDate)(e.invoiceDate)})]}),(0,t.jsx)("a",{href:n,target:"_blank",rel:"noopener noreferrer",title:`Download invoice ${e.invoiceNumber} (PDF)`,"aria-label":`Download invoice ${e.invoiceNumber} PDF`,className:"inline-flex h-7 w-7 flex-none items-center justify-center rounded-md border border-border-default bg-surface text-text-secondary transition-colors hover:border-accent hover:text-accent",children:(0,t.jsx)(l.Download,{className:"h-3.5 w-3.5"})}),(0,t.jsx)("a",{href:`${n}&template=packing`,target:"_blank",rel:"noopener noreferrer",title:`Download packing list for ${e.invoiceNumber} (PDF)`,"aria-label":`Download packing list for ${e.invoiceNumber}`,className:"inline-flex h-7 w-7 flex-none items-center justify-center rounded-md border border-border-default bg-surface text-text-secondary transition-colors hover:border-accent hover:text-accent",children:(0,t.jsx)(o.Package,{className:"h-3.5 w-3.5"})})]})}e.s(["default",0,ei],156075);let em=/^1Z[0-9A-Z]{10,16}$/,ep=/^[0-9]{8,22}$/,eh=/^[A-Z]{2}[0-9]{9}US$/,ef=/^[0-9]{6}AIR[A-Z]{2,6}[A-Z0-9]{0,3}$/,eg=/^CONT[0-9]{6,16}[A-Z]{2,4}$/,eb=/^[A-Z]{4}[0-9]{7}$/,ey=/^(so|inv|iv|po|p0)[\s-]?\d/i;var ev=e.i(697421),ej=e.i(295619);let eN=[{value:"all",label:"All",description:"Everything on your account"},{value:"pending-approval",label:"Awaiting approval",description:"Orders waiting on your team's approval"},{value:"open",label:"Open",description:"Orders the warehouse can still ship"},{value:"in-transit",label:"In transit",description:"Shipped, on its way to you"},{value:"to-pay",label:"To pay",description:"Open invoices"},{value:"overdue",label:"Overdue",description:"Past-due invoices"}],ew=[{value:"all",label:"All",description:"Every record type"},{value:"orders",label:"Orders",description:"Sales orders"},{value:"invoices",label:"Invoices",description:"Invoices only"},{value:"credit-memos",label:"Credit memos",description:"Credit memos only"},{value:"payments",label:"Payments",description:"Payments only"},{value:"refunds",label:"Refunds",description:"Refunds only"}],ek=new Set(["SalesOrd:B","SalesOrd:D","SalesOrd:E","SalesOrd:F"]);function eS(e){return ek.has(e.statusRef)}function eC(e){return"SalesOrd:A"===e.statusRef}function e$(e){return(e.fulfillments??[]).some(e=>{let t=J(e,(0,A.businessToday)());return"in-transit"===t.state||"out-for-delivery"===t.state})}function eI(e){return!!e.invoices&&0!==e.invoices.length&&e.invoices.some(e=>null!=e.amountRemaining&&e.amountRemaining>0)}function eD(e){return!0===e.isOverdue&&e.amountRemaining>0}function eT(e){return e.amountRemaining>0}let eP={paid:0,refunded:0,balance:0,payments:[],refunds:[],deposits:[],creditApplications:[]};function eL(e){let t=new Map;for(let r of e)r.id&&r.salesOrderId&&t.set(r.id,r.salesOrderId);return t}function eE(e,t){return e.sourceSalesOrderId?e.sourceSalesOrderId:e.source&&"deposit"===e.source.type&&e.source.id?t.get(e.source.id)??null:null}function eO(e,t,r,n,s=[]){let a=new Map,i=e=>{let t=a.get(e);return t||(t={...eP,payments:[],refunds:[],deposits:[],creditApplications:[]},a.set(e,t)),t},l=new Map;for(let t of e)if(t.invoices)for(let e of t.invoices)l.set(e.id,t.id);for(let t of e){let e=i(t.id);if(t.invoices)for(let r of t.invoices){let t=Number(r.amountRemaining||0);t>0&&(e.balance+=t)}}for(let e of t){let t=new Set;for(let r of e.appliedInvoices||[]){let n=l.get(r.id);if(!n||t.has(n))continue;t.add(n);let s=i(n);s.payments.push(e),s.paid+=Number(e.amount||0)}}let o=eL(n);for(let e of r){let t=eE(e,o);if(!t)continue;let r=i(t);r.refunds.push(e),r.refunded+=Number(e.amount||0)}for(let e of n)e.salesOrderId&&i(e.salesOrderId).deposits.push(e);let d=new Map;for(let t of e)if(t.invoices)for(let e of t.invoices)d.set(e.id,{total:Number(e.total||0),remaining:Number(e.amountRemaining||0)});for(let e of s)if(e.appliedInvoices&&0!==e.appliedInvoices.length)for(let t of e.appliedInvoices){let r=l.get(t.id);if(!r)continue;let n=i(r),s=d.get(t.id),a=Math.min(s?Math.max(s.total-s.remaining,0):0,Number(e.total||0));n.creditApplications.push({credit:e,appliedToInvoiceId:t.id,appliedToInvoiceNumber:t.tranId,appliedAmount:a})}return a}function eA(e,t,r){let n=eL(r);return{refunds:e.filter(e=>!eE(e,n)),credits:t.slice(),deposits:r.filter(e=>!e.salesOrderId)}}function eM(e){let t=Date.now(),r={current:{key:"current",label:"Current",amount:0,count:0},"1-30":{key:"1-30",label:"1â30 days",amount:0,count:0},"31-60":{key:"31-60",label:"31â60 days",amount:0,count:0},"61-90":{key:"61-90",label:"61â90 days",amount:0,count:0},"90+":{key:"90+",label:"90+ days",amount:0,count:0}};for(let n of e){let e;if(!eT(n))continue;let s=n.dueDate?Date.parse(n.dueDate):NaN,a=isNaN(s)?0:Math.floor((t-s)/864e5);e=a<=0?"current":a<=30?"1-30":a<=60?"31-60":a<=90?"61-90":"90+",r[e].amount+=n.amountRemaining,r[e].count+=1}return[r.current,r["1-30"],r["31-60"],r["61-90"],r["90+"]]}function eU(e){if(!e||0===e.length)return[];let t=new Map;for(let r of e){let e=(r.trackingNumbers||[]).map(e=>String(e).trim()).filter(e=>e.length>=5).sort(),n=e.length>0?`tn:${e.join("|")}|${function(e){let t=String(e.date??"").trim();if(!t)return"";if(/^\d{4}-\d{2}-\d{2}/.test(t))return t.slice(0,10);let r=Date.parse(t);return Number.isNaN(r)?"":new Date(r).toISOString().slice(0,10)}(r)}`:`id:${r.fulfillmentId}`,s=t.get(n);s?s.push(r):t.set(n,[r])}function r(e){let t=0;e.upsTrackingStatus&&e.upsTrackingStatus.length>0&&(t+=100),e.deliveryDate&&e.deliveryDate.length>
10&&(t+=50),e.status&&!/^shipped$/i.test(e.status)&&(t+=10);let r=e.date?Date.parse(e.date):NaN;return Number.isNaN(r)||(t+=Math.floor(r/864e5)),t}let n=[];for(let e of t.values()){if(1===e.length){n.push(e[0]);continue}let t=e[0],s=r(t);for(let n=1;n<e.length;n++){let a=r(e[n]);a>s&&(t=e[n],s=a)}n.push({...t,groupMembers:e})}return n}function eR(e){if(!e||0===e.length)return[];let t=new Set,r=[];for(let n of e)for(let e of n.trackingNumbers||[])!e||e.length<5||t.has(e)||(t.add(e),r.push({tn:e,origin:n.origin||"",carrier:n.carrier||"",status:n.upsTrackingStatus||n.status||""}));return r}function eF(e){let t=(e.lines??[]).filter(e=>"number"==typeof e.quantity&&e.quantity>0),r=t.reduce((e,t)=>e+t.quantity,0);if(r<=0||0===t.length)return{units:0};if(t.some(e=>!e.unitsPerMaster||e.unitsPerMaster<=0))return{units:r};let n=0,s=0;for(let e of t){let t=e.unitsPerMaster;n+=Math.floor(e.quantity/t),s+=e.quantity%t/t}return s>0&&(n+=Math.ceil(s-1e-9)),{units:r,cartons:n,cartonsApprox:s>0||void 0}}function eq(e,t){return!e||!t||e<=0||t<=0?{}:e%t==0?{cartons:e/t}:{cartons:Math.ceil(e/t),cartonsApprox:!0}}function eB(e,t){if(!t||0===t.length)return[];let r=t.some(e=>(e.lines?.length??0)>0),n=t.filter(t=>t.lines?.some(t=>t.itemId===e)||(t.lines?.length??0)===0);return 0!==n.length||r||(n=t),n.filter(t=>(t.trackingNumbers?.length??0)>0||(t.containerTracking?.length??0)>0||!!t.containerRef||(t.lines?.some(t=>t.itemId===e)??!1)).map(t=>{let r=function(e,t){let r=(e??[]).filter(e=>e.itemId===t).map(e=>"number"==typeof e.quantity?e.quantity:Number(e.quantity)).filter(e=>Number.isFinite(e)&&0!==e);if(0===r.length)return;let n=r.filter(e=>e>0);return n.length>0?n.reduce((e,t)=>e+t,0):Math.max(...r.map(e=>Math.abs(e)))}(t.lines,e),n=t.lines?.find(t=>t.itemId===e&&(t.unitsPerMaster??0)>0)?.unitsPerMaster;return{fulfillmentId:t.fulfillmentId,trackingNumbers:t.trackingNumbers,carrier:t.carrier||"",origin:t.origin||"",status:t.upsTrackingStatus||t.status||"",deliveryDate:t.deliveryDate||"",date:t.date||"",shippedQty:r,containerRef:t.containerRef,containerTracking:t.containerTracking,containerEta:t.containerEta,containerDelivered:t.containerDelivered,deliveryEvidence:t.deliveryEvidence,containerArrived:t.containerArrived,inboundShipmentId:t.inboundShipmentId,inboundMode:t.inbou
1ndMode,freightRef:t.freightRef,...eq(r,n)}})}function e_(e,t){let r=e=>{if(!e)return null;let t=/^(\d{4})-(\d{2})-(\d{2})/.exec(e);if(t)return Date.UTC(Number(t[1]),Number(t[2])-1,Number(t[3]));let r=/^(\d{1,2})\/(\d{1,2})\/(\d{4})/.exec(e);return r?Date.UTC(Number(r[3]),Number(r[1])-1,Number(r[2])):null},n=r(e),s=r(t);if(null==n||null==s)return 1/0;let a=0;for(let e=n+864e5;e<=s;e+=864e5){let t=new Date(e).getUTCDay();0!==t&&6!==t&&a++}return a}function ez(e,t){let r=[];for(let n of e.fulfillments??[]){let e=J({trackingNumbers:n.trackingNumbers,upsTrackingStatus:n.upsTrackingStatus,status:n.status,date:n.date,deliveryDate:n.deliveryDate,containerRef:n.containerRef,containerTracking:n.containerTracking,containerDelivered:n.containerDelivered,deliveryEvidence:n.deliveryEvidence,containerEta:n.containerEta,containerArrived:n.containerArrived},t);if(!e.issue||"ocean"===n.inboundMode)continue;let s=(n.trackingNumbers??[])[0]??null;if((0,K.isUspsShipment)(n.carrier,s)||"no-carrier-scan"===e.issue&&3>e_(n.date,t)||"stalled-in-transit"===e.issue&&n.deliveryDate&&2>e_(n.deliveryDate,t))continue;let a=eF(n),i=(n.lines??[]).filter(e=>"number"==typeof e.quantity&&e.quantity>0).map(e=>({sku:e.externalId||eK(e.itemName),qty:e.quantity})),l={ref:n.fulfillmentId,lines:i.length>0?i:void 0,units:a.units>0?a.units:void 0,cartons:a.cartons,cartonsApprox:a.cartonsApprox,shippedDate:n.date||void 0,statusLabel:e.label,eta:(e.dateIsEta?e.date:void 0)??void 0,trackingNumbers:(n.trackingNumbers?.length??0)>0?n.trackingNumbers:n.containerTracking??void 0,carrier:n.carrier||void 0};"no-carrier-scan"===e.issue?r.push({...l,kind:"no-carrier-scan",label:`${n.fulfillmentId} â label created, no carrier scan`}):"past-eta"===e.issue?r.push({...l,kind:"past-eta",label:`${n.fulfillmentId} â past ETA, not delivered`}):"stalled-in-transit"===e.issue?r.push({...l,kind:"stalled-in-transit",label:`${n.fulfillmentId} â in transit, no movement`}):"exception"===e.issue&&r.push({...l,kind:"exception",label:`${n.fulfillmentId} â carrier exception`})}if(eS(e))for(let n of(0,x.splitOrderLines)(e.lines).products){let e=(n.expectedShipDate??"").slice(0,10);if(!e)continue;let s=n.quantity-(n.quantityShipped??0);s>0&&e<t&&r.push({ref:n.externalId||String(n.itemId),kind:"past-esd",label:`${n.externalId||"line"} â ${s.toLocaleString("en-US")} to ship, ESD ${e} passed`,statusLabel:`${s.toLocaleString("en-US")} to ship`,eta:e})}return r}function eH(e,t){return ez(e,t).length>0}function eW(e,t){let r=[];for(let n of e)for(let e of ez(n,t))r.push({orderId:n.id,orderNumber:n.orderNumber,customerName:n.customerName||void 0,issue:e});return r}function eK(e){if(!e)return"--";let t=e.split(" : ");return t.length>1?t[t.length-1].trim():e.trim()}function eV(e){let t=e??"",r=t.indexOf(" : ");return r>=0?t.slice(r+3):t}function eQ(e,t){let r=new Set;for(let e of t)if(e.invoices)for(let t of e.invoices)r.add(t.id);return e.filter(e=>!r.has(e.id))}function eX(e){return null==e?"":String(e).toLowerCase().replace(/[\s\-_./]/g,"")}function eZ(e){return e.split(",").map(e=>e.trim().split(/\s+/).map(eX).filter(Boolean)).filter(e=>e.length>0)}function eG(e,t){if(0===t.length)return!0;let r=function(e){let t=[],r=e=>{let r=eX(e);r&&t.push(r)};if(r(e.orderNumber),r(e.poNumber),r(e.shipMethod),r(e.id),r(e.statusLabel),r(e.customerName),r(e.parentName),e.invoices)for(let t of e.invoices)r(t.invoiceNumber);if(e.fulfillments){for(let t of e.fulfillments)if(t.trackingNumbers)for(let e of t.trackingNumbers)r(e)}if(e.lines)for(let t of e.lines)r(t.itemId),r(t.externalId),r(t.upc),r(t.scpItemNo),r(t.itemName),r(t.description);if(r(e.lineSearchBlob),e.shippingAddress){let t=e.shippingAddress;r(t.company),r(t.attention),r(t.addr1),r(t.addr2),r(t.city),r(t.state),r(t.zip)}return t.join(" ")}(e);return t.some(e=>e.every(e=>r.includes(e)))}function eY(e){let t=new Set(e.map(e=>e.trim().toLowerCase()).filter(Boolean));return 0===t.size?null:e=>(e.phoneModels??[]).some(e=>t.has(e.trim().toLowerCase()))}function eJ(e,t){if(!t.trim())return!0;let r=eZ(t);if(0===r.length)return!0;let n=function(e){let t=[],r=e=>{let r=eX(e);r&&t.push(r)};if(r(e.invoiceNumber),r(e.salesOrderNumber),r(e.poNumber),r(e.id),r(e.status),e.lines)for(let t of e.lines)r(t.itemId),r(t.externalId),r(t.upc),r(t.itemName),r(t.description),r(t.trackingNumber);return t.join(" ")}(e);return r.some(e=>e.every(e=>n.includes(e)))}function e0(e,t){if(!e.trim())return!0;
1let r=e.trim().split(/\s+/).map(eX).filter(Boolean);return 0===r.length||r.every(e=>t.includes(e))}function e1(e,t){let r=[],n=e=>{let t=eX(e);t&&r.push(t)};return n(e.tranId),n(e.id),n(e.methodLabel),n(e.statusLabel),e.source&&(n(e.source.tranId),n(e.source.label)),n(e.sourceSalesOrderNumber),e0(t,r.join(" "))}function e2(e,t){let r=[],n=e=>{let t=eX(e);t&&r.push(t)};return n(e.tranId),n(e.id),n(e.memo),n(e.poNumber),n(e.linkedReturnTranId),e0(t,r.join(" "))}function e5(e,t){let r=[],n=e=>{let t=eX(e);t&&r.push(t)};return n(e.tranId),n(e.id),n(e.memo),n(e.salesOrderNumber),e0(t,r.join(" "))}function e3(e,t){return null==t||t<=e?"":` loaded (${t} total)`}function e4(e,t,r){return null!=e&&t===e&&r}function e8(e,t,r,n=!1,s=0){return n?{label:"Shipment needs attention",detail:`${t} of ${e} shipments delivered`}:t===e&&e>0&&!r?{label:"Delivered",detail:e>1?`All ${e} shipments delivered`:""}:t>0||s>0?{label:"Partially delivered",detail:r?"More items are preparing to ship":s>0?"Some packages have been delivered":`${t} of ${e} shipments delivered`}:{label:1===e?"Shipment on the way":`${e} shipments on the way`,detail:r?"More items are preparing to ship":""}}function e6(e,t,r){if(r)return"More items are preparing to ship.";if(e.length<=1||t)return null;let n=new Set(e.map(e=>e.origin)),s=2===n.size&&n.has("CA")&&n.has("TN")?" from our Tennessee and California warehouses":"";return`Your order is arriving in ${e.length} separate shipments${s}.`}function e9(e,t,r){return r?`Shipment ${e+1}`:1===t?"Shipment":`Shipment ${e+1} of ${t}`}e.s(["LINE_HIGHLIGHT_FADE_MS",0,2e3,"RECORD_TYPE_OPTIONS",0,ew,"VIEW_OPTIONS",0,eN,"buildAgingBuckets",0,eM,"buildAttentionRows",0,eW,"buildMoneyTrails",0,eO,"buildPhoneModelPredicate",0,eY,"cartonsForQty",0,eq,"extractChildSKU",0,eK,"extractTrackingChips",0,eR,"findOrphanInvoices",0,eQ,"findStandaloneEvents",0,eA,"fulfillmentUnitsAndCartons",0,eF,"getOrdersContainingItemSuffix",0,e3,"groupFulfillmentsByShipment",0,eU,"invoiceIsOpen",0,eT,"invoiceIsOverdue",0,eD,"isOrderInTransit",0,e$,"isOrderOpen",0,eS,"isOrderPendingApproval",0,eC,"matchesCreditSearch",0,e2,"matchesDepositSearch",0,e5,"matchesInvoiceSearch",0,eJ,"matchesOrderSearchGroups",0,eG,"matchesRefundSearch",0,e1,"orderHasUnpaidInvoice",0,eI,"orderNeedsAttention",0,eH,"parseSearchGroups",0,eZ,"shipmentDeliverySummary",0,e8,"shipmentLabel",0,e9,"shipmentsForLine",0,eB,"shouldShowLineHighlight",0,e4,"splitShipmentExplanation",0,e6,"stripStatusPrefix",0,eV],524198);let e7=(0,a.default)("banknote",[["rect",{width:"20",height:"12",x:"2",y:"6",rx:"2",key:"9lu3g6"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}],["path",{d:"M6 12h.01M18 12h.01",key:"113zkx"}]]);var te=e.i(705325),tt=e.i(154586);let tr=(0,a.default)("wallet",[["path",{d:"M19 7V4a1 1 0 0 0-1-1H5a2 2 0 0 0 0 4h15a1 1 0 0 1 1 1v4h-3a2 2 0 0 0 0 4h3a1 1 0 0 0 1-1v-2a1 1 0 0 0-1-1",key:"18etb6"}],["path",{d:"M3 5v14a2 2 0 0 0 2 2h15a1 1 0 0 0 1-1v-4",key:"xoc0q4"}]]);var tn=e.i(118551),ts=e.i(358462);function ta({shipTo:e,variant:n="classic"}){let[a,i]=(0,r.useState)(!1);return e.city||e.state?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("span",{role:"button",tabIndex:0,"aria-expanded":a,onClick:e=>{e.stopPropagation(),i(e=>!e)},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),e.stopPropagation(),i(e=>!e))},title:"Show full ship-to address",className:"-my-1 inline-flex items-center gap-1 rounded py-1 transition-colors hover:text-accent focus:outline-none focus-visible:ring-2 focus-visible:ring-accent",children:[(0,t.jsx)("span",{className:"v4"===n?"font-mono text-[9px] font-bold uppercase tracking-[0.1em] text-text-tertiary":"text-[9px] font-semibold uppercase tracking-wider",children:"Ship to:"}),(0,t.jsx)("span",{className:"v4"===n?"font-bold":"font-medium text-text-secondary",children:[e.city,e.state].filter(Boolean).join(", ")}),(0,t.jsx)(s.ChevronDown,{className:`h-3 w-3 transition-transform ${a?"rotate-180":""}`})]}),a&&(0,t.jsxs)("span",{onClick:e=>e.stopPropagation(),className:"mt-1 block w-fit max-w-full rounded-md border border-border-subtle bg-surface-elevated px-2.5 py-1.5 text-[11px] font-normal leading-snug text-text-secondary",children:[e.company&&(0,t.jsx)("span",{className:"block font-medium text-text-primary",children:e.company}),e.attention&&(0,t.jsx)("span",{className:"block",children:e.attention}),e.addr1&&(0,t.jsx)("span",{className:"block",children:e.addr1}),e.addr2&&(0,t.jsx)("span",{className:"block",children:e.addr2}),(0,t.jsxs)("span",{className:"block",children:[[e.city,e.state].filter(
1Boolean).join(", ")," ",e.zip]}),e.country&&"US"!==e.country&&(0,t.jsx)("span",{className:"block",children:e.country})]})]}):null}e.s(["default",0,ta],51819);var ti=e.i(540833),tl=e.i(948769);let to={CA:{label:"California",color:"text-info",bg:"bg-info-bg",border:"border-info/30"},TN:{label:"Tennessee",color:"text-success",bg:"bg-success-bg",border:"border-success/30"}};function td(e,t,r,n){if(r?.deliveryState==="delivered")return{state:"delivered",label:"Delivered",color:"text-success",isOfd:!1,isException:!1};if(r?.deliveryState==="partially-delivered")return{state:"partially-delivered",label:"Partially delivered",color:"text-info",isOfd:!1,isException:!1};r?.deliveryState==="unconfirmed"&&(e={...e,deliveryEvidence:void 0,status:"Shipped",upsTrackingStatus:r.statusDescription,containerDelivered:!1});let s=e.deliveryEvidence?.packages.some(e=>null!=e.evidence),a=J(e,(0,A.businessToday)());if("delivered"===a.state||"partially-delivered"===a.state||s||r?.deliveryState==="unconfirmed"||!r){let t=e.upsTrackingStatus||e.status||"",r="pending-pickup"===a.state?"Label Created":"pending"===a.state&&/\b(picked|packed)\b(?!\s*up)/i.test(t)?"Preparing shipment":!s&&/^(customs hold|picked up)$/i.test(t.trim())?t.trim():"in-transit"===a.state?"In Transit":a.label;return{state:a.state,label:r,color:"delivered"===a.state?"text-success":"exception"===a.state?"text-error":"out-for-delivery"===a.state?"text-warning":"text-text-secondary",isOfd:"out-for-delivery"===a.state,isException:"exception"===a.state}}if(r.isDelivered)return(e.trackingNumbers?.length??0)>1?{state:"partially-delivered",label:"Partially delivered",color:"text-info",isOfd:!1,isException:!1}:{state:"delivered",label:"Delivered",color:"text-success",isOfd:!1,isException:!1};if("Partially delivered"===r.statusDescription)return{state:"partially-delivered",label:"Partially delivered",color:"text-info",isOfd:!1,isException:!1};let i=J({...e,upsTrackingStatus:r.statusDescription},(0,A.businessToday)());return{label:r.statusDescription||a.label,state:r.isException?"exception":r.isOfd?"out-for-delivery":"delivered"===i.state?"shipped":i.state,color:r.isException?"text-error":r.isOfd?"text-warning":"text-info",isOfd:r.isOfd,isException:r.isException}}function tc(e){if(!e)return"";let t=(0,A.formatMonthDay)(e);return"â"===t?e:t}function tu(e){if(!e)return"";let t=e.split("/");if(3===t.length){let e=parseInt(t[0],10),r=parseInt(t[1],10),n=parseInt(t[2],10);if(Number.isFinite(e)&&Number.isFinite(r)&&Number.isFinite(n)){let t=new Date(Date.UTC(n,e-1,r));if(!isNaN(t.getTime()))return t.toLocaleDateString("en-US",{month:"short",day:"numeric",timeZone:"UTC"})}}return e}function tx(e){return e&&Array.isArray(e)?h(e):[]}function tm({f:e,invoices:n,orderCompleted:s,isMultiWarehouse:a,selected:i,onSelect:l,activeItem:o}){let d=to[e.origin||""]||null,c=tx(e.trackingNumbers),u=tx(e.containerTracking),x=c.length>0?c:u,m=x[0]||null,[p,h]=(0,r.useState)(!1),f=(0,H.isUpsShipment)(e.carrier,m),g=!f&&(0,K.isUspsShipment)(e.carrier,m),b=!f&&!g&&(0,V.isTForceShipment)(e.carrier,m),y=f||g||b,v="delivered"===J(e,(0,A.businessToday)()).state,j=(0,H.isWithinUpsTrackingWindow)(e.date||null),N=(0,W.isWithinUspsTrackingWindow)(e.date||null),w=function(e){if(!e)return!1;let t=Date.parse(e);if(Number.isNaN(t))return!1;let r=(Date.now()-t)/864e5;return r>=0&&r<=120}(e.date||null),k=f&&x.length>0&&!v&&j,S=g&&x.length>0&&!v&&N,C=b&&x.length>0&&!v&&w,{data:$}=(0,H.useUpsTracking)(m,k),{data:I}=(0,W.useUspsTracking)(m,S),{data:D}=function(e,t){let[n,s]=(0,r.useState)(null),[a,i]=(0,r.useState)(!1);return(0,r.useEffect)(()=>{if(!t||!e){s(null),i(!1);return}let r=new AbortController;return i(!0),fetch("/api/tracking/tforce",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({trackingNumber:e}),signal:r.signal}).then(e=>e.json()).then(e=>{if(!e||!1===e.success)return;let t=function(e){if(!e)return null;let t=String(e.statusDescription||""),r=t.toLowerCase(),n="delivered"===e.status||r.includes("delivered"),s=!n&&r.includes("out for delivery"),a=!n&&(r.includes("exception")||r.includes("refused")||r.includes("damage")),i=Array.isArray(e.events)?e.events[0]:void 0,l=i?{description:String(i.description||""),location:String(i.location||""),when:[i.date,i.time].filter(
1Boolean).join(" ")}:null;return{statusDescription:t,estimatedDelivery:e.estimatedDelivery??null,deliveredDate:e.deliveredDate??null,signedBy:e.signedBy??null,latestEvent:l,isOfd:s,isException:a,isDelivered:n}}("object"==typeof e&&"data"in e?e.data:e);t&&s(t)}).catch(()=>{}).finally(()=>{r.signal.aborted||i(!1)}),()=>{r.abort()}},[e,t]),{data:n,loading:a}}(m,C),T=($||I||D)??null,P=td(e,s,T,y),L="Delivered"===P.label,E=(e.groupMembers?.length??0)>1?e.groupMembers.map(e=>({m:e,meta:eF(e)})):null,O=E?function(e){let t=e.reduce((e,t)=>e+t.meta.units,0);if(e.some(e=>e.meta.units>0&&"number"!=typeof e.meta.cartons))return{units:t};let r=0,n=!1;for(let t of e)"number"==typeof t.meta.cartons&&(r+=t.meta.cartons),t.meta.cartonsApprox&&(n=!0);return r>0?{units:t,cartons:r,cartonsApprox:n||void 0}:{units:t}}(E):eF(e),M=E?E.map(({m:e})=>e.fulfillmentId).filter(e=>!!e):[],U=[E&&M.length>0?M.join(" + "):e.fulfillmentId||null,O.units>0?`${O.units.toLocaleString("en-US")} units`:null,e.containerRef?`shipment ${e.containerRef}`:null,null!=e.inboundShipmentId?`IS #${e.inboundShipmentId}`:null].filter(Boolean).join(" · "),R=(0,ee.useInboundHostPresent)(),F=Array.from(new Set((E?E.flatMap(({m:e})=>e.lines??[]):e.lines??[]).filter(e=>"number"==typeof e.quantity&&e.quantity>0).map(e=>e.externalId).filter(e=>!!e))),q=function(e){let{cardSkus:t,activeItem:r,itemIdForSku:n}=e,s=t.filter(e=>!!e);if(r&&Number.isFinite(r.itemId)&&r.itemId>0&&(0===s.length||s.includes(r.sku)))return{itemId:r.itemId,sku:r.sku};if(1===s.length&&n){let e=s[0],t=n(e);if("number"==typeof t&&Number.isFinite(t)&&t>0)return{itemId:t,sku:e}}return null}({cardSkus:F,activeItem:o,itemIdForSku:t=>(E?E.flatMap(({m:e})=>e.lines??[]):e.lines??[]).find(e=>e.externalId===t)?.itemId??null}),B=e.containerRef?{ref:e.containerRef,isId:e.inboundShipmentId,highlightSku:q?.sku??(1===F.length?F[0]:void 0),highlightItemId:q?.itemId}:void 0,_=y&&((f?j:g?N:!!b&&w)||!L),z=function(e,t){if(e&&t&&0!==t.length)return t.find(t=>t.origin===e)}(e.origin,n),Q=L?"":tu(T?.estimatedDelivery),X=Q||(e.deliveryDate?tc(e.deliveryDate):""),Z=Q?"live":e.deliveryDate?"ns":"none",G=L?null:function(e){if(!e)return null;let t=Date.parse(e);if(Number.isNaN(t))return null;let r=new Date(t),n=new Date(r.getFullYear(),r.getMonth(),r.getDate()),s=new Date,a=new Date(s.getFullYear(),s.getMonth(),s.getDate()),i=Math.round((n.getTime()-a.getTime())/864e5);return i<0?null:0===i?"today":1===i?"tomorrow":i<=7?`in ${i} days`:null}(T?.estimatedDelivery||e.deliveryDate||null),er=!!(T?.isDelivered||e.containerDelivered),en=er?T?.deliveredDate?tu(T.deliveredDate.split(" ")[0]):e.containerArrived?tc(e.containerArrived):null:null,es=er?en?` \xb7 arrived ${en}`:" · arrived":e.containerEta?` \xb7 ETA ${tc(e.containerEta)}`:"";return(0,t.jsxs)("div",{role:l?"button":void 0,tabIndex:l?0:void 0,"aria-pressed":l?!!i:void 0,onClick:l?function(e){var t;l&&(t=e.target,(function(e){if(!e)return null;if("function"==typeof e.closest)return e;let t=e.parentElement;return t&&"function"==typeof t.closest?t:null})(t)?.closest("a, button")||l())}:void 0,onKeyDown:l?e=>{e.target===e.currentTarget&&("Enter"===e.key||" "===e.key)&&(e.preventDefault(),l())}:void 0,className:(0,et.cn)("rounded-xl border p-4",d?`${d.bg} ${d.border}`:"border-border-default bg-surface-elevated/50",l&&"cursor-pointer transition-shadow hover:ring-1 hover:ring-accent/40",i&&"ring-2 ring-accent border-accent/60"),children:[(0,t.jsxs)("div",{className:"flex items-center justify-between gap-3 mb-3",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[e.origin&&(0,t.jsx)("span",{className:(0,et.cn)("inline-flex items-center justify-center w-8 h-8 rounded-full text-xs font-bold shrink-0","TN"===e.origin?"bg-success-bg text-success":"CA"===e.origin?"bg-info-bg text-info":"bg-surface-elevated text-text-secondary"),children:e.origin}),(0,t.jsxs)("div",{children:[a&&d&&(0,t.jsxs)("p",{className:(0,et.cn)("text-xs font-medium",d.color),children:["Shipped from ",d.label]}),(0,t.jsxs)("p",{className:(0,et.cn)("text-sm font-semibold flex items-center gap-1.5",P.color),children:[P.isOfd&&(0,t.jsxs)("span",{className:"relative flex h-2 w-2",children:[(0,t.jsx)("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-warning opacity-75"}),(0,t.jsx)("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-warning"})]}
1),P.label,e.inboundMode&&(0,t.jsx)("span",{className:"text-[10px] font-medium text-text-tertiary",children:"air"===e.inboundMode?"â Air":"ð¢ Ocean"})]}),(e.fulfillmentId||O.units>0)&&(0,t.jsx)("p",{className:"text-[10px] text-text-tertiary",children:E?(0,t.jsxs)(t.Fragment,{children:[O.units>0&&(0,t.jsxs)(t.Fragment,{children:[O.units.toLocaleString("en-US")," units"]}),"number"==typeof O.cartons&&O.cartons>0&&(0,t.jsxs)(t.Fragment,{children:[" · ",O.cartonsApprox?"~":"",O.cartons.toLocaleString("en-US")," cartons"]}),(O.units>0||(O.cartons??0)>0)&&" · ",E.length," fulfillments"]}):(0,t.jsxs)(t.Fragment,{children:[e.fulfillmentId&&(0,t.jsx)("span",{className:"font-mono",children:e.fulfillmentId}),O.units>0&&(0,t.jsxs)(t.Fragment,{children:[e.fulfillmentId&&" · ",O.units.toLocaleString("en-US")," units"]}),"number"==typeof O.cartons&&O.cartons>0&&(0,t.jsxs)(t.Fragment,{children:[" · ",O.cartonsApprox?"~":"",O.cartons.toLocaleString("en-US")," cartons"]})]})}),E&&(0,t.jsx)("div",{className:"mt-1 flex flex-wrap gap-1",children:E.map(({m:e,meta:r},n)=>(0,t.jsxs)("span",{className:"inline-flex items-center gap-1 rounded border border-border-subtle bg-surface-elevated/70 px-1.5 py-px font-mono text-[9.5px] text-text-secondary",children:[e.fulfillmentId||"IF â",r.units>0&&(0,t.jsxs)("span",{className:"text-text-tertiary",children:["· ",r.units.toLocaleString("en-US")]})]},e.fulfillmentId||n))})]})]}),(0,t.jsxs)("div",{className:"text-right",children:[X&&(0,t.jsx)("p",{className:"text-xs text-text-muted",children:L?"Delivered":"live"===Z?g?"USPS estimate":"UPS estimate":y?"Est. delivery":"Scheduled delivery"}),X&&(0,t.jsx)("p",{className:(0,et.cn)("text-sm font-semibold",L?"text-success":"text-accent"),children:X}),G&&(0,t.jsxs)("p",{className:"text-[10px] text-text-tertiary",children:["Delivers ",G]}),e.date&&(0,t.jsxs)("p",{className:X?"text-[10px] text-text-tertiary":"text-xs text-text-muted",children:[Y(e.upsTrackingStatus||e.status)," ",tc(e.date)]})]})]}),(e.containerRef||0===c.length&&u.length>0)&&(0,t.jsxs)("div",{className:"mb-2 space-y-1",children:[(0,t.jsxs)("p",{className:"text-[11px] text-text-secondary",children:["Shipped direct from factory",e.containerRef&&(R&&B?.highlightItemId!=null?(0,t.jsxs)(t.Fragment,{children:[" â ",(0,t.jsxs)("button",{type:"button",onClick:()=>(0,ee.openInboundShipment)(B),className:"text-accent hover:underline",title:"Open the inbound shipment record",children:["shipment ",(0,t.jsx)("span",{className:"font-mono",children:e.containerRef}),null!=e.inboundShipmentId&&(0,t.jsxs)(t.Fragment,{children:[" · IS #",e.inboundShipmentId]})," âº"]})]}):(0,t.jsxs)(t.Fragment,{children:[" â shipment ",(0,t.jsx)("span",{className:"font-mono",children:e.containerRef}),null!=e.inboundShipmentId&&(0,t.jsxs)("span",{className:"text-text-muted",children:[" ","(IS #",e.inboundShipmentId,")"]})]})),es&&(0,t.jsx)("span",{className:"text-text-muted",children:es})]}),0===c.length&&(e.containerTracking??[]).filter(e=>e&&e.length>=5).length>0&&(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,t.jsx)("span",{className:"text-[10px] font-medium text-text-tertiary",children:"Tracking:"}),(e.containerTracking??[]).filter(e=>e&&e.length>=5).map(r=>(0,t.jsx)(ti.default,{trackingNumber:r,carrier:e.carrier||"UPS",context:U,inbound:B},r))]})]}),0===c.length&&!e.containerRef&&0===u.length&&(L?(0,t.jsx)("div",{className:"mb-2 text-[11px] text-text-muted",children:"No carrier tracking on record for this shipment."}):e.freightRef?(0,t.jsxs)("div",{className:"mb-2 flex items-center gap-2 text-[11px] text-text-muted",children:[(0,t.jsx)("span",{className:"font-medium",children:"Ref:"}),(0,t.jsx)("span",{className:"font-mono text-text-secondary",children:e.freightRef}),(0,t.jsx)("span",{children:"â carrier tracking not recorded yet."})]}):(0,t.jsxs)("div",{className:"mb-2 flex items-center gap-2 text-[11px] text-text-muted",children:[(0,t.jsx)("svg",{className:"h-3 w-3 shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"})}),(0,t.jsx)("span",{children:"Tracking number will appear here once the carrier picks up the package."})]})),c.length>0&&(0,t.jsxs)("div",{className:"mb-2",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,t.jsx)("span",{className:"text-[10px] text-text-tertiary font-medium",children:"Tracking:"}),_?(0,t.jsx)(ti.default,{trackingNumber:c[0],carrier:e.carrier||"UPS",context:U,inbound:B}):(0,t.jsx)("span",{className:"text-xs font-mono text-text-secondary",children:c[0]}),c.length>1&&(0,t.jsxs)("button",{type:"button",onClick:()=>h(e=>!e),className:"text-[10px] text-accent hover:underline font-medium inline-flex items-center gap-0.5",children:[p?"Hide list":`+${c.length-1} more \xb7 ${c.length} packages`,(0,t.jsx)("svg",{className:(0,et.cn)("w-3 h-3 transition-transform",p&&"rotate-180"),fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19 9l-7 7-7-7"})})]})]}),p&&c.length>1&&(0,t.jsx)("div",{className:"mt-2 ml-1 grid gap-1 text-xs",children:c.slice(1).map((r,n)=>(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsxs)("span",{className:"text-[10px] text-text-muted w-6 tabular-nums",children:["#",n+2]}),_?(0,t.jsx)(ti.default,{trackingNumber:r,carrier:e.carrier||"UPS",context:U,inbound:B}):(0,t.jsx)("span",{className:"font-mono text-text-secondary",children:r})]},r))})]}),T?.latestEvent&&!L&&!P.isException&&(0,t.jsxs)("div",{className:"flex items-center gap-1.5 mb-2 text-[11px] text-text-secondary",children:[(0,t.jsx)("svg",{className:"w-3 h-3 text-text-tertiary shrink-0",fill:"currentColor",viewBox:"0 0 20 20",children:(0,t.jsx)("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zm.75-13a.75.75 0 00-1.5 0v5c0 .414.336.75.75.75h4a.75.75 0 000-1.5h-3.25V5z",clipRule:"evenodd"})}),(0,t.jsxs)("span",{className:"truncate",children:[T.latestEvent.location&&(0,t.jsxs)("span",{className:"font-medium",children:[T.latestEvent.location," · "]}),T.latestEvent.description,T.latestEvent.when&&(0,t.jsxs)("span",{className:"text-text-muted",children:[" · ",T.latestEvent.when]})]})]}),z&&(0,t.jsxs)("div",{className:"flex items-center gap-2 mb-2",children:[(0,t.jsx)("span",{className:"text-[10px] text-text-tertiary font-medium",children:"Invoice:"}),(0,t.jsx)(tl.default,{href:`/account/activity?invoice=${z.invoiceNumber}`,className:"text-xs text-accent hover:underline font-mono",children:z.invoiceNumber}),null!=z.total&&(0,t.jsxs)("span",{className:"text-xs text-text-muted",children:["$",z.total.toLocaleStr
1ing("en-US",{minimumFractionDigits:2})]}),z.status&&(0,t.jsx)("span",{className:(0,et.cn)("text-[9px] font-medium px-1.5 rounded",z.status.includes("Paid")?"bg-success-bg text-success":"bg-warning-bg text-warning"),children:z.status.includes("Paid")?"Paid":"Open"})]})]})}function tp({fulfillments:e,invoices:r,orderCompleted:n,selectedId:s,onSelect:a,activeItem:i}){if(!e||0===e.length)return null;let l=new Set(e.map(e=>e.origin).filter(Boolean)).size>1;return(0,t.jsxs)("div",{className:"space-y-3",children:[e.map(e=>(0,t.jsx)(tm,{f:e,invoices:r,orderCompleted:n,isMultiWarehouse:l,activeItem:i,selected:null!=s&&e.fulfillmentId===s,onSelect:a&&(e.groupMembers??[e]).some(e=>(e.lines?.length??0)>0)?()=>a(e.fulfillmentId):void 0},e.fulfillmentId)),l&&(0,t.jsx)("div",{className:"rounded-lg border border-info/30 bg-info-bg px-3 py-2",children:(0,t.jsxs)("p",{className:"text-[11px] text-info",children:["This order shipped from ",new Set(e.map(e=>e.origin).filter(Boolean)).size," locations for fastest delivery. Each location generates a separate invoice."]})})]})}function th({trackingNumber:e,enabled:t,onReport:n,usps:s=!1}){let{data:a}=(0,H.useUpsTracking)(e,t&&!s),{data:i}=(0,W.useUspsTracking)(e,t&&s),l=a||i;return(0,r.useEffect)(()=>{l&&n(e,{deliveryState:s?void 0:a?.deliveryState,statusDescription:l.statusDescription,ofd:l.isOfd,exception:l.isException,delivered:l.isDelivered,eta:l.estimatedDelivery||null})},[l,e,n]),null}function tf({fulfillments:e,morePending:n,v4:s}){let[a,i]=(0,r.useState)({}),l=(0,r.useCallback)((e,t)=>{i(r=>{let n=r[e];return n&&n.statusDescription===t.statusDescription&&n.ofd===t.ofd&&n.exception===t.exception&&n.delivered===t.delivered&&n.eta===t.eta?r:{...r,[e]:t}})},[]);if(!e||0===e.length)return null;let o=e.map(e=>{let t=(e.trackingNumbers||[]).find(e=>e.length>=5)||(e.containerTracking||[]).find(e=>e.length>=5)||"",r=(0,H.isUpsShipment)(e.carrier,t),n=!!s&&!r&&(0,K.isUspsShipment)(e.carrier,t),a=(e.upsTrackingStatus||e.status||"").toLowerCase(),i=n?(0,W.isWithinUspsTrackingWindow)(e.date||null):(0,H.isWithinUpsTrackingWindow)(e.date||null),l=!!e.containerRef||(e.containerTracking?.length??0)>0,o=!!e.containerDelivered,d="CA"===e.origin||"TN"===e.origin?e.origin:void 0;return{f:e,tracking:t,isUps:r,isUsps:n,nsText:a,inWindow:i,origin:d,containerBacked:l,containerDelivered:o}}),d=o.filter(e=>(e.isUps||e.isUsps)&&e.tracking&&e.inWindow),c=o.map(e=>{var t;let r=e.inWindow?a[e.tracking]:null,n=(t=e.f,td(t,!1,r?{deliveryState:r.deliveryState,statusDescription:r.statusDescription,isDelivered:r.delivered,isOfd:r.ofd,isException:r.exception,estimatedDelivery:r.eta}:null,e.isUps||e.isUsps)).state;return"delivered"===n?"delivered":"partially-delivered"===n?"partially_delivered":"out-for-delivery"===n?"ofd":"exception"===n?"exception":"in-transit"===n?"in_transit":"pending-pickup"===n||"pending"===n?"pending_pickup":"shipped"===n?"shipped":"unknown"}),u=c.filter(e=>"unknown"!==e);if(0===u.length&&!n&&!s)return null;let x=c.includes("exception"),m=c.includes("ofd"),p=c.length>0&&c.every(e=>"delivered"===e),h=x?"exception":m?"ofd":p?"delivered":"in_transit",f=d.map(e=>a[e.tracking]).filter(Boolean).map(e=>e.eta).filter(e=>!!e),g=f.length>0?f.reduce((e,t)=>{let r=tg(e),n=tg(t);return null===r?t:null===n?e:n<r?t:e}):null,b="delivered"===h||"exception"===h?null:function(e){if(!e)return null;let t=e.split("/");if(3!==t.length)return null;let r=parseInt(t[0],10),n=parseInt(t[1],10),s=parseInt(t[2],10);if(![r,n,s].every(Number.isFinite))return null;let a=new Date(Date.UTC(s,r-1,n));if(Number.isNaN(a.getTime()))return null;let i=new Date(`${(0,A.businessToday)()}T00:00:00.000Z`),l=Math.round((a.getTime()-i.getTime())/864e5);return l<0?null:0===l?"today":1===l?"tomorrow":l<=7?`in ${l} days`:a.toLocaleDateString("en-US",{month:"short",day:"numeric",timeZone:"UTC"})}(g);if(s){let r=c.filter(e=>"delivered"===e).length,s=e8(e.length,r,!!n,x,c.filter(e=>"partially_delivered"===e).length),a=0===r&&c.every(e=>"pending_pickup"===e),i=0===r&&0===u.length,o=c.length>0&&c.every(e=>"shipped"===e);return(0,t.jsxs)(t.Fragment,{children:[d.map(e=>
1(0,t.jsx)(th,{trackingNumber:e.tracking,enabled:!0,usps:e.isUsps,onReport:l},e.tracking)),(0,t.jsx)("span",{className:`mt-1 block text-xs font-semibold ${x?"text-error":r>0?"text-text-primary":"text-accent-dark"}`,children:a?"Preparing shipment":o?"Shipped":i?"Delivery status pending":s.label}),s.detail&&(0,t.jsx)("span",{className:"mt-1 block text-[11px] text-text-secondary",children:s.detail})]})}return(0,t.jsxs)(t.Fragment,{children:[d.map(e=>(0,t.jsx)(th,{trackingNumber:e.tracking,enabled:!0,onReport:l},e.tracking)),e.length>=3?(0,t.jsx)(ty,{states:c,total:e.length}):o.map((e,r)=>"unknown"===c[r]?null:(0,t.jsx)(tv,{origin:e.origin,state:c[r]},e.tracking||r)),b&&(0,t.jsx)(tN,{label:b}),n&&(0,t.jsx)(tj,{})]})}function tg(e){let t=e.split("/");if(3!==t.length)return null;let r=parseInt(t[0],10),n=parseInt(t[1],10),s=parseInt(t[2],10);if(![r,n,s].every(Number.isFinite))return null;let a=new Date(s,r-1,n);return Number.isNaN(a.getTime())?null:a.getTime()}let tb={shipped:{cls:"bg-surface-elevated text-text-secondary",dot:"bg-text-muted",word:"Shipped"},partially_delivered:{cls:"bg-info-bg text-info",dot:"bg-info",word:"Partially delivered"},delivered:{cls:"bg-success-bg text-success",dot:"bg-success",word:"Delivered",check:!0},ofd:{cls:"bg-warning-bg text-warning",dot:"bg-warning",word:"Out for Delivery",ping:!0},in_transit:{cls:"bg-info-bg text-info",dot:"bg-info",word:"In Transit"},pending_pickup:{cls:"bg-surface-elevated text-text-secondary",dot:"bg-text-muted",word:"Pending Pickup"},exception:{cls:"bg-error-bg text-error",dot:"bg-error",word:"Action Needed"}};function ty({states:e,total:r}){return(0,t.jsx)(t.Fragment,{children:["delivered","partially_delivered","shipped","ofd","in_transit","pending_pickup","exception"].map(n=>{let s=e.filter(e=>e===n).length;if(0===s)return null;let a=tb[n],i="delivered"===n?`${s} of ${r} delivered`:`${s} ${a.word.toLowerCase()}`;return(0,t.jsxs)("span",{className:`ml-2 inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-[10px] font-medium ${a.cls}`,children:[a.check?(0,t.jsx)("svg",{className:"h-2.5 w-2.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:3,children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})}):(0,t.jsx)("span",{className:`inline-flex h-1.5 w-1.5 rounded-full ${a.dot}`}),i]},n)})})}function tv({origin:e,state:r}){if("unknown"===r)return null;let n=tb[r];return(0,t.jsxs)("span",{className:`ml-2 inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-[10px] font-medium ${n.cls}`,title:e?`Ships from ${e}`:void 0,children:[e&&(0,t.jsx)("span",{className:"font-semibold tracking-wide opacity-80",children:e}),n.check?(0,t.jsx)("svg",{className:"h-2.5 w-2.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:3,children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})}):n.ping?(0,t.jsxs)("span",{className:"relative flex h-1.5 w-1.5",children:[(0,t.jsx)("span",{className:`absolute inline-flex h-full w-full animate-ping rounded-full ${n.dot} opacity-75`}),(0,t.jsx)("span",{className:`relative inline-flex h-1.5 w-1.5 rounded-full ${n.dot}`})]}):(0,t.jsx)("span",{className:`inline-flex h-1.5 w-1.5 rounded-full ${n.dot}`}),n.word]})}function tj(){return(0,t.jsxs)("span",{className:"ml-2 inline-flex items-center gap-1 rounded-full bg-warning-bg px-2 py-0.5 text-[10px] font-medium text-warning",title:"More items on this order are still being prepared or shipped from another warehouse.",children:[(0,t.jsxs)("svg",{className:"h-2.5 w-2.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:[(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 17a2 2 0 11-4 0 2 2 0 014 0zm10 0a2 2 0 11-4 0 2 2 0 014 0z"}),(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M13 16V6a1 1 0 00-1-1H3m10 11h4m4 0v-3.6a1 1 0 00-.3-.7l-2.4-2.4a1 1 0 00-.7-.3H13"})]}),"More on the way"]})}function tN({label:e}){return(0,t.jsxs)("span",{className:"ml-1.5 inline-flex items-center gap-1 rounded-full bg-surface-elevated px-2 py-0.5 text-[10px] font-medium text-text-secondary",children:[(0,t.jsx)("svg",{className:"h-2.5 w-2.5 text-text-tertiary",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"})}),"Delivers ",e]})}var tw=e.i(762568),tk=e.i(250222),tS=e.i(338685),tC=e.i(485362);function t$({order:e,api:n}){let[s,a]=(0,r.useState)({kind:"idle"}),[i,l]=(0,r.useState)(""),o=function(e,t){if(!t||!eC(e))return{kind:"none"};let r=t.can(e),n=!0===r.approve,s=!0===r.cancel;return{kind:"actionable",canApprove:n,canCancel:s,reason:n||s?void 0:r.reason}}(e,n);if("none"===o.kind||!n)return null;let d="working"===s.kind;async function c(t){if(n){a({kind:"working",action:t});try{"approve"===t?await n.approve(e):"cancel"===t?await n.cancel(e,i.trim()):await n.nudge?.(e),a({kind:"done",action:t}),l(""),"nudge"!==t&&n.onChanged?.()}catch(e){a({kind:"error",message:e instanceof Error&&e.message?e.message:"That didn't go through. Please try again in a moment."})}}}return"done"===s.kind?(0,t.jsxs)("div",{className:"flex items-center gap-2 border-t border-success/30 bg-success-bg px-5 py-3 text-sm text-success",children:[(0,t.jsx)(R.Check,{className:"h-4 w-4 shrink-0"}),(0,t.jsx)("span",{children:"approve"===s.action?`Approved. ${e.orderNumber} is released for fulfillment.`:"cancel"===s.action?`Cancelled. ${e.orderNumber} is closed and the buyer has been notified.`:`Your administrator has been reminded about ${e.orderNumber}.`})]}):(0,t.jsxs)("div",{className:"border-t border-warning/30 bg-warning-bg/60 px-5 py-3",children:[(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-2",children:[(0,t.jsx)(tC.ShieldCheck,{className:"h-4 w-4 shrink-0 text-warning-foreground
1/70"}),(0,t.jsx)("span",{className:"text-sm font-semibold text-text-primary",children:"Waiting for approval"}),o.reason&&(0,t.jsx)("span",{className:"text-sm text-text-secondary",children:o.reason}),"cancelling"!==s.kind&&(o.canApprove||o.canCancel||!!n.nudge)&&(0,t.jsxs)("span",{className:"ml-auto flex flex-wrap items-center gap-2",children:[o.canApprove&&(0,t.jsxs)("button",{type:"button",disabled:d,onClick:()=>c("approve"),className:"inline-flex items-center gap-1.5 rounded-lg bg-success px-3 py-1.5 text-sm font-semibold text-success-foreground transition-opacity hover:opacity-90 focus:outline-none focus-visible:ring-2 focus-visible:ring-accent disabled:opacity-60",children:[d&&"approve"===s.action?(0,t.jsx)(tS.Loader2,{className:"h-3.5 w-3.5 animate-spin"}):(0,t.jsx)(R.Check,{className:"h-3.5 w-3.5"}),"Approve"]}),o.canCancel&&(0,t.jsxs)("button",{type:"button",disabled:d,onClick:()=>{a({kind:"cancelling"}),l("")},className:"inline-flex items-center gap-1.5 rounded-lg border border-error/40 px-3 py-1.5 text-sm font-semibold text-error transition-colors hover:bg-error-bg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent disabled:opacity-60",children:[(0,t.jsx)(q.X,{className:"h-3.5 w-3.5"}),"Cancel order"]}
1),n.nudge&&(0,t.jsxs)("button",{type:"button",disabled:d,onClick:()=>c("nudge"),className:"inline-flex items-center gap-1.5 rounded-lg border border-accent/40 px-3 py-1.5 text-sm font-semibold text-accent transition-colors hover:bg-accent/5 focus:outline-none focus-visible:ring-2 focus-visible:ring-accent disabled:opacity-60",children:[d&&"nudge"===s.action?(0,t.jsx)(tS.Loader2,{className:"h-3.5 w-3.5 animate-spin"}):(0,t.jsx)(tk.Bell,{className:"h-3.5 w-3.5"}),"Nudge admin"]})]})]}),"cancelling"===s.kind&&(0,t.jsxs)("div",{className:"mt-3 rounded-lg border border-border-subtle bg-surface p-3",children:[(0,t.jsxs)("label",{htmlFor:`cancel-reason-${e.id}`,className:"block text-sm font-medium text-text-primary",children:["Why is ",e.orderNumber," being cancelled?"]}),(0,t.jsx)("p",{className:"mt-0.5 text-xs text-text-tertiary",children:"This closes the order and is sent to whoever placed it."}),(0,t.jsx)("textarea",{id:`cancel-reason-${e.id}`,value:i,onChange:e=>l(e.target.value),rows:2,autoFocus:!0,placeholder:"e.g. Duplicate of an order already placed",className:"mt-2 w-full rounded-lg border border-border-subtle bg-surface-elevated px-3 py-2 text-sm outline-none focus:border-accent"}),(0,t.jsxs)("div",{className:"mt-2 flex justify-end gap-2",children:[(0,t.jsx)("button",{type:"button",onClick:()=>a({kind:"idle"}),className:"rounded-lg px-3 py-1.5 text-sm font-medium text-text-secondary transition-colors hover:bg-surface-elevated focus:outline-none focus-visible:ring-2 focus-visible:ring-accent",children:"Keep order"}),(0,t.jsx)("button",{type:"button",disabled:!(i.trim().length>=3),onClick:()=>c("cancel"),className:"inline-flex items-center gap-1.5 rounded-lg bg-error px-3 py-1.5 text-sm font-semibold text-error-foreground transition-opacity hover:opacity-90 focus:outline-none focus-visible:ring-2 focus-visible:ring-accent disabled:opacity-50",children:"Cancel this order"})]})]}),"error"===s.kind&&(0,t.jsxs)("div",{role:"alert",className:"mt-2 flex items-start gap-2 text-sm text-error",children:[(0,t.jsx)(tw.AlertCircle,{className:"mt-0.5 h-4 w-4 shrink-0"}),(0,t.jsx)("span",{children:s.message})]})]})}var tI=e.i(255073),tD=e.i(530147);function tT(e={}){let{skipStockCheck:t=!1,clampShortStock:n=!0,onSuccess:s}=e,a=I(),[i,l]=(0,r.useState)(!1),[o,d]=(0,r.useState)(null),c=(0,r.useCallback)(()=>d(null),[]);return{reorder:(0,r.useCallback)(async e=>{l(!0),d(null);try{let r=[],{products:i}=function(e){let t=e.map(e=>({itemId:e.itemId,itemName:e.itemName??"",externalId:e.externalId,description:e.description,quantity:e.quantity,rate:e.rate??0,amount:0,quantityShipped:0,quantityBackordered:0,isDropShip:!1})),r=new Set((0,x.splitOrderLines)(t).products.map(e=>e.itemId)),n=[],s=[];for(let t of e)r.has(t.itemId)?n.push(t):s.push(t);return{products:n,nonProducts:s}}(e),l=[];for(let e of i){if(e.quantity<=0){r.push({itemId:e.itemId,externalId:e.externalId,itemName:e.itemName,description:e.description,requested:e.quantity,queued:0,status:"skipped_zero_qty",message:"Zero quantity â line was fully refunded"});continue}l.push(e)}let o=new Map;for(let e of l){let t=o.get(e.itemId);t?t.quantity+=e.quantity:o.set(e.itemId,{...e})}let c=Array.from(o.values());if(!t&&c.length>0)try{let e=await fetch("/api/stock-check",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:c.map(e=>({itemId:e.itemId,quantity:e.quantity}))})});if(e.ok){let t=await e.json(),s=t?.data?.items??t?.items??[],a=new Map;for(let e of s)a.set(e.itemId,e);let i=[];for(let e of c){let t=a.get(e.itemId);if(!t){i.push(e);continue}if(t.available<=0){r.push({itemId:e.itemId,externalId:e.externalId,itemName:e.itemName,description:e.description,requested:e.quantity,queued:0,available:t.available,status:"skipped_out_of_stock",message:"Out of stock"});continue}if(t.isShort&&!n){r.push({itemId:e.itemId,externalId:e.externalId,itemName:e.itemName,description:e.description,requested:e.quantity,queued:0,available:t.available,status:"skipped_short",message:`Only ${t.available} available (you ordered ${e.quantity})`});continue}if(t.isShort&&n){i.push({...e,quantity:t.available});continue}i.push(e)}c=i}}catch{}let u=null,m=[];if(c.length>0)try{if(!a)throw Error("Reorder is not available in this context (no cart provider).");for(let e of(await a.addItems(c.map(e=>({itemId:e.itemId,quantity:e.quantity}))),c))m.push({itemId:e.itemId,externalId:e.externalId,itemName:e.itemName,description:e.description,requested:e.quantity,queued:e.quantity,status:"added"})}catch(e){for(let t of(u=e instanceof Error?e.message:"Failed to add items to cart",c))r.push({itemId:t.itemId,externalId:t.externalId,itemName:t.itemName,description:t.description,requested:t.quantity,queued:0,status:"skipped_unknown",message:u})}let p={added:m,skipped:r,totalAdded:m.length,totalAddedUnits:m.reduce((e,t)=>
1e+t.queued,0),totalSkipped:r.length,hardError:u};return d(p),m.length>0&&s?.(p),p}finally{l(!1)}},[a,t,n,s]),reordering:i,lastSummary:o,reset:c}}function tP(e){let t=I(),r=new Map;if(!t?.countInCart||0===e.length)return r;for(let n of e){let e=t.countInCart(n);e>0&&r.set(n,e)}return r}function tL({item:e,flashMs:n=2500}){let s,{reorder:a,reordering:i,lastSummary:l,reset:o}=tT({}),d=tP([e.itemId]).get(e.itemId)??0,{ui:c,skipReason:u}=(0,r.useMemo)(()=>{if(i)return{ui:"loading",skipReason:null};if(!l)return{ui:"idle",skipReason:null};if(l.hardError)return{ui:"error",skipReason:l.hardError};if(l.added.find(t=>t.itemId===e.itemId))return{ui:"added",skipReason:null};let t=l.skipped.find(t=>t.itemId===e.itemId);return t?{ui:"skipped",skipReason:t.message??"Skipped"}:{ui:"idle",skipReason:null}},[i,l,e.itemId]);if((0,r.useEffect)(()=>{if("idle"===c||"loading"===c)return;let e=setTimeout(()=>o(),n);return()=>clearTimeout(e)},[c,n,o]),!(0,r.useContext)(C).showAddLine)return null;let x=async t=>{t.stopPropagation(),await a([e])};if("loading"===c)s=(0,t.jsx)(tE,{});else if("added"===c){let r=d||l?.added.find(t=>t.itemId===e.itemId)?.queued||0;s=(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(R.Check,{className:"h-3 w-3"}),(0,t.jsx)("span",{children:r>0?`In cart (${r})`:"Added"})]})}else s="skipped"===c?(0,t.jsx)("span",{className:"text-[10px]",children:u||"Skipped"}):"error"===c?(0,t.jsx)("span",{className:"text-[10px]",children:"Try again"}):d>0?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(tD.Plus,{className:"h-3 w-3"}),(0,t.jsx)("span",{children:"Add"}),(0,t.jsxs)("span",{className:"ml-1 rounded-full bg-accent/15 px-1.5 text-[10px] font-semibold text-accent",children:[d," in cart"]})]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(tD.Plus,{className:"h-3 w-3"}),(0,t.jsx)("span",{children:"Add"})]});return(0,t.jsx)("button",{type:"button",onClick:x,disabled:"loading"===c,title:"skipped"===c?u||"Couldn't add":"added"===c?"Added to cart":`Add ${e.quantity} to cart`,"aria-label":`Add ${e.itemName||e.externalId||"item"} to cart`,className:`inline-flex items-center gap-1 rounded-md border px-2 py-1 text-[11px] font-medium transition-colors disabled:cursor-not-allowed ${{idle:"border-border-subtle bg-surface text-text-tertiary hover:border-accent hover:bg-accent/5 hover:text-accent",loading:"border-border-subtle bg-surface-elevated text-text-tertiary",added:"border-success/30 bg-success-bg text-success",skipped:"border-warning/30 bg-warning-bg text-warning",error:"border-error/30 bg-error-bg text-error"}[c]}`,children:s})}function tE(){return(0,t.jsxs)("svg",{className:"h-3 w-3 animate-spin",viewBox:"0 0 16 16","aria-hidden":!0,children:[(0,t.jsx)("circle",{cx:"8",cy:"8",r:"6",fill:"none",stroke:"currentColor",strokeWidth:"2",opacity:"0.25"}),(0,t.jsx)("path",{d:"M14 8a6 6 0 0 0-6-6",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]})}var tO=e.i(201289);function tA({order:e,onResult:n}){let{reorder:s,reordering:a}=tT({onSuccess:e=>n?.(e.totalAdded,e.totalSkipped)}),[i,l]=(0,r.useState)(null),[o,d]=(0,r.useState)(!1),c=e.lines??i??[],u=c.filter(e=>e.quantity>0).map(e=>({itemId:e.itemId,quantity:e.quantity,externalId:e.externalId,itemName:e.itemName,description:e.description,rate:e.rate})),m=tP(u.map(e=>e.itemId)).size;if(!(0,r.useContext)(C).showBuyAgain||(e.lineCount??0)===0||null!==i&&0===u.length)return null;let p=u.length||e.lineCount||0;async function h(){if(c.length>0)return c;if(o)return null;d(!0);try{let t=await fetch(`/api/customer/orders?orderId=${e.id}&includeLines=true`),r=await t.json(),n=r?.data?.orders?.[0]??r?.orders?.[0],s=n?.lines??[];return l(s),s}catch(e){return console.error("[QuickReorderButton] detail fetch failed:",e),null}finally{d(!1)}}function f(e){let{products:t}=(0,x.splitOrderLines)(e);return t.filter(e=>e.quantity>0).map(e=>({itemId:e.itemId,quantity:e.quantity,externalId:e.externalId,itemName:e.itemName,description:e.description,rate:e.rate}))}let g=a||o,b=async e=>{if(e.stopPropagation(),g)return;let t=await h();t&&0!==t.length&&await s(f(t))},y=async e=>{if("Enter"===e.key||" "===e.key){if(e.preventDefault(),e.stopPropagation(),g)return;let t=await h();t&&0!==t.length&&await s(f(t))}};return(0,t.jsx)("span",{role:"button",tabIndex:g?-1:0,onClick:b,onKeyDown:y,"aria-disabled":g||void 0,"aria-label":`Buy again â ${p} items from ${e.orderNumber}`,title:`Buy again â ${p} ${1===p?"item":"items"}`,className:`inline-flex select-none items-center gap-1 rounded-md border border-border-subtle bg-surface px-2 py-1 text-[11px] font-medium text-text-secondary transition-colors hover:border-accent hover:bg-accent/5 hover:text-accent focus:outline-none focus-visible:ring-2 focus-visible:ring-accent ${g?"cursor-not-allowed opacity-60":"cursor-pointer"}`,children:o?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(tM,{}),(0,t.jsx)("span",{children:"Loadingâ¦"})]}):a?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(tM,{}),(0,t.jsx)("span",{children:"Addingâ¦"})]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(tO.ShoppingCart,{className:"h-3 w-3"}),(0,t.jsx)("span",{children:"Buy again"}),m>0&&u.length>0&&(0,t.jsx)("span",{className:"ml-1 rounded-full bg-accent/15 px-1.5 text-[10px] font-semibold text-accent",children:m===u.length?"all in cart":`${m} in cart`})]})})}function tM(){return(0,t.jsxs)("svg",{className:"h-3 w-3 animate-spin",viewBox:"0 0 16 16","aria-hidden":!0,
1children:[(0,t.jsx)("circle",{cx:"8",cy:"8",r:"6",fill:"none",stroke:"currentColor",strokeWidth:"2",opacity:"0.25"}),(0,t.jsx)("path",{d:"M14 8a6 6 0 0 0-6-6",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]})}let tU={success:"border-success/20 bg-success-bg text-success",partial:"border-warning/20 bg-warning-bg text-warning",empty:"border-border-subtle bg-surface-elevated text-text-secondary",error:"border-error/20 bg-error-bg text-error"},tR={added:"Added",skipped_zero_qty:"Skipped",skipped_out_of_stock:"Out of stock",skipped_short:"Low stock",skipped_unknown:"Couldn't add"},tF={added:"bg-success/10 text-success",skipped_zero_qty:"bg-text-muted/10 text-text-tertiary",skipped_out_of_stock:"bg-warning/10 text-warning",skipped_short:"bg-warning/10 text-warning",skipped_unknown:"bg-error/10 text-error"};function tq({summary:e,orderRef:r,onDismiss:n,onViewCart:s,collapseDetails:a=!1}){let i,l,{added:o,skipped:d,totalAdded:c,totalAddedUnits:u,totalSkipped:x,hardError:m}=e;return m?(i="error",l=`Couldn't add to cart â ${m}`):c>0&&0===x?(i="success",l=`Added ${u} ${1===u?"item":"items"} to cart${r?` from ${r}`:""}`):c>0&&x>0?(i="partial",l=`Added ${u} ${1===u?"item":"items"} \xb7 ${x} skipped`):(i="empty",l="Nothing to add â all items unavailable or refunded"),(0,t.jsxs)("div",{role:"status","aria-live":"polite",className:`rounded-lg border px-3 py-2 text-xs ${tU[i]}`,children:[(0,t.jsxs)("div",{className:"flex items-start justify-between gap-3",children:[(0,t.jsxs)("div",{className:"flex min-w-0 items-center gap-1.5 font-medium",children:[(0,t.jsx)(t_,{tone:i}),(0,t.jsx)("span",{className:"truncate",children:l})]}),(0,t.jsxs)("div",{className:"flex flex-shrink-0 items-center gap-2",children:[s&&c>0&&(0,t.jsx)("button",{type:"button",onClick:s,className:"text-[11px] font-semibold underline underline-offset-2 hover:opacity-80",children:"View cart â"}),n&&(0,t.jsx)("button",{type:"button",onClick:n,"aria-label":"Dismiss",className:"text-current/60 leading-none hover:opacity-80",children:"Ã"})]})]}),!a&&(o.length>0||d.length>0)&&(0,t.jsxs)("ul",{className:"mt-2 grid gap-1",children:[o.map((e,r)=>(0,t.jsx)(tB,{r:e},`a-${e.itemId}-${r}`)),d.map((e,r)=>(0,t.jsx)(tB,{r:e},`s-${e.itemId}-${r}`))]})]})}function tB({r:e}){let r=tR[e.status],n=tF[e.status],s=e.description||e.itemName||e.externalId||`Item ${e.itemId}`,a="added"===e.status;return(0,t.jsxs)("li",{className:"flex items-center gap-2 text-text-primary",children:[(0,t.jsxs)("span",{className:"min-w-0 flex-1 truncate",children:[(0,t.jsx)("span",{className:"font-medium",children:s}),e.externalId&&e.externalId!==s&&(0,t.jsx)("span",{className:"ml-1 font-mono text-[10px] text-text-tertiary",children:e.externalId}),a&&e.queued>0&&(0,t.jsxs)("span",{className:"ml-1 text-text-tertiary",children:["· qty ",e.queued]}),!a&&e.message&&(0,t.jsxs)("span",{className:"ml-1 text-text-tertiary",children:["· ",e.message]})]}),(0,t.jsx)("span",{className:`flex-shrink-0 rounded-full px-1.5 py-0.5 text-[10px] font-medium ${n}`,children:r})]})}function t_({tone:e}){return"success"===e?(0,t.jsx)("svg",{viewBox:"0 0 16 16",width:"14",height:"14",fill:"none",stroke:"currentColor",strokeWidth:"2.5","aria-hidden":!0,children:(0,t.jsx)("path",{d:"M3 8.5l3 3 7-7",strokeLinecap:"round",strokeLinejoin:"round"})}):"partial"===e||"error"===e?(0,t.jsxs)("svg",{viewBox:"0 0 16 16",width:"14",height:"14",fill:"none",stroke:"currentColor",strokeWidth:"1.6","aria-hidden":!0,children:[(0,t.jsx)("path",{d:"M8 1.5L0.5 14h15L8 1.5z"}),(0,t.jsx)("path",{d:"M8 6v4M8 11.5v.5",strokeLinecap:"round"})]}):(0,t.jsxs)("svg",{viewBox:"0 0 16 16",width:"14",height:"14",fill:"none",stroke:"currentColor",strokeWidth:"1.5","aria-hidden":!0,children:[(0,t.jsx)("circle",{cx:"8",cy:"8",r:"6.5"}),(0,t.jsx)("path",{d:"M8 7.5v4M8 5v.5",strokeLinecap:"round"})]})}var tz=e.i(929543),tH=e.i(984755);function tW({stage:e}){return(0,t.jsx)("ol",{"aria-label":"Shipment progress",className:"mx-2 mt-4 flex justify-between sm:mx-10",children:["Ready to ship","Shipped","Out for delivery","Delivered"].map((r,n)=>(0,t.jsxs)("li",{"aria-current":n===e?"step":void 0,className:"relative flex flex-1 flex-col items-center gap-2 text-center text-[11px] sm:text-xs",children:[n<3&&(0,t.jsx)("span",{"aria-hidden":"true",className:`absolute left-1/2 top-2 h-px w-full ${null!==e&&n<e?"bg-accent":"bg-border-default"}`}),(0,t.jsx)("span",{"aria-hidden":"true",className:`relative flex h-4 w-4 items-center justify-center rounded-full border-2 ${null!==e&&n<e?"border-accent bg-accent text-white":n===e?"border-accent bg-surface ring-2 ring-accent/20":"border-border-default bg-surface"}`,children:null!==e&&n<e?(0,t.jsx)(R.Check,{className:"h-3 w-3"}
1):n===e?(0,t.jsx)("span",{className:"h-1.5 w-1.5 rounded-full bg-accent"}):null}),(0,t.jsx)("span",{className:n===e?"font-semibold text-accent-dark":"text-text-secondary",children:r})]},r))})}let tK=(0,r.createContext)({});function tV(){return(0,r.useContext)(tK)}function tQ(e){return Math.max(.02,Math.min(.98,[.03,.12,.5,.9][Math.max(0,Math.min(3,Math.floor(e)))]))}e.s(["ActivityV4SlotsProvider",0,function({value:e,children:r}){return(0,t.jsx)(tK.Provider,{value:e,children:r})},"stageFallbackProgress",0,tQ,"useActivityV4Slots",0,tV],102283);let tX={CA:"California",TN:"Tennessee"};function tZ({f:e,order:n,label:s,selected:a,onSelect:i,onReport:l,renderDetails:d}){let c=tV(),u=h(e.trackingNumbers??[]),x=u[0]||null,m=(0,H.isUpsShipment)(e.carrier,x),p=!m&&(0,K.isUspsShipment)(e.carrier,x),f=/delivered/i.test(e.upsTrackingStatus||e.status||""),{data:g,loading:b}=(0,H.useUpsTracking)(x,m&&(0,H.isWithinUpsTrackingWindow)(e.date)),{data:y,loading:v}=(0,W.useUspsTracking)(x,p&&(0,W.isWithinUspsTrackingWindow)(e.date)),j=g||y,N=td(e,!1,j,m||p),w=!!j?.isDelivered||!j&&(f||!!e.containerDelivered),k=w||"Delivered"!==N.label?N.label:"Delivery status pending",S=N.isOfd||j?.status==="out_for_delivery"?2:j?.status==="in_transit"||j?.status==="picked_up"?1:j?.status==="pre_shipment"||/label|ready|processing|pre.?shipment/i.test(k)?0:/transit|picked up|shipped|facility|on the way|we have your package|accepted/i.test(k)?1:null,C=j?.estimatedDelivery||(w?null:e.deliveryDate),$=(0,A.upcomingDeliveryDate)(C),I=!!j?.estimatedDelivery&&(0,A.formatDate)(j.estimatedDelivery)===(0,A.formatDate)((0,A.businessToday)()),D=j?.deliveredDate?.split(" ")[0]||(e.containerDelivered?e.containerArrived:null),T=(e.groupMembers??[e]).flatMap(e=>e.lines??[]).filter(e=>e.quantity>0),[P,L]=(0,r.useState)(!1),E="CA"===e.origin?"chino":"TN"===e.origin?"nashville":null,O=n.shippingAddress?.state?.trim().toUpperCase()||null,M=j?.latestEvent?.location||null,U=j?.latestEvent?[j.latestEvent.location,j.latestEvent.description,j.latestEvent.when].filter(Boolean).join(" · "):void 0,F=!w&&!!E&&!!O&&(null!==S||!!M),q=2===S?3:2*(1===S),B=F?c.deriveProgress?.({from:E,toState:O,scanLocation:M,stage:q})??tQ(q):0,_=!!c.renderMap;(0,r.useEffect)(()=>
1{l(e.fulfillmentId,{delivered:w,map:F&&_?{id:x||e.fulfillmentId,from:E,toState:O,progress:B,status:k,lastScan:U,label:s}:null})},[e.fulfillmentId,w,F,_,x,E,O,B,k,U,s,l]);let z=e.origin&&tX[e.origin],V=w?"Delivered":I&&!N.isException?"Expected today":k,Q=u.length>0?(0,t.jsx)("div",{className:"flex flex-wrap gap-x-3 gap-y-2",children:u.map((r,n)=>(0,t.jsx)(ti.default,{trackingNumber:r,carrier:e.carrier||"",context:`${s} \xb7 ${e.fulfillmentId}`,label:u.length>1?`Track package ${n+1}`:"Track shipment",className:"inline-flex items-center gap-1 rounded-full border border-accent/25 bg-accent-subtle px-3 py-1.5 text-xs font-semibold text-accent-dark hover:bg-accent-bg"},r))}):(0,t.jsx)("span",{className:"text-xs text-text-tertiary",children:"Tracking pending"}),X=T.length>0&&i?(0,t.jsxs)("button",{type:"button","aria-pressed":a,onClick:()=>i(e.fulfillmentId),className:"inline-flex items-center gap-1 text-xs font-semibold text-accent-dark hover:underline",children:[a?"Show all items":"View items",(0,t.jsx)(tz.ChevronRight,{className:"h-3.5 w-3.5"})]}):null;return(0,t.jsxs)("article",{"aria-label":s,className:`overflow-hidden rounded-xl border bg-surface ${a?"border-accent ring-1 ring-accent/20":w?"border-border-default":"border-accent/25"}`,children:[(0,t.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-3 px-4 py-3.5 sm:px-5",children:[(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[w?(0,t.jsx)("span",{className:"flex h-8 w-8 items-center justify-center rounded-full bg-success-bg text-success",children:(0,t.jsx)(R.Check,{className:"h-4 w-4"})}):(0,t.jsx)(o.Package,{className:"h-7 w-7 text-text-secondary",strokeWidth:1.5}),(0,t.jsxs)("div",{children:[(0,t.jsx)("h4",{className:"text-sm font-semibold text-text-primary",children:s}),z&&(0,t.jsxs)("p",{className:"mt-0.5 text-xs text-text-secondary",children:["From ",z," warehouse"]})]})]}),(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-4",children:[(0,t.jsxs)("div",{className:"sm:text-right",children:[(0,t.jsxs)("p",{className:`text-sm font-semibold ${w?"text-success":N.isException?"text-error":"text-text-primary"}`,children:[V,w&&D?` ${(0,A.formatDate)(D)}`:""]}),!w&&I&&!N.isException&&(0,t.jsx)("p",{className:"mt-0.5 text-xs text-accent-dark",children:k})]}),(w||d)&&(0,t.jsxs)(t.Fragment,{children:[w&&X,(0,t.jsx)("button",{type:"button","aria-expanded":P,onClick:()=>L(e=>!e),className:"text-xs font-semibold text-accent-dark hover:underline",children:P?"Hide details":"Details"})]})]})]}),!w&&!N.isException&&(0,t.jsx)("div",{className:"px-4 pb-4 sm:px-5",children:(0,t.jsx)(tW,{stage:S})}),d&&P&&(0,t.jsx)("div",{className:"border-t border-border-default p-3 sm:p-4",children:d(e)}),(!w||P&&!d)&&(0,t.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-3 border-t border-border-default px-4 py-3 sm:px-5",children:[(0,t.jsxs)("div",{className:"text-xs text-text-secondary",children:[e.carrier&&(0,t.jsxs)("span",{children:[e.carrier," · "]}),w?D?`Delivered ${(0,A.formatDate)(D)}`:"Delivered":b||v?"Updating trackingâ¦":$?`Expected ${$}`:"Delivery date pending"]}),(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-4",children:[Q,!w&&X]})]})]})}function tG({order:e,fulfillments:n,morePending:s=!1,selectedId:a,onSelect:i,renderDetails:l}){let o=tV(),[d,c]=(0,r.useState)(!1),[u,x]=(0,r.useState)({}),m=(0,r.useCallback)((e,t)=>{x(r=>JSON.stringify(r[e])===JSON.stringify(t)?r:{...r,[e]:t})},[]);if(0===n.length)return null;let p=e=>(e.groupMembers??[e]).map(e=>e.fulfillmentId).sort((e,t)=>e.localeCompare(t,void 0,{numeric:!0}))[0],h=[...n].sort((e,t)=>(Date.parse(e.date)||0)-(Date.parse(t.date)||0)||p(e).localeCompare(p(t),void 0,{numeric:!0})),f=e=>u[e.fulfillmentId]?.delivered??(/delivered/i.test(e.upsTrackingStatus||e.status||"")||!!e.containerDelivered),g=h.flatMap(e=>u[e.fulfillmentId]?.map?[u[e.fulfillmentId].map]:[]),b=h.every(f),y=e6(h,b,s),v=h.map((e,t)=>({f:e,label:e9(t,h.length,s)})).sort((e,t)=>Number(f(e.f))-Number(f(t.f)));return(0,t.jsxs)("section",{"aria-label":"Delivery progress",className:"mb-3",children:[(0,t.jsxs)("div",{className:"mb-3 flex items-start justify-between gap-3",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("h3",{className:"text-base font-semibold text-text-primary",children:b&&!s?"Delivery complete":"Delivery progress"}),y&&(0,t.jsx)("p",{className:"mt-1 text-xs leading-relaxed text-text-secondary",children:y})]}),(0,t.jsxs)("span",{className:"shrink-0 text-xs text-text-tertiary",children:[h.length," shipment",1===h.length?"":"s",s?" so far":""]})]}),(0,t.jsx)("div",{className:"space-y-2.5",children:v.map(({f:r,label:n})=>(0,t.jsx)(tZ,{f:r,order:e,label:n,selected:a===r.fulfillmentId,onSelect:i,onReport:m,renderDetails:l},r.fulfillmentId))}),o.renderMap&&g.length>0&&(0,t.jsxs)("div",{className:"mt-3 overflow-hidden rounded-xl border border-border-default bg-surface",children:[(0,t.jsxs)("button",{type:"button","aria-expanded":d,onClick:()=>c(e=>!e),className:"flex w-full items-center justify-center gap-2 bg-accent-subtle px-4 py-3 text-xs font-semibold text-accent-dark hover:bg-accent-bg",children:[(0,t.jsx)(tH.MapPin,{className:"h-3.5 w-3.5"}),d?"Hide map":"Track live on map",(0,t.jsx)("span",{"aria-hidden":"true",children:d?"â´":"â¾"})]}),d&&(0,t.jsxs)("div",{className:"border-t border-border-default p-4",children:[(0,t.jsx)("div",{className:"mx-auto max-w-[560px]",children:o.renderMap(g)}),g.some(e=>e.lastScan)&&(0,t.jsx)("div",{className:"mt-2 space-y-1 text-center text-xs text-text-secondary",children:g.filter(e=>e.lastScan).map(e=>(0,t.jsxs)("p",{children:[e.label," · ",e.lastScan]},e.id))})]})]})]})}function tY(e){return"success"===e?"success":"warning"===e?"warning":"error"===e?"error":"default"}
1function tJ({order:e,expanded:n,detail:a,detailLoading:d,onToggle:c,highlightedInvoice:u,highlightedLine:m,moneyTrail:h,v4:f=!1,showAirBadge:y=!1,hideCustomerName:v=!1,activeItem:S=null}){let $,U,R=I(),F=T(),q=D(),{enabled:B,load:_}={enabled:($=(0,r.useContext)(C)).modernXlsxEnabled,load:$.loadModernXlsxExporter},H=P(),W=L(),K=E(),V=(0,r.useContext)(C).renderLineExtras,Q=(0,r.useContext)(C).approval,{lastSummary:X,reset:Z}=tT(),[G,Y]=(0,r.useState)(new Set),[J,ee]=(0,r.useState)({}),[et,er]=(0,r.useState)(new Set);async function en(e){if(Y(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r}),!J[e]&&!et.has(e)){er(t=>new Set(t).add(e));try{let t=await fetch(`${H}?invoiceId=${e}`),r=await t.json(),n=r.data??r;n&&n.id&&ee(t=>({...t,[e]:n}))}catch(e){console.error("[activity] invoice detail fetch failed:",e)}finally{er(t=>{let r=new Set(t);return r.delete(e),r})}}}let es=a??e,ea=es.fulfillments??e.fulfillments,el=eU(ea),eo=es.invoices??e.invoices,[ed,ec]=(0,r.useState)(null);(0,r.useEffect)(()=>{n||ec(null)},[n]);let eu=(0,r.useMemo)(()=>{if(!ed)return null;let e=el?.find(e=>e.fulfillmentId===ed);if(!e)return null;let t=new Set;for(let r of e.groupMembers??[e])for(let e of r.lines??[])e.quantity>0&&t.add(e.itemId);return t.size>0?t:null},[ed,el]),ex=(0,r.useRef)(null);(0,r.useEffect)(()=>{if(!eu)return;let e=ex.current;if(!e)return;let t=requestAnimationFrame(()=>e.scrollIntoView({behavior:"smooth",block:"nearest"}));return()=>cancelAnimationFrame(t)},[eu]);let em=(0,r.useRef)(null);(0,r.useEffect)(()=>{if(!n||null==m)return;let e=em.current;if(!e)return;let t=requestAnimationFrame(()=>e.scrollIntoView({behavior:"smooth",block:"center"}));return()=>cancelAnimationFrame(t)},[n,m,a]);let[ep,eh]=(0,r.useState)(!0);(0,r.useEffect)(()=>{if(null==m)return;eh(!0);let e=setTimeout(()=>eh(!1),2e3);return()=>clearTimeout(e)},[m]);let ef=u?.toLowerCase();(0,r.useEffect)(()=>{if(!n||null==m||!ef)return;let e=eo?.find(e=>e.invoiceNumber?.toLowerCase()===ef);e&&!G.has(e.id)&&en(e.id)},[n,m,ef,eo]);let eg=(0,r.useMemo)(()=>{let e=new Map,t=ea??[];if(0===t.length)return e;for(let r of t){let t=r.origin;if("CA"===t||"TN"===t)for(let n of r.lines??[])"number"!=typeof n.itemId||e.has(n.itemId)||e.set(n.itemId,t)}return e},[ea]),eb=(0,r.useMemo)(()=>{let e=ea??[];if(1!==e.length)return;let t=e[0].origin;return"CA"===t||"TN"===t?t:void 0},[ea]),ey=eR(el),ev=(0,A.getStatusTone)(e.status),ej=(0,A.formatPoNumber)(e.poNumber),eN=e.shippingAddress,ew=!0===e.keepBackorder,ek=ew&&(0,x.splitOrderLines)(es.lines).products.some(e=>e.quantityBackordered>0);async function eS(){if(a){if(B&&_)try{let e=await _();await e.exportOrderDetail(a);return}catch(e){console.error("[export] Modern order XLSX failed; falling back",e)}w(function(e){let t=(e.invoices??[]).map(e=>e.invoiceNumber).join(", "),r=[...new Set((e.fulfillments??[]).map(e=>e.origin).filter(Boolean))],n=(e.fulfillments??[]).flatMap(e=>e.trackingNumbers.filter(e=>e.length>=5)),s=e.lines??[],a=s.filter(e=>!j(e)),i=s.filter(e=>j(e)),l=a.reduce((e,t)=>e+(t.amount||0),0),o=`<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel"> 2<head><meta charset="utf-8"> 3<style> 4 td, th { font-family: Calibri, Arial, sans-serif; font-size: 11pt; } 5 th { background: #1e3a5f; color: white; font-weight: bold; padding: 6px 10px; } 6 td { padding: 4px 10px; border-bottom: 1px solid #e2e8f0; } 7 .header-row td { font-weight: bold; background: #f1f5f9; } 8 .subtotal-row td { font-weight: bold; background: #f8fafc; border-top: 1px solid #94a3b8; } 9 .total-row td { font-weight: bold; background: #e2e8f0; border-top: 2px solid #1e3a5f; } 10 .num { mso-number-format:"\\#\\,\\#\\#0\\.00"; text-align: right; } 11 .qty { text-align: center; } 12</style> 13</head><body> 14<table> 15 <tr class="header-row"><td colspan="8">Order ${e.orderNumber}</td></tr> 16 <tr><td>Date:</td><td colspan="3">${e.date}</td><td>PO #:</td><td colspan="3">${e.poNumber||"N/A"}</td></tr> 17 <tr><td>Status:</td><td colspan="3">${e.status}</td><td>Ship Method:</td><td colspan="3">${e.shipMethod||"N/A"}</td></tr> 18 <tr><td>Terms:</td><td colspan="3">${e.terms||"N/A"}</td><td>Invoice(s):</td><td colspan="3">${t||"N/A"}</td></tr> 19 <tr><td>Origin:</td><td colspan="3">
19${r.join(", ")||"N/A"}</td><td>Tracking:</td><td colspan="3">${n.join(", ")||"N/A"}</td></tr> 20 ${e.customerName?`<tr><td>Customer:</td><td colspan="3">${e.customerName}</td><td>Bill To:</td><td colspan="3">${e.customerName}</td></tr>`:""} 21 <tr><td style="vertical-align:top">Ship To:</td><td colspan="7">${function(e){if(!e)return"N/A";let t=[[e.city,e.state].filter(Boolean).join(", "),e.zip||""].filter(e=>e&&e.trim()).join(" "),r=[e.attention||"",e.company||"",e.addr1||"",e.addr2||"",t,e.country&&"US"!==e.country?e.country:"",e.phone||""].filter(e=>e&&e.trim());return r.length?r.join("<br>"):"N/A"}(e.shippingAddress)}</td></tr> 22 <tr><td colspan="8"></td></tr> 23 <tr> 24 <th>Product</th><th>SKU</th><th>UPC</th><th>Ordered</th><th>Shipped</th><th>Backordered</th><th>Rate</th><th>Total</th> 25 </tr>`;for(let e of a)o+=`<tr> 26 <td>${N(e)}</td> 27 <td>${e.externalId||""}</td> 28 <td>${e.upc||""}</td> 29 <td class="qty">${g(e.quantity)}</td> 30 <td class="qty">${g(e.quantityShipped)}</td> 31 <td class="qty">${g(e.quantityBackordered)}</td> 32 <td class="num">${e.rate.toFixed(2)}</td> 33 <td class="num">${e.amount.toFixed(2)}</td> 34 </tr>`;for(let e of(o+=`<tr class="subtotal-row"> 35 <td colspan="7" style="text-align:right">Subtotal</td> 36 <td class="num">${l.toFixed(2)}</td> 37 </tr>`,i)){let t=(0,x.summaryChargeLabel)(e,N(e)||e.itemType||"Charge");o+=`<tr> 38 <td colspan="7" style="text-align:right">${t}</td> 39 <td class="num">${e.amount.toFixed(2)}</td> 40 </tr>`}return o+`<tr class="total-row"> 41 <td colspan="7" style="text-align:right">Order Total</td> 42 <td class="num">${e.total.toFixed(2)}</td> 43 </tr></table></body></html>`}(a),`${e.orderNumber}.xls`)}}async function eC(){window.open(`${H}?action=pdf&transactionId=${e.id}&recordType=salesorder`,"_blank","noopener,noreferrer")}async function e$(e){let t=J[e]??null;if(t)return t;er(t=>new Set(t).add(e));try{let r=await fetch(`${H}?invoiceId=${e}`),n=await r.json(),s=n.data??n;s&&s.id&&(t=s,ee(t=>({...t,[e]:s})))}catch(e){console.error("[activity] invoice fetch failed:",e)}finally{er(t=>{let r=new Set(t);return r.delete(e),r})}return t}async function eI(t){let r=await e$(t);if(!r)return;let n=a??e;if(B&&_)try{let e=await _();await e.exportInvoiceDetail(r,n);return}catch(e){console.error("[export] Modern invoice XLSX failed; falling back",e)}w(function(e,t){let r=e.salesOrderNumber||t?.orderNumber||"",n=t?.shipMethod||"",s=[];if(e.lines&&e.lines.length>0){let t=new Set;for(let r of e.lines){let e=String(r.trackingNumber||"").trim();if(!e||t.has(e))continue;t.add(e);let n=p(e)[0];n&&s.push(n)}}if(0===s.length&&t?.fulfillments)for(let e of t.fulfillments){let t=(e.trackingNumbers||[]).find(e=>e.length>=5);t&&!s.includes(t)&&s.push(t)}let a=e.lines??[],i=a.filter(e=>!j(e)),l=a.filter(e=>j(e)),o=i.reduce((e,t)=>e+(t.amount||0),0),d=`<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel"> 44<head><meta charset="utf-8"> 45<style> 46 td, th { font-family: Calibri, Arial, sans-serif; font-size: 11pt; } 47 th { background: #1e3a5f; color: white; font-weight: bold; padding: 6px 10px; } 48 td { padding: 4px 10px; border-bottom: 1px solid #e2e8f0; } 49 .header-row td { font-weight: bold; background: #f1f5f9; } 50 .subtotal-row td { font-weight: bold; background: #f8fafc; border-top: 1px solid #94a3b8; } 51 .total-row td { font-weight: bold; background: #e2e8f0; border-top: 2px solid #1e3a5f; } 52 .num { mso-number-format:"\\#\\,\\#\\#0\\.00"; text-align: right; } 53 .qty { text-align: center; } 54</style> 55</head><body> 56<table> 57 <tr class="header-row"><td colspan="6">Invoice ${e.invoiceNumber}</td></tr> 58 <tr><td>Date:</td><td colspan="2">${e.date}</td><td>Due:</td><td colspan="2">${e.dueDate||"N/A"}</td></tr> 59 <tr><td>Status:</td><td colspan="2">${e.status}</td><td>Terms:</td><td colspan="2">${e.terms||"N/A"}</td></tr> 60 <tr><td>PO #:</td><td colspan="2">${e.poNumber||"N/A"}</td><td>SO #:</td><td colspan="2">${r||"N/A"}</td></tr> 61 <tr><td>Ship Method:</td><td colspan="2">${n||"N/A"}</td><td>Tracking:</td><td colspan="2">
61${s.join(", ")||"N/A"}</td></tr> 62 <tr><td colspan="6"></td></tr> 63 <tr> 64 <th>Product</th><th>SKU</th><th>UPC</th><th>Qty</th><th>Rate</th><th>Total</th> 65 </tr>`;for(let e of i)d+=`<tr> 66 <td>${N(e)}</td> 67 <td>${e.externalId||""}</td> 68 <td>${e.upc||""}</td> 69 <td class="qty">${g(e.quantity)}</td> 70 <td class="num">${e.rate.toFixed(2)}</td> 71 <td class="num">${e.amount.toFixed(2)}</td> 72 </tr>`;for(let e of(d+=`<tr class="subtotal-row"> 73 <td colspan="5" style="text-align:right">Subtotal</td> 74 <td class="num">${o.toFixed(2)}</td> 75 </tr>`,l)){let t=(0,x.summaryChargeLabel)(e,N(e)||"Charge");d+=`<tr> 76 <td colspan="5" style="text-align:right">${t}</td> 77 <td class="num">${e.amount.toFixed(2)}</td> 78 </tr>`}return d+`<tr class="total-row"> 79 <td colspan="5" style="text-align:right">Invoice Total</td> 80 <td class="num">${e.total.toFixed(2)}</td> 81 </tr></table></body></html>`}(r,n),`${r.invoiceNumber}.xls`)}async function eD(e){window.open(`${H}?action=pdf&invoiceId=${e}`,"_blank","noopener,noreferrer")}async function eT(e){window.open(`${H}?action=pdf&invoiceId=${e}&template=packing`,"_blank","noopener,noreferrer")}let eP="success"===ev?"bg-success-bg text-success":"warning"===ev?"bg-warning-bg text-warning":"error"===ev?"bg-error-bg text-error":"bg-surface-elevated text-text-secondary";return(0,t.jsxs)("section",{className:f?"overflow-hidden rounded-2xl border border-border-default bg-surface transition-shadow data-[expanded=true]:shadow-sm":"rounded-xl border border-border-default bg-surface transition-shadow data-[expanded=true]:shadow-sm","data-expanded":n,children:[f?(0,t.jsxs)("button",{type:"button",onClick:c,"aria-expanded":n,"aria-controls":`order-detail-${e.id}`,className:"flex w-full flex-wrap items-center gap-[18px] px-[22px] py-[18px] text-left transition-colors hover:bg-surface-elevated/30 focus:outline-none focus-visible:ring-2 focus-visible:ring-accent",children:[(0,t.jsxs)("span",{className:"min-w-[220px] flex-[1.5] basis-[240px]",children:[(0,t.jsxs)("span",{className:"flex flex-wrap items-center gap-2.5",children:[(0,t.jsx)("span",{className:"text-base font-extrabold tracking-[-0.01em] text-text-primary",children:e.orderNumber}),(0,t.jsx)(z,{value:e.orderNumber,label:"SO number",size:"md"}),(0,t.jsx)("span",{className:`inline-flex items-center gap-[5px] whitespace-nowrap rounded-full px-2.5 py-[3px] text-[11px] font-semibold ${eP}`,children:eV(e.status)})]}),e.customerName&&!v&&(0,t.jsxs)("span",{className:"mt-0.5 block truncate text-xs font-medium text-text-secondary",children:[e.customerName,e.customerEmail&&(0,t.jsx)("span",{className:"ml-1.5 font-normal text-text-tertiary",children:e.customerEmail})]}),(0,t.jsxs)("span",{className:"mt-[5px] block text-xs text-text-tertiary",children:[(0,A.formatDate)(e.date),"â"!==ej&&(0,t.jsxs)(t.Fragment,{children:[" · ",(0,t.jsxs)("span",{className:"font-mono text-[11px]",children:["PO ",ej]})]})]}),eN&&(eN.city||eN.state)&&(0,t.jsx)("span",{className:"mt-1 block text-[11.5px] text-text-secondary",children:(0,t.jsx)(ta,{shipTo:eN,variant:"v4"})}),h&&(h.paid>0||h.refunded>0||h.balance>0)&&(0,t.jsxs)("span",{className:"mt-[5px] flex flex-wrap items-center gap-x-2 gap-y-0.5 text-[11.5px]",children:[h.paid>0&&(0,t.jsxs)("span",{className:"inline-flex items-center gap-1.5 text-text-secondary",children:[(0,t.jsx)("span",{className:"h-1.5 w-1.5 rounded-full bg-success"}),"Paid ",(0,A.formatCurrency)(h.paid)]}),h.refunded>0&&(0,t.jsxs)("span",{className:"inline-flex items-center gap-1.5 text-success",children:[(0,t.jsx)("span",{className:"h-1.5 w-1.5 rounded-full bg-success"}),"Refunded ",(0,A.formatCurrency)(h.refunded)]}),h.balance>0&&(0,t.jsxs)("span",{className:"inline-flex items-center gap-1.5 font-medium text-warning",children:[(0,t.jsx)("span",{className:"h-1.5 w-1.5 rounded-full bg-warning"}),(0,A.formatCurrency)(h.balance)," owed"]})]})]}),(0,t.jsxs)("span",{className:"min-w-[130px] flex-1 text-[12.5px] text-text-secondary",children:[e.lineCount>0&&(0,t.jsxs)("span",{children:[e.lineCount," item",1!==e.lineCount?"s":""]}),el&&el.length>0&&(0,t.jsx)(tf,{v4:!0,fulfillments:el,orderCompleted:["SalesOrd:G","SalesOrd:H"].includes(e.statusRef),morePending:["SalesOrd:D","SalesOrd:E"].includes(e.statusRef)})]}),(0,t.jsxs)("span",{className:"flex min-w-[120px] flex-1 flex-wrap items-center gap-1.5",children:[eo&&eo.length>0?eo.slice(0,2).map(e=>{let r=q&&(e.amountRemaining??0)>0,n="inline-flex items-center rounded-md bg-surface-elevated px-2 py-1 font-mono text-[10px] font-semibold text-text-secondary";if(!r)return(0,t.jsx)("span",{className:n,children:e.invoiceNumber},e.id);let s=()=>{F&&F([String(e.id)])};return(0,t.jsx)("span",{role:"link",tabIndex:0,title:`Pay ${e.invoiceNumber}`,onClick:e=>{e.stopPropagation(),s()},onKeyDown:e=>
81{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),e.stopPropagation(),s())},className:`${n} cursor-pointer transition-colors hover:bg-accent/10 hover:text-accent focus:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:e.invoiceNumber},e.id)}):(0,t.jsx)("span",{className:"text-xs text-text-muted",children:"No invoice"}),eo&&eo.length>2&&(0,t.jsxs)("span",{className:"text-[10px] text-text-muted",children:["+",eo.length-2]})]}),(0,t.jsxs)("span",{className:"flex items-center gap-3",children:[(0,t.jsx)("span",{className:"whitespace-nowrap text-base font-extrabold tabular-nums text-text-primary",children:(0,A.formatCurrency)(e.total)}),(()=>{let r=q&&e.invoices?e.invoices.filter(e=>(e.amountRemaining??0)>0):[];if(0===r.length)return null;let n=()=>{F&&F(r.map(e=>String(e.id)))};return(0,t.jsx)("span",{role:"link",tabIndex:0,title:1===r.length?`Pay ${r[0].invoiceNumber}`:`Pay ${r.length} open invoices on this order`,onClick:e=>{e.stopPropagation(),n()},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),e.stopPropagation(),n())},className:"inline-flex items-center gap-1 rounded-lg bg-accent px-3 py-1.5 text-xs font-semibold text-accent-foreground transition-colors hover:bg-accent/90 focus:outline-none focus-visible:ring-2 focus-visible:ring-accent",children:"Pay"})})(),(0,t.jsx)(tA,{order:e}),(0,t.jsx)("span",{"aria-hidden":"true",className:`text-[11px] text-text-tertiary transition-transform duration-200 ${n?"rotate-180":""}`,children:"â¾"})]})]}):(0,t.jsx)("button",{type:"button",onClick:c,"aria-expanded":n,"aria-controls":`order-detail-${e.id}`,className:"flex w-full items-center gap-4 px-5 py-4 text-left transition-colors hover:bg-surface-elevated/40 focus:outline-none focus-visible:ring-2 focus-visible:ring-accent",children:(0,t.jsxs)("div",{className:"min-w-0 flex-1 grid grid-cols-1 gap-2 sm:grid-cols-[minmax(0,1.2fr)_minmax(0,0.8fr)_minmax(0,1fr)_auto] sm:items-center",children:[(0,t.jsxs)("div",{className:"min-w-0",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("span",{className:"font-medium text-text-primary",children:e.orderNumber}),(0,t.jsx)(z,{value:e.orderNumber,label:"SO number",size:"md"}),(0,t.jsx)(tn.default,{variant:tY(ev),children:eV(e.status)}),y&&(e.airPendingUnits??e.airUnits??0)>0?(0,t.jsxs)("span",{className:"inline-flex items-center gap-1 whitespace-nowrap rounded-full bg-warning-bg px-2 py-0.5 text-[10px] font-semibold text-warning",title:"Air freight units still to ship",children:["â Air ·"," ",(0,t.jsx)("span",{className:"font-mono tabular-nums",children:(e.airPendingUnits??e.airUnits).toLocaleString("en-US")})]}):null]}),e.customerName&&!v&&(0,t.jsxs)("p",{className:"mt-0.5 truncate text-xs font-medium text-text-secondary",children:[e.customerName,e.customerEmail&&(0,t.jsx)("span",{className:"ml-1.5 font-normal text-text-tertiary",children:e.customerEmail})]}),(0,t.jsxs)("p",{className:"mt-0.5 truncate text-xs text-text-tertiary",children:[(0,A.formatDate)(e.date),"â"!==ej&&(0,t.jsxs)(t.Fragment,{children:[" · ","PO ",(0,t.jsx)("span",{className:"font-mono",children:ej}),e.poSplitCount&&e.poSplitCount>=2?(0,t.jsxs)("span",{className:"ml-1.5 inline-flex items-center gap-0.5 rounded border border-warning/40 bg-warning-bg/50 px-1 py-px align-middle text-[9px] font-bold uppercase tracking-wide text-warning-foreground",title:`This customer PO is split across ${e.poSplitCount} orders.`,children:["â Split · ",e.poSplitCount]}):null]})]}),eN&&(eN.city||eN.state)&&(0,t.jsx)("p",{className:"mt-0.5 text-xs text-text-tertiary",children:(0,t.jsx)(ta,{shipTo:eN,variant:"classic"})}),h&&(h.paid>0||h.refunded>0||h.balance>0)&&(0,t.jsxs)("p",{className:"mt-1 flex flex-wrap items-center gap-x-2 gap-y-0.5 text-[11px]",children:[h.paid>0&&(0,t.jsxs)("span",{className:"inline-flex items-center gap-1 text-text-secondary",children:[(0,t.jsx)("span",{className:"h-1.5 w-1.5 rounded-full bg-success"}),"Paid ",(0,A.formatCurrency)(h.paid)]}),h.refunded>0&&(0,t.jsxs)("span",{className:"inline-flex items-center gap-1 text-success",children:[(0,t.jsx)("span",{className:"h-1.5 w-1.5 rounded-full bg-success"}),"Refunded ",(0,A.formatCurrency)(h.refunded)]}),h.balance>0&&(0,t.jsxs)("span",{className:"inline-flex items-center gap-1 font-medium text-warning",children:[(0,t.jsx)("span",{className:"h-1.5 w-1.5 rounded-full bg-warning"}),(0,A.formatCurrency)(h.balance)," owed"]})]})]}),(0,t.jsxs)("div",{className:"min-w-0 text-xs text-text-secondary",children:[e.lineCount>0&&(0,t.jsxs)("span",{children:[e.lineCount," item",1!==e.lineCount?"s":""]}),el&&el.length>0&&(0,t.jsx)(t.Fragment,{children:(0,t.jsx)(tf,{v4:!0,fulfillments:el,orderCompleted:["SalesOrd:G","SalesOrd:H"].includes(e.statusRef),morePending:["SalesOrd:D","SalesOrd:E"].includes(e.statusRef)})})]}),(0,t.jsxs)("div",{className:"flex min-w-0 flex-wrap items-center gap-1",children:[eo&&eo.length>0?eo.slice(0,2).map(e=>{let r=q&&(e.amountRemaining??0)>0,n="inline-flex items-center rounded bg-surface-elevated px-1.5 py-0.5 font-mono text-[10px] text-text-secondary";if(!r)return(0,t.jsx)("span",{className:n,children:e.invoiceNumber},e.id);let s=()=>{F&&F([String(e.id)])};return(0,t.jsx)("span",{role:"link",tabIndex:0,title:`Pay ${e.invoiceNumber}`,onClick:e=>{e.stopPropagation(),s()},onKeyDown:e=>
81{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),e.stopPropagation(),s())},className:`${n} cursor-pointer transition-colors hover:bg-accent/10 hover:text-accent focus:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:e.invoiceNumber},e.id)}):(0,t.jsx)("span",{className:"text-xs text-text-muted",children:"No invoice"}),eo&&eo.length>2&&(0,t.jsxs)("span",{className:"text-[10px] text-text-muted",children:["+",eo.length-2]})]}),(0,t.jsxs)("div",{className:"flex items-center justify-end gap-3",children:[(0,t.jsx)("span",{className:"whitespace-nowrap text-sm font-semibold tabular-nums text-text-primary",children:(0,A.formatCurrency)(e.total)}),(()=>{let r=q&&e.invoices?e.invoices.filter(e=>(e.amountRemaining??0)>0):[];if(0===r.length)return null;let n=()=>{F&&F(r.map(e=>String(e.id)))};return(0,t.jsx)("span",{role:"link",tabIndex:0,title:1===r.length?`Pay ${r[0].invoiceNumber}`:`Pay ${r.length} open invoices on this order`,onClick:e=>{e.stopPropagation(),n()},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),e.stopPropagation(),n())},className:"inline-flex items-center gap-1 rounded-md bg-accent px-2.5 py-1 text-[11px] font-semibold text-accent-foreground transition-colors hover:bg-accent/90 focus:outline-none focus-visible:ring-2 focus-visible:ring-accent",children:"Pay"})})(),(0,t.jsx)(tA,{order:e}),n?(0,t.jsx)(i,{className:"h-4 w-4 text-text-tertiary"}):(0,t.jsx)(s.ChevronDown,{className:"h-4 w-4 text-text-tertiary"})]})]})}),(0,t.jsx)(t$,{order:e,api:Q}),n&&(0,t.jsxs)("div",{id:`order-detail-${e.id}`,className:f?"border-t border-border-subtle bg-background px-[22px] pb-[22px] pt-[18px]":"border-t border-border-subtle px-5 pb-5 pt-4",children:[(0,t.jsxs)("div",{className:"mb-4 flex items-center justify-between",children:[(0,t.jsx)("p",{className:"text-[10px] font-semibold uppercase tracking-wider text-text-tertiary",children:"Order details"}),(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[(0,t.jsxs)("button",{type:"button",onClick:eC,title:"Download Sales Order PDF",className:"inline-flex items-center gap-1 text-[10px] font-medium text-text-tertiary transition-colors hover:text-accent",children:[(0,t.jsx)(l.Download,{className:"h-3 w-3"}),"PDF"]}),(0,t.jsxs)("button",{type:"button",onClick:function(){a&&k(function(e){let t=[],r=(e.invoices??[]).map(e=>e.invoiceNumber).join("; "),n=[],s=[];for(let t of e.fulfillments??[]){for(let e of t.trackingNumbers)n.push(e);t.origin&&!s.includes(t.origin)&&s.push(t.origin)}let{products:a,summary:i}=(0,x.splitOrderLines)(e.lines);for(let i of a)t.push([b(e.orderNumber),b(e.date),b(e.poNumber),b(e.status),b(e.shipMethod),b(N(i)),b(i.externalId||""),b(i.upc||""),String(g(i.quantity)),String(g(i.quantityShipped)),String(g(i.quantityBackordered)),i.rate.toFixed(2),i.amount.toFixed(2),b(r),b(n.join("; ")),b(s.join(", "))]);for(let n of i)t.push([b(e.orderNumber),b(e.date),b(e.poNumber),b(e.status),b(e.shipMethod),b((0,x.summaryChargeLabel)(n,n.description||n.itemName||"Summary charge")),"","","","","",n.rate.toFixed(2),n.amount.toFixed(2),b(r),"",""]);let l=function(e){if(!e)return"";let t=[[e.city,e.state].filter(Boolean).join(", "),e.zip||""].filter(e=>e&&e.trim()).join(" ");return[e.attention||e.company||"",e.addr1||"",e.addr2||"",t,e.country&&"US"!==e.country?e.country:""].filter(e=>e&&e.trim()).join(", ")}(e.shippingAddress),o=[];e.customerName&&o.push(`${b("Customer")},${b(e.customerName)}`),l&&o.push(`${b("Ship To")},${b(l)}`),e.customerName&&o.push(`${b("Bill To")},${b(e.customerName)}`);let d=["Order #,Order Date,PO #,Status,Ship Method,Product,SKU,UPC,Qty Ordered,Qty Shipped,Backordered,Unit Price,Line Total,Invoice(s),Tracking,Origin",...t.map(e=>e.join(","))];return(o.length?[...o,"",...d]:d).join("\n")}(a),`${e.orderNumber}.csv`)},disabled:!a?.lines||0===a.lines.length,title:a?.lines&&a.lines.length>0?"Download Sales Order line items as CSV":"Line items still loadingâ¦",className:"inline-flex items-center gap-1 text-[10px] font-medium text-text-tertiary transition-colors hover:text-accent disabled:cursor-not-allowed disabled:opacity-40",children:[(0,t.jsx)(te.FileText,{className:"h-3 w-3"}),"CSV"]}),(0,t.jsxs)("button",{type:"button",onClick:eS,disabled:!a?.lines||0===a.lines.length,title:a?.lines&&a.lines.length>0?"Download Sales Order as Excel":"Line items still loadingâ¦",className:"inline-flex items-center gap-1 text-[10px] font-medium text-text-tertiary transition-colors hover:text-accent disabled:cursor-not-allowed disabled:opacity-40",children:[(0,t.jsx)(O,{className:"h-3 w-3"}),"Excel"]})]})]}),ek&&(0,t.jsx)("div",{className:"mb-4 rounded-lg border border-warning/20 bg-warning-bg px-4 py-2 text-xs text-warning",children:"Some items on this order are backordered."}),el&&el.length>0&&(0,t.jsx)("div",{className:"mb-4",children:(0,t.jsx)(tG,{order:es,fulfillments:el,morePending:["SalesOrd:D","SalesOrd:E"].includes(e.statusRef),selectedId:ed,onSelect:e=>ec(t=>t===e?null:e),orderCompleted:["SalesOrd:G","SalesOrd:H"].includes(e.statusRef),renderDetails:f?void 0:r=>(0,t.jsx)(tp,{fulfillments:[r],invoices:e.invoices,activeItem:S,orderCompleted:["SalesOrd:G","SalesOrd:H"].includes(e.statusRef)})})}),(()=>{let r,n,{lines:s,skeleton:i}=(r=a?.lines??e.lines,n=d&&!a&&!(r&&r.length>0),{lines:r,skeleton:n}),l=(0,x.splitOrderLines)(s);if(i)return(0,t.jsxs)("div",{className:"mb-4 space-y-2",children:[(0,t.jsx)(ts.default,{className:"h-3 w-40"}),(0,t.jsx)(ts.default,{className:"h-10 w-full"}),(0,t.jsx)(ts.default,{className:"h-10 w-full"}),(0,t.jsx)(ts.default,{className:"h-10 w-full"})]});if(!s||0===l.products.length)return null;let o=eu?l.products.findIndex(e=>eu.has(e.itemId)):-1;return(0,t.jsx)("div",{className:"mb-4 overflow-hidden rounded-lg border border-border-subtle",children:(0,t.jsxs)("table",{className:"w-full text-xs",children:[(0,t.jsx)("thead",{children:(0,t.jsxs)("tr",{className:"border-b border-border-subtle bg-surface-elevated/40 text-left text-text-tertiary",children:[(0,t.jsx)("th",{className:"hidden px-3 py-2 font-medium sm:table-cell",children:"SKU"}),(0,t.jsx)("th",{className:"px-3 py-2 font-medium",children:"Product"}),(0,t.jsx)("th",{className:"hidden px-3 py-2 font-medium md:table-cell",children:"UPC"}),(0,t.jsx)("th",{className:"px-3 py-2 text-center font-medium",children:"Qty"}),(0,t.jsx)("th",{className:"px-3 py-2 text-center font-medium",children:"Shipped"}),(0,t.jsx)("th",{className:"hidden px-3 py-2 text-right font-medium sm:table-cell",children:"Price"}),(0,t.jsx)("th",{className:"px-3 py-2 text-right font-medium",children:"Total"}),(0,t.jsx)("th",{className:"hidden px-3 py-2 text-right font-medium sm:table-cell","aria-label":"Add to cart"})]})}),(0,t.jsx)("tbody",{children:l.products.map((e,r)=>{let n=`${e.itemId}-${r}`,s=eB(e.itemId,ea),a=e4(m,e.itemId,ep),i=eu?.has(e.itemId)??!1,l=null!=eu&&!i;return(0,t.jsxs)("tr",{ref:a?em:i&&r===o?ex:void 0,className:`border-b border-border-subtle/50 transition-all ${a||i?"bg-accent-bg":""} ${l?"opacity-40":""}`,children:[(0,t.jsxs)("td",{className:"hidden px-3 py-2 font-mono text-[10px] text-text-secondary sm:table-cell",children:[e.externalId||"â",e.scpItemNo&&(0,t.jsxs)("div",{className:"mt-0.5 text-[10px] font-semibold",style:{color:"#7c3aed"},children:["BPN: ",e.scpItemNo]})]}),(0,t.jsxs)("td",{className:"px-3 py-2 text-text-primary",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)(M,{isDropShip:e.isDropShip,fallbackOrigin:eg.get(e.itemId)??eb}),e.description||eK(e.itemName)||"â",s.length>0&&(0,t.jsx)("span",{className:"ml-1.5",children:(0,t.jsx)(ei,{shipments:s.map(t=>({ref:t.fulfillmentId,qty:t.shippedQty,cartons:t.cartons,cartonsApprox:t.cartonsApprox,trackingNumbers:t.trackingNumbers,carrier:t.carrier,status:t.status,origin:t.origin,date:t.date,deliveryDate:t.deliveryDate,containerRef:t.containerRef,containerTracking:t.containerTracking,containerEta:t.containerEta,containerDelivered:t.containerDelivered,containerArrived:t.containerArrived,inboundShipmentId:t.inboundShipmentId,mode:t.inbou
81ndMode,sku:e.externalId}))})}),(e.airPendingQty??0)>0&&!e.airStatus?(0,t.jsxs)("span",{className:"ml-1.5 inline-flex items-center gap-1 whitespace-nowrap rounded-full bg-warning-bg px-1.5 py-px align-middle text-[10px] font-semibold text-warning",title:`${e.airPendingQty.toLocaleString("en-US")} units still to air-ship${e.expectedShipDate?` \xb7 ESD ${(0,A.formatDate)(e.expectedShipDate)}`:""}`,children:["â Air ·"," ",(0,t.jsx)("span",{className:"font-mono tabular-nums",children:e.airPendingQty.toLocaleString("en-US")})]}):null,(e.airShippedQty??0)>0&&!e.airStatus?(0,t.jsxs)("span",{className:"ml-1.5 inline-flex items-center gap-1 whitespace-nowrap rounded-full bg-success-bg px-1.5 py-px align-middle text-[10px] font-semibold text-success",title:`${e.airShippedQty.toLocaleString("en-US")} units of this line already shipped by air`,children:["â"," ",(0,t.jsx)("span",{className:"font-mono tabular-nums",children:e.airShippedQty.toLocaleString("en-US")})," ","air shipped"]}):null,(e.oceanBalanceQty??0)>0?(0,t.jsxs)("span",{className:"ml-1.5 inline-flex items-center gap-1 whitespace-nowrap rounded-full bg-info-bg px-1.5 py-px align-middle text-[10px] font-semibold text-info",title:`${e.oceanBalanceQty.toLocaleString("en-US")} units open, not flagged for air${e.expectedShipDate?` \xb7 ESD ${(0,A.formatDate)(e.expectedShipDate)}`:" · no ESD set"}`,children:["Ocean ·"," ",(0,t.jsx)("span",{className:"font-mono tabular-nums",children:e.oceanBalanceQty.toLocaleString("en-US")})]}):null]}),(0,t.jsxs)("div",{className:"mt-0.5 flex flex-wrap items-center gap-x-2 font-mono text-[10px] text-text-tertiary sm:hidden",children:[e.externalId&&(0,t.jsx)("span",{children:e.externalId}),e.scpItemNo&&(0,t.jsxs)("span",{className:"font-semibold",style:{color:"#7c3aed"},children:["BPN ",e.scpItemNo]}),e.upc&&(0,t.jsxs)("span",{children:["UPC ",e.upc]})]}),(0,t.jsxs)("div",{className:"mt-0.5 text-[10px] text-text-tertiary tabular-nums sm:hidden",children:[(0,A.formatCurrency)(e.rate)," each"]}),V?V(e):null,(0,t.jsx)("div",{className:"mt-1.5 sm:hidden",children:(0,t.jsx)(tL,{item:{itemId:e.itemId,quantity:Math.abs(e.quantity),externalId:e.externalId,itemName:e.itemName,description:e.description,rate:e.rate}})})]}),(0,t.jsx)("td",{className:"hidden px-3 py-2 font-mono text-[10px] text-text-secondary md:table-cell",children:e.upc||"â"}),(0,t.jsx)("td",{className:"px-3 py-2 text-center text-text-secondary",children:Math.abs(e.quantity)}),(0,t.jsxs)("td",{className:"px-3 py-2 text-center text-text-secondary",children:[Math.abs(e.quantityShipped),ew&&e.quantityBackordered>0&&(0,t.jsxs)("span",{className:"ml-1 text-warning",children:["(+",e.quantityBackordered," BO)"]})]}),(0,t.jsx)("td",{className:"hidden px-3 py-2 text-right text-text-secondary tabular-nums sm:table-cell",children:(0,A.formatCurrency)(e.rate)}),(0,t.jsx)("td",{className:"px-3 py-2 text-right font-medium tabular-nums",children:(0,A.formatCurrency)(e.amount)}),(0,t.jsx)("td",{className:"hidden px-3 py-2 text-right sm:table-cell",children:(0,t.jsx)(tL,{item:{itemId:e.itemId,quantity:Math.abs(e.quantity),externalId:e.externalId,itemName:e.itemName,description:e.description,rate:e.rate}})})]},n)})}),(0,t.jsxs)("tfoot",{className:"bg-surface-elevated/40 text-text-secondary",children:[(0,t.jsxs)("tr",{className:"border-t border-border-subtle",children:[(0,t.jsx)("td",{colSpan:6,className:"px-3 py-2 text-right text-text-tertiary",children:"Subtotal"}),(0,t.jsx)("td",{className:"px-3 py-2 text-right font-medium tabular-nums",children:(0,A.formatCurrency)(l.productSubtotal)}),(0,t.jsx)("td",{})]}),l.summary.map((e,r)=>(0,t.jsxs)("tr",{children:[(0,t.jsx)("td",{colSpan:6,className:"px-3 py-1.5 text-right text-text-tertiary",children:(0,x.summaryChargeLabel)(e,(0,tI.cleanShipLabel)(e.description||eK(e.itemName)||e.itemType||"Charge"))}),(0,t.jsx)("td",{className:`px-3 py-1.5 text-right tabular-nums ${e.amount<0?"text-success":"text-text-secondary"}`,children:(0,A.formatCurrency)(e.amount)}),(0,t.jsx)("td",{})]},`summary-${e.itemId}-${r}`)),(0,t.jsxs)("tr",{className:"border-t border-border-default",children:[(0,t.jsx)("td",{colSpan:6,className:"px-3 py-2 text-right text-[10px] font-semibold uppercase tracking-wider text-text-tertiary",children:"Order Total"}),(0,t.jsx)("td",{className:"px-3 py-2 text-right font-bold tabular-nums text-text-primary",children:(0,A.formatCurrency)(e.total)}),(0,t.jsx)("td",{})]})]})]})})})(),e.invoices&&e.invoices.length>0&&(0,t.jsxs)("div",{className:"mb-4",children:[(0,t.jsx)("p",{className:f?"mb-2.5 font-mono text-[9.5px] font-bold uppercase tracking-[0.12em] text-text-tertiary":"mb-2 text-[10px] font-semibold uppercase tracking-wider text-text-tertiary",children:"Invoices"}),(0,t.jsx)("div",{className:"divide-y divide-border-subtle rounded-lg border border-border-subtle",children:e.invoices.map(e=>{let r=u&&u.toLowerCase()===e.invoiceNumber?.toLowerCase(),n=G.has(e.id),a=et.has(e.id),d=J[e.id];return(0,t.jsxs)("div",{className:r?"bg-accent-bg":"",children:[(0,t.jsxs)("div",{onClick:()=>en(e.id),role:"button",tabIndex:0,onKeyDown:t=>{("Enter"===t.key||" "===t.key)&&(t.preventDefault(),en(e.id))},"aria-expanded":n,className:"flex cursor-pointer items-center justify-between gap-3 px-3 py-2 text-xs transition-colors hover:bg-surface-elevated/40",children:[(0,t.jsxs)("div",{className:"flex min-w-0 flex-1 flex-wrap items-center gap-x-2 gap-y-1",children:[n?(0,t.jsx)(i,{className:"h-3 w-3 shrink-0 text-text-tertiary"}):(0,t.jsx)(s.ChevronDown,{className:"h-3 w-3 shrink-0 text-text-tertiary"}),(0,t.jsx)("span",{className:"font-mono font-medium text-text-primary",children:e.invoiceNumber}),e.origin&&(0,t.jsx)("span",{className:"rounded bg-surface-elevated px-1 py-0.5 text-[9px] font-bold text-text-tertiary",children:e.origin}),e.date&&(0,t.jsx)("span",{className:"hidden text-text-muted sm:inline",children:(0,A.formatDate)(e.date)})]}),(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[null!=e.total&&(0,t.jsx)("span",{className:"font-medium tabular-nums text-text-primary",children:(0,A.formatCurrency)(e.total)}),e.status&&(0,t.jsx)(tn.default,{variant:tY((0,A.getStatusTone)(e.status)),children:e.status}),(0,t.jsx)("button",{type:"button",title:"Download Invoice PDF",onClick:t=>{t.stopPropagation(),eD(e.id)},className:"inline-flex h-6 w-6 items-center justify-center rounded text-text-tertiary hover:bg-surface-elevated hover:text-accent",children:(0,t.jsx)(l.Download,{className:"h-3 w-3"})}),(0,t.jsx)("button",{type:"button",title:"Download Packing List PDF",onClick:t=>{t.stopPropagation(),eT(e.id)},className:"inline-flex h-6 w-6 items-center justify-center rounded text-text-tertiary hover:bg-surface-elevated hover:text-accent",children:(0,t.jsx)(o.Package,{className:"h-3 w-3"})}),(0,t.jsx)("button",{type:"button",title:"Download Invoice as Excel",onClick:t=>{t.stopPropagation(),eI(e.id)},className:"inline-flex h-6 w-6 items-center justify-center rounded text-text-tertiary hover:bg-surface-elevated hover:text-accent",children:(0,t.jsx)(O,{className:"h-3 w-3"})})]})]}),n&&(0,t.jsx)("div",{className:"border-t border-border-subtle bg-surface-elevated/20 px-3 py-3",children:a&&!d?(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(ts.default,{className:"h-8 w-full"}),(0,t.jsx)(ts.default,{className:"h-8 w-full"})]}):d?.lines&&d.lines.length>0?(()=>{let r=[],n=new Set;for(let e of d.lines){let t=String(e.trackingNumber||"").trim();if(!t||n.has(t))continue;n.add(t);let s=p(t)[0];s&&r.push(s)}let s=(0,x.splitOrderLines)(d.lines);return(0,t.jsxs)(t.Fragment,{children:[r.length>0&&(0,t.jsxs)("div",{className:"mb-3 flex flex-wrap items-center gap-2 text-[10px] text-text-tertiary",children:[(0,t.jsx)("span",{className:"uppercase tracking-wider",children:"Tracking:"}),r.slice(0,3).map(e=>(0,t.jsx)(ti.default,{trackingNumber:e,carrier:"UPS"},e)),r.length>3&&(0,t.jsxs)("span",{className:"text-text-muted",children:["+",r.length-3," more"]})]}),(0,t.jsx)("div",{className:"overflow-hidden rounded-lg border border-border-subtle bg-surface",children:(0,t.jsxs)("table",{className:"w-full text-xs",children:[(0,t.jsx)("thead",{children:(0,t.jsxs)("tr",{className:"border-b border-border-subtle bg-surface-elevated/40 text-left text-text-tertiary",children:[(0,t.jsx)("th",{className:"hidden px-3 py-2 font-medium sm:table-cell",children:"SKU"}),(0,t.jsx)("th",{className:"px-3 py-2 font-medium",children:"Product"}),(0,t.jsx)("th",{className:"hidden px-3 py-2 font-medium md:table-cell",children:"UPC"}),(0,t.jsx)("th",{className:"px-3 py-2 text-center font-medium",children:"Qty"}),(0,t.jsx)("th",{className:"hidden px-3 py-2 text-right font-medium sm:table-cell",children:"Price"}),(0,t.jsx)("th",{className:"px-3 py-2 text-right font-medium",children:"Total"})]})}),(0,t.jsx)("tbody",{children:s.products.map((r,n)=>{let s=`inv-${e.id}-${r.itemId}-${n}`,a=p(String(r.trackingNumber||"")),i=e4(m,r.itemId,ep);return(0,t.jsxs)("tr",{className:`border-b border-border-subtle/50 transition-colors last:border-0 ${i?"bg-accent-bg":""}`,children:[(0,t.jsxs)("td",{className:"hidden px-3 py-2 font-mono text-[10px] text-text-secondary sm:table-cell",children:[r.externalId||"â",r.scpItemNo&&(0,t.jsxs)("div",{className:"mt-0.5 text-[10px] font-semibold",style:{color:"#7c3aed"},children:["BPN: ",r.scpItemNo]})]}),(0,t.jsxs)("td",{className:"px-3 py-2 text-text-primary",children:[(0,t.jsxs)("div",{children:[r.description||eK(r.itemName)||"â",a.length>0&&(0,t.jsx)("span",{className:"ml-1.5",children:(0,t.jsx)(ei,{shipments:[{ref:e.invoiceNumber,qty:Math.abs(r.quantity),trackingNumbers:a}]})})]}),(0,t.jsxs)("div",{className:"mt-0.5 flex flex-wrap gap-x-2 font-mono text-[10px] text-text-tertiary sm:hidden",children:[r.externalId&&(0,t.jsx)("span",{children:r.externalId}),r.scpItemNo&&(0,t.jsxs)("span",{className:"font-semibold",style:{color:"#7c3aed"},children:["BPN ",r.scpItemNo]}),r.upc&&(0,t.jsxs)("span",{children:["UPC ",r.upc]})]}),(0,t.jsxs)("div",{className:"mt-0.5 text-[10px] text-text-tertiary tabular-nums sm:hidden",children:[(0,A.formatCurrency)(r.rate)," each"]})]}),(0,t.jsx)("td",{className:"hidden px-3 py-2 font-mono text-[10px] text-text-secondary md:table-cell",children:r.upc||"â"}),(0,t.jsx)("td",{className:"px-3 py-2 text-center text-text-secondary",children:Math.abs(r.quantity)}),(0,t.jsx)("td",{className:"hidden px-3 py-2 text-right text-text-secondary tabular-nums sm:table-cell",children:(0,A.formatCurrency)(r.rate)}),(0,t.jsx)("td",{className:"px-3 py-2 text-right font-medium tabular-nums",children:(0,A.formatCurrency)(r.amount)})]},s)})}),(0,t.jsxs)("tfoot",{className:"bg-surface-elevated/40 text-text-secondary",children:[(0,t.jsxs)("tr",{className:"border-t border-border-subtle",children:[(0,t.jsx)("td",{colSpan:5,className:"px-3 py-2 text-right text-text-tertiary",children:"Subtotal"}),(0,t.jsx)("td",{className:"px-3 py-2 text-right font-medium tabular-nums",children:(0,A.formatCurrency)(s.productSubtotal)})]}),s.summary.map((e,r)=>(0,t.jsxs)("tr",{children:[(0,t.jsx)("td",{colSpan:5,className:"px-3 py-1.5 text-right text-text-tertiary",children:(0,x.summaryChargeLabel)(e,(0,tI.cleanShipLabel)(e.description||eK(e.itemName)||"Charge"))}),(0,t.jsx)("td",{className:`px-3 py-1.5 text-right tabular-nums ${e.amount<0?"text-success":"text-text-secondary"}`,children:(0,A.formatCurrency)(e.amount)})]},`inv-summary-${e.itemId}-${r}`)),(0,t.jsxs)("tr",{className:"border-t border-border-default",children:[(0,t.jsx)("td",{colSpan:5,className:"px-3 py-2 text-right text-[10px] font-semibold uppercase tracking-wider text-text-tertiary",children:"Invoice Total"}),(0,t.jsx)("td",{className:"px-3 py-2 text-right font-bold tabular-nums text-text-primary",children:(0,A.formatCurrency)(e.total??s.productSubtotal)})]})]})]})})]})})():(0,t.jsx)("p",{className:"text-center text-xs text-text-muted",children:"No line items available for this invoice."})})]},e.id)})})]}),ey.length>0&&!e.fulfillments?.length&&(0,t.jsx)("div",{className:"mb-4 flex flex-wrap gap-2 text-xs",children:ey.map(e=>(0,t.jsx)(ti.default,{trackingNumber:e.tn,carrier:e.carrier||"UPS"},e.tn))}),e.shippingAddress&&(0,t.jsxs)("div",{className:"mb-4 rounded-lg border border-border-subtle p-3",children:[(0,t.jsxs)("div",{className:"mb-1 flex items-center justify-between",children:[(0,t.jsx)("p",{className:"text-[10px] font-semibold uppercase tracking-wider text-text-tertiary",children:"Shipping Address"}),e.shipMethod&&(0,t.jsxs)("p",{className:"text-[10px] text-text-tertiary",children:[(0,t.jsx)("span",{className:"uppercase tracking-wider",children:"Method:"})," ",(0,t.jsx)("span",{className:"font-medium text-text-secondary",children:(0,tI.cleanShipLabel)(e.shipMethod)})]})]}),(0,t.jsxs)("div",{className:"space-y-0.5 text-xs text-text-secondary",children:[e.shippingAddress.attention&&(0,t.jsx)("p",{children:e.shippingAddress.attention}),e.shippingAddress.company&&(0,t.jsx)("p",{children:e.shippingAddress.company}),(0,t.jsx)("p",{children:e.shippingAddress.addr1}),e.shippingAddress.addr2&&(0,t.jsx)("p",{children:e.shippingAddress.addr2}),(0,t.jsxs)("p",{children:[e.shippingAddress.city,", ",e.shippingAddress.state," ",e.shippingAddress.zip]})]})]}),!e.shippingAddress&&e.shipMethod&&(0,t.jsxs)("div",{className:"mb-4 rounded-lg border border-border-subtle p-3",children:[(0,t.jsx)("p",{className:"text-[10px] font-semibold uppercase tracking-wider text-text-tertiary",children:"Shipping Method"}),(0,t.jsx)("p",{className:"mt-0.5 text-xs text-text-secondary",children:(0,tI.cleanShipLabel)(e.shipMethod)})]}),X&&(X.totalSkipped>0||X.hardError)&&(0,t.jsx)("div",{className:"mt-3",children:(0,t.jsx)(tq,{summary:X,orderRef:e.orderNumber,onDismiss:Z,onViewCart:()=>R?.openDrawer?.()})}),h&&(h.payments.length>0||h.refunds.length>0||h.deposits.length>0||h.creditApplications.length>0)&&(0,t.jsxs)("div",{className:"mt-4 rounded-lg border border-border-subtle bg-surface-elevated/30",children:[(0,t.jsx)("div",{className:"border-b border-border-subtle px-4 py-2.5",children:(0,t.jsx)("p",{className:"text-[10px] font-semibold uppercase tracking-wider text-text-tertiary",children:"Payments & refunds for this order"})}),h.payments.map(r=>(0,t.jsxs)("div",{className:"flex items-center gap-3 border-b border-border-subtle/50 px-4 py-3 last:border-b-0",children:[(0,t.jsx)("span",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-success-bg text-success",children:(0,t.jsx)(e7,{className:"h-4 w-4"})}),(0,t.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,t.jsxs)("p",{className:"text-sm font-medium text-text-primary",children:["Payment ",r.tranId]}),(0,t.jsxs)("p",{className:"text-xs text-text-muted",children:[(0,A.formatDate)(r.date),r.paymentMethod&&(0,t.jsxs)(t.Fragment,{children:[" · ",r.paymentMethod]})]})]}),(0,t.jsx)("p",{className:"text-sm font-semibold tabular-nums text-success",children:(0,A.formatCurrency)(r.amount)}),(0,t.jsx)("a",{href:`${W}
81?action=pdf&paymentId=${r.id}`,target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),title:`Download receipt for ${r.tranId}`,className:"inline-flex h-10 w-10 items-center justify-center rounded-lg text-text-secondary hover:bg-surface hover:text-accent",children:(0,t.jsx)(l.Download,{className:"h-4 w-4"})})]},`order-${e.id}-pmt-${r.id}`)),h.refunds.map(r=>(0,t.jsxs)("div",{className:"flex items-center gap-3 border-b border-border-subtle/50 px-4 py-3 last:border-b-0",children:[(0,t.jsx)("span",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-success-bg text-success",children:(0,t.jsx)(tt.Undo2,{className:"h-4 w-4"})}),(0,t.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,t.jsxs)("p",{className:"text-sm font-medium text-text-primary",children:["Refund ",r.tranId]}),(0,t.jsxs)("p",{className:"text-xs text-text-muted",children:[(0,A.formatDate)(r.date)," · ",r.methodLabel,r.source&&(0,t.jsxs)(t.Fragment,{children:[" · ","vs ",r.source.label]})]})]}),(0,t.jsxs)("p",{className:"text-sm font-semibold tabular-nums text-success",children:["+",(0,A.formatCurrency)(r.amount)]}),(0,t.jsx)("a",{href:`${K}?action=pdf&refundId=${r.id}`,target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),title:`Download refund ${r.tranId} PDF`,className:"inline-flex h-10 w-10 items-center justify-center rounded-lg text-text-secondary hover:bg-surface hover:text-accent",children:(0,t.jsx)(l.Download,{className:"h-4 w-4"})})]},`order-${e.id}-rfd-${r.id}`)),h.deposits.map(r=>{let n=0===r.unapplied&&r.amount>0,s=r.unapplied>0?r.unapplied:0,a=s>0&&s<r.amount,i=!["SalesOrd:G","SalesOrd:H","SalesOrd:C"].includes(e.statusRef);return(0,t.jsxs)("div",{className:"flex items-center gap-3 border-b border-border-subtle/50 px-4 py-3 last:border-b-0",children:[(0,t.jsx)("span",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-info-bg text-info",children:(0,t.jsx)(tr,{className:"h-4 w-4"})}),(0,t.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,t.jsxs)("p",{className:"text-sm font-medium text-text-primary",children:["Payment ",r.tranId,n&&(0,t.jsx)("span",{className:"ml-2 text-[10px] uppercase tracking-wide text-text-muted",children:"· applied"})]}),(0,t.jsxs)("p",{className:"text-xs text-text-muted",children:[(0,A.formatDate)(r.date),r.memo&&(0,t.jsxs)(t.Fragment,{children:[" · ",r.memo]})]}),a&&(0,t.jsxs)("p",{className:"mt-1 inline-flex items-center gap-1.5 text-[11px] font-medium text-info",children:[(0,t.jsx)("span",{className:"h-1.5 w-1.5 rounded-full bg-info"}),i?(0,t.jsxs)(t.Fragment,{children:[(0,A.formatCurrency)(s)," held for the rest of this order â applied when your remaining items ship"]}):(0,t.jsxs)(t.Fragment,{children:[(0,A.formatCurrency)(s)," unused â available on your account"]})]})]}),(0,t.jsxs)("div",{className:"text-right",children:[(0,t.jsx)("p",{className:`text-sm font-semibold tabular-nums ${n?"text-text-muted":"text-info"}`,children:(0,A.formatCurrency)(r.amount)}),(0,t.jsx)("p",{className:"text-[10px] text-text-muted",children:"paid"})]}),(0,t.jsx)("a",{href:`${H}?action=pdf&transactionId=${r.id}&recordType=customerdeposit`,target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),title:`Download receipt for ${r.tranId}`,className:"inline-flex h-10 w-10 items-center justify-center rounded-lg text-text-secondary hover:bg-surface hover:text-accent",children:(0,t.jsx)(l.Download,{className:"h-4 w-4"})})]},`order-${e.id}-dep-${r.id}`)}),h.creditApplications.map(r=>(0,t.jsxs)("div",{className:"flex items-center gap-3 border-b border-border-subtle/50 px-4 py-3 last:border-b-0",children:[(0,t.jsx)("span",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-info-bg text-info",children:(0,t.jsx)(te.FileText,{className:"h-4 w-4"})}),(0,t.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,t.jsxs)("p",{className:"text-sm font-medium text-text-primary",children:["Credit Memo ",r.credit.tranId,(0,t.jsxs)("span",{className:"ml-2 text-[10px] uppercase tracking-wide text-text-muted",children:["· applied to ",r.appliedToInvoiceNumber]})]}),(0,t.jsxs)("p",{className:"text-xs text-text-muted",children:[(0,A.formatDate)(r.credit.date),r.credit.memo&&(0,t.jsxs)(t.Fragment,{children:[" · ",r.credit.memo]})]})]}),(0,t.jsxs)("div",{className:"text-right",children:[(0,t.jsx)("p",{className:"text-sm font-semibold tabular-nums text-info",children:(0,A.formatCurrency)(r.appliedAmount)}),(0,t.jsx)("p",{className:"text-[10px] text-text-muted",children:"applied total"})]}),(0,t.jsx)("a",{href:`${H}
81?action=pdf&transactionId=${r.credit.id}&recordType=creditmemo`,target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),title:`Download ${r.credit.tranId} PDF`,className:"inline-flex h-10 w-10 items-center justify-center rounded-lg text-text-secondary hover:bg-surface hover:text-accent",children:(0,t.jsx)(l.Download,{className:"h-4 w-4"})})]},`order-${e.id}-cma-${r.credit.id}-${r.appliedToInvoiceId}`)),h.refunds.length>0&&(U=h.deposits.reduce((e,t)=>e+Number(t.amount||0),0)+h.payments.reduce((e,t)=>e+Number(t.amount||0),0)-h.refunded,(0,t.jsxs)("div",{className:"flex items-center justify-between gap-3 border-t border-border-subtle bg-surface-elevated/50 px-4 py-2.5",children:[(0,t.jsx)("span",{className:"text-[11px] font-semibold uppercase tracking-wider text-text-tertiary",children:"Net paid for this order"}),(0,t.jsx)("span",{className:"text-sm font-semibold tabular-nums text-text-primary",children:(0,A.formatCurrency)(U)})]}))]})]})]})}function t0(e){if(!e)return"â";let t=/^(\d{4})-(\d{2})-(\d{2})/.exec(e);return t?`${t[2]}/${t[3]}/${t[1].slice(2)}`:"â"}let t1={exception:{label:"Carrier exception",cls:"bg-error-bg text-error"},"stalled-in-transit":{label:"No movement",cls:"bg-error-bg text-error"},"no-carrier-scan":{label:"No carrier scan",cls:"bg-warning-bg text-warning"},"past-eta":{label:"Past ETA",cls:"bg-warning-bg text-warning"},"past-esd":{label:"Past ship date",cls:"bg-warning-bg text-warning"}};function t2({rows:e,onOpenOrder:r,showCustomer:n}){if(0===e.length)return null;let s=new Set(e.map(e=>e.orderId)).size;return(0,t.jsxs)("div",{className:"mb-4 overflow-hidden rounded-xl border border-border-default bg-surface",children:[(0,t.jsxs)("div",{className:"flex items-baseline justify-between gap-3 border-b border-border-default px-4 py-2.5",children:[(0,t.jsx)("div",{className:"text-[10px] font-semibold uppercase tracking-wider text-text-tertiary",children:"Issues to work"}),(0,t.jsxs)("div",{className:"text-[11px] text-text-tertiary",children:[e.length.toLocaleString("en-US")," ",1===e.length?"issue":"issues"," across"," ",s.toLocaleString("en-US")," ",1===s?"order":"orders"," â click a row for the full drilldown"]})]}),(0,t.jsx)("div",{className:"overflow-x-auto",children:(0,t.jsxs)("table",{className:"w-full min-w-[1000px] text-[12.5px]",children:[(0,t.jsx)("thead",{children:(0,t.jsxs)("tr",{className:"border-b border-border-default text-left text-[10px] font-medium uppercase tracking-wider text-text-tertiary",children:[(0,t.jsx)("th",{className:"px-4 py-2",children:"SO #"}),n&&(0,t.jsx)("th",{className:"px-3 py-2",children:"Customer"}),(0,t.jsx)("th",{className:"px-3 py-2",children:"Shipment / line"}),(0,t.jsx)("th",{className:"px-3 py-2",children:"Lines"}),(0,t.jsx)("th",{className:"px-3 py-2",children:"Boxes"}),(0,t.jsx)("th",{className:"px-3 py-2",children:"Shipped"}),(0,t.jsx)("th",{className:"px-3 py-2",children:"Status"}),(0,t.jsx)("th",{className:"px-3 py-2",children:"ETA / SDD"}),(0,t.jsx)("th",{className:"px-3 py-2",children:"Issue"}),(0,t.jsx)("th",{className:"px-3 py-2",children:"Tracking"})]})}),(0,t.jsx)("tbody",{children:e.map((e,s)=>{let a=t1[e.issue.kind],i=(e.issue.trackingNumbers??[]).filter(Boolean);return(0,t.jsxs)("tr",{onClick:()=>r(e.orderId),className:"cursor-pointer border-b border-border-subtle/60 transition-colors last:border-b-0 hover:bg-surface-elevated",children:[(0,t.jsx)("td",{className:"px-4 py-2.5",children:(0,t.jsxs)("span",{className:"inline-flex items-center gap-1",children:[(0,t.jsx)("span",{className:"font-mono text-xs font-semibold text-accent",children:e.orderNumber}),(0,t.jsx)(z,{value:e.orderNumber,label:"SO number"})]})}),n&&(0,t.jsx)("td",{className:"max-w-[180px] truncate px-3 py-2.5 text-xs text-text-secondary",children:e.customerName||"â"}),(0,t.jsx)("td",{className:"px-3 py-2.5",children:(0,t.jsxs)("span",{className:"inline-flex items-center gap-1 font-mono text-[11px] text-text-secondary",children:[e.issue.ref||"â",e.issue.ref&&(0,t.jsx)(z,{value:e.issue.ref,label:"past-esd"===e.issue.kind?"SKU":"shipment number"})]})}),(0,t.jsx)("td",{className:"px-3 py-2.5",children:e.issue.lines&&e.issue.lines.length>0?(0,t.jsxs)("div",{className:"flex flex-col gap-0.5",children:[e.issue.lines.slice(0,3).map((e,r)=>(0,t.jsxs)("span",{className:"whitespace-nowrap font-mono text-[10.5px] text-text-secondary",children:[e.sku,(0,t.jsxs)("span",{className:"text-text-tertiary",children:[" ","Ã ",e.qty.toLocaleStr
81ing("en-US")]})]},`${e.sku}-${r}`)),e.issue.lines.length>3&&(0,t.jsxs)("span",{className:"text-[10px] text-text-tertiary",children:["+",e.issue.lines.length-3," more"]})]}):(0,t.jsx)("span",{className:"text-xs text-text-tertiary",children:"â"})}),(0,t.jsx)("td",{className:"px-3 py-2.5 text-xs tabular-nums text-text-secondary",children:"number"==typeof e.issue.cartons&&e.issue.cartons>0?(0,t.jsxs)("span",{title:e.issue.units?`${e.issue.units.toLocaleString("en-US")} units`:void 0,children:[(0,t.jsxs)("span",{className:"font-semibold text-text-primary",children:[e.issue.cartonsApprox?"~":"",e.issue.cartons.toLocaleString("en-US")]})," ",(0,t.jsx)("span",{className:"text-text-tertiary",children:1===e.issue.cartons?"box":"boxes"})]}):e.issue.units?(0,t.jsxs)("span",{className:"text-text-tertiary",children:[e.issue.units.toLocaleString("en-US")," units"]}):(0,t.jsx)("span",{className:"text-text-tertiary",children:"â"})}),(0,t.jsx)("td",{className:"px-3 py-2.5 text-xs tabular-nums text-text-secondary",children:t0(e.issue.shippedDate)}),(0,t.jsx)("td",{className:"px-3 py-2.5 text-xs text-text-secondary",children:e.issue.statusLabel||"â"}),(0,t.jsx)("td",{className:"px-3 py-2.5 text-xs tabular-nums text-text-secondary",children:t0(e.issue.eta)}),(0,t.jsx)("td",{className:"px-3 py-2.5",children:(0,t.jsx)("span",{className:`inline-flex items-center whitespace-nowrap rounded-full px-2 py-0.5 text-[10px] font-semibold ${a.cls}`,children:a.label})}),(0,t.jsx)("td",{className:"px-3 py-2.5",onClick:e=>e.stopPropagation(),children:i.length>0?(0,t.jsxs)("div",{className:"flex flex-col gap-0.5",children:[i.slice(0,2).map(r=>(0,t.jsx)(ti.default,{trackingNumber:r,carrier:e.issue.carrier||"",context:`${e.orderNumber} \xb7 ${e.issue.ref}`},r)),i.length>2&&(0,t.jsxs)("span",{className:"text-[10px] text-text-tertiary",children:["+",i.length-2," more"]})]}):(0,t.jsx)("span",{className:"text-xs text-text-tertiary",children:"â"})})]},`${e.orderId}-${e.issue.ref}-${e.issue.kind}-${s}`)})})]})})]})}var t5=e.i(517320);function t3({lines:e,loading:r,invoiceNumber:n,invoiceTotal:s,highlightedLine:a}){if(r&&!e)return(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(ts.default,{className:"h-8 w-full"}),(0,t.jsx)(ts.default,{className:"h-8 w-full"})]});if(!e||0===e.length)return(0,t.jsx)("p",{className:"text-center text-xs text-text-muted",children:"No line items available for this invoice."});let i=[],l=new Set;for(let t of e){let e=String(t.trackingNumber||"").trim();if(!e||l.has(e))continue;l.add(e);let r=p(e)[0];r&&i.push(r)}let o=(0,x.splitOrderLines)(e);return(0,t.jsxs)(t.Fragment,{children:[i.length>0&&(0,t.jsxs)("div",{className:"mb-3 flex flex-wrap items-center gap-2 text-[10px] text-text-tertiary",children:[(0,t.jsx)("span",{className:"uppercase tracking-wider",children:"Tracking:"}),i.slice(0,3).map(e=>(0,t.jsx)(ti.default,{trackingNumber:e,carrier:"UPS"},e)),i.length>3&&(0,t.jsxs)("span",{className:"text-text-muted",children:["+",i.length-3," more"]})]}),(0,t.jsx)("div",{className:"overflow-hidden rounded-lg border border-border-subtle bg-surface",children:(0,t.jsxs)("table",{className:"w-full text-xs",children:[(0,t.jsx)("thead",{children:(0,t.jsxs)("tr",{className:"border-b border-border-subtle bg-surface-elevated/40 text-left text-text-tertiary",children:[(0,t.jsx)("th",{className:"hidden px-3 py-2 font-medium sm:table-cell",children:"SKU"}),(0,t.jsx)("th",{className:"px-3 py-2 font-medium",children:"Product"}),(0,t.jsx)("th",{className:"hidden px-3 py-2 font-medium md:table-cell",children:"UPC"}),(0,t.jsx)("th",{className:"px-3 py-2 text-center font-medium",children:"Qty"}),(0,t.jsx)("th",{className:"hidden px-3 py-2 text-right font-medium sm:table-cell",children:"Price"}),(0,t.jsx)("th",{className:"px-3 py-2 text-right font-medium",children:"Total"})]})}),(0,t.jsx)("tbody",{children:o.products.map((e,r)=>{let s=`inv-${n}-${e.itemId}-${r}`,i=p(String(e.trackingNumber||"")),l=null!=a&&e.itemId===a;return(0,t.jsxs)("tr",{className:`border-b border-border-subtle/50 transition-colors last:border-0 ${l?"bg-accent-bg":""}`,children:[(0,t.jsx)("td",{className:"hidden px-3 py-2 font-mono text-[10px] text-text-secondary sm:table-cell",children:e.externalId||"â"}),(0,t.jsxs)("td",{className:"px-3 py-2 text-text-primary",children:[(0,t.jsxs)("div",{children:[e.description||eK(e.itemName)||"â",i.length>0&&(0,t.jsx)("span",{className:"ml-1.5",children:(0,t.jsx)(ei,{shipments:[{ref:n,qty:Math.abs(e.quantity),trackingNumbers:i}]})})]}),(0,t.jsxs)("div",{className:"mt-0.5 flex flex-wrap gap-x-2 font-mono text-[10px] text-text-tertiary sm:hidden",children:[e.externalId&&(0,t.jsx)("span",{children:e.externalId}),e.upc&&(0,t.jsxs)("span",{children:["UPC ",e.upc]})]}),(0,t.jsxs)("div",{className:"mt-0.5 text-[10px] text-text-tertiary tabular-nums sm:hidden",children:[(0,A.formatCurrency)(e.rate)," each"]})]}),(0,t.jsx)("td",{className:"hidden px-3 py-2 font-mono text-[10px] text-text-secondary md:table-cell",children:e.upc||"â"}),(0,t.jsx)("td",{className:"px-3 py-2 text-center text-text-secondary",children:Math.abs(e.quantity)}),(0,t.jsx)("td",{className:"hidden px-3 py-2 text-right text-text-secondary tabular-nums sm:table-cell",children:(0,A.formatCurrency)(e.rate)}),(0,t.jsx)("td",{className:"px-3 py-2 text-right font-medium tabular-nums",children:(0,A.formatCurrency)(e.amount)})]},s)})}),(0,t.jsxs)("tfoot",{className:"bg-surface-elevated/40 text-text-secondary",children:[(0,t.jsxs)("tr",{className:"border-t border-border-subtle",children:[(0,t.jsx)("td",{colSpan:5,className:"px-3 py-2 text-right text-text-tertiary",children:"Subtotal"}),(0,t.jsx)("td",{className:"px-3 py-2 text-right font-medium tabular-nums",children:(0,A.formatCurrency)(o.productSubtotal)})]}),o.summary.map((e,r)=>(0,t.jsxs)("tr",{children:[(0,t.jsx)("td",{colSpan:5,className:"px-3 py-1.5 text-right text-text-tertiary",children:(0,tI.cleanShipLabel)(e.description||eK(e.itemName)||"Charge")}
81),(0,t.jsx)("td",{className:`px-3 py-1.5 text-right tabular-nums ${e.amount<0?"text-success":"text-text-secondary"}`,children:(0,A.formatCurrency)(e.amount)})]},`inv-summary-${e.itemId}-${r}`)),(0,t.jsxs)("tr",{className:"border-t border-border-default",children:[(0,t.jsx)("td",{colSpan:5,className:"px-3 py-2 text-right text-[10px] font-semibold uppercase tracking-wider text-text-tertiary",children:"Invoice Total"}),(0,t.jsx)("td",{className:"px-3 py-2 text-right font-bold tabular-nums text-text-primary",children:(0,A.formatCurrency)(s??o.productSubtotal)})]})]})]})})]})}function t4(e){if("Cancelled"===e.status||"Voided"===e.status)return"Cancelled";if(e.isOverdue)return"Overdue";let t=Number(e.amountRemaining??0),r=Number(e.total??0);return 0===t&&r>0?"Paid":0===t&&0===r?"No charge":"Open"}function t8({invoice:e,highlighted:n}){let a=D(),d=T(),c=P(),[u,x]=(0,r.useState)(!1),[m,p]=(0,r.useState)(null),[h,f]=(0,r.useState)(!1);async function g(){let t=!u;if(x(t),t&&!m&&!h){f(!0);try{let t=await fetch(`${c}?invoiceId=${e.id}`),r=await t.json(),n=r.data??r;n&&n.id&&p(n)}catch(e){console.error("[activity] invoice detail fetch failed:",e)}finally{f(!1)}}}let b=t4(e),y=(0,A.getStatusTone)(b),v=(0,A.formatPoNumber)(e.poNumber),j=!!d&&a&&e.amountRemaining>0;return(0,t.jsxs)("section",{className:`rounded-xl border bg-surface px-5 py-4 ${n?"border-accent ring-2 ring-accent/30":"border-border-default"}`,children:[(0,t.jsxs)("div",{className:"flex flex-col gap-2 sm:flex-row sm:flex-wrap sm:items-center sm:justify-between sm:gap-3",children:[(0,t.jsxs)("div",{onClick:g,role:"button",tabIndex:0,onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),g())},"aria-expanded":u,className:"min-w-0 flex-1 cursor-pointer",children:[(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[u?(0,t.jsx)(i,{className:"h-3.5 w-3.5 shrink-0 text-text-tertiary"}):(0,t.jsx)(s.ChevronDown,{className:"h-3.5 w-3.5 shrink-0 text-text-tertiary"}),(0,t.jsx)("span",{className:"font-mono font-medium text-text-primary",children:e.invoiceNumber}),(0,t.jsx)(tn.default,{variant:"success"===y?"success":"warning"===y?"warning":"error"===y?"error":"default",children:b}),(0,t.jsx)("span",{className:"whitespace-nowrap rounded bg-surface-elevated px-1.5 py-0.5 text-[10px] font-medium text-text-tertiary",children:"Invoice only"})]}),(0,t.jsxs)("p",{className:"mt-0.5 truncate text-xs text-text-tertiary",children:["Issued ",(0,A.formatDate)(e.date),e.dueDate&&(0,t.jsxs)(t.Fragment,{children:[" · Due ",(0,A.formatDate)(e.dueDate)]}),"â"!==v&&(0,t.jsxs)(t.Fragment,{children:[" · ","PO ",(0,t.jsx)("span",{className:"font-mono",children:v})]})]})]}),(0,t.jsxs)("div",{className:"flex w-full items-center justify-between gap-3 sm:w-auto sm:justify-end",children:[(0,t.jsx)("div",{className:"text-left sm:text-right",children:e.amountRemaining>0?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("p",{className:"text-[10px] uppercase tracking-wide text-text-tertiary",children:"Remaining"}),(0,t.jsx)("p",{className:"font-semibold tabular-nums text-text-primary",children:(0,A.formatCurrency)(e.amountRemaining)})]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("p",{className:"text-[10px] uppercase tracking-wide text-text-tertiary",children:"Total"}),(0,t.jsx)("p",{className:"font-semibold tabular-nums text-text-primary",children:(0,A.formatCurrency)(e.total)})]})}),j&&(0,t.jsxs)("button",{type:"button",onClick:function(){d&&d([String(e.id)])},title:`Pay ${e.invoiceNumber}`,className:"inline-flex h-8 items-center gap-1.5 rounded-lg bg-accent/10 px-2.5 text-xs font-medium text-accent transition-colors hover:bg-accent hover:text-accent-foreground",children:[(0,t.jsx)(t5.CreditCard,{className:"h-3.5 w-3.5"}),"Pay"]}),(0,t.jsx)("a",{href:`${c}?action=pdf&invoiceId=${e.id}`,target:"_blank",rel:"noopener noreferrer",title:"Download Invoice PDF",className:"inline-flex h-10 w-10 items-center justify-center rounded-lg text-text-secondary hover:bg-surface-elevated hover:text-accent",children:(0,t.jsx)(l.Download,{className:"h-4 w-4"})}),(0,t.jsx)("a",{href:`${c}
81?action=pdf&invoiceId=${e.id}&template=packing`,target:"_blank",rel:"noopener noreferrer",title:"Download Packing List PDF",className:"inline-flex h-10 w-10 items-center justify-center rounded-lg text-text-secondary hover:bg-surface-elevated hover:text-accent",children:(0,t.jsx)(o.Package,{className:"h-4 w-4"})})]})]}),u&&(0,t.jsx)("div",{className:"mt-3 border-t border-border-subtle pt-3",children:(0,t.jsx)(t3,{lines:m?.lines,loading:h,invoiceNumber:e.invoiceNumber,invoiceTotal:e.total})})]})}e.s(["resolveInvoiceStatusLabel",0,t4],186855);var t6=e.i(401412);let t9=(0,a.default)("rotate-ccw",[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}]]);function t7({row:e,selectable:n,selected:s,onToggleSelect:a,invoicePdfHref:i}){let o=P(),d=L(),c=(0,r.useContext)(C).returnsPdfBase,u=E();if("invoice"===e.kind){let r=e.data,o=function(e){if(!e)return 0;let t=new Date(e).getTime();return Number.isFinite(t)?Math.floor((Date.now()-t)/864e5):0}(r.dueDate),d=o>0&&r.amountRemaining>0,c=0===r.amountRemaining&&r.total>0;return(0,t.jsxs)("label",{className:(0,et.cn)("flex cursor-pointer items-center gap-3 border-b border-border-default px-4 py-3 transition-colors",s?"bg-accent/5":"hover:bg-surface-elevated"),children:[n&&!c?(0,t.jsx)("input",{type:"checkbox",className:"h-4 w-4 accent-accent",checked:s,onChange:a}):(0,t.jsx)("span",{className:"w-4"}),(0,t.jsx)("span",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-surface-elevated text-text-tertiary",children:(0,t.jsx)(t6.Receipt,{className:"h-4 w-4"})}),(0,t.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,t.jsx)("span",{className:"text-sm font-semibold text-text-primary",children:r.invoiceNumber}),(0,t.jsx)(tn.default,{variant:c?"success":d?"error":"default",children:c?"Paid":d?`${o}d overdue`:"Open"}),r.salesOrderNumber&&(0,t.jsx)("span",{className:"rounded bg-surface-elevated px-1.5 py-0.5 text-[10px] font-medium text-text-muted",children:r.salesOrderNumber})]}),(0,t.jsxs)("div",{className:"mt-0.5 text-xs text-text-muted",children:["Issued ",(0,A.formatDate)(r.date),r.dueDate&&(0,t.jsxs)(t.Fragment,{children:[" · Due ",(0,A.formatDate)(r.dueDate)]}),r.poNumber&&(0,t.jsxs)(t.Fragment,{children:[" · PO ",r.poNumber]})]})]}),(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[(0,t.jsxs)("div",{className:"text-right",children:[(0,t.jsx)("div",{className:(0,et.cn)("text-sm font-semibold tabular-nums",c?"text-text-muted":"text-text-primary"),children:(0,A.formatCurrency)(c?r.total:r.amountRemaining)}),!c&&r.amountRemaining!==r.total&&(0,t.jsxs)("div",{className:"text-[11px] text-text-muted",children:["of ",(0,A.formatCurrency)(r.total)]})]}),(0,t.jsx)("a",{href:i(r.id),target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),title:"Download PDF",className:"inline-flex h-8 w-8 items-center justify-center rounded-lg text-text-secondary hover:bg-surface-elevated hover:text-accent",children:(0,t.jsx)(l.Download,{className:"h-4 w-4"})})]})]})}if("credit"===e.kind){let r=e.data,n=0===r.unapplied&&r.total>0,s=r.unapplied>0&&r.unapplied<r.total,a=r.unapplied>0;return(0,t.jsxs)("div",{className:"flex items-center gap-3 border-b border-border-default px-4 py-3 hover:bg-surface-elevated",children:[(0,t.jsx)("span",{className:"w-4"}),(0,t.jsx)("span",{className:(0,et.cn)("flex h-8 w-8 shrink-0 items-center justify-center rounded-lg",n?"bg-surface-elevated text-text-tertiary":"bg-success-bg text-success"),children:(0,t.jsx)(te.FileText,{className:"h-4 w-4"})}),(0,t.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,t.jsx)("span",{className:"text-sm font-semibold text-text-primary",children:r.tranId}),n?(0,t.jsx)(tn.default,{variant:"default",children:"Applied"}):(0,t.jsx)(tn.default,{variant:"success",children:"Credit"}),s&&(0,t.jsx)("span",{className:"rounded bg-surface-elevated px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide text-text-muted",children:"Partial"}),r.poNumber&&(0,t.jsxs)("span",{className:"rounded bg-surface-elevated px-1.5 py-0.5 text-[10px] font-medium text-text-muted",children:["PO ",r.poNumber]}
81),r.linkedReturnTranId&&(0,t.jsxs)("span",{className:"rounded bg-warning-bg px-1.5 py-0.5 text-[10px] font-medium text-warning",children:["from ",r.linkedReturnTranId]})]}),(0,t.jsxs)("div",{className:"mt-0.5 text-xs text-text-muted",children:["Issued ",(0,A.formatDate)(r.date),r.memo&&(0,t.jsxs)(t.Fragment,{children:[" · ",r.memo]})]})]}),(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[(0,t.jsxs)("div",{className:"text-right",children:[(0,t.jsx)("div",{className:(0,et.cn)("text-sm font-semibold tabular-nums",n?"text-text-muted":"text-success"),children:(0,A.formatCurrency)(n?r.total:r.unapplied)}),s&&(0,t.jsxs)("div",{className:"text-[11px] text-text-muted",children:["of ",(0,A.formatCurrency)(r.total)]})]}),a&&(0,t.jsx)(tl.default,{href:"/account/activity?view=to-pay",title:"Apply to an invoice",className:"rounded-md border border-border-default bg-surface px-2.5 py-1.5 text-xs font-medium text-text-primary hover:bg-surface-elevated",children:"Apply"}),(0,t.jsx)("a",{href:`${o}?action=pdf&transactionId=${r.id}&recordType=creditmemo`,target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),title:"Download credit memo PDF",className:"inline-flex h-8 w-8 items-center justify-center rounded-lg text-text-secondary hover:bg-surface-elevated hover:text-accent",children:(0,t.jsx)(l.Download,{className:"h-4 w-4"})})]})]})}if("payment"===e.kind){let r=e.data,n=r.appliedInvoices??[];return(0,t.jsxs)("div",{className:"flex items-center gap-3 border-b border-border-default px-4 py-3 hover:bg-surface-elevated",children:[(0,t.jsx)("span",{className:"w-4"}),(0,t.jsx)("span",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-surface-elevated text-text-secondary",children:(0,t.jsx)(t5.CreditCard,{className:"h-4 w-4"})}),(0,t.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,t.jsx)("span",{className:"text-sm font-semibold text-text-primary",children:r.tranId}),(0,t.jsx)(tn.default,{variant:"success",children:r.statusLabel||"Posted"}),r.paymentMethod&&(0,t.jsx)("span",{className:"rounded bg-surface-elevated px-1.5 py-0.5 text-[10px] font-medium text-text-muted",children:r.paymentMethod}),n.length>0&&(0,t.jsxs)("span",{className:"text-[11px] text-text-muted",children:["Applied to"," ",n.slice(0,3).map(e=>e.tranId).join(", "),n.length>3&&` +${n.length-3} more`]})]}),(0,t.jsxs)("div",{className:"mt-0.5 text-xs text-text-muted",children:["Received ",(0,A.formatDate)(r.date),r.memo&&(0,t.jsxs)(t.Fragment,{children:[" · ",r.memo]})]})]}),(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[(0,t.jsx)("div",{className:"text-right",children:(0,t.jsxs)("div",{className:"text-sm font-semibold tabular-nums text-text-secondary",children:["â",(0,A.formatCurrency)(r.amount)]})}),(0,t.jsx)("a",{href:`${d}?action=pdf&paymentId=${r.id}`,target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),title:"Download receipt PDF",className:"inline-flex h-8 w-8 items-center justify-center rounded-lg text-text-secondary hover:bg-surface-elevated hover:text-accent",children:(0,t.jsx)(l.Download,{className:"h-4 w-4"})})]})]})}if("return"===e.kind){let r=e.data,n=r.statusLabel||"Return";return(0,t.jsxs)("div",{className:"flex items-center gap-3 border-b border-border-default px-4 py-3 hover:bg-surface-elevated",children:[(0,t.jsx)("span",{className:"w-4"}),(0,t.jsx)("span",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-warning-bg text-warning",children:(0,t.jsx)(t9,{className:"h-4 w-4"})}),(0,t.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,t.jsx)("span",{className:"text-sm font-semibold text-text-primary",children:r.tranId}),(0,t.jsx)(tn.default,{variant:"warning",children:n}),r.sourceSalesOrderNumber&&(0,t.jsxs)("span",{className:"rounded bg-surface-elevated px-1.5 py-0.5 text-[10px] font-medium text-text-muted",children:["from ",r.sourceSalesOrderNumber]}),r.creditMemoTranId&&(0,t.jsxs)("span",{className:"rounded bg-success-bg px-1.5 py-0.5 text-[10px] font-medium text-success",children:["â ",r.creditMemoTranId]})]}),(0,t.jsxs)("div",{className:"mt-0.5 text-xs text-text-muted",children:["Opened ",(0,A.formatDate)(r.date),r.memo&&(0,t.jsxs)(t.Fragment,{children:[" · ",r.memo]})]})]}),(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[(0,t.jsx)("div",{className:"text-right",children:(0,t.jsx)("div",{className:"text-sm font-semibold tabular-nums text-warning",children:(0,A.formatCurrency)(r.total)})}),(0,t.jsx)("a",{href:`${c}/${r.id}/pdf`,target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),title:"Download RA PDF",className:"inline-flex h-8 w-8 items-center justify-center rounded-lg text-text-secondary hover:bg-surface-elevated hover:text-accent",children:(0,t.jsx)(l.Download,{className:"h-4 w-4"})})]})]})}if("refund"===e.kind){let r=e.data,n=r.source&&("deposit"===r.source.type||"credit_memo"===r.source.type)?`/account/activity?focus=${encodeURIComponent(r.source.tranId)}`:null;return(0,t.jsxs)("div",{className:"flex items-center gap-3 border-b border-border-default px-4 py-3 hover:bg-surface-elevated",children:[(0,t.jsx)("span",{className:"w-4"}),(0,t.jsx)("span",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-success-bg text-success",children:(0,t.jsx)(tt.Undo2,{className:"h-4 w-4"})}),(0,t.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,t.jsx)("span",{className:"text-sm font-semibold text-text-primary",children:r.tranId}),(0,t.jsx)(tn.default,{variant:"success",children:r.statusLabel}),r.source&&(0,t.jsxs)("span",{className:"rounded bg-surface-elevated px-1.5 py-0.5 text-[10px] font-medium text-text-muted",children:["vs ",r.source.tranId]}
81),r.sourceSalesOrderNumber&&(0,t.jsxs)(tl.default,{href:`/account/activity?order=${r.sourceSalesOrderId}`,onClick:e=>e.stopPropagation(),className:"rounded bg-accent/10 px-1.5 py-0.5 text-[10px] font-medium text-accent hover:bg-accent/15",title:`Open the originating sales order ${r.sourceSalesOrderNumber}`,children:["from ",r.sourceSalesOrderNumber]})]}),(0,t.jsxs)("div",{className:"mt-0.5 text-xs text-text-muted",children:[r.methodLabel," · ",(0,A.formatDate)(r.date),r.source&&(0,t.jsxs)(t.Fragment,{children:[" · Refunded against ",n?(0,t.jsx)(tl.default,{href:n,onClick:e=>e.stopPropagation(),className:"font-medium text-accent hover:underline",children:r.source.label}):(0,t.jsx)("span",{className:"font-medium text-text-secondary",children:r.source.label})]})]})]}),(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[(0,t.jsxs)("div",{className:"text-right",children:[(0,t.jsxs)("div",{className:"text-sm font-semibold tabular-nums text-success",children:["+",(0,A.formatCurrency)(r.amount)]}),(0,t.jsx)("div",{className:"text-[11px] text-text-muted",children:"to you"})]}),(0,t.jsx)("a",{href:`${u}?action=pdf&refundId=${r.id}`,target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),title:`Download refund ${r.tranId} PDF`,className:"inline-flex h-8 w-8 items-center justify-center rounded-lg text-text-secondary hover:bg-surface-elevated hover:text-accent",children:(0,t.jsx)(l.Download,{className:"h-4 w-4"})})]})]})}let x=e.data,m=0===x.unapplied&&x.amount>0,p=x.unapplied>0&&x.unapplied<x.amount,h=x.unapplied>0;return(0,t.jsxs)("div",{className:"flex items-center gap-3 border-b border-border-default px-4 py-3 hover:bg-surface-elevated",children:[(0,t.jsx)("span",{className:"w-4"}),(0,t.jsx)("span",{className:(0,et.cn)("flex h-8 w-8 shrink-0 items-center justify-center rounded-lg",m?"bg-surface-elevated text-text-tertiary":"bg-info-bg text-info"),children:(0,t.jsx)(tr,{className:"h-4 w-4"})}),(0,t.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,t.jsx)("span",{className:"text-sm font-semibold text-text-primary",children:x.tranId}),m?(0,t.jsx)(tn.default,{variant:"default",children:"Applied"}):(0,t.jsx)(tn.default,{variant:"default",children:"Payment"}),x.salesOrderNumber&&(0,t.jsxs)("span",{className:"rounded bg-surface-elevated px-1.5 py-0.5 text-[10px] font-medium text-text-muted",children:["from ",x.salesOrderNumber]}),p&&(0,t.jsx)("span",{className:"rounded bg-surface-elevated px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide text-text-muted",children:"Partial"})]}),(0,t.jsxs)("div",{className:"mt-0.5 text-xs text-text-muted",children:["Received ",(0,A.formatDate)(x.date),x.memo&&(0,t.jsxs)(t.Fragment,{children:[" · ",x.memo]})]})]}),(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[(0,t.jsxs)("div",{className:"text-right",children:[(0,t.jsx)("div",{className:(0,et.cn)("text-sm font-semibold tabular-nums",m?"text-text-muted":"text-info"),children:(0,A.formatCurrency)(m?x.amount:x.unapplied)}),p&&(0,t.jsxs)("div",{className:"text-[11px] text-text-muted",children:["of ",(0,A.formatCurrency)(x.amount)]})]}),h&&(0,t.jsx)(tl.default,{href:"/account/transactions?type=invoice",title:"Apply to an invoice",className:"rounded-md border border-border-default bg-surface px-2.5 py-1.5 text-xs font-medium text-text-primary hover:bg-surface-elevated",children:"Apply"}),(0,t.jsx)("a",{href:`${o}?action=pdf&transactionId=${x.id}&recordType=customerdeposit`,target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),title:"Download deposit PDF",className:"inline-flex h-8 w-8 items-center justify-center rounded-lg text-text-secondary hover:bg-surface-elevated hover:text-accent",children:(0,t.jsx)(l.Download,{className:"h-4 w-4"})})]})]})}function re(e,t,r=Date.now(),n={}){let s;if(!e)return null;if(e.isDelivered||"delivered"===e.status)return{kind:"delivered",date:e.deliveredDate??null};if(e.isException||"exception"===e.status)return{kind:"exception",label:e.statusDescription?.trim()||"Exception"};if(e.isOfd||"out_for_delivery"===e.status)return{kind:"out-for-delivery"};if("in_transit"===e.status||"picked_up"===e.status)return{kind:"in-transit"};if(n.lineHasArrivalEvidence)return null;if((s=(e.statusDescription||"").toLowerCase()).includes("label")||s.includes("created")||s.includes("ready")){let e=function(e,t){if(!e)return null;let r=/^(\d{4})-(\d{2})-(\d{2})/.exec(e),n=r?Date.UTC(Number(r[1]),Number(r[2])-1,Number(r[3])):Date.parse(e);return Number.isNaN(n)?null:Math.floor((t-n)/864e5)}(t,r);if(null!==e&&e>=3)return{kind:"no-carrier-scan",days:e}}return null}function rt({bundle:e,showCustomer:r,onOpenOrder:n,onOpenInvoiceLine:s,onOpenCustomer:a,onPickSuggestion:i,rowFilter:l,oorHrefForRow:o,exportRows:d,scpInboundHref:c,onScpInboundClick:u,scpDestination:x}){let m=e.item,p=e.suggestions??[],h=p.length>0;if(!m&&!h)return null;let f=l?e.rows.filter(l):e.rows,g=l?function(e){let t=0,r=0,n=0,s=0;for(let a of e)t+=a.ordered,r+=a.shipped,s+=a.amount,"cancelled"!==a.status&&(n+=Math.max(0,a.ordered-a.shipped));return{orders:new Set(e.map(e=>
81e.orderId)).size,ordered:t,shipped:r,openToShip:n,amount:s}}(f):e.totals,b=r?8:7;return(0,t.jsxs)("div",{className:"overflow-hidden rounded-xl border border-border-default bg-surface-elevated",children:[(0,t.jsx)("div",{className:"h-[3px] bg-accent"}),m?(0,t.jsxs)("div",{className:"flex items-start gap-4 px-4 pb-3 pt-4",children:[(0,t.jsx)(rs,{sku:m.sku,imageUrl:m.imageUrl}),(0,t.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,t.jsx)("div",{className:"text-[10px] font-semibold uppercase tracking-wider text-text-tertiary",children:h?"Product family":"Item match"}),(0,t.jsx)("div",{className:"font-mono text-[15px] font-semibold text-text-primary",children:m.sku}),m.name&&(0,t.jsx)("div",{className:"mt-0.5 truncate text-[13px] text-text-secondary",children:m.name}),(0,t.jsxs)("div",{className:"mt-1.5 flex flex-wrap items-center gap-2",children:[m.brand&&(0,t.jsx)("span",{className:"inline-flex items-center rounded-full border border-border-subtle bg-surface px-2 py-0.5 text-[10px] font-bold uppercase tracking-wide text-text-secondary",children:m.brand}),m.upc&&(0,t.jsxs)("span",{className:"font-mono text-[10.5px] text-text-tertiary",children:["UPC ",m.upc]})]})]}),d&&f.length>0&&(0,t.jsxs)("button",{type:"button",onClick:()=>d(f,m,r),title:`Download ${f.length.toLocaleString("en-US")} line(s) as Excel (.xlsx)`,className:"inline-flex flex-none items-center gap-1.5 self-start rounded-lg border border-border-default bg-surface px-2.5 py-1.5 text-[11px] font-semibold text-text-secondary transition-colors hover:bg-surface-elevated hover:text-text-primary",children:[(0,t.jsx)(O,{className:"h-4 w-4"}),"Excel"]})]}):(0,t.jsxs)("div",{className:"px-4 pb-1 pt-4",children:[(0,t.jsx)("div",{className:"text-[10px] font-semibold uppercase tracking-wider text-text-tertiary",children:"Multiple matches"}),(0,t.jsx)("div",{className:"mt-0.5 text-[13px] text-text-secondary",children:"Pick the exact SKU to see its full order & shipment history."})]}),h?(0,t.jsx)(rr,{suggestions:p,onPick:i}):(0,t.jsx)(rn,{showCustomer:r,colCount:b,rows:f,totals:g,item:m,onOpenOrder:n,onOpenInvoiceLine:s,onOpenCustomer:a,oorHrefForRow:o,scpInboundHref:c,onScpInboundClick:u,scpDestination:x})]})}function rr({suggestions:e,onPick:r}){return(0,t.jsxs)("div",{className:"px-4 pb-4 pt-1.5",children:[(0,t.jsx)("div",{className:"mb-2 text-[10px] font-semibold uppercase tracking-wider text-text-tertiary",children:"Did you mean â pick a variant"}),(0,t.jsx)("div",{className:"flex flex-wrap gap-2",children:e.map(e=>{let n=function(e){let t=e.name.lastIndexOf(" - ");if(t>=0){let r=e.name.slice(t+3).trim();if(r)return r}let r=e.sku.split("-");return r.length>1?r[r.length-1]:""}(e);return(0,t.jsxs)("button",{type:"button",onClick:()=>r?.(e.sku),disabled:!r,title:e.name||e.sku,className:"group inline-flex max-w-full items-center gap-2 rounded-lg border border-border-default bg-surface px-2.5 py-1.5 text-left transition-colors hover:border-accent hover:bg-accent-bg disabled:cursor-default disabled:opacity-70",children:[(0,t.jsx)("span",{className:"font-mono text-[12px] font-semibold text-text-primary group-hover:text-accent",children:e.sku}),n&&(0,t.jsx)("span",{className:"max-w-[160px] truncate text-[11px] text-text-tertiary",children:n})]},e.sku)})})]})}function rn({showCustomer:e,colCount:r,rows:n,totals:s,item:a,onOpenOrder:i,onOpenInvoiceLine:l,onOpenCustomer:o,oorHrefForRow:d,scpInboundHref:c,onScpInboundClick:u,scpDestination:x}){return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"flex flex-wrap gap-x-6 gap-y-2 px-4 pb-1",children:[(0,t.jsx)(ra,{label:"Orders",value:s.orders,sub:e?"all customers":n[0]?.customerName||void 0}),(0,t.jsx)(ra,{label:"Units ordered",value:s.ordered}),(0,t.jsx)(ra,{label:"Units shipped",value:s.shipped}),(0,t.jsx)(ra,{label:"Still to ship",value:s.openToShip,warn:s.openToShip>0})]}),(0,t.jsx)("div",{className:"px-3 pb-3 pt-1.5",children:0===n.length?(0,t.jsx)("div",{className:"px-2 py-6 text-center text-xs text-text-tertiary",children:"No orders for this item in this view."}):(0,t.jsx)("div",{className:"-mx-1 overflow-x-auto",children:(0,t.jsxs)("table",{className:"w-full min-w-[640px] text-[12.5px]",children:[(0,t.jsx)("thead",{children:(0,t.jsxs)("tr",{className:"border-b border-border-default text-left text-[10px] font-medium uppercase tracking-wider text-text-tertiary",children:[(0,t.jsx)("th",{className:"px-2.5 py-2 font-medium",children:"SO #"}),e&&(0,t.jsx)("th",{className:"px-2.5 py-2 font-medium",children:"Customer"}),(0,t.jsx)("th",{className:"px-2.5 py-2 font-medium",children:"Item"}),(0,t.jsx)("th",{className:"px-2.5 py-2 text-center font-medium",children:"Ordered"}),(0,t.jsx)("th",{className:"px-2.5 py-2 text-center font-medium",children:"Shipped"}),(0,t.jsx)("th",{className:"px-2.5 py-2 text-right font-medium",children:"Rate"}),(0,t.jsx)("th",{className:"px-2.5 py-2 text-right font-medium",children:"Amount"}),(0,t.jsx)("th",{className:"px-2.5 py-2","aria-label":"Tracking"}),(0,t.jsx)("th",{className:"px-2.5 py-2 font-medium",children:"Status"})]})}),(0,t.jsx)("tbody",{children:n.map(r=>(0,t.jsx)(ri,{row:r,itemSku:a.sku,itemDesc:a.name,showCustomer:e,onOpenOrder:i,onOpenInvoiceLine:l,onOpenCustomer:o,oorHrefForRow:d,scpHref:c?.(r)??null,onScpClick:u,scpDest:x?.(r)??null},`${r.orderId}-${r.lineId}`))}),n.length>0&&(0,t.jsx)("tfoot",{children:(0,t.jsxs)("tr",{className:"border-t border-border-subtle text-text-tertiary",children:[(0,t.jsx)("td",{colSpan:r-3,className:"px-2.5 py-2 text-right",children:"Totals"}),(0,t.jsx)("td",{className:"px-2.5 py-2 text-center font-semibold tabular-nums text-text-primary",children:s.ordered.toLocaleStr
81ing("en-US")}),(0,t.jsx)("td",{className:"px-2.5 py-2 text-center font-semibold tabular-nums text-text-primary",children:s.shipped.toLocaleString("en-US")}),(0,t.jsx)("td",{}),(0,t.jsx)("td",{className:"px-2.5 py-2 text-right font-semibold tabular-nums text-text-primary",children:(0,A.formatCurrency)(s.amount)}),(0,t.jsx)("td",{}),(0,t.jsx)("td",{})]})})]})})})]})}function rs({sku:e,imageUrl:r}){if(r)return(0,t.jsx)("div",{className:"flex h-[60px] w-[60px] flex-none items-center justify-center overflow-hidden rounded-lg border border-border-subtle bg-white",children:(0,t.jsx)("img",{src:r,alt:e,className:"h-full w-full object-contain",loading:"lazy"})});let n=(e.split("-")[0]||e).slice(0,4).toUpperCase();return(0,t.jsx)("div",{className:"flex h-[60px] w-[60px] flex-none items-center justify-center rounded-lg border border-border-subtle bg-accent-bg text-[11px] font-bold tracking-wide text-accent",children:n})}function ra({label:e,value:r,sub:n,warn:s}){return(0,t.jsxs)("div",{className:"border-r border-border-subtle pr-6 last:border-r-0 last:pr-0",children:[(0,t.jsx)("div",{className:"text-[10px] font-semibold uppercase tracking-wide text-text-tertiary",children:e}),(0,t.jsx)("div",{className:`text-lg font-bold tabular-nums ${s?"text-warning":"text-text-primary"}`,children:r.toLocaleString("en-US")}),n&&(0,t.jsx)("div",{className:"text-[11px] text-text-tertiary",children:n})]})}function ri({row:e,itemSku:r,itemDesc:n,showCustomer:s,onOpenOrder:a,onOpenInvoiceLine:i,onOpenCustomer:l,oorHrefForRow:o,scpHref:d,onScpClick:c,scpDest:u}){let x=e.fulfillments??[],m=e.shipped>0&&(x.length>0||e.trackingNumbers&&e.trackingNumbers.length>0);return(0,t.jsxs)("tr",{className:"border-b border-border-subtle/60 hover:bg-surface",children:[(0,t.jsxs)("td",{className:"px-2.5 py-2.5 align-middle",children:[(0,t.jsx)("button",{type:"button",onClick:()=>a(e.orderId),title:`Open ${e.orderNumber}`,className:"font-mono text-[12.5px] font-semibold text-accent hover:underline",children:e.orderNumber}),e.poNumber&&e.poNumber.trim()&&(0,t.jsx)("div",{className:"truncate text-[10.5px] text-text-tertiary",title:`Customer PO ${e.poNumber}`,children:(0,A.formatPoNumber)(e.poNumber,{withLabel:!0})}),(0,t.jsx)("div",{className:"text-[11px] text-text-tertiary",children:(0,A.formatDate)(e.orderDate)})]}),s&&(0,t.jsx)("td",{className:"px-2.5 py-2.5 align-middle text-xs",children:e.customerName?(0,t.jsx)("button",{type:"button",onClick:()=>l(e.customerId,e.orderId,e.itemId),title:`Open ${e.customerName} â ${e.orderNumber}, line highlighted`,className:"text-left text-accent hover:underline",children:e.customerName}):(0,t.jsx)("span",{className:"text-text-muted",children:"â"})}),(0,t.jsxs)("td",{className:"px-2.5 py-2.5 align-middle",children:[(0,t.jsxs)("div",{className:"flex items-center",children:[(0,t.jsx)(M,{fallbackOrigin:e.origin??void 0}),(0,t.jsx)("span",{className:"font-mono text-[11px] text-text-secondary",children:r})]}),e.bpn&&(0,t.jsxs)("div",{className:"mt-0.5 font-mono text-[10px] font-semibold",style:{color:"#7c3aed"},children:["BPN: ",e.bpn]}),(e.description||n)&&(0,t.jsx)("div",{className:"mt-0.5 text-[11px] text-text-tertiary",children:e.description||n})]}),(0,t.jsx)("td",{className:"px-2.5 py-2.5 text-center align-middle tabular-nums text-text-secondary",children:e.ordered}),(0,t.jsx)("td",{className:"px-2.5 py-2.5 text-center align-middle tabular-nums",children:(0,t.jsx)(rl,{row:e,onOpenInvoiceLine:i,oorHrefForRow:o})}),(0,t.jsx)("td",{className:"px-2.5 py-2.5 text-right align-middle tabular-nums text-text-secondary",children:(0,A.formatCurrency)(e.rate)}),(0,t.jsx)("td",{className:"px-2.5 py-2.5 text-right align-middle font-medium tabular-nums",children:(0,A.formatCurrency)(e.amount)}),(0,t.jsx)("td",{className:"px-2.5 py-2.5 text-center align-middle",children:m?(0,t.jsx)(ei,{shipments:x.length>0?x.map(t=>(function(e,t){let r=e.qty??void 0,{cartons:n,cartonsApprox:s}=eq(r,e.unitsPerMaster);return{ref:e.ref,qty:r,cartons:n,cartonsApprox:s,trackingNumbers:e.trackingNumbers??[],carrier:e.carrier??void 0,status:e.status??void 0,deliveryDate:e.deliveryDate??void 0,deliveryEvidence:e.deliveryEvidence,date:e.date,containerRef:e.containerRef??void 0,containerTracking:e.containerTracking,containerEta:e.containerEta??void 0,containerDelivered:e.containerDelivered,containerArrived:e.containerArrived??void 0,inboundShipmentId:e.inboundShipmentId,mode:e.inboundMode,sku:t}})(t,e.sku)):[{ref:e.invoiceNumber??e.orderNumber,qty:e.shipped,trackingNumbers:e.trackingNumbers,carrier:e.carrier??void 0,date:e.shipDate}]}):(0,t.jsx)("span",{className:"inline-flex p-0.5 text-text-muted opacity-40",title:"Tracking pending",children:(0,t.jsx)(F.Tru
81ck,{className:"h-[15px] w-[15px]"})})}),(0,t.jsx)("td",{className:"px-2.5 py-2.5 align-middle",children:(0,t.jsx)(rc,{row:e,scpHref:d,onScpClick:c,scpDest:u})})]})}function rl({row:e,onOpenInvoiceLine:r,oorHrefForRow:n}){if(e.shipped>0&&e.invoiceId)return(0,t.jsx)("button",{type:"button",onClick:()=>r(e.orderId,e.invoiceNumber,e.itemId),title:`Open ${e.invoiceNumber??"invoice"} \xb7 line`,className:"font-semibold text-accent hover:underline",children:e.shipped});if("cancelled"===e.status)return(0,t.jsx)("span",{className:"text-text-muted",children:"â"});let s=0===e.shipped?n?.(e)??null:null;return s?(0,t.jsx)("a",{href:s,target:"_blank",rel:"noopener noreferrer",title:"Open this open line in the OOR (Order Fulfillment Tracker)",className:"font-semibold text-accent hover:underline",children:e.shipped}):(0,t.jsx)("span",{className:"text-text-muted",children:e.shipped})}function ro(e){if(!e)return"";let t=/^(\d{4})-(\d{2})-(\d{2})/.exec(e);if(!t)return"";let r=new Date(Date.UTC(Number(t[1]),Number(t[2])-1,Number(t[3])));return Number.isNaN(r.getTime())?"":r.toLocaleDateString("en-US",{month:"short",day:"numeric",timeZone:"UTC"})}e.s(["RotateCcw",0,t9],490108);let rd="inline-flex items-center gap-1.5 whitespace-nowrap rounded-full px-2.5 py-1 text-[10.5px] font-semibold";function rc({row:e,scpHref:r,onScpClick:n,scpDest:s}){let a=(e.trackingNumbers||[]).find(e=>e&&e.length>=5)||"",i="cancelled"!==e.status&&e.ordered>0&&e.shipped>=e.ordered&&(0,H.isUpsShipment)(e.carrier,a)&&(0,H.isWithinUpsTrackingWindow)(e.shipDate),{data:l}=(0,H.useUpsTracking)(i?a:null,i),o=(e.fulfillments??[]).some(e=>!0===e.containerDelivered||!!e.containerArrived||(e.status||"").toLowerCase().includes("delivered")),d=function(e){let t;if(e.deliveryLegs?.length){let t=e.deliveryLegs.map(t=>{let r=new Date(e.nowMs??Date.now()).toISOString().slice(0,10);return e.trackingNumber&&t.trackingNumbers?.includes(e.trackingNumber)&&e.live?.deliveryState?"delivered"===e.live.deliveryState?{state:"delivered",label:"Delivered",date:e.live.deliveredDate??void 0}:"partially-delivered"===e.live.deliveryState?{state:"partially-delivered",label:"Partially delivered"}:J({...t,deliveryEvidence:void 0,status:e.live.statusDescription,upsTrackingStatus:e.live.statusDescription,containerDelivered:!1},r):J(t,r)});if(e.morePending&&t.some(e=>"delivered"===e.state))return{kind:"partially-delivered"};if(t.every(e=>"delivered"===e.state))return{kind:"delivered",date:t.every(e=>!!e.date)?t.map(e=>e.date).sort().at(-1):null};if(t.some(e=>["delivered","partially-delivered"].includes(e.state)))return{kind:"partially-delivered"};let r=t.find(e=>"exception"===e.state);if(r)return{kind:"exception",label:r.label};if(e.deliveryLegs.some(e=>e.deliveryEvidence?.packages.some(e=>!!e.evidence)))return t.some(e=>"out-for-delivery"===e.state)?{kind:"out-for-delivery"}:t.some(e=>"in-transit"===e.state)?{kind:"in-transit"}:{kind:"shipped"};let n=re(e.live,e.shipDate,e.nowMs??Date.now());return n?.kind==="delivered"&&t.length>1?{kind:"partially-delivered"}:n}let r=(t=(e.nsShipStatus||"").trim(),!/sender|shipper|return/i.test(t)&&/^(?:delivered|delivered\s+(?:on|at|to)\b[^\n]*)$/i.test(t)),n=re(e.live,e.shipDate,e.nowMs??Date.now(),{lineHasArrivalEvidence:e.lineHasArrivalEvidence||r});return r?n?.kind==="delivered"?n:{kind:"delivered",date:null}:n}({trackingNumber:a,morePending:e.shipped<e.ordered,deliveryLegs:(e.fulfillments??[]).map(e=>({...e,status:e.status,deliveryEvidence:e.deliveryEvidence})),live:l,nsShipStatus:e.nsShipStatus,shipDate:e.shipDate,lineHasArrivalEvidence:o});return(0,t.jsxs)("div",{className:"flex flex-col items-start gap-1",children:[(0,t.jsx)(rp,{row:e,live:l,verdict:d}),(e.airQty??0)>0&&(0,t.jsx)(ru,{qty:e.airQty}),(0,t.jsx)(rm,{row:e}),(0,t.jsx)(rx,{row:e,href:r,onClick:n,dest:s})]})}function ru({qty:e}){return(0,t.jsxs)("span",{className:"inline-flex items-center gap-1 whitespace-nowrap text-[10px] font-medium text-warning",title:"Air freight units",children:["â Air ·"," ",(0,t.jsx)("span",{className:"font-mono tabular-nums",children:e.toLocaleString("en-US")})]})}function rx({row:e,href:r,onClick:n,dest:s}){var a;if(!e.scpInTransit||!e.scpEta)return null;let i="inline-flex items-center gap-1 whitespace-nowrap text-[10px] font-medium text-info",l=(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(F.Tru
81ck,{className:"h-[11px] w-[11px]"}),"In transit to ",s||"SCP"," · ETA ",(0,A.formatDate)(e.scpEta)]}),o=(a={hasClick:!!n,hasHref:!!r,scpBol:e.scpBol}).hasClick?"button":a.hasHref&&a.scpBol?"link":"text";return"button"===o&&n?(0,t.jsx)("button",{type:"button",onClick:()=>n(e),title:`View in-transit inventory for ${e.sku}`,className:`${i} hover:underline`,children:l}):"link"===o&&r?(0,t.jsx)("a",{href:r,target:"_blank",rel:"noopener noreferrer",title:`View inbound shipment${e.scpBol?` ${e.scpBol}`:""}`,className:`${i} hover:underline`,children:l}):(0,t.jsx)("span",{className:i,children:l})}function rm({row:e}){if(("pending"===e.status||"partial"===e.status)&&e.esd){let r=Math.max(0,e.ordered-e.shipped);return(0,t.jsxs)("span",{className:"whitespace-nowrap text-[10px] text-text-tertiary",children:["ESD ",(0,A.formatDate)(e.esd),r>0&&(0,t.jsxs)(t.Fragment,{children:[" · ",(0,t.jsx)("span",{className:"font-semibold tabular-nums",children:r.toLocaleString("en-US")})," ","to ship"]})]})}return"intransit"===e.status&&e.expectedDelivery?(0,t.jsxs)("span",{className:"whitespace-nowrap text-[10px] text-text-tertiary",children:["Delivers ",(0,A.formatDate)(e.expectedDelivery)]}):null}function rp({row:e,live:r,verdict:n}){if(n)return(0,t.jsx)(rh,{verdict:n,live:r});switch(e.status){case"shipped":return(0,t.jsxs)("span",{className:`${rd} bg-success-bg text-success`,children:[(0,t.jsx)(rf,{}),"Shipped ",ro(e.shipDate)]});case"intransit":return(0,t.jsxs)("span",{className:"inline-flex flex-wrap items-center gap-1.5",children:[(0,t.jsxs)("span",{className:`${rd} bg-info-bg text-info`,children:[(0,t.jsx)("span",{className:"h-1.5 w-1.5 rounded-full bg-info"}),"In Transit"]}),(0,t.jsx)(rg,{live:r})]});case"partial":return(0,t.jsxs)("span",{className:`${rd} bg-warning-bg text-warning`,children:[(0,t.jsx)(F.Truck,{className:"h-[11px] w-[11px]"}),"Partial · ",e.shipped,"/",e.ordered]});case"pending":return(0,t.jsxs)("span",{className:`${rd} border border-border-subtle bg-surface text-text-secondary`,children:[(0,t.jsx)("span",{className:"h-1.5 w-1.5 rounded-full bg-warning"}),"Pending shipment"]});case"cancelled":return(0,t.jsx)("span",{className:`${rd} bg-error-bg text-error`,children:"Cancelled"});default:return null}}function rh({verdict:e,live:r}){switch(e.kind){case"partially-delivered":case"shipped":return(0,t.jsx)("span",{className:`${rd} bg-info-bg text-info`,children:"shipped"===e.kind?"Shipped":"Partially delivered"});case"delivered":var n;let s;return(0,t.jsxs)("span",{className:`${rd} bg-success-bg text-success`,title:r?.signedBy?`Signed for by ${r.signedBy}`:void 0,children:[(0,t.jsx)(rf,{}),"Delivered ",(n=e.date,(s=/^(d{4})(d{2})(d{2})$/.exec((n||"").trim()))?ro(`${s[1]}-${s[2]}-${s[3]}`):ro(n))]});case"out-for-delivery":return(0,t.jsxs)("span",{className:`${rd} bg-info-bg text-info`,children:[(0,t.jsx)(F.Truck,{className:"h-[11px] w-[11px]"}),"Out for delivery"]});case"in-transit":return(0,t.jsxs)("span",{className:`${rd} bg-info-bg text-info`,children:[(0,t.jsx)("span",{className:"h-1.5 w-1.5 rounded-full bg-info"}),"In Transit"]});case"exception":return(0,t.jsx)("span",{className:`${rd} bg-error-bg text-error`,title:e.label,children:e.label});case"no-carrier-scan":return(0,t.jsxs)("span",{className:`${rd} bg-warning-bg text-warning`,title:"A label exists but the carrier has never scanned it â the goods may not have been collected",children:[(0,t.jsx)("span",{className:"h-1.5 w-1.5 rounded-full bg-warning"}),"Not picked up · ",e.days,"d"]})}}function rf(){return(0,t.jsx)("svg",{className:"h-[11px] w-[11px]",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:3,children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})})}function rg({live:e}){let r=function(e){if(!e)return null;let t=e.split("/");if(3!==t.length)return null;let[r,n,s]=t.map(e=>parseInt(e,10));if(![r,n,s].every(Number.isFinite))return null;let a=new Date(Date.UTC(s,r-1,n));if(Number.isNaN(a.getTime()))return null;let i=new Date(`${(0,A.businessToday)()}T00:00:00.000Z`),l=Math.round((a.getTime()-i.getTime())/864e5);
81return l<0?null:0===l?"today":1===l?"tomorrow":l<=7?`in ${l} days`:a.toLocaleDateString("en-US",{month:"short",day:"numeric",timeZone:"UTC"})}(e?.estimatedDelivery??null);return r?(0,t.jsxs)("span",{className:`${rd} border border-border-subtle bg-surface text-text-secondary`,children:[(0,t.jsx)("svg",{className:"h-[11px] w-[11px] text-text-tertiary",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"})}),"Delivers ",r]}):null}function rb(e){let t=(e??"").trim();return!(t.length<3||/\s/.test(t)||t.includes(",")||/^so\d/i.test(t)||/^inv\d/i.test(t)||/^1z/i.test(t)||/^\d{12,}$/.test(t))}function ry(e){let t=(e??"").split(",").map(e=>e.trim()).filter(Boolean),r=[],n=new Set;for(let e of t){if(!rb(e))continue;let t=e.toLowerCase();if(!n.has(t)&&(n.add(t),r.push(e),r.length>=500))break}return r}function rv(e,t,r=500){let n=new Set(t.map(e=>e.trim().toLowerCase()).filter(Boolean));if(0===n.size)return[];let s=new Map;for(let t of e)for(let e of t.lines??[]){let t=(e.externalId??"").trim();if(!t)continue;let r=t.toLowerCase();!s.has(r)&&(e.phoneModels??[]).some(e=>n.has(e.trim().toLowerCase()))&&s.set(r,t)}return Array.from(s.values()).sort((e,t)=>e.localeCompare(t)).slice(0,r)}function rj({options:e,selected:n,onChange:s,allLabel:a="All phone models"}){let[i,l]=(0,r.useState)(!1),[o,d]=(0,r.useState)(""),[c,u]=(0,r.useState)(n),x=(0,r.useRef)(n),m=(0,r.useRef)(null),p=(0,r.useRef)(null),h=e=>[...e].map(e=>e.toLowerCase()).sort().join(" "),f=h(n),g=(0,r.useCallback)(e=>{s(Array.from(new Set(e.map(e=>e.trim()).filter(Boolean))))},[s]),b=(0,r.useCallback)(()=>{l(!1),d("");let e=x.current;h(e)!==f&&g(e)},[g,f]);(0,r.useEffect)(()=>{if(i)return document.addEventListener("mousedown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t)};function e(e){m.current&&!m.current.contains(e.target)&&b()}function t(e){"Escape"===e.key&&b()}},[i,b]);let y=(0,r.useMemo)(()=>
81{let t=o.trim().toLowerCase(),r=t?e.filter(e=>e.toLowerCase().includes(t)):e,n=new Set(c.map(e=>e.toLowerCase()));return[...r].sort((e,t)=>{let r=+!n.has(e.toLowerCase()),s=+!n.has(t.toLowerCase());return r!==s?r-s:e.localeCompare(t)})},[e,o,c]),v=n.length,j=0===v?a:1===v?n[0]:`${v} models`;return(0,t.jsxs)("div",{ref:m,className:"relative",children:[(0,t.jsxs)("button",{type:"button",onClick:()=>i?b():void(x.current=n,u(n),d(""),l(!0),requestAnimationFrame(()=>p.current?.focus())),"aria-haspopup":"listbox","aria-expanded":i,"aria-label":"Phone model",title:v>0?n.join(", "):"Filter by phone model",className:"flex w-full items-center gap-1.5 rounded-lg border bg-surface px-3 py-2 text-sm text-text-primary transition-colors focus:outline-none focus:ring-1 focus:ring-accent "+(v>0?"border-accent text-accent":"border-border-default hover:border-accent"),children:[(0,t.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",className:"shrink-0 text-text-tertiary",children:[(0,t.jsx)("rect",{x:"7",y:"2",width:"10",height:"20",rx:"2"}),(0,t.jsx)("path",{d:"M11 18h2"})]}),(0,t.jsx)("span",{className:"flex-1 truncate text-left",children:j}),v>0?(0,t.jsx)("span",{className:"inline-flex h-4 min-w-4 items-center justify-center rounded-full bg-accent px-1 font-mono text-[10px] font-bold text-accent-foreground",children:v}):null,(0,t.jsx)("svg",{width:"9",height:"9",viewBox:"0 0 9 9",fill:"none",stroke:"currentColor",strokeWidth:"1.4","aria-hidden":"true",className:"shrink-0 text-text-tertiary",children:(0,t.jsx)("path",{d:"M2 3.5l2.5 2L7 3.5"})})]}),i?(0,t.jsxs)("div",{role:"listbox","aria-multiselectable":"true",className:"absolute left-0 z-50 mt-1 w-[280px] max-w-[calc(100vw-2rem)] rounded-lg border border-border-default bg-surface-elevated shadow-lg",children:[(0,t.jsx)("div",{className:"border-b border-border-subtle p-2",children:(0,t.jsx)("input",{ref:p,type:"text",value:o,onChange:e=>d(e.target.value),placeholder:"Search modelsâ¦","aria-label":"Search phone models",className:"w-full rounded-md border border-border-default bg-surface px-2.5 py-1.5 text-sm text-text-primary placeholder:text-text-tertiary focus:outline-none focus:ring-1 focus:ring-accent"})}),(0,t.jsx)("div",{className:"max-h-72 overflow-y-auto py-1",children:0===y.length?(0,t.jsx)("p",{className:"px-3 py-4 text-center text-sm text-text-tertiary",children:"No models match."}):y.map(e=>{let r=c.some(t=>t.toLowerCase()===e.toLowerCase());return(0,t.jsxs)("label",{className:"flex cursor-pointer items-center gap-2 px-3 py-1.5 text-sm text-text-primary hover:bg-surface",children:[(0,t.jsx)("input",{type:"checkbox",checked:r,onChange:()=>{let t,r;return r=(t=x.current).includes(e)?t.filter(t=>t!==e):[...t,e],void(x.current=r,u(r))},className:"h-4 w-4 shrink-0 rounded-[4px] accent-accent"}),(0,t.jsx)("span",{className:"truncate",children:e})]},e)})}),(0,t.jsxs)("div",{className:"flex items-center justify-between gap-2 border-t border-border-subtle p-2",children:[(0,t.jsx)("span",{className:"text-xs text-text-tertiary",children:c.length>0?`${c.length} selected`:"None selected"}),(0,t.jsxs)("div",{className:"flex items-center gap-1.5",children:[c.length>0?(0,t.jsx)("button",{type:"button",onClick:()=>{x.current=[],u([]),g([]),l(!1),d("")},className:"rounded-md px-2 py-1 text-xs text-text-secondary hover:text-text-primary",children:"Clear all"}):null,(0,t.jsx)("button",{type:"button",onClick:b,className:"rounded-md bg-accent px-3 py-1 text-xs font-medium text-accent-foreground hover:opacity-90",children:"Apply"})]})]})]}):null]})}e.s(["default",0,rt],284864),e.s(["deriveSkusForPhoneModels",0,rv,"isItemLookupQuery",0,rb,"parseItemLookupTokens",0,ry],867074);let rN=[{value:"",label:"All Statuses"},{value:"SalesOrd:B",label:"Pending Fulfillment"},{value:"SalesOrd:D",label:"Partially Fulfilled"},{value:"SalesOrd:G",label:"Billed"},{value:"SalesOrd:C",label:"Cancelled"}];function rw(e,t){let r=t.toString();if("self"===e.kind)return r?`/api/customer/activity?${r}`:"/api/customer/activity";if("customer-set"===e.kind){let t=e.apiBase??"/api/admin/inventory/orders",n=`${t}/activity-bundle?scopeKey=${encodeURIComponent(e.scopeKey)}`;return r?`${n}&${r}`:n}let n=`/api/portal/team/sales/customers/${e.customerId}
81/activity-bundle`;return r?`${n}?${r}`:n}function rk(e,t){let r=t.toString();if("self"===e.kind)return r?`/api/customer/orders?${r}`:"/api/customer/orders";if("customer-set"===e.kind){let t=`${e.apiBase??"/api/admin/inventory/orders"}/detail`;return r?`${t}?${r}`:t}let n=`/api/portal/team/sales/customers/${e.customerId}/orders`;return r?`${n}?${r}`:n}e.s(["default",0,function({scope:e,permissions:a,title:x,subtitle:m,embedded:p=!1,collapseOrdersTo:h,canPayInvoices:f,modernXlsxEnabled:g,onPayInvoice:y,loadModernXlsxExporter:v,cart:j,approval:N,renderLineExtras:w,oorLinkBase:S,balanceChipSlot:C,exportItemRows:I,exportTrackingRows:D,scpInboundHref:T,onScpInboundClick:P,scpDestination:L,batchPaste:E,initialBundle:O}){var M;let U=(0,n.useRouter)(),R=(0,n.useSearchParams)(),F="self"===e.kind?"/account/activity":"customer-set"===e.kind?e.pagePath:`/sales/customers/${e.customerId}`,q=g??!1,B=v??null,_="v4"===a.layout&&"self"===e.kind&&!p,z=R.get("view")||"all",[H,W]=(0,r.useState)(z),K=R.get("type")||"all",[V,Q]=(0,r.useState)(K),X=R.get("status")||"",Z=R.get("dateFrom")||"",G=R.get("dateTo")||"",Y="customer-set"===e.kind?"customer-set:static":`${X}|${Z}|${G}`,J=R.get("search")||"",ee=R.get("order")||"",et=R.get("expand")||"",er=R.get("invoice")||"",en=R.get("line")||"",es=R.toString();(0,r.useEffect)(()=>{let e=R.get("view")||"all";e!==H&&W(e);let t=R.get("type")||"all";t!==V&&Q(t)},[es]);let[ea,ei]=(0,r.useState)(J),el=(0,r.useRef)(new Set);(0,r.useEffect)(()=>{el.current.delete(J)||(el.current.clear(),ei(J))},[J]);let ed="customer-set"===e.kind,ec="customer-set"===e.kind&&!!e.singleCompany,eu=ed&&!ec,[ex,ek]=(0,r.useState)(""),[eP,eL]=(0,r.useState)([]),[eE,eU]=(0,r.useState)([]),[eR,eF]=(0,r.useState)(25),eq=(0,r.useRef)(null),eB="customer-set"===e.kind?`${e.apiBase??""}|${e.scopeKey}`:"customer"===e.kind?String(e.customerId):"self",[e_,ez]=(0,r.useState)({bundle:null,loading:!1,error:null}),eK=(0,r.useRef)(null),eV=(0,r.useMemo)(()=>{let e=ea.trim();return!function(e){let t=(e??"").trim();if(!t||t.includes(",")||ey.test(t))return!1;let r=(t??"").replace(/[â-â]/g,"").replace(/[\s-]/g,"").toUpperCase();return!(r.length<8)&&(em.test(r)||ep.test(r)||eh.test(r)||ef.test(r)||eg.test(r)||eb.test(r))}(e)?"":e},[ea]);function eX(){ei(""),el.current.add("");let e=new URLSearchParams(R.toString());e.delete("search"),e.delete("order"),e.delete("invoice");let t=e.toString();U.replace(t?`${F}?${t}`:F,{scroll:!1})}(0,r.useEffect)(()=>{if(ea===J)return;let e=setTimeout(()=>{let e=new URLSearchParams(R.toString());ea?e.set("search",ea):e.delete("search"),e.delete("order"),e.delete("invoice"),el.current.add(ea),U.replace(`${F}?${e.toString()}`,{scroll:!1})},300);return()=>clearTimeout(e)},[ea]);let[e0,e4]=(0,r.useState)(()=>O?.orders?.orders??[]),[e8,e6]=(0,r.useState)(()=>O?.invoices?.invoices??[]),[e9,e7]=(0,r.useState)(()=>O?.invoices?.summary?.aging??null),[te,tt]=(0,r.useState)(()=>O?.invoices?.consolidated??null),[tr,tn]=(0,r.useState)(()=>O?.refunds?.refunds??[]),[ts,ta]=(0,r.useState)(()=>O?.payments?.payments??[]),[ti,tl]=(0,r.useState)(()=>O?.credits?.credits??[]),[to,td]=(0,r.useState)(()=>O?.credits?.deposits??[]),[tc,tu]=(0,r.useState)(()=>!O),[tx,tm]=(0,r.useState)(!1),[tp,th]=(0,r.useState)(!1);(0,r.useEffect)(()=>{if(tc||!tx||tp)return;let e=setTimeout(()=>th(!0),2e3);return()=>clearTimeout(e)},[tc,tx,tp]);let[tf,tg]=(0,r.useState)([]),[tb,ty]=(0,r.useState)(null),tv=(0,r.useRef)(0),[tj,tN]=(0,r.useState)(null),[tw,tk]=(0,r.useState)(1),[tS,tC]=(0,r.useState)(()=>O?.orders?.total??O?.orders?.orders?.length??0),[t$,tI]=(0,r.useState)(!1),[tD,tT]=(0,r.useState)(!1),tP=(0,r.useRef)(new Set),[tL,tE]=(0,r.useState)(!1),[tO,tA]=(0,r.useState)(()=>new Set),[tM,tU]=(0,r.useState)({}),[tR,tF]=(0,r.useState)(null),tq="bw_activity_standalone_expanded",[tB,t_]=(0,r.useState)(!1);(0,r.useEffect)(()=>{try{let e=sessionStorage.getItem(tq);"1"===e&&t_(!0)}catch{}},[]);let tz=(0,r.useCallback)(()=>{t_(e=>{let t=!e;try{sessionStorage.setItem(tq,t?"1":"0")}catch{}return t})},[]),tH=(0,r.useRef)({}),tW=(0,r.useRef)(!1),tK=(0,r.useMemo)(()=>ry(ea.trim()),[ea]),tV=(0,r.useMemo)(()=>"customer-set"!==e.kind||0===eP.length||tK.length>0?[]:rv(e0,eP),[e.kind,eP,tK.length,e0]),tQ=tK.length>0?tK:tV,tX=tQ.join("\n");(0,r.useEffect)(()=>{eq.current?.abort();let t=new AbortController;eq.current=t;let r=null,n=setTimeout(()=>{if(0===tQ.length)return void eU([]);let n=tQ.length>1;eU(e=>{let t=new Map(e.map(e=>[e.token.toLowerCase(),e.bundle])),r=1===tQ.length&&1===e.length;return tQ.map(n=>({token:n,bundle:t.get(n.toLowerCase())??(r?e[0].bundle:null),loading:!0}))}),eF(25);let s=new Map,a=()=>
81{if(r=null,t.signal.aborted||0===s.size)return;let e=new Map(s);s.clear(),eU(t=>t.map(t=>{let r=t.token.toLowerCase();return e.has(r)?{token:t.token,bundle:e.get(r)??null,loading:!1}:t}))},i=()=>{null==r&&(r=setTimeout(a,120))},l=async r=>{try{let a=await fetch(function(e,t){let r=encodeURIComponent(t);if("self"===e.kind)return`/api/customer/item-activity?q=${r}`;if("customer-set"===e.kind){let t=e.apiBase??"/api/admin/inventory/orders";return`${t}/item-activity?scopeKey=${encodeURIComponent(e.scopeKey)}&q=${r}`}return`/api/portal/team/sales/customers/${e.customerId}/item-activity?q=${r}`}(e,r),{signal:t.signal}),l=a.ok?await a.json():null,o=l?.data??l??null;if(t.signal.aborted)return;let d=n?!!o?.item:!!o?.item||(o?.suggestions?.length??0)>0;s.set(r.toLowerCase(),d?o:null),i()}catch(e){if(e?.name==="AbortError")return;s.set(r.toLowerCase(),null),i()}},o=0,d=async()=>{for(;!t.signal.aborted;){let e=o++;if(e>=tQ.length)return;await l(tQ[e])}};for(let e=0;e<Math.min(6,tQ.length);e++)d()},300);return()=>{clearTimeout(n),null!=r&&clearTimeout(r),t.abort()}},[tX,eB]),(0,r.useEffect)(()=>{eK.current?.abort();let t=eV?function(e,t){if("customer-set"!==e.kind)return null;let r=e.apiBase??"/api/admin/inventory/orders";return`${r}/tracking-activity?scopeKey=${encodeURIComponent(e.scopeKey)}&q=${encodeURIComponent(t)}`}(e,eV):null;if(!t)return void ez(e=>e.bundle||e.loading||e.error?{bundle:null,loading:!1,error:null}:e);let r=new AbortController;eK.current=r;let n=setTimeout(()=>{ez(e=>({...e,loading:!0,error:null})),(async()=>{try{let e=await fetch(t,{signal:r.signal});if(!e.ok)throw Error(`lookup failed (${e.status})`);let n=await e.json(),s=n?.data??n??null;if(r.signal.aborted)return;ez({bundle:s,loading:!1,error:null})}catch(e){if(e?.name==="AbortError")return;ez({bundle:null,loading:!1,error:e?.message||"lookup failed"})}})()},300);return()=>{clearTimeout(n),r.abort()}},[eV,eB]);let tZ=(0,r.useCallback)(async()=>{let t=++tv.current;tu(!0),tN(null),ty(null),tg([]),tm("self"===e.kind),th(!1),e6([]),e7(null),tt(null),tn([]),ta([]),tl([]),td([]),tk(1);try{async function r(e){let t=new AbortController,r=setTimeout(()=>t.abort(),35e3);try{let r=await fetch(e,{signal:t.signal});if(!r.ok)throw Error(401===r.status||403===r.status?"Your session cannot access this activity. Please sign in again.":"Could not load activity. Please try again.");let n=await r.json();if(!n||!1===n.success)throw Error("Could not load activity. Please try again.");return n.data??n}finally{clearTimeout(r)}}let s=new URLSearchParams;function n(e){let t=["invoices","refunds","payments","credits"].filter(t=>e.errors?.[t]||!e[t]);tg(t);let r=t.some(t=>[401,403].includes(e.errors?.[t]?.status??0));ty(r?"Your session cannot access this history. Please sign in again.":t.length?`Could not load ${t.join(", ")}. Please retry to see complete activity.`:null),e6(e.invoices?.invoices??[]),e7(e.invoices?.summary?.aging??null),tt(e.invoices?.consolidated??null),tn(e.refunds?.refunds??[]),ta(e.payments?.payments??[]),tl(e.credits?.credits??[]),td(e.credits?.deposits??[])}if(s.set("limit",String(50)),s.set("page","1"),X&&s.set("status",X),Z&&s.set("dateFrom",Z),G&&s.set("dateTo",G),"self"===e.kind){let a=new URLSearchParams(s);a.set("sections","details"),r(rw(e,a)).then(e=>{t===tv.current&&n(e)}).catch(()=>{t===tv.current&&(tg(["invoices","refunds","payments","credits"]),ty("Could not load invoices, refunds, payments, or credits. Please retry."))}).finally(()=>{t===tv.current&&tm(!1)}),s.set("sections","orders")}let a=await r(rw(e,s));if(t!==tv.current)return;if(a.errors?.orders||!Array.isArray(a.orders?.orders))throw Error([401,403].includes(a.errors?.orders?.status??0)?"Your session cannot access orders. Please sign in again.":a.errors?.orders?.code==="incomplete"?"Order history is incomplete because linked account orders could not be loaded. Please retry.":"Could not load orders. Please try again.");e4(a.orders.orders),tC(a.orders.total??a.orders.orders.length),"self"!==e.kind&&n(a)}catch(e){if(t!==tv.current)return;tN(e instanceof Error?e.message:"Could not load activity. Please try again."),e4([]),tC(0),e6([]),e7(null),tt(null),tn([]),ta([]),tl([]),td([])}finally{t===tv.current&&tu(!1)}},[Y]),tG=(0,r.useCallback)(async()=>
81{if(t$)return;let t=tw+1;tI(!0);try{let r=new URLSearchParams;r.set("includeTracking","true"),r.set("includeLines","true"),r.set("limit",String(50)),r.set("page",String(t)),X&&r.set("status",X),Z&&r.set("dateFrom",Z),G&&r.set("dateTo",G);let n=await fetch(rk(e,r)),s=await n.json(),a=s.data??s,i=a.orders??[];e4(e=>{let t=new Set(e.map(e=>e.id)),r=i.filter(e=>!t.has(e.id));return[...e,...r]}),tC(a.total??tS),tk(t)}catch(e){console.error("[Activity] load more failed:",e)}finally{tI(!1)}},[t$,tw,tS,X,Z,G]),tY=(0,r.useCallback)(async()=>{if(!t$&&!(e0.length>=tS)){tI(!0);try{let t=tS-e0.length,r=Math.ceil(t/50),n=tw+1,s=n+r-1,a=[];for(let e=n;e<=s;e++)a.push(e);let i=[],l=tS;for(let t=0;t<a.length;t+=10){let r=a.slice(t,t+10);for(let t of(await Promise.all(r.map(async t=>{let r=new URLSearchParams;r.set("includeTracking","true"),r.set("includeLines","true"),r.set("limit",String(50)),r.set("page",String(t)),X&&r.set("status",X),Z&&r.set("dateFrom",Z),G&&r.set("dateTo",G);try{let t=await fetch(rk(e,r));if(!t.ok)return null;let n=await t.json();return n.data??n}catch{return null}}))))t&&(i.push(...t.orders??[]),null!=t.total&&(l=t.total))}e4(e=>{let t=new Set(e.map(e=>e.id)),r=i.filter(e=>!t.has(e.id));return[...e,...r]}),tC(l),tk(s)}catch(e){console.error("[Activity] bulk load failed:",e)}finally{tI(!1)}}},[t$,e0.length,tS,tw,X,Z,G]),t0=(0,r.useCallback)(async t=>{let r=t.trim();if(r.length<2||"customer-set"!==e.kind)return;let n=r.toLowerCase();if(!tP.current.has(n)){tP.current.add(n),tT(!0);try{let t=new URLSearchParams;t.set("q",r);let n=new AbortController,s=setTimeout(()=>n.abort(),35e3),a={};try{let r=await fetch(rw(e,t),{signal:n.signal});if(r.ok){let e=await r.json();a=e?.data??e??{}}}finally{clearTimeout(s)}let i=(e,t)=>{if(!t||0===t.length)return e;let r=new Set(e.map(e=>e.id)),n=t.filter(e=>!r.has(e.id));return n.length?[...e,...n]:e},l=(a.orders?.orders??[]).filter(Boolean);e4(e=>{let t=i(e,l);return t.length>e.length&&tC(e=>Math.max(e,t.length)),t}),e6(e=>i(e,a.invoices?.invoices)),ta(e=>i(e,a.payments?.payments)),tn(e=>i(e,a.refunds?.refunds)),tl(e=>i(e,a.credits?.credits)),td(e=>i(e,a.credits?.deposits))}catch(e){console.error("[Activity] history search failed:",e)}finally{tT(!1)}}},[e]),t1=(0,r.useRef)(!!O);(0,r.useEffect)(()=>{if(t1.current){t1.current=!1;return}return tZ(),()=>{tv.current+=1}},[tZ]);let t5=(0,r.useCallback)(async t=>{if(!tM[t]){tF(t);try{let r=new URLSearchParams({orderId:String(t),includeLines:"true",includeTracking:"true",includeFullDetail:"true"}),n=await fetch(rk(e,r)),s=await n.json(),a=s.data??s,i=a.orders?.[0];i&&tU(e=>({...e,[t]:i}))}catch(e){console.error("[Activity] order detail fetch failed:",e)}finally{tF(null)}}},[tM]);function t3(e){requestAnimationFrame(()=>{let t=tH.current[e];t&&t.scrollIntoView({behavior:"smooth",block:"start"})})}(0,r.useEffect)(()=>{if(!tc&&!tW.current&&(ee||et||er)){if(et){let e=et.split(",").map(e=>Number(e.trim())).filter(e=>Number.isFinite(e)&&e>0),t=new Set;for(let r of e0)e.includes(r.id)&&t.add(r.id);if(t.size>0){for(let e of(tA(t),t))t5(e);let e=Array.from(t)[0];t3(`order-${e}`),tW.current=!0;return}}if(ee){let e=/^\d+$/.test(ee),t=e0.find(t=>e?t.id===Number(ee):t.orderNumber===ee);if(t){tA(new Set([t.id])),t5(t.id),t3(`order-${t.id}`),tW.current=!0;return}}if(er){let e=er.toLowerCase(),t=e0.find(t=>t.invoices?.some(t=>t.invoiceNumber?.toLowerCase()===e));if(t){tA(new Set([t.id])),t5(t.id),t3(`order-${t.id}`),tW.current=!0;return}let r=e8.find(t=>t.invoiceNumber?.toLowerCase()===e);if(r){t3(`invoice-${r.id}`),tW.current=!0;return}}(ee||et||er&&!tx&&!tf.includes("invoices"))&&e0.length<tS&&!t$&&tY()}},[tc,ee,et,er,tx,tf,e0,e8,tS,t$,t5,tY]);let t4=(0,r.useCallback)(e=>{tA(t=>new Set(t).add(e)),t5(e);let t=new URLSearchParams(es);t.set("expand",String(e)),t.delete("order"),U.replace(`${F}?${t.toString()}`,{scroll:!1}),tW.current=!1,t3(`order-${e}`)},[F,U,es,t5]),t6=(0,r.useCallback)((e,t,r)=>{tA(t=>new Set(t).add(e)),t5(e);let n=new URLSearchParams(es);n.set("expand",String(e)),n.delete("order"),t&&n.set("invoice",t),n.set("line",String(r)),U.replace(`${F}?${n.toString()}`,{scroll:!1}),tW.current=!1,t3(`order-${e}`)},[F,U,es,t5]),t9=(0,r.useCallback)((e,t,r)=>{let n=`/sales/customers/${e}?tab=activity&expand=${t}&line=${r}`;window.location.hostname.startsWith("admin.")?window.open(window.location.origin.replace("//admin.","//team.")+n,"_blank","noopener"):U.push(n)},[U]),re=(0,r.useMemo)(()=>eO(e0,ts,tr,to,ti),[e0,ts,tr,to,ti]),rr=(0,r.useMemo)(()=>{let e=eA(tr,ti,to),t=ea.trim();return t?{refunds:e.refunds.filter(e=>e1(e,t)),credits:e.credits.filter(e=>e2(e,t)),deposits:e.deposits.filter(e=>e5(e,t))}:e},[tr,ti,to,ea]),rn=(0,r.useMemo)(()=>{let e=e0;if("pending-approval"===H)e=e.filter(e=>eC(e));else if("open"===H)e=e.filter(e=>eS(e));else if("in-transit"===H)e=e.filter(e=>e$(e));else if("to-pay"===H)e=e.filter(e=>eI(e));else if("overdue"===H){let t=new Set(e8.filter(e=>eD(e)).map(e=>e.id));e=e.filter(e=>e.invoices?.some(e=>t.has(e.id)))}else if("money-back"===H)e=e.filter(e=>{let t;return!!(t=re.get(e.id))&&t.refunds.length>0});else if("air"===H)e=e.filter(e=>(e.airUnits??0)>0);else if("attention"===H){let t=(0,A.businessToday)();e=e.filter(e=>eH(e,t))}if(ea){let t=eZ(ea);t.length>0&&(e=e.filter(e=>eG(e,t)))}let t=ex.trim().toLowerCase();if(eu&&t&&(e=e.filter(e=>(e.customerName||"").toLowerCase().includes(t))),ed){let t=eY(eP);t&&(e=e.filter(t))}return e},[e0,e8,H,ea,re,ex,eu,ed,eP]),rs=(0,r.useMemo)(()=>
81{if("customer-set"!==e.kind)return[];let t=new Map;for(let e of e0)for(let r of e.phoneModels??[]){let e=r.toLowerCase();t.has(e)||t.set(e,r)}return Array.from(t.values()).sort((e,t)=>e.localeCompare(t))},[e0,e.kind]),ra=(0,r.useMemo)(()=>{let t=eu&&"customer-set"===e.kind?ex.trim().toLowerCase():"";if(t||Z||G||X)return e=>{if(t&&!(e.customerName||"").toLowerCase().includes(t))return!1;let r=(e.orderDate||"").slice(0,10);return(!Z||!r||!(r<Z))&&(!G||!r||!(r>G))&&(!X||e.orderStatusRef===X)}},[eu,e.kind,ex,Z,G,X]),ri=(0,r.useMemo)(()=>{if(S)return e=>`${S}?q=${encodeURIComponent(e.orderNumber)}`},[S]),rl="number"==typeof h&&h>0,ro=rl&&!tL;(0,r.useEffect)(()=>{rl&&tE(!1)},[H,ea,rl]);let rd=ro?rn.slice(0,h):rn,rc=Math.max(0,rn.length-rd.length),ru=(0,r.useMemo)(()=>"attention"===H&&ed?eW(rn,(0,A.businessToday)()):[],[H,ed,rn]),rx=(0,r.useMemo)(()=>{let e=eQ(e8,e0);return"all"===H||(e="to-pay"===H?e.filter(e=>eT(e)):"overdue"===H?e.filter(e=>eD(e)):"money-back"===H?e.filter(e=>eT(e)):[]),ea&&(e=e.filter(e=>eJ(e,ea))),e},[e8,e0,H,ea]),rm=(0,r.useMemo)(()=>{let e,t=e0.filter(eC).length,r=e0.filter(eS).length,n=e0.filter(e$).length,s=e0.filter(eI).length+eQ(e8,e0).filter(eT).length,a=new Set(e8.filter(eD).map(e=>e.id)),i=e0.filter(e=>e.invoices?.some(e=>a.has(e.id))).length+eQ(e8,e0).filter(eD).length,l=e0.filter(e=>{let t=re.get(e.id);return!!t&&t.refunds.length>0}).length,o=rr.refunds.length+rr.credits.length+rr.deposits.length;return{all:e0.length+eQ(e8,e0).length+o,"pending-approval":t,open:r,"in-transit":n,"to-pay":s,overdue:i,"money-back":l+rr.refunds.length,air:e0.filter(e=>(e.airUnits??0)>0).length,attention:(e=(0,A.businessToday)(),e0.filter(t=>eH(t,e)).length)}},[e0,e8,re,rr]),rp=(0,r.useMemo)(()=>{let e=ea.trim();return e?e8.filter(t=>eJ(t,e)):e8},[e8,ea]),rh=(0,r.useMemo)(()=>{let e=ea.trim();return e?ti.filter(t=>e2(t,e)):ti},[ti,ea]),rf=(0,r.useMemo)(()=>{let e=ea.trim();return e?tr.filter(t=>e1(t,e)):tr},[tr,ea]),rg=(0,r.useMemo)(()=>{let e=ea.trim().toLowerCase();return e?ts.filter(t=>JSON.stringify(t).toLowerCase().includes(e)):ts},[ts,ea]),rb=(0,r.useMemo)(()=>({all:e0.length+eQ(e8,e0).length+rr.refunds.length+rr.credits.length+rr.deposits.length,orders:e0.length,invoices:e8.length,"credit-memos":ti.length,payments:ts.length,refunds:tr.length}),[e0,e8,ti,ts,tr,rr]),rS=(0,r.useMemo)(()=>{let e=e0.filter(eS).length,t=e8.filter(eT).length,r=ti.filter(e=>(e.unapplied??0)>0).length;return{all:e+t+r,orders:e,invoices:t,"credit-memos":r,payments:0,refunds:0}},[e0,e8,ti]),rC="invoices"===V||"credit-memos"===V||"payments"===V||"refunds"===V,r$=(0,r.useMemo)(()=>{if(e9)return[{key:"current",label:"Current",amount:e9.current.total,count:e9.current.count},{key:"1-30",label:"1â30 days",amount:e9.days1to30.total,count:e9.days1to30.count},{key:"31-60",label:"31â60 days",amount:e9.days31to60.total,count:e9.days31to60.count},{key:"61-90",label:"61â90 days",amount:e9.days61to90.total,count:e9.days61to90.count},{key:"90+",label:"90+ days",amount:e9.days90plus.total,count:e9.days90plus.count}];let e=[...e8],t=new Set(e.map(e=>e.id));for(let r of e0)for(let n of r.invoices??[])t.has(n.id)||(t.add(n.id),e.push(n));return eM(e)},[e9,e0,e8]),rI=(0,r.useMemo)(()=>r$.reduce((e,t)=>e+t.amount,0),[r$]),[rD,rT]=(0,r.useState)(!1);function rP(){ek(""),eL([]);let e=new URLSearchParams(R.toString());e.delete("status"),e.delete("dateFrom"),e.delete("dateTo"),e.delete("order"),e.delete("invoice");let t=e.toString();U.push(t?`${F}?${t}`:F)}function rL(e,t){let r=new URLSearchParams(R.toString());t?r.set(e,t):r.delete(e),"order"!==e&&"invoice"!==e&&(r.delete("order"),r.delete("invoice"));let n=r.toString(),s=n?`${F}?${n}`:F;U.push(s)}function rE(e){W(e);let t=new URLSearchParams(R.toString());"all"===e?t.delete("view"):t.set("view",e),t.delete("order"),t.delete("invoice");let r=t.toString(),n=r?`${F}?${r}`:F;window.history.replaceState({},"",n);try{U.replace(n,{scroll:!1})}catch{}}function rO(e){Q(e),"all"!==e&&"orders"!==e&&W("all");let t=new URLSearchParams(R.toString());"all"===e?t.delete("type"):t.set("type",e),"all"!==e&&"orders"!==e&&t.delete("view"),t.delete("order"),t.delete("invoice"),t.delete("expand");let r=t.toString(),n=r?`${F}?${r}`:F;window.history.replaceState({},"",n);try{U.replace(n,{scroll:!1})}catch{}}let rA=!!(X||Z||G||ea||ex||eP.length>
810||"all"!==H),rM=+!!X+ +!!Z+ +!!G+(eu&&ex.trim()?1:0)+(ed&&eP.length>0?1:0),rU=rD||rM>0,rR="customer-set"===e.kind&&((rm.air??0)>0||"air"===H),rF="customer-set"===e.kind&&((rm.attention??0)>0||"attention"===H),rq=!tc&&0===rn.length&&0===rx.length,rB="invoices"===V?["invoices"]:"payments"===V?["payments"]:"refunds"===V?["refunds"]:"credit-memos"===V?["credits"]:"to-pay"===H||"overdue"===H?["invoices"]:"money-back"===H?["refunds","credits"]:"all"===V&&rq?["invoices","refunds","payments","credits"]:[],r_=rB.some(e=>tf.includes(e)),rz=(M={detailsLoading:tx,detailsGraceExpired:tp}).detailsLoading&&!M.detailsGraceExpired,rH=eE.filter(e=>e.bundle&&(e.bundle.item||1===eE.length&&(e.bundle.suggestions?.length??0)>0)),rW=rH.length>1?rH.filter(e=>{let t;return!e.bundle?.item||0!==(t=e.bundle?.rows??[]).length&&(!ra||t.some(ra))}):rH,rK=rW.filter(e=>e.bundle?.item),rV=1===rK.length&&rK[0]?.bundle?.item?{itemId:rK[0].bundle.item.itemId,sku:rK[0].bundle.item.sku}:null,rQ=eE.some(e=>e.loading),rX=eE.filter(e=>!e.loading).length,rZ=rW.slice(0,eR),rG=rW.length-rZ.length,rY=(0,r.useRef)("");(0,r.useEffect)(()=>{let t=ea.trim();if(!t){rY.current="";return}tc||t$||tD||rn.length>0||rx.length>0||("customer-set"===e.kind?t0(t):e0.length>=tS||rY.current!==t&&(rY.current=t,tY()))},[ea,tc,t$,tD,rn.length,rx.length,e0.length,tS,tY,t0,e.kind]);let rJ=!!ea.trim()&&(t$||tD||e0.length<tS&&0===rn.length&&0===rx.length),r0=x??("self"===e.kind?"Activity":"Order activity");async function r1(){let e=new Date().toISOString().slice(0,10);if(q&&B)try{let e=await B();await e.exportOrderHistory(rn);return}catch(e){console.error("[activity] Modern order-history XLSX failed; falling back",e)}k(function(e){let t=[];for(let r of e){let e=(r.invoices??[]).map(e=>e.invoiceNumber).join("; "),n=(r.invoices??[]).map(e=>null!=e.total?`$${e.total.toFixed(2)}
81`:"").filter(Boolean).join("; "),s=[],a=[],i="",l="";for(let e of r.fulfillments??[]){for(let t of e.trackingNumbers)t.length>=5&&!s.includes(t)&&s.push(t);e.origin&&!a.includes(e.origin)&&a.push(e.origin),e.upsTrackingStatus&&!i&&(i=e.upsTrackingStatus),e.deliveryDate&&!l&&(l=e.deliveryDate)}t.push([b(r.orderNumber),b(r.date),b(r.poNumber),b(r.status),b(r.shipMethod),b(r.terms),String(r.lineCount||0),r.total.toFixed(2),b(e),b(n),b(s.join("; ")),b(a.join(", ")),b(i),b(l)])}return["Order #,Date,PO #,Status,Ship Method,Terms,Items,Total,Invoice(s),Invoice Total(s),Tracking,Origin(s),Delivery Status,Delivery Date",...t.map(e=>e.join(","))].join("\n")}(rn),`activity-${H}-${e}.csv`)}let r2=ed&&rs.length>0,r5=3+ +!!eu+ +!!r2,r3=rU?(0,t.jsxs)("div",{className:`grid grid-cols-1 gap-3 ${5===r5?"sm:grid-cols-2 lg:grid-cols-5":4===r5?"sm:grid-cols-2 lg:grid-cols-4":"sm:grid-cols-3"}`,children:[eu&&(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"mb-1 block text-xs text-text-tertiary",children:"Customer"}),(0,t.jsx)("input",{type:"text",value:ex,onChange:e=>ek(e.target.value),placeholder:"Company nameâ¦",className:"w-full rounded-lg border border-border-default bg-surface px-3 py-2 text-[16px] sm:text-sm text-text-primary outline-none placeholder:text-text-tertiary focus:border-accent"})]}),r2&&(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"mb-1 block text-xs text-text-tertiary",children:"Phone model"}),(0,t.jsx)(rj,{options:rs,selected:eP,onChange:eL})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"mb-1 block text-xs text-text-tertiary",children:"Status"}),(0,t.jsx)("select",{value:X,onChange:e=>rL("status",e.target.value),className:"w-full rounded-lg border border-border-default bg-surface px-3 py-2 text-[16px] sm:text-sm text-text-primary",children:rN.map(e=>(0,t.jsx)("option",{value:e.value,children:e.label},e.value))})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"mb-1 block text-xs text-text-tertiary",children:"From"}),(0,t.jsx)("input",{type:"date",value:Z,onChange:e=>rL("dateFrom",e.target.value),className:"w-full rounded-lg border border-border-default bg-surface px-3 py-2 text-[16px] sm:text-sm text-text-primary"})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"mb-1 block text-xs text-text-tertiary",children:"To"}),(0,t.jsx)("input",{type:"date",value:G,onChange:e=>rL("dateTo",e.target.value),className:"w-full rounded-lg border border-border-default bg-surface px-3 py-2 text-[16px] sm:text-sm text-text-primary"})]})]}):null;return(0,t.jsx)($,{value:{canPayInvoices:f??!1,modernXlsxEnabled:q,onPayInvoice:y??null,loadModernXlsxExporter:B,cart:j??null,invoiceApiBase:"customer"===e.kind?`/api/portal/team/sales/customers/${e.customerId}/invoices`:"customer-set"===e.kind?`${e.apiBase??"/api/admin/inventory/orders"}/invoice-detail`:"/api/customer/invoices",ordersApiBase:"customer"===e.kind?`/api/portal/team/sales/customers/${e.customerId}/orders`:"customer-set"===e.kind?`${e.apiBase??"/api/admin/inventory/orders"}/detail`:"/api/customer/orders",paymentsApiBase:"customer"===e.kind?`/api/portal/team/sales/customers/${e.customerId}/payments`:"/api/customer/payments",returnsPdfBase:"self"===e.kind?"/api/customer/returns":"/api/portal/team/sales/transactions",refundsApiBase:"customer"===e.kind?`/api/portal/team/sales/customers/${e.customerId}/refunds`:"/api/customer/refunds",showBuyAgain:a.showBuyAgain,showAddLine:a.showAddLine,renderLineExtras:w??null,approval:N??null},children:(0,t.jsxs)("div",{className:"space-y-3",children:[_?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-[18px]",children:[(0,t.jsx)("h1",{className:"text-[22px] font-extrabold leading-none tracking-[-0.02em] text-text-primary",children:r0}),(0,t.jsx)("div",{role:"tablist",className:"inline-flex gap-0.5 rounded-[11px] bg-surface-elevated p-[3px]",children:ew.map(e=>{let r=V===e.value,n=rb[e.value],s=rS[e.value];return"all"===e.value||r||(n??0)!==0?(0,t.jsxs)("button",{type:"button",role:"tab","aria-selected":r,onClick:()=>rO(e.value),title:s>0?`${e.label}: ${s} open / need attention`:e.description,className:`inline-flex items-center gap-1.5 rounded-[9px] px-3.5 py-[7px] text-[12.5px] font-bold transition-colors ${r?"bg-surface text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:[e.label,s>0&&(0,t.jsx)("span",{className:"inline-flex h-4 min-w-[16px] items-center justify-center rounded-full bg-surface-elevated px-1 font-mono text-[9.5px] font-bold tabular-nums text-text-tertiary",children:s})]},e.value):null})}),(0,t.jsxs)("div",{className:"ml-auto flex items-center gap-3.5",children:[(0,t.jsxs)("button",{type:"button",onClick:r1,disabled:tc||0===rn.length,"aria-label":q?"Export visible orders to Excel":"Export visible orders to CSV",className:"inline-flex items-center gap-[7px] text-[12.5px] font-semibold text-text-primary transition-colors hover:text-accent disabled:cursor-not-allowed disabled:opacity-40",children:[(0,t.jsx)(l.Download,{className:"h-[13px] w-[13px]"}),q?"Export Excel":"Export CSV"]}),(0,t.jsx)("button",{type:"button",onClick:()=>tZ(),"aria-label":"Refresh",className:"flex text-text-tertiary transition-colors hover:text-text-primary",children:(0,t.jsx)(d.RefreshCw,{className:"h-3.5 w-3.5"})})]})]}),(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,t.jsxs)("div",{className:"relative min-w-[220px] flex-1",children:[(0,t.jsx)("svg",{"aria-hidden":"true",className:"pointer-events-none absolute left-3.5 to
81p-1/2 h-3.5 w-3.5 -translate-y-1/2 text-text-tertiary",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M21 21l-4.35-4.35M10.5 18a7.5 7.5 0 100-15 7.5 7.5 0 000 15z"})}),(0,t.jsx)("input",{type:"text",value:ea,onChange:e=>ei(e.target.value),placeholder:"Search by SO#, PO#, invoice, SKU, UPC, tracking, ship-toâ¦",className:"h-10 w-full rounded-[11px] border border-border-default bg-surface pl-9 pr-9 text-[16px] sm:text-[13px] text-text-primary placeholder:text-text-muted focus:border-accent focus:outline-none focus:ring-1 focus:ring-accent","aria-label":"Search orders and invoices"}),ea&&(0,t.jsx)("button",{type:"button",onClick:eX,"aria-label":"Clear search",className:"absolute right-2 top-1/2 -translate-y-1/2 rounded p-1 text-text-tertiary hover:bg-surface-elevated hover:text-text-primary",children:(0,t.jsx)("svg",{className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]}),!rC&&eN.map(e=>{let r=H===e.value,n=rm[e.value];if("all"!==e.value&&!r&&(n??0)===0)return null;let s="all"===e.value?"All orders":e.label;return(0,t.jsxs)("button",{type:"button",onClick:()=>rE(e.value),title:e.description,className:`inline-flex h-[34px] items-center gap-[7px] rounded-full border px-3.5 text-[12.5px] font-semibold transition-colors ${r?"border-accent bg-accent text-accent-foreground":"border-border-default bg-surface text-text-secondary hover:border-accent hover:text-text-primary"}`,children:[s,n>0&&(0,t.jsx)("span",{className:`inline-flex h-4 min-w-[16px] items-center justify-center rounded-full px-1 font-mono text-[9.5px] font-bold tabular-nums ${r?"bg-white/25 text-accent-foreground":"bg-surface-elevated text-text-tertiary"}`,children:n})]},e.value)}),!rC&&rR&&(0,t.jsxs)("button",{type:"button",onClick:()=>rE("air"),title:"Orders with air-freight units",className:`inline-flex h-[34px] items-center gap-[7px] rounded-full border px-3.5 text-[12.5px] font-semibold transition-colors ${"air"===H?"border-accent bg-accent text-accent-foreground":"border-border-default bg-surface text-text-secondary hover:border-accent hover:text-text-primary"}`,children:["Air",rm.air>0&&(0,t.jsx)("span",{className:`inline-flex h-4 min-w-[16px] items-center justify-center rounded-full px-1 font-mono text-[9.5px] font-bold tabular-nums ${"air"===H?"bg-white/25 text-accent-foreground":"bg-surface-elevated text-text-tertiary"}`,children:rm.air})]}),!rC&&rF&&(0,t.jsxs)("button",{type:"button",onClick:()=>rE("attention"===H?"all":"attention"),"aria-pressed":"attention"===H,title:"attention"===H?"Showing shipments with tracking issues or delays â click to clear":"Shipments with tracking issues or delays â stuck labels, past-ETA, carrier exceptions, open lines past their ship date",className:`inline-flex h-[34px] items-center gap-[7px] rounded-full border px-3.5 text-[12.5px] font-semibold transition-colors ${"attention"===H?"border-warning bg-warning text-warning-foreground":"border-warning/40 bg-surface text-warning hover:border-warning"}`,children:["Needs attention",rm.attention>0&&(0,t.jsx)("span",{className:`inline-flex h-4 min-w-[16px] items-center justify-center rounded-full px-1 font-mono text-[9.5px] font-bold tabular-nums ${"attention"===H?"bg-white/25 text-warning-foreground":"bg-warning-bg text-warning"}`,children:rm.attention})]}),!rC&&C,(0,t.jsxs)("button",{type:"button",onClick:()=>rT(e=>!e),"aria-expanded":rU,className:"inline-flex h-[34px] items-center gap-1.5 rounded-full border border-border-default bg-surface px-[13px] text-xs font-semibold text-text-primary transition-colors hover:border-accent",children:["Filters",rM>0&&(0,t.jsx)("span",{className:"inline-flex h-4 min-w-[16px] items-center justify-center rounded-full bg-accent px-1 font-mono text-[9.5px] font-bold tabular-nums text-accent-foreground",children:rM}),(0,t.jsx)(s.ChevronDown,{"aria-hidden":"true",className:`h-3.5 w-3.5 transition-transform ${rU?"rotate-180":""}`})]}),rM>0&&(0,t.jsx)("button",{type:"button",onClick:rP,className:"text-xs text-text-tertiary transition-colors hover:text-accent",children:"Clear"})]}),r3]}
81):(0,t.jsxs)(t.Fragment,{children:[!p&&(0,t.jsxs)("div",{className:"flex items-start justify-between gap-4",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("h1",{className:"text-lg font-bold text-text-primary",children:r0}),(0,t.jsx)("p",{className:"mt-0.5 text-xs text-text-muted",children:m??"Orders, shipments, and invoices in one place."})]}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsxs)(c.default,{variant:"ghost",size:"sm",onClick:r1,disabled:tc||0===rn.length,"aria-label":q?"Export visible orders to Excel":"Export visible orders to CSV",children:[(0,t.jsx)(l.Download,{className:"h-4 w-4"}),(0,t.jsx)("span",{className:"sr-only sm:not-sr-only sm:ml-1.5",children:q?"Export Excel":"Export CSV"})]}),(0,t.jsx)(c.default,{variant:"ghost",size:"sm",onClick:()=>tZ(),"aria-label":"Refresh",children:(0,t.jsx)(d.RefreshCw,{className:"h-4 w-4"})})]})]}),(0,t.jsx)("div",{className:"flex flex-wrap items-center gap-2",children:ew.map(e=>{let r=V===e.value,n=rb[e.value],s=rS[e.value];return"all"===e.value||r||(n??0)!==0?(0,t.jsxs)("button",{type:"button",onClick:()=>rO(e.value),className:`inline-flex items-center gap-1.5 rounded-full border px-3 py-1.5 text-xs font-medium transition-colors ${r?"border-accent bg-accent text-accent-foreground":"border-border-default bg-surface text-text-secondary hover:border-accent hover:text-text-primary"}`,title:s>0?`${e.label}: ${s} open / need attention`:e.description,children:[e.label,s>0&&(0,t.jsx)("span",{className:`inline-flex min-w-[18px] items-center justify-center rounded-full px-1.5 text-[10px] tabular-nums ${r?"bg-white/20 text-white":"bg-surface-elevated text-text-tertiary"}`,children:s})]},e.value):null})}),!rC&&(null!=C||rR||eN.some(e=>"all"!==e.value&&(rm[e.value]??0)>0))&&(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-2 border-b border-border-default pb-3",children:[eN.map(e=>{let r=H===e.value,n=rm[e.value];if("all"!==e.value&&!r&&(n??0)===0)return null;let s="all"===e.value?"All orders":e.label;return(0,t.jsxs)("button",{type:"button",onClick:()=>rE(e.value),className:`inline-flex items-center gap-1.5 rounded-full border px-3 py-1.5 text-xs font-medium transition-colors ${r?"border-accent bg-accent text-accent-foreground":"border-border-default bg-surface text-text-secondary hover:border-accent hover:text-text-primary"}`,title:e.description,children:[s,n>0&&(0,t.jsx)("span",{className:`inline-flex min-w-[18px] items-center justify-center rounded-full px-1.5 text-[10px] tabular-nums ${r?"bg-white/20 text-white":"bg-surface-elevated text-text-tertiary"}`,children:n})]},e.value)}),rR&&(0,t.jsxs)("button",{type:"button",onClick:()=>rE("air"),title:"Orders with air-freight units",className:`inline-flex items-center gap-1.5 rounded-full border px-3 py-1.5 text-xs font-medium transition-colors ${"air"===H?"border-accent bg-accent text-accent-foreground":"border-border-default bg-surface text-text-secondary hover:border-accent hover:text-text-primary"}`,children:["Air",rm.air>0&&(0,t.jsx)("span",{className:`inline-flex min-w-[18px] items-center justify-center rounded-full px-1.5 text-[10px] tabular-nums ${"air"===H?"bg-white/20 text-white":"bg-surface-elevated text-text-tertiary"}`,children:rm.air})]}),rF&&(0,t.jsxs)("button",{type:"button",onClick:()=>rE("attention"===H?"all":"attention"),"aria-pressed":"attention"===H,title:"attention"===H?"Showing shipments with tracking issues or delays â click to clear":"Shipments with tracking issues or delays",className:`inline-flex items-center gap-1.5 rounded-full border px-3 py-1.5 text-xs font-medium transition-colors ${"attention"===H?"border-warning bg-warning text-warning-foreground":"border-warning/40 bg-surface text-warning hover:border-warning"}`,children:["Needs attention",rm.attention>0&&(0,t.jsx)("span",{className:`inline-flex min-w-[18px] items-center justify-center rounded-full px-1.5 text-[10px] tabular-nums ${"attention"===H?"bg-white/20 text-warning-foreground":"bg-warning-bg text-warning"}`,children:rm.attention})]}),C]}),(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsxs)("div",{className:"flex items-stretch gap-2",children:[(0,t.jsxs)("div",{className:"relative flex-1",children:[(0,t.jsx)("svg",{"aria-hidden":"true",className:"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-text-tertiary",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M21 21l-4.35-4.35M10.5 18a7.5 7.5 0 100-15 7.5 7.5 0 000 15z"})}),(0,t.jsx)("input",{type:"text",value:ea,onChange:e=>ei(e.target.value),placeholder:"Search by SO#, PO#, invoice, SKU, UPC, tracking, ship-toâ¦",className:"w-full rounded-lg border border-border-default bg-surface py-2 pl-10 pr-9 text-[16px] sm:text-sm text-text-primary placeholder:text-text-muted focus:border-accent focus:outline-none focus:ring-1 focus:ring-accent","aria-label":"Search orders and invoices"}),ea&&(0,t.jsx)("button",{type:"button",onClick:eX,"aria-label":"Clear search",className:"absolute right-2 top-1/2 -translate-y-1/2 roun
81ded p-1 text-text-tertiary hover:bg-surface-elevated hover:text-text-primary",children:(0,t.jsx)("svg",{className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]}),E?E(e=>ei(e.join(", "))):null]}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsxs)("button",{type:"button",onClick:()=>rT(e=>!e),"aria-expanded":rU,className:"inline-flex items-center gap-1.5 rounded-lg border border-border-default bg-surface px-2.5 py-1.5 text-xs font-medium text-text-secondary transition-colors hover:border-accent hover:text-text-primary",children:["Filters",rM>0&&(0,t.jsx)("span",{className:"inline-flex min-w-[18px] items-center justify-center rounded-full bg-accent px-1.5 text-[10px] tabular-nums text-accent-foreground",children:rM}),(0,t.jsx)(s.ChevronDown,{"aria-hidden":"true",className:`h-3.5 w-3.5 transition-transform ${rU?"rotate-180":""}`})]}),rM>0&&(0,t.jsx)("button",{type:"button",onClick:rP,className:"text-xs text-text-tertiary transition-colors hover:text-accent",children:"Clear"})]}),r3]}
81)]}),("to-pay"===H||"overdue"===H)&&rI>0&&(0,t.jsx)(u.default,{title:"Amount due by age",subtitle:(()=>{let e=r$.reduce((e,t)=>e+t.count,0),t=`${(0,A.formatCurrency)(rI)} outstanding across ${e} invoice${1!==e?"s":""}`;if(te&&te.descendantNames.length>0){let e=te.descendantNames.slice(0,3).join(", "),r=te.descendantNames.length>3?` and ${te.descendantNames.length-3} more`:"";return`${t} \xb7 Consolidated â includes ${e}${r}`}return t})(),padding:"compact",children:(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsx)("div",{className:"flex h-3 w-full overflow-hidden rounded-full bg-surface-elevated",role:"img","aria-label":"Invoice aging breakdown",children:r$.map(e=>{let r=rI>0?e.amount/rI*100:0;if(0===r)return null;let n="current"===e.key?"bg-success":"1-30"===e.key?"bg-info":"31-60"===e.key||"61-90"===e.key?"bg-warning":"bg-error";return(0,t.jsx)("div",{className:n,style:{width:`${r}%`},title:`${e.label}: ${(0,A.formatCurrency)(e.amount)}`},e.key)})}),(0,t.jsx)("div",{className:"grid grid-cols-2 gap-2 text-xs sm:grid-cols-5",children:r$.map(e=>{let r="current"===e.key?"bg-success":"1-30"===e.key?"bg-info":"31-60"===e.key||"61-90"===e.key?"bg-warning":"bg-error";return(0,t.jsxs)("div",{className:"flex items-start gap-2",children:[(0,t.jsx)("span",{className:`mt-1 h-2 w-2 flex-shrink-0 rounded-full ${r}`}),(0,t.jsxs)("div",{className:"min-w-0",children:[(0,t.jsx)("p",{className:"text-text-tertiary",children:e.label}),(0,t.jsx)("p",{className:"font-medium text-text-primary",children:(0,A.formatCurrency)(e.amount)}),(0,t.jsxs)("p",{className:"text-[10px] text-text-muted",children:[e.count," invoice",1!==e.count?"s":""]})]})]},e.key)})})]})}),rA&&(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsxs)("span",{className:"text-xs text-text-tertiary",children:[rn.length+rx.length," result",rn.length+rx.length!==1?"s":""]}),(0,t.jsx)("button",{type:"button",onClick:()=>U.replace(F,{scroll:!1}),className:"text-xs text-accent hover:underline",children:"Clear filters"})]}),rC||!e_.loading||e_.bundle?null:(0,t.jsx)(ej.default,{shape:"detail"}),!rC&&(e_.bundle?.tracking||e_.error)?(0,t.jsx)(eo,{bundle:e_.bundle,error:e_.error,showCustomer:"customer-set"===e.kind,onOpenOrder:t4,onOpenCustomer:t9,exportRows:D,packingListsHref:eV?function(e,t){if("customer-set"!==e.kind)return null;let r=e.apiBase??"/api/admin/inventory/orders";return`${r}/tracking-documents?scopeKey=${encodeURIComponent(e.scopeKey)}&q=${encodeURIComponent(t)}`}(e,eV)??void 0:void 0}):null,!rC&&e_.bundle?.tracking&&0===rK.length&&!tc&&(0,t.jsxs)("p",{className:"ml-0.5 text-[11px] font-semibold uppercase tracking-wide text-text-tertiary",children:["Orders in this shipment · ",rn.length]}),!rC&&(rW.length>0||rQ)?rW.length>0?(0,t.jsxs)(t.Fragment,{children:[rZ.map(r=>(0,t.jsx)(rt,{bundle:r.bundle,showCustomer:"customer-set"===e.kind,onOpenOrder:t4,onOpenInvoiceLine:t6,onOpenCustomer:t9,onPickSuggestion:e=>ei(e),rowFilter:ra,oorHrefForRow:ri,exportRows:I,scpInboundHref:T,onScpInboundClick:P,scpDestination:L},r.token.toLowerCase())),rG>0&&(0,t.jsx)("div",{className:"flex justify-center",children:(0,t.jsxs)(c.default,{variant:"outline",size:"sm",onClick:()=>eF(e=>e+25),children:["Show ",rG," more item",1!==rG?"s":""]})}),rQ&&(0,t.jsxs)("div",{className:"space-y-1.5",children:[eE.length>1&&(0,t.jsxs)("p",{className:"text-xs tabular-nums text-text-tertiary",children:[rX,"/",eE.length]}),(0,t.jsx)(ej.default,{shape:"detail"})]})]}):(0,t.jsxs)("div",{className:"space-y-1.5",children:[eE.length>1&&(0,t.jsxs)("p",{className:"text-xs tabular-nums text-text-tertiary",children:[rX,"/",eE.length]}),(0,t.jsx)(ej.default,{shape:"detail"})]}):null,!rC&&rK.length>0&&!tc&&(0,t.jsxs)("p",{className:"ml-0.5 text-[11px] font-semibold uppercase tracking-wide text-text-tertiary",children:[rK.length>1?"Orders containing these items":"Orders containing this item"," ","· ",rn.length,e3(rn.length,1===rK.length?rK[0].bundle?.totals.orders??null:null)]}),tx&&!tc&&(0,t.jsx)("p",{role:"status",className:"text-sm text-text-secondary",children:"Loading invoices and payment historyâ¦"}),tb&&!tc&&(0,t.jsxs)("div",{role:"alert",className:"flex items-center gap-3 text-sm text-text-secondary",children:[(0,t.jsx)("span",{children:tb}),(0,t.jsx)(c.default,{variant:"outline",size:"sm",onClick:()=>tZ(),children:"Retry"})]}),tc||rz||tx&&rB.length>0?(0,t.jsx)(ej.default,{shape:"table"}):tj?(0,t.jsx)(u.default,{children:(0,t.jsx)(ev.default,{variant:"error",description:tj,action:(0,t.jsx)(c.default,{variant:"outline",size:"sm",onClick:()=>tZ(),children:"Retry"})})}):r_?null:rC?(()=>{if("invoices"===V&&0===rp.length||"credit-memos"===V&&0===rh.length||"payments"===V&&0===rg.length||"refunds"===V&&0===rf.length){let e=ew.find(e=>e.value===V)?.label??"records";return(0,t.jsx)(u.default,{children:(0,t.jsx)(ev.default,{variant:ea?"no-results":"no-data",icon:(0,t.jsx)(o.Package,{className:"h-5 w-5"}),description:ea?`No ${e.toLowerCase()} match "${ea}".`:`No ${e.toLowerCase()} on this account.`,action:ea?(0,t.jsx)(c.default,{variant:"outline",size:"sm",onClick:eX,children:"Clear search"}):void 0})})}return(0,t.jsxs)("div",{className:"space-y-3",children:["invoices"===V&&rp.map(e=>(0,t.jsx)("div",{ref:t=>{tH.current[`invoice-${e.id}`]=t},children:(0,t.jsx)(t8,{invoice:e,highlighted:er.toLowerCase()===e.invoiceNumber?.toLowerCase()})},`flat-invoice-${e.id}`)),("credit-memos"===V||"payments"===V||"refunds"===V)&&(0,t.jsxs)("div",{className:"overflow-hidden rounded-xl border border-border-default bg-surface",children:["credit-memos"===V&&rh.map(e=>(0,t.jsx)(t7,{row:{kind:"credit",data:e},selectable:!1,selected:!1,onToggleSelect:()=>{},invoicePdfHref:()=>""},`flat-credit-${e.id}`)),"payments"===V&&rg.map(e=>(0,t.jsx)(t7,{row:{kind:"payment",data:e},selectable:!1,selected:!1,onToggleSelect:()=>{},invoicePdfHref:()=>""},`flat-payment-${e.id}`)),"refunds"===V&&rf.map(e=>(0,t.jsx)(t7,{row:{kind:"refund",data:e},selectable:!1,selected:!1,onToggleSelect:()=>{},invoicePdfHref:()=>""},`flat-refund-${e.id}`))]})]})})():rq?(0,t.jsx)(u.default,{children:rJ?(0,t.jsx)(ev.default,{variant:"no-results",icon:(0,t.jsx)(o.Package,{className:"h-5 w-5"}),description:tD?`Searching all history for "${ea}" â this can take a momentâ¦`:`Searching all ${tS.toLocaleStr
81ing("en-US")} orders for "${ea}"â¦`,action:(0,t.jsx)(c.default,{variant:"outline",size:"sm",onClick:eX,children:"Cancel search"})}):ea&&e0.length>=tS&&tS>0?(0,t.jsx)(ev.default,{variant:"no-results",icon:(0,t.jsx)(o.Package,{className:"h-5 w-5"}),description:`No orders match "${ea}" across all ${tS.toLocaleString("en-US")} of your orders. Check the spelling, or try a partial SKU / tracking number.`,action:(0,t.jsx)(c.default,{variant:"outline",size:"sm",onClick:eX,children:"Clear search"})}):ea&&e0.length<tS?(0,t.jsx)(ev.default,{variant:"no-results",icon:(0,t.jsx)(o.Package,{className:"h-5 w-5"}),description:`No matches for "${ea}" in the ${e0.length.toLocaleString("en-US")} most recent orders. Load older orders to expand the search across all ${tS.toLocaleString("en-US")}.`,action:(0,t.jsxs)("div",{className:"flex flex-wrap items-center justify-center gap-2",children:[(0,t.jsx)(c.default,{variant:"primary",size:"sm",onClick:tG,loading:t$,children:"Load more orders"}),(0,t.jsx)(c.default,{variant:"outline",size:"sm",onClick:eX,children:"Clear search"})]})}):(0,t.jsx)(ev.default,{variant:rA?"no-results":"no-data",icon:(0,t.jsx)(o.Package,{className:"h-5 w-5"}),description:rA?"Try adjusting your filters or clearing your search.":"You haven't placed any orders yet. When you do, they'll appear here.",action:rA?(0,t.jsx)(c.default,{variant:"outline",size:"sm",onClick:()=>U.replace(F,{scroll:!1}),children:"Clear filters"}):void 0})}):(0,t.jsxs)("div",{className:_?"space-y-3.5":"space-y-3",children:["attention"===H&&ru.length>0&&(0,t.jsx)(t2,{rows:ru,onOpenOrder:t4,showCustomer:!ec}),rd.map(r=>(0,t.jsx)("div",{ref:e=>{tH.current[`order-${r.id}`]=e},children:(0,t.jsx)(tJ,{order:r,expanded:tO.has(r.id),detail:tM[r.id]??null,detailLoading:tR===r.id,onToggle:()=>{tA(e=>{let t=new Set(e);t.has(r.id)?t.delete(r.id):(t.add(r.id),t5(r.id));let n=new URLSearchParams(R.toString());t.size>0?n.set("expand",Array.from(t).sort((e,t)=>e-t).join(",")):n.delete("expand"),n.delete("order"),n.delete("invoice");let s=n.toString(),a=s?`${F}?${s}`:F;window.history.replaceState({},"",a);try{U.replace(a,{scroll:!1})}catch{}return t})},highlightedInvoice:er,highlightedLine:en?Number(en):void 0,moneyTrail:re.get(r.id),v4:_,showAirBadge:"customer-set"===e.kind,hideCustomerName:ec,activeItem:rV})},`order-${r.id}`)),ro&&(rc>0||tS>rd.length||rx.length>0)&&(0,t.jsx)("div",{className:"flex justify-center pt-1",children:(0,t.jsxs)(c.default,{variant:"outline",size:"sm",onClick:()=>tE(!0),children:["Show all",tS>0?` ${tS.toLocaleString("en-US")}`:rc>0?` ${(rd.length+rc).toLocaleString("en-US")}`:""," ","transactions"]})}),"all"===V&&!ro&&rx.map(e=>(0,t.jsx)("div",{ref:t=>{tH.current[`invoice-${e.id}`]=t},children:(0,t.jsx)(t8,{invoice:e,highlighted:er.toLowerCase()===e.invoiceNumber?.toLowerCase()})},`invoice-${e.id}`)),"all"===V&&!ro&&("all"===H||"money-back"===H||"to-pay"===H||"overdue"===H)&&(rr.refunds.length>0||rr.credits.length>0||rr.deposits.length>0)&&(0,t.jsxs)("div",{className:"rounded-xl border border-border-default bg-surface",children:[(0,t.jsxs)("button",{type:"button",onClick:tz,"aria-expanded":tB,"aria-controls":"standalone-events-body",className:"flex w-full items-center justify-between gap-3 px-5 py-3 text-left transition-colors hover:bg-surface-elevated focus:outline-none focus-visible:ring-2 focus-visible:ring-accent",children:[(0,t.jsxs)("div",{className:"min-w-0",children:[(0,t.jsxs)("p",{className:"flex items-center gap-2 text-[10px] font-semibold uppercase tracking-wider text-text-tertiary",children:["Standalone events",(0,t.jsx)("span",{className:"rounded-full bg-surface-elevated px-1.5 py-0.5 font-mono text-[9px] tracking-normal text-text-secondary normal-case",children:rr.refunds.length+rr.credits.length+rr.deposits.length})]}),(0,t.jsx)("p",{className:"mt-0.5 text-xs text-text-muted",children:"Refunds, credits, and payments not linked to a specific order."})]}),tB?(0,t.jsx)(i,{className:"h-4 w-4 flex-shrink-0 text-text-tertiary"}):(0,t.jsx)(s.ChevronDown,{className:"h-4 w-4 flex-shrink-0 text-text-tertiary"})]}),tB&&(0,t.jsxs)("div",{id:"standalone-events-body",className:"border-t border-border-subtle",children:[rr.refunds.map(e=>(0,t.jsx)("div",{ref:t=>{tH.current[`refund-${e.id}`]=t},children:(0,t.jsx)(t7,{row:{kind:"refund",data:e},selectable:!1,selected:!1,onToggleSelect:()=>{},invoicePdfHref:()=>""})},`refund-${e.id}`)),rr.credits.map(e=>(0,t.jsx)("div",{children:(0,t.jsx)(t7,{row:{kind:"credit",data:e},selectable:!1,selected:!1,onToggleSelect:()=>{},invoicePdfHref:()=>""})},`credit-${e.id}`)),rr.deposits.map(e=>(0,t.jsx)("div",{children:(0,t.jsx)(t7,{row:{kind:"deposit",data:e},selectable:!1,selected:!1,onToggleSelect:()=>{},invoicePdfHref:()=>""})},`deposit-${e.id}`))]})]})]}),!tc&&!ro&&"all"===H&&e0.length<tS&&(0,t.jsxs)("div",{className:"flex flex-col items-center gap-2 pt-2",children:[(0,t.jsxs)("p",{className:"text-xs text-text-tertiary",children:["Showing ",e0.length.toLocaleStr
81ing("en-US")," of"," ",tS.toLocaleString("en-US")," orders"]}),(0,t.jsx)(c.default,{variant:"outline",size:"sm",onClick:tG,loading:t$,children:"Load more orders"})]}),!tc&&"all"!==H&&e0.length<tS&&tS>50&&(0,t.jsxs)("p",{className:"pt-2 text-center text-xs text-text-tertiary",children:["Showing matches from the most recent ",e0.length.toLocaleString("en-US")," ","of ",tS.toLocaleString("en-US")," orders. Switch to"," ",(0,t.jsx)("button",{type:"button",onClick:()=>rE("all"),className:"text-accent hover:underline",children:"All"})," ","to load more history."]})]})})}],445799),e.s([],97051)}]);
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.