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{n as o,t as s}from"./filter-sheet-guEWYDqt.js";import{F as c,Gr as l,Hr as u,j as d,os as f,za as p}from"./index-CsuVxiRQ.js";import{t as m}from"./page-content-DdXVZwik.js";import{t as h}from"./badge-DLCseWie.js";import{t as g}from"./list-page-header-BnFKDjpb.js";import{t as _}from"./row-actions-DALRrgnK.js";import{t as v}from"./workflow-status-badge-BdRZ0is7.js";var y=e(t(),1),b=r(),x=[{value:`draft`,label:`Draft`},{value:`submitted`,label:`Submitted`},{value:`approved`,label:`Approved`},{value:`cancelled`,label:`Cancelled`}];function S(){let e=f(),[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.branch=w),E!==`all`&&(M.client=E),O!==`all`&&(M.sales_invoice=O),t&&(M.search=t);let{data:N=[],isLoading:P}=d(M),{data:F=[]}=u(),{data:I=[]}=l(),{data:L=[]}=c(),R=()=>{C(`all`),T(`all`),D(`all`),k(`all`)},z=[S,w,E,O].filter(e=>e!==`all`).length;return(0,b.jsxs)(m,{children:[(0,b.jsx)(g,{title:`Credit Notes`,description:`Credit notes for invoice reversals`,searchPlaceholder:`Search by CN number, client, invoice code...`,searchValue:t,onSearchChange:r,filter:(0,b.jsxs)(p,{variant:`outline`,size:`sm`,onClick:()=>j(!0),className:`relative`,children:[(0,b.jsx)(a,{className:`mr-2 h-4 w-4`}),` Filters`,z>0&&(0,b.jsx)(h,{variant:`destructive`,className:`ml-2 size-5 p-0 flex items-center justify-center text-[10px]`,children:z})]})}),(0,b.jsx)(i,{data:N,onRowClick:t=>e(`/credit-notes/${t.id}`),columns:[{key:`code`,label:`CN No`,render:e=>(0,b.jsx)(`span`,{className:`font-mono`,children:e.code})},{key:`credit_date`,label:`Date`,render:e=>n(e.credit_date)},{key:`sales_invoice_code`,label:`Invoice`,render:e=>(0,b.jsx)(`span`,{className:`font-mono text-xs`,children:e.sales_invoice_code})},{key:`client_name`,label:`Client`},{key:`credit_type`,label:`Type`,render:e=>(0,b.jsx)(`span`,{className:`capitalize`,children:e.credit_type})},{key:`credit_amount`,label:`Credit Amount`,className:`text-center`,render:e=>(0,b.jsx)(`span`,{className:`font-mono`,children:Number(e.credit_amount).toLocaleString()})},{key:`status`,label:`Status`,render:e=>(0,b.jsx)(v,{status:e.status})},{key:`actions`,label:`Actions`,sortable:!1,render:t=>(0,b.jsx)(_,{onView:()=>e(`/credit-notes/${t.id}`)})}],isLoading:P,rowKey:e=>e.id,emptyMessage:`No credit notes found`}),(0,b.jsxs)(o,{open:A,onOpenChange:j,onClear:R,children:[(0,b.jsx)(s,{label:`Status`,value:S,onChange:C,placeholder:`All Status`,options:x}),(0,b.jsx)(s,{label:`Branch`,value:w,onChange:T,placeholder:`All Branches`,options:F.map(e=>({value:String(e.id),label:e.name}))}),(0,b.jsx)(s,{label:`Client`,value:E,onChange:D,placeholder:`All Clients`,options:I.map(e=>({value:String(e.id),label:e.name}))}),(0,b.jsx)(s,{label:`Sales Invoice`,value:O,onChange:k,placeholder:`All Invoices`,options:L.map(e=>({value:String(e.id),label:e.code}))})]})]})}export{S as default};