import{a as e}from"./rolldown-runtime-B0Z9INg1.js";import{$ as t}from"./vendor-charts-iXlq6Rne.js";import{g as n}from"./vendor-react-Dzc9WstK.js";import{t as r}from"./Pagination-CXRYv0dn.js";import{_ as i}from"./vendor-flow-IzlrcDx6.js";import{En as a,Q as o,i as s,jn as c,rn as l}from"./index-HkVQGc9M.js";import{t as u}from"./EmptyState-CsLvB2WD.js";import{t as d}from"./Skeleton-BPr2yo9M.js";import{i as f,n as p,o as m,s as h}from"./format-QkiyqXRi2.js";import{r as g}from"./_shared-Bl6kLtzz.js";var _=e(t(),1),v=i(),y=[{value:`all`,label:`All`},{value:`planned`,label:`Planned`},{value:`dispatched`,label:`On the road`},{value:`completed`,label:`Completed`},{value:`cancelled`,label:`Cancelled`}];function b(){let e=n(),[t,i]=(0,_.useState)(`all`),[b,x]=(0,_.useState)(``),[S,C]=(0,_.useState)(1),w=(0,_.useMemo)(()=>{let e={page:String(S),page_size:`20`};return b.trim()&&(e.search=b.trim()),t!==`all`&&(e.status=t),e},[S,b,t]),{data:T,isLoading:E,isFetching:D}=o(w),O=T?.results??[],k=T?.count??0;return(0,v.jsx)(m,{actions:(0,v.jsxs)(s,{onClick:()=>e(`/admin/dispatch`),children:[(0,v.jsx)(a,{className:`h-4 w-4`}),` Plan a load`]}),toolbar:(0,v.jsxs)(v.Fragment,{children:[y.map(e=>(0,v.jsx)(`button`,{type:`button`,onClick:()=>{i(e.value),C(1)},className:l(`rounded-lg border px-2.5 py-1 text-[12px] font-medium transition-colors`,t===e.value?`border-[var(--color-accent)] bg-[var(--color-accent-soft)] text-[var(--color-accent-ink)]`:`border-[var(--color-border)] bg-[var(--color-surface)] text-[var(--color-text-secondary)] hover:text-[var(--color-text-primary)]`),children:e.label},e.value)),(0,v.jsxs)(`div`,{className:`relative ml-auto w-64`,children:[(0,v.jsx)(c,{className:`pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-[var(--color-text-muted)]`}),(0,v.jsx)(`input`,{value:b,onChange:e=>{x(e.target.value),C(1)},placeholder:`Vehicle, driver, customer…`,className:`h-8 w-full rounded-lg border border-[var(--color-border)] bg-[var(--color-surface)] pl-8 pr-2.5 text-[12.5px] placeholder:text-[var(--color-text-muted)] focus:border-[var(--color-accent)] focus:outline-none`})]})]}),children:(0,v.jsxs)(h,{children:[E?(0,v.jsx)(`div`,{className:`space-y-2`,children:Array.from({length:6}).map((e,t)=>(0,v.jsx)(d,{className:`h-16 w-full`},t))}):O.length===0?(0,v.jsx)(`div`,{className:`grid h-full place-items-center`,children:(0,v.jsx)(u,{icon:a,title:`No loads`,description:`Pick the orders that belong on a lorry from the dispatch queue.`,actionLabel:`Go to the queue`,onAction:()=>e(`/admin/dispatch`)})}):(0,v.jsx)(`div`,{className:l(`space-y-2`,D&&`opacity-70`),children:O.map(t=>(0,v.jsxs)(`button`,{type:`button`,onClick:()=>e(`/admin/dispatch/loads/${t.id}`),className:`flex w-full flex-wrap items-center gap-4 rounded-[var(--radius-card)] border border-[var(--color-border)] bg-[var(--color-surface)] px-4 py-3 text-left transition-all hover:border-[var(--color-accent)] hover:shadow-[var(--shadow-sm)]`,children:[(0,v.jsxs)(`div`,{className:`min-w-[200px] flex-1`,children:[(0,v.jsxs)(`p`,{className:`truncate text-[13px] font-semibold text-[var(--color-text-primary)]`,children:[t.customer_names.length?t.customer_names.slice(0,3).join(` · `):`Empty lorry`,t.customer_names.length>3&&(0,v.jsxs)(`span`,{className:`text-[var(--color-text-muted)]`,children:[` `,`+`,t.customer_names.length-3,` more`]})]}),(0,v.jsxs)(`p`,{className:`text-[11.5px] text-[var(--color-text-muted)]`,children:[(0,v.jsx)(`span`,{className:`font-mono`,children:t.code}),` · `,t.warehouse_name,t.route_name&&` · ${t.route_name}`]})]}),(0,v.jsxs)(`div`,{className:`w-40`,children:[(0,v.jsx)(`p`,{className:`font-mono text-[12.5px] font-semibold text-[var(--color-text-primary)]`,children:t.vehicle_number||`—`}),(0,v.jsxs)(`p`,{className:`truncate text-[11.5px] text-[var(--color-text-muted)]`,children:[t.transporter_name||`Own fleet`,t.driver_name&&` · ${t.driver_name}`]})]}),(0,v.jsxs)(`div`,{className:`w-24 text-center`,children:[(0,v.jsx)(`p`,{className:`text-[13px] font-semibold text-[var(--color-text-primary)] tabular-nums`,children:t.drop_count}),(0,v.jsxs)(`p`,{className:`text-[11px] text-[var(--color-text-muted)]`,children:[`drop`,t.drop_count===1?``:`s`]})]}),(0,v.jsxs)(`div`,{className:`w-28 text-right`,children:[(0,v.jsx)(`p`,{className:`text-[12.5px] text-[var(--color-text-secondary)] tabular-nums`,children:p(t.dispatched_at??t.planned_date)}),(0,v.jsx)(`p`,{className:`text-[11px] text-[var(--color-text-muted)]`,children:t.dispatched_at?`left`:`leaves`})]}),(0,v.jsx)(`div`,{className:`w-28 text-right`,children:Number(t.freight_total)>0&&(0,v.jsxs)(`p`,{className:`text-[12px] text-[var(--color-text-muted)] tabular-nums`,children:[`Freight `,f(t.freight_total)]})}),(0,v.jsx)(g,{status:t.status})]},t.id))}),k>20&&(0,v.jsx)(`div`,{className:`mt-3`,children:(0,v.jsx)(r,{currentPage:S,totalPages:Math.max(1,Math.ceil(k/20)),totalItems:k,pageSize:20,onPageChange:C})})]})})}export{b as default};