import{a as e,t}from"./react-DK-MTtD8.js";import{s as n}from"./utils-CXcsdpX-.js";import{t as r}from"./list-table-CF_0QrYo.js";import{t as i}from"./funnel-BT4pjjO7.js";import{t as a}from"./plus-CuMPbIyn.js";import{n as o,t as s}from"./filter-sheet-_WHotb9o.js";import{rs as c,za as l}from"./index-CvTTLloU.js";import{t as u}from"./page-content-Bh5Zxb_Y.js";import{t as d}from"./badge-CL1e8lO_.js";import{a as f,i as p,n as m,o as h,t as g}from"./dialog-DrW_2c38.js";import{t as _}from"./status-badge-DPBh_NCk.js";import{t as v}from"./list-page-header-D6ls_V1f.js";import{t as y}from"./row-actions-C-24DtZS.js";import{h as b,w as x}from"./serviceApi-8BCtX3rt.js";var S=e(t(),1),C=n(),w=[{value:`project`,label:`Project`},{value:`employee`,label:`Employee`}],T=[{value:`active`,label:`Active`},{value:`inactive`,label:`Inactive`}];function E(){let e=c(),[t,n]=(0,S.useState)(``),[E,D]=(0,S.useState)(`all`),[O,k]=(0,S.useState)(`all`),[A,j]=(0,S.useState)(!1),M={};E!==`all`&&(M.expense_type=E),O!==`all`&&(M.status=O),t&&(M.search=t);let{data:N=[],isLoading:P,refetch:F}=x(M),[I]=b(),[L,R]=(0,S.useState)(null),z=async()=>{L&&(await I(L).unwrap().catch(()=>{}),R(null),F())},B=()=>{D(`all`),k(`all`)},V=[E,O].filter(e=>e!==`all`).length;return(0,C.jsxs)(u,{children:[(0,C.jsx)(v,{title:`Expenses`,description:`Configure expense types for daily log entries`,searchPlaceholder:`Search by name or code...`,searchValue:t,onSearchChange:n,action:(0,C.jsxs)(l,{onClick:()=>e(`/masters/expenses/new`),children:[(0,C.jsx)(a,{className:`size-4 mr-2`}),` Add Expense Type`]}),filter:(0,C.jsxs)(l,{variant:`outline`,size:`sm`,onClick:()=>j(!0),className:`relative`,children:[(0,C.jsx)(i,{className:`mr-2 h-4 w-4`}),` Filters`,V>0&&(0,C.jsx)(d,{variant:`destructive`,className:`ml-2 size-5 p-0 flex items-center justify-center text-[10px]`,children:V})]})}),(0,C.jsx)(r,{data:N,columns:[{key:`code`,label:`Code`,render:e=>(0,C.jsx)(`span`,{className:`font-mono`,children:e.code})},{key:`name`,label:`Name`},{key:`expense_type`,label:`Type`,render:e=>(0,C.jsx)(d,{variant:`outline`,className:`capitalize`,children:e.expense_type})},{key:`calculation_type`,label:`Calculation`,render:e=>(0,C.jsx)(`span`,{className:`capitalize`,children:e.calculation_type})},{key:`fixed_amount`,label:`Fixed Amount`,className:`text-center`,render:e=>e.fixed_amount?(0,C.jsx)(`span`,{className:`font-mono`,children:Number(e.fixed_amount).toLocaleString()}):`—`},{key:`status`,label:`Status`,render:e=>(0,C.jsx)(_,{active:e.status===`active`})},{key:`actions`,label:`Actions`,sortable:!1,render:t=>(0,C.jsx)(y,{onView:()=>e(`/masters/expenses/${t.id}/edit`),onEdit:()=>e(`/masters/expenses/${t.id}/edit`),onDelete:()=>R(t.id)})}],isLoading:P,rowKey:e=>e.id,emptyMessage:`No expenses found`}),(0,C.jsxs)(o,{open:A,onOpenChange:j,onClear:B,children:[(0,C.jsx)(s,{label:`Expense Type`,value:E,onChange:D,placeholder:`All Types`,options:w}),(0,C.jsx)(s,{label:`Status`,value:O,onChange:k,placeholder:`All Status`,options:T})]}),(0,C.jsx)(g,{open:!!L,onOpenChange:e=>{e||R(null)},children:(0,C.jsxs)(m,{className:`sm:max-w-md`,children:[(0,C.jsx)(f,{children:(0,C.jsx)(h,{children:`Delete Expense Type`})}),(0,C.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Are you sure you want to delete this expense type?`}),(0,C.jsxs)(p,{children:[(0,C.jsx)(l,{variant:`outline`,size:`sm`,onClick:()=>R(null),children:`Cancel`}),(0,C.jsx)(l,{variant:`destructive`,size:`sm`,onClick:z,children:`Delete`})]})]})})]})}export{E as default};