import{i as e}from"./rolldown-runtime-Dd_uD5pT.js";import{t}from"./react-BatatxyT.js";import{r as n,s as r}from"./utils-BO1RPuol.js";import{t as i}from"./list-table-DNq_Jbx2.js";import{t as a}from"./funnel-CzLimyxu.js";import{n as o,t as s}from"./filter-sheet-guEWYDqt.js";import{Ci as c,os as l,za as u}from"./index-CsuVxiRQ.js";import{t as d}from"./page-content-DdXVZwik.js";import{t as f}from"./badge-DLCseWie.js";import{t as p}from"./list-page-header-BnFKDjpb.js";import{a as m}from"./inventoryApi-BDhL4nCe.js";var h=e(t(),1),g=r(),_={inbound:`Inbound`,outbound:`Outbound`,adjustment_in:`Adjustment In`,adjustment_out:`Adjustment Out`,transfer_in:`Transfer In`,transfer_out:`Transfer Out`},v={draft:`secondary`,confirmed:`default`,cancelled:`destructive`},y=[{value:`inbound`,label:`Inbound`},{value:`outbound`,label:`Outbound`},{value:`adjustment_in`,label:`Adjustment In`},{value:`adjustment_out`,label:`Adjustment Out`},{value:`transfer_in`,label:`Transfer In`},{value:`transfer_out`,label:`Transfer Out`}],b=[{value:`draft`,label:`Draft`},{value:`confirmed`,label:`Confirmed`},{value:`cancelled`,label:`Cancelled`}],x=[{value:`MRN`,label:`MRN`},{value:`Manual`,label:`Manual`}];function S(){let e=l(),[t,r]=(0,h.useState)(``),[S,C]=(0,h.useState)(`all`),[w,T]=(0,h.useState)(`all`),[E,D]=(0,h.useState)(`all`),[O,k]=(0,h.useState)(`all`),[A,j]=(0,h.useState)(``),[M,N]=(0,h.useState)(``),[P,F]=(0,h.useState)(!1),I={};S!==`all`&&(I.warehouse=S),w!==`all`&&(I.movement_type=w),E!==`all`&&(I.movement_status=E),O!==`all`&&(I.reference_type=O),A&&(I.movement_date_after=A),M&&(I.movement_date_before=M),t&&(I.search=t);let{data:L=[],isLoading:R}=m(Object.keys(I).length?I:void 0),{data:z=[]}=c(),B=()=>{C(`all`),T(`all`),D(`all`),k(`all`),j(``),N(``)},V=(0,h.useMemo)(()=>{let e=0;return S!==`all`&&e++,w!==`all`&&e++,E!==`all`&&e++,O!==`all`&&e++,(A||M)&&e++,e},[S,w,E,O,A,M]);return(0,g.jsxs)(d,{children:[(0,g.jsx)(p,{title:`Stock Movements`,description:`All inventory transactions and movements`,searchPlaceholder:`Search by code, item code, or description...`,searchValue:t,onSearchChange:r,filter:(0,g.jsxs)(u,{variant:`outline`,size:`sm`,onClick:()=>F(!0),className:`relative`,children:[(0,g.jsx)(a,{className:`mr-2 h-4 w-4`}),` Filters`,V>0&&(0,g.jsx)(f,{variant:`destructive`,className:`ml-2 size-5 p-0 flex items-center justify-center text-[10px]`,children:V})]})}),(0,g.jsx)(i,{data:L,onRowClick:t=>e(`/inventory/stock-movements/${t.id}`),columns:[{key:`code`,label:`Code`,render:e=>(0,g.jsx)(`span`,{className:`font-mono text-xs`,children:e.code})},{key:`warehouse_name`,label:`Warehouse`},{key:`item_description`,label:`Item`},{key:`movement_type`,label:`Type`,render:e=>_[e.movement_type]||e.movement_type},{key:`movement_date`,label:`Date`,render:e=>n(e.movement_date)},{key:`quantity`,label:`Quantity`,className:`text-center`,render:e=>(0,g.jsx)(`span`,{className:`font-mono`,children:Number(e.quantity).toLocaleString()})},{key:`unit_cost`,label:`Unit Cost`,className:`text-center`,render:e=>(0,g.jsx)(`span`,{className:`font-mono`,children:Number(e.unit_cost).toLocaleString(void 0,{minimumFractionDigits:2})})},{key:`total_cost`,label:`Total Cost`,className:`text-center`,render:e=>(0,g.jsx)(`span`,{className:`font-mono font-semibold`,children:Number(e.total_cost).toLocaleString(void 0,{minimumFractionDigits:2})})},{key:`movement_status`,label:`Status`,render:e=>(0,g.jsx)(f,{variant:v[e.movement_status]||`secondary`,children:e.movement_status})},{key:`reference_code`,label:`Reference`,render:e=>e.reference_code?(0,g.jsxs)(`span`,{className:`font-mono text-xs`,children:[e.reference_type,`: `,e.reference_code]}):`—`}],isLoading:R,rowKey:e=>e.id,emptyMessage:`No stock movements found`}),(0,g.jsxs)(o,{open:P,onOpenChange:F,onClear:B,children:[(0,g.jsx)(s,{label:`Warehouse`,value:S,onChange:C,placeholder:`All Warehouses`,options:z.map(e=>({value:String(e.id),label:e.name}))}),(0,g.jsx)(s,{label:`Movement Type`,value:w,onChange:T,placeholder:`All Types`,options:y}),(0,g.jsx)(s,{label:`Status`,value:E,onChange:D,placeholder:`All Statuses`,options:b}),(0,g.jsx)(s,{label:`Reference Type`,value:O,onChange:k,placeholder:`All References`,options:x}),(0,g.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,g.jsx)(`label`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:`Date Range`}),(0,g.jsxs)(`div`,{className:`flex gap-2`,children:[(0,g.jsx)(`input`,{type:`date`,value:A,onChange:e=>j(e.target.value),className:`flex h-9 w-full rounded-md border border-input bg-background px-3 py-1 text-sm shadow-sm focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`}),(0,g.jsx)(`input`,{type:`date`,value:M,onChange:e=>N(e.target.value),className:`flex h-9 w-full rounded-md border border-input bg-background px-3 py-1 text-sm shadow-sm focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`})]})]})]})]})}export{S as default};