import{a as e}from"./rolldown-runtime-B0Z9INg1.js";import{$ as t}from"./vendor-charts-iXlq6Rne.js";import{l as n}from"./vendor-react-Dzc9WstK.js";import{t as r}from"./DataTable-Dc5x7VxX.js";import{t as i}from"./file-text-6Qqw2k_h.js";import{_ as a}from"./vendor-flow-IzlrcDx6.js";import{t as o}from"./Dropdown-BZh579Ix.js";import{t as s}from"./Badge-Cw8tCXX7.js";import{t as c}from"./CommonSelectComponent-CSkkj6m6.js";import{a as l,r as u,t as d}from"./format-DOnLYpxL.js";import{t as f}from"./useMasterTable-CIy11KIN.js";import{D as p,O as m,h,m as g}from"./schemesRtkApi-DJOTGYww.js";import{s as _}from"./types-CVcMF3y-.js";var v=e(t(),1),y=a(),b=Object.keys(_).map(e=>({value:e,label:_[e]}));function x(){let[e,t]=(0,v.useState)(``),[a,_]=(0,v.useState)(``),[x,S]=(0,v.useState)(``),C=f({scheme:e,customer:a,settlement_mode:x}),{data:w,isLoading:T,isFetching:E}=g(C.params),{data:D}=h({page_size:100}),O=[{accessorKey:`earned_at`,header:`When`,cell:({getValue:e})=>(0,y.jsx)(`span`,{className:`whitespace-nowrap text-[12.5px] text-[var(--color-text-secondary)]`,children:u(e())})},{accessorKey:`scheme_code`,header:`Scheme`,cell:({getValue:e})=>(0,y.jsx)(`span`,{className:`font-mono text-[11.5px] font-semibold text-[var(--color-text-secondary)]`,children:e()})},{accessorKey:`customer_name`,header:`Customer`,cell:({row:e})=>(0,y.jsxs)(`div`,{className:`max-w-[200px]`,children:[(0,y.jsx)(`div`,{className:`truncate font-medium text-[var(--color-text-primary)]`,children:e.original.customer_name}),(0,y.jsx)(`p`,{className:`font-mono text-[11px] text-[var(--color-text-muted)]`,children:e.original.customer_code})]})},{id:`what`,header:`What they got`,enableSorting:!1,cell:({row:e})=>{let t=e.original;return Number(t.free_qty||0)>0?(0,y.jsxs)(`span`,{className:`text-[12.5px] text-[var(--color-text-primary)]`,children:[(0,y.jsx)(`span`,{className:`font-semibold tabular-nums`,children:l(t.free_qty)}),(0,y.jsx)(`span`,{className:`text-[var(--color-text-muted)]`,children:` × `}),t.free_product_name||`free goods`]}):(0,y.jsx)(`span`,{className:`text-[13px] font-bold tabular-nums text-[var(--color-text-primary)]`,children:d(t.amount)})}},{accessorKey:`settlement_mode_display`,header:`How`,cell:({getValue:e})=>(0,y.jsx)(`span`,{className:`text-[12.5px] text-[var(--color-text-secondary)]`,children:e()})},{id:`order`,header:`Order`,enableSorting:!1,cell:({row:e})=>e.original.order_code?(0,y.jsx)(`span`,{className:`font-mono text-[11.5px] text-[var(--color-text-secondary)]`,children:e.original.order_code}):(0,y.jsx)(`span`,{className:`text-[12px] text-[var(--color-text-muted)]`,children:`—`})},{id:`credit_note`,header:`Credit note`,enableSorting:!1,cell:({row:e})=>e.original.ledger_entry?(0,y.jsx)(n,{to:`/admin/credit`,className:`inline-flex`,children:(0,y.jsxs)(s,{variant:`info`,size:`sm`,className:`cursor-pointer`,children:[(0,y.jsx)(i,{className:`h-3 w-3`}),`On the ledger`]})}):(0,y.jsx)(`span`,{className:`text-[12px] text-[var(--color-text-muted)]`,children:`—`})}],k=w?.count??0,A=(D?.results??[]).map(e=>({value:e.id,label:e.name,description:e.code}));return(0,y.jsx)(p,{toolbar:(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(o,{options:A,value:e,onChange:e=>{t(e),C.resetPage()},placeholder:`Any scheme`,size:`sm`,clearable:!0,searchable:!0,className:`w-60`}),(0,y.jsx)(c,{endpoint:`/masters/customers/`,labelKey:`name`,descriptionKey:`code`,placeholder:`Any customer`,value:a,onChange:e=>{_(e),C.resetPage()},size:`sm`,clearable:!0,className:`w-60`}),(0,y.jsx)(o,{options:b,value:x,onChange:e=>{S(e),C.resetPage()},placeholder:`Any settlement`,size:`sm`,clearable:!0,className:`w-64`})]}),children:(0,y.jsxs)(m,{className:`space-y-2.5`,children:[(0,y.jsx)(`p`,{className:`text-[11.5px] text-[var(--color-text-muted)]`,children:`Append-only — a benefit is never edited or removed once it is written. This is the record finance reconciles a scheme's spend against.`}),(0,y.jsx)(r,{columns:O,data:w?.results??[],isLoading:T,isFetching:E,searchable:!0,searchPlaceholder:`Search by customer, scheme or order…`,onSearch:C.onSearch,totalItems:k,currentPage:C.page,pageSize:C.pageSize,totalPages:C.totalPages(k),onPageChange:C.onPageChange,emptyTitle:`Nothing has been given away yet`,emptyDescription:`A benefit is the record of one payout — a discount off an invoice, free bags on an order, or a credit note posted to a customer's ledger. Once a live scheme starts earning, every rupee of it lands here.`})]})})}export{x as default};