"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[79307],{79307:(e,t,s)=>{s.r(t),s.d(t,{default:()=>x});var a=s(95155),i=s(12115),l=s(61659),c=s(74016),d=s(38992),n=s(59210),r=s(10558),m=s(30313),o=s(7404),h=s(2581);function x(){let[e,t]=(0,i.useState)([]),[s,x]=(0,i.useState)(!0),[j,u]=(0,i.useState)(!1),[v,p]=(0,i.useState)(""),[y,f]=(0,i.useState)(""),N=(0,i.useCallback)(async()=>{x(!0);try{t(await (0,o.bX)())}catch(e){(0,h.Qg)(e instanceof Error?e.message:"Failed to load payment methods")}finally{x(!1)}},[]);(0,i.useEffect)(()=>{N()},[N]);let g=async e=>{if(e.preventDefault(),!v.trim())return void(0,h.Qg)("Payment method name is required");u(!0);try{await (0,o.kj)({name:v.trim(),code:y.trim()||void 0}),(0,h.Te)(`Payment method "${v.trim()}" created`),p(""),f(""),N()}catch(e){(0,h.Qg)(e instanceof Error?e.message:"Failed to create payment method")}finally{u(!1)}},b=async e=>{try{await (0,o.VJ)(e.id,{isActive:!e.isActive}),(0,h.Te)(e.isActive?`${e.name} deactivated`:`${e.name} activated`),N()}catch(e){(0,h.Qg)(e instanceof Error?e.message:"Failed to update payment method")}};return(0,a.jsxs)("div",{className:"space-y-6",children:[(0,a.jsx)(c.wc,{title:"Payment Method",description:"Ways money is received or paid — cash, bank, wallet, and more."}),(0,a.jsx)(r.i,{}),(0,a.jsx)(m.a,{tone:"info",title:"Fee collection",children:"Codes like CASH or BANK help fee payments map automatically into the matching income account."}),s?(0,a.jsx)(m.nI,{rows:3}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(d.Z,{className:"overflow-hidden shadow-sm",children:(0,a.jsx)("div",{className:"p-4 sm:p-5",children:(0,a.jsx)(m.Vd,{title:"Add payment method",icon:l.XtC,children:(0,a.jsxs)("form",{onSubmit:g,children:[(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2 lg:max-w-2xl",children:[(0,a.jsx)(n.p,{label:"Name",value:v,onChange:e=>p(e.target.value),placeholder:"Khalti",required:!0}),(0,a.jsx)(n.p,{label:"Code",value:y,onChange:e=>f(e.target.value),placeholder:"KHALTI"})]}),(0,a.jsx)(m.bE,{className:"mt-4",children:(0,a.jsx)(m.kL,{type:"submit",disabled:j||!v.trim(),children:j?"Saving…":"Add method"})})]})})})}),(0,a.jsxs)(d.Z,{className:"overflow-hidden shadow-sm",children:[(0,a.jsx)(m.yg,{children:0===e.length?(0,a.jsx)(m.i0,{title:"No payment methods",description:"Defaults are created on first use."}):e.map(e=>(0,a.jsxs)(m.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.jsx)("p",{className:"text-sm text-slate-500",children:e.code||"No code"})]}),(0,a.jsx)(m.tF,{active:e.isActive})]}),(0,a.jsx)("div",{className:"mt-3",children:(0,a.jsx)(m.mU,{type:"button",size:"sm",onClick:()=>void b(e),children:e.isActive?"Deactivate":"Activate"})})]},e.id))}),(0,a.jsx)(m.iZ,{children:(0,a.jsxs)(m.cR,{minWidth:"36rem",children:[(0,a.jsx)(m.K_,{children:(0,a.jsxs)("tr",{children:[(0,a.jsx)("th",{className:`${m.aB} font-medium`,children:"Name"}),(0,a.jsx)("th",{className:`${m.aB} font-medium`,children:"Code"}),(0,a.jsx)("th",{className:`${m.aB} font-medium`,children:"Status"}),(0,a.jsx)("th",{className:`${m.aB} font-medium`,children:"Actions"})]})}),(0,a.jsx)("tbody",{children:0===e.length?(0,a.jsx)("tr",{children:(0,a.jsx)("td",{colSpan:4,className:`${m.Cl} text-center text-slate-500`,children:"No payment methods yet."})}):e.map(e=>(0,a.jsxs)("tr",{className:"border-t border-slate-100",children:[(0,a.jsx)("td",{className:`${m.Cl} font-medium text-slate-900`,children:e.name}),(0,a.jsx)("td",{className:`${m.Cl} text-slate-600`,children:e.code||"—"}),(0,a.jsx)("td",{className:m.Cl,children:(0,a.jsx)(m.tF,{active:e.isActive})}),(0,a.jsx)("td",{className:m.Cl,children:(0,a.jsx)(m.mU,{type:"button",size:"sm",onClick:()=>void b(e),children:e.isActive?"Deactivate":"Activate"})})]},e.id))})]})})]})]})]})}}}]);