import{i as e}from"./rolldown-runtime-Dd_uD5pT.js";import{t}from"./react-BatatxyT.js";import{r as n,s as r}from"./utils-BO1RPuol.js";import{t as i}from"./list-table-DNq_Jbx2.js";import{t as a}from"./funnel-CzLimyxu.js";import{t as o}from"./plus-BEDg_66Y.js";import{n as s,t as c}from"./filter-sheet-guEWYDqt.js";import{Hr as l,Nt as u,Yt as d,os as f,tn as p,za as m}from"./index-CsuVxiRQ.js";import{t as h}from"./page-content-DdXVZwik.js";import{t as g}from"./badge-DLCseWie.js";import{a as _,i as v,n as y,o as b,t as x}from"./dialog-BT7QjyH-.js";import{t as S}from"./list-page-header-BnFKDjpb.js";import{t as C}from"./auth-status-badge-C6fBtAs6.js";import{t as w}from"./row-actions-DALRrgnK.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=f(),[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}=d(V),{data:G=[]}=p(),{data:K=[]}=l(),[q]=u(),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)(m,{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)(m,{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:`tender_number`,label:`Tender No`,render:e=>(0,E.jsx)(`span`,{className:`font-mono text-xs`,children:e.tender_number||`—`})},{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)(m,{variant:`outline`,size:`sm`,onClick:()=>B(null),children:`Cancel`}),(0,E.jsx)(m,{variant:`destructive`,size:`sm`,onClick:J,children:`Delete`})]})]})})]})}export{k as default};