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-M8Qu8ozW.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-ChUwrDC4.js";import{Fo as l,Mr as u,P as d,ga as f,kr as p}from"./index-8M5AnKdQ.js";import{t as m}from"./page-content-DDtdeMxM.js";import{t as h}from"./badge-Crg76WQE.js";import{t as g}from"./list-page-header-DTmo84Zp.js";import{t as _}from"./row-actions-CXQ090e_.js";import{t as v}from"./workflow-status-badge-B5qOWo7t.js";var y=e(t(),1),b=r(),x=[{value:`draft`,label:`Draft`},{value:`submitted`,label:`Submitted`},{value:`approved`,label:`Approved`},{value:`sent`,label:`Sent`},{value:`paid`,label:`Paid`},{value:`partially_paid`,label:`Partially Paid`},{value:`cancelled`,label:`Cancelled`}];function S(){let e=l(),[t,r]=(0,y.useState)(``),[S,C]=(0,y.useState)(`all`),[w,T]=(0,y.useState)(`all`),[E,D]=(0,y.useState)(`all`),[O,k]=(0,y.useState)(`all`),[A,j]=(0,y.useState)(!1),M={};S!==`all`&&(M.status=S),w!==`all`&&(M.invoice_type=w),t&&(M.search=t),E!==`all`&&(M.branch=E),O!==`all`&&(M.client=O);let{data:N=[],isLoading:P}=d(M),{data:F=[]}=p(),{data:I=[]}=u(),L=()=>{C(`all`),T(`all`),D(`all`),k(`all`)},R=[S,w,E,O].filter(e=>e!==`all`).length;return(0,b.jsxs)(m,{children:[(0,b.jsx)(g,{title:`Sales Invoices`,description:`Invoices generated against confirmed sales orders`,searchPlaceholder:`Search by invoice number, client, SO code...`,searchValue:t,onSearchChange:r,action:(0,b.jsxs)(f,{onClick:()=>e(`/sales-invoices/new`),children:[(0,b.jsx)(o,{className:`size-4 mr-2`}),` Create Invoice`]}),filter:(0,b.jsxs)(f,{variant:`outline`,size:`sm`,onClick:()=>j(!0),className:`relative`,children:[(0,b.jsx)(a,{className:`mr-2 h-4 w-4`}),` Filters`,R>0&&(0,b.jsx)(h,{variant:`destructive`,className:`ml-2 size-5 p-0 flex items-center justify-center text-[10px]`,children:R})]})}),(0,b.jsx)(i,{data:N,onRowClick:t=>e(`/sales-invoices/${t.id}`),columns:[{key:`code`,label:`Invoice No`,render:e=>(0,b.jsx)(`span`,{className:`font-mono`,children:e.code})},{key:`invoice_date`,label:`Date`,render:e=>n(e.invoice_date)},{key:`client_name`,label:`Client`},{key:`sales_order_code`,label:`Linked SO`,render:e=>(0,b.jsx)(`span`,{className:`font-mono text-xs`,children:e.sales_order_code})},{key:`net_payable`,label:`Net Payable`,className:`text-center`,render:e=>(0,b.jsx)(`span`,{className:`font-mono`,children:Number(e.net_payable).toLocaleString()})},{key:`outstanding_amount`,label:`Outstanding`,className:`text-center`,render:e=>(0,b.jsx)(`span`,{className:`font-mono`,children:Number(e.outstanding_amount).toLocaleString()})},{key:`status`,label:`Status`,render:e=>(0,b.jsx)(v,{status:e.status})},{key:`branch_name`,label:`Branch`,render:e=>e.branch_name||`—`},{key:`actions`,label:`Actions`,sortable:!1,render:t=>(0,b.jsx)(_,{onView:()=>e(`/sales-invoices/${t.id}`),onEdit:()=>e(`/sales-invoices/${t.id}/edit`),onDelete:()=>{}})}],isLoading:P,rowKey:e=>e.id,emptyMessage:`No sales invoices found`}),(0,b.jsxs)(s,{open:A,onOpenChange:j,onClear:L,children:[(0,b.jsx)(c,{label:`Status`,value:S,onChange:C,placeholder:`All Status`,options:x}),(0,b.jsx)(c,{label:`Branch`,value:E,onChange:D,placeholder:`All Branches`,options:F.map(e=>({value:String(e.id),label:e.name}))}),(0,b.jsx)(c,{label:`Client`,value:O,onChange:k,placeholder:`All Clients`,options:I.map(e=>({value:String(e.id),label:e.name}))})]})]})}export{S as default};