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{n as o,t as s}from"./filter-sheet-Baado-aR.js";import{A as c,Fo as l,Mr as u,P as d,ga as f,kr as p}from"./index-BP3TYB4i.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-48VsPegf.js";import{t as _}from"./row-actions-_6H5dRTY.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:`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.branch=w),E!==`all`&&(M.client=E),O!==`all`&&(M.sales_invoice=O),t&&(M.search=t);let{data:N=[],isLoading:P}=c(M),{data:F=[]}=p(),{data:I=[]}=u(),{data:L=[]}=d(),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)(f,{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};