Spaces:
Running
Running
| import{j as e,r,d as Ss}from"./vendor-react-B4AQeu28.js";import{C as it,S as nt,a as qs}from"./Sidebar-BzrDfqvL.js";import ct from"./ConfirmModal-DRuU23Cj.js";import{e as we,p as Te,g as M,n as Se,j as S,h as _t,m as re,l as V,R as Me,k as Ot,v as Cs,Q as Bt,S as Gt,q as ot,u as cs,L as dt,V as As,y as xt,w as De,U as Pe,G as is,i as qt,W as Hs,X as Ws,Y as Vs,r as Ht,A as Qs,Z as Fe,$ as Wt,B as Vt,T as mt,b as He,H as Qt,a0 as Xt,a1 as Kt,E as Yt,M as Zt,O as Jt}from"./index-BOwCDUuj.js";import{B as E}from"./button-1xSKxP0s.js";import{S as J,a as ee,b as Ue,c as se,d as C}from"./select-Bl8DiN6a.js";import{I as xe}from"./input-BWVxOiw5.js";import{S as rs}from"./subjects-D7EDkved.js";import{getDocs as F,query as ve,collection as L,orderBy as We,deleteDoc as ea,doc as Es,limit as ns,where as Ve,addDoc as sa,serverTimestamp as ta,updateDoc as ws}from"./vendor-firebase-firestore-CNv3xXal.js";import{U as es}from"./upload-Cb7mbtBZ.js";import{D as fe}from"./LogoutActionButton-CjcJZZx1.js";import{F as Ce,A as _e,N as aa}from"./NotificationDropdown-DQeKfdb8.js";import{T as je}from"./trash-2-BOWLMguw.js";import{S as Xs}from"./sparkles-CxtI97fU.js";import{S as Ks,D as ht,a as pt,b as ut,c as gt,e as la}from"./dialog-CuD_NQRu.js";import{D as Ps}from"./download-BuFRG5Sl.js";import{S as zs}from"./shield-check-DNEs_q5F.js";import{S as bt}from"./search-ZUhbeLSB.js";import{C as Rs}from"./clock-DWx_frvc.js";import{E as ft,a as ra}from"./eye-CTVWgX_z.js";import{C as jt}from"./chevron-left-CrYQBVqe.js";import{C as vt}from"./chevron-right-BYKfhEhh.js";import{C as Re}from"./circle-alert-DxWksfMb.js";import{I as wt}from"./info-diWzsnAp.js";import{C as ia,a as na}from"./vendor-radix-C5nwdvGr.js";import{C as ca}from"./check-t4OiAwNW.js";import{M as oa}from"./mail-kTfbSOFG.js";import{P as Ys}from"./plus-DlHlqqJC.js";import{S as Nt}from"./save-CXyfXtOF.js";import{C as da}from"./chart-column-BFl6enfG.js";import{u as xa}from"./useQuery-CpGFa-gH.js";import{X as Ms}from"./x-kvx-MEXn.js";import{D as ma}from"./dollar-sign-BIZA5VNx.js";import{S as ha}from"./switch-Buh709Bh.js";import{u as pa,t as ua,a as ga}from"./useSubjectAvailability-9BDlT88a.js";import{C as ba}from"./chevron-up-BCCxX_dd.js";import{C as fa}from"./circle-help-CJo7eWXo.js";import{B as ja}from"./bell-48E-Lrzw.js";import{R as Zs,B as va,C as wa,X as Na,Y as ya,T as ka,a as Js,P as Sa,d as Ca,b as et}from"./vendor-charts-CAmziV1y.js";import{C as Ns}from"./circle-check-HPNz0jRj.js";import"./tooltip-BpnlqC8V.js";import"./shirt-OuYr8sXT.js";import"./log-out-BlnkNLnZ.js";import"./vendor-firebase-core-D7GXCeNu.js";import"./vendor-firebase-auth-T_wvTOvf.js";import"./vendor-firebase-storage-Bi7H_66d.js";import"./vendor-firebase-analytics-rHarj5hR.js";import"./vendor-markdown-yqZQ_iQm.js";import"./formatDistanceToNow-BJVtxIP9.js";/** | |
| * @license lucide-react v0.487.0 - ISC | |
| * | |
| * This source code is licensed under the ISC license. | |
| * See the LICENSE file in the root directory of this source tree. | |
| */const Aa=[["path",{d:"M7 7h10v10",key:"1tivn9"}],["path",{d:"M7 17 17 7",key:"1vkiza"}]],Ea=we("arrow-up-right",Aa);/** | |
| * @license lucide-react v0.487.0 - ISC | |
| * | |
| * This source code is licensed under the ISC license. | |
| * See the LICENSE file in the root directory of this source tree. | |
| */const za=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m4.9 4.9 14.2 14.2",key:"1m5liu"}]],st=we("ban",za);/** | |
| * @license lucide-react v0.487.0 - ISC | |
| * | |
| * This source code is licensed under the ISC license. | |
| * See the LICENSE file in the root directory of this source tree. | |
| */const Da=[["path",{d:"M21 12c.552 0 1.005-.449.95-.998a10 10 0 0 0-8.953-8.951c-.55-.055-.998.398-.998.95v8a1 1 0 0 0 1 1z",key:"pzmjnu"}],["path",{d:"M21.21 15.89A10 10 0 1 1 8 2.83",key:"k2fpak"}]],Pa=we("chart-pie",Da);/** | |
| * @license lucide-react v0.487.0 - ISC | |
| * | |
| * This source code is licensed under the ISC license. | |
| * See the LICENSE file in the root directory of this source tree. | |
| */const Ra=[["path",{d:"M12.531 3H3a1 1 0 0 0-.742 1.67l7.225 7.989A2 2 0 0 1 10 14v6a1 1 0 0 0 .553.895l2 1A1 1 0 0 0 14 21v-7a2 2 0 0 1 .517-1.341l.427-.473",key:"ol2ft2"}],["path",{d:"m16.5 3.5 5 5",key:"15e6fa"}],["path",{d:"m21.5 3.5-5 5",key:"m0lwru"}]],yt=we("funnel-x",Ra);/** | |
| * @license lucide-react v0.487.0 - ISC | |
| * | |
| * This source code is licensed under the ISC license. | |
| * See the LICENSE file in the root directory of this source tree. | |
| */const Ma=[["path",{d:"M3 12h.01",key:"nlz23k"}],["path",{d:"M3 18h.01",key:"1tta3j"}],["path",{d:"M3 6h.01",key:"1rqtza"}],["path",{d:"M8 12h13",key:"1za7za"}],["path",{d:"M8 18h13",key:"1lx6n3"}],["path",{d:"M8 6h13",key:"ik3vkj"}]],Ta=we("list",Ma);/** | |
| * @license lucide-react v0.487.0 - ISC | |
| * | |
| * This source code is licensed under the ISC license. | |
| * See the LICENSE file in the root directory of this source tree. | |
| */const $a=[["rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2",key:"1w4ew1"}],["path",{d:"M7 11V7a5 5 0 0 1 9.9-1",key:"1mm8w8"}]],La=we("lock-open",$a);/** | |
| * @license lucide-react v0.487.0 - ISC | |
| * | |
| * This source code is licensed under the ISC license. | |
| * See the LICENSE file in the root directory of this source tree. | |
| */const Ua=[["path",{d:"M7.21 15 2.66 7.14a2 2 0 0 1 .13-2.2L4.4 2.8A2 2 0 0 1 6 2h12a2 2 0 0 1 1.6.8l1.6 2.14a2 2 0 0 1 .14 2.2L16.79 15",key:"143lza"}],["path",{d:"M11 12 5.12 2.2",key:"qhuxz6"}],["path",{d:"m13 12 5.88-9.8",key:"hbye0f"}],["path",{d:"M8 7h8",key:"i86dvs"}],["circle",{cx:"12",cy:"17",r:"5",key:"qbz8iq"}],["path",{d:"M12 18v-2h-.5",key:"fawc4q"}]],tt=we("medal",Ua);/** | |
| * @license lucide-react v0.487.0 - ISC | |
| * | |
| * This source code is licensed under the ISC license. | |
| * See the LICENSE file in the root directory of this source tree. | |
| */const Ia=[["path",{d:"M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7",key:"1m0v6g"}],["path",{d:"M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z",key:"ohrbg2"}]],ss=we("square-pen",Ia);/** | |
| * @license lucide-react v0.487.0 - ISC | |
| * | |
| * This source code is licensed under the ISC license. | |
| * See the LICENSE file in the root directory of this source tree. | |
| */const Fa=[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["polyline",{points:"16 11 18 13 22 9",key:"1pwet4"}]],qe=we("user-check",Fa);function kt({className:s,...a}){return e.jsx("div",{"data-slot":"table-container",className:"relative w-full overflow-x-auto",children:e.jsx("table",{"data-slot":"table",className:Te("w-full caption-bottom text-sm",s),...a})})}function St({className:s,...a}){return e.jsx("thead",{"data-slot":"table-header",className:Te("[&_tr]:border-b",s),...a})}function Ct({className:s,...a}){return e.jsx("tbody",{"data-slot":"table-body",className:Te("[&_tr:last-child]:border-0",s),...a})}function Ie({className:s,...a}){return e.jsx("tr",{"data-slot":"table-row",className:Te("hover:bg-muted/50 data-[state=selected]:bg-muted border-b transition-colors",s),...a})}function ge({className:s,...a}){return e.jsx("th",{"data-slot":"table-head",className:Te("text-foreground h-10 px-2 text-left align-middle font-medium whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",s),...a})}function ie({className:s,...a}){return e.jsx("td",{"data-slot":"table-cell",className:Te("p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",s),...a})}const _a=({onUploadSuccess:s})=>{const[a,n]=r.useState("upload"),[i,l]=r.useState(!1),[o,g]=r.useState(null),[m,N]=r.useState(!1),[v,h]=r.useState(null),[c,x]=r.useState(""),[f,w]=r.useState(""),[A,u]=r.useState("1"),[y,D]=r.useState(0),[T,q]=r.useState(null),[me,he]=r.useState(!1),Ne=r.useRef(null),[_,pe]=r.useState([]),[X,Q]=r.useState(!1),U=r.useCallback(async()=>{Q(!0);try{const[p,P]=await Promise.all([F(ve(L(M,"courseMaterials"),We("createdAt","desc"))),F(ve(L(M,"classRecordImports"),We("createdAt","desc")))]),H=[...p.docs.map(Y=>{const G=Y.data();return{id:Y.id,fileName:G.fileName||"Untitled",teacherEmail:G.teacherEmail||"",fileType:G.fileType||"PDF",className:G.className,createdAt:G.createdAt?.toDate?.()||new Date,collection:"courseMaterials"}}),...P.docs.map(Y=>{const G=Y.data();return{id:Y.id,fileName:G.fileName||"Untitled",teacherEmail:G.teacherEmail||"",fileType:G.fileType||"CSV",className:G.className,createdAt:G.createdAt?.toDate?.()||new Date,collection:"classRecordImports"}})].sort((Y,G)=>G.createdAt.getTime()-Y.createdAt.getTime());pe(H)}catch(p){console.error("Failed to load uploaded files:",p)}finally{Q(!1)}},[]),te=async(p,P)=>{try{await Se.adminDeleteFile(p,P),S.success("File removed"),U()}catch{try{await ea(Es(M,P,p)),S.success("File removed"),U()}catch{S.error("Failed to delete file")}}};Ss.useEffect(()=>{U()},[U]);const O=r.useCallback(async()=>{he(!0);try{const p=await Se.getRagHealth();q({subjects:p.subjects||{},chunkCount:p.chunkCount||0,lastIngested:p.lastIngested||""})}catch{S.error("Failed to load RAG health status")}finally{he(!1)}},[]);Ss.useEffect(()=>{O()},[O]);const K=p=>{if(p.type!=="application/pdf"){S.error("Only PDF files are allowed");return}if(p.size>50*1024*1024){S.error("File size must be under 50MB");return}if(h(p),c){const P=rs.find(H=>H.id===c);P&&w(P.name)}},ne=r.useCallback(p=>{p.preventDefault(),N(!1);const P=p.dataTransfer.files[0];P&&K(P)},[c]),B=r.useCallback(p=>{p.preventDefault(),N(!0)},[]),ce=r.useCallback(()=>N(!1),[]),d=p=>{x(p);const P=rs.find(H=>H.id===p);P&&w(P.name)},ae=async()=>{if(!v||!c||!f.trim()){S.error("Please select a PDF file, subject, and enter a subject name");return}l(!0),D(0);try{const p=new FormData;p.append("file",v),p.append("subjectId",c),p.append("subjectName",f.trim()),p.append("quarter",A);const P=setInterval(()=>{D(Y=>Math.min(Y+15,85))},300),H=await Se.uploadModulePdf(p);clearInterval(P),D(100),H.success?(S.success(`${v.name} uploaded! ${H.chunkCount??0} chunks indexed.`),h(null),H.chunkCount!==void 0&&s?.(c,H.chunkCount),O(),setTimeout(()=>n("inventory"),1e3)):S.error(H.error||"Upload failed")}catch(p){S.error(p instanceof Error?p.message:"Upload failed")}finally{l(!1),setTimeout(()=>D(0),500)}};return T&&Object.entries(T.subjects).map(([p,P])=>({name:p,chunks:P,storagePath:"",status:P>0?"active":"missing"})).filter(p=>p.chunks>0),e.jsxs("div",{className:"space-y-4 pt-2 xl:pt-4 pb-4 max-w-[1200px] mx-auto",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-1 bg-white p-1 rounded-2xl border border-slate-200 shadow-sm",children:[e.jsxs("button",{onClick:()=>n("upload"),className:`flex items-center gap-2 px-5 py-2 rounded-xl text-[12px] font-black transition-all duration-300 ${a==="upload"?"bg-[#9956DE] text-white shadow-lg shadow-purple-200":"text-slate-400 hover:text-purple-600 hover:bg-purple-50"}`,children:[e.jsx(es,{size:14}),"Import"]}),e.jsxs("button",{onClick:()=>n("inventory"),className:`flex items-center gap-2 px-5 py-2 rounded-xl text-[12px] font-black transition-all duration-300 ${a==="inventory"?"bg-[#9956DE] text-white shadow-lg shadow-purple-200":"text-slate-400 hover:text-purple-600 hover:bg-purple-50"}`,children:[e.jsx(fe,{size:14}),"Inventory"]})]}),e.jsx("div",{className:"flex items-center gap-3"})]}),e.jsx(_t,{mode:"wait",children:a==="upload"?e.jsxs(re.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},exit:{opacity:0,y:-8},className:"space-y-4",children:[e.jsxs("div",{className:"bg-white rounded-[24px] border border-slate-200 shadow-sm overflow-hidden group",children:[e.jsxs("div",{className:"p-6 border-b border-slate-50 bg-gradient-to-br from-white to-purple-50/20 relative",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-black text-[#1e293b] tracking-tight",children:"Learning Module Upload"}),e.jsx("p",{className:"text-[11px] text-slate-500 font-medium italic",children:"Provide curriculum context for AI tutoring logic."})]}),e.jsx("div",{className:"w-10 h-10 bg-[#9956DE] rounded-xl flex items-center justify-center text-white shadow-md transition-transform group-hover:scale-110",children:e.jsx(es,{size:20})})]}),e.jsx("div",{className:"mt-6",children:e.jsxs("div",{onDrop:ne,onDragOver:B,onDragLeave:ce,onClick:()=>!i&&Ne.current?.click(),className:` | |
| relative border-2 border-dashed rounded-2xl p-6 text-center cursor-pointer transition-all duration-300 group/drop | |
| ${m?"border-[#9956DE] bg-purple-50 scale-[0.99]":"border-slate-200 hover:border-[#9956DE] bg-white hover:bg-purple-50/30"} | |
| ${i?"cursor-not-allowed opacity-60":""} | |
| min-h-[160px] flex flex-col items-center justify-center | |
| `,children:[e.jsx("input",{ref:Ne,type:"file",accept:".pdf",className:"hidden",onChange:p=>p.target.files?.[0]&&K(p.target.files[0])}),v?e.jsxs("div",{className:"flex items-center gap-4 text-left",children:[e.jsx("div",{className:"w-14 h-14 bg-purple-50 rounded-xl flex items-center justify-center text-purple-600 border border-purple-100 shadow-sm shrink-0",children:e.jsx(Ce,{size:28})}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("p",{className:"font-black text-[14px] text-[#1e293b] truncate max-w-[300px]",children:v.name}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-[10px] text-purple-500 font-black uppercase",children:[(v.size/1024/1024).toFixed(2)," MB"]}),e.jsx("span",{className:"text-[10px] text-slate-400 font-bold uppercase tracking-widest italic",children:"PDF Source"})]}),e.jsxs("button",{onClick:p=>{p.stopPropagation(),h(null)},className:"text-[10px] font-black text-rose-500 hover:text-rose-600 mt-1 flex items-center gap-1",children:[e.jsx(je,{size:10})," Replace"]})]})]}):e.jsxs("div",{className:"flex flex-col items-center justify-center",children:[e.jsx("div",{className:"w-12 h-12 bg-slate-50 rounded-xl flex items-center justify-center text-slate-300 mb-4 group-hover/drop:text-purple-500 group-hover/drop:bg-purple-50 transition-all",children:e.jsx(es,{size:24})}),e.jsx("h4",{className:"text-[14px] font-black text-[#1e293b]",children:"Drop PDF or click to browse"}),e.jsx("p",{className:"text-[10px] text-slate-400 mt-1 font-medium italic",children:"Max 50MB (SLM, Textbook, Guide)"})]}),y>0&&e.jsx("div",{className:"absolute inset-0 bg-white/95 backdrop-blur-[1px] rounded-2xl flex flex-col items-center justify-center p-8 z-20",children:e.jsxs("div",{className:"w-full max-w-xs space-y-3 text-center",children:[e.jsx("div",{className:"w-12 h-12 bg-[#9956DE] rounded-xl flex items-center justify-center mx-auto mb-2 animate-bounce",children:e.jsx(Xs,{size:24,className:"text-white"})}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("h5",{className:"text-sm font-black text-[#1e293b]",children:i?"Analyzing Curriculum...":"Complete!"}),e.jsx("p",{className:"text-[9px] font-black text-slate-400 uppercase tracking-widest",children:"Platform Ingestion"})]}),e.jsx("div",{className:"h-2 bg-slate-100 rounded-full overflow-hidden p-0.5 border border-slate-200 mt-2",children:e.jsx(re.div,{className:"h-full bg-gradient-to-r from-purple-500 to-sky-500 rounded-full",initial:{width:0},animate:{width:`${y}%`},transition:{duration:.3}})})]})})]})})]}),e.jsxs("div",{className:"p-6 space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-[9px] font-black text-slate-400 uppercase tracking-widest ml-1",children:"Curriculum Subject"}),e.jsxs(J,{value:c,onValueChange:d,disabled:i,children:[e.jsx(ee,{className:"w-full h-10 bg-slate-50/50 border-slate-200 rounded-xl text-[12px] font-bold focus:ring-purple-500/20",children:e.jsx(Ue,{placeholder:"Select subject"})}),e.jsx(se,{className:"rounded-xl border-slate-200",children:rs.map(p=>e.jsx(C,{value:p.id,className:"rounded-lg py-2",children:e.jsxs("div",{className:"flex flex-col items-start",children:[e.jsx("span",{className:"font-black text-[12px]",children:p.name}),e.jsxs("span",{className:"text-[9px] text-slate-400 font-bold uppercase",children:[p.gradeLevel," • ",p.semester]})]})},p.id))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-[9px] font-black text-slate-400 uppercase tracking-widest ml-1",children:"Display Label"}),e.jsx(xe,{value:f,onChange:p=>w(p.target.value),placeholder:"e.g. General Mathematics",disabled:i,className:"h-10 bg-slate-50/50 border-slate-200 rounded-xl text-[12px] font-bold px-4 focus-visible:ring-purple-500/20"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-[9px] font-black text-slate-400 uppercase tracking-widest ml-1",children:"Quarter"}),e.jsxs(J,{value:A,onValueChange:u,disabled:i,children:[e.jsx(ee,{className:"w-full h-10 bg-slate-50/50 border-slate-200 rounded-xl text-[12px] font-bold focus:ring-purple-500/20",children:e.jsx(Ue,{})}),e.jsxs(se,{className:"rounded-xl border-slate-200",children:[e.jsx(C,{value:"1",className:"rounded-lg text-[12px] font-bold",children:"First Quarter"}),e.jsx(C,{value:"2",className:"rounded-lg text-[12px] font-bold",children:"Second Quarter"}),e.jsx(C,{value:"3",className:"rounded-lg text-[12px] font-bold",children:"Third Quarter"}),e.jsx(C,{value:"4",className:"rounded-lg text-[12px] font-bold",children:"Fourth Quarter"})]})]})]})]}),e.jsx(E,{onClick:ae,disabled:i||!v||!c||!f.trim(),className:"w-full h-12 gap-2 bg-[#9956DE] hover:bg-[#8b5cf6] text-white rounded-2xl shadow-lg shadow-purple-100 transition-all hover:scale-[1.01] active:scale-95 text-[14px] font-black",children:i?e.jsxs(e.Fragment,{children:[e.jsx(V,{size:16,className:"animate-spin"})," Ingesting..."]}):e.jsxs(e.Fragment,{children:[e.jsx(es,{size:16})," Deploy Knowledge Source"]})})]})]}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:[{icon:Xs,color:"bg-purple-50",iconColor:"text-purple-600",title:"Grounding",desc:"Curriculum-pinned logic."},{icon:fe,color:"bg-sky-50",iconColor:"text-sky-600",title:"Indexing",desc:"Millisecond RAG retrieval."},{icon:it,color:"bg-emerald-50",iconColor:"text-emerald-600",title:"Extraction",desc:"Neural chunk parsing."}].map((p,P)=>e.jsxs("div",{className:"bg-white rounded-xl p-3 border border-slate-100 shadow-sm flex items-start gap-3",children:[e.jsx("div",{className:`w-8 h-8 rounded-lg ${p.color} flex items-center justify-center shrink-0`,children:e.jsx(p.icon,{size:14,className:p.iconColor})}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-[10px] font-black text-[#1e293b] uppercase tracking-wide leading-none",children:p.title}),e.jsx("p",{className:"text-[9px] text-slate-400 leading-tight mt-1 font-medium italic",children:p.desc})]})]},P))})]},"upload-tab"):e.jsx(re.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},exit:{opacity:0,y:-8},className:"space-y-4",children:e.jsx("div",{className:"bg-white rounded-[24px] border border-slate-200 shadow-sm overflow-hidden relative",children:e.jsxs(kt,{className:"w-full text-left border-collapse",children:[e.jsx(St,{children:e.jsxs(Ie,{className:"bg-[#9956DE] hover:bg-[#9956DE] border-b border-[#8b5cf6] sticky top-0 z-20 shadow-sm",children:[e.jsx(ge,{className:"px-6 py-4 text-[10px] font-black text-white uppercase tracking-widest h-auto",children:"File Name"}),e.jsx(ge,{className:"px-6 py-4 text-[10px] font-black text-white uppercase tracking-widest h-auto",children:"Uploaded By"}),e.jsx(ge,{className:"px-6 py-4 text-[10px] font-black text-white uppercase tracking-widest h-auto",children:"Type"}),e.jsx(ge,{className:"px-6 py-4 text-[10px] font-black text-white uppercase tracking-widest h-auto",children:"Date"}),e.jsx(ge,{className:"px-6 py-4 text-[10px] font-black text-white uppercase tracking-widest h-auto text-right",children:e.jsx(E,{variant:"ghost",size:"sm",className:"h-8 px-2 bg-white/10 text-white hover:bg-white/20 rounded-lg",onClick:U,disabled:X,children:e.jsx(Me,{size:12,className:X?"animate-spin":""})})})]})}),e.jsx(Ct,{className:"divide-y divide-slate-50",children:X?e.jsx(Ie,{children:e.jsxs(ie,{colSpan:5,className:"h-48 text-center",children:[e.jsx(V,{size:24,className:"animate-spin text-purple-500 mx-auto"}),e.jsx("p",{className:"text-[10px] font-black text-slate-400 uppercase tracking-widest mt-2",children:"Loading files..."})]})}):_.length===0?e.jsx(Ie,{children:e.jsxs(ie,{colSpan:5,className:"h-48 text-center",children:[e.jsx(Ce,{size:24,className:"text-slate-200 mx-auto"}),e.jsx("p",{className:"text-[12px] font-black text-slate-400 mt-2",children:"No uploaded files found."})]})}):_.map(p=>e.jsxs(Ie,{className:"group hover:bg-purple-50/10 transition-all",children:[e.jsx(ie,{className:"px-6 py-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Ce,{size:16,className:"text-purple-500"}),e.jsx("span",{className:"font-bold text-[13px] text-slate-800 truncate max-w-[200px]",children:p.fileName})]})}),e.jsx(ie,{className:"px-6 py-4 text-[12px] text-slate-600",children:p.teacherEmail||"—"}),e.jsx(ie,{className:"px-6 py-4",children:e.jsx("span",{className:"px-2 py-0.5 rounded-full text-[9px] font-black uppercase bg-slate-100 text-slate-600",children:p.fileType})}),e.jsx(ie,{className:"px-6 py-4 text-[12px] text-slate-500",children:p.createdAt.toLocaleDateString()}),e.jsx(ie,{className:"px-6 py-4 text-right",children:e.jsx(E,{variant:"ghost",size:"sm",className:"h-7 px-2 text-slate-400 hover:text-red-500 hover:bg-red-50",onClick:()=>te(p.id,p.collection),children:e.jsx(je,{size:14})})})]},p.id))})]})})},"inventory-tab")})]})};function At(s){return s?s.charAt(0).toUpperCase()+s.slice(1):"Student"}function Ds(s){if(!s||!s.toDate)return new Date().toISOString().replace("T"," ").slice(0,19);const a=s.toDate();return`${a.getFullYear()}-${String(a.getMonth()+1).padStart(2,"0")}-${String(a.getDate()).padStart(2,"0")} ${String(a.getHours()).padStart(2,"0")}:${String(a.getMinutes()).padStart(2,"0")}:${String(a.getSeconds()).padStart(2,"0")}`}function Oa(){return Ds({toDate:()=>new Date})}function Ba(s){if(!s)return"Never";const a=new Date(s);if(Number.isNaN(a.getTime()))return s;const i=Date.now()-a.getTime(),l=Math.floor(i/6e4);if(l<1)return"Just now";if(l<60)return`${l} minute${l!==1?"s":""} ago`;const o=Math.floor(l/60);if(o<24)return`${o} hour${o!==1?"s":""} ago`;const g=Math.floor(o/24);return g<7?`${g} day${g!==1?"s":""} ago`:a.toLocaleDateString()}function Ga(s){const a=(s.grade||"").trim(),n=(s.section||"").trim(),i=[a,n].filter(Boolean).join(" - ");return{id:s.uid,name:s.name||"Unknown",email:s.email||"",role:At(s.role||""),status:s.status||"Active",department:s.department||(s.role?.toLowerCase()==="student"?i||"Student":""),grade:a,section:n,classSectionId:s.classSectionId||void 0,classSection:i,lrn:(s.lrn||"").trim(),gender:s.gender||null,photo:(s.photo||"").trim(),lastLogin:Ba(s.lastLogin),createdAt:s.createdAt||void 0}}function os(s){if(s instanceof ot){try{const a=JSON.parse(s.responseBody);if(a?.detail&&typeof a.detail=="string")return a.detail}catch{}return`Request failed (${s.status}).`}return s instanceof Error?s.message:"Request failed."}async function qa(s={}){try{const a=await Se.getAdminUsers({page:s.page??1,pageSize:s.pageSize??25,search:s.searchQuery,role:s.roleFilter,status:s.statusFilter,grade:s.gradeFilter,section:s.sectionFilter,classSectionId:s.classSectionId});if(!a.success)throw new Error("Failed to load admin users");return{users:(a.users||[]).map(Ga),page:a.page,pageSize:a.pageSize,total:a.total,totalPages:a.totalPages,hasNextPage:a.hasNextPage}}catch(a){throw console.error("[adminService] getAdminUsersPage error:",a),a instanceof Bt?new Error("Loading users timed out. Please refresh and try again."):a instanceof Gt?new Error("Unable to reach the server. Please check your connection and retry."):a instanceof ot&&a.status===504?new Error("Loading users took too long. Try narrowing your filters and retrying."):new Error(os(a))}}async function Ha(s,a){try{await Se.updateAdminUser(s,{...a.name!==void 0?{name:a.name}:{},...a.role!==void 0?{role:a.role}:{},...a.status!==void 0?{status:a.status}:{},...a.department!==void 0?{department:a.department}:{},...a.grade!==void 0?{grade:a.grade}:{},...a.section!==void 0?{section:a.section}:{},...a.lrn!==void 0?{lrn:a.lrn}:{}})}catch(n){throw new Error(os(n))}}async function Wa(s){try{const a=await Se.createAdminUser({name:s.name.trim(),email:s.email.trim().toLowerCase(),password:s.password,confirmPassword:s.confirmPassword,role:s.role,status:s.status,grade:s.grade.trim(),section:s.section.trim(),...s.lrn?.trim()?{lrn:s.lrn.trim()}:{}});if(!a.success||!a.userCreated||!a.uid)throw new Error(a.message||"Failed to create user account.");return{uid:a.uid,userCreated:a.userCreated,emailSent:a.emailSent,resultCode:a.resultCode,message:a.message,warnings:a.warnings??[],emailError:a.emailError}}catch(a){throw new Error(os(a))}}async function Va(s){try{const a=await Se.bulkAdminUsers({action:s.action,userIds:s.userIds??[],excludeUserIds:s.excludeUserIds??[],filters:s.filters,role:s.role,status:s.status,grade:s.grade,section:s.section,lrn:s.lrn,dryRun:s.dryRun,exportFormat:s.exportFormat??"csv"});return{success:a.success,action:a.action,summary:a.summary,results:a.results,warnings:a.warnings||[],exportRows:a.export?.rows||[]}}catch(a){throw new Error(os(a))}}async function Et(){try{if(!Ot.currentUser)return[];const s=ve(L(M,"accessAuditLogs"),We("timestamp","desc"),ns(100)),n=(await F(s)).docs.map(g=>{const m=g.data(),v=m.success!==!1?"Info":"Error",h=m.action||"";let c="System";return m.module==="admin"||h.startsWith("admin_")?c="User":h.includes("login")||h.includes("auth")?c="Auth":(h.includes("upload")||h.includes("course"))&&(c="Content"),{id:g.id,severity:v,timestamp:typeof m.timestamp=="string"?m.timestamp:Ds(m.timestamp),user:{name:(()=>{const f=m.actorName||m.actorEmail||m.teacherEmail||m.teacherId||"SYSTEM";return f==="Unknown"||!f?"SYSTEM":f.includes("@")?f.split("@")[0].replace(/[._-]/g," ").replace(/\b\w/g,A=>A.toUpperCase()):f})(),role:At(m.actorRole||m.role||"System"),avatar:null},action:h,category:c,details:m.description||(m.status?`Status: ${m.status}`:"")}}),i=ve(L(M,"auditLogs"),We("timestampRaw","desc"),ns(50)),o=(await F(i)).docs.map(g=>{const m=g.data(),N=m.user;return{id:`audit-${g.id}`,severity:m.severity||"Info",timestamp:m.timestamp||Ds(m.timestampRaw),user:{name:N?.name||"SYSTEM",role:N?.role||"System",avatar:N?.avatar??null},action:m.action||"",category:m.category||"System",details:m.details||""}});return[...n,...o].sort((g,m)=>m.timestamp.localeCompare(g.timestamp)).slice(0,100)}catch(s){const a=s;return a?.code==="permission-denied"||a?.code==="firestore/permission-denied"?[]:(console.error("[adminService] getAuditLogs error:",s),[])}}async function ys(s,a,n,i,l){await sa(L(M,"auditLogs"),{severity:n,timestamp:Oa(),timestampRaw:ta(),user:l,action:s,category:a,details:i})}async function Qa(){try{const s=await F(L(M,"users"));let a=0,n=0,i=0;const l=new Set;s.docs.forEach(N=>{const v=N.data();v.role==="student"&&(a++,v.overallRisk==="High"&&(i++,l.add(N.id))),v.role==="teacher"&&v.status!=="Inactive"&&n++});try{(await F(L(M,"managedStudents"))).docs.forEach(v=>{const c=v.data().riskStatus;c&&["intervene","critical","at_risk"].includes(c)&&(l.has(v.id)||(i++,l.add(v.id)))})}catch{}let o=0;try{o=(await F(L(M,"classrooms"))).size}catch{}let g=0;try{g=(await F(L(M,"xpActivities"))).size}catch{}let m=0;try{const N=await F(L(M,"progress")),v=[];N.docs.forEach(h=>{const c=h.data();typeof c.averageScore=="number"&&v.push(c.averageScore)}),m=v.length>0?Math.round(v.reduce((h,c)=>h+c,0)/v.length):0}catch{}return{totalStudents:a,activeTeachers:n,totalClasses:o,atRiskStudents:i,avgPerformance:m,aiPredictions:g}}catch(s){return console.error("[adminService] getDashboardStats error:",s),{totalStudents:0,activeTeachers:0,totalClasses:0,atRiskStudents:0,avgPerformance:0,aiPredictions:0}}}async function Xa(s=3){const a=i=>{const l=i.data(),o=l.level||1,g=l.currentXP||0,m=Math.min(100,o*8+Math.round(g/100));return{id:i.id,name:l.name||"Student",avatar:l.photo||l.photoURL||Cs(l.gender||null),class:l.grade||"Math",performance:m,level:o}},n=i=>i.sort((l,o)=>o.level!==l.level?o.level-l.level:o.performance-l.performance).slice(0,s);try{const i=ve(L(M,"users"),Ve("role","==","student"),We("level","desc"),ns(s)),l=await F(i);return n(l.docs.map(a))}catch(i){if(i?.code==="failed-precondition")try{const o=ve(L(M,"users"),Ve("role","==","student"),ns(Math.max(50,s))),g=await F(o);return n(g.docs.map(a))}catch(o){return console.error("[adminService] getTopPerformers fallback error:",o),[]}return console.error("[adminService] getTopPerformers error:",i),[]}}async function Ka(){try{const s=new Date,a=["S","M","T","W","T","F","S"],n=[];for(let l=6;l>=0;l--){const o=new Date(s);o.setDate(o.getDate()-l),n.push({name:a[o.getDay()],ai:0,man:0})}return(await F(L(M,"xpActivities"))).docs.forEach(l=>{const o=l.data(),g=o.timestamp;if(!g?.toDate)return;const m=g.toDate(),N=Math.floor((s.getTime()-m.getTime())/864e5);if(N<0||N>6)return;const v=6-N,h=o.type;h==="lesson_complete"||h==="quiz_complete"?n[v].ai++:n[v].man++}),n}catch(s){return console.error("[adminService] getWeeklyActivity error:",s),[{name:"M",ai:0,man:0},{name:"T",ai:0,man:0},{name:"W",ai:0,man:0},{name:"T",ai:0,man:0},{name:"F",ai:0,man:0},{name:"S",ai:0,man:0},{name:"S",ai:0,man:0}]}}async function Ya(){try{const s=await F(L(M,"progress")),a={"gen-math":{enrolled:0,totalProgress:0},"stats-prob":{enrolled:0,totalProgress:0}};return s.docs.forEach(n=>{const l=n.data().subjects;l&&Object.entries(l).forEach(([o,g])=>{a[o]&&(a[o].enrolled++,a[o].totalProgress+=g?.progress??0)})}),[{name:"General Mathematics",type:"Core",count:a["gen-math"].enrolled,progress:a["gen-math"].enrolled>0?Math.round(a["gen-math"].totalProgress/a["gen-math"].enrolled):0},{name:"Statistics & Probability",type:"Core",count:a["stats-prob"].enrolled,progress:a["stats-prob"].enrolled>0?Math.round(a["stats-prob"].totalProgress/a["stats-prob"].enrolled):0}]}catch(s){return console.error("[adminService] getSubjectBreakdown error:",s),[]}}async function Za(){try{const s=new Set;let a=0;(await F(ve(L(M,"users"),Ve("role","==","student")))).docs.forEach(i=>{i.data().overallRisk==="High"&&(a++,s.add(i.id))});try{(await F(L(M,"managedStudents"))).docs.forEach(l=>{const g=l.data().riskStatus;g&&["intervene","critical","at_risk"].includes(g)&&!s.has(l.id)&&(a++,s.add(l.id))})}catch{}return{subjectName:"General Mathematics",atRiskCount:a}}catch(s){return console.error("[adminService] getPriorityAttention error:",s),{subjectName:"General Mathematics",atRiskCount:0}}}async function Ja(){try{const s=await F(L(M,"progress"));let a=0,n=0,i=0,l=0;return s.docs.forEach(o=>{const m=o.data().averageScore;typeof m=="number"?(a+=m,l++,m>=60?n++:i++):i++}),{avgMastery:l>0?Math.round(a/l):0,passed:n,pending:i}}catch(s){return console.error("[adminService] getGlobalMastery error:",s),{avgMastery:0,passed:0,pending:0}}}async function el(){try{const s=await F(L(M,"progress"));let a=0,n=0,i=0;s.docs.forEach(o=>{const m=o.data().averageScore;if(typeof m!="number"){a++;return}m<50?a++:m<80?n++:i++});const l=a+n+i||1;return{foundational:Math.round(a/l*100),intermediate:Math.round(n/l*100),advanced:Math.round(i/l*100)}}catch(s){return console.error("[adminService] getDifficultyDistribution error:",s),{foundational:0,intermediate:0,advanced:0}}}async function sl(){try{const s=await F(L(M,"users"));let a=0,n=0,i=0,l=0,o=0;const g=new Set;s.docs.forEach(c=>{const x=c.data();x.role==="student"&&(a++,x.overallRisk==="High"&&(i++,g.add(c.id)),x.streak>0&&o++,l+=x.totalXP||0),x.role==="teacher"&&n++});try{(await F(L(M,"managedStudents"))).docs.forEach(x=>{const w=x.data().riskStatus;w&&["intervene","critical","at_risk"].includes(w)&&!g.has(x.id)&&(i++,g.add(x.id))})}catch{}let m=0;try{m=(await F(L(M,"achievements"))).size}catch{}let N=0;try{N=(await F(L(M,"chatSessions"))).size}catch{}let v=0,h=0;try{const c=await F(L(M,"progress")),x=[];c.docs.forEach(f=>{const A=f.data().quizAttempts;A?.length&&(v+=A.length,A.forEach(u=>{typeof u.score=="number"&&x.push(u.score)}))}),h=x.length>0?Math.round(x.reduce((f,w)=>f+w,0)/x.length):0}catch{}return{totalActiveUsers:a+n,totalStudents:a,totalTeachers:n,atRiskStudents:i,achievementsUnlocked:m,totalXPEarned:l,activeStreaks:o,aiTutorSessions:N,totalQuizzesTaken:v,avgQuizScore:h}}catch(s){return console.error("[adminService] getAnalyticsSummary error:",s),{totalActiveUsers:0,totalStudents:0,totalTeachers:0,atRiskStudents:0,achievementsUnlocked:0,totalXPEarned:0,activeStreaks:0,aiTutorSessions:0,totalQuizzesTaken:0,avgQuizScore:0}}}const tl=[10,25,50,100],ts=({title:s,value:a,subtitle:n,icon:i,variant:l})=>{const o={blue:"bg-[#5154E7] shadow-blue-200/50",purple:"bg-[#9956DE] shadow-purple-200/50",rose:"bg-[#F43F5E] shadow-rose-200/50",emerald:"bg-[#10B981] shadow-emerald-200/50"};return e.jsxs("div",{className:`relative overflow-hidden rounded-[24px] p-5 text-white shadow-lg transition-all hover:scale-[1.02] ${o[l]}`,children:[e.jsx("div",{className:"absolute -right-4 -top-4 opacity-10",children:e.jsx(i,{size:100})}),e.jsx("div",{className:"absolute right-4 top-4 w-8 h-8 rounded-full bg-white/20 flex items-center justify-center",children:e.jsx(i,{size:16})}),e.jsx("p",{className:"text-[10px] font-black uppercase tracking-[0.2em] opacity-80",children:s}),e.jsx("h3",{className:"text-2xl font-black mt-2 leading-none",children:a}),e.jsx("p",{className:"text-[10px] font-bold mt-4 opacity-70 uppercase tracking-widest",children:n}),e.jsx("div",{className:"absolute -bottom-8 -left-8 w-20 h-20 bg-white/10 rounded-full blur-2xl"})]})},al=()=>{const{userProfile:s,loading:a}=cs(),[n,i]=r.useState([]),[l,o]=r.useState(!0),[g,m]=r.useState(!1),[N,v]=r.useState(""),[h,c]=r.useState("All Categories"),[x,f]=r.useState("All Severities"),[w,A]=r.useState("All Roles"),[u,y]=r.useState(null),[D,T]=r.useState(1),[q,me]=r.useState(25),he=r.useCallback(async()=>{if(a||!s)return;const d=String(s.role||"").toLowerCase();if(d!=="admin"&&d!=="teacher"){o(!1),m(!0);return}m(!1),o(!0);try{const ae=await Et();i(ae)}catch{S.error("Failed to load audit logs")}finally{o(!1)}},[a,s]);r.useEffect(()=>{he()},[he]);const Ne=n.filter(d=>d.severity==="Info").length;n.filter(d=>d.severity==="Warning").length;const _=n.filter(d=>d.severity==="Error"||d.severity==="Critical").length,pe=d=>{switch(d){case"Info":return e.jsx(wt,{size:14});case"Warning":return e.jsx(xt,{size:14});case"Error":return e.jsx(Ks,{size:14});case"Critical":return e.jsx(Re,{size:14});default:return e.jsx(_e,{size:14})}},X=d=>{switch(d){case"Info":return"bg-sky-50 text-sky-600 border-sky-100";case"Warning":return"bg-amber-50 text-amber-600 border-amber-100";case"Error":return"bg-rose-50 text-rose-600 border-rose-100";case"Critical":return"bg-red-50 text-red-600 border-red-100 ring-1 ring-red-500";default:return"bg-slate-50 text-slate-600 border-slate-100"}},Q={"All Categories":"All Categories",Auth:"Authentication",Data:"Data Operations",User:"User Management",System:"System Engine",Content:"Content Pipeline"},U={"All Severities":"All Severities",Info:"Information",Warning:"Warning",Error:"Error",Critical:"Critical"},te={"All Roles":"All Roles",Admin:"Administrator",Teacher:"Educator",Student:"Student"},O=r.useMemo(()=>n.filter(d=>{const ae=d.action.toLowerCase().includes(N.toLowerCase())||d.details.toLowerCase().includes(N.toLowerCase())||d.user.name.toLowerCase().includes(N.toLowerCase()),p=h==="All Categories"||d.category===h,P=x==="All Severities"||d.severity===x,H=w==="All Roles"||d.user.role===w;return ae&&p&&P&&H}),[n,N,h,x,w]),K=Math.max(Math.ceil(O.length/q),1),ne=r.useMemo(()=>{const d=(D-1)*q;return O.slice(d,d+q)},[O,D,q]);if(r.useEffect(()=>{T(1)},[N,h,x,w]),g)return e.jsxs("div",{className:"flex flex-col items-center justify-center min-h-[400px] text-center p-8 bg-white rounded-[32px] border border-slate-200 mt-8",children:[e.jsx("div",{className:"w-20 h-20 rounded-full bg-rose-50 flex items-center justify-center mb-6",children:e.jsx(dt,{size:40,className:"text-rose-500"})}),e.jsx("h3",{className:"text-2xl font-black text-[#1e293b]",children:"Access Denied"}),e.jsx("p",{className:"text-slate-400 font-medium max-w-md mx-auto mt-2 uppercase text-[11px] tracking-widest",children:"Security policy restricts audit log visibility to administrative personnel only."})]});const B=O.length===0?0:(D-1)*q+1,ce=Math.min(D*q,O.length);return e.jsxs("div",{className:"flex flex-col min-h-full animate-in fade-in duration-500",children:[e.jsxs("div",{className:"flex-1 space-y-8 pt-6 xl:pt-8 pb-6 px-1 max-w-[1600px] mx-auto w-full",children:[e.jsxs("div",{className:"flex items-center justify-between px-2 shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-1.5 h-6 bg-[#9956DE] rounded-full"}),e.jsx("p",{className:"text-[11px] font-black text-slate-400 uppercase tracking-[0.2em]",children:"System Governance Pipeline"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{onClick:he,disabled:l,className:"p-2.5 rounded-xl bg-white border border-slate-200 text-slate-400 hover:text-purple-600 shadow-sm transition-all active:scale-95 group",title:"Synchronize logs",children:e.jsx(Me,{size:14,className:l?"animate-spin":"group-hover:rotate-180 transition-transform duration-500"})}),e.jsxs("button",{disabled:!0,className:"flex items-center gap-2 px-4 py-2 bg-white border border-slate-200 text-slate-400 rounded-xl text-[10px] font-black uppercase tracking-widest opacity-60 cursor-not-allowed",children:[e.jsx(Ps,{size:14})," Export Logs"]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4 shrink-0",children:[e.jsx(ts,{title:"Total Events",value:l?"...":n.length,subtitle:"System-Wide Logs",icon:Ce,variant:"purple"}),e.jsx(ts,{title:"Security Alerts",value:l?"...":_,subtitle:"Critical Incidents",icon:Ks,variant:"rose"}),e.jsx(ts,{title:"Operational Info",value:l?"...":Ne,subtitle:"Routine Pipelines",icon:qe,variant:"blue"}),e.jsx(ts,{title:"System Health",value:_>0?"Compromised":"Healthy",subtitle:"Live Monitoring",icon:zs,variant:_>0?"rose":"emerald"})]})]}),e.jsx("div",{className:"sticky top-0 z-40 -mx-[24px] xl:-mx-[32px] px-[24px] xl:px-[32px] pt-4 pb-4 bg-[#f8fafc] backdrop-blur-sm",children:e.jsxs("div",{className:"flex flex-col xl:flex-row items-center gap-3",children:[e.jsxs("div",{className:"relative flex-1 w-full group",children:[e.jsx(bt,{className:"absolute left-4 top-1/2 -translate-y-1/2 text-slate-400 group-focus-within:text-[#9956DE] transition-colors",size:16}),e.jsx(xe,{type:"text",placeholder:"Trace user identity, action strings, or operation details...",className:"pl-11 h-12 bg-white border-slate-200/60 rounded-2xl focus-visible:ring-[#9956DE]/20 focus-visible:border-[#9956DE] transition-all text-sm font-medium shadow-md shadow-slate-200/40",value:N,onChange:d=>v(d.target.value)})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 w-full xl:w-auto",children:[e.jsxs(J,{value:h,onValueChange:c,children:[e.jsx(ee,{className:"w-[200px] bg-white border border-slate-200 hover:border-[#9956DE] transition-all focus:ring-2 focus:ring-[#9956DE]/10 text-[10px] font-black uppercase tracking-widest text-slate-900 rounded-xl h-12 shadow-md shadow-slate-200/40 px-4",children:e.jsx("span",{className:"truncate",children:Q[h]||h})}),e.jsxs(se,{className:"rounded-xl border-slate-200",children:[e.jsx(C,{value:"All Categories",className:"font-bold",children:"All Categories"}),e.jsx(C,{value:"Auth",className:"font-bold",children:"Authentication"}),e.jsx(C,{value:"Data",className:"font-bold",children:"Data Operations"}),e.jsx(C,{value:"User",className:"font-bold",children:"User Management"}),e.jsx(C,{value:"System",className:"font-bold",children:"System Engine"}),e.jsx(C,{value:"Content",className:"font-bold",children:"Content Pipeline"})]})]}),e.jsxs(J,{value:x,onValueChange:f,children:[e.jsx(ee,{className:"w-[200px] bg-white border border-slate-200 hover:border-[#9956DE] transition-all focus:ring-2 focus:ring-[#9956DE]/10 text-[10px] font-black uppercase tracking-widest text-slate-900 rounded-xl h-12 shadow-md shadow-slate-200/40 px-4",children:e.jsx("span",{className:"truncate",children:U[x]||x})}),e.jsxs(se,{className:"rounded-xl border-slate-200",children:[e.jsx(C,{value:"All Severities",className:"font-bold",children:"All Severities"}),e.jsx(C,{value:"Info",className:"font-bold",children:"Information"}),e.jsx(C,{value:"Warning",className:"font-bold",children:"Warning"}),e.jsx(C,{value:"Error",className:"font-bold",children:"Error"}),e.jsx(C,{value:"Critical",className:"font-bold",children:"Critical"})]})]}),e.jsxs(J,{value:w,onValueChange:A,children:[e.jsx(ee,{className:"w-[200px] bg-white border border-slate-200 hover:border-[#9956DE] transition-all focus:ring-2 focus:ring-[#9956DE]/10 text-[10px] font-black uppercase tracking-widest text-slate-900 rounded-xl h-12 shadow-md shadow-slate-200/40 px-4",children:e.jsx("span",{className:"truncate",children:te[w]||w})}),e.jsxs(se,{className:"rounded-xl border-slate-200",children:[e.jsx(C,{value:"All Roles",className:"font-bold",children:"All Roles"}),e.jsx(C,{value:"Admin",className:"font-bold",children:"Administrator"}),e.jsx(C,{value:"Teacher",className:"font-bold",children:"Educator"}),e.jsx(C,{value:"Student",className:"font-bold",children:"Student"})]})]}),e.jsx(E,{variant:"outline",size:"icon",onClick:()=>{v(""),c("All Categories"),f("All Severities"),A("All Roles")},disabled:!N&&h==="All Categories"&&x==="All Severities"&&w==="All Roles",className:"h-12 w-12 rounded-2xl border-slate-200/60 text-[#9956DE] hover:bg-purple-50 disabled:opacity-30 disabled:cursor-not-allowed transition-all shadow-sm",title:"Reset Filters",children:e.jsx(yt,{size:18})})]})]})}),e.jsx("div",{className:"bg-white rounded-[32px] border border-slate-200/60 shadow-sm shadow-slate-200/40 relative",children:e.jsx("div",{className:"rounded-[32px]",children:e.jsxs("table",{className:"w-full text-left border-collapse min-w-[1000px]",children:[e.jsx("thead",{className:"sticky top-[80px] z-30 bg-[#f8fafc] backdrop-blur-sm shadow-[0_-12px_0_0_#f8fafc]",children:e.jsxs("tr",{className:"border-b border-[#8b5cf6]",children:[e.jsx("th",{className:"bg-[#9956DE] px-8 py-5 text-[11px] font-black text-white uppercase tracking-widest whitespace-nowrap rounded-tl-[20px]",children:"Incident Level"}),e.jsx("th",{className:"bg-[#9956DE] px-8 py-5 text-[11px] font-black text-white uppercase tracking-widest whitespace-nowrap",children:"Timestamp"}),e.jsx("th",{className:"bg-[#9956DE] px-8 py-5 text-[11px] font-black text-white uppercase tracking-widest",children:"User Actor"}),e.jsx("th",{className:"bg-[#9956DE] px-8 py-5 text-[11px] font-black text-white uppercase tracking-widest",children:"Action Performed"}),e.jsx("th",{className:"bg-[#9956DE] px-8 py-5 text-[11px] font-black text-white uppercase tracking-widest",children:"Component"}),e.jsx("th",{className:"bg-[#9956DE] px-8 py-5 text-[11px] font-black text-white uppercase tracking-widest text-right whitespace-nowrap rounded-tr-[20px]",children:"Review"})]})}),e.jsx("tbody",{className:"divide-y divide-slate-100",children:l?Array(10).fill(0).map((d,ae)=>e.jsx("tr",{children:e.jsx("td",{colSpan:6,className:"h-20 p-8",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-slate-50 animate-pulse"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"w-32 h-3 bg-slate-50 animate-pulse rounded"}),e.jsx("div",{className:"w-48 h-2 bg-slate-50 animate-pulse rounded"})]})]})})},ae)):ne.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:6,className:"h-64 text-center",children:e.jsxs("div",{className:"flex flex-col items-center justify-center",children:[e.jsx(As,{size:48,className:"text-slate-100 mb-4"}),e.jsx("p",{className:"text-[16px] font-black text-[#1e293b]",children:"No audit trails captured"}),e.jsx("p",{className:"text-[11px] font-bold text-slate-400 uppercase tracking-widest mt-1",children:"Try adjusting your tracking filters"})]})})}):ne.map(d=>e.jsxs("tr",{className:"group hover:bg-purple-50/20 transition-colors",children:[e.jsx("td",{className:"px-8 py-5",children:e.jsxs("span",{className:`inline-flex items-center gap-2 px-3 py-1.5 rounded-full text-[9px] font-black uppercase tracking-wider border ${X(d.severity)}`,children:[pe(d.severity),d.severity]})}),e.jsx("td",{className:"px-8 py-5",children:e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-slate-50 flex items-center justify-center text-slate-400",children:e.jsx(Rs,{size:14})}),e.jsx("span",{className:"text-[13px] font-bold text-[#1e293b]",children:d.timestamp})]})}),e.jsx("td",{className:"px-8 py-5",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-full bg-slate-50 border border-slate-100 flex items-center justify-center overflow-hidden shrink-0",children:d.user.avatar?e.jsx("img",{src:d.user.avatar,alt:d.user.name,className:"w-full h-full object-cover"}):e.jsx(As,{size:16,className:"text-slate-300"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-black text-[#1e293b] leading-none group-hover:text-[#9956DE] transition-colors truncate",children:d.user.name||"SYSTEM"}),e.jsx("p",{className:"text-[10px] font-bold text-slate-400 uppercase tracking-tighter mt-1",children:d.user.role||"System"})]})]})}),e.jsxs("td",{className:"px-8 py-5",children:[e.jsx("p",{className:"text-sm font-bold text-[#1e293b] truncate max-w-[250px]",title:d.details,children:d.action}),e.jsx("p",{className:"text-[10px] text-slate-400 font-medium truncate max-w-[250px] mt-0.5",children:d.details})]}),e.jsx("td",{className:"px-8 py-5",children:e.jsx("span",{className:"text-[10px] font-black px-2.5 py-1 rounded-lg bg-slate-50 text-slate-600 border border-slate-100 uppercase tracking-widest",children:d.category})}),e.jsx("td",{className:"px-8 py-5 text-right",children:e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{onClick:()=>y(d),className:"w-9 h-9 rounded-xl border border-slate-200 flex items-center justify-center text-slate-400 hover:text-[#9956DE] hover:border-[#9956DE]/30 hover:bg-purple-50 transition-all ",children:e.jsx(ft,{size:16})})})})]},d.id))})]})})}),e.jsxs("div",{className:"sticky bottom-0 z-50 flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 px-12 py-3 bg-white border-t-2 border-slate-100 shadow-[0_-8px_30px_rgba(0,0,0,0.08)] -mx-[24px] xl:-mx-[32px] w-[calc(100%+48px)] xl:w-[calc(100%+64px)]",children:[e.jsxs("p",{className:"text-[12px] font-black text-slate-500 uppercase tracking-widest flex items-center gap-4",children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-full bg-[#9956DE] animate-pulse shadow-[0_0_12px_rgba(153,86,222,0.6)]"}),"Showing ",e.jsxs("span",{className:"text-slate-900 font-black border-b-2 border-[#9956DE]/40 pb-0.5",children:[B,"–",ce]}),e.jsx("span",{className:"text-slate-300 font-bold mx-1",children:"/"}),e.jsx("span",{className:"text-slate-900 font-black border-b-2 border-[#9956DE]/40 pb-0.5",children:O.length}),e.jsx("span",{className:"text-slate-400 ml-1",children:"Total System Records"})]}),e.jsxs("div",{className:"flex items-center gap-6",children:[e.jsxs(J,{value:String(q),onValueChange:d=>{me(Number(d)),T(1)},children:[e.jsx(ee,{className:"h-10 w-[140px] bg-white border border-slate-300 text-[11px] font-black uppercase tracking-wider text-slate-900 rounded-xl hover:border-[#9956DE] transition-all px-4 shadow-sm",children:e.jsxs("span",{className:"truncate",children:[q," / Page"]})}),e.jsx(se,{className:"rounded-xl border-slate-200",children:tl.map(d=>e.jsxs(C,{value:String(d),className:"font-bold",children:[d," / Page"]},d))})]}),e.jsxs("div",{className:"flex items-center gap-2 bg-slate-50 p-1.5 rounded-2xl border border-slate-200 shadow-inner",children:[e.jsx(E,{variant:"outline",size:"sm",className:"h-9 w-9 p-0 rounded-xl bg-[#9956DE] border-none text-white hover:bg-[#8b5cf6] hover:scale-105 active:scale-95 disabled:opacity-30 transition-all shadow-lg shadow-purple-200/60",disabled:D<=1||l,onClick:()=>T(d=>Math.max(d-1,1)),children:e.jsx(jt,{size:18,strokeWidth:3})}),e.jsx("div",{className:"px-5 py-2 bg-white rounded-xl shadow-sm border border-slate-200 flex items-center justify-center min-w-[130px]",children:e.jsxs("span",{className:"text-[11px] font-black text-slate-900 uppercase tracking-widest",children:["Page ",e.jsx("span",{className:"text-[#9956DE] mx-1",children:D}),e.jsx("span",{className:"text-slate-300 mx-1",children:"OF"}),e.jsx("span",{className:"text-slate-500",children:Math.max(K,1)})]})}),e.jsx(E,{variant:"outline",size:"sm",className:"h-9 w-9 p-0 rounded-xl bg-[#9956DE] border-none text-white hover:bg-[#8b5cf6] hover:scale-105 active:scale-95 disabled:opacity-30 transition-all shadow-lg shadow-purple-200/60",disabled:D>=K||l,onClick:()=>T(d=>Math.min(d+1,K||1)),children:e.jsx(vt,{size:18,strokeWidth:3})})]})]})]}),e.jsx(ht,{open:!!u,onOpenChange:d=>{d||y(null)},children:e.jsxs(pt,{className:"sm:max-w-[600px] rounded-[32px] border-none shadow-2xl p-0 overflow-hidden",children:[e.jsx("div",{className:`h-2 w-full ${u?X(u.severity).split(" ")[0].replace("bg-","bg-").replace("-50","-500"):"bg-purple-600"}`}),e.jsxs("div",{className:"p-8 space-y-6",children:[e.jsx(ut,{className:"text-left",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"w-12 h-12 rounded-2xl bg-slate-50 flex items-center justify-center text-[#9956DE] border border-slate-100",children:e.jsx(zs,{size:24})}),e.jsxs("div",{children:[e.jsx(gt,{className:"text-xl font-black text-[#1e293b] leading-tight",children:u?.action||"Audit Event Details"}),e.jsx("p",{className:"text-[10px] font-black text-slate-400 uppercase tracking-[0.2em] mt-1",children:"Platform Operational Integrity Trail"})]})]})}),u&&e.jsxs("div",{className:"grid grid-cols-2 gap-6 bg-slate-50/50 p-6 rounded-2xl border border-slate-100",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[9px] font-black text-slate-400 uppercase tracking-widest",children:"Incident Severity"}),e.jsx("p",{className:"text-sm font-black text-[#1e293b]",children:u.severity})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[9px] font-black text-slate-400 uppercase tracking-widest",children:"Timestamp"}),e.jsx("p",{className:"text-sm font-black text-[#1e293b]",children:u.timestamp})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[9px] font-black text-slate-400 uppercase tracking-widest",children:"Component"}),e.jsx("p",{className:"text-sm font-black text-[#1e293b]",children:u.category})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[9px] font-black text-slate-400 uppercase tracking-widest",children:"User Actor"}),e.jsx("p",{className:"text-sm font-black text-[#1e293b]",children:u?.user.name})]}),e.jsxs("div",{className:"col-span-2 space-y-1 mt-2",children:[e.jsx("p",{className:"text-[9px] font-black text-slate-400 uppercase tracking-widest",children:"Full Operation Details"}),e.jsx("p",{className:"text-sm font-medium text-[#1e293b] leading-relaxed bg-white p-4 rounded-xl border border-slate-100",children:u.details})]})]}),e.jsx("div",{className:"flex justify-end pt-2",children:e.jsx(E,{onClick:()=>y(null),className:"bg-[#9956DE] hover:bg-[#8b5cf6] text-white rounded-xl px-8 font-black uppercase text-[11px] tracking-widest shadow-lg shadow-purple-100 transition-all",children:"Dismiss Review"})})]})]})})]})},ll=()=>{const[s,a]=r.useState([]),[n,i]=r.useState(0),[l,o]=r.useState(!0),[g,m]=r.useState(null),[N,v]=r.useState(!1),h=r.useCallback(async()=>{o(!0);try{const u=await De("/api/rag/documents");a(u.documents),i(u.total_chunks)}catch(u){console.error("Failed to fetch RAG documents:",u),S.error("Failed to load RAG inventory")}finally{o(!1)}},[]);r.useEffect(()=>{h()},[h]);const c=Ss.useMemo(()=>{const u=new Map;for(const y of s){const D=u.get(y.subject)||[];D.push(y),u.set(y.subject,D)}return Array.from(u.entries()).map(([y,D])=>({subject:y,files:D,totalChunks:D.reduce((T,q)=>T+q.chunk_count,0)}))},[s]),x=async u=>{m(`subject:${u}`);try{const y=await De(`/api/rag/documents/by-subject/${encodeURIComponent(u)}`,{method:"DELETE"});S.success(y.message),await h()}catch(y){S.error(`Failed to delete subject: ${y}`)}finally{m(null)}},f=async u=>{m(`source:${u}`);try{const y=await De(`/api/rag/documents/by-source?source_file=${encodeURIComponent(u)}`,{method:"DELETE"});S.success(y.message),await h()}catch(y){S.error(`Failed to delete source: ${y}`)}finally{m(null)}},w=async()=>{m("purge");try{const u=await De("/api/rag/documents/all",{method:"DELETE"});S.success(u.message),v(!1),await h()}catch(u){S.error(`Purge failed: ${u}`)}finally{m(null)}},A=async()=>{m("reingest");try{await De("/api/admin/reingest-pdf",{method:"POST",body:JSON.stringify({})}),S.success("Re-ingestion triggered. This may take a few minutes."),setTimeout(h,5e3)}catch(u){S.error(`Re-ingestion failed: ${u}`)}finally{m(null)}};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-indigo-100 flex items-center justify-center",children:e.jsx(fe,{className:"w-5 h-5 text-indigo-600"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-bold text-slate-800",children:"RAG Pipeline Manager"}),e.jsx("p",{className:"text-sm text-slate-500",children:"Manage vectorstore content and uploaded files"})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"px-4 py-2 bg-indigo-50 rounded-xl text-center",children:[e.jsx("p",{className:"text-xl font-bold text-indigo-600",children:n}),e.jsx("p",{className:"text-[10px] font-bold text-indigo-400 uppercase",children:"Total Chunks"})]}),e.jsxs("div",{className:"px-4 py-2 bg-emerald-50 rounded-xl text-center",children:[e.jsx("p",{className:"text-xl font-bold text-emerald-600",children:c.length}),e.jsx("p",{className:"text-[10px] font-bold text-emerald-400 uppercase",children:"Subjects"})]})]})]}),e.jsxs("div",{className:"flex items-center gap-3 p-4 bg-slate-50 rounded-2xl border border-slate-200",children:[e.jsxs(E,{onClick:h,disabled:l,variant:"outline",className:"gap-2",children:[e.jsx(Me,{size:14,className:l?"animate-spin":""}),"Refresh"]}),e.jsxs(E,{onClick:A,disabled:!!g,variant:"outline",className:"gap-2",children:[g==="reingest"?e.jsx(V,{size:14,className:"animate-spin"}):e.jsx(Me,{size:14}),"Re-ingest All PDFs"]}),e.jsx("div",{className:"flex-1"}),N?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-sm text-red-600 font-medium flex items-center gap-1",children:[e.jsx(xt,{size:14})," This will delete ALL RAG content"]}),e.jsxs(E,{onClick:w,disabled:g==="purge",className:"bg-red-600 hover:bg-red-700 text-white gap-2",children:[g==="purge"?e.jsx(V,{size:14,className:"animate-spin"}):e.jsx(je,{size:14}),"Confirm Purge"]}),e.jsx(E,{onClick:()=>v(!1),variant:"outline",children:"Cancel"})]}):e.jsxs(E,{onClick:()=>v(!0),variant:"outline",className:"gap-2 text-red-600 border-red-200 hover:bg-red-50",children:[e.jsx(je,{size:14}),"Purge All"]})]}),l?e.jsx("div",{className:"flex items-center justify-center py-16",children:e.jsx(V,{size:32,className:"animate-spin text-indigo-500"})}):c.length===0?e.jsxs("div",{className:"text-center py-16 text-slate-500",children:[e.jsx(fe,{size:48,className:"mx-auto mb-3 text-slate-300"}),e.jsx("p",{className:"font-medium",children:"No RAG content found"}),e.jsx("p",{className:"text-sm",children:"Upload PDFs via the Content tab or trigger re-ingestion"})]}):e.jsx("div",{className:"space-y-4",children:c.map(u=>e.jsxs(re.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:"bg-white rounded-2xl border border-slate-200 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-4 bg-slate-50 border-b border-slate-100",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-indigo-100 flex items-center justify-center",children:e.jsx(Ce,{size:16,className:"text-indigo-600"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-bold text-slate-800 capitalize",children:u.subject.replace(/_/g," ")}),e.jsxs("p",{className:"text-xs text-slate-500",children:[u.totalChunks," chunks • ",u.files.length," source file",u.files.length!==1?"s":""]})]})]}),e.jsxs(E,{onClick:()=>x(u.subject),disabled:!!g,variant:"outline",className:"gap-2 text-red-600 border-red-200 hover:bg-red-50 text-xs h-8",children:[g===`subject:${u.subject}`?e.jsx(V,{size:12,className:"animate-spin"}):e.jsx(je,{size:12}),"Remove Subject"]})]}),e.jsx("div",{className:"divide-y divide-slate-100",children:u.files.map(y=>e.jsxs("div",{className:"flex items-center justify-between px-5 py-3 hover:bg-slate-50 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Ce,{size:14,className:"text-slate-400"}),e.jsx("span",{className:"text-sm text-slate-700 font-medium truncate max-w-[400px]",children:y.source_file}),e.jsxs("span",{className:"text-xs text-slate-400 bg-slate-100 px-2 py-0.5 rounded-full",children:[y.chunk_count," chunks"]})]}),e.jsx("button",{onClick:()=>f(y.source_file),disabled:!!g,className:"p-1.5 rounded-lg text-slate-400 hover:text-red-500 hover:bg-red-50 transition-colors disabled:opacity-50",children:g===`source:${y.source_file}`?e.jsx(V,{size:14,className:"animate-spin"}):e.jsx(je,{size:14})})]},y.source_file))})]},u.subject))})]})};function as({className:s,...a}){return e.jsx(ia,{"data-slot":"checkbox",className:Te("peer border bg-input-background dark:bg-input/30 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=checked]:border-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive size-4 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",s),...a,children:e.jsx(na,{"data-slot":"checkbox-indicator",className:"flex items-center justify-center text-current transition-none",children:e.jsx(ca,{className:"size-3.5"})})})}const rl=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,il=/[A-Z]/,nl=/[a-z]/,cl=/\d/,ol=/[^A-Za-z0-9]/;function dl(s){const a={};s.name.trim()||(a.name="Name is required.");const n=s.email.trim().toLowerCase();n?rl.test(n)||(a.email="Enter a valid email address."):a.email="Email is required.";const i=s.password;return i.length<8?a.password="Password must be at least 8 characters.":il.test(i)?nl.test(i)?cl.test(i)?ol.test(i)||(a.password="Password must include at least one special character."):a.password="Password must include at least one number.":a.password="Password must include at least one lowercase letter.":a.password="Password must include at least one uppercase letter.",s.confirmPassword?s.confirmPassword!==i&&(a.confirmPassword="Passwords do not match."):a.confirmPassword="Confirm password is required.",s.role.trim()||(a.role="Role is required."),s.status.trim()||(a.status="Status is required."),s.grade.trim()||(a.grade="Grade is required."),s.section.trim()||(a.section="Section is required."),s.role.trim().toLowerCase()==="student"&&!s.lrn.trim()&&(a.lrn="LRN is required for student accounts."),a}function xl(s){return Object.values(s).find(n=>!!n)??null}const at=(s="Student")=>({name:"",email:"",password:"",confirmPassword:"",role:s,status:"Active",department:s==="Teacher"?"Mathematics":s==="Admin"?"System":"",grade:"",section:"",lrn:""}),ml=["10","25","50","100"];function ks(s,a){const n=s.trim();if(!(!n||n===a))return n}function lt(s){const a=String(s??"");return/[",\n]/.test(a)?`"${a.replace(/"/g,'""')}"`:a}const hl=({createIntentRole:s=null,onCreateIntentConsumed:a})=>{const{userProfile:n}=cs(),[i,l]=r.useState([]),[o,g]=r.useState(!0),[m,N]=r.useState(null),[v,h]=r.useState(!1),[c,x]=r.useState(!1),[f,w]=r.useState(null),[A,u]=r.useState(1),[y,D]=r.useState(25),[T,q]=r.useState(0),[me,he]=r.useState(1),[Ne,_]=r.useState(!1),[pe,X]=r.useState(""),[Q,U]=r.useState("All Roles"),[te,O]=r.useState("All Status"),[K,ne]=r.useState("All Sections"),[B,ce]=r.useState(new Set),[d,ae]=r.useState(!1),[p,P]=r.useState(new Set),[H,Y]=r.useState({}),[G,Qe]=r.useState("Student"),[Oe,k]=r.useState("Active"),[$,oe]=r.useState("Grade 11"),[Ae,Ts]=r.useState(""),[ds,Ee]=r.useState(!1),[xs,Be]=r.useState(!1),[$e,Xe]=r.useState(!1),[le,ms]=r.useState(null),[W,$s]=r.useState(null),[hs,Ke]=r.useState({}),[ps,Ye]=r.useState(!1),[Cl,us]=r.useState(!1),[j,de]=r.useState(at()),I=r.useMemo(()=>({search:pe.trim()||void 0,role:ks(Q,"All Roles"),status:ks(te,"All Status"),section:ks(K,"All Sections")}),[pe,Q,te,K]),ue=r.useCallback(()=>{ce(new Set),ae(!1),P(new Set)},[]),Ze=r.useCallback(t=>d?!p.has(t):B.has(t),[d,p,B]),Z=r.useMemo(()=>d?Math.max(T-p.size,0):B.size,[d,p,B,T]),Ls=r.useMemo(()=>i.length===0?!1:i.every(t=>Ze(t.id)),[i,Ze]),be=r.useMemo(()=>d?[]:Array.from(B).map(t=>H[t]).filter(t=>!!t),[d,B,H]);r.useMemo(()=>Z===0?!1:d?!I.role||I.role.toLowerCase()==="student":be.length!==B.size?!1:be.every(t=>t.role==="Student"),[d,Z,be,B.size,I.role]),r.useMemo(()=>Z===0?!1:d?I.status?.toLowerCase()!=="active":be.length!==B.size?!1:be.some(t=>t.status!=="Active"),[d,Z,be,B.size,I.status]),r.useMemo(()=>Z===0?!1:d?I.status?.toLowerCase()!=="inactive":be.length!==B.size?!1:be.some(t=>t.status!=="Inactive"),[d,Z,be,B.size,I.status]);const ye=r.useCallback(async t=>{g(!0),N(null);try{const b=await qa({page:t,pageSize:y,searchQuery:I.search,roleFilter:I.role,statusFilter:I.status});l(b.users),u(b.total===0?1:b.page),q(b.total),he(b.totalPages||1),_(b.hasNextPage),Y(R=>{const ke={...R};return b.users.forEach(z=>{ke[z.id]=z}),ke})}catch(b){const R=b instanceof Error?b.message:"Failed to load users";N(R),S.error(R)}finally{g(!1)}},[y,I.search,I.role,I.status]);r.useEffect(()=>{ye(A)},[ye,A]);const Us=r.useMemo(()=>{const t=new Set;return i.forEach(b=>{b.section&&t.add(b.section)}),Array.from(t).sort()},[i]),gs=r.useMemo(()=>I.section?i.filter(t=>t.section===I.section):i,[i,I.section]),bs=r.useCallback((t="Student")=>{$s(null),Ke({}),Ye(!1),us(!1),de(at(t)),Ee(!0)},[]);r.useEffect(()=>{s&&(bs(s),a?.())},[s,bs,a]);const Is=r.useCallback(t=>{if(d){P(b=>{const R=new Set(b);return R.has(t)?R.delete(t):R.add(t),R});return}ce(b=>{const R=new Set(b);return R.has(t)?R.delete(t):R.add(t),R})},[d]),Fs=r.useCallback(()=>{if(i.length===0)return;const t=gs.map(b=>b.id);if(d){P(b=>{const R=new Set(b);return t.every(z=>!R.has(z))?t.forEach(z=>R.add(z)):t.forEach(z=>R.delete(z)),R});return}ce(b=>{const R=new Set(b);return t.every(z=>R.has(z))?t.forEach(z=>R.delete(z)):t.forEach(z=>R.add(z)),R})},[i,d]),zt=r.useCallback(()=>{ae(!0),ce(new Set),P(new Set)},[]),_s=r.useCallback(t=>{if(!t.length){S.info("No rows were returned for export.");return}const b=Array.from(t.reduce((Je,vs)=>(Object.keys(vs).forEach(Ft=>Je.add(Ft)),Je),new Set)),R=[b.map(lt).join(","),...t.map(Je=>b.map(vs=>lt(Je[vs])).join(","))].join(` | |
| `),ke=new Blob([R],{type:"text/csv;charset=utf-8;"}),z=URL.createObjectURL(ke),js=document.createElement("a");js.href=z,js.download=`admin-users-export-${Date.now()}.csv`,js.click(),URL.revokeObjectURL(z)},[]),ze=r.useCallback(async(t,b)=>{const R=b.userIds,ke={...I.search?{search:I.search}:{},...I.role?{role:I.role}:{},...I.status?{status:I.status}:{}};if(!R&&Z===0){S.error("Select at least one user before applying a bulk action.");return}x(!0);try{const z=await Va({action:t,...R?{userIds:R}:d?{userIds:[],excludeUserIds:Array.from(p),filters:ke}:{userIds:Array.from(B)},...b.role?{role:b.role}:{},...b.status?{status:b.status}:{},...b.grade?{grade:b.grade}:{},...b.section?{section:b.section}:{},...b.exportFormat?{exportFormat:b.exportFormat}:{}});t==="export"&&_s(z.exportRows),z.summary.failed>0?S.warning(`Completed with partial failures. ${z.summary.succeeded} succeeded, ${z.summary.failed} failed, ${z.summary.skipped} skipped.`):z.summary.succeeded===0&&z.summary.targeted>0?S.error(z.summary.skipped>0?`Action skipped for ${z.summary.skipped} user(s).`:"Action could not be completed. No users were updated."):S.success(`Action completed. ${z.summary.succeeded} user(s) updated.`),z.warnings.length>0&&S.info(z.warnings[0]);try{await ys(b.auditAction,"User",t==="delete"||t==="deactivate"?"Warning":"Info",`${b.auditDetail}; targeted=${z.summary.targeted}, succeeded=${z.summary.succeeded}, failed=${z.summary.failed}, skipped=${z.summary.skipped}`,{name:n?.name||"Admin",role:"Admin",avatar:n?.photo||null})}catch{}b.skipSelectionReset||ue(),await ye(A)}catch(z){S.error(z instanceof Error?z.message:"Bulk action failed")}finally{x(!1)}},[I.search,I.role,I.status,d,p,B,Z,n?.name,n?.photo,ue,ye,A,_s]),fs=r.useCallback(t=>{ms(t),Be(!0)},[]),Dt=r.useCallback(async()=>{if(!(!le||$e)){Xe(!0);try{await ze(le.action,{...le.params||{},auditAction:le.auditAction,auditDetail:le.auditDetail}),Be(!1),ms(null)}finally{Xe(!1)}}},[le,$e,ze]),Os=t=>{$s(t),Ke({}),Ye(!1),us(!1),de({name:t.name,email:t.email,password:"",confirmPassword:"",role:t.role,status:t.status,department:t.department,grade:t.grade||"Grade 11",section:t.section||"",lrn:t.lrn||""}),Ee(!0)},Pt=async()=>{if(!j.name.trim()||!j.email.trim()){S.error("Name and email are required");return}if(!W){const t=dl({name:j.name,email:j.email,password:j.password,confirmPassword:j.confirmPassword,role:j.role,status:j.status,grade:j.grade,section:j.section,lrn:j.lrn}),b=xl(t);if(b){Ke(t),S.error(b);return}}h(!0);try{if(W){const t={name:j.name,role:j.role,status:j.status,grade:j.grade,section:j.section,lrn:j.role==="Student"?j.lrn:void 0};j.role!=="Student"&&(t.department=j.department),await Ha(W.id,t),await ys("User Updated","User","Info",`Updated user: ${j.name} (${W.email})`,{name:n?.name||"Admin",role:"Admin",avatar:n?.photo||null}),S.success("User updated successfully")}else{const t=await Wa({email:j.email,name:j.name,password:j.password,confirmPassword:j.confirmPassword,role:j.role,status:j.status,grade:j.grade,section:j.section,lrn:j.role==="Student"?j.lrn:void 0});await ys("Created New User","User","Info",`Created new ${j.role.toLowerCase()} account: ${j.name} (${j.email}), emailSent=${t.emailSent}`,{name:n?.name||"Admin",role:"Admin",avatar:n?.photo||null}),t.emailSent?S.success("User created and welcome email sent"):(S.warning("User created, but welcome email failed to send"),t.emailError?.message&&S.error(t.emailError.message))}W?await ye(A):(ue(),u(1),await ye(1)),Ee(!1),Ye(!1),us(!1)}finally{h(!1)}},Bs=(t,b)=>{fs({title:"Delete User?",message:`Delete user "${b}"? This cannot be undone.`,confirmText:"Delete",action:"delete",params:{userIds:[t]},auditAction:"User Deleted",auditDetail:`Deleted user account: ${b}`})},Gs=async t=>{if(f||c)return;if(t.status==="Active"){fs({title:"Deactivate User?",message:`Deactivate "${t.name}"? They will lose access until reactivated.`,confirmText:"Deactivate",action:"deactivate",params:{userIds:[t.id]},auditAction:"User Status Changed",auditDetail:`Deactivated user: ${t.email}`});return}w(t.id);try{await ze("activate",{userIds:[t.id],auditAction:"User Status Changed",auditDetail:`Activated user: ${t.email}`,skipSelectionReset:!0})}finally{w(null)}},Rt=async()=>{await ze("change_role",{role:G,auditAction:"Bulk Role Update",auditDetail:`Updated selected users to role ${G}`})},Mt=async()=>{await ze("change_status",{status:Oe,auditAction:"Bulk Status Update",auditDetail:`Updated selected users to status ${Oe}`})},Tt=async()=>{await ze("reset_password_email",{auditAction:"Bulk Password Reset",auditDetail:"Sent password reset emails to selected users"})},$t=async()=>{await ze("export",{exportFormat:"csv",auditAction:"Bulk Export Users",auditDetail:"Exported selected users"})},Lt=()=>{fs({title:"Delete Selected Users?",message:`Delete ${Z} selected user(s)? This action cannot be undone.`,confirmText:"Delete Users",action:"delete",auditAction:"Bulk User Deletion",auditDetail:`Deleted ${Z} selected users`})};i.filter(t=>t.status==="Active").length,i.filter(t=>t.role==="Admin").length,i.filter(t=>t.role==="Teacher").length,i.filter(t=>t.role==="Student").length;const Ut=T===0?0:(A-1)*y+1,It=T===0?0:Math.min(A*y,T);return e.jsxs("div",{className:"flex flex-col animate-in fade-in duration-500",children:[e.jsx("div",{className:"space-y-8 pt-6 xl:pt-8 pb-6 px-1",children:e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 md:grid-cols-5 gap-4",children:o&&i.length===0?Array.from({length:5}).map((t,b)=>e.jsxs("div",{className:"bg-white p-5 rounded-[28px] border border-slate-200/60 shadow-sm shadow-slate-200/50 animate-pulse",children:[e.jsx("div",{className:"h-4 w-20 bg-slate-100 rounded-full mb-3"}),e.jsx("div",{className:"h-8 w-12 bg-slate-100 rounded-lg"})]},`stats-skeleton-${b}`)):[{label:"Total Users",value:T,icon:Pe,bg:"bg-[#4f46e5]",shadow:"shadow-indigo-500/20"},{label:"Active Today",value:i.filter(t=>t.status==="Active").length,icon:qe,bg:"bg-[#10b981]",shadow:"shadow-emerald-500/20"},{label:"Admins",value:i.filter(t=>t.role==="Admin").length,icon:As,bg:"bg-[#0ea5e9]",shadow:"shadow-sky-500/20"},{label:"Teachers",value:i.filter(t=>t.role==="Teacher").length,icon:is,bg:"bg-[#8b5cf6]",shadow:"shadow-purple-500/20"},{label:"Students",value:i.filter(t=>t.role==="Student").length,icon:nt,bg:"bg-[#3b82f6]",shadow:"shadow-blue-500/20"}].map((t,b)=>e.jsxs("div",{className:`relative overflow-hidden ${t.bg} ${t.shadow} p-5 rounded-[28px] text-white flex flex-col gap-3 group hover:scale-[1.02] transition-all duration-300 shadow-lg`,children:[e.jsx("div",{className:"absolute -right-4 -bottom-4 w-24 h-24 rounded-full bg-white/10 group-hover:scale-[1.6] transition-transform duration-700 ease-out"}),e.jsx("div",{className:"absolute -left-4 -top-4 w-12 h-12 rounded-full bg-white/10 group-hover:scale-[1.4] transition-transform duration-700 delay-75 ease-out"}),e.jsxs("div",{className:"relative z-10 flex items-center justify-between",children:[e.jsx("p",{className:"text-[10px] font-black uppercase tracking-[0.2em] opacity-80",children:t.label}),e.jsx("div",{className:"bg-white/20 p-2 rounded-xl backdrop-blur-sm group-hover:bg-white/30 transition-colors",children:e.jsx(t.icon,{size:14})})]}),e.jsx("h3",{className:"relative z-10 text-3xl font-display font-black leading-none tracking-tight",children:t.value})]},b))})}),e.jsx("div",{className:"sticky top-0 z-40 -mx-[24px] xl:-mx-[32px] px-[24px] xl:px-[32px] pt-4 pb-4 bg-[#f8fafc] backdrop-blur-sm",children:e.jsxs("div",{className:"flex flex-col xl:flex-row items-center gap-3",children:[e.jsxs("div",{className:"relative flex-1 w-full group",children:[e.jsx(bt,{className:"absolute left-4 top-1/2 -translate-y-1/2 text-slate-400 group-focus-within:text-indigo-500 transition-colors",size:16}),e.jsx(xe,{placeholder:"Search by name, email, or LRN...",className:"pl-11 h-12 bg-white border-slate-200/60 rounded-2xl focus-visible:ring-indigo-500/20 focus-visible:border-indigo-500 transition-all text-sm font-medium shadow-md shadow-slate-200/40",value:pe,onChange:t=>{X(t.target.value),u(1),ue()}})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 w-full xl:w-auto",children:[e.jsxs(J,{value:Q,onValueChange:t=>{U(t),u(1),ue()},children:[e.jsx(ee,{className:"w-[180px] h-12 rounded-xl bg-white border border-slate-200 hover:border-[#9956DE] transition-all focus:ring-2 focus:ring-[#9956DE]/10 text-[10px] font-black uppercase tracking-widest text-slate-900 shadow-md shadow-slate-200/40 px-4",children:e.jsx("span",{className:"truncate",children:Q==="All Roles"?"All Roles":Q==="Admin"?"Administrator":Q==="Teacher"?"Educator":Q})}),e.jsxs(se,{className:"rounded-xl border-slate-200",children:[e.jsx(C,{value:"All Roles",className:"font-bold uppercase tracking-widest text-[10px]",children:"All Roles"}),e.jsx(C,{value:"Admin",className:"font-bold uppercase tracking-widest text-[10px]",children:"Administrator"}),e.jsx(C,{value:"Teacher",className:"font-bold uppercase tracking-widest text-[10px]",children:"Educator"}),e.jsx(C,{value:"Student",className:"font-bold uppercase tracking-widest text-[10px]",children:"Student"})]})]}),e.jsxs(J,{value:te,onValueChange:t=>{O(t),u(1),ue()},children:[e.jsx(ee,{className:"w-[180px] h-12 rounded-xl bg-white border border-slate-200 hover:border-[#9956DE] transition-all focus:ring-2 focus:ring-[#9956DE]/10 text-[10px] font-black uppercase tracking-widest text-slate-900 shadow-md shadow-slate-200/40 px-4",children:e.jsx("span",{className:"truncate",children:te==="All Status"?"All Statuses":te})}),e.jsxs(se,{className:"rounded-xl border-slate-200",children:[e.jsx(C,{value:"All Status",className:"font-bold uppercase tracking-widest text-[10px]",children:"All Statuses"}),e.jsx(C,{value:"Active",className:"font-bold uppercase tracking-widest text-[10px]",children:"Active"}),e.jsx(C,{value:"Inactive",className:"font-bold uppercase tracking-widest text-[10px]",children:"Inactive"})]})]}),Us.length>0&&e.jsxs(J,{value:K,onValueChange:t=>{ne(t),ue()},children:[e.jsx(ee,{className:"w-[180px] h-12 rounded-xl bg-white border border-slate-200 hover:border-[#9956DE] transition-all focus:ring-2 focus:ring-[#9956DE]/10 text-[10px] font-black uppercase tracking-widest text-slate-900 shadow-md shadow-slate-200/40 px-4",children:e.jsx("span",{className:"truncate",children:K==="All Sections"?"All Sections":K})}),e.jsxs(se,{className:"rounded-xl border-slate-200",children:[e.jsx(C,{value:"All Sections",className:"font-bold uppercase tracking-widest text-[10px]",children:"All Sections"}),Us.map(t=>e.jsx(C,{value:t,className:"font-bold uppercase tracking-widest text-[10px]",children:t},t))]})]})]}),e.jsx(E,{variant:"outline",size:"icon",onClick:()=>{X(""),U("All Roles"),O("All Status"),ne("All Sections"),u(1),ue()},disabled:!pe&&Q==="All Roles"&&te==="All Status",className:"h-12 w-12 rounded-xl border-slate-200 text-[#9956DE] hover:bg-purple-50 disabled:opacity-30 disabled:cursor-not-allowed transition-all shadow-md shadow-slate-200/40",title:"Reset Filters",children:e.jsx(yt,{size:18})}),e.jsx(E,{variant:"outline",size:"icon",className:"h-12 w-12 rounded-xl border-slate-200 text-slate-500 hover:bg-slate-50 transition-all shadow-md shadow-slate-200/40",onClick:()=>ye(A),disabled:o||c,children:e.jsx(Me,{size:18,className:o?"animate-spin":""})}),e.jsxs(E,{className:"h-12 gap-2 bg-[#9956DE] hover:bg-[#8b5cf6] text-white rounded-xl shadow-lg shadow-purple-200/50 transition-all px-6 font-black uppercase text-[11px] tracking-widest",onClick:()=>bs(),disabled:c,children:[e.jsx(qt,{size:18}),"Add User"]})]})}),Z>0&&e.jsxs("div",{className:"fixed bottom-16 left-1/2 -translate-x-1/2 z-[60] w-[calc(100%-4rem)] max-w-[1100px] bg-[#2d1b69] rounded-2xl p-3 flex flex-col xl:flex-row items-center gap-4 animate-in slide-in-from-bottom-2 duration-300 shadow-2xl shadow-purple-900/50",children:[e.jsxs("div",{className:"flex items-center gap-3 px-3 border-r border-white/10 pr-6",children:[e.jsx("div",{className:"w-8 h-8 rounded-xl bg-purple-500/30 flex items-center justify-center text-white font-black text-xs",children:Z}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] font-black text-purple-300 uppercase tracking-widest leading-none",children:"Selected"}),e.jsx("p",{className:"text-[9px] text-white/60 font-medium mt-1",children:d?"All matching users":`${Z} users chosen`})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-1 bg-white/5 p-1 rounded-xl",children:[e.jsxs(J,{value:G,onValueChange:t=>Qe(t),children:[e.jsx(ee,{className:"h-8 bg-transparent border-none text-white text-[10px] font-bold min-w-[90px] focus:ring-0",children:e.jsx(Ue,{})}),e.jsxs(se,{className:"rounded-xl",children:[e.jsx(C,{value:"Student",children:"Student"}),e.jsx(C,{value:"Teacher",children:"Teacher"}),e.jsx(C,{value:"Admin",children:"Admin"})]})]}),e.jsx(E,{size:"sm",className:"h-8 bg-purple-600 hover:bg-purple-500 text-[10px] font-black rounded-lg",onClick:()=>void Rt(),children:"Apply Role"})]}),e.jsxs("div",{className:"flex items-center gap-1 bg-white/5 p-1 rounded-xl",children:[e.jsxs(J,{value:Oe,onValueChange:t=>k(t),children:[e.jsx(ee,{className:"h-8 bg-transparent border-none text-white text-[10px] font-bold min-w-[90px] focus:ring-0",children:e.jsx(Ue,{})}),e.jsxs(se,{className:"rounded-xl",children:[e.jsx(C,{value:"Active",children:"Active"}),e.jsx(C,{value:"Inactive",children:"Inactive"})]})]}),e.jsx(E,{size:"sm",className:"h-8 bg-purple-600 hover:bg-purple-500 text-[10px] font-black rounded-lg",onClick:()=>void Mt(),children:"Set Status"})]}),e.jsx("div",{className:"h-6 w-[1px] bg-white/10 mx-1"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(E,{size:"sm",variant:"ghost",className:"h-9 text-white hover:bg-white/10 text-[10px] font-black uppercase tracking-widest gap-2",onClick:()=>void Tt(),children:[e.jsx(oa,{size:14})," Reset Pass"]}),e.jsxs(E,{size:"sm",variant:"ghost",className:"h-9 text-white hover:bg-white/10 text-[10px] font-black uppercase tracking-widest gap-2",onClick:()=>void $t(),children:[e.jsx(Ps,{size:14})," Export"]}),e.jsxs(E,{size:"sm",variant:"ghost",className:"h-9 text-rose-400 hover:bg-rose-500/10 hover:text-rose-300 text-[10px] font-black uppercase tracking-widest gap-2",onClick:Lt,children:[e.jsx(je,{size:14})," Delete"]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 pl-4 border-l border-white/10",children:[!d&&Z<T&&e.jsxs(E,{variant:"ghost",className:"h-9 text-indigo-200 hover:text-white hover:bg-white/10 text-[10px] font-black uppercase tracking-widest",onClick:zt,children:["Select All ",T]}),e.jsx(E,{size:"icon",variant:"ghost",className:"h-9 w-9 text-white/40 hover:text-white hover:bg-white/10 rounded-xl",onClick:ue,children:e.jsx(ss,{size:16,className:"rotate-45"})})]})]}),m?e.jsxs("div",{className:"rounded-xl border border-red-200 bg-red-50 px-4 py-3 flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex items-start gap-2 min-w-0",children:[e.jsx(Re,{size:18,className:"text-red-600 mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-semibold text-red-700",children:"Unable to load users"}),e.jsx("p",{className:"text-sm text-red-600 break-words",children:m})]})]}),e.jsx(E,{type:"button",variant:"outline",className:"border-red-200 text-red-700 hover:bg-red-100",onClick:()=>ye(A),disabled:o||c,children:"Retry"})]}):null,e.jsxs("div",{className:"bg-white rounded-[32px] border border-slate-200/60 shadow-sm shadow-slate-200/50 relative",children:[o&&i.length>0&&e.jsx("div",{className:"absolute inset-0 bg-white/40 backdrop-blur-[1px] z-20 flex items-center justify-center",children:e.jsx(V,{className:"animate-spin text-indigo-500",size:32})}),e.jsxs("div",{className:"md:hidden divide-y divide-slate-100",children:[e.jsxs("div",{className:"px-6 py-4 bg-slate-50/50 border-b border-slate-100 flex items-center justify-between",children:[e.jsxs("label",{className:"flex items-center gap-3 text-[10px] font-black text-slate-400 uppercase tracking-widest cursor-pointer",children:[e.jsx(as,{checked:Ls,onCheckedChange:Fs,className:"rounded-md border-slate-300"}),"Select Page"]}),e.jsxs("span",{className:"text-[10px] font-black text-slate-400 uppercase tracking-widest",children:["Page ",A," of ",me]})]}),o&&i.length===0?e.jsx("div",{className:"px-6 py-12 text-center text-slate-400 font-medium",children:"Loading users..."}):i.length>0?gs.map(t=>(t.id,e.jsxs("div",{className:"p-5 space-y-4 group hover:bg-slate-50/50 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"flex items-center self-center",children:e.jsx(as,{checked:Ze(t.id),onCheckedChange:()=>Is(t.id),className:"rounded-md border-slate-300"})}),e.jsxs("div",{className:"relative",children:[e.jsxs(Hs,{className:"h-12 w-12 rounded-full border-2 border-white shadow-sm",children:[e.jsx(Ws,{src:t.photo||Cs(t.gender),className:"object-cover"}),e.jsx(Vs,{className:"bg-indigo-50 text-indigo-600 font-bold",children:t.name.charAt(0)})]}),e.jsx("div",{className:`absolute -bottom-1 -right-1 w-4 h-4 rounded-full border-2 border-white shadow-sm ${t.status==="Active"?"bg-emerald-500":"bg-slate-300"}`})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-black text-[#1e293b] truncate text-sm",children:t.name}),e.jsx("p",{className:"text-[11px] font-medium text-slate-400 truncate mt-0.5",children:t.email})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("span",{className:`text-[9px] font-black uppercase tracking-widest px-2 py-1 rounded-lg ${t.role==="Admin"?"bg-sky-50 text-sky-600":t.role==="Teacher"?"bg-purple-50 text-purple-600":"bg-blue-50 text-blue-600"}`,children:t.role}),e.jsxs("span",{className:"text-[9px] font-black uppercase tracking-widest px-2 py-1 rounded-lg bg-slate-50 text-slate-500",children:[t.grade," • ",t.section||t.department]})]}),e.jsxs("div",{className:"flex items-center gap-2 pt-2",children:[e.jsxs(E,{variant:"outline",size:"sm",className:"flex-1 h-9 rounded-xl border-slate-200 text-slate-600 font-bold text-xs gap-2",onClick:()=>Os(t),children:[e.jsx(ss,{size:14})," Edit"]}),e.jsxs(E,{variant:"outline",size:"sm",className:`flex-1 h-9 rounded-xl border-slate-200 font-bold text-xs gap-2 ${t.status==="Active"?"text-slate-600":"text-emerald-600"}`,onClick:()=>Gs(t),disabled:f===t.id||c,children:[f===t.id?e.jsx(V,{size:14,className:"animate-spin"}):t.status==="Active"?e.jsx(st,{size:14}):e.jsx(qe,{size:14}),t.status==="Active"?"Ban":"Active"]}),e.jsx(E,{variant:"outline",size:"icon",className:"h-9 w-9 rounded-xl border-slate-200 text-rose-500 hover:bg-rose-50 hover:border-rose-100",onClick:()=>Bs(t.id,t.name),disabled:c,children:e.jsx(je,{size:14})})]})]},`mobile-${t.id}`))):e.jsxs("div",{className:"px-6 py-20 text-center space-y-4",children:[e.jsx("div",{className:"w-20 h-20 bg-slate-50 rounded-full flex items-center justify-center mx-auto",children:e.jsx(Pe,{size:32,className:"text-slate-300"})}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"font-black text-slate-600 uppercase tracking-widest text-sm",children:"No Users Found"}),e.jsx("p",{className:"text-xs text-slate-400 font-medium max-w-[200px] mx-auto leading-relaxed",children:"We couldn't find any users matching your current filters. Try adjusting your search."})]}),e.jsx(E,{variant:"outline",size:"sm",className:"rounded-xl border-slate-200 text-indigo-600 font-bold",onClick:()=>{X(""),U("All Roles"),O("All Status")},children:"Clear Filters"})]})]}),e.jsx("div",{className:"hidden md:block",children:e.jsxs("table",{className:"w-full text-left border-collapse",children:[e.jsx("thead",{className:"sticky top-[80px] z-30 bg-[#f8fafc] backdrop-blur-sm shadow-[0_-12px_0_0_#f8fafc]",children:e.jsxs("tr",{className:"border-b border-[#8b5cf6]",children:[e.jsx("th",{className:"bg-[#9956DE] px-6 py-4 w-[60px] rounded-tl-[20px]",children:e.jsx(as,{checked:Ls,onCheckedChange:Fs,className:"rounded-md border-white/50 data-[state=checked]:bg-white data-[state=checked]:text-[#9956DE]"})}),e.jsx("th",{className:"bg-[#9956DE] px-6 py-4 text-[11px] font-black text-white uppercase tracking-widest",children:"User Profile"}),e.jsx("th",{className:"bg-[#9956DE] px-6 py-4 text-[11px] font-black text-white uppercase tracking-widest",children:"Role & Access"}),e.jsx("th",{className:"bg-[#9956DE] px-6 py-4 text-[11px] font-black text-white uppercase tracking-widest",children:"Status"}),e.jsx("th",{className:"bg-[#9956DE] px-6 py-4 text-[11px] font-black text-white uppercase tracking-widest",children:"Placement"}),e.jsx("th",{className:"bg-[#9956DE] px-6 py-4 text-[11px] font-black text-white uppercase tracking-widest",children:"Activity"}),e.jsx("th",{className:"bg-[#9956DE] px-6 py-4 text-right text-[11px] font-black text-white uppercase tracking-widest rounded-tr-[20px]",children:"Actions"})]})}),e.jsx("tbody",{className:"divide-y divide-slate-50",children:o&&i.length===0?e.jsx("tr",{children:e.jsxs("td",{colSpan:7,className:"px-6 py-20 text-center",children:[e.jsx(V,{className:"animate-spin text-indigo-200 mx-auto",size:40}),e.jsx("p",{className:"mt-4 text-[10px] font-black text-slate-300 uppercase tracking-widest",children:"Loading Records..."})]})}):i.length>0?gs.map(t=>{const b=f===t.id;return e.jsxs("tr",{className:"hover:bg-slate-50/50 transition-all group",children:[e.jsx("td",{className:"px-6 py-4 align-middle",children:e.jsx(as,{checked:Ze(t.id),onCheckedChange:()=>Is(t.id),className:"rounded-md border-slate-300 group-hover:border-indigo-400 transition-colors"})}),e.jsx("td",{className:"px-6 py-4",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"relative shrink-0",children:e.jsxs(Hs,{className:"h-11 w-11 rounded-full border-2 border-white shadow-sm ring-1 ring-slate-100",children:[e.jsx(Ws,{src:t.photo||Cs(t.gender),className:"object-cover"}),e.jsx(Vs,{className:"bg-indigo-50 text-indigo-600 font-bold text-sm",children:t.name.charAt(0)})]})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-black text-[#1e293b] truncate text-sm leading-tight group-hover:text-indigo-600 transition-colors",children:t.name}),e.jsx("p",{className:"text-[11px] font-medium text-slate-400 truncate mt-0.5",children:t.email})]})]})}),e.jsx("td",{className:"px-6 py-4",children:e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsx("span",{className:` | |
| text-[9px] font-black px-2 py-0.5 rounded-lg uppercase tracking-wider | |
| ${t.role==="Admin"?"bg-sky-50 text-sky-600":""} | |
| ${t.role==="Teacher"?"bg-purple-50 text-purple-600":""} | |
| ${t.role==="Student"?"bg-blue-50 text-blue-600":""} | |
| `,children:t.role})}),t.lrn&&e.jsxs("p",{className:"text-[9px] font-black text-slate-300 uppercase tracking-tighter ml-0.5",children:["LRN: ",t.lrn]})]})}),e.jsx("td",{className:"px-6 py-4",children:e.jsxs("span",{className:` | |
| inline-flex items-center gap-1.5 px-3 py-1.5 rounded-2xl text-[10px] font-black uppercase tracking-wider border | |
| ${t.status==="Active"?"bg-emerald-50 text-emerald-600 border-emerald-100":"bg-slate-50 text-slate-400 border-slate-100"} | |
| `,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${t.status==="Active"?"bg-emerald-500 animate-pulse":"bg-slate-300"}`}),t.status]})}),e.jsx("td",{className:"px-6 py-4",children:e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("p",{className:"text-xs font-black text-slate-600",children:t.grade||"N/A"}),e.jsx("p",{className:"text-[10px] font-medium text-slate-400",children:t.role==="Student"?t.classSection||t.section||"Unassigned":t.department})]})}),e.jsx("td",{className:"px-6 py-4",children:e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("p",{className:"text-[10px] font-black text-slate-600 uppercase tracking-tighter",children:t.lastLogin?"Recent Activity":"Inactive Account"}),e.jsx("p",{className:"text-[10px] font-medium text-slate-400",children:t.lastLogin||"No login history"})]})}),e.jsx("td",{className:"px-6 py-4 text-right",children:e.jsxs("div",{className:"flex items-center justify-end gap-1",children:[e.jsx(E,{variant:"ghost",size:"icon",onClick:()=>Os(t),className:"h-9 w-9 rounded-xl text-slate-400 hover:text-indigo-600 hover:bg-indigo-50 transition-all",title:"Edit User",children:e.jsx(ss,{size:16})}),e.jsx(E,{variant:"ghost",size:"icon",onClick:()=>Gs(t),disabled:b||c,className:`h-9 w-9 rounded-xl transition-all ${t.status==="Active"?"text-slate-400 hover:text-amber-600 hover:bg-amber-50":"text-slate-400 hover:text-emerald-600 hover:bg-emerald-50"}`,title:t.status==="Active"?"Deactivate":"Activate",children:b?e.jsx(V,{size:16,className:"animate-spin"}):t.status==="Active"?e.jsx(st,{size:16}):e.jsx(qe,{size:16})}),e.jsx(E,{variant:"ghost",size:"icon",onClick:()=>Bs(t.id,t.name),disabled:c,className:"h-9 w-9 rounded-xl text-slate-400 hover:text-rose-600 hover:bg-rose-50 transition-all",title:"Delete User",children:e.jsx(je,{size:16})})]})})]},t.id)}):e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"px-6 py-32 text-center",children:e.jsxs("div",{className:"max-w-xs mx-auto space-y-6",children:[e.jsx("div",{className:"w-24 h-24 bg-slate-50 rounded-[32px] flex items-center justify-center mx-auto shadow-sm shadow-slate-100 group-hover:scale-110 transition-transform duration-500",children:e.jsx(Pe,{size:40,className:"text-slate-200"})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"text-sm font-black text-slate-600 uppercase tracking-widest",children:"No matching users"}),e.jsx("p",{className:"text-xs text-slate-400 font-medium leading-relaxed",children:"We couldn't find any results for your current query. Try broadening your search or clearing filters."})]}),e.jsx(E,{variant:"outline",size:"sm",className:"rounded-xl border-slate-200 text-indigo-600 font-bold px-6 h-10 hover:bg-indigo-50",onClick:()=>{X(""),U("All Roles"),O("All Status")},children:"Reset Filters"})]})})})})]})})]}),e.jsxs("div",{className:"sticky bottom-0 z-50 flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 px-12 py-3 bg-white border-t-2 border-slate-100 shadow-[0_-8px_30px_rgba(0,0,0,0.08)] -mx-[24px] xl:-mx-[32px] w-[calc(100%+48px)] xl:w-[calc(100%+64px)]",children:[e.jsxs("p",{className:"text-[12px] font-black text-slate-500 uppercase tracking-widest flex items-center gap-4",children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-full bg-[#9956DE] animate-pulse shadow-[0_0_12px_rgba(153,86,222,0.6)]"}),"Showing ",e.jsxs("span",{className:"text-slate-900 font-black border-b-2 border-[#9956DE]/40 pb-0.5",children:[Ut,"–",It]}),e.jsx("span",{className:"text-slate-300 font-bold mx-1",children:"/"}),e.jsx("span",{className:"text-slate-900 font-black border-b-2 border-[#9956DE]/40 pb-0.5",children:T}),e.jsx("span",{className:"text-slate-400 ml-1",children:"Total System Records"})]}),e.jsxs("div",{className:"flex items-center gap-6",children:[e.jsxs(J,{value:String(y),onValueChange:t=>{const b=Number(t);Number.isNaN(b)||(D(b),u(1),ue())},children:[e.jsx(ee,{className:"h-10 w-[140px] bg-white border border-slate-300 text-[11px] font-black uppercase tracking-wider text-slate-900 rounded-xl hover:border-[#9956DE] transition-all px-4 shadow-sm",children:e.jsxs("span",{className:"truncate",children:[y," / Page"]})}),e.jsx(se,{className:"rounded-xl border-slate-200",children:ml.map(t=>e.jsxs(C,{value:t,className:"font-bold",children:[t," / Page"]},t))})]}),e.jsxs("div",{className:"flex items-center gap-2 bg-slate-50 p-1.5 rounded-2xl border border-slate-200 shadow-inner",children:[e.jsx(E,{variant:"outline",size:"sm",className:"h-9 w-9 p-0 rounded-xl bg-[#9956DE] border-none text-white hover:bg-[#8b5cf6] hover:scale-105 active:scale-95 disabled:opacity-30 transition-all shadow-lg shadow-purple-200/60",disabled:A<=1||o||c,onClick:()=>u(t=>Math.max(t-1,1)),children:e.jsx(jt,{size:18,strokeWidth:3})}),e.jsx("div",{className:"px-5 py-2 bg-white rounded-xl shadow-sm border border-slate-200 flex items-center justify-center min-w-[130px]",children:e.jsxs("span",{className:"text-[11px] font-black text-slate-900 uppercase tracking-widest",children:["Page ",e.jsx("span",{className:"text-[#9956DE] mx-1",children:A}),e.jsx("span",{className:"text-slate-300 mx-1",children:"OF"}),e.jsx("span",{className:"text-slate-500",children:Math.max(me,1)})]})}),e.jsx(E,{variant:"outline",size:"sm",className:"h-9 w-9 p-0 rounded-xl bg-[#9956DE] border-none text-white hover:bg-[#8b5cf6] hover:scale-105 active:scale-95 disabled:opacity-30 transition-all shadow-lg shadow-purple-200/60",disabled:!Ne||o||c||A>=me,onClick:()=>u(t=>Math.min(t+1,me||1)),children:e.jsx(vt,{size:18,strokeWidth:3})})]})]})]}),e.jsx(ht,{open:ds,onOpenChange:t=>!v&&Ee(t),children:e.jsxs(pt,{className:"sm:max-w-[850px] rounded-[32px] border-none shadow-2xl p-0 overflow-hidden [&>button:last-child]:hidden",children:[e.jsx("div",{className:`h-2 w-full bg-gradient-to-r ${W?"from-indigo-600 to-purple-600":"from-emerald-600 to-indigo-600"}`}),e.jsxs("div",{className:"p-8 space-y-8",children:[e.jsx(ut,{className:"text-left",children:e.jsxs("div",{className:"flex items-center gap-5",children:[e.jsx("div",{className:`w-14 h-14 rounded-2xl flex items-center justify-center shadow-lg transition-transform duration-500 hover:rotate-3 ${W?"bg-indigo-100 text-indigo-700 shadow-indigo-200/50":"bg-emerald-100 text-emerald-700 shadow-emerald-200/50"}`,children:W?e.jsx(ss,{size:28,className:"drop-shadow-sm"}):e.jsx(Ys,{size:28,className:"drop-shadow-sm"})}),e.jsxs("div",{children:[e.jsx(gt,{className:"text-2xl font-display font-black text-[#1e293b] leading-tight",children:W?"Edit User Access":"Onboard New User"}),e.jsxs("p",{className:"text-[11px] font-black text-slate-400 uppercase tracking-[0.2em] mt-1 flex items-center gap-2",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-indigo-500 animate-pulse"}),W?"User Identity Management":"System Enrollment Pipeline"]})]})]})}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-x-10 gap-y-6",children:[e.jsx("div",{className:"space-y-6",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("h4",{className:"text-[11px] font-black text-indigo-600 uppercase tracking-[0.15em] pb-1 border-b border-indigo-50",children:"Identity Details"}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-[10px] font-black text-slate-400 uppercase tracking-widest ml-1",children:"Full Name"}),e.jsxs("div",{className:"relative group",children:[e.jsx(xe,{value:j.name,onChange:t=>{de({...j,name:t.target.value}),hs.name&&Ke(b=>({...b,name:void 0}))},placeholder:"Enter full name",className:`h-12 rounded-xl bg-slate-50 border-slate-200 focus-visible:ring-indigo-500/20 focus-visible:border-indigo-500 transition-all font-bold text-[#1e293b] ${hs.name?"border-rose-300 bg-rose-50/20":""}`}),hs.name&&e.jsx(Re,{size:14,className:"absolute right-3 top-1/2 -translate-y-1/2 text-rose-500"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-[10px] font-black text-slate-400 uppercase tracking-widest ml-1",children:"Email Address"}),e.jsx(xe,{type:"email",value:j.email,onChange:t=>{W||de({...j,email:t.target.value})},readOnly:!!W,placeholder:"name@example.com",className:`h-12 rounded-xl bg-slate-50 border-slate-200 focus-visible:ring-indigo-500/20 focus-visible:border-indigo-500 transition-all font-bold text-[#1e293b] ${W?"opacity-60 grayscale bg-slate-100":""}`})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-[10px] font-black text-slate-400 uppercase tracking-widest ml-1",children:"Access Role"}),e.jsxs(J,{value:j.role,onValueChange:t=>{de({...j,role:t,lrn:t==="Student"?j.lrn:""})},children:[e.jsx(ee,{className:"h-12 rounded-xl bg-slate-50 border-slate-200 font-black text-[#1e293b]",children:e.jsx(Ue,{placeholder:"Role"})}),e.jsxs(se,{className:"rounded-xl border-slate-200",children:[e.jsx(C,{value:"Student",className:"font-bold",children:"Student"}),e.jsx(C,{value:"Teacher",className:"font-bold",children:"Teacher"}),e.jsx(C,{value:"Admin",className:"font-bold",children:"Admin"})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-[10px] font-black text-slate-400 uppercase tracking-widest ml-1",children:"Status"}),e.jsxs(J,{value:j.status,onValueChange:t=>de({...j,status:t}),children:[e.jsx(ee,{className:"h-12 rounded-xl bg-slate-50 border-slate-200 font-black text-[#1e293b]",children:e.jsx(Ue,{placeholder:"Status"})}),e.jsxs(se,{className:"rounded-xl border-slate-200",children:[e.jsx(C,{value:"Active",className:"font-bold",children:"Active"}),e.jsx(C,{value:"Inactive",className:"font-bold",children:"Inactive"})]})]})]})]})]})}),e.jsx("div",{className:"space-y-6",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("h4",{className:"text-[11px] font-black text-indigo-600 uppercase tracking-[0.15em] pb-1 border-b border-indigo-50",children:"Contextual Assignment"}),j.role==="Student"?e.jsxs("div",{className:"space-y-4 animate-in fade-in slide-in-from-right-4 duration-500",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-[10px] font-black text-slate-400 uppercase tracking-widest ml-1",children:"Grade Level"}),e.jsx(xe,{value:j.grade,onChange:t=>de({...j,grade:t.target.value}),placeholder:"Grade 11",className:"h-12 rounded-xl bg-slate-50 border-slate-200 font-bold"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-[10px] font-black text-slate-400 uppercase tracking-widest ml-1",children:"Section"}),e.jsx(xe,{value:j.section,onChange:t=>de({...j,section:t.target.value}),placeholder:"STEM A",className:"h-12 rounded-xl bg-slate-50 border-slate-200 font-bold"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-[10px] font-black text-slate-400 uppercase tracking-widest ml-1",children:"LRN (Learner Reference Number)"}),e.jsx(xe,{value:j.lrn,onChange:t=>de({...j,lrn:t.target.value}),placeholder:"12-digit number",className:"h-12 rounded-xl bg-slate-50 border-slate-200 font-black tracking-widest"})]})]}):e.jsxs("div",{className:"space-y-1.5 animate-in fade-in slide-in-from-right-4 duration-500",children:[e.jsx("label",{className:"text-[10px] font-black text-slate-400 uppercase tracking-widest ml-1",children:"Department / Office"}),e.jsx(xe,{value:j.department,onChange:t=>de({...j,department:t.target.value}),placeholder:"e.g. Mathematics Department",className:"h-12 rounded-xl bg-slate-50 border-slate-200 font-bold"})]}),!W&&e.jsxs("div",{className:"space-y-1.5 pt-2",children:[e.jsx("label",{className:"text-[10px] font-black text-slate-400 uppercase tracking-widest ml-1",children:"Initial Password"}),e.jsxs("div",{className:"relative",children:[e.jsx(xe,{type:ps?"text":"password",value:j.password,onChange:t=>de({...j,password:t.target.value}),className:"h-12 rounded-xl bg-slate-50 border-slate-200 pr-10 font-black tracking-widest"}),e.jsx("button",{type:"button",onClick:()=>Ye(!ps),className:"absolute right-3 top-1/2 -translate-y-1/2 text-slate-400 hover:text-slate-600",children:ps?e.jsx(ft,{size:16}):e.jsx(ra,{size:16})})]})]})]})})]}),e.jsxs(la,{className:"grid grid-cols-2 gap-3 pt-6 border-t border-slate-100",children:[e.jsx(E,{variant:"outline",className:`h-12 rounded-xl font-black uppercase tracking-widest text-[10px] transition-all border-2 ${W?"border-indigo-600/50 text-indigo-600 hover:bg-indigo-50":"border-emerald-600/50 text-emerald-600 hover:bg-emerald-50"}`,onClick:()=>Ee(!1),disabled:v,children:"Cancel"}),e.jsx(E,{onClick:Pt,className:`h-12 rounded-xl font-black uppercase tracking-widest gap-3 text-[10px] shadow-lg transition-all active:scale-95 ${W?"bg-indigo-600 hover:bg-indigo-700 shadow-indigo-500/25":"bg-emerald-600 hover:bg-emerald-700 shadow-emerald-500/25"}`,disabled:v,children:v?e.jsx(V,{size:16,className:"animate-spin"}):W?e.jsxs(e.Fragment,{children:[e.jsx(Nt,{size:16})," Save Changes"]}):e.jsxs(e.Fragment,{children:[e.jsx(Ys,{size:16})," Onboard User"]})})]})]})]})}),e.jsx(ct,{isOpen:xs,zIndexClass:"z-[70]",onClose:()=>{$e||(Be(!1),ms(null))},onConfirm:Dt,title:le?.title||"Confirm Action",message:le?.message||"Proceed with this action?",confirmText:$e?"Processing...":le?.confirmText||"Confirm",cancelText:"Cancel",type:"danger",icon:"delete"})]})},Ge=({icon:s,title:a,subtitle:n})=>e.jsxs("div",{className:"flex flex-col items-center justify-center gap-3 py-12 text-center",children:[e.jsx("div",{className:"w-14 h-14 rounded-2xl bg-slate-50 border border-slate-100 flex items-center justify-center",children:s}),e.jsx("p",{className:"text-[11px] font-black text-slate-500 uppercase tracking-widest",children:a}),n&&e.jsx("p",{className:"text-[10px] text-slate-400 font-medium max-w-xs leading-relaxed",children:n})]}),pl=()=>{const[s,a]=r.useState("30d"),[n,i]=r.useState(null),[l,o]=r.useState(!0),g=()=>{o(!0),sl().then(i).catch(console.error).finally(()=>o(!1))};r.useEffect(()=>{g()},[]);const m={"7d":"7 Days","30d":"30 Days","90d":"90 Days","12m":"12 Months"},N=[{label:"Total Active Users",value:l?null:(n?.totalActiveUsers??0).toLocaleString(),icon:Pe,bg:"bg-[#4f46e5]",shadow:"shadow-indigo-500/20"},{label:"Avg. Quiz Score",value:l?null:`${n?.avgQuizScore??0}%`,icon:Ht,bg:"bg-[#10b981]",shadow:"shadow-emerald-500/20"},{label:"Quizzes Taken",value:l?null:(n?.totalQuizzesTaken??0).toLocaleString(),icon:Rs,bg:"bg-[#8b5cf6]",shadow:"shadow-purple-500/20"},{label:"At-Risk Students",value:l?null:(n?.atRiskStudents??0).toString(),icon:_e,bg:"bg-[#f43f5e]",shadow:"shadow-rose-500/20"}],v=[{label:"Achievements Unlocked",icon:Qs,color:"text-rose-600",bg:"bg-rose-50",border:"border-rose-100",value:l?null:(n?.achievementsUnlocked??0).toLocaleString()},{label:"XP Earned (Platform)",icon:Fe,color:"text-violet-600",bg:"bg-violet-50",border:"border-violet-100",value:l?null:(n?.totalXPEarned??0)>=1e6?`${((n?.totalXPEarned??0)/1e6).toFixed(1)}M`:(n?.totalXPEarned??0)>=1e3?`${Math.round((n?.totalXPEarned??0)/1e3)}K`:(n?.totalXPEarned??0).toLocaleString()},{label:"Active Streaks",icon:Wt,color:"text-orange-600",bg:"bg-orange-50",border:"border-orange-100",value:l?null:(n?.activeStreaks??0).toLocaleString()},{label:"AI Tutor Sessions",icon:Vt,color:"text-sky-600",bg:"bg-sky-50",border:"border-sky-100",value:l?null:(n?.aiTutorSessions??0).toLocaleString()}];return e.jsxs("div",{className:"space-y-6 pt-6 xl:pt-8 pb-10 max-w-[1600px] mx-auto",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-1.5 h-6 bg-[#9956DE] rounded-full"}),e.jsx("p",{className:"text-[11px] font-black text-slate-400 uppercase tracking-[0.2em]",children:"Platform Analytics"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex items-center bg-white rounded-xl p-1 shadow-sm border border-slate-200/60",children:Object.entries(m).map(([h,c])=>e.jsx("button",{onClick:()=>a(h),disabled:!0,title:"Range selection unavailable",className:`px-3 py-1.5 rounded-lg text-[10px] font-black uppercase tracking-widest transition-all ${s===h?"bg-[#9956DE] text-white shadow-sm":"text-slate-500 hover:bg-slate-50"} opacity-50 cursor-not-allowed`,children:c},h))}),e.jsx("button",{onClick:g,disabled:l,title:"Refresh data",className:"p-2.5 rounded-xl bg-white border border-slate-200 text-slate-400 hover:text-[#9956DE] shadow-sm transition-all active:scale-95",children:e.jsx(Me,{size:14,className:l?"animate-spin":""})}),e.jsxs(E,{variant:"outline",disabled:!0,title:"Export unavailable",className:"h-9 px-4 gap-2 rounded-xl border-slate-200 text-[10px] font-black uppercase tracking-widest text-slate-400 opacity-50 cursor-not-allowed shadow-sm",children:[e.jsx(Ps,{size:14}),"Export"]})]})]}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4",children:N.map((h,c)=>{const x=h.icon;return e.jsxs(re.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.3,delay:c*.05},className:`relative overflow-hidden ${h.bg} ${h.shadow} p-5 rounded-[28px] text-white flex flex-col gap-3 group hover:scale-[1.02] transition-all duration-300 shadow-lg`,children:[e.jsx("div",{className:"absolute -right-4 -bottom-4 w-24 h-24 rounded-full bg-white/10 group-hover:scale-[1.6] transition-transform duration-700 ease-out"}),e.jsx("div",{className:"absolute -left-4 -top-4 w-12 h-12 rounded-full bg-white/10 group-hover:scale-[1.4] transition-transform duration-700 delay-75 ease-out"}),e.jsxs("div",{className:"relative z-10 flex items-center justify-between",children:[e.jsx("p",{className:"text-[10px] font-black uppercase tracking-[0.2em] opacity-80",children:h.label}),e.jsx("div",{className:"bg-white/20 p-2 rounded-xl backdrop-blur-sm group-hover:bg-white/30 transition-colors",children:e.jsx(x,{size:14})})]}),l?e.jsx("div",{className:"relative z-10 flex items-center gap-2",children:e.jsx(V,{size:18,className:"animate-spin opacity-60"})}):e.jsx("h3",{className:"relative z-10 text-3xl font-display font-black leading-none tracking-tight",children:h.value})]},h.label)})}),!l&&!n?.totalActiveUsers&&e.jsxs(re.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},className:"flex items-center gap-3 bg-amber-50 border border-amber-100 rounded-2xl px-5 py-3",children:[e.jsx(fe,{size:16,className:"text-amber-600 shrink-0"}),e.jsx("p",{className:"text-[10px] font-black text-amber-700 uppercase tracking-widest",children:"Limited data — KPIs populate as platform usage grows. Charts require time-series data."})]}),e.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-12 gap-5",children:[e.jsxs(re.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.35,delay:.1},className:"xl:col-span-8 bg-white rounded-[28px] border border-slate-200/60 p-6 shadow-sm shadow-slate-200/40",children:[e.jsxs("div",{className:"flex items-center justify-between mb-5",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-indigo-50 text-indigo-600 flex items-center justify-center border border-indigo-100",children:e.jsx(mt,{size:18})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-black text-[#1e293b] tracking-tight",children:"Performance Trends"}),e.jsx("p",{className:"text-[10px] text-slate-400 font-bold uppercase tracking-widest mt-0.5",children:"Students vs. Teacher Targets"})]})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-indigo-400"}),e.jsx("span",{className:"text-[9px] font-black text-slate-400 uppercase tracking-widest",children:"Students"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-purple-400"}),e.jsx("span",{className:"text-[9px] font-black text-slate-400 uppercase tracking-widest",children:"Targets"})]})]})]}),e.jsx(Ge,{icon:e.jsx(da,{size:22,className:"text-slate-300"}),title:"No performance data yet",subtitle:"Trend charts will generate as students complete quizzes and assessments."})]}),e.jsxs(re.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.35,delay:.15},className:"xl:col-span-4 bg-white rounded-[28px] border border-slate-200/60 p-6 shadow-sm shadow-slate-200/40",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-5",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-purple-50 text-purple-600 flex items-center justify-center border border-purple-100",children:e.jsx(Pa,{size:18})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-black text-[#1e293b] tracking-tight",children:"Grade Distribution"}),e.jsx("p",{className:"text-[10px] text-slate-400 font-bold uppercase tracking-widest mt-0.5",children:"Current Term"})]})]}),e.jsx(Ge,{icon:e.jsx(fe,{size:22,className:"text-slate-300"}),title:"No grade data",subtitle:"Import quiz results to see grade breakdowns."})]})]}),e.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-12 gap-5",children:[e.jsxs(re.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.35,delay:.2},className:"xl:col-span-7 bg-white rounded-[28px] border border-slate-200/60 p-6 shadow-sm shadow-slate-200/40",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-5",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-sky-50 text-sky-600 flex items-center justify-center border border-sky-100",children:e.jsx(He,{size:18})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-black text-[#1e293b] tracking-tight",children:"Subject Engagement"}),e.jsx("p",{className:"text-[10px] text-slate-400 font-bold uppercase tracking-widest mt-0.5",children:"Enrollment & Completion"})]})]}),e.jsx("div",{className:"rounded-2xl border border-slate-200/60 overflow-hidden",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-slate-50/80",children:[e.jsx("th",{className:"text-left text-[10px] font-black text-slate-400 uppercase tracking-widest px-5 py-3",children:"Subject"}),e.jsx("th",{className:"text-right text-[10px] font-black text-slate-400 uppercase tracking-widest px-5 py-3",children:"Enrolled"}),e.jsx("th",{className:"text-right text-[10px] font-black text-slate-400 uppercase tracking-widest px-5 py-3",children:"Completion"}),e.jsx("th",{className:"text-right text-[10px] font-black text-slate-400 uppercase tracking-widest px-5 py-3",children:"Avg. Score"}),e.jsx("th",{className:"text-left text-[10px] font-black text-slate-400 uppercase tracking-widest px-5 py-3 w-32",children:"Progress"})]})}),e.jsx("tbody",{children:e.jsx("tr",{children:e.jsx("td",{colSpan:5,className:"px-4 py-8",children:e.jsx(Ge,{icon:e.jsx(fe,{size:20,className:"text-slate-300"}),title:"No subject data available",subtitle:"Import class enrollment records to view engagement."})})})})]})})]}),e.jsxs(re.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.35,delay:.25},className:"xl:col-span-5 bg-white rounded-[28px] border border-slate-200/60 p-6 shadow-sm shadow-slate-200/40",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-5",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-orange-50 text-orange-600 flex items-center justify-center border border-orange-100",children:e.jsx(Qt,{size:18})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-black text-[#1e293b] tracking-tight",children:"Weekly Activity"}),e.jsx("p",{className:"text-[10px] text-slate-400 font-bold uppercase tracking-widest mt-0.5",children:"Sessions Per Day"})]})]}),e.jsx(Ge,{icon:e.jsx(_e,{size:22,className:"text-slate-300"}),title:"No session activity yet",subtitle:"Student logins and session data will appear here."})]})]}),e.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-12 gap-5",children:[e.jsxs(re.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.35,delay:.3},className:"xl:col-span-5 bg-white rounded-[28px] border border-slate-200/60 p-6 shadow-sm shadow-slate-200/40",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-5",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-rose-50 text-rose-600 flex items-center justify-center border border-rose-100",children:e.jsx(Qs,{size:18})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-black text-[#1e293b] tracking-tight",children:"Gamification Overview"}),e.jsx("p",{className:"text-[10px] text-slate-400 font-bold uppercase tracking-widest mt-0.5",children:"Engagement Metrics"})]})]}),e.jsx("div",{className:"grid grid-cols-2 gap-3",children:v.map(h=>{const c=h.icon;return e.jsxs("div",{className:`${h.bg} border ${h.border} rounded-2xl p-4 group hover:scale-[1.02] transition-all duration-200`,children:[e.jsx("div",{className:"flex items-center justify-between mb-2",children:e.jsx(c,{size:18,className:h.color})}),l?e.jsx("div",{className:"w-12 h-5 bg-white/60 rounded-lg mt-1 mb-1 animate-pulse"}):e.jsx("p",{className:"text-xl font-black text-[#1e293b] leading-none",children:h.value}),e.jsx("p",{className:"text-[9px] font-black text-slate-400 uppercase tracking-widest mt-2",children:h.label})]},h.label)})})]}),e.jsxs(re.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.35,delay:.35},className:"xl:col-span-7 bg-white rounded-[28px] border border-slate-200/60 p-6 shadow-sm shadow-slate-200/40",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-5",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-emerald-50 text-emerald-600 flex items-center justify-center border border-emerald-100",children:e.jsx(is,{size:18})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-black text-[#1e293b] tracking-tight",children:"Top Performing Classes"}),e.jsx("p",{className:"text-[10px] text-slate-400 font-bold uppercase tracking-widest mt-0.5",children:"Ranked by Average Score"})]})]}),e.jsx(Ge,{icon:e.jsx(fe,{size:22,className:"text-slate-300"}),title:"No class data yet",subtitle:"Import class and student records to see top performers."})]})]})]})};async function ul(){return De("/api/admin/ai-monitoring/summary")}async function gl(){return De("/api/admin/ai-monitoring/refresh",{method:"POST"})}function bl(){const s=Xt(),{data:a,isLoading:n,isError:i,error:l}=xa({queryKey:["ai-monitoring"],queryFn:ul,refetchInterval:3e4,staleTime:15e3});return{data:a,isLoading:n,isError:i,error:l,refetch:async()=>{await gl(),s.invalidateQueries({queryKey:["ai-monitoring"]})}}}const ls=({title:s,value:a,subValue:n,icon:i,badge:l,gradient:o="from-slate-800 to-slate-900"})=>e.jsxs("div",{className:`relative rounded-xl bg-gradient-to-br ${o} p-5 text-white shadow-lg overflow-hidden`,children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium text-white/60 uppercase tracking-wide",children:s}),e.jsx("p",{className:"text-2xl font-bold",children:a}),n&&e.jsx("p",{className:"text-xs text-white/50",children:n})]}),e.jsx("div",{className:"rounded-lg bg-white/10 p-2",children:i})]}),l&&e.jsx("span",{className:"absolute top-2 right-2 rounded-full bg-amber-400/90 px-2 py-0.5 text-[10px] font-semibold text-amber-900",children:l})]}),fl=({promoExpiresUtc:s,daysUntilPromoEnds:a,fullPriceInputRate:n,fullPriceOutputRate:i})=>{const[l,o]=r.useState(!1),g=r.useMemo(()=>{if(!s)return a;const m=new Date(s).getTime()-Date.now();return Math.max(0,Math.ceil(m/(1e3*60*60*24)))},[s,a]);return l?null:e.jsxs("div",{className:"relative rounded-lg border border-amber-300/50 bg-amber-50 px-4 py-3 text-sm text-amber-900",children:[e.jsx("button",{onClick:()=>o(!0),className:"absolute top-2 right-2 rounded p-1 hover:bg-amber-200/50","aria-label":"Dismiss",children:e.jsx(Ms,{className:"h-3.5 w-3.5"})}),e.jsxs("div",{className:"flex items-start gap-2 pr-6",children:[e.jsx(Fe,{className:"mt-0.5 h-4 w-4 flex-shrink-0 text-amber-600"}),e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold",children:"DeepSeek V4 Pro is currently 75% OFF"})," ","(cache-miss: $0.435/1M, output: $0.87/1M). Sale ends May 31, 2026 at 15:59 UTC — ",e.jsxs("strong",{children:[g," days remaining"]}),".",e.jsx("br",{}),e.jsxs("span",{className:"text-amber-700",children:["Full price after sale: $",n,"/1M input · $",i,"/1M output."]})]})]})]})},rt=({title:s,feature:a})=>a?e.jsxs("div",{className:"rounded-xl border border-slate-200 bg-white p-4 shadow-sm",children:[e.jsx("p",{className:"text-xs font-medium text-slate-500 uppercase tracking-wide mb-2",children:s}),e.jsx("p",{className:"text-lg font-bold text-slate-900",children:a.featureName}),e.jsxs("div",{className:"mt-2 flex items-center gap-3 text-xs text-slate-600",children:[e.jsxs("span",{children:["$",a.monthlyCost.toFixed(4)]}),e.jsx("span",{className:"text-slate-300",children:"|"}),e.jsxs("span",{children:[a.totalRequests.toLocaleString()," reqs"]}),e.jsx("span",{className:"text-slate-300",children:"|"}),e.jsxs("span",{children:[(a.cacheHitRate*100).toFixed(0),"% cache"]})]})]}):null,jl=({features:s})=>{const a=[...s].sort((n,i)=>i.monthlyCost-n.monthlyCost);return e.jsxs("div",{className:"rounded-xl border border-slate-200 bg-white p-4 shadow-sm",children:[e.jsx("p",{className:"text-xs font-medium text-slate-500 uppercase tracking-wide mb-3",children:"Resource Breakdown"}),e.jsx("div",{className:"space-y-2",children:a.map(n=>e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"truncate font-medium text-slate-700",children:n.featureName}),e.jsxs("span",{className:"text-xs text-slate-500",children:["$",n.monthlyCost.toFixed(4)]})]}),e.jsx("div",{className:"mt-1 h-1.5 w-full rounded-full bg-slate-100 overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full bg-indigo-500",style:{width:`${Math.min(n.costShare,100)}%`}})})]}),e.jsxs("span",{className:"text-xs text-slate-400 w-10 text-right",children:[n.costShare.toFixed(0),"%"]})]},n.featureId))})]})},vl=({open:s,onClose:a,features:n})=>s?e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40",onClick:a,children:e.jsxs("div",{className:"relative w-full max-w-2xl max-h-[80vh] overflow-y-auto rounded-xl bg-white p-6 shadow-xl",onClick:i=>i.stopPropagation(),children:[e.jsx("button",{onClick:a,className:"absolute top-3 right-3 rounded p-1 hover:bg-slate-100","aria-label":"Close",children:e.jsx(Ms,{className:"h-5 w-5 text-slate-500"})}),e.jsx("h2",{className:"text-lg font-bold text-slate-900 mb-4",children:"AI Feature Directory"}),e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b text-left text-xs text-slate-500 uppercase",children:[e.jsx("th",{className:"pb-2",children:"Feature"}),e.jsx("th",{className:"pb-2",children:"Model"}),e.jsx("th",{className:"pb-2 text-right",children:"Cost"}),e.jsx("th",{className:"pb-2 text-right",children:"Requests"}),e.jsx("th",{className:"pb-2 text-right",children:"Cache Hit"})]})}),e.jsx("tbody",{children:n.map(i=>e.jsxs("tr",{className:"border-b border-slate-100",children:[e.jsx("td",{className:"py-2 font-medium text-slate-800",children:i.featureName}),e.jsx("td",{className:"py-2 text-slate-600",children:i.modelId}),e.jsxs("td",{className:"py-2 text-right",children:["$",i.monthlyCost.toFixed(4)]}),e.jsx("td",{className:"py-2 text-right",children:i.totalRequests.toLocaleString()}),e.jsxs("td",{className:"py-2 text-right",children:[(i.cacheHitRate*100).toFixed(0),"%"]})]},i.featureId))})]})]})}):null,wl=({pricingMeta:s})=>{const[a,n]=r.useState(!1);return e.jsxs("div",{className:"relative inline-block",children:[e.jsx("button",{onMouseEnter:()=>n(!0),onMouseLeave:()=>n(!1),className:"rounded p-1 text-slate-400 hover:text-slate-600","aria-label":"Pricing info",children:e.jsx(wt,{className:"h-4 w-4"})}),a&&e.jsxs("div",{className:"absolute bottom-full left-1/2 z-50 mb-2 w-64 -translate-x-1/2 rounded-lg border border-slate-200 bg-white p-3 text-xs shadow-lg",children:[e.jsx("p",{className:"font-semibold text-slate-800 mb-1",children:s.isPromotional?"Promotional Pricing (75% OFF)":"Standard Pricing"}),e.jsxs("div",{className:"space-y-1 text-slate-600",children:[e.jsxs("p",{children:["Input (cache miss): ",e.jsxs("strong",{children:["$",s.currentInputCacheMissRate,"/1M"]})]}),e.jsxs("p",{children:["Output: ",e.jsxs("strong",{children:["$",s.currentOutputRate,"/1M"]})]}),s.isPromotional&&e.jsxs(e.Fragment,{children:[e.jsx("hr",{className:"my-1 border-slate-100"}),e.jsxs("p",{className:"text-slate-400",children:["Full price: $",s.fullPriceInputRate,"/1M in · $",s.fullPriceOutputRate,"/1M out"]})]})]})]})]})},Nl=()=>{const{data:s,isLoading:a,refetch:n}=bl(),[i,l]=r.useState(!1),[o,g]=r.useState(!1),m=async()=>{g(!0);try{await n()}finally{g(!1)}};if(a||!s)return e.jsxs("div",{className:"space-y-5 p-1",children:[e.jsx("div",{className:"h-[72px] w-full rounded-xl bg-slate-100 animate-pulse"}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"h-4 w-48 rounded bg-slate-100 animate-pulse"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("div",{className:"h-8 w-24 rounded-lg bg-slate-100 animate-pulse"}),e.jsx("div",{className:"h-8 w-20 rounded-lg bg-slate-100 animate-pulse"})]})]}),e.jsx("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-4",children:Array.from({length:4}).map((h,c)=>e.jsx("div",{className:"h-[120px] rounded-xl bg-gradient-to-br from-slate-100 to-slate-50 animate-pulse"},c))}),e.jsx("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-3",children:Array.from({length:3}).map((h,c)=>e.jsx("div",{className:"h-[130px] rounded-xl border border-slate-100 bg-slate-50/50 animate-pulse"},c))}),e.jsxs("div",{className:"rounded-xl border border-slate-100 bg-white p-5 space-y-4",children:[e.jsx("div",{className:"h-4 w-40 rounded bg-slate-100 animate-pulse"}),Array.from({length:5}).map((h,c)=>e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"h-3 w-28 rounded bg-slate-100 animate-pulse"}),e.jsx("div",{className:"flex-1 h-2 rounded-full bg-slate-100 animate-pulse"}),e.jsx("div",{className:"h-3 w-16 rounded bg-slate-100 animate-pulse"})]},c))]})]});const N=s.features.find(h=>h.isTopSpending),v=s.features.find(h=>h.isMostActive);return e.jsxs("div",{className:"space-y-5 p-1",children:[s.promotionalPricingActive&&e.jsx(fl,{promoExpiresUtc:s.pricingMeta.promoExpiresUtc,daysUntilPromoEnds:s.pricingMeta.daysUntilPromoEnds,fullPriceInputRate:s.pricingMeta.fullPriceInputRate,fullPriceOutputRate:s.pricingMeta.fullPriceOutputRate}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(wl,{pricingMeta:s.pricingMeta}),e.jsxs("span",{className:"text-xs text-slate-400",children:["Last updated: ",new Date(s.lastUpdated).toLocaleTimeString()]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{onClick:()=>l(!0),className:"inline-flex items-center gap-1.5 rounded-lg border border-slate-200 bg-white px-3 py-1.5 text-xs font-medium text-slate-700 hover:bg-slate-50",children:[e.jsx(Ta,{className:"h-3.5 w-3.5"})," Directory"]}),e.jsxs("button",{onClick:m,disabled:o,className:"inline-flex items-center gap-1.5 rounded-lg bg-indigo-600 px-3 py-1.5 text-xs font-medium text-white hover:bg-indigo-700 disabled:opacity-50",children:[e.jsx(Me,{className:`h-3.5 w-3.5 ${o?"animate-spin":""}`})," Refresh"]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-4",children:[e.jsx(ls,{title:"Monthly Cost",value:`$${s.monthlyCost.toFixed(2)}`,subValue:`Would be ~$${s.estimatedCostAfterPromo.toFixed(2)} at full price`,icon:e.jsx(ma,{className:"h-5 w-5"}),gradient:"from-emerald-600 to-emerald-800"}),e.jsx(ls,{title:"Active Engine",value:s.activeEngine,subValue:s.engineTier,icon:e.jsx(it,{className:"h-5 w-5"}),badge:s.promotionalPricingActive?"75% OFF until May 31":void 0,gradient:"from-indigo-600 to-indigo-800"}),e.jsx(ls,{title:"Total Requests",value:s.totalUsage.toLocaleString(),subValue:s.billingCycleLabel,icon:e.jsx(_e,{className:"h-5 w-5"}),gradient:"from-violet-600 to-violet-800"}),e.jsx(ls,{title:"Cache Efficiency",value:`${(s.cacheHitRate*100).toFixed(1)}%`,subValue:"Cache hits: $0.003625/1M vs miss: $0.435/1M",icon:e.jsx(fe,{className:"h-5 w-5"}),gradient:"from-sky-600 to-sky-800"})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-3",children:[e.jsx(rt,{title:"Top Spending",feature:N}),e.jsx(rt,{title:"Most Active",feature:v}),e.jsxs("div",{className:"rounded-xl border border-slate-200 bg-white p-4 shadow-sm",children:[e.jsx("p",{className:"text-xs font-medium text-slate-500 uppercase tracking-wide mb-2",children:"Cost Breakdown"}),e.jsxs("div",{className:"space-y-2 text-sm",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-slate-600",children:"Cache Hit"}),e.jsxs("span",{className:"font-medium",children:["$",s.costBreakdown.cacheHitCost.toFixed(6)]})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-slate-600",children:"Cache Miss"}),e.jsxs("span",{className:"font-medium",children:["$",s.costBreakdown.cacheMissCost.toFixed(6)]})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-slate-600",children:"Output"}),e.jsxs("span",{className:"font-medium",children:["$",s.costBreakdown.outputCost.toFixed(6)]})]})]})]})]}),e.jsx(jl,{features:s.features}),e.jsx(vl,{open:i,onClose:()=>l(!1),features:s.features})]})},Le=rs.map(s=>({id:s.id,name:s.name,code:s.code,gradeLevel:s.gradeLevel,semester:s.semester,color:s.color})),yl=()=>{const{userProfile:s}=cs(),{availability:a,loading:n,error:i}=pa(),[l,o]=r.useState(null),[g,m]=r.useState({}),N=r.useCallback(async(c,x)=>{if(!s?.uid){S.error("You must be logged in as admin to change availability");return}o(c);try{await ua(c,x,s.uid),S.success(`${Le.find(f=>f.id===c)?.name||c} is now ${x?"available":"locked"}`)}catch(f){S.error("Failed to update subject availability"),console.error(f)}finally{o(null)}},[s?.uid]),v=r.useCallback((c,x)=>{m(f=>({...f,[c]:x}))},[]),h=r.useCallback(async c=>{if(!s?.uid){S.error("You must be logged in as admin");return}const x=g[c]?.trim()||null;o(c);try{await ga(c,x,s.uid),S.success("PDF path updated")}catch(f){S.error("Failed to update PDF path"),console.error(f)}finally{o(null)}},[g,s?.uid]);return e.jsxs("div",{className:"flex flex-col min-h-full space-y-8 pt-6 xl:pt-8 animate-in fade-in slide-in-from-bottom-4 duration-700 pb-6",children:[n&&e.jsx("div",{className:"flex items-center justify-end px-2",children:e.jsxs("div",{className:"flex items-center gap-3 px-4 py-2 bg-indigo-50 text-indigo-600 rounded-2xl border border-indigo-100 animate-pulse",children:[e.jsx(V,{size:16,className:"animate-spin"}),e.jsx("span",{className:"text-[10px] font-black uppercase tracking-widest",children:"Syncing Subject Cloud Data..."})]})}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 md:grid-cols-4 gap-4",children:[{label:"Total Subjects",value:Le.length,icon:He,bg:"bg-[#4f46e5]",shadow:"shadow-indigo-500/20"},{label:"Available",value:Le.filter(c=>a[c.id]?.available!==!1).length,icon:La,bg:"bg-[#10b981]",shadow:"shadow-emerald-500/20"},{label:"Locked",value:Le.filter(c=>a[c.id]?.available===!1).length,icon:dt,bg:"bg-[#ef4444]",shadow:"shadow-rose-500/20"},{label:"RAG Sources",value:Le.filter(c=>a[c.id]?.pdfPath).length,icon:Ce,bg:"bg-[#8b5cf6]",shadow:"shadow-purple-500/20"}].map((c,x)=>e.jsxs("div",{className:`relative overflow-hidden ${c.bg} ${c.shadow} p-5 rounded-[28px] text-white flex flex-col gap-3 group hover:scale-[1.02] transition-all duration-300 shadow-lg`,children:[e.jsx("div",{className:"absolute -right-4 -bottom-4 w-24 h-24 rounded-full bg-white/10 group-hover:scale-[1.6] transition-transform duration-700 ease-out"}),e.jsxs("div",{className:"relative z-10 flex items-center justify-between",children:[e.jsx("p",{className:"text-[10px] font-black uppercase tracking-[0.2em] opacity-80",children:c.label}),e.jsx("div",{className:"bg-white/20 p-2 rounded-xl backdrop-blur-sm",children:e.jsx(c.icon,{size:14})})]}),e.jsx("h3",{className:"relative z-10 text-3xl font-display font-black leading-none tracking-tight",children:c.value})]},x))}),i&&e.jsxs("div",{className:"rounded-2xl border border-rose-200 bg-rose-50 px-6 py-4 flex items-center gap-3 animate-in shake duration-500",children:[e.jsx(Re,{className:"text-rose-600",size:20}),e.jsx("p",{className:"text-sm font-bold text-rose-700",children:i})]}),e.jsx("div",{className:"bg-white rounded-[32px] border border-slate-200/60 shadow-sm shadow-slate-200/50 overflow-hidden relative",children:e.jsxs(kt,{className:"w-full text-left border-collapse",children:[e.jsx(St,{children:e.jsxs(Ie,{className:"bg-[#9956DE] hover:bg-[#9956DE] border-b border-[#8b5cf6] sticky top-0 z-20 shadow-md",children:[e.jsx(ge,{className:"px-6 py-5 text-[11px] font-black text-white uppercase tracking-widest",children:"Subject Identity"}),e.jsx(ge,{className:"px-6 py-5 text-[11px] font-black text-white uppercase tracking-widest",children:"Grade / Semester"}),e.jsx(ge,{className:"px-6 py-5 text-[11px] font-black text-white uppercase tracking-widest",children:"Access Status"}),e.jsx(ge,{className:"px-6 py-5 text-[11px] font-black text-white uppercase tracking-widest",children:"Toggle Access"}),e.jsx(ge,{className:"px-6 py-5 text-[11px] font-black text-white uppercase tracking-widest",children:"RAG Resource Mapping"})]})}),e.jsx(Ct,{className:"divide-y divide-slate-50",children:Le.map(c=>{const x=a[c.id],f=x?.available??!0,w=g[c.id]??x?.pdfPath??"",A=x?.lastUpdated,u=l===c.id;return e.jsxs(Ie,{className:"group hover:bg-slate-50/50 transition-all",children:[e.jsx(ie,{className:"px-6 py-5",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:`w-12 h-12 rounded-2xl bg-gradient-to-br ${c.color} flex items-center justify-center text-white shadow-lg shadow-indigo-100 group-hover:scale-110 transition-transform duration-500`,children:e.jsx(He,{size:20,className:"drop-shadow-sm"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-black text-[#1e293b] truncate text-sm leading-tight group-hover:text-indigo-600 transition-colors",children:c.name}),e.jsx("p",{className:"text-[11px] font-black text-slate-400 uppercase tracking-tighter mt-1",children:c.code})]})]})}),e.jsx(ie,{className:"px-6 py-5",children:e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-black text-slate-700 uppercase tracking-wide",children:c.gradeLevel}),e.jsx("p",{className:"text-[10px] font-black text-slate-400 uppercase tracking-tight",children:c.semester})]})}),e.jsx(ie,{className:"px-6 py-5",children:e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("span",{className:` | |
| inline-flex items-center gap-1.5 px-3 py-1.5 rounded-2xl text-[10px] font-black uppercase tracking-wider border | |
| ${f?"bg-emerald-50 text-emerald-600 border-emerald-100":"bg-slate-50 text-slate-400 border-slate-100"} | |
| `,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${f?"bg-emerald-500 animate-pulse":"bg-slate-300"}`}),f?"Available":"Locked"]}),A&&e.jsxs("p",{className:"text-[9px] font-black text-slate-400 uppercase tracking-tighter ml-1 flex items-center gap-1",children:[e.jsx(Rs,{size:10}),"Updated: ",A.toLocaleString()]})]})}),e.jsx(ie,{className:"px-6 py-5",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ha,{checked:f,onCheckedChange:y=>N(c.id,y),disabled:u,className:"data-[state=checked]:bg-emerald-500 data-[state=unchecked]:bg-slate-200","aria-label":`Toggle ${c.name} availability`}),u&&e.jsx(V,{size:16,className:"animate-spin text-indigo-500"})]})}),e.jsx(ie,{className:"px-6 py-5",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"relative flex-1 group/input",children:[e.jsx(Ce,{size:14,className:"absolute left-3.5 top-1/2 -translate-y-1/2 text-slate-400 group-focus-within/input:text-indigo-500 transition-colors"}),e.jsx(xe,{value:w,onChange:y=>v(c.id,y.target.value),placeholder:"Firebase path (e.g., rag/calculus.pdf)",className:"pl-10 h-10 text-xs font-bold rounded-xl bg-slate-50/50 border-slate-200 focus-visible:ring-indigo-500/20 focus-visible:border-indigo-500 transition-all",disabled:u})]}),e.jsx(E,{variant:"ghost",size:"icon",className:"h-10 w-10 rounded-xl text-slate-400 hover:text-indigo-600 hover:bg-indigo-50 transition-all",onClick:()=>h(c.id),disabled:u,title:"Save PDF Path",children:u?e.jsx(V,{size:18,className:"animate-spin text-indigo-500"}):e.jsx(Nt,{size:18})})]})})]},c.id)})})]})})]})},kl=()=>{const[s,a]=r.useState([]),[n,i]=r.useState([]),[l,o]=r.useState(!0),[g,m]=r.useState(null),[N,v]=r.useState({});r.useEffect(()=>{h()},[]);const h=async()=>{o(!0);try{const f=(await F(L(M,"classrooms"))).docs.map(D=>({id:D.id,...D.data()}));a(f);const w=ve(L(M,"users"),Ve("role","==","teacher")),u=(await F(w)).docs.map(D=>{const T=D.data();return{uid:D.id,name:T.name||T.displayName||"Teacher",email:T.email||""}});i(u);const y={};f.forEach(D=>{D.managerId&&(y[D.id]=D.managerId)}),v(y)}catch{S.error("Failed to load class data")}finally{o(!1)}},c=async x=>{const f=N[x];if(!f){S.error("Select a teacher first");return}const w=n.find(A=>A.uid===f);if(w){m(x);try{await ws(Es(M,"classrooms",x),{managerId:w.uid,managerName:w.name});const A=Es(M,"classSectionOwnership",x),u=await F(ve(L(M,"classSectionOwnership"),Ve("classSectionId","==",x)));if(u.docs.length>0)await ws(u.docs[0].ref,{managerId:w.uid,managerName:w.name});else try{await ws(A,{managerId:w.uid,managerName:w.name})}catch{}a(y=>y.map(D=>D.id===x?{...D,managerId:w.uid,managerName:w.name}:D)),S.success(`Assigned ${w.name} as manager`)}catch{S.error("Failed to assign manager")}finally{m(null)}}};return l?e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx("div",{className:"w-8 h-8 border-2 border-indigo-500 border-t-transparent rounded-full animate-spin"})}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:[e.jsx("div",{className:"bg-white rounded-xl p-5 border border-slate-200 shadow-sm",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg bg-indigo-50 flex items-center justify-center",children:e.jsx(nt,{className:"w-5 h-5 text-indigo-600"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[24px] font-bold text-slate-900",children:s.length}),e.jsx("p",{className:"text-[12px] text-slate-500 font-medium",children:"Total Classes"})]})]})}),e.jsx("div",{className:"bg-white rounded-xl p-5 border border-slate-200 shadow-sm",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg bg-emerald-50 flex items-center justify-center",children:e.jsx(qe,{className:"w-5 h-5 text-emerald-600"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[24px] font-bold text-slate-900",children:s.filter(x=>x.managerId).length}),e.jsx("p",{className:"text-[12px] text-slate-500 font-medium",children:"With Manager"})]})]})}),e.jsx("div",{className:"bg-white rounded-xl p-5 border border-slate-200 shadow-sm",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg bg-amber-50 flex items-center justify-center",children:e.jsx(Pe,{className:"w-5 h-5 text-amber-600"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[24px] font-bold text-slate-900",children:s.filter(x=>!x.managerId).length}),e.jsx("p",{className:"text-[12px] text-slate-500 font-medium",children:"Unassigned"})]})]})})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-slate-200 shadow-sm overflow-hidden",children:[e.jsx("div",{className:"px-6 py-4 border-b border-slate-100",children:e.jsx("h3",{className:"text-[15px] font-bold text-slate-900",children:"All Classes"})}),e.jsx("div",{className:"divide-y divide-slate-100",children:s.length===0?e.jsx("div",{className:"px-6 py-12 text-center text-slate-500 text-[13px]",children:"No classes found."}):s.map(x=>e.jsxs("div",{className:"px-6 py-4 flex flex-col sm:flex-row sm:items-center gap-3 sm:gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-[14px] font-semibold text-slate-900 truncate",children:x.name}),e.jsxs("p",{className:"text-[12px] text-slate-500",children:[x.gradeLevel||""," ",x.section?`• ${x.section}`:""," ",x.studentCount?`• ${x.studentCount} students`:""]}),x.managerName&&e.jsxs("p",{className:"text-[11px] text-emerald-600 font-medium mt-0.5",children:["Manager: ",x.managerName]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:N[x.id]||"",onChange:f=>v(w=>({...w,[x.id]:f.target.value})),className:"appearance-none bg-slate-50 border border-slate-200 text-slate-700 text-[12px] font-semibold rounded-lg pl-3 pr-8 py-2 outline-none focus:border-indigo-400 focus:ring-2 focus:ring-indigo-100 w-[220px]",children:[e.jsx("option",{value:"",children:"Select teacher..."}),n.map(f=>e.jsxs("option",{value:f.uid,children:[f.name," (",f.email,")"]},f.uid))]}),e.jsx(ba,{className:"w-3.5 h-3.5 text-slate-400 absolute right-2.5 top-1/2 -translate-y-1/2 pointer-events-none"})]}),e.jsx("button",{onClick:()=>c(x.id),disabled:!N[x.id]||g===x.id,className:"px-4 py-2 bg-indigo-600 hover:bg-indigo-700 text-white text-[12px] font-bold rounded-lg disabled:opacity-50 transition-colors whitespace-nowrap",children:g===x.id?"...":"Assign"})]})]},x.id))})]})]})},Sl=({isOpen:s,onClose:a})=>s?e.jsxs("div",{className:"fixed inset-0 z-[100] flex items-center justify-center p-4 sm:p-6",children:[e.jsx("div",{className:"absolute inset-0 bg-slate-900/40 backdrop-blur-sm animate-in fade-in duration-300",onClick:a}),e.jsxs("div",{className:"relative bg-white w-full max-w-4xl rounded-[40px] shadow-2xl border border-slate-200 overflow-hidden animate-in zoom-in slide-in-from-bottom-8 duration-500",children:[e.jsxs("div",{className:"px-10 pt-10 pb-6 flex items-center justify-between border-b border-slate-50 bg-slate-50/50",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-xl font-black text-[#1e293b] uppercase tracking-wider",children:"How It Works: Subject Governance"}),e.jsx("p",{className:"text-[11px] font-black text-indigo-500 uppercase tracking-[0.2em] mt-1",children:"Platform Curriculum Protocol & RAG Workflow"})]}),e.jsx("button",{onClick:a,className:"w-12 h-12 rounded-2xl flex items-center justify-center bg-white text-slate-400 hover:text-rose-500 hover:bg-rose-50 transition-all border border-slate-200 shadow-sm group",children:e.jsx(Ms,{size:20,className:"group-hover:rotate-90 transition-transform duration-300"})})]}),e.jsx("div",{className:"p-12",children:e.jsxs("div",{className:"flex flex-col md:flex-row items-center justify-between gap-12 relative",children:[e.jsx("div",{className:"absolute top-12 left-0 right-0 h-0.5 border-t-2 border-dashed border-indigo-100 hidden md:block z-0",style:{left:"10%",right:"10%"}}),[{step:"1",title:"Define Identity",desc:"Assign subject codes and grade levels in the core registry.",icon:He,color:"text-indigo-600",bg:"bg-indigo-50"},{step:"2",title:"Map RAG Source",desc:"Link Firebase PDF paths to the AI Knowledge Base.",icon:Fe,color:"text-amber-600",bg:"bg-amber-50"},{step:"3",title:"Global Toggle",desc:"Enable or lock subject access across all dashboards instantly.",icon:Kt,color:"text-emerald-600",bg:"bg-emerald-50"},{step:"4",title:"Audit Sync",desc:"Every modification is logged and synced to the cloud registry.",icon:zs,color:"text-purple-600",bg:"bg-purple-50"}].map((n,i)=>e.jsxs("div",{className:"flex-1 flex flex-col items-center text-center group relative z-10",children:[e.jsxs("div",{className:`relative mb-6 w-24 h-24 ${n.bg} rounded-[32px] flex items-center justify-center transition-all duration-500 group-hover:scale-110 group-hover:rotate-3 shadow-lg shadow-indigo-100/20`,children:[e.jsx(n.icon,{size:36,className:`${n.color} drop-shadow-sm`}),e.jsx("div",{className:"absolute -top-3 -left-3 bg-[#9956DE] text-white text-[12px] font-black w-10 h-10 rounded-2xl flex items-center justify-center shadow-lg border-2 border-white",children:n.step})]}),e.jsx("h4",{className:"text-sm font-black text-[#1e293b] uppercase tracking-wide mb-2",children:n.title}),e.jsx("p",{className:"text-xs text-slate-400 font-bold leading-relaxed max-w-[180px]",children:n.desc})]},i))]})}),e.jsxs("div",{className:"px-12 py-6 bg-slate-50/50 border-t border-slate-100 flex items-center justify-center gap-4",children:[e.jsx("div",{className:"flex -space-x-2",children:[1,2,3].map(n=>e.jsx("div",{className:"w-8 h-8 rounded-full border-2 border-white bg-indigo-100 flex items-center justify-center",children:e.jsx("div",{className:"w-4 h-4 rounded-full bg-indigo-500 animate-pulse"})},n))}),e.jsx("p",{className:"text-[10px] font-black text-slate-400 uppercase tracking-widest",children:"Platform Governance Active & Monitored"})]})]})]}):null,Nr=({onLogout:s,onOpenProfile:a,onOpenSettings:n})=>{const{userProfile:i}=cs(),[l,o]=r.useState("Overview"),[g,m]=r.useState(!1),[N,v]=r.useState(!1),[h,c]=r.useState(!1),[x,f]=r.useState(null),[w,A]=r.useState(null),[u,y]=r.useState([]),[D,T]=r.useState([]),[q,me]=r.useState(!0),[he,Ne]=r.useState([]),[_,pe]=r.useState(null),[X,Q]=r.useState([]),[U,te]=r.useState(null),[O,K]=r.useState(null),[ne,B]=r.useState(null),[ce,d]=r.useState(!1),{unreadCount:ae}=Yt(),[p,P]=r.useState(!1),[H,Y]=r.useState(!1),G=k=>(l===k||(o(k),k==="Subjects"&&(Y(!0),setTimeout(()=>Y(!1),2e3))),!0),Qe=k=>{G(k)&&c(!1)};r.useEffect(()=>{if(l!=="Overview"||!i)return;const k=String(i.role||"").toLowerCase(),$=k==="admin"||k==="teacher";let oe=!1;return me(!0),Promise.all([Qa(),$?Et():Promise.resolve([]),Xa(3),Ka(),Ya(),Za(),Ja(),el(),Se.getInferenceMetrics().catch(()=>null)]).then(([Ae,Ts,ds,Ee,xs,Be,$e,Xe,le])=>{oe||(A(Ae),y(Ts.slice(0,4)),T(ds),Ne(Ee),Q(xs),te(Be),K($e),B(Xe),le&&pe(le.metrics))}).catch(console.error).finally(()=>{oe||me(!1)}),()=>{oe=!0}},[l,i]);const Oe=[{label:"Active Teachers",value:(w?.activeTeachers??0).toString(),icon:is,color:"bg-teal-100",iconColor:"text-teal-600"},{label:"Total Classes",value:(w?.totalClasses??0).toString(),icon:He,color:"bg-indigo-100",iconColor:"text-indigo-600"},{label:"XP Events",value:(w?.aiPredictions??0).toLocaleString(),icon:Fe,color:"bg-amber-100",iconColor:"text-amber-600"},{label:"At-Risk Alerts",value:(w?.atRiskStudents??0).toString(),icon:Re,color:"bg-rose-100",iconColor:"text-rose-600"}];return e.jsxs("div",{className:"flex h-screen w-full bg-[#f8fafc] overflow-hidden font-body",children:[e.jsx("div",{className:"hidden lg:block",children:e.jsx(qs,{activeTab:l,setActiveTab:Qe,userRole:"admin",onOpenSettings:()=>n?.(),onLogout:()=>m(!0),sidebarCollapsed:N,setSidebarCollapsed:v})}),h&&e.jsxs(e.Fragment,{children:[e.jsx("button",{"aria-label":"Close navigation",className:"fixed inset-0 z-40 bg-slate-900/40 backdrop-blur-[1px] lg:hidden",onClick:()=>c(!1)}),e.jsx("div",{className:"fixed inset-y-0 left-0 z-50 p-3 lg:hidden",children:e.jsx(qs,{mode:"mobile",onRequestClose:()=>c(!1),activeTab:l,setActiveTab:Qe,userRole:"admin",onOpenSettings:()=>n?.(),onLogout:()=>{m(!0),c(!1)},sidebarCollapsed:!1})})]}),e.jsxs("div",{className:"flex-1 flex flex-col",children:[e.jsx("header",{className:"bg-transparent border-b border-[#e2e8f0]/40 px-[24px] xl:px-[32px] pt-[24px] pb-[16px] flex-shrink-0 z-30",children:e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-start justify-between gap-4 mb-0",children:[e.jsxs("div",{className:"flex-1 flex items-start gap-3",children:[e.jsx("button",{type:"button",onClick:()=>c(!0),className:"lg:hidden mt-1 p-2 rounded-lg border border-[#dde3eb] bg-white text-[#5a6578] hover:bg-[#edf1f7] transition-colors","aria-label":"Open navigation",children:e.jsx(Zt,{size:18})}),e.jsxs("div",{children:[e.jsxs("h1",{className:"text-[26px] font-bold text-[#1e293b] tracking-tight leading-tight",children:[l==="Overview"&&"Admin Dashboard",l==="Content"&&"Content",l==="Audit Log"&&"Audit Log",l==="User Management"&&"User Management",l==="Analytics"&&"Analytics",l==="AI Monitoring"&&"AI Monitoring",l==="Subjects"&&"Curriculum Control",l==="Class Management"&&"Class Management"]}),e.jsxs("p",{className:"text-[13px] text-[#64748b] mt-1",children:[l==="Overview"&&"System Overview & Management",l==="Content"&&"Upload PDFs for AI-powered content.",l==="Audit Log"&&"Monitor system activity and security.",l==="User Management"&&"Manage all user accounts and roles.",l==="Analytics"&&"Detailed system performance metrics.",l==="AI Monitoring"&&"Platform AI usage and system health.",l==="Subjects"&&"Manage academic subjects, availability, and RAG knowledge sources.",l==="Class Management"&&"Assign section managers and manage class rosters."]})]}),l==="Overview"&&e.jsxs("div",{className:"hidden xl:flex items-center gap-2 ml-4 mt-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1.5 bg-[#4f46e5]/10 border border-[#4f46e5]/20 rounded-lg",children:[e.jsx(Pe,{size:13,className:"text-[#4f46e5]"}),e.jsxs("span",{className:"text-xs font-display font-semibold text-[#4f46e5]",children:[(w?.totalStudents??0).toLocaleString()," students"]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1.5 bg-[#0ea5e9]/10 border border-[#0ea5e9]/20 rounded-lg",children:[e.jsx(is,{size:13,className:"text-[#0ea5e9]"}),e.jsxs("span",{className:"text-xs font-display font-semibold text-[#0ea5e9]",children:[w?.activeTeachers??0," teachers"]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1.5 bg-amber-500/10 border border-amber-500/20 rounded-lg",children:[e.jsx(Fe,{size:13,className:"text-amber-600"}),e.jsxs("span",{className:"text-xs font-display font-semibold text-amber-600",children:[(w?.aiPredictions??0).toLocaleString()," XP events"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-3 shrink-0 self-end sm:self-auto",children:[l==="Subjects"&&e.jsxs("div",{className:"relative",children:[e.jsx("button",{onClick:()=>P(!0),className:"relative w-10 h-10 flex items-center justify-center bg-indigo-600 hover:bg-indigo-700 rounded-full shadow-lg shadow-indigo-200 text-white transition-all cursor-pointer hover:scale-110 active:scale-95 animate-in zoom-in duration-300","aria-label":"How it works",children:e.jsx(fa,{size:20})}),H&&e.jsxs("div",{className:"absolute top-12 left-1/2 -translate-x-1/2 px-3 py-1.5 bg-[#1e293b] text-white text-[10px] font-black uppercase tracking-widest rounded-lg shadow-xl whitespace-nowrap animate-in fade-in slide-in-from-top-2 duration-300 z-50",children:["How It Works?",e.jsx("div",{className:"absolute -top-1 left-1/2 -translate-x-1/2 w-2 h-2 bg-[#1e293b] rotate-45"})]})]}),e.jsxs("div",{className:"relative",children:[e.jsxs("button",{onClick:()=>d(!ce),className:"relative w-10 h-10 flex items-center justify-center bg-white/60 hover:bg-white/80 rounded-full backdrop-blur-[12px] shadow-[0_1px_4px_rgba(0,0,0,0.04)] border border-white/50 text-[#64748b] hover:text-[#1e293b] transition-colors cursor-pointer hover:scale-[1.02]","aria-label":"View notifications",children:[e.jsx(ja,{size:18}),ae>0&&e.jsx("span",{className:"absolute top-2.5 right-2.5 w-2 h-2 bg-rose-500 rounded-full border border-white"})]}),e.jsx(aa,{isOpen:ce,onClose:()=>d(!1),onViewAll:()=>G("Audit Log")})]}),e.jsxs("div",{onClick:a,className:"flex items-center gap-2 bg-white/60 px-4 py-2 rounded-full backdrop-blur-[12px] shadow-[0_1px_4px_rgba(0,0,0,0.04)] border border-white/50 cursor-pointer hover:bg-white/80 transition-colors h-10 hover:scale-[1.02]",children:[e.jsx("div",{className:"w-6 h-6 rounded-full bg-indigo-100 overflow-hidden shrink-0",children:e.jsx(Jt,{src:i?.photo,name:i?.name||"Admin",gender:i?.gender,className:"w-full h-full object-cover"})}),e.jsx("span",{className:"text-[13px] font-semibold text-[#1e293b]",children:i?.name||"Admin"})]})]})]})}),e.jsxs("main",{className:`flex-1 overflow-y-auto px-[24px] xl:px-[32px] scrollbar-hide ${["User Management","Audit Log"].includes(l)?"pb-0":"pb-[32px]"}`,children:[l==="Overview"&&e.jsxs("div",{className:"max-w-[1600px] mx-auto space-y-8 pt-6 xl:pt-8",children:[e.jsxs("div",{className:"grid grid-cols-12 gap-6 h-[170px]",children:[e.jsxs("div",{className:"col-span-12 xl:col-span-4 h-full bg-gradient-to-br from-[#4f46e5] to-[#7c3aed] rounded-[28px] p-6 relative overflow-hidden shadow-sm shadow-indigo-500/10 group",children:[e.jsx("div",{className:"absolute -top-24 -right-24 w-64 h-64 bg-white/10 rounded-full blur-3xl group-hover:bg-white/20 transition-all duration-1000"}),e.jsxs("div",{className:"relative z-10 flex flex-col justify-between h-full",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-white/70 text-[10px] font-black uppercase tracking-[0.2em] mb-1.5",children:"Platform Overview"}),e.jsx("p",{className:"text-white text-4xl font-display font-black tracking-tighter leading-none",children:q?"...":(w?.totalStudents??0).toLocaleString()}),e.jsx("p",{className:"text-white/80 text-xs font-medium mt-1",children:"Total Active Students"})]}),e.jsxs("div",{className:"flex items-center gap-2 py-1 px-3 bg-white/10 backdrop-blur-md rounded-full w-fit border border-white/10",children:[e.jsx(mt,{size:12,className:"text-emerald-400"}),e.jsxs("span",{className:"text-white text-[10px] font-bold tracking-wide",children:[w?.activeTeachers??0," teachers · ",w?.totalClasses??0," classes"]})]})]}),e.jsx("div",{className:"absolute -bottom-6 -right-6 opacity-10 group-hover:scale-110 group-hover:rotate-6 transition-all duration-700 pointer-events-none",children:e.jsx(Pe,{size:140,className:"text-white"})})]}),e.jsx("div",{className:"col-span-12 xl:col-span-8 h-full bg-white border border-slate-200/60 rounded-[28px] px-2 py-5 flex items-center shadow-sm shadow-slate-200/50",children:e.jsx("div",{className:"grid grid-cols-4 w-full h-full",children:Oe.map((k,$)=>e.jsxs("div",{className:`flex flex-col justify-center px-8 ${$!==3?"border-r border-slate-100":""}`,children:[e.jsx("div",{className:`w-10 h-10 ${k.color} rounded-xl flex items-center justify-center mb-3 shadow-sm`,children:e.jsx(k.icon,{size:20,className:k.iconColor})}),e.jsx("p",{className:"text-[24px] font-display font-black text-[#1e293b] leading-tight tracking-tight",children:q?"...":k.value}),e.jsx("p",{className:"text-[9px] font-black text-slate-400 uppercase tracking-[0.15em] mt-0.5",children:k.label})]},$))})})]}),e.jsxs("div",{className:"grid grid-cols-12 gap-6 min-h-[330px]",children:[e.jsxs("div",{className:"col-span-12 xl:col-span-5 bg-white rounded-[28px] border border-slate-200/60 p-6 flex flex-col shadow-sm shadow-slate-200/50",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-[16px] font-bold text-[#1e293b]",children:"System Performance"}),e.jsx("p",{className:"text-[11px] text-slate-400 font-medium",children:"AI vs Manual Activity"})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-0.5 bg-slate-50 rounded-lg",children:[e.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#6366f1]"}),e.jsx("span",{className:"text-[9px] font-black text-slate-500 uppercase tracking-wider",children:"AI"})]}),e.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-0.5 bg-slate-50 rounded-lg",children:[e.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-slate-200"}),e.jsx("span",{className:"text-[9px] font-black text-slate-500 uppercase tracking-wider",children:"Manual"})]})]})]}),e.jsx("div",{className:"flex-1 w-full min-h-[200px]",children:e.jsx(Zs,{width:"100%",height:"100%",children:e.jsxs(va,{data:he,margin:{top:0,right:0,left:-20,bottom:0},children:[e.jsx(wa,{strokeDasharray:"4 4",vertical:!1,stroke:"#f1f5f9"}),e.jsx(Na,{dataKey:"name",axisLine:!1,tickLine:!1,tick:{fontSize:9,fontWeight:800,fill:"#cbd5e1"},dy:10}),e.jsx(ya,{axisLine:!1,tickLine:!1,tick:{fontSize:9,fontWeight:800,fill:"#cbd5e1"}}),e.jsx(ka,{contentStyle:{borderRadius:"12px",border:"none",boxShadow:"0 15px 20px -5px rgb(0 0 0 / 0.1)",padding:"10px"},cursor:{fill:"#f8fafc"}}),e.jsx(Js,{dataKey:"ai",fill:"#6366f1",radius:[4,4,0,0],barSize:12}),e.jsx(Js,{dataKey:"man",fill:"#e2e8f0",radius:[4,4,0,0],barSize:12})]})})})]}),e.jsxs("div",{className:"col-span-12 xl:col-span-4 bg-white rounded-[28px] border border-slate-200/60 p-6 flex flex-col shadow-sm shadow-slate-200/50 group",children:[e.jsxs("div",{className:"flex items-start justify-between mb-1",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-[16px] font-bold text-[#1e293b]",children:"AI Model Status"}),e.jsx("p",{className:"text-[11px] text-slate-400 font-medium",children:"Success Rate"})]}),e.jsx("div",{className:"w-9 h-9 bg-indigo-50 rounded-xl flex items-center justify-center",children:e.jsx(_e,{size:16,className:"text-indigo-600"})})]}),e.jsx("div",{className:"flex items-baseline gap-2 mb-4",children:_?(()=>{const k=_.requests_ok+_.requests_error,$=k>0?Math.round(_.requests_ok/k*100):100,oe=$>=90;return e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"text-[38px] font-display font-black text-indigo-600 tracking-tighter leading-none",children:[$,"%"]}),e.jsx("span",{className:`text-[10px] font-black px-2 py-0.5 rounded-full uppercase tracking-wider ${oe?"text-emerald-500 bg-emerald-50":"text-amber-500 bg-amber-50"}`,children:oe?"Optimal":`${_.requests_error} errors`})]})})():e.jsx("span",{className:"text-[38px] font-display font-black text-indigo-600 tracking-tighter leading-none",children:"..."})}),e.jsx("div",{className:"flex-1 flex flex-col justify-center gap-3",children:_&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("div",{className:"flex-1 h-3 bg-slate-100 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-indigo-500 rounded-full",style:{width:`${Math.round(_.requests_ok/(_.requests_ok+_.requests_error||1)*100)}%`}})})}),e.jsxs("div",{className:"flex justify-between text-[10px] font-bold text-slate-400",children:[e.jsxs("span",{children:[_.requests_ok.toLocaleString()," OK"]}),e.jsxs("span",{children:[_.requests_error.toLocaleString()," failed"]})]}),e.jsxs("p",{className:"text-[10px] text-slate-400",children:[_.requests_total.toLocaleString()," total attempts · ",_.retries_total.toLocaleString()," retries"]})]})}),e.jsxs("button",{onClick:()=>o("AI Monitoring"),className:"w-full mt-4 py-3 bg-slate-50 text-[#1e293b] text-[11px] font-black uppercase tracking-[0.15em] rounded-xl hover:bg-indigo-600 hover:text-white transition-all flex items-center justify-center gap-2.5 group/btn",children:["Health Check ",e.jsx(Ea,{size:14,className:"group-hover/btn:translate-x-0.5 group-hover/btn:-translate-y-0.5 transition-transform"})]})]}),e.jsxs("div",{className:"col-span-12 xl:col-span-3 flex flex-col gap-4",children:[e.jsx("h3",{className:"text-[10px] font-black text-slate-400 uppercase tracking-[0.2em] pl-2",children:"Top Performers"}),e.jsxs("div",{className:"flex flex-col gap-3 flex-1",children:[q?e.jsx("div",{className:"flex-1 flex items-center justify-center bg-white rounded-[28px] border border-slate-100",children:e.jsx(V,{size:24,className:"animate-spin text-slate-200"})}):D.slice(0,2).map((k,$)=>e.jsxs("div",{className:`relative rounded-[28px] border p-4 shadow-sm shadow-slate-200/50 transition-all cursor-pointer group overflow-hidden ${$===0?"bg-gradient-to-br from-emerald-50 to-white border-emerald-200/50":"bg-gradient-to-br from-indigo-50 to-white border-indigo-200/50"}`,children:[e.jsx("div",{className:`absolute -top-12 -right-12 w-32 h-32 rounded-full blur-2xl opacity-20 transition-all duration-700 group-hover:scale-125 ${$===0?"bg-emerald-400":"bg-indigo-400"}`}),e.jsxs("div",{className:"flex items-center gap-3 relative z-10",children:[e.jsxs("div",{className:"relative shrink-0",children:[e.jsx("div",{className:`p-[3px] rounded-[20px] shadow-sm ${$===0?"bg-gradient-to-tr from-emerald-500 to-emerald-200":"bg-gradient-to-tr from-indigo-500 to-indigo-200"}`,children:e.jsx("img",{src:k.avatar,alt:"",className:"w-11 h-11 rounded-[17px] object-cover bg-white"})}),e.jsx("div",{className:`absolute -top-2 -right-2 w-6 h-6 text-[10px] font-black rounded-full flex items-center justify-center border-2 border-white shadow-md ${$===0?"bg-emerald-500 text-white":"bg-indigo-500 text-white"}`,children:$===0?e.jsx(tt,{size:16,className:"text-amber-500"}):e.jsx(tt,{size:16,className:"text-slate-400"})})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h4",{className:`text-[13px] font-black truncate transition-colors ${$===0?"text-emerald-900 group-hover:text-emerald-600":"text-indigo-900 group-hover:text-indigo-600"}`,children:k.name}),e.jsx("div",{className:"flex items-center gap-1.5 mt-0.5",children:e.jsx("span",{className:`text-[8px] font-black uppercase tracking-widest px-1.5 py-0.5 rounded-md ${$===0?"bg-emerald-500/10 text-emerald-600":"bg-indigo-500/10 text-indigo-600"}`,children:k.class})})]}),e.jsxs("div",{className:"text-right",children:[e.jsxs("p",{className:`text-xl font-display font-black leading-none ${$===0?"text-emerald-600":"text-indigo-600"}`,children:[k.performance,"%"]}),e.jsx("p",{className:"text-[7px] font-black text-slate-400 uppercase tracking-tighter mt-1",children:"Mastery"})]})]})]},k.id)),e.jsx("button",{onClick:()=>o("Analytics"),className:"mt-auto py-2.5 text-[10px] font-black text-indigo-600 uppercase tracking-[0.2em] text-center bg-white border border-slate-200/60 rounded-xl hover:bg-slate-50 transition-all shadow-sm shadow-slate-200/50",children:"All Rankings"})]})]})]}),e.jsxs("div",{className:"flex flex-col xl:flex-row gap-6 pb-8 items-stretch",children:[e.jsxs("div",{className:"w-full xl:w-1/3 flex flex-col gap-6",children:[e.jsxs("div",{className:"bg-[#1e293b] rounded-[28px] p-6 text-white shadow-sm shadow-slate-900/10 relative overflow-hidden group min-h-[190px] flex flex-col justify-between shrink-0",children:[e.jsx("div",{className:"absolute -bottom-10 -right-10 opacity-5 group-hover:scale-110 group-hover:-rotate-12 transition-all duration-700 pointer-events-none",children:(U?.atRiskCount??0)>0?e.jsx(Re,{size:200}):e.jsx(Ns,{size:200})}),e.jsxs("div",{className:"relative z-10",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsx("div",{className:`w-10 h-10 ${(U?.atRiskCount??0)>0?"bg-rose-500 shadow-rose-500/20":"bg-emerald-500 shadow-emerald-500/20"} rounded-xl flex items-center justify-center mb-4 shadow-lg`,children:(U?.atRiskCount??0)>0?e.jsx(Re,{size:18,className:"text-white"}):e.jsx(Ns,{size:18,className:"text-white"})}),e.jsxs("div",{className:"px-2.5 py-1 bg-white/10 backdrop-blur-md rounded-full border border-white/10 flex items-center gap-2",children:[e.jsx("div",{className:`w-1.5 h-1.5 rounded-full ${(U?.atRiskCount??0)>0?"bg-rose-500 animate-pulse":"bg-emerald-400"}`}),e.jsx("span",{className:"text-[9px] font-black uppercase tracking-widest",children:(U?.atRiskCount??0)>0?"Urgent":"All Clear"})]})]}),e.jsx("h4",{className:"text-[10px] font-black text-slate-400 uppercase tracking-[0.2em] mb-0.5",children:(U?.atRiskCount??0)>0?"Priority Attention":"Status"}),e.jsx("h3",{className:"text-xl font-display font-black tracking-tight leading-tight",children:(U?.atRiskCount??0)>0?U?.subjectName:"No At-Risk Students"})]}),e.jsxs("div",{className:"relative z-10 pt-2 flex items-center justify-between",children:[e.jsx("span",{className:"text-xs font-medium text-slate-400",children:(U?.atRiskCount??0)>0?`${U.atRiskCount} At-Risk Student${U.atRiskCount!==1?"s":""}`:"All students on track"}),(U?.atRiskCount??0)>0&&e.jsx("button",{onClick:()=>o("Analytics"),className:"text-[10px] font-black uppercase tracking-widest text-indigo-400 hover:text-indigo-300 transition-colors",children:"Review"})]})]}),e.jsxs("div",{className:"bg-white rounded-[28px] border border-slate-200/60 p-7 flex flex-col items-center justify-center shadow-sm shadow-slate-200/50 relative overflow-hidden flex-1",children:[e.jsxs("div",{className:"absolute top-7 left-8",children:[e.jsx("h3",{className:"text-[14px] font-bold text-[#1e293b]",children:"Global Mastery"}),e.jsx("p",{className:"text-[10px] text-slate-400 font-medium",children:"Average performance"})]}),e.jsxs("div",{className:"relative w-40 h-40 mt-6",children:[e.jsx(Zs,{width:"100%",height:"100%",children:e.jsx(Sa,{children:e.jsxs(Ca,{data:[{name:"Mastery",value:O?.avgMastery??0},{name:"Remaining",value:100-(O?.avgMastery??0)}],cx:"50%",cy:"50%",innerRadius:55,outerRadius:75,paddingAngle:8,dataKey:"value",startAngle:90,endAngle:450,stroke:"none",children:[e.jsx(et,{fill:"#6366f1"}),e.jsx(et,{fill:"#f1f5f9"})]})})}),e.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center",children:[e.jsxs("span",{className:"text-[36px] font-display font-black text-[#1e293b] leading-none",children:[O?.avgMastery??0,"%"]}),e.jsx("span",{className:"text-[9px] font-black text-slate-400 uppercase tracking-[0.1em] mt-1",children:"Overall"})]})]}),e.jsxs("div",{className:"mt-8 flex items-center gap-12",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-xl font-display font-black text-indigo-600 leading-none",children:(O?.passed??0).toLocaleString()}),e.jsx("p",{className:"text-[8px] font-black text-slate-400 uppercase tracking-widest mt-1",children:"Passed"})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-xl font-display font-black text-slate-300 leading-none",children:(O?.pending??0).toLocaleString()}),e.jsx("p",{className:"text-[8px] font-black text-slate-400 uppercase tracking-widest mt-1",children:"Pending"})]})]}),e.jsx("div",{className:"absolute bottom-0 left-0 w-full h-1 bg-gradient-to-r from-indigo-500/20 to-purple-500/20"})]})]}),e.jsxs("div",{className:"w-full xl:w-2/3 flex flex-col gap-6",children:[e.jsxs("div",{className:"bg-white rounded-[28px] border border-slate-200/60 shadow-sm shadow-slate-200/50 overflow-hidden flex flex-col",children:[e.jsxs("div",{className:"px-6 py-4 border-b border-slate-50 flex items-center justify-between bg-slate-50/30",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-[15px] font-bold text-[#1e293b]",children:"Subject Breakdown"}),e.jsx("p",{className:"text-[11px] text-slate-400 font-medium",children:"Core vs STEM performance"})]}),e.jsx("button",{onClick:()=>{const k=["Subject,Category,Enrolled,Progress%",...X.map(Ae=>`${Ae.name},${Ae.type},${Ae.count},${Ae.progress}`)].join(` | |
| `),$=new Blob([k],{type:"text/csv"}),oe=document.createElement("a");oe.href=URL.createObjectURL($),oe.download="subject-breakdown.csv",oe.click()},className:"px-3 py-1.5 bg-white border border-slate-200 text-[10px] font-black text-[#1e293b] uppercase tracking-widest rounded-lg hover:bg-slate-50 transition-all",children:"Export"})]}),e.jsx("div",{className:"flex-1 overflow-x-auto",children:e.jsxs("table",{className:"w-full text-left",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-slate-50/20",children:[e.jsx("th",{className:"px-6 py-3 text-[9px] font-black text-slate-300 uppercase tracking-[0.2em]",children:"Subject"}),e.jsx("th",{className:"px-6 py-3 text-[9px] font-black text-slate-300 uppercase tracking-[0.2em]",children:"Category"}),e.jsx("th",{className:"px-6 py-3 text-[9px] font-black text-slate-300 uppercase tracking-[0.2em] text-center",children:"Enrolled"}),e.jsx("th",{className:"px-6 py-3 text-[9px] font-black text-slate-300 uppercase tracking-[0.2em]",children:"Progress"})]})}),e.jsx("tbody",{className:"divide-y divide-slate-50/60",children:X.map((k,$)=>e.jsxs("tr",{className:"hover:bg-slate-50/50 transition-colors group",children:[e.jsx("td",{className:"px-6 py-4",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-[13px] font-bold text-[#1e293b] group-hover:text-indigo-600 transition-colors",children:k.name}),e.jsx("span",{className:"text-[9px] font-medium text-slate-400",children:"Semester 1"})]})}),e.jsx("td",{className:"px-6 py-4",children:e.jsx("span",{className:`text-[8px] font-black px-2 py-0.5 rounded-md uppercase tracking-wider ${k.type==="STEM"?"bg-indigo-50 text-indigo-600 border border-indigo-100":"bg-slate-100 text-slate-500 border border-slate-200"}`,children:k.type})}),e.jsx("td",{className:"px-6 py-4 text-center",children:e.jsx("span",{className:"text-[12px] font-bold text-slate-600",children:k.count})}),e.jsx("td",{className:"px-6 py-4 min-w-[180px]",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex-1 h-1.5 bg-slate-100 rounded-full overflow-hidden p-[1px]",children:e.jsx("div",{className:`h-full rounded-full ${k.progress>80?"bg-indigo-500":k.progress>60?"bg-indigo-400":"bg-rose-400"} transition-all duration-1000`,style:{width:`${k.progress}%`}})}),e.jsxs("span",{className:"text-[11px] font-black text-[#1e293b] w-8",children:[k.progress,"%"]})]})})]},$))})]})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-6",children:[e.jsxs("div",{className:"bg-white rounded-[28px] border border-slate-200/60 p-6 shadow-sm shadow-slate-200/50",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsx("h3",{className:"text-[15px] font-bold text-[#1e293b]",children:"Activity"}),e.jsx("div",{className:"w-7 h-7 bg-slate-50 rounded-lg flex items-center justify-center",children:e.jsx(_e,{size:14,className:"text-slate-400"})})]}),e.jsx("div",{className:"space-y-5",children:u.slice(0,3).map((k,$)=>e.jsxs("div",{className:"flex gap-3 group",children:[e.jsx("div",{className:"w-9 h-9 rounded-xl bg-indigo-50 flex items-center justify-center shrink-0 group-hover:scale-110 transition-transform",children:e.jsx(Ns,{size:14,className:"text-indigo-600"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-[12px] font-bold text-[#1e293b] truncate leading-tight group-hover:text-indigo-600 transition-colors",children:k.action}),e.jsx("p",{className:"text-[10px] font-medium text-slate-400 truncate mt-0.5",children:k.details})]})]},$))})]}),e.jsxs("div",{className:"bg-white rounded-[28px] border border-slate-200/60 p-6 shadow-sm shadow-slate-200/50",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsx("h3",{className:"text-[15px] font-bold text-[#1e293b]",children:"Load"}),e.jsx("div",{className:"w-7 h-7 bg-slate-50 rounded-lg flex items-center justify-center",children:e.jsx(Fe,{size:14,className:"text-slate-400"})})]}),e.jsx("div",{className:"space-y-5",children:[{label:"Foundational",color:"bg-emerald-400",val:ne?.foundational??0},{label:"Intermediate",color:"bg-indigo-400",val:ne?.intermediate??0},{label:"Advanced",color:"bg-rose-400",val:ne?.advanced??0}].map((k,$)=>e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-center mb-1.5",children:[e.jsx("span",{className:"text-[9px] font-black text-slate-400 uppercase tracking-[0.15em]",children:k.label}),e.jsxs("span",{className:"text-[11px] font-black text-[#1e293b]",children:[k.val,"%"]})]}),e.jsx("div",{className:"h-1.5 bg-slate-50 rounded-full overflow-hidden p-[1px]",children:e.jsx("div",{className:`h-full rounded-full ${k.color}`,style:{width:`${k.val}%`}})})]},$))})]})]})]})]})]}),l==="Content"&&e.jsx(_a,{}),l==="RAG Manager"&&e.jsx(ll,{}),l==="Audit Log"&&e.jsx(al,{}),l==="User Management"&&e.jsx(hl,{createIntentRole:x,onCreateIntentConsumed:()=>f(null)}),l==="Analytics"&&e.jsx(pl,{}),l==="AI Monitoring"&&e.jsx(Nl,{}),l==="Class Management"&&e.jsx(kl,{}),l==="Subjects"&&e.jsx(yl,{})]})]}),e.jsx(Sl,{isOpen:p,onClose:()=>P(!1)}),e.jsx(ct,{isOpen:g,onClose:()=>m(!1),onConfirm:s,title:"Logout Confirmation",message:"Are you sure you want to log out? This will end your current session.",confirmText:"Logout",cancelText:"Cancel"})]})};export{Nr as default}; | |