import{u as w,r as l,j as i,b as t,S as R,A as f,d as T,c as g,e as C,t as A,B as r,bc as y}from"./index-BiWH3VAt.js";import{P as E,S as F}from"./SectionCard-Dnomuq8E.js";import{S as W}from"./StatusPill-PU3UH01Y.js";import{R as k}from"./RowActionsMenu-ysuq3my_.js";import{u as B}from"./StockTransferReceiveAPI-CpisQsXn.js";import{u as _}from"./branchApi-BYhxRmGe.js";import"./Breadcrumbs-DDQs7r4b.js";const M={POSTED:"success",CANCELLED:"error",DRAFT:"default"},Q=()=>{const n=w(),[o,p]=l.useState({page:0,pageSize:20}),{data:s,isLoading:x,refetch:v}=B({page:o.page,size:o.pageSize,sort:"created_date,desc"}),d=l.useMemo(()=>s??[],[s]),{data:c=[]}=_(),N=l.useMemo(()=>{const e=new Map;return c.forEach(a=>e.set(a.id,a.name??a.organizationName??"")),e},[c]),m=(e,a)=>(e!=null?N.get(e):void 0)??a??(e!=null?`#${e}`:"—"),S=e=>[{key:"view",label:"View",icon:t(y,{fontSize:"small"}),onClick:()=>n(`${g.STOCK_TRANSFER_RECEIVE}/view/${e.id}`)}];return i(r,{sx:{width:"100%",minHeight:"calc(100vh - 64px)",bgcolor:e=>e.palette.mode==="dark"?e.palette.background.default:"#F8FAFC",px:{xs:2,md:3},py:{xs:2,md:2.5}},children:[t(E,{breadcrumbs:[{label:"Inventory"},{label:"Stock Transfer Receive"}],title:"Stock Transfer Receive",subtitle:"MRN-style receive: stock added to this branch with batch + tax detail",actions:i(R,{direction:"row",spacing:1,children:[t(f,{btnType:"info",onClick:()=>v(),children:"Refresh"}),i(f,{btnType:"create",onClick:()=>n(g.STOCK_TRANSFER_RECEIVE_CREATE),children:[t(T,{fontSize:"small",sx:{mr:.5}}),"New Receive"]})]})}),t(F,{noPadding:!0,children:t(C,{rows:d,columns:[{field:"receiveNo",headerName:"Receive No",flex:1,minWidth:160,renderCell:e=>t(r,{sx:{fontWeight:600,color:"text.primary"},children:e.value})},{field:"transferNo",headerName:"Transfer No",flex:1,minWidth:140},{field:"fromBranchName",headerName:"From → To",flex:1.4,minWidth:200,renderCell:e=>i(r,{sx:{fontSize:13},children:[t(r,{component:"span",sx:{color:"text.primary",fontWeight:500},children:m(e.row.fromBranchId,e.row.fromBranchName)}),t(r,{component:"span",sx:{color:"text.secondary",mx:.75},children:"→"}),t(r,{component:"span",sx:{color:"text.primary",fontWeight:500},children:m(e.row.toBranchId,e.row.toBranchName)})]})},{field:"receiveDate",headerName:"Receive Date",flex:.8,minWidth:120,valueFormatter:e=>e.value?A(e.value):""},{field:"materialType",headerName:"Material",flex:.8,minWidth:120,valueFormatter:e=>{var a;return((a=e.value)==null?void 0:a.replace(/_/g," "))??""}},{field:"uomName",headerName:"UOM",flex:.5,minWidth:70,valueGetter:e=>{var u;const a=((u=e.row)==null?void 0:u.products)??[],h=Array.from(new Set(a.map(b=>(b.uomName??"").trim()).filter(Boolean)));return h.length===0?"—":h.join(", ")}},{field:"totalQty",headerName:"Qty",flex:.5,minWidth:80,align:"right",headerAlign:"right"},{field:"totalChargesAmount",headerName:"Charges",flex:.6,minWidth:100,align:"right",headerAlign:"right",valueFormatter:e=>e.value!=null?Number(e.value).toFixed(2):""},{field:"grandTotal",headerName:"Grand Total",flex:.7,minWidth:120,align:"right",headerAlign:"right",valueFormatter:e=>e.value!=null?Number(e.value).toFixed(2):""},{field:"status",headerName:"Status",flex:.8,minWidth:130,renderCell:e=>{var a;return t(W,{label:((a=e.value)==null?void 0:a.replace(/_/g," "))??"—",tone:M[e.value]??"default",size:"small"})}},{field:"actions",headerName:"",width:72,sortable:!1,filterable:!1,align:"right",headerAlign:"right",renderCell:e=>t(k,{actions:S(e.row)})}],loading:x,rowCount:d.length,paginationModel:o,onPaginationModelChange:e=>p(e),getRowId:e=>e.id??0,height:"calc(100vh - 220px)"})})]})};export{Q as default};
