import{i as e}from"./rolldown-runtime-Dd_uD5pT.js";import{t}from"./react-BatatxyT.js";import{u as n}from"./api-672io9y2.js";import{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{n as c}from"./Helper-DM8_S2CX.js";import{Ra as l,aa as u,za as d}from"./index-CsuVxiRQ.js";import{t as f}from"./page-content-DdXVZwik.js";import{t as p}from"./badge-DLCseWie.js";import{t as m}from"./list-page-header-BnFKDjpb.js";var h=e(t(),1),g=r();function _(){let[e,t]=(0,h.useState)(null),[r,_]=(0,h.useState)(!0),[v,y]=(0,h.useState)(``),[b,x]=(0,h.useState)(``),[S,C]=(0,h.useState)(``),[w,T]=(0,h.useState)(`all`),[E,D]=(0,h.useState)(!1),{data:O}=n(),k=(0,h.useMemo)(()=>(O?.results||[]).map(e=>({value:String(e.id),label:`${e.first_name} ${e.last_name}`.trim()||e.username})),[O]);(0,h.useEffect)(()=>{A()},[b,S,w]);let A=async()=>{try{_(!0);let e={};b&&(e.date_from=b),S&&(e.date_to=S),w!==`all`&&(e.attended_by=w);let n=await c(`/sales/daily-logs/expense-statement/`,e);t(n)}catch{t(null)}finally{_(!1)}},j=e?.by_employee||[],M=v?j.filter(e=>e.employee_name.toLowerCase().includes(v.toLowerCase())):j,N=()=>{x(``),C(``),T(`all`)},P=[b,S].filter(Boolean).length+(w===`all`?0:1);return(0,g.jsxs)(f,{children:[(0,g.jsx)(m,{title:`Expense Statements`,description:e?`${e.total_expenses} total expenses · ₹${Number(e.total_amount).toLocaleString()}`:`Employee-wise expense summary report`,searchPlaceholder:`Search by employee...`,searchValue:v,onSearchChange:y,filter:(0,g.jsxs)(d,{variant:`outline`,size:`sm`,onClick:()=>D(!0),className:`relative`,children:[(0,g.jsx)(a,{className:`mr-2 h-4 w-4`}),` Filters`,P>0&&(0,g.jsx)(p,{variant:`destructive`,className:`ml-2 size-5 p-0 flex items-center justify-center text-[10px]`,children:P})]})}),(0,g.jsx)(i,{data:M,isLoading:r,rowKey:e=>String(e.employee_id),emptyMessage:`No expense data found`,columns:[{key:`employee_name`,label:`Employee`,render:e=>(0,g.jsx)(`span`,{className:`font-medium`,children:e.employee_name})},{key:`count`,label:`No. of Expenses`,className:`w-[130px] text-center`,render:e=>e.count},{key:`total_amount`,label:`Total Amount`,className:`w-[140px] text-right`,render:e=>(0,g.jsxs)(`span`,{className:`font-medium`,children:[`₹`,Number(e.total_amount).toLocaleString()]})}]}),(0,g.jsxs)(o,{open:E,onOpenChange:D,onClear:N,children:[(0,g.jsx)(s,{label:`Employee`,value:w,onChange:T,placeholder:`All Employees`,options:k}),(0,g.jsxs)(`div`,{className:`space-y-2`,children:[(0,g.jsx)(u,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:`Date From`}),(0,g.jsx)(l,{type:`date`,value:b,onChange:e=>x(e.target.value)})]}),(0,g.jsxs)(`div`,{className:`space-y-2`,children:[(0,g.jsx)(u,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:`Date To`}),(0,g.jsx)(l,{type:`date`,value:S,onChange:e=>C(e.target.value)})]})]})]})}export{_ as default};