import{r as e}from"./rolldown-runtime-hePW80VL.js";import{o as t}from"./vendor-forms-yQg41KHz.js";import{l as n,t as r}from"./vendor-react-CAGJwf-T.js";import{t as i}from"./DataTable-BFSm8gty.js";import{t as a}from"./format-BVO_kFTb.js";import{S as o,o as s,w as c}from"./index-Z_bdWDpJ.js";import{r as l}from"./vendor-table-DrED5BwI.js";import{t as u}from"./PageHeader-UI75nV23.js";import{p as d}from"./loanServicingRtkApi-ZdY6nJIe.js";var f=e(t(),1),p=r(),m={draft:`Draft`,pending_approval:`Pending Approval`,approved:`Approved`,rejected:`Rejected`,paid:`Paid`,cancelled:`Cancelled`},h={draft:`outline`,pending_approval:`info`,approved:`warning`,rejected:`error`,paid:`success`,cancelled:`outline`},g={dealer:`Dealer`,customer:`Customer`,other:`Other`},_=[{value:``,label:`All Status`},{value:`draft`,label:`Draft`},{value:`pending_approval`,label:`Pending Approval`},{value:`approved`,label:`Approved`},{value:`rejected`,label:`Rejected`},{value:`paid`,label:`Paid`},{value:`cancelled`,label:`Cancelled`}],v=[{value:``,label:`All Payees`},{value:`dealer`,label:`Dealer`},{value:`customer`,label:`Customer`},{value:`other`,label:`Other`}],y=l();function b(e){return e?`₹${Number(e).toLocaleString(`en-IN`)}`:`—`}function x(){let e=n(),[t,r]=(0,f.useState)(1),[s]=(0,f.useState)(20),[l,x]=(0,f.useState)(``),[S,C]=(0,f.useState)(``),[w,T]=(0,f.useState)(``),E=(0,f.useMemo)(()=>{let e={page:String(t),page_size:String(s)};return l&&(e.search=l),S&&(e.status=S),w&&(e.payee_type=w),e},[t,s,l,S,w]),{data:D,isLoading:O,isFetching:k}=d(E),A=D?.results??[],j=D?.count??0,M=Math.ceil(j/s),N=(0,f.useMemo)(()=>[y.accessor(`disbursement_number`,{header:`Disbursement #`,cell:e=>(0,p.jsx)(`span`,{className:`font-mono text-[12px] font-semibold text-[var(--color-primary)]`,children:e.getValue()||`—`})}),y.accessor(`loan_account_number`,{header:`Loan Account`,cell:e=>{let t=e.row.original;return(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`span`,{className:`font-mono text-[12px] text-[var(--color-text-secondary)]`,children:e.getValue()||`—`}),(0,p.jsx)(`span`,{className:`block text-[11px] text-[var(--color-text-muted)] truncate max-w-[200px]`,children:t.borrower_name||t.application_number||`—`})]})}}),y.accessor(`payee_name`,{header:`Payee`,cell:e=>{let t=e.row.original;return(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`span`,{className:`text-[13px] font-medium text-[var(--color-text-primary)]`,children:e.getValue()||`—`}),(0,p.jsx)(`span`,{className:`block text-[11px] text-[var(--color-text-muted)]`,children:g[t.payee_type]})]})}}),y.accessor(`gross_amount`,{header:`Gross`,cell:e=>(0,p.jsx)(`span`,{className:`text-[13px] tabular-nums text-[var(--color-text-secondary)]`,children:b(e.getValue())})}),y.accessor(`net_amount`,{header:`Net`,cell:e=>(0,p.jsx)(`span`,{className:`text-[13px] font-medium tabular-nums text-[var(--color-text-primary)]`,children:b(e.getValue())})}),y.accessor(`status`,{header:`Status`,cell:e=>{let t=e.getValue();return(0,p.jsx)(o,{variant:h[t],size:`sm`,children:m[t]})}}),y.accessor(`value_date`,{header:`Value Date`,cell:e=>{let t=e.getValue();return(0,p.jsx)(`span`,{className:`text-[12px] text-[var(--color-text-muted)] tabular-nums`,children:t?a(new Date(t),`dd MMM yyyy`):`—`})}}),y.accessor(`created_at`,{header:`Created`,cell:e=>(0,p.jsx)(`span`,{className:`text-[12px] text-[var(--color-text-muted)] tabular-nums`,children:a(new Date(e.getValue()),`dd MMM yyyy`)})})],[]);return(0,p.jsxs)(`div`,{children:[(0,p.jsx)(u,{title:`Disbursements`,description:`Track payout tranches against sanctioned loan accounts.`}),(0,p.jsx)(i,{columns:N,data:A,isLoading:O,isFetching:k,searchable:!0,searchPlaceholder:`Search by disbursement number, payee, or account...`,onSearch:e=>{x(e),r(1)},totalItems:j,currentPage:t,pageSize:s,totalPages:M,onPageChange:r,emptyTitle:`No disbursements`,emptyDescription:`Disbursements appear here once a sanctioned application is disbursed.`,toolbar:(0,p.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,p.jsx)(c,{value:S,onChange:e=>{C(e),r(1)},options:_,placeholder:`All Status`}),(0,p.jsx)(c,{value:w,onChange:e=>{T(e),r(1)},options:v,placeholder:`All Payees`})]}),onRowClick:t=>e(`/admin/loan-servicing/disbursements/${t.id}`)})]})}function S(){return(0,p.jsx)(s,{module:`loan_servicing`,children:(0,p.jsx)(x,{})})}export{S as default};