1import{j as e}from"./vendor-pdf-CAs81Xpx.js";import{i as H,a as l}from"./vendor-react-WakpR0wD.js";import{M as J}from"./MainLayout-Svkkv2is.js";import{j as q,i as p,c4 as B,aJ as K,c7 as Q,c8 as W}from"./index-BQksJ-U7.js";import{g as z,d as A,b as D,c as I}from"./vendor-firestore-C84qCbTf.js";import{C as X}from"./chevron-left-DhGEpv32.js";import{L as M}from"./layers-BqW9rdU4.js";import{U as Z}from"./users-FNKwIhe4.js";import{C as ee}from"./circle-check-6jn1nmmv.js";import{S as te}from"./shield-alert-CNxBFgC1.js";import{C as ae}from"./circle-alert-PQlQFZ8S.js";import{m as R}from"./vendor-motion-CONVzr3A.js";import"./vendor-firebase-auth-DWo6Js8N.js";import"./vendor-firebase-core-DfI3m37w.js";import"./Navbar-BYlHuWeG.js";import"./vendor-charts-Dhh0UBmn.js";import"./ProfileAvatar-C57cy0cU.js";import"./profile-DDlO39M8.js";import"./index-CTJayJtD.js";import"./SkeletonLoader-ODolvGj-.js";import"./vendor-swal-BgUaMQbp.js";import"./AIAssistantWidget-DjAJzlhp.js";const Se=()=>{const P=H(),[U,f]=l.useState(!0),[k,T]=l.useState([]),[j,Y]=l.useState([]),[N,O]=l.useState(""),[h,_]=l.useState(""),[b,G]=l.useState(""),[v,F]=l.useState(""),w=l.useCallback(async()=>{var t;f(!0);try{const s=q.currentUser;if(!s)return;const i=(t=(await z(A(p,"users",s.uid))).data())==null?void 0:t.schoolId;if(!i)return;const[m,y]=await Promise.all([z(A(p,"school-settings",i)),B(p,i)]);if(m.exists()){const a=m.data();O((a==null?void 0:a.schoolName)||""),F((a==null?void 0:a.affiliation)||(a==null?void 0:a.educationArea)||(a==null?void 0:a.areaOffice)||"")}_(y.academicYear||""),G(y.currentTerm||"");const d=(await D(I(p,"school-settings",i,"students"))).docs.map(a=>({id:a.id,...a.data()})).filter(a=>K(a)==="à¸à¸³à¸¥à¸±à¸à¸¨à¸¶à¸à¸©à¸²à¸à¸¢à¸¹à¹");T(d);const c=[];await Promise.all(d.map(async a=>{(await D(I(p,"school-settings",i,"students",a.id,"home-visits"))).docs.forEach(g=>c.push({id:g.id,...g.data(),studentId:a.id}))})),Y(c)}catch(s){console.error("Error fetching data:",s)}finally{f(!1)}},[]);l.useEffect(()=>{w()},[w]);const n=l.useMemo(()=>{const t=new Map;return j.forEach(s=>{(!t.has(s.studentId)||s.visitDate>t.get(s.studentId).visitDate)&&t.set(s.studentId,s)}),Q.map(s=>{const u=k.filter(a=>{var x;return((x=W(a.classLevel))==null?void 0:x.key)===s.key}),i=new Set(u.filter(a=>t.has(a.id)).map(a=>a.id)),m=u.filter(a=>t.has(a.id)).map(a=>t.get(a.id)),y=m.filter(a=>{var x,g,L,E,V;return(((x=a.healthRisk)==null?void 0:x.length)||0)>0||(((g=a.drugRisk)==null?void 0:g.length)||0)>0||(((L=a.violenceRisk)==null?void 0:L.length)||0)>0||(((E=a.sexualRisk)==null?void 0:E.length)||0)>0||(((V=a.gameRisk)==null?void 0:V.length)||0)>0}).length,$=m.filter(a=>a.visitSummary==="à¸à¹à¸§à¸¢à¹à¸«à¸¥à¸·à¸à¸à¹à¸§à¸").length,d=u.length,c=i.size;return{key:s.key,label:s.label,total:d,visited:c,notVisited:d-c,riskCount:y,urgentCount:$,percent:d>0?Math.round(c/d*100):0}}).filter(s=>s.total>0)},[k,j]),r=l.useMemo(()=>({total:n.reduce((t,s)=>t+s.total,0),visited:n.reduce((t,s)=>t+s.visited,0),risk:n.reduce((t,s)=>t+s.riskCount,0),urgent:n.reduce((t,s)=>t+s.urgentCount,0)}),[n]),S=t=>t>=80?"bg-emerald-500":t>=50?"bg-amber-400":"bg-rose-500",C=t=>t>=80?"text-emerald-600 dark:text-emerald-400":t>
1=50?"text-amber-600 dark:text-amber-400":"text-rose-600 dark:text-rose-400";if(U)return e.jsx("div",{className:"min-h-screen bg-gray-50 dark:bg-[#1a1b1e] p-4 sm:p-6",children:e.jsxs("div",{className:"max-w-6xl w-full mx-auto space-y-6",children:[e.jsx("div",{className:"h-10 w-64 rounded-lg bg-gray-200 dark:bg-gray-700 animate-pulse"}),e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[...Array(4)].map((t,s)=>e.jsx("div",{className:"h-24 rounded-2xl bg-gray-200 dark:bg-gray-700 animate-pulse"},`skeleton-stat-${s}`))}),e.jsx("div",{className:"h-72 w-full rounded-2xl bg-gray-200 dark:bg-gray-700 animate-pulse"})]})});const o=r.total>0?Math.round(r.visited/r.total*100):0;return e.jsx(J,{children:e.jsxs("div",{className:"min-h-screen bg-gray-50 dark:bg-[#1a1b1e]",children:[e.jsx("div",{className:"bg-white dark:bg-[#212326] border-b border-gray-100 dark:border-gray-800",children:e.jsx("div",{className:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-5",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("button",{onClick:()=>P("/student-support/home-visit/summary"),className:"flex-shrink-0 p-2.5 bg-gray-100 dark:bg-gray-800 hover:bg-gray-200 dark:hover:bg-gray-700 text-gray-600 dark:text-gray-400 rounded-xl transition-all active:scale-95",children:e.jsx(X,{size:20})}),e.jsx("div",{className:"flex-shrink-0 w-10 h-10 bg-gradient-to-br from-orange-500 to-amber-600 rounded-xl flex items-center justify-center shadow-md shadow-orange-500/25",children:e.jsx(M,{size:18,className:"text-white"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h1",{className:"text-xl font-black text-gray-900 dark:text-white",children:"สรุà¸à¹à¸à¸à¸à¹à¸§à¸à¸à¸±à¹à¸"}),e.jsxs("p",{className:"text-sm text-gray-400 dark:text-gray-500 font-medium",children:[n.length," à¸à¹à¸§à¸à¸à¸±à¹à¸",h&&e.jsxs(e.Fragment,{children:[" · à¸à¸µ ",h,b?` à¹à¸à¸à¸¡ ${b}`:""]})]})]})]})})}),e.jsxs("div",{className:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-6 space-y-6",children:[e.jsx("div",{className:"bg-white dark:bg-[#25262a] rounded-2xl border border-gray-100 dark:border-gray-800 shadow-sm p-5",children:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[N&&e.jsx("span",{className:"inline-flex items-center px-3 py-1.5 bg-gray-50 dark:bg-gray-800 text-gray-700 dark:text-gray-300 rounded-xl text-sm font-semibold border border-gray-100 dark:border-gray-700",children:N}),h&&e.jsxs("span",{className:"inline-flex items-center px-3 py-1.5 bg-orange-50 dark:bg-orange-900/20 text-orange-700 dark:text-orange-300 rounded-xl text-sm font-semibold border border-orange-100 dark:border-orange-800/50",children:["à¸à¸µ ",h,b?` à¹à¸à¸à¸¡ ${b}`:""]}),v&&e.jsx("span",{className:"inline-flex items-center px-3 py-1.5 bg-gray-50 dark:bg-gray-800 text-gray-500 dark:text-gray-400 rounded-xl text-xs font-medium border border-gray-100 dark:border-gray-700",children:v})]})}),e.jsx("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4",children:[{label:"à¸à¸±à¸à¹à¸£à¸µà¸¢à¸à¸à¸±à¹à¸à¸«à¸¡à¸",value:r.total,icon:e.jsx(Z,{size:20}),accent:"from-blue-500 to-indigo-600",text:"text-blue-600 dark:text-blue-400",sub:`${n.length} à¸à¹à¸§à¸à¸à¸±à¹à¸`},{label:"à¹à¸¢à¸µà¹à¸¢à¸¡à¹à¸¥à¹à¸§à¸à¸±à¹à¸à¸«à¸¡à¸",value:r.visited,icon:e.jsx(ee,{size:20}),accent:"from-emerald-500 to-teal-600",text:"text-emerald-600 dark:text-emerald-400",sub:`${o}%`},{label:"à¸à¸à¸à¸¥à¸¸à¹à¸¡à¹à¸ªà¸µà¹à¸¢à¸",value:r.risk,icon:e.jsx(te,{size:20}),accent:"from-amber-500 to-orange-600",text:"text-amber-600 dark:text-amber-400",sub:"รวมà¸à¸¸à¸à¸à¹à¸§à¸à¸à¸±à¹à¸"},{label:"à¸à¹à¸à¸à¸à¸²à¸£à¸à¸§à¸²à¸¡à¸à¹à¸§à¸¢à¹à¸«à¸¥à¸·à¸",value:r.urgent,icon:e.jsx(ae,{size:20}
1),accent:"from-rose-500 to-pink-600",text:"text-rose-600 dark:text-rose-400",sub:"à¸à¸¥à¸¸à¹à¸¡à¸§à¸´à¸à¸¤à¸"}].map((t,s)=>e.jsxs(R.div,{initial:{opacity:0,y:16},animate:{opacity:1,y:0},transition:{delay:s*.07},className:"bg-white dark:bg-[#25262a] rounded-2xl border border-gray-100 dark:border-gray-800 shadow-sm overflow-hidden",children:[e.jsx("div",{className:`h-1 bg-gradient-to-r ${t.accent}`}),e.jsxs("div",{className:"p-5",children:[e.jsx("div",{className:`inline-flex p-2.5 rounded-xl mb-3 bg-gray-50 dark:bg-gray-800/80 ${t.text}`,children:t.icon}),e.jsx("p",{className:"text-xs font-bold text-gray-400 mb-1",children:t.label}),e.jsxs("div",{className:"flex items-baseline gap-1.5",children:[e.jsx("span",{className:"text-3xl font-black text-gray-900 dark:text-white",children:t.value}),e.jsx("span",{className:"text-sm text-gray-400 font-bold",children:"à¸à¸"})]}),e.jsx("p",{className:`text-[11px] font-bold mt-2 ${t.text}`,children:t.sub})]})]},s))}),e.jsxs("div",{className:"bg-white dark:bg-[#25262a] rounded-2xl border border-gray-100 dark:border-gray-800 shadow-sm overflow-hidden",children:[e.jsx("div",{className:"h-1 bg-gradient-to-r from-orange-500 to-amber-600"}),e.jsxs("div",{className:"p-5 border-b border-gray-50 dark:border-gray-800 flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"font-black text-base text-gray-900 dark:text-white flex items-center gap-2",children:[e.jsx(M,{size:18,className:"text-orange-600"}),"à¸à¸²à¸£à¸²à¸à¸ªà¸£à¸¸à¸à¹à¸à¸à¸à¹à¸§à¸à¸à¸±à¹à¸"]}),e.jsx("p",{className:"text-xs font-medium text-gray-400 mt-0.5",children:"รวมà¸à¸±à¸à¹à¸£à¸µà¸¢à¸à¸à¸¸à¸à¸«à¹à¸à¸à¹à¸à¸à¹à¸§à¸à¸à¸±à¹à¸à¹à¸à¸µà¸¢à¸§à¸à¸±à¸"})]}),e.jsxs("span",{className:"text-xs font-black text-gray-400 bg-gray-50 dark:bg-gray-800 px-3 py-1.5 rounded-xl border border-gray-100 dark:border-gray-700",children:[n.length," à¸à¹à¸§à¸à¸à¸±à¹à¸"]})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{className:"bg-gray-50 dark:bg-gray-800/50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-5 py-3 text-left text-[10px] font-black text-gray-400 uppercase tracking-widest",children:"à¸à¹à¸§à¸à¸à¸±à¹à¸"}),e.jsx("th",{className:"px-5 py-3 text-center text-[10px] font-black text-gray-400 uppercase tracking-widest",children:"à¸à¸±à¸à¹à¸£à¸µà¸¢à¸"}),e.jsx("th",{className:"px-5 py-3 text-center text-[10px] font-black text-gray-400 uppercase tracking-widest",children:"à¹à¸¢à¸µà¹à¸¢à¸¡à¹à¸¥à¹à¸§"}),e.jsx("th",{className:"px-5 py-3 text-center text-[10px] font-black text-gray-400 uppercase tracking-widest",children:"ยัà¸à¹à¸¡à¹à¹à¸¢à¸µà¹à¸¢à¸¡"}),e.jsx("th",{className:"px-5 py-3 text-left text-[10px] font-black text-gray-400 uppercase tracking-widest w-44",children:"à¸à¸§à¸²à¸¡à¸à¸·à¸à¸«à¸à¹à¸²"}),e.jsx("th",{className:"px-5 py-3 text-center text-[10px] font-black text-gray-400 uppercase tracking-widest",children:"à¸à¸¥à¸¸à¹à¸¡à¹à¸ªà¸µà¹à¸¢à¸"}),e.jsx("th",{className:"px-5 py-3 text-center text-[10px] font-black text-gray-400 uppercase tracking-widest",children:"à¸à¹à¸§à¸¢à¹à¸«à¸¥à¸·à¸à¸à¹à¸§à¸"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-50 dark:divide-gray-800",children:n.map((t,s)=>e.jsxs(R.tr,{initial:{opacity:0}
1,animate:{opacity:1},transition:{delay:s*.05},children:[e.jsx("td",{className:"px-5 py-4",children:e.jsx("p",{className:"font-bold text-gray-900 dark:text-white text-sm",children:t.label})}),e.jsxs("td",{className:"px-5 py-4 text-center",children:[e.jsx("span",{className:"font-black text-gray-900 dark:text-white",children:t.total}),e.jsx("span",{className:"text-gray-400 text-xs ml-1",children:"à¸à¸"})]}),e.jsxs("td",{className:"px-5 py-4 text-center",children:[e.jsx("span",{className:"font-black text-emerald-600 dark:text-emerald-400",children:t.visited}),e.jsx("span",{className:"text-gray-400 text-xs ml-1",children:"à¸à¸"})]}),e.jsxs("td",{className:"px-5 py-4 text-center",children:[e.jsx("span",{className:`font-black ${t.notVisited>0?"text-rose-500 dark:text-rose-400":"text-gray-400"}`,children:t.notVisited}),e.jsx("span",{className:"text-gray-400 text-xs ml-1",children:"à¸à¸"})]}),e.jsx("td",{className:"px-5 py-4",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex-1 h-2 bg-gray-100 dark:bg-gray-700 rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full transition-all ${S(t.percent)}`,style:{width:`${t.percent}%`}})}),e.jsxs("span",{className:`text-xs font-black w-10 text-right ${C(t.percent)}`,children:[t.percent,"%"]})]})}),e.jsx("td",{className:"px-5 py-4 text-center",children:t.riskCount>0?e.jsx("span",{className:"inline-flex items-center justify-center w-7 h-7 bg-amber-50 dark:bg-amber-900/20 text-amber-600 dark:text-amber-400 rounded-lg text-xs font-black",children:t.riskCount}):e.jsx("span",{className:"text-gray-300 dark:text-gray-600 font-black",children:"â"})}),e.jsx("td",{className:"px-5 py-4 text-center",children:t.urgentCount>0?e.jsx("span",{className:"inline-flex items-center justify-center w-7 h-7 bg-rose-50 dark:bg-rose-900/20 text-rose-600 dar
1k:text-rose-400 rounded-lg text-xs font-black",children:t.urgentCount}):e.jsx("span",{className:"text-gray-300 dark:text-gray-600 font-black",children:"â"})})]},t.key))}),e.jsx("tfoot",{children:e.jsxs("tr",{className:"bg-orange-50 dark:bg-orange-900/10 border-t-2 border-orange-200 dark:border-orange-800/50",children:[e.jsx("td",{className:"px-5 py-4",children:e.jsx("span",{className:"font-black text-sm text-orange-700 dark:text-orange-300",children:"รวมà¸à¸±à¹à¸à¸«à¸¡à¸"})}),e.jsxs("td",{className:"px-5 py-4 text-center",children:[e.jsx("span",{className:"font-black text-gray-900 dark:text-white",children:r.total}),e.jsx("span",{className:"text-gray-400 text-xs ml-1",children:"à¸à¸"})]}),e.jsxs("td",{className:"px-5 py-4 text-center",children:[e.jsx("span",{className:"font-black text-emerald-600 dark:text-emerald-400",children:r.visited}),e.jsx("span",{className:"text-gray-400 text-xs ml-1",children:"à¸à¸"})]}),e.jsxs("td",{className:"px-5 py-4 text-center",children:[e.jsx("span",{className:`font-black ${r.total-r.visited>0?"text-rose-500":"text-gray-400"}`,children:r.total-r.visited}),e.jsx("span",{className:"text-gray-400 text-xs ml-1",children:"à¸à¸"})]}),e.jsx("td",{className:"px-5 py-4",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex-1 h-2 bg-orange-100 dark:bg-orange-900/30 rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full ${S(o)}`,style:{width:`${o}%`}})}),e.jsxs("span",{className:`text-xs font-black w-10 text-right ${C(o)}`,children:[o,"%"]})]})}),e.jsx("td",{className:"px-5 py-4 text-center",children:e.jsx("span",{className:"font-black text-amber-600 dark:text-amber-400",children:r.risk})}),e.jsx("td",{className:"px-5 py-4 text-center",children:e.jsx("span",{className:"font-black text-rose-600 dar
1k:text-rose-400",children:r.urgent})})]})})]})})]})]})]})})};export{Se as default};
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.