import{a as e,t}from"./react-D0JuimcS.js";import{u as n}from"./api-Dal_nT4z.js";import{o as r}from"./utils-Dac180Gn.js";import{t as i}from"./list-table-M8Qu8ozW.js";import{t as a}from"./funnel-BDsPorMA.js";import{n as o,t as s}from"./filter-sheet-ChUwrDC4.js";import{n as c}from"./Helper-7k0HBglN.js";import{Ki as l,ga as u,ha as d}from"./index-8M5AnKdQ.js";import{t as f}from"./page-content-DDtdeMxM.js";import{t as p}from"./badge-Crg76WQE.js";import{t as m}from"./list-page-header-DTmo84Zp.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),t(await c(`/sales/daily-logs/expense-statement/`,e))}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)(u,{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)(l,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:`Date From`}),(0,g.jsx)(d,{type:`date`,value:b,onChange:e=>x(e.target.value)})]}),(0,g.jsxs)(`div`,{className:`space-y-2`,children:[(0,g.jsx)(l,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:`Date To`}),(0,g.jsx)(d,{type:`date`,value:S,onChange:e=>C(e.target.value)})]})]})]})}export{_ as default};