"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[91424],{91424:(e,t,s)=>{s.r(t),s.d(t,{default:()=>u});var a=s(95155),i=s(12115),n=s(61659),c=s(74016),l=s(38992),r=s(59210),d=s(10558),o=s(30313),m=s(7404),h=s(2581);function u(){let[e,t]=(0,i.useState)([]),[s,u]=(0,i.useState)(!0),[x,j]=(0,i.useState)(!1),[p,v]=(0,i.useState)(""),[g,N]=(0,i.useState)("CASH"),[f,b]=(0,i.useState)("0"),[y,C]=(0,i.useState)(""),A=(0,i.useCallback)(async()=>{u(!0);try{t(await (0,m.iy)())}catch(e){(0,h.Qg)(e instanceof Error?e.message:"Failed to load accounts")}finally{u(!1)}},[]);(0,i.useEffect)(()=>{A()},[A]);let S=async e=>{e.preventDefault();let t=Number(f||0);if(!p.trim())return void(0,h.Qg)("Account name is required");if(!Number.isFinite(t))return void(0,h.Qg)("Opening balance must be a number");j(!0);try{await (0,m.Zp)({name:p.trim(),accountType:g,openingBalance:t,description:y.trim()||void 0}),(0,h.Te)(`Account "${p.trim()}" created`),v(""),b("0"),C(""),N("CASH"),A()}catch(e){(0,h.Qg)(e instanceof Error?e.message:"Failed to create account")}finally{j(!1)}},w=async e=>{try{await (0,m.Mt)(e.id,{isActive:!e.isActive}),(0,h.Te)(e.isActive?`${e.name} deactivated`:`${e.name} activated`),A()}catch(e){(0,h.Qg)(e instanceof Error?e.message:"Failed to update account")}};return(0,a.jsxs)("div",{className:"space-y-6",children:[(0,a.jsx)(c.wc,{title:"Account List",description:"Cash, bank, and other ledger accounts used for income and expense."}),(0,a.jsx)(d.i,{}),s?(0,a.jsx)(o.nI,{rows:3}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(l.Z,{className:"overflow-hidden shadow-sm",children:(0,a.jsx)("div",{className:"p-4 sm:p-5",children:(0,a.jsx)(o.Vd,{title:"Add account",icon:n.VwS,children:(0,a.jsxs)("form",{onSubmit:S,children:[(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2 lg:max-w-3xl",children:[(0,a.jsx)(r.p,{label:"Account name",value:p,onChange:e=>v(e.target.value),placeholder:"Petty Cash",required:!0}),(0,a.jsx)(o.yB,{label:"Type",children:(0,a.jsxs)(o.Kd,{value:g,onChange:e=>N(e.target.value),children:[(0,a.jsx)("option",{value:"CASH",children:"Cash"}),(0,a.jsx)("option",{value:"BANK",children:"Bank"}),(0,a.jsx)("option",{value:"OTHER",children:"Other"})]})}),(0,a.jsx)(r.p,{label:"Opening balance",type:"number",step:"0.01",value:f,onChange:e=>b(e.target.value)}),(0,a.jsx)(r.p,{label:"Description",value:y,onChange:e=>C(e.target.value),placeholder:"Optional note"})]}),(0,a.jsx)(o.bE,{className:"mt-4",children:(0,a.jsx)(o.kL,{type:"submit",disabled:x||!p.trim(),children:x?"Saving…":"Add account"})})]})})})}),(0,a.jsxs)(l.Z,{className:"overflow-hidden shadow-sm",children:[(0,a.jsx)(o.yg,{children:0===e.length?(0,a.jsx)(o.i0,{title:"No accounts",description:"Defaults are created on first use."}):e.map(e=>(0,a.jsxs)(o.oe,{children:[(0,a.jsxs)("div",{className:"flex items-start justify-between gap-3",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"font-semibold text-slate-900",children:e.name}),(0,a.jsxs)("p",{className:"text-sm text-slate-500",children:[e.accountType," \xb7 Opening ",(0,d.B)(e.openingBalance)]})]}),(0,a.jsx)(o.tF,{active:e.isActive})]}),(0,a.jsx)("div",{className:"mt-3",children:(0,a.jsx)(o.mU,{type:"button",size:"sm",onClick:()=>void w(e),children:e.isActive?"Deactivate":"Activate"})})]},e.id))}),(0,a.jsx)(o.iZ,{children:(0,a.jsxs)(o.cR,{minWidth:"40rem",children:[(0,a.jsx)(o.K_,{children:(0,a.jsxs)("tr",{children:[(0,a.jsx)("th",{className:`${o.aB} font-medium`,children:"Name"}),(0,a.jsx)("th",{className:`${o.aB} font-medium`,children:"Type"}),(0,a.jsx)("th",{className:`${o.aB} font-medium text-right`,children:"Opening"}),(0,a.jsx)("th",{className:`${o.aB} font-medium`,children:"Status"}),(0,a.jsx)("th",{className:`${o.aB} font-medium`,children:"Actions"})]})}),(0,a.jsx)("tbody",{children:0===e.length?(0,a.jsx)("tr",{children:(0,a.jsx)("td",{colSpan:5,className:`${o.Cl} text-center text-slate-500`,children:"No accounts yet."})}):e.map(e=>(0,a.jsxs)("tr",{className:"border-t border-slate-100",children:[(0,a.jsxs)("td",{className:`${o.Cl} font-medium text-slate-900`,children:[e.name,e.description?(0,a.jsx)("p",{className:"text-xs font-normal text-slate-500",children:e.description}):null]}),(0,a.jsx)("td",{className:`${o.Cl} text-slate-600`,children:e.accountType}),(0,a.jsx)("td",{className:`${o.Cl} text-right tabular-nums text-slate-700`,children:(0,d.B)(e.openingBalance)}),(0,a.jsx)("td",{className:o.Cl,children:(0,a.jsx)(o.tF,{active:e.isActive})}),(0,a.jsx)("td",{className:o.Cl,children:(0,a.jsx)(o.mU,{type:"button",size:"sm",onClick:()=>void w(e),children:e.isActive?"Deactivate":"Activate"})})]},e.id))})]})})]})]})]})}}}]);