import{a as e,t}from"./react-D0JuimcS.js";import{n,o as r}from"./utils-Dac180Gn.js";import{t as i}from"./list-table-dcNbCPvq.js";import{t as a}from"./funnel-BDsPorMA.js";import{t as o}from"./plus-VCCEyniC.js";import{n as s,t as c}from"./filter-sheet-Baado-aR.js";import{Fo as l,Gt as u,Tt as d,ga as f,kr as p,zt as m}from"./index-BP3TYB4i.js";import{t as h}from"./page-content-DDtdeMxM.js";import{t as g}from"./badge-Crg76WQE.js";import{a as _,i as v,n as y,o as b,t as x}from"./dialog-BeOPOVZK.js";import{t as S}from"./list-page-header-48VsPegf.js";import{t as C}from"./auth-status-badge-pVqOsTb5.js";import{t as w}from"./row-actions-_6H5dRTY.js";var T=e(t(),1),E=r(),D={draft:`Draft`,submitted:`Submitted`,approved:`Approved`,rejected:`Rejected`,paid:`Paid`,partially_paid:`Partially Paid`},O={draft:`secondary`,submitted:`default`,approved:`default`,rejected:`destructive`,paid:`default`,partially_paid:`default`};function k(){let e=l(),[t,r]=(0,T.useState)(``),[k,A]=(0,T.useState)(`all`),[j,M]=(0,T.useState)(`all`),[N,P]=(0,T.useState)(`all`),[F,I]=(0,T.useState)(`all`),[L,R]=(0,T.useState)(!1),[z,B]=(0,T.useState)(null),V={};k!==`all`&&(V.pv_status=k),t&&(V.search=t),j!==`all`&&(V.vendor=j),N!==`all`&&(V.branch=N),F!==`all`&&(V.authorized_status=F);let{data:H=[],isLoading:U,refetch:W}=m(V),{data:G=[]}=u(),{data:K=[]}=p(),[q]=d(),J=async()=>{z&&(await q(z).unwrap().catch(()=>{}),B(null),W())},Y=()=>{A(`all`),M(`all`),P(`all`),I(`all`)},X=[k,j,N,F].filter(e=>e!==`all`).length;return(0,E.jsxs)(h,{children:[(0,E.jsx)(S,{title:`Purchase Invoices`,description:`Financial liabilities for vendor payments`,searchPlaceholder:`Search vouchers...`,searchValue:t,onSearchChange:r,action:(0,E.jsxs)(f,{onClick:()=>e(`/purchase/vouchers/new`),size:`sm`,children:[(0,E.jsx)(o,{className:`mr-2 h-4 w-4`}),` New Voucher`]}),filter:(0,E.jsxs)(f,{variant:`outline`,size:`sm`,onClick:()=>R(!0),className:`relative`,children:[(0,E.jsx)(a,{className:`mr-2 h-4 w-4`}),` Filters`,X>0&&(0,E.jsx)(g,{variant:`destructive`,className:`ml-2 size-5 p-0 flex items-center justify-center text-[10px]`,children:X})]})}),(0,E.jsx)(i,{data:H,onRowClick:t=>e(`/purchase/vouchers/${t.id}`),columns:[{key:`code`,label:`Code`,render:e=>(0,E.jsx)(`span`,{className:`font-mono`,children:e.code})},{key:`purchase_order_code`,label:`PO Code`,render:e=>(0,E.jsx)(`span`,{className:`font-mono text-xs`,children:e.purchase_order_code})},{key:`vendor_name`,label:`Vendor`},{key:`voucher_date`,label:`Voucher Date`,render:e=>n(e.voucher_date)},{key:`invoice_number`,label:`Invoice Number`},{key:`pv_status`,label:`Status`,render:e=>(0,E.jsx)(g,{variant:O[e.pv_status]||`secondary`,children:D[e.pv_status]||e.pv_status})},{key:`grand_total`,label:`Grand Total`,className:`text-center`,render:e=>(0,E.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,E.jsx)(C,{status:e.authorized_status})},{key:`actions`,label:`Actions`,sortable:!1,render:t=>(0,E.jsx)(w,{onView:()=>e(`/purchase/vouchers/${t.id}`),onEdit:()=>e(`/purchase/vouchers/${t.id}/edit`),onDelete:()=>B(t.id)})}],isLoading:U,rowKey:e=>e.id,emptyMessage:`No purchase invoices found`}),(0,E.jsxs)(s,{open:L,onOpenChange:R,onClear:Y,children:[(0,E.jsx)(c,{label:`Status`,value:k,onChange:A,placeholder:`All Status`,options:Object.entries(D).map(([e,t])=>({value:e,label:t}))}),(0,E.jsx)(c,{label:`Vendor`,value:j,onChange:M,placeholder:`All Vendors`,options:G.map(e=>({value:String(e.id),label:e.name}))}),(0,E.jsx)(c,{label:`Branch`,value:N,onChange:P,placeholder:`All Branches`,options:K.map(e=>({value:String(e.id),label:e.name}))}),(0,E.jsx)(c,{label:`Authorization`,value:F,onChange:I,placeholder:`All`,options:[{value:`1`,label:`Pending`},{value:`2`,label:`Approved`},{value:`3`,label:`Rejected`}]})]}),(0,E.jsx)(x,{open:!!z,onOpenChange:e=>{e||B(null)},children:(0,E.jsxs)(y,{className:`sm:max-w-md`,children:[(0,E.jsx)(_,{children:(0,E.jsx)(b,{children:`Delete Purchase Invoice`})}),(0,E.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Are you sure you want to delete this purchase invoice?`}),(0,E.jsxs)(v,{children:[(0,E.jsx)(f,{variant:`outline`,size:`sm`,onClick:()=>B(null),children:`Cancel`}),(0,E.jsx)(f,{variant:`destructive`,size:`sm`,onClick:J,children:`Delete`})]})]})})]})}export{k as default};