import{a as e,t}from"./react-D0JuimcS.js";import{n,o as r}from"./utils-Dac180Gn.js";import{r as i}from"./api-NMlTtVre.js";import{t as a}from"./list-table-dcNbCPvq.js";import{t as o}from"./funnel-BDsPorMA.js";import{t as s}from"./plus-VCCEyniC.js";import{n as c,t as l}from"./filter-sheet-Baado-aR.js";import{Fo as u,Gt as d,St as f,ga as p,jt as m,kr as h}from"./index-BP3TYB4i.js";import{t as g}from"./page-content-DDtdeMxM.js";import{t as _}from"./badge-Crg76WQE.js";import{a as v,i as y,n as b,o as x,t as S}from"./dialog-BeOPOVZK.js";import{t as C}from"./list-page-header-48VsPegf.js";import{t as w}from"./auth-status-badge-pVqOsTb5.js";import{t as T}from"./row-actions-_6H5dRTY.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=u(),[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}=m(H),{data:K=[]}=d(),{data:q=[]}=h(),[J]=f(),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)(p,{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)(p,{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:`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)(p,{variant:`outline`,size:`sm`,onClick:()=>V(null),children:`Cancel`}),(0,D.jsx)(p,{variant:`destructive`,size:`sm`,onClick:Y,children:`Delete`})]})]})})]})}export{A as default};