PageSourceSearch

https://seodoon-church-admin.web.app/assets/VisitManagementPage-hYs4x-cO.js

js seodoon-church-admin.web.app collected 2026-10-03 12:35:41 UTC 76,245 bytes, 15 lines download raw bytes

1import{j as e}from"./vendor-data-Z5doMMu-.js";import{b as he,r as m}from"./vendor-react-zNM0AU50.js";import{v as q}from"./visitService-DcwGr2oo.js";import{m as we}from"./index-D1K3lVhu.js";import{a7 as S,H as te,x as B,aa as _e,Z as me,K as Ce,A,c as ke,U as ue,n as se,g as Se,af as H,T as ae,ag as ge,a as re,X as G,an as Me,ai as De,i as $e,ac as ee}from"./vendor-ui-CW5bJ11U.js";import"./vendor-firebase-Da9KY1q_.js";import"./vendor-charts-08G1rM8P.js";function Ze(){he();const[d,j]=m.useState(!0),[h,p]=m.useState([]),[b,g]=m.useState([]),[r,t]=m.useState("records"),[o,x]=m.useState("list"),[u,i]=m.useState(""),[a,l]=m.useState("all"),[y,f]=m.useState("all"),[v,_]=m.useState("all"),[s,c]=m.useState("all"),[N,w]=m.useState(!1),[D,T]=m.useState(""),[$,Y]=m.useState(""),[be,W]=m.useState(!1),[E,K]=m.useState(null),[le,L]=m.useState(null),[je,ne]=m.useState(!1),[X,oe]=m.useState(null);m.useEffect(()=>{O()},[]);async function O(){try{j(!0);const[n,C]=await Promise.all([q.getAllVisits(),we.getMembers()]);p(n),g(C)}catch(n){console.error("데이터 로딩 실패:",n),S.error("데이터를 불러올 수 없습니다")}finally{j(!1)}}const I=m.useMemo(()=>{const n=new Map;return b.forEach(C=>n.set(C.id,C)),n},[b]),ye=m.useMemo(()=>{const n=new Set(b.map(C=>C.parish).filter(Boolean));return Array.from(n).sort()},[b]),fe=m.useMemo(()=>b.filter(n=>n.member_classification==="서둔출석교역자").map(n=>n.name).filter(Boolean).sort(),[b]),P=m.useMemo(()=>h.filter(n=>{const C=I.get(n.member_id),M=(C==null?void 0:C.name)||n.member_name||"";if(u){const U=u.toLowerCase();if(!M.toLowerCase().includes(U)&&!(n.purpose||"").toLowerCase().includes(U)&&!(n.content||"").toLowerCase().includes(U)&&!(n.visitors||[]).some(J=>J.toLowerCase().includes(U)))return!1}return!(a!=="all"&&n.visit_type!==a||y!=="all"&&(n.urgency||"일반")!==y||N&&!n.follow_up_needed||D&&n.visit_date<D||$&&n.visit_date>$||v!=="all"&&(!C||C.parish!==v)||s!=="all"&&!(n.visitors||[]).includes(s))}),[h,I,u,a,y,N,D,$,v,s]),V={total:h.length,thisMonth:h.filter(n=>{const C=new Date(n.visit_date),M=new Date;return C.getMonth()===M.getMonth()&&C.getFullYear()===M.getFullYear()}).length,followUpNeeded:h.filter(n=>n.follow_up_needed).length,byType:{가정심방:h.filter(n=>n.visit_type==="가정심방").length,병원심방:h.filter(n=>n.visit_type==="병원심방").length,전화심방:h.filter(n=>n.visit_type==="전화심방").length,상담:h.filter(n=>n.visit_type==="상담").length}};async function Z(n){if(confirm("이 심방 기록을 삭제하시겠습니까?"))try{await q.deleteVisit(n),S.success("삭제되었습니다"),O()}catch{S.error("삭제에 실패했습니다")}}async function ce(n){try{await q.updateVisit(n,{follow_up_needed:!1}),S.success("후속조치가 완료되었습니다"),O()}catch{S.error("처리에 실패했습니다")}}function R(n,C){if(n.length===0){S.error("내보낼 데이터가 없습니다");return}const M=n.map(k=>{var de,xe,pe;const F=I.get(k.member_id);return{교인명:(F==null?void 0:F.name)||k.member_name||"-",직분:(F==null?void 0:F.position)||((de=k.original_data)==null?void 0:de.position)||"-",교구:(F==null?void 0:F.parish)||"-",심방일자:k.visit_date,심방유형:k.visit_type,구분:k.urgency||"일반",심방자:((xe=k.visitors)==null?void 0:xe.join(", "))||"-",동행자:k.companion||"-",목적:k.purpose,장소:k.location||"-",내용:k.content,말씀:k.scripture||"-",찬송:k.hymn||"-",기도제목:((pe=k.prayer_topics)==null?void 0:pe.join(", "))||"-",후속조치:k.follow_up_needed?"필요":"-",후속조치예정일:k.follow_up_date||"-"}}),U=Object.keys(M[0]),J=[U.join(","),...M.map(k=>U.map(F=>`"${k[F]||""}"`).join(","))].join(`
2`),ve=new Blob(["\uFEFF"+J],{type:"text/csv;charset=utf-8;"}),ie=URL.createObjectURL(ve),Q=document.createElement("a");Q.href=ie,Q.download=`${C}_${new Date().toISOString().split("T")[0]}.csv`,Q.click(),URL.revokeObjectURL(ie),S.success("엑셀 파일이 다운로드되었습니다")}function Ne(n){oe(n),ne(!0)}return d?e.jsx("div",{className:"flex items-center justify-center h-96",children:e.jsx("div",{className:"text-gray-500 text-[13px]",children:"데이터를 불러오는 중..."})}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-[18px] font-bold text-gray-900 flex items-center gap-2",children:[e.jsx(te,{className:"w-5 h-5 text-blue-600"}),"심방 관리"]}),e.jsx("p",{className:"text-[12px] text-gray-500 mt-1",children:"가정/병원 심방 기록과 통계를 관리합니다"})]}),e.jsx("div",{className:"flex items-center gap-2",children:r==="records"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:()=>R(P,"심방기록_전체"),className:"flex items-center gap-1.5 px-3 py-1.5 border border-gray-300 text-gray-700 rounded hover:bg-gray-50 transition-colors text-[13px] font-medium",children:[e.jsx(B,{className:"w-4 h-4"}),"엑셀"]}),e.jsxs("button",{onClick:()=>W(!0),className:"flex items-center gap-1.5 px-3 py-1.5 bg-blue-600 text-white rounded hover:bg-blue-700 transition-colors text-[13px] font-medium",children:[e.jsx(_e,{className:"w-4 h-4"}),"심방 기록 추가"]})]})})]}),e.jsxs("div",{className:"flex gap-1 bg-gray-100 p-1 rounded-lg w-fit",children:[e.jsx("button",{onClick:()=>t("records"),className:`px-4 py-2 rounded-md text-[13px] font-medium transition-all ${r==="records"?"bg-white text-blue-600 shadow-sm":"text-gray-500 hover:text-gray-700"}`,children:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(me,{className:"w-4 h-4"}),"심방기록"]})}),e.jsx("button",{onClick:()=>t("stats"),className:`px-4 py-2 rounded-md text-[13px] font-medium transition-all ${r==="stats"?"bg-white text-blue-600 shadow-sm":"text-gray-500 hover:text-gray-700"}`,children:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ce,{className:"w-4 h-4"}),"통계"]})})]}),r==="records"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-4 gap-3",children:[e.jsx(z,{label:"전체 심방",value:V.total,color:"blue"}),e.jsx(z,{label:"이번 달",value:V.thisMonth,color:"green"}),e.jsx(z,{label:"후속조치",value:V.followUpNeeded,color:"orange",isAlert:V.followUpNeeded>0}),e.jsx(z,{label:"가정심방",value:V.byType.가정심방,color:"purple"})]}),V.followUpNeeded>0&&!N&&e.jsx("div",{className:"bg-yellow-50 border border-yellow-200 rounded p-3",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(A,{className:"w-4 h-4 text-yellow-600 mt-0.5"}),e.jsx("div",{className:"flex-1",children:e.jsxs("h3",{className:"text-[13px] font-bold text-yellow-900",children:["후속조치가 필요한 심방: ",V.followUpNeeded,"건"]})}),e.jsx("button",{onClick:()=>w(!0),className:"text-[12px] text-yellow-700 hover:text-yellow-900 font-medium",children:"보기 →"})]})}),e.jsxs("div",{className:"bg-white border border-gray-200 rounded shadow-sm p-3",children:[e.jsxs("div",{className:"grid grid-cols-4 gap-3 mb-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-[12px] font-medium text-gray-700 mb-1",children:"보기 모드"}),e.jsx("div",{className:"flex gap-1",children:[["list","목록",me],["calendar","캘린더",ke],["member","교인별",ue],["visitor","교역자별",se]].map(([n,C,M])=>e.jsxs("button",{onClick:()=>x(n),className:`flex-1 flex items-center justify-center gap-1 px-2 py-1.5 rounded text-[12px] transition-colors ${o===n?"bg-blue-600 text-white":"bg-gray-100 text-gray-600 hover:bg-gray-200"}`,children:[e.jsx(M,{className:"w-3.5 h-3.5"}),C]},n))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[12px] font-medium text-gray-700 mb-1",children:"심방 유형"}),e.jsxs("select",{value:a,onChange:n=>l(n.target.value),className:"compact-input",children:[e.jsx("option",{value:"all",children:"전체"}),e.jsx("option",{value:"가정심방",children:"가정심방"}),e.jsx("option",{value:"병원심방",children:"병원심방"}),e.jsx("option",{value:"전화심방",children:"전화심방"}),e.jsx("option",{value:"상담",children:"상담"}),e.jsx("option",{value:"이사심방",children:"이사심방"}),e.jsx("option",{value:"축하심방",children:"축하심방"}),e.jsx("option",{value:"위로심방",children:"위로심방"}),e.jsx("option",{value:"순회심방",children:"순회심방"}),e.jsx("option",{value:"등록심방",children:"등록심방"}),e.jsx("option",{value:"장결자심방",children:"장결자심방"}),e.jsx("option",{value:"구역예배",children:"구역예배"}),e.jsx("option",{value:"기타",children:"기타"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[12px] font-medium text-gray-700 mb-1",children:"구분"}),e.jsxs("select",{value:y,onChange:n=>
2f(n.target.value),className:"compact-input",children:[e.jsx("option",{value:"all",children:"전체"}),e.jsx("option",{value:"일반",children:"일반"}),e.jsx("option",{value:"긴급",children:"긴급"}),e.jsx("option",{value:"비공개",children:"비공개"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[12px] font-medium text-gray-700 mb-1",children:"후속조치"}),e.jsxs("label",{className:"flex items-center gap-2 px-2 py-1.5 border border-gray-300 rounded cursor-pointer hover:bg-gray-50",children:[e.jsx("input",{type:"checkbox",checked:N,onChange:n=>w(n.target.checked),className:"w-4 h-4"}),e.jsx("span",{className:"text-[12px]",children:"필요만 보기"})]})]})]}),e.jsxs("div",{className:"grid grid-cols-5 gap-3 mb-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-[12px] font-medium text-gray-700 mb-1",children:"시작일"}),e.jsx("input",{type:"date",value:D,onChange:n=>T(n.target.value),className:"compact-input"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[12px] font-medium text-gray-700 mb-1",children:"종료일"}),e.jsx("input",{type:"date",value:$,onChange:n=>Y(n.target.value),className:"compact-input"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[12px] font-medium text-gray-700 mb-1",children:"교구"}),e.jsxs("select",{value:v,onChange:n=>_(n.target.value),className:"compact-input",children:[e.jsx("option",{value:"all",children:"전체"}),ye.map(n=>e.jsx("option",{value:n,children:n},n))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[12px] font-medium text-gray-700 mb-1",children:"교역자"}),e.jsxs("select",{value:s,onChange:n=>c(n.target.value),className:"compact-input",children:[e.jsx("option",{value:"all",children:"전체"}),fe.map(n=>e.jsx("option",{value:n,children:n},n))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[12px] font-medium text-gray-700 mb-1",children:"검색"}),e.jsxs("div",{className:"relative",children:[e.jsx(Se,{className:"absolute left-2 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-gray-400"}),e.jsx("input",{type:"text",placeholder:"이름, 목적, 내용, 심방자...",value:u,onChange:n=>i(n.target.value),className:"compact-input pl-8"})]})]})]}),e.jsxs("div",{className:"flex items-center justify-between text-[11px] text-gray-500",children:[e.jsxs("span",{children:["총 ",P.length,"건의 심방 기록"]}),(D||$||v!=="all"||s!=="all"||y!=="all"||a!=="all"||N||u)&&e.jsx("button",{onClick:()=>{T(""),Y(""),_("all"),c("all"),f("all"),l("all"),w(!1),i("")},className:"text-red-500 hover:text-red-700 font-medium",children:"필터 초기화"})]})]}),o==="list"?e.jsx(Fe,{visits:P,membersMap:I,onEdit:n=>L(n),onDelete:Z,onCompleteFollowUp:ce,onShowHistory:K}):o==="calendar"?e.jsx(Te,{visits:P,members:b}):o==="visitor"?e.jsx(Ve,{visits:P,membersMap:I,members:b,onEdit:n=>L(n),onDelete:Z,onCompleteFollowUp:ce,exportToExcel:R}):e.jsx(Ee,{visits:P,members:b,onSelectMember:K})]}):e.jsx(Oe,{visits:h,members:b,exportToExcel:R}),be&&e.jsx(Ue,{members:b,onClose:()=>W(!1),onSuccess:n=>{n||W(!1),O()}}),E&&e.jsx(Ye,{memberId:E,member:b.find(n=>n.id===E),visits:h.filter(n=>n.member_id===E),onClose:()=>K(null),onEdit:n=>L(n),onDelete:Z,onPrint:()=>Ne(E),onExport:()=>{const n=h.filter(M=>M.member_id===E),C=b.find(M=>M.id===E);R(n,`심방기록_${(C==null?void 0:C.name)||""}`)}}),le&&e.jsx(Pe,{visit:le,members:b,onClose:()=>L(null),onSuccess:()=>{L(null),O()}}),je&&X&&e.jsx(Le,{member:b.find(n=>n.id===X),visits:h.filter(n=>n.member_id===X),onClose:()=>{ne(!1),oe(null)}})]})}function z({label:d,value:j,color:h,isAlert:p}){return e.jsxs("div",{className:"bg-white border border-gray-200 rounded shadow-sm p-3",children:[e.jsxs("div",{className:"text-[22px] font-bold text-gray-900 flex items-center gap-2",children:[j,p&&j>0&&e.jsx(A,{className:"w-4 h-4 text-orange-500"})]}),e.jsx("div",{className:"text-[11px] text-gray-500",children:d})]})}function Fe({visits:d,membersMap:j,onEdit:h,onDelete:p,onCompleteFollowUp:b,onShowHistory:g}){const r={가정심방:"bg-blue-50 text-blue-700",병원심방:"bg-red-50 text-red-700",전화심방:"bg-green-50 text-green-700",상담:"bg-blue-50 text-blue-700",이사심방:"bg-yellow-50 text-yellow-700",축하심방:"bg-blue-50 text-blue-700",위로심방:"bg-blue-50 text-blue-700",순회심방:"bg-blue-50 text-blue-700",등록심방:"bg-lime-50 text-lime-700",장결자심방:"bg-
2amber-50 text-amber-700",구역예배:"bg-orange-50 text-orange-700",기타:"bg-gray-100 text-gray-600"};return d.length===0?e.jsxs("div",{className:"bg-white border border-gray-200 rounded shadow-sm p-12 text-center",children:[e.jsx(te,{className:"w-12 h-12 text-gray-300 mx-auto mb-3"}),e.jsx("p",{className:"text-[13px] text-gray-500",children:"심방 기록이 없습니다"})]}):e.jsx("div",{className:"bg-white border border-gray-200 rounded shadow-sm overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-[12px]",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[e.jsx("th",{className:"text-left p-2 font-bold text-gray-700 whitespace-nowrap",children:"심방일자"}),e.jsx("th",{className:"text-left p-2 font-bold text-gray-700 whitespace-nowrap",children:"교인명"}),e.jsx("th",{className:"text-left p-2 font-bold text-gray-700 whitespace-nowrap",children:"직분"}),e.jsx("th",{className:"text-left p-2 font-bold text-gray-700 whitespace-nowrap",children:"교구"}),e.jsx("th",{className:"text-left p-2 font-bold text-gray-700 whitespace-nowrap",children:"심방유형"}),e.jsx("th",{className:"text-left p-2 font-bold text-gray-700 whitespace-nowrap",children:"구분"}),e.jsx("th",{className:"text-left p-2 font-bold text-gray-700 whitespace-nowrap",children:"심방자"}),e.jsx("th",{className:"text-left p-2 font-bold text-gray-700 whitespace-nowrap",children:"목적"}),e.jsx("th",{className:"text-left p-2 font-bold text-gray-700 whitespace-nowrap max-w-[200px]",children:"내용"}),e.jsx("th",{className:"text-center p-2 font-bold text-gray-700 whitespace-nowrap",children:"후속"}),e.jsx("th",{className:"text-center p-2 font-bold text-gray-700 whitespace-nowrap",children:"관리"})]})}),e.jsx("tbody",{children:d.map(t=>{var a,l;const o=j.get(t.member_id),x=(o==null?void 0:o.name)||t.member_name||"-",u=(o==null?void 0:o.position)||((a=t.original_data)==null?void 0:a.position)||"-",i=(o==null?void 0:o.parish)||"-";return e.jsxs("tr",{className:"border-t border-gray-100 hover:bg-blue-50/30 cursor-pointer",onClick:()=>h(t),children:[e.jsx("td",{className:"p-2 whitespace-nowrap text-gray-900",children:t.visit_date}),e.jsx("td",{className:"p-2 whitespace-nowrap font-medium text-gray-900",children:x}),e.jsx("td",{className:"p-2 whitespace-nowrap text-gray-500",children:u}),e.jsx("td",{className:"p-2 whitespace-nowrap text-gray-500",children:i}),e.jsx("td",{className:"p-2 whitespace-nowrap",children:e.jsx("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-medium ${r[t.visit_type]||"bg-gray-100 text-gray-600"}`,children:t.visit_type})}),e.jsxs("td",{className:"p-2 whitespace-nowrap",children:[t.urgency==="긴급"&&e.jsx("span",{className:"px-1.5 py-0.5 rounded text-[10px] font-medium bg-red-100 text-red-700",children:"긴급"}),t.urgency==="비공개"&&e.jsx("span",{className:"px-1.5 py-0.5 rounded text-[10px] font-medium bg-gray-200 text-gray-600",children:"비공개"}),(!t.urgency||t.urgency==="일반")&&e.jsx("span",{className:"text-gray-400",children:"-"})]}),e.jsx("td",{className:"p-2 whitespace-nowrap text-gray-600 text-[11px]",children:((l=t.visitors)==null?void 0:l.join(", "))||"-"}),e.jsx("td",{className:"p-2 text-gray-600 max-w-[150px] truncate",children:t.purpose||"-"}),e.jsx("td",{className:"p-2 text-gray-500 max-w-[200px] truncate",children:t.content||"-"}),e.jsx("td",{className:"p-2 text-center",children:t.follow_up_needed?e.jsx("button",{onClick:y=>{y.stopPropagation(),b(t.id)},className:"text-orange-500 hover:text-green-600",title:"후속조치 완료 처리",children:e.jsx(A,{className:"w-4 h-4"})}):e.jsx("span",{className:"text-gray-300",children:"-"})}),e.jsx("td",{className:"p-2 text-center",children:e.jsxs("div",{className:"flex items-center justify-center gap-1",children:[e.jsx("button",{onClick:y=>{y.stopPropagation(),h(t)},className:"text-blue-500 hover:text-blue-700",title:"수정",children:e.jsx(H,{className:"w-3.5 h-3.5"})}),e.jsx("button",{onClick:y=>{y.stopPropagation(),p(t.id)},className:"text-red-400 hover:text-red-600",title:"삭제",children:e.jsx(ae,{className:"w-3.5 h-3.5"})})]})})]},t.id)})})]})})})}function Te({visits:d,members:j}){const h=new Date,[p,b]=m.useState(h.getFullYear()),[g,r]=m.useState(h.getMonth()),[t,o]=m.useState(null),x=new Date(p,g,1).getDay(),u=new Date(p,g+1,0).getDate(),i=`${p}-${String(g+1).padStart(2,"0")}`,a=m.useMemo(()=>{const s={};return d.forEach(c=>{if(c.visit_date.startsWith(i)){const N=parseInt(c.visit_date.split("-")[2]);s[N]||(s[N]=[]),s[N].push(c)}}),s},[d,i]),l=Object.values(a).reduce((s,c)=>s+c.length,0);function y(){g===0?(b(p-1),r(11)):r(g-1),o(null)}function f(){g===11?(b(p+1),r(0)):r(g+1),o(null)}const v=[];for(let s=0;s<x;
2s++)v.push(null);for(let s=1;s<=u;s++)v.push(s);for(;v.length%7!==0;)v.push(null);const _=t?a[t]||[]:[];return e.jsxs("div",{className:"bg-white border border-gray-200 rounded shadow-sm p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("button",{onClick:y,className:"p-2 hover:bg-gray-100 rounded transition-colors",children:e.jsx(ge,{className:"w-5 h-5 text-gray-600"})}),e.jsxs("div",{className:"text-center",children:[e.jsxs("h3",{className:"text-[16px] font-bold text-gray-900",children:[p,"년 ",g+1,"월"]}),e.jsxs("p",{className:"text-[12px] text-gray-500",children:["심방 ",l,"건"]})]}),e.jsx("button",{onClick:f,className:"p-2 hover:bg-gray-100 rounded transition-colors",children:e.jsx(re,{className:"w-5 h-5 text-gray-600"})})]}),e.jsx("div",{className:"grid grid-cols-7 gap-1 mb-1",children:["일","월","화","수","목","금","토"].map((s,c)=>e.jsx("div",{className:`text-center text-[11px] font-bold py-1 ${c===0?"text-red-500":c===6?"text-blue-500":"text-gray-500"}`,children:s},s))}),e.jsx("div",{className:"grid grid-cols-7 gap-1",children:v.map((s,c)=>{var $;if(s===null)return e.jsx("div",{className:"h-16"},`e${c}`);const N=(($=a[s])==null?void 0:$.length)||0,w=p===h.getFullYear()&&g===h.getMonth()&&s===h.getDate(),D=t===s,T=c%7;return e.jsxs("div",{onClick:()=>o(s===t?null:s),className:`h-16 p-1 rounded cursor-pointer transition-all border ${D?"border-blue-600 bg-blue-50 shadow-sm":w?"border-blue-300 bg-blue-50":N>0?"border-gray-200 bg-gray-50 hover:bg-green-50 hover:border-green-200":"border-transparent hover:bg-gray-50"}`,children:[e.jsx("div",{className:`text-[12px] font-medium ${T===0?"text-red-500":T===6?"text-blue-500":"text-gray-700"} ${w?"font-bold":""}`,children:s}),N>0&&e.jsx("div",{className:"mt-1",children:e.jsxs("div",{className:`text-[10px] font-bold text-center rounded py-0.5 ${N>=3?"bg-blue-600 text-white":N>=2?"bg-green-200 text-green-800":"bg-green-100 text-green-700"}`,children:[N,"건"]})})]},s)})}),t&&_.length>0&&e.jsxs("div",{className:"mt-4 pt-4 border-t border-gray-200",children:[e.jsxs("h4",{className:"text-[13px] font-bold text-gray-900 mb-3",children:[g+1,"월 ",t,"일 심방 (",_.length,"건)"]}),e.jsx("div",{className:"space-y-2",children:_.map(s=>{var D;const c=j.find(T=>T.id===s.member_id),N=(c==null?void 0:c.name)||s.member_name||"(이름 없음)",w={가정심방:"bg-blue-100 text-blue-700",병원심방:"bg-red-100 text-red-700",전화심방:"bg-green-100 text-green-700",상담:"bg-blue-100 text-blue-700",이사심방:"bg-cyan-100 text-cyan-700",축하심방:"bg-blue-100 text-blue-700",위로심방:"bg-blue-100 text-blue-700",순회심방:"bg-blue-100 text-blue-700",등록심방:"bg-lime-100 text-lime-700",장결자심방:"bg-amber-100 text-amber-700",구역예배:"bg-orange-100 text-orange-700",기타:"bg-gray-100 text-gray-700"};return e.jsxs("div",{className:"p-3 bg-gray-50 rounded border border-gray-200",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:"text-[13px] font-bold text-gray-900",children:N}),e.jsx("span",{className:"text-[11px] text-gray-500",children:(c==null?void 0:c.position)||((D=s.original_data)==null?void 0:D.position)||""}),e.jsx("span",{className:`text-[10px] px-2 py-0.5 rounded font-medium ${w[s.visit_type]||w.기타}`,children:s.visit_type})]}),e.jsxs("div",{className:"text-[12px] text-gray-600",children:[s.visitors&&s.visitors.length>0&&e.jsxs("span",{children:["심방자: ",s.visitors.join(", ")," | "]}),s.purpose]}),s.location&&e.jsxs("div",{className:"text-[11px] text-gray-500 mt-0.5",children:["장소: ",s.location]})]},s.id)})})]}),t&&_.length===0&&e.jsxs("div",{className:"mt-4 pt-4 border-t border-gray-200 text-center text-[12px] text-gray-500 py-4",children:[g+1,"월 ",t,"일에 심방 기록이 없습니다"]})]})}function Ee({visits:d,members:j,onSelectMember:h}){const p=he(),b=d.reduce((r,t)=>{const o=t.member_id||"unknown";return r[o]||(r[o]=[]),r[o].push(t),r},{}),g=Object.entries(b).map(([r,t])=>{var a,l,y;const o=j.find(f=>f.id===r),x=(o==null?void 0:o.name)||((a=t[0])==null?void 0:a.member_name)||"(이름 없음)",u=(o==null?void 0:o.position)||((y=(l=t[0])==null?void 0:l.original_data)==null?void 0:y.position)||"",i=t.reduce((f,v)=>(f[v.visit_type]=(f[v.visit_type]||0)+1,f),{});return{member:o,memberId:r,displayName:x,displayPosition:u,total:t.length,lastDate:t[0].visit_date||"",lastType:t[0].visit_type,visitTypes:i,hasFollowUp:t.some(f=>f.follow_up_needed)}}).sort((r,t)=>t.lastDate.localeCompare(r.lastDate));return g.length===0?e.jsxs("div",{className:"bg-white border border-gray-200 rounded shadow-sm p-12 text-center",children:[e.jsx(ue,{className:"w-12 h-12 text-gray-300 mx-auto mb-3"}),e.jsx("p",{className:"text-[13px] text-gray-500",children:"심방 기록이 있는 교인이 없습니다"})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"text-[12px] text-gray-500 mb-2",children:["심방 기록이 있는 교인: ",g.length,"명"]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3",children:g.map(r=>{const{member:t,memberId:o,displayName:x,displayPosition:u,total:i,lastDate:a,visitTypes:l,hasFollowUp:y}=r;return e.jsx("div",{onClick:()=>h(o),className:"bg-white border border-gray-200 rounded shadow-sm p-4 cursor-pointer hover:border-blue-600 hover:shadow-md transition-all",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{onClick:f=>{f.stopPropagation(),t&&p(`/members/${o}/edit`)},className:t?"cursor-pointer":"",title:t?"교적부 보기":"디모데 전용 멤버",children:t!=null&&t.photo_url?e.jsx("img",{src:t.photo_url,alt:x,className:"w-12 h-12 rounded-full object-cover hover:ring-2 hover:ring-blue-600",onError:f=>{f.currentTarget.style.display="none"}}):e.jsx("div",{className:`w-12 h-12 rounded-full flex items-center justify-center text-[14px] font-bold ${t?"bg-gray-200 text-gray-600 hover:ring-2 hover:ring-blue-600":"bg-amber-100 text-amber-700"}`,children:x[0]})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"text-[14px] font-bold text-gray-900",children:x}),!t&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-amber-100 text-amber-700 rounded",children:"디모데"}),y&&e.jsx(A,{className:"w-3.5 h-3.5 text-orange-500"})]}),e.jsx("p",{className:"text-[11px] text-gray-500",children:u}),e.jsxs("div",{className:"mt-2 flex items-center gap-3 text-[11px]",children:[e.jsxs("span",{className:"text-blue-600 font-medium",children:["총 ",i,"회"]}),e.jsx("span",{className:"text-gray-400",children:"|"}),e.jsxs("span",{className:"text-gray-500",children:["최근: ",a||"날짜 없음"]})]}),e.jsx("div",{className:"mt-2 flex flex-wrap gap-1",children:Object.entries(l).map(([f,v])=>e.jsxs("span",{className:"text-[10px] px-1.5 py-0.5 bg-gray-100 text-gray-600 rounded",children:[f," ",v]},f))})]}),e.jsx(re,{className:"w-5 h-5 text-gray-400"})]})},o)})})]})}function Ve({visits:d,membersMap:j,members:h,onEdit:p,onDelete:b,onCompleteFollowUp:g,exportToExcel:r}
2){const[t,o]=m.useState(null),x=m.useMemo(()=>h.filter(l=>l.member_classification==="서둔출석교역자").map(l=>l.name).filter(Boolean),[h]),u=m.useMemo(()=>{const l={};return d.forEach(y=>{(y.visitors||[]).forEach(f=>{x.includes(f)&&(l[f]||(l[f]=[]),l[f].push(y))})}),l},[d,x]),i=m.useMemo(()=>{const l=new Date;return Object.entries(u).map(([y,f])=>{const v=f.filter(_=>{const s=new Date(_.visit_date);return s.getMonth()===l.getMonth()&&s.getFullYear()===l.getFullYear()}).length;return{name:y,total:f.length,thisMonth:v}}).sort((y,f)=>f.total-y.total)},[u]),a=m.useMemo(()=>t?u[t]||[]:d,[t,u,d]);return i.length===0?e.jsxs("div",{className:"bg-white border border-gray-200 rounded shadow-sm p-12 text-center",children:[e.jsx(se,{className:"w-12 h-12 text-gray-300 mx-auto mb-3"}),e.jsx("p",{className:"text-[13px] text-gray-500",children:"심방 기록이 없습니다"})]}):e.jsxs("div",{className:"flex gap-4",children:[e.jsxs("div",{className:"w-56 flex-shrink-0 space-y-1",children:[e.jsxs("div",{className:"text-[12px] text-gray-500 mb-2",children:["교역자: ",i.length,"명"]}),e.jsx("button",{onClick:()=>o(null),className:`w-full text-left px-3 py-2 rounded text-[12px] transition-colors ${t?"bg-white border border-gray-200 text-gray-700 hover:bg-gray-50":"bg-blue-600 text-white font-bold"}`,children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{children:"전체 보기"}),e.jsxs("span",{className:`text-[11px] ${t?"text-gray-400":"text-white/80"}`,children:[d.length,"건"]})]})}),i.map(({name:l,total:y,thisMonth:f})=>e.jsxs("button",{onClick:()=>o(l),className:`w-full text-left px-3 py-2 rounded text-[12px] transition-colors ${t===l?"bg-blue-600 text-white font-bold":"bg-white border border-gray-200 text-gray-700 hover:bg-gray-50"}`,children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"font-medium truncate",children:l}),e.jsxs("span",{className:`text-[11px] ${t===l?"text-white/80":"text-blue-600 font-bold"}`,children:[y,"건"]})]}),e.jsxs("div",{className:`text-[10px] mt-0.5 ${t===l?"text-white/60":"text-gray-400"}`,children:["이번달 ",f,"건"]})]},l))]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("div",{className:"text-[12px] text-gray-500",children:t?e.jsxs("span",{children:[e.jsx("span",{className:"font-bold text-gray-900",children:t})," 교역자의 심방기록 (",a.length,"건)"]}):e.jsxs("span",{children:["전체 심방기록 (",a.length,"건)"]})}),e.jsxs("button",{onClick:()=>r(a,`심방기록_${t||"전체"}`),className:"flex items-center gap-1 px-3 py-1.5 bg-green-50 text-green-700 rounded text-[11px] hover:bg-green-100 transition-colors",children:[e.jsx(B,{className:"w-3.5 h-3.5"}),"엑셀"]})]}),e.jsx("div",{className:"bg-white border border-gray-200 rounded shadow-sm overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-[12px]",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[e.jsx("th",{className:"text-left p-2 font-bold text-gray-700 whitespace-nowrap",children:"심방일자"}),e.jsx("th",{className:"text-left p-2 font-bold text-gray-700 whitespace-nowrap",children:"교인명"}),e.jsx("th",{className:"text-left p-2 font-bold text-gray-700 whitespace-nowrap",children:"직분"}),e.jsx("th",{className:"text-left p-2 font-bold text-gray-700 whitespace-nowrap",children:"교구"}),e.jsx("th",{className:"text-left p-2 font-bold text-gray-700 whitespace-nowrap",children:"심방유형"}),e.jsx("th",{className:"text-left p-2 font-bold text-gray-700 whitespace-nowrap",children:"구분"}),e.jsx("th",{className:"text-left p-2 font-bold text-gray-700 whitespace-nowrap",children:"심방자"}),e.jsx("th",{className:"text-left p-2 font-bold text-gray-700 whitespace-nowrap",children:"목적"}),e.jsx("th",{className:"text-left p-2 font-bold text-gray-700 whitespace-nowrap max-w-[200px]",children:"내용"}),e.jsx("th",{className:"text-center p-2 font-bold text-gray-700 whitespace-nowrap",children:"후속"}),e.jsx("th",{className:"text-center p-2 font-bold text-gray-700 whitespace-nowrap",children:"관리"})]})}),e.jsx("tbody",{children:a.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:11,className:"text-center py-8 text-gray-400",children:"심방 기록이 없습니다"})}
2):a.map(l=>{var c,N;const y=j.get(l.member_id),f=(y==null?void 0:y.name)||l.member_name||"-",v=(y==null?void 0:y.position)||((c=l.original_data)==null?void 0:c.position)||"-",_=(y==null?void 0:y.parish)||"-",s={가정심방:"bg-blue-50 text-blue-700",병원심방:"bg-red-50 text-red-700",전화심방:"bg-green-50 text-green-700",상담:"bg-blue-50 text-blue-700",이사심방:"bg-yellow-50 text-yellow-700",축하심방:"bg-blue-50 text-blue-700",위로심방:"bg-blue-50 text-blue-700",구역예배:"bg-blue-50 text-blue-700"};return e.jsxs("tr",{className:"border-t border-gray-100 hover:bg-blue-50/30 cursor-pointer",onClick:()=>p(l),children:[e.jsx("td",{className:"p-2 whitespace-nowrap text-gray-900",children:l.visit_date}),e.jsx("td",{className:"p-2 whitespace-nowrap font-medium text-gray-900",children:f}),e.jsx("td",{className:"p-2 whitespace-nowrap text-gray-500",children:v}),e.jsx("td",{className:"p-2 whitespace-nowrap text-gray-500",children:_}),e.jsx("td",{className:"p-2 whitespace-nowrap",children:e.jsx("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-medium ${s[l.visit_type]||"bg-gray-100 text-gray-600"}`,children:l.visit_type})}),e.jsxs("td",{className:"p-2 whitespace-nowrap",children:[l.urgency==="긴급"&&e.jsx("span",{className:"px-1.5 py-0.5 rounded text-[10px] font-medium bg-red-100 text-red-700",children:"긴급"}),l.urgency==="비공개"&&e.jsx("span",{className:"px-1.5 py-0.5 rounded text-[10px] font-medium bg-gray-200 text-gray-600",children:"비공개"}),(!l.urgency||l.urgency==="일반")&&e.jsx("span",{className:"text-gray-400",children:"-"})]}),e.jsx("td",{className:"p-2 whitespace-nowrap text-gray-600 text-[11px]",children:((N=l.visitors)==null?void 0:N.join(", "))||"-"}),e.jsx("td",{className:"p-2 text-gray-600 max-w-[150px] truncate",children:l.purpose||"-"}),e.jsx("td",{className:"p-2 text-gray-500 max-w-[200px] truncate",children:l.content||"-"}),e.jsx("td",{className:"p-2 text-center",children:l.follow_up_needed?e.jsx("button",{onClick:w=>{w.stopPropagation(),g(l.id)},className:"text-orange-500 hover:text-green-600",title:"후속조치 완료 처리",children:e.jsx(A,{className:"w-4 h-4"})}):e.jsx("span",{className:"text-gray-300",children:"-"})}),e.jsx("td",{className:"p-2 text-center",children:e.jsxs("div",{className:"flex items-center justify-center gap-1",children:[e.jsx("button",{onClick:w=>{w.stopPropagation(),p(l)},className:"text-blue-500 hover:text-blue-700",title:"수정",children:e.jsx(H,{className:"w-3.5 h-3.5"})}),e.jsx("button",{onClick:w=>{w.stopPropagation(),b(l.id)},className:"text-red-400 hover:text-red-600",title:"삭제",children:e.jsx(ae,{className:"w-3.5 h-3.5"})})]})})]},l.id)})})]})})})]})]})}function Ue({members:d,onClose:j,onSuccess:h}){const[p,b]=m.useState(!1),[g,r]=m.useState(!1),[t,o]=m.useState(""),[x,u]=m.useState(!1),i=m.useRef(null),[a,l]=m.useState({member_id:"",visit_date:new Date().toISOString().split("T")[0],visit_type:"가정심방",urgency:"일반",visitors:"",companion:"",purpose:"",content:"",location:"",scripture:"",hymn:"",prayer_topics:"",follow_up_needed:!1,follow_up_date:""}),y=m.useMemo(()=>{if(!t)return d.slice(0,50);const s=t.toLowerCase();return d.filter(c=>c.name.toLowerCase().includes(s)||(c.position||"").toLowerCase().includes(s))},[d,t]);m.useEffect(()=>{function s(c){i.current&&!i.current.contains(c.target)&&u(!1)}return document.addEventListener("mousedown",s),()=>document.removeEventListener("mousedown",s)},[]);function f(){l({member_id:"",visit_date:new Date().toISOString().split("T")[0],visit_type:a.visit_type,urgency:a.urgency,visitors:a.visitors,companion:"",purpose:"",content:"",location:"",scripture:"",hymn:"",prayer_topics:"",follow_up_needed:!1,follow_up_date:""}),o("")}async function v(s){if(s.preventDefault(),!a.member_id||!a.purpose||!a.content){S.error("필수 항목을 입력하세요");return}try{b(!0),await q.addVisit({member_id:a.member_id,visit_date:a.visit_date,visit_type:a.visit_type,urgency:a.urgency||"일반",visitors:a.visitors.split(",").map(c=>c.trim()).filter(c=>c),companion:a.companion.trim()||void 0,purpose:a.purpose,content:a.content,location:a.location.trim()||void 0,scripture:a.scripture.trim()||void 0,hymn:a.hymn.trim()||void 0,prayer_topics:a.prayer_topics?a.prayer_topics.split(`
3`).map(c=>c.trim()).filter(c=>c):void 0,follow_up_needed:a.follow_up_needed,follow_up_date:a.follow_up_needed?a.follow_up_date:void 0}),g?(S.success("추가됨! 계속 입력하세요."),f(),h(!0)):(S.success("심방 기록이 추가되었습니다"),h(!1))}catch{S.error("추가에 실패했습니다")}finally{b(!1)}}const _=d.find(s=>s.id===a.member_id);return e.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4",children:e.jsxs("div",{className:"bg-white rounded-lg shadow-xl max-w-xl w-full max-h-[90vh] overflow-y-auto",children:[e.jsxs("div",{className:"p-4 border-b border-gray-200 flex items-center justify-between",children:[e.jsx("h2",{className:"text-[16px] font-bold text-gray-900",children:"심방 기록 추가"}),e.jsx("button",{onClick:j,className:"p-1 hover:bg-gray-100 rounded",children:e.jsx(G,{className:"w-5 h-5 text-gray-500"})})]}),e.jsxs("form",{onSubmit:v,className:"p-4 space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{ref:i,className:"relative",children:[e.jsxs("label",{className:"block text-[12px] font-medium text-gray-700 mb-1",children:["교인 ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{type:"text",value:t,onChange:s=>{o(s.target.value),u(!0),l({...a,member_id:""})},onFocus:()=>u(!0),className:"compact-input",placeholder:"이름을 입력하세요"}),_&&e.jsxs("div",{className:"text-[10px] text-green-600 mt-0.5 flex items-center gap-1",children:[e.jsx("span",{children:"✓"})," ",_.name," (",_.position,")"]}),x&&e.jsx("div",{className:"absolute z-20 w-full mt-1 bg-white border border-gray-200 rounded shadow-lg max-h-48 overflow-y-auto",children:y.length===0?e.jsx("div",{className:"px-3 py-2 text-[12px] text-gray-500",children:"검색 ê²°ê
3³¼ 없음"}):y.map(s=>e.jsxs("div",{onClick:()=>{l({...a,member_id:s.id}),o(s.name),u(!1)},className:`px-3 py-2 text-[12px] cursor-pointer hover:bg-green-50 transition-colors ${a.member_id===s.id?"bg-green-50 text-green-700 font-medium":"text-gray-700"}`,children:[s.name," ",e.jsxs("span",{className:"text-gray-400",children:["(",s.position,")"]})]},s.id))})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-[12px] font-medium text-gray-700 mb-1",children:["심방 유형 ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsxs("select",{value:a.visit_type,onChange:s=>l({...a,visit_type:s.target.value}),className:"compact-input",children:[e.jsx("option",{value:"가정심방",children:"가정심방"}),e.jsx("option",{value:"병원심방",children:"병원심방"}),e.jsx("option",{value:"전화심방",children:"전화심방"}),e.jsx("option",{value:"상담",children:"상담"}),e.jsx("option",{value:"이사심방",children:"이사심방"}),e.jsx("option",{value:"축하심방",children:"축하심방"}),e.jsx("option",{value:"위로심방",children:"위로심방"}),e.jsx("option",{value:"순회심방",children:"순회심방"}),e.jsx("option",{value:"등록심방",children:"등록심방"}),e.jsx("option",{value:"장결자심방",children:"장결자심방"}),e.jsx("option",{value:"구역예배",children:"구역예배"}),e.jsx("option",{value:"기타",children:"기타"})]})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-[12px] font-medium text-gray-700 mb-1",children:["심방 날짜 ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{type:"date",value:a.visit_date,onChange:s=>l({...a,visit_date:s.target.value}),className:"compact-input",required:!0})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[12px] font-medium text-gray-700 mb-1",children:"구분"}),e.jsxs("select",{value:a.urgency,onChange:s=>l({...a,urgency:s.target.value}),className:"compact-input",children:[e.jsx("option",{value:"일반",children:"일반"}),e.jsx("option",{value:"긴급",children:"긴급"}),e.jsx("option",{value:"비공개",children:"비공개"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[12px] font-medium text-gray-700 mb-1",children:"심방자 (쉼표로 구분)"}),e.jsx("input",{type:"text",value:a.visitors,onChange:s=>l({...a,visitors:s.target.value}),className:"compact-input",placeholder:"홍길동, 김철수"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[12px] font-medium text-gray-700 mb-1",children:"동행자"}),e.jsx("input",{type:"text",value:a.companion,onChange:s=>l({...a,companion:s.target.value}),className:"compact-input",placeholder:"동행자"})]})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-[12px] font-medium text-gray-700 mb-1",children:["심방 목적 ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{type:"text",value:a.purpose,onChange:s=>l({...a,purpose:s.target.value}),className:"compact-input",placeholder:"예: 정기 심방, 병문안",required:!0})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[12px] font-medium text-gray-700 mb-1",children:"장소"}),e.jsx("input",{type:"text",value:a.location,onChange:s=>l({...a,location:s.target.value}),className:"compact-input",placeholder:"예: 자택, 병원, 교회"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-[12px] font-medium text-gray-700 mb-1",children:["심방 내용 ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("textarea",{value:a.content,onChange:s=>l({...a,content:s.target.value}),className:"compact-input",rows:4,placeholder:"심방 내용을 자세히 기록하세요",required:!0})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-[12px] font-medium text-gray-700 mb-1",children:"말씀 (성경 구절)"}),e.jsx("input",{type:"text",value:a.scripture,onChange:s=>l({...a,scripture:s.target.value}),className:"compact-input",placeholder:"예: 시편 23:1-6"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[12px] font-medium text-gray-700 mb-1",children:"찬송"}),e.jsx("input",{type:"text",value:a.hymn,onChange:s=>l({...a,hymn:s.target.value}),className:"compact-input",placeholder:"예: 찬송가 370장"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[12px] font-medium text-gray-700 mb-1",children:"기도 제목 
3(줄바꿈으로 구분)"}),e.jsx("textarea",{value:a.prayer_topics,onChange:s=>l({...a,prayer_topics:s.target.value}),className:"compact-input",rows:3,placeholder:`건강 회복
4가족 평안`})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:a.follow_up_needed,onChange:s=>l({...a,follow_up_needed:s.target.checked}),className:"w-4 h-4"}),e.jsx("span",{className:"text-[12px] font-medium text-gray-700",children:"후속조치 필요"})]}),a.follow_up_needed&&e.jsx("input",{type:"date",value:a.follow_up_date,onChange:s=>l({...a,follow_up_date:s.target.value}),className:"compact-input"})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t border-gray-200",children:[e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:g,onChange:s=>r(s.target.checked),className:"w-4 h-4"}),e.jsx("span",{className:"text-[12px] text-gray-600",children:"연속 입력"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:j,className:"px-4 py-2 border border-gray-300 rounded hover:bg-gray-50 text-[13px]",children:"취소"}),e.jsx("button",{type:"submit",disabled:p,className:"px-4 py-2 bg-blue-600 text-white rounded hover:bg-blue-700 text-[13px] font-medium disabled:opacity-50",children:p?"추가 중...":"추가"})]})]})]})]})})}function Pe({visit:d,members:j,onClose:h,onSuccess:p}){var u,i;const[b,g]=m.useState(!1),[r,t]=m.useState({member_id:d.member_id,visit_date:d.visit_date,visit_type:d.visit_type,urgency:d.urgency||"일반",visitors:((u=d.visitors)==null?void 0:u.join(", "))||"",companion:d.companion||"",purpose:d.purpose,content:d.content,location:d.location||"",scripture:d.scripture||"",hymn:d.hymn||"",prayer_topics:((i=d.prayer_topics)==null?void 0:i.join(`
5`))||"",follow_up_needed:d.follow_up_needed,follow_up_date:d.follow_up_date||""}),o=j.find(a=>a.id===d.member_id);async function x(a){if(a.preventDefault(),!r.member_id||!r.purpose||!r.content){S.error("필수 항목을 입력하세요");return}try{g(!0),await q.updateVisit(d.id,{member_id:r.member_id,visit_date:r.visit_date,visit_type:r.visit_type,urgency:r.urgency,visitors:r.visitors.split(",").map(l=>l.trim()).filter(l=>l),companion:r.companion.trim()||void 0,purpose:r.purpose,content:r.content,location:r.location.trim()||void 0,scripture:r.scripture.trim()||void 0,hymn:r.hymn.trim()||void 0,prayer_topics:r.prayer_topics?r.prayer_topics.split(`
6`).map(l=>l.trim()).filter(l=>l):void 0,follow_up_needed:r.follow_up_needed,follow_up_date:r.follow_up_needed?r.follow_up_date:void 0}),S.success("심방 기록이 수정되었습니다"),p()}catch{S.error("수정에 실패했습니다")}finally{g(!1)}}return e.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4",children:e.jsxs("div",{className:"bg-white rounded-lg shadow-xl max-w-xl w-full max-h-[90vh] overflow-y-auto",children:[e.jsxs("div",{className:"p-4 border-b border-gray-200 flex items-center justify-between",children:[e.jsxs("h2",{className:"text-[16px] font-bold text-gray-900 flex items-center gap-2",children:[e.jsx(H,{className:"w-4 h-4 text-blue-600"}),"심방 기록 수정"]}),e.jsx("button",{onClick:h,className:"p-1 hover:bg-gray-100 rounded",children:e.jsx(G,{className:"w-5 h-5 text-gray-500"})})]}),e.jsxs("form",{onSubmit:x,className:"p-4 space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-[12px] font-medium text-gray-700 mb-1",children:"교인"}),e.jsx("input",{type:"text",value:(o==null?void 0:o.name)||d.member_name||"-",disabled:!0,className:"compact-input bg-gray-50"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-[12px] font-medium text-gray-700 mb-1",children:["심방 유형 ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsxs("select",{value:r.visit_type,onChange:a=>t({...r,visit_type:a.target.value}),className:"compact-input",children:[e.jsx("option",{value:"가정심방",children:"가정심방"}),e.jsx("option",{value:"병원심방",children:"병원심방"}),e.jsx("option",{value:"전화심방",children:"전화심방"}),e.jsx("option",{value:"상담",children:"상담"}),e.jsx("option",{value:"이사심방",children:"이사심방"}),e.jsx("option",{value:"축하심방",children:"축하심방"}),e.jsx("option",{value:"위로심방",children:"위로심방"}),e.jsx("option",{value:"순회심방",children:"순회심방"}),e.jsx("option",{value:"등록심방",children:"등록심방"}),e.jsx("option",{value:"장결자심방",children:"장결자심방"}),e.jsx("option",{value:"구역예배",children:"구역예배"}),e.jsx("option",{value:"기타",children:"기타"})]})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-[12px] font-medium text-gray-700 mb-1",children:["심방 날짜 ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{type:"date",value:r.visit_date,onChange:a=>t({...r,visit_date:a.target.value}),className:"compact-input",required:!0})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[12px] font-medium text-gray-700 mb-1",children:"구분"}),e.jsxs("select",{value:r.urgency,onChange:a=>t({...r,urgency:a.target.value}),className:"compact-input",children:[e.jsx("option",{value:"일반",children:"일반"}),e.jsx("option",{value:"긴급",children:"긴급"}),e.jsx("option",{value:"비공개",children:"비공개"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[12px] font-medium text-gray-700 mb-1",children:"심방자 (쉼표로 구분)"}),e.jsx("input",{type:"text",value:r.visitors,onChange:a=>t({...r,visitors:a.target.value}),className:"compact-input",placeholder:"홍길동, 김철수"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[12px] font-medium text-gray-700 mb-1",children:"동행자"}),e.jsx("input",{type:"text",value:r.companion,onChange:a=>t({...r,companion:a.target.value}),className:"compact-input",placeholder:"동행자"})]})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-[12px] font-medium text-gray-700 mb-1",children:["심방 목적 ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{type:"text",value:r.purpose,onChange:a=>t({...r,purpose:a.target.value}),className:"compact-input",required:!0})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[12px] font-medium text-gray-700 mb-1",children:"장소"}),e.jsx("input",{type:"text",value:r.location,onChange:a=>t({...r,location:a.target.value}),className:"compact-input",placeholder:"예: 자택, 병원, 교회"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-[12px] font-medium text-gray-700 mb-1",children:["심방 내용 ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("textarea",{value:r.content,onChange:a=>t({...r,content:a.target.value}),className:"compact-input",rows:4,required:!0})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-[12px] font-medium text-gray-700 mb-1",children:"말씀 (성경 구절)"}),e.jsx("input",{type:"text",value:r.scripture,onChange:a=>t({...r,scripture:a.target.value}),className:"compact-input",placeholder:"예: 시편 23:1-6"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[12px] font-medium text-gray-700 mb-1",children:"찬송"}),e.jsx("input",{type:"text",value:r.hymn,onChange:a=>t({...r,hymn:a.target.value}),className:"compact-input",placeholder:"예: 찬송가 370장"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[12px] font-medium text-gray-700 mb-1",children:"기도 제목 
6(줄바꿈으로 구분)"}),e.jsx("textarea",{value:r.prayer_topics,onChange:a=>t({...r,prayer_topics:a.target.value}),className:"compact-input",rows:3})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:r.follow_up_needed,onChange:a=>t({...r,follow_up_needed:a.target.checked}),className:"w-4 h-4"}),e.jsx("span",{className:"text-[12px] font-medium text-gray-700",children:"후속조치 필요"})]}),r.follow_up_needed&&e.jsx("input",{type:"date",value:r.follow_up_date,onChange:a=>t({...r,follow_up_date:a.target.value}),className:"compact-input"})]}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx("button",{type:"button",onClick:h,className:"flex-1 px-3 py-2 border border-gray-300 rounded hover:bg-gray-50 text-[13px]",children:"취소"}),e.jsx("button",{type:"submit",disabled:b,className:"flex-1 px-3 py-2 bg-blue-600 text-white rounded hover:bg-blue-700 text-[13px] font-medium disabled:opacity-50",children:b?"수정 중...":"수정"})]})]})]})})}function Ye({memberId:d,member:j,visits:h,onClose:p,onEdit:b,onDelete:g,onPrint:r,onExport:t}){var y,f,v,_;const[o,x]=m.useState(!1),u=(j==null?void 0:j.name)||((y=h[0])==null?void 0:y.member_name)||"(이름 없음)",i=(j==null?void 0:j.position)||((v=(f=h[0])==null?void 0:f.original_data)==null?void 0:v.position)||"",a={가정심방:"bg-blue-500",병원심방:"bg-red-500",전화심방:"bg-green-500",상담:"bg-blue-500",이사심방:"bg-cyan-500",축하심방:"bg-blue-500",위로심방:"bg-blue-500",순회심방:"bg-blue-500",등록심방:"bg-lime-500",장결자심방:"bg-amber-500",구역예배:"bg-orange-500",기타:"bg-gray-500"},l={total:h.length,lastVisit:((_=h[0])==null?void 0:_.visit_date)||"-",visitTypes:h.reduce((s,c)=>(s[c.visit_type]=(s[c.visit_type]||0)+1,s),{}),followUpCount:h.filter(s=>s.follow_up_needed).length};return e.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4",children:e.jsxs("div",{className:"bg-white rounded-lg shadow-xl max-w-2xl w-full max-h-[90vh] flex flex-col",children:[e.jsxs("div",{className:"p-4 border-b border-gray-200 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[j!=null&&j.photo_url&&!o?e.jsx("img",{src:j.photo_url,alt:u,className:"w-10 h-10 rounded-full object-cover",onError:()=>x(!0)}):e.jsx("div",{className:`w-10 h-10 rounded-full flex items-center justify-center text-[15px] font-bold shadow-sm ${j?"bg-blue-600 text-white":"bg-amber-100 text-amber-700"}`,children:u[0]||"?"}),e.jsxs("div",{children:[e.jsxs("h2",{className:"text-[16px] font-bold text-gray-900 flex items-center gap-2",children:[e.jsx(Me,{className:"w-4 h-4 text-blue-600"}),u," 심방 히스토리",!j&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-amber-100 text-amber-700 rounded",children:"디모데"})]}),e.jsx("p",{className:"text-[12px] text-gray-500",children:i})]})]}),e.jsx("button",{onClick:p,className:"p-1 hover:bg-gray-100 rounded",children:e.jsx(G,{className:"w-5 h-5 text-gray-500"})})]}),e.jsx("div",{className:"p-4 bg-gray-50 border-b border-gray-200",children:e.jsxs("div",{className:"grid grid-cols-4 gap-3",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-[20px] font-bold text-blue-600",children:l.total}),e.jsx("div",{className:"text-[11px] text-gray-500",children:"총 심방"})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-[13px] font-bold text-gray-900",children:l.lastVisit}),e.jsx("div",{className:"text-[11px] text-gray-500",children:"최근 심방"})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-[20px] font-bold text-blue-600",children:l.visitTypes.가정심방||0}),e.jsx("div",{className:"text-[11px] text-gray-500",children:"가정심방"})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-[20px] font-bold text-orange-600",children:l.followUpCount}),e.jsx("div",{className:"text-[11px] text-gray-500",children:"후속조치"})]})]})}),e.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:h.length===0?e.jsxs("div",{className:"text-center py-8",children:[e.jsx(te,{className:"w-12 h-12 text-gray-300 mx-auto mb-3"}),e.jsx("p",{className:"text-[13px] text-gray-500",children:"심방 기록이 없습니다"})]}):e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute left-4 top-0 bottom-0 w-0.5 bg-gray-200"}),e.jsx("div",{className:"space-y-4",children:h.map(s=>e.jsxs("div",{className:"relative pl-10",children:[e.jsx("div",{className:`absolute left-2.5 w-3 h-3 rounded-full ${a[s.visit_type]||a.기타}
6`,style:{top:"6px"}}),e.jsxs("div",{className:"bg-white border border-gray-200 rounded p-3 hover:shadow-sm transition-shadow",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[13px] font-bold text-gray-900",children:s.visit_date}),e.jsx("span",{className:`text-[11px] px-2 py-0.5 rounded font-medium text-white ${a[s.visit_type]||a.기타}`,children:s.visit_type}),s.urgency&&s.urgency!=="일반"&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-red-50 text-red-600 rounded",children:s.urgency}),s.follow_up_needed&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-orange-100 text-orange-700 rounded",children:"후속조치"})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{onClick:()=>b(s),className:"p-1 hover:bg-gray-100 rounded",title:"수정",children:e.jsx(H,{className:"w-3 h-3 text-blue-600"})}),e.jsx("button",{onClick:()=>g(s.id),className:"p-1 hover:bg-gray-100 rounded",title:"삭제",children:e.jsx(ae,{className:"w-3 h-3 text-red-600"})})]})]}),e.jsxs("div",{className:"space-y-1.5 text-[12px]",children:[s.visitors&&s.visitors.length>0&&e.jsxs("div",{className:"flex items-center gap-1 text-gray-600",children:[e.jsx(se,{className:"w-3 h-3 text-gray-400"}),e.jsxs("span",{children:["심방자: ",s.visitors.join(", ")]})]}),s.companion&&e.jsxs("div",{className:"text-gray-600",children:[e.jsx("span",{className:"font-medium text-gray-700",children:"동행자:"})," ",s.companion]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-gray-700",children:"목적:"}),e.jsx("span",{className:"text-gray-600 ml-1",children:s.purpose})]}),s.location&&e.jsxs("div",{className:"flex items-center gap-1 text-gray-600",children:[e.jsx(De,{className:"w-3 h-3 text-gray-400"}),e.jsxs("span",{children:["장소: ",s.location]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-gray-700",children:"내용:"}),e.jsx("p",{className:"text-gray-600 mt-0.5 whitespace-pre-wrap",children:s.content})]}),s.scripture&&e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-gray-700",children:"말씀:"}),e.jsx("span",{className:"text-gray-600 ml-1",children:s.scripture})]}),s.hymn&&e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-gray-700",children:"찬송:"}),e.jsx("span",{className:"text-gray-600 ml-1",children:s.hymn})]}),s.prayer_topics&&s.prayer_topics.length>0&&e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-gray-700",children:"기도 제목:"}),e.jsx("ul",{className:"text-gray-600 mt-0.5 ml-4",children:s.prayer_topics.map((c,N)=>e.jsx("li",{className:"list-disc",children:c},N))})]}),s.follow_up_needed&&s.follow_up_date&&e.jsxs("div",{className:"flex items-center gap-1 text-orange-600",children:[e.jsx($e,{className:"w-3 h-3"}),e.jsxs("span",{children:["후속조치 예정: ",s.follow_up_date]})]})]})]})]},s.id))})]})}),e.jsx("div",{className:"p-4 border-t border-gray-200",children:e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{onClick:r,className:"flex-1 flex items-center justify-center gap-1.5 px-4 py-2 border border-gray-300 text-gray-700 rounded hover:bg-gray-50 text-[13px] font-medium",children:[e.jsx(ee,{className:"w-4 h-4"}),"인쇄"]}),e.jsxs("button",{onClick:t,className:"flex-1 flex items-center justify-center gap-1.5 px-4 py-2 border border-gray-300 text-gray-700 rounded hover:bg-gray-50 text-[13px] font-medium",children:[e.jsx(B,{className:"w-4 h-4"}),"엑셀"]}),e.jsx("button",{onClick:p,className:"flex-1 px-4 py-2 bg-gray-100 text-gray-700 rounded hover:bg-gray-200 text-[13px] font-medium",children:"닫기"})]})})]})})}function Le({member:d,visits:j,onClose:h}){var r;if(!d)return null;const p={가정심방:"#3b82f6",병원심방:"#ef4444",전화심방:"#22c55e",상담:"#a855f7",기타:"#6b7280"},b={total:j.length,lastVisit:((r=j[0])==null?void 0:r.visit_date)||"-",visitTypes:j.reduce((t,o)=>(t[o.visit_type]=(t[o.visit_type]||0)+1,t),{}),followUpCount:j.filter(t=>t.follow_up_needed).length};function g(){const t=document.getElementById("print-content");
6if(!t)return;const o=window.open("","_blank");if(!o){S.error("팝업이 차단되었습니다.");return}o.document.write(`<!DOCTYPE html><html><head><title>${d.name} 심방 히스토리</title><style>
7      *{margin:0;padding:0;box-sizing:border-box}body{font-family:'Malgun Gothic',sans-serif;padding:20px;font-size:12px}
8      .header{text-align:center;margin-bottom:20px;padding-bottom:15px;border-bottom:2px solid #333}.header h1{font-size:18px;margin-bottom:5px}
9      .stats{display:flex;justify-content:space-around;margin-bottom:20px;padding:10px;background:#f5f5f5}
10      .visit-item{margin-bottom:15px;padding:10px;border:1px solid #ddd;border-radius:4px;page-break-inside:avoid}
11      .visit-type{padding:2px 8px;border-radius:4px;color:white;font-size:10px}
12      .footer{margin-top:20px;text-align:center;font-size:10px;color:#999;border-top:1px solid #ddd;padding-top:10px}
13      @media print{body{padding:0}.no-print{display:none}}
14    </style></head><body>${t.innerHTML}<div class="footer">서둔교회 ChurchOS - 출력일: ${new Date().toLocaleDateString("ko-KR")}</div></body></html>`),o.document.close(),o.focus(),setTimeout(()=>{o.print(),o.close()},250)}return e.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4",children:e.jsxs("div",{className:"bg-white rounded-lg shadow-xl max-w-3xl w-full max-h-[90vh] flex flex-col",children:[e.jsxs("div",{className:"p-4 border-b border-gray-200 flex items-center justify-between",children:[e.jsxs("h2",{className:"text-[16px] font-bold text-gray-900 flex items-center gap-2",children:[e.jsx(ee,{className:"w-4 h-4 text-gray-600"}),"인쇄 미리보기"]}),e.jsx("button",{onClick:h,className:"p-1 hover:bg-gray-100 rounded",children:e.jsx(G,{className:"w-5 h-5 text-gray-500"})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-6 bg-gray-100",children:e.jsxs("div",{id:"print-content",className:"bg-white p-6 shadow-sm max-w-2xl mx-auto",style:{minHeight:"600px"},children:[e.jsxs("div",{className:"header text-center mb-6 pb-4 border-b-2 border-gray-800",children:[e.jsxs("h1",{className:"text-xl font-bold mb-1",children:[d.name," 심방 히스토리"]}),e.jsxs("p",{className:"text-sm text-gray-600",children:[d.position," | 총 ",b.total,"회 심방"]})]}),e.jsxs("div",{className:"stats grid grid-cols-4 gap-4 mb-6 p-3 bg-gray-50 rounded",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-lg font-bold text-green-600",children:b.total}),e.jsx("div",{className:"text-xs text-gray-500",children:"총 심방"})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-sm font-bold",children:b.lastVisit}),e.jsx("div",{className:"text-xs text-gray-500",children:"최근 심방"})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-lg font-bold text-blue-600",children:b.visitTypes.가정심방||0}),e.jsx("div",{className:"text-xs text-gray-500",children:"가정심방"})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-lg font-bold text-orange-600",children:b.followUpCount}),e.jsx("div",{className:"text-xs text-gray-500",children:"후속조치"})]})]}),e.jsx("div",{className:"space-y-4",children:j.map(t=>e.jsxs("div",{className:"p-3 border border-gray-200 rounded",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"font-bold",children:t.visit_date}),e.jsx("span",{className:"text-xs px-2 py-0.5 rounded text-white",style:{backgroundColor:p[t.visit_type]||p.기타},children:t.visit_type})]}),e.jsxs("div",{className:"text-xs space-y-1 text-gray-700",children:[t.visitors&&t.visitors.length>0&&e.jsxs("p",{children:[e.jsx("strong",{children:"심방자:"})," ",t.visitors.join(", ")]}),t.companion&&e.jsxs("p",{children:[e.jsx("strong",{children:"동행자:"})," ",t.companion]}),e.jsxs("p",{children:[e.jsx("strong",{children:"목적:"})," ",t.purpose]}),t.location&&e.jsxs("p",{children:[e.jsx("strong",{children:"장소:"})," ",t.location]}),e.jsxs("p",{children:[e.jsx("strong",{children:"내용:"})," ",t.content]}
14),t.scripture&&e.jsxs("p",{children:[e.jsx("strong",{children:"말씀:"})," ",t.scripture]}),t.hymn&&e.jsxs("p",{children:[e.jsx("strong",{children:"찬송:"})," ",t.hymn]}),t.prayer_topics&&t.prayer_topics.length>0&&e.jsxs("p",{children:[e.jsx("strong",{children:"기도제목:"})," ",t.prayer_topics.join(", ")]}),t.follow_up_needed&&e.jsxs("p",{className:"text-orange-600",children:[e.jsx("strong",{children:"후속조치 예정:"})," ",t.follow_up_date||"미정"]})]})]},t.id))})]})}),e.jsx("div",{className:"p-4 border-t border-gray-200",children:e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:h,className:"flex-1 px-4 py-2 border border-gray-300 text-gray-700 rounded hover:bg-gray-50 text-[13px] font-medium",children:"취소"}),e.jsxs("button",{onClick:g,className:"flex-1 flex items-center justify-center gap-1.5 px-4 py-2 bg-blue-600 text-white rounded hover:bg-blue-700 text-[13px] font-medium",children:[e.jsx(ee,{className:"w-4 h-4"}),"인쇄하기"]})]})})]})})}function Oe({visits:d,members:j,exportToExcel:h}){const[p,b]=m.useState("monthly");return e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex gap-1 bg-gray-100 p-1 rounded-lg overflow-x-auto",children:[["monthly","월별 심방현황"],["visitor","심방자별 통계"],["type","심방구분별 통계"],["individual","개인별 연간통계"]].map(([g,r])=>e.jsx("button",{onClick:()=>b(g),className:`px-4 py-2 rounded-md text-[13px] font-medium transition-all whitespace-nowrap ${p===g?"bg-white text-blue-600 shadow-sm":"text-gray-500 hover:text-gray-700"}`,children:r},g))}),p==="monthly"&&e.jsx(Ie,{visits:d,members:j}),p==="visitor"&&e.jsx(qe,{visits:d}),p==="type"&&e.jsx(Ae,{visits:d}),p==="individual"&&e.jsx(Re,{visits:d,members:j,exportToExcel:h})]})}function Ie({visits:d,members:j}){const h=new Date,[p,b]=m.useState(h.getFullYear()),[g,r]=m.useState(h.getMonth()),[t,o]=m.useState(null),x=`${p}-${String(g+1).padStart(2,"0")}`,u=new Date(p,g,1).getDay(),i=new Date(p,g+1,0).getDate(),a=m.useMemo(()=>{const c={};return d.forEach(N=>{if(N.visit_date.startsWith(x)){const w=parseInt(N.visit_date.split("-")[2]);c[w]||(c[w]=[]),c[w].push(N)}}),c},[d,x]),l=Object.values(a).reduce((c,N)=>c+N.length,0),y=Object.keys(a).length,f=[];for(let c=0;c<u;c++)f.push(null);for(let c=1;c<=i;c++)f.push(c);for(;f.length%7!==0;)f.push(null);function v(){g===0?(b(p-1),r(11)):r(g-1),o(null)}function _(){g===11?(b(p+1),r(0)):r(g+1),o(null)}const s=t?a[t]||[]:[];return e.jsxs("div",{className:"bg-white border border-gray-200 rounded shadow-sm p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("button",{onClick:v,className:"p-2 hover:bg-gray-100 rounded",children:e.jsx(ge,{className:"w-5 h-5 text-gray-600"})}),e.jsxs("div",{className:"text-center",children:[e.jsxs("h3",{className:"text-[16px] font-bold text-gray-900",children:[p,"년 ",g+1,"월"]}),e.jsxs("p",{className:"text-[12px] text-gray-500",children:["심방 ",l,"건 / ",y,"일"]})]}),e.jsx("button",{onClick:_,className:"p-2 hover:bg-gray-100 rounded",children:e.jsx(re,{className:"w-5 h-5 text-gray-600"})})]}),e.jsx("div",{className:"grid grid-cols-7 gap-1 mb-1",children:["일","월","화","수","목","금","토"].map((c,N)=>e.jsx("div",{className:`text-center text-[11px] font-bold py-1 ${N===0?"text-red-500":N===6?"text-blue-500":"text-gray-500"}`,children:c},c))}),e.jsx("div",{className:"grid grid-cols-7 gap-1",children:f.map((c,N)=>{var Y;if(c===null)return e.jsx("div",{className:"h-16"},`e${N}`);const w=((Y=a[c])==null?void 0:Y.length)||0,D=p===h.getFullYear()&&g===h.getMonth()&&c===h.getDate(),T=t===c,$=N%7;return e.jsxs("div",{onClick:()=>o(c===t?null:c),className:`h-16 p-1 rounded cursor-pointer transition-all border ${T?"border-blue-600 bg-blue-50 shadow-sm":D?"border-blue-300 bg-blue-50":w>0?"border-gray-200 bg-gray-50 hover:bg-green-50":"border-transparent hover:bg-gray-50"}`,children:[e.jsx("div",{className:`text-[12px] font-medium ${$===0?"text-red-500":$===6?"text-blue-500":"text-gray-700"}`,children:c}),w>0&&e.jsx("div",{className:"mt-1",children:e.jsxs("div",{className:`text-[10px] font-bold text-center rounded py-0.5 ${w>=3?"bg-blue-600 text-white":w>=2?"bg-green-200 text-green-800":"bg-green-100 text-green-700"}`,children:[w,"건"]})})]},c)})}),t&&e.jsxs("div",{className:"mt-4 pt-4 border-t border-gray-200",children:[e.jsxs("h4",{className:"text-[13px] font-bold text-gray-900 mb-3",children:[g+1,"월 ",t,"일 심방 (",s.length,"건)"]}),s.length===0?e.jsx("p",{className:"text-[12px] text-gray-500 text-center py-4",children:"심방 기록 없음"}):e.jsx("div",{className:"space-y-2",children:s.map(c=>{const N=j.find(w=>w.id===c.member_id);return e.jsxs("div",{className:"p-3 bg-gray-50 rounded border border-gray-200 text-[12px]",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:"font-bold text-gray-900",children:N==null?void 0:N.name}),e.jsx("span",{className:"text-gray-500",children:N==null?void 0:N.position}),e.jsx("span",{className:"text-[10px] px-2 py-0.5 bg-blue-100 text-blue-700 rounded",children:c.visit_type}),c.urgency&&c.urgency!=="일반"&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-red-50 text-red-600 rounded",children:c.urgency})]}),c.visitors&&c.visitors.length>0&&e.jsxs("div",{className:"text-gray-600",children:["심방자: ",c.visitors.join(", ")
14]}),e.jsx("div",{className:"text-gray-600",children:c.purpose}),c.location&&e.jsxs("div",{className:"text-gray-500",children:["장소: ",c.location]})]},c.id)})})]})]})}function qe({visits:d}){const[j,h]=m.useState("month"),p=new Date,b=m.useMemo(()=>d.filter(t=>{const o=new Date(t.visit_date);if(j==="month")return o.getMonth()===p.getMonth()&&o.getFullYear()===p.getFullYear();if(j==="quarter"){const x=Math.floor(p.getMonth()/3);return Math.floor(o.getMonth()/3)===x&&o.getFullYear()===p.getFullYear()}return o.getFullYear()===p.getFullYear()}),[d,j]),g=m.useMemo(()=>{const t={};return b.forEach(o=>{(o.visitors||[]).forEach(x=>{t[x]||(t[x]={total:0,byType:{}}),t[x].total++,t[x].byType[o.visit_type]=(t[x].byType[o.visit_type]||0)+1})}),Object.entries(t).sort((o,x)=>x[1].total-o[1].total)},[b]),r=["가정심방","병원심방","전화심방","상담","기타"];return e.jsxs("div",{className:"bg-white border border-gray-200 rounded shadow-sm p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h3",{className:"text-[14px] font-bold text-gray-900",children:"심방자별 통계"}),e.jsx("div",{className:"flex gap-1",children:[["month","월간"],["quarter","분기"],["year","연간"]].map(([t,o])=>e.jsx("button",{onClick:()=>h(t),className:`px-3 py-1 rounded text-[12px] ${j===t?"bg-blue-600 text-white":"bg-gray-100 text-gray-600 hover:bg-gray-200"}`,children:o},t))})]}),g.length===0?e.jsx("p",{className:"text-[13px] text-gray-500 text-center py-8",children:"해당 기간 심방 기록이 없습니다"}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-[12px]",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-gray-50",children:[e.jsx("th",{className:"text-left p-2 font-bold text-gray-700",children:"심방자"}),r.map(t=>e.jsx("th",{className:"text-center p-2 font-bold text-gray-700",children:t},t)),e.jsx("th",{className:"text-center p-2 font-bold text-gray-900",children:"합계"})]})}),e.jsx("tbody",{children:g.map(([t,o])=>e.jsxs("tr",{className:"border-t border-gray-100 hover:bg-gray-50",children:[e.jsx("td",{className:"p-2 font-medium text-gray-900",children:t}),r.map(x=>e.jsx("td",{className:"text-center p-2 text-gray-600",children:o.byType[x]||"-"},x)),e.jsx("td",{className:"text-center p-2 font-bold text-blue-600",children:o.total})]},t))}),e.jsx("tfoot",{children:e.jsxs("tr",{className:"border-t-2 border-gray-300 bg-gray-50",children:[e.jsx("td",{className:"p-2 font-bold text-gray-900",children:"합계"}),r.map(t=>{const o=g.reduce((x,[,u])=>x+(u.byType[t]||0),0);return e.jsx("td",{className:"text-center p-2 font-bold text-gray-700",children:o||"-"},t)}),e.jsx("td",{className:"text-center p-2 font-bold text-blue-600",children:b.length})]})})]})})]})}function Ae({visits:d}){const[j,h]=m.useState("month"),p=new Date,b=m.useMemo(()=>d.filter(x=>{const u=new Date(x.visit_date);if(j==="month")return u.getMonth()===p.getMonth()&&u.getFullYear()===p.getFullYear();if(j==="quarter"){const i=Math.floor(p.getMonth()/3);return Math.floor(u.getMonth()/3)===i&&u.getFullYear()===p.getFullYear()}return u.getFullYear()===p.getFullYear()}),[d,j]),g=m.useMemo(()=>{const x={};return b.forEach(u=>{x[u.visit_type]=(x[u.visit_type]||0)+1}),Object.entries(x).sort((u,i)=>i[1]-u[1])},[b]),r=g.length>0?Math.max(...g.map(([,x])=>x)):1,t={가정심방:"bg-blue-500",병원심방:"bg-red-500",전화심방:"bg-green-500",상담:"bg-blue-500",기타:"bg-gray-500"},o=m.useMemo(()=>{const x={일반:0,긴급:0,비공개:0};return b.forEach(u=>{const i=u.urgency||"일반";x[i]=(x[i]||0)+1}),x},[b]);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"bg-white border border-gray-200 rounded shadow-sm p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h3",{className:"text-[14px] font-bold text-gray-900",children:"심방유형별 통계"}),e.jsx("div",{className:"flex gap-1",children:[["month","월간"],["quarter","분기"],["year","연간"]].map(([x,u])=>e.jsx("button",{onClick:()=>h(x),className:`px-3 py-1 rounded text-[12px] ${j===x?"bg-blue-600 text-white":"bg-gray-100 text-gray-600 hover:bg-gray-200"}`,children:u},x))})]}),g.length===0?e.jsx("p",{className:"text-[13px] text-gray-500 text-center py-8",children:"해당 기간 심방 기록이 없습니다"}):e.jsxs("div",{className:"space-y-3",children:[g.map(([x,u])=>e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("span",{className:"text-[12px] font-medium text-gray-700",children:x}),e.jsxs("span",{className:"text-[12px] font-bold text-gray-900",children:[u,"건"]})]}),e.jsx("div",{className:"w-full bg-gray-100 rounded-full h-6",children:e.jsx("div",{className:`h-6 rounded-full ${t[x]||t.기타} flex items-center justify-end pr-2 transition-all duration-500`,style:{width:`${Math.max(u/r*100,8)}%`},children:e.jsxs("span",{className:"text-[10px] text-white font-bold",children:[(u/b.length*100).toFixed(0),"%"]})})})]},x)),e.jsx("div",{className:"pt-3 border-t border-gray-200 text-center",children:e.jsxs("span",{className:"text-[13px] font-bold text-gray-900",children:["총 ",b.length,"건"]})})]})]}),e.jsxs("div",{className:"bg-white border border-gray-200 rounded shadow-sm p-4",children:[e.jsx("h3",{className:"text-[14px] font-bold text-gray-900 mb-4",children:"구분별 통계"}),e.jsx("div",{className:"grid grid-cols-3 gap-4",children:Object.entries(o).map(([x,u])=>{const i={일반:"text-blue-600 bg-blue-50",긴급:"text-red-600 bg-red-50",비공개:"text-gray-600 bg-gray-100"};return e.jsxs("div",{className:`text-center p-4 rounded-lg ${i[x]||"bg-gray-50"}`,children:[e.jsx("div",{className:"text-[24px] font-bold",children:u}
14),e.jsx("div",{className:"text-[12px] font-medium mt-1",children:x})]},x)})})]})]})}function Re({visits:d,members:j,exportToExcel:h}){const[p,b]=m.useState(new Date().getFullYear()),g=m.useMemo(()=>d.filter(i=>i.visit_date.startsWith(String(p))),[d,p]),r=m.useMemo(()=>{const i={};return g.forEach(a=>{const l=j.find(f=>f.id===a.member_id);if(!l)return;i[a.member_id]||(i[a.member_id]={name:l.name,position:l.position||"",months:Array(12).fill(0),total:0});const y=parseInt(a.visit_date.split("-")[1])-1;i[a.member_id].months[y]++,i[a.member_id].total++}),Object.values(i).sort((a,l)=>l.total-a.total)},[g,j]),t=m.useMemo(()=>{const i=Array(12).fill(0);return r.forEach(a=>a.months.forEach((l,y)=>{i[y]+=l})),i},[r]),o=t.reduce((i,a)=>i+a,0),x=m.useMemo(()=>{const i=new Set(d.map(a=>parseInt(a.visit_date.split("-")[0])));return i.add(new Date().getFullYear()),Array.from(i).sort((a,l)=>l-a)},[d]);function u(){if(r.length===0){S.error("내보낼 데이터가 없습니다");return}const a=["교인명","직분",...["1월","2월","3월","4월","5월","6월","7월","8월","9월","10월","11월","12월"],"합계"],l=r.map(s=>[s.name,s.position,...s.months.map(c=>c||""),s.total]);l.push(["합계","",...t.map(s=>s||""),o]);const y=[a.join(","),...l.map(s=>s.map(c=>`"${c}"`).join(","))].join(`
15`),f=new Blob(["\uFEFF"+y],{type:"text/csv;charset=utf-8;"}),v=URL.createObjectURL(f),_=document.createElement("a");_.href=v,_.download=`개인별연간심방_${p}.csv`,_.click(),URL.revokeObjectURL(v),S.success("엑셀 파일이 다운로드되었습니다")}return e.jsxs("div",{className:"bg-white border border-gray-200 rounded shadow-sm p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h3",{className:"text-[14px] font-bold text-gray-900",children:"개인별 연간 심방통계"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("select",{value:p,onChange:i=>b(Number(i.target.value)),className:"compact-input w-auto",children:x.map(i=>e.jsxs("option",{value:i,children:[i,"년"]},i))}),e.jsxs("button",{onClick:u,className:"flex items-center gap-1.5 px-3 py-1.5 border border-gray-300 text-gray-700 rounded hover:bg-gray-50 text-[12px] font-medium",children:[e.jsx(B,{className:"w-3.5 h-3.5"}),"엑셀"]})]})]}),r.length===0?e.jsxs("p",{className:"text-[13px] text-gray-500 text-center py-8",children:[p,"년 심방 기록이 없습니다"]}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-[11px]",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-gray-50",children:[e.jsx("th",{className:"text-left p-2 font-bold text-gray-700 sticky left-0 bg-gray-50",children:"교인명"}),e.jsx("th",{className:"text-left p-2 font-bold text-gray-700",children:"직분"}),Array.from({length:12},(i,a)=>e.jsxs("th",{className:"text-center p-2 font-bold text-gray-700 min-w-[36px]",children:[a+1,"월"]},a)),e.jsx("th",{className:"text-center p-2 font-bold text-gray-900 bg-green-50",children:"합계"})]})}),e.jsx("tbody",{children:r.map(i=>e.jsxs("tr",{className:"border-t border-gray-100 hover:bg-gray-50",children:[e.jsx("td",{className:"p-2 font-medium text-gray-900 sticky left-0 bg-white",children:i.name}),e.jsx("td",{className:"p-2 text-gray-500",children:i.position}),i.months.map((a,l)=>e.jsx("td",{className:`text-center p-2 ${a>0?"text-blue-600 font-bold":"text-gray-300"}`,children:a||"-"},l)),e.jsx("td",{className:"text-center p-2 font-bold text-blue-600 bg-green-50",children:i.total})]},i.name))}),e.jsx("tfoot",{children:e.jsxs("tr",{className:"border-t-2 border-gray-300 bg-gray-50",children:[e.jsx("td",{className:"p-2 font-bold text-gray-900 sticky left-0 bg-gray-50",children:"합계"}),e.jsx("td",{className:"p-2"}),t.map((i,a)=>e.jsx("td",{className:`text-center p-2 font-bold ${i>0?"text-gray-900":"text-gray-300"}`,children:i||"-"},a)),e.jsx("td",{className:"text-center p-2 font-bold text-blue-600 bg-green-50",children:o})]})})]})}),r.length>0&&e.jsxs("div",{className:"mt-3 text-[11px] text-gray-500 text-right",children:["총 ",r.length,"명, ",o,"건의 심방"]})]})}export{Ze as VisitManagementPage};

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.