import{a as e,t}from"./react-D0JuimcS.js";import{u as n}from"./api-Dal_nT4z.js";import{n as r,o as i}from"./utils-Dac180Gn.js";import{r as a}from"./api-NMlTtVre.js";import{t as o}from"./list-table-M8Qu8ozW.js";import{t as s}from"./funnel-BDsPorMA.js";import{t as c}from"./plus-VCCEyniC.js";import{n as l,t as u}from"./filter-sheet-ChUwrDC4.js";import{n as d}from"./Helper-7k0HBglN.js";import{Fo as f,Ki as p,ga as m,ha as h}from"./index-8M5AnKdQ.js";import{t as g}from"./page-content-DDtdeMxM.js";import{t as _}from"./badge-Crg76WQE.js";import{t as v}from"./record-actions-3WNKE8L8.js";import{t as y}from"./list-page-header-DTmo84Zp.js";var b=e(t(),1),x=i(),S=[{value:`employee`,label:`Employee`},{value:`project`,label:`Project`}],C=e=>r(e);function w(){let e=f(),[t,r]=(0,b.useState)(null),[i,w]=(0,b.useState)(!0),[T,E]=(0,b.useState)(``),[D,O]=(0,b.useState)(``),[k,A]=(0,b.useState)(``),[j,M]=(0,b.useState)(`all`),[N,P]=(0,b.useState)(`all`),[F,I]=(0,b.useState)(!1),{data:L}=n(),R=(0,b.useMemo)(()=>(L?.results||[]).map(e=>({value:String(e.id),label:`${e.first_name} ${e.last_name}`.trim()||e.username})),[L]);(0,b.useEffect)(()=>{z()},[D,k,j]);let z=async()=>{try{w(!0);let e={};D&&(e.date_from=D),k&&(e.date_to=k),j!==`all`&&(e.attended_by=j),r(await d(`/sales/daily-logs/expense-statement/`,e))}catch{r(null)}finally{w(!1)}},B=(t?.rows||[]).filter(e=>{if(T){let t=T.toLowerCase();if(!e.employee_name.toLowerCase().includes(t)&&!e.expense_master_name.toLowerCase().includes(t)&&!e.daily_log_code.toLowerCase().includes(t))return!1}return!(N!==`all`&&e.expense_type!==N)}),V=()=>{O(``),A(``),M(`all`),P(`all`)},H=[D,k].filter(Boolean).length+[j,N].filter(e=>e!==`all`).length;return(0,x.jsxs)(g,{children:[(0,x.jsx)(y,{title:`Employee Expenses`,description:t?`${t.total_expenses} expenses · Total: ₹${Number(t.total_amount).toLocaleString()}`:`Employee expense records from service daily logs`,searchPlaceholder:`Search by employee, expense, code...`,searchValue:T,onSearchChange:E,action:(0,x.jsxs)(m,{size:`sm`,onClick:()=>e(`/service-daily-logs/new`),children:[(0,x.jsx)(c,{className:`mr-2 h-4 w-4`}),` Add Employee Expense`]}),filter:(0,x.jsxs)(m,{variant:`outline`,size:`sm`,onClick:()=>I(!0),className:`relative`,children:[(0,x.jsx)(s,{className:`mr-2 h-4 w-4`}),` Filters`,H>0&&(0,x.jsx)(_,{variant:`destructive`,className:`ml-2 size-5 p-0 flex items-center justify-center text-[10px]`,children:H})]})}),(0,x.jsx)(o,{data:B,isLoading:i,rowKey:e=>e.id,emptyMessage:`No employee expenses found`,columns:[{key:`daily_log_code`,label:`Log Code`,className:`w-[100px]`,render:e=>(0,x.jsx)(`span`,{className:`font-mono text-xs`,children:e.daily_log_code})},{key:`date`,label:`Date`,className:`w-[110px]`,render:e=>C(e.date)},{key:`employee_name`,label:`Employee`,render:e=>(0,x.jsx)(`span`,{className:`font-medium`,children:e.employee_name})},{key:`expense_master_name`,label:`Expense`,render:e=>e.expense_master_name},{key:`expense_type`,label:`Type`,className:`w-[100px]`,render:e=>(0,x.jsx)(_,{variant:e.expense_type===`employee`?`secondary`:`outline`,className:`text-[10px]`,children:e.expense_type===`employee`?`Employee`:e.expense_type===`project`?`Project`:e.expense_type||`—`})},{key:`company_name`,label:`Company`,render:e=>(0,x.jsx)(`span`,{className:`text-muted-foreground truncate block max-w-[150px]`,children:e.company_name||`—`})},{key:`amount`,label:`Amount`,className:`w-[100px] text-right`,render:e=>(0,x.jsxs)(`span`,{className:`font-medium`,children:[`₹`,Number(e.amount).toLocaleString()]})},{key:`actions`,label:`Actions`,sortable:!1,className:`w-[120px]`,render:t=>(0,x.jsx)(v,{approval:{entityType:`DailyLog`,objectId:t.daily_log_id,contentTypeId:a.DAILY_LOG,authorizedStatus:t.authorized_status??1,onApprovalChange:()=>z()},onView:()=>e(`/service-daily-logs/${t.daily_log_id}`),onEdit:()=>e(`/service-daily-logs/${t.daily_log_id}/edit`)})}]}),(0,x.jsxs)(l,{open:F,onOpenChange:I,onClear:V,children:[(0,x.jsx)(u,{label:`Employee`,value:j,onChange:M,placeholder:`All Employees`,options:R}),(0,x.jsx)(u,{label:`Expense Type`,value:N,onChange:P,placeholder:`All Types`,options:S}),(0,x.jsxs)(`div`,{className:`space-y-2`,children:[(0,x.jsx)(p,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:`Date From`}),(0,x.jsx)(h,{type:`date`,value:D,onChange:e=>O(e.target.value)})]}),(0,x.jsxs)(`div`,{className:`space-y-2`,children:[(0,x.jsx)(p,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:`Date To`}),(0,x.jsx)(h,{type:`date`,value:k,onChange:e=>A(e.target.value)})]})]})]})}export{w as default};