import{a as e,t}from"./react-DK-MTtD8.js";import{u as n}from"./api-rGh4pPta.js";import{s as r}from"./utils-CXcsdpX-.js";import{t as i}from"./list-table-CQD2C7IB.js";import{t as a}from"./funnel-BT4pjjO7.js";import{n as o,t as s}from"./filter-sheet-omdfG0qY.js";import{n as c}from"./Helper-CgZLd8U2.js";import{Ra as l,aa as u,za as d}from"./index-Ct5uU080.js";import{t as f}from"./page-content-Bh5Zxb_Y.js";import{t as p}from"./badge-CL1e8lO_.js";import{t as m}from"./list-page-header-CePoWpko.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};