1import{j as e}from"./vendor-data-Z5doMMu-.js";import{b as C,h as S,r as o}from"./vendor-react-zNM0AU50.js";import{u as M}from"./index-D1K3lVhu.js";import{o as f}from"./offeringService-Cuo8E004.js";import{f as T}from"./financeCloseService-C1M9uxKC.js";import{g as I,r as b,P as O}from"./financeConstants-CXKUiVP8.js";import{f as A}from"./financeSettingsService-Gao7wv_9.js";import{M as k}from"./MemberSearchInput-B4_Iy3N2.js";import{z as n,aD as D,c as E,N as F,n as Y,F as P,b as _,bD as q,ae as z}from"./vendor-ui-CW5bJ11U.js";import"./vendor-firebase-Da9KY1q_.js";import"./vendor-charts-08G1rM8P.js";function W({mode:i}){const m=C(),{id:d}=S(),{user:u}=M(),l=(u==null?void 0:u.churchId)||"seodoon-church",[y,p]=o.useState(!1),[g,x]=o.useState(!1),[r,t]=o.useState({date:new Date().toISOString().split("T")[0],fiscalYear:I(),amount:0,type:"tithe",typeName:"ìì¼ì¡°",isAnonymous:!1,paymentMethod:"cash",status:"pending",memo:""}),[h,v]=o.useState(()=>b());o.useEffect(()=>{A.getSettings(l).then(s=>v(b(s.offeringTypes))).catch(()=>{})},[l]),o.useEffect(()=>{i==="edit"&&d&&j()},[i,d]);const j=async()=>{try{p(!0);const s=await f.getOffering(l,d);s&&t({date:s.date,fiscalYear:s.fiscalYear,amount:s.amount,type:s.type,typeName:s.typeName,memberId:s.memberId,memberName:s.memberName,isAnonymous:s.isAnonymous,paymentMethod:s.paymentMethod,serviceType:s.serviceType,status:s.status,memo:s.memo})}catch(s){console.error("íê¸ ë¡ë ì¤í¨:",s),n.error("íê¸ ì 보를 ë¶ë¬ì¤ëë° ì¤í¨íìµëë¤")}finally{p(!1)}},N=s=>{const a=h.find(c=>c.value===s);t(c=>({...c,type:s,typeName:(a==null?void 0:a.label)||s}))},w=async s=>{if(s.preventDefault(),!r.amount||r.amount<=0){n.error("ê¸ì¡ì ì
ë ¥í´ì£¼ì¸ì");return}if(!r.isAnonymous&&!r.memberId){n.error("íê¸ì를 ì íí´ì£¼ì¸ì");return}try{if(x(!0),await T.isMonthClosed(l,r.date)){n.error("ë§ê°ë ìì
ëë¤. í´ë¹ ìì íê¸ì ë±ë¡/ìì í ì ììµëë¤."),x(!1);return}i==="create"?(await f.createOffering(l,r),n.success("íê¸ì´ ë±ë¡ëììµëë¤")):(await f.updateOffering(l,d,r),n.success("íê¸ì´ ìì ëììµëë¤")),m("/finance/offerings")}catch(a){console.error("íê¸ ì ì¥ ì¤í¨:",a),n.error("íê¸ ì ì¥ì ì¤í¨íìµëë¤")}finally{x(!1)}};return y?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 max-w-2xl mx-auto",children:[e.jsxs("div",{className:"flex items-center gap-4 mb-6",children:[e.jsx("button",{onClick:()=>m("/finance/offerings"),className:"p-2 hover:bg-gray-100 rounded-lg transition-colors",children:e.jsx(D,{className:"w-5 h-5"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-900",children:i==="create"?"íê¸ ë±ë¡":"íê¸ ìì "}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:i==="create"?"ìë¡ì´ íê¸ì ë±ë¡í©ëë¤":"íê¸ ì 보를 ìì í©ëë¤"})]})]}),e.jsxs("form",{onSubmit:w,className:"bg-white rounded-xl shadow-sm border border-gray-100 p-6 space-y-6",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm font-medium text-gray-700 mb-2",children:[e.jsx(E,{className:"w-4 h-4"}),"ë ì§ *"]}),e.jsx("input",{type:"date",value:r.date,onChange:s=>t(a=>({...a,date:s.target.value})),className:"w-full px-4 py-2.5 border border-gray-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500",required:!0})]}),e.jsx("div",{children:e.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:r.isAnonymous,onChange:s=>t(a=>({...a,isAnonymous:s.target.checked,memberId:s.target.checked?void 0:a.memberId,memberName:s.target.checked?void 0:a.memberName})),className:"w-4 h-4 text-blue-600 rounded focus:ring-blue-500"}),e.jsxs("span",{className:"flex items-center gap-2 text-sm text-gray-700",children:[e.jsx(F,{className:"w-4 h-4"}),"ìµëª
íê¸"]})]})}),!r.isAnonymous&&e.jsxs("div",{children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm font-medium text-gray-700 mb-2",children:[e.jsx(Y,{className:"w-4 h-4"}),"íê¸ì *"]}),e.jsx(k,{value:r.memberId&&r.memberName?{id:r.memberId,name:r.memberName}:null,onChange:s=>t(a=>({...a,memberId:s==null?void 0:s.id,memberName:s==null?void 0:s.name})),placeholder:"êµì¸ ì´ë¦ ê²ì..."})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm font-medium text-gray-700 mb-2",children:[e.jsx(P,{className:"w-4 h-4"}),"íê¸ ì í *"]}
1),e.jsx("select",{value:r.type,onChange:s=>N(s.target.value),className:"w-full px-4 py-2.5 border border-gray-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500",required:!0,children:h.map(s=>e.jsx("option",{value:s.value,children:s.label},s.value))})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm font-medium text-gray-700 mb-2",children:[e.jsx(_,{className:"w-4 h-4"}),"ê¸ì¡ *"]}),e.jsxs("div",{className:"relative",children:[e.jsx("span",{className:"absolute left-4 top-1/2 -translate-y-1/2 text-gray-400",children:"â©"}),e.jsx("input",{type:"number",placeholder:"0",value:r.amount||"",onChange:s=>t(a=>({...a,amount:Number(s.target.value)})),className:"w-full pl-8 pr-4 py-2.5 border border-gray-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500",min:"0",step:"1000",required:!0})]})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm font-medium text-gray-700 mb-2",children:[e.jsx(q,{className:"w-4 h-4"}),"ê²°ì ë°©ë² *"]}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-2",children:O.map(s=>e.jsxs("label",{className:`flex items-center justify-center gap-2 px-4 py-2.5 border rounded-lg cursor-pointer transition-colors ${r.paymentMethod===s.value?"border-blue-500 bg-blue-50 text-blue-700":"border-gray-200 hover:border-gray-300"}`,children:[e.jsx("input",{type:"radio",name:"paymentMethod",value:s.value,checked:r.paymentMethod===s.value,onChange:a=>t(c=>({...c,paymentMethod:a.target.value})),className:"sr-only"}),e.jsx("span",{className:"text-sm",children:s.label})]},s.value))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"flex items-center gap-2 text-sm font-medium text-gray-700 mb-2",children:"ìë°° ì í"}),e.jsxs("select",{value:r.serviceType||"",onChange:s=>t(a=>({...a,serviceType:s.target.value||void 0})),className:"w-full px-4 py-2.5 border border-gray-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500",children:[e.jsx("option",{value:"",children:"ì í ìí¨"}),e.jsx("option",{value:"sunday_1",children:"ì£¼ì¼ 1ë¶"}),e.jsx("option",{value:"sunday_2",children:"ì£¼ì¼ 2ë¶"}),e.jsx("option",{value:"sunday_3",children:"ì£¼ì¼ 3ë¶"}),e.jsx("option",{value:"wednesday",children:"ìììë°°"}),e.jsx("option",{value:"friday",children:"ê¸ììë°°"}),e.jsx("option",{value:"dawn",children:"ìë²½ìë°°"}),e.jsx("option",{value:"special",children:"í¹ë³ìë°°"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-gray-700 mb-2 block",children:"ë©ëª¨"}),e.jsx("textarea",{placeholder:"ë©ëª¨ë¥¼ ì
ë ¥íì¸ì",value:r.memo||"",onChange:s=>t(a=>({...a,memo:s.target.value})),className:"w-full px-4 py-2.5 border border-gray-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 resize-none",rows:3})]}),e.jsxs("div",{className:"flex items-center justify-end gap-3 pt-4 border-t",children:[e.jsx("button",{type:"button",onClick:()=>m("/finance/offerings"),className:"px-4 py-2.5 border border-gray-200 rounded-lg text-gray-700 hover:bg-gray-50 transition-colors",children:"ì·¨ì"}),e.jsxs("button",{type:"submit",disabled:g,className:"flex items-center gap-2 px-4 py-2.5 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors disabled:opacity-50",children:[e.jsx(z,{className:"w-4 h-4"}),g?"ì ì¥ ì¤...":"ì ì¥"]})]})]})]})}export{W as OfferingFormPage};
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.