import{a as e,t}from"./react-DK-MTtD8.js";import{r as n,s as r}from"./utils-CXcsdpX-.js";import{r as i}from"./api-DcvYaav1.js";import{t as a}from"./list-table-CQD2C7IB.js";import{t as o}from"./funnel-BT4pjjO7.js";import{t as s}from"./plus-CuMPbIyn.js";import{n as c,t as l}from"./filter-sheet-omdfG0qY.js";import{Hr as u,Ot as d,rs as f,tn as p,za as m,zt as h}from"./index-Ct5uU080.js";import{t as g}from"./page-content-Bh5Zxb_Y.js";import{t as _}from"./badge-CL1e8lO_.js";import{a as v,i as y,n as b,o as x,t as S}from"./dialog-DuXDR687.js";import{t as C}from"./list-page-header-CePoWpko.js";import{t as w}from"./auth-status-badge-BlJK5R24.js";import{t as T}from"./row-actions-bhl00K6X.js";var E=e(t(),1),D=r(),O={draft:`Draft`,submitted:`Submitted`,approved:`Approved`,rejected:`Rejected`},k={draft:`secondary`,submitted:`default`,approved:`default`,rejected:`destructive`};function A(){let e=f(),[t,r]=(0,E.useState)(``),[A,j]=(0,E.useState)(`all`),[M,N]=(0,E.useState)(`all`),[P,F]=(0,E.useState)(`all`),[I,L]=(0,E.useState)(`all`),[R,z]=(0,E.useState)(!1),[B,V]=(0,E.useState)(null),H={};A!==`all`&&(H.mrn_status=A),t&&(H.search=t),M!==`all`&&(H.vendor=M),P!==`all`&&(H.branch=P),I!==`all`&&(H.authorized_status=I);let{data:U=[],isLoading:W,refetch:G}=h(H),{data:K=[]}=p(),{data:q=[]}=u(),[J]=d(),Y=async()=>{B&&(await J(B).unwrap().catch(()=>{}),V(null),G())},X=()=>{j(`all`),N(`all`),F(`all`),L(`all`)},Z=[A,M,P,I].filter(e=>e!==`all`).length;return(0,D.jsxs)(g,{children:[(0,D.jsx)(C,{title:`Material Receipt Notes`,description:`Goods received against approved purchase orders`,searchPlaceholder:`Search MRNs...`,searchValue:t,onSearchChange:r,action:(0,D.jsxs)(m,{onClick:()=>e(`/purchase/mrns/new`),size:`sm`,children:[(0,D.jsx)(s,{className:`mr-2 h-4 w-4`}),` New MRN`]}),filter:(0,D.jsxs)(m,{variant:`outline`,size:`sm`,onClick:()=>z(!0),className:`relative`,children:[(0,D.jsx)(o,{className:`mr-2 h-4 w-4`}),` Filters`,Z>0&&(0,D.jsx)(_,{variant:`destructive`,className:`ml-2 size-5 p-0 flex items-center justify-center text-[10px]`,children:Z})]})}),(0,D.jsx)(a,{data:U,onRowClick:t=>e(`/purchase/mrns/${t.id}`),columns:[{key:`code`,label:`Code`,render:e=>(0,D.jsx)(`span`,{className:`font-mono`,children:e.code})},{key:`tender_number`,label:`Tender No`,render:e=>(0,D.jsx)(`span`,{className:`font-mono text-xs`,children:e.tender_number||`—`})},{key:`purchase_order_code`,label:`PO Code`,render:e=>(0,D.jsx)(`span`,{className:`font-mono text-xs`,children:e.purchase_order_code})},{key:`vendor_name`,label:`Vendor`},{key:`mrn_date`,label:`MRN Date`,render:e=>n(e.mrn_date)},{key:`mrn_status`,label:`Status`,render:e=>(0,D.jsx)(_,{variant:k[e.mrn_status]||`secondary`,children:O[e.mrn_status]||e.mrn_status})},{key:`grand_total`,label:`Grand Total`,className:`text-center`,render:e=>(0,D.jsx)(`span`,{className:`font-mono`,children:Number(e.grand_total).toLocaleString()})},{key:`branch_name`,label:`Branch`},{key:`authorized_status`,label:`Approval Status`,render:e=>(0,D.jsx)(w,{status:e.authorized_status})},{key:`actions`,label:`Actions`,sortable:!1,render:t=>(0,D.jsx)(T,{onView:()=>e(`/purchase/mrns/${t.id}`),onEdit:()=>e(`/purchase/mrns/${t.id}/edit`),onDelete:()=>V(t.id),approval:{entityType:`MaterialReceiptNote`,objectId:t.id,contentTypeId:i.MRN,authorizedStatus:t.authorized_status??1,onApprovalChange:()=>G()}})}],isLoading:W,rowKey:e=>e.id,emptyMessage:`No material receipt notes found`}),(0,D.jsxs)(c,{open:R,onOpenChange:z,onClear:X,children:[(0,D.jsx)(l,{label:`Status`,value:A,onChange:j,placeholder:`All Status`,options:Object.entries(O).map(([e,t])=>({value:e,label:t}))}),(0,D.jsx)(l,{label:`Vendor`,value:M,onChange:N,placeholder:`All Vendors`,options:K.map(e=>({value:String(e.id),label:e.name}))}),(0,D.jsx)(l,{label:`Branch`,value:P,onChange:F,placeholder:`All Branches`,options:q.map(e=>({value:String(e.id),label:e.name}))}),(0,D.jsx)(l,{label:`Authorization`,value:I,onChange:L,placeholder:`All`,options:[{value:`1`,label:`Pending`},{value:`2`,label:`Approved`},{value:`3`,label:`Rejected`}]})]}),(0,D.jsx)(S,{open:!!B,onOpenChange:e=>{e||V(null)},children:(0,D.jsxs)(b,{className:`sm:max-w-md`,children:[(0,D.jsx)(v,{children:(0,D.jsx)(x,{children:`Delete Material Receipt Note`})}),(0,D.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Are you sure you want to delete this MRN?`}),(0,D.jsxs)(y,{children:[(0,D.jsx)(m,{variant:`outline`,size:`sm`,onClick:()=>V(null),children:`Cancel`}),(0,D.jsx)(m,{variant:`destructive`,size:`sm`,onClick:Y,children:`Delete`})]})]})})]})}export{A as default};