import{a as e,t}from"./react-DK-MTtD8.js";import{s as n}from"./utils-CXcsdpX-.js";import{t as r}from"./list-table-CQD2C7IB.js";import{t as i}from"./funnel-BT4pjjO7.js";import{n as a,t as o}from"./filter-sheet-omdfG0qY.js";import{Ci as s,Lo as c,So as l,ao as u,rs as d,za as f}from"./index-Ct5uU080.js";import{t as p}from"./page-content-Bh5Zxb_Y.js";import{t as m}from"./card-CCLQVS9k.js";import{t as h}from"./badge-CL1e8lO_.js";import{t as g}from"./list-page-header-CePoWpko.js";import{s as _}from"./inventoryApi-Cjq7hXA7.js";var v=e(t(),1),y=n();function b(){let e=d(),[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=[]}=s(),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)(f,{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)(c,{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)(u,{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_name`,label:`Item Name`,render:e=>e.item_name||e.item_description||`—`},{key:`item_description`,label:`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};