1import{j as e}from"./vendor-data-Z5doMMu-.js";import{b as B,r as h}from"./vendor-react-zNM0AU50.js";import{m as J}from"./index-D1K3lVhu.js";import{f as U}from"./faithJourneyService-B56_rhGw.js";import{v as Y}from"./visitService-DcwGr2oo.js";import{p as W}from"./prayerService-DgtIrt49.js";import{a as X}from"./attendanceService-CvkHMi2v.js";import{s as z,U as P,$ as G,aw as R,v as $,g as H,a as K,ar as Q,ax as Z}from"./vendor-ui-CW5bJ11U.js";import"./vendor-firebase-Da9KY1q_.js";import"./vendor-charts-08G1rM8P.js";const T={calculateMetrics(t,s,a,i,r){const c=new Date;c.setFullYear(c.getFullYear()-1);const d=this.calculateAttendanceScore(t,r),f=this.calculateParticipationScore(t),j=this.calculateJourneyScore(s),A=this.calculateRelationshipScore(a,c),u=this.calculatePrayerScore(i),N=Math.round(d+f+j+A+u),D=this.determineLevel(N),m=a.filter(l=>new Date(l.visit_date)>=c),x=m.length>0?m.sort((l,n)=>n.visit_date.localeCompare(l.visit_date))[0]:null,p=s.length>0?s.sort((l,n)=>n.event_date.localeCompare(l.event_date))[0]:null,w=i.filter(l=>l.status==="ìëµë¨");return{member_id:t.id,attendance_rate:(r==null?void 0:r.attendance_rate)||t.attendance_rate||0,consecutive_attendance:(r==null?void 0:r.consecutive_weeks)||this.calculateConsecutiveAttendance(t),small_group_participation:!!t.district,ministry_participation:!!t.ministry,training_completion_count:s.filter(l=>l.event_type==="íë ¨ìë£").length,journey_events_count:s.length,last_journey_event_date:p==null?void 0:p.event_date,visit_count:m.length,last_visit_date:x==null?void 0:x.visit_date,prayer_request_count:i.length,answered_prayer_count:w.length,overall_score:N,spiritual_level:D,calculated_at:new Date().toISOString()}},calculateAttendanceScore(t,s){const a=(s==null?void 0:s.attendance_rate)||t.attendance_rate||0;return a>=90?30:a>=80?25:a>=70?20:a>=60?15:a>=50?10:5},calculateParticipationScore(t){var i;let s=0;t.district&&(s+=8),t.ministry&&(s+=10);const a=parseInt(((i=t.spiritual_maturity)==null?void 0:i[0])||"1");return s+=a*1.4,Math.round(s)},calculateJourneyScore(t){if(t.length===0)return 0;let s=0;s+=Math.min(t.length*2,10);const a=new Date;a.setMonth(a.getMonth()-6),t.filter(c=>new Date(c.event_date)>=a).length>0&&(s+=5);const r=t.filter(c=>c.achievement_level);if(r.length>0){const c=r.reduce((d,f)=>d+(f.achievement_level||0),0)/r.length;s+=c}return Math.round(Math.min(s,20))},calculateRelationshipScore(t,s){const a=t.filter(d=>new Date(d.visit_date)>=s);if(a.length===0)return 0;let i=Math.min(a.length*2.5,10);const r=new Date;return r.setMonth(r.getMonth()-3),a.filter(d=>new Date(d.visit_date)>=r).length>0&&(i+=5),Math.round(Math.min(i,15))},calculatePrayerScore(t){if(t.length===0)return 0;let s=0;s+=Math.min(t.length,5);const a=t.filter(i=>i.status==="ìëµë¨");return s+=Math.min(a.length,5),Math.round(Math.min(s,10))},calculateConsecutiveAttendance(t){const s=t.attendance_rate||0;return s>=95?12:s>=90?8:s>=80?4:0},determineLevel(t){return t>=85?5:t>=70?4:t>=55?3:t>=40?2:1},generateRecommendations(t,s){const a=[];return t.attendance_rate<80&&a.push("ð
ì£¼ì¼ ìë°° ì¶ìë¥ ì ëì¬ë³´ì¸ì"),t.small_group_participation||a.push("ð¥ 구ì 모ìì ì°¸ì¬í´ë³´ì¸ì"),t.ministry_participation||a.push("ð¯ êµí ì¬ìì ì°¸ì¬í´ë³´ì¸ì"),t.journey_events_count===0?a.push("ð ì ì íë ¨ ê³¼ì ì ììí´ë³´ì¸ì"):(!t.last_journey_event_date||this.isOlderThan(t.last_journey_event_date,12))&&a.push("ð ìë¡ì´ ì ì íë ¨ì ëì í´ë³´ì¸ì"),(!t.last_visit_date||this.isOlderThan(t.last_visit_date,6))&&a.push("ð 목íìì ìë´ ìê°ì ê°ì ¸ë³´ì¸ì"),t.prayer_request_count===0&&a.push("ð 기ë ì 목ì ëëì´ë³´ì¸ì"),t.spiritual_level<=2&&a.push("⨠ì ìíë ¨ ê³¼ì ì ì¶ì²ë립ëë¤"),a}
1,isOlderThan(t,s){const a=new Date(t),i=new Date;return i.setMonth(i.getMonth()-s),a<i}};function ue(){B();const[t,s]=h.useState(!0),[a,i]=h.useState([]),[r,c]=h.useState(new Map),[d,f]=h.useState(""),[j,A]=h.useState("all"),[u,N]=h.useState("");h.useEffect(()=>{D()},[]);async function D(){try{s(!0);const[l,n,b,M]=await Promise.all([J.getMembers(),U.getAllEvents(),Y.getAllVisits(),W.getAllPrayers()]),v=l.filter(o=>o.member_classification==="ìëì¶ìì±ë");i(v);const y=new Map,k=v.map(o=>X.calculateStats(o.id)),E=await Promise.all(k),L=new Map;E.forEach(o=>{L.set(o.member_id,o)}),v.forEach(o=>{const F=n.filter(_=>_.member_id===o.id),I=b.filter(_=>_.member_id===o.id),V=M.filter(_=>_.member_id===o.id),O=L.get(o.id),q=T.calculateMetrics(o,F,I,V,O);y.set(o.id,q)}),c(y)}catch(l){console.error("ë°ì´í° ë¡ë© ì¤í¨:",l)}finally{s(!1)}}const m=a.filter(l=>{if(d&&!l.name.toLowerCase().includes(d.toLowerCase()))return!1;if(j!=="all"){const n=r.get(l.id);if(!n||n.spiritual_level!==parseInt(j))return!1}return!0}).sort((l,n)=>{var v,y;const b=((v=r.get(l.id))==null?void 0:v.overall_score)||0;return(((y=r.get(n.id))==null?void 0:y.overall_score)||0)-b}),x={total:a.length,avgScore:a.length>0?Math.round(Array.from(r.values()).reduce((l,n)=>l+n.overall_score,0)/a.length):0,levelDistribution:{level1:Array.from(r.values()).filter(l=>l.spiritual_level===1).length,level2:Array.from(r.values()).filter(l=>l.spiritual_level===2).length,level3:Array.from(r.values()).filter(l=>l.spiritual_level===3).length,level4:Array.from(r.values()).filter(l=>l.spiritual_level===4).length,level5:Array.from(r.values()).filter(l=>l.spiritual_level===5).length}};if(t)return e.jsx("div",{className:"flex items-center justify-center h-96",children:e.jsx("div",{className:"text-gray-500 text-[13px]",children:"ìì ì§ì를 ê³ì°íë ì¤..."})});const p=u?r.get(u):null,w=u?a.find(l=>l.id===u):null;return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-[18px] font-bold text-gray-900 flex items-center gap-2",children:[e.jsx(z,{className:"w-5 h-5 text-blue-600"}),"ìì ì§ì ë¶ì"]}),e.jsx("p",{className:"text-[12px] text-gray-500 mt-1",children:"êµì¸ë¤ì ìì ì±ìë를 ì¢
í© ë¶ìí©ëë¤"})]}),e.jsxs("div",{className:"grid grid-cols-4 gap-3",children:[e.jsx(S,{label:"ì ì²´ êµì¸",value:x.total,color:"blue",icon:e.jsx(P,{className:"w-3 h-3"})}),e.jsx(S,{label:"íê· ì ì",value:x.avgScore,color:"green",suffix:"ì ",icon:e.jsx(G,{className:"w-3 h-3"})}),e.jsx(S,{label:"5ë¨ê³",value:x.levelDistribution.level5,color:"purple",icon:e.jsx(R,{className:"w-3 h-3"})}),e.jsx(S,{label:"4ë¨ê³",value:x.levelDistribution.level4,color:"orange",icon:e.jsx($,{className:"w-3 h-3"})})]}),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-3",children:"ìì ì±ìë ë¶í¬"}),e.jsx("div",{className:"space-y-2",children:[5,4,3,2,1].map(l=>{const n=x.levelDistribution[`level${l}`],b=x.total>0?(n/x.total*100).toFixed(1):"0",M=["ìì ì","ë°°ì°ë ì ì","ìì ë ì ì","ì±ì¥íë ì ì","ì±ìí ì ì"];return e.jsx(ee,{level:l,label:M[l-1],count:n,percentage:parseFloat(b)},l)})})]}),e.jsxs("div",{className:"bg-white border border-gray-200 rounded shadow-sm p-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.jsxs("select",{value:j,onChange:l=>A(l.target.value),className:"compact-input",children:[e.jsx("option",{value:"all",children:"ì ì²´"}),e.jsx("option",{value:"5",children:"5ë¨ê³ (ì±ìí ì ì)"}),e.jsx("option",{value:"4",children:"4ë¨ê³ (ì±ì¥íë ì ì)"}),e.jsx("option",{value:"3",children:"3ë¨ê³ (ìì ë ì ì)"}),e.jsx("option",{value:"2",children:"2ë¨ê³ (ë°°ì°ë ì ì)"}),e.jsx("option",{value:"1",children:"1ë¨ê³ (ìì ì)"})]})]}),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(H,{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:d,onChange:l=>f(l.target.value),className:"compact-input pl-8"})]})]})]}),e.jsxs("div",{className:"text-[11px] text-gray-500 mt-2",children:["ì´ ",m.length,"ëª
"]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsxs("div",{className:"col-span-1 bg-white border border-gray-200 rounded shadow-sm p-3 max-h-[600px] overflow-y-auto",children:[e.jsx("h3",{className:"text-[13px] font-bold text-gray-900 mb-3",children:"êµì¸ 목ë¡"}),e.jsx("div",{className:"space-y-2",children:m.map(l=>{const n=r.get(l.id);return n?e.jsx("button",{onClick:()=>N(l.id),className:`w-full text-left p-2 rounded transition-colors ${u===l.id?"bg-blue-50 border-2 border-blue-600":"bg-gray-50 hover:bg-gray-100 border-2 border-transparent"}`,children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-[13px] font-bold text-gray-900",children:l.name}),e.jsxs("div",{className:"text-[11px] text-gray-500",children:[l.position," · ",l.district||"미배ì "]})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("div",{className:"text-[16px] font-bold text-blue-600",children:n.overall_score}),e.jsxs("div",{className:"text-[10px] text-gray-500",children:[n.spiritual_level,"ë¨ê³"]})]})]})},l.id):null})})]}),e.jsx("div",{className:"col-span-2",children:p&&w?e.jsx(te,{member:w,metrics:p}):e.jsxs("div",{className:"bg-white border border-gray-200 rounded shadow-sm p-12 text-center",children:[e.jsx(P,{className:"w-12 h-12 text-gray-300 mx-auto mb-3"}),e.jsx("p",{className:"text-[13px] text-gray-500",children:"êµì¸ì ì ííë©´ ìì¸ ë¶ìì íì¸í ì ììµëë¤"})]})})]})]})}function S({label:t,value:s,color:a,icon:i,suffix:r}){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:[s,r,i]}),e.jsx("div",{className:"text-[11px] text-gray-500",children:t})]})}function ee({level:t,label:s,count:a,percentage:i}){const r=["bg-gray-200","bg-blue-200","bg-green-200","bg-yellow-200","bg-orange-200","bg-blue-300"];return e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("span",{className:"text-[12px] text-gray-600 w-24",children:[t,"ë¨ê³"]}),e.jsx("div",{className:"flex-1 bg-gray-100 rounded-full h-6 overflow-hidden",children:e.jsxs("div",{className:`h-full ${r[t]} flex items-center justify-between px-3 transition-all`,style:{width:`${Math.max(i,3)}%`},children:[e.jsx("span",{className:"text-[11px] font-medium text-gray-700",children:s}),a>0&&e.jsxs("span",{className:"text-[10px] font-bold text-gray-700",children:[a,"ëª
"]})]})}),e.jsxs("span",{className:"text-[11px] text-gray-500 w-12 text-right",children:[i,"%"]})]})}function te({member:t,metrics:s}){const a=T.generateRecommendations(s,t),i=["ìì ì","ë°°ì°ë ì ì","ìì ë ì ì","ì±ì¥íë ì ì","ì±ìí ì ì"];return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"bg-blue-600 rounded-lg shadow-sm p-6 text-white",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-[20px] font-bold mb-1",children:t.name}),e.jsxs("p",{className:"text-[13px] opacity-90",children:[t.position," · ",t.district||"미배ì "]})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("div",{className:"text-[48px] font-bold leading-none",children:s.overall_score}),e.jsx("div",{className:"text-[13px] opacity-90",children:"/ 100ì "})]})]}),e.jsx("div",{className:"mt-4 pt-4 border-t border-white/20",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-[13px]",children:"ìì ë 벨"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(R,{className:"w-4 h-4"}),e.jsxs("span",{className:"text-[16px] font-bold",children:[s.spiritual_level,"ë¨ê³ - ",i[s.spiritual_level-1]]})]})]})})]}),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-3",children:"ì¸ë¶ ì§í"}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(g,{label:"ì¶ìë¥ ",value:s.attendance_rate,max:100,suffix:"%",color:"blue"}),e.jsx(g,{label:"ì°ì ì¶ì",value:s.consecutive_attendance,max:52,suffix:"주",color:"green"}),e.jsx(g,{label:"ì ì ì¬ì ",value:s.journey_events_count,max:10,suffix:"ê±´",color:"blue"}),e.jsx(g,{label:"ì¬ë°© (1ë
)",value:s.visit_count,max:12,suffix:"í",color:"orange"}),e.jsx(g,{label:"기ë ì 목",value:s.prayer_request_count,max:10,suffix:"ê±´",color:"blue"}
1),e.jsx(g,{label:"ìëµë 기ë",value:s.answered_prayer_count,max:10,suffix:"ê±´",color:"yellow"})]})]}),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-3",children:"ì°¸ì¬ íí©"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{label:"구ì 모ì",isActive:s.small_group_participation}),e.jsx(C,{label:"ì¬ì ì°¸ì¬",isActive:s.ministry_participation,detail:t.ministry}),e.jsx(C,{label:"íë ¨ ìë£",isActive:s.training_completion_count>0,detail:`${s.training_completion_count}í`})]})]}),a.length>0&&e.jsxs("div",{className:"bg-blue-50 border border-blue-200 rounded shadow-sm p-4",children:[e.jsxs("h3",{className:"text-[14px] font-bold text-blue-900 mb-3 flex items-center gap-2",children:[e.jsx($,{className:"w-4 h-4"}),"ì±ì¥ì ìí ì ì"]}),e.jsx("ul",{className:"space-y-2",children:a.map((r,c)=>e.jsxs("li",{className:"text-[12px] text-blue-800 flex items-start gap-2",children:[e.jsx(K,{className:"w-3 h-3 mt-0.5 flex-shrink-0"}),e.jsx("span",{children:r})]},c))})]})]})}function g({label:t,value:s,max:a,suffix:i,color:r}){const c=Math.min(s/a*100,100);return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("span",{className:"text-[12px] text-gray-700",children:t}),e.jsxs("span",{className:"text-[12px] font-bold text-gray-900",children:[s,i]})]}),e.jsx("div",{className:"w-full bg-gray-100 rounded-full h-2 overflow-hidden",children:e.jsx("div",{className:`h-full bg-${r}-400 transition-all`,style:{width:`${c}%`}})})]})}function C({label:t,isActive:s,detail:a}){return e.jsxs("div",{className:"flex items-center justify-between p-2 bg-gray-50 rounded",children:[e.jsx("span",{className:"text-[12px] text-gray-700",children:t}),e.jsxs("div",{className:"flex items-center gap-2",children:[a&&e.jsx("span",{className:"text-[11px] text-gray-500",children:a}),s?e.jsx(Q,{className:"w-4 h-4 text-green-600"}):e.jsx(Z,{className:"w-4 h-4 text-gray-400"})]})]})}export{ue as SpiritualMetricsPage};
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.