import{a as e,t}from"./react-D0JuimcS.js";import{o as n}from"./utils-Dac180Gn.js";import{t as r}from"./list-table-dcNbCPvq.js";import{t as i}from"./funnel-BDsPorMA.js";import{n as a,t as o}from"./filter-sheet-Baado-aR.js";import{Fo as s,La as c,eo as l,ga as u,mo as d,ui as f}from"./index-BP3TYB4i.js";import{t as p}from"./page-content-DDtdeMxM.js";import{t as m}from"./card-BVFw-jgA.js";import{t as h}from"./badge-Crg76WQE.js";import{t as g}from"./list-page-header-48VsPegf.js";import{s as _}from"./inventoryApi-BpMmJXTM.js";var v=e(t(),1),y=n();function b(){let e=s(),[t,n]=(0,v.useState)(``),[b,x]=(0,v.useState)(`all`),[S,C]=(0,v.useState)(`all`),[w,T]=(0,v.useState)(!1),E={};b!==`all`&&(E.warehouse=b),t&&(E.search=t);let{data:D=[],isLoading:O}=_(Object.keys(E).length?E:void 0),{data:k=[]}=f(),A=(0,v.useMemo)(()=>S===`all`?D:D.filter(e=>e.item_category===S),[D,S]),j=(0,v.useMemo)(()=>{let e=new Set(D.map(e=>e.item_category).filter(Boolean));return Array.from(e).sort()},[D]),M=A.length,N=A.reduce((e,t)=>e+Number(t.total_value||0),0),P=new Set(A.map(e=>e.warehouse_name)).size,F=()=>{x(`all`),C(`all`)},I=[b,S].filter(e=>e!==`all`).length;return(0,y.jsxs)(p,{children:[(0,y.jsx)(g,{title:`Stock Records`,description:`Current inventory levels across all warehouses`,searchPlaceholder:`Search by item code or description...`,searchValue:t,onSearchChange:n,filter:(0,y.jsxs)(u,{variant:`outline`,size:`sm`,onClick:()=>T(!0),className:`relative`,children:[(0,y.jsx)(i,{className:`mr-2 h-4 w-4`}),` Filters`,I>0&&(0,y.jsx)(h,{variant:`destructive`,className:`ml-2 size-5 p-0 flex items-center justify-center text-[10px]`,children:I})]})}),(0,y.jsxs)(`div`,{className:`grid grid-cols-3 gap-4`,children:[(0,y.jsxs)(m,{className:`p-4 flex items-center gap-3`,children:[(0,y.jsx)(`div`,{className:`rounded-md bg-blue-50 p-2`,children:(0,y.jsx)(l,{className:`h-5 w-5 text-blue-600`})}),(0,y.jsxs)(`div`,{children:[(0,y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Total Items Tracked`}),(0,y.jsx)(`p`,{className:`text-xl font-semibold`,children:M.toLocaleString()})]})]}),(0,y.jsxs)(m,{className:`p-4 flex items-center gap-3`,children:[(0,y.jsx)(`div`,{className:`rounded-md bg-green-50 p-2`,children:(0,y.jsx)(d,{className:`h-5 w-5 text-green-600`})}),(0,y.jsxs)(`div`,{children:[(0,y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Total Inventory Value`}),(0,y.jsx)(`p`,{className:`text-xl font-semibold`,children:N.toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2})})]})]}),(0,y.jsxs)(m,{className:`p-4 flex items-center gap-3`,children:[(0,y.jsx)(`div`,{className:`rounded-md bg-purple-50 p-2`,children:(0,y.jsx)(c,{className:`h-5 w-5 text-purple-600`})}),(0,y.jsxs)(`div`,{children:[(0,y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Warehouses`}),(0,y.jsx)(`p`,{className:`text-xl font-semibold`,children:P})]})]})]}),(0,y.jsx)(r,{data:A,onRowClick:t=>e(`/inventory/stock-records/${t.id}`),columns:[{key:`item_code`,label:`Item Code`,render:e=>(0,y.jsx)(`span`,{className:`font-mono text-xs`,children:e.item_code})},{key:`item_description`,label:`Item Description`},{key:`warehouse_name`,label:`Warehouse`},{key:`item_category`,label:`Category`},{key:`quantity_on_hand`,label:`Qty on Hand`,className:`text-center`,render:e=>(0,y.jsx)(`span`,{className:`font-mono`,children:Number(e.quantity_on_hand).toLocaleString()})},{key:`average_cost`,label:`Avg Cost`,className:`text-center`,render:e=>(0,y.jsx)(`span`,{className:`font-mono`,children:Number(e.average_cost).toLocaleString(void 0,{minimumFractionDigits:2})})},{key:`total_value`,label:`Total Value`,className:`text-center`,render:e=>(0,y.jsx)(`span`,{className:`font-mono font-semibold`,children:Number(e.total_value).toLocaleString(void 0,{minimumFractionDigits:2})})}],isLoading:O,rowKey:e=>e.id,emptyMessage:`No stock records found`}),(0,y.jsxs)(a,{open:w,onOpenChange:T,onClear:F,children:[(0,y.jsx)(o,{label:`Warehouse`,value:b,onChange:x,placeholder:`All Warehouses`,options:k.map(e=>({value:String(e.id),label:e.name}))}),(0,y.jsx)(o,{label:`Item Category`,value:S,onChange:C,placeholder:`All Categories`,options:j.map(e=>({value:e,label:e}))})]})]})}export{b as default};