1import{j as e}from"./vendor-data-Z5doMMu-.js";import{r as i}from"./vendor-react-zNM0AU50.js";import{u as z}from"./index-D1K3lVhu.js";import{accountService as g}from"./accountService-CnSilcbs.js";import{A as v}from"./financeConstants-CXKUiVP8.js";import{z as c,aa as q,g as I,f as U,a as B,al as F,T as M,r as O,t as R,s as W,bE as Y,bP as _,am as G}from"./vendor-ui-CW5bJ11U.js";import"./vendor-firebase-Da9KY1q_.js";import"./vendor-charts-08G1rM8P.js";const H={asset:e.jsx(G,{className:"w-4 h-4"}),liability:e.jsx(_,{className:"w-4 h-4"}),equity:e.jsx(Y,{className:"w-4 h-4"}),revenue:e.jsx(W,{className:"w-4 h-4"}),expense:e.jsx(R,{className:"w-4 h-4"})},J={asset:"text-blue-600 bg-blue-50",liability:"text-red-600 bg-red-50",equity:"text-purple-600 bg-purple-50",revenue:"text-green-600 bg-green-50",expense:"text-orange-600 bg-orange-50"};function re({embedded:K=!1}){const{user:p}=z(),d=(p==null?void 0:p.churchId)||"seodoon-church",[w,A]=i.useState([]),[C,N]=i.useState(!0),[x,S]=i.useState(""),[b,k]=i.useState(new Set(["asset","liability","equity","revenue","expense"])),[E,y]=i.useState(!1),[o,f]=i.useState(null),[l,n]=i.useState({code:"",name:"",nameEn:"",type:"asset",parentCode:"",description:"",isActive:!0});i.useEffect(()=>{m()},[d]);const m=async()=>{try{N(!0);const s=await g.getAccounts(d);A(s)}catch(s){console.error("ê³ì 과목 ë¡ë ì¤í¨:",s),c.error("ê³ì 과목ì ë¶ë¬ì¤ëë° ì¤í¨íìµëë¤")}finally{N(!1)}},T=s=>{k(t=>{const a=new Set(t);return a.has(s)?a.delete(s):a.add(s),a})},P=async()=>{if(!l.code||!l.name){c.error("ê³ì ì½ëì ê³ì ëª
ì íìì
ëë¤");return}try{await g.createAccount(d,{...l,level:l.parentCode?3:l.code.endsWith("00")?2:1,isSystemAccount:!1}),c.success("ê³ì ê³¼ëª©ì´ ì¶ê°ëììµëë¤"),y(!1),j(),m()}catch(s){console.error("ê³ì 과목 ì¶ê° ì¤í¨:",s),c.error("ê³ì 과목 ì¶ê°ì ì¤í¨íìµëë¤")}},D=async()=>{if(o)try{await g.updateAccount(d,o.id,l),c.success("ê³ì ê³¼ëª©ì´ ìì ëììµëë¤"),f(null),j(),m()}catch(s){console.error("ê³ì 과목 ìì ì¤í¨:",s),c.error("ê³ì 과목 ìì ì ì¤í¨íìµëë¤")}},L=async s=>{if(s.isSystemAccount){c.error("ìì¤í
ê³ì ì ìì í ì ììµëë¤");return}if(confirm(`"${s.name}" ê³ì ì ìì íìê² ìµëê¹?`))try{await g.deleteAccount(d,s.id),c.success("ê³ì ê³¼ëª©ì´ ìì ëììµëë¤"),m()}catch(t){console.error("ê³ì 과목 ìì ì¤í¨:",t),c.error("ê³ì 과목 ìì ì ì¤í¨íìµëë¤")}},$=s=>{n({code:s.code,name:s.name,nameEn:s.nameEn||"",type:s.type,parentCode:s.parentCode||"",description:s.description||"",isActive:s.isActive}),f(s)},j=()=>{n({code:"",name:"",nameEn:"",type:"asset",parentCode:"",description:"",isActive:!0})},u=v.reduce((s,t)=>(s[t.value]=w.filter(a=>a.type===t.value).filter(a=>x===""||a.code.includes(x)||a.name.includes(x)||a.nameEn&&a.nameEn.toLowerCase().includes(x.toLowerCase())).sort((a,h)=>a.code.localeCompare(h.code)),s),{});return C?e.jsx("div",{className:"flex items-center justify-center min-h-[400px]",children:e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-blue-500"})}):e.jsxs("div",{className:"p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-900",children:"ê³ì 과목 ê´ë¦¬"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"ë³µìë¶ê¸°ë¥¼ ìí ê³ì 과목ì ê´ë¦¬í©ëë¤ (Pro 모ë)"})]}),e.jsxs("button",{onClick:()=>y(!0),className:"flex items-center gap-2 px-4 py-2.5 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors",children:[e.jsx(q,{className:"w-4 h-4"}),"ê³ì ì¶ê°"]})]}),e.jsx("div",{className:"bg-white rounded-xl shadow-sm border border-gray-100 p-4 mb-6",children:e.jsxs("div",{className:"relative",children:[e.jsx(I,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-5 h-5 text-gray-400"}),e.jsx("input",{type:"text",placeholder:"ê³ì ì½ë ëë ê³ì ëª
ì¼ë¡ ê²ì...",value:x,onChange:s=>S(s.target.value),className:"w-full pl-10 pr-4 py-2.5 border border-gray-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"})]})}),e.jsx("div",{className:"space-y-4",children:v.map(s=>{var t,a,h;return e.jsxs("div",{className:"bg-white rounded-xl shadow-sm border border-gray-100 overflow-hidden",children:[e.jsxs("button",{onClick:()=>
1T(s.value),className:"w-full flex items-center justify-between p-4 hover:bg-gray-50 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`p-2 rounded-lg ${J[s.value]}`,children:H[s.value]}),e.jsxs("div",{className:"text-left",children:[e.jsx("span",{className:"font-semibold text-gray-900",children:s.label}),e.jsxs("span",{className:"text-sm text-gray-500 ml-2",children:["(",s.labelEn,")"]})]}),e.jsxs("span",{className:"text-sm text-gray-400",children:[((t=u[s.value])==null?void 0:t.length)||0,"ê°"]})]}),b.has(s.value)?e.jsx(U,{className:"w-5 h-5 text-gray-400"}):e.jsx(B,{className:"w-5 h-5 text-gray-400"})]}),b.has(s.value)&&((a=u[s.value])==null?void 0:a.length)>0&&e.jsx("div",{className:"border-t border-gray-100",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{className:"bg-gray-50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase",children:"ì½ë"}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase",children:"ê³ì ëª
"}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase",children:"ì문ëª
"}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase",children:"ë 벨"}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase",children:"ìí"}),e.jsx("th",{className:"px-4 py-3 text-right text-xs font-medium text-gray-500 uppercase",children:"ìì
"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-100",children:u[s.value].map(r=>e.jsxs("tr",{className:"hover:bg-gray-50",children:[e.jsx("td",{className:"px-4 py-3",children:e.jsx("span",{className:"font-mono text-sm text-gray-900",children:r.code})}),e.jsx("td",{className:"px-4 py-3",children:e.jsxs("span",{className:"text-sm text-gray-900",style:{paddingLeft:`${(r.level-1)*16}px`},children:[r.level>1&&e.jsx("span",{className:"text-gray-300 mr-2",children:"â"}),r.name]})}),e.jsx("td",{className:"px-4 py-3",children:e.jsx("span",{className:"text-sm text-gray-500",children:r.nameEn||"
1-"})}),e.jsx("td",{className:"px-4 py-3",children:e.jsx("span",{className:`inline-flex items-center px-2 py-0.5 rounded text-xs font-medium ${r.level===1?"bg-blue-100 text-blue-700":r.level===2?"bg-green-100 text-green-700":"bg-gray-100 text-gray-700"}`,children:r.level===1?"ëë¶ë¥":r.level===2?"ì¤ë¶ë¥":"ìë¶ë¥"})}),e.jsx("td",{className:"px-4 py-3",children:e.jsx("span",{className:`inline-flex items-center px-2 py-0.5 rounded text-xs font-medium ${r.isActive?"bg-green-100 text-green-700":"bg-gray-100 text-gray-500"}`,children:r.isActive?"ì¬ì©":"미ì¬ì©"})}),e.jsxs("td",{className:"px-4 py-3 text-right",children:[!r.isSystemAccount&&e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx("button",{onClick:()=>$(r),className:"p-1.5 text-gray-400 hover:text-blue-600 hover:bg-blue-50 rounded transition-colors",children:e.jsx(F,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>L(r),className:"p-1.5 text-gray-400 hover:text-red-600 hover:bg-red-50 rounded transition-colors",children:e.jsx(M,{className:"w-4 h-4"})})]}),r.isSystemAccount&&e.jsx("span",{className:"text-xs text-gray-400",children:"ìì¤í
"})]})]},r.id))})]})}),b.has(s.value)&&((h=u[s.value])==null?void 0:h.length)===0&&e.jsxs("div",{className:"p-8 text-center text-gray-500 border-t border-gray-100",children:[e.jsx(O,{className:"w-8 h-8 mx-auto mb-2 text-gray-300"}),e.jsx("p",{className:"text-sm",children:"ë±ë¡ë ê³ì ì´ ììµëë¤"})]})]},s.value)})}),(E||o)&&e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:e.jsxs("div",{className:"bg-white rounded-xl shadow-xl w-full max-w-md p-6",children:[e.jsx("h2",{className:"text-lg font-semibold text-gray-900 mb-4",children:o?"ê³ì 과목 ìì ":"ê³ì 과목 ì¶ê°"}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"ê³ì ì½ë *"}),e.jsx("input",{type:"text",placeholder:"ì: 1101",value:l.code,onChange:s=>n(t=>({...t,code:s.target.value})),className:"w-full px-3 py-2 border border-gray-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500",disabled:!!o})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"ê³ì ì í *"}),e.jsx("select",{value:l.type,onChange:s=>n(t=>({...t,type:s.target.value})),className:"w-full px-3 py-2 border border-gray-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500",disabled:!!o,children:v.map(s=>e.jsx("option",{value:s.value,children:s.label},s.value))})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"ê³ì ëª
*"}),e.jsx("input",{type:"text",placeholder:"ì: íê¸",value:l.name,onChange:s=>n(t=>({...t,name:s.target.value})),className:"w-full px-3 py-2 border border-gray-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"ì문ëª
"}),e.jsx("input",{type:"text",placeholder:"ì: Cash",value:l.nameEn,onChange:s=>n(t=>({...t,nameEn:s.target.value})),className:"w-full px-3 py-2 border border-gray-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"ìì ê³ì ì½ë"}),e.jsx("input",{type:"text",placeholder:"ì: 1100",value:l.parentCode,onChange:s=>n(t=>({...t,parentCode:s.target.value})),className:"w-full px-3 py-2 border border-gray-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"ì¤ëª
"}),e.jsx("textarea",{placeholder:"ê³ì ì ëí ì¤ëª
",value:l.description,onChange:s=>n(t=>({...t,description:s.target.value})),className:"w-full px-3 py-2 border border-gray-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 resize-none",rows:2})]}),e.jsx("div",{children:e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:l.isActive,onChange:s=>n(t=>({...t,isActive:s.target.checked})),className:"w-4 h-4 text-blue-600 rounded focus:ring-blue-500"}),e.jsx("span",{className:"text-sm text-gray-700",children:"ì¬ì©"})]})})]}),e.jsxs("div",{className:"flex justify-end gap-3 mt-6",children:[e.jsx("button",{onClick:()=>{y(!1),f(null),j()},className:"px-4 py-2 border border-gray-200 rounded-lg text-gray-700 hover:bg-gray-50 transition-colors",children:"ì·¨ì"}),e.jsx("button",{onClick:o?D:P,className:"px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors",children:o?"ìì ":"ì¶ê°"})]})]})})]})}export{re as AccountListPage};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.