import{r as f,j as t,e as l,C as h}from"./index-B1H8BCL7.js";import{l as S}from"./stockApi-D1nxeMJU.js";import{R as x}from"./ReportPageShell-B7ORyOeG.js";import{G as i}from"./Grid-CTEl0Elf.js";import"./FileDownloadOutlined-B1TjRPKt.js";import"./Refresh-942gtAB1.js";import"./Stack-BIAbaqpj.js";import"./useThemeProps-DL_l3A7P.js";import"./TableContainer-CXAjhAg6.js";import"./TableRow-BfKE_xn9.js";import"./TableCell-D8CotAsC.js";const m={EXPIRED:{bg:"#fef2f2",fg:"#b91c1c"},DAMAGED:{bg:"#fef2f2",fg:"#b91c1c"},BROKEN:{bg:"#fef2f2",fg:"#b91c1c"},CONTAMINATED:{bg:"#fef2f2",fg:"#b91c1c"},SPILLAGE:{bg:"#fef3c7",fg:"#b45309"},TRANSIT_LOSS:{bg:"#fef3c7",fg:"#b45309"},QC_FAILURE:{bg:"#fef3c7",fg:"#b45309"},MACHINE_PRIME:{bg:"#eff6ff",fg:"#1d4ed8"},OPENING_LOSS:{bg:"#eff6ff",fg:"#1d4ed8"},MANUAL_CORRECTION:{bg:"#f1f5f9",fg:"#475569"},OTHER:{bg:"#f1f5f9",fg:"#475569"}},R=[{key:"reason",header:"Reason",width:160,format:e=>{const a=m[e]??m.OTHER;return t.jsx(h,{size:"small",label:(e||"").replaceAll("_"," "),sx:{height:18,fontSize:"0.62rem",fontWeight:700,letterSpacing:"0.04em",backgroundColor:a.bg,color:a.fg,borderRadius:"4px"}})}},{key:"itemCode",header:"Item Code",width:110},{key:"itemName",header:"Item"},{key:"totalQty",header:"Qty",align:"right",format:E},{key:"totalValue",header:"Total Value",align:"right",format:g},{key:"entriesCount",header:"Entries",align:"right"}],P=()=>{const[e,a]=f.useState(N()),[s,u]=f.useState(I()),{data:o,isFetching:c,refetch:b}=S({from:e,to:s}),n=(o==null?void 0:o.list)??[],d=n.reduce((r,p)=>r+(Number(p.totalValue)||0),0);return t.jsx(x,{title:"Wastage Summary",subtitle:`Aggregated by (reason × item). Total write-off value: ${g(d)}`,filters:t.jsxs(i,{container:!0,spacing:1.5,children:[t.jsx(i,{item:!0,xs:6,sm:3,children:t.jsx(l,{label:"From",type:"date",size:"small",fullWidth:!0,InputLabelProps:{shrink:!0},value:e,onChange:r=>a(r.target.value)})}),t.jsx(i,{item:!0,xs:6,sm:3,children:t.jsx(l,{label:"To",type:"date",size:"small",fullWidth:!0,InputLabelProps:{shrink:!0},value:s,onChange:r=>u(r.target.value)})})]}),columns:R,rows:n,isFetching:c,refetch:b,csvFilenameStem:"wastage"})};function E(e){return e==null?"0":Number(e).toLocaleString("en-IN",{minimumFractionDigits:0,maximumFractionDigits:3})}function g(e){return e==null?"0.00":Number(e).toLocaleString("en-IN",{minimumFractionDigits:2,maximumFractionDigits:2})}function I(){return new Date().toISOString().slice(0,10)}function N(){const e=new Date;return e.setDate(e.getDate()-30),e.toISOString().slice(0,10)}export{P as default};
