import{r as y,u as f,j as e,H as b}from"./app-BQEFzdw6.js";import{A as v}from"./AppLayout-kozc03ce.js";import{P as _}from"./PageHeader-Bj1OQnqr.js";import{F as n}from"./FormField-HY4WrCzQ.js";import{a as N,f as C}from"./formatters-ClI693-F.js";import{F as D}from"./PlusIcon-ElxOOThC.js";import"./useThemeColor-qPCpc713.js";import"./dayjs.min-BDUBcDj6.js";const E=["rent","salaries","utilities","transport","marketing","office_supplies","maintenance","entertainment","other"];function q({expenses:i,accountHeads:x,projects:u}){const[o,l]=y.useState(!1),{data:a,setData:s,post:h,processing:c,errors:r,reset:j}=f({description:"",category:"other",amount:"",expense_date:new Date().toISOString().substring(0,10),account_head_id:"",project_id:"",payment_method:"cash",reference:"",notes:""});function g(t){t.preventDefault(),h(route("accounts.expenses.store"),{onSuccess:()=>{j(),l(!1)}})}return e.jsxs(v,{children:[e.jsx(b,{title:"Expenses"}),e.jsx(_,{title:"Expenses",subtitle:`${(i.data??i).length} expenses`,children:e.jsxs("button",{onClick:()=>l(!o),className:"btn btn-primary flex items-center gap-2",children:[e.jsx(D,{className:"w-4 h-4"})," Add Expense"]})}),e.jsxs("div",{className:"p-4 sm:p-6",children:[o&&e.jsxs("form",{onSubmit:g,className:"card p-4 mb-4 space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3",children:[e.jsx(n,{label:"Description",error:r.description,required:!0,children:e.jsx("input",{className:"form-input text-sm",value:a.description,onChange:t=>s("description",t.target.value)})}),e.jsx(n,{label:"Category",error:r.category,children:e.jsx("select",{className:"form-input text-sm",value:a.category,onChange:t=>s("category",t.target.value),children:E.map(t=>e.jsx("option",{value:t,children:t.replace("_"," ")},t))})}),e.jsx(n,{label:"Amount (৳)",error:r.amount,required:!0,children:e.jsx("input",{type:"number",className:"form-input text-sm",value:a.amount,onChange:t=>s("amount",t.target.value)})}),e.jsx(n,{label:"Date",error:r.expense_date,children:e.jsx("input",{type:"date",className:"form-input text-sm",value:a.expense_date,onChange:t=>s("expense_date",t.target.value)})}),e.jsx(n,{label:"Account Head",error:r.account_head_id,children:e.jsxs("select",{className:"form-input text-sm",value:a.account_head_id,onChange:t=>s("account_head_id",t.target.value),children:[e.jsx("option",{value:"",children:"-- Auto --"}),(x??[]).map(t=>e.jsxs("option",{value:t.id,children:[t.code," - ",t.name]},t.id))]})}),e.jsx(n,{label:"Project",error:r.project_id,children:e.jsxs("select",{className:"form-input text-sm",value:a.project_id,onChange:t=>s("project_id",t.target.value),children:[e.jsx("option",{value:"",children:"-- No Project --"}),(u??[]).map(t=>e.jsx("option",{value:t.id,children:t.name},t.id))]})}),e.jsx(n,{label:"Payment Method",error:r.payment_method,children:e.jsx("select",{className:"form-input text-sm",value:a.payment_method,onChange:t=>s("payment_method",t.target.value),children:["cash","bank_transfer","cheque","mobile_banking"].map(t=>e.jsx("option",{value:t,children:t.replace("_"," ")},t))})})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"submit",disabled:c,className:"btn btn-primary text-sm",children:c?"…":"Record Expense"}),e.jsx("button",{type:"button",onClick:()=>l(!1),className:"btn text-sm",children:"Cancel"})]})]}),e.jsx("div",{className:"card overflow-hidden",children:e.jsxs("table",{className:"min-w-full divide-y divide-gray-200",children:[e.jsx("thead",{className:"bg-gray-50",children:e.jsx("tr",{children:["Date","Description","Category","Amount","Project","Method"].map(t=>e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase",children:t},t))})}),e.jsxs("tbody",{className:"divide-y divide-gray-100",children:[(i.data??i).map(t=>{var d,m,p;return e.jsxs("tr",{children:[e.jsx("td",{className:"px-4 py-3 text-sm",children:N(t.expense_date)}),e.jsx("td",{className:"px-4 py-3 text-sm font-medium",children:t.description}),e.jsx("td",{className:"px-4 py-3 text-sm capitalize text-gray-600",children:(d=t.category)==null?void 0:d.replace("_"," ")}),e.jsx("td",{className:"px-4 py-3 text-sm font-semibold text-red-600",children:C(t.amount)}),e.jsx("td",{className:"px-4 py-3 text-sm text-gray-600",children:((m=t.project)==null?void 0:m.name)??"—"}),e.jsx("td",{className:"px-4 py-3 text-sm capitalize text-gray-500",children:(p=t.payment_method)==null?void 0:p.replace("_"," ")})]},t.id)}),(i.data??i).length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:6,className:"px-4 py-8 text-center text-gray-400",children:"No expenses found."})})]})]})})]})]})}export{q as default};
