diff --git a/assets/AIChatPage-AJHAnKG2.js b/assets/AIChatPage-DesRqPBP.js similarity index 94% rename from assets/AIChatPage-AJHAnKG2.js rename to assets/AIChatPage-DesRqPBP.js index ae46b97eb2215bb596c664c1dc13d6ba858bf574..021245a8b5d3cca8a2bcd014db73d3785a04cfe7 100644 --- a/assets/AIChatPage-AJHAnKG2.js +++ b/assets/AIChatPage-DesRqPBP.js @@ -1,2 +1,2 @@ -const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-BufUS6SI.js","assets/vendor-react-B4AQeu28.js","assets/vendor-firebase-firestore-CNv3xXal.js","assets/vendor-firebase-core-D7GXCeNu.js","assets/vendor-firebase-auth-T_wvTOvf.js","assets/vendor-firebase-storage-Bi7H_66d.js","assets/vendor-firebase-analytics-rHarj5hR.js","assets/vendor-radix-C5nwdvGr.js","assets/vendor-charts-CAmziV1y.js","assets/vendor-markdown-yqZQ_iQm.js","assets/vendor-markdown-CfVKi3_s.css","assets/index-CIg5rXpX.css"])))=>i.map(i=>d[i]); -import{aG as B,u as z,_ as F,h as C,m as I,O as H}from"./index-BufUS6SI.js";import{r,j as e}from"./vendor-react-B4AQeu28.js";import{B as O}from"./button-DsnZWCoA.js";import{I as A}from"./input-BPglbGHJ.js";import W from"./ChatMarkdown-BrSWjY6i.js";import{P as G}from"./plus-B4qs4LzO.js";import{S as Y}from"./search-DFK_sFlt.js";import{T as Q}from"./trash-2-CBXOjqKg.js";import{C as q}from"./chevron-left-DMbkPbec.js";import{S as K}from"./send-DsMS4hUP.js";import"./vendor-firebase-firestore-CNv3xXal.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-radix-C5nwdvGr.js";import"./vendor-charts-CAmziV1y.js";import"./vendor-markdown-yqZQ_iQm.js";function U(a){return a?a instanceof Date?a.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):typeof a=="object"&&"toDate"in a?a.toDate().toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):String(a):""}const ue=()=>{const{sessions:a,activeSessionId:o,isLoading:l,loadingSessionId:L,setActiveSessionId:n,createNewSession:c,sendMessage:T,deleteSession:_,getActiveSession:M,sessionsLoaded:g}=B(),{userProfile:m}=z(),[x,P]=r.useState(""),[i,y]=r.useState(""),[j,w]=r.useState(!1),h=r.useRef(null),u=r.useRef(!0),p=r.useRef(!1),d=M(),f=d?.messages||[],D=f.some(t=>t.sender==="ai"&&t.id.startsWith("stream-")),v=l&&o===L&&!D,N=(t="auto")=>{const s=h.current;s&&s.scrollTo({top:s.scrollHeight,behavior:t})},E=()=>{const t=h.current;return t?t.scrollHeight-t.scrollTop-t.clientHeight<=120:!0},R=()=>{u.current=E()};r.useEffect(()=>{F(async()=>{const{warmupBackend:t}=await import("./index-BufUS6SI.js").then(s=>s.b8);return{warmupBackend:t}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11])).then(({warmupBackend:t})=>{t()}).catch(t=>{console.warn("AI chat warmup skipped:",t)})},[]),r.useEffect(()=>{if(g&&a.length===0){const t={id:"welcome-"+Date.now(),sender:"ai",text:"Hi! I'm your AI math tutor. What would you like to learn about today?",timestamp:new Date().toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})},s=c(t);n(s)}},[g]),r.useEffect(()=>{if(!u.current)return;const t=window.requestAnimationFrame(()=>N("auto"));return()=>window.cancelAnimationFrame(t)},[f,v]),r.useEffect(()=>{u.current=!0,N("auto")},[o]);const k=async()=>{if(!(!i.trim()||l||j||p.current)){p.current=!0,w(!0);try{let t=o;t||(t=c(),n(t));const s=i.trim();y(""),await T(t,s)}finally{p.current=!1,w(!1)}}},S=()=>{const t={id:"welcome-"+Date.now(),sender:"ai",text:"Hi! I'm your AI math tutor. What would you like to learn about today?",timestamp:new Date().toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})},s=c(t);n(s)},$=(t,s)=>{s.stopPropagation(),_(t)},b=a.filter(t=>t.title.toLowerCase().includes(x.toLowerCase())||t.preview.toLowerCase().includes(x.toLowerCase()));return e.jsxs("div",{className:"h-full min-h-0 overflow-hidden flex md:gap-4 px-0 md:px-4 sm:px-6 xl:px-10 py-0 md:py-6",children:[e.jsxs("div",{className:`${o?"hidden md:flex":"flex"} w-full md:w-80 min-h-0 flex-col bg-[#f7f9fc] rounded-none md:rounded-3xl border-0 md:border border-[#dde3eb] overflow-hidden`,children:[e.jsxs("div",{className:"p-4 border-b border-[#dde3eb] flex-shrink-0",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 md:w-12 md:h-12 bg-gradient-to-r from-sky-600 to-sky-500 rounded-xl md:rounded-2xl flex items-center justify-center shrink-0",children:e.jsx("img",{src:"/avatar/avatar_icon.png",alt:"AI Tutor",className:"w-8 h-8 md:w-10 md:h-10 object-contain drop-shadow-md"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm md:text-base font-bold font-display text-[#0a1628]",children:"L.O.L.I."}),e.jsx("p",{className:"text-[10px] text-[#5a6578]",children:"Your AI Math Tutor"})]})]}),e.jsxs("button",{onClick:S,className:"bg-gradient-to-r from-sky-600 to-sky-500 hover:from-sky-700 hover:to-sky-600 text-white px-3 py-2 rounded-xl text-xs font-bold transition-all shadow-md hover:shadow-lg flex items-center justify-center gap-1.5 shrink-0",children:[e.jsx(G,{size:14}),"New Chat"]})]}),e.jsxs("div",{className:"relative mt-3",children:[e.jsx(Y,{className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-500",size:14}),e.jsx(A,{type:"text",placeholder:"Search conversations...",value:x,onChange:t=>P(t.target.value),className:"w-full pl-9 pr-3 py-2 text-xs rounded-xl border-[#dde3eb] focus:border-sky-600 focus:ring-2 focus:ring-sky-100"})]})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-3 space-y-2",children:[e.jsx("div",{className:"flex items-center justify-between mb-2 px-2",children:e.jsxs("span",{className:"text-xs font-bold text-[#5a6578]",children:[b.length," Conversations"]})}),e.jsx(C,{children:b.map(t=>e.jsxs(I.div,{initial:{opacity:0,x:-20},animate:{opacity:1,x:0},exit:{opacity:0,x:-20},onClick:()=>n(t.id),className:`group p-3 rounded-2xl cursor-pointer transition-all duration-200 border relative ${o===t.id?"bg-sky-50 border-sky-200 shadow-sm":"bg-[#edf1f7] border-transparent hover:bg-[#dde3eb] hover:border-[#dde3eb]"}`,children:[e.jsxs("div",{className:"flex items-start justify-between mb-1",children:[e.jsx("h3",{className:`text-xs font-bold mb-0.5 pr-6 line-clamp-1 ${o===t.id?"text-sky-700":"text-[#0a1628]"}`,children:t.title}),e.jsx("button",{onClick:s=>$(t.id,s),className:"absolute top-2 right-2 p-1.5 rounded-lg opacity-0 group-hover:opacity-100 hover:bg-red-100 text-slate-500 hover:text-red-600 transition-all",children:e.jsx(Q,{size:12})})]}),e.jsx("p",{className:"text-[10px] text-[#5a6578] mb-2 line-clamp-2",children:t.preview}),e.jsxs("div",{className:"flex items-center justify-between text-[10px]",children:[e.jsx("span",{className:"text-slate-500",children:t.date}),e.jsxs("span",{className:`px-2 py-0.5 rounded-full ${o===t.id?"bg-sky-100 text-sky-600":"bg-[#dde3eb] text-[#5a6578]"}`,children:[t.messageCount," msgs"]})]})]},t.id))}),b.length===0&&e.jsxs("div",{className:"text-center py-8",children:[e.jsx("img",{src:"/avatar/avatar_icon.png",alt:"AI Tutor",className:"w-16 h-16 object-contain mx-auto mb-2 opacity-60 drop-shadow-sm grayscale contrast-50"}),e.jsx("p",{className:"text-sm text-slate-500",children:"No conversations found"}),e.jsx("p",{className:"text-xs text-slate-500/60 mt-1",children:"Start a new chat!"})]})]})]}),e.jsx("div",{className:`${o?"flex":"hidden md:flex"} flex-1 min-h-0 flex-col bg-[#f7f9fc] rounded-none md:rounded-3xl border-0 md:border border-[#dde3eb] overflow-hidden`,children:o?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"p-3 md:p-4 border-b border-[#dde3eb] flex items-center justify-between flex-shrink-0 bg-white md:bg-transparent shadow-sm md:shadow-none z-10 relative",children:[e.jsxs("div",{className:"flex items-center gap-2 md:gap-3",children:[e.jsx("button",{onClick:()=>n(null),className:"md:hidden p-1.5 -ml-1 text-slate-500 hover:text-slate-800 rounded-lg hover:bg-slate-100",children:e.jsx(q,{size:20})}),e.jsxs("div",{children:[e.jsx("h2",{className:"font-bold font-display text-[#0a1628] text-sm md:text-base",children:d?.title}),e.jsx("p",{className:"text-[10px] md:text-xs text-[#5a6578]",children:d?.date})]})]}),e.jsx("div",{className:"flex items-center gap-2",children:d?.topics.map((t,s)=>e.jsx("span",{className:"px-3 py-1 bg-sky-50 text-sky-600 text-xs font-bold rounded-lg",children:t},s))})]}),e.jsxs("div",{ref:h,onScroll:R,className:"flex-1 overflow-y-auto overscroll-contain p-4 md:p-6 space-y-4 bg-[#edf1f7] min-h-0",children:[e.jsx(C,{children:f.map(t=>e.jsxs(I.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`flex items-end gap-2 ${t.sender==="user"?"justify-end":"justify-start"}`,children:[t.sender!=="user"&&e.jsx("div",{className:"w-7 h-7 rounded-full bg-gradient-to-r from-sky-600 to-sky-500 flex items-center justify-center flex-shrink-0 mb-1",children:e.jsx("img",{src:"/avatar/avatar_icon.png",alt:"AI",className:"w-5 h-5 object-contain"})}),e.jsxs("div",{className:`max-w-[70%] rounded-2xl px-5 py-3 ${t.sender==="user"?"bg-gradient-to-r from-sky-600 to-sky-500 text-white":"bg-white text-[#0a1628] shadow-md border border-[#dde3eb]"}`,children:[t.sender==="user"?e.jsx("p",{className:"text-sm whitespace-pre-wrap leading-relaxed",children:t.text}):e.jsx(W,{children:t.text}),e.jsx("p",{className:`text-[10px] mt-1.5 ${t.sender==="user"?"text-sky-200":"text-slate-500"}`,children:U(t.timestamp)})]}),t.sender==="user"&&e.jsx(H,{src:m?.photo,name:m?.name,gender:m?.gender,className:"w-7 h-7 flex-shrink-0 mb-1",fallbackClassName:"text-[10px]"})]},t.id))}),v&&e.jsx("div",{className:"flex justify-start",children:e.jsx("div",{className:"bg-white text-[#0a1628] shadow-md border border-[#dde3eb] rounded-2xl px-5 py-3 max-w-[70%]",children:e.jsxs("div",{className:"flex gap-1",children:[e.jsx("div",{className:"w-2 h-2 bg-sky-400 rounded-full animate-bounce"}),e.jsx("div",{className:"w-2 h-2 bg-sky-400 rounded-full animate-bounce [animation-delay:150ms]"}),e.jsx("div",{className:"w-2 h-2 bg-sky-400 rounded-full animate-bounce [animation-delay:300ms]"})]})})})]}),e.jsx("div",{className:"p-3 md:p-4 border-t border-[#dde3eb] bg-white flex-shrink-0",children:e.jsxs("div",{className:"flex gap-2 md:gap-3",children:[e.jsx(A,{type:"text",value:i,onChange:t=>y(t.target.value),onKeyPress:t=>t.key==="Enter"&&k(),placeholder:"Ask me anything about math...",className:"flex-1 px-5 py-3 rounded-xl border-[#dde3eb] focus:border-sky-600 focus:ring-2 focus:ring-sky-100 text-sm"}),e.jsx(O,{onClick:k,disabled:!i.trim()||l||j,className:"px-6 bg-gradient-to-r from-sky-600 to-sky-500 hover:from-sky-700 hover:to-sky-600 text-white rounded-xl transition-all disabled:opacity-50 disabled:cursor-not-allowed shadow-md hover:shadow-lg",children:e.jsx(K,{size:18})})]})})]}):e.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center p-8 text-center",children:[e.jsx("div",{className:"w-24 h-24 bg-gradient-to-r from-sky-100 to-cyan-100 rounded-3xl flex items-center justify-center mb-6",children:e.jsx("img",{src:"/avatar/avatar_icon.png",alt:"AI Tutor",className:"w-20 h-20 object-contain drop-shadow-lg"})}),e.jsx("h2",{className:"text-2xl font-bold font-display text-[#0a1628] mb-1",children:"Welcome to L.O.L.I."}),e.jsx("p",{className:"text-sky-600 text-sm font-bold tracking-wide uppercase mb-4",children:"Logical Operations & Learning Intelligence"}),e.jsx("p",{className:"text-[#5a6578] mb-6 max-w-md",children:"Your personal AI math tutor is here to help! Start a new conversation or select one from the sidebar."}),e.jsx("button",{onClick:S,className:"px-6 py-3 bg-gradient-to-r from-sky-600 to-sky-500 hover:from-sky-700 hover:to-sky-600 text-white rounded-xl font-bold shadow-lg hover:shadow-xl transition-all",children:"Start Your First Chat"}),e.jsx("div",{className:"mt-8 grid grid-cols-3 gap-4 max-w-2xl",children:["Algebra","Geometry","Calculus"].map(t=>e.jsxs("div",{className:"p-4 bg-[#edf1f7] rounded-xl border border-[#dde3eb]",children:[e.jsx("p",{className:"text-sm font-bold text-[#0a1628]",children:t}),e.jsxs("p",{className:"text-xs text-[#5a6578] mt-1",children:["Get help with ",t.toLowerCase()]})]},t))})]})})]})};export{ue as default}; +const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-Bp7MiGcW.js","assets/vendor-react-B4AQeu28.js","assets/vendor-firebase-firestore-CNv3xXal.js","assets/vendor-firebase-core-D7GXCeNu.js","assets/vendor-firebase-auth-T_wvTOvf.js","assets/vendor-firebase-storage-Bi7H_66d.js","assets/vendor-firebase-analytics-rHarj5hR.js","assets/vendor-radix-C5nwdvGr.js","assets/vendor-charts-CAmziV1y.js","assets/vendor-markdown-yqZQ_iQm.js","assets/vendor-markdown-CfVKi3_s.css","assets/index-Dja0MwoB.css"])))=>i.map(i=>d[i]); +import{aG as B,u as z,_ as F,h as C,m as I,O as H}from"./index-Bp7MiGcW.js";import{r,j as e}from"./vendor-react-B4AQeu28.js";import{B as O}from"./button-BMVm9YQO.js";import{I as A}from"./input-Co0dljwe.js";import W from"./ChatMarkdown-Cwsa2RCx.js";import{P as G}from"./plus-D4SEqrVj.js";import{S as Y}from"./search-DbD51Zen.js";import{T as Q}from"./trash-2-BhUbBhdb.js";import{C as q}from"./chevron-left-Be5knpOV.js";import{S as K}from"./send-BA-OOIJf.js";import"./vendor-firebase-firestore-CNv3xXal.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-radix-C5nwdvGr.js";import"./vendor-charts-CAmziV1y.js";import"./vendor-markdown-yqZQ_iQm.js";function U(a){return a?a instanceof Date?a.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):typeof a=="object"&&"toDate"in a?a.toDate().toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):String(a):""}const ue=()=>{const{sessions:a,activeSessionId:o,isLoading:l,loadingSessionId:L,setActiveSessionId:n,createNewSession:c,sendMessage:T,deleteSession:_,getActiveSession:M,sessionsLoaded:g}=B(),{userProfile:m}=z(),[x,P]=r.useState(""),[i,y]=r.useState(""),[j,w]=r.useState(!1),h=r.useRef(null),u=r.useRef(!0),p=r.useRef(!1),d=M(),f=d?.messages||[],D=f.some(t=>t.sender==="ai"&&t.id.startsWith("stream-")),v=l&&o===L&&!D,N=(t="auto")=>{const s=h.current;s&&s.scrollTo({top:s.scrollHeight,behavior:t})},E=()=>{const t=h.current;return t?t.scrollHeight-t.scrollTop-t.clientHeight<=120:!0},R=()=>{u.current=E()};r.useEffect(()=>{F(async()=>{const{warmupBackend:t}=await import("./index-Bp7MiGcW.js").then(s=>s.b8);return{warmupBackend:t}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11])).then(({warmupBackend:t})=>{t()}).catch(t=>{console.warn("AI chat warmup skipped:",t)})},[]),r.useEffect(()=>{if(g&&a.length===0){const t={id:"welcome-"+Date.now(),sender:"ai",text:"Hi! I'm your AI math tutor. What would you like to learn about today?",timestamp:new Date().toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})},s=c(t);n(s)}},[g]),r.useEffect(()=>{if(!u.current)return;const t=window.requestAnimationFrame(()=>N("auto"));return()=>window.cancelAnimationFrame(t)},[f,v]),r.useEffect(()=>{u.current=!0,N("auto")},[o]);const k=async()=>{if(!(!i.trim()||l||j||p.current)){p.current=!0,w(!0);try{let t=o;t||(t=c(),n(t));const s=i.trim();y(""),await T(t,s)}finally{p.current=!1,w(!1)}}},S=()=>{const t={id:"welcome-"+Date.now(),sender:"ai",text:"Hi! I'm your AI math tutor. What would you like to learn about today?",timestamp:new Date().toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})},s=c(t);n(s)},$=(t,s)=>{s.stopPropagation(),_(t)},b=a.filter(t=>t.title.toLowerCase().includes(x.toLowerCase())||t.preview.toLowerCase().includes(x.toLowerCase()));return e.jsxs("div",{className:"h-full min-h-0 overflow-hidden flex md:gap-4 px-0 md:px-4 sm:px-6 xl:px-10 py-0 md:py-6",children:[e.jsxs("div",{className:`${o?"hidden md:flex":"flex"} w-full md:w-80 min-h-0 flex-col bg-[#f7f9fc] rounded-none md:rounded-3xl border-0 md:border border-[#dde3eb] overflow-hidden`,children:[e.jsxs("div",{className:"p-4 border-b border-[#dde3eb] flex-shrink-0",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 md:w-12 md:h-12 bg-gradient-to-r from-sky-600 to-sky-500 rounded-xl md:rounded-2xl flex items-center justify-center shrink-0",children:e.jsx("img",{src:"/avatar/avatar_icon.png",alt:"AI Tutor",className:"w-8 h-8 md:w-10 md:h-10 object-contain drop-shadow-md"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm md:text-base font-bold font-display text-[#0a1628]",children:"L.O.L.I."}),e.jsx("p",{className:"text-[10px] text-[#5a6578]",children:"Your AI Math Tutor"})]})]}),e.jsxs("button",{onClick:S,className:"bg-gradient-to-r from-sky-600 to-sky-500 hover:from-sky-700 hover:to-sky-600 text-white px-3 py-2 rounded-xl text-xs font-bold transition-all shadow-md hover:shadow-lg flex items-center justify-center gap-1.5 shrink-0",children:[e.jsx(G,{size:14}),"New Chat"]})]}),e.jsxs("div",{className:"relative mt-3",children:[e.jsx(Y,{className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-500",size:14}),e.jsx(A,{type:"text",placeholder:"Search conversations...",value:x,onChange:t=>P(t.target.value),className:"w-full pl-9 pr-3 py-2 text-xs rounded-xl border-[#dde3eb] focus:border-sky-600 focus:ring-2 focus:ring-sky-100"})]})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-3 space-y-2",children:[e.jsx("div",{className:"flex items-center justify-between mb-2 px-2",children:e.jsxs("span",{className:"text-xs font-bold text-[#5a6578]",children:[b.length," Conversations"]})}),e.jsx(C,{children:b.map(t=>e.jsxs(I.div,{initial:{opacity:0,x:-20},animate:{opacity:1,x:0},exit:{opacity:0,x:-20},onClick:()=>n(t.id),className:`group p-3 rounded-2xl cursor-pointer transition-all duration-200 border relative ${o===t.id?"bg-sky-50 border-sky-200 shadow-sm":"bg-[#edf1f7] border-transparent hover:bg-[#dde3eb] hover:border-[#dde3eb]"}`,children:[e.jsxs("div",{className:"flex items-start justify-between mb-1",children:[e.jsx("h3",{className:`text-xs font-bold mb-0.5 pr-6 line-clamp-1 ${o===t.id?"text-sky-700":"text-[#0a1628]"}`,children:t.title}),e.jsx("button",{onClick:s=>$(t.id,s),className:"absolute top-2 right-2 p-1.5 rounded-lg opacity-0 group-hover:opacity-100 hover:bg-red-100 text-slate-500 hover:text-red-600 transition-all",children:e.jsx(Q,{size:12})})]}),e.jsx("p",{className:"text-[10px] text-[#5a6578] mb-2 line-clamp-2",children:t.preview}),e.jsxs("div",{className:"flex items-center justify-between text-[10px]",children:[e.jsx("span",{className:"text-slate-500",children:t.date}),e.jsxs("span",{className:`px-2 py-0.5 rounded-full ${o===t.id?"bg-sky-100 text-sky-600":"bg-[#dde3eb] text-[#5a6578]"}`,children:[t.messageCount," msgs"]})]})]},t.id))}),b.length===0&&e.jsxs("div",{className:"text-center py-8",children:[e.jsx("img",{src:"/avatar/avatar_icon.png",alt:"AI Tutor",className:"w-16 h-16 object-contain mx-auto mb-2 opacity-60 drop-shadow-sm grayscale contrast-50"}),e.jsx("p",{className:"text-sm text-slate-500",children:"No conversations found"}),e.jsx("p",{className:"text-xs text-slate-500/60 mt-1",children:"Start a new chat!"})]})]})]}),e.jsx("div",{className:`${o?"flex":"hidden md:flex"} flex-1 min-h-0 flex-col bg-[#f7f9fc] rounded-none md:rounded-3xl border-0 md:border border-[#dde3eb] overflow-hidden`,children:o?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"p-3 md:p-4 border-b border-[#dde3eb] flex items-center justify-between flex-shrink-0 bg-white md:bg-transparent shadow-sm md:shadow-none z-10 relative",children:[e.jsxs("div",{className:"flex items-center gap-2 md:gap-3",children:[e.jsx("button",{onClick:()=>n(null),className:"md:hidden p-1.5 -ml-1 text-slate-500 hover:text-slate-800 rounded-lg hover:bg-slate-100",children:e.jsx(q,{size:20})}),e.jsxs("div",{children:[e.jsx("h2",{className:"font-bold font-display text-[#0a1628] text-sm md:text-base",children:d?.title}),e.jsx("p",{className:"text-[10px] md:text-xs text-[#5a6578]",children:d?.date})]})]}),e.jsx("div",{className:"flex items-center gap-2",children:d?.topics.map((t,s)=>e.jsx("span",{className:"px-3 py-1 bg-sky-50 text-sky-600 text-xs font-bold rounded-lg",children:t},s))})]}),e.jsxs("div",{ref:h,onScroll:R,className:"flex-1 overflow-y-auto overscroll-contain p-4 md:p-6 space-y-4 bg-[#edf1f7] min-h-0",children:[e.jsx(C,{children:f.map(t=>e.jsxs(I.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`flex items-end gap-2 ${t.sender==="user"?"justify-end":"justify-start"}`,children:[t.sender!=="user"&&e.jsx("div",{className:"w-7 h-7 rounded-full bg-gradient-to-r from-sky-600 to-sky-500 flex items-center justify-center flex-shrink-0 mb-1",children:e.jsx("img",{src:"/avatar/avatar_icon.png",alt:"AI",className:"w-5 h-5 object-contain"})}),e.jsxs("div",{className:`max-w-[70%] rounded-2xl px-5 py-3 ${t.sender==="user"?"bg-gradient-to-r from-sky-600 to-sky-500 text-white":"bg-white text-[#0a1628] shadow-md border border-[#dde3eb]"}`,children:[t.sender==="user"?e.jsx("p",{className:"text-sm whitespace-pre-wrap leading-relaxed",children:t.text}):e.jsx(W,{children:t.text}),e.jsx("p",{className:`text-[10px] mt-1.5 ${t.sender==="user"?"text-sky-200":"text-slate-500"}`,children:U(t.timestamp)})]}),t.sender==="user"&&e.jsx(H,{src:m?.photo,name:m?.name,gender:m?.gender,className:"w-7 h-7 flex-shrink-0 mb-1",fallbackClassName:"text-[10px]"})]},t.id))}),v&&e.jsx("div",{className:"flex justify-start",children:e.jsx("div",{className:"bg-white text-[#0a1628] shadow-md border border-[#dde3eb] rounded-2xl px-5 py-3 max-w-[70%]",children:e.jsxs("div",{className:"flex gap-1",children:[e.jsx("div",{className:"w-2 h-2 bg-sky-400 rounded-full animate-bounce"}),e.jsx("div",{className:"w-2 h-2 bg-sky-400 rounded-full animate-bounce [animation-delay:150ms]"}),e.jsx("div",{className:"w-2 h-2 bg-sky-400 rounded-full animate-bounce [animation-delay:300ms]"})]})})})]}),e.jsx("div",{className:"p-3 md:p-4 border-t border-[#dde3eb] bg-white flex-shrink-0",children:e.jsxs("div",{className:"flex gap-2 md:gap-3",children:[e.jsx(A,{type:"text",value:i,onChange:t=>y(t.target.value),onKeyPress:t=>t.key==="Enter"&&k(),placeholder:"Ask me anything about math...",className:"flex-1 px-5 py-3 rounded-xl border-[#dde3eb] focus:border-sky-600 focus:ring-2 focus:ring-sky-100 text-sm"}),e.jsx(O,{onClick:k,disabled:!i.trim()||l||j,className:"px-6 bg-gradient-to-r from-sky-600 to-sky-500 hover:from-sky-700 hover:to-sky-600 text-white rounded-xl transition-all disabled:opacity-50 disabled:cursor-not-allowed shadow-md hover:shadow-lg",children:e.jsx(K,{size:18})})]})})]}):e.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center p-8 text-center",children:[e.jsx("div",{className:"w-24 h-24 bg-gradient-to-r from-sky-100 to-cyan-100 rounded-3xl flex items-center justify-center mb-6",children:e.jsx("img",{src:"/avatar/avatar_icon.png",alt:"AI Tutor",className:"w-20 h-20 object-contain drop-shadow-lg"})}),e.jsx("h2",{className:"text-2xl font-bold font-display text-[#0a1628] mb-1",children:"Welcome to L.O.L.I."}),e.jsx("p",{className:"text-sky-600 text-sm font-bold tracking-wide uppercase mb-4",children:"Logical Operations & Learning Intelligence"}),e.jsx("p",{className:"text-[#5a6578] mb-6 max-w-md",children:"Your personal AI math tutor is here to help! Start a new conversation or select one from the sidebar."}),e.jsx("button",{onClick:S,className:"px-6 py-3 bg-gradient-to-r from-sky-600 to-sky-500 hover:from-sky-700 hover:to-sky-600 text-white rounded-xl font-bold shadow-lg hover:shadow-xl transition-all",children:"Start Your First Chat"}),e.jsx("div",{className:"mt-8 grid grid-cols-3 gap-4 max-w-2xl",children:["Algebra","Geometry","Calculus"].map(t=>e.jsxs("div",{className:"p-4 bg-[#edf1f7] rounded-xl border border-[#dde3eb]",children:[e.jsx("p",{className:"text-sm font-bold text-[#0a1628]",children:t}),e.jsxs("p",{className:"text-xs text-[#5a6578] mt-1",children:["Get help with ",t.toLowerCase()]})]},t))})]})})]})};export{ue as default}; diff --git a/assets/AdminDashboard-6u-n_Aj4.js b/assets/AdminDashboard-BbvhhwJY.js similarity index 98% rename from assets/AdminDashboard-6u-n_Aj4.js rename to assets/AdminDashboard-BbvhhwJY.js index 9f314378b69d2659df36143036d48445778c366d..f45fc12833f6e931903f32e62591b27c5121400f 100644 --- a/assets/AdminDashboard-6u-n_Aj4.js +++ b/assets/AdminDashboard-BbvhhwJY.js @@ -1,4 +1,4 @@ -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-bryEim00.js";import ct from"./ConfirmModal-B3J78vrR.js";import{e as we,o as Te,g as M,n as Se,j as S,h as _t,m as re,q as V,R as Me,k as Ot,v as Cs,Q as Bt,S as Gt,p 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-BufUS6SI.js";import{B as E}from"./button-DsnZWCoA.js";import{S as J,a as ee,b as Ue,c as se,d as C}from"./select-CPMGrUkA.js";import{I as xe}from"./input-BPglbGHJ.js";import{S as rs}from"./subjects-D9a9cUC-.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-gDf1MsBj.js";import{D as fe}from"./LogoutActionButton-ke8I5kxg.js";import{F as Ce,A as _e,N as aa}from"./NotificationDropdown-BwLtHvqY.js";import{T as je}from"./trash-2-CBXOjqKg.js";import{S as Xs}from"./sparkles-DYlMf97S.js";import{S as Ks,D as ht,a as pt,b as ut,c as gt,e as la}from"./dialog-JRlpFJpo.js";import{D as Ps}from"./download-DGNoiQkf.js";import{S as zs}from"./shield-check-DMfBBdB0.js";import{S as bt}from"./search-DFK_sFlt.js";import{C as Rs}from"./clock-CooTZK0X.js";import{E as ft,a as ra}from"./eye-CDIJHn8i.js";import{C as jt}from"./chevron-left-DMbkPbec.js";import{C as vt}from"./chevron-right-DADygX42.js";import{C as Re}from"./circle-alert-DDdeEgNa.js";import{I as wt}from"./info-a-Ci1_jf.js";import{C as ia,a as na}from"./vendor-radix-C5nwdvGr.js";import{C as ca}from"./check-B-qbiSF7.js";import{M as oa}from"./mail-d6dXXOFo.js";import{P as Ys}from"./plus-B4qs4LzO.js";import{S as Nt}from"./save-CwINi309.js";import{C as da}from"./chart-column-BcVJ31XT.js";import{u as xa}from"./useQuery-BQZpC2ch.js";import{X as Ms}from"./x-BuBjuj2Y.js";import{D as ma}from"./dollar-sign-DWySnopv.js";import{S as ha}from"./switch-Cwzq1Jz4.js";import{u as pa,t as ua,a as ga}from"./useSubjectAvailability-BXzXJ4_J.js";import{C as ba}from"./chevron-up-CoNRuMZ7.js";import{C as fa}from"./circle-help-DNA0h1v1.js";import{B as ja}from"./bell-D9j1Gy0m.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-BzgmgbHa.js";import"./tooltip-qcWo8nUO.js";import"./shirt-18q8_SAr.js";import"./log-out-Cp6gBYHP.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-cESSXRCA.js";/** +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-BzRsh0CN.js";import ct from"./ConfirmModal-CH3zQe0u.js";import{e as we,o as Te,g as M,n as Se,j as S,h as _t,m as re,q as V,R as Me,k as Ot,v as Cs,Q as Bt,S as Gt,p 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-Bp7MiGcW.js";import{B as E}from"./button-BMVm9YQO.js";import{S as J,a as ee,b as Ue,c as se,d as C}from"./select-CNQuOudF.js";import{I as xe}from"./input-Co0dljwe.js";import{S as rs}from"./subjects-DNoBzeBL.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-CP6O7WIX.js";import{D as fe}from"./LogoutActionButton-BlHbD8Uf.js";import{F as Ce,A as _e,N as aa}from"./NotificationDropdown-DNm6nFOm.js";import{T as je}from"./trash-2-BhUbBhdb.js";import{S as Xs}from"./sparkles-fLB3ltj1.js";import{S as Ks,D as ht,a as pt,b as ut,c as gt,e as la}from"./dialog-C3ON9pD8.js";import{D as Ps}from"./download-DFL4ZCXr.js";import{S as zs}from"./shield-check-qhTHRSP5.js";import{S as bt}from"./search-DbD51Zen.js";import{C as Rs}from"./clock-Cc6sJz1J.js";import{E as ft,a as ra}from"./eye-B_U0s6fm.js";import{C as jt}from"./chevron-left-Be5knpOV.js";import{C as vt}from"./chevron-right-BxoysOas.js";import{C as Re}from"./circle-alert-CHGy8HcB.js";import{I as wt}from"./info-Bcg_cBHY.js";import{C as ia,a as na}from"./vendor-radix-C5nwdvGr.js";import{C as ca}from"./check-qsSFTYCr.js";import{M as oa}from"./mail-jAg7cqFw.js";import{P as Ys}from"./plus-D4SEqrVj.js";import{S as Nt}from"./save-D7oNX_Ki.js";import{C as da}from"./chart-column-Dyv8TfXk.js";import{u as xa}from"./useQuery-DN_XJYxl.js";import{X as Ms}from"./x-k8d6VLEw.js";import{D as ma}from"./dollar-sign-Dm4HJ6Ci.js";import{S as ha}from"./switch-C4JL2ii9.js";import{u as pa,t as ua,a as ga}from"./useSubjectAvailability-Dm-85m8R.js";import{C as ba}from"./chevron-up-DtS9MvUZ.js";import{C as fa}from"./circle-help-CLCoBWDy.js";import{B as ja}from"./bell-DyLbgepV.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-DzQphSnP.js";import"./tooltip-nLNeX3nd.js";import"./shirt-C1GQiNvP.js";import"./log-out-DrAbcVI9.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-D-5-www2.js";/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. diff --git a/assets/AssessmentPage-CmqDSE0L.js b/assets/AssessmentPage-D6fgX4f6.js similarity index 95% rename from assets/AssessmentPage-CmqDSE0L.js rename to assets/AssessmentPage-D6fgX4f6.js index c054a6d594a2d6d47f09ccf70b8c190be6abedcb..0e95cec015c8f1d0e716d50d1fec350ce85cb34d 100644 --- a/assets/AssessmentPage-CmqDSE0L.js +++ b/assets/AssessmentPage-D6fgX4f6.js @@ -1,7 +1,7 @@ -const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/pipelineService-BxyJyUSp.js","assets/index-BufUS6SI.js","assets/vendor-react-B4AQeu28.js","assets/vendor-firebase-firestore-CNv3xXal.js","assets/vendor-firebase-core-D7GXCeNu.js","assets/vendor-firebase-auth-T_wvTOvf.js","assets/vendor-firebase-storage-Bi7H_66d.js","assets/vendor-firebase-analytics-rHarj5hR.js","assets/vendor-radix-C5nwdvGr.js","assets/vendor-charts-CAmziV1y.js","assets/vendor-markdown-yqZQ_iQm.js","assets/vendor-markdown-CfVKi3_s.css","assets/index-CIg5rXpX.css"])))=>i.map(i=>d[i]); -import{e as V,_ as M,m as i,Z,h as G,T as H,F as W,r as X}from"./index-BufUS6SI.js";import{r,j as e}from"./vendor-react-B4AQeu28.js";import{B as K}from"./button-DsnZWCoA.js";import{s as ee}from"./diagnosticService-B5t8MYB4.js";import{M as te}from"./maximize-2-DJehxXl_.js";import{X as se}from"./x-BuBjuj2Y.js";import{C as ne}from"./clock-CooTZK0X.js";import{C as re}from"./circle-check-big-CDg2qLfH.js";import{C as ae}from"./chevron-right-DADygX42.js";import"./vendor-firebase-firestore-CNv3xXal.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-radix-C5nwdvGr.js";import"./vendor-charts-CAmziV1y.js";import"./vendor-markdown-yqZQ_iQm.js";/** +const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/pipelineService-D7yl0SJO.js","assets/index-Bp7MiGcW.js","assets/vendor-react-B4AQeu28.js","assets/vendor-firebase-firestore-CNv3xXal.js","assets/vendor-firebase-core-D7GXCeNu.js","assets/vendor-firebase-auth-T_wvTOvf.js","assets/vendor-firebase-storage-Bi7H_66d.js","assets/vendor-firebase-analytics-rHarj5hR.js","assets/vendor-radix-C5nwdvGr.js","assets/vendor-charts-CAmziV1y.js","assets/vendor-markdown-yqZQ_iQm.js","assets/vendor-markdown-CfVKi3_s.css","assets/index-Dja0MwoB.css"])))=>i.map(i=>d[i]); +import{e as V,_ as M,m as i,Z,h as G,T as H,F as W,r as X}from"./index-Bp7MiGcW.js";import{r,j as e}from"./vendor-react-B4AQeu28.js";import{B as K}from"./button-BMVm9YQO.js";import{s as ee}from"./diagnosticService-E5zPXoFs.js";import{M as te}from"./maximize-2-CWmKKmit.js";import{X as se}from"./x-k8d6VLEw.js";import{C as ne}from"./clock-Cc6sJz1J.js";import{C as re}from"./circle-check-big-JdaMs3bP.js";import{C as ae}from"./chevron-right-BxoysOas.js";import"./vendor-firebase-firestore-CNv3xXal.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-radix-C5nwdvGr.js";import"./vendor-charts-CAmziV1y.js";import"./vendor-markdown-yqZQ_iQm.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 ie=[["polyline",{points:"4 14 10 14 10 20",key:"11kfnr"}],["polyline",{points:"20 10 14 10 14 4",key:"rlmsce"}],["line",{x1:"14",x2:"21",y1:"10",y2:"3",key:"o5lafz"}],["line",{x1:"3",x2:"10",y1:"21",y2:"14",key:"1atl0r"}]],le=V("minimize-2",ie),Se=({testId:T,questions:f,userName:$,onComplete:B,onCancel:L})=>{const[h,_]=r.useState("testing"),[a,S]=r.useState(0),[o,b]=r.useState(null),[u,E]=r.useState(()=>{try{const t=sessionStorage.getItem("mathpulse_diagnostic_responses");return t?JSON.parse(t):[]}catch{return[]}}),[g,k]=r.useState([]),[x,z]=r.useState(0),[C,D]=r.useState(null),[A,w]=r.useState(!1),c=r.useRef(null),F=r.useRef(Date.now()),p=r.useRef(!1),d=f.length,l=f[a],P=Math.round((a+(o?1:0))/d*100),v=t=>t==="easy"?60:t==="hard"?120:90,[q]=r.useState(Array.from({length:10},(t,s)=>({id:s,size:Math.random()*80+30,x:Math.random()*100,y:Math.random()*100,duration:Math.random()*20+15,delay:Math.random()*-20,color:["bg-purple-500/10","bg-blue-500/10","bg-cyan-500/10","bg-emerald-500/10"][Math.floor(Math.random()*4)]})));r.useEffect(()=>{const t=v(l?.difficulty||"medium");return F.current=Date.now(),p.current=!1,z(t),c.current&&clearInterval(c.current),c.current=setInterval(()=>{const s=Math.floor((Date.now()-F.current)/1e3),n=Math.max(0,t-s);z(n),n<=0&&!p.current&&(p.current=!0,clearInterval(c.current))},250),()=>{c.current&&clearInterval(c.current)}},[a]),r.useEffect(()=>{if(x===0&&p.current&&h==="testing"){const t=v(l?.difficulty||"medium"),s=[...u,{question_id:l.question_id,student_answer:o||"",time_spent_seconds:t}],n=[...g,!1];k(n),E(s),b(null),am+1):I(s)}},[x]);const O=r.useCallback(()=>{const t=document.getElementById("assessment-container");t&&(document.fullscreenElement?document.exitFullscreen&&document.exitFullscreen().then(()=>{w(!1)}).catch(s=>{console.error("Exit fullscreen error:",s)}):t.requestFullscreen().then(()=>{w(!0)}).catch(s=>{console.error("Fullscreen error:",s)}))},[]);r.useEffect(()=>{const t=()=>{w(!!document.fullscreenElement)};return document.addEventListener("fullscreenchange",t),()=>document.removeEventListener("fullscreenchange",t)},[]);const Q=t=>{b(t)},U=()=>{if(!o)return;c.current&&clearInterval(c.current);const t=v(l?.difficulty||"medium")-x,s=[...g,!0],n=[...u,{question_id:l.question_id,student_answer:o,time_spent_seconds:t}];k(s),E(n),b(null),am+1):I(n)},I=async t=>{_("submitting"),D(null);try{sessionStorage.setItem("mathpulse_diagnostic_responses",JSON.stringify(t))}catch{}try{const s=await ee(T,t);sessionStorage.removeItem("mathpulse_diagnostic"),sessionStorage.removeItem("mathpulse_diagnostic_responses"),_("results");try{const{emitPipelineEvent:n,getStudentContext:m}=await M(async()=>{const{emitPipelineEvent:j,getStudentContext:N}=await import("./pipelineService-BxyJyUSp.js");return{emitPipelineEvent:j,getStudentContext:N}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12])),{auth:R}=await M(async()=>{const{auth:j}=await import("./index-BufUS6SI.js").then(N=>N.b7);return{auth:j}},__vite__mapDeps([1,2,3,4,5,6,7,8,9,10,11,12])),y=m();y&&R.currentUser&&n({student_id:R.currentUser.uid,event_type:"diagnostic",event_data:{overall_score:s.overall_score_percent,mastery_summary:s.mastery_summary},occurred_at:new Date().toISOString(),class_id:y.classId,teacher_id:y.teacherId})}catch{}setTimeout(()=>{B({overallRisk:s.overall_risk,overallScorePercent:s.overall_score_percent,intervention:s.recommended_intervention,xpEarned:s.xp_earned,badgeUnlocked:s.badge_unlocked})},3e3)}catch(s){const n=s instanceof Error?s.message:"Submission failed. Your answers are saved locally.";D(n)}},Y=t=>{const s=Math.floor(t/60),n=t%60;return`${s}:${n.toString().padStart(2,"0")}`},J=["A","B","C","D"];return e.jsx("div",{className:"fixed inset-0 z-50 bg-black/60 backdrop-blur-md flex items-center justify-center p-4 sm:p-6 overflow-hidden",children:e.jsxs("div",{id:"assessment-container",className:"bg-white/95 backdrop-blur-xl border border-white/20 rounded-3xl shadow-[0_0_50px_rgba(0,0,0,0.3)] w-full max-w-4xl h-[95vh] sm:h-[90vh] md:h-[85vh] flex flex-col relative z-10 overflow-hidden transition-all duration-300",children:[e.jsx("div",{className:"absolute inset-0 pointer-events-none z-0 overflow-hidden",children:q.map(t=>e.jsx(i.div,{className:`absolute rounded-full blur-3xl ${t.color.replace("/10","/30")}`,style:{width:t.size*1.5,height:t.size*1.5,left:`${t.x}%`,top:`${t.y}%`},animate:{x:[0,Math.random()*100-50,0],y:[0,Math.random()*100-50,0],scale:[1,1.3,1]},transition:{duration:t.duration,repeat:1/0,ease:"linear",delay:t.delay}},t.id))}),e.jsxs(i.div,{className:"shrink-0 text-white border-b border-white/10 shadow-md relative z-10",style:{backgroundColor:"#9956DE"},children:[e.jsxs("div",{className:"flex items-center justify-between p-4 sm:p-5 md:p-6",children:[e.jsxs("div",{className:"flex-1 min-w-0 mr-2",children:[e.jsx("h2",{className:"text-lg sm:text-xl md:text-2xl font-bold truncate",children:"Diagnostic Assessment"}),e.jsxs("p",{className:"text-white/80 text-xs sm:text-sm font-medium truncate",children:[l.domain," • ",l.difficulty]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:O,className:"w-9 h-9 sm:w-10 sm:h-10 bg-white/20 hover:bg-white/30 rounded-xl flex items-center justify-center transition-colors",title:A?"Exit Fullscreen":"Enter Fullscreen",children:A?e.jsx(le,{size:18}):e.jsx(te,{size:18})}),e.jsx("button",{onClick:L,className:"w-9 h-9 sm:w-10 sm:h-10 bg-white/20 hover:bg-white/30 rounded-xl flex items-center justify-center transition-colors",children:e.jsx(se,{size:20})})]})]}),e.jsxs("div",{className:"flex items-center justify-between px-4 sm:px-5 md:px-6 pb-3 sm:pb-4 md:pb-5",children:[e.jsx("div",{className:"flex items-center gap-3",children:e.jsxs("div",{className:"bg-white/20 px-3 py-1 rounded-full flex items-center gap-1",children:[e.jsx(Z,{size:16}),e.jsxs("span",{className:"font-bold text-sm",children:[u.length," / ",d]})]})}),e.jsxs("div",{className:`flex items-center gap-1 px-3 py-1 rounded-full ${x<=10?"bg-red-500/80 animate-pulse":"bg-white/20"}`,children:[e.jsx(ne,{size:16}),e.jsx("span",{className:"font-bold text-sm",children:Y(x)})]})]}),e.jsxs("div",{className:"px-4 sm:px-5 md:px-6 pb-3 sm:pb-4 md:pb-5",children:[e.jsxs("div",{className:"flex justify-between items-center mb-2",children:[e.jsxs("span",{className:"text-sm font-medium",children:["Question ",a+1," of ",d]}),e.jsxs("span",{className:"text-sm font-bold",children:[P,"%"]})]}),e.jsx("div",{className:"flex items-center gap-1",children:f.map((t,s)=>{let n="bg-white/30";return s{const s=l.options[t];if(!s)return null;const n=o===t;let m="bg-[#edf1f7] hover:bg-[#dde3eb] border-[#dde3eb]";return n&&(m="bg-purple-50 border-[#9956DE]"),e.jsx(i.button,{whileHover:{scale:1.01},whileTap:{scale:.99},onClick:()=>Q(t),className:`w-full text-left p-2.5 sm:p-3 md:p-4 rounded-xl border-2 transition-all ${m} cursor-pointer shadow-sm hover:shadow-md flex items-center min-h-[3rem] sm:min-h-[4rem] md:min-h-[5rem]`,children:e.jsxs("div",{className:"flex items-center gap-2 sm:gap-3 w-full min-w-0",children:[e.jsx("div",{className:`w-8 h-8 sm:w-10 sm:h-10 rounded-xl shrink-0 flex items-center justify-center font-bold text-sm sm:text-base ${n?"bg-[#9956DE] text-white shadow-inner":"bg-white text-[#0a1628] shadow-sm"}`,children:t}),e.jsx("span",{className:"font-semibold text-[#0a1628] text-xs sm:text-sm md:text-base break-words",children:s}),n&&e.jsx(re,{size:18,className:"ml-auto text-[#9956DE] flex-shrink-0"})]})},t)})})]},a)})}),e.jsx("div",{className:"p-4 sm:p-5 md:p-6 bg-[#edf1f7] border-t border-[#dde3eb]",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"text-sm text-[#5a6578]",children:o?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(H,{size:16}),"Ready for the next one!"]}):e.jsx("span",{children:x<=10?`Auto-skipping in ${x}s...`:"Select an answer to continue"})}),e.jsxs(K,{onClick:U,disabled:!o,className:`font-bold px-6 py-2.5 sm:py-3 rounded-xl flex items-center gap-2 transition-all shadow-md hover:shadow-lg text-sm ${o?"bg-[#9956DE] hover:bg-[#8850CE] text-white shadow-[#9956DE]/20":"bg-[#dde3eb] text-slate-500 cursor-not-allowed"}`,children:[a=d*.7?"bg-gradient-to-br from-[#75D06A] to-[#6ED1CF]":"bg-gradient-to-br from-[#FFB356] to-[#FF8B8B]"}`,children:u.length>=d*.7?e.jsx(W,{size:48,className:"text-white"}):e.jsx(X,{size:48,className:"text-white"})}),e.jsx("h2",{className:"text-3xl font-bold font-display text-[#0a1628] mb-2",children:"Assessment Complete!"}),e.jsxs("p",{className:"text-[#5a6578] mb-6",children:["Great job, ",$,"! Your personalized learning path is ready."]}),e.jsxs("div",{className:"bg-gradient-to-br from-[#1FA7E1]/10 to-[#6ED1CF]/10 rounded-2xl p-5 mb-5",children:[e.jsxs("div",{className:"text-sm text-[#5a6578] mb-2",children:["You answered ",u.length," questions"]}),e.jsx("div",{className:"text-xs text-[#5a6578]",children:"Results will be available shortly..."})]}),e.jsx("p",{className:"text-xs text-slate-400 mb-4",children:"Redirecting to dashboard..."})]})})]})})};export{Se as default}; + */const ie=[["polyline",{points:"4 14 10 14 10 20",key:"11kfnr"}],["polyline",{points:"20 10 14 10 14 4",key:"rlmsce"}],["line",{x1:"14",x2:"21",y1:"10",y2:"3",key:"o5lafz"}],["line",{x1:"3",x2:"10",y1:"21",y2:"14",key:"1atl0r"}]],le=V("minimize-2",ie),Se=({testId:T,questions:f,userName:$,onComplete:B,onCancel:L})=>{const[h,_]=r.useState("testing"),[a,S]=r.useState(0),[o,b]=r.useState(null),[u,E]=r.useState(()=>{try{const t=sessionStorage.getItem("mathpulse_diagnostic_responses");return t?JSON.parse(t):[]}catch{return[]}}),[g,k]=r.useState([]),[x,z]=r.useState(0),[C,D]=r.useState(null),[A,w]=r.useState(!1),c=r.useRef(null),F=r.useRef(Date.now()),p=r.useRef(!1),d=f.length,l=f[a],P=Math.round((a+(o?1:0))/d*100),v=t=>t==="easy"?60:t==="hard"?120:90,[q]=r.useState(Array.from({length:10},(t,s)=>({id:s,size:Math.random()*80+30,x:Math.random()*100,y:Math.random()*100,duration:Math.random()*20+15,delay:Math.random()*-20,color:["bg-purple-500/10","bg-blue-500/10","bg-cyan-500/10","bg-emerald-500/10"][Math.floor(Math.random()*4)]})));r.useEffect(()=>{const t=v(l?.difficulty||"medium");return F.current=Date.now(),p.current=!1,z(t),c.current&&clearInterval(c.current),c.current=setInterval(()=>{const s=Math.floor((Date.now()-F.current)/1e3),n=Math.max(0,t-s);z(n),n<=0&&!p.current&&(p.current=!0,clearInterval(c.current))},250),()=>{c.current&&clearInterval(c.current)}},[a]),r.useEffect(()=>{if(x===0&&p.current&&h==="testing"){const t=v(l?.difficulty||"medium"),s=[...u,{question_id:l.question_id,student_answer:o||"",time_spent_seconds:t}],n=[...g,!1];k(n),E(s),b(null),am+1):I(s)}},[x]);const O=r.useCallback(()=>{const t=document.getElementById("assessment-container");t&&(document.fullscreenElement?document.exitFullscreen&&document.exitFullscreen().then(()=>{w(!1)}).catch(s=>{console.error("Exit fullscreen error:",s)}):t.requestFullscreen().then(()=>{w(!0)}).catch(s=>{console.error("Fullscreen error:",s)}))},[]);r.useEffect(()=>{const t=()=>{w(!!document.fullscreenElement)};return document.addEventListener("fullscreenchange",t),()=>document.removeEventListener("fullscreenchange",t)},[]);const Q=t=>{b(t)},U=()=>{if(!o)return;c.current&&clearInterval(c.current);const t=v(l?.difficulty||"medium")-x,s=[...g,!0],n=[...u,{question_id:l.question_id,student_answer:o,time_spent_seconds:t}];k(s),E(n),b(null),am+1):I(n)},I=async t=>{_("submitting"),D(null);try{sessionStorage.setItem("mathpulse_diagnostic_responses",JSON.stringify(t))}catch{}try{const s=await ee(T,t);sessionStorage.removeItem("mathpulse_diagnostic"),sessionStorage.removeItem("mathpulse_diagnostic_responses"),_("results");try{const{emitPipelineEvent:n,getStudentContext:m}=await M(async()=>{const{emitPipelineEvent:j,getStudentContext:N}=await import("./pipelineService-D7yl0SJO.js");return{emitPipelineEvent:j,getStudentContext:N}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12])),{auth:R}=await M(async()=>{const{auth:j}=await import("./index-Bp7MiGcW.js").then(N=>N.b7);return{auth:j}},__vite__mapDeps([1,2,3,4,5,6,7,8,9,10,11,12])),y=m();y&&R.currentUser&&n({student_id:R.currentUser.uid,event_type:"diagnostic",event_data:{overall_score:s.overall_score_percent,mastery_summary:s.mastery_summary},occurred_at:new Date().toISOString(),class_id:y.classId,teacher_id:y.teacherId})}catch{}setTimeout(()=>{B({overallRisk:s.overall_risk,overallScorePercent:s.overall_score_percent,intervention:s.recommended_intervention,xpEarned:s.xp_earned,badgeUnlocked:s.badge_unlocked})},3e3)}catch(s){const n=s instanceof Error?s.message:"Submission failed. Your answers are saved locally.";D(n)}},Y=t=>{const s=Math.floor(t/60),n=t%60;return`${s}:${n.toString().padStart(2,"0")}`},J=["A","B","C","D"];return e.jsx("div",{className:"fixed inset-0 z-50 bg-black/60 backdrop-blur-md flex items-center justify-center p-4 sm:p-6 overflow-hidden",children:e.jsxs("div",{id:"assessment-container",className:"bg-white/95 backdrop-blur-xl border border-white/20 rounded-3xl shadow-[0_0_50px_rgba(0,0,0,0.3)] w-full max-w-4xl h-[95vh] sm:h-[90vh] md:h-[85vh] flex flex-col relative z-10 overflow-hidden transition-all duration-300",children:[e.jsx("div",{className:"absolute inset-0 pointer-events-none z-0 overflow-hidden",children:q.map(t=>e.jsx(i.div,{className:`absolute rounded-full blur-3xl ${t.color.replace("/10","/30")}`,style:{width:t.size*1.5,height:t.size*1.5,left:`${t.x}%`,top:`${t.y}%`},animate:{x:[0,Math.random()*100-50,0],y:[0,Math.random()*100-50,0],scale:[1,1.3,1]},transition:{duration:t.duration,repeat:1/0,ease:"linear",delay:t.delay}},t.id))}),e.jsxs(i.div,{className:"shrink-0 text-white border-b border-white/10 shadow-md relative z-10",style:{backgroundColor:"#9956DE"},children:[e.jsxs("div",{className:"flex items-center justify-between p-4 sm:p-5 md:p-6",children:[e.jsxs("div",{className:"flex-1 min-w-0 mr-2",children:[e.jsx("h2",{className:"text-lg sm:text-xl md:text-2xl font-bold truncate",children:"Diagnostic Assessment"}),e.jsxs("p",{className:"text-white/80 text-xs sm:text-sm font-medium truncate",children:[l.domain," • ",l.difficulty]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:O,className:"w-9 h-9 sm:w-10 sm:h-10 bg-white/20 hover:bg-white/30 rounded-xl flex items-center justify-center transition-colors",title:A?"Exit Fullscreen":"Enter Fullscreen",children:A?e.jsx(le,{size:18}):e.jsx(te,{size:18})}),e.jsx("button",{onClick:L,className:"w-9 h-9 sm:w-10 sm:h-10 bg-white/20 hover:bg-white/30 rounded-xl flex items-center justify-center transition-colors",children:e.jsx(se,{size:20})})]})]}),e.jsxs("div",{className:"flex items-center justify-between px-4 sm:px-5 md:px-6 pb-3 sm:pb-4 md:pb-5",children:[e.jsx("div",{className:"flex items-center gap-3",children:e.jsxs("div",{className:"bg-white/20 px-3 py-1 rounded-full flex items-center gap-1",children:[e.jsx(Z,{size:16}),e.jsxs("span",{className:"font-bold text-sm",children:[u.length," / ",d]})]})}),e.jsxs("div",{className:`flex items-center gap-1 px-3 py-1 rounded-full ${x<=10?"bg-red-500/80 animate-pulse":"bg-white/20"}`,children:[e.jsx(ne,{size:16}),e.jsx("span",{className:"font-bold text-sm",children:Y(x)})]})]}),e.jsxs("div",{className:"px-4 sm:px-5 md:px-6 pb-3 sm:pb-4 md:pb-5",children:[e.jsxs("div",{className:"flex justify-between items-center mb-2",children:[e.jsxs("span",{className:"text-sm font-medium",children:["Question ",a+1," of ",d]}),e.jsxs("span",{className:"text-sm font-bold",children:[P,"%"]})]}),e.jsx("div",{className:"flex items-center gap-1",children:f.map((t,s)=>{let n="bg-white/30";return s{const s=l.options[t];if(!s)return null;const n=o===t;let m="bg-[#edf1f7] hover:bg-[#dde3eb] border-[#dde3eb]";return n&&(m="bg-purple-50 border-[#9956DE]"),e.jsx(i.button,{whileHover:{scale:1.01},whileTap:{scale:.99},onClick:()=>Q(t),className:`w-full text-left p-2.5 sm:p-3 md:p-4 rounded-xl border-2 transition-all ${m} cursor-pointer shadow-sm hover:shadow-md flex items-center min-h-[3rem] sm:min-h-[4rem] md:min-h-[5rem]`,children:e.jsxs("div",{className:"flex items-center gap-2 sm:gap-3 w-full min-w-0",children:[e.jsx("div",{className:`w-8 h-8 sm:w-10 sm:h-10 rounded-xl shrink-0 flex items-center justify-center font-bold text-sm sm:text-base ${n?"bg-[#9956DE] text-white shadow-inner":"bg-white text-[#0a1628] shadow-sm"}`,children:t}),e.jsx("span",{className:"font-semibold text-[#0a1628] text-xs sm:text-sm md:text-base break-words",children:s}),n&&e.jsx(re,{size:18,className:"ml-auto text-[#9956DE] flex-shrink-0"})]})},t)})})]},a)})}),e.jsx("div",{className:"p-4 sm:p-5 md:p-6 bg-[#edf1f7] border-t border-[#dde3eb]",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"text-sm text-[#5a6578]",children:o?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(H,{size:16}),"Ready for the next one!"]}):e.jsx("span",{children:x<=10?`Auto-skipping in ${x}s...`:"Select an answer to continue"})}),e.jsxs(K,{onClick:U,disabled:!o,className:`font-bold px-6 py-2.5 sm:py-3 rounded-xl flex items-center gap-2 transition-all shadow-md hover:shadow-lg text-sm ${o?"bg-[#9956DE] hover:bg-[#8850CE] text-white shadow-[#9956DE]/20":"bg-[#dde3eb] text-slate-500 cursor-not-allowed"}`,children:[a=d*.7?"bg-gradient-to-br from-[#75D06A] to-[#6ED1CF]":"bg-gradient-to-br from-[#FFB356] to-[#FF8B8B]"}`,children:u.length>=d*.7?e.jsx(W,{size:48,className:"text-white"}):e.jsx(X,{size:48,className:"text-white"})}),e.jsx("h2",{className:"text-3xl font-bold font-display text-[#0a1628] mb-2",children:"Assessment Complete!"}),e.jsxs("p",{className:"text-[#5a6578] mb-6",children:["Great job, ",$,"! Your personalized learning path is ready."]}),e.jsxs("div",{className:"bg-gradient-to-br from-[#1FA7E1]/10 to-[#6ED1CF]/10 rounded-2xl p-5 mb-5",children:[e.jsxs("div",{className:"text-sm text-[#5a6578] mb-2",children:["You answered ",u.length," questions"]}),e.jsx("div",{className:"text-xs text-[#5a6578]",children:"Results will be available shortly..."})]}),e.jsx("p",{className:"text-xs text-slate-400 mb-4",children:"Redirecting to dashboard..."})]})})]})})};export{Se as default}; diff --git a/assets/AvatarShop-DZiViM0D.js b/assets/AvatarShop-DZiViM0D.js deleted file mode 100644 index 74d9ae81cc8b9db7b770749dfd43869dcf031c47..0000000000000000000000000000000000000000 --- a/assets/AvatarShop-DZiViM0D.js +++ /dev/null @@ -1,31 +0,0 @@ -import{r as i,j as e}from"./vendor-react-B4AQeu28.js";import{e as se,L as ae,g as re,f as oe}from"./vendor-radix-C5nwdvGr.js";import{e as S,u as le,L as w,a6 as R,m as y,h as ie,j as c,aP as ne,aQ as ce}from"./index-BufUS6SI.js";import{u as de}from"./useFeatureAccess-D82RK3T0.js";import{T as me,a as ue,b as xe}from"./tooltip-qcWo8nUO.js";import{C as pe}from"./CompositeAvatar-Col05lJc.js";import{M as j}from"./avatarData-BuQSOXo3.js";import{S as O}from"./save-CwINi309.js";import{S as V}from"./sparkles-DYlMf97S.js";import{S as fe}from"./shirt-18q8_SAr.js";import"./vendor-firebase-firestore-CNv3xXal.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-charts-CAmziV1y.js";import"./vendor-markdown-yqZQ_iQm.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 he=[["path",{d:"M4 16v-2.38C4 11.5 2.97 10.5 3 8c.03-2.72 1.49-6 4.5-6C9.37 2 10 3.8 10 5.5c0 3.11-2 5.66-2 8.68V16a2 2 0 1 1-4 0Z",key:"1dudjm"}],["path",{d:"M20 20v-2.38c0-2.12 1.03-3.12 1-5.62-.03-2.72-1.49-6-4.5-6C14.63 6 14 7.8 14 9.5c0 3.11 2 5.66 2 8.68V20a2 2 0 1 0 4 0Z",key:"l2t8xc"}],["path",{d:"M16 17h4",key:"1dejxt"}],["path",{d:"M4 13h4",key:"1bwh8b"}]],be=S("footprints",he);/** - * @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 ve=[["circle",{cx:"6",cy:"6",r:"3",key:"1lh9wr"}],["path",{d:"M8.12 8.12 12 12",key:"1alkpv"}],["path",{d:"M20 4 8.12 15.88",key:"xgtan2"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}],["path",{d:"M14.8 14.8 20 20",key:"ptml3r"}]],ge=S("scissors",ve);/** - * @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 we=[["path",{d:"M6 2 3 6v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6l-3-4Z",key:"hou9p0"}],["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M16 10a4 4 0 0 1-8 0",key:"1ltviw"}]],N=S("shopping-bag",we),ye=` - @keyframes avatar-float { - 0%, 100% { transform: translateY(-8px); } - 50% { transform: translateY(8px); } - } - @keyframes spin-slow { - from { transform: rotate(0deg); } - to { transform: rotate(360deg); } - } - .animate-avatar-float { - animation: avatar-float 4s ease-in-out infinite; - } - .animate-spin-slow { - animation: spin-slow 1s linear infinite; - } -`,X=["Wow!","Cute!","I love it!","Perfect!","So cool!","Awesome!"],q=["Gain more XP to buy me more clothes!","Help me get stylish!","Let's earn some XP to unlock more!","I'd love to try on more outfits!","Keep learning to unlock new looks!"],Y="top_blue",F="mathpulse:avatar-inventory:v2",je=600*1e3,Ne=2e4,Ye=({onSaveProfile:k,onNavigateToModules:U})=>{const{userProfile:l,refreshProfile:$,currentUser:D}=le(),{cosmeticShop:B,loading:H}=de(D?.uid||null),G=!1,[m,A]=i.useState({top:l?.avatarLayers?.top??Y,bottom:l?.avatarLayers?.bottom||"",shoes:l?.avatarLayers?.shoes||"",accessory:l?.avatarLayers?.accessory||""}),[x,p]=i.useState(!1),[f,E]=i.useState([]),[K,T]=i.useState(0),[P,_]=i.useState(null),[d,h]=i.useState(null),[I,z]=i.useState(j),[Z,J]=i.useState("top"),C=i.useRef(l);C.current=l;const b=i.useRef(!1),v=i.useRef(null);i.useEffect(()=>{if(typeof window>"u")return;const t=Date.now();try{const o=sessionStorage.getItem(F);if(o){const s=JSON.parse(o);if(Array.isArray(s.items)&&typeof s.expiresAt=="number"&&s.expiresAt>t){z(s.items);return}}}catch{}z(j);try{sessionStorage.setItem(F,JSON.stringify({expiresAt:t+je,items:j}))}catch{}},[]),i.useEffect(()=>{if(l&&l.role==="student"){const t=l;E(t.ownedAvatarItems||[]),T(t.currentXP||0)}},[l]),i.useEffect(()=>{A({top:l?.avatarLayers?.top??Y,bottom:l?.avatarLayers?.bottom||"",shoes:l?.avatarLayers?.shoes||"",accessory:l?.avatarLayers?.accessory||""})},[]),i.useEffect(()=>{if(!d){const t=setInterval(()=>{Math.random()>.6&&h(q[Math.floor(Math.random()*q.length)])},4e3);return()=>clearInterval(t)}},[d]),i.useEffect(()=>{if(d){const t=setTimeout(()=>{h(null)},3500);return()=>clearTimeout(t)}},[d]);const Q=(t,o)=>{const s=I.find(n=>n.id===o);if(s&&(s.price&&s.price>0||s.isReward)&&!f.includes(o)){c.error("This item is locked. Earn or purchase it first!");return}const a={...m,[t]:m[t]===o?"":o};A(a),h(X[Math.floor(Math.random()*X.length)]),g(a,{showSuccessToast:!1,showSavingState:!1})},W=async(t,o,s)=>{if(t.stopPropagation(),!l?.uid){c.error("You must be logged in to purchase items");return}if(f.includes(o)){c.info("You already own this item");return}_(o);try{const a=await ne(l.uid,o,s);a.success?(c.success(a.message||"Item purchased!"),E(n=>[...n,o]),a.currentXP!==void 0&&T(a.currentXP),await $()):c.error(a.message||"Failed to purchase item")}catch(a){console.error("Purchase error:",a),c.error("Error purchasing item")}finally{_(null)}},L=t=>({top:typeof t.top=="string"?t.top:"",bottom:typeof t.bottom=="string"?t.bottom:"",shoes:typeof t.shoes=="string"?t.shoes:"",accessory:typeof t.accessory=="string"?t.accessory:""}),ee=(t,o,s)=>{let a;const n=new Promise((r,u)=>{a=setTimeout(()=>{u(new Error(`${s} timed out after ${Math.round(o/1e3)}s`))},o)});return Promise.race([t,n]).finally(()=>{a!==void 0&&clearTimeout(a)})},g=async(t,o={})=>{const s=C.current;if(!s?.uid)return;const{showSuccessToast:a=!0,showSavingState:n=!0}=o;if(b.current){v.current={layers:L(t),options:{showSuccessToast:a,showSavingState:n}},n&&p(!0);return}b.current=!0,n&&p(!0);try{const r=L(t);await ee(ce(s.uid,{avatarLayers:r}),Ne,"Avatar save"),k&&k(r),a&&c.success("Avatar saved successfully")}catch(r){if(console.error(r),a){const u=r instanceof Error&&r.message.includes("timed out");c.error(u?"Avatar save timed out. Please try again.":"Failed to save avatar")}}finally{const r=v.current;if(v.current=null,b.current=!1,r){g(r.layers,r.options);return}(n||x)&&p(!1)}},te=async()=>{await g(m,{showSuccessToast:!0,showSavingState:!0})},M=[{id:"top",label:"Tops",icon:e.jsx(fe,{size:16})},{id:"bottom",label:"Bottoms",icon:e.jsx(ge,{size:16,className:"rotate-90"})},{id:"shoes",label:"Shoes",icon:e.jsx(be,{size:16})},{id:"accessory",label:"Accessories",icon:e.jsx(R,{size:16})}];return H?e.jsxs("div",{className:"flex flex-col justify-center items-center h-[500px] gap-3",children:[e.jsx("div",{className:"animate-spin",children:e.jsx(O,{size:24,className:"opacity-50"})}),e.jsx("p",{className:"text-sm text-slate-400 font-medium",children:"Loading..."})]}):B?e.jsxs(e.Fragment,{children:[e.jsx("style",{children:ye}),e.jsx("div",{className:"h-full w-full flex items-start xl:items-center justify-center p-4 sm:p-6 lg:p-8 overflow-y-auto xl:overflow-hidden",children:e.jsxs("div",{className:"relative w-full max-w-[1000px] min-h-[500px] xl:h-[80vh] xl:max-h-[700px] rounded-[2rem] p-6 lg:p-8 bg-gradient-to-br from-white via-sky-50/30 to-white border border-slate-200/80 shadow-[0_8px_30px_rgb(0,0,0,0.04)] flex flex-col xl:flex-row gap-8 xl:gap-12 overflow-visible xl:overflow-hidden",children:[e.jsxs("div",{className:"absolute inset-0 overflow-hidden rounded-[2rem] pointer-events-none",children:[e.jsx("div",{className:"absolute top-0 left-0 right-0 h-px bg-gradient-to-r from-transparent via-sky-400/30 to-transparent"}),e.jsx("div",{className:"absolute -top-40 -right-40 w-96 h-96 bg-blue-100/40 rounded-full blur-3xl"}),e.jsx("div",{className:"absolute -bottom-40 -left-40 w-96 h-96 bg-purple-100/30 rounded-full blur-3xl"})]}),e.jsxs("div",{className:"flex flex-col xl:h-full min-h-0 relative z-10 w-full xl:w-[50%] mx-auto xl:mx-0 flex-1",children:[e.jsxs("div",{className:"mb-6 flex flex-col gap-2 shrink-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between xl:justify-start gap-4",children:[e.jsxs("h1",{className:"text-3xl md:text-4xl font-display font-black text-[#0a1628] tracking-tight flex items-center gap-2.5",children:[e.jsx("span",{className:"whitespace-nowrap",children:"Avatar Studio"})," ",e.jsx(V,{className:"text-blue-500 fill-blue-500",size:28})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[G,e.jsxs("div",{className:"bg-gradient-to-br from-amber-400 to-orange-500 rounded-xl px-3 py-1.5 shadow-md flex items-center gap-2 h-fit",children:[e.jsx(N,{className:"text-white shrink-0",size:16}),e.jsxs(me,{children:[e.jsx(ue,{asChild:!0,children:e.jsxs("button",{onClick:U,className:"cursor-pointer hover:opacity-90 transition-opacity active:scale-95 text-left",children:[e.jsx("p",{className:"text-white text-[9px] font-bold uppercase tracking-wider leading-none mb-0.5",children:"XP Balance"}),e.jsx("p",{className:"text-white text-base font-black leading-none",children:K})]})}),e.jsx(xe,{side:"bottom",className:"bg-slate-900 text-white border border-slate-700",children:"Review more lessons to earn more XP!"})]})]})]})]}),e.jsx("p",{className:"text-slate-500 font-medium text-sm md:text-base",children:"Design your perfect learning companion."})]}),e.jsxs(se,{value:Z,onValueChange:t=>J(t),className:"flex flex-col flex-1 min-h-0",children:[e.jsx(ae,{className:"flex flex-nowrap shrink-0 justify-start space-x-1 sm:space-x-2 mb-4 bg-white shadow-sm p-1 rounded-full border border-slate-100 w-fit overflow-x-auto max-w-full scrollbar-hide",children:M.map(t=>e.jsxs(re,{value:t.id,className:"flex items-center gap-1.5 px-4 py-2 rounded-full font-bold text-[13px] text-slate-500 hover:bg-slate-50 data-[state=active]:bg-gradient-to-r data-[state=active]:from-blue-600 data-[state=active]:to-sky-500 data-[state=active]:text-white transition-all shadow-sm outline-none whitespace-nowrap",children:[t.icon,t.label]},t.id))}),e.jsx("div",{className:"flex-1 overflow-y-auto overflow-x-hidden min-h-0 pb-6 scrollbar-hide px-2 -mx-2",children:M.map(t=>{const o=I.filter(s=>s.category===t.id);return e.jsx(oe,{value:t.id,className:"outline-none pt-2 h-full",children:o.length===0?e.jsxs("div",{className:"w-full h-full min-h-[250px] flex flex-col items-center justify-center border-2 border-dashed border-slate-200 rounded-[2rem] bg-slate-50/50 p-8 text-center",children:[e.jsx(R,{size:48,className:"text-slate-300 mb-4 opacity-50"}),e.jsx("h3",{className:"font-bold text-xl text-slate-500 mb-2",children:"Accessories coming soon"}),e.jsx("p",{className:"text-slate-400 text-sm max-w-xs",children:"We're crafting some awesome gear for your avatar! Check back later."})]}):e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-4 lg:gap-6",children:o.map(s=>{const a=m[t.id]===s.id,n=f.includes(s.id),r=!!((s.price&&s.price>0||s.isReward)&&!n);return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("button",{onClick:()=>!r&&Q(t.id,s.id),disabled:r,className:`relative w-full aspect-square rounded-2xl border-2 transition-all flex flex-col items-center justify-center group ${a&&!r?"bg-white border-blue-500 shadow-md scale-[1.02] z-10":r?"bg-slate-50 border-slate-200 opacity-50 cursor-not-allowed":"bg-white border-slate-100 hover:border-sky-300 hover:shadow-lg hover:scale-[1.02] hover:z-10"}`,children:[a&&!r&&e.jsxs("div",{className:"absolute top-1.5 left-1/2 -translate-x-1/2 px-1.5 py-0.5 bg-gradient-to-r from-blue-500 to-sky-400 text-white text-[9px] font-black rounded-full flex items-center gap-1 z-10 whitespace-nowrap",children:["Equipped ",e.jsx(V,{size:9,className:"fill-white"})]}),r&&e.jsx("div",{className:"absolute inset-0 bg-black/20 z-20 flex items-center justify-center rounded-[1rem]",children:e.jsx(w,{className:"text-white",size:24})}),e.jsx("img",{src:s.thumbnail,alt:s.name,className:`w-3/4 h-3/4 object-contain transition-transform e-filter ${!r&&"group-hover:scale-110"}`,style:{"--filter":r?"grayscale(70%)":"none"}})]}),e.jsx("p",{className:"text-xs font-bold text-slate-700 text-center line-clamp-2",children:s.name}),r&&(s.isReward?e.jsxs("div",{className:"w-full py-1 bg-slate-200 text-slate-500 text-[9px] font-bold flex items-center justify-center gap-1 rounded shadow-sm border border-slate-300",children:[e.jsx(w,{size:11})," Exclusive Reward"]}):e.jsx(y.button,{initial:{opacity:0},animate:{opacity:1},onClick:u=>W(u,s.id,s.price||0),disabled:P===s.id,className:"w-full py-1 bg-gradient-to-r from-amber-500 to-orange-500 hover:from-amber-600 hover:to-orange-600 text-white text-[9px] font-bold flex items-center justify-center gap-1 rounded shadow-sm transition-all disabled:opacity-70",children:P===s.id?e.jsx(y.div,{animate:{rotate:360},transition:{repeat:1/0,duration:1},children:e.jsx(N,{size:11})}):e.jsxs(e.Fragment,{children:[e.jsx(N,{size:11}),s.price," XP"]})}))]},s.id)})})},t.id)})})]})]}),e.jsxs("div",{className:"flex flex-col gap-4 relative z-10 w-full xl:w-[350px] max-w-[420px] xl:max-w-none shrink-0 xl:self-center mx-auto xl:mx-0",children:[e.jsxs("div",{className:"bg-[#0f1422] rounded-[2rem] overflow-hidden relative shadow-[0_20px_50px_rgba(15,20,34,0.2)] h-[400px] w-full flex items-center justify-center mx-auto border-4 border-slate-800",children:[e.jsx("div",{className:"absolute top-[-10%] left-0 right-0 h-[110%] pointer-events-none mix-blend-screen opacity-70 avatar-gloss"}),e.jsx("div",{className:"absolute bottom-12 left-1/2 -translate-x-1/2 w-[220px] h-[25px] bg-sky-500/20 blur-xl rounded-full"}),e.jsxs("div",{className:"relative w-full h-[80%] z-10 flex justify-center items-center animate-avatar-float",children:[e.jsx(pe,{layers:m,className:"w-full h-full absolute inset-0 z-20"}),e.jsx(ie,{children:d&&e.jsxs(y.div,{initial:{opacity:0,y:-10,scale:.8},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:10,scale:.8},transition:{duration:.3},className:"absolute -top-24 left-1/2 -translate-x-1/2 z-30 bg-white text-slate-800 px-4 py-2 rounded-full shadow-lg border-2 border-sky-300 whitespace-nowrap font-bold text-sm max-w-xs text-center",children:[d,e.jsx("div",{className:"absolute -bottom-2 left-1/2 -translate-x-1/2 w-0 h-0 border-l-4 border-r-4 border-t-4 border-l-transparent border-r-transparent border-t-white"})]})})]})]}),e.jsxs("button",{onClick:te,disabled:x,className:"w-full max-w-[450px] mx-auto h-[54px] bg-blue-600 hover:bg-blue-500 text-white rounded-xl font-bold text-base flex items-center justify-center gap-2 transition-colors shadow-md disabled:opacity-70 disabled:cursor-not-allowed active:scale-[0.98]",children:[x?e.jsx("div",{className:"animate-spin-slow",children:e.jsx(O,{size:24,className:"opacity-50"})}):null,x?"Saving...":"Save Profile Avatar"]})]})]})})]}):e.jsxs("div",{className:"flex flex-col justify-center items-center h-[500px] gap-4",children:[e.jsx("div",{className:"w-14 h-14 rounded-full bg-slate-100 flex items-center justify-center",children:e.jsx(w,{className:"w-7 h-7 text-slate-400"})}),e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-sm font-semibold text-slate-700 mb-1",children:"Avatar Shop Locked"}),e.jsx("p",{className:"text-xs text-slate-400",children:"This feature is temporarily unavailable while you focus on your learning."})]})]})};export{Ye as default}; diff --git a/assets/AvatarShop-DqyERXR_.js b/assets/AvatarShop-DqyERXR_.js new file mode 100644 index 0000000000000000000000000000000000000000..49bcc58fa14e3ea3c862cb628c2a4eb7fe9cee2e --- /dev/null +++ b/assets/AvatarShop-DqyERXR_.js @@ -0,0 +1,21 @@ +import{r as l,j as e}from"./vendor-react-B4AQeu28.js";import{e as Ee,L as Pe,g as Ae,f as ze}from"./vendor-radix-C5nwdvGr.js";import{e as Y,u as Te,j as h,L as oe,h as le,m as S,y as Ie,a6 as ie,a7 as E,aP as Me,aQ as _e}from"./index-Bp7MiGcW.js";import{u as Ce}from"./useFeatureAccess-O2Vj4dYD.js";import{T as Re,a as qe,b as Xe}from"./tooltip-nLNeX3nd.js";import{C as Fe}from"./CompositeAvatar-DoKZfi7O.js";import{M as Oe,E as Ue}from"./avatarData-ChByUhv2.js";import{S as P}from"./save-D7oNX_Ki.js";import{X as Ve}from"./x-k8d6VLEw.js";import{S as Ye}from"./shirt-C1GQiNvP.js";import{S as $e}from"./sparkles-fLB3ltj1.js";import"./vendor-firebase-firestore-CNv3xXal.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-charts-CAmziV1y.js";import"./vendor-markdown-yqZQ_iQm.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 Be=[["path",{d:"M4 16v-2.38C4 11.5 2.97 10.5 3 8c.03-2.72 1.49-6 4.5-6C9.37 2 10 3.8 10 5.5c0 3.11-2 5.66-2 8.68V16a2 2 0 1 1-4 0Z",key:"1dudjm"}],["path",{d:"M20 20v-2.38c0-2.12 1.03-3.12 1-5.62-.03-2.72-1.49-6-4.5-6C14.63 6 14 7.8 14 9.5c0 3.11 2 5.66 2 8.68V20a2 2 0 1 0 4 0Z",key:"l2t8xc"}],["path",{d:"M16 17h4",key:"1dejxt"}],["path",{d:"M4 13h4",key:"1bwh8b"}]],De=Y("footprints",Be);/** + * @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 Ge=[["circle",{cx:"6",cy:"6",r:"3",key:"1lh9wr"}],["path",{d:"M8.12 8.12 12 12",key:"1alkpv"}],["path",{d:"M20 4 8.12 15.88",key:"xgtan2"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}],["path",{d:"M14.8 14.8 20 20",key:"ptml3r"}]],Ze=Y("scissors",Ge);/** + * @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 He=[["path",{d:"M6 2 3 6v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6l-3-4Z",key:"hou9p0"}],["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M16 10a4 4 0 0 1-8 0",key:"1ltviw"}]],U=Y("shopping-bag",He),Ke=` + @keyframes avatar-float { 0%, 100% { transform: translateY(-8px); } 50% { transform: translateY(8px); } } + @keyframes spin-slow { from { transform: rotate(0deg); } to { transform: rotate(360deg); } } + .animate-avatar-float { animation: avatar-float 4s ease-in-out infinite; } + .animate-spin-slow { animation: spin-slow 1s linear infinite; } +`,ne=["Wow!","Cute!","I love it!","Perfect!","So cool!","Awesome!"],ce=["Gain more XP to buy me more clothes!","Help me get stylish!","Let's earn some XP to unlock more!","I'd love to try on more outfits!","Keep learning to unlock new looks!"],V="top_blue",Qe=2e4,pt=({onSaveProfile:$,onNavigateToModules:de,unsavedChangesRef:A,onConfirmLeave:k,pendingNavigation:B,onCancelNavigation:D})=>{const{userProfile:i,refreshProfile:ue,currentUser:xe}=Te(),{cosmeticShop:me,loading:fe}=Ce(xe?.uid||null),he=!1,[n,p]=l.useState({top:i?.avatarLayers?.top??V,bottom:i?.avatarLayers?.bottom||"",shoes:i?.avatarLayers?.shoes||"",accessory:i?.avatarLayers?.accessory||""}),[x,G]=l.useState({top:i?.avatarLayers?.top??V,bottom:i?.avatarLayers?.bottom||"",shoes:i?.avatarLayers?.shoes||"",accessory:i?.avatarLayers?.accessory||""}),[z,T]=l.useState(!1),[w,Z]=l.useState([]),[pe,H]=l.useState(0),[K,Q]=l.useState(null),[g,b]=l.useState(null),v=Oe,[W,be]=l.useState("top"),[ve,L]=l.useState(!1),[m,I]=l.useState(!1),M=l.useRef(!1),[_,C]=l.useState(0),y=l.useRef(null),J=l.useRef({top:"",bottom:"",shoes:"",accessory:""}),ee=l.useRef(i);ee.current=i;const R=l.useRef(!1),q=l.useRef(null),j=l.useMemo(()=>n.top!==x.top||n.bottom!==x.bottom||n.shoes!==x.shoes||n.accessory!==x.accessory,[n,x]),te=l.useMemo(()=>[n.top,n.bottom,n.shoes,n.accessory].filter(Boolean).some(o=>{const t=v.find(r=>r.id===o);return(t?.isExclusive||t?.isReward)&&!w.includes(o)}),[n,v,w]);l.useEffect(()=>{A&&(A.current=j)},[j,A]),l.useEffect(()=>{B&&j&&L(!0)},[B,j]),l.useEffect(()=>{if(i&&i.role==="student"){const s=i;Z(s.ownedAvatarItems||[]),H(s.currentXP||0)}},[i]),l.useEffect(()=>{const s={top:i?.avatarLayers?.top??V,bottom:i?.avatarLayers?.bottom||"",shoes:i?.avatarLayers?.shoes||"",accessory:i?.avatarLayers?.accessory||""};p(s),G(s)},[i?.uid]),l.useEffect(()=>{if(!g){const s=setInterval(()=>{Math.random()>.6&&b(ce[Math.floor(Math.random()*ce.length)])},5e3);return()=>clearInterval(s)}},[g]),l.useEffect(()=>{if(g){const s=setTimeout(()=>b(null),3500);return()=>clearTimeout(s)}},[g]);const se=(s,o)=>{const t=v.find(a=>a.id===o);if(!t)return;y.current&&(clearTimeout(y.current),y.current=null);const r={...n};if(J.current=r,I(!0),M.current=!0,t.setLayers){const a={...r};t.setLayers.top&&(a.top=t.setLayers.top),t.setLayers.bottom&&(a.bottom=t.setLayers.bottom),t.setLayers.shoes&&(a.shoes=t.setLayers.shoes),t.setLayers.accessory&&(a.accessory=t.setLayers.accessory),p(a)}else p({...r,[s]:o});b("Preview only!"),C(3);const d=setInterval(()=>{C(a=>a<=1?(clearInterval(d),0):a-1)},1e3);y.current=setTimeout(()=>{clearInterval(d),p(r),C(0),I(!1),M.current=!1,b(null),y.current=null},3e3)},ye=l.useCallback((s,o)=>{const t=v.find(u=>u.id===o);if(!t)return;const r=w.includes(o),d=!!((t.price&&t.price>0||t.isReward)&&!r);if(m&&y.current&&(clearTimeout(y.current),I(!1),M.current=!1,p(J.current)),t.setLayers){const u={...n};t.setLayers.top&&(u.top=t.setLayers.top),t.setLayers.bottom&&(u.bottom=t.setLayers.bottom),t.setLayers.shoes&&(u.shoes=t.setLayers.shoes),t.setLayers.accessory&&(u.accessory=t.setLayers.accessory),p(u),b(t.isExclusive&&!r?"Preview only!":"Full set equipped!");return}if(d&&!t.isExclusive){h.error("This item is locked. Earn or purchase it first!");return}let a={...n};const f=v.filter(u=>u.setLayers),c=new Set(f.flatMap(u=>Object.values(u.setLayers||{})));(c.has(a.top||"")||c.has(a.bottom||"")||c.has(a.shoes||"")||c.has(a.accessory||""))&&(c.has(a.top||"")&&(a.top=x.top),c.has(a.bottom||"")&&(a.bottom=x.bottom),c.has(a.shoes||"")&&(a.shoes=x.shoes),c.has(a.accessory||"")&&(a.accessory=x.accessory));const N={...a,[s]:a[s]===o?"":o};p(N),t.isExclusive&&!r?b("Preview only!"):b(ne[Math.floor(Math.random()*ne.length)])},[n,v,w,m]),we=async(s,o,t)=>{if(s.stopPropagation(),!i?.uid){h.error("You must be logged in");return}if(w.includes(o)){h.info("You already own this item");return}Q(o);try{const r=await Me(i.uid,o,t);r.success?(h.success(r.message||"Item purchased!"),Z(d=>[...d,o]),r.currentXP!==void 0&&H(r.currentXP),await ue()):h.error(r.message||"Failed to purchase")}catch(r){console.error(r),h.error("Error purchasing item")}finally{Q(null)}},ae=s=>({top:typeof s.top=="string"?s.top:"",bottom:typeof s.bottom=="string"?s.bottom:"",shoes:typeof s.shoes=="string"?s.shoes:"",accessory:typeof s.accessory=="string"?s.accessory:""}),ge=(s,o,t)=>{let r;const d=new Promise((a,f)=>{r=setTimeout(()=>f(new Error(`${t} timed out`)),o)});return Promise.race([s,d]).finally(()=>{r&&clearTimeout(r)})},X=async(s,o={})=>{const t=ee.current;if(!t?.uid)return;const{showSuccessToast:r=!0,showSavingState:d=!0}=o;if(R.current){q.current={layers:ae(s),options:o},d&&T(!0);return}R.current=!0,d&&T(!0);try{const a=ae(s);await ge(_e(t.uid,{avatarLayers:a}),Qe,"Avatar save"),$&&$(a),G(a),r&&h.success("Avatar saved!")}catch(a){console.error(a),r&&h.error(a instanceof Error&&a.message.includes("timed out")?"Save timed out.":"Failed to save")}finally{const a=q.current;if(q.current=null,R.current=!1,a){X(a.layers,a.options);return}(d||z)&&T(!1)}},je=async()=>{if(!m){if(te){h.error("You need to purchase this item first to save it.");return}await X(n,{showSuccessToast:!0,showSavingState:!0})}},Ne=async()=>{L(!1),te||await X(n,{showSuccessToast:!0,showSavingState:!0}),k&&k()},Se=()=>{L(!1),p(x),k&&k()},F=[{id:"top",label:"Tops",icon:e.jsx(Ye,{size:16})},{id:"bottom",label:"Bottoms",icon:e.jsx(Ze,{size:16,className:"rotate-90"})},{id:"shoes",label:"Shoes",icon:e.jsx(De,{size:16})},{id:"accessory",label:"Accessories",icon:e.jsx(ie,{size:16})},{id:"exclusive",label:"Exclusive",icon:e.jsx(E,{size:16,className:W==="exclusive"?"text-white fill-white":"text-amber-500 fill-amber-500"})}];if(fe)return e.jsxs("div",{className:"flex flex-col justify-center items-center h-[500px] gap-3",children:[e.jsx("div",{className:"animate-spin",children:e.jsx(P,{size:24,className:"opacity-50"})}),e.jsx("p",{className:"text-sm text-slate-400 font-medium",children:"Loading..."})]});if(!me)return e.jsxs("div",{className:"flex flex-col justify-center items-center h-[500px] gap-4",children:[e.jsx("div",{className:"w-14 h-14 rounded-full bg-slate-100 flex items-center justify-center",children:e.jsx(oe,{className:"w-7 h-7 text-slate-400"})}),e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-sm font-semibold text-slate-700 mb-1",children:"Avatar Shop Locked"}),e.jsx("p",{className:"text-xs text-slate-400",children:"This feature is temporarily unavailable."})]})]});const ke=s=>s==="exclusive"?Ue:v.filter(o=>o.category===s&&!o.isExclusive),Le=s=>{const o=ke(s);if(o.length===0){const t=s==="exclusive"?"Exclusive items":F.find(r=>r.id===s)?.label||"Items";return e.jsxs("div",{className:"w-full min-h-[200px] flex flex-col items-center justify-center border-2 border-dashed border-slate-200 rounded-2xl bg-slate-50/50 p-6 text-center",children:[e.jsx(ie,{size:40,className:"text-slate-300 mb-3 opacity-50"}),e.jsxs("h3",{className:"font-bold text-lg text-slate-500 mb-1",children:[t," coming soon"]}),e.jsx("p",{className:"text-slate-400 text-sm max-w-xs",children:"We're crafting some awesome gear for your avatar!"})]})}return e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-4 p-1",children:o.map(t=>{const r=t.category,d=t.setLayers?Object.entries(t.setLayers).every(([O,re])=>!re||n[O]===re):n[r]===t.id,a=w.includes(t.id),f=!!t.isExclusive,c=!!((t.price&&t.price>0||t.isReward)&&!a),N=f&&!a,u=d&&N;return e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("button",{onClick:()=>{c||ye(r,t.id)},disabled:c,className:`relative w-full aspect-square rounded-xl border-2 transition-all flex items-center justify-center group ${u?"bg-gradient-to-br from-amber-50 to-orange-50 border-amber-400 shadow-md scale-[1.02] z-10":d&&!c?"bg-white border-blue-500 shadow-md scale-[1.02] z-10":c&&!f?"bg-slate-50 border-slate-200 opacity-50 cursor-not-allowed":N?"bg-slate-50 border-slate-200 opacity-60 cursor-default":"bg-white border-slate-100 hover:border-sky-300 hover:shadow-md hover:scale-[1.02]"}`,children:[u&&e.jsxs("div",{className:"absolute top-1 left-1/2 -translate-x-1/2 px-1.5 py-0.5 bg-gradient-to-r from-amber-500 to-orange-400 text-white text-[8px] font-black rounded-full flex items-center gap-0.5 z-10 whitespace-nowrap",children:["Preview ",e.jsx(E,{size:8,className:"fill-white"})]}),d&&!c&&!u&&e.jsxs("div",{className:"absolute top-1 left-1/2 -translate-x-1/2 px-1.5 py-0.5 bg-gradient-to-r from-blue-500 to-sky-400 text-white text-[8px] font-black rounded-full flex items-center gap-0.5 z-10 whitespace-nowrap",children:["Equipped ",e.jsx($e,{size:8,className:"fill-white"})]}),c&&!f&&e.jsx("div",{className:"absolute inset-0 bg-black/20 z-20 flex items-center justify-center rounded-[10px]",children:e.jsx(oe,{className:"text-white",size:20})}),e.jsx("img",{src:t.thumbnail,alt:t.name,className:`w-[80%] h-[80%] object-contain transition-transform ${c&&!f?"":"group-hover:scale-110"}`})]}),e.jsx("p",{className:"text-xs font-bold text-slate-700 text-center line-clamp-2",children:t.name}),c&&!f&&!t.isReward&&e.jsx(S.button,{initial:{opacity:0},animate:{opacity:1},onClick:O=>we(O,t.id,t.price||0),disabled:K===t.id,className:"w-full py-0.5 bg-gradient-to-r from-amber-500 to-orange-500 hover:from-amber-600 hover:to-orange-600 text-white text-[9px] font-bold flex items-center justify-center gap-1 rounded shadow-sm transition-all disabled:opacity-70",children:K===t.id?e.jsx(S.div,{animate:{rotate:360},transition:{repeat:1/0,duration:1},children:e.jsx(U,{size:10})}):e.jsxs(e.Fragment,{children:[e.jsx(U,{size:10})," ",t.price," XP"]})}),N&&!t.setLayers&&e.jsxs("button",{onClick:()=>se(r,t.id),disabled:m,className:`w-full py-1 text-[11px] font-bold flex items-center justify-center gap-1 rounded-lg border transition-colors ${m?"bg-slate-100 text-slate-400 border-slate-200 cursor-not-allowed":"bg-amber-50 hover:bg-amber-100 text-amber-600 border-amber-200 cursor-pointer"}`,children:[e.jsx(E,{size:11})," Preview"]}),N&&t.setLayers&&e.jsxs("button",{onClick:()=>se(r,t.id),disabled:m,className:`w-full py-1 text-[11px] font-bold flex items-center justify-center gap-1 rounded-lg border transition-colors ${m?"bg-slate-100 text-slate-400 border-slate-200 cursor-not-allowed":"bg-amber-50 hover:bg-amber-100 text-amber-600 border-amber-200 cursor-pointer"}`,children:[e.jsx(E,{size:11})," Preview Set"]})]},t.id)})})};return e.jsxs(e.Fragment,{children:[e.jsx("style",{children:Ke}),e.jsx("div",{className:"h-full w-full flex items-start xl:items-center justify-center p-4 sm:p-5 lg:p-6 overflow-y-auto xl:overflow-hidden",children:e.jsxs("div",{className:"relative w-full max-w-6xl min-h-[480px] xl:h-[78vh] xl:max-h-[720px] rounded-[2rem] p-5 lg:p-6 bg-gradient-to-br from-white via-sky-50/30 to-white border border-slate-200/80 shadow-[0_8px_30px_rgb(0,0,0,0.04)] flex flex-col xl:flex-row gap-5 xl:gap-8 overflow-visible",children:[e.jsxs("div",{className:"absolute inset-0 overflow-hidden rounded-[2rem] pointer-events-none",children:[e.jsx("div",{className:"absolute top-0 left-0 right-0 h-px bg-gradient-to-r from-transparent via-sky-400/30 to-transparent"}),e.jsx("div",{className:"absolute -top-40 -right-40 w-96 h-96 bg-blue-100/40 rounded-full blur-3xl"}),e.jsx("div",{className:"absolute -bottom-40 -left-40 w-96 h-96 bg-purple-100/30 rounded-full blur-3xl"})]}),e.jsxs("div",{className:"flex flex-col xl:h-full min-h-0 relative z-10 w-full xl:flex-1 max-w-[600px]",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between shrink-0",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-display font-bold text-[#0a1628] tracking-tight truncate",children:i?.name||"Student"}),e.jsx("p",{className:"text-sm text-slate-400 font-medium",children:"Customize your avatar's look here!"})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[he,e.jsxs(Re,{children:[e.jsx(qe,{asChild:!0,children:e.jsxs("button",{onClick:de,className:"bg-gradient-to-br from-amber-400 to-orange-500 rounded-lg px-2.5 py-1 shadow-sm flex items-center gap-1.5 cursor-pointer hover:opacity-90 active:scale-95 transition-all",children:[e.jsx(U,{className:"text-white shrink-0",size:13}),e.jsxs("span",{className:"text-white text-sm font-black",children:[pe," XP"]})]})}),e.jsx(Xe,{side:"bottom",className:"bg-slate-900 text-white border border-slate-700",children:"Earn more XP from lessons!"})]})]})]}),e.jsxs(Ee,{value:W,onValueChange:s=>be(s),className:"flex flex-col flex-1 min-h-0",children:[e.jsx(Pe,{className:"flex flex-nowrap shrink-0 justify-start space-x-1 mb-3 bg-white shadow-sm p-1 rounded-full border border-slate-100 w-fit overflow-x-auto max-w-full scrollbar-hide",children:F.map(s=>e.jsxs(Ae,{value:s.id,className:`flex items-center gap-1 px-3 py-1.5 rounded-full font-bold text-[13px] hover:bg-slate-50 transition-all outline-none whitespace-nowrap ${s.id==="exclusive"?"data-[state=active]:bg-gradient-to-r data-[state=active]:from-amber-500 data-[state=active]:to-orange-500 data-[state=active]:text-white [&_svg]:data-[state=active]:text-white text-amber-600":"data-[state=active]:bg-gradient-to-r data-[state=active]:from-blue-600 data-[state=active]:to-sky-500 data-[state=active]:text-white text-slate-500"}`,children:[s.icon,s.label]},s.id))}),e.jsx("div",{className:"flex-1 overflow-y-auto min-h-0 pb-4 scrollbar-hide px-3 -mx-3",children:F.map(s=>e.jsx(ze,{value:s.id,className:"outline-none h-full",children:Le(s.id)},s.id))})]})]}),e.jsxs("div",{className:"flex flex-col gap-3 relative z-10 w-full xl:w-[340px] min-w-[280px] shrink-0 xl:self-center mx-auto xl:mx-0",children:[e.jsxs("div",{className:"bg-[#0f1422] rounded-[2rem] relative shadow-[0_20px_50px_rgba(15,20,34,0.2)] h-[340px] xl:h-[400px] w-full flex items-center justify-center border-4 border-slate-800",children:[e.jsx("div",{className:"absolute bottom-10 left-1/2 -translate-x-1/2 w-[200px] h-[20px] bg-sky-500/20 blur-xl rounded-full"}),e.jsxs("div",{className:"relative w-full h-[80%] z-10 flex justify-center items-center animate-avatar-float",children:[e.jsx(Fe,{layers:n,className:"w-full h-full absolute inset-0 z-20"}),e.jsx(le,{children:g&&e.jsxs(S.div,{initial:{opacity:0,y:-10,scale:.8},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:10,scale:.8},transition:{duration:.3},className:"absolute -top-12 left-1/2 -translate-x-1/2 z-30 bg-white text-slate-800 px-3 py-1.5 rounded-full shadow-lg border-2 border-sky-300 whitespace-nowrap font-bold text-xs max-w-[200px] text-center",children:[g,e.jsx("div",{className:"absolute -bottom-1.5 left-1/2 -translate-x-1/2 w-0 h-0 border-l-[5px] border-r-[5px] border-t-[5px] border-l-transparent border-r-transparent border-t-white"})]})}),m&&_>0&&e.jsx(S.div,{initial:{scale:1.5,opacity:0},animate:{scale:1,opacity:1},className:"absolute bottom-6 left-1/2 -translate-x-1/2 z-30 bg-amber-500 text-white w-10 h-10 rounded-full flex items-center justify-center font-black text-xl shadow-lg border-2 border-amber-300",children:_},_)]})]}),e.jsx("div",{className:"h-[48px]",children:e.jsx("button",{onClick:je,disabled:z||!j||m,className:"w-full h-full bg-blue-600 hover:bg-blue-500 disabled:bg-slate-200 disabled:text-slate-400 text-white rounded-xl font-bold text-sm flex items-center justify-center gap-2 transition-colors shadow-md disabled:shadow-none active:scale-[0.98]",children:z?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"animate-spin-slow",children:e.jsx(P,{size:16})})," Saving..."]}):j?e.jsxs(e.Fragment,{children:[e.jsx(P,{size:16})," Save Profile Avatar"]}):e.jsxs(e.Fragment,{children:[e.jsx(P,{size:16})," Save Profile Avatar"]})})})]})]})}),e.jsx(le,{children:ve&&e.jsx(S.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-[100] flex items-center justify-center p-4 bg-black/50 backdrop-blur-sm",children:e.jsxs(S.div,{initial:{scale:.9,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.9,opacity:0},className:"bg-white rounded-2xl p-6 w-full max-w-[340px] shadow-2xl border border-slate-200 flex flex-col items-center gap-4",children:[e.jsx("div",{className:"w-12 h-12 rounded-full bg-amber-100 flex items-center justify-center",children:e.jsx(Ie,{className:"text-amber-600",size:24})}),e.jsx("button",{onClick:()=>{L(!1),D&&D()},className:"absolute top-3 right-3 text-slate-400 hover:text-slate-600",children:e.jsx(Ve,{size:18})}),e.jsx("h3",{className:"text-lg font-bold text-slate-900 text-center",children:"You've unsaved changes on Avatar Studio"}),e.jsxs("div",{className:"w-full flex flex-col gap-2",children:[e.jsx("button",{onClick:Ne,className:"w-full py-3 bg-white border-2 border-slate-200 text-slate-900 font-bold rounded-xl hover:bg-slate-50 transition-colors",children:"Save and continue"}),e.jsx("button",{onClick:Se,className:"w-full py-3 bg-slate-100 text-slate-500 font-bold rounded-xl hover:bg-slate-200 transition-colors",children:"Exit anyway"})]})]})})})]})};export{pt as default}; diff --git a/assets/ChatMarkdown-BrSWjY6i.js b/assets/ChatMarkdown-Cwsa2RCx.js similarity index 97% rename from assets/ChatMarkdown-BrSWjY6i.js rename to assets/ChatMarkdown-Cwsa2RCx.js index c6442314952ac323ae25dde48662afb937eb4370..1b2def8d6ed1d178c4af1c9d112d39b457741369 100644 --- a/assets/ChatMarkdown-BrSWjY6i.js +++ b/assets/ChatMarkdown-Cwsa2RCx.js @@ -1,2 +1,2 @@ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/vendor-markdown-yqZQ_iQm.js","assets/vendor-react-B4AQeu28.js","assets/vendor-markdown-CfVKi3_s.css"])))=>i.map(i=>d[i]); -import{b6 as d,_ as c}from"./index-BufUS6SI.js";import{r as m,j as r}from"./vendor-react-B4AQeu28.js";import{M as h,r as x,a as y}from"./vendor-markdown-yqZQ_iQm.js";import"./vendor-firebase-firestore-CNv3xXal.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-radix-C5nwdvGr.js";import"./vendor-charts-CAmziV1y.js";let a=null;const p=()=>(a||(a=c(()=>import("./vendor-markdown-yqZQ_iQm.js").then(l=>l.k),__vite__mapDeps([0,1,2]))),a),M=({children:l})=>{if(m.useEffect(()=>{p()},[]),!l||typeof l!="string")return null;const t=d(l);return r.jsx("div",{className:"chat-markdown",children:r.jsx(h,{remarkPlugins:[y],rehypePlugins:[x],components:{a:({href:e,children:s})=>r.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 hover:underline",children:s}),code:e=>{const{inline:s,className:o,children:n,...i}=e;return r.jsx("code",{className:`${s?"bg-gray-100 dark:bg-gray-800 rounded px-1 py-0.5 text-sm":"block bg-gray-100 dark:bg-gray-900 rounded p-3 overflow-x-auto my-2"} ${o||""}`,...i,children:n})},blockquote:({children:e})=>r.jsx("blockquote",{className:"border-l-4 border-gray-300 dark:border-gray-600 pl-4 italic text-gray-600 dark:text-gray-400 my-2",children:e}),h1:({children:e})=>r.jsx("h1",{className:"text-2xl font-bold my-2",children:e}),h2:({children:e})=>r.jsx("h2",{className:"text-xl font-bold my-2",children:e}),h3:({children:e})=>r.jsx("h3",{className:"text-lg font-bold my-2",children:e}),h4:({children:e})=>r.jsx("h4",{className:"text-base font-bold my-2",children:e}),h5:({children:e})=>r.jsx("h5",{className:"text-sm font-bold my-2",children:e}),h6:({children:e})=>r.jsx("h6",{className:"text-xs font-bold my-2",children:e}),ul:({children:e})=>r.jsx("ul",{className:"list-disc list-inside my-2",children:e}),ol:({children:e})=>r.jsx("ol",{className:"list-decimal list-inside my-2",children:e}),li:({children:e})=>r.jsx("li",{className:"ml-2",children:e}),hr:()=>r.jsx("hr",{className:"my-4 border-t border-gray-300 dark:border-gray-600"}),p:({children:e})=>r.jsx("p",{className:"my-1",children:e})},children:t})})};export{M as default}; +import{b6 as d,_ as c}from"./index-Bp7MiGcW.js";import{r as m,j as r}from"./vendor-react-B4AQeu28.js";import{M as h,r as x,a as y}from"./vendor-markdown-yqZQ_iQm.js";import"./vendor-firebase-firestore-CNv3xXal.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-radix-C5nwdvGr.js";import"./vendor-charts-CAmziV1y.js";let a=null;const p=()=>(a||(a=c(()=>import("./vendor-markdown-yqZQ_iQm.js").then(l=>l.k),__vite__mapDeps([0,1,2]))),a),M=({children:l})=>{if(m.useEffect(()=>{p()},[]),!l||typeof l!="string")return null;const t=d(l);return r.jsx("div",{className:"chat-markdown",children:r.jsx(h,{remarkPlugins:[y],rehypePlugins:[x],components:{a:({href:e,children:s})=>r.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 hover:underline",children:s}),code:e=>{const{inline:s,className:o,children:n,...i}=e;return r.jsx("code",{className:`${s?"bg-gray-100 dark:bg-gray-800 rounded px-1 py-0.5 text-sm":"block bg-gray-100 dark:bg-gray-900 rounded p-3 overflow-x-auto my-2"} ${o||""}`,...i,children:n})},blockquote:({children:e})=>r.jsx("blockquote",{className:"border-l-4 border-gray-300 dark:border-gray-600 pl-4 italic text-gray-600 dark:text-gray-400 my-2",children:e}),h1:({children:e})=>r.jsx("h1",{className:"text-2xl font-bold my-2",children:e}),h2:({children:e})=>r.jsx("h2",{className:"text-xl font-bold my-2",children:e}),h3:({children:e})=>r.jsx("h3",{className:"text-lg font-bold my-2",children:e}),h4:({children:e})=>r.jsx("h4",{className:"text-base font-bold my-2",children:e}),h5:({children:e})=>r.jsx("h5",{className:"text-sm font-bold my-2",children:e}),h6:({children:e})=>r.jsx("h6",{className:"text-xs font-bold my-2",children:e}),ul:({children:e})=>r.jsx("ul",{className:"list-disc list-inside my-2",children:e}),ol:({children:e})=>r.jsx("ol",{className:"list-decimal list-inside my-2",children:e}),li:({children:e})=>r.jsx("li",{className:"ml-2",children:e}),hr:()=>r.jsx("hr",{className:"my-4 border-t border-gray-300 dark:border-gray-600"}),p:({children:e})=>r.jsx("p",{className:"my-1",children:e})},children:t})})};export{M as default}; diff --git a/assets/CompetencyRadarChart-qES5nrtq.js b/assets/CompetencyRadarChart-BbKzMlR1.js similarity index 97% rename from assets/CompetencyRadarChart-qES5nrtq.js rename to assets/CompetencyRadarChart-BbKzMlR1.js index 5bead301d66c057e1b8de0190f4eddeb993c57c4..8ba2e71bb6f2cdcc1d5c092365499ff7e44caec3 100644 --- a/assets/CompetencyRadarChart-qES5nrtq.js +++ b/assets/CompetencyRadarChart-BbKzMlR1.js @@ -1 +1 @@ -import{r as g,j as t}from"./vendor-react-B4AQeu28.js";import{g as A,ad as I,u as B,m as L,B as O,R as W,b as H}from"./index-BufUS6SI.js";import{collection as R,getDocs as q,query as K,orderBy as U,limit as $,Timestamp as G,getDoc as J,doc as V}from"./vendor-firebase-firestore-CNv3xXal.js";import{g as X,s as Y}from"./subjects-D9a9cUC-.js";import{S as Z}from"./sparkles-DYlMf97S.js";import{R as ee,f as te,g as se,h as ne,i as ae,j as oe,T as re}from"./vendor-charts-CAmziV1y.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-radix-C5nwdvGr.js";import"./vendor-markdown-yqZQ_iQm.js";import"./chart-column-BcVJ31XT.js";const P=["#1FA7E1","#9956DE","#75D06A","#FFB356","#7274ED","#FF8B8B","#6ED1CF","#FB96BB"];async function ie(a){try{const r=R(A,"users",a,"quizResults"),d=K(r,U("timestamp","desc"),$(500)),l=await q(d);return l.empty?F(a):l.docs.map(s=>{const e=s.data();return{quizId:s.id,moduleId:e.moduleId||"",subjectId:e.subjectId||"",score:typeof e.score=="number"?e.score:0,totalQuestions:e.totalQuestions||0,correctAnswers:e.correctAnswers||0,questionType:e.questionType||"multiple_choice",timestamp:e.timestamp instanceof G||e.timestamp?.toDate?e.timestamp.toDate():new Date,timeSpent:e.timeSpent||0}})}catch(r){return console.error("[competencyService] fetchQuizResults failed, falling back:",r),F(a)}}async function F(a){const r=await J(V(A,"progress",a));return r.exists()?(r.data().quizAttempts||[]).map((s,e)=>({quizId:String(s.quizId||`attempt-${e}`),moduleId:String(s.moduleId||s.quizId||""),subjectId:String(s.subjectId||""),score:typeof s.score=="number"?s.score:0,totalQuestions:s.totalQuestions||0,correctAnswers:typeof s.correctAnswers=="number"?s.correctAnswers:0,questionType:s.questionType||"multiple_choice",timestamp:s.completedAt?new Date(s.completedAt):new Date,timeSpent:s.timeSpent||0})):[]}async function ce(a){try{const r=R(A,"users",a,"moduleProgress"),d=await q(r);if(d.empty)return{};const l={};return d.forEach(s=>{const e=s.data();l[s.id]={moduleId:s.id,subjectId:e.subjectId||"",sessionsCompleted:e.sessionsCompleted||0,lastActive:e.lastActive?e.lastActive instanceof G?e.lastActive.toDate():new Date(e.lastActive):new Date,moduleTitle:e.moduleTitle||s.id,lessonsCompleted:e.lessonsCompleted||[],quizzesCompleted:e.quizzesCompleted||[]}}),l}catch(r){return console.error("[competencyService] fetchModuleProgress failed:",r),{}}}function _(a,r,d,l){const s=r.filter(p=>p.moduleId===a),e=s.length>0?s.reduce((p,b)=>p+b.score,0)/s.length:0,h=["identification","multiple_choice"],u=s.filter(p=>h.includes(p.questionType)),i=u.length>0?u.reduce((p,b)=>p+b.score,0)/u.length:e*.9,o=["word_problem","equation_based","enumeration"],n=s.filter(p=>o.includes(p.questionType)),c=n.length>0?n.reduce((p,b)=>p+b.score,0)/n.length:e*.85,m=d,f=m?.lessonsCompleted?.length||0,N=m?.quizzesCompleted?.length||0,D=m?.sessionsCompleted||0,y=l.find(p=>p.id===a),x=y?.lessons?.length||1,C=y?.quizzes?.length||1,z=Math.min(100,f/x*100),k=Math.min(100,N/C*100),v=Math.min(100,(z+k+D*5)/2.5);if(s.length<2){const p=v>50?60+v*.3:v*.8;return{overallMastery:e,conceptGrasp:i,application:c,engagement:v,consistency:Math.min(100,p)}}const w=s.map(p=>p.score),M=w.reduce((p,b)=>p+b,0)/w.length,E=w.reduce((p,b)=>p+Math.pow(b-M,2),0)/w.length,j=Math.sqrt(E)/Math.max(M,1),S=Math.max(0,Math.min(100,(1-j)*100));return{overallMastery:Math.round(e),conceptGrasp:Math.round(i),application:Math.round(c),engagement:Math.round(v),consistency:Math.round(S)}}async function le(a){try{const r=R(A,"users",a,"competencyMatrix"),d=await q(r);if(d.empty)return{};const l={};return d.forEach(s=>{const e=s.data();l[s.id]={moduleId:s.id,moduleName:e.moduleName||s.id,overallMastery:e.overallMastery??0,conceptGrasp:e.conceptGrasp??0,application:e.application??0,engagement:e.engagement??0,consistency:e.consistency??0,computedAt:e.computedAt?.toDate?.()||new Date}}),l}catch(r){return console.error("[competencyService] fetchCachedCompetencyMatrix failed:",r),{}}}const Q=[{key:"progress",label:"Overall Mastery"},{key:"concept",label:"Concept Grasp"},{key:"application",label:"Application"},{key:"engagement",label:"Engagement"},{key:"consistency",label:"Consistency"}];function de(a){const[r,d]=g.useState([]),[l,s]=g.useState([]),[e,h]=g.useState("N/A"),[u,i]=g.useState(!0),[o,n]=g.useState(null),[c,m]=g.useState(!1),f=g.useRef(0),N=g.useCallback(async(y,x)=>{if(x!==f.current)return;const z=X(null)[0]??"gen-math",k=Y.find(j=>j.id===z)?.modules||[],v=k.map((j,S)=>({id:j.id,name:j.title.length>15?j.title.substring(0,15).trim()+"...":j.title,color:P[S%P.length]})),w=await le(a);if(x!==f.current)return;if(Object.keys(w).length>0){ue(w,v,d,h),m(!1),i(!1);return}const M=await ie(a),E=await ce(a);if(x!==f.current)return;const T=M.length>0;m(!T),pe(M,E,v,k,d,h),i(!1)},[a]),D=g.useCallback(async()=>{if(!a){i(!1);return}const y=++f.current;i(!0),n(null);try{const x=await new Promise(C=>{const z=I(a,k=>{z(),C(k)})});if(y!==f.current)return;await N(x,y)}catch(x){console.error("[useCompetencyMatrix] Failed to load:",x),y===f.current&&(n("Failed to load competency data. Please try again."),i(!1))}},[a,N]);return g.useEffect(()=>{if(!a)return;const y=I(a,x=>{const C=++f.current;N(x,C)});return()=>y()},[a,N]),{data:r,modulesList:l,topModule:e,loading:u,error:o,isEmpty:c,refresh:D}}function ue(a,r,d,l){let s=-1,e="N/A";const h=Q.map(u=>{const i={metric:u.label,fullMark:100};return r.forEach(o=>{const n=a[o.id];n&&(u.key==="progress"?i[o.id]=n.overallMastery:u.key==="concept"?i[o.id]=n.conceptGrasp:u.key==="application"?i[o.id]=n.application:u.key==="engagement"?i[o.id]=n.engagement:u.key==="consistency"&&(i[o.id]=n.consistency))}),i});r.forEach(u=>{const i=a[u.id];if(i){const o=(i.overallMastery+i.conceptGrasp+i.application+i.engagement+i.consistency)/5;o>s&&(s=o,e=u.name)}}),l(e),d(h)}function pe(a,r,d,l,s,e){let h=-1,u="N/A";const i=Q.map(o=>{const n={metric:o.label,fullMark:100};return l.forEach(c=>{const m=r[c.id],f=_(c.id,a,m??{moduleId:c.id,sessionsCompleted:0,moduleTitle:c.title,lessonsCompleted:[],quizzesCompleted:[]},l);o.key==="progress"?n[c.id]=f.overallMastery:o.key==="concept"?n[c.id]=f.conceptGrasp:o.key==="application"?n[c.id]=f.application:o.key==="engagement"?n[c.id]=f.engagement:o.key==="consistency"&&(n[c.id]=f.consistency)}),n});l.forEach(o=>{const n=r[o.id],c=_(o.id,a,n??{moduleId:o.id,sessionsCompleted:0,moduleTitle:o.title,lessonsCompleted:[],quizzesCompleted:[]},l),m=(c.overallMastery+c.conceptGrasp+c.application+c.engagement+c.consistency)/5;m>h&&(h=m,u=d.find(f=>f.id===o.id)?.name||"N/A")}),e(u),s(i)}const ze=()=>{const{userProfile:a}=B(),{data:r,modulesList:d,topModule:l,loading:s,error:e,isEmpty:h,refresh:u}=de(a?.uid??""),[i,o]=g.useState(!1);return t.jsxs(L.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{duration:.5,ease:[.22,1,.36,1]},className:"relative overflow-hidden bg-white rounded-[16px] border border-slate-200 shadow-sm p-6 lg:p-8 group",onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!1),children:[t.jsx("div",{className:"absolute -right-12 -bottom-12 w-32 h-32 bg-[#9956DE]/5 rounded-full transition-transform duration-500 group-hover:scale-[1.8] group-hover:-translate-y-4 group-hover:-translate-x-4"}),t.jsxs("div",{className:"flex flex-col sm:flex-row items-start sm:items-center justify-between mb-6 relative z-10 gap-4",children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("div",{className:"w-10 h-10 rounded-[12px] bg-gradient-to-br from-[#a855f7] to-[#9333ea] flex items-center justify-center shadow-[0_4px_12px_rgba(168,85,247,0.2)]",children:t.jsx(O,{size:20,className:"text-white"})}),t.jsxs("div",{children:[t.jsx("h3",{className:"text-[15px] font-bold text-slate-900",children:"Competency Matrix"}),t.jsx("p",{className:"text-[12px] text-slate-500",children:"Realtime performance across modules"})]})]}),t.jsxs("div",{className:"flex items-center gap-3",children:[!s&&!h&&!e&&t.jsxs("div",{className:"flex items-center gap-2 bg-[#f5f3ff] border border-[#e0e7ff] px-3 py-1.5 rounded-full",children:[t.jsx(Z,{size:12,className:"text-amber-500"}),t.jsx("span",{className:"text-[11px] font-bold text-[#9956DE] uppercase tracking-wider",children:l})]}),!s&&t.jsx("button",{onClick:u,className:"w-8 h-8 rounded-full bg-white border border-slate-200 flex items-center justify-center hover:bg-[#f5f3ff] hover:border-[#9956DE]/30 transition-colors shadow-sm",title:"Refresh",children:t.jsx(W,{size:13,className:"text-slate-400"})})]})]}),t.jsx("div",{className:"h-[300px] sm:h-[360px] w-full relative z-10",children:s?t.jsx("div",{className:"w-full h-full flex items-center justify-center",children:t.jsxs("div",{className:"flex flex-col items-center gap-3",children:[t.jsx("div",{className:"w-8 h-8 border-4 border-[#9956DE]/20 border-t-[#9956DE] rounded-full animate-spin"}),t.jsx("p",{className:"text-[13px] text-slate-400 font-medium",children:"Analyzing skill vectors..."})]})}):h||e?t.jsxs("div",{className:"w-full h-full flex flex-col items-center justify-center gap-4",children:[t.jsx("div",{className:"w-14 h-14 rounded-[16px] bg-gradient-to-br from-slate-100 to-slate-50 flex items-center justify-center border border-slate-200",children:t.jsx(H,{size:24,className:"text-slate-400"})}),t.jsxs("div",{className:"text-center",children:[t.jsx("p",{className:"text-[13px] font-semibold text-slate-600 mb-1",children:e?"Unable to load competency data":"No activity yet"}),t.jsx("p",{className:"text-[12px] text-slate-400 max-w-[260px]",children:e||"Complete quizzes and lessons to see your competency matrix here."})]}),e&&t.jsx("button",{onClick:u,className:"px-4 py-2 text-[12px] font-semibold bg-[#9956DE] text-white rounded-full hover:bg-[#8b45d1] transition-colors shadow-md",children:"Try Again"})]}):t.jsx(ee,{width:"100%",height:"100%",children:t.jsxs(te,{cx:"50%",cy:"50%",outerRadius:i?"75%":"70%",data:r,children:[t.jsx(se,{stroke:"#e2e8f0",strokeDasharray:"4 4",polarRadius:[20,40,60,80,100]}),t.jsx(ne,{dataKey:"metric",tick:{fill:"#475569",fontSize:12,fontWeight:600}}),t.jsx(ae,{angle:90,domain:[0,100],tick:{fill:"#94a3b8",fontSize:10},tickCount:6,axisLine:!1}),d.map(n=>t.jsx(oe,{name:n.name,dataKey:n.id,stroke:n.color,strokeWidth:2,fill:n.color,fillOpacity:.3,dot:{r:3,fill:"#fff",stroke:n.color,strokeWidth:2},activeDot:{r:5,fill:n.color,stroke:"#fff",strokeWidth:2},isAnimationActive:!0,animationDuration:1500,animationEasing:"ease-out"},n.id)),t.jsx(re,{cursor:!1,content:({active:n,payload:c})=>n&&c&&c.length?t.jsxs("div",{className:"bg-white/95 backdrop-blur-[12px] shadow-[0_8px_24px_rgba(0,0,0,0.12)] border border-slate-100 rounded-[12px] p-4",children:[t.jsx("p",{className:"font-bold text-slate-800 text-[13px] mb-2",children:c[0].payload.metric}),t.jsx("div",{className:"flex flex-col gap-1.5",children:c.map(m=>t.jsxs("div",{className:"flex items-center justify-between gap-4",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("div",{className:"w-2 h-2 rounded-full",style:{backgroundColor:m.stroke}}),t.jsx("span",{className:"text-[11px] font-semibold text-slate-600 truncate max-w-[120px]",children:String(m.name)})]}),t.jsxs("span",{className:"text-[13px] font-bold",style:{color:m.stroke},children:[Math.round(m.value),"%"]})]},m.name))})]}):null})]})})}),!s&&!h&&!e&&d.length>0&&t.jsx("div",{className:"flex flex-wrap justify-center items-center gap-3 mt-4 relative z-10",children:d.map(n=>t.jsxs("div",{className:"flex items-center gap-1.5 bg-slate-50 px-2.5 py-1 rounded-full border border-slate-100",children:[t.jsx("div",{className:"w-2 h-2 rounded-full",style:{backgroundColor:n.color}}),t.jsx("span",{className:"text-[10px] font-bold text-slate-600 uppercase tracking-wider",children:n.name.length>15?n.name.substring(0,12)+"...":n.name})]},n.id))})]})};export{ze as CompetencyRadarChart}; +import{r as g,j as t}from"./vendor-react-B4AQeu28.js";import{g as A,ad as I,u as B,m as L,B as O,R as W,b as H}from"./index-Bp7MiGcW.js";import{collection as R,getDocs as q,query as K,orderBy as U,limit as $,Timestamp as G,getDoc as J,doc as V}from"./vendor-firebase-firestore-CNv3xXal.js";import{g as X,s as Y}from"./subjects-DNoBzeBL.js";import{S as Z}from"./sparkles-fLB3ltj1.js";import{R as ee,f as te,g as se,h as ne,i as ae,j as oe,T as re}from"./vendor-charts-CAmziV1y.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-radix-C5nwdvGr.js";import"./vendor-markdown-yqZQ_iQm.js";import"./chart-column-Dyv8TfXk.js";const P=["#1FA7E1","#9956DE","#75D06A","#FFB356","#7274ED","#FF8B8B","#6ED1CF","#FB96BB"];async function ie(a){try{const r=R(A,"users",a,"quizResults"),d=K(r,U("timestamp","desc"),$(500)),l=await q(d);return l.empty?F(a):l.docs.map(s=>{const e=s.data();return{quizId:s.id,moduleId:e.moduleId||"",subjectId:e.subjectId||"",score:typeof e.score=="number"?e.score:0,totalQuestions:e.totalQuestions||0,correctAnswers:e.correctAnswers||0,questionType:e.questionType||"multiple_choice",timestamp:e.timestamp instanceof G||e.timestamp?.toDate?e.timestamp.toDate():new Date,timeSpent:e.timeSpent||0}})}catch(r){return console.error("[competencyService] fetchQuizResults failed, falling back:",r),F(a)}}async function F(a){const r=await J(V(A,"progress",a));return r.exists()?(r.data().quizAttempts||[]).map((s,e)=>({quizId:String(s.quizId||`attempt-${e}`),moduleId:String(s.moduleId||s.quizId||""),subjectId:String(s.subjectId||""),score:typeof s.score=="number"?s.score:0,totalQuestions:s.totalQuestions||0,correctAnswers:typeof s.correctAnswers=="number"?s.correctAnswers:0,questionType:s.questionType||"multiple_choice",timestamp:s.completedAt?new Date(s.completedAt):new Date,timeSpent:s.timeSpent||0})):[]}async function ce(a){try{const r=R(A,"users",a,"moduleProgress"),d=await q(r);if(d.empty)return{};const l={};return d.forEach(s=>{const e=s.data();l[s.id]={moduleId:s.id,subjectId:e.subjectId||"",sessionsCompleted:e.sessionsCompleted||0,lastActive:e.lastActive?e.lastActive instanceof G?e.lastActive.toDate():new Date(e.lastActive):new Date,moduleTitle:e.moduleTitle||s.id,lessonsCompleted:e.lessonsCompleted||[],quizzesCompleted:e.quizzesCompleted||[]}}),l}catch(r){return console.error("[competencyService] fetchModuleProgress failed:",r),{}}}function _(a,r,d,l){const s=r.filter(p=>p.moduleId===a),e=s.length>0?s.reduce((p,b)=>p+b.score,0)/s.length:0,h=["identification","multiple_choice"],u=s.filter(p=>h.includes(p.questionType)),i=u.length>0?u.reduce((p,b)=>p+b.score,0)/u.length:e*.9,o=["word_problem","equation_based","enumeration"],n=s.filter(p=>o.includes(p.questionType)),c=n.length>0?n.reduce((p,b)=>p+b.score,0)/n.length:e*.85,m=d,f=m?.lessonsCompleted?.length||0,N=m?.quizzesCompleted?.length||0,D=m?.sessionsCompleted||0,y=l.find(p=>p.id===a),x=y?.lessons?.length||1,C=y?.quizzes?.length||1,z=Math.min(100,f/x*100),k=Math.min(100,N/C*100),v=Math.min(100,(z+k+D*5)/2.5);if(s.length<2){const p=v>50?60+v*.3:v*.8;return{overallMastery:e,conceptGrasp:i,application:c,engagement:v,consistency:Math.min(100,p)}}const w=s.map(p=>p.score),M=w.reduce((p,b)=>p+b,0)/w.length,E=w.reduce((p,b)=>p+Math.pow(b-M,2),0)/w.length,j=Math.sqrt(E)/Math.max(M,1),S=Math.max(0,Math.min(100,(1-j)*100));return{overallMastery:Math.round(e),conceptGrasp:Math.round(i),application:Math.round(c),engagement:Math.round(v),consistency:Math.round(S)}}async function le(a){try{const r=R(A,"users",a,"competencyMatrix"),d=await q(r);if(d.empty)return{};const l={};return d.forEach(s=>{const e=s.data();l[s.id]={moduleId:s.id,moduleName:e.moduleName||s.id,overallMastery:e.overallMastery??0,conceptGrasp:e.conceptGrasp??0,application:e.application??0,engagement:e.engagement??0,consistency:e.consistency??0,computedAt:e.computedAt?.toDate?.()||new Date}}),l}catch(r){return console.error("[competencyService] fetchCachedCompetencyMatrix failed:",r),{}}}const Q=[{key:"progress",label:"Overall Mastery"},{key:"concept",label:"Concept Grasp"},{key:"application",label:"Application"},{key:"engagement",label:"Engagement"},{key:"consistency",label:"Consistency"}];function de(a){const[r,d]=g.useState([]),[l,s]=g.useState([]),[e,h]=g.useState("N/A"),[u,i]=g.useState(!0),[o,n]=g.useState(null),[c,m]=g.useState(!1),f=g.useRef(0),N=g.useCallback(async(y,x)=>{if(x!==f.current)return;const z=X(null)[0]??"gen-math",k=Y.find(j=>j.id===z)?.modules||[],v=k.map((j,S)=>({id:j.id,name:j.title.length>15?j.title.substring(0,15).trim()+"...":j.title,color:P[S%P.length]})),w=await le(a);if(x!==f.current)return;if(Object.keys(w).length>0){ue(w,v,d,h),m(!1),i(!1);return}const M=await ie(a),E=await ce(a);if(x!==f.current)return;const T=M.length>0;m(!T),pe(M,E,v,k,d,h),i(!1)},[a]),D=g.useCallback(async()=>{if(!a){i(!1);return}const y=++f.current;i(!0),n(null);try{const x=await new Promise(C=>{const z=I(a,k=>{z(),C(k)})});if(y!==f.current)return;await N(x,y)}catch(x){console.error("[useCompetencyMatrix] Failed to load:",x),y===f.current&&(n("Failed to load competency data. Please try again."),i(!1))}},[a,N]);return g.useEffect(()=>{if(!a)return;const y=I(a,x=>{const C=++f.current;N(x,C)});return()=>y()},[a,N]),{data:r,modulesList:l,topModule:e,loading:u,error:o,isEmpty:c,refresh:D}}function ue(a,r,d,l){let s=-1,e="N/A";const h=Q.map(u=>{const i={metric:u.label,fullMark:100};return r.forEach(o=>{const n=a[o.id];n&&(u.key==="progress"?i[o.id]=n.overallMastery:u.key==="concept"?i[o.id]=n.conceptGrasp:u.key==="application"?i[o.id]=n.application:u.key==="engagement"?i[o.id]=n.engagement:u.key==="consistency"&&(i[o.id]=n.consistency))}),i});r.forEach(u=>{const i=a[u.id];if(i){const o=(i.overallMastery+i.conceptGrasp+i.application+i.engagement+i.consistency)/5;o>s&&(s=o,e=u.name)}}),l(e),d(h)}function pe(a,r,d,l,s,e){let h=-1,u="N/A";const i=Q.map(o=>{const n={metric:o.label,fullMark:100};return l.forEach(c=>{const m=r[c.id],f=_(c.id,a,m??{moduleId:c.id,sessionsCompleted:0,moduleTitle:c.title,lessonsCompleted:[],quizzesCompleted:[]},l);o.key==="progress"?n[c.id]=f.overallMastery:o.key==="concept"?n[c.id]=f.conceptGrasp:o.key==="application"?n[c.id]=f.application:o.key==="engagement"?n[c.id]=f.engagement:o.key==="consistency"&&(n[c.id]=f.consistency)}),n});l.forEach(o=>{const n=r[o.id],c=_(o.id,a,n??{moduleId:o.id,sessionsCompleted:0,moduleTitle:o.title,lessonsCompleted:[],quizzesCompleted:[]},l),m=(c.overallMastery+c.conceptGrasp+c.application+c.engagement+c.consistency)/5;m>h&&(h=m,u=d.find(f=>f.id===o.id)?.name||"N/A")}),e(u),s(i)}const ze=()=>{const{userProfile:a}=B(),{data:r,modulesList:d,topModule:l,loading:s,error:e,isEmpty:h,refresh:u}=de(a?.uid??""),[i,o]=g.useState(!1);return t.jsxs(L.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{duration:.5,ease:[.22,1,.36,1]},className:"relative overflow-hidden bg-white rounded-[16px] border border-slate-200 shadow-sm p-6 lg:p-8 group",onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!1),children:[t.jsx("div",{className:"absolute -right-12 -bottom-12 w-32 h-32 bg-[#9956DE]/5 rounded-full transition-transform duration-500 group-hover:scale-[1.8] group-hover:-translate-y-4 group-hover:-translate-x-4"}),t.jsxs("div",{className:"flex flex-col sm:flex-row items-start sm:items-center justify-between mb-6 relative z-10 gap-4",children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("div",{className:"w-10 h-10 rounded-[12px] bg-gradient-to-br from-[#a855f7] to-[#9333ea] flex items-center justify-center shadow-[0_4px_12px_rgba(168,85,247,0.2)]",children:t.jsx(O,{size:20,className:"text-white"})}),t.jsxs("div",{children:[t.jsx("h3",{className:"text-[15px] font-bold text-slate-900",children:"Competency Matrix"}),t.jsx("p",{className:"text-[12px] text-slate-500",children:"Realtime performance across modules"})]})]}),t.jsxs("div",{className:"flex items-center gap-3",children:[!s&&!h&&!e&&t.jsxs("div",{className:"flex items-center gap-2 bg-[#f5f3ff] border border-[#e0e7ff] px-3 py-1.5 rounded-full",children:[t.jsx(Z,{size:12,className:"text-amber-500"}),t.jsx("span",{className:"text-[11px] font-bold text-[#9956DE] uppercase tracking-wider",children:l})]}),!s&&t.jsx("button",{onClick:u,className:"w-8 h-8 rounded-full bg-white border border-slate-200 flex items-center justify-center hover:bg-[#f5f3ff] hover:border-[#9956DE]/30 transition-colors shadow-sm",title:"Refresh",children:t.jsx(W,{size:13,className:"text-slate-400"})})]})]}),t.jsx("div",{className:"h-[300px] sm:h-[360px] w-full relative z-10",children:s?t.jsx("div",{className:"w-full h-full flex items-center justify-center",children:t.jsxs("div",{className:"flex flex-col items-center gap-3",children:[t.jsx("div",{className:"w-8 h-8 border-4 border-[#9956DE]/20 border-t-[#9956DE] rounded-full animate-spin"}),t.jsx("p",{className:"text-[13px] text-slate-400 font-medium",children:"Analyzing skill vectors..."})]})}):h||e?t.jsxs("div",{className:"w-full h-full flex flex-col items-center justify-center gap-4",children:[t.jsx("div",{className:"w-14 h-14 rounded-[16px] bg-gradient-to-br from-slate-100 to-slate-50 flex items-center justify-center border border-slate-200",children:t.jsx(H,{size:24,className:"text-slate-400"})}),t.jsxs("div",{className:"text-center",children:[t.jsx("p",{className:"text-[13px] font-semibold text-slate-600 mb-1",children:e?"Unable to load competency data":"No activity yet"}),t.jsx("p",{className:"text-[12px] text-slate-400 max-w-[260px]",children:e||"Complete quizzes and lessons to see your competency matrix here."})]}),e&&t.jsx("button",{onClick:u,className:"px-4 py-2 text-[12px] font-semibold bg-[#9956DE] text-white rounded-full hover:bg-[#8b45d1] transition-colors shadow-md",children:"Try Again"})]}):t.jsx(ee,{width:"100%",height:"100%",children:t.jsxs(te,{cx:"50%",cy:"50%",outerRadius:i?"75%":"70%",data:r,children:[t.jsx(se,{stroke:"#e2e8f0",strokeDasharray:"4 4",polarRadius:[20,40,60,80,100]}),t.jsx(ne,{dataKey:"metric",tick:{fill:"#475569",fontSize:12,fontWeight:600}}),t.jsx(ae,{angle:90,domain:[0,100],tick:{fill:"#94a3b8",fontSize:10},tickCount:6,axisLine:!1}),d.map(n=>t.jsx(oe,{name:n.name,dataKey:n.id,stroke:n.color,strokeWidth:2,fill:n.color,fillOpacity:.3,dot:{r:3,fill:"#fff",stroke:n.color,strokeWidth:2},activeDot:{r:5,fill:n.color,stroke:"#fff",strokeWidth:2},isAnimationActive:!0,animationDuration:1500,animationEasing:"ease-out"},n.id)),t.jsx(re,{cursor:!1,content:({active:n,payload:c})=>n&&c&&c.length?t.jsxs("div",{className:"bg-white/95 backdrop-blur-[12px] shadow-[0_8px_24px_rgba(0,0,0,0.12)] border border-slate-100 rounded-[12px] p-4",children:[t.jsx("p",{className:"font-bold text-slate-800 text-[13px] mb-2",children:c[0].payload.metric}),t.jsx("div",{className:"flex flex-col gap-1.5",children:c.map(m=>t.jsxs("div",{className:"flex items-center justify-between gap-4",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("div",{className:"w-2 h-2 rounded-full",style:{backgroundColor:m.stroke}}),t.jsx("span",{className:"text-[11px] font-semibold text-slate-600 truncate max-w-[120px]",children:String(m.name)})]}),t.jsxs("span",{className:"text-[13px] font-bold",style:{color:m.stroke},children:[Math.round(m.value),"%"]})]},m.name))})]}):null})]})})}),!s&&!h&&!e&&d.length>0&&t.jsx("div",{className:"flex flex-wrap justify-center items-center gap-3 mt-4 relative z-10",children:d.map(n=>t.jsxs("div",{className:"flex items-center gap-1.5 bg-slate-50 px-2.5 py-1 rounded-full border border-slate-100",children:[t.jsx("div",{className:"w-2 h-2 rounded-full",style:{backgroundColor:n.color}}),t.jsx("span",{className:"text-[10px] font-bold text-slate-600 uppercase tracking-wider",children:n.name.length>15?n.name.substring(0,12)+"...":n.name})]},n.id))})]})};export{ze as CompetencyRadarChart}; diff --git a/assets/CompositeAvatar-Col05lJc.js b/assets/CompositeAvatar-DoKZfi7O.js similarity index 98% rename from assets/CompositeAvatar-Col05lJc.js rename to assets/CompositeAvatar-DoKZfi7O.js index 881e847767ec399b33d0e3869cb86f67b9d07bf0..6b397bf2a10dd60326be0315bbb5426b22cb9a00 100644 --- a/assets/CompositeAvatar-Col05lJc.js +++ b/assets/CompositeAvatar-DoKZfi7O.js @@ -1,4 +1,4 @@ -import{j as a}from"./vendor-react-B4AQeu28.js";import{g as e}from"./avatarData-BuQSOXo3.js";const m=` +import{j as a}from"./vendor-react-B4AQeu28.js";import{g as e}from"./avatarData-ChByUhv2.js";const m=` @keyframes head-sway { 0%, 100% { transform: rotate(-2deg) translateY(0); } 50% { transform: rotate(2deg) translateY(-3px); } diff --git a/assets/ConfirmModal-B3J78vrR.js b/assets/ConfirmModal-CH3zQe0u.js similarity index 91% rename from assets/ConfirmModal-B3J78vrR.js rename to assets/ConfirmModal-CH3zQe0u.js index 5fc46e2d4f53e681d7f85241644902b073cec0f5..9ec39856175172700bb119fc001f6d79971ddc87 100644 --- a/assets/ConfirmModal-B3J78vrR.js +++ b/assets/ConfirmModal-CH3zQe0u.js @@ -1 +1 @@ -import{j as e}from"./vendor-react-B4AQeu28.js";import{B as i}from"./button-DsnZWCoA.js";import{h as u,m as r,y as f}from"./index-BufUS6SI.js";import{X as y}from"./x-BuBjuj2Y.js";import{T as j}from"./trash-2-CBXOjqKg.js";import{L as w}from"./log-out-Cp6gBYHP.js";import"./vendor-radix-C5nwdvGr.js";import"./vendor-charts-CAmziV1y.js";import"./vendor-firebase-firestore-CNv3xXal.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";const O=({isOpen:s,onClose:t,onConfirm:n,title:a,message:l,confirmText:c="Confirm",cancelText:d="Cancel",type:m="warning",icon:x="warning",zIndexClass:g="z-50"})=>{const b=()=>{switch(x){case"logout":return e.jsx(w,{size:32});case"delete":return e.jsx(j,{size:32});case"warning":default:return e.jsx(f,{size:32})}},o=(()=>{switch(m){case"danger":return{iconBg:"bg-red-100",iconColor:"text-red-600",buttonBg:"bg-red-600 hover:bg-red-700",buttonText:"text-white"};case"warning":return{iconBg:"bg-rose-100",iconColor:"text-rose-600",buttonBg:"bg-rose-600 hover:bg-rose-700",buttonText:"text-white"};case"info":default:return{iconBg:"bg-sky-100",iconColor:"text-sky-600",buttonBg:"bg-sky-600 hover:bg-sky-700",buttonText:"text-white"}}})(),p=async()=>{try{await n(),t()}catch{}};return e.jsx(u,{children:s&&e.jsx(e.Fragment,{children:e.jsx(r.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},onClick:t,className:`fixed inset-0 bg-black/50 backdrop-blur-sm ${g} flex items-center justify-center p-4`,children:e.jsxs(r.div,{initial:{opacity:0,scale:.9,y:20},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.9,y:20},transition:{type:"spring",damping:25,stiffness:300},onClick:h=>h.stopPropagation(),className:"bg-[#f7f9fc] rounded-3xl shadow-2xl max-w-md w-full overflow-hidden border border-[#dde3eb]",children:[e.jsx("button",{onClick:t,className:"absolute top-4 right-4 p-2 text-slate-500 hover:text-[#0a1628] hover:bg-[#dde3eb] rounded-xl transition-colors z-10",children:e.jsx(y,{size:20})}),e.jsxs("div",{className:"p-8 text-center",children:[e.jsx(r.div,{initial:{scale:0},animate:{scale:1},transition:{delay:.1,type:"spring",damping:15},className:`w-20 h-20 ${o.iconBg} rounded-full flex items-center justify-center mx-auto mb-6 ${o.iconColor}`,children:b()}),e.jsx("h2",{className:"text-2xl font-display font-bold text-[#0a1628] mb-3",children:a}),e.jsx("p",{className:"text-[#5a6578] mb-8 leading-relaxed",children:l}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx(i,{onClick:t,variant:"outline",size:"lg",className:"flex-1 h-12 rounded-xl border-[#dde3eb] hover:border-[#d1cec6] hover:bg-[#edf1f7] font-bold",children:d}),e.jsx(i,{onClick:p,size:"lg",className:`flex-1 h-12 rounded-xl font-bold ${o.buttonBg} ${o.buttonText} transition-colors shadow-lg`,children:c})]})]})]})})})})};export{O as default}; +import{j as e}from"./vendor-react-B4AQeu28.js";import{B as i}from"./button-BMVm9YQO.js";import{h as u,m as r,y as f}from"./index-Bp7MiGcW.js";import{X as y}from"./x-k8d6VLEw.js";import{T as j}from"./trash-2-BhUbBhdb.js";import{L as w}from"./log-out-DrAbcVI9.js";import"./vendor-radix-C5nwdvGr.js";import"./vendor-charts-CAmziV1y.js";import"./vendor-firebase-firestore-CNv3xXal.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";const O=({isOpen:s,onClose:t,onConfirm:n,title:a,message:l,confirmText:c="Confirm",cancelText:d="Cancel",type:m="warning",icon:x="warning",zIndexClass:g="z-50"})=>{const b=()=>{switch(x){case"logout":return e.jsx(w,{size:32});case"delete":return e.jsx(j,{size:32});case"warning":default:return e.jsx(f,{size:32})}},o=(()=>{switch(m){case"danger":return{iconBg:"bg-red-100",iconColor:"text-red-600",buttonBg:"bg-red-600 hover:bg-red-700",buttonText:"text-white"};case"warning":return{iconBg:"bg-rose-100",iconColor:"text-rose-600",buttonBg:"bg-rose-600 hover:bg-rose-700",buttonText:"text-white"};case"info":default:return{iconBg:"bg-sky-100",iconColor:"text-sky-600",buttonBg:"bg-sky-600 hover:bg-sky-700",buttonText:"text-white"}}})(),p=async()=>{try{await n(),t()}catch{}};return e.jsx(u,{children:s&&e.jsx(e.Fragment,{children:e.jsx(r.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},onClick:t,className:`fixed inset-0 bg-black/50 backdrop-blur-sm ${g} flex items-center justify-center p-4`,children:e.jsxs(r.div,{initial:{opacity:0,scale:.9,y:20},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.9,y:20},transition:{type:"spring",damping:25,stiffness:300},onClick:h=>h.stopPropagation(),className:"bg-[#f7f9fc] rounded-3xl shadow-2xl max-w-md w-full overflow-hidden border border-[#dde3eb]",children:[e.jsx("button",{onClick:t,className:"absolute top-4 right-4 p-2 text-slate-500 hover:text-[#0a1628] hover:bg-[#dde3eb] rounded-xl transition-colors z-10",children:e.jsx(y,{size:20})}),e.jsxs("div",{className:"p-8 text-center",children:[e.jsx(r.div,{initial:{scale:0},animate:{scale:1},transition:{delay:.1,type:"spring",damping:15},className:`w-20 h-20 ${o.iconBg} rounded-full flex items-center justify-center mx-auto mb-6 ${o.iconColor}`,children:b()}),e.jsx("h2",{className:"text-2xl font-display font-bold text-[#0a1628] mb-3",children:a}),e.jsx("p",{className:"text-[#5a6578] mb-8 leading-relaxed",children:l}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx(i,{onClick:t,variant:"outline",size:"lg",className:"flex-1 h-12 rounded-xl border-[#dde3eb] hover:border-[#d1cec6] hover:bg-[#edf1f7] font-bold",children:d}),e.jsx(i,{onClick:p,size:"lg",className:`flex-1 h-12 rounded-xl font-bold ${o.buttonBg} ${o.buttonText} transition-colors shadow-lg`,children:c})]})]})]})})})})};export{O as default}; diff --git a/assets/DashboardAvatar-CbAKGmA6.js b/assets/DashboardAvatar-D5djDQQ1.js similarity index 98% rename from assets/DashboardAvatar-CbAKGmA6.js rename to assets/DashboardAvatar-D5djDQQ1.js index 25a13eb4c659621d1a4472107206fd65d70294a8..07fff8da4beada05dc7a72c53fbbad14f46e72c9 100644 --- a/assets/DashboardAvatar-CbAKGmA6.js +++ b/assets/DashboardAvatar-D5djDQQ1.js @@ -1,4 +1,4 @@ -import{j as a}from"./vendor-react-B4AQeu28.js";import{g as e}from"./avatarData-BuQSOXo3.js";const l=` +import{j as a}from"./vendor-react-B4AQeu28.js";import{g as e}from"./avatarData-ChByUhv2.js";const l=` @keyframes head-sway { 0%, 100% { transform: rotate(-2deg); } 50% { transform: rotate(2deg); } diff --git a/assets/DiagnosticBreakdown-BF7w8Bn-.js b/assets/DiagnosticBreakdown-DkqMV9oI.js similarity index 97% rename from assets/DiagnosticBreakdown-BF7w8Bn-.js rename to assets/DiagnosticBreakdown-DkqMV9oI.js index b729b95c6862f7738874198bfa87d799a94e2d46..89f0de4241cd00ad6994238d8013f063321c28dc 100644 --- a/assets/DiagnosticBreakdown-BF7w8Bn-.js +++ b/assets/DiagnosticBreakdown-DkqMV9oI.js @@ -1 +1 @@ -import{r as i,j as e}from"./vendor-react-B4AQeu28.js";import{getDoc as y,doc as _}from"./vendor-firebase-firestore-CNv3xXal.js";import{g as k,w as Z,B as H,Z as J,y as C,T as W,r as S,m,h as Y}from"./index-BufUS6SI.js";import{X as G}from"./x-BuBjuj2Y.js";import{C as A}from"./clock-CooTZK0X.js";import{L as T,C as K}from"./lightbulb-bxzKA78M.js";import{C as q}from"./circle-check-BzgmgbHa.js";import{C as D}from"./chart-column-BcVJ31XT.js";import{a as O,C as V}from"./chevron-up-CoNRuMZ7.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-radix-C5nwdvGr.js";import"./vendor-charts-CAmziV1y.js";import"./vendor-markdown-yqZQ_iQm.js";const ge=({userId:d,mode:h,isOpen:c=!0,onClose:p})=>{const[o,P]=i.useState([]),[B,$]=i.useState({}),[r,R]=i.useState({}),[a,E]=i.useState(null),[L,x]=i.useState(!0),[Q,j]=i.useState(!0),[g,z]=i.useState(null);i.useEffect(()=>{!d||!c||M()},[d,c]);const M=async()=>{x(!0);try{const s=await y(_(k,"diagnosticResults",d));if(!s.exists()){x(!1);return}const t=s.data(),U=t.responses||[];$(t.domainScores||{}),R(t.riskProfile||{});const b=t.testId;let v={};if(b){const l=await y(_(k,"diagnosticSessions",b));if(l.exists()){const X=l.data();for(const w of X.questions||[])v[w.question_id]=w.question_text}}P(U.map(l=>({...l,question_text:v[l.question_id]}))),x(!1),j(!0);try{const l=await Z("/api/diagnostic/analyze",{method:"POST",body:JSON.stringify({user_id:d})});l.success&&E(l.analysis)}catch(l){console.error("[DiagnosticBreakdown] AI analysis failed:",l)}finally{j(!1)}}catch(s){console.error("[DiagnosticBreakdown] Failed to load data:",s),x(!1),j(!1)}},u=o.filter(s=>s.is_correct).length,n=o.length,f=o.reduce((s,t)=>s+t.time_spent_seconds,0),F=n>0?Math.round(f/n):0,I=n>0?Math.round(u/n*100):0;if(!c)return null;const N=e.jsxs("div",{className:`${h==="fullscreen"?"min-h-screen bg-gradient-to-br from-slate-50 via-white to-indigo-50/30":""} flex flex-col`,children:[e.jsx("div",{className:"top-0 z-10 bg-white border-b border-slate-200/60 px-6 py-4",children:e.jsxs("div",{className:"max-w-6xl mx-auto flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 bg-gradient-to-br from-indigo-500 to-purple-600 rounded-xl flex items-center justify-center shadow-lg shadow-indigo-200",children:e.jsx(H,{className:"w-5 h-5 text-white"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-lg font-bold text-slate-900",children:"Diagnostic Assessment Breakdown"}),e.jsx("p",{className:"text-xs text-slate-500",children:"AI-powered analysis of your performance"})]})]}),e.jsx("button",{onClick:p,className:"p-2 hover:bg-slate-100 rounded-xl transition-colors",title:"Close",children:e.jsx(G,{className:"w-5 h-5 text-slate-500"})})]})}),e.jsx("div",{className:"max-w-6xl mx-auto w-full px-6 py-8 space-y-8",children:L?e.jsx("div",{className:"space-y-4",children:[1,2,3].map(s=>e.jsx("div",{className:"h-32 bg-slate-100 rounded-2xl animate-pulse"},s))}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"bg-gradient-to-br from-indigo-500 to-purple-600 rounded-2xl p-5 text-white shadow-lg shadow-indigo-200/50",children:[e.jsx("p",{className:"text-indigo-200 text-xs font-medium uppercase",children:"Score"}),e.jsxs("p",{className:"text-3xl font-black mt-1",children:[I,"%"]}),e.jsxs("p",{className:"text-indigo-200 text-sm",children:[u,"/",n," correct"]})]}),e.jsxs("div",{className:"bg-white rounded-2xl p-5 border border-slate-100",children:[e.jsxs("div",{className:"flex items-center gap-2 text-slate-500 mb-1",children:[e.jsx(A,{className:"w-4 h-4"})," ",e.jsx("span",{className:"text-xs font-medium uppercase",children:"Avg Time"})]}),e.jsxs("p",{className:"text-2xl font-bold text-slate-800",children:[F,"s"]}),e.jsx("p",{className:"text-xs text-slate-400",children:"per question"})]}),e.jsxs("div",{className:"bg-white rounded-2xl p-5 border border-slate-100",children:[e.jsxs("div",{className:"flex items-center gap-2 text-slate-500 mb-1",children:[e.jsx(J,{className:"w-4 h-4"})," ",e.jsx("span",{className:"text-xs font-medium uppercase",children:"Total Time"})]}),e.jsxs("p",{className:"text-2xl font-bold text-slate-800",children:[Math.floor(f/60),"m ",f%60,"s"]}),e.jsx("p",{className:"text-xs text-slate-400",children:"assessment duration"})]}),e.jsxs("div",{className:"bg-white rounded-2xl p-5 border border-slate-100",children:[e.jsxs("div",{className:"flex items-center gap-2 text-slate-500 mb-1",children:[e.jsx(C,{className:"w-4 h-4"})," ",e.jsx("span",{className:"text-xs font-medium uppercase",children:"Risk"})]}),e.jsx("p",{className:`text-2xl font-bold ${r.overall_risk==="high"||r.overall_risk==="critical"?"text-red-600":r.overall_risk==="moderate"?"text-amber-600":"text-emerald-600"}`,children:(r.overall_risk||"unknown").charAt(0).toUpperCase()+(r.overall_risk||"unknown").slice(1)}),e.jsx("p",{className:"text-xs text-slate-400",children:"risk level"})]})]}),e.jsxs("div",{className:"bg-white rounded-2xl border border-slate-100 overflow-hidden",children:[e.jsx("div",{className:"px-6 py-4 border-b border-slate-100 bg-gradient-to-r from-amber-50 to-orange-50",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(T,{className:"w-5 h-5 text-amber-500"}),e.jsx("h2",{className:"font-bold text-slate-800",children:"AI Analysis"})]})}),e.jsx("div",{className:"p-6",children:Q?e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"h-4 bg-slate-100 rounded animate-pulse w-3/4"}),e.jsx("div",{className:"h-4 bg-slate-100 rounded animate-pulse w-1/2"}),e.jsx("div",{className:"h-4 bg-slate-100 rounded animate-pulse w-5/6"})]}):a?e.jsxs("div",{className:"space-y-6",children:[e.jsx("p",{className:"text-slate-700 leading-relaxed",children:a.overall_summary}),e.jsxs("div",{className:"bg-sky-50 border border-sky-100 rounded-xl p-4",children:[e.jsxs("h3",{className:"font-semibold text-sky-800 text-sm mb-2 flex items-center gap-2",children:[e.jsx(A,{className:"w-4 h-4"})," Timing Patterns"]}),e.jsx("p",{className:"text-sm text-sky-700",children:a.time_analysis.insight}),a.time_analysis.slow_questions.length>0&&e.jsxs("p",{className:"text-xs text-sky-600 mt-2",children:[e.jsx("span",{className:"font-medium",children:"Took longest on:"})," ",a.time_analysis.slow_questions.join(", ")]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[a.strength_areas.length>0&&e.jsxs("div",{className:"border border-emerald-100 bg-emerald-50/50 rounded-xl p-4",children:[e.jsxs("h3",{className:"font-semibold text-emerald-800 text-sm mb-3 flex items-center gap-2",children:[e.jsx(W,{className:"w-4 h-4"})," Strengths"]}),e.jsx("ul",{className:"space-y-2",children:a.strength_areas.map((s,t)=>e.jsxs("li",{className:"text-sm text-emerald-700 flex items-start gap-2",children:[e.jsx(q,{className:"w-3.5 h-3.5 mt-0.5 flex-shrink-0"}),e.jsxs("span",{children:[e.jsxs("strong",{children:[s.domain,":"]})," ",s.detail]})]},t))})]}),a.weakness_areas.length>0&&e.jsxs("div",{className:"border border-red-100 bg-red-50/50 rounded-xl p-4",children:[e.jsxs("h3",{className:"font-semibold text-red-800 text-sm mb-3 flex items-center gap-2",children:[e.jsx(S,{className:"w-4 h-4"})," Weak Areas"]}),e.jsx("ul",{className:"space-y-2",children:a.weakness_areas.map((s,t)=>e.jsxs("li",{className:"text-sm text-red-700 flex items-start gap-2",children:[e.jsx(C,{className:"w-3.5 h-3.5 mt-0.5 flex-shrink-0"}),e.jsxs("span",{children:[e.jsxs("strong",{children:[s.domain,":"]})," ",s.detail]})]},t))})]})]}),a.answer_patterns.common_mistakes.length>0&&e.jsxs("div",{className:"bg-amber-50 border border-amber-100 rounded-xl p-4",children:[e.jsx("h3",{className:"font-semibold text-amber-800 text-sm mb-2",children:"Answer Patterns"}),e.jsx("p",{className:"text-sm text-amber-700 mb-2",children:a.answer_patterns.description}),e.jsx("ul",{className:"space-y-1",children:a.answer_patterns.common_mistakes.map((s,t)=>e.jsxs("li",{className:"text-xs text-amber-600",children:["• ",s]},t))})]}),a.recommendations.length>0&&e.jsxs("div",{className:"bg-indigo-50 border border-indigo-100 rounded-xl p-4",children:[e.jsxs("h3",{className:"font-semibold text-indigo-800 text-sm mb-3 flex items-center gap-2",children:[e.jsx(T,{className:"w-4 h-4"})," Recommendations"]}),e.jsx("ol",{className:"space-y-2",children:a.recommendations.map((s,t)=>e.jsxs("li",{className:"text-sm text-indigo-700",children:[e.jsxs("span",{className:"font-medium",children:[t+1,". ",s.action]}),e.jsxs("span",{className:"text-indigo-500 text-xs ml-2",children:["— ",s.reason]})]},t))})]}),e.jsxs("div",{className:"bg-slate-50 border border-slate-100 rounded-xl p-4",children:[e.jsxs("h3",{className:"font-semibold text-slate-800 text-sm mb-3 flex items-center gap-2",children:[e.jsx(D,{className:"w-4 h-4"})," Performance by Difficulty"]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-xs text-slate-500 uppercase font-medium",children:"Easy"}),e.jsx("p",{className:"text-sm font-bold text-slate-700 mt-1",children:a.difficulty_analysis.easy_performance})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-xs text-slate-500 uppercase font-medium",children:"Medium"}),e.jsx("p",{className:"text-sm font-bold text-slate-700 mt-1",children:a.difficulty_analysis.medium_performance})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-xs text-slate-500 uppercase font-medium",children:"Hard"}),e.jsx("p",{className:"text-sm font-bold text-slate-700 mt-1",children:a.difficulty_analysis.hard_performance})]})]})]})]}):e.jsx("p",{className:"text-slate-500 text-sm",children:"Analysis unavailable."})})]}),e.jsxs("div",{className:"bg-white rounded-2xl border border-slate-100 overflow-hidden",children:[e.jsx("div",{className:"px-6 py-4 border-b border-slate-100",children:e.jsxs("h2",{className:"font-bold text-slate-800 flex items-center gap-2",children:[e.jsx(D,{className:"w-5 h-5 text-indigo-500"})," Domain Scores"]})}),e.jsx("div",{className:"p-6 grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4",children:Object.entries(B).map(([s,t])=>e.jsxs("div",{className:"border border-slate-100 rounded-xl p-4",children:[e.jsx("p",{className:"text-sm font-semibold text-slate-700 mb-2",children:s}),e.jsxs("div",{className:"flex items-end gap-2",children:[e.jsxs("span",{className:"text-2xl font-black text-slate-800",children:[t.percentage,"%"]}),e.jsxs("span",{className:"text-xs text-slate-400 mb-1",children:[t.correct,"/",t.total]})]}),e.jsx("div",{className:"mt-2 h-2 bg-slate-100 rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full transition-all ${t.percentage>=80?"bg-emerald-500":t.percentage>=60?"bg-amber-500":"bg-red-500"}`,style:{width:`${t.percentage}%`}})}),e.jsx("p",{className:`text-xs mt-1 font-medium ${t.mastery_level==="mastered"?"text-emerald-600":t.mastery_level==="developing"?"text-amber-600":"text-red-600"}`,children:t.mastery_level})]},s))})]}),e.jsxs("div",{className:"bg-white rounded-2xl border border-slate-100 overflow-hidden",children:[e.jsx("div",{className:"px-6 py-4 border-b border-slate-100",children:e.jsxs("h2",{className:"font-bold text-slate-800 flex items-center gap-2",children:[e.jsx(S,{className:"w-5 h-5 text-indigo-500"})," Question-by-Question Breakdown"]})}),e.jsx("div",{className:"divide-y divide-slate-50",children:o.map((s,t)=>e.jsxs("div",{className:"px-6 py-3 hover:bg-slate-50/50 transition-colors",children:[e.jsxs("button",{onClick:()=>z(g===t?null:t),className:"w-full flex items-center gap-3 text-left",children:[e.jsx("div",{className:`w-7 h-7 rounded-full flex items-center justify-center flex-shrink-0 ${s.is_correct?"bg-emerald-100 text-emerald-600":"bg-red-100 text-red-600"}`,children:s.is_correct?e.jsx(q,{className:"w-4 h-4"}):e.jsx(K,{className:"w-4 h-4"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("p",{className:"text-sm font-medium text-slate-700 truncate",children:["Q",t+1,". ",s.question_text||`${s.topic} (${s.domain})`]}),e.jsxs("div",{className:"flex items-center gap-3 mt-0.5",children:[e.jsx("span",{className:"text-xs text-slate-400",children:s.difficulty}),e.jsxs("span",{className:"text-xs text-slate-400",children:[s.time_spent_seconds,"s"]}),e.jsx("span",{className:"text-xs text-slate-400",children:s.domain})]})]}),g===t?e.jsx(O,{className:"w-4 h-4 text-slate-400"}):e.jsx(V,{className:"w-4 h-4 text-slate-400"})]}),g===t&&e.jsxs(m.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},className:"ml-10 mt-2 pb-2 space-y-2",children:[s.question_text&&e.jsx("p",{className:"text-sm text-slate-600",children:s.question_text}),e.jsxs("div",{className:"flex flex-wrap gap-4 text-xs",children:[e.jsxs("span",{className:s.is_correct?"text-emerald-600":"text-red-600",children:["Your answer: ",e.jsx("strong",{children:s.student_answer||"—"})]}),!s.is_correct&&e.jsxs("span",{className:"text-emerald-600",children:["Correct: ",e.jsx("strong",{children:s.correct_answer})]}),e.jsxs("span",{className:"text-slate-500",children:["Time: ",s.time_spent_seconds,"s"]}),e.jsxs("span",{className:"text-slate-500",children:["Bloom: ",s.bloom_level]})]})]})]},t))})]}),e.jsx("div",{className:"flex justify-center pb-8",children:e.jsx("button",{onClick:p,className:"px-8 py-3 bg-indigo-600 hover:bg-indigo-700 text-white font-bold rounded-xl shadow-lg shadow-indigo-200 transition-all",children:h==="fullscreen"?"Continue to Dashboard":"Close"})})]})})]});return h==="modal"?e.jsx(Y,{children:c&&e.jsx(m.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-50 bg-black/50 flex items-center justify-center p-4",onClick:p,children:e.jsx(m.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,y:10},className:"bg-white rounded-2xl shadow-xl w-full max-w-5xl max-h-[90vh] overflow-y-auto will-change-transform",onClick:s=>s.stopPropagation(),children:N})})}):e.jsx(m.div,{initial:{opacity:0},animate:{opacity:1},className:"fixed inset-0 z-50 overflow-y-auto bg-gradient-to-br from-slate-50 via-white to-indigo-50/30",children:N})};export{ge as default}; +import{r as i,j as e}from"./vendor-react-B4AQeu28.js";import{getDoc as y,doc as _}from"./vendor-firebase-firestore-CNv3xXal.js";import{g as k,w as Z,B as H,Z as J,y as C,T as W,r as S,m,h as Y}from"./index-Bp7MiGcW.js";import{X as G}from"./x-k8d6VLEw.js";import{C as A}from"./clock-Cc6sJz1J.js";import{L as T,C as K}from"./lightbulb-DG1NwVgr.js";import{C as q}from"./circle-check-DzQphSnP.js";import{C as D}from"./chart-column-Dyv8TfXk.js";import{a as O,C as V}from"./chevron-up-DtS9MvUZ.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-radix-C5nwdvGr.js";import"./vendor-charts-CAmziV1y.js";import"./vendor-markdown-yqZQ_iQm.js";const ge=({userId:d,mode:h,isOpen:c=!0,onClose:p})=>{const[o,P]=i.useState([]),[B,$]=i.useState({}),[r,R]=i.useState({}),[a,E]=i.useState(null),[L,x]=i.useState(!0),[Q,j]=i.useState(!0),[g,z]=i.useState(null);i.useEffect(()=>{!d||!c||M()},[d,c]);const M=async()=>{x(!0);try{const s=await y(_(k,"diagnosticResults",d));if(!s.exists()){x(!1);return}const t=s.data(),U=t.responses||[];$(t.domainScores||{}),R(t.riskProfile||{});const b=t.testId;let v={};if(b){const l=await y(_(k,"diagnosticSessions",b));if(l.exists()){const X=l.data();for(const w of X.questions||[])v[w.question_id]=w.question_text}}P(U.map(l=>({...l,question_text:v[l.question_id]}))),x(!1),j(!0);try{const l=await Z("/api/diagnostic/analyze",{method:"POST",body:JSON.stringify({user_id:d})});l.success&&E(l.analysis)}catch(l){console.error("[DiagnosticBreakdown] AI analysis failed:",l)}finally{j(!1)}}catch(s){console.error("[DiagnosticBreakdown] Failed to load data:",s),x(!1),j(!1)}},u=o.filter(s=>s.is_correct).length,n=o.length,f=o.reduce((s,t)=>s+t.time_spent_seconds,0),F=n>0?Math.round(f/n):0,I=n>0?Math.round(u/n*100):0;if(!c)return null;const N=e.jsxs("div",{className:`${h==="fullscreen"?"min-h-screen bg-gradient-to-br from-slate-50 via-white to-indigo-50/30":""} flex flex-col`,children:[e.jsx("div",{className:"top-0 z-10 bg-white border-b border-slate-200/60 px-6 py-4",children:e.jsxs("div",{className:"max-w-6xl mx-auto flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 bg-gradient-to-br from-indigo-500 to-purple-600 rounded-xl flex items-center justify-center shadow-lg shadow-indigo-200",children:e.jsx(H,{className:"w-5 h-5 text-white"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-lg font-bold text-slate-900",children:"Diagnostic Assessment Breakdown"}),e.jsx("p",{className:"text-xs text-slate-500",children:"AI-powered analysis of your performance"})]})]}),e.jsx("button",{onClick:p,className:"p-2 hover:bg-slate-100 rounded-xl transition-colors",title:"Close",children:e.jsx(G,{className:"w-5 h-5 text-slate-500"})})]})}),e.jsx("div",{className:"max-w-6xl mx-auto w-full px-6 py-8 space-y-8",children:L?e.jsx("div",{className:"space-y-4",children:[1,2,3].map(s=>e.jsx("div",{className:"h-32 bg-slate-100 rounded-2xl animate-pulse"},s))}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"bg-gradient-to-br from-indigo-500 to-purple-600 rounded-2xl p-5 text-white shadow-lg shadow-indigo-200/50",children:[e.jsx("p",{className:"text-indigo-200 text-xs font-medium uppercase",children:"Score"}),e.jsxs("p",{className:"text-3xl font-black mt-1",children:[I,"%"]}),e.jsxs("p",{className:"text-indigo-200 text-sm",children:[u,"/",n," correct"]})]}),e.jsxs("div",{className:"bg-white rounded-2xl p-5 border border-slate-100",children:[e.jsxs("div",{className:"flex items-center gap-2 text-slate-500 mb-1",children:[e.jsx(A,{className:"w-4 h-4"})," ",e.jsx("span",{className:"text-xs font-medium uppercase",children:"Avg Time"})]}),e.jsxs("p",{className:"text-2xl font-bold text-slate-800",children:[F,"s"]}),e.jsx("p",{className:"text-xs text-slate-400",children:"per question"})]}),e.jsxs("div",{className:"bg-white rounded-2xl p-5 border border-slate-100",children:[e.jsxs("div",{className:"flex items-center gap-2 text-slate-500 mb-1",children:[e.jsx(J,{className:"w-4 h-4"})," ",e.jsx("span",{className:"text-xs font-medium uppercase",children:"Total Time"})]}),e.jsxs("p",{className:"text-2xl font-bold text-slate-800",children:[Math.floor(f/60),"m ",f%60,"s"]}),e.jsx("p",{className:"text-xs text-slate-400",children:"assessment duration"})]}),e.jsxs("div",{className:"bg-white rounded-2xl p-5 border border-slate-100",children:[e.jsxs("div",{className:"flex items-center gap-2 text-slate-500 mb-1",children:[e.jsx(C,{className:"w-4 h-4"})," ",e.jsx("span",{className:"text-xs font-medium uppercase",children:"Risk"})]}),e.jsx("p",{className:`text-2xl font-bold ${r.overall_risk==="high"||r.overall_risk==="critical"?"text-red-600":r.overall_risk==="moderate"?"text-amber-600":"text-emerald-600"}`,children:(r.overall_risk||"unknown").charAt(0).toUpperCase()+(r.overall_risk||"unknown").slice(1)}),e.jsx("p",{className:"text-xs text-slate-400",children:"risk level"})]})]}),e.jsxs("div",{className:"bg-white rounded-2xl border border-slate-100 overflow-hidden",children:[e.jsx("div",{className:"px-6 py-4 border-b border-slate-100 bg-gradient-to-r from-amber-50 to-orange-50",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(T,{className:"w-5 h-5 text-amber-500"}),e.jsx("h2",{className:"font-bold text-slate-800",children:"AI Analysis"})]})}),e.jsx("div",{className:"p-6",children:Q?e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"h-4 bg-slate-100 rounded animate-pulse w-3/4"}),e.jsx("div",{className:"h-4 bg-slate-100 rounded animate-pulse w-1/2"}),e.jsx("div",{className:"h-4 bg-slate-100 rounded animate-pulse w-5/6"})]}):a?e.jsxs("div",{className:"space-y-6",children:[e.jsx("p",{className:"text-slate-700 leading-relaxed",children:a.overall_summary}),e.jsxs("div",{className:"bg-sky-50 border border-sky-100 rounded-xl p-4",children:[e.jsxs("h3",{className:"font-semibold text-sky-800 text-sm mb-2 flex items-center gap-2",children:[e.jsx(A,{className:"w-4 h-4"})," Timing Patterns"]}),e.jsx("p",{className:"text-sm text-sky-700",children:a.time_analysis.insight}),a.time_analysis.slow_questions.length>0&&e.jsxs("p",{className:"text-xs text-sky-600 mt-2",children:[e.jsx("span",{className:"font-medium",children:"Took longest on:"})," ",a.time_analysis.slow_questions.join(", ")]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[a.strength_areas.length>0&&e.jsxs("div",{className:"border border-emerald-100 bg-emerald-50/50 rounded-xl p-4",children:[e.jsxs("h3",{className:"font-semibold text-emerald-800 text-sm mb-3 flex items-center gap-2",children:[e.jsx(W,{className:"w-4 h-4"})," Strengths"]}),e.jsx("ul",{className:"space-y-2",children:a.strength_areas.map((s,t)=>e.jsxs("li",{className:"text-sm text-emerald-700 flex items-start gap-2",children:[e.jsx(q,{className:"w-3.5 h-3.5 mt-0.5 flex-shrink-0"}),e.jsxs("span",{children:[e.jsxs("strong",{children:[s.domain,":"]})," ",s.detail]})]},t))})]}),a.weakness_areas.length>0&&e.jsxs("div",{className:"border border-red-100 bg-red-50/50 rounded-xl p-4",children:[e.jsxs("h3",{className:"font-semibold text-red-800 text-sm mb-3 flex items-center gap-2",children:[e.jsx(S,{className:"w-4 h-4"})," Weak Areas"]}),e.jsx("ul",{className:"space-y-2",children:a.weakness_areas.map((s,t)=>e.jsxs("li",{className:"text-sm text-red-700 flex items-start gap-2",children:[e.jsx(C,{className:"w-3.5 h-3.5 mt-0.5 flex-shrink-0"}),e.jsxs("span",{children:[e.jsxs("strong",{children:[s.domain,":"]})," ",s.detail]})]},t))})]})]}),a.answer_patterns.common_mistakes.length>0&&e.jsxs("div",{className:"bg-amber-50 border border-amber-100 rounded-xl p-4",children:[e.jsx("h3",{className:"font-semibold text-amber-800 text-sm mb-2",children:"Answer Patterns"}),e.jsx("p",{className:"text-sm text-amber-700 mb-2",children:a.answer_patterns.description}),e.jsx("ul",{className:"space-y-1",children:a.answer_patterns.common_mistakes.map((s,t)=>e.jsxs("li",{className:"text-xs text-amber-600",children:["• ",s]},t))})]}),a.recommendations.length>0&&e.jsxs("div",{className:"bg-indigo-50 border border-indigo-100 rounded-xl p-4",children:[e.jsxs("h3",{className:"font-semibold text-indigo-800 text-sm mb-3 flex items-center gap-2",children:[e.jsx(T,{className:"w-4 h-4"})," Recommendations"]}),e.jsx("ol",{className:"space-y-2",children:a.recommendations.map((s,t)=>e.jsxs("li",{className:"text-sm text-indigo-700",children:[e.jsxs("span",{className:"font-medium",children:[t+1,". ",s.action]}),e.jsxs("span",{className:"text-indigo-500 text-xs ml-2",children:["— ",s.reason]})]},t))})]}),e.jsxs("div",{className:"bg-slate-50 border border-slate-100 rounded-xl p-4",children:[e.jsxs("h3",{className:"font-semibold text-slate-800 text-sm mb-3 flex items-center gap-2",children:[e.jsx(D,{className:"w-4 h-4"})," Performance by Difficulty"]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-xs text-slate-500 uppercase font-medium",children:"Easy"}),e.jsx("p",{className:"text-sm font-bold text-slate-700 mt-1",children:a.difficulty_analysis.easy_performance})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-xs text-slate-500 uppercase font-medium",children:"Medium"}),e.jsx("p",{className:"text-sm font-bold text-slate-700 mt-1",children:a.difficulty_analysis.medium_performance})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-xs text-slate-500 uppercase font-medium",children:"Hard"}),e.jsx("p",{className:"text-sm font-bold text-slate-700 mt-1",children:a.difficulty_analysis.hard_performance})]})]})]})]}):e.jsx("p",{className:"text-slate-500 text-sm",children:"Analysis unavailable."})})]}),e.jsxs("div",{className:"bg-white rounded-2xl border border-slate-100 overflow-hidden",children:[e.jsx("div",{className:"px-6 py-4 border-b border-slate-100",children:e.jsxs("h2",{className:"font-bold text-slate-800 flex items-center gap-2",children:[e.jsx(D,{className:"w-5 h-5 text-indigo-500"})," Domain Scores"]})}),e.jsx("div",{className:"p-6 grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4",children:Object.entries(B).map(([s,t])=>e.jsxs("div",{className:"border border-slate-100 rounded-xl p-4",children:[e.jsx("p",{className:"text-sm font-semibold text-slate-700 mb-2",children:s}),e.jsxs("div",{className:"flex items-end gap-2",children:[e.jsxs("span",{className:"text-2xl font-black text-slate-800",children:[t.percentage,"%"]}),e.jsxs("span",{className:"text-xs text-slate-400 mb-1",children:[t.correct,"/",t.total]})]}),e.jsx("div",{className:"mt-2 h-2 bg-slate-100 rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full transition-all ${t.percentage>=80?"bg-emerald-500":t.percentage>=60?"bg-amber-500":"bg-red-500"}`,style:{width:`${t.percentage}%`}})}),e.jsx("p",{className:`text-xs mt-1 font-medium ${t.mastery_level==="mastered"?"text-emerald-600":t.mastery_level==="developing"?"text-amber-600":"text-red-600"}`,children:t.mastery_level})]},s))})]}),e.jsxs("div",{className:"bg-white rounded-2xl border border-slate-100 overflow-hidden",children:[e.jsx("div",{className:"px-6 py-4 border-b border-slate-100",children:e.jsxs("h2",{className:"font-bold text-slate-800 flex items-center gap-2",children:[e.jsx(S,{className:"w-5 h-5 text-indigo-500"})," Question-by-Question Breakdown"]})}),e.jsx("div",{className:"divide-y divide-slate-50",children:o.map((s,t)=>e.jsxs("div",{className:"px-6 py-3 hover:bg-slate-50/50 transition-colors",children:[e.jsxs("button",{onClick:()=>z(g===t?null:t),className:"w-full flex items-center gap-3 text-left",children:[e.jsx("div",{className:`w-7 h-7 rounded-full flex items-center justify-center flex-shrink-0 ${s.is_correct?"bg-emerald-100 text-emerald-600":"bg-red-100 text-red-600"}`,children:s.is_correct?e.jsx(q,{className:"w-4 h-4"}):e.jsx(K,{className:"w-4 h-4"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("p",{className:"text-sm font-medium text-slate-700 truncate",children:["Q",t+1,". ",s.question_text||`${s.topic} (${s.domain})`]}),e.jsxs("div",{className:"flex items-center gap-3 mt-0.5",children:[e.jsx("span",{className:"text-xs text-slate-400",children:s.difficulty}),e.jsxs("span",{className:"text-xs text-slate-400",children:[s.time_spent_seconds,"s"]}),e.jsx("span",{className:"text-xs text-slate-400",children:s.domain})]})]}),g===t?e.jsx(O,{className:"w-4 h-4 text-slate-400"}):e.jsx(V,{className:"w-4 h-4 text-slate-400"})]}),g===t&&e.jsxs(m.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},className:"ml-10 mt-2 pb-2 space-y-2",children:[s.question_text&&e.jsx("p",{className:"text-sm text-slate-600",children:s.question_text}),e.jsxs("div",{className:"flex flex-wrap gap-4 text-xs",children:[e.jsxs("span",{className:s.is_correct?"text-emerald-600":"text-red-600",children:["Your answer: ",e.jsx("strong",{children:s.student_answer||"—"})]}),!s.is_correct&&e.jsxs("span",{className:"text-emerald-600",children:["Correct: ",e.jsx("strong",{children:s.correct_answer})]}),e.jsxs("span",{className:"text-slate-500",children:["Time: ",s.time_spent_seconds,"s"]}),e.jsxs("span",{className:"text-slate-500",children:["Bloom: ",s.bloom_level]})]})]})]},t))})]}),e.jsx("div",{className:"flex justify-center pb-8",children:e.jsx("button",{onClick:p,className:"px-8 py-3 bg-indigo-600 hover:bg-indigo-700 text-white font-bold rounded-xl shadow-lg shadow-indigo-200 transition-all",children:h==="fullscreen"?"Continue to Dashboard":"Close"})})]})})]});return h==="modal"?e.jsx(Y,{children:c&&e.jsx(m.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-50 bg-black/50 flex items-center justify-center p-4",onClick:p,children:e.jsx(m.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,y:10},className:"bg-white rounded-2xl shadow-xl w-full max-w-5xl max-h-[90vh] overflow-y-auto will-change-transform",onClick:s=>s.stopPropagation(),children:N})})}):e.jsx(m.div,{initial:{opacity:0},animate:{opacity:1},className:"fixed inset-0 z-50 overflow-y-auto bg-gradient-to-br from-slate-50 via-white to-indigo-50/30",children:N})};export{ge as default}; diff --git a/assets/FloatingAITutor-BnnsbuI9.js b/assets/FloatingAITutor-wfjL9MBE.js similarity index 93% rename from assets/FloatingAITutor-BnnsbuI9.js rename to assets/FloatingAITutor-wfjL9MBE.js index 269cc7b3e047210a7fb82f232469975f9b2e5445..2df6398246082823f4c0060da81e74d6860776d7 100644 --- a/assets/FloatingAITutor-BnnsbuI9.js +++ b/assets/FloatingAITutor-wfjL9MBE.js @@ -1,2 +1,2 @@ -const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-BufUS6SI.js","assets/vendor-react-B4AQeu28.js","assets/vendor-firebase-firestore-CNv3xXal.js","assets/vendor-firebase-core-D7GXCeNu.js","assets/vendor-firebase-auth-T_wvTOvf.js","assets/vendor-firebase-storage-Bi7H_66d.js","assets/vendor-firebase-analytics-rHarj5hR.js","assets/vendor-radix-C5nwdvGr.js","assets/vendor-charts-CAmziV1y.js","assets/vendor-markdown-yqZQ_iQm.js","assets/vendor-markdown-CfVKi3_s.css","assets/index-CIg5rXpX.css","assets/ChatMarkdown-BrSWjY6i.js"])))=>i.map(i=>d[i]); -import{g as T,_ as w,aG as O,u as D,m as A,N as P}from"./index-BufUS6SI.js";import{r as a,j as e}from"./vendor-react-B4AQeu28.js";import{collection as $,query as B,limit as q,orderBy as H,where as V,onSnapshot as F,doc as U,updateDoc as G}from"./vendor-firebase-firestore-CNv3xXal.js";import{M as K}from"./maximize-2-DJehxXl_.js";import{M as z}from"./minus-DuS-NH5j.js";import{X as C}from"./x-BuBjuj2Y.js";import{S as W}from"./send-DsMS4hUP.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-radix-C5nwdvGr.js";import"./vendor-charts-CAmziV1y.js";import"./vendor-markdown-yqZQ_iQm.js";function X(s,o){const n=$(T,"tutorNudges",s,"nudges"),u=B(n,V("consumed","==",!1),H("createdAt","desc"),q(1));return F(u,d=>{if(d.empty){o(null);return}const h=d.docs[0],m=h.data();o({id:h.id,message:m.message,topic:m.topic,createdAt:m.createdAt?.toDate?.()||new Date,consumed:!1})},()=>o(null))}async function J(s,o){const n=U(T,"tutorNudges",s,"nudges",o);await G(n,{consumed:!0})}const Q="https://deign86-mathpulse-api-v3test.hf.space";async function Y(s){try{const{auth:o}=await w(async()=>{const{auth:u}=await import("./index-BufUS6SI.js").then(d=>d.b7);return{auth:u}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11])),n=await o.currentUser?.getIdToken();await fetch(`${Q}/api/pipeline/nudge/${s}`,{method:"POST",headers:{"Content-Type":"application/json",...n?{Authorization:`Bearer ${n}`}:{}}})}catch{}}const Z=a.lazy(()=>w(()=>import("./ChatMarkdown-BrSWjY6i.js"),__vite__mapDeps([12,0,1,2,3,4,5,6,7,8,9,10,11])));function ee(s){return s?s instanceof Date?s.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):typeof s=="object"&&"toDate"in s?s.toDate().toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):String(s):""}const xe=({constraintsRef:s,onFullScreen:o})=>{const{activeSessionId:n,setActiveSessionId:u,createNewSession:d,getActiveSession:h,sendMessage:m,isLoading:f}=O(),{currentUser:c,userRole:y}=D(),[i,x]=a.useState(!1),[g,j]=a.useState(()=>typeof window>"u"?!1:window.localStorage.getItem("floating_ai_tutor_minimized")==="1"),[p,v]=a.useState(""),[r,b]=a.useState(null),N=a.useRef(null),k=a.useRef(null);a.useEffect(()=>{if(!c?.uid||y!=="student")return;let t=!1;return X(c.uid,l=>{l&&l.id!==k.current?b(l):(b(null),t||(t=!0,Y(c.uid)))})},[c?.uid,y]),a.useEffect(()=>{typeof window>"u"||window.localStorage.setItem("floating_ai_tutor_minimized",g?"1":"0")},[g]),a.useEffect(()=>{i&&w(async()=>{const{warmupBackend:t}=await import("./index-BufUS6SI.js").then(l=>l.b8);return{warmupBackend:t}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11])).then(({warmupBackend:t})=>{t()}).catch(t=>{console.warn("Floating tutor warmup skipped:",t)})},[i]),a.useEffect(()=>{if(i&&!n){const t=r?r.message:"Hi! I'm your AI math tutor. What would you like to learn about today?",l={id:r?`nudge-${r.id}`:"1",sender:"ai",text:t,timestamp:new Date().toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})},R=d(l);u(R)}},[i]),a.useEffect(()=>{i&&r&&c?.uid&&(k.current=r.id,J(c.uid,r.id).catch(()=>{}),b(null))},[i,r]);const I=h()?.messages||[],M=()=>{N.current?.scrollIntoView({behavior:"smooth"})};a.useEffect(()=>{M()},[I]);const _=async()=>{if(!p.trim()||!n||f)return;const t=p.trim();v(""),await m(n,t)},E=()=>{o()},S=()=>{x(!1),j(!0)},L=()=>{j(!1)};return e.jsxs("div",{className:"pointer-events-none flex flex-col items-end",children:[e.jsxs("div",{className:`pointer-events-auto mb-4 w-80 bg-[#f7f9fc] rounded-3xl shadow-2xl border border-[#dde3eb] flex flex-col overflow-hidden transition-all duration-300 origin-bottom-right select-none ${i?"opacity-100 scale-100 translate-y-0":"opacity-0 scale-95 translate-y-10 pointer-events-none h-0"}`,style:{"--max-h":i?"32rem":"0",willChange:"transform, opacity"},children:[e.jsxs("div",{className:"bg-gradient-to-r from-sky-600 to-sky-500 p-4 flex items-center justify-between flex-shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 bg-white/20 rounded-xl flex items-center justify-center backdrop-blur-sm",children:e.jsx("img",{src:"/avatar/avatar_icon.png",alt:"AI Tutor",className:"w-9 h-9 object-contain drop-shadow-md"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-white font-bold text-sm",children:"L.O.L.I."}),e.jsxs("p",{className:"text-sky-100 text-[10px] leading-tight",children:["Logical Operations &",e.jsx("br",{}),"Learning Intelligence"]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:E,type:"button","aria-label":"Open fullscreen",className:"p-2 hover:bg-white/20 rounded-lg transition-colors",title:"Open fullscreen",children:e.jsx(K,{size:16,className:"text-white"})}),e.jsx("button",{type:"button","aria-label":"Minimize AI tutor launcher",onClick:S,className:"p-2 hover:bg-white/20 rounded-lg transition-colors",title:"Minimize",children:e.jsx(z,{size:16,className:"text-white"})}),e.jsx("button",{type:"button","aria-label":"Close chat",onClick:()=>x(!1),className:"p-2 hover:bg-white/20 rounded-lg transition-colors",children:e.jsx(C,{size:16,className:"text-white"})})]})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-4 space-y-3 bg-[#edf1f7]",children:[I.map(t=>e.jsx("div",{className:`flex ${t.sender==="user"?"justify-end":"justify-start"}`,children:e.jsxs("div",{className:`max-w-[75%] rounded-2xl px-4 py-2.5 ${t.sender==="user"?"bg-sky-600 text-white":"bg-white text-[#0a1628] shadow-sm border border-[#dde3eb]"}`,children:[t.sender==="user"?e.jsx("p",{className:"text-sm whitespace-pre-wrap",children:t.text}):e.jsx(a.Suspense,{fallback:e.jsx("p",{className:"text-sm whitespace-pre-wrap",children:t.text}),children:e.jsx(Z,{children:t.text})}),e.jsx("p",{className:`text-[10px] mt-1 ${t.sender==="user"?"text-sky-200":"text-slate-500"}`,children:ee(t.timestamp)})]})},t.id)),f&&e.jsx("div",{className:"flex justify-start",children:e.jsx("div",{className:"bg-white text-[#0a1628] shadow-sm border border-[#dde3eb] rounded-2xl px-4 py-2.5 max-w-[75%]",children:e.jsxs("div",{className:"flex gap-1",children:[e.jsx("div",{className:"w-2 h-2 bg-sky-400 rounded-full animate-bounce"}),e.jsx("div",{className:"w-2 h-2 bg-sky-400 rounded-full animate-bounce [animation-delay:150ms]"}),e.jsx("div",{className:"w-2 h-2 bg-sky-400 rounded-full animate-bounce [animation-delay:300ms]"})]})})}),e.jsx("div",{ref:N})]}),e.jsx("div",{className:"p-4 border-t border-[#dde3eb] bg-white flex-shrink-0",children:e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{id:"ai-tutor-input",name:"ai-tutor-input","aria-label":"Ask AI tutor a question",type:"text",value:p,onChange:t=>v(t.target.value),onKeyPress:t=>t.key==="Enter"&&_(),placeholder:"Ask me anything...",className:"flex-1 px-4 py-2.5 rounded-xl border border-[#dde3eb] focus:outline-none focus:ring-2 focus:ring-sky-500 text-sm bg-[#f7f9fc]"}),e.jsx("button",{type:"button","aria-label":"Send message",onClick:_,className:"p-2.5 bg-sky-600 hover:bg-sky-700 text-white rounded-xl transition-colors disabled:opacity-50 disabled:cursor-not-allowed",disabled:!p.trim()||f,children:e.jsx(W,{size:18})})]})})]}),e.jsx("div",{className:"pointer-events-auto relative self-end",children:g?e.jsx(A.button,{type:"button",onClick:L,whileHover:{scale:1.08},whileTap:{scale:.95},transition:{duration:.15,ease:"easeOut"},className:"h-9 w-9 rounded-full bg-slate-900/85 text-white shadow-lg ring-1 ring-white/20 backdrop-blur-sm flex items-center justify-center","aria-label":"Restore AI tutor launcher",title:"Show AI tutor",style:{willChange:"transform"},children:e.jsx(P,{size:14})}):e.jsxs("div",{className:"relative group",children:[!i&&e.jsxs("div",{className:"absolute right-full mr-4 top-1/2 -translate-y-1/2 px-4 py-2 bg-slate-800 text-white text-sm rounded-xl opacity-0 group-hover:opacity-100 transition-opacity duration-300 pointer-events-none whitespace-nowrap shadow-xl z-50",children:["Hello! I'm L.O.L.I., how may I help you?",e.jsx("div",{className:"absolute top-1/2 -translate-y-1/2 -right-1 w-3 h-3 bg-slate-800 rotate-45"})]}),!i&&e.jsx("button",{type:"button","aria-label":"Minimize AI tutor launcher",title:"Minimize",onClick:S,className:"absolute -top-2 -left-2 z-10 h-6 w-6 rounded-full bg-white text-slate-700 border border-slate-200 shadow-md hover:bg-slate-100 transition-colors flex items-center justify-center",children:e.jsx(z,{size:12})}),e.jsxs(A.button,{type:"button",onClick:()=>x(!i),whileHover:{scale:1.1},whileTap:{scale:.9},transition:{duration:.15,ease:"easeOut"},className:"w-16 h-16 bg-gradient-to-br from-sky-600 to-sky-500 rounded-xl shadow-2xl flex items-center justify-center text-white hover:shadow-sky-300/50 transition-all","aria-label":i?"Close AI tutor chat":"Open AI tutor chat",style:{willChange:"transform"},children:[i?e.jsx(C,{size:28}):e.jsx("img",{src:"/avatar/avatar_icon.png",alt:"AI Tutor",className:"w-14 h-14 object-contain drop-shadow-lg"}),!i&&r&&e.jsx("span",{className:"absolute -top-1 -right-1 w-4 h-4 bg-amber-400 rounded-full border-2 border-white animate-pulse"})]})]})})]})};export{xe as default}; +const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-Bp7MiGcW.js","assets/vendor-react-B4AQeu28.js","assets/vendor-firebase-firestore-CNv3xXal.js","assets/vendor-firebase-core-D7GXCeNu.js","assets/vendor-firebase-auth-T_wvTOvf.js","assets/vendor-firebase-storage-Bi7H_66d.js","assets/vendor-firebase-analytics-rHarj5hR.js","assets/vendor-radix-C5nwdvGr.js","assets/vendor-charts-CAmziV1y.js","assets/vendor-markdown-yqZQ_iQm.js","assets/vendor-markdown-CfVKi3_s.css","assets/index-Dja0MwoB.css","assets/ChatMarkdown-Cwsa2RCx.js"])))=>i.map(i=>d[i]); +import{g as T,_ as w,aG as O,u as D,m as A,N as P}from"./index-Bp7MiGcW.js";import{r as a,j as e}from"./vendor-react-B4AQeu28.js";import{collection as $,query as B,limit as q,orderBy as H,where as V,onSnapshot as F,doc as U,updateDoc as G}from"./vendor-firebase-firestore-CNv3xXal.js";import{M as K}from"./maximize-2-CWmKKmit.js";import{M as z}from"./minus-BK7K7Pi2.js";import{X as C}from"./x-k8d6VLEw.js";import{S as W}from"./send-BA-OOIJf.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-radix-C5nwdvGr.js";import"./vendor-charts-CAmziV1y.js";import"./vendor-markdown-yqZQ_iQm.js";function X(s,o){const n=$(T,"tutorNudges",s,"nudges"),u=B(n,V("consumed","==",!1),H("createdAt","desc"),q(1));return F(u,d=>{if(d.empty){o(null);return}const h=d.docs[0],m=h.data();o({id:h.id,message:m.message,topic:m.topic,createdAt:m.createdAt?.toDate?.()||new Date,consumed:!1})},()=>o(null))}async function J(s,o){const n=U(T,"tutorNudges",s,"nudges",o);await G(n,{consumed:!0})}const Q="https://deign86-mathpulse-api-v3test.hf.space";async function Y(s){try{const{auth:o}=await w(async()=>{const{auth:u}=await import("./index-Bp7MiGcW.js").then(d=>d.b7);return{auth:u}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11])),n=await o.currentUser?.getIdToken();await fetch(`${Q}/api/pipeline/nudge/${s}`,{method:"POST",headers:{"Content-Type":"application/json",...n?{Authorization:`Bearer ${n}`}:{}}})}catch{}}const Z=a.lazy(()=>w(()=>import("./ChatMarkdown-Cwsa2RCx.js"),__vite__mapDeps([12,0,1,2,3,4,5,6,7,8,9,10,11])));function ee(s){return s?s instanceof Date?s.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):typeof s=="object"&&"toDate"in s?s.toDate().toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):String(s):""}const xe=({constraintsRef:s,onFullScreen:o})=>{const{activeSessionId:n,setActiveSessionId:u,createNewSession:d,getActiveSession:h,sendMessage:m,isLoading:f}=O(),{currentUser:c,userRole:y}=D(),[i,x]=a.useState(!1),[g,j]=a.useState(()=>typeof window>"u"?!1:window.localStorage.getItem("floating_ai_tutor_minimized")==="1"),[p,v]=a.useState(""),[r,b]=a.useState(null),N=a.useRef(null),k=a.useRef(null);a.useEffect(()=>{if(!c?.uid||y!=="student")return;let t=!1;return X(c.uid,l=>{l&&l.id!==k.current?b(l):(b(null),t||(t=!0,Y(c.uid)))})},[c?.uid,y]),a.useEffect(()=>{typeof window>"u"||window.localStorage.setItem("floating_ai_tutor_minimized",g?"1":"0")},[g]),a.useEffect(()=>{i&&w(async()=>{const{warmupBackend:t}=await import("./index-Bp7MiGcW.js").then(l=>l.b8);return{warmupBackend:t}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11])).then(({warmupBackend:t})=>{t()}).catch(t=>{console.warn("Floating tutor warmup skipped:",t)})},[i]),a.useEffect(()=>{if(i&&!n){const t=r?r.message:"Hi! I'm your AI math tutor. What would you like to learn about today?",l={id:r?`nudge-${r.id}`:"1",sender:"ai",text:t,timestamp:new Date().toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})},R=d(l);u(R)}},[i]),a.useEffect(()=>{i&&r&&c?.uid&&(k.current=r.id,J(c.uid,r.id).catch(()=>{}),b(null))},[i,r]);const I=h()?.messages||[],M=()=>{N.current?.scrollIntoView({behavior:"smooth"})};a.useEffect(()=>{M()},[I]);const _=async()=>{if(!p.trim()||!n||f)return;const t=p.trim();v(""),await m(n,t)},E=()=>{o()},S=()=>{x(!1),j(!0)},L=()=>{j(!1)};return e.jsxs("div",{className:"pointer-events-none flex flex-col items-end",children:[e.jsxs("div",{className:`pointer-events-auto mb-4 w-80 bg-[#f7f9fc] rounded-3xl shadow-2xl border border-[#dde3eb] flex flex-col overflow-hidden transition-all duration-300 origin-bottom-right select-none ${i?"opacity-100 scale-100 translate-y-0":"opacity-0 scale-95 translate-y-10 pointer-events-none h-0"}`,style:{"--max-h":i?"32rem":"0",willChange:"transform, opacity"},children:[e.jsxs("div",{className:"bg-gradient-to-r from-sky-600 to-sky-500 p-4 flex items-center justify-between flex-shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 bg-white/20 rounded-xl flex items-center justify-center backdrop-blur-sm",children:e.jsx("img",{src:"/avatar/avatar_icon.png",alt:"AI Tutor",className:"w-9 h-9 object-contain drop-shadow-md"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-white font-bold text-sm",children:"L.O.L.I."}),e.jsxs("p",{className:"text-sky-100 text-[10px] leading-tight",children:["Logical Operations &",e.jsx("br",{}),"Learning Intelligence"]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:E,type:"button","aria-label":"Open fullscreen",className:"p-2 hover:bg-white/20 rounded-lg transition-colors",title:"Open fullscreen",children:e.jsx(K,{size:16,className:"text-white"})}),e.jsx("button",{type:"button","aria-label":"Minimize AI tutor launcher",onClick:S,className:"p-2 hover:bg-white/20 rounded-lg transition-colors",title:"Minimize",children:e.jsx(z,{size:16,className:"text-white"})}),e.jsx("button",{type:"button","aria-label":"Close chat",onClick:()=>x(!1),className:"p-2 hover:bg-white/20 rounded-lg transition-colors",children:e.jsx(C,{size:16,className:"text-white"})})]})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-4 space-y-3 bg-[#edf1f7]",children:[I.map(t=>e.jsx("div",{className:`flex ${t.sender==="user"?"justify-end":"justify-start"}`,children:e.jsxs("div",{className:`max-w-[75%] rounded-2xl px-4 py-2.5 ${t.sender==="user"?"bg-sky-600 text-white":"bg-white text-[#0a1628] shadow-sm border border-[#dde3eb]"}`,children:[t.sender==="user"?e.jsx("p",{className:"text-sm whitespace-pre-wrap",children:t.text}):e.jsx(a.Suspense,{fallback:e.jsx("p",{className:"text-sm whitespace-pre-wrap",children:t.text}),children:e.jsx(Z,{children:t.text})}),e.jsx("p",{className:`text-[10px] mt-1 ${t.sender==="user"?"text-sky-200":"text-slate-500"}`,children:ee(t.timestamp)})]})},t.id)),f&&e.jsx("div",{className:"flex justify-start",children:e.jsx("div",{className:"bg-white text-[#0a1628] shadow-sm border border-[#dde3eb] rounded-2xl px-4 py-2.5 max-w-[75%]",children:e.jsxs("div",{className:"flex gap-1",children:[e.jsx("div",{className:"w-2 h-2 bg-sky-400 rounded-full animate-bounce"}),e.jsx("div",{className:"w-2 h-2 bg-sky-400 rounded-full animate-bounce [animation-delay:150ms]"}),e.jsx("div",{className:"w-2 h-2 bg-sky-400 rounded-full animate-bounce [animation-delay:300ms]"})]})})}),e.jsx("div",{ref:N})]}),e.jsx("div",{className:"p-4 border-t border-[#dde3eb] bg-white flex-shrink-0",children:e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{id:"ai-tutor-input",name:"ai-tutor-input","aria-label":"Ask AI tutor a question",type:"text",value:p,onChange:t=>v(t.target.value),onKeyPress:t=>t.key==="Enter"&&_(),placeholder:"Ask me anything...",className:"flex-1 px-4 py-2.5 rounded-xl border border-[#dde3eb] focus:outline-none focus:ring-2 focus:ring-sky-500 text-sm bg-[#f7f9fc]"}),e.jsx("button",{type:"button","aria-label":"Send message",onClick:_,className:"p-2.5 bg-sky-600 hover:bg-sky-700 text-white rounded-xl transition-colors disabled:opacity-50 disabled:cursor-not-allowed",disabled:!p.trim()||f,children:e.jsx(W,{size:18})})]})})]}),e.jsx("div",{className:"pointer-events-auto relative self-end",children:g?e.jsx(A.button,{type:"button",onClick:L,whileHover:{scale:1.08},whileTap:{scale:.95},transition:{duration:.15,ease:"easeOut"},className:"h-9 w-9 rounded-full bg-slate-900/85 text-white shadow-lg ring-1 ring-white/20 backdrop-blur-sm flex items-center justify-center","aria-label":"Restore AI tutor launcher",title:"Show AI tutor",style:{willChange:"transform"},children:e.jsx(P,{size:14})}):e.jsxs("div",{className:"relative group",children:[!i&&e.jsxs("div",{className:"absolute right-full mr-4 top-1/2 -translate-y-1/2 px-4 py-2 bg-slate-800 text-white text-sm rounded-xl opacity-0 group-hover:opacity-100 transition-opacity duration-300 pointer-events-none whitespace-nowrap shadow-xl z-50",children:["Hello! I'm L.O.L.I., how may I help you?",e.jsx("div",{className:"absolute top-1/2 -translate-y-1/2 -right-1 w-3 h-3 bg-slate-800 rotate-45"})]}),!i&&e.jsx("button",{type:"button","aria-label":"Minimize AI tutor launcher",title:"Minimize",onClick:S,className:"absolute -top-2 -left-2 z-10 h-6 w-6 rounded-full bg-white text-slate-700 border border-slate-200 shadow-md hover:bg-slate-100 transition-colors flex items-center justify-center",children:e.jsx(z,{size:12})}),e.jsxs(A.button,{type:"button",onClick:()=>x(!i),whileHover:{scale:1.1},whileTap:{scale:.9},transition:{duration:.15,ease:"easeOut"},className:"w-16 h-16 bg-gradient-to-br from-sky-600 to-sky-500 rounded-xl shadow-2xl flex items-center justify-center text-white hover:shadow-sky-300/50 transition-all","aria-label":i?"Close AI tutor chat":"Open AI tutor chat",style:{willChange:"transform"},children:[i?e.jsx(C,{size:28}):e.jsx("img",{src:"/avatar/avatar_icon.png",alt:"AI Tutor",className:"w-14 h-14 object-contain drop-shadow-lg"}),!i&&r&&e.jsx("span",{className:"absolute -top-1 -right-1 w-4 h-4 bg-amber-400 rounded-full border-2 border-white animate-pulse"})]})]})})]})};export{xe as default}; diff --git a/assets/GradesPage-Dtj8WgVn.js b/assets/GradesPage-CTmxSKZ7.js similarity index 95% rename from assets/GradesPage-Dtj8WgVn.js rename to assets/GradesPage-CTmxSKZ7.js index 878967ae1545fef51ec5d28c8396b04d6333cc73..093951102e2d167fda520b21c62b4f9e34fddf18 100644 --- a/assets/GradesPage-Dtj8WgVn.js +++ b/assets/GradesPage-CTmxSKZ7.js @@ -1,3 +1,3 @@ -const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/DiagnosticBreakdown-BF7w8Bn-.js","assets/vendor-react-B4AQeu28.js","assets/vendor-firebase-firestore-CNv3xXal.js","assets/vendor-firebase-core-D7GXCeNu.js","assets/index-BufUS6SI.js","assets/vendor-firebase-auth-T_wvTOvf.js","assets/vendor-firebase-storage-Bi7H_66d.js","assets/vendor-firebase-analytics-rHarj5hR.js","assets/vendor-radix-C5nwdvGr.js","assets/vendor-charts-CAmziV1y.js","assets/vendor-markdown-yqZQ_iQm.js","assets/vendor-markdown-CfVKi3_s.css","assets/index-CIg5rXpX.css","assets/x-BuBjuj2Y.js","assets/clock-CooTZK0X.js","assets/lightbulb-bxzKA78M.js","assets/circle-check-BzgmgbHa.js","assets/chart-column-BcVJ31XT.js","assets/chevron-up-CoNRuMZ7.js"])))=>i.map(i=>d[i]); -import{u as re,aH as le,aI as ne,ad as oe,g as S,H as ie,A as ce,r as O,T as F,B as de,_ as me}from"./index-BufUS6SI.js";import{r as o,j as e}from"./vendor-react-B4AQeu28.js";import{B as k}from"./button-DsnZWCoA.js";import{g as xe,S as _,s as pe}from"./subjects-D9a9cUC-.js";import{u as ue}from"./useCurriculum-DhjMQzo9.js";import{getDoc as A,doc as z}from"./vendor-firebase-firestore-CNv3xXal.js";import{D as he}from"./download-DGNoiQkf.js";import{C as be}from"./circle-check-BzgmgbHa.js";import{C as ge}from"./circle-alert-DDdeEgNa.js";import{F as q}from"./funnel-zhOTiCKD.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-radix-C5nwdvGr.js";import"./vendor-charts-CAmziV1y.js";import"./vendor-markdown-yqZQ_iQm.js";import"./chart-column-BcVJ31XT.js";const fe=o.lazy(()=>me(()=>import("./DiagnosticBreakdown-BF7w8Bn-.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18]))),$e=()=>{const{currentUser:d,userProfile:C}=re(),[u,E]=o.useState("all"),[b,H]=o.useState("all"),[V,w]=o.useState(!0),[g,Y]=o.useState(null),[M,K]=o.useState([]),[m,W]=o.useState(null),[T,v]=o.useState(!1),[p,J]=o.useState(null),L=C?.grade,P=xe(L),R=new Set(P),{isLoading:X}=ue(L);o.useEffect(()=>{},[X]);const D=s=>{if(s==null)return"N/A";const t=s instanceof Date?s:new Date(s);return Number.isNaN(t.getTime())?"N/A":t.toISOString().split("T")[0]};o.useEffect(()=>{if(!d)return;w(!0);const s=le(d.uid,a=>{Y(a),w(!1)}),t=ne(d.uid,a=>{K(a),w(!1)}),r=oe(d.uid,a=>{J(a)});return()=>{s(),t(),r()}},[d]),o.useEffect(()=>{d?.uid&&(async()=>{try{let s=0,t="Unknown",r=[],a="";const l=await A(z(S,"users",d.uid,"dashboardSummary","heroBannerModal"));if(l.exists()){const n=l.data();n.status==="ready"&&(s=n.latestScorePercent||0,t=n.latestRiskLevel||"Unknown",r=n.weaknesses||[],a=n.recommendation||"")}else{const n=await A(z(S,"users",d.uid));if(n.exists()){const i=n.data();(i.initialAssessmentCompleted||i.hasCompletedInitialAssessment)&&(t=i.atRiskSubjects?.length>0?"Moderate":"Low",r=i.atRiskSubjects||[])}}const x=await A(z(S,"diagnosticResults",d.uid,"cache","analysis"));if(x.exists()){const n=x.data(),i=n.recommendations||[];i.length>0&&(a=i.map(c=>c.action).join(". ")+".");const j=n.weakness_areas||[];j.length>0&&(r=j.map(c=>c.domain))}(s>0||t!=="Unknown"||r.length>0)&&W({score:s,riskLevel:t,weaknesses:r,recommendation:a||"Continue with your personalized learning path."})}catch{}})()},[d?.uid]);const N=g?.averageScore?Math.round(g.averageScore):p?.averageScore?Math.round(p.averageScore):0,Z=Math.max(g?.quizzesCompleted??0,p?.quizAttempts?.length??0),ee=N>0?N.toString():"—",se={"gen-math":"indigo","stats-prob":"violet"},$={indigo:{dot:"bg-indigo-500",bar:"bg-indigo-500"},violet:{dot:"bg-violet-500",bar:"bg-violet-500"},fuchsia:{dot:"bg-fuchsia-500",bar:"bg-fuchsia-500"},purple:{dot:"bg-purple-500",bar:"bg-purple-500"},slate:{dot:"bg-slate-500",bar:"bg-slate-500"}},U=_.reduce((s,t)=>(s[t.id]={label:t.name,color:se[t.id]||"slate"},s),{}),h=_.filter(s=>R.has(s.id)).map(s=>s.name),B=Object.entries(p?.subjects??{}).filter(([s])=>R.has(s)).map(([s,t])=>{const r=U[s]||{label:s,color:"slate"},a=(p?.quizAttempts||[]).filter(x=>{const n=t?.modulesProgress||{};return Object.values(n).some(i=>i.quizzesCompleted?.includes(x.quizId))}),l=a.length>0?Math.round(a.reduce((x,n)=>x+n.score,0)/a.length):Math.round(t?.progress??0);return{subject:r.label,average:l,quizzes:a.length||t?.completedModules||0,color:r.color}}),te=P.map(s=>{const t=U[s]||{label:s,color:"slate"},r=g?.subjectPerformance?.[t.label],a=r?.avgScore?Math.round(r.avgScore):0;return{subject:t.label,average:a,quizzes:r?.count||0,color:t.color}}),I=B.length>0?B:te,Q=o.useMemo(()=>{if(!p?.quizAttempts?.length)return[];const s=new Map;return pe.forEach(t=>{const a=_.find(l=>l.id===t.id)?.name||t.title;t.modules.forEach(l=>{l.quizzes.forEach(x=>{s.set(x.id,{title:x.title,subject:a})})})}),p.quizAttempts.map((t,r)=>{const a=s.get(t.quizId),l=t.completedAt instanceof Date?t.completedAt:new Date(t.completedAt);return{id:1e4+r,title:a?.title||t.quizId.replace(/-/g," ").replace(/\b\w/g,x=>x.toUpperCase()),subject:a?.subject||"General Mathematics",score:Math.round(t.score),date:D(l),type:"quiz",status:t.score>=80?"Excellent":t.score>=60?"Passing":"Needs Review",_timestamp:l.getTime()}})},[p?.quizAttempts]),G=o.useMemo(()=>{const s=M.slice().map((a,l)=>({id:l+1,title:a.title||`Assessment ${l+1}`,subject:a.subject||"General",score:a.score,date:a.completedAt?D(a.completedAt.toDate()):"N/A",type:a.type==="practice"?"practice":(a.type==="diagnostic","quiz"),status:a.score>=80?"Excellent":a.score>=60?"Passing":"Needs Review",_timestamp:a.completedAt?.toDate?.()?.getTime()??0})),t=new Set(s.map(a=>a.title.toLowerCase())),r=Q.filter(a=>!t.has(a.title.toLowerCase()));return[...s,...r].sort((a,l)=>(l._timestamp||0)-(a._timestamp||0)).slice(0,20).filter(a=>h.includes(a.subject))},[M,Q,h]),f=G.filter(s=>{if(!h.includes(s.subject))return!1;const t=u==="all"||s.subject===u,r=b==="all"||s.type===b;return t&&r});o.useEffect(()=>{u!=="all"&&(h.includes(u)||E("all"))},[h,u]);const ae=()=>{const s=c=>{const y=String(c??"");return/[",\n]/.test(y)?`"${y.replace(/"/g,'""')}"`:y},t=[],r=C?.name||d?.displayName||d?.email||"Student",a=new Date().toISOString().split("T")[0];t.push("Grade Report"),t.push(`Student,${s(r)}`),t.push(`Export Date,${s(a)}`),t.push(`Subject Filter,${s(u)}`),t.push(`Type Filter,${s(b)}`),t.push(""),t.push("Subject Performance"),t.push("Subject,Average Score"),I.forEach(c=>{t.push([s(c.subject),s(c.average)].join(","))}),t.push(""),t.push("Recent Quizzes"),t.push("Title,Subject,Score,Date,Type,Status"),f.length===0?t.push("No quiz data available for the selected filters"):f.forEach(c=>{t.push([s(c.title),s(c.subject),s(c.score),s(c.date),s(c.type),s(c.status)].join(","))});const l=t.join(` +const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/DiagnosticBreakdown-DkqMV9oI.js","assets/vendor-react-B4AQeu28.js","assets/vendor-firebase-firestore-CNv3xXal.js","assets/vendor-firebase-core-D7GXCeNu.js","assets/index-Bp7MiGcW.js","assets/vendor-firebase-auth-T_wvTOvf.js","assets/vendor-firebase-storage-Bi7H_66d.js","assets/vendor-firebase-analytics-rHarj5hR.js","assets/vendor-radix-C5nwdvGr.js","assets/vendor-charts-CAmziV1y.js","assets/vendor-markdown-yqZQ_iQm.js","assets/vendor-markdown-CfVKi3_s.css","assets/index-Dja0MwoB.css","assets/x-k8d6VLEw.js","assets/clock-Cc6sJz1J.js","assets/lightbulb-DG1NwVgr.js","assets/circle-check-DzQphSnP.js","assets/chart-column-Dyv8TfXk.js","assets/chevron-up-DtS9MvUZ.js"])))=>i.map(i=>d[i]); +import{u as re,aH as le,aI as ne,ad as oe,g as S,H as ie,A as ce,r as O,T as F,B as de,_ as me}from"./index-Bp7MiGcW.js";import{r as o,j as e}from"./vendor-react-B4AQeu28.js";import{B as k}from"./button-BMVm9YQO.js";import{g as xe,S as _,s as pe}from"./subjects-DNoBzeBL.js";import{u as ue}from"./useCurriculum-BaLeFz19.js";import{getDoc as A,doc as z}from"./vendor-firebase-firestore-CNv3xXal.js";import{D as he}from"./download-DFL4ZCXr.js";import{C as be}from"./circle-check-DzQphSnP.js";import{C as ge}from"./circle-alert-CHGy8HcB.js";import{F as q}from"./funnel-KPSYPixk.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-radix-C5nwdvGr.js";import"./vendor-charts-CAmziV1y.js";import"./vendor-markdown-yqZQ_iQm.js";import"./chart-column-Dyv8TfXk.js";const fe=o.lazy(()=>me(()=>import("./DiagnosticBreakdown-DkqMV9oI.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18]))),$e=()=>{const{currentUser:d,userProfile:C}=re(),[u,E]=o.useState("all"),[b,H]=o.useState("all"),[V,w]=o.useState(!0),[g,Y]=o.useState(null),[M,K]=o.useState([]),[m,W]=o.useState(null),[T,v]=o.useState(!1),[p,J]=o.useState(null),L=C?.grade,P=xe(L),R=new Set(P),{isLoading:X}=ue(L);o.useEffect(()=>{},[X]);const D=s=>{if(s==null)return"N/A";const t=s instanceof Date?s:new Date(s);return Number.isNaN(t.getTime())?"N/A":t.toISOString().split("T")[0]};o.useEffect(()=>{if(!d)return;w(!0);const s=le(d.uid,a=>{Y(a),w(!1)}),t=ne(d.uid,a=>{K(a),w(!1)}),r=oe(d.uid,a=>{J(a)});return()=>{s(),t(),r()}},[d]),o.useEffect(()=>{d?.uid&&(async()=>{try{let s=0,t="Unknown",r=[],a="";const l=await A(z(S,"users",d.uid,"dashboardSummary","heroBannerModal"));if(l.exists()){const n=l.data();n.status==="ready"&&(s=n.latestScorePercent||0,t=n.latestRiskLevel||"Unknown",r=n.weaknesses||[],a=n.recommendation||"")}else{const n=await A(z(S,"users",d.uid));if(n.exists()){const i=n.data();(i.initialAssessmentCompleted||i.hasCompletedInitialAssessment)&&(t=i.atRiskSubjects?.length>0?"Moderate":"Low",r=i.atRiskSubjects||[])}}const x=await A(z(S,"diagnosticResults",d.uid,"cache","analysis"));if(x.exists()){const n=x.data(),i=n.recommendations||[];i.length>0&&(a=i.map(c=>c.action).join(". ")+".");const j=n.weakness_areas||[];j.length>0&&(r=j.map(c=>c.domain))}(s>0||t!=="Unknown"||r.length>0)&&W({score:s,riskLevel:t,weaknesses:r,recommendation:a||"Continue with your personalized learning path."})}catch{}})()},[d?.uid]);const N=g?.averageScore?Math.round(g.averageScore):p?.averageScore?Math.round(p.averageScore):0,Z=Math.max(g?.quizzesCompleted??0,p?.quizAttempts?.length??0),ee=N>0?N.toString():"—",se={"gen-math":"indigo","stats-prob":"violet"},$={indigo:{dot:"bg-indigo-500",bar:"bg-indigo-500"},violet:{dot:"bg-violet-500",bar:"bg-violet-500"},fuchsia:{dot:"bg-fuchsia-500",bar:"bg-fuchsia-500"},purple:{dot:"bg-purple-500",bar:"bg-purple-500"},slate:{dot:"bg-slate-500",bar:"bg-slate-500"}},U=_.reduce((s,t)=>(s[t.id]={label:t.name,color:se[t.id]||"slate"},s),{}),h=_.filter(s=>R.has(s.id)).map(s=>s.name),B=Object.entries(p?.subjects??{}).filter(([s])=>R.has(s)).map(([s,t])=>{const r=U[s]||{label:s,color:"slate"},a=(p?.quizAttempts||[]).filter(x=>{const n=t?.modulesProgress||{};return Object.values(n).some(i=>i.quizzesCompleted?.includes(x.quizId))}),l=a.length>0?Math.round(a.reduce((x,n)=>x+n.score,0)/a.length):Math.round(t?.progress??0);return{subject:r.label,average:l,quizzes:a.length||t?.completedModules||0,color:r.color}}),te=P.map(s=>{const t=U[s]||{label:s,color:"slate"},r=g?.subjectPerformance?.[t.label],a=r?.avgScore?Math.round(r.avgScore):0;return{subject:t.label,average:a,quizzes:r?.count||0,color:t.color}}),I=B.length>0?B:te,Q=o.useMemo(()=>{if(!p?.quizAttempts?.length)return[];const s=new Map;return pe.forEach(t=>{const a=_.find(l=>l.id===t.id)?.name||t.title;t.modules.forEach(l=>{l.quizzes.forEach(x=>{s.set(x.id,{title:x.title,subject:a})})})}),p.quizAttempts.map((t,r)=>{const a=s.get(t.quizId),l=t.completedAt instanceof Date?t.completedAt:new Date(t.completedAt);return{id:1e4+r,title:a?.title||t.quizId.replace(/-/g," ").replace(/\b\w/g,x=>x.toUpperCase()),subject:a?.subject||"General Mathematics",score:Math.round(t.score),date:D(l),type:"quiz",status:t.score>=80?"Excellent":t.score>=60?"Passing":"Needs Review",_timestamp:l.getTime()}})},[p?.quizAttempts]),G=o.useMemo(()=>{const s=M.slice().map((a,l)=>({id:l+1,title:a.title||`Assessment ${l+1}`,subject:a.subject||"General",score:a.score,date:a.completedAt?D(a.completedAt.toDate()):"N/A",type:a.type==="practice"?"practice":(a.type==="diagnostic","quiz"),status:a.score>=80?"Excellent":a.score>=60?"Passing":"Needs Review",_timestamp:a.completedAt?.toDate?.()?.getTime()??0})),t=new Set(s.map(a=>a.title.toLowerCase())),r=Q.filter(a=>!t.has(a.title.toLowerCase()));return[...s,...r].sort((a,l)=>(l._timestamp||0)-(a._timestamp||0)).slice(0,20).filter(a=>h.includes(a.subject))},[M,Q,h]),f=G.filter(s=>{if(!h.includes(s.subject))return!1;const t=u==="all"||s.subject===u,r=b==="all"||s.type===b;return t&&r});o.useEffect(()=>{u!=="all"&&(h.includes(u)||E("all"))},[h,u]);const ae=()=>{const s=c=>{const y=String(c??"");return/[",\n]/.test(y)?`"${y.replace(/"/g,'""')}"`:y},t=[],r=C?.name||d?.displayName||d?.email||"Student",a=new Date().toISOString().split("T")[0];t.push("Grade Report"),t.push(`Student,${s(r)}`),t.push(`Export Date,${s(a)}`),t.push(`Subject Filter,${s(u)}`),t.push(`Type Filter,${s(b)}`),t.push(""),t.push("Subject Performance"),t.push("Subject,Average Score"),I.forEach(c=>{t.push([s(c.subject),s(c.average)].join(","))}),t.push(""),t.push("Recent Quizzes"),t.push("Title,Subject,Score,Date,Type,Status"),f.length===0?t.push("No quiz data available for the selected filters"):f.forEach(c=>{t.push([s(c.title),s(c.subject),s(c.score),s(c.date),s(c.type),s(c.status)].join(","))});const l=t.join(` `),x=new Blob([l],{type:"text/csv;charset=utf-8;"}),n=window.URL.createObjectURL(x),i=document.createElement("a"),j=r.replace(/[^a-z0-9]+/gi,"-").replace(/^-+|-+$/g,"").toLowerCase()||"student";i.href=n,i.setAttribute("download",`grade-report-${j}-${a}.csv`),document.body.appendChild(i),i.click(),document.body.removeChild(i),window.URL.revokeObjectURL(n)};return V?e.jsx("div",{className:"p-8 flex justify-center items-center h-full",children:e.jsx("div",{className:"w-10 h-10 border-4 border-indigo-500 border-t-transparent rounded-full animate-spin"})}):e.jsxs("div",{className:"p-4 sm:p-6 lg:p-8 space-y-6 lg:space-y-8 max-w-7xl mx-auto",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4 bg-white p-5 sm:p-6 rounded-[1.5rem] sm:rounded-[2rem] shadow-[0_8px_30px_-12px_rgba(0,0,0,0.06)] border border-slate-50",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-display font-black text-slate-800 tracking-tight",children:"Assessment"}),e.jsx("p",{className:"text-slate-400 font-bold mt-1 text-[13px]",children:"Review your performance across subjects"})]}),e.jsxs("div",{className:"flex gap-3 w-full sm:w-auto",children:[e.jsxs(k,{variant:"outline",className:"flex-1 sm:flex-none border-slate-200 text-slate-500 font-bold rounded-xl h-11 px-5 hover:bg-slate-50 hover:text-slate-700",children:[e.jsx(ie,{className:"w-4 h-4 mr-2 text-slate-400"}),"This Quarter"]}),e.jsxs(k,{className:"flex-1 sm:flex-none bg-indigo-600 hover:bg-indigo-700 text-white font-bold rounded-xl h-11 px-5 shadow-[0_8px_20px_-8px_rgba(79,70,229,0.5)] hover:-translate-y-0.5 transition-all",onClick:ae,children:[e.jsx(he,{className:"w-4 h-4 mr-2"}),"Report"]})]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3 sm:gap-6",children:[e.jsxs("div",{className:"bg-white rounded-[1.2rem] sm:rounded-[2rem] border border-slate-100 p-4 sm:p-8 shadow-[0_8px_24px_-10px_rgba(0,0,0,0.05)] relative overflow-hidden group hover:border-indigo-100 transition-colors",children:[e.jsx("div",{className:"absolute -right-6 -top-6 sm:-right-8 sm:-top-8 w-20 h-20 sm:w-32 sm:h-32 bg-indigo-50 rounded-full group-hover:scale-110 transition-transform duration-500"}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"w-10 h-10 sm:w-14 sm:h-14 bg-indigo-100 text-indigo-600 rounded-xl sm:rounded-2xl flex items-center justify-center mb-3 sm:mb-6 shadow-sm",children:e.jsx(ce,{className:"w-5 h-5 sm:w-7 sm:h-7"})}),e.jsxs("p",{className:"text-slate-400 font-bold text-[9px] sm:text-sm tracking-wider sm:tracking-wide uppercase h-6 sm:h-auto flex items-end sm:block",children:[e.jsx("span",{className:"sm:hidden",children:"GEN. AVE."}),e.jsx("span",{className:"hidden sm:inline",children:"General Average"})]}),e.jsx("div",{className:"flex items-end gap-2 mt-1 sm:mt-2",children:e.jsxs("h3",{className:"text-xl sm:text-4xl font-display font-black text-slate-800",children:[ee,N>0?"%":""]})})]})]}),e.jsxs("div",{className:"bg-white rounded-[1.2rem] sm:rounded-[2rem] border border-slate-100 p-4 sm:p-8 shadow-[0_8px_24px_-10px_rgba(0,0,0,0.05)] relative overflow-hidden group hover:border-emerald-100 transition-colors",children:[e.jsx("div",{className:"absolute -right-6 -top-6 sm:-right-8 sm:-top-8 w-20 h-20 sm:w-32 sm:h-32 bg-emerald-50 rounded-full group-hover:scale-110 transition-transform duration-500"}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"w-10 h-10 sm:w-14 sm:h-14 bg-emerald-100 text-emerald-600 rounded-xl sm:rounded-2xl flex items-center justify-center mb-3 sm:mb-6 shadow-sm",children:e.jsx(O,{className:"w-5 h-5 sm:w-7 sm:h-7"})}),e.jsxs("p",{className:"text-slate-400 font-bold text-[9px] sm:text-sm tracking-wider sm:tracking-wide uppercase h-6 sm:h-auto flex items-end sm:block",children:[e.jsx("span",{className:"sm:hidden",children:"Weakest"}),e.jsx("span",{className:"hidden sm:inline",children:"Weakest Subject"})]}),e.jsx("div",{className:"flex items-end gap-2 mt-1 sm:mt-2",children:e.jsx("h3",{className:"text-lg sm:text-2xl font-display font-black text-slate-800 truncate",children:m?.weaknesses?.[0]||"—"})})]})]}),e.jsxs("div",{className:"bg-white rounded-[1.2rem] sm:rounded-[2rem] border border-slate-100 p-4 sm:p-8 shadow-[0_8px_24px_-10px_rgba(0,0,0,0.05)] relative overflow-hidden group hover:border-violet-100 transition-colors",children:[e.jsx("div",{className:"absolute -right-6 -top-6 sm:-right-8 sm:-top-8 w-20 h-20 sm:w-32 sm:h-32 bg-violet-50 rounded-full group-hover:scale-110 transition-transform duration-500"}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"w-10 h-10 sm:w-14 sm:h-14 bg-violet-100 text-violet-600 rounded-xl sm:rounded-2xl flex items-center justify-center mb-3 sm:mb-6 shadow-sm",children:e.jsx(F,{className:"w-5 h-5 sm:w-7 sm:h-7"})}),e.jsxs("p",{className:"text-slate-400 font-bold text-[9px] sm:text-sm tracking-wider sm:tracking-wide uppercase h-6 sm:h-auto flex items-end sm:block",children:[e.jsx("span",{className:"sm:hidden",children:"Quizzes"}),e.jsx("span",{className:"hidden sm:inline",children:"Quizzes Completed"})]}),e.jsx("div",{className:"flex items-end gap-2 mt-1 sm:mt-2",children:e.jsx("h3",{className:"text-xl sm:text-4xl font-display font-black text-slate-800",children:Z})})]})]})]}),m&&e.jsxs("div",{className:"bg-white rounded-2xl border border-slate-100 p-6 shadow-sm cursor-pointer hover:shadow-md hover:border-indigo-200 transition-all",onClick:()=>v(!0),role:"button",tabIndex:0,onKeyDown:s=>{s.key==="Enter"&&v(!0)},children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 bg-indigo-100 rounded-xl flex items-center justify-center",children:e.jsx(de,{className:"w-5 h-5 text-indigo-600"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-bold text-slate-800",children:"Diagnostic Assessment Results"}),e.jsx("p",{className:"text-xs text-slate-500",children:"Your initial competency evaluation"})]})]}),e.jsxs("span",{className:`px-3 py-1 rounded-full text-xs font-bold flex items-center gap-1.5 ${m.riskLevel==="Low"?"bg-emerald-100 text-emerald-700":m.riskLevel==="High"||m.riskLevel==="At Risk"?"bg-red-100 text-red-700":"bg-amber-100 text-amber-700"}`,children:[m.riskLevel==="Low"?e.jsx(be,{size:12}):e.jsx(ge,{size:12}),m.riskLevel]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[m.score>0&&e.jsxs("div",{className:"bg-slate-50 rounded-xl p-4",children:[e.jsx("p",{className:"text-xs font-bold text-slate-400 uppercase mb-1",children:"Score"}),e.jsxs("p",{className:"text-2xl font-black text-slate-800",children:[m.score,"%"]})]}),m.weaknesses.length>0&&e.jsxs("div",{className:"bg-amber-50 border border-amber-100 rounded-xl p-4",children:[e.jsx("p",{className:"text-xs font-bold text-amber-600 uppercase mb-2",children:"Focus Areas"}),e.jsx("ul",{className:"space-y-1",children:m.weaknesses.map((s,t)=>e.jsxs("li",{className:"text-sm text-amber-800 flex items-center gap-2",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-amber-400"}),s]},t))})]}),m.recommendation&&e.jsxs("div",{className:"bg-indigo-50 border border-indigo-100 rounded-xl p-4",children:[e.jsx("p",{className:"text-xs font-bold text-indigo-600 uppercase mb-2",children:"Recommendation"}),e.jsx("p",{className:"text-sm text-indigo-800",children:m.recommendation})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-8",children:[e.jsx("div",{className:"lg:col-span-2",children:e.jsxs("div",{className:"bg-white rounded-[1.5rem] sm:rounded-[2rem] border border-slate-100 shadow-[0_8px_30px_-12px_rgba(0,0,0,0.06)] overflow-hidden flex flex-col h-full w-full",children:[e.jsxs("div",{className:"p-5 sm:p-8 border-b border-slate-50 flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4 sm:gap-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-display font-black text-xl text-slate-800",children:"Recent Assessments"}),e.jsx("p",{className:"text-slate-400 font-bold text-[13px] mt-1",children:"Your latest quiz and practice results"})]}),e.jsxs("div",{className:"flex items-center gap-2 sm:gap-3 w-full sm:w-auto",children:[e.jsxs("div",{className:"relative flex-1 sm:flex-none",children:[e.jsxs("select",{value:u,onChange:s=>E(s.target.value),className:"appearance-none w-full pl-3 pr-8 py-2.5 border-none bg-slate-50 rounded-xl text-xs sm:text-sm font-bold text-slate-600 focus:ring-2 focus:ring-indigo-500/30 transition-all cursor-pointer min-w-0 sm:min-w-[140px] shadow-sm",children:[e.jsx("option",{value:"all",children:"All Subjects"}),h.map(s=>e.jsx("option",{value:s,children:s},s))]}),e.jsx(q,{className:"w-4 h-4 text-slate-400 absolute right-3 top-1/2 -translate-y-1/2 pointer-events-none"})]}),e.jsxs("div",{className:"relative flex-1 sm:flex-none",children:[e.jsxs("select",{value:b,onChange:s=>H(s.target.value),className:"appearance-none w-full pl-3 pr-8 py-2.5 border-none bg-slate-50 rounded-xl text-xs sm:text-sm font-bold text-slate-600 focus:ring-2 focus:ring-indigo-500/30 transition-all cursor-pointer min-w-0 sm:min-w-[120px] shadow-sm",children:[e.jsx("option",{value:"all",children:"All Types"}),e.jsx("option",{value:"quiz",children:"Quiz"}),e.jsx("option",{value:"practice",children:"Practice"})]}),e.jsx(q,{className:"w-4 h-4 text-slate-400 absolute right-3 top-1/2 -translate-y-1/2 pointer-events-none"})]})]})]}),e.jsx("div",{className:"overflow-x-auto no-scrollbar flex-1 px-4 sm:px-6 pb-4 -mx-4 sm:mx-0",children:e.jsxs("table",{className:"w-full text-left border-separate border-spacing-y-2 mb-4 whitespace-nowrap md:whitespace-normal",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-3 text-[11px] font-bold text-slate-400 uppercase tracking-wider border-b border-transparent",children:"Assessment"}),e.jsx("th",{className:"px-4 py-3 text-[11px] font-bold text-slate-400 uppercase tracking-wider border-b border-transparent min-w-[120px]",children:"Subject"}),e.jsx("th",{className:"px-4 py-3 text-[11px] font-bold text-slate-400 uppercase tracking-wider border-b border-transparent",children:"Type"}),e.jsx("th",{className:"px-4 py-3 text-[11px] font-bold text-slate-400 uppercase tracking-wider text-right border-b border-transparent",children:"Score"})]})}),e.jsx("tbody",{children:f.length>0?f.map(s=>e.jsxs("tr",{className:"group hover:bg-slate-50/70 transition-colors",children:[e.jsxs("td",{className:"px-4 py-4 rounded-l-2xl",children:[e.jsx("p",{className:"text-[14px] font-bold text-slate-800",children:s.title}),e.jsx("p",{className:"text-[11px] font-bold text-slate-400 mt-1",children:s.date})]}),e.jsx("td",{className:"px-4 py-4",children:e.jsx("span",{className:"inline-flex flex-col gap-1 items-start",children:e.jsx("span",{className:"text-[13px] font-bold text-slate-600 truncate max-w-[140px] block",children:s.subject})})}),e.jsx("td",{className:"px-4 py-4",children:e.jsx("span",{className:`inline-flex items-center px-3 py-1.5 rounded-lg text-[11px] font-bold uppercase tracking-wide ${s.type==="practice"?"bg-emerald-100/50 text-emerald-600":"bg-indigo-100/50 text-indigo-600"}`,children:s.type==="practice"?"Practice":"Quiz"})}),e.jsx("td",{className:"px-4 py-4 text-right rounded-r-2xl",children:e.jsxs("span",{className:`inline-flex items-center px-3 py-1.5 rounded-xl text-[13px] font-black ${s.score>=80?"bg-emerald-100 text-emerald-700":s.score>=60?"bg-amber-100 text-amber-700":"bg-rose-100 text-rose-700"}`,children:[s.score,"%"]})})]},s.id)):e.jsx("tr",{children:e.jsx("td",{colSpan:4,className:"px-6 py-16 text-center",children:e.jsxs("div",{className:"flex flex-col items-center justify-center",children:[e.jsx("div",{className:"w-16 h-16 bg-slate-50 rounded-full flex items-center justify-center mb-4",children:e.jsx(O,{className:"w-8 h-8 text-slate-300"})}),e.jsx("p",{className:"text-slate-500 font-bold text-sm",children:"No recent assessments match the selected filters."})]})})})})]})})]})}),e.jsxs("div",{className:"space-y-6 lg:space-y-8 flex flex-col",children:[e.jsxs("div",{className:"bg-white rounded-[1.5rem] sm:rounded-[2rem] border border-slate-100 p-5 sm:p-8 shadow-[0_8px_30px_-12px_rgba(0,0,0,0.06)]",children:[e.jsx("div",{className:"flex items-center justify-between mb-8",children:e.jsx("h3",{className:"font-display font-black text-lg text-slate-800",children:"Subject Performance"})}),e.jsx("div",{className:"space-y-7",children:I.map((s,t)=>{const r=$[s.color]||$.slate;return e.jsxs("div",{className:"group",children:[e.jsxs("div",{className:"flex justify-between items-end mb-3",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"text-[14px] font-bold text-slate-800 flex items-center gap-2",children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${r.dot} group-hover:scale-125 transition-transform`}),s.subject]}),e.jsxs("p",{className:"text-[11px] text-slate-400 font-bold ml-4 mt-0.5",children:[s.quizzes," activities"]})]}),e.jsxs("span",{className:"text-[15px] font-black text-slate-800",children:[s.average,"%"]})]}),e.jsx("div",{className:"h-2.5 w-full bg-slate-100 rounded-full overflow-hidden shadow-inner",children:e.jsx("div",{className:`h-full rounded-full e-w ${r.bar} shadow-sm relative overflow-hidden transition-all duration-1000`,style:{"--w":`${Math.max(s.average,5)}%`},children:e.jsx("div",{className:"absolute inset-0 bg-white/20 w-1/2 -skew-x-12 translate-x-[-100%] group-hover:animate-[shimmer_1.5s_ease-out]"})})})]},t)})})]}),e.jsxs("div",{className:"relative bg-gradient-to-br from-indigo-600 to-violet-700 rounded-[1.5rem] sm:rounded-[2rem] p-5 sm:p-8 shadow-[0_12px_30px_-10px_rgba(79,70,229,0.5)] text-white overflow-hidden group",children:[e.jsx("div",{className:"absolute top-0 right-0 w-48 h-48 bg-white/10 rounded-full blur-3xl -mt-10 -mr-10 group-hover:bg-white/20 transition-all duration-700 ease-in-out"}),e.jsx("div",{className:"absolute bottom-0 left-0 w-32 h-32 bg-indigo-400/30 rounded-full blur-2xl -mb-10 -ml-10"}),e.jsxs("div",{className:"relative z-10",children:[e.jsx("div",{className:"w-12 h-12 bg-white/10 rounded-2xl flex items-center justify-center mb-5 backdrop-blur-sm border border-white/20 shadow-sm group-hover:scale-110 transition-transform",children:e.jsx(F,{className:"w-6 h-6 text-white"})}),e.jsx("h3",{className:"text-2xl font-display font-black tracking-tight mb-2 leading-tight",children:"Keep up the momentum!"}),e.jsxs("p",{className:"text-white/80 text-[13px] font-medium leading-relaxed mb-8 max-w-[90%]",children:["You've completed ",e.jsx("span",{className:"font-black text-white",children:G.length})," activities recently. Try a practice session to boost your lowest scores."]}),e.jsx(k,{onClick:()=>{sessionStorage.setItem("mathpulse_modules_tab","practice"),window.dispatchEvent(new CustomEvent("mathpulse:navigate",{detail:{tab:"Modules"}}))},className:"w-full bg-white text-indigo-600 hover:bg-slate-50 border-0 font-black h-12 rounded-xl shadow-[0_8px_16px_rgba(0,0,0,0.15)] hover:shadow-[0_8px_24px_rgba(0,0,0,0.2)] hover:-translate-y-0.5 transition-all",children:"Start Practice Session"})]})]})]})]}),T&&d?.uid&&e.jsx(o.Suspense,{fallback:null,children:e.jsx(fe,{userId:d.uid,mode:"modal",isOpen:T,onClose:()=>v(!1)})})]})};export{$e as default}; diff --git a/assets/HeroBanner-B32-rtu2.js b/assets/HeroBanner-BMkaVujy.js similarity index 97% rename from assets/HeroBanner-B32-rtu2.js rename to assets/HeroBanner-BMkaVujy.js index d2f76f3c7bff95da92bd98ef80c089d4b84c4a4a..2f536629fafd55941e4d26244c2d0cbea702875a 100644 --- a/assets/HeroBanner-B32-rtu2.js +++ b/assets/HeroBanner-BMkaVujy.js @@ -1,3 +1,3 @@ -const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/DashboardAvatar-CbAKGmA6.js","assets/vendor-react-B4AQeu28.js","assets/avatarData-BuQSOXo3.js"])))=>i.map(i=>d[i]); -import{T as R,g as b,a3 as M,h as _,m as f,a4 as E,A as G,B as S,r as z,Z as Y,a as F,_ as Q}from"./index-BufUS6SI.js";import{j as e,r as m}from"./vendor-react-B4AQeu28.js";import{D as W,a as q,S as V}from"./dialog-JRlpFJpo.js";import{R as K,L as X,C as U,X as Z,Y as O,T as I,e as J}from"./vendor-charts-CAmziV1y.js";import{collection as v,query as w,limit as N,orderBy as k,getDocs as A,getDoc as L,doc as C}from"./vendor-firebase-firestore-CNv3xXal.js";import{X as ee}from"./x-BuBjuj2Y.js";import{C as H}from"./circle-alert-DDdeEgNa.js";import{C as se}from"./circle-check-BzgmgbHa.js";import{S as te}from"./sparkles-DYlMf97S.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-radix-C5nwdvGr.js";import"./vendor-markdown-yqZQ_iQm.js";const ae=({history:s})=>{if(s.length===0)return e.jsxs("div",{className:"text-center py-12 text-slate-400",children:[e.jsx(R,{className:"w-12 h-12 mx-auto mb-3 opacity-40"}),e.jsx("p",{className:"text-sm",children:"Complete more assessments to see your progress history."})]});const a=s.map(r=>({date:new Date(r.completedAt).toLocaleDateString("en-US",{month:"short",day:"numeric"}),score:r.percentage,level:r.proficiencyLevel}));return e.jsx("div",{className:"w-full",children:e.jsx(K,{width:"100%",height:250,children:e.jsxs(X,{data:a,margin:{top:10,right:20,left:0,bottom:5},children:[e.jsx(U,{strokeDasharray:"3 3",stroke:"#e2e8f0"}),e.jsx(Z,{dataKey:"date",tick:{fontSize:12,fill:"#64748b"}}),e.jsx(O,{domain:[0,100],tick:{fontSize:12,fill:"#64748b"}}),e.jsx(I,{contentStyle:{borderRadius:"12px",border:"1px solid #e2e8f0",boxShadow:"0 4px 12px rgba(0,0,0,0.08)"}}),e.jsx(J,{type:"monotone",dataKey:"score",stroke:"#0ea5e9",strokeWidth:3,dot:{fill:"#0ea5e9",strokeWidth:2,r:5},activeDot:{r:7,fill:"#0284c7"}})]})})})};async function re(s){const a=v(b,"assessmentResults",s,"attempts"),r=w(a,k("completedAt","desc"),N(10));return(await A(r)).docs.map(i=>{const n=i.data();return{attemptId:n.attemptId,score:n.score,totalQuestions:n.totalQuestions,percentage:n.percentage,completedAt:n.completedAt?.toDate?.()?.toISOString()||n.completedAt,proficiencyLevel:n.proficiencyLevel}})}async function le(s){const a=v(b,"assessmentResults",s,"attempts"),r=w(a,k("completedAt","desc"),N(1)),c=await A(r);if(c.empty)return null;const n=c.docs[0].data();return{...n,completedAt:n.completedAt?.toDate?.()?.toISOString()||n.completedAt}}const oe={Beginner:"bg-amber-100 text-amber-700 border-amber-300",Developing:"bg-blue-100 text-blue-700 border-blue-300",Proficient:"bg-emerald-100 text-emerald-700 border-emerald-300",Advanced:"bg-violet-100 text-violet-700 border-violet-300"},ne=({result:s})=>e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"bg-gradient-to-br from-sky-500 to-teal-600 rounded-xl p-6 text-white",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sky-200 text-sm font-medium",children:"Total Score"}),e.jsxs("p",{className:"text-4xl font-bold",children:[s.score,"/",s.totalQuestions]}),e.jsxs("p",{className:"text-sky-200 text-sm mt-1",children:[s.percentage,"% Correct"]})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("p",{className:"text-sky-200 text-sm font-medium",children:"Proficiency"}),e.jsx("span",{className:`inline-block mt-1 px-3 py-1 rounded-full text-sm font-semibold border ${oe[s.proficiencyLevel]}`,children:s.proficiencyLevel})]})]})}),e.jsxs("div",{children:[e.jsxs("h3",{className:"font-semibold text-slate-800 mb-3 flex items-center gap-2",children:[e.jsx(S,{className:"w-4 h-4 text-sky-500"}),"Competency Breakdown"]}),e.jsx("div",{className:"space-y-2",children:s.competencyBreakdown.map((a,r)=>e.jsxs("div",{className:"flex items-center gap-3 p-3 bg-slate-50 rounded-lg",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm font-medium text-slate-700",children:a.topic}),e.jsxs("p",{className:"text-xs text-slate-500",children:[a.correctAnswers,"/",a.totalQuestions," correct"]})]}),e.jsx("div",{className:"w-20 h-2 bg-slate-200 rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full ${a.accuracyPercent>=70?"bg-emerald-500":"bg-red-400"}`,style:{width:`${a.accuracyPercent}%`}})}),e.jsxs("span",{className:"text-sm font-semibold text-slate-600 w-10 text-right",children:[a.accuracyPercent,"%"]})]},r))})]}),s.aiNarrative&&e.jsx("div",{className:"bg-amber-50 border border-amber-200 rounded-xl p-4",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(te,{className:"w-4 h-4 text-amber-500 mt-0.5 flex-shrink-0"}),e.jsx("p",{className:"text-sm text-amber-800 leading-relaxed",children:s.aiNarrative})]})}),e.jsxs("div",{children:[e.jsxs("h3",{className:"font-semibold text-slate-800 mb-3 flex items-center gap-2",children:[e.jsx(z,{className:"w-4 h-4 text-sky-500"}),"Question Breakdown"]}),e.jsx("div",{className:"space-y-3",children:s.answers.map((a,r)=>e.jsxs("div",{className:`p-4 rounded-xl border-2 ${a.isCorrect?"border-emerald-200 bg-emerald-50/30":"border-red-200 bg-red-50/30"}`,children:[e.jsxs("p",{className:"text-sm font-medium text-slate-800 mb-2",children:["Q",r+1,". ",a.questionText]}),e.jsxs("div",{className:"flex items-center gap-4 text-sm",children:[e.jsxs("span",{className:"text-slate-500",children:["Your answer: ",e.jsx("span",{className:a.isCorrect?"text-emerald-600 font-medium":"text-red-500 font-medium",children:a.userAnswer||"—"})]}),!a.isCorrect&&e.jsxs("span",{className:"text-slate-500",children:["Correct: ",e.jsx("span",{className:"text-emerald-600 font-medium",children:a.correctAnswer})]})]}),a.explanation&&e.jsx("p",{className:"text-xs text-slate-500 mt-2 leading-relaxed",children:a.explanation})]},r))})]})]}),ie=({summary:s})=>e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row gap-4 items-start sm:items-center justify-between",children:[e.jsxs("div",{className:"bg-sky-50 border border-sky-100 rounded-2xl p-4 flex items-center gap-4 flex-1",children:[e.jsxs("div",{className:"w-12 h-12 bg-sky-500 rounded-full flex items-center justify-center text-white font-bold text-lg shadow-sm",children:[s.latestScorePercent,"%"]}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium text-slate-500",children:"Latest Score"}),e.jsx("p",{className:"text-slate-800 font-bold",children:s.headline})]})]}),s.latestRiskLevel&&e.jsxs("div",{className:`px-4 py-2 rounded-full text-sm font-semibold flex items-center gap-2 - ${s.latestRiskLevel==="At Risk"?"bg-red-100 text-red-700":s.latestRiskLevel==="Needs Attention"?"bg-amber-100 text-amber-700":"bg-emerald-100 text-emerald-700"}`,children:[s.latestRiskLevel==="At Risk"?e.jsx(V,{className:"w-4 h-4"}):s.latestRiskLevel==="Needs Attention"?e.jsx(H,{className:"w-4 h-4"}):e.jsx(se,{className:"w-4 h-4"}),s.latestRiskLevel]})]}),e.jsx("div",{className:"bg-slate-50 p-5 rounded-2xl border border-slate-100",children:e.jsx("p",{className:"text-slate-700 leading-relaxed",children:s.summary})}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[s.strengths?.length>0&&e.jsxs("div",{className:"border border-emerald-100 bg-emerald-50/30 rounded-xl p-4",children:[e.jsxs("h4",{className:"font-semibold text-emerald-800 mb-3 flex items-center gap-2",children:[e.jsx(R,{className:"w-4 h-4"}),"Strengths"]}),e.jsx("ul",{className:"space-y-2",children:s.strengths.map((a,r)=>e.jsxs("li",{className:"text-sm text-emerald-700 flex items-start gap-2",children:[e.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-emerald-400 mt-1.5 flex-shrink-0"}),e.jsx("span",{children:a})]},r))})]}),s.weaknesses?.length>0&&e.jsxs("div",{className:"border border-amber-100 bg-amber-50/30 rounded-xl p-4",children:[e.jsxs("h4",{className:"font-semibold text-amber-800 mb-3 flex items-center gap-2",children:[e.jsx(z,{className:"w-4 h-4"}),"Focus Areas"]}),e.jsx("ul",{className:"space-y-2",children:s.weaknesses.map((a,r)=>e.jsxs("li",{className:"text-sm text-amber-700 flex items-start gap-2",children:[e.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-amber-400 mt-1.5 flex-shrink-0"}),e.jsx("span",{children:a})]},r))})]})]}),s.recommendation&&e.jsxs("div",{className:"bg-gradient-to-br from-indigo-50 to-purple-50 rounded-xl p-5 border border-indigo-100",children:[e.jsxs("h4",{className:"font-semibold text-indigo-900 mb-2 flex items-center gap-2",children:[e.jsx(S,{className:"w-4 h-4 text-indigo-500"}),"Recommended Next Step"]}),e.jsx("p",{className:"text-sm text-indigo-800 leading-relaxed",children:s.recommendation})]})]}),de=({heroBannerSummary:s,latestResult:a,loading:r})=>r?e.jsxs("div",{className:"animate-pulse space-y-4",children:[e.jsx("div",{className:"h-32 bg-slate-200 rounded-xl"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"h-4 bg-slate-200 rounded w-3/4"}),e.jsx("div",{className:"h-4 bg-slate-200 rounded w-1/2"}),e.jsx("div",{className:"h-4 bg-slate-200 rounded w-5/6"})]})]}):!s&&!a?e.jsxs("div",{className:"text-center py-8",children:[e.jsx("div",{className:"w-16 h-16 bg-sky-100 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx(S,{className:"w-8 h-8 text-sky-500"})}),e.jsx("h3",{className:"text-lg font-bold text-slate-800 mb-2",children:"Let's personalize your learning"}),e.jsx("p",{className:"text-sm text-slate-500 max-w-xs mx-auto",children:"Complete your diagnostic assessment so I can understand your strengths, weak areas, and the best next lessons for you."})]}):s?.status==="ready"?e.jsx(ie,{summary:s}):a?e.jsx(ne,{result:a}):e.jsxs("div",{className:"text-center py-8",children:[e.jsx("div",{className:"w-16 h-16 bg-amber-100 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx(H,{className:"w-8 h-8 text-amber-500"})}),e.jsx("h3",{className:"text-lg font-bold text-slate-800 mb-2",children:"Your learning summary is being prepared"}),e.jsx("p",{className:"text-sm text-slate-500 max-w-xs mx-auto",children:"Please try opening this again in a moment."})]});async function ce(s){const a=await L(C(b,"competencyProfiles",s)).catch(()=>null);if(a?.exists()){const t=a.data(),l=t.primaryStrength?[t.primaryStrength]:[],o=t.primaryWeakness?[t.primaryWeakness]:[];return{status:"ready",headline:t.overallScore>=70?"Good job — keep it up!":"Let's build your foundation",summary:o.length>0?`Focus on strengthening ${o[0]} to improve your overall performance.`:"Keep practicing to maintain and expand your skills.",strengths:l,weaknesses:o,recommendation:t.suggestedModule?`Start with the ${t.suggestedModule} module.`:"Continue with your personalized learning path.",latestAssessmentId:"",latestScorePercent:t.overallScore||0,latestRiskLevel:t.overallScore>=70?"Low":t.overallScore>=50?"Moderate":"High",updatedAt:t.updatedAt?.toDate?.()||new Date}}const r=await A(w(v(b,"assessments",s,"attempts"),k("completedAt","desc"),N(1))).catch(()=>null);if(r&&!r.empty){const t=r.docs[0].data(),l=t.rawScore||t.overallScorePercent||0,o=t.proficiencyProfile;return{status:"ready",headline:l>=70?"Good job — keep it up!":"Let's build your foundation",summary:o?.weaknesses?.length>0?`Focus on strengthening ${o.weaknesses[0]} to improve.`:l>=70?"You have a solid foundation!":"With practice, you'll build confidence.",strengths:o?.strengths||[],weaknesses:o?.weaknesses||[],recommendation:o?.suggestedStartingModule?`Start with ${o.suggestedStartingModule}.`:"Follow your personalized learning path.",latestAssessmentId:t.assessmentId||"",latestScorePercent:l,latestRiskLevel:l>=70?"Low":l>=50?"Moderate":"High",updatedAt:t.completedAt?.toDate?.()||new Date}}const c=await L(C(b,"diagnosticResults",s)).catch(()=>null);if(c?.exists()){const t=c.data(),l=t.overallScorePercent||t.overall_score_percent||0,o=t.riskProfile?.weak_domains||[];return{status:"ready",headline:l>=70?"Good job — keep it up!":"Let's build your foundation",summary:o.length>0?`Areas to focus on: ${o.join(", ")}.`:"Assessment completed. Follow your learning path.",strengths:[],weaknesses:o,recommendation:t.recommended_intervention||"Continue with your personalized learning path.",latestAssessmentId:"",latestScorePercent:l,latestRiskLevel:t.overall_risk||(l>=70?"Low":"Moderate"),updatedAt:t.completedAt?.toDate?.()||new Date}}const i=await A(w(v(b,"users",s,"assessments"),k("completedAt","desc"),N(5))).catch(()=>null);if(i&&!i.empty){const t=i.docs.map(p=>p.data()),l=t[0],o=l.score||l.scorePercent||0,x=t.length,j=Math.round(t.reduce((p,u)=>p+(u.score||u.scorePercent||0),0)/x);return{status:"ready",headline:o>=70?"Good job — keep it up!":"Let's build your foundation",summary:`You've completed ${x} diagnostic assessment${x>1?"s":""}. Your latest score is ${o}% (average: ${j}%).`,strengths:[],weaknesses:l.risk==="At Risk"||l.risk==="High"?[l.subject||"General Mathematics"]:[],recommendation:"Continue with your personalized learning path to strengthen weak areas.",latestAssessmentId:l.testId||"",latestScorePercent:o,latestRiskLevel:l.risk||(o>=70?"Low":o>=50?"Moderate":"High"),updatedAt:l.completedAt?.toDate?.()||new Date}}const n=await L(C(b,"users",s)).catch(()=>null);if(n?.exists()){const t=n.data();if(t.initialAssessmentCompleted||t.hasCompletedInitialAssessment){const l=t.atRiskSubjects||[];return{status:"ready",headline:"Assessment Complete! ✓",summary:l.length>0?`Areas to focus on: ${l.join(", ")}. Follow your personalized learning path to improve.`:"Your diagnostic assessment is complete. Your personalized learning path is ready.",strengths:[],weaknesses:l,recommendation:"Continue with your recommended lessons to strengthen your skills.",latestAssessmentId:"",latestScorePercent:0,latestRiskLevel:l.length>0?"Moderate":"Low",updatedAt:t.assessmentCompletedAt?.toDate?.()||new Date}}}return null}const me=({isOpen:s,onClose:a,studentId:r,latestResult:c,heroBannerSummary:i})=>{const[n,t]=m.useState("latest"),[l,o]=m.useState(c||null),[x,j]=m.useState([]),[p,u]=m.useState(!1),[g,y]=m.useState(null);m.useEffect(()=>{if(s&&r&&!i){const d=M(r,h=>{y(h)});return()=>d()}},[s,r,i]);const $=i||g;m.useEffect(()=>{s&&r&&(u(!0),(async()=>{try{const[h,T]=await Promise.all([c?Promise.resolve(c):le(r),re(r)]);if(o(h),j(T),!i&&!g){const D=await E(r);if(D)y(D);else{const P=await ce(r);P&&y(P)}}}catch(h){console.error("[AssessmentResultsModal] fetch error:",h)}finally{u(!1)}})())},[s,r,c]);const B=[{key:"latest",label:"Last Results",icon:e.jsx(G,{className:"w-4 h-4"})},{key:"history",label:"History & Trends",icon:e.jsx(R,{className:"w-4 h-4"})}];return e.jsx(W,{open:s,onOpenChange:d=>!d&&a(),children:e.jsxs(q,{className:"max-w-2xl max-h-[85vh] overflow-y-auto p-0 bg-white rounded-2xl shadow-2xl border-0",children:[e.jsxs("div",{className:"sticky top-0 z-10 bg-white border-b border-slate-200 rounded-t-2xl px-6 py-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("h2",{className:"text-xl font-bold text-slate-800",children:"Assessment Results"}),e.jsx("button",{onClick:a,className:"p-1.5 rounded-lg hover:bg-slate-100 transition-colors",children:e.jsx(ee,{className:"w-5 h-5 text-slate-400"})})]}),e.jsx("div",{className:"flex gap-1 bg-slate-100 p-1 rounded-lg",children:B.map(d=>e.jsxs("button",{onClick:()=>t(d.key),className:`flex items-center gap-2 px-4 py-2 rounded-md text-sm font-medium transition-all ${n===d.key?"bg-white text-sky-600 shadow-sm":"text-slate-600 hover:text-slate-800"}`,children:[d.icon,d.label]},d.key))})]}),e.jsx("div",{className:"px-6 py-5",children:e.jsxs(_,{mode:"wait",children:[n==="latest"&&e.jsx(f.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},children:e.jsx(de,{heroBannerSummary:$,latestResult:l,loading:p})},"latest"),n==="history"&&e.jsxs(f.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},children:[e.jsx(ae,{history:x}),x.length>0&&e.jsxs("div",{className:"mt-6 space-y-2",children:[e.jsx("h3",{className:"font-semibold text-slate-800 mb-3",children:"All Attempts"}),x.map((d,h)=>e.jsxs("div",{className:"flex items-center justify-between p-3 bg-slate-50 rounded-lg",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"text-sm font-medium text-slate-700",children:["Attempt ",x.length-h]}),e.jsx("p",{className:"text-xs text-slate-500",children:new Date(d.completedAt).toLocaleDateString()})]}),e.jsxs("div",{className:"text-right",children:[e.jsxs("p",{className:"text-sm font-semibold text-sky-600",children:[d.percentage,"%"]}),e.jsx("p",{className:"text-xs text-slate-500",children:d.proficiencyLevel})]})]},h))]})]},"history")]})})]})})},xe=m.lazy(()=>Q(()=>import("./DashboardAvatar-CbAKGmA6.js"),__vite__mapDeps([0,1,2]))),Ce=({userName:s="Student",userLevel:a=1,avatarLayers:r,onContinueLearning:c,showAssessmentTooltip:i,onOpenAssessment:n,studentId:t,assessmentCompleted:l=!1})=>{const[o,x]=m.useState(!1),[j,p]=m.useState(null);m.useEffect(()=>{if(!o||!t)return;const g=M(t,y=>{p(y)});return()=>g()},[o,t]),m.useEffect(()=>{o||p(null)},[o]);const u=()=>{const g=new Date().getHours();return g<12?"Good Morning":g<18?"Good Afternoon":"Good Evening"};return e.jsxs(f.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{duration:.6,ease:[.22,1,.36,1]},className:"relative w-full mt-0 rounded-2xl md:rounded-[2rem] p-5 md:p-6 lg:p-8 bg-gradient-to-br from-white via-sky-50/50 to-white border border-slate-200/80 card-elevated-lg",children:[e.jsxs("div",{className:"absolute inset-0 overflow-hidden rounded-2xl md:rounded-[2rem] pointer-events-none",children:[e.jsx("div",{className:"absolute top-0 left-0 right-0 h-px bg-gradient-to-r from-transparent via-sky-400/50 to-transparent"}),e.jsx("div",{className:"absolute top-0 right-0 w-96 h-96 bg-sky-100/40 rounded-full blur-3xl -translate-y-1/2 translate-x-1/4"}),e.jsx("div",{className:"absolute bottom-0 left-0 w-64 h-64 bg-rose-100/30 rounded-full blur-3xl translate-y-1/2 -translate-x-1/4"}),e.jsx("div",{className:"absolute inset-0 bg-dot-pattern opacity-40"})]}),e.jsx("div",{className:"relative z-10 flex flex-col md:flex-row min-h-[140px] lg:min-h-[160px] items-start md:items-center justify-between gap-4 md:gap-6 pb-0",children:e.jsxs("div",{className:"flex-1 w-full md:w-auto min-w-0 pr-0 md:pr-40 lg:pr-[280px] pb-2 md:pb-0 py-1",children:[e.jsxs("div",{className:"flex flex-wrap md:flex-nowrap items-center gap-2 mb-3 md:mb-2",children:[e.jsx("div",{className:"px-3 md:px-4 py-1.5 rounded-full bg-sky-100 border border-sky-200",children:e.jsxs("span",{className:"text-xs md:text-sm font-body font-bold text-sky-700",children:["Level ",a]})}),e.jsxs("div",{className:"px-3 md:px-4 py-1.5 rounded-full bg-rose-50 border border-rose-200",children:[e.jsx(Y,{size:14,className:"inline -mt-0.5 text-rose-500 mr-1"}),e.jsx("span",{className:"text-xs md:text-sm font-body font-bold text-rose-700",children:"Active"})]})]}),e.jsxs("h1",{className:"text-2xl md:text-2xl lg:text-3xl font-display font-black text-[#0a1628] mb-1.5 tracking-tight leading-[1.1]",children:[u(),", ",s,"!"]}),e.jsx("p",{className:"text-slate-500 mb-2 md:mb-1 text-sm md:text-sm font-body font-bold pr-[155px] md:pr-0",children:"Today is a great day to move one step forward in math mastery."}),e.jsx("p",{className:"text-xs md:text-xs text-slate-400 font-body mb-5 md:mb-4 pr-[150px] md:pr-0",children:"Focus on your next recommended lesson and keep your momentum."}),e.jsxs(f.button,{onClick:c,whileHover:{scale:1.03},whileTap:{scale:.97},className:"mt-2 md:mt-2 bg-gradient-to-r from-purple-600 to-[#9956DE] text-white px-5 py-3 md:py-2 rounded-xl font-body font-bold text-base md:text-sm shadow-lg shadow-purple-500/20 hover:shadow-purple-500/30 transition-all flex justify-center md:justify-start items-center gap-2 group w-auto md:w-auto",children:["Continue Learning",e.jsx(F,{size:14,className:"group-hover:translate-x-1 transition-transform"})]})]})}),i&&e.jsx(f.div,{initial:{opacity:0,scale:.9,x:10},animate:{opacity:1,scale:1,x:0},transition:{delay:.5,type:"spring"},onClick:n,className:"absolute hidden md:block right-[150px] lg:right-[250px] bottom-16 lg:bottom-20 z-30 cursor-pointer drop-shadow-lg group",children:e.jsxs("div",{className:"bg-white px-4 py-3 rounded-2xl rounded-br-sm border-2 border-amber-300 relative transition-all group-hover:bg-amber-50 group-hover:border-amber-400 group-hover:-translate-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-amber-500",children:e.jsx(S,{size:16})}),e.jsxs("p",{className:"text-xs lg:text-sm font-bold text-amber-900 leading-tight",children:["Don't forget to take the",e.jsx("br",{}),"Initial Assessment!"]})]}),e.jsx("div",{className:"absolute -right-2 bottom-0 w-4 h-4 bg-white border-2 border-transparent border-r-amber-300 border-b-amber-300 rotate-45 group-hover:bg-amber-50 group-hover:border-r-amber-400 group-hover:border-b-amber-400 transition-colors"})]})}),l&&!i&&e.jsx(f.div,{initial:{opacity:0,scale:.9,x:10},animate:{opacity:1,scale:1,x:0},transition:{delay:.5,type:"spring"},onClick:()=>window.dispatchEvent(new CustomEvent("mathpulse:navigate",{detail:{tab:"Grades"}})),className:"absolute hidden md:block right-[150px] lg:right-[250px] bottom-16 lg:bottom-20 z-30 cursor-pointer drop-shadow-lg group",children:e.jsxs("div",{className:"bg-white px-4 py-3 rounded-2xl rounded-br-sm border-2 border-teal-300 relative transition-all group-hover:bg-teal-50 group-hover:border-teal-400 group-hover:-translate-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-6 h-6 bg-teal-100 rounded-full flex items-center justify-center shrink-0",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",className:"text-teal-600",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})})}),e.jsxs("p",{className:"text-xs lg:text-sm font-bold text-teal-900 leading-tight",children:["Assessment Complete!",e.jsx("br",{}),e.jsx("span",{className:"text-[10px] lg:text-[11px] font-normal text-teal-700",children:"View results & history"})]})]}),e.jsx("div",{className:"absolute -right-2 bottom-0 w-4 h-4 bg-white border-2 border-transparent border-r-teal-300 border-b-teal-300 rotate-45 group-hover:bg-teal-50 group-hover:border-r-teal-400 group-hover:border-b-teal-400 transition-colors"})]})}),o&&t&&e.jsx(me,{isOpen:o,onClose:()=>x(!1),studentId:t,heroBannerSummary:j}),e.jsx("div",{className:"absolute right-0 bottom-0 lg:right-10 w-[160px] md:w-[150px] lg:w-[270px] pointer-events-none z-20",style:{clipPath:"inset(-100% -50% 0 -50%)"},children:e.jsx("div",{className:"relative w-full aspect-[4/5] translate-y-[10%] md:translate-y-[21%] lg:translate-y-[19%] drop-shadow-2xl",children:e.jsx(m.Suspense,{fallback:e.jsx("div",{className:"w-full h-full scale-[1.15] md:scale-[1.25] lg:scale-[1.3] origin-bottom"}),children:e.jsx(xe,{layers:r,className:"w-full h-full scale-[1.35] md:scale-[1.25] lg:scale-[1.3] origin-bottom"})})})})]})};export{Ce as default}; +const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/DashboardAvatar-D5djDQQ1.js","assets/vendor-react-B4AQeu28.js","assets/avatarData-ChByUhv2.js"])))=>i.map(i=>d[i]); +import{T as R,g as b,a3 as M,h as _,m as f,a4 as E,A as G,B as S,r as z,Z as Y,a as F,_ as Q}from"./index-Bp7MiGcW.js";import{j as e,r as m}from"./vendor-react-B4AQeu28.js";import{D as W,a as q,S as V}from"./dialog-C3ON9pD8.js";import{R as K,L as X,C as U,X as Z,Y as O,T as I,e as J}from"./vendor-charts-CAmziV1y.js";import{collection as v,query as w,limit as N,orderBy as k,getDocs as A,getDoc as L,doc as C}from"./vendor-firebase-firestore-CNv3xXal.js";import{X as ee}from"./x-k8d6VLEw.js";import{C as H}from"./circle-alert-CHGy8HcB.js";import{C as se}from"./circle-check-DzQphSnP.js";import{S as te}from"./sparkles-fLB3ltj1.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-radix-C5nwdvGr.js";import"./vendor-markdown-yqZQ_iQm.js";const ae=({history:s})=>{if(s.length===0)return e.jsxs("div",{className:"text-center py-12 text-slate-400",children:[e.jsx(R,{className:"w-12 h-12 mx-auto mb-3 opacity-40"}),e.jsx("p",{className:"text-sm",children:"Complete more assessments to see your progress history."})]});const a=s.map(r=>({date:new Date(r.completedAt).toLocaleDateString("en-US",{month:"short",day:"numeric"}),score:r.percentage,level:r.proficiencyLevel}));return e.jsx("div",{className:"w-full",children:e.jsx(K,{width:"100%",height:250,children:e.jsxs(X,{data:a,margin:{top:10,right:20,left:0,bottom:5},children:[e.jsx(U,{strokeDasharray:"3 3",stroke:"#e2e8f0"}),e.jsx(Z,{dataKey:"date",tick:{fontSize:12,fill:"#64748b"}}),e.jsx(O,{domain:[0,100],tick:{fontSize:12,fill:"#64748b"}}),e.jsx(I,{contentStyle:{borderRadius:"12px",border:"1px solid #e2e8f0",boxShadow:"0 4px 12px rgba(0,0,0,0.08)"}}),e.jsx(J,{type:"monotone",dataKey:"score",stroke:"#0ea5e9",strokeWidth:3,dot:{fill:"#0ea5e9",strokeWidth:2,r:5},activeDot:{r:7,fill:"#0284c7"}})]})})})};async function re(s){const a=v(b,"assessmentResults",s,"attempts"),r=w(a,k("completedAt","desc"),N(10));return(await A(r)).docs.map(i=>{const n=i.data();return{attemptId:n.attemptId,score:n.score,totalQuestions:n.totalQuestions,percentage:n.percentage,completedAt:n.completedAt?.toDate?.()?.toISOString()||n.completedAt,proficiencyLevel:n.proficiencyLevel}})}async function le(s){const a=v(b,"assessmentResults",s,"attempts"),r=w(a,k("completedAt","desc"),N(1)),c=await A(r);if(c.empty)return null;const n=c.docs[0].data();return{...n,completedAt:n.completedAt?.toDate?.()?.toISOString()||n.completedAt}}const oe={Beginner:"bg-amber-100 text-amber-700 border-amber-300",Developing:"bg-blue-100 text-blue-700 border-blue-300",Proficient:"bg-emerald-100 text-emerald-700 border-emerald-300",Advanced:"bg-violet-100 text-violet-700 border-violet-300"},ne=({result:s})=>e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"bg-gradient-to-br from-sky-500 to-teal-600 rounded-xl p-6 text-white",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sky-200 text-sm font-medium",children:"Total Score"}),e.jsxs("p",{className:"text-4xl font-bold",children:[s.score,"/",s.totalQuestions]}),e.jsxs("p",{className:"text-sky-200 text-sm mt-1",children:[s.percentage,"% Correct"]})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("p",{className:"text-sky-200 text-sm font-medium",children:"Proficiency"}),e.jsx("span",{className:`inline-block mt-1 px-3 py-1 rounded-full text-sm font-semibold border ${oe[s.proficiencyLevel]}`,children:s.proficiencyLevel})]})]})}),e.jsxs("div",{children:[e.jsxs("h3",{className:"font-semibold text-slate-800 mb-3 flex items-center gap-2",children:[e.jsx(S,{className:"w-4 h-4 text-sky-500"}),"Competency Breakdown"]}),e.jsx("div",{className:"space-y-2",children:s.competencyBreakdown.map((a,r)=>e.jsxs("div",{className:"flex items-center gap-3 p-3 bg-slate-50 rounded-lg",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm font-medium text-slate-700",children:a.topic}),e.jsxs("p",{className:"text-xs text-slate-500",children:[a.correctAnswers,"/",a.totalQuestions," correct"]})]}),e.jsx("div",{className:"w-20 h-2 bg-slate-200 rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full ${a.accuracyPercent>=70?"bg-emerald-500":"bg-red-400"}`,style:{width:`${a.accuracyPercent}%`}})}),e.jsxs("span",{className:"text-sm font-semibold text-slate-600 w-10 text-right",children:[a.accuracyPercent,"%"]})]},r))})]}),s.aiNarrative&&e.jsx("div",{className:"bg-amber-50 border border-amber-200 rounded-xl p-4",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(te,{className:"w-4 h-4 text-amber-500 mt-0.5 flex-shrink-0"}),e.jsx("p",{className:"text-sm text-amber-800 leading-relaxed",children:s.aiNarrative})]})}),e.jsxs("div",{children:[e.jsxs("h3",{className:"font-semibold text-slate-800 mb-3 flex items-center gap-2",children:[e.jsx(z,{className:"w-4 h-4 text-sky-500"}),"Question Breakdown"]}),e.jsx("div",{className:"space-y-3",children:s.answers.map((a,r)=>e.jsxs("div",{className:`p-4 rounded-xl border-2 ${a.isCorrect?"border-emerald-200 bg-emerald-50/30":"border-red-200 bg-red-50/30"}`,children:[e.jsxs("p",{className:"text-sm font-medium text-slate-800 mb-2",children:["Q",r+1,". ",a.questionText]}),e.jsxs("div",{className:"flex items-center gap-4 text-sm",children:[e.jsxs("span",{className:"text-slate-500",children:["Your answer: ",e.jsx("span",{className:a.isCorrect?"text-emerald-600 font-medium":"text-red-500 font-medium",children:a.userAnswer||"—"})]}),!a.isCorrect&&e.jsxs("span",{className:"text-slate-500",children:["Correct: ",e.jsx("span",{className:"text-emerald-600 font-medium",children:a.correctAnswer})]})]}),a.explanation&&e.jsx("p",{className:"text-xs text-slate-500 mt-2 leading-relaxed",children:a.explanation})]},r))})]})]}),ie=({summary:s})=>e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row gap-4 items-start sm:items-center justify-between",children:[e.jsxs("div",{className:"bg-sky-50 border border-sky-100 rounded-2xl p-4 flex items-center gap-4 flex-1",children:[e.jsxs("div",{className:"w-12 h-12 bg-sky-500 rounded-full flex items-center justify-center text-white font-bold text-lg shadow-sm",children:[s.latestScorePercent,"%"]}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium text-slate-500",children:"Latest Score"}),e.jsx("p",{className:"text-slate-800 font-bold",children:s.headline})]})]}),s.latestRiskLevel&&e.jsxs("div",{className:`px-4 py-2 rounded-full text-sm font-semibold flex items-center gap-2 + ${s.latestRiskLevel==="At Risk"?"bg-red-100 text-red-700":s.latestRiskLevel==="Needs Attention"?"bg-amber-100 text-amber-700":"bg-emerald-100 text-emerald-700"}`,children:[s.latestRiskLevel==="At Risk"?e.jsx(V,{className:"w-4 h-4"}):s.latestRiskLevel==="Needs Attention"?e.jsx(H,{className:"w-4 h-4"}):e.jsx(se,{className:"w-4 h-4"}),s.latestRiskLevel]})]}),e.jsx("div",{className:"bg-slate-50 p-5 rounded-2xl border border-slate-100",children:e.jsx("p",{className:"text-slate-700 leading-relaxed",children:s.summary})}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[s.strengths?.length>0&&e.jsxs("div",{className:"border border-emerald-100 bg-emerald-50/30 rounded-xl p-4",children:[e.jsxs("h4",{className:"font-semibold text-emerald-800 mb-3 flex items-center gap-2",children:[e.jsx(R,{className:"w-4 h-4"}),"Strengths"]}),e.jsx("ul",{className:"space-y-2",children:s.strengths.map((a,r)=>e.jsxs("li",{className:"text-sm text-emerald-700 flex items-start gap-2",children:[e.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-emerald-400 mt-1.5 flex-shrink-0"}),e.jsx("span",{children:a})]},r))})]}),s.weaknesses?.length>0&&e.jsxs("div",{className:"border border-amber-100 bg-amber-50/30 rounded-xl p-4",children:[e.jsxs("h4",{className:"font-semibold text-amber-800 mb-3 flex items-center gap-2",children:[e.jsx(z,{className:"w-4 h-4"}),"Focus Areas"]}),e.jsx("ul",{className:"space-y-2",children:s.weaknesses.map((a,r)=>e.jsxs("li",{className:"text-sm text-amber-700 flex items-start gap-2",children:[e.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-amber-400 mt-1.5 flex-shrink-0"}),e.jsx("span",{children:a})]},r))})]})]}),s.recommendation&&e.jsxs("div",{className:"bg-gradient-to-br from-indigo-50 to-purple-50 rounded-xl p-5 border border-indigo-100",children:[e.jsxs("h4",{className:"font-semibold text-indigo-900 mb-2 flex items-center gap-2",children:[e.jsx(S,{className:"w-4 h-4 text-indigo-500"}),"Recommended Next Step"]}),e.jsx("p",{className:"text-sm text-indigo-800 leading-relaxed",children:s.recommendation})]})]}),de=({heroBannerSummary:s,latestResult:a,loading:r})=>r?e.jsxs("div",{className:"animate-pulse space-y-4",children:[e.jsx("div",{className:"h-32 bg-slate-200 rounded-xl"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"h-4 bg-slate-200 rounded w-3/4"}),e.jsx("div",{className:"h-4 bg-slate-200 rounded w-1/2"}),e.jsx("div",{className:"h-4 bg-slate-200 rounded w-5/6"})]})]}):!s&&!a?e.jsxs("div",{className:"text-center py-8",children:[e.jsx("div",{className:"w-16 h-16 bg-sky-100 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx(S,{className:"w-8 h-8 text-sky-500"})}),e.jsx("h3",{className:"text-lg font-bold text-slate-800 mb-2",children:"Let's personalize your learning"}),e.jsx("p",{className:"text-sm text-slate-500 max-w-xs mx-auto",children:"Complete your diagnostic assessment so I can understand your strengths, weak areas, and the best next lessons for you."})]}):s?.status==="ready"?e.jsx(ie,{summary:s}):a?e.jsx(ne,{result:a}):e.jsxs("div",{className:"text-center py-8",children:[e.jsx("div",{className:"w-16 h-16 bg-amber-100 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx(H,{className:"w-8 h-8 text-amber-500"})}),e.jsx("h3",{className:"text-lg font-bold text-slate-800 mb-2",children:"Your learning summary is being prepared"}),e.jsx("p",{className:"text-sm text-slate-500 max-w-xs mx-auto",children:"Please try opening this again in a moment."})]});async function ce(s){const a=await L(C(b,"competencyProfiles",s)).catch(()=>null);if(a?.exists()){const t=a.data(),l=t.primaryStrength?[t.primaryStrength]:[],o=t.primaryWeakness?[t.primaryWeakness]:[];return{status:"ready",headline:t.overallScore>=70?"Good job — keep it up!":"Let's build your foundation",summary:o.length>0?`Focus on strengthening ${o[0]} to improve your overall performance.`:"Keep practicing to maintain and expand your skills.",strengths:l,weaknesses:o,recommendation:t.suggestedModule?`Start with the ${t.suggestedModule} module.`:"Continue with your personalized learning path.",latestAssessmentId:"",latestScorePercent:t.overallScore||0,latestRiskLevel:t.overallScore>=70?"Low":t.overallScore>=50?"Moderate":"High",updatedAt:t.updatedAt?.toDate?.()||new Date}}const r=await A(w(v(b,"assessments",s,"attempts"),k("completedAt","desc"),N(1))).catch(()=>null);if(r&&!r.empty){const t=r.docs[0].data(),l=t.rawScore||t.overallScorePercent||0,o=t.proficiencyProfile;return{status:"ready",headline:l>=70?"Good job — keep it up!":"Let's build your foundation",summary:o?.weaknesses?.length>0?`Focus on strengthening ${o.weaknesses[0]} to improve.`:l>=70?"You have a solid foundation!":"With practice, you'll build confidence.",strengths:o?.strengths||[],weaknesses:o?.weaknesses||[],recommendation:o?.suggestedStartingModule?`Start with ${o.suggestedStartingModule}.`:"Follow your personalized learning path.",latestAssessmentId:t.assessmentId||"",latestScorePercent:l,latestRiskLevel:l>=70?"Low":l>=50?"Moderate":"High",updatedAt:t.completedAt?.toDate?.()||new Date}}const c=await L(C(b,"diagnosticResults",s)).catch(()=>null);if(c?.exists()){const t=c.data(),l=t.overallScorePercent||t.overall_score_percent||0,o=t.riskProfile?.weak_domains||[];return{status:"ready",headline:l>=70?"Good job — keep it up!":"Let's build your foundation",summary:o.length>0?`Areas to focus on: ${o.join(", ")}.`:"Assessment completed. Follow your learning path.",strengths:[],weaknesses:o,recommendation:t.recommended_intervention||"Continue with your personalized learning path.",latestAssessmentId:"",latestScorePercent:l,latestRiskLevel:t.overall_risk||(l>=70?"Low":"Moderate"),updatedAt:t.completedAt?.toDate?.()||new Date}}const i=await A(w(v(b,"users",s,"assessments"),k("completedAt","desc"),N(5))).catch(()=>null);if(i&&!i.empty){const t=i.docs.map(p=>p.data()),l=t[0],o=l.score||l.scorePercent||0,x=t.length,j=Math.round(t.reduce((p,u)=>p+(u.score||u.scorePercent||0),0)/x);return{status:"ready",headline:o>=70?"Good job — keep it up!":"Let's build your foundation",summary:`You've completed ${x} diagnostic assessment${x>1?"s":""}. Your latest score is ${o}% (average: ${j}%).`,strengths:[],weaknesses:l.risk==="At Risk"||l.risk==="High"?[l.subject||"General Mathematics"]:[],recommendation:"Continue with your personalized learning path to strengthen weak areas.",latestAssessmentId:l.testId||"",latestScorePercent:o,latestRiskLevel:l.risk||(o>=70?"Low":o>=50?"Moderate":"High"),updatedAt:l.completedAt?.toDate?.()||new Date}}const n=await L(C(b,"users",s)).catch(()=>null);if(n?.exists()){const t=n.data();if(t.initialAssessmentCompleted||t.hasCompletedInitialAssessment){const l=t.atRiskSubjects||[];return{status:"ready",headline:"Assessment Complete! ✓",summary:l.length>0?`Areas to focus on: ${l.join(", ")}. Follow your personalized learning path to improve.`:"Your diagnostic assessment is complete. Your personalized learning path is ready.",strengths:[],weaknesses:l,recommendation:"Continue with your recommended lessons to strengthen your skills.",latestAssessmentId:"",latestScorePercent:0,latestRiskLevel:l.length>0?"Moderate":"Low",updatedAt:t.assessmentCompletedAt?.toDate?.()||new Date}}}return null}const me=({isOpen:s,onClose:a,studentId:r,latestResult:c,heroBannerSummary:i})=>{const[n,t]=m.useState("latest"),[l,o]=m.useState(c||null),[x,j]=m.useState([]),[p,u]=m.useState(!1),[g,y]=m.useState(null);m.useEffect(()=>{if(s&&r&&!i){const d=M(r,h=>{y(h)});return()=>d()}},[s,r,i]);const $=i||g;m.useEffect(()=>{s&&r&&(u(!0),(async()=>{try{const[h,T]=await Promise.all([c?Promise.resolve(c):le(r),re(r)]);if(o(h),j(T),!i&&!g){const D=await E(r);if(D)y(D);else{const P=await ce(r);P&&y(P)}}}catch(h){console.error("[AssessmentResultsModal] fetch error:",h)}finally{u(!1)}})())},[s,r,c]);const B=[{key:"latest",label:"Last Results",icon:e.jsx(G,{className:"w-4 h-4"})},{key:"history",label:"History & Trends",icon:e.jsx(R,{className:"w-4 h-4"})}];return e.jsx(W,{open:s,onOpenChange:d=>!d&&a(),children:e.jsxs(q,{className:"max-w-2xl max-h-[85vh] overflow-y-auto p-0 bg-white rounded-2xl shadow-2xl border-0",children:[e.jsxs("div",{className:"sticky top-0 z-10 bg-white border-b border-slate-200 rounded-t-2xl px-6 py-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("h2",{className:"text-xl font-bold text-slate-800",children:"Assessment Results"}),e.jsx("button",{onClick:a,className:"p-1.5 rounded-lg hover:bg-slate-100 transition-colors",children:e.jsx(ee,{className:"w-5 h-5 text-slate-400"})})]}),e.jsx("div",{className:"flex gap-1 bg-slate-100 p-1 rounded-lg",children:B.map(d=>e.jsxs("button",{onClick:()=>t(d.key),className:`flex items-center gap-2 px-4 py-2 rounded-md text-sm font-medium transition-all ${n===d.key?"bg-white text-sky-600 shadow-sm":"text-slate-600 hover:text-slate-800"}`,children:[d.icon,d.label]},d.key))})]}),e.jsx("div",{className:"px-6 py-5",children:e.jsxs(_,{mode:"wait",children:[n==="latest"&&e.jsx(f.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},children:e.jsx(de,{heroBannerSummary:$,latestResult:l,loading:p})},"latest"),n==="history"&&e.jsxs(f.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},children:[e.jsx(ae,{history:x}),x.length>0&&e.jsxs("div",{className:"mt-6 space-y-2",children:[e.jsx("h3",{className:"font-semibold text-slate-800 mb-3",children:"All Attempts"}),x.map((d,h)=>e.jsxs("div",{className:"flex items-center justify-between p-3 bg-slate-50 rounded-lg",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"text-sm font-medium text-slate-700",children:["Attempt ",x.length-h]}),e.jsx("p",{className:"text-xs text-slate-500",children:new Date(d.completedAt).toLocaleDateString()})]}),e.jsxs("div",{className:"text-right",children:[e.jsxs("p",{className:"text-sm font-semibold text-sky-600",children:[d.percentage,"%"]}),e.jsx("p",{className:"text-xs text-slate-500",children:d.proficiencyLevel})]})]},h))]})]},"history")]})})]})})},xe=m.lazy(()=>Q(()=>import("./DashboardAvatar-D5djDQQ1.js"),__vite__mapDeps([0,1,2]))),Ce=({userName:s="Student",userLevel:a=1,avatarLayers:r,onContinueLearning:c,showAssessmentTooltip:i,onOpenAssessment:n,studentId:t,assessmentCompleted:l=!1})=>{const[o,x]=m.useState(!1),[j,p]=m.useState(null);m.useEffect(()=>{if(!o||!t)return;const g=M(t,y=>{p(y)});return()=>g()},[o,t]),m.useEffect(()=>{o||p(null)},[o]);const u=()=>{const g=new Date().getHours();return g<12?"Good Morning":g<18?"Good Afternoon":"Good Evening"};return e.jsxs(f.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{duration:.6,ease:[.22,1,.36,1]},className:"relative w-full mt-0 rounded-2xl md:rounded-[2rem] p-5 md:p-6 lg:p-8 bg-gradient-to-br from-white via-sky-50/50 to-white border border-slate-200/80 card-elevated-lg",children:[e.jsxs("div",{className:"absolute inset-0 overflow-hidden rounded-2xl md:rounded-[2rem] pointer-events-none",children:[e.jsx("div",{className:"absolute top-0 left-0 right-0 h-px bg-gradient-to-r from-transparent via-sky-400/50 to-transparent"}),e.jsx("div",{className:"absolute top-0 right-0 w-96 h-96 bg-sky-100/40 rounded-full blur-3xl -translate-y-1/2 translate-x-1/4"}),e.jsx("div",{className:"absolute bottom-0 left-0 w-64 h-64 bg-rose-100/30 rounded-full blur-3xl translate-y-1/2 -translate-x-1/4"}),e.jsx("div",{className:"absolute inset-0 bg-dot-pattern opacity-40"})]}),e.jsx("div",{className:"relative z-10 flex flex-col md:flex-row min-h-[140px] lg:min-h-[160px] items-start md:items-center justify-between gap-4 md:gap-6 pb-0",children:e.jsxs("div",{className:"flex-1 w-full md:w-auto min-w-0 pr-0 md:pr-40 lg:pr-[280px] pb-2 md:pb-0 py-1",children:[e.jsxs("div",{className:"flex flex-wrap md:flex-nowrap items-center gap-2 mb-3 md:mb-2",children:[e.jsx("div",{className:"px-3 md:px-4 py-1.5 rounded-full bg-sky-100 border border-sky-200",children:e.jsxs("span",{className:"text-xs md:text-sm font-body font-bold text-sky-700",children:["Level ",a]})}),e.jsxs("div",{className:"px-3 md:px-4 py-1.5 rounded-full bg-rose-50 border border-rose-200",children:[e.jsx(Y,{size:14,className:"inline -mt-0.5 text-rose-500 mr-1"}),e.jsx("span",{className:"text-xs md:text-sm font-body font-bold text-rose-700",children:"Active"})]})]}),e.jsxs("h1",{className:"text-2xl md:text-2xl lg:text-3xl font-display font-black text-[#0a1628] mb-1.5 tracking-tight leading-[1.1]",children:[u(),", ",s,"!"]}),e.jsx("p",{className:"text-slate-500 mb-2 md:mb-1 text-sm md:text-sm font-body font-bold pr-[155px] md:pr-0",children:"Today is a great day to move one step forward in math mastery."}),e.jsx("p",{className:"text-xs md:text-xs text-slate-400 font-body mb-5 md:mb-4 pr-[150px] md:pr-0",children:"Focus on your next recommended lesson and keep your momentum."}),e.jsxs(f.button,{onClick:c,whileHover:{scale:1.03},whileTap:{scale:.97},className:"mt-2 md:mt-2 bg-gradient-to-r from-purple-600 to-[#9956DE] text-white px-5 py-3 md:py-2 rounded-xl font-body font-bold text-base md:text-sm shadow-lg shadow-purple-500/20 hover:shadow-purple-500/30 transition-all flex justify-center md:justify-start items-center gap-2 group w-auto md:w-auto",children:["Continue Learning",e.jsx(F,{size:14,className:"group-hover:translate-x-1 transition-transform"})]})]})}),i&&e.jsx(f.div,{initial:{opacity:0,scale:.9,x:10},animate:{opacity:1,scale:1,x:0},transition:{delay:.5,type:"spring"},onClick:n,className:"absolute hidden md:block right-[150px] lg:right-[250px] bottom-16 lg:bottom-20 z-30 cursor-pointer drop-shadow-lg group",children:e.jsxs("div",{className:"bg-white px-4 py-3 rounded-2xl rounded-br-sm border-2 border-amber-300 relative transition-all group-hover:bg-amber-50 group-hover:border-amber-400 group-hover:-translate-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-amber-500",children:e.jsx(S,{size:16})}),e.jsxs("p",{className:"text-xs lg:text-sm font-bold text-amber-900 leading-tight",children:["Don't forget to take the",e.jsx("br",{}),"Initial Assessment!"]})]}),e.jsx("div",{className:"absolute -right-2 bottom-0 w-4 h-4 bg-white border-2 border-transparent border-r-amber-300 border-b-amber-300 rotate-45 group-hover:bg-amber-50 group-hover:border-r-amber-400 group-hover:border-b-amber-400 transition-colors"})]})}),l&&!i&&e.jsx(f.div,{initial:{opacity:0,scale:.9,x:10},animate:{opacity:1,scale:1,x:0},transition:{delay:.5,type:"spring"},onClick:()=>window.dispatchEvent(new CustomEvent("mathpulse:navigate",{detail:{tab:"Grades"}})),className:"absolute hidden md:block right-[150px] lg:right-[250px] bottom-16 lg:bottom-20 z-30 cursor-pointer drop-shadow-lg group",children:e.jsxs("div",{className:"bg-white px-4 py-3 rounded-2xl rounded-br-sm border-2 border-teal-300 relative transition-all group-hover:bg-teal-50 group-hover:border-teal-400 group-hover:-translate-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-6 h-6 bg-teal-100 rounded-full flex items-center justify-center shrink-0",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",className:"text-teal-600",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})})}),e.jsxs("p",{className:"text-xs lg:text-sm font-bold text-teal-900 leading-tight",children:["Assessment Complete!",e.jsx("br",{}),e.jsx("span",{className:"text-[10px] lg:text-[11px] font-normal text-teal-700",children:"View results & history"})]})]}),e.jsx("div",{className:"absolute -right-2 bottom-0 w-4 h-4 bg-white border-2 border-transparent border-r-teal-300 border-b-teal-300 rotate-45 group-hover:bg-teal-50 group-hover:border-r-teal-400 group-hover:border-b-teal-400 transition-colors"})]})}),o&&t&&e.jsx(me,{isOpen:o,onClose:()=>x(!1),studentId:t,heroBannerSummary:j}),e.jsx("div",{className:"absolute right-0 bottom-0 lg:right-10 w-[160px] md:w-[150px] lg:w-[270px] pointer-events-none z-20",style:{clipPath:"inset(-100% -50% 0 -50%)"},children:e.jsx("div",{className:"relative w-full aspect-[4/5] translate-y-[10%] md:translate-y-[21%] lg:translate-y-[19%] drop-shadow-2xl",children:e.jsx(m.Suspense,{fallback:e.jsx("div",{className:"w-full h-full scale-[1.15] md:scale-[1.25] lg:scale-[1.3] origin-bottom"}),children:e.jsx(xe,{layers:r,className:"w-full h-full scale-[1.35] md:scale-[1.25] lg:scale-[1.3] origin-bottom"})})})})]})};export{Ce as default}; diff --git a/assets/InitialAssessmentModal-DcJcuab5.js b/assets/InitialAssessmentModal-CnFHhYba.js similarity index 94% rename from assets/InitialAssessmentModal-DcJcuab5.js rename to assets/InitialAssessmentModal-CnFHhYba.js index c6940de4b81efcfd4019cb83c26083d0c2ec8820..0a874be7dc520672e3d9f63b77356a6ca6c951c9 100644 --- a/assets/InitialAssessmentModal-DcJcuab5.js +++ b/assets/InitialAssessmentModal-CnFHhYba.js @@ -1 +1 @@ -import{r as l,j as e}from"./vendor-react-B4AQeu28.js";import{B as j}from"./button-DsnZWCoA.js";import{g as y}from"./diagnosticService-B5t8MYB4.js";import{updateDoc as N,doc as v,serverTimestamp as w}from"./vendor-firebase-firestore-CNv3xXal.js";import{m as o,B as k,y as C,q as L,g as z}from"./index-BufUS6SI.js";import{X as S}from"./x-BuBjuj2Y.js";import{C as A}from"./circle-check-big-CDg2qLfH.js";import"./vendor-radix-C5nwdvGr.js";import"./vendor-charts-CAmziV1y.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";const H=({isOpen:n,onClose:d,onDismiss:m,userId:c,strand:x,gradeLevel:p,onAssessmentStart:u,onAssessmentComplete:I})=>{const[t,a]=l.useState(!1),[r,i]=l.useState(null),h=async()=>{a(!0),i(null);try{const s=await y(x,p);sessionStorage.setItem("mathpulse_diagnostic",JSON.stringify({testId:s.test_id,questions:s.questions,totalItems:s.total_items,estimatedMinutes:s.estimated_minutes})),u(s.test_id,s.questions)}catch(s){const b=s instanceof Error?s.message:"Failed to load assessment";i(b),a(!1)}},f=()=>{sessionStorage.setItem("mathpulse_iar_session_dismissed","true"),d()},g=async()=>{try{await N(v(z,"users",c),{assessmentDismissed:!0,assessmentDismissedAt:w()})}catch(s){console.error("[diagnostic] Failed to save dismiss state:",s)}m()};return n?e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/50 backdrop-blur-sm",onClick:s=>s.stopPropagation(),children:e.jsxs(o.div,{initial:{opacity:0,scale:.9},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.9},transition:{type:"spring",damping:25,stiffness:200},className:"bg-white rounded-2xl shadow-2xl max-w-[44rem] w-full flex flex-col overflow-hidden pointer-events-auto",onClick:s=>s.stopPropagation(),style:{willChange:"transform, opacity"},children:[e.jsxs("div",{className:"px-5 py-3 border-b border-[#dde3eb] flex items-center justify-between bg-[#edf1f7] flex-shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 bg-purple-100 rounded-lg flex items-center justify-center text-purple-600",children:e.jsx(k,{size:18})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-bold text-[#0a1628] leading-tight",children:"Initial Assessment"}),e.jsx("p",{className:"text-[11px] text-[#5a6578]",children:"Analyze your strengths & weaknesses"})]})]}),e.jsx("button",{onClick:f,"aria-label":"Close assessment modal",className:"ml-auto w-8 h-8 rounded-lg flex items-center justify-center text-[#5a6578] hover:bg-[#dde3eb] hover:text-[#0a1628] transition-colors",children:e.jsx(S,{size:18})})]}),e.jsx("div",{className:"p-5 text-center space-y-3",children:e.jsxs(o.div,{initial:{opacity:0,x:20},animate:{opacity:1,x:0},transition:{duration:.3,ease:"easeOut"},children:[e.jsx("div",{className:"w-20 h-20 bg-purple-50 rounded-full flex items-center justify-center mx-auto mb-3",children:e.jsx("svg",{className:"w-9 h-9 text-purple-600",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9.813 15.904L9 18.75l-.813-2.846a4.5 4.5 0 00-3.09-3.09L2.25 12l2.846-.813a4.5 4.5 0 003.09-3.09L9 5.25l.813 2.846a4.5 4.5 0 003.09 3.09L15.75 12l-2.846.813a4.5 4.5 0 00-3.09 3.09zM18.259 8.715L18 9.75l-.259-1.035a3.375 3.375 0 00-2.455-2.456L14.25 6l1.036-.259a3.375 3.375 0 002.455-2.456L18 2.25l.259 1.035a3.375 3.375 0 002.455 2.456L21.75 6l-1.036.259a3.375 3.375 0 00-2.455 2.456zM16.894 20.567L16.5 21.75l-.394-1.183a2.25 2.25 0 00-1.423-1.423L13.5 18.75l1.183-.394a2.25 2.25 0 001.423-1.423l.394-1.183.394 1.183a2.25 2.25 0 001.423 1.423l1.183.394-1.183.394a2.25 2.25 0 00-1.423 1.423z"})})}),e.jsx("h3",{className:"text-lg font-bold text-[#0a1628]",children:"Welcome to MathPulse AI!"}),e.jsx("p",{className:"text-[13px] text-[#5a6578] max-w-[24rem] mx-auto leading-relaxed",children:"To personalize your learning path, complete a DepEd competency-based SHS diagnostic (15 items, around 11.6 minutes)."}),e.jsxs("div",{className:"grid grid-cols-2 gap-2.5 max-w-[28rem] mx-auto text-left mt-4",children:[e.jsxs("div",{className:"bg-[#edf1f7] p-2.5 rounded-lg border border-[#dde3eb]",children:[e.jsxs("div",{className:"flex items-center gap-1.5 font-bold text-[13px] text-[#0a1628] mb-1",children:[e.jsx(A,{size:14,className:"text-teal-500"}),"Personalized Path"]}),e.jsx("p",{className:"text-[10px] text-[#5a6578] pl-[18px]",children:"Get recommendations based on your level."})]}),e.jsxs("div",{className:"bg-[#edf1f7] p-2.5 rounded-lg border border-[#dde3eb]",children:[e.jsxs("div",{className:"flex items-center gap-1.5 font-bold text-[13px] text-[#0a1628] mb-1",children:[e.jsx(C,{size:14,className:"text-rose-500"}),"Identify Risks"]}),e.jsx("p",{className:"text-[10px] text-[#5a6578] pl-[18px]",children:"Spot areas that need more attention early."})]})]}),r&&e.jsx("div",{className:"mt-3 p-2.5 bg-red-50 border border-red-200 rounded-lg",children:e.jsx("p",{className:"text-xs text-red-700",children:r})}),e.jsxs("div",{className:"pt-3 space-y-2.5",children:[e.jsx(j,{onClick:h,disabled:t,className:"bg-gradient-to-r from-purple-600 to-purple-500 hover:from-purple-700 hover:to-purple-600 text-white px-5 py-3 rounded-xl text-sm font-bold shadow-lg shadow-purple-200 w-full max-w-[380px] mx-auto",children:t?e.jsxs(e.Fragment,{children:[e.jsx(L,{size:16,className:"animate-spin mr-2"}),"Crafting your assessment..."]}):"Start Assessment"}),t&&e.jsx("p",{className:"text-[10px] text-slate-400 max-w-[24rem] mx-auto text-center leading-relaxed",children:"This may take up to 90 seconds while AI generates your personalized test."}),!t&&e.jsx("button",{onClick:g,disabled:t,className:"block mx-auto text-xs text-slate-500 hover:text-[#5a6578] transition-colors font-medium disabled:opacity-40",children:"Skip for now"})]})]})})]})}):null};export{H as default}; +import{r as l,j as e}from"./vendor-react-B4AQeu28.js";import{B as j}from"./button-BMVm9YQO.js";import{g as y}from"./diagnosticService-E5zPXoFs.js";import{updateDoc as N,doc as v,serverTimestamp as w}from"./vendor-firebase-firestore-CNv3xXal.js";import{m as o,B as k,y as C,q as L,g as z}from"./index-Bp7MiGcW.js";import{X as S}from"./x-k8d6VLEw.js";import{C as A}from"./circle-check-big-JdaMs3bP.js";import"./vendor-radix-C5nwdvGr.js";import"./vendor-charts-CAmziV1y.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";const H=({isOpen:n,onClose:d,onDismiss:m,userId:c,strand:x,gradeLevel:p,onAssessmentStart:u,onAssessmentComplete:I})=>{const[t,a]=l.useState(!1),[r,i]=l.useState(null),h=async()=>{a(!0),i(null);try{const s=await y(x,p);sessionStorage.setItem("mathpulse_diagnostic",JSON.stringify({testId:s.test_id,questions:s.questions,totalItems:s.total_items,estimatedMinutes:s.estimated_minutes})),u(s.test_id,s.questions)}catch(s){const b=s instanceof Error?s.message:"Failed to load assessment";i(b),a(!1)}},f=()=>{sessionStorage.setItem("mathpulse_iar_session_dismissed","true"),d()},g=async()=>{try{await N(v(z,"users",c),{assessmentDismissed:!0,assessmentDismissedAt:w()})}catch(s){console.error("[diagnostic] Failed to save dismiss state:",s)}m()};return n?e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/50 backdrop-blur-sm",onClick:s=>s.stopPropagation(),children:e.jsxs(o.div,{initial:{opacity:0,scale:.9},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.9},transition:{type:"spring",damping:25,stiffness:200},className:"bg-white rounded-2xl shadow-2xl max-w-[44rem] w-full flex flex-col overflow-hidden pointer-events-auto",onClick:s=>s.stopPropagation(),style:{willChange:"transform, opacity"},children:[e.jsxs("div",{className:"px-5 py-3 border-b border-[#dde3eb] flex items-center justify-between bg-[#edf1f7] flex-shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 bg-purple-100 rounded-lg flex items-center justify-center text-purple-600",children:e.jsx(k,{size:18})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-bold text-[#0a1628] leading-tight",children:"Initial Assessment"}),e.jsx("p",{className:"text-[11px] text-[#5a6578]",children:"Analyze your strengths & weaknesses"})]})]}),e.jsx("button",{onClick:f,"aria-label":"Close assessment modal",className:"ml-auto w-8 h-8 rounded-lg flex items-center justify-center text-[#5a6578] hover:bg-[#dde3eb] hover:text-[#0a1628] transition-colors",children:e.jsx(S,{size:18})})]}),e.jsx("div",{className:"p-5 text-center space-y-3",children:e.jsxs(o.div,{initial:{opacity:0,x:20},animate:{opacity:1,x:0},transition:{duration:.3,ease:"easeOut"},children:[e.jsx("div",{className:"w-20 h-20 bg-purple-50 rounded-full flex items-center justify-center mx-auto mb-3",children:e.jsx("svg",{className:"w-9 h-9 text-purple-600",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9.813 15.904L9 18.75l-.813-2.846a4.5 4.5 0 00-3.09-3.09L2.25 12l2.846-.813a4.5 4.5 0 003.09-3.09L9 5.25l.813 2.846a4.5 4.5 0 003.09 3.09L15.75 12l-2.846.813a4.5 4.5 0 00-3.09 3.09zM18.259 8.715L18 9.75l-.259-1.035a3.375 3.375 0 00-2.455-2.456L14.25 6l1.036-.259a3.375 3.375 0 002.455-2.456L18 2.25l.259 1.035a3.375 3.375 0 002.455 2.456L21.75 6l-1.036.259a3.375 3.375 0 00-2.455 2.456zM16.894 20.567L16.5 21.75l-.394-1.183a2.25 2.25 0 00-1.423-1.423L13.5 18.75l1.183-.394a2.25 2.25 0 001.423-1.423l.394-1.183.394 1.183a2.25 2.25 0 001.423 1.423l1.183.394-1.183.394a2.25 2.25 0 00-1.423 1.423z"})})}),e.jsx("h3",{className:"text-lg font-bold text-[#0a1628]",children:"Welcome to MathPulse AI!"}),e.jsx("p",{className:"text-[13px] text-[#5a6578] max-w-[24rem] mx-auto leading-relaxed",children:"To personalize your learning path, complete a DepEd competency-based SHS diagnostic (15 items, around 11.6 minutes)."}),e.jsxs("div",{className:"grid grid-cols-2 gap-2.5 max-w-[28rem] mx-auto text-left mt-4",children:[e.jsxs("div",{className:"bg-[#edf1f7] p-2.5 rounded-lg border border-[#dde3eb]",children:[e.jsxs("div",{className:"flex items-center gap-1.5 font-bold text-[13px] text-[#0a1628] mb-1",children:[e.jsx(A,{size:14,className:"text-teal-500"}),"Personalized Path"]}),e.jsx("p",{className:"text-[10px] text-[#5a6578] pl-[18px]",children:"Get recommendations based on your level."})]}),e.jsxs("div",{className:"bg-[#edf1f7] p-2.5 rounded-lg border border-[#dde3eb]",children:[e.jsxs("div",{className:"flex items-center gap-1.5 font-bold text-[13px] text-[#0a1628] mb-1",children:[e.jsx(C,{size:14,className:"text-rose-500"}),"Identify Risks"]}),e.jsx("p",{className:"text-[10px] text-[#5a6578] pl-[18px]",children:"Spot areas that need more attention early."})]})]}),r&&e.jsx("div",{className:"mt-3 p-2.5 bg-red-50 border border-red-200 rounded-lg",children:e.jsx("p",{className:"text-xs text-red-700",children:r})}),e.jsxs("div",{className:"pt-3 space-y-2.5",children:[e.jsx(j,{onClick:h,disabled:t,className:"bg-gradient-to-r from-purple-600 to-purple-500 hover:from-purple-700 hover:to-purple-600 text-white px-5 py-3 rounded-xl text-sm font-bold shadow-lg shadow-purple-200 w-full max-w-[380px] mx-auto",children:t?e.jsxs(e.Fragment,{children:[e.jsx(L,{size:16,className:"animate-spin mr-2"}),"Crafting your assessment..."]}):"Start Assessment"}),t&&e.jsx("p",{className:"text-[10px] text-slate-400 max-w-[24rem] mx-auto text-center leading-relaxed",children:"This may take up to 90 seconds while AI generates your personalized test."}),!t&&e.jsx("button",{onClick:g,disabled:t,className:"block mx-auto text-xs text-slate-500 hover:text-[#5a6578] transition-colors font-medium disabled:opacity-40",children:"Skip for now"})]})]})})]})}):null};export{H as default}; diff --git a/assets/LeaderboardPage-FEtdr_oR.js b/assets/LeaderboardPage-Cl1rvXzo.js similarity index 99% rename from assets/LeaderboardPage-FEtdr_oR.js rename to assets/LeaderboardPage-Cl1rvXzo.js index cccf1ccd53e91dc7f49f18fb0da442e48a7b9e70..86547501f3c62acf1c57e3d9c258a238315f9120 100644 --- a/assets/LeaderboardPage-FEtdr_oR.js +++ b/assets/LeaderboardPage-Cl1rvXzo.js @@ -1,4 +1,4 @@ -import{r as l,j as e}from"./vendor-react-B4AQeu28.js";import{e as O,aK as W,h as q,m as n,b as y,r as P,A as k,F as m,T as E,q as _,a6 as T,a7 as H,$ as U,u as $,aL as K,R as G,L as Q,D as X}from"./index-BufUS6SI.js";import{X as V}from"./x-BuBjuj2Y.js";import{C as Z}from"./clock-CooTZK0X.js";import{u as J}from"./useFeatureAccess-D82RK3T0.js";import"./vendor-firebase-firestore-CNv3xXal.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-radix-C5nwdvGr.js";import"./vendor-charts-CAmziV1y.js";import"./vendor-markdown-yqZQ_iQm.js";/** +import{r as l,j as e}from"./vendor-react-B4AQeu28.js";import{e as O,aK as W,h as q,m as n,b as y,r as P,A as k,F as m,T as E,q as _,a6 as T,a7 as H,$ as U,u as $,aL as K,R as G,L as Q,D as X}from"./index-Bp7MiGcW.js";import{X as V}from"./x-k8d6VLEw.js";import{C as Z}from"./clock-Cc6sJz1J.js";import{u as J}from"./useFeatureAccess-O2Vj4dYD.js";import"./vendor-firebase-firestore-CNv3xXal.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-radix-C5nwdvGr.js";import"./vendor-charts-CAmziV1y.js";import"./vendor-markdown-yqZQ_iQm.js";/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. diff --git a/assets/LearningPath-Dtvj49AG.js b/assets/LearningPath-8IT3WoMT.js similarity index 89% rename from assets/LearningPath-Dtvj49AG.js rename to assets/LearningPath-8IT3WoMT.js index ff36f7afcbaa03796a1646aff7865ec2264d741e..f4f0d900b2dee7286a1f5cda24890228716441b1 100644 --- a/assets/LearningPath-Dtvj49AG.js +++ b/assets/LearningPath-8IT3WoMT.js @@ -1 +1 @@ -import{r as p,d as g,j as r}from"./vendor-react-B4AQeu28.js";import{u as b,ab as j,ac as N,z as k,b as P,a as I}from"./index-BufUS6SI.js";import{M as v}from"./ModuleFolderCard-CqhxwGI0.js";import"./vendor-firebase-firestore-CNv3xXal.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-radix-C5nwdvGr.js";import"./vendor-charts-CAmziV1y.js";import"./vendor-markdown-yqZQ_iQm.js";import"./useSubjectAvailability-BXzXJ4_J.js";import"./deepseekRagService-Bke9fSTt.js";import"./clock-CooTZK0X.js";import"./bell-D9j1Gy0m.js";import"./info-a-Ci1_jf.js";const Y=({onNavigateToModules:m,atRiskSubjects:l=[],priorityTopics:o=[],modules:i})=>{const{userProfile:d}=b(),[x,h]=p.useState(null),a=g.useMemo(()=>{const e=o.length>0?o:l.map(s=>j(s)).filter(s=>s!==null),t=new Set;return e.filter(s=>t.has(s)?!1:(t.add(s),!0))},[o,l]),u=g.useMemo(()=>{if(a.length===0)return i.slice(0,3);const e=new Map(a.map((t,s)=>[N[t],s]));return[...i].sort((t,s)=>{const n=e.get(t.id)??Number.POSITIVE_INFINITY,w=e.get(s.id)??Number.POSITIVE_INFINITY;return n-w}).slice(0,3)},[i,a]);p.useEffect(()=>{d?.uid&&k(d.uid).then(h).catch(console.error)},[d?.uid]);const c=u.slice(0,3).map(e=>{const t=x?.subjects?.[e.subject]?.modulesProgress?.[e.id],s=e.lessons.length,n=t?.progress??(s>0?Math.round((t?.lessonsCompleted?.length||0)/s*100):0);return{...e,progress:n,status:n===100?"Completed":n>0?"In Progress":"Not Started"}}),f=c.some(e=>e.progress>0)?"Continue Learning":"Start Learning";return r.jsxs("div",{children:[r.jsxs("div",{className:"flex justify-between items-center mb-4 md:mb-6 px-1",children:[r.jsxs("div",{className:"flex items-center gap-2 md:gap-3",children:[r.jsx("div",{className:"w-8 h-8 md:w-10 md:h-10 shrink-0 rounded-xl md:rounded-[14px] bg-indigo-50 border border-indigo-100 flex items-center justify-center text-indigo-500 shadow-inner",children:r.jsx(P,{className:"w-4 h-4 md:w-5 md:h-5",strokeWidth:2.5})}),r.jsx("h2",{className:"font-display font-black text-lg md:text-[24px] text-slate-800 tracking-tight whitespace-nowrap",children:f})]}),r.jsxs("button",{onClick:()=>m?.(),className:"text-primary font-bold text-xs md:text-sm flex shrink-0 items-center gap-1 hover:gap-2 transition-all bg-primary/10 px-3 py-1.5 md:px-4 md:py-2 rounded-lg md:rounded-xl hover:bg-primary/20 whitespace-nowrap",children:["View All ",r.jsx(I,{className:"w-3.5 h-3.5 md:w-4 md:h-4"})]})]}),r.jsx("div",{className:"flex overflow-x-auto snap-x snap-mandatory scrollbar-hide -mx-4 px-4 pb-4 gap-4 md:grid md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-3 md:gap-6 md:pb-0 md:mx-0 md:px-0 md:overflow-visible",children:c.map((e,t)=>r.jsx("div",{className:"w-[72vw] max-w-[260px] h-[220px] shrink-0 snap-center md:min-w-0 md:max-w-none md:w-auto md:shrink md:h-auto",children:r.jsx(v,{module:e,index:t,onClick:()=>m?.(e.id),isAtRisk:a.length>0,badgeLabel:e.status!=="Not Started"?e.status:void 0})},e.id))})]})};export{Y as default}; +import{r as p,d as g,j as r}from"./vendor-react-B4AQeu28.js";import{u as b,ab as j,ac as N,z as k,b as P,a as I}from"./index-Bp7MiGcW.js";import{M as v}from"./ModuleFolderCard-BaBw0Pd9.js";import"./vendor-firebase-firestore-CNv3xXal.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-radix-C5nwdvGr.js";import"./vendor-charts-CAmziV1y.js";import"./vendor-markdown-yqZQ_iQm.js";import"./useSubjectAvailability-Dm-85m8R.js";import"./deepseekRagService-Bke9fSTt.js";import"./clock-Cc6sJz1J.js";import"./bell-DyLbgepV.js";import"./info-Bcg_cBHY.js";const Y=({onNavigateToModules:m,atRiskSubjects:l=[],priorityTopics:o=[],modules:i})=>{const{userProfile:d}=b(),[x,h]=p.useState(null),a=g.useMemo(()=>{const e=o.length>0?o:l.map(s=>j(s)).filter(s=>s!==null),t=new Set;return e.filter(s=>t.has(s)?!1:(t.add(s),!0))},[o,l]),u=g.useMemo(()=>{if(a.length===0)return i.slice(0,3);const e=new Map(a.map((t,s)=>[N[t],s]));return[...i].sort((t,s)=>{const n=e.get(t.id)??Number.POSITIVE_INFINITY,w=e.get(s.id)??Number.POSITIVE_INFINITY;return n-w}).slice(0,3)},[i,a]);p.useEffect(()=>{d?.uid&&k(d.uid).then(h).catch(console.error)},[d?.uid]);const c=u.slice(0,3).map(e=>{const t=x?.subjects?.[e.subject]?.modulesProgress?.[e.id],s=e.lessons.length,n=t?.progress??(s>0?Math.round((t?.lessonsCompleted?.length||0)/s*100):0);return{...e,progress:n,status:n===100?"Completed":n>0?"In Progress":"Not Started"}}),f=c.some(e=>e.progress>0)?"Continue Learning":"Start Learning";return r.jsxs("div",{children:[r.jsxs("div",{className:"flex justify-between items-center mb-4 md:mb-6 px-1",children:[r.jsxs("div",{className:"flex items-center gap-2 md:gap-3",children:[r.jsx("div",{className:"w-8 h-8 md:w-10 md:h-10 shrink-0 rounded-xl md:rounded-[14px] bg-indigo-50 border border-indigo-100 flex items-center justify-center text-indigo-500 shadow-inner",children:r.jsx(P,{className:"w-4 h-4 md:w-5 md:h-5",strokeWidth:2.5})}),r.jsx("h2",{className:"font-display font-black text-lg md:text-[24px] text-slate-800 tracking-tight whitespace-nowrap",children:f})]}),r.jsxs("button",{onClick:()=>m?.(),className:"text-primary font-bold text-xs md:text-sm flex shrink-0 items-center gap-1 hover:gap-2 transition-all bg-primary/10 px-3 py-1.5 md:px-4 md:py-2 rounded-lg md:rounded-xl hover:bg-primary/20 whitespace-nowrap",children:["View All ",r.jsx(I,{className:"w-3.5 h-3.5 md:w-4 md:h-4"})]})]}),r.jsx("div",{className:"flex overflow-x-auto snap-x snap-mandatory scrollbar-hide -mx-4 px-4 pb-4 gap-4 md:grid md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-3 md:gap-6 md:pb-0 md:mx-0 md:px-0 md:overflow-visible",children:c.map((e,t)=>r.jsx("div",{className:"w-[72vw] max-w-[260px] h-[220px] shrink-0 snap-center md:min-w-0 md:max-w-none md:w-auto md:shrink md:h-auto",children:r.jsx(v,{module:e,index:t,onClick:()=>m?.(e.id),isAtRisk:a.length>0,badgeLabel:e.status!=="Not Started"?e.status:void 0})},e.id))})]})};export{Y as default}; diff --git a/assets/LoginPage-DpTH-gW8.js b/assets/LoginPage-LAyBJ2QS.js similarity index 97% rename from assets/LoginPage-DpTH-gW8.js rename to assets/LoginPage-LAyBJ2QS.js index 513f880ede1fc92e6350fda6bad59503a63d8ba2..f34c71743eb5c1b1c3ec9546da1909fb6978d0c4 100644 --- a/assets/LoginPage-DpTH-gW8.js +++ b/assets/LoginPage-LAyBJ2QS.js @@ -1 +1 @@ -import{r as s,j as e}from"./vendor-react-B4AQeu28.js";import{B as je}from"./button-DsnZWCoA.js";import{I as L}from"./input-BPglbGHJ.js";import{m as i,B as we,T as Ne,A as ke,U as Q,L as X,a as K,G as Se,b as Pe,s as ee,c as Ae,d as te}from"./index-BufUS6SI.js";import{S as Me}from"./sparkles-DYlMf97S.js";import{M as Re}from"./mail-d6dXXOFo.js";import{E as Ce,a as Ee}from"./eye-CDIJHn8i.js";import{S as Te}from"./shield-check-DMfBBdB0.js";import"./vendor-radix-C5nwdvGr.js";import"./vendor-charts-CAmziV1y.js";import"./vendor-firebase-firestore-CNv3xXal.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";const se="/assets/shader-bg-DA7bEbBA.mp4",Le=[{id:"length",label:"At least 8 characters",test:a=>a.length>=8},{id:"upper-lower",label:"Contains uppercase and lowercase letters",test:a=>/[A-Z]/.test(a)&&/[a-z]/.test(a)},{id:"number",label:"Contains at least one number",test:a=>/\d/.test(a)},{id:"special",label:"Contains at least one special character",test:a=>/[^A-Za-z0-9]/.test(a)}],I="Use at least 8 characters with uppercase, lowercase, number, and special character.",Ie=a=>{const c=typeof a=="object"&&a!==null?a:null,o=a instanceof Error?a.message:"";if(c?.code&&typeof c.code=="string")return{code:c.code.toLowerCase(),message:o};const n=o.match(/auth\/[a-z-]+/i);return{code:n?n[0].toLowerCase():"",message:o}},ze=a=>a.replace(/^Firebase:\s*/i,"").replace(/\s*\(auth\/[a-z-]+\)\.?/i,"").trim(),ae=(a,c)=>{const{code:o,message:n}=Ie(a),h=ze(n);return o==="auth/invalid-credential"||o==="auth/wrong-password"||o==="auth/user-not-found"?"Invalid email or password. Please check your credentials and try again.":o==="auth/email-already-in-use"?"This email is already registered. Please sign in instead.":o==="auth/weak-password"||o==="auth/password-does-not-meet-requirements"?h?`Password does not meet signup requirements. ${h}`:`Password does not meet signup requirements. ${I}`:o==="auth/too-many-requests"?"Access to this account has been temporarily disabled due to many failed login attempts. You can immediately restore it by resetting your password or you can try again later.":o==="auth/network-request-failed"?"Network error. Please check your internet connection and try again.":o.startsWith("auth/")?h||c:n.includes("Firebase:")||n.includes("auth/")?c:n||c},et=()=>{const a={"Grade 11":["Academic","Tech-Pro"]},[c,o]=s.useState(""),[n,h]=s.useState(""),[S,re]=s.useState(!1),[l,z]=s.useState(!1),[P,ie]=s.useState(""),[y,D]=s.useState("student"),[b,De]=s.useState("Grade 11"),[v,B]=s.useState(a["Grade 11"][0]),[_,x]=s.useState(!1),[f,u]=s.useState(null),[oe,le]=s.useState(!1),[ne,ce]=s.useState(!1),[A,de]=s.useState(16),[q,V]=s.useState("primary"),[O,M]=s.useState(0),R=s.useRef(null),C=s.useRef(null),j=oe&&ne,g=s.useRef("primary"),w=s.useRef(0),N=s.useRef(!1),F=1.1,G=.34,U=t=>{const r=Math.max(0,Math.min(1,t));Math.abs(w.current-r)<.02||(w.current=r,M(r))},$=t=>{!Number.isFinite(t)||t<=0||Math.abs(A-t)>.05&&de(t)},E=s.useMemo(()=>Le.map(t=>({...t,met:t.test(n)})),[n]),W=s.useMemo(()=>E.every(t=>t.met),[E]),me=s.useMemo(()=>{if(!l||!f)return!1;const t=f.toLowerCase();return t.includes("password requirements not met")||t.includes("password does not meet")},[f,l]),ue=()=>{const t=R.current?.duration;t&&Number.isFinite(t)&&t>0&&$(t)},pe=()=>{const t=C.current?.duration;t&&Number.isFinite(t)&&t>0&&$(t)};s.useEffect(()=>{if(!j)return;const t=R.current,r=C.current;if(!t||!r)return;let d=!1,m=0;g.current="primary",V("primary"),N.current=!1,w.current=0,M(0),t.loop=!1,r.loop=!1,t.currentTime=0,r.currentTime=0,r.pause(),t.play().catch(()=>{});const k=()=>{if(d)return;const p=g.current==="primary"?t:r,Z=g.current==="primary"?r:t,ge=Number.isFinite(p.duration)&&p.duration>0?p.duration:A,T=Math.max(ge-p.currentTime,0);if(T<=F){N.current||(N.current=!0,Z.currentTime=0,Z.play().catch(()=>{}));const ve=1-T/F;if(U(ve),T<=.03||p.ended){p.pause(),p.currentTime=0;const J=g.current==="primary"?"secondary":"primary";g.current=J,V(J),N.current=!1,w.current=0,M(0)}}else U(0);m=window.requestAnimationFrame(k)};return m=window.requestAnimationFrame(k),()=>{d=!0,m&&window.cancelAnimationFrame(m)}},[A,j]);const Y=j?G*(1-O):0,H=j?G*O:0,xe=q==="primary"?Y:H,ye=q==="secondary"?Y:H;s.useEffect(()=>{const t=a[b]||[];t.length>0&&!t.includes(v)&&B(t[0])},[b,v]);const he=[{label:"Student",role:"student",email:"teststudent@school.edu",password:"TestPass123!",icon:Se,color:"sky"},{label:"Teacher",role:"teacher",email:"testteacher@school.edu",password:"TestPass123!",icon:Pe,color:"emerald"},{label:"Admin",role:"admin",email:"testadmin@school.edu",password:"TestPass123!",icon:Te,color:"rose"}],be=async(t,r,d)=>{u(null),x(!0),o(t),h(r),D(d),z(!1);try{ee(d),await te(t,r)}catch(m){u(ae(m,"Demo sign-in failed. Please try again.")),x(!1)}},fe=async t=>{t.preventDefault(),u(null),x(!0);try{if(l){if(!P.trim()){u("Please enter your name"),x(!1);return}if(y==="student"&&!b){u("Please select a grade level"),x(!1);return}if(y==="admin"){u("Admin account creation is restricted. Please contact an existing administrator."),x(!1);return}if(!W){u(`Password does not meet signup requirements. ${I}`),x(!1);return}ee(y),await Ae(c,n,P,y,y==="student"?{grade:b,section:v}:{department:"Mathematics"})}else await te(c,n)}catch(r){const d=l?`Sign-up failed. ${I}`:"Sign-in failed. Please check your credentials and try again.";u(ae(r,d)),x(!1)}};return e.jsxs("div",{className:"min-h-screen w-full flex items-center justify-center px-4 sm:px-6 py-8 overflow-y-auto relative login-bg",children:[e.jsx("video",{ref:R,autoPlay:!0,muted:!0,playsInline:!0,preload:"auto",onCanPlay:()=>le(!0),onLoadedMetadata:ue,className:"absolute inset-0 w-full h-full object-cover transition-opacity duration-150 e-opacity",style:{"--o":xe},src:se}),e.jsx("video",{ref:C,autoPlay:!0,muted:!0,playsInline:!0,preload:"auto",onCanPlay:()=>ce(!0),onLoadedMetadata:pe,className:"absolute inset-0 w-full h-full object-cover transition-opacity duration-150 e-opacity",style:{"--o":ye},src:se}),e.jsx("div",{className:"absolute inset-0 pointer-events-none login-frost-overlay"}),e.jsx("div",{className:"absolute top-[10%] left-[-10%] w-[60%] h-[60%] rounded-full blur-[140px] pointer-events-none mix-blend-multiply login-orb-purple"}),e.jsx("div",{className:"absolute bottom-[-10%] right-[-10%] w-[70%] h-[70%] rounded-full blur-[160px] pointer-events-none mix-blend-multiply login-orb-pink"}),e.jsx("div",{className:"absolute top-[40%] left-[40%] w-[40%] h-[40%] rounded-full blur-[120px] pointer-events-none mix-blend-screen login-orb-blue"}),e.jsx("div",{className:"relative z-10 w-full max-w-6xl mx-auto",children:e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-8 lg:gap-12 items-center",children:[e.jsxs(i.div,{initial:{opacity:0,x:-40},animate:{opacity:1,x:0},transition:{duration:.8,ease:[.22,1,.36,1]},className:"flex flex-col items-center lg:items-start justify-center space-y-5 lg:space-y-8 text-center lg:text-left",children:[e.jsxs(i.div,{className:"flex items-center justify-center lg:justify-start gap-2.5",children:[e.jsx(i.div,{className:"relative flex items-center justify-center drop-shadow-md",children:e.jsx("img",{src:"/mathpulse_final_logo.png",alt:"MathPulse AI Logo",className:"w-10 h-10 lg:w-16 lg:h-16 object-contain flex-shrink-0"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl lg:text-3xl font-display font-black tracking-tight text-slate-900 bg-clip-text text-transparent bg-gradient-to-r from-purple-600 via-pink-600 to-sky-500",children:"MathPulse"}),e.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5",children:[e.jsx(Me,{size:12,className:"text-rose-500"}),e.jsx("span",{className:"text-xs text-slate-500 font-body font-medium tracking-wide",children:"Powered by Machine Learning"})]})]})]}),e.jsxs(i.div,{className:"space-y-3 lg:space-y-5",initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.2,duration:.8},children:[e.jsxs("h2",{className:"text-3xl sm:text-4xl lg:text-5xl xl:text-[3.4rem] font-display font-extrabold leading-[1.1] tracking-tight text-slate-900",children:["Transform Your",e.jsx("br",{}),e.jsx("span",{className:"bg-gradient-to-r from-sky-600 via-cyan-500 to-sky-500 bg-clip-text text-transparent",children:"Math Journey"})]}),e.jsx("p",{className:"text-sm lg:text-base text-slate-500 leading-relaxed max-w-md mx-auto lg:mx-0 font-body",children:"AI-powered predictive system designed to identify at-risk students and provide personalized learning recommendations."})]}),e.jsx("div",{className:"grid grid-cols-3 gap-2 lg:gap-3",children:[{icon:we,label:"AI Predictions",desc:"Smart detection",color:"sky"},{icon:Ne,label:"Analytics",desc:"Real-time data",color:"rose"},{icon:ke,label:"Gamified",desc:"Learn & earn",color:"emerald"}].map((t,r)=>{const d=t.icon,m={sky:"border-sky-200/60 hover:border-sky-300",rose:"border-rose-200/60 hover:border-rose-300",emerald:"border-emerald-200/60 hover:border-emerald-300"},k={sky:"text-sky-600",rose:"text-rose-500",emerald:"text-emerald-600"},p={sky:"bg-sky-100",rose:"bg-rose-100",emerald:"bg-emerald-100"};return e.jsxs(i.div,{className:`bg-white/80 backdrop-blur-xl border ${m[t.color]} rounded-xl p-3 lg:p-4 transition-all cursor-pointer group shadow-md shadow-slate-900/[0.04]`,initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.5+r*.1},whileHover:{scale:1.03,y:-4},children:[e.jsx("div",{className:`w-7 h-7 lg:w-9 lg:h-9 rounded-lg ${p[t.color]} flex items-center justify-center mx-auto lg:mx-0 mb-2 lg:mb-3`,children:e.jsx(d,{size:15,className:k[t.color]})}),e.jsx("h3",{className:"text-xs lg:text-sm font-display font-semibold text-slate-800 mb-0.5",children:t.label}),e.jsx("p",{className:"text-[10px] lg:text-xs text-slate-400 font-body",children:t.desc})]},r)})})]}),e.jsx(i.div,{initial:{opacity:0,y:30},animate:{opacity:1,y:0},transition:{duration:.8,delay:.15,ease:[.22,1,.36,1]},className:"relative flex justify-center lg:justify-end",children:e.jsxs("div",{className:"bg-white/85 backdrop-blur-2xl border border-slate-200/60 rounded-3xl p-6 sm:p-7 w-full max-w-md relative overflow-hidden shadow-[0_20px_60px_-15px_rgba(168,85,247,0.15)] max-h-[85vh] overflow-y-auto",children:[e.jsx("div",{className:"absolute top-0 left-0 right-0 h-[3px] bg-gradient-to-r from-purple-500 via-pink-500 to-sky-500"}),e.jsx("div",{className:"absolute -top-40 left-1/2 -translate-x-1/2 w-80 h-80 bg-gradient-to-br from-purple-400/20 to-pink-400/20 rounded-full blur-[60px] pointer-events-none"}),e.jsxs("div",{className:"text-center mb-4 relative",children:[e.jsx(i.h3,{className:"text-2xl font-display font-bold text-slate-900 mb-2",initial:{opacity:0},animate:{opacity:1},transition:{delay:.4},children:l?"Create Account":"Welcome Back"}),e.jsx(i.p,{className:"text-sm text-slate-500 font-body",initial:{opacity:0},animate:{opacity:1},transition:{delay:.5},children:l?"Begin your learning journey":"Sign in to continue learning"})]}),e.jsxs("form",{onSubmit:fe,className:"space-y-3 mb-4 relative",children:[f&&!me&&e.jsx(i.div,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},className:"bg-rose-50 border border-rose-200 text-rose-600 px-4 py-3 rounded-lg text-sm font-body",children:f}),l&&e.jsxs(i.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},children:[e.jsx("label",{className:"block text-xs font-body font-semibold text-slate-500 mb-2 uppercase tracking-wider",children:"Full Name"}),e.jsxs("div",{className:"relative",children:[e.jsx(Q,{size:16,className:"absolute left-4 top-1/2 -translate-y-1/2 text-slate-400"}),e.jsx(L,{type:"text",placeholder:"Your Name",value:P,onChange:t=>ie(t.target.value),className:"w-full pl-11 pr-4 py-3 rounded-lg bg-slate-100/70 border-slate-200/80 text-slate-900 placeholder:text-slate-400 focus:border-sky-400 focus:ring-2 focus:ring-sky-400/20 focus:bg-white text-sm font-body transition-all",required:!0})]})]}),l&&e.jsxs(i.div,{initial:{opacity:0,x:-20},animate:{opacity:1,x:0},transition:{delay:.45},children:[e.jsx("label",{className:"block text-xs font-body font-semibold text-slate-500 mb-2 uppercase tracking-wider",children:"Account Type"}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:[{role:"student",label:"Student"},{role:"teacher",label:"Teacher"}].map(t=>{const r=y===t.role;return e.jsx("button",{type:"button",onClick:()=>D(t.role),className:`rounded-lg border px-3 py-2.5 text-sm font-body font-semibold transition-all ${r?"border-sky-400 bg-sky-50 text-sky-700":"border-slate-200 bg-slate-50 text-slate-500 hover:border-slate-300"}`,children:t.label},t.role)})})]}),l&&y==="student"&&e.jsx(i.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},className:"space-y-3",children:e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-body font-semibold text-slate-500 mb-2 uppercase tracking-wider",children:"Section"}),e.jsxs("div",{className:"relative",children:[e.jsx(Q,{size:16,className:"absolute left-4 top-1/2 -translate-y-1/2 text-slate-400"}),e.jsx("select",{value:v,onChange:t=>B(t.target.value),className:"w-full pl-11 pr-4 py-2.5 rounded-lg bg-slate-100/70 border border-slate-200/80 text-slate-900 focus:border-sky-400 focus:ring-2 focus:ring-sky-400/20 focus:bg-white text-sm font-body transition-all appearance-none",required:!0,children:(a[b]||[]).map(t=>e.jsx("option",{value:t,children:t},t))})]})]})}),e.jsxs(i.div,{initial:{opacity:0,x:-20},animate:{opacity:1,x:0},transition:{delay:.5},children:[e.jsx("label",{className:"block text-xs font-body font-semibold text-slate-500 mb-2 uppercase tracking-wider",children:"Email Address"}),e.jsxs("div",{className:"relative",children:[e.jsx(Re,{size:16,className:"absolute left-4 top-1/2 -translate-y-1/2 text-slate-400"}),e.jsx(L,{type:"email",placeholder:"your.email@school.edu",value:c,onChange:t=>o(t.target.value),className:"w-full pl-11 pr-4 py-3 rounded-lg bg-slate-100/70 border-slate-200/80 text-slate-900 placeholder:text-slate-400 focus:border-sky-400 focus:ring-2 focus:ring-sky-400/20 focus:bg-white text-sm font-body transition-all",required:!0})]})]}),e.jsxs(i.div,{initial:{opacity:0,x:-20},animate:{opacity:1,x:0},transition:{delay:.6},children:[e.jsx("label",{className:"block text-xs font-body font-semibold text-slate-500 mb-2 uppercase tracking-wider",children:"Password"}),e.jsxs("div",{className:"relative",children:[e.jsx(X,{size:16,className:"absolute left-4 top-1/2 -translate-y-1/2 text-slate-400"}),e.jsx(L,{type:S?"text":"password",placeholder:"••••••••",value:n,onChange:t=>h(t.target.value),className:"w-full pl-11 pr-11 py-3 rounded-lg bg-slate-100/70 border-slate-200/80 text-slate-900 placeholder:text-slate-400 focus:border-sky-400 focus:ring-2 focus:ring-sky-400/20 focus:bg-white text-sm font-body transition-all",required:!0,minLength:l?8:6}),e.jsx(i.button,{type:"button",onClick:()=>re(!S),className:"absolute right-3 top-1/2 -translate-y-1/2 text-slate-400 hover:text-slate-600 transition-colors",whileTap:{scale:.9},children:S?e.jsx(Ce,{size:16}):e.jsx(Ee,{size:16})})]}),l&&n.length>0&&!W&&e.jsxs("div",{className:"mt-2 rounded-lg border border-sky-100/80 bg-sky-50/70 px-3 py-2",children:[e.jsx("p",{className:"text-[11px] font-body font-semibold uppercase tracking-wider text-slate-600",children:"Password requirements"}),e.jsx("ul",{className:"mt-2 space-y-1",children:E.map(t=>e.jsxs("li",{className:`flex items-center gap-2 text-[11px] font-body ${t.met?"text-emerald-700":"text-slate-500"}`,children:[e.jsx("span",{className:`inline-block h-1.5 w-1.5 rounded-full ${t.met?"bg-emerald-500":"bg-slate-300"}`}),e.jsx("span",{children:t.label})]},t.id))})]})]}),e.jsx(i.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:.7},children:e.jsxs(je,{type:"submit",disabled:_,className:"w-full bg-gradient-to-r from-purple-600 to-pink-500 hover:from-purple-500 hover:to-pink-400 text-white font-body font-semibold py-3 rounded-xl shadow-lg shadow-purple-600/25 hover:shadow-pink-500/35 hover:scale-[1.02] transition-all text-sm group relative overflow-hidden disabled:opacity-50 disabled:cursor-not-allowed",children:[e.jsx(i.span,{className:"absolute inset-0 bg-gradient-to-r from-white/0 via-white/15 to-white/0",animate:{x:["-100%","100%"]},transition:{duration:3,repeat:1/0,repeatDelay:2}}),e.jsxs("span",{className:"relative flex items-center justify-center gap-2",children:[_?"Please wait...":l?"Create Account":"Sign In",e.jsx(K,{size:16,className:"group-hover:translate-x-1 transition-transform"})]})]})}),e.jsx("div",{className:"text-center",children:e.jsx("button",{type:"button",onClick:()=>{z(!l),u(null)},className:"text-sm text-slate-400 hover:text-sky-500 font-body font-medium transition-colors",children:l?"Already have an account? Sign in":"Don't have an account? Create one"})})]}),!l&&e.jsxs(i.div,{initial:{opacity:0},animate:{opacity:1},transition:{delay:.85},className:"mb-4 relative",children:[e.jsxs("div",{className:"relative flex items-center gap-3 mb-4",children:[e.jsx("div",{className:"flex-1 h-px bg-slate-200"}),e.jsx("span",{className:"text-[10px] font-body font-semibold text-slate-400 uppercase tracking-widest",children:"Quick Demo Access"}),e.jsx("div",{className:"flex-1 h-px bg-slate-200"})]}),e.jsx("div",{className:"flex flex-col gap-2",children:he.map(t=>{const r=t.icon,d={sky:"bg-sky-100",emerald:"bg-emerald-100",rose:"bg-rose-100"},m={sky:"text-sky-600",emerald:"text-emerald-600",rose:"text-rose-500"};return e.jsxs(i.button,{type:"button",onClick:()=>be(t.email,t.password,t.role),className:"group flex items-center gap-3 w-full px-4 py-2.5 rounded-lg bg-slate-50/80 border border-slate-200/70 hover:border-sky-300 hover:bg-sky-50/80 hover:shadow-sm transition-all text-left",whileHover:{scale:1.01},whileTap:{scale:.99},children:[e.jsx("div",{className:`w-8 h-8 rounded-md flex items-center justify-center shrink-0 ${d[t.color]}`,children:e.jsx(r,{size:15,className:m[t.color]})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("p",{className:"text-xs font-body font-semibold text-slate-700 group-hover:text-sky-600 transition-colors",children:[t.label," Account"]}),e.jsx("p",{className:"text-[10px] text-slate-400 font-body truncate",children:t.email})]}),e.jsx(K,{size:14,className:"text-slate-300 group-hover:text-sky-500 group-hover:translate-x-0.5 transition-all shrink-0"})]},t.label)})})]}),e.jsxs(i.p,{className:"text-xs text-slate-400 text-center mt-4 font-body relative",initial:{opacity:0},animate:{opacity:1},transition:{delay:1},children:[e.jsx(X,{size:10,className:"inline mr-1 -mt-0.5"})," Your data is encrypted and secure"]})]})})]})})]})};export{et as default}; +import{r as s,j as e}from"./vendor-react-B4AQeu28.js";import{B as je}from"./button-BMVm9YQO.js";import{I as L}from"./input-Co0dljwe.js";import{m as i,B as we,T as Ne,A as ke,U as Q,L as X,a as K,G as Se,b as Pe,s as ee,c as Ae,d as te}from"./index-Bp7MiGcW.js";import{S as Me}from"./sparkles-fLB3ltj1.js";import{M as Re}from"./mail-jAg7cqFw.js";import{E as Ce,a as Ee}from"./eye-B_U0s6fm.js";import{S as Te}from"./shield-check-qhTHRSP5.js";import"./vendor-radix-C5nwdvGr.js";import"./vendor-charts-CAmziV1y.js";import"./vendor-firebase-firestore-CNv3xXal.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";const se="/assets/shader-bg-DA7bEbBA.mp4",Le=[{id:"length",label:"At least 8 characters",test:a=>a.length>=8},{id:"upper-lower",label:"Contains uppercase and lowercase letters",test:a=>/[A-Z]/.test(a)&&/[a-z]/.test(a)},{id:"number",label:"Contains at least one number",test:a=>/\d/.test(a)},{id:"special",label:"Contains at least one special character",test:a=>/[^A-Za-z0-9]/.test(a)}],I="Use at least 8 characters with uppercase, lowercase, number, and special character.",Ie=a=>{const c=typeof a=="object"&&a!==null?a:null,o=a instanceof Error?a.message:"";if(c?.code&&typeof c.code=="string")return{code:c.code.toLowerCase(),message:o};const n=o.match(/auth\/[a-z-]+/i);return{code:n?n[0].toLowerCase():"",message:o}},ze=a=>a.replace(/^Firebase:\s*/i,"").replace(/\s*\(auth\/[a-z-]+\)\.?/i,"").trim(),ae=(a,c)=>{const{code:o,message:n}=Ie(a),h=ze(n);return o==="auth/invalid-credential"||o==="auth/wrong-password"||o==="auth/user-not-found"?"Invalid email or password. Please check your credentials and try again.":o==="auth/email-already-in-use"?"This email is already registered. Please sign in instead.":o==="auth/weak-password"||o==="auth/password-does-not-meet-requirements"?h?`Password does not meet signup requirements. ${h}`:`Password does not meet signup requirements. ${I}`:o==="auth/too-many-requests"?"Access to this account has been temporarily disabled due to many failed login attempts. You can immediately restore it by resetting your password or you can try again later.":o==="auth/network-request-failed"?"Network error. Please check your internet connection and try again.":o.startsWith("auth/")?h||c:n.includes("Firebase:")||n.includes("auth/")?c:n||c},et=()=>{const a={"Grade 11":["Academic","Tech-Pro"]},[c,o]=s.useState(""),[n,h]=s.useState(""),[S,re]=s.useState(!1),[l,z]=s.useState(!1),[P,ie]=s.useState(""),[y,D]=s.useState("student"),[b,De]=s.useState("Grade 11"),[v,B]=s.useState(a["Grade 11"][0]),[_,x]=s.useState(!1),[f,u]=s.useState(null),[oe,le]=s.useState(!1),[ne,ce]=s.useState(!1),[A,de]=s.useState(16),[q,V]=s.useState("primary"),[O,M]=s.useState(0),R=s.useRef(null),C=s.useRef(null),j=oe&&ne,g=s.useRef("primary"),w=s.useRef(0),N=s.useRef(!1),F=1.1,G=.34,U=t=>{const r=Math.max(0,Math.min(1,t));Math.abs(w.current-r)<.02||(w.current=r,M(r))},$=t=>{!Number.isFinite(t)||t<=0||Math.abs(A-t)>.05&&de(t)},E=s.useMemo(()=>Le.map(t=>({...t,met:t.test(n)})),[n]),W=s.useMemo(()=>E.every(t=>t.met),[E]),me=s.useMemo(()=>{if(!l||!f)return!1;const t=f.toLowerCase();return t.includes("password requirements not met")||t.includes("password does not meet")},[f,l]),ue=()=>{const t=R.current?.duration;t&&Number.isFinite(t)&&t>0&&$(t)},pe=()=>{const t=C.current?.duration;t&&Number.isFinite(t)&&t>0&&$(t)};s.useEffect(()=>{if(!j)return;const t=R.current,r=C.current;if(!t||!r)return;let d=!1,m=0;g.current="primary",V("primary"),N.current=!1,w.current=0,M(0),t.loop=!1,r.loop=!1,t.currentTime=0,r.currentTime=0,r.pause(),t.play().catch(()=>{});const k=()=>{if(d)return;const p=g.current==="primary"?t:r,Z=g.current==="primary"?r:t,ge=Number.isFinite(p.duration)&&p.duration>0?p.duration:A,T=Math.max(ge-p.currentTime,0);if(T<=F){N.current||(N.current=!0,Z.currentTime=0,Z.play().catch(()=>{}));const ve=1-T/F;if(U(ve),T<=.03||p.ended){p.pause(),p.currentTime=0;const J=g.current==="primary"?"secondary":"primary";g.current=J,V(J),N.current=!1,w.current=0,M(0)}}else U(0);m=window.requestAnimationFrame(k)};return m=window.requestAnimationFrame(k),()=>{d=!0,m&&window.cancelAnimationFrame(m)}},[A,j]);const Y=j?G*(1-O):0,H=j?G*O:0,xe=q==="primary"?Y:H,ye=q==="secondary"?Y:H;s.useEffect(()=>{const t=a[b]||[];t.length>0&&!t.includes(v)&&B(t[0])},[b,v]);const he=[{label:"Student",role:"student",email:"teststudent@school.edu",password:"TestPass123!",icon:Se,color:"sky"},{label:"Teacher",role:"teacher",email:"testteacher@school.edu",password:"TestPass123!",icon:Pe,color:"emerald"},{label:"Admin",role:"admin",email:"testadmin@school.edu",password:"TestPass123!",icon:Te,color:"rose"}],be=async(t,r,d)=>{u(null),x(!0),o(t),h(r),D(d),z(!1);try{ee(d),await te(t,r)}catch(m){u(ae(m,"Demo sign-in failed. Please try again.")),x(!1)}},fe=async t=>{t.preventDefault(),u(null),x(!0);try{if(l){if(!P.trim()){u("Please enter your name"),x(!1);return}if(y==="student"&&!b){u("Please select a grade level"),x(!1);return}if(y==="admin"){u("Admin account creation is restricted. Please contact an existing administrator."),x(!1);return}if(!W){u(`Password does not meet signup requirements. ${I}`),x(!1);return}ee(y),await Ae(c,n,P,y,y==="student"?{grade:b,section:v}:{department:"Mathematics"})}else await te(c,n)}catch(r){const d=l?`Sign-up failed. ${I}`:"Sign-in failed. Please check your credentials and try again.";u(ae(r,d)),x(!1)}};return e.jsxs("div",{className:"min-h-screen w-full flex items-center justify-center px-4 sm:px-6 py-8 overflow-y-auto relative login-bg",children:[e.jsx("video",{ref:R,autoPlay:!0,muted:!0,playsInline:!0,preload:"auto",onCanPlay:()=>le(!0),onLoadedMetadata:ue,className:"absolute inset-0 w-full h-full object-cover transition-opacity duration-150 e-opacity",style:{"--o":xe},src:se}),e.jsx("video",{ref:C,autoPlay:!0,muted:!0,playsInline:!0,preload:"auto",onCanPlay:()=>ce(!0),onLoadedMetadata:pe,className:"absolute inset-0 w-full h-full object-cover transition-opacity duration-150 e-opacity",style:{"--o":ye},src:se}),e.jsx("div",{className:"absolute inset-0 pointer-events-none login-frost-overlay"}),e.jsx("div",{className:"absolute top-[10%] left-[-10%] w-[60%] h-[60%] rounded-full blur-[140px] pointer-events-none mix-blend-multiply login-orb-purple"}),e.jsx("div",{className:"absolute bottom-[-10%] right-[-10%] w-[70%] h-[70%] rounded-full blur-[160px] pointer-events-none mix-blend-multiply login-orb-pink"}),e.jsx("div",{className:"absolute top-[40%] left-[40%] w-[40%] h-[40%] rounded-full blur-[120px] pointer-events-none mix-blend-screen login-orb-blue"}),e.jsx("div",{className:"relative z-10 w-full max-w-6xl mx-auto",children:e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-8 lg:gap-12 items-center",children:[e.jsxs(i.div,{initial:{opacity:0,x:-40},animate:{opacity:1,x:0},transition:{duration:.8,ease:[.22,1,.36,1]},className:"flex flex-col items-center lg:items-start justify-center space-y-5 lg:space-y-8 text-center lg:text-left",children:[e.jsxs(i.div,{className:"flex items-center justify-center lg:justify-start gap-2.5",children:[e.jsx(i.div,{className:"relative flex items-center justify-center drop-shadow-md",children:e.jsx("img",{src:"/mathpulse_final_logo.png",alt:"MathPulse AI Logo",className:"w-10 h-10 lg:w-16 lg:h-16 object-contain flex-shrink-0"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl lg:text-3xl font-display font-black tracking-tight text-slate-900 bg-clip-text text-transparent bg-gradient-to-r from-purple-600 via-pink-600 to-sky-500",children:"MathPulse"}),e.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5",children:[e.jsx(Me,{size:12,className:"text-rose-500"}),e.jsx("span",{className:"text-xs text-slate-500 font-body font-medium tracking-wide",children:"Powered by Machine Learning"})]})]})]}),e.jsxs(i.div,{className:"space-y-3 lg:space-y-5",initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.2,duration:.8},children:[e.jsxs("h2",{className:"text-3xl sm:text-4xl lg:text-5xl xl:text-[3.4rem] font-display font-extrabold leading-[1.1] tracking-tight text-slate-900",children:["Transform Your",e.jsx("br",{}),e.jsx("span",{className:"bg-gradient-to-r from-sky-600 via-cyan-500 to-sky-500 bg-clip-text text-transparent",children:"Math Journey"})]}),e.jsx("p",{className:"text-sm lg:text-base text-slate-500 leading-relaxed max-w-md mx-auto lg:mx-0 font-body",children:"AI-powered predictive system designed to identify at-risk students and provide personalized learning recommendations."})]}),e.jsx("div",{className:"grid grid-cols-3 gap-2 lg:gap-3",children:[{icon:we,label:"AI Predictions",desc:"Smart detection",color:"sky"},{icon:Ne,label:"Analytics",desc:"Real-time data",color:"rose"},{icon:ke,label:"Gamified",desc:"Learn & earn",color:"emerald"}].map((t,r)=>{const d=t.icon,m={sky:"border-sky-200/60 hover:border-sky-300",rose:"border-rose-200/60 hover:border-rose-300",emerald:"border-emerald-200/60 hover:border-emerald-300"},k={sky:"text-sky-600",rose:"text-rose-500",emerald:"text-emerald-600"},p={sky:"bg-sky-100",rose:"bg-rose-100",emerald:"bg-emerald-100"};return e.jsxs(i.div,{className:`bg-white/80 backdrop-blur-xl border ${m[t.color]} rounded-xl p-3 lg:p-4 transition-all cursor-pointer group shadow-md shadow-slate-900/[0.04]`,initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.5+r*.1},whileHover:{scale:1.03,y:-4},children:[e.jsx("div",{className:`w-7 h-7 lg:w-9 lg:h-9 rounded-lg ${p[t.color]} flex items-center justify-center mx-auto lg:mx-0 mb-2 lg:mb-3`,children:e.jsx(d,{size:15,className:k[t.color]})}),e.jsx("h3",{className:"text-xs lg:text-sm font-display font-semibold text-slate-800 mb-0.5",children:t.label}),e.jsx("p",{className:"text-[10px] lg:text-xs text-slate-400 font-body",children:t.desc})]},r)})})]}),e.jsx(i.div,{initial:{opacity:0,y:30},animate:{opacity:1,y:0},transition:{duration:.8,delay:.15,ease:[.22,1,.36,1]},className:"relative flex justify-center lg:justify-end",children:e.jsxs("div",{className:"bg-white/85 backdrop-blur-2xl border border-slate-200/60 rounded-3xl p-6 sm:p-7 w-full max-w-md relative overflow-hidden shadow-[0_20px_60px_-15px_rgba(168,85,247,0.15)] max-h-[85vh] overflow-y-auto",children:[e.jsx("div",{className:"absolute top-0 left-0 right-0 h-[3px] bg-gradient-to-r from-purple-500 via-pink-500 to-sky-500"}),e.jsx("div",{className:"absolute -top-40 left-1/2 -translate-x-1/2 w-80 h-80 bg-gradient-to-br from-purple-400/20 to-pink-400/20 rounded-full blur-[60px] pointer-events-none"}),e.jsxs("div",{className:"text-center mb-4 relative",children:[e.jsx(i.h3,{className:"text-2xl font-display font-bold text-slate-900 mb-2",initial:{opacity:0},animate:{opacity:1},transition:{delay:.4},children:l?"Create Account":"Welcome Back"}),e.jsx(i.p,{className:"text-sm text-slate-500 font-body",initial:{opacity:0},animate:{opacity:1},transition:{delay:.5},children:l?"Begin your learning journey":"Sign in to continue learning"})]}),e.jsxs("form",{onSubmit:fe,className:"space-y-3 mb-4 relative",children:[f&&!me&&e.jsx(i.div,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},className:"bg-rose-50 border border-rose-200 text-rose-600 px-4 py-3 rounded-lg text-sm font-body",children:f}),l&&e.jsxs(i.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},children:[e.jsx("label",{className:"block text-xs font-body font-semibold text-slate-500 mb-2 uppercase tracking-wider",children:"Full Name"}),e.jsxs("div",{className:"relative",children:[e.jsx(Q,{size:16,className:"absolute left-4 top-1/2 -translate-y-1/2 text-slate-400"}),e.jsx(L,{type:"text",placeholder:"Your Name",value:P,onChange:t=>ie(t.target.value),className:"w-full pl-11 pr-4 py-3 rounded-lg bg-slate-100/70 border-slate-200/80 text-slate-900 placeholder:text-slate-400 focus:border-sky-400 focus:ring-2 focus:ring-sky-400/20 focus:bg-white text-sm font-body transition-all",required:!0})]})]}),l&&e.jsxs(i.div,{initial:{opacity:0,x:-20},animate:{opacity:1,x:0},transition:{delay:.45},children:[e.jsx("label",{className:"block text-xs font-body font-semibold text-slate-500 mb-2 uppercase tracking-wider",children:"Account Type"}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:[{role:"student",label:"Student"},{role:"teacher",label:"Teacher"}].map(t=>{const r=y===t.role;return e.jsx("button",{type:"button",onClick:()=>D(t.role),className:`rounded-lg border px-3 py-2.5 text-sm font-body font-semibold transition-all ${r?"border-sky-400 bg-sky-50 text-sky-700":"border-slate-200 bg-slate-50 text-slate-500 hover:border-slate-300"}`,children:t.label},t.role)})})]}),l&&y==="student"&&e.jsx(i.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},className:"space-y-3",children:e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-body font-semibold text-slate-500 mb-2 uppercase tracking-wider",children:"Section"}),e.jsxs("div",{className:"relative",children:[e.jsx(Q,{size:16,className:"absolute left-4 top-1/2 -translate-y-1/2 text-slate-400"}),e.jsx("select",{value:v,onChange:t=>B(t.target.value),className:"w-full pl-11 pr-4 py-2.5 rounded-lg bg-slate-100/70 border border-slate-200/80 text-slate-900 focus:border-sky-400 focus:ring-2 focus:ring-sky-400/20 focus:bg-white text-sm font-body transition-all appearance-none",required:!0,children:(a[b]||[]).map(t=>e.jsx("option",{value:t,children:t},t))})]})]})}),e.jsxs(i.div,{initial:{opacity:0,x:-20},animate:{opacity:1,x:0},transition:{delay:.5},children:[e.jsx("label",{className:"block text-xs font-body font-semibold text-slate-500 mb-2 uppercase tracking-wider",children:"Email Address"}),e.jsxs("div",{className:"relative",children:[e.jsx(Re,{size:16,className:"absolute left-4 top-1/2 -translate-y-1/2 text-slate-400"}),e.jsx(L,{type:"email",placeholder:"your.email@school.edu",value:c,onChange:t=>o(t.target.value),className:"w-full pl-11 pr-4 py-3 rounded-lg bg-slate-100/70 border-slate-200/80 text-slate-900 placeholder:text-slate-400 focus:border-sky-400 focus:ring-2 focus:ring-sky-400/20 focus:bg-white text-sm font-body transition-all",required:!0})]})]}),e.jsxs(i.div,{initial:{opacity:0,x:-20},animate:{opacity:1,x:0},transition:{delay:.6},children:[e.jsx("label",{className:"block text-xs font-body font-semibold text-slate-500 mb-2 uppercase tracking-wider",children:"Password"}),e.jsxs("div",{className:"relative",children:[e.jsx(X,{size:16,className:"absolute left-4 top-1/2 -translate-y-1/2 text-slate-400"}),e.jsx(L,{type:S?"text":"password",placeholder:"••••••••",value:n,onChange:t=>h(t.target.value),className:"w-full pl-11 pr-11 py-3 rounded-lg bg-slate-100/70 border-slate-200/80 text-slate-900 placeholder:text-slate-400 focus:border-sky-400 focus:ring-2 focus:ring-sky-400/20 focus:bg-white text-sm font-body transition-all",required:!0,minLength:l?8:6}),e.jsx(i.button,{type:"button",onClick:()=>re(!S),className:"absolute right-3 top-1/2 -translate-y-1/2 text-slate-400 hover:text-slate-600 transition-colors",whileTap:{scale:.9},children:S?e.jsx(Ce,{size:16}):e.jsx(Ee,{size:16})})]}),l&&n.length>0&&!W&&e.jsxs("div",{className:"mt-2 rounded-lg border border-sky-100/80 bg-sky-50/70 px-3 py-2",children:[e.jsx("p",{className:"text-[11px] font-body font-semibold uppercase tracking-wider text-slate-600",children:"Password requirements"}),e.jsx("ul",{className:"mt-2 space-y-1",children:E.map(t=>e.jsxs("li",{className:`flex items-center gap-2 text-[11px] font-body ${t.met?"text-emerald-700":"text-slate-500"}`,children:[e.jsx("span",{className:`inline-block h-1.5 w-1.5 rounded-full ${t.met?"bg-emerald-500":"bg-slate-300"}`}),e.jsx("span",{children:t.label})]},t.id))})]})]}),e.jsx(i.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:.7},children:e.jsxs(je,{type:"submit",disabled:_,className:"w-full bg-gradient-to-r from-purple-600 to-pink-500 hover:from-purple-500 hover:to-pink-400 text-white font-body font-semibold py-3 rounded-xl shadow-lg shadow-purple-600/25 hover:shadow-pink-500/35 hover:scale-[1.02] transition-all text-sm group relative overflow-hidden disabled:opacity-50 disabled:cursor-not-allowed",children:[e.jsx(i.span,{className:"absolute inset-0 bg-gradient-to-r from-white/0 via-white/15 to-white/0",animate:{x:["-100%","100%"]},transition:{duration:3,repeat:1/0,repeatDelay:2}}),e.jsxs("span",{className:"relative flex items-center justify-center gap-2",children:[_?"Please wait...":l?"Create Account":"Sign In",e.jsx(K,{size:16,className:"group-hover:translate-x-1 transition-transform"})]})]})}),e.jsx("div",{className:"text-center",children:e.jsx("button",{type:"button",onClick:()=>{z(!l),u(null)},className:"text-sm text-slate-400 hover:text-sky-500 font-body font-medium transition-colors",children:l?"Already have an account? Sign in":"Don't have an account? Create one"})})]}),!l&&e.jsxs(i.div,{initial:{opacity:0},animate:{opacity:1},transition:{delay:.85},className:"mb-4 relative",children:[e.jsxs("div",{className:"relative flex items-center gap-3 mb-4",children:[e.jsx("div",{className:"flex-1 h-px bg-slate-200"}),e.jsx("span",{className:"text-[10px] font-body font-semibold text-slate-400 uppercase tracking-widest",children:"Quick Demo Access"}),e.jsx("div",{className:"flex-1 h-px bg-slate-200"})]}),e.jsx("div",{className:"flex flex-col gap-2",children:he.map(t=>{const r=t.icon,d={sky:"bg-sky-100",emerald:"bg-emerald-100",rose:"bg-rose-100"},m={sky:"text-sky-600",emerald:"text-emerald-600",rose:"text-rose-500"};return e.jsxs(i.button,{type:"button",onClick:()=>be(t.email,t.password,t.role),className:"group flex items-center gap-3 w-full px-4 py-2.5 rounded-lg bg-slate-50/80 border border-slate-200/70 hover:border-sky-300 hover:bg-sky-50/80 hover:shadow-sm transition-all text-left",whileHover:{scale:1.01},whileTap:{scale:.99},children:[e.jsx("div",{className:`w-8 h-8 rounded-md flex items-center justify-center shrink-0 ${d[t.color]}`,children:e.jsx(r,{size:15,className:m[t.color]})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("p",{className:"text-xs font-body font-semibold text-slate-700 group-hover:text-sky-600 transition-colors",children:[t.label," Account"]}),e.jsx("p",{className:"text-[10px] text-slate-400 font-body truncate",children:t.email})]}),e.jsx(K,{size:14,className:"text-slate-300 group-hover:text-sky-500 group-hover:translate-x-0.5 transition-all shrink-0"})]},t.label)})})]}),e.jsxs(i.p,{className:"text-xs text-slate-400 text-center mt-4 font-body relative",initial:{opacity:0},animate:{opacity:1},transition:{delay:1},children:[e.jsx(X,{size:10,className:"inline mr-1 -mt-0.5"})," Your data is encrypted and secure"]})]})})]})})]})};export{et as default}; diff --git a/assets/LogoutActionButton-ke8I5kxg.js b/assets/LogoutActionButton-BlHbD8Uf.js similarity index 94% rename from assets/LogoutActionButton-ke8I5kxg.js rename to assets/LogoutActionButton-BlHbD8Uf.js index 45fe426da3f3e2f38121395a3895220c0ff6d9f1..b40ad9a22645c783e88baa9ff26b62e90e003b57 100644 --- a/assets/LogoutActionButton-ke8I5kxg.js +++ b/assets/LogoutActionButton-BlHbD8Uf.js @@ -1,4 +1,4 @@ -import{e,m as r,o as l}from"./index-BufUS6SI.js";import{j as t}from"./vendor-react-B4AQeu28.js";import{L as n}from"./log-out-Cp6gBYHP.js";/** +import{e,m as r,o as l}from"./index-Bp7MiGcW.js";import{j as t}from"./vendor-react-B4AQeu28.js";import{L as n}from"./log-out-DrAbcVI9.js";/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. diff --git a/assets/ModuleFolderCard-CqhxwGI0.js b/assets/ModuleFolderCard-BaBw0Pd9.js similarity index 97% rename from assets/ModuleFolderCard-CqhxwGI0.js rename to assets/ModuleFolderCard-BaBw0Pd9.js index d3cd529cc06f2f7ca84642d6f73b97bd9d86c653..66a954029d64243de08399489207cf2e4c71ef7c 100644 --- a/assets/ModuleFolderCard-CqhxwGI0.js +++ b/assets/ModuleFolderCard-BaBw0Pd9.js @@ -1,4 +1,4 @@ -import{j as e,r as h}from"./vendor-react-B4AQeu28.js";import{u as j}from"./useSubjectAvailability-BXzXJ4_J.js";import{a as y}from"./deepseekRagService-Bke9fSTt.js";import{e as u,m as N,b as k,y as _,G as B}from"./index-BufUS6SI.js";import{C as z}from"./clock-CooTZK0X.js";import{B as A}from"./bell-D9j1Gy0m.js";import{I as M}from"./info-a-Ci1_jf.js";/** +import{j as e,r as h}from"./vendor-react-B4AQeu28.js";import{u as j}from"./useSubjectAvailability-Dm-85m8R.js";import{a as y}from"./deepseekRagService-Bke9fSTt.js";import{e as u,m as N,b as k,y as _,G as B}from"./index-Bp7MiGcW.js";import{C as z}from"./clock-Cc6sJz1J.js";import{B as A}from"./bell-DyLbgepV.js";import{I as M}from"./info-Bcg_cBHY.js";/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. diff --git a/assets/ModulesPage-CT0lsQBD.js b/assets/ModulesPage-CT0lsQBD.js deleted file mode 100644 index 736139ac703e62e3115182d878a709b070e76cbc..0000000000000000000000000000000000000000 --- a/assets/ModulesPage-CT0lsQBD.js +++ /dev/null @@ -1,199 +0,0 @@ -const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-BufUS6SI.js","assets/vendor-react-B4AQeu28.js","assets/vendor-firebase-firestore-CNv3xXal.js","assets/vendor-firebase-core-D7GXCeNu.js","assets/vendor-firebase-auth-T_wvTOvf.js","assets/vendor-firebase-storage-Bi7H_66d.js","assets/vendor-firebase-analytics-rHarj5hR.js","assets/vendor-radix-C5nwdvGr.js","assets/vendor-charts-CAmziV1y.js","assets/vendor-markdown-yqZQ_iQm.js","assets/vendor-markdown-CfVKi3_s.css","assets/index-CIg5rXpX.css"])))=>i.map(i=>d[i]); -import{r as a,j as e,b as vt,d as je,c as sa}from"./vendor-react-B4AQeu28.js";import{u as aa}from"./useQuery-BQZpC2ch.js";import{doc as kt,onSnapshot as as,getDoc as Yt,runTransaction as ra,serverTimestamp as na,query as la,where as ia,collection as oa}from"./vendor-firebase-firestore-CNv3xXal.js";import{e as ae,g as tt,ae as ca,_ as Ft,m as S,Z as Xe,h as ot,$ as rs,b as Fe,C as wt,M as da,a as ht,T as At,r as et,a7 as $s,R as Bs,F as ns,w as $t,u as Bt,A as Tt,o as It,y as Hs,ad as us,af as ma,ag as ps,ah as xa,q as qs,ai as ua,L as Os,B as pa,aj as ha,ak as Qs,al as fa,am as ba,an as ga,ab as ya,x as wa,ao as hs,ap as ja,aq as fs,G as va,j as ut,a9 as Na,ac as ka}from"./index-BufUS6SI.js";import{M as Kt}from"./ModuleFolderCard-CqhxwGI0.js";import{B as Me}from"./button-DsnZWCoA.js";import{triggerQuizSubmitted as Sa}from"./automationService-KQFQd_ic.js";import{e as Ca,g as za,A as Zt,V as Ma,c as _a,P as Jt,L as Aa}from"./quizService-pQBMW3NE.js";import Ws from"./ScientificCalculator-BIH8UnvI.js";import{C as Rt}from"./check-B-qbiSF7.js";import{X as Je}from"./x-BuBjuj2Y.js";import{C as Nt}from"./clock-CooTZK0X.js";import{V as es,a as ts,M as Us,b as Gs}from"./volume-x-B-4GTwzp.js";import{C as ss}from"./chevron-left-DMbkPbec.js";import{C as it}from"./chevron-right-DADygX42.js";import{C as Ut,L as jt}from"./lightbulb-bxzKA78M.js";import{C as ft}from"./circle-check-big-CDg2qLfH.js";import{C as Ea}from"./circle-help-DNA0h1v1.js";import{logLessonView as Ta}from"./trackingService-BvYmoqHJ.js";import{C as Pa}from"./clipboard-check-UJ1-0W8j.js";import{s as Dt,S as bs}from"./subjects-D9a9cUC-.js";import{C as Xs}from"./circle-check-BzgmgbHa.js";import{C as La}from"./chart-column-BcVJ31XT.js";import{D as Ia}from"./dollar-sign-DWySnopv.js";import gs from"./confetti.module-C94ZD2ww.js";import{G as Da}from"./gift-D-3Burw1.js";import{u as Ra}from"./useCurriculum-DhjMQzo9.js";import{w as Fa}from"./moduleWatchService-D8kT4330.js";import{S as $a}from"./search-DFK_sFlt.js";import{F as Ba}from"./funnel-zhOTiCKD.js";import{S as Ha}from"./sparkles-DYlMf97S.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-radix-C5nwdvGr.js";import"./vendor-charts-CAmziV1y.js";import"./vendor-markdown-yqZQ_iQm.js";import"./useSubjectAvailability-BXzXJ4_J.js";import"./deepseekRagService-Bke9fSTt.js";import"./bell-D9j1Gy0m.js";import"./info-a-Ci1_jf.js";import"./chevron-up-CoNRuMZ7.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 qa=[["rect",{x:"14",y:"14",width:"4",height:"6",rx:"2",key:"p02svl"}],["rect",{x:"6",y:"4",width:"4",height:"6",rx:"2",key:"xm4xkj"}],["path",{d:"M6 20h4",key:"1i6q5t"}],["path",{d:"M14 10h4",key:"ru81e7"}],["path",{d:"M6 14h2v6",key:"16z9wg"}],["path",{d:"M14 4h2v6",key:"1idq9u"}]],Oa=ae("binary",qa);/** - * @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 Qa=[["path",{d:"M15 13a3 3 0 1 0-6 0",key:"10j68g"}],["path",{d:"M4 19.5v-15A2.5 2.5 0 0 1 6.5 2H19a1 1 0 0 1 1 1v18a1 1 0 0 1-1 1H6.5a1 1 0 0 1 0-5H20",key:"k3hazp"}],["circle",{cx:"12",cy:"8",r:"2",key:"1822b1"}]],ys=ae("book-user",Qa);/** - * @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 Wa=[["path",{d:"m19 21-7-4-7 4V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16z",key:"1fy3hk"}]],ws=ae("bookmark",Wa);/** - * @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:"M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z",key:"hh9hay"}],["path",{d:"m3.3 7 8.7 5 8.7-5",key:"g66t2b"}],["path",{d:"M12 22V12",key:"d0xqtd"}]],js=ae("box",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 Ga=[["path",{d:"M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1",key:"ezmyqa"}],["path",{d:"M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 1-2-2V5a2 2 0 0 0-2-2h-1",key:"e1hn23"}]],vs=ae("braces",Ga);/** - * @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 Xa=[["circle",{cx:"7.5",cy:"7.5",r:".5",fill:"currentColor",key:"kqv944"}],["circle",{cx:"18.5",cy:"5.5",r:".5",fill:"currentColor",key:"lysivs"}],["circle",{cx:"11.5",cy:"11.5",r:".5",fill:"currentColor",key:"byv1b8"}],["circle",{cx:"7.5",cy:"16.5",r:".5",fill:"currentColor",key:"nkw3mc"}],["circle",{cx:"17.5",cy:"14.5",r:".5",fill:"currentColor",key:"1gjh6j"}],["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}]],Va=ae("chart-scatter",Xa);/** - * @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 Ya=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["polygon",{points:"10 8 16 12 10 16 10 8",key:"1cimsy"}]],Ka=ae("circle-play",Ya);/** - * @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"}]],Ns=ae("circle",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 Ja=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"22",x2:"18",y1:"12",y2:"12",key:"l9bcsi"}],["line",{x1:"6",x2:"2",y1:"12",y2:"12",key:"13hhkx"}],["line",{x1:"12",x2:"12",y1:"6",y2:"2",key:"10w3f3"}],["line",{x1:"12",x2:"12",y1:"22",y2:"18",key:"15g9kq"}]],er=ae("crosshair",Ja);/** - * @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 tr=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}],["path",{d:"M16 8h.01",key:"cr5u4v"}],["path",{d:"M8 8h.01",key:"1e4136"}],["path",{d:"M8 16h.01",key:"18s6g9"}],["path",{d:"M16 16h.01",key:"1f9h7w"}],["path",{d:"M12 12h.01",key:"1mp3jc"}]],sr=ae("dice-5",tr);/** - * @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 ar=[["circle",{cx:"12",cy:"6",r:"1",key:"1bh7o1"}],["line",{x1:"5",x2:"19",y1:"12",y2:"12",key:"13b5wn"}],["circle",{cx:"12",cy:"18",r:"1",key:"lqb9t5"}]],Gt=ae("divide",ar);/** - * @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 rr=[["path",{d:"M14 2v6a2 2 0 0 0 .245.96l5.51 10.08A2 2 0 0 1 18 22H6a2 2 0 0 1-1.755-2.96l5.51-10.08A2 2 0 0 0 10 8V2",key:"18mbvz"}],["path",{d:"M6.453 15h11.094",key:"3shlmq"}],["path",{d:"M8.5 2h7",key:"csnxdl"}]],nr=ae("flask-conical",rr);/** - * @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 lr=[["line",{x1:"4",x2:"20",y1:"9",y2:"9",key:"4lhtct"}],["line",{x1:"4",x2:"20",y1:"15",y2:"15",key:"vyu0kd"}],["line",{x1:"10",x2:"8",y1:"3",y2:"21",key:"1ggp8o"}],["line",{x1:"16",x2:"14",y1:"3",y2:"21",key:"weycgp"}]],ks=ae("hash",lr);/** - * @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 ir=[["path",{d:"M19 14c1.49-1.46 3-3.21 3-5.5A5.5 5.5 0 0 0 16.5 3c-1.76 0-3 .5-4.5 2-1.5-1.5-2.74-2-4.5-2A5.5 5.5 0 0 0 2 8.5c0 2.3 1.5 4.05 3 5.5l7 7Z",key:"c3ymky"}],["path",{d:"m12 13-1-1 2-2-3-3 2-2",key:"xjdxli"}]],Vs=ae("heart-crack",ir);/** - * @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 or=[["path",{d:"m15.5 7.5 2.3 2.3a1 1 0 0 0 1.4 0l2.1-2.1a1 1 0 0 0 0-1.4L19 4",key:"g0fldk"}],["path",{d:"m21 2-9.6 9.6",key:"1j0ho8"}],["circle",{cx:"7.5",cy:"15.5",r:"5.5",key:"yqb3hr"}]],cr=ae("key",or);/** - * @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 dr=[["path",{d:"M13.4 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-7.4",key:"re6nr2"}],["path",{d:"M2 6h4",key:"aawbzj"}],["path",{d:"M2 10h4",key:"l0bgd4"}],["path",{d:"M2 14h4",key:"1gsvsf"}],["path",{d:"M2 18h4",key:"1bu2t1"}],["path",{d:"M21.378 5.626a1 1 0 1 0-3.004-3.004l-5.01 5.012a2 2 0 0 0-.506.854l-.837 2.87a.5.5 0 0 0 .62.62l2.87-.837a2 2 0 0 0 .854-.506z",key:"pqwjuv"}]],mr=ae("notebook-pen",dr);/** - * @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 xr=[["line",{x1:"19",x2:"5",y1:"5",y2:"19",key:"1x9vlm"}],["circle",{cx:"6.5",cy:"6.5",r:"2.5",key:"4mh3h7"}],["circle",{cx:"17.5",cy:"17.5",r:"2.5",key:"1mdrzq"}]],Ss=ae("percent",xr);/** - * @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 ur=[["path",{d:"M21.3 15.3a2.4 2.4 0 0 1 0 3.4l-2.6 2.6a2.4 2.4 0 0 1-3.4 0L2.7 8.7a2.41 2.41 0 0 1 0-3.4l2.6-2.6a2.41 2.41 0 0 1 3.4 0Z",key:"icamh8"}],["path",{d:"m14.5 12.5 2-2",key:"inckbg"}],["path",{d:"m11.5 9.5 2-2",key:"fmmyf7"}],["path",{d:"m8.5 6.5 2-2",key:"vc6u1g"}],["path",{d:"m17.5 15.5 2-2",key:"wo5hmg"}]],pr=ae("ruler",ur);/** - * @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 hr=[["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:"M14 15H9v-5",key:"pi4jk9"}],["path",{d:"M16 3h5v5",key:"1806ms"}],["path",{d:"M21 3 9 15",key:"15kdhq"}]],fr=ae("scaling",hr);/** - * @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 br=[["path",{d:"M18 7V5a1 1 0 0 0-1-1H6.5a.5.5 0 0 0-.4.8l4.5 6a2 2 0 0 1 0 2.4l-4.5 6a.5.5 0 0 0 .4.8H17a1 1 0 0 0 1-1v-2",key:"wuwx1p"}]],Cs=ae("sigma",br);/** - * @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 gr=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}],["path",{d:"M9 17c2 0 2.8-1 2.8-2.8V10c0-2 1-3.3 3.2-3",key:"m1af9g"}],["path",{d:"M9 11.2h5.7",key:"3zgcl2"}]],Xt=ae("square-function",gr);/** - * @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 yr=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]],zs=ae("square",yr);/** - * @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 wr=[["line",{x1:"10",x2:"14",y1:"2",y2:"2",key:"14vaq8"}],["line",{x1:"12",x2:"15",y1:"14",y2:"11",key:"17fdiu"}],["circle",{cx:"12",cy:"14",r:"8",key:"1e1u0o"}]],jr=ae("timer",wr);/** - * @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 vr=[["path",{d:"M13.73 4a2 2 0 0 0-3.46 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z",key:"14u9p9"}]],Ms=ae("triangle",vr);function Nr(t){let s=t>>>0;return()=>{s+=1831565813;let n=Math.imul(s^s>>>15,s|1);return n^=n+Math.imul(n^n>>>7,n|61),((n^n>>>14)>>>0)/4294967296}}function kr(t,s){const n=[...t],i=Nr(s);for(let l=n.length-1;l>0;l--){const c=Math.floor(i()*(l+1));[n[l],n[c]]=[n[c],n[l]]}return n}function ls(t){const s=t??new Date;return new Intl.DateTimeFormat("en-CA",{timeZone:"Asia/Manila",year:"numeric",month:"2-digit",day:"2-digit"}).format(s)}function is(t){const s=new Date,n=new Intl.DateTimeFormat("en-US",{timeZone:"Asia/Manila",year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!1}).formatToParts(s),i=l=>parseInt(n.find(c=>c.type===l)?.value??"0",10);return new Date(i("year"),i("month")-1,i("day"),i("hour"),i("minute"),i("second"))}function os(t){const s=is(),n=s.getFullYear(),i=(s.getDay()+6)%7,l=new Date(s);l.setDate(s.getDate()-i+3);const c=new Date(l.getFullYear(),0,1),r=Math.floor((l.getTime()-c.getTime())/(1440*60*1e3)),d=Math.floor(r/7)+1;return n*100+d}function cs(t){return(is().getDay()+6)%7}function Sr(t){const s=new Date,n=480*60*1e3,i=s.getTime()+n,c=(new Date(i).getUTCDay()+6)%7,r=c===0?7:7-c,x=i-i%(1440*60*1e3)+r*24*60*60*1e3;return new Date(x-n)}const Cr=[{id:"xp_50",label:"+50 XP Boost",description:"Bonus XP on your next quiz",icon:"⚡",type:"xp",value:50,rarity:"common",color:"#4ade80"},{id:"xp_100",label:"+100 XP Boost",description:"Double bonus XP reward",icon:"🌟",type:"xp",value:100,rarity:"rare",color:"#facc15"},{id:"xp_200",label:"+200 XP Epic Boost",description:"Massive XP surge",icon:"💥",type:"xp",value:200,rarity:"epic",color:"#f97316"},{id:"streak_shield",label:"Streak Shield",description:"Protects streak if you miss a day",icon:"🛡️",type:"streak_shield",value:1,rarity:"rare",color:"#60a5fa"},{id:"hint_x3",label:"3 Hint Tokens",description:"Use in-quiz hints",icon:"💡",type:"hint_token",value:3,rarity:"common",color:"#a78bfa"},{id:"hint_x5",label:"5 Hint Tokens",description:"More hints to use",icon:"🔦",type:"hint_token",value:5,rarity:"rare",color:"#8b5cf6"},{id:"xp_mult_1h",label:"1-Hour XP ×1.5",description:"1.5× XP for all quizzes for 1 hour",icon:"⏰",type:"xp_multiplier",value:60,rarity:"epic",color:"#ec4899"},{id:"xp_mult_30m",label:"30-Min XP ×2",description:"2× XP for 30 minutes",icon:"🚀",type:"xp_multiplier",value:30,rarity:"epic",color:"#e11d48"},{id:"xp_75",label:"+75 XP Boost",description:"Solid XP reward",icon:"✨",type:"xp",value:75,rarity:"common",color:"#34d399"},{id:"hint_x2",label:"2 Hint Tokens",description:"Quick hint pack",icon:"🕯️",type:"hint_token",value:2,rarity:"common",color:"#7c3aed"},{id:"xp_streak_150",label:"+150 XP + Streak Save",description:"XP boost + streak protection combo",icon:"🔥",type:"xp",value:150,rarity:"epic",color:"#dc2626"},{id:"xp_25",label:"+25 XP Starter",description:"Small but reliable XP",icon:"🌱",type:"xp",value:25,rarity:"common",color:"#86efac"},{id:"hint_x1",label:"1 Hint Token",description:"A single lifeline",icon:"🔍",type:"hint_token",value:1,rarity:"common",color:"#c4b5fd"},{id:"streak_shield2",label:"2 Streak Shields",description:"Double streak protection",icon:"🏰",type:"streak_shield",value:2,rarity:"epic",color:"#3b82f6"},{id:"xp_120",label:"+120 XP Power Surge",description:"Strong XP reward for the day",icon:"⚡",type:"xp",value:120,rarity:"rare",color:"#16a34a"},{id:"hint_x4",label:"4 Hint Tokens",description:"Generous hint pack",icon:"📚",type:"hint_token",value:4,rarity:"rare",color:"#9333ea"}];function zr(t){return kr(Cr,t).slice(0,7).map((i,l)=>({...i,day:l}))}function ds(){return zr(os())}function Mr(){const t=ds(),s=cs();return t[s]}function _r(t){const[s,n]=a.useState({extraHintsEnabled:!1,hintTokens:0,totalHintsAvailable:0,loading:!0});return a.useEffect(()=>{if(!t){n({extraHintsEnabled:!1,hintTokens:0,totalHintsAvailable:0,loading:!1});return}const i=kt(tt,"users",t);return as(i,c=>{if(!c.exists()){n({extraHintsEnabled:!1,hintTokens:0,totalHintsAvailable:0,loading:!1});return}const r=c.data(),d=r?.extraHintsEnabled===!0,x=r?.hintTokens||0,f=d?x+3:x;n({extraHintsEnabled:d,hintTokens:x,totalHintsAvailable:f,loading:!1})},c=>{console.error("[useExtraHints] snapshot error:",c),n({extraHintsEnabled:!1,hintTokens:0,totalHintsAvailable:0,loading:!1})})},[t]),s}const _s=` - @keyframes score-pop { - 0% { transform: scale(1); } - 50% { transform: scale(1.4); } - 100% { transform: scale(1); } - } - @keyframes overlay-slide-up { - 0% { transform: translateY(40px) scale(0.85); opacity: 0; } - 100% { transform: translateY(0) scale(1); opacity: 1; } - } - @keyframes confetti-fall { - 0% { transform: translateY(-10vh) rotate(0deg); opacity: 1; } - 100% { transform: translateY(110vh) rotate(720deg); opacity: 0; } - } - .animate-score-pop { animation: score-pop 0.5s ease-out forwards; } - .animate-overlay-slide-up { animation: overlay-slide-up 0.4s cubic-bezier(0.22, 1, 0.36, 1) forwards; } - .confetti-piece { - position: absolute; - width: 10px; - height: 10px; - animation: confetti-fall linear forwards; - } -`,Ar=({viewportHeight:t})=>e.jsx("div",{className:"absolute inset-0 pointer-events-none z-[250] overflow-hidden flex justify-between bg-slate-900/5",children:je.useMemo(()=>[...Array(40)].map((s,n)=>({id:n,left:`${Math.random()*100}%`,duration:.6+Math.random()*.4,delay:Math.random()*.4})),[t]).map(s=>e.jsx(S.div,{className:"absolute w-0.5 h-16 bg-blue-400/30 rounded-full",style:{left:s.left,top:"-10%"},animate:{y:[0,t*1.2]},transition:{duration:s.duration,ease:"linear",delay:s.delay}},s.id))}),Er=()=>{const t=je.useMemo(()=>[...Array(60)].map((s,n)=>({id:n,left:`${Math.random()*100}%`,backgroundColor:["#75D06A","#6ED1CF","#9956DE","#FB96BB","#FFB356"][n%5],duration:2+Math.random()*2,delay:Math.random()*.5,size:6+Math.random()*8,borderRadius:Math.random()>.5?"50%":"2px"})),[]);return e.jsx("div",{className:"absolute inset-0 pointer-events-none z-[250] overflow-hidden",children:t.map(s=>e.jsx("div",{className:"confetti-piece",style:{left:s.left,top:"-10%",backgroundColor:s.backgroundColor,width:s.size,height:s.size,borderRadius:s.borderRadius,animationDuration:`${s.duration}s`,animationDelay:`${s.delay}s`}},s.id))})},Tr=({viewportHeight:t,viewportWidth:s})=>{const n=je.useMemo(()=>[...Array(30)].map((i,l)=>({id:l,xShift:(Math.random()-.5)*s*.8,yShift:(Math.random()-.5)*t*.8,scale:Math.random()*1.5+.5,duration:2+Math.random()*1.5,delay:Math.random()*.35})),[t,s]);return e.jsx("div",{className:"absolute inset-0 pointer-events-none z-[250] overflow-hidden flex items-center justify-center",children:n.map(i=>e.jsx(S.div,{className:"absolute w-2 h-2 bg-amber-400 rounded-full shadow-[0_0_10px_rgba(251,191,36,0.5)]",style:{left:"50%",top:"50%"},animate:{y:[0,i.yShift],x:[0,i.xShift],scale:[0,i.scale,0],opacity:[0,1,0]},transition:{duration:i.duration,ease:"easeOut",delay:i.delay}},i.id))})},As=({value:t,label:s,delay:n=0,icon:i})=>{const[l,c]=je.useState(0);return je.useEffect(()=>{if(t<=0)return;const r=1e3,d=30,x=Math.abs(Math.floor(r/d));let f=0;const M=setTimeout(()=>{const u=setInterval(()=>{f+=Math.max(1,Math.floor(t/d)),f>=t?(c(t),clearInterval(u)):c(f)},x);return()=>clearInterval(u)},n);return()=>clearTimeout(M)},[t,n]),t<0?null:e.jsxs(S.div,{initial:{opacity:0,transform:"translateX(-20px)"},animate:{opacity:1,transform:"translateX(0)"},transition:{delay:n/1e3,duration:.5},className:"flex items-center justify-between bg-slate-50 border border-slate-100 rounded-xl p-3",children:[e.jsxs("div",{className:"flex items-center gap-3 text-slate-500 font-bold uppercase tracking-wider text-[10px]",children:[i,s]}),e.jsxs("div",{className:"text-xl font-black text-purple-600 tabular-nums",children:["+",l]})]})};function Pr(t){if(t.questionType==="multiple_choice"&&t.options&&t.options.length>0){const s=t.options.findIndex(n=>n.trim().toLowerCase()===t.correctAnswer.trim().toLowerCase());return{id:t.id,question:t.question,options:t.options,correctAnswer:s>=0?s:0,correctAnswerText:t.correctAnswer,explanation:t.explanation,questionType:t.questionType,points:t.points,difficulty:t.difficulty,topic:t.topic,bloomLevel:t.bloomLevel}}return{id:t.id,question:t.question,options:[],correctAnswer:-1,correctAnswerText:t.correctAnswer,explanation:t.explanation,questionType:t.questionType,points:t.points,difficulty:t.difficulty,topic:t.topic,bloomLevel:t.bloomLevel}}function Es(t){return t.replace(/²/g,"^2").replace(/³/g,"^3").replace(/⁻¹/g,"^-1").replace(/⁰/g,"^0").replace(/¹/g,"^1").replace(/⁴/g,"^4").replace(/⁵/g,"^5").replace(/⁶/g,"^6").replace(/⁷/g,"^7").replace(/⁸/g,"^8").replace(/⁹/g,"^9").replace(/π/g,"pi").replace(/√/g,"sqrt").replace(/×/g,"*").replace(/÷/g,"/").replace(/\s+/g,"").toLowerCase().trim()}function Lr(t,s,n){const i=l=>l.trim().toLowerCase().replace(/\s+/g," ");switch(n){case"identification":return i(t)===i(s);case"enumeration":{const l=t.split(",").map(r=>i(r)).filter(Boolean).sort(),c=s.split(",").map(r=>i(r)).filter(Boolean).sort();return JSON.stringify(l)===JSON.stringify(c)}case"word_problem":case"equation_based":{const l=Es(t),c=Es(s);if(l===c)return!0;const r=parseFloat(t.replace(/[^\d.\-]/g,"")),d=parseFloat(s.replace(/[^\d.\-]/g,""));return!isNaN(r)&&!isNaN(d)?Math.abs(r-d)<=.01:i(t)===i(s)}default:return i(t)===i(s)}}const Ys=({quiz:t,onClose:s,onComplete:n,onQuizEnd:i,studentId:l,atRiskSubjects:c=[]})=>{const[r,d]=a.useState(0),[x,f]=a.useState(null),[M,u]=a.useState(""),[N,m]=a.useState(!1),[p,k]=a.useState(!1),[y,W]=a.useState(!1),[j,E]=a.useState(0),[_,D]=a.useState(0),[b,I]=a.useState(1),[B,se]=a.useState([]),[C,re]=a.useState([]),[ge,Oe]=a.useState(Date.now()),[oe,Qe]=a.useState(!1),[Se,G]=a.useState(!1),[ve,We]=a.useState(null),[_e,Ve]=a.useState(0),[$e,Ue]=a.useState(0),[h,A]=a.useState(!1),[T,X]=a.useState(!1),[$,Z]=a.useState(!0),[le,Ae]=a.useState(!1),[fe,be]=a.useState({width:1280,height:720});a.useEffect(()=>{const v=()=>be({width:window.innerWidth,height:window.innerHeight});return v(),window.addEventListener("resize",v),()=>window.removeEventListener("resize",v)},[]);const[Te,F]=a.useState(0),[ee,ue]=a.useState({}),[Be,st]=a.useState(!1),[St,bt]=a.useState(!1),[Ge,Ct]=a.useState(!1),{totalHintsAvailable:Ne}=_r(l||null),[ce,at]=a.useState(5),[rt,ct]=a.useState(15),zt=ce+Ne,[He,Ye]=a.useState(null),[Ke,o]=a.useState(!1),[P,Q]=a.useState(900*1e3),[de,U]=a.useState([]),[q,me]=a.useState(0),[Pe,Ee]=a.useState(null),[xe]=a.useState(()=>t.loadedQuestions&&t.loadedQuestions.length>0?t.loadedQuestions.map(Pr):Array.from({length:t.questions},(v,w)=>({id:`q${w+1}`,question:Ir(t.subject,w),options:Dr(t.subject,w),correctAnswer:Rr(t.subject,w),explanation:Fr(t.subject,w,t.difficulty)})));a.useEffect(()=>{ue({}),U([]),at(5),ct(15),F(0),E(0),D(0),I(1)},[t.id]);const ne=xe[r];a.useEffect(()=>{const v=parseInt(t.duration)||10;Ve(v*60);const w=setInterval(()=>{Ve(V=>V<=1?(clearInterval(w),ke(),0):V-1)},1e3);return()=>clearInterval(w)},[]),a.useEffect(()=>{rt===0&&!He&&(Ye(Date.now()),o(!0))},[rt,He]),a.useEffect(()=>{if(!Ke||!He)return;const v=setInterval(()=>{const w=Date.now()-He,V=Math.max(0,900*1e3-w);Q(V)},1e3);return()=>clearInterval(v)},[Ke,He]);const[Le,gt]=a.useState(Array.from({length:15},(v,w)=>({id:w,size:Math.random()*120+40,x:Math.random()*100,y:Math.random()*100,duration:Math.random()*20+15,delay:Math.random()*-20,color:["bg-purple-500/10","bg-blue-500/10","bg-cyan-500/10","bg-emerald-500/10"][Math.floor(Math.random()*4)]}))),Ze=v=>{if($)try{const w=window.AudioContext||window.webkitAudioContext;if(!w)return;const V=new w,R=V.currentTime,H=(Ce,Ie,ye,ze=.1,we="sine")=>{const pe=V.createOscillator(),mt=V.createGain();pe.type=we,pe.frequency.value=Ce,mt.gain.setValueAtTime(0,Ie),mt.gain.linearRampToValueAtTime(ze,Ie+.05),mt.gain.exponentialRampToValueAtTime(.001,Ie+ye),pe.connect(mt),mt.connect(V.destination),pe.start(Ie),pe.stop(Ie+ye)};v==="correct"?(H(880,R,.1,.1,"sine"),H(1108.73,R+.1,.2,.1,"sine")):v==="incorrect"?(H(300,R,.2,.05,"sawtooth"),H(250,R+.15,.3,.05,"sawtooth")):v==="combo"?(H(440,R,.1,.05,"square"),H(554.37,R+.1,.1,.05,"square"),H(659.25,R+.2,.1,.05,"square"),H(880,R+.3,.4,.05,"square")):v==="complete"&&(H(523.25,R,.1,.1),H(659.25,R+.15,.1,.1),H(783.99,R+.3,.1,.1),H(1046.5,R+.45,.5,.1))}catch{}},ke=()=>{Qe(!0),qt()},Pt=()=>{i?.(t,C),s()},Lt=()=>{if(ce<=0||p)return;const v=ee[r]||[],w=ne.options.filter(R=>R!==ne.correctAnswerText).filter(R=>!v.includes(R));if(w.length===0)return;const V=w[Math.floor(Math.random()*w.length)];ue(R=>({...R,[r]:[...v,V]})),at(R=>Math.max(0,R-1)),Ze("correct")},Mt=v=>{p||L||(f(v),setTimeout(()=>{dt(v)},150))},dt=v=>{const w=ne.questionType!=null&&ne.questionType!=="multiple_choice",V=v!==void 0?v:x;if(w){if(!M.trim())return}else if(V===null)return;const R=w?Lr(M,ne.correctAnswerText||"",ne.questionType||""):V===ne.correctAnswer,H=w?M:String(V),Ce=Math.round((Date.now()-ge)/1e3);re(pe=>[...pe,{questionId:ne.id,answer:H,correct:R,timeSpent:Ce}]);const Ie=[...B];if(Ie[r]=R?1:0,se(Ie),m(R),k(!0),!R){bt(!0),Ze("incorrect"),setTimeout(()=>bt(!1),500),ct(pe=>Math.max(0,pe-1)),D(0),I(1),setTimeout(()=>{nt()},1500);return}Ze("correct");const ze=(ee[r]||[]).length>0?5:10;F(pe=>pe+ze),E(j+1);const we=_+1;D(we),we===2?Ee("streak"):we===3&&b<2?Ee("multiplier2"):we===5&&b<3&&Ee("multiplier3"),we>0&&we%3===0&&Ze("combo"),we>=5?I(3):we>=3?I(2):I(1),Ft(()=>import("./confetti.module-C94ZD2ww.js"),[]).then(pe=>{pe.default({particleCount:30,spread:40,colors:["#75D06A","#6ED1CF"],origin:{y:.6}})}),Ct(!0),setTimeout(()=>{Ct(!1),Ee(null),setTimeout(()=>nt(),300)},1500)},nt=()=>{if(r{const v=Math.round(j/xe.length*100);let w=t.xpReward;v>=90?w=Math.round(w*1.5):v>=80&&(w=Math.round(w*1.25));const V=parseInt(t.duration)*60;_e>V*.5&&(w=Math.round(w*1.2)),Ue(w);const R=V-_e;l&&Sa({lrn:l,quizId:t.id,subject:t.subject,score:v,totalQuestions:xe.length,correctAnswers:j,timeSpentSeconds:R}).catch(H=>console.error("[WARN] Automation: quiz pipeline failed:",H)),t.source==="ai_generated"&&l?Ca(l,t.id,t.generatedQuizId,t.subject,t.source,v,w,R,C,xe.map(H=>({topic:H.topic||t.subject,difficulty:H.difficulty||"medium",bloomLevel:H.bloomLevel||"understand"}))).catch(H=>console.error("[WARN] Quiz result save failed:",H)):l&&ca(l,t.id,t.subject,v,C.map(H=>({questionId:H.questionId,selectedAnswer:H.answer,isCorrect:H.correct})),R).catch(H=>console.error("[WARN] Practice quiz persist failed:",H)),l&&Ft(async()=>{const{saveAssessmentResult:H}=await import("./index-BufUS6SI.js").then(Ce=>Ce.ba);return{saveAssessmentResult:H}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11])).then(({saveAssessmentResult:H})=>{H({uid:l,testId:t.id,title:t.title||t.id,subject:t.subject||"General Mathematics",type:t.source==="ai_generated"?"quiz":"practice",score:v,totalQuestions:xe.length,risk:v<60?"High":"Low",intervention:"",xpEarned:w,badgeUnlocked:""}).catch(Ce=>console.error("[WARN] Assessment record save failed:",Ce))}),Ze("complete"),n?.(v,w)},L=q{document.fullscreenElement?(document.exitFullscreen().catch(()=>{}),Ae(!1)):(document.documentElement.requestFullscreen().catch(()=>{}),Ae(!0))};if(oe){const v=Math.round(j/xe.length*100),w=v>=80,V=v>=50&&v<80,R=v<50,H=document.getElementById("modal-root"),Ce=e.jsxs("div",{className:"fixed inset-0 z-[200] flex items-center justify-center p-4 bg-slate-900/50 backdrop-blur-sm",children:[e.jsx("style",{children:_s}),w&&e.jsx(Er,{}),V&&e.jsx(Tr,{viewportHeight:fe.height,viewportWidth:fe.width}),R&&e.jsx(Ar,{viewportHeight:fe.height}),e.jsxs(S.div,{initial:{opacity:0,scale:.8,y:40},animate:{opacity:1,scale:1,y:0},transition:{type:"spring",damping:18,stiffness:200},className:"w-full max-w-xs sm:max-w-sm bg-white border-2 border-slate-200 shadow-[0_25px_60px_rgba(0,0,0,0.15)] rounded-[2rem] p-4 sm:p-5 text-center relative z-10",children:[e.jsx(S.div,{initial:{scale:0,rotate:-180},animate:{scale:1,rotate:0},transition:{type:"spring",damping:12,stiffness:150,delay:.2},className:"mb-3",children:e.jsx("img",{src:"/mascot/modules_avatar.png",alt:"Mascot",className:"w-16 h-16 sm:w-20 sm:h-20 mx-auto drop-shadow-xl animate-mascot-float"})}),e.jsx(S.h2,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:.3},className:`text-xl sm:text-2xl font-black uppercase tracking-tight mb-1 drop-shadow-sm ${w?"text-emerald-500":V?"text-amber-500":"text-rose-500"}`,children:w?"EXCELLENT!":V?"GOOD JOB!":"KEEP TRYING!"}),e.jsxs("p",{className:"text-slate-400 font-bold text-[10px] mb-3 uppercase tracking-widest",children:["Quiz Complete • Score: ",j,"/",xe.length]}),e.jsx(S.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.4},className:"bg-slate-50/50 rounded-xl p-3 mb-4 border border-slate-100 flex flex-col gap-2",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-slate-400 text-[9px] font-black uppercase tracking-widest text-left mb-1.5 ml-1",children:"Performance Details"}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(As,{value:j,label:"Correct Answers",delay:500,icon:e.jsx(Rt,{className:"h-3 w-3 text-emerald-500"})}),e.jsx(As,{value:$e,label:"Total XP Earned",delay:800,icon:e.jsx(Xe,{className:"h-3 w-3 text-amber-500"})}),e.jsxs(S.div,{initial:{opacity:0},animate:{opacity:1},transition:{delay:1.2,duration:.4},className:"flex items-center justify-between pt-1.5 mt-1 border-t border-slate-100",children:[e.jsx("span",{className:"text-slate-400 text-[9px] font-black uppercase tracking-widest",children:"Final Accuracy"}),e.jsxs("span",{className:"text-lg font-black text-slate-800 tabular-nums",children:[v,"%"]})]})]})]})}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(Me,{size:"lg",onClick:()=>{d(0),me(0),f(null),u(""),E(0),D(0),I(1),se([]),re([]),F(0),Qe(!1),k(!1),W(!1),Oe(Date.now()),ue({}),U([]),st(!1),at(5),G(!1)},className:"w-full h-10 sm:h-11 rounded-2xl text-xs font-black bg-white hover:bg-slate-50 text-purple-600 border-2 border-purple-100",children:"RETAKE QUIZ"}),e.jsx(Me,{size:"lg",onClick:s,className:"w-full h-10 sm:h-11 rounded-2xl text-xs font-black bg-purple-600 hover:bg-purple-700 text-white shadow-lg shadow-purple-200",children:"FINISH"})]})]})]});return vt.createPortal(Ce,H)}return e.jsxs(e.Fragment,{children:[e.jsx("style",{children:_s}),h&&vt.createPortal(e.jsx(S.div,{initial:{opacity:0,x:20},animate:{opacity:1,x:0},exit:{opacity:0,x:20},className:"fixed right-6 top-1/2 -translate-y-1/2 z-[9999] w-64",children:e.jsxs("div",{className:"bg-white rounded-2xl p-3 border border-slate-200 shadow-[0_10px_40px_rgba(0,0,0,0.3)]",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2 px-1",children:[e.jsxs("h4",{className:"text-xs font-bold text-[#0a1628] flex items-center gap-2",children:[e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-purple-600",children:[e.jsx("rect",{x:"4",y:"2",width:"16",height:"20",rx:"2"}),e.jsx("line",{x1:"8",x2:"16",y1:"6",y2:"6"})]}),"Calculator"]}),e.jsx("button",{onClick:()=>A(!1),className:"w-6 h-6 rounded-full bg-slate-100 flex items-center justify-center text-slate-500 hover:text-slate-800 hover:bg-slate-200 transition-colors",children:e.jsx(Je,{size:12})})]}),e.jsx(Ws,{isOpen:!0,onClose:()=>A(!1),inline:!0})]})}),document.getElementById("modal-root")),Ke&&vt.createPortal(e.jsx("div",{className:"fixed inset-0 z-[200] flex items-center justify-center p-4 bg-slate-900/50",children:e.jsxs(S.div,{initial:{scale:.9,opacity:0},animate:{scale:1,opacity:1},className:"bg-white rounded-[2rem] p-6 max-w-xs w-full text-center border-2 border-rose-200 shadow-[0_25px_60px_rgba(0,0,0,0.15)]",children:[e.jsx(S.div,{animate:{scale:[1,1.1,1]},transition:{duration:1,repeat:1/0},className:"text-6xl mb-4",children:e.jsx(Vs,{className:"w-10 h-10 text-rose-500"})}),e.jsx("h2",{className:"text-2xl font-black text-slate-800 mb-3",children:"Out of Lives!"}),e.jsx("p",{className:"text-slate-500 text-sm mb-4",children:"Your hearts have run out. You can wait for them to refill or head back and review your lessons in the meantime."}),e.jsxs("div",{className:"flex items-center justify-center gap-2 mb-2 text-rose-500 font-bold",children:[e.jsx("img",{src:"/icons/quiz_heart.png",alt:"Hearts",className:"w-5 h-5"}),e.jsx("span",{children:"0 / 15 hearts"})]}),e.jsxs("p",{className:"text-slate-400 text-xs mb-4",children:["Next heart in: ",e.jsxs("span",{className:"font-bold text-slate-600",children:[Math.floor(P/6e4),":",Math.floor(P%6e4/1e3).toString().padStart(2,"0")]})," (15 minutes per heart)"]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(Me,{onClick:Pt,className:"w-full py-3 bg-rose-500 hover:bg-rose-600 text-white font-bold rounded-full",children:"Exit Quiz"}),e.jsx(Me,{onClick:()=>{o(!1)},className:"w-full py-3 bg-slate-100 hover:bg-slate-200 text-slate-700 font-bold rounded-full",children:"Review Lessons"})]})]})}),document.getElementById("modal-root")),e.jsx(ot,{children:Ge&&N&&e.jsx(S.div,{initial:{opacity:0,scale:.8,y:20},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:1.1,filter:"blur(10px)"},transition:{type:"spring",damping:20,stiffness:300},className:"fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 z-[200] pointer-events-none flex flex-col items-center justify-center",children:e.jsxs("div",{className:"bg-white/95 backdrop-blur-xl border border-slate-200 rounded-[2rem] p-6 md:p-8 shadow-[0_30px_80px_rgba(0,0,0,0.15)] flex flex-col items-center min-w-[280px] md:min-w-[320px]",children:[e.jsx("img",{src:"/mascot/modules_avatar.png",alt:"Mascot",className:"w-24 h-24 md:w-32 md:h-32 mb-4 drop-shadow-[0_10px_20px_rgba(0,0,0,0.15)]"}),e.jsx("h2",{className:"text-3xl md:text-4xl font-black mb-4 uppercase tracking-widest text-emerald-500",children:"Correct!"}),e.jsxs("div",{className:"flex flex-col items-center gap-3 w-full justify-center",children:[e.jsx("div",{className:"flex items-center gap-2 bg-emerald-500/20 text-emerald-400 px-4 py-2 rounded-full font-bold border border-emerald-500/30",children:e.jsxs("span",{children:["+ ",(ee[r]||[]).length>0?5:10," XP"]})}),Pe==="streak"&&e.jsxs("div",{className:"flex items-center gap-2 bg-orange-500/20 text-orange-400 px-4 py-1.5 rounded-full text-sm font-bold border border-orange-500/30",children:[e.jsx(rs,{size:14})," Streak Started!"]}),Pe==="multiplier2"&&e.jsxs("div",{className:"flex items-center gap-2 bg-amber-500/20 text-amber-400 px-4 py-1.5 rounded-full text-sm font-bold border border-amber-500/30",children:[e.jsx(Xe,{size:14})," Multiplier ×2!"]}),Pe==="multiplier3"&&e.jsxs("div",{className:"flex items-center gap-2 bg-amber-500/20 text-amber-400 px-4 py-1.5 rounded-full text-sm font-bold border border-amber-500/30",children:[e.jsx(Xe,{size:14})," Multiplier ×3!"]})]})]})},"round-result")}),e.jsxs("div",{className:"fixed inset-0 z-[100] h-screen w-full flex flex-col bg-slate-50 overflow-hidden",children:[e.jsxs("header",{className:"relative shrink-0 flex flex-col items-center justify-start px-4 pt-4 sm:pt-6 pb-6 z-[60] shadow-md overflow-hidden bg-gradient-to-r from-purple-600 to-indigo-400 rounded-b-[32px] sm:rounded-b-[40px] min-h-[110px] sm:min-h-[130px]",children:[e.jsxs("div",{className:"absolute inset-0 z-0 pointer-events-none",children:[e.jsx("div",{className:"absolute top-0 left-0 w-64 h-64 bg-white opacity-10 rounded-full -translate-x-1/2 -translate-y-1/2 blur-2xl"}),e.jsx("div",{className:"absolute bottom-0 right-0 w-80 h-80 bg-white opacity-10 rounded-full translate-x-1/3 translate-y-1/3 blur-3xl"})]}),e.jsxs("div",{className:"w-full max-w-7xl flex items-center justify-between relative z-10 mb-3 sm:mb-4 md:mb-6",children:[e.jsx("div",{className:"flex-1 flex items-center gap-1 sm:gap-2",children:e.jsxs("div",{className:"flex items-center gap-1 bg-white/20 px-2 py-1 sm:px-3 sm:py-1.5 rounded-full text-white text-xs sm:text-sm font-bold",children:[e.jsx(Nt,{size:14,className:"shrink-0"})," ",$r(_e)]})}),e.jsxs("div",{className:"relative flex items-center justify-center bg-purple-900/40 backdrop-blur-md px-2 sm:px-5 md:px-8 py-2 sm:py-3 rounded-full border border-white/10 gap-1.5 sm:gap-3 md:gap-4 shadow-inner",children:[e.jsx("div",{className:"hidden sm:block w-3 h-3 md:w-4 md:h-4 rounded-full bg-yellow-400 shrink-0 shadow-[0_0_10px_rgba(250,204,21,0.6)]"}),e.jsxs("div",{className:"flex flex-col items-start justify-center",children:[e.jsx("span",{className:"hidden sm:block text-[9px] md:text-[11px] font-black text-purple-200 uppercase tracking-widest leading-none mb-0.5",children:"Try It Yourself!"}),e.jsx("span",{className:"font-bold text-white tracking-wide text-xs sm:text-sm md:text-lg leading-none truncate max-w-[90px] sm:max-w-[180px] md:max-w-[300px]",children:t.title||t.subject})]})]}),e.jsxs("div",{className:"flex-1 flex justify-end gap-1 sm:gap-2 md:gap-3 relative pointer-events-auto",children:[e.jsxs("button",{onClick:()=>Z(!$),className:"w-8 h-8 sm:w-10 sm:h-10 md:w-12 md:h-12 rounded-full bg-purple-900/20 text-white flex items-center justify-center hover:bg-purple-900/40 transition-colors shadow-sm border border-white/10",children:[$?e.jsx(es,{size:16,className:"sm:hidden"}):e.jsx(ts,{size:16,className:"sm:hidden"}),$?e.jsx(es,{size:20,className:"hidden sm:block"}):e.jsx(ts,{size:20,className:"hidden sm:block"})]}),e.jsx("button",{onClick:Ot,className:"hidden sm:flex w-10 h-10 md:w-12 md:h-12 rounded-full bg-purple-900/20 text-white items-center justify-center hover:bg-purple-900/40 transition-colors shadow-sm border border-white/10",children:le?e.jsx(Us,{size:20}):e.jsx(Gs,{size:20})}),e.jsxs("button",{onClick:()=>X(!0),className:"w-8 h-8 sm:w-10 sm:h-10 md:w-12 md:h-12 rounded-full bg-purple-900/20 text-white flex items-center justify-center hover:bg-purple-900/40 transition-colors shadow-sm border border-white/10",children:[e.jsx(Je,{size:18,className:"sm:hidden"}),e.jsx(Je,{size:20,className:"hidden sm:block"})]})]})]}),e.jsx("div",{className:"w-full max-w-[50rem] flex items-center justify-center px-4 z-10",children:e.jsx("div",{className:"w-full flex items-center gap-2 sm:gap-3",children:xe.map((v,w)=>{let V=w<=r?"bg-white shadow-[0_0_8px_rgba(255,255,255,0.8)]":"bg-white/20";return e.jsx("div",{className:`h-1.5 sm:h-2 rounded-full flex-1 transition-all ${V}`},w)})})})]}),e.jsxs("div",{className:"w-full max-w-[54rem] mx-auto shrink-0 flex items-center justify-between px-2 sm:px-4 md:px-6 py-2 sm:py-3 z-[50] relative mt-4 sm:mt-6 md:mt-8",children:[e.jsxs("button",{onClick:()=>me(v=>Math.max(0,v-1)),disabled:q===0,className:`w-8 h-8 sm:w-10 sm:h-10 md:w-12 md:h-12 shrink-0 rounded-full flex items-center justify-center shadow-md border-2 transition-all ${q===0?"bg-slate-100 text-slate-400 border-slate-200 cursor-not-allowed":"bg-white text-purple-600 border-purple-100 hover:bg-purple-50 hover:border-purple-200 hover:scale-105 active:scale-95"}`,children:[e.jsx(ss,{size:18,className:"sm:hidden"}),e.jsx(ss,{size:24,className:"hidden sm:block"})]}),e.jsxs("div",{className:"flex items-center justify-center gap-1.5 sm:gap-3 md:gap-5 flex-1 mx-1 sm:mx-2",children:[e.jsxs("div",{className:"flex items-center gap-1 sm:gap-2 md:gap-3 px-2.5 sm:px-5 md:px-10 py-1.5 sm:py-2 rounded-full bg-white shadow-md border border-slate-200/60 text-rose-500 font-extrabold text-xs sm:text-sm md:text-base",children:[e.jsx("img",{src:"/icons/quiz_heart.png",alt:"Hearts",className:"w-4 h-4 sm:w-5 sm:h-5 object-contain"})," ",rt]}),e.jsxs("div",{className:"flex items-center gap-1 sm:gap-2 md:gap-3 px-2.5 sm:px-5 md:px-10 py-1.5 sm:py-2 rounded-full bg-white shadow-md border border-slate-200/60 text-yellow-500 font-extrabold text-xs sm:text-sm md:text-base",children:[e.jsx("img",{src:"/icons/quiz_key.png",alt:"Keys",className:"w-4 h-4 sm:w-5 sm:h-5 object-contain"})," ",ce]}),e.jsxs("div",{className:"flex items-center gap-1.5 sm:gap-3 md:gap-4 px-2 sm:px-3 py-1 sm:py-1.5 pl-2.5 sm:pl-4 md:pl-6 rounded-full bg-white shadow-md border border-slate-200/60",children:[e.jsxs("div",{className:"flex items-center gap-1 sm:gap-1.5 text-orange-500 font-extrabold text-xs sm:text-sm md:text-base",children:[e.jsx("img",{src:"/icons/quiz_streak.png",alt:"Streak",className:"w-4 h-4 sm:w-5 sm:h-5 object-contain"})," ",_]}),e.jsxs("div",{className:"bg-emerald-100 text-emerald-800 px-2 sm:px-3 md:px-4 py-1 sm:py-1.5 rounded-full font-bold text-xs sm:text-sm md:text-base shadow-inner border border-emerald-200/50 whitespace-nowrap",children:["+ ",Te," pts"]})]})]}),e.jsxs("button",{onClick:()=>me(v=>Math.min(r,v+1)),disabled:q>=r,className:`w-8 h-8 sm:w-10 sm:h-10 md:w-12 md:h-12 shrink-0 rounded-full flex items-center justify-center shadow-md border-2 transition-all ${q>=r?"bg-slate-100 text-slate-400 border-slate-200 cursor-not-allowed":"bg-white text-purple-600 border-purple-100 hover:bg-purple-50 hover:border-purple-200 hover:scale-105 active:scale-95"}`,children:[e.jsx(it,{size:18,className:"sm:hidden"}),e.jsx(it,{size:24,className:"hidden sm:block"})]})]}),e.jsx("main",{className:"flex-1 overflow-y-auto w-full px-4 sm:px-6 pt-0 pb-6 flex flex-col items-center relative z-10",children:e.jsxs(S.div,{initial:{opacity:0,x:20},animate:St?{x:[-10,10,-10,10,0],scale:[1,1.01,1],opacity:1}:{opacity:1,x:0},className:"w-full max-w-3xl flex flex-col mt-2",children:[e.jsxs("div",{className:"bg-white rounded-3xl shadow-lg border-t-[6px] border-purple-500 p-4 sm:p-6 md:p-8 text-center flex flex-col items-center mb-4 sm:mb-6 w-full relative overflow-hidden",children:[e.jsxs("div",{className:"bg-slate-100 text-slate-600 px-3 sm:px-4 py-1 sm:py-1.5 rounded-full text-[10px] sm:text-[11px] md:text-xs font-black uppercase tracking-widest mb-3 sm:mb-4 flex items-center shadow-sm",children:["Q",q+1," of ",xe.length]}),e.jsx("h2",{className:"text-base sm:text-xl md:text-2xl font-extrabold text-[#0a1628] leading-tight w-full",children:J.question.includes("___")?e.jsx("span",{children:J.question.split("___").map((v,w,V)=>e.jsxs(je.Fragment,{children:[v,wu(R.target.value),onKeyDown:R=>{R.key==="Enter"&&!p&&dt()},className:`inline-block w-24 mx-2 border-b-4 outline-none text-center bg-transparent font-bold ${L?"border-slate-300 text-slate-500":"border-[#7C3AED] text-[#7C3AED] focus:border-[#75D06A]"}`})]},w))}):J.question})]}),e.jsxs("div",{className:"w-full flex flex-col items-center",children:[J.questionType==="multiple_choice"||!J.questionType?e.jsx("div",{className:"w-full grid grid-cols-1 sm:grid-cols-2 gap-2.5 sm:gap-3 md:gap-5",children:(J.options||[]).map((v,w)=>{const V=ee[r]||[],R=V.includes(v),H=V.length,Ce=(J.options||[]).length-1,Ie=Ce>0&&H>=Ce;let ye="bg-white hover:bg-slate-50 border-transparent text-slate-700 hover:border-slate-200",ze=!1;if(Ie){ze=!0;const we=J.options?.[J.correctAnswer];v===we?ye="bg-emerald-50 border-emerald-400 text-emerald-800":C[q]?.answer===String(w)?ye="bg-rose-50 border-rose-400 text-rose-800 opacity-80":ye="bg-slate-100 border-slate-200 text-slate-400 opacity-40 line-through"}else if(R)ye="bg-slate-100 border-slate-200 text-slate-400 opacity-40 line-through cursor-not-allowed";else if(L){const we=w===J.correctAnswer,pe=q===r&&(x===w||ve===w)||q{ze||L||R||Mt(w)},className:`p-3 sm:p-4 md:p-5 rounded-2xl shadow-sm border-[3px] font-extrabold text-sm sm:text-base md:text-lg text-left transition-all flex items-center justify-between ${ye} ${ze||L||R?"cursor-default":"hover:shadow-md hover:-translate-y-0.5 active:translate-y-0"}`,children:[e.jsx("span",{className:"truncate pr-4",children:v}),R&&e.jsx(Ut,{size:20,className:"text-slate-400 shrink-0"}),L&&w===J.correctAnswer&&e.jsx(ft,{size:22,className:"text-emerald-500 shrink-0"}),L&&x===w&&w!==J.correctAnswer&&e.jsx(Ut,{size:22,className:"text-rose-500 shrink-0"})]},w)})}):e.jsx("div",{className:"w-full max-w-2xl mx-auto flex flex-col gap-4",children:!J.question.includes("___")&&e.jsx("input",{type:"text",disabled:L,value:q===r?M:"",onChange:v=>u(v.target.value),onKeyDown:v=>{v.key==="Enter"&&!p&&dt()},placeholder:"Type your answer here...",className:`w-full p-3 sm:p-4 md:p-5 rounded-2xl border-[3px] font-extrabold text-base sm:text-lg text-center outline-none transition-colors ${L?N?"border-emerald-400 text-emerald-700 bg-emerald-50":"border-rose-400 text-rose-700 bg-rose-50":"border-slate-200 focus:border-[#7C3AED] bg-white text-slate-800"}`})}),L&&y&&e.jsxs("div",{className:"w-full max-w-3xl mt-6 flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-bold text-[#0a1628]",children:J.topic||t?.subject||"General Math"}),e.jsxs("p",{className:"text-sm text-slate-500",children:["Question ",q+1," Explanation"]})]}),e.jsx("img",{src:"/icons/default-module-avatar.png",alt:"Module Avatar",className:"w-12 h-12 rounded-full object-cover border-2 border-slate-200"})]}),L&&y&&e.jsx(S.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:"w-full mt-4 space-y-4 max-w-3xl",children:e.jsxs("div",{className:`border-2 rounded-2xl p-5 flex items-start gap-4 ${(q===r?N:C[q]?.correct)?"bg-emerald-50 border-emerald-200":"bg-rose-50 border-rose-200"}`,children:[(q===r?N:C[q]?.correct)?e.jsx(ft,{size:28,className:"text-emerald-500 shrink-0 mt-0.5"}):e.jsx(Ut,{size:28,className:"text-rose-500 shrink-0 mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{className:`font-extrabold text-lg mb-1 ${(q===r?N:C[q]?.correct)?"text-emerald-700":"text-rose-700"}`,children:(q===r?N:C[q]?.correct)?"Correct!":"Incorrect"}),e.jsx("p",{className:`text-base leading-relaxed ${(q===r?N:C[q]?.correct)?"text-emerald-800":"text-rose-800"}`,children:J.explanation||`Correct Answer: ${J.correctAnswerText||J.options?.[J.correctAnswer]}`})]})]})})]})]},q)}),e.jsx("footer",{className:"shrink-0 relative z-[60] flex flex-col items-center justify-center p-4 sm:p-6 bg-gradient-to-r from-purple-600 to-indigo-400 rounded-t-[32px] sm:rounded-t-[40px] shadow-[0_-10px_40px_rgba(0,0,0,0.15)]",children:(()=>{const v=(ee[r]||[]).length,w=(ne.options||[]).length-1,V=w>0&&v>=w;return V||L&&!N?e.jsxs("button",{onClick:nt,className:"bg-orange-500 hover:bg-orange-600 text-white font-extrabold text-sm sm:text-base md:text-lg px-5 sm:px-8 py-3 sm:py-4 rounded-full flex items-center justify-center gap-2 sm:gap-3 shadow-xl hover:scale-[1.02] active:scale-[0.98] transition-all w-full max-w-md mx-auto",children:[r{const H=zt>0&&!p&&!V;return e.jsxs("button",{onClick:Lt,disabled:!H,className:"bg-white hover:bg-slate-50 disabled:opacity-70 disabled:cursor-not-allowed text-slate-700 font-bold px-4 sm:px-6 md:px-8 py-2.5 sm:py-3 md:py-3.5 rounded-full flex items-center gap-1.5 sm:gap-2 text-sm sm:text-base shadow-lg transition-transform hover:scale-105 active:scale-95 border border-slate-200",children:[e.jsx("img",{src:"/icons/quiz_key.png",alt:"Key",className:"w-4 h-4 sm:w-5 sm:h-5 object-contain"})," Hint"]})})(),L&&e.jsxs("button",{onClick:()=>W(!0),className:"bg-white hover:bg-slate-50 text-slate-700 font-bold px-4 sm:px-6 md:px-8 py-2.5 sm:py-3 md:py-3.5 rounded-full flex items-center gap-1.5 sm:gap-2 text-sm sm:text-base shadow-lg transition-transform hover:scale-105 active:scale-95 border border-slate-200",children:[e.jsx(Fe,{size:16,className:"sm:hidden"}),e.jsx(Fe,{size:20,className:"hidden sm:block"})," Explain"]}),e.jsx("button",{onClick:()=>A(H=>!H),className:`w-11 h-11 sm:w-12 sm:h-12 rounded-full flex items-center justify-center shadow-lg transition-transform hover:scale-105 active:scale-95 border border-slate-200 ${h?"bg-purple-100 text-purple-600 border-purple-300":"bg-white hover:bg-slate-50 text-slate-700"}`,children:e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"4",y:"2",width:"16",height:"20",rx:"2"}),e.jsx("line",{x1:"8",x2:"16",y1:"6",y2:"6"}),e.jsx("path",{d:"M16 10h.01"}),e.jsx("path",{d:"M12 10h.01"}),e.jsx("path",{d:"M8 10h.01"}),e.jsx("path",{d:"M12 14h.01"}),e.jsx("path",{d:"M8 14h.01"}),e.jsx("path",{d:"M12 18h.01"}),e.jsx("path",{d:"M8 18h.01"}),e.jsx("line",{x1:"16",x2:"16",y1:"14",y2:"18"})]})})]}):qme(r),className:"bg-white text-slate-700 font-extrabold text-sm sm:text-base md:text-lg px-4 sm:px-6 md:px-8 py-2.5 sm:py-3 md:py-4 rounded-full inline-flex items-center gap-1.5 sm:gap-2 md:gap-3 shadow-lg hover:bg-slate-50 transition-transform hover:scale-105 active:scale-95 border border-slate-200",children:[e.jsx(it,{size:16,className:"sm:hidden"}),e.jsx(it,{size:20,className:"hidden sm:block"}),"Back to Current Question"]}):null})()})]}),T&&e.jsx("div",{className:"fixed inset-0 z-[300] flex items-center justify-center p-4 bg-black/50 backdrop-blur-sm",children:e.jsxs(S.div,{initial:{scale:.9,opacity:0},animate:{scale:1,opacity:1},className:"bg-white rounded-2xl p-6 w-full max-w-[320px] shadow-2xl border border-slate-200 flex flex-col items-center gap-4",children:[e.jsx("h3",{className:"text-lg font-bold text-slate-900 text-center",children:"Leave this quiz?"}),e.jsx("p",{className:"text-sm text-slate-500 text-center",children:"Your progress will be reset and you'll need to start over."}),e.jsxs("div",{className:"w-full flex flex-col gap-2",children:[e.jsx("button",{onClick:()=>X(!1),className:"w-full py-3 bg-[#9956DE] hover:bg-[#8544c7] text-white font-bold rounded-full transition-colors",children:"Stay"}),e.jsx("button",{onClick:()=>{X(!1),s()},className:"w-full py-3 bg-slate-100 hover:bg-slate-200 text-slate-700 font-bold rounded-full transition-colors",children:"Leave Quiz"})]})]})})]})};function Ir(t,s){const n={"Pre-Calculus":["What is the domain of the function f(x) = √(x - 2)?","Solve for x: 2^x = 16","What is the period of the function y = sin(2x)?","Find the inverse of f(x) = 3x + 5","What is the value of log₂(32)?","Simplify: (x² - 9) / (x - 3)","What is the range of f(x) = |x| - 3?","If f(x) = 2x + 1 and g(x) = x², find f(g(2)).","What is the amplitude of y = 3cos(x)?","Solve: log₃(x) = 4"],"General Mathematics":["Simplify: (2x + 3)(x - 4)","What is 15% of 240?","Solve: 3x + 7 = 22","What is the value of 5! (5 factorial)?","Convert 0.75 to a fraction","What is 25% of 360?","Simplify: 12/18","What is the GCD of 24 and 36?","Convert 3/8 to a decimal","If a shirt costs $40 and is 20% off, what is the sale price?","What is 2/3 + 1/4?","Calculate: 15% tip on a $80 bill","Simplify: 45/60","What fraction is equivalent to 0.125?","If 30% of a number is 45, what is the number?"],"Statistics and Probability":["What is the probability of rolling a 6 on a fair die?","Calculate the mean of: 4, 7, 9, 12, 15","What is the median of: 2, 5, 8, 11, 14?","In a bag with 5 red and 3 blue balls, what is P(red)?","What is the range of: 10, 15, 20, 25, 30?","What is the mode of: 3, 5, 5, 7, 8, 5, 9?","What is the standard deviation concept?","P(A) = 0.3, P(B) = 0.5, events independent. P(A and B) = ?","What is the median of: 4, 7, 10, 13?","How many ways can you arrange 3 books?"],"Basic Calculus":["Find the derivative of f(x) = 3x²","What is the limit of (x² - 4)/(x - 2) as x → 2?","Integrate: ∫ 2x dx","Find f'(x) if f(x) = 5x³ - 2x","What is the derivative of sin(x)?","Find the derivative of f(x) = eˣ + 3x","What is ∫ cos(x) dx?","Find the derivative of f(x) = ln(x)","What is the limit of 1/x as x → ∞?","Find f'(x) if f(x) = x⁴ - 2x² + 1"]},i=Ht(t),l=n[i]||n["General Mathematics"];return l[s%l.length]}function Ht(t){const s=t.toLowerCase();return s.includes("pre-calc")||s.includes("pre calc")||s.includes("precalc")?"Pre-Calculus":s.includes("statistic")||s.includes("probability")?"Statistics and Probability":s.includes("calculus")&&!s.includes("pre")?"Basic Calculus":s.includes("general")||s.includes("math")||s.includes("algebra")||s.includes("fraction")||s.includes("percent")||s.includes("ratio")||s.includes("geometry")?"General Mathematics":s.includes("derivative")||s.includes("integral")||s.includes("limit")?"Basic Calculus":s.includes("trig")||s.includes("function")||s.includes("log")?"Pre-Calculus":s.includes("mean")||s.includes("median")||s.includes("data")?"Statistics and Probability":"General Mathematics"}function Dr(t,s){const n={"Pre-Calculus":[["x ≥ 2","x ≤ 2","x ≥ 0","All real numbers"],["x = 2","x = 4","x = 8","x = 16"],["π","2π","π/2","4π"],["f⁻¹(x) = (x - 5)/3","f⁻¹(x) = 3x - 5","f⁻¹(x) = x/3 - 5","f⁻¹(x) = (x + 5)/3"],["4","5","6","7"],["x + 3","x - 3","x² + 3","(x + 3)(x - 3)"],["y ≥ -3","y ≥ 0","All real numbers","y > -3"],["9","5","7","3"],["1","2","3","1/3"],["12","27","64","81"]],"General Mathematics":[["2x² - 5x - 12","2x² + 5x - 12","2x² - 8x + 12","2x² - 5x + 12"],["36","32","28","24"],["x = 5","x = 4","x = 6","x = 7"],["120","24","60","720"],["3/4","1/2","2/3","4/5"],["90","80","100","72"],["2/3","3/4","4/6","6/9"],["12","6","8","4"],["0.375","0.38","0.35","0.325"],["$32","$28","$30","$36"],["11/12","3/7","5/6","2/3"],["$12","$10","$15","$8"],["3/4","2/3","4/5","9/12"],["1/8","1/4","1/5","1/6"],["150","135","120","160"]],"Statistics and Probability":[["1/6","1/3","1/2","2/3"],["9.4","8.5","10.2","7.8"],["8","9","7","10"],["5/8","3/8","1/2","2/5"],["20","15","25","30"],["5","3","7","8"],["Spread of data from the mean","The highest value","The average","The middle value"],["0.15","0.8","0.35","0.2"],["8.5","7","10","9"],["6","3","9","12"]],"Basic Calculus":[["6x","3x","9x²","6x²"],["4","2","0","undefined"],["x² + C","2x² + C","x²/2 + C","2x + C"],["15x² - 2","15x² - 2x","5x² - 2","15x - 2"],["cos(x)","-cos(x)","tan(x)","-sin(x)"],["eˣ + 3","eˣ + 3x","xeˣ + 3","eˣ"],["sin(x) + C","-sin(x) + C","tan(x) + C","-cos(x) + C"],["1/x","x","ln(x)","-1/x²"],["0","1","∞","undefined"],["4x³ - 4x","4x³ - 2x","x³ - 4x","4x⁴ - 4x²"]]},i=Ht(t),l=n[i]||n["General Mathematics"];return l[s%l.length]}function Rr(t,s){const n={"Pre-Calculus":[0,1,0,0,1,0,0,0,2,3],"General Mathematics":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"Statistics and Probability":[0,0,0,0,0,0,0,0,0,0],"Basic Calculus":[0,0,0,0,0,0,0,0,0,0]},i=Ht(t),l=n[i]||n["General Mathematics"];return l[s%l.length]}function Fr(t,s,n){const i={"Pre-Calculus":["The expression under the square root must be non-negative: x - 2 ≥ 0, so x ≥ 2.","Since 2⁴ = 16, we get x = 4.","The period of sin(kx) is 2π/k. Here k = 2, so period = 2π/2 = π.","To find the inverse: y = 3x + 5 → x = 3y + 5 → y = (x - 5)/3.","Since 2⁵ = 32, log₂(32) = 5.","(x² - 9)/(x - 3) = (x+3)(x-3)/(x-3) = x + 3 (for x ≠ 3).","The absolute value |x| ≥ 0 for all x, so |x| - 3 ≥ -3. The range is y ≥ -3.","g(2) = 4, then f(4) = 2(4) + 1 = 9.","The amplitude of y = Acos(x) is |A|. Here A = 3, so amplitude = 3.","log₃(x) = 4 means 3⁴ = x, so x = 81."],"General Mathematics":["(2x + 3)(x - 4) = 2x² - 8x + 3x - 12 = 2x² - 5x - 12","15% of 240 = 0.15 × 240 = 36","3x + 7 = 22 → 3x = 15 → x = 5","5! = 5 × 4 × 3 × 2 × 1 = 120","0.75 = 75/100 = 3/4 after simplifying by dividing both by 25","25% of 360 = 0.25 × 360 = 90","12/18 = (12÷6)/(18÷6) = 2/3","Factors of 24: {1,2,3,4,6,8,12,24}. Factors of 36: {1,2,3,4,6,9,12,18,36}. GCD = 12","3 ÷ 8 = 0.375","20% off $40 = $40 × 0.80 = $32","2/3 + 1/4 = 8/12 + 3/12 = 11/12","15% of $80 = 0.15 × 80 = $12","45/60 = (45÷15)/(60÷15) = 3/4","0.125 = 125/1000 = 1/8","30% × N = 45 → N = 45/0.30 = 150"],"Statistics and Probability":["A fair die has 6 outcomes, each equally likely. P(6) = 1/6.","Mean = (4 + 7 + 9 + 12 + 15) / 5 = 47/5 = 9.4","Sorted: 2, 5, 8, 11, 14. The middle value is 8.","P(red) = 5/(5+3) = 5/8","Range = max - min = 30 - 10 = 20","The value 5 appears 3 times, more than any other value. Mode = 5.","Standard deviation measures how spread out data points are from the mean.","For independent events: P(A and B) = P(A) × P(B) = 0.3 × 0.5 = 0.15","For even-count dataset {4,7,10,13}: median = (7+10)/2 = 8.5","3 books can be arranged in 3! = 3 × 2 × 1 = 6 ways."],"Basic Calculus":["Using the power rule: d/dx[3x²] = 3 × 2x = 6x","Factor: (x²-4)/(x-2) = (x+2)(x-2)/(x-2) = x+2. As x→2: 2+2 = 4","∫ 2x dx = 2 × x²/2 + C = x² + C","f'(x) = 5 × 3x² - 2 = 15x² - 2","The derivative of sin(x) is cos(x). This is a fundamental trigonometric derivative.","d/dx[eˣ + 3x] = eˣ + 3. The derivative of eˣ is eˣ and of 3x is 3.","∫ cos(x) dx = sin(x) + C. Integration is the reverse of differentiation.","The derivative of ln(x) is 1/x. This is a fundamental logarithmic derivative.","As x → ∞, 1/x approaches 0. The function gets infinitely close to zero.","f'(x) = 4x³ - 4x using the power rule on each term."]},l=Ht(t),c=i[l]||i["General Mathematics"];return c[s%c.length]}function $r(t){const s=Math.floor(t/60),n=t%60;return`${s}:${n.toString().padStart(2,"0")}`}const Ts=({value:t,label:s,delay:n=0,icon:i})=>{const[l,c]=je.useState(0);return je.useEffect(()=>{if(t<=0)return;const r=1e3,d=30,x=Math.abs(Math.floor(r/d));let f=0;const M=setTimeout(()=>{const u=setInterval(()=>{f+=Math.max(1,Math.floor(t/d)),f>=t?(c(t),clearInterval(u)):c(f)},x);return()=>clearInterval(u)},n);return()=>clearTimeout(M)},[t,n]),t<0?null:e.jsxs(S.div,{initial:{opacity:0,transform:"translateX(-20px)"},animate:{opacity:1,transform:"translateX(0)"},transition:{delay:n/1e3,duration:.5},className:"flex items-center justify-between bg-slate-50 border border-slate-100 rounded-xl p-3",children:[e.jsxs("div",{className:"flex items-center gap-3 text-slate-500 font-bold uppercase tracking-wider text-[10px]",children:[i,s]}),e.jsxs("div",{className:"text-xl font-black text-purple-600 tabular-nums",children:["+",l]})]})},Br=({viewportHeight:t})=>{const s=je.useMemo(()=>[...Array(40)].map((n,i)=>({id:i,left:`${Math.random()*100}%`,duration:.6+Math.random()*.4,delay:Math.random()*.4})),[t]);return e.jsx("div",{className:"absolute inset-0 pointer-events-none z-[250] overflow-hidden flex justify-between",children:s.map(n=>e.jsx(S.div,{className:"absolute w-0.5 h-16 bg-blue-400/40 rounded-full",style:{left:n.left,top:"-10%"},animate:{y:[0,t*1.2]},transition:{duration:n.duration,ease:"linear",delay:n.delay}},n.id))})},Hr=({viewportHeight:t,viewportWidth:s})=>{const n=je.useMemo(()=>[...Array(30)].map((i,l)=>({id:l,xShift:(Math.random()-.5)*s*.8,yShift:(Math.random()-.5)*t*.8,scale:Math.random()*1.5+.5,duration:2+Math.random()*1.5,delay:Math.random()*.35})),[t,s]);return e.jsx("div",{className:"absolute inset-0 pointer-events-none z-[250] overflow-hidden flex items-center justify-center",children:n.map(i=>e.jsx(S.div,{className:"absolute w-2 h-2 bg-amber-400 rounded-full shadow-[0_0_10px_rgba(251,191,36,0.6)]",style:{left:"50%",top:"50%"},animate:{y:[0,i.yShift],x:[0,i.xShift],scale:[0,i.scale,0],opacity:[0,1,0]},transition:{duration:i.duration,ease:"easeOut",delay:i.delay}},i.id))})},qr=()=>{const t=je.useMemo(()=>[...Array(60)].map((s,n)=>({id:n,left:`${Math.random()*100}%`,backgroundColor:["#75D06A","#6ED1CF","#9956DE","#FB96BB","#FFB356"][n%5],duration:2+Math.random()*2,delay:Math.random()*.5,size:6+Math.random()*8,borderRadius:Math.random()>.5?"50%":"2px"})),[]);return e.jsxs("div",{className:"absolute inset-0 pointer-events-none z-[250] overflow-hidden",children:[e.jsx("style",{children:` - @keyframes confetti-fall { - 0% { transform: translateY(-10vh) rotate(0deg); opacity: 1; } - 100% { transform: translateY(110vh) rotate(720deg); opacity: 0; } - } - .confetti-piece { - animation-name: confetti-fall; - animation-timing-function: linear; - animation-fill-mode: forwards; - } - `}),t.map(s=>e.jsx("div",{className:"confetti-piece absolute",style:{left:s.left,top:"-10%",backgroundColor:s.backgroundColor,width:s.size,height:s.size,borderRadius:s.borderRadius,animationDuration:`${s.duration}s`,animationDelay:`${s.delay}s`}},s.id))]})},Or=({lesson:t,questions:s,onComplete:n,onBack:i})=>{const[l,c]=a.useState(0),[r,d]=a.useState(0),[x,f]=a.useState(null),[M,u]=a.useState(""),[N,m]=a.useState(!1),[p,k]=a.useState(!1),[y,W]=a.useState(0),[j,E]=a.useState(0),[_,D]=a.useState(0),[b,I]=a.useState(!1),[B,se]=a.useState([]),[C,re]=a.useState(!1),[ge,Oe]=a.useState(!1),[oe,Qe]=a.useState(null),[Se,G]=a.useState(null),[ve,We]=a.useState(!1),[_e,Ve]=a.useState(!1),[$e,Ue]=a.useState(!1),[h,A]=a.useState(!1),[T,X]=a.useState(!1),[$,Z]=a.useState(typeof window<"u"?window.innerHeight:800),[le,Ae]=a.useState(typeof window<"u"?window.innerWidth:1200),[fe,be]=a.useState([]),[Te]=a.useState(Date.now()),[F,ee]=a.useState(0),[ue,Be]=a.useState(!1),[st,St]=a.useState(!0),[bt,Ge]=a.useState(!1),[Ct,Ne]=a.useState(!1),[ce,at]=a.useState(!1),[rt,ct]=a.useState(!1),[zt,He]=a.useState(0),[Ye,Ke]=a.useState({}),[o,P]=a.useState(5),[Q,de]=a.useState(15),[U,q]=a.useState(null),[me,Pe]=a.useState(!1),[Ee,xe]=a.useState(900*1e3),[ne,Le]=a.useState({}),[gt,Ze]=a.useState({}),[ke,Pt]=a.useState(!1),[Lt,Mt]=a.useState(!1),[dt,nt]=a.useState(null),[qt]=a.useState(Array.from({length:15},(g,z)=>({id:z,size:Math.random()*120+60,x:Math.random()*100,y:Math.random()*100,duration:Math.random()*25+15,delay:Math.random()*-20,color:["bg-white/5","bg-indigo-300/10","bg-sky-300/10","bg-purple-300/10"][Math.floor(Math.random()*4)]}))),L=s[r],J=r{if(st)try{const z=window.AudioContext||window.webkitAudioContext;if(!z)return;const O=new z,K=O.currentTime,he=(te,Y,ie,De=.1,yt="sine")=>{const lt=O.createOscillator(),xt=O.createGain();lt.type=yt,lt.frequency.value=te,xt.gain.setValueAtTime(0,Y),xt.gain.linearRampToValueAtTime(De,Y+.05),xt.gain.exponentialRampToValueAtTime(.001,Y+ie),lt.connect(xt),xt.connect(O.destination),lt.start(Y),lt.stop(Y+ie)};g==="correct"?(he(880,K,.1,.1,"sine"),he(1108.73,K+.1,.2,.1,"sine")):g==="incorrect"?(he(300,K,.2,.05,"sawtooth"),he(250,K+.15,.3,.05,"sawtooth")):g==="streak"?(he(440,K,.1,.05,"square"),he(554.37,K+.1,.1,.05,"square"),he(659.25,K+.2,.1,.05,"square"),he(880,K+.3,.4,.05,"square")):g==="complete"&&(he(523.25,K,.1,.1),he(659.25,K+.15,.1,.1),he(783.99,K+.3,.1,.1),he(1046.5,K+.45,.5,.1))}catch{}};a.useEffect(()=>{const g=()=>{Z(window.innerHeight),Ae(window.innerWidth)};return window.addEventListener("resize",g),()=>window.removeEventListener("resize",g)},[]),a.useEffect(()=>{if(L?.type==="multiple-choice"&&L.options){const g=L.options.map((z,O)=>({id:`${L.id}-${O}`,text:z}));for(let z=g.length-1;z>0;z--){const O=Math.floor(Math.random()*(z+1));[g[z],g[O]]=[g[O],g[z]]}se(g)}else se([])},[l,L]),a.useEffect(()=>{Ne(!1),at(!1)},[l]);const V=()=>{document.fullscreenElement?(document.exitFullscreen().catch(()=>{}),Ge(!1)):(document.documentElement.requestFullscreen().catch(()=>{}),Ge(!0))},R=()=>at(g=>!g);a.useEffect(()=>{const g=z=>{z.key==="Enter"&&(!N&&H()?ye():N&&ze())};return window.addEventListener("keypress",g),()=>window.removeEventListener("keypress",g)},[N,x,M]),a.useEffect(()=>{Q===0&&!U&&(q(Date.now()),Pe(!0))},[Q,U]),a.useEffect(()=>{if(!me||!U)return;const g=setInterval(()=>{const z=Date.now()-U,O=Math.max(0,900*1e3-z);xe(O)},1e3);return()=>clearInterval(g)},[me,U]);const H=()=>L.type==="fill-in-blank"?M.trim().length>0:x!==null,Ce=()=>{if(o<=0||N||ne[l]||ce)return;const g=Ye[l]||[],z=B.filter(K=>K.text!==L.correctAnswer).filter(K=>!g.includes(K.text));if(z.length===0)return;const O=z[Math.floor(Math.random()*z.length)];Ke(K=>({...K,[l]:[...g,O.text]})),P(K=>Math.max(0,K-1)),He(K=>Math.max(0,K-5)),w("correct")},Ie=()=>{ne[l]||N||ce||(Le(g=>({...g,[l]:!0})),Ne(!0))},ye=g=>{if(C||rie.id===x);O=Y?Y.text:""}else{re(!1);return}z=O===L.correctAnswer}if(!z){Pt(!0),w("incorrect"),setTimeout(()=>Pt(!1),500),de(ie=>Math.max(0,ie-1)),E(0);const Y=[...gt[l]||[],O];if(Ze(ie=>({...ie,[l]:Y})),L.type==="multiple-choice"||L.type==="true-false"){const ie=L.options?L.options.length-1:1;Y.length>=ie&&(k(!1),m(!0),be(De=>{const yt=[...De];return yt[r]=!1,yt}))}else Y.length>=3&&(k(!1),m(!0),be(ie=>{const De=[...ie];return De[r]=!1,De}));re(!1);return}k(!0),m(!0),be(Y=>{const ie=[...Y];return ie[r]=!0,ie});const he=(Ye[l]||[]).length>0?5:10;He(Y=>Y+he),W(Y=>Y+1);const te=j+1;if(E(te),D(Math.max(_,te)),te===2?nt("streak"):te===3&&xs<2?nt("multiplier2"):te===5&&xs<3&&nt("multiplier3"),te>0&&te%3===0){const Y=te*5;ee(ie=>ie+Y),w("streak")}else w("correct");ct(!0),setTimeout(()=>{ct(!1),nt(null),setTimeout(()=>ze(),500)},1200),Ft(()=>import("./confetti.module-C94ZD2ww.js"),[]).then(Y=>{Y.default({particleCount:30,spread:40,colors:["#75D06A","#6ED1CF"],origin:{y:.6}})}).finally(()=>re(!1))},ze=()=>{lg+1),d(g=>g+1),m(!1),f(null),u(""),k(!1)):we()},we=()=>{const g=Math.round(y/s.length*100);I(!0),g>=80||(g>=50?(A(!0),setTimeout(()=>A(!1),5e3)):(Ue(!0),setTimeout(()=>Ue(!1),5e3))),w("complete")},pe=v==="quiz"?{gradient:"bg-gradient-to-br from-[#7274ED] via-[#9956DE] to-[#7274ED]"}:{gradient:"bg-gradient-to-br from-[#75D06A] via-[#6ED1CF] to-[#75D06A]"},Qt=(()=>{const g=Ot.toLowerCase();return g.includes("geometry")||g.includes("shape")?[Ms,Ns,zs,js,pr,fr]:g.includes("algebra")||g.includes("equation")?[Je,Gt,vs,Xt,wt,Ss]:g.includes("calculus")||g.includes("derivative")||g.includes("integral")?[Cs,Xt,At,wt,Gt,vs]:g.includes("statistics")||g.includes("probability")?[et,At,js,Ns,Ms,zs]:[wt,Cs,Gt,Ss,Xt,Oa]})();Qt[0];const xs=Math.min(2,1+j*.1);if(b){const g=Math.round(y/s.length*100),z=g>=80,O=g>=50&&g<80,K=v==="quiz"?100:50,he=Math.round(y/s.length*100),te=K+he+F,Y=document.getElementById("modal-root"),ie=e.jsxs("div",{className:"fixed inset-0 z-[200] flex items-center justify-center p-4 bg-slate-900/40",children:[h&&e.jsx(Hr,{viewportHeight:$,viewportWidth:le}),$e&&e.jsx(Br,{viewportHeight:$}),z&&e.jsx(qr,{}),e.jsxs(S.div,{initial:{opacity:0,scale:.8,y:40},animate:{opacity:1,scale:1,y:0},transition:{type:"spring",damping:18,stiffness:200},className:"w-full max-w-xs sm:max-w-sm bg-white border-2 border-slate-200 shadow-[0_25px_60px_rgba(0,0,0,0.15)] rounded-[2rem] p-4 sm:p-5 text-center relative z-10",children:[e.jsx(S.div,{initial:{scale:0,rotate:-180},animate:{scale:1,rotate:0},transition:{type:"spring",damping:12,stiffness:150,delay:.2},className:"mb-3",children:e.jsx("img",{src:"/mascot/modules_avatar.png",alt:"Mascot",className:"w-16 h-16 sm:w-20 sm:h-20 mx-auto drop-shadow-xl"})}),e.jsx(S.h2,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:.3},className:`text-xl sm:text-2xl font-black uppercase tracking-tight mb-1 drop-shadow-sm ${z?"text-emerald-500":O?"text-amber-500":"text-rose-500"}`,children:z?"EXCELLENT!":O?"GOOD JOB!":"KEEP TRYING!"}),e.jsxs("p",{className:"text-slate-400 font-bold text-[10px] mb-3 uppercase tracking-widest",children:["Quiz Complete • Score: ",y,"/",s.length]}),e.jsx(S.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.4},className:"bg-slate-50/50 rounded-xl p-3 mb-4 border border-slate-100 flex flex-col gap-2",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-slate-400 text-[9px] font-black uppercase tracking-widest text-left mb-1.5 ml-1",children:"Performance Details"}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(Ts,{value:y,label:"Correct Answers",delay:500,icon:e.jsx(Rt,{size:14,className:"h-3 w-3 text-emerald-500"})}),e.jsx(Ts,{value:te,label:"Total XP Earned",delay:800,icon:e.jsx(Xe,{size:14,className:"h-3 w-3 text-amber-500"})}),e.jsxs(S.div,{initial:{opacity:0},animate:{opacity:1},transition:{delay:1.2,duration:.4},className:"flex items-center justify-between pt-1.5 mt-1 border-t border-slate-100",children:[e.jsx("span",{className:"text-slate-400 text-[9px] font-black uppercase tracking-widest",children:"Final Accuracy"}),e.jsxs("span",{className:"text-lg font-black text-slate-800 tabular-nums",children:[g,"%"]})]})]})]})}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(Me,{size:"lg",onClick:()=>{c(0),d(0),f(null),u(""),W(0),E(0),D(0),He(0),be([]),m(!1),k(!1),I(!1),Ke({}),Le({}),Ze({}),X(!1)},className:"w-full h-10 sm:h-11 rounded-2xl text-xs font-black bg-white hover:bg-slate-50 text-purple-600 border-2 border-purple-100",children:"RETAKE QUIZ"}),e.jsx(Me,{size:"lg",onClick:()=>n(g,te),className:"w-full h-10 sm:h-11 rounded-2xl text-xs font-black bg-purple-600 hover:bg-purple-700 text-white shadow-lg shadow-purple-200",children:"BACK TO MODULE"})]})]})]});return vt.createPortal(ie,Y)}return e.jsxs(e.Fragment,{children:[Lt&&vt.createPortal(e.jsx(S.div,{initial:{opacity:0,x:20},animate:{opacity:1,x:0},exit:{opacity:0,x:20},className:"fixed right-6 top-1/2 -translate-y-1/2 z-[9999] w-64",children:e.jsxs("div",{className:"bg-white rounded-2xl p-3 border border-slate-200 shadow-[0_10px_40px_rgba(0,0,0,0.2)]",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2 px-1",children:[e.jsxs("h4",{className:"text-xs font-bold text-[#0a1628] flex items-center gap-2",children:[e.jsx(wt,{size:14,className:"text-purple-600"})," Calculator"]}),e.jsx("button",{onClick:()=>Mt(!1),className:"w-6 h-6 rounded-full bg-slate-100 flex items-center justify-center text-slate-500 hover:text-slate-800 hover:bg-slate-200 transition-colors",children:e.jsx(Je,{size:12})})]}),e.jsx(Ws,{isOpen:!0,onClose:()=>Mt(!1),inline:!0})]})}),document.getElementById("modal-root")),me&&vt.createPortal(e.jsx("div",{className:"fixed inset-0 z-[200] flex items-center justify-center p-4 bg-slate-900/50",children:e.jsxs(S.div,{initial:{scale:.9,opacity:0},animate:{scale:1,opacity:1},className:"bg-white rounded-[2rem] p-6 max-w-xs w-full text-center border-2 border-rose-200 shadow-[0_25px_60px_rgba(0,0,0,0.15)]",children:[e.jsx(S.div,{animate:{scale:[1,1.1,1]},transition:{duration:1,repeat:1/0},className:"text-6xl mb-4",children:e.jsx(Vs,{className:"w-10 h-10 text-rose-500"})}),e.jsx("h2",{className:"text-2xl font-black text-slate-800 mb-3",children:"Out of Lives!"}),e.jsx("p",{className:"text-slate-500 text-sm mb-4",children:"Your hearts have run out. You can wait for them to refill or head back and review your lessons in the meantime."}),e.jsxs("div",{className:"flex items-center justify-center gap-2 mb-2 text-rose-500 font-bold",children:[e.jsx("img",{src:"/icons/quiz_heart.png",alt:"Hearts",className:"w-5 h-5"}),e.jsx("span",{children:"0 / 15 hearts"})]}),e.jsxs("p",{className:"text-slate-400 text-xs mb-4",children:["Next heart in: ",e.jsxs("span",{className:"font-bold text-slate-600",children:[Math.floor(Ee/6e4),":",Math.floor(Ee%6e4/1e3).toString().padStart(2,"0")]})," (15 minutes per heart)"]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(Me,{onClick:i,className:"w-full py-3 bg-rose-500 hover:bg-rose-600 text-white font-bold rounded-full",children:"Exit Quiz"}),e.jsx(Me,{onClick:()=>{Pe(!1)},className:"w-full py-3 bg-slate-100 hover:bg-slate-200 text-slate-700 font-bold rounded-full",children:"Review Lessons"})]})]})}),document.getElementById("modal-root")),e.jsxs(ot,{children:[ve&&Se&&e.jsx(S.div,{initial:{y:-20,opacity:0},animate:{y:0,opacity:1},exit:{y:-20,opacity:0},transition:{type:"spring",damping:20,stiffness:300},className:"fixed top-24 left-1/2 -translate-x-1/2 z-[75] pointer-events-none",style:{willChange:"transform, opacity"},children:e.jsx("div",{className:"bg-white/90 px-4 py-2 rounded-2xl shadow-xl font-bold text-sm",children:Se})},"popup"),rt&&e.jsx(S.div,{initial:{opacity:0,scale:.8,y:20},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:1.1,filter:"blur(10px)"},transition:{type:"spring",damping:20,stiffness:300},className:"fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 z-[100] pointer-events-none flex flex-col items-center justify-center",children:e.jsxs("div",{className:"bg-white/95 backdrop-blur-xl border border-slate-200 rounded-[2rem] p-6 md:p-8 shadow-[0_30px_80px_rgba(0,0,0,0.15)] flex flex-col items-center min-w-[280px] md:min-w-[320px]",children:[e.jsx("img",{src:"/mascot/modules_avatar.png",alt:"Mascot",className:"w-24 h-24 md:w-32 md:h-32 mb-4 drop-shadow-[0_10px_20px_rgba(0,0,0,0.15)]"}),e.jsx("h2",{className:`text-3xl md:text-4xl font-black mb-4 uppercase tracking-widest ${p?"text-emerald-500":"text-rose-500"}`,children:p?"Correct!":"Incorrect"}),p?e.jsxs("div",{className:"flex flex-col items-center gap-3 w-full justify-center",children:[e.jsx("div",{className:"flex items-center gap-2 bg-emerald-500/20 text-emerald-400 px-4 py-2 rounded-full font-bold border border-emerald-500/30",children:e.jsxs("span",{children:["+ ",(Ye[l]||[]).length>0?5:10," XP"]})}),dt==="streak"&&e.jsxs("div",{className:"flex items-center gap-2 bg-orange-500/20 text-orange-400 px-4 py-1.5 rounded-full text-sm font-bold border border-orange-500/30",children:[e.jsx(rs,{size:14})," Streak Started!"]}),dt==="multiplier2"&&e.jsxs("div",{className:"flex items-center gap-2 bg-amber-500/20 text-amber-400 px-4 py-1.5 rounded-full text-sm font-bold border border-amber-500/30",children:[e.jsx(Xe,{size:14})," Multiplier ×2!"]}),dt==="multiplier3"&&e.jsxs("div",{className:"flex items-center gap-2 bg-amber-500/20 text-amber-400 px-4 py-1.5 rounded-full text-sm font-bold border border-amber-500/30",children:[e.jsx(Xe,{size:14})," Multiplier ×3!"]})]}):e.jsxs("div",{className:"bg-rose-500/20 border border-rose-500/30 text-rose-400 font-bold px-5 py-2 rounded-xl text-center",children:["Correct: ",L.correctAnswer]})]})},"round-result")]}),e.jsxs("div",{className:"fixed inset-0 z-50 h-screen w-full flex flex-col bg-slate-50 overflow-hidden",children:[e.jsxs("header",{className:`relative shrink-0 flex flex-col items-center justify-start px-4 pt-4 sm:pt-6 pb-6 z-[60] shadow-md overflow-hidden ${pe.gradient} rounded-b-[32px] sm:rounded-b-[40px] min-h-[110px] sm:min-h-[130px]`,children:[e.jsxs("div",{className:"absolute inset-0 z-0 pointer-events-none",children:[e.jsx("div",{className:"absolute top-0 left-0 w-64 h-64 bg-white opacity-10 rounded-full -translate-x-1/2 -translate-y-1/2 blur-2xl"}),e.jsx("div",{className:"absolute bottom-0 right-0 w-80 h-80 bg-white opacity-10 rounded-full translate-x-1/3 translate-y-1/3 blur-3xl"}),Qt.map((g,z)=>e.jsx("div",{className:"absolute text-white/10",style:{top:`${10+z*15}%`,left:`${10+z*25%80}%`,transform:`rotate(${z*45}deg) scale(${1+z%3*.2})`},children:e.jsx(g,{size:48+z%2*32})},z))]}),e.jsxs("div",{className:"w-full max-w-7xl flex items-start justify-between relative z-10 mb-4 sm:mb-6",children:[e.jsx("div",{className:"flex-1 pointer-events-none"}),e.jsxs("div",{className:"relative flex items-center justify-center bg-purple-900/40 backdrop-blur-md px-6 sm:px-8 py-3 rounded-full border border-white/10 gap-3 sm:gap-4 shadow-inner",children:[e.jsx("div",{className:"w-3 h-3 sm:w-4 sm:h-4 rounded-full bg-yellow-400 shrink-0 shadow-[0_0_10px_rgba(250,204,21,0.6)]"}),e.jsxs("div",{className:"flex flex-col items-start justify-center",children:[e.jsx("span",{className:"text-[10px] sm:text-[11px] font-black text-purple-200 uppercase tracking-widest leading-none mb-1",children:"Try It Yourself!"}),e.jsxs("span",{className:"font-bold text-white tracking-wide text-base sm:text-lg leading-none truncate max-w-[200px] sm:max-w-[300px]",children:["LESSON ",t.id||"1"]})]})]}),e.jsxs("div",{className:"flex-1 flex justify-end gap-2 sm:gap-3 relative pointer-events-auto",children:[e.jsx("button",{onClick:()=>St(!st),className:"w-10 h-10 sm:w-12 sm:h-12 rounded-full bg-purple-900/20 text-white flex items-center justify-center hover:bg-purple-900/40 transition-colors shadow-sm border border-white/10",children:st?e.jsx(es,{size:20}):e.jsx(ts,{size:20})}),e.jsx("button",{onClick:V,className:"hidden sm:flex w-10 h-10 sm:w-12 sm:h-12 rounded-full bg-purple-900/20 text-white items-center justify-center hover:bg-purple-900/40 transition-colors shadow-sm border border-white/10",children:bt?e.jsx(Us,{size:20}):e.jsx(Gs,{size:20})}),e.jsx("button",{onClick:()=>Be(!0),className:"w-10 h-10 sm:w-12 sm:h-12 rounded-full bg-purple-900/20 text-white flex items-center justify-center hover:bg-purple-900/40 transition-colors shadow-sm border border-white/10",children:e.jsx(da,{size:20})})]})]}),e.jsx("div",{className:"w-full max-w-[50rem] flex items-center justify-center px-4 z-10",children:e.jsx("div",{className:"w-full flex items-center gap-2 sm:gap-3",children:s.map((g,z)=>e.jsx("div",{className:`h-1.5 sm:h-2 rounded-full flex-1 transition-all ${z<=l?"bg-white shadow-[0_0_8px_rgba(255,255,255,0.8)]":"bg-white/20"}`},z))})})]}),e.jsx(ot,{children:ue&&e.jsx(S.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-[100] bg-black/60 backdrop-blur-sm flex items-center justify-center p-4",onClick:()=>Be(!1),children:e.jsxs(S.div,{onClick:g=>g.stopPropagation(),initial:{scale:.9,opacity:0,y:20},animate:{scale:1,opacity:1,y:0},exit:{scale:.9,opacity:0,y:20},className:"bg-white rounded-[2rem] p-6 sm:p-8 max-w-xs w-full shadow-2xl flex flex-col gap-4 text-center",children:[e.jsx("h2",{className:"text-xl font-black text-slate-800",children:"Are you sure you want to leave?"}),e.jsx("p",{className:"text-sm text-slate-500",children:"Your progress won't be saved."}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(Me,{onClick:()=>Be(!1),className:"w-full py-3 rounded-full bg-[#9956DE] hover:bg-[#8544c7] text-white font-bold",children:"Stay"}),e.jsx(Me,{onClick:()=>{Be(!1),i()},className:"w-full py-3 rounded-full bg-slate-100 hover:bg-slate-200 text-slate-600 font-bold",children:"Leave"})]})]})})}),e.jsxs("div",{className:"w-full max-w-[54rem] mx-auto shrink-0 flex items-center justify-between px-4 sm:px-6 py-2 sm:py-3 z-[50] relative mt-4",children:[e.jsx("button",{onClick:()=>d(g=>Math.max(0,g-1)),disabled:r===0,className:`w-10 h-10 sm:w-12 sm:h-12 shrink-0 rounded-full flex items-center justify-center shadow-md border-2 transition-all ${r===0?"bg-slate-100 text-slate-400 border-slate-200 cursor-not-allowed":"bg-white text-purple-600 border-purple-100 hover:bg-purple-50 hover:border-purple-200 hover:scale-105 active:scale-95"}`,children:e.jsx(ss,{size:24})}),e.jsxs("div",{className:"flex items-center justify-center gap-3 sm:gap-5 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 sm:gap-3 px-8 sm:px-10 py-2 rounded-full bg-white shadow-md border border-slate-200/60 text-rose-500 font-extrabold text-sm sm:text-base",children:[e.jsx("img",{src:"/icons/quiz_heart.png",alt:"Hearts",className:"w-5 h-5 object-contain"}),Q]}),e.jsxs("div",{className:"flex items-center gap-2 sm:gap-3 px-8 sm:px-10 py-2 rounded-full bg-white shadow-md border border-slate-200/60 text-yellow-500 font-extrabold text-sm sm:text-base",children:[e.jsx("img",{src:"/icons/quiz_key.png",alt:"Keys",className:"w-5 h-5 object-contain"}),o]}),e.jsxs("div",{className:"flex items-center gap-3 sm:gap-4 px-3 py-1.5 pl-5 sm:pl-6 rounded-full bg-white shadow-md border border-slate-200/60",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-orange-500 font-extrabold text-sm sm:text-base",children:[e.jsx("img",{src:"/icons/quiz_streak.png",alt:"Streak",className:"w-5 h-5 object-contain"})," ",j]}),e.jsxs("div",{className:"bg-emerald-100 text-emerald-800 px-4 py-1.5 rounded-full font-bold text-sm sm:text-base shadow-inner border border-emerald-200/50",children:["+ ",zt," pts"]})]})]}),e.jsx("button",{onClick:()=>d(g=>Math.min(l,g+1)),disabled:r>=l,className:`w-10 h-10 sm:w-12 sm:h-12 shrink-0 rounded-full flex items-center justify-center shadow-md border-2 transition-all ${r>=l?"bg-slate-100 text-slate-400 border-slate-200 cursor-not-allowed":"bg-white text-purple-600 border-purple-100 hover:bg-purple-50 hover:border-purple-200 hover:scale-105 active:scale-95"}`,children:e.jsx(it,{size:24})})]}),e.jsx("main",{className:"flex-1 overflow-y-auto w-full px-4 sm:px-6 pt-0 pb-6 flex flex-col items-center relative z-10",children:e.jsxs(S.div,{initial:{opacity:0,x:20},animate:ke?{x:[-10,10,-10,10,0],scale:[1,1.01,1],opacity:1}:{opacity:1,x:0},className:"w-full max-w-3xl flex flex-col mt-2",children:[e.jsxs("div",{className:"bg-white rounded-3xl shadow-lg border-t-[6px] border-purple-500 p-6 sm:p-8 text-center flex flex-col items-center mb-6 w-full relative overflow-hidden",children:[(()=>{const z=[{label:"New",color:"bg-blue-100 text-blue-700",icon:e.jsx($s,{size:14,className:"mr-1.5"})},{label:"Learning",color:"bg-amber-100 text-amber-700",icon:e.jsx(At,{size:14,className:"mr-1.5"})},{label:"Retry",color:"bg-rose-100 text-rose-700",icon:e.jsx(Bs,{size:14,className:"mr-1.5"})},{label:"Mastered",color:"bg-emerald-100 text-emerald-700",icon:e.jsx(ns,{size:14,className:"mr-1.5"})}][r%4];return e.jsxs("div",{className:`${z.color} px-4 py-1.5 rounded-full text-[11px] sm:text-xs font-black uppercase tracking-widest mb-6 flex items-center shadow-sm`,children:[z.icon," ",z.label]})})(),e.jsx("h2",{className:"text-xl sm:text-2xl font-extrabold text-[#0a1628] leading-tight w-full",children:L.question.includes("___")?e.jsx("span",{children:L.question.split("___").map((g,z,O)=>e.jsxs(je.Fragment,{children:[g,z0,value:M,onChange:K=>u(K.target.value),className:`inline-block w-24 mx-2 border-b-4 outline-none text-center bg-transparent font-bold ${J?fe[r]?"border-[#75D06A] text-[#75D06A]":"border-rose-500 text-rose-500":"border-[#7C3AED] text-[#7C3AED] focus:border-[#75D06A]"}`})]},z))}):L.question})]}),e.jsxs("div",{className:"w-full flex flex-col items-center",children:[(L.type==="multiple-choice"||L.type==="true-false")&&e.jsx("div",{className:"w-full grid grid-cols-1 sm:grid-cols-2 gap-3 sm:gap-5",children:(L.type==="true-false"?["True","False"]:B).map((g,z)=>{const O=typeof g=="string"?g:g.text,K=typeof g=="string"?`${L.id}-${z}`:g.id,te=(gt[r]||[]).includes(O),Y=ne[r]||ce,ie=Ye[l]||[],De=ie.includes(O),yt=ie.length,lt=B.filter(ta=>ta.text!==L.correctAnswer).length,xt=r===l&<>0&&yt>=lt;let Re="bg-white hover:bg-slate-50 border-transparent text-slate-700 hover:border-slate-200",Wt=!1;return xt?(Wt=!0,O===L.correctAnswer?Re="bg-emerald-50 border-emerald-400 text-emerald-800":te?Re="bg-rose-50 border-rose-400 text-rose-800 opacity-80":Re="bg-slate-100 border-slate-200 text-slate-400 opacity-40 line-through"):De?Re="bg-slate-100 border-slate-200 text-slate-400 opacity-40 line-through cursor-not-allowed":Y?O===L.correctAnswer?Re="bg-emerald-50 border-emerald-400 text-emerald-800 shadow-[0_0_15px_rgba(16,185,129,0.2)] scale-[1.02] z-10":Re="bg-slate-50 border-slate-200 text-slate-400 opacity-60":J?O===L.correctAnswer?Re="bg-emerald-50 border-emerald-400 text-emerald-800 shadow-[0_0_15px_rgba(16,185,129,0.2)] scale-[1.02] z-10":te?Re="bg-rose-50 border-rose-400 text-rose-800 opacity-60":Re="bg-slate-50 border-slate-200 text-slate-400 opacity-60":te?Re="bg-rose-50 border-rose-400 text-rose-800 opacity-60":x===K&&(Re="bg-purple-50 border-[#9956DE] text-[#9956DE]"),e.jsxs("button",{disabled:Wt||J||te||Y||De,onClick:()=>{Wt||J||C||te||Y||De||(f(K),ye(O))},className:`p-4 sm:p-5 rounded-2xl shadow-sm border-[3px] font-extrabold text-base sm:text-lg text-left transition-all flex items-center justify-between ${Re} ${J||Y||De?"cursor-default":"hover:shadow-md hover:-translate-y-0.5 active:translate-y-0"}`,children:[e.jsx("span",{className:"truncate pr-4",children:O}),De&&e.jsx(Je,{size:20,className:"text-slate-400 shrink-0"}),Y&&O===L.correctAnswer&&e.jsx(Rt,{size:24,className:"text-emerald-500 shrink-0"}),J&&O===L.correctAnswer&&!Y&&e.jsx(Rt,{size:24,className:"text-emerald-500 shrink-0"}),(J||te)&&te&&e.jsx(Je,{size:24,className:"text-rose-500 shrink-0"})]},K)})}),ce&&e.jsx(S.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:"w-full mt-6 space-y-4 max-w-3xl",children:e.jsxs("div",{className:"border-2 rounded-2xl p-5 flex items-start gap-4 bg-sky-50 border-sky-200",children:[e.jsx("img",{src:"/mascot/modules_avatar.png",className:"w-10 h-10 shrink-0",alt:"AI Explain"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-extrabold text-lg mb-1 text-sky-700",children:"Explanation"}),e.jsx("p",{className:"text-base leading-relaxed text-sky-800",children:L.explanation||`The correct answer is: ${L.correctAnswer}`})]})]})})]})]},r)}),e.jsxs("footer",{className:`shrink-0 relative z-[60] flex flex-col items-center justify-center p-4 sm:p-6 ${pe.gradient} rounded-t-[32px] sm:rounded-t-[40px] shadow-[0_-10px_40px_rgba(0,0,0,0.15)]`,children:[e.jsx("div",{className:"absolute inset-0 z-0 pointer-events-none opacity-20",children:Qt.slice(0,3).map((g,z)=>e.jsx("div",{className:"absolute text-white",style:{top:`${20+z*20}%`,left:`${20+z*30}%`,transform:`rotate(${z*30}deg) scale(1.5)`},children:e.jsx(g,{size:32})},z))}),e.jsx("div",{className:"relative z-10 flex flex-col gap-3",children:rd(l),className:"bg-white text-slate-700 font-extrabold text-lg px-6 sm:px-8 py-3 sm:py-4 rounded-full flex items-center gap-2 sm:gap-3 shadow-lg hover:bg-slate-50 transition-transform hover:scale-105 active:scale-95 border border-slate-200",children:[e.jsx(it,{size:20,className:"sm:w-6 sm:h-6"}),"Back to Current Question"]})]}):e.jsx(e.Fragment,{children:(()=>{const g=(Ye[l]||[]).length,z=B.filter(te=>te.text!==L.correctAnswer).length,O=z>0&&g>=z,K=N&&!p||ne[l]||ce||O;if(ce)return e.jsxs("button",{onClick:ze,className:"bg-orange-500 hover:bg-orange-600 text-white font-extrabold text-lg px-8 py-4 rounded-full flex items-center justify-center gap-3 shadow-xl hover:scale-[1.02] active:scale-[0.98] transition-all w-full",children:[l0&&!N&&!ne[l]&&!ce&&!O;return e.jsxs("div",{className:"flex flex-wrap justify-center gap-3 sm:gap-4",children:[e.jsxs("button",{onClick:Ce,disabled:!he,className:"bg-white hover:bg-slate-50 disabled:opacity-70 disabled:cursor-not-allowed text-slate-700 font-bold px-6 sm:px-8 py-3 sm:py-3.5 rounded-full flex items-center gap-2 shadow-lg transition-transform hover:scale-105 active:scale-95 border border-slate-200",children:[e.jsx("img",{src:"/icons/quiz_key.png",alt:"Hint",className:"w-5 h-5 object-contain"}),"Hint"]}),e.jsxs("button",{onClick:Ie,disabled:ne[l]||N||ce,className:"bg-white hover:bg-slate-50 disabled:opacity-70 disabled:cursor-not-allowed text-slate-700 font-bold px-6 sm:px-8 py-3 sm:py-3.5 rounded-full flex items-center gap-2 shadow-lg transition-transform hover:scale-105 active:scale-95 border border-slate-200",children:[e.jsx(Ea,{size:18,className:"text-purple-500"}),"Reveal"]}),e.jsxs("button",{onClick:R,className:"bg-white hover:bg-slate-50 text-slate-700 font-bold px-6 sm:px-8 py-3 sm:py-3.5 rounded-full flex items-center gap-2 shadow-lg transition-transform hover:scale-105 active:scale-95 border border-slate-200",children:[e.jsx("img",{src:"/mascot/modules_avatar.png",className:"w-5 h-5 drop-shadow-sm",alt:"AI Explain"}),"Explain"]}),e.jsx("button",{onClick:()=>Mt(te=>!te),className:`w-11 h-11 sm:w-12 sm:h-12 rounded-full flex items-center justify-center shadow-lg transition-transform hover:scale-105 active:scale-95 border border-slate-200 ${Lt?"bg-purple-100 text-purple-600 border-purple-300":"bg-white hover:bg-slate-50 text-slate-700"}`,children:e.jsx(wt,{size:20})})]})})()})})]})]})]})},Qr=[{id:1,type:"multiple-choice",question:"What is the value of π (pi) to two decimal places?",options:["3.12","3.14","3.16","3.18"],correctAnswer:"3.14",explanation:"π ≈ 3.14159..., so to two decimal places it is 3.14."},{id:2,type:"true-false",question:"The sum of angles in a triangle is 180 degrees.",correctAnswer:"True",explanation:"The interior angles of any Euclidean triangle sum to 180°."},{id:3,type:"fill-in-blank",question:"If 2x + 5 = 13, then x = ___.",correctAnswer:"4",explanation:"2x = 13 - 5 = 8 → x = 4."},{id:4,type:"multiple-choice",question:"Which of the following is a prime number?",options:["9","15","17","21"],correctAnswer:"17",explanation:"17 is only divisible by 1 and itself. 9=3×3, 15=3×5, 21=3×7."},{id:5,type:"true-false",question:"The slope of a horizontal line is zero.",correctAnswer:"True",explanation:"A horizontal line has no rise, so rise/run = 0."},{id:6,type:"fill-in-blank",question:"The square root of 144 is ___.",correctAnswer:"12",explanation:"12 × 12 = 144, so √144 = 12."}];async function Wr(t){const{lessonTitle:s,topic:n,subjectId:i,competencyCode:l,questionCount:c=6}=t,r=Gr(i)||"General Mathematics",d=t.lessonId?Math.abs(t.lessonId.split("").reduce((x,f)=>Math.imul(31,x)+f.charCodeAt(0)|0,0))%1e6:Math.floor(Math.random()*1e6);try{const x=await $t("/api/quiz/generate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({topic:n||s,subject:r,lessonTitle:s,questionCount:c,questionTypes:["multiple-choice","true-false","fill-in-blank"],difficulty:"medium",competencyCode:l,varianceSeed:d})});return!x.questions||x.questions.length===0?(console.warn("[lessonQuizService] API returned empty questions, using fallback"),Ps(c)):x.questions.map(f=>({id:f.id,type:f.type,question:f.question,options:f.options||void 0,correctAnswer:f.correctAnswer,explanation:f.explanation}))}catch(x){return console.error("[lessonQuizService] Failed to generate quiz via API:",x),console.warn("[lessonQuizService] Using fallback questions"),Ps(c)}}function Ur(t){return 6}function Gr(t){if(!t)return null;const s=t.toLowerCase();return s.includes("gen-math")||s.includes("gen_math")?"General Mathematics":s.includes("stats")||s.includes("prob")?"Statistics and Probability":s.includes("pre-calc")||s.includes("pre_calc")?"Pre-Calculus":s.includes("basic-calc")||s.includes("basic_calc")||s.includes("calculus")?"Basic Calculus":null}function Ps(t){const s=[...Qr].sort(()=>Math.random()-.5);return s.slice(0,Math.min(t,s.length)).map((n,i)=>({...n,id:i+1}))}const Xr="rag_lesson_";function ms(t){return`${Xr}${t}`}function Vr(t){try{const s=sessionStorage.getItem(ms(t));if(s)return JSON.parse(s)}catch{}return null}function Yr(t,s){try{sessionStorage.setItem(ms(t),JSON.stringify(s))}catch{}}function Kr(t,s,n=!0){const[i,l]=a.useState([]),[c,r]=a.useState(!0),[d,x]=a.useState(null),[f,M]=a.useState([]),[u,N]=a.useState("low"),[m,p]=a.useState(0),[k,y]=a.useState(!1),[W,j]=a.useState(void 0),[E,_]=a.useState(!1),D=a.useCallback(async()=>{if(!n||!t)return;const I=Vr(t);if(I){l(I.sections),M(I.sources),N(I.retrievalBand),p(I.retrievalConfidence),y(I.needsReview),j(I.activeModel),r(!1),x(null),_(!1);return}r(!0),x(null),_(!1);try{const se=(await Ft(()=>import("./vendor-firebase-auth-T_wvTOvf.js"),__vite__mapDeps([4,3])).then(re=>re.getAuth().currentUser))?.uid,C=await za({...s,lessonId:t,userId:se});l(C.sections),M(C.sources||[]),N(C.retrievalBand),p(C.retrievalConfidence),y(C.needsReview),j(C.activeModel),Yr(t,C),x(null),_(!1)}catch(B){const se=B.status||B.response?.status,C=B.body||B.response;let re="Failed to load lesson content.",ge=!1;se===404&&C?.error==="no_curriculum_context"?(re=C.message||"Lesson source PDF not found or not yet ingested.",ge=!0):se===401?re="Please sign in again to access lessons.":navigator.onLine||(re="No internet connection. Please try again when online.",ge=!0),x(re),_(ge),l([])}finally{r(!1)}},[t,n,JSON.stringify(s)]);a.useEffect(()=>{D()},[D]);const b=a.useCallback(()=>{t&&sessionStorage.removeItem(ms(t)),r(!0),x(null),D()},[D,t]);return{sections:i,isLoading:c,error:d,retry:b,sources:f,retrievalBand:u,retrievalConfidence:m,needsReview:k,activeModel:W,isOffline:E}}const Ks=/[=×÷±√∑∫π²³%]/,Zr=/^(Definition|Formula|Note|Reminder|Important|Example|Key Concept|Concept|Rule|Theorem|Property|Step)s?\s*:/i;function pt(t){return t.replace(/\b([A-Z][a-zA-Z\s]{2,30}?)\s+(is|are|refers to|defined as|means)\b/g,(s,n,i)=>`**${n.trim()}** ${i}`).replace(/"([^"]{3,40})"/g,(s,n)=>`**${n}**`)}function Vt(t){if(!t?.trim())return null;const s=t.split(` -`),n=[];let i=[],l=[],c=[],r=0;const d=()=>{if(i.length===0)return;const p=i.join(" ").trim();if(!p){i=[];return}const k=p.match(/[^.!?]+[.!?]+["']?/g)||[p],y=[];let W=[],j=0;for(const E of k)W.push(E),j+=E.length,j>220&&(y.push(W),W=[],j=0);W.length&&y.push(W);for(const E of y){const _=pt(E.join(" ").trim());n.push(e.jsx("p",{className:"lesson-body-text text-slate-700 leading-[1.8] text-[1rem] font-body",children:qe(_)},r++))}i=[]},x=()=>{l.length!==0&&(n.push(e.jsx("ul",{className:"space-y-2.5 my-1 pl-1",children:l.map((p,k)=>e.jsxs("li",{className:"flex items-start gap-3 text-slate-700 text-[0.95rem] leading-[1.75] font-body",children:[e.jsx("span",{className:"mt-[0.5rem] w-2 h-2 rounded-full bg-[#1a85a4] flex-shrink-0"}),e.jsx("span",{children:qe(pt(p))})]},k))},r++)),l=[])},f=()=>{c.length!==0&&(n.push(e.jsx("ol",{className:"space-y-2.5 my-1 list-none pl-1",children:c.map((p,k)=>e.jsxs("li",{className:"flex items-start gap-3 text-slate-700 text-[0.95rem] leading-[1.75] font-body",children:[e.jsx("span",{className:"mt-0.5 min-w-[1.5rem] h-[1.5rem] rounded-full bg-[#1a85a4] text-white text-[0.7rem] font-bold flex items-center justify-center flex-shrink-0",children:k+1}),e.jsx("span",{children:qe(pt(p))})]},k))},r++)),c=[])},M=p=>/^[\-•\*]\s+/.test(p.trim()),u=p=>/^\d+[\.\)]\s+/.test(p.trim()),N=p=>Ks.test(p)&&p.trim().length<120,m=p=>{const k=p.toLowerCase();return/formula|theorem|property|rule/.test(k)?{bg:"bg-amber-50",border:"border-amber-300",text:"text-amber-900",label:"FORMULA"}:/definition|concept|key/.test(k)?{bg:"bg-blue-50",border:"border-blue-300",text:"text-blue-900",label:"DEFINITION"}:/note|reminder|important/.test(k)?{bg:"bg-rose-50",border:"border-rose-300",text:"text-rose-900",label:"NOTE"}:/example|step/.test(k)?{bg:"bg-emerald-50",border:"border-emerald-300",text:"text-emerald-900",label:"EXAMPLE"}:{bg:"bg-slate-50",border:"border-slate-300",text:"text-slate-800",label:"TIP"}};for(const p of s){const k=p.trimEnd(),y=k.trim();if(y===""){x(),f(),d();continue}const W=y.match(Zr);if(W){x(),f(),d();const j=W[1],E=y.slice(W[0].length).trim(),_=m(j);n.push(e.jsxs("div",{className:`rounded-xl px-4 py-3.5 border-l-4 ${_.bg} ${_.border} my-1`,children:[e.jsxs("p",{className:`text-[0.75rem] font-black uppercase tracking-widest mb-1.5 ${_.text} opacity-80 font-display`,children:[_.label," ",j]}),e.jsx("p",{className:`text-[0.95rem] leading-[1.75] font-semibold font-body ${_.text}`,children:qe(E)})]},r++));continue}if(M(y)){d(),f(),l.push(y.replace(/^[\-•\*]\s+/,""));continue}if(u(y)){d(),x(),c.push(y.replace(/^\d+[\.\)]\s+/,""));continue}if(N(y)&&!/[a-z]{5,}/.test(y)){x(),f(),d(),n.push(e.jsx("div",{className:"lesson-formula-box my-3",children:y},r++));continue}if(y.endsWith(":")&&y.length<80&&!y.startsWith(" ")){x(),f(),d(),n.push(e.jsx("p",{className:"lesson-section-heading text-[#1a85a4] text-[1.05rem] mt-5 mb-1 border-b-2 border-[#1a85a4]/20 pb-1.5",children:qe(y)},r++));continue}x(),f(),i.push(k)}return x(),f(),d(),e.jsx("div",{className:"space-y-3",children:n})}function qe(t){const s=[],n=/(\*\*(.+?)\*\*|\*(.+?)\*|`(.+?)`|==(.+?)==)/g;let i=0,l,c=0;for(;(l=n.exec(t))!==null;)l.index>i&&s.push(e.jsx(je.Fragment,{children:t.slice(i,l.index)},c++)),l[2]?s.push(e.jsx("strong",{className:"font-extrabold text-[#1a85a4] bg-[#e0f4fa] px-1 py-0.5 rounded-md font-body",children:l[2]},c++)):l[3]?s.push(e.jsx("em",{className:"italic text-slate-500 font-body",children:l[3]},c++)):l[4]?s.push(e.jsx("code",{className:"px-1.5 py-0.5 bg-slate-100 rounded text-[0.85em] font-mono text-[#e66a5e] border border-slate-200 font-semibold",children:l[4]},c++)):l[5]&&s.push(e.jsx("mark",{className:"bg-[#fff3cd] text-[#92400e] px-1 py-0.5 rounded-md font-bold border-b-2 border-[#fbbf24]",children:l[5]},c++)),i=l.index+l[0].length;return i0?e.jsx(e.Fragment,{children:s}):t}function Jr(t){if(!t?.trim())return{welcome:"",objectives:[]};const s=t.split(` -`).map(d=>d.trim()).filter(Boolean),n=/^(\d+[\.\)]\s+|[-•*]\s+|(Identify|Write|Set|Use|Apply|Solve|Compute|Calculate|Determine|Understand|Describe|Explain|Analyze|Evaluate|Create|Define|Distinguish|Compare|Illustrate|Demonstrate|Perform|Simplify|Represent|Model|Interpret|Recognize|Classify|Construct|Derive|Formulate|Graph|Sketch|Verify|Prove|Estimate|Approximate|Convert|Translate|Predict|Justify|Generalize|Extend|Develop|Explore|Investigate|Discover|Observe|Measure|Record|Report|Present|Communicate|Collaborate|Reflect|Review|Summarize|Conclude|Infer|Hypothesize|Test|Experiment|Design|Plan|Implement|Evaluate|Assess|Monitor|Adjust|Improve|Optimize|Innovate|Create|Produce|Publish|Share|Teach|Learn|Practice|Apply|Transfer|Connect|Integrate|Synthesize|Analyze|Evaluate|Create)\b)/i,i=/^(Example:|e\.g\.|For example:|Sample:|\()/i,l=[],c=[];let r=!1;for(let d=0;d0&&t.callouts.map((p,k)=>e.jsxs("div",{className:`lesson-callout-headsup flex items-start gap-3.5 ${p.type==="tip"?"!bg-gradient-to-r !from-emerald-50 !to-teal-50 !border-emerald-400":""}`,children:[e.jsx("div",{className:`w-9 h-9 rounded-xl flex items-center justify-center flex-shrink-0 mt-0.5 shadow-sm ${p.type==="tip"?"bg-emerald-500":"bg-amber-500"}`,children:e.jsx(jt,{size:16,className:"text-white"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:`lesson-section-heading text-[0.65rem] uppercase tracking-[0.2em] mb-1 ${p.type==="tip"?"text-emerald-600":"text-amber-600"}`,children:p.type==="tip"?"Tip":p.type==="important"?"Heads Up":"Note"}),e.jsx("p",{className:"font-body text-[0.95rem] text-slate-700 leading-[1.75] font-medium",children:p.text})]})]},k)),(!t.callouts||t.callouts.length===0)&&e.jsxs("div",{className:"lesson-callout-headsup flex items-start gap-3.5",children:[e.jsx("div",{className:"w-9 h-9 rounded-xl bg-amber-500 flex items-center justify-center flex-shrink-0 mt-0.5 shadow-sm",children:e.jsx(jt,{size:16,className:"text-white"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"lesson-section-heading text-[0.65rem] uppercase tracking-[0.2em] mb-1 text-amber-600",children:"Heads Up"}),e.jsxs("p",{className:"font-body text-[0.95rem] text-slate-700 leading-[1.75] font-medium",children:["This lesson has ",7," sections and takes about 20 minutes to complete. Grab a pen — you might want to take notes along the way!"]})]})]}),N.length>0&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(ft,{size:20,className:"text-violet-500"}),e.jsx("h3",{className:"lesson-section-heading text-[1.05rem]",style:{color:"#7c3aed"},children:"What you'll learn"})]}),e.jsx("div",{className:"space-y-2.5",children:N.map((p,k)=>{const y=Ls[k%Ls.length];return e.jsxs("div",{className:`rounded-xl border-2 px-4 py-3.5 flex items-start gap-3.5 ${y.bg} ${y.border} shadow-sm`,children:[e.jsx("span",{className:`mt-0.5 min-w-[1.75rem] h-7 rounded-full ${y.num} text-white text-[0.7rem] font-black flex items-center justify-center flex-shrink-0 shadow-sm`,children:k+1}),e.jsxs("div",{children:[e.jsx("p",{className:`font-body text-[0.95rem] font-semibold leading-snug ${y.text}`,children:qe(pt(p.text))}),p.example&&e.jsx("p",{className:`text-xs mt-1 ${y.ex} font-mono font-semibold`,children:p.example})]})]},k)})})]})]})}case"key_concepts":return e.jsxs("div",{className:"space-y-4",children:[t.content?.trim()?e.jsx("div",{className:"mb-4",children:Vt(t.content)}):e.jsx("p",{className:"text-slate-400 text-sm italic mb-4",children:"Key concepts are being compiled. Review the curriculum sources below for reference material."}),t.callouts&&t.callouts.length>0&&e.jsx("div",{className:"space-y-3",children:t.callouts.map((u,N)=>e.jsxs("div",{className:`rounded-xl border-2 px-5 py-4 flex items-start gap-3.5 shadow-sm ${u.type==="important"?"bg-rose-50 border-rose-300":u.type==="tip"?"bg-emerald-50 border-emerald-300":"bg-amber-50 border-amber-300"}`,children:[e.jsx("div",{className:`w-9 h-9 rounded-xl flex items-center justify-center flex-shrink-0 mt-0.5 shadow-sm ${u.type==="important"?"bg-rose-500":u.type==="tip"?"bg-emerald-500":"bg-amber-500"}`,children:e.jsx(jt,{size:16,className:"text-white"})}),e.jsxs("div",{children:[e.jsx("p",{className:`lesson-section-heading text-[0.65rem] uppercase tracking-[0.2em] mb-1 ${u.type==="important"?"text-rose-500":u.type==="tip"?"text-emerald-600":"text-amber-600"}`,children:u.type==="important"?"Important":u.type==="tip"?"Tip":"Note"}),e.jsx("p",{className:"font-body text-[0.95rem] text-slate-700 leading-[1.75] font-medium",children:qe(u.text)})]})]},N))})]});case"video":return e.jsxs("div",{className:"space-y-4",children:[t.content?.trim()?e.jsx("p",{className:"text-slate-600 text-sm",children:t.content}):e.jsx("p",{className:"text-slate-400 text-sm italic",children:"Video explanation loading..."}),e.jsx(Ma,{videos:t.videos||[],topic:l.title})]});case"worked_examples":return e.jsx("div",{className:"space-y-5",children:t.examples&&t.examples.length>0?t.examples.map((u,N)=>e.jsxs("div",{className:"bg-gradient-to-br from-rose-50 via-orange-50 to-amber-50 rounded-2xl p-5 border-2 border-rose-200 shadow-md",children:[e.jsxs("div",{className:"flex items-start gap-3.5 mb-4",children:[e.jsx("div",{className:"w-10 h-10 bg-gradient-to-br from-rose-500 to-orange-500 rounded-xl flex items-center justify-center flex-shrink-0 shadow-md",children:e.jsx(wt,{size:18,className:"text-white"})}),e.jsxs("div",{children:[e.jsxs("p",{className:"lesson-section-heading text-[0.65rem] uppercase tracking-[0.2em] text-rose-400 mb-1",children:["Example ",N+1]}),e.jsx("p",{className:"font-body font-bold text-slate-800 text-[1rem] leading-snug",children:u.problem})]})]}),u.steps.length>0&&e.jsxs("div",{className:"ml-14 space-y-2.5 mb-3",children:[e.jsx("p",{className:"lesson-section-heading text-[0.65rem] uppercase tracking-[0.2em] text-slate-400 mb-1.5",children:"Solution"}),u.steps.map((m,p)=>Ks.test(m)&&m.length<100&&!/[a-z]{6,}/.test(m)?e.jsx("div",{className:"lesson-formula-box",children:m},p):e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"mt-0.5 min-w-[1.5rem] h-[1.5rem] rounded-full bg-white border-2 border-rose-300 text-rose-500 text-[0.65rem] font-black flex items-center justify-center flex-shrink-0 shadow-sm",children:p+1}),e.jsx("p",{className:"font-body text-slate-700 text-[0.95rem] leading-[1.75]",children:qe(m)})]},p))]}),u.answer&&e.jsxs("div",{className:"ml-14 flex items-center gap-3 mt-3 pt-3 border-t-2 border-rose-200",children:[e.jsx("div",{className:"px-3.5 py-1.5 bg-gradient-to-r from-rose-500 to-orange-500 rounded-lg text-white text-[0.65rem] font-black uppercase tracking-widest flex-shrink-0 shadow-sm",children:"Answer"}),e.jsx("p",{className:"font-body text-slate-800 text-[0.95rem] font-bold",children:u.answer})]})]},N)):e.jsx("p",{className:"text-slate-400 text-sm italic",children:"No worked examples available for this lesson."})});case"important_notes":return e.jsx("div",{className:"space-y-3",children:t.bulletPoints&&t.bulletPoints.length>0?t.bulletPoints.map((u,N)=>{const m=u.match(/^(Note|Important|Remember|Warning|Tip|Key|Formula|Rule)\s*:/i);if(m){const p=m[1],k=u.slice(m[0].length).trim(),y=/note|important|warning|remember/i.test(p);return e.jsxs("div",{className:`rounded-xl px-5 py-4 border-l-4 flex items-start gap-3.5 shadow-sm ${y?"bg-rose-50 border-rose-400":"bg-amber-50 border-amber-400"}`,children:[e.jsx(jt,{size:18,className:`mt-0.5 flex-shrink-0 ${y?"text-rose-500":"text-amber-500"}`}),e.jsxs("div",{children:[e.jsx("p",{className:`lesson-section-heading text-[0.65rem] uppercase tracking-[0.2em] mb-1 ${y?"text-rose-500":"text-amber-600"}`,children:p}),e.jsx("p",{className:"font-body text-[0.95rem] text-slate-700 leading-[1.75] font-medium",children:qe(pt(k))})]})]},N)}return e.jsxs("div",{className:"flex items-start gap-3.5 p-4 rounded-xl bg-slate-50 border-2 border-slate-200 hover:border-[#1a85a4]/40 hover:bg-[#f0fbff] transition-colors",children:[e.jsx("div",{className:"mt-0.5 w-6 h-6 rounded-full bg-[#1a85a4] flex items-center justify-center flex-shrink-0 shadow-sm",children:e.jsx("span",{className:"text-white text-[0.65rem] font-black",children:N+1})}),e.jsx("p",{className:"font-body text-slate-700 text-[0.95rem] leading-[1.75] font-medium",children:qe(pt(u))})]},N)}):e.jsx("p",{className:"text-slate-400 text-sm italic",children:"No notes available for this lesson."})});case"try_it_yourself":return e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"flex flex-col items-center text-center gap-3 py-4",children:[e.jsx("div",{className:"w-16 h-16 rounded-full flex items-center justify-center shadow-lg",style:{background:"#9956DE"},children:e.jsx(ft,{size:32,className:"text-white"})}),e.jsx("h3",{className:"text-xl font-black",style:{color:"#9956DE"},children:"Try It Yourself"}),e.jsx("p",{className:"text-slate-500 text-sm max-w-xs leading-relaxed",children:"Now it's your turn! Try applying what you've learned. You can practice with the exercises at the end of this module."})]}),e.jsxs("div",{className:"flex items-start gap-2 rounded-xl px-4 py-3 border",style:{background:"#f5eeff",borderColor:"#d4aaff"},children:[e.jsx(jt,{size:16,className:"mt-0.5 shrink-0",style:{color:"#9956DE"}}),e.jsxs("p",{className:"text-sm",style:{color:"#7a3db8"},children:[e.jsx("span",{className:"font-bold",children:"Tip:"})," Complete the practice quizzes after this lesson to reinforce your learning!"]})]}),c&&e.jsx("div",{className:"bg-white rounded-2xl p-5 border border-slate-200 shadow-sm",children:r?e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 bg-emerald-100 rounded-xl flex items-center justify-center",children:e.jsx(ft,{size:20,className:"text-emerald-600"})}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-sm font-bold text-emerald-700",children:["Quiz Complete",typeof d=="number"&&e.jsxs("span",{className:"ml-2 text-emerald-600",children:[d,"%"]})]}),e.jsx("p",{className:"text-xs text-emerald-600/80",children:"Great job! You can now complete this lesson."})]})]}):e.jsxs("div",{className:"flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] font-black uppercase tracking-widest mb-1",style:{color:"#9956DE"},children:"Practice Quiz"}),e.jsx("p",{className:"font-bold text-slate-800 text-sm",children:c.title}),e.jsxs("p",{className:"text-xs text-slate-500 mt-0.5",children:[c.questions," questions · ",c.duration]})]}),e.jsx("button",{onClick:x,className:"w-full sm:w-auto px-6 py-2.5 rounded-xl bg-[#1a85a4] text-white text-sm font-black hover:bg-[#126b84] transition-colors shadow-md uppercase tracking-wide",children:"Start Practice"})]})}),!c&&e.jsxs("button",{onClick:M,className:"w-full flex items-center justify-between gap-4 text-white rounded-2xl px-6 py-4 shadow-lg transition-all hover:shadow-xl hover:scale-[1.01] active:scale-[0.99] group",style:{background:"#9956DE"},onMouseEnter:u=>u.currentTarget.style.background="#8744cc",onMouseLeave:u=>u.currentTarget.style.background="#9956DE",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 bg-white/20 rounded-xl flex items-center justify-center shrink-0",children:e.jsx(Ka,{size:22,className:"text-white"})}),e.jsxs("div",{className:"text-left",children:[e.jsx("p",{className:"font-black text-sm uppercase tracking-wide",children:"Start Practice Quiz"}),e.jsx("p",{className:"text-white/80 text-xs mt-0.5",children:"10 questions · AI-generated"})]})]}),e.jsx(ht,{size:20,className:"text-white/80 group-hover:translate-x-1 transition-transform"})]})]});case"summary":return e.jsx("div",{className:"space-y-3",children:t.content?.trim()?Vt(t.content):e.jsx("p",{className:"text-slate-400 text-sm italic",children:"Summary is being prepared. Review the lesson sections above to reinforce your understanding."})});default:return e.jsx("p",{className:"text-slate-500 text-sm italic",children:"Section content not available."})}}const _t=[{type:"introduction",label:"Intro",helper:"Welcome note",icon:Nt,accent:"from-[#1a85a4] to-[#126b84]",tint:"bg-[#1a85a4] text-white border-transparent",tabBg:"bg-[#1a85a4]"},{type:"key_concepts",label:"Concepts",helper:"Core ideas",icon:cr,accent:"from-[#fbab41] to-[#e0983a]",tint:"bg-[#fbab41] text-white border-transparent",tabBg:"bg-[#fbab41]"},{type:"video",label:"Video",helper:"Watch and learn",icon:jt,accent:"from-[#e66a5e] to-[#ce5e53]",tint:"bg-[#e66a5e] text-white border-transparent",tabBg:"bg-[#e66a5e]"},{type:"worked_examples",label:"Examples",helper:"Guided solving",icon:Pa,accent:"from-[#7ec16d] to-[#71ad62]",tint:"bg-[#7ec16d] text-white border-transparent",tabBg:"bg-[#7ec16d]"},{type:"important_notes",label:"Notes",helper:"Key reminders",icon:mr,accent:"from-[#9a67d0] to-[#8a5cc0]",tint:"bg-[#9a67d0] text-white border-transparent",tabBg:"bg-[#9a67d0]"},{type:"try_it_yourself",label:"Practice",helper:"Try it yourself",icon:et,accent:"from-[#eb74a6] to-[#d46895]",tint:"bg-[#eb74a6] text-white border-transparent",tabBg:"bg-[#eb74a6]"},{type:"summary",label:"Summary",helper:"Wrap-up",icon:Tt,accent:"from-[#48bca6] to-[#40a794]",tint:"bg-[#48bca6] text-white border-transparent",tabBg:"bg-[#48bca6]"}],an=({lesson:t,lessonCompletionXP:s=10,practiceQuiz:n,practiceQuizCompleted:i=!1,practiceQuizScore:l,initialSection:c=0,onStartPractice:r,onBack:d,onComplete:x,onProgressUpdate:f,onTryItQuizComplete:M,onContinueLearning:u})=>{const{userProfile:N}=Bt(),[m,p]=a.useState(0),[k,y]=a.useState(1),[W,j]=a.useState(!1),[E,_]=a.useState(null),[D,b]=a.useState(!1),[I,B]=a.useState(null),[se,C]=a.useState(!1);a.useEffect(()=>{!D||I||(C(!0),Wr({lessonId:t.id?.toString()||"unknown",lessonTitle:t.title,topic:t.title,subjectId:t.subjectId,competencyCode:t.competencyCode,questionCount:10}).then(F=>B(F)).catch(F=>{console.error("[LessonViewer] Quiz generation failed:",F),b(!1)}).finally(()=>C(!1)))},[D,I,t]);const[re,ge]=a.useState(!1),Oe={topic:t.title,subject:t.subject||"General Mathematics",quarter:t.quarter||1,lessonTitle:t.title,moduleId:t.subjectId,lessonId:t.id,competencyCode:t.competencyCode,learnerLevel:"Grade 11-12",storagePath:t.storagePath},{sections:oe,isLoading:Qe,error:Se,retry:G,sources:ve,retrievalBand:We,activeModel:_e,isOffline:Ve}=Kr(t.id,Oe,!0),[$e,Ue]=a.useState(null);a.useEffect(()=>{if(oe.length>0){const F=oe.find(ee=>ee.type==="introduction");if(F?.title){const ue=F.title.replace(/^Introduction\s+(to|-|:|—)\s+/i,"").replace(/\s*[-:—]\s*Introduction$/i,"").replace(/\s+Introduction$/i,"").trim();ue&&ue.toLowerCase()!=="introduction"&&Ue(ue)}}},[oe]),a.useEffect(()=>{oe.length>0&&N?.uid&&t.id&&Ta(N.uid,t.id,$e||t.title).catch(()=>{})},[oe.length,N?.uid,t.id,$e,t.title]);const h=oe.length||_t.length;if(a.useEffect(()=>{c>=0&&c{const F=oe.findIndex(ee=>ee.type==="try_it_yourself");c===-1&&F>=0&&p(F)},[oe,c]),a.useEffect(()=>{const F=h>0?(m+1)/h*100:0;f?.(F)},[m,h,f]),Qe)return e.jsx(en,{});if(Se&&oe.length===0)return e.jsx(tn,{message:Se,onRetry:G,isOffline:Ve});const A=String(t.id||"").match(/\d+/);if(A&&A[0],D)return se||!I?e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm",children:e.jsxs("div",{className:"bg-white rounded-2xl p-6 flex flex-col items-center gap-3 shadow-xl",children:[e.jsx("div",{className:"w-10 h-10 border-4 border-indigo-500 border-t-transparent rounded-full animate-spin"}),e.jsx("p",{className:"font-bold text-slate-700",children:"Generating Quiz..."})]})}):e.jsx(Or,{lesson:{id:parseInt(String(t.id||"1").replace(/\D/g,"")||"1"),title:t.title,duration:"15 min",type:"quiz",completed:!1,locked:!1},questions:I,onBack:()=>{b(!1),B(null)},onComplete:F=>{const ee=Math.round(F/(I?.length||10)*100);M?.(ee),ge(!0),b(!1),B(null)}});const T=oe[m]||{type:"introduction",title:"Loading...",content:"Lesson content is loading. Please wait a moment."},X=()=>{mF+1)):(!n||i)&&j(!0)},$=()=>{m>0&&(y(-1),p(F=>F-1))},Z=F=>{x(void 0,void 0,F)},le=!!(n&&!i||!re),Ae=_t[m]||_t[0],fe=Ae.icon,be=e.jsxs("div",{className:"fixed inset-0 z-50 flex flex-col bg-slate-50 overflow-hidden font-sans",children:[e.jsx("header",{className:"flex-none bg-transparent px-3 sm:px-6 pt-2 sm:pt-3 md:pt-4 pb-2 sm:pb-3 sm:py-4 relative z-40",children:e.jsxs("div",{className:"max-w-[90rem] mx-auto flex items-center justify-between gap-2 sm:gap-4",children:[e.jsxs("div",{className:"flex items-center gap-2 sm:gap-4 min-w-0 flex-1",children:[e.jsx("button",{onClick:d,className:"w-9 h-9 sm:w-10 sm:h-10 rounded-full bg-white border border-slate-200 hover:bg-slate-50 flex items-center justify-center text-slate-600 transition-colors flex-shrink-0 shadow-sm","aria-label":"Go back",children:e.jsx(Zt,{size:16})}),e.jsxs("div",{className:"min-w-0 flex flex-col justify-center flex-1",children:[e.jsxs("div",{className:"hidden sm:flex items-center gap-1.5 sm:gap-2 text-[9px] sm:text-[10px] font-bold text-slate-500 uppercase tracking-widest mb-0.5",children:[e.jsx(Fe,{size:10}),e.jsx("span",{children:"NOTEBOOK"}),_e&&e.jsx("span",{className:"text-slate-400 bg-slate-100 px-1.5 py-0.5 rounded font-mono",children:_e.split("/").pop()}),We==="high"&&e.jsx("span",{className:"text-emerald-600 bg-emerald-50 px-1.5 py-0.5 rounded text-[10px] font-semibold border border-emerald-200",children:"DepEd Source"})]}),e.jsxs("div",{className:"flex sm:hidden items-center gap-1 text-[9px] font-bold text-slate-400 uppercase tracking-widest mb-0.5",children:[e.jsx(Fe,{size:9}),e.jsx("span",{children:"Notebook"}),We==="high"&&e.jsx("span",{className:"text-emerald-600 bg-emerald-50 px-1 py-0.5 rounded text-[8px] font-semibold border border-emerald-200 leading-none",children:"DepEd"})]}),e.jsx("h1",{className:"font-bold text-slate-800 text-xs sm:text-sm truncate",children:t.title})]})]}),e.jsxs("div",{className:"flex items-center gap-2 sm:gap-4 flex-shrink-0",children:[e.jsxs("div",{className:"text-right hidden sm:block",children:[e.jsx("p",{className:"text-[10px] font-bold text-slate-500 uppercase tracking-wider",children:"Progress"}),e.jsxs("p",{className:"text-sm font-bold text-slate-800",children:[Math.round((m+1)/h*100),"%"]})]}),e.jsx("div",{className:"w-12 sm:w-24 md:w-32 h-1.5 sm:h-2 bg-slate-200 rounded-full overflow-hidden",children:e.jsx(S.div,{className:"h-full bg-[#7ec16d] rounded-full",animate:{width:`${(m+1)/h*100}%`},transition:{duration:.25}})})]})]})}),e.jsx("main",{className:"flex-1 overflow-hidden px-2 sm:px-5 pb-2 relative flex justify-center min-h-0",children:e.jsxs("div",{className:"w-full max-w-[90rem] h-full relative flex md:pl-16 pt-10 sm:pt-10 md:pt-0",children:[e.jsx("div",{className:"hidden md:flex absolute left-0 top-8 bottom-8 w-20 flex-col justify-between z-0 py-2",children:_t.map((F,ee)=>{const ue=ee===m,Be=F.icon;return e.jsxs("button",{onClick:()=>{y(ee>m?1:-1),p(ee)},className:It("group relative flex items-center justify-start pl-4 rounded-l-[1.5rem] transition-all duration-300 shadow-sm border-r-0 flex-shrink-0",F.tabBg,ue?"w-24 h-20 -translate-x-4 shadow-xl z-20 brightness-105":"w-16 h-16 hover:w-24 hover:h-20 hover:-translate-x-4 hover:brightness-110 opacity-90 hover:opacity-100 z-10"),"aria-label":`Go to ${F.label} section`,children:[e.jsx("div",{className:It("transition-all duration-300 rounded-xl",ue?"bg-white/30 p-2.5":"bg-white/20 p-2 group-hover:bg-white/30 group-hover:p-2.5"),children:e.jsx(Be,{size:ue?24:20,className:"text-white transition-transform duration-300 group-hover:scale-110"})}),e.jsxs("div",{className:"absolute right-full mr-3 px-3 py-1.5 bg-slate-800 text-white text-xs font-bold rounded-lg opacity-0 group-hover:opacity-100 pointer-events-none transition-opacity whitespace-nowrap z-[100] shadow-xl border border-slate-700/50",children:[e.jsx("div",{className:"absolute top-1/2 -right-1 -translate-y-1/2 w-2 h-2 bg-slate-800 rotate-45 border-r border-t border-slate-700/50"}),F.label]})]},F.type)})}),e.jsx("div",{className:"md:hidden absolute left-0 right-0 top-0 z-30 bg-slate-100/95 backdrop-blur-sm",children:e.jsx("div",{className:"flex gap-0.8 overflow-x-auto [-ms-overflow-style:none] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden px-1",children:_t.map((F,ee)=>{const ue=ee===m,Be=F.icon;return e.jsxs("button",{onClick:()=>{y(ee>m?1:-1),p(ee)},className:It("flex items-center gap-1.5 px-3 py-2 rounded-t-lg transition-all duration-200 shrink-0 text-[11px] font-bold touch-manipulation min-h-[2.5rem]",ue?`${F.tabBg} text-white shadow-md`:"bg-slate-200/80 text-slate-500"),children:[e.jsx(Be,{size:14}),e.jsx("span",{children:F.label})]},F.type)})})}),e.jsxs("div",{className:It("flex-1 min-w-0 rounded-none sm:rounded-lg shadow-2xl flex flex-col overflow-visible relative z-10 transition-colors duration-500",Ae.tabBg),children:[e.jsxs("div",{className:"px-3 sm:px-6 py-2 sm:py-3.5 flex items-center gap-2 sm:gap-4 text-white",children:[e.jsx("div",{className:"bg-white/20 p-1 sm:p-2 rounded-lg sm:rounded-xl shrink-0",children:e.jsx(fe,{size:16,className:"text-white"})}),e.jsxs("div",{className:"flex flex-col min-w-0",children:[e.jsx("h2",{className:"lesson-section-heading text-sm sm:text-xl md:text-2xl truncate",title:T.title,children:T.title}),e.jsx("p",{className:"text-white/90 text-[10px] sm:text-xs font-medium truncate mt-0.5 font-body",title:t.title,children:t.title})]})]}),e.jsxs("div",{className:"flex-1 min-h-0 bg-[#fdfdfd] rounded-lg sm:rounded-[1.5rem] m-1 mt-0 relative overflow-hidden shadow-inner flex flex-col",children:[e.jsx("div",{className:"absolute inset-0 pointer-events-none opacity-30",style:{backgroundImage:"linear-gradient(transparent 95%, #cbd5e1 95%)",backgroundSize:"100% 40px",backgroundPosition:"0 0"}}),e.jsx("div",{className:"absolute top-0 bottom-0 left-8 sm:left-12 md:left-16 w-[2px] bg-rose-300/60 pointer-events-none z-0"}),e.jsx("div",{className:"relative z-10 flex-1 min-h-0 overflow-y-auto px-3 sm:px-5 md:pl-20 md:pr-10 py-2 sm:py-6",children:e.jsx(ot,{mode:"wait",children:e.jsxs(S.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},transition:{duration:.2},className:"space-y-4 sm:space-y-6",children:[e.jsx("div",{className:"bg-white/90 backdrop-blur-sm rounded-xl sm:rounded-[1.5rem] p-4 sm:p-6 md:p-8 shadow-sm border border-slate-100/50 font-body",children:e.jsx(sn,{section:T,sectionIndex:m,onShowSolution:F=>_(E===F?null:F),expandedIndex:E,lesson:t,practiceQuiz:n,practiceQuizCompleted:i,practiceQuizScore:l,onStartPractice:r,lessonSpecificTopic:$e,onStartTryItQuiz:()=>b(!0)})}),ve.length>0&&(N?.role==="admin"||N?.role==="teacher")&&e.jsxs("details",{className:"rounded-xl border border-slate-200 bg-white/90 backdrop-blur-sm px-4 py-3 text-xs text-slate-500 shadow-sm",children:[e.jsxs("summary",{className:"cursor-pointer font-semibold text-slate-600 hover:text-slate-800",children:[ve.length," source",ve.length>1?"s":""," used"]}),e.jsx("div",{className:"mt-2 space-y-1 pl-2",children:ve.slice(0,3).map((F,ee)=>e.jsxs("p",{className:"font-mono truncate",children:[F.source_file," p.",F.page," (",Math.round((F.score||0)*100),"%)"]},ee))})]})]},m)})},m)]})]})]})}),e.jsx("footer",{className:"bg-slate-50 border-t border-slate-100 px-3 sm:px-6 flex-shrink-0 relative z-50 w-full flex justify-center items-center py-1.5 sm:py-3",children:e.jsxs("div",{className:"w-full max-w-[90rem] flex flex-col items-center",children:[e.jsxs("div",{className:"flex items-center justify-center gap-4 sm:gap-8 w-full md:ml-16",children:[e.jsxs(Me,{onClick:$,disabled:m===0,variant:"outline",className:"px-4 sm:px-5 py-2 sm:py-2 rounded-full font-bold text-xs sm:text-sm bg-white border-slate-200 text-slate-600 shadow-sm disabled:opacity-40 hover:bg-slate-50 transition-colors flex items-center gap-1 sm:gap-2 min-w-[2.5rem] min-h-[2.5rem] touch-manipulation",children:[e.jsx(Zt,{size:14}),e.jsx("span",{className:"hidden sm:inline",children:"Previous"})]}),e.jsxs("p",{className:"text-xs sm:text-sm text-slate-500 font-bold tabular-nums",children:[m+1," / ",h]}),e.jsx(Me,{onClick:X,disabled:m===h-1&&le,className:"px-5 sm:px-7 py-2 sm:py-2 rounded-full font-bold text-xs sm:text-sm bg-[#7ec16d] text-white hover:bg-[#6ab359] shadow-md transition-colors disabled:opacity-40 flex items-center gap-1 sm:gap-2 min-w-[2.5rem] min-h-[2.5rem] touch-manipulation",children:m===h-1?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"hidden sm:inline",children:"Complete"}),e.jsx(ft,{size:14})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"hidden sm:inline",children:"Next"}),e.jsx(ht,{size:14})]})})]}),m===h-1&&le&&e.jsx("p",{className:"text-center text-[10px] sm:text-xs font-semibold text-amber-600 mt-2 sm:mt-3 md:ml-16",children:re?"Complete the practice quiz first to unlock lesson completion.":"Complete the Try It Yourself quiz first to unlock lesson completion."})]})}),e.jsx(ot,{children:W&&e.jsx(S.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"absolute inset-0 z-[100] flex items-center justify-center bg-slate-900/40 backdrop-blur-sm p-4",children:e.jsxs(S.div,{initial:{scale:.9,opacity:0},animate:{scale:1,opacity:1},className:"bg-white rounded-[2rem] p-8 max-w-sm w-full text-center shadow-2xl",children:[e.jsx("div",{className:"w-20 h-20 bg-[#7ec16d] rounded-full flex items-center justify-center mx-auto mb-5 shadow-lg",children:e.jsx(ft,{size:40,className:"text-white"})}),e.jsx("h2",{className:"text-2xl font-black text-slate-800 mb-2",children:"Lesson Complete!"}),e.jsxs("p",{className:"text-slate-500 text-sm mb-6 leading-relaxed",children:["Great job finishing ",e.jsx("strong",{className:"text-slate-700",children:t.title}),"."]}),e.jsxs("div",{className:"bg-emerald-50 rounded-2xl p-4 mb-6 border border-emerald-100",children:[e.jsx("div",{className:"flex items-center justify-center mb-1",children:e.jsx(Tt,{className:"text-[#7ec16d]",size:22})}),e.jsx("p",{className:"text-xs text-[#7ec16d] font-bold uppercase tracking-wider mb-0.5",children:"XP Earned"}),e.jsxs("p",{className:"text-3xl font-black text-[#7ec16d]",children:["+",s]})]}),e.jsxs("div",{className:"space-y-2.5",children:[e.jsx("button",{onClick:()=>Z(!0),disabled:le,className:"w-full py-3 rounded-xl font-bold text-sm bg-[#1a85a4] text-white hover:bg-[#126b84] transition-colors disabled:opacity-40 disabled:cursor-not-allowed",children:"Continue to Next Lesson"}),e.jsx("button",{onClick:()=>Z(!1),className:"w-full py-3 rounded-xl font-bold text-sm bg-slate-100 text-slate-600 hover:bg-slate-200 transition-colors",children:"Back to Modules"})]})]})})})]}),Te=document.getElementById("modal-root")||document.body;return sa.createPortal(be,Te)},rn={maxRetries:2,timeoutMs:9e4,baseBackoffMs:2e3},Zs=async t=>$t("/api/practice/generate",{method:"POST",body:JSON.stringify(t)},rn),nn=async t=>$t("/api/practice/submit",{method:"POST",body:JSON.stringify(t)}),ln=async t=>$t(`/api/practice/stats/${t}`,{method:"GET"}),on=({module:t,onBack:s,onEarnXP:n,isInQuizMode:i=!1,setIsInQuizMode:l})=>{const[r,d]=a.useState(null),{userProfile:x}=Bt(),[f,M]=a.useState(null),[u,N]=a.useState(!1),[m,p]=a.useState(null);a.useEffect(()=>{if(!x?.uid)return;(async()=>{try{const[A,T]=await Promise.all([Yt(kt(tt,"diagnosticResults",x.uid)),Yt(kt(tt,"competencyProfiles",x.uid))]),X=A.exists()&&A.data()?.status==="completed",$=T.exists()&&(T.data()?.overallScore??0)>0;N(X||$)}catch{N(!1)}})()},[x?.uid]);const k=a.useRef(n);a.useEffect(()=>{k.current=n},[n]);const y=a.useRef(r);a.useEffect(()=>{y.current=r},[r]),a.useEffect(()=>{try{const h=sessionStorage.getItem(`mathpulse_module_${t.id}_selectedLesson`);if(h){const{lessonId:A}=JSON.parse(h),T=t.lessons.find(X=>X.id===A);T&&d({lesson:T,type:"lesson"})}}catch{}},[]),a.useEffect(()=>{if(r?.type==="lesson"&&r.lesson)try{sessionStorage.setItem(`mathpulse_module_${t.id}_selectedLesson`,JSON.stringify({lessonId:r.lesson.id}))}catch{}else if(r===null)try{sessionStorage.removeItem(`mathpulse_module_${t.id}_selectedLesson`)}catch{}},[r,t.id]);const W=a.useMemo(()=>{const h=Number(t.id.split("-").pop());return Number.isFinite(h)&&h>0?h:1},[t.id]),j=a.useMemo(()=>{const h=t.subjectId;return h||(Dt.find(T=>T.modules.some(X=>X.id===t.id))?.id??null)},[t.id]),E=["#1FA7E1","#9956DE","#75D06A","#FFB356","#7274ED","#FF8B8B","#6ED1CF","#FB96BB"];a.useMemo(()=>{const h=t.subjectAccentColor;if(h)return h;const T=(j?Dt.find($=>$.id===j):null)?.modules?.findIndex($=>$.id===t.id)??0,X=T>=0?T:0;return E[X%E.length]},[t,t.id,j]),a.useEffect(()=>{if(x?.uid)return us(x.uid,M)},[x?.uid]),a.useEffect(()=>{if(!r||r.type!=="quiz"||!x?.uid)return;let h=!1;const T=Dt.find(X=>X.modules.some($=>$.id===t.id))?.title??"General Mathematics";return(async()=>{try{const X=await Zs({userId:x.uid,subject:T,competency:r.quiz.title.replace(/^(Practice Quiz|Module Quiz):\s*/i,""),difficulty:r.quiz.type==="module"?"Challenge":"Practice",count:r.quiz.questions||5});if(h)return;const $=X.questions.filter(Z=>Z.options?.length&&Z.correct_index>=0&&Z.correct_index({id:Z.id||"q-"+le,questionType:"multiple_choice",question:Z.question,options:Z.options,correctAnswer:Z.options[Z.correct_index],bloomLevel:Z.bloomsLevel?.toLowerCase()||"understand",difficulty:"medium",topic:r.quiz.title,subject:T,points:10,explanation:Z.explanation||""}));p($)}catch(X){console.error("[ModuleDetailView] Quiz generation failed:",X);const $=r.quiz.questions||5,Z=Array.from({length:$}).map((le,Ae)=>{const fe=Math.floor(Math.random()*20)+2,be=Math.floor(Math.random()*20)+2,Te=(fe+be).toString();return{id:"fallback-"+Ae,questionType:"multiple_choice",question:`Compute: ${fe} + ${be}`,options:[Te,(fe*be).toString(),Math.abs(fe-be).toString(),(fe+be+1).toString()],correctAnswer:Te,bloomLevel:"remember",difficulty:"easy",topic:r.quiz.title,subject:T,points:10,explanation:`${fe} + ${be} = ${Te}`}});h||p(Z)}})(),()=>{h=!0}},[r,x?.uid,t.id]);const _=a.useMemo(()=>j?f?.subjects?.[j]?.modulesProgress?.[t.id]??null:null,[t.id,j,f?.subjects]),[D,b]=a.useState(null),I=a.useMemo(()=>{const h=_?.lessonsCompleted??[];return new Set(h)},[_?.lessonsCompleted]),B=a.useMemo(()=>{const h=_?.quizzesCompleted??[];return new Set(h)},[_?.quizzesCompleted]),se=_?.lessonsCompleted?.length??t.lessons.filter(h=>h.completed).length,C=_?.quizzesCompleted?.length??t.quizzes.filter(h=>h.completed).length,re=_?.progress??t.progress,ge=t.lessons.length+t.quizzes.length,Oe=se+C;t.lessons.length&&se/t.lessons.length*100,t.quizzes.length&&C/t.quizzes.length*100;const oe=(h,A)=>{const T=f?.lessons?.[h]?.score;return typeof T=="number"&&Number.isFinite(T)?Math.max(0,Math.min(100,T)):A?100:0},Qe=a.useMemo(()=>{if(!ge)return 0;const h=t.lessons.reduce((T,X)=>{const $=I.has(X.id)||X.completed;return T+oe(X.id,$)},0),A=C*100;return Math.round((h+A)/ge)},[I,C,t.lessons,t.quizzes.length,ge,f?.lessons]),Se=re>0?re:Qe,G=a.useMemo(()=>{const h=t.quizzes.find(T=>T.type==="final"||/module\s+quiz|general\s+quiz/i.test(T.title));if(h)return h;const A=t.quizzes.find(T=>T.isStandalone===!0);return A||(t.quizzes.length?t.quizzes[0]:null)},[t.quizzes]),ve=a.useMemo(()=>{const h=new Map;t.lessons.forEach(T=>{h.set(T.id,[])});const A=t.lessons.length;return A===0||t.quizzes.forEach((T,X)=>{if(G?.id===T.id)return;const $=Math.min(X,A-1),Z=t.lessons[$];if(!Z)return;const le=h.get(Z.id)??[];le.push(T),h.set(Z.id,le)}),h},[t.lessons,t.quizzes,G?.id]),We=a.useMemo(()=>Math.max(1,Math.ceil(t.lessons.length/2)),[t.lessons.length]),_e=a.useCallback(()=>{d(null),b(null)},[]),Ve=a.useCallback(()=>{const h=y.current?.type==="lesson"?y.current.lesson:null;if(!h)return;const A={id:`${h.id}-practice`,title:`Practice Quiz: ${h.title}`,questions:Ur(),duration:h.duration,completed:!1,locked:!1,type:"practice"};b(h),d({type:"quiz",quiz:A})},[]),$e=a.useCallback((h,A,T)=>{const X=y.current;if(X?.type!=="lesson"||!X.lesson)return;const $=X.lesson,Z=10;if(k.current?.(Z,`Completed "${$.title}"`),x?.uid&&j&&(async()=>{try{await ma(x.uid,j,t.id,$.id,0,Z),await ps(x.uid,j,t.id,t.lessons.length,t.quizzes.length)}catch(le){console.error("[LessonComplete] Failed to persist progress:",le)}})(),T){const le=t.lessons.findIndex(Ae=>Ae.id===$.id);le!==-1&&le0?d({type:"quiz",quiz:t.quizzes[0]}):d(null)}else d(null)},[j,t.id,t.lessons.length,t.quizzes.length]),Ue=a.useCallback(h=>{if(!x?.uid||!y.current||y.current.type!=="lesson")return;const A=y.current.lesson.id;(async()=>{try{await xa(x.uid,A,h)}catch(T){console.warn("[ModuleDetailView] Failed to persist lesson progress:",T)}})()},[x?.uid,t.id]);if(r)if(r.type==="lesson"){const h=ve.get(r.lesson.id)?.[0]??null,A=h?B.has(h.id)||h.completed:!1;return e.jsx(an,{lesson:r.lesson,lessonCompletionXP:10,practiceQuiz:h,practiceQuizCompleted:A,initialSection:r.returnFromQuiz?-1:0,onBack:_e,onStartPractice:Ve,onProgressUpdate:Ue,onComplete:$e})}else return m?e.jsx(Ys,{quiz:{id:r.quiz.id,title:r.quiz.title,subject:Dt.find(h=>h.modules.some(A=>A.id===t.id))?.title||"Mathematics",difficulty:"Medium",questions:m.length,duration:r.quiz.duration||"15 min",xpReward:50,type:"practice",completed:r.quiz.completed,locked:!1,loadedQuestions:m,source:"ai_generated"},onClose:()=>{p(null),D?(d({type:"lesson",lesson:D,returnFromQuiz:!0}),b(null)):d(null),l&&l(!1)},onComplete:(h,A)=>{x?.uid&&j&&(async()=>{try{await ua(x.uid,j,t.id,r.quiz.id,h,[],0,A),await ps(x.uid,j,t.id,t.lessons.length,t.quizzes.length),await us(x.uid,M)}catch(T){console.warn("[Quiz] Progress persist failed:",T)}n&&n(A??0,"Quiz Complete! +"+(A??0)+" XP")})()},studentId:x?.uid}):e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm",children:e.jsxs("div",{className:"bg-white rounded-2xl p-6 flex flex-col items-center gap-3 shadow-xl",children:[e.jsx(qs,{size:36,className:"animate-spin text-indigo-600"}),e.jsx("p",{className:"font-bold text-slate-700",children:"Generating Quiz..."}),e.jsxs("p",{className:"text-sm text-slate-500",children:["AI is crafting questions for ",r.quiz.title]})]})});return e.jsxs("div",{className:"h-full overflow-y-auto scrollbar-hide px-4 md:px-6 lg:px-10 py-4 md:py-6 lg:py-8 relative",children:[e.jsx("div",{className:"relative mb-4 lg:mb-6 xl:mb-8 w-full lg:w-max",children:e.jsxs("button",{onClick:s,className:"flex items-center gap-2 px-4 py-2.5 rounded-full bg-white/80 backdrop-blur-xl border border-slate-200/60 text-slate-600 hover:text-indigo-600 font-bold text-sm tracking-wide transition-all hover:-translate-x-1 shadow-sm hover:shadow-md",children:[e.jsx(Zt,{size:18}),"Back"]})}),e.jsxs(S.div,{initial:{opacity:0,y:-20},animate:{opacity:1,y:0},className:`relative mb-6 lg:mb-8 rounded-[2rem] ${t.accentColor} shadow-[0_20px_40px_-15px_rgba(0,0,0,0.3)] shrink-0 overflow-hidden`,children:[e.jsx("div",{className:"absolute inset-0 bg-black/60 pointer-events-none z-0"}),e.jsx("div",{className:"absolute inset-0 opacity-10 pointer-events-none module-detail-grid-pattern"}),e.jsx("div",{className:"absolute top-0 right-0 w-[400px] h-[400px] bg-sky-500/20 blur-[100px] rounded-full pointer-events-none"}),e.jsxs("div",{className:"relative p-5 md:p-6 lg:p-8 flex flex-col md:flex-row md:items-center justify-between gap-3 md:gap-5",children:[e.jsxs("div",{className:"flex-1 text-white",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-2 md:mb-2.5",children:[e.jsxs("div",{className:"px-2.5 py-0.5 bg-white/10 backdrop-blur-md rounded-full text-[10px] font-black uppercase tracking-widest text-[#f8fafc] border border-white/20 shadow-sm flex items-center gap-1",children:[e.jsx(ws,{size:12})," Chapter ",t.id.split("-").pop()||"1"]}),e.jsxs("div",{className:"px-2.5 py-0.5 bg-white/10 backdrop-blur-md rounded-full text-[10px] font-black uppercase tracking-widest text-emerald-400 border border-emerald-400/30",children:["Lv ",W]})]}),e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("span",{className:"flex lg:hidden text-white/80 shrink-0",children:e.jsx(Fe,{size:18,strokeWidth:1.5})}),e.jsx("h1",{className:"text-lg md:text-2xl lg:text-3xl font-display font-black text-white tracking-[-0.02em] leading-tight",children:t.title})]}),e.jsx("p",{className:"text-slate-300 text-xs md:text-sm max-w-2xl font-medium leading-relaxed mb-3",children:t.description}),e.jsxs("div",{className:"bg-black/20 backdrop-blur-md rounded-xl p-2 md:p-3 border border-white/10 max-w-xl",children:[e.jsxs("div",{className:"flex justify-between items-end gap-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Tt,{size:16,className:"text-emerald-400"}),e.jsx("span",{className:"text-[11px] md:text-xs font-black text-white uppercase tracking-wider",children:"Module Mastery"})]}),e.jsxs("div",{className:"flex items-baseline gap-1.5",children:[e.jsxs("span",{className:"text-[10px] md:text-xs font-bold text-slate-400",children:[Oe,"/",ge]}),e.jsxs("span",{className:"text-base md:text-lg font-black text-white shrink-0 leading-none",children:[Math.round(Se),"%"]})]})]}),e.jsx("div",{className:"h-2 bg-black/40 rounded-full overflow-hidden shadow-inner ring-1 ring-white/10 p-0.5 mt-2",children:e.jsx(S.div,{initial:{width:0},animate:{width:`${Se}%`},transition:{duration:1.5,ease:"easeOut",delay:.2},className:`h-full rounded-full relative ${Se===100?"bg-gradient-to-r from-emerald-400 to-teal-300":t.accentColor}`,children:e.jsx("div",{className:"absolute inset-0 bg-[url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI4IiBoZWlnaHQ9IjgiPgo8cmVjdCB3aWR0aD0iOCIgaGVpZ2h0PSI4IiBmaWxsPSIjZmZmIiBmaWxsLW9wYWNpdHk9IjAuMSI+PC9yZWN0Pgo8L3N2Zz4=')] opacity-30 mix-blend-overlay"})})})]})]}),e.jsxs("div",{className:"hidden lg:flex w-32 h-32 bg-white/5 rounded-2xl border border-white/10 backdrop-blur-md items-center justify-center transform rotate-[-3deg] shadow-2xl relative group hover:rotate-0 transition-all duration-500 shrink-0",children:[e.jsx("div",{className:`absolute inset-0 opacity-40 rounded-2xl ${t.progress===100?"bg-gradient-to-br from-emerald-400 to-teal-600":t.accentColor}`}),Se===100?e.jsx(ns,{size:56,className:"text-white drop-shadow-xl z-10 scale-100 group-hover:scale-110 transition-transform duration-500",strokeWidth:1}):e.jsx(Fe,{size:56,className:"text-white drop-shadow-xl z-10 scale-100 group-hover:scale-110 transition-transform duration-500",strokeWidth:1}),e.jsx(S.div,{animate:{y:[-5,5,-5],rotate:[-10,10,-10]},transition:{duration:4,repeat:1/0},className:"absolute top-4 left-4 text-emerald-300 z-20",children:e.jsx($s,{size:16,fill:"currentColor"})}),e.jsx(S.div,{animate:{y:[5,-5,5],rotate:[10,-10,10]},transition:{duration:3.5,repeat:1/0},className:"absolute bottom-6 right-4 text-sky-300 z-20",children:e.jsx(ks,{size:18})})]})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto pr-2 pb-8 scrollbar-hide",children:e.jsxs("div",{className:"relative rounded-[2rem] border border-slate-200 bg-white/90 shadow-sm overflow-hidden",children:[e.jsx("div",{className:"absolute inset-0 pointer-events-none bg-[radial-gradient(circle_at_top_right,rgba(153,86,222,0.08),transparent_45%),radial-gradient(circle_at_bottom_left,rgba(31,167,225,0.08),transparent_45%)]"}),e.jsxs("div",{className:"relative z-10 px-4 sm:px-6 md:px-8 py-5 md:py-6 border-b border-slate-200/70 bg-white/70 backdrop-blur-sm flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("h2",{className:"font-display font-black text-xl md:text-2xl text-slate-800 flex items-center gap-3",children:[e.jsx(Fe,{size:24,className:"text-sky-500"}),"Study Journey"]}),e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsxs("div",{className:"text-xs md:text-sm font-bold bg-sky-100 text-sky-700 px-3 py-1 rounded-full shadow-sm border border-sky-200/50",children:["Lessons ",se,"/",t.lessons.length]}),e.jsxs("div",{className:"text-xs md:text-sm font-bold bg-rose-100 text-rose-700 px-3 py-1 rounded-full shadow-sm border border-rose-200/50",children:["Quizzes ",C,"/",t.quizzes.length]})]})]}),e.jsxs("div",{className:"relative z-10 px-3 md:px-6 lg:px-8 py-4 md:py-6 space-y-4 md:space-y-5",children:[t.lessons.map((h,A)=>{const T=I.has(h.id)||h.completed,X=oe(h.id,T),$=E[A%E.length];return e.jsxs(je.Fragment,{children:[e.jsxs(S.div,{initial:{opacity:0,y:14},animate:{opacity:1,y:0},transition:{delay:A*.05},className:`relative rounded-[1.5rem] border overflow-hidden group transition-all duration-500 mb-4 md:mb-6 ${h.locked?"border-slate-200 opacity-65 saturate-50":"border-slate-200/80 hover:border-slate-300 hover:shadow-[0_16px_40px_-15px_rgba(0,0,0,0.12)] hover:-translate-y-0.5"}`,children:[e.jsx("div",{className:"absolute top-0 left-0 right-0 h-[6px] z-20 bg-slate-100 overflow-hidden",children:e.jsx(S.div,{initial:{width:0},animate:{width:`${Math.max(2,X)}%`},transition:{duration:1.2,ease:"easeOut",delay:.1+A*.05},className:"h-full relative",style:{backgroundColor:$},children:e.jsx("div",{className:"absolute inset-0 bg-[url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI4IiBoZWlnaHQ9IjgiPgo8cmVjdCB3aWR0aD0iOCIgaGVpZ2h0PSI4IiBmaWxsPSIjZmZmIiBmaWxsLW9wYWNpdHk9IjAuMSI+PC9yZWN0Pgo8L3N2Zz4=')] opacity-30 mix-blend-overlay"})})}),e.jsx("div",{className:"absolute inset-0 bg-white transition-opacity duration-500 group-hover:opacity-90",style:{backgroundImage:`linear-gradient(to right, ${$}44 0%, ${$}11 50%, white 100%)`}}),e.jsx("div",{className:"absolute inset-0 opacity-[0.2] pointer-events-none",style:{backgroundImage:`radial-gradient(circle at 2px 2px, ${$} 1.5px, transparent 0)`,backgroundSize:"24px 24px"}}),e.jsx("div",{className:"absolute -top-12 -left-10 h-40 w-40 rounded-full blur-[32px] pointer-events-none transition-transform duration-700 group-hover:scale-[1.3] group-hover:translate-x-4",style:{backgroundColor:`${$}22`}}),e.jsx("div",{className:"absolute -bottom-8 right-8 h-32 w-32 rounded-full blur-2xl pointer-events-none transition-transform duration-700 group-hover:scale-125 group-hover:-translate-y-4",style:{backgroundColor:`${$}11`}}),e.jsx("div",{className:"absolute right-4 top-4 opacity-10 pointer-events-none transition-all duration-500 group-hover:rotate-12 group-hover:scale-110 drop-shadow-sm",style:{color:$},children:e.jsx(ks,{size:56,strokeWidth:1})}),e.jsx("div",{className:"absolute right-16 bottom-5 opacity-10 pointer-events-none transition-all duration-500 group-hover:-rotate-6 group-hover:-translate-y-2 drop-shadow-sm",style:{color:$},children:e.jsx(Fe,{size:40,strokeWidth:1})}),e.jsxs("div",{className:"relative z-10 p-3 md:p-5 pt-5 md:pt-6 space-y-3 md:space-y-4",children:[e.jsxs("button",{type:"button",onClick:()=>!h.locked&&d({lesson:h,type:"lesson"}),className:`w-full text-left flex flex-wrap items-center justify-between gap-2 md:gap-3 rounded-2xl px-3 md:px-5 py-3 md:py-4 transition shadow-sm ${h.locked?"cursor-not-allowed border border-slate-200 bg-white/70":"cursor-pointer bg-white hover:bg-slate-50"}`,children:[e.jsxs("div",{className:"flex items-center gap-2 md:gap-4 min-w-0",children:[e.jsx("div",{className:`w-10 h-10 md:w-12 md:h-12 rounded-full flex items-center justify-center shrink-0 transition-colors shadow-sm ${h.locked?"bg-slate-100 text-slate-400":"text-white"}`,style:h.locked?{}:T?{backgroundColor:"#0ea5e9"}:{backgroundColor:$},children:h.locked?e.jsx(Os,{size:16}):T?e.jsx(Xs,{size:20}):e.jsx(_a,{size:18,className:"ml-0.5"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("p",{className:"text-[10px] md:text-[12px] font-black uppercase tracking-wider text-slate-500 mb-0.5",children:["Lesson ",A+1]}),e.jsx("h3",{className:"font-bold text-[14px] md:text-[18px] text-[#0a1628] leading-tight line-clamp-2",children:h.title})]})]}),e.jsx("div",{className:"flex items-center justify-end shrink-0",children:e.jsxs("span",{className:"inline-flex items-center gap-1 text-slate-500 text-[11px] md:text-sm font-semibold bg-slate-100/80 px-2 md:px-3 py-1 md:py-1.5 rounded-lg md:rounded-xl",children:[e.jsx(Nt,{size:12}),h.duration]})})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 md:gap-3 px-0.5 md:px-1",children:[e.jsxs("button",{type:"button",className:"inline-flex items-center gap-1 rounded-full bg-white px-3 md:px-4 py-1 md:py-1.5 text-[11px] md:text-[12px] font-bold shadow-sm transition hover:-translate-y-0.5",style:{color:$},children:[e.jsx(Fe,{size:12})," Study Materials"]}),e.jsxs("button",{type:"button",className:"inline-flex items-center gap-1 rounded-full bg-white px-3 md:px-4 py-1 md:py-1.5 text-[11px] md:text-[12px] font-bold shadow-sm transition hover:-translate-y-0.5",style:{color:$},children:[e.jsx(ws,{size:12})," Quiz"]})]})]})]}),G&&A===We-1&&e.jsxs(S.div,{initial:{opacity:0,y:16},animate:{opacity:1,y:0},transition:{delay:.15+A*.03},className:"mt-4 md:mt-6 mb-4 md:mb-6",children:[e.jsxs("div",{className:"flex items-center gap-2 md:gap-4 mb-4 md:mb-6",children:[e.jsx("div",{className:"flex-1 h-px bg-slate-200"}),e.jsx("span",{className:"text-[10px] md:text-xs font-bold text-indigo-400 uppercase tracking-widest text-center",children:"mid-module checkpoint"}),e.jsx("div",{className:"flex-1 h-px bg-slate-200"})]}),e.jsxs("div",{className:"relative rounded-[1.5rem] bg-[#533ab6] p-3 md:p-5 shadow-lg overflow-hidden group transition-all hover:shadow-xl hover:-translate-y-1",children:[e.jsx("div",{className:"absolute right-2 md:right-10 top-1/2 -translate-y-1/2 text-white/5 text-[80px] md:text-[140px] font-black font-display pointer-events-none group-hover:scale-110 transition-transform duration-500",children:"?"}),e.jsxs("div",{className:"relative z-10 flex flex-wrap items-center gap-3 md:gap-5",children:[e.jsx("div",{className:"w-12 h-12 md:w-14 md:h-14 rounded-[12px] md:rounded-[14px] bg-white/10 backdrop-blur-md border border-white/10 shrink-0 flex items-center justify-center shadow-inner",children:e.jsx(et,{size:22,className:"text-rose-400"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-[9px] md:text-[11px] font-black uppercase tracking-widest text-[#a3b1ee] mb-0.5 md:mb-1 drop-shadow-sm",children:"COMPETENCY CHECK · General Quiz"}),e.jsx("h3",{className:"font-display font-medium text-[16px] md:text-[22px] text-white leading-tight mb-1 md:mb-2 tracking-tight",children:G.title}),e.jsxs("p",{className:"text-[11px] md:text-xs font-semibold text-white/80 flex flex-wrap items-center gap-2 md:gap-3",children:[e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Jt,{size:11})," ",G.questions," Qs"]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Nt,{size:11})," ",G.duration]}),e.jsxs("span",{className:"inline-flex items-center gap-1 text-amber-300 drop-shadow-md",children:[e.jsx(Xe,{size:11,className:"fill-amber-300"})," +50 XP"]})]})]}),e.jsx("button",{type:"button",onClick:()=>!G.locked&&(d({quiz:G,type:"quiz"}),l&&l(!0)),className:`px-4 md:px-6 py-2 md:py-2.5 rounded-xl text-[11px] md:text-sm font-bold tracking-wider transition-all backdrop-blur-sm self-center shrink-0 ${G.locked?"bg-white/5 text-white/30 border border-white/10 cursor-not-allowed":u&&(B.has(G.id)||G.completed)?"bg-white/20 text-white border border-white/40 hover:bg-white/30 shadow-sm":"bg-transparent text-white border border-white/40 hover:bg-white/10 shadow-sm"}`,children:u&&(B.has(G.id)||G.completed)?"REVIEW":"START"})]})]})]})]},h.id)}),t.lessons.length===0&&G&&e.jsxs("div",{className:"relative rounded-[1.5rem] bg-[#533ab6] p-5 shadow-lg overflow-hidden group",children:[e.jsx("div",{className:"absolute right-4 md:right-10 top-1/2 -translate-y-1/2 text-white/5 text-[140px] font-black font-display pointer-events-none group-hover:scale-110 transition-transform duration-500",children:"?"}),e.jsxs("div",{className:"relative z-10 flex flex-wrap items-center justify-between gap-4 md:gap-5",children:[e.jsxs("div",{className:"flex items-center gap-4 flex-1",children:[e.jsx("div",{className:"w-14 h-14 rounded-[14px] bg-white/10 backdrop-blur-md border border-white/10 shrink-0 flex items-center justify-center shadow-inner",children:e.jsx(et,{size:28,className:"text-rose-400"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] md:text-[11px] font-black uppercase tracking-widest text-[#a3b1ee] mb-1 drop-shadow-sm",children:"COMPETENCY CHECK · General Quiz"}),e.jsx("h3",{className:"font-display font-medium text-[20px] md:text-[22px] text-white leading-tight mb-2 tracking-tight",children:G.title}),e.jsxs("p",{className:"text-xs font-semibold text-white/80 flex items-center gap-3",children:[e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Jt,{size:12})," ",G.questions," Qs"]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Nt,{size:12})," ",G.duration]}),e.jsxs("span",{className:"inline-flex items-center gap-1 text-amber-300 drop-shadow-md",children:[e.jsx(Xe,{size:12,className:"fill-amber-300"})," +50 XP"]})]})]})]}),e.jsx("button",{type:"button",onClick:()=>!G.locked&&(d({quiz:G,type:"quiz"}),l&&l(!0)),className:`px-6 py-2.5 rounded-xl text-xs md:text-sm font-bold tracking-wider transition-all backdrop-blur-sm self-center shrink-0 ${G.locked?"bg-white/5 text-white/30 border border-white/10 cursor-not-allowed":u&&(B.has(G.id)||G.completed)?"bg-white/20 text-white border border-white/40 hover:bg-white/30 shadow-sm":"bg-transparent text-white border border-white/40 hover:bg-white/10 shadow-sm"}`,children:u&&(B.has(G.id)||G.completed)?"REVIEW":"START"})]})]})]})]})})]})},cn={"Patterns, Relations, and Functions":{icon:At,bg:"bg-indigo-500"},"Financial Mathematics":{icon:Ia,bg:"bg-emerald-500"},"Logic and Mathematical Reasoning":{icon:pa,bg:"bg-purple-500"},"Random Variables":{icon:sr,bg:"bg-orange-500"},"Normal Distribution":{icon:La,bg:"bg-sky-500"},"Sampling and Estimation":{icon:er,bg:"bg-teal-500"},"Hypothesis Testing":{icon:nr,bg:"bg-rose-500"},"Correlation and Regression":{icon:Va,bg:"bg-amber-500"}};function dn(t){return cn[t]||{icon:Jt,bg:"bg-slate-500"}}const mn=({userId:t,onStartQuiz:s,searchQuery:n="",allowedSubjectIds:i})=>{const{userProfile:l}=Bt(),[c,r]=a.useState("all"),[d,x]=a.useState("Medium"),[f,M]=a.useState(null),[u,N]=a.useState(!1),[m,p]=a.useState(null),k=a.useMemo(()=>!i||i.length===0?bs:bs.filter(b=>i.includes(b.id)),[i]),y=a.useMemo(()=>k.flatMap(b=>b.topics.map(I=>({id:I.id,name:I.name,unit:I.unit,subject:b.name,subjectId:b.id}))),[k]),W=a.useMemo(()=>y.filter(b=>{const I=c==="all"||b.subject===c,B=!n||b.name.toLowerCase().includes(n.toLowerCase())||b.unit.toLowerCase().includes(n.toLowerCase())||b.subject.toLowerCase().includes(n.toLowerCase());return I&&B}),[y,c,n]);a.useEffect(()=>{t&&(N(!0),ln(t).then(M).catch(console.error).finally(()=>N(!1)))},[t]);const j=f?.quizzesCompleted??0,E=f?.totalXPEarned??l?.totalXP??0,_=f?.averageScore??0,D=a.useCallback(async b=>{if(!(!t||m)){p(b.id);try{const I={Easy:"Practice",Medium:"Challenge",Hard:"Mastery"},B=await Zs({userId:t,subject:b.subject,competency:b.name,difficulty:I[d],count:5}),se={id:B.session_id,title:`Practice Quiz: ${b.name} (AI)`,subject:b.subject,difficulty:d,questions:B.questions.length,duration:"10 min",xpReward:d==="Hard"?75:d==="Medium"?50:25,type:"practice",loadedQuestions:B.questions.map(C=>({id:C.id,questionType:"multiple_choice",question:C.question,options:C.options,correctAnswer:C.options[C.correct_index],bloomLevel:["remember","understand","apply","analyze"].includes(C.bloomsLevel?.toLowerCase()||"")?C.bloomsLevel.toLowerCase():"understand",difficulty:d.toLowerCase(),topic:b.name,subject:b.subject,points:10,explanation:C.explanation})),generatedQuizId:B.session_id,source:"ai_generated",completed:!1,locked:!1};s?.(se)}catch(I){console.error("Failed to generate practice quiz:",I)}finally{p(null)}}},[t,d,m,s]);return e.jsxs("div",{className:"px-4 sm:px-6 xl:px-10 py-4 sm:py-6",children:[e.jsxs("div",{className:"grid grid-cols-3 gap-2 sm:gap-4 mb-6",children:[e.jsxs(S.div,{whileHover:{scale:1.02},className:"bg-gradient-to-br from-sky-700 to-sky-500 rounded-xl sm:rounded-2xl p-3 sm:p-5 text-white shadow-lg",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between mb-1 sm:mb-3 gap-1 sm:gap-0",children:[e.jsxs("div",{className:"w-8 h-8 sm:w-12 sm:h-12 bg-white/20 rounded-lg sm:rounded-xl flex items-center justify-center shrink-0",children:[e.jsx(Tt,{size:16,className:"sm:hidden"}),e.jsx(Tt,{size:24,className:"hidden sm:block"})]}),e.jsx("span",{className:"text-xl sm:text-3xl font-bold",children:j})]}),e.jsx("p",{className:"text-[10px] sm:text-sm font-medium text-sky-100 leading-tight",children:"Quizzes Completed"})]}),e.jsxs(S.div,{whileHover:{scale:1.02},className:"bg-gradient-to-br from-rose-500 to-rose-600 rounded-xl sm:rounded-2xl p-3 sm:p-5 text-white shadow-lg",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between mb-1 sm:mb-3 gap-1 sm:gap-0",children:[e.jsxs("div",{className:"w-8 h-8 sm:w-12 sm:h-12 bg-white/20 rounded-lg sm:rounded-xl flex items-center justify-center shrink-0",children:[e.jsx(Xe,{size:16,className:"sm:hidden"}),e.jsx(Xe,{size:24,className:"hidden sm:block"})]}),e.jsx("span",{className:"text-xl sm:text-3xl font-bold",children:E.toLocaleString()})]}),e.jsx("p",{className:"text-[10px] sm:text-sm font-medium text-cyan-100 leading-tight",children:"Total XP Earned"})]}),e.jsxs(S.div,{whileHover:{scale:1.02},className:"bg-gradient-to-br from-indigo-600 to-indigo-700 rounded-xl sm:rounded-2xl p-3 sm:p-5 text-white shadow-lg",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between mb-1 sm:mb-3 gap-1 sm:gap-0",children:[e.jsxs("div",{className:"w-8 h-8 sm:w-12 sm:h-12 bg-white/20 rounded-lg sm:rounded-xl flex items-center justify-center shrink-0",children:[e.jsx(et,{size:16,className:"sm:hidden"}),e.jsx(et,{size:24,className:"hidden sm:block"})]}),e.jsxs("span",{className:"text-xl sm:text-3xl font-bold",children:[Math.round(_),"%"]})]}),e.jsx("p",{className:"text-[10px] sm:text-sm font-medium text-sky-100 leading-tight",children:"Average Score"})]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center gap-2 sm:gap-3 mb-6",children:[e.jsxs("select",{value:c,onChange:b=>r(b.target.value),className:"w-full sm:w-auto px-3 sm:px-4 py-2 sm:py-2.5 bg-white border-2 border-[#dde3eb] rounded-xl text-xs sm:text-sm font-bold text-[#0a1628] focus:border-indigo-600 focus:outline-none",children:[e.jsx("option",{value:"all",children:"All Subjects"}),k.map(b=>e.jsx("option",{value:b.name,children:b.name},b.id))]}),e.jsxs("div",{className:"flex items-center gap-1.5 sm:gap-2 bg-white rounded-xl p-1 shadow-sm",children:[e.jsx("span",{className:"px-2 text-xs font-bold text-slate-400",children:"Difficulty:"}),["Easy","Medium","Hard"].map(b=>e.jsx("button",{onClick:()=>x(b),className:`px-3 py-1.5 rounded-lg text-xs font-bold transition-all whitespace-nowrap ${d===b?b==="Easy"?"bg-green-500 text-white shadow-sm":b==="Medium"?"bg-orange-500 text-white shadow-sm":"bg-red-500 text-white shadow-sm":"text-[#5a6578] hover:bg-[#edf1f7]"}`,children:b},b))]})]}),m&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm",children:e.jsxs("div",{className:"bg-white rounded-2xl p-6 flex flex-col items-center gap-3 shadow-xl",children:[e.jsx(qs,{size:36,className:"animate-spin text-indigo-600"}),e.jsx("p",{className:"font-bold text-slate-700",children:"Generating Quiz..."}),e.jsx("p",{className:"text-sm text-slate-500",children:"AI is crafting questions from curriculum"})]})}),e.jsxs("div",{className:"pr-2 pb-4 rounded-[2rem] border border-slate-200 shadow-inner relative",style:{backgroundImage:"radial-gradient(#CBD5E1 1px, transparent 1px)",backgroundSize:"24px 24px",backgroundPosition:"-12px -12px",backgroundColor:"#FAFAFA"},children:[e.jsx("div",{className:"absolute left-12 top-0 bottom-0 w-0.5 bg-rose-200/60 pointer-events-none z-0"}),e.jsx("div",{className:"absolute left-[54px] top-0 bottom-0 w-px bg-rose-100/40 pointer-events-none z-0"}),e.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4 lg:gap-5 p-4 md:p-6 relative z-10",children:W.map((b,I)=>e.jsx(S.div,{initial:{opacity:0,x:-20},animate:{opacity:1,x:0},transition:{delay:I*.03},onClick:()=>D(b),className:`bg-white/90 backdrop-blur-sm rounded-2xl p-4 md:p-5 border-2 relative select-none transition-all duration-300 ${m===b.id?"border-indigo-300 opacity-80 cursor-wait":m?"border-slate-200 opacity-60 cursor-not-allowed":"border-slate-200 shadow-sm hover:border-indigo-300 hover:shadow-md cursor-pointer"} group`,children:e.jsxs("div",{className:"flex items-center justify-between gap-3 md:gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3 md:gap-4 flex-1",children:[(()=>{const{icon:B,bg:se}=dn(b.unit);return e.jsx("div",{className:`w-10 h-10 md:w-12 md:h-12 rounded-xl flex items-center justify-center shrink-0 shadow-sm transform group-hover:rotate-3 transition-transform ${se} text-white`,children:e.jsx(B,{size:18})})})(),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-1",children:[e.jsxs("span",{className:`px-2 py-0.5 rounded-[6px] text-[9px] md:text-[10px] font-black uppercase tracking-wider ${d==="Easy"?"bg-green-100 text-green-700":d==="Medium"?"bg-orange-100 text-orange-700":"bg-red-100 text-red-700"}`,children:["AI ","•"," ",d]}),e.jsx("span",{className:"w-1.5 h-1.5 md:w-2 md:h-2 rounded-full bg-emerald-500 animate-pulse"})]}),e.jsx("h3",{className:"font-bold text-[14px] md:text-[16px] leading-tight mb-1 md:mb-1.5 text-[#0a1628] transition-colors",children:b.name}),e.jsxs("p",{className:"text-[11px] md:text-[12px] text-slate-500 mb-1.5 line-clamp-1",children:[b.subject," — ",b.unit]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 md:gap-3 text-[11px] md:text-[12px] font-bold text-slate-400",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Fe,{size:12})," 5 Qs"]}),e.jsx("span",{className:"hidden sm:inline",children:"•"}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Nt,{size:12})," 10 min"]}),e.jsx("span",{className:"hidden sm:inline",children:"•"}),e.jsxs("span",{className:"flex items-center gap-1 text-rose-500",children:[e.jsx(ns,{size:12})," +",d==="Hard"?75:d==="Medium"?50:25," XP"]})]})]})]}),e.jsx("div",{className:"shrink-0",children:e.jsx("div",{className:`px-3 py-1.5 md:px-4 md:py-2 rounded-xl text-[11px] md:text-[12px] font-black uppercase tracking-wider shadow-sm transition-all ${m===b.id?"bg-indigo-100 text-indigo-600":"bg-indigo-500 text-white group-hover:bg-indigo-600 shadow-indigo-200"}`,children:m===b.id?"Loading...":"Start"})})]})},b.id))}),W.length===0&&e.jsxs("div",{className:"flex flex-col items-center justify-center h-64 text-slate-500 relative z-10",children:[e.jsx(et,{size:48,className:"mb-3"}),e.jsx("p",{className:"font-medium",children:"No topics found"}),e.jsx("p",{className:"text-sm",children:"Try adjusting your filters or search query"})]})]})]})},xn=` - @keyframes head-sway { - 0%, 100% { transform: rotate(-2deg) translateY(0); } - 50% { transform: rotate(2deg) translateY(-2px); } - } - @keyframes horn-left-wiggle { - 0%, 100% { transform: rotate(-4deg); } - 50% { transform: rotate(4deg); } - } - @keyframes horn-right-wiggle { - 0%, 100% { transform: rotate(4deg); } - 50% { transform: rotate(-4deg); } - } - @keyframes blink { - 0%, 90%, 100% { transform: scaleY(1); } - 95% { transform: scaleY(0.1); } - } - @keyframes mouth-talk { - 0%, 100% { transform: scaleY(1) scaleX(1); } - 25% { transform: scaleY(1.1) scaleX(0.98); } - 50% { transform: scaleY(0.9) scaleX(1.02); } - 75% { transform: scaleY(1.05) scaleX(0.98); } - } - .animate-head-sway { - transform-origin: 50% 75%; - animation: head-sway 4s ease-in-out infinite; - } - .animate-horn-left { - transform-origin: 50% 45%; - animation: horn-left-wiggle 4s ease-in-out infinite; - } - .animate-horn-right { - transform-origin: 50% 45%; - animation: horn-right-wiggle 4s ease-in-out infinite; - } - .animate-blink { - transform-origin: 50% 45%; - animation: blink 3.7s ease-in-out infinite; - } - .animate-mouth { - transform-origin: 50% 55%; - animation: mouth-talk 3s ease-in-out infinite; - } -`,Is=({assessmentDismissed:t,initialAssessmentCompleted:s})=>{const n="absolute inset-0 w-full h-full object-contain",[i,l]=a.useState(!1);a.useEffect(()=>{t&&!s&&!sessionStorage.getItem("mathpulse_assessment_reminder_shown")?l(!0):l(!1)},[t,s]);const c=()=>{sessionStorage.setItem("mathpulse_assessment_reminder_shown","true"),l(!1),window.dispatchEvent(new CustomEvent("mathpulse:open-assessment"))};return e.jsxs(e.Fragment,{children:[e.jsx("style",{children:xn}),e.jsxs("div",{className:"relative w-full h-[250px] flex items-end justify-center drop-shadow-sm select-none pointer-events-none",children:[i&&e.jsxs(S.div,{initial:{opacity:0,scale:.8,x:10},animate:{opacity:1,scale:1,x:0},className:"absolute top-0 right-0 z-50 max-w-[180px] bg-white rounded-2xl shadow-lg border border-[#dde3eb] p-3 cursor-pointer pointer-events-auto",onClick:c,children:[e.jsx("p",{className:"text-[11px] font-bold text-[#0a1628] leading-snug",children:"Psst! Complete your assessment for a personalized path!"}),e.jsxs("div",{className:"mt-1.5 flex items-center gap-1",children:[e.jsx("div",{className:"w-1.5 h-1.5 bg-purple-500 rounded-full animate-pulse"}),e.jsx("span",{className:"text-[10px] text-[#5a6578] font-medium",children:"Tap to start"})]}),e.jsx("div",{className:"absolute -bottom-2 left-4 w-3 h-3 bg-white border-r border-b border-[#dde3eb] rotate-45"})]}),e.jsx("img",{src:"/mascot/modules_avatar_body.png",alt:"Desk setup",className:`${n} z-10`}),e.jsxs("div",{className:`${n} z-20 animate-head-sway`,children:[e.jsx("img",{src:"/mascot/modules_left_horn.png",alt:"Left Horn",className:`${n} z-0 animate-horn-left`}),e.jsx("img",{src:"/mascot/modules_right_horn.png",alt:"Right Horn",className:`${n} z-0 animate-horn-right`}),e.jsx("img",{src:"/mascot/modules_head.png",alt:"Mascot Head",className:`${n} z-[1]`}),e.jsx("img",{src:"/mascot/modules_eyes.png",alt:"Eyes",className:`${n} z-[2] animate-blink`}),e.jsx("img",{src:"/mascot/modules_mouth.png",alt:"Mouth",className:`${n} z-[3] animate-mouth`})]})]})]})},Ds={common:"bg-slate-100 text-slate-500",rare:"bg-blue-50 text-blue-500",epic:"bg-amber-50 text-amber-500"},Rs=["bg-[#1FA7E1]/80 text-white","bg-[#9956DE]/80 text-white","bg-[#FFB356]/90 text-white","bg-[#7274ED]/80 text-white","bg-[#1FA7E1]/80 text-white","bg-[#9956DE]/80 text-white","bg-gradient-to-r from-[#FFB356] to-[#FF8C00] text-white"],un=({isOpen:t,onClose:s,onClaim:n,weekRewards:i,todayReward:l,canClaim:c,isClaiming:r,claimedDays:d,currentDayIndex:x,timeUntilReset:f})=>{const[M,u]=a.useState(!1);if(!t)return null;const N=()=>{if(!c||M)return;u(!0),l?.rarity==="epic"?gs({particleCount:150,spread:80,origin:{y:.6},colors:["#FFD700","#FFA500","#FF8C00","#FF6B6B","#4ade80"]}):gs({particleCount:100,spread:70,origin:{y:.6},colors:["#FFD700","#FFA500","#FF8C00"]}),setTimeout(()=>{u(!1),n()},1200)},m=E=>E+1,p=E=>E===x,k=E=>d.includes(E),y=E=>E>x,W=i.slice(0,6),j=i[6];return e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4 sm:p-8",children:[e.jsx(ot,{children:t&&e.jsx(S.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"absolute inset-0 bg-slate-900/60 backdrop-blur-sm",onClick:s})}),e.jsxs(S.div,{initial:{scale:.9,opacity:0,y:20},animate:{scale:1,opacity:1,y:0},exit:{scale:.9,opacity:0,y:20},className:"relative w-full max-w-[420px] bg-[#f7f9fc] rounded-3xl border border-[#dde3eb] shadow-2xl flex flex-col items-center p-5 overflow-visible",children:[e.jsxs("div",{className:"absolute -top-6 w-[85%] h-12 bg-gradient-to-r from-[#9956DE] via-[#7274ED] to-[#1FA7E1] rounded-xl shadow-lg flex items-center justify-center z-20",children:[e.jsx("div",{className:"absolute -left-2.5 -z-10 w-5 h-8 bg-[#633299] rounded-l-full rotate-12 top-1.5"}),e.jsx("div",{className:"absolute -right-2.5 -z-10 w-5 h-8 bg-[#10709b] rounded-r-full -rotate-12 top-1.5"}),e.jsx("h2",{className:"text-white font-black text-lg tracking-wide uppercase drop-shadow-sm font-display",children:"Daily Rewards"})]}),e.jsx("button",{onClick:s,className:"absolute -right-3 -top-3 w-8 h-8 bg-white hover:bg-slate-100 border border-slate-200 text-slate-500 hover:text-slate-800 rounded-full flex items-center justify-center z-30 shadow-md transition-transform hover:scale-105 active:scale-95",children:e.jsx(Je,{size:16,strokeWidth:3})}),e.jsxs("div",{className:"mt-6 mb-2 text-center w-full",children:[e.jsx("h3",{className:"text-xl font-bold text-slate-800 font-display mt-2",children:"Welcome Back!"}),e.jsx("p",{className:"text-slate-500 font-medium text-xs mt-0.5",children:"Claim your daily reward for today."})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 w-full mb-5 relative z-10",children:[W.map((E,_)=>{const D=m(_),b=k(_),I=p(_),B=y(_);return e.jsxs("div",{className:`relative rounded-xl flex flex-col overflow-hidden border-[1.5px] transition-all ${I&&!b?"border-amber-400 shadow-[0_0_15px_rgba(251,191,36,0.25)] scale-105 z-10 bg-amber-50":b?"border-[#dde3eb] bg-slate-200/50":"border-[#dde3eb] bg-white"}`,children:[e.jsxs("div",{className:`py-0.5 text-center font-black text-[10px] uppercase tracking-wider ${I&&!b?"bg-amber-400 text-amber-900":Rs[_]}`,children:["Day ",D]}),e.jsx("div",{className:"absolute top-5 right-1 z-10",children:e.jsx("span",{className:`text-[8px] font-bold uppercase px-1 rounded ${Ds[E.rarity]}`,children:E.rarity})}),e.jsxs("div",{className:"flex-1 p-2 flex flex-col items-center justify-center relative min-h-[75px]",children:[b&&e.jsxs(S.div,{initial:{scale:0},animate:{scale:1},transition:{type:"spring",bounce:.5},className:"absolute inset-0 flex items-center justify-center z-20 pointer-events-none",children:[e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsx("div",{className:"w-12 h-12 rounded-full bg-emerald-200/50"})}),e.jsxs("div",{className:"relative w-14 h-14 rounded-full border-[3px] border-emerald-500 bg-emerald-100 flex items-center justify-center transform -rotate-12 shadow-lg",children:[e.jsx(Xs,{className:"w-8 h-8 text-emerald-600"}),e.jsx("div",{className:"absolute -bottom-2.5 left-1/2 -translate-x-1/2 bg-emerald-500 rounded-md px-2 py-0.5 border-2 border-emerald-300 shadow-md",children:e.jsx("span",{className:"text-[9px] font-black text-white uppercase tracking-wider leading-none whitespace-nowrap",children:"Claimed"})})]})]}),B&&e.jsx("div",{className:"absolute top-1 right-1 bg-slate-200 rounded-full p-0.5 z-10",children:e.jsx(Os,{size:8,className:"text-slate-400"})}),e.jsxs("div",{className:`flex flex-col items-center transition-all w-full ${b?"opacity-30 grayscale":""}`,children:[e.jsx("div",{className:"w-10 h-10 rounded-full flex items-center justify-center border-2 mb-1",style:{backgroundColor:E.color+"20",borderColor:E.color+"40"},children:e.jsx("span",{className:"text-lg",children:E.icon})}),e.jsx("div",{className:`font-black text-xs leading-none mt-0.5 text-center ${I?"text-amber-600":b?"text-slate-500":"text-slate-600"}`,children:E.label})]})]})]},E.id)}),j&&e.jsxs("div",{className:`col-span-3 relative rounded-xl flex flex-col overflow-hidden border-[1.5px] transition-all mt-1 ${p(6)&&!k(6)?"border-amber-400 shadow-[0_0_20px_rgba(251,191,36,0.3)] scale-[1.02] z-10 bg-amber-50":k(6)?"border-[#dde3eb] bg-slate-200/50":"border-[#dde3eb] bg-white"}`,children:[e.jsx("div",{className:`py-1 text-center font-black text-[10px] uppercase tracking-widest ${p(6)&&!k(6)?"bg-amber-400 text-amber-900":Rs[6]}`,children:"Day 7 • Epic Reward"}),e.jsx("div",{className:"absolute top-6 right-2 z-10",children:e.jsx("span",{className:`text-[8px] font-bold uppercase px-1.5 py-0.5 rounded ${Ds[j.rarity]}`,children:j.rarity})}),e.jsxs("div",{className:"flex items-center justify-center gap-5 p-3 relative",children:[k(6)&&e.jsxs(S.div,{initial:{scale:0},animate:{scale:1},transition:{type:"spring",bounce:.5},className:"absolute inset-0 flex items-center justify-center z-20 pointer-events-none",children:[e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsx("div",{className:"w-16 h-16 rounded-full bg-rose-200/50"})}),e.jsxs("div",{className:"relative w-20 h-20 rounded-full border-[4px] border-rose-500 bg-rose-100 flex items-center justify-center transform rotate-12 shadow-lg",children:[e.jsx("img",{src:"/avatar/avatar_icon.png",alt:"Claimed",className:"w-14 h-14 object-contain drop-shadow-md"}),e.jsx("div",{className:"absolute -bottom-3 left-1/2 -translate-x-1/2 bg-rose-500 rounded-md px-2.5 py-1 border-2 border-rose-300 shadow-md",children:e.jsx("span",{className:"text-[10px] font-black text-white uppercase tracking-wider leading-none whitespace-nowrap",children:"Claimed"})})]})]}),e.jsxs("div",{className:`flex items-center justify-center gap-5 w-full transition-all ${k(6)?"opacity-30 grayscale":""}`,children:[e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("div",{className:"w-12 h-12 rounded-full flex items-center justify-center border-2 shadow-sm mb-0.5",style:{backgroundColor:j.color+"20",borderColor:j.color+"40"},children:e.jsx("span",{className:"text-2xl",children:j.icon})}),e.jsx("span",{className:`font-black text-sm ${p(6)?"text-amber-600":"text-slate-600"}`,children:j.label})]}),j.rarity==="epic"&&e.jsxs("div",{className:"relative mt-1",children:[e.jsx("div",{className:"w-14 h-14 bg-purple-50 rounded-xl flex items-center justify-center border-2 border-purple-200 shadow-sm",children:e.jsx(Da,{className:"w-8 h-8 text-purple-500 drop-shadow-md"})}),e.jsx("div",{className:"absolute -right-5 -bottom-4 w-14 h-14 bg-white rounded-xl p-1 border-2 border-amber-300 shadow-lg transform rotate-[-5deg]",children:e.jsx("img",{src:"/avatar/crown_thumbnail.png",alt:"Crown",className:"w-full h-full object-contain drop-shadow-md"})})]})]})]})]})]}),e.jsxs("div",{className:"mb-3 flex items-center gap-2 text-xs text-slate-400",children:[e.jsx(jr,{size:14}),e.jsx("span",{className:"font-mono font-medium",children:f}),e.jsx("span",{children:"until next reset"})]}),e.jsx(S.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:N,disabled:!c||r||M,className:`w-[85%] py-3 rounded-full font-black text-base tracking-wide uppercase shadow-lg transition-all mt-2 ${!c||r||M?"bg-slate-200 text-slate-400 cursor-not-allowed border border-slate-300":"bg-gradient-to-r from-[#FFB356] to-[#FF8C00] text-white hover:from-[#FFA500] hover:to-[#FF7F00] border-b-4 border-[#e67e00]"}`,children:r||M?"Claiming...":c?"Claim!":"Claimed"})]})]})};function pn(t){const[s,n]=a.useState({difficulty:"normal",loading:!0});return a.useEffect(()=>{if(!t){n({difficulty:"normal",loading:!1});return}const i=kt(tt,"users",t);return as(i,c=>{if(!c.exists()){n({difficulty:"normal",loading:!1});return}const d=c.data()?.moduleDifficulty||"normal";n({difficulty:["normal","easier","remedial"].includes(d)?d:"normal",loading:!1})},c=>{console.error("[useModuleDifficulty] snapshot error:",c),n({difficulty:"normal",loading:!1})})},[t]),s}function hn(t,s){return s==="normal"?t:s==="easier"?t.filter(n=>{const i=n.tags||[],l=n.difficulty||"";return i.some(c=>["foundation","basic","introductory"].includes(c.toLowerCase()))||["foundation","basic","introductory"].includes(l.toLowerCase())||!i.includes("advanced")&&!l.toLowerCase().includes("advanced")}):s==="remedial"?t.filter(n=>{const i=n.tags||[],l=n.difficulty||"";return i.some(c=>["remedial","review","catch-up"].includes(c.toLowerCase()))||["remedial","review","catch-up"].includes(l.toLowerCase())}):t}const fn=new Set([7,14,30,60,100]),Et={lastClaimedDate:"",lastClaimedWeekSeed:0,claimedDays:[],currentStreak:0,longestStreak:0,totalClaimed:0,hintTokens:0,streakShields:0,activeMultiplier:null};function bn(t){if(t<=0)return"00:00:00";const s=Math.floor(t/1e3),n=Math.floor(s/3600),i=Math.floor(s%3600/60),l=s%60;return`${String(n).padStart(2,"0")}:${String(i).padStart(2,"0")}:${String(l).padStart(2,"0")}`}function gn(){const t=is();return t.setDate(t.getDate()-1),ls(t)}function Js(t){return t?new Date(t.expiresAt).getTime()>Date.now():!1}function ea(t){return kt(tt,"users",t,"dailyRewards",t)}function yn(t){return kt(tt,"users",t)}async function Fs(t){try{const s=ea(t),n=await Yt(s);if(!n.exists())return{...Et};const i=n.data(),l=os();return i.lastClaimedWeekSeed&&i.lastClaimedWeekSeed!==l?{...i,claimedDays:[],lastClaimedWeekSeed:l}:{...Et,...i,activeMultiplier:i.activeMultiplier&&Js(i.activeMultiplier)?i.activeMultiplier:null}}catch(s){return console.error("[dailyRewardService] Error getting state:",s),{...Et}}}function wn(t){const s=ls();return t.lastClaimedDate!==s}async function jn(t){const s=ls(),n=os(),i=cs(),c=ds()[i];if(!c)throw new Error(`No reward found for day index ${i}`);try{const r=await ra(tt,async x=>{const f=ea(t),M=yn(t),u=await x.get(f),N=await x.get(M);let m;if(u.exists()?m={...Et,...u.data()}:(m={...Et,lastClaimedWeekSeed:n},x.set(f,m)),m.lastClaimedWeekSeed!==n&&(m.claimedDays=[],m.lastClaimedWeekSeed=n),m.lastClaimedDate===s)return{code:"ALREADY_CLAIMED",state:m};let p=m.currentStreak,k=!1;if(!m.lastClaimedDate||m.currentStreak===0)p=1;else{const _=gn();m.lastClaimedDate===_?p=m.currentStreak+1:m.streakShields>0?(m.streakShields-=1,p=m.currentStreak+1,k=!0):p=1}const y=Math.max(m.longestStreak,p);let W=0,j=1;switch(c.type){case"xp":{const _=typeof c.value=="number"?c.value:parseInt(c.value,10)||0;j=Js(m.activeMultiplier)?m.activeMultiplier?.multiplier??1:1,W=Math.floor(_*j);break}case"hint_token":{const _=typeof c.value=="number"?c.value:parseInt(c.value,10)||0;m.hintTokens+=_;break}case"streak_shield":{const _=typeof c.value=="number"?c.value:parseInt(c.value,10)||0;m.streakShields+=_;break}case"xp_multiplier":{const _=typeof c.value=="number"?c.value:parseInt(c.value,10)||60,D=c.id.includes("2")?2:1.5,b=new Date;b.setMinutes(b.getMinutes()+_),m.activeMultiplier={multiplier:D,expiresAt:b.toISOString()};break}case"badge_unlock":break}const E=[...m.claimedDays,i];return m.lastClaimedDate=s,m.currentStreak=p,m.longestStreak=y,m.totalClaimed+=1,x.set(f,m,{merge:!0}),N.exists()&&x.update(M,{hintTokens:m.hintTokens,streakShields:m.streakShields,activeMultiplier:m.activeMultiplier,lastClaimedDate:m.lastClaimedDate,updatedAt:na()}),{code:"SUCCESS",state:m,newClaimedDays:E,newStreak:p,newLongestStreak:y,xpAwarded:W,multiplierApplied:j,streakPreserved:k}});if(r.code==="ALREADY_CLAIMED")return{success:!1,reward:c,dayIndex:i,streakAfter:r.state.currentStreak,longestStreakAfter:r.state.longestStreak,hintTokensAfter:r.state.hintTokens,streakShieldsAfter:r.state.streakShields,streakPreserved:!1,xpAwarded:0,multiplierApplied:1,isMilestone:!1,error:"Already claimed today"};if(r.xpAwarded>0)try{await ha(t,r.xpAwarded,"daily_reward",`Daily Reward Day ${i+1}! +${r.xpAwarded} XP`)}catch(x){console.error("[dailyRewardService] Error awarding XP:",x)}if(c.type==="badge_unlock"&&typeof c.value=="string")try{await Qs(t,c.value)}catch(x){console.error("[dailyRewardService] Error unlocking avatar item:",x)}const d=fn.has(r.newStreak);return{success:!0,reward:c,dayIndex:i,streakAfter:r.newStreak,longestStreakAfter:r.newLongestStreak,hintTokensAfter:r.state.hintTokens,streakShieldsAfter:r.state.streakShields,streakPreserved:r.streakPreserved,xpAwarded:r.xpAwarded,multiplierApplied:r.multiplierApplied,isMilestone:d}}catch(r){throw console.error("[dailyRewardService] Error claiming daily reward:",r),r}}function vn(t){const[s,n]=a.useState(null),[i,l]=a.useState(!1),[c,r]=a.useState(!1),[d,x]=a.useState(null),[f,M]=a.useState(null),[u,N]=a.useState("00:00:00"),m=a.useRef(null),p=a.useMemo(()=>ds(),[]),k=a.useMemo(()=>Mr(),[]),y=a.useCallback(async()=>{if(!t){n(null);return}try{M(null);const D=await Fs(t);n(D)}catch(D){const b=D instanceof Error?D.message:"Failed to load rewards";M(b),console.error("[useDailyReward] refresh error:",D)}},[t]);a.useEffect(()=>{y()},[y]),a.useEffect(()=>{const D=()=>{const I=Sr().getTime()-Date.now();N(bn(I))};return D(),m.current=setInterval(D,1e3),()=>{m.current&&(clearInterval(m.current),m.current=null)}},[]);const W=a.useMemo(()=>!s||i?!1:wn(s),[s,i]),j=a.useMemo(()=>!s?.activeMultiplier||new Date(s.activeMultiplier.expiresAt).getTime()<=Date.now()?null:s.activeMultiplier,[s?.activeMultiplier]),E=a.useCallback(async()=>{if(!(!t||!W)){l(!0),M(null);try{const D=await jn(t);if(x(D),D.success){r(!0);const b=await Fs(t);n(b)}else M(D.error||"Claim failed")}catch(D){const b=D instanceof Error?D.message:"Claim failed";M(b),console.error("[useDailyReward] claim error:",D)}finally{l(!1)}}},[t,W]),_=a.useCallback(()=>{r(!1)},[]);return{weekRewards:p,todayReward:k,canClaim:W,isClaiming:i,claimedDays:s?.claimedDays??[],currentStreak:s?.currentStreak??0,longestStreak:s?.longestStreak??0,totalClaimed:s?.totalClaimed??0,hintTokens:s?.hintTokens??0,streakShields:s?.streakShields??0,activeMultiplier:j,timeUntilReset:u,showModal:c,lastClaimResult:d,error:f,claim:E,dismissModal:_,refresh:y}}const Nn=["all","Q1","Q2","Q3","Q4"],hl=({onEarnXP:t,atRiskSubjects:s=[],priorityTopics:n=[],initialModuleId:i=null,isInQuizMode:l=!1,setIsInQuizMode:c,hasCompletedDiagnostic:r=!1})=>{const{userProfile:d,currentUser:x}=Bt(),[f,M]=a.useState(()=>{const o=sessionStorage.getItem("mathpulse_modules_tab");return o==="practice"||o==="recommended"||o==="teacher_uploaded"?(sessionStorage.removeItem("mathpulse_modules_tab"),o):"modules"}),u=d,N=u?.grade,m=fa(N);Ra(m);const[p,k]=a.useState(""),[y,W]=a.useState("all"),[j,E]=a.useState("all"),[_,D]=a.useState("all"),[b,I]=a.useState(!1),[B,se]=a.useState(null),[C,re]=a.useState(null),ge=a.useMemo(()=>{const o=u?.learnerCurriculumAssignments?.subjects??u?.assignedSubjects??u?.curriculumAssignedSubjects??[];return Array.isArray(o)?o:[]},[u]),{difficulty:Oe}=pn(x?.uid||null),oe=a.useMemo(()=>{const o=ba(m,ge);return hn(o,Oe)},[m,ge,Oe]),Qe=i&&oe.find(o=>o.id===i)||null,[Se,G]=a.useState(Qe),[ve,We]=a.useState(null),_e=je.useRef(null),[Ve,$e]=a.useState(null),[Ue,h]=a.useState(!1),[A,T]=a.useState(null),[X,$]=a.useState(!1),[Z,le]=a.useState([]),[Ae,fe]=a.useState(!1);a.useEffect(()=>{if(f!=="teacher_uploaded"||!tt)return;fe(!0);const o=as(la(oa(tt,"modules"),ia("moduleType","==","teacher_uploaded")),P=>{const Q=x?.uid,de=P.docs.map(U=>({...U.data(),moduleId:U.id})).filter(U=>!U.assignedTo||U.assignedTo===Q);le(de),fe(!1)},P=>{console.error("Error fetching teacher modules:",P),fe(!1)});return()=>o()},[f,x?.uid]);const[be,Te]=a.useState(!1),{weekRewards:F,todayReward:ee,canClaim:ue,isClaiming:Be,claimedDays:st,timeUntilReset:St,claim:bt,lastClaimResult:Ge}=vn(d?.uid??null);a.useEffect(()=>{if(!d?.uid)return;let o=!1;const P=async U=>{o||(ue||U)&&Te(!0)},Q=U=>{U.detail?.tab==="Modules"&&P(!0)},de=setTimeout(()=>P(),500);return window.addEventListener("mathpulse:navigate",Q),()=>{o=!0,clearTimeout(de),window.removeEventListener("mathpulse:navigate",Q)}},[d?.uid,ue]);const Ct=async()=>{if(d?.uid)try{await bt(),Ge?.success&&(Na({userId:d.uid,type:"daily_checkin",title:"Daily Reward Claimed!",message:`You earned ${Ge.reward.label} and kept your streak alive!`,metadata:{rewardId:Ge.reward.id,streakDay:Ge.dayIndex+1}}).catch(console.error),Ge.reward.rarity==="epic"&&Qs(d.uid,"acc_crown").then(()=>ut.success("Epic reward unlocked!")).catch(console.error)),setTimeout(()=>Te(!1),1e3)}catch(o){const P=o instanceof Error?o.message:"";console.error("Failed to claim daily reward:",o),P.includes("Already claimed")?ut.info("You already claimed your reward today!"):ut.error("Failed to claim daily reward. Please try again.")}};a.useEffect(()=>{if(i){const o=oe.find(P=>P.id===i);o&&G(o)}},[i,oe]),a.useEffect(()=>{d?.uid&&($(!0),ga(d.uid).then(o=>{T(o)}).catch(o=>{console.error("Failed to load competency profile:",o)}).finally(()=>{$(!1)}))},[d?.uid]);const Ne=a.useMemo(()=>{const o=n.length>0?n:s.map(Q=>ya(Q)).filter(Q=>Q!==null),P=new Set;return o.filter(Q=>P.has(Q)?!1:(P.add(Q),!0))},[n,s]),{data:ce=[]}=aa({queryKey:wa.modules(m,Ne),enabled:!0,staleTime:600*1e3,gcTime:1800*1e3,queryFn:async()=>{const o=oe;if(Ne.length===0)return o;const P=new Map(Ne.map((Q,de)=>[ka[Q],de]));return[...o].sort((Q,de)=>{const U=P.get(Q.id)??Number.POSITIVE_INFINITY,q=P.get(de.id)??Number.POSITIVE_INFINITY;return U-q})}}),at=a.useMemo(()=>{const o=new Set;return ce.forEach(P=>o.add(P.competency_group)),Array.from(o)},[ce]),rt=a.useMemo(()=>{const o=p.trim().toLowerCase(),P=ce.filter(Q=>{const de=!o||Q.title.toLowerCase().includes(o),U=!o||Q.description.toLowerCase().includes(o),q=!o||Q.lessons.some(Le=>Le.title.toLowerCase().includes(o)),me=!o||Q.quizzes.some(Le=>Le.title.toLowerCase().includes(o)),Pe=o?Q.competencies.some(Le=>Le.outcome.toLowerCase().includes(o)||Le.code.toLowerCase().includes(o)):!0,Ee=y==="all"||Q.subjectId===y,xe=j==="all"||Q.quarter===j,ne=_==="all"||Q.competency_group===_;return(de||U||q||me||Pe)&&Ee&&xe&&ne});if(A?.competencies){const Q=new Set(Object.entries(A.competencies).filter(([,U])=>U.score<50).map(([U])=>U)),de=new Set(Object.entries(A.competencies).filter(([,U])=>U.score>=80).map(([U])=>U));return P.sort((U,q)=>{const me=U.competencies.map(ke=>ke.code),Pe=q.competencies.map(ke=>ke.code),Ee=me.some(ke=>Q.has(ke))?1:0,xe=Pe.some(ke=>Q.has(ke))?1:0,ne=me.some(ke=>de.has(ke))?1:0,Le=Pe.some(ke=>de.has(ke))?1:0,gt=Ee*2+ne;return xe*2+Le-gt})}return P},[ce,p,y,j,_,A]),ct=a.useMemo(()=>{const o=j==="all"?"All Quarters":j,P=y==="all"?"All Subjects":hs[y]?.label??"Subject";return`${m} · ${P} · ${o}`},[m,y,j]),zt=a.useMemo(()=>{const o=new Set(ce.map(P=>P.subjectId));return Array.from(o)},[ce]),He=()=>{W("all"),E("all"),D("all"),k("")};a.useEffect(()=>{f!=="recommended"||Ne.length===0||(h(!0),ja({weakTopics:Ne.map(o=>fs[o]),subject:y!=="all"?y:"General Mathematics",userId:d?.uid}).then(o=>{$e(o.curriculumContext),h(!1)}).catch(()=>h(!1)))},[f,Ne]);const Ye=(o,P)=>{t&&t(P,`Quiz Completed! +${P} XP`)},Ke=async o=>{if(x?.uid)try{await Fa(x.uid,o),ut.success("You'll be notified when this module becomes available.")}catch{ut.error("Could not subscribe. Try again later.")}};return a.useEffect(()=>{c&&c(!!ve)},[ve,c]),ve?e.jsx(Ys,{quiz:ve,onClose:()=>{_e.current=null,We(null)},onComplete:Ye,onQuizEnd:_e.current??void 0,studentId:d?.uid}):Se?e.jsx(on,{module:Se,onBack:()=>G(null),onEarnXP:t,isInQuizMode:l,setIsInQuizMode:c}):C?e.jsxs("div",{className:"h-full overflow-y-auto px-4 sm:px-6 xl:px-10 pb-8 scrollbar-hide scroll-smooth relative",children:[e.jsxs("button",{onClick:()=>re(null),className:"mb-4 inline-flex items-center gap-2 text-sm font-bold text-slate-600 hover:text-slate-900 transition-colors",children:[e.jsx(ht,{className:"rotate-180",size:16}),"Back to Modules"]}),e.jsxs("div",{className:"bg-white rounded-2xl border border-[#F08386]/30 p-6 md:p-8",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx("span",{className:"px-2 py-1 rounded-md bg-[#F08386]/12 border border-[#F08386]/30 text-[#F08386] text-xs font-bold",children:"Teacher Upload"}),C.quarter&&e.jsx("span",{className:"px-2 py-1 rounded-md bg-slate-100 text-slate-600 text-xs",children:C.quarter})]}),e.jsx("h1",{className:"text-2xl md:text-3xl font-display font-black text-slate-900 mb-2",children:C.title}),e.jsxs("p",{className:"text-sm text-slate-600 mb-6",children:[C.subject," · ",C.gradeLevel]}),C.summary&&e.jsx("p",{className:"text-slate-700 text-base leading-relaxed mb-6",children:C.summary}),C.learningObjectives?.length>0&&e.jsxs("div",{className:"mb-6",children:[e.jsx("h2",{className:"text-lg font-bold text-slate-900 mb-2",children:"Learning Objectives"}),e.jsx("ul",{className:"list-disc list-inside space-y-1 text-slate-700",children:C.learningObjectives.map((o,P)=>e.jsx("li",{children:o},P))})]}),C.sections?.length>0&&e.jsxs("div",{className:"mb-6",children:[e.jsx("h2",{className:"text-lg font-bold text-slate-900 mb-3",children:"Sections"}),e.jsx("div",{className:"space-y-3",children:C.sections.map((o,P)=>e.jsxs("div",{className:"border border-slate-200 rounded-xl p-4",children:[e.jsx("h3",{className:"text-sm font-bold text-slate-800 mb-1",children:o.title}),e.jsx("p",{className:"text-sm text-slate-600 leading-relaxed",children:o.content})]},P))})]}),C.practice?.length>0&&e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-bold text-slate-900 mb-3",children:"Practice Questions"}),e.jsx("div",{className:"space-y-3",children:C.practice.map((o,P)=>e.jsxs("div",{className:"border border-slate-200 rounded-xl p-4",children:[e.jsx("p",{className:"text-sm font-bold text-slate-800 mb-2",children:o.question}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2 mb-2",children:o.options.map((Q,de)=>e.jsxs("div",{className:"text-xs text-slate-600 bg-slate-50 rounded-lg px-3 py-2",children:[Q.label,". ",Q.text]},de))}),e.jsxs("p",{className:"text-xs text-emerald-700 font-semibold",children:["Answer: ",o.answer]}),e.jsx("p",{className:"text-xs text-slate-500 mt-1",children:o.explanation})]},P))})]})]})]}):e.jsxs("div",{className:"h-full overflow-y-auto px-4 sm:px-6 xl:px-10 pb-8 scrollbar-hide scroll-smooth relative",onScroll:o=>I(o.currentTarget.scrollTop>100),children:[e.jsx(un,{isOpen:be,onClose:()=>Te(!1),onClaim:Ct,weekRewards:F,todayReward:ee,canClaim:ue,isClaiming:Be,claimedDays:st,currentDayIndex:cs(),timeUntilReset:St}),e.jsxs("div",{className:"flex flex-col lg:flex-row justify-between items-start lg:items-center py-4 md:py-6 gap-4 md:gap-6",children:[e.jsxs("div",{className:"flex-1 max-w-3xl",children:[e.jsx("h1",{className:"text-[28px] md:text-[44px] font-display font-black text-[#202124] tracking-tight leading-[1.1] mb-3 md:mb-4",children:"Curriculum Modules"}),e.jsx("p",{className:"text-[#3c4043] text-[13px] md:text-[17px] leading-relaxed md:leading-[1.7] md:pr-10",children:"MathPulse AI loads modules directly from DepEd Strengthened SHS curriculum guides with AI-powered RAG lesson generation. Currently available: General Mathematics, Business Mathematics, and Statistics & Probability. Pre-Calculus and Basic Calculus modules are coming soon once teaching module PDFs are sourced."}),e.jsx("div",{className:"mt-4 flex items-center gap-3",children:e.jsx("div",{className:"inline-flex items-center rounded-full border border-sky-200 bg-sky-50 px-4 py-2 text-sm font-bold text-sky-900",children:ct})})]}),e.jsx("div",{className:"hidden lg:flex flex-shrink-0 items-center justify-end w-[350px]",children:e.jsx(Is,{assessmentDismissed:d?.assessmentDismissed,initialAssessmentCompleted:d?.initialAssessmentCompleted})})]}),e.jsxs("div",{className:`sticky top-0 z-30 -mx-4 px-4 sm:-mx-6 sm:px-6 xl:-mx-10 xl:px-10 pt-3 pb-3 space-y-3 transition-colors duration-300 ${b?"bg-[#f8faff] border-b border-[#dde3eb] shadow-sm":"bg-transparent"}`,children:[e.jsxs("div",{className:"flex flex-col lg:flex-row items-center gap-3 w-full",children:[e.jsxs("div",{className:"relative flex-1 w-full",children:[e.jsx("div",{className:"absolute left-4 top-1/2 -translate-y-1/2 text-[#5f6368]",children:e.jsx($a,{size:16,strokeWidth:2.5})}),e.jsx("input",{id:"modules-search",name:"modules-search","aria-label":"Search modules",type:"text",value:p,onChange:o=>k(o.target.value),placeholder:"Search modules, lessons, or assessments...",className:"w-full pl-10 pr-10 py-2 rounded-xl border border-[#dadce0] bg-white text-[#202124] text-[13px] font-medium focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary transition-all shadow-sm"}),!1]}),e.jsxs("div",{className:"flex flex-row overflow-x-auto no-scrollbar items-center gap-2 w-full lg:w-auto shrink-0 -mx-4 px-4 sm:mx-0 sm:px-0 pb-1 sm:pb-0",children:[e.jsxs("select",{value:y,onChange:o=>W(o.target.value),className:"shrink-0 rounded-xl border border-slate-200 bg-white pl-3 pr-8 py-2 text-xs font-semibold text-slate-700 focus:border-sky-400 focus:outline-none shadow-sm","aria-label":"Subject",children:[e.jsx("option",{value:"all",children:"All Subjects"}),zt.map(o=>e.jsx("option",{value:o,children:hs[o].label},o))]}),e.jsx("select",{value:j,onChange:o=>E(o.target.value),className:"shrink-0 rounded-xl border border-slate-200 bg-white pl-3 pr-8 py-2 text-xs font-semibold text-slate-700 focus:border-sky-400 focus:outline-none shadow-sm","aria-label":"Quarter",children:Nn.map(o=>e.jsx("option",{value:o,children:o==="all"?"All Quarters":o},o))}),e.jsxs("select",{value:_,onChange:o=>D(o.target.value),className:"shrink-0 rounded-xl border border-slate-200 bg-white pl-3 pr-8 py-2 text-xs font-semibold text-slate-700 focus:border-sky-400 focus:outline-none shadow-sm","aria-label":"Competency Group",children:[e.jsx("option",{value:"all",children:"All Competencies"}),at.map(o=>e.jsx("option",{value:o,children:o},o))]}),e.jsxs("button",{type:"button",onClick:He,className:"inline-flex shrink-0 items-center justify-center gap-1.5 rounded-xl border border-slate-200 bg-white px-3 py-2 text-xs font-bold text-slate-700 transition-colors hover:bg-slate-50 shadow-sm",children:[e.jsx(Ba,{size:14}),"Reset"]})]})]}),e.jsxs("div",{className:"flex flex-col md:flex-row md:items-center gap-3 mt-2",children:[e.jsx("div",{className:"flex items-center bg-slate-100/80 p-1 rounded-full border border-slate-200/60 shadow-inner gap-1 overflow-x-auto no-scrollbar w-full md:w-auto",children:[{id:"modules",label:"Modules",icon:Fe,color:"text-[#1FA7E1]"},{id:"recommended",label:"Recommended",icon:At,color:"text-[#75D06A]"},{id:"practice",label:"Practice",icon:et,color:"text-[#FFB356]"},{id:"teacher_uploaded",label:"Teacher Uploaded",icon:va,color:"text-[#F08386]"}].map(o=>{const P=f===o.id;return e.jsxs("button",{onClick:()=>M(o.id),className:`relative flex items-center gap-1.5 px-4 py-1.5 rounded-full text-[13px] font-bold transition-all duration-300 flex-shrink-0 ${P?"shadow-sm":"text-slate-500 hover:text-slate-700 hover:bg-slate-200/50"}`,children:[P&&e.jsx(S.div,{layoutId:"modulesTabBackground",className:"absolute inset-0 bg-white rounded-full shadow-[0_2px_15px_-3px_rgba(0,0,0,0.1)] border border-slate-100",transition:{type:"spring",bounce:.2,duration:.6}}),e.jsxs("span",{className:`relative z-10 flex items-center gap-1.5 ${P?o.color:""}`,children:[e.jsx(o.icon,{size:15,strokeWidth:P?2.5:2}),o.label]})]},o.id)})}),e.jsxs("div",{className:"flex items-center gap-2 ml-1",children:[f==="modules"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-7 h-7 rounded-lg bg-indigo-50 border border-indigo-100 flex items-center justify-center text-indigo-500",children:e.jsx(Aa,{size:15,strokeWidth:2.5})}),e.jsx("span",{className:"font-display font-black text-[15px] text-slate-700 tracking-tight whitespace-nowrap",children:"DepEd Strengthened SHS Modules"})]}),f==="recommended"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-7 h-7 rounded-lg bg-[#75D06A]/10 flex items-center justify-center",children:e.jsx(Ha,{size:15,className:"text-[#75D06A]"})}),e.jsx("span",{className:"font-display font-black text-[15px] text-slate-700 tracking-tight whitespace-nowrap",children:"Suggested Next"})]}),f==="practice"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-7 h-7 rounded-lg bg-[#FFB356]/10 flex items-center justify-center",children:e.jsx(et,{size:15,className:"text-[#FFB356]"})}),e.jsx("span",{className:"font-display font-black text-[15px] text-slate-700 tracking-tight whitespace-nowrap",children:"Practice Center"})]}),f==="teacher_uploaded"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-7 h-7 rounded-lg bg-[#F08386]/15 border border-[#F08386]/30 flex items-center justify-center text-[#F08386]",children:e.jsx(ys,{size:15,strokeWidth:2.5})}),e.jsx("span",{className:"font-display font-black text-[15px] text-slate-700 tracking-tight whitespace-nowrap",children:"Teacher Uploaded Modules"})]})]})]})]}),e.jsx("div",{className:"flex lg:hidden items-center justify-center w-full mt-2 mb-2",children:e.jsx(Is,{assessmentDismissed:d?.assessmentDismissed,initialAssessmentCompleted:d?.initialAssessmentCompleted})}),e.jsxs("div",{className:"pt-4",children:[Ne.length>0&&e.jsxs("div",{className:"mb-4 rounded-2xl border border-amber-300 bg-amber-50 px-5 py-4 shadow-sm",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"inline-flex items-center gap-2 text-sm font-black text-amber-900",children:[e.jsx(Hs,{size:15}),"Assessment Focus Areas"]}),e.jsx("p",{className:"mt-1 text-sm text-amber-900/80",children:"Modules are currently prioritized by your latest diagnostic needs."})]}),e.jsxs("button",{type:"button",onClick:()=>M("recommended"),className:"inline-flex items-center gap-1.5 rounded-xl bg-amber-600 px-3 py-2 text-xs font-bold text-white transition-colors hover:bg-amber-700",children:["View Recommended",e.jsx(ht,{size:14})]})]}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:Ne.map((o,P)=>e.jsxs("span",{className:"rounded-full bg-white px-3 py-1 text-xs font-semibold text-amber-900 shadow-sm",children:[P+1,". ",fs[o]]},o))})]}),e.jsx(ot,{mode:"wait",children:e.jsx(S.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},exit:{opacity:0,y:-20},transition:{duration:.3},className:"pb-8 mt-4",children:f==="practice"?e.jsx(mn,{userId:d?.uid??"",onStartQuiz:o=>{_e.current=async(P,Q)=>{if(!(!d?.uid||!P.generatedQuizId))try{const de=new Map((P.loadedQuestions||[]).map(me=>[me.id,me])),U=Q.map(me=>{const Ee=de.get(me.questionId)?.options?.findIndex(xe=>xe.trim().toLowerCase()===me.answer.trim().toLowerCase())??0;return{question_id:me.questionId,selected_index:Ee}}),q=await nn({session_id:P.generatedQuizId,userId:d.uid,answers:U});ut.success(`Score: ${q.score_percent}% | Correct: ${q.correct_count}/${q.total} | +${q.xp_earned} XP`)}catch(de){console.error(de),ut.error("Failed to submit quiz results")}},We(o)},searchQuery:p}):f==="teacher_uploaded"?Ae?e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6 mt-6",children:[1,2,3].map(o=>e.jsxs("div",{className:"bg-white rounded-2xl border border-slate-200 p-6 animate-pulse",children:[e.jsx("div",{className:"h-4 bg-slate-200 rounded w-3/4 mb-4"}),e.jsx("div",{className:"h-3 bg-slate-100 rounded w-1/2 mb-3"}),e.jsx("div",{className:"h-3 bg-slate-100 rounded w-5/6"})]},o))}):Z.length===0?e.jsxs("div",{className:"text-center py-16",children:[e.jsx("div",{className:"w-16 h-16 bg-[#F08386]/10 rounded-2xl flex items-center justify-center mx-auto mb-4",children:e.jsx(ys,{size:32,className:"text-[#F08386]"})}),e.jsx("h3",{className:"text-lg font-bold text-slate-800 mb-2",children:"No Teacher-Uploaded Modules Yet"}),e.jsx("p",{className:"text-slate-500 text-sm",children:"Your teachers haven't uploaded any custom modules yet."})]}):e.jsx("div",{className:"grid grid-cols-2 lg:grid-cols-3 gap-3 md:gap-6 mt-6",children:Z.map(o=>e.jsxs("div",{className:"bg-white rounded-2xl border border-[#F08386]/30 p-6 hover:border-[#F08386]/60 hover:shadow-md transition-all cursor-pointer",onClick:()=>re(o),children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx("span",{className:"px-2 py-1 rounded-md bg-[#F08386]/12 border border-[#F08386]/30 text-[#F08386] text-xs font-bold",children:"Teacher Upload"}),o.quarter&&e.jsx("span",{className:"px-2 py-1 rounded-md bg-slate-100 text-slate-600 text-xs",children:o.quarter})]}),e.jsx("h3",{className:"text-lg font-bold text-slate-900 mb-2 line-clamp-2",children:o.title}),e.jsxs("p",{className:"text-sm text-slate-600 mb-3",children:[o.subject," · ",o.gradeLevel]}),o.summary&&e.jsx("p",{className:"text-xs text-slate-500 line-clamp-3",children:o.summary})]},o.moduleId))}):f==="modules"?e.jsx(kn,{modules:rt,onSelectModule:G,onPreviewSources:se,isAtRisk:Ne.length>0&&r,weakTopics:u?.assessmentResults?.weakTopics||[],onNotifyMe:Ke}):e.jsx(Sn,{modules:rt,fullPool:ce,onSelectModule:G,onPreviewSources:se,isAtRisk:Ne.length>0&&r,learningPathContext:Ve,learningPathLoading:Ue,weakTopics:u?.assessmentResults?.weakTopics||[],onNotifyMe:Ke})},f)})]}),e.jsx(ot,{children:B&&e.jsxs(S.aside,{initial:{opacity:0,x:24},animate:{opacity:1,x:0},exit:{opacity:0,x:24},transition:{duration:.25},className:"fixed inset-y-0 right-0 z-[80] w-full max-w-xl border-l border-slate-200 bg-white p-6 shadow-2xl",children:[e.jsxs("div",{className:"mb-4 flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-black uppercase tracking-wide text-sky-700",children:"Curriculum Preview"}),e.jsx("h3",{className:"mt-1 text-xl font-black text-slate-900",children:B.title}),e.jsxs("p",{className:"mt-1 text-sm text-slate-600",children:[B.active_grade_level," · ",B.subject," · ",B.quarter]})]}),e.jsx("button",{type:"button",onClick:()=>se(null),className:"rounded-lg border border-slate-200 p-2 text-slate-500 hover:bg-slate-50",children:e.jsx(Je,{size:16})})]}),e.jsxs("div",{className:"space-y-4 overflow-y-auto pr-1",children:[e.jsxs("div",{className:"rounded-2xl border border-slate-200 bg-slate-50 p-4",children:[e.jsx("p",{className:"text-xs font-bold uppercase tracking-wide text-slate-500",children:"Competency Group"}),e.jsx("p",{className:"mt-1 text-sm font-semibold text-slate-800",children:B.competency_group})]}),e.jsxs("div",{className:"rounded-2xl border border-slate-200 p-4",children:[e.jsx("p",{className:"text-xs font-bold uppercase tracking-wide text-slate-500",children:"Performance Standard"}),e.jsx("p",{className:"mt-1 text-sm text-slate-700",children:B.performance_standard})]}),e.jsxs("div",{className:"rounded-2xl border border-slate-200 p-4",children:[e.jsx("p",{className:"text-xs font-bold uppercase tracking-wide text-slate-500",children:"Competencies"}),e.jsx("div",{className:"mt-2 space-y-2",children:B.competencies.map(o=>e.jsxs("div",{className:"rounded-xl border border-slate-100 bg-slate-50 p-3",children:[e.jsx("p",{className:"text-xs font-black text-slate-600",children:o.code}),e.jsx("p",{className:"mt-1 text-sm text-slate-700",children:o.outcome})]},o.code))})]})]})]})})]})},kn=({modules:t,onSelectModule:s,onPreviewSources:n,isAtRisk:i=!1,weakTopics:l=[],onNotifyMe:c})=>e.jsx("div",{className:"pr-2 space-y-8",children:e.jsx("div",{children:t.length===0?e.jsxs("div",{className:"bg-white rounded-2xl border border-[#dde3eb] p-8 text-center",children:[e.jsx("p",{className:"text-slate-700 font-semibold",children:"No matching modules found."}),e.jsx("p",{className:"mt-2 text-sm text-slate-500",children:"If modules are not yet available for your selected view, this area will unlock after assessment sync and content rollout."})]}):e.jsx("div",{className:"grid grid-cols-2 lg:grid-cols-3 xl:grid-cols-3 gap-3 md:gap-6",children:t.map((r,d)=>{const x=l.some(f=>r.content_domain&&r.content_domain.toLowerCase().includes(f.toLowerCase())||r.title&&r.title.toLowerCase().includes(f.toLowerCase())||r.competency_group&&r.competency_group.toLowerCase().includes(f.toLowerCase())||r.subject&&r.subject.toLowerCase().includes(f.toLowerCase()));return e.jsx(Kt,{module:r,index:d,onClick:()=>s(r),onPreviewSources:()=>n(r),isAtRisk:i,isRecommended:x,onNotifyMe:c},r.id)})})})}),Sn=({modules:t,fullPool:s,onSelectModule:n,onPreviewSources:i,isAtRisk:l=!1,learningPathContext:c=null,learningPathLoading:r=!1,weakTopics:d=[],onNotifyMe:x})=>{const f=t.filter(u=>u.progress>0&&u.progress<100),M=(t.length>0?t:s).filter(u=>u.progress===0).slice(0,6);return e.jsxs("div",{className:"pr-2 space-y-10",children:[r&&e.jsxs("div",{className:"mb-6 rounded-2xl border border-sky-200 bg-sky-50 px-5 py-4 flex items-center gap-3",children:[e.jsx("div",{className:"w-5 h-5 rounded-full border-2 border-sky-400 border-t-transparent animate-spin flex-shrink-0"}),e.jsx("p",{className:"text-sm font-semibold text-sky-800",children:"Building your personalized learning path from DepEd curriculum..."})]}),c&&!r&&e.jsxs("div",{className:"mb-6 rounded-2xl border border-indigo-200 bg-gradient-to-br from-indigo-50 to-purple-50 px-5 py-4 shadow-sm",children:[e.jsxs("p",{className:"text-xs font-black uppercase tracking-wide text-indigo-700 mb-2 flex items-center gap-1.5",children:[e.jsx(Fe,{size:14})," Your Personalized Learning Path"]}),e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-indigo-900 font-medium leading-relaxed font-sans",children:c})]}),f.length>0&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-3 mb-6",children:[e.jsx("div",{className:"w-10 h-10 rounded-[14px] bg-[#FF8B8B]/10 flex items-center justify-center shadow-inner",children:e.jsx(rs,{size:20,className:"text-[#FF8B8B]"})}),e.jsx("h2",{className:"font-display font-black text-[24px] text-slate-800 tracking-tight",children:"Continue This Module"})]}),e.jsx("div",{className:"grid grid-cols-2 lg:grid-cols-3 xl:grid-cols-3 gap-3 md:gap-6",children:f.slice(0,4).map((u,N)=>{const m=d.some(p=>u.content_domain&&u.content_domain.toLowerCase().includes(p.toLowerCase())||u.title&&u.title.toLowerCase().includes(p.toLowerCase())||u.competency_group&&u.competency_group.toLowerCase().includes(p.toLowerCase())||u.subject&&u.subject.toLowerCase().includes(p.toLowerCase()));return e.jsx(Kt,{module:u,index:N,onClick:()=>n(u),onPreviewSources:()=>i(u),isAtRisk:l,badgeLabel:"In Progress",isRecommended:m,onNotifyMe:x},u.id)})})]}),e.jsx("div",{children:M.length===0?e.jsx("div",{className:"bg-white rounded-2xl border border-[#dde3eb] p-8 text-center text-slate-500 font-medium",children:"You are all caught up. Practice more quizzes to unlock additional recommendations."}):e.jsx("div",{className:"grid grid-cols-2 lg:grid-cols-3 xl:grid-cols-3 gap-3 md:gap-6",children:M.map((u,N)=>{const m=d.some(p=>u.content_domain&&u.content_domain.toLowerCase().includes(p.toLowerCase())||u.title&&u.title.toLowerCase().includes(p.toLowerCase())||u.competency_group&&u.competency_group.toLowerCase().includes(p.toLowerCase())||u.subject&&u.subject.toLowerCase().includes(p.toLowerCase()));return e.jsx(Kt,{module:u,index:N,onClick:()=>n(u),onPreviewSources:()=>i(u),isAtRisk:l,badgeLabel:"Start",isRecommended:m,onNotifyMe:x},u.id)})})})]})};export{hl as default}; diff --git a/assets/ModulesPage-CTVBRDaK.js b/assets/ModulesPage-CTVBRDaK.js new file mode 100644 index 0000000000000000000000000000000000000000..ca2188b9ee02a7680fabb925aefbfbbe0e38d1a3 --- /dev/null +++ b/assets/ModulesPage-CTVBRDaK.js @@ -0,0 +1,189 @@ +const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-Bp7MiGcW.js","assets/vendor-react-B4AQeu28.js","assets/vendor-firebase-firestore-CNv3xXal.js","assets/vendor-firebase-core-D7GXCeNu.js","assets/vendor-firebase-auth-T_wvTOvf.js","assets/vendor-firebase-storage-Bi7H_66d.js","assets/vendor-firebase-analytics-rHarj5hR.js","assets/vendor-radix-C5nwdvGr.js","assets/vendor-charts-CAmziV1y.js","assets/vendor-markdown-yqZQ_iQm.js","assets/vendor-markdown-CfVKi3_s.css","assets/index-Dja0MwoB.css"])))=>i.map(i=>d[i]); +import{j as e,r as a,b as At,d as Ie,c as Ws}from"./vendor-react-B4AQeu28.js";import{u as Us}from"./useQuery-DN_XJYxl.js";import{doc as ht,onSnapshot as es,getDoc as Ut,runTransaction as Gs,serverTimestamp as Xs,query as Vs,where as Ys,collection as Ks}from"./vendor-firebase-firestore-CNv3xXal.js";import{e as de,g as Ke,ae as Zs,_ as St,m as E,Z as Ve,h as Ze,$ as Gt,b as $e,w as at,a as tt,r as Qe,a7 as As,C as ut,M as Js,L as ts,T as Pt,u as $t,A as zt,o as _t,y as Es,R as ea,ad as Xt,af as ta,ag as os,ah as sa,q as Ps,ai as aa,F as Ts,B as ra,aj as la,ak as Ls,al as na,am as ia,an as oa,ab as ca,x as da,ao as cs,ap as ma,aq as ds,G as xa,j as mt,a9 as ua,ac as pa}from"./index-Bp7MiGcW.js";import{M as Vt}from"./ModuleFolderCard-BaBw0Pd9.js";import{B as qe}from"./button-BMVm9YQO.js";import{M as ha,r as fa,a as ba}from"./vendor-markdown-yqZQ_iQm.js";import{triggerQuizSubmitted as ga}from"./automationService-g67Xos9d.js";import{e as ya,g as wa,A as Yt,V as ja,c as va,P as Kt,L as Na}from"./quizService-DrftrnKO.js";import Rs from"./ScientificCalculator-BCm13p89.js";import{C as Et}from"./check-qsSFTYCr.js";import{X as Ye}from"./x-k8d6VLEw.js";import{C as pt}from"./clock-Cc6sJz1J.js";import{V as Zt,a as Jt,M as Ds,b as Is}from"./volume-x-DCLZlWDn.js";import{C as ms}from"./chevron-left-Be5knpOV.js";import{C as xt}from"./chevron-right-BxoysOas.js";import{C as Ot,L as ot}from"./lightbulb-DG1NwVgr.js";import{C as st}from"./circle-check-big-JdaMs3bP.js";import{C as Bt}from"./circle-help-CLCoBWDy.js";import{logLessonView as ka}from"./trackingService-C66NvvrU.js";import{C as Ca}from"./clipboard-check-Cb8JdEuA.js";import{s as Mt,S as xs}from"./subjects-DNoBzeBL.js";import{C as Fs}from"./circle-check-DzQphSnP.js";import{H as Sa}from"./history-DVu_-tNM.js";import{C as za}from"./chart-column-Dyv8TfXk.js";import{D as _a}from"./dollar-sign-Dm4HJ6Ci.js";import us from"./confetti.module-C94ZD2ww.js";import{G as Ma}from"./gift-CnT2c-5r.js";import{u as Aa}from"./useCurriculum-BaLeFz19.js";import{w as Ea}from"./moduleWatchService-Cyzc6bn4.js";import{S as Pa}from"./search-DbD51Zen.js";import{F as Ta}from"./funnel-KPSYPixk.js";import{S as La}from"./sparkles-fLB3ltj1.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-radix-C5nwdvGr.js";import"./vendor-charts-CAmziV1y.js";import"./useSubjectAvailability-Dm-85m8R.js";import"./deepseekRagService-Bke9fSTt.js";import"./bell-DyLbgepV.js";import"./info-Bcg_cBHY.js";import"./chevron-up-DtS9MvUZ.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 Ra=[["rect",{x:"14",y:"14",width:"4",height:"6",rx:"2",key:"p02svl"}],["rect",{x:"6",y:"4",width:"4",height:"6",rx:"2",key:"xm4xkj"}],["path",{d:"M6 20h4",key:"1i6q5t"}],["path",{d:"M14 10h4",key:"ru81e7"}],["path",{d:"M6 14h2v6",key:"16z9wg"}],["path",{d:"M14 4h2v6",key:"1idq9u"}]],Da=de("binary",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 Ia=[["path",{d:"M15 13a3 3 0 1 0-6 0",key:"10j68g"}],["path",{d:"M4 19.5v-15A2.5 2.5 0 0 1 6.5 2H19a1 1 0 0 1 1 1v18a1 1 0 0 1-1 1H6.5a1 1 0 0 1 0-5H20",key:"k3hazp"}],["circle",{cx:"12",cy:"8",r:"2",key:"1822b1"}]],ps=de("book-user",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:"m19 21-7-4-7 4V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16z",key:"1fy3hk"}]],hs=de("bookmark",Fa);/** + * @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=[["path",{d:"M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z",key:"hh9hay"}],["path",{d:"m3.3 7 8.7 5 8.7-5",key:"g66t2b"}],["path",{d:"M12 22V12",key:"d0xqtd"}]],fs=de("box",$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 qa=[["path",{d:"M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1",key:"ezmyqa"}],["path",{d:"M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 1-2-2V5a2 2 0 0 0-2-2h-1",key:"e1hn23"}]],bs=de("braces",qa);/** + * @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 Oa=[["circle",{cx:"7.5",cy:"7.5",r:".5",fill:"currentColor",key:"kqv944"}],["circle",{cx:"18.5",cy:"5.5",r:".5",fill:"currentColor",key:"lysivs"}],["circle",{cx:"11.5",cy:"11.5",r:".5",fill:"currentColor",key:"byv1b8"}],["circle",{cx:"7.5",cy:"16.5",r:".5",fill:"currentColor",key:"nkw3mc"}],["circle",{cx:"17.5",cy:"14.5",r:".5",fill:"currentColor",key:"1gjh6j"}],["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}]],Ba=de("chart-scatter",Oa);/** + * @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 Ha=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["polygon",{points:"10 8 16 12 10 16 10 8",key:"1cimsy"}]],Qa=de("circle-play",Ha);/** + * @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 Wa=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]],Tt=de("circle",Wa);/** + * @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=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"22",x2:"18",y1:"12",y2:"12",key:"l9bcsi"}],["line",{x1:"6",x2:"2",y1:"12",y2:"12",key:"13hhkx"}],["line",{x1:"12",x2:"12",y1:"6",y2:"2",key:"10w3f3"}],["line",{x1:"12",x2:"12",y1:"22",y2:"18",key:"15g9kq"}]],Ga=de("crosshair",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 Xa=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}],["path",{d:"M16 8h.01",key:"cr5u4v"}],["path",{d:"M8 8h.01",key:"1e4136"}],["path",{d:"M8 16h.01",key:"18s6g9"}],["path",{d:"M16 16h.01",key:"1f9h7w"}],["path",{d:"M12 12h.01",key:"1mp3jc"}]],Va=de("dice-5",Xa);/** + * @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 Ya=[["circle",{cx:"12",cy:"6",r:"1",key:"1bh7o1"}],["line",{x1:"5",x2:"19",y1:"12",y2:"12",key:"13b5wn"}],["circle",{cx:"12",cy:"18",r:"1",key:"lqb9t5"}]],kt=de("divide",Ya);/** + * @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 Ka=[["path",{d:"M14 2v6a2 2 0 0 0 .245.96l5.51 10.08A2 2 0 0 1 18 22H6a2 2 0 0 1-1.755-2.96l5.51-10.08A2 2 0 0 0 10 8V2",key:"18mbvz"}],["path",{d:"M6.453 15h11.094",key:"3shlmq"}],["path",{d:"M8.5 2h7",key:"csnxdl"}]],Za=de("flask-conical",Ka);/** + * @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 Ja=[["line",{x1:"4",x2:"20",y1:"9",y2:"9",key:"4lhtct"}],["line",{x1:"4",x2:"20",y1:"15",y2:"15",key:"vyu0kd"}],["line",{x1:"10",x2:"8",y1:"3",y2:"21",key:"1ggp8o"}],["line",{x1:"16",x2:"14",y1:"3",y2:"21",key:"weycgp"}]],gs=de("hash",Ja);/** + * @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 er=[["path",{d:"M19 14c1.49-1.46 3-3.21 3-5.5A5.5 5.5 0 0 0 16.5 3c-1.76 0-3 .5-4.5 2-1.5-1.5-2.74-2-4.5-2A5.5 5.5 0 0 0 2 8.5c0 2.3 1.5 4.05 3 5.5l7 7Z",key:"c3ymky"}],["path",{d:"m12 13-1-1 2-2-3-3 2-2",key:"xjdxli"}]],tr=de("heart-crack",er);/** + * @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 sr=[["path",{d:"m15.5 7.5 2.3 2.3a1 1 0 0 0 1.4 0l2.1-2.1a1 1 0 0 0 0-1.4L19 4",key:"g0fldk"}],["path",{d:"m21 2-9.6 9.6",key:"1j0ho8"}],["circle",{cx:"7.5",cy:"15.5",r:"5.5",key:"yqb3hr"}]],ar=de("key",sr);/** + * @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 rr=[["path",{d:"M13.4 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-7.4",key:"re6nr2"}],["path",{d:"M2 6h4",key:"aawbzj"}],["path",{d:"M2 10h4",key:"l0bgd4"}],["path",{d:"M2 14h4",key:"1gsvsf"}],["path",{d:"M2 18h4",key:"1bu2t1"}],["path",{d:"M21.378 5.626a1 1 0 1 0-3.004-3.004l-5.01 5.012a2 2 0 0 0-.506.854l-.837 2.87a.5.5 0 0 0 .62.62l2.87-.837a2 2 0 0 0 .854-.506z",key:"pqwjuv"}]],lr=de("notebook-pen",rr);/** + * @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 nr=[["line",{x1:"19",x2:"5",y1:"5",y2:"19",key:"1x9vlm"}],["circle",{cx:"6.5",cy:"6.5",r:"2.5",key:"4mh3h7"}],["circle",{cx:"17.5",cy:"17.5",r:"2.5",key:"1mdrzq"}]],Lt=de("percent",nr);/** + * @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 ir=[["path",{d:"M21.3 15.3a2.4 2.4 0 0 1 0 3.4l-2.6 2.6a2.4 2.4 0 0 1-3.4 0L2.7 8.7a2.41 2.41 0 0 1 0-3.4l2.6-2.6a2.41 2.41 0 0 1 3.4 0Z",key:"icamh8"}],["path",{d:"m14.5 12.5 2-2",key:"inckbg"}],["path",{d:"m11.5 9.5 2-2",key:"fmmyf7"}],["path",{d:"m8.5 6.5 2-2",key:"vc6u1g"}],["path",{d:"m17.5 15.5 2-2",key:"wo5hmg"}]],$s=de("ruler",ir);/** + * @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 or=[["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:"M14 15H9v-5",key:"pi4jk9"}],["path",{d:"M16 3h5v5",key:"1806ms"}],["path",{d:"M21 3 9 15",key:"15kdhq"}]],cr=de("scaling",or);/** + * @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 dr=[["path",{d:"M18 7V5a1 1 0 0 0-1-1H6.5a.5.5 0 0 0-.4.8l4.5 6a2 2 0 0 1 0 2.4l-4.5 6a.5.5 0 0 0 .4.8H17a1 1 0 0 0 1-1v-2",key:"wuwx1p"}]],Rt=de("sigma",dr);/** + * @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 mr=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}],["path",{d:"M9 17c2 0 2.8-1 2.8-2.8V10c0-2 1-3.3 3.2-3",key:"m1af9g"}],["path",{d:"M9 11.2h5.7",key:"3zgcl2"}]],Ht=de("square-function",mr);/** + * @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 xr=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]],Dt=de("square",xr);/** + * @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 ur=[["line",{x1:"10",x2:"14",y1:"2",y2:"2",key:"14vaq8"}],["line",{x1:"12",x2:"15",y1:"14",y2:"11",key:"17fdiu"}],["circle",{cx:"12",cy:"14",r:"8",key:"1e1u0o"}]],pr=de("timer",ur);/** + * @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 hr=[["path",{d:"M13.73 4a2 2 0 0 0-3.46 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z",key:"14u9p9"}]],It=de("triangle",hr);function fr(t){let s=t>>>0;return()=>{s+=1831565813;let l=Math.imul(s^s>>>15,s|1);return l^=l+Math.imul(l^l>>>7,l|61),((l^l>>>14)>>>0)/4294967296}}function br(t,s){const l=[...t],n=fr(s);for(let i=l.length-1;i>0;i--){const c=Math.floor(n()*(i+1));[l[i],l[c]]=[l[c],l[i]]}return l}function ss(t){const s=t??new Date;return new Intl.DateTimeFormat("en-CA",{timeZone:"Asia/Manila",year:"numeric",month:"2-digit",day:"2-digit"}).format(s)}function as(t){const s=new Date,l=new Intl.DateTimeFormat("en-US",{timeZone:"Asia/Manila",year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!1}).formatToParts(s),n=i=>parseInt(l.find(c=>c.type===i)?.value??"0",10);return new Date(n("year"),n("month")-1,n("day"),n("hour"),n("minute"),n("second"))}function rs(t){const s=as(),l=s.getFullYear(),n=(s.getDay()+6)%7,i=new Date(s);i.setDate(s.getDate()-n+3);const c=new Date(i.getFullYear(),0,1),r=Math.floor((i.getTime()-c.getTime())/(1440*60*1e3)),u=Math.floor(r/7)+1;return l*100+u}function ls(t){return(as().getDay()+6)%7}function gr(t){const s=new Date,l=480*60*1e3,n=s.getTime()+l,c=(new Date(n).getUTCDay()+6)%7,r=c===0?7:7-c,d=n-n%(1440*60*1e3)+r*24*60*60*1e3;return new Date(d-l)}const yr=[{id:"xp_50",label:"+50 XP Boost",description:"Bonus XP on your next quiz",icon:"⚡",type:"xp",value:50,rarity:"common",color:"#4ade80"},{id:"xp_100",label:"+100 XP Boost",description:"Double bonus XP reward",icon:"🌟",type:"xp",value:100,rarity:"rare",color:"#facc15"},{id:"xp_200",label:"+200 XP Epic Boost",description:"Massive XP surge",icon:"💥",type:"xp",value:200,rarity:"epic",color:"#f97316"},{id:"streak_shield",label:"Streak Shield",description:"Protects streak if you miss a day",icon:"🛡️",type:"streak_shield",value:1,rarity:"rare",color:"#60a5fa"},{id:"hint_x3",label:"3 Hint Tokens",description:"Use in-quiz hints",icon:"💡",type:"hint_token",value:3,rarity:"common",color:"#a78bfa"},{id:"hint_x5",label:"5 Hint Tokens",description:"More hints to use",icon:"🔦",type:"hint_token",value:5,rarity:"rare",color:"#8b5cf6"},{id:"xp_mult_1h",label:"1-Hour XP ×1.5",description:"1.5× XP for all quizzes for 1 hour",icon:"⏰",type:"xp_multiplier",value:60,rarity:"epic",color:"#ec4899"},{id:"xp_mult_30m",label:"30-Min XP ×2",description:"2× XP for 30 minutes",icon:"🚀",type:"xp_multiplier",value:30,rarity:"epic",color:"#e11d48"},{id:"xp_75",label:"+75 XP Boost",description:"Solid XP reward",icon:"✨",type:"xp",value:75,rarity:"common",color:"#34d399"},{id:"hint_x2",label:"2 Hint Tokens",description:"Quick hint pack",icon:"🕯️",type:"hint_token",value:2,rarity:"common",color:"#7c3aed"},{id:"xp_streak_150",label:"+150 XP + Streak Save",description:"XP boost + streak protection combo",icon:"🔥",type:"xp",value:150,rarity:"epic",color:"#dc2626"},{id:"xp_25",label:"+25 XP Starter",description:"Small but reliable XP",icon:"🌱",type:"xp",value:25,rarity:"common",color:"#86efac"},{id:"hint_x1",label:"1 Hint Token",description:"A single lifeline",icon:"🔍",type:"hint_token",value:1,rarity:"common",color:"#c4b5fd"},{id:"streak_shield2",label:"2 Streak Shields",description:"Double streak protection",icon:"🏰",type:"streak_shield",value:2,rarity:"epic",color:"#3b82f6"},{id:"xp_120",label:"+120 XP Power Surge",description:"Strong XP reward for the day",icon:"⚡",type:"xp",value:120,rarity:"rare",color:"#16a34a"},{id:"hint_x4",label:"4 Hint Tokens",description:"Generous hint pack",icon:"📚",type:"hint_token",value:4,rarity:"rare",color:"#9333ea"}];function wr(t){return br(yr,t).slice(0,7).map((n,i)=>({...n,day:i}))}function ns(){return wr(rs())}function jr(){const t=ns(),s=ls();return t[s]}function vr(t){if(!t)return"";if(t.includes("$")||!/\d[\^*×÷]|[\^*×÷]\d|\\frac|\\sqrt|\\times|\w\^\w/.test(t))return t;const l=t.match(/^([A-Z]:\s*)/),n=l?l[1]:"",i=n?t.slice(n.length):t;if(i.includes("=")&&(i.includes("^")||i.includes("*"))){const r=ys(i);return n?`${n}$${r}$`:`$${r}$`}return t.replace(/([A-Za-z()\d.]+(?:\s*[*×]\s*[A-Za-z()\d.^{}]+)+|[A-Za-z()\d.]+\^[A-Za-z()\d.{}]+)/g,r=>`$${ys(r)}$`)}function ys(t){let s=t;return s=s.replace(/\s*\*\s*/g," \\times "),s=s.replace(/\^(\{[^}]+\})/g,"^$1"),s=s.replace(/\^([^{])/g,"^{$1}"),s}const Ft=({children:t,className:s})=>{if(!t||typeof t!="string")return null;const l=vr(t);return l.includes("$")?e.jsx("span",{className:s,children:e.jsx(ha,{remarkPlugins:[ba],rehypePlugins:[fa],components:{p:({children:n})=>e.jsx(e.Fragment,{children:n})},children:l})}):e.jsx("span",{className:s,children:t})};function Nr(t){const[s,l]=a.useState({extraHintsEnabled:!1,hintTokens:0,totalHintsAvailable:0,loading:!0});return a.useEffect(()=>{if(!t){l({extraHintsEnabled:!1,hintTokens:0,totalHintsAvailable:0,loading:!1});return}const n=ht(Ke,"users",t);return es(n,c=>{if(!c.exists()){l({extraHintsEnabled:!1,hintTokens:0,totalHintsAvailable:0,loading:!1});return}const r=c.data(),u=r?.extraHintsEnabled===!0,d=r?.hintTokens||0,h=u?d+3:d;l({extraHintsEnabled:u,hintTokens:d,totalHintsAvailable:h,loading:!1})},c=>{console.error("[useExtraHints] snapshot error:",c),l({extraHintsEnabled:!1,hintTokens:0,totalHintsAvailable:0,loading:!1})})},[t]),s}const ws=` + @keyframes score-pop { + 0% { transform: scale(1); } + 50% { transform: scale(1.4); } + 100% { transform: scale(1); } + } + @keyframes overlay-slide-up { + 0% { transform: translateY(40px) scale(0.85); opacity: 0; } + 100% { transform: translateY(0) scale(1); opacity: 1; } + } + @keyframes confetti-fall { + 0% { transform: translateY(-10vh) rotate(0deg); opacity: 1; } + 100% { transform: translateY(110vh) rotate(720deg); opacity: 0; } + } + .animate-score-pop { animation: score-pop 0.5s ease-out forwards; } + .animate-overlay-slide-up { animation: overlay-slide-up 0.4s cubic-bezier(0.22, 1, 0.36, 1) forwards; } + .confetti-piece { + position: absolute; + width: 10px; + height: 10px; + animation: confetti-fall linear forwards; + } +`,kr=({viewportHeight:t})=>e.jsx("div",{className:"absolute inset-0 pointer-events-none z-[250] overflow-hidden flex justify-between bg-slate-900/5",children:Ie.useMemo(()=>[...Array(40)].map((s,l)=>({id:l,left:`${Math.random()*100}%`,duration:.6+Math.random()*.4,delay:Math.random()*.4})),[t]).map(s=>e.jsx(E.div,{className:"absolute w-0.5 h-16 bg-blue-400/30 rounded-full",style:{left:s.left,top:"-10%"},animate:{y:[0,t*1.2]},transition:{duration:s.duration,ease:"linear",delay:s.delay}},s.id))}),Cr=()=>{const t=Ie.useMemo(()=>[...Array(60)].map((s,l)=>({id:l,left:`${Math.random()*100}%`,backgroundColor:["#75D06A","#6ED1CF","#9956DE","#FB96BB","#FFB356"][l%5],duration:2+Math.random()*2,delay:Math.random()*.5,size:6+Math.random()*8,borderRadius:Math.random()>.5?"50%":"2px"})),[]);return e.jsx("div",{className:"absolute inset-0 pointer-events-none z-[250] overflow-hidden",children:t.map(s=>e.jsx("div",{className:"confetti-piece",style:{left:s.left,top:"-10%",backgroundColor:s.backgroundColor,width:s.size,height:s.size,borderRadius:s.borderRadius,animationDuration:`${s.duration}s`,animationDelay:`${s.delay}s`}},s.id))})},Sr=({viewportHeight:t,viewportWidth:s})=>{const l=Ie.useMemo(()=>[...Array(30)].map((n,i)=>({id:i,xShift:(Math.random()-.5)*s*.8,yShift:(Math.random()-.5)*t*.8,scale:Math.random()*1.5+.5,duration:2+Math.random()*1.5,delay:Math.random()*.35})),[t,s]);return e.jsx("div",{className:"absolute inset-0 pointer-events-none z-[250] overflow-hidden flex items-center justify-center",children:l.map(n=>e.jsx(E.div,{className:"absolute w-2 h-2 bg-amber-400 rounded-full shadow-[0_0_10px_rgba(251,191,36,0.5)]",style:{left:"50%",top:"50%"},animate:{y:[0,n.yShift],x:[0,n.xShift],scale:[0,n.scale,0],opacity:[0,1,0]},transition:{duration:n.duration,ease:"easeOut",delay:n.delay}},n.id))})},js=({value:t,label:s,delay:l=0,icon:n})=>{const[i,c]=Ie.useState(0);return Ie.useEffect(()=>{if(t<=0)return;const r=1e3,u=30,d=Math.abs(Math.floor(r/u));let h=0;const S=setTimeout(()=>{const m=setInterval(()=>{h+=Math.max(1,Math.floor(t/u)),h>=t?(c(t),clearInterval(m)):c(h)},d);return()=>clearInterval(m)},l);return()=>clearTimeout(S)},[t,l]),t<0?null:e.jsxs(E.div,{initial:{opacity:0,transform:"translateX(-20px)"},animate:{opacity:1,transform:"translateX(0)"},transition:{delay:l/1e3,duration:.5},className:"flex items-center justify-between bg-slate-50 border border-slate-100 rounded-xl p-3",children:[e.jsxs("div",{className:"flex items-center gap-3 text-slate-500 font-bold uppercase tracking-wider text-[10px]",children:[n,s]}),e.jsxs("div",{className:"text-xl font-black text-purple-600 tabular-nums",children:["+",i]})]})};function zr(t){if(t.questionType==="multiple_choice"&&t.options&&t.options.length>0){const s=t.options.findIndex(l=>l.trim().toLowerCase()===t.correctAnswer.trim().toLowerCase());return{id:t.id,question:t.question,options:t.options,correctAnswer:s>=0?s:0,correctAnswerText:t.correctAnswer,explanation:t.explanation,questionType:t.questionType,points:t.points,difficulty:t.difficulty,topic:t.topic,bloomLevel:t.bloomLevel}}return{id:t.id,question:t.question,options:[],correctAnswer:-1,correctAnswerText:t.correctAnswer,explanation:t.explanation,questionType:t.questionType,points:t.points,difficulty:t.difficulty,topic:t.topic,bloomLevel:t.bloomLevel}}function vs(t){return t.replace(/²/g,"^2").replace(/³/g,"^3").replace(/⁻¹/g,"^-1").replace(/⁰/g,"^0").replace(/¹/g,"^1").replace(/⁴/g,"^4").replace(/⁵/g,"^5").replace(/⁶/g,"^6").replace(/⁷/g,"^7").replace(/⁸/g,"^8").replace(/⁹/g,"^9").replace(/π/g,"pi").replace(/√/g,"sqrt").replace(/×/g,"*").replace(/÷/g,"/").replace(/\s+/g,"").toLowerCase().trim()}function _r(t,s,l){const n=i=>i.trim().toLowerCase().replace(/\s+/g," ");switch(l){case"identification":return n(t)===n(s);case"enumeration":{const i=t.split(",").map(r=>n(r)).filter(Boolean).sort(),c=s.split(",").map(r=>n(r)).filter(Boolean).sort();return JSON.stringify(i)===JSON.stringify(c)}case"word_problem":case"equation_based":{const i=vs(t),c=vs(s);if(i===c)return!0;const r=parseFloat(t.replace(/[^\d.\-]/g,"")),u=parseFloat(s.replace(/[^\d.\-]/g,""));return!isNaN(r)&&!isNaN(u)?Math.abs(r-u)<=.01:n(t)===n(s)}default:return n(t)===n(s)}}const qs=({quiz:t,onClose:s,onComplete:l,onQuizEnd:n,studentId:i,atRiskSubjects:c=[]})=>{const[r,u]=a.useState(0),[d,h]=a.useState(null),[S,m]=a.useState(""),[M,p]=a.useState(!1),[x,N]=a.useState(!1),[g,z]=a.useState(!1),[k,R]=a.useState(0),[P,F]=a.useState(0),[X,K]=a.useState(1),[Y,ee]=a.useState([]),[D,me]=a.useState([]),[ue,Se]=a.useState(Date.now()),[Ce,f]=a.useState(!1),[q,O]=a.useState(!1),[ae,ie]=a.useState(null),[be,ze]=a.useState(0),[Le,_e]=a.useState(0),[b,T]=a.useState(!1),[C,B]=a.useState(!1),[I,te]=a.useState(!0),[xe,ve]=a.useState(!1),[ye,ge]=a.useState({width:1280,height:720});a.useEffect(()=>{const A=()=>ge({width:window.innerWidth,height:window.innerHeight});return A(),window.addEventListener("resize",A),()=>window.removeEventListener("resize",A)},[]);const[Ne,We]=a.useState(0),[Ee,H]=a.useState({}),[he,pe]=a.useState(!1),[Ue,ft]=a.useState(!1),[bt,Re]=a.useState(!1),{totalHintsAvailable:Ge}=Nr(i||null),[Je,w]=a.useState(5),[Me,rt]=a.useState(15),Pe=Je+Ge,[Oe,gt]=a.useState(null),[lt,Xe]=a.useState(!1),[nt,it]=a.useState(900*1e3),[o,L]=a.useState([]),[v,$]=a.useState(0),[Z,ce]=a.useState(null),[le]=a.useState(()=>t.loadedQuestions&&t.loadedQuestions.length>0?t.loadedQuestions.map(zr):Array.from({length:t.questions},(A,_)=>({id:`q${_+1}`,question:Mr(t.subject,_),options:Ar(t.subject,_),correctAnswer:Er(t.subject,_),explanation:Pr(t.subject,_,t.difficulty)})));a.useEffect(()=>{H({}),L([]),w(5),rt(15),We(0),R(0),F(0),K(1)},[t.id]);const oe=le[r];a.useEffect(()=>{const A=parseInt(t.duration)||10;ze(A*60);const _=setInterval(()=>{ze(J=>J<=1?(clearInterval(_),y(),0):J-1)},1e3);return()=>clearInterval(_)},[]),a.useEffect(()=>{Me===0&&!Oe&&(gt(Date.now()),Xe(!0))},[Me,Oe]),a.useEffect(()=>{if(!lt||!Oe)return;const A=setInterval(()=>{const _=Date.now()-Oe,J=Math.max(0,900*1e3-_);it(J)},1e3);return()=>clearInterval(A)},[lt,Oe]);const[we,Be]=a.useState(Array.from({length:15},(A,_)=>({id:_,size:Math.random()*120+40,x:Math.random()*100,y:Math.random()*100,duration:Math.random()*20+15,delay:Math.random()*-20,color:["bg-purple-500/10","bg-blue-500/10","bg-cyan-500/10","bg-emerald-500/10"][Math.floor(Math.random()*4)]}))),fe=A=>{if(I)try{const _=window.AudioContext||window.webkitAudioContext;if(!_)return;const J=new _,G=J.currentTime,V=(De,He,Te,et=.1,Ae="sine")=>{const ke=J.createOscillator(),dt=J.createGain();ke.type=Ae,ke.frequency.value=De,dt.gain.setValueAtTime(0,He),dt.gain.linearRampToValueAtTime(et,He+.05),dt.gain.exponentialRampToValueAtTime(.001,He+Te),ke.connect(dt),dt.connect(J.destination),ke.start(He),ke.stop(He+Te)};A==="correct"?(V(880,G,.1,.1,"sine"),V(1108.73,G+.1,.2,.1,"sine")):A==="incorrect"?(V(300,G,.2,.05,"sawtooth"),V(250,G+.15,.3,.05,"sawtooth")):A==="combo"?(V(440,G,.1,.05,"square"),V(554.37,G+.1,.1,.05,"square"),V(659.25,G+.2,.1,.05,"square"),V(880,G+.3,.4,.05,"square")):A==="complete"&&(V(523.25,G,.1,.1),V(659.25,G+.15,.1,.1),V(783.99,G+.3,.1,.1),V(1046.5,G+.45,.5,.1))}catch{}},y=()=>{f(!0),se()},j=()=>{n?.(t,D),s()},Q=()=>{if(Je<=0||x)return;const A=Ee[r]||[],_=oe.options.filter(G=>G!==oe.correctAnswerText).filter(G=>!A.includes(G));if(_.length===0)return;const J=_[Math.floor(Math.random()*_.length)];H(G=>({...G,[r]:[...A,J]})),w(G=>Math.max(0,G-1)),fe("correct")},W=A=>{x||U||(h(A),setTimeout(()=>{re(A)},150))},re=A=>{const _=oe.questionType!=null&&oe.questionType!=="multiple_choice",J=A!==void 0?A:d;if(_){if(!S.trim())return}else if(J===null)return;const G=_?_r(S,oe.correctAnswerText||"",oe.questionType||""):J===oe.correctAnswer,V=_?S:String(J),De=Math.round((Date.now()-ue)/1e3);me(ke=>[...ke,{questionId:oe.id,answer:V,correct:G,timeSpent:De}]);const He=[...Y];if(He[r]=G?1:0,ee(He),p(G),N(!0),!G){ft(!0),fe("incorrect"),setTimeout(()=>ft(!1),500),rt(ke=>Math.max(0,ke-1)),F(0),K(1),setTimeout(()=>{je()},1500);return}fe("correct");const et=(Ee[r]||[]).length>0?5:10;We(ke=>ke+et),R(k+1);const Ae=P+1;F(Ae),Ae===2?ce("streak"):Ae===3&&X<2?ce("multiplier2"):Ae===5&&X<3&&ce("multiplier3"),Ae>0&&Ae%3===0&&fe("combo"),Ae>=5?K(3):Ae>=3?K(2):K(1),St(()=>import("./confetti.module-C94ZD2ww.js"),[]).then(ke=>{ke.default({particleCount:30,spread:40,colors:["#75D06A","#6ED1CF"],origin:{y:.6}})}),Re(!0),setTimeout(()=>{Re(!1),ce(null),setTimeout(()=>je(),300)},1500)},je=()=>{if(r{const A=Math.round(k/le.length*100);let _=t.xpReward;A>=90?_=Math.round(_*1.5):A>=80&&(_=Math.round(_*1.25));const J=parseInt(t.duration)*60;be>J*.5&&(_=Math.round(_*1.2)),_e(_);const G=J-be;i&&ga({lrn:i,quizId:t.id,subject:t.subject,score:A,totalQuestions:le.length,correctAnswers:k,timeSpentSeconds:G}).catch(V=>console.error("[WARN] Automation: quiz pipeline failed:",V)),t.source==="ai_generated"&&i?ya(i,t.id,t.generatedQuizId,t.subject,t.source,A,_,G,D,le.map(V=>({topic:V.topic||t.subject,difficulty:V.difficulty||"medium",bloomLevel:V.bloomLevel||"understand"}))).catch(V=>console.error("[WARN] Quiz result save failed:",V)):i&&Zs(i,t.id,t.subject,A,D.map(V=>({questionId:V.questionId,selectedAnswer:V.answer,isCorrect:V.correct})),G).catch(V=>console.error("[WARN] Practice quiz persist failed:",V)),i&&St(async()=>{const{saveAssessmentResult:V}=await import("./index-Bp7MiGcW.js").then(De=>De.ba);return{saveAssessmentResult:V}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11])).then(({saveAssessmentResult:V})=>{V({uid:i,testId:t.id,title:t.title||t.id,subject:t.subject||"General Mathematics",type:t.source==="ai_generated"?"quiz":"practice",score:A,totalQuestions:le.length,risk:A<60?"High":"Low",intervention:"",xpEarned:_,badgeUnlocked:""}).catch(De=>console.error("[WARN] Assessment record save failed:",De))}),fe("complete"),l?.(A,_)},U=v{document.fullscreenElement?(document.exitFullscreen().catch(()=>{}),ve(!1)):(document.documentElement.requestFullscreen().catch(()=>{}),ve(!0))};if(Ce){const A=Math.round(k/le.length*100),_=A>=80,J=A>=50&&A<80,G=A<50,V=document.getElementById("modal-root"),De=e.jsxs("div",{className:"fixed inset-0 z-[200] flex items-center justify-center p-4 bg-slate-900/50 backdrop-blur-sm",children:[e.jsx("style",{children:ws}),_&&e.jsx(Cr,{}),J&&e.jsx(Sr,{viewportHeight:ye.height,viewportWidth:ye.width}),G&&e.jsx(kr,{viewportHeight:ye.height}),e.jsxs(E.div,{initial:{opacity:0,scale:.8,y:40},animate:{opacity:1,scale:1,y:0},transition:{type:"spring",damping:18,stiffness:200},className:"w-full max-w-xs sm:max-w-sm bg-white border-2 border-slate-200 shadow-[0_25px_60px_rgba(0,0,0,0.15)] rounded-[2rem] p-4 sm:p-5 text-center relative z-10",children:[e.jsx(E.div,{initial:{scale:0,rotate:-180},animate:{scale:1,rotate:0},transition:{type:"spring",damping:12,stiffness:150,delay:.2},className:"mb-3",children:e.jsx("img",{src:"/mascot/modules_avatar.png",alt:"Mascot",className:"w-16 h-16 sm:w-20 sm:h-20 mx-auto drop-shadow-xl animate-mascot-float"})}),e.jsx(E.h2,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:.3},className:`text-xl sm:text-2xl font-black uppercase tracking-tight mb-1 drop-shadow-sm ${_?"text-emerald-500":J?"text-amber-500":"text-rose-500"}`,children:_?"EXCELLENT!":J?"GOOD JOB!":"KEEP TRYING!"}),e.jsxs("p",{className:"text-slate-400 font-bold text-[10px] mb-3 uppercase tracking-widest",children:["Quiz Complete • Score: ",k,"/",le.length]}),e.jsx(E.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.4},className:"bg-slate-50/50 rounded-xl p-3 mb-4 border border-slate-100 flex flex-col gap-2",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-slate-400 text-[9px] font-black uppercase tracking-widest text-left mb-1.5 ml-1",children:"Performance Details"}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(js,{value:k,label:"Correct Answers",delay:500,icon:e.jsx(Et,{className:"h-3 w-3 text-emerald-500"})}),e.jsx(js,{value:Le,label:"Total XP Earned",delay:800,icon:e.jsx(Ve,{className:"h-3 w-3 text-amber-500"})}),e.jsxs(E.div,{initial:{opacity:0},animate:{opacity:1},transition:{delay:1.2,duration:.4},className:"flex items-center justify-between pt-1.5 mt-1 border-t border-slate-100",children:[e.jsx("span",{className:"text-slate-400 text-[9px] font-black uppercase tracking-widest",children:"Final Accuracy"}),e.jsxs("span",{className:"text-lg font-black text-slate-800 tabular-nums",children:[A,"%"]})]})]})]})}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(qe,{size:"lg",onClick:()=>{u(0),$(0),h(null),m(""),R(0),F(0),K(1),ee([]),me([]),We(0),f(!1),N(!1),z(!1),Se(Date.now()),H({}),L([]),pe(!1),w(5),O(!1)},className:"w-full h-10 sm:h-11 rounded-2xl text-xs font-black bg-white hover:bg-slate-50 text-purple-600 border-2 border-purple-100",children:"RETAKE QUIZ"}),e.jsx(qe,{size:"lg",onClick:j,className:"w-full h-10 sm:h-11 rounded-2xl text-xs font-black bg-purple-600 hover:bg-purple-700 text-white shadow-lg shadow-purple-200",children:"FINISH"})]})]})]});return At.createPortal(De,V)}return e.jsxs(e.Fragment,{children:[e.jsx("style",{children:ws}),b&&At.createPortal(e.jsx(E.div,{initial:{opacity:0,x:20},animate:{opacity:1,x:0},exit:{opacity:0,x:20},className:"fixed right-6 top-1/2 -translate-y-1/2 z-[9999] w-64",children:e.jsxs("div",{className:"bg-white rounded-2xl p-3 border border-slate-200 shadow-[0_10px_40px_rgba(0,0,0,0.3)]",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2 px-1",children:[e.jsxs("h4",{className:"text-xs font-bold text-[#0a1628] flex items-center gap-2",children:[e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-purple-600",children:[e.jsx("rect",{x:"4",y:"2",width:"16",height:"20",rx:"2"}),e.jsx("line",{x1:"8",x2:"16",y1:"6",y2:"6"})]}),"Calculator"]}),e.jsx("button",{onClick:()=>T(!1),className:"w-6 h-6 rounded-full bg-slate-100 flex items-center justify-center text-slate-500 hover:text-slate-800 hover:bg-slate-200 transition-colors",children:e.jsx(Ye,{size:12})})]}),e.jsx(Rs,{isOpen:!0,onClose:()=>T(!1),inline:!0})]})}),document.getElementById("modal-root")),lt&&At.createPortal(e.jsx("div",{className:"fixed inset-0 z-[200] flex items-center justify-center p-4 bg-slate-900/50",children:e.jsxs(E.div,{initial:{scale:.9,opacity:0},animate:{scale:1,opacity:1},className:"bg-white rounded-[2rem] p-6 max-w-xs w-full text-center border-2 border-rose-200 shadow-[0_25px_60px_rgba(0,0,0,0.15)]",children:[e.jsx(E.div,{animate:{scale:[1,1.1,1]},transition:{duration:1,repeat:1/0},className:"text-6xl mb-4",children:e.jsx(tr,{className:"w-10 h-10 text-rose-500"})}),e.jsx("h2",{className:"text-2xl font-black text-slate-800 mb-3",children:"Out of Lives!"}),e.jsx("p",{className:"text-slate-500 text-sm mb-4",children:"Your hearts have run out. You can wait for them to refill or head back and review your lessons in the meantime."}),e.jsxs("div",{className:"flex items-center justify-center gap-2 mb-2 text-rose-500 font-bold",children:[e.jsx("img",{src:"/icons/quiz_heart.png",alt:"Hearts",className:"w-5 h-5"}),e.jsx("span",{children:"0 / 15 hearts"})]}),e.jsxs("p",{className:"text-slate-400 text-xs mb-4",children:["Next heart in: ",e.jsxs("span",{className:"font-bold text-slate-600",children:[Math.floor(nt/6e4),":",Math.floor(nt%6e4/1e3).toString().padStart(2,"0")]})," (15 minutes per heart)"]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(qe,{onClick:j,className:"w-full py-3 bg-rose-500 hover:bg-rose-600 text-white font-bold rounded-full",children:"Exit Quiz"}),e.jsx(qe,{onClick:()=>{Xe(!1)},className:"w-full py-3 bg-slate-100 hover:bg-slate-200 text-slate-700 font-bold rounded-full",children:"Review Lessons"})]})]})}),document.getElementById("modal-root")),e.jsx(Ze,{children:bt&&M&&e.jsx(E.div,{initial:{opacity:0,scale:.8,y:20},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:1.1,filter:"blur(10px)"},transition:{type:"spring",damping:20,stiffness:300},className:"fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 z-[200] pointer-events-none flex flex-col items-center justify-center",children:e.jsxs("div",{className:"bg-white/95 backdrop-blur-xl border border-slate-200 rounded-[2rem] p-6 md:p-8 shadow-[0_30px_80px_rgba(0,0,0,0.15)] flex flex-col items-center min-w-[280px] md:min-w-[320px]",children:[e.jsx("img",{src:"/mascot/modules_avatar.png",alt:"Mascot",className:"w-24 h-24 md:w-32 md:h-32 mb-4 drop-shadow-[0_10px_20px_rgba(0,0,0,0.15)]"}),e.jsx("h2",{className:"text-3xl md:text-4xl font-black mb-4 uppercase tracking-widest text-emerald-500",children:"Correct!"}),e.jsxs("div",{className:"flex flex-col items-center gap-3 w-full justify-center",children:[e.jsx("div",{className:"flex items-center gap-2 bg-emerald-500/20 text-emerald-400 px-4 py-2 rounded-full font-bold border border-emerald-500/30",children:e.jsxs("span",{children:["+ ",(Ee[r]||[]).length>0?5:10," XP"]})}),Z==="streak"&&e.jsxs("div",{className:"flex items-center gap-2 bg-orange-500/20 text-orange-400 px-4 py-1.5 rounded-full text-sm font-bold border border-orange-500/30",children:[e.jsx(Gt,{size:14})," Streak Started!"]}),Z==="multiplier2"&&e.jsxs("div",{className:"flex items-center gap-2 bg-amber-500/20 text-amber-400 px-4 py-1.5 rounded-full text-sm font-bold border border-amber-500/30",children:[e.jsx(Ve,{size:14})," Multiplier ×2!"]}),Z==="multiplier3"&&e.jsxs("div",{className:"flex items-center gap-2 bg-amber-500/20 text-amber-400 px-4 py-1.5 rounded-full text-sm font-bold border border-amber-500/30",children:[e.jsx(Ve,{size:14})," Multiplier ×3!"]})]})]})},"round-result")}),e.jsxs("div",{className:"fixed inset-0 z-[100] h-screen w-full flex flex-col bg-slate-50 overflow-hidden",children:[e.jsxs("header",{className:"relative shrink-0 flex flex-col items-center justify-start px-4 pt-4 sm:pt-6 pb-6 z-[60] shadow-md overflow-hidden bg-gradient-to-r from-purple-600 to-indigo-400 rounded-b-[32px] sm:rounded-b-[40px] min-h-[110px] sm:min-h-[130px]",children:[e.jsxs("div",{className:"absolute inset-0 z-0 pointer-events-none",children:[e.jsx("div",{className:"absolute top-0 left-0 w-64 h-64 bg-white opacity-10 rounded-full -translate-x-1/2 -translate-y-1/2 blur-2xl"}),e.jsx("div",{className:"absolute bottom-0 right-0 w-80 h-80 bg-white opacity-10 rounded-full translate-x-1/3 translate-y-1/3 blur-3xl"})]}),e.jsxs("div",{className:"w-full max-w-7xl flex items-center justify-between relative z-10 mb-3 sm:mb-4 md:mb-6",children:[e.jsx("div",{className:"flex-1 flex items-center gap-1 sm:gap-2",children:e.jsxs("div",{className:"flex items-center gap-1 bg-white/20 px-2 py-1 sm:px-3 sm:py-1.5 rounded-full text-white text-xs sm:text-sm font-bold",children:[e.jsx(pt,{size:14,className:"shrink-0"})," ",Tr(be)]})}),e.jsxs("div",{className:"relative flex items-center justify-center bg-purple-900/40 backdrop-blur-md px-2 sm:px-5 md:px-8 py-2 sm:py-3 rounded-full border border-white/10 gap-1.5 sm:gap-3 md:gap-4 shadow-inner",children:[e.jsx("div",{className:"hidden sm:block w-3 h-3 md:w-4 md:h-4 rounded-full bg-yellow-400 shrink-0 shadow-[0_0_10px_rgba(250,204,21,0.6)]"}),e.jsxs("div",{className:"flex flex-col items-start justify-center",children:[e.jsx("span",{className:"hidden sm:block text-[9px] md:text-[11px] font-black text-purple-200 uppercase tracking-widest leading-none mb-0.5",children:"Try It Yourself!"}),e.jsx("span",{className:"font-bold text-white tracking-wide text-xs sm:text-sm md:text-lg leading-none truncate max-w-[90px] sm:max-w-[180px] md:max-w-[300px]",children:t.title||t.subject})]})]}),e.jsxs("div",{className:"flex-1 flex justify-end gap-1 sm:gap-2 md:gap-3 relative pointer-events-auto",children:[e.jsxs("button",{onClick:()=>te(!I),className:"w-8 h-8 sm:w-10 sm:h-10 md:w-12 md:h-12 rounded-full bg-purple-900/20 text-white flex items-center justify-center hover:bg-purple-900/40 transition-colors shadow-sm border border-white/10",children:[I?e.jsx(Zt,{size:16,className:"sm:hidden"}):e.jsx(Jt,{size:16,className:"sm:hidden"}),I?e.jsx(Zt,{size:20,className:"hidden sm:block"}):e.jsx(Jt,{size:20,className:"hidden sm:block"})]}),e.jsx("button",{onClick:yt,className:"hidden sm:flex w-10 h-10 md:w-12 md:h-12 rounded-full bg-purple-900/20 text-white items-center justify-center hover:bg-purple-900/40 transition-colors shadow-sm border border-white/10",children:xe?e.jsx(Ds,{size:20}):e.jsx(Is,{size:20})}),e.jsxs("button",{onClick:()=>B(!0),className:"w-8 h-8 sm:w-10 sm:h-10 md:w-12 md:h-12 rounded-full bg-purple-900/20 text-white flex items-center justify-center hover:bg-purple-900/40 transition-colors shadow-sm border border-white/10",children:[e.jsx(Ye,{size:18,className:"sm:hidden"}),e.jsx(Ye,{size:20,className:"hidden sm:block"})]})]})]}),e.jsx("div",{className:"w-full max-w-[50rem] flex items-center justify-center px-4 z-10",children:e.jsx("div",{className:"w-full flex items-center gap-2 sm:gap-3",children:le.map((A,_)=>{let J=_<=r?"bg-white shadow-[0_0_8px_rgba(255,255,255,0.8)]":"bg-white/20";return e.jsx("div",{className:`h-1.5 sm:h-2 rounded-full flex-1 transition-all ${J}`},_)})})})]}),e.jsxs("div",{className:"w-full max-w-[54rem] mx-auto shrink-0 flex items-center justify-between px-2 sm:px-4 md:px-6 py-2 sm:py-3 z-[50] relative mt-4 sm:mt-6 md:mt-8",children:[e.jsxs("button",{onClick:()=>$(A=>Math.max(0,A-1)),disabled:v===0,className:`w-8 h-8 sm:w-10 sm:h-10 md:w-12 md:h-12 shrink-0 rounded-full flex items-center justify-center shadow-md border-2 transition-all ${v===0?"bg-slate-100 text-slate-400 border-slate-200 cursor-not-allowed":"bg-white text-purple-600 border-purple-100 hover:bg-purple-50 hover:border-purple-200 hover:scale-105 active:scale-95"}`,children:[e.jsx(ms,{size:18,className:"sm:hidden"}),e.jsx(ms,{size:24,className:"hidden sm:block"})]}),e.jsxs("div",{className:"flex items-center justify-center gap-1.5 sm:gap-3 md:gap-5 flex-1 mx-1 sm:mx-2",children:[e.jsxs("div",{className:"flex items-center gap-1 sm:gap-2 md:gap-3 px-2.5 sm:px-5 md:px-10 py-1.5 sm:py-2 rounded-full bg-white shadow-md border border-slate-200/60 text-rose-500 font-extrabold text-xs sm:text-sm md:text-base",children:[e.jsx("img",{src:"/icons/quiz_heart.png",alt:"Hearts",className:"w-4 h-4 sm:w-5 sm:h-5 object-contain"})," ",Me]}),e.jsxs("div",{className:"flex items-center gap-1 sm:gap-2 md:gap-3 px-2.5 sm:px-5 md:px-10 py-1.5 sm:py-2 rounded-full bg-white shadow-md border border-slate-200/60 text-yellow-500 font-extrabold text-xs sm:text-sm md:text-base",children:[e.jsx("img",{src:"/icons/quiz_key.png",alt:"Keys",className:"w-4 h-4 sm:w-5 sm:h-5 object-contain"})," ",Je]}),e.jsxs("div",{className:"flex items-center gap-1.5 sm:gap-3 md:gap-4 px-2 sm:px-3 py-1 sm:py-1.5 pl-2.5 sm:pl-4 md:pl-6 rounded-full bg-white shadow-md border border-slate-200/60",children:[e.jsxs("div",{className:"flex items-center gap-1 sm:gap-1.5 text-orange-500 font-extrabold text-xs sm:text-sm md:text-base",children:[e.jsx("img",{src:"/icons/quiz_streak.png",alt:"Streak",className:"w-4 h-4 sm:w-5 sm:h-5 object-contain"})," ",P]}),e.jsxs("div",{className:"bg-emerald-100 text-emerald-800 px-2 sm:px-3 md:px-4 py-1 sm:py-1.5 rounded-full font-bold text-xs sm:text-sm md:text-base shadow-inner border border-emerald-200/50 whitespace-nowrap",children:["+ ",Ne," pts"]})]})]}),e.jsxs("button",{onClick:()=>$(A=>Math.min(r,A+1)),disabled:v>=r,className:`w-8 h-8 sm:w-10 sm:h-10 md:w-12 md:h-12 shrink-0 rounded-full flex items-center justify-center shadow-md border-2 transition-all ${v>=r?"bg-slate-100 text-slate-400 border-slate-200 cursor-not-allowed":"bg-white text-purple-600 border-purple-100 hover:bg-purple-50 hover:border-purple-200 hover:scale-105 active:scale-95"}`,children:[e.jsx(xt,{size:18,className:"sm:hidden"}),e.jsx(xt,{size:24,className:"hidden sm:block"})]})]}),e.jsx("main",{className:"flex-1 overflow-y-auto w-full px-4 sm:px-6 pt-0 pb-6 flex flex-col items-center relative z-10",children:e.jsxs(E.div,{initial:{opacity:0,x:20},animate:Ue?{x:[-10,10,-10,10,0],scale:[1,1.01,1],opacity:1}:{opacity:1,x:0},className:"w-full max-w-3xl flex flex-col mt-2",children:[e.jsxs("div",{className:"bg-white rounded-3xl shadow-lg border-t-[6px] border-purple-500 p-4 sm:p-6 md:p-8 text-center flex flex-col items-center mb-4 sm:mb-6 w-full relative overflow-hidden",children:[e.jsxs("div",{className:"bg-slate-100 text-slate-600 px-3 sm:px-4 py-1 sm:py-1.5 rounded-full text-[10px] sm:text-[11px] md:text-xs font-black uppercase tracking-widest mb-3 sm:mb-4 flex items-center shadow-sm",children:["Q",v+1," of ",le.length]}),e.jsx("h2",{className:"text-base sm:text-xl md:text-2xl font-extrabold text-[#0a1628] leading-tight w-full",children:ne.question.includes("___")?e.jsx("span",{children:ne.question.split("___").map((A,_,J)=>e.jsxs(Ie.Fragment,{children:[A,_m(G.target.value),onKeyDown:G=>{G.key==="Enter"&&!x&&re()},className:`inline-block w-24 mx-2 border-b-4 outline-none text-center bg-transparent font-bold ${U?"border-slate-300 text-slate-500":"border-[#7C3AED] text-[#7C3AED] focus:border-[#75D06A]"}`})]},_))}):e.jsx(Ft,{children:ne.question})})]}),e.jsxs("div",{className:"w-full flex flex-col items-center",children:[ne.questionType==="multiple_choice"||!ne.questionType?e.jsx("div",{className:"w-full grid grid-cols-1 sm:grid-cols-2 gap-2.5 sm:gap-3 md:gap-5",children:(ne.options||[]).map((A,_)=>{const J=Ee[r]||[],G=J.includes(A),V=J.length,De=(ne.options||[]).length-1,He=De>0&&V>=De;let Te="bg-white hover:bg-slate-50 border-transparent text-slate-700 hover:border-slate-200",et=!1;if(He){et=!0;const Ae=ne.options?.[ne.correctAnswer];A===Ae?Te="bg-emerald-50 border-emerald-400 text-emerald-800":D[v]?.answer===String(_)?Te="bg-rose-50 border-rose-400 text-rose-800 opacity-80":Te="bg-slate-100 border-slate-200 text-slate-400 opacity-40 line-through"}else if(G)Te="bg-slate-100 border-slate-200 text-slate-400 opacity-40 line-through cursor-not-allowed";else if(U){const Ae=_===ne.correctAnswer,ke=v===r&&(d===_||ae===_)||v{et||U||G||W(_)},className:`p-3 sm:p-4 md:p-5 rounded-2xl shadow-sm border-[3px] font-extrabold text-sm sm:text-base md:text-lg text-left transition-all flex items-center justify-between ${Te} ${et||U||G?"cursor-default":"hover:shadow-md hover:-translate-y-0.5 active:translate-y-0"}`,children:[e.jsx("span",{className:"truncate pr-4",children:e.jsx(Ft,{children:A})}),G&&e.jsx(Ot,{size:20,className:"text-slate-400 shrink-0"}),U&&_===ne.correctAnswer&&e.jsx(st,{size:22,className:"text-emerald-500 shrink-0"}),U&&d===_&&_!==ne.correctAnswer&&e.jsx(Ot,{size:22,className:"text-rose-500 shrink-0"})]},_)})}):e.jsx("div",{className:"w-full max-w-2xl mx-auto flex flex-col gap-4",children:!ne.question.includes("___")&&e.jsx("input",{type:"text",disabled:U,value:v===r?S:"",onChange:A=>m(A.target.value),onKeyDown:A=>{A.key==="Enter"&&!x&&re()},placeholder:"Type your answer here...",className:`w-full p-3 sm:p-4 md:p-5 rounded-2xl border-[3px] font-extrabold text-base sm:text-lg text-center outline-none transition-colors ${U?M?"border-emerald-400 text-emerald-700 bg-emerald-50":"border-rose-400 text-rose-700 bg-rose-50":"border-slate-200 focus:border-[#7C3AED] bg-white text-slate-800"}`})}),U&&g&&e.jsxs("div",{className:"w-full max-w-3xl mt-6 flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-bold text-[#0a1628]",children:ne.topic||t?.subject||"General Math"}),e.jsxs("p",{className:"text-sm text-slate-500",children:["Question ",v+1," Explanation"]})]}),e.jsx("img",{src:"/icons/default-module-avatar.png",alt:"Module Avatar",className:"w-12 h-12 rounded-full object-cover border-2 border-slate-200"})]}),U&&g&&e.jsx(E.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:"w-full mt-4 space-y-4 max-w-3xl",children:e.jsxs("div",{className:`border-2 rounded-2xl p-5 flex items-start gap-4 ${(v===r?M:D[v]?.correct)?"bg-emerald-50 border-emerald-200":"bg-rose-50 border-rose-200"}`,children:[(v===r?M:D[v]?.correct)?e.jsx(st,{size:28,className:"text-emerald-500 shrink-0 mt-0.5"}):e.jsx(Ot,{size:28,className:"text-rose-500 shrink-0 mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{className:`font-extrabold text-lg mb-1 ${(v===r?M:D[v]?.correct)?"text-emerald-700":"text-rose-700"}`,children:(v===r?M:D[v]?.correct)?"Correct!":"Incorrect"}),e.jsx("p",{className:`text-base leading-relaxed ${(v===r?M:D[v]?.correct)?"text-emerald-800":"text-rose-800"}`,children:ne.explanation||`Correct Answer: ${ne.correctAnswerText||ne.options?.[ne.correctAnswer]}`})]})]})})]})]},v)}),e.jsx("footer",{className:"shrink-0 relative z-[60] flex flex-col items-center justify-center p-4 sm:p-6 bg-gradient-to-r from-purple-600 to-indigo-400 rounded-t-[32px] sm:rounded-t-[40px] shadow-[0_-10px_40px_rgba(0,0,0,0.15)]",children:(()=>{const A=(Ee[r]||[]).length,_=(oe.options||[]).length-1,J=_>0&&A>=_;return J||U&&!M?e.jsxs("button",{onClick:je,className:"bg-orange-500 hover:bg-orange-600 text-white font-extrabold text-sm sm:text-base md:text-lg px-5 sm:px-8 py-3 sm:py-4 rounded-full flex items-center justify-center gap-2 sm:gap-3 shadow-xl hover:scale-[1.02] active:scale-[0.98] transition-all w-full max-w-md mx-auto",children:[r{const V=Pe>0&&!x&&!J;return e.jsxs("button",{onClick:Q,disabled:!V,className:"bg-white hover:bg-slate-50 disabled:opacity-70 disabled:cursor-not-allowed text-slate-700 font-bold px-4 sm:px-6 md:px-8 py-2.5 sm:py-3 md:py-3.5 rounded-full flex items-center gap-1.5 sm:gap-2 text-sm sm:text-base shadow-lg transition-transform hover:scale-105 active:scale-95 border border-slate-200",children:[e.jsx("img",{src:"/icons/quiz_key.png",alt:"Key",className:"w-4 h-4 sm:w-5 sm:h-5 object-contain"})," Hint"]})})(),U&&e.jsxs("button",{onClick:()=>z(!0),className:"bg-white hover:bg-slate-50 text-slate-700 font-bold px-4 sm:px-6 md:px-8 py-2.5 sm:py-3 md:py-3.5 rounded-full flex items-center gap-1.5 sm:gap-2 text-sm sm:text-base shadow-lg transition-transform hover:scale-105 active:scale-95 border border-slate-200",children:[e.jsx($e,{size:16,className:"sm:hidden"}),e.jsx($e,{size:20,className:"hidden sm:block"})," Explain"]}),e.jsx("button",{onClick:()=>T(V=>!V),className:`w-11 h-11 sm:w-12 sm:h-12 rounded-full flex items-center justify-center shadow-lg transition-transform hover:scale-105 active:scale-95 border border-slate-200 ${b?"bg-purple-100 text-purple-600 border-purple-300":"bg-white hover:bg-slate-50 text-slate-700"}`,children:e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"4",y:"2",width:"16",height:"20",rx:"2"}),e.jsx("line",{x1:"8",x2:"16",y1:"6",y2:"6"}),e.jsx("path",{d:"M16 10h.01"}),e.jsx("path",{d:"M12 10h.01"}),e.jsx("path",{d:"M8 10h.01"}),e.jsx("path",{d:"M12 14h.01"}),e.jsx("path",{d:"M8 14h.01"}),e.jsx("path",{d:"M12 18h.01"}),e.jsx("path",{d:"M8 18h.01"}),e.jsx("line",{x1:"16",x2:"16",y1:"14",y2:"18"})]})})]}):v$(r),className:"bg-white text-slate-700 font-extrabold text-sm sm:text-base md:text-lg px-4 sm:px-6 md:px-8 py-2.5 sm:py-3 md:py-4 rounded-full inline-flex items-center gap-1.5 sm:gap-2 md:gap-3 shadow-lg hover:bg-slate-50 transition-transform hover:scale-105 active:scale-95 border border-slate-200",children:[e.jsx(xt,{size:16,className:"sm:hidden"}),e.jsx(xt,{size:20,className:"hidden sm:block"}),"Back to Current Question"]}):null})()})]}),C&&e.jsx("div",{className:"fixed inset-0 z-[300] flex items-center justify-center p-4 bg-black/50 backdrop-blur-sm",children:e.jsxs(E.div,{initial:{scale:.9,opacity:0},animate:{scale:1,opacity:1},className:"bg-white rounded-2xl p-6 w-full max-w-[320px] shadow-2xl border border-slate-200 flex flex-col items-center gap-4",children:[e.jsx("h3",{className:"text-lg font-bold text-slate-900 text-center",children:"Leave this quiz?"}),e.jsx("p",{className:"text-sm text-slate-500 text-center",children:"Your progress will be reset and you'll need to start over."}),e.jsxs("div",{className:"w-full flex flex-col gap-2",children:[e.jsx("button",{onClick:()=>B(!1),className:"w-full py-3 bg-[#9956DE] hover:bg-[#8544c7] text-white font-bold rounded-full transition-colors",children:"Stay"}),e.jsx("button",{onClick:()=>{B(!1),s()},className:"w-full py-3 bg-slate-100 hover:bg-slate-200 text-slate-700 font-bold rounded-full transition-colors",children:"Leave Quiz"})]})]})})]})};function Mr(t,s){const l={"Pre-Calculus":["What is the domain of the function f(x) = √(x - 2)?","Solve for x: 2^x = 16","What is the period of the function y = sin(2x)?","Find the inverse of f(x) = 3x + 5","What is the value of log₂(32)?","Simplify: (x² - 9) / (x - 3)","What is the range of f(x) = |x| - 3?","If f(x) = 2x + 1 and g(x) = x², find f(g(2)).","What is the amplitude of y = 3cos(x)?","Solve: log₃(x) = 4"],"General Mathematics":["Simplify: (2x + 3)(x - 4)","What is 15% of 240?","Solve: 3x + 7 = 22","What is the value of 5! (5 factorial)?","Convert 0.75 to a fraction","What is 25% of 360?","Simplify: 12/18","What is the GCD of 24 and 36?","Convert 3/8 to a decimal","If a shirt costs $40 and is 20% off, what is the sale price?","What is 2/3 + 1/4?","Calculate: 15% tip on a $80 bill","Simplify: 45/60","What fraction is equivalent to 0.125?","If 30% of a number is 45, what is the number?"],"Statistics and Probability":["What is the probability of rolling a 6 on a fair die?","Calculate the mean of: 4, 7, 9, 12, 15","What is the median of: 2, 5, 8, 11, 14?","In a bag with 5 red and 3 blue balls, what is P(red)?","What is the range of: 10, 15, 20, 25, 30?","What is the mode of: 3, 5, 5, 7, 8, 5, 9?","What is the standard deviation concept?","P(A) = 0.3, P(B) = 0.5, events independent. P(A and B) = ?","What is the median of: 4, 7, 10, 13?","How many ways can you arrange 3 books?"],"Basic Calculus":["Find the derivative of f(x) = 3x²","What is the limit of (x² - 4)/(x - 2) as x → 2?","Integrate: ∫ 2x dx","Find f'(x) if f(x) = 5x³ - 2x","What is the derivative of sin(x)?","Find the derivative of f(x) = eˣ + 3x","What is ∫ cos(x) dx?","Find the derivative of f(x) = ln(x)","What is the limit of 1/x as x → ∞?","Find f'(x) if f(x) = x⁴ - 2x² + 1"]},n=qt(t),i=l[n]||l["General Mathematics"];return i[s%i.length]}function qt(t){const s=t.toLowerCase();return s.includes("pre-calc")||s.includes("pre calc")||s.includes("precalc")?"Pre-Calculus":s.includes("statistic")||s.includes("probability")?"Statistics and Probability":s.includes("calculus")&&!s.includes("pre")?"Basic Calculus":s.includes("general")||s.includes("math")||s.includes("algebra")||s.includes("fraction")||s.includes("percent")||s.includes("ratio")||s.includes("geometry")?"General Mathematics":s.includes("derivative")||s.includes("integral")||s.includes("limit")?"Basic Calculus":s.includes("trig")||s.includes("function")||s.includes("log")?"Pre-Calculus":s.includes("mean")||s.includes("median")||s.includes("data")?"Statistics and Probability":"General Mathematics"}function Ar(t,s){const l={"Pre-Calculus":[["x ≥ 2","x ≤ 2","x ≥ 0","All real numbers"],["x = 2","x = 4","x = 8","x = 16"],["π","2π","π/2","4π"],["f⁻¹(x) = (x - 5)/3","f⁻¹(x) = 3x - 5","f⁻¹(x) = x/3 - 5","f⁻¹(x) = (x + 5)/3"],["4","5","6","7"],["x + 3","x - 3","x² + 3","(x + 3)(x - 3)"],["y ≥ -3","y ≥ 0","All real numbers","y > -3"],["9","5","7","3"],["1","2","3","1/3"],["12","27","64","81"]],"General Mathematics":[["2x² - 5x - 12","2x² + 5x - 12","2x² - 8x + 12","2x² - 5x + 12"],["36","32","28","24"],["x = 5","x = 4","x = 6","x = 7"],["120","24","60","720"],["3/4","1/2","2/3","4/5"],["90","80","100","72"],["2/3","3/4","4/6","6/9"],["12","6","8","4"],["0.375","0.38","0.35","0.325"],["$32","$28","$30","$36"],["11/12","3/7","5/6","2/3"],["$12","$10","$15","$8"],["3/4","2/3","4/5","9/12"],["1/8","1/4","1/5","1/6"],["150","135","120","160"]],"Statistics and Probability":[["1/6","1/3","1/2","2/3"],["9.4","8.5","10.2","7.8"],["8","9","7","10"],["5/8","3/8","1/2","2/5"],["20","15","25","30"],["5","3","7","8"],["Spread of data from the mean","The highest value","The average","The middle value"],["0.15","0.8","0.35","0.2"],["8.5","7","10","9"],["6","3","9","12"]],"Basic Calculus":[["6x","3x","9x²","6x²"],["4","2","0","undefined"],["x² + C","2x² + C","x²/2 + C","2x + C"],["15x² - 2","15x² - 2x","5x² - 2","15x - 2"],["cos(x)","-cos(x)","tan(x)","-sin(x)"],["eˣ + 3","eˣ + 3x","xeˣ + 3","eˣ"],["sin(x) + C","-sin(x) + C","tan(x) + C","-cos(x) + C"],["1/x","x","ln(x)","-1/x²"],["0","1","∞","undefined"],["4x³ - 4x","4x³ - 2x","x³ - 4x","4x⁴ - 4x²"]]},n=qt(t),i=l[n]||l["General Mathematics"];return i[s%i.length]}function Er(t,s){const l={"Pre-Calculus":[0,1,0,0,1,0,0,0,2,3],"General Mathematics":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"Statistics and Probability":[0,0,0,0,0,0,0,0,0,0],"Basic Calculus":[0,0,0,0,0,0,0,0,0,0]},n=qt(t),i=l[n]||l["General Mathematics"];return i[s%i.length]}function Pr(t,s,l){const n={"Pre-Calculus":["The expression under the square root must be non-negative: x - 2 ≥ 0, so x ≥ 2.","Since 2⁴ = 16, we get x = 4.","The period of sin(kx) is 2π/k. Here k = 2, so period = 2π/2 = π.","To find the inverse: y = 3x + 5 → x = 3y + 5 → y = (x - 5)/3.","Since 2⁵ = 32, log₂(32) = 5.","(x² - 9)/(x - 3) = (x+3)(x-3)/(x-3) = x + 3 (for x ≠ 3).","The absolute value |x| ≥ 0 for all x, so |x| - 3 ≥ -3. The range is y ≥ -3.","g(2) = 4, then f(4) = 2(4) + 1 = 9.","The amplitude of y = Acos(x) is |A|. Here A = 3, so amplitude = 3.","log₃(x) = 4 means 3⁴ = x, so x = 81."],"General Mathematics":["(2x + 3)(x - 4) = 2x² - 8x + 3x - 12 = 2x² - 5x - 12","15% of 240 = 0.15 × 240 = 36","3x + 7 = 22 → 3x = 15 → x = 5","5! = 5 × 4 × 3 × 2 × 1 = 120","0.75 = 75/100 = 3/4 after simplifying by dividing both by 25","25% of 360 = 0.25 × 360 = 90","12/18 = (12÷6)/(18÷6) = 2/3","Factors of 24: {1,2,3,4,6,8,12,24}. Factors of 36: {1,2,3,4,6,9,12,18,36}. GCD = 12","3 ÷ 8 = 0.375","20% off $40 = $40 × 0.80 = $32","2/3 + 1/4 = 8/12 + 3/12 = 11/12","15% of $80 = 0.15 × 80 = $12","45/60 = (45÷15)/(60÷15) = 3/4","0.125 = 125/1000 = 1/8","30% × N = 45 → N = 45/0.30 = 150"],"Statistics and Probability":["A fair die has 6 outcomes, each equally likely. P(6) = 1/6.","Mean = (4 + 7 + 9 + 12 + 15) / 5 = 47/5 = 9.4","Sorted: 2, 5, 8, 11, 14. The middle value is 8.","P(red) = 5/(5+3) = 5/8","Range = max - min = 30 - 10 = 20","The value 5 appears 3 times, more than any other value. Mode = 5.","Standard deviation measures how spread out data points are from the mean.","For independent events: P(A and B) = P(A) × P(B) = 0.3 × 0.5 = 0.15","For even-count dataset {4,7,10,13}: median = (7+10)/2 = 8.5","3 books can be arranged in 3! = 3 × 2 × 1 = 6 ways."],"Basic Calculus":["Using the power rule: d/dx[3x²] = 3 × 2x = 6x","Factor: (x²-4)/(x-2) = (x+2)(x-2)/(x-2) = x+2. As x→2: 2+2 = 4","∫ 2x dx = 2 × x²/2 + C = x² + C","f'(x) = 5 × 3x² - 2 = 15x² - 2","The derivative of sin(x) is cos(x). This is a fundamental trigonometric derivative.","d/dx[eˣ + 3x] = eˣ + 3. The derivative of eˣ is eˣ and of 3x is 3.","∫ cos(x) dx = sin(x) + C. Integration is the reverse of differentiation.","The derivative of ln(x) is 1/x. This is a fundamental logarithmic derivative.","As x → ∞, 1/x approaches 0. The function gets infinitely close to zero.","f'(x) = 4x³ - 4x using the power rule on each term."]},i=qt(t),c=n[i]||n["General Mathematics"];return c[s%c.length]}function Tr(t){const s=Math.floor(t/60),l=t%60;return`${s}:${l.toString().padStart(2,"0")}`}async function Qt(t){return at("/api/try-it-yourself/resolve-question",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}async function Lr(t){return at("/api/try-it-yourself/use-hint",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}async function Rr(t){return at("/api/try-it-yourself/complete-session",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}async function Dr(t){return at("/api/try-it-yourself/shadow-retry",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}const Ir=["foundation","application","complexity","gauntlet"],Fr={0:1,1:.7,2:.4,3:.2},$r=10,qr=2,Or=2,Br=1,Hr=3;function Qr(t,s){const l=Fr[Math.min(t,3)]??.2;return Math.max(Math.round($r*l),qr)}function Wr(t){const s=t.length,l=4;if(t.filter(p=>p.bloomLevel).length0&&N.push(z)}return N}const i=t.filter(p=>p.bloomLevel==="remember"||p.bloomLevel==="understand"),c=t.filter(p=>p.bloomLevel==="apply"),r=t.filter(p=>p.bloomLevel==="analyze"),u=t.filter(p=>p.bloomLevel==="evaluate"),d=t.filter(p=>!p.bloomLevel),h=[],S=[...i,...d];S.length>0&&h.push(S),c.length>0&&h.push(c),r.length>0&&h.push(r),u.length>0&&h.push(u);const m=[];let M=[];for(const p of h)M=[...M,...p],M.length>=l&&(m.push(M),M=[]);return M.length>0&&(m.length>0?m[m.length-1]=[...m[m.length-1],...M]:m.push(M)),m.length>0?m:[t]}function Ns(t){return t==="multiple-choice"?Or:t==="fill-in-blank"?Br:null}function Ur(t){const s=t.toLowerCase();return s.includes("geometry")||s.includes("shape")?[It,Tt,Dt,fs,$s,cr]:s.includes("algebra")||s.includes("equation")?[Ye,kt,bs,Ht,ut,Lt]:s.includes("calculus")||s.includes("derivative")||s.includes("integral")?[Rt,Ht,Pt,ut,kt,bs]:s.includes("statistics")||s.includes("probability")?[Qe,Pt,fs,Tt,It,Dt]:[ut,Rt,kt,Lt,Ht,Da]}let wt=null;function Gr(){if(wt&&wt.state!=="closed")return wt;const t=window.AudioContext||window.webkitAudioContext;return t?(wt=new t,wt):null}function jt(t,s){if(s)try{const l=Gr();if(!l)return;l.state==="suspended"&&l.resume();const n=l.currentTime,i=(c,r,u,d=.1,h="sine")=>{const S=l.createOscillator(),m=l.createGain();S.type=h,S.frequency.value=c,m.gain.setValueAtTime(0,r),m.gain.linearRampToValueAtTime(d,r+.05),m.gain.exponentialRampToValueAtTime(.001,r+u),S.connect(m),m.connect(l.destination),S.start(r),S.stop(r+u)};switch(t){case"correct":i(880,n,.1),i(1108.73,n+.1,.2);break;case"incorrect":i(300,n,.2,.05,"sawtooth"),i(250,n+.15,.3,.05,"sawtooth");break;case"streak":i(440,n,.1,.05,"square"),i(554.37,n+.1,.1,.05,"square"),i(659.25,n+.2,.1,.05,"square"),i(880,n+.3,.4,.05,"square");break;case"complete":i(523.25,n,.1),i(659.25,n+.15,.1),i(783.99,n+.3,.1),i(1046.5,n+.45,.5);break;case"hint":i(600,n,.15,.06,"triangle");break}}catch{}}const vt=({label:t,value:s,prefix:l="",suffix:n="",icon:i,delay:c=0,large:r})=>{const[u,d]=Ie.useState(0);return Ie.useEffect(()=>{if(s<=0){d(s);return}const h=setTimeout(()=>{const M=Math.floor(40);let p=0;const x=setInterval(()=>{p+=Math.max(1,Math.floor(s/20)),p>=s?(d(s),clearInterval(x)):d(p)},M)},c);return()=>clearTimeout(h)},[s,c]),e.jsxs(E.div,{initial:{opacity:0,x:-20},animate:{opacity:1,x:0},transition:{delay:c/1e3,duration:.4},className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-slate-500 text-xs font-bold uppercase tracking-wider flex items-center gap-2",children:[i," ",t]}),e.jsxs("span",{className:`font-black tabular-nums ${r?"text-2xl text-purple-600":"text-lg text-slate-800"}`,children:[l,u,n]})]})},Xr=({questions:t,lessonTitle:s,subject:l,sessionId:n,userId:i,onComplete:c,onBack:r})=>{const u=a.useMemo(()=>Wr(t),[t]),d=u.length,[h,S]=a.useState(0),[m,M]=a.useState(()=>[...u[0]]),[p,x]=a.useState(0),[N,g]=a.useState("playing"),[z,k]=a.useState({}),[R,P]=a.useState(null),[F,X]=a.useState(""),[K,Y]=a.useState([]),[ee,D]=a.useState(!1),[me,ue]=a.useState(!1),[Se,Ce]=a.useState(!1),[f,q]=a.useState(!1),[O,ae]=a.useState(!1),[ie,be]=a.useState(!1),[ze,Le]=a.useState(!1),[_e,b]=a.useState(!1),[T,C]=a.useState(!0),[B,I]=a.useState(!1),[te,xe]=a.useState(!1),[ve,ye]=a.useState(0),[ge,Ne]=a.useState(0),[We,Ee]=a.useState(0),[H,he]=a.useState(15),[pe,Ue]=a.useState(5),[ft,bt]=a.useState([]),[Re,Ge]=a.useState(null);a.useRef(Date.now());const Je=a.useRef(null),w=m[p]||null,Me=a.useMemo(()=>Ur(s),[s]),rt={gradient:"bg-gradient-to-br from-[#7274ED] via-[#9956DE] to-[#7274ED]"},Pe=a.useCallback(y=>z[y]||{attempts:0,hintsUsed:0,resolved:!1,resolution:null,failedOptions:[],xpAwarded:0},[z]);a.useEffect(()=>{if(w){if(w.type==="multiple-choice"&&w.options){const y=w.options.map((j,Q)=>({id:`${w.id}-${Q}`,text:j}));for(let j=y.length-1;j>0;j--){const Q=Math.floor(Math.random()*(j+1));[y[j],y[Q]]=[y[Q],y[j]]}Y(y)}else Y([]);P(null),X(""),D(!1),ue(!1),be(!1),w.type==="fill-in-blank"&&setTimeout(()=>Je.current?.focus(),100)}},[w?.id]);const Oe=()=>{document.fullscreenElement?(document.exitFullscreen().catch(()=>{}),I(!1)):(document.documentElement.requestFullscreen().catch(()=>{}),I(!0))},gt=a.useCallback(()=>{if(!w)return;const y=Pe(w.id);if(y.resolved||y.hintsUsed>=(w.hints?.length||0)||pe<=0)return;jt("hint",T),D(!0),Ue(Q=>Q-1);const j=y.hintsUsed+1;k(Q=>({...Q,[w.id]:{...y,hintsUsed:j}})),i&&Lr({userId:i,sessionId:n,questionId:String(w.id),currentHintTier:y.hintsUsed}).catch(()=>{})},[w,z,i,n,T,pe,Pe]),lt=a.useCallback(()=>{if(!w)return;const y=Pe(w.id);if(y.resolved)return;const j=Ns(w.type);j===null||y.attempts({...Q,[w.id]:{...y,resolved:!0,resolution:"revealed",xpAwarded:0}})),Ne(0),i&&Qt({userId:i,sessionId:n,questionId:String(w.id),resolution:"revealed",attempts:y.attempts,hintsUsed:y.hintsUsed}).catch(()=>{}))},[w,z,i,n,Pe]),Xe=a.useCallback(y=>{if(!w||_e)return;const j=Pe(w.id);if(j.resolved)return;let Q="";if(w.type==="fill-in-blank"){if(Q=F.trim(),!Q)return}else if(Q=y||"",!Q)return;b(!0);const W=j.attempts+1;let re=!1;if(w.type==="fill-in-blank"?re=Q.toLowerCase().replace(/\s+/g,"")===w.correctAnswer.toLowerCase().replace(/\s+/g,""):re=Q===w.correctAnswer,re){const je=Qr(j.hintsUsed);k(U=>({...U,[w.id]:{...j,attempts:W,resolved:!0,resolution:"correct",xpAwarded:je}})),ye(U=>U+je);const se=ge+1;Ne(se),Ee(U=>Math.max(U,se)),jt(se>=3?"streak":"correct",T),Le(!0),be(!0),St(()=>import("./confetti.module-C94ZD2ww.js"),[]).then(U=>{U.default({particleCount:30,spread:40,colors:["#75D06A","#6ED1CF"],origin:{y:.6}})}).catch(()=>{}),i&&Qt({userId:i,sessionId:n,questionId:String(w.id),resolution:"correct",attempts:W,hintsUsed:j.hintsUsed}).catch(()=>{}),setTimeout(()=>{be(!1),b(!1)},1400)}else{const je=[...j.failedOptions,Q],se={...j,attempts:W,failedOptions:je};let U=!1;if(w.type==="multiple-choice"&&w.options?U=w.options.filter(yt=>yt!==w.correctAnswer).every(yt=>je.includes(yt)):w.type==="true-false"&&(U=!0),U){k(ne=>({...ne,[w.id]:{...se,resolved:!0,resolution:"revealed",xpAwarded:0}})),Ne(0),he(ne=>Math.max(0,ne-1)),jt("incorrect",T),b(!1),i&&Qt({userId:i,sessionId:n,questionId:String(w.id),resolution:"revealed",attempts:W,hintsUsed:j.hintsUsed}).catch(()=>{});return}k(ne=>({...ne,[w.id]:se})),Ne(0),he(ne=>Math.max(0,ne-1)),jt("incorrect",T),ae(!0),setTimeout(()=>ae(!1),500),w.type==="fill-in-blank"&&X(""),b(!1)}},[w,z,F,_e,ge,i,n,T,Pe]),nt=a.useRef(()=>{}),it=a.useCallback(()=>{const y=p+1;if(m.slice(y).filter(Q=>!z[Q.id]?.resolved).length===0){const Q=m.filter(W=>!z[W.id]?.resolved);Q.length>0?(M(Q),x(0)):nt.current()}else x(y)},[p,m,z]),o=a.useCallback(()=>{const y=u[h]||[];let j=0,Q=0,W=0;const re=[];y.forEach(se=>{const U=z[se.id];U&&(j+=U.xpAwarded,U.resolution==="correct"&&Q++,U.resolution==="revealed"&&W++,U.attempts>=Hr&&re.push(se.topic||se.competencyCode||s))});const je={phase:Ir[h],questionsCorrect:Q,questionsRevealed:W,xpEarned:j,struggleTopics:[...new Set(re)]};Ge(je),bt(se=>[...se,je]),h>=d-1?(g("complete"),jt("complete",T)):(g("phase-complete"),xe(!1))},[h,d,u,z,s,T]);nt.current=o;const L=a.useCallback(async()=>{const y=h+1;if(y>=d){g("complete");return}g("loading-next");const Q=(u[h]||[]).filter(se=>z[se.id]?.resolution==="revealed");let W=[...u[y],...Q];const re=Re?.struggleTopics||[];if(re.length>0&&i)try{const se=await Dr({userId:i,sessionId:n,struggleTopics:re,subject:l,count:Math.min(2,re.length)});se.variants?.length&&(W=[...W,...se.variants.map(U=>({id:U.id,type:U.type,question:U.question,options:U.options,correctAnswer:U.correctAnswer,explanation:U.explanation||"",hints:U.hints||[]}))])}catch{}S(y),M(W),x(0);const je={...z};Q.forEach(se=>{delete je[se.id]}),k(je),g("playing")},[h,d,u,Re,z,i,n,l]),v=a.useCallback(async()=>{const y=t.map(W=>{const re=z[W.id];return{questionId:String(W.id),resolution:re?.resolution||"correct",attempts:re?.attempts||1,hintsUsed:re?.hintsUsed||0,topic:s}});let j=ve;if(i)try{j=(await Rr({userId:i,sessionId:n,questionResults:y})).totalXP}catch{}const Q=Object.values(z).filter(W=>W.resolution==="correct").length;c(Math.round(Q/t.length*100),j)},[t,z,ve,i,n,s,c]);if(a.useEffect(()=>{const y=j=>{j.key==="Enter"&&w?.type==="fill-in-blank"&&F.trim()&&(j.preventDefault(),Xe())};return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[Xe,w,F]),a.useEffect(()=>{(N==="phase-complete"||N==="complete")&&!te&&(xe(!0),St(()=>import("./confetti.module-C94ZD2ww.js"),[]).then(y=>{y.default({particleCount:100,spread:80,colors:["#9956DE","#75D06A","#6ED1CF","#FFD700","#FF6B6B"],origin:{y:.35}}),setTimeout(()=>y.default({particleCount:60,spread:100,colors:["#9956DE","#75D06A","#FFD700"],origin:{y:.5,x:.3}}),300),setTimeout(()=>y.default({particleCount:60,spread:100,colors:["#6ED1CF","#FF6B6B","#FFD700"],origin:{y:.5,x:.7}}),600)}).catch(()=>{}))},[N,te]),N==="phase-complete"&&Re)return e.jsxs("div",{className:"fixed inset-0 z-[200] flex flex-col items-center justify-center bg-gradient-to-br from-[#e8e0f7] via-[#f0e8ff] to-[#ddd6f3] p-6",children:[e.jsxs("div",{className:"absolute inset-0 pointer-events-none overflow-hidden",children:[[It,Tt,Dt,kt,Lt,Rt].map((y,j)=>e.jsx(E.div,{className:"absolute text-purple-300/30",style:{top:`${10+j*14%80}%`,left:`${5+j*18%85}%`},animate:{y:[0,-15,0],rotate:[0,360]},transition:{duration:4+j,repeat:1/0,ease:"easeInOut",delay:j*.5},children:e.jsx(y,{size:28+j%3*12})},j)),e.jsx("div",{className:"absolute top-0 left-0 w-64 h-64 bg-purple-200 opacity-20 rounded-full -translate-x-1/2 -translate-y-1/2 blur-3xl"}),e.jsx("div",{className:"absolute bottom-0 right-0 w-80 h-80 bg-indigo-200 opacity-20 rounded-full translate-x-1/3 translate-y-1/3 blur-3xl"})]}),e.jsxs(E.div,{initial:{scale:.8,opacity:0},animate:{scale:1,opacity:1},transition:{type:"spring",damping:20,stiffness:200},className:"relative z-10 flex flex-col items-center text-center max-w-sm w-full",children:[e.jsx(E.img,{src:"/mascot/modules_avatar.png",alt:"Mascot",className:"w-36 h-36 sm:w-44 sm:h-44 mb-6 drop-shadow-[0_15px_30px_rgba(0,0,0,0.15)]",initial:{y:-20},animate:{y:[0,-8,0]},transition:{duration:2,repeat:1/0,ease:"easeInOut"}}),e.jsxs("h1",{className:"text-3xl sm:text-4xl font-black text-[#5b3a9e] mb-2 drop-shadow-sm",children:["Phase ",h+1," Complete!"]}),e.jsx("p",{className:"text-purple-500/70 text-sm mb-6",children:"Great work! Keep going."}),e.jsxs("div",{className:"bg-white/80 backdrop-blur-md rounded-2xl p-5 w-full mb-6 border border-purple-200/50 shadow-lg space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-slate-500 text-xs font-bold uppercase tracking-wider flex items-center gap-2",children:[e.jsx(Et,{size:14,className:"text-emerald-500"})," Correct"]}),e.jsx("span",{className:"text-lg font-black text-emerald-600",children:Re.questionsCorrect})]}),Re.questionsRevealed>0&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-slate-500 text-xs font-bold uppercase tracking-wider flex items-center gap-2",children:[e.jsx(Bt,{size:14,className:"text-amber-500"})," Revealed"]}),e.jsx("span",{className:"text-lg font-black text-amber-600",children:Re.questionsRevealed})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t border-purple-100",children:[e.jsxs("span",{className:"text-slate-500 text-xs font-bold uppercase tracking-wider flex items-center gap-2",children:[e.jsx(Ve,{size:14,className:"text-purple-500"})," XP Earned"]}),e.jsxs("span",{className:"text-xl font-black text-purple-600",children:["+",Re.xpEarned]})]})]}),e.jsx("div",{className:"flex items-center gap-2 mb-8",children:Array.from({length:d}).map((y,j)=>e.jsx("div",{className:`w-3 h-3 rounded-full transition-all ${j<=h?"bg-purple-500 shadow-[0_0_8px_rgba(153,86,222,0.6)]":"bg-purple-200"}`},j))}),e.jsxs("button",{onClick:L,className:"w-full py-4 rounded-full bg-[#9956DE] hover:bg-[#8544c7] text-white font-black text-lg shadow-xl hover:scale-[1.02] active:scale-[0.98] transition-transform mb-3",children:["Continue to Next Phase ",e.jsx(tt,{size:20,className:"inline ml-2"})]}),e.jsx("button",{onClick:()=>q(!0),className:"text-purple-400 hover:text-purple-600 text-sm font-bold transition-colors",children:"Quit Quiz"})]}),f&&e.jsx("div",{className:"fixed inset-0 z-[220] flex items-center justify-center p-4 bg-black/40 backdrop-blur-sm",children:e.jsxs(E.div,{initial:{scale:.9,opacity:0},animate:{scale:1,opacity:1},className:"bg-white rounded-[2rem] p-6 sm:p-8 max-w-xs w-full shadow-2xl flex flex-col gap-4 text-center",children:[e.jsx("h2",{className:"text-xl font-black text-slate-800",children:"Are you sure you want to leave?"}),e.jsx("p",{className:"text-sm text-slate-500",children:"Your progress won't be saved."}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(qe,{onClick:()=>q(!1),className:"w-full py-3 rounded-full bg-[#9956DE] hover:bg-[#8544c7] text-white font-bold",children:"Stay"}),e.jsx(qe,{onClick:r,className:"w-full py-3 rounded-full bg-slate-100 hover:bg-slate-200 text-slate-600 font-bold",children:"Leave"})]})]})})]});if(N==="loading-next")return e.jsx("div",{className:"fixed inset-0 z-[200] flex items-center justify-center bg-gradient-to-br from-[#7274ED] via-[#9956DE] to-[#7274ED]",children:e.jsxs("div",{className:"flex flex-col items-center gap-4",children:[e.jsx("div",{className:"w-12 h-12 border-4 border-white border-t-transparent rounded-full animate-spin"}),e.jsx("p",{className:"font-bold text-white text-lg",children:"Preparing next phase..."})]})});if(N==="complete"){const y=Object.values(z).filter(W=>W.resolution==="correct").length,j=Object.values(z).filter(W=>W.resolution==="revealed").length,Q=Math.round(y/t.length*100);return e.jsxs("div",{className:"fixed inset-0 z-[200] flex flex-col items-center justify-center bg-gradient-to-br from-[#e8e0f7] via-[#f0e8ff] to-[#ddd6f3] p-6",children:[e.jsxs("div",{className:"absolute inset-0 pointer-events-none overflow-hidden",children:[[It,Tt,Dt,kt,Lt,Rt,$s,Qe].map((W,re)=>e.jsx(E.div,{className:"absolute text-purple-300/25",style:{top:`${8+re*12%80}%`,left:`${3+re*13%90}%`},animate:{y:[0,-12,0],rotate:[0,360]},transition:{duration:5+re,repeat:1/0,ease:"easeInOut",delay:re*.4},children:e.jsx(W,{size:24+re%4*10})},re)),e.jsx("div",{className:"absolute top-0 right-0 w-72 h-72 bg-purple-200 opacity-20 rounded-full translate-x-1/3 -translate-y-1/3 blur-3xl"}),e.jsx("div",{className:"absolute bottom-0 left-0 w-64 h-64 bg-indigo-200 opacity-20 rounded-full -translate-x-1/3 translate-y-1/3 blur-3xl"})]}),e.jsxs(E.div,{initial:{scale:.8,opacity:0},animate:{scale:1,opacity:1},className:"relative z-10 flex flex-col items-center text-center max-w-sm w-full",children:[e.jsx(E.img,{src:"/mascot/modules_avatar.png",alt:"Mascot",className:"w-36 h-36 sm:w-44 sm:h-44 mb-6 drop-shadow-[0_15px_30px_rgba(0,0,0,0.15)]",initial:{y:-20},animate:{y:[0,-8,0]},transition:{duration:2,repeat:1/0,ease:"easeInOut"}}),e.jsx("h1",{className:"text-3xl sm:text-4xl font-black text-[#5b3a9e] mb-2",children:"Quiz Complete!"}),e.jsx("p",{className:"text-purple-500/70 text-sm mb-6",children:s}),e.jsxs("div",{className:"bg-white/80 backdrop-blur-md rounded-2xl p-5 w-full mb-6 border border-purple-200/50 shadow-lg space-y-3",children:[e.jsx(vt,{label:"Score",value:Q,suffix:"%",icon:e.jsx(As,{size:14,className:"text-purple-500"}),delay:0}),e.jsx(vt,{label:"Correct",value:y,suffix:`/${t.length}`,icon:e.jsx(Et,{size:14,className:"text-emerald-500"}),delay:200}),j>0&&e.jsx(vt,{label:"Revealed",value:j,icon:e.jsx(Bt,{size:14,className:"text-amber-500"}),delay:400}),e.jsx(vt,{label:"Best Streak",value:We,icon:e.jsx(Gt,{size:14,className:"text-orange-500"}),delay:600}),e.jsx("div",{className:"pt-2 border-t border-purple-100",children:e.jsx(vt,{label:"Total XP",value:ve,prefix:"+",icon:e.jsx(Ve,{size:14,className:"text-purple-500"}),delay:800,large:!0})})]}),e.jsx("button",{onClick:v,className:"w-full py-4 rounded-full bg-[#9956DE] hover:bg-[#8544c7] text-white font-black text-lg shadow-xl hover:scale-[1.02] active:scale-[0.98] transition-transform",children:"FINISH"})]})]})}const $=w?Pe(w.id):null,Z=w?Ns(w.type):null,ce=Z!==null&&($?.attempts??0)>=Z,le=Z===null||!ce,oe=!$?.resolved,we=w?.hints?.length??0,Be=we-($?.hintsUsed??0),fe=u[h]||[];return fe.filter(y=>z[y.id]?.resolved).length,w?e.jsxs(e.Fragment,{children:[Se&&At.createPortal(e.jsx(E.div,{initial:{opacity:0,x:20},animate:{opacity:1,x:0},exit:{opacity:0,x:20},className:"fixed right-6 top-1/2 -translate-y-1/2 z-[9999] w-64",children:e.jsxs("div",{className:"bg-white rounded-2xl p-3 border border-slate-200 shadow-[0_10px_40px_rgba(0,0,0,0.2)]",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2 px-1",children:[e.jsxs("h4",{className:"text-xs font-bold text-[#0a1628] flex items-center gap-2",children:[e.jsx(ut,{size:14,className:"text-purple-600"})," Calculator"]}),e.jsx("button",{onClick:()=>Ce(!1),className:"w-6 h-6 rounded-full bg-slate-100 flex items-center justify-center text-slate-500 hover:text-slate-800 hover:bg-slate-200 transition-colors",children:e.jsx(Ye,{size:12})})]}),e.jsx(Rs,{isOpen:!0,onClose:()=>Ce(!1),inline:!0})]})}),document.getElementById("modal-root")||document.body),e.jsx(Ze,{children:ie&&e.jsx(E.div,{initial:{opacity:0,scale:.8,y:20},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:1.1,filter:"blur(10px)"},transition:{type:"spring",damping:20,stiffness:300},className:"fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 z-[100] pointer-events-none flex flex-col items-center justify-center",children:e.jsxs("div",{className:"bg-white/95 backdrop-blur-xl border border-slate-200 rounded-[2rem] p-6 md:p-8 shadow-[0_30px_80px_rgba(0,0,0,0.15)] flex flex-col items-center min-w-[280px] md:min-w-[320px]",children:[e.jsx("img",{src:"/mascot/modules_avatar.png",alt:"Mascot",className:"w-24 h-24 md:w-32 md:h-32 mb-4 drop-shadow-[0_10px_20px_rgba(0,0,0,0.15)]"}),e.jsx("h2",{className:`text-3xl md:text-4xl font-black mb-4 uppercase tracking-widest ${ze?"text-emerald-500":"text-rose-500"}`,children:ze?"Correct!":"Incorrect"}),ze?e.jsxs("div",{className:"flex flex-col items-center gap-3 w-full justify-center",children:[e.jsx("div",{className:"flex items-center gap-2 bg-emerald-500/20 text-emerald-400 px-4 py-2 rounded-full font-bold border border-emerald-500/30",children:e.jsxs("span",{children:["+ ",$?.xpAwarded??10," XP"]})}),ge>=3&&e.jsxs("div",{className:"flex items-center gap-2 bg-orange-500/20 text-orange-400 px-4 py-1.5 rounded-full text-sm font-bold border border-orange-500/30",children:[e.jsx(Gt,{size:14})," Streak ×",ge,"!"]})]}):e.jsxs("div",{className:"bg-rose-500/20 border border-rose-500/30 text-rose-400 font-bold px-5 py-2 rounded-xl text-center",children:["Correct: ",w.correctAnswer]})]})},"round-result")}),e.jsx(Ze,{children:f&&e.jsx(E.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-[100] bg-black/60 backdrop-blur-sm flex items-center justify-center p-4",onClick:()=>q(!1),children:e.jsxs(E.div,{onClick:y=>y.stopPropagation(),initial:{scale:.9,opacity:0,y:20},animate:{scale:1,opacity:1,y:0},exit:{scale:.9,opacity:0,y:20},className:"bg-white rounded-[2rem] p-6 sm:p-8 max-w-xs w-full shadow-2xl flex flex-col gap-4 text-center",children:[e.jsx("h2",{className:"text-xl font-black text-slate-800",children:"Are you sure you want to leave?"}),e.jsx("p",{className:"text-sm text-slate-500",children:"Your progress won't be saved."}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(qe,{onClick:()=>q(!1),className:"w-full py-3 rounded-full bg-[#9956DE] hover:bg-[#8544c7] text-white font-bold",children:"Stay"}),e.jsx(qe,{onClick:()=>{q(!1),r()},className:"w-full py-3 rounded-full bg-slate-100 hover:bg-slate-200 text-slate-600 font-bold",children:"Leave"})]})]})})}),e.jsxs("div",{className:"fixed inset-0 z-50 h-screen w-full flex flex-col bg-slate-50 overflow-hidden",children:[e.jsxs("header",{className:`relative shrink-0 flex flex-col items-center justify-start px-4 pt-4 sm:pt-6 pb-6 z-[60] shadow-md overflow-hidden ${rt.gradient} rounded-b-[32px] sm:rounded-b-[40px] min-h-[110px] sm:min-h-[130px]`,children:[e.jsxs("div",{className:"absolute inset-0 z-0 pointer-events-none",children:[e.jsx("div",{className:"absolute top-0 left-0 w-64 h-64 bg-white opacity-10 rounded-full -translate-x-1/2 -translate-y-1/2 blur-2xl"}),e.jsx("div",{className:"absolute bottom-0 right-0 w-80 h-80 bg-white opacity-10 rounded-full translate-x-1/3 translate-y-1/3 blur-3xl"}),Me.map((y,j)=>e.jsx("div",{className:"absolute text-white/10",style:{top:`${10+j*15}%`,left:`${10+j*25%80}%`,transform:`rotate(${j*45}deg) scale(${1+j%3*.2})`},children:e.jsx(y,{size:48+j%2*32})},j))]}),e.jsxs("div",{className:"w-full max-w-7xl flex items-start justify-between relative z-10 mb-4 sm:mb-6",children:[e.jsx("div",{className:"flex-1 pointer-events-none"}),e.jsxs("div",{className:"relative flex items-center justify-center bg-purple-900/40 backdrop-blur-md px-6 sm:px-8 py-3 rounded-full border border-white/10 gap-3 sm:gap-4 shadow-inner",children:[e.jsx("div",{className:"w-3 h-3 sm:w-4 sm:h-4 rounded-full bg-yellow-400 shrink-0 shadow-[0_0_10px_rgba(250,204,21,0.6)]"}),e.jsxs("div",{className:"flex flex-col items-start justify-center",children:[e.jsx("span",{className:"text-[10px] sm:text-[11px] font-black text-purple-200 uppercase tracking-widest leading-none mb-1",children:"Try It Yourself!"}),e.jsx("span",{className:"font-bold text-white tracking-wide text-base sm:text-lg leading-none truncate max-w-[200px] sm:max-w-[300px]",children:s})]})]}),e.jsxs("div",{className:"flex-1 flex justify-end gap-2 sm:gap-3 relative pointer-events-auto",children:[e.jsx("button",{onClick:()=>C(!T),className:"w-10 h-10 sm:w-12 sm:h-12 rounded-full bg-purple-900/20 text-white flex items-center justify-center hover:bg-purple-900/40 transition-colors shadow-sm border border-white/10",children:T?e.jsx(Zt,{size:20}):e.jsx(Jt,{size:20})}),e.jsx("button",{onClick:Oe,className:"hidden sm:flex w-10 h-10 sm:w-12 sm:h-12 rounded-full bg-purple-900/20 text-white items-center justify-center hover:bg-purple-900/40 transition-colors shadow-sm border border-white/10",children:B?e.jsx(Ds,{size:20}):e.jsx(Is,{size:20})}),e.jsx("button",{onClick:()=>q(!0),className:"w-10 h-10 sm:w-12 sm:h-12 rounded-full bg-purple-900/20 text-white flex items-center justify-center hover:bg-purple-900/40 transition-colors shadow-sm border border-white/10",children:e.jsx(Js,{size:20})})]})]}),e.jsx("div",{className:"w-full max-w-[50rem] flex items-center justify-center px-4 z-10",children:e.jsx("div",{className:"w-full flex items-center gap-2 sm:gap-3",children:fe.map((y,j)=>e.jsx("div",{className:`h-1.5 sm:h-2 rounded-full flex-1 transition-all ${z[y.id]?.resolved?"bg-white shadow-[0_0_8px_rgba(255,255,255,0.8)]":"bg-white/20"}`},y.id))})})]}),e.jsx("div",{className:"w-full max-w-[54rem] mx-auto shrink-0 flex items-center justify-between px-4 sm:px-6 py-2 sm:py-3 z-[50] relative mt-4",children:e.jsxs("div",{className:"flex items-center justify-center gap-3 sm:gap-5 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 sm:gap-3 px-8 sm:px-10 py-2 rounded-full bg-white shadow-md border border-slate-200/60 text-rose-500 font-extrabold text-sm sm:text-base",children:[e.jsx("img",{src:"/icons/quiz_heart.png",alt:"Hearts",className:"w-5 h-5 object-contain"}),H]}),e.jsxs("div",{className:"flex items-center gap-2 sm:gap-3 px-8 sm:px-10 py-2 rounded-full bg-white shadow-md border border-slate-200/60 text-yellow-500 font-extrabold text-sm sm:text-base",children:[e.jsx("img",{src:"/icons/quiz_key.png",alt:"Keys",className:"w-5 h-5 object-contain"}),pe]}),e.jsxs("div",{className:"flex items-center gap-3 sm:gap-4 px-3 py-1.5 pl-5 sm:pl-6 rounded-full bg-white shadow-md border border-slate-200/60",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-orange-500 font-extrabold text-sm sm:text-base",children:[e.jsx("img",{src:"/icons/quiz_streak.png",alt:"Streak",className:"w-5 h-5 object-contain"})," ",ge]}),e.jsxs("div",{className:"bg-emerald-100 text-emerald-800 px-4 py-1.5 rounded-full font-bold text-sm sm:text-base shadow-inner border border-emerald-200/50",children:["+ ",ve," XP"]})]})]})}),e.jsx("main",{className:"flex-1 overflow-y-auto w-full px-4 sm:px-6 pt-0 pb-6 flex flex-col items-center relative z-10",children:e.jsxs(E.div,{initial:{opacity:0,x:20},animate:O?{x:[-10,10,-10,10,0],scale:[1,1.01,1],opacity:1}:{opacity:1,x:0},className:"w-full max-w-3xl flex flex-col mt-2",children:[e.jsxs("div",{className:"bg-white rounded-3xl shadow-lg border-t-[6px] border-purple-500 p-6 sm:p-8 text-center flex flex-col items-center mb-6 w-full relative overflow-hidden",children:[e.jsx("h2",{className:"text-xl sm:text-2xl font-extrabold text-[#0a1628] leading-tight w-full",children:e.jsx(Ft,{children:w.question})}),w.type==="fill-in-blank"&&!$?.resolved&&e.jsx("input",{ref:Je,type:"text",value:F,onChange:y=>X(y.target.value),placeholder:"Type your answer...",disabled:$?.resolved||_e,className:"mt-4 w-full max-w-xs mx-auto px-4 py-3 border-b-4 border-[#7C3AED] text-center text-lg font-bold outline-none bg-transparent focus:border-[#75D06A] transition-colors"}),w.type==="fill-in-blank"&&$?.resolved&&e.jsx("div",{className:"mt-4 px-4 py-3 bg-emerald-50 border-2 border-emerald-300 rounded-xl text-emerald-700 font-bold text-lg",children:w.correctAnswer})]}),e.jsxs("div",{className:"w-full flex flex-col items-center",children:[(w.type==="multiple-choice"||w.type==="true-false")&&e.jsx("div",{className:"w-full grid grid-cols-1 sm:grid-cols-2 gap-3 sm:gap-5",children:(w.type==="true-false"?[{id:"tf-true",text:"True"},{id:"tf-false",text:"False"}]:K).map(y=>{const j=y.text,Q=$?.failedOptions.includes(j),W=$?.resolved&&$.resolution==="revealed",re=$?.resolved&&$.resolution==="correct",je=j===w.correctAnswer;let se="bg-white hover:bg-slate-50 border-transparent text-slate-700 hover:border-slate-200";return W||re?je?se="bg-emerald-50 border-emerald-400 text-emerald-800 shadow-[0_0_15px_rgba(16,185,129,0.2)] scale-[1.02] z-10":Q?se="bg-rose-50 border-rose-400 text-rose-800 opacity-60":se="bg-slate-50 border-slate-200 text-slate-400 opacity-60":Q?se="bg-rose-50 border-rose-400 text-rose-800 opacity-60":R===y.id&&(se="bg-purple-50 border-[#9956DE] text-[#9956DE]"),e.jsxs("button",{disabled:$?.resolved||Q||_e,onClick:()=>{$?.resolved||_e||Q||(P(y.id),Xe(j))},className:`p-4 sm:p-5 rounded-2xl shadow-sm border-[3px] font-extrabold text-base sm:text-lg text-left transition-all flex items-center justify-between ${se} ${$?.resolved?"cursor-default":"hover:shadow-md hover:-translate-y-0.5 active:translate-y-0"}`,children:[e.jsx("span",{className:"truncate pr-4",children:e.jsx(Ft,{children:j})}),(W||re)&&je&&e.jsx(Et,{size:24,className:"text-emerald-500 shrink-0"}),Q&&e.jsx(Ye,{size:24,className:"text-rose-500 shrink-0"})]},y.id)})}),ee&&w.hints&&($?.hintsUsed??0)>0&&e.jsx(E.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:"w-full mt-6 max-w-3xl",children:e.jsxs("div",{className:"border-2 rounded-2xl p-5 bg-amber-50 border-amber-200",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(ot,{size:18,className:"text-amber-500"}),e.jsxs("span",{className:"font-bold text-amber-700 text-sm",children:["Hints (",$?.hintsUsed,"/",we,")"]})]}),e.jsx("div",{className:"space-y-2",children:w.hints.slice(0,$?.hintsUsed??0).map((y,j)=>e.jsxs("p",{className:"text-sm text-amber-800 leading-relaxed",children:[e.jsxs("span",{className:"font-bold text-amber-600",children:[j+1,"."]})," ",y]},j))})]})}),me&&$?.resolved&&w.explanation&&e.jsx(E.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:"w-full mt-6 max-w-3xl",children:e.jsxs("div",{className:"border-2 rounded-2xl p-5 flex items-start gap-4 bg-sky-50 border-sky-200",children:[e.jsx("img",{src:"/mascot/modules_avatar.png",className:"w-10 h-10 shrink-0",alt:"AI Explain"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-extrabold text-lg mb-1 text-sky-700",children:"Explanation"}),e.jsx("p",{className:"text-base leading-relaxed text-sky-800",children:w.explanation})]})]})})]})]},w.id)}),e.jsxs("footer",{className:`shrink-0 relative z-[60] flex flex-col items-center justify-center p-4 sm:p-6 ${rt.gradient} rounded-t-[32px] sm:rounded-t-[40px] shadow-[0_-10px_40px_rgba(0,0,0,0.15)]`,children:[e.jsx("div",{className:"absolute inset-0 z-0 pointer-events-none opacity-20",children:Me.slice(0,3).map((y,j)=>e.jsx("div",{className:"absolute text-white",style:{top:`${20+j*20}%`,left:`${20+j*30}%`,transform:`rotate(${j*30}deg) scale(1.5)`},children:e.jsx(y,{size:32})},j))}),e.jsx("div",{className:"relative z-10 flex flex-col gap-3",children:$?.resolved?me?e.jsxs("button",{onClick:it,className:"bg-orange-500 hover:bg-orange-600 text-white font-extrabold text-lg px-8 py-4 rounded-full flex items-center justify-center gap-3 shadow-xl hover:scale-[1.02] active:scale-[0.98] transition-all w-full",children:["Next Question ",e.jsx(tt,{size:24})]}):e.jsxs("div",{className:"flex flex-wrap justify-center gap-3 sm:gap-4",children:[e.jsxs("button",{onClick:()=>{oe||ue(!0)},disabled:oe,className:"bg-white hover:bg-slate-50 disabled:opacity-50 disabled:cursor-not-allowed text-slate-700 font-bold px-6 sm:px-8 py-3 sm:py-3.5 rounded-full flex items-center gap-2 shadow-lg transition-transform hover:scale-105 active:scale-95 border border-slate-200",children:[e.jsx("img",{src:"/mascot/modules_avatar.png",className:"w-5 h-5 drop-shadow-sm",alt:"Explain"}),"Explain"]}),e.jsxs("button",{onClick:it,className:"bg-orange-500 hover:bg-orange-600 text-white font-extrabold text-lg px-8 py-3 sm:py-3.5 rounded-full flex items-center justify-center gap-2 shadow-xl hover:scale-105 active:scale-95",children:["Next Question ",e.jsx(tt,{size:20})]})]}):e.jsxs("div",{className:"flex flex-wrap justify-center gap-3 sm:gap-4",children:[e.jsxs("button",{onClick:gt,disabled:pe<=0||Be<=0,className:"bg-white hover:bg-slate-50 disabled:opacity-70 disabled:cursor-not-allowed text-slate-700 font-bold px-6 sm:px-8 py-3 sm:py-3.5 rounded-full flex items-center gap-2 shadow-lg transition-transform hover:scale-105 active:scale-95 border border-slate-200",children:[e.jsx("img",{src:"/icons/quiz_key.png",alt:"Hint",className:"w-5 h-5 object-contain"}),"Hint"]}),e.jsxs("div",{className:"relative group",children:[e.jsxs("button",{onClick:lt,disabled:le,className:"bg-white hover:bg-slate-50 disabled:opacity-70 disabled:cursor-not-allowed text-slate-700 font-bold px-6 sm:px-8 py-3 sm:py-3.5 rounded-full flex items-center gap-2 shadow-lg transition-transform hover:scale-105 active:scale-95 border border-slate-200",children:[e.jsx(Bt,{size:18,className:"text-purple-500"}),"Reveal"]}),le&&Z!==null&&e.jsx("div",{className:"absolute bottom-full left-1/2 -translate-x-1/2 mb-2 px-3 py-1.5 bg-slate-800 text-white text-[11px] rounded-lg whitespace-nowrap opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none font-medium",children:"Reveal locked. Give it another try!"})]}),e.jsxs("div",{className:"relative group",children:[e.jsxs("button",{disabled:!0,className:"bg-white disabled:opacity-50 disabled:cursor-not-allowed text-slate-700 font-bold px-6 sm:px-8 py-3 sm:py-3.5 rounded-full flex items-center gap-2 shadow-lg border border-slate-200",children:[e.jsx(ts,{size:16,className:"text-slate-400"}),"Explain"]}),e.jsx("div",{className:"absolute bottom-full left-1/2 -translate-x-1/2 mb-2 px-3 py-1.5 bg-slate-800 text-white text-[11px] rounded-lg whitespace-nowrap opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none font-medium",children:"Unlocks after you complete or reveal this question"})]}),e.jsx("button",{onClick:()=>Ce(y=>!y),className:`w-11 h-11 sm:w-12 sm:h-12 rounded-full flex items-center justify-center shadow-lg transition-transform hover:scale-105 active:scale-95 border border-slate-200 ${Se?"bg-purple-100 text-purple-600 border-purple-300":"bg-white hover:bg-slate-50 text-slate-700"}`,children:e.jsx(ut,{size:20})}),w.type==="fill-in-blank"&&e.jsxs("button",{onClick:()=>Xe(),disabled:!F.trim()||_e,className:"bg-orange-500 hover:bg-orange-600 disabled:opacity-50 disabled:cursor-not-allowed text-white font-extrabold text-lg px-8 py-3 sm:py-3.5 rounded-full flex items-center justify-center gap-2 shadow-xl hover:scale-105 active:scale-95",children:["Submit ",e.jsx(tt,{size:20})]})]})})]})]})]}):null},Vr=[{id:1,type:"multiple-choice",question:"What is the value of π (pi) to two decimal places?",options:["3.12","3.14","3.16","3.18"],correctAnswer:"3.14",explanation:"π ≈ 3.14159..., so to two decimal places it is 3.14."},{id:2,type:"true-false",question:"The sum of angles in a triangle is 180 degrees.",correctAnswer:"True",explanation:"The interior angles of any Euclidean triangle sum to 180°."},{id:3,type:"fill-in-blank",question:"If 2x + 5 = 13, then x = ___.",correctAnswer:"4",explanation:"2x = 13 - 5 = 8 → x = 4."},{id:4,type:"multiple-choice",question:"Which of the following is a prime number?",options:["9","15","17","21"],correctAnswer:"17",explanation:"17 is only divisible by 1 and itself. 9=3×3, 15=3×5, 21=3×7."},{id:5,type:"true-false",question:"The slope of a horizontal line is zero.",correctAnswer:"True",explanation:"A horizontal line has no rise, so rise/run = 0."},{id:6,type:"fill-in-blank",question:"The square root of 144 is ___.",correctAnswer:"12",explanation:"12 × 12 = 144, so √144 = 12."}];async function Yr(t){const{lessonTitle:s,topic:l,subjectId:n,competencyCode:i,questionCount:c=6}=t,r=Zr(n)||"General Mathematics",u=t.lessonId?Math.abs(t.lessonId.split("").reduce((d,h)=>Math.imul(31,d)+h.charCodeAt(0)|0,0))%1e6:Math.floor(Math.random()*1e6);try{const d=await at("/api/quiz/generate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({topic:l||s,subject:r,lessonTitle:s,questionCount:c,questionTypes:["multiple-choice","true-false","fill-in-blank"],difficulty:"medium",competencyCode:i,varianceSeed:u})});return!d.questions||d.questions.length===0?(console.warn("[lessonQuizService] API returned empty questions, using fallback"),ks(c)):d.questions.map(h=>({id:h.id,type:h.type,question:h.question,options:h.options||void 0,correctAnswer:h.correctAnswer,explanation:h.explanation,hints:h.hints||[],bloomLevel:h.bloomLevel||"remember"}))}catch(d){return console.error("[lessonQuizService] Failed to generate quiz via API:",d),console.warn("[lessonQuizService] Using fallback questions"),ks(c)}}function Kr(t){return 6}function Zr(t){if(!t)return null;const s=t.toLowerCase();return s.includes("gen-math")||s.includes("gen_math")?"General Mathematics":s.includes("stats")||s.includes("prob")?"Statistics and Probability":s.includes("pre-calc")||s.includes("pre_calc")?"Pre-Calculus":s.includes("basic-calc")||s.includes("basic_calc")||s.includes("calculus")?"Basic Calculus":null}function ks(t){const s=[...Vr].sort(()=>Math.random()-.5);return s.slice(0,Math.min(t,s.length)).map((l,n)=>({...l,id:n+1}))}const Jr="rag_lesson_";function is(t){return`${Jr}${t}`}function el(t){try{const s=sessionStorage.getItem(is(t));if(s)return JSON.parse(s)}catch{}return null}function tl(t,s){try{sessionStorage.setItem(is(t),JSON.stringify(s))}catch{}}function sl(t,s,l=!0){const[n,i]=a.useState([]),[c,r]=a.useState(!0),[u,d]=a.useState(null),[h,S]=a.useState([]),[m,M]=a.useState("low"),[p,x]=a.useState(0),[N,g]=a.useState(!1),[z,k]=a.useState(void 0),[R,P]=a.useState(!1),F=a.useCallback(async()=>{if(!l||!t)return;const K=el(t);if(K){i(K.sections),S(K.sources),M(K.retrievalBand),x(K.retrievalConfidence),g(K.needsReview),k(K.activeModel),r(!1),d(null),P(!1);return}r(!0),d(null),P(!1);try{const ee=(await St(()=>import("./vendor-firebase-auth-T_wvTOvf.js"),__vite__mapDeps([4,3])).then(me=>me.getAuth().currentUser))?.uid,D=await wa({...s,lessonId:t,userId:ee});i(D.sections),S(D.sources||[]),M(D.retrievalBand),x(D.retrievalConfidence),g(D.needsReview),k(D.activeModel),tl(t,D),d(null),P(!1)}catch(Y){const ee=Y.status||Y.response?.status,D=Y.body||Y.response;let me="Failed to load lesson content.",ue=!1;ee===404&&D?.error==="no_curriculum_context"?(me=D.message||"Lesson source PDF not found or not yet ingested.",ue=!0):ee===401?me="Please sign in again to access lessons.":navigator.onLine||(me="No internet connection. Please try again when online.",ue=!0),d(me),P(ue),i([])}finally{r(!1)}},[t,l,JSON.stringify(s)]);a.useEffect(()=>{F()},[F]);const X=a.useCallback(()=>{t&&sessionStorage.removeItem(is(t)),r(!0),d(null),F()},[F,t]);return{sections:n,isLoading:c,error:u,retry:X,sources:h,retrievalBand:m,retrievalConfidence:p,needsReview:N,activeModel:z,isOffline:R}}const Os=/[=×÷±√∑∫π²³%]/,al=/^(Definition|Formula|Note|Reminder|Important|Example|Key Concept|Concept|Rule|Theorem|Property|Step)s?\s*:/i;function ct(t){return t.replace(/\b([A-Z][a-zA-Z\s]{2,30}?)\s+(is|are|refers to|defined as|means)\b/g,(s,l,n)=>`**${l.trim()}** ${n}`).replace(/"([^"]{3,40})"/g,(s,l)=>`**${l}**`)}function Wt(t){if(!t?.trim())return null;const s=t.split(` +`),l=[];let n=[],i=[],c=[],r=0;const u=()=>{if(n.length===0)return;const x=n.join(" ").trim();if(!x){n=[];return}const N=x.match(/[^.!?]+[.!?]+["']?/g)||[x],g=[];let z=[],k=0;for(const R of N)z.push(R),k+=R.length,k>220&&(g.push(z),z=[],k=0);z.length&&g.push(z);for(const R of g){const P=ct(R.join(" ").trim());l.push(e.jsx("p",{className:"lesson-body-text text-slate-700 leading-[1.8] text-[1rem] font-body",children:Fe(P)},r++))}n=[]},d=()=>{i.length!==0&&(l.push(e.jsx("ul",{className:"space-y-2.5 my-1 pl-1",children:i.map((x,N)=>e.jsxs("li",{className:"flex items-start gap-3 text-slate-700 text-[0.95rem] leading-[1.75] font-body",children:[e.jsx("span",{className:"mt-[0.5rem] w-2 h-2 rounded-full bg-[#1a85a4] flex-shrink-0"}),e.jsx("span",{children:Fe(ct(x))})]},N))},r++)),i=[])},h=()=>{c.length!==0&&(l.push(e.jsx("ol",{className:"space-y-2.5 my-1 list-none pl-1",children:c.map((x,N)=>e.jsxs("li",{className:"flex items-start gap-3 text-slate-700 text-[0.95rem] leading-[1.75] font-body",children:[e.jsx("span",{className:"mt-0.5 min-w-[1.5rem] h-[1.5rem] rounded-full bg-[#1a85a4] text-white text-[0.7rem] font-bold flex items-center justify-center flex-shrink-0",children:N+1}),e.jsx("span",{children:Fe(ct(x))})]},N))},r++)),c=[])},S=x=>/^[\-•\*]\s+/.test(x.trim()),m=x=>/^\d+[\.\)]\s+/.test(x.trim()),M=x=>Os.test(x)&&x.trim().length<120,p=x=>{const N=x.toLowerCase();return/formula|theorem|property|rule/.test(N)?{bg:"bg-amber-50",border:"border-amber-300",text:"text-amber-900",label:"📐"}:/definition|concept|key/.test(N)?{bg:"bg-blue-50",border:"border-blue-300",text:"text-blue-900",label:"📖"}:/note|reminder|important/.test(N)?{bg:"bg-rose-50",border:"border-rose-300",text:"text-rose-900",label:"⚠️"}:/example|step/.test(N)?{bg:"bg-emerald-50",border:"border-emerald-300",text:"text-emerald-900",label:"✏️"}:{bg:"bg-slate-50",border:"border-slate-300",text:"text-slate-800",label:"💡"}};for(const x of s){const N=x.trimEnd(),g=N.trim();if(g===""){d(),h(),u();continue}const z=g.match(al);if(z){d(),h(),u();const k=z[1],R=g.slice(z[0].length).trim(),P=p(k);l.push(e.jsxs("div",{className:`rounded-xl px-4 py-3.5 border-l-4 ${P.bg} ${P.border} my-1`,children:[e.jsxs("p",{className:`text-[0.75rem] font-black uppercase tracking-widest mb-1.5 ${P.text} opacity-80 font-display`,children:[P.label," ",k]}),e.jsx("p",{className:`text-[0.95rem] leading-[1.75] font-semibold font-body ${P.text}`,children:Fe(R)})]},r++));continue}if(S(g)){u(),h(),i.push(g.replace(/^[\-•\*]\s+/,""));continue}if(m(g)){u(),d(),c.push(g.replace(/^\d+[\.\)]\s+/,""));continue}if(M(g)&&!/[a-z]{5,}/.test(g)){d(),h(),u(),l.push(e.jsx("div",{className:"lesson-formula-box my-3",children:g},r++));continue}if(g.endsWith(":")&&g.length<80&&!g.startsWith(" ")){d(),h(),u(),l.push(e.jsx("p",{className:"lesson-section-heading text-[#1a85a4] text-[1.05rem] mt-5 mb-1 border-b-2 border-[#1a85a4]/20 pb-1.5",children:Fe(g)},r++));continue}d(),h(),n.push(N)}return d(),h(),u(),e.jsx("div",{className:"space-y-3",children:l})}function Fe(t){const s=[],l=/(\*\*(.+?)\*\*|\*(.+?)\*|`(.+?)`|==(.+?)==)/g;let n=0,i,c=0;for(;(i=l.exec(t))!==null;)i.index>n&&s.push(e.jsx(Ie.Fragment,{children:t.slice(n,i.index)},c++)),i[2]?s.push(e.jsx("strong",{className:"font-extrabold text-[#1a85a4] bg-[#e0f4fa] px-1 py-0.5 rounded-md font-body",children:i[2]},c++)):i[3]?s.push(e.jsx("em",{className:"italic text-slate-500 font-body",children:i[3]},c++)):i[4]?s.push(e.jsx("code",{className:"px-1.5 py-0.5 bg-slate-100 rounded text-[0.85em] font-mono text-[#e66a5e] border border-slate-200 font-semibold",children:i[4]},c++)):i[5]&&s.push(e.jsx("mark",{className:"bg-[#fff3cd] text-[#92400e] px-1 py-0.5 rounded-md font-bold border-b-2 border-[#fbbf24]",children:i[5]},c++)),n=i.index+i[0].length;return n0?e.jsx(e.Fragment,{children:s}):t}function rl(t){if(!t?.trim())return{welcome:"",objectives:[]};const s=t.split(` +`).map(u=>u.trim()).filter(Boolean),l=/^(\d+[\.\)]\s+|[-•*]\s+|(Identify|Write|Set|Use|Apply|Solve|Compute|Calculate|Determine|Understand|Describe|Explain|Analyze|Evaluate|Create|Define|Distinguish|Compare|Illustrate|Demonstrate|Perform|Simplify|Represent|Model|Interpret|Recognize|Classify|Construct|Derive|Formulate|Graph|Sketch|Verify|Prove|Estimate|Approximate|Convert|Translate|Predict|Justify|Generalize|Extend|Develop|Explore|Investigate|Discover|Observe|Measure|Record|Report|Present|Communicate|Collaborate|Reflect|Review|Summarize|Conclude|Infer|Hypothesize|Test|Experiment|Design|Plan|Implement|Evaluate|Assess|Monitor|Adjust|Improve|Optimize|Innovate|Create|Produce|Publish|Share|Teach|Learn|Practice|Apply|Transfer|Connect|Integrate|Synthesize|Analyze|Evaluate|Create)\b)/i,n=/^(Example:|e\.g\.|For example:|Sample:|\()/i,i=[],c=[];let r=!1;for(let u=0;u0&&t.callouts.map((x,N)=>e.jsxs("div",{className:`lesson-callout-headsup flex items-start gap-3.5 ${x.type==="tip"?"!bg-gradient-to-r !from-emerald-50 !to-teal-50 !border-emerald-400":""}`,children:[e.jsx("div",{className:`w-9 h-9 rounded-xl flex items-center justify-center flex-shrink-0 mt-0.5 shadow-sm ${x.type==="tip"?"bg-emerald-500":"bg-amber-500"}`,children:e.jsx(ot,{size:16,className:"text-white"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:`lesson-section-heading text-[0.65rem] uppercase tracking-[0.2em] mb-1 ${x.type==="tip"?"text-emerald-600":"text-amber-600"}`,children:x.type==="tip"?"✨ Tip":x.type==="important"?"⚠️ Heads Up":"📌 Note"}),e.jsx("p",{className:"font-body text-[0.95rem] text-slate-700 leading-[1.75] font-medium",children:x.text})]})]},N)),(!t.callouts||t.callouts.length===0)&&e.jsxs("div",{className:"lesson-callout-headsup flex items-start gap-3.5",children:[e.jsx("div",{className:"w-9 h-9 rounded-xl bg-amber-500 flex items-center justify-center flex-shrink-0 mt-0.5 shadow-sm",children:e.jsx(ot,{size:16,className:"text-white"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"lesson-section-heading text-[0.65rem] uppercase tracking-[0.2em] mb-1 text-amber-600",children:"⚠️ Heads Up"}),e.jsxs("p",{className:"font-body text-[0.95rem] text-slate-700 leading-[1.75] font-medium",children:["This lesson has ",7," sections and takes about 20 minutes to complete. Grab a pen — you might want to take notes along the way!"]})]})]}),M.length>0&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(st,{size:20,className:"text-violet-500"}),e.jsx("h3",{className:"lesson-section-heading text-[1.05rem]",style:{color:"#7c3aed"},children:"What you'll learn"})]}),e.jsx("div",{className:"space-y-2.5",children:M.map((x,N)=>{const g=Cs[N%Cs.length];return e.jsxs("div",{className:`rounded-xl border-2 px-4 py-3.5 flex items-start gap-3.5 ${g.bg} ${g.border} shadow-sm`,children:[e.jsx("span",{className:`mt-0.5 min-w-[1.75rem] h-7 rounded-full ${g.num} text-white text-[0.7rem] font-black flex items-center justify-center flex-shrink-0 shadow-sm`,children:N+1}),e.jsxs("div",{children:[e.jsx("p",{className:`font-body text-[0.95rem] font-semibold leading-snug ${g.text}`,children:Fe(ct(x.text))}),x.example&&e.jsx("p",{className:`text-xs mt-1 ${g.ex} font-mono font-semibold`,children:x.example})]})]},N)})})]})]})}case"key_concepts":return e.jsxs("div",{className:"space-y-4",children:[t.content?.trim()?e.jsx("div",{className:"mb-4",children:Wt(t.content)}):e.jsx("p",{className:"text-slate-400 text-sm italic mb-4",children:"Key concepts are being compiled. Review the curriculum sources below for reference material."}),t.callouts&&t.callouts.length>0&&e.jsx("div",{className:"space-y-3",children:t.callouts.map((m,M)=>e.jsxs("div",{className:`rounded-xl border-2 px-5 py-4 flex items-start gap-3.5 shadow-sm ${m.type==="important"?"bg-rose-50 border-rose-300":m.type==="tip"?"bg-emerald-50 border-emerald-300":"bg-amber-50 border-amber-300"}`,children:[e.jsx("div",{className:`w-9 h-9 rounded-xl flex items-center justify-center flex-shrink-0 mt-0.5 shadow-sm ${m.type==="important"?"bg-rose-500":m.type==="tip"?"bg-emerald-500":"bg-amber-500"}`,children:e.jsx(ot,{size:16,className:"text-white"})}),e.jsxs("div",{children:[e.jsx("p",{className:`lesson-section-heading text-[0.65rem] uppercase tracking-[0.2em] mb-1 ${m.type==="important"?"text-rose-500":m.type==="tip"?"text-emerald-600":"text-amber-600"}`,children:m.type==="important"?"🔑 Important":m.type==="tip"?"✨ Tip":"📌 Note"}),e.jsx("p",{className:"font-body text-[0.95rem] text-slate-700 leading-[1.75] font-medium",children:Fe(m.text)})]})]},M))})]});case"video":return e.jsxs("div",{className:"space-y-4",children:[t.content?.trim()?e.jsx("p",{className:"text-slate-600 text-sm",children:t.content}):e.jsx("p",{className:"text-slate-400 text-sm italic",children:"Video explanation loading..."}),e.jsx(ja,{videos:t.videos||[],topic:i.title})]});case"worked_examples":return e.jsx("div",{className:"space-y-5",children:t.examples&&t.examples.length>0?t.examples.map((m,M)=>e.jsxs("div",{className:"bg-gradient-to-br from-rose-50 via-orange-50 to-amber-50 rounded-2xl p-5 border-2 border-rose-200 shadow-md",children:[e.jsxs("div",{className:"flex items-start gap-3.5 mb-4",children:[e.jsx("div",{className:"w-10 h-10 bg-gradient-to-br from-rose-500 to-orange-500 rounded-xl flex items-center justify-center flex-shrink-0 shadow-md",children:e.jsx(ut,{size:18,className:"text-white"})}),e.jsxs("div",{children:[e.jsxs("p",{className:"lesson-section-heading text-[0.65rem] uppercase tracking-[0.2em] text-rose-400 mb-1",children:["Example ",M+1]}),e.jsx("p",{className:"font-body font-bold text-slate-800 text-[1rem] leading-snug",children:m.problem})]})]}),m.steps.length>0&&e.jsxs("div",{className:"ml-14 space-y-2.5 mb-3",children:[e.jsx("p",{className:"lesson-section-heading text-[0.65rem] uppercase tracking-[0.2em] text-slate-400 mb-1.5",children:"Solution"}),m.steps.map((p,x)=>Os.test(p)&&p.length<100&&!/[a-z]{6,}/.test(p)?e.jsx("div",{className:"lesson-formula-box",children:p},x):e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"mt-0.5 min-w-[1.5rem] h-[1.5rem] rounded-full bg-white border-2 border-rose-300 text-rose-500 text-[0.65rem] font-black flex items-center justify-center flex-shrink-0 shadow-sm",children:x+1}),e.jsx("p",{className:"font-body text-slate-700 text-[0.95rem] leading-[1.75]",children:Fe(p)})]},x))]}),m.answer&&e.jsxs("div",{className:"ml-14 flex items-center gap-3 mt-3 pt-3 border-t-2 border-rose-200",children:[e.jsx("div",{className:"px-3.5 py-1.5 bg-gradient-to-r from-rose-500 to-orange-500 rounded-lg text-white text-[0.65rem] font-black uppercase tracking-widest flex-shrink-0 shadow-sm",children:"Answer"}),e.jsx("p",{className:"font-body text-slate-800 text-[0.95rem] font-bold",children:m.answer})]})]},M)):e.jsx("p",{className:"text-slate-400 text-sm italic",children:"No worked examples available for this lesson."})});case"important_notes":return e.jsx("div",{className:"space-y-3",children:t.bulletPoints&&t.bulletPoints.length>0?t.bulletPoints.map((m,M)=>{const p=m.match(/^(Note|Important|Remember|Warning|Tip|Key|Formula|Rule)\s*:/i);if(p){const x=p[1],N=m.slice(p[0].length).trim(),g=/note|important|warning|remember/i.test(x);return e.jsxs("div",{className:`rounded-xl px-5 py-4 border-l-4 flex items-start gap-3.5 shadow-sm ${g?"bg-rose-50 border-rose-400":"bg-amber-50 border-amber-400"}`,children:[e.jsx(ot,{size:18,className:`mt-0.5 flex-shrink-0 ${g?"text-rose-500":"text-amber-500"}`}),e.jsxs("div",{children:[e.jsx("p",{className:`lesson-section-heading text-[0.65rem] uppercase tracking-[0.2em] mb-1 ${g?"text-rose-500":"text-amber-600"}`,children:x}),e.jsx("p",{className:"font-body text-[0.95rem] text-slate-700 leading-[1.75] font-medium",children:Fe(ct(N))})]})]},M)}return e.jsxs("div",{className:"flex items-start gap-3.5 p-4 rounded-xl bg-slate-50 border-2 border-slate-200 hover:border-[#1a85a4]/40 hover:bg-[#f0fbff] transition-colors",children:[e.jsx("div",{className:"mt-0.5 w-6 h-6 rounded-full bg-[#1a85a4] flex items-center justify-center flex-shrink-0 shadow-sm",children:e.jsx("span",{className:"text-white text-[0.65rem] font-black",children:M+1})}),e.jsx("p",{className:"font-body text-slate-700 text-[0.95rem] leading-[1.75] font-medium",children:Fe(ct(m))})]},M)}):e.jsx("p",{className:"text-slate-400 text-sm italic",children:"No notes available for this lesson."})});case"try_it_yourself":return e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"flex flex-col items-center text-center gap-3 py-4",children:[e.jsx("div",{className:"w-16 h-16 rounded-full flex items-center justify-center shadow-lg",style:{background:"#9956DE"},children:e.jsx(st,{size:32,className:"text-white"})}),e.jsx("h3",{className:"text-xl font-black",style:{color:"#9956DE"},children:"Try It Yourself"}),e.jsx("p",{className:"text-slate-500 text-sm max-w-xs leading-relaxed",children:"Now it's your turn! Try applying what you've learned. You can practice with the exercises at the end of this module."})]}),e.jsxs("div",{className:"flex items-start gap-2 rounded-xl px-4 py-3 border",style:{background:"#f5eeff",borderColor:"#d4aaff"},children:[e.jsx(ot,{size:16,className:"mt-0.5 shrink-0",style:{color:"#9956DE"}}),e.jsxs("p",{className:"text-sm",style:{color:"#7a3db8"},children:[e.jsx("span",{className:"font-bold",children:"Tip:"})," Complete the practice quizzes after this lesson to reinforce your learning!"]})]}),c&&e.jsx("div",{className:"bg-white rounded-2xl p-5 border border-slate-200 shadow-sm",children:r?e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 bg-emerald-100 rounded-xl flex items-center justify-center",children:e.jsx(st,{size:20,className:"text-emerald-600"})}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-sm font-bold text-emerald-700",children:["Quiz Complete",typeof u=="number"&&e.jsxs("span",{className:"ml-2 text-emerald-600",children:[u,"%"]})]}),e.jsx("p",{className:"text-xs text-emerald-600/80",children:"Great job! You can now complete this lesson."})]})]}):e.jsxs("div",{className:"flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] font-black uppercase tracking-widest mb-1",style:{color:"#9956DE"},children:"Practice Quiz"}),e.jsx("p",{className:"font-bold text-slate-800 text-sm",children:c.title}),e.jsxs("p",{className:"text-xs text-slate-500 mt-0.5",children:[c.questions," questions · ",c.duration]})]}),e.jsx("button",{onClick:d,className:"w-full sm:w-auto px-6 py-2.5 rounded-xl bg-[#1a85a4] text-white text-sm font-black hover:bg-[#126b84] transition-colors shadow-md uppercase tracking-wide",children:"Start Practice"})]})}),!c&&e.jsxs("button",{onClick:S,className:"w-full flex items-center justify-between gap-4 text-white rounded-2xl px-6 py-4 shadow-lg transition-all hover:shadow-xl hover:scale-[1.01] active:scale-[0.99] group",style:{background:"#9956DE"},onMouseEnter:m=>m.currentTarget.style.background="#8744cc",onMouseLeave:m=>m.currentTarget.style.background="#9956DE",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 bg-white/20 rounded-xl flex items-center justify-center shrink-0",children:e.jsx(Qa,{size:22,className:"text-white"})}),e.jsxs("div",{className:"text-left",children:[e.jsx("p",{className:"font-black text-sm uppercase tracking-wide",children:"Start Practice Quiz"}),e.jsx("p",{className:"text-white/80 text-xs mt-0.5",children:"10 questions · AI-generated"})]})]}),e.jsx(tt,{size:20,className:"text-white/80 group-hover:translate-x-1 transition-transform"})]})]});case"summary":return e.jsx("div",{className:"space-y-3",children:t.content?.trim()?Wt(t.content):e.jsx("p",{className:"text-slate-400 text-sm italic",children:"Summary is being prepared. Review the lesson sections above to reinforce your understanding."})});default:return e.jsx("p",{className:"text-slate-500 text-sm italic",children:"Section content not available."})}}const Nt=[{type:"introduction",label:"Intro",helper:"Welcome note",icon:pt,accent:"from-[#1a85a4] to-[#126b84]",tint:"bg-[#1a85a4] text-white border-transparent",tabBg:"bg-[#1a85a4]"},{type:"key_concepts",label:"Concepts",helper:"Core ideas",icon:ar,accent:"from-[#fbab41] to-[#e0983a]",tint:"bg-[#fbab41] text-white border-transparent",tabBg:"bg-[#fbab41]"},{type:"video",label:"Video",helper:"Watch and learn",icon:ot,accent:"from-[#e66a5e] to-[#ce5e53]",tint:"bg-[#e66a5e] text-white border-transparent",tabBg:"bg-[#e66a5e]"},{type:"worked_examples",label:"Examples",helper:"Guided solving",icon:Ca,accent:"from-[#7ec16d] to-[#71ad62]",tint:"bg-[#7ec16d] text-white border-transparent",tabBg:"bg-[#7ec16d]"},{type:"important_notes",label:"Notes",helper:"Key reminders",icon:lr,accent:"from-[#9a67d0] to-[#8a5cc0]",tint:"bg-[#9a67d0] text-white border-transparent",tabBg:"bg-[#9a67d0]"},{type:"try_it_yourself",label:"Practice",helper:"Try it yourself",icon:Qe,accent:"from-[#eb74a6] to-[#d46895]",tint:"bg-[#eb74a6] text-white border-transparent",tabBg:"bg-[#eb74a6]"},{type:"summary",label:"Summary",helper:"Wrap-up",icon:zt,accent:"from-[#48bca6] to-[#40a794]",tint:"bg-[#48bca6] text-white border-transparent",tabBg:"bg-[#48bca6]"}],ol=({lesson:t,lessonCompletionXP:s=10,practiceQuiz:l,practiceQuizCompleted:n=!1,practiceQuizScore:i,initialSection:c=0,nextContentLabel:r,onStartPractice:u,onBack:d,onComplete:h,onProgressUpdate:S,onTryItQuizComplete:m,onContinueLearning:M})=>{const{userProfile:p}=$t(),[x,N]=a.useState(0),[g,z]=a.useState(1),[k,R]=a.useState(!1),[P,F]=a.useState(null),[X,K]=a.useState(!1),[Y,ee]=a.useState(null),[D,me]=a.useState(!1),[ue]=a.useState(()=>`tiy-${Date.now()}`);a.useEffect(()=>{!X||Y||(me(!0),Yr({lessonId:t.id?.toString()||"unknown",lessonTitle:t.title,topic:t.title,subjectId:t.subjectId,competencyCode:t.competencyCode,questionCount:15}).then(H=>ee(H)).catch(H=>{console.error("[LessonViewer] Quiz generation failed:",H),K(!1)}).finally(()=>me(!1)))},[X,Y,t]);const[Se,Ce]=a.useState(!1),f={topic:t.title,subject:t.subject||"General Mathematics",quarter:t.quarter||1,lessonTitle:t.title,moduleId:t.subjectId,lessonId:t.id,competencyCode:t.competencyCode,learnerLevel:"Grade 11-12",storagePath:t.storagePath},{sections:q,isLoading:O,error:ae,retry:ie,sources:be,retrievalBand:ze,activeModel:Le,isOffline:_e}=sl(t.id,f,!0),[b,T]=a.useState(null);a.useEffect(()=>{if(q.length>0){const H=q.find(he=>he.type==="introduction");if(H?.title){const pe=H.title.replace(/^Introduction\s+(to|-|:|—)\s+/i,"").replace(/\s*[-:—]\s*Introduction$/i,"").replace(/\s+Introduction$/i,"").trim();pe&&pe.toLowerCase()!=="introduction"&&T(pe)}}},[q]),a.useEffect(()=>{q.length>0&&p?.uid&&t.id&&ka(p.uid,t.id,b||t.title).catch(()=>{})},[q.length,p?.uid,t.id,b,t.title]);const C=q.length||Nt.length;if(a.useEffect(()=>{c>=0&&c{const H=q.findIndex(he=>he.type==="try_it_yourself");c===-1&&H>=0&&N(H)},[q,c]),a.useEffect(()=>{const H=C>0?(x+1)/C*100:0;S?.(H)},[x,C,S]),O)return e.jsx(ll,{});if(ae&&q.length===0)return e.jsx(nl,{message:ae,onRetry:ie,isOffline:_e});const B=String(t.id||"").match(/\d+/);if(B&&B[0],X)return D||!Y?e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm",children:e.jsxs("div",{className:"bg-white rounded-2xl p-6 flex flex-col items-center gap-3 shadow-xl",children:[e.jsx("div",{className:"w-10 h-10 border-4 border-indigo-500 border-t-transparent rounded-full animate-spin"}),e.jsx("p",{className:"font-bold text-slate-700",children:"Generating Quiz..."})]})}):e.jsx(Xr,{questions:Y,lessonTitle:t.title,subject:t.subject||"General Mathematics",sessionId:ue,userId:p?.uid,onBack:()=>{K(!1),ee(null)},onComplete:H=>{m?.(H),Ce(!0),K(!1),ee(null)}});const I=q[x]||{type:"introduction",title:"Loading...",content:"Lesson content is loading. Please wait a moment."},te=()=>{xH+1)):(!l||n)&&R(!0)},xe=()=>{x>0&&(z(-1),N(H=>H-1))},ve=H=>{R(!1),h(void 0,void 0,H)},ye=!!(l&&!n||!Se),ge=Nt[x]||Nt[0],Ne=ge.icon,We=e.jsxs("div",{className:"fixed inset-0 z-50 flex flex-col bg-slate-50 overflow-hidden font-sans",children:[e.jsx("header",{className:"flex-none bg-transparent px-3 sm:px-6 pt-2 sm:pt-3 md:pt-4 pb-2 sm:pb-3 sm:py-4 relative z-40",children:e.jsxs("div",{className:"max-w-[90rem] mx-auto flex items-center justify-between gap-2 sm:gap-4",children:[e.jsxs("div",{className:"flex items-center gap-2 sm:gap-4 min-w-0 flex-1",children:[e.jsx("button",{onClick:d,className:"w-9 h-9 sm:w-10 sm:h-10 rounded-full bg-white border border-slate-200 hover:bg-slate-50 flex items-center justify-center text-slate-600 transition-colors flex-shrink-0 shadow-sm","aria-label":"Go back",children:e.jsx(Yt,{size:16})}),e.jsxs("div",{className:"min-w-0 flex flex-col justify-center flex-1",children:[e.jsxs("div",{className:"hidden sm:flex items-center gap-1.5 sm:gap-2 text-[9px] sm:text-[10px] font-bold text-slate-500 uppercase tracking-widest mb-0.5",children:[e.jsx($e,{size:10}),e.jsx("span",{children:"NOTEBOOK"}),Le&&e.jsx("span",{className:"text-slate-400 bg-slate-100 px-1.5 py-0.5 rounded font-mono",children:Le.split("/").pop()}),ze==="high"&&e.jsx("span",{className:"text-emerald-600 bg-emerald-50 px-1.5 py-0.5 rounded text-[10px] font-semibold border border-emerald-200",children:"DepEd Source"})]}),e.jsxs("div",{className:"flex sm:hidden items-center gap-1 text-[9px] font-bold text-slate-400 uppercase tracking-widest mb-0.5",children:[e.jsx($e,{size:9}),e.jsx("span",{children:"Notebook"}),ze==="high"&&e.jsx("span",{className:"text-emerald-600 bg-emerald-50 px-1 py-0.5 rounded text-[8px] font-semibold border border-emerald-200 leading-none",children:"DepEd"})]}),e.jsx("h1",{className:"font-bold text-slate-800 text-xs sm:text-sm truncate",children:t.title})]})]}),e.jsxs("div",{className:"flex items-center gap-2 sm:gap-4 flex-shrink-0",children:[e.jsxs("div",{className:"text-right hidden sm:block",children:[e.jsx("p",{className:"text-[10px] font-bold text-slate-500 uppercase tracking-wider",children:"Progress"}),e.jsxs("p",{className:"text-sm font-bold text-slate-800",children:[Math.round((x+1)/C*100),"%"]})]}),e.jsx("div",{className:"w-12 sm:w-24 md:w-32 h-1.5 sm:h-2 bg-slate-200 rounded-full overflow-hidden",children:e.jsx(E.div,{className:"h-full bg-[#7ec16d] rounded-full",animate:{width:`${(x+1)/C*100}%`},transition:{duration:.25}})})]})]})}),e.jsx("main",{className:"flex-1 overflow-hidden px-2 sm:px-5 pb-2 relative flex justify-center min-h-0",children:e.jsxs("div",{className:"w-full max-w-[90rem] h-full relative flex md:pl-16 pt-10 sm:pt-10 md:pt-0",children:[e.jsx("div",{className:"hidden md:flex absolute left-0 top-8 bottom-8 w-20 flex-col justify-between z-0 py-2",children:Nt.map((H,he)=>{const pe=he===x,Ue=H.icon;return e.jsxs("button",{onClick:()=>{z(he>x?1:-1),N(he)},className:_t("group relative flex items-center justify-start pl-4 rounded-l-[1.5rem] transition-all duration-300 shadow-sm border-r-0 flex-shrink-0",H.tabBg,pe?"w-24 h-20 -translate-x-4 shadow-xl z-20 brightness-105":"w-16 h-16 hover:w-24 hover:h-20 hover:-translate-x-4 hover:brightness-110 opacity-90 hover:opacity-100 z-10"),"aria-label":`Go to ${H.label} section`,children:[e.jsx("div",{className:_t("transition-all duration-300 rounded-xl",pe?"bg-white/30 p-2.5":"bg-white/20 p-2 group-hover:bg-white/30 group-hover:p-2.5"),children:e.jsx(Ue,{size:pe?24:20,className:"text-white transition-transform duration-300 group-hover:scale-110"})}),e.jsxs("div",{className:"absolute right-full mr-3 px-3 py-1.5 bg-slate-800 text-white text-xs font-bold rounded-lg opacity-0 group-hover:opacity-100 pointer-events-none transition-opacity whitespace-nowrap z-[100] shadow-xl border border-slate-700/50",children:[e.jsx("div",{className:"absolute top-1/2 -right-1 -translate-y-1/2 w-2 h-2 bg-slate-800 rotate-45 border-r border-t border-slate-700/50"}),H.label]})]},H.type)})}),e.jsx("div",{className:"md:hidden absolute left-0 right-0 top-0 z-30 bg-slate-100/95 backdrop-blur-sm",children:e.jsx("div",{className:"flex gap-0.8 overflow-x-auto [-ms-overflow-style:none] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden px-1",children:Nt.map((H,he)=>{const pe=he===x,Ue=H.icon;return e.jsxs("button",{onClick:()=>{z(he>x?1:-1),N(he)},className:_t("flex items-center gap-1.5 px-3 py-2 rounded-t-lg transition-all duration-200 shrink-0 text-[11px] font-bold touch-manipulation min-h-[2.5rem]",pe?`${H.tabBg} text-white shadow-md`:"bg-slate-200/80 text-slate-500"),children:[e.jsx(Ue,{size:14}),e.jsx("span",{children:H.label})]},H.type)})})}),e.jsxs("div",{className:_t("flex-1 min-w-0 rounded-none sm:rounded-lg shadow-2xl flex flex-col overflow-visible relative z-10 transition-colors duration-500",ge.tabBg),children:[e.jsxs("div",{className:"px-3 sm:px-6 py-2 sm:py-3.5 flex items-center gap-2 sm:gap-4 text-white",children:[e.jsx("div",{className:"bg-white/20 p-1 sm:p-2 rounded-lg sm:rounded-xl shrink-0",children:e.jsx(Ne,{size:16,className:"text-white"})}),e.jsxs("div",{className:"flex flex-col min-w-0",children:[e.jsx("h2",{className:"lesson-section-heading text-sm sm:text-xl md:text-2xl truncate",title:I.title,children:I.title}),e.jsx("p",{className:"text-white/90 text-[10px] sm:text-xs font-medium truncate mt-0.5 font-body",title:t.title,children:t.title})]})]}),e.jsxs("div",{className:"flex-1 min-h-0 bg-[#fdfdfd] rounded-lg sm:rounded-[1.5rem] m-1 mt-0 relative overflow-hidden shadow-inner flex flex-col",children:[e.jsx("div",{className:"absolute inset-0 pointer-events-none opacity-30",style:{backgroundImage:"linear-gradient(transparent 95%, #cbd5e1 95%)",backgroundSize:"100% 40px",backgroundPosition:"0 0"}}),e.jsx("div",{className:"absolute top-0 bottom-0 left-8 sm:left-12 md:left-16 w-[2px] bg-rose-300/60 pointer-events-none z-0"}),e.jsx("div",{className:"relative z-10 flex-1 min-h-0 overflow-y-auto px-3 sm:px-5 md:pl-20 md:pr-10 py-2 sm:py-6",children:e.jsx(Ze,{mode:"wait",children:e.jsxs(E.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},transition:{duration:.2},className:"space-y-4 sm:space-y-6",children:[e.jsx("div",{className:"bg-white/90 backdrop-blur-sm rounded-xl sm:rounded-[1.5rem] p-4 sm:p-6 md:p-8 shadow-sm border border-slate-100/50 font-body",children:e.jsx(il,{section:I,sectionIndex:x,onShowSolution:H=>F(P===H?null:H),expandedIndex:P,lesson:t,practiceQuiz:l,practiceQuizCompleted:n,practiceQuizScore:i,onStartPractice:u,lessonSpecificTopic:b,onStartTryItQuiz:()=>K(!0)})}),be.length>0&&(p?.role==="admin"||p?.role==="teacher")&&e.jsxs("details",{className:"rounded-xl border border-slate-200 bg-white/90 backdrop-blur-sm px-4 py-3 text-xs text-slate-500 shadow-sm",children:[e.jsxs("summary",{className:"cursor-pointer font-semibold text-slate-600 hover:text-slate-800",children:[be.length," source",be.length>1?"s":""," used"]}),e.jsx("div",{className:"mt-2 space-y-1 pl-2",children:be.slice(0,3).map((H,he)=>e.jsxs("p",{className:"font-mono truncate",children:[H.source_file," p.",H.page," (",Math.round((H.score||0)*100),"%)"]},he))})]})]},x)})},x)]})]})]})}),e.jsx("footer",{className:"bg-slate-50 border-t border-slate-100 px-3 sm:px-6 flex-shrink-0 relative z-50 w-full flex justify-center items-center py-1.5 sm:py-3",children:e.jsxs("div",{className:"w-full max-w-[90rem] flex flex-col items-center",children:[e.jsxs("div",{className:"flex items-center justify-center gap-4 sm:gap-8 w-full md:ml-16",children:[e.jsxs(qe,{onClick:xe,disabled:x===0,variant:"outline",className:"px-4 sm:px-5 py-2 sm:py-2 rounded-full font-bold text-xs sm:text-sm bg-white border-slate-200 text-slate-600 shadow-sm disabled:opacity-40 hover:bg-slate-50 transition-colors flex items-center gap-1 sm:gap-2 min-w-[2.5rem] min-h-[2.5rem] touch-manipulation",children:[e.jsx(Yt,{size:14}),e.jsx("span",{className:"hidden sm:inline",children:"Previous"})]}),e.jsxs("p",{className:"text-xs sm:text-sm text-slate-500 font-bold tabular-nums",children:[x+1," / ",C]}),e.jsx(qe,{onClick:te,disabled:x===C-1&&ye,className:"px-5 sm:px-7 py-2 sm:py-2 rounded-full font-bold text-xs sm:text-sm bg-[#7ec16d] text-white hover:bg-[#6ab359] shadow-md transition-colors disabled:opacity-40 flex items-center gap-1 sm:gap-2 min-w-[2.5rem] min-h-[2.5rem] touch-manipulation",children:x===C-1?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"hidden sm:inline",children:"Complete"}),e.jsx(st,{size:14})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"hidden sm:inline",children:"Next"}),e.jsx(tt,{size:14})]})})]}),x===C-1&&ye&&e.jsx("p",{className:"text-center text-[10px] sm:text-xs font-semibold text-amber-600 mt-2 sm:mt-3 md:ml-16",children:Se?"Complete the practice quiz first to unlock lesson completion.":"Complete the Try It Yourself quiz first to unlock lesson completion."})]})}),e.jsx(Ze,{children:k&&e.jsx(E.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"absolute inset-0 z-[100] flex items-center justify-center bg-slate-900/40 backdrop-blur-sm p-4",children:e.jsxs(E.div,{initial:{scale:.9,opacity:0},animate:{scale:1,opacity:1},className:"bg-white rounded-[2rem] p-8 max-w-sm w-full text-center shadow-2xl",children:[e.jsx("div",{className:"w-20 h-20 bg-[#7ec16d] rounded-full flex items-center justify-center mx-auto mb-5 shadow-lg",children:e.jsx(st,{size:40,className:"text-white"})}),e.jsx("h2",{className:"text-2xl font-black text-slate-800 mb-2",children:"Lesson Complete!"}),e.jsxs("p",{className:"text-slate-500 text-sm mb-6 leading-relaxed",children:["Great job finishing ",e.jsx("strong",{className:"text-slate-700",children:t.title}),"."]}),e.jsxs("div",{className:"bg-emerald-50 rounded-2xl p-4 mb-6 border border-emerald-100",children:[e.jsx("div",{className:"flex items-center justify-center mb-1",children:e.jsx(zt,{className:"text-[#7ec16d]",size:22})}),e.jsx("p",{className:"text-xs text-[#7ec16d] font-bold uppercase tracking-wider mb-0.5",children:"XP Earned"}),e.jsxs("p",{className:"text-3xl font-black text-[#7ec16d]",children:["+",s]})]}),e.jsxs("div",{className:"space-y-2.5",children:[e.jsx("button",{onClick:()=>ve(!0),disabled:ye,className:"w-full py-3 rounded-xl font-bold text-sm bg-[#1a85a4] text-white hover:bg-[#126b84] transition-colors disabled:opacity-40 disabled:cursor-not-allowed",children:r||"Continue to Next Lesson"}),e.jsx("button",{onClick:()=>ve(!1),className:"w-full py-3 rounded-xl font-bold text-sm bg-slate-100 text-slate-600 hover:bg-slate-200 transition-colors",children:"Back to Modules"})]})]})})})]}),Ee=document.getElementById("modal-root")||document.body;return Ws.createPortal(We,Ee)},cl={maxRetries:2,timeoutMs:9e4,baseBackoffMs:2e3},Bs=async t=>at("/api/practice/generate",{method:"POST",body:JSON.stringify(t)},cl),dl=async t=>at("/api/practice/submit",{method:"POST",body:JSON.stringify(t)}),ml=async t=>at(`/api/practice/stats/${t}`,{method:"GET"}),xl=({module:t,onBack:s,onEarnXP:l,isInQuizMode:n=!1,setIsInQuizMode:i})=>{const[r,u]=a.useState(null),{userProfile:d}=$t(),[h,S]=a.useState(null),[m,M]=a.useState(!1),[p,x]=a.useState(null);a.useEffect(()=>{if(!d?.uid)return;(async()=>{try{const[T,C]=await Promise.all([Ut(ht(Ke,"diagnosticResults",d.uid)),Ut(ht(Ke,"competencyProfiles",d.uid))]),B=T.exists()&&T.data()?.status==="completed",I=C.exists()&&(C.data()?.overallScore??0)>0;M(B||I)}catch{M(!1)}})()},[d?.uid]);const N=a.useRef(l);a.useEffect(()=>{N.current=l},[l]);const g=a.useRef(r);a.useEffect(()=>{g.current=r},[r]),a.useEffect(()=>{try{const b=sessionStorage.getItem(`mathpulse_module_${t.id}_selectedLesson`);if(b){const{lessonId:T}=JSON.parse(b),C=t.lessons.find(B=>B.id===T);C&&u({lesson:C,type:"lesson"})}}catch{}},[]),a.useEffect(()=>{if(r?.type==="lesson"&&r.lesson)try{sessionStorage.setItem(`mathpulse_module_${t.id}_selectedLesson`,JSON.stringify({lessonId:r.lesson.id}))}catch{}else if(r===null)try{sessionStorage.removeItem(`mathpulse_module_${t.id}_selectedLesson`)}catch{}},[r,t.id]);const z=a.useMemo(()=>{const b=Number(t.id.split("-").pop());return Number.isFinite(b)&&b>0?b:1},[t.id]),k=a.useMemo(()=>{const b=t.subjectId;return b||(Mt.find(C=>C.modules.some(B=>B.id===t.id))?.id??null)},[t.id]),R=["#1FA7E1","#9956DE","#75D06A","#FFB356","#7274ED","#FF8B8B","#6ED1CF","#FB96BB"];a.useMemo(()=>{const b=t.subjectAccentColor;if(b)return b;const C=(k?Mt.find(I=>I.id===k):null)?.modules?.findIndex(I=>I.id===t.id)??0,B=C>=0?C:0;return R[B%R.length]},[t,t.id,k]),a.useEffect(()=>{if(d?.uid)return Xt(d.uid,S)},[d?.uid]),a.useEffect(()=>{if(!r||r.type!=="quiz"||!d?.uid)return;let b=!1;const C=Mt.find(B=>B.modules.some(I=>I.id===t.id))?.title??"General Mathematics";return(async()=>{try{const B=await Bs({userId:d.uid,subject:C,competency:r.quiz.title.replace(/^(Practice Quiz|Module Quiz):\s*/i,""),difficulty:r.quiz.type==="module"?"Challenge":"Practice",count:r.quiz.questions||5});if(b)return;const I=B.questions.filter(te=>te.options?.length&&te.correct_index>=0&&te.correct_index({id:te.id||"q-"+xe,questionType:"multiple_choice",question:te.question,options:te.options,correctAnswer:te.options[te.correct_index],bloomLevel:te.bloom_level?.toLowerCase()||"understand",difficulty:"medium",topic:r.quiz.title,subject:C,points:10,explanation:te.explanation||""}));x(I)}catch(B){console.error("[ModuleDetailView] Quiz generation failed:",B);const I=r.quiz.questions||5,te=Array.from({length:I}).map((xe,ve)=>{const ye=Math.floor(Math.random()*20)+2,ge=Math.floor(Math.random()*20)+2,Ne=(ye+ge).toString();return{id:ve+1,type:"multiple-choice",question:`Compute: ${ye} + ${ge}`,options:[Ne,(ye*ge).toString(),Math.abs(ye-ge).toString(),(ye+ge+1).toString()],correctAnswer:Ne,explanation:`${ye} + ${ge} = ${Ne}`}});b||x(te)}})(),()=>{b=!0}},[r,d?.uid,t.id]);const P=a.useMemo(()=>k?h?.subjects?.[k]?.modulesProgress?.[t.id]??null:null,[t.id,k,h?.subjects]),[F,X]=a.useState(null),K=a.useMemo(()=>{const b=P?.lessonsCompleted??[];return new Set(b)},[P?.lessonsCompleted]),Y=a.useMemo(()=>{const b=P?.quizzesCompleted??[];return new Set(b)},[P?.quizzesCompleted]),ee=P?.lessonsCompleted?.length??t.lessons.filter(b=>b.completed).length,D=P?.quizzesCompleted?.length??t.quizzes.filter(b=>b.completed).length,me=P?.progress??t.progress,ue=t.lessons.length+t.quizzes.length,Se=ee+D;t.lessons.length&&ee/t.lessons.length*100,t.quizzes.length&&D/t.quizzes.length*100;const Ce=(b,T)=>{const C=h?.lessons?.[b]?.score;return typeof C=="number"&&Number.isFinite(C)?Math.max(0,Math.min(100,C)):T?100:0},f=a.useMemo(()=>{if(!ue)return 0;const b=t.lessons.reduce((C,B)=>{const I=K.has(B.id)||B.completed;return C+Ce(B.id,I)},0),T=D*100;return Math.round((b+T)/ue)},[K,D,t.lessons,t.quizzes.length,ue,h?.lessons]),q=me>0?me:f,O=a.useMemo(()=>{const b=t.quizzes.find(C=>C.type==="final"||/module\s+quiz|general\s+quiz/i.test(C.title));if(b)return b;const T=t.quizzes.find(C=>C.isStandalone===!0);return T||(t.quizzes.length?t.quizzes[0]:null)},[t.quizzes]),ae=a.useMemo(()=>{const b=new Map;t.lessons.forEach(C=>{b.set(C.id,[])});const T=t.lessons.length;return T===0||t.quizzes.forEach((C,B)=>{if(O?.id===C.id)return;const I=Math.min(B,T-1),te=t.lessons[I];if(!te)return;const xe=b.get(te.id)??[];xe.push(C),b.set(te.id,xe)}),b},[t.lessons,t.quizzes,O?.id]),ie=a.useMemo(()=>Math.max(1,Math.ceil(t.lessons.length/2)),[t.lessons.length]),be=a.useCallback(()=>{u(null),X(null)},[]),ze=a.useCallback(()=>{const b=g.current?.type==="lesson"?g.current.lesson:null;if(!b)return;const T={id:`${b.id}-practice`,title:`Practice Quiz: ${b.title}`,questions:Kr(),duration:b.duration,completed:!1,locked:!1,type:"practice"};X(b),u({type:"quiz",quiz:T})},[]),Le=a.useCallback((b,T,C)=>{const B=g.current;if(B?.type!=="lesson"||!B.lesson)return;const I=B.lesson,te=10;if(N.current?.(te,`Completed "${I.title}"`),d?.uid&&k&&(async()=>{try{await ta(d.uid,k,t.id,I.id,0,te),await os(d.uid,k,t.id,t.lessons.length,t.quizzes.length)}catch(xe){console.error("[LessonComplete] Failed to persist progress:",xe)}})(),C){const xe=t.lessons.findIndex(ve=>ve.id===I.id);xe!==-1&&xe0?u({type:"quiz",quiz:t.quizzes[0]}):u(null)}else u(null)},[k,t.id,t.lessons.length,t.quizzes.length]),_e=a.useCallback(b=>{if(!d?.uid||!g.current||g.current.type!=="lesson")return;const T=g.current.lesson.id;(async()=>{try{await sa(d.uid,T,b)}catch(C){console.warn("[ModuleDetailView] Failed to persist lesson progress:",C)}})()},[d?.uid,t.id]);if(r)if(r.type==="lesson"){const b=ae.get(r.lesson.id)?.[0]??null,T=b?Y.has(b.id)||b.completed:!1,C=t.lessons.findIndex(I=>I.id===r.lesson.id);let B;if(C!==-1&&C0){const I=t.quizzes[0];I.type==="module"?B="Take Mid-Module Checkpoint":I.type==="final"?B="Take Final Assessment":B="Start Practice Quiz"}return e.jsx(ol,{lesson:r.lesson,lessonCompletionXP:10,practiceQuiz:b,practiceQuizCompleted:T,initialSection:r.returnFromQuiz?-1:0,nextContentLabel:B,onBack:be,onStartPractice:ze,onProgressUpdate:_e,onComplete:Le})}else return p?e.jsx(qs,{quiz:{id:r.quiz.id,title:r.quiz.title,subject:Mt.find(b=>b.modules.some(T=>T.id===t.id))?.title||"Mathematics",difficulty:"Medium",questions:p.length,duration:r.quiz.duration||"15 min",xpReward:50,type:"practice",completed:r.quiz.completed,locked:!1,loadedQuestions:p,source:"ai_generated"},onClose:()=>{x(null),F?(u({type:"lesson",lesson:F,returnFromQuiz:!0}),X(null)):u(null),i&&i(!1)},onComplete:(b,T)=>{d?.uid&&k&&(async()=>{try{await aa(d.uid,k,t.id,r.quiz.id,b,[],0,T),await os(d.uid,k,t.id,t.lessons.length,t.quizzes.length),await Xt(d.uid,S)}catch(C){console.warn("[Quiz] Progress persist failed:",C)}l&&l(T??0,"Quiz Complete! +"+(T??0)+" XP")})()},studentId:d?.uid}):e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm",children:e.jsxs("div",{className:"bg-white rounded-2xl p-6 flex flex-col items-center gap-3 shadow-xl",children:[e.jsx(Ps,{size:36,className:"animate-spin text-indigo-600"}),e.jsx("p",{className:"font-bold text-slate-700",children:"Generating Quiz..."}),e.jsxs("p",{className:"text-sm text-slate-500",children:["AI is crafting questions for ",r.quiz.title]})]})});return e.jsxs("div",{className:"h-full overflow-y-auto scrollbar-hide px-4 md:px-6 lg:px-10 py-4 md:py-6 lg:py-8 relative",children:[e.jsx("div",{className:"relative mb-4 lg:mb-6 xl:mb-8 w-full lg:w-max",children:e.jsxs("button",{onClick:s,className:"flex items-center gap-2 px-4 py-2.5 rounded-full bg-white/80 backdrop-blur-xl border border-slate-200/60 text-slate-600 hover:text-indigo-600 font-bold text-sm tracking-wide transition-all hover:-translate-x-1 shadow-sm hover:shadow-md",children:[e.jsx(Yt,{size:18}),"Back"]})}),e.jsxs(E.div,{initial:{opacity:0,y:-20},animate:{opacity:1,y:0},className:`relative mb-6 lg:mb-8 rounded-[2rem] ${t.accentColor} shadow-[0_20px_40px_-15px_rgba(0,0,0,0.3)] shrink-0 overflow-hidden`,children:[e.jsx("div",{className:"absolute inset-0 bg-black/60 pointer-events-none z-0"}),e.jsx("div",{className:"absolute inset-0 opacity-10 pointer-events-none module-detail-grid-pattern"}),e.jsx("div",{className:"absolute top-0 right-0 w-[400px] h-[400px] bg-sky-500/20 blur-[100px] rounded-full pointer-events-none"}),e.jsxs("div",{className:"relative p-5 md:p-6 lg:p-8 flex flex-col md:flex-row md:items-center justify-between gap-3 md:gap-5",children:[e.jsxs("div",{className:"flex-1 text-white",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-2 md:mb-2.5",children:[e.jsxs("div",{className:"px-2.5 py-0.5 bg-white/10 backdrop-blur-md rounded-full text-[10px] font-black uppercase tracking-widest text-[#f8fafc] border border-white/20 shadow-sm flex items-center gap-1",children:[e.jsx(hs,{size:12})," Chapter ",t.id.split("-").pop()||"1"]}),e.jsxs("div",{className:"px-2.5 py-0.5 bg-white/10 backdrop-blur-md rounded-full text-[10px] font-black uppercase tracking-widest text-emerald-400 border border-emerald-400/30",children:["Lv ",z]})]}),e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("span",{className:"flex lg:hidden text-white/80 shrink-0",children:e.jsx($e,{size:18,strokeWidth:1.5})}),e.jsx("h1",{className:"text-lg md:text-2xl lg:text-3xl font-display font-black text-white tracking-[-0.02em] leading-tight",children:t.title})]}),e.jsx("p",{className:"text-slate-300 text-xs md:text-sm max-w-2xl font-medium leading-relaxed mb-3",children:t.description}),e.jsxs("div",{className:"bg-black/20 backdrop-blur-md rounded-xl p-2 md:p-3 border border-white/10 max-w-xl",children:[e.jsxs("div",{className:"flex justify-between items-end gap-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(zt,{size:16,className:"text-emerald-400"}),e.jsx("span",{className:"text-[11px] md:text-xs font-black text-white uppercase tracking-wider",children:"Module Mastery"})]}),e.jsxs("div",{className:"flex items-baseline gap-1.5",children:[e.jsxs("span",{className:"text-[10px] md:text-xs font-bold text-slate-400",children:[Se,"/",ue]}),e.jsxs("span",{className:"text-base md:text-lg font-black text-white shrink-0 leading-none",children:[Math.round(q),"%"]})]})]}),e.jsx("div",{className:"h-2 bg-black/40 rounded-full overflow-hidden shadow-inner ring-1 ring-white/10 p-0.5 mt-2",children:e.jsx(E.div,{initial:{width:0},animate:{width:`${q}%`},transition:{duration:1.5,ease:"easeOut",delay:.2},className:`h-full rounded-full relative ${q===100?"bg-gradient-to-r from-emerald-400 to-teal-300":t.accentColor}`,children:e.jsx("div",{className:"absolute inset-0 bg-[url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI4IiBoZWlnaHQ9IjgiPgo8cmVjdCB3aWR0aD0iOCIgaGVpZ2h0PSI4IiBmaWxsPSIjZmZmIiBmaWxsLW9wYWNpdHk9IjAuMSI+PC9yZWN0Pgo8L3N2Zz4=')] opacity-30 mix-blend-overlay"})})})]})]}),e.jsxs("div",{className:"hidden lg:flex w-32 h-32 bg-white/5 rounded-2xl border border-white/10 backdrop-blur-md items-center justify-center transform rotate-[-3deg] shadow-2xl relative group hover:rotate-0 transition-all duration-500 shrink-0",children:[e.jsx("div",{className:`absolute inset-0 opacity-40 rounded-2xl ${t.progress===100?"bg-gradient-to-br from-emerald-400 to-teal-600":t.accentColor}`}),q===100?e.jsx(Ts,{size:56,className:"text-white drop-shadow-xl z-10 scale-100 group-hover:scale-110 transition-transform duration-500",strokeWidth:1}):e.jsx($e,{size:56,className:"text-white drop-shadow-xl z-10 scale-100 group-hover:scale-110 transition-transform duration-500",strokeWidth:1}),e.jsx(E.div,{animate:{y:[-5,5,-5],rotate:[-10,10,-10]},transition:{duration:4,repeat:1/0},className:"absolute top-4 left-4 text-emerald-300 z-20",children:e.jsx(As,{size:16,fill:"currentColor"})}),e.jsx(E.div,{animate:{y:[5,-5,5],rotate:[10,-10,10]},transition:{duration:3.5,repeat:1/0},className:"absolute bottom-6 right-4 text-sky-300 z-20",children:e.jsx(gs,{size:18})})]})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto pr-2 pb-8 scrollbar-hide",children:e.jsxs("div",{className:"relative rounded-[2rem] border border-slate-200 bg-white/90 shadow-sm overflow-hidden",children:[e.jsx("div",{className:"absolute inset-0 pointer-events-none bg-[radial-gradient(circle_at_top_right,rgba(153,86,222,0.08),transparent_45%),radial-gradient(circle_at_bottom_left,rgba(31,167,225,0.08),transparent_45%)]"}),e.jsxs("div",{className:"relative z-10 px-4 sm:px-6 md:px-8 py-5 md:py-6 border-b border-slate-200/70 bg-white/70 backdrop-blur-sm flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("h2",{className:"font-display font-black text-xl md:text-2xl text-slate-800 flex items-center gap-3",children:[e.jsx($e,{size:24,className:"text-sky-500"}),"Study Journey"]}),e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsxs("div",{className:"text-xs md:text-sm font-bold bg-sky-100 text-sky-700 px-3 py-1 rounded-full shadow-sm border border-sky-200/50",children:["Lessons ",ee,"/",t.lessons.length]}),e.jsxs("div",{className:"text-xs md:text-sm font-bold bg-rose-100 text-rose-700 px-3 py-1 rounded-full shadow-sm border border-rose-200/50",children:["Quizzes ",D,"/",t.quizzes.length]})]})]}),e.jsxs("div",{className:"relative z-10 px-3 md:px-6 lg:px-8 py-4 md:py-6 space-y-4 md:space-y-5",children:[t.lessons.map((b,T)=>{const C=K.has(b.id)||b.completed,B=Ce(b.id,C),I=R[T%R.length];return e.jsxs(Ie.Fragment,{children:[e.jsxs(E.div,{initial:{opacity:0,y:14},animate:{opacity:1,y:0},transition:{delay:T*.05},className:`relative rounded-[1.5rem] border overflow-hidden group transition-all duration-500 mb-4 md:mb-6 ${b.locked?"border-slate-200 opacity-65 saturate-50":"border-slate-200/80 hover:border-slate-300 hover:shadow-[0_16px_40px_-15px_rgba(0,0,0,0.12)] hover:-translate-y-0.5"}`,children:[e.jsx("div",{className:"absolute top-0 left-0 right-0 h-[6px] z-20 bg-slate-100 overflow-hidden",children:e.jsx(E.div,{initial:{width:0},animate:{width:`${Math.max(2,B)}%`},transition:{duration:1.2,ease:"easeOut",delay:.1+T*.05},className:"h-full relative",style:{backgroundColor:I},children:e.jsx("div",{className:"absolute inset-0 bg-[url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI4IiBoZWlnaHQ9IjgiPgo8cmVjdCB3aWR0aD0iOCIgaGVpZ2h0PSI4IiBmaWxsPSIjZmZmIiBmaWxsLW9wYWNpdHk9IjAuMSI+PC9yZWN0Pgo8L3N2Zz4=')] opacity-30 mix-blend-overlay"})})}),e.jsx("div",{className:"absolute inset-0 bg-white transition-opacity duration-500 group-hover:opacity-90",style:{backgroundImage:`linear-gradient(to right, ${I}44 0%, ${I}11 50%, white 100%)`}}),e.jsx("div",{className:"absolute inset-0 opacity-[0.2] pointer-events-none",style:{backgroundImage:`radial-gradient(circle at 2px 2px, ${I} 1.5px, transparent 0)`,backgroundSize:"24px 24px"}}),e.jsx("div",{className:"absolute -top-12 -left-10 h-40 w-40 rounded-full blur-[32px] pointer-events-none transition-transform duration-700 group-hover:scale-[1.3] group-hover:translate-x-4",style:{backgroundColor:`${I}22`}}),e.jsx("div",{className:"absolute -bottom-8 right-8 h-32 w-32 rounded-full blur-2xl pointer-events-none transition-transform duration-700 group-hover:scale-125 group-hover:-translate-y-4",style:{backgroundColor:`${I}11`}}),e.jsx("div",{className:"absolute right-4 top-4 opacity-10 pointer-events-none transition-all duration-500 group-hover:rotate-12 group-hover:scale-110 drop-shadow-sm",style:{color:I},children:e.jsx(gs,{size:56,strokeWidth:1})}),e.jsx("div",{className:"absolute right-16 bottom-5 opacity-10 pointer-events-none transition-all duration-500 group-hover:-rotate-6 group-hover:-translate-y-2 drop-shadow-sm",style:{color:I},children:e.jsx($e,{size:40,strokeWidth:1})}),e.jsxs("div",{className:"relative z-10 p-3 md:p-5 pt-5 md:pt-6 space-y-3 md:space-y-4",children:[e.jsxs("button",{type:"button",onClick:()=>!b.locked&&u({lesson:b,type:"lesson"}),className:`w-full text-left flex flex-wrap items-center justify-between gap-2 md:gap-3 rounded-2xl px-3 md:px-5 py-3 md:py-4 transition shadow-sm ${b.locked?"cursor-not-allowed border border-slate-200 bg-white/70":"cursor-pointer bg-white hover:bg-slate-50"}`,children:[e.jsxs("div",{className:"flex items-center gap-2 md:gap-4 min-w-0",children:[e.jsx("div",{className:`w-10 h-10 md:w-12 md:h-12 rounded-full flex items-center justify-center shrink-0 transition-colors shadow-sm ${b.locked?"bg-slate-100 text-slate-400":"text-white"}`,style:b.locked?{}:C?{backgroundColor:"#0ea5e9"}:{backgroundColor:I},children:b.locked?e.jsx(ts,{size:16}):C?e.jsx(Fs,{size:20}):e.jsx(va,{size:18,className:"ml-0.5"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("p",{className:"text-[10px] md:text-[12px] font-black uppercase tracking-wider text-slate-500 mb-0.5",children:["Lesson ",T+1]}),e.jsx("h3",{className:"font-bold text-[14px] md:text-[18px] text-[#0a1628] leading-tight line-clamp-2",children:b.title})]})]}),e.jsx("div",{className:"flex items-center justify-end shrink-0",children:e.jsxs("span",{className:"inline-flex items-center gap-1 text-slate-500 text-[11px] md:text-sm font-semibold bg-slate-100/80 px-2 md:px-3 py-1 md:py-1.5 rounded-lg md:rounded-xl",children:[e.jsx(pt,{size:12}),b.duration]})})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 md:gap-3 px-0.5 md:px-1",children:[e.jsxs("button",{type:"button",className:"inline-flex items-center gap-1 rounded-full bg-white px-3 md:px-4 py-1 md:py-1.5 text-[11px] md:text-[12px] font-bold shadow-sm transition hover:-translate-y-0.5",style:{color:I},children:[e.jsx($e,{size:12})," Study Materials"]}),e.jsxs("button",{type:"button",className:"inline-flex items-center gap-1 rounded-full bg-white px-3 md:px-4 py-1 md:py-1.5 text-[11px] md:text-[12px] font-bold shadow-sm transition hover:-translate-y-0.5",style:{color:I},children:[e.jsx(hs,{size:12})," Quiz"]})]})]})]}),O&&T===ie-1&&e.jsxs(E.div,{initial:{opacity:0,y:16},animate:{opacity:1,y:0},transition:{delay:.15+T*.03},className:"mt-4 md:mt-6 mb-4 md:mb-6",children:[e.jsxs("div",{className:"flex items-center gap-2 md:gap-4 mb-4 md:mb-6",children:[e.jsx("div",{className:"flex-1 h-px bg-slate-200"}),e.jsx("span",{className:"text-[10px] md:text-xs font-bold text-indigo-400 uppercase tracking-widest text-center",children:"mid-module checkpoint"}),e.jsx("div",{className:"flex-1 h-px bg-slate-200"})]}),e.jsxs("div",{className:"relative rounded-[1.5rem] bg-[#533ab6] p-3 md:p-5 shadow-lg overflow-hidden group transition-all hover:shadow-xl hover:-translate-y-1",children:[e.jsx("div",{className:"absolute right-2 md:right-10 top-1/2 -translate-y-1/2 text-white/5 text-[80px] md:text-[140px] font-black font-display pointer-events-none group-hover:scale-110 transition-transform duration-500",children:"?"}),e.jsxs("div",{className:"relative z-10 flex flex-wrap items-center gap-3 md:gap-5",children:[e.jsx("div",{className:"w-12 h-12 md:w-14 md:h-14 rounded-[12px] md:rounded-[14px] bg-white/10 backdrop-blur-md border border-white/10 shrink-0 flex items-center justify-center shadow-inner",children:e.jsx(Qe,{size:22,className:"text-rose-400"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-[9px] md:text-[11px] font-black uppercase tracking-widest text-[#a3b1ee] mb-0.5 md:mb-1 drop-shadow-sm",children:"COMPETENCY CHECK · General Quiz"}),e.jsx("h3",{className:"font-display font-medium text-[16px] md:text-[22px] text-white leading-tight mb-1 md:mb-2 tracking-tight",children:O.title}),e.jsxs("p",{className:"text-[11px] md:text-xs font-semibold text-white/80 flex flex-wrap items-center gap-2 md:gap-3",children:[e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Kt,{size:11})," ",O.questions," Qs"]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(pt,{size:11})," ",O.duration]}),e.jsxs("span",{className:"inline-flex items-center gap-1 text-amber-300 drop-shadow-md",children:[e.jsx(Ve,{size:11,className:"fill-amber-300"})," +50 XP"]})]})]}),e.jsx("button",{type:"button",onClick:()=>!O.locked&&(u({quiz:O,type:"quiz"}),i&&i(!0)),className:`px-4 md:px-6 py-2 md:py-2.5 rounded-xl text-[11px] md:text-sm font-bold tracking-wider transition-all backdrop-blur-sm self-center shrink-0 ${O.locked?"bg-white/5 text-white/30 border border-white/10 cursor-not-allowed":m&&(Y.has(O.id)||O.completed)?"bg-white/20 text-white border border-white/40 hover:bg-white/30 shadow-sm":"bg-transparent text-white border border-white/40 hover:bg-white/10 shadow-sm"}`,children:m&&(Y.has(O.id)||O.completed)?"REVIEW":"START"})]})]})]})]},b.id)}),t.lessons.length===0&&O&&e.jsxs("div",{className:"relative rounded-[1.5rem] bg-[#533ab6] p-5 shadow-lg overflow-hidden group",children:[e.jsx("div",{className:"absolute right-4 md:right-10 top-1/2 -translate-y-1/2 text-white/5 text-[140px] font-black font-display pointer-events-none group-hover:scale-110 transition-transform duration-500",children:"?"}),e.jsxs("div",{className:"relative z-10 flex flex-wrap items-center justify-between gap-4 md:gap-5",children:[e.jsxs("div",{className:"flex items-center gap-4 flex-1",children:[e.jsx("div",{className:"w-14 h-14 rounded-[14px] bg-white/10 backdrop-blur-md border border-white/10 shrink-0 flex items-center justify-center shadow-inner",children:e.jsx(Qe,{size:28,className:"text-rose-400"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] md:text-[11px] font-black uppercase tracking-widest text-[#a3b1ee] mb-1 drop-shadow-sm",children:"COMPETENCY CHECK · General Quiz"}),e.jsx("h3",{className:"font-display font-medium text-[20px] md:text-[22px] text-white leading-tight mb-2 tracking-tight",children:O.title}),e.jsxs("p",{className:"text-xs font-semibold text-white/80 flex items-center gap-3",children:[e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Kt,{size:12})," ",O.questions," Qs"]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(pt,{size:12})," ",O.duration]}),e.jsxs("span",{className:"inline-flex items-center gap-1 text-amber-300 drop-shadow-md",children:[e.jsx(Ve,{size:12,className:"fill-amber-300"})," +50 XP"]})]})]})]}),e.jsx("button",{type:"button",onClick:()=>!O.locked&&(u({quiz:O,type:"quiz"}),i&&i(!0)),className:`px-6 py-2.5 rounded-xl text-xs md:text-sm font-bold tracking-wider transition-all backdrop-blur-sm self-center shrink-0 ${O.locked?"bg-white/5 text-white/30 border border-white/10 cursor-not-allowed":m&&(Y.has(O.id)||O.completed)?"bg-white/20 text-white border border-white/40 hover:bg-white/30 shadow-sm":"bg-transparent text-white border border-white/40 hover:bg-white/10 shadow-sm"}`,children:m&&(Y.has(O.id)||O.completed)?"REVIEW":"START"})]})]})]})]})})]})},ul={"Patterns, Relations, and Functions":{icon:Pt,bg:"bg-indigo-500"},"Financial Mathematics":{icon:_a,bg:"bg-emerald-500"},"Logic and Mathematical Reasoning":{icon:ra,bg:"bg-purple-500"},"Random Variables":{icon:Va,bg:"bg-orange-500"},"Normal Distribution":{icon:za,bg:"bg-sky-500"},"Sampling and Estimation":{icon:Ga,bg:"bg-teal-500"},"Hypothesis Testing":{icon:Za,bg:"bg-rose-500"},"Correlation and Regression":{icon:Ba,bg:"bg-amber-500"}};function pl(t){return ul[t]||{icon:Kt,bg:"bg-slate-500"}}const hl=({userId:t,onStartQuiz:s,searchQuery:l="",allowedSubjectIds:n,atRiskTopics:i=[]})=>{const{userProfile:c}=$t(),[r,u]=a.useState("all"),[d,h]=a.useState("Medium"),[S,m]=a.useState("all"),[M,p]=a.useState(null),[x,N]=a.useState(!1),[g,z]=a.useState(null),[k,R]=a.useState(null),P=a.useMemo(()=>!n||n.length===0?xs:xs.filter(f=>n.includes(f.id)),[n]),F=a.useMemo(()=>P.flatMap(f=>f.topics.map(q=>({id:q.id,name:q.name,unit:q.unit,subject:f.name,subjectId:f.id}))),[P]);a.useEffect(()=>{t&&(N(!0),ml(t).then(p).catch(console.error).finally(()=>N(!1)))},[t]);const X=`mathpulse_practice_completed_${t}`,[K,Y]=a.useState(0);a.useEffect(()=>{const f=()=>Y(ae=>ae+1),q=ae=>{ae.key===X&&Y(ie=>ie+1)},O=()=>Y(ae=>ae+1);return window.addEventListener("focus",f),window.addEventListener("storage",q),window.addEventListener("practice-completion-updated",O),()=>{window.removeEventListener("focus",f),window.removeEventListener("storage",q),window.removeEventListener("practice-completion-updated",O)}},[X]);const ee=a.useMemo(()=>{try{const f=localStorage.getItem(X);if(f)return new Map(JSON.parse(f))}catch{}return new Map},[X,K]),D=a.useMemo(()=>F.filter(f=>{const q=r==="all"||f.subject===r,O=!l||f.name.toLowerCase().includes(l.toLowerCase())||f.unit.toLowerCase().includes(l.toLowerCase())||f.subject.toLowerCase().includes(l.toLowerCase());let ae=!0;return S==="completed"?ae=ee.has(f.name.toLowerCase()):S==="recommended"&&(ae=i.some(ie=>f.name.toLowerCase().includes(ie.toLowerCase())||ie.toLowerCase().includes(f.name.toLowerCase()))),q&&O&&ae}),[F,r,l,S,ee,i]),me=M?.quizzesCompleted??0,ue=M?.totalXPEarned??c?.totalXP??0,Se=M?.averageScore??0,Ce=a.useCallback(async f=>{if(!(!t||g)){z(f.id);try{const q={Easy:"Practice",Medium:"Challenge",Hard:"Mastery"},O=await Bs({userId:t,subject:f.subject,competency:f.name,difficulty:q[d],count:5}),ae={id:O.session_id,title:`Practice Quiz: ${f.name} (AI)`,subject:f.subject,difficulty:d,questions:O.questions.length,duration:"10 min",xpReward:d==="Hard"?75:d==="Medium"?50:25,type:"practice",loadedQuestions:O.questions.map(ie=>({id:ie.id,questionType:"multiple_choice",question:ie.question,options:ie.options,correctAnswer:ie.options[ie.correct_index],bloomLevel:["remember","understand","apply","analyze"].includes(ie.bloomsLevel?.toLowerCase()||"")?ie.bloomsLevel.toLowerCase():"understand",difficulty:d.toLowerCase(),topic:f.name,subject:f.subject,points:10,explanation:ie.explanation})),generatedQuizId:O.session_id,source:"ai_generated",completed:!1,locked:!1};s?.(ae)}catch(q){console.error("Failed to generate practice quiz:",q)}finally{z(null)}}},[t,d,g,s]);return e.jsxs("div",{className:"px-4 sm:px-6 xl:px-10 py-4 sm:py-6",children:[e.jsxs("div",{className:"grid grid-cols-3 gap-2 sm:gap-4 mb-6",children:[e.jsxs(E.div,{whileHover:{scale:1.02},className:"bg-gradient-to-br from-sky-700 to-sky-500 rounded-xl sm:rounded-2xl p-3 sm:p-5 text-white shadow-lg",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between mb-1 sm:mb-3 gap-1 sm:gap-0",children:[e.jsxs("div",{className:"w-8 h-8 sm:w-12 sm:h-12 bg-white/20 rounded-lg sm:rounded-xl flex items-center justify-center shrink-0",children:[e.jsx(zt,{size:16,className:"sm:hidden"}),e.jsx(zt,{size:24,className:"hidden sm:block"})]}),e.jsx("span",{className:"text-xl sm:text-3xl font-bold",children:me})]}),e.jsx("p",{className:"text-[10px] sm:text-sm font-medium text-sky-100 leading-tight",children:"Quizzes Completed"})]}),e.jsxs(E.div,{whileHover:{scale:1.02},className:"bg-gradient-to-br from-rose-500 to-rose-600 rounded-xl sm:rounded-2xl p-3 sm:p-5 text-white shadow-lg",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between mb-1 sm:mb-3 gap-1 sm:gap-0",children:[e.jsxs("div",{className:"w-8 h-8 sm:w-12 sm:h-12 bg-white/20 rounded-lg sm:rounded-xl flex items-center justify-center shrink-0",children:[e.jsx(Ve,{size:16,className:"sm:hidden"}),e.jsx(Ve,{size:24,className:"hidden sm:block"})]}),e.jsx("span",{className:"text-xl sm:text-3xl font-bold",children:ue.toLocaleString()})]}),e.jsx("p",{className:"text-[10px] sm:text-sm font-medium text-cyan-100 leading-tight",children:"Total XP Earned"})]}),e.jsxs(E.div,{whileHover:{scale:1.02},className:"bg-gradient-to-br from-indigo-600 to-indigo-700 rounded-xl sm:rounded-2xl p-3 sm:p-5 text-white shadow-lg",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between mb-1 sm:mb-3 gap-1 sm:gap-0",children:[e.jsxs("div",{className:"w-8 h-8 sm:w-12 sm:h-12 bg-white/20 rounded-lg sm:rounded-xl flex items-center justify-center shrink-0",children:[e.jsx(Qe,{size:16,className:"sm:hidden"}),e.jsx(Qe,{size:24,className:"hidden sm:block"})]}),e.jsxs("span",{className:"text-xl sm:text-3xl font-bold",children:[Math.round(Se),"%"]})]}),e.jsx("p",{className:"text-[10px] sm:text-sm font-medium text-sky-100 leading-tight",children:"Average Score"})]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center gap-2 sm:gap-3 mb-6",children:[e.jsxs("select",{value:r,onChange:f=>u(f.target.value),className:"w-full sm:w-auto px-3 sm:px-4 py-2 sm:py-2.5 bg-white border-2 border-[#dde3eb] rounded-xl text-xs sm:text-sm font-bold text-[#0a1628] focus:border-indigo-600 focus:outline-none",children:[e.jsx("option",{value:"all",children:"All Subjects"}),P.map(f=>e.jsx("option",{value:f.name,children:f.name},f.id))]}),e.jsxs("div",{className:"flex items-center gap-1.5 sm:gap-2 bg-white rounded-xl p-1 shadow-sm",children:[e.jsx("span",{className:"px-2 text-xs font-bold text-slate-400",children:"Difficulty:"}),["Easy","Medium","Hard"].map(f=>e.jsx("button",{onClick:()=>h(f),className:`px-3 py-1.5 rounded-lg text-xs font-bold transition-all whitespace-nowrap ${d===f?f==="Easy"?"bg-green-500 text-white shadow-sm":f==="Medium"?"bg-orange-500 text-white shadow-sm":"bg-red-500 text-white shadow-sm":"text-[#5a6578] hover:bg-[#edf1f7]"}`,children:f},f))]}),e.jsx("div",{className:"flex items-center gap-1.5 sm:gap-2 bg-white rounded-xl p-1 shadow-sm",children:[["all","All"],["completed","Completed"],["recommended","Recommended"]].map(([f,q])=>e.jsx("button",{onClick:()=>m(f),className:`px-3 py-1.5 rounded-lg text-xs font-bold transition-all whitespace-nowrap ${S===f?f==="completed"?"bg-emerald-500 text-white shadow-sm":f==="recommended"?"bg-purple-500 text-white shadow-sm":"bg-indigo-500 text-white shadow-sm":"text-[#5a6578] hover:bg-[#edf1f7]"}`,children:q},f))})]}),g&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm",children:e.jsxs("div",{className:"bg-white rounded-2xl p-6 flex flex-col items-center gap-3 shadow-xl",children:[e.jsx(Ps,{size:36,className:"animate-spin text-indigo-600"}),e.jsx("p",{className:"font-bold text-slate-700",children:"Generating Quiz..."}),e.jsx("p",{className:"text-sm text-slate-500",children:"AI is crafting questions from curriculum"})]})}),e.jsxs("div",{className:"pr-2 pb-4 rounded-[2rem] border border-slate-200 shadow-inner relative",style:{backgroundImage:"radial-gradient(#CBD5E1 1px, transparent 1px)",backgroundSize:"24px 24px",backgroundPosition:"-12px -12px",backgroundColor:"#FAFAFA"},children:[e.jsx("div",{className:"absolute left-12 top-0 bottom-0 w-0.5 bg-rose-200/60 pointer-events-none z-0"}),e.jsx("div",{className:"absolute left-[54px] top-0 bottom-0 w-px bg-rose-100/40 pointer-events-none z-0"}),e.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4 lg:gap-5 p-4 md:p-6 relative z-10",children:D.map((f,q)=>e.jsx(E.div,{initial:{opacity:0,x:-20},animate:{opacity:1,x:0},transition:{delay:q*.03},onClick:()=>Ce(f),className:`bg-white/90 backdrop-blur-sm rounded-2xl p-4 md:p-5 border-2 relative select-none transition-all duration-300 ${g===f.id?"border-indigo-300 opacity-80 cursor-wait":g?"border-slate-200 opacity-60 cursor-not-allowed":"border-slate-200 shadow-sm hover:border-indigo-300 hover:shadow-md cursor-pointer"} group`,children:e.jsxs("div",{className:"flex items-center justify-between gap-3 md:gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3 md:gap-4 flex-1",children:[(()=>{const{icon:O,bg:ae}=pl(f.unit);return e.jsxs("div",{className:`w-10 h-10 md:w-12 md:h-12 rounded-xl flex items-center justify-center shrink-0 shadow-sm transform group-hover:rotate-3 transition-transform ${ae} text-white relative`,children:[e.jsx(O,{size:18}),ee.has(f.name.toLowerCase())&&e.jsx("div",{className:"absolute -top-1 -right-1 w-4 h-4 bg-emerald-500 rounded-full flex items-center justify-center border-2 border-white",children:e.jsx(st,{size:10,className:"text-white"})})]})})(),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-1",children:[e.jsxs("span",{className:`px-2 py-0.5 rounded-[6px] text-[9px] md:text-[10px] font-black uppercase tracking-wider ${d==="Easy"?"bg-green-100 text-green-700":d==="Medium"?"bg-orange-100 text-orange-700":"bg-red-100 text-red-700"}`,children:["AI ","•"," ",d]}),ee.has(f.name.toLowerCase())&&e.jsxs("span",{className:"px-2 py-0.5 rounded-[6px] text-[9px] md:text-[10px] font-black uppercase tracking-wider bg-emerald-100 text-emerald-700",children:["Best: ",ee.get(f.name.toLowerCase())?.bestScore,"%"]}),e.jsx("span",{className:"w-1.5 h-1.5 md:w-2 md:h-2 rounded-full bg-emerald-500 animate-pulse"})]}),e.jsx("h3",{className:"font-bold text-[14px] md:text-[16px] leading-tight mb-1 md:mb-1.5 text-[#0a1628] transition-colors",children:f.name}),e.jsxs("p",{className:"text-[11px] md:text-[12px] text-slate-500 mb-1.5 line-clamp-1",children:[f.subject," — ",f.unit]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 md:gap-3 text-[11px] md:text-[12px] font-bold text-slate-400",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx($e,{size:12})," 5 Qs"]}),e.jsx("span",{className:"hidden sm:inline",children:"•"}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(pt,{size:12})," 10 min"]}),e.jsx("span",{className:"hidden sm:inline",children:"•"}),e.jsxs("span",{className:"flex items-center gap-1 text-rose-500",children:[e.jsx(Ts,{size:12})," +",d==="Hard"?75:d==="Medium"?50:25," XP"]})]})]})]}),e.jsxs("div",{className:"shrink-0 flex flex-col items-center gap-1.5",children:[e.jsx("div",{className:`px-3 py-1.5 md:px-4 md:py-2 rounded-xl text-[11px] md:text-[12px] font-black uppercase tracking-wider shadow-sm transition-all ${g===f.id?"bg-indigo-100 text-indigo-600":ee.has(f.name.toLowerCase())?"bg-orange-500 text-white group-hover:bg-orange-600 shadow-orange-200":"bg-indigo-500 text-white group-hover:bg-indigo-600 shadow-indigo-200"}`,children:g===f.id?"Loading...":ee.has(f.name.toLowerCase())?"Retry":"Start"}),ee.has(f.name.toLowerCase())&&e.jsxs("button",{onClick:O=>{O.stopPropagation();const ae=ee.get(f.name.toLowerCase());R({topic:f.name,items:ae?.history||[]})},className:"flex items-center gap-1 px-2 py-1 rounded-lg text-[10px] font-bold text-slate-400 hover:text-indigo-600 hover:bg-indigo-50 transition-colors",children:[e.jsx(Sa,{size:11})," History"]})]})]})},f.id))}),D.length===0&&e.jsxs("div",{className:"flex flex-col items-center justify-center h-64 text-slate-500 relative z-10",children:[e.jsx(Qe,{size:48,className:"mb-3"}),e.jsx("p",{className:"font-medium",children:"No topics found"}),e.jsx("p",{className:"text-sm",children:"Try adjusting your filters or search query"})]})]}),e.jsx(Ze,{children:k&&e.jsx(E.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-[200] flex items-center justify-center p-4 bg-black/50 backdrop-blur-sm",onClick:()=>R(null),children:e.jsxs(E.div,{initial:{scale:.9,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.9,opacity:0},onClick:f=>f.stopPropagation(),className:"bg-white rounded-2xl p-6 max-w-md w-full shadow-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h3",{className:"text-lg font-black text-slate-800",children:"Quiz History"}),e.jsx("button",{onClick:()=>R(null),className:"p-1.5 rounded-full hover:bg-slate-100",children:e.jsx(Ye,{size:18,className:"text-slate-400"})})]}),e.jsx("p",{className:"text-sm text-slate-500 mb-4",children:k.topic}),k.items.length===0?e.jsx("p",{className:"text-center text-slate-400 py-8 text-sm",children:"No history found for this topic."}):e.jsx("div",{className:"space-y-3",children:k.items.map((f,q)=>e.jsxs("div",{className:"flex items-center justify-between p-3 bg-slate-50 rounded-xl border border-slate-100",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-bold text-slate-700",children:new Date(f.date).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}),e.jsxs("p",{className:"text-xs text-slate-400",children:[f.difficulty," difficulty"]})]}),e.jsxs("div",{className:`text-lg font-black ${f.score>=80?"text-emerald-600":f.score>=50?"text-amber-600":"text-rose-600"}`,children:[f.score,"%"]})]},q))})]})})})]})},fl=` + @keyframes head-sway { + 0%, 100% { transform: rotate(-2deg) translateY(0); } + 50% { transform: rotate(2deg) translateY(-2px); } + } + @keyframes horn-left-wiggle { + 0%, 100% { transform: rotate(-4deg); } + 50% { transform: rotate(4deg); } + } + @keyframes horn-right-wiggle { + 0%, 100% { transform: rotate(4deg); } + 50% { transform: rotate(-4deg); } + } + @keyframes blink { + 0%, 90%, 100% { transform: scaleY(1); } + 95% { transform: scaleY(0.1); } + } + @keyframes mouth-talk { + 0%, 100% { transform: scaleY(1) scaleX(1); } + 25% { transform: scaleY(1.1) scaleX(0.98); } + 50% { transform: scaleY(0.9) scaleX(1.02); } + 75% { transform: scaleY(1.05) scaleX(0.98); } + } + .animate-head-sway { + transform-origin: 50% 75%; + animation: head-sway 4s ease-in-out infinite; + } + .animate-horn-left { + transform-origin: 50% 45%; + animation: horn-left-wiggle 4s ease-in-out infinite; + } + .animate-horn-right { + transform-origin: 50% 45%; + animation: horn-right-wiggle 4s ease-in-out infinite; + } + .animate-blink { + transform-origin: 50% 45%; + animation: blink 3.7s ease-in-out infinite; + } + .animate-mouth { + transform-origin: 50% 55%; + animation: mouth-talk 3s ease-in-out infinite; + } +`,Ss=({assessmentDismissed:t,initialAssessmentCompleted:s})=>{const l="absolute inset-0 w-full h-full object-contain",[n,i]=a.useState(!1);a.useEffect(()=>{t&&!s&&!sessionStorage.getItem("mathpulse_assessment_reminder_shown")?i(!0):i(!1)},[t,s]);const c=()=>{sessionStorage.setItem("mathpulse_assessment_reminder_shown","true"),i(!1),window.dispatchEvent(new CustomEvent("mathpulse:open-assessment"))};return e.jsxs(e.Fragment,{children:[e.jsx("style",{children:fl}),e.jsxs("div",{className:"relative w-full h-[250px] flex items-end justify-center drop-shadow-sm select-none pointer-events-none",children:[n&&e.jsxs(E.div,{initial:{opacity:0,scale:.8,x:10},animate:{opacity:1,scale:1,x:0},className:"absolute top-0 right-0 z-50 max-w-[180px] bg-white rounded-2xl shadow-lg border border-[#dde3eb] p-3 cursor-pointer pointer-events-auto",onClick:c,children:[e.jsx("p",{className:"text-[11px] font-bold text-[#0a1628] leading-snug",children:"Psst! Complete your assessment for a personalized path!"}),e.jsxs("div",{className:"mt-1.5 flex items-center gap-1",children:[e.jsx("div",{className:"w-1.5 h-1.5 bg-purple-500 rounded-full animate-pulse"}),e.jsx("span",{className:"text-[10px] text-[#5a6578] font-medium",children:"Tap to start"})]}),e.jsx("div",{className:"absolute -bottom-2 left-4 w-3 h-3 bg-white border-r border-b border-[#dde3eb] rotate-45"})]}),e.jsx("img",{src:"/mascot/modules_avatar_body.png",alt:"Desk setup",className:`${l} z-10`}),e.jsxs("div",{className:`${l} z-20 animate-head-sway`,children:[e.jsx("img",{src:"/mascot/modules_left_horn.png",alt:"Left Horn",className:`${l} z-0 animate-horn-left`}),e.jsx("img",{src:"/mascot/modules_right_horn.png",alt:"Right Horn",className:`${l} z-0 animate-horn-right`}),e.jsx("img",{src:"/mascot/modules_head.png",alt:"Mascot Head",className:`${l} z-[1]`}),e.jsx("img",{src:"/mascot/modules_eyes.png",alt:"Eyes",className:`${l} z-[2] animate-blink`}),e.jsx("img",{src:"/mascot/modules_mouth.png",alt:"Mouth",className:`${l} z-[3] animate-mouth`})]})]})]})},zs={common:"bg-slate-100 text-slate-500",rare:"bg-blue-50 text-blue-500",epic:"bg-amber-50 text-amber-500"},_s=["bg-[#1FA7E1]/80 text-white","bg-[#9956DE]/80 text-white","bg-[#FFB356]/90 text-white","bg-[#7274ED]/80 text-white","bg-[#1FA7E1]/80 text-white","bg-[#9956DE]/80 text-white","bg-gradient-to-r from-[#FFB356] to-[#FF8C00] text-white"],bl=({isOpen:t,onClose:s,onClaim:l,weekRewards:n,todayReward:i,canClaim:c,isClaiming:r,claimedDays:u,currentDayIndex:d,timeUntilReset:h})=>{const[S,m]=a.useState(!1);if(!t)return null;const M=()=>{if(!c||S)return;m(!0),i?.rarity==="epic"?us({particleCount:150,spread:80,origin:{y:.6},colors:["#FFD700","#FFA500","#FF8C00","#FF6B6B","#4ade80"]}):us({particleCount:100,spread:70,origin:{y:.6},colors:["#FFD700","#FFA500","#FF8C00"]}),setTimeout(()=>{m(!1),l()},1200)},p=R=>R+1,x=R=>R===d,N=R=>u.includes(R),g=R=>R>d,z=n.slice(0,6),k=n[6];return e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4 sm:p-8",children:[e.jsx(Ze,{children:t&&e.jsx(E.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"absolute inset-0 bg-slate-900/60 backdrop-blur-sm",onClick:s})}),e.jsxs(E.div,{initial:{scale:.9,opacity:0,y:20},animate:{scale:1,opacity:1,y:0},exit:{scale:.9,opacity:0,y:20},className:"relative w-full max-w-[420px] bg-[#f7f9fc] rounded-3xl border border-[#dde3eb] shadow-2xl flex flex-col items-center p-5 overflow-visible",children:[e.jsxs("div",{className:"absolute -top-6 w-[85%] h-12 bg-gradient-to-r from-[#9956DE] via-[#7274ED] to-[#1FA7E1] rounded-xl shadow-lg flex items-center justify-center z-20",children:[e.jsx("div",{className:"absolute -left-2.5 -z-10 w-5 h-8 bg-[#633299] rounded-l-full rotate-12 top-1.5"}),e.jsx("div",{className:"absolute -right-2.5 -z-10 w-5 h-8 bg-[#10709b] rounded-r-full -rotate-12 top-1.5"}),e.jsx("h2",{className:"text-white font-black text-lg tracking-wide uppercase drop-shadow-sm font-display",children:"Daily Rewards"})]}),e.jsx("button",{onClick:s,className:"absolute -right-3 -top-3 w-8 h-8 bg-white hover:bg-slate-100 border border-slate-200 text-slate-500 hover:text-slate-800 rounded-full flex items-center justify-center z-30 shadow-md transition-transform hover:scale-105 active:scale-95",children:e.jsx(Ye,{size:16,strokeWidth:3})}),e.jsxs("div",{className:"mt-6 mb-2 text-center w-full",children:[e.jsx("h3",{className:"text-xl font-bold text-slate-800 font-display mt-2",children:"Welcome Back!"}),e.jsx("p",{className:"text-slate-500 font-medium text-xs mt-0.5",children:"Claim your daily reward for today."})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 w-full mb-5 relative z-10",children:[z.map((R,P)=>{const F=p(P),X=N(P),K=x(P),Y=g(P);return e.jsxs("div",{className:`relative rounded-xl flex flex-col overflow-hidden border-[1.5px] transition-all ${K&&!X?"border-amber-400 shadow-[0_0_15px_rgba(251,191,36,0.25)] scale-105 z-10 bg-amber-50":X?"border-[#dde3eb] bg-slate-200/50":"border-[#dde3eb] bg-white"}`,children:[e.jsxs("div",{className:`py-0.5 text-center font-black text-[10px] uppercase tracking-wider ${K&&!X?"bg-amber-400 text-amber-900":_s[P]}`,children:["Day ",F]}),e.jsx("div",{className:"absolute top-5 right-1 z-10",children:e.jsx("span",{className:`text-[8px] font-bold uppercase px-1 rounded ${zs[R.rarity]}`,children:R.rarity})}),e.jsxs("div",{className:"flex-1 p-2 flex flex-col items-center justify-center relative min-h-[75px]",children:[X&&e.jsxs(E.div,{initial:{scale:0},animate:{scale:1},transition:{type:"spring",bounce:.5},className:"absolute inset-0 flex items-center justify-center z-20 pointer-events-none",children:[e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsx("div",{className:"w-12 h-12 rounded-full bg-emerald-200/50"})}),e.jsxs("div",{className:"relative w-14 h-14 rounded-full border-[3px] border-emerald-500 bg-emerald-100 flex items-center justify-center transform -rotate-12 shadow-lg",children:[e.jsx(Fs,{className:"w-8 h-8 text-emerald-600"}),e.jsx("div",{className:"absolute -bottom-2.5 left-1/2 -translate-x-1/2 bg-emerald-500 rounded-md px-2 py-0.5 border-2 border-emerald-300 shadow-md",children:e.jsx("span",{className:"text-[9px] font-black text-white uppercase tracking-wider leading-none whitespace-nowrap",children:"Claimed"})})]})]}),Y&&e.jsx("div",{className:"absolute top-1 right-1 bg-slate-200 rounded-full p-0.5 z-10",children:e.jsx(ts,{size:8,className:"text-slate-400"})}),e.jsxs("div",{className:`flex flex-col items-center transition-all w-full ${X?"opacity-30 grayscale":""}`,children:[e.jsx("div",{className:"w-10 h-10 rounded-full flex items-center justify-center border-2 mb-1",style:{backgroundColor:R.color+"20",borderColor:R.color+"40"},children:e.jsx("span",{className:"text-lg",children:R.icon})}),e.jsx("div",{className:`font-black text-xs leading-none mt-0.5 text-center ${K?"text-amber-600":X?"text-slate-500":"text-slate-600"}`,children:R.label})]})]})]},R.id)}),k&&e.jsxs("div",{className:`col-span-3 relative rounded-xl flex flex-col overflow-hidden border-[1.5px] transition-all mt-1 ${x(6)&&!N(6)?"border-amber-400 shadow-[0_0_20px_rgba(251,191,36,0.3)] scale-[1.02] z-10 bg-amber-50":N(6)?"border-[#dde3eb] bg-slate-200/50":"border-[#dde3eb] bg-white"}`,children:[e.jsx("div",{className:`py-1 text-center font-black text-[10px] uppercase tracking-widest ${x(6)&&!N(6)?"bg-amber-400 text-amber-900":_s[6]}`,children:"Day 7 • Epic Reward"}),e.jsx("div",{className:"absolute top-6 right-2 z-10",children:e.jsx("span",{className:`text-[8px] font-bold uppercase px-1.5 py-0.5 rounded ${zs[k.rarity]}`,children:k.rarity})}),e.jsxs("div",{className:"flex items-center justify-center gap-5 p-3 relative",children:[N(6)&&e.jsxs(E.div,{initial:{scale:0},animate:{scale:1},transition:{type:"spring",bounce:.5},className:"absolute inset-0 flex items-center justify-center z-20 pointer-events-none",children:[e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsx("div",{className:"w-16 h-16 rounded-full bg-rose-200/50"})}),e.jsxs("div",{className:"relative w-20 h-20 rounded-full border-[4px] border-rose-500 bg-rose-100 flex items-center justify-center transform rotate-12 shadow-lg",children:[e.jsx("img",{src:"/avatar/avatar_icon.png",alt:"Claimed",className:"w-14 h-14 object-contain drop-shadow-md"}),e.jsx("div",{className:"absolute -bottom-3 left-1/2 -translate-x-1/2 bg-rose-500 rounded-md px-2.5 py-1 border-2 border-rose-300 shadow-md",children:e.jsx("span",{className:"text-[10px] font-black text-white uppercase tracking-wider leading-none whitespace-nowrap",children:"Claimed"})})]})]}),e.jsxs("div",{className:`flex items-center justify-center gap-5 w-full transition-all ${N(6)?"opacity-30 grayscale":""}`,children:[e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("div",{className:"w-12 h-12 rounded-full flex items-center justify-center border-2 shadow-sm mb-0.5",style:{backgroundColor:k.color+"20",borderColor:k.color+"40"},children:e.jsx("span",{className:"text-2xl",children:k.icon})}),e.jsx("span",{className:`font-black text-sm ${x(6)?"text-amber-600":"text-slate-600"}`,children:k.label})]}),k.rarity==="epic"&&e.jsxs("div",{className:"relative mt-1",children:[e.jsx("div",{className:"w-14 h-14 bg-purple-50 rounded-xl flex items-center justify-center border-2 border-purple-200 shadow-sm",children:e.jsx(Ma,{className:"w-8 h-8 text-purple-500 drop-shadow-md"})}),e.jsx("div",{className:"absolute -right-5 -bottom-4 w-14 h-14 bg-white rounded-xl p-1 border-2 border-amber-300 shadow-lg transform rotate-[-5deg]",children:e.jsx("img",{src:"/avatar/crown_thumbnail.png",alt:"Crown",className:"w-full h-full object-contain drop-shadow-md"})})]})]})]})]})]}),e.jsxs("div",{className:"mb-3 flex items-center gap-2 text-xs text-slate-400",children:[e.jsx(pr,{size:14}),e.jsx("span",{className:"font-mono font-medium",children:h}),e.jsx("span",{children:"until next reset"})]}),e.jsx(E.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:M,disabled:!c||r||S,className:`w-[85%] py-3 rounded-full font-black text-base tracking-wide uppercase shadow-lg transition-all mt-2 ${!c||r||S?"bg-slate-200 text-slate-400 cursor-not-allowed border border-slate-300":"bg-gradient-to-r from-[#FFB356] to-[#FF8C00] text-white hover:from-[#FFA500] hover:to-[#FF7F00] border-b-4 border-[#e67e00]"}`,children:r||S?"Claiming...":c?"Claim!":"Claimed"})]})]})};function gl(t){const[s,l]=a.useState({difficulty:"normal",loading:!0});return a.useEffect(()=>{if(!t){l({difficulty:"normal",loading:!1});return}const n=ht(Ke,"users",t);return es(n,c=>{if(!c.exists()){l({difficulty:"normal",loading:!1});return}const u=c.data()?.moduleDifficulty||"normal";l({difficulty:["normal","easier","remedial"].includes(u)?u:"normal",loading:!1})},c=>{console.error("[useModuleDifficulty] snapshot error:",c),l({difficulty:"normal",loading:!1})})},[t]),s}function yl(t,s){return s==="normal"?t:s==="easier"?t.filter(l=>{const n=l.tags||[],i=l.difficulty||"";return n.some(c=>["foundation","basic","introductory"].includes(c.toLowerCase()))||["foundation","basic","introductory"].includes(i.toLowerCase())||!n.includes("advanced")&&!i.toLowerCase().includes("advanced")}):s==="remedial"?t.filter(l=>{const n=l.tags||[],i=l.difficulty||"";return n.some(c=>["remedial","review","catch-up"].includes(c.toLowerCase()))||["remedial","review","catch-up"].includes(i.toLowerCase())}):t}const wl=new Set([7,14,30,60,100]),Ct={lastClaimedDate:"",lastClaimedWeekSeed:0,claimedDays:[],currentStreak:0,longestStreak:0,totalClaimed:0,hintTokens:0,streakShields:0,activeMultiplier:null};function jl(t){if(t<=0)return"00:00:00";const s=Math.floor(t/1e3),l=Math.floor(s/3600),n=Math.floor(s%3600/60),i=s%60;return`${String(l).padStart(2,"0")}:${String(n).padStart(2,"0")}:${String(i).padStart(2,"0")}`}function vl(){const t=as();return t.setDate(t.getDate()-1),ss(t)}function Hs(t){return t?new Date(t.expiresAt).getTime()>Date.now():!1}function Qs(t){return ht(Ke,"users",t,"dailyRewards",t)}function Nl(t){return ht(Ke,"users",t)}async function Ms(t){try{const s=Qs(t),l=await Ut(s);if(!l.exists())return{...Ct};const n=l.data(),i=rs();return n.lastClaimedWeekSeed&&n.lastClaimedWeekSeed!==i?{...n,claimedDays:[],lastClaimedWeekSeed:i}:{...Ct,...n,activeMultiplier:n.activeMultiplier&&Hs(n.activeMultiplier)?n.activeMultiplier:null}}catch(s){return console.error("[dailyRewardService] Error getting state:",s),{...Ct}}}function kl(t){const s=ss();return t.lastClaimedDate!==s}async function Cl(t){const s=ss(),l=rs(),n=ls(),c=ns()[n];if(!c)throw new Error(`No reward found for day index ${n}`);try{const r=await Gs(Ke,async d=>{const h=Qs(t),S=Nl(t),m=await d.get(h),M=await d.get(S);let p;if(m.exists()?p={...Ct,...m.data()}:(p={...Ct,lastClaimedWeekSeed:l},d.set(h,p)),p.lastClaimedWeekSeed!==l&&(p.claimedDays=[],p.lastClaimedWeekSeed=l),p.lastClaimedDate===s)return{code:"ALREADY_CLAIMED",state:p};let x=p.currentStreak,N=!1;if(!p.lastClaimedDate||p.currentStreak===0)x=1;else{const P=vl();p.lastClaimedDate===P?x=p.currentStreak+1:p.streakShields>0?(p.streakShields-=1,x=p.currentStreak+1,N=!0):x=1}const g=Math.max(p.longestStreak,x);let z=0,k=1;switch(c.type){case"xp":{const P=typeof c.value=="number"?c.value:parseInt(c.value,10)||0;k=Hs(p.activeMultiplier)?p.activeMultiplier?.multiplier??1:1,z=Math.floor(P*k);break}case"hint_token":{const P=typeof c.value=="number"?c.value:parseInt(c.value,10)||0;p.hintTokens+=P;break}case"streak_shield":{const P=typeof c.value=="number"?c.value:parseInt(c.value,10)||0;p.streakShields+=P;break}case"xp_multiplier":{const P=typeof c.value=="number"?c.value:parseInt(c.value,10)||60,F=c.id.includes("2")?2:1.5,X=new Date;X.setMinutes(X.getMinutes()+P),p.activeMultiplier={multiplier:F,expiresAt:X.toISOString()};break}case"badge_unlock":break}const R=[...p.claimedDays,n];return p.lastClaimedDate=s,p.currentStreak=x,p.longestStreak=g,p.totalClaimed+=1,d.set(h,p,{merge:!0}),M.exists()&&d.update(S,{hintTokens:p.hintTokens,streakShields:p.streakShields,activeMultiplier:p.activeMultiplier,lastClaimedDate:p.lastClaimedDate,updatedAt:Xs()}),{code:"SUCCESS",state:p,newClaimedDays:R,newStreak:x,newLongestStreak:g,xpAwarded:z,multiplierApplied:k,streakPreserved:N}});if(r.code==="ALREADY_CLAIMED")return{success:!1,reward:c,dayIndex:n,streakAfter:r.state.currentStreak,longestStreakAfter:r.state.longestStreak,hintTokensAfter:r.state.hintTokens,streakShieldsAfter:r.state.streakShields,streakPreserved:!1,xpAwarded:0,multiplierApplied:1,isMilestone:!1,error:"Already claimed today"};if(r.xpAwarded>0)try{await la(t,r.xpAwarded,"daily_reward",`Daily Reward Day ${n+1}! +${r.xpAwarded} XP`)}catch(d){console.error("[dailyRewardService] Error awarding XP:",d)}if(c.type==="badge_unlock"&&typeof c.value=="string")try{await Ls(t,c.value)}catch(d){console.error("[dailyRewardService] Error unlocking avatar item:",d)}const u=wl.has(r.newStreak);return{success:!0,reward:c,dayIndex:n,streakAfter:r.newStreak,longestStreakAfter:r.newLongestStreak,hintTokensAfter:r.state.hintTokens,streakShieldsAfter:r.state.streakShields,streakPreserved:r.streakPreserved,xpAwarded:r.xpAwarded,multiplierApplied:r.multiplierApplied,isMilestone:u}}catch(r){throw console.error("[dailyRewardService] Error claiming daily reward:",r),r}}function Sl(t){const[s,l]=a.useState(null),[n,i]=a.useState(!1),[c,r]=a.useState(!1),[u,d]=a.useState(null),[h,S]=a.useState(null),[m,M]=a.useState("00:00:00"),p=a.useRef(null),x=a.useMemo(()=>ns(),[]),N=a.useMemo(()=>jr(),[]),g=a.useCallback(async()=>{if(!t){l(null);return}try{S(null);const F=await Ms(t);l(F)}catch(F){const X=F instanceof Error?F.message:"Failed to load rewards";S(X),console.error("[useDailyReward] refresh error:",F)}},[t]);a.useEffect(()=>{g()},[g]),a.useEffect(()=>{const F=()=>{const K=gr().getTime()-Date.now();M(jl(K))};return F(),p.current=setInterval(F,1e3),()=>{p.current&&(clearInterval(p.current),p.current=null)}},[]);const z=a.useMemo(()=>!s||n?!1:kl(s),[s,n]),k=a.useMemo(()=>!s?.activeMultiplier||new Date(s.activeMultiplier.expiresAt).getTime()<=Date.now()?null:s.activeMultiplier,[s?.activeMultiplier]),R=a.useCallback(async()=>{if(!(!t||!z)){i(!0),S(null);try{const F=await Cl(t);if(d(F),F.success){r(!0);const X=await Ms(t);l(X)}else S(F.error||"Claim failed")}catch(F){const X=F instanceof Error?F.message:"Claim failed";S(X),console.error("[useDailyReward] claim error:",F)}finally{i(!1)}}},[t,z]),P=a.useCallback(()=>{r(!1)},[]);return{weekRewards:x,todayReward:N,canClaim:z,isClaiming:n,claimedDays:s?.claimedDays??[],currentStreak:s?.currentStreak??0,longestStreak:s?.longestStreak??0,totalClaimed:s?.totalClaimed??0,hintTokens:s?.hintTokens??0,streakShields:s?.streakShields??0,activeMultiplier:k,timeUntilReset:m,showModal:c,lastClaimResult:u,error:h,claim:R,dismissModal:P,refresh:g}}const zl=["all","Q1","Q2","Q3","Q4"],jn=({onEarnXP:t,atRiskSubjects:s=[],priorityTopics:l=[],initialModuleId:n=null,isInQuizMode:i=!1,setIsInQuizMode:c,hasCompletedDiagnostic:r=!1})=>{const{userProfile:u,currentUser:d}=$t(),[h,S]=a.useState(()=>{const o=sessionStorage.getItem("mathpulse_modules_tab");return o==="practice"||o==="recommended"||o==="teacher_uploaded"?(sessionStorage.removeItem("mathpulse_modules_tab"),o):"modules"}),m=u,M=m?.grade,p=na(M);Aa(p);const[x,N]=a.useState(""),[g,z]=a.useState("all"),[k,R]=a.useState("all"),[P,F]=a.useState("all"),[X,K]=a.useState(!1),[Y,ee]=a.useState(null),[D,me]=a.useState(null),[ue,Se]=a.useState(null);a.useEffect(()=>{if(u?.uid)return Xt(u.uid,Se)},[u?.uid]);const Ce=a.useMemo(()=>{const o=m?.learnerCurriculumAssignments?.subjects??m?.assignedSubjects??m?.curriculumAssignedSubjects??[];return Array.isArray(o)?o:[]},[m]),{difficulty:f}=gl(d?.uid||null),q=a.useMemo(()=>{const o=ia(p,Ce);return yl(o,f)},[p,Ce,f]),O=n&&q.find(o=>o.id===n)||null,[ae,ie]=a.useState(O),[be,ze]=a.useState(null),Le=Ie.useRef(null),[_e,b]=a.useState(null),[T,C]=a.useState(!1),[B,I]=a.useState(null),[te,xe]=a.useState(!1),[ve,ye]=a.useState([]),[ge,Ne]=a.useState(!1);a.useEffect(()=>{if(h!=="teacher_uploaded"||!Ke)return;Ne(!0);const o=es(Vs(Ks(Ke,"modules"),Ys("moduleType","==","teacher_uploaded")),L=>{const v=L.docs.map($=>({...$.data(),moduleId:$.id}));ye(v),Ne(!1)},L=>{console.error("Error fetching teacher modules:",L),Ne(!1)});return()=>o()},[h]);const[We,Ee]=a.useState(!1),{weekRewards:H,todayReward:he,canClaim:pe,isClaiming:Ue,claimedDays:ft,timeUntilReset:bt,claim:Re,lastClaimResult:Ge}=Sl(u?.uid??null);a.useEffect(()=>{if(!u?.uid)return;let o=!1;const L=async Z=>{o||(pe||Z)&&Ee(!0)},v=Z=>{Z.detail?.tab==="Modules"&&L(!0)},$=setTimeout(()=>L(),500);return window.addEventListener("mathpulse:navigate",v),()=>{o=!0,clearTimeout($),window.removeEventListener("mathpulse:navigate",v)}},[u?.uid,pe]);const Je=async()=>{if(u?.uid)try{await Re(),Ge?.success&&(ua({userId:u.uid,type:"daily_checkin",title:"Daily Reward Claimed!",message:`You earned ${Ge.reward.label} and kept your streak alive!`,metadata:{rewardId:Ge.reward.id,streakDay:Ge.dayIndex+1}}).catch(console.error),Ge.reward.rarity==="epic"&&Ls(u.uid,"acc_crown").then(()=>mt.success("👑 Epic reward unlocked!")).catch(console.error)),setTimeout(()=>Ee(!1),1e3)}catch(o){const L=o instanceof Error?o.message:"";console.error("Failed to claim daily reward:",o),L.includes("Already claimed")?mt.info("You already claimed your reward today!"):mt.error("Failed to claim daily reward. Please try again.")}};a.useEffect(()=>{if(n){const o=q.find(L=>L.id===n);o&&ie(o)}},[n,q]),a.useEffect(()=>{u?.uid&&(xe(!0),oa(u.uid).then(o=>{I(o)}).catch(o=>{console.error("Failed to load competency profile:",o)}).finally(()=>{xe(!1)}))},[u?.uid]);const w=a.useMemo(()=>{const o=l.length>0?l:s.map(v=>ca(v)).filter(v=>v!==null),L=new Set;return o.filter(v=>L.has(v)?!1:(L.add(v),!0))},[l,s]),{data:Me=[]}=Us({queryKey:da.modules(p,w),enabled:!0,staleTime:600*1e3,gcTime:1800*1e3,queryFn:async()=>{const o=q;if(w.length===0)return o;const L=new Map(w.map((v,$)=>[pa[v],$]));return[...o].sort((v,$)=>{const Z=L.get(v.id)??Number.POSITIVE_INFINITY,ce=L.get($.id)??Number.POSITIVE_INFINITY;return Z-ce})}}),rt=a.useMemo(()=>{const o=new Set;return Me.forEach(L=>o.add(L.competency_group)),Array.from(o)},[Me]),Pe=a.useMemo(()=>{const o=x.trim().toLowerCase(),L=Me.filter(v=>{const $=!o||v.title.toLowerCase().includes(o),Z=!o||v.description.toLowerCase().includes(o),ce=!o||v.lessons.some(y=>y.title.toLowerCase().includes(o)),le=!o||v.quizzes.some(y=>y.title.toLowerCase().includes(o)),oe=o?v.competencies.some(y=>y.outcome.toLowerCase().includes(o)||y.code.toLowerCase().includes(o)):!0,we=g==="all"||v.subjectId===g,Be=k==="all"||v.quarter===k,fe=P==="all"||v.competency_group===P;return($||Z||ce||le||oe)&&we&&Be&&fe});if(B?.competencies){const v=new Set(Object.entries(B.competencies).filter(([,Z])=>Z.score<50).map(([Z])=>Z)),$=new Set(Object.entries(B.competencies).filter(([,Z])=>Z.score>=80).map(([Z])=>Z));return L.sort((Z,ce)=>{const le=Z.competencies.map(W=>W.code),oe=ce.competencies.map(W=>W.code),we=le.some(W=>v.has(W))?1:0,Be=oe.some(W=>v.has(W))?1:0,fe=le.some(W=>$.has(W))?1:0,y=oe.some(W=>$.has(W))?1:0,j=we*2+fe;return Be*2+y-j})}return L},[Me,x,g,k,P,B]),Oe=a.useMemo(()=>ue?Pe.map(o=>{const v=Object.values(ue.subjects||{}).find(le=>le.modulesProgress?.[o.id])?.modulesProgress?.[o.id];if(!v)return o;const $=o.lessons.length+o.quizzes.length,Z=(v.lessonsCompleted?.length||0)+(v.quizzesCompleted?.length||0),ce=$>0?Math.round(Z/$*100):0;return{...o,progress:ce}}):Pe,[Pe,ue]),gt=a.useMemo(()=>{const o=k==="all"?"All Quarters":k,L=g==="all"?"All Subjects":cs[g]?.label??"Subject";return`${p} · ${L} · ${o}`},[p,g,k]),lt=a.useMemo(()=>{const o=new Set(Me.map(L=>L.subjectId));return Array.from(o)},[Me]),Xe=()=>{z("all"),R("all"),F("all"),N("")};a.useEffect(()=>{h!=="recommended"||w.length===0||(C(!0),ma({weakTopics:w.map(o=>ds[o]),subject:g!=="all"?g:"General Mathematics",userId:u?.uid}).then(o=>{b(o.curriculumContext),C(!1)}).catch(()=>C(!1)))},[h,w]);const nt=(o,L)=>{t&&t(L,`Quiz Completed! +${L} XP`)},it=async o=>{if(d?.uid)try{await Ea(d.uid,o),mt.success("You'll be notified when this module becomes available.")}catch{}};return a.useEffect(()=>{c&&c(!!be)},[be,c]),be?e.jsx(qs,{quiz:be,onClose:()=>{Le.current=null,ze(null)},onComplete:nt,onQuizEnd:Le.current??void 0,studentId:u?.uid}):ae?e.jsx(xl,{module:ae,onBack:()=>ie(null),onEarnXP:t,isInQuizMode:i,setIsInQuizMode:c}):D?e.jsxs("div",{className:"h-full overflow-y-auto px-4 sm:px-6 xl:px-10 pb-8 scrollbar-hide scroll-smooth relative",children:[e.jsxs("button",{onClick:()=>me(null),className:"mb-4 inline-flex items-center gap-2 text-sm font-bold text-slate-600 hover:text-slate-900 transition-colors",children:[e.jsx(tt,{className:"rotate-180",size:16}),"Back to Modules"]}),e.jsxs("div",{className:"bg-white rounded-2xl border border-[#F08386]/30 p-6 md:p-8",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx("span",{className:"px-2 py-1 rounded-md bg-[#F08386]/12 border border-[#F08386]/30 text-[#F08386] text-xs font-bold",children:"Teacher Upload"}),D.quarter&&e.jsx("span",{className:"px-2 py-1 rounded-md bg-slate-100 text-slate-600 text-xs",children:D.quarter})]}),e.jsx("h1",{className:"text-2xl md:text-3xl font-display font-black text-slate-900 mb-2",children:D.title}),e.jsxs("p",{className:"text-sm text-slate-600 mb-6",children:[D.subject," · ",D.gradeLevel]}),D.summary&&e.jsx("p",{className:"text-slate-700 text-base leading-relaxed mb-6",children:D.summary}),D.learningObjectives?.length>0&&e.jsxs("div",{className:"mb-6",children:[e.jsx("h2",{className:"text-lg font-bold text-slate-900 mb-2",children:"Learning Objectives"}),e.jsx("ul",{className:"list-disc list-inside space-y-1 text-slate-700",children:D.learningObjectives.map((o,L)=>e.jsx("li",{children:o},L))})]}),D.sections?.length>0&&e.jsxs("div",{className:"mb-6",children:[e.jsx("h2",{className:"text-lg font-bold text-slate-900 mb-3",children:"Sections"}),e.jsx("div",{className:"space-y-3",children:D.sections.map((o,L)=>e.jsxs("div",{className:"border border-slate-200 rounded-xl p-4",children:[e.jsx("h3",{className:"text-sm font-bold text-slate-800 mb-1",children:o.title}),e.jsx("p",{className:"text-sm text-slate-600 leading-relaxed",children:o.content})]},L))})]}),D.practice?.length>0&&e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-bold text-slate-900 mb-3",children:"Practice Questions"}),e.jsx("div",{className:"space-y-3",children:D.practice.map((o,L)=>e.jsxs("div",{className:"border border-slate-200 rounded-xl p-4",children:[e.jsx("p",{className:"text-sm font-bold text-slate-800 mb-2",children:o.question}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2 mb-2",children:o.options.map((v,$)=>e.jsxs("div",{className:"text-xs text-slate-600 bg-slate-50 rounded-lg px-3 py-2",children:[v.label,". ",v.text]},$))}),e.jsxs("p",{className:"text-xs text-emerald-700 font-semibold",children:["Answer: ",o.answer]}),e.jsx("p",{className:"text-xs text-slate-500 mt-1",children:o.explanation})]},L))})]})]})]}):e.jsxs("div",{className:"h-full overflow-y-auto px-4 sm:px-6 xl:px-10 pb-8 scrollbar-hide scroll-smooth relative",onScroll:o=>K(o.currentTarget.scrollTop>100),children:[e.jsx(bl,{isOpen:We,onClose:()=>Ee(!1),onClaim:Je,weekRewards:H,todayReward:he,canClaim:pe,isClaiming:Ue,claimedDays:ft,currentDayIndex:ls(),timeUntilReset:bt}),e.jsxs("div",{className:"flex flex-col lg:flex-row justify-between items-start lg:items-center py-4 md:py-6 gap-4 md:gap-6",children:[e.jsxs("div",{className:"flex-1 max-w-3xl",children:[e.jsx("h1",{className:"text-[28px] md:text-[44px] font-display font-black text-[#202124] tracking-tight leading-[1.1] mb-3 md:mb-4",children:"Curriculum Modules"}),e.jsx("p",{className:"text-[#3c4043] text-[13px] md:text-[17px] leading-relaxed md:leading-[1.7] md:pr-10",children:"MathPulse AI loads modules directly from DepEd Strengthened SHS curriculum guides with AI-powered RAG lesson generation. Currently available: General Mathematics, Business Mathematics, and Statistics & Probability. Pre-Calculus and Basic Calculus modules are coming soon once teaching module PDFs are sourced."}),e.jsx("div",{className:"mt-4 flex items-center gap-3",children:e.jsx("div",{className:"inline-flex items-center rounded-full border border-sky-200 bg-sky-50 px-4 py-2 text-sm font-bold text-sky-900",children:gt})})]}),e.jsx("div",{className:"hidden lg:flex flex-shrink-0 items-center justify-end w-[350px]",children:e.jsx(Ss,{assessmentDismissed:u?.assessmentDismissed,initialAssessmentCompleted:u?.initialAssessmentCompleted})})]}),e.jsxs("div",{className:`sticky top-0 z-30 -mx-4 px-4 sm:-mx-6 sm:px-6 xl:-mx-10 xl:px-10 pt-3 pb-3 space-y-3 transition-colors duration-300 ${X?"bg-[#f8faff] border-b border-[#dde3eb] shadow-sm":"bg-transparent"}`,children:[e.jsxs("div",{className:"flex flex-col lg:flex-row items-center gap-3 w-full",children:[e.jsxs("div",{className:"relative flex-1 w-full",children:[e.jsx("div",{className:"absolute left-4 top-1/2 -translate-y-1/2 text-[#5f6368]",children:e.jsx(Pa,{size:16,strokeWidth:2.5})}),e.jsx("input",{id:"modules-search",name:"modules-search","aria-label":"Search modules",type:"text",value:x,onChange:o=>N(o.target.value),placeholder:"Search modules, lessons, or assessments...",className:"w-full pl-10 pr-10 py-2 rounded-xl border border-[#dadce0] bg-white text-[#202124] text-[13px] font-medium focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary transition-all shadow-sm"}),!1]}),e.jsxs("div",{className:"flex flex-row overflow-x-auto no-scrollbar items-center gap-2 w-full lg:w-auto shrink-0 -mx-4 px-4 sm:mx-0 sm:px-0 pb-1 sm:pb-0",children:[e.jsxs("select",{value:g,onChange:o=>z(o.target.value),className:"shrink-0 rounded-xl border border-slate-200 bg-white pl-3 pr-8 py-2 text-xs font-semibold text-slate-700 focus:border-sky-400 focus:outline-none shadow-sm","aria-label":"Subject",children:[e.jsx("option",{value:"all",children:"All Subjects"}),lt.map(o=>e.jsx("option",{value:o,children:cs[o].label},o))]}),e.jsx("select",{value:k,onChange:o=>R(o.target.value),className:"shrink-0 rounded-xl border border-slate-200 bg-white pl-3 pr-8 py-2 text-xs font-semibold text-slate-700 focus:border-sky-400 focus:outline-none shadow-sm","aria-label":"Quarter",children:zl.map(o=>e.jsx("option",{value:o,children:o==="all"?"All Quarters":o},o))}),e.jsxs("select",{value:P,onChange:o=>F(o.target.value),className:"shrink-0 rounded-xl border border-slate-200 bg-white pl-3 pr-8 py-2 text-xs font-semibold text-slate-700 focus:border-sky-400 focus:outline-none shadow-sm","aria-label":"Competency Group",children:[e.jsx("option",{value:"all",children:"All Competencies"}),rt.map(o=>e.jsx("option",{value:o,children:o},o))]}),e.jsxs("button",{type:"button",onClick:Xe,className:"inline-flex shrink-0 items-center justify-center gap-1.5 rounded-xl border border-slate-200 bg-white px-3 py-2 text-xs font-bold text-slate-700 transition-colors hover:bg-slate-50 shadow-sm",children:[e.jsx(Ta,{size:14}),"Reset"]})]})]}),e.jsxs("div",{className:"flex flex-col md:flex-row md:items-center gap-3 mt-2",children:[e.jsx("div",{className:"flex items-center bg-slate-100/80 p-1 rounded-full border border-slate-200/60 shadow-inner gap-1 overflow-x-auto no-scrollbar w-full md:w-auto",children:[{id:"modules",label:"Modules",icon:$e,color:"text-[#1FA7E1]"},{id:"recommended",label:"Recommended",icon:Pt,color:"text-[#75D06A]"},{id:"practice",label:"Practice",icon:Qe,color:"text-[#FFB356]"},{id:"teacher_uploaded",label:"Teacher Uploaded",icon:xa,color:"text-[#F08386]"}].map(o=>{const L=h===o.id;return e.jsxs("button",{onClick:()=>S(o.id),className:`relative flex items-center gap-1.5 px-4 py-1.5 rounded-full text-[13px] font-bold transition-all duration-300 flex-shrink-0 ${L?"shadow-sm":"text-slate-500 hover:text-slate-700 hover:bg-slate-200/50"}`,children:[L&&e.jsx(E.div,{layoutId:"modulesTabBackground",className:"absolute inset-0 bg-white rounded-full shadow-[0_2px_15px_-3px_rgba(0,0,0,0.1)] border border-slate-100",transition:{type:"spring",bounce:.2,duration:.6}}),e.jsxs("span",{className:`relative z-10 flex items-center gap-1.5 ${L?o.color:""}`,children:[e.jsx(o.icon,{size:15,strokeWidth:L?2.5:2}),o.label]})]},o.id)})}),e.jsxs("div",{className:"flex items-center gap-2 ml-1",children:[h==="modules"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-7 h-7 rounded-lg bg-indigo-50 border border-indigo-100 flex items-center justify-center text-indigo-500",children:e.jsx(Na,{size:15,strokeWidth:2.5})}),e.jsx("span",{className:"font-display font-black text-[15px] text-slate-700 tracking-tight whitespace-nowrap",children:"DepEd Strengthened SHS Modules"})]}),h==="recommended"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-7 h-7 rounded-lg bg-[#75D06A]/10 flex items-center justify-center",children:e.jsx(La,{size:15,className:"text-[#75D06A]"})}),e.jsx("span",{className:"font-display font-black text-[15px] text-slate-700 tracking-tight whitespace-nowrap",children:"Suggested Next"})]}),h==="practice"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-7 h-7 rounded-lg bg-[#FFB356]/10 flex items-center justify-center",children:e.jsx(Qe,{size:15,className:"text-[#FFB356]"})}),e.jsx("span",{className:"font-display font-black text-[15px] text-slate-700 tracking-tight whitespace-nowrap",children:"Practice Center"})]}),h==="teacher_uploaded"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-7 h-7 rounded-lg bg-[#F08386]/15 border border-[#F08386]/30 flex items-center justify-center text-[#F08386]",children:e.jsx(ps,{size:15,strokeWidth:2.5})}),e.jsx("span",{className:"font-display font-black text-[15px] text-slate-700 tracking-tight whitespace-nowrap",children:"Teacher Uploaded Modules"})]})]})]})]}),e.jsx("div",{className:"flex lg:hidden items-center justify-center w-full mt-2 mb-2",children:e.jsx(Ss,{assessmentDismissed:u?.assessmentDismissed,initialAssessmentCompleted:u?.initialAssessmentCompleted})}),e.jsxs("div",{className:"pt-4",children:[w.length>0&&e.jsxs("div",{className:"mb-4 rounded-2xl border border-amber-300 bg-amber-50 px-5 py-4 shadow-sm",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"inline-flex items-center gap-2 text-sm font-black text-amber-900",children:[e.jsx(Es,{size:15}),"Assessment Focus Areas"]}),e.jsx("p",{className:"mt-1 text-sm text-amber-900/80",children:"Modules are currently prioritized by your latest diagnostic needs."})]}),e.jsxs("button",{type:"button",onClick:()=>S("recommended"),className:"inline-flex items-center gap-1.5 rounded-xl bg-amber-600 px-3 py-2 text-xs font-bold text-white transition-colors hover:bg-amber-700",children:["View Recommended",e.jsx(tt,{size:14})]})]}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:w.map((o,L)=>e.jsxs("span",{className:"rounded-full bg-white px-3 py-1 text-xs font-semibold text-amber-900 shadow-sm",children:[L+1,". ",ds[o]]},o))})]}),e.jsx(Ze,{mode:"wait",children:e.jsx(E.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},exit:{opacity:0,y:-20},transition:{duration:.3},className:"pb-8 mt-4",children:h==="practice"?e.jsx(hl,{userId:u?.uid??"",onStartQuiz:o=>{Le.current=async(L,v)=>{if(!u?.uid)return;const $=L.title?.replace(/^Practice Quiz:\s*/i,"").replace(/\s*\(AI\)\s*$/i,"")||"",Z=Math.round(v.filter(ce=>ce.correct).length/Math.max(v.length,1)*100);if($){const ce=`mathpulse_practice_completed_${u.uid}`;try{const le=localStorage.getItem(ce),oe=le?JSON.parse(le):[],we=new Map(oe),Be=$.toLowerCase(),fe=we.get(Be)||{bestScore:0,attempts:0,history:[]};fe.bestScore=Math.max(fe.bestScore,Z),fe.attempts+=1,fe.history.unshift({date:new Date().toISOString(),score:Z,difficulty:L.difficulty||"Medium"}),we.set(Be,fe),localStorage.setItem(ce,JSON.stringify(Array.from(we.entries())))}catch{}}if(L.generatedQuizId)try{const ce=new Map((L.loadedQuestions||[]).map(we=>[we.id,we])),le=v.map(we=>{const fe=ce.get(we.questionId)?.options?.findIndex(y=>y.trim().toLowerCase()===we.answer.trim().toLowerCase())??0;return{question_id:we.questionId,selected_index:fe}}),oe=await dl({session_id:L.generatedQuizId,userId:u.uid,answers:le});mt.success(`Score: ${oe.score_percent}% | Correct: ${oe.correct_count}/${oe.total} | +${oe.xp_earned} XP`)}catch(ce){console.error(ce),mt.success(`Score: ${Z}%`)}},ze(o)},searchQuery:x,atRiskTopics:w}):h==="teacher_uploaded"?ge?e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6 mt-6",children:[1,2,3].map(o=>e.jsxs("div",{className:"bg-white rounded-2xl border border-slate-200 p-6 animate-pulse",children:[e.jsx("div",{className:"h-4 bg-slate-200 rounded w-3/4 mb-4"}),e.jsx("div",{className:"h-3 bg-slate-100 rounded w-1/2 mb-3"}),e.jsx("div",{className:"h-3 bg-slate-100 rounded w-5/6"})]},o))}):ve.length===0?e.jsxs("div",{className:"text-center py-16",children:[e.jsx("div",{className:"w-16 h-16 bg-[#F08386]/10 rounded-2xl flex items-center justify-center mx-auto mb-4",children:e.jsx(ps,{size:32,className:"text-[#F08386]"})}),e.jsx("h3",{className:"text-lg font-bold text-slate-800 mb-2",children:"No Teacher-Uploaded Modules Yet"}),e.jsx("p",{className:"text-slate-500 text-sm",children:"Your teachers haven't uploaded any custom modules yet."})]}):e.jsx("div",{className:"grid grid-cols-2 lg:grid-cols-3 gap-3 md:gap-6 mt-6",children:ve.map(o=>e.jsxs("div",{className:"bg-white rounded-2xl border border-[#F08386]/30 p-6 hover:border-[#F08386]/60 hover:shadow-md transition-all cursor-pointer",onClick:()=>me(o),children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx("span",{className:"px-2 py-1 rounded-md bg-[#F08386]/12 border border-[#F08386]/30 text-[#F08386] text-xs font-bold",children:"Teacher Upload"}),o.quarter&&e.jsx("span",{className:"px-2 py-1 rounded-md bg-slate-100 text-slate-600 text-xs",children:o.quarter})]}),e.jsx("h3",{className:"text-lg font-bold text-slate-900 mb-2 line-clamp-2",children:o.title}),e.jsxs("p",{className:"text-sm text-slate-600 mb-3",children:[o.subject," · ",o.gradeLevel]}),o.summary&&e.jsx("p",{className:"text-xs text-slate-500 line-clamp-3",children:o.summary})]},o.moduleId))}):h==="modules"?e.jsx(_l,{modules:Oe,onSelectModule:ie,onPreviewSources:ee,isAtRisk:w.length>0&&r,weakTopics:m?.assessmentResults?.weakTopics||[],onNotifyMe:it}):e.jsx(Ml,{modules:Oe,fullPool:Me,onSelectModule:ie,onPreviewSources:ee,isAtRisk:w.length>0&&r,learningPathContext:_e,learningPathLoading:T,weakTopics:m?.assessmentResults?.weakTopics||[],onNotifyMe:it})},h)})]}),e.jsx(Ze,{children:Y&&e.jsxs(E.aside,{initial:{opacity:0,x:24},animate:{opacity:1,x:0},exit:{opacity:0,x:24},transition:{duration:.25},className:"fixed inset-y-0 right-0 z-[80] w-full max-w-xl border-l border-slate-200 bg-white p-6 shadow-2xl",children:[e.jsxs("div",{className:"mb-4 flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-black uppercase tracking-wide text-sky-700",children:"Curriculum Preview"}),e.jsx("h3",{className:"mt-1 text-xl font-black text-slate-900",children:Y.title}),e.jsxs("p",{className:"mt-1 text-sm text-slate-600",children:[Y.active_grade_level," · ",Y.subject," · ",Y.quarter]})]}),e.jsx("button",{type:"button",onClick:()=>ee(null),className:"rounded-lg border border-slate-200 p-2 text-slate-500 hover:bg-slate-50",children:e.jsx(Ye,{size:16})})]}),e.jsxs("div",{className:"space-y-4 overflow-y-auto pr-1",children:[e.jsxs("div",{className:"rounded-2xl border border-slate-200 bg-slate-50 p-4",children:[e.jsx("p",{className:"text-xs font-bold uppercase tracking-wide text-slate-500",children:"Competency Group"}),e.jsx("p",{className:"mt-1 text-sm font-semibold text-slate-800",children:Y.competency_group})]}),e.jsxs("div",{className:"rounded-2xl border border-slate-200 p-4",children:[e.jsx("p",{className:"text-xs font-bold uppercase tracking-wide text-slate-500",children:"Performance Standard"}),e.jsx("p",{className:"mt-1 text-sm text-slate-700",children:Y.performance_standard})]}),e.jsxs("div",{className:"rounded-2xl border border-slate-200 p-4",children:[e.jsx("p",{className:"text-xs font-bold uppercase tracking-wide text-slate-500",children:"Competencies"}),e.jsx("div",{className:"mt-2 space-y-2",children:Y.competencies.map(o=>e.jsxs("div",{className:"rounded-xl border border-slate-100 bg-slate-50 p-3",children:[e.jsx("p",{className:"text-xs font-black text-slate-600",children:o.code}),e.jsx("p",{className:"mt-1 text-sm text-slate-700",children:o.outcome})]},o.code))})]})]})]})})]})},_l=({modules:t,onSelectModule:s,onPreviewSources:l,isAtRisk:n=!1,weakTopics:i=[],onNotifyMe:c})=>e.jsx("div",{className:"pr-2 space-y-8",children:e.jsx("div",{children:t.length===0?e.jsxs("div",{className:"bg-white rounded-2xl border border-[#dde3eb] p-8 text-center",children:[e.jsx("p",{className:"text-slate-700 font-semibold",children:"No matching modules found."}),e.jsx("p",{className:"mt-2 text-sm text-slate-500",children:"If modules are not yet available for your selected view, this area will unlock after assessment sync and content rollout."})]}):e.jsx("div",{className:"grid grid-cols-2 lg:grid-cols-3 xl:grid-cols-3 gap-3 md:gap-6",children:t.map((r,u)=>{const d=i.some(h=>r.content_domain&&r.content_domain.toLowerCase().includes(h.toLowerCase())||r.title&&r.title.toLowerCase().includes(h.toLowerCase())||r.competency_group&&r.competency_group.toLowerCase().includes(h.toLowerCase())||r.subject&&r.subject.toLowerCase().includes(h.toLowerCase()));return e.jsx(Vt,{module:r,index:u,onClick:()=>s(r),onPreviewSources:()=>l(r),isAtRisk:n,isRecommended:d,onNotifyMe:c},r.id)})})})}),Ml=({modules:t,fullPool:s,onSelectModule:l,onPreviewSources:n,isAtRisk:i=!1,learningPathContext:c=null,learningPathLoading:r=!1,weakTopics:u=[],onNotifyMe:d})=>{const h=t.filter(m=>m.progress>0&&m.progress<100),S=(t.length>0?t:s).filter(m=>m.progress===0).slice(0,6);return e.jsxs("div",{className:"pr-2 space-y-10",children:[r&&e.jsxs("div",{className:"mb-6 rounded-2xl border border-sky-200 bg-sky-50 px-5 py-4 flex items-center gap-3",children:[e.jsx("div",{className:"w-5 h-5 rounded-full border-2 border-sky-400 border-t-transparent animate-spin flex-shrink-0"}),e.jsx("p",{className:"text-sm font-semibold text-sky-800",children:"Building your personalized learning path from DepEd curriculum..."})]}),c&&!r&&e.jsxs("div",{className:"mb-6 rounded-2xl border border-indigo-200 bg-gradient-to-br from-indigo-50 to-purple-50 px-5 py-4 shadow-sm",children:[e.jsx("p",{className:"text-xs font-black uppercase tracking-wide text-indigo-700 mb-2",children:"📚 Your Personalized Learning Path"}),e.jsx("pre",{className:"whitespace-pre-wrap text-sm text-indigo-900 font-medium leading-relaxed font-sans",children:c})]}),h.length>0&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-3 mb-6",children:[e.jsx("div",{className:"w-10 h-10 rounded-[14px] bg-[#FF8B8B]/10 flex items-center justify-center text-[20px] shadow-inner",children:"🔥"}),e.jsx("h2",{className:"font-display font-black text-[24px] text-slate-800 tracking-tight",children:"Continue This Module"})]}),e.jsx("div",{className:"grid grid-cols-2 lg:grid-cols-3 xl:grid-cols-3 gap-3 md:gap-6",children:h.slice(0,4).map((m,M)=>{const p=u.some(x=>m.content_domain&&m.content_domain.toLowerCase().includes(x.toLowerCase())||m.title&&m.title.toLowerCase().includes(x.toLowerCase())||m.competency_group&&m.competency_group.toLowerCase().includes(x.toLowerCase())||m.subject&&m.subject.toLowerCase().includes(x.toLowerCase()));return e.jsx(Vt,{module:m,index:M,onClick:()=>l(m),onPreviewSources:()=>n(m),isAtRisk:i,badgeLabel:"In Progress",isRecommended:p,onNotifyMe:d},m.id)})})]}),e.jsx("div",{children:S.length===0?e.jsx("div",{className:"bg-white rounded-2xl border border-[#dde3eb] p-8 text-center text-slate-500 font-medium",children:"You are all caught up. Practice more quizzes to unlock additional recommendations."}):e.jsx("div",{className:"grid grid-cols-2 lg:grid-cols-3 xl:grid-cols-3 gap-3 md:gap-6",children:S.map((m,M)=>{const p=u.some(x=>m.content_domain&&m.content_domain.toLowerCase().includes(x.toLowerCase())||m.title&&m.title.toLowerCase().includes(x.toLowerCase())||m.competency_group&&m.competency_group.toLowerCase().includes(x.toLowerCase())||m.subject&&m.subject.toLowerCase().includes(x.toLowerCase()));return e.jsx(Vt,{module:m,index:M,onClick:()=>l(m),onPreviewSources:()=>n(m),isAtRisk:i,badgeLabel:"Start",isRecommended:p,onNotifyMe:d},m.id)})})})]})};export{jn as default}; diff --git a/assets/NotificationDropdown-BwLtHvqY.js b/assets/NotificationDropdown-DNm6nFOm.js similarity index 94% rename from assets/NotificationDropdown-BwLtHvqY.js rename to assets/NotificationDropdown-DNm6nFOm.js index 325153c7f308459fe2ae182b29d48faf08587eda..263144bb03c08f761496279b8d9815c4753e7cc0 100644 --- a/assets/NotificationDropdown-BwLtHvqY.js +++ b/assets/NotificationDropdown-DNm6nFOm.js @@ -1,4 +1,4 @@ -import{e as n,E as b,u as N,h as w,m as j,a as g,U as k}from"./index-BufUS6SI.js";import{r as _,j as e}from"./vendor-react-B4AQeu28.js";import"./vendor-firebase-firestore-CNv3xXal.js";import{C as y,f as v}from"./formatDistanceToNow-cESSXRCA.js";import{B as o}from"./bell-D9j1Gy0m.js";import{C}from"./circle-check-BzgmgbHa.js";import{C as A}from"./circle-alert-DDdeEgNa.js";import{S as z}from"./sparkles-DYlMf97S.js";/** +import{e as n,E as b,u as N,h as w,m as j,a as g,U as k}from"./index-Bp7MiGcW.js";import{r as _,j as e}from"./vendor-react-B4AQeu28.js";import"./vendor-firebase-firestore-CNv3xXal.js";import{C as y,f as v}from"./formatDistanceToNow-D-5-www2.js";import{B as o}from"./bell-DyLbgepV.js";import{C}from"./circle-check-DzQphSnP.js";import{C as A}from"./circle-alert-CHGy8HcB.js";import{S as z}from"./sparkles-fLB3ltj1.js";/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. diff --git a/assets/ProfileModal-CsRM_gfJ.js b/assets/ProfileModal-c1MJMwBW.js similarity index 96% rename from assets/ProfileModal-CsRM_gfJ.js rename to assets/ProfileModal-c1MJMwBW.js index e1e65aed15b969bc6afacb634f899e1dd88f2f72..0e82838c5e11b9f9e9f83321707e5f2680335692 100644 --- a/assets/ProfileModal-CsRM_gfJ.js +++ b/assets/ProfileModal-c1MJMwBW.js @@ -1,4 +1,4 @@ -import{r,j as e}from"./vendor-react-B4AQeu28.js";import{e as R,h as U,m as k,U as u,A as x,b as w,H as _,a1 as D,aL as T,aV as B,j as V}from"./index-BufUS6SI.js";import{B as b}from"./button-DsnZWCoA.js";import{I as d}from"./input-BPglbGHJ.js";import{S as $,a as q,c as G,d as p}from"./select-CPMGrUkA.js";import{P as X,M as z,V as C}from"./ProfilePictureUploader-B-ipxzWy.js";import{X as Y}from"./x-BuBjuj2Y.js";import{M as H}from"./mail-d6dXXOFo.js";import{C as L}from"./circle-help-DNA0h1v1.js";import{S as K}from"./save-CwINi309.js";import"./vendor-firebase-firestore-CNv3xXal.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-radix-C5nwdvGr.js";import"./vendor-charts-CAmziV1y.js";import"./vendor-markdown-yqZQ_iQm.js";import"./chevron-up-CoNRuMZ7.js";import"./check-B-qbiSF7.js";import"./minus-DuS-NH5j.js";import"./plus-B4qs4LzO.js";import"./upload-gDf1MsBj.js";/** +import{r,j as e}from"./vendor-react-B4AQeu28.js";import{e as R,h as U,m as k,U as u,A as x,b as w,H as _,a1 as D,aL as T,aV as B,j as V}from"./index-Bp7MiGcW.js";import{B as b}from"./button-BMVm9YQO.js";import{I as d}from"./input-Co0dljwe.js";import{S as $,a as q,c as G,d as p}from"./select-CNQuOudF.js";import{P as X,M as z,V as C}from"./ProfilePictureUploader-Cdp-MoCI.js";import{X as Y}from"./x-k8d6VLEw.js";import{M as H}from"./mail-jAg7cqFw.js";import{C as L}from"./circle-help-CLCoBWDy.js";import{S as K}from"./save-D7oNX_Ki.js";import"./vendor-firebase-firestore-CNv3xXal.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-radix-C5nwdvGr.js";import"./vendor-charts-CAmziV1y.js";import"./vendor-markdown-yqZQ_iQm.js";import"./chevron-up-DtS9MvUZ.js";import"./check-qsSFTYCr.js";import"./minus-BK7K7Pi2.js";import"./plus-D4SEqrVj.js";import"./upload-CP6O7WIX.js";/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. diff --git a/assets/ProfilePictureUploader-B-ipxzWy.js b/assets/ProfilePictureUploader-Cdp-MoCI.js similarity index 98% rename from assets/ProfilePictureUploader-B-ipxzWy.js rename to assets/ProfilePictureUploader-Cdp-MoCI.js index 80b0c3f0101ad138dee3da2a47f8708cb3167b50..5875dbe4c955b2cd70500cb80307e9d3acf08837 100644 --- a/assets/ProfilePictureUploader-B-ipxzWy.js +++ b/assets/ProfilePictureUploader-Cdp-MoCI.js @@ -1,5 +1,5 @@ -const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/vendor-firebase-firestore-CNv3xXal.js","assets/vendor-firebase-core-D7GXCeNu.js","assets/index-BufUS6SI.js","assets/vendor-react-B4AQeu28.js","assets/vendor-firebase-auth-T_wvTOvf.js","assets/vendor-firebase-storage-Bi7H_66d.js","assets/vendor-firebase-analytics-rHarj5hR.js","assets/vendor-radix-C5nwdvGr.js","assets/vendor-charts-CAmziV1y.js","assets/vendor-markdown-yqZQ_iQm.js","assets/vendor-markdown-CfVKi3_s.css","assets/index-CIg5rXpX.css"])))=>i.map(i=>d[i]); -import{e as V,o as B,k as K,J as ge,_ as $,b4 as we,u as xe,W as ye,X as be,Y as Ce,h as Pe,m as J,j as Q}from"./index-BufUS6SI.js";import{g as Re,r as x,j as p}from"./vendor-react-B4AQeu28.js";import{_ as Ee,o as b,p as Se,q as _e,r as ze,s as De}from"./vendor-radix-C5nwdvGr.js";import{B as ee}from"./button-DsnZWCoA.js";import{updateProfile as Me}from"./vendor-firebase-auth-T_wvTOvf.js";import"./vendor-firebase-core-D7GXCeNu.js";import{r as Ae,u as Te,a as Ne}from"./vendor-firebase-storage-Bi7H_66d.js";import{X as je}from"./x-BuBjuj2Y.js";import{M as Ue}from"./minus-DuS-NH5j.js";import{P as Fe}from"./plus-B4qs4LzO.js";import{U as Ie}from"./upload-gDf1MsBj.js";/** +const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/vendor-firebase-firestore-CNv3xXal.js","assets/vendor-firebase-core-D7GXCeNu.js","assets/index-Bp7MiGcW.js","assets/vendor-react-B4AQeu28.js","assets/vendor-firebase-auth-T_wvTOvf.js","assets/vendor-firebase-storage-Bi7H_66d.js","assets/vendor-firebase-analytics-rHarj5hR.js","assets/vendor-radix-C5nwdvGr.js","assets/vendor-charts-CAmziV1y.js","assets/vendor-markdown-yqZQ_iQm.js","assets/vendor-markdown-CfVKi3_s.css","assets/index-Dja0MwoB.css"])))=>i.map(i=>d[i]); +import{e as V,o as B,k as K,J as ge,_ as $,b4 as we,u as xe,W as ye,X as be,Y as Ce,h as Pe,m as J,j as Q}from"./index-Bp7MiGcW.js";import{g as Re,r as x,j as p}from"./vendor-react-B4AQeu28.js";import{_ as Ee,o as b,p as Se,q as _e,r as ze,s as De}from"./vendor-radix-C5nwdvGr.js";import{B as ee}from"./button-BMVm9YQO.js";import{updateProfile as Me}from"./vendor-firebase-auth-T_wvTOvf.js";import"./vendor-firebase-core-D7GXCeNu.js";import{r as Ae,u as Te,a as Ne}from"./vendor-firebase-storage-Bi7H_66d.js";import{X as je}from"./x-k8d6VLEw.js";import{M as Ue}from"./minus-BK7K7Pi2.js";import{P as Fe}from"./plus-D4SEqrVj.js";import{U as Ie}from"./upload-CP6O7WIX.js";/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. @@ -107,4 +107,4 @@ import{e as V,o as B,k as K,J as ge,_ as $,b4 as we,u as xe,W as ye,X as be,Y as border-left: 0; border-right: 0; } -`,nt=1,at=3,st=1,ct=(function(a){Ee(o,a);function o(){var e=a!==null&&a.apply(this,arguments)||this;return e.cropperRef=x.createRef(),e.imageRef=x.createRef(),e.videoRef=x.createRef(),e.containerPosition={x:0,y:0},e.containerRef=null,e.styleRef=null,e.containerRect=null,e.mediaSize={width:0,height:0,naturalWidth:0,naturalHeight:0},e.dragStartPosition={x:0,y:0},e.dragStartCrop={x:0,y:0},e.gestureZoomStart=0,e.gestureRotationStart=0,e.isTouching=!1,e.lastPinchDistance=0,e.lastPinchRotation=0,e.rafDragTimeout=null,e.rafPinchTimeout=null,e.wheelTimer=null,e.currentDoc=typeof document<"u"?document:null,e.currentWindow=typeof window<"u"?window:null,e.resizeObserver=null,e.previousCropSize=null,e.isInitialized=!1,e.state={cropSize:null,hasWheelJustStarted:!1,mediaObjectFit:void 0},e.initResizeObserver=function(){if(!(typeof window.ResizeObserver>"u"||!e.containerRef)){var t=!0;e.resizeObserver=new window.ResizeObserver(function(r){if(t){t=!1;return}e.computeSizes()}),e.resizeObserver.observe(e.containerRef)}},e.preventZoomSafari=function(t){return t.preventDefault()},e.cleanEvents=function(){e.currentDoc&&(e.currentDoc.removeEventListener("mousemove",e.onMouseMove),e.currentDoc.removeEventListener("mouseup",e.onDragStopped),e.currentDoc.removeEventListener("touchmove",e.onTouchMove),e.currentDoc.removeEventListener("touchend",e.onDragStopped),e.currentDoc.removeEventListener("gesturechange",e.onGestureChange),e.currentDoc.removeEventListener("gestureend",e.onGestureEnd),e.currentDoc.removeEventListener("scroll",e.onScroll))},e.clearScrollEvent=function(){e.containerRef&&e.containerRef.removeEventListener("wheel",e.onWheel),e.wheelTimer&&clearTimeout(e.wheelTimer)},e.onMediaLoad=function(){var t=e.computeSizes();t&&(e.previousCropSize=t,e.emitCropData(),e.setInitialCrop(t),e.isInitialized=!0),e.props.onMediaLoaded&&e.props.onMediaLoaded(e.mediaSize)},e.setInitialCrop=function(t){if(e.props.initialCroppedAreaPercentages){var r=et(e.props.initialCroppedAreaPercentages,e.mediaSize,e.props.rotation,t,e.props.minZoom,e.props.maxZoom),i=r.crop,n=r.zoom;e.props.onCropChange(i),e.props.onZoomChange&&e.props.onZoomChange(n)}else if(e.props.initialCroppedAreaPixels){var s=rt(e.props.initialCroppedAreaPixels,e.mediaSize,e.props.rotation,t,e.props.minZoom,e.props.maxZoom),i=s.crop,n=s.zoom;e.props.onCropChange(i),e.props.onZoomChange&&e.props.onZoomChange(n)}},e.computeSizes=function(){var t,r,i,n,s,c,l=e.imageRef.current||e.videoRef.current;if(l&&e.containerRef){e.containerRect=e.containerRef.getBoundingClientRect(),e.saveContainerPosition();var u=e.containerRect.width/e.containerRect.height,h=((t=e.imageRef.current)===null||t===void 0?void 0:t.naturalWidth)||((r=e.videoRef.current)===null||r===void 0?void 0:r.videoWidth)||0,d=((i=e.imageRef.current)===null||i===void 0?void 0:i.naturalHeight)||((n=e.videoRef.current)===null||n===void 0?void 0:n.videoHeight)||0,m=l.offsetWidthw?{width:e.containerRect.height*w,height:e.containerRect.height}:{width:e.containerRect.width,height:e.containerRect.width/w};break;case"horizontal-cover":v={width:e.containerRect.width,height:e.containerRect.width/w};break;case"vertical-cover":v={width:e.containerRect.height*w,height:e.containerRect.height};break}else v={width:l.offsetWidth,height:l.offsetHeight};e.mediaSize=b(b({},v),{naturalWidth:h,naturalHeight:d}),e.props.setMediaSize&&e.props.setMediaSize(e.mediaSize);var f=e.props.cropSize?e.props.cropSize:Xe(e.mediaSize.width,e.mediaSize.height,e.containerRect.width,e.containerRect.height,e.props.aspect,e.props.rotation);return(((s=e.state.cropSize)===null||s===void 0?void 0:s.height)!==f.height||((c=e.state.cropSize)===null||c===void 0?void 0:c.width)!==f.width)&&e.props.onCropSizeChange&&e.props.onCropSizeChange(f),e.setState({cropSize:f},e.recomputeCropPosition),e.props.setCropSize&&e.props.setCropSize(f),f}},e.saveContainerPosition=function(){if(e.containerRef){var t=e.containerRef.getBoundingClientRect();e.containerPosition={x:t.left,y:t.top}}},e.onMouseDown=function(t){e.currentDoc&&(t.preventDefault(),e.currentDoc.addEventListener("mousemove",e.onMouseMove),e.currentDoc.addEventListener("mouseup",e.onDragStopped),e.saveContainerPosition(),e.onDragStart(o.getMousePoint(t)))},e.onMouseMove=function(t){return e.onDrag(o.getMousePoint(t))},e.onScroll=function(t){e.currentDoc&&(t.preventDefault(),e.saveContainerPosition())},e.onTouchStart=function(t){e.currentDoc&&(e.isTouching=!0,!(e.props.onTouchRequest&&!e.props.onTouchRequest(t))&&(e.currentDoc.addEventListener("touchmove",e.onTouchMove,{passive:!1}),e.currentDoc.addEventListener("touchend",e.onDragStopped),e.saveContainerPosition(),t.touches.length===2?e.onPinchStart(t):t.touches.length===1&&e.onDragStart(o.getTouchPoint(t.touches[0]))))},e.onTouchMove=function(t){t.preventDefault(),t.touches.length===2?e.onPinchMove(t):t.touches.length===1&&e.onDrag(o.getTouchPoint(t.touches[0]))},e.onGestureStart=function(t){e.currentDoc&&(t.preventDefault(),e.currentDoc.addEventListener("gesturechange",e.onGestureChange),e.currentDoc.addEventListener("gestureend",e.onGestureEnd),e.gestureZoomStart=e.props.zoom,e.gestureRotationStart=e.props.rotation)},e.onGestureChange=function(t){if(t.preventDefault(),!e.isTouching){var r=o.getMousePoint(t),i=e.gestureZoomStart-1+t.scale;if(e.setNewZoom(i,r,{shouldUpdatePosition:!0}),e.props.onRotationChange){var n=e.gestureRotationStart+t.rotation;e.props.onRotationChange(n)}}},e.onGestureEnd=function(t){e.cleanEvents()},e.onDragStart=function(t){var r,i,n=t.x,s=t.y;e.dragStartPosition={x:n,y:s},e.dragStartCrop=b({},e.props.crop),(i=(r=e.props).onInteractionStart)===null||i===void 0||i.call(r)},e.onDrag=function(t){var r=t.x,i=t.y;e.currentWindow&&(e.rafDragTimeout&&e.currentWindow.cancelAnimationFrame(e.rafDragTimeout),e.rafDragTimeout=e.currentWindow.requestAnimationFrame(function(){if(e.state.cropSize&&!(r===void 0||i===void 0)){var n=r-e.dragStartPosition.x,s=i-e.dragStartPosition.y,c={x:e.dragStartCrop.x+n,y:e.dragStartCrop.y+s},l=e.props.restrictPosition?N(c,e.mediaSize,e.state.cropSize,e.props.zoom,e.props.rotation):c;e.props.onCropChange(l)}}))},e.onDragStopped=function(){var t,r;e.isTouching=!1,e.cleanEvents(),e.emitCropData(),(r=(t=e.props).onInteractionEnd)===null||r===void 0||r.call(t)},e.onWheel=function(t){if(e.currentWindow&&!(e.props.onWheelRequest&&!e.props.onWheelRequest(t))){t.preventDefault();var r=o.getMousePoint(t),i=Ye(t).pixelY,n=e.props.zoom-i*e.props.zoomSpeed/200;e.setNewZoom(n,r,{shouldUpdatePosition:!0}),e.state.hasWheelJustStarted||e.setState({hasWheelJustStarted:!0},function(){var s,c;return(c=(s=e.props).onInteractionStart)===null||c===void 0?void 0:c.call(s)}),e.wheelTimer&&clearTimeout(e.wheelTimer),e.wheelTimer=e.currentWindow.setTimeout(function(){return e.setState({hasWheelJustStarted:!1},function(){var s,c;return(c=(s=e.props).onInteractionEnd)===null||c===void 0?void 0:c.call(s)})},250)}},e.getPointOnContainer=function(t,r){var i=t.x,n=t.y;if(!e.containerRect)throw new Error("The Cropper is not mounted");return{x:e.containerRect.width/2-(i-r.x),y:e.containerRect.height/2-(n-r.y)}},e.getPointOnMedia=function(t){var r=t.x,i=t.y,n=e.props,s=n.crop,c=n.zoom;return{x:(r+s.x)/c,y:(i+s.y)/c}},e.setNewZoom=function(t,r,i){var n=i===void 0?{}:i,s=n.shouldUpdatePosition,c=s===void 0?!0:s;if(!(!e.state.cropSize||!e.props.onZoomChange)){var l=O(t,e.props.minZoom,e.props.maxZoom);if(c){var u=e.getPointOnContainer(r,e.containerPosition),h=e.getPointOnMedia(u),d={x:h.x*l-u.x,y:h.y*l-u.y},m=e.props.restrictPosition?N(d,e.mediaSize,e.state.cropSize,l,e.props.rotation):d;e.props.onCropChange(m)}e.props.onZoomChange(l)}},e.getCropData=function(){if(!e.state.cropSize)return null;var t=e.props.restrictPosition?N(e.props.crop,e.mediaSize,e.state.cropSize,e.props.zoom,e.props.rotation):e.props.crop;return Ke(t,e.mediaSize,e.state.cropSize,e.getAspect(),e.props.zoom,e.props.rotation,e.props.restrictPosition)},e.emitCropData=function(){var t=e.getCropData();if(t){var r=t.croppedAreaPercentages,i=t.croppedAreaPixels;e.props.onCropComplete&&e.props.onCropComplete(r,i),e.props.onCropAreaChange&&e.props.onCropAreaChange(r,i)}},e.emitCropAreaChange=function(){var t=e.getCropData();if(t){var r=t.croppedAreaPercentages,i=t.croppedAreaPixels;e.props.onCropAreaChange&&e.props.onCropAreaChange(r,i)}},e.recomputeCropPosition=function(){var t,r;if(e.state.cropSize){var i=e.props.crop;if(e.isInitialized&&(!((t=e.previousCropSize)===null||t===void 0)&&t.width)&&(!((r=e.previousCropSize)===null||r===void 0)&&r.height)){var n=Math.abs(e.previousCropSize.width-e.state.cropSize.width)>1e-6||Math.abs(e.previousCropSize.height-e.state.cropSize.height)>1e-6;if(n){var s=e.state.cropSize.width/e.previousCropSize.width,c=e.state.cropSize.height/e.previousCropSize.height;i={x:e.props.crop.x*s,y:e.props.crop.y*c}}}var l=e.props.restrictPosition?N(i,e.mediaSize,e.state.cropSize,e.props.zoom,e.props.rotation):i;e.previousCropSize=e.state.cropSize,e.props.onCropChange(l),e.emitCropData()}},e.onKeyDown=function(t){var r,i,n=e.props,s=n.crop,c=n.onCropChange,l=n.keyboardStep,u=n.zoom,h=n.rotation,d=l;if(e.state.cropSize){t.shiftKey&&(d*=.2);var m=b({},s);switch(t.key){case"ArrowUp":m.y-=d,t.preventDefault();break;case"ArrowDown":m.y+=d,t.preventDefault();break;case"ArrowLeft":m.x-=d,t.preventDefault();break;case"ArrowRight":m.x+=d,t.preventDefault();break;default:return}e.props.restrictPosition&&(m=N(m,e.mediaSize,e.state.cropSize,u,h)),t.repeat||(i=(r=e.props).onInteractionStart)===null||i===void 0||i.call(r),c(m)}},e.onKeyUp=function(t){var r,i;switch(t.key){case"ArrowUp":case"ArrowDown":case"ArrowLeft":case"ArrowRight":t.preventDefault();break;default:return}e.emitCropData(),(i=(r=e.props).onInteractionEnd)===null||i===void 0||i.call(r)},e}return o.prototype.componentDidMount=function(){!this.currentDoc||!this.currentWindow||(this.containerRef&&(this.containerRef.ownerDocument&&(this.currentDoc=this.containerRef.ownerDocument),this.currentDoc.defaultView&&(this.currentWindow=this.currentDoc.defaultView),this.initResizeObserver(),typeof window.ResizeObserver>"u"&&this.currentWindow.addEventListener("resize",this.computeSizes),this.props.zoomWithScroll&&this.containerRef.addEventListener("wheel",this.onWheel,{passive:!1}),this.containerRef.addEventListener("gesturestart",this.onGestureStart)),this.currentDoc.addEventListener("scroll",this.onScroll),this.props.disableAutomaticStylesInjection||(this.styleRef=this.currentDoc.createElement("style"),this.styleRef.setAttribute("type","text/css"),this.props.nonce&&this.styleRef.setAttribute("nonce",this.props.nonce),this.styleRef.innerHTML=it,this.currentDoc.head.appendChild(this.styleRef)),this.imageRef.current&&this.imageRef.current.complete&&this.onMediaLoad(),this.props.setImageRef&&this.props.setImageRef(this.imageRef),this.props.setVideoRef&&this.props.setVideoRef(this.videoRef),this.props.setCropperRef&&this.props.setCropperRef(this.cropperRef))},o.prototype.componentWillUnmount=function(){var e,t;!this.currentDoc||!this.currentWindow||(typeof window.ResizeObserver>"u"&&this.currentWindow.removeEventListener("resize",this.computeSizes),(e=this.resizeObserver)===null||e===void 0||e.disconnect(),this.containerRef&&this.containerRef.removeEventListener("gesturestart",this.preventZoomSafari),this.styleRef&&((t=this.styleRef.parentNode)===null||t===void 0||t.removeChild(this.styleRef)),this.cleanEvents(),this.props.zoomWithScroll&&this.clearScrollEvent())},o.prototype.componentDidUpdate=function(e){var t,r,i,n,s,c,l,u,h;e.rotation!==this.props.rotation?(this.computeSizes(),this.recomputeCropPosition()):e.aspect!==this.props.aspect?this.computeSizes():e.objectFit!==this.props.objectFit?this.computeSizes():e.zoom!==this.props.zoom?this.recomputeCropPosition():((t=e.cropSize)===null||t===void 0?void 0:t.height)!==((r=this.props.cropSize)===null||r===void 0?void 0:r.height)||((i=e.cropSize)===null||i===void 0?void 0:i.width)!==((n=this.props.cropSize)===null||n===void 0?void 0:n.width)?this.computeSizes():(((s=e.crop)===null||s===void 0?void 0:s.x)!==((c=this.props.crop)===null||c===void 0?void 0:c.x)||((l=e.crop)===null||l===void 0?void 0:l.y)!==((u=this.props.crop)===null||u===void 0?void 0:u.y))&&this.emitCropAreaChange(),e.zoomWithScroll!==this.props.zoomWithScroll&&this.containerRef&&(this.props.zoomWithScroll?this.containerRef.addEventListener("wheel",this.onWheel,{passive:!1}):this.clearScrollEvent()),e.video!==this.props.video&&((h=this.videoRef.current)===null||h===void 0||h.load());var d=this.getObjectFit();d!==this.state.mediaObjectFit&&this.setState({mediaObjectFit:d},this.computeSizes)},o.prototype.getAspect=function(){var e=this.props,t=e.cropSize,r=e.aspect;return t?t.width/t.height:r},o.prototype.getObjectFit=function(){var e,t,r,i;if(this.props.objectFit==="cover"){var n=this.imageRef.current||this.videoRef.current;if(n&&this.containerRef){this.containerRect=this.containerRef.getBoundingClientRect();var s=this.containerRect.width/this.containerRect.height,c=((e=this.imageRef.current)===null||e===void 0?void 0:e.naturalWidth)||((t=this.videoRef.current)===null||t===void 0?void 0:t.videoWidth)||0,l=((r=this.imageRef.current)===null||r===void 0?void 0:r.naturalHeight)||((i=this.videoRef.current)===null||i===void 0?void 0:i.videoHeight)||0,u=c/l;return uArray.isArray(e)?e:Array.isArray(o)?o:[t,r],[e,o,t,r]);return p.jsxs(Se,{"data-slot":"slider",defaultValue:o,value:e,min:t,max:r,className:B("relative flex w-full touch-none items-center select-none data-[disabled]:opacity-50 data-[orientation=vertical]:h-full data-[orientation=vertical]:min-h-44 data-[orientation=vertical]:w-auto data-[orientation=vertical]:flex-col",a),...i,children:[p.jsx(_e,{"data-slot":"slider-track",className:B("bg-muted relative grow overflow-hidden rounded-full data-[orientation=horizontal]:h-4 data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-1.5"),children:p.jsx(ze,{"data-slot":"slider-range",className:B("bg-primary absolute data-[orientation=horizontal]:h-full data-[orientation=vertical]:w-full")})}),Array.from({length:n.length},(s,c)=>p.jsx(De,{"data-slot":"slider-thumb",className:"border-primary bg-background ring-ring/50 block size-4 shrink-0 rounded-full border shadow-sm transition-[color,box-shadow] hover:ring-4 focus-visible:ring-4 focus-visible:outline-hidden disabled:pointer-events-none disabled:opacity-50"},c))]})}const de=["image/png","image/jpeg","image/webp"],he=2*1024*1024,fe=256,ut=a=>{const o=a.normalize("NFKD").toLowerCase(),e=o.lastIndexOf("."),t=e>0?o.slice(0,e):o,r=e>0?o.slice(e).replace(/[^.a-z0-9]/g,""):"";return`${t.replace(/[^a-z0-9]+/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"")||"profile-picture"}${r}`},pt=(a,o,e=Date.now())=>`profile-pictures/${a}/${e}-${ut(o)}`,me=a=>de.includes(a.type)?a.size>he?"Profile pictures must be 2MB or smaller.":a.name.trim()?null:"Please choose a valid image file.":"Only PNG, JPEG, and WebP images are allowed.",dt=a=>new Promise((o,e)=>{const t=URL.createObjectURL(a),r=new Image,i=setTimeout(()=>{URL.revokeObjectURL(t),e(new Error("Image loading timed out. Please try a different file."))},15e3);r.onload=()=>{clearTimeout(i),URL.revokeObjectURL(t),o(r)},r.onerror=()=>{clearTimeout(i),URL.revokeObjectURL(t),e(new Error("Unable to read the selected image. Please try another file."))},r.crossOrigin="anonymous",r.src=t}),ue=(a,o,e)=>new Promise((t,r)=>{a.toBlob(i=>{if(!i){r(new Error("Failed to prepare the image for upload."));return}t(i)},o,e)}),ht=async(a,o=fe)=>{const e=await dt(a),t=document.createElement("canvas");t.width=o,t.height=o;const r=t.getContext("2d");if(!r)throw new Error("Your browser cannot process image uploads right now.");const i=e.naturalWidth||e.width,n=e.naturalHeight||e.height,s=Math.min(i,n),c=Math.max(0,(i-s)/2),l=Math.max(0,(n-s)/2);r.clearRect(0,0,o,o),r.drawImage(e,c,l,s,s,0,0,o,o);try{return await ue(t,"image/webp",.9)}catch{return await ue(t,"image/jpeg",.9)}},j=(a,o,e)=>{let t;const r=new Promise((i,n)=>{t=setTimeout(()=>n(new Error(`${e} timed out after ${Math.round(o/1e3)}s`)),o)});return Promise.race([a,r]).finally(()=>clearTimeout(t))},ft=async(a,o,e)=>{const t=we.options.projectId;if(!t)throw new Error("Firebase project ID is not configured.");const r=await a.getIdToken(),i=`https://firestore.googleapis.com/v1/projects/${t}/databases/(default)/documents/users/${o}?updateMask.fieldPaths=photo&updateMask.fieldPaths=updatedAt`,n=await fetch(i,{method:"PATCH",headers:{Authorization:`Bearer ${r}`,"Content-Type":"application/json"},body:JSON.stringify({fields:{photo:{stringValue:e},updatedAt:{timestampValue:new Date().toISOString()}}})});if(!n.ok){const s=await n.text().catch(()=>"");throw new Error(`Firestore REST update failed (${n.status}): ${s}`)}},mt=async({file:a,uid:o,currentUser:e=K.currentUser,syncFirestore:t=!0})=>{const r=me(a);if(r)throw new Error(r);const i=e??K.currentUser;if(!i)throw new Error("You need to be signed in to change your profile picture.");const n=o||i.uid;if(!n)throw new Error("Unable to determine which profile should be updated.");if(i.uid!==n)throw new Error("The signed-in user does not match the profile being edited.");const s=await j(ht(a,fe),2e4,"Image processing"),c=pt(n,a.name),l=Ae(ge,c),u=await j(Te(l,s,{contentType:s.type||"image/webp",cacheControl:"public, max-age=31536000, immutable"}),3e4,"Storage upload"),h=await j(Ne(u.ref),1e4,"Download URL retrieval");try{await j(Me(i,{photoURL:h}),1e4,"Auth profile update")}catch(d){console.warn("[PROFILE UPLOAD] Auth profile update failed (non-fatal):",d)}if(t){try{await j(ft(i,n,h),1e4,"Firestore profile sync")}catch(d){console.error("[PROFILE UPLOAD] Firestore REST sync failed:",d),console.warn("[PROFILE UPLOAD] Photo was uploaded but the database record may be stale. It will refresh on next login.")}try{const{doc:d,updateDoc:m}=await $(async()=>{const{doc:v,updateDoc:f}=await import("./vendor-firebase-firestore-CNv3xXal.js");return{doc:v,updateDoc:f}},__vite__mapDeps([0,1])),{db:w}=await $(async()=>{const{db:v}=await import("./index-BufUS6SI.js").then(f=>f.b7);return{db:v}},__vite__mapDeps([2,3,0,1,4,5,6,7,8,9,10,11]));await m(d(w,"leaderboard",n),{photo:h}).catch(()=>$(async()=>{const{setDoc:v}=await import("./vendor-firebase-firestore-CNv3xXal.js");return{setDoc:v}},__vite__mapDeps([0,1])).then(({setDoc:v})=>v(d(w,"leaderboard",n),{photo:h},{merge:!0})))}catch{}}return h},vt=a=>`${(a/(1024*1024)).toFixed(1)} MB`,gt=a=>{const o=(a||"").trim();return o?o.split(/\s+/).slice(0,2).map(e=>e[0]?.toUpperCase()).join(""):"U"},wt=a=>new Promise((o,e)=>{const t=new Image;t.onload=()=>o(t),t.onerror=()=>e(new Error("Unable to load the image for cropping.")),t.src=a}),pe=(a,o,e)=>new Promise((t,r)=>{a.toBlob(i=>{if(!i){r(new Error("Failed to prepare the cropped image."));return}t(i)},o,e)}),xt=async(a,o,e)=>{const t=await wt(a),r=document.createElement("canvas"),i=640;r.width=i,r.height=i;const n=r.getContext("2d");if(!n)throw new Error("Your browser cannot process the selected image right now.");n.clearRect(0,0,i,i),n.drawImage(t,o.x,o.y,o.width,o.height,0,0,i,i);let s;try{s=await pe(r,"image/webp",.92)}catch{s=await pe(r,"image/jpeg",.92)}if(!s)throw new Error("Could not create an image from the cropped area.");const c=s.type==="image/webp"?"webp":"jpg",u=`${e.name.replace(/\.[^/.]+$/,"")||"profile-picture"}-cropped.${c}`;return new File([s],u,{type:s.type,lastModified:Date.now()})},Nt=({uid:a,photoURL:o,displayName:e,className:t="",onUploaded:r,syncFirestore:i=!0})=>{const{currentUser:n,refreshProfile:s}=xe(),[c,l]=x.useState(null),[u,h]=x.useState(null),[d,m]=x.useState({x:0,y:0}),[w,v]=x.useState(1),[f,R]=x.useState(null),[y,g]=x.useState(""),[E,_]=x.useState(!1),P=x.useRef(null);x.useEffect(()=>{if(!c){h(null);return}const C=URL.createObjectURL(c);return h(C),()=>URL.revokeObjectURL(C)},[c]);const k=u||o||"",W=x.useMemo(()=>`${de.map(S=>S.replace("image/","").toUpperCase()).join(", ")} up to ${vt(he)}. The image will be cropped to a circular avatar.`,[]),D=()=>{l(null),m({x:0,y:0}),v(1),R(null),g(""),P.current&&(P.current.value="")},z=C=>{const S=C.target.files?.[0]||null;if(!S)return;const M=me(S);if(M){g(M),l(null),C.target.value="";return}g(""),l(S),m({x:0,y:0}),v(1),R(null)},T=async()=>{if(!c){g("Choose an image before saving.");return}_(!0),g("");const C=6e4;let S;try{const M=(async()=>{const I=u&&f?await xt(u,f,c):c,Z=a||n?.uid;return mt({file:I,uid:Z,currentUser:n,syncFirestore:i})})(),F=new Promise((I,Z)=>{S=setTimeout(()=>Z(new Error("Upload timed out. Please check your connection and try again.")),C)}),ve=await Promise.race([M,F]);r?.(ve),s().catch(I=>console.warn("[ProfilePictureUploader] refreshProfile failed:",I)),Q.success("Profile picture updated."),D()}catch(M){const F=M instanceof Error?M.message:"Failed to update your profile picture.";g(F),Q.error(F)}finally{clearTimeout(S),_(!1)}},U=()=>{P.current?.click()};return p.jsxs(p.Fragment,{children:[p.jsxs("section",{className:`flex items-center gap-4 rounded-xl border border-slate-200 bg-white p-4 shadow-sm ${t}`,children:[p.jsxs("div",{className:"relative cursor-pointer group",onClick:U,role:"button",tabIndex:0,onKeyDown:C=>C.key==="Enter"&&U(),"aria-label":"Change profile picture",children:[p.jsxs(ye,{className:"size-16 sm:size-20 ring-4 ring-sky-50 shadow-sm transition-transform duration-200 group-hover:scale-105",children:[p.jsx(be,{src:k,alt:`${e||"User"} profile picture`}),p.jsx(Ce,{className:"bg-gradient-to-br from-sky-600 to-cyan-500 text-lg font-semibold text-white",children:gt(e)})]}),p.jsx("span",{className:"absolute -right-1 -top-1 inline-flex items-center justify-center rounded-full bg-slate-900 p-1.5 text-white shadow-md transition-colors group-hover:bg-slate-700",children:p.jsx(Oe,{size:14})})]}),p.jsxs("div",{className:"space-y-1 flex-1",children:[p.jsx("p",{className:"text-sm font-semibold text-slate-900",children:"Profile picture"}),p.jsx("p",{className:"text-xs text-slate-500",children:"Click your avatar to upload a new photo."}),y&&p.jsx("p",{className:"text-xs font-medium text-rose-600 mt-1",children:y})]}),p.jsx("input",{ref:P,type:"file",accept:"image/*",onChange:z,className:"sr-only","aria-label":"Choose profile picture"})]}),p.jsx(Pe,{children:u&&p.jsxs(p.Fragment,{children:[p.jsx(J.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 bg-black/60 backdrop-blur-sm z-[60]",onClick:D}),p.jsx(J.div,{initial:{opacity:0,scale:.95,y:20},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:20},transition:{type:"spring",duration:.5,bounce:.3},className:"fixed inset-0 z-[60] flex items-center justify-center p-4 sm:p-6",onClick:C=>C.stopPropagation(),children:p.jsxs("div",{className:"bg-white rounded-2xl shadow-xl w-full max-w-lg overflow-hidden flex flex-col",children:[p.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-slate-100",children:[p.jsx("h3",{className:"text-lg font-bold text-slate-900",children:"Update profile picture"}),p.jsx("button",{onClick:D,className:"p-2 text-slate-400 hover:text-slate-600 hover:bg-slate-100 rounded-full transition-colors","aria-label":"Close modal",children:p.jsx(je,{size:20})})]}),p.jsxs("div",{className:"p-4 sm:p-6 bg-slate-50 flex flex-col items-center",children:[p.jsx("div",{className:"relative h-[350px] sm:h-[450px] w-[350px] sm:w-[450px] mx-auto overflow-hidden rounded-xl bg-slate-100 ring-1 ring-inset ring-slate-200 shadow-inner",children:p.jsx(ct,{image:u,crop:d,zoom:w,aspect:1,cropShape:"round",showGrid:!1,objectFit:"cover",restrictPosition:!0,onCropChange:m,onZoomChange:v,onCropComplete:(C,S)=>R(S),style:{containerStyle:{backgroundColor:"#f8fafc"}}})}),p.jsxs("div",{className:"mt-6 w-full max-w-xs flex items-center gap-4",children:[p.jsx(Ue,{size:18,className:"text-slate-500"}),p.jsx(lt,{value:[w],min:1,max:3,step:.05,onValueChange:C=>v(C[0]||1),"aria-label":"Profile picture zoom",className:"flex-1 cursor-pointer"}),p.jsx(Fe,{size:18,className:"text-slate-500"})]}),p.jsx("p",{className:"mt-4 text-xs text-slate-500 text-center",children:W})]}),p.jsxs("div",{className:"p-4 border-t border-slate-100 flex items-center justify-end gap-3 bg-white",children:[p.jsx(ee,{type:"button",variant:"ghost",onClick:D,disabled:E,className:"font-medium text-slate-600 hover:text-slate-900 hover:bg-slate-100 px-5",children:"Cancel"}),p.jsx(ee,{type:"button",onClick:T,disabled:E||!c,className:"bg-sky-600 hover:bg-sky-700 text-white min-w-[120px] gap-2 shadow-sm",children:E?p.jsxs(p.Fragment,{children:[p.jsx(Ie,{size:16,className:"animate-pulse"}),"Saving..."]}):"Save picture"})]})]})})]})})]})};export{At as M,Nt as P,Tt as V}; +`,nt=1,at=3,st=1,ct=(function(a){Ee(o,a);function o(){var e=a!==null&&a.apply(this,arguments)||this;return e.cropperRef=x.createRef(),e.imageRef=x.createRef(),e.videoRef=x.createRef(),e.containerPosition={x:0,y:0},e.containerRef=null,e.styleRef=null,e.containerRect=null,e.mediaSize={width:0,height:0,naturalWidth:0,naturalHeight:0},e.dragStartPosition={x:0,y:0},e.dragStartCrop={x:0,y:0},e.gestureZoomStart=0,e.gestureRotationStart=0,e.isTouching=!1,e.lastPinchDistance=0,e.lastPinchRotation=0,e.rafDragTimeout=null,e.rafPinchTimeout=null,e.wheelTimer=null,e.currentDoc=typeof document<"u"?document:null,e.currentWindow=typeof window<"u"?window:null,e.resizeObserver=null,e.previousCropSize=null,e.isInitialized=!1,e.state={cropSize:null,hasWheelJustStarted:!1,mediaObjectFit:void 0},e.initResizeObserver=function(){if(!(typeof window.ResizeObserver>"u"||!e.containerRef)){var t=!0;e.resizeObserver=new window.ResizeObserver(function(r){if(t){t=!1;return}e.computeSizes()}),e.resizeObserver.observe(e.containerRef)}},e.preventZoomSafari=function(t){return t.preventDefault()},e.cleanEvents=function(){e.currentDoc&&(e.currentDoc.removeEventListener("mousemove",e.onMouseMove),e.currentDoc.removeEventListener("mouseup",e.onDragStopped),e.currentDoc.removeEventListener("touchmove",e.onTouchMove),e.currentDoc.removeEventListener("touchend",e.onDragStopped),e.currentDoc.removeEventListener("gesturechange",e.onGestureChange),e.currentDoc.removeEventListener("gestureend",e.onGestureEnd),e.currentDoc.removeEventListener("scroll",e.onScroll))},e.clearScrollEvent=function(){e.containerRef&&e.containerRef.removeEventListener("wheel",e.onWheel),e.wheelTimer&&clearTimeout(e.wheelTimer)},e.onMediaLoad=function(){var t=e.computeSizes();t&&(e.previousCropSize=t,e.emitCropData(),e.setInitialCrop(t),e.isInitialized=!0),e.props.onMediaLoaded&&e.props.onMediaLoaded(e.mediaSize)},e.setInitialCrop=function(t){if(e.props.initialCroppedAreaPercentages){var r=et(e.props.initialCroppedAreaPercentages,e.mediaSize,e.props.rotation,t,e.props.minZoom,e.props.maxZoom),i=r.crop,n=r.zoom;e.props.onCropChange(i),e.props.onZoomChange&&e.props.onZoomChange(n)}else if(e.props.initialCroppedAreaPixels){var s=rt(e.props.initialCroppedAreaPixels,e.mediaSize,e.props.rotation,t,e.props.minZoom,e.props.maxZoom),i=s.crop,n=s.zoom;e.props.onCropChange(i),e.props.onZoomChange&&e.props.onZoomChange(n)}},e.computeSizes=function(){var t,r,i,n,s,c,l=e.imageRef.current||e.videoRef.current;if(l&&e.containerRef){e.containerRect=e.containerRef.getBoundingClientRect(),e.saveContainerPosition();var u=e.containerRect.width/e.containerRect.height,h=((t=e.imageRef.current)===null||t===void 0?void 0:t.naturalWidth)||((r=e.videoRef.current)===null||r===void 0?void 0:r.videoWidth)||0,d=((i=e.imageRef.current)===null||i===void 0?void 0:i.naturalHeight)||((n=e.videoRef.current)===null||n===void 0?void 0:n.videoHeight)||0,m=l.offsetWidthw?{width:e.containerRect.height*w,height:e.containerRect.height}:{width:e.containerRect.width,height:e.containerRect.width/w};break;case"horizontal-cover":v={width:e.containerRect.width,height:e.containerRect.width/w};break;case"vertical-cover":v={width:e.containerRect.height*w,height:e.containerRect.height};break}else v={width:l.offsetWidth,height:l.offsetHeight};e.mediaSize=b(b({},v),{naturalWidth:h,naturalHeight:d}),e.props.setMediaSize&&e.props.setMediaSize(e.mediaSize);var f=e.props.cropSize?e.props.cropSize:Xe(e.mediaSize.width,e.mediaSize.height,e.containerRect.width,e.containerRect.height,e.props.aspect,e.props.rotation);return(((s=e.state.cropSize)===null||s===void 0?void 0:s.height)!==f.height||((c=e.state.cropSize)===null||c===void 0?void 0:c.width)!==f.width)&&e.props.onCropSizeChange&&e.props.onCropSizeChange(f),e.setState({cropSize:f},e.recomputeCropPosition),e.props.setCropSize&&e.props.setCropSize(f),f}},e.saveContainerPosition=function(){if(e.containerRef){var t=e.containerRef.getBoundingClientRect();e.containerPosition={x:t.left,y:t.top}}},e.onMouseDown=function(t){e.currentDoc&&(t.preventDefault(),e.currentDoc.addEventListener("mousemove",e.onMouseMove),e.currentDoc.addEventListener("mouseup",e.onDragStopped),e.saveContainerPosition(),e.onDragStart(o.getMousePoint(t)))},e.onMouseMove=function(t){return e.onDrag(o.getMousePoint(t))},e.onScroll=function(t){e.currentDoc&&(t.preventDefault(),e.saveContainerPosition())},e.onTouchStart=function(t){e.currentDoc&&(e.isTouching=!0,!(e.props.onTouchRequest&&!e.props.onTouchRequest(t))&&(e.currentDoc.addEventListener("touchmove",e.onTouchMove,{passive:!1}),e.currentDoc.addEventListener("touchend",e.onDragStopped),e.saveContainerPosition(),t.touches.length===2?e.onPinchStart(t):t.touches.length===1&&e.onDragStart(o.getTouchPoint(t.touches[0]))))},e.onTouchMove=function(t){t.preventDefault(),t.touches.length===2?e.onPinchMove(t):t.touches.length===1&&e.onDrag(o.getTouchPoint(t.touches[0]))},e.onGestureStart=function(t){e.currentDoc&&(t.preventDefault(),e.currentDoc.addEventListener("gesturechange",e.onGestureChange),e.currentDoc.addEventListener("gestureend",e.onGestureEnd),e.gestureZoomStart=e.props.zoom,e.gestureRotationStart=e.props.rotation)},e.onGestureChange=function(t){if(t.preventDefault(),!e.isTouching){var r=o.getMousePoint(t),i=e.gestureZoomStart-1+t.scale;if(e.setNewZoom(i,r,{shouldUpdatePosition:!0}),e.props.onRotationChange){var n=e.gestureRotationStart+t.rotation;e.props.onRotationChange(n)}}},e.onGestureEnd=function(t){e.cleanEvents()},e.onDragStart=function(t){var r,i,n=t.x,s=t.y;e.dragStartPosition={x:n,y:s},e.dragStartCrop=b({},e.props.crop),(i=(r=e.props).onInteractionStart)===null||i===void 0||i.call(r)},e.onDrag=function(t){var r=t.x,i=t.y;e.currentWindow&&(e.rafDragTimeout&&e.currentWindow.cancelAnimationFrame(e.rafDragTimeout),e.rafDragTimeout=e.currentWindow.requestAnimationFrame(function(){if(e.state.cropSize&&!(r===void 0||i===void 0)){var n=r-e.dragStartPosition.x,s=i-e.dragStartPosition.y,c={x:e.dragStartCrop.x+n,y:e.dragStartCrop.y+s},l=e.props.restrictPosition?N(c,e.mediaSize,e.state.cropSize,e.props.zoom,e.props.rotation):c;e.props.onCropChange(l)}}))},e.onDragStopped=function(){var t,r;e.isTouching=!1,e.cleanEvents(),e.emitCropData(),(r=(t=e.props).onInteractionEnd)===null||r===void 0||r.call(t)},e.onWheel=function(t){if(e.currentWindow&&!(e.props.onWheelRequest&&!e.props.onWheelRequest(t))){t.preventDefault();var r=o.getMousePoint(t),i=Ye(t).pixelY,n=e.props.zoom-i*e.props.zoomSpeed/200;e.setNewZoom(n,r,{shouldUpdatePosition:!0}),e.state.hasWheelJustStarted||e.setState({hasWheelJustStarted:!0},function(){var s,c;return(c=(s=e.props).onInteractionStart)===null||c===void 0?void 0:c.call(s)}),e.wheelTimer&&clearTimeout(e.wheelTimer),e.wheelTimer=e.currentWindow.setTimeout(function(){return e.setState({hasWheelJustStarted:!1},function(){var s,c;return(c=(s=e.props).onInteractionEnd)===null||c===void 0?void 0:c.call(s)})},250)}},e.getPointOnContainer=function(t,r){var i=t.x,n=t.y;if(!e.containerRect)throw new Error("The Cropper is not mounted");return{x:e.containerRect.width/2-(i-r.x),y:e.containerRect.height/2-(n-r.y)}},e.getPointOnMedia=function(t){var r=t.x,i=t.y,n=e.props,s=n.crop,c=n.zoom;return{x:(r+s.x)/c,y:(i+s.y)/c}},e.setNewZoom=function(t,r,i){var n=i===void 0?{}:i,s=n.shouldUpdatePosition,c=s===void 0?!0:s;if(!(!e.state.cropSize||!e.props.onZoomChange)){var l=O(t,e.props.minZoom,e.props.maxZoom);if(c){var u=e.getPointOnContainer(r,e.containerPosition),h=e.getPointOnMedia(u),d={x:h.x*l-u.x,y:h.y*l-u.y},m=e.props.restrictPosition?N(d,e.mediaSize,e.state.cropSize,l,e.props.rotation):d;e.props.onCropChange(m)}e.props.onZoomChange(l)}},e.getCropData=function(){if(!e.state.cropSize)return null;var t=e.props.restrictPosition?N(e.props.crop,e.mediaSize,e.state.cropSize,e.props.zoom,e.props.rotation):e.props.crop;return Ke(t,e.mediaSize,e.state.cropSize,e.getAspect(),e.props.zoom,e.props.rotation,e.props.restrictPosition)},e.emitCropData=function(){var t=e.getCropData();if(t){var r=t.croppedAreaPercentages,i=t.croppedAreaPixels;e.props.onCropComplete&&e.props.onCropComplete(r,i),e.props.onCropAreaChange&&e.props.onCropAreaChange(r,i)}},e.emitCropAreaChange=function(){var t=e.getCropData();if(t){var r=t.croppedAreaPercentages,i=t.croppedAreaPixels;e.props.onCropAreaChange&&e.props.onCropAreaChange(r,i)}},e.recomputeCropPosition=function(){var t,r;if(e.state.cropSize){var i=e.props.crop;if(e.isInitialized&&(!((t=e.previousCropSize)===null||t===void 0)&&t.width)&&(!((r=e.previousCropSize)===null||r===void 0)&&r.height)){var n=Math.abs(e.previousCropSize.width-e.state.cropSize.width)>1e-6||Math.abs(e.previousCropSize.height-e.state.cropSize.height)>1e-6;if(n){var s=e.state.cropSize.width/e.previousCropSize.width,c=e.state.cropSize.height/e.previousCropSize.height;i={x:e.props.crop.x*s,y:e.props.crop.y*c}}}var l=e.props.restrictPosition?N(i,e.mediaSize,e.state.cropSize,e.props.zoom,e.props.rotation):i;e.previousCropSize=e.state.cropSize,e.props.onCropChange(l),e.emitCropData()}},e.onKeyDown=function(t){var r,i,n=e.props,s=n.crop,c=n.onCropChange,l=n.keyboardStep,u=n.zoom,h=n.rotation,d=l;if(e.state.cropSize){t.shiftKey&&(d*=.2);var m=b({},s);switch(t.key){case"ArrowUp":m.y-=d,t.preventDefault();break;case"ArrowDown":m.y+=d,t.preventDefault();break;case"ArrowLeft":m.x-=d,t.preventDefault();break;case"ArrowRight":m.x+=d,t.preventDefault();break;default:return}e.props.restrictPosition&&(m=N(m,e.mediaSize,e.state.cropSize,u,h)),t.repeat||(i=(r=e.props).onInteractionStart)===null||i===void 0||i.call(r),c(m)}},e.onKeyUp=function(t){var r,i;switch(t.key){case"ArrowUp":case"ArrowDown":case"ArrowLeft":case"ArrowRight":t.preventDefault();break;default:return}e.emitCropData(),(i=(r=e.props).onInteractionEnd)===null||i===void 0||i.call(r)},e}return o.prototype.componentDidMount=function(){!this.currentDoc||!this.currentWindow||(this.containerRef&&(this.containerRef.ownerDocument&&(this.currentDoc=this.containerRef.ownerDocument),this.currentDoc.defaultView&&(this.currentWindow=this.currentDoc.defaultView),this.initResizeObserver(),typeof window.ResizeObserver>"u"&&this.currentWindow.addEventListener("resize",this.computeSizes),this.props.zoomWithScroll&&this.containerRef.addEventListener("wheel",this.onWheel,{passive:!1}),this.containerRef.addEventListener("gesturestart",this.onGestureStart)),this.currentDoc.addEventListener("scroll",this.onScroll),this.props.disableAutomaticStylesInjection||(this.styleRef=this.currentDoc.createElement("style"),this.styleRef.setAttribute("type","text/css"),this.props.nonce&&this.styleRef.setAttribute("nonce",this.props.nonce),this.styleRef.innerHTML=it,this.currentDoc.head.appendChild(this.styleRef)),this.imageRef.current&&this.imageRef.current.complete&&this.onMediaLoad(),this.props.setImageRef&&this.props.setImageRef(this.imageRef),this.props.setVideoRef&&this.props.setVideoRef(this.videoRef),this.props.setCropperRef&&this.props.setCropperRef(this.cropperRef))},o.prototype.componentWillUnmount=function(){var e,t;!this.currentDoc||!this.currentWindow||(typeof window.ResizeObserver>"u"&&this.currentWindow.removeEventListener("resize",this.computeSizes),(e=this.resizeObserver)===null||e===void 0||e.disconnect(),this.containerRef&&this.containerRef.removeEventListener("gesturestart",this.preventZoomSafari),this.styleRef&&((t=this.styleRef.parentNode)===null||t===void 0||t.removeChild(this.styleRef)),this.cleanEvents(),this.props.zoomWithScroll&&this.clearScrollEvent())},o.prototype.componentDidUpdate=function(e){var t,r,i,n,s,c,l,u,h;e.rotation!==this.props.rotation?(this.computeSizes(),this.recomputeCropPosition()):e.aspect!==this.props.aspect?this.computeSizes():e.objectFit!==this.props.objectFit?this.computeSizes():e.zoom!==this.props.zoom?this.recomputeCropPosition():((t=e.cropSize)===null||t===void 0?void 0:t.height)!==((r=this.props.cropSize)===null||r===void 0?void 0:r.height)||((i=e.cropSize)===null||i===void 0?void 0:i.width)!==((n=this.props.cropSize)===null||n===void 0?void 0:n.width)?this.computeSizes():(((s=e.crop)===null||s===void 0?void 0:s.x)!==((c=this.props.crop)===null||c===void 0?void 0:c.x)||((l=e.crop)===null||l===void 0?void 0:l.y)!==((u=this.props.crop)===null||u===void 0?void 0:u.y))&&this.emitCropAreaChange(),e.zoomWithScroll!==this.props.zoomWithScroll&&this.containerRef&&(this.props.zoomWithScroll?this.containerRef.addEventListener("wheel",this.onWheel,{passive:!1}):this.clearScrollEvent()),e.video!==this.props.video&&((h=this.videoRef.current)===null||h===void 0||h.load());var d=this.getObjectFit();d!==this.state.mediaObjectFit&&this.setState({mediaObjectFit:d},this.computeSizes)},o.prototype.getAspect=function(){var e=this.props,t=e.cropSize,r=e.aspect;return t?t.width/t.height:r},o.prototype.getObjectFit=function(){var e,t,r,i;if(this.props.objectFit==="cover"){var n=this.imageRef.current||this.videoRef.current;if(n&&this.containerRef){this.containerRect=this.containerRef.getBoundingClientRect();var s=this.containerRect.width/this.containerRect.height,c=((e=this.imageRef.current)===null||e===void 0?void 0:e.naturalWidth)||((t=this.videoRef.current)===null||t===void 0?void 0:t.videoWidth)||0,l=((r=this.imageRef.current)===null||r===void 0?void 0:r.naturalHeight)||((i=this.videoRef.current)===null||i===void 0?void 0:i.videoHeight)||0,u=c/l;return uArray.isArray(e)?e:Array.isArray(o)?o:[t,r],[e,o,t,r]);return p.jsxs(Se,{"data-slot":"slider",defaultValue:o,value:e,min:t,max:r,className:B("relative flex w-full touch-none items-center select-none data-[disabled]:opacity-50 data-[orientation=vertical]:h-full data-[orientation=vertical]:min-h-44 data-[orientation=vertical]:w-auto data-[orientation=vertical]:flex-col",a),...i,children:[p.jsx(_e,{"data-slot":"slider-track",className:B("bg-muted relative grow overflow-hidden rounded-full data-[orientation=horizontal]:h-4 data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-1.5"),children:p.jsx(ze,{"data-slot":"slider-range",className:B("bg-primary absolute data-[orientation=horizontal]:h-full data-[orientation=vertical]:w-full")})}),Array.from({length:n.length},(s,c)=>p.jsx(De,{"data-slot":"slider-thumb",className:"border-primary bg-background ring-ring/50 block size-4 shrink-0 rounded-full border shadow-sm transition-[color,box-shadow] hover:ring-4 focus-visible:ring-4 focus-visible:outline-hidden disabled:pointer-events-none disabled:opacity-50"},c))]})}const de=["image/png","image/jpeg","image/webp"],he=2*1024*1024,fe=256,ut=a=>{const o=a.normalize("NFKD").toLowerCase(),e=o.lastIndexOf("."),t=e>0?o.slice(0,e):o,r=e>0?o.slice(e).replace(/[^.a-z0-9]/g,""):"";return`${t.replace(/[^a-z0-9]+/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"")||"profile-picture"}${r}`},pt=(a,o,e=Date.now())=>`profile-pictures/${a}/${e}-${ut(o)}`,me=a=>de.includes(a.type)?a.size>he?"Profile pictures must be 2MB or smaller.":a.name.trim()?null:"Please choose a valid image file.":"Only PNG, JPEG, and WebP images are allowed.",dt=a=>new Promise((o,e)=>{const t=URL.createObjectURL(a),r=new Image,i=setTimeout(()=>{URL.revokeObjectURL(t),e(new Error("Image loading timed out. Please try a different file."))},15e3);r.onload=()=>{clearTimeout(i),URL.revokeObjectURL(t),o(r)},r.onerror=()=>{clearTimeout(i),URL.revokeObjectURL(t),e(new Error("Unable to read the selected image. Please try another file."))},r.crossOrigin="anonymous",r.src=t}),ue=(a,o,e)=>new Promise((t,r)=>{a.toBlob(i=>{if(!i){r(new Error("Failed to prepare the image for upload."));return}t(i)},o,e)}),ht=async(a,o=fe)=>{const e=await dt(a),t=document.createElement("canvas");t.width=o,t.height=o;const r=t.getContext("2d");if(!r)throw new Error("Your browser cannot process image uploads right now.");const i=e.naturalWidth||e.width,n=e.naturalHeight||e.height,s=Math.min(i,n),c=Math.max(0,(i-s)/2),l=Math.max(0,(n-s)/2);r.clearRect(0,0,o,o),r.drawImage(e,c,l,s,s,0,0,o,o);try{return await ue(t,"image/webp",.9)}catch{return await ue(t,"image/jpeg",.9)}},j=(a,o,e)=>{let t;const r=new Promise((i,n)=>{t=setTimeout(()=>n(new Error(`${e} timed out after ${Math.round(o/1e3)}s`)),o)});return Promise.race([a,r]).finally(()=>clearTimeout(t))},ft=async(a,o,e)=>{const t=we.options.projectId;if(!t)throw new Error("Firebase project ID is not configured.");const r=await a.getIdToken(),i=`https://firestore.googleapis.com/v1/projects/${t}/databases/(default)/documents/users/${o}?updateMask.fieldPaths=photo&updateMask.fieldPaths=updatedAt`,n=await fetch(i,{method:"PATCH",headers:{Authorization:`Bearer ${r}`,"Content-Type":"application/json"},body:JSON.stringify({fields:{photo:{stringValue:e},updatedAt:{timestampValue:new Date().toISOString()}}})});if(!n.ok){const s=await n.text().catch(()=>"");throw new Error(`Firestore REST update failed (${n.status}): ${s}`)}},mt=async({file:a,uid:o,currentUser:e=K.currentUser,syncFirestore:t=!0})=>{const r=me(a);if(r)throw new Error(r);const i=e??K.currentUser;if(!i)throw new Error("You need to be signed in to change your profile picture.");const n=o||i.uid;if(!n)throw new Error("Unable to determine which profile should be updated.");if(i.uid!==n)throw new Error("The signed-in user does not match the profile being edited.");const s=await j(ht(a,fe),2e4,"Image processing"),c=pt(n,a.name),l=Ae(ge,c),u=await j(Te(l,s,{contentType:s.type||"image/webp",cacheControl:"public, max-age=31536000, immutable"}),3e4,"Storage upload"),h=await j(Ne(u.ref),1e4,"Download URL retrieval");try{await j(Me(i,{photoURL:h}),1e4,"Auth profile update")}catch(d){console.warn("[PROFILE UPLOAD] Auth profile update failed (non-fatal):",d)}if(t){try{await j(ft(i,n,h),1e4,"Firestore profile sync")}catch(d){console.error("[PROFILE UPLOAD] Firestore REST sync failed:",d),console.warn("[PROFILE UPLOAD] Photo was uploaded but the database record may be stale. It will refresh on next login.")}try{const{doc:d,updateDoc:m}=await $(async()=>{const{doc:v,updateDoc:f}=await import("./vendor-firebase-firestore-CNv3xXal.js");return{doc:v,updateDoc:f}},__vite__mapDeps([0,1])),{db:w}=await $(async()=>{const{db:v}=await import("./index-Bp7MiGcW.js").then(f=>f.b7);return{db:v}},__vite__mapDeps([2,3,0,1,4,5,6,7,8,9,10,11]));await m(d(w,"leaderboard",n),{photo:h}).catch(()=>$(async()=>{const{setDoc:v}=await import("./vendor-firebase-firestore-CNv3xXal.js");return{setDoc:v}},__vite__mapDeps([0,1])).then(({setDoc:v})=>v(d(w,"leaderboard",n),{photo:h},{merge:!0})))}catch{}}return h},vt=a=>`${(a/(1024*1024)).toFixed(1)} MB`,gt=a=>{const o=(a||"").trim();return o?o.split(/\s+/).slice(0,2).map(e=>e[0]?.toUpperCase()).join(""):"U"},wt=a=>new Promise((o,e)=>{const t=new Image;t.onload=()=>o(t),t.onerror=()=>e(new Error("Unable to load the image for cropping.")),t.src=a}),pe=(a,o,e)=>new Promise((t,r)=>{a.toBlob(i=>{if(!i){r(new Error("Failed to prepare the cropped image."));return}t(i)},o,e)}),xt=async(a,o,e)=>{const t=await wt(a),r=document.createElement("canvas"),i=640;r.width=i,r.height=i;const n=r.getContext("2d");if(!n)throw new Error("Your browser cannot process the selected image right now.");n.clearRect(0,0,i,i),n.drawImage(t,o.x,o.y,o.width,o.height,0,0,i,i);let s;try{s=await pe(r,"image/webp",.92)}catch{s=await pe(r,"image/jpeg",.92)}if(!s)throw new Error("Could not create an image from the cropped area.");const c=s.type==="image/webp"?"webp":"jpg",u=`${e.name.replace(/\.[^/.]+$/,"")||"profile-picture"}-cropped.${c}`;return new File([s],u,{type:s.type,lastModified:Date.now()})},Nt=({uid:a,photoURL:o,displayName:e,className:t="",onUploaded:r,syncFirestore:i=!0})=>{const{currentUser:n,refreshProfile:s}=xe(),[c,l]=x.useState(null),[u,h]=x.useState(null),[d,m]=x.useState({x:0,y:0}),[w,v]=x.useState(1),[f,R]=x.useState(null),[y,g]=x.useState(""),[E,_]=x.useState(!1),P=x.useRef(null);x.useEffect(()=>{if(!c){h(null);return}const C=URL.createObjectURL(c);return h(C),()=>URL.revokeObjectURL(C)},[c]);const k=u||o||"",W=x.useMemo(()=>`${de.map(S=>S.replace("image/","").toUpperCase()).join(", ")} up to ${vt(he)}. The image will be cropped to a circular avatar.`,[]),D=()=>{l(null),m({x:0,y:0}),v(1),R(null),g(""),P.current&&(P.current.value="")},z=C=>{const S=C.target.files?.[0]||null;if(!S)return;const M=me(S);if(M){g(M),l(null),C.target.value="";return}g(""),l(S),m({x:0,y:0}),v(1),R(null)},T=async()=>{if(!c){g("Choose an image before saving.");return}_(!0),g("");const C=6e4;let S;try{const M=(async()=>{const I=u&&f?await xt(u,f,c):c,Z=a||n?.uid;return mt({file:I,uid:Z,currentUser:n,syncFirestore:i})})(),F=new Promise((I,Z)=>{S=setTimeout(()=>Z(new Error("Upload timed out. Please check your connection and try again.")),C)}),ve=await Promise.race([M,F]);r?.(ve),s().catch(I=>console.warn("[ProfilePictureUploader] refreshProfile failed:",I)),Q.success("Profile picture updated."),D()}catch(M){const F=M instanceof Error?M.message:"Failed to update your profile picture.";g(F),Q.error(F)}finally{clearTimeout(S),_(!1)}},U=()=>{P.current?.click()};return p.jsxs(p.Fragment,{children:[p.jsxs("section",{className:`flex items-center gap-4 rounded-xl border border-slate-200 bg-white p-4 shadow-sm ${t}`,children:[p.jsxs("div",{className:"relative cursor-pointer group",onClick:U,role:"button",tabIndex:0,onKeyDown:C=>C.key==="Enter"&&U(),"aria-label":"Change profile picture",children:[p.jsxs(ye,{className:"size-16 sm:size-20 ring-4 ring-sky-50 shadow-sm transition-transform duration-200 group-hover:scale-105",children:[p.jsx(be,{src:k,alt:`${e||"User"} profile picture`}),p.jsx(Ce,{className:"bg-gradient-to-br from-sky-600 to-cyan-500 text-lg font-semibold text-white",children:gt(e)})]}),p.jsx("span",{className:"absolute -right-1 -top-1 inline-flex items-center justify-center rounded-full bg-slate-900 p-1.5 text-white shadow-md transition-colors group-hover:bg-slate-700",children:p.jsx(Oe,{size:14})})]}),p.jsxs("div",{className:"space-y-1 flex-1",children:[p.jsx("p",{className:"text-sm font-semibold text-slate-900",children:"Profile picture"}),p.jsx("p",{className:"text-xs text-slate-500",children:"Click your avatar to upload a new photo."}),y&&p.jsx("p",{className:"text-xs font-medium text-rose-600 mt-1",children:y})]}),p.jsx("input",{ref:P,type:"file",accept:"image/*",onChange:z,className:"sr-only","aria-label":"Choose profile picture"})]}),p.jsx(Pe,{children:u&&p.jsxs(p.Fragment,{children:[p.jsx(J.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 bg-black/60 backdrop-blur-sm z-[60]",onClick:D}),p.jsx(J.div,{initial:{opacity:0,scale:.95,y:20},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:20},transition:{type:"spring",duration:.5,bounce:.3},className:"fixed inset-0 z-[60] flex items-center justify-center p-4 sm:p-6",onClick:C=>C.stopPropagation(),children:p.jsxs("div",{className:"bg-white rounded-2xl shadow-xl w-full max-w-lg overflow-hidden flex flex-col",children:[p.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-slate-100",children:[p.jsx("h3",{className:"text-lg font-bold text-slate-900",children:"Update profile picture"}),p.jsx("button",{onClick:D,className:"p-2 text-slate-400 hover:text-slate-600 hover:bg-slate-100 rounded-full transition-colors","aria-label":"Close modal",children:p.jsx(je,{size:20})})]}),p.jsxs("div",{className:"p-4 sm:p-6 bg-slate-50 flex flex-col items-center",children:[p.jsx("div",{className:"relative h-[350px] sm:h-[450px] w-[350px] sm:w-[450px] mx-auto overflow-hidden rounded-xl bg-slate-100 ring-1 ring-inset ring-slate-200 shadow-inner",children:p.jsx(ct,{image:u,crop:d,zoom:w,aspect:1,cropShape:"round",showGrid:!1,objectFit:"cover",restrictPosition:!0,onCropChange:m,onZoomChange:v,onCropComplete:(C,S)=>R(S),style:{containerStyle:{backgroundColor:"#f8fafc"}}})}),p.jsxs("div",{className:"mt-6 w-full max-w-xs flex items-center gap-4",children:[p.jsx(Ue,{size:18,className:"text-slate-500"}),p.jsx(lt,{value:[w],min:1,max:3,step:.05,onValueChange:C=>v(C[0]||1),"aria-label":"Profile picture zoom",className:"flex-1 cursor-pointer"}),p.jsx(Fe,{size:18,className:"text-slate-500"})]}),p.jsx("p",{className:"mt-4 text-xs text-slate-500 text-center",children:W})]}),p.jsxs("div",{className:"p-4 border-t border-slate-100 flex items-center justify-end gap-3 bg-white",children:[p.jsx(ee,{type:"button",variant:"ghost",onClick:D,disabled:E,className:"font-medium text-slate-600 hover:text-slate-900 hover:bg-slate-100 px-5",children:"Cancel"}),p.jsx(ee,{type:"button",onClick:T,disabled:E||!c,className:"bg-sky-600 hover:bg-sky-700 text-white min-w-[120px] gap-2 shadow-sm",children:E?p.jsxs(p.Fragment,{children:[p.jsx(Ie,{size:16,className:"animate-pulse"}),"Saving..."]}):"Save picture"})]})]})})]})})]})};export{At as M,Nt as P,Tt as V}; diff --git a/assets/QuizBattlePage-Dalws6PZ.js b/assets/QuizBattlePage-R77VTOls.js similarity index 98% rename from assets/QuizBattlePage-Dalws6PZ.js rename to assets/QuizBattlePage-R77VTOls.js index cbea2e94c578f9f68759567afd615620e346ddba..d78b1a96cfc6fba9b2cad5928324e699438bc31d 100644 --- a/assets/QuizBattlePage-Dalws6PZ.js +++ b/assets/QuizBattlePage-R77VTOls.js @@ -1,5 +1,5 @@ -const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/pipelineService-BxyJyUSp.js","assets/index-BufUS6SI.js","assets/vendor-react-B4AQeu28.js","assets/vendor-firebase-firestore-CNv3xXal.js","assets/vendor-firebase-core-D7GXCeNu.js","assets/vendor-firebase-auth-T_wvTOvf.js","assets/vendor-firebase-storage-Bi7H_66d.js","assets/vendor-firebase-analytics-rHarj5hR.js","assets/vendor-radix-C5nwdvGr.js","assets/vendor-charts-CAmziV1y.js","assets/vendor-markdown-yqZQ_iQm.js","assets/vendor-markdown-CfVKi3_s.css","assets/index-CIg5rXpX.css"])))=>i.map(i=>d[i]); -import{e as xa,o as u,m as y,g as et,aM as De,k as st,aN as q,_ as pa,$ as Ha,r as zt,M as Va,aO as Ua,N as Te,h as Ze,U as ke,q as Ke,u as Wa,F as gt,a2 as wt,a7 as vt,a6 as ea}from"./index-BufUS6SI.js";import{r as i,j as e,d as Et}from"./vendor-react-B4AQeu28.js";import{q as jt}from"./quiz_battle_avatar-BXHPSput.js";import{g as Ya,s as ta}from"./subjects-D9a9cUC-.js";import{doc as Xa,getDoc as Ga,where as aa,orderBy as ha,limit as Ct,getDocs as It,query as Bt,collection as Mt}from"./vendor-firebase-firestore-CNv3xXal.js";import{a4 as L,a5 as ba,a6 as fa,a7 as _e,a8 as Za}from"./vendor-firebase-core-D7GXCeNu.js";import{B as z}from"./button-DsnZWCoA.js";import{e as Ka,f as Ja}from"./vendor-radix-C5nwdvGr.js";import{S as Me,a as Fe,b as Ee,c as Re,d as de}from"./select-CPMGrUkA.js";import{I as es}from"./input-BPglbGHJ.js";import{S as ts}from"./switch-Cwzq1Jz4.js";import{H as as,S as xe,C as sa}from"./skeleton-CyzcASDd.js";import{V as ga,a as wa,M as ss,b as rs}from"./volume-x-B-4GTwzp.js";import{C as yt}from"./CompositeAvatar-Col05lJc.js";import{S as Je}from"./sparkles-DYlMf97S.js";import{C as Nt}from"./check-B-qbiSF7.js";import{C as Ue}from"./chevron-right-DADygX42.js";import"./vendor-firebase-auth-T_wvTOvf.js";import"./vendor-firebase-storage-Bi7H_66d.js";import"./vendor-firebase-analytics-rHarj5hR.js";import"./vendor-charts-CAmziV1y.js";import"./vendor-markdown-yqZQ_iQm.js";import"./chart-column-BcVJ31XT.js";import"./chevron-up-CoNRuMZ7.js";import"./avatarData-BuQSOXo3.js";/** +const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/pipelineService-D7yl0SJO.js","assets/index-Bp7MiGcW.js","assets/vendor-react-B4AQeu28.js","assets/vendor-firebase-firestore-CNv3xXal.js","assets/vendor-firebase-core-D7GXCeNu.js","assets/vendor-firebase-auth-T_wvTOvf.js","assets/vendor-firebase-storage-Bi7H_66d.js","assets/vendor-firebase-analytics-rHarj5hR.js","assets/vendor-radix-C5nwdvGr.js","assets/vendor-charts-CAmziV1y.js","assets/vendor-markdown-yqZQ_iQm.js","assets/vendor-markdown-CfVKi3_s.css","assets/index-Dja0MwoB.css"])))=>i.map(i=>d[i]); +import{e as xa,o as u,m as y,g as et,aM as De,k as st,aN as q,_ as pa,$ as Ha,r as zt,M as Va,aO as Ua,N as Te,h as Ze,U as ke,q as Ke,u as Wa,F as gt,a2 as wt,a7 as vt,a6 as ea}from"./index-Bp7MiGcW.js";import{r as i,j as e,d as Et}from"./vendor-react-B4AQeu28.js";import{q as jt}from"./quiz_battle_avatar-BXHPSput.js";import{g as Ya,s as ta}from"./subjects-DNoBzeBL.js";import{doc as Xa,getDoc as Ga,where as aa,orderBy as ha,limit as Ct,getDocs as It,query as Bt,collection as Mt}from"./vendor-firebase-firestore-CNv3xXal.js";import{a4 as L,a5 as ba,a6 as fa,a7 as _e,a8 as Za}from"./vendor-firebase-core-D7GXCeNu.js";import{B as z}from"./button-BMVm9YQO.js";import{e as Ka,f as Ja}from"./vendor-radix-C5nwdvGr.js";import{S as Me,a as Fe,b as Ee,c as Re,d as de}from"./select-CNQuOudF.js";import{I as es}from"./input-Co0dljwe.js";import{S as ts}from"./switch-C4JL2ii9.js";import{S as xe,C as sa}from"./skeleton-BM3FTF2K.js";import{V as ga,a as wa,M as as,b as ss}from"./volume-x-DCLZlWDn.js";import{C as yt}from"./CompositeAvatar-DoKZfi7O.js";import{S as Je}from"./sparkles-fLB3ltj1.js";import{C as Nt}from"./check-qsSFTYCr.js";import{H as rs}from"./history-DVu_-tNM.js";import{C as Ue}from"./chevron-right-BxoysOas.js";import"./vendor-firebase-auth-T_wvTOvf.js";import"./vendor-firebase-storage-Bi7H_66d.js";import"./vendor-firebase-analytics-rHarj5hR.js";import"./vendor-charts-CAmziV1y.js";import"./vendor-markdown-yqZQ_iQm.js";import"./chart-column-Dyv8TfXk.js";import"./chevron-up-DtS9MvUZ.js";import"./avatarData-ChByUhv2.js";/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. @@ -9,7 +9,7 @@ import{e as xa,o as u,m as y,g as et,aM as De,k as st,aN as q,_ as pa,$ as Ha,r * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. - */const os=[["rect",{x:"14",y:"4",width:"4",height:"16",rx:"1",key:"zuxfzm"}],["rect",{x:"6",y:"4",width:"4",height:"16",rx:"1",key:"1okwgv"}]],ls=xa("pause",os),We=({width:a,x:s,delay:n,duration:c})=>{const d=["#9956DE","#7274ED","#1FA7E1","#6ED1CF","#75D06A","#FFB356","#FF8B8B","#FB96BB"],l=d[Math.floor(Math.random()*d.length)],w=Math.floor(Math.random()*10)+1;return e.jsx(y.div,{style:{"--x":`${s}`,"--width":`${a}`,"--aspect-ratio":`${w}`,"--background":`linear-gradient(${l}cc, transparent)`},className:"absolute left-[var(--x)] top-0 [aspect-ratio:1/var(--aspect-ratio)] [background:var(--background)] [width:var(--width)]",initial:{y:"100cqmax",x:"-50%"},animate:{y:"-100%",x:"-50%"},transition:{duration:c,delay:n,repeat:Number.POSITIVE_INFINITY,ease:"linear"}})},na=({children:a,perspective:s=100,className:n,bgVideo:c,beamsPerSide:d=6,beamSize:l=4,beamDelayMax:w=1.5,beamDelayMin:A=0,beamDuration:f=4,gridColor:N="rgba(100, 116, 139, 0.08)",...b})=>{const j=i.useCallback(()=>{const S=[],Y=Math.floor(100/l)/d;for(let O=0;Oj(),[j]),m=i.useMemo(()=>j(),[j]),v=i.useMemo(()=>j(),[j]),W=i.useMemo(()=>j(),[j]);return e.jsxs("div",{className:u("relative w-full h-full",n),...b,children:[c?e.jsx("video",{autoPlay:!0,loop:!0,muted:!0,playsInline:!0,className:"pointer-events-none absolute inset-0 w-full h-full object-cover -z-10",src:c}):e.jsxs("div",{style:{"--perspective":`${s}px`,"--grid-color":N,"--beam-size":`${l}%`},className:"pointer-events-none absolute inset-0 overflow-hidden [clip-path:inset(0)] [container-type:size] [perspective:var(--perspective)] [transform-style:preserve-3d] -z-10 bg-[#42389d]",children:[e.jsx("div",{className:"absolute [transform-style:preserve-3d] [background-size:var(--beam-size)_var(--beam-size)] [background:linear-gradient(var(--grid-color)_0_1px,_transparent_1px_var(--beam-size))_50%_-0.5px_/var(--beam-size)_var(--beam-size),linear-gradient(90deg,_var(--grid-color)_0_1px,_transparent_1px_var(--beam-size))_50%_50%_/var(--beam-size)_var(--beam-size)] [container-type:inline-size] [height:100cqmax] [transform-origin:50%_0%] [transform:rotateX(-90deg)] [width:100cqi]",children:h.map((S,R)=>e.jsx(We,{width:`${l}%`,x:`${S.x*l}%`,delay:S.delay,duration:f},`top-${R}`))}),e.jsx("div",{className:"absolute top-full [transform-style:preserve-3d] [background-size:var(--beam-size)_var(--beam-size)] [background:linear-gradient(var(--grid-color)_0_1px,_transparent_1px_var(--beam-size))_50%_-0.5px_/var(--beam-size)_var(--beam-size),linear-gradient(90deg,_var(--grid-color)_0_1px,_transparent_1px_var(--beam-size))_50%_50%_/var(--beam-size)_var(--beam-size)] [container-type:inline-size] [height:100cqmax] [transform-origin:50%_0%] [transform:rotateX(-90deg)] [width:100cqi]",children:v.map((S,R)=>e.jsx(We,{width:`${l}%`,x:`${S.x*l}%`,delay:S.delay,duration:f},`bottom-${R}`))}),e.jsx("div",{className:"absolute left-0 top-0 [transform-style:preserve-3d] [background-size:var(--beam-size)_var(--beam-size)] [background:linear-gradient(var(--grid-color)_0_1px,_transparent_1px_var(--beam-size))_50%_-0.5px_/var(--beam-size)_var(--beam-size),linear-gradient(90deg,_var(--grid-color)_0_1px,_transparent_1px_var(--beam-size))_50%_50%_/var(--beam-size)_var(--beam-size)] [container-type:inline-size] [height:100cqmax] [transform-origin:0%_0%] [transform:rotate(90deg)_rotateX(-90deg)] [width:100cqh]",children:W.map((S,R)=>e.jsx(We,{width:`${l}%`,x:`${S.x*l}%`,delay:S.delay,duration:f},`left-${R}`))}),e.jsx("div",{className:"absolute right-0 top-0 [transform-style:preserve-3d] [background-size:var(--beam-size)_var(--beam-size)] [background:linear-gradient(var(--grid-color)_0_1px,_transparent_1px_var(--beam-size))_50%_-0.5px_/var(--beam-size)_var(--beam-size),linear-gradient(90deg,_var(--grid-color)_0_1px,_transparent_1px_var(--beam-size))_50%_50%_/var(--beam-size)_var(--beam-size)] [container-type:inline-size] [height:100cqmax] [width:100cqh] [transform-origin:100%_0%] [transform:rotate(-90deg)_rotateX(-90deg)]",children:m.map((S,R)=>e.jsx(We,{width:`${l}%`,x:`${S.x*l}%`,delay:S.delay,duration:f},`right-${R}`))})]}),e.jsx("div",{className:"relative z-10 w-full h-full",children:a})]})},is=15e3,ds="mathpulse.quizBattle.local",oa="".toLowerCase()==="true",rt=typeof window<"u",tt=()=>rt&&!1,Rt=()=>{const a=st.currentUser?.uid;return a||"local-student"},va=a=>`${ds}.${a}`,Pe=a=>{const s={stats:Se(a),history:[],queueStatus:"idle"};if(!rt)return s;try{const n=window.localStorage.getItem(va(a));if(!n)return s;const c=JSON.parse(n),d=Array.isArray(c.history)?c.history.map(w=>Ft(w.matchId||"local-match",w)):[];return{stats:c.stats?{...Se(a),...c.stats,userId:a,updatedAt:at(c.stats.updatedAt)}:Se(a),history:d,queueStatus:c.queueStatus==="queued"||c.queueStatus==="matched"?c.queueStatus:"idle"}}catch(n){return console.error("Error reading local Quiz Battle fallback store:",n),s}},ja=(a,s)=>{if(rt)try{window.localStorage.setItem(va(a),JSON.stringify(s))}catch(n){console.error("Error writing local Quiz Battle fallback store:",n)}},ya=a=>{const s=a||{},n=typeof s.code=="string"?s.code:"";return n?n.startsWith("functions/")?n.replace("functions/",""):n:""},ne=a=>{if(!tt())return!1;const s=ya(a);if(["internal","not-found","unavailable","deadline-exceeded"].includes(s))return!0;const n=a||{},c=(typeof n.message=="string"?n.message:a instanceof Error?a.message:"").toLowerCase();return c?c.includes("cors policy")||c.includes("no access-control-allow-origin")||c.includes("failed to fetch")||c.includes("network error")||c.includes("err_failed"):!1},Ye=(a,s)=>Math.floor(Math.random()*(s-a+1))+a,cs=(a,s)=>{const n=Math.max(3,a),c=s==="easy"?0:s==="medium"?1:s==="hard"?2:1,d=Ye(Math.max(0,n-3-c),n),l=Ye(Math.max(0,n-4+c),n),w=Math.min(n,Math.max(0,d)),A=Math.min(n,Math.max(0,l)),f=Math.max(0,Math.min(100,w/n*100+Ye(-8,6))),N=Ye(1800,6200);return{scoreFor:w,scoreAgainst:A,accuracy:f,averageResponseMs:N}},us=a=>{const s=Rt(),n=Pe(s),c=`local-bot-${Date.now()}-${Math.random().toString(16).slice(2,8)}`,d=cs(a.rounds,a.botDifficulty),l=d.scoreFor>d.scoreAgainst?"win":d.scoreFor0?m/h*100:0,averageAccuracy:h>0?(n.stats.averageAccuracy*n.stats.matchesPlayed+d.accuracy)/h:d.accuracy,averageResponseMs:h>0?Math.round((n.stats.averageResponseMs*n.stats.matchesPlayed+d.averageResponseMs)/h):d.averageResponseMs,currentStreak:S,bestStreak:R,favoriteTopicId:a.topicId,leaderboardScore:n.stats.leaderboardScore+j.xpEarned,updatedAt:w};ja(s,{stats:Y,history:[j,...n.history].slice(0,50),queueStatus:"idle"});try{pa(async()=>{const{emitPipelineEvent:O,getStudentContext:M}=await import("./pipelineService-BxyJyUSp.js");return{emitPipelineEvent:O,getStudentContext:M}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12])).then(({emitPipelineEvent:O,getStudentContext:M})=>{const D=M();D&&O({student_id:s,event_type:"battle",event_data:{battle_id:c,topic:a.topicId,score:d.accuracy,won:l==="win",total_questions:a.rounds,correct_answers:d.scoreFor},occurred_at:new Date().toISOString(),class_id:D.classId,teacher_id:D.teacherId})}).catch(()=>{})}catch{}return{success:!0,matchId:c,status:"ready",botDifficulty:a.botDifficulty}},Na=a=>{const s=Rt(),n=Pe(s);ja(s,{...n,queueStatus:a})},ms=()=>Math.random().toString(36).slice(2,8).toUpperCase(),Tt=a=>{const s=Rt();return{roomId:`local-room-${Date.now()}`,roomCode:a||ms(),ownerStudentId:s,participantIds:[s],participantCount:1,status:"waiting",subjectId:"gen-math",topicId:"functions",difficulty:"medium",rounds:5,timePerQuestionSec:30,isOwner:!0}},ka=()=>rt&&!!st.currentUser?.uid&&!!De,_a=(a,s,n)=>`quizBattlePresence/${a}/${s}/${n}`,xs=async(a,s)=>{if(!ka()||!s.trim()||!De)return;const n=st.currentUser?.uid;if(!n)return;const c=ba(De,_a(a,s,n));try{await fa(c,{studentId:n,scope:a,resourceId:s,online:!0,heartbeatAt:_e(),updatedAt:_e()}),await Za(c).update({online:!1,updatedAt:_e(),disconnectedAt:_e()})}catch(d){console.warn("Realtime presence connect failed:",d)}},ps=async(a,s)=>{if(!ka()||!s.trim()||!De)return;const n=st.currentUser?.uid;if(!n)return;const c=ba(De,_a(a,s,n));try{await fa(c,{studentId:n,scope:a,resourceId:s,online:!1,updatedAt:_e(),disconnectedAt:_e()})}catch(d){console.warn("Realtime presence disconnect failed:",d)}},V=(a,s)=>{const n=`Unable to continue while ${a}. Please try again.`;if(s instanceof Error&&s.message.startsWith("Timed out while"))return s.message;const c=s||{},d=ya(s),l=typeof c.message=="string"?c.message.trim():"";return d==="unauthenticated"?"Your session has expired. Sign in again before starting a battle.":d==="permission-denied"?"Only student accounts can access Quiz Battle matchmaking.":d==="invalid-argument"?l||"Battle setup is invalid. Review the selected options and try again.":d==="already-exists"?l||"This room is already full. Try another room code.":d==="failed-precondition"?l||"Battle state changed. Please refresh and continue.":d==="unavailable"||d==="internal"||d==="not-found"||d==="deadline-exceeded"?/question generation temporarily unavailable/i.test(l)?l:"Quiz Battle service is temporarily unavailable. Please retry in a moment.":n},$=async(a,s,n=is)=>{let c;try{return await Promise.race([s,new Promise((d,l)=>{c=setTimeout(()=>{l(new Error(`Timed out while ${a}. Please try again.`))},n)})])}finally{c&&clearTimeout(c)}},at=a=>{if(!a)return new Date;if(a instanceof Date)return a;if(typeof a=="string"){const s=Date.parse(a);return Number.isNaN(s)?new Date:new Date(s)}if(typeof a=="number")return new Date(a);if(typeof a=="object"){const s=a;if(typeof s.toDate=="function")return s.toDate();if(typeof s.seconds=="number")return new Date(s.seconds*1e3)}return new Date},hs=()=>({mode:"online",subjectId:"gen-math",topicId:"",difficulty:"medium",rounds:5,timePerQuestionSec:30,queueType:"public_matchmaking",botDifficulty:"medium",adaptiveBot:!1}),bs=a=>{const s=[];return a.subjectId.trim()||s.push({field:"subjectId",message:"Choose a category before starting."}),a.topicId.trim()||s.push({field:"topicId",message:"Choose a strand or topic before starting."}),(a.rounds<3||a.rounds>20)&&s.push({field:"rounds",message:"Questions must be between 3 and 20."}),(a.timePerQuestionSec<10||a.timePerQuestionSec>180)&&s.push({field:"timePerQuestionSec",message:"Timer must be between 10s and 180s."}),a.mode==="bot"&&a.queueType!=="public_matchmaking"&&s.push({field:"queueType",message:"Bot battles use instant start and do not support private room mode."}),s},Se=a=>({userId:a,matchesPlayed:0,wins:0,losses:0,draws:0,winRate:0,averageAccuracy:0,averageResponseMs:0,bestStreak:0,currentStreak:0,favoriteTopicId:void 0,leaderboardScore:0,updatedAt:new Date}),fs=async a=>{try{const s=Xa(et,"studentBattleStats",a),n=await Ga(s),c=tt()?Pe(a).stats:null;if(!n.exists())return c&&c.matchesPlayed>0?c:Se(a);const d=n.data(),l={...Se(a),...d,userId:a,updatedAt:at(d.updatedAt)};return c&&c.matchesPlayed>l.matchesPlayed?c:l}catch(s){if(console.error("Error loading battle stats:",s),tt()){const n=Pe(a).stats;if(n.matchesPlayed>0)return n}return Se(a)}},Ft=(a,s)=>({matchId:s.matchId||a,mode:s.mode||"online",status:s.status||"completed",subjectId:s.subjectId||"gen-math",topicId:s.topicId||"unknown-topic",difficulty:s.difficulty||"medium",rounds:s.rounds||0,timePerQuestionSec:s.timePerQuestionSec||0,scoreFor:s.scoreFor||0,scoreAgainst:s.scoreAgainst||0,outcome:s.outcome||"draw",accuracy:s.accuracy||0,averageResponseMs:s.averageResponseMs||0,bestStreak:s.bestStreak||0,xpEarned:s.xpEarned||0,opponentName:s.opponentName||"Unknown opponent",opponentType:s.opponentType||"student",createdAt:at(s.createdAt),endedAt:at(s.endedAt)}),gs=async(a,s={})=>{const n=s.limitCount||25,c=tt()?Pe(a).history:[],d=w=>w.filter(f=>!(s.mode&&s.mode!=="all"&&f.mode!==s.mode||s.subjectId&&f.subjectId!==s.subjectId||s.startDate&&f.endedAts.endDate)).sort((f,N)=>N.endedAt.getTime()-f.endedAt.getTime()).slice(0,n),l=w=>{if(c.length===0)return d(w);const A=new Map;return[...c,...w].forEach(f=>{A.set(f.matchId,f)}),d(Array.from(A.values()))};try{const w=[aa("studentId","==",a),ha("endedAt","desc"),Ct(n)],f=(await It(Bt(Mt(et,"quizBattleHistory"),...w))).docs.map(N=>Ft(N.id,N.data()));return l(f)}catch(w){try{const f=(await It(Bt(Mt(et,"quizBattleHistory"),aa("studentId","==",a),Ct(n)))).docs.map(N=>Ft(N.id,N.data())).sort((N,b)=>b.endedAt.getTime()-N.endedAt.getTime());return l(f)}catch(A){return console.error("Error loading battle history:",w,A),d(c)}}},ws=async a=>{const s=L(q,"quizBattleJoinQueue");try{return(await $("joining Quiz Battle matchmaking queue",s({setup:a}))).data}catch(n){if(ne(n))return Na("queued"),{success:!0,status:"queued",queueEntryId:`local-queue-${Date.now()}`};throw new Error(V("joining Quiz Battle matchmaking queue",n))}},la=async()=>{const a=L(q,"quizBattleLeaveQueue");try{return(await $("leaving Quiz Battle matchmaking queue",a({}))).data}catch(s){if(ne(s))return Na("idle"),{success:!0,status:"idle"};throw new Error(V("leaving Quiz Battle matchmaking queue",s))}},vs=async a=>{const s=L(q,"quizBattleCreatePrivateRoom");try{return(await $("creating Quiz Battle private room",s({setup:a}))).data}catch(n){if(ne(n))return{success:!0,room:Tt()};throw new Error(V("creating Quiz Battle private room",n))}},js=async a=>{const s=L(q,"quizBattleJoinPrivateRoom");try{return(await $("joining Quiz Battle private room",s({roomCode:a}),2e4)).data}catch(n){if(ne(n))return{success:!0,room:Tt(a.trim().toUpperCase()||void 0)};throw new Error(V("joining Quiz Battle private room",n))}},ys=async a=>{const s=L(q,"quizBattleGetPrivateRoomState");try{return(await $("loading Quiz Battle private room state",s(a),2e4)).data}catch(n){if(ne(n))return{success:!0,room:Tt(a.roomCode?.trim().toUpperCase()||void 0)};throw new Error(V("loading Quiz Battle private room state",n))}},Ns=async(a={})=>{const s=L(q,"quizBattleLeavePrivateRoom");try{return(await $("leaving Quiz Battle private room",s(a),2e4)).data}catch(n){if(ne(n))return{success:!0,status:"idle"};throw new Error(V("leaving Quiz Battle private room",n))}},ia=async()=>{const a=L(q,"quizBattleResumeSession");try{return(await $("resuming Quiz Battle session",a({}),2e4)).data}catch(s){if(ne(s))return{success:!0,sessionType:"idle"};throw new Error(V("resuming Quiz Battle session",s))}},ks=async(a,s)=>{if(!s.trim())return;const n=L(q,"quizBattleHeartbeat");await xs(a,s);try{await $("sending Quiz Battle heartbeat",n({scope:a,resourceId:s}),12e3)}catch(c){if(!ne(c))throw new Error(V("sending Quiz Battle heartbeat",c))}},_s=async a=>{const s=L(q,"quizBattleCreateBotMatch");try{return(await $("starting Quiz Battle bot match",s({setup:a}))).data}catch(n){if(ne(n))return us(a);throw new Error(V("starting Quiz Battle bot match",n))}},Ss=async a=>{const s=L(q,"quizBattleGetGenerationAudit");return(await $("verifying Quiz Battle generation metadata",s({matchId:a}),2e4)).data},re=async a=>{const s=L(q,"quizBattleStartMatch");try{const c=(await $("starting Quiz Battle match",s({matchId:a}),2e4)).data.match;if(c.mode==="online")try{const d=await Ss(a);if(oa&&!d.isAiSource)throw new Error(`Quiz Battle generation audit failed: expected AI source, got "${d.questionSetSource||"unknown"}".`)}catch(d){if(d instanceof Error&&d.message.startsWith("Quiz Battle generation audit failed"))throw d;if(console.warn("Quiz Battle generation audit unavailable:",d),oa)throw new Error("Unable to verify Quiz Battle generation metadata. Please retry in a moment.")}return c}catch(n){throw new Error(V("starting Quiz Battle match",n))}},kt=async a=>{const s=L(q,"quizBattleGetMatchState");try{return(await $("loading Quiz Battle match state",s({matchId:a}),2e4)).data.match}catch(n){throw new Error(V("loading Quiz Battle match state",n))}},As=async a=>{const s=L(q,"quizBattleSubmitAnswer");try{return(await $("submitting Quiz Battle answer",s({...a,idempotencyKey:a.idempotencyKey||`client-${Date.now()}-${Math.random().toString(16).slice(2,8)}`}),2e4)).data}catch(n){throw new Error(V("submitting Quiz Battle answer",n))}},zs=async a=>{const s=L(q,"quizBattleRequestRematch");try{return(await $("creating Quiz Battle rematch",s({matchId:a}),2e4)).data}catch(n){throw new Error(V("creating Quiz Battle rematch",n))}},Cs=async(a=20)=>{try{const s=Bt(Mt(et,"studentBattleLeaderboard"),ha("leaderboardScore","desc"),Ct(a));return(await It(s)).docs.map((c,d)=>{const l=c.data();return{userId:l.userId||c.id,displayName:l.displayName||"Student",photo:l.photo,rank:l.rank||d+1,leaderboardScore:l.leaderboardScore||0,winRate:l.winRate||0,bestStreak:l.bestStreak||0}})}catch(s){return console.error("Error loading Quiz Battle leaderboard:",s),[]}};function pe({className:a,...s}){return e.jsx("div",{"data-slot":"card",className:u("bg-card text-card-foreground flex flex-col gap-6 rounded-xl border",a),...s})}function he({className:a,...s}){return e.jsx("div",{"data-slot":"card-header",className:u("@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-1.5 px-6 pt-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6",a),...s})}function be({className:a,...s}){return e.jsx("h4",{"data-slot":"card-title",className:u("leading-none",a),...s})}function ye({className:a,...s}){return e.jsx("p",{"data-slot":"card-description",className:u("text-muted-foreground",a),...s})}function Xe({className:a,...s}){return e.jsx("div",{"data-slot":"card-content",className:u("px-6 [&:last-child]:pb-6",a),...s})}function Is({className:a,...s}){return e.jsx(Ka,{"data-slot":"tabs",className:u("flex flex-col gap-2",a),...s})}function Ne({className:a,...s}){return e.jsx(Ja,{"data-slot":"tabs-content",className:u("flex-1 outline-none",a),...s})}const Sa=Et.memo(({playerRoundStreak:a,playerVisualMultiplier:s,liveXpEarned:n,activeMatch:c,subjects:d,battleSoundEnabled:l,onToggleSound:w,isFullscreen:A,onToggleFullscreen:f,isDesignPauseAvailable:N,onTogglePause:b})=>e.jsxs("header",{className:"flex items-center justify-between shrink-0 h-14 sm:h-16 relative gap-2 sm:gap-4",children:[e.jsx("div",{className:"flex items-center min-w-0",children:e.jsxs("div",{className:"flex items-center gap-2 sm:gap-3 md:gap-4 px-2.5 sm:px-4 py-1.5 sm:py-2 md:px-5 md:py-2.5 rounded-full bg-white/5 border border-white/10 backdrop-blur-md min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1 sm:gap-1.5 text-amber-400 font-bold text-xs sm:text-sm shrink-0",children:[e.jsx(Ha,{className:"w-3 h-3 sm:w-4 sm:h-4"})," ",a]}),e.jsx("div",{className:"w-px h-3 sm:h-4 bg-white/10 shrink-0"}),e.jsxs("div",{className:"flex items-center gap-1 sm:gap-1.5 text-violet-300 font-bold text-xs sm:text-sm shrink-0",children:[e.jsx(zt,{className:"w-3 h-3 sm:w-4 sm:h-4"})," ",s.toFixed(2),"x"]}),e.jsx("div",{className:"w-px h-3 sm:h-4 bg-white/10 shrink-0"}),e.jsxs(y.div,{animate:n>0?{scale:[1,1.25,1]}:{},transition:{duration:.35},className:"flex flex-col items-center text-emerald-400 bg-emerald-500/10 px-2 sm:px-3 py-0.5 rounded-full border border-emerald-500/20 font-bold shadow-[0_0_10px_rgba(16,185,129,0.15)] shrink-0",children:[e.jsxs("span",{className:"text-xs sm:text-sm leading-none tabular-nums",children:[n," pts"]}),e.jsx("span",{className:"hidden sm:block text-[8px] leading-none text-emerald-500/70 uppercase tracking-widest font-black whitespace-nowrap",children:"Battle Score"})]},n)]})}),e.jsxs("div",{className:"absolute left-1/2 -translate-x-1/2 hidden md:flex items-center gap-3 bg-black/20 px-5 py-2 rounded-full border border-white/5 min-w-0 max-w-[48%]",children:[e.jsx("div",{className:"w-3.5 h-3.5 rounded-sm bg-orange-400 shadow-[0_0_10px_rgba(251,146,60,0.5)] shrink-0"}),e.jsx("div",{className:"flex flex-col items-start justify-center -space-y-0.5 min-w-0",children:(()=>{if(!c?.topicId)return e.jsx("span",{className:"font-bold text-white/90 tracking-wide text-sm leading-none truncate",children:"Practice Match"});for(const j of d){const h=j.modules?.find(m=>m.id===c.topicId);if(h)return e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-[9px] font-black text-white/40 uppercase tracking-widest leading-none",children:j.title}),e.jsx("span",{className:"font-bold text-white/90 tracking-wide text-sm leading-none pt-1 truncate",children:h.title})]})}return e.jsx("span",{className:"font-bold text-white/90 tracking-wide text-sm leading-none truncate",children:c.topicId.split("-").map(j=>j.charAt(0).toUpperCase()+j.slice(1)).join(" ")})})()})]}),e.jsxs("div",{className:"flex items-center gap-1.5 sm:gap-3",children:[e.jsx(z,{variant:"outline",size:"icon",className:"h-9 w-9 sm:h-12 sm:w-12 rounded-full border-white/20 bg-black/20 hover:bg-white/10 text-white",onClick:w,children:l?e.jsx(ga,{className:"h-4 w-4 sm:h-5 sm:w-5"}):e.jsx(wa,{className:"h-4 w-4 sm:h-5 sm:w-5"})}),e.jsx(z,{variant:"outline",size:"icon",className:"hidden sm:flex h-12 w-12 rounded-full border-white/20 bg-black/20 hover:bg-white/10 text-white",onClick:f,children:A?e.jsx(ss,{className:"h-5 w-5"}):e.jsx(rs,{className:"h-5 w-5"})}),e.jsx(z,{variant:"outline",size:"icon",className:u("h-9 w-9 sm:h-12 sm:w-12 rounded-full border-white/20 text-white",N?"bg-black/20 hover:bg-white/10":"bg-black/10 opacity-50 cursor-not-allowed"),onClick:b,disabled:!N,children:e.jsx(Va,{className:"h-4 w-4 sm:h-5 sm:w-5"})})]})]}));Sa.displayName="BattleHeader";const Aa=Et.memo(({studentProfile:a,activeMatch:s,scorePulseTarget:n,quizBattleAvatar:c,opponentId:d})=>{const[l,w]=i.useState(null);return i.useEffect(()=>{if(!d)return;let A=!1;return Ua(d).then(f=>{!A&&f?.avatarLayers&&w(f.avatarLayers)}).catch(()=>{}),()=>{A=!0}},[d]),e.jsxs("div",{className:"absolute bottom-0 left-0 right-0 w-full xl:max-w-[1400px] mx-auto px-2 sm:px-4 md:px-8 shrink-0 h-28 sm:h-32 md:h-48 flex justify-between items-end pb-0 pointer-events-none z-30",children:[e.jsxs("div",{className:"flex items-end gap-1.5 sm:gap-3 md:gap-6 relative pointer-events-auto",children:[e.jsx("div",{className:"relative w-16 h-16 sm:w-28 sm:h-28 md:w-40 md:h-40 rounded-t-[40px] flex items-end",children:e.jsx(yt,{layers:a?.avatarLayers||{},className:"w-full h-full object-contain origin-bottom scale-[1.15]"})}),e.jsxs("div",{className:"bg-black/40 backdrop-blur-xl border border-white/20 rounded-xl sm:rounded-2xl px-2 sm:px-4 py-2 sm:py-3 md:px-5 shadow-[0_8px_30px_rgba(0,0,0,0.5)] flex items-center gap-1.5 sm:gap-3 md:gap-4 mb-2 sm:mb-4 max-w-[130px] sm:max-w-[220px] md:max-w-[280px]",children:[e.jsxs("div",{className:"flex flex-col flex-1 min-w-0",children:[e.jsx("span",{className:"text-white font-black text-xs sm:text-base md:text-lg truncate tracking-wide",children:a?.name||"Player"}),e.jsxs("span",{className:"text-[9px] sm:text-xs md:text-sm text-white/50 font-bold uppercase tracking-wider",children:["Level ",a?.level||1]})]}),e.jsx("div",{className:"h-6 sm:h-10 w-px bg-white/20"}),e.jsxs("div",{className:"flex flex-col items-center justify-center shrink-0 w-6 sm:w-10 md:w-12",children:[e.jsx(y.span,{animate:n==="player"?{scale:[1,1.4,1],color:["#fff","#34d399","#fff"]}:{},transition:{duration:.5},className:"text-lg sm:text-2xl md:text-3xl font-black text-white leading-none",children:s.scoreFor}),e.jsx("span",{className:"text-[7px] sm:text-[9px] md:text-[10px] text-emerald-400 font-bold uppercase tracking-widest mt-0.5 sm:mt-1 leading-none",children:"Score"})]})]})]}),e.jsxs("div",{className:"flex items-end gap-1.5 sm:gap-3 md:gap-6 relative flex-row-reverse pointer-events-auto",children:[e.jsx("div",{className:"relative w-16 h-16 sm:w-28 sm:h-28 md:w-40 md:h-40 rounded-t-[40px] flex items-end justify-center",children:s.mode==="bot"?e.jsx(Te,{className:"h-8 w-8 sm:h-16 sm:w-16 md:h-20 md:w-20 text-rose-400 mb-3 sm:mb-6 drop-shadow-xl",strokeWidth:1.5}):l?e.jsx(yt,{layers:l,className:"w-full h-full object-contain origin-bottom scale-[1.15]"}):e.jsx(yt,{layers:{},className:"w-full h-full object-contain origin-bottom scale-[1.15]"})}),e.jsxs("div",{className:"bg-black/40 backdrop-blur-xl border border-white/20 rounded-xl sm:rounded-2xl px-2 sm:px-4 py-2 sm:py-3 md:px-5 shadow-[0_8px_30px_rgba(0,0,0,0.5)] flex items-center gap-1.5 sm:gap-3 md:gap-4 mb-2 sm:mb-4 flex-row-reverse text-right max-w-[130px] sm:max-w-[220px] md:max-w-[280px]",children:[e.jsxs("div",{className:"flex flex-col flex-1 min-w-0",children:[e.jsx("span",{className:"text-white font-black text-xs sm:text-base md:text-lg truncate tracking-wide",children:s.opponentName||"Anonymous"}),e.jsx("span",{className:"text-[9px] sm:text-xs md:text-sm text-rose-400 font-bold uppercase tracking-wider",children:s.mode==="bot"?"System Bot":"Challenger"})]}),e.jsx("div",{className:"h-6 sm:h-10 w-px bg-white/20"}),e.jsxs("div",{className:"flex flex-col items-center justify-center shrink-0 w-6 sm:w-10 md:w-12",children:[e.jsx(y.span,{animate:n==="opponent"?{scale:[1,1.4,1],color:["#fff","#fb7185","#fff"]}:{},transition:{duration:.5},className:"text-lg sm:text-2xl md:text-3xl font-black text-white leading-none",children:s.scoreAgainst}),e.jsx("span",{className:"text-[7px] sm:text-[9px] md:text-[10px] text-rose-400 font-bold uppercase tracking-widest mt-0.5 sm:mt-1 leading-none",children:"Score"})]})]})]})]})});Aa.displayName="BattleFooter";const za=Et.memo(({activeMatch:a,roundSecondsLeft:s,lastRoundResult:n,selectedOptionIndex:c,roundLocked:d,answerSubmitting:l,designPauseActive:w,onOptionSelect:A,floatingMomentum:f,lastRoundMomentumDelta:N,studentProfile:b,quizBattleAvatar:j})=>e.jsxs("div",{className:"flex-1 flex flex-col justify-center items-center gap-4 md:gap-6 w-full min-h-0 overflow-y-auto pt-4 pb-28 z-20 no-scrollbar",children:[e.jsxs("div",{className:u("relative bg-[#1e2536] border shadow-[0_20px_60px_rgba(0,0,0,0.4)] rounded-[1.5rem] p-5 md:p-6 w-full max-w-4xl text-center flex flex-col items-center",s<=3?"border-rose-400/50":"border-white/10"),children:[e.jsxs("div",{className:"absolute -top-3.5 bg-[#2f3547] border border-white/10 text-white/80 px-4 py-1 rounded-full text-xs font-black shadow-lg uppercase tracking-wider",children:[a.currentRound," / ",a.totalRounds]}),e.jsx(Ze,{children:f&&f.tone==="positive"&&e.jsx(y.div,{initial:{opacity:0,y:14,scale:.92},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-10,scale:.9},className:u("absolute -top-12 rounded-full border px-3 py-1 text-[10px] font-black uppercase tracking-[0.15em] backdrop-blur-lg",f.tone==="positive"?"border-emerald-300/70 bg-emerald-500/20 text-emerald-100":f.tone==="negative"?"border-rose-300/70 bg-rose-500/20 text-rose-100":"border-slate-300/50 bg-slate-500/20 text-slate-100"),children:f.label},f.id)}),e.jsx("p",{className:"text-base sm:text-lg md:text-xl text-white font-extrabold leading-tight tracking-tight mt-1 min-h-[40px] flex items-center justify-center",children:a.currentQuestion?.prompt}),typeof window<"u"&&window.location.search.includes("debug=true")&&a.currentQuestion?.varianceApplied&&e.jsx("div",{className:"flex flex-wrap gap-1 mt-2 justify-center",children:a.currentQuestion.varianceApplied.map(h=>e.jsx("span",{className:"inline-flex items-center px-2 py-0.5 rounded text-[10px] font-medium bg-blue-500/20 text-blue-200 border border-blue-400/30",children:h.replace(/_/g," ")},h))})]}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3 md:gap-4 w-full max-w-4xl px-4",children:a.currentQuestion?.choices.map((h,m)=>{const v=c===m,W=l||d,S=!!n&&n.roundNumber===a.currentRound,R=S&&n.correctOptionIndex===m;let Y=-1;if(S)if(a.mode==="bot")if(n.botCorrect)Y=n.correctOptionIndex;else{const D=[0,1,2,3].filter(C=>C!==n.correctOptionIndex);Y=D[n.roundNumber%D.length]}else Y=typeof n.botSelectedIndex=="number"?n.botSelectedIndex:-1;const O=Y===m;let M="bg-[#1e2433] hover:bg-[#283042] border-[#2f384e] text-white shadow-[0_6px_0_rgba(15,20,30,0.5)]";return S?R?M="bg-emerald-500 text-emerald-950 border-emerald-400 shadow-[0_6px_0_rgba(5,150,105,1)]":v?M="bg-rose-500 text-white border-rose-400 shadow-[0_6px_0_rgba(225,29,72,1)]":M="bg-[#1e2433] opacity-40 border-[#2f384e] shadow-[0_6px_0_rgba(15,20,30,0.5)] text-white":v&&(M="bg-indigo-500 text-white border-indigo-400 shadow-[0_6px_0_rgba(79,70,229,1)]"),e.jsxs(y.button,{whileTap:{y:8,scale:.98},whileHover:!S&&!W?{scale:1.02}:{},disabled:W||d||w,onClick:()=>A(m),className:u("relative h-16 md:h-20 rounded-2xl md:rounded-3xl font-black text-base md:text-lg pl-6 pr-20 border-[2px] border-b-[4px] flex items-center justify-start text-left transition-all disabled:cursor-not-allowed",M,v&&!S?"ring-[4px] ring-white/20 ring-offset-[4px] ring-offset-[#0B0F19]":"",s<=3&&!W&&!S?"shadow-[0_0_0_2px_rgba(251,113,133,0.45),0_6px_0_rgba(127,29,29,1)]":""),children:[e.jsx("span",{className:"mr-3 md:mr-4 text-xs md:text-sm opacity-60 bg-black/20 px-3 py-1 rounded-full",children:String.fromCharCode(65+m)}),e.jsx("span",{className:"line-clamp-2",children:h}),e.jsxs("div",{className:"absolute right-3 md:right-4 flex items-center gap-1.5 md:gap-2",children:[O&&e.jsx(y.div,{initial:{opacity:0,scale:.5},animate:{opacity:1,scale:1},className:"w-8 h-8 md:w-10 md:h-10 rounded-full border-[3px] border-[#0B0F19] overflow-hidden bg-rose-500 shadow-lg flex items-center justify-center z-10",children:a.mode==="bot"?e.jsx(Te,{className:"w-4 h-4 md:w-5 md:h-5 text-white"}):e.jsx(ke,{className:"w-4 h-4 md:w-5 md:h-5 text-white"})}),v&&e.jsx(y.div,{initial:{opacity:0,scale:.5},animate:{opacity:1,scale:1},className:"w-8 h-8 md:w-10 md:h-10 rounded-full border-[3px] border-[#0B0F19] overflow-hidden bg-indigo-200 shadow-lg z-20",children:e.jsx("img",{src:b?.photo||j,alt:"You",className:"w-full h-full object-cover"})})]})]},m)})}),e.jsx(Ze,{children:d&&!n&&a.mode==="online"&&e.jsxs(y.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,y:10},className:"mt-4 flex flex-col items-center gap-1",children:[e.jsxs("div",{className:"flex items-center gap-2 text-white/70 font-semibold bg-black/30 px-6 py-2 rounded-full border border-white/10",children:[e.jsx(Ke,{className:"w-4 h-4 animate-spin text-amber-400"}),"Waiting for opponent..."]}),e.jsx("p",{className:"text-white/30 text-[11px] mt-1",children:"Choices locked until round resolves"})]})}),e.jsx(Ze,{children:n?.studentCorrect&&e.jsx(y.div,{initial:{opacity:0,scale:.8,y:20},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:1.1,filter:"blur(10px)"},transition:{type:"spring",damping:20,stiffness:300},className:"fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 z-[100] pointer-events-none flex flex-col items-center justify-center",children:e.jsxs("div",{className:"bg-[#1e2433]/95 backdrop-blur-xl border border-white/10 rounded-[2rem] p-6 md:p-8 shadow-[0_30px_80px_rgba(0,0,0,0.6)] flex flex-col items-center min-w-[280px] md:min-w-[320px]",children:[e.jsx("img",{src:j,alt:"Mascot",className:"w-24 h-24 md:w-32 md:h-32 mb-4 drop-shadow-xl"}),e.jsx("h2",{className:u("text-3xl md:text-4xl font-black mb-4 uppercase tracking-widest",n.studentCorrect?"text-emerald-400":"text-rose-400"),children:n.studentCorrect?"Correct!":"Incorrect"}),n.studentCorrect?e.jsxs("div",{className:"flex items-center gap-3 w-full justify-center",children:[e.jsx("div",{className:"flex items-center gap-2 bg-emerald-500/20 text-emerald-400 px-4 py-2 rounded-2xl font-bold border border-emerald-500/30",children:e.jsx("span",{children:"+ 10 XP"})}),N!==null&&N>0&&e.jsx("div",{className:"flex items-center gap-2 bg-amber-500/20 text-amber-400 px-4 py-2 rounded-2xl font-bold border border-amber-500/30",children:e.jsxs("span",{children:["+ ",N," ",e.jsx(Je,{className:"w-4 h-4 inline"})]})})]}):e.jsxs("div",{className:"bg-rose-500/20 border border-rose-500/30 text-rose-400 font-bold px-5 py-2 rounded-xl text-center",children:["Correct: ",String.fromCharCode(65+n.correctOptionIndex)]})]})})})]}));za.displayName="BattleActiveContent";const _t={width:1280,height:720},St=` + */const os=[["rect",{x:"14",y:"4",width:"4",height:"16",rx:"1",key:"zuxfzm"}],["rect",{x:"6",y:"4",width:"4",height:"16",rx:"1",key:"1okwgv"}]],ls=xa("pause",os),We=({width:a,x:s,delay:n,duration:c})=>{const d=["#9956DE","#7274ED","#1FA7E1","#6ED1CF","#75D06A","#FFB356","#FF8B8B","#FB96BB"],l=d[Math.floor(Math.random()*d.length)],w=Math.floor(Math.random()*10)+1;return e.jsx(y.div,{style:{"--x":`${s}`,"--width":`${a}`,"--aspect-ratio":`${w}`,"--background":`linear-gradient(${l}cc, transparent)`},className:"absolute left-[var(--x)] top-0 [aspect-ratio:1/var(--aspect-ratio)] [background:var(--background)] [width:var(--width)]",initial:{y:"100cqmax",x:"-50%"},animate:{y:"-100%",x:"-50%"},transition:{duration:c,delay:n,repeat:Number.POSITIVE_INFINITY,ease:"linear"}})},na=({children:a,perspective:s=100,className:n,bgVideo:c,beamsPerSide:d=6,beamSize:l=4,beamDelayMax:w=1.5,beamDelayMin:A=0,beamDuration:f=4,gridColor:N="rgba(100, 116, 139, 0.08)",...b})=>{const j=i.useCallback(()=>{const S=[],Y=Math.floor(100/l)/d;for(let O=0;Oj(),[j]),m=i.useMemo(()=>j(),[j]),v=i.useMemo(()=>j(),[j]),W=i.useMemo(()=>j(),[j]);return e.jsxs("div",{className:u("relative w-full h-full",n),...b,children:[c?e.jsx("video",{autoPlay:!0,loop:!0,muted:!0,playsInline:!0,className:"pointer-events-none absolute inset-0 w-full h-full object-cover -z-10",src:c}):e.jsxs("div",{style:{"--perspective":`${s}px`,"--grid-color":N,"--beam-size":`${l}%`},className:"pointer-events-none absolute inset-0 overflow-hidden [clip-path:inset(0)] [container-type:size] [perspective:var(--perspective)] [transform-style:preserve-3d] -z-10 bg-[#42389d]",children:[e.jsx("div",{className:"absolute [transform-style:preserve-3d] [background-size:var(--beam-size)_var(--beam-size)] [background:linear-gradient(var(--grid-color)_0_1px,_transparent_1px_var(--beam-size))_50%_-0.5px_/var(--beam-size)_var(--beam-size),linear-gradient(90deg,_var(--grid-color)_0_1px,_transparent_1px_var(--beam-size))_50%_50%_/var(--beam-size)_var(--beam-size)] [container-type:inline-size] [height:100cqmax] [transform-origin:50%_0%] [transform:rotateX(-90deg)] [width:100cqi]",children:h.map((S,R)=>e.jsx(We,{width:`${l}%`,x:`${S.x*l}%`,delay:S.delay,duration:f},`top-${R}`))}),e.jsx("div",{className:"absolute top-full [transform-style:preserve-3d] [background-size:var(--beam-size)_var(--beam-size)] [background:linear-gradient(var(--grid-color)_0_1px,_transparent_1px_var(--beam-size))_50%_-0.5px_/var(--beam-size)_var(--beam-size),linear-gradient(90deg,_var(--grid-color)_0_1px,_transparent_1px_var(--beam-size))_50%_50%_/var(--beam-size)_var(--beam-size)] [container-type:inline-size] [height:100cqmax] [transform-origin:50%_0%] [transform:rotateX(-90deg)] [width:100cqi]",children:v.map((S,R)=>e.jsx(We,{width:`${l}%`,x:`${S.x*l}%`,delay:S.delay,duration:f},`bottom-${R}`))}),e.jsx("div",{className:"absolute left-0 top-0 [transform-style:preserve-3d] [background-size:var(--beam-size)_var(--beam-size)] [background:linear-gradient(var(--grid-color)_0_1px,_transparent_1px_var(--beam-size))_50%_-0.5px_/var(--beam-size)_var(--beam-size),linear-gradient(90deg,_var(--grid-color)_0_1px,_transparent_1px_var(--beam-size))_50%_50%_/var(--beam-size)_var(--beam-size)] [container-type:inline-size] [height:100cqmax] [transform-origin:0%_0%] [transform:rotate(90deg)_rotateX(-90deg)] [width:100cqh]",children:W.map((S,R)=>e.jsx(We,{width:`${l}%`,x:`${S.x*l}%`,delay:S.delay,duration:f},`left-${R}`))}),e.jsx("div",{className:"absolute right-0 top-0 [transform-style:preserve-3d] [background-size:var(--beam-size)_var(--beam-size)] [background:linear-gradient(var(--grid-color)_0_1px,_transparent_1px_var(--beam-size))_50%_-0.5px_/var(--beam-size)_var(--beam-size),linear-gradient(90deg,_var(--grid-color)_0_1px,_transparent_1px_var(--beam-size))_50%_50%_/var(--beam-size)_var(--beam-size)] [container-type:inline-size] [height:100cqmax] [width:100cqh] [transform-origin:100%_0%] [transform:rotate(-90deg)_rotateX(-90deg)]",children:m.map((S,R)=>e.jsx(We,{width:`${l}%`,x:`${S.x*l}%`,delay:S.delay,duration:f},`right-${R}`))})]}),e.jsx("div",{className:"relative z-10 w-full h-full",children:a})]})},is=15e3,ds="mathpulse.quizBattle.local",oa="".toLowerCase()==="true",rt=typeof window<"u",tt=()=>rt&&!1,Rt=()=>{const a=st.currentUser?.uid;return a||"local-student"},va=a=>`${ds}.${a}`,Pe=a=>{const s={stats:Se(a),history:[],queueStatus:"idle"};if(!rt)return s;try{const n=window.localStorage.getItem(va(a));if(!n)return s;const c=JSON.parse(n),d=Array.isArray(c.history)?c.history.map(w=>Ft(w.matchId||"local-match",w)):[];return{stats:c.stats?{...Se(a),...c.stats,userId:a,updatedAt:at(c.stats.updatedAt)}:Se(a),history:d,queueStatus:c.queueStatus==="queued"||c.queueStatus==="matched"?c.queueStatus:"idle"}}catch(n){return console.error("Error reading local Quiz Battle fallback store:",n),s}},ja=(a,s)=>{if(rt)try{window.localStorage.setItem(va(a),JSON.stringify(s))}catch(n){console.error("Error writing local Quiz Battle fallback store:",n)}},ya=a=>{const s=a||{},n=typeof s.code=="string"?s.code:"";return n?n.startsWith("functions/")?n.replace("functions/",""):n:""},ne=a=>{if(!tt())return!1;const s=ya(a);if(["internal","not-found","unavailable","deadline-exceeded"].includes(s))return!0;const n=a||{},c=(typeof n.message=="string"?n.message:a instanceof Error?a.message:"").toLowerCase();return c?c.includes("cors policy")||c.includes("no access-control-allow-origin")||c.includes("failed to fetch")||c.includes("network error")||c.includes("err_failed"):!1},Ye=(a,s)=>Math.floor(Math.random()*(s-a+1))+a,cs=(a,s)=>{const n=Math.max(3,a),c=s==="easy"?0:s==="medium"?1:s==="hard"?2:1,d=Ye(Math.max(0,n-3-c),n),l=Ye(Math.max(0,n-4+c),n),w=Math.min(n,Math.max(0,d)),A=Math.min(n,Math.max(0,l)),f=Math.max(0,Math.min(100,w/n*100+Ye(-8,6))),N=Ye(1800,6200);return{scoreFor:w,scoreAgainst:A,accuracy:f,averageResponseMs:N}},us=a=>{const s=Rt(),n=Pe(s),c=`local-bot-${Date.now()}-${Math.random().toString(16).slice(2,8)}`,d=cs(a.rounds,a.botDifficulty),l=d.scoreFor>d.scoreAgainst?"win":d.scoreFor0?m/h*100:0,averageAccuracy:h>0?(n.stats.averageAccuracy*n.stats.matchesPlayed+d.accuracy)/h:d.accuracy,averageResponseMs:h>0?Math.round((n.stats.averageResponseMs*n.stats.matchesPlayed+d.averageResponseMs)/h):d.averageResponseMs,currentStreak:S,bestStreak:R,favoriteTopicId:a.topicId,leaderboardScore:n.stats.leaderboardScore+j.xpEarned,updatedAt:w};ja(s,{stats:Y,history:[j,...n.history].slice(0,50),queueStatus:"idle"});try{pa(async()=>{const{emitPipelineEvent:O,getStudentContext:M}=await import("./pipelineService-D7yl0SJO.js");return{emitPipelineEvent:O,getStudentContext:M}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12])).then(({emitPipelineEvent:O,getStudentContext:M})=>{const D=M();D&&O({student_id:s,event_type:"battle",event_data:{battle_id:c,topic:a.topicId,score:d.accuracy,won:l==="win",total_questions:a.rounds,correct_answers:d.scoreFor},occurred_at:new Date().toISOString(),class_id:D.classId,teacher_id:D.teacherId})}).catch(()=>{})}catch{}return{success:!0,matchId:c,status:"ready",botDifficulty:a.botDifficulty}},Na=a=>{const s=Rt(),n=Pe(s);ja(s,{...n,queueStatus:a})},ms=()=>Math.random().toString(36).slice(2,8).toUpperCase(),Tt=a=>{const s=Rt();return{roomId:`local-room-${Date.now()}`,roomCode:a||ms(),ownerStudentId:s,participantIds:[s],participantCount:1,status:"waiting",subjectId:"gen-math",topicId:"functions",difficulty:"medium",rounds:5,timePerQuestionSec:30,isOwner:!0}},ka=()=>rt&&!!st.currentUser?.uid&&!!De,_a=(a,s,n)=>`quizBattlePresence/${a}/${s}/${n}`,xs=async(a,s)=>{if(!ka()||!s.trim()||!De)return;const n=st.currentUser?.uid;if(!n)return;const c=ba(De,_a(a,s,n));try{await fa(c,{studentId:n,scope:a,resourceId:s,online:!0,heartbeatAt:_e(),updatedAt:_e()}),await Za(c).update({online:!1,updatedAt:_e(),disconnectedAt:_e()})}catch(d){console.warn("Realtime presence connect failed:",d)}},ps=async(a,s)=>{if(!ka()||!s.trim()||!De)return;const n=st.currentUser?.uid;if(!n)return;const c=ba(De,_a(a,s,n));try{await fa(c,{studentId:n,scope:a,resourceId:s,online:!1,updatedAt:_e(),disconnectedAt:_e()})}catch(d){console.warn("Realtime presence disconnect failed:",d)}},V=(a,s)=>{const n=`Unable to continue while ${a}. Please try again.`;if(s instanceof Error&&s.message.startsWith("Timed out while"))return s.message;const c=s||{},d=ya(s),l=typeof c.message=="string"?c.message.trim():"";return d==="unauthenticated"?"Your session has expired. Sign in again before starting a battle.":d==="permission-denied"?"Only student accounts can access Quiz Battle matchmaking.":d==="invalid-argument"?l||"Battle setup is invalid. Review the selected options and try again.":d==="already-exists"?l||"This room is already full. Try another room code.":d==="failed-precondition"?l||"Battle state changed. Please refresh and continue.":d==="unavailable"||d==="internal"||d==="not-found"||d==="deadline-exceeded"?/question generation temporarily unavailable/i.test(l)?l:"Quiz Battle service is temporarily unavailable. Please retry in a moment.":n},$=async(a,s,n=is)=>{let c;try{return await Promise.race([s,new Promise((d,l)=>{c=setTimeout(()=>{l(new Error(`Timed out while ${a}. Please try again.`))},n)})])}finally{c&&clearTimeout(c)}},at=a=>{if(!a)return new Date;if(a instanceof Date)return a;if(typeof a=="string"){const s=Date.parse(a);return Number.isNaN(s)?new Date:new Date(s)}if(typeof a=="number")return new Date(a);if(typeof a=="object"){const s=a;if(typeof s.toDate=="function")return s.toDate();if(typeof s.seconds=="number")return new Date(s.seconds*1e3)}return new Date},hs=()=>({mode:"online",subjectId:"gen-math",topicId:"",difficulty:"medium",rounds:5,timePerQuestionSec:30,queueType:"public_matchmaking",botDifficulty:"medium",adaptiveBot:!1}),bs=a=>{const s=[];return a.subjectId.trim()||s.push({field:"subjectId",message:"Choose a category before starting."}),a.topicId.trim()||s.push({field:"topicId",message:"Choose a strand or topic before starting."}),(a.rounds<3||a.rounds>20)&&s.push({field:"rounds",message:"Questions must be between 3 and 20."}),(a.timePerQuestionSec<10||a.timePerQuestionSec>180)&&s.push({field:"timePerQuestionSec",message:"Timer must be between 10s and 180s."}),a.mode==="bot"&&a.queueType!=="public_matchmaking"&&s.push({field:"queueType",message:"Bot battles use instant start and do not support private room mode."}),s},Se=a=>({userId:a,matchesPlayed:0,wins:0,losses:0,draws:0,winRate:0,averageAccuracy:0,averageResponseMs:0,bestStreak:0,currentStreak:0,favoriteTopicId:void 0,leaderboardScore:0,updatedAt:new Date}),fs=async a=>{try{const s=Xa(et,"studentBattleStats",a),n=await Ga(s),c=tt()?Pe(a).stats:null;if(!n.exists())return c&&c.matchesPlayed>0?c:Se(a);const d=n.data(),l={...Se(a),...d,userId:a,updatedAt:at(d.updatedAt)};return c&&c.matchesPlayed>l.matchesPlayed?c:l}catch(s){if(console.error("Error loading battle stats:",s),tt()){const n=Pe(a).stats;if(n.matchesPlayed>0)return n}return Se(a)}},Ft=(a,s)=>({matchId:s.matchId||a,mode:s.mode||"online",status:s.status||"completed",subjectId:s.subjectId||"gen-math",topicId:s.topicId||"unknown-topic",difficulty:s.difficulty||"medium",rounds:s.rounds||0,timePerQuestionSec:s.timePerQuestionSec||0,scoreFor:s.scoreFor||0,scoreAgainst:s.scoreAgainst||0,outcome:s.outcome||"draw",accuracy:s.accuracy||0,averageResponseMs:s.averageResponseMs||0,bestStreak:s.bestStreak||0,xpEarned:s.xpEarned||0,opponentName:s.opponentName||"Unknown opponent",opponentType:s.opponentType||"student",createdAt:at(s.createdAt),endedAt:at(s.endedAt)}),gs=async(a,s={})=>{const n=s.limitCount||25,c=tt()?Pe(a).history:[],d=w=>w.filter(f=>!(s.mode&&s.mode!=="all"&&f.mode!==s.mode||s.subjectId&&f.subjectId!==s.subjectId||s.startDate&&f.endedAts.endDate)).sort((f,N)=>N.endedAt.getTime()-f.endedAt.getTime()).slice(0,n),l=w=>{if(c.length===0)return d(w);const A=new Map;return[...c,...w].forEach(f=>{A.set(f.matchId,f)}),d(Array.from(A.values()))};try{const w=[aa("studentId","==",a),ha("endedAt","desc"),Ct(n)],f=(await It(Bt(Mt(et,"quizBattleHistory"),...w))).docs.map(N=>Ft(N.id,N.data()));return l(f)}catch(w){try{const f=(await It(Bt(Mt(et,"quizBattleHistory"),aa("studentId","==",a),Ct(n)))).docs.map(N=>Ft(N.id,N.data())).sort((N,b)=>b.endedAt.getTime()-N.endedAt.getTime());return l(f)}catch(A){return console.error("Error loading battle history:",w,A),d(c)}}},ws=async a=>{const s=L(q,"quizBattleJoinQueue");try{return(await $("joining Quiz Battle matchmaking queue",s({setup:a}))).data}catch(n){if(ne(n))return Na("queued"),{success:!0,status:"queued",queueEntryId:`local-queue-${Date.now()}`};throw new Error(V("joining Quiz Battle matchmaking queue",n))}},la=async()=>{const a=L(q,"quizBattleLeaveQueue");try{return(await $("leaving Quiz Battle matchmaking queue",a({}))).data}catch(s){if(ne(s))return Na("idle"),{success:!0,status:"idle"};throw new Error(V("leaving Quiz Battle matchmaking queue",s))}},vs=async a=>{const s=L(q,"quizBattleCreatePrivateRoom");try{return(await $("creating Quiz Battle private room",s({setup:a}))).data}catch(n){if(ne(n))return{success:!0,room:Tt()};throw new Error(V("creating Quiz Battle private room",n))}},js=async a=>{const s=L(q,"quizBattleJoinPrivateRoom");try{return(await $("joining Quiz Battle private room",s({roomCode:a}),2e4)).data}catch(n){if(ne(n))return{success:!0,room:Tt(a.trim().toUpperCase()||void 0)};throw new Error(V("joining Quiz Battle private room",n))}},ys=async a=>{const s=L(q,"quizBattleGetPrivateRoomState");try{return(await $("loading Quiz Battle private room state",s(a),2e4)).data}catch(n){if(ne(n))return{success:!0,room:Tt(a.roomCode?.trim().toUpperCase()||void 0)};throw new Error(V("loading Quiz Battle private room state",n))}},Ns=async(a={})=>{const s=L(q,"quizBattleLeavePrivateRoom");try{return(await $("leaving Quiz Battle private room",s(a),2e4)).data}catch(n){if(ne(n))return{success:!0,status:"idle"};throw new Error(V("leaving Quiz Battle private room",n))}},ia=async()=>{const a=L(q,"quizBattleResumeSession");try{return(await $("resuming Quiz Battle session",a({}),2e4)).data}catch(s){if(ne(s))return{success:!0,sessionType:"idle"};throw new Error(V("resuming Quiz Battle session",s))}},ks=async(a,s)=>{if(!s.trim())return;const n=L(q,"quizBattleHeartbeat");await xs(a,s);try{await $("sending Quiz Battle heartbeat",n({scope:a,resourceId:s}),12e3)}catch(c){if(!ne(c))throw new Error(V("sending Quiz Battle heartbeat",c))}},_s=async a=>{const s=L(q,"quizBattleCreateBotMatch");try{return(await $("starting Quiz Battle bot match",s({setup:a}))).data}catch(n){if(ne(n))return us(a);throw new Error(V("starting Quiz Battle bot match",n))}},Ss=async a=>{const s=L(q,"quizBattleGetGenerationAudit");return(await $("verifying Quiz Battle generation metadata",s({matchId:a}),2e4)).data},re=async a=>{const s=L(q,"quizBattleStartMatch");try{const c=(await $("starting Quiz Battle match",s({matchId:a}),2e4)).data.match;if(c.mode==="online")try{const d=await Ss(a);if(oa&&!d.isAiSource)throw new Error(`Quiz Battle generation audit failed: expected AI source, got "${d.questionSetSource||"unknown"}".`)}catch(d){if(d instanceof Error&&d.message.startsWith("Quiz Battle generation audit failed"))throw d;if(console.warn("Quiz Battle generation audit unavailable:",d),oa)throw new Error("Unable to verify Quiz Battle generation metadata. Please retry in a moment.")}return c}catch(n){throw new Error(V("starting Quiz Battle match",n))}},kt=async a=>{const s=L(q,"quizBattleGetMatchState");try{return(await $("loading Quiz Battle match state",s({matchId:a}),2e4)).data.match}catch(n){throw new Error(V("loading Quiz Battle match state",n))}},As=async a=>{const s=L(q,"quizBattleSubmitAnswer");try{return(await $("submitting Quiz Battle answer",s({...a,idempotencyKey:a.idempotencyKey||`client-${Date.now()}-${Math.random().toString(16).slice(2,8)}`}),2e4)).data}catch(n){throw new Error(V("submitting Quiz Battle answer",n))}},zs=async a=>{const s=L(q,"quizBattleRequestRematch");try{return(await $("creating Quiz Battle rematch",s({matchId:a}),2e4)).data}catch(n){throw new Error(V("creating Quiz Battle rematch",n))}},Cs=async(a=20)=>{try{const s=Bt(Mt(et,"studentBattleLeaderboard"),ha("leaderboardScore","desc"),Ct(a));return(await It(s)).docs.map((c,d)=>{const l=c.data();return{userId:l.userId||c.id,displayName:l.displayName||"Student",photo:l.photo,rank:l.rank||d+1,leaderboardScore:l.leaderboardScore||0,winRate:l.winRate||0,bestStreak:l.bestStreak||0}})}catch(s){return console.error("Error loading Quiz Battle leaderboard:",s),[]}};function pe({className:a,...s}){return e.jsx("div",{"data-slot":"card",className:u("bg-card text-card-foreground flex flex-col gap-6 rounded-xl border",a),...s})}function he({className:a,...s}){return e.jsx("div",{"data-slot":"card-header",className:u("@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-1.5 px-6 pt-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6",a),...s})}function be({className:a,...s}){return e.jsx("h4",{"data-slot":"card-title",className:u("leading-none",a),...s})}function ye({className:a,...s}){return e.jsx("p",{"data-slot":"card-description",className:u("text-muted-foreground",a),...s})}function Xe({className:a,...s}){return e.jsx("div",{"data-slot":"card-content",className:u("px-6 [&:last-child]:pb-6",a),...s})}function Is({className:a,...s}){return e.jsx(Ka,{"data-slot":"tabs",className:u("flex flex-col gap-2",a),...s})}function Ne({className:a,...s}){return e.jsx(Ja,{"data-slot":"tabs-content",className:u("flex-1 outline-none",a),...s})}const Sa=Et.memo(({playerRoundStreak:a,playerVisualMultiplier:s,liveXpEarned:n,activeMatch:c,subjects:d,battleSoundEnabled:l,onToggleSound:w,isFullscreen:A,onToggleFullscreen:f,isDesignPauseAvailable:N,onTogglePause:b})=>e.jsxs("header",{className:"flex items-center justify-between shrink-0 h-14 sm:h-16 relative gap-2 sm:gap-4",children:[e.jsx("div",{className:"flex items-center min-w-0",children:e.jsxs("div",{className:"flex items-center gap-2 sm:gap-3 md:gap-4 px-2.5 sm:px-4 py-1.5 sm:py-2 md:px-5 md:py-2.5 rounded-full bg-white/5 border border-white/10 backdrop-blur-md min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1 sm:gap-1.5 text-amber-400 font-bold text-xs sm:text-sm shrink-0",children:[e.jsx(Ha,{className:"w-3 h-3 sm:w-4 sm:h-4"})," ",a]}),e.jsx("div",{className:"w-px h-3 sm:h-4 bg-white/10 shrink-0"}),e.jsxs("div",{className:"flex items-center gap-1 sm:gap-1.5 text-violet-300 font-bold text-xs sm:text-sm shrink-0",children:[e.jsx(zt,{className:"w-3 h-3 sm:w-4 sm:h-4"})," ",s.toFixed(2),"x"]}),e.jsx("div",{className:"w-px h-3 sm:h-4 bg-white/10 shrink-0"}),e.jsxs(y.div,{animate:n>0?{scale:[1,1.25,1]}:{},transition:{duration:.35},className:"flex flex-col items-center text-emerald-400 bg-emerald-500/10 px-2 sm:px-3 py-0.5 rounded-full border border-emerald-500/20 font-bold shadow-[0_0_10px_rgba(16,185,129,0.15)] shrink-0",children:[e.jsxs("span",{className:"text-xs sm:text-sm leading-none tabular-nums",children:[n," pts"]}),e.jsx("span",{className:"hidden sm:block text-[8px] leading-none text-emerald-500/70 uppercase tracking-widest font-black whitespace-nowrap",children:"Battle Score"})]},n)]})}),e.jsxs("div",{className:"absolute left-1/2 -translate-x-1/2 hidden md:flex items-center gap-3 bg-black/20 px-5 py-2 rounded-full border border-white/5 min-w-0 max-w-[48%]",children:[e.jsx("div",{className:"w-3.5 h-3.5 rounded-sm bg-orange-400 shadow-[0_0_10px_rgba(251,146,60,0.5)] shrink-0"}),e.jsx("div",{className:"flex flex-col items-start justify-center -space-y-0.5 min-w-0",children:(()=>{if(!c?.topicId)return e.jsx("span",{className:"font-bold text-white/90 tracking-wide text-sm leading-none truncate",children:"Practice Match"});for(const j of d){const h=j.modules?.find(m=>m.id===c.topicId);if(h)return e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-[9px] font-black text-white/40 uppercase tracking-widest leading-none",children:j.title}),e.jsx("span",{className:"font-bold text-white/90 tracking-wide text-sm leading-none pt-1 truncate",children:h.title})]})}return e.jsx("span",{className:"font-bold text-white/90 tracking-wide text-sm leading-none truncate",children:c.topicId.split("-").map(j=>j.charAt(0).toUpperCase()+j.slice(1)).join(" ")})})()})]}),e.jsxs("div",{className:"flex items-center gap-1.5 sm:gap-3",children:[e.jsx(z,{variant:"outline",size:"icon",className:"h-9 w-9 sm:h-12 sm:w-12 rounded-full border-white/20 bg-black/20 hover:bg-white/10 text-white",onClick:w,children:l?e.jsx(ga,{className:"h-4 w-4 sm:h-5 sm:w-5"}):e.jsx(wa,{className:"h-4 w-4 sm:h-5 sm:w-5"})}),e.jsx(z,{variant:"outline",size:"icon",className:"hidden sm:flex h-12 w-12 rounded-full border-white/20 bg-black/20 hover:bg-white/10 text-white",onClick:f,children:A?e.jsx(as,{className:"h-5 w-5"}):e.jsx(ss,{className:"h-5 w-5"})}),e.jsx(z,{variant:"outline",size:"icon",className:u("h-9 w-9 sm:h-12 sm:w-12 rounded-full border-white/20 text-white",N?"bg-black/20 hover:bg-white/10":"bg-black/10 opacity-50 cursor-not-allowed"),onClick:b,disabled:!N,children:e.jsx(Va,{className:"h-4 w-4 sm:h-5 sm:w-5"})})]})]}));Sa.displayName="BattleHeader";const Aa=Et.memo(({studentProfile:a,activeMatch:s,scorePulseTarget:n,quizBattleAvatar:c,opponentId:d})=>{const[l,w]=i.useState(null);return i.useEffect(()=>{if(!d)return;let A=!1;return Ua(d).then(f=>{!A&&f?.avatarLayers&&w(f.avatarLayers)}).catch(()=>{}),()=>{A=!0}},[d]),e.jsxs("div",{className:"absolute bottom-0 left-0 right-0 w-full xl:max-w-[1400px] mx-auto px-2 sm:px-4 md:px-8 shrink-0 h-28 sm:h-32 md:h-48 flex justify-between items-end pb-0 pointer-events-none z-30",children:[e.jsxs("div",{className:"flex items-end gap-1.5 sm:gap-3 md:gap-6 relative pointer-events-auto",children:[e.jsx("div",{className:"relative w-16 h-16 sm:w-28 sm:h-28 md:w-40 md:h-40 rounded-t-[40px] flex items-end",children:e.jsx(yt,{layers:a?.avatarLayers||{},className:"w-full h-full object-contain origin-bottom scale-[1.15]"})}),e.jsxs("div",{className:"bg-black/40 backdrop-blur-xl border border-white/20 rounded-xl sm:rounded-2xl px-2 sm:px-4 py-2 sm:py-3 md:px-5 shadow-[0_8px_30px_rgba(0,0,0,0.5)] flex items-center gap-1.5 sm:gap-3 md:gap-4 mb-2 sm:mb-4 max-w-[130px] sm:max-w-[220px] md:max-w-[280px]",children:[e.jsxs("div",{className:"flex flex-col flex-1 min-w-0",children:[e.jsx("span",{className:"text-white font-black text-xs sm:text-base md:text-lg truncate tracking-wide",children:a?.name||"Player"}),e.jsxs("span",{className:"text-[9px] sm:text-xs md:text-sm text-white/50 font-bold uppercase tracking-wider",children:["Level ",a?.level||1]})]}),e.jsx("div",{className:"h-6 sm:h-10 w-px bg-white/20"}),e.jsxs("div",{className:"flex flex-col items-center justify-center shrink-0 w-6 sm:w-10 md:w-12",children:[e.jsx(y.span,{animate:n==="player"?{scale:[1,1.4,1],color:["#fff","#34d399","#fff"]}:{},transition:{duration:.5},className:"text-lg sm:text-2xl md:text-3xl font-black text-white leading-none",children:s.scoreFor}),e.jsx("span",{className:"text-[7px] sm:text-[9px] md:text-[10px] text-emerald-400 font-bold uppercase tracking-widest mt-0.5 sm:mt-1 leading-none",children:"Score"})]})]})]}),e.jsxs("div",{className:"flex items-end gap-1.5 sm:gap-3 md:gap-6 relative flex-row-reverse pointer-events-auto",children:[e.jsx("div",{className:"relative w-16 h-16 sm:w-28 sm:h-28 md:w-40 md:h-40 rounded-t-[40px] flex items-end justify-center",children:s.mode==="bot"?e.jsx(Te,{className:"h-8 w-8 sm:h-16 sm:w-16 md:h-20 md:w-20 text-rose-400 mb-3 sm:mb-6 drop-shadow-xl",strokeWidth:1.5}):l?e.jsx(yt,{layers:l,className:"w-full h-full object-contain origin-bottom scale-[1.15]"}):e.jsx(yt,{layers:{},className:"w-full h-full object-contain origin-bottom scale-[1.15]"})}),e.jsxs("div",{className:"bg-black/40 backdrop-blur-xl border border-white/20 rounded-xl sm:rounded-2xl px-2 sm:px-4 py-2 sm:py-3 md:px-5 shadow-[0_8px_30px_rgba(0,0,0,0.5)] flex items-center gap-1.5 sm:gap-3 md:gap-4 mb-2 sm:mb-4 flex-row-reverse text-right max-w-[130px] sm:max-w-[220px] md:max-w-[280px]",children:[e.jsxs("div",{className:"flex flex-col flex-1 min-w-0",children:[e.jsx("span",{className:"text-white font-black text-xs sm:text-base md:text-lg truncate tracking-wide",children:s.opponentName||"Anonymous"}),e.jsx("span",{className:"text-[9px] sm:text-xs md:text-sm text-rose-400 font-bold uppercase tracking-wider",children:s.mode==="bot"?"System Bot":"Challenger"})]}),e.jsx("div",{className:"h-6 sm:h-10 w-px bg-white/20"}),e.jsxs("div",{className:"flex flex-col items-center justify-center shrink-0 w-6 sm:w-10 md:w-12",children:[e.jsx(y.span,{animate:n==="opponent"?{scale:[1,1.4,1],color:["#fff","#fb7185","#fff"]}:{},transition:{duration:.5},className:"text-lg sm:text-2xl md:text-3xl font-black text-white leading-none",children:s.scoreAgainst}),e.jsx("span",{className:"text-[7px] sm:text-[9px] md:text-[10px] text-rose-400 font-bold uppercase tracking-widest mt-0.5 sm:mt-1 leading-none",children:"Score"})]})]})]})]})});Aa.displayName="BattleFooter";const za=Et.memo(({activeMatch:a,roundSecondsLeft:s,lastRoundResult:n,selectedOptionIndex:c,roundLocked:d,answerSubmitting:l,designPauseActive:w,onOptionSelect:A,floatingMomentum:f,lastRoundMomentumDelta:N,studentProfile:b,quizBattleAvatar:j})=>e.jsxs("div",{className:"flex-1 flex flex-col justify-center items-center gap-4 md:gap-6 w-full min-h-0 overflow-y-auto pt-4 pb-28 z-20 no-scrollbar",children:[e.jsxs("div",{className:u("relative bg-[#1e2536] border shadow-[0_20px_60px_rgba(0,0,0,0.4)] rounded-[1.5rem] p-5 md:p-6 w-full max-w-4xl text-center flex flex-col items-center",s<=3?"border-rose-400/50":"border-white/10"),children:[e.jsxs("div",{className:"absolute -top-3.5 bg-[#2f3547] border border-white/10 text-white/80 px-4 py-1 rounded-full text-xs font-black shadow-lg uppercase tracking-wider",children:[a.currentRound," / ",a.totalRounds]}),e.jsx(Ze,{children:f&&f.tone==="positive"&&e.jsx(y.div,{initial:{opacity:0,y:14,scale:.92},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-10,scale:.9},className:u("absolute -top-12 rounded-full border px-3 py-1 text-[10px] font-black uppercase tracking-[0.15em] backdrop-blur-lg",f.tone==="positive"?"border-emerald-300/70 bg-emerald-500/20 text-emerald-100":f.tone==="negative"?"border-rose-300/70 bg-rose-500/20 text-rose-100":"border-slate-300/50 bg-slate-500/20 text-slate-100"),children:f.label},f.id)}),e.jsx("p",{className:"text-base sm:text-lg md:text-xl text-white font-extrabold leading-tight tracking-tight mt-1 min-h-[40px] flex items-center justify-center",children:a.currentQuestion?.prompt}),typeof window<"u"&&window.location.search.includes("debug=true")&&a.currentQuestion?.varianceApplied&&e.jsx("div",{className:"flex flex-wrap gap-1 mt-2 justify-center",children:a.currentQuestion.varianceApplied.map(h=>e.jsx("span",{className:"inline-flex items-center px-2 py-0.5 rounded text-[10px] font-medium bg-blue-500/20 text-blue-200 border border-blue-400/30",children:h.replace(/_/g," ")},h))})]}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3 md:gap-4 w-full max-w-4xl px-4",children:a.currentQuestion?.choices.map((h,m)=>{const v=c===m,W=l||d,S=!!n&&n.roundNumber===a.currentRound,R=S&&n.correctOptionIndex===m;let Y=-1;if(S)if(a.mode==="bot")if(n.botCorrect)Y=n.correctOptionIndex;else{const D=[0,1,2,3].filter(C=>C!==n.correctOptionIndex);Y=D[n.roundNumber%D.length]}else Y=typeof n.botSelectedIndex=="number"?n.botSelectedIndex:-1;const O=Y===m;let M="bg-[#1e2433] hover:bg-[#283042] border-[#2f384e] text-white shadow-[0_6px_0_rgba(15,20,30,0.5)]";return S?R?M="bg-emerald-500 text-emerald-950 border-emerald-400 shadow-[0_6px_0_rgba(5,150,105,1)]":v?M="bg-rose-500 text-white border-rose-400 shadow-[0_6px_0_rgba(225,29,72,1)]":M="bg-[#1e2433] opacity-40 border-[#2f384e] shadow-[0_6px_0_rgba(15,20,30,0.5)] text-white":v&&(M="bg-indigo-500 text-white border-indigo-400 shadow-[0_6px_0_rgba(79,70,229,1)]"),e.jsxs(y.button,{whileTap:{y:8,scale:.98},whileHover:!S&&!W?{scale:1.02}:{},disabled:W||d||w,onClick:()=>A(m),className:u("relative h-16 md:h-20 rounded-2xl md:rounded-3xl font-black text-base md:text-lg pl-6 pr-20 border-[2px] border-b-[4px] flex items-center justify-start text-left transition-all disabled:cursor-not-allowed",M,v&&!S?"ring-[4px] ring-white/20 ring-offset-[4px] ring-offset-[#0B0F19]":"",s<=3&&!W&&!S?"shadow-[0_0_0_2px_rgba(251,113,133,0.45),0_6px_0_rgba(127,29,29,1)]":""),children:[e.jsx("span",{className:"mr-3 md:mr-4 text-xs md:text-sm opacity-60 bg-black/20 px-3 py-1 rounded-full",children:String.fromCharCode(65+m)}),e.jsx("span",{className:"line-clamp-2",children:h}),e.jsxs("div",{className:"absolute right-3 md:right-4 flex items-center gap-1.5 md:gap-2",children:[O&&e.jsx(y.div,{initial:{opacity:0,scale:.5},animate:{opacity:1,scale:1},className:"w-8 h-8 md:w-10 md:h-10 rounded-full border-[3px] border-[#0B0F19] overflow-hidden bg-rose-500 shadow-lg flex items-center justify-center z-10",children:a.mode==="bot"?e.jsx(Te,{className:"w-4 h-4 md:w-5 md:h-5 text-white"}):e.jsx(ke,{className:"w-4 h-4 md:w-5 md:h-5 text-white"})}),v&&e.jsx(y.div,{initial:{opacity:0,scale:.5},animate:{opacity:1,scale:1},className:"w-8 h-8 md:w-10 md:h-10 rounded-full border-[3px] border-[#0B0F19] overflow-hidden bg-indigo-200 shadow-lg z-20",children:e.jsx("img",{src:b?.photo||j,alt:"You",className:"w-full h-full object-cover"})})]})]},m)})}),e.jsx(Ze,{children:d&&!n&&a.mode==="online"&&e.jsxs(y.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,y:10},className:"mt-4 flex flex-col items-center gap-1",children:[e.jsxs("div",{className:"flex items-center gap-2 text-white/70 font-semibold bg-black/30 px-6 py-2 rounded-full border border-white/10",children:[e.jsx(Ke,{className:"w-4 h-4 animate-spin text-amber-400"}),"Waiting for opponent..."]}),e.jsx("p",{className:"text-white/30 text-[11px] mt-1",children:"Choices locked until round resolves"})]})}),e.jsx(Ze,{children:n?.studentCorrect&&e.jsx(y.div,{initial:{opacity:0,scale:.8,y:20},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:1.1,filter:"blur(10px)"},transition:{type:"spring",damping:20,stiffness:300},className:"fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 z-[100] pointer-events-none flex flex-col items-center justify-center",children:e.jsxs("div",{className:"bg-[#1e2433]/95 backdrop-blur-xl border border-white/10 rounded-[2rem] p-6 md:p-8 shadow-[0_30px_80px_rgba(0,0,0,0.6)] flex flex-col items-center min-w-[280px] md:min-w-[320px]",children:[e.jsx("img",{src:j,alt:"Mascot",className:"w-24 h-24 md:w-32 md:h-32 mb-4 drop-shadow-xl"}),e.jsx("h2",{className:u("text-3xl md:text-4xl font-black mb-4 uppercase tracking-widest",n.studentCorrect?"text-emerald-400":"text-rose-400"),children:n.studentCorrect?"Correct!":"Incorrect"}),n.studentCorrect?e.jsxs("div",{className:"flex items-center gap-3 w-full justify-center",children:[e.jsx("div",{className:"flex items-center gap-2 bg-emerald-500/20 text-emerald-400 px-4 py-2 rounded-2xl font-bold border border-emerald-500/30",children:e.jsx("span",{children:"+ 10 XP"})}),N!==null&&N>0&&e.jsx("div",{className:"flex items-center gap-2 bg-amber-500/20 text-amber-400 px-4 py-2 rounded-2xl font-bold border border-amber-500/30",children:e.jsxs("span",{children:["+ ",N," ",e.jsx(Je,{className:"w-4 h-4 inline"})]})})]}):e.jsxs("div",{className:"bg-rose-500/20 border border-rose-500/30 text-rose-400 font-bold px-5 py-2 rounded-xl text-center",children:["Correct: ",String.fromCharCode(65+n.correctOptionIndex)]})]})})})]}));za.displayName="BattleActiveContent";const _t={width:1280,height:720},St=` @keyframes mascot-float { 0%, 100% { transform: translateY(0) rotate(-3deg); } 50% { transform: translateY(-24px) rotate(3deg); } @@ -103,4 +103,4 @@ import{e as xa,o as u,m as y,g as et,aM as De,k as st,aN as q,_ as pa,$ as Ha,r .animate-reward-pop { animation: reward-pop 0.5s cubic-bezier(0.22, 1, 0.36, 1) forwards; } .animate-score-pop { animation: score-pop 0.5s ease-out forwards; } .animate-overlay-slide-up { animation: overlay-slide-up 0.4s cubic-bezier(0.22, 1, 0.36, 1) forwards; } -`,Bs=300*1e3,Ms=({viewportHeight:a})=>e.jsx("div",{className:"absolute inset-0 pointer-events-none z-[50] overflow-hidden flex justify-between bg-slate-900/10",children:i.useMemo(()=>[...Array(40)].map((s,n)=>({id:n,left:`${Math.random()*100}%`,duration:.6+Math.random()*.4,delay:Math.random()*.4})),[a]).map(s=>e.jsx(y.div,{className:"absolute w-0.5 h-16 bg-blue-300/40 rounded-full e-left-top",style:{"--left":s.left,"--top":"-10%"},animate:{y:[0,a*1.2]},transition:{duration:s.duration,ease:"linear",delay:s.delay}},s.id))}),Fs=({viewportHeight:a,viewportWidth:s})=>{const n=i.useMemo(()=>[...Array(30)].map((c,d)=>({id:d,xShift:(Math.random()-.5)*s*.8,yShift:(Math.random()-.5)*a*.8,scale:Math.random()*1.5+.5,duration:2+Math.random()*1.5,delay:Math.random()*.35})),[a,s]);return e.jsx("div",{className:"absolute inset-0 pointer-events-none z-[50] overflow-hidden flex items-center justify-center",children:n.map(c=>e.jsx(y.div,{className:"absolute w-2 h-2 bg-amber-400 rounded-full shadow-[0_0_10px_rgba(251,191,36,0.8)] e-left-top",style:{"--left":"50%","--top":"50%"},animate:{y:[0,c.yShift],x:[0,c.xShift],scale:[0,c.scale,0],opacity:[0,1,0]},transition:{duration:c.duration,ease:"easeOut",delay:c.delay}},c.id))})},da=({value:a,label:s,delay:n=0,icon:c})=>{const[d,l]=i.useState(0);return i.useEffect(()=>{if(a<=0)return;const w=1e3,A=30,f=Math.abs(Math.floor(w/A));let N=0;const b=setTimeout(()=>{const j=setInterval(()=>{N+=Math.max(1,Math.floor(a/A)),N>=a?(l(a),clearInterval(j)):l(N)},f);return()=>clearInterval(j)},n);return()=>clearTimeout(b)},[a,n]),a<=0?null:e.jsxs(y.div,{initial:{opacity:0,transform:"translateX(-20px)"},animate:{opacity:1,transform:"translateX(0)"},transition:{delay:n/1e3,duration:.5},className:"flex items-center justify-between bg-white/5 border border-white/10 rounded-xl p-3",children:[e.jsxs("div",{className:"flex items-center gap-3 text-white/80 font-bold uppercase tracking-wider text-sm",children:[c,s]}),e.jsxs("div",{className:"text-2xl font-black text-amber-400 tabular-nums",children:["+",d]})]})},fe="border border-border bg-card text-card-foreground shadow-sm dark:border-[#2b3140] dark:bg-[#181d27] dark:text-[#f5f7fb] dark:shadow-[0_12px_24px_rgba(0,0,0,0.22)]",Es=a=>a<=0?"--":`${(a/1e3).toFixed(2)}s`,Rs=a=>a==="win"?"Win":a==="loss"?"Loss":"Draw",Ge=(a,s,n)=>Math.max(s,Math.min(n,a)),ca=a=>{const s=Math.floor(a/60),n=a%60;return`${s}:${String(n).padStart(2,"0")}`},Ts=a=>{const s=a.trim().split(/\s+/).filter(Boolean).slice(0,2);return s.length===0?"ST":s.map(n=>n[0]?.toUpperCase()||"").join("")},ua=(a,s)=>a?a.eventType==="round_started"?`Round ${a.roundNumber} started.`:a.eventType==="answer_locked"?a.lockedByStudentId&&s&&a.lockedByStudentId===s?`Round ${a.roundNumber}: your answer is locked.`:`Round ${a.roundNumber}: opponent answer locked.`:a.eventType==="round_result"?`Round ${a.roundNumber} resolved.`:"Match completed.":null;let At=null;const ma=()=>{if(typeof window>"u")return null;if(!At){const a=window.AudioContext||window.webkitAudioContext;a&&(At=new a)}return At},cr=()=>{const{userProfile:a,userRole:s}=Wa(),n=a,[c,d]=i.useState("hub"),[l,w]=i.useState(hs),[A,f]=i.useState([]),[N,b]=i.useState({status:"idle"}),[j,h]=i.useState(!1),[m,v]=i.useState(null),[W,S]=i.useState(""),[R,Y]=i.useState(null),[O,M]=i.useState(0),[D,C]=i.useState(null),[J,Dt]=i.useState(()=>typeof window>"u"?!0:window.localStorage.getItem("quiz_battle_sound_enabled")!=="0"),[ce,Ca]=i.useState(()=>{if(typeof window>"u")return .7;const t=Number(window.localStorage.getItem("quiz_battle_sound_volume")||"0.7");return Number.isFinite(t)?Ge(t,0,1):.7}),[Pt,I]=i.useState("connected"),[ge,Ia]=i.useState("all"),[Qt,nt]=i.useState(!0),[ee,ot]=i.useState(null),[lt,it]=i.useState([]),[Ba,qt]=i.useState(!1),[Lt,Ma]=i.useState([]),[dt,Ds]=i.useState("full"),[$t,Ps]=i.useState(!0),[r,_]=i.useState(null),[we,X]=i.useState(null),[G,Ae]=i.useState(!1),[P,ze]=i.useState(0),[Z,K]=i.useState(!1),[F,ct]=i.useState(!1),[Fa,Ea]=i.useState(!1),[ut,Ra]=i.useState(_t),[B,te]=i.useState(null),[Ta,mt]=i.useState(!1),[Qe,xt]=i.useState(null),[Da,pt]=i.useState(null),[Pa,qe]=i.useState(null),Ot=i.useRef(""),ht=i.useRef(null),ve=i.useRef(null),oe=i.useRef(0),Ht=i.useRef(""),Ce=i.useRef(0),bt=i.useRef(0),Le=i.useRef(null),Ie=i.useRef(null),$e=i.useRef(-1),ft=!1,le=i.useMemo(()=>{const t=Ya(n?.grade);return ta.filter(o=>t.includes(o.id))},[n?.grade]),Qa=i.useMemo(()=>(le.find(o=>o.id===l.subjectId)?.modules||[]).map(o=>({value:o.id,label:o.title})),[le,l.subjectId]),H=i.useMemo(()=>{const t=r?.roundResults||[];let o=0;return t.forEach(p=>{o=p.studentCorrect?o+1:0}),o},[r?.roundResults]),qa=i.useMemo(()=>{const t=Math.max(0,H-1)*.12;return Number((1+Math.min(.72,t)).toFixed(2))},[H]),La=i.useMemo(()=>{if(!r)return 0;if(r.status==="completed")return r.xpEarned||0;const t=r.roundResults||[];let o=0,p=0;for(const x of t)if(x.studentCorrect){o++;const k=o>=2?Math.min(25,(o-1)*5):0;p+=10+k}else o=0;return p},[r?.status,r?.xpEarned,r?.roundResults]),Vt=i.useMemo(()=>{const t=r?.roundResults||[];let o=0;return t.forEach(p=>{o=p.botCorrect?o+1:0}),o},[r?.roundResults]);i.useMemo(()=>{const t=Math.max(0,Vt-1)*.1;return Number((1+Math.min(.5,t)).toFixed(2))},[Vt]),i.useMemo(()=>H>=5?{label:"Inferno",badgeClass:"text-amber-300 border-amber-300/50 bg-amber-500/20 shadow-[0_0_18px_rgba(251,191,36,0.35)]"}:H>=3?{label:"Heating Up",badgeClass:"text-orange-300 border-orange-300/50 bg-orange-500/15 shadow-[0_0_16px_rgba(249,115,22,0.3)]"}:B?.studentCorrect?{label:"Steady",badgeClass:"text-emerald-300 border-emerald-300/40 bg-emerald-500/15 shadow-[0_0_14px_rgba(16,185,129,0.25)]"}:{label:"Rebuild",badgeClass:"text-slate-300 border-slate-300/30 bg-slate-500/15 shadow-[0_0_14px_rgba(148,163,184,0.2)]"},[B?.studentCorrect,H]);const ie=i.useMemo(()=>{if(!B)return null;const t=B.studentCorrect?12:-8,o=B.studentCorrect&&!B.botCorrect?6:0,p=B.studentCorrect?Math.max(0,(H-1)*2):0;return t+o+p},[B,H]),Q=i.useCallback(t=>{if(!(!J||ce<=0||typeof window>"u"))try{const o=ma();if(!o)return;o.state==="suspended"&&o.resume().catch(()=>{});const x={tick:{notes:[740],duration:.06,type:"triangle",volume:.03},lock:{notes:[520],duration:.08,type:"square",volume:.04},result:{notes:[660,720],duration:.08,type:"sine",volume:.04},win:{notes:[920,1040,1180],duration:.12,type:"triangle",volume:.05},loss:{notes:[260,220],duration:.14,type:"sawtooth",volume:.045},streak:{notes:[780,920],duration:.09,type:"triangle",volume:.045},multiplier:{notes:[660,880,1120],duration:.08,type:"triangle",volume:.05}}[t],k=o.currentTime,T=.07,g=Ge(x.volume*ce,.004,.08);x.notes.forEach((E,se)=>{const me=o.createOscillator(),Be=o.createGain(),je=k+se*T;me.type=x.type,me.frequency.setValueAtTime(E,je),Be.gain.setValueAtTime(1e-4,je),Be.gain.exponentialRampToValueAtTime(g,je+.012),Be.gain.exponentialRampToValueAtTime(1e-4,je+x.duration),me.connect(Be),Be.connect(o.destination),me.start(je),me.stop(je+x.duration+.02)})}catch(o){console.warn("Battle tone playback skipped or blocked:",o)}},[J,ce]),Ut=i.useCallback(async t=>{if(!(!t||typeof window>"u"))try{await window.navigator.clipboard.writeText(t),Y(t),window.setTimeout(()=>{Y(o=>o===t?null:o)},1600)}catch{b({status:"error",message:"Unable to copy room code automatically. Please copy it manually."})}},[]),Wt=i.useCallback(()=>{},[ft]),Yt=i.useCallback(t=>{h(!1),v(null),_(null),M(0),C(null),b({status:"error",message:t}),d("setup")},[]),ae=i.useCallback(async()=>{if(!n?.uid)return null;const[t,o]=await Promise.all([fs(n.uid),gs(n.uid,{mode:ge,limitCount:8})]);return{stats:t,history:o}},[ge,n?.uid]);i.useEffect(()=>{if(le.length===0)return;const o=le.some(k=>k.id===l.subjectId)?l.subjectId:le[0].id,p=le.find(k=>k.id===o),x=p?.modules?.[0]?.id||"";w(k=>{const T=p?.modules?.some(g=>g.id===k.topicId)?k.topicId:x;return k.subjectId===o&&k.topicId===T?k:{...k,subjectId:o,topicId:T}})},[le,l.subjectId]),i.useEffect(()=>{if(!n?.uid){ot(null),it([]),nt(!1);return}let t=!0;return nt(!0),(async()=>{const p=await ae();t&&(p&&(ot(p.stats),it(p.history)),nt(!1))})(),()=>{t=!1}},[ae,n?.uid]);const Oe=i.useMemo(()=>ge==="all"?lt:lt.filter(t=>t.mode===ge),[lt,ge]),Xt=i.useMemo(()=>Lt.map((t,o)=>{const p=t.rank||o+1,x=t.userId===n?.uid,k=`Student-${t.userId.slice(-4).toUpperCase()}`,T=dt==="full"?t.displayName:dt==="initials"?Ts(t.displayName):k,g=Math.floor(t.leaderboardScore/25)*25,E=$t||x?`${t.leaderboardScore} pts`:`${g}-${g+24} pts`;return{...t,rank:p,isSelf:x,displayName:T,scoreLabel:E}}),[Lt,dt,$t,n?.uid]);i.useEffect(()=>{if(c!=="leaderboard"&&c!=="hub")return;let t=!0;return qt(!0),(async()=>{const p=await Cs(20);t&&(Ma(p),qt(!1))})(),()=>{t=!1}},[c]);const He=i.useCallback(async()=>{if(n?.uid)try{const t=await ia();if(t.sessionType==="match"&&t.match){let o=t.match;if(t.match.mode==="bot"&&t.match.status==="ready")try{o=await re(t.match.matchId),Ce.current=0}catch(p){const x=p;h(!1),v(null),_(null),d("setup"),I(typeof window<"u"&&window.navigator.onLine?"connected":"disconnected"),b({status:"error",message:x?.message||"Unable to resume bot battle. Please start a new match."});return}h(!1),v(t.room||null),_(o),C(t.queue?.expiresAtMs||o.expiresAtMs||null),d("battle"),I("connected");return}if(t.sessionType==="room"&&t.room){h(!1),v(t.room),_(o=>o?.mode==="bot"?o:null),C(null),I("connected");return}if(t.sessionType==="queue"){h(!0),v(null),_(o=>o?.mode==="bot"?o:null),C(t.queue?.expiresAtMs||null),I("connected");return}h(!1),v(null),_(o=>o?.mode==="bot"?o:null),C(null),I("connected")}catch(t){console.warn("Quiz Battle session resume failed:",t),I("reconnecting")}},[n?.uid]);i.useEffect(()=>{n?.uid&&He()},[n?.uid,He]),i.useEffect(()=>{typeof window>"u"||window.localStorage.setItem("quiz_battle_sound_enabled",J?"1":"0")},[J]),i.useEffect(()=>{typeof window>"u"||window.localStorage.setItem("quiz_battle_sound_volume",ce.toFixed(2))},[ce]),i.useEffect(()=>{if(typeof window>"u")return;const t=()=>{const o=window.innerWidth,p=window.innerHeight;Ra({width:Number.isFinite(o)&&o>0?o:_t.width,height:Number.isFinite(p)&&p>0?p:_t.height})};return t(),window.addEventListener("resize",t),()=>{window.removeEventListener("resize",t)}},[]),i.useEffect(()=>{if(typeof document>"u")return;const t=()=>{Ea(!!document.fullscreenElement)};return t(),document.addEventListener("fullscreenchange",t),()=>{document.removeEventListener("fullscreenchange",t)}},[]),i.useEffect(()=>{const t=D!==null;if(!(j||m&&(m.status==="waiting"||m.status==="ready")||t)){M(0);return}const o=()=>{if(!D){M(x=>x+1);return}M(Math.max(0,Math.ceil((D-Date.now())/1e3)))};o();const p=window.setInterval(o,1e3);return()=>{window.clearInterval(p)}},[j,m?.status,m?.roomId,D]),i.useEffect(()=>{if(!D)return;const t=window.setInterval(()=>{D-Date.now()<=0&&(window.clearInterval(t),(async()=>{try{(j||!m)&&await la()}catch{}finally{Yt("Public matchmaking timed out after 5 minutes. Please start again.")}})())},1e3);return()=>{window.clearInterval(t)}},[m,Yt,j,D]),i.useEffect(()=>{if(typeof window>"u")return;I(window.navigator.onLine?"connected":"disconnected");const t=()=>{I("reconnecting"),He()},o=()=>{I("disconnected")};return window.addEventListener("online",t),window.addEventListener("offline",o),()=>{window.removeEventListener("online",t),window.removeEventListener("offline",o)}},[He]),i.useEffect(()=>{const t=r?.mode==="online"&&(r.status==="ready"||r.status==="in_progress"),o=r?.mode==="bot"&&r.status==="ready",p=!!(m&&(m.status==="waiting"||m.status==="ready"));if(o||(Ce.current=0),!j&&!p&&!t&&!o||F)return;let x=!1;const k=async()=>{try{if(r?.mode==="bot"&&r.status==="ready"){const g=await re(r.matchId);if(x)return;_(g),I("connected"),C(g.expiresAtMs||null),Ce.current=0,g.status==="in_progress"&&b({status:"queued",message:"Practice bot match started."});return}if(r?.mode==="online"){if(r.status==="ready"){const se=await re(r.matchId);if(x)return;_(se),I("connected"),C(se.expiresAtMs||null),se.status==="in_progress"&&b({status:"queued",message:"Match started. Round timer is live."});return}const g=await kt(r.matchId);if(x)return;const E=g.roundResults.filter(se=>se.roundNumber>$e.current).sort((se,me)=>se.roundNumber-me.roundNumber)[0];E?($e.current=E.roundNumber,te(E),xt(g)):(_(g),g.status==="completed"&&(h(!1),v(null),C(null)),g.status==="cancelled"&&r.status==="in_progress"&&(mt(!0),K(!1))),I("connected");return}if(m?.roomId){const g=await ys({roomId:m.roomId});if(x)return;if(v(g.room),g.match){const E=await re(g.match.matchId);if(x)return;_(E),v(g.room),h(!1),C(E.expiresAtMs||null),d("battle"),I("connected"),b({status:"queued",message:E.status==="ready"?"Opponent connected. Waiting for synchronized start...":"Private room match started."})}return}if(j){const g=await ia();if(x)return;if(g.sessionType==="match"&&g.match){const E=await re(g.match.matchId);if(x)return;_(E),v(g.room||null),h(!1),C(E.expiresAtMs||null),d("battle"),I("connected"),b({status:"queued",message:"Opponent found. Preparing synchronized start..."});return}if(g.sessionType==="room"&&g.room){h(!1),v(g.room),C(null),I("connected");return}I("connected")}}catch(g){if(!x){if(console.warn("Quiz Battle sync poll failed:",g),r?.mode==="bot"&&r.status==="ready"&&(Ce.current+=1,Ce.current>=3)){const E=g;h(!1),v(null),_(null),d("setup"),b({status:"error",message:E?.message||"Unable to start bot battle. Please try again."}),I("disconnected");return}I("reconnecting")}}};k();const T=window.setInterval(()=>{k()},3e3);return()=>{x=!0,window.clearInterval(T)}},[r?.matchId,r?.mode,r?.status,m?.roomId,m?.status,F,j]);const ue=i.useMemo(()=>r?.mode==="online"&&(r.status==="ready"||r.status==="in_progress")?{scope:"match",resourceId:r.matchId}:m&&(m.status==="waiting"||m.status==="ready")?{scope:"room",resourceId:m.roomId}:j&&n?.uid?{scope:"queue",resourceId:n.uid}:null,[r,m,j,n?.uid]);i.useEffect(()=>{if(!ue)return;let t=!1;const o=async()=>{try{await ks(ue.scope,ue.resourceId),t||I("connected")}catch(x){t||(console.warn("Quiz Battle heartbeat failed:",x),I("reconnecting"))}};o();const p=window.setInterval(()=>{o()},8e3);return()=>{t=!0,window.clearInterval(p),ps(ue.scope,ue.resourceId)}},[ue?.scope,ue?.resourceId]),i.useEffect(()=>{if(!r||r.status!=="in_progress"){K(!1),ve.current=null,oe.current=0;return}ve.current=null,oe.current=0;const t=r.roundDeadlineAtMs?Math.max(0,Math.ceil((r.roundDeadlineAtMs-Date.now())/1e3)):r.timePerQuestionSec;ze(t),X(null),K(!1)},[r?.matchId,r?.status,r?.currentRound,r?.timePerQuestionSec]),i.useEffect(()=>{F&&(!r||r.status!=="in_progress")&&ct(!1)},[r?.matchId,r?.status,F]),i.useEffect(()=>{const t=r?.lifecycle;if(!t?.eventType)return;const o=`${t.eventType}:${t.sequence}`;Ot.current!==o&&(Ot.current=o,t.eventType==="answer_locked"?Q("lock"):t.eventType==="round_result"&&Q("result"))},[r?.lifecycle?.eventType,r?.lifecycle?.sequence,Q]),i.useEffect(()=>{!r||r.status!=="completed"||Ht.current!==r.matchId&&(Ht.current=r.matchId,Q(r.outcome==="loss"?"loss":"win"),r.outcome==="win"&&pa(()=>import("./confetti.module-C94ZD2ww.js"),[]).then(t=>{t.default({particleCount:110,spread:78,origin:{y:.62},ticks:160})}).catch(()=>{}))},[r?.matchId,r?.status,r?.outcome,Q]),i.useEffect(()=>{if(!r||r.status!=="in_progress"||Z||G||F){ht.current=null;return}P<=3&&P>0&&ht.current!==P&&(ht.current=P,Q("tick"))},[r?.status,P,Z,G,F,Q]),i.useEffect(()=>{if(!r||r.status!=="in_progress"){bt.current=0;return}H>bt.current&&H>=2&&Q(H>=4?"multiplier":"streak"),bt.current=H},[r?.matchId,r?.status,H,Q]),i.useEffect(()=>{if(!r){Le.current=null,qe(null);return}const t=Le.current;if(!t||t.matchId!==r.matchId){Le.current={matchId:r.matchId,scoreFor:r.scoreFor,scoreAgainst:r.scoreAgainst},qe(null);return}if(r.scoreFor!==t.scoreFor||r.scoreAgainst!==t.scoreAgainst){const o=r.scoreFor>t.scoreFor?"player":"opponent";qe(o),Ie.current&&window.clearTimeout(Ie.current),Ie.current=window.setTimeout(()=>{qe(null)},850)}Le.current={matchId:r.matchId,scoreFor:r.scoreFor,scoreAgainst:r.scoreAgainst}},[r?.matchId,r?.scoreAgainst,r?.scoreFor]),i.useEffect(()=>()=>{Ie.current&&window.clearTimeout(Ie.current)},[]),i.useEffect(()=>{if(!B?.studentCorrect||ie===null||ie<=0){pt(null);return}const t=ie>0?"positive":ie<0?"negative":"neutral";pt({id:Date.now(),label:`${ie>=0?"+":""}${ie} Momentum`,tone:t});const o=window.setTimeout(()=>{pt(null)},1400);return()=>{window.clearTimeout(o)}},[ie,B]),i.useEffect(()=>{if(B&&Qe){B.studentCorrect?Q("win"):Q("loss");const t=window.setTimeout(()=>{_(Qe),te(null),X(null),K(!1),xt(null),Qe.status==="completed"&&(h(!1),v(null),ae(),$e.current=-1)},1500);return()=>window.clearTimeout(t)}},[B,Qe,Q,ae]);const Ve=i.useCallback(async t=>{if(!r||r.status!=="in_progress"||Z||F)return;Ae(!0);const o=window.setTimeout(()=>{Ae(!1),b({status:"error",message:"Submission took too long. Syncing latest match state now..."}),kt(r.matchId).then(p=>{_(p),p.status==="completed"&&(h(!1),v(null),C(null))}).catch(()=>{})},12e3);try{const p=r.roundDeadlineAtMs?Ge(r.timePerQuestionSec*1e3-Math.max(0,r.roundDeadlineAtMs-Date.now()),0,r.timePerQuestionSec*1e3):Math.max(0,(r.timePerQuestionSec-P)*1e3),x=await As({matchId:r.matchId,roundNumber:r.currentRound,selectedOptionIndex:t,responseMs:p});ve.current=null,oe.current=0,x.roundResult?($e.current=x.roundResult.roundNumber,te(x.roundResult),xt(x.match)):(_(x.match),te(null),x.match.mode==="online"&&x.match.status==="in_progress"?(K(!0),b({status:"queued",message:"Answer locked. Waiting for opponent to finish the round..."})):X(null)),x.match.status==="completed"&&(h(!1),v(null),C(null),ae(),b({status:"queued",message:x.completion?`Match finished (${x.completion.outcome.toUpperCase()}) +${x.completion.xpEarned} XP`:"Match finished. Results saved."}))}catch(p){const k=p?.message||"Unable to submit answer right now. Please try again.";if(t===null||k.includes("Round timer elapsed")||k.includes("Expected round")||k.includes("Match is not currently active"))try{const g=await kt(r.matchId),E=g.currentRound!==r.currentRound;if(_(g),X(null),K(!1),E||g.status==="completed"?(ve.current=null,oe.current=0):t===null&&(oe.current=Date.now()+3e3),g.status==="completed"){h(!1),v(null),C(null),ae(),b({status:"queued",message:"Match finished. Results synchronized."});return}b({status:"queued",message:"Round timed out. Synced to the latest battle state."});return}catch{}t===null&&(oe.current=Date.now()+3e3),b({status:"error",message:k})}finally{window.clearTimeout(o),Ae(!1)}},[r,F,ae,Z,P]);i.useEffect(()=>{if(!r||r.status!=="in_progress"||F||G||Z)return;const t=r.roundDeadlineAtMs?Math.max(0,Math.ceil((r.roundDeadlineAtMs-Date.now())/1e3)):P;if(r.roundDeadlineAtMs&&t!==P&&ze(t),we===null?t<=1:t<=0){if(ve.current===r.currentRound&&Date.now(){r.roundDeadlineAtMs?ze(Math.max(0,Math.ceil((r.roundDeadlineAtMs-Date.now())/1e3))):ze(x=>Math.max(0,x-1))},1e3);return()=>{window.clearTimeout(p)}},[r,G,F,Z,P,we,Ve]);const Gt=i.useCallback(async()=>{if(!(!r||r.mode!=="bot")){Ae(!0),b({status:"validating"});try{const t=await zs(r.matchId),o=await re(t.matchId);_(o),v(null),h(!1),C(null),te(null),X(null),K(!1),d("battle"),b({status:"queued",message:`Rematch ready (${t.botDifficulty}). Good luck!`})}catch(t){b({status:"error",message:t?.message||"Unable to start rematch right now."})}finally{Ae(!1)}}},[r]);if(s!=="student")return e.jsxs(e.Fragment,{children:[e.jsx("style",{children:St}),e.jsx("div",{className:"px-4 sm:px-6 xl:px-10 py-6 sm:py-8",children:e.jsx(pe,{className:u(fe,"max-w-2xl"),children:e.jsxs(he,{children:[e.jsx(be,{children:"Quiz Battle is student-only"}),e.jsx(ye,{className:"text-muted-foreground dark:text-[#aab3c7]",children:"Your account role does not have access to this module."})]})})})]});const Zt=t=>{f([]),b({status:"idle"}),ct(!1),h(!1),v(null),S(""),_(null),te(null),X(null),K(!1),C(null),w(o=>({...o,mode:t,queueType:t==="online"?o.queueType:"public_matchmaking"})),M(0),d("setup")},Kt=async()=>{b({status:"validating"});try{m?.roomId?await Ns({roomId:m.roomId}):await la(),h(!1),v(null),_(t=>!t||t.mode!=="online"?t:t.status==="ready"||t.status==="cancelled"?null:t),S(""),M(0),C(null),b({status:"queued",message:m?.roomId?"Private room cancelled.":"Left matchmaking queue."})}catch(t){b({status:"error",message:t?.message||"Unable to cancel this online session right now. Please try again."})}},$a=async()=>{b({status:"validating"});const t=bs(l);if(t.length>0){f(t),b({status:"error",message:"Fix the highlighted setup fields before starting."});return}f([]);try{if(l.mode==="online"){if(l.queueType==="private_room"){const k=W.trim().toUpperCase(),T=k?await js(k):await vs(l);if(h(!1),v(T.room),S(""),C(T.match?.expiresAtMs||null),T.match){const g=await re(T.match.matchId);_(g),te(null),X(null),K(!1),d("battle"),C(g.expiresAtMs||null),b({status:"queued",message:g.status==="ready"?`Room ${T.room.roomCode} linked. Waiting for synchronized start...`:"Private room match started."});return}_(null),C(null),b({status:"queued",message:k?"Joined private room. Waiting for opponent...":"Private room created. Share code:"});return}const x=await ws(l);if(x.status==="matched"&&x.matchId){const k=await re(x.matchId);h(!1),v(null),_(k),te(null),X(null),K(!1),d("battle"),C(k.expiresAtMs||null),b({status:"queued",message:"Opponent found. Preparing synchronized start..."});return}h(!0),v(null),_(null),C(x.expiresAtMs||Date.now()+Bs),M(0),b({status:"queued",message:"Joined matchmaking queue. Waiting for an opponent..."});return}const o=await _s(l),p=await re(o.matchId);h(!1),v(null),_(p),te(null),X(null),K(!1),ze(p.timePerQuestionSec),C(null),d("battle"),b({status:"queued",message:`Bot match ${o.matchId.slice(0,8)} live (${o.botDifficulty}).`}),ae().then(x=>{x&&(ot(x.stats),it(x.history))})}catch(o){h(!1),b({status:"error",message:o?.message||"Unable to start battle. Please try again."})}},U=t=>A.find(o=>o.field===t)?.message;ee?.winRate;const Jt=!!(l.mode==="online"&&m&&(m.status==="waiting"||m.status==="ready")&&(!r||r.status!=="completed")),Oa=!!(j||m&&(m.status==="waiting"||m.status==="ready")&&(!r||r.status==="ready"||r.status==="cancelled"));return r&&(r.status==="in_progress"||r.status==="completed")?e.jsxs(e.Fragment,{children:[e.jsx("style",{children:St}),e.jsxs("div",{className:"fixed inset-0 z-[100] bg-[#0B0F19] text-white flex flex-col overflow-hidden",children:[r.status==="completed"&&r.outcome==="loss"&&e.jsx(Ms,{viewportHeight:ut.height}),r.status==="completed"&&r.outcome==="draw"&&e.jsx(Fs,{viewportHeight:ut.height,viewportWidth:ut.width}),e.jsx("div",{className:"absolute inset-0 z-0 opacity-40",children:e.jsx(na,{children:e.jsx("div",{className:"h-full w-full"})})}),e.jsx(Ze,{children:Ta&&e.jsx(y.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"absolute inset-0 z-[120] bg-black/70 backdrop-blur-md flex flex-col items-center justify-center px-6",children:e.jsxs(y.div,{initial:{opacity:0,transform:"translateY(40px) scale(0.85)"},animate:{opacity:1,transform:"translateY(0) scale(1)"},transition:{type:"spring",damping:18,stiffness:250,delay:.1},className:"bg-[#1e2433] border border-white/10 rounded-[2rem] p-8 flex flex-col items-center gap-5 max-w-sm w-full shadow-[0_30px_80px_rgba(0,0,0,0.6)]",children:[e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"w-24 h-24 rounded-full bg-[#1a2030] border-4 border-rose-500/50 overflow-hidden flex items-end justify-center shadow-xl",children:r.mode==="bot"?e.jsx(Te,{className:"h-16 w-16 text-rose-400 mb-2",strokeWidth:1.5}):e.jsx(ke,{className:"h-14 w-14 text-slate-500 mb-2",strokeWidth:1.5})}),e.jsx(y.div,{initial:{opacity:0,transform:"scale(0.5) translateX(-10px)"},animate:{opacity:1,transform:"scale(1) translateX(0)"},transition:{delay:.4,type:"spring",stiffness:300},className:"absolute -top-2 left-full ml-2 bg-white text-slate-900 text-xs font-black px-3 py-1.5 rounded-2xl rounded-bl-none whitespace-nowrap shadow-lg",children:"I give up!"})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("h2",{className:"text-2xl font-black text-white mb-1",children:"Opponent Surrendered"}),e.jsxs("p",{className:"text-white/50 text-sm",children:[e.jsx("span",{className:"font-bold text-white/70",children:r.opponentName||"Your opponent"})," left the match. You win!"]})]}),e.jsxs("div",{className:"flex flex-col gap-3 w-full",children:[e.jsxs(z,{size:"lg",className:"w-full h-12 bg-emerald-500 hover:bg-emerald-400 text-white font-black rounded-xl",onClick:()=>{mt(!1),_(null),v(null),h(!1),b({status:"idle"}),d("hub"),ae()},children:[e.jsx(gt,{size:14,className:"inline mr-1"}),"Claim Victory"]}),e.jsx(z,{size:"lg",variant:"outline",className:"w-full h-12 border-white/20 text-white/70 hover:bg-white/10 rounded-xl",onClick:()=>{mt(!1),_(null),v(null),h(!1),b({status:"idle"}),d("hub")},children:"Back to Arena"})]})]})})}),F&&e.jsx("div",{className:"absolute inset-0 z-[110] bg-black/60 backdrop-blur-md flex items-center justify-center",children:e.jsxs(pe,{className:"w-full max-w-sm border-border/50 bg-[#181d27] shadow-[0_20px_50px_rgba(0,0,0,0.5)]",children:[e.jsxs(he,{className:"text-center",children:[e.jsx(be,{className:"text-3xl font-black text-white",children:"PAUSED"}),e.jsx(ye,{className:"text-base text-muted-foreground mt-2",children:r.mode==="online"?"Online match - timer continues in the background! Hurry!":"Bot match - round timer frozen."})]}),e.jsxs(Xe,{className:"flex flex-col gap-3",children:[e.jsx(z,{variant:"default",size:"lg",className:"w-full text-lg h-12",onClick:Wt,children:"Resume Match"}),e.jsx(z,{variant:"outline",size:"lg",className:"w-full text-lg h-12 border-rose-500/20 text-rose-500 hover:bg-rose-500/10",onClick:()=>{ct(!1),_(null),v(null),h(!1),b({status:"idle"}),d("setup")},children:"Leave Match"})]})]})}),e.jsxs("div",{className:"relative z-10 flex flex-col h-full w-full max-w-[1400px] mx-auto px-4 md:px-8 py-4",children:[e.jsx(Sa,{playerRoundStreak:H,playerVisualMultiplier:qa,liveXpEarned:La,activeMatch:r,subjects:ta,battleSoundEnabled:J,onToggleSound:()=>Dt(t=>!t),isFullscreen:Fa,onToggleFullscreen:()=>{typeof document>"u"||(document.fullscreenElement?document.exitFullscreen().catch(t=>{console.warn("Fullscreen mode unavailable or blocked by browser (exit):",t)}):document.documentElement.requestFullscreen().catch(t=>{console.warn("Fullscreen mode unavailable or blocked by browser (enter):",t)}))},isDesignPauseAvailable:ft,onTogglePause:Wt}),r.status==="in_progress"?e.jsx("div",{className:"shrink-0 w-full max-w-4xl mx-auto h-2 bg-white/10 rounded-full overflow-hidden mt-6 mb-4",children:e.jsx(y.div,{className:"h-full",animate:{width:`${Math.max(0,P/r.timePerQuestionSec*100)}%`,backgroundColor:P>Math.floor(r.timePerQuestionSec/2)?"#10b981":P>3?"#f59e0b":"#ef4444"},transition:{duration:1,ease:"linear"}})}):e.jsx("div",{className:"shrink-0 h-6 md:h-10 w-full"}),e.jsx("div",{className:"flex-1 flex flex-col justify-center items-center w-full min-h-0 relative",children:r.status==="completed"?e.jsx("div",{className:"fixed inset-0 z-[200] flex flex-col items-center justify-center bg-slate-900/50 backdrop-blur-md px-4",children:e.jsxs(y.div,{initial:{opacity:0,scale:.9,y:10},animate:{opacity:1,scale:1,y:0},className:"w-full max-w-sm sm:max-w-md bg-[#161a25]/90 border border-white/20 shadow-[0_30px_80px_rgba(0,0,0,0.8)] rounded-[1.5rem] p-6 text-center",children:[e.jsx("h2",{className:u("text-3xl font-black uppercase tracking-widest drop-shadow-md mb-2",r.outcome==="win"?"text-emerald-400":r.outcome==="loss"?"text-rose-400":"text-amber-400"),children:r.outcome==="win"?"VICTORY!":r.outcome==="loss"?"DEFEAT":"DRAW MATCH"}),e.jsxs("p",{className:"text-white/80 font-bold text-sm mb-4 uppercase tracking-widest",children:["Final Score: ",r.scoreFor," - ",r.scoreAgainst]}),e.jsxs("div",{className:"bg-black/50 rounded-xl p-4 mb-5 border border-white/5 flex flex-col gap-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-white/40 text-[10px] font-black uppercase tracking-widest text-left mb-2",children:"Battle Score"}),(()=>{const t=r.roundResults||[];let o=0,p=0,x=0;for(const k of t)if(k.studentCorrect){o++;const T=o>=2?Math.min(15,(o-1)*5):0;p+=10,x+=T}else o=0;return e.jsxs(e.Fragment,{children:[e.jsx(da,{value:p,label:"Correct Answers",delay:300,icon:e.jsx(Nt,{className:"h-3 w-3 text-emerald-400"})}),e.jsx(da,{value:x,label:"Streak Bonus",delay:900,icon:e.jsx(Je,{className:"h-3 w-3 text-amber-400"})}),e.jsxs(y.div,{initial:{opacity:0},animate:{opacity:1},transition:{delay:1.5,duration:.4},className:"flex items-center justify-between pt-1 mt-1 border-t border-white/5",children:[e.jsx("span",{className:"text-white/50 text-xs font-bold uppercase tracking-widest",children:"Total"}),e.jsxs("span",{className:"text-base font-black text-white/80",children:[p+x," pts"]})]})]})})()]}),e.jsx("div",{className:"w-full h-px bg-white/10"}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-white/40 text-[10px] font-black uppercase tracking-widest text-left mb-2",children:"Match Reward"}),e.jsxs(y.div,{initial:{opacity:0,scale:.9},animate:{opacity:1,scale:1},transition:{delay:2,duration:.5,type:"spring"},className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-white/70 text-sm font-bold",children:r.outcome==="win"?"Victory Reward":r.outcome==="draw"?"Draw Reward":"Participation Reward"}),e.jsxs("span",{className:"text-2xl font-black text-amber-400 drop-shadow-md",children:["+",r.xpEarned||(r.outcome==="win"?80:r.outcome==="draw"?55:35)," XP"]})]}),e.jsx("p",{className:"text-white/25 text-[9px] mt-1 text-right uppercase tracking-widest",children:"Credited to your profile"})]})]}),e.jsxs("div",{className:"flex flex-col gap-3 justify-center",children:[e.jsx(z,{size:"lg",onClick:()=>{_(null),v(null),h(!1),d("hub")},className:"w-full h-12 rounded-xl text-sm font-black bg-white/10 hover:bg-white/20 text-white border border-white/20",children:"BACK TO ARENA"}),r.mode==="bot"&&e.jsx(z,{size:"lg",onClick:()=>void Gt(),disabled:G,className:"w-full h-12 rounded-xl text-sm font-black bg-violet-600 hover:bg-violet-500 text-white border-b-2 border-violet-800 active:border-b-0 active:translate-y-[2px]",children:"REMATCH"})]})]})}):e.jsx(za,{activeMatch:r,roundSecondsLeft:P,lastRoundResult:B,selectedOptionIndex:we,roundLocked:Z,answerSubmitting:G,designPauseActive:F,onOptionSelect:t=>{B&&B.roundNumber===r.currentRound||G||Z||(ma()?.resume().catch(()=>{}),Q("lock"),X(t),Ve(t))},floatingMomentum:Da,lastRoundMomentumDelta:ie,studentProfile:n,quizBattleAvatar:jt})}),e.jsx(Aa,{studentProfile:n,activeMatch:r,scorePulseTarget:Pa,quizBattleAvatar:jt,opponentId:m?.participantIds?.find(t=>t!==a?.uid)||null})]})]})]}):e.jsxs(e.Fragment,{children:[e.jsx("style",{children:St}),e.jsx(na,{bgVideo:"/videos/warp_bg.mp4",className:"-mx-3 lg:-mx-4 -mt-3 lg:-mt-4 -mb-8 px-4 sm:px-6 xl:px-10 py-6 sm:py-8 min-h-[calc(100vh-3.5rem)] !w-auto overflow-hidden relative",children:e.jsx("div",{className:"h-full flex flex-col max-w-[1400px] mx-auto w-full",children:e.jsx(y.div,{initial:{opacity:0,y:16},animate:{opacity:1,y:0},transition:{duration:.24,ease:[.22,1,.36,1]},className:"space-y-3 lg:space-y-4",children:e.jsxs(Is,{value:c,onValueChange:t=>d(t),children:[e.jsx(Ne,{value:"hub",className:"mt-0 outline-none",children:e.jsx(y.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},exit:{opacity:0,y:-12},className:"space-y-5",children:e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-[1fr_300px] xl:grid-cols-[1fr_320px] gap-6 sm:gap-8 lg:gap-10",children:[e.jsxs("div",{className:"space-y-3 lg:space-y-4",children:[e.jsxs("div",{className:"relative select-none isolate bg-indigo-600 rounded-[2rem] shadow-[0_20px_45px_-15px_rgba(0,0,0,0.3)] shrink-0",children:[e.jsx("div",{className:"absolute inset-0 bg-black/60 pointer-events-none z-0 rounded-[2rem]"}),e.jsx("div",{className:"absolute inset-0 opacity-10 pointer-events-none rounded-[2rem] overflow-hidden repeating-stripe-bg"}),e.jsx("div",{className:"absolute top-0 right-0 w-[400px] h-[400px] bg-sky-500/20 blur-[100px] rounded-full pointer-events-none"}),e.jsxs("div",{className:"relative z-10 flex flex-col md:flex-row items-center justify-between p-6 lg:p-8 h-full min-h-[140px] lg:min-h-[160px]",children:[e.jsx("div",{className:"flex-1 space-y-3 w-full pr-0 md:pr-[240px] lg:pr-[280px]",children:e.jsxs("div",{children:[e.jsxs("h1",{className:"flex items-center gap-3 text-3xl sm:text-4xl lg:text-[46px] font-black tracking-tight text-white mb-2 sm:mb-4",children:[e.jsx(wt,{className:"h-8 w-8 sm:h-10 sm:w-10 lg:h-12 lg:w-12 text-[#d1abff]",strokeWidth:2.5}),"Quiz Battle"]}),e.jsx("p",{className:"text-base sm:text-lg lg:text-xl text-white mt-1.5 sm:mt-2 max-w-2xl leading-relaxed",children:"Timed student duels with synchronized rounds, instant feedback, and progression rewards."}),e.jsxs("p",{className:"text-xs lg:text-sm font-semibold uppercase tracking-[0.15em] text-[#8a7fbc] mt-3",children:["Connection: ",e.jsx("span",{className:Pt==="connected"?"text-emerald-400":"text-amber-400",children:Pt})]})]})}),e.jsx("div",{className:"hidden md:block absolute right-[-5px] lg:right-[-15px] top-0 lg:top-[5px] w-[200px] lg:w-[260px] shrink-0 pointer-events-none z-20",children:e.jsx("img",{src:jt,alt:"Mascot",className:"w-full h-full object-contain animate-mascot-float"})})]})]}),e.jsxs("div",{className:"pt-4 lg:pt-6",children:[e.jsxs("h2",{className:"flex items-center gap-2 pb-4 text-xl lg:text-2xl font-black tracking-wide uppercase text-white drop-shadow-[0_0_12px_rgba(255,255,255,0.4)]",children:[e.jsx(wt,{className:"h-6 w-6 lg:h-8 lg:w-8 text-amber-400 drop-shadow-[0_0_8px_rgba(251,191,36,0.9)]"})," BATTLE MODES"]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-2 gap-3 sm:gap-4 lg:gap-6 relative z-10 w-full mb-2",children:[e.jsxs(y.button,{type:"button",onClick:()=>Zt("online"),whileHover:{scale:1.025},whileTap:{scale:.98},transition:{type:"spring",stiffness:400,damping:15},className:"w-full h-[170px] sm:h-[245px] lg:h-[265px] bg-[#8A3FD3] rounded-[22px] border-none relative text-left shadow-[0_8px_30px_rgba(138,63,211,0.2)] hover:shadow-[0_12px_45px_rgba(138,63,211,0.4)] block flex-col group",children:[e.jsx("div",{className:"absolute inset-0 rounded-[22px] shadow-[inset_0_6px_15px_rgba(255,255,255,0.4)] pointer-events-none z-40"}),e.jsxs("div",{className:"absolute top-4 -left-4 z-20 w-[100px] h-[40px] opacity-100",children:[e.jsx("svg",{viewBox:"0 0 100 40",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:"w-full h-full block drop-shadow-md",children:e.jsx("path",{d:"M0 0 H94 Q100 0 100 6 V34 Q100 40 94 40 H0 L14 20 Z",fill:"#b91c1c"})}),e.jsx("div",{className:"absolute inset-0 flex items-center justify-end pr-3 font-black text-[13px] text-white tracking-[0.3px] opacity-100 font-nunito",children:"VS Player"})]}),e.jsxs("div",{className:"rounded-[22px] overflow-hidden relative isolate h-full flex flex-col justify-end",children:[e.jsx("div",{className:"absolute top-0 -left-[150%] w-[100%] h-full bg-gradient-to-r from-transparent via-white/40 to-transparent -skew-x-12 z-50 pointer-events-none transition-all duration-0 group-hover:duration-[800ms] ease-in-out group-hover:left-[150%]"}),e.jsxs("div",{className:"flex-1 w-full flex items-end justify-center relative pt-2 pointer-events-none",children:[e.jsx("div",{className:"absolute bottom-0 left-0 w-full h-[50px] sm:h-[95px] bg-[#662AA8] rounded-[50%_50%_0_0/100%_100%_0_0] scale-[1.05] z-0"}),e.jsxs("div",{className:"relative z-10 flex items-center justify-center mb-[2px] h-[80px] sm:h-[140px] w-full",children:[e.jsx("img",{src:"/avatar/avatar_icon.png",alt:"",className:"h-[120%] sm:h-[125%] object-contain relative z-20 origin-bottom right-[-10px] sm:right-[-15px] drop-shadow-[0_12px_15px_rgba(0,0,0,0.3)] animate-avatar-left"}),e.jsx("div",{className:"relative z-30 flex flex-col items-center mx-[-20px] scale-[1.1] animate-vs-pulse",children:e.jsxs("span",{className:"font-black italic text-[28px] sm:text-[40px] text-gray-200 tracking-tighter leading-none drop-shadow-[-2px_3px_0px_rgba(0,0,0,0.8)] webkit-text-stroke",children:[e.jsx("span",{className:"text-gray-300",children:"V"}),e.jsx("span",{className:"text-gray-400",children:"S"})]})}),e.jsx("img",{src:"/avatar/avatar_icon.png",alt:"",className:"h-[120%] sm:h-[125%] object-contain relative z-10 scale-x-[-1] origin-bottom left-[-20px] drop-shadow-[0_12px_15px_rgba(0,0,0,0.3)] animate-avatar-right"})]})]}),e.jsx("div",{className:"relative z-10 w-full px-3 sm:px-5 py-2 sm:py-4 text-center bg-[#662AA8]",children:e.jsx("p",{className:"text-[10px] sm:text-[13px] font-bold text-white leading-[1.4] font-nunito",children:"Queue or room-code match with another student."})})]})]}),e.jsxs(y.button,{type:"button",onClick:()=>Zt("bot"),whileHover:{scale:1.025},whileTap:{scale:.98},transition:{type:"spring",stiffness:400,damping:15},className:"w-full h-[170px] sm:h-[245px] lg:h-[265px] bg-[#1FA7E1] rounded-[22px] border-none relative text-left shadow-[0_8px_30px_rgba(31,167,225,0.2)] hover:shadow-[0_12px_45px_rgba(31,167,225,0.4)] block flex-col group",children:[e.jsx("div",{className:"absolute inset-0 rounded-[22px] shadow-[inset_0_6px_15px_rgba(255,255,255,0.4)] pointer-events-none z-40"}),e.jsxs("div",{className:"absolute top-4 -left-4 z-20 w-[100px] h-[40px] opacity-100",children:[e.jsx("svg",{viewBox:"0 0 100 40",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:"w-full h-full block drop-shadow-md",children:e.jsx("path",{d:"M0 0 H94 Q100 0 100 6 V34 Q100 40 94 40 H0 L14 20 Z",fill:"#b91c1c"})}),e.jsx("div",{className:"absolute inset-0 flex items-center justify-end pr-3 font-black text-[13px] text-white tracking-[0.3px] opacity-100 font-nunito",children:"VS Bot"})]}),e.jsxs("div",{className:"rounded-[22px] overflow-hidden relative isolate h-full flex flex-col justify-end",children:[e.jsx("div",{className:"absolute top-0 -left-[150%] w-[100%] h-full bg-gradient-to-r from-transparent via-white/40 to-transparent -skew-x-12 z-50 pointer-events-none transition-all duration-0 group-hover:duration-[800ms] ease-in-out group-hover:left-[150%]"}),e.jsxs("div",{className:"flex-1 w-full flex items-end justify-center relative pt-2 pointer-events-none",children:[e.jsx("div",{className:"absolute bottom-0 left-0 w-full h-[50px] sm:h-[95px] bg-[#127DA6] rounded-[50%_50%_0_0/100%_100%_0_0] scale-[1.05] z-0"}),e.jsxs("div",{className:"relative z-10 flex items-end justify-center mb-[2px] h-[85px] sm:h-[145px] w-full",children:[e.jsx("img",{src:"/avatar/avatar_icon.png",alt:"",className:"absolute opacity-40 blur-[1px] h-full object-contain origin-bottom -translate-x-[30px] sm:-translate-x-[60px] scale-[0.80] sm:scale-[0.85] animate-ghost-left"}),e.jsx("img",{src:"/avatar/avatar_icon.png",alt:"",className:"absolute opacity-40 blur-[1px] h-full object-contain origin-bottom translate-x-[30px] sm:translate-x-[60px] scale-[0.80] sm:scale-[0.85] animate-ghost-right"}),e.jsx("img",{src:"/avatar/avatar_icon.png",alt:"VS Bot",className:"relative opacity-100 scale-100 h-[105%] sm:h-[115%] object-contain drop-shadow-[0_15px_15px_rgba(0,0,0,0.3)] z-20 origin-bottom animate-main-avatar"})]})]}),e.jsx("div",{className:"relative z-10 w-full px-3 sm:px-5 py-2 sm:py-4 text-center bg-[#127DA6]",children:e.jsx("p",{className:"text-[10px] sm:text-[13px] font-bold text-white leading-[1.4] font-nunito",children:"Instant solo duel with selectable bot difficulty."})})]})]})]})]})]}),e.jsxs("div",{className:"space-y-3 lg:space-y-4 flex flex-col h-full justify-between",children:[e.jsx("div",{onClick:()=>d("leaderboard"),className:"relative w-full bg-[#3b3a82] dark:bg-[#2b2b5f] rounded-[24px] overflow-hidden flex flex-col shadow-[0_8px_30px_rgba(59,58,130,0.3)] cursor-pointer group mb-4",children:e.jsxs("div",{className:"relative w-full h-[190px] flex flex-col items-center justify-end pt-8",children:[e.jsxs("div",{className:"absolute top-[25px] w-full flex justify-center items-end px-2 z-10 gap-3",children:[e.jsx(vt,{strokeWidth:0,fill:"currentColor",className:"w-[32px] h-[32px] text-[#fcd34d] -rotate-[15deg] mb-2 drop-shadow-[0_0_15px_rgba(252,211,77,0.8)]"}),e.jsx("div",{className:"z-10 animate-star-float",children:e.jsx(vt,{strokeWidth:0,fill:"currentColor",className:"w-[48px] h-[48px] text-[#fcd34d] drop-shadow-[0_0_25px_rgba(252,211,77,0.9)]"})}),e.jsx(vt,{strokeWidth:0,fill:"currentColor",className:"w-[32px] h-[32px] text-[#fcd34d] rotate-[15deg] mb-2 drop-shadow-[0_0_15px_rgba(252,211,77,0.8)]"})]}),e.jsx("div",{className:"absolute bottom-[50px] left-1/2 -translate-x-1/2 w-[220px] h-[160px] bg-gradient-to-t from-white/20 to-transparent blur-[2px] z-0 pointer-events-none",style:{clipPath:"polygon(25% 0, 75% 0, 100% 100%, 0% 100%)"}}),e.jsxs("div",{className:"flex items-end justify-center z-10 relative px-4 bottom-[35px]",children:[e.jsxs("div",{className:"flex flex-col items-center relative z-10",children:[e.jsx("div",{className:"w-[75px] h-[14px] bg-[#D44747] rounded-t-[3px] border-x-[1.5px] border-white/90"}),e.jsxs("div",{className:"w-[65px] h-[45px] bg-[#FE6464] flex flex-col items-center justify-center gap-2 border-x-[1.5px] border-white/90",children:[e.jsx("div",{className:"w-8 h-1.5 bg-white/90 rounded-full mt-1"}),e.jsx("div",{className:"w-8 h-1.5 bg-white/90 rounded-full"})]})]}),e.jsxs("div",{className:"flex flex-col items-center relative z-20 -mx-1",children:[e.jsx("div",{className:"w-[90px] h-[16px] bg-[#F39029] rounded-t-[3px] border-x-[1.5px] border-white/90"}),e.jsxs("div",{className:"w-[80px] h-[65px] bg-[#FFA23A] flex flex-col items-center justify-center gap-2.5 border-x-[1.5px] border-white/90",children:[e.jsx("div",{className:"w-10 h-1.5 bg-white/90 rounded-full mt-1"}),e.jsx("div",{className:"w-10 h-1.5 bg-white/90 rounded-full"})]})]}),e.jsxs("div",{className:"flex flex-col items-center relative z-10",children:[e.jsx("div",{className:"w-[75px] h-[14px] bg-[#D44747] rounded-t-[3px] border-x-[1.5px] border-white/90"}),e.jsxs("div",{className:"w-[65px] h-[45px] bg-[#FE6464] flex flex-col items-center justify-center gap-2 border-x-[1.5px] border-white/90",children:[e.jsx("div",{className:"w-8 h-1.5 bg-white/90 rounded-full mt-1"}),e.jsx("div",{className:"w-8 h-1.5 bg-white/90 rounded-full"})]})]})]}),e.jsxs("div",{className:"absolute bottom-[2px] w-full flex justify-center z-30",children:[e.jsx("div",{className:"absolute top-[10px] w-full h-[35px] bg-[#8E1010] z-0"}),e.jsxs("div",{className:"relative w-[85%] h-[50px] bg-[#C62828] z-10 flex flex-col items-center justify-center rounded-[3px] shadow-[0_4px_10px_rgba(0,0,0,0.2)]",children:[e.jsx("h3",{className:"text-[18px] font-black text-white tracking-wide leading-none font-nunito mt-0.5",children:"Hall of Fame"}),e.jsx("span",{className:"text-[10px] font-bold text-white/90 tracking-wide mt-1",children:"View Page >"})]})]})]})}),e.jsxs("div",{className:"relative w-full bg-[#3b3a82] dark:bg-[#2b2b5f] rounded-[24px] overflow-hidden flex flex-col shadow-[0_8px_30px_rgba(59,58,130,0.3)]",children:[e.jsxs("div",{className:"flex flex-row items-center justify-between px-5 pt-5 pb-3 relative z-10",children:[e.jsx("h3",{className:"text-[20px] font-black text-white tracking-wide leading-none drop-shadow-md font-nunito",children:"My Stats"}),e.jsx(z,{className:"bg-[#7C51A8] hover:bg-[#6b4494] text-white font-bold text-[10px] tracking-widest uppercase rounded-full px-4 h-[28px] border border-white/10 shadow-md transition-transform active:scale-95",onClick:()=>d("stats"),children:"View Stats >"})]}),e.jsxs("div",{className:"relative z-10 w-full overflow-hidden pb-6",children:[e.jsx("div",{className:"absolute left-0 top-0 bottom-6 w-8 bg-gradient-to-r from-[#3b3a82] dark:from-[#2b2b5f] to-transparent z-20 pointer-events-none"}),e.jsx("div",{className:"absolute right-0 top-0 bottom-6 w-8 bg-gradient-to-l from-[#3b3a82] dark:from-[#2b2b5f] to-transparent z-20 pointer-events-none"}),e.jsx(y.div,{className:"flex w-max",animate:{x:["0%","-33.333333%"]},transition:{ease:"linear",duration:15,repeat:1/0},children:[1,2,3].map(t=>e.jsx("div",{className:"flex gap-3 pr-3",children:[{key:"totalXP",bg:"from-[#FF7B88] to-[#FF5C70]",shadow:"shadow-[0_4px_15px_rgba(255,92,112,0.4),inset_0_1px_1px_rgba(255,255,255,0.4)]",icon:Je,value:n?.currentXP||0,label:"Total XP"},{key:"winRate",bg:"from-[#B467FF] to-[#9D44FF]",shadow:"shadow-[0_4px_15px_rgba(157,68,255,0.4),inset_0_1px_1px_rgba(255,255,255,0.4)]",icon:gt,value:`${Math.round(ee?.winRate||0)} %`,label:"Win Rate"},{key:"matches",bg:"from-[#4DB9E9] to-[#2DA1D8]",shadow:"shadow-[0_4px_15px_rgba(45,161,216,0.4),inset_0_1px_1px_rgba(255,255,255,0.4)]",icon:zt,value:ee?.matchesPlayed||0,label:"Matches"},{key:"response",bg:"from-[#48DA94] to-[#2BBF7B]",shadow:"shadow-[0_4px_15px_rgba(43,191,123,0.4),inset_0_1px_1px_rgba(255,255,255,0.4)]",icon:ra,value:ee?.averageResponseMs?`${(ee.averageResponseMs/1e3).toFixed(0)}s`:"0s",label:"Response"}].map(o=>e.jsxs("div",{className:u("w-[90px] sm:w-[100px] shrink-0 aspect-square rounded-[16px] bg-gradient-to-br p-3 flex flex-col justify-between relative overflow-hidden group",o.bg,o.shadow),children:[e.jsx("div",{className:"absolute -bottom-6 -right-6 text-white/10 transition-transform duration-500 group-hover:scale-110",children:e.jsx(o.icon,{className:"w-20 h-20"})}),e.jsx("div",{className:"w-8 h-8 rounded-full border border-white/30 flex items-center justify-center relative z-10 shadow-[inset_0_1px_3px_rgba(255,255,255,0.5)]",children:e.jsx(o.icon,{className:"w-4 h-4 text-white"})}),e.jsxs("div",{className:"relative z-10 flex flex-col",children:[e.jsx("h4",{className:"text-[14px] sm:text-[16px] lg:text-[18px] font-black text-white leading-none tracking-tight drop-shadow-sm",children:o.value}),e.jsx("p",{className:"text-[8px] sm:text-[9px] font-extrabold text-white/80 uppercase tracking-widest mt-1 truncate",children:o.label})]})]},o.key))},t))})]})]}),e.jsxs(pe,{className:u(fe,"rounded-[18px] flex flex-col min-h-[200px]"),children:[e.jsxs(he,{className:"pb-0 pt-3 px-4 flex flex-row items-center justify-between",children:[e.jsxs(be,{className:"text-[14px] font-black flex items-center gap-2 text-[#2e2b5e] dark:text-[#f5f7fb]",children:[e.jsx(as,{className:"h-[16px] w-[16px] text-[#2e2b5e] dark:text-[#9e8fff]"})," Match History"]}),e.jsx(z,{variant:"link",size:"sm",className:"h-auto p-0 text-[12px] font-semibold text-muted-foreground dark:text-[#95a0bb] hover:text-primary transition-colors",onClick:()=>d("history"),children:"View All"})]}),e.jsxs(Xe,{className:"space-y-1.5 px-4 pt-1 pb-3 overflow-y-auto",children:[e.jsx("div",{className:"text-[11px] text-muted-foreground dark:text-[#8b95ad] mb-1.5 leading-relaxed",children:"Your recent student battles only."}),Qt?e.jsxs("div",{className:"space-y-2",children:[e.jsx(xe,{className:"h-10 w-full rounded-xl bg-muted dark:bg-[#2a3143]"}),e.jsx(xe,{className:"h-10 w-full rounded-xl bg-muted dark:bg-[#2a3143]"})]}):Oe.length===0?e.jsx("p",{className:"text-xs text-center text-muted-foreground dark:text-[#a8b2c9] py-2",children:"No battle history yet."}):Oe.slice(0,3).map(t=>{const o=t.outcome==="win",p=t.outcome==="loss",x=t.opponentName.split(" ").map(k=>k[0]).join("").substring(0,2).toUpperCase()||"OP";return e.jsxs("div",{className:"group relative overflow-hidden rounded-[14px] border border-muted-foreground/15 bg-white dark:bg-[#11151d] dark:border-[#2f3547] p-2 shadow-sm transition-all hover:scale-[1.01] hover:shadow-md",children:[e.jsx("div",{className:u("absolute inset-y-0 right-0 w-[55%] pointer-events-none opacity-[0.2] dark:opacity-[0.25] mix-blend-multiply dark:mix-blend-screen transition-all",o?"bg-gradient-to-l from-emerald-500 via-emerald-500/40 to-transparent":p?"bg-gradient-to-l from-rose-500 via-rose-500/40 to-transparent":"bg-gradient-to-l from-amber-400 via-amber-400/40 to-transparent")}),e.jsxs("div",{className:"flex items-center gap-2.5 relative z-10 w-full",children:[e.jsx("div",{className:u("w-9 h-9 rounded-full flex items-center justify-center font-black text-[12px] tracking-wide text-white flex-shrink-0 shadow-inner",o?"bg-[#34d399] dark:bg-[#15803d]":p?"bg-[#fb7185] dark:bg-[#be123c]":"bg-[#fbbf24] dark:bg-[#b45309]"),children:x}),e.jsxs("div",{className:"flex-grow min-w-0 flex flex-col justify-center",children:[e.jsxs("p",{className:"text-[13px] font-extrabold text-[#36326e] dark:text-[#e4e7f1] truncate leading-tight",children:["vs ",t.opponentName]}),e.jsxs("p",{className:"text-[10px] font-bold text-muted-foreground/60 dark:text-[#7f88a3] truncate flex items-center gap-1 mt-0.5",children:[t.subjectId," ",e.jsx("span",{className:"w-1 h-1 rounded-full bg-muted-foreground/30"})," ",t.difficulty||"Medium"," ",e.jsx("span",{className:"w-1 h-1 rounded-full bg-muted-foreground/30"})," ",t.rounds||"5"," rnds"]})]}),e.jsxs("div",{className:"text-right flex flex-col items-end justify-center pl-2 flex-shrink-0",children:[e.jsxs("p",{className:"tabular-nums text-[16px] leading-[1.1] font-black text-[#2e2b5e] dark:text-[#f5f7fb] tracking-tighter",children:[t.scoreFor,e.jsx("span",{className:"text-muted-foreground/40 mx-[1px]",children:"-"}),t.scoreAgainst]}),e.jsx("p",{className:u("text-[9px] font-black uppercase tracking-[0.1em]",o?"text-emerald-500 dark:text-emerald-400":p?"text-rose-500 dark:text-rose-400":"text-amber-500 dark:text-amber-400"),children:t.outcome})]})]})]},t.matchId)})]})]})]})]})},"hub")}),e.jsx(Ne,{value:"setup",className:"mt-0 outline-none",children:e.jsxs(y.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},exit:{opacity:0,y:-12},className:"w-full space-y-6",children:[e.jsxs(y.div,{className:u(fe,"relative overflow-hidden rounded-[24px] mb-6 shadow-lg",l.mode==="online"?"border-purple-500/20 shadow-[0_0_40px_-10px_rgba(138,63,211,0.2)]":"border-sky-500/20 shadow-[0_0_40px_-10px_rgba(31,167,225,0.2)]"),whileHover:{scale:1.01},transition:{type:"spring",stiffness:300,damping:20},children:[e.jsx("div",{className:u("pointer-events-none absolute inset-0 bg-gradient-to-r",l.mode==="online"?"from-purple-500/20 via-fuchsia-500/10 to-purple-600/5 dark:from-purple-500/20 dark:via-fuchsia-500/10 dark:to-purple-900/10":"from-sky-500/20 via-cyan-500/10 to-sky-600/5 dark:from-sky-500/20 dark:via-cyan-500/10 dark:to-sky-900/10")}),e.jsx("div",{className:u("pointer-events-none absolute -top-24 -right-24 h-64 w-64 rounded-full blur-3xl animate-orb-pulse",l.mode==="online"?"bg-purple-400/20":"bg-sky-400/20")}),e.jsx("div",{className:u("pointer-events-none absolute -bottom-12 -left-12 h-40 w-40 rounded-full blur-2xl animate-orb-pulse-delayed",l.mode==="online"?"bg-fuchsia-400/30":"bg-cyan-400/30")}),e.jsx("div",{className:"absolute inset-0 bg-[url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI0IiBoZWlnaHQ9IjQiPgo8cmVjdCB3aWR0aD0iNCIgaGVpZ2h0PSI0IiBmaWxsPSIjZmZmIiBmaWxsLW9wYWNpdHk9IjAiLz4KPHBhdGggZD0iTTAgMEgxdjFIMHoiIGZpbGw9IiM2MzY2ZjEiIGZpbGwtb3BhY2l0eT0iMC4wNSIvPgo8L3N2Zz4=')] opacity-30 dark:opacity-10 mix-blend-overlay"}),e.jsxs("div",{className:"relative p-6 sm:p-8 md:px-10 flex items-center gap-5 sm:gap-8 z-10",children:[e.jsx(z,{variant:"ghost",onClick:()=>d("hub"),className:u("h-12 w-12 sm:h-14 sm:w-14 p-0 rounded-full hover:scale-105 transition-all backdrop-blur-md shadow-lg shrink-0 flex items-center justify-center group",l.mode==="online"?"bg-white/50 dark:bg-black/40 hover:bg-white/80 dark:hover:bg-black/60 border border-purple-500/30":"bg-white/50 dark:bg-black/40 hover:bg-white/80 dark:hover:bg-black/60 border border-sky-500/30"),children:e.jsx(Ue,{className:u("h-6 w-6 sm:h-8 sm:w-8 rotate-180 transition-transform group-hover:-translate-x-0.5",l.mode==="online"?"text-purple-800 dark:text-purple-300":"text-sky-800 dark:text-sky-300")})}),e.jsxs("div",{children:[e.jsxs("h2",{className:u("flex items-center gap-3 text-3xl sm:text-4xl font-black tracking-tight text-transparent bg-clip-text bg-gradient-to-br drop-shadow-sm",l.mode==="online"?"from-purple-600 to-fuchsia-500 dark:from-purple-300 dark:to-fuchsia-200":"from-sky-600 to-cyan-500 dark:from-sky-300 dark:to-cyan-200"),children:[e.jsx("div",{className:u("p-2 rounded-2xl shadow-inner border animate-icon-bob",l.mode==="online"?"bg-purple-100 dark:bg-purple-900/50 border-purple-200 dark:border-purple-700/50":"bg-sky-100 dark:bg-sky-900/50 border-sky-200 dark:border-sky-700/50"),children:l.mode==="online"?e.jsx(ke,{className:"h-8 w-8 text-purple-600 dark:text-purple-400 drop-shadow-[0_0_8px_rgba(138,63,211,0.5)]"}):e.jsx(Te,{className:"h-8 w-8 text-sky-600 dark:text-sky-400 drop-shadow-[0_0_8px_rgba(31,167,225,0.5)]"})}),l.mode==="online"?"1v1 Online":"1v1 vs Bot"]}),e.jsx("p",{className:u("text-[10px] sm:text-[12px] font-black uppercase tracking-[0.2em] mt-1.5 drop-shadow-sm",l.mode==="online"?"text-purple-600/80 dark:text-purple-400/80":"text-sky-600/80 dark:text-sky-400/80"),children:l.mode==="online"?"CHALLENGE YOUR SCHOOLMATES AND PROVE YOUR SKILLS.":"CHALLENGE THE AI AND SHARPEN YOUR SKILLS."})]})]})]}),e.jsx("div",{className:"rounded-[24px] border border-white/40 bg-white/85 dark:border-white/10 dark:bg-black/80 backdrop-blur-xl p-5 sm:p-7 shadow-xl",children:e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6 lg:gap-10",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1.5 group",children:[e.jsx("label",{className:u("text-[11px] font-black uppercase tracking-[0.12em] ml-1",l.mode==="online"?"text-[#8A3FD3] dark:text-[#a35ceb]":"text-[#1FA7E1] dark:text-[#4bc1f2]"),children:"Category"}),e.jsxs(Me,{value:l.subjectId,onValueChange:t=>w(o=>({...o,subjectId:t})),children:[e.jsx(Fe,{className:u("rounded-xl h-11 border-white/20 bg-white text-slate-800 dark:bg-black/50 dark:text-white dark:border-white/10 transition-colors shadow-inner",l.mode==="online"?"hover:border-[#8A3FD3]/50":"hover:border-[#1FA7E1]/50",U("subjectId")&&"border-rose-400"),children:e.jsx(Ee,{placeholder:"Select category"})}),e.jsx(Re,{className:"rounded-xl backdrop-blur-xl bg-white/90 dark:bg-[#1a1f2e]/90",children:le.map(t=>e.jsx(de,{value:t.id,className:"rounded-lg",children:t.title},t.id))})]}),U("subjectId")&&e.jsx("p",{className:"text-xs text-destructive dark:text-rose-300 ml-1",children:U("subjectId")})]}),e.jsxs("div",{className:"space-y-1.5 group",children:[e.jsx("label",{className:u("text-[11px] font-black uppercase tracking-[0.12em] ml-1",l.mode==="online"?"text-[#8A3FD3] dark:text-[#a35ceb]":"text-[#1FA7E1] dark:text-[#4bc1f2]"),children:"Strand / Topic Group"}),e.jsxs(Me,{value:l.topicId,onValueChange:t=>w(o=>({...o,topicId:t})),children:[e.jsx(Fe,{className:u("rounded-xl h-11 border-white/20 bg-white text-slate-800 dark:bg-black/50 dark:text-white dark:border-white/10 transition-colors shadow-inner",l.mode==="online"?"hover:border-[#8A3FD3]/50":"hover:border-[#1FA7E1]/50",U("topicId")&&"border-rose-400"),children:e.jsx(Ee,{placeholder:"Select topic group"})}),e.jsx(Re,{className:"rounded-xl backdrop-blur-xl bg-white/90 dark:bg-[#1a1f2e]/90",children:Qa.map(t=>e.jsx(de,{value:t.value,className:"rounded-lg",children:t.label},t.value))})]}),U("topicId")&&e.jsx("p",{className:"text-xs text-destructive dark:text-rose-300 ml-1",children:U("topicId")})]}),e.jsxs("div",{className:"space-y-1.5 group",children:[e.jsx("label",{className:u("text-[11px] font-black uppercase tracking-[0.12em] ml-1",l.mode==="online"?"text-[#8A3FD3] dark:text-[#a35ceb]":"text-[#1FA7E1] dark:text-[#4bc1f2]"),children:l.mode==="online"?"Difficulty":"Bot Difficulty"}),e.jsxs(Me,{value:l.mode==="bot"?l.adaptiveBot?"adaptive":l.botDifficulty:l.difficulty,onValueChange:t=>w(o=>o.mode==="bot"?{...o,botDifficulty:t,adaptiveBot:t==="adaptive"}:{...o,difficulty:t}),children:[e.jsx(Fe,{className:u("rounded-xl h-11 border-white/20 bg-white text-slate-800 dark:bg-black/50 dark:text-white dark:border-white/10 transition-colors shadow-inner",l.mode==="online"?"hover:border-[#8A3FD3]/50":"hover:border-[#1FA7E1]/50"),children:e.jsx(Ee,{})}),e.jsxs(Re,{className:"rounded-xl backdrop-blur-xl bg-white/90 dark:bg-[#1a1f2e]/90",children:[e.jsx(de,{value:"easy",className:"rounded-lg",children:"Easy"}),e.jsx(de,{value:"medium",className:"rounded-lg",children:"Medium"}),e.jsx(de,{value:"hard",className:"rounded-lg",children:"Hard"}),l.mode==="bot"&&e.jsx(de,{value:"adaptive",className:"rounded-lg",children:"Adaptive"})]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-1.5 group",children:[e.jsx("label",{className:u("text-[10px] sm:text-[11px] font-black uppercase tracking-[0.12em] ml-1",l.mode==="online"?"text-[#8A3FD3] dark:text-[#a35ceb]":"text-[#1FA7E1] dark:text-[#4bc1f2]"),children:"Questions"}),e.jsxs(Me,{value:String(l.rounds),onValueChange:t=>w(o=>({...o,rounds:Number(t)})),children:[e.jsx(Fe,{className:u("rounded-xl h-11 border-white/20 bg-white text-slate-800 dark:bg-black/50 dark:text-white dark:border-white/10 transition-colors shadow-inner",l.mode==="online"?"hover:border-[#8A3FD3]/50":"hover:border-[#1FA7E1]/50",U("rounds")&&"border-rose-400"),children:e.jsx(Ee,{})}),e.jsx(Re,{className:"rounded-xl backdrop-blur-xl bg-white/90 dark:bg-[#1a1f2e]/90",children:[3,5,7,10,12,15].map(t=>e.jsx(de,{value:String(t),className:"rounded-lg",children:t},t))})]}),U("rounds")&&e.jsx("p",{className:"text-xs text-destructive dark:text-rose-300 ml-1",children:U("rounds")})]}),e.jsxs("div",{className:"space-y-1.5 group",children:[e.jsx("label",{className:u("text-[10px] sm:text-[11px] font-black uppercase tracking-[0.12em] ml-1 line-clamp-1",l.mode==="online"?"text-[#8A3FD3] dark:text-[#a35ceb]":"text-[#1FA7E1] dark:text-[#4bc1f2]"),children:"Time / Q"}),e.jsxs(Me,{value:String(l.timePerQuestionSec),onValueChange:t=>w(o=>({...o,timePerQuestionSec:Number(t)})),children:[e.jsx(Fe,{className:u("rounded-xl h-11 border-white/20 bg-white text-slate-800 dark:bg-black/50 dark:text-white dark:border-white/10 transition-colors shadow-inner",l.mode==="online"?"hover:border-[#8A3FD3]/50":"hover:border-[#1FA7E1]/50",U("timePerQuestionSec")&&"border-rose-400"),children:e.jsx(Ee,{})}),e.jsx(Re,{className:"rounded-xl backdrop-blur-xl bg-white/90 dark:bg-[#1a1f2e]/90",children:[15,20,30,45,60,90].map(t=>e.jsxs(de,{value:String(t),className:"rounded-lg",children:[t," sec"]},t))})]}),U("timePerQuestionSec")&&e.jsx("p",{className:"text-xs text-destructive dark:text-rose-300 ml-1",children:U("timePerQuestionSec")})]})]})]}),e.jsxs("div",{className:"flex flex-col justify-between space-y-6",children:[e.jsxs("div",{className:"space-y-5",children:[l.mode==="online"&&e.jsxs("div",{className:"space-y-3 rounded-2xl border border-[#8A3FD3]/20 bg-[#8A3FD3]/5 dark:border-[#8A3FD3]/20 p-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-[11px] font-black uppercase tracking-[0.12em] text-[#8A3FD3] dark:text-[#a35ceb] ml-1",children:"Online Match Type"}),e.jsx("div",{className:"grid grid-cols-2 gap-3",children:[{value:"public_matchmaking",label:"Public Queue"},{value:"private_room",label:"Private Room"}].map(t=>e.jsx(z,{type:"button",variant:l.queueType===t.value?"default":"outline",className:u("rounded-xl h-11 transition-all border-none font-bold text-xs",l.queueType===t.value?"bg-[#8A3FD3] hover:bg-[#7b35c0] text-white shadow-md shadow-[#8A3FD3]/30":"bg-white/50 hover:bg-white/80 dark:bg-black/30 dark:hover:bg-black/50 text-[#8A3FD3] dark:text-[#d3a8ff]"),onClick:()=>w(o=>({...o,queueType:t.value})),children:t.label},t.value))})]}),l.queueType==="private_room"&&e.jsxs(y.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},className:"pt-2 space-y-2",children:[e.jsx("label",{className:"text-[11px] font-black uppercase tracking-[0.12em] text-[#8A3FD3] dark:text-[#a35ceb] ml-1",children:"Room Code (optional)"}),e.jsx(es,{value:W,onChange:t=>S(t.target.value.toUpperCase().replace(/[^A-Z0-9]/g,"").slice(0,6)),placeholder:"Leave blank to create a room",className:"rounded-xl h-12 text-center text-lg uppercase font-bold tracking-[0.25em] border-[#8A3FD3]/30 bg-white/80 dark:bg-black/50 dark:border-[#8A3FD3]/20 focus-visible:ring-[#8A3FD3]/50 shadow-inner",maxLength:6}),e.jsx("div",{className:"rounded-xl border border-[#8A3FD3]/30 bg-[#8A3FD3]/10 px-3 py-3 text-[12px] font-semibold text-[#6620a2] leading-snug dark:border-[#8A3FD3]/30 dark:bg-[#8A3FD3]/10 dark:text-[#d3a8ff]",children:"Enter a room code to join an existing battle, or leave it blank to create a new room and share your code."})]})]}),e.jsxs("label",{className:u("flex flex-col sm:flex-row sm:items-center justify-between rounded-[16px] border bg-white/50 p-4 transition-colors cursor-pointer shadow-sm dark:bg-black/50 group",l.mode==="online"?"border-[#8A3FD3]/20 hover:bg-[#8A3FD3]/5 dark:border-[#8A3FD3]/20 dark:hover:bg-[#8A3FD3]/10":"border-[#1FA7E1]/20 hover:bg-[#1FA7E1]/5 dark:border-[#1FA7E1]/20 dark:hover:bg-[#1FA7E1]/10"),children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:u("h-11 w-11 rounded-full flex items-center justify-center group-hover:scale-110 transition-transform",l.mode==="online"?"bg-[#8A3FD3]/10 text-[#8A3FD3] dark:text-[#c48bfc]":"bg-[#1FA7E1]/10 text-[#1FA7E1] dark:text-[#7ad8ff]"),children:J?e.jsx(ga,{className:"h-5 w-5"}):e.jsx(wa,{className:"h-5 w-5 opacity-60"})}),e.jsxs("div",{className:"mb-3 sm:mb-0",children:[e.jsx("p",{className:"text-sm font-bold text-slate-800 dark:text-slate-200",children:"Battle Sounds"}),e.jsx("p",{className:"text-xs font-medium text-slate-500 dark:text-slate-400",children:"Cues for countdowns and results."})]})]}),e.jsx(ts,{checked:J,onCheckedChange:Dt})]}),e.jsxs(y.div,{initial:!1,animate:{opacity:J?1:.45,y:J?0:-2},className:u("rounded-[16px] border bg-white/40 p-4 shadow-sm dark:bg-black/40",l.mode==="online"?"border-[#8A3FD3]/20 dark:border-[#8A3FD3]/20":"border-[#1FA7E1]/20 dark:border-[#1FA7E1]/20"),children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[e.jsx("p",{className:"text-xs font-black uppercase tracking-[0.14em] text-slate-700 dark:text-slate-200",children:"SFX Volume"}),e.jsxs("p",{className:"text-xs font-bold text-slate-500 dark:text-slate-400",children:[Math.round(ce*100),"%"]})]}),e.jsx("input",{type:"range",min:0,max:100,step:1,value:Math.round(ce*100),disabled:!J,onChange:t=>{const o=Ge(Number(t.target.value)/100,0,1);Ca(o)},onMouseUp:()=>Q("tick"),onTouchEnd:()=>Q("tick"),className:"h-2 w-full cursor-pointer accent-violet-500 disabled:cursor-not-allowed disabled:opacity-50","aria-label":"Battle sound effects volume"})]})]}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{"aria-live":"polite",className:"min-h-[24px] text-sm font-medium",children:[N.status==="queued"&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:u("inline-flex items-center gap-1 text-[13px] font-bold px-3 py-1.5 rounded-lg",l.mode==="online"?"text-[#8A3FD3] bg-[#8A3FD3]/10":"text-[#1FA7E1] bg-[#1FA7E1]/10"),children:N.message}),l.mode==="online"&&l.queueType==="private_room"&&m?.roomCode&&e.jsxs(z,{type:"button",variant:"outline",className:u("h-8 rounded-full border-emerald-500/50 bg-emerald-50 px-4 text-xs font-black uppercase tracking-[0.16em] text-emerald-900 shadow-sm hover:bg-emerald-100 hover:scale-105 transition-all dark:border-emerald-500/40 dark:bg-emerald-500/10 dark:text-emerald-300 dark:hover:bg-emerald-500/20",R===m.roomCode&&"scale-105 bg-emerald-200 dark:bg-emerald-500/30"),onClick:()=>void Ut(m.roomCode),"aria-label":`Copy room code ${m.roomCode}`,children:[R===m.roomCode?e.jsx(Nt,{className:"h-4 w-4"}):e.jsx(sa,{className:"h-4 w-4"}),m.roomCode]}),(j||Jt)&&O>0&&e.jsxs("span",{className:u("inline-flex items-center gap-1.5 rounded-full px-3 py-1 text-xs font-bold animate-pulse",l.mode==="online"?"bg-[#8A3FD3]/10 text-[#8A3FD3]":"bg-[#1FA7E1]/10 text-[#1FA7E1]"),children:["Waiting ",ca(O)]})]}),N.status==="error"&&e.jsx("span",{className:"inline-flex items-center gap-1.5 text-[13px] font-bold text-rose-600 dark:text-rose-400 bg-rose-50 dark:bg-rose-500/10 px-3 py-1.5 rounded-lg border border-rose-200 dark:border-rose-500/20",children:N.message}),N.status==="validating"&&e.jsxs("span",{className:u("inline-flex items-center gap-2 font-bold px-3 py-1.5 rounded-lg",l.mode==="online"?"text-[#8A3FD3] bg-[#8A3FD3]/10":"text-[#1FA7E1] bg-[#1FA7E1]/10"),children:[e.jsx(Ke,{className:"h-4 w-4 animate-spin"})," Validating..."]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[Oa&&e.jsx(z,{type:"button",variant:"outline",onClick:Kt,disabled:N.status==="validating",className:"rounded-xl h-14 flex-1 sm:flex-none border-slate-300 hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800 font-bold px-6",children:m?"Cancel room":"Leave queue"}),e.jsx(z,{type:"button",onClick:$a,disabled:N.status==="validating"||j||Jt,className:u("rounded-xl h-14 flex-1 px-8 font-black uppercase tracking-wide text-sm shadow-xl hover:scale-[1.02] active:scale-95 transition-all text-white border-0",l.mode==="online"?"bg-[#8A3FD3] hover:bg-[#7b35c0] shadow-[#8A3FD3]/40":"bg-[#1FA7E1] hover:bg-[#1a95c9] shadow-[#1FA7E1]/40"),children:N.status==="validating"?e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx(Ke,{className:"h-5 w-5 animate-spin"})," Starting..."]}):l.mode==="online"&&l.queueType==="private_room"?W.trim()?"Join Room":"Create Room":"Start Battle"})]})]})]})]})})]},"setup")}),e.jsx(Ne,{value:"battle",className:"mt-0 outline-none",children:e.jsx(y.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},exit:{opacity:0,y:-12},className:"space-y-4",children:r?e.jsxs(pe,{className:u(fe,"rounded-[18px]"),children:[e.jsxs(he,{children:[e.jsxs(be,{className:"text-base flex items-center justify-between gap-3",children:[e.jsxs("span",{className:"inline-flex items-center gap-2",children:[r.mode==="bot"?e.jsx(Te,{className:"h-4 w-4 text-primary dark:text-[#9e8fff]"}):e.jsx(ke,{className:"h-4 w-4 text-primary dark:text-[#9e8fff]"}),"vs ",r.opponentName]}),e.jsxs("div",{className:"inline-flex items-center gap-2",children:[ft,e.jsxs("span",{className:"text-sm font-bold tabular-nums",children:[r.scoreFor," - ",r.scoreAgainst]})]})]}),e.jsx(ye,{className:"text-muted-foreground dark:text-[#b2bad0]",children:r.status==="completed"?`Completed in ${r.totalRounds} rounds.`:r.status==="ready"?r.mode==="online"?"Waiting for both players to confirm and start together.":"Finalizing practice bot session start.":`Round ${r.currentRound} of ${r.totalRounds}${F?" (paused for design)":""}`}),ua(r.lifecycle,n?.uid)&&e.jsx("p",{className:"text-xs font-medium text-muted-foreground dark:text-[#9aa4be]",children:ua(r.lifecycle,n?.uid)})]}),e.jsxs(Xe,{className:"space-y-4",children:[r.status==="ready"&&e.jsxs("div",{className:"rounded-xl border border-border bg-muted/30 p-4 dark:border-[#2f3547] dark:bg-[#11151d] flex flex-col gap-3",children:[e.jsx("p",{className:"text-sm font-semibold text-foreground dark:text-[#ecf0fb]",children:r.mode==="online"?"Waiting for both players to lock in start...":"Starting practice bot round..."}),r.mode==="online"&&r.expiresAtMs&&e.jsxs("p",{className:"text-xs font-medium text-muted-foreground dark:text-[#9aa4be]",children:["Public match expires in ",e.jsx("span",{className:"font-semibold tabular-nums",children:ca(O)})," if the synchronized start does not happen."]}),e.jsx(z,{variant:"outline",size:"sm",className:"w-full text-rose-500 border-rose-200 hover:bg-rose-50 dark:border-rose-900 dark:hover:bg-rose-900/30",onClick:()=>{_(null),v(null),h(!1),b({status:"idle"}),d("setup")},children:"Force Cancel"})]}),r.status==="in_progress"&&r.currentQuestion&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rounded-xl border border-border bg-muted/40 p-3 dark:border-[#2f3547] dark:bg-[#11151d]",children:[e.jsxs("p",{className:"text-xs text-muted-foreground dark:text-[#9aa4be]",children:["Time left: ",e.jsxs("span",{className:"font-semibold tabular-nums",children:[P,"s"]}),F?" (paused)":""]}),F&&e.jsx("p",{className:"mt-1 text-[11px] font-medium text-amber-700 dark:text-amber-300",children:"Design pause keeps this battle screen static while you edit UI."})]}),e.jsx("p",{className:"text-lg font-bold text-foreground dark:text-[#f5f7fb]",children:r.currentQuestion.prompt}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2",children:r.currentQuestion.choices.map((t,o)=>e.jsxs(z,{type:"button",variant:we===o?"default":"outline",onClick:()=>X(o),disabled:G||Z||F,className:u("h-auto min-h-[48px] justify-start text-left font-medium px-4 py-3 rounded-xl whitespace-normal",we===o?"ring-2 ring-primary ring-offset-2 dark:ring-offset-[#0B0F19]":""),children:[e.jsxs("span",{className:"mr-2 font-semibold",children:[String.fromCharCode(65+o),"."]}),t]},o))}),e.jsx("div",{className:"flex justify-end",children:e.jsx(z,{type:"button",onClick:()=>void Ve(we),disabled:G||Z||F,className:"rounded-xl",children:F?e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx(ls,{className:"h-4 w-4"})," Paused for design"]}):G?e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx(Ke,{className:"h-4 w-4 animate-spin"})," Submitting..."]}):Z?"Waiting for opponent...":"Lock Answer"})})]}),B&&e.jsxs("div",{className:"rounded-xl border border-border bg-muted/30 p-3 dark:border-[#2f3547] dark:bg-[#11151d]",children:[e.jsxs("p",{className:"text-sm font-semibold text-foreground dark:text-[#ecf0fb]",children:["Last round: ",B.studentCorrect?"Correct":"Incorrect"," · ",r.mode==="bot"?"Bot":"Opponent"," ",B.botCorrect?"Correct":"Incorrect"]}),e.jsxs("p",{className:"text-xs text-muted-foreground dark:text-[#9aa4be]",children:["Correct option: ",String.fromCharCode(65+B.correctOptionIndex)]})]}),r.status==="completed"&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:u("rounded-2xl border p-4",r.outcome==="win"?"border-emerald-300 bg-emerald-50 dark:border-emerald-400/40 dark:bg-emerald-900/20":r.outcome==="loss"?"border-rose-300 bg-rose-50 dark:border-rose-400/40 dark:bg-rose-900/20":"border-amber-300 bg-amber-50 dark:border-amber-400/40 dark:bg-amber-900/20"),children:[e.jsx("p",{className:"text-lg font-black tracking-wide text-foreground dark:text-[#ecf0fb]",children:r.outcome==="win"?"Victory!":r.outcome==="loss"?"Match Complete":"Draw Match"}),e.jsxs("p",{className:"mt-1 text-sm font-semibold text-foreground dark:text-[#ecf0fb]",children:["Final Score: ",r.scoreFor," - ",r.scoreAgainst]}),e.jsxs("p",{className:"text-xs text-muted-foreground dark:text-[#9aa4be]",children:["XP Earned: +",r.xpBreakdown?.totalXPAwarded??r.xpEarned??0,r.xpBreakdown&&e.jsxs("span",{className:"block",children:["Base: +",r.xpBreakdown.baseMatchXP," + Performance: +",r.xpBreakdown.performanceXP]})]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(z,{type:"button",variant:"outline",onClick:()=>{_(null),v(null),h(!1),d("setup")},className:"rounded-xl",children:"Start New Match"}),r.mode==="bot"&&e.jsx(z,{type:"button",onClick:()=>void Gt(),disabled:G,className:"rounded-xl",children:"Rematch"})]})]})]})]}):m?e.jsxs(pe,{className:u(fe,"rounded-[18px]"),children:[e.jsxs(he,{children:[e.jsxs(be,{className:"text-base flex items-center gap-2",children:[e.jsx(ke,{className:"h-4 w-4 text-primary dark:text-[#9e8fff]"}),"Private Room Lobby"]}),e.jsxs(ye,{className:"text-muted-foreground dark:text-[#b2bad0]",children:["Room ",m.roomCode," · ",m.participantCount,"/2 students connected."]})]}),e.jsx(Xe,{className:"space-y-3",children:e.jsxs("div",{className:"rounded-xl border border-border bg-muted/30 p-3 dark:border-[#2f3547] dark:bg-[#11151d]",children:[e.jsx("p",{className:"text-sm font-semibold text-foreground dark:text-[#ecf0fb]",children:m.status==="ready"?"Opponent connected. Syncing start...":"Waiting for another student to join this room."}),e.jsxs("p",{className:"text-xs text-muted-foreground dark:text-[#9aa4be]",children:["Share room code ",m.roomCode," with your classmate."]}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center justify-end gap-2",children:[(m.status==="waiting"||m.status==="ready")&&e.jsx(z,{type:"button",variant:"outline",className:"h-8 rounded-lg",onClick:Kt,disabled:N.status==="validating",children:"Cancel room"}),e.jsxs(z,{type:"button",variant:"outline",className:"h-8 rounded-lg",onClick:()=>void Ut(m.roomCode),children:[R===m.roomCode?e.jsx(Nt,{className:"h-4 w-4"}):e.jsx(sa,{className:"h-4 w-4"}),R===m.roomCode?"Copied":"Copy code"]})]})]})})]}):j?e.jsx(pe,{className:u(fe,"rounded-[18px]"),children:e.jsxs(he,{children:[e.jsxs(be,{className:"text-base flex items-center gap-2",children:[e.jsx(ke,{className:"h-4 w-4 text-primary dark:text-[#9e8fff]"}),"Public Matchmaking"]}),e.jsx(ye,{className:"text-muted-foreground dark:text-[#b2bad0]",children:"Searching for a student with the same setup..."})]})}):e.jsx(pe,{className:u(fe,"rounded-[18px]"),children:e.jsxs(he,{children:[e.jsxs(be,{className:"text-base flex items-center gap-2",children:[e.jsx(wt,{className:"h-4 w-4 text-primary dark:text-[#9e8fff]"}),"No active battle"]}),e.jsx(ye,{className:"text-muted-foreground dark:text-[#b2bad0]",children:"Start from Setup to create a bot match, private room, or public queue session."})]})})},"battle")}),e.jsx(Ne,{value:"history",className:"mt-0 outline-none",children:e.jsxs(y.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},exit:{opacity:0,y:-12},className:"space-y-4",children:[e.jsxs(y.div,{className:"relative overflow-hidden rounded-[24px] mb-6 bg-white/5 border border-white/10 shadow-2xl backdrop-blur-3xl",whileHover:{scale:1.01},transition:{type:"spring",stiffness:300,damping:20},children:[e.jsx("div",{className:"pointer-events-none absolute inset-0 bg-gradient-to-r from-emerald-500/10 via-teal-500/5 to-transparent"}),e.jsx("div",{className:"pointer-events-none absolute -top-24 -right-24 h-64 w-64 rounded-full bg-emerald-500/20 blur-3xl animate-orb-pulse"}),e.jsx("div",{className:"pointer-events-none absolute -bottom-12 -left-12 h-40 w-40 rounded-full bg-teal-500/20 blur-2xl animate-orb-pulse-delayed"}),e.jsx("div",{className:"relative z-10 p-6 sm:p-8 flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4",children:e.jsxs("div",{className:"flex items-center gap-5",children:[e.jsx(z,{variant:"ghost",onClick:()=>d("hub"),className:"h-12 w-12 p-0 rounded-full bg-white/10 hover:bg-white/20 hover:scale-105 transition-all backdrop-blur-md border border-white/10 shadow-[0_0_15px_rgba(16,185,129,0.15)] shrink-0",children:e.jsx(Ue,{className:"h-6 w-6 rotate-180 text-emerald-300"})}),e.jsxs("div",{children:[e.jsxs("h2",{className:"flex items-center gap-3 text-3xl sm:text-4xl font-black tracking-tight text-white drop-shadow-md",children:[e.jsx("div",{className:"bg-emerald-500/20 p-2 rounded-2xl shadow-inner border border-emerald-500/30",children:e.jsxs("div",{className:"relative w-8 h-8 flex items-center justify-center",children:[e.jsx("div",{className:"absolute w-5 h-6 bg-emerald-500/30 border border-emerald-400/50 rounded-sm -rotate-12 translate-x-1 shadow-sm"}),e.jsx("div",{className:"absolute w-5 h-6 bg-teal-400/50 border border-teal-300/60 rounded-sm rotate-6 -translate-x-1 shadow-md backdrop-blur-sm"}),e.jsxs("div",{className:"absolute w-5 h-6 bg-gradient-to-br from-emerald-400 to-teal-500 rounded-sm shadow-[0_0_15px_rgba(52,211,153,0.8)] z-10 flex flex-col items-center justify-center gap-[3px]",children:[e.jsx("div",{className:"w-2.5 h-[2px] bg-white/90 rounded-full"}),e.jsx("div",{className:"w-3 h-[2px] bg-white/90 rounded-full"}),e.jsx("div",{className:"w-2 h-[2px] bg-white/90 rounded-full"})]})]})}),"Matches History"]}),e.jsx("p",{className:"text-[12px] font-black text-white/60 mt-2 tracking-[0.1em] uppercase",children:"Review your past duels and track your progress."})]})]})})]}),e.jsxs("div",{className:"relative isolate w-full",children:[e.jsx("div",{className:"absolute top-[-10%] right-[-5%] w-[400px] h-[400px] bg-blue-500/20 rounded-full blur-[120px] pointer-events-none -z-10"}),e.jsx("div",{className:"absolute bottom-[-10%] left-[-5%] w-[350px] h-[350px] bg-teal-500/20 rounded-full blur-[120px] pointer-events-none -z-10"}),e.jsxs("div",{className:"rounded-[24px] bg-white/5 border border-white/10 shadow-2xl backdrop-blur-3xl p-6 sm:p-8",children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h3",{className:"text-xl font-black text-white tracking-wide leading-none drop-shadow-md",children:"Match History"}),e.jsx("p",{className:"text-sm font-semibold text-white/60 mt-2",children:"Your recent student battles only."})]}),e.jsx("div",{className:"flex gap-2 mb-6",children:[{value:"all",label:"All"},{value:"online",label:"Online"},{value:"bot",label:"Bot"}].map(t=>e.jsx(z,{type:"button",variant:"outline",onClick:()=>Ia(t.value),className:u("rounded-full h-9 px-5 border transition-all font-bold tracking-wide",ge===t.value?"bg-emerald-500/20 border-emerald-500/50 text-emerald-300 shadow-[0_0_15px_rgba(16,185,129,0.2)]":"bg-white/5 border-white/10 text-white/70 hover:bg-white/10 hover:text-white"),children:t.label},t.value))}),e.jsx("div",{className:"space-y-4",children:Qt?e.jsxs("div",{className:"space-y-3",children:[e.jsx(xe,{className:"h-[76px] w-full rounded-2xl bg-white/5 border border-white/10"}),e.jsx(xe,{className:"h-[76px] w-full rounded-2xl bg-white/5 border border-white/10"})]}):Oe.length===0?e.jsx("p",{className:"text-sm text-white/50 py-4",children:"No matches in this filter yet."}):Oe.map(t=>{const o=t.outcome==="win",p=t.outcome==="loss";return e.jsxs("div",{className:"relative overflow-hidden rounded-[20px] bg-white/5 border border-white/10 p-5 flex items-center justify-between shadow-lg transition-all hover:bg-white/10 hover:shadow-xl",children:[e.jsx("div",{className:u("absolute inset-y-0 left-0 w-3/4 pointer-events-none z-0",o?"bg-gradient-to-r from-emerald-500/50 via-emerald-500/10 to-transparent":p?"bg-gradient-to-r from-rose-500/50 via-rose-500/10 to-transparent":"bg-gradient-to-r from-amber-500/50 via-amber-500/10 to-transparent")}),e.jsxs("div",{className:"relative z-10 pl-2",children:[e.jsxs("p",{className:"text-base sm:text-lg font-black text-white drop-shadow-md",children:["vs ",t.opponentName]}),e.jsxs("p",{className:"text-[13px] font-bold text-white/60 tabular-nums mt-0.5",children:[t.scoreFor,"-",t.scoreAgainst," ",e.jsx("span",{className:"mx-1",children:"•"})," ",t.accuracy.toFixed(0),"% ",e.jsx("span",{className:"mx-1",children:"•"})," +",t.xpEarned," XP"]})]}),e.jsx("div",{className:"relative z-10",children:e.jsx("span",{className:u("text-sm font-black uppercase tracking-[0.1em] rounded-full px-4 py-1.5 border shadow-sm",o?"text-emerald-300 border-emerald-500/30 bg-emerald-500/10 shadow-[0_0_15px_rgba(16,185,129,0.15)]":p?"text-rose-300 border-rose-500/30 bg-rose-500/10 shadow-[0_0_15px_rgba(244,63,94,0.15)]":"text-amber-300 border-amber-500/30 bg-amber-500/10 shadow-[0_0_15px_rgba(245,158,11,0.15)]"),children:Rs(t.outcome)})})]},t.matchId)})})]})]})]},"history")}),e.jsx(Ne,{value:"stats",className:"mt-0 outline-none",children:e.jsxs(y.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},exit:{opacity:0,y:-12},className:"space-y-4",children:[e.jsxs(y.div,{className:"relative overflow-hidden rounded-[24px] mb-6 bg-white/5 border border-white/10 shadow-2xl backdrop-blur-3xl",whileHover:{scale:1.01},transition:{type:"spring",stiffness:300,damping:20},children:[e.jsx("div",{className:"pointer-events-none absolute inset-0 bg-gradient-to-r from-indigo-500/10 via-purple-500/5 to-transparent"}),e.jsx("div",{className:"pointer-events-none absolute -top-24 -right-24 h-64 w-64 rounded-full bg-indigo-500/20 blur-3xl animate-orb-pulse"}),e.jsx("div",{className:"pointer-events-none absolute -bottom-12 -left-12 h-40 w-40 rounded-full bg-purple-500/20 blur-2xl animate-orb-pulse-delayed"}),e.jsx("div",{className:"relative z-10 p-6 sm:p-8 flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4",children:e.jsxs("div",{className:"flex items-center gap-5",children:[e.jsx(z,{variant:"ghost",onClick:()=>d("hub"),className:"h-12 w-12 p-0 rounded-full bg-white/10 hover:bg-white/20 hover:scale-105 transition-all backdrop-blur-md border border-white/10 shadow-[0_0_15px_rgba(99,102,241,0.15)] shrink-0",children:e.jsx(Ue,{className:"h-6 w-6 rotate-180 text-indigo-300"})}),e.jsxs("div",{children:[e.jsxs("h2",{className:"flex items-center gap-3 text-3xl sm:text-4xl font-black tracking-tight text-white drop-shadow-md",children:[e.jsx("div",{className:"bg-indigo-500/20 p-2 rounded-2xl shadow-inner border border-indigo-500/30 animate-icon-bob",children:e.jsxs("div",{className:"relative w-8 h-8 flex items-end justify-center gap-1 pb-1",children:[e.jsx("div",{className:"w-1.5 h-3 bg-indigo-300 rounded-t-[2px] shadow-[0_0_8px_rgba(165,180,252,0.8)]"}),e.jsx("div",{className:"w-1.5 h-6 bg-purple-400 rounded-t-[2px] shadow-[0_0_12px_rgba(192,132,252,0.9)]"}),e.jsx("div",{className:"w-1.5 h-4 bg-indigo-400 rounded-t-[2px] shadow-[0_0_8px_rgba(129,140,248,0.8)]"})]})}),"My Statistics"]}),e.jsx("p",{className:"text-[12px] font-black text-white/60 mt-2 tracking-[0.1em] uppercase",children:"Analyzing your battlefield performance."})]})]})})]}),e.jsxs("div",{className:"relative isolate w-full",children:[e.jsx("div",{className:"absolute top-[0%] left-[10%] w-[350px] h-[350px] bg-indigo-500/30 rounded-full blur-[120px] pointer-events-none -z-10"}),e.jsx("div",{className:"absolute bottom-[0%] right-[10%] w-[300px] h-[300px] bg-purple-500/30 rounded-full blur-[120px] pointer-events-none -z-10"}),e.jsx("div",{className:"rounded-[24px] bg-white/5 border border-white/10 shadow-2xl backdrop-blur-3xl p-6 sm:p-8",children:e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-4 gap-4 sm:gap-6",children:[{label:"WINS",value:ee?.wins??0,icon:gt,textColor:"text-rose-400",gradient:"radial-gradient(circle at 10% 90%, rgba(244,63,94,0.35) 0%, transparent 70%)"},{label:"CURRENT STREAK",value:ee?.currentStreak??0,icon:Je,textColor:"text-purple-400",gradient:"radial-gradient(circle at 10% 90%, rgba(168,85,247,0.35) 0%, transparent 70%)"},{label:"AVG ACCURACY",value:`${(ee?.averageAccuracy||0).toFixed(1)}%`,icon:zt,textColor:"text-blue-400",gradient:"radial-gradient(circle at 10% 90%, rgba(59,130,246,0.35) 0%, transparent 70%)"},{label:"AVG RESPONSE",value:Es(ee?.averageResponseMs||0),icon:ra,textColor:"text-teal-400",gradient:"radial-gradient(circle at 10% 90%, rgba(20,184,166,0.35) 0%, transparent 70%)"}].map(t=>e.jsxs("div",{className:"relative overflow-hidden rounded-[20px] bg-white/5 border border-white/10 shadow-lg min-h-[160px] flex flex-col justify-between p-6 transition-transform hover:scale-105",children:[e.jsx("div",{className:"absolute inset-0 pointer-events-none z-0 mix-blend-screen",style:{background:t.gradient}}),e.jsxs("div",{className:"relative z-10",children:[e.jsx("p",{className:u("text-[11px] font-black uppercase tracking-[0.15em] mb-3",t.textColor),children:t.label}),e.jsx("p",{className:"text-4xl sm:text-5xl font-black text-white tabular-nums tracking-tighter drop-shadow-md",children:t.value})]}),e.jsx("div",{className:"relative z-10 mt-6 flex justify-start",children:e.jsx(t.icon,{className:u("h-5 w-5 drop-shadow-md",t.textColor)})})]},t.label))})})]})]},"stats")}),e.jsx(Ne,{value:"leaderboard",className:"mt-0 outline-none",children:e.jsxs(y.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},exit:{opacity:0,y:-12},className:"space-y-4",children:[e.jsxs(y.div,{className:"relative overflow-hidden rounded-[24px] mb-6 bg-white/5 border border-white/10 shadow-2xl backdrop-blur-3xl",whileHover:{scale:1.01},transition:{type:"spring",stiffness:300,damping:20},children:[e.jsx("div",{className:"pointer-events-none absolute inset-0 bg-gradient-to-r from-amber-500/10 via-orange-500/5 to-transparent"}),e.jsx("div",{className:"pointer-events-none absolute -top-24 -right-24 h-64 w-64 rounded-full bg-amber-500/20 blur-3xl animate-orb-pulse"}),e.jsx("div",{className:"pointer-events-none absolute -bottom-12 -left-12 h-40 w-40 rounded-full bg-orange-500/20 blur-2xl animate-orb-pulse-delayed"}),e.jsx("div",{className:"relative z-10 p-6 sm:p-8 flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4",children:e.jsxs("div",{className:"flex items-center gap-5",children:[e.jsx(z,{variant:"ghost",onClick:()=>d("hub"),className:"h-12 w-12 p-0 rounded-full bg-white/10 hover:bg-white/20 hover:scale-105 transition-all backdrop-blur-md border border-white/10 shadow-[0_0_15px_rgba(245,158,11,0.15)] shrink-0",children:e.jsx(Ue,{className:"h-6 w-6 rotate-180 text-amber-300"})}),e.jsxs("div",{children:[e.jsxs("h2",{className:"flex items-center gap-3 text-3xl sm:text-4xl font-black tracking-tight text-white drop-shadow-md",children:[e.jsx(y.div,{animate:{scale:[1,1.1,1]},transition:{duration:2,repeat:1/0,ease:"easeInOut"},className:"bg-amber-500/20 p-2 rounded-2xl shadow-inner border border-amber-500/30",children:e.jsx(ea,{className:"h-8 w-8 text-amber-400 drop-shadow-[0_0_12px_rgba(245,158,11,0.8)]"})}),"Hall of Fame"]}),e.jsx("p",{className:"text-[12px] font-black text-white/60 mt-2 tracking-[0.1em] uppercase",children:"The top-ranked minds across the globe."})]})]})})]}),e.jsxs("div",{className:"relative isolate w-full",children:[e.jsx("div",{className:"absolute top-[20%] left-[20%] w-[400px] h-[400px] bg-orange-500/20 rounded-full blur-[120px] pointer-events-none -z-10"}),e.jsx("div",{className:"absolute bottom-[-10%] right-[-10%] w-[350px] h-[350px] bg-pink-500/20 rounded-full blur-[120px] pointer-events-none -z-10"}),e.jsxs("div",{className:"rounded-[24px] bg-white/5 border border-white/10 shadow-2xl backdrop-blur-3xl p-6 sm:p-8",children:[e.jsxs("div",{className:"mb-8 flex items-start gap-3",children:[e.jsx(ea,{className:"h-8 w-8 text-amber-400 drop-shadow-[0_0_12px_rgba(245,158,11,0.6)] shrink-0"}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-xl font-black text-white tracking-wide leading-none drop-shadow-md",children:"Hall of Fame"}),e.jsx("p",{className:"text-sm font-semibold text-white/60 mt-2",children:"Student-only ranking using trusted backend aggregates."})]})]}),Ba?e.jsxs("div",{className:"space-y-4",children:[e.jsx(xe,{className:"h-[80px] w-full rounded-2xl bg-white/5 border border-white/10"}),e.jsx(xe,{className:"h-[80px] w-full rounded-2xl bg-white/5 border border-white/10"}),e.jsx(xe,{className:"h-[80px] w-full rounded-2xl bg-white/5 border border-white/10"})]}):Xt.length===0?e.jsx("p",{className:"text-sm text-white/50",children:"No leaderboard entries yet. Finish a battle to place on the board."}):e.jsx("div",{className:"space-y-6",children:e.jsx("div",{className:"space-y-3",children:Xt.map(t=>e.jsxs("div",{className:u("relative overflow-hidden rounded-[20px] p-5 flex items-center justify-between shadow-lg transition-all hover:scale-[1.01] group",t.isSelf?"bg-amber-500/10 border border-amber-500/40 shadow-[0_0_20px_rgba(245,158,11,0.15)]":"bg-white/5 border border-white/10 hover:bg-white/10"),children:[t.isSelf&&e.jsx("div",{className:"absolute inset-0 bg-gradient-to-r from-amber-500/20 to-transparent pointer-events-none -z-10"}),e.jsxs("div",{className:"relative z-10 flex flex-col gap-1.5",children:[e.jsxs("h4",{className:u("text-lg sm:text-xl font-black drop-shadow-md",t.isSelf?"text-amber-400":"text-white"),children:["#",t.rank," ",t.displayName,t.isSelf?" (You)":""]}),e.jsxs("p",{className:"text-[13px] font-bold text-white/60",children:["Win rate ",t.winRate.toFixed(1),"% ",e.jsx("span",{className:"mx-1",children:"•"})," Best streak ",t.bestStreak]})]}),e.jsx("div",{className:"relative z-10 text-xl sm:text-2xl font-black text-white tabular-nums drop-shadow-md",children:t.scoreLabel})]},t.userId))})})]})]})]},"leaderboard")})]})})})})]})};export{cr as default}; +`,Bs=300*1e3,Ms=({viewportHeight:a})=>e.jsx("div",{className:"absolute inset-0 pointer-events-none z-[50] overflow-hidden flex justify-between bg-slate-900/10",children:i.useMemo(()=>[...Array(40)].map((s,n)=>({id:n,left:`${Math.random()*100}%`,duration:.6+Math.random()*.4,delay:Math.random()*.4})),[a]).map(s=>e.jsx(y.div,{className:"absolute w-0.5 h-16 bg-blue-300/40 rounded-full e-left-top",style:{"--left":s.left,"--top":"-10%"},animate:{y:[0,a*1.2]},transition:{duration:s.duration,ease:"linear",delay:s.delay}},s.id))}),Fs=({viewportHeight:a,viewportWidth:s})=>{const n=i.useMemo(()=>[...Array(30)].map((c,d)=>({id:d,xShift:(Math.random()-.5)*s*.8,yShift:(Math.random()-.5)*a*.8,scale:Math.random()*1.5+.5,duration:2+Math.random()*1.5,delay:Math.random()*.35})),[a,s]);return e.jsx("div",{className:"absolute inset-0 pointer-events-none z-[50] overflow-hidden flex items-center justify-center",children:n.map(c=>e.jsx(y.div,{className:"absolute w-2 h-2 bg-amber-400 rounded-full shadow-[0_0_10px_rgba(251,191,36,0.8)] e-left-top",style:{"--left":"50%","--top":"50%"},animate:{y:[0,c.yShift],x:[0,c.xShift],scale:[0,c.scale,0],opacity:[0,1,0]},transition:{duration:c.duration,ease:"easeOut",delay:c.delay}},c.id))})},da=({value:a,label:s,delay:n=0,icon:c})=>{const[d,l]=i.useState(0);return i.useEffect(()=>{if(a<=0)return;const w=1e3,A=30,f=Math.abs(Math.floor(w/A));let N=0;const b=setTimeout(()=>{const j=setInterval(()=>{N+=Math.max(1,Math.floor(a/A)),N>=a?(l(a),clearInterval(j)):l(N)},f);return()=>clearInterval(j)},n);return()=>clearTimeout(b)},[a,n]),a<=0?null:e.jsxs(y.div,{initial:{opacity:0,transform:"translateX(-20px)"},animate:{opacity:1,transform:"translateX(0)"},transition:{delay:n/1e3,duration:.5},className:"flex items-center justify-between bg-white/5 border border-white/10 rounded-xl p-3",children:[e.jsxs("div",{className:"flex items-center gap-3 text-white/80 font-bold uppercase tracking-wider text-sm",children:[c,s]}),e.jsxs("div",{className:"text-2xl font-black text-amber-400 tabular-nums",children:["+",d]})]})},fe="border border-border bg-card text-card-foreground shadow-sm dark:border-[#2b3140] dark:bg-[#181d27] dark:text-[#f5f7fb] dark:shadow-[0_12px_24px_rgba(0,0,0,0.22)]",Es=a=>a<=0?"--":`${(a/1e3).toFixed(2)}s`,Rs=a=>a==="win"?"Win":a==="loss"?"Loss":"Draw",Ge=(a,s,n)=>Math.max(s,Math.min(n,a)),ca=a=>{const s=Math.floor(a/60),n=a%60;return`${s}:${String(n).padStart(2,"0")}`},Ts=a=>{const s=a.trim().split(/\s+/).filter(Boolean).slice(0,2);return s.length===0?"ST":s.map(n=>n[0]?.toUpperCase()||"").join("")},ua=(a,s)=>a?a.eventType==="round_started"?`Round ${a.roundNumber} started.`:a.eventType==="answer_locked"?a.lockedByStudentId&&s&&a.lockedByStudentId===s?`Round ${a.roundNumber}: your answer is locked.`:`Round ${a.roundNumber}: opponent answer locked.`:a.eventType==="round_result"?`Round ${a.roundNumber} resolved.`:"Match completed.":null;let At=null;const ma=()=>{if(typeof window>"u")return null;if(!At){const a=window.AudioContext||window.webkitAudioContext;a&&(At=new a)}return At},ur=()=>{const{userProfile:a,userRole:s}=Wa(),n=a,[c,d]=i.useState("hub"),[l,w]=i.useState(hs),[A,f]=i.useState([]),[N,b]=i.useState({status:"idle"}),[j,h]=i.useState(!1),[m,v]=i.useState(null),[W,S]=i.useState(""),[R,Y]=i.useState(null),[O,M]=i.useState(0),[D,C]=i.useState(null),[J,Dt]=i.useState(()=>typeof window>"u"?!0:window.localStorage.getItem("quiz_battle_sound_enabled")!=="0"),[ce,Ca]=i.useState(()=>{if(typeof window>"u")return .7;const t=Number(window.localStorage.getItem("quiz_battle_sound_volume")||"0.7");return Number.isFinite(t)?Ge(t,0,1):.7}),[Pt,I]=i.useState("connected"),[ge,Ia]=i.useState("all"),[Qt,nt]=i.useState(!0),[ee,ot]=i.useState(null),[lt,it]=i.useState([]),[Ba,qt]=i.useState(!1),[Lt,Ma]=i.useState([]),[dt,Ds]=i.useState("full"),[$t,Ps]=i.useState(!0),[r,_]=i.useState(null),[we,X]=i.useState(null),[G,Ae]=i.useState(!1),[P,ze]=i.useState(0),[Z,K]=i.useState(!1),[F,ct]=i.useState(!1),[Fa,Ea]=i.useState(!1),[ut,Ra]=i.useState(_t),[B,te]=i.useState(null),[Ta,mt]=i.useState(!1),[Qe,xt]=i.useState(null),[Da,pt]=i.useState(null),[Pa,qe]=i.useState(null),Ot=i.useRef(""),ht=i.useRef(null),ve=i.useRef(null),oe=i.useRef(0),Ht=i.useRef(""),Ce=i.useRef(0),bt=i.useRef(0),Le=i.useRef(null),Ie=i.useRef(null),$e=i.useRef(-1),ft=!1,le=i.useMemo(()=>{const t=Ya(n?.grade);return ta.filter(o=>t.includes(o.id))},[n?.grade]),Qa=i.useMemo(()=>(le.find(o=>o.id===l.subjectId)?.modules||[]).map(o=>({value:o.id,label:o.title})),[le,l.subjectId]),H=i.useMemo(()=>{const t=r?.roundResults||[];let o=0;return t.forEach(p=>{o=p.studentCorrect?o+1:0}),o},[r?.roundResults]),qa=i.useMemo(()=>{const t=Math.max(0,H-1)*.12;return Number((1+Math.min(.72,t)).toFixed(2))},[H]),La=i.useMemo(()=>{if(!r)return 0;if(r.status==="completed")return r.xpEarned||0;const t=r.roundResults||[];let o=0,p=0;for(const x of t)if(x.studentCorrect){o++;const k=o>=2?Math.min(25,(o-1)*5):0;p+=10+k}else o=0;return p},[r?.status,r?.xpEarned,r?.roundResults]),Vt=i.useMemo(()=>{const t=r?.roundResults||[];let o=0;return t.forEach(p=>{o=p.botCorrect?o+1:0}),o},[r?.roundResults]);i.useMemo(()=>{const t=Math.max(0,Vt-1)*.1;return Number((1+Math.min(.5,t)).toFixed(2))},[Vt]),i.useMemo(()=>H>=5?{label:"Inferno",badgeClass:"text-amber-300 border-amber-300/50 bg-amber-500/20 shadow-[0_0_18px_rgba(251,191,36,0.35)]"}:H>=3?{label:"Heating Up",badgeClass:"text-orange-300 border-orange-300/50 bg-orange-500/15 shadow-[0_0_16px_rgba(249,115,22,0.3)]"}:B?.studentCorrect?{label:"Steady",badgeClass:"text-emerald-300 border-emerald-300/40 bg-emerald-500/15 shadow-[0_0_14px_rgba(16,185,129,0.25)]"}:{label:"Rebuild",badgeClass:"text-slate-300 border-slate-300/30 bg-slate-500/15 shadow-[0_0_14px_rgba(148,163,184,0.2)]"},[B?.studentCorrect,H]);const ie=i.useMemo(()=>{if(!B)return null;const t=B.studentCorrect?12:-8,o=B.studentCorrect&&!B.botCorrect?6:0,p=B.studentCorrect?Math.max(0,(H-1)*2):0;return t+o+p},[B,H]),Q=i.useCallback(t=>{if(!(!J||ce<=0||typeof window>"u"))try{const o=ma();if(!o)return;o.state==="suspended"&&o.resume().catch(()=>{});const x={tick:{notes:[740],duration:.06,type:"triangle",volume:.03},lock:{notes:[520],duration:.08,type:"square",volume:.04},result:{notes:[660,720],duration:.08,type:"sine",volume:.04},win:{notes:[920,1040,1180],duration:.12,type:"triangle",volume:.05},loss:{notes:[260,220],duration:.14,type:"sawtooth",volume:.045},streak:{notes:[780,920],duration:.09,type:"triangle",volume:.045},multiplier:{notes:[660,880,1120],duration:.08,type:"triangle",volume:.05}}[t],k=o.currentTime,T=.07,g=Ge(x.volume*ce,.004,.08);x.notes.forEach((E,se)=>{const me=o.createOscillator(),Be=o.createGain(),je=k+se*T;me.type=x.type,me.frequency.setValueAtTime(E,je),Be.gain.setValueAtTime(1e-4,je),Be.gain.exponentialRampToValueAtTime(g,je+.012),Be.gain.exponentialRampToValueAtTime(1e-4,je+x.duration),me.connect(Be),Be.connect(o.destination),me.start(je),me.stop(je+x.duration+.02)})}catch(o){console.warn("Battle tone playback skipped or blocked:",o)}},[J,ce]),Ut=i.useCallback(async t=>{if(!(!t||typeof window>"u"))try{await window.navigator.clipboard.writeText(t),Y(t),window.setTimeout(()=>{Y(o=>o===t?null:o)},1600)}catch{b({status:"error",message:"Unable to copy room code automatically. Please copy it manually."})}},[]),Wt=i.useCallback(()=>{},[ft]),Yt=i.useCallback(t=>{h(!1),v(null),_(null),M(0),C(null),b({status:"error",message:t}),d("setup")},[]),ae=i.useCallback(async()=>{if(!n?.uid)return null;const[t,o]=await Promise.all([fs(n.uid),gs(n.uid,{mode:ge,limitCount:8})]);return{stats:t,history:o}},[ge,n?.uid]);i.useEffect(()=>{if(le.length===0)return;const o=le.some(k=>k.id===l.subjectId)?l.subjectId:le[0].id,p=le.find(k=>k.id===o),x=p?.modules?.[0]?.id||"";w(k=>{const T=p?.modules?.some(g=>g.id===k.topicId)?k.topicId:x;return k.subjectId===o&&k.topicId===T?k:{...k,subjectId:o,topicId:T}})},[le,l.subjectId]),i.useEffect(()=>{if(!n?.uid){ot(null),it([]),nt(!1);return}let t=!0;return nt(!0),(async()=>{const p=await ae();t&&(p&&(ot(p.stats),it(p.history)),nt(!1))})(),()=>{t=!1}},[ae,n?.uid]);const Oe=i.useMemo(()=>ge==="all"?lt:lt.filter(t=>t.mode===ge),[lt,ge]),Xt=i.useMemo(()=>Lt.map((t,o)=>{const p=t.rank||o+1,x=t.userId===n?.uid,k=`Student-${t.userId.slice(-4).toUpperCase()}`,T=dt==="full"?t.displayName:dt==="initials"?Ts(t.displayName):k,g=Math.floor(t.leaderboardScore/25)*25,E=$t||x?`${t.leaderboardScore} pts`:`${g}-${g+24} pts`;return{...t,rank:p,isSelf:x,displayName:T,scoreLabel:E}}),[Lt,dt,$t,n?.uid]);i.useEffect(()=>{if(c!=="leaderboard"&&c!=="hub")return;let t=!0;return qt(!0),(async()=>{const p=await Cs(20);t&&(Ma(p),qt(!1))})(),()=>{t=!1}},[c]);const He=i.useCallback(async()=>{if(n?.uid)try{const t=await ia();if(t.sessionType==="match"&&t.match){let o=t.match;if(t.match.mode==="bot"&&t.match.status==="ready")try{o=await re(t.match.matchId),Ce.current=0}catch(p){const x=p;h(!1),v(null),_(null),d("setup"),I(typeof window<"u"&&window.navigator.onLine?"connected":"disconnected"),b({status:"error",message:x?.message||"Unable to resume bot battle. Please start a new match."});return}h(!1),v(t.room||null),_(o),C(t.queue?.expiresAtMs||o.expiresAtMs||null),d("battle"),I("connected");return}if(t.sessionType==="room"&&t.room){h(!1),v(t.room),_(o=>o?.mode==="bot"?o:null),C(null),I("connected");return}if(t.sessionType==="queue"){h(!0),v(null),_(o=>o?.mode==="bot"?o:null),C(t.queue?.expiresAtMs||null),I("connected");return}h(!1),v(null),_(o=>o?.mode==="bot"?o:null),C(null),I("connected")}catch(t){console.warn("Quiz Battle session resume failed:",t),I("reconnecting")}},[n?.uid]);i.useEffect(()=>{n?.uid&&He()},[n?.uid,He]),i.useEffect(()=>{typeof window>"u"||window.localStorage.setItem("quiz_battle_sound_enabled",J?"1":"0")},[J]),i.useEffect(()=>{typeof window>"u"||window.localStorage.setItem("quiz_battle_sound_volume",ce.toFixed(2))},[ce]),i.useEffect(()=>{if(typeof window>"u")return;const t=()=>{const o=window.innerWidth,p=window.innerHeight;Ra({width:Number.isFinite(o)&&o>0?o:_t.width,height:Number.isFinite(p)&&p>0?p:_t.height})};return t(),window.addEventListener("resize",t),()=>{window.removeEventListener("resize",t)}},[]),i.useEffect(()=>{if(typeof document>"u")return;const t=()=>{Ea(!!document.fullscreenElement)};return t(),document.addEventListener("fullscreenchange",t),()=>{document.removeEventListener("fullscreenchange",t)}},[]),i.useEffect(()=>{const t=D!==null;if(!(j||m&&(m.status==="waiting"||m.status==="ready")||t)){M(0);return}const o=()=>{if(!D){M(x=>x+1);return}M(Math.max(0,Math.ceil((D-Date.now())/1e3)))};o();const p=window.setInterval(o,1e3);return()=>{window.clearInterval(p)}},[j,m?.status,m?.roomId,D]),i.useEffect(()=>{if(!D)return;const t=window.setInterval(()=>{D-Date.now()<=0&&(window.clearInterval(t),(async()=>{try{(j||!m)&&await la()}catch{}finally{Yt("Public matchmaking timed out after 5 minutes. Please start again.")}})())},1e3);return()=>{window.clearInterval(t)}},[m,Yt,j,D]),i.useEffect(()=>{if(typeof window>"u")return;I(window.navigator.onLine?"connected":"disconnected");const t=()=>{I("reconnecting"),He()},o=()=>{I("disconnected")};return window.addEventListener("online",t),window.addEventListener("offline",o),()=>{window.removeEventListener("online",t),window.removeEventListener("offline",o)}},[He]),i.useEffect(()=>{const t=r?.mode==="online"&&(r.status==="ready"||r.status==="in_progress"),o=r?.mode==="bot"&&r.status==="ready",p=!!(m&&(m.status==="waiting"||m.status==="ready"));if(o||(Ce.current=0),!j&&!p&&!t&&!o||F)return;let x=!1;const k=async()=>{try{if(r?.mode==="bot"&&r.status==="ready"){const g=await re(r.matchId);if(x)return;_(g),I("connected"),C(g.expiresAtMs||null),Ce.current=0,g.status==="in_progress"&&b({status:"queued",message:"Practice bot match started."});return}if(r?.mode==="online"){if(r.status==="ready"){const se=await re(r.matchId);if(x)return;_(se),I("connected"),C(se.expiresAtMs||null),se.status==="in_progress"&&b({status:"queued",message:"Match started. Round timer is live."});return}const g=await kt(r.matchId);if(x)return;const E=g.roundResults.filter(se=>se.roundNumber>$e.current).sort((se,me)=>se.roundNumber-me.roundNumber)[0];E?($e.current=E.roundNumber,te(E),xt(g)):(_(g),g.status==="completed"&&(h(!1),v(null),C(null)),g.status==="cancelled"&&r.status==="in_progress"&&(mt(!0),K(!1))),I("connected");return}if(m?.roomId){const g=await ys({roomId:m.roomId});if(x)return;if(v(g.room),g.match){const E=await re(g.match.matchId);if(x)return;_(E),v(g.room),h(!1),C(E.expiresAtMs||null),d("battle"),I("connected"),b({status:"queued",message:E.status==="ready"?"Opponent connected. Waiting for synchronized start...":"Private room match started."})}return}if(j){const g=await ia();if(x)return;if(g.sessionType==="match"&&g.match){const E=await re(g.match.matchId);if(x)return;_(E),v(g.room||null),h(!1),C(E.expiresAtMs||null),d("battle"),I("connected"),b({status:"queued",message:"Opponent found. Preparing synchronized start..."});return}if(g.sessionType==="room"&&g.room){h(!1),v(g.room),C(null),I("connected");return}I("connected")}}catch(g){if(!x){if(console.warn("Quiz Battle sync poll failed:",g),r?.mode==="bot"&&r.status==="ready"&&(Ce.current+=1,Ce.current>=3)){const E=g;h(!1),v(null),_(null),d("setup"),b({status:"error",message:E?.message||"Unable to start bot battle. Please try again."}),I("disconnected");return}I("reconnecting")}}};k();const T=window.setInterval(()=>{k()},3e3);return()=>{x=!0,window.clearInterval(T)}},[r?.matchId,r?.mode,r?.status,m?.roomId,m?.status,F,j]);const ue=i.useMemo(()=>r?.mode==="online"&&(r.status==="ready"||r.status==="in_progress")?{scope:"match",resourceId:r.matchId}:m&&(m.status==="waiting"||m.status==="ready")?{scope:"room",resourceId:m.roomId}:j&&n?.uid?{scope:"queue",resourceId:n.uid}:null,[r,m,j,n?.uid]);i.useEffect(()=>{if(!ue)return;let t=!1;const o=async()=>{try{await ks(ue.scope,ue.resourceId),t||I("connected")}catch(x){t||(console.warn("Quiz Battle heartbeat failed:",x),I("reconnecting"))}};o();const p=window.setInterval(()=>{o()},8e3);return()=>{t=!0,window.clearInterval(p),ps(ue.scope,ue.resourceId)}},[ue?.scope,ue?.resourceId]),i.useEffect(()=>{if(!r||r.status!=="in_progress"){K(!1),ve.current=null,oe.current=0;return}ve.current=null,oe.current=0;const t=r.roundDeadlineAtMs?Math.max(0,Math.ceil((r.roundDeadlineAtMs-Date.now())/1e3)):r.timePerQuestionSec;ze(t),X(null),K(!1)},[r?.matchId,r?.status,r?.currentRound,r?.timePerQuestionSec]),i.useEffect(()=>{F&&(!r||r.status!=="in_progress")&&ct(!1)},[r?.matchId,r?.status,F]),i.useEffect(()=>{const t=r?.lifecycle;if(!t?.eventType)return;const o=`${t.eventType}:${t.sequence}`;Ot.current!==o&&(Ot.current=o,t.eventType==="answer_locked"?Q("lock"):t.eventType==="round_result"&&Q("result"))},[r?.lifecycle?.eventType,r?.lifecycle?.sequence,Q]),i.useEffect(()=>{!r||r.status!=="completed"||Ht.current!==r.matchId&&(Ht.current=r.matchId,Q(r.outcome==="loss"?"loss":"win"),r.outcome==="win"&&pa(()=>import("./confetti.module-C94ZD2ww.js"),[]).then(t=>{t.default({particleCount:110,spread:78,origin:{y:.62},ticks:160})}).catch(()=>{}))},[r?.matchId,r?.status,r?.outcome,Q]),i.useEffect(()=>{if(!r||r.status!=="in_progress"||Z||G||F){ht.current=null;return}P<=3&&P>0&&ht.current!==P&&(ht.current=P,Q("tick"))},[r?.status,P,Z,G,F,Q]),i.useEffect(()=>{if(!r||r.status!=="in_progress"){bt.current=0;return}H>bt.current&&H>=2&&Q(H>=4?"multiplier":"streak"),bt.current=H},[r?.matchId,r?.status,H,Q]),i.useEffect(()=>{if(!r){Le.current=null,qe(null);return}const t=Le.current;if(!t||t.matchId!==r.matchId){Le.current={matchId:r.matchId,scoreFor:r.scoreFor,scoreAgainst:r.scoreAgainst},qe(null);return}if(r.scoreFor!==t.scoreFor||r.scoreAgainst!==t.scoreAgainst){const o=r.scoreFor>t.scoreFor?"player":"opponent";qe(o),Ie.current&&window.clearTimeout(Ie.current),Ie.current=window.setTimeout(()=>{qe(null)},850)}Le.current={matchId:r.matchId,scoreFor:r.scoreFor,scoreAgainst:r.scoreAgainst}},[r?.matchId,r?.scoreAgainst,r?.scoreFor]),i.useEffect(()=>()=>{Ie.current&&window.clearTimeout(Ie.current)},[]),i.useEffect(()=>{if(!B?.studentCorrect||ie===null||ie<=0){pt(null);return}const t=ie>0?"positive":ie<0?"negative":"neutral";pt({id:Date.now(),label:`${ie>=0?"+":""}${ie} Momentum`,tone:t});const o=window.setTimeout(()=>{pt(null)},1400);return()=>{window.clearTimeout(o)}},[ie,B]),i.useEffect(()=>{if(B&&Qe){B.studentCorrect?Q("win"):Q("loss");const t=window.setTimeout(()=>{_(Qe),te(null),X(null),K(!1),xt(null),Qe.status==="completed"&&(h(!1),v(null),ae(),$e.current=-1)},1500);return()=>window.clearTimeout(t)}},[B,Qe,Q,ae]);const Ve=i.useCallback(async t=>{if(!r||r.status!=="in_progress"||Z||F)return;Ae(!0);const o=window.setTimeout(()=>{Ae(!1),b({status:"error",message:"Submission took too long. Syncing latest match state now..."}),kt(r.matchId).then(p=>{_(p),p.status==="completed"&&(h(!1),v(null),C(null))}).catch(()=>{})},12e3);try{const p=r.roundDeadlineAtMs?Ge(r.timePerQuestionSec*1e3-Math.max(0,r.roundDeadlineAtMs-Date.now()),0,r.timePerQuestionSec*1e3):Math.max(0,(r.timePerQuestionSec-P)*1e3),x=await As({matchId:r.matchId,roundNumber:r.currentRound,selectedOptionIndex:t,responseMs:p});ve.current=null,oe.current=0,x.roundResult?($e.current=x.roundResult.roundNumber,te(x.roundResult),xt(x.match)):(_(x.match),te(null),x.match.mode==="online"&&x.match.status==="in_progress"?(K(!0),b({status:"queued",message:"Answer locked. Waiting for opponent to finish the round..."})):X(null)),x.match.status==="completed"&&(h(!1),v(null),C(null),ae(),b({status:"queued",message:x.completion?`Match finished (${x.completion.outcome.toUpperCase()}) +${x.completion.xpEarned} XP`:"Match finished. Results saved."}))}catch(p){const k=p?.message||"Unable to submit answer right now. Please try again.";if(t===null||k.includes("Round timer elapsed")||k.includes("Expected round")||k.includes("Match is not currently active"))try{const g=await kt(r.matchId),E=g.currentRound!==r.currentRound;if(_(g),X(null),K(!1),E||g.status==="completed"?(ve.current=null,oe.current=0):t===null&&(oe.current=Date.now()+3e3),g.status==="completed"){h(!1),v(null),C(null),ae(),b({status:"queued",message:"Match finished. Results synchronized."});return}b({status:"queued",message:"Round timed out. Synced to the latest battle state."});return}catch{}t===null&&(oe.current=Date.now()+3e3),b({status:"error",message:k})}finally{window.clearTimeout(o),Ae(!1)}},[r,F,ae,Z,P]);i.useEffect(()=>{if(!r||r.status!=="in_progress"||F||G||Z)return;const t=r.roundDeadlineAtMs?Math.max(0,Math.ceil((r.roundDeadlineAtMs-Date.now())/1e3)):P;if(r.roundDeadlineAtMs&&t!==P&&ze(t),we===null?t<=1:t<=0){if(ve.current===r.currentRound&&Date.now(){r.roundDeadlineAtMs?ze(Math.max(0,Math.ceil((r.roundDeadlineAtMs-Date.now())/1e3))):ze(x=>Math.max(0,x-1))},1e3);return()=>{window.clearTimeout(p)}},[r,G,F,Z,P,we,Ve]);const Gt=i.useCallback(async()=>{if(!(!r||r.mode!=="bot")){Ae(!0),b({status:"validating"});try{const t=await zs(r.matchId),o=await re(t.matchId);_(o),v(null),h(!1),C(null),te(null),X(null),K(!1),d("battle"),b({status:"queued",message:`Rematch ready (${t.botDifficulty}). Good luck!`})}catch(t){b({status:"error",message:t?.message||"Unable to start rematch right now."})}finally{Ae(!1)}}},[r]);if(s!=="student")return e.jsxs(e.Fragment,{children:[e.jsx("style",{children:St}),e.jsx("div",{className:"px-4 sm:px-6 xl:px-10 py-6 sm:py-8",children:e.jsx(pe,{className:u(fe,"max-w-2xl"),children:e.jsxs(he,{children:[e.jsx(be,{children:"Quiz Battle is student-only"}),e.jsx(ye,{className:"text-muted-foreground dark:text-[#aab3c7]",children:"Your account role does not have access to this module."})]})})})]});const Zt=t=>{f([]),b({status:"idle"}),ct(!1),h(!1),v(null),S(""),_(null),te(null),X(null),K(!1),C(null),w(o=>({...o,mode:t,queueType:t==="online"?o.queueType:"public_matchmaking"})),M(0),d("setup")},Kt=async()=>{b({status:"validating"});try{m?.roomId?await Ns({roomId:m.roomId}):await la(),h(!1),v(null),_(t=>!t||t.mode!=="online"?t:t.status==="ready"||t.status==="cancelled"?null:t),S(""),M(0),C(null),b({status:"queued",message:m?.roomId?"Private room cancelled.":"Left matchmaking queue."})}catch(t){b({status:"error",message:t?.message||"Unable to cancel this online session right now. Please try again."})}},$a=async()=>{b({status:"validating"});const t=bs(l);if(t.length>0){f(t),b({status:"error",message:"Fix the highlighted setup fields before starting."});return}f([]);try{if(l.mode==="online"){if(l.queueType==="private_room"){const k=W.trim().toUpperCase(),T=k?await js(k):await vs(l);if(h(!1),v(T.room),S(""),C(T.match?.expiresAtMs||null),T.match){const g=await re(T.match.matchId);_(g),te(null),X(null),K(!1),d("battle"),C(g.expiresAtMs||null),b({status:"queued",message:g.status==="ready"?`Room ${T.room.roomCode} linked. Waiting for synchronized start...`:"Private room match started."});return}_(null),C(null),b({status:"queued",message:k?"Joined private room. Waiting for opponent...":"Private room created. Share code:"});return}const x=await ws(l);if(x.status==="matched"&&x.matchId){const k=await re(x.matchId);h(!1),v(null),_(k),te(null),X(null),K(!1),d("battle"),C(k.expiresAtMs||null),b({status:"queued",message:"Opponent found. Preparing synchronized start..."});return}h(!0),v(null),_(null),C(x.expiresAtMs||Date.now()+Bs),M(0),b({status:"queued",message:"Joined matchmaking queue. Waiting for an opponent..."});return}const o=await _s(l),p=await re(o.matchId);h(!1),v(null),_(p),te(null),X(null),K(!1),ze(p.timePerQuestionSec),C(null),d("battle"),b({status:"queued",message:`Bot match ${o.matchId.slice(0,8)} live (${o.botDifficulty}).`}),ae().then(x=>{x&&(ot(x.stats),it(x.history))})}catch(o){h(!1),b({status:"error",message:o?.message||"Unable to start battle. Please try again."})}},U=t=>A.find(o=>o.field===t)?.message;ee?.winRate;const Jt=!!(l.mode==="online"&&m&&(m.status==="waiting"||m.status==="ready")&&(!r||r.status!=="completed")),Oa=!!(j||m&&(m.status==="waiting"||m.status==="ready")&&(!r||r.status==="ready"||r.status==="cancelled"));return r&&(r.status==="in_progress"||r.status==="completed")?e.jsxs(e.Fragment,{children:[e.jsx("style",{children:St}),e.jsxs("div",{className:"fixed inset-0 z-[100] bg-[#0B0F19] text-white flex flex-col overflow-hidden",children:[r.status==="completed"&&r.outcome==="loss"&&e.jsx(Ms,{viewportHeight:ut.height}),r.status==="completed"&&r.outcome==="draw"&&e.jsx(Fs,{viewportHeight:ut.height,viewportWidth:ut.width}),e.jsx("div",{className:"absolute inset-0 z-0 opacity-40",children:e.jsx(na,{children:e.jsx("div",{className:"h-full w-full"})})}),e.jsx(Ze,{children:Ta&&e.jsx(y.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"absolute inset-0 z-[120] bg-black/70 backdrop-blur-md flex flex-col items-center justify-center px-6",children:e.jsxs(y.div,{initial:{opacity:0,transform:"translateY(40px) scale(0.85)"},animate:{opacity:1,transform:"translateY(0) scale(1)"},transition:{type:"spring",damping:18,stiffness:250,delay:.1},className:"bg-[#1e2433] border border-white/10 rounded-[2rem] p-8 flex flex-col items-center gap-5 max-w-sm w-full shadow-[0_30px_80px_rgba(0,0,0,0.6)]",children:[e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"w-24 h-24 rounded-full bg-[#1a2030] border-4 border-rose-500/50 overflow-hidden flex items-end justify-center shadow-xl",children:r.mode==="bot"?e.jsx(Te,{className:"h-16 w-16 text-rose-400 mb-2",strokeWidth:1.5}):e.jsx(ke,{className:"h-14 w-14 text-slate-500 mb-2",strokeWidth:1.5})}),e.jsx(y.div,{initial:{opacity:0,transform:"scale(0.5) translateX(-10px)"},animate:{opacity:1,transform:"scale(1) translateX(0)"},transition:{delay:.4,type:"spring",stiffness:300},className:"absolute -top-2 left-full ml-2 bg-white text-slate-900 text-xs font-black px-3 py-1.5 rounded-2xl rounded-bl-none whitespace-nowrap shadow-lg",children:"I give up!"})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("h2",{className:"text-2xl font-black text-white mb-1",children:"Opponent Surrendered"}),e.jsxs("p",{className:"text-white/50 text-sm",children:[e.jsx("span",{className:"font-bold text-white/70",children:r.opponentName||"Your opponent"})," left the match. You win!"]})]}),e.jsxs("div",{className:"flex flex-col gap-3 w-full",children:[e.jsxs(z,{size:"lg",className:"w-full h-12 bg-emerald-500 hover:bg-emerald-400 text-white font-black rounded-xl",onClick:()=>{mt(!1),_(null),v(null),h(!1),b({status:"idle"}),d("hub"),ae()},children:[e.jsx(gt,{size:14,className:"inline mr-1"}),"Claim Victory"]}),e.jsx(z,{size:"lg",variant:"outline",className:"w-full h-12 border-white/20 text-white/70 hover:bg-white/10 rounded-xl",onClick:()=>{mt(!1),_(null),v(null),h(!1),b({status:"idle"}),d("hub")},children:"Back to Arena"})]})]})})}),F&&e.jsx("div",{className:"absolute inset-0 z-[110] bg-black/60 backdrop-blur-md flex items-center justify-center",children:e.jsxs(pe,{className:"w-full max-w-sm border-border/50 bg-[#181d27] shadow-[0_20px_50px_rgba(0,0,0,0.5)]",children:[e.jsxs(he,{className:"text-center",children:[e.jsx(be,{className:"text-3xl font-black text-white",children:"PAUSED"}),e.jsx(ye,{className:"text-base text-muted-foreground mt-2",children:r.mode==="online"?"Online match - timer continues in the background! Hurry!":"Bot match - round timer frozen."})]}),e.jsxs(Xe,{className:"flex flex-col gap-3",children:[e.jsx(z,{variant:"default",size:"lg",className:"w-full text-lg h-12",onClick:Wt,children:"Resume Match"}),e.jsx(z,{variant:"outline",size:"lg",className:"w-full text-lg h-12 border-rose-500/20 text-rose-500 hover:bg-rose-500/10",onClick:()=>{ct(!1),_(null),v(null),h(!1),b({status:"idle"}),d("setup")},children:"Leave Match"})]})]})}),e.jsxs("div",{className:"relative z-10 flex flex-col h-full w-full max-w-[1400px] mx-auto px-4 md:px-8 py-4",children:[e.jsx(Sa,{playerRoundStreak:H,playerVisualMultiplier:qa,liveXpEarned:La,activeMatch:r,subjects:ta,battleSoundEnabled:J,onToggleSound:()=>Dt(t=>!t),isFullscreen:Fa,onToggleFullscreen:()=>{typeof document>"u"||(document.fullscreenElement?document.exitFullscreen().catch(t=>{console.warn("Fullscreen mode unavailable or blocked by browser (exit):",t)}):document.documentElement.requestFullscreen().catch(t=>{console.warn("Fullscreen mode unavailable or blocked by browser (enter):",t)}))},isDesignPauseAvailable:ft,onTogglePause:Wt}),r.status==="in_progress"?e.jsx("div",{className:"shrink-0 w-full max-w-4xl mx-auto h-2 bg-white/10 rounded-full overflow-hidden mt-6 mb-4",children:e.jsx(y.div,{className:"h-full",animate:{width:`${Math.max(0,P/r.timePerQuestionSec*100)}%`,backgroundColor:P>Math.floor(r.timePerQuestionSec/2)?"#10b981":P>3?"#f59e0b":"#ef4444"},transition:{duration:1,ease:"linear"}})}):e.jsx("div",{className:"shrink-0 h-6 md:h-10 w-full"}),e.jsx("div",{className:"flex-1 flex flex-col justify-center items-center w-full min-h-0 relative",children:r.status==="completed"?e.jsx("div",{className:"fixed inset-0 z-[200] flex flex-col items-center justify-center bg-slate-900/50 backdrop-blur-md px-4",children:e.jsxs(y.div,{initial:{opacity:0,scale:.9,y:10},animate:{opacity:1,scale:1,y:0},className:"w-full max-w-sm sm:max-w-md bg-[#161a25]/90 border border-white/20 shadow-[0_30px_80px_rgba(0,0,0,0.8)] rounded-[1.5rem] p-6 text-center",children:[e.jsx("h2",{className:u("text-3xl font-black uppercase tracking-widest drop-shadow-md mb-2",r.outcome==="win"?"text-emerald-400":r.outcome==="loss"?"text-rose-400":"text-amber-400"),children:r.outcome==="win"?"VICTORY!":r.outcome==="loss"?"DEFEAT":"DRAW MATCH"}),e.jsxs("p",{className:"text-white/80 font-bold text-sm mb-4 uppercase tracking-widest",children:["Final Score: ",r.scoreFor," - ",r.scoreAgainst]}),e.jsxs("div",{className:"bg-black/50 rounded-xl p-4 mb-5 border border-white/5 flex flex-col gap-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-white/40 text-[10px] font-black uppercase tracking-widest text-left mb-2",children:"Battle Score"}),(()=>{const t=r.roundResults||[];let o=0,p=0,x=0;for(const k of t)if(k.studentCorrect){o++;const T=o>=2?Math.min(15,(o-1)*5):0;p+=10,x+=T}else o=0;return e.jsxs(e.Fragment,{children:[e.jsx(da,{value:p,label:"Correct Answers",delay:300,icon:e.jsx(Nt,{className:"h-3 w-3 text-emerald-400"})}),e.jsx(da,{value:x,label:"Streak Bonus",delay:900,icon:e.jsx(Je,{className:"h-3 w-3 text-amber-400"})}),e.jsxs(y.div,{initial:{opacity:0},animate:{opacity:1},transition:{delay:1.5,duration:.4},className:"flex items-center justify-between pt-1 mt-1 border-t border-white/5",children:[e.jsx("span",{className:"text-white/50 text-xs font-bold uppercase tracking-widest",children:"Total"}),e.jsxs("span",{className:"text-base font-black text-white/80",children:[p+x," pts"]})]})]})})()]}),e.jsx("div",{className:"w-full h-px bg-white/10"}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-white/40 text-[10px] font-black uppercase tracking-widest text-left mb-2",children:"Match Reward"}),e.jsxs(y.div,{initial:{opacity:0,scale:.9},animate:{opacity:1,scale:1},transition:{delay:2,duration:.5,type:"spring"},className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-white/70 text-sm font-bold",children:r.outcome==="win"?"Victory Reward":r.outcome==="draw"?"Draw Reward":"Participation Reward"}),e.jsxs("span",{className:"text-2xl font-black text-amber-400 drop-shadow-md",children:["+",r.xpEarned||(r.outcome==="win"?80:r.outcome==="draw"?55:35)," XP"]})]}),e.jsx("p",{className:"text-white/25 text-[9px] mt-1 text-right uppercase tracking-widest",children:"Credited to your profile"})]})]}),e.jsxs("div",{className:"flex flex-col gap-3 justify-center",children:[e.jsx(z,{size:"lg",onClick:()=>{_(null),v(null),h(!1),d("hub")},className:"w-full h-12 rounded-xl text-sm font-black bg-white/10 hover:bg-white/20 text-white border border-white/20",children:"BACK TO ARENA"}),r.mode==="bot"&&e.jsx(z,{size:"lg",onClick:()=>void Gt(),disabled:G,className:"w-full h-12 rounded-xl text-sm font-black bg-violet-600 hover:bg-violet-500 text-white border-b-2 border-violet-800 active:border-b-0 active:translate-y-[2px]",children:"REMATCH"})]})]})}):e.jsx(za,{activeMatch:r,roundSecondsLeft:P,lastRoundResult:B,selectedOptionIndex:we,roundLocked:Z,answerSubmitting:G,designPauseActive:F,onOptionSelect:t=>{B&&B.roundNumber===r.currentRound||G||Z||(ma()?.resume().catch(()=>{}),Q("lock"),X(t),Ve(t))},floatingMomentum:Da,lastRoundMomentumDelta:ie,studentProfile:n,quizBattleAvatar:jt})}),e.jsx(Aa,{studentProfile:n,activeMatch:r,scorePulseTarget:Pa,quizBattleAvatar:jt,opponentId:m?.participantIds?.find(t=>t!==a?.uid)||null})]})]})]}):e.jsxs(e.Fragment,{children:[e.jsx("style",{children:St}),e.jsx(na,{bgVideo:"/videos/warp_bg.mp4",className:"-mx-3 lg:-mx-4 -mt-3 lg:-mt-4 -mb-8 px-4 sm:px-6 xl:px-10 py-6 sm:py-8 min-h-[calc(100vh-3.5rem)] !w-auto overflow-hidden relative",children:e.jsx("div",{className:"h-full flex flex-col max-w-[1400px] mx-auto w-full",children:e.jsx(y.div,{initial:{opacity:0,y:16},animate:{opacity:1,y:0},transition:{duration:.24,ease:[.22,1,.36,1]},className:"space-y-3 lg:space-y-4",children:e.jsxs(Is,{value:c,onValueChange:t=>d(t),children:[e.jsx(Ne,{value:"hub",className:"mt-0 outline-none",children:e.jsx(y.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},exit:{opacity:0,y:-12},className:"space-y-5",children:e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-[1fr_300px] xl:grid-cols-[1fr_320px] gap-6 sm:gap-8 lg:gap-10",children:[e.jsxs("div",{className:"space-y-3 lg:space-y-4",children:[e.jsxs("div",{className:"relative select-none isolate bg-indigo-600 rounded-[2rem] shadow-[0_20px_45px_-15px_rgba(0,0,0,0.3)] shrink-0",children:[e.jsx("div",{className:"absolute inset-0 bg-black/60 pointer-events-none z-0 rounded-[2rem]"}),e.jsx("div",{className:"absolute inset-0 opacity-10 pointer-events-none rounded-[2rem] overflow-hidden repeating-stripe-bg"}),e.jsx("div",{className:"absolute top-0 right-0 w-[400px] h-[400px] bg-sky-500/20 blur-[100px] rounded-full pointer-events-none"}),e.jsxs("div",{className:"relative z-10 flex flex-col md:flex-row items-center justify-between p-6 lg:p-8 h-full min-h-[140px] lg:min-h-[160px]",children:[e.jsx("div",{className:"flex-1 space-y-3 w-full pr-0 md:pr-[240px] lg:pr-[280px]",children:e.jsxs("div",{children:[e.jsxs("h1",{className:"flex items-center gap-3 text-3xl sm:text-4xl lg:text-[46px] font-black tracking-tight text-white mb-2 sm:mb-4",children:[e.jsx(wt,{className:"h-8 w-8 sm:h-10 sm:w-10 lg:h-12 lg:w-12 text-[#d1abff]",strokeWidth:2.5}),"Quiz Battle"]}),e.jsx("p",{className:"text-base sm:text-lg lg:text-xl text-white mt-1.5 sm:mt-2 max-w-2xl leading-relaxed",children:"Timed student duels with synchronized rounds, instant feedback, and progression rewards."}),e.jsxs("p",{className:"text-xs lg:text-sm font-semibold uppercase tracking-[0.15em] text-[#8a7fbc] mt-3",children:["Connection: ",e.jsx("span",{className:Pt==="connected"?"text-emerald-400":"text-amber-400",children:Pt})]})]})}),e.jsx("div",{className:"hidden md:block absolute right-[-5px] lg:right-[-15px] top-0 lg:top-[5px] w-[200px] lg:w-[260px] shrink-0 pointer-events-none z-20",children:e.jsx("img",{src:jt,alt:"Mascot",className:"w-full h-full object-contain animate-mascot-float"})})]})]}),e.jsxs("div",{className:"pt-4 lg:pt-6",children:[e.jsxs("h2",{className:"flex items-center gap-2 pb-4 text-xl lg:text-2xl font-black tracking-wide uppercase text-white drop-shadow-[0_0_12px_rgba(255,255,255,0.4)]",children:[e.jsx(wt,{className:"h-6 w-6 lg:h-8 lg:w-8 text-amber-400 drop-shadow-[0_0_8px_rgba(251,191,36,0.9)]"})," BATTLE MODES"]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-2 gap-3 sm:gap-4 lg:gap-6 relative z-10 w-full mb-2",children:[e.jsxs(y.button,{type:"button",onClick:()=>Zt("online"),whileHover:{scale:1.025},whileTap:{scale:.98},transition:{type:"spring",stiffness:400,damping:15},className:"w-full h-[170px] sm:h-[245px] lg:h-[265px] bg-[#8A3FD3] rounded-[22px] border-none relative text-left shadow-[0_8px_30px_rgba(138,63,211,0.2)] hover:shadow-[0_12px_45px_rgba(138,63,211,0.4)] block flex-col group",children:[e.jsx("div",{className:"absolute inset-0 rounded-[22px] shadow-[inset_0_6px_15px_rgba(255,255,255,0.4)] pointer-events-none z-40"}),e.jsxs("div",{className:"absolute top-4 -left-4 z-20 w-[100px] h-[40px] opacity-100",children:[e.jsx("svg",{viewBox:"0 0 100 40",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:"w-full h-full block drop-shadow-md",children:e.jsx("path",{d:"M0 0 H94 Q100 0 100 6 V34 Q100 40 94 40 H0 L14 20 Z",fill:"#b91c1c"})}),e.jsx("div",{className:"absolute inset-0 flex items-center justify-end pr-3 font-black text-[13px] text-white tracking-[0.3px] opacity-100 font-nunito",children:"VS Player"})]}),e.jsxs("div",{className:"rounded-[22px] overflow-hidden relative isolate h-full flex flex-col justify-end",children:[e.jsx("div",{className:"absolute top-0 -left-[150%] w-[100%] h-full bg-gradient-to-r from-transparent via-white/40 to-transparent -skew-x-12 z-50 pointer-events-none transition-all duration-0 group-hover:duration-[800ms] ease-in-out group-hover:left-[150%]"}),e.jsxs("div",{className:"flex-1 w-full flex items-end justify-center relative pt-2 pointer-events-none",children:[e.jsx("div",{className:"absolute bottom-0 left-0 w-full h-[50px] sm:h-[95px] bg-[#662AA8] rounded-[50%_50%_0_0/100%_100%_0_0] scale-[1.05] z-0"}),e.jsxs("div",{className:"relative z-10 flex items-center justify-center mb-[2px] h-[80px] sm:h-[140px] w-full",children:[e.jsx("img",{src:"/avatar/avatar_icon.png",alt:"",className:"h-[120%] sm:h-[125%] object-contain relative z-20 origin-bottom right-[-10px] sm:right-[-15px] drop-shadow-[0_12px_15px_rgba(0,0,0,0.3)] animate-avatar-left"}),e.jsx("div",{className:"relative z-30 flex flex-col items-center mx-[-20px] scale-[1.1] animate-vs-pulse",children:e.jsxs("span",{className:"font-black italic text-[28px] sm:text-[40px] text-gray-200 tracking-tighter leading-none drop-shadow-[-2px_3px_0px_rgba(0,0,0,0.8)] webkit-text-stroke",children:[e.jsx("span",{className:"text-gray-300",children:"V"}),e.jsx("span",{className:"text-gray-400",children:"S"})]})}),e.jsx("img",{src:"/avatar/avatar_icon.png",alt:"",className:"h-[120%] sm:h-[125%] object-contain relative z-10 scale-x-[-1] origin-bottom left-[-20px] drop-shadow-[0_12px_15px_rgba(0,0,0,0.3)] animate-avatar-right"})]})]}),e.jsx("div",{className:"relative z-10 w-full px-3 sm:px-5 py-2 sm:py-4 text-center bg-[#662AA8]",children:e.jsx("p",{className:"text-[10px] sm:text-[13px] font-bold text-white leading-[1.4] font-nunito",children:"Queue or room-code match with another student."})})]})]}),e.jsxs(y.button,{type:"button",onClick:()=>Zt("bot"),whileHover:{scale:1.025},whileTap:{scale:.98},transition:{type:"spring",stiffness:400,damping:15},className:"w-full h-[170px] sm:h-[245px] lg:h-[265px] bg-[#1FA7E1] rounded-[22px] border-none relative text-left shadow-[0_8px_30px_rgba(31,167,225,0.2)] hover:shadow-[0_12px_45px_rgba(31,167,225,0.4)] block flex-col group",children:[e.jsx("div",{className:"absolute inset-0 rounded-[22px] shadow-[inset_0_6px_15px_rgba(255,255,255,0.4)] pointer-events-none z-40"}),e.jsxs("div",{className:"absolute top-4 -left-4 z-20 w-[100px] h-[40px] opacity-100",children:[e.jsx("svg",{viewBox:"0 0 100 40",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:"w-full h-full block drop-shadow-md",children:e.jsx("path",{d:"M0 0 H94 Q100 0 100 6 V34 Q100 40 94 40 H0 L14 20 Z",fill:"#b91c1c"})}),e.jsx("div",{className:"absolute inset-0 flex items-center justify-end pr-3 font-black text-[13px] text-white tracking-[0.3px] opacity-100 font-nunito",children:"VS Bot"})]}),e.jsxs("div",{className:"rounded-[22px] overflow-hidden relative isolate h-full flex flex-col justify-end",children:[e.jsx("div",{className:"absolute top-0 -left-[150%] w-[100%] h-full bg-gradient-to-r from-transparent via-white/40 to-transparent -skew-x-12 z-50 pointer-events-none transition-all duration-0 group-hover:duration-[800ms] ease-in-out group-hover:left-[150%]"}),e.jsxs("div",{className:"flex-1 w-full flex items-end justify-center relative pt-2 pointer-events-none",children:[e.jsx("div",{className:"absolute bottom-0 left-0 w-full h-[50px] sm:h-[95px] bg-[#127DA6] rounded-[50%_50%_0_0/100%_100%_0_0] scale-[1.05] z-0"}),e.jsxs("div",{className:"relative z-10 flex items-end justify-center mb-[2px] h-[85px] sm:h-[145px] w-full",children:[e.jsx("img",{src:"/avatar/avatar_icon.png",alt:"",className:"absolute opacity-40 blur-[1px] h-full object-contain origin-bottom -translate-x-[30px] sm:-translate-x-[60px] scale-[0.80] sm:scale-[0.85] animate-ghost-left"}),e.jsx("img",{src:"/avatar/avatar_icon.png",alt:"",className:"absolute opacity-40 blur-[1px] h-full object-contain origin-bottom translate-x-[30px] sm:translate-x-[60px] scale-[0.80] sm:scale-[0.85] animate-ghost-right"}),e.jsx("img",{src:"/avatar/avatar_icon.png",alt:"VS Bot",className:"relative opacity-100 scale-100 h-[105%] sm:h-[115%] object-contain drop-shadow-[0_15px_15px_rgba(0,0,0,0.3)] z-20 origin-bottom animate-main-avatar"})]})]}),e.jsx("div",{className:"relative z-10 w-full px-3 sm:px-5 py-2 sm:py-4 text-center bg-[#127DA6]",children:e.jsx("p",{className:"text-[10px] sm:text-[13px] font-bold text-white leading-[1.4] font-nunito",children:"Instant solo duel with selectable bot difficulty."})})]})]})]})]})]}),e.jsxs("div",{className:"space-y-3 lg:space-y-4 flex flex-col h-full justify-between",children:[e.jsx("div",{onClick:()=>d("leaderboard"),className:"relative w-full bg-[#3b3a82] dark:bg-[#2b2b5f] rounded-[24px] overflow-hidden flex flex-col shadow-[0_8px_30px_rgba(59,58,130,0.3)] cursor-pointer group mb-4",children:e.jsxs("div",{className:"relative w-full h-[190px] flex flex-col items-center justify-end pt-8",children:[e.jsxs("div",{className:"absolute top-[25px] w-full flex justify-center items-end px-2 z-10 gap-3",children:[e.jsx(vt,{strokeWidth:0,fill:"currentColor",className:"w-[32px] h-[32px] text-[#fcd34d] -rotate-[15deg] mb-2 drop-shadow-[0_0_15px_rgba(252,211,77,0.8)]"}),e.jsx("div",{className:"z-10 animate-star-float",children:e.jsx(vt,{strokeWidth:0,fill:"currentColor",className:"w-[48px] h-[48px] text-[#fcd34d] drop-shadow-[0_0_25px_rgba(252,211,77,0.9)]"})}),e.jsx(vt,{strokeWidth:0,fill:"currentColor",className:"w-[32px] h-[32px] text-[#fcd34d] rotate-[15deg] mb-2 drop-shadow-[0_0_15px_rgba(252,211,77,0.8)]"})]}),e.jsx("div",{className:"absolute bottom-[50px] left-1/2 -translate-x-1/2 w-[220px] h-[160px] bg-gradient-to-t from-white/20 to-transparent blur-[2px] z-0 pointer-events-none",style:{clipPath:"polygon(25% 0, 75% 0, 100% 100%, 0% 100%)"}}),e.jsxs("div",{className:"flex items-end justify-center z-10 relative px-4 bottom-[35px]",children:[e.jsxs("div",{className:"flex flex-col items-center relative z-10",children:[e.jsx("div",{className:"w-[75px] h-[14px] bg-[#D44747] rounded-t-[3px] border-x-[1.5px] border-white/90"}),e.jsxs("div",{className:"w-[65px] h-[45px] bg-[#FE6464] flex flex-col items-center justify-center gap-2 border-x-[1.5px] border-white/90",children:[e.jsx("div",{className:"w-8 h-1.5 bg-white/90 rounded-full mt-1"}),e.jsx("div",{className:"w-8 h-1.5 bg-white/90 rounded-full"})]})]}),e.jsxs("div",{className:"flex flex-col items-center relative z-20 -mx-1",children:[e.jsx("div",{className:"w-[90px] h-[16px] bg-[#F39029] rounded-t-[3px] border-x-[1.5px] border-white/90"}),e.jsxs("div",{className:"w-[80px] h-[65px] bg-[#FFA23A] flex flex-col items-center justify-center gap-2.5 border-x-[1.5px] border-white/90",children:[e.jsx("div",{className:"w-10 h-1.5 bg-white/90 rounded-full mt-1"}),e.jsx("div",{className:"w-10 h-1.5 bg-white/90 rounded-full"})]})]}),e.jsxs("div",{className:"flex flex-col items-center relative z-10",children:[e.jsx("div",{className:"w-[75px] h-[14px] bg-[#D44747] rounded-t-[3px] border-x-[1.5px] border-white/90"}),e.jsxs("div",{className:"w-[65px] h-[45px] bg-[#FE6464] flex flex-col items-center justify-center gap-2 border-x-[1.5px] border-white/90",children:[e.jsx("div",{className:"w-8 h-1.5 bg-white/90 rounded-full mt-1"}),e.jsx("div",{className:"w-8 h-1.5 bg-white/90 rounded-full"})]})]})]}),e.jsxs("div",{className:"absolute bottom-[2px] w-full flex justify-center z-30",children:[e.jsx("div",{className:"absolute top-[10px] w-full h-[35px] bg-[#8E1010] z-0"}),e.jsxs("div",{className:"relative w-[85%] h-[50px] bg-[#C62828] z-10 flex flex-col items-center justify-center rounded-[3px] shadow-[0_4px_10px_rgba(0,0,0,0.2)]",children:[e.jsx("h3",{className:"text-[18px] font-black text-white tracking-wide leading-none font-nunito mt-0.5",children:"Hall of Fame"}),e.jsx("span",{className:"text-[10px] font-bold text-white/90 tracking-wide mt-1",children:"View Page >"})]})]})]})}),e.jsxs("div",{className:"relative w-full bg-[#3b3a82] dark:bg-[#2b2b5f] rounded-[24px] overflow-hidden flex flex-col shadow-[0_8px_30px_rgba(59,58,130,0.3)]",children:[e.jsxs("div",{className:"flex flex-row items-center justify-between px-5 pt-5 pb-3 relative z-10",children:[e.jsx("h3",{className:"text-[20px] font-black text-white tracking-wide leading-none drop-shadow-md font-nunito",children:"My Stats"}),e.jsx(z,{className:"bg-[#7C51A8] hover:bg-[#6b4494] text-white font-bold text-[10px] tracking-widest uppercase rounded-full px-4 h-[28px] border border-white/10 shadow-md transition-transform active:scale-95",onClick:()=>d("stats"),children:"View Stats >"})]}),e.jsxs("div",{className:"relative z-10 w-full overflow-hidden pb-6",children:[e.jsx("div",{className:"absolute left-0 top-0 bottom-6 w-8 bg-gradient-to-r from-[#3b3a82] dark:from-[#2b2b5f] to-transparent z-20 pointer-events-none"}),e.jsx("div",{className:"absolute right-0 top-0 bottom-6 w-8 bg-gradient-to-l from-[#3b3a82] dark:from-[#2b2b5f] to-transparent z-20 pointer-events-none"}),e.jsx(y.div,{className:"flex w-max",animate:{x:["0%","-33.333333%"]},transition:{ease:"linear",duration:15,repeat:1/0},children:[1,2,3].map(t=>e.jsx("div",{className:"flex gap-3 pr-3",children:[{key:"totalXP",bg:"from-[#FF7B88] to-[#FF5C70]",shadow:"shadow-[0_4px_15px_rgba(255,92,112,0.4),inset_0_1px_1px_rgba(255,255,255,0.4)]",icon:Je,value:n?.currentXP||0,label:"Total XP"},{key:"winRate",bg:"from-[#B467FF] to-[#9D44FF]",shadow:"shadow-[0_4px_15px_rgba(157,68,255,0.4),inset_0_1px_1px_rgba(255,255,255,0.4)]",icon:gt,value:`${Math.round(ee?.winRate||0)} %`,label:"Win Rate"},{key:"matches",bg:"from-[#4DB9E9] to-[#2DA1D8]",shadow:"shadow-[0_4px_15px_rgba(45,161,216,0.4),inset_0_1px_1px_rgba(255,255,255,0.4)]",icon:zt,value:ee?.matchesPlayed||0,label:"Matches"},{key:"response",bg:"from-[#48DA94] to-[#2BBF7B]",shadow:"shadow-[0_4px_15px_rgba(43,191,123,0.4),inset_0_1px_1px_rgba(255,255,255,0.4)]",icon:ra,value:ee?.averageResponseMs?`${(ee.averageResponseMs/1e3).toFixed(0)}s`:"0s",label:"Response"}].map(o=>e.jsxs("div",{className:u("w-[90px] sm:w-[100px] shrink-0 aspect-square rounded-[16px] bg-gradient-to-br p-3 flex flex-col justify-between relative overflow-hidden group",o.bg,o.shadow),children:[e.jsx("div",{className:"absolute -bottom-6 -right-6 text-white/10 transition-transform duration-500 group-hover:scale-110",children:e.jsx(o.icon,{className:"w-20 h-20"})}),e.jsx("div",{className:"w-8 h-8 rounded-full border border-white/30 flex items-center justify-center relative z-10 shadow-[inset_0_1px_3px_rgba(255,255,255,0.5)]",children:e.jsx(o.icon,{className:"w-4 h-4 text-white"})}),e.jsxs("div",{className:"relative z-10 flex flex-col",children:[e.jsx("h4",{className:"text-[14px] sm:text-[16px] lg:text-[18px] font-black text-white leading-none tracking-tight drop-shadow-sm",children:o.value}),e.jsx("p",{className:"text-[8px] sm:text-[9px] font-extrabold text-white/80 uppercase tracking-widest mt-1 truncate",children:o.label})]})]},o.key))},t))})]})]}),e.jsxs(pe,{className:u(fe,"rounded-[18px] flex flex-col min-h-[200px]"),children:[e.jsxs(he,{className:"pb-0 pt-3 px-4 flex flex-row items-center justify-between",children:[e.jsxs(be,{className:"text-[14px] font-black flex items-center gap-2 text-[#2e2b5e] dark:text-[#f5f7fb]",children:[e.jsx(rs,{className:"h-[16px] w-[16px] text-[#2e2b5e] dark:text-[#9e8fff]"})," Match History"]}),e.jsx(z,{variant:"link",size:"sm",className:"h-auto p-0 text-[12px] font-semibold text-muted-foreground dark:text-[#95a0bb] hover:text-primary transition-colors",onClick:()=>d("history"),children:"View All"})]}),e.jsxs(Xe,{className:"space-y-1.5 px-4 pt-1 pb-3 overflow-y-auto",children:[e.jsx("div",{className:"text-[11px] text-muted-foreground dark:text-[#8b95ad] mb-1.5 leading-relaxed",children:"Your recent student battles only."}),Qt?e.jsxs("div",{className:"space-y-2",children:[e.jsx(xe,{className:"h-10 w-full rounded-xl bg-muted dark:bg-[#2a3143]"}),e.jsx(xe,{className:"h-10 w-full rounded-xl bg-muted dark:bg-[#2a3143]"})]}):Oe.length===0?e.jsx("p",{className:"text-xs text-center text-muted-foreground dark:text-[#a8b2c9] py-2",children:"No battle history yet."}):Oe.slice(0,3).map(t=>{const o=t.outcome==="win",p=t.outcome==="loss",x=t.opponentName.split(" ").map(k=>k[0]).join("").substring(0,2).toUpperCase()||"OP";return e.jsxs("div",{className:"group relative overflow-hidden rounded-[14px] border border-muted-foreground/15 bg-white dark:bg-[#11151d] dark:border-[#2f3547] p-2 shadow-sm transition-all hover:scale-[1.01] hover:shadow-md",children:[e.jsx("div",{className:u("absolute inset-y-0 right-0 w-[55%] pointer-events-none opacity-[0.2] dark:opacity-[0.25] mix-blend-multiply dark:mix-blend-screen transition-all",o?"bg-gradient-to-l from-emerald-500 via-emerald-500/40 to-transparent":p?"bg-gradient-to-l from-rose-500 via-rose-500/40 to-transparent":"bg-gradient-to-l from-amber-400 via-amber-400/40 to-transparent")}),e.jsxs("div",{className:"flex items-center gap-2.5 relative z-10 w-full",children:[e.jsx("div",{className:u("w-9 h-9 rounded-full flex items-center justify-center font-black text-[12px] tracking-wide text-white flex-shrink-0 shadow-inner",o?"bg-[#34d399] dark:bg-[#15803d]":p?"bg-[#fb7185] dark:bg-[#be123c]":"bg-[#fbbf24] dark:bg-[#b45309]"),children:x}),e.jsxs("div",{className:"flex-grow min-w-0 flex flex-col justify-center",children:[e.jsxs("p",{className:"text-[13px] font-extrabold text-[#36326e] dark:text-[#e4e7f1] truncate leading-tight",children:["vs ",t.opponentName]}),e.jsxs("p",{className:"text-[10px] font-bold text-muted-foreground/60 dark:text-[#7f88a3] truncate flex items-center gap-1 mt-0.5",children:[t.subjectId," ",e.jsx("span",{className:"w-1 h-1 rounded-full bg-muted-foreground/30"})," ",t.difficulty||"Medium"," ",e.jsx("span",{className:"w-1 h-1 rounded-full bg-muted-foreground/30"})," ",t.rounds||"5"," rnds"]})]}),e.jsxs("div",{className:"text-right flex flex-col items-end justify-center pl-2 flex-shrink-0",children:[e.jsxs("p",{className:"tabular-nums text-[16px] leading-[1.1] font-black text-[#2e2b5e] dark:text-[#f5f7fb] tracking-tighter",children:[t.scoreFor,e.jsx("span",{className:"text-muted-foreground/40 mx-[1px]",children:"-"}),t.scoreAgainst]}),e.jsx("p",{className:u("text-[9px] font-black uppercase tracking-[0.1em]",o?"text-emerald-500 dark:text-emerald-400":p?"text-rose-500 dark:text-rose-400":"text-amber-500 dark:text-amber-400"),children:t.outcome})]})]})]},t.matchId)})]})]})]})]})},"hub")}),e.jsx(Ne,{value:"setup",className:"mt-0 outline-none",children:e.jsxs(y.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},exit:{opacity:0,y:-12},className:"w-full space-y-6",children:[e.jsxs(y.div,{className:u(fe,"relative overflow-hidden rounded-[24px] mb-6 shadow-lg",l.mode==="online"?"border-purple-500/20 shadow-[0_0_40px_-10px_rgba(138,63,211,0.2)]":"border-sky-500/20 shadow-[0_0_40px_-10px_rgba(31,167,225,0.2)]"),whileHover:{scale:1.01},transition:{type:"spring",stiffness:300,damping:20},children:[e.jsx("div",{className:u("pointer-events-none absolute inset-0 bg-gradient-to-r",l.mode==="online"?"from-purple-500/20 via-fuchsia-500/10 to-purple-600/5 dark:from-purple-500/20 dark:via-fuchsia-500/10 dark:to-purple-900/10":"from-sky-500/20 via-cyan-500/10 to-sky-600/5 dark:from-sky-500/20 dark:via-cyan-500/10 dark:to-sky-900/10")}),e.jsx("div",{className:u("pointer-events-none absolute -top-24 -right-24 h-64 w-64 rounded-full blur-3xl animate-orb-pulse",l.mode==="online"?"bg-purple-400/20":"bg-sky-400/20")}),e.jsx("div",{className:u("pointer-events-none absolute -bottom-12 -left-12 h-40 w-40 rounded-full blur-2xl animate-orb-pulse-delayed",l.mode==="online"?"bg-fuchsia-400/30":"bg-cyan-400/30")}),e.jsx("div",{className:"absolute inset-0 bg-[url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI0IiBoZWlnaHQ9IjQiPgo8cmVjdCB3aWR0aD0iNCIgaGVpZ2h0PSI0IiBmaWxsPSIjZmZmIiBmaWxsLW9wYWNpdHk9IjAiLz4KPHBhdGggZD0iTTAgMEgxdjFIMHoiIGZpbGw9IiM2MzY2ZjEiIGZpbGwtb3BhY2l0eT0iMC4wNSIvPgo8L3N2Zz4=')] opacity-30 dark:opacity-10 mix-blend-overlay"}),e.jsxs("div",{className:"relative p-6 sm:p-8 md:px-10 flex items-center gap-5 sm:gap-8 z-10",children:[e.jsx(z,{variant:"ghost",onClick:()=>d("hub"),className:u("h-12 w-12 sm:h-14 sm:w-14 p-0 rounded-full hover:scale-105 transition-all backdrop-blur-md shadow-lg shrink-0 flex items-center justify-center group",l.mode==="online"?"bg-white/50 dark:bg-black/40 hover:bg-white/80 dark:hover:bg-black/60 border border-purple-500/30":"bg-white/50 dark:bg-black/40 hover:bg-white/80 dark:hover:bg-black/60 border border-sky-500/30"),children:e.jsx(Ue,{className:u("h-6 w-6 sm:h-8 sm:w-8 rotate-180 transition-transform group-hover:-translate-x-0.5",l.mode==="online"?"text-purple-800 dark:text-purple-300":"text-sky-800 dark:text-sky-300")})}),e.jsxs("div",{children:[e.jsxs("h2",{className:u("flex items-center gap-3 text-3xl sm:text-4xl font-black tracking-tight text-transparent bg-clip-text bg-gradient-to-br drop-shadow-sm",l.mode==="online"?"from-purple-600 to-fuchsia-500 dark:from-purple-300 dark:to-fuchsia-200":"from-sky-600 to-cyan-500 dark:from-sky-300 dark:to-cyan-200"),children:[e.jsx("div",{className:u("p-2 rounded-2xl shadow-inner border animate-icon-bob",l.mode==="online"?"bg-purple-100 dark:bg-purple-900/50 border-purple-200 dark:border-purple-700/50":"bg-sky-100 dark:bg-sky-900/50 border-sky-200 dark:border-sky-700/50"),children:l.mode==="online"?e.jsx(ke,{className:"h-8 w-8 text-purple-600 dark:text-purple-400 drop-shadow-[0_0_8px_rgba(138,63,211,0.5)]"}):e.jsx(Te,{className:"h-8 w-8 text-sky-600 dark:text-sky-400 drop-shadow-[0_0_8px_rgba(31,167,225,0.5)]"})}),l.mode==="online"?"1v1 Online":"1v1 vs Bot"]}),e.jsx("p",{className:u("text-[10px] sm:text-[12px] font-black uppercase tracking-[0.2em] mt-1.5 drop-shadow-sm",l.mode==="online"?"text-purple-600/80 dark:text-purple-400/80":"text-sky-600/80 dark:text-sky-400/80"),children:l.mode==="online"?"CHALLENGE YOUR SCHOOLMATES AND PROVE YOUR SKILLS.":"CHALLENGE THE AI AND SHARPEN YOUR SKILLS."})]})]})]}),e.jsx("div",{className:"rounded-[24px] border border-white/40 bg-white/85 dark:border-white/10 dark:bg-black/80 backdrop-blur-xl p-5 sm:p-7 shadow-xl",children:e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6 lg:gap-10",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1.5 group",children:[e.jsx("label",{className:u("text-[11px] font-black uppercase tracking-[0.12em] ml-1",l.mode==="online"?"text-[#8A3FD3] dark:text-[#a35ceb]":"text-[#1FA7E1] dark:text-[#4bc1f2]"),children:"Category"}),e.jsxs(Me,{value:l.subjectId,onValueChange:t=>w(o=>({...o,subjectId:t})),children:[e.jsx(Fe,{className:u("rounded-xl h-11 border-white/20 bg-white text-slate-800 dark:bg-black/50 dark:text-white dark:border-white/10 transition-colors shadow-inner",l.mode==="online"?"hover:border-[#8A3FD3]/50":"hover:border-[#1FA7E1]/50",U("subjectId")&&"border-rose-400"),children:e.jsx(Ee,{placeholder:"Select category"})}),e.jsx(Re,{className:"rounded-xl backdrop-blur-xl bg-white/90 dark:bg-[#1a1f2e]/90",children:le.map(t=>e.jsx(de,{value:t.id,className:"rounded-lg",children:t.title},t.id))})]}),U("subjectId")&&e.jsx("p",{className:"text-xs text-destructive dark:text-rose-300 ml-1",children:U("subjectId")})]}),e.jsxs("div",{className:"space-y-1.5 group",children:[e.jsx("label",{className:u("text-[11px] font-black uppercase tracking-[0.12em] ml-1",l.mode==="online"?"text-[#8A3FD3] dark:text-[#a35ceb]":"text-[#1FA7E1] dark:text-[#4bc1f2]"),children:"Strand / Topic Group"}),e.jsxs(Me,{value:l.topicId,onValueChange:t=>w(o=>({...o,topicId:t})),children:[e.jsx(Fe,{className:u("rounded-xl h-11 border-white/20 bg-white text-slate-800 dark:bg-black/50 dark:text-white dark:border-white/10 transition-colors shadow-inner",l.mode==="online"?"hover:border-[#8A3FD3]/50":"hover:border-[#1FA7E1]/50",U("topicId")&&"border-rose-400"),children:e.jsx(Ee,{placeholder:"Select topic group"})}),e.jsx(Re,{className:"rounded-xl backdrop-blur-xl bg-white/90 dark:bg-[#1a1f2e]/90",children:Qa.map(t=>e.jsx(de,{value:t.value,className:"rounded-lg",children:t.label},t.value))})]}),U("topicId")&&e.jsx("p",{className:"text-xs text-destructive dark:text-rose-300 ml-1",children:U("topicId")})]}),e.jsxs("div",{className:"space-y-1.5 group",children:[e.jsx("label",{className:u("text-[11px] font-black uppercase tracking-[0.12em] ml-1",l.mode==="online"?"text-[#8A3FD3] dark:text-[#a35ceb]":"text-[#1FA7E1] dark:text-[#4bc1f2]"),children:l.mode==="online"?"Difficulty":"Bot Difficulty"}),e.jsxs(Me,{value:l.mode==="bot"?l.adaptiveBot?"adaptive":l.botDifficulty:l.difficulty,onValueChange:t=>w(o=>o.mode==="bot"?{...o,botDifficulty:t,adaptiveBot:t==="adaptive"}:{...o,difficulty:t}),children:[e.jsx(Fe,{className:u("rounded-xl h-11 border-white/20 bg-white text-slate-800 dark:bg-black/50 dark:text-white dark:border-white/10 transition-colors shadow-inner",l.mode==="online"?"hover:border-[#8A3FD3]/50":"hover:border-[#1FA7E1]/50"),children:e.jsx(Ee,{})}),e.jsxs(Re,{className:"rounded-xl backdrop-blur-xl bg-white/90 dark:bg-[#1a1f2e]/90",children:[e.jsx(de,{value:"easy",className:"rounded-lg",children:"Easy"}),e.jsx(de,{value:"medium",className:"rounded-lg",children:"Medium"}),e.jsx(de,{value:"hard",className:"rounded-lg",children:"Hard"}),l.mode==="bot"&&e.jsx(de,{value:"adaptive",className:"rounded-lg",children:"Adaptive"})]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-1.5 group",children:[e.jsx("label",{className:u("text-[10px] sm:text-[11px] font-black uppercase tracking-[0.12em] ml-1",l.mode==="online"?"text-[#8A3FD3] dark:text-[#a35ceb]":"text-[#1FA7E1] dark:text-[#4bc1f2]"),children:"Questions"}),e.jsxs(Me,{value:String(l.rounds),onValueChange:t=>w(o=>({...o,rounds:Number(t)})),children:[e.jsx(Fe,{className:u("rounded-xl h-11 border-white/20 bg-white text-slate-800 dark:bg-black/50 dark:text-white dark:border-white/10 transition-colors shadow-inner",l.mode==="online"?"hover:border-[#8A3FD3]/50":"hover:border-[#1FA7E1]/50",U("rounds")&&"border-rose-400"),children:e.jsx(Ee,{})}),e.jsx(Re,{className:"rounded-xl backdrop-blur-xl bg-white/90 dark:bg-[#1a1f2e]/90",children:[3,5,7,10,12,15].map(t=>e.jsx(de,{value:String(t),className:"rounded-lg",children:t},t))})]}),U("rounds")&&e.jsx("p",{className:"text-xs text-destructive dark:text-rose-300 ml-1",children:U("rounds")})]}),e.jsxs("div",{className:"space-y-1.5 group",children:[e.jsx("label",{className:u("text-[10px] sm:text-[11px] font-black uppercase tracking-[0.12em] ml-1 line-clamp-1",l.mode==="online"?"text-[#8A3FD3] dark:text-[#a35ceb]":"text-[#1FA7E1] dark:text-[#4bc1f2]"),children:"Time / Q"}),e.jsxs(Me,{value:String(l.timePerQuestionSec),onValueChange:t=>w(o=>({...o,timePerQuestionSec:Number(t)})),children:[e.jsx(Fe,{className:u("rounded-xl h-11 border-white/20 bg-white text-slate-800 dark:bg-black/50 dark:text-white dark:border-white/10 transition-colors shadow-inner",l.mode==="online"?"hover:border-[#8A3FD3]/50":"hover:border-[#1FA7E1]/50",U("timePerQuestionSec")&&"border-rose-400"),children:e.jsx(Ee,{})}),e.jsx(Re,{className:"rounded-xl backdrop-blur-xl bg-white/90 dark:bg-[#1a1f2e]/90",children:[15,20,30,45,60,90].map(t=>e.jsxs(de,{value:String(t),className:"rounded-lg",children:[t," sec"]},t))})]}),U("timePerQuestionSec")&&e.jsx("p",{className:"text-xs text-destructive dark:text-rose-300 ml-1",children:U("timePerQuestionSec")})]})]})]}),e.jsxs("div",{className:"flex flex-col justify-between space-y-6",children:[e.jsxs("div",{className:"space-y-5",children:[l.mode==="online"&&e.jsxs("div",{className:"space-y-3 rounded-2xl border border-[#8A3FD3]/20 bg-[#8A3FD3]/5 dark:border-[#8A3FD3]/20 p-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-[11px] font-black uppercase tracking-[0.12em] text-[#8A3FD3] dark:text-[#a35ceb] ml-1",children:"Online Match Type"}),e.jsx("div",{className:"grid grid-cols-2 gap-3",children:[{value:"public_matchmaking",label:"Public Queue"},{value:"private_room",label:"Private Room"}].map(t=>e.jsx(z,{type:"button",variant:l.queueType===t.value?"default":"outline",className:u("rounded-xl h-11 transition-all border-none font-bold text-xs",l.queueType===t.value?"bg-[#8A3FD3] hover:bg-[#7b35c0] text-white shadow-md shadow-[#8A3FD3]/30":"bg-white/50 hover:bg-white/80 dark:bg-black/30 dark:hover:bg-black/50 text-[#8A3FD3] dark:text-[#d3a8ff]"),onClick:()=>w(o=>({...o,queueType:t.value})),children:t.label},t.value))})]}),l.queueType==="private_room"&&e.jsxs(y.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},className:"pt-2 space-y-2",children:[e.jsx("label",{className:"text-[11px] font-black uppercase tracking-[0.12em] text-[#8A3FD3] dark:text-[#a35ceb] ml-1",children:"Room Code (optional)"}),e.jsx(es,{value:W,onChange:t=>S(t.target.value.toUpperCase().replace(/[^A-Z0-9]/g,"").slice(0,6)),placeholder:"Leave blank to create a room",className:"rounded-xl h-12 text-center text-lg uppercase font-bold tracking-[0.25em] border-[#8A3FD3]/30 bg-white/80 dark:bg-black/50 dark:border-[#8A3FD3]/20 focus-visible:ring-[#8A3FD3]/50 shadow-inner",maxLength:6}),e.jsx("div",{className:"rounded-xl border border-[#8A3FD3]/30 bg-[#8A3FD3]/10 px-3 py-3 text-[12px] font-semibold text-[#6620a2] leading-snug dark:border-[#8A3FD3]/30 dark:bg-[#8A3FD3]/10 dark:text-[#d3a8ff]",children:"Enter a room code to join an existing battle, or leave it blank to create a new room and share your code."})]})]}),e.jsxs("label",{className:u("flex flex-col sm:flex-row sm:items-center justify-between rounded-[16px] border bg-white/50 p-4 transition-colors cursor-pointer shadow-sm dark:bg-black/50 group",l.mode==="online"?"border-[#8A3FD3]/20 hover:bg-[#8A3FD3]/5 dark:border-[#8A3FD3]/20 dark:hover:bg-[#8A3FD3]/10":"border-[#1FA7E1]/20 hover:bg-[#1FA7E1]/5 dark:border-[#1FA7E1]/20 dark:hover:bg-[#1FA7E1]/10"),children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:u("h-11 w-11 rounded-full flex items-center justify-center group-hover:scale-110 transition-transform",l.mode==="online"?"bg-[#8A3FD3]/10 text-[#8A3FD3] dark:text-[#c48bfc]":"bg-[#1FA7E1]/10 text-[#1FA7E1] dark:text-[#7ad8ff]"),children:J?e.jsx(ga,{className:"h-5 w-5"}):e.jsx(wa,{className:"h-5 w-5 opacity-60"})}),e.jsxs("div",{className:"mb-3 sm:mb-0",children:[e.jsx("p",{className:"text-sm font-bold text-slate-800 dark:text-slate-200",children:"Battle Sounds"}),e.jsx("p",{className:"text-xs font-medium text-slate-500 dark:text-slate-400",children:"Cues for countdowns and results."})]})]}),e.jsx(ts,{checked:J,onCheckedChange:Dt})]}),e.jsxs(y.div,{initial:!1,animate:{opacity:J?1:.45,y:J?0:-2},className:u("rounded-[16px] border bg-white/40 p-4 shadow-sm dark:bg-black/40",l.mode==="online"?"border-[#8A3FD3]/20 dark:border-[#8A3FD3]/20":"border-[#1FA7E1]/20 dark:border-[#1FA7E1]/20"),children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[e.jsx("p",{className:"text-xs font-black uppercase tracking-[0.14em] text-slate-700 dark:text-slate-200",children:"SFX Volume"}),e.jsxs("p",{className:"text-xs font-bold text-slate-500 dark:text-slate-400",children:[Math.round(ce*100),"%"]})]}),e.jsx("input",{type:"range",min:0,max:100,step:1,value:Math.round(ce*100),disabled:!J,onChange:t=>{const o=Ge(Number(t.target.value)/100,0,1);Ca(o)},onMouseUp:()=>Q("tick"),onTouchEnd:()=>Q("tick"),className:"h-2 w-full cursor-pointer accent-violet-500 disabled:cursor-not-allowed disabled:opacity-50","aria-label":"Battle sound effects volume"})]})]}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{"aria-live":"polite",className:"min-h-[24px] text-sm font-medium",children:[N.status==="queued"&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:u("inline-flex items-center gap-1 text-[13px] font-bold px-3 py-1.5 rounded-lg",l.mode==="online"?"text-[#8A3FD3] bg-[#8A3FD3]/10":"text-[#1FA7E1] bg-[#1FA7E1]/10"),children:N.message}),l.mode==="online"&&l.queueType==="private_room"&&m?.roomCode&&e.jsxs(z,{type:"button",variant:"outline",className:u("h-8 rounded-full border-emerald-500/50 bg-emerald-50 px-4 text-xs font-black uppercase tracking-[0.16em] text-emerald-900 shadow-sm hover:bg-emerald-100 hover:scale-105 transition-all dark:border-emerald-500/40 dark:bg-emerald-500/10 dark:text-emerald-300 dark:hover:bg-emerald-500/20",R===m.roomCode&&"scale-105 bg-emerald-200 dark:bg-emerald-500/30"),onClick:()=>void Ut(m.roomCode),"aria-label":`Copy room code ${m.roomCode}`,children:[R===m.roomCode?e.jsx(Nt,{className:"h-4 w-4"}):e.jsx(sa,{className:"h-4 w-4"}),m.roomCode]}),(j||Jt)&&O>0&&e.jsxs("span",{className:u("inline-flex items-center gap-1.5 rounded-full px-3 py-1 text-xs font-bold animate-pulse",l.mode==="online"?"bg-[#8A3FD3]/10 text-[#8A3FD3]":"bg-[#1FA7E1]/10 text-[#1FA7E1]"),children:["Waiting ",ca(O)]})]}),N.status==="error"&&e.jsx("span",{className:"inline-flex items-center gap-1.5 text-[13px] font-bold text-rose-600 dark:text-rose-400 bg-rose-50 dark:bg-rose-500/10 px-3 py-1.5 rounded-lg border border-rose-200 dark:border-rose-500/20",children:N.message}),N.status==="validating"&&e.jsxs("span",{className:u("inline-flex items-center gap-2 font-bold px-3 py-1.5 rounded-lg",l.mode==="online"?"text-[#8A3FD3] bg-[#8A3FD3]/10":"text-[#1FA7E1] bg-[#1FA7E1]/10"),children:[e.jsx(Ke,{className:"h-4 w-4 animate-spin"})," Validating..."]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[Oa&&e.jsx(z,{type:"button",variant:"outline",onClick:Kt,disabled:N.status==="validating",className:"rounded-xl h-14 flex-1 sm:flex-none border-slate-300 hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800 font-bold px-6",children:m?"Cancel room":"Leave queue"}),e.jsx(z,{type:"button",onClick:$a,disabled:N.status==="validating"||j||Jt,className:u("rounded-xl h-14 flex-1 px-8 font-black uppercase tracking-wide text-sm shadow-xl hover:scale-[1.02] active:scale-95 transition-all text-white border-0",l.mode==="online"?"bg-[#8A3FD3] hover:bg-[#7b35c0] shadow-[#8A3FD3]/40":"bg-[#1FA7E1] hover:bg-[#1a95c9] shadow-[#1FA7E1]/40"),children:N.status==="validating"?e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx(Ke,{className:"h-5 w-5 animate-spin"})," Starting..."]}):l.mode==="online"&&l.queueType==="private_room"?W.trim()?"Join Room":"Create Room":"Start Battle"})]})]})]})]})})]},"setup")}),e.jsx(Ne,{value:"battle",className:"mt-0 outline-none",children:e.jsx(y.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},exit:{opacity:0,y:-12},className:"space-y-4",children:r?e.jsxs(pe,{className:u(fe,"rounded-[18px]"),children:[e.jsxs(he,{children:[e.jsxs(be,{className:"text-base flex items-center justify-between gap-3",children:[e.jsxs("span",{className:"inline-flex items-center gap-2",children:[r.mode==="bot"?e.jsx(Te,{className:"h-4 w-4 text-primary dark:text-[#9e8fff]"}):e.jsx(ke,{className:"h-4 w-4 text-primary dark:text-[#9e8fff]"}),"vs ",r.opponentName]}),e.jsxs("div",{className:"inline-flex items-center gap-2",children:[ft,e.jsxs("span",{className:"text-sm font-bold tabular-nums",children:[r.scoreFor," - ",r.scoreAgainst]})]})]}),e.jsx(ye,{className:"text-muted-foreground dark:text-[#b2bad0]",children:r.status==="completed"?`Completed in ${r.totalRounds} rounds.`:r.status==="ready"?r.mode==="online"?"Waiting for both players to confirm and start together.":"Finalizing practice bot session start.":`Round ${r.currentRound} of ${r.totalRounds}${F?" (paused for design)":""}`}),ua(r.lifecycle,n?.uid)&&e.jsx("p",{className:"text-xs font-medium text-muted-foreground dark:text-[#9aa4be]",children:ua(r.lifecycle,n?.uid)})]}),e.jsxs(Xe,{className:"space-y-4",children:[r.status==="ready"&&e.jsxs("div",{className:"rounded-xl border border-border bg-muted/30 p-4 dark:border-[#2f3547] dark:bg-[#11151d] flex flex-col gap-3",children:[e.jsx("p",{className:"text-sm font-semibold text-foreground dark:text-[#ecf0fb]",children:r.mode==="online"?"Waiting for both players to lock in start...":"Starting practice bot round..."}),r.mode==="online"&&r.expiresAtMs&&e.jsxs("p",{className:"text-xs font-medium text-muted-foreground dark:text-[#9aa4be]",children:["Public match expires in ",e.jsx("span",{className:"font-semibold tabular-nums",children:ca(O)})," if the synchronized start does not happen."]}),e.jsx(z,{variant:"outline",size:"sm",className:"w-full text-rose-500 border-rose-200 hover:bg-rose-50 dark:border-rose-900 dark:hover:bg-rose-900/30",onClick:()=>{_(null),v(null),h(!1),b({status:"idle"}),d("setup")},children:"Force Cancel"})]}),r.status==="in_progress"&&r.currentQuestion&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rounded-xl border border-border bg-muted/40 p-3 dark:border-[#2f3547] dark:bg-[#11151d]",children:[e.jsxs("p",{className:"text-xs text-muted-foreground dark:text-[#9aa4be]",children:["Time left: ",e.jsxs("span",{className:"font-semibold tabular-nums",children:[P,"s"]}),F?" (paused)":""]}),F&&e.jsx("p",{className:"mt-1 text-[11px] font-medium text-amber-700 dark:text-amber-300",children:"Design pause keeps this battle screen static while you edit UI."})]}),e.jsx("p",{className:"text-lg font-bold text-foreground dark:text-[#f5f7fb]",children:r.currentQuestion.prompt}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2",children:r.currentQuestion.choices.map((t,o)=>e.jsxs(z,{type:"button",variant:we===o?"default":"outline",onClick:()=>X(o),disabled:G||Z||F,className:u("h-auto min-h-[48px] justify-start text-left font-medium px-4 py-3 rounded-xl whitespace-normal",we===o?"ring-2 ring-primary ring-offset-2 dark:ring-offset-[#0B0F19]":""),children:[e.jsxs("span",{className:"mr-2 font-semibold",children:[String.fromCharCode(65+o),"."]}),t]},o))}),e.jsx("div",{className:"flex justify-end",children:e.jsx(z,{type:"button",onClick:()=>void Ve(we),disabled:G||Z||F,className:"rounded-xl",children:F?e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx(ls,{className:"h-4 w-4"})," Paused for design"]}):G?e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx(Ke,{className:"h-4 w-4 animate-spin"})," Submitting..."]}):Z?"Waiting for opponent...":"Lock Answer"})})]}),B&&e.jsxs("div",{className:"rounded-xl border border-border bg-muted/30 p-3 dark:border-[#2f3547] dark:bg-[#11151d]",children:[e.jsxs("p",{className:"text-sm font-semibold text-foreground dark:text-[#ecf0fb]",children:["Last round: ",B.studentCorrect?"Correct":"Incorrect"," · ",r.mode==="bot"?"Bot":"Opponent"," ",B.botCorrect?"Correct":"Incorrect"]}),e.jsxs("p",{className:"text-xs text-muted-foreground dark:text-[#9aa4be]",children:["Correct option: ",String.fromCharCode(65+B.correctOptionIndex)]})]}),r.status==="completed"&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:u("rounded-2xl border p-4",r.outcome==="win"?"border-emerald-300 bg-emerald-50 dark:border-emerald-400/40 dark:bg-emerald-900/20":r.outcome==="loss"?"border-rose-300 bg-rose-50 dark:border-rose-400/40 dark:bg-rose-900/20":"border-amber-300 bg-amber-50 dark:border-amber-400/40 dark:bg-amber-900/20"),children:[e.jsx("p",{className:"text-lg font-black tracking-wide text-foreground dark:text-[#ecf0fb]",children:r.outcome==="win"?"Victory!":r.outcome==="loss"?"Match Complete":"Draw Match"}),e.jsxs("p",{className:"mt-1 text-sm font-semibold text-foreground dark:text-[#ecf0fb]",children:["Final Score: ",r.scoreFor," - ",r.scoreAgainst]}),e.jsxs("p",{className:"text-xs text-muted-foreground dark:text-[#9aa4be]",children:["XP Earned: +",r.xpBreakdown?.totalXPAwarded??r.xpEarned??0,r.xpBreakdown&&e.jsxs("span",{className:"block",children:["Base: +",r.xpBreakdown.baseMatchXP," + Performance: +",r.xpBreakdown.performanceXP]})]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(z,{type:"button",variant:"outline",onClick:()=>{_(null),v(null),h(!1),d("setup")},className:"rounded-xl",children:"Start New Match"}),r.mode==="bot"&&e.jsx(z,{type:"button",onClick:()=>void Gt(),disabled:G,className:"rounded-xl",children:"Rematch"})]})]})]})]}):m?e.jsxs(pe,{className:u(fe,"rounded-[18px]"),children:[e.jsxs(he,{children:[e.jsxs(be,{className:"text-base flex items-center gap-2",children:[e.jsx(ke,{className:"h-4 w-4 text-primary dark:text-[#9e8fff]"}),"Private Room Lobby"]}),e.jsxs(ye,{className:"text-muted-foreground dark:text-[#b2bad0]",children:["Room ",m.roomCode," · ",m.participantCount,"/2 students connected."]})]}),e.jsx(Xe,{className:"space-y-3",children:e.jsxs("div",{className:"rounded-xl border border-border bg-muted/30 p-3 dark:border-[#2f3547] dark:bg-[#11151d]",children:[e.jsx("p",{className:"text-sm font-semibold text-foreground dark:text-[#ecf0fb]",children:m.status==="ready"?"Opponent connected. Syncing start...":"Waiting for another student to join this room."}),e.jsxs("p",{className:"text-xs text-muted-foreground dark:text-[#9aa4be]",children:["Share room code ",m.roomCode," with your classmate."]}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center justify-end gap-2",children:[(m.status==="waiting"||m.status==="ready")&&e.jsx(z,{type:"button",variant:"outline",className:"h-8 rounded-lg",onClick:Kt,disabled:N.status==="validating",children:"Cancel room"}),e.jsxs(z,{type:"button",variant:"outline",className:"h-8 rounded-lg",onClick:()=>void Ut(m.roomCode),children:[R===m.roomCode?e.jsx(Nt,{className:"h-4 w-4"}):e.jsx(sa,{className:"h-4 w-4"}),R===m.roomCode?"Copied":"Copy code"]})]})]})})]}):j?e.jsx(pe,{className:u(fe,"rounded-[18px]"),children:e.jsxs(he,{children:[e.jsxs(be,{className:"text-base flex items-center gap-2",children:[e.jsx(ke,{className:"h-4 w-4 text-primary dark:text-[#9e8fff]"}),"Public Matchmaking"]}),e.jsx(ye,{className:"text-muted-foreground dark:text-[#b2bad0]",children:"Searching for a student with the same setup..."})]})}):e.jsx(pe,{className:u(fe,"rounded-[18px]"),children:e.jsxs(he,{children:[e.jsxs(be,{className:"text-base flex items-center gap-2",children:[e.jsx(wt,{className:"h-4 w-4 text-primary dark:text-[#9e8fff]"}),"No active battle"]}),e.jsx(ye,{className:"text-muted-foreground dark:text-[#b2bad0]",children:"Start from Setup to create a bot match, private room, or public queue session."})]})})},"battle")}),e.jsx(Ne,{value:"history",className:"mt-0 outline-none",children:e.jsxs(y.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},exit:{opacity:0,y:-12},className:"space-y-4",children:[e.jsxs(y.div,{className:"relative overflow-hidden rounded-[24px] mb-6 bg-white/5 border border-white/10 shadow-2xl backdrop-blur-3xl",whileHover:{scale:1.01},transition:{type:"spring",stiffness:300,damping:20},children:[e.jsx("div",{className:"pointer-events-none absolute inset-0 bg-gradient-to-r from-emerald-500/10 via-teal-500/5 to-transparent"}),e.jsx("div",{className:"pointer-events-none absolute -top-24 -right-24 h-64 w-64 rounded-full bg-emerald-500/20 blur-3xl animate-orb-pulse"}),e.jsx("div",{className:"pointer-events-none absolute -bottom-12 -left-12 h-40 w-40 rounded-full bg-teal-500/20 blur-2xl animate-orb-pulse-delayed"}),e.jsx("div",{className:"relative z-10 p-6 sm:p-8 flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4",children:e.jsxs("div",{className:"flex items-center gap-5",children:[e.jsx(z,{variant:"ghost",onClick:()=>d("hub"),className:"h-12 w-12 p-0 rounded-full bg-white/10 hover:bg-white/20 hover:scale-105 transition-all backdrop-blur-md border border-white/10 shadow-[0_0_15px_rgba(16,185,129,0.15)] shrink-0",children:e.jsx(Ue,{className:"h-6 w-6 rotate-180 text-emerald-300"})}),e.jsxs("div",{children:[e.jsxs("h2",{className:"flex items-center gap-3 text-3xl sm:text-4xl font-black tracking-tight text-white drop-shadow-md",children:[e.jsx("div",{className:"bg-emerald-500/20 p-2 rounded-2xl shadow-inner border border-emerald-500/30",children:e.jsxs("div",{className:"relative w-8 h-8 flex items-center justify-center",children:[e.jsx("div",{className:"absolute w-5 h-6 bg-emerald-500/30 border border-emerald-400/50 rounded-sm -rotate-12 translate-x-1 shadow-sm"}),e.jsx("div",{className:"absolute w-5 h-6 bg-teal-400/50 border border-teal-300/60 rounded-sm rotate-6 -translate-x-1 shadow-md backdrop-blur-sm"}),e.jsxs("div",{className:"absolute w-5 h-6 bg-gradient-to-br from-emerald-400 to-teal-500 rounded-sm shadow-[0_0_15px_rgba(52,211,153,0.8)] z-10 flex flex-col items-center justify-center gap-[3px]",children:[e.jsx("div",{className:"w-2.5 h-[2px] bg-white/90 rounded-full"}),e.jsx("div",{className:"w-3 h-[2px] bg-white/90 rounded-full"}),e.jsx("div",{className:"w-2 h-[2px] bg-white/90 rounded-full"})]})]})}),"Matches History"]}),e.jsx("p",{className:"text-[12px] font-black text-white/60 mt-2 tracking-[0.1em] uppercase",children:"Review your past duels and track your progress."})]})]})})]}),e.jsxs("div",{className:"relative isolate w-full",children:[e.jsx("div",{className:"absolute top-[-10%] right-[-5%] w-[400px] h-[400px] bg-blue-500/20 rounded-full blur-[120px] pointer-events-none -z-10"}),e.jsx("div",{className:"absolute bottom-[-10%] left-[-5%] w-[350px] h-[350px] bg-teal-500/20 rounded-full blur-[120px] pointer-events-none -z-10"}),e.jsxs("div",{className:"rounded-[24px] bg-white/5 border border-white/10 shadow-2xl backdrop-blur-3xl p-6 sm:p-8",children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h3",{className:"text-xl font-black text-white tracking-wide leading-none drop-shadow-md",children:"Match History"}),e.jsx("p",{className:"text-sm font-semibold text-white/60 mt-2",children:"Your recent student battles only."})]}),e.jsx("div",{className:"flex gap-2 mb-6",children:[{value:"all",label:"All"},{value:"online",label:"Online"},{value:"bot",label:"Bot"}].map(t=>e.jsx(z,{type:"button",variant:"outline",onClick:()=>Ia(t.value),className:u("rounded-full h-9 px-5 border transition-all font-bold tracking-wide",ge===t.value?"bg-emerald-500/20 border-emerald-500/50 text-emerald-300 shadow-[0_0_15px_rgba(16,185,129,0.2)]":"bg-white/5 border-white/10 text-white/70 hover:bg-white/10 hover:text-white"),children:t.label},t.value))}),e.jsx("div",{className:"space-y-4",children:Qt?e.jsxs("div",{className:"space-y-3",children:[e.jsx(xe,{className:"h-[76px] w-full rounded-2xl bg-white/5 border border-white/10"}),e.jsx(xe,{className:"h-[76px] w-full rounded-2xl bg-white/5 border border-white/10"})]}):Oe.length===0?e.jsx("p",{className:"text-sm text-white/50 py-4",children:"No matches in this filter yet."}):Oe.map(t=>{const o=t.outcome==="win",p=t.outcome==="loss";return e.jsxs("div",{className:"relative overflow-hidden rounded-[20px] bg-white/5 border border-white/10 p-5 flex items-center justify-between shadow-lg transition-all hover:bg-white/10 hover:shadow-xl",children:[e.jsx("div",{className:u("absolute inset-y-0 left-0 w-3/4 pointer-events-none z-0",o?"bg-gradient-to-r from-emerald-500/50 via-emerald-500/10 to-transparent":p?"bg-gradient-to-r from-rose-500/50 via-rose-500/10 to-transparent":"bg-gradient-to-r from-amber-500/50 via-amber-500/10 to-transparent")}),e.jsxs("div",{className:"relative z-10 pl-2",children:[e.jsxs("p",{className:"text-base sm:text-lg font-black text-white drop-shadow-md",children:["vs ",t.opponentName]}),e.jsxs("p",{className:"text-[13px] font-bold text-white/60 tabular-nums mt-0.5",children:[t.scoreFor,"-",t.scoreAgainst," ",e.jsx("span",{className:"mx-1",children:"•"})," ",t.accuracy.toFixed(0),"% ",e.jsx("span",{className:"mx-1",children:"•"})," +",t.xpEarned," XP"]})]}),e.jsx("div",{className:"relative z-10",children:e.jsx("span",{className:u("text-sm font-black uppercase tracking-[0.1em] rounded-full px-4 py-1.5 border shadow-sm",o?"text-emerald-300 border-emerald-500/30 bg-emerald-500/10 shadow-[0_0_15px_rgba(16,185,129,0.15)]":p?"text-rose-300 border-rose-500/30 bg-rose-500/10 shadow-[0_0_15px_rgba(244,63,94,0.15)]":"text-amber-300 border-amber-500/30 bg-amber-500/10 shadow-[0_0_15px_rgba(245,158,11,0.15)]"),children:Rs(t.outcome)})})]},t.matchId)})})]})]})]},"history")}),e.jsx(Ne,{value:"stats",className:"mt-0 outline-none",children:e.jsxs(y.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},exit:{opacity:0,y:-12},className:"space-y-4",children:[e.jsxs(y.div,{className:"relative overflow-hidden rounded-[24px] mb-6 bg-white/5 border border-white/10 shadow-2xl backdrop-blur-3xl",whileHover:{scale:1.01},transition:{type:"spring",stiffness:300,damping:20},children:[e.jsx("div",{className:"pointer-events-none absolute inset-0 bg-gradient-to-r from-indigo-500/10 via-purple-500/5 to-transparent"}),e.jsx("div",{className:"pointer-events-none absolute -top-24 -right-24 h-64 w-64 rounded-full bg-indigo-500/20 blur-3xl animate-orb-pulse"}),e.jsx("div",{className:"pointer-events-none absolute -bottom-12 -left-12 h-40 w-40 rounded-full bg-purple-500/20 blur-2xl animate-orb-pulse-delayed"}),e.jsx("div",{className:"relative z-10 p-6 sm:p-8 flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4",children:e.jsxs("div",{className:"flex items-center gap-5",children:[e.jsx(z,{variant:"ghost",onClick:()=>d("hub"),className:"h-12 w-12 p-0 rounded-full bg-white/10 hover:bg-white/20 hover:scale-105 transition-all backdrop-blur-md border border-white/10 shadow-[0_0_15px_rgba(99,102,241,0.15)] shrink-0",children:e.jsx(Ue,{className:"h-6 w-6 rotate-180 text-indigo-300"})}),e.jsxs("div",{children:[e.jsxs("h2",{className:"flex items-center gap-3 text-3xl sm:text-4xl font-black tracking-tight text-white drop-shadow-md",children:[e.jsx("div",{className:"bg-indigo-500/20 p-2 rounded-2xl shadow-inner border border-indigo-500/30 animate-icon-bob",children:e.jsxs("div",{className:"relative w-8 h-8 flex items-end justify-center gap-1 pb-1",children:[e.jsx("div",{className:"w-1.5 h-3 bg-indigo-300 rounded-t-[2px] shadow-[0_0_8px_rgba(165,180,252,0.8)]"}),e.jsx("div",{className:"w-1.5 h-6 bg-purple-400 rounded-t-[2px] shadow-[0_0_12px_rgba(192,132,252,0.9)]"}),e.jsx("div",{className:"w-1.5 h-4 bg-indigo-400 rounded-t-[2px] shadow-[0_0_8px_rgba(129,140,248,0.8)]"})]})}),"My Statistics"]}),e.jsx("p",{className:"text-[12px] font-black text-white/60 mt-2 tracking-[0.1em] uppercase",children:"Analyzing your battlefield performance."})]})]})})]}),e.jsxs("div",{className:"relative isolate w-full",children:[e.jsx("div",{className:"absolute top-[0%] left-[10%] w-[350px] h-[350px] bg-indigo-500/30 rounded-full blur-[120px] pointer-events-none -z-10"}),e.jsx("div",{className:"absolute bottom-[0%] right-[10%] w-[300px] h-[300px] bg-purple-500/30 rounded-full blur-[120px] pointer-events-none -z-10"}),e.jsx("div",{className:"rounded-[24px] bg-white/5 border border-white/10 shadow-2xl backdrop-blur-3xl p-6 sm:p-8",children:e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-4 gap-4 sm:gap-6",children:[{label:"WINS",value:ee?.wins??0,icon:gt,textColor:"text-rose-400",gradient:"radial-gradient(circle at 10% 90%, rgba(244,63,94,0.35) 0%, transparent 70%)"},{label:"CURRENT STREAK",value:ee?.currentStreak??0,icon:Je,textColor:"text-purple-400",gradient:"radial-gradient(circle at 10% 90%, rgba(168,85,247,0.35) 0%, transparent 70%)"},{label:"AVG ACCURACY",value:`${(ee?.averageAccuracy||0).toFixed(1)}%`,icon:zt,textColor:"text-blue-400",gradient:"radial-gradient(circle at 10% 90%, rgba(59,130,246,0.35) 0%, transparent 70%)"},{label:"AVG RESPONSE",value:Es(ee?.averageResponseMs||0),icon:ra,textColor:"text-teal-400",gradient:"radial-gradient(circle at 10% 90%, rgba(20,184,166,0.35) 0%, transparent 70%)"}].map(t=>e.jsxs("div",{className:"relative overflow-hidden rounded-[20px] bg-white/5 border border-white/10 shadow-lg min-h-[160px] flex flex-col justify-between p-6 transition-transform hover:scale-105",children:[e.jsx("div",{className:"absolute inset-0 pointer-events-none z-0 mix-blend-screen",style:{background:t.gradient}}),e.jsxs("div",{className:"relative z-10",children:[e.jsx("p",{className:u("text-[11px] font-black uppercase tracking-[0.15em] mb-3",t.textColor),children:t.label}),e.jsx("p",{className:"text-4xl sm:text-5xl font-black text-white tabular-nums tracking-tighter drop-shadow-md",children:t.value})]}),e.jsx("div",{className:"relative z-10 mt-6 flex justify-start",children:e.jsx(t.icon,{className:u("h-5 w-5 drop-shadow-md",t.textColor)})})]},t.label))})})]})]},"stats")}),e.jsx(Ne,{value:"leaderboard",className:"mt-0 outline-none",children:e.jsxs(y.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},exit:{opacity:0,y:-12},className:"space-y-4",children:[e.jsxs(y.div,{className:"relative overflow-hidden rounded-[24px] mb-6 bg-white/5 border border-white/10 shadow-2xl backdrop-blur-3xl",whileHover:{scale:1.01},transition:{type:"spring",stiffness:300,damping:20},children:[e.jsx("div",{className:"pointer-events-none absolute inset-0 bg-gradient-to-r from-amber-500/10 via-orange-500/5 to-transparent"}),e.jsx("div",{className:"pointer-events-none absolute -top-24 -right-24 h-64 w-64 rounded-full bg-amber-500/20 blur-3xl animate-orb-pulse"}),e.jsx("div",{className:"pointer-events-none absolute -bottom-12 -left-12 h-40 w-40 rounded-full bg-orange-500/20 blur-2xl animate-orb-pulse-delayed"}),e.jsx("div",{className:"relative z-10 p-6 sm:p-8 flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4",children:e.jsxs("div",{className:"flex items-center gap-5",children:[e.jsx(z,{variant:"ghost",onClick:()=>d("hub"),className:"h-12 w-12 p-0 rounded-full bg-white/10 hover:bg-white/20 hover:scale-105 transition-all backdrop-blur-md border border-white/10 shadow-[0_0_15px_rgba(245,158,11,0.15)] shrink-0",children:e.jsx(Ue,{className:"h-6 w-6 rotate-180 text-amber-300"})}),e.jsxs("div",{children:[e.jsxs("h2",{className:"flex items-center gap-3 text-3xl sm:text-4xl font-black tracking-tight text-white drop-shadow-md",children:[e.jsx(y.div,{animate:{scale:[1,1.1,1]},transition:{duration:2,repeat:1/0,ease:"easeInOut"},className:"bg-amber-500/20 p-2 rounded-2xl shadow-inner border border-amber-500/30",children:e.jsx(ea,{className:"h-8 w-8 text-amber-400 drop-shadow-[0_0_12px_rgba(245,158,11,0.8)]"})}),"Hall of Fame"]}),e.jsx("p",{className:"text-[12px] font-black text-white/60 mt-2 tracking-[0.1em] uppercase",children:"The top-ranked minds across the globe."})]})]})})]}),e.jsxs("div",{className:"relative isolate w-full",children:[e.jsx("div",{className:"absolute top-[20%] left-[20%] w-[400px] h-[400px] bg-orange-500/20 rounded-full blur-[120px] pointer-events-none -z-10"}),e.jsx("div",{className:"absolute bottom-[-10%] right-[-10%] w-[350px] h-[350px] bg-pink-500/20 rounded-full blur-[120px] pointer-events-none -z-10"}),e.jsxs("div",{className:"rounded-[24px] bg-white/5 border border-white/10 shadow-2xl backdrop-blur-3xl p-6 sm:p-8",children:[e.jsxs("div",{className:"mb-8 flex items-start gap-3",children:[e.jsx(ea,{className:"h-8 w-8 text-amber-400 drop-shadow-[0_0_12px_rgba(245,158,11,0.6)] shrink-0"}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-xl font-black text-white tracking-wide leading-none drop-shadow-md",children:"Hall of Fame"}),e.jsx("p",{className:"text-sm font-semibold text-white/60 mt-2",children:"Student-only ranking using trusted backend aggregates."})]})]}),Ba?e.jsxs("div",{className:"space-y-4",children:[e.jsx(xe,{className:"h-[80px] w-full rounded-2xl bg-white/5 border border-white/10"}),e.jsx(xe,{className:"h-[80px] w-full rounded-2xl bg-white/5 border border-white/10"}),e.jsx(xe,{className:"h-[80px] w-full rounded-2xl bg-white/5 border border-white/10"})]}):Xt.length===0?e.jsx("p",{className:"text-sm text-white/50",children:"No leaderboard entries yet. Finish a battle to place on the board."}):e.jsx("div",{className:"space-y-6",children:e.jsx("div",{className:"space-y-3",children:Xt.map(t=>e.jsxs("div",{className:u("relative overflow-hidden rounded-[20px] p-5 flex items-center justify-between shadow-lg transition-all hover:scale-[1.01] group",t.isSelf?"bg-amber-500/10 border border-amber-500/40 shadow-[0_0_20px_rgba(245,158,11,0.15)]":"bg-white/5 border border-white/10 hover:bg-white/10"),children:[t.isSelf&&e.jsx("div",{className:"absolute inset-0 bg-gradient-to-r from-amber-500/20 to-transparent pointer-events-none -z-10"}),e.jsxs("div",{className:"relative z-10 flex flex-col gap-1.5",children:[e.jsxs("h4",{className:u("text-lg sm:text-xl font-black drop-shadow-md",t.isSelf?"text-amber-400":"text-white"),children:["#",t.rank," ",t.displayName,t.isSelf?" (You)":""]}),e.jsxs("p",{className:"text-[13px] font-bold text-white/60",children:["Win rate ",t.winRate.toFixed(1),"% ",e.jsx("span",{className:"mx-1",children:"•"})," Best streak ",t.bestStreak]})]}),e.jsx("div",{className:"relative z-10 text-xl sm:text-2xl font-black text-white tabular-nums drop-shadow-md",children:t.scoreLabel})]},t.userId))})})]})]})]},"leaderboard")})]})})})})]})};export{ur as default}; diff --git a/assets/RewardsModal-wGM2jgcg.js b/assets/RewardsModal-C2mMOy8T.js similarity index 99% rename from assets/RewardsModal-wGM2jgcg.js rename to assets/RewardsModal-C2mMOy8T.js index a2f39463762759a80c11f18620d8b4c4948f5fa4..f7d9e4e5500e544317170eb26a686fe203b133df 100644 --- a/assets/RewardsModal-wGM2jgcg.js +++ b/assets/RewardsModal-C2mMOy8T.js @@ -1 +1 @@ -import{r as i,j as e}from"./vendor-react-B4AQeu28.js";import{getDoc as F,doc as S}from"./vendor-firebase-firestore-CNv3xXal.js";import{aR as g,A as u,aS as U,aT as P,U as $,H as B,i as R,D as I,a1 as T,T as j,aU as q,a6 as N,R as H,V as L,a2 as M,$ as v,a7 as w,B as G,Z as X,r as V,F as Z,G as K,b as Q,aK as W,g as J}from"./index-BufUS6SI.js";import{X as O}from"./x-BuBjuj2Y.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-radix-C5nwdvGr.js";import"./vendor-charts-CAmziV1y.js";import"./vendor-markdown-yqZQ_iQm.js";const Y={BookOpen:Q,GraduationCap:K,Trophy:Z,Target:V,Zap:X,Brain:G,Star:w,Flame:v,Swords:M,Shield:L,RefreshCw:H,Crown:N,Sun:q,TrendingUp:j,Globe:T,User:I,UserPlus:R,Calendar:B,Users:$,Compass:P,Heart:U,Award:u},me=({isOpen:o,onClose:c,userLevel:n,currentXP:x,xpToNextLevel:m,totalXP:p,userId:d})=>{const[y,b]=i.useState(!0),[k,_]=i.useState(new Set),[E,C]=i.useState({});i.useEffect(()=>{if(!o||!d)return;(async()=>{b(!0);try{const t=await W(d);_(new Set(t.map(a=>a.id)));const l=await F(S(J,"progress",d));l.exists()&&C(l.data())}catch(t){console.error("Error loading achievements:",t)}finally{b(!1)}})()},[o,d]);const D=s=>{const{condition:t,threshold:l}=s,a=E;let r=0,f=l??1;switch(t){case"lesson_complete":r=a.totalLessonsCompleted||0;break;case"quiz_complete":r=a.totalQuizzesCompleted||0;break;case"battle_win":case"battle_undefeated":r=a.battleWins||0;break;case"mastery_10":case"social_streak_30":case"social_daily_return":r=a.consecutiveDaysActive||0;break;case"mastery_xp":r=p;break;case"explore_friend_added":case"social_friend":case"explore_social":r=a.friendsAdded||0;break;case"perfect_score":{r=(a.quizAttempts||[]).filter(z=>z.score===100).length;break}default:return}return{progress:Math.min(r,f),total:f}},h=g.map(s=>{const t=Y[s.icon.name]??u,l=k.has(s.id),a=D(s);return{id:s.id,icon:t,title:s.title,description:s.description,progress:a?.progress,total:a?.total,unlocked:l,color:l?s.iconColor:"text-slate-500",bgColor:l?s.iconColor.replace("text-","bg-").replace("-500","/10").replace("-400","/10").replace("-600","/10"):"bg-slate-100"}}),A=h.filter(s=>s.unlocked).length;return o?e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-2 sm:p-8",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm",onClick:c}),e.jsxs("div",{className:"relative bg-[#f7f9fc] rounded-2xl shadow-2xl border border-[#dde3eb] w-full max-w-2xl max-h-[90vh] sm:max-h-[85vh] flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"bg-gradient-to-r from-[#9956DE] via-[#7274ED] to-[#1FA7E1] p-4 md:p-6 text-white relative flex-shrink-0",children:[e.jsx("div",{className:"absolute inset-0 bg-[radial-gradient(circle_at_14%_12%,rgba(251,150,187,0.35),transparent_42%),radial-gradient(circle_at_80%_80%,rgba(117,208,106,0.25),transparent_38%)]"}),e.jsxs("div",{className:"flex items-center justify-between mb-4 relative z-10",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl md:text-2xl font-display font-bold",children:"Rewards & Achievements"}),e.jsxs("p",{className:"text-white/90 text-sm font-body",children:[A," / ",g.length," Achievements Unlocked"]})]}),e.jsx("button",{onClick:c,className:"text-white/90 hover:text-white hover:bg-white/20 p-2 rounded-xl transition-colors",children:e.jsx(O,{size:24})})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 md:gap-3 relative z-10",children:[e.jsxs("div",{className:"bg-white/15 backdrop-blur-sm rounded-xl p-3 md:p-4 border border-white/25",children:[e.jsxs("div",{className:"flex items-center gap-1 md:gap-2 mb-1",children:[e.jsx(N,{size:16,className:"text-[#FFB356]"}),e.jsx("span",{className:"text-[10px] md:text-xs font-medium text-white/90 font-body",children:"Level"})]}),e.jsx("p",{className:"text-xl md:text-2xl font-bold",children:n})]}),e.jsxs("div",{className:"bg-white/15 backdrop-blur-sm rounded-xl p-3 md:p-4 border border-white/25",children:[e.jsxs("div",{className:"flex items-center gap-1 md:gap-2 mb-1",children:[e.jsx(w,{size:16,className:"text-[#6ED1CF]"}),e.jsx("span",{className:"text-[10px] md:text-xs font-medium text-white/90 font-body",children:"Total XP"})]}),e.jsx("p",{className:"text-xl md:text-2xl font-bold",children:p.toLocaleString()})]}),e.jsxs("div",{className:"bg-white/15 backdrop-blur-sm rounded-xl p-3 md:p-4 border border-white/25",children:[e.jsxs("div",{className:"flex items-center gap-1 md:gap-2 mb-1",children:[e.jsx(v,{size:16,className:"text-[#FF8B8B]"}),e.jsx("span",{className:"text-[10px] md:text-xs font-medium text-white/90 font-body",children:"Daily Rewards"})]}),e.jsx("p",{className:"text-xl md:text-2xl font-bold",children:"Check-in"})]})]}),e.jsxs("div",{className:"mt-4 relative z-10",children:[e.jsxs("div",{className:"flex justify-between items-center mb-2",children:[e.jsxs("span",{className:"text-sm font-bold text-white font-body",children:["Level ",n]}),e.jsxs("span",{className:"text-sm font-bold text-white font-body",children:["Level ",n+1]})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"flex justify-between items-center mb-1",children:e.jsxs("span",{className:"text-xs text-white/90",children:[x," / ",m," XP"]})}),e.jsx("div",{className:"h-3 bg-white/20 rounded-full overflow-hidden border border-white/20",children:e.jsx("div",{className:"h-full bg-gradient-to-r from-[#6ED1CF] via-[#75D06A] to-[#FFB356] rounded-full transition-all duration-500 e-w",style:{"--w":`${x/m*100}%`}})})]})]})]}),e.jsx("div",{className:"p-4 md:p-6 overflow-y-auto flex-1",children:y?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx("div",{className:"animate-spin w-8 h-8 border-2 border-[#9956DE] border-t-transparent rounded-full"})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h3",{className:"text-lg font-display font-bold text-[#0a1628] mb-4",children:"Achievements"}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:h.map(s=>{const t=s.icon;return e.jsx("div",{className:`${s.unlocked?"bg-white border-[#9956DE]/25":"bg-[#edf1f7] border-[#dde3eb]"} border-2 rounded-xl p-4 transition-all ${s.unlocked?"shadow-md":"opacity-60"}`,children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:`w-12 h-12 ${s.bgColor} rounded-xl flex items-center justify-center flex-shrink-0`,children:e.jsx(t,{size:24,className:s.color})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("h4",{className:`text-sm font-bold ${s.unlocked?"text-[#0a1628]":"text-slate-500"} font-body`,children:s.title}),s.unlocked&&e.jsx("span",{className:"px-2 py-0.5 bg-[#75D06A] text-white text-[9px] font-bold rounded-full",children:"Unlocked"})]}),e.jsx("p",{className:`text-xs ${s.unlocked?"text-[#5a6578]":"text-slate-500"} mb-2`,children:s.description}),s.progress!==void 0&&s.total!==void 0&&!s.unlocked&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-center mb-1",children:[e.jsx("span",{className:"text-[10px] text-slate-500",children:"Progress"}),e.jsxs("span",{className:"text-[10px] font-bold text-[#5a6578]",children:[s.progress," / ",s.total]})]}),e.jsx("div",{className:"h-1.5 bg-[#dde3eb] rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-gradient-to-r from-[#7274ED] to-[#1FA7E1] rounded-full transition-all e-w",style:{"--w":`${s.progress/s.total*100}%`}})})]})]})]})},s.id)})})]}),e.jsxs("div",{className:"bg-white rounded-xl p-5 border border-[#dde3eb]",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx("div",{className:"w-8 h-8 bg-gradient-to-br from-[#7274ED] to-[#1FA7E1] rounded-lg flex items-center justify-center",children:e.jsx(j,{size:16,className:"text-white"})}),e.jsx("h3",{className:"text-base font-display font-bold text-[#0a1628]",children:"How to Earn XP"})]}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2",children:[{activity:"Complete a video lesson",xp:50},{activity:"Complete exercises",xp:100},{activity:"Perfect quiz score",xp:150},{activity:"Finish a quiz",xp:75},{activity:"Daily check-in",xp:"20-100"}].map((s,t)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-1.5 h-1.5 bg-[#1FA7E1] rounded-full"}),e.jsxs("span",{className:"text-xs text-[#5a6578] font-body",children:[s.activity,":"]}),e.jsxs("span",{className:"text-xs font-bold text-[#7274ED]",children:["+",s.xp," XP"]})]},t))})]})]})})]})]}):null};export{me as default}; +import{r as i,j as e}from"./vendor-react-B4AQeu28.js";import{getDoc as F,doc as S}from"./vendor-firebase-firestore-CNv3xXal.js";import{aR as g,A as u,aS as U,aT as P,U as $,H as B,i as R,D as I,a1 as T,T as j,aU as q,a6 as N,R as H,V as L,a2 as M,$ as v,a7 as w,B as G,Z as X,r as V,F as Z,G as K,b as Q,aK as W,g as J}from"./index-Bp7MiGcW.js";import{X as O}from"./x-k8d6VLEw.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-radix-C5nwdvGr.js";import"./vendor-charts-CAmziV1y.js";import"./vendor-markdown-yqZQ_iQm.js";const Y={BookOpen:Q,GraduationCap:K,Trophy:Z,Target:V,Zap:X,Brain:G,Star:w,Flame:v,Swords:M,Shield:L,RefreshCw:H,Crown:N,Sun:q,TrendingUp:j,Globe:T,User:I,UserPlus:R,Calendar:B,Users:$,Compass:P,Heart:U,Award:u},me=({isOpen:o,onClose:c,userLevel:n,currentXP:x,xpToNextLevel:m,totalXP:p,userId:d})=>{const[y,b]=i.useState(!0),[k,_]=i.useState(new Set),[E,C]=i.useState({});i.useEffect(()=>{if(!o||!d)return;(async()=>{b(!0);try{const t=await W(d);_(new Set(t.map(a=>a.id)));const l=await F(S(J,"progress",d));l.exists()&&C(l.data())}catch(t){console.error("Error loading achievements:",t)}finally{b(!1)}})()},[o,d]);const D=s=>{const{condition:t,threshold:l}=s,a=E;let r=0,f=l??1;switch(t){case"lesson_complete":r=a.totalLessonsCompleted||0;break;case"quiz_complete":r=a.totalQuizzesCompleted||0;break;case"battle_win":case"battle_undefeated":r=a.battleWins||0;break;case"mastery_10":case"social_streak_30":case"social_daily_return":r=a.consecutiveDaysActive||0;break;case"mastery_xp":r=p;break;case"explore_friend_added":case"social_friend":case"explore_social":r=a.friendsAdded||0;break;case"perfect_score":{r=(a.quizAttempts||[]).filter(z=>z.score===100).length;break}default:return}return{progress:Math.min(r,f),total:f}},h=g.map(s=>{const t=Y[s.icon.name]??u,l=k.has(s.id),a=D(s);return{id:s.id,icon:t,title:s.title,description:s.description,progress:a?.progress,total:a?.total,unlocked:l,color:l?s.iconColor:"text-slate-500",bgColor:l?s.iconColor.replace("text-","bg-").replace("-500","/10").replace("-400","/10").replace("-600","/10"):"bg-slate-100"}}),A=h.filter(s=>s.unlocked).length;return o?e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-2 sm:p-8",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm",onClick:c}),e.jsxs("div",{className:"relative bg-[#f7f9fc] rounded-2xl shadow-2xl border border-[#dde3eb] w-full max-w-2xl max-h-[90vh] sm:max-h-[85vh] flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"bg-gradient-to-r from-[#9956DE] via-[#7274ED] to-[#1FA7E1] p-4 md:p-6 text-white relative flex-shrink-0",children:[e.jsx("div",{className:"absolute inset-0 bg-[radial-gradient(circle_at_14%_12%,rgba(251,150,187,0.35),transparent_42%),radial-gradient(circle_at_80%_80%,rgba(117,208,106,0.25),transparent_38%)]"}),e.jsxs("div",{className:"flex items-center justify-between mb-4 relative z-10",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl md:text-2xl font-display font-bold",children:"Rewards & Achievements"}),e.jsxs("p",{className:"text-white/90 text-sm font-body",children:[A," / ",g.length," Achievements Unlocked"]})]}),e.jsx("button",{onClick:c,className:"text-white/90 hover:text-white hover:bg-white/20 p-2 rounded-xl transition-colors",children:e.jsx(O,{size:24})})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 md:gap-3 relative z-10",children:[e.jsxs("div",{className:"bg-white/15 backdrop-blur-sm rounded-xl p-3 md:p-4 border border-white/25",children:[e.jsxs("div",{className:"flex items-center gap-1 md:gap-2 mb-1",children:[e.jsx(N,{size:16,className:"text-[#FFB356]"}),e.jsx("span",{className:"text-[10px] md:text-xs font-medium text-white/90 font-body",children:"Level"})]}),e.jsx("p",{className:"text-xl md:text-2xl font-bold",children:n})]}),e.jsxs("div",{className:"bg-white/15 backdrop-blur-sm rounded-xl p-3 md:p-4 border border-white/25",children:[e.jsxs("div",{className:"flex items-center gap-1 md:gap-2 mb-1",children:[e.jsx(w,{size:16,className:"text-[#6ED1CF]"}),e.jsx("span",{className:"text-[10px] md:text-xs font-medium text-white/90 font-body",children:"Total XP"})]}),e.jsx("p",{className:"text-xl md:text-2xl font-bold",children:p.toLocaleString()})]}),e.jsxs("div",{className:"bg-white/15 backdrop-blur-sm rounded-xl p-3 md:p-4 border border-white/25",children:[e.jsxs("div",{className:"flex items-center gap-1 md:gap-2 mb-1",children:[e.jsx(v,{size:16,className:"text-[#FF8B8B]"}),e.jsx("span",{className:"text-[10px] md:text-xs font-medium text-white/90 font-body",children:"Daily Rewards"})]}),e.jsx("p",{className:"text-xl md:text-2xl font-bold",children:"Check-in"})]})]}),e.jsxs("div",{className:"mt-4 relative z-10",children:[e.jsxs("div",{className:"flex justify-between items-center mb-2",children:[e.jsxs("span",{className:"text-sm font-bold text-white font-body",children:["Level ",n]}),e.jsxs("span",{className:"text-sm font-bold text-white font-body",children:["Level ",n+1]})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"flex justify-between items-center mb-1",children:e.jsxs("span",{className:"text-xs text-white/90",children:[x," / ",m," XP"]})}),e.jsx("div",{className:"h-3 bg-white/20 rounded-full overflow-hidden border border-white/20",children:e.jsx("div",{className:"h-full bg-gradient-to-r from-[#6ED1CF] via-[#75D06A] to-[#FFB356] rounded-full transition-all duration-500 e-w",style:{"--w":`${x/m*100}%`}})})]})]})]}),e.jsx("div",{className:"p-4 md:p-6 overflow-y-auto flex-1",children:y?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx("div",{className:"animate-spin w-8 h-8 border-2 border-[#9956DE] border-t-transparent rounded-full"})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h3",{className:"text-lg font-display font-bold text-[#0a1628] mb-4",children:"Achievements"}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:h.map(s=>{const t=s.icon;return e.jsx("div",{className:`${s.unlocked?"bg-white border-[#9956DE]/25":"bg-[#edf1f7] border-[#dde3eb]"} border-2 rounded-xl p-4 transition-all ${s.unlocked?"shadow-md":"opacity-60"}`,children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:`w-12 h-12 ${s.bgColor} rounded-xl flex items-center justify-center flex-shrink-0`,children:e.jsx(t,{size:24,className:s.color})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("h4",{className:`text-sm font-bold ${s.unlocked?"text-[#0a1628]":"text-slate-500"} font-body`,children:s.title}),s.unlocked&&e.jsx("span",{className:"px-2 py-0.5 bg-[#75D06A] text-white text-[9px] font-bold rounded-full",children:"Unlocked"})]}),e.jsx("p",{className:`text-xs ${s.unlocked?"text-[#5a6578]":"text-slate-500"} mb-2`,children:s.description}),s.progress!==void 0&&s.total!==void 0&&!s.unlocked&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-center mb-1",children:[e.jsx("span",{className:"text-[10px] text-slate-500",children:"Progress"}),e.jsxs("span",{className:"text-[10px] font-bold text-[#5a6578]",children:[s.progress," / ",s.total]})]}),e.jsx("div",{className:"h-1.5 bg-[#dde3eb] rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-gradient-to-r from-[#7274ED] to-[#1FA7E1] rounded-full transition-all e-w",style:{"--w":`${s.progress/s.total*100}%`}})})]})]})]})},s.id)})})]}),e.jsxs("div",{className:"bg-white rounded-xl p-5 border border-[#dde3eb]",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx("div",{className:"w-8 h-8 bg-gradient-to-br from-[#7274ED] to-[#1FA7E1] rounded-lg flex items-center justify-center",children:e.jsx(j,{size:16,className:"text-white"})}),e.jsx("h3",{className:"text-base font-display font-bold text-[#0a1628]",children:"How to Earn XP"})]}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2",children:[{activity:"Complete a video lesson",xp:50},{activity:"Complete exercises",xp:100},{activity:"Perfect quiz score",xp:150},{activity:"Finish a quiz",xp:75},{activity:"Daily check-in",xp:"20-100"}].map((s,t)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-1.5 h-1.5 bg-[#1FA7E1] rounded-full"}),e.jsxs("span",{className:"text-xs text-[#5a6578] font-body",children:[s.activity,":"]}),e.jsxs("span",{className:"text-xs font-bold text-[#7274ED]",children:["+",s.xp," XP"]})]},t))})]})]})})]})]}):null};export{me as default}; diff --git a/assets/RightSidebar-DiW3T5Yf.js b/assets/RightSidebar-D6kbBdAu.js similarity index 98% rename from assets/RightSidebar-DiW3T5Yf.js rename to assets/RightSidebar-D6kbBdAu.js index ec4698ad038bd55280aca7136a551da3cd143bdc..7266c495c94406392d14863bd5d9389db45bc33c 100644 --- a/assets/RightSidebar-DiW3T5Yf.js +++ b/assets/RightSidebar-D6kbBdAu.js @@ -1 +1 @@ -import{r as o,j as e}from"./vendor-react-B4AQeu28.js";import{q as S}from"./quiz_battle_avatar-BXHPSput.js";import{h as q,m as c,Z as _,a2 as B,a5 as P,F as W,a6 as v,a7 as X,q as Y,D as k}from"./index-BufUS6SI.js";import{C as M}from"./circle-check-big-CDg2qLfH.js";import{T as O,a as Z,b as H}from"./tooltip-qcWo8nUO.js";import{C as T}from"./chevron-right-DADygX42.js";import"./vendor-firebase-firestore-CNv3xXal.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-radix-C5nwdvGr.js";import"./vendor-charts-CAmziV1y.js";import"./vendor-markdown-yqZQ_iQm.js";const E=[{id:1,title:"Quiz Battle",subtitle:"Challenge players worldwide!",bgColor:"bg-[#9956de]",orbColor:"bg-[#6D28D9]",icon:e.jsx(B,{size:24,className:"text-white"}),buttonText:"Join Battle",actionType:"quiz-battle",avatarText:"Waiting for you to join..."},{id:2,title:"Topic Explorer",subtitle:"Dive into a new math topic today",bgColor:"bg-[#FF8B8B]",orbColor:"bg-[#E06A6A]",icon:e.jsx(_,{size:24,className:"text-white"}),buttonText:"Explore",actionType:"explore",avatarText:"Knowledge is power!"},{id:3,title:"Speed Runner",subtitle:"Finish a quiz in under 5 mins",bgColor:"bg-[#75D06A]",orbColor:"bg-[#58B34D]",icon:e.jsx(M,{size:24,className:"text-white"}),buttonText:null,actionType:null,avatarText:"Ready for action!"}],J=({onNavigateToQuizBattle:s,userPhoto:a})=>{const[x,m]=o.useState(0);o.useEffect(()=>{const r=setInterval(()=>{m(l=>(l+1)%E.length)},5e3);return()=>clearInterval(r)},[]);const t=E[x];return e.jsx("div",{className:"bg-white rounded-[24px] p-4 shadow-sm border border-slate-100 flex flex-col gap-6 mt-4 relative overflow-hidden",children:e.jsx("div",{className:"relative h-[185px] rounded-[-20px] rounded-2xl overflow-hidden cursor-pointer group",children:e.jsx(q,{mode:"wait",children:e.jsxs(c.div,{initial:{opacity:0,x:20},animate:{opacity:1,x:0},exit:{opacity:0,x:-20},transition:{duration:.3},className:`absolute inset-0 ${t.bgColor} p-4 sm:p-5 flex flex-col justify-between overflow-hidden`,children:[e.jsxs("div",{className:"absolute top-4 right-4 flex gap-1 items-center z-20",children:[e.jsx("div",{className:"w-3 h-1.5 rounded-full bg-white/60"}),e.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-white/40"}),e.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-white/40"})]}),t.actionType==="quiz-battle"&&e.jsx("div",{className:"absolute -right-4 -bottom-6 w-32 h-32 opacity-25 mix-blend-overlay pointer-events-none z-0 transform group-hover:scale-105 transition-transform duration-700",children:e.jsx("img",{src:S,alt:"",className:"w-full h-full object-contain"})}),e.jsx("div",{className:`absolute -right-4 -top-8 w-36 h-36 rounded-full ${t.orbColor} opacity-90 blur-2xl group-hover:scale-110 transition-transform duration-700 pointer-events-none`}),e.jsx("div",{className:"absolute right-4 top-1/2 -translate-y-1/2 w-[48px] h-[48px] rounded-2xl rotate-12 bg-white/20 backdrop-blur-md shadow-sm border border-white/20 group-hover:rotate-[25deg] group-hover:scale-110 transition-transform duration-700 flex items-center justify-center z-10",children:t.icon}),e.jsxs("div",{className:"relative z-10 w-full pr-[60px]",children:[e.jsx("h3",{className:"font-display font-bold text-[20px] leading-tight text-white mb-0.5",children:t.title}),e.jsx("p",{className:"text-[12px] font-medium text-white/90 leading-snug",children:t.subtitle}),t.buttonText&&e.jsx("button",{onClick:r=>{r.stopPropagation(),t.actionType==="quiz-battle"&&s&&s()},className:"mt-2.5 bg-white text-[#0a1628] px-2 py-1 rounded-lg font-bold text-xs shadow-sm hover:scale-105 transition-transform uppercase tracking-wider whitespace-nowrap w-fit",children:t.buttonText})]}),e.jsxs("div",{className:"flex items-center gap-2.5 relative z-10 mt-auto pt-2",children:[a?e.jsxs("div",{className:"relative group/avatar shrink-0",children:[e.jsx("div",{className:"absolute inset-0 bg-white/40 blur-md rounded-full animate-pulse"}),e.jsx("img",{src:a,alt:"You",className:"w-8 h-8 rounded-full border-[2px] border-white object-cover relative z-10 shadow-md group-hover/avatar:scale-110 transition-transform"}),t.actionType==="quiz-battle"&&e.jsx("div",{className:"absolute -bottom-1 -right-1 w-[16px] h-[16px] bg-[#75D06A] border-2 border-[#7C3AED] rounded-full z-20 flex items-center justify-center",children:e.jsx(_,{size:8,className:"text-white",fill:"currentColor"})})]}):null,e.jsx("span",{className:"text-[12px] font-bold text-white tracking-wide leading-tight flex-1 pr-[60px]",children:t.avatarText})]})]},t.id)})})})},K=s=>{if(s>=1e3){const a=s/1e3;return a>=10?`${Math.round(a)}k`:`${a.toFixed(1)}k`}return`${s}`},G=({entry:s,rank:a,isYou:x,userPhoto:m,rankColor:t})=>{const r=x?s?.photo||m:s?.photo,l=x?"You":s?.name||"---",h=s?.xp||0;return e.jsxs(e.Fragment,{children:[e.jsxs(c.div,{initial:{y:20,opacity:0},animate:{y:0,opacity:1},transition:{delay:.3+a*.1},className:"relative mb-2",children:[a===1&&e.jsx("div",{className:"absolute -top-4 left-1/2 -translate-x-1/2 z-20",children:e.jsx(v,{size:22,className:"text-amber-400 drop-shadow-md mb-1",fill:"#fbbf24",strokeWidth:1.5})}),e.jsx("div",{className:`w-10 h-10 rounded-full border-[3px] ${a===1?"w-[52px] h-[52px]":""} ${t.border} z-10 relative overflow-hidden ${t.shadow} bg-white`,children:r?e.jsx("img",{src:r,alt:l,className:"w-full h-full object-cover",onError:f=>{f.target.style.display="none"}}):e.jsx("div",{className:"w-full h-full bg-gradient-to-br from-slate-200 to-slate-300 flex items-center justify-center",children:e.jsx(k,{size:a===1?22:16,className:"text-slate-400"})})}),e.jsx("div",{className:`absolute -bottom-2 left-1/2 -translate-x-1/2 ${t.badge} text-white text-[10px] font-bold px-2 py-0.5 rounded-full z-20 shadow-sm`,children:a})]}),e.jsxs("div",{className:"mt-2 text-center",children:[e.jsx("span",{className:`block ${a===1?"text-[13px] font-black":"text-[12px] font-bold"} text-[#0a1628] truncate max-w-[80px]`,children:l}),e.jsxs("span",{className:`block ${a===1?"text-[11px]":"text-[10px]"} ${t.badge.replace("bg-","text-").replace("-500","-600").replace("-400","-600").replace("amber","amber")} font-bold`,children:[K(h)," XP"]})]})]})},ce=({currentUserId:s,onOpenRewards:a,onOpenLeaderboard:x,onNavigateToModules:m,onNavigateToQuizBattle:t,userLevel:r,userPhoto:l,currentXP:h,xpToNextLevel:f})=>{const N=h/f*100,[$,D]=o.useState([]),[F,u]=o.useState(!0),[y,g]=o.useState(null),p=o.useRef(null),n=o.useRef(null);o.useEffect(()=>{if(!s){u(!1);return}u(!0),g(null);const d=P(b=>{D(b),u(!1),g(null),n.current&&(clearTimeout(n.current),n.current=null)},s,!1,"all",3);return p.current=d,n.current=setTimeout(()=>{u(!1),g("Leaderboard data unavailable")},15e3),()=>{n.current&&(clearTimeout(n.current),n.current=null),p.current&&(p.current(),p.current=null)}},[s]);const i=$.slice(0,3);i.some(d=>d.userId===s);const z=[{bg:"from-amber-100 to-amber-50",border:"border-amber-400",badge:"bg-amber-500",shadow:"shadow-md"},{bg:"from-slate-200 to-slate-100",border:"border-sky-400",badge:"bg-sky-500",shadow:"shadow-sm"},{bg:"from-orange-50 to-slate-50",border:"border-orange-400",badge:"bg-orange-500",shadow:"shadow-sm"}],A=["74px","54px","38px"],L=["w-[78px]","w-[70px]","w-[70px]"],w=(d,b,C,R,j)=>e.jsxs("div",{className:"flex flex-col items-center relative z-10",children:[e.jsx(G,{entry:d,rank:C,isYou:R==="You",userPhoto:l,rankColor:z[j]}),e.jsxs(c.div,{initial:{height:0},animate:{height:A[b]},transition:{delay:.2+b*.1,duration:.5,ease:"easeOut"},className:`${L[b]} bg-gradient-to-b ${z[j].bg} rounded-t-xl rounded-b-md border-t-2 border-white/20 flex items-center justify-center relative shadow-[inset_0_-4px_6px_rgba(0,0,0,0.05),0_4px_6px_rgba(0,0,0,0.05)]`,children:[e.jsx("span",{className:`${j===0?"text-amber-400 text-3xl":"text-slate-400 text-2xl"} font-black opacity-40 translate-y-1`,children:C}),e.jsx("div",{className:"absolute top-0 left-0 right-0 h-1.5 bg-white/70 rounded-t-xl"})]})]});return e.jsxs("div",{className:"space-y-2.5",children:[e.jsxs(c.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{delay:.1,duration:.4,ease:[.22,1,.36,1]},onClick:a,className:"rounded-2xl border border-[#9956DE]/25 cursor-pointer transition-all group relative overflow-hidden bg-gradient-to-br from-[#9956DE] via-[#7274ED] to-[#1FA7E1] hover:shadow-[0_16px_40px_rgba(114,116,237,0.28)] hover:-translate-y-0.5",children:[e.jsx("div",{className:"absolute inset-0 bg-[radial-gradient(circle_at_18%_8%,rgba(251,150,187,0.32),transparent_42%),radial-gradient(circle_at_85%_84%,rgba(117,208,106,0.24),transparent_40%)]"}),e.jsxs("div",{className:"relative z-10 p-3",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"shrink-0 w-8 h-8 bg-white/20 rounded-xl flex items-center justify-center border border-white/35 backdrop-blur-sm",children:e.jsx(W,{size:14,className:"text-white"})}),e.jsxs("h3",{className:"font-display font-bold text-[13px] leading-tight text-white tracking-wide",children:["Rewards & ",e.jsx("br",{className:"hidden 2xl:block"})," Achievements"]})]}),e.jsx(T,{size:14,className:"shrink-0 text-white/80 group-hover:text-white group-hover:translate-x-0.5 transition-all"})]}),e.jsxs("div",{className:"flex items-center justify-between gap-1 mb-3 bg-white/10 p-1.5 rounded-xl border border-white/20 backdrop-blur-sm",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-body px-1 text-white",children:[e.jsx(v,{size:12,className:"text-[#FFB356]"}),e.jsxs("span",{className:"font-bold",children:["Lv ",r]})]}),e.jsx("div",{className:"w-px h-3 bg-white/35"}),e.jsxs(O,{children:[e.jsx(Z,{asChild:!0,children:e.jsxs("button",{onClick:d=>{d.stopPropagation(),m?.()},className:"flex items-center gap-1.5 text-xs font-body px-1 text-white cursor-pointer transition-colors active:scale-95",children:[e.jsx(X,{size:12,className:"text-[#6ED1CF]"}),e.jsxs("span",{className:"font-bold whitespace-nowrap",children:[h," XP"]})]})}),e.jsx(H,{side:"top",className:"bg-slate-900 text-white border border-slate-700",children:"Review more lessons to earn more XP!"})]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-center mb-1.5",children:[e.jsxs("span",{className:"text-[11px] font-body text-white/90",children:["Next: Level ",r+1]}),e.jsxs("span",{className:"text-[11px] font-body font-semibold text-white",children:[Math.round(N),"%"]})]}),e.jsx("div",{className:"h-2 bg-white/25 rounded-full overflow-hidden border border-white/20",children:e.jsx(c.div,{initial:{width:0},animate:{width:`${N}%`},transition:{duration:1,ease:"easeOut"},className:"h-full bg-gradient-to-r from-[#6ED1CF] via-[#75D06A] to-[#FFB356] rounded-full"})})]})]})]}),e.jsx(c.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{delay:.2,duration:.4,ease:[.22,1,.36,1]},children:e.jsx(J,{onNavigateToQuizBattle:t,userPhoto:l})}),e.jsxs(c.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{delay:.3,duration:.4,ease:[.22,1,.36,1]},onClick:x,className:"bg-white rounded-xl border border-slate-200/80 hover:shadow-md hover:border-amber-200/60 transition-all group overflow-hidden cursor-pointer",children:[e.jsxs("div",{className:"p-3 border-b border-slate-100 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-7 h-7 bg-amber-50 rounded-lg flex items-center justify-center border border-amber-200/60 transition-colors group-hover:bg-amber-100/50",children:e.jsx(v,{size:14,className:"text-amber-500"})}),e.jsx("h3",{className:"font-display font-bold text-sm text-[#0a1628]",children:"Leaderboards"})]}),e.jsx(T,{size:14,className:"text-slate-400 group-hover:translate-x-0.5 group-hover:text-amber-500 transition-transform"})]}),e.jsx("div",{className:"pt-8 pb-3 px-2 bg-gradient-to-b from-slate-50/30 to-white flex items-end justify-center gap-1.5 min-h-[170px]",children:F?e.jsxs("div",{className:"flex flex-col items-center justify-center h-full py-8",children:[e.jsx(Y,{className:"w-5 h-5 animate-spin text-amber-400 mb-2"}),e.jsx("span",{className:"text-xs text-slate-400",children:"Loading rankings..."})]}):y||i.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center h-full py-8",children:[e.jsx(k,{className:"w-8 h-8 text-slate-300 mb-2"}),e.jsx("span",{className:"text-xs text-slate-400 text-center",children:y||"No rankings available yet"})]}):e.jsxs(e.Fragment,{children:[w(i[1],1,2,i[1]?.name||"---",1),w(i[0],0,1,i[0]?.name||"---",0),w(i[2],2,3,i[2]?.name||"---",2)]})})]})]})};export{ce as default}; +import{r as o,j as e}from"./vendor-react-B4AQeu28.js";import{q as S}from"./quiz_battle_avatar-BXHPSput.js";import{h as q,m as c,Z as _,a2 as B,a5 as P,F as W,a6 as v,a7 as X,q as Y,D as k}from"./index-Bp7MiGcW.js";import{C as M}from"./circle-check-big-JdaMs3bP.js";import{T as O,a as Z,b as H}from"./tooltip-nLNeX3nd.js";import{C as T}from"./chevron-right-BxoysOas.js";import"./vendor-firebase-firestore-CNv3xXal.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-radix-C5nwdvGr.js";import"./vendor-charts-CAmziV1y.js";import"./vendor-markdown-yqZQ_iQm.js";const E=[{id:1,title:"Quiz Battle",subtitle:"Challenge players worldwide!",bgColor:"bg-[#9956de]",orbColor:"bg-[#6D28D9]",icon:e.jsx(B,{size:24,className:"text-white"}),buttonText:"Join Battle",actionType:"quiz-battle",avatarText:"Waiting for you to join..."},{id:2,title:"Topic Explorer",subtitle:"Dive into a new math topic today",bgColor:"bg-[#FF8B8B]",orbColor:"bg-[#E06A6A]",icon:e.jsx(_,{size:24,className:"text-white"}),buttonText:"Explore",actionType:"explore",avatarText:"Knowledge is power!"},{id:3,title:"Speed Runner",subtitle:"Finish a quiz in under 5 mins",bgColor:"bg-[#75D06A]",orbColor:"bg-[#58B34D]",icon:e.jsx(M,{size:24,className:"text-white"}),buttonText:null,actionType:null,avatarText:"Ready for action!"}],J=({onNavigateToQuizBattle:s,userPhoto:a})=>{const[x,m]=o.useState(0);o.useEffect(()=>{const r=setInterval(()=>{m(l=>(l+1)%E.length)},5e3);return()=>clearInterval(r)},[]);const t=E[x];return e.jsx("div",{className:"bg-white rounded-[24px] p-4 shadow-sm border border-slate-100 flex flex-col gap-6 mt-4 relative overflow-hidden",children:e.jsx("div",{className:"relative h-[185px] rounded-[-20px] rounded-2xl overflow-hidden cursor-pointer group",children:e.jsx(q,{mode:"wait",children:e.jsxs(c.div,{initial:{opacity:0,x:20},animate:{opacity:1,x:0},exit:{opacity:0,x:-20},transition:{duration:.3},className:`absolute inset-0 ${t.bgColor} p-4 sm:p-5 flex flex-col justify-between overflow-hidden`,children:[e.jsxs("div",{className:"absolute top-4 right-4 flex gap-1 items-center z-20",children:[e.jsx("div",{className:"w-3 h-1.5 rounded-full bg-white/60"}),e.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-white/40"}),e.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-white/40"})]}),t.actionType==="quiz-battle"&&e.jsx("div",{className:"absolute -right-4 -bottom-6 w-32 h-32 opacity-25 mix-blend-overlay pointer-events-none z-0 transform group-hover:scale-105 transition-transform duration-700",children:e.jsx("img",{src:S,alt:"",className:"w-full h-full object-contain"})}),e.jsx("div",{className:`absolute -right-4 -top-8 w-36 h-36 rounded-full ${t.orbColor} opacity-90 blur-2xl group-hover:scale-110 transition-transform duration-700 pointer-events-none`}),e.jsx("div",{className:"absolute right-4 top-1/2 -translate-y-1/2 w-[48px] h-[48px] rounded-2xl rotate-12 bg-white/20 backdrop-blur-md shadow-sm border border-white/20 group-hover:rotate-[25deg] group-hover:scale-110 transition-transform duration-700 flex items-center justify-center z-10",children:t.icon}),e.jsxs("div",{className:"relative z-10 w-full pr-[60px]",children:[e.jsx("h3",{className:"font-display font-bold text-[20px] leading-tight text-white mb-0.5",children:t.title}),e.jsx("p",{className:"text-[12px] font-medium text-white/90 leading-snug",children:t.subtitle}),t.buttonText&&e.jsx("button",{onClick:r=>{r.stopPropagation(),t.actionType==="quiz-battle"&&s&&s()},className:"mt-2.5 bg-white text-[#0a1628] px-2 py-1 rounded-lg font-bold text-xs shadow-sm hover:scale-105 transition-transform uppercase tracking-wider whitespace-nowrap w-fit",children:t.buttonText})]}),e.jsxs("div",{className:"flex items-center gap-2.5 relative z-10 mt-auto pt-2",children:[a?e.jsxs("div",{className:"relative group/avatar shrink-0",children:[e.jsx("div",{className:"absolute inset-0 bg-white/40 blur-md rounded-full animate-pulse"}),e.jsx("img",{src:a,alt:"You",className:"w-8 h-8 rounded-full border-[2px] border-white object-cover relative z-10 shadow-md group-hover/avatar:scale-110 transition-transform"}),t.actionType==="quiz-battle"&&e.jsx("div",{className:"absolute -bottom-1 -right-1 w-[16px] h-[16px] bg-[#75D06A] border-2 border-[#7C3AED] rounded-full z-20 flex items-center justify-center",children:e.jsx(_,{size:8,className:"text-white",fill:"currentColor"})})]}):null,e.jsx("span",{className:"text-[12px] font-bold text-white tracking-wide leading-tight flex-1 pr-[60px]",children:t.avatarText})]})]},t.id)})})})},K=s=>{if(s>=1e3){const a=s/1e3;return a>=10?`${Math.round(a)}k`:`${a.toFixed(1)}k`}return`${s}`},G=({entry:s,rank:a,isYou:x,userPhoto:m,rankColor:t})=>{const r=x?s?.photo||m:s?.photo,l=x?"You":s?.name||"---",h=s?.xp||0;return e.jsxs(e.Fragment,{children:[e.jsxs(c.div,{initial:{y:20,opacity:0},animate:{y:0,opacity:1},transition:{delay:.3+a*.1},className:"relative mb-2",children:[a===1&&e.jsx("div",{className:"absolute -top-4 left-1/2 -translate-x-1/2 z-20",children:e.jsx(v,{size:22,className:"text-amber-400 drop-shadow-md mb-1",fill:"#fbbf24",strokeWidth:1.5})}),e.jsx("div",{className:`w-10 h-10 rounded-full border-[3px] ${a===1?"w-[52px] h-[52px]":""} ${t.border} z-10 relative overflow-hidden ${t.shadow} bg-white`,children:r?e.jsx("img",{src:r,alt:l,className:"w-full h-full object-cover",onError:f=>{f.target.style.display="none"}}):e.jsx("div",{className:"w-full h-full bg-gradient-to-br from-slate-200 to-slate-300 flex items-center justify-center",children:e.jsx(k,{size:a===1?22:16,className:"text-slate-400"})})}),e.jsx("div",{className:`absolute -bottom-2 left-1/2 -translate-x-1/2 ${t.badge} text-white text-[10px] font-bold px-2 py-0.5 rounded-full z-20 shadow-sm`,children:a})]}),e.jsxs("div",{className:"mt-2 text-center",children:[e.jsx("span",{className:`block ${a===1?"text-[13px] font-black":"text-[12px] font-bold"} text-[#0a1628] truncate max-w-[80px]`,children:l}),e.jsxs("span",{className:`block ${a===1?"text-[11px]":"text-[10px]"} ${t.badge.replace("bg-","text-").replace("-500","-600").replace("-400","-600").replace("amber","amber")} font-bold`,children:[K(h)," XP"]})]})]})},ce=({currentUserId:s,onOpenRewards:a,onOpenLeaderboard:x,onNavigateToModules:m,onNavigateToQuizBattle:t,userLevel:r,userPhoto:l,currentXP:h,xpToNextLevel:f})=>{const N=h/f*100,[$,D]=o.useState([]),[F,u]=o.useState(!0),[y,g]=o.useState(null),p=o.useRef(null),n=o.useRef(null);o.useEffect(()=>{if(!s){u(!1);return}u(!0),g(null);const d=P(b=>{D(b),u(!1),g(null),n.current&&(clearTimeout(n.current),n.current=null)},s,!1,"all",3);return p.current=d,n.current=setTimeout(()=>{u(!1),g("Leaderboard data unavailable")},15e3),()=>{n.current&&(clearTimeout(n.current),n.current=null),p.current&&(p.current(),p.current=null)}},[s]);const i=$.slice(0,3);i.some(d=>d.userId===s);const z=[{bg:"from-amber-100 to-amber-50",border:"border-amber-400",badge:"bg-amber-500",shadow:"shadow-md"},{bg:"from-slate-200 to-slate-100",border:"border-sky-400",badge:"bg-sky-500",shadow:"shadow-sm"},{bg:"from-orange-50 to-slate-50",border:"border-orange-400",badge:"bg-orange-500",shadow:"shadow-sm"}],A=["74px","54px","38px"],L=["w-[78px]","w-[70px]","w-[70px]"],w=(d,b,C,R,j)=>e.jsxs("div",{className:"flex flex-col items-center relative z-10",children:[e.jsx(G,{entry:d,rank:C,isYou:R==="You",userPhoto:l,rankColor:z[j]}),e.jsxs(c.div,{initial:{height:0},animate:{height:A[b]},transition:{delay:.2+b*.1,duration:.5,ease:"easeOut"},className:`${L[b]} bg-gradient-to-b ${z[j].bg} rounded-t-xl rounded-b-md border-t-2 border-white/20 flex items-center justify-center relative shadow-[inset_0_-4px_6px_rgba(0,0,0,0.05),0_4px_6px_rgba(0,0,0,0.05)]`,children:[e.jsx("span",{className:`${j===0?"text-amber-400 text-3xl":"text-slate-400 text-2xl"} font-black opacity-40 translate-y-1`,children:C}),e.jsx("div",{className:"absolute top-0 left-0 right-0 h-1.5 bg-white/70 rounded-t-xl"})]})]});return e.jsxs("div",{className:"space-y-2.5",children:[e.jsxs(c.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{delay:.1,duration:.4,ease:[.22,1,.36,1]},onClick:a,className:"rounded-2xl border border-[#9956DE]/25 cursor-pointer transition-all group relative overflow-hidden bg-gradient-to-br from-[#9956DE] via-[#7274ED] to-[#1FA7E1] hover:shadow-[0_16px_40px_rgba(114,116,237,0.28)] hover:-translate-y-0.5",children:[e.jsx("div",{className:"absolute inset-0 bg-[radial-gradient(circle_at_18%_8%,rgba(251,150,187,0.32),transparent_42%),radial-gradient(circle_at_85%_84%,rgba(117,208,106,0.24),transparent_40%)]"}),e.jsxs("div",{className:"relative z-10 p-3",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"shrink-0 w-8 h-8 bg-white/20 rounded-xl flex items-center justify-center border border-white/35 backdrop-blur-sm",children:e.jsx(W,{size:14,className:"text-white"})}),e.jsxs("h3",{className:"font-display font-bold text-[13px] leading-tight text-white tracking-wide",children:["Rewards & ",e.jsx("br",{className:"hidden 2xl:block"})," Achievements"]})]}),e.jsx(T,{size:14,className:"shrink-0 text-white/80 group-hover:text-white group-hover:translate-x-0.5 transition-all"})]}),e.jsxs("div",{className:"flex items-center justify-between gap-1 mb-3 bg-white/10 p-1.5 rounded-xl border border-white/20 backdrop-blur-sm",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-body px-1 text-white",children:[e.jsx(v,{size:12,className:"text-[#FFB356]"}),e.jsxs("span",{className:"font-bold",children:["Lv ",r]})]}),e.jsx("div",{className:"w-px h-3 bg-white/35"}),e.jsxs(O,{children:[e.jsx(Z,{asChild:!0,children:e.jsxs("button",{onClick:d=>{d.stopPropagation(),m?.()},className:"flex items-center gap-1.5 text-xs font-body px-1 text-white cursor-pointer transition-colors active:scale-95",children:[e.jsx(X,{size:12,className:"text-[#6ED1CF]"}),e.jsxs("span",{className:"font-bold whitespace-nowrap",children:[h," XP"]})]})}),e.jsx(H,{side:"top",className:"bg-slate-900 text-white border border-slate-700",children:"Review more lessons to earn more XP!"})]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-center mb-1.5",children:[e.jsxs("span",{className:"text-[11px] font-body text-white/90",children:["Next: Level ",r+1]}),e.jsxs("span",{className:"text-[11px] font-body font-semibold text-white",children:[Math.round(N),"%"]})]}),e.jsx("div",{className:"h-2 bg-white/25 rounded-full overflow-hidden border border-white/20",children:e.jsx(c.div,{initial:{width:0},animate:{width:`${N}%`},transition:{duration:1,ease:"easeOut"},className:"h-full bg-gradient-to-r from-[#6ED1CF] via-[#75D06A] to-[#FFB356] rounded-full"})})]})]})]}),e.jsx(c.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{delay:.2,duration:.4,ease:[.22,1,.36,1]},children:e.jsx(J,{onNavigateToQuizBattle:t,userPhoto:l})}),e.jsxs(c.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{delay:.3,duration:.4,ease:[.22,1,.36,1]},onClick:x,className:"bg-white rounded-xl border border-slate-200/80 hover:shadow-md hover:border-amber-200/60 transition-all group overflow-hidden cursor-pointer",children:[e.jsxs("div",{className:"p-3 border-b border-slate-100 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-7 h-7 bg-amber-50 rounded-lg flex items-center justify-center border border-amber-200/60 transition-colors group-hover:bg-amber-100/50",children:e.jsx(v,{size:14,className:"text-amber-500"})}),e.jsx("h3",{className:"font-display font-bold text-sm text-[#0a1628]",children:"Leaderboards"})]}),e.jsx(T,{size:14,className:"text-slate-400 group-hover:translate-x-0.5 group-hover:text-amber-500 transition-transform"})]}),e.jsx("div",{className:"pt-8 pb-3 px-2 bg-gradient-to-b from-slate-50/30 to-white flex items-end justify-center gap-1.5 min-h-[170px]",children:F?e.jsxs("div",{className:"flex flex-col items-center justify-center h-full py-8",children:[e.jsx(Y,{className:"w-5 h-5 animate-spin text-amber-400 mb-2"}),e.jsx("span",{className:"text-xs text-slate-400",children:"Loading rankings..."})]}):y||i.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center h-full py-8",children:[e.jsx(k,{className:"w-8 h-8 text-slate-300 mb-2"}),e.jsx("span",{className:"text-xs text-slate-400 text-center",children:y||"No rankings available yet"})]}):e.jsxs(e.Fragment,{children:[w(i[1],1,2,i[1]?.name||"---",1),w(i[0],0,1,i[0]?.name||"---",0),w(i[2],2,3,i[2]?.name||"---",2)]})})]})]})};export{ce as default}; diff --git a/assets/ScientificCalculator-BIH8UnvI.js b/assets/ScientificCalculator-BCm13p89.js similarity index 99% rename from assets/ScientificCalculator-BIH8UnvI.js rename to assets/ScientificCalculator-BCm13p89.js index 2edf9bcb2c88988920c3d1af8e3efc631162cf83..b310d64eccbce5c77aa9f89b597339f47f48faab 100644 --- a/assets/ScientificCalculator-BIH8UnvI.js +++ b/assets/ScientificCalculator-BCm13p89.js @@ -1,4 +1,4 @@ -import{r as c,j as e}from"./vendor-react-B4AQeu28.js";import{e as Z,n as de,h as U,m as ue}from"./index-BufUS6SI.js";import{a as fe,C as pe}from"./chevron-up-CoNRuMZ7.js";import{X as be}from"./x-BuBjuj2Y.js";import"./vendor-firebase-firestore-CNv3xXal.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-radix-C5nwdvGr.js";import"./vendor-charts-CAmziV1y.js";import"./vendor-markdown-yqZQ_iQm.js";/** +import{r as c,j as e}from"./vendor-react-B4AQeu28.js";import{e as Z,n as de,h as U,m as ue}from"./index-Bp7MiGcW.js";import{a as fe,C as pe}from"./chevron-up-DtS9MvUZ.js";import{X as be}from"./x-k8d6VLEw.js";import"./vendor-firebase-firestore-CNv3xXal.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-radix-C5nwdvGr.js";import"./vendor-charts-CAmziV1y.js";import"./vendor-markdown-yqZQ_iQm.js";/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. diff --git a/assets/SettingsModal-DnlLyFdo.js b/assets/SettingsModal-DNhoMuH7.js similarity index 96% rename from assets/SettingsModal-DnlLyFdo.js rename to assets/SettingsModal-DNhoMuH7.js index 00252adffef3563bc6b5b3ad25668d328011924d..65496b2977072d6ebd6af913a76958b061e92641 100644 --- a/assets/SettingsModal-DnlLyFdo.js +++ b/assets/SettingsModal-DNhoMuH7.js @@ -1,5 +1,5 @@ -const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-BufUS6SI.js","assets/vendor-react-B4AQeu28.js","assets/vendor-firebase-firestore-CNv3xXal.js","assets/vendor-firebase-core-D7GXCeNu.js","assets/vendor-firebase-auth-T_wvTOvf.js","assets/vendor-firebase-storage-Bi7H_66d.js","assets/vendor-firebase-analytics-rHarj5hR.js","assets/vendor-radix-C5nwdvGr.js","assets/vendor-charts-CAmziV1y.js","assets/vendor-markdown-yqZQ_iQm.js","assets/vendor-markdown-CfVKi3_s.css","assets/index-CIg5rXpX.css"])))=>i.map(i=>d[i]); -import{e as U,u as Me,aW as Le,aX as De,aY as qe,aZ as Ie,a_ as Fe,a$ as Ve,D as Oe,V as He,a1 as Ge,b as Ue,h as $e,m as H,L as Be,F as Xe,a2 as Ye,$ as Qe,_ as G,j as d,b0 as We,aV as Je,b1 as Ke,b2 as Ze,b3 as es}from"./index-BufUS6SI.js";import{r as a,j as e}from"./vendor-react-B4AQeu28.js";import{S as ss,a as ts,b as as,c as ns,d as te}from"./select-CPMGrUkA.js";import{B as p}from"./button-DsnZWCoA.js";import{I as n}from"./input-BPglbGHJ.js";import{S as x}from"./switch-Cwzq1Jz4.js";import je from"./ConfirmModal-B3J78vrR.js";import{P as is,M as rs,V as ls}from"./ProfilePictureUploader-B-ipxzWy.js";import{B as ge}from"./bell-D9j1Gy0m.js";import{D as ve}from"./download-DGNoiQkf.js";import{X as Ne}from"./x-BuBjuj2Y.js";import{C as cs}from"./circle-help-DNA0h1v1.js";import{G as os}from"./gift-D-3Burw1.js";import{C as ds}from"./chart-column-BcVJ31XT.js";import{M as xs}from"./megaphone-D_6g5Uzx.js";import{C as ms}from"./clock-CooTZK0X.js";import{T as hs}from"./trash-2-CBXOjqKg.js";import{E as us,a as bs}from"./eye-CDIJHn8i.js";import"./vendor-firebase-firestore-CNv3xXal.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-radix-C5nwdvGr.js";import"./vendor-charts-CAmziV1y.js";import"./vendor-markdown-yqZQ_iQm.js";import"./chevron-up-CoNRuMZ7.js";import"./check-B-qbiSF7.js";import"./log-out-Cp6gBYHP.js";import"./minus-DuS-NH5j.js";import"./plus-B4qs4LzO.js";import"./upload-gDf1MsBj.js";/** +const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-Bp7MiGcW.js","assets/vendor-react-B4AQeu28.js","assets/vendor-firebase-firestore-CNv3xXal.js","assets/vendor-firebase-core-D7GXCeNu.js","assets/vendor-firebase-auth-T_wvTOvf.js","assets/vendor-firebase-storage-Bi7H_66d.js","assets/vendor-firebase-analytics-rHarj5hR.js","assets/vendor-radix-C5nwdvGr.js","assets/vendor-charts-CAmziV1y.js","assets/vendor-markdown-yqZQ_iQm.js","assets/vendor-markdown-CfVKi3_s.css","assets/index-Dja0MwoB.css"])))=>i.map(i=>d[i]); +import{e as U,u as Me,aW as Le,aX as De,aY as qe,aZ as Ie,a_ as Fe,a$ as Ve,D as Oe,V as He,a1 as Ge,b as Ue,h as $e,m as H,L as Be,F as Xe,a2 as Ye,$ as Qe,_ as G,j as d,b0 as We,aV as Je,b1 as Ke,b2 as Ze,b3 as es}from"./index-Bp7MiGcW.js";import{r as a,j as e}from"./vendor-react-B4AQeu28.js";import{S as ss,a as ts,b as as,c as ns,d as te}from"./select-CNQuOudF.js";import{B as p}from"./button-BMVm9YQO.js";import{I as n}from"./input-Co0dljwe.js";import{S as x}from"./switch-C4JL2ii9.js";import je from"./ConfirmModal-CH3zQe0u.js";import{P as is,M as rs,V as ls}from"./ProfilePictureUploader-Cdp-MoCI.js";import{B as ge}from"./bell-DyLbgepV.js";import{D as ve}from"./download-DFL4ZCXr.js";import{X as Ne}from"./x-k8d6VLEw.js";import{C as cs}from"./circle-help-CLCoBWDy.js";import{G as os}from"./gift-CnT2c-5r.js";import{C as ds}from"./chart-column-Dyv8TfXk.js";import{M as xs}from"./megaphone-3N3DDeq6.js";import{C as ms}from"./clock-Cc6sJz1J.js";import{T as hs}from"./trash-2-BhUbBhdb.js";import{E as us,a as bs}from"./eye-B_U0s6fm.js";import"./vendor-firebase-firestore-CNv3xXal.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-radix-C5nwdvGr.js";import"./vendor-charts-CAmziV1y.js";import"./vendor-markdown-yqZQ_iQm.js";import"./chevron-up-DtS9MvUZ.js";import"./check-qsSFTYCr.js";import"./log-out-DrAbcVI9.js";import"./minus-BK7K7Pi2.js";import"./plus-D4SEqrVj.js";import"./upload-CP6O7WIX.js";/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. @@ -19,4 +19,4 @@ import{e as U,u as Me,aW as Le,aX as De,aY as qe,aZ as Ie,a_ as Fe,a$ as Ve,D as * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. - */const Ns=[["rect",{width:"14",height:"20",x:"5",y:"2",rx:"2",ry:"2",key:"1yt0o3"}],["path",{d:"M12 18h.01",key:"mhygvu"}]],ks=U("smartphone",Ns),ws=()=>{const{userProfile:m,userRole:y}=Me(),[r,z]=a.useState(Le),[R,_]=a.useState(De),[k,T]=a.useState(!1),[D,E]=a.useState(null);a.useEffect(()=>{if(!m?.uid)return;(async()=>{T(!0),E(null);try{if(y==="teacher"){const u=await Fe(m.uid);z(u)}if(y==="admin"){const u=await Ve();_(u)}}catch(u){E(u instanceof Error?u.message:"Failed to load settings")}finally{T(!1)}})()},[m?.uid,y]);const o=a.useCallback(async g=>{if(!m?.uid)return;const u=await qe(m.uid,g);z(u)},[m?.uid]),M=a.useCallback(async g=>{const u=await Ie(g);_(u)},[]);return{teacherPrefs:r,adminConfig:R,loading:k,error:D,saveTeacherPrefs:o,saveAdminConfig:M}},ae=()=>JSON.parse(JSON.stringify(We)),rt=({isOpen:m,onClose:y,profileData:r,onSave:z,settingsData:R,onSaveSettings:_,onApplySettingsPreview:k,onExportData:T,onClearCache:D,onResetData:E})=>{const o=r?.role||"student",{teacherPrefs:M,adminConfig:g,saveTeacherPrefs:u,saveAdminConfig:ke}=ws(),[b,ne]=a.useState("account"),[l,h]=a.useState({}),[i,ie]=a.useState(ae()),[w,C]=a.useState(M),[j,$]=a.useState(g),[B,re]=a.useState(!1),[q,le]=a.useState(!1),[X,ce]=a.useState(!1),[Y,oe]=a.useState(!1),[de,Cs]=a.useState(!1),[we,I]=a.useState(!1),[Ce,F]=a.useState(!1),[Se,P]=a.useState(!1),[L,xe]=a.useState(""),[f,Ae]=a.useState(null),[v,me]=a.useState(!1),[Q,he]=a.useState(!1),[W,ue]=a.useState(""),[V,be]=a.useState(""),J=a.useRef(!1),K=a.useRef(ae());a.useEffect(()=>{if(!m){J.current=!1;return}if(J.current)return;J.current=!0;const s=R?JSON.parse(JSON.stringify(R)):ae();K.current=s,h({uid:r?.uid,name:r?.name||"",email:r?.email||"",phone:r?.phone||"",photo:r?.photo||"",avatarLayers:r?.avatarLayers,role:r?.role,gender:r?.gender,lrn:r?.lrn||"",grade:r?.grade||"",section:r?.section||"",school:r?.school||"",department:r?.department||"",subject:r?.subject||"",yearsOfExperience:r?.yearsOfExperience||"",qualification:r?.qualification||"",position:r?.position||""}),ie(s),C(M),$(g)},[m,r,R,M,g]),a.useEffect(()=>{m&&k?.(i)},[m,i,k]),a.useEffect(()=>{if(!m)return;const s=t=>{t.key==="Escape"&&(k?.(K.current),y())};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[m,y,k]);const Z=a.useMemo(()=>{const s=[{id:"account",label:"Account",icon:Oe},{id:"notifications",label:"Notifications",icon:ge},{id:"appearance",label:"Appearance",icon:js}];return o==="student"&&(s.push({id:"privacy",label:"Privacy & Security",icon:He}),s.push({id:"learning",label:"Learning",icon:Ge})),o==="teacher"&&s.push({id:"teaching",label:"Teaching",icon:Ue}),o==="admin"&&s.push({id:"system",label:"System",icon:vs}),s.push({id:"data",label:"Data & Storage",icon:ve}),s},[o]),c=s=>{ie(t=>s(t))},ee=s=>{Ae(s),xe(""),he(!1),s==="password"&&ue(""),s==="email"&&be(l.email||""),P(!0)},fe=async()=>{if(!L.trim()){d.error("Current password is required");return}me(!0);try{if(f==="password"){if(W.length<8){d.error("New password must be at least 8 characters");return}await Ke(L,W),d.success("Password updated")}else if(f==="email"){if(!V.includes("@")){d.error("Enter a valid email");return}await Ze(L,V),h(s=>({...s,email:V})),d.success("Email updated")}else if(f==="delete"){await es(L,l.uid||""),d.success("Account deleted"),y();return}P(!1)}catch(s){d.error(s instanceof Error?s.message:"Authentication failed")}finally{me(!1)}},Ee=async()=>{const s=Je({name:l.name,phone:l.phone});if(s){d.error(s);return}re(!0);try{z&&await z(l),_&&await _(i),o==="teacher"&&await u(w),o==="admin"&&await ke(j),y()}catch(t){d.error(t instanceof Error?t.message:"Failed to save settings")}finally{re(!1)}},se=()=>{P(!1),I(!1),F(!1),k?.(K.current),y()},Pe=async()=>{if(!(!T||X)){ce(!0);try{await T()}catch(s){d.error(s instanceof Error?s.message:"Failed to export data")}finally{ce(!1)}}},ze=async()=>{if(!(!D||Y)){oe(!0);try{await D()}catch(s){d.error(s instanceof Error?s.message:"Failed to clear cache")}finally{oe(!1)}}},Re=async()=>{if(!(!E||q)){I(!1),le(!0);try{await E(),d.success("Testing data reset completed")}catch(s){d.error(s instanceof Error?s.message:"Failed to reset testing data")}finally{le(!1)}}},_e=()=>{F(!1),ee("delete")};return m?e.jsx($e,{children:e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"fixed inset-0 z-[100] flex items-end sm:items-center justify-center sm:p-4",children:[e.jsx(H.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},onClick:se,className:"absolute inset-0 bg-black/50 backdrop-blur-sm"}),e.jsxs(H.div,{initial:{opacity:0,scale:.95,y:20},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:20},transition:{duration:.2},className:"relative bg-[#f7f9fc] rounded-t-2xl sm:rounded-2xl shadow-2xl border border-[#dde3eb] w-full sm:max-w-4xl h-[92vh] sm:max-h-[85vh] overflow-hidden flex flex-col sm:flex-row",children:[e.jsxs("div",{className:"hidden sm:flex w-64 flex-shrink-0 bg-slate-50 border-r border-slate-200 flex-col p-6 overflow-y-auto",children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h2",{className:"text-xl font-display font-bold text-[#0a1628]",children:"Settings"}),e.jsx("p",{className:"text-xs text-slate-500 mt-1 font-body",children:"Manage your preferences"})]}),e.jsx("nav",{className:"space-y-1",children:Z.map(s=>{const t=s.icon;return e.jsxs("button",{onClick:()=>ne(s.id),className:`w-full flex items-center gap-3 px-4 py-3 rounded-xl text-left transition-all ${b===s.id?"bg-sky-50 text-sky-700 shadow-sm":"text-slate-500 hover:bg-slate-100 hover:text-sky-700"}`,children:[e.jsx(t,{size:18}),e.jsx("span",{className:"text-sm font-medium",children:s.label})]},s.id)})})]}),e.jsxs("div",{className:"flex-1 flex flex-col min-h-0",children:[e.jsx("div",{className:"sm:hidden flex items-center border-b border-[#dde3eb] bg-slate-50 overflow-x-auto no-scrollbar px-2",children:Z.map(s=>{const t=s.icon;return e.jsxs("button",{onClick:()=>ne(s.id),className:`flex flex-col items-center gap-0.5 px-3 py-2.5 shrink-0 text-xs font-medium border-b-2 transition-colors ${b===s.id?"border-sky-600 text-sky-700":"border-transparent text-slate-500"}`,children:[e.jsx(t,{size:16}),e.jsx("span",{className:"whitespace-nowrap",children:s.label})]},s.id)})}),e.jsxs("div",{className:"flex items-center justify-between px-4 sm:px-6 py-3 sm:py-4 border-b border-[#dde3eb]",children:[e.jsx("h3",{className:"text-base sm:text-lg font-display font-bold text-[#0a1628]",children:Z.find(s=>s.id===b)?.label}),e.jsx("button",{onClick:se,className:"p-2 hover:bg-[#edf1f7] rounded-xl transition-colors",children:e.jsx(Ne,{size:20,className:"text-[#5a6578]"})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-4 sm:p-6",children:[b==="account"&&e.jsxs("div",{className:"space-y-6",children:[e.jsx(is,{uid:l.uid,photoURL:l.photo,displayName:l.name,onUploaded:s=>h(t=>({...t,photo:s}))}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-bold text-[#5a6578] mb-2 block font-body uppercase tracking-wider text-xs",children:"Full Name"}),e.jsx(n,{type:"text",value:l.name||"",onChange:s=>h(t=>({...t,name:s.target.value})),maxLength:100,autoComplete:"name",className:"max-w-md"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-bold text-[#5a6578] mb-2 block font-body uppercase tracking-wider text-xs",children:"Email Address"}),e.jsxs("div",{className:"flex items-center gap-2 max-w-md",children:[e.jsx(n,{type:"email",value:l.email||"",disabled:!0,className:"flex-1 bg-slate-100"}),e.jsx(p,{variant:"outline",size:"sm",onClick:()=>ee("email"),children:"Change"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-bold text-[#5a6578] mb-2 block font-body uppercase tracking-wider text-xs",children:"Phone Number"}),e.jsx(n,{type:"tel",value:l.phone||"",onChange:s=>h(t=>({...t,phone:s.target.value})),maxLength:20,inputMode:"tel",autoComplete:"tel",pattern:"^\\+?[0-9 ()\\-.]{7,20}$",placeholder:"+63 912 345 6789",className:"max-w-md"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-bold text-[#5a6578] mb-2 block font-body uppercase tracking-wider text-xs",children:"Gender"}),e.jsxs(ss,{value:l.gender||"",onValueChange:s=>h(t=>({...t,gender:s})),children:[e.jsx(ts,{className:"max-w-md bg-white border-[#dde3eb] rounded-lg",children:e.jsx(as,{placeholder:"Select gender (optional)"})}),e.jsxs(ns,{children:[e.jsx(te,{value:"male",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(rs,{className:"size-4 text-blue-500"}),e.jsx("span",{children:"Male"})]})}),e.jsx(te,{value:"female",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ls,{className:"size-4 text-pink-500"}),e.jsx("span",{children:"Female"})]})}),e.jsx(te,{value:"prefer_not_to_say",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(cs,{className:"size-4 text-gray-500"}),e.jsx("span",{children:"Prefer not to say"})]})})]})]})]}),o==="student"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-bold text-[#5a6578] mb-2 block font-body uppercase tracking-wider text-xs",children:"LRN"}),e.jsx(n,{value:l.lrn||"",onChange:s=>h(t=>({...t,lrn:s.target.value})),className:"max-w-md"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-bold text-[#5a6578] mb-2 block font-body uppercase tracking-wider text-xs",children:"Grade Level"}),e.jsx(n,{value:l.grade||"",onChange:s=>h(t=>({...t,grade:s.target.value})),className:"max-w-md"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-bold text-[#5a6578] mb-2 block font-body uppercase tracking-wider text-xs",children:"Section"}),e.jsx(n,{value:l.section||"",onChange:s=>h(t=>({...t,section:s.target.value})),className:"max-w-md"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-bold text-[#5a6578] mb-2 block font-body uppercase tracking-wider text-xs",children:"School"}),e.jsx(n,{value:l.school||"",onChange:s=>h(t=>({...t,school:s.target.value})),className:"max-w-md"})]})]}),o==="teacher"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-bold text-[#5a6578] mb-2 block font-body uppercase tracking-wider text-xs",children:"Department"}),e.jsx(n,{value:l.department||"",onChange:s=>h(t=>({...t,department:s.target.value})),className:"max-w-md"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-bold text-[#5a6578] mb-2 block font-body uppercase tracking-wider text-xs",children:"Subject"}),e.jsx(n,{value:l.subject||"",onChange:s=>h(t=>({...t,subject:s.target.value})),className:"max-w-md"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-bold text-[#5a6578] mb-2 block font-body uppercase tracking-wider text-xs",children:"Years of Experience"}),e.jsx(n,{value:l.yearsOfExperience||"",onChange:s=>h(t=>({...t,yearsOfExperience:s.target.value})),className:"max-w-md"})]})]}),o==="admin"&&e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-bold text-[#5a6578] mb-2 block font-body uppercase tracking-wider text-xs",children:"Position"}),e.jsx(n,{value:l.position||"",onChange:s=>h(t=>({...t,position:s.target.value})),className:"max-w-md"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-bold text-[#5a6578] mb-2 block font-body uppercase tracking-wider text-xs",children:"Change Password"}),e.jsxs(p,{variant:"outline",className:"rounded-xl",onClick:()=>ee("password"),children:[e.jsx(Be,{size:16,className:"mr-2"}),"Update Password"]})]})]}),b==="notifications"&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-[#dde3eb]",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-[#0a1628] font-body",children:"Push Notifications"}),e.jsx("p",{className:"text-xs text-slate-500 mt-1",children:"Get notified on your device"})]}),e.jsx(x,{checked:i.notifications.pushNotifications,onCheckedChange:s=>c(t=>({...t,notifications:{...t.notifications,pushNotifications:s}}))})]}),e.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-[#dde3eb]",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-[#0a1628] font-body",children:"Sound Effects"}),e.jsx("p",{className:"text-xs text-slate-500 mt-1",children:"Play sounds for notifications"})]}),e.jsx(x,{checked:i.notifications.soundEnabled,onCheckedChange:s=>c(t=>({...t,notifications:{...t.notifications,soundEnabled:s}}))})]}),o==="teacher"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-[#dde3eb]",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-[#0a1628] font-body",children:"Student Submissions"}),e.jsx("p",{className:"text-xs text-slate-500 mt-1",children:"Notify when students submit work"})]}),e.jsx(x,{checked:w.notifyOnSubmission,onCheckedChange:s=>C(t=>({...t,notifyOnSubmission:s}))})]}),e.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-[#dde3eb]",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-[#0a1628] font-body",children:"Student Activity Alerts"}),e.jsx("p",{className:"text-xs text-slate-500 mt-1",children:"Notify on at-risk student activity"})]}),e.jsx(x,{checked:w.notifyOnStudentActivity,onCheckedChange:s=>C(t=>({...t,notifyOnStudentActivity:s}))})]})]}),e.jsxs("div",{className:"pt-4",children:[e.jsx("h4",{className:"text-sm font-bold text-[#0a1628] mb-3 font-body",children:"Notification Types"}),e.jsx("div",{className:"space-y-3",children:[{key:"quizReminders",label:"Quiz Reminders"},{key:"newContent",label:"New Content"},{key:"achievements",label:"Achievements"},{key:"streakAlerts",label:"Streak Alerts"},{key:"weeklySummary",label:"Weekly Summary"}].map(s=>e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("input",{type:"checkbox",checked:i.notifications.notificationTypes[s.key],onChange:t=>c(N=>({...N,notifications:{...N.notifications,notificationTypes:{...N.notifications.notificationTypes,[s.key]:t.target.checked}}})),className:"w-4 h-4 rounded border-[#dde3eb] text-sky-600 focus:ring-sky-500"}),e.jsx("span",{className:"text-sm text-[#0a1628] font-body",children:s.label})]},s.key))})]}),e.jsxs("div",{className:"pt-4 border-t border-[#dde3eb]",children:[e.jsx("h4",{className:"text-sm font-bold text-[#0a1628] mb-1 font-body",children:"Push Notification Categories"}),e.jsx("p",{className:"text-xs text-slate-500 mb-3",children:"Choose which kinds of pushes you want to receive on this device."}),e.jsxs("div",{className:"flex items-center justify-between py-2 mb-2 border-b border-[#dde3eb]",children:[e.jsxs("div",{children:[e.jsx("h5",{className:"text-sm font-bold text-[#0a1628] font-body",children:"Enable Push (master)"}),e.jsx("p",{className:"text-xs text-slate-500 mt-0.5",children:"Turn off to silence ALL push categories."})]}),e.jsx(x,{checked:i.pushPreferences.pushEnabled,onCheckedChange:s=>c(t=>({...t,pushPreferences:{...t.pushPreferences,pushEnabled:s}}))})]}),e.jsx("div",{className:"space-y-2",children:[{key:"achievement",label:"Achievements unlocked",icon:Xe},{key:"quiz_battle",label:"Quiz battle invites & results",icon:Ye},{key:"daily_reward",label:"Daily reward reminders",icon:os},{key:"assignment",label:"New assignments / deadlines",icon:ps},{key:"streak_reminder",label:"Streak reminders",icon:Qe},{key:"leaderboard",label:"Leaderboard updates",icon:ds},{key:"system",label:"System announcements",icon:xs}].map(s=>{const t=s.key,N=s.icon;return e.jsxs("label",{className:"flex items-center justify-between py-1.5",children:[e.jsxs("span",{className:"text-sm text-[#0a1628] font-body flex items-center gap-2",children:[e.jsx(N,{className:"h-4 w-4 text-[#6c47ff]"}),s.label]}),e.jsx(x,{checked:!!i.pushPreferences[t],onCheckedChange:pe=>c(O=>({...O,pushPreferences:{...O.pushPreferences,[s.key]:pe}})),disabled:!i.pushPreferences.pushEnabled&&t!=="pushEnabled"})]},s.key)})}),e.jsx("div",{className:"mt-4",children:e.jsxs(p,{type:"button",variant:"outline",size:"sm",onClick:async()=>{try{const{requestPushPermissionAndRegister:s}=await G(async()=>{const{requestPushPermissionAndRegister:S}=await import("./index-BufUS6SI.js").then(A=>A.b9);return{requestPushPermissionAndRegister:S}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11])),{auth:t}=await G(async()=>{const{auth:S}=await import("./index-BufUS6SI.js").then(A=>A.b7);return{auth:S}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11])),N=t.currentUser?.uid;if(!N){d.error("You must be signed in to test push notifications.");return}if(!await s(N)){d.error("Push setup failed. Check that VITE_FIREBASE_VAPID_KEY is configured and notifications are allowed.");return}const{httpsCallable:O}=await G(async()=>{const{httpsCallable:S}=await import("./vendor-firebase-core-D7GXCeNu.js").then(A=>A.a9);return{httpsCallable:S}},[]),{cloudFunctions:Te}=await G(async()=>{const{cloudFunctions:S}=await import("./index-BufUS6SI.js").then(A=>A.b7);return{cloudFunctions:S}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11])),ye=(await O(Te,"sendTestPush")({}))?.data?.sent??0;ye>0?d.success(`Sent test push to ${ye} device(s).`):d.message("No active devices found. Enable browser notifications first.")}catch(s){d.error(s instanceof Error?s.message:"Failed to send test push")}},children:[e.jsx(ge,{size:14,className:"mr-2"}),"Send test push"]})})]}),e.jsxs("div",{className:"pt-4 border-t border-[#dde3eb]",children:[e.jsxs("label",{className:"text-sm font-bold text-[#5a6578] mb-2 block font-body uppercase tracking-wider text-xs",children:[e.jsx(ms,{size:16,className:"inline mr-2"}),"Quiet Hours"]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(n,{type:"time",value:i.notifications.quietHours.start,onChange:s=>c(t=>({...t,notifications:{...t.notifications,quietHours:{...t.notifications.quietHours,start:s.target.value}}})),className:"w-32"}),e.jsx("span",{className:"text-[#5a6578]",children:"to"}),e.jsx(n,{type:"time",value:i.notifications.quietHours.end,onChange:s=>c(t=>({...t,notifications:{...t.notifications,quietHours:{...t.notifications.quietHours,end:s.target.value}}})),className:"w-32"})]})]})]}),b==="appearance"&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-[#dde3eb]",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-[#0a1628] font-body",children:"Dark Mode"}),e.jsx("p",{className:"text-xs text-slate-500 mt-1",children:"Toggle dark theme"})]}),e.jsx(x,{checked:i.appearance.darkMode,onCheckedChange:s=>c(t=>({...t,appearance:{...t.appearance,darkMode:s}}))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-bold text-[#5a6578] mb-3 block font-body uppercase tracking-wider text-xs",children:"Font Size"}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("span",{className:"text-xs text-slate-500",children:"Small"}),e.jsx("input",{type:"range",min:"12",max:"20",value:i.appearance.fontSize,onChange:s=>c(t=>({...t,appearance:{...t.appearance,fontSize:Number(s.target.value)}})),className:"flex-1"}),e.jsx("span",{className:"text-xs text-slate-500",children:"Large"}),e.jsxs("span",{className:"text-xs font-mono text-slate-600 w-8",children:[i.appearance.fontSize,"px"]})]})]}),e.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-[#dde3eb]",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-[#0a1628] font-body",children:"Compact View"}),e.jsx("p",{className:"text-xs text-slate-500 mt-1",children:"Show more content on screen"})]}),e.jsx(x,{checked:i.appearance.compactView,onCheckedChange:s=>c(t=>({...t,appearance:{...t.appearance,compactView:s}}))})]}),e.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-[#dde3eb]",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-[#0a1628] font-body",children:"Reduce Animations"}),e.jsx("p",{className:"text-xs text-slate-500 mt-1",children:"Minimize motion effects"})]}),e.jsx(x,{checked:i.appearance.reduceAnimations,onCheckedChange:s=>c(t=>({...t,appearance:{...t.appearance,reduceAnimations:s}}))})]})]}),b==="privacy"&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-[#dde3eb]",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-[#0a1628] font-body",children:"Profile Visibility"}),e.jsx("p",{className:"text-xs text-slate-500 mt-1",children:"Who can see your profile"})]}),e.jsxs("select",{value:i.privacy.profileVisibility,onChange:s=>c(t=>({...t,privacy:{...t.privacy,profileVisibility:s.target.value}})),className:"px-3 py-2 border border-[#dde3eb] rounded-lg text-sm bg-white text-[#0a1628]",children:[e.jsx("option",{value:"everyone",children:"Everyone"}),e.jsx("option",{value:"students_and_staff",children:"Students and Staff"}),e.jsx("option",{value:"private",children:"Private"})]})]}),e.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-[#dde3eb]",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-[#0a1628] font-body",children:"Show Activity Status"}),e.jsx("p",{className:"text-xs text-slate-500 mt-1",children:"Let others see when you're online"})]}),e.jsx(x,{checked:i.privacy.showActivityStatus,onCheckedChange:s=>c(t=>({...t,privacy:{...t.privacy,showActivityStatus:s}}))})]}),e.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-[#dde3eb]",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-[#0a1628] font-body",children:"Data Sharing"}),e.jsx("p",{className:"text-xs text-slate-500 mt-1",children:"Share anonymous usage data"})]}),e.jsx(x,{checked:i.privacy.dataSharing,onCheckedChange:s=>c(t=>({...t,privacy:{...t.privacy,dataSharing:s}}))})]})]}),b==="learning"&&o==="student"&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-bold text-[#5a6578] mb-2 block font-body uppercase tracking-wider text-xs",children:"Daily XP Goal"}),e.jsx(n,{type:"number",value:i.learning.dailyXpGoal,onChange:s=>c(t=>({...t,learning:{...t.learning,dailyXpGoal:Number(s.target.value||0)}})),className:"max-w-xs"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-bold text-[#5a6578] mb-2 block font-body uppercase tracking-wider text-xs",children:"Preferred Study Time"}),e.jsxs("select",{value:i.learning.preferredStudyTime,onChange:s=>c(t=>({...t,learning:{...t.learning,preferredStudyTime:s.target.value}})),className:"px-3 py-2 border border-[#dde3eb] rounded-lg text-sm w-full max-w-xs bg-white text-[#0a1628]",children:[e.jsx("option",{value:"morning",children:"Morning (6AM - 12PM)"}),e.jsx("option",{value:"afternoon",children:"Afternoon (12PM - 6PM)"}),e.jsx("option",{value:"evening",children:"Evening (6PM - 12PM)"}),e.jsx("option",{value:"night",children:"Night (12AM - 6AM)"})]})]}),e.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-[#dde3eb]",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-[#0a1628] font-body",children:"Auto-play Next Lesson"}),e.jsx("p",{className:"text-xs text-slate-500 mt-1",children:"Automatically start the next lesson"})]}),e.jsx(x,{checked:i.learning.autoPlayLessons,onCheckedChange:s=>c(t=>({...t,learning:{...t.learning,autoPlayLessons:s}}))})]}),e.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-[#dde3eb]",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-[#0a1628] font-body",children:"Show Hints During Quizzes"}),e.jsx("p",{className:"text-xs text-slate-500 mt-1",children:"Display helpful hints for questions"})]}),e.jsx(x,{checked:i.learning.showHints,onCheckedChange:s=>c(t=>({...t,learning:{...t.learning,showHints:s}}))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-bold text-[#5a6578] mb-2 block font-body uppercase tracking-wider text-xs",children:"Quiz Difficulty Preference"}),e.jsxs("select",{value:i.learning.quizDifficultyPreference,onChange:s=>c(t=>({...t,learning:{...t.learning,quizDifficultyPreference:s.target.value}})),className:"px-3 py-2 border border-[#dde3eb] rounded-lg text-sm w-full max-w-xs bg-white text-[#0a1628]",children:[e.jsx("option",{value:"adaptive",children:"Adaptive (Recommended)"}),e.jsx("option",{value:"easy",children:"Easy"}),e.jsx("option",{value:"medium",children:"Medium"}),e.jsx("option",{value:"hard",children:"Hard"})]})]}),e.jsxs("div",{className:"pt-4 border-t border-[#dde3eb]",children:[e.jsxs("label",{className:"text-sm font-bold text-[#5a6578] mb-2 block font-body uppercase tracking-wider text-xs",children:[e.jsx(ks,{size:16,className:"inline mr-2"}),"Study Reminders"]}),e.jsx(n,{type:"time",value:i.learning.studyReminderTime,onChange:s=>c(t=>({...t,learning:{...t.learning,studyReminderTime:s.target.value}})),className:"w-32"})]})]}),b==="teaching"&&o==="teacher"&&e.jsxs("div",{className:"space-y-6",children:[e.jsx("h4",{className:"text-sm font-bold text-[#0a1628] font-body",children:"Quiz Defaults"}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-[#5a6578] block mb-1",children:"Time Limit (min)"}),e.jsx(n,{type:"number",value:w.quizDefaults.timeLimitMinutes,onChange:s=>C(t=>({...t,quizDefaults:{...t.quizDefaults,timeLimitMinutes:Number(s.target.value)}}))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-[#5a6578] block mb-1",children:"Passing Score (%)"}),e.jsx(n,{type:"number",value:w.quizDefaults.passingScore,onChange:s=>C(t=>({...t,quizDefaults:{...t.quizDefaults,passingScore:Number(s.target.value)}}))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-[#5a6578] block mb-1",children:"Max Attempts"}),e.jsx(n,{type:"number",value:w.quizDefaults.maxAttempts,onChange:s=>C(t=>({...t,quizDefaults:{...t.quizDefaults,maxAttempts:Number(s.target.value)}}))})]})]}),e.jsx("h4",{className:"text-sm font-bold text-[#0a1628] font-body pt-4",children:"Class Preferences"}),e.jsxs("div",{className:"flex items-center justify-between py-3 border-t border-[#dde3eb]",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-[#0a1628] font-body",children:"Student Analytics Visibility"}),e.jsx("p",{className:"text-xs text-slate-500 mt-1",children:"Let students see their leaderboard rank"})]}),e.jsx(x,{checked:w.studentAnalyticsVisibility,onCheckedChange:s=>C(t=>({...t,studentAnalyticsVisibility:s}))})]})]}),b==="system"&&o==="admin"&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-[#dde3eb]",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-[#0a1628] font-body",children:"Maintenance Mode"}),e.jsx("p",{className:"text-xs text-slate-500 mt-1",children:"Disable platform access for non-admins"})]}),e.jsx(x,{checked:j.maintenanceMode,onCheckedChange:s=>$(t=>({...t,maintenanceMode:s}))})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-[#5a6578] block mb-1",children:"Default Grade Level"}),e.jsx(n,{value:j.defaultGradeLevel,disabled:!0})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-[#5a6578] block mb-1",children:"Default Curriculum"}),e.jsx(n,{value:j.defaultCurriculum,disabled:!0})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-[#5a6578] block mb-1",children:"Max Class Size"}),e.jsx(n,{type:"number",value:j.maxClassSize,disabled:!0})]})]}),e.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-[#dde3eb]",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-[#0a1628] font-body",children:"Audit Log Visible"}),e.jsx("p",{className:"text-xs text-slate-500 mt-1",children:"Show audit logs in admin dashboard"})]}),e.jsx(x,{checked:j.auditLogVisible,onCheckedChange:s=>$(t=>({...t,auditLogVisible:s}))})]}),e.jsx("h4",{className:"text-sm font-bold text-[#0a1628] font-body pt-4",children:"AI Configuration"}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-[#5a6578] block mb-1",children:"Model Name"}),e.jsx(n,{value:j.aiConfig.modelName,disabled:!0})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-[#5a6578] block mb-1",children:"Temperature"}),e.jsx(n,{type:"number",value:j.aiConfig.temperature,disabled:!0})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx("label",{className:"text-xs text-[#5a6578] block mb-1",children:"API Endpoint"}),e.jsx(n,{value:j.aiConfig.endpoint,disabled:!0})]})]})]}),b==="data"&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"p-4 bg-sky-50 border border-sky-200 rounded-xl",children:[e.jsx("h4",{className:"text-sm font-bold text-sky-900 mb-1 font-body",children:"Download Your Data"}),e.jsx("p",{className:"text-xs text-sky-700 mb-3",children:"Export all your learning data and progress"}),e.jsxs(p,{variant:"outline",size:"sm",className:"rounded-xl",onClick:Pe,disabled:X,children:[e.jsx(ve,{size:16,className:"mr-2"}),X?"Exporting...":"Request Data Export"]})]}),e.jsxs("div",{className:"p-4 bg-white border border-[#dde3eb] rounded-xl",children:[e.jsx("h4",{className:"text-sm font-bold text-[#0a1628] mb-1 font-body",children:"Clear Cache"}),e.jsx("p",{className:"text-xs text-[#5a6578] mb-3",children:"Free up space by clearing cached data"}),e.jsx(p,{variant:"outline",size:"sm",className:"rounded-xl",onClick:ze,disabled:Y,children:Y?"Clearing...":"Clear Cache"})]}),e.jsxs("div",{className:"p-4 bg-rose-50 border border-rose-200 rounded-xl",children:[e.jsx("h4",{className:"text-sm font-bold text-rose-900 mb-1",children:"Reset Progress"}),e.jsxs("p",{className:"text-xs text-rose-700 mb-3",children:[o==="student"&&"Reset quizzes, diagnostic state, XP, and learning progress for retesting.",o==="teacher"&&"Reset imported records, managed classrooms, and teacher-generated quiz artifacts.",o==="admin"&&"Reset admin testing artifacts like personal audit/content update records."]}),e.jsx(p,{variant:"outline",size:"sm",className:"rounded-xl text-rose-700 border-rose-300",disabled:!E||q,onClick:()=>I(!0),children:q?"Resetting...":"Reset Testing Data"})]}),e.jsxs("div",{className:"p-4 bg-red-50 border border-red-200 rounded-xl",children:[e.jsx("h4",{className:"text-sm font-bold text-red-900 mb-1",children:"Delete Account"}),e.jsx("p",{className:"text-xs text-red-700 mb-3",children:"Permanently delete your account and all data"}),e.jsxs(p,{variant:"outline",size:"sm",className:"rounded-xl text-red-700 border-red-300",onClick:()=>F(!0),disabled:de,children:[e.jsx(hs,{size:16,className:"mr-2"}),de?"Deleting...":"Delete Account"]})]})]})]}),e.jsxs("div",{className:"shrink-0 px-4 sm:px-6 py-3 sm:py-4 border-t border-[#dde3eb] bg-[#edf1f7] flex flex-col sm:flex-row items-stretch sm:items-center justify-between gap-2 sm:gap-0",children:[e.jsx("p",{className:"text-xs text-slate-500 font-body text-center sm:text-left",children:"MathPulse AI v2.1.0"}),e.jsxs("div",{className:"flex gap-2 w-full sm:w-auto",children:[e.jsx(p,{variant:"outline",onClick:se,className:"rounded-lg border-[#dde3eb] flex-1 sm:flex-none",disabled:B,children:"Cancel"}),e.jsx(p,{onClick:Ee,className:"rounded-lg bg-sky-600 hover:bg-sky-700 text-white flex-1 sm:flex-none",disabled:B,children:B?"Saving...":"Save Changes"})]})]})]})]})]}),Se&&e.jsx(H.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-[130] bg-black/50 backdrop-blur-sm flex items-center justify-center p-4",onClick:()=>{v||P(!1)},children:e.jsxs(H.div,{initial:{opacity:0,scale:.95,y:12},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:12},transition:{duration:.2},className:"w-full max-w-md rounded-2xl border border-[#dde3eb] bg-[#f7f9fc] shadow-2xl",onClick:s=>s.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-[#dde3eb] px-6 py-4",children:[e.jsxs("h4",{className:"text-lg font-display font-bold text-[#0a1628]",children:[f==="password"&&"Change Password",f==="email"&&"Change Email",f==="delete"&&"Delete Account"]}),e.jsx("button",{onClick:()=>{v||P(!1)},className:"p-2 rounded-xl hover:bg-[#edf1f7] transition-colors","aria-label":"Close",children:e.jsx(Ne,{size:18,className:"text-[#5a6578]"})})]}),e.jsxs("div",{className:"px-6 py-5 space-y-4",children:[e.jsx("p",{className:"text-sm text-[#5a6578]",children:"Enter your current password to continue."}),e.jsxs("div",{className:"relative",children:[e.jsx(n,{type:Q?"text":"password",value:L,onChange:s=>xe(s.target.value),placeholder:"Current password",autoFocus:!0,className:"pr-10",disabled:v,onKeyDown:s=>{s.key==="Enter"&&fe()}}),e.jsx("button",{type:"button",onClick:()=>he(!Q),className:"absolute right-3 top-1/2 -translate-y-1/2 text-slate-400 hover:text-slate-600",tabIndex:-1,children:Q?e.jsx(us,{size:16}):e.jsx(bs,{size:16})})]}),f==="password"&&e.jsx("div",{className:"relative",children:e.jsx(n,{type:"password",value:W,onChange:s=>ue(s.target.value),placeholder:"New password (min 8 chars)",disabled:v})}),f==="email"&&e.jsx(n,{type:"email",value:V,onChange:s=>be(s.target.value),placeholder:"New email address",disabled:v}),f==="delete"&&e.jsx("p",{className:"text-sm text-red-600 font-medium",children:"This action is permanent and cannot be undone."}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(p,{variant:"outline",onClick:()=>P(!1),disabled:v,children:"Cancel"}),e.jsx(p,{onClick:()=>void fe(),className:f==="delete"?"bg-red-600 hover:bg-red-700 text-white":"bg-sky-600 hover:bg-sky-700 text-white",disabled:v,children:v?"Processing...":f==="delete"?"Delete Forever":"Confirm"})]})]})]})}),e.jsx(je,{isOpen:we,onClose:()=>I(!1),onConfirm:Re,title:"Reset Testing Data?",message:`Reset ${o} testing data? This will clear quizzes, diagnostic assessments, assessment history, XP, and learning progress. This action cannot be undone.`,confirmText:q?"Resetting...":"Reset Data",cancelText:"Cancel",type:"warning",icon:"warning",zIndexClass:"z-[130]"}),e.jsx(je,{isOpen:Ce,onClose:()=>F(!1),onConfirm:_e,title:"Delete Account?",message:"You will need to re-authenticate to permanently delete your account. This cannot be undone.",confirmText:"Continue",cancelText:"Cancel",type:"danger",icon:"delete",zIndexClass:"z-[130]"})]})}):null};export{rt as default}; + */const Ns=[["rect",{width:"14",height:"20",x:"5",y:"2",rx:"2",ry:"2",key:"1yt0o3"}],["path",{d:"M12 18h.01",key:"mhygvu"}]],ks=U("smartphone",Ns),ws=()=>{const{userProfile:m,userRole:y}=Me(),[r,z]=a.useState(Le),[R,_]=a.useState(De),[k,T]=a.useState(!1),[D,E]=a.useState(null);a.useEffect(()=>{if(!m?.uid)return;(async()=>{T(!0),E(null);try{if(y==="teacher"){const u=await Fe(m.uid);z(u)}if(y==="admin"){const u=await Ve();_(u)}}catch(u){E(u instanceof Error?u.message:"Failed to load settings")}finally{T(!1)}})()},[m?.uid,y]);const o=a.useCallback(async g=>{if(!m?.uid)return;const u=await qe(m.uid,g);z(u)},[m?.uid]),M=a.useCallback(async g=>{const u=await Ie(g);_(u)},[]);return{teacherPrefs:r,adminConfig:R,loading:k,error:D,saveTeacherPrefs:o,saveAdminConfig:M}},ae=()=>JSON.parse(JSON.stringify(We)),rt=({isOpen:m,onClose:y,profileData:r,onSave:z,settingsData:R,onSaveSettings:_,onApplySettingsPreview:k,onExportData:T,onClearCache:D,onResetData:E})=>{const o=r?.role||"student",{teacherPrefs:M,adminConfig:g,saveTeacherPrefs:u,saveAdminConfig:ke}=ws(),[b,ne]=a.useState("account"),[l,h]=a.useState({}),[i,ie]=a.useState(ae()),[w,C]=a.useState(M),[j,$]=a.useState(g),[B,re]=a.useState(!1),[q,le]=a.useState(!1),[X,ce]=a.useState(!1),[Y,oe]=a.useState(!1),[de,Cs]=a.useState(!1),[we,I]=a.useState(!1),[Ce,F]=a.useState(!1),[Se,P]=a.useState(!1),[L,xe]=a.useState(""),[f,Ae]=a.useState(null),[v,me]=a.useState(!1),[Q,he]=a.useState(!1),[W,ue]=a.useState(""),[V,be]=a.useState(""),J=a.useRef(!1),K=a.useRef(ae());a.useEffect(()=>{if(!m){J.current=!1;return}if(J.current)return;J.current=!0;const s=R?JSON.parse(JSON.stringify(R)):ae();K.current=s,h({uid:r?.uid,name:r?.name||"",email:r?.email||"",phone:r?.phone||"",photo:r?.photo||"",avatarLayers:r?.avatarLayers,role:r?.role,gender:r?.gender,lrn:r?.lrn||"",grade:r?.grade||"",section:r?.section||"",school:r?.school||"",department:r?.department||"",subject:r?.subject||"",yearsOfExperience:r?.yearsOfExperience||"",qualification:r?.qualification||"",position:r?.position||""}),ie(s),C(M),$(g)},[m,r,R,M,g]),a.useEffect(()=>{m&&k?.(i)},[m,i,k]),a.useEffect(()=>{if(!m)return;const s=t=>{t.key==="Escape"&&(k?.(K.current),y())};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[m,y,k]);const Z=a.useMemo(()=>{const s=[{id:"account",label:"Account",icon:Oe},{id:"notifications",label:"Notifications",icon:ge},{id:"appearance",label:"Appearance",icon:js}];return o==="student"&&(s.push({id:"privacy",label:"Privacy & Security",icon:He}),s.push({id:"learning",label:"Learning",icon:Ge})),o==="teacher"&&s.push({id:"teaching",label:"Teaching",icon:Ue}),o==="admin"&&s.push({id:"system",label:"System",icon:vs}),s.push({id:"data",label:"Data & Storage",icon:ve}),s},[o]),c=s=>{ie(t=>s(t))},ee=s=>{Ae(s),xe(""),he(!1),s==="password"&&ue(""),s==="email"&&be(l.email||""),P(!0)},fe=async()=>{if(!L.trim()){d.error("Current password is required");return}me(!0);try{if(f==="password"){if(W.length<8){d.error("New password must be at least 8 characters");return}await Ke(L,W),d.success("Password updated")}else if(f==="email"){if(!V.includes("@")){d.error("Enter a valid email");return}await Ze(L,V),h(s=>({...s,email:V})),d.success("Email updated")}else if(f==="delete"){await es(L,l.uid||""),d.success("Account deleted"),y();return}P(!1)}catch(s){d.error(s instanceof Error?s.message:"Authentication failed")}finally{me(!1)}},Ee=async()=>{const s=Je({name:l.name,phone:l.phone});if(s){d.error(s);return}re(!0);try{z&&await z(l),_&&await _(i),o==="teacher"&&await u(w),o==="admin"&&await ke(j),y()}catch(t){d.error(t instanceof Error?t.message:"Failed to save settings")}finally{re(!1)}},se=()=>{P(!1),I(!1),F(!1),k?.(K.current),y()},Pe=async()=>{if(!(!T||X)){ce(!0);try{await T()}catch(s){d.error(s instanceof Error?s.message:"Failed to export data")}finally{ce(!1)}}},ze=async()=>{if(!(!D||Y)){oe(!0);try{await D()}catch(s){d.error(s instanceof Error?s.message:"Failed to clear cache")}finally{oe(!1)}}},Re=async()=>{if(!(!E||q)){I(!1),le(!0);try{await E(),d.success("Testing data reset completed")}catch(s){d.error(s instanceof Error?s.message:"Failed to reset testing data")}finally{le(!1)}}},_e=()=>{F(!1),ee("delete")};return m?e.jsx($e,{children:e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"fixed inset-0 z-[100] flex items-end sm:items-center justify-center sm:p-4",children:[e.jsx(H.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},onClick:se,className:"absolute inset-0 bg-black/50 backdrop-blur-sm"}),e.jsxs(H.div,{initial:{opacity:0,scale:.95,y:20},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:20},transition:{duration:.2},className:"relative bg-[#f7f9fc] rounded-t-2xl sm:rounded-2xl shadow-2xl border border-[#dde3eb] w-full sm:max-w-4xl h-[92vh] sm:max-h-[85vh] overflow-hidden flex flex-col sm:flex-row",children:[e.jsxs("div",{className:"hidden sm:flex w-64 flex-shrink-0 bg-slate-50 border-r border-slate-200 flex-col p-6 overflow-y-auto",children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h2",{className:"text-xl font-display font-bold text-[#0a1628]",children:"Settings"}),e.jsx("p",{className:"text-xs text-slate-500 mt-1 font-body",children:"Manage your preferences"})]}),e.jsx("nav",{className:"space-y-1",children:Z.map(s=>{const t=s.icon;return e.jsxs("button",{onClick:()=>ne(s.id),className:`w-full flex items-center gap-3 px-4 py-3 rounded-xl text-left transition-all ${b===s.id?"bg-sky-50 text-sky-700 shadow-sm":"text-slate-500 hover:bg-slate-100 hover:text-sky-700"}`,children:[e.jsx(t,{size:18}),e.jsx("span",{className:"text-sm font-medium",children:s.label})]},s.id)})})]}),e.jsxs("div",{className:"flex-1 flex flex-col min-h-0",children:[e.jsx("div",{className:"sm:hidden flex items-center border-b border-[#dde3eb] bg-slate-50 overflow-x-auto no-scrollbar px-2",children:Z.map(s=>{const t=s.icon;return e.jsxs("button",{onClick:()=>ne(s.id),className:`flex flex-col items-center gap-0.5 px-3 py-2.5 shrink-0 text-xs font-medium border-b-2 transition-colors ${b===s.id?"border-sky-600 text-sky-700":"border-transparent text-slate-500"}`,children:[e.jsx(t,{size:16}),e.jsx("span",{className:"whitespace-nowrap",children:s.label})]},s.id)})}),e.jsxs("div",{className:"flex items-center justify-between px-4 sm:px-6 py-3 sm:py-4 border-b border-[#dde3eb]",children:[e.jsx("h3",{className:"text-base sm:text-lg font-display font-bold text-[#0a1628]",children:Z.find(s=>s.id===b)?.label}),e.jsx("button",{onClick:se,className:"p-2 hover:bg-[#edf1f7] rounded-xl transition-colors",children:e.jsx(Ne,{size:20,className:"text-[#5a6578]"})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-4 sm:p-6",children:[b==="account"&&e.jsxs("div",{className:"space-y-6",children:[e.jsx(is,{uid:l.uid,photoURL:l.photo,displayName:l.name,onUploaded:s=>h(t=>({...t,photo:s}))}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-bold text-[#5a6578] mb-2 block font-body uppercase tracking-wider text-xs",children:"Full Name"}),e.jsx(n,{type:"text",value:l.name||"",onChange:s=>h(t=>({...t,name:s.target.value})),maxLength:100,autoComplete:"name",className:"max-w-md"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-bold text-[#5a6578] mb-2 block font-body uppercase tracking-wider text-xs",children:"Email Address"}),e.jsxs("div",{className:"flex items-center gap-2 max-w-md",children:[e.jsx(n,{type:"email",value:l.email||"",disabled:!0,className:"flex-1 bg-slate-100"}),e.jsx(p,{variant:"outline",size:"sm",onClick:()=>ee("email"),children:"Change"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-bold text-[#5a6578] mb-2 block font-body uppercase tracking-wider text-xs",children:"Phone Number"}),e.jsx(n,{type:"tel",value:l.phone||"",onChange:s=>h(t=>({...t,phone:s.target.value})),maxLength:20,inputMode:"tel",autoComplete:"tel",pattern:"^\\+?[0-9 ()\\-.]{7,20}$",placeholder:"+63 912 345 6789",className:"max-w-md"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-bold text-[#5a6578] mb-2 block font-body uppercase tracking-wider text-xs",children:"Gender"}),e.jsxs(ss,{value:l.gender||"",onValueChange:s=>h(t=>({...t,gender:s})),children:[e.jsx(ts,{className:"max-w-md bg-white border-[#dde3eb] rounded-lg",children:e.jsx(as,{placeholder:"Select gender (optional)"})}),e.jsxs(ns,{children:[e.jsx(te,{value:"male",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(rs,{className:"size-4 text-blue-500"}),e.jsx("span",{children:"Male"})]})}),e.jsx(te,{value:"female",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ls,{className:"size-4 text-pink-500"}),e.jsx("span",{children:"Female"})]})}),e.jsx(te,{value:"prefer_not_to_say",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(cs,{className:"size-4 text-gray-500"}),e.jsx("span",{children:"Prefer not to say"})]})})]})]})]}),o==="student"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-bold text-[#5a6578] mb-2 block font-body uppercase tracking-wider text-xs",children:"LRN"}),e.jsx(n,{value:l.lrn||"",onChange:s=>h(t=>({...t,lrn:s.target.value})),className:"max-w-md"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-bold text-[#5a6578] mb-2 block font-body uppercase tracking-wider text-xs",children:"Grade Level"}),e.jsx(n,{value:l.grade||"",onChange:s=>h(t=>({...t,grade:s.target.value})),className:"max-w-md"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-bold text-[#5a6578] mb-2 block font-body uppercase tracking-wider text-xs",children:"Section"}),e.jsx(n,{value:l.section||"",onChange:s=>h(t=>({...t,section:s.target.value})),className:"max-w-md"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-bold text-[#5a6578] mb-2 block font-body uppercase tracking-wider text-xs",children:"School"}),e.jsx(n,{value:l.school||"",onChange:s=>h(t=>({...t,school:s.target.value})),className:"max-w-md"})]})]}),o==="teacher"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-bold text-[#5a6578] mb-2 block font-body uppercase tracking-wider text-xs",children:"Department"}),e.jsx(n,{value:l.department||"",onChange:s=>h(t=>({...t,department:s.target.value})),className:"max-w-md"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-bold text-[#5a6578] mb-2 block font-body uppercase tracking-wider text-xs",children:"Subject"}),e.jsx(n,{value:l.subject||"",onChange:s=>h(t=>({...t,subject:s.target.value})),className:"max-w-md"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-bold text-[#5a6578] mb-2 block font-body uppercase tracking-wider text-xs",children:"Years of Experience"}),e.jsx(n,{value:l.yearsOfExperience||"",onChange:s=>h(t=>({...t,yearsOfExperience:s.target.value})),className:"max-w-md"})]})]}),o==="admin"&&e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-bold text-[#5a6578] mb-2 block font-body uppercase tracking-wider text-xs",children:"Position"}),e.jsx(n,{value:l.position||"",onChange:s=>h(t=>({...t,position:s.target.value})),className:"max-w-md"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-bold text-[#5a6578] mb-2 block font-body uppercase tracking-wider text-xs",children:"Change Password"}),e.jsxs(p,{variant:"outline",className:"rounded-xl",onClick:()=>ee("password"),children:[e.jsx(Be,{size:16,className:"mr-2"}),"Update Password"]})]})]}),b==="notifications"&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-[#dde3eb]",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-[#0a1628] font-body",children:"Push Notifications"}),e.jsx("p",{className:"text-xs text-slate-500 mt-1",children:"Get notified on your device"})]}),e.jsx(x,{checked:i.notifications.pushNotifications,onCheckedChange:s=>c(t=>({...t,notifications:{...t.notifications,pushNotifications:s}}))})]}),e.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-[#dde3eb]",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-[#0a1628] font-body",children:"Sound Effects"}),e.jsx("p",{className:"text-xs text-slate-500 mt-1",children:"Play sounds for notifications"})]}),e.jsx(x,{checked:i.notifications.soundEnabled,onCheckedChange:s=>c(t=>({...t,notifications:{...t.notifications,soundEnabled:s}}))})]}),o==="teacher"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-[#dde3eb]",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-[#0a1628] font-body",children:"Student Submissions"}),e.jsx("p",{className:"text-xs text-slate-500 mt-1",children:"Notify when students submit work"})]}),e.jsx(x,{checked:w.notifyOnSubmission,onCheckedChange:s=>C(t=>({...t,notifyOnSubmission:s}))})]}),e.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-[#dde3eb]",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-[#0a1628] font-body",children:"Student Activity Alerts"}),e.jsx("p",{className:"text-xs text-slate-500 mt-1",children:"Notify on at-risk student activity"})]}),e.jsx(x,{checked:w.notifyOnStudentActivity,onCheckedChange:s=>C(t=>({...t,notifyOnStudentActivity:s}))})]})]}),e.jsxs("div",{className:"pt-4",children:[e.jsx("h4",{className:"text-sm font-bold text-[#0a1628] mb-3 font-body",children:"Notification Types"}),e.jsx("div",{className:"space-y-3",children:[{key:"quizReminders",label:"Quiz Reminders"},{key:"newContent",label:"New Content"},{key:"achievements",label:"Achievements"},{key:"streakAlerts",label:"Streak Alerts"},{key:"weeklySummary",label:"Weekly Summary"}].map(s=>e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("input",{type:"checkbox",checked:i.notifications.notificationTypes[s.key],onChange:t=>c(N=>({...N,notifications:{...N.notifications,notificationTypes:{...N.notifications.notificationTypes,[s.key]:t.target.checked}}})),className:"w-4 h-4 rounded border-[#dde3eb] text-sky-600 focus:ring-sky-500"}),e.jsx("span",{className:"text-sm text-[#0a1628] font-body",children:s.label})]},s.key))})]}),e.jsxs("div",{className:"pt-4 border-t border-[#dde3eb]",children:[e.jsx("h4",{className:"text-sm font-bold text-[#0a1628] mb-1 font-body",children:"Push Notification Categories"}),e.jsx("p",{className:"text-xs text-slate-500 mb-3",children:"Choose which kinds of pushes you want to receive on this device."}),e.jsxs("div",{className:"flex items-center justify-between py-2 mb-2 border-b border-[#dde3eb]",children:[e.jsxs("div",{children:[e.jsx("h5",{className:"text-sm font-bold text-[#0a1628] font-body",children:"Enable Push (master)"}),e.jsx("p",{className:"text-xs text-slate-500 mt-0.5",children:"Turn off to silence ALL push categories."})]}),e.jsx(x,{checked:i.pushPreferences.pushEnabled,onCheckedChange:s=>c(t=>({...t,pushPreferences:{...t.pushPreferences,pushEnabled:s}}))})]}),e.jsx("div",{className:"space-y-2",children:[{key:"achievement",label:"Achievements unlocked",icon:Xe},{key:"quiz_battle",label:"Quiz battle invites & results",icon:Ye},{key:"daily_reward",label:"Daily reward reminders",icon:os},{key:"assignment",label:"New assignments / deadlines",icon:ps},{key:"streak_reminder",label:"Streak reminders",icon:Qe},{key:"leaderboard",label:"Leaderboard updates",icon:ds},{key:"system",label:"System announcements",icon:xs}].map(s=>{const t=s.key,N=s.icon;return e.jsxs("label",{className:"flex items-center justify-between py-1.5",children:[e.jsxs("span",{className:"text-sm text-[#0a1628] font-body flex items-center gap-2",children:[e.jsx(N,{className:"h-4 w-4 text-[#6c47ff]"}),s.label]}),e.jsx(x,{checked:!!i.pushPreferences[t],onCheckedChange:pe=>c(O=>({...O,pushPreferences:{...O.pushPreferences,[s.key]:pe}})),disabled:!i.pushPreferences.pushEnabled&&t!=="pushEnabled"})]},s.key)})}),e.jsx("div",{className:"mt-4",children:e.jsxs(p,{type:"button",variant:"outline",size:"sm",onClick:async()=>{try{const{requestPushPermissionAndRegister:s}=await G(async()=>{const{requestPushPermissionAndRegister:S}=await import("./index-Bp7MiGcW.js").then(A=>A.b9);return{requestPushPermissionAndRegister:S}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11])),{auth:t}=await G(async()=>{const{auth:S}=await import("./index-Bp7MiGcW.js").then(A=>A.b7);return{auth:S}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11])),N=t.currentUser?.uid;if(!N){d.error("You must be signed in to test push notifications.");return}if(!await s(N)){d.error("Push setup failed. Check that VITE_FIREBASE_VAPID_KEY is configured and notifications are allowed.");return}const{httpsCallable:O}=await G(async()=>{const{httpsCallable:S}=await import("./vendor-firebase-core-D7GXCeNu.js").then(A=>A.a9);return{httpsCallable:S}},[]),{cloudFunctions:Te}=await G(async()=>{const{cloudFunctions:S}=await import("./index-Bp7MiGcW.js").then(A=>A.b7);return{cloudFunctions:S}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11])),ye=(await O(Te,"sendTestPush")({}))?.data?.sent??0;ye>0?d.success(`Sent test push to ${ye} device(s).`):d.message("No active devices found. Enable browser notifications first.")}catch(s){d.error(s instanceof Error?s.message:"Failed to send test push")}},children:[e.jsx(ge,{size:14,className:"mr-2"}),"Send test push"]})})]}),e.jsxs("div",{className:"pt-4 border-t border-[#dde3eb]",children:[e.jsxs("label",{className:"text-sm font-bold text-[#5a6578] mb-2 block font-body uppercase tracking-wider text-xs",children:[e.jsx(ms,{size:16,className:"inline mr-2"}),"Quiet Hours"]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(n,{type:"time",value:i.notifications.quietHours.start,onChange:s=>c(t=>({...t,notifications:{...t.notifications,quietHours:{...t.notifications.quietHours,start:s.target.value}}})),className:"w-32"}),e.jsx("span",{className:"text-[#5a6578]",children:"to"}),e.jsx(n,{type:"time",value:i.notifications.quietHours.end,onChange:s=>c(t=>({...t,notifications:{...t.notifications,quietHours:{...t.notifications.quietHours,end:s.target.value}}})),className:"w-32"})]})]})]}),b==="appearance"&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-[#dde3eb]",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-[#0a1628] font-body",children:"Dark Mode"}),e.jsx("p",{className:"text-xs text-slate-500 mt-1",children:"Toggle dark theme"})]}),e.jsx(x,{checked:i.appearance.darkMode,onCheckedChange:s=>c(t=>({...t,appearance:{...t.appearance,darkMode:s}}))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-bold text-[#5a6578] mb-3 block font-body uppercase tracking-wider text-xs",children:"Font Size"}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("span",{className:"text-xs text-slate-500",children:"Small"}),e.jsx("input",{type:"range",min:"12",max:"20",value:i.appearance.fontSize,onChange:s=>c(t=>({...t,appearance:{...t.appearance,fontSize:Number(s.target.value)}})),className:"flex-1"}),e.jsx("span",{className:"text-xs text-slate-500",children:"Large"}),e.jsxs("span",{className:"text-xs font-mono text-slate-600 w-8",children:[i.appearance.fontSize,"px"]})]})]}),e.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-[#dde3eb]",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-[#0a1628] font-body",children:"Compact View"}),e.jsx("p",{className:"text-xs text-slate-500 mt-1",children:"Show more content on screen"})]}),e.jsx(x,{checked:i.appearance.compactView,onCheckedChange:s=>c(t=>({...t,appearance:{...t.appearance,compactView:s}}))})]}),e.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-[#dde3eb]",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-[#0a1628] font-body",children:"Reduce Animations"}),e.jsx("p",{className:"text-xs text-slate-500 mt-1",children:"Minimize motion effects"})]}),e.jsx(x,{checked:i.appearance.reduceAnimations,onCheckedChange:s=>c(t=>({...t,appearance:{...t.appearance,reduceAnimations:s}}))})]})]}),b==="privacy"&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-[#dde3eb]",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-[#0a1628] font-body",children:"Profile Visibility"}),e.jsx("p",{className:"text-xs text-slate-500 mt-1",children:"Who can see your profile"})]}),e.jsxs("select",{value:i.privacy.profileVisibility,onChange:s=>c(t=>({...t,privacy:{...t.privacy,profileVisibility:s.target.value}})),className:"px-3 py-2 border border-[#dde3eb] rounded-lg text-sm bg-white text-[#0a1628]",children:[e.jsx("option",{value:"everyone",children:"Everyone"}),e.jsx("option",{value:"students_and_staff",children:"Students and Staff"}),e.jsx("option",{value:"private",children:"Private"})]})]}),e.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-[#dde3eb]",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-[#0a1628] font-body",children:"Show Activity Status"}),e.jsx("p",{className:"text-xs text-slate-500 mt-1",children:"Let others see when you're online"})]}),e.jsx(x,{checked:i.privacy.showActivityStatus,onCheckedChange:s=>c(t=>({...t,privacy:{...t.privacy,showActivityStatus:s}}))})]}),e.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-[#dde3eb]",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-[#0a1628] font-body",children:"Data Sharing"}),e.jsx("p",{className:"text-xs text-slate-500 mt-1",children:"Share anonymous usage data"})]}),e.jsx(x,{checked:i.privacy.dataSharing,onCheckedChange:s=>c(t=>({...t,privacy:{...t.privacy,dataSharing:s}}))})]})]}),b==="learning"&&o==="student"&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-bold text-[#5a6578] mb-2 block font-body uppercase tracking-wider text-xs",children:"Daily XP Goal"}),e.jsx(n,{type:"number",value:i.learning.dailyXpGoal,onChange:s=>c(t=>({...t,learning:{...t.learning,dailyXpGoal:Number(s.target.value||0)}})),className:"max-w-xs"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-bold text-[#5a6578] mb-2 block font-body uppercase tracking-wider text-xs",children:"Preferred Study Time"}),e.jsxs("select",{value:i.learning.preferredStudyTime,onChange:s=>c(t=>({...t,learning:{...t.learning,preferredStudyTime:s.target.value}})),className:"px-3 py-2 border border-[#dde3eb] rounded-lg text-sm w-full max-w-xs bg-white text-[#0a1628]",children:[e.jsx("option",{value:"morning",children:"Morning (6AM - 12PM)"}),e.jsx("option",{value:"afternoon",children:"Afternoon (12PM - 6PM)"}),e.jsx("option",{value:"evening",children:"Evening (6PM - 12PM)"}),e.jsx("option",{value:"night",children:"Night (12AM - 6AM)"})]})]}),e.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-[#dde3eb]",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-[#0a1628] font-body",children:"Auto-play Next Lesson"}),e.jsx("p",{className:"text-xs text-slate-500 mt-1",children:"Automatically start the next lesson"})]}),e.jsx(x,{checked:i.learning.autoPlayLessons,onCheckedChange:s=>c(t=>({...t,learning:{...t.learning,autoPlayLessons:s}}))})]}),e.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-[#dde3eb]",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-[#0a1628] font-body",children:"Show Hints During Quizzes"}),e.jsx("p",{className:"text-xs text-slate-500 mt-1",children:"Display helpful hints for questions"})]}),e.jsx(x,{checked:i.learning.showHints,onCheckedChange:s=>c(t=>({...t,learning:{...t.learning,showHints:s}}))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-bold text-[#5a6578] mb-2 block font-body uppercase tracking-wider text-xs",children:"Quiz Difficulty Preference"}),e.jsxs("select",{value:i.learning.quizDifficultyPreference,onChange:s=>c(t=>({...t,learning:{...t.learning,quizDifficultyPreference:s.target.value}})),className:"px-3 py-2 border border-[#dde3eb] rounded-lg text-sm w-full max-w-xs bg-white text-[#0a1628]",children:[e.jsx("option",{value:"adaptive",children:"Adaptive (Recommended)"}),e.jsx("option",{value:"easy",children:"Easy"}),e.jsx("option",{value:"medium",children:"Medium"}),e.jsx("option",{value:"hard",children:"Hard"})]})]}),e.jsxs("div",{className:"pt-4 border-t border-[#dde3eb]",children:[e.jsxs("label",{className:"text-sm font-bold text-[#5a6578] mb-2 block font-body uppercase tracking-wider text-xs",children:[e.jsx(ks,{size:16,className:"inline mr-2"}),"Study Reminders"]}),e.jsx(n,{type:"time",value:i.learning.studyReminderTime,onChange:s=>c(t=>({...t,learning:{...t.learning,studyReminderTime:s.target.value}})),className:"w-32"})]})]}),b==="teaching"&&o==="teacher"&&e.jsxs("div",{className:"space-y-6",children:[e.jsx("h4",{className:"text-sm font-bold text-[#0a1628] font-body",children:"Quiz Defaults"}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-[#5a6578] block mb-1",children:"Time Limit (min)"}),e.jsx(n,{type:"number",value:w.quizDefaults.timeLimitMinutes,onChange:s=>C(t=>({...t,quizDefaults:{...t.quizDefaults,timeLimitMinutes:Number(s.target.value)}}))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-[#5a6578] block mb-1",children:"Passing Score (%)"}),e.jsx(n,{type:"number",value:w.quizDefaults.passingScore,onChange:s=>C(t=>({...t,quizDefaults:{...t.quizDefaults,passingScore:Number(s.target.value)}}))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-[#5a6578] block mb-1",children:"Max Attempts"}),e.jsx(n,{type:"number",value:w.quizDefaults.maxAttempts,onChange:s=>C(t=>({...t,quizDefaults:{...t.quizDefaults,maxAttempts:Number(s.target.value)}}))})]})]}),e.jsx("h4",{className:"text-sm font-bold text-[#0a1628] font-body pt-4",children:"Class Preferences"}),e.jsxs("div",{className:"flex items-center justify-between py-3 border-t border-[#dde3eb]",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-[#0a1628] font-body",children:"Student Analytics Visibility"}),e.jsx("p",{className:"text-xs text-slate-500 mt-1",children:"Let students see their leaderboard rank"})]}),e.jsx(x,{checked:w.studentAnalyticsVisibility,onCheckedChange:s=>C(t=>({...t,studentAnalyticsVisibility:s}))})]})]}),b==="system"&&o==="admin"&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-[#dde3eb]",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-[#0a1628] font-body",children:"Maintenance Mode"}),e.jsx("p",{className:"text-xs text-slate-500 mt-1",children:"Disable platform access for non-admins"})]}),e.jsx(x,{checked:j.maintenanceMode,onCheckedChange:s=>$(t=>({...t,maintenanceMode:s}))})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-[#5a6578] block mb-1",children:"Default Grade Level"}),e.jsx(n,{value:j.defaultGradeLevel,disabled:!0})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-[#5a6578] block mb-1",children:"Default Curriculum"}),e.jsx(n,{value:j.defaultCurriculum,disabled:!0})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-[#5a6578] block mb-1",children:"Max Class Size"}),e.jsx(n,{type:"number",value:j.maxClassSize,disabled:!0})]})]}),e.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-[#dde3eb]",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-[#0a1628] font-body",children:"Audit Log Visible"}),e.jsx("p",{className:"text-xs text-slate-500 mt-1",children:"Show audit logs in admin dashboard"})]}),e.jsx(x,{checked:j.auditLogVisible,onCheckedChange:s=>$(t=>({...t,auditLogVisible:s}))})]}),e.jsx("h4",{className:"text-sm font-bold text-[#0a1628] font-body pt-4",children:"AI Configuration"}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-[#5a6578] block mb-1",children:"Model Name"}),e.jsx(n,{value:j.aiConfig.modelName,disabled:!0})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-[#5a6578] block mb-1",children:"Temperature"}),e.jsx(n,{type:"number",value:j.aiConfig.temperature,disabled:!0})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx("label",{className:"text-xs text-[#5a6578] block mb-1",children:"API Endpoint"}),e.jsx(n,{value:j.aiConfig.endpoint,disabled:!0})]})]})]}),b==="data"&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"p-4 bg-sky-50 border border-sky-200 rounded-xl",children:[e.jsx("h4",{className:"text-sm font-bold text-sky-900 mb-1 font-body",children:"Download Your Data"}),e.jsx("p",{className:"text-xs text-sky-700 mb-3",children:"Export all your learning data and progress"}),e.jsxs(p,{variant:"outline",size:"sm",className:"rounded-xl",onClick:Pe,disabled:X,children:[e.jsx(ve,{size:16,className:"mr-2"}),X?"Exporting...":"Request Data Export"]})]}),e.jsxs("div",{className:"p-4 bg-white border border-[#dde3eb] rounded-xl",children:[e.jsx("h4",{className:"text-sm font-bold text-[#0a1628] mb-1 font-body",children:"Clear Cache"}),e.jsx("p",{className:"text-xs text-[#5a6578] mb-3",children:"Free up space by clearing cached data"}),e.jsx(p,{variant:"outline",size:"sm",className:"rounded-xl",onClick:ze,disabled:Y,children:Y?"Clearing...":"Clear Cache"})]}),e.jsxs("div",{className:"p-4 bg-rose-50 border border-rose-200 rounded-xl",children:[e.jsx("h4",{className:"text-sm font-bold text-rose-900 mb-1",children:"Reset Progress"}),e.jsxs("p",{className:"text-xs text-rose-700 mb-3",children:[o==="student"&&"Reset quizzes, diagnostic state, XP, and learning progress for retesting.",o==="teacher"&&"Reset imported records, managed classrooms, and teacher-generated quiz artifacts.",o==="admin"&&"Reset admin testing artifacts like personal audit/content update records."]}),e.jsx(p,{variant:"outline",size:"sm",className:"rounded-xl text-rose-700 border-rose-300",disabled:!E||q,onClick:()=>I(!0),children:q?"Resetting...":"Reset Testing Data"})]}),e.jsxs("div",{className:"p-4 bg-red-50 border border-red-200 rounded-xl",children:[e.jsx("h4",{className:"text-sm font-bold text-red-900 mb-1",children:"Delete Account"}),e.jsx("p",{className:"text-xs text-red-700 mb-3",children:"Permanently delete your account and all data"}),e.jsxs(p,{variant:"outline",size:"sm",className:"rounded-xl text-red-700 border-red-300",onClick:()=>F(!0),disabled:de,children:[e.jsx(hs,{size:16,className:"mr-2"}),de?"Deleting...":"Delete Account"]})]})]})]}),e.jsxs("div",{className:"shrink-0 px-4 sm:px-6 py-3 sm:py-4 border-t border-[#dde3eb] bg-[#edf1f7] flex flex-col sm:flex-row items-stretch sm:items-center justify-between gap-2 sm:gap-0",children:[e.jsx("p",{className:"text-xs text-slate-500 font-body text-center sm:text-left",children:"MathPulse AI v2.1.0"}),e.jsxs("div",{className:"flex gap-2 w-full sm:w-auto",children:[e.jsx(p,{variant:"outline",onClick:se,className:"rounded-lg border-[#dde3eb] flex-1 sm:flex-none",disabled:B,children:"Cancel"}),e.jsx(p,{onClick:Ee,className:"rounded-lg bg-sky-600 hover:bg-sky-700 text-white flex-1 sm:flex-none",disabled:B,children:B?"Saving...":"Save Changes"})]})]})]})]})]}),Se&&e.jsx(H.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-[130] bg-black/50 backdrop-blur-sm flex items-center justify-center p-4",onClick:()=>{v||P(!1)},children:e.jsxs(H.div,{initial:{opacity:0,scale:.95,y:12},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:12},transition:{duration:.2},className:"w-full max-w-md rounded-2xl border border-[#dde3eb] bg-[#f7f9fc] shadow-2xl",onClick:s=>s.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-[#dde3eb] px-6 py-4",children:[e.jsxs("h4",{className:"text-lg font-display font-bold text-[#0a1628]",children:[f==="password"&&"Change Password",f==="email"&&"Change Email",f==="delete"&&"Delete Account"]}),e.jsx("button",{onClick:()=>{v||P(!1)},className:"p-2 rounded-xl hover:bg-[#edf1f7] transition-colors","aria-label":"Close",children:e.jsx(Ne,{size:18,className:"text-[#5a6578]"})})]}),e.jsxs("div",{className:"px-6 py-5 space-y-4",children:[e.jsx("p",{className:"text-sm text-[#5a6578]",children:"Enter your current password to continue."}),e.jsxs("div",{className:"relative",children:[e.jsx(n,{type:Q?"text":"password",value:L,onChange:s=>xe(s.target.value),placeholder:"Current password",autoFocus:!0,className:"pr-10",disabled:v,onKeyDown:s=>{s.key==="Enter"&&fe()}}),e.jsx("button",{type:"button",onClick:()=>he(!Q),className:"absolute right-3 top-1/2 -translate-y-1/2 text-slate-400 hover:text-slate-600",tabIndex:-1,children:Q?e.jsx(us,{size:16}):e.jsx(bs,{size:16})})]}),f==="password"&&e.jsx("div",{className:"relative",children:e.jsx(n,{type:"password",value:W,onChange:s=>ue(s.target.value),placeholder:"New password (min 8 chars)",disabled:v})}),f==="email"&&e.jsx(n,{type:"email",value:V,onChange:s=>be(s.target.value),placeholder:"New email address",disabled:v}),f==="delete"&&e.jsx("p",{className:"text-sm text-red-600 font-medium",children:"This action is permanent and cannot be undone."}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(p,{variant:"outline",onClick:()=>P(!1),disabled:v,children:"Cancel"}),e.jsx(p,{onClick:()=>void fe(),className:f==="delete"?"bg-red-600 hover:bg-red-700 text-white":"bg-sky-600 hover:bg-sky-700 text-white",disabled:v,children:v?"Processing...":f==="delete"?"Delete Forever":"Confirm"})]})]})]})}),e.jsx(je,{isOpen:we,onClose:()=>I(!1),onConfirm:Re,title:"Reset Testing Data?",message:`Reset ${o} testing data? This will clear quizzes, diagnostic assessments, assessment history, XP, and learning progress. This action cannot be undone.`,confirmText:q?"Resetting...":"Reset Data",cancelText:"Cancel",type:"warning",icon:"warning",zIndexClass:"z-[130]"}),e.jsx(je,{isOpen:Ce,onClose:()=>F(!1),onConfirm:_e,title:"Delete Account?",message:"You will need to re-authenticate to permanently delete your account. This cannot be undone.",confirmText:"Continue",cancelText:"Cancel",type:"danger",icon:"delete",zIndexClass:"z-[130]"})]})}):null};export{rt as default}; diff --git a/assets/Sidebar-bryEim00.js b/assets/Sidebar-BzRsh0CN.js similarity index 94% rename from assets/Sidebar-bryEim00.js rename to assets/Sidebar-BzRsh0CN.js index 11dde2cb1435b25b81ea106ace5438447af124fe..a0d4a7b1f1809d013a10d1c37d11453f8c33c439 100644 --- a/assets/Sidebar-bryEim00.js +++ b/assets/Sidebar-BzRsh0CN.js @@ -1,4 +1,4 @@ -import{r as x,j as e}from"./vendor-react-B4AQeu28.js";import{S as $,a as B,L as u,D,M as G}from"./LogoutActionButton-ke8I5kxg.js";import{e as z,m as c,o as P,U as M,G as N,b as m,V as q,a2 as F,F as U}from"./index-BufUS6SI.js";import{T as S,a as L,b as C}from"./tooltip-qcWo8nUO.js";import{X as Q}from"./x-BuBjuj2Y.js";import{C as V}from"./chevron-right-DADygX42.js";import{C as W}from"./chevron-left-DMbkPbec.js";import{C as A}from"./chart-column-BcVJ31XT.js";import{S as R}from"./shirt-18q8_SAr.js";/** +import{r as x,j as e}from"./vendor-react-B4AQeu28.js";import{S as $,a as B,L as u,D,M as G}from"./LogoutActionButton-BlHbD8Uf.js";import{e as z,m as c,o as P,U as M,G as N,b as m,V as q,a2 as F,F as U}from"./index-Bp7MiGcW.js";import{T as S,a as L,b as C}from"./tooltip-nLNeX3nd.js";import{X as Q}from"./x-k8d6VLEw.js";import{C as V}from"./chevron-right-BxoysOas.js";import{C as W}from"./chevron-left-Be5knpOV.js";import{C as A}from"./chart-column-Dyv8TfXk.js";import{S as R}from"./shirt-C1GQiNvP.js";/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. diff --git a/assets/SupplementalBanner-BtyN_3ih.js b/assets/SupplementalBanner-BiW4WQHX.js similarity index 97% rename from assets/SupplementalBanner-BtyN_3ih.js rename to assets/SupplementalBanner-BiW4WQHX.js index 8162d1a56fe6b78b73c7b9c27b291df15eead3cd..148e40ccd1e21fea46b5e41a92e79f3d647070f8 100644 --- a/assets/SupplementalBanner-BtyN_3ih.js +++ b/assets/SupplementalBanner-BiW4WQHX.js @@ -1 +1 @@ -import{j as e,r as y}from"./vendor-react-B4AQeu28.js";import{h as j,m as p,y as h,b as f,T as m,B as x}from"./index-BufUS6SI.js";import{X as v}from"./x-BuBjuj2Y.js";import{S as w}from"./sparkles-DYlMf97S.js";import{C as g}from"./chevron-right-DADygX42.js";import"./vendor-firebase-firestore-CNv3xXal.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-radix-C5nwdvGr.js";import"./vendor-charts-CAmziV1y.js";import"./vendor-markdown-yqZQ_iQm.js";const b={"General Mathematics":[{label:"Functions Deep Dive",description:"Interactive review of function types and graphs",icon:e.jsx(m,{size:14})},{label:"Business Math Basics",description:"Simple & compound interest practice",icon:e.jsx(f,{size:14})}],"Statistics and Probability":[{label:"Distribution Visualizer",description:"Explore normal distribution curves",icon:e.jsx(m,{size:14})},{label:"Hypothesis Practice",description:"Step-by-step hypothesis testing",icon:e.jsx(x,{size:14})}],"Pre-Calculus":[{label:"Conic Sections Explorer",description:"Visual parabola, ellipse, hyperbola tool",icon:e.jsx(m,{size:14})},{label:"Trig Identity Practice",description:"Identity verification drill set",icon:e.jsx(x,{size:14})}],"Basic Calculus":[{label:"Limits Visualizer",description:"Graphical approach to limits",icon:e.jsx(m,{size:14})},{label:"Derivative Rules Drill",description:"Practice chain rule & implicit diff",icon:e.jsx(x,{size:14})}]};function u(i){const s=i.toLowerCase();return s==="functions"||s.includes("function")||s==="businessmath"||s.includes("business")||s==="logic"||s.includes("reason")||s.includes("general")||s.includes("gen-math")||s.includes("gen math")?"General Mathematics":s.includes("stat")||s.includes("prob")?"Statistics and Probability":s.includes("pre-calc")||s.includes("pre calc")||s.includes("precalc")?"Pre-Calculus":s.includes("basic")||s.includes("calc")?"Basic Calculus":null}function N(i){const s=i.trim().toLowerCase();return s==="functions"?"Functions and Graphs":s==="businessmath"?"Business and Financial Mathematics":s==="logic"?"Logic and Reasoning":i}const k=({atRiskSubjects:i=[],onAction:s,onDismiss:n})=>{const[l,a]=y.useState(!1);if(l||i.length===0)return null;const r=()=>{a(!0),n?.()};return e.jsx(j,{children:!l&&e.jsx(p.div,{initial:{opacity:0,y:-10,height:0},animate:{opacity:1,y:0,height:"auto"},exit:{opacity:0,y:-10,height:0},className:"overflow-hidden",children:e.jsxs("div",{className:"relative bg-gradient-to-r from-sky-600 via-sky-500 to-sky-600 rounded-2xl p-5 text-white shadow-lg shadow-sky-500/20",children:[e.jsx("button",{onClick:r,className:"absolute top-3 right-3 w-7 h-7 bg-white/20 hover:bg-white/30 rounded-full flex items-center justify-center transition-colors",children:e.jsx(v,{size:14})}),e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"w-12 h-12 bg-white/20 rounded-xl flex items-center justify-center flex-shrink-0",children:e.jsx(w,{size:24})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"font-bold text-lg mb-1",children:"Supplemental Materials Available"}),e.jsx("p",{className:"text-sky-100 text-sm mb-3",children:"Based on your diagnostic assessment, we've identified topics that could use extra practice. Strengthening these areas will improve your overall performance."}),e.jsx("div",{className:"flex flex-wrap gap-2 mb-3",children:i.map(t=>e.jsxs("span",{className:"inline-flex items-center gap-1.5 bg-white/20 backdrop-blur-sm px-3 py-1 rounded-full text-xs font-semibold",children:[e.jsx(h,{size:12}),N(t)]},t))}),e.jsxs("button",{onClick:s,className:"inline-flex items-center gap-2 bg-white text-sky-600 font-bold text-sm px-4 py-2 rounded-xl hover:bg-sky-50 transition-colors",children:["Review Topics",e.jsx(g,{size:16})]})]})]})]})})})},z=({quizSubject:i,atRiskSubjects:s=[]})=>{const n=i?u(i):null;if(!s.some(r=>{const t=u(r);return t&&t===n})||!n)return null;const a=b[n]||[];return e.jsx(p.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},className:"mb-4 overflow-hidden",children:e.jsxs("div",{className:"bg-gradient-to-r from-rose-50 to-orange-50 border border-rose-200 rounded-xl p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[e.jsx(h,{size:14,className:"text-rose-600"}),e.jsxs("span",{className:"text-xs font-bold text-rose-800",children:["Supplemental Focus Area — ",n]})]}),e.jsx("p",{className:"text-xs text-rose-700 mb-2",children:"This topic was flagged in your diagnostic. Take your time and review the explanations carefully."}),a.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5",children:a.slice(0,2).map((r,t)=>e.jsxs("span",{className:"inline-flex items-center gap-1 bg-rose-100 text-rose-700 px-2 py-0.5 rounded-md text-xs font-medium",children:[r.icon,r.label]},t))})]})})},C=({quizSubject:i,quizScore:s=0,atRiskSubjects:n=[],onAction:l})=>{const a=i?u(i):null,r=n.some(c=>{const d=u(c);return d&&d===a});if(s>=70&&!r)return null;const t=a?b[a]||[]:[],o=s<70;return e.jsx(p.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:.5},className:"mt-4",children:e.jsx("div",{className:`rounded-2xl p-4 border-2 ${o?"bg-orange-50 border-orange-200":"bg-sky-50 border-sky-200"}`,children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:`w-10 h-10 rounded-xl flex items-center justify-center flex-shrink-0 ${o?"bg-orange-500":"bg-sky-500"}`,children:e.jsx(f,{size:20,className:"text-white"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h4",{className:"font-display font-bold text-[#0a1628] text-sm mb-1",children:o?"Review Recommended":"Supplemental Materials"}),e.jsx("p",{className:"text-xs text-[#5a6578] mb-2",children:o?`You scored ${s}% on this quiz. We recommend reviewing the following resources to strengthen your understanding.`:"This topic was identified as an area for growth. Check out these additional resources."}),t.length>0&&e.jsx("div",{className:"space-y-1.5 mb-3",children:t.map((c,d)=>e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("span",{className:`w-5 h-5 rounded flex items-center justify-center ${o?"bg-orange-100 text-orange-600":"bg-sky-100 text-sky-600"}`,children:c.icon}),e.jsx("span",{className:"font-medium text-[#0a1628]",children:c.label}),e.jsxs("span",{className:"text-slate-500",children:["— ",c.description]})]},d))}),l&&e.jsxs("button",{onClick:l,className:`inline-flex items-center gap-1.5 text-xs font-bold px-3 py-1.5 rounded-lg transition-colors ${o?"bg-orange-500 hover:bg-orange-600 text-white":"bg-sky-500 hover:bg-sky-600 text-white"}`,children:["Review Topics",e.jsx(g,{size:12})]})]})]})})})},I=i=>{switch(i.variant){case"compact":return e.jsx(z,{...i});case"results":return e.jsx(C,{...i});case"full":default:return e.jsx(k,{...i})}};export{I as default}; +import{j as e,r as y}from"./vendor-react-B4AQeu28.js";import{h as j,m as p,y as h,b as f,T as m,B as x}from"./index-Bp7MiGcW.js";import{X as v}from"./x-k8d6VLEw.js";import{S as w}from"./sparkles-fLB3ltj1.js";import{C as g}from"./chevron-right-BxoysOas.js";import"./vendor-firebase-firestore-CNv3xXal.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-radix-C5nwdvGr.js";import"./vendor-charts-CAmziV1y.js";import"./vendor-markdown-yqZQ_iQm.js";const b={"General Mathematics":[{label:"Functions Deep Dive",description:"Interactive review of function types and graphs",icon:e.jsx(m,{size:14})},{label:"Business Math Basics",description:"Simple & compound interest practice",icon:e.jsx(f,{size:14})}],"Statistics and Probability":[{label:"Distribution Visualizer",description:"Explore normal distribution curves",icon:e.jsx(m,{size:14})},{label:"Hypothesis Practice",description:"Step-by-step hypothesis testing",icon:e.jsx(x,{size:14})}],"Pre-Calculus":[{label:"Conic Sections Explorer",description:"Visual parabola, ellipse, hyperbola tool",icon:e.jsx(m,{size:14})},{label:"Trig Identity Practice",description:"Identity verification drill set",icon:e.jsx(x,{size:14})}],"Basic Calculus":[{label:"Limits Visualizer",description:"Graphical approach to limits",icon:e.jsx(m,{size:14})},{label:"Derivative Rules Drill",description:"Practice chain rule & implicit diff",icon:e.jsx(x,{size:14})}]};function u(i){const s=i.toLowerCase();return s==="functions"||s.includes("function")||s==="businessmath"||s.includes("business")||s==="logic"||s.includes("reason")||s.includes("general")||s.includes("gen-math")||s.includes("gen math")?"General Mathematics":s.includes("stat")||s.includes("prob")?"Statistics and Probability":s.includes("pre-calc")||s.includes("pre calc")||s.includes("precalc")?"Pre-Calculus":s.includes("basic")||s.includes("calc")?"Basic Calculus":null}function N(i){const s=i.trim().toLowerCase();return s==="functions"?"Functions and Graphs":s==="businessmath"?"Business and Financial Mathematics":s==="logic"?"Logic and Reasoning":i}const k=({atRiskSubjects:i=[],onAction:s,onDismiss:n})=>{const[l,a]=y.useState(!1);if(l||i.length===0)return null;const r=()=>{a(!0),n?.()};return e.jsx(j,{children:!l&&e.jsx(p.div,{initial:{opacity:0,y:-10,height:0},animate:{opacity:1,y:0,height:"auto"},exit:{opacity:0,y:-10,height:0},className:"overflow-hidden",children:e.jsxs("div",{className:"relative bg-gradient-to-r from-sky-600 via-sky-500 to-sky-600 rounded-2xl p-5 text-white shadow-lg shadow-sky-500/20",children:[e.jsx("button",{onClick:r,className:"absolute top-3 right-3 w-7 h-7 bg-white/20 hover:bg-white/30 rounded-full flex items-center justify-center transition-colors",children:e.jsx(v,{size:14})}),e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"w-12 h-12 bg-white/20 rounded-xl flex items-center justify-center flex-shrink-0",children:e.jsx(w,{size:24})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"font-bold text-lg mb-1",children:"Supplemental Materials Available"}),e.jsx("p",{className:"text-sky-100 text-sm mb-3",children:"Based on your diagnostic assessment, we've identified topics that could use extra practice. Strengthening these areas will improve your overall performance."}),e.jsx("div",{className:"flex flex-wrap gap-2 mb-3",children:i.map(t=>e.jsxs("span",{className:"inline-flex items-center gap-1.5 bg-white/20 backdrop-blur-sm px-3 py-1 rounded-full text-xs font-semibold",children:[e.jsx(h,{size:12}),N(t)]},t))}),e.jsxs("button",{onClick:s,className:"inline-flex items-center gap-2 bg-white text-sky-600 font-bold text-sm px-4 py-2 rounded-xl hover:bg-sky-50 transition-colors",children:["Review Topics",e.jsx(g,{size:16})]})]})]})]})})})},z=({quizSubject:i,atRiskSubjects:s=[]})=>{const n=i?u(i):null;if(!s.some(r=>{const t=u(r);return t&&t===n})||!n)return null;const a=b[n]||[];return e.jsx(p.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},className:"mb-4 overflow-hidden",children:e.jsxs("div",{className:"bg-gradient-to-r from-rose-50 to-orange-50 border border-rose-200 rounded-xl p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[e.jsx(h,{size:14,className:"text-rose-600"}),e.jsxs("span",{className:"text-xs font-bold text-rose-800",children:["Supplemental Focus Area — ",n]})]}),e.jsx("p",{className:"text-xs text-rose-700 mb-2",children:"This topic was flagged in your diagnostic. Take your time and review the explanations carefully."}),a.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5",children:a.slice(0,2).map((r,t)=>e.jsxs("span",{className:"inline-flex items-center gap-1 bg-rose-100 text-rose-700 px-2 py-0.5 rounded-md text-xs font-medium",children:[r.icon,r.label]},t))})]})})},C=({quizSubject:i,quizScore:s=0,atRiskSubjects:n=[],onAction:l})=>{const a=i?u(i):null,r=n.some(c=>{const d=u(c);return d&&d===a});if(s>=70&&!r)return null;const t=a?b[a]||[]:[],o=s<70;return e.jsx(p.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:.5},className:"mt-4",children:e.jsx("div",{className:`rounded-2xl p-4 border-2 ${o?"bg-orange-50 border-orange-200":"bg-sky-50 border-sky-200"}`,children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:`w-10 h-10 rounded-xl flex items-center justify-center flex-shrink-0 ${o?"bg-orange-500":"bg-sky-500"}`,children:e.jsx(f,{size:20,className:"text-white"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h4",{className:"font-display font-bold text-[#0a1628] text-sm mb-1",children:o?"Review Recommended":"Supplemental Materials"}),e.jsx("p",{className:"text-xs text-[#5a6578] mb-2",children:o?`You scored ${s}% on this quiz. We recommend reviewing the following resources to strengthen your understanding.`:"This topic was identified as an area for growth. Check out these additional resources."}),t.length>0&&e.jsx("div",{className:"space-y-1.5 mb-3",children:t.map((c,d)=>e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("span",{className:`w-5 h-5 rounded flex items-center justify-center ${o?"bg-orange-100 text-orange-600":"bg-sky-100 text-sky-600"}`,children:c.icon}),e.jsx("span",{className:"font-medium text-[#0a1628]",children:c.label}),e.jsxs("span",{className:"text-slate-500",children:["— ",c.description]})]},d))}),l&&e.jsxs("button",{onClick:l,className:`inline-flex items-center gap-1.5 text-xs font-bold px-3 py-1.5 rounded-lg transition-colors ${o?"bg-orange-500 hover:bg-orange-600 text-white":"bg-sky-500 hover:bg-sky-600 text-white"}`,children:["Review Topics",e.jsx(g,{size:12})]})]})]})})})},I=i=>{switch(i.variant){case"compact":return e.jsx(z,{...i});case"results":return e.jsx(C,{...i});case"full":default:return e.jsx(k,{...i})}};export{I as default}; diff --git a/assets/SupplementalPillCarousel-0O59RLiu.js b/assets/SupplementalPillCarousel-BpO68D9M.js similarity index 99% rename from assets/SupplementalPillCarousel-0O59RLiu.js rename to assets/SupplementalPillCarousel-BpO68D9M.js index 51ff1b9cf024a383a5ca07026eda302536942d38..a33932609e42478d43c1528c5d224b65ffbb8630 100644 --- a/assets/SupplementalPillCarousel-0O59RLiu.js +++ b/assets/SupplementalPillCarousel-BpO68D9M.js @@ -1,4 +1,4 @@ -import{d as o,r as U,j as r}from"./vendor-react-B4AQeu28.js";import{o as se,h as Qe,m as Ie,y as Se,a as jt,L as Ze,I as et}from"./index-BufUS6SI.js";import{f as Dt}from"./deepseekRagService-Bke9fSTt.js";import{T as Nt,D as Ot,d as It,b as At,c as _t,P as kt,O as Pt}from"./vendor-radix-C5nwdvGr.js";import{w as $t}from"./moduleWatchService-D8kT4330.js";import{C as Lt}from"./circle-alert-DDdeEgNa.js";import{a as Bt,C as Ft}from"./chevron-up-CoNRuMZ7.js";import{B as Gt}from"./bell-D9j1Gy0m.js";import{C as tt}from"./clock-CooTZK0X.js";import{C as Ve}from"./chevron-right-DADygX42.js";import{S as Ht}from"./sparkles-DYlMf97S.js";import{X as qt}from"./x-BuBjuj2Y.js";import"./vendor-firebase-firestore-CNv3xXal.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-charts-CAmziV1y.js";import"./vendor-markdown-yqZQ_iQm.js";const ke=[{topicId:"gm-q1-business-finance",label:"Business and Finance",subjectId:"gen-math",quarter:1,competencyCodes:["GM11-BF-1","GM11-BF-2","GM11-BF-3"]},{topicId:"gm-q1-patterns-sequences-series",label:"Patterns, Sequences, and Series",subjectId:"gen-math",quarter:1,competencyCodes:["GM11-PSS-1","GM11-PSS-2","GM11-PSS-3"]},{topicId:"gm-q1-financial-application-sequences-series",label:"Financial Application of Sequences and Series",subjectId:"gen-math",quarter:1,competencyCodes:["GM11-FASS-1","GM11-FASS-2"]},{topicId:"gm-q2-measurement-conversion",label:"Measurement and Conversion",subjectId:"gen-math",quarter:2,competencyCodes:["GM11-MC-1","GM11-MC-2"]},{topicId:"gm-q2-functions-graphs",label:"Functions and Their Graphs",subjectId:"gen-math",quarter:2,competencyCodes:["GM11-FG-1","GM11-FG-2","GM11-FG-3","M11GM-Ia-2","M11GM-Ib-5","M11GM-Id-2","M11GM-Ie-f-1","M11GM-Ii-4"]},{topicId:"gm-q2-piecewise-functions",label:"Piecewise Functions",subjectId:"gen-math",quarter:2,competencyCodes:["GM11-PF-1","GM11-PF-2"]},{topicId:"gm-q2-statistical-variables",label:"Statistical Variables",subjectId:"gen-math",quarter:2,competencyCodes:["GM11-SV-1","GM11-SV-2"]},{topicId:"gm-q3-basic-trigonometry",label:"Basic Trigonometry",subjectId:"gen-math",quarter:3,competencyCodes:["GM11-BT-1","GM11-BT-2"]},{topicId:"gm-q3-practical-applications-measurement",label:"Practical Applications of Measurement",subjectId:"gen-math",quarter:3,competencyCodes:["GM11-PAM-1","GM11-PAM-2","M11GM-IIa-b-1","M11GM-IIa-2","M11GM-IIc-d-1","M11GM-IIf-3"]},{topicId:"gm-q3-transformational-geometry-volume-capacity",label:"Transformational Geometry / Volume and Capacity",subjectId:"gen-math",quarter:3,competencyCodes:["GM11-TGVC-1","GM11-TGVC-2"]},{topicId:"gm-q3-random-variables-sampling",label:"Random Variables and Sampling",subjectId:"gen-math",quarter:3,competencyCodes:["GM11-RVS-1","GM11-RVS-2","GM11-RVS-3"]},{topicId:"gm-q4-compound-interest-annuities-loans",label:"Compound Interest, Annuities, and Loans",subjectId:"gen-math",quarter:4,competencyCodes:["GM11-CIAL-1","GM11-CIAL-2","GM11-CIAL-3"]},{topicId:"gm-q4-hypothesis-testing-regression",label:"Hypothesis Testing and Regression",subjectId:"gen-math",quarter:4,competencyCodes:["GM11-HTR-1","GM11-HTR-2"]},{topicId:"gm-q4-propositions-syllogisms-fallacies",label:"Logical Propositions, Syllogisms, and Fallacies",subjectId:"gen-math",quarter:4,competencyCodes:["GM11-PSF-1","GM11-PSF-2","GM11-PSF-3","M11GM-IIg-1","M11GM-IIh-1","M11GM-IIi-1","M11GM-IIi-2","M11GM-IIj-1"]}];for(const e of ke)for(const n of e.competencyCodes)e.topicId;const zt={};for(const e of ke)zt[e.topicId]=e;const nt={};for(const e of ke)nt[e.topicId]=e.label;function Ut(e){if(typeof document>"u")return;let n=document.head||document.getElementsByTagName("head")[0],t=document.createElement("style");t.type="text/css",n.appendChild(t),t.styleSheet?t.styleSheet.cssText=e:t.appendChild(document.createTextNode(e))}const rt=o.createContext({drawerRef:{current:null},overlayRef:{current:null},onPress:()=>{},onRelease:()=>{},onDrag:()=>{},onNestedDrag:()=>{},onNestedOpenChange:()=>{},onNestedRelease:()=>{},openProp:void 0,dismissible:!1,isOpen:!1,isDragging:!1,keyboardIsOpen:{current:!1},snapPointsOffset:null,snapPoints:null,handleOnly:!1,modal:!1,shouldFade:!1,activeSnapPoint:null,onOpenChange:()=>{},setActiveSnapPoint:()=>{},closeDrawer:()=>{},direction:"bottom",shouldAnimate:{current:!0},shouldScaleBackground:!1,setBackgroundColorOnScale:!0,noBodyStyles:!1,container:null,autoFocus:!1}),he=()=>{const e=o.useContext(rt);if(!e)throw new Error("useDrawerContext must be used within a Drawer.Root");return e};Ut(`[data-vaul-drawer]{touch-action:none;will-change:transform;transition:transform .5s cubic-bezier(.32, .72, 0, 1);animation-duration:.5s;animation-timing-function:cubic-bezier(0.32,0.72,0,1)}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=bottom][data-state=open]{animation-name:slideFromBottom}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=bottom][data-state=closed]{animation-name:slideToBottom}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=top][data-state=open]{animation-name:slideFromTop}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=top][data-state=closed]{animation-name:slideToTop}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=left][data-state=open]{animation-name:slideFromLeft}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=left][data-state=closed]{animation-name:slideToLeft}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=right][data-state=open]{animation-name:slideFromRight}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=right][data-state=closed]{animation-name:slideToRight}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=bottom]{transform:translate3d(0,var(--initial-transform,100%),0)}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=top]{transform:translate3d(0,calc(var(--initial-transform,100%) * -1),0)}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=left]{transform:translate3d(calc(var(--initial-transform,100%) * -1),0,0)}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=right]{transform:translate3d(var(--initial-transform,100%),0,0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=top]{transform:translate3d(0,var(--snap-point-height,0),0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=bottom]{transform:translate3d(0,var(--snap-point-height,0),0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=left]{transform:translate3d(var(--snap-point-height,0),0,0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=right]{transform:translate3d(var(--snap-point-height,0),0,0)}[data-vaul-overlay][data-vaul-snap-points=false]{animation-duration:.5s;animation-timing-function:cubic-bezier(0.32,0.72,0,1)}[data-vaul-overlay][data-vaul-snap-points=false][data-state=open]{animation-name:fadeIn}[data-vaul-overlay][data-state=closed]{animation-name:fadeOut}[data-vaul-animate=false]{animation:none!important}[data-vaul-overlay][data-vaul-snap-points=true]{opacity:0;transition:opacity .5s cubic-bezier(.32, .72, 0, 1)}[data-vaul-overlay][data-vaul-snap-points=true]{opacity:1}[data-vaul-drawer]:not([data-vaul-custom-container=true])::after{content:'';position:absolute;background:inherit;background-color:inherit}[data-vaul-drawer][data-vaul-drawer-direction=top]::after{top:initial;bottom:100%;left:0;right:0;height:200%}[data-vaul-drawer][data-vaul-drawer-direction=bottom]::after{top:100%;bottom:initial;left:0;right:0;height:200%}[data-vaul-drawer][data-vaul-drawer-direction=left]::after{left:initial;right:100%;top:0;bottom:0;width:200%}[data-vaul-drawer][data-vaul-drawer-direction=right]::after{left:100%;right:initial;top:0;bottom:0;width:200%}[data-vaul-overlay][data-vaul-snap-points=true]:not([data-vaul-snap-points-overlay=true]):not( +import{d as o,r as U,j as r}from"./vendor-react-B4AQeu28.js";import{o as se,h as Qe,m as Ie,y as Se,a as jt,L as Ze,I as et}from"./index-Bp7MiGcW.js";import{f as Dt}from"./deepseekRagService-Bke9fSTt.js";import{T as Nt,D as Ot,d as It,b as At,c as _t,P as kt,O as Pt}from"./vendor-radix-C5nwdvGr.js";import{w as $t}from"./moduleWatchService-Cyzc6bn4.js";import{C as Lt}from"./circle-alert-CHGy8HcB.js";import{a as Bt,C as Ft}from"./chevron-up-DtS9MvUZ.js";import{B as Gt}from"./bell-DyLbgepV.js";import{C as tt}from"./clock-Cc6sJz1J.js";import{C as Ve}from"./chevron-right-BxoysOas.js";import{S as Ht}from"./sparkles-fLB3ltj1.js";import{X as qt}from"./x-k8d6VLEw.js";import"./vendor-firebase-firestore-CNv3xXal.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-charts-CAmziV1y.js";import"./vendor-markdown-yqZQ_iQm.js";const ke=[{topicId:"gm-q1-business-finance",label:"Business and Finance",subjectId:"gen-math",quarter:1,competencyCodes:["GM11-BF-1","GM11-BF-2","GM11-BF-3"]},{topicId:"gm-q1-patterns-sequences-series",label:"Patterns, Sequences, and Series",subjectId:"gen-math",quarter:1,competencyCodes:["GM11-PSS-1","GM11-PSS-2","GM11-PSS-3"]},{topicId:"gm-q1-financial-application-sequences-series",label:"Financial Application of Sequences and Series",subjectId:"gen-math",quarter:1,competencyCodes:["GM11-FASS-1","GM11-FASS-2"]},{topicId:"gm-q2-measurement-conversion",label:"Measurement and Conversion",subjectId:"gen-math",quarter:2,competencyCodes:["GM11-MC-1","GM11-MC-2"]},{topicId:"gm-q2-functions-graphs",label:"Functions and Their Graphs",subjectId:"gen-math",quarter:2,competencyCodes:["GM11-FG-1","GM11-FG-2","GM11-FG-3","M11GM-Ia-2","M11GM-Ib-5","M11GM-Id-2","M11GM-Ie-f-1","M11GM-Ii-4"]},{topicId:"gm-q2-piecewise-functions",label:"Piecewise Functions",subjectId:"gen-math",quarter:2,competencyCodes:["GM11-PF-1","GM11-PF-2"]},{topicId:"gm-q2-statistical-variables",label:"Statistical Variables",subjectId:"gen-math",quarter:2,competencyCodes:["GM11-SV-1","GM11-SV-2"]},{topicId:"gm-q3-basic-trigonometry",label:"Basic Trigonometry",subjectId:"gen-math",quarter:3,competencyCodes:["GM11-BT-1","GM11-BT-2"]},{topicId:"gm-q3-practical-applications-measurement",label:"Practical Applications of Measurement",subjectId:"gen-math",quarter:3,competencyCodes:["GM11-PAM-1","GM11-PAM-2","M11GM-IIa-b-1","M11GM-IIa-2","M11GM-IIc-d-1","M11GM-IIf-3"]},{topicId:"gm-q3-transformational-geometry-volume-capacity",label:"Transformational Geometry / Volume and Capacity",subjectId:"gen-math",quarter:3,competencyCodes:["GM11-TGVC-1","GM11-TGVC-2"]},{topicId:"gm-q3-random-variables-sampling",label:"Random Variables and Sampling",subjectId:"gen-math",quarter:3,competencyCodes:["GM11-RVS-1","GM11-RVS-2","GM11-RVS-3"]},{topicId:"gm-q4-compound-interest-annuities-loans",label:"Compound Interest, Annuities, and Loans",subjectId:"gen-math",quarter:4,competencyCodes:["GM11-CIAL-1","GM11-CIAL-2","GM11-CIAL-3"]},{topicId:"gm-q4-hypothesis-testing-regression",label:"Hypothesis Testing and Regression",subjectId:"gen-math",quarter:4,competencyCodes:["GM11-HTR-1","GM11-HTR-2"]},{topicId:"gm-q4-propositions-syllogisms-fallacies",label:"Logical Propositions, Syllogisms, and Fallacies",subjectId:"gen-math",quarter:4,competencyCodes:["GM11-PSF-1","GM11-PSF-2","GM11-PSF-3","M11GM-IIg-1","M11GM-IIh-1","M11GM-IIi-1","M11GM-IIi-2","M11GM-IIj-1"]}];for(const e of ke)for(const n of e.competencyCodes)e.topicId;const zt={};for(const e of ke)zt[e.topicId]=e;const nt={};for(const e of ke)nt[e.topicId]=e.label;function Ut(e){if(typeof document>"u")return;let n=document.head||document.getElementsByTagName("head")[0],t=document.createElement("style");t.type="text/css",n.appendChild(t),t.styleSheet?t.styleSheet.cssText=e:t.appendChild(document.createTextNode(e))}const rt=o.createContext({drawerRef:{current:null},overlayRef:{current:null},onPress:()=>{},onRelease:()=>{},onDrag:()=>{},onNestedDrag:()=>{},onNestedOpenChange:()=>{},onNestedRelease:()=>{},openProp:void 0,dismissible:!1,isOpen:!1,isDragging:!1,keyboardIsOpen:{current:!1},snapPointsOffset:null,snapPoints:null,handleOnly:!1,modal:!1,shouldFade:!1,activeSnapPoint:null,onOpenChange:()=>{},setActiveSnapPoint:()=>{},closeDrawer:()=>{},direction:"bottom",shouldAnimate:{current:!0},shouldScaleBackground:!1,setBackgroundColorOnScale:!0,noBodyStyles:!1,container:null,autoFocus:!1}),he=()=>{const e=o.useContext(rt);if(!e)throw new Error("useDrawerContext must be used within a Drawer.Root");return e};Ut(`[data-vaul-drawer]{touch-action:none;will-change:transform;transition:transform .5s cubic-bezier(.32, .72, 0, 1);animation-duration:.5s;animation-timing-function:cubic-bezier(0.32,0.72,0,1)}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=bottom][data-state=open]{animation-name:slideFromBottom}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=bottom][data-state=closed]{animation-name:slideToBottom}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=top][data-state=open]{animation-name:slideFromTop}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=top][data-state=closed]{animation-name:slideToTop}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=left][data-state=open]{animation-name:slideFromLeft}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=left][data-state=closed]{animation-name:slideToLeft}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=right][data-state=open]{animation-name:slideFromRight}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=right][data-state=closed]{animation-name:slideToRight}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=bottom]{transform:translate3d(0,var(--initial-transform,100%),0)}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=top]{transform:translate3d(0,calc(var(--initial-transform,100%) * -1),0)}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=left]{transform:translate3d(calc(var(--initial-transform,100%) * -1),0,0)}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=right]{transform:translate3d(var(--initial-transform,100%),0,0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=top]{transform:translate3d(0,var(--snap-point-height,0),0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=bottom]{transform:translate3d(0,var(--snap-point-height,0),0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=left]{transform:translate3d(var(--snap-point-height,0),0,0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=right]{transform:translate3d(var(--snap-point-height,0),0,0)}[data-vaul-overlay][data-vaul-snap-points=false]{animation-duration:.5s;animation-timing-function:cubic-bezier(0.32,0.72,0,1)}[data-vaul-overlay][data-vaul-snap-points=false][data-state=open]{animation-name:fadeIn}[data-vaul-overlay][data-state=closed]{animation-name:fadeOut}[data-vaul-animate=false]{animation:none!important}[data-vaul-overlay][data-vaul-snap-points=true]{opacity:0;transition:opacity .5s cubic-bezier(.32, .72, 0, 1)}[data-vaul-overlay][data-vaul-snap-points=true]{opacity:1}[data-vaul-drawer]:not([data-vaul-custom-container=true])::after{content:'';position:absolute;background:inherit;background-color:inherit}[data-vaul-drawer][data-vaul-drawer-direction=top]::after{top:initial;bottom:100%;left:0;right:0;height:200%}[data-vaul-drawer][data-vaul-drawer-direction=bottom]::after{top:100%;bottom:initial;left:0;right:0;height:200%}[data-vaul-drawer][data-vaul-drawer-direction=left]::after{left:initial;right:100%;top:0;bottom:0;width:200%}[data-vaul-drawer][data-vaul-drawer-direction=right]::after{left:100%;right:initial;top:0;bottom:0;width:200%}[data-vaul-overlay][data-vaul-snap-points=true]:not([data-vaul-snap-points-overlay=true]):not( [data-state=closed] ){opacity:0}[data-vaul-overlay][data-vaul-snap-points-overlay=true]{opacity:1}[data-vaul-handle]{display:block;position:relative;opacity:.7;background:#e2e2e4;margin-left:auto;margin-right:auto;height:5px;width:32px;border-radius:1rem;touch-action:pan-y}[data-vaul-handle]:active,[data-vaul-handle]:hover{opacity:1}[data-vaul-handle-hitarea]{position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);width:max(100%,2.75rem);height:max(100%,2.75rem);touch-action:inherit}@media (hover:hover) and (pointer:fine){[data-vaul-drawer]{user-select:none}}@media (pointer:fine){[data-vaul-handle-hitarea]:{width:100%;height:100%}}@keyframes fadeIn{from{opacity:0}to{opacity:1}}@keyframes fadeOut{to{opacity:0}}@keyframes slideFromBottom{from{transform:translate3d(0,var(--initial-transform,100%),0)}to{transform:translate3d(0,0,0)}}@keyframes slideToBottom{to{transform:translate3d(0,var(--initial-transform,100%),0)}}@keyframes slideFromTop{from{transform:translate3d(0,calc(var(--initial-transform,100%) * -1),0)}to{transform:translate3d(0,0,0)}}@keyframes slideToTop{to{transform:translate3d(0,calc(var(--initial-transform,100%) * -1),0)}}@keyframes slideFromLeft{from{transform:translate3d(calc(var(--initial-transform,100%) * -1),0,0)}to{transform:translate3d(0,0,0)}}@keyframes slideToLeft{to{transform:translate3d(calc(var(--initial-transform,100%) * -1),0,0)}}@keyframes slideFromRight{from{transform:translate3d(var(--initial-transform,100%),0,0)}to{transform:translate3d(0,0,0)}}@keyframes slideToRight{to{transform:translate3d(var(--initial-transform,100%),0,0)}}`);function Wt(){const e=navigator.userAgent;return typeof window<"u"&&(/Firefox/.test(e)&&/Mobile/.test(e)||/FxiOS/.test(e))}function Vt(){return Pe(/^Mac/)}function Yt(){return Pe(/^iPhone/)}function Ye(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function Xt(){return Pe(/^iPad/)||Vt()&&navigator.maxTouchPoints>1}function at(){return Yt()||Xt()}function Pe(e){return typeof window<"u"&&window.navigator!=null?e.test(window.navigator.platform):void 0}const Kt=24,Jt=typeof window<"u"?U.useLayoutEffect:U.useEffect;function Xe(...e){return(...n)=>{for(let t of e)typeof t=="function"&&t(...n)}}const je=typeof document<"u"&&window.visualViewport;function Ke(e){let n=window.getComputedStyle(e);return/(auto|scroll)/.test(n.overflow+n.overflowX+n.overflowY)}function ot(e){for(Ke(e)&&(e=e.parentElement);e&&!Ke(e);)e=e.parentElement;return e||document.scrollingElement||document.documentElement}const Qt=new Set(["checkbox","radio","range","color","file","image","button","submit","reset"]);let be=0,De;function Zt(e={}){let{isDisabled:n}=e;Jt(()=>{if(!n)return be++,be===1&&at()&&(De=en()),()=>{be--,be===0&&De?.()}},[n])}function en(){let e,n=0,t=m=>{e=ot(m.target),!(e===document.documentElement&&e===document.body)&&(n=m.changedTouches[0].pageY)},i=m=>{if(!e||e===document.documentElement||e===document.body){m.preventDefault();return}let c=m.changedTouches[0].pageY,$=e.scrollTop,I=e.scrollHeight-e.clientHeight;I!==0&&(($<=0&&c>n||$>=I&&c{let c=m.target;Ae(c)&&c!==document.activeElement&&(m.preventDefault(),c.style.transform="translateY(-2000px)",c.focus(),requestAnimationFrame(()=>{c.style.transform=""}))},a=m=>{let c=m.target;Ae(c)&&(c.style.transform="translateY(-2000px)",requestAnimationFrame(()=>{c.style.transform="",je&&(je.height{Je(c)}):je.addEventListener("resize",()=>Je(c),{once:!0}))}))},h=()=>{window.scrollTo(0,0)},w=window.pageXOffset,y=window.pageYOffset,S=Xe(tn(document.documentElement,"paddingRight",`${window.innerWidth-document.documentElement.clientWidth}px`));window.scrollTo(0,0);let v=Xe(me(document,"touchstart",t,{passive:!1,capture:!0}),me(document,"touchmove",i,{passive:!1,capture:!0}),me(document,"touchend",s,{passive:!1,capture:!0}),me(document,"focus",a,!0),me(window,"scroll",h));return()=>{S(),v(),window.scrollTo(w,y)}}function tn(e,n,t){let i=e.style[n];return e.style[n]=t,()=>{e.style[n]=i}}function me(e,n,t,i){return e.addEventListener(n,t,i),()=>{e.removeEventListener(n,t,i)}}function Je(e){let n=document.scrollingElement||document.documentElement;for(;e&&e!==n;){let t=ot(e);if(t!==document.documentElement&&t!==document.body&&t!==e){let i=t.getBoundingClientRect().top,s=e.getBoundingClientRect().top,a=e.getBoundingClientRect().bottom;const h=t.getBoundingClientRect().bottom+Kt;a>h&&(t.scrollTop+=s-i)}e=t.parentElement}}function Ae(e){return e instanceof HTMLInputElement&&!Qt.has(e.type)||e instanceof HTMLTextAreaElement||e instanceof HTMLElement&&e.isContentEditable}function nn(e,n){typeof e=="function"?e(n):e!=null&&(e.current=n)}function rn(...e){return n=>e.forEach(t=>nn(t,n))}function it(...e){return U.useCallback(rn(...e),e)}const st=new WeakMap;function L(e,n,t=!1){if(!e||!(e instanceof HTMLElement))return;let i={};Object.entries(n).forEach(([s,a])=>{if(s.startsWith("--")){e.style.setProperty(s,a);return}i[s]=e.style[s],e.style[s]=a}),!t&&st.set(e,i)}function an(e,n){if(!e||!(e instanceof HTMLElement))return;let t=st.get(e);t&&(e.style[n]=t[n])}const P=e=>{switch(e){case"top":case"bottom":return!0;case"left":case"right":return!1;default:return e}};function xe(e,n){if(!e)return null;const t=window.getComputedStyle(e),i=t.transform||t.webkitTransform||t.mozTransform;let s=i.match(/^matrix3d\((.+)\)$/);return s?parseFloat(s[1].split(", ")[P(n)?13:12]):(s=i.match(/^matrix\((.+)\)$/),s?parseFloat(s[1].split(", ")[P(n)?5:4]):null)}function on(e){return 8*(Math.log(e+1)-2)}function Ne(e,n){if(!e)return()=>{};const t=e.style.cssText;return Object.assign(e.style,n),()=>{e.style.cssText=t}}function sn(...e){return(...n)=>{for(const t of e)typeof t=="function"&&t(...n)}}const D={DURATION:.5,EASE:[.32,.72,0,1]},lt=.4,ln=.25,cn=100,ct=8,ne=16,_e=26,Oe="vaul-dragging";function ut(e){const n=o.useRef(e);return o.useEffect(()=>{n.current=e}),o.useMemo(()=>(...t)=>n.current==null?void 0:n.current.call(n,...t),[])}function un({defaultProp:e,onChange:n}){const t=o.useState(e),[i]=t,s=o.useRef(i),a=ut(n);return o.useEffect(()=>{s.current!==i&&(a(i),s.current=i)},[i,s,a]),t}function dt({prop:e,defaultProp:n,onChange:t=()=>{}}){const[i,s]=un({defaultProp:n,onChange:t}),a=e!==void 0,h=a?e:i,w=ut(t),y=o.useCallback(S=>{if(a){const m=typeof S=="function"?S(e):S;m!==e&&w(m)}else s(S)},[a,e,s,w]);return[h,y]}function dn({activeSnapPointProp:e,setActiveSnapPointProp:n,snapPoints:t,drawerRef:i,overlayRef:s,fadeFromIndex:a,onSnapPointChange:h,direction:w="bottom",container:y,snapToSequentialPoint:S}){const[v,m]=dt({prop:e,defaultProp:t?.[0],onChange:n}),[c,$]=o.useState(typeof window<"u"?{innerWidth:window.innerWidth,innerHeight:window.innerHeight}:void 0);o.useEffect(()=>{function p(){$({innerWidth:window.innerWidth,innerHeight:window.innerHeight})}return window.addEventListener("resize",p),()=>window.removeEventListener("resize",p)},[]);const I=o.useMemo(()=>v===t?.[t.length-1]||null,[t,v]),M=o.useMemo(()=>{var p;return(p=t?.findIndex(R=>R===v))!=null?p:null},[t,v]),F=t&&t.length>0&&(a||a===0)&&!Number.isNaN(a)&&t[a]===v||!t,f=o.useMemo(()=>{const p=y?{width:y.getBoundingClientRect().width,height:y.getBoundingClientRect().height}:typeof window<"u"?{width:window.innerWidth,height:window.innerHeight}:{width:0,height:0};var R;return(R=t?.map(x=>{const G=typeof x=="string";let B=0;if(G&&(B=parseInt(x,10)),P(w)){const u=G?B:c?x*p.height:0;return c?w==="bottom"?p.height-u:-p.height+u:u}const H=G?B:c?x*p.width:0;return c?w==="right"?p.width-H:-p.width+H:H}))!=null?R:[]},[t,c,y]),A=o.useMemo(()=>M!==null?f?.[M]:null,[f,M]),N=o.useCallback(p=>{var R;const x=(R=f?.findIndex(G=>G===p))!=null?R:null;h(x),L(i.current,{transition:`transform ${D.DURATION}s cubic-bezier(${D.EASE.join(",")})`,transform:P(w)?`translate3d(0, ${p}px, 0)`:`translate3d(${p}px, 0, 0)`}),f&&x!==f.length-1&&a!==void 0&&x!==a&&x{if(v||e){var p;const R=(p=t?.findIndex(x=>x===e||x===v))!=null?p:-1;f&&R!==-1&&typeof f[R]=="number"&&N(f[R])}},[v,e,t,f,N]);function l({draggedDistance:p,closeDrawer:R,velocity:x,dismissible:G}){if(a===void 0)return;const B=w==="bottom"||w==="right"?(A??0)-p:(A??0)+p,H=M===a-1,u=M===0,b=p>0;if(H&&L(s.current,{transition:`opacity ${D.DURATION}s cubic-bezier(${D.EASE.join(",")})`}),!S&&x>2&&!b){G?R():N(f[0]);return}if(!S&&x>2&&b&&f&&t){N(f[t.length-1]);return}const j=f?.reduce((_,W)=>typeof _!="number"||typeof W!="number"?_:Math.abs(W-B)lt&&Math.abs(p)0&&I&&t){N(f[t.length-1]);return}if(u&&_<0&&G&&R(),M===null)return;N(f[M+_]);return}N(j)}function V({draggedDistance:p}){if(A===null)return;const R=w==="bottom"||w==="right"?A-p:A+p;(w==="bottom"||w==="right")&&Rf[f.length-1]||L(i.current,{transform:P(w)?`translate3d(0, ${R}px, 0)`:`translate3d(${R}px, 0, 0)`})}function X(p,R){if(!t||typeof M!="number"||!f||a===void 0)return null;const x=M===a-1;if(M>=a&&R)return 0;if(x&&!R)return 1;if(!F&&!x)return null;const B=x?M+1:M-1,H=x?f[B]-f[B-1]:f[B+1]-f[B],u=p/Math.abs(H);return x?1-u:u}return{isLastSnapPoint:I,activeSnapPoint:v,shouldFade:F,getPercentageDragged:X,setActiveSnapPoint:m,activeSnapPointIndex:M,onRelease:l,onDrag:V,snapPointsOffset:f}}const fn=()=>()=>{};function mn(){const{direction:e,isOpen:n,shouldScaleBackground:t,setBackgroundColorOnScale:i,noBodyStyles:s}=he(),a=o.useRef(null),h=U.useMemo(()=>document.body.style.backgroundColor,[]);function w(){return(window.innerWidth-_e)/window.innerWidth}o.useEffect(()=>{if(n&&t){a.current&&clearTimeout(a.current);const y=document.querySelector("[data-vaul-drawer-wrapper]")||document.querySelector("[vaul-drawer-wrapper]");if(!y)return;sn(i&&!s?Ne(document.body,{background:"black"}):fn,Ne(y,{transformOrigin:P(e)?"top":"left",transitionProperty:"transform, border-radius",transitionDuration:`${D.DURATION}s`,transitionTimingFunction:`cubic-bezier(${D.EASE.join(",")})`}));const S=Ne(y,{borderRadius:`${ct}px`,overflow:"hidden",...P(e)?{transform:`scale(${w()}) translate3d(0, calc(env(safe-area-inset-top) + 14px), 0)`}:{transform:`scale(${w()}) translate3d(calc(env(safe-area-inset-top) + 14px), 0, 0)`}});return()=>{S(),a.current=window.setTimeout(()=>{h?document.body.style.background=h:document.body.style.removeProperty("background")},D.DURATION*1e3)}}},[n,t,h])}let pe=null;function pn({isOpen:e,modal:n,nested:t,hasBeenOpened:i,preventScrollRestoration:s,noBodyStyles:a}){const[h,w]=o.useState(()=>typeof window<"u"?window.location.href:""),y=o.useRef(0),S=o.useCallback(()=>{if(Ye()&&pe===null&&e&&!a){pe={position:document.body.style.position,top:document.body.style.top,left:document.body.style.left,height:document.body.style.height,right:"unset"};const{scrollX:m,innerHeight:c}=window;document.body.style.setProperty("position","fixed","important"),Object.assign(document.body.style,{top:`${-y.current}px`,left:`${-m}px`,right:"0px",height:"auto"}),window.setTimeout(()=>window.requestAnimationFrame(()=>{const $=c-window.innerHeight;$&&y.current>=c&&(document.body.style.top=`${-(y.current+$)}px`)}),300)}},[e]),v=o.useCallback(()=>{if(Ye()&&pe!==null&&!a){const m=-parseInt(document.body.style.top,10),c=-parseInt(document.body.style.left,10);Object.assign(document.body.style,pe),window.requestAnimationFrame(()=>{if(s&&h!==window.location.href){w(window.location.href);return}window.scrollTo(c,m)}),pe=null}},[h]);return o.useEffect(()=>{function m(){y.current=window.scrollY}return m(),window.addEventListener("scroll",m),()=>{window.removeEventListener("scroll",m)}},[]),o.useEffect(()=>{if(n)return()=>{typeof document>"u"||document.querySelector("[data-vaul-drawer]")||v()}},[n,v]),o.useEffect(()=>{t||!i||(e?(!window.matchMedia("(display-mode: standalone)").matches&&S(),n||window.setTimeout(()=>{v()},500)):v())},[e,i,h,n,t,S,v]),{restorePositionSetting:v}}function hn({open:e,onOpenChange:n,children:t,onDrag:i,onRelease:s,snapPoints:a,shouldScaleBackground:h=!1,setBackgroundColorOnScale:w=!0,closeThreshold:y=ln,scrollLockTimeout:S=cn,dismissible:v=!0,handleOnly:m=!1,fadeFromIndex:c=a&&a.length-1,activeSnapPoint:$,setActiveSnapPoint:I,fixed:M,modal:F=!0,onClose:f,nested:A,noBodyStyles:N=!1,direction:l="bottom",defaultOpen:V=!1,disablePreventScroll:X=!0,snapToSequentialPoint:p=!1,preventScrollRestoration:R=!1,repositionInputs:x=!0,onAnimationEnd:G,container:B,autoFocus:H=!1}){var u,b;const[j=!1,O]=dt({defaultProp:V,prop:e,onChange:d=>{n?.(d),!d&&!A&&xt(),setTimeout(()=>{G?.(d)},D.DURATION*1e3),d&&!F&&typeof window<"u"&&window.requestAnimationFrame(()=>{document.body.style.pointerEvents="auto"}),d||(document.body.style.pointerEvents="auto")}}),[_,W]=o.useState(!1),[Q,le]=o.useState(!1),[pt,$e]=o.useState(!1),ae=o.useRef(null),ge=o.useRef(null),Te=o.useRef(null),Re=o.useRef(null),ce=o.useRef(null),ue=o.useRef(!1),Ce=o.useRef(null),Me=o.useRef(0),oe=o.useRef(!1),Le=o.useRef(!V),Be=o.useRef(0),g=o.useRef(null),Fe=o.useRef(((u=g.current)==null?void 0:u.getBoundingClientRect().height)||0),Ge=o.useRef(((b=g.current)==null?void 0:b.getBoundingClientRect().width)||0),Ee=o.useRef(0),ht=o.useCallback(d=>{a&&d===de.length-1&&(ge.current=new Date)},[]),{activeSnapPoint:gt,activeSnapPointIndex:ie,setActiveSnapPoint:He,onRelease:wt,snapPointsOffset:de,onDrag:vt,shouldFade:qe,getPercentageDragged:bt}=dn({snapPoints:a,activeSnapPointProp:$,setActiveSnapPointProp:I,drawerRef:g,fadeFromIndex:c,overlayRef:ae,onSnapPointChange:ht,direction:l,container:B,snapToSequentialPoint:p});Zt({isDisabled:!j||Q||!F||pt||!_||!x||!X});const{restorePositionSetting:xt}=pn({isOpen:j,modal:F,nested:A??!1,hasBeenOpened:_,preventScrollRestoration:R,noBodyStyles:N});function we(){return(window.innerWidth-_e)/window.innerWidth}function yt(d){var C,E;!v&&!a||g.current&&!g.current.contains(d.target)||(Fe.current=((C=g.current)==null?void 0:C.getBoundingClientRect().height)||0,Ge.current=((E=g.current)==null?void 0:E.getBoundingClientRect().width)||0,le(!0),Te.current=new Date,at()&&window.addEventListener("touchend",()=>ue.current=!1,{once:!0}),d.target.setPointerCapture(d.pointerId),Me.current=P(l)?d.pageY:d.pageX)}function ze(d,C){var E;let T=d;const k=(E=window.getSelection())==null?void 0:E.toString(),z=g.current?xe(g.current,l):null,q=new Date;if(T.tagName==="SELECT"||T.hasAttribute("data-vaul-no-drag")||T.closest("[data-vaul-no-drag]"))return!1;if(l==="right"||l==="left")return!0;if(ge.current&&q.getTime()-ge.current.getTime()<500)return!1;if(z!==null&&(l==="bottom"?z>0:z<0))return!0;if(k&&k.length>0)return!1;if(ce.current&&q.getTime()-ce.current.getTime()T.clientHeight){if(T.scrollTop!==0)return ce.current=new Date,!1;if(T.getAttribute("role")==="dialog")return!0}T=T.parentNode}return!0}function St(d){if(g.current&&Q){const C=l==="bottom"||l==="right"?1:-1,E=(Me.current-(P(l)?d.pageY:d.pageX))*C,T=E>0,k=a&&!v&&!T;if(k&&ie===0)return;const z=Math.abs(E),q=document.querySelector("[data-vaul-drawer-wrapper]"),Z=l==="bottom"||l==="top"?Fe.current:Ge.current;let Y=z/Z;const te=bt(z,T);if(te!==null&&(Y=te),k&&Y>=1||!ue.current&&!ze(d.target,T))return;if(g.current.classList.add(Oe),ue.current=!0,L(g.current,{transition:"none"}),L(ae.current,{transition:"none"}),a&&vt({draggedDistance:E}),T&&!a){const K=on(E),ve=Math.min(K*-1,0)*C;L(g.current,{transform:P(l)?`translate3d(0, ${ve}px, 0)`:`translate3d(${ve}px, 0, 0)`});return}const ee=1-Y;if((qe||c&&ie===c-1)&&(i?.(d,Y),L(ae.current,{opacity:`${ee}`,transition:"none"},!0)),q&&ae.current&&h){const K=Math.min(we()+Y*(1-we()),1),ve=8-Y*8,We=Math.max(0,14-Y*14);L(q,{borderRadius:`${ve}px`,transform:P(l)?`scale(${K}) translate3d(0, ${We}px, 0)`:`scale(${K}) translate3d(${We}px, 0, 0)`,transition:"none"},!0)}if(!a){const K=z*C;L(g.current,{transform:P(l)?`translate3d(0, ${K}px, 0)`:`translate3d(${K}px, 0, 0)`})}}}o.useEffect(()=>{window.requestAnimationFrame(()=>{Le.current=!0})},[]),o.useEffect(()=>{var d;function C(){if(!g.current||!x)return;const E=document.activeElement;if(Ae(E)||oe.current){var T;const k=((T=window.visualViewport)==null?void 0:T.height)||0,z=window.innerHeight;let q=z-k;const Z=g.current.getBoundingClientRect().height||0,Y=Z>z*.8;Ee.current||(Ee.current=Z);const te=g.current.getBoundingClientRect().top;if(Math.abs(Be.current-q)>60&&(oe.current=!oe.current),a&&a.length>0&&de&&ie){const ee=de[ie]||0;q+=ee}if(Be.current=q,Z>k||oe.current){const ee=g.current.getBoundingClientRect().height;let K=ee;ee>k&&(K=k-(Y?te:_e)),M?g.current.style.height=`${ee-Math.max(q,0)}px`:g.current.style.height=`${Math.max(K,k-te)}px`}else Wt()||(g.current.style.height=`${Ee.current}px`);a&&a.length>0&&!oe.current?g.current.style.bottom="0px":g.current.style.bottom=`${Math.max(q,0)}px`}}return(d=window.visualViewport)==null||d.addEventListener("resize",C),()=>{var E;return(E=window.visualViewport)==null?void 0:E.removeEventListener("resize",C)}},[ie,a,de]);function fe(d){Tt(),f?.(),d||O(!1),setTimeout(()=>{a&&He(a[0])},D.DURATION*1e3)}function Ue(){if(!g.current)return;const d=document.querySelector("[data-vaul-drawer-wrapper]"),C=xe(g.current,l);L(g.current,{transform:"translate3d(0, 0, 0)",transition:`transform ${D.DURATION}s cubic-bezier(${D.EASE.join(",")})`}),L(ae.current,{transition:`opacity ${D.DURATION}s cubic-bezier(${D.EASE.join(",")})`,opacity:"1"}),h&&C&&C>0&&j&&L(d,{borderRadius:`${ct}px`,overflow:"hidden",...P(l)?{transform:`scale(${we()}) translate3d(0, calc(env(safe-area-inset-top) + 14px), 0)`,transformOrigin:"top"}:{transform:`scale(${we()}) translate3d(calc(env(safe-area-inset-top) + 14px), 0, 0)`,transformOrigin:"left"},transitionProperty:"transform, border-radius",transitionDuration:`${D.DURATION}s`,transitionTimingFunction:`cubic-bezier(${D.EASE.join(",")})`},!0)}function Tt(){!Q||!g.current||(g.current.classList.remove(Oe),ue.current=!1,le(!1),Re.current=new Date)}function Rt(d){if(!Q||!g.current)return;g.current.classList.remove(Oe),ue.current=!1,le(!1),Re.current=new Date;const C=xe(g.current,l);if(!d||!ze(d.target,!1)||!C||Number.isNaN(C)||Te.current===null)return;const E=Re.current.getTime()-Te.current.getTime(),T=Me.current-(P(l)?d.pageY:d.pageX),k=Math.abs(T)/E;if(k>.05&&($e(!0),setTimeout(()=>{$e(!1)},200)),a){wt({draggedDistance:T*(l==="bottom"||l==="right"?1:-1),closeDrawer:fe,velocity:k,dismissible:v}),s?.(d,!0);return}if(l==="bottom"||l==="right"?T>0:T<0){Ue(),s?.(d,!0);return}if(k>lt){fe(),s?.(d,!1);return}var z;const q=Math.min((z=g.current.getBoundingClientRect().height)!=null?z:0,window.innerHeight);var Z;const Y=Math.min((Z=g.current.getBoundingClientRect().width)!=null?Z:0,window.innerWidth),te=l==="left"||l==="right";if(Math.abs(C)>=(te?Y:q)*y){fe(),s?.(d,!1);return}s?.(d,!0),Ue()}o.useEffect(()=>(j&&(L(document.documentElement,{scrollBehavior:"auto"}),ge.current=new Date),()=>{an(document.documentElement,"scrollBehavior")}),[j]);function Ct(d){const C=d?(window.innerWidth-ne)/window.innerWidth:1,E=d?-ne:0;Ce.current&&window.clearTimeout(Ce.current),L(g.current,{transition:`transform ${D.DURATION}s cubic-bezier(${D.EASE.join(",")})`,transform:P(l)?`scale(${C}) translate3d(0, ${E}px, 0)`:`scale(${C}) translate3d(${E}px, 0, 0)`}),!d&&g.current&&(Ce.current=setTimeout(()=>{const T=xe(g.current,l);L(g.current,{transition:"none",transform:P(l)?`translate3d(0, ${T}px, 0)`:`translate3d(${T}px, 0, 0)`})},500))}function Mt(d,C){if(C<0)return;const E=(window.innerWidth-ne)/window.innerWidth,T=E+C*(1-E),k=-ne+C*ne;L(g.current,{transform:P(l)?`scale(${T}) translate3d(0, ${k}px, 0)`:`scale(${T}) translate3d(${k}px, 0, 0)`,transition:"none"})}function Et(d,C){const E=P(l)?window.innerHeight:window.innerWidth,T=C?(E-ne)/E:1,k=C?-ne:0;C&&L(g.current,{transition:`transform ${D.DURATION}s cubic-bezier(${D.EASE.join(",")})`,transform:P(l)?`scale(${T}) translate3d(0, ${k}px, 0)`:`scale(${T}) translate3d(${k}px, 0, 0)`})}return o.useEffect(()=>{F||window.requestAnimationFrame(()=>{document.body.style.pointerEvents="auto"})},[F]),o.createElement(At,{defaultOpen:V,onOpenChange:d=>{!v&&!d||(d?W(!0):fe(!0),O(d))},open:j},o.createElement(rt.Provider,{value:{activeSnapPoint:gt,snapPoints:a,setActiveSnapPoint:He,drawerRef:g,overlayRef:ae,onOpenChange:n,onPress:yt,onRelease:Rt,onDrag:St,dismissible:v,shouldAnimate:Le,handleOnly:m,isOpen:j,isDragging:Q,shouldFade:qe,closeDrawer:fe,onNestedDrag:Mt,onNestedOpenChange:Ct,onNestedRelease:Et,keyboardIsOpen:oe,modal:F,snapPointsOffset:de,activeSnapPointIndex:ie,direction:l,shouldScaleBackground:h,setBackgroundColorOnScale:w,noBodyStyles:N,container:B,autoFocus:H}},t))}const ft=o.forwardRef(function({...e},n){const{overlayRef:t,snapPoints:i,onRelease:s,shouldFade:a,isOpen:h,modal:w,shouldAnimate:y}=he(),S=it(n,t),v=i&&i.length>0;if(!w)return null;const m=o.useCallback(c=>s(c),[s]);return o.createElement(Pt,{onMouseUp:m,ref:S,"data-vaul-overlay":"","data-vaul-snap-points":h&&v?"true":"false","data-vaul-snap-points-overlay":h&&a?"true":"false","data-vaul-animate":y?.current?"true":"false",...e})});ft.displayName="Drawer.Overlay";const mt=o.forwardRef(function({onPointerDownOutside:e,style:n,onOpenAutoFocus:t,...i},s){const{drawerRef:a,onPress:h,onRelease:w,onDrag:y,keyboardIsOpen:S,snapPointsOffset:v,activeSnapPointIndex:m,modal:c,isOpen:$,direction:I,snapPoints:M,container:F,handleOnly:f,shouldAnimate:A,autoFocus:N}=he(),[l,V]=o.useState(!1),X=it(s,a),p=o.useRef(null),R=o.useRef(null),x=o.useRef(!1),G=M&&M.length>0;mn();const B=(u,b,j=0)=>{if(x.current)return!0;const O=Math.abs(u.y),_=Math.abs(u.x),W=_>O,Q=["bottom","right"].includes(b)?1:-1;if(b==="left"||b==="right"){if(!(u.x*Q<0)&&_>=0&&_<=j)return W}else if(!(u.y*Q<0)&&O>=0&&O<=j)return!W;return x.current=!0,!0};o.useEffect(()=>{G&&window.requestAnimationFrame(()=>{V(!0)})},[]);function H(u){p.current=null,x.current=!1,w(u)}return o.createElement(_t,{"data-vaul-drawer-direction":I,"data-vaul-drawer":"","data-vaul-delayed-snap-points":l?"true":"false","data-vaul-snap-points":$&&G?"true":"false","data-vaul-custom-container":F?"true":"false","data-vaul-animate":A?.current?"true":"false",...i,ref:X,style:v&&v.length>0?{"--snap-point-height":`${v[m??0]}px`,...n}:n,onPointerDown:u=>{f||(i.onPointerDown==null||i.onPointerDown.call(i,u),p.current={x:u.pageX,y:u.pageY},h(u))},onOpenAutoFocus:u=>{t?.(u),N||u.preventDefault()},onPointerDownOutside:u=>{if(e?.(u),!c||u.defaultPrevented){u.preventDefault();return}S.current&&(S.current=!1)},onFocusOutside:u=>{if(!c){u.preventDefault();return}},onPointerMove:u=>{if(R.current=u,f||(i.onPointerMove==null||i.onPointerMove.call(i,u),!p.current))return;const b=u.pageY-p.current.y,j=u.pageX-p.current.x,O=u.pointerType==="touch"?10:2;B({x:j,y:b},I,O)?y(u):(Math.abs(j)>O||Math.abs(b)>O)&&(p.current=null)},onPointerUp:u=>{i.onPointerUp==null||i.onPointerUp.call(i,u),p.current=null,x.current=!1,w(u)},onPointerOut:u=>{i.onPointerOut==null||i.onPointerOut.call(i,u),H(R.current)},onContextMenu:u=>{i.onContextMenu==null||i.onContextMenu.call(i,u),R.current&&H(R.current)}})});mt.displayName="Drawer.Content";const gn=250,wn=120,vn=o.forwardRef(function({preventCycle:e=!1,children:n,...t},i){const{closeDrawer:s,isDragging:a,snapPoints:h,activeSnapPoint:w,setActiveSnapPoint:y,dismissible:S,handleOnly:v,isOpen:m,onPress:c,onDrag:$}=he(),I=o.useRef(null),M=o.useRef(!1);function F(){if(M.current){N();return}window.setTimeout(()=>{f()},wn)}function f(){if(a||e||M.current){N();return}if(N(),!h||h.length===0){S||s();return}if(w===h[h.length-1]&&S){s();return}const V=h.findIndex(p=>p===w);if(V===-1)return;const X=h[V+1];y(X)}function A(){I.current=window.setTimeout(()=>{M.current=!0},gn)}function N(){I.current&&window.clearTimeout(I.current),M.current=!1}return o.createElement("div",{onClick:F,onPointerCancel:N,onPointerDown:l=>{v&&c(l),A()},onPointerMove:l=>{v&&$(l)},ref:i,"data-vaul-drawer-visible":m?"true":"false","data-vaul-handle":"","aria-hidden":"true",...t},o.createElement("span",{"data-vaul-handle-hitarea":"","aria-hidden":"true"},n))});vn.displayName="Drawer.Handle";function bn(e){const n=he(),{container:t=n.container,...i}=e;return o.createElement(kt,{container:t,...i})}const re={Root:hn,Content:mt,Overlay:ft,Portal:bn,Close:It,Title:Nt,Description:Ot};function xn({...e}){return r.jsx(re.Root,{"data-slot":"drawer",...e})}function yn({...e}){return r.jsx(re.Portal,{"data-slot":"drawer-portal",...e})}function Sn({...e}){return r.jsx(re.Close,{"data-slot":"drawer-close",...e})}function Tn({className:e,...n}){return r.jsx(re.Overlay,{"data-slot":"drawer-overlay",className:se("data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",e),...n})}function Rn({className:e,children:n,...t}){return r.jsxs(yn,{"data-slot":"drawer-portal",children:[r.jsx(Tn,{}),r.jsxs(re.Content,{"data-slot":"drawer-content",className:se("group/drawer-content bg-background fixed z-50 flex h-auto flex-col","data-[vaul-drawer-direction=top]:inset-x-0 data-[vaul-drawer-direction=top]:top-0 data-[vaul-drawer-direction=top]:mb-24 data-[vaul-drawer-direction=top]:max-h-[80vh] data-[vaul-drawer-direction=top]:rounded-b-lg data-[vaul-drawer-direction=top]:border-b","data-[vaul-drawer-direction=bottom]:inset-x-0 data-[vaul-drawer-direction=bottom]:bottom-0 data-[vaul-drawer-direction=bottom]:mt-24 data-[vaul-drawer-direction=bottom]:max-h-[80vh] data-[vaul-drawer-direction=bottom]:rounded-t-lg data-[vaul-drawer-direction=bottom]:border-t","data-[vaul-drawer-direction=right]:inset-y-0 data-[vaul-drawer-direction=right]:right-0 data-[vaul-drawer-direction=right]:w-3/4 data-[vaul-drawer-direction=right]:border-l data-[vaul-drawer-direction=right]:sm:max-w-sm","data-[vaul-drawer-direction=left]:inset-y-0 data-[vaul-drawer-direction=left]:left-0 data-[vaul-drawer-direction=left]:w-3/4 data-[vaul-drawer-direction=left]:border-r data-[vaul-drawer-direction=left]:sm:max-w-sm",e),...t,children:[r.jsx("div",{className:"bg-muted mx-auto mt-4 hidden h-2 w-[100px] shrink-0 rounded-full group-data-[vaul-drawer-direction=bottom]/drawer-content:block"}),n]})]})}function Cn({className:e,...n}){return r.jsx("div",{"data-slot":"drawer-header",className:se("flex flex-col gap-1.5 p-4",e),...n})}function Mn({className:e,...n}){return r.jsx("div",{"data-slot":"drawer-footer",className:se("mt-auto flex flex-col gap-2 p-4",e),...n})}function En({className:e,...n}){return r.jsx(re.Title,{"data-slot":"drawer-title",className:se("text-foreground font-semibold",e),...n})}function jn({className:e,...n}){return r.jsx(re.Description,{"data-slot":"drawer-description",className:se("text-muted-foreground text-sm",e),...n})}const Dn={coming_soon:{icon:r.jsx(tt,{size:16}),bg:"bg-amber-50 border-amber-200",text:"text-amber-800",message:"The full module for this topic isn't available yet — here's what you can study in the meantime, based on the DepEd curriculum."},progression_locked:{icon:r.jsx(Ze,{size:16}),bg:"bg-purple-50 border-purple-200",text:"text-purple-800",message:"You're flagged as at-risk here, but this module is currently locked behind progression. Study this brief while you work toward unlocking it."},no_module:{icon:r.jsx(Se,{size:16}),bg:"bg-rose-50 border-rose-200",text:"text-rose-800",message:"No module has been created for this topic yet. Here's what the DepEd curriculum says you should know."}},Nn=({open:e,onOpenChange:n,topicName:t,topicId:i,resolutionState:s,fallbackContent:a,moduleId:h,studentId:w,onNavigateToPrerequisite:y,loading:S=!1,error:v=null})=>{const[m,c]=U.useState(!1),[$,I]=U.useState(!1),[M,F]=U.useState(!1),f=Dn[s],A=async()=>{if(!(!w||!h)){I(!0);try{await $t(w,h),F(!0)}catch{}I(!1)}};return r.jsx(xn,{open:e,onOpenChange:n,children:r.jsxs(Rn,{className:"max-h-[85vh]",children:[r.jsxs(Cn,{children:[r.jsx(En,{className:"text-lg",children:t}),r.jsx(jn,{children:"At-Risk Study Brief"})]}),r.jsxs("div",{className:"px-4 pb-4 overflow-y-auto flex-1 space-y-4",children:[r.jsxs("div",{className:`flex items-start gap-2 p-3 rounded-lg border ${f.bg}`,children:[r.jsx("span",{className:`mt-0.5 ${f.text}`,children:f.icon}),r.jsx("p",{className:`text-xs leading-relaxed ${f.text}`,children:f.message})]}),S&&r.jsx("div",{className:"flex items-center justify-center py-8",children:r.jsx("div",{className:"animate-pulse text-sm text-gray-500",children:"Loading study brief..."})}),v&&r.jsxs("div",{className:"flex items-center gap-2 p-3 rounded-lg bg-red-50 border border-red-200",children:[r.jsx(Lt,{size:14,className:"text-red-600"}),r.jsx("p",{className:"text-xs text-red-700",children:v})]}),a&&!S&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{children:[r.jsx("h4",{className:"text-sm font-semibold text-gray-900 mb-1",children:"Overview"}),r.jsx("p",{className:"text-sm text-gray-700 leading-relaxed",children:a.summary})]}),a.key_concepts.length>0&&r.jsxs("div",{children:[r.jsx("h4",{className:"text-sm font-semibold text-gray-900 mb-2",children:"Key Concepts"}),r.jsx("ul",{className:"space-y-1.5",children:a.key_concepts.map((N,l)=>r.jsxs("li",{className:"flex items-start gap-2 text-sm text-gray-700",children:[r.jsx("span",{className:"mt-1.5 w-1.5 h-1.5 rounded-full bg-purple-500 flex-shrink-0"}),N]},l))})]}),a.one_worked_example?.problem&&r.jsxs("div",{className:"border border-gray-200 rounded-lg overflow-hidden",children:[r.jsxs("button",{onClick:()=>c(!m),className:"w-full flex items-center justify-between px-3 py-2.5 bg-gray-50 hover:bg-gray-100 transition-colors",children:[r.jsx("span",{className:"text-sm font-semibold text-gray-900",children:"Worked Example"}),m?r.jsx(Bt,{size:16}):r.jsx(Ft,{size:16})]}),r.jsx(Qe,{children:m&&r.jsx(Ie.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},className:"overflow-hidden",children:r.jsxs("div",{className:"px-3 py-3 space-y-2",children:[r.jsxs("div",{children:[r.jsx("span",{className:"text-xs font-bold text-gray-500 uppercase",children:"Problem"}),r.jsx("p",{className:"text-sm text-gray-800 mt-0.5",children:a.one_worked_example.problem})]}),r.jsxs("div",{children:[r.jsx("span",{className:"text-xs font-bold text-gray-500 uppercase",children:"Solution"}),r.jsx("p",{className:"text-sm text-gray-800 mt-0.5 whitespace-pre-line",children:a.one_worked_example.solution})]})]})})})]}),a.what_to_focus_on&&r.jsxs("div",{className:"bg-blue-50 border border-blue-200 rounded-lg p-3",children:[r.jsx("h4",{className:"text-xs font-bold text-blue-800 uppercase mb-1",children:"What to Focus On"}),r.jsx("p",{className:"text-sm text-blue-900 leading-relaxed",children:a.what_to_focus_on})]}),a.rag_confidence==="low"&&r.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-gray-500",children:[r.jsx(Se,{size:12}),r.jsx("span",{children:"Limited curriculum data was available for this topic preview."})]})]})]}),r.jsxs(Mn,{children:[s==="coming_soon"&&h&&r.jsxs("button",{onClick:A,disabled:M||$,className:"flex items-center justify-center gap-2 w-full py-2.5 rounded-lg bg-amber-500 hover:bg-amber-600 text-white text-sm font-semibold disabled:opacity-50 transition-colors",children:[r.jsx(Gt,{size:14}),M?"Subscribed!":$?"Subscribing...":"Notify Me When Available"]}),s==="progression_locked"&&h&&y&&r.jsxs("button",{onClick:()=>{y(h),n(!1)},className:"flex items-center justify-center gap-2 w-full py-2.5 rounded-lg bg-purple-600 hover:bg-purple-700 text-white text-sm font-semibold transition-colors",children:["Go to prerequisite module",r.jsx(jt,{size:14})]}),r.jsx(Sn,{asChild:!0,children:r.jsx("button",{className:"w-full py-2 rounded-lg border border-gray-200 text-sm text-gray-600 hover:bg-gray-50 transition-colors",children:"Close"})})]})]})})},J={pillBg:"#E9D5FF",pillText:"#6B21A8",pillLockedBg:"#EDE9FE",pillLockedText:"#7C3AED",pillComingSoonBg:"#FEF3C7",pillComingSoonText:"#92400E",pillNoModuleBg:"#FFE4E6",pillNoModuleText:"#BE123C",headerText:"#1F2937",arrowBg:"#F3F4F6"},On=new Set(et.map(e=>e.id));function ye(e){return nt[e]||et.find(n=>n.id===e)?.moduleTitle||e.split("-").slice(2).join(" ").replace(/\b\w/g,n=>n.toUpperCase())}function In(e){switch(e){case"coming_soon":return{style:{backgroundColor:J.pillComingSoonBg,color:J.pillComingSoonText,cursor:"pointer"},icon:r.jsx(tt,{size:14})};case"progression_locked":return{style:{backgroundColor:J.pillLockedBg,color:J.pillLockedText,cursor:"pointer"},icon:r.jsx(Ze,{size:14})};case"no_module":return{style:{backgroundColor:J.pillNoModuleBg,color:J.pillNoModuleText,cursor:"pointer"},icon:r.jsx(Se,{size:14})};default:return{style:{backgroundColor:J.pillBg,color:J.pillText,cursor:"pointer"},icon:r.jsx(Se,{size:14})}}}const Qn=({flaggedTopics:e=[],atRiskSubjects:n=[],unlockedModuleIds:t,moduleStatusMap:i={},resolutionStateMap:s={},fallbackContentMap:a={},onTopicClick:h,onNavigateToPrerequisite:w,studentId:y})=>{const S=U.useRef(null),[v,m]=U.useState(!1),[c,$]=U.useState(null),[I,M]=U.useState({}),[F,f]=U.useState(null),[A,N]=U.useState(!1),[l,V]=U.useState(""),X=e.filter(b=>On.has(b));if(X.length===0)return null;const p=()=>{if(S.current){const{scrollLeft:b,scrollWidth:j,clientWidth:O}=S.current;m(b+O{S.current?.scrollBy({left:200,behavior:"smooth"})},x=b=>{if(s[b])return s[b];const j=i[b];return j==="coming_soon"?"coming_soon":j==="unavailable"?"no_module":(j==="available"||j==="teacher_uploaded")&&t&&!t.has(b)?"progression_locked":"accessible"},G=async b=>{if(x(b)==="accessible"){if(c===b){h?.(b);return}if($(b),!I[b]&&y){f(b);try{const O=ye(b),_=await Dt(y,b,O,"General Mathematics",.7);_.generated&&M(W=>({...W,[b]:_.tips}))}catch{}f(null)}}else V(b),N(!0)},B=l?x(l):"no_module",H=l&&a[l]||null,u=l||null;return r.jsxs(r.Fragment,{children:[r.jsxs(Ie.div,{initial:{opacity:0,y:-8},animate:{opacity:1,y:0},className:"mb-4",children:[r.jsx("h3",{className:"text-base font-bold mb-3",style:{color:J.headerText},children:"Recommended for Review"}),r.jsxs("div",{className:"relative flex items-center",children:[r.jsx("div",{ref:S,onScroll:p,className:"flex gap-2 overflow-x-auto scrollbar-hide pb-1",style:{scrollbarWidth:"none",msOverflowStyle:"none"},children:X.slice(0,8).map((b,j)=>{const O=x(b),{style:_,icon:W}=In(O);return r.jsxs("button",{onClick:()=>G(b),title:O==="coming_soon"?"Module coming soon — tap for study brief":O==="progression_locked"?"Locked — complete previous module first":O==="no_module"?"No module yet — tap for curriculum brief":void 0,className:"flex items-center gap-1.5 px-4 py-2 rounded-full text-sm font-semibold transition-all whitespace-nowrap hover:scale-[1.02] active:scale-[0.98]",style:_,children:[W,ye(b),O==="accessible"&&r.jsx(Ve,{size:14})]},`${b}-${j}`)})}),v&&r.jsx("button",{onClick:R,className:"flex-shrink-0 ml-2 w-8 h-8 rounded-full flex items-center justify-center transition-colors",style:{backgroundColor:J.arrowBg},"aria-label":"Scroll right",children:r.jsx(Ve,{size:16,className:"text-gray-600"})})]}),r.jsx("style",{children:` .scrollbar-hide::-webkit-scrollbar { display: none; } diff --git a/assets/TeacherDashboard-BlgU-Xg_.js b/assets/TeacherDashboard-Dqx3gqwf.js similarity index 99% rename from assets/TeacherDashboard-BlgU-Xg_.js rename to assets/TeacherDashboard-Dqx3gqwf.js index 852bd51dcbc5c22f7d70a533fc92a8c4e0c97d4b..790dc101a4d0d29be09a0f38f0f2a92f6c56d26a 100644 --- a/assets/TeacherDashboard-BlgU-Xg_.js +++ b/assets/TeacherDashboard-Dqx3gqwf.js @@ -1,5 +1,5 @@ -const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-BufUS6SI.js","assets/vendor-react-B4AQeu28.js","assets/vendor-firebase-firestore-CNv3xXal.js","assets/vendor-firebase-core-D7GXCeNu.js","assets/vendor-firebase-auth-T_wvTOvf.js","assets/vendor-firebase-storage-Bi7H_66d.js","assets/vendor-firebase-analytics-rHarj5hR.js","assets/vendor-radix-C5nwdvGr.js","assets/vendor-charts-CAmziV1y.js","assets/vendor-markdown-yqZQ_iQm.js","assets/vendor-markdown-CfVKi3_s.css","assets/index-CIg5rXpX.css","assets/jspdf.es.min-C77sCDH3.js"])))=>i.map(i=>d[i]); -import{e as wt,t as Dl,f as zn,g as He,_ as Ss,u as hs,h as zt,m as Le,i as ci,j as ie,k as di,R as cs,l as $l,n as xt,o as ui,b as Gt,G as mi,B as Ur,Z as Fl,p as rr,q as gt,A as xi,U as us,r as ms,T as la,v as Ja,C as Ol,w as Dn,x as Pl,y as ca,z as Gr,D as $n,E as pi,F as Bl,H as nr,I as Hl,J as Ul,K as Gl,M as Ql,N as Fn,O as Vl,P as Wl}from"./index-BufUS6SI.js";import{d as he,j as e,r as u,c as Qr}from"./vendor-react-B4AQeu28.js";import{B as St,c as ql}from"./button-DsnZWCoA.js";import{I as Is}from"./input-BPglbGHJ.js";import Yl from"./ConfirmModal-B3J78vrR.js";import{collection as Mt,query as At,limit as or,where as Et,getDocs as Ot,doc as pt,getDoc as ks,updateDoc as es,serverTimestamp as it,setDoc as ts,arrayRemove as Kl,deleteDoc as hi,Timestamp as Xl,orderBy as Jl,onSnapshot as fi,addDoc as gi}from"./vendor-firebase-firestore-CNv3xXal.js";import{X as Xt}from"./x-BuBjuj2Y.js";import{S as qs}from"./search-DFK_sFlt.js";import{C as Ht}from"./check-B-qbiSF7.js";import{P as da}from"./plus-B4qs4LzO.js";import{F as Rs,N as Zl,A as bi}from"./NotificationDropdown-BwLtHvqY.js";import{M as ec,L as tc,D as sc,S as ac,a as rc}from"./LogoutActionButton-ke8I5kxg.js";import{f as nc,V as oc,P as ir,s as On,a as vi,L as lr,d as ic,p as lc,b as cc,A as cr,c as dc}from"./quizService-pQBMW3NE.js";import{C as As}from"./clock-CooTZK0X.js";import{S as aa}from"./send-DsMS4hUP.js";import{C as La}from"./circle-check-big-CDg2qLfH.js";import{S as uc}from"./vendor-radix-C5nwdvGr.js";import{T as mc,a as xc,b as pc}from"./tooltip-qcWo8nUO.js";import{C as hc}from"./circle-help-DNA0h1v1.js";import{E as fc,a as gc}from"./eye-CDIJHn8i.js";import{T as wi}from"./trash-2-CBXOjqKg.js";import{C as br}from"./circle-alert-DDdeEgNa.js";import{I as na}from"./info-a-Ci1_jf.js";import{C as $t,a as Ca}from"./chevron-up-CoNRuMZ7.js";import{M as Pn}from"./minus-DuS-NH5j.js";import{C as Ls}from"./chart-column-BcVJ31XT.js";import{C as Vr,H as Bn,S as Hn}from"./skeleton-CyzcASDd.js";import{D as bc}from"./download-DGNoiQkf.js";import{C as zs}from"./chevron-left-DMbkPbec.js";import{C as Ms}from"./chevron-right-DADygX42.js";import{S as Ni}from"./save-CwINi309.js";import{C as ya}from"./circle-check-BzgmgbHa.js";import{S as ps}from"./sparkles-DYlMf97S.js";import{U as Wr}from"./upload-gDf1MsBj.js";import{L as vc,C as wc}from"./lightbulb-bxzKA78M.js";import{u as Nc}from"./useQuery-BQZpC2ch.js";import{S as Un,g as jc,G as yc,s as Gn}from"./subjects-D9a9cUC-.js";import{u as Sc}from"./useCurriculum-DhjMQzo9.js";import kc from"./ChatMarkdown-BrSWjY6i.js";import{c as Cc,a as ji,C as Ic,f as Tc}from"./formatDistanceToNow-cESSXRCA.js";import{B as dr}from"./bell-D9j1Gy0m.js";import{D as Qn,a as Vn,b as _c,c as Ec,d as Rc,S as Mc}from"./dialog-JRlpFJpo.js";import{u as Kt,r as Ac}from"./vendor-xlsx-uZelXSz_.js";import{s as Lc}from"./moduleWatchService-D8kT4330.js";import{r as zc,u as Dc,a as $c}from"./vendor-firebase-storage-Bi7H_66d.js";import{C as qr}from"./clipboard-check-UJ1-0W8j.js";import{R as Wn,B as qn,C as Yn,X as Kn,Y as Xn,T as Jn,a as Zn,b as eo}from"./vendor-charts-CAmziV1y.js";import"./vendor-firebase-core-D7GXCeNu.js";import"./vendor-firebase-auth-T_wvTOvf.js";import"./vendor-firebase-analytics-rHarj5hR.js";import"./vendor-markdown-yqZQ_iQm.js";import"./log-out-Cp6gBYHP.js";/** +const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-Bp7MiGcW.js","assets/vendor-react-B4AQeu28.js","assets/vendor-firebase-firestore-CNv3xXal.js","assets/vendor-firebase-core-D7GXCeNu.js","assets/vendor-firebase-auth-T_wvTOvf.js","assets/vendor-firebase-storage-Bi7H_66d.js","assets/vendor-firebase-analytics-rHarj5hR.js","assets/vendor-radix-C5nwdvGr.js","assets/vendor-charts-CAmziV1y.js","assets/vendor-markdown-yqZQ_iQm.js","assets/vendor-markdown-CfVKi3_s.css","assets/index-Dja0MwoB.css","assets/jspdf.es.min-IqJLf-7q.js"])))=>i.map(i=>d[i]); +import{e as wt,t as Dl,f as zn,g as He,_ as Ss,u as hs,h as zt,m as Le,i as ci,j as ie,k as di,R as cs,l as $l,n as xt,o as ui,b as Gt,G as mi,B as Ur,Z as Fl,p as rr,q as gt,A as xi,U as us,r as ms,T as la,v as Ja,C as Ol,w as Dn,x as Pl,y as ca,z as Gr,D as $n,E as pi,F as Bl,H as nr,I as Hl,J as Ul,K as Gl,M as Ql,N as Fn,O as Vl,P as Wl}from"./index-Bp7MiGcW.js";import{d as he,j as e,r as u,c as Qr}from"./vendor-react-B4AQeu28.js";import{B as St,c as ql}from"./button-BMVm9YQO.js";import{I as Is}from"./input-Co0dljwe.js";import Yl from"./ConfirmModal-CH3zQe0u.js";import{collection as Mt,query as At,limit as or,where as Et,getDocs as Ot,doc as pt,getDoc as ks,updateDoc as es,serverTimestamp as it,setDoc as ts,arrayRemove as Kl,deleteDoc as hi,Timestamp as Xl,orderBy as Jl,onSnapshot as fi,addDoc as gi}from"./vendor-firebase-firestore-CNv3xXal.js";import{X as Xt}from"./x-k8d6VLEw.js";import{S as qs}from"./search-DbD51Zen.js";import{C as Ht}from"./check-qsSFTYCr.js";import{P as da}from"./plus-D4SEqrVj.js";import{F as Rs,N as Zl,A as bi}from"./NotificationDropdown-DNm6nFOm.js";import{M as ec,L as tc,D as sc,S as ac,a as rc}from"./LogoutActionButton-BlHbD8Uf.js";import{f as nc,V as oc,P as ir,s as On,a as vi,L as lr,d as ic,p as lc,b as cc,A as cr,c as dc}from"./quizService-DrftrnKO.js";import{C as As}from"./clock-Cc6sJz1J.js";import{S as aa}from"./send-BA-OOIJf.js";import{C as La}from"./circle-check-big-JdaMs3bP.js";import{S as uc}from"./vendor-radix-C5nwdvGr.js";import{T as mc,a as xc,b as pc}from"./tooltip-nLNeX3nd.js";import{C as hc}from"./circle-help-CLCoBWDy.js";import{E as fc,a as gc}from"./eye-B_U0s6fm.js";import{T as wi}from"./trash-2-BhUbBhdb.js";import{C as br}from"./circle-alert-CHGy8HcB.js";import{I as na}from"./info-Bcg_cBHY.js";import{C as $t,a as Ca}from"./chevron-up-DtS9MvUZ.js";import{M as Pn}from"./minus-BK7K7Pi2.js";import{C as Ls}from"./chart-column-Dyv8TfXk.js";import{C as Vr,S as Bn}from"./skeleton-BM3FTF2K.js";import{D as bc}from"./download-DFL4ZCXr.js";import{C as zs}from"./chevron-left-Be5knpOV.js";import{C as Ms}from"./chevron-right-BxoysOas.js";import{S as Ni}from"./save-D7oNX_Ki.js";import{C as ya}from"./circle-check-DzQphSnP.js";import{S as ps}from"./sparkles-fLB3ltj1.js";import{U as Wr}from"./upload-CP6O7WIX.js";import{L as vc,C as wc}from"./lightbulb-DG1NwVgr.js";import{u as Nc}from"./useQuery-DN_XJYxl.js";import{S as Hn,g as jc,G as yc,s as Un}from"./subjects-DNoBzeBL.js";import{u as Sc}from"./useCurriculum-BaLeFz19.js";import kc from"./ChatMarkdown-Cwsa2RCx.js";import{c as Cc,a as ji,C as Ic,f as Tc}from"./formatDistanceToNow-D-5-www2.js";import{H as Gn}from"./history-DVu_-tNM.js";import{B as dr}from"./bell-DyLbgepV.js";import{D as Qn,a as Vn,b as _c,c as Ec,d as Rc,S as Mc}from"./dialog-C3ON9pD8.js";import{u as Kt,r as Ac}from"./vendor-xlsx-uZelXSz_.js";import{s as Lc}from"./moduleWatchService-Cyzc6bn4.js";import{r as zc,u as Dc,a as $c}from"./vendor-firebase-storage-Bi7H_66d.js";import{C as qr}from"./clipboard-check-Cb8JdEuA.js";import{R as Wn,B as qn,C as Yn,X as Kn,Y as Xn,T as Jn,a as Zn,b as eo}from"./vendor-charts-CAmziV1y.js";import"./vendor-firebase-core-D7GXCeNu.js";import"./vendor-firebase-auth-T_wvTOvf.js";import"./vendor-firebase-analytics-rHarj5hR.js";import"./vendor-markdown-yqZQ_iQm.js";import"./log-out-DrAbcVI9.js";/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. @@ -94,7 +94,7 @@ import{e as wt,t as Dl,f as zn,g as He,_ as Ss,u as hs,h as zt,m as Le,i as ci,j * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. - */const ud=[["path",{d:"m21.64 3.64-1.28-1.28a1.21 1.21 0 0 0-1.72 0L2.36 18.64a1.21 1.21 0 0 0 0 1.72l1.28 1.28a1.2 1.2 0 0 0 1.72 0L21.64 5.36a1.2 1.2 0 0 0 0-1.72",key:"ul74o6"}],["path",{d:"m14 7 3 3",key:"1r5n42"}],["path",{d:"M5 6v4",key:"ilb8ba"}],["path",{d:"M19 14v4",key:"blhpug"}],["path",{d:"M10 2v2",key:"7u0qdc"}],["path",{d:"M7 8H3",key:"zfb6yr"}],["path",{d:"M21 16h-4",key:"1cnmox"}],["path",{d:"M11 3H9",key:"1obp7u"}]],Xr=wt("wand-sparkles",ud);function md(t,s){const a=Dl(t);return isNaN(s)?Cc(t,NaN):(a.setDate(a.getDate()+s),a)}function Ci(t,s){const a=zn(t),r=zn(s);return+a==+r}function so(t){return Ci(t,ji(t))}function xd(t,s){return md(t,-1)}function ao(t){return Ci(t,xd(ji(t)))}const vr=0,$s=1,ua=2,Ii=4;function ro(t){return()=>t}function pd(t){t()}function Ti(t,s){return a=>t(s(a))}function no(t,s){return()=>t(s)}function hd(t,s){return a=>t(s,a)}function cn(t){return t!==void 0}function fd(...t){return()=>{t.map(pd)}}function ma(){}function wr(t,s){return s(t),t}function gd(t,s){return s(t)}function at(...t){return t}function Xe(t,s){return t($s,s)}function Ae(t,s){t(vr,s)}function dn(t){t(ua)}function ot(t){return t(Ii)}function ge(t,s){return Xe(t,hd(s,vr))}function ss(t,s){const a=t($s,r=>{a(),s(r)});return a}function oo(t){let s,a;return r=>o=>{s=o,a&&clearTimeout(a),a=setTimeout(()=>{r(s)},t)}}function _i(t,s){return t===s}function st(t=_i){let s;return a=>r=>{t(s,r)||(s=r,a(r))}}function ke(t){return s=>a=>{t(a)&&s(a)}}function xe(t){return s=>Ti(s,t)}function ls(t){return s=>()=>{s(t)}}function K(t,...s){const a=bd(...s);return((r,o)=>{switch(r){case ua:dn(t);return;case $s:return Xe(t,a(o))}})}function ds(t,s){return a=>r=>{a(s=t(s,r))}}function Ws(t){return s=>a=>{t>0?t--:s(a)}}function Cs(t){let s=null,a;return r=>o=>{s=o,!a&&(a=setTimeout(()=>{a=void 0,r(s)},t))}}function ze(...t){const s=new Array(t.length);let a=0,r=null;const o=2**t.length-1;return t.forEach((n,i)=>{const l=2**i;Xe(n,c=>{const d=a;a|=l,s[i]=c,d!==o&&a===o&&r&&(r(),r=null)})}),n=>i=>{const l=()=>{n([i].concat(s))};a===o?l():r=l}}function bd(...t){return s=>t.reduceRight(gd,s)}function vd(t){let s,a;const r=()=>s?.();return function(o,n){switch(o){case $s:return n?a===n?void 0:(r(),a=n,s=Xe(t,n),s):(r(),ma);case ua:r(),a=null;return}}}function Z(t){let s=t;const a=Be();return((r,o)=>{switch(r){case vr:s=o;break;case $s:{o(s);break}case Ii:return s}return a(r,o)})}function Rt(t,s){return wr(Z(s),a=>ge(t,a))}function Be(){const t=[];return((s,a)=>{switch(s){case vr:t.slice().forEach(r=>{r(a)});return;case ua:t.splice(0,t.length);return;case $s:return t.push(a),()=>{const r=t.indexOf(a);r>-1&&t.splice(r,1)}}})}function Qt(t){return wr(Be(),s=>ge(t,s))}function Ke(t,s=[],{singleton:a}={singleton:!0}){return{constructor:t,dependencies:s,id:wd(),singleton:a}}const wd=()=>Symbol();function Nd(t){const s=new Map,a=({constructor:r,dependencies:o,id:n,singleton:i})=>{if(i&&s.has(n))return s.get(n);const l=r(o.map(c=>a(c)));return i&&s.set(n,l),l};return a(t)}function ht(...t){const s=Be(),a=new Array(t.length);let r=0;const o=2**t.length-1;return t.forEach((n,i)=>{const l=2**i;Xe(n,c=>{a[i]=c,r|=l,r===o&&Ae(s,a)})}),function(n,i){switch(n){case ua:{dn(s);return}case $s:return r===o&&i(a),Xe(s,i)}}}function Se(t,s=_i){return K(t,st(s))}function Jr(...t){return function(s,a){switch(s){case ua:return;case $s:return fd(...t.map(r=>Xe(r,a)))}}}const vt={DEBUG:0,INFO:1,WARN:2,ERROR:3},jd={[vt.DEBUG]:"debug",[vt.ERROR]:"error",[vt.INFO]:"log",[vt.WARN]:"warn"},yd=()=>typeof globalThis>"u"?window:globalThis,Fs=Ke(()=>{const t=Z(vt.ERROR);return{log:Z((s,a,r=vt.INFO)=>{const o=yd().VIRTUOSO_LOG_LEVEL??ot(t);r>=o&&console[jd[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",s,a)}),logLevel:t}},[],{singleton:!0});function Ys(t,s,a){return un(t,s,a).callbackRef}function un(t,s,a){const r=he.useRef(null);let o=i=>{};const n=he.useMemo(()=>typeof ResizeObserver<"u"?new ResizeObserver(i=>{const l=()=>{const c=i[0].target;c.offsetParent!==null&&t(c)};a?l():requestAnimationFrame(l)}):null,[t,a]);return o=i=>{i&&s?(n?.observe(i),r.current=i):(r.current&&n?.unobserve(r.current),r.current=null)},{callbackRef:o,ref:r}}function Sd(t,s,a,r,o,n,i,l,c){const d=he.useCallback(m=>{const p=kd(m.children,s,l?"offsetWidth":"offsetHeight",o);let h=m.parentElement;for(;h.dataset.virtuosoScroller===void 0;)h=h.parentElement;const b=h.lastElementChild.dataset.viewportType==="window";let S;b&&(S=h.ownerDocument.defaultView);const k=i?l?i.scrollLeft:i.scrollTop:b?l?S.scrollX||S.document.documentElement.scrollLeft:S.scrollY||S.document.documentElement.scrollTop:l?h.scrollLeft:h.scrollTop,N=i?l?i.scrollWidth:i.scrollHeight:b?l?S.document.documentElement.scrollWidth:S.document.documentElement.scrollHeight:l?h.scrollWidth:h.scrollHeight,v=i?l?i.offsetWidth:i.offsetHeight:b?l?S.innerWidth:S.innerHeight:l?h.offsetWidth:h.offsetHeight;r({scrollHeight:N,scrollTop:Math.max(k,0),viewportHeight:v}),n?.(l?io("column-gap",getComputedStyle(m).columnGap,o):io("row-gap",getComputedStyle(m).rowGap,o)),p!==null&&t(p)},[t,s,o,n,i,r,l]);return un(d,a,c)}function kd(t,s,a,r){const o=t.length;if(o===0)return null;const n=[];for(let i=0;i{if(!c?.offsetParent)return;const d=c.getBoundingClientRect(),m=d.width;let p,h;if(s){const b=s.getBoundingClientRect(),S=d.top-b.top;h=b.height-Math.max(0,S),p=S+s.scrollTop}else{const b=i.current.ownerDocument.defaultView;h=b.innerHeight-Math.max(0,d.top),p=d.top+b.scrollY}r.current={listHeight:d.height,offsetTop:p,visibleHeight:h,visibleWidth:m},t(r.current)},[t,s]),{callbackRef:n,ref:i}=un(o,!0,a),l=he.useCallback(()=>{o(i.current)},[o,i]);return he.useEffect(()=>{if(s){s.addEventListener("scroll",l);const d=new ResizeObserver(()=>{requestAnimationFrame(l)});return d.observe(s),()=>{s.removeEventListener("scroll",l),d.unobserve(s)}}const c=i.current?.ownerDocument.defaultView;return c?.addEventListener("scroll",l),c?.addEventListener("resize",l),()=>{c?.removeEventListener("scroll",l),c?.removeEventListener("resize",l)}},[l,s,i]),n}const Dt=Ke(()=>{const t=Be(),s=Be(),a=Z(0),r=Be(),o=Z(0),n=Be(),i=Be(),l=Z(0),c=Z(0),d=Z(0),m=Z(0),p=Be(),h=Be(),b=Z(!1),S=Z(!1),k=Z(!1);return ge(K(t,xe(({scrollTop:N})=>N)),s),ge(K(t,xe(({scrollHeight:N})=>N)),i),ge(s,o),{deviation:a,fixedFooterHeight:d,fixedHeaderHeight:c,footerHeight:m,headerHeight:l,horizontalDirection:S,scrollBy:h,scrollContainerState:t,scrollHeight:i,scrollingInProgress:b,scrollTo:p,scrollTop:s,skipAnimationFrameInResizeObserver:k,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:n}},[],{singleton:!0}),Ia={lvl:0};function Ri(t,s){const a=t.length;if(a===0)return[];let{index:r,value:o}=s(t[0]);const n=[];for(let i=1;is&&(l=l.concat(en(o,s,a))),r>=s&&r<=a&&l.push({k:r,v:i}),r<=a&&(l=l.concat(en(n,s,a))),l}function er(t){const{l:s,lvl:a,r}=t;if(r.lvl>=a-1&&s.lvl>=a-1)return t;if(a>r.lvl+1){if(Rr(s))return zi(bt(t,{lvl:a-1}));if(!et(s)&&!et(s.r))return bt(s.r,{l:bt(s,{r:s.r.l}),lvl:a,r:bt(t,{l:s.r.r,lvl:a-1})});throw new Error("Unexpected empty nodes")}if(Rr(t))return tn(bt(t,{lvl:a-1}));if(!et(r)&&!et(r.l)){const o=r.l,n=Rr(o)?r.lvl-1:r.lvl;return bt(o,{l:bt(t,{lvl:a-1,r:o.l}),lvl:o.lvl+1,r:tn(bt(r,{l:o.r,lvl:n}))})}throw new Error("Unexpected empty nodes")}function bt(t,s){return Li(s.k!==void 0?s.k:t.k,s.v!==void 0?s.v:t.v,s.lvl!==void 0?s.lvl:t.lvl,s.l!==void 0?s.l:t.l,s.r!==void 0?s.r:t.r)}function Mi(t){return et(t.r)?t.l:er(bt(t,{r:Mi(t.r)}))}function Rr(t){return et(t)||t.lvl>t.r.lvl}function Ai(t){return et(t.r)?[t.k,t.v]:Ai(t.r)}function Li(t,s,a,r=Ia,o=Ia){return{k:t,l:r,lvl:a,r:o,v:s}}function lo(t){return tn(zi(t))}function zi(t){const{l:s}=t;return!et(s)&&s.lvl===t.lvl?bt(s,{r:bt(t,{l:s.r})}):t}function tn(t){const{lvl:s,r:a}=t;return!et(a)&&!et(a.r)&&a.lvl===s&&a.r.lvl===s?bt(a,{l:bt(t,{r:a.l}),lvl:s+1}):t}function Cd(t){return Ri(t,({k:s,v:a})=>({index:s,value:a}))}function Di(t,s){return!!(t&&t.startIndex===s.startIndex&&t.endIndex===s.endIndex)}function _a(t,s){return!!(t&&t[0]===s[0]&&t[1]===s[1])}const mn=Ke(()=>({recalcInProgress:Z(!1)}),[],{singleton:!0});function $i(t,s,a){return t[mr(t,s,a)]}function mr(t,s,a,r=0){let o=t.length-1;for(;r<=o;){const n=Math.floor((r+o)/2),i=t[n],l=a(i,s);if(l===0)return n;if(l===-1){if(o-r<2)return n-1;o=n-1}else{if(o===r)return n;r=n+1}}throw new Error(`Failed binary finding record in array - ${t.join(",")}, searched for ${s}`)}function Id(t,s,a,r){const o=mr(t,s,r),n=mr(t,a,r,o);return t.slice(o,n+1)}function Ds(t,s){return Math.round(t.getBoundingClientRect()[s])}function Nr(t){return!et(t.groupOffsetTree)}function xn({index:t},s){return s===t?0:s=p||n===h)&&(t=Zr(t,p)):(d=h!==n,c=!0),m>o&&o>=p&&h!==n&&(t=Ut(t,o+1,h));d&&(t=Ut(t,i,n))}return[t,a]}function Ed(t){return typeof t.groupIndex<"u"}function Rd({offset:t},s){return s===t?0:s0?l+a:l}function Fi(t,s){if(!Nr(s))return t;let a=0;for(;s.groupIndices[a]<=t+a;)a++;return t+a}function Oi(t,s,a){if(Ed(t))return s.groupIndices[t.groupIndex]+1;const r=t.index==="LAST"?a:t.index;let o=Fi(r,s);return o=Math.max(0,o,Math.min(a,o)),o}function Md(t,s,a,r=0){return r>0&&(s=Math.max(s,$i(t,r,xn).offset)),Ri(Id(t,s,a,Rd),zd)}function Ad(t,[s,a,r,o]){s.length>0&&r("received item sizes",s,vt.DEBUG);const n=t.sizeTree;let i=n,l=0;if(a.length>0&&et(n)&&s.length===2){const h=s[0].size,b=s[1].size;i=a.reduce((S,k)=>Ut(Ut(S,k,h),k+1,b),i)}else[i,l]=_d(i,s);if(i===n)return t;const{lastIndex:c,lastOffset:d,lastSize:m,offsetTree:p}=sn(t.offsetTree,l,i,o);return{groupIndices:a,groupOffsetTree:a.reduce((h,b)=>Ut(h,b,Ea(b,p,o)),oa()),lastIndex:c,lastOffset:d,lastSize:m,offsetTree:p,sizeTree:i}}function Ld(t){return Vs(t).map(({k:s,v:a},r,o)=>{const n=o[r+1];return{endIndex:n!==void 0?n.k-1:1/0,size:a,startIndex:s}})}function co(t,s){let a=0,r=0;for(;ao.start===r&&(o.end===s||o.end===1/0)&&o.value===a}const $d={offsetHeight:"height",offsetWidth:"width"},fs=Ke(([{log:t},{recalcInProgress:s}])=>{const a=Be(),r=Be(),o=Rt(r,0),n=Be(),i=Be(),l=Z(0),c=Z([]),d=Z(void 0),m=Z(void 0),p=Z(void 0),h=Z(void 0),b=Z((f,C)=>Ds(f,$d[C])),S=Z(void 0),k=Z(0),N=Td(),v=Rt(K(a,ze(c,t,k),ds(Ad,N),st()),N),g=Rt(K(c,st(),ds((f,C)=>({current:C,prev:f.current}),{current:[],prev:[]}),xe(({prev:f})=>f)),[]);ge(K(c,ke(f=>f.length>0),ze(v,k),xe(([f,C,w])=>{const $=f.reduce((A,y,q)=>Ut(A,y,Ea(y,C.offsetTree,w)||q),oa());return{...C,groupIndices:f,groupOffsetTree:$}})),v),ge(K(r,ze(v),ke(([f,{lastIndex:C}])=>f[{endIndex:C,size:w,startIndex:f}])),a),ge(d,m);const I=Rt(K(d,xe(f=>f===void 0)),!0);ge(K(m,ke(f=>f!==void 0&&et(ot(v).sizeTree)),xe(f=>{const C=ot(p),w=ot(c).length>0;return C!==void 0&&C!==0?w?[{endIndex:0,size:C,startIndex:0},{endIndex:1,size:f,startIndex:1}]:[]:[{endIndex:0,size:f,startIndex:0}]})),a),ge(K(h,ke(f=>f!==void 0&&f.length>0&&et(ot(v).sizeTree)),xe(f=>{const C=[];let w=f[0],$=0;for(let A=1;Af!==void 0&&C!==void 0),xe(([f,C,w])=>{const $=[];for(let A=0;A({changed:w!==f,sizes:w}),{changed:!1,sizes:N}),xe(f=>f.changed)));Xe(K(l,ds((f,C)=>({diff:f.prev-C,prev:C}),{diff:0,prev:0}),xe(f=>f.diff)),f=>{const{groupIndices:C}=ot(v);if(f>0)Ae(s,!0),Ae(n,f+co(f,C));else if(f<0){const w=ot(g);w.length>0&&(f-=co(-f,w)),Ae(i,f)}}),Xe(K(l,ze(t)),([f,C])=>{f<0&&C("`firstItemIndex` prop should not be set to less than zero. If you don't know the total count, just use a very high value",{firstItemIndex:l},vt.ERROR)});const R=Qt(n);ge(K(n,ze(v),xe(([f,C])=>{const w=C.groupIndices.length>0,$=[],A=C.lastSize;if(w){const y=Ta(C.sizeTree,0);let q=0,J=0;for(;q{let Ie=le.ranges;return le.prevSize!==0&&(Ie=[...le.ranges,{endIndex:ne+f-1,size:le.prevSize,startIndex:le.prevIndex}]),{prevIndex:ne+f,prevSize:be,ranges:Ie}},{prevIndex:f,prevSize:0,ranges:$}).ranges}return Vs(C.sizeTree).reduce((y,{k:q,v:J})=>({prevIndex:q+f,prevSize:J,ranges:[...y.ranges,{endIndex:q+f-1,size:y.prevSize,startIndex:y.prevIndex}]}),{prevIndex:0,prevSize:A,ranges:[]}).ranges})),a);const W=Qt(K(i,ze(v,k),xe(([f,{offsetTree:C},w])=>{const $=-f;return Ea($,C,w)})));return ge(K(i,ze(v,k),xe(([f,C,w])=>{if(C.groupIndices.length>0){if(et(C.sizeTree))return C;let A=oa();const y=ot(g);let q=0,J=0,re=0;for(;q<-f;){re=y[J];const le=y[J+1]-re-1;J++,q+=le+1}if(A=Vs(C.sizeTree).reduce((le,{k:ne,v:be})=>Ut(le,Math.max(0,ne+f),be),A),q!==-f){const le=Ta(C.sizeTree,re);A=Ut(A,0,le);const ne=as(C.sizeTree,-f+1)[1];A=Ut(A,1,ne)}return{...C,sizeTree:A,...sn(C.offsetTree,0,A,w)}}const $=Vs(C.sizeTree).reduce((A,{k:y,v:q})=>Ut(A,Math.max(0,y+f),q),oa());return{...C,sizeTree:$,...sn(C.offsetTree,0,$,w)}})),v),{beforeUnshiftWith:R,data:S,defaultItemSize:m,firstItemIndex:l,fixedItemSize:d,fixedGroupSize:p,gap:k,groupIndices:c,heightEstimates:h,itemSize:b,listRefresh:z,shiftWith:i,shiftWithOffset:W,sizeRanges:a,sizes:v,statefulTotalCount:o,totalCount:r,trackItemSizes:I,unshiftWith:n}},at(Fs,mn),{singleton:!0});function Fd(t){return t.reduce((s,a)=>(s.groupIndices.push(s.totalCount),s.totalCount+=a+1,s),{groupIndices:[],totalCount:0})}const Pi=Ke(([{groupIndices:t,sizes:s,totalCount:a},{headerHeight:r,scrollTop:o}])=>{const n=Be(),i=Be(),l=Qt(K(n,xe(Fd)));return ge(K(l,xe(c=>c.totalCount)),a),ge(K(l,xe(c=>c.groupIndices)),t),ge(K(ht(o,s,r),ke(([c,d])=>Nr(d)),xe(([c,d,m])=>as(d.groupOffsetTree,Math.max(c-m,0),"v")[0]),st(),xe(c=>[c])),i),{groupCounts:n,topItemsIndexes:i}},at(fs,Dt)),Os=Ke(([{log:t}])=>{const s=Z(!1),a=Qt(K(s,ke(r=>r),st()));return Xe(s,r=>{r&&ot(t)("props updated",{},vt.DEBUG)}),{didMount:a,propsReady:s}},at(Fs),{singleton:!0}),Od=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function Bi(t){const s=typeof t=="number"?{index:t}:t;return s.align||(s.align="start"),(!s.behavior||!Od)&&(s.behavior="auto"),s.offset===void 0&&(s.offset=0),s}const za=Ke(([{gap:t,listRefresh:s,sizes:a,totalCount:r},{fixedFooterHeight:o,fixedHeaderHeight:n,footerHeight:i,headerHeight:l,scrollingInProgress:c,scrollTo:d,smoothScrollTargetReached:m,viewportHeight:p},{log:h}])=>{const b=Be(),S=Be(),k=Z(0);let N=null,v=null,g=null;function I(){N!==null&&(N(),N=null),g!==null&&(g(),g=null),v&&(clearTimeout(v),v=null),Ae(c,!1)}return ge(K(b,ze(a,p,r,k,l,i,h),ze(t,n,o),xe(([[z,R,W,f,C,w,$,A],y,q,J])=>{const re=Bi(z),{align:le,behavior:ne,offset:be}=re,Ie=f-1,de=Oi(re,R,Ie);let fe=Ea(de,R.offsetTree,y)+w;le==="end"?(fe+=q+as(R.sizeTree,de)[1]-W+J,de===Ie&&(fe+=$)):le==="center"?fe+=(q+as(R.sizeTree,de)[1]-W+J)/2:fe-=C,be!==void 0&&be!==0&&(fe+=be);const H=ee=>{I(),ee?(A("retrying to scroll to",{location:z},vt.DEBUG),Ae(b,z)):(Ae(S,!0),A("list did not change, scroll successful",{},vt.DEBUG))};if(I(),ne==="smooth"){let ee=!1;g=Xe(s,oe=>{ee=ee||oe}),N=ss(m,()=>{H(ee)})}else N=ss(K(s,Pd(150)),H);return v=setTimeout(()=>{I()},1200),Ae(c,!0),A("scrolling from index to",{behavior:ne,index:de,top:fe},vt.DEBUG),{behavior:ne,top:fe}})),d),{scrollTargetReached:S,scrollToIndex:b,topListHeight:k}},at(fs,Dt,Fs),{singleton:!0});function Pd(t){return s=>{const a=setTimeout(()=>{s(!1)},t);return r=>{r&&(s(!0),clearTimeout(a))}}}function pn(t,s){t===0?s():requestAnimationFrame(()=>{pn(t-1,s)})}function hn(t,s){const a=s-1;return typeof t=="number"?t:t.index==="LAST"?a:t.index}const Da=Ke(([{defaultItemSize:t,listRefresh:s,sizes:a},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:n},{didMount:i}])=>{const l=Z(!0),c=Z(0),d=Z(!0);return ge(K(i,ze(c),ke(([m,p])=>p!==0),ls(!1)),l),ge(K(i,ze(c),ke(([m,p])=>p!==0),ls(!1)),d),Xe(K(ht(s,i),ze(l,a,t,d),ke(([[,m],p,{sizeTree:h},b,S])=>m&&(!et(h)||cn(b))&&!p&&!S),ze(c)),([,m])=>{ss(o,()=>{Ae(d,!0)}),pn(4,()=>{ss(r,()=>{Ae(l,!0)}),Ae(n,m)})}),{initialItemFinalLocationReached:d,initialTopMostItemIndex:c,scrolledToInitialItem:l}},at(fs,Dt,za,Os),{singleton:!0});function Hi(t,s){return Math.abs(t-s)<1.01}const Ra="up",Sa="down",Bd="none",Hd={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},Ud=0,$a=Ke(([{footerHeight:t,headerHeight:s,scrollBy:a,scrollContainerState:r,scrollTop:o,viewportHeight:n}])=>{const i=Z(!1),l=Z(!0),c=Be(),d=Be(),m=Z(4),p=Z(Ud),h=Rt(K(Jr(K(Se(o),Ws(1),ls(!0)),K(Se(o),Ws(1),ls(!1),oo(100))),st()),!1),b=Rt(K(Jr(K(a,ls(!0)),K(a,ls(!1),oo(200))),st()),!1);ge(K(ht(Se(o),Se(p)),xe(([g,I])=>g<=I),st()),l),ge(K(l,Cs(50)),d);const S=Qt(K(ht(r,Se(n),Se(s),Se(t),Se(m)),ds((g,[{scrollHeight:I,scrollTop:z},R,W,f,C])=>{const w=z+R-I>-C,$={scrollHeight:I,scrollTop:z,viewportHeight:R};if(w){let y,q;return z>g.state.scrollTop?(y="SCROLLED_DOWN",q=g.state.scrollTop-z):(y="SIZE_DECREASED",q=g.state.scrollTop-z||g.scrollTopDelta),{atBottom:!0,atBottomBecause:y,scrollTopDelta:q,state:$}}let A;return $.scrollHeight>g.state.scrollHeight?A="SIZE_INCREASED":Rg!==void 0&&g.atBottom===I.atBottom))),k=Rt(K(r,ds((g,{scrollHeight:I,scrollTop:z,viewportHeight:R})=>{if(!Hi(g.scrollHeight,I)){const W=I-(z+R)<1;return g.scrollTop!==z&&W?{changed:!0,jump:g.scrollTop-z,scrollHeight:I,scrollTop:z}:{changed:!0,jump:0,scrollHeight:I,scrollTop:z}}return{changed:!1,jump:0,scrollHeight:I,scrollTop:z}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),ke(g=>g.changed),xe(g=>g.jump)),0);ge(K(S,xe(g=>g.atBottom)),i),ge(K(i,Cs(50)),c);const N=Z(Sa);ge(K(r,xe(({scrollTop:g})=>g),st(),ds((g,I)=>ot(b)?{direction:g.direction,prevScrollTop:I}:{direction:Ig.direction)),N),ge(K(r,Cs(50),ls(Bd)),N);const v=Z(0);return ge(K(h,ke(g=>!g),ls(0)),v),ge(K(o,Cs(100),ze(h),ke(([g,I])=>I),ds(([g,I],[z])=>[I,z],[0,0]),xe(([g,I])=>I-g)),v),{atBottomState:S,atBottomStateChange:c,atBottomThreshold:m,atTopStateChange:d,atTopThreshold:p,isAtBottom:i,isAtTop:l,isScrolling:h,lastJumpDueToItemResize:k,scrollDirection:N,scrollVelocity:v}},at(Dt)),Ma="top",Aa="bottom",uo="none";function mo(t,s,a){return typeof t=="number"?a===Ra&&s===Ma||a===Sa&&s===Aa?t:0:a===Ra?s===Ma?t.main:t.reverse:s===Aa?t.main:t.reverse}function xo(t,s){return typeof t=="number"?t:t[s]??0}const fn=Ke(([{deviation:t,fixedHeaderHeight:s,headerHeight:a,scrollTop:r,viewportHeight:o}])=>{const n=Be(),i=Z(0),l=Z(0),c=Z(0),d=Rt(K(ht(Se(r),Se(o),Se(a),Se(n,_a),Se(c),Se(i),Se(s),Se(t),Se(l)),xe(([m,p,h,[b,S],k,N,v,g,I])=>{const z=m-g,R=N+v,W=Math.max(h-z,0);let f=uo;const C=xo(I,Ma),w=xo(I,Aa);return b-=g,b+=h+v,S+=h+v,S-=g,b>m+R-C&&(f=Ra),Sm!==null),st(_a)),[0,0]);return{increaseViewportBy:l,listBoundary:n,overscan:c,topListHeight:i,visibleRange:d}},at(Dt),{singleton:!0});function Gd(t,s,a){if(Nr(s)){const r=Fi(t,s);return[{index:as(s.groupOffsetTree,r)[0],offset:0,size:0},{data:a?.[0],index:r,offset:0,size:0}]}return[{data:a?.[0],index:t,offset:0,size:0}]}const Mr={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function tr(t,s,a,r,o,n){const{lastIndex:i,lastOffset:l,lastSize:c}=o;let d=0,m=0;if(t.length>0){d=t[0].offset;const k=t[t.length-1];m=k.offset+k.size}const p=a-i,h=l+p*c+(p-1)*r,b=d,S=h-m;return{bottom:m,firstItemIndex:n,items:po(t,o,n),offsetBottom:S,offsetTop:d,top:b,topItems:po(s,o,n),topListHeight:s.reduce((k,N)=>N.size+k,0),totalCount:a}}function Ui(t,s,a,r,o,n){let i=0;if(a.groupIndices.length>0)for(const m of a.groupIndices){if(m-i>=t)break;i++}const l=t+i,c=hn(s,l),d=Array.from({length:l}).map((m,p)=>({data:n[p+c],index:p+c,offset:0,size:0}));return tr(d,[],l,o,a,r)}function po(t,s,a){if(t.length===0)return[];if(!Nr(s))return t.map(d=>({...d,index:d.index+a,originalIndex:d.index}));const r=t[0].index,o=t[t.length-1].index,n=[],i=ia(s.groupOffsetTree,r,o);let l,c=0;for(const d of t){(!l||l.end{const k=Z([]),N=Z(0),v=Be(),g=Z(0);ge(n.topItemsIndexes,k);const I=Rt(K(ht(b,S,Se(c,_a),Se(o),Se(r),Se(d),m,Se(k),Se(s),Se(a),Se(g),t),ke(([f,C,,w,,,,,,,,$])=>{const A=$!==void 0&&$.length!==w;return f&&!C&&!A}),xe(([,,[f,C],w,$,A,y,q,J,re,le,ne])=>{const be=$,{offsetTree:Ie,sizeTree:de}=be,fe=ot(N);if(w===0)return{...Mr,totalCount:w};if(f===0&&C===0)return fe===0?{...Mr,totalCount:w}:Ui(fe,A,$,J,re,ne||[]);if(et(de))return fe>0?null:tr(Gd(hn(A,w),be,ne),[],w,re,be,J);const H=[];if(q.length>0){const te=q[0],E=q[q.length-1];let Y=0;for(const V of ia(de,te,E)){const pe=V.value,D=Math.max(V.start,te),j=Math.min(V.end,E);for(let _=D;_<=j;_++)H.push({data:ne?.[_],index:_,offset:Y,size:pe}),Y+=pe}}if(!y)return tr([],H,w,re,be,J);const ee=q.length>0?q[q.length-1]+1:0,oe=Md(Ie,f,C,ee);if(oe.length===0)return null;const Re=w-1,Fe=wr([],te=>{for(const E of oe){const Y=E.value;let V=Y.offset,pe=E.start;const D=Y.size;if(Y.offset=C);_++)te.push({data:ne?.[_],index:_,offset:V,size:D}),V+=D+re}}),Pe=ho(le,Ma),G=ho(le,Aa);if(Fe.length>0&&(Pe>0||G>0)){const te=Fe[0],E=Fe[Fe.length-1];if(Pe>0&&te.index>ee){const Y=Math.min(Pe,te.index-ee),V=[];let pe=te.offset;for(let D=te.index-1;D>=te.index-Y;D--){const j=ia(de,D,D)[0]?.value??te.size;pe-=j+re,V.unshift({data:ne?.[D],index:D,offset:pe,size:j})}Fe.unshift(...V)}if(G>0&&E.indexf!==null),st()),Mr);ge(K(t,ke(cn),xe(f=>f?.length)),o),ge(K(I,xe(f=>f.topListHeight)),p),ge(p,l),ge(K(I,xe(f=>[f.top,f.bottom])),i),ge(K(I,xe(f=>f.items)),v);const z=Qt(K(I,ke(({items:f})=>f.length>0),ze(o,t),ke(([{items:f},C])=>f[f.length-1].originalIndex===C-1),xe(([,f,C])=>[f-1,C]),st(_a),xe(([f])=>f))),R=Qt(K(I,Cs(200),ke(({items:f,topItems:C})=>f.length>0&&f[0].originalIndex===C.length),xe(({items:f})=>f[0].index),st())),W=Qt(K(I,ke(({items:f})=>f.length>0),xe(({items:f})=>{let C=0,w=f.length-1;for(;f[C].type==="group"&&CC;)w--;return{endIndex:f[w].index,startIndex:f[C].index}}),st(Di)));return{endReached:z,initialItemCount:N,itemsRendered:v,listState:I,minOverscanItemCount:g,rangeChanged:W,startReached:R,topItemsIndexes:k,...h}},at(fs,Pi,fn,Da,za,$a,Os,mn),{singleton:!0}),Gi=Ke(([{fixedFooterHeight:t,fixedHeaderHeight:s,footerHeight:a,headerHeight:r},{listState:o}])=>{const n=Be(),i=Rt(K(ht(a,t,r,s,o),xe(([l,c,d,m,p])=>l+c+d+m+p.offsetBottom+p.bottom)),0);return ge(Se(i),n),{totalListHeight:i,totalListHeightChanged:n}},at(Dt,Ks),{singleton:!0}),Qd=Ke(([{viewportHeight:t},{totalListHeight:s}])=>{const a=Z(!1),r=Rt(K(ht(a,t,s),ke(([o])=>o),xe(([,o,n])=>Math.max(0,o-n)),Cs(0),st()),0);return{alignToBottom:a,paddingTopAddition:r}},at(Dt,Gi),{singleton:!0}),Qi=Ke(()=>({context:Z(null)})),Vd=({itemBottom:t,itemTop:s,locationParams:{align:a,behavior:r,...o},viewportBottom:n,viewportTop:i})=>sn?{...o,align:a??"end",...r!==void 0?{behavior:r}:{}}:null,Vi=Ke(([{gap:t,sizes:s,totalCount:a},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:n,scrollingInProgress:i,scrollTop:l,viewportHeight:c},{scrollToIndex:d}])=>{const m=Be();return ge(K(m,ze(s,c,a,n,o,r,l),ze(t),xe(([[p,h,b,S,k,N,v,g],I])=>{const{calculateViewLocation:z=Vd,done:R,...W}=p,f=Oi(p,h,S-1),C=Ea(f,h.offsetTree,I)+k+N,w=C+as(h.sizeTree,f)[1],$=g+N,A=g+b-v,y=z({itemBottom:w,itemTop:C,locationParams:W,viewportBottom:A,viewportTop:$});return y!==null?R&&ss(K(i,ke(q=>!q),Ws(ot(i)?1:2)),R):R?.(),y}),ke(p=>p!==null)),d),{scrollIntoView:m}},at(fs,Dt,za,Ks,Fs),{singleton:!0});function fo(t){return t===!1?!1:t==="smooth"?"smooth":"auto"}const Wd=(t,s)=>typeof t=="function"?fo(t(s)):s&&fo(t),qd=Ke(([{listRefresh:t,totalCount:s,fixedItemSize:a,data:r},{atBottomState:o,isAtBottom:n},{scrollToIndex:i},{scrolledToInitialItem:l},{didMount:c,propsReady:d},{log:m},{scrollingInProgress:p},{context:h},{scrollIntoView:b}])=>{const S=Z(!1),k=Be();let N=null;function v(R){Ae(i,{align:"end",behavior:R,index:"LAST"})}Xe(K(ht(K(Se(s),Ws(1)),c),ze(Se(S),n,l,p),xe(([[R,W],f,C,w,$])=>{let A=W&&w,y="auto";return A&&(y=Wd(f,C||$),A=A&&y!==!1),{followOutputBehavior:y,shouldFollow:A,totalCount:R}}),ke(({shouldFollow:R})=>R)),({followOutputBehavior:R,totalCount:W})=>{N!==null&&(N(),N=null),ot(a)!==void 0?requestAnimationFrame(()=>{ot(m)("following output to ",{totalCount:W},vt.DEBUG),v(R)}):N=ss(t,()=>{ot(m)("following output to ",{totalCount:W},vt.DEBUG),v(R),N=null})});function g(R){const W=ss(o,f=>{R&&!f.atBottom&&f.notAtBottomBecause==="SIZE_INCREASED"&&N===null&&(ot(m)("scrolling to bottom due to increased size",{},vt.DEBUG),v("auto"))});setTimeout(W,100)}Xe(K(ht(Se(S),s,d),ke(([R,,W])=>R!==!1&&W),ds(({value:R},[,W])=>({refreshed:R===W,value:W}),{refreshed:!1,value:0}),ke(({refreshed:R})=>R),ze(S,s)),([,R])=>{ot(l)&&g(R!==!1)}),Xe(k,()=>{g(ot(S)!==!1)}),Xe(ht(Se(S),o),([R,W])=>{R!==!1&&!W.atBottom&&W.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&v("auto")});const I=Z(null),z=Be();return ge(Jr(K(Se(r),xe(R=>R?.length??0)),K(Se(s))),z),Xe(K(ht(K(z,Ws(1)),c),ze(Se(I),l,p,h),xe(([[R,W],f,C,w,$])=>W&&C&&f?.({context:$,totalCount:R,scrollingInProgress:w})),ke(R=>!!R),Cs(0)),R=>{N!==null&&(N(),N=null),ot(a)!==void 0?requestAnimationFrame(()=>{ot(m)("scrolling into view",{}),Ae(b,R)}):N=ss(t,()=>{ot(m)("scrolling into view",{}),Ae(b,R),N=null})}),{autoscrollToBottom:k,followOutput:S,scrollIntoViewOnChange:I}},at(fs,$a,za,Da,Os,Fs,Dt,Qi,Vi)),Yd=Ke(([{data:t,firstItemIndex:s,gap:a,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:n,listState:i},{didMount:l}])=>(ge(K(l,ze(n),ke(([,c])=>c!==0),ze(o,r,s,a,t),xe(([[,c],d,m,p,h,b=[]])=>Ui(c,d,m,p,h,b))),i),{}),at(fs,Da,Ks,Os),{singleton:!0}),Kd=Ke(([{didMount:t},{scrollTo:s},{listState:a}])=>{const r=Z(0);return Xe(K(t,ze(r),ke(([,o])=>o!==0),xe(([,o])=>({top:o}))),o=>{ss(K(a,Ws(1),ke(n=>n.items.length>1)),()=>{requestAnimationFrame(()=>{Ae(s,o)})})}),{initialScrollTop:r}},at(Os,Dt,Ks),{singleton:!0}),Wi=Ke(([{scrollVelocity:t}])=>{const s=Z(!1),a=Be(),r=Z(!1);return ge(K(t,ze(r,s,a),ke(([o,n])=>n!==!1&&n!==void 0),xe(([o,n,i,l])=>{const{enter:c,exit:d}=n;if(i){if(d(o,l))return!1}else if(c(o,l))return!0;return i}),st()),s),Xe(K(ht(s,t,a),ze(r)),([[o,n,i],l])=>{o&&l!==!1&&l!==void 0&&l.change&&l.change(n,i)}),{isSeeking:s,scrollSeekConfiguration:r,scrollSeekRangeChanged:a,scrollVelocity:t}},at($a),{singleton:!0}),gn=Ke(([{scrollContainerState:t,scrollTo:s}])=>{const a=Be(),r=Be(),o=Be(),n=Z(!1),i=Z(void 0);return ge(K(ht(a,r),xe(([{scrollTop:l,viewportHeight:c},{offsetTop:d,listHeight:m}])=>({scrollHeight:m,scrollTop:Math.max(0,l-d),viewportHeight:c}))),t),ge(K(s,ze(r),xe(([l,{offsetTop:c}])=>({...l,top:l.top+c}))),o),{customScrollParent:i,useWindowScroll:n,windowScrollContainerState:a,windowScrollTo:o,windowViewportRect:r}},at(Dt)),Xd=Ke(([{sizeRanges:t,sizes:s},{headerHeight:a,scrollTop:r},{initialTopMostItemIndex:o},{didMount:n},{useWindowScroll:i,windowScrollContainerState:l,windowViewportRect:c}])=>{const d=Be(),m=Z(void 0),p=Z(null),h=Z(null);return ge(l,p),ge(c,h),Xe(K(d,ze(s,r,i,p,h,a)),([b,S,k,N,v,g,I])=>{const z=Ld(S.sizeTree);N&&v!==null&&g!==null&&(k=v.scrollTop-g.offsetTop),k-=I,b({ranges:z,scrollTop:k})}),ge(K(m,ke(cn),xe(Jd)),o),ge(K(n,ze(m),ke(([,b])=>b!==void 0),st(),xe(([,b])=>b.ranges)),t),{getState:d,restoreStateFrom:m}},at(fs,Dt,Da,Os,gn));function Jd(t){return{align:"start",index:0,offset:t.scrollTop}}const Zd=Ke(([{topItemsIndexes:t}])=>{const s=Z(0);return ge(K(s,ke(a=>a>=0),xe(a=>Array.from({length:a}).map((r,o)=>o))),t),{topItemCount:s}},at(Ks));function qi(t){let s=!1,a;return(()=>(s||(s=!0,a=t()),a))}const eu=qi(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),tu=Ke(([{deviation:t,scrollBy:s,scrollingInProgress:a,scrollTop:r},{isAtBottom:o,isScrolling:n,lastJumpDueToItemResize:i,scrollDirection:l},{listState:c},{beforeUnshiftWith:d,gap:m,shiftWithOffset:p,sizes:h},{log:b},{recalcInProgress:S}])=>{const k=Qt(K(c,ze(i),ds(([,v,g,I],[{bottom:z,items:R,offsetBottom:W,totalCount:f},C])=>{const w=z+W;let $=0;return g===f&&v.length>0&&R.length>0&&(R[0].originalIndex===0&&v[0].originalIndex===0||($=w-I,$!==0&&($+=C))),[$,R,f,w]},[0,[],0,0]),ke(([v])=>v!==0),ze(r,l,a,o,b,S),ke(([,v,g,I,,,z])=>!z&&!I&&v!==0&&g===Ra),xe(([[v],,,,,g])=>(g("Upward scrolling compensation",{amount:v},vt.DEBUG),v))));function N(v){v>0?(Ae(s,{behavior:"auto",top:-v}),Ae(t,0)):(Ae(t,0),Ae(s,{behavior:"auto",top:-v}))}return Xe(K(k,ze(t,n)),([v,g,I])=>{I&&eu()?Ae(t,g-v):N(-v)}),Xe(K(ht(Rt(n,!1),t,S),ke(([v,g,I])=>!v&&!I&&g!==0),xe(([v,g])=>g),Cs(1)),N),ge(K(p,xe(v=>({top:-v}))),s),Xe(K(d,ze(h,m),xe(([v,{groupIndices:g,lastSize:I,sizeTree:z},R])=>{function W(A){return A*(I+R)}if(g.length===0)return W(v);let f=0;const C=Ta(z,0);let w=0,$=0;for(;wv&&(f-=C,A=v-w+1),w+=A,f+=W(A),$++}return f})),v=>{Ae(t,v),requestAnimationFrame(()=>{Ae(s,{top:v}),requestAnimationFrame(()=>{Ae(t,0),Ae(S,!1)})})}),{deviation:t}},at(Dt,$a,Ks,fs,Fs,mn)),su=Ke(([t,s,a,r,o,n,i,l,c,d,m])=>({...t,...s,...a,...r,...o,...n,...i,...l,...c,...d,...m}),at(fn,Yd,Os,Wi,Gi,Kd,Qd,gn,Vi,Fs,Qi)),Yi=Ke(([{data:t,defaultItemSize:s,firstItemIndex:a,fixedItemSize:r,fixedGroupSize:o,gap:n,groupIndices:i,heightEstimates:l,itemSize:c,sizeRanges:d,sizes:m,statefulTotalCount:p,totalCount:h,trackItemSizes:b},{initialItemFinalLocationReached:S,initialTopMostItemIndex:k,scrolledToInitialItem:N},v,g,I,z,{scrollToIndex:R},W,{topItemCount:f},{groupCounts:C},w])=>{const{listState:$,minOverscanItemCount:A,topItemsIndexes:y,rangeChanged:q,...J}=z;return ge(q,w.scrollSeekRangeChanged),ge(K(w.windowViewportRect,xe(re=>re.visibleHeight)),v.viewportHeight),{data:t,defaultItemHeight:s,firstItemIndex:a,fixedItemHeight:r,fixedGroupHeight:o,gap:n,groupCounts:C,heightEstimates:l,initialItemFinalLocationReached:S,initialTopMostItemIndex:k,scrolledToInitialItem:N,sizeRanges:d,topItemCount:f,topItemsIndexes:y,totalCount:h,...I,groupIndices:i,itemSize:c,listState:$,minOverscanItemCount:A,scrollToIndex:R,statefulTotalCount:p,trackItemSizes:b,rangeChanged:q,...J,...w,...v,sizes:m,...g}},at(fs,Da,Dt,Xd,qd,Ks,za,tu,Zd,Pi,su));function au(t,s){const a={},r={};let o=0;const n=t.length;for(;o(v[g]=I=>{const z=N[s.methods[g]];Ae(z,I)},v),{})}function m(N){return i.reduce((v,g)=>(v[g]=vd(N[s.events[g]]),v),{})}const p=he.forwardRef(function(N,v){const{children:g,...I}=N,[z]=he.useState(()=>wr(Nd(t),f=>{c(f,I)})),[R]=he.useState(no(m,z));Qa(()=>{for(const f of i)f in I&&Xe(R[f],I[f]);return()=>{Object.values(R).map(dn)}},[I,R,z]),Qa(()=>{c(z,I)}),he.useImperativeHandle(v,ro(d(z)));const W=a;return e.jsx(l.Provider,{value:z,children:a!==void 0?e.jsx(W,{...au([...r,...o,...i],I),children:g}):g})}),h=N=>{const v=he.useContext(l);return he.useCallback(g=>{Ae(v[N],g)},[v,N])},b=N=>{const v=he.useContext(l)[N],g=he.useCallback(I=>Xe(v,I),[v]);return he.useSyncExternalStore(g,()=>ot(v),()=>ot(v))},S=N=>{const v=he.useContext(l)[N],[g,I]=he.useState(no(ot,v));return Qa(()=>Xe(v,z=>{z!==g&&I(ro(z))}),[v,g]),g},k=parseInt(he.version)>=18?b:S;return{Component:p,useEmitter:(N,v)=>{const g=he.useContext(l)[N];Qa(()=>Xe(g,v),[v,g])},useEmitterValue:k,usePublisher:h}}const Xi=he.createContext(void 0),Ji=he.createContext(void 0),Ar="-webkit-sticky",go="sticky",bn=qi(()=>{if(typeof document>"u")return go;const t=document.createElement("div");return t.style.position=Ar,t.style.position===Ar?Ar:go}),Zi=typeof document<"u"?he.useLayoutEffect:he.useEffect;function Lr(t){return"self"in t}function ru(t){return"body"in t}function el(t,s,a,r=ma,o,n){const i=he.useRef(null),l=he.useRef(null),c=he.useRef(null),d=he.useCallback(h=>{let b,S,k;const N=h.target;if(ru(N)||Lr(N)){const g=Lr(N)?N:N.defaultView;k=n===!0?g.scrollX:g.scrollY,b=n===!0?g.document.documentElement.scrollWidth:g.document.documentElement.scrollHeight,S=n===!0?g.innerWidth:g.innerHeight}else k=n===!0?N.scrollLeft:N.scrollTop,b=n===!0?N.scrollWidth:N.scrollHeight,S=n===!0?N.offsetWidth:N.offsetHeight;const v=()=>{t({scrollHeight:b,scrollTop:Math.max(k,0),viewportHeight:S})};h.suppressFlushSync===!0?v():Qr.flushSync(v),l.current!==null&&(k===l.current||k<=0||k===b-S)&&(l.current=null,s(!0),c.current&&(clearTimeout(c.current),c.current=null))},[t,s,n]);he.useEffect(()=>{const h=o||i.current;return r(o||i.current),d({suppressFlushSync:!0,target:h}),h.addEventListener("scroll",d,{passive:!0}),()=>{r(null),h.removeEventListener("scroll",d)}},[i,d,a,r,o]);function m(h){const b=i.current;if(!b||(n===!0?"offsetWidth"in b&&b.offsetWidth===0:"offsetHeight"in b&&b.offsetHeight===0))return;const S=h.behavior==="smooth";let k,N,v;Lr(b)?(N=Math.max(Ds(b.document.documentElement,n===!0?"width":"height"),n===!0?b.document.documentElement.scrollWidth:b.document.documentElement.scrollHeight),k=n===!0?b.innerWidth:b.innerHeight,v=n===!0?window.scrollX:window.scrollY):(N=b[n===!0?"scrollWidth":"scrollHeight"],k=Ds(b,n===!0?"width":"height"),v=b[n===!0?"scrollLeft":"scrollTop"]);const g=N-k;if(h.top=Math.ceil(Math.max(Math.min(g,h.top),0)),Hi(k,N)||h.top===v){t({scrollHeight:N,scrollTop:v,viewportHeight:k}),S&&s(!0);return}S?(l.current=h.top,c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{c.current=null,l.current=null,s(!0)},1e3)):l.current=null,n===!0&&(h={...h.behavior!==void 0?{behavior:h.behavior}:{},left:h.top}),b.scrollTo(h)}function p(h){n===!0&&(h={...h.behavior!==void 0?{behavior:h.behavior}:{},...h.top!==void 0?{left:h.top}:{}}),i.current.scrollBy(h)}return{scrollByCallback:p,scrollerRef:i,scrollToCallback:m}}function vn(t){return t}const nu=Ke(()=>{const t=Z(l=>`Item ${l}`),s=Z(l=>`Group ${l}`),a=Z({}),r=Z(vn),o=Z("div"),n=Z(ma),i=(l,c=null)=>Rt(K(a,xe(d=>d[l]),st()),c);return{components:a,computeItemKey:r,EmptyPlaceholder:i("EmptyPlaceholder"),FooterComponent:i("Footer"),GroupComponent:i("Group","div"),groupContent:s,HeaderComponent:i("Header"),HeaderFooterTag:o,ItemComponent:i("Item","div"),itemContent:t,ListComponent:i("List","div"),ScrollerComponent:i("Scroller","div"),scrollerRef:n,ScrollSeekPlaceholder:i("ScrollSeekPlaceholder"),TopItemListComponent:i("TopItemList")}}),ou=Ke(([t,s])=>({...t,...s}),at(Yi,nu)),iu=({height:t})=>e.jsx("div",{style:{height:t}}),lu={overflowAnchor:"none",position:bn(),zIndex:1},tl={overflowAnchor:"none"},cu={...tl,display:"inline-block",height:"100%"},bo=he.memo(function({showTopList:t=!1}){const s=Te("listState"),a=qt("sizeRanges"),r=Te("useWindowScroll"),o=Te("customScrollParent"),n=qt("windowScrollContainerState"),i=qt("scrollContainerState"),l=o||r?n:i,c=Te("itemContent"),d=Te("context"),m=Te("groupContent"),p=Te("trackItemSizes"),h=Te("itemSize"),b=Te("log"),S=qt("gap"),k=Te("horizontalDirection"),{callbackRef:N}=Sd(a,h,p,t?ma:l,b,S,o,k,Te("skipAnimationFrameInResizeObserver")),[v,g]=he.useState(0);Nn("deviation",J=>{v!==J&&g(J)});const I=Te("EmptyPlaceholder"),z=Te("ScrollSeekPlaceholder")??iu,R=Te("ListComponent"),W=Te("ItemComponent"),f=Te("GroupComponent"),C=Te("computeItemKey"),w=Te("isSeeking"),$=Te("groupIndices").length>0,A=Te("alignToBottom"),y=Te("initialItemFinalLocationReached"),q=t?{}:{boxSizing:"border-box",...k?{display:"inline-block",height:"100%",marginLeft:v!==0?v:A?"auto":0,paddingLeft:s.offsetTop,paddingRight:s.offsetBottom,whiteSpace:"nowrap"}:{marginTop:v!==0?v:A?"auto":0,paddingBottom:s.offsetBottom,paddingTop:s.offsetTop},...y?{}:{visibility:"hidden"}};return!t&&s.totalCount===0&&I!==null&&I!==void 0?e.jsx(I,{..._t(I,d)}):e.jsx(R,{..._t(R,d),"data-testid":t?"virtuoso-top-item-list":"virtuoso-item-list",ref:N,style:q,children:(t?s.topItems:s.items).map(J=>{const re=J.originalIndex,le=C(re+s.firstItemIndex,J.data,d);return w?u.createElement(z,{..._t(z,d),height:J.size,index:J.index,key:le,type:J.type||"item",...J.type==="group"?{}:{groupIndex:J.groupIndex}}):J.type==="group"?u.createElement(f,{..._t(f,d),"data-index":re,"data-item-index":J.index,"data-known-size":J.size,key:le,style:lu},m(J.index,d)):u.createElement(W,{..._t(W,d),...xu(W,J.data),"data-index":re,"data-item-group-index":J.groupIndex,"data-item-index":J.index,"data-known-size":J.size,key:le,style:k?cu:tl},$?c(J.index,J.groupIndex,J.data,d):c(J.index,J.data,d))})})}),du={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},uu={outline:"none",overflowX:"auto",position:"relative"},wn=t=>({height:"100%",position:"absolute",top:0,width:"100%",...t?{display:"flex",flexDirection:"column"}:void 0}),sl=(t,s,a=0)=>({...wn(t),position:s?"relative":"absolute",top:s?-a:0}),mu={position:bn(),top:0,width:"100%",zIndex:1};function _t(t,s){if(typeof t!="string")return{context:s}}function xu(t,s){return{item:typeof t=="string"?void 0:s}}const pu=he.memo(function(){const t=Te("HeaderComponent"),s=qt("headerHeight"),a=Te("HeaderFooterTag"),r=Ys(he.useMemo(()=>n=>{s(Ds(n,"height"))},[s]),!0,Te("skipAnimationFrameInResizeObserver")),o=Te("context");return t!=null?e.jsx(a,{ref:r,children:e.jsx(t,{..._t(t,o)})}):null}),hu=he.memo(function(){const t=Te("FooterComponent"),s=qt("footerHeight"),a=Te("HeaderFooterTag"),r=Ys(he.useMemo(()=>n=>{s(Ds(n,"height"))},[s]),!0,Te("skipAnimationFrameInResizeObserver")),o=Te("context");return t!=null?e.jsx(a,{ref:r,children:e.jsx(t,{..._t(t,o)})}):null});function al({useEmitter:t,useEmitterValue:s,usePublisher:a}){return he.memo(function({children:r,style:o,context:n,...i}){const l=a("scrollContainerState"),c=s("ScrollerComponent"),d=a("smoothScrollTargetReached"),m=s("scrollerRef"),p=s("horizontalDirection")||!1,{scrollByCallback:h,scrollerRef:b,scrollToCallback:S}=el(l,d,c,m,void 0,p);return t("scrollTo",S),t("scrollBy",h),e.jsx(c,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:b,style:{...p?uu:du,...o},tabIndex:0,...i,..._t(c,n),children:r})})}function rl({useEmitter:t,useEmitterValue:s,usePublisher:a}){return he.memo(function({children:r,style:o,context:n,...i}){const l=a("windowScrollContainerState"),c=s("ScrollerComponent"),d=a("smoothScrollTargetReached"),m=s("totalListHeight"),p=s("deviation"),h=s("customScrollParent"),b=he.useRef(null),S=s("scrollerRef"),{scrollByCallback:k,scrollerRef:N,scrollToCallback:v}=el(l,d,c,S,h);return Zi(()=>(N.current=h||b.current?.ownerDocument.defaultView,()=>{N.current=null}),[N,h]),t("windowScrollTo",v),t("scrollBy",k),e.jsx(c,{ref:b,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...m!==0?{height:m+p}:void 0},...i,..._t(c,n),children:r})})}const fu=({children:t})=>{const s=he.useContext(Xi),a=qt("viewportHeight"),r=qt("fixedItemHeight"),o=Te("alignToBottom"),n=Te("horizontalDirection"),i=he.useMemo(()=>Ti(a,c=>Ds(c,n?"width":"height")),[a,n]),l=Ys(i,!0,Te("skipAnimationFrameInResizeObserver"));return he.useEffect(()=>{s&&(a(s.viewportHeight),r(s.itemHeight))},[s,a,r]),e.jsx("div",{"data-viewport-type":"element",ref:l,style:wn(o),children:t})},gu=({children:t})=>{const s=he.useContext(Xi),a=qt("windowViewportRect"),r=qt("fixedItemHeight"),o=Te("customScrollParent"),n=Te("useWindowScroll"),i=Te("topListHeight"),l=Ei(a,o,Te("skipAnimationFrameInResizeObserver")),c=Te("alignToBottom");return he.useEffect(()=>{s&&(r(s.itemHeight),a({listHeight:0,offsetTop:0,visibleHeight:s.viewportHeight,visibleWidth:100}))},[s,a,r]),e.jsx("div",{"data-viewport-type":"window",ref:l,style:sl(c,n,i),children:t})},bu=({children:t})=>{const s=Te("TopItemListComponent")??"div",a=Te("headerHeight"),r={...mu,marginTop:`${a}px`},o=Te("context");return e.jsx(s,{style:r,..._t(s,o),children:t})},vu=he.memo(function(t){const s=Te("useWindowScroll"),a=Te("topItemsIndexes").length>0,r=Te("customScrollParent"),o=Te("context");return e.jsxs(r||s?ju:Nu,{...t,context:o,children:[a&&e.jsx(bu,{children:e.jsx(bo,{showTopList:!0})}),e.jsxs(r||s?gu:fu,{children:[e.jsx(pu,{}),e.jsx(bo,{}),e.jsx(hu,{})]})]})}),{Component:wu,useEmitter:Nn,useEmitterValue:Te,usePublisher:qt}=Ki(ou,{optional:{restoreStateFrom:"restoreStateFrom",context:"context",followOutput:"followOutput",scrollIntoViewOnChange:"scrollIntoViewOnChange",itemContent:"itemContent",groupContent:"groupContent",overscan:"overscan",increaseViewportBy:"increaseViewportBy",minOverscanItemCount:"minOverscanItemCount",totalCount:"totalCount",groupCounts:"groupCounts",topItemCount:"topItemCount",firstItemIndex:"firstItemIndex",initialTopMostItemIndex:"initialTopMostItemIndex",components:"components",atBottomThreshold:"atBottomThreshold",atTopThreshold:"atTopThreshold",computeItemKey:"computeItemKey",defaultItemHeight:"defaultItemHeight",fixedGroupHeight:"fixedGroupHeight",fixedItemHeight:"fixedItemHeight",heightEstimates:"heightEstimates",itemSize:"itemSize",scrollSeekConfiguration:"scrollSeekConfiguration",headerFooterTag:"HeaderFooterTag",data:"data",initialItemCount:"initialItemCount",initialScrollTop:"initialScrollTop",alignToBottom:"alignToBottom",useWindowScroll:"useWindowScroll",customScrollParent:"customScrollParent",scrollerRef:"scrollerRef",logLevel:"logLevel",horizontalDirection:"horizontalDirection",skipAnimationFrameInResizeObserver:"skipAnimationFrameInResizeObserver"},methods:{scrollToIndex:"scrollToIndex",scrollIntoView:"scrollIntoView",scrollTo:"scrollTo",scrollBy:"scrollBy",autoscrollToBottom:"autoscrollToBottom",getState:"getState"},events:{isScrolling:"isScrolling",endReached:"endReached",startReached:"startReached",rangeChanged:"rangeChanged",atBottomStateChange:"atBottomStateChange",atTopStateChange:"atTopStateChange",totalListHeightChanged:"totalListHeightChanged",itemsRendered:"itemsRendered",groupIndices:"groupIndices"}},vu),Nu=al({useEmitter:Nn,useEmitterValue:Te,usePublisher:qt}),ju=rl({useEmitter:Nn,useEmitterValue:Te,usePublisher:qt}),yu=wu,Su=Ke(()=>{const t=Z(d=>e.jsxs("td",{children:["Item $",d]})),s=Z(null),a=Z(d=>e.jsxs("td",{colSpan:1e3,children:["Group ",d]})),r=Z(null),o=Z(null),n=Z({}),i=Z(vn),l=Z(ma),c=(d,m=null)=>Rt(K(n,xe(p=>p[d]),st()),m);return{components:n,computeItemKey:i,context:s,EmptyPlaceholder:c("EmptyPlaceholder"),FillerRow:c("FillerRow"),fixedFooterContent:o,fixedHeaderContent:r,itemContent:t,groupContent:a,ScrollerComponent:c("Scroller","div"),scrollerRef:l,ScrollSeekPlaceholder:c("ScrollSeekPlaceholder"),TableBodyComponent:c("TableBody","tbody"),TableComponent:c("Table","table"),TableFooterComponent:c("TableFoot","tfoot"),TableHeadComponent:c("TableHead","thead"),TableRowComponent:c("TableRow","tr"),GroupComponent:c("Group","tr")}});at(Yi,Su);bn();const vo={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},ku={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:wo,floor:xr,max:ka,min:zr,round:No}=Math;function jo(t,s,a){return Array.from({length:s-t+1}).map((r,o)=>({data:a===null?null:a[o+t],index:o+t}))}function Cu(t){return{...ku,items:t}}function Va(t,s){return t!==void 0&&t.width===s.width&&t.height===s.height}function Iu(t,s){return t!==void 0&&t.column===s.column&&t.row===s.row}const Tu=Ke(([{increaseViewportBy:t,listBoundary:s,overscan:a,visibleRange:r},{footerHeight:o,headerHeight:n,scrollBy:i,scrollContainerState:l,scrollTo:c,scrollTop:d,smoothScrollTargetReached:m,viewportHeight:p},h,b,{didMount:S,propsReady:k},{customScrollParent:N,useWindowScroll:v,windowScrollContainerState:g,windowScrollTo:I,windowViewportRect:z},R])=>{const W=Z(0),f=Z(0),C=Z(vo),w=Z({height:0,width:0}),$=Z({height:0,width:0}),A=Be(),y=Be(),q=Z(0),J=Z(null),re=Z({column:0,row:0}),le=Be(),ne=Be(),be=Z(!1),Ie=Z(0),de=Z(!0),fe=Z(!1),H=Z(!1);Xe(K(S,ze(Ie),ke(([G,te])=>te!==0)),()=>{Ae(de,!1)}),Xe(K(ht(S,de,$,w,Ie,fe),ke(([G,te,E,Y,,V])=>G&&!te&&E.height!==0&&Y.height!==0&&!V)),([,,,,G])=>{Ae(fe,!0),pn(1,()=>{Ae(A,G)}),ss(K(d),()=>{Ae(s,[0,0]),Ae(de,!0)})}),ge(K(ne,ke(G=>G!=null&&G.scrollTop>0),ls(0)),f),Xe(K(S,ze(ne),ke(([,G])=>G!=null)),([,G])=>{G&&(Ae(w,G.viewport),Ae($,G.item),Ae(re,G.gap),G.scrollTop>0&&(Ae(be,!0),ss(K(d,Ws(1)),te=>{Ae(be,!1)}),Ae(c,{top:G.scrollTop})))}),ge(K(w,xe(({height:G})=>G)),p),ge(K(ht(Se(w,Va),Se($,Va),Se(re,(G,te)=>G!==void 0&&G.column===te.column&&G.row===te.row),Se(d)),xe(([G,te,E,Y])=>({gap:E,item:te,scrollTop:Y,viewport:G}))),le),ge(K(ht(Se(W),r,Se(re,Iu),Se($,Va),Se(w,Va),Se(J),Se(f),Se(be),Se(de),Se(Ie)),ke(([,,,,,,,G])=>!G),xe(([G,[te,E],Y,V,pe,D,j,,_,T])=>{const{column:Q,row:ue}=Y,{height:ce,width:ae}=V,{width:Ce}=pe;if(j===0&&(G===0||Ce===0))return vo;if(ae===0){const Lt=hn(T,G),rs=Lt+Math.max(j-1,0);return Cu(jo(Lt,rs,D))}const Ne=nl(Ce,ae,Q);let Je,$e;_?te===0&&E===0&&j>0?(Je=0,$e=j-1):(Je=Ne*xr((te+ue)/(ce+ue)),$e=Ne*wo((E+ue)/(ce+ue))-1,$e=zr(G-1,ka($e,Ne-1)),Je=zr($e,ka(0,Je))):(Je=0,$e=-1);const Ge=jo(Je,$e,D),{bottom:ft,top:Nt}=yo(pe,Y,V,Ge),dt=wo(G/Ne),jt=dt*ce+(dt-1)*ue-ft;return{bottom:ft,itemHeight:ce,items:Ge,itemWidth:ae,offsetBottom:jt,offsetTop:Nt,top:Nt}})),C),ge(K(J,ke(G=>G!==null),xe(G=>G.length)),W),ge(K(ht(w,$,C,re),ke(([G,te,{items:E}])=>E.length>0&&te.height!==0&&G.height!==0),xe(([G,te,{items:E},Y])=>{const{bottom:V,top:pe}=yo(G,Y,te,E);return[pe,V]}),st(_a)),s);const ee=Z(!1);ge(K(d,ze(ee),xe(([G,te])=>te||G!==0)),ee);const oe=Qt(K(ht(C,W),ke(([{items:G}])=>G.length>0),ze(ee),ke(([[G,te],E])=>{const Y=G.items[G.items.length-1].index===te-1;return(E||G.bottom>0&&G.itemHeight>0&&G.offsetBottom===0&&G.items.length===te)&&Y}),xe(([[,G]])=>G-1),st())),Re=Qt(K(Se(C),ke(({items:G})=>G.length>0&&G[0].index===0),ls(0),st())),Fe=Qt(K(Se(C),ze(be),ke(([{items:G},te])=>G.length>0&&!te),xe(([{items:G}])=>({endIndex:G[G.length-1].index,startIndex:G[0].index})),st(Di),Cs(0)));ge(Fe,b.scrollSeekRangeChanged),ge(K(A,ze(w,$,W,re),xe(([G,te,E,Y,V])=>{const pe=Bi(G),{align:D,behavior:j,offset:_}=pe;let T=pe.index;T==="LAST"&&(T=Y-1),T=ka(0,T,zr(Y-1,T));let Q=an(te,V,E,T);return D==="end"?Q=No(Q-te.height+E.height):D==="center"&&(Q=No(Q-te.height/2+E.height/2)),_!==void 0&&_!==0&&(Q+=_),{behavior:j,top:Q}})),c);const Pe=Rt(K(C,xe(G=>G.offsetBottom+G.bottom)),0);return ge(K(z,xe(G=>({height:G.visibleHeight,width:G.visibleWidth}))),w),{customScrollParent:N,data:J,deviation:q,footerHeight:o,gap:re,headerHeight:n,increaseViewportBy:t,initialItemCount:f,itemDimensions:$,overscan:a,restoreStateFrom:ne,scrollBy:i,scrollContainerState:l,scrollHeight:y,scrollTo:c,scrollToIndex:A,scrollTop:d,smoothScrollTargetReached:m,totalCount:W,useWindowScroll:v,viewportDimensions:w,windowScrollContainerState:g,windowScrollTo:I,windowViewportRect:z,...b,gridState:C,horizontalDirection:H,initialTopMostItemIndex:Ie,totalListHeight:Pe,...h,endReached:oe,propsReady:k,rangeChanged:Fe,startReached:Re,stateChanged:le,stateRestoreInProgress:be,...R}},at(fn,Dt,$a,Wi,Os,gn,Fs));function nl(t,s,a){return ka(1,xr((t+a)/(xr(s)+a)))}function yo(t,s,a,r){const{height:o}=a;if(o===void 0||r.length===0)return{bottom:0,top:0};const n=an(t,s,a,r[0].index);return{bottom:an(t,s,a,r[r.length-1].index)+o,top:n}}function an(t,s,a,r){const o=nl(t.width,a.width,s.column),n=xr(r/o),i=n*a.height+ka(0,n-1)*s.row;return i>0?i+s.row:i}const _u=Ke(()=>{const t=Z(p=>`Item ${p}`),s=Z({}),a=Z(null),r=Z("virtuoso-grid-item"),o=Z("virtuoso-grid-list"),n=Z(vn),i=Z("div"),l=Z(ma),c=(p,h=null)=>Rt(K(s,xe(b=>b[p]),st()),h),d=Z(!1),m=Z(!1);return ge(Se(m),d),{components:s,computeItemKey:n,context:a,FooterComponent:c("Footer"),HeaderComponent:c("Header"),headerFooterTag:i,itemClassName:r,ItemComponent:c("Item","div"),itemContent:t,listClassName:o,ListComponent:c("List","div"),readyStateChanged:d,reportReadyState:m,ScrollerComponent:c("Scroller","div"),scrollerRef:l,ScrollSeekPlaceholder:c("ScrollSeekPlaceholder","div")}}),Eu=Ke(([t,s])=>({...t,...s}),at(Tu,_u)),Ru=he.memo(function(){const t=tt("gridState"),s=tt("listClassName"),a=tt("itemClassName"),r=tt("itemContent"),o=tt("computeItemKey"),n=tt("isSeeking"),i=Yt("scrollHeight"),l=tt("ItemComponent"),c=tt("ListComponent"),d=tt("ScrollSeekPlaceholder"),m=tt("context"),p=Yt("itemDimensions"),h=Yt("gap"),b=tt("log"),S=tt("stateRestoreInProgress"),k=Yt("reportReadyState"),N=Ys(he.useMemo(()=>v=>{const g=v.parentElement.parentElement.scrollHeight;i(g);const I=v.firstChild;if(I!==null){const{height:z,width:R}=I.getBoundingClientRect();p({height:z,width:R})}h({column:So("column-gap",getComputedStyle(v).columnGap,b),row:So("row-gap",getComputedStyle(v).rowGap,b)})},[i,p,h,b]),!0,!1);return Zi(()=>{t.itemHeight>0&&t.itemWidth>0&&k(!0)},[t]),S?null:e.jsx(c,{className:s,ref:N,..._t(c,m),"data-testid":"virtuoso-item-list",style:{paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},children:t.items.map(v=>{const g=o(v.index,v.data,m);return n?e.jsx(d,{..._t(d,m),height:t.itemHeight,index:v.index,width:t.itemWidth},g):u.createElement(l,{..._t(l,m),className:a,"data-index":v.index,key:g},r(v.index,v.data,m))})})}),Mu=he.memo(function(){const t=tt("HeaderComponent"),s=Yt("headerHeight"),a=tt("headerFooterTag"),r=Ys(he.useMemo(()=>n=>{s(Ds(n,"height"))},[s]),!0,!1),o=tt("context");return t!=null?e.jsx(a,{ref:r,children:e.jsx(t,{..._t(t,o)})}):null}),Au=he.memo(function(){const t=tt("FooterComponent"),s=Yt("footerHeight"),a=tt("headerFooterTag"),r=Ys(he.useMemo(()=>n=>{s(Ds(n,"height"))},[s]),!0,!1),o=tt("context");return t!=null?e.jsx(a,{ref:r,children:e.jsx(t,{..._t(t,o)})}):null}),Lu=({children:t})=>{const s=he.useContext(Ji),a=Yt("itemDimensions"),r=Yt("viewportDimensions"),o=Ys(he.useMemo(()=>n=>{r(n.getBoundingClientRect())},[r]),!0,!1);return he.useEffect(()=>{s&&(r({height:s.viewportHeight,width:s.viewportWidth}),a({height:s.itemHeight,width:s.itemWidth}))},[s,r,a]),e.jsx("div",{ref:o,style:wn(!1),children:t})},zu=({children:t})=>{const s=he.useContext(Ji),a=Yt("windowViewportRect"),r=Yt("itemDimensions"),o=tt("customScrollParent"),n=tt("useWindowScroll"),i=Ei(a,o,!1);return he.useEffect(()=>{s&&(r({height:s.itemHeight,width:s.itemWidth}),a({listHeight:0,offsetTop:0,visibleHeight:s.viewportHeight,visibleWidth:s.viewportWidth}))},[s,a,r]),e.jsx("div",{ref:i,style:sl(!1,n),children:t})},Du=he.memo(function({...t}){const s=tt("useWindowScroll"),a=tt("customScrollParent"),r=a||s?Fu:$u,o=a||s?zu:Lu,n=tt("context");return e.jsx(r,{...t,..._t(r,n),children:e.jsxs(o,{children:[e.jsx(Mu,{}),e.jsx(Ru,{}),e.jsx(Au,{})]})})}),{useEmitter:ol,useEmitterValue:tt,usePublisher:Yt}=Ki(Eu,{optional:{context:"context",totalCount:"totalCount",overscan:"overscan",itemContent:"itemContent",components:"components",computeItemKey:"computeItemKey",data:"data",initialItemCount:"initialItemCount",scrollSeekConfiguration:"scrollSeekConfiguration",headerFooterTag:"headerFooterTag",listClassName:"listClassName",itemClassName:"itemClassName",useWindowScroll:"useWindowScroll",customScrollParent:"customScrollParent",scrollerRef:"scrollerRef",logLevel:"logLevel",restoreStateFrom:"restoreStateFrom",initialTopMostItemIndex:"initialTopMostItemIndex",increaseViewportBy:"increaseViewportBy"},methods:{scrollTo:"scrollTo",scrollBy:"scrollBy",scrollToIndex:"scrollToIndex"},events:{isScrolling:"isScrolling",endReached:"endReached",startReached:"startReached",rangeChanged:"rangeChanged",atBottomStateChange:"atBottomStateChange",atTopStateChange:"atTopStateChange",stateChanged:"stateChanged",readyStateChanged:"readyStateChanged"}},Du),$u=al({useEmitter:ol,useEmitterValue:tt,usePublisher:Yt}),Fu=rl({useEmitter:ol,useEmitterValue:tt,usePublisher:Yt});function So(t,s,a){return s!=="normal"&&s?.endsWith("px")!==!0&&a(`${t} was not resolved to pixel value correctly`,s,vt.WARN),s==="normal"?0:parseInt(s??"0",10)}function ko(t){if(Array.isArray(t)){if(t.length<5||t.length>6)throw new Error(`Invalid bone format: expected [x,y,w,h,r,c?] but got ${t.length} elements`);const s=t;return{x:s[0],y:s[1],w:s[2],h:s[3],r:s[4],c:s[5]||void 0}}return t}const Co=new Set(["p","h1","h2","h3","h4","h5","h6","li","td","th"]);function Ou(t,s="component",a){const r=t.getBoundingClientRect(),o=[],n=a?.leafTags?new Set([...Co,...a.leafTags]):Co,i=a?.captureRoundedBorders??!0,l=a?.excludeTags?new Set(a.excludeTags):null,c=a?.excludeSelectors??null;function d(m){const p=getComputedStyle(m);if(p.display==="none"||p.visibility==="hidden"||p.opacity==="0")return;const h=m.tagName.toLowerCase();if(l?.has(h)||c?.some(w=>m.matches(w)))return;const b=[...m.children].filter(w=>{const $=getComputedStyle(w);return $.display!=="none"&&$.visibility!=="hidden"&&$.opacity!=="0"}),S=h==="img"||h==="svg"||h==="video"||h==="canvas",k=h==="input"||h==="button"||h==="textarea"||h==="select",N=b.length===0||S||k||n.has(h),v=p.backgroundColor,g=v!=="rgba(0, 0, 0, 0)"&&v!=="transparent",I=p.backgroundImage!=="none",z=parseFloat(p.borderTopWidth)||0,R=i&&z>0&&p.borderTopColor!=="rgba(0, 0, 0, 0)"&&p.borderTopColor!=="transparent",W=(parseFloat(p.borderTopLeftRadius)||0)>0,f=g||I||R&&W,C=h==="tr"||h==="td"||h==="th"||h==="thead"||h==="tbody"||h==="table";if(N){const w=m.getBoundingClientRect();if(w.width<1||w.height<1)return;const $=S&&w.width>0&&w.height>0&&Math.abs(w.width-w.height)<4,A=C?0:$?"50%":Io(p,m)??8,y=r.width;o.push({x:y>0?+((w.left-r.left)/y*100).toFixed(4):0,y:Math.round(w.top-r.top),w:y>0?+(w.width/y*100).toFixed(4):0,h:Math.round(w.height),r:A});return}if(f){const w=m.getBoundingClientRect();if(w.width>=1&&w.height>=1){const $=C?0:Io(p,m)??8,A=r.width;o.push({x:A>0?+((w.left-r.left)/A*100).toFixed(4):0,y:Math.round(w.top-r.top),w:A>0?+(w.width/A*100).toFixed(4):0,h:Math.round(w.height),r:$,c:!0})}}for(const w of b)d(w)}for(const m of t.children)d(m);return{name:s,viewportWidth:Math.round(r.width),width:Math.round(r.width),height:Math.round(r.height),bones:o}}function Io(t,s){const a=parseFloat(t.borderTopLeftRadius)||0,r=parseFloat(t.borderTopRightRadius)||0,o=parseFloat(t.borderBottomRightRadius)||0,n=parseFloat(t.borderBottomLeftRadius)||0;if(a===0&&r===0&&o===0&&n===0)return;const i=s?(()=>{const d=s.getBoundingClientRect();return d.width>0&&d.height>0&&Math.abs(d.width-d.height)<4})():!1;return t.borderRadius==="50%"?"50%":Math.max(a,r,o,n)>9998?i?"50%":9999:a===r&&r===o&&o===n?a!==8?a:void 0:`${a}px ${r}px ${o}px ${n}px`}const Pu=new Map;function Bu(t){return Pu.get(t)}function Hu(){typeof window<"u"&&window.__BONEYARD_BUILD&&(window.__BONEYARD_SNAPSHOT=Ou)}function Uu(){return typeof window<"u"&&window.__BONEYARD_BUILD===!0}function Gu(t,s){if(!("breakpoints"in t))return t;const a=Object.keys(t.breakpoints).map(Number).sort((o,n)=>o-n);if(a.length===0)return null;const r=[...a].reverse().find(o=>s>=o)??a[0];return t.breakpoints[r]??null}const ea={angle:110,start:30,end:70,speed:"2s",lightHighlight:"#f7f7f7",darkHighlight:"#2c2c2c"},ba={speed:"1.8s",lightAdjust:.3,darkAdjust:.02},To={web:{light:"#f0f0f0",dark:"#222222"}},Qu=/rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*(?:,\s*([\d.]+))?\s*\)/;function _o(t,s){const a=t.match(Qu);if(a){const[,r,o,n,i="1"]=a,l=Math.min(1,parseFloat(i)+s*.5);return`rgba(${r},${o},${n},${l.toFixed(3)})`}if(t.startsWith("#")&&t.length>=7){const r=parseInt(t.slice(1,3),16),o=parseInt(t.slice(3,5),16),n=parseInt(t.slice(5,7),16);if(!isNaN(r)&&!isNaN(o)&&!isNaN(n)){const i=Math.round(r+(255-r)*s),l=Math.round(o+(255-o)*s),c=Math.round(n+(255-n)*s);return`#${i.toString(16).padStart(2,"0")}${l.toString(16).padStart(2,"0")}${c.toString(16).padStart(2,"0")}`}}return t}Hu();let is={};function Eo({loading:t,children:s,name:a,initialBones:r,color:o,darkColor:n,animate:i,stagger:l=!1,transition:c=!1,boneClass:d,className:m,fallback:p,fixture:h,snapshotConfig:b}){const S=u.useRef(null),k=u.useRef(Math.random().toString(36).slice(2,8)).current,[N,v]=u.useState(0),[g,I]=u.useState(0),[z,R]=u.useState(!1);u.useEffect(()=>{if(typeof window>"u")return;const E=()=>{const pe=document.documentElement.classList.contains("dark")||!!S.current?.closest(".dark");R(pe)};E();const Y=new MutationObserver(E);Y.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]});const V=window.matchMedia("(prefers-color-scheme: dark)");return V.addEventListener("change",E),()=>{Y.disconnect(),V.removeEventListener("change",E)}},[]);const W=o??is.color??To.web.light,f=n??is.darkColor??To.web.dark,C=z?f:W,w=i??is.animate??"pulse",$=w===!0?"pulse":w===!1?"solid":w;u.useEffect(()=>{const E=S.current;if(!E)return;const Y=new ResizeObserver(pe=>{const D=pe[0]?.contentRect;v(Math.round(D?.width??0)),D&&D.height>0&&I(Math.round(D.height))});Y.observe(E);const V=E.getBoundingClientRect();return v(Math.round(V.width)),V.height>0&&I(Math.round(V.height)),()=>Y.disconnect()},[]);const A={};if(a&&(A["data-boneyard"]=a,b&&(A["data-boneyard-config"]=JSON.stringify(b))),Uu())return e.jsx("div",{ref:S,className:m,style:{position:"relative"},...A,children:e.jsx("div",{children:h??s})});const[y,q]=u.useState(!1);u.useLayoutEffect(()=>{q(!0)},[]);const J=r??(a?Bu(a):void 0),re=y&&typeof window<"u"?window.innerWidth:0,le=N>0?N:re,ne=J&&le>0?Gu(J,le):null,be=d??is.boneClass,Ie=(()=>{const E=l??is.stagger;return E===!0?80:E===!1||!E?0:E})(),de=(()=>{const E=c??is.transition;return E===!0?300:E===!1||!E?0:E})(),[fe,H]=u.useState(!1),ee=u.useRef(t),oe=u.useRef(null);u.useEffect(()=>(ee.current&&!t&&de>0&&ne&&(oe.current&&clearTimeout(oe.current),H(!0),oe.current=setTimeout(()=>{H(!1),oe.current=null},de)),ee.current=t,()=>{oe.current&&clearTimeout(oe.current)}),[t,de,ne]);const Re=(t||fe)&&ne,Fe=t&&!ne&&!fe,Pe=g>0?g:ne?.height??0,G=ne?.height??0,te=Pe>0&&G>0?Pe/G:1;return e.jsxs("div",{ref:S,className:m,style:{position:"relative"},...A,children:[e.jsx("div",{"data-boneyard-content":"true",style:Re&&!fe?{visibility:"hidden"}:void 0,children:Fe?p:s}),Re&&e.jsx("div",{"data-boneyard-overlay":"true",style:{position:"absolute",inset:0,overflow:"hidden",opacity:fe?0:1,transition:de>0?`opacity ${de}ms ease-out`:void 0},children:e.jsxs("div",{style:{position:"relative",width:"100%",height:"100%"},children:[ne.bones.filter(E=>!ko(E).c).map((E,Y)=>{const V=ko(E),pe=C;_o(C,z?ba.darkAdjust:ba.lightAdjust);const D=V.w/100*(ne.width??0),j=V.r==="50%"&&Math.abs(D-V.h)<4,_={position:"absolute",left:`${V.x}%`,top:V.y*te,width:j?V.h*te:`${V.w}%`,height:V.h*te,borderRadius:typeof V.r=="string"?V.r:`${V.r}px`,backgroundColor:pe},T=is.speed;if($==="pulse")_.animation=`bp-${k} ${T??ba.speed} ease-in-out infinite`;else if($==="shimmer"){const Q=z?is.darkShimmerColor??ea.darkHighlight:is.shimmerColor??ea.lightHighlight,ue=is.shimmerAngle??ea.angle;delete _.backgroundColor,_.backgroundImage=`linear-gradient(${ue}deg, ${pe} ${ea.start}%, ${Q} 50%, ${pe} ${ea.end}%)`,_.backgroundSize="200% 100%",_.animation=`bs-${k} ${T??ea.speed} linear infinite`}return Ie>0&&(_.opacity=0,_.animation=`${_.animation?_.animation+",":""} by-${k} 0.3s ease-out ${Y*Ie}ms forwards`),e.jsx("div",{"data-boneyard-bone":"true",className:be,style:_},Y)}),$==="pulse"&&e.jsx("style",{children:`@keyframes bp-${k}{0%,100%{background-color:${C}}50%{background-color:${_o(C,z?ba.darkAdjust:ba.lightAdjust)}}}`}),$==="shimmer"&&e.jsx("style",{children:`@keyframes bs-${k}{0%{background-position:200% 0}100%{background-position:-200% 0}}`}),Ie>0&&e.jsx("style",{children:`@keyframes by-${k}{from{opacity:0}to{opacity:1}}`})]})})]})}async function jn(t){const s=Mt(He,"managedStudents");try{const n=At(s,Et("teacherId","==",t)),i=await Ot(n);if(!i.empty)return i.docs.map(c=>({id:c.id,...c.data()})).sort((c,d)=>String(c.name||"").localeCompare(String(d.name||"")))}catch{}const r=(await ll(t)).map(n=>n.id);if(r.length===0)return[];const o=new Map;for(let n=0;n{o.set(d.id,{id:d.id,...d.data()})})}return Array.from(o.values()).sort((n,i)=>String(n.name||"").localeCompare(String(i.name||"")))}async function Vu(t,s=[]){if(!t)return[];const a=Mt(He,"users"),r=new Map,o=(i,l)=>String(l.role||"").toLowerCase()!=="student"?null:{uid:i,name:String(l.name||l.displayName||"").trim()||"Student",email:String(l.email||"").trim(),lrn:l.lrn&&String(l.lrn).trim()||void 0,photo:l.photo?String(l.photo).trim()||void 0:l.photoURL&&String(l.photoURL).trim()||void 0,grade:l.grade&&String(l.grade).trim()||void 0,section:l.section&&String(l.section).trim()||void 0,classSectionId:l.classSectionId&&String(l.classSectionId).trim()||void 0,adviserTeacherId:l.adviserTeacherId&&String(l.adviserTeacherId).trim()||void 0,role:"student",createdAt:l.createdAt||void 0};try{const i=At(a,Et("role","==","student"),Et("adviserTeacherId","==",t));(await Ot(i)).docs.forEach(c=>{const d=o(c.id,c.data());d&&r.set(c.id,d)})}catch(i){console.warn("[studentService] adviser-scoped student query failed:",i)}const n=Array.from(new Set((s||[]).map(i=>(i||"").trim()).filter(i=>!!i)));for(let i=0;i{if(r.has(m.id))return;const p=o(m.id,m.data());p&&r.set(m.id,p)})}catch(c){console.warn("[studentService] section-scoped student query failed:",c)}}return Array.from(r.values()).sort((i,l)=>i.name.localeCompare(l.name))}function Wu(t){const s=`https://ui-avatars.com/api/?name=${encodeURIComponent(t.name||"Student")}&background=random`,a=Xl.now();return{id:t.uid,accountUid:t.uid,lrn:t.lrn,name:t.name,email:t.email,avatar:t.photo||s,teacherId:t.adviserTeacherId,grade:t.grade,gradeLevel:gs(t.grade)||void 0,section:t.section,classSectionId:t.classSectionId,riskLevel:"Low",engagementScore:0,avgQuizScore:0,weakestTopic:"N/A",classroomId:t.classSectionId||"",attendance:0,assignmentCompletion:0,lastActive:null,struggles:[],createdAt:t.createdAt||a,updatedAt:a,hasRegisteredAccount:!0,source:"registered"}}function Ro(t){return(t||"").normalize("NFD").replace(/[\u0300-\u036f]/g,"").toLowerCase().replace(/[^a-z0-9\s]+/g," ").trim().replace(/\s+/g," ")}async function qu(t){const s=(t.studentId||"").trim();if(!s)throw new Error("Cannot reassign section: studentId is required.");const a=(t.newClassSectionId||"").trim()||Ft(t.newGrade,t.newSection);if(!a)throw new Error("Cannot reassign section: a target class section is required.");const r=(t.teacherId||"").trim(),o=(t.teacherName||"").trim(),n=(t.schoolYear||"").trim(),i=(t.previousClassSectionId||"").trim();try{const l=pt(He,"managedStudents",s),c=await ks(l);c.exists()&&await es(l,{grade:t.newGrade,section:t.newSection,classSectionId:a,gradeLevel:gs(t.newGrade)||t.newGrade,teacherId:r||c.data()?.teacherId,updatedAt:it()})}catch(l){console.warn("[studentService] reassignStudentSection: managedStudents update failed:",l)}if(t.isRegisteredAccount)try{await ts(pt(He,"users",s),{grade:t.newGrade,section:t.newSection,classSectionId:a,adviserTeacherId:r||void 0,adviserTeacherName:o||void 0,updatedAt:it()},{merge:!0})}catch(l){console.warn("[studentService] reassignStudentSection: users profile update failed:",l)}try{await jr({classSectionId:a,grade:t.newGrade,section:t.newSection,schoolYear:n,ownerTeacherId:r,ownerTeacherName:o,studentUids:[s]})}catch(l){console.warn("[studentService] reassignStudentSection: ownership upsert failed:",l)}if(i&&i!==a)try{const l=pt(He,"classSectionOwnership",i),c=await ks(l);if(c.exists()){const m=(c.data().studentUids||[]).filter(p=>p!==s);await es(l,{studentUids:m,updatedAt:it()})}}catch(l){console.warn("[studentService] reassignStudentSection: previous-section cleanup failed:",l)}}async function Yu(t){const{apiService:s}=await Ss(async()=>{const{apiService:d}=await import("./index-BufUS6SI.js").then(m=>m.b8);return{apiService:d}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11])),a=(t.adviserTeacherId||"").trim();if(!a)throw new Error("createStudentAccountFromRoster requires adviserTeacherId.");const r=(t.email||"").trim().toLowerCase();if(!r)throw new Error("createStudentAccountFromRoster requires an email.");const o=(t.grade||"").trim(),n=(t.section||"").trim(),i=(t.classSectionId||"").trim()||(o&&n?Ft(o,n):""),c=((await s.createStudentAccount({name:(t.name||"").trim()||"Student",email:r,temporaryPassword:t.temporaryPassword,lrn:t.lrn?.trim()||void 0,grade:o||void 0,section:n||void 0,classSectionId:i||void 0,adviserTeacherId:a,adviserTeacherName:t.adviserTeacherName?.trim()||void 0,schoolYear:t.schoolYear?.trim()||void 0})).uid||"").trim();if(!c)throw new Error("Backend did not return a uid for the newly created student.");try{await ts(pt(He,"managedStudents",c),pr({accountUid:c,name:(t.name||"").trim()||"Student",email:r,lrn:t.lrn?.trim()||null,teacherId:a,grade:o||null,gradeLevel:gs(o)||null,section:n||null,classSectionId:i||null,classroomId:i||null,riskLevel:"Low",avgQuizScore:0,engagementScore:0,attendance:0,assignmentCompletion:0,weakestTopic:"",struggles:[],avatar:`https://ui-avatars.com/api/?name=${encodeURIComponent(t.name||"Student")}&background=random`,hasRegisteredAccount:!0,source:"both",createdAt:it(),updatedAt:it()}))}catch(d){console.warn("[studentService] createStudentAccountFromRoster: managed-student merge failed:",d)}if(i&&o&&n)try{await jr({classSectionId:i,grade:o,section:n,schoolYear:t.schoolYear||"",ownerTeacherId:a,ownerTeacherName:t.adviserTeacherName,studentUids:[c]})}catch(d){console.warn("[studentService] createStudentAccountFromRoster: ownership upsert failed:",d)}return{uid:c,email:r,temporaryPassword:t.temporaryPassword}}async function il(t,s,a){const r=Ft(s,a),o=pt(He,"managedStudents",t);await es(o,{grade:s,section:a,classSectionId:r,updatedAt:it()})}async function Ku(t,s){const a=pt(He,"classSectionOwnership",s);await es(a,{studentUids:Kl(t),updatedAt:it()}).catch(r=>console.warn("[studentService] removeStudentFromClass: ownership update failed:",r)),await hi(pt(He,"managedStudents",t)).catch(r=>console.warn("[studentService] removeStudentFromClass: managedStudents delete failed:",r))}function Ft(t,s){return[t,s].filter(Boolean).join("_").replace(/\s+/g,"_").toLowerCase()}function pr(t){const s=Object.entries(t).filter(([,a])=>a!==void 0);return Object.fromEntries(s)}function gs(t){const s=(t||"").trim();if(!s)return null;const a=s.match(/(\d{1,2})/);return a?`Grade ${a[1]}`:/^grade\s+/i.test(s)?s.replace(/\s+/g," ").trim().replace(/^grade/i,"Grade"):s}function xa(t){const a=gs(t)?.match(/(\d{1,2})/),r=a?Number.parseInt(a[1],10):Number.NaN;return Number.isFinite(r)?r>=11?"Senior High School":"Junior High School":null}function pa(t,s){const a=`${t||""} ${s||""}`.toUpperCase();if(!a.trim())return null;const r=["STEM","ABM","HUMSS","GAS","TVL","ICT"];for(const o of r)if(new RegExp(`\\b${o}\\b`).test(a))return o;return null}function xs(t){const s=(t||"").trim();if(!s)return{grade:"Grade 11",section:"Section A"};const[a="Grade 11",r="Section A"]=s.split(" - ").map(o=>o.trim());return{grade:a||"Grade 11",section:r||"Section A"}}function Ct(t){const s=t.metadata||{},a=t.className||s.className,r=xs(a),o=(t.grade||s.grade||r.grade||"").trim()||null,n=(t.section||s.section||r.section||"").trim()||null,i=(t.classSectionId||s.classSectionId||"").trim()||(o&&n?Ft(o,n):"")||null,l=(a||"").trim()||(o&&n?`${o} - ${n}`:"")||null,c=gs(t.gradeLevel||s.gradeLevel||o),d=(t.classification||s.classification||"").trim()||xa(c)||null,m=(t.strand||s.strand||"").trim()||pa(l,n)||null;return{classSectionId:i,className:l,grade:o,section:n,gradeLevel:c,classification:d,strand:m,schoolYear:(t.schoolYear||s.schoolYear||"").trim()||null,ownerTeacherId:(t.ownerTeacherId||s.ownerTeacherId||"").trim()||null,ownerTeacherName:(t.ownerTeacherName||s.ownerTeacherName||"").trim()||null,adviserTeacherId:(t.adviserTeacherId||s.adviserTeacherId||"").trim()||null,adviserTeacherName:(t.adviserTeacherName||s.adviserTeacherName||"").trim()||null,managerId:(t.managerId||s.managerId||"").trim()||null,managerName:(t.managerName||s.managerName||"").trim()||null}}function Xu(t){const s=(t.className||"").trim(),[a="",r=""]=s.split(" - "),o=(t.grade||a||"").trim()||null,n=(t.section||r||"").trim()||null,i=(t.classSectionId||"").trim()||(o&&n?Ft(o,n):"")||null,l=s||(o&&n?`${o} - ${n}`:null),c=gs(t.gradeLevel||o),d=(t.classification||"").trim()||xa(c),m=(t.strand||"").trim()||pa(l,n);return{classSectionId:i,className:l,grade:o,section:n,gradeLevel:c,classification:d,strand:m,schoolYear:(t.schoolYear||"").trim()||null,ownerTeacherId:(t.ownerTeacherId||"").trim()||null,ownerTeacherName:(t.ownerTeacherName||"").trim()||null,adviserTeacherId:(t.adviserTeacherId||"").trim()||null,adviserTeacherName:(t.adviserTeacherName||"").trim()||null,managerId:(t.managerId||"").trim()||null,managerName:(t.managerName||"").trim()||null}}async function ll(t){const s=Mt(He,"classrooms"),a=new Map,r=At(s,Et("teacherId","==",t));(await Ot(r)).docs.forEach(l=>{a.set(l.id,{id:l.id,...l.data()})});const n=At(s,Et("managerId","==",t));return(await Ot(n)).docs.forEach(l=>{a.set(l.id,{id:l.id,...l.data()})}),Array.from(a.values()).sort((l,c)=>String(l.name||"").localeCompare(String(c.name||"")))}async function jr(t){const s=t.classSectionId||Ft(t.grade,t.section),a=pt(He,"classSectionOwnership",s),r=await ks(a),o=r.exists()?r.data().studentUids||[]:[],n=Array.from(new Set([...t.studentUids||[],...o])),i=pr(t);return r.exists()?await es(a,{...i,classSectionId:s,studentUids:n,updatedAt:it()}):await ts(a,{...i,classSectionId:s,studentUids:n,createdAt:it(),updatedAt:it()}),s}async function cl(t){const s=(t.classSectionId||"").trim()||Ft(t.grade,t.section),a=(t.className||"").trim()||`${t.grade} - ${t.section}`,r=Xu({classSectionId:s,className:a,grade:t.grade,section:t.section,schoolYear:t.schoolYear,ownerTeacherId:t.ownerTeacherId,ownerTeacherName:t.ownerTeacherName,adviserTeacherId:t.ownerTeacherId,adviserTeacherName:t.ownerTeacherName,managerId:t.managerId,managerName:t.managerName,classification:t.classification,strand:t.strand,gradeLevel:t.gradeLevel});await jr({classSectionId:s,className:a,grade:r.grade||t.grade,gradeLevel:r.gradeLevel||t.gradeLevel||t.grade,classification:r.classification||t.classification,strand:r.strand||t.strand,section:r.section||t.section,schoolYear:t.schoolYear,ownerTeacherId:t.ownerTeacherId,ownerTeacherName:t.ownerTeacherName,managerId:t.managerId,managerName:t.managerName,studentUids:[]});const o=Mt(He,"classrooms"),n=At(o,Et("classSectionId","==",s)),i=await Ot(n);if(i.empty){const l=pr({name:a,teacherId:t.ownerTeacherId,grade:r.grade,gradeLevel:r.gradeLevel,classification:r.classification,strand:r.strand,section:r.section,classSectionId:s,schoolYear:t.schoolYear,ownerTeacherId:t.ownerTeacherId,ownerTeacherName:t.ownerTeacherName||"",adviserTeacherId:t.ownerTeacherId,adviserTeacherName:t.ownerTeacherName||"",managerId:t.managerId,managerName:t.managerName||"",classMetadata:r,schedule:"Mon-Fri",studentCount:0,avgScore:0,atRiskCount:0,createdAt:it(),updatedAt:it()});await ts(pt(He,"classrooms",s),l,{merge:!0})}else for(const l of i.docs){const c=pr({name:a,grade:r.grade,gradeLevel:r.gradeLevel,classification:r.classification,strand:r.strand,section:r.section,schoolYear:t.schoolYear,ownerTeacherId:t.ownerTeacherId,ownerTeacherName:t.ownerTeacherName||"",adviserTeacherId:t.ownerTeacherId,adviserTeacherName:t.ownerTeacherName||"",managerId:t.managerId,managerName:t.managerName||"",classMetadata:r,updatedAt:it()});await es(l.ref,c)}return s}async function yr(t,s,a,r,o,n){const i=Ft(s,a);await jr({classSectionId:i,grade:s,section:a,schoolYear:o,ownerTeacherId:r,ownerTeacherName:n,studentUids:[t]});const l=await ks(pt(He,"users",t)),c=l.exists()?l.data():{};await ts(pt(He,"users",t),{grade:s,section:a,classSectionId:i,adviserTeacherId:r,adviserTeacherName:n||"",updatedAt:it()},{merge:!0}),await ts(pt(He,"managedStudents",t),{accountUid:t,name:c.name||c.displayName||"Student",email:c.email||"",lrn:c.lrn||null,teacherId:r,grade:s,gradeLevel:s,section:a,classSectionId:i,classroomId:i,hasRegisteredAccount:!0,source:"registered",updatedAt:it()},{merge:!0})}async function Ju(t){const s=Mt(He,"classSectionOwnership"),a=new Map,r=At(s,Et("ownerTeacherId","==",t));(await Ot(r)).docs.forEach(l=>{a.set(l.id,{id:l.id,...l.data()})});const n=At(s,Et("managerId","==",t));return(await Ot(n)).docs.forEach(l=>{a.set(l.id,{id:l.id,...l.data()})}),Array.from(a.values()).sort((l,c)=>String(l.classSectionId||"").localeCompare(String(c.classSectionId||"")))}async function Zu(t="",s=25){const a=Mt(He,"users"),r=Math.max(1,Math.min(100,s)),o=At(a,Et("role","==","teacher"),or(r*4)),n=await Ot(o),i=t.trim().toLowerCase();return n.docs.map(c=>{const d=c.data(),m=String(d.name||"").trim(),p=String(d.email||"").trim();return{uid:c.id,name:m||"Teacher",email:p,photo:String(d.photo||d.photoURL||"").trim()||void 0}}).filter(c=>i?c.name.toLowerCase().includes(i)||c.email.toLowerCase().includes(i):!0).sort((c,d)=>c.name.localeCompare(d.name)).slice(0,r)}function em(t,s,a=20){if(t.length===0)return s([]),()=>{};const r=Mt(He,"activities"),o=At(r,Et("classroomId","in",t),Jl("timestamp","desc"));return fi(o,n=>{const i=n.docs.slice(0,a).map(l=>({id:l.id,...l.data()}));s(i)},n=>{console.error("[studentService] subscribeToActivities error:",n),s([])})}const tm=({open:t,onClose:s,onCreated:a,teacherName:r})=>{const{currentUser:o}=hs(),[n,i]=u.useState("details"),[l,c]=u.useState(""),d="Grade 11",[m,p]=u.useState(""),[h,b]=u.useState(!1),[S,k]=u.useState(""),[N,v]=u.useState([]),[g,I]=u.useState(new Set),[z,R]=u.useState(""),[W,f]=u.useState(!1);u.useEffect(()=>{t||(i("details"),c(""),p(""),k(""),I(new Set),R(""))},[t]),u.useEffect(()=>{t&&n==="students"&&C()},[t,n]);const C=async()=>{f(!0);try{const y=Mt(He,"users"),q=At(y,Et("role","==","student")),J=await Ot(q),re=[];J.docs.forEach(le=>{const ne=le.data();re.push({uid:le.id,name:ne.name||ne.displayName||"Student",email:ne.email||"",grade:ne.grade,section:ne.section})}),v(re.sort((le,ne)=>le.name.localeCompare(ne.name)))}catch(y){console.error("[CreateClassModal] Failed to load students:",y)}finally{f(!1)}},w=async()=>{if(o){if(!m.trim()){k("Section name is required");return}k(""),b(!0);try{const y=String(new Date().getFullYear());if(await cl({classSectionId:"",grade:d,section:m.trim(),schoolYear:y,ownerTeacherId:o.uid,ownerTeacherName:r||o.displayName||"",managerId:o.uid,managerName:r||o.displayName||"",className:l.trim()||`${d} - ${m.trim()}`}),g.size>0){const q=Array.from(g).map(J=>yr(J,d,m.trim(),o.uid,y,r||o.displayName||""));await Promise.allSettled(q)}a(),s()}catch(y){k(y instanceof Error?y.message:"Failed to create class")}finally{b(!1)}}},$=y=>{I(q=>{const J=new Set(q);return J.has(y)?J.delete(y):J.add(y),J})},A=N.filter(y=>y.name.toLowerCase().includes(z.toLowerCase())||y.email.toLowerCase().includes(z.toLowerCase()));return t?e.jsx(zt,{children:e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[e.jsx(Le.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"absolute inset-0 bg-black/40 backdrop-blur-sm",onClick:s}),e.jsxs(Le.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.95},className:"relative bg-white rounded-2xl shadow-xl w-full max-w-lg mx-4 max-h-[80vh] flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-[#f1f5f9]",children:[e.jsx("h2",{className:"text-lg font-semibold text-[#1e293b]",children:n==="details"?"Create New Class":"Add Students"}),e.jsx("button",{onClick:s,className:"p-1 rounded-lg hover:bg-[#f1f5f9] transition-colors",children:e.jsx(Xt,{size:20,className:"text-[#64748b]"})})]}),e.jsxs("div",{className:"p-6 overflow-y-auto flex-1",children:[n==="details"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-[#475569] block mb-1.5",children:"Class Name"}),e.jsx(Is,{placeholder:"e.g. Grade 11 - Section A",value:l,onChange:y=>c(y.target.value)}),e.jsx("p",{className:"text-xs text-[#94a3b8] mt-1",children:"Optional. Auto-generated from grade + section if empty."})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-[#475569] block mb-1.5",children:"Section"}),e.jsx(Is,{placeholder:"e.g. Section A, STEM-1, Rizal",value:m,onChange:y=>p(y.target.value)})]}),S&&e.jsx("p",{className:"text-sm text-rose-500",children:S})]}),n==="students"&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx(qs,{size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-[#94a3b8]"}),e.jsx(Is,{placeholder:"Search students...",value:z,onChange:y=>R(y.target.value),className:"pl-9"})]}),e.jsxs("p",{className:"text-xs text-[#64748b]",children:[g.size," student(s) selected"]}),W?e.jsx("p",{className:"text-sm text-[#64748b] text-center py-4",children:"Loading students..."}):A.length===0?e.jsx("p",{className:"text-sm text-[#64748b] text-center py-4",children:"No students found."}):e.jsx("div",{className:"space-y-1 max-h-[300px] overflow-y-auto",children:A.map(y=>e.jsxs("button",{onClick:()=>$(y.uid),className:`w-full flex items-center gap-3 px-3 py-2.5 rounded-lg text-left transition-colors ${g.has(y.uid)?"bg-purple-50 border border-purple-200":"hover:bg-[#f8fafc] border border-transparent"}`,children:[e.jsx("div",{className:`w-5 h-5 rounded-md border-2 flex items-center justify-center ${g.has(y.uid)?"bg-[#9956DE] border-[#9956DE]":"border-[#cbd5e1]"}`,children:g.has(y.uid)&&e.jsx(Ht,{size:12,className:"text-white"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-[#1e293b] truncate",children:y.name}),e.jsx("p",{className:"text-xs text-[#64748b] truncate",children:y.email})]}),y.grade&&e.jsx("span",{className:"text-xs text-[#94a3b8]",children:y.grade})]},y.uid))}),S&&e.jsx("p",{className:"text-sm text-rose-500",children:S})]})]}),e.jsx("div",{className:"flex items-center justify-between p-6 border-t border-[#f1f5f9]",children:n==="details"?e.jsxs(e.Fragment,{children:[e.jsx(St,{variant:"outline",onClick:s,children:"Cancel"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(St,{variant:"outline",onClick:()=>{if(!m.trim()){k("Section is required");return}k(""),i("students")},children:"Add Students"}),e.jsx(St,{onClick:w,disabled:h||!m.trim(),className:"bg-[#9956DE] hover:bg-[#7c3aed] text-white",children:h?"Creating...":"Create Class"})]})]}):e.jsxs(e.Fragment,{children:[e.jsx(St,{variant:"outline",onClick:()=>i("details"),children:"Back"}),e.jsxs(St,{onClick:w,disabled:h,className:"bg-[#9956DE] hover:bg-[#7c3aed] text-white",children:[e.jsx(da,{size:16,className:"mr-1"}),h?"Creating...":`Create with ${g.size} Student${g.size!==1?"s":""}`]})]})})]})]})}):null},sm=({open:t,onClose:s,onAdded:a,grade:r,section:o,teacherName:n,existingStudentUids:i=[]})=>{const{currentUser:l}=hs(),[c,d]=u.useState([]),[m,p]=u.useState(new Set),[h,b]=u.useState(""),[S,k]=u.useState(!1),[N,v]=u.useState(!1);u.useEffect(()=>{t&&(p(new Set),b(""),g())},[t]);const g=async()=>{k(!0);try{const R=At(Mt(He,"users"),Et("role","==","student")),f=(await Ot(R)).docs.filter(C=>!i.includes(C.id)).map(C=>{const w=C.data();return{uid:C.id,name:w.name||w.displayName||"Student",email:w.email||""}}).sort((C,w)=>C.name.localeCompare(w.name));d(f)}catch{}k(!1)},I=async()=>{if(!(!l||m.size===0)){v(!0);try{const R=String(new Date().getFullYear()),W=Array.from(m).map(f=>yr(f,r,o,l.uid,R,n||l.displayName||""));await Promise.allSettled(W),ie.success(`Added ${m.size} student(s) to class`),a(),s()}catch{ie.error("Failed to add students")}v(!1)}},z=c.filter(R=>R.name.toLowerCase().includes(h.toLowerCase())||R.email.toLowerCase().includes(h.toLowerCase()));return t?e.jsx(zt,{children:e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[e.jsx(Le.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"absolute inset-0 bg-black/40 backdrop-blur-sm",onClick:s}),e.jsxs(Le.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.95},className:"relative bg-white rounded-2xl shadow-xl w-full max-w-2xl mx-4 max-h-[80vh] flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between p-5 border-b border-[#f1f5f9]",children:[e.jsxs("h2",{className:"text-base font-semibold text-[#1e293b]",children:["Add Students to ",r," - ",o]}),e.jsx("button",{onClick:s,className:"p-1 rounded-lg hover:bg-[#f1f5f9]",children:e.jsx(Xt,{size:18,className:"text-[#64748b]"})})]}),e.jsxs("div",{className:"p-4 space-y-3 flex-1 overflow-hidden flex flex-col",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(qs,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-[#94a3b8]"}),e.jsx(Is,{placeholder:"Search students...",value:h,onChange:R=>b(R.target.value),className:"pl-8 h-9 text-sm"})]}),e.jsx("button",{onClick:()=>{m.size===z.length?p(new Set):p(new Set(z.map(R=>R.uid)))},className:"text-[11px] font-semibold text-[#9956DE] hover:text-[#7c3aed] bg-[#9956DE]/10 hover:bg-[#9956DE]/20 px-3 py-1.5 rounded-lg transition-colors whitespace-nowrap",children:m.size===z.length&&z.length>0?"Deselect All":"Select All"})]}),e.jsxs("p",{className:"text-xs text-[#64748b]",children:[m.size," of ",z.length," selected"]}),e.jsx("div",{className:"flex-1 overflow-y-auto space-y-1 min-h-[300px]",children:S?e.jsx("p",{className:"text-sm text-center text-[#64748b] py-6",children:"Loading..."}):z.length===0?e.jsx("p",{className:"text-sm text-center text-[#64748b] py-6",children:"No students available"}):z.map(R=>e.jsxs("button",{onClick:()=>p(W=>{const f=new Set(W);return f.has(R.uid)?f.delete(R.uid):f.add(R.uid),f}),className:`w-full flex items-center gap-3 px-3 py-2 rounded-lg text-left transition-colors ${m.has(R.uid)?"bg-purple-50 border border-purple-200":"hover:bg-[#f8fafc] border border-transparent"}`,children:[e.jsx("div",{className:`w-5 h-5 rounded-md border-2 flex items-center justify-center shrink-0 ${m.has(R.uid)?"bg-[#9956DE] border-[#9956DE]":"border-[#cbd5e1]"}`,children:m.has(R.uid)&&e.jsx(Ht,{size:12,className:"text-white"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-[#1e293b] truncate",children:R.name}),e.jsx("p",{className:"text-[11px] text-[#64748b] truncate",children:R.email})]})]},R.uid))})]}),e.jsxs("div",{className:"flex items-center justify-between p-4 border-t border-[#f1f5f9]",children:[e.jsx(St,{variant:"outline",size:"sm",onClick:s,children:"Cancel"}),e.jsxs(St,{size:"sm",onClick:I,disabled:N||m.size===0,className:"bg-[#9956DE] hover:bg-[#7c3aed] text-white",children:[e.jsx(ci,{size:14,className:"mr-1.5"}),N?"Adding...":`Add ${m.size} Student${m.size!==1?"s":""}`]})]})]})]})}):null},dl="https://deign86-mathpulse-api-v3test.hf.space";async function ul(){const t={"Content-Type":"application/json"},s=di.currentUser;if(s)try{const a=await s.getIdToken(!1);a&&(t.Authorization=`Bearer ${a}`)}catch{}return t}async function Mo(t,s=!1){const a=await ul(),r=`${dl}/api/analytics/class/${encodeURIComponent(t)}${s?"?refresh=true":""}`,o=await fetch(r,{headers:a});if(!o.ok)throw new Error(`GET class analytics failed: ${o.status}`);return o.json()}async function am(t){const s=await ul(),a=await fetch(`${dl}/api/analytics/class/${encodeURIComponent(t)}/refresh-insights`,{method:"POST",headers:s});if(!a.ok)throw a.status===429?new Error("Insights can only be refreshed once every 5 minutes."):new Error(`POST refresh insights failed: ${a.status}`);return a.json()}const Sr="https://deign86-mathpulse-api-v3test.hf.space";async function kr(){const t={"Content-Type":"application/json"},s=di.currentUser;if(s)try{const a=await s.getIdToken(!1);a&&(t.Authorization=`Bearer ${a}`)}catch{}return t}async function rn(t){const s=await kr(),a=await fetch(`${Sr}/api/intervention/${encodeURIComponent(t)}`,{headers:s});if(!a.ok)throw new Error(`GET intervention failed: ${a.status}`);return a.json()}async function ml(t){const s=await kr(),a=await fetch(`${Sr}/api/intervention/generate`,{method:"POST",headers:s,body:JSON.stringify({student_id:t})});if(!a.ok)throw new Error(`POST intervention/generate failed: ${a.status}`);return a.json()}async function rm(t,s,a,r){const o=await kr(),n=await fetch(`${Sr}/api/intervention/${encodeURIComponent(t)}/step/${s}/complete`,{method:"POST",headers:o,body:JSON.stringify({score:a,time_spent_minutes:r})});if(!n.ok)throw new Error(`POST step complete failed: ${n.status}`);return n.json()}async function nm(t){const s=await kr(),a=await fetch(`${Sr}/api/intervention/${encodeURIComponent(t)}/export-pdf`,{headers:s});if(!a.ok)throw new Error(`GET export-pdf failed: ${a.status}`);return a.json()}async function xl(t,s){const r=(t.learning_path?.steps||[]).map(n=>({title:`Step ${n.step_number}: ${n.title}`,content:`${n.description||n.topic} (${n.type.replace("_"," ")} · ${n.duration_minutes} mins${n.num_items?` · ${n.num_items} items`:""})`}));return(await gi(Mt(He,"modules"),{title:`Intervention: ${t.weakest_topic} — ${t.student_name}`,gradeLevel:t.grade_level||"Grade 11",subject:"General Mathematics",quarter:"Q1",strandOrTrack:null,competencyTags:t.weak_topics.slice(0,3),moduleType:"teacher_uploaded",sourceLabel:"Teacher Upload",summary:t.next_steps_summary||`Personalized intervention for ${t.weakest_topic}`,learningObjectives:[t.learning_strengths,t.next_steps_summary].filter(Boolean),sections:r,practice:[],teacherId:s,assignedTo:t.student_id,createdAt:it()})).id}async function pl(t,s,a){return(await gi(Mt(He,"modules"),{title:t.title,gradeLevel:"Grade 11",subject:"General Mathematics",quarter:"Q1",strandOrTrack:null,competencyTags:[t.competency_tag].filter(Boolean),moduleType:"teacher_uploaded",sourceLabel:"Teacher Upload",summary:t.description||`${t.topic} (${t.difficulty})`,learningObjectives:[t.description].filter(Boolean),sections:[{title:t.title,content:t.description||t.topic}],practice:[],teacherId:a,assignedTo:s,createdAt:it()})).id}const om=Object.freeze(Object.defineProperty({__proto__:null,assignLearningPathAsModule:xl,assignStepAsModule:pl,completeStep:rm,generateInterventionPlan:ml,getExportPDFData:nm,getInterventionPlan:rn},Symbol.toStringTag,{value:"Module"}));function im(t,s=!0){const[a,r]=u.useState([]),[o,n]=u.useState(!1),[i,l]=u.useState(null);return u.useEffect(()=>{if(!t||!s){r([]);return}let c=!1;return n(!0),l(null),nc(t).then(d=>{c||r(d)}).catch(d=>{c||l(d.message)}).finally(()=>{c||n(!1)}),()=>{c=!0}},[t,s]),{videos:a,isLoading:o,error:i}}const lm=({step:t,isActive:s})=>{const{videos:a,isLoading:r,error:o}=im(t.youtube_query||`${t.topic} math tutorial Philippines`,s);return s?e.jsxs("div",{className:"mt-4",children:[o&&e.jsxs("p",{className:"text-xs text-red-400 mb-2",children:["Could not load videos: ",o]}),e.jsx(oc,{videos:r?[]:a,topic:t.title})]}):null},hl={"gen-math":{id:"gen-math",name:"General Mathematics",shortLabel:"Gen Math",color:"#3B82F6"},"stats-prob":{id:"stats-prob",name:"Statistics and Probability",shortLabel:"Stats & Prob",color:"#0ea5e9"},"business-math":{id:"business-math",name:"Business Mathematics",shortLabel:"Business Math",color:"#166534"},"pre-calc":{id:"pre-calc",name:"Pre-Calculus",shortLabel:"Pre-Calculus",color:"#F97316"},"basic-calc":{id:"basic-calc",name:"Basic Calculus",shortLabel:"Basic Calculus",color:"#EF4444"}},cm={gm:"gen-math",gen_math:"gen-math","gen math":"gen-math",genmath:"gen-math","general mathematics":"gen-math",sp:"stats-prob",stat:"stats-prob","stat&prob":"stats-prob",statistics:"stats-prob","statistics and probability":"stats-prob",bm:"business-math","business math":"business-math","business mathematics":"business-math",pc:"pre-calc","pre-calculus":"pre-calc",pre_calc:"pre-calc",precalc:"pre-calc",bc:"basic-calc",basic_calc:"basic-calc","basic calculus":"basic-calc",basiccalc:"basic-calc"};function dm(t){const s=t.toLowerCase().trim();return hl[s]?s:cm[s]||null}function um(t){const s=dm(t);return s?hl[s].name:t}function ys(t){if(!t)return t;const s=t.match(/^(Gm|Gen\s*Math|Stat|Stats?(?:\s*&\s*Prob)?|Pre[- ]?Cal(?:c)?|Basic[- ]?Cal(?:c)?|Bm|Business\s*Math)\s*(Q\d)?\s*[-–]?\s*(.*)$/i);if(!s)return t;const[,a,r,o]=s,i=[um(a)];return r&&i.push(r.toUpperCase()),o?.trim()&&i.push(o.trim()),i.join(" – ")}const mm={video_lesson:e.jsx(Za,{className:"w-5 h-5"}),practice:e.jsx(ir,{className:"w-5 h-5"}),assessment:e.jsx(La,{className:"w-5 h-5"}),chat_session:e.jsx(Si,{className:"w-5 h-5"}),review:e.jsx(cs,{className:"w-5 h-5"})},Ao={easy:"bg-emerald-100 text-emerald-700",medium:"bg-amber-100 text-amber-700",hard:"bg-rose-100 text-rose-700"},xm=({step:t,studentId:s,studentName:a,teacherId:r,totalSteps:o,onClose:n,onStepCompleted:i})=>{const[l,c]=u.useState(!1),[d,m]=u.useState([{role:"assistant",content:`Hi ${a}! Let's work on "${ys(t.title)}". ${t.description||`This covers ${ys(t.topic)}.`} Ready to start?`}]),[p,h]=u.useState(""),b=async()=>{c(!0);try{await pl(t,s,r),i(t.step_number),ie.success(`Step ${t.step_number} assigned to student!`),n()}catch{ie.error("Failed to assign step.")}finally{c(!1)}},S=()=>{if(!p.trim())return;const k=p.trim();m(N=>[...N,{role:"user",content:k}]),h(""),setTimeout(()=>{m(N=>[...N,{role:"assistant",content:`Great question about ${t.topic}! Let me help you understand this step by step. What part are you finding most challenging?`}])},1e3)};return e.jsx(zt,{children:e.jsxs(Le.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-[9999] flex items-center justify-center p-4",onClick:n,children:[e.jsx("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm"}),e.jsxs(Le.div,{initial:{scale:.95,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.95,opacity:0},className:"relative bg-white rounded-[24px] shadow-[0_24px_64px_rgba(0,0,0,0.18)] w-full max-w-[800px] max-h-[85vh] flex flex-col overflow-hidden z-10",onClick:k=>k.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-slate-100 shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-[12px] bg-gradient-to-br from-indigo-500 to-purple-600 flex items-center justify-center text-white",children:mm[t.type]||e.jsx(ir,{className:"w-5 h-5"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-[15px] font-bold text-[#1e293b]",children:ys(t.title)}),e.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[e.jsxs("span",{className:"text-[11px] text-[#64748b]",children:["Step ",t.step_number," of ",o]}),t.competency_tag&&e.jsx("span",{className:"px-1.5 py-0.5 bg-indigo-50 text-indigo-600 text-[9px] font-mono rounded",children:t.competency_tag}),e.jsx("span",{className:`px-2 py-0.5 text-[10px] font-semibold rounded-full ${Ao[t.difficulty]||Ao.easy}`,children:t.difficulty})]})]})]}),e.jsx("button",{onClick:n,className:"w-8 h-8 rounded-full bg-slate-100 hover:bg-slate-200 flex items-center justify-center transition-colors",children:e.jsx(Xt,{className:"w-4 h-4 text-slate-500"})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-6 grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"bg-slate-50 rounded-[14px] p-4 border border-slate-100",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(As,{className:"w-4 h-4 text-slate-500"}),e.jsxs("span",{className:"text-[12px] font-semibold text-slate-600",children:[t.duration_minutes," minutes"]}),t.num_items&&e.jsxs("span",{className:"text-[12px] text-slate-500",children:["• ",t.num_items," items"]})]}),e.jsx("p",{className:"text-[13px] text-[#475569] leading-relaxed",children:t.description||`Work through ${t.topic} at ${t.difficulty} difficulty.`})]}),t.type==="video_lesson"&&e.jsx(lm,{step:t,isActive:!0}),(t.type==="practice"||t.type==="assessment")&&e.jsxs("div",{className:"bg-purple-50/50 rounded-[14px] p-6 border border-purple-100 flex flex-col items-center justify-center min-h-[160px]",children:[e.jsx(ir,{className:"w-10 h-10 text-purple-400 mb-3"}),e.jsxs("p",{className:"text-[13px] font-semibold text-purple-700",children:[t.type==="assessment"?"Assessment":"Practice"," Questions"]}),e.jsxs("p",{className:"text-[11px] text-purple-500 mt-1",children:[t.num_items||10," questions on ",t.topic]})]})]}),e.jsxs("div",{className:"flex flex-col bg-slate-50 rounded-[14px] border border-slate-100 overflow-hidden",children:[e.jsx("div",{className:"px-4 py-3 border-b border-slate-100 bg-white",children:e.jsxs("p",{className:"text-[12px] font-semibold text-[#1e293b] flex items-center gap-1.5",children:[e.jsx(Si,{className:"w-3.5 h-3.5 text-indigo-500"})," AI Guide",e.jsx("span",{className:"text-[9px] font-medium text-slate-400 ml-1",children:"(Preview)"})]})}),e.jsx("div",{className:"flex-1 overflow-y-auto p-3 space-y-3 min-h-[200px] max-h-[300px]",children:d.map((k,N)=>e.jsx("div",{className:`flex ${k.role==="user"?"justify-end":"justify-start"}`,children:e.jsx("div",{className:`max-w-[85%] px-3 py-2 rounded-[12px] text-[12px] leading-relaxed ${k.role==="user"?"bg-indigo-500 text-white":"bg-white border border-slate-200 text-[#475569]"}`,children:k.content})},N))}),e.jsxs("div",{className:"p-3 border-t border-slate-100 bg-white flex gap-2",children:[e.jsx("input",{type:"text",value:p,onChange:k=>h(k.target.value),onKeyDown:k=>k.key==="Enter"&&S(),placeholder:"Ask for help...",className:"flex-1 text-[12px] px-3 py-2 rounded-[10px] border border-slate-200 focus:outline-none focus:border-indigo-300"}),e.jsx("button",{onClick:S,className:"w-8 h-8 rounded-full bg-indigo-500 hover:bg-indigo-600 flex items-center justify-center text-white transition-colors",children:e.jsx(aa,{className:"w-3.5 h-3.5"})})]})]})]}),e.jsxs("div",{className:"px-6 py-4 border-t border-slate-100 flex items-center justify-between shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-full bg-slate-200 h-2 rounded-full overflow-hidden",style:{width:120},children:e.jsx("div",{className:"h-full bg-indigo-500 rounded-full",style:{width:`${t.step_number/o*100}%`}})}),e.jsxs("span",{className:"text-[11px] text-slate-500",children:[t.step_number,"/",o]})]}),e.jsxs("button",{onClick:b,disabled:l||t.is_completed,className:"flex items-center gap-2 px-5 py-2.5 bg-indigo-500 hover:bg-indigo-600 text-white text-[13px] font-semibold rounded-full transition-colors disabled:opacity-50 shadow-sm",children:[e.jsx(La,{className:"w-4 h-4"}),t.is_completed?"Assigned ✓":l?"Assigning...":"Assign"]})]})]})]})})};async function pm(t,s,a){const r=pt(Mt(He,"generatedLessonPlans"));return await ts(r,{...t,teacherId:s,teacherName:a?.teacherName||null,studentId:a?.studentId||null,studentName:a?.studentName||null,status:"draft",createdAt:it(),updatedAt:it()}),r.id}async function hm(t){const s=pt(He,"generatedLessonPlans",t),a=await ks(s);if(!a.exists())throw new Error("Lesson draft not found. Save draft before publishing.");if(!a.data().publishReady)throw new Error("Lesson is not publish-ready. Resolve source legitimacy and validation issues first.");await es(s,{status:"published",publishedAt:it(),updatedAt:it()})}async function Lo(t,s=!0){const a=t.learningCompetency||t.lessonTitle||t.focusTopics&&t.focusTopics[0]||"general mathematics",r=t.subject||"general_math",o=t.quarter??1;let n="",i=[],l,c,d,m=!1;if(s)try{const b=await $l(a,r,o,{lessonTitle:t.lessonTitle,learningCompetency:t.learningCompetency,moduleUnit:t.moduleUnit,learnerLevel:t.learnerLevel});i=b.sources||[],n=b.explanation||"",l=b.retrievalConfidence,c=b.retrievalBand,d=b.retrievalQuery,m=b.needsReview??!1}catch{n="",i=[]}const p={...t,subject:r,quarter:o,curriculumContext:n?`[CURRICULUM CONTEXT] + */const ud=[["path",{d:"m21.64 3.64-1.28-1.28a1.21 1.21 0 0 0-1.72 0L2.36 18.64a1.21 1.21 0 0 0 0 1.72l1.28 1.28a1.2 1.2 0 0 0 1.72 0L21.64 5.36a1.2 1.2 0 0 0 0-1.72",key:"ul74o6"}],["path",{d:"m14 7 3 3",key:"1r5n42"}],["path",{d:"M5 6v4",key:"ilb8ba"}],["path",{d:"M19 14v4",key:"blhpug"}],["path",{d:"M10 2v2",key:"7u0qdc"}],["path",{d:"M7 8H3",key:"zfb6yr"}],["path",{d:"M21 16h-4",key:"1cnmox"}],["path",{d:"M11 3H9",key:"1obp7u"}]],Xr=wt("wand-sparkles",ud);function md(t,s){const a=Dl(t);return isNaN(s)?Cc(t,NaN):(a.setDate(a.getDate()+s),a)}function Ci(t,s){const a=zn(t),r=zn(s);return+a==+r}function so(t){return Ci(t,ji(t))}function xd(t,s){return md(t,-1)}function ao(t){return Ci(t,xd(ji(t)))}const vr=0,$s=1,ua=2,Ii=4;function ro(t){return()=>t}function pd(t){t()}function Ti(t,s){return a=>t(s(a))}function no(t,s){return()=>t(s)}function hd(t,s){return a=>t(s,a)}function cn(t){return t!==void 0}function fd(...t){return()=>{t.map(pd)}}function ma(){}function wr(t,s){return s(t),t}function gd(t,s){return s(t)}function at(...t){return t}function Xe(t,s){return t($s,s)}function Ae(t,s){t(vr,s)}function dn(t){t(ua)}function ot(t){return t(Ii)}function ge(t,s){return Xe(t,hd(s,vr))}function ss(t,s){const a=t($s,r=>{a(),s(r)});return a}function oo(t){let s,a;return r=>o=>{s=o,a&&clearTimeout(a),a=setTimeout(()=>{r(s)},t)}}function _i(t,s){return t===s}function st(t=_i){let s;return a=>r=>{t(s,r)||(s=r,a(r))}}function ke(t){return s=>a=>{t(a)&&s(a)}}function xe(t){return s=>Ti(s,t)}function ls(t){return s=>()=>{s(t)}}function K(t,...s){const a=bd(...s);return((r,o)=>{switch(r){case ua:dn(t);return;case $s:return Xe(t,a(o))}})}function ds(t,s){return a=>r=>{a(s=t(s,r))}}function Ws(t){return s=>a=>{t>0?t--:s(a)}}function Cs(t){let s=null,a;return r=>o=>{s=o,!a&&(a=setTimeout(()=>{a=void 0,r(s)},t))}}function ze(...t){const s=new Array(t.length);let a=0,r=null;const o=2**t.length-1;return t.forEach((n,i)=>{const l=2**i;Xe(n,c=>{const d=a;a|=l,s[i]=c,d!==o&&a===o&&r&&(r(),r=null)})}),n=>i=>{const l=()=>{n([i].concat(s))};a===o?l():r=l}}function bd(...t){return s=>t.reduceRight(gd,s)}function vd(t){let s,a;const r=()=>s?.();return function(o,n){switch(o){case $s:return n?a===n?void 0:(r(),a=n,s=Xe(t,n),s):(r(),ma);case ua:r(),a=null;return}}}function Z(t){let s=t;const a=Be();return((r,o)=>{switch(r){case vr:s=o;break;case $s:{o(s);break}case Ii:return s}return a(r,o)})}function Rt(t,s){return wr(Z(s),a=>ge(t,a))}function Be(){const t=[];return((s,a)=>{switch(s){case vr:t.slice().forEach(r=>{r(a)});return;case ua:t.splice(0,t.length);return;case $s:return t.push(a),()=>{const r=t.indexOf(a);r>-1&&t.splice(r,1)}}})}function Qt(t){return wr(Be(),s=>ge(t,s))}function Ke(t,s=[],{singleton:a}={singleton:!0}){return{constructor:t,dependencies:s,id:wd(),singleton:a}}const wd=()=>Symbol();function Nd(t){const s=new Map,a=({constructor:r,dependencies:o,id:n,singleton:i})=>{if(i&&s.has(n))return s.get(n);const l=r(o.map(c=>a(c)));return i&&s.set(n,l),l};return a(t)}function ht(...t){const s=Be(),a=new Array(t.length);let r=0;const o=2**t.length-1;return t.forEach((n,i)=>{const l=2**i;Xe(n,c=>{a[i]=c,r|=l,r===o&&Ae(s,a)})}),function(n,i){switch(n){case ua:{dn(s);return}case $s:return r===o&&i(a),Xe(s,i)}}}function Se(t,s=_i){return K(t,st(s))}function Jr(...t){return function(s,a){switch(s){case ua:return;case $s:return fd(...t.map(r=>Xe(r,a)))}}}const vt={DEBUG:0,INFO:1,WARN:2,ERROR:3},jd={[vt.DEBUG]:"debug",[vt.ERROR]:"error",[vt.INFO]:"log",[vt.WARN]:"warn"},yd=()=>typeof globalThis>"u"?window:globalThis,Fs=Ke(()=>{const t=Z(vt.ERROR);return{log:Z((s,a,r=vt.INFO)=>{const o=yd().VIRTUOSO_LOG_LEVEL??ot(t);r>=o&&console[jd[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",s,a)}),logLevel:t}},[],{singleton:!0});function Ys(t,s,a){return un(t,s,a).callbackRef}function un(t,s,a){const r=he.useRef(null);let o=i=>{};const n=he.useMemo(()=>typeof ResizeObserver<"u"?new ResizeObserver(i=>{const l=()=>{const c=i[0].target;c.offsetParent!==null&&t(c)};a?l():requestAnimationFrame(l)}):null,[t,a]);return o=i=>{i&&s?(n?.observe(i),r.current=i):(r.current&&n?.unobserve(r.current),r.current=null)},{callbackRef:o,ref:r}}function Sd(t,s,a,r,o,n,i,l,c){const d=he.useCallback(m=>{const p=kd(m.children,s,l?"offsetWidth":"offsetHeight",o);let h=m.parentElement;for(;h.dataset.virtuosoScroller===void 0;)h=h.parentElement;const b=h.lastElementChild.dataset.viewportType==="window";let S;b&&(S=h.ownerDocument.defaultView);const k=i?l?i.scrollLeft:i.scrollTop:b?l?S.scrollX||S.document.documentElement.scrollLeft:S.scrollY||S.document.documentElement.scrollTop:l?h.scrollLeft:h.scrollTop,N=i?l?i.scrollWidth:i.scrollHeight:b?l?S.document.documentElement.scrollWidth:S.document.documentElement.scrollHeight:l?h.scrollWidth:h.scrollHeight,v=i?l?i.offsetWidth:i.offsetHeight:b?l?S.innerWidth:S.innerHeight:l?h.offsetWidth:h.offsetHeight;r({scrollHeight:N,scrollTop:Math.max(k,0),viewportHeight:v}),n?.(l?io("column-gap",getComputedStyle(m).columnGap,o):io("row-gap",getComputedStyle(m).rowGap,o)),p!==null&&t(p)},[t,s,o,n,i,r,l]);return un(d,a,c)}function kd(t,s,a,r){const o=t.length;if(o===0)return null;const n=[];for(let i=0;i{if(!c?.offsetParent)return;const d=c.getBoundingClientRect(),m=d.width;let p,h;if(s){const b=s.getBoundingClientRect(),S=d.top-b.top;h=b.height-Math.max(0,S),p=S+s.scrollTop}else{const b=i.current.ownerDocument.defaultView;h=b.innerHeight-Math.max(0,d.top),p=d.top+b.scrollY}r.current={listHeight:d.height,offsetTop:p,visibleHeight:h,visibleWidth:m},t(r.current)},[t,s]),{callbackRef:n,ref:i}=un(o,!0,a),l=he.useCallback(()=>{o(i.current)},[o,i]);return he.useEffect(()=>{if(s){s.addEventListener("scroll",l);const d=new ResizeObserver(()=>{requestAnimationFrame(l)});return d.observe(s),()=>{s.removeEventListener("scroll",l),d.unobserve(s)}}const c=i.current?.ownerDocument.defaultView;return c?.addEventListener("scroll",l),c?.addEventListener("resize",l),()=>{c?.removeEventListener("scroll",l),c?.removeEventListener("resize",l)}},[l,s,i]),n}const Dt=Ke(()=>{const t=Be(),s=Be(),a=Z(0),r=Be(),o=Z(0),n=Be(),i=Be(),l=Z(0),c=Z(0),d=Z(0),m=Z(0),p=Be(),h=Be(),b=Z(!1),S=Z(!1),k=Z(!1);return ge(K(t,xe(({scrollTop:N})=>N)),s),ge(K(t,xe(({scrollHeight:N})=>N)),i),ge(s,o),{deviation:a,fixedFooterHeight:d,fixedHeaderHeight:c,footerHeight:m,headerHeight:l,horizontalDirection:S,scrollBy:h,scrollContainerState:t,scrollHeight:i,scrollingInProgress:b,scrollTo:p,scrollTop:s,skipAnimationFrameInResizeObserver:k,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:n}},[],{singleton:!0}),Ia={lvl:0};function Ri(t,s){const a=t.length;if(a===0)return[];let{index:r,value:o}=s(t[0]);const n=[];for(let i=1;is&&(l=l.concat(en(o,s,a))),r>=s&&r<=a&&l.push({k:r,v:i}),r<=a&&(l=l.concat(en(n,s,a))),l}function er(t){const{l:s,lvl:a,r}=t;if(r.lvl>=a-1&&s.lvl>=a-1)return t;if(a>r.lvl+1){if(Rr(s))return zi(bt(t,{lvl:a-1}));if(!et(s)&&!et(s.r))return bt(s.r,{l:bt(s,{r:s.r.l}),lvl:a,r:bt(t,{l:s.r.r,lvl:a-1})});throw new Error("Unexpected empty nodes")}if(Rr(t))return tn(bt(t,{lvl:a-1}));if(!et(r)&&!et(r.l)){const o=r.l,n=Rr(o)?r.lvl-1:r.lvl;return bt(o,{l:bt(t,{lvl:a-1,r:o.l}),lvl:o.lvl+1,r:tn(bt(r,{l:o.r,lvl:n}))})}throw new Error("Unexpected empty nodes")}function bt(t,s){return Li(s.k!==void 0?s.k:t.k,s.v!==void 0?s.v:t.v,s.lvl!==void 0?s.lvl:t.lvl,s.l!==void 0?s.l:t.l,s.r!==void 0?s.r:t.r)}function Mi(t){return et(t.r)?t.l:er(bt(t,{r:Mi(t.r)}))}function Rr(t){return et(t)||t.lvl>t.r.lvl}function Ai(t){return et(t.r)?[t.k,t.v]:Ai(t.r)}function Li(t,s,a,r=Ia,o=Ia){return{k:t,l:r,lvl:a,r:o,v:s}}function lo(t){return tn(zi(t))}function zi(t){const{l:s}=t;return!et(s)&&s.lvl===t.lvl?bt(s,{r:bt(t,{l:s.r})}):t}function tn(t){const{lvl:s,r:a}=t;return!et(a)&&!et(a.r)&&a.lvl===s&&a.r.lvl===s?bt(a,{l:bt(t,{r:a.l}),lvl:s+1}):t}function Cd(t){return Ri(t,({k:s,v:a})=>({index:s,value:a}))}function Di(t,s){return!!(t&&t.startIndex===s.startIndex&&t.endIndex===s.endIndex)}function _a(t,s){return!!(t&&t[0]===s[0]&&t[1]===s[1])}const mn=Ke(()=>({recalcInProgress:Z(!1)}),[],{singleton:!0});function $i(t,s,a){return t[mr(t,s,a)]}function mr(t,s,a,r=0){let o=t.length-1;for(;r<=o;){const n=Math.floor((r+o)/2),i=t[n],l=a(i,s);if(l===0)return n;if(l===-1){if(o-r<2)return n-1;o=n-1}else{if(o===r)return n;r=n+1}}throw new Error(`Failed binary finding record in array - ${t.join(",")}, searched for ${s}`)}function Id(t,s,a,r){const o=mr(t,s,r),n=mr(t,a,r,o);return t.slice(o,n+1)}function Ds(t,s){return Math.round(t.getBoundingClientRect()[s])}function Nr(t){return!et(t.groupOffsetTree)}function xn({index:t},s){return s===t?0:s=p||n===h)&&(t=Zr(t,p)):(d=h!==n,c=!0),m>o&&o>=p&&h!==n&&(t=Ut(t,o+1,h));d&&(t=Ut(t,i,n))}return[t,a]}function Ed(t){return typeof t.groupIndex<"u"}function Rd({offset:t},s){return s===t?0:s0?l+a:l}function Fi(t,s){if(!Nr(s))return t;let a=0;for(;s.groupIndices[a]<=t+a;)a++;return t+a}function Oi(t,s,a){if(Ed(t))return s.groupIndices[t.groupIndex]+1;const r=t.index==="LAST"?a:t.index;let o=Fi(r,s);return o=Math.max(0,o,Math.min(a,o)),o}function Md(t,s,a,r=0){return r>0&&(s=Math.max(s,$i(t,r,xn).offset)),Ri(Id(t,s,a,Rd),zd)}function Ad(t,[s,a,r,o]){s.length>0&&r("received item sizes",s,vt.DEBUG);const n=t.sizeTree;let i=n,l=0;if(a.length>0&&et(n)&&s.length===2){const h=s[0].size,b=s[1].size;i=a.reduce((S,k)=>Ut(Ut(S,k,h),k+1,b),i)}else[i,l]=_d(i,s);if(i===n)return t;const{lastIndex:c,lastOffset:d,lastSize:m,offsetTree:p}=sn(t.offsetTree,l,i,o);return{groupIndices:a,groupOffsetTree:a.reduce((h,b)=>Ut(h,b,Ea(b,p,o)),oa()),lastIndex:c,lastOffset:d,lastSize:m,offsetTree:p,sizeTree:i}}function Ld(t){return Vs(t).map(({k:s,v:a},r,o)=>{const n=o[r+1];return{endIndex:n!==void 0?n.k-1:1/0,size:a,startIndex:s}})}function co(t,s){let a=0,r=0;for(;ao.start===r&&(o.end===s||o.end===1/0)&&o.value===a}const $d={offsetHeight:"height",offsetWidth:"width"},fs=Ke(([{log:t},{recalcInProgress:s}])=>{const a=Be(),r=Be(),o=Rt(r,0),n=Be(),i=Be(),l=Z(0),c=Z([]),d=Z(void 0),m=Z(void 0),p=Z(void 0),h=Z(void 0),b=Z((f,C)=>Ds(f,$d[C])),S=Z(void 0),k=Z(0),N=Td(),v=Rt(K(a,ze(c,t,k),ds(Ad,N),st()),N),g=Rt(K(c,st(),ds((f,C)=>({current:C,prev:f.current}),{current:[],prev:[]}),xe(({prev:f})=>f)),[]);ge(K(c,ke(f=>f.length>0),ze(v,k),xe(([f,C,w])=>{const $=f.reduce((A,y,q)=>Ut(A,y,Ea(y,C.offsetTree,w)||q),oa());return{...C,groupIndices:f,groupOffsetTree:$}})),v),ge(K(r,ze(v),ke(([f,{lastIndex:C}])=>f[{endIndex:C,size:w,startIndex:f}])),a),ge(d,m);const I=Rt(K(d,xe(f=>f===void 0)),!0);ge(K(m,ke(f=>f!==void 0&&et(ot(v).sizeTree)),xe(f=>{const C=ot(p),w=ot(c).length>0;return C!==void 0&&C!==0?w?[{endIndex:0,size:C,startIndex:0},{endIndex:1,size:f,startIndex:1}]:[]:[{endIndex:0,size:f,startIndex:0}]})),a),ge(K(h,ke(f=>f!==void 0&&f.length>0&&et(ot(v).sizeTree)),xe(f=>{const C=[];let w=f[0],$=0;for(let A=1;Af!==void 0&&C!==void 0),xe(([f,C,w])=>{const $=[];for(let A=0;A({changed:w!==f,sizes:w}),{changed:!1,sizes:N}),xe(f=>f.changed)));Xe(K(l,ds((f,C)=>({diff:f.prev-C,prev:C}),{diff:0,prev:0}),xe(f=>f.diff)),f=>{const{groupIndices:C}=ot(v);if(f>0)Ae(s,!0),Ae(n,f+co(f,C));else if(f<0){const w=ot(g);w.length>0&&(f-=co(-f,w)),Ae(i,f)}}),Xe(K(l,ze(t)),([f,C])=>{f<0&&C("`firstItemIndex` prop should not be set to less than zero. If you don't know the total count, just use a very high value",{firstItemIndex:l},vt.ERROR)});const R=Qt(n);ge(K(n,ze(v),xe(([f,C])=>{const w=C.groupIndices.length>0,$=[],A=C.lastSize;if(w){const y=Ta(C.sizeTree,0);let q=0,J=0;for(;q{let Ie=le.ranges;return le.prevSize!==0&&(Ie=[...le.ranges,{endIndex:ne+f-1,size:le.prevSize,startIndex:le.prevIndex}]),{prevIndex:ne+f,prevSize:be,ranges:Ie}},{prevIndex:f,prevSize:0,ranges:$}).ranges}return Vs(C.sizeTree).reduce((y,{k:q,v:J})=>({prevIndex:q+f,prevSize:J,ranges:[...y.ranges,{endIndex:q+f-1,size:y.prevSize,startIndex:y.prevIndex}]}),{prevIndex:0,prevSize:A,ranges:[]}).ranges})),a);const W=Qt(K(i,ze(v,k),xe(([f,{offsetTree:C},w])=>{const $=-f;return Ea($,C,w)})));return ge(K(i,ze(v,k),xe(([f,C,w])=>{if(C.groupIndices.length>0){if(et(C.sizeTree))return C;let A=oa();const y=ot(g);let q=0,J=0,re=0;for(;q<-f;){re=y[J];const le=y[J+1]-re-1;J++,q+=le+1}if(A=Vs(C.sizeTree).reduce((le,{k:ne,v:be})=>Ut(le,Math.max(0,ne+f),be),A),q!==-f){const le=Ta(C.sizeTree,re);A=Ut(A,0,le);const ne=as(C.sizeTree,-f+1)[1];A=Ut(A,1,ne)}return{...C,sizeTree:A,...sn(C.offsetTree,0,A,w)}}const $=Vs(C.sizeTree).reduce((A,{k:y,v:q})=>Ut(A,Math.max(0,y+f),q),oa());return{...C,sizeTree:$,...sn(C.offsetTree,0,$,w)}})),v),{beforeUnshiftWith:R,data:S,defaultItemSize:m,firstItemIndex:l,fixedItemSize:d,fixedGroupSize:p,gap:k,groupIndices:c,heightEstimates:h,itemSize:b,listRefresh:z,shiftWith:i,shiftWithOffset:W,sizeRanges:a,sizes:v,statefulTotalCount:o,totalCount:r,trackItemSizes:I,unshiftWith:n}},at(Fs,mn),{singleton:!0});function Fd(t){return t.reduce((s,a)=>(s.groupIndices.push(s.totalCount),s.totalCount+=a+1,s),{groupIndices:[],totalCount:0})}const Pi=Ke(([{groupIndices:t,sizes:s,totalCount:a},{headerHeight:r,scrollTop:o}])=>{const n=Be(),i=Be(),l=Qt(K(n,xe(Fd)));return ge(K(l,xe(c=>c.totalCount)),a),ge(K(l,xe(c=>c.groupIndices)),t),ge(K(ht(o,s,r),ke(([c,d])=>Nr(d)),xe(([c,d,m])=>as(d.groupOffsetTree,Math.max(c-m,0),"v")[0]),st(),xe(c=>[c])),i),{groupCounts:n,topItemsIndexes:i}},at(fs,Dt)),Os=Ke(([{log:t}])=>{const s=Z(!1),a=Qt(K(s,ke(r=>r),st()));return Xe(s,r=>{r&&ot(t)("props updated",{},vt.DEBUG)}),{didMount:a,propsReady:s}},at(Fs),{singleton:!0}),Od=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function Bi(t){const s=typeof t=="number"?{index:t}:t;return s.align||(s.align="start"),(!s.behavior||!Od)&&(s.behavior="auto"),s.offset===void 0&&(s.offset=0),s}const za=Ke(([{gap:t,listRefresh:s,sizes:a,totalCount:r},{fixedFooterHeight:o,fixedHeaderHeight:n,footerHeight:i,headerHeight:l,scrollingInProgress:c,scrollTo:d,smoothScrollTargetReached:m,viewportHeight:p},{log:h}])=>{const b=Be(),S=Be(),k=Z(0);let N=null,v=null,g=null;function I(){N!==null&&(N(),N=null),g!==null&&(g(),g=null),v&&(clearTimeout(v),v=null),Ae(c,!1)}return ge(K(b,ze(a,p,r,k,l,i,h),ze(t,n,o),xe(([[z,R,W,f,C,w,$,A],y,q,J])=>{const re=Bi(z),{align:le,behavior:ne,offset:be}=re,Ie=f-1,de=Oi(re,R,Ie);let fe=Ea(de,R.offsetTree,y)+w;le==="end"?(fe+=q+as(R.sizeTree,de)[1]-W+J,de===Ie&&(fe+=$)):le==="center"?fe+=(q+as(R.sizeTree,de)[1]-W+J)/2:fe-=C,be!==void 0&&be!==0&&(fe+=be);const H=ee=>{I(),ee?(A("retrying to scroll to",{location:z},vt.DEBUG),Ae(b,z)):(Ae(S,!0),A("list did not change, scroll successful",{},vt.DEBUG))};if(I(),ne==="smooth"){let ee=!1;g=Xe(s,oe=>{ee=ee||oe}),N=ss(m,()=>{H(ee)})}else N=ss(K(s,Pd(150)),H);return v=setTimeout(()=>{I()},1200),Ae(c,!0),A("scrolling from index to",{behavior:ne,index:de,top:fe},vt.DEBUG),{behavior:ne,top:fe}})),d),{scrollTargetReached:S,scrollToIndex:b,topListHeight:k}},at(fs,Dt,Fs),{singleton:!0});function Pd(t){return s=>{const a=setTimeout(()=>{s(!1)},t);return r=>{r&&(s(!0),clearTimeout(a))}}}function pn(t,s){t===0?s():requestAnimationFrame(()=>{pn(t-1,s)})}function hn(t,s){const a=s-1;return typeof t=="number"?t:t.index==="LAST"?a:t.index}const Da=Ke(([{defaultItemSize:t,listRefresh:s,sizes:a},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:n},{didMount:i}])=>{const l=Z(!0),c=Z(0),d=Z(!0);return ge(K(i,ze(c),ke(([m,p])=>p!==0),ls(!1)),l),ge(K(i,ze(c),ke(([m,p])=>p!==0),ls(!1)),d),Xe(K(ht(s,i),ze(l,a,t,d),ke(([[,m],p,{sizeTree:h},b,S])=>m&&(!et(h)||cn(b))&&!p&&!S),ze(c)),([,m])=>{ss(o,()=>{Ae(d,!0)}),pn(4,()=>{ss(r,()=>{Ae(l,!0)}),Ae(n,m)})}),{initialItemFinalLocationReached:d,initialTopMostItemIndex:c,scrolledToInitialItem:l}},at(fs,Dt,za,Os),{singleton:!0});function Hi(t,s){return Math.abs(t-s)<1.01}const Ra="up",Sa="down",Bd="none",Hd={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},Ud=0,$a=Ke(([{footerHeight:t,headerHeight:s,scrollBy:a,scrollContainerState:r,scrollTop:o,viewportHeight:n}])=>{const i=Z(!1),l=Z(!0),c=Be(),d=Be(),m=Z(4),p=Z(Ud),h=Rt(K(Jr(K(Se(o),Ws(1),ls(!0)),K(Se(o),Ws(1),ls(!1),oo(100))),st()),!1),b=Rt(K(Jr(K(a,ls(!0)),K(a,ls(!1),oo(200))),st()),!1);ge(K(ht(Se(o),Se(p)),xe(([g,I])=>g<=I),st()),l),ge(K(l,Cs(50)),d);const S=Qt(K(ht(r,Se(n),Se(s),Se(t),Se(m)),ds((g,[{scrollHeight:I,scrollTop:z},R,W,f,C])=>{const w=z+R-I>-C,$={scrollHeight:I,scrollTop:z,viewportHeight:R};if(w){let y,q;return z>g.state.scrollTop?(y="SCROLLED_DOWN",q=g.state.scrollTop-z):(y="SIZE_DECREASED",q=g.state.scrollTop-z||g.scrollTopDelta),{atBottom:!0,atBottomBecause:y,scrollTopDelta:q,state:$}}let A;return $.scrollHeight>g.state.scrollHeight?A="SIZE_INCREASED":Rg!==void 0&&g.atBottom===I.atBottom))),k=Rt(K(r,ds((g,{scrollHeight:I,scrollTop:z,viewportHeight:R})=>{if(!Hi(g.scrollHeight,I)){const W=I-(z+R)<1;return g.scrollTop!==z&&W?{changed:!0,jump:g.scrollTop-z,scrollHeight:I,scrollTop:z}:{changed:!0,jump:0,scrollHeight:I,scrollTop:z}}return{changed:!1,jump:0,scrollHeight:I,scrollTop:z}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),ke(g=>g.changed),xe(g=>g.jump)),0);ge(K(S,xe(g=>g.atBottom)),i),ge(K(i,Cs(50)),c);const N=Z(Sa);ge(K(r,xe(({scrollTop:g})=>g),st(),ds((g,I)=>ot(b)?{direction:g.direction,prevScrollTop:I}:{direction:Ig.direction)),N),ge(K(r,Cs(50),ls(Bd)),N);const v=Z(0);return ge(K(h,ke(g=>!g),ls(0)),v),ge(K(o,Cs(100),ze(h),ke(([g,I])=>I),ds(([g,I],[z])=>[I,z],[0,0]),xe(([g,I])=>I-g)),v),{atBottomState:S,atBottomStateChange:c,atBottomThreshold:m,atTopStateChange:d,atTopThreshold:p,isAtBottom:i,isAtTop:l,isScrolling:h,lastJumpDueToItemResize:k,scrollDirection:N,scrollVelocity:v}},at(Dt)),Ma="top",Aa="bottom",uo="none";function mo(t,s,a){return typeof t=="number"?a===Ra&&s===Ma||a===Sa&&s===Aa?t:0:a===Ra?s===Ma?t.main:t.reverse:s===Aa?t.main:t.reverse}function xo(t,s){return typeof t=="number"?t:t[s]??0}const fn=Ke(([{deviation:t,fixedHeaderHeight:s,headerHeight:a,scrollTop:r,viewportHeight:o}])=>{const n=Be(),i=Z(0),l=Z(0),c=Z(0),d=Rt(K(ht(Se(r),Se(o),Se(a),Se(n,_a),Se(c),Se(i),Se(s),Se(t),Se(l)),xe(([m,p,h,[b,S],k,N,v,g,I])=>{const z=m-g,R=N+v,W=Math.max(h-z,0);let f=uo;const C=xo(I,Ma),w=xo(I,Aa);return b-=g,b+=h+v,S+=h+v,S-=g,b>m+R-C&&(f=Ra),Sm!==null),st(_a)),[0,0]);return{increaseViewportBy:l,listBoundary:n,overscan:c,topListHeight:i,visibleRange:d}},at(Dt),{singleton:!0});function Gd(t,s,a){if(Nr(s)){const r=Fi(t,s);return[{index:as(s.groupOffsetTree,r)[0],offset:0,size:0},{data:a?.[0],index:r,offset:0,size:0}]}return[{data:a?.[0],index:t,offset:0,size:0}]}const Mr={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function tr(t,s,a,r,o,n){const{lastIndex:i,lastOffset:l,lastSize:c}=o;let d=0,m=0;if(t.length>0){d=t[0].offset;const k=t[t.length-1];m=k.offset+k.size}const p=a-i,h=l+p*c+(p-1)*r,b=d,S=h-m;return{bottom:m,firstItemIndex:n,items:po(t,o,n),offsetBottom:S,offsetTop:d,top:b,topItems:po(s,o,n),topListHeight:s.reduce((k,N)=>N.size+k,0),totalCount:a}}function Ui(t,s,a,r,o,n){let i=0;if(a.groupIndices.length>0)for(const m of a.groupIndices){if(m-i>=t)break;i++}const l=t+i,c=hn(s,l),d=Array.from({length:l}).map((m,p)=>({data:n[p+c],index:p+c,offset:0,size:0}));return tr(d,[],l,o,a,r)}function po(t,s,a){if(t.length===0)return[];if(!Nr(s))return t.map(d=>({...d,index:d.index+a,originalIndex:d.index}));const r=t[0].index,o=t[t.length-1].index,n=[],i=ia(s.groupOffsetTree,r,o);let l,c=0;for(const d of t){(!l||l.end{const k=Z([]),N=Z(0),v=Be(),g=Z(0);ge(n.topItemsIndexes,k);const I=Rt(K(ht(b,S,Se(c,_a),Se(o),Se(r),Se(d),m,Se(k),Se(s),Se(a),Se(g),t),ke(([f,C,,w,,,,,,,,$])=>{const A=$!==void 0&&$.length!==w;return f&&!C&&!A}),xe(([,,[f,C],w,$,A,y,q,J,re,le,ne])=>{const be=$,{offsetTree:Ie,sizeTree:de}=be,fe=ot(N);if(w===0)return{...Mr,totalCount:w};if(f===0&&C===0)return fe===0?{...Mr,totalCount:w}:Ui(fe,A,$,J,re,ne||[]);if(et(de))return fe>0?null:tr(Gd(hn(A,w),be,ne),[],w,re,be,J);const H=[];if(q.length>0){const te=q[0],E=q[q.length-1];let Y=0;for(const V of ia(de,te,E)){const pe=V.value,D=Math.max(V.start,te),j=Math.min(V.end,E);for(let _=D;_<=j;_++)H.push({data:ne?.[_],index:_,offset:Y,size:pe}),Y+=pe}}if(!y)return tr([],H,w,re,be,J);const ee=q.length>0?q[q.length-1]+1:0,oe=Md(Ie,f,C,ee);if(oe.length===0)return null;const Re=w-1,Fe=wr([],te=>{for(const E of oe){const Y=E.value;let V=Y.offset,pe=E.start;const D=Y.size;if(Y.offset=C);_++)te.push({data:ne?.[_],index:_,offset:V,size:D}),V+=D+re}}),Pe=ho(le,Ma),G=ho(le,Aa);if(Fe.length>0&&(Pe>0||G>0)){const te=Fe[0],E=Fe[Fe.length-1];if(Pe>0&&te.index>ee){const Y=Math.min(Pe,te.index-ee),V=[];let pe=te.offset;for(let D=te.index-1;D>=te.index-Y;D--){const j=ia(de,D,D)[0]?.value??te.size;pe-=j+re,V.unshift({data:ne?.[D],index:D,offset:pe,size:j})}Fe.unshift(...V)}if(G>0&&E.indexf!==null),st()),Mr);ge(K(t,ke(cn),xe(f=>f?.length)),o),ge(K(I,xe(f=>f.topListHeight)),p),ge(p,l),ge(K(I,xe(f=>[f.top,f.bottom])),i),ge(K(I,xe(f=>f.items)),v);const z=Qt(K(I,ke(({items:f})=>f.length>0),ze(o,t),ke(([{items:f},C])=>f[f.length-1].originalIndex===C-1),xe(([,f,C])=>[f-1,C]),st(_a),xe(([f])=>f))),R=Qt(K(I,Cs(200),ke(({items:f,topItems:C})=>f.length>0&&f[0].originalIndex===C.length),xe(({items:f})=>f[0].index),st())),W=Qt(K(I,ke(({items:f})=>f.length>0),xe(({items:f})=>{let C=0,w=f.length-1;for(;f[C].type==="group"&&CC;)w--;return{endIndex:f[w].index,startIndex:f[C].index}}),st(Di)));return{endReached:z,initialItemCount:N,itemsRendered:v,listState:I,minOverscanItemCount:g,rangeChanged:W,startReached:R,topItemsIndexes:k,...h}},at(fs,Pi,fn,Da,za,$a,Os,mn),{singleton:!0}),Gi=Ke(([{fixedFooterHeight:t,fixedHeaderHeight:s,footerHeight:a,headerHeight:r},{listState:o}])=>{const n=Be(),i=Rt(K(ht(a,t,r,s,o),xe(([l,c,d,m,p])=>l+c+d+m+p.offsetBottom+p.bottom)),0);return ge(Se(i),n),{totalListHeight:i,totalListHeightChanged:n}},at(Dt,Ks),{singleton:!0}),Qd=Ke(([{viewportHeight:t},{totalListHeight:s}])=>{const a=Z(!1),r=Rt(K(ht(a,t,s),ke(([o])=>o),xe(([,o,n])=>Math.max(0,o-n)),Cs(0),st()),0);return{alignToBottom:a,paddingTopAddition:r}},at(Dt,Gi),{singleton:!0}),Qi=Ke(()=>({context:Z(null)})),Vd=({itemBottom:t,itemTop:s,locationParams:{align:a,behavior:r,...o},viewportBottom:n,viewportTop:i})=>sn?{...o,align:a??"end",...r!==void 0?{behavior:r}:{}}:null,Vi=Ke(([{gap:t,sizes:s,totalCount:a},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:n,scrollingInProgress:i,scrollTop:l,viewportHeight:c},{scrollToIndex:d}])=>{const m=Be();return ge(K(m,ze(s,c,a,n,o,r,l),ze(t),xe(([[p,h,b,S,k,N,v,g],I])=>{const{calculateViewLocation:z=Vd,done:R,...W}=p,f=Oi(p,h,S-1),C=Ea(f,h.offsetTree,I)+k+N,w=C+as(h.sizeTree,f)[1],$=g+N,A=g+b-v,y=z({itemBottom:w,itemTop:C,locationParams:W,viewportBottom:A,viewportTop:$});return y!==null?R&&ss(K(i,ke(q=>!q),Ws(ot(i)?1:2)),R):R?.(),y}),ke(p=>p!==null)),d),{scrollIntoView:m}},at(fs,Dt,za,Ks,Fs),{singleton:!0});function fo(t){return t===!1?!1:t==="smooth"?"smooth":"auto"}const Wd=(t,s)=>typeof t=="function"?fo(t(s)):s&&fo(t),qd=Ke(([{listRefresh:t,totalCount:s,fixedItemSize:a,data:r},{atBottomState:o,isAtBottom:n},{scrollToIndex:i},{scrolledToInitialItem:l},{didMount:c,propsReady:d},{log:m},{scrollingInProgress:p},{context:h},{scrollIntoView:b}])=>{const S=Z(!1),k=Be();let N=null;function v(R){Ae(i,{align:"end",behavior:R,index:"LAST"})}Xe(K(ht(K(Se(s),Ws(1)),c),ze(Se(S),n,l,p),xe(([[R,W],f,C,w,$])=>{let A=W&&w,y="auto";return A&&(y=Wd(f,C||$),A=A&&y!==!1),{followOutputBehavior:y,shouldFollow:A,totalCount:R}}),ke(({shouldFollow:R})=>R)),({followOutputBehavior:R,totalCount:W})=>{N!==null&&(N(),N=null),ot(a)!==void 0?requestAnimationFrame(()=>{ot(m)("following output to ",{totalCount:W},vt.DEBUG),v(R)}):N=ss(t,()=>{ot(m)("following output to ",{totalCount:W},vt.DEBUG),v(R),N=null})});function g(R){const W=ss(o,f=>{R&&!f.atBottom&&f.notAtBottomBecause==="SIZE_INCREASED"&&N===null&&(ot(m)("scrolling to bottom due to increased size",{},vt.DEBUG),v("auto"))});setTimeout(W,100)}Xe(K(ht(Se(S),s,d),ke(([R,,W])=>R!==!1&&W),ds(({value:R},[,W])=>({refreshed:R===W,value:W}),{refreshed:!1,value:0}),ke(({refreshed:R})=>R),ze(S,s)),([,R])=>{ot(l)&&g(R!==!1)}),Xe(k,()=>{g(ot(S)!==!1)}),Xe(ht(Se(S),o),([R,W])=>{R!==!1&&!W.atBottom&&W.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&v("auto")});const I=Z(null),z=Be();return ge(Jr(K(Se(r),xe(R=>R?.length??0)),K(Se(s))),z),Xe(K(ht(K(z,Ws(1)),c),ze(Se(I),l,p,h),xe(([[R,W],f,C,w,$])=>W&&C&&f?.({context:$,totalCount:R,scrollingInProgress:w})),ke(R=>!!R),Cs(0)),R=>{N!==null&&(N(),N=null),ot(a)!==void 0?requestAnimationFrame(()=>{ot(m)("scrolling into view",{}),Ae(b,R)}):N=ss(t,()=>{ot(m)("scrolling into view",{}),Ae(b,R),N=null})}),{autoscrollToBottom:k,followOutput:S,scrollIntoViewOnChange:I}},at(fs,$a,za,Da,Os,Fs,Dt,Qi,Vi)),Yd=Ke(([{data:t,firstItemIndex:s,gap:a,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:n,listState:i},{didMount:l}])=>(ge(K(l,ze(n),ke(([,c])=>c!==0),ze(o,r,s,a,t),xe(([[,c],d,m,p,h,b=[]])=>Ui(c,d,m,p,h,b))),i),{}),at(fs,Da,Ks,Os),{singleton:!0}),Kd=Ke(([{didMount:t},{scrollTo:s},{listState:a}])=>{const r=Z(0);return Xe(K(t,ze(r),ke(([,o])=>o!==0),xe(([,o])=>({top:o}))),o=>{ss(K(a,Ws(1),ke(n=>n.items.length>1)),()=>{requestAnimationFrame(()=>{Ae(s,o)})})}),{initialScrollTop:r}},at(Os,Dt,Ks),{singleton:!0}),Wi=Ke(([{scrollVelocity:t}])=>{const s=Z(!1),a=Be(),r=Z(!1);return ge(K(t,ze(r,s,a),ke(([o,n])=>n!==!1&&n!==void 0),xe(([o,n,i,l])=>{const{enter:c,exit:d}=n;if(i){if(d(o,l))return!1}else if(c(o,l))return!0;return i}),st()),s),Xe(K(ht(s,t,a),ze(r)),([[o,n,i],l])=>{o&&l!==!1&&l!==void 0&&l.change&&l.change(n,i)}),{isSeeking:s,scrollSeekConfiguration:r,scrollSeekRangeChanged:a,scrollVelocity:t}},at($a),{singleton:!0}),gn=Ke(([{scrollContainerState:t,scrollTo:s}])=>{const a=Be(),r=Be(),o=Be(),n=Z(!1),i=Z(void 0);return ge(K(ht(a,r),xe(([{scrollTop:l,viewportHeight:c},{offsetTop:d,listHeight:m}])=>({scrollHeight:m,scrollTop:Math.max(0,l-d),viewportHeight:c}))),t),ge(K(s,ze(r),xe(([l,{offsetTop:c}])=>({...l,top:l.top+c}))),o),{customScrollParent:i,useWindowScroll:n,windowScrollContainerState:a,windowScrollTo:o,windowViewportRect:r}},at(Dt)),Xd=Ke(([{sizeRanges:t,sizes:s},{headerHeight:a,scrollTop:r},{initialTopMostItemIndex:o},{didMount:n},{useWindowScroll:i,windowScrollContainerState:l,windowViewportRect:c}])=>{const d=Be(),m=Z(void 0),p=Z(null),h=Z(null);return ge(l,p),ge(c,h),Xe(K(d,ze(s,r,i,p,h,a)),([b,S,k,N,v,g,I])=>{const z=Ld(S.sizeTree);N&&v!==null&&g!==null&&(k=v.scrollTop-g.offsetTop),k-=I,b({ranges:z,scrollTop:k})}),ge(K(m,ke(cn),xe(Jd)),o),ge(K(n,ze(m),ke(([,b])=>b!==void 0),st(),xe(([,b])=>b.ranges)),t),{getState:d,restoreStateFrom:m}},at(fs,Dt,Da,Os,gn));function Jd(t){return{align:"start",index:0,offset:t.scrollTop}}const Zd=Ke(([{topItemsIndexes:t}])=>{const s=Z(0);return ge(K(s,ke(a=>a>=0),xe(a=>Array.from({length:a}).map((r,o)=>o))),t),{topItemCount:s}},at(Ks));function qi(t){let s=!1,a;return(()=>(s||(s=!0,a=t()),a))}const eu=qi(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),tu=Ke(([{deviation:t,scrollBy:s,scrollingInProgress:a,scrollTop:r},{isAtBottom:o,isScrolling:n,lastJumpDueToItemResize:i,scrollDirection:l},{listState:c},{beforeUnshiftWith:d,gap:m,shiftWithOffset:p,sizes:h},{log:b},{recalcInProgress:S}])=>{const k=Qt(K(c,ze(i),ds(([,v,g,I],[{bottom:z,items:R,offsetBottom:W,totalCount:f},C])=>{const w=z+W;let $=0;return g===f&&v.length>0&&R.length>0&&(R[0].originalIndex===0&&v[0].originalIndex===0||($=w-I,$!==0&&($+=C))),[$,R,f,w]},[0,[],0,0]),ke(([v])=>v!==0),ze(r,l,a,o,b,S),ke(([,v,g,I,,,z])=>!z&&!I&&v!==0&&g===Ra),xe(([[v],,,,,g])=>(g("Upward scrolling compensation",{amount:v},vt.DEBUG),v))));function N(v){v>0?(Ae(s,{behavior:"auto",top:-v}),Ae(t,0)):(Ae(t,0),Ae(s,{behavior:"auto",top:-v}))}return Xe(K(k,ze(t,n)),([v,g,I])=>{I&&eu()?Ae(t,g-v):N(-v)}),Xe(K(ht(Rt(n,!1),t,S),ke(([v,g,I])=>!v&&!I&&g!==0),xe(([v,g])=>g),Cs(1)),N),ge(K(p,xe(v=>({top:-v}))),s),Xe(K(d,ze(h,m),xe(([v,{groupIndices:g,lastSize:I,sizeTree:z},R])=>{function W(A){return A*(I+R)}if(g.length===0)return W(v);let f=0;const C=Ta(z,0);let w=0,$=0;for(;wv&&(f-=C,A=v-w+1),w+=A,f+=W(A),$++}return f})),v=>{Ae(t,v),requestAnimationFrame(()=>{Ae(s,{top:v}),requestAnimationFrame(()=>{Ae(t,0),Ae(S,!1)})})}),{deviation:t}},at(Dt,$a,Ks,fs,Fs,mn)),su=Ke(([t,s,a,r,o,n,i,l,c,d,m])=>({...t,...s,...a,...r,...o,...n,...i,...l,...c,...d,...m}),at(fn,Yd,Os,Wi,Gi,Kd,Qd,gn,Vi,Fs,Qi)),Yi=Ke(([{data:t,defaultItemSize:s,firstItemIndex:a,fixedItemSize:r,fixedGroupSize:o,gap:n,groupIndices:i,heightEstimates:l,itemSize:c,sizeRanges:d,sizes:m,statefulTotalCount:p,totalCount:h,trackItemSizes:b},{initialItemFinalLocationReached:S,initialTopMostItemIndex:k,scrolledToInitialItem:N},v,g,I,z,{scrollToIndex:R},W,{topItemCount:f},{groupCounts:C},w])=>{const{listState:$,minOverscanItemCount:A,topItemsIndexes:y,rangeChanged:q,...J}=z;return ge(q,w.scrollSeekRangeChanged),ge(K(w.windowViewportRect,xe(re=>re.visibleHeight)),v.viewportHeight),{data:t,defaultItemHeight:s,firstItemIndex:a,fixedItemHeight:r,fixedGroupHeight:o,gap:n,groupCounts:C,heightEstimates:l,initialItemFinalLocationReached:S,initialTopMostItemIndex:k,scrolledToInitialItem:N,sizeRanges:d,topItemCount:f,topItemsIndexes:y,totalCount:h,...I,groupIndices:i,itemSize:c,listState:$,minOverscanItemCount:A,scrollToIndex:R,statefulTotalCount:p,trackItemSizes:b,rangeChanged:q,...J,...w,...v,sizes:m,...g}},at(fs,Da,Dt,Xd,qd,Ks,za,tu,Zd,Pi,su));function au(t,s){const a={},r={};let o=0;const n=t.length;for(;o(v[g]=I=>{const z=N[s.methods[g]];Ae(z,I)},v),{})}function m(N){return i.reduce((v,g)=>(v[g]=vd(N[s.events[g]]),v),{})}const p=he.forwardRef(function(N,v){const{children:g,...I}=N,[z]=he.useState(()=>wr(Nd(t),f=>{c(f,I)})),[R]=he.useState(no(m,z));Qa(()=>{for(const f of i)f in I&&Xe(R[f],I[f]);return()=>{Object.values(R).map(dn)}},[I,R,z]),Qa(()=>{c(z,I)}),he.useImperativeHandle(v,ro(d(z)));const W=a;return e.jsx(l.Provider,{value:z,children:a!==void 0?e.jsx(W,{...au([...r,...o,...i],I),children:g}):g})}),h=N=>{const v=he.useContext(l);return he.useCallback(g=>{Ae(v[N],g)},[v,N])},b=N=>{const v=he.useContext(l)[N],g=he.useCallback(I=>Xe(v,I),[v]);return he.useSyncExternalStore(g,()=>ot(v),()=>ot(v))},S=N=>{const v=he.useContext(l)[N],[g,I]=he.useState(no(ot,v));return Qa(()=>Xe(v,z=>{z!==g&&I(ro(z))}),[v,g]),g},k=parseInt(he.version)>=18?b:S;return{Component:p,useEmitter:(N,v)=>{const g=he.useContext(l)[N];Qa(()=>Xe(g,v),[v,g])},useEmitterValue:k,usePublisher:h}}const Xi=he.createContext(void 0),Ji=he.createContext(void 0),Ar="-webkit-sticky",go="sticky",bn=qi(()=>{if(typeof document>"u")return go;const t=document.createElement("div");return t.style.position=Ar,t.style.position===Ar?Ar:go}),Zi=typeof document<"u"?he.useLayoutEffect:he.useEffect;function Lr(t){return"self"in t}function ru(t){return"body"in t}function el(t,s,a,r=ma,o,n){const i=he.useRef(null),l=he.useRef(null),c=he.useRef(null),d=he.useCallback(h=>{let b,S,k;const N=h.target;if(ru(N)||Lr(N)){const g=Lr(N)?N:N.defaultView;k=n===!0?g.scrollX:g.scrollY,b=n===!0?g.document.documentElement.scrollWidth:g.document.documentElement.scrollHeight,S=n===!0?g.innerWidth:g.innerHeight}else k=n===!0?N.scrollLeft:N.scrollTop,b=n===!0?N.scrollWidth:N.scrollHeight,S=n===!0?N.offsetWidth:N.offsetHeight;const v=()=>{t({scrollHeight:b,scrollTop:Math.max(k,0),viewportHeight:S})};h.suppressFlushSync===!0?v():Qr.flushSync(v),l.current!==null&&(k===l.current||k<=0||k===b-S)&&(l.current=null,s(!0),c.current&&(clearTimeout(c.current),c.current=null))},[t,s,n]);he.useEffect(()=>{const h=o||i.current;return r(o||i.current),d({suppressFlushSync:!0,target:h}),h.addEventListener("scroll",d,{passive:!0}),()=>{r(null),h.removeEventListener("scroll",d)}},[i,d,a,r,o]);function m(h){const b=i.current;if(!b||(n===!0?"offsetWidth"in b&&b.offsetWidth===0:"offsetHeight"in b&&b.offsetHeight===0))return;const S=h.behavior==="smooth";let k,N,v;Lr(b)?(N=Math.max(Ds(b.document.documentElement,n===!0?"width":"height"),n===!0?b.document.documentElement.scrollWidth:b.document.documentElement.scrollHeight),k=n===!0?b.innerWidth:b.innerHeight,v=n===!0?window.scrollX:window.scrollY):(N=b[n===!0?"scrollWidth":"scrollHeight"],k=Ds(b,n===!0?"width":"height"),v=b[n===!0?"scrollLeft":"scrollTop"]);const g=N-k;if(h.top=Math.ceil(Math.max(Math.min(g,h.top),0)),Hi(k,N)||h.top===v){t({scrollHeight:N,scrollTop:v,viewportHeight:k}),S&&s(!0);return}S?(l.current=h.top,c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{c.current=null,l.current=null,s(!0)},1e3)):l.current=null,n===!0&&(h={...h.behavior!==void 0?{behavior:h.behavior}:{},left:h.top}),b.scrollTo(h)}function p(h){n===!0&&(h={...h.behavior!==void 0?{behavior:h.behavior}:{},...h.top!==void 0?{left:h.top}:{}}),i.current.scrollBy(h)}return{scrollByCallback:p,scrollerRef:i,scrollToCallback:m}}function vn(t){return t}const nu=Ke(()=>{const t=Z(l=>`Item ${l}`),s=Z(l=>`Group ${l}`),a=Z({}),r=Z(vn),o=Z("div"),n=Z(ma),i=(l,c=null)=>Rt(K(a,xe(d=>d[l]),st()),c);return{components:a,computeItemKey:r,EmptyPlaceholder:i("EmptyPlaceholder"),FooterComponent:i("Footer"),GroupComponent:i("Group","div"),groupContent:s,HeaderComponent:i("Header"),HeaderFooterTag:o,ItemComponent:i("Item","div"),itemContent:t,ListComponent:i("List","div"),ScrollerComponent:i("Scroller","div"),scrollerRef:n,ScrollSeekPlaceholder:i("ScrollSeekPlaceholder"),TopItemListComponent:i("TopItemList")}}),ou=Ke(([t,s])=>({...t,...s}),at(Yi,nu)),iu=({height:t})=>e.jsx("div",{style:{height:t}}),lu={overflowAnchor:"none",position:bn(),zIndex:1},tl={overflowAnchor:"none"},cu={...tl,display:"inline-block",height:"100%"},bo=he.memo(function({showTopList:t=!1}){const s=Te("listState"),a=qt("sizeRanges"),r=Te("useWindowScroll"),o=Te("customScrollParent"),n=qt("windowScrollContainerState"),i=qt("scrollContainerState"),l=o||r?n:i,c=Te("itemContent"),d=Te("context"),m=Te("groupContent"),p=Te("trackItemSizes"),h=Te("itemSize"),b=Te("log"),S=qt("gap"),k=Te("horizontalDirection"),{callbackRef:N}=Sd(a,h,p,t?ma:l,b,S,o,k,Te("skipAnimationFrameInResizeObserver")),[v,g]=he.useState(0);Nn("deviation",J=>{v!==J&&g(J)});const I=Te("EmptyPlaceholder"),z=Te("ScrollSeekPlaceholder")??iu,R=Te("ListComponent"),W=Te("ItemComponent"),f=Te("GroupComponent"),C=Te("computeItemKey"),w=Te("isSeeking"),$=Te("groupIndices").length>0,A=Te("alignToBottom"),y=Te("initialItemFinalLocationReached"),q=t?{}:{boxSizing:"border-box",...k?{display:"inline-block",height:"100%",marginLeft:v!==0?v:A?"auto":0,paddingLeft:s.offsetTop,paddingRight:s.offsetBottom,whiteSpace:"nowrap"}:{marginTop:v!==0?v:A?"auto":0,paddingBottom:s.offsetBottom,paddingTop:s.offsetTop},...y?{}:{visibility:"hidden"}};return!t&&s.totalCount===0&&I!==null&&I!==void 0?e.jsx(I,{..._t(I,d)}):e.jsx(R,{..._t(R,d),"data-testid":t?"virtuoso-top-item-list":"virtuoso-item-list",ref:N,style:q,children:(t?s.topItems:s.items).map(J=>{const re=J.originalIndex,le=C(re+s.firstItemIndex,J.data,d);return w?u.createElement(z,{..._t(z,d),height:J.size,index:J.index,key:le,type:J.type||"item",...J.type==="group"?{}:{groupIndex:J.groupIndex}}):J.type==="group"?u.createElement(f,{..._t(f,d),"data-index":re,"data-item-index":J.index,"data-known-size":J.size,key:le,style:lu},m(J.index,d)):u.createElement(W,{..._t(W,d),...xu(W,J.data),"data-index":re,"data-item-group-index":J.groupIndex,"data-item-index":J.index,"data-known-size":J.size,key:le,style:k?cu:tl},$?c(J.index,J.groupIndex,J.data,d):c(J.index,J.data,d))})})}),du={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},uu={outline:"none",overflowX:"auto",position:"relative"},wn=t=>({height:"100%",position:"absolute",top:0,width:"100%",...t?{display:"flex",flexDirection:"column"}:void 0}),sl=(t,s,a=0)=>({...wn(t),position:s?"relative":"absolute",top:s?-a:0}),mu={position:bn(),top:0,width:"100%",zIndex:1};function _t(t,s){if(typeof t!="string")return{context:s}}function xu(t,s){return{item:typeof t=="string"?void 0:s}}const pu=he.memo(function(){const t=Te("HeaderComponent"),s=qt("headerHeight"),a=Te("HeaderFooterTag"),r=Ys(he.useMemo(()=>n=>{s(Ds(n,"height"))},[s]),!0,Te("skipAnimationFrameInResizeObserver")),o=Te("context");return t!=null?e.jsx(a,{ref:r,children:e.jsx(t,{..._t(t,o)})}):null}),hu=he.memo(function(){const t=Te("FooterComponent"),s=qt("footerHeight"),a=Te("HeaderFooterTag"),r=Ys(he.useMemo(()=>n=>{s(Ds(n,"height"))},[s]),!0,Te("skipAnimationFrameInResizeObserver")),o=Te("context");return t!=null?e.jsx(a,{ref:r,children:e.jsx(t,{..._t(t,o)})}):null});function al({useEmitter:t,useEmitterValue:s,usePublisher:a}){return he.memo(function({children:r,style:o,context:n,...i}){const l=a("scrollContainerState"),c=s("ScrollerComponent"),d=a("smoothScrollTargetReached"),m=s("scrollerRef"),p=s("horizontalDirection")||!1,{scrollByCallback:h,scrollerRef:b,scrollToCallback:S}=el(l,d,c,m,void 0,p);return t("scrollTo",S),t("scrollBy",h),e.jsx(c,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:b,style:{...p?uu:du,...o},tabIndex:0,...i,..._t(c,n),children:r})})}function rl({useEmitter:t,useEmitterValue:s,usePublisher:a}){return he.memo(function({children:r,style:o,context:n,...i}){const l=a("windowScrollContainerState"),c=s("ScrollerComponent"),d=a("smoothScrollTargetReached"),m=s("totalListHeight"),p=s("deviation"),h=s("customScrollParent"),b=he.useRef(null),S=s("scrollerRef"),{scrollByCallback:k,scrollerRef:N,scrollToCallback:v}=el(l,d,c,S,h);return Zi(()=>(N.current=h||b.current?.ownerDocument.defaultView,()=>{N.current=null}),[N,h]),t("windowScrollTo",v),t("scrollBy",k),e.jsx(c,{ref:b,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...m!==0?{height:m+p}:void 0},...i,..._t(c,n),children:r})})}const fu=({children:t})=>{const s=he.useContext(Xi),a=qt("viewportHeight"),r=qt("fixedItemHeight"),o=Te("alignToBottom"),n=Te("horizontalDirection"),i=he.useMemo(()=>Ti(a,c=>Ds(c,n?"width":"height")),[a,n]),l=Ys(i,!0,Te("skipAnimationFrameInResizeObserver"));return he.useEffect(()=>{s&&(a(s.viewportHeight),r(s.itemHeight))},[s,a,r]),e.jsx("div",{"data-viewport-type":"element",ref:l,style:wn(o),children:t})},gu=({children:t})=>{const s=he.useContext(Xi),a=qt("windowViewportRect"),r=qt("fixedItemHeight"),o=Te("customScrollParent"),n=Te("useWindowScroll"),i=Te("topListHeight"),l=Ei(a,o,Te("skipAnimationFrameInResizeObserver")),c=Te("alignToBottom");return he.useEffect(()=>{s&&(r(s.itemHeight),a({listHeight:0,offsetTop:0,visibleHeight:s.viewportHeight,visibleWidth:100}))},[s,a,r]),e.jsx("div",{"data-viewport-type":"window",ref:l,style:sl(c,n,i),children:t})},bu=({children:t})=>{const s=Te("TopItemListComponent")??"div",a=Te("headerHeight"),r={...mu,marginTop:`${a}px`},o=Te("context");return e.jsx(s,{style:r,..._t(s,o),children:t})},vu=he.memo(function(t){const s=Te("useWindowScroll"),a=Te("topItemsIndexes").length>0,r=Te("customScrollParent"),o=Te("context");return e.jsxs(r||s?ju:Nu,{...t,context:o,children:[a&&e.jsx(bu,{children:e.jsx(bo,{showTopList:!0})}),e.jsxs(r||s?gu:fu,{children:[e.jsx(pu,{}),e.jsx(bo,{}),e.jsx(hu,{})]})]})}),{Component:wu,useEmitter:Nn,useEmitterValue:Te,usePublisher:qt}=Ki(ou,{optional:{restoreStateFrom:"restoreStateFrom",context:"context",followOutput:"followOutput",scrollIntoViewOnChange:"scrollIntoViewOnChange",itemContent:"itemContent",groupContent:"groupContent",overscan:"overscan",increaseViewportBy:"increaseViewportBy",minOverscanItemCount:"minOverscanItemCount",totalCount:"totalCount",groupCounts:"groupCounts",topItemCount:"topItemCount",firstItemIndex:"firstItemIndex",initialTopMostItemIndex:"initialTopMostItemIndex",components:"components",atBottomThreshold:"atBottomThreshold",atTopThreshold:"atTopThreshold",computeItemKey:"computeItemKey",defaultItemHeight:"defaultItemHeight",fixedGroupHeight:"fixedGroupHeight",fixedItemHeight:"fixedItemHeight",heightEstimates:"heightEstimates",itemSize:"itemSize",scrollSeekConfiguration:"scrollSeekConfiguration",headerFooterTag:"HeaderFooterTag",data:"data",initialItemCount:"initialItemCount",initialScrollTop:"initialScrollTop",alignToBottom:"alignToBottom",useWindowScroll:"useWindowScroll",customScrollParent:"customScrollParent",scrollerRef:"scrollerRef",logLevel:"logLevel",horizontalDirection:"horizontalDirection",skipAnimationFrameInResizeObserver:"skipAnimationFrameInResizeObserver"},methods:{scrollToIndex:"scrollToIndex",scrollIntoView:"scrollIntoView",scrollTo:"scrollTo",scrollBy:"scrollBy",autoscrollToBottom:"autoscrollToBottom",getState:"getState"},events:{isScrolling:"isScrolling",endReached:"endReached",startReached:"startReached",rangeChanged:"rangeChanged",atBottomStateChange:"atBottomStateChange",atTopStateChange:"atTopStateChange",totalListHeightChanged:"totalListHeightChanged",itemsRendered:"itemsRendered",groupIndices:"groupIndices"}},vu),Nu=al({useEmitter:Nn,useEmitterValue:Te,usePublisher:qt}),ju=rl({useEmitter:Nn,useEmitterValue:Te,usePublisher:qt}),yu=wu,Su=Ke(()=>{const t=Z(d=>e.jsxs("td",{children:["Item $",d]})),s=Z(null),a=Z(d=>e.jsxs("td",{colSpan:1e3,children:["Group ",d]})),r=Z(null),o=Z(null),n=Z({}),i=Z(vn),l=Z(ma),c=(d,m=null)=>Rt(K(n,xe(p=>p[d]),st()),m);return{components:n,computeItemKey:i,context:s,EmptyPlaceholder:c("EmptyPlaceholder"),FillerRow:c("FillerRow"),fixedFooterContent:o,fixedHeaderContent:r,itemContent:t,groupContent:a,ScrollerComponent:c("Scroller","div"),scrollerRef:l,ScrollSeekPlaceholder:c("ScrollSeekPlaceholder"),TableBodyComponent:c("TableBody","tbody"),TableComponent:c("Table","table"),TableFooterComponent:c("TableFoot","tfoot"),TableHeadComponent:c("TableHead","thead"),TableRowComponent:c("TableRow","tr"),GroupComponent:c("Group","tr")}});at(Yi,Su);bn();const vo={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},ku={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:wo,floor:xr,max:ka,min:zr,round:No}=Math;function jo(t,s,a){return Array.from({length:s-t+1}).map((r,o)=>({data:a===null?null:a[o+t],index:o+t}))}function Cu(t){return{...ku,items:t}}function Va(t,s){return t!==void 0&&t.width===s.width&&t.height===s.height}function Iu(t,s){return t!==void 0&&t.column===s.column&&t.row===s.row}const Tu=Ke(([{increaseViewportBy:t,listBoundary:s,overscan:a,visibleRange:r},{footerHeight:o,headerHeight:n,scrollBy:i,scrollContainerState:l,scrollTo:c,scrollTop:d,smoothScrollTargetReached:m,viewportHeight:p},h,b,{didMount:S,propsReady:k},{customScrollParent:N,useWindowScroll:v,windowScrollContainerState:g,windowScrollTo:I,windowViewportRect:z},R])=>{const W=Z(0),f=Z(0),C=Z(vo),w=Z({height:0,width:0}),$=Z({height:0,width:0}),A=Be(),y=Be(),q=Z(0),J=Z(null),re=Z({column:0,row:0}),le=Be(),ne=Be(),be=Z(!1),Ie=Z(0),de=Z(!0),fe=Z(!1),H=Z(!1);Xe(K(S,ze(Ie),ke(([G,te])=>te!==0)),()=>{Ae(de,!1)}),Xe(K(ht(S,de,$,w,Ie,fe),ke(([G,te,E,Y,,V])=>G&&!te&&E.height!==0&&Y.height!==0&&!V)),([,,,,G])=>{Ae(fe,!0),pn(1,()=>{Ae(A,G)}),ss(K(d),()=>{Ae(s,[0,0]),Ae(de,!0)})}),ge(K(ne,ke(G=>G!=null&&G.scrollTop>0),ls(0)),f),Xe(K(S,ze(ne),ke(([,G])=>G!=null)),([,G])=>{G&&(Ae(w,G.viewport),Ae($,G.item),Ae(re,G.gap),G.scrollTop>0&&(Ae(be,!0),ss(K(d,Ws(1)),te=>{Ae(be,!1)}),Ae(c,{top:G.scrollTop})))}),ge(K(w,xe(({height:G})=>G)),p),ge(K(ht(Se(w,Va),Se($,Va),Se(re,(G,te)=>G!==void 0&&G.column===te.column&&G.row===te.row),Se(d)),xe(([G,te,E,Y])=>({gap:E,item:te,scrollTop:Y,viewport:G}))),le),ge(K(ht(Se(W),r,Se(re,Iu),Se($,Va),Se(w,Va),Se(J),Se(f),Se(be),Se(de),Se(Ie)),ke(([,,,,,,,G])=>!G),xe(([G,[te,E],Y,V,pe,D,j,,_,T])=>{const{column:Q,row:ue}=Y,{height:ce,width:ae}=V,{width:Ce}=pe;if(j===0&&(G===0||Ce===0))return vo;if(ae===0){const Lt=hn(T,G),rs=Lt+Math.max(j-1,0);return Cu(jo(Lt,rs,D))}const Ne=nl(Ce,ae,Q);let Je,$e;_?te===0&&E===0&&j>0?(Je=0,$e=j-1):(Je=Ne*xr((te+ue)/(ce+ue)),$e=Ne*wo((E+ue)/(ce+ue))-1,$e=zr(G-1,ka($e,Ne-1)),Je=zr($e,ka(0,Je))):(Je=0,$e=-1);const Ge=jo(Je,$e,D),{bottom:ft,top:Nt}=yo(pe,Y,V,Ge),dt=wo(G/Ne),jt=dt*ce+(dt-1)*ue-ft;return{bottom:ft,itemHeight:ce,items:Ge,itemWidth:ae,offsetBottom:jt,offsetTop:Nt,top:Nt}})),C),ge(K(J,ke(G=>G!==null),xe(G=>G.length)),W),ge(K(ht(w,$,C,re),ke(([G,te,{items:E}])=>E.length>0&&te.height!==0&&G.height!==0),xe(([G,te,{items:E},Y])=>{const{bottom:V,top:pe}=yo(G,Y,te,E);return[pe,V]}),st(_a)),s);const ee=Z(!1);ge(K(d,ze(ee),xe(([G,te])=>te||G!==0)),ee);const oe=Qt(K(ht(C,W),ke(([{items:G}])=>G.length>0),ze(ee),ke(([[G,te],E])=>{const Y=G.items[G.items.length-1].index===te-1;return(E||G.bottom>0&&G.itemHeight>0&&G.offsetBottom===0&&G.items.length===te)&&Y}),xe(([[,G]])=>G-1),st())),Re=Qt(K(Se(C),ke(({items:G})=>G.length>0&&G[0].index===0),ls(0),st())),Fe=Qt(K(Se(C),ze(be),ke(([{items:G},te])=>G.length>0&&!te),xe(([{items:G}])=>({endIndex:G[G.length-1].index,startIndex:G[0].index})),st(Di),Cs(0)));ge(Fe,b.scrollSeekRangeChanged),ge(K(A,ze(w,$,W,re),xe(([G,te,E,Y,V])=>{const pe=Bi(G),{align:D,behavior:j,offset:_}=pe;let T=pe.index;T==="LAST"&&(T=Y-1),T=ka(0,T,zr(Y-1,T));let Q=an(te,V,E,T);return D==="end"?Q=No(Q-te.height+E.height):D==="center"&&(Q=No(Q-te.height/2+E.height/2)),_!==void 0&&_!==0&&(Q+=_),{behavior:j,top:Q}})),c);const Pe=Rt(K(C,xe(G=>G.offsetBottom+G.bottom)),0);return ge(K(z,xe(G=>({height:G.visibleHeight,width:G.visibleWidth}))),w),{customScrollParent:N,data:J,deviation:q,footerHeight:o,gap:re,headerHeight:n,increaseViewportBy:t,initialItemCount:f,itemDimensions:$,overscan:a,restoreStateFrom:ne,scrollBy:i,scrollContainerState:l,scrollHeight:y,scrollTo:c,scrollToIndex:A,scrollTop:d,smoothScrollTargetReached:m,totalCount:W,useWindowScroll:v,viewportDimensions:w,windowScrollContainerState:g,windowScrollTo:I,windowViewportRect:z,...b,gridState:C,horizontalDirection:H,initialTopMostItemIndex:Ie,totalListHeight:Pe,...h,endReached:oe,propsReady:k,rangeChanged:Fe,startReached:Re,stateChanged:le,stateRestoreInProgress:be,...R}},at(fn,Dt,$a,Wi,Os,gn,Fs));function nl(t,s,a){return ka(1,xr((t+a)/(xr(s)+a)))}function yo(t,s,a,r){const{height:o}=a;if(o===void 0||r.length===0)return{bottom:0,top:0};const n=an(t,s,a,r[0].index);return{bottom:an(t,s,a,r[r.length-1].index)+o,top:n}}function an(t,s,a,r){const o=nl(t.width,a.width,s.column),n=xr(r/o),i=n*a.height+ka(0,n-1)*s.row;return i>0?i+s.row:i}const _u=Ke(()=>{const t=Z(p=>`Item ${p}`),s=Z({}),a=Z(null),r=Z("virtuoso-grid-item"),o=Z("virtuoso-grid-list"),n=Z(vn),i=Z("div"),l=Z(ma),c=(p,h=null)=>Rt(K(s,xe(b=>b[p]),st()),h),d=Z(!1),m=Z(!1);return ge(Se(m),d),{components:s,computeItemKey:n,context:a,FooterComponent:c("Footer"),HeaderComponent:c("Header"),headerFooterTag:i,itemClassName:r,ItemComponent:c("Item","div"),itemContent:t,listClassName:o,ListComponent:c("List","div"),readyStateChanged:d,reportReadyState:m,ScrollerComponent:c("Scroller","div"),scrollerRef:l,ScrollSeekPlaceholder:c("ScrollSeekPlaceholder","div")}}),Eu=Ke(([t,s])=>({...t,...s}),at(Tu,_u)),Ru=he.memo(function(){const t=tt("gridState"),s=tt("listClassName"),a=tt("itemClassName"),r=tt("itemContent"),o=tt("computeItemKey"),n=tt("isSeeking"),i=Yt("scrollHeight"),l=tt("ItemComponent"),c=tt("ListComponent"),d=tt("ScrollSeekPlaceholder"),m=tt("context"),p=Yt("itemDimensions"),h=Yt("gap"),b=tt("log"),S=tt("stateRestoreInProgress"),k=Yt("reportReadyState"),N=Ys(he.useMemo(()=>v=>{const g=v.parentElement.parentElement.scrollHeight;i(g);const I=v.firstChild;if(I!==null){const{height:z,width:R}=I.getBoundingClientRect();p({height:z,width:R})}h({column:So("column-gap",getComputedStyle(v).columnGap,b),row:So("row-gap",getComputedStyle(v).rowGap,b)})},[i,p,h,b]),!0,!1);return Zi(()=>{t.itemHeight>0&&t.itemWidth>0&&k(!0)},[t]),S?null:e.jsx(c,{className:s,ref:N,..._t(c,m),"data-testid":"virtuoso-item-list",style:{paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},children:t.items.map(v=>{const g=o(v.index,v.data,m);return n?e.jsx(d,{..._t(d,m),height:t.itemHeight,index:v.index,width:t.itemWidth},g):u.createElement(l,{..._t(l,m),className:a,"data-index":v.index,key:g},r(v.index,v.data,m))})})}),Mu=he.memo(function(){const t=tt("HeaderComponent"),s=Yt("headerHeight"),a=tt("headerFooterTag"),r=Ys(he.useMemo(()=>n=>{s(Ds(n,"height"))},[s]),!0,!1),o=tt("context");return t!=null?e.jsx(a,{ref:r,children:e.jsx(t,{..._t(t,o)})}):null}),Au=he.memo(function(){const t=tt("FooterComponent"),s=Yt("footerHeight"),a=tt("headerFooterTag"),r=Ys(he.useMemo(()=>n=>{s(Ds(n,"height"))},[s]),!0,!1),o=tt("context");return t!=null?e.jsx(a,{ref:r,children:e.jsx(t,{..._t(t,o)})}):null}),Lu=({children:t})=>{const s=he.useContext(Ji),a=Yt("itemDimensions"),r=Yt("viewportDimensions"),o=Ys(he.useMemo(()=>n=>{r(n.getBoundingClientRect())},[r]),!0,!1);return he.useEffect(()=>{s&&(r({height:s.viewportHeight,width:s.viewportWidth}),a({height:s.itemHeight,width:s.itemWidth}))},[s,r,a]),e.jsx("div",{ref:o,style:wn(!1),children:t})},zu=({children:t})=>{const s=he.useContext(Ji),a=Yt("windowViewportRect"),r=Yt("itemDimensions"),o=tt("customScrollParent"),n=tt("useWindowScroll"),i=Ei(a,o,!1);return he.useEffect(()=>{s&&(r({height:s.itemHeight,width:s.itemWidth}),a({listHeight:0,offsetTop:0,visibleHeight:s.viewportHeight,visibleWidth:s.viewportWidth}))},[s,a,r]),e.jsx("div",{ref:i,style:sl(!1,n),children:t})},Du=he.memo(function({...t}){const s=tt("useWindowScroll"),a=tt("customScrollParent"),r=a||s?Fu:$u,o=a||s?zu:Lu,n=tt("context");return e.jsx(r,{...t,..._t(r,n),children:e.jsxs(o,{children:[e.jsx(Mu,{}),e.jsx(Ru,{}),e.jsx(Au,{})]})})}),{useEmitter:ol,useEmitterValue:tt,usePublisher:Yt}=Ki(Eu,{optional:{context:"context",totalCount:"totalCount",overscan:"overscan",itemContent:"itemContent",components:"components",computeItemKey:"computeItemKey",data:"data",initialItemCount:"initialItemCount",scrollSeekConfiguration:"scrollSeekConfiguration",headerFooterTag:"headerFooterTag",listClassName:"listClassName",itemClassName:"itemClassName",useWindowScroll:"useWindowScroll",customScrollParent:"customScrollParent",scrollerRef:"scrollerRef",logLevel:"logLevel",restoreStateFrom:"restoreStateFrom",initialTopMostItemIndex:"initialTopMostItemIndex",increaseViewportBy:"increaseViewportBy"},methods:{scrollTo:"scrollTo",scrollBy:"scrollBy",scrollToIndex:"scrollToIndex"},events:{isScrolling:"isScrolling",endReached:"endReached",startReached:"startReached",rangeChanged:"rangeChanged",atBottomStateChange:"atBottomStateChange",atTopStateChange:"atTopStateChange",stateChanged:"stateChanged",readyStateChanged:"readyStateChanged"}},Du),$u=al({useEmitter:ol,useEmitterValue:tt,usePublisher:Yt}),Fu=rl({useEmitter:ol,useEmitterValue:tt,usePublisher:Yt});function So(t,s,a){return s!=="normal"&&s?.endsWith("px")!==!0&&a(`${t} was not resolved to pixel value correctly`,s,vt.WARN),s==="normal"?0:parseInt(s??"0",10)}function ko(t){if(Array.isArray(t)){if(t.length<5||t.length>6)throw new Error(`Invalid bone format: expected [x,y,w,h,r,c?] but got ${t.length} elements`);const s=t;return{x:s[0],y:s[1],w:s[2],h:s[3],r:s[4],c:s[5]||void 0}}return t}const Co=new Set(["p","h1","h2","h3","h4","h5","h6","li","td","th"]);function Ou(t,s="component",a){const r=t.getBoundingClientRect(),o=[],n=a?.leafTags?new Set([...Co,...a.leafTags]):Co,i=a?.captureRoundedBorders??!0,l=a?.excludeTags?new Set(a.excludeTags):null,c=a?.excludeSelectors??null;function d(m){const p=getComputedStyle(m);if(p.display==="none"||p.visibility==="hidden"||p.opacity==="0")return;const h=m.tagName.toLowerCase();if(l?.has(h)||c?.some(w=>m.matches(w)))return;const b=[...m.children].filter(w=>{const $=getComputedStyle(w);return $.display!=="none"&&$.visibility!=="hidden"&&$.opacity!=="0"}),S=h==="img"||h==="svg"||h==="video"||h==="canvas",k=h==="input"||h==="button"||h==="textarea"||h==="select",N=b.length===0||S||k||n.has(h),v=p.backgroundColor,g=v!=="rgba(0, 0, 0, 0)"&&v!=="transparent",I=p.backgroundImage!=="none",z=parseFloat(p.borderTopWidth)||0,R=i&&z>0&&p.borderTopColor!=="rgba(0, 0, 0, 0)"&&p.borderTopColor!=="transparent",W=(parseFloat(p.borderTopLeftRadius)||0)>0,f=g||I||R&&W,C=h==="tr"||h==="td"||h==="th"||h==="thead"||h==="tbody"||h==="table";if(N){const w=m.getBoundingClientRect();if(w.width<1||w.height<1)return;const $=S&&w.width>0&&w.height>0&&Math.abs(w.width-w.height)<4,A=C?0:$?"50%":Io(p,m)??8,y=r.width;o.push({x:y>0?+((w.left-r.left)/y*100).toFixed(4):0,y:Math.round(w.top-r.top),w:y>0?+(w.width/y*100).toFixed(4):0,h:Math.round(w.height),r:A});return}if(f){const w=m.getBoundingClientRect();if(w.width>=1&&w.height>=1){const $=C?0:Io(p,m)??8,A=r.width;o.push({x:A>0?+((w.left-r.left)/A*100).toFixed(4):0,y:Math.round(w.top-r.top),w:A>0?+(w.width/A*100).toFixed(4):0,h:Math.round(w.height),r:$,c:!0})}}for(const w of b)d(w)}for(const m of t.children)d(m);return{name:s,viewportWidth:Math.round(r.width),width:Math.round(r.width),height:Math.round(r.height),bones:o}}function Io(t,s){const a=parseFloat(t.borderTopLeftRadius)||0,r=parseFloat(t.borderTopRightRadius)||0,o=parseFloat(t.borderBottomRightRadius)||0,n=parseFloat(t.borderBottomLeftRadius)||0;if(a===0&&r===0&&o===0&&n===0)return;const i=s?(()=>{const d=s.getBoundingClientRect();return d.width>0&&d.height>0&&Math.abs(d.width-d.height)<4})():!1;return t.borderRadius==="50%"?"50%":Math.max(a,r,o,n)>9998?i?"50%":9999:a===r&&r===o&&o===n?a!==8?a:void 0:`${a}px ${r}px ${o}px ${n}px`}const Pu=new Map;function Bu(t){return Pu.get(t)}function Hu(){typeof window<"u"&&window.__BONEYARD_BUILD&&(window.__BONEYARD_SNAPSHOT=Ou)}function Uu(){return typeof window<"u"&&window.__BONEYARD_BUILD===!0}function Gu(t,s){if(!("breakpoints"in t))return t;const a=Object.keys(t.breakpoints).map(Number).sort((o,n)=>o-n);if(a.length===0)return null;const r=[...a].reverse().find(o=>s>=o)??a[0];return t.breakpoints[r]??null}const ea={angle:110,start:30,end:70,speed:"2s",lightHighlight:"#f7f7f7",darkHighlight:"#2c2c2c"},ba={speed:"1.8s",lightAdjust:.3,darkAdjust:.02},To={web:{light:"#f0f0f0",dark:"#222222"}},Qu=/rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*(?:,\s*([\d.]+))?\s*\)/;function _o(t,s){const a=t.match(Qu);if(a){const[,r,o,n,i="1"]=a,l=Math.min(1,parseFloat(i)+s*.5);return`rgba(${r},${o},${n},${l.toFixed(3)})`}if(t.startsWith("#")&&t.length>=7){const r=parseInt(t.slice(1,3),16),o=parseInt(t.slice(3,5),16),n=parseInt(t.slice(5,7),16);if(!isNaN(r)&&!isNaN(o)&&!isNaN(n)){const i=Math.round(r+(255-r)*s),l=Math.round(o+(255-o)*s),c=Math.round(n+(255-n)*s);return`#${i.toString(16).padStart(2,"0")}${l.toString(16).padStart(2,"0")}${c.toString(16).padStart(2,"0")}`}}return t}Hu();let is={};function Eo({loading:t,children:s,name:a,initialBones:r,color:o,darkColor:n,animate:i,stagger:l=!1,transition:c=!1,boneClass:d,className:m,fallback:p,fixture:h,snapshotConfig:b}){const S=u.useRef(null),k=u.useRef(Math.random().toString(36).slice(2,8)).current,[N,v]=u.useState(0),[g,I]=u.useState(0),[z,R]=u.useState(!1);u.useEffect(()=>{if(typeof window>"u")return;const E=()=>{const pe=document.documentElement.classList.contains("dark")||!!S.current?.closest(".dark");R(pe)};E();const Y=new MutationObserver(E);Y.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]});const V=window.matchMedia("(prefers-color-scheme: dark)");return V.addEventListener("change",E),()=>{Y.disconnect(),V.removeEventListener("change",E)}},[]);const W=o??is.color??To.web.light,f=n??is.darkColor??To.web.dark,C=z?f:W,w=i??is.animate??"pulse",$=w===!0?"pulse":w===!1?"solid":w;u.useEffect(()=>{const E=S.current;if(!E)return;const Y=new ResizeObserver(pe=>{const D=pe[0]?.contentRect;v(Math.round(D?.width??0)),D&&D.height>0&&I(Math.round(D.height))});Y.observe(E);const V=E.getBoundingClientRect();return v(Math.round(V.width)),V.height>0&&I(Math.round(V.height)),()=>Y.disconnect()},[]);const A={};if(a&&(A["data-boneyard"]=a,b&&(A["data-boneyard-config"]=JSON.stringify(b))),Uu())return e.jsx("div",{ref:S,className:m,style:{position:"relative"},...A,children:e.jsx("div",{children:h??s})});const[y,q]=u.useState(!1);u.useLayoutEffect(()=>{q(!0)},[]);const J=r??(a?Bu(a):void 0),re=y&&typeof window<"u"?window.innerWidth:0,le=N>0?N:re,ne=J&&le>0?Gu(J,le):null,be=d??is.boneClass,Ie=(()=>{const E=l??is.stagger;return E===!0?80:E===!1||!E?0:E})(),de=(()=>{const E=c??is.transition;return E===!0?300:E===!1||!E?0:E})(),[fe,H]=u.useState(!1),ee=u.useRef(t),oe=u.useRef(null);u.useEffect(()=>(ee.current&&!t&&de>0&&ne&&(oe.current&&clearTimeout(oe.current),H(!0),oe.current=setTimeout(()=>{H(!1),oe.current=null},de)),ee.current=t,()=>{oe.current&&clearTimeout(oe.current)}),[t,de,ne]);const Re=(t||fe)&&ne,Fe=t&&!ne&&!fe,Pe=g>0?g:ne?.height??0,G=ne?.height??0,te=Pe>0&&G>0?Pe/G:1;return e.jsxs("div",{ref:S,className:m,style:{position:"relative"},...A,children:[e.jsx("div",{"data-boneyard-content":"true",style:Re&&!fe?{visibility:"hidden"}:void 0,children:Fe?p:s}),Re&&e.jsx("div",{"data-boneyard-overlay":"true",style:{position:"absolute",inset:0,overflow:"hidden",opacity:fe?0:1,transition:de>0?`opacity ${de}ms ease-out`:void 0},children:e.jsxs("div",{style:{position:"relative",width:"100%",height:"100%"},children:[ne.bones.filter(E=>!ko(E).c).map((E,Y)=>{const V=ko(E),pe=C;_o(C,z?ba.darkAdjust:ba.lightAdjust);const D=V.w/100*(ne.width??0),j=V.r==="50%"&&Math.abs(D-V.h)<4,_={position:"absolute",left:`${V.x}%`,top:V.y*te,width:j?V.h*te:`${V.w}%`,height:V.h*te,borderRadius:typeof V.r=="string"?V.r:`${V.r}px`,backgroundColor:pe},T=is.speed;if($==="pulse")_.animation=`bp-${k} ${T??ba.speed} ease-in-out infinite`;else if($==="shimmer"){const Q=z?is.darkShimmerColor??ea.darkHighlight:is.shimmerColor??ea.lightHighlight,ue=is.shimmerAngle??ea.angle;delete _.backgroundColor,_.backgroundImage=`linear-gradient(${ue}deg, ${pe} ${ea.start}%, ${Q} 50%, ${pe} ${ea.end}%)`,_.backgroundSize="200% 100%",_.animation=`bs-${k} ${T??ea.speed} linear infinite`}return Ie>0&&(_.opacity=0,_.animation=`${_.animation?_.animation+",":""} by-${k} 0.3s ease-out ${Y*Ie}ms forwards`),e.jsx("div",{"data-boneyard-bone":"true",className:be,style:_},Y)}),$==="pulse"&&e.jsx("style",{children:`@keyframes bp-${k}{0%,100%{background-color:${C}}50%{background-color:${_o(C,z?ba.darkAdjust:ba.lightAdjust)}}}`}),$==="shimmer"&&e.jsx("style",{children:`@keyframes bs-${k}{0%{background-position:200% 0}100%{background-position:-200% 0}}`}),Ie>0&&e.jsx("style",{children:`@keyframes by-${k}{from{opacity:0}to{opacity:1}}`})]})})]})}async function jn(t){const s=Mt(He,"managedStudents");try{const n=At(s,Et("teacherId","==",t)),i=await Ot(n);if(!i.empty)return i.docs.map(c=>({id:c.id,...c.data()})).sort((c,d)=>String(c.name||"").localeCompare(String(d.name||"")))}catch{}const r=(await ll(t)).map(n=>n.id);if(r.length===0)return[];const o=new Map;for(let n=0;n{o.set(d.id,{id:d.id,...d.data()})})}return Array.from(o.values()).sort((n,i)=>String(n.name||"").localeCompare(String(i.name||"")))}async function Vu(t,s=[]){if(!t)return[];const a=Mt(He,"users"),r=new Map,o=(i,l)=>String(l.role||"").toLowerCase()!=="student"?null:{uid:i,name:String(l.name||l.displayName||"").trim()||"Student",email:String(l.email||"").trim(),lrn:l.lrn&&String(l.lrn).trim()||void 0,photo:l.photo?String(l.photo).trim()||void 0:l.photoURL&&String(l.photoURL).trim()||void 0,grade:l.grade&&String(l.grade).trim()||void 0,section:l.section&&String(l.section).trim()||void 0,classSectionId:l.classSectionId&&String(l.classSectionId).trim()||void 0,adviserTeacherId:l.adviserTeacherId&&String(l.adviserTeacherId).trim()||void 0,role:"student",createdAt:l.createdAt||void 0};try{const i=At(a,Et("role","==","student"),Et("adviserTeacherId","==",t));(await Ot(i)).docs.forEach(c=>{const d=o(c.id,c.data());d&&r.set(c.id,d)})}catch(i){console.warn("[studentService] adviser-scoped student query failed:",i)}const n=Array.from(new Set((s||[]).map(i=>(i||"").trim()).filter(i=>!!i)));for(let i=0;i{if(r.has(m.id))return;const p=o(m.id,m.data());p&&r.set(m.id,p)})}catch(c){console.warn("[studentService] section-scoped student query failed:",c)}}return Array.from(r.values()).sort((i,l)=>i.name.localeCompare(l.name))}function Wu(t){const s=`https://ui-avatars.com/api/?name=${encodeURIComponent(t.name||"Student")}&background=random`,a=Xl.now();return{id:t.uid,accountUid:t.uid,lrn:t.lrn,name:t.name,email:t.email,avatar:t.photo||s,teacherId:t.adviserTeacherId,grade:t.grade,gradeLevel:gs(t.grade)||void 0,section:t.section,classSectionId:t.classSectionId,riskLevel:"Low",engagementScore:0,avgQuizScore:0,weakestTopic:"N/A",classroomId:t.classSectionId||"",attendance:0,assignmentCompletion:0,lastActive:null,struggles:[],createdAt:t.createdAt||a,updatedAt:a,hasRegisteredAccount:!0,source:"registered"}}function Ro(t){return(t||"").normalize("NFD").replace(/[\u0300-\u036f]/g,"").toLowerCase().replace(/[^a-z0-9\s]+/g," ").trim().replace(/\s+/g," ")}async function qu(t){const s=(t.studentId||"").trim();if(!s)throw new Error("Cannot reassign section: studentId is required.");const a=(t.newClassSectionId||"").trim()||Ft(t.newGrade,t.newSection);if(!a)throw new Error("Cannot reassign section: a target class section is required.");const r=(t.teacherId||"").trim(),o=(t.teacherName||"").trim(),n=(t.schoolYear||"").trim(),i=(t.previousClassSectionId||"").trim();try{const l=pt(He,"managedStudents",s),c=await ks(l);c.exists()&&await es(l,{grade:t.newGrade,section:t.newSection,classSectionId:a,gradeLevel:gs(t.newGrade)||t.newGrade,teacherId:r||c.data()?.teacherId,updatedAt:it()})}catch(l){console.warn("[studentService] reassignStudentSection: managedStudents update failed:",l)}if(t.isRegisteredAccount)try{await ts(pt(He,"users",s),{grade:t.newGrade,section:t.newSection,classSectionId:a,adviserTeacherId:r||void 0,adviserTeacherName:o||void 0,updatedAt:it()},{merge:!0})}catch(l){console.warn("[studentService] reassignStudentSection: users profile update failed:",l)}try{await jr({classSectionId:a,grade:t.newGrade,section:t.newSection,schoolYear:n,ownerTeacherId:r,ownerTeacherName:o,studentUids:[s]})}catch(l){console.warn("[studentService] reassignStudentSection: ownership upsert failed:",l)}if(i&&i!==a)try{const l=pt(He,"classSectionOwnership",i),c=await ks(l);if(c.exists()){const m=(c.data().studentUids||[]).filter(p=>p!==s);await es(l,{studentUids:m,updatedAt:it()})}}catch(l){console.warn("[studentService] reassignStudentSection: previous-section cleanup failed:",l)}}async function Yu(t){const{apiService:s}=await Ss(async()=>{const{apiService:d}=await import("./index-Bp7MiGcW.js").then(m=>m.b8);return{apiService:d}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11])),a=(t.adviserTeacherId||"").trim();if(!a)throw new Error("createStudentAccountFromRoster requires adviserTeacherId.");const r=(t.email||"").trim().toLowerCase();if(!r)throw new Error("createStudentAccountFromRoster requires an email.");const o=(t.grade||"").trim(),n=(t.section||"").trim(),i=(t.classSectionId||"").trim()||(o&&n?Ft(o,n):""),c=((await s.createStudentAccount({name:(t.name||"").trim()||"Student",email:r,temporaryPassword:t.temporaryPassword,lrn:t.lrn?.trim()||void 0,grade:o||void 0,section:n||void 0,classSectionId:i||void 0,adviserTeacherId:a,adviserTeacherName:t.adviserTeacherName?.trim()||void 0,schoolYear:t.schoolYear?.trim()||void 0})).uid||"").trim();if(!c)throw new Error("Backend did not return a uid for the newly created student.");try{await ts(pt(He,"managedStudents",c),pr({accountUid:c,name:(t.name||"").trim()||"Student",email:r,lrn:t.lrn?.trim()||null,teacherId:a,grade:o||null,gradeLevel:gs(o)||null,section:n||null,classSectionId:i||null,classroomId:i||null,riskLevel:"Low",avgQuizScore:0,engagementScore:0,attendance:0,assignmentCompletion:0,weakestTopic:"",struggles:[],avatar:`https://ui-avatars.com/api/?name=${encodeURIComponent(t.name||"Student")}&background=random`,hasRegisteredAccount:!0,source:"both",createdAt:it(),updatedAt:it()}))}catch(d){console.warn("[studentService] createStudentAccountFromRoster: managed-student merge failed:",d)}if(i&&o&&n)try{await jr({classSectionId:i,grade:o,section:n,schoolYear:t.schoolYear||"",ownerTeacherId:a,ownerTeacherName:t.adviserTeacherName,studentUids:[c]})}catch(d){console.warn("[studentService] createStudentAccountFromRoster: ownership upsert failed:",d)}return{uid:c,email:r,temporaryPassword:t.temporaryPassword}}async function il(t,s,a){const r=Ft(s,a),o=pt(He,"managedStudents",t);await es(o,{grade:s,section:a,classSectionId:r,updatedAt:it()})}async function Ku(t,s){const a=pt(He,"classSectionOwnership",s);await es(a,{studentUids:Kl(t),updatedAt:it()}).catch(r=>console.warn("[studentService] removeStudentFromClass: ownership update failed:",r)),await hi(pt(He,"managedStudents",t)).catch(r=>console.warn("[studentService] removeStudentFromClass: managedStudents delete failed:",r))}function Ft(t,s){return[t,s].filter(Boolean).join("_").replace(/\s+/g,"_").toLowerCase()}function pr(t){const s=Object.entries(t).filter(([,a])=>a!==void 0);return Object.fromEntries(s)}function gs(t){const s=(t||"").trim();if(!s)return null;const a=s.match(/(\d{1,2})/);return a?`Grade ${a[1]}`:/^grade\s+/i.test(s)?s.replace(/\s+/g," ").trim().replace(/^grade/i,"Grade"):s}function xa(t){const a=gs(t)?.match(/(\d{1,2})/),r=a?Number.parseInt(a[1],10):Number.NaN;return Number.isFinite(r)?r>=11?"Senior High School":"Junior High School":null}function pa(t,s){const a=`${t||""} ${s||""}`.toUpperCase();if(!a.trim())return null;const r=["STEM","ABM","HUMSS","GAS","TVL","ICT"];for(const o of r)if(new RegExp(`\\b${o}\\b`).test(a))return o;return null}function xs(t){const s=(t||"").trim();if(!s)return{grade:"Grade 11",section:"Section A"};const[a="Grade 11",r="Section A"]=s.split(" - ").map(o=>o.trim());return{grade:a||"Grade 11",section:r||"Section A"}}function Ct(t){const s=t.metadata||{},a=t.className||s.className,r=xs(a),o=(t.grade||s.grade||r.grade||"").trim()||null,n=(t.section||s.section||r.section||"").trim()||null,i=(t.classSectionId||s.classSectionId||"").trim()||(o&&n?Ft(o,n):"")||null,l=(a||"").trim()||(o&&n?`${o} - ${n}`:"")||null,c=gs(t.gradeLevel||s.gradeLevel||o),d=(t.classification||s.classification||"").trim()||xa(c)||null,m=(t.strand||s.strand||"").trim()||pa(l,n)||null;return{classSectionId:i,className:l,grade:o,section:n,gradeLevel:c,classification:d,strand:m,schoolYear:(t.schoolYear||s.schoolYear||"").trim()||null,ownerTeacherId:(t.ownerTeacherId||s.ownerTeacherId||"").trim()||null,ownerTeacherName:(t.ownerTeacherName||s.ownerTeacherName||"").trim()||null,adviserTeacherId:(t.adviserTeacherId||s.adviserTeacherId||"").trim()||null,adviserTeacherName:(t.adviserTeacherName||s.adviserTeacherName||"").trim()||null,managerId:(t.managerId||s.managerId||"").trim()||null,managerName:(t.managerName||s.managerName||"").trim()||null}}function Xu(t){const s=(t.className||"").trim(),[a="",r=""]=s.split(" - "),o=(t.grade||a||"").trim()||null,n=(t.section||r||"").trim()||null,i=(t.classSectionId||"").trim()||(o&&n?Ft(o,n):"")||null,l=s||(o&&n?`${o} - ${n}`:null),c=gs(t.gradeLevel||o),d=(t.classification||"").trim()||xa(c),m=(t.strand||"").trim()||pa(l,n);return{classSectionId:i,className:l,grade:o,section:n,gradeLevel:c,classification:d,strand:m,schoolYear:(t.schoolYear||"").trim()||null,ownerTeacherId:(t.ownerTeacherId||"").trim()||null,ownerTeacherName:(t.ownerTeacherName||"").trim()||null,adviserTeacherId:(t.adviserTeacherId||"").trim()||null,adviserTeacherName:(t.adviserTeacherName||"").trim()||null,managerId:(t.managerId||"").trim()||null,managerName:(t.managerName||"").trim()||null}}async function ll(t){const s=Mt(He,"classrooms"),a=new Map,r=At(s,Et("teacherId","==",t));(await Ot(r)).docs.forEach(l=>{a.set(l.id,{id:l.id,...l.data()})});const n=At(s,Et("managerId","==",t));return(await Ot(n)).docs.forEach(l=>{a.set(l.id,{id:l.id,...l.data()})}),Array.from(a.values()).sort((l,c)=>String(l.name||"").localeCompare(String(c.name||"")))}async function jr(t){const s=t.classSectionId||Ft(t.grade,t.section),a=pt(He,"classSectionOwnership",s),r=await ks(a),o=r.exists()?r.data().studentUids||[]:[],n=Array.from(new Set([...t.studentUids||[],...o])),i=pr(t);return r.exists()?await es(a,{...i,classSectionId:s,studentUids:n,updatedAt:it()}):await ts(a,{...i,classSectionId:s,studentUids:n,createdAt:it(),updatedAt:it()}),s}async function cl(t){const s=(t.classSectionId||"").trim()||Ft(t.grade,t.section),a=(t.className||"").trim()||`${t.grade} - ${t.section}`,r=Xu({classSectionId:s,className:a,grade:t.grade,section:t.section,schoolYear:t.schoolYear,ownerTeacherId:t.ownerTeacherId,ownerTeacherName:t.ownerTeacherName,adviserTeacherId:t.ownerTeacherId,adviserTeacherName:t.ownerTeacherName,managerId:t.managerId,managerName:t.managerName,classification:t.classification,strand:t.strand,gradeLevel:t.gradeLevel});await jr({classSectionId:s,className:a,grade:r.grade||t.grade,gradeLevel:r.gradeLevel||t.gradeLevel||t.grade,classification:r.classification||t.classification,strand:r.strand||t.strand,section:r.section||t.section,schoolYear:t.schoolYear,ownerTeacherId:t.ownerTeacherId,ownerTeacherName:t.ownerTeacherName,managerId:t.managerId,managerName:t.managerName,studentUids:[]});const o=Mt(He,"classrooms"),n=At(o,Et("classSectionId","==",s)),i=await Ot(n);if(i.empty){const l=pr({name:a,teacherId:t.ownerTeacherId,grade:r.grade,gradeLevel:r.gradeLevel,classification:r.classification,strand:r.strand,section:r.section,classSectionId:s,schoolYear:t.schoolYear,ownerTeacherId:t.ownerTeacherId,ownerTeacherName:t.ownerTeacherName||"",adviserTeacherId:t.ownerTeacherId,adviserTeacherName:t.ownerTeacherName||"",managerId:t.managerId,managerName:t.managerName||"",classMetadata:r,schedule:"Mon-Fri",studentCount:0,avgScore:0,atRiskCount:0,createdAt:it(),updatedAt:it()});await ts(pt(He,"classrooms",s),l,{merge:!0})}else for(const l of i.docs){const c=pr({name:a,grade:r.grade,gradeLevel:r.gradeLevel,classification:r.classification,strand:r.strand,section:r.section,schoolYear:t.schoolYear,ownerTeacherId:t.ownerTeacherId,ownerTeacherName:t.ownerTeacherName||"",adviserTeacherId:t.ownerTeacherId,adviserTeacherName:t.ownerTeacherName||"",managerId:t.managerId,managerName:t.managerName||"",classMetadata:r,updatedAt:it()});await es(l.ref,c)}return s}async function yr(t,s,a,r,o,n){const i=Ft(s,a);await jr({classSectionId:i,grade:s,section:a,schoolYear:o,ownerTeacherId:r,ownerTeacherName:n,studentUids:[t]});const l=await ks(pt(He,"users",t)),c=l.exists()?l.data():{};await ts(pt(He,"users",t),{grade:s,section:a,classSectionId:i,adviserTeacherId:r,adviserTeacherName:n||"",updatedAt:it()},{merge:!0}),await ts(pt(He,"managedStudents",t),{accountUid:t,name:c.name||c.displayName||"Student",email:c.email||"",lrn:c.lrn||null,teacherId:r,grade:s,gradeLevel:s,section:a,classSectionId:i,classroomId:i,hasRegisteredAccount:!0,source:"registered",updatedAt:it()},{merge:!0})}async function Ju(t){const s=Mt(He,"classSectionOwnership"),a=new Map,r=At(s,Et("ownerTeacherId","==",t));(await Ot(r)).docs.forEach(l=>{a.set(l.id,{id:l.id,...l.data()})});const n=At(s,Et("managerId","==",t));return(await Ot(n)).docs.forEach(l=>{a.set(l.id,{id:l.id,...l.data()})}),Array.from(a.values()).sort((l,c)=>String(l.classSectionId||"").localeCompare(String(c.classSectionId||"")))}async function Zu(t="",s=25){const a=Mt(He,"users"),r=Math.max(1,Math.min(100,s)),o=At(a,Et("role","==","teacher"),or(r*4)),n=await Ot(o),i=t.trim().toLowerCase();return n.docs.map(c=>{const d=c.data(),m=String(d.name||"").trim(),p=String(d.email||"").trim();return{uid:c.id,name:m||"Teacher",email:p,photo:String(d.photo||d.photoURL||"").trim()||void 0}}).filter(c=>i?c.name.toLowerCase().includes(i)||c.email.toLowerCase().includes(i):!0).sort((c,d)=>c.name.localeCompare(d.name)).slice(0,r)}function em(t,s,a=20){if(t.length===0)return s([]),()=>{};const r=Mt(He,"activities"),o=At(r,Et("classroomId","in",t),Jl("timestamp","desc"));return fi(o,n=>{const i=n.docs.slice(0,a).map(l=>({id:l.id,...l.data()}));s(i)},n=>{console.error("[studentService] subscribeToActivities error:",n),s([])})}const tm=({open:t,onClose:s,onCreated:a,teacherName:r})=>{const{currentUser:o}=hs(),[n,i]=u.useState("details"),[l,c]=u.useState(""),d="Grade 11",[m,p]=u.useState(""),[h,b]=u.useState(!1),[S,k]=u.useState(""),[N,v]=u.useState([]),[g,I]=u.useState(new Set),[z,R]=u.useState(""),[W,f]=u.useState(!1);u.useEffect(()=>{t||(i("details"),c(""),p(""),k(""),I(new Set),R(""))},[t]),u.useEffect(()=>{t&&n==="students"&&C()},[t,n]);const C=async()=>{f(!0);try{const y=Mt(He,"users"),q=At(y,Et("role","==","student")),J=await Ot(q),re=[];J.docs.forEach(le=>{const ne=le.data();re.push({uid:le.id,name:ne.name||ne.displayName||"Student",email:ne.email||"",grade:ne.grade,section:ne.section})}),v(re.sort((le,ne)=>le.name.localeCompare(ne.name)))}catch(y){console.error("[CreateClassModal] Failed to load students:",y)}finally{f(!1)}},w=async()=>{if(o){if(!m.trim()){k("Section name is required");return}k(""),b(!0);try{const y=String(new Date().getFullYear());if(await cl({classSectionId:"",grade:d,section:m.trim(),schoolYear:y,ownerTeacherId:o.uid,ownerTeacherName:r||o.displayName||"",managerId:o.uid,managerName:r||o.displayName||"",className:l.trim()||`${d} - ${m.trim()}`}),g.size>0){const q=Array.from(g).map(J=>yr(J,d,m.trim(),o.uid,y,r||o.displayName||""));await Promise.allSettled(q)}a(),s()}catch(y){k(y instanceof Error?y.message:"Failed to create class")}finally{b(!1)}}},$=y=>{I(q=>{const J=new Set(q);return J.has(y)?J.delete(y):J.add(y),J})},A=N.filter(y=>y.name.toLowerCase().includes(z.toLowerCase())||y.email.toLowerCase().includes(z.toLowerCase()));return t?e.jsx(zt,{children:e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[e.jsx(Le.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"absolute inset-0 bg-black/40 backdrop-blur-sm",onClick:s}),e.jsxs(Le.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.95},className:"relative bg-white rounded-2xl shadow-xl w-full max-w-lg mx-4 max-h-[80vh] flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-[#f1f5f9]",children:[e.jsx("h2",{className:"text-lg font-semibold text-[#1e293b]",children:n==="details"?"Create New Class":"Add Students"}),e.jsx("button",{onClick:s,className:"p-1 rounded-lg hover:bg-[#f1f5f9] transition-colors",children:e.jsx(Xt,{size:20,className:"text-[#64748b]"})})]}),e.jsxs("div",{className:"p-6 overflow-y-auto flex-1",children:[n==="details"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-[#475569] block mb-1.5",children:"Class Name"}),e.jsx(Is,{placeholder:"e.g. Grade 11 - Section A",value:l,onChange:y=>c(y.target.value)}),e.jsx("p",{className:"text-xs text-[#94a3b8] mt-1",children:"Optional. Auto-generated from grade + section if empty."})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-[#475569] block mb-1.5",children:"Section"}),e.jsx(Is,{placeholder:"e.g. Section A, STEM-1, Rizal",value:m,onChange:y=>p(y.target.value)})]}),S&&e.jsx("p",{className:"text-sm text-rose-500",children:S})]}),n==="students"&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx(qs,{size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-[#94a3b8]"}),e.jsx(Is,{placeholder:"Search students...",value:z,onChange:y=>R(y.target.value),className:"pl-9"})]}),e.jsxs("p",{className:"text-xs text-[#64748b]",children:[g.size," student(s) selected"]}),W?e.jsx("p",{className:"text-sm text-[#64748b] text-center py-4",children:"Loading students..."}):A.length===0?e.jsx("p",{className:"text-sm text-[#64748b] text-center py-4",children:"No students found."}):e.jsx("div",{className:"space-y-1 max-h-[300px] overflow-y-auto",children:A.map(y=>e.jsxs("button",{onClick:()=>$(y.uid),className:`w-full flex items-center gap-3 px-3 py-2.5 rounded-lg text-left transition-colors ${g.has(y.uid)?"bg-purple-50 border border-purple-200":"hover:bg-[#f8fafc] border border-transparent"}`,children:[e.jsx("div",{className:`w-5 h-5 rounded-md border-2 flex items-center justify-center ${g.has(y.uid)?"bg-[#9956DE] border-[#9956DE]":"border-[#cbd5e1]"}`,children:g.has(y.uid)&&e.jsx(Ht,{size:12,className:"text-white"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-[#1e293b] truncate",children:y.name}),e.jsx("p",{className:"text-xs text-[#64748b] truncate",children:y.email})]}),y.grade&&e.jsx("span",{className:"text-xs text-[#94a3b8]",children:y.grade})]},y.uid))}),S&&e.jsx("p",{className:"text-sm text-rose-500",children:S})]})]}),e.jsx("div",{className:"flex items-center justify-between p-6 border-t border-[#f1f5f9]",children:n==="details"?e.jsxs(e.Fragment,{children:[e.jsx(St,{variant:"outline",onClick:s,children:"Cancel"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(St,{variant:"outline",onClick:()=>{if(!m.trim()){k("Section is required");return}k(""),i("students")},children:"Add Students"}),e.jsx(St,{onClick:w,disabled:h||!m.trim(),className:"bg-[#9956DE] hover:bg-[#7c3aed] text-white",children:h?"Creating...":"Create Class"})]})]}):e.jsxs(e.Fragment,{children:[e.jsx(St,{variant:"outline",onClick:()=>i("details"),children:"Back"}),e.jsxs(St,{onClick:w,disabled:h,className:"bg-[#9956DE] hover:bg-[#7c3aed] text-white",children:[e.jsx(da,{size:16,className:"mr-1"}),h?"Creating...":`Create with ${g.size} Student${g.size!==1?"s":""}`]})]})})]})]})}):null},sm=({open:t,onClose:s,onAdded:a,grade:r,section:o,teacherName:n,existingStudentUids:i=[]})=>{const{currentUser:l}=hs(),[c,d]=u.useState([]),[m,p]=u.useState(new Set),[h,b]=u.useState(""),[S,k]=u.useState(!1),[N,v]=u.useState(!1);u.useEffect(()=>{t&&(p(new Set),b(""),g())},[t]);const g=async()=>{k(!0);try{const R=At(Mt(He,"users"),Et("role","==","student")),f=(await Ot(R)).docs.filter(C=>!i.includes(C.id)).map(C=>{const w=C.data();return{uid:C.id,name:w.name||w.displayName||"Student",email:w.email||""}}).sort((C,w)=>C.name.localeCompare(w.name));d(f)}catch{}k(!1)},I=async()=>{if(!(!l||m.size===0)){v(!0);try{const R=String(new Date().getFullYear()),W=Array.from(m).map(f=>yr(f,r,o,l.uid,R,n||l.displayName||""));await Promise.allSettled(W),ie.success(`Added ${m.size} student(s) to class`),a(),s()}catch{ie.error("Failed to add students")}v(!1)}},z=c.filter(R=>R.name.toLowerCase().includes(h.toLowerCase())||R.email.toLowerCase().includes(h.toLowerCase()));return t?e.jsx(zt,{children:e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[e.jsx(Le.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"absolute inset-0 bg-black/40 backdrop-blur-sm",onClick:s}),e.jsxs(Le.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.95},className:"relative bg-white rounded-2xl shadow-xl w-full max-w-2xl mx-4 max-h-[80vh] flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between p-5 border-b border-[#f1f5f9]",children:[e.jsxs("h2",{className:"text-base font-semibold text-[#1e293b]",children:["Add Students to ",r," - ",o]}),e.jsx("button",{onClick:s,className:"p-1 rounded-lg hover:bg-[#f1f5f9]",children:e.jsx(Xt,{size:18,className:"text-[#64748b]"})})]}),e.jsxs("div",{className:"p-4 space-y-3 flex-1 overflow-hidden flex flex-col",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(qs,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-[#94a3b8]"}),e.jsx(Is,{placeholder:"Search students...",value:h,onChange:R=>b(R.target.value),className:"pl-8 h-9 text-sm"})]}),e.jsx("button",{onClick:()=>{m.size===z.length?p(new Set):p(new Set(z.map(R=>R.uid)))},className:"text-[11px] font-semibold text-[#9956DE] hover:text-[#7c3aed] bg-[#9956DE]/10 hover:bg-[#9956DE]/20 px-3 py-1.5 rounded-lg transition-colors whitespace-nowrap",children:m.size===z.length&&z.length>0?"Deselect All":"Select All"})]}),e.jsxs("p",{className:"text-xs text-[#64748b]",children:[m.size," of ",z.length," selected"]}),e.jsx("div",{className:"flex-1 overflow-y-auto space-y-1 min-h-[300px]",children:S?e.jsx("p",{className:"text-sm text-center text-[#64748b] py-6",children:"Loading..."}):z.length===0?e.jsx("p",{className:"text-sm text-center text-[#64748b] py-6",children:"No students available"}):z.map(R=>e.jsxs("button",{onClick:()=>p(W=>{const f=new Set(W);return f.has(R.uid)?f.delete(R.uid):f.add(R.uid),f}),className:`w-full flex items-center gap-3 px-3 py-2 rounded-lg text-left transition-colors ${m.has(R.uid)?"bg-purple-50 border border-purple-200":"hover:bg-[#f8fafc] border border-transparent"}`,children:[e.jsx("div",{className:`w-5 h-5 rounded-md border-2 flex items-center justify-center shrink-0 ${m.has(R.uid)?"bg-[#9956DE] border-[#9956DE]":"border-[#cbd5e1]"}`,children:m.has(R.uid)&&e.jsx(Ht,{size:12,className:"text-white"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-[#1e293b] truncate",children:R.name}),e.jsx("p",{className:"text-[11px] text-[#64748b] truncate",children:R.email})]})]},R.uid))})]}),e.jsxs("div",{className:"flex items-center justify-between p-4 border-t border-[#f1f5f9]",children:[e.jsx(St,{variant:"outline",size:"sm",onClick:s,children:"Cancel"}),e.jsxs(St,{size:"sm",onClick:I,disabled:N||m.size===0,className:"bg-[#9956DE] hover:bg-[#7c3aed] text-white",children:[e.jsx(ci,{size:14,className:"mr-1.5"}),N?"Adding...":`Add ${m.size} Student${m.size!==1?"s":""}`]})]})]})]})}):null},dl="https://deign86-mathpulse-api-v3test.hf.space";async function ul(){const t={"Content-Type":"application/json"},s=di.currentUser;if(s)try{const a=await s.getIdToken(!1);a&&(t.Authorization=`Bearer ${a}`)}catch{}return t}async function Mo(t,s=!1){const a=await ul(),r=`${dl}/api/analytics/class/${encodeURIComponent(t)}${s?"?refresh=true":""}`,o=await fetch(r,{headers:a});if(!o.ok)throw new Error(`GET class analytics failed: ${o.status}`);return o.json()}async function am(t){const s=await ul(),a=await fetch(`${dl}/api/analytics/class/${encodeURIComponent(t)}/refresh-insights`,{method:"POST",headers:s});if(!a.ok)throw a.status===429?new Error("Insights can only be refreshed once every 5 minutes."):new Error(`POST refresh insights failed: ${a.status}`);return a.json()}const Sr="https://deign86-mathpulse-api-v3test.hf.space";async function kr(){const t={"Content-Type":"application/json"},s=di.currentUser;if(s)try{const a=await s.getIdToken(!1);a&&(t.Authorization=`Bearer ${a}`)}catch{}return t}async function rn(t){const s=await kr(),a=await fetch(`${Sr}/api/intervention/${encodeURIComponent(t)}`,{headers:s});if(!a.ok)throw new Error(`GET intervention failed: ${a.status}`);return a.json()}async function ml(t){const s=await kr(),a=await fetch(`${Sr}/api/intervention/generate`,{method:"POST",headers:s,body:JSON.stringify({student_id:t})});if(!a.ok)throw new Error(`POST intervention/generate failed: ${a.status}`);return a.json()}async function rm(t,s,a,r){const o=await kr(),n=await fetch(`${Sr}/api/intervention/${encodeURIComponent(t)}/step/${s}/complete`,{method:"POST",headers:o,body:JSON.stringify({score:a,time_spent_minutes:r})});if(!n.ok)throw new Error(`POST step complete failed: ${n.status}`);return n.json()}async function nm(t){const s=await kr(),a=await fetch(`${Sr}/api/intervention/${encodeURIComponent(t)}/export-pdf`,{headers:s});if(!a.ok)throw new Error(`GET export-pdf failed: ${a.status}`);return a.json()}async function xl(t,s){const r=(t.learning_path?.steps||[]).map(n=>({title:`Step ${n.step_number}: ${n.title}`,content:`${n.description||n.topic} (${n.type.replace("_"," ")} · ${n.duration_minutes} mins${n.num_items?` · ${n.num_items} items`:""})`}));return(await gi(Mt(He,"modules"),{title:`Intervention: ${t.weakest_topic} — ${t.student_name}`,gradeLevel:t.grade_level||"Grade 11",subject:"General Mathematics",quarter:"Q1",strandOrTrack:null,competencyTags:t.weak_topics.slice(0,3),moduleType:"teacher_uploaded",sourceLabel:"Teacher Upload",summary:t.next_steps_summary||`Personalized intervention for ${t.weakest_topic}`,learningObjectives:[t.learning_strengths,t.next_steps_summary].filter(Boolean),sections:r,practice:[],teacherId:s,assignedTo:t.student_id,createdAt:it()})).id}async function pl(t,s,a){return(await gi(Mt(He,"modules"),{title:t.title,gradeLevel:"Grade 11",subject:"General Mathematics",quarter:"Q1",strandOrTrack:null,competencyTags:[t.competency_tag].filter(Boolean),moduleType:"teacher_uploaded",sourceLabel:"Teacher Upload",summary:t.description||`${t.topic} (${t.difficulty})`,learningObjectives:[t.description].filter(Boolean),sections:[{title:t.title,content:t.description||t.topic}],practice:[],teacherId:a,assignedTo:s,createdAt:it()})).id}const om=Object.freeze(Object.defineProperty({__proto__:null,assignLearningPathAsModule:xl,assignStepAsModule:pl,completeStep:rm,generateInterventionPlan:ml,getExportPDFData:nm,getInterventionPlan:rn},Symbol.toStringTag,{value:"Module"}));function im(t,s=!0){const[a,r]=u.useState([]),[o,n]=u.useState(!1),[i,l]=u.useState(null);return u.useEffect(()=>{if(!t||!s){r([]);return}let c=!1;return n(!0),l(null),nc(t).then(d=>{c||r(d)}).catch(d=>{c||l(d.message)}).finally(()=>{c||n(!1)}),()=>{c=!0}},[t,s]),{videos:a,isLoading:o,error:i}}const lm=({step:t,isActive:s})=>{const{videos:a,isLoading:r,error:o}=im(t.youtube_query||`${t.topic} math tutorial Philippines`,s);return s?e.jsxs("div",{className:"mt-4",children:[o&&e.jsxs("p",{className:"text-xs text-red-400 mb-2",children:["Could not load videos: ",o]}),e.jsx(oc,{videos:r?[]:a,topic:t.title})]}):null},hl={"gen-math":{id:"gen-math",name:"General Mathematics",shortLabel:"Gen Math",color:"#3B82F6"},"stats-prob":{id:"stats-prob",name:"Statistics and Probability",shortLabel:"Stats & Prob",color:"#0ea5e9"},"business-math":{id:"business-math",name:"Business Mathematics",shortLabel:"Business Math",color:"#166534"},"pre-calc":{id:"pre-calc",name:"Pre-Calculus",shortLabel:"Pre-Calculus",color:"#F97316"},"basic-calc":{id:"basic-calc",name:"Basic Calculus",shortLabel:"Basic Calculus",color:"#EF4444"}},cm={gm:"gen-math",gen_math:"gen-math","gen math":"gen-math",genmath:"gen-math","general mathematics":"gen-math",sp:"stats-prob",stat:"stats-prob","stat&prob":"stats-prob",statistics:"stats-prob","statistics and probability":"stats-prob",bm:"business-math","business math":"business-math","business mathematics":"business-math",pc:"pre-calc","pre-calculus":"pre-calc",pre_calc:"pre-calc",precalc:"pre-calc",bc:"basic-calc",basic_calc:"basic-calc","basic calculus":"basic-calc",basiccalc:"basic-calc"};function dm(t){const s=t.toLowerCase().trim();return hl[s]?s:cm[s]||null}function um(t){const s=dm(t);return s?hl[s].name:t}function ys(t){if(!t)return t;const s=t.match(/^(Gm|Gen\s*Math|Stat|Stats?(?:\s*&\s*Prob)?|Pre[- ]?Cal(?:c)?|Basic[- ]?Cal(?:c)?|Bm|Business\s*Math)\s*(Q\d)?\s*[-–]?\s*(.*)$/i);if(!s)return t;const[,a,r,o]=s,i=[um(a)];return r&&i.push(r.toUpperCase()),o?.trim()&&i.push(o.trim()),i.join(" – ")}const mm={video_lesson:e.jsx(Za,{className:"w-5 h-5"}),practice:e.jsx(ir,{className:"w-5 h-5"}),assessment:e.jsx(La,{className:"w-5 h-5"}),chat_session:e.jsx(Si,{className:"w-5 h-5"}),review:e.jsx(cs,{className:"w-5 h-5"})},Ao={easy:"bg-emerald-100 text-emerald-700",medium:"bg-amber-100 text-amber-700",hard:"bg-rose-100 text-rose-700"},xm=({step:t,studentId:s,studentName:a,teacherId:r,totalSteps:o,onClose:n,onStepCompleted:i})=>{const[l,c]=u.useState(!1),[d,m]=u.useState([{role:"assistant",content:`Hi ${a}! Let's work on "${ys(t.title)}". ${t.description||`This covers ${ys(t.topic)}.`} Ready to start?`}]),[p,h]=u.useState(""),b=async()=>{c(!0);try{await pl(t,s,r),i(t.step_number),ie.success(`Step ${t.step_number} assigned to student!`),n()}catch{ie.error("Failed to assign step.")}finally{c(!1)}},S=()=>{if(!p.trim())return;const k=p.trim();m(N=>[...N,{role:"user",content:k}]),h(""),setTimeout(()=>{m(N=>[...N,{role:"assistant",content:`Great question about ${t.topic}! Let me help you understand this step by step. What part are you finding most challenging?`}])},1e3)};return e.jsx(zt,{children:e.jsxs(Le.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-[9999] flex items-center justify-center p-4",onClick:n,children:[e.jsx("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm"}),e.jsxs(Le.div,{initial:{scale:.95,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.95,opacity:0},className:"relative bg-white rounded-[24px] shadow-[0_24px_64px_rgba(0,0,0,0.18)] w-full max-w-[800px] max-h-[85vh] flex flex-col overflow-hidden z-10",onClick:k=>k.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-slate-100 shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-[12px] bg-gradient-to-br from-indigo-500 to-purple-600 flex items-center justify-center text-white",children:mm[t.type]||e.jsx(ir,{className:"w-5 h-5"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-[15px] font-bold text-[#1e293b]",children:ys(t.title)}),e.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[e.jsxs("span",{className:"text-[11px] text-[#64748b]",children:["Step ",t.step_number," of ",o]}),t.competency_tag&&e.jsx("span",{className:"px-1.5 py-0.5 bg-indigo-50 text-indigo-600 text-[9px] font-mono rounded",children:t.competency_tag}),e.jsx("span",{className:`px-2 py-0.5 text-[10px] font-semibold rounded-full ${Ao[t.difficulty]||Ao.easy}`,children:t.difficulty})]})]})]}),e.jsx("button",{onClick:n,className:"w-8 h-8 rounded-full bg-slate-100 hover:bg-slate-200 flex items-center justify-center transition-colors",children:e.jsx(Xt,{className:"w-4 h-4 text-slate-500"})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-6 grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"bg-slate-50 rounded-[14px] p-4 border border-slate-100",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(As,{className:"w-4 h-4 text-slate-500"}),e.jsxs("span",{className:"text-[12px] font-semibold text-slate-600",children:[t.duration_minutes," minutes"]}),t.num_items&&e.jsxs("span",{className:"text-[12px] text-slate-500",children:["• ",t.num_items," items"]})]}),e.jsx("p",{className:"text-[13px] text-[#475569] leading-relaxed",children:t.description||`Work through ${t.topic} at ${t.difficulty} difficulty.`})]}),t.type==="video_lesson"&&e.jsx(lm,{step:t,isActive:!0}),(t.type==="practice"||t.type==="assessment")&&e.jsxs("div",{className:"bg-purple-50/50 rounded-[14px] p-6 border border-purple-100 flex flex-col items-center justify-center min-h-[160px]",children:[e.jsx(ir,{className:"w-10 h-10 text-purple-400 mb-3"}),e.jsxs("p",{className:"text-[13px] font-semibold text-purple-700",children:[t.type==="assessment"?"Assessment":"Practice"," Questions"]}),e.jsxs("p",{className:"text-[11px] text-purple-500 mt-1",children:[t.num_items||10," questions on ",t.topic]})]})]}),e.jsxs("div",{className:"flex flex-col bg-slate-50 rounded-[14px] border border-slate-100 overflow-hidden",children:[e.jsx("div",{className:"px-4 py-3 border-b border-slate-100 bg-white",children:e.jsxs("p",{className:"text-[12px] font-semibold text-[#1e293b] flex items-center gap-1.5",children:[e.jsx(Si,{className:"w-3.5 h-3.5 text-indigo-500"})," AI Guide",e.jsx("span",{className:"text-[9px] font-medium text-slate-400 ml-1",children:"(Preview)"})]})}),e.jsx("div",{className:"flex-1 overflow-y-auto p-3 space-y-3 min-h-[200px] max-h-[300px]",children:d.map((k,N)=>e.jsx("div",{className:`flex ${k.role==="user"?"justify-end":"justify-start"}`,children:e.jsx("div",{className:`max-w-[85%] px-3 py-2 rounded-[12px] text-[12px] leading-relaxed ${k.role==="user"?"bg-indigo-500 text-white":"bg-white border border-slate-200 text-[#475569]"}`,children:k.content})},N))}),e.jsxs("div",{className:"p-3 border-t border-slate-100 bg-white flex gap-2",children:[e.jsx("input",{type:"text",value:p,onChange:k=>h(k.target.value),onKeyDown:k=>k.key==="Enter"&&S(),placeholder:"Ask for help...",className:"flex-1 text-[12px] px-3 py-2 rounded-[10px] border border-slate-200 focus:outline-none focus:border-indigo-300"}),e.jsx("button",{onClick:S,className:"w-8 h-8 rounded-full bg-indigo-500 hover:bg-indigo-600 flex items-center justify-center text-white transition-colors",children:e.jsx(aa,{className:"w-3.5 h-3.5"})})]})]})]}),e.jsxs("div",{className:"px-6 py-4 border-t border-slate-100 flex items-center justify-between shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-full bg-slate-200 h-2 rounded-full overflow-hidden",style:{width:120},children:e.jsx("div",{className:"h-full bg-indigo-500 rounded-full",style:{width:`${t.step_number/o*100}%`}})}),e.jsxs("span",{className:"text-[11px] text-slate-500",children:[t.step_number,"/",o]})]}),e.jsxs("button",{onClick:b,disabled:l||t.is_completed,className:"flex items-center gap-2 px-5 py-2.5 bg-indigo-500 hover:bg-indigo-600 text-white text-[13px] font-semibold rounded-full transition-colors disabled:opacity-50 shadow-sm",children:[e.jsx(La,{className:"w-4 h-4"}),t.is_completed?"Assigned ✓":l?"Assigning...":"Assign"]})]})]})]})})};async function pm(t,s,a){const r=pt(Mt(He,"generatedLessonPlans"));return await ts(r,{...t,teacherId:s,teacherName:a?.teacherName||null,studentId:a?.studentId||null,studentName:a?.studentName||null,status:"draft",createdAt:it(),updatedAt:it()}),r.id}async function hm(t){const s=pt(He,"generatedLessonPlans",t),a=await ks(s);if(!a.exists())throw new Error("Lesson draft not found. Save draft before publishing.");if(!a.data().publishReady)throw new Error("Lesson is not publish-ready. Resolve source legitimacy and validation issues first.");await es(s,{status:"published",publishedAt:it(),updatedAt:it()})}async function Lo(t,s=!0){const a=t.learningCompetency||t.lessonTitle||t.focusTopics&&t.focusTopics[0]||"general mathematics",r=t.subject||"general_math",o=t.quarter??1;let n="",i=[],l,c,d,m=!1;if(s)try{const b=await $l(a,r,o,{lessonTitle:t.lessonTitle,learningCompetency:t.learningCompetency,moduleUnit:t.moduleUnit,learnerLevel:t.learnerLevel});i=b.sources||[],n=b.explanation||"",l=b.retrievalConfidence,c=b.retrievalBand,d=b.retrievalQuery,m=b.needsReview??!1}catch{n="",i=[]}const p={...t,subject:r,quarter:o,curriculumContext:n?`[CURRICULUM CONTEXT] ${n}`:void 0,curriculumRetrievalConfidence:l,curriculumRetrievalBand:c,curriculumRetrievalQuery:d,needsReview:m};return{...await xt.generateLessonPlan(p),curriculumSources:i,curriculumContext:n}}const fm=ql("inline-flex items-center justify-center rounded-md border px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-hidden",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground [a&]:hover:bg-primary/90",secondary:"border-transparent bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90",destructive:"border-transparent bg-destructive text-white [a&]:hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",outline:"text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground"}},defaultVariants:{variant:"default"}});function gm({className:t,variant:s,asChild:a=!1,...r}){const o=a?uc:"span";return e.jsx(o,{"data-slot":"badge",className:ui(fm({variant:s}),t),...r})}function bm(t){return t.length<=42?t:`${t.slice(0,18)}...${t.slice(-20)}`}const zo=({sources:t=[],className:s})=>t.length?e.jsxs(mc,{children:[e.jsx(xc,{asChild:!0,children:e.jsxs(gm,{className:["bg-[#75D06A]/15 text-[#2E7D32] border-[#75D06A]/40 font-body font-semibold text-[11px] px-2.5 py-1 rounded-full cursor-help",s||""].join(" "),variant:"outline",children:[e.jsx(Gt,{size:12}),"DepEd Aligned"]})}),e.jsxs(pc,{side:"top",sideOffset:6,className:"max-w-sm bg-white border border-[#dde3eb] text-[#0a1628] shadow-lg p-3",children:[e.jsx("p",{className:"text-[11px] font-display font-bold uppercase tracking-wide text-[#5a6578] mb-2",children:"Curriculum Sources"}),e.jsx("div",{className:"space-y-2",children:t.slice(0,5).map((a,r)=>e.jsxs("div",{className:"text-xs leading-relaxed",children:[e.jsxs("p",{className:"font-semibold text-[#0a1628]",children:[a.subject," | Q",a.quarter]}),e.jsxs("p",{className:"text-[#5a6578]",children:[bm(a.sourceFile)," | p.",a.page]}),e.jsxs("p",{className:"text-[#5a6578]",children:["Similarity: ",(a.score*100).toFixed(1),"%"]})]},`${a.sourceFile}-${a.page}-${r}`))})]})]}):null,vm=[{level:"Remember",icon:Ur,bgColor:"bg-sky-500/20",borderColor:"border-sky-500/40",textColor:"text-sky-400",description:"Recall facts, formulas, definitions, and basic procedures.",mathExample:"State the quadratic formula.",mapsTo:"Identification, Enumeration",defaultWeight:"Included by default"},{level:"Understand",icon:Gt,bgColor:"bg-sky-500/20",borderColor:"border-sky-500/40",textColor:"text-sky-400",description:"Explain concepts, interpret graphs, classify mathematical objects.",mathExample:"Explain why the discriminant determines the number of roots.",mapsTo:"Multiple Choice, Identification",defaultWeight:"Included by default"},{level:"Apply",icon:Fl,bgColor:"bg-green-500/20",borderColor:"border-green-500/40",textColor:"text-green-400",description:"Use formulas and procedures to solve routine problems.",mathExample:"Solve: 2x² + 5x - 3 = 0 using the quadratic formula.",mapsTo:"Equation-Based, Word Problem",defaultWeight:"Included by default"},{level:"Analyze",icon:Hc,bgColor:"bg-orange-500/20",borderColor:"border-orange-500/40",textColor:"text-orange-400",description:"Break down problems, compare solution methods, identify patterns.",mathExample:"Given f(x) = x³ - 3x, find and classify all critical points.",mapsTo:"Word Problem, Equation-Based",defaultWeight:"Included by default"}],wm=({isOpen:t,onClose:s})=>t?e.jsx(zt,{children:t&&e.jsx(Le.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 bg-black/50 backdrop-blur-sm z-[70] flex items-center justify-center p-4",onClick:s,children:e.jsxs(Le.div,{initial:{scale:.95,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.95,opacity:0},className:"bg-white border border-slate-200 rounded-2xl shadow-2xl w-full max-w-3xl max-h-[85vh] flex flex-col overflow-hidden",onClick:a=>a.stopPropagation(),children:[e.jsxs("div",{className:"bg-gradient-to-r from-sky-600 to-sky-500 px-6 py-4 flex items-center justify-between flex-shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 bg-white/20 rounded-xl flex items-center justify-center",children:e.jsx(mi,{size:22,className:"text-white"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-bold text-white",children:"Bloom's Taxonomy in MathPulse AI"}),e.jsx("p",{className:"text-cyan-200 text-xs",children:"Understanding cognitive levels in assessments"})]})]}),e.jsx("button",{onClick:s,className:"w-8 h-8 bg-white/20 hover:bg-white/30 rounded-lg flex items-center justify-center transition-colors",children:e.jsx(Xt,{size:16,className:"text-white"})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-6 space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-bold text-rose-400 uppercase tracking-wide mb-2",children:"What is Bloom's Taxonomy?"}),e.jsx("p",{className:"text-sm text-slate-500 leading-relaxed",children:"Bloom's Taxonomy is an educational framework developed by Benjamin Bloom in 1956 and revised in 2001. It classifies learning objectives into six cognitive levels, from basic recall of facts up to complex evaluation and creation. MathPulse AI uses the first four levels most relevant to Senior High School mathematics."})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-bold text-rose-400 uppercase tracking-wide mb-2",children:"Why MathPulse AI Uses It"}),e.jsx("p",{className:"text-sm text-slate-500 leading-relaxed",children:"Using Bloom's Taxonomy ensures that assessments do not only test memorization. A well-balanced math quiz should challenge students at multiple cognitive levels: remembering formulas, understanding concepts, applying procedures, and analyzing relationships. This mirrors the DepEd K-12 competency framework which requires higher-order thinking skills (HOTS) alongside foundational knowledge."})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-bold text-rose-400 uppercase tracking-wide mb-3",children:"Level-by-Level Breakdown"}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:vm.map(a=>{const r=a.icon;return e.jsxs("div",{className:`${a.bgColor} border ${a.borderColor} rounded-xl p-4 space-y-2`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(r,{size:18,className:a.textColor}),e.jsx("span",{className:`font-bold text-sm ${a.textColor}`,children:a.level})]}),e.jsx("p",{className:"text-xs text-slate-500",children:a.description}),e.jsxs("div",{className:"bg-black/20 rounded-lg p-2",children:[e.jsx("p",{className:"text-[10px] font-semibold text-slate-500 uppercase tracking-wide mb-0.5",children:"Math Example"}),e.jsx("p",{className:"text-xs text-[#dde3eb] italic",children:a.mathExample})]}),e.jsxs("div",{className:"flex items-center justify-between text-[10px]",children:[e.jsxs("span",{className:"text-slate-500",children:["Maps to: ",e.jsx("span",{className:"text-slate-500 font-medium",children:a.mapsTo})]}),e.jsx("span",{className:"text-green-400 font-medium",children:a.defaultWeight})]})]},a.level)})})]}),e.jsx("div",{className:"bg-slate-50 border border-slate-200 rounded-xl p-4",children:e.jsxs("p",{className:"text-xs text-slate-500 leading-relaxed",children:[e.jsx("span",{className:"font-semibold text-slate-600",children:"Note:"})," ","All four levels are selected by default to produce a balanced, HOTS-aligned assessment. Deselecting a level will remove questions of that cognitive depth from the generated quiz."]})})]}),e.jsxs("div",{className:"border-t border-slate-200 px-6 py-3 flex items-center justify-between flex-shrink-0 bg-slate-50",children:[e.jsxs("a",{href:"https://cft.vanderbilt.edu/guides-sub-pages/blooms-taxonomy/",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-xs text-rose-400 hover:text-rose-300 font-medium transition-colors",children:[e.jsx(Wc,{size:12}),"Learn More"]}),e.jsx("button",{onClick:s,className:"px-5 py-2 bg-sky-600 hover:bg-rose-500 text-white text-sm font-bold rounded-xl transition-colors",children:"Got it"})]})]})})}):null,Nm={draft:"bg-[#edf1f7] text-[#5a6578]",published:"bg-green-100 text-green-700",assigned:"bg-sky-100 text-sky-700",completed:"bg-rose-100 text-rose-700"},Wa={identification:{label:"Identification",icon:e.jsx(Rs,{size:16}),description:"Define or identify concepts"},enumeration:{label:"Enumeration",icon:e.jsx(lr,{size:16}),description:"List steps or properties"},multiple_choice:{label:"Multiple Choice",icon:e.jsx(Ht,{size:16}),description:"Choose from 4 options"},word_problem:{label:"Word Problem",icon:e.jsx(Gt,{size:16}),description:"Real-world scenarios"},equation_based:{label:"Equation-Based",icon:e.jsx(Ol,{size:16}),description:"Solve equations"}},Do={remember:{label:"Remember",color:"bg-sky-100 text-sky-700 border-sky-300",description:"Recall facts & formulas"},understand:{label:"Understand",color:"bg-emerald-100 text-emerald-700 border-emerald-300",description:"Explain concepts"},apply:{label:"Apply",color:"bg-rose-100 text-rose-700 border-rose-300",description:"Use in new contexts"},analyze:{label:"Analyze",color:"bg-rose-100 text-rose-700 border-rose-300",description:"Examine & compare"}},jm=["Grade 11","Grade 12"],Dr=t=>{const s=(t||"").trim().toLowerCase();return s==="grade 12"||s==="12"||s.includes("12")?"Grade 12":"Grade 11"},ym={"Grade 11":{"General Mathematics - Patterns, Relations, and Functions":["Patterns and Real-Life Relationships","Functions as Mathematical Models","Function Notation and Evaluation","Domain and Range of Functions","Operations on Functions","Composite Functions","Inverse Functions","Graphs of Rational Functions","Graphs of Exponential Functions","Graphs of Logarithmic Functions"],"General Mathematics - Financial Mathematics":["Simple and Compound Interest","Simple and General Annuities","Present and Future Value","Loans, Amortization, and Sinking Funds","Stocks, Bonds, and Market Indices","Business Decision-Making with Mathematical Models"],"General Mathematics - Logic and Mathematical Reasoning":["Propositions and Logical Connectives","Truth Values and Truth Tables","Logical Equivalence and Implication","Quantifiers and Negation","Validity of Arguments"]},"Grade 12":{"Pre-Calculus - Analytic Geometry":["Conic Sections - Parabola","Conic Sections - Ellipse","Conic Sections - Hyperbola","Conic Sections - Circle","Systems of Nonlinear Equations"],"Pre-Calculus - Series and Induction":["Sequences and Series","Arithmetic Sequences","Geometric Sequences","Mathematical Induction","Binomial Theorem"],"Pre-Calculus - Trigonometry":["Angles and Unit Circle","Trigonometric Functions","Trigonometric Identities","Sum and Difference Formulas","Inverse Trigonometric Functions","Polar Coordinates"],"Basic Calculus - Limits":["Limits of Functions","Limit Theorems","One-Sided Limits","Infinite Limits and Limits at Infinity","Continuity of Functions"],"Basic Calculus - Derivatives":["Definition of the Derivative","Differentiation Rules","Chain Rule","Implicit Differentiation","Higher-Order Derivatives","Related Rates","Extrema and the First Derivative Test","Concavity and the Second Derivative Test","Optimization Problems"],"Basic Calculus - Integration":["Antiderivatives and Indefinite Integrals","Definite Integrals and the FTC","Integration by Substitution","Area Under a Curve"]}},Sm={"Grade 11":["General Mathematics - "],"Grade 12":["Pre-Calculus - ","Basic Calculus - "]},$o=(t,s)=>{const a=Sm[s];return Object.fromEntries(Object.entries(t).filter(([r])=>a.some(o=>r.startsWith(o))))},va=30,wa=12,$r="mathpulse:quiz-maker:active-task",km={easy:"text-green-600",medium:"text-rose-600",hard:"text-red-600"},fl=({onBack:t,gradeLevel:s,selectedClassId:a,selectedClassName:r,onOpenNotifications:o,onOpenProfile:n,onOpenInsightModal:i,userPhoto:l,teacherName:c,drawerMode:d=!1,onQuizSaved:m,onQuizGenerating:p})=>{const{currentUser:h,loading:b}=hs(),S=u.useMemo(()=>xt.getImportGroundedRolloutFlags(),[]),[k,N]=u.useState("create"),[v,g]=u.useState("setup"),[I,z]=u.useState(Dr(s)),[R,W]=u.useState(10),[f,C]=u.useState([]),[w,$]=u.useState([]),[A,y]=u.useState(["multiple_choice","word_problem","identification"]),[q,J]=u.useState(["remember","understand","apply","analyze"]),[re,le]=u.useState(!1),[ne,be]=u.useState({easy:30,medium:50,hard:20}),[Ie,de]=u.useState({}),[fe,H]=u.useState(!1),[ee,oe]=u.useState([]),[Re,Fe]=u.useState(!1),[Pe,G]=u.useState(""),[te,E]=u.useState(!1),[Y,V]=u.useState(!1),[pe,D]=u.useState(null),[j,_]=u.useState(0),[T,Q]=u.useState("queued"),[ue,ce]=u.useState("Waiting to start generation..."),[ae,Ce]=u.useState(null),[Ne,Je]=u.useState(null),[$e,Ge]=u.useState(""),[ft,Nt]=u.useState(!1),dt=u.useRef(!1),[jt,Lt]=u.useState("topics"),[rs,Ts]=u.useState(null),[bs,Bs]=u.useState(!1),[ns,vs]=u.useState("all"),[os,L]=u.useState("all"),[me,We]=u.useState(!1),[B,kt]=u.useState(null),[Me,M]=u.useState(!1),[F,ve]=u.useState(!1),[we,qe]=u.useState(!1),[je,yt]=u.useState([]),[lt,se]=u.useState(!1),[rt,nt]=u.useState(""),[ut,ws]=u.useState(null),[Xs,_s]=u.useState([]),[Oa,Js]=u.useState(!1),[Hs,Pa]=u.useState("all"),[Ba,Ha]=u.useState(null),[Ua,Us]=u.useState(null),ha=u.useCallback(async()=>{H(!0);const x=Dr(I);try{const O=await xt.getQuizTopics(x);O.topics&&de($o(O.topics,x))}catch{de($o(ym[x],x))}finally{H(!1)}},[I]),P=u.useCallback(async()=>{if(!S.quizEnabled){oe([]),G("Import-grounded quiz generation is disabled by rollout flag; using curriculum defaults."),Fe(!1);return}Fe(!0),G("");try{const x=await xt.getCourseMaterialTopics({classSectionId:a,limit:20}),O=(x.topics||[]).filter(U=>U.title?.trim());oe(O),x.warnings&&x.warnings.length>0&&G(x.warnings.join(" "))}catch{oe([]),G("Imported topics are currently unavailable; quiz generation will use curriculum defaults.")}finally{Fe(!1)}},[a,S.quizEnabled]);u.useEffect(()=>{ha(),C([]),$([])},[ha]),u.useEffect(()=>{P()},[P]);const X=u.useMemo(()=>{const x=Array.from(new Set(ee.map(O=>O.title.trim()).filter(Boolean)));return x.length===0?Ie:{"Imported Course Materials":x,...Ie}},[Ie,ee]);u.useEffect(()=>{vs("all"),L("all")},[ae]);const Ee=u.useMemo(()=>{if(!ae)return[];const x=ae.questions.map(U=>U.provenance?.sourceFile?.trim()).filter(U=>!!U),O=(ae.metadata.topicProvenance||[]).map(U=>U.sourceFile?.trim()).filter(U=>!!U);return Array.from(new Set([...x,...O])).sort((U,ye)=>U.localeCompare(ye))},[ae]),Oe=u.useMemo(()=>{if(!ae)return[];const x=ae.questions.map(U=>U.provenance?.materialId?.trim()).filter(U=>!!U),O=(ae.metadata.topicProvenance||[]).map(U=>U.materialId?.trim()).filter(U=>!!U);return Array.from(new Set([...x,...O])).sort((U,ye)=>U.localeCompare(ye))},[ae]),Pt=u.useMemo(()=>ae?ae.questions.filter(x=>{const O=ns==="all"||(x.provenance?.sourceFile||"").trim()===ns,U=os==="all"||(x.provenance?.materialId||"").trim()===os;return O&&U}):[],[ae,ns,os]),De=(x,O)=>{const U={...ne},ye=Math.max(0,Math.min(100,U[x]+O)),Qe=ye-U[x];U[x]=ye;const Ze=Object.keys(U).filter(mt=>mt!==x),Vt=Ze.reduce((mt,Jt)=>mt+U[Jt],0);if(Vt>0)for(const mt of Ze)U[mt]=Math.max(0,Math.round(U[mt]-Qe*U[mt]/Vt));const Zs=Object.values(U).reduce((mt,Jt)=>mt+Jt,0);if(Zs!==100){const mt=Ze.reduce((Jt,Ln)=>U[Jt]>=U[Ln]?Jt:Ln);U[mt]+=100-Zs}be(U)},Ga=x=>{C(O=>O.includes(x)?O.filter(U=>U!==x):[...O,x]),$(O=>O.filter(U=>U!==x))},Bt=x=>{y(O=>O.includes(x)?O.length>1?O.filter(U=>U!==x):O:[...O,x])},Ye=x=>{J(O=>O.includes(x)?O.length>1?O.filter(U=>U!==x):O:[...O,x])},fa=()=>{let x=f.length>0?f.filter(U=>!w.includes(U)):Object.values(X).flat().filter(U=>!w.includes(U)).slice(0,3);x.length>wa&&(x=x.slice(0,wa));const O=Math.min(R,va);return{topics:x,gradeLevel:I,numQuestions:O,questionTypes:A,includeGraphs:re,difficultyDistribution:ne,bloomLevels:q,excludeTopics:w,classSectionId:a,className:r,preferImportedTopics:S.quizEnabled}},ga=u.useCallback((x,O)=>{const U={taskId:x,request:O,createdAt:new Date().toISOString(),ownerUid:h?.uid};try{sessionStorage.setItem($r,JSON.stringify(U))}catch{}},[h]),Ns=u.useCallback(()=>{try{sessionStorage.removeItem($r)}catch{}},[]),Cr=u.useCallback(x=>{const O=Math.max(0,Math.min(100,Math.round(typeof x.progressPercent=="number"?x.progressPercent:x.status==="queued"?10:x.status==="running"?65:x.status==="completed"?100:x.status==="cancelling"?95:100)));_(U=>{let ye=Math.max(U,O);if(x.status==="running"&&O<=U){const Qe=String(x.progressStage||"").toLowerCase(),Ze=Qe.includes("assembling")||Qe.includes("final")?97:Qe.includes("generating")?89:95;ye=Math.min(Ze,U+1)}return ye}),Q(x.progressStage||x.status),ce(x.progressMessage||(x.status==="queued"?"Task queued for generation.":x.status==="running"?"Generating quiz in the background...":x.status==="completed"?"Generation complete.":x.status==="cancelling"?"Cancelling generation...":"Generation finished with an error."))},[]);u.useEffect(()=>{if(b||dt.current)return;if(dt.current=!0,!h){Ns();return}let x=!1;const O=sessionStorage.getItem($r);if(!O)return;let U=null;try{U=JSON.parse(O)}catch{Ns();return}if(!U?.taskId){Ns();return}if(U.ownerUid&&U.ownerUid!==h.uid){Ns();return}return E(!0),D(U.taskId),Ge(""),xt.waitForTaskResult(U.taskId,{timeoutMs:24e4,pollIntervalMs:1500,onProgress:Cr}).then(async ye=>{if(x)return;const Qe=ye.result;if(!Qe||typeof Qe!="object")throw new Error("Quiz generation completed without a valid result payload.");const Ze=Qe;Ce(Ze),g("results"),_(100),Q("completed"),ce("Generation complete."),D(null),Ns();try{await _n(Ze,U.request),ie.success("Quiz auto-saved to your library as draft.")}catch(Vt){ie.error(Vt instanceof Error?Vt.message:"Quiz generated but failed to save to library")}}).catch(ye=>{if(!x){if(ye instanceof rr&&(ye.status===401||ye.status===403)){dt.current=!1,E(!1);return}Ge(ye instanceof Error?ye.message:"Failed to resume quiz generation"),D(null),Ns()}}).finally(()=>{x||E(!1)}),()=>{x=!0}},[Cr,b,Ns,h]);const Cn=()=>{if(te){window.confirm("Quiz generation is in progress. Are you sure you want to leave?")&&(g("setup"),Ce(null),Ge(""),t());return}g("setup"),Ce(null),Ge(""),t()},Il=async()=>{p?.(),Ge(""),E(!0),Us(null),_(8),Q("queued"),ce("Submitting quiz generation task..."),Ce(null);const x=fa();try{const O=await xt.generateQuiz(x,{onTaskCreated:U=>{D(U),ga(U,x),_(ye=>Math.max(ye,12)),Q("queued"),ce("Task queued. Generation is running in the background.")},onProgress:U=>{Cr(U),U.taskId&&U.taskId!==pe&&D(U.taskId)}});Ce(O),g("results"),_(100),Q("completed"),ce("Generation complete."),D(null),Ns();try{await _n(O,x),ie.success("Quiz auto-saved to your library as draft.")}catch(U){ie.error(U instanceof Error?U.message:"Quiz generated but failed to save to library")}xt.reportImportGroundedFeedback({flow:"quiz",status:"success",classSectionId:x.classSectionId,className:x.className,metadata:{totalQuestions:O.metadata.totalQuestions,usedImportedTopics:!!O.metadata.usedImportedTopics,importedTopicCount:O.metadata.importedTopicCount??0,importGroundingEnabled:S.quizEnabled}})}catch(O){Ge(O instanceof Error?O.message:"Quiz generation failed"),_(100),Q("failed"),ce("Generation failed."),D(null),Ns(),xt.reportImportGroundedFeedback({flow:"quiz",status:"failed",classSectionId:x.classSectionId,className:x.className,metadata:{error:O instanceof Error?O.message:"Quiz generation failed",importGroundingEnabled:S.quizEnabled}})}finally{E(!1)}},Tl=()=>{if(!ae)return;const x=ae.questions.map((O,U)=>{let ye=`${U+1}. [${O.difficulty.toUpperCase()}] [${O.bloomLevel}] (${O.points} pts) `;return ye+=` ${O.question} `,O.options&&(ye+=O.options.map(Qe=>` ${Qe}`).join(` @@ -102,13 +102,13 @@ ${n}`:void 0,curriculumRetrievalConfidence:l,curriculumRetrievalBand:c,curriculu `),ye+=` Answer: ${O.correctAnswer} `,ye+=` Explanation: ${O.explanation} `,ye}).join(` -`);navigator.clipboard.writeText(x),Nt(!0),setTimeout(()=>Nt(!1),2e3)},_l=()=>{if(!ae)return;const x=new Blob([JSON.stringify(ae,null,2)],{type:"application/json"}),O=URL.createObjectURL(x),U=document.createElement("a");U.href=O,U.download=`quiz_${I.replace(/\s/g,"_")}_${Date.now()}.json`,U.click(),URL.revokeObjectURL(O)};f.length>0||Object.values(X).flat().length>0;const In=(x,O)=>{const U=O?.gradeLevel||I,ye=O?.topics||f,Qe=x.questions.map((Ze,Vt)=>({id:`q_${Date.now()}_${Vt}`,questionType:Ze.questionType||"identification",question:Ze.question,...Ze.options?{options:Ze.options}:{},correctAnswer:Ze.correctAnswer,bloomLevel:Ze.bloomLevel||"understand",difficulty:Ze.difficulty||"medium",topic:Ze.topic,subject:U,points:Ze.points,explanation:Ze.explanation}));return{title:`${U} Quiz – ${ye.length>0?ye.slice(0,2).join(", "):"Mixed Topics"}`,gradeLevel:U,questions:Qe,totalPoints:x.totalPoints,metadata:{topicsCovered:Object.keys(x.metadata.topicsCovered),difficultyBreakdown:{easy:x.metadata.difficultyBreakdown.easy??0,medium:x.metadata.difficultyBreakdown.medium??0,hard:x.metadata.difficultyBreakdown.hard??0},bloomDistribution:x.metadata.bloomTaxonomyDistribution,questionTypeBreakdown:x.metadata.questionTypeBreakdown,supplementalPurpose:x.metadata.supplementalPurpose,recommendedTeacherActions:x.metadata.recommendedTeacherActions??[],generatedAt:new Date().toISOString(),generatedBy:"teacher_generated"},status:"draft",source:"teacher_generated"}},Tn=u.useCallback(x=>{_s(O=>[x,...O.filter(U=>U.id!==x.id)])},[]);async function _n(x,O){if(!h)return null;const U=In(x,O),ye=await On(U,h.uid,B?{documentId:B}:void 0);return kt(ye),Tn({id:ye,...U,teacherId:h.uid}),ye}const El=async()=>{if(!ae){ie.error("No quiz to save. Generate a quiz first.");return}if(!h){ie.error("You must be signed in to save quizzes.");return}We(!0);try{const x=In(ae),O=await On(x,h.uid,B?{documentId:B}:void 0);kt(O),Tn({id:O,...x,teacherId:h.uid}),ie.success("Quiz saved to your library!"),m?.(O)}catch(x){ie.error(x instanceof Error?x.message:"Failed to save quiz")}finally{We(!1)}},Rl=async()=>{if(B){M(!0);try{await lc(B),_s(x=>x.map(O=>O.id===B?{...O,status:"published"}:O)),ie.success("Quiz published to Quiz Bank!")}catch(x){ie.error(x instanceof Error?x.message:"Failed to publish quiz")}finally{M(!1)}}},Ir=async x=>{const O=x??B;if(!O){ie.error("Save the quiz first before assigning.");return}if(Ha(O),ve(!0),ws(null),nt(""),je.length===0&&h){se(!0);try{const U=await jn(h.uid);yt(U)}catch{ie.error("Failed to load students")}finally{se(!1)}}},Ml=async()=>{const x=Ba??B;if(!(!ut||!x||!h)){qe(!0);try{await cc(x,ut,h.uid),_s(O=>O.map(U=>U.id===x?{...U,status:"assigned",metadata:{...U.metadata,assignedTo:ut}}:U)),ie.success("Quiz assigned to student!"),ve(!1),Ha(null),k==="bank"&&Tr()}catch(O){ie.error(O instanceof Error?O.message:"Failed to assign quiz")}finally{qe(!1)}}},Tr=u.useCallback(async()=>{if(h){Js(!0);try{const x=await vi(h.uid);_s(x)}catch{ie.error("Failed to load quiz bank")}finally{Js(!1)}}},[h]);u.useEffect(()=>{k==="bank"&&Tr()},[k,Tr]);const Al=async x=>{try{await ic(x),_s(O=>O.filter(U=>U.id!==x)),ie.success("Quiz deleted")}catch{ie.error("Failed to delete quiz")}},En=je.filter(x=>x.name.toLowerCase().includes(rt.toLowerCase())||x.email.toLowerCase().includes(rt.toLowerCase())),Rn=Hs==="all"?Xs:Xs.filter(x=>x.status===Hs),Ll=x=>{const O=(x.metadata.topicsCovered||[]).reduce((U,ye)=>(U[ye]=(U[ye]||0)+1,U),{});return{questions:x.questions.map(U=>({questionType:U.questionType,question:U.question,correctAnswer:U.correctAnswer,options:U.options??null,bloomLevel:U.bloomLevel,difficulty:U.difficulty,topic:U.topic,points:U.points,explanation:U.explanation})),totalPoints:x.totalPoints,metadata:{topicsCovered:O,difficultyBreakdown:x.metadata.difficultyBreakdown,bloomTaxonomyDistribution:x.metadata.bloomDistribution,questionTypeBreakdown:x.metadata.questionTypeBreakdown,gradeLevel:x.gradeLevel,totalQuestions:x.questions.length,includesGraphQuestions:!1,supplementalPurpose:x.metadata.supplementalPurpose,bloomTaxonomyRationale:"Loaded from saved quiz bank entry.",recommendedTeacherActions:x.metadata.recommendedTeacherActions||[]}}},_r=x=>{kt(x.id),Ce(Ll(x)),Je(null),Us(x.id),vs("all"),L("all"),Ts(null),g("results"),N("create")},Mn={remember:{badge:"border-purple-200 text-purple-700 bg-purple-50",card:"from-[#a855f7] to-[#9333ea]",num:"text-purple-700 bg-purple-100 border-purple-200"},understand:{badge:"border-blue-200 text-blue-700 bg-blue-50",card:"from-[#3b82f6] to-[#2563eb]",num:"text-blue-700 bg-blue-100 border-blue-200"},apply:{badge:"border-amber-200 text-amber-700 bg-amber-50",card:"from-[#f59e0b] to-[#d97706]",num:"text-amber-700 bg-amber-100 border-amber-200"},analyze:{badge:"border-orange-200 text-orange-700 bg-orange-50",card:"from-[#f97316] to-[#ea580c]",num:"text-orange-700 bg-orange-100 border-orange-200"},evaluate:{badge:"border-rose-200 text-rose-700 bg-rose-50",card:"from-[#f43f5e] to-[#e11d48]",num:"text-rose-700 bg-rose-100 border-rose-200"},create:{badge:"border-emerald-200 text-emerald-700 bg-emerald-50",card:"from-[#10b981] to-[#059669]",num:"text-emerald-700 bg-emerald-100 border-emerald-200"}},zl=(x,O,U)=>{const ye=rs===O,Qe=Mn[x.bloomLevel?.toLowerCase()]||Mn.remember,Ze=x.bloomLevel?.toLowerCase()==="remember"?"hover:border-purple-200":x.bloomLevel?.toLowerCase()==="understand"?"hover:border-blue-200":x.bloomLevel?.toLowerCase()==="apply"?"hover:border-amber-200":"hover:border-slate-200";return e.jsxs(Le.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:O*.05},className:`border border-[#e2e8f0] rounded-[20px] overflow-hidden bg-white shadow-sm hover:shadow-md ${Ze} transition-all duration-300`,children:[e.jsxs("div",{className:"p-6 flex justify-between items-start cursor-pointer hover:bg-slate-50/50 transition-colors",onClick:()=>Ts(ye?null:O),children:[e.jsxs("div",{className:"space-y-3 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2.5 flex-wrap mb-1",children:[e.jsxs("span",{className:`w-8 h-8 rounded-lg bg-gradient-to-br ${Qe.card} text-white flex items-center justify-center font-bold text-[13px] shadow-sm`,children:["Q",O+1]}),e.jsx("span",{className:`px-2.5 py-1 rounded-md border text-[10px] font-bold uppercase tracking-wider shadow-sm ${Qe.badge}`,children:x.bloomLevel}),e.jsx("span",{className:`px-2.5 py-1 rounded-md border text-[10px] font-bold uppercase tracking-wider shadow-sm ${x.difficulty==="easy"?"border-emerald-200 text-emerald-700 bg-emerald-50":x.difficulty==="hard"?"border-rose-200 text-rose-700 bg-rose-50":"border-amber-200 text-amber-700 bg-amber-50"}`,children:x.difficulty}),e.jsxs("span",{className:"text-[12px] font-bold text-[#64748b] bg-slate-100 px-2 py-1 rounded-md",children:[x.points," pts"]}),x.topic&&e.jsx("span",{className:"text-[12px] font-semibold text-[#64748b] px-2 py-1 hidden sm:inline-block border-l border-slate-200",children:x.topic})]}),e.jsx("p",{className:"text-[16px] font-bold text-[#1e293b] pr-4 leading-relaxed",children:x.question})]}),e.jsxs("div",{className:"flex flex-col items-end justify-between h-full gap-4 shrink-0 mt-1",children:[e.jsx("span",{className:`px-3 py-1.5 rounded-md text-[10px] font-bold uppercase tracking-widest hidden sm:block border shadow-sm ${Qe.badge}`,children:x.bloomLevel}),e.jsx("div",{className:"w-8 h-8 rounded-full bg-slate-50 flex items-center justify-center border border-slate-200 mt-2",children:ye?e.jsx(Ca,{size:16,className:"text-[#64748b] transition-transform duration-300"}):e.jsx($t,{size:16,className:"text-[#64748b]"})})]})]}),e.jsx(zt,{children:ye&&e.jsx(Le.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},className:"overflow-hidden",children:e.jsxs("div",{className:"p-6 pt-0 bg-white",children:[e.jsx("div",{className:"h-px w-full bg-gradient-to-r from-transparent via-[#e2e8f0] to-transparent mb-6"}),x.options&&e.jsxs("div",{className:"mb-6",children:[e.jsx("p",{className:"text-[13px] font-bold text-[#64748b] mb-3 uppercase tracking-wider",children:"Options:"}),e.jsx("div",{className:"space-y-3",children:x.options.map((Vt,Zs)=>{const mt=Vt.includes(x.correctAnswer);return e.jsxs("div",{className:`rounded-[12px] p-4 text-[14px] font-medium transition-all cursor-pointer relative overflow-hidden ${mt?"bg-gradient-to-r from-emerald-50 to-emerald-100/30 border-2 border-emerald-400 text-emerald-800 font-bold shadow-sm":"bg-white border border-[#e2e8f0] text-[#475569] hover:border-[#a855f7] hover:shadow-[0_2px_8px_rgba(168,85,247,0.1)]"}`,children:[mt&&e.jsx("div",{className:"absolute left-0 top-0 w-1 h-full bg-emerald-500"}),e.jsx("span",{className:mt?"pl-2":"",children:Vt}),mt&&e.jsx("div",{className:"w-6 h-6 rounded-full bg-emerald-500 text-white flex items-center justify-center shadow-sm absolute right-4 top-1/2 -translate-y-1/2",children:e.jsx(Ht,{size:13})})]},Zs)})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4 mb-5",children:[e.jsxs("div",{className:"bg-emerald-50/80 border border-emerald-200/60 rounded-[16px] p-5 shadow-sm",children:[e.jsxs("p",{className:"text-[11px] font-bold text-emerald-700 uppercase tracking-wider mb-2 flex items-center gap-1.5",children:[e.jsx(ya,{size:14})," Correct Answer"]}),e.jsx("p",{className:"text-[16px] font-bold text-[#1e293b]",children:x.correctAnswer})]}),e.jsxs("div",{className:"bg-purple-50/80 border border-purple-200/60 rounded-[16px] p-5 shadow-sm",children:[e.jsxs("p",{className:"text-[11px] font-bold text-purple-700 uppercase tracking-wider mb-2 flex items-center gap-1.5",children:[e.jsx(ps,{size:14})," AI Explanation"]}),e.jsx("p",{className:"text-[13px] text-[#475569] leading-relaxed font-medium",children:x.explanation})]})]}),e.jsxs("div",{className:"flex gap-6 text-[12px] font-medium text-[#64748b] mt-5 pt-4 border-t border-slate-100",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Rs,{size:14})," ",e.jsx("strong",{className:"text-[#1e293b]",children:"Type:"})," ",Wa[x.questionType]?.label||x.questionType]}),e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ur,{size:14})," ",e.jsx("strong",{className:"text-[#1e293b]",children:"Bloom:"})," ",x.bloomLevel]})]})]})})})]},O)},An=e.jsxs("div",{className:"w-full h-full flex flex-col overflow-y-auto bg-gradient-to-br from-[#eef2ff] via-[#f5f3ff] to-[#fff7ed]",children:[e.jsx("div",{className:"w-full px-[24px] xl:px-[32px] pt-[12px] pb-4",children:e.jsxs("div",{className:"flex items-center gap-1 bg-white/50 backdrop-blur-md p-1.5 rounded-full border border-white shadow-[0_2px_8px_rgba(0,0,0,0.04)] w-max",children:[e.jsxs("button",{onClick:()=>N("create"),className:`px-6 py-2 rounded-full text-[13px] font-bold flex items-center gap-2 transition-all duration-300 ease-out ${k==="create"?"bg-white text-[#a855f7] shadow-[0_2px_8px_rgba(168,85,247,0.15)] scale-100":"bg-transparent text-[#64748b] hover:text-[#1e293b] hover:bg-white/60 scale-95 hover:scale-100"}`,children:[e.jsx(Xr,{size:16})," Create Quiz"]}),e.jsxs("button",{onClick:()=>N("bank"),className:`px-6 py-2 rounded-full text-[13px] font-bold flex items-center gap-2 transition-all duration-300 ease-out ${k==="bank"?"bg-white text-[#a855f7] shadow-[0_2px_8px_rgba(168,85,247,0.15)] scale-100":"bg-transparent text-[#64748b] hover:text-[#1e293b] hover:bg-white/60 scale-95 hover:scale-100"}`,children:[e.jsx(ur,{size:16})," Quiz Bank"]})]})}),e.jsxs("div",{className:"w-full px-[24px] xl:px-[32px] pb-[32px] flex-1",children:[k==="bank"&&e.jsxs("div",{className:"w-full space-y-[24px]",children:[e.jsx("div",{className:"flex items-center gap-3 overflow-x-auto pb-2 border-b border-[#e2e8f0] mb-6",style:{scrollbarWidth:"none"},children:["all","draft","published","assigned","completed"].map(x=>e.jsx("button",{onClick:()=>Pa(x),className:`px-5 py-2 text-[13px] font-bold rounded-full whitespace-nowrap transition-all duration-300 mb-4 capitalize ${Hs===x?"bg-purple-50 text-[#9333ea] border border-purple-200 shadow-[0_2px_8px_rgba(168,85,247,0.15)] hover:scale-105":"bg-white/80 text-[#64748b] border border-white hover:border-[#e2e8f0] hover:bg-white shadow-sm hover:shadow-md hover:-translate-y-0.5"}`,children:x==="all"?"All":x.charAt(0).toUpperCase()+x.slice(1)},x))}),Oa?e.jsxs("div",{className:"flex items-center justify-center py-16",children:[e.jsx(gt,{size:24,className:"animate-spin text-sky-500"}),e.jsx("span",{className:"ml-2 text-sm text-[#5a6578]",children:"Loading quiz bank…"})]}):Rn.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-slate-500",children:[e.jsx(ur,{size:40,className:"mb-3"}),e.jsx("p",{className:"font-medium",children:"No quizzes found"}),e.jsx("p",{className:"text-xs mt-1",children:"Generate your first quiz in the Create tab"})]}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:Rn.map(x=>e.jsxs(Le.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},onClick:()=>_r(x),role:"button",tabIndex:0,onKeyDown:O=>{(O.key==="Enter"||O.key===" ")&&(O.preventDefault(),_r(x))},className:`relative bg-white/80 backdrop-blur-md rounded-[20px] p-6 shadow-sm border flex flex-col group hover:-translate-y-1 transition-all duration-300 cursor-pointer overflow-hidden focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#a855f7] ${x.status==="assigned"||x.status==="published"?"border-white hover:border-purple-100 hover:shadow-[0_8px_24px_rgba(168,85,247,0.1)]":"border-white hover:border-slate-200 hover:shadow-[0_8px_24px_rgba(0,0,0,0.06)]"}`,children:[e.jsx("div",{className:`absolute top-0 left-0 w-[6px] h-full transition-colors duration-300 ${x.status==="assigned"||x.status==="published"?"bg-purple-300 group-hover:bg-[#a855f7]":"bg-slate-200 group-hover:bg-slate-400"}`}),e.jsxs("div",{className:"flex justify-between items-start mb-4 gap-4 pl-3",children:[e.jsx("h3",{className:`font-bold text-[15px] text-[#1e293b] leading-tight transition-colors ${x.status==="assigned"||x.status==="published"?"group-hover:text-[#9333ea]":"group-hover:text-slate-700"}`,children:x.title}),e.jsx("span",{className:`px-2.5 py-1 rounded-[6px] text-[10px] font-bold uppercase tracking-wider shrink-0 shadow-sm ${Nm[x.status]}`,children:x.status})]}),e.jsx("div",{className:"flex flex-wrap gap-2 mb-5 pl-3",children:x.metadata.topicsCovered.slice(0,3).map(O=>e.jsx("span",{className:"px-2.5 py-1 bg-[#f8fafc] text-slate-600 text-[11px] font-medium rounded-md border border-slate-200 group-hover:border-slate-300 transition-colors",children:O},O))}),e.jsxs("div",{className:"flex items-center gap-5 text-[13px] text-[#64748b] font-medium mb-6 pl-3",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(hc,{size:14})," ",x.questions.length," questions"]}),e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(xi,{size:14})," ",x.totalPoints," pts"]}),e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(us,{size:14})," ",x.gradeLevel]})]}),e.jsxs("div",{className:"flex items-center gap-4 mt-auto pt-5 border-t border-[#f1f5f9] pl-3",children:[e.jsxs("button",{onClick:O=>{O.stopPropagation(),_r(x)},className:"flex items-center gap-1.5 text-[13px] font-semibold text-[#64748b] hover:text-[#1e293b] transition-colors bg-slate-50 hover:bg-slate-100 border border-slate-200 px-4 py-2 rounded-full shadow-sm",children:[e.jsx(fc,{size:14})," View"]}),e.jsxs("button",{onClick:O=>{O.stopPropagation(),Ir(x.id)},className:"flex items-center gap-1.5 text-[13px] font-bold text-[#a855f7] hover:text-[#9333ea] transition-colors",children:[e.jsx(aa,{size:14})," Assign"]}),e.jsxs("button",{onClick:O=>{O.stopPropagation(),Al(x.id)},className:"flex items-center gap-1.5 text-[13px] font-semibold text-rose-500 hover:text-rose-700 transition-colors ml-auto opacity-60 group-hover:opacity-100",children:[e.jsx(wi,{size:14})," Delete"]})]})]},x.id))})]}),k==="create"&&e.jsxs(e.Fragment,{children:[$e&&e.jsx("div",{className:"w-full px-[24px] xl:px-[32px] pt-4",children:e.jsxs(Le.div,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},className:"bg-red-50 border border-red-200 rounded-xl p-4 flex items-start gap-3",children:[e.jsx(br,{size:18,className:"text-red-500 flex-shrink-0 mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-red-800 font-medium",children:"Error"}),e.jsx("p",{className:"text-sm text-red-600",children:$e})]}),e.jsx("button",{onClick:()=>Ge(""),className:"ml-auto",children:e.jsx(Xt,{size:14,className:"text-red-400"})})]})}),te&&e.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center p-[24px] xl:p-[32px]",children:[e.jsxs("div",{className:"bg-white p-8 rounded-[16px] shadow-sm border border-[#e2e8f0] w-full max-w-3xl",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("h3",{className:"text-[16px] font-bold text-[#1e293b] flex items-center gap-3",children:[e.jsx(gt,{size:20,className:"animate-spin text-[#a855f7]"}),"Generating Quiz in Background"]}),e.jsxs("span",{className:"text-[14px] font-extrabold text-[#9333ea]",children:[j,"%"]})]}),e.jsx("div",{className:"w-full bg-slate-100 h-2.5 rounded-full overflow-hidden mb-6",children:e.jsx(Le.div,{animate:{width:`${j}%`},transition:{duration:.35,ease:"easeOut"},className:"bg-gradient-to-r from-sky-400 via-indigo-500 to-purple-500 h-full rounded-full"})}),e.jsxs("div",{className:"text-[13px] text-[#64748b]",children:[e.jsxs("p",{className:"font-medium text-[#475569] mb-1",children:["Stage: ",e.jsx("span",{className:"font-bold text-[#1e293b] capitalize",children:T.replace(/_/g," ")})]}),e.jsx("p",{children:ue}),pe&&e.jsxs("p",{className:"text-[11px] mt-3 opacity-60 font-mono",children:["Task ID: ",pe]})]})]}),e.jsxs("p",{className:"mt-8 text-[14px] font-medium text-[#64748b] flex items-center gap-2 animate-pulse",children:[e.jsx(gt,{size:16,className:"animate-spin"})," Generating quiz... Please wait."]})]}),!te&&v!=="results"&&e.jsx("div",{className:"w-full px-[24px] xl:px-[32px] mb-8",children:e.jsx("div",{className:"flex items-center justify-between bg-white/80 backdrop-blur-[12px] rounded-2xl border border-white shadow-[0_4px_16px_rgba(0,0,0,0.03)] p-1.5",children:[{id:"setup",label:"Setup"},{id:"topics",label:"Topics"},{id:"style",label:"Question Style"},{id:"preview",label:"Preview"}].map((x,O)=>{const ye=["setup","topics","style","preview"].indexOf(v),Qe=ye>O,Ze=ye===O;return e.jsxs("div",{className:`flex-1 flex items-center justify-center gap-2 py-3 px-4 rounded-xl transition-all duration-500 ${Ze?"bg-purple-50/80 shadow-[0_1px_3px_rgba(168,85,247,0.1)]":Qe?"bg-transparent":"bg-transparent opacity-60"}`,children:[e.jsx("div",{className:`w-6 h-6 rounded-full flex items-center justify-center text-[12px] font-bold shrink-0 ${Ze?"bg-gradient-to-br from-[#a855f7] to-[#9333ea] text-white shadow-md":Qe?"bg-emerald-500 text-white shadow-sm":"bg-slate-100 text-[#64748b]"}`,children:Qe?e.jsx(Ht,{size:13,strokeWidth:3}):O+1}),e.jsx("span",{className:`text-[13px] font-bold whitespace-nowrap ${Ze?"text-[#9333ea]":Qe?"text-[#1e293b]":"text-[#64748b]"}`,children:x.label})]},x.id)})})}),v==="setup"&&!te&&e.jsxs("div",{className:"w-full px-[24px] xl:px-[32px] flex-1 space-y-[24px] pb-8",children:[e.jsxs("div",{className:"bg-gradient-to-r from-purple-50/80 to-indigo-50/80 backdrop-blur-sm border border-purple-100/50 rounded-[16px] p-5 flex items-start gap-4 shadow-sm hover:shadow-md transition-shadow duration-300",children:[e.jsx("div",{className:"bg-white p-2 rounded-full shadow-sm shrink-0",children:e.jsx(na,{size:18,className:"text-[#9333ea]"})}),e.jsxs("p",{className:"text-[13px] text-[#475569] leading-relaxed pt-0.5",children:["This quiz maker generates ",e.jsx("span",{className:"font-bold text-[#9333ea]",children:"supplemental assessments"})," to support classroom instruction. Questions follow Bloom's Taxonomy for comprehensive skill evaluation. Generation limit: up to ",va," questions and ",wa," topics per quiz."]})]}),e.jsxs("div",{className:"bg-white/80 backdrop-blur-[12px] rounded-[20px] border border-white shadow-[0_4px_16px_rgba(0,0,0,0.03)] overflow-hidden hover:shadow-[0_8px_24px_rgba(0,0,0,0.06)] transition-all duration-300",children:[e.jsx("div",{className:"p-5 border-b border-[#f1f5f9] bg-white/50",children:e.jsx("h3",{className:"text-[11px] font-bold text-[#64748b] uppercase tracking-wider",children:"Basic Settings"})}),e.jsxs("div",{className:"p-8 flex flex-col md:flex-row gap-8",children:[e.jsxs("div",{className:"flex-1 group",children:[e.jsx("label",{htmlFor:"quiz-grade-level",className:"text-[13px] font-bold text-[#1e293b] mb-2 block group-hover:text-[#a855f7] transition-colors",children:"Grade level"}),e.jsxs("div",{className:"relative",children:[e.jsx("select",{id:"quiz-grade-level",value:I,onChange:x=>z(Dr(x.target.value)),className:"appearance-none w-full bg-white border border-[#e2e8f0] hover:border-[#cbd5e1] text-[#475569] text-[14px] font-medium rounded-xl px-4 py-3.5 outline-none focus:border-[#a855f7] focus:ring-4 focus:ring-[#a855f7]/10 cursor-pointer transition-all duration-200 shadow-sm",children:jm.map(x=>e.jsx("option",{value:x,children:x},x))}),e.jsx($t,{size:18,className:"text-[#64748b] absolute right-4 top-1/2 -translate-y-1/2 pointer-events-none"})]})]}),e.jsxs("div",{className:"flex-1 group",children:[e.jsx("label",{htmlFor:"quiz-num-questions",className:"text-[13px] font-bold text-[#1e293b] mb-2 block group-hover:text-[#a855f7] transition-colors",children:"Number of questions"}),e.jsxs("div",{className:"flex items-center bg-white border border-[#e2e8f0] rounded-xl overflow-hidden focus-within:border-[#a855f7] focus-within:ring-4 focus-within:ring-[#a855f7]/10 transition-all duration-200 h-[50px] shadow-sm hover:border-[#cbd5e1]",children:[e.jsx("button",{onClick:()=>W(Math.max(1,R-1)),className:"w-14 h-full flex items-center justify-center text-[#64748b] bg-slate-50 hover:bg-slate-100 hover:text-[#1e293b] transition-colors border-r border-[#e2e8f0] active:bg-slate-200",children:e.jsx(Pn,{size:16})}),e.jsx("input",{id:"quiz-num-questions",type:"number",min:1,max:va,value:R,onChange:x=>W(Math.min(va,Math.max(1,parseInt(x.target.value)||1))),className:"flex-1 text-center font-bold text-[16px] text-[#1e293b] border-none outline-none focus:ring-0 w-full h-full p-0"}),e.jsx("button",{onClick:()=>W(Math.min(va,R+1)),className:"w-14 h-full flex items-center justify-center text-[#64748b] bg-slate-50 hover:bg-slate-100 hover:text-[#1e293b] transition-colors border-l border-[#e2e8f0] active:bg-slate-200",children:e.jsx(da,{size:16})})]})]})]})]})]}),v==="topics"&&!te&&e.jsxs("div",{className:"w-full px-[24px] xl:px-[32px] flex-1 space-y-[24px] pb-8",children:[e.jsxs("div",{className:"flex items-end justify-between mb-2",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-[20px] font-bold text-[#1e293b] mb-1",children:"Select topics"}),e.jsxs("p",{className:"text-[13px] text-[#64748b]",children:["Choose up to ",wa," topics across all strands"]})]}),e.jsxs("div",{className:"bg-purple-50 border border-purple-100 px-3 py-1.5 rounded-full flex items-center gap-2 shadow-sm",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-[#a855f7] animate-pulse"}),e.jsxs("span",{className:"text-[12px] font-bold text-[#a855f7]",children:[f.filter(x=>!w.includes(x)).length," of ",wa," selected"]})]})]}),fe?e.jsxs("div",{className:"flex items-center justify-center py-10 text-sm text-[#5a6578]",children:[e.jsx(gt,{size:24,className:"animate-spin text-[#9b51e0] mr-2"})," Loading topics..."]}):e.jsx("div",{className:"space-y-3",children:Object.entries(X).map(([x,O])=>{const U=O.filter(Qe=>f.includes(Qe)&&!w.includes(Qe)).length,ye=jt===x;return e.jsxs("div",{className:"border border-[#dde3eb] rounded-xl bg-white overflow-hidden shadow-sm",children:[e.jsxs("button",{onClick:()=>Lt(ye?null:x),className:"w-full flex items-center justify-between p-4 hover:bg-[#f7f9fc] transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-1 h-6 bg-[#9b51e0] rounded-full"}),e.jsxs("div",{className:"text-left",children:[e.jsx("p",{className:"font-bold text-[#0a1628] text-sm",children:x}),e.jsxs("p",{className:"text-xs text-slate-500",children:[O.length," topics"]})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("span",{className:"bg-purple-100 text-[#9b51e0] px-2.5 py-0.5 rounded-full text-xs font-semibold",children:[U," selected"]}),ye?e.jsx(Ca,{size:18,className:"text-slate-400"}):e.jsx($t,{size:18,className:"text-slate-400"})]})]}),e.jsx(zt,{children:ye&&e.jsx(Le.div,{initial:{height:0},animate:{height:"auto"},exit:{height:0},className:"overflow-hidden border-t border-[#edf1f7]",children:e.jsx("div",{className:"py-2",children:O.map((Qe,Ze)=>{const Vt=f.includes(Qe),Zs=w.includes(Qe),mt=Vt&&!Zs;let Jt="Core";return Ze%3===0&&(Jt="Foundation"),Ze%3===2&&(Jt="Advanced"),e.jsxs("div",{className:"flex items-center justify-between px-6 py-3 hover:bg-[#f7f9fc]",children:[e.jsxs("label",{className:"flex items-center gap-3 cursor-pointer flex-1",children:[e.jsx("div",{className:`w-5 h-5 rounded flex items-center justify-center transition-colors ${mt?"bg-[#9b51e0] border-[#9b51e0]":"border-2 border-[#dde3eb] bg-white"}`,children:mt&&e.jsx(Ht,{size:14,className:"text-white"})}),e.jsx("input",{type:"checkbox",className:"hidden",checked:mt,onChange:()=>Ga(Qe)}),e.jsx("span",{className:`text-sm font-semibold ${mt?"text-[#0a1628]":"text-[#5a6578]"}`,children:Qe})]}),e.jsx("span",{className:`border px-3 py-1 rounded-full text-[10px] uppercase font-bold tracking-wider ${Jt==="Advanced"?"bg-white text-slate-400 border-[#dde3eb]":"bg-purple-50 text-[#9b51e0] border-purple-100"}`,children:Jt})]},Qe)})})})})]},x)})})]}),v==="style"&&!te&&e.jsxs("div",{className:"w-full px-[24px] xl:px-[32px] flex-1 space-y-[24px] pb-8",children:[e.jsxs("div",{className:"bg-white/80 backdrop-blur-[12px] rounded-[20px] border border-[#e2e8f0] shadow-sm overflow-hidden hover:shadow-[0_8px_24px_rgba(0,0,0,0.04)] transition-shadow duration-300",children:[e.jsx("div",{className:"p-5 border-b border-[#f1f5f9] bg-white/50",children:e.jsx("h3",{className:"text-[11px] font-bold text-[#64748b] uppercase tracking-wider",children:"Question Types"})}),e.jsx("div",{className:"p-4 grid grid-cols-2 sm:grid-cols-5 gap-3",children:Object.entries(Wa).map(([x,O])=>{const U=A.includes(x);return e.jsxs("button",{onClick:()=>Bt(x),className:`border-2 rounded-[16px] p-4 flex flex-col items-center justify-center text-center cursor-pointer transition-all duration-300 relative overflow-hidden group hover:-translate-y-1 ${U?"border-[#a855f7] bg-gradient-to-b from-purple-50/80 to-white/80 shadow-[0_4px_12px_rgba(168,85,247,0.12)]":"border-slate-100 bg-slate-50/50 shadow-sm hover:shadow-md hover:border-purple-200"}`,children:[U&&e.jsx("div",{className:"absolute top-2 right-2 w-5 h-5 bg-gradient-to-br from-[#a855f7] to-[#9333ea] rounded-full flex items-center justify-center shadow-md",children:e.jsx(Ht,{size:11,className:"text-white"})}),e.jsx("div",{className:`w-12 h-12 rounded-full flex items-center justify-center mb-3 group-hover:scale-110 transition-transform duration-300 ${U?"bg-white border border-purple-200 shadow-md":"bg-white border border-slate-200 shadow-sm group-hover:shadow-md"}`,children:e.jsx("span",{className:U?"text-[#a855f7]":"text-slate-500",children:O.icon})}),e.jsx("span",{className:`font-bold text-[12px] leading-tight ${U?"text-[#9333ea]":"text-slate-700"}`,children:O.label})]},x)})})]}),e.jsxs("div",{className:"bg-white/80 backdrop-blur-[12px] rounded-[20px] border border-[#e2e8f0] shadow-sm overflow-hidden hover:shadow-[0_8px_24px_rgba(0,0,0,0.04)] transition-shadow duration-300",children:[e.jsx("div",{className:"p-5 border-b border-[#f1f5f9] bg-white/50",children:e.jsx("h3",{className:"text-[11px] font-bold text-[#64748b] uppercase tracking-wider",children:"Bloom's Taxonomy Levels"})}),e.jsx("div",{className:"p-6 flex flex-wrap gap-4",children:Object.entries(Do).map(([x,O])=>{const U=q.includes(x);return e.jsx("button",{onClick:()=>Ye(x),className:`px-6 py-2.5 rounded-full border-2 font-bold text-[13px] transition-all duration-200 hover:-translate-y-0.5 capitalize ${U?"border-[#a855f7] text-[#9333ea] bg-purple-50/80 shadow-[0_2px_8px_rgba(168,85,247,0.15)]":"border-slate-200 text-[#64748b] bg-white shadow-sm hover:border-slate-300 hover:bg-slate-50"}`,children:x},x)})})]}),e.jsxs("div",{className:"bg-white/80 backdrop-blur-[12px] rounded-[20px] border border-[#e2e8f0] shadow-sm overflow-hidden hover:shadow-[0_8px_24px_rgba(0,0,0,0.04)] transition-shadow duration-300",children:[e.jsx("div",{className:"p-5 border-b border-[#f1f5f9] bg-white/50",children:e.jsx("h3",{className:"text-[11px] font-bold text-[#64748b] uppercase tracking-wider",children:"Difficulty Distribution"})}),e.jsx("div",{className:"p-8 space-y-8",children:Object.entries(ne).map(([x,O])=>{const U={easy:"bg-emerald-400",medium:"bg-amber-400",hard:"bg-rose-400"},ye={easy:"text-emerald-600",medium:"text-amber-500",hard:"text-rose-500"},Qe={easy:"group-hover:border-emerald-200",medium:"group-hover:border-amber-200",hard:"group-hover:border-rose-200"};return e.jsxs("div",{className:"flex items-center gap-6 group",children:[e.jsx("span",{className:`w-16 text-[13px] font-bold text-[#475569] capitalize group-hover:${ye[x]} transition-colors`,children:x}),e.jsx("div",{className:"flex-1 bg-slate-100 h-3 rounded-full overflow-hidden shadow-inner",children:e.jsx(Le.div,{animate:{width:`${O}%`},className:`h-full rounded-full transition-all duration-500 ease-out ${U[x]}`})}),e.jsxs("div",{className:`flex items-center bg-white border border-[#e2e8f0] rounded-xl shadow-sm overflow-hidden p-0.5 w-28 h-10 transition-colors ${Qe[x]}`,children:[e.jsx("button",{onClick:()=>De(x,-5),className:`w-8 h-full flex items-center justify-center text-[#64748b] hover:bg-slate-50 hover:${ye[x]} rounded-lg transition-colors`,children:e.jsx(Pn,{className:"w-3.5 h-3.5"})}),e.jsx("input",{type:"text",value:`${O}%`,readOnly:!0,className:"flex-1 text-center font-bold text-[14px] text-[#1e293b] border-none outline-none focus:ring-0 w-full p-0 pointer-events-none"}),e.jsx("button",{onClick:()=>De(x,5),className:`w-8 h-full flex items-center justify-center text-[#64748b] hover:bg-slate-50 hover:${ye[x]} rounded-lg transition-colors`,children:e.jsx(da,{className:"w-3.5 h-3.5"})})]})]},x)})})]})]}),v==="preview"&&!te&&!ae&&e.jsx("div",{className:"w-full px-[24px] xl:px-[32px] flex-1 space-y-[24px] pb-8",children:e.jsxs("div",{className:"bg-white/80 backdrop-blur-md rounded-[20px] border border-[#e2e8f0] shadow-[0_8px_24px_rgba(0,0,0,0.04)] overflow-hidden p-8",children:[e.jsxs("h3",{className:"text-[12px] font-bold text-[#64748b] uppercase tracking-wider mb-6 flex items-center gap-2",children:[e.jsx(Ls,{size:16,className:"text-[#a855f7]"})," Quiz Summary"]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-6 mb-6",children:[{label:"Questions",value:R},{label:"Topics",value:f.filter(x=>!w.includes(x)).length},{label:"Level",value:I.replace("Grade ","Gr. ")}].map(x=>e.jsxs("div",{className:"relative overflow-hidden bg-gradient-to-br from-purple-50 to-indigo-50 rounded-[16px] p-6 text-center border border-purple-100/50 shadow-sm flex flex-col items-center justify-center group hover:-translate-y-1 transition-transform",children:[e.jsx("div",{className:"absolute -right-4 -top-4 w-16 h-16 bg-purple-200/30 rounded-full group-hover:scale-150 transition-transform duration-500"}),e.jsx("span",{className:"text-[36px] font-extrabold text-transparent bg-clip-text bg-gradient-to-r from-[#a855f7] to-[#9333ea] leading-none mb-1 relative z-10",children:x.value}),e.jsx("span",{className:"text-[13px] font-bold text-[#64748b] relative z-10",children:x.label})]},x.label))}),e.jsxs("div",{className:"bg-slate-50/80 rounded-[14px] p-5 border border-slate-200/60 text-[#475569] text-[14px] leading-relaxed flex gap-4 items-start shadow-inner",children:[e.jsx(na,{size:18,className:"text-[#94a3b8] shrink-0 mt-0.5"}),e.jsxs("p",{children:[A.map(x=>Wa[x]?.label).join(" and ")," questions across"," ",e.jsxs("span",{className:"font-bold text-[#1e293b]",children:[f.filter(x=>!w.includes(x)).length," topics"]})," ","— aligned to ",e.jsx("span",{className:"font-semibold",children:q.map(x=>Do[x]?.label).join(", ")})," levels of Bloom's Taxonomy."," ",e.jsxs("span",{className:"font-semibold text-emerald-600",children:["Easy ",ne.easy,"%"]})," • ",e.jsxs("span",{className:"font-semibold text-amber-500",children:["Medium ",ne.medium,"%"]})," • ",e.jsxs("span",{className:"font-semibold text-rose-500",children:["Hard ",ne.hard,"%"]}),"."]})]})]})}),v==="results"&&ae&&e.jsxs("div",{className:"w-full px-[24px] xl:px-[32px] space-y-[24px] pb-8",children:[e.jsxs("div",{className:"bg-white/80 backdrop-blur-md rounded-[20px] border border-[#e2e8f0] shadow-[0_8px_24px_rgba(0,0,0,0.04)] p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h3",{className:"text-lg font-bold font-display text-[#0a1628]",children:"Quiz Generated"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:Tl,className:"flex items-center gap-1.5 px-3 py-1.5 bg-white border border-[#dde3eb] rounded-lg text-xs font-medium text-[#5a6578] hover:bg-[#edf1f7] transition-colors",children:[ft?e.jsx(Ht,{size:14,className:"text-green-500"}):e.jsx(Vr,{size:14}),ft?"Copied!":"Copy All"]}),e.jsxs("button",{onClick:_l,className:"flex items-center gap-1.5 px-3 py-1.5 bg-white border border-[#dde3eb] rounded-lg text-xs font-medium text-[#5a6578] hover:bg-[#edf1f7] transition-colors",children:[e.jsx(bc,{size:14}),"Export JSON"]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4 md:gap-6",children:[e.jsxs("div",{className:"relative overflow-hidden bg-gradient-to-br from-[#a855f7] to-[#9333ea] text-white shadow-[0_8px_16px_rgba(168,85,247,0.25)] rounded-[20px] p-6 text-center flex flex-col items-center justify-center group hover:-translate-y-1 transition-transform",children:[e.jsx("div",{className:"absolute -right-4 -top-4 w-20 h-20 bg-white/10 rounded-full group-hover:scale-150 transition-transform duration-500"}),e.jsx(Rs,{size:22,className:"text-white/80 mb-2 relative z-10"}),e.jsx("span",{className:"text-[32px] font-extrabold leading-none mb-1 relative z-10 drop-shadow-sm",children:ae.questions.length}),e.jsx("span",{className:"text-[12px] font-bold text-white/90 uppercase tracking-widest relative z-10",children:"Questions"})]}),e.jsxs("div",{className:"relative overflow-hidden bg-gradient-to-br from-[#f43f5e] to-[#e11d48] text-white shadow-[0_8px_16px_rgba(244,63,94,0.25)] rounded-[20px] p-6 text-center flex flex-col items-center justify-center group hover:-translate-y-1 transition-transform",children:[e.jsx("div",{className:"absolute -right-4 -top-4 w-20 h-20 bg-white/10 rounded-full group-hover:scale-150 transition-transform duration-500"}),e.jsx(ms,{size:22,className:"text-white/80 mb-2 relative z-10"}),e.jsx("span",{className:"text-[32px] font-extrabold leading-none mb-1 relative z-10 drop-shadow-sm",children:ae.totalPoints}),e.jsx("span",{className:"text-[12px] font-bold text-white/90 uppercase tracking-widest relative z-10",children:"Total Points"})]}),e.jsxs("div",{className:"relative overflow-hidden bg-gradient-to-br from-[#f59e0b] to-[#d97706] text-white shadow-[0_8px_16px_rgba(245,158,11,0.25)] rounded-[20px] p-6 text-center flex flex-col items-center justify-center group hover:-translate-y-1 transition-transform",children:[e.jsx("div",{className:"absolute -right-4 -top-4 w-20 h-20 bg-white/10 rounded-full group-hover:scale-150 transition-transform duration-500"}),e.jsx(Gt,{size:22,className:"text-white/80 mb-2 relative z-10"}),e.jsx("span",{className:"text-[32px] font-extrabold leading-none mb-1 relative z-10 drop-shadow-sm",children:Object.keys(ae.metadata.topicsCovered).length}),e.jsx("span",{className:"text-[12px] font-bold text-white/90 uppercase tracking-widest relative z-10",children:"Topics"})]}),e.jsxs("div",{className:"relative overflow-hidden bg-gradient-to-br from-[#10b981] to-[#059669] text-white shadow-[0_8px_16px_rgba(16,185,129,0.25)] rounded-[20px] p-6 text-center flex flex-col items-center justify-center group hover:-translate-y-1 transition-transform",children:[e.jsx("div",{className:"absolute -right-4 -top-4 w-20 h-20 bg-white/10 rounded-full group-hover:scale-150 transition-transform duration-500"}),e.jsx(lr,{size:22,className:"text-white/80 mb-2 relative z-10"}),e.jsx("span",{className:"text-[32px] font-extrabold leading-none mb-1 relative z-10 drop-shadow-sm",children:Object.keys(ae.metadata.bloomTaxonomyDistribution).length}),e.jsx("span",{className:"text-[12px] font-bold text-white/90 uppercase tracking-widest relative z-10",children:"Bloom Levels"})]})]}),(ae.metadata.usedImportedTopics||(ae.metadata.topicProvenance||[]).length>0)&&e.jsxs("div",{className:"mt-4 bg-white rounded-lg p-3 border border-[#dde3eb]",children:[e.jsx("p",{className:"text-xs font-semibold text-[#5a6578] mb-2",children:"Imported Topic Provenance"}),e.jsxs("p",{className:"text-xs text-[#5a6578] mb-2",children:["Imported topics used: ",ae.metadata.usedImportedTopics?"Yes":"No"," • ","Materials: ",ae.metadata.importedMaterialsCount??0," • ","Topics: ",ae.metadata.importedTopicCount??0]}),(ae.metadata.topicProvenance||[]).slice(0,5).map((x,O)=>e.jsxs("div",{className:"text-xs text-[#5a6578]",children:[x.title||"Untitled topic",x.sourceFile?` • ${x.sourceFile}`:""]},`${x.topicId||x.title||"topic"}_${O}`)),(Ee.length>0||Oe.length>0)&&e.jsxs("div",{className:"mt-3 grid grid-cols-1 md:grid-cols-2 gap-2",children:[e.jsxs("label",{className:"text-xs text-[#5a6578] flex flex-col gap-1",children:[e.jsx("span",{className:"font-semibold",children:"Filter by Source File"}),e.jsxs("select",{value:ns,onChange:x=>vs(x.target.value),className:"bg-white border border-[#dde3eb] rounded-md px-2 py-1.5 text-xs",children:[e.jsx("option",{value:"all",children:"All sources"}),Ee.map(x=>e.jsx("option",{value:x,children:x},x))]})]}),e.jsxs("label",{className:"text-xs text-[#5a6578] flex flex-col gap-1",children:[e.jsx("span",{className:"font-semibold",children:"Filter by Material ID"}),e.jsxs("select",{value:os,onChange:x=>L(x.target.value),className:"bg-white border border-[#dde3eb] rounded-md px-2 py-1.5 text-xs",children:[e.jsx("option",{value:"all",children:"All materials"}),Oe.map(x=>e.jsx("option",{value:x,children:x},x))]})]})]}),e.jsxs("p",{className:"text-[11px] text-[#5a6578] mt-2",children:["Showing ",Pt.length," of ",ae.questions.length," questions after provenance filters."]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-6 mt-8 mb-10",children:[e.jsxs("div",{className:"bg-white border border-[#e2e8f0] rounded-[16px] p-6 shadow-sm border-t-[4px] border-t-[#10b981] hover:shadow-md transition-shadow",children:[e.jsxs("h4",{className:"text-[12px] font-bold text-[#64748b] uppercase tracking-wider mb-5 flex items-center gap-2",children:[e.jsx(Ls,{size:14})," Difficulty"]}),e.jsx("div",{className:"space-y-3 text-[14px] font-medium text-[#475569]",children:Object.entries(ae.metadata.difficultyBreakdown).map(([x,O])=>e.jsxs("div",{className:"flex justify-between items-center bg-slate-50 px-3 py-2 rounded-lg",children:[e.jsx("span",{className:`font-bold capitalize ${km[x]||"text-[#475569]"}`,children:x}),e.jsx("span",{className:"font-bold text-[#1e293b] bg-white px-2 py-0.5 rounded shadow-sm border border-slate-100",children:O})]},x))})]}),e.jsxs("div",{className:"bg-white border border-[#e2e8f0] rounded-[16px] p-6 shadow-sm border-t-[4px] border-t-[#a855f7] hover:shadow-md transition-shadow",children:[e.jsxs("h4",{className:"text-[12px] font-bold text-[#64748b] uppercase tracking-wider mb-5 flex items-center gap-2",children:[e.jsx(Ur,{size:14})," Bloom's Taxonomy"]}),e.jsx("div",{className:"space-y-3 text-[14px] font-medium text-[#475569]",children:Object.entries(ae.metadata.bloomTaxonomyDistribution).map(([x,O])=>e.jsxs("div",{className:"flex justify-between items-center bg-slate-50 px-3 py-2 rounded-lg",children:[e.jsx("span",{className:"text-[#1e293b] font-semibold capitalize",children:x}),e.jsx("span",{className:"font-bold text-[#1e293b] bg-white px-2 py-0.5 rounded shadow-sm border border-slate-100",children:O})]},x))})]}),e.jsxs("div",{className:"bg-white border border-[#e2e8f0] rounded-[16px] p-6 shadow-sm border-t-[4px] border-t-[#0ea5e9] hover:shadow-md transition-shadow",children:[e.jsxs("h4",{className:"text-[12px] font-bold text-[#64748b] uppercase tracking-wider mb-5 flex items-center gap-2",children:[e.jsx(lr,{size:14})," Question Types"]}),e.jsx("div",{className:"space-y-3 text-[14px] font-medium text-[#475569]",children:Object.entries(ae.metadata.questionTypeBreakdown).map(([x,O])=>e.jsxs("div",{className:"flex justify-between items-center bg-slate-50 px-3 py-2 rounded-lg",children:[e.jsx("span",{className:"text-[#1e293b] font-semibold",children:Wa[x]?.label||x}),e.jsx("span",{className:"font-bold text-[#1e293b] bg-white px-2 py-0.5 rounded shadow-sm border border-slate-100",children:O})]},x))})]})]}),e.jsxs("div",{className:"bg-gradient-to-r from-purple-50 to-indigo-50/50 border border-purple-100 rounded-[16px] p-6 mb-10 flex items-start gap-4 shadow-sm relative overflow-hidden",children:[e.jsx("div",{className:"absolute top-0 left-0 w-1.5 h-full bg-[#a855f7]"}),e.jsx("div",{className:"bg-white p-2 rounded-full shadow-sm shrink-0",children:e.jsx(na,{size:18,className:"text-[#9333ea]"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[14px] font-bold text-[#9333ea] mb-3",children:ae.metadata.supplementalPurpose||"This quiz is designed to supplement classroom instruction, not replace teacher-led learning."}),ae.metadata.recommendedTeacherActions&&ae.metadata.recommendedTeacherActions.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] font-bold text-[#1e293b] mb-2",children:"Recommended Actions:"}),e.jsx("ul",{className:"list-disc pl-5 text-[13px] font-medium text-[#475569] space-y-1.5",children:ae.metadata.recommendedTeacherActions.map((x,O)=>e.jsx("li",{children:x},O))})]})]})]})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("h3",{className:"text-[18px] font-bold text-[#1e293b] flex items-center gap-2",children:[e.jsx(yi,{size:20,className:"text-[#a855f7]"})," Review Questions"]}),e.jsx("div",{className:"space-y-4",children:Pt.length>0?Pt.map((x,O)=>zl(x,O)):e.jsx("div",{className:"border border-[#dde3eb] rounded-xl p-4 bg-white text-sm text-[#5a6578]",children:"No questions match the selected provenance filters. Clear one or both filters to view all questions."})})]})]})]})]}),k==="create"&&e.jsx("div",{className:"sticky bottom-0 mt-auto w-full bg-white/90 backdrop-blur-[12px] border-t border-[#e2e8f0] z-30 shadow-[0_-4px_12px_rgba(0,0,0,0.03)]",children:e.jsxs("div",{className:"w-full px-6 xl:px-8 py-4 flex items-center justify-between",children:[e.jsxs("div",{children:[v==="topics"&&!te&&e.jsx("button",{onClick:()=>{C([]),$([])},className:"text-[13px] font-semibold text-[#a855f7] hover:underline",children:"Clear all"}),(v==="style"||v==="preview")&&!te&&e.jsxs("button",{onClick:()=>g(v==="preview"?"style":"topics"),className:"bg-white hover:bg-slate-50 border border-slate-200 text-[#475569] text-[14px] font-semibold rounded-full px-6 py-2.5 shadow-sm transition-transform hover:scale-[1.02] flex items-center gap-2",children:[e.jsx(zs,{size:16})," Back"]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[v==="setup"&&!te&&e.jsxs("button",{onClick:()=>g("topics"),className:"bg-[#a855f7] hover:bg-[#9333ea] text-white text-[14px] font-semibold rounded-full px-8 py-2.5 shadow-[0_4px_12px_rgba(168,85,247,0.3)] transition-transform hover:scale-[1.02] flex items-center gap-2",children:["Next: Topics ",e.jsx(Ms,{size:16})]}),v==="topics"&&!te&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:()=>g("setup"),className:"bg-white hover:bg-slate-50 border border-slate-200 text-[#475569] text-[14px] font-semibold rounded-full px-6 py-2.5 shadow-sm transition-transform hover:scale-[1.02] flex items-center gap-2",children:[e.jsx(zs,{size:16})," Back"]}),e.jsxs("button",{onClick:()=>g("style"),className:"bg-[#a855f7] hover:bg-[#9333ea] text-white text-[14px] font-semibold rounded-full px-6 py-2.5 shadow-[0_4px_12px_rgba(168,85,247,0.3)] transition-transform hover:scale-[1.02] flex items-center gap-2",children:["Next: Question Style ",e.jsx(Ms,{size:16})]})]}),v==="style"&&!te&&e.jsxs("button",{onClick:()=>g("preview"),className:"bg-[#a855f7] hover:bg-[#9333ea] text-white text-[14px] font-semibold rounded-full px-8 py-2.5 shadow-[0_4px_12px_rgba(168,85,247,0.3)] transition-transform hover:scale-[1.02] flex items-center gap-2",children:["Next: Preview ",e.jsx(Ms,{size:16})]}),v==="preview"&&!te&&!ae&&e.jsxs("button",{onClick:Il,className:"bg-[#a855f7] hover:bg-[#9333ea] text-white text-[14px] font-bold rounded-full px-8 py-2.5 shadow-[0_4px_12px_rgba(168,85,247,0.3)] transition-all hover:scale-[1.02] flex items-center gap-2",children:[e.jsx(Ht,{size:16})," Generate Quiz"]}),te&&e.jsxs("div",{className:"flex items-center gap-3 text-slate-500 font-medium text-sm",children:[e.jsx(gt,{size:16,className:"animate-spin"})," Generating quiz... Please wait."]}),v==="results"&&(Ua?e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>{N("bank"),Us(null)},className:"bg-white hover:bg-slate-50 border border-slate-200 text-[#475569] text-[14px] font-semibold rounded-full px-6 py-2.5 shadow-sm transition-transform hover:scale-[1.02]",children:"Back to Quiz Bank"}),e.jsxs("button",{onClick:()=>Ir(Ua),className:"bg-white border border-[#a855f7] text-[#9333ea] hover:bg-purple-50 text-[14px] font-bold rounded-full px-8 py-2.5 shadow-sm transition-transform hover:scale-[1.02] flex items-center gap-2",children:[e.jsx(aa,{size:16})," Assign"]}),e.jsx("button",{onClick:Cn,className:"bg-[#a855f7] hover:bg-[#9333ea] text-white text-[14px] font-bold rounded-full px-10 py-2.5 shadow-[0_4px_12px_rgba(168,85,247,0.3)] transition-transform hover:scale-[1.02]",children:"Done"})]}):e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>{g("setup"),Ce(null),Je(null),kt(null),Us(null)},className:"bg-white hover:bg-slate-50 border border-slate-200 text-[#475569] text-[14px] font-semibold rounded-full px-6 py-2.5 shadow-sm transition-transform hover:scale-[1.02]",children:"Create Another"}),B?e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:Rl,disabled:Me,className:"bg-white border border-[#a855f7] text-[#9333ea] hover:bg-purple-50 text-[14px] font-bold rounded-full px-8 py-2.5 shadow-sm transition-transform hover:scale-[1.02] flex items-center gap-2",children:[Me?e.jsx(gt,{size:16,className:"animate-spin"}):e.jsx(la,{size:16})," Publish"]}),e.jsxs("button",{onClick:()=>Ir(),className:"bg-[#a855f7] hover:bg-[#9333ea] text-white text-[14px] font-bold rounded-full px-8 py-2.5 shadow-[0_4px_12px_rgba(168,85,247,0.3)] transition-transform hover:scale-[1.02] flex items-center gap-2",children:[e.jsx(aa,{size:16})," Assign to Class"]})]}):e.jsxs("button",{onClick:El,disabled:me,className:"bg-emerald-600 hover:bg-emerald-700 text-white px-8 py-2.5 rounded-full font-bold shadow-lg shadow-emerald-500/30 hover:-translate-y-1 transition-all flex items-center gap-2 text-[14px]",children:[me?e.jsx(gt,{size:16,className:"animate-spin"}):e.jsx(Ni,{size:16})," Save to Library"]}),e.jsx("button",{onClick:Cn,className:"bg-[#a855f7] hover:bg-[#9333ea] text-white text-[14px] font-bold rounded-full px-10 py-2.5 shadow-[0_4px_12px_rgba(168,85,247,0.3)] transition-transform hover:scale-[1.02]",children:"Done"})]}))]})]})}),e.jsx(wm,{isOpen:bs,onClose:()=>Bs(!1)}),e.jsx(zt,{children:F&&e.jsx(Le.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 bg-black/40 z-[60] flex items-center justify-center p-4",onClick:()=>ve(!1),children:e.jsxs(Le.div,{initial:{scale:.95,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.95,opacity:0},className:"bg-[#f7f9fc] rounded-2xl shadow-2xl w-full max-w-md max-h-[70vh] flex flex-col overflow-hidden border border-[#dde3eb]",onClick:x=>x.stopPropagation(),children:[e.jsxs("div",{className:"px-5 py-4 border-b border-[#dde3eb] flex items-center justify-between",children:[e.jsxs("h3",{className:"text-base font-bold font-display text-[#0a1628] flex items-center gap-2",children:[e.jsx(us,{size:18,className:"text-sky-600"}),"Assign to Student"]}),e.jsx("button",{onClick:()=>ve(!1),className:"p-1 hover:bg-[#edf1f7] rounded-lg transition-colors",children:e.jsx(Xt,{size:16,className:"text-slate-500"})})]}),e.jsx("div",{className:"px-5 py-3 border-b border-[#dde3eb]",children:e.jsxs("div",{className:"flex items-center gap-2 bg-[#edf1f7] rounded-xl px-3 py-2",children:[e.jsx(qs,{size:14,className:"text-slate-500"}),e.jsx("input",{type:"text",placeholder:"Search students…",value:rt,onChange:x=>nt(x.target.value),className:"flex-1 bg-transparent text-sm outline-none placeholder:text-slate-500"})]})}),e.jsx("div",{className:"flex-1 overflow-y-auto p-3 space-y-1",children:lt?e.jsx("div",{className:"flex items-center justify-center py-10",children:e.jsx(gt,{size:20,className:"animate-spin text-sky-500"})}):En.length===0?e.jsx("p",{className:"text-center text-sm text-slate-500 py-10",children:"No students found"}):En.map(x=>e.jsxs("button",{onClick:()=>ws(x.id),className:`w-full flex items-center gap-3 px-3 py-2.5 rounded-xl text-left transition-colors ${ut===x.id?"bg-sky-50 border border-sky-300":"hover:bg-[#edf1f7] border border-transparent"}`,children:[e.jsx("img",{src:x.avatar&&!x.avatar.includes("ui-avatars.com")?x.avatar:Ja(x.gender),alt:x.name,className:"w-8 h-8 rounded-lg object-cover"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-semibold text-[#0a1628] truncate",children:x.name}),e.jsx("p",{className:"text-xs text-slate-500 truncate",children:x.email})]}),ut===x.id&&e.jsx(Ht,{size:16,className:"text-sky-600 flex-shrink-0"})]},x.id))}),e.jsxs("div",{className:"px-5 py-3 border-t border-[#dde3eb] flex justify-end gap-2",children:[e.jsx("button",{onClick:()=>ve(!1),className:"px-4 py-2 text-sm font-medium text-[#5a6578] hover:bg-[#edf1f7] rounded-xl transition-colors",children:"Cancel"}),e.jsxs("button",{onClick:Ml,disabled:!ut||we,className:`flex items-center gap-2 px-4 py-2 rounded-xl text-sm font-bold transition-all ${ut&&!we?"bg-gradient-to-r from-sky-600 to-sky-500 text-white shadow-sm":"bg-[#dde3eb] text-slate-500 cursor-not-allowed"}`,children:[we?e.jsx(gt,{size:14,className:"animate-spin"}):e.jsx(aa,{size:14}),"Assign"]})]})]})})})]});return d?e.jsx("div",{className:"w-full h-full flex flex-col overflow-hidden bg-white",children:An}):An},Cm=({onOpenNotifications:t,onOpenProfile:s,onOpenInsightModal:a,userPhoto:r,teacherName:o})=>{const[n,i]=u.useState([]),[l,c]=u.useState(!1),[d,m]=u.useState(!1),[p,h]=u.useState(""),[b,S]=u.useState(11),[k,N]=u.useState("general_mathematics"),[v,g]=u.useState([]),[I,z]=u.useState(!1),[R,W]=u.useState(null),f=u.useCallback(async()=>{z(!0);try{const y=At(Mt(He,"question_bank",String(b),k,"questions","questions"),or(50));let J=(await Ot(y)).docs.map(re=>{const le=re.data();return{id:re.id,question:le.question||"",choices:le.choices||[],correct_answer:le.correct_answer||"",explanation:le.explanation||"",topic:le.topic||"",difficulty:le.difficulty||"medium",grade_level:le.grade_level||11}});if(J.length===0){const re=At(Mt(He,"quizBattleQuestionBank"),or(50));J=(await Ot(re)).docs.map(ne=>{const be=ne.data();return{id:ne.id,question:be.question||"",choices:be.choices||[],correct_answer:be.correct_answer||"",explanation:be.explanation||"",topic:be.topic||"",difficulty:be.difficulty||"medium",grade_level:be.grade_level||11}})}g(J)}catch(y){console.warn("[QuestionBankPanel] Failed to load questions:",y)}finally{z(!1)}},[b,k]);u.useEffect(()=>{f()},[f]);const C=u.useCallback(async()=>{c(!0);try{const y=await Dn("/api/quiz-battle/bank-status");i(y.pdfs)}catch(y){const q=y instanceof rr?y.message:"Failed to load bank status";ie.error(q)}finally{c(!1)}},[]);u.useEffect(()=>{C()},[C]);const w=async()=>{if(!p.trim()){ie.error("Please enter a storage path");return}m(!0);try{await Dn("/api/quiz-battle/ingest-pdf",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({storage_path:p.trim(),grade_level:b,topic:k.trim(),force_reingest:!1})}),ie.success("PDF ingestion completed"),await C(),h("")}catch(y){const q=y instanceof rr?y.message:"Ingestion failed";ie.error(q)}finally{m(!1)}},$=n.reduce((y,q)=>y+q.question_count,0),A=n.filter(y=>y.processed).length;return e.jsxs("div",{className:"w-full h-full flex flex-col overflow-y-auto bg-gradient-to-br from-[#f8fafc] to-[#f1f5f9]",children:[e.jsx("div",{className:"w-full px-[24px] xl:px-[32px] pt-[12px] pb-2"}),e.jsxs("div",{className:"w-full px-[24px] xl:px-[32px] pb-[32px] space-y-[32px]",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-6",children:[e.jsxs("div",{className:"relative overflow-hidden bg-gradient-to-br from-[#3b82f6] to-[#2563eb] rounded-[16px] p-[20px] shadow-[0_4px_12px_rgba(59,130,246,0.2)] hover:shadow-[0_8px_24px_rgba(59,130,246,0.3)] hover:-translate-y-1 transition-all duration-300 flex flex-col justify-between group text-white",children:[e.jsx("div",{className:"absolute -right-12 -bottom-12 w-40 h-40 bg-white/10 rounded-full transition-transform duration-500 group-hover:scale-[1.8] group-hover:-translate-y-4 group-hover:-translate-x-4"}),e.jsxs("div",{className:"flex items-start justify-between relative z-10 mb-4",children:[e.jsx("span",{className:"text-[13px] font-medium text-white/90",children:"Total PDFs"}),e.jsx("div",{className:"w-8 h-8 rounded-full border border-white/30 flex items-center justify-center bg-white/10",children:e.jsx(Rs,{size:16,className:"text-white"})})]}),e.jsx("div",{className:"text-[32px] font-bold relative z-10 leading-none",children:n.length})]}),e.jsxs("div",{className:"relative overflow-hidden bg-gradient-to-br from-[#a855f7] to-[#9333ea] rounded-[16px] p-[20px] shadow-[0_4px_12px_rgba(168,85,247,0.2)] hover:shadow-[0_8px_24px_rgba(168,85,247,0.3)] hover:-translate-y-1 transition-all duration-300 flex flex-col justify-between group text-white",children:[e.jsx("div",{className:"absolute -right-12 -bottom-12 w-40 h-40 bg-white/10 rounded-full transition-transform duration-500 group-hover:scale-[1.8] group-hover:-translate-y-4 group-hover:-translate-x-4"}),e.jsxs("div",{className:"flex items-start justify-between relative z-10 mb-4",children:[e.jsx("span",{className:"text-[13px] font-medium text-white/90",children:"Total Questions"}),e.jsx("div",{className:"w-8 h-8 rounded-full border border-white/30 flex items-center justify-center bg-white/10",children:e.jsx(Gt,{size:16,className:"text-white"})})]}),e.jsx("div",{className:"text-[32px] font-bold relative z-10 leading-none",children:$})]}),e.jsxs("div",{className:"relative overflow-hidden bg-gradient-to-br from-[#10b981] to-[#059669] rounded-[16px] p-[20px] shadow-[0_4px_12px_rgba(16,185,129,0.2)] hover:shadow-[0_8px_24px_rgba(16,185,129,0.3)] hover:-translate-y-1 transition-all duration-300 flex flex-col justify-between group text-white",children:[e.jsx("div",{className:"absolute -right-12 -bottom-12 w-40 h-40 bg-white/10 rounded-full transition-transform duration-500 group-hover:scale-[1.8] group-hover:-translate-y-4 group-hover:-translate-x-4"}),e.jsxs("div",{className:"flex items-start justify-between relative z-10 mb-4",children:[e.jsx("span",{className:"text-[13px] font-medium text-white/90",children:"Processed"}),e.jsx("div",{className:"w-8 h-8 rounded-full border border-white/30 flex items-center justify-center bg-white/10",children:e.jsx(cs,{size:16,className:"text-white"})})]}),e.jsx("div",{className:"text-[32px] font-bold relative z-10 leading-none",children:A})]})]}),e.jsx("div",{className:"bg-white/80 backdrop-blur-[12px] rounded-[24px] border border-white shadow-[0_8px_32px_rgba(0,0,0,0.04)] overflow-hidden",children:e.jsxs("div",{className:"p-[24px] sm:p-[32px]",children:[e.jsxs("h2",{className:"text-[20px] font-bold text-[#1e293b] mb-6 flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-[10px] bg-gradient-to-br from-[#a855f7] to-[#9333ea] flex items-center justify-center shadow-md shadow-purple-500/20",children:e.jsx(Wr,{className:"w-4 h-4 text-white"})}),"Ingest New PDF"]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-12 gap-6 items-end",children:[e.jsxs("div",{className:"md:col-span-6 group",children:[e.jsx("label",{className:"text-[13px] font-bold text-[#1e293b] mb-2 block group-hover:text-[#a855f7] transition-colors",children:"Firebase Storage Path"}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-y-0 left-0 pl-4 flex items-center pointer-events-none",children:e.jsx(Rs,{className:"h-4 w-4 text-[#94a3b8] group-hover:text-[#a855f7] transition-colors"})}),e.jsx("input",{type:"text",placeholder:"quiz_pdfs/grade_11/gen_math_q1.pdf",value:p,onChange:y=>h(y.target.value),className:"w-full bg-slate-50 border border-slate-200 hover:border-[#cbd5e1] text-[#475569] text-[14px] font-medium rounded-xl pl-11 pr-4 py-3.5 outline-none focus:bg-white focus:border-[#a855f7] focus:ring-4 focus:ring-[#a855f7]/10 transition-all shadow-inner"})]})]}),e.jsxs("div",{className:"md:col-span-2 group",children:[e.jsx("label",{className:"text-[13px] font-bold text-[#1e293b] mb-2 block group-hover:text-[#a855f7] transition-colors",children:"Grade Level"}),e.jsx("input",{type:"number",placeholder:"11",min:7,max:12,value:b,onChange:y=>S(Number(y.target.value)),className:"w-full bg-slate-50 border border-slate-200 hover:border-[#cbd5e1] text-[#475569] text-[14px] font-medium rounded-xl px-4 py-3.5 outline-none focus:bg-white focus:border-[#a855f7] focus:ring-4 focus:ring-[#a855f7]/10 transition-all shadow-inner"})]}),e.jsxs("div",{className:"md:col-span-4 group",children:[e.jsx("label",{className:"text-[13px] font-bold text-[#1e293b] mb-2 block group-hover:text-[#a855f7] transition-colors",children:"Topic Slug"}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-y-0 left-0 pl-4 flex items-center pointer-events-none",children:e.jsx(Gt,{className:"h-4 w-4 text-[#94a3b8] group-hover:text-[#a855f7] transition-colors"})}),e.jsx("input",{type:"text",placeholder:"general_mathematics",value:k,onChange:y=>N(y.target.value),className:"w-full bg-slate-50 border border-slate-200 hover:border-[#cbd5e1] text-[#475569] text-[14px] font-medium rounded-xl pl-11 pr-4 py-3.5 outline-none focus:bg-white focus:border-[#a855f7] focus:ring-4 focus:ring-[#a855f7]/10 transition-all shadow-inner"})]})]})]}),e.jsx("div",{className:"mt-6 flex justify-end pt-6 border-t border-slate-100",children:e.jsxs("button",{onClick:w,disabled:d,className:"bg-gradient-to-r from-[#a855f7] to-[#9333ea] hover:from-[#9333ea] hover:to-[#7e22ce] text-white text-[14px] font-bold rounded-full px-8 py-3 shadow-[0_4px_16px_rgba(168,85,247,0.3)] transition-all hover:scale-[1.02] flex items-center gap-2 hover:shadow-[0_8px_24px_rgba(168,85,247,0.4)] disabled:opacity-50 disabled:hover:scale-100",children:[d?e.jsx(gt,{className:"w-4 h-4 animate-spin"}):e.jsx(Wr,{className:"w-4 h-4"}),"Ingest PDF"]})})]})}),e.jsxs("div",{className:"bg-white/80 backdrop-blur-[12px] rounded-[24px] border border-white shadow-[0_8px_32px_rgba(0,0,0,0.04)] p-[24px] sm:p-[32px]",children:[e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsx("h2",{className:"text-[20px] font-bold text-[#1e293b]",children:"Processing Status"}),e.jsx("button",{onClick:C,disabled:l,className:"w-9 h-9 rounded-full bg-white border border-slate-200 flex items-center justify-center text-[#64748b] hover:text-[#9333ea] hover:border-purple-200 shadow-sm transition-all hover:scale-105 active:scale-95 disabled:opacity-50",children:e.jsx(cs,{className:`w-4 h-4 ${l?"animate-spin":""}`})})]}),e.jsx("div",{className:"bg-white rounded-[16px] border border-[#f1f5f9] overflow-hidden shadow-[0_1px_4px_rgba(0,0,0,0.02)]",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-left border-collapse",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-[#9956DE] border-b border-[#8b5cf6] shadow-md relative z-10",children:[e.jsx("th",{className:"h-12 px-6 text-[11px] font-bold text-white uppercase tracking-wider whitespace-nowrap",children:"Filename"}),e.jsx("th",{className:"h-12 px-6 text-[11px] font-bold text-white uppercase tracking-wider whitespace-nowrap",children:"Grade"}),e.jsx("th",{className:"h-12 px-6 text-[11px] font-bold text-white uppercase tracking-wider whitespace-nowrap",children:"Topic"}),e.jsx("th",{className:"h-12 px-6 text-[11px] font-bold text-white uppercase tracking-wider whitespace-nowrap text-center",children:"Questions"}),e.jsx("th",{className:"h-12 px-6 text-[11px] font-bold text-white uppercase tracking-wider whitespace-nowrap",children:"Status"}),e.jsx("th",{className:"h-12 px-6 text-[11px] font-bold text-white uppercase tracking-wider whitespace-nowrap",children:"Processed At"})]})}),e.jsxs("tbody",{className:"divide-y divide-[#f1f5f9] bg-white",children:[n.map(y=>e.jsxs("tr",{className:"hover:bg-slate-50/50 transition-colors group",children:[e.jsx("td",{className:"py-4 px-6",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`w-8 h-8 rounded-lg flex items-center justify-center shrink-0 ${y.processed?"bg-indigo-50 text-indigo-500":"bg-amber-50 text-amber-500"}`,children:e.jsx(Rs,{className:"w-4 h-4"})}),e.jsx("span",{className:"text-[13px] font-bold text-[#1e293b] group-hover:text-purple-600 transition-colors line-clamp-1",children:y.filename})]})}),e.jsx("td",{className:"py-4 px-6 text-[13px] font-semibold text-[#475569]",children:y.grade_level}),e.jsx("td",{className:"py-4 px-6",children:e.jsx("span",{className:"text-[12px] font-medium bg-slate-100 text-slate-600 px-2.5 py-1 rounded-md line-clamp-1",children:y.topic})}),e.jsx("td",{className:"py-4 px-6 text-[13px] font-bold text-[#1e293b] text-center",children:y.question_count||"-"}),e.jsx("td",{className:"py-4 px-6",children:e.jsxs("span",{className:`inline-flex items-center gap-1.5 px-3 py-1 text-[11px] font-bold rounded-full border shadow-sm ${y.processed?"bg-emerald-50 text-emerald-600 border-emerald-200/50":"bg-amber-50 text-amber-600 border-amber-200/50"}`,children:[y.processed?e.jsx(cs,{className:"w-3 h-3"}):e.jsx(gt,{className:"w-3 h-3 animate-spin"}),y.processed?"Completed":"Processing..."]})}),e.jsx("td",{className:"py-4 px-6 text-[13px] font-medium text-[#64748b]",children:y.timestamp?new Date(y.timestamp).toLocaleDateString():"-"})]},y.filename)),n.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:6,className:"py-12 px-6 text-center",children:e.jsxs("div",{className:"flex flex-col items-center justify-center text-[#64748b]",children:[e.jsx("div",{className:"w-16 h-16 bg-slate-50 rounded-full flex items-center justify-center mb-4 border border-slate-100",children:e.jsx(Rs,{className:"w-8 h-8 text-slate-300"})}),e.jsx("p",{className:"text-[14px] font-bold text-[#1e293b] mb-1",children:"No PDFs processed yet"}),e.jsx("p",{className:"text-[13px]",children:"Upload a PDF using the form above to get started."})]})})})]})]})})})]}),e.jsxs("div",{className:"bg-white/80 backdrop-blur-[12px] rounded-[24px] border border-white shadow-[0_8px_32px_rgba(0,0,0,0.04)] p-[24px] sm:p-[32px]",children:[e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsxs("h2",{className:"text-[20px] font-bold text-[#1e293b] flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-[10px] bg-gradient-to-br from-[#3b82f6] to-[#2563eb] flex items-center justify-center shadow-md shadow-blue-500/20",children:e.jsx(Gt,{className:"w-4 h-4 text-white"})}),"Question Bank (",v.length,")"]}),e.jsx("button",{onClick:f,disabled:I,className:"w-9 h-9 rounded-full bg-white border border-slate-200 flex items-center justify-center text-[#64748b] hover:text-[#9333ea] hover:border-purple-200 shadow-sm transition-all hover:scale-105 active:scale-95 disabled:opacity-50",children:e.jsx(cs,{className:`w-4 h-4 ${I?"animate-spin":""}`})})]}),I?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(gt,{className:"w-6 h-6 animate-spin text-[#9956DE]"})}):v.length===0?e.jsxs("div",{className:"text-center py-12 text-[#64748b]",children:[e.jsx(Gt,{className:"w-10 h-10 mx-auto mb-3 text-slate-300"}),e.jsx("p",{className:"text-[14px] font-bold text-[#1e293b] mb-1",children:"No questions in the bank yet"}),e.jsx("p",{className:"text-[13px]",children:"Ingest a PDF above to populate the question bank."})]}):e.jsx("div",{className:"space-y-2 max-h-[500px] overflow-y-auto",children:v.map(y=>e.jsxs("div",{className:"border border-[#f1f5f9] rounded-xl p-4 hover:border-purple-200 transition-colors bg-white",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 cursor-pointer",onClick:()=>W(R===y.id?null:y.id),children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-[13px] font-medium text-[#1e293b] line-clamp-2",children:y.question}),e.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[e.jsxs("span",{className:"text-[11px] px-2 py-0.5 rounded-md bg-blue-50 text-blue-600 font-semibold",children:["Grade ",y.grade_level]}),e.jsx("span",{className:"text-[11px] px-2 py-0.5 rounded-md bg-slate-100 text-slate-600 font-medium",children:y.topic}),e.jsx("span",{className:`text-[11px] px-2 py-0.5 rounded-md font-semibold ${y.difficulty==="easy"?"bg-green-50 text-green-600":y.difficulty==="hard"?"bg-rose-50 text-rose-600":"bg-amber-50 text-amber-600"}`,children:y.difficulty})]})]}),R===y.id?e.jsx(Ca,{size:16,className:"text-[#94a3b8] shrink-0"}):e.jsx($t,{size:16,className:"text-[#94a3b8] shrink-0"})]}),R===y.id&&e.jsxs("div",{className:"mt-3 pt-3 border-t border-[#f1f5f9] space-y-2",children:[e.jsx("div",{className:"space-y-1",children:y.choices.map((q,J)=>e.jsxs("p",{className:`text-[12px] px-3 py-1.5 rounded-lg ${q===y.correct_answer?"bg-green-50 text-green-700 font-semibold border border-green-200":"bg-slate-50 text-[#475569]"}`,children:[String.fromCharCode(65+J),". ",q]},J))}),y.explanation&&e.jsxs("p",{className:"text-[12px] text-[#64748b] italic mt-2 flex items-center gap-1",children:[e.jsx(vc,{size:12})," ",y.explanation]})]})]},y.id))})]})]})]})},Fo={totalTopicsTracked:0,masteredCount:0,needsAttentionCount:0,excludedCount:0},Im={"gen-math":{label:"General Mathematics",color:"bg-sky-100 text-sky-700"},"stats-prob":{label:"Statistics & Probability",color:"bg-sky-100 text-sky-700"},"pre-calc":{label:"Pre-Calculus",color:"bg-orange-100 text-orange-700"},"basic-calc":{label:"Basic Calculus",color:"bg-red-100 text-red-700"}},Oo={mastered:{label:"Mastered",color:"text-emerald-600 bg-emerald-50 border-emerald-100"},on_track:{label:"On Track",color:"text-amber-600 bg-amber-50 border-amber-100"},needs_attention:{label:"Needs Work",color:"text-rose-600 bg-rose-50 border-rose-100"},no_data:{label:"No Data",color:"text-slate-600 bg-slate-50 border-slate-200"}},Po={needs_attention:0,on_track:1,no_data:2,mastered:3},Tm=({classSectionId:t,onOpenNotifications:s,onOpenProfile:a})=>{const{currentUser:r,userProfile:o}=hs(),[n,i]=u.useState([]),[l,c]=u.useState(Fo),[d,m]=u.useState(!0),[p,h]=u.useState("all"),[b,S]=u.useState("all"),[k,N]=u.useState(""),[v,g]=u.useState("classAverage"),[I,z]=u.useState("asc"),R=Un.map(H=>H.id),W=Un.reduce((H,ee)=>(H[ee.id]=ee.name,H),{}),{isLoading:f,refetch:C}=Sc();u.useEffect(()=>{f||(console.log("[TopicMasteryView] Curriculum ready"),C())},[f,C]);const[w,$]=u.useState(new Set),[A,y]=u.useState([]),q=Nc({queryKey:Pl.topicMastery(r?.uid||"anonymous",t),enabled:!!r,staleTime:120*1e3,gcTime:900*1e3,queryFn:async()=>{try{if(!r)return{excluded:[],topics:[],summary:{totalTopicsTracked:0,masteredCount:0,needsAttentionCount:0,excludedCount:0}};const H=pt(He,"teachers",r.uid,"settings","quizSettings"),ee=await ks(H),oe=ee.exists()?ee.data()?.excludedTopics||[]:[],Re="https://deign86-mathpulse-api-v3test.hf.space",Fe=new URLSearchParams({teacherId:r.uid});t&&Fe.set("classSectionId",t);const Pe=await r.getIdToken(),G=await fetch(`${Re}/api/analytics/topic-mastery?${Fe.toString()}`,{headers:{Authorization:`Bearer ${Pe}`}});if(!G.ok)return{excluded:oe,topics:[],summary:{totalTopicsTracked:0,masteredCount:0,needsAttentionCount:0,excludedCount:oe.length}};const te=await G.json(),E=(te.topics||[]).map(Y=>({...Y,isExcluded:oe.includes(Y.topicName)}));return{excluded:oe,topics:E,summary:te.summary||{totalTopicsTracked:0,masteredCount:0,needsAttentionCount:0,excludedCount:oe.length}}}catch{return{excluded:[],topics:[],summary:{totalTopicsTracked:0,masteredCount:0,needsAttentionCount:0,excludedCount:0}}}}});u.useEffect(()=>{if(m(q.isLoading||q.isFetching),!q.data){y([]),i([]),c(Fo),$(new Set);return}y(q.data.excluded),i(q.data.topics),c(q.data.summary)},[q.data,q.isFetching,q.isLoading]);const J=async H=>{if(!r)return;const ee=A.includes(H)?A.filter(oe=>oe!==H):[...A,H];y(ee),i(oe=>oe.map(Re=>Re.topicName===H?{...Re,isExcluded:!Re.isExcluded}:Re)),c(oe=>({...oe,excludedCount:ee.length}));try{const oe=pt(He,"teachers",r.uid,"settings","quizSettings");(await ks(oe)).exists()?await es(oe,{excludedTopics:ee}):await ts(oe,{excludedTopics:ee})}catch{ie.error("Failed to update excluded topics")}},re=async()=>{if(!r)return;const H=[...new Set([...A,...w])];y(H),i(ee=>ee.map(oe=>w.has(oe.topicName)?{...oe,isExcluded:!0}:oe)),c(ee=>({...ee,excludedCount:H.length})),$(new Set);try{const ee=pt(He,"teachers",r.uid,"settings","quizSettings");(await ks(ee)).exists()?await es(ee,{excludedTopics:H}):await ts(ee,{excludedTopics:H}),ie.success(`${w.size} topics excluded from quizzes`)}catch{ie.error("Failed to update")}},le=async()=>{if(!r)return;const H=A.filter(ee=>!w.has(ee));y(H),i(ee=>ee.map(oe=>w.has(oe.topicName)?{...oe,isExcluded:!1}:oe)),c(ee=>({...ee,excludedCount:H.length})),$(new Set);try{const ee=pt(He,"teachers",r.uid,"settings","quizSettings");(await ks(ee)).exists()?await es(ee,{excludedTopics:H}):await ts(ee,{excludedTopics:H}),ie.success(`${w.size} topics re-included in quizzes`)}catch{ie.error("Failed to update")}},ne=H=>{v===H?z(ee=>ee==="asc"?"desc":"asc"):(g(H),z("asc"))},be=b==="all"?R:jc(b);u.useEffect(()=>{p!=="all"&&(be.includes(p)||h("all"))},[be,p]);const Ie=n.filter(H=>!(p!=="all"&&H.subjectId!==p||!be.includes(H.subjectId)||k&&!H.topicName.toLowerCase().includes(k.toLowerCase()))).sort((H,ee)=>{const oe=I==="asc"?1:-1;switch(v){case"topicName":return oe*H.topicName.localeCompare(ee.topicName);case"classAverage":return oe*(H.classAverage-ee.classAverage);case"studentsAttempted":return oe*(H.studentsAttempted-ee.studentsAttempted);case"masteryStatus":return oe*((Po[H.masteryStatus]||0)-(Po[ee.masteryStatus]||0));default:return 0}}),de=()=>{w.size===Ie.length?$(new Set):$(new Set(Ie.map(H=>H.topicName)))},fe=({field:H})=>v!==H?e.jsx($t,{size:14,className:"text-white/40"}):I==="asc"?e.jsx(Ca,{size:14,className:"text-white font-bold"}):e.jsx($t,{size:14,className:"text-white font-bold"});return d?e.jsxs("div",{className:"flex items-center justify-center py-20",children:[e.jsx(gt,{size:24,className:"animate-spin text-indigo-500"}),e.jsx("span",{className:"ml-2 text-[#64748b]",children:"Loading topic mastery data..."})]}):e.jsxs(Le.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},exit:{opacity:0,y:-20},className:"w-full p-[24px] xl:p-[32px] space-y-[24px]",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-[16px]",children:[e.jsxs("div",{className:"relative overflow-hidden bg-gradient-to-br from-[#a855f7] to-[#9333ea] rounded-[16px] p-[20px] shadow-[0_4px_12px_rgba(168,85,247,0.2)] flex flex-col justify-between h-full group text-white",children:[e.jsx("div",{className:"absolute -right-12 -bottom-12 w-40 h-40 bg-white/10 rounded-full"}),e.jsxs("div",{className:"flex items-start justify-between relative z-10 mb-4",children:[e.jsx("span",{className:"text-[13px] font-medium text-white/90",children:"Total Topics Tracked"}),e.jsx("div",{className:"w-8 h-8 rounded-full border border-white/30 flex items-center justify-center bg-white/10",children:e.jsx(Ls,{size:16,className:"text-white"})})]}),e.jsx("div",{className:"text-[32px] font-bold relative z-10 leading-none",children:l.totalTopicsTracked})]}),e.jsxs("div",{className:"relative overflow-hidden bg-gradient-to-br from-[#10b981] to-[#059669] rounded-[16px] p-[20px] shadow-[0_4px_12px_rgba(16,185,129,0.2)] flex flex-col justify-between h-full group text-white",children:[e.jsx("div",{className:"absolute -right-12 -bottom-12 w-40 h-40 bg-white/10 rounded-full"}),e.jsxs("div",{className:"flex items-start justify-between relative z-10 mb-4",children:[e.jsx("span",{className:"text-[13px] font-medium text-white/90",children:"Mastered by Class"}),e.jsx("div",{className:"w-8 h-8 rounded-full border border-white/30 flex items-center justify-center bg-white/10",children:e.jsx(La,{size:16,className:"text-white"})})]}),e.jsx("div",{className:"text-[32px] font-bold relative z-10 leading-none",children:l.masteredCount})]}),e.jsxs("div",{className:"relative overflow-hidden bg-gradient-to-br from-[#f43f5e] to-[#e11d48] rounded-[16px] p-[20px] shadow-[0_4px_12px_rgba(244,63,94,0.2)] flex flex-col justify-between h-full group text-white",children:[e.jsx("div",{className:"absolute -right-12 -bottom-12 w-40 h-40 bg-white/10 rounded-full"}),e.jsxs("div",{className:"flex items-start justify-between relative z-10 mb-4",children:[e.jsx("span",{className:"text-[13px] font-medium text-white/90",children:"Needs Work"}),e.jsx("div",{className:"w-8 h-8 rounded-full border border-white/30 flex items-center justify-center bg-white/10",children:e.jsx(ca,{size:16,className:"text-white"})})]}),e.jsx("div",{className:"text-[32px] font-bold relative z-10 leading-none",children:l.needsAttentionCount})]}),e.jsxs("div",{className:"relative overflow-hidden bg-gradient-to-br from-[#64748b] to-[#475569] rounded-[16px] p-[20px] shadow-[0_4px_12px_rgba(100,116,139,0.2)] flex flex-col justify-between h-full group text-white",children:[e.jsx("div",{className:"absolute -right-12 -bottom-12 w-40 h-40 bg-white/10 rounded-full"}),e.jsxs("div",{className:"flex items-start justify-between relative z-10 mb-4",children:[e.jsx("span",{className:"text-[13px] font-medium text-white/90",children:"Excluded Topics"}),e.jsx("div",{className:"w-8 h-8 rounded-full border border-white/30 flex items-center justify-center bg-white/10",children:e.jsx(gc,{size:16,className:"text-white"})})]}),e.jsx("div",{className:"text-[32px] font-bold relative z-10 leading-none",children:l.excludedCount})]})]}),e.jsxs("div",{className:"bg-white/80 backdrop-blur-[12px] rounded-[24px] p-[24px] shadow-[0_1px_4px_rgba(0,0,0,0.02)] border border-white",children:[e.jsxs("div",{className:"flex flex-col md:flex-row gap-4 mb-6",children:[e.jsxs("div",{className:"flex items-center bg-white px-4 py-2.5 rounded-[12px] shadow-[0_1px_4px_rgba(0,0,0,0.02)] border border-[#e2e8f0] group focus-within:ring-2 focus-within:ring-indigo-500/20 transition-all w-full md:w-64",children:[e.jsx(qs,{size:16,className:"text-[#64748b] shrink-0 group-focus-within:text-[#4f46e5] transition-colors"}),e.jsx("input",{type:"text",placeholder:"Search topics...",value:k,onChange:H=>N(H.target.value),className:"bg-transparent border-none focus:outline-none ml-2 text-[13px] w-full text-[#475569] placeholder:text-[#94a3b8]"})]}),e.jsxs("div",{className:"relative w-full md:w-48",children:[e.jsxs("select",{value:p,onChange:H=>h(H.target.value),className:"appearance-none w-full bg-white border border-[#e2e8f0] text-[#475569] text-[13px] font-medium rounded-[12px] pl-4 pr-10 py-2.5 outline-none focus:border-[#a855f7] focus:ring-2 focus:ring-[#a855f7]/20 shadow-[0_1px_4px_rgba(0,0,0,0.02)] cursor-pointer",children:[e.jsx("option",{value:"all",children:"All Subjects"}),be.map(H=>e.jsx("option",{value:H,children:W[H]||H},H))]}),e.jsx($t,{size:16,className:"text-[#64748b] absolute right-3 top-1/2 -translate-y-1/2 pointer-events-none"})]}),e.jsxs("div",{className:"relative w-full md:w-48",children:[e.jsxs("select",{value:b,onChange:H=>S(H.target.value),className:"appearance-none w-full bg-white border border-[#e2e8f0] text-[#475569] text-[13px] font-medium rounded-[12px] pl-4 pr-10 py-2.5 outline-none focus:border-[#a855f7] focus:ring-2 focus:ring-[#a855f7]/20 shadow-[0_1px_4px_rgba(0,0,0,0.02)] cursor-pointer",children:[e.jsx("option",{value:"all",children:"All Grades"}),yc.map(H=>e.jsx("option",{value:H,children:H},H))]}),e.jsx($t,{size:16,className:"text-[#64748b] absolute right-3 top-1/2 -translate-y-1/2 pointer-events-none"})]})]}),e.jsx(zt,{children:w.size>0&&e.jsxs(Le.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},className:"mb-4 bg-indigo-50 border border-indigo-200 rounded-[12px] p-3 flex items-center gap-3 flex-wrap overflow-hidden",children:[e.jsxs("span",{className:"text-[13px] font-semibold text-indigo-700",children:[w.size," topics selected"]}),e.jsx("button",{onClick:re,className:"px-4 py-1.5 bg-[#475569] text-white text-[11px] font-bold rounded-full hover:bg-[#334155] transition-colors shadow-sm",children:"Exclude Selected"}),e.jsx("button",{onClick:le,className:"px-4 py-1.5 bg-emerald-600 text-white text-[11px] font-bold rounded-full hover:bg-emerald-700 transition-colors shadow-sm",children:"Include Selected"}),e.jsx("button",{onClick:()=>$(new Set),className:"px-4 py-1.5 bg-white border border-[#e2e8f0] text-[#64748b] text-[11px] font-bold rounded-full hover:bg-[#f8fafc] transition-colors shadow-sm",children:"Clear Selection"})]})}),e.jsx("div",{className:"bg-white rounded-[16px] border border-[#f1f5f9] overflow-hidden shadow-[0_1px_4px_rgba(0,0,0,0.02)]",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("div",{className:"min-w-[800px]",children:[e.jsxs("div",{className:"bg-[#9956DE] grid grid-cols-12 gap-4 p-4 border-b border-[#8b5cf6] items-center text-[11px] font-bold text-white tracking-wider uppercase shadow-md relative z-10 h-12",children:[e.jsx("div",{className:"col-span-1 flex justify-center",children:e.jsx("input",{type:"checkbox",checked:w.size===Ie.length&&Ie.length>0,onChange:de,className:"rounded text-[#4f46e5] focus:ring-[#4f46e5] w-4 h-4 border-white/30 bg-white/10 cursor-pointer"})}),e.jsxs("div",{className:"col-span-3 flex items-center gap-1 cursor-pointer hover:text-white/80 select-none",onClick:()=>ne("topicName"),children:["TOPIC NAME ",e.jsx(fe,{field:"topicName"})]}),e.jsx("div",{className:"col-span-2",children:"UNIT"}),e.jsxs("div",{className:"col-span-2 flex items-center gap-1 cursor-pointer hover:text-white/80 select-none",onClick:()=>ne("classAverage"),children:["CLASS AVG % ",e.jsx(fe,{field:"classAverage"})]}),e.jsxs("div",{className:"col-span-2 flex items-center gap-1 cursor-pointer hover:text-white/80 select-none",onClick:()=>ne("studentsAttempted"),children:["STUDENTS ",e.jsx(fe,{field:"studentsAttempted"})]}),e.jsxs("div",{className:"col-span-1 flex items-center gap-1 cursor-pointer hover:text-white/80 select-none",onClick:()=>ne("masteryStatus"),children:["STATUS ",e.jsx(fe,{field:"masteryStatus"})]}),e.jsx("div",{className:"col-span-1 text-center",children:"EXCLUDE"})]}),e.jsx("div",{className:"flex flex-col",children:Ie.length===0?e.jsx("div",{className:"p-16 text-center border-b border-[#f1f5f9]",children:n.length===0?e.jsxs("div",{className:"flex flex-col items-center gap-2",children:[e.jsx(Ls,{size:32,className:"text-[#cbd5e1]"}),e.jsx("p",{className:"text-[13px] font-semibold text-[#64748b]",children:"No topic data available yet"}),e.jsx("p",{className:"text-[11px] text-[#94a3b8]",children:"Import student quiz data to see class topic mastery analytics."})]}):e.jsx("span",{className:"text-[13px] text-[#64748b]",children:"No topics match the current filters."})}):Ie.map(H=>{const ee=w.has(H.topicName),oe=Oo[H.masteryStatus]||Oo.no_data,Re=Im[H.subjectId]||{label:H.subjectId.toUpperCase(),color:"bg-[#f8fafc] text-[#64748b]"},Fe=H.classAverage<60?"bg-rose-500":H.classAverage<85?"bg-amber-500":"bg-emerald-500",Pe=H.isExcluded?"bg-slate-50/60 opacity-70":H.masteryStatus==="needs_attention"?"bg-rose-50/30":H.masteryStatus==="mastered"?"bg-emerald-50/20":"";return e.jsxs("div",{className:`grid grid-cols-12 gap-4 p-4 border-b border-[#f1f5f9] items-center hover:bg-slate-50/80 transition-colors group ${Pe} ${H.isExcluded?"line-through decoration-slate-400":""}`,children:[e.jsx("div",{className:"col-span-1 flex justify-center",children:e.jsx("input",{type:"checkbox",checked:ee,onChange:()=>{const G=new Set(w);ee?G.delete(H.topicName):G.add(H.topicName),$(G)},className:"rounded text-[#4f46e5] focus:ring-[#4f46e5] w-4 h-4 border-gray-300 cursor-pointer"})}),e.jsxs("div",{className:"col-span-3 flex flex-col sm:flex-row sm:items-center gap-1.5 pr-2 min-w-0",children:[e.jsx("span",{className:"font-semibold text-[#1e293b] text-[13px] truncate",children:H.topicName}),e.jsx("span",{className:`text-[9px] font-bold px-1.5 py-0.5 rounded shrink-0 ${Re.color}`,children:Re.label})]}),e.jsx("div",{className:"col-span-2 text-[#475569] text-[13px] truncate pr-2",children:H.unit}),e.jsx("div",{className:"col-span-2",children:e.jsxs("span",{className:"font-bold text-[#1e293b] text-[14px]",children:[H.classAverage,"%"]})}),e.jsxs("div",{className:"col-span-2 pr-4",children:[e.jsx("div",{className:"flex justify-between items-center text-[11px] mb-1",children:e.jsxs("span",{className:"font-semibold text-[#1e293b]",children:[H.studentsAttempted," / ",H.totalStudents]})}),e.jsx("div",{className:"w-full bg-[#f1f5f9] h-1.5 rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full transition-all duration-500 ${Fe}`,style:{width:`${H.classAverage}%`}})})]}),e.jsx("div",{className:"col-span-1",children:e.jsx("span",{className:`text-[10px] font-bold px-2.5 py-1 rounded-full border whitespace-nowrap ${oe.color}`,children:oe.label})}),e.jsxs("div",{className:"col-span-1 flex justify-center relative",children:[e.jsxs("label",{className:"relative inline-flex items-center cursor-pointer group/toggle",children:[e.jsx("input",{type:"checkbox",checked:H.isExcluded,onChange:()=>J(H.topicName),className:"sr-only peer"}),e.jsx("div",{className:"w-9 h-5 bg-slate-200 peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-[#4f46e5]"})]}),e.jsx("div",{className:"hidden group-hover/toggle:block absolute z-20 bottom-full left-1/2 -translate-x-1/2 mb-2 px-2 py-1 bg-slate-800 text-white text-[10px] rounded whitespace-nowrap shadow-lg",children:H.isExcluded?"Include in generation":"Exclude from generation"})]})]},H.topicName)})})]})})})]})]})};function gl(t){return(t||"").trim().toLowerCase()}function Bo(t){const s=(t.lrn||"").trim().toLowerCase();if(s)return`lrn:${s}`;const a=(t.email||"").trim().toLowerCase();if(a)return`email:${a}`;const r=t.name.trim().toLowerCase();if(r)return`name:${r}`;const o=gl(t.classSectionId),n=(t.id||"").trim().toLowerCase();return o&&n?`${o}|id:${n}`:n?`id:${n}`:`${o}|anonymous`}function _m(t,s){const a=[],r=(t.lrn||"").trim().toLowerCase(),o=(t.email||"").trim().toLowerCase(),n=t.name.trim().toLowerCase(),i=(t.id||"").trim().toLowerCase();return r&&a.push(`${s}|lrn:${r}`),o&&a.push(`${s}|email:${o}`),n&&a.push(`${s}|name:${n}`),i&&a.push(`${s}|id:${i}`),a.length===0&&a.push(`${s}|anonymous`),a}function Em(t,s){const a=[t.riskLevel,s.riskLevel].includes("High")?"High":[t.riskLevel,s.riskLevel].includes("Medium")?"Medium":"Low";return{...t,lrn:t.lrn||s.lrn,classSectionId:t.classSectionId??s.classSectionId,avgQuizScore:s.avgQuizScore>0?s.avgQuizScore:t.avgQuizScore,engagementScore:s.engagementScore>0?s.engagementScore:t.engagementScore,weakestTopic:t.weakestTopic&&t.weakestTopic!=="Foundational Skills"?t.weakestTopic:s.weakestTopic,riskLevel:a}}function bl(t,s){const a=new Map,r=new Map,o=s?gl(s):"all";return t.forEach(n=>{const i=_m(n,o),l=i.map(m=>r.get(m)).find(Boolean)||i[0],c=a.get(l),d=c?Em(c,n):n;a.set(l,d),i.forEach(m=>r.set(m,l))}),Array.from(a.values())}function Ho(t,s){return bl([...t,...s])}function ta(t){return Number.isFinite(t)?Math.max(0,Math.min(100,t)):0}function Rm(t){if(!t)return null;const s="gen-math",a=Gn.find(i=>i.id===s)?.modules||[];if(a.length===0)return null;const r={mastery:0,concept:0,application:0,engagement:0,consistency:0},o=t.lessons??{};a.forEach(i=>{const l=Gn.find(N=>N.modules.some(v=>v.id===i.id)),c=l?t?.subjects?.[l.id]?.modulesProgress?.[i.id]:null,d=ta(c?.progress||0),m=i.lessons.length?i.lessons.reduce((N,v)=>{const g=o?.[v.id]?.score;if(typeof g=="number"&&Number.isFinite(g))return N+ta(g);const I=!!c?.lessonsCompleted?.includes?.(v.id);return N+(I?100:0)},0)/i.lessons.length:0,p=i.quizzes.length?(c?.quizzesCompleted?.length||0)/i.quizzes.length*100:0,h=ta(m),b=ta(p),S=ta(Math.min(100,(h+b*2)/1.5)),k=ta(Math.min(100,40+d*.6));r.mastery+=d,r.concept+=h,r.application+=b,r.engagement+=S,r.consistency+=k});const n=a.length;return{mastery:Math.round(r.mastery/n),concept:Math.round(r.concept/n),application:Math.round(r.application/n),engagement:Math.round(r.engagement/n),consistency:Math.round(r.consistency/n)}}const Uo={advanced:{bg:"bg-emerald-100",text:"text-emerald-700",bar:"bg-emerald-500"},proficient:{bg:"bg-sky-100",text:"text-sky-700",bar:"bg-sky-500"},developing:{bg:"bg-rose-100",text:"text-rose-700",bar:"bg-rose-500"},beginner:{bg:"bg-red-100",text:"text-red-700",bar:"bg-red-500"}},Fr=[{key:"mastery",short:"M",label:"Overall Mastery",header:"Mastery"},{key:"concept",short:"C",label:"Concept Grasp",header:"Concept"},{key:"application",short:"A",label:"Application",header:"Applications"},{key:"consistency",short:"S",label:"Consistency",header:"Consistency"}],Mm=({classSectionId:t,className:s,fallbackStudents:a=[],onBack:r,onOpenNotifications:o,onOpenProfile:n,insightDismissed:i,onOpenInsightModal:l})=>{const{currentUser:c,userProfile:d}=hs(),m=u.useRef(0),[p,h]=u.useState([]),[b,S]=u.useState(!0),[k,N]=u.useState(""),[v,g]=u.useState("riskLevel"),[I,z]=u.useState("desc"),[R,W]=u.useState("all"),[f,C]=u.useState([]),[w,$]=u.useState(!1),[A,y]=u.useState(""),[q,J]=u.useState(""),re=u.useCallback(E=>({id:E.id,lrn:E.lrn||void 0,name:E.name,email:E.email||"",avatar:Ja(E.gender),classSectionId:E.classSectionId??null,riskLevel:E.riskLevel||"Low",engagementScore:E.engagementScore,avgQuizScore:E.avgQuizScore,weakestTopic:E.weakestTopic||"Foundational Skills"}),[]),le=u.useCallback(E=>({id:E.id,lrn:E.lrn,name:E.name,email:E.email||"",avatar:E.avatar&&!E.avatar.includes("ui-avatars.com")?E.avatar:Ja(E.gender),classSectionId:E.classSectionId??null,riskLevel:String(E.riskLevel).charAt(0).toUpperCase()+String(E.riskLevel).slice(1).toLowerCase(),engagementScore:Number(E.engagementScore)||0,avgQuizScore:Number(E.avgQuizScore??E.avgScore??0)||0,weakestTopic:E.weakestTopic||"Foundational Skills",accountUid:E.accountUid}),[]),ne=u.useCallback(async(E,Y)=>{const V=new Map,pe=new Map;E.forEach(j=>V.set(j.id,null));const D=25;for(let j=0;j{const ue=Q.accountUid||Q.id;try{const ce=await Gr(ue),ae=ce?.averageScore||0;return{studentId:Q.id,summary:Rm(ce),avgScore:ae}}catch{return{studentId:Q.id,summary:null,avgScore:0}}}))).forEach((Q,ue)=>{const ce=_[ue]?.id;ce&&(Q.status==="fulfilled"?(V.set(ce,Q.value.summary),Q.value.avgScore>0&&pe.set(ce,Q.value.avgScore)):V.set(ce,null))})}m.current===Y&&h(j=>j.map(_=>{if(!V.has(_.student.id))return _;const T=pe.get(_.student.id);return{..._,student:T!=null&&T>_.student.avgQuizScore?{..._.student,avgQuizScore:Math.round(T)}:_.student,competencyMatrix:V.get(_.student.id)??null,competencyMatrixLoading:!1}}))},[]),be=u.useCallback(async()=>{if(c?.uid){S(!0),J("");try{let Y=(await jn(c.uid)).map(j=>({id:j.id,name:j.name,email:j.email||"",avatar:j.avatar&&!j.avatar.includes("ui-avatars.com")?j.avatar:Ja(j.gender),classSectionId:j.classSectionId??null,riskLevel:j.riskLevel,engagementScore:Number(j.engagementScore)||0,avgQuizScore:Number(j.avgQuizScore)||0,weakestTopic:j.weakestTopic||"Foundational Skills",accountUid:j.accountUid}));a.length>0&&(Y=Ho(Y,a.map(le))),t&&(Y=Y.filter(j=>j.classSectionId===t));const V=await xt.getImportedClassOverview({classSectionId:t,limit:3e3});V.warnings.length>0&&J(V.warnings.join(" ")),Y=Ho(Y,V.students.map(re));const pe=bl(Y,t),D=m.current+=1;h(pe.map((j,_)=>({rowKey:`${Bo(j)}|row:${_}`,student:j,competency:null,competencyMatrix:null,competencyMatrixLoading:!0,loading:!1,expanded:!1}))),ne(pe,D)}catch(E){if(console.error("Failed to load students:",E),a.length>0){const Y=a.map(le).filter(V=>!t||V.classSectionId===t).map((V,pe)=>({rowKey:`${Bo(V)}|row:${pe}`,student:V,competency:null,competencyMatrix:null,competencyMatrixLoading:!1,loading:!1,expanded:!1}));h(Y),J("Showing recently imported students while backend roster sync catches up.")}else h([]),J("Student competency roster is unavailable right now.")}finally{S(!1)}}},[t,c?.uid,a,ne,le,re]);u.useEffect(()=>{be()},[be]),u.useEffect(()=>{(async()=>{if(!t){C([]),y("");return}$(!0),y("");try{const Y=await xt.getCourseMaterialTopics({classSectionId:t,limit:20}),V=(Y.topics||[]).filter(pe=>pe.title?.trim());C(V),Y.warnings.length>0&&y(Y.warnings.join(" "))}catch{C([]),y("Imported topic context is unavailable right now.")}finally{$(!1)}})()},[t]);const Ie=async E=>{h(Y=>Y.map(V=>{if(V.rowKey!==E)return V;const pe=!V.expanded,D=V.student.id,j={weakestTopic:V.student.weakestTopic,avgQuizScore:V.student.avgQuizScore};return pe&&!V.competency&&!V.loading?(de(E,D,j),{...V,expanded:!0,loading:!0}):{...V,expanded:pe}}))},de=async(E,Y,V)=>{try{const D=((await Gr(Y))?.quizAttempts??[]).map(_=>({topic:_.quizId,score:_.score,total:100,timeTaken:_.timeSpent})),j=await xt.getStudentCompetency(Y,D.length>0?D:void 0);h(_=>_.map(T=>T.rowKey===E?{...T,competency:j,loading:!1}:T))}catch{const D=V.avgQuizScore||50,j={studentId:Y,competencies:[{topic:V.weakestTopic||"Unknown",efficiencyScore:Math.max(15,D-20),competencyLevel:D<50?"beginner":"developing",perspective:`Student needs focused practice in ${V.weakestTopic}.`},{topic:"Functions and Relations",efficiencyScore:Math.min(95,D+10),competencyLevel:D>70?"proficient":"developing",perspective:"Shows solid understanding of function concepts."},{topic:"Problem Solving",efficiencyScore:D,competencyLevel:D>80?"advanced":D>60?"proficient":"developing",perspective:"Applies mathematical reasoning consistently."}],recommendedTopics:[V.weakestTopic||"Review fundamentals"],excludeTopics:[]};h(_=>_.map(T=>T.rowKey===E?{...T,competency:j,loading:!1}:T))}},fe=E=>{v===E?z(Y=>Y==="asc"?"desc":"asc"):(g(E),z("asc"))},H={High:0,Medium:1,Low:2},ee=p.filter(E=>{if(R!=="all"&&E.student.riskLevel!==R)return!1;if(k){const Y=k.toLowerCase();return E.student.name.toLowerCase().includes(Y)||E.student.email.toLowerCase().includes(Y)}return!0}).sort((E,Y)=>{let V=0;switch(v){case"name":V=E.student.name.localeCompare(Y.student.name);break;case"avgQuizScore":V=E.student.avgQuizScore-Y.student.avgQuizScore;break;case"riskLevel":V=H[E.student.riskLevel]-H[Y.student.riskLevel];break;case"engagementScore":V=E.student.engagementScore-Y.student.engagementScore;break}return I==="asc"?V:-V}),oe=p.length,Re=p.filter(E=>E.student.riskLevel==="High").length,Fe=oe>0?Math.round(p.reduce((E,Y)=>E+(Number(Y.student.avgQuizScore)||0),0)/oe):0,Pe=oe>0?Math.round(p.reduce((E,Y)=>E+(Number(Y.student.engagementScore)||0),0)/oe):0,G=Array.from(new Set(f.map(E=>E.title).filter(Boolean))).slice(0,10),te=({field:E})=>v!==E?e.jsx($t,{size:14,className:"text-white/40"}):I==="asc"?e.jsx(Ca,{size:14,className:"text-white font-bold"}):e.jsx($t,{size:14,className:"text-white font-bold"});return b?e.jsxs("div",{className:"flex items-center justify-center py-20 p-6",children:[e.jsx(gt,{size:32,className:"animate-spin text-[var(--primary)]"}),e.jsx("span",{className:"ml-3 text-muted-foreground",children:"Loading student data..."})]}):e.jsxs(Le.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},exit:{opacity:0,y:-20},className:"p-6 space-y-6",children:[r&&e.jsx("div",{className:"flex items-center justify-between mb-2",children:e.jsxs("button",{onClick:r,className:"flex items-center gap-2 text-[13px] font-semibold text-[#4f46e5] hover:text-[#3730a3] transition-colors bg-white/60 hover:bg-white/80 px-[18px] py-2 rounded-full backdrop-blur-[12px] shadow-[0_1px_4px_rgba(0,0,0,0.04)] border border-white/50",children:[e.jsx(zs,{className:"w-4 h-4"}),"Back to Classes"]})}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-[16px] mb-6",children:[e.jsxs("div",{className:"relative overflow-hidden bg-gradient-to-br from-[#a855f7] to-[#9333ea] rounded-[16px] p-5 shadow-[0_4px_12px_rgba(168,85,247,0.2)] hover:shadow-[0_8px_24px_rgba(168,85,247,0.3)] hover:-translate-y-1 transition-all duration-300 flex flex-col justify-between group text-white",children:[e.jsx("div",{className:"absolute -right-8 -bottom-8 w-24 h-24 bg-white/10 rounded-full transition-transform duration-500 group-hover:scale-[1.8] group-hover:-translate-y-4 group-hover:-translate-x-4"}),e.jsxs("div",{className:"flex items-start justify-between relative z-10 mb-2",children:[e.jsx("span",{className:"text-[13px] font-medium text-white/90",children:"Total Students"}),e.jsx("div",{className:"w-8 h-8 rounded-full border border-white/30 flex items-center justify-center bg-white/10",children:e.jsx($n,{className:"w-4 h-4 text-white"})})]}),e.jsx("div",{className:"text-[28px] font-bold relative z-10 leading-none mb-4",children:oe}),e.jsx("div",{className:"flex items-center justify-between relative z-10 border-t border-white/20 pt-3 mt-auto",children:e.jsx("span",{className:"text-[12px] font-medium text-white/90",children:"Evaluated in this class"})})]}),e.jsxs("div",{className:"relative overflow-hidden bg-gradient-to-br from-[#f97316] to-[#ea580c] rounded-[16px] p-5 shadow-[0_4px_12px_rgba(249,115,22,0.2)] hover:shadow-[0_8px_24px_rgba(249,115,22,0.3)] hover:-translate-y-1 transition-all duration-300 flex flex-col justify-between group text-white",children:[e.jsx("div",{className:"absolute -right-8 -bottom-8 w-24 h-24 bg-white/10 rounded-full transition-transform duration-500 group-hover:scale-[1.8] group-hover:-translate-y-4 group-hover:-translate-x-4"}),e.jsxs("div",{className:"flex items-start justify-between relative z-10 mb-2",children:[e.jsx("span",{className:"text-[13px] font-medium text-white/90",children:"At-Risk Students"}),e.jsx("div",{className:"w-8 h-8 rounded-full border border-white/30 flex items-center justify-center bg-white/10",children:e.jsx(ca,{className:"w-4 h-4 text-white"})})]}),e.jsx("div",{className:"text-[28px] font-bold relative z-10 leading-none mb-4",children:Re}),e.jsx("div",{className:"flex items-center justify-between relative z-10 border-t border-white/20 pt-3 mt-auto",children:e.jsx("span",{className:"text-[12px] font-medium text-white/90",children:"Need immediate intervention"})})]}),e.jsxs("div",{className:"relative overflow-hidden bg-gradient-to-br from-[#0ea5e9] to-[#0284c7] rounded-[16px] p-5 shadow-[0_4px_12px_rgba(14,165,233,0.2)] hover:shadow-[0_8px_24px_rgba(14,165,233,0.3)] hover:-translate-y-1 transition-all duration-300 flex flex-col justify-between group text-white",children:[e.jsx("div",{className:"absolute -right-8 -bottom-8 w-24 h-24 bg-white/10 rounded-full transition-transform duration-500 group-hover:scale-[1.8] group-hover:-translate-y-4 group-hover:-translate-x-4"}),e.jsxs("div",{className:"flex items-start justify-between relative z-10 mb-2",children:[e.jsx("span",{className:"text-[13px] font-medium text-white/90",children:"Class Average"}),e.jsx("div",{className:"w-8 h-8 rounded-full border border-white/30 flex items-center justify-center bg-white/10",children:e.jsx(Ls,{className:"w-4 h-4 text-white"})})]}),e.jsxs("div",{className:"text-[28px] font-bold relative z-10 leading-none mb-4",children:[Fe,"%"]}),e.jsx("div",{className:"flex items-center justify-between relative z-10 border-t border-white/20 pt-3 mt-auto",children:e.jsx("span",{className:"text-[12px] font-medium text-white/90",children:"Vs. expected benchmark"})})]}),e.jsxs("div",{className:"relative overflow-hidden bg-gradient-to-br from-[#10b981] to-[#059669] rounded-[16px] p-5 shadow-[0_4px_12px_rgba(16,185,129,0.2)] hover:shadow-[0_8px_24px_rgba(16,185,129,0.3)] hover:-translate-y-1 transition-all duration-300 flex flex-col justify-between group text-white",children:[e.jsx("div",{className:"absolute -right-8 -bottom-8 w-24 h-24 bg-white/10 rounded-full transition-transform duration-500 group-hover:scale-[1.8] group-hover:-translate-y-4 group-hover:-translate-x-4"}),e.jsxs("div",{className:"flex items-start justify-between relative z-10 mb-2",children:[e.jsx("span",{className:"text-[13px] font-medium text-white/90",children:"Avg. Engagement"}),e.jsx("div",{className:"w-8 h-8 rounded-full border border-white/30 flex items-center justify-center bg-white/10",children:e.jsx(la,{className:"w-4 h-4 text-white"})})]}),e.jsxs("div",{className:"text-[28px] font-bold relative z-10 leading-none mb-4",children:[Pe,"%"]}),e.jsx("div",{className:"flex items-center justify-between relative z-10 border-t border-white/20 pt-3 mt-auto",children:e.jsx("span",{className:"text-[12px] font-medium text-white/90",children:"Activity completion rate"})})]})]}),e.jsx("div",{className:"sticky top-0 z-30 py-4 -my-4 bg-[#f8fafc]/80 backdrop-blur-[16px] border-b border-slate-200/50 shadow-[0_4px_20px_rgba(0,0,0,0.02)] px-2 sm:-mx-6 sm:px-6 mb-6 rounded-b-[18px]",children:e.jsxs("div",{className:"flex flex-col md:flex-row gap-4 items-center justify-between",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row gap-4 w-full md:w-auto items-center",children:[e.jsxs("div",{className:"flex items-center bg-white px-4 py-2.5 rounded-full shadow-[0_1px_4px_rgba(0,0,0,0.04)] border border-[#e2e8f0] group focus-within:ring-2 focus-within:ring-indigo-500/20 transition-all w-full sm:w-64",children:[e.jsx(qs,{className:"w-4 h-4 text-[#64748b] shrink-0 group-focus-within:text-[#9956DE] transition-colors"}),e.jsx("input",{type:"text",placeholder:"Search students...",value:k,onChange:E=>N(E.target.value),className:"bg-transparent border-none focus:outline-none ml-2 text-[13px] w-full text-[#475569] placeholder:text-[#94a3b8]"})]}),e.jsx("div",{className:"flex items-center gap-2 overflow-x-auto no-scrollbar w-full sm:w-auto p-2 -m-2",children:["all","High","Medium","Low"].map(E=>e.jsx("button",{onClick:()=>W(E),className:`px-4 py-1.5 text-[13px] font-semibold rounded-full whitespace-nowrap transition-colors shadow-md ${R===E?"bg-[#9956DE] text-white":"bg-white text-slate-500 hover:text-slate-700 hover:bg-slate-50"}`,children:E==="all"?"All":`${E} Risk`},E))})]}),e.jsxs("button",{onClick:be,className:"flex items-center gap-2 text-[13px] font-semibold text-slate-500 hover:text-slate-700 transition-colors shrink-0 bg-white px-4 py-2 rounded-full shadow-md hover:bg-slate-50 self-end sm:self-auto",children:[e.jsx(cs,{className:"w-4 h-4"})," Refresh"]})]})}),e.jsxs("div",{className:"bg-[#f5f3ff]/60 border border-[#e0e7ff] rounded-[14px] px-5 py-3 mb-6 flex items-start sm:items-center gap-3",children:[e.jsx("div",{className:"mt-0.5 sm:mt-0 shrink-0",children:e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-[#9956DE]",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("path",{d:"M12 16v-4"}),e.jsx("path",{d:"M12 8h.01"})]})}),e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center flex-1",children:[e.jsxs("span",{className:"text-[#9956DE] font-semibold text-[13px] whitespace-nowrap mr-1",children:["Imported Topic Context",s?` for ${s}`:"",":"]}),w?e.jsx("span",{className:"text-[#8b5cf6] text-[13px]",children:"Loading class-scoped imported topics..."}):G.length>0?e.jsx("div",{className:"flex flex-wrap items-center gap-1.5 mt-1 sm:mt-0",children:G.map((E,Y)=>e.jsxs(he.Fragment,{children:[e.jsx("span",{className:"text-[#8b5cf6] text-[13px]",children:E}),Yfe("name"),children:["Student ",e.jsx(te,{field:"name"})]}),e.jsxs("div",{className:"w-[120px] shrink-0 px-4 flex justify-center cursor-pointer hover:text-white/80 transition-colors",onClick:()=>fe("riskLevel"),children:["Risk Level ",e.jsx(te,{field:"riskLevel"})]}),e.jsxs("div",{className:"w-[200px] shrink-0 px-4 flex items-center gap-1 cursor-pointer hover:text-white/80 transition-colors",onClick:()=>fe("avgQuizScore"),children:["Avg. Score ",e.jsx(te,{field:"avgQuizScore"})]}),e.jsxs("div",{className:"w-[180px] shrink-0 px-4 flex items-center gap-1 cursor-pointer hover:text-white/80 transition-colors",onClick:()=>fe("engagementScore"),children:["Engagement ",e.jsx(te,{field:"engagementScore"})]}),e.jsx("div",{className:"w-[160px] shrink-0 px-4 flex justify-center cursor-pointer hover:text-white/80 transition-colors",children:"Weakest Topic"}),Fr.map((E,Y)=>e.jsx("div",{className:`w-[100px] shrink-0 px-2 flex justify-center ${Y===Fr.length-1?"border-r border-transparent":""}`,children:E.header},E.key))]}),ee.length===0?e.jsxs("div",{className:"py-12 text-center text-slate-500",children:[e.jsx($n,{size:32,className:"mx-auto mb-2 opacity-50"}),e.jsx("p",{className:"text-sm",children:"No students match the current filters"})]}):e.jsx("div",{className:"divide-y divide-border",children:ee.map(E=>(E.student.riskLevel==="High"||E.student.riskLevel,e.jsxs("div",{className:"flex flex-col border-b border-slate-100 group",children:[e.jsxs("div",{className:"flex items-center min-h-[64px] hover:bg-slate-50/60 transition-colors cursor-pointer relative",onClick:()=>void Ie(E.rowKey),children:[e.jsxs("div",{className:"w-[260px] shrink-0 sticky left-0 z-10 bg-white group-hover:bg-slate-50/90 transition-colors px-5 h-full min-h-[64px] flex items-center border-r border-slate-100 shadow-[2px_0_4px_rgba(0,0,0,0.01)]",children:[e.jsx("div",{className:`transition-transform duration-200 mr-3 shrink-0 ${E.expanded?"rotate-90":""}`,children:e.jsx(Ms,{className:"w-4 h-4 text-slate-400"})}),e.jsx("img",{src:E.student.avatar,alt:E.student.name,className:"w-8 h-8 rounded-full bg-border object-cover shrink-0 mr-3"}),e.jsx("span",{className:"font-semibold text-slate-800 text-[14px] truncate",children:E.student.name})]}),e.jsx("div",{className:"w-[120px] shrink-0 px-4 flex justify-center",children:e.jsx("span",{className:`px-3 py-1 rounded-full border text-[11px] font-bold uppercase tracking-wider ${E.student.riskLevel==="High"?"bg-rose-50 text-rose-600 border-rose-200":E.student.riskLevel==="Medium"?"bg-amber-50 text-amber-600 border-amber-200":"bg-emerald-50 text-emerald-600 border-emerald-200"}`,children:E.student.riskLevel})}),e.jsxs("div",{className:"w-[200px] shrink-0 px-4 flex items-center gap-3",children:[e.jsx("div",{className:"flex-1 bg-slate-100 h-2.5 rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full ${E.student.avgQuizScore>=80?"bg-emerald-500":E.student.avgQuizScore>=60?"bg-amber-400":"bg-rose-500"}`,style:{width:`${E.student.avgQuizScore}%`}})}),e.jsxs("span",{className:"text-[13px] font-bold text-slate-800 w-8",children:[E.student.avgQuizScore,"%"]})]}),e.jsxs("div",{className:"w-[180px] shrink-0 px-4 flex items-center gap-3",children:[e.jsx("div",{className:"flex-1 bg-slate-100 h-2.5 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full bg-[#9956DE]",style:{width:`${E.student.engagementScore}%`}})}),e.jsxs("span",{className:"text-[13px] font-bold text-slate-800 w-8",children:[E.student.engagementScore,"%"]})]}),e.jsx("div",{className:"w-[160px] shrink-0 px-4 flex justify-center",children:e.jsx("span",{className:"px-3 py-1 bg-slate-100 text-slate-600 text-[11px] font-medium rounded-full truncate max-w-full border border-slate-200",children:E.student.weakestTopic})}),Fr.map(Y=>{const V=E.competencyMatrix?.[Y.key]??0;return e.jsx("div",{className:"w-[100px] shrink-0 px-2 flex justify-center",children:E.competencyMatrixLoading?e.jsx(gt,{size:12,className:"animate-spin text-muted-foreground"}):E.competencyMatrix?e.jsxs("span",{className:`text-[12px] font-medium px-2 rounded-full border ${V>=80?"text-emerald-600 bg-emerald-50 border-emerald-100":V>=60?"text-amber-600 bg-amber-50 border-amber-100":"text-rose-500 bg-rose-50 border-rose-100"}`,children:[V,"%"]}):e.jsx("span",{className:"text-xs text-muted-foreground",children:"—"})},Y.key)})]}),e.jsx(zt,{children:E.expanded&&e.jsx(Le.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},className:"overflow-hidden bg-slate-50/80 border-t border-slate-100 shadow-inner",children:e.jsxs("div",{className:"flex min-w-[1320px]",children:[e.jsx("div",{className:"w-[260px] shrink-0 sticky left-0 z-10 bg-slate-50/90 border-r border-slate-100 flex items-start justify-end pr-4 py-4",children:e.jsx("div",{className:"w-1.5 h-full rounded-full bg-[#9956DE]/30"})}),e.jsx("div",{className:"flex-1 py-4 pl-6 pr-6",children:E.loading?e.jsxs("div",{className:"flex items-center py-4",children:[e.jsx(gt,{size:16,className:"animate-spin text-indigo-500 mr-2"}),e.jsx("span",{className:"text-sm text-slate-500",children:"Analyzing competency data..."})]}):E.competency?e.jsxs("div",{className:"space-y-4 max-w-4xl",children:[E.competency.recommendedTopics.length>0&&e.jsxs("div",{className:"bg-[#f5f3ff] rounded-[12px] p-4 border border-[#e0e7ff] inline-block shadow-sm mb-4",children:[e.jsxs("h4",{className:"text-[#7274ED] font-semibold text-[13px] flex items-center gap-2 mb-1.5",children:[e.jsx(Gt,{className:"w-4 h-4"})," Recommended Focus Areas"]}),e.jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:E.competency.recommendedTopics.map((Y,V)=>e.jsx("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full border border-indigo-100 bg-white text-indigo-700 text-xs font-medium shadow-sm",children:Y},V))})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:E.competency.competencies.map((Y,V)=>e.jsx(Am,{competency:Y},V))})]}):e.jsx("div",{className:"text-sm text-slate-500 py-4",children:"Failed to load competency details."})})]})})})]},E.rowKey)))})]})})]})},Am=({competency:t})=>{const s=Uo[t.competencyLevel]||Uo.developing;return e.jsxs("div",{className:"bg-card rounded-lg border border-border p-3",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("h6",{className:"text-xs font-bold text-foreground truncate flex-1",children:t.topic}),e.jsx("span",{className:`ml-2 px-2 py-0.5 rounded text-[10px] font-bold uppercase ${s.bg} ${s.text}`,children:t.competencyLevel})]}),e.jsxs("div",{className:"mb-2",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs mb-1",children:[e.jsx("span",{className:"text-slate-500",children:"Efficiency"}),e.jsxs("span",{className:"font-bold text-muted-foreground",children:[t.efficiencyScore,"%"]})]}),e.jsx("div",{className:"h-1.5 bg-muted rounded-full overflow-hidden",children:e.jsx(Le.div,{initial:{width:0},animate:{width:`${t.efficiencyScore}%`},transition:{duration:.6,delay:.1},className:`h-full rounded-full ${s.bar}`})})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground leading-snug line-clamp-2",children:t.perspective})]})},Lm=()=>{const{notifications:t,unreadCount:s,isLoading:a,markAsRead:r,markAllAsRead:o}=pi(),[n,i]=u.useState("all"),l=["streak_reminder","daily_checkin","streak_milestone","achievement_unlocked","level_up","xp_earned","quiz_result"],c=t.filter(S=>!S.isRead&&!l.includes(S.type)).length,d=S=>{switch(S){case"achievement_unlocked":case"achievement":return Bl;case"message":return ec;case"grade":case"quiz_result":return mi;case"reminder":case"streak_reminder":case"daily_checkin":return As;case"risk_alert":return ca;case"sparkles":case"lesson_plan_ready":return ps;case"users":case"student_import":return us;default:return dr}},m=(S,k)=>{switch(S){case"risk_alert":return"bg-rose-50/30 text-rose-500 border-rose-100";case"sparkles":case"lesson_plan_ready":return"bg-purple-50/30 text-[#a855f7] border-purple-100";case"daily_checkin":return"bg-amber-50/20 text-amber-500 border-amber-100";case"users":case"student_import":return"bg-blue-50/30 text-blue-500 border-blue-100";default:return"bg-slate-50 text-slate-500 border-slate-100"}},p=S=>{switch(S){case"risk_alert":return"from-rose-400 to-rose-600 shadow-[0_4px_12px_rgba(244,63,94,0.3)]";case"sparkles":case"lesson_plan_ready":return"from-[#a855f7] to-[#9333ea] shadow-[0_4px_12px_rgba(168,85,247,0.3)]";case"daily_checkin":return"from-amber-300 to-amber-500 shadow-[0_4px_12px_rgba(245,158,11,0.3)]";case"users":case"student_import":return"from-blue-400 to-blue-600 shadow-[0_4px_12px_rgba(59,130,246,0.3)]";default:return"from-slate-400 to-slate-600 shadow-[0_4px_12px_rgba(100,116,139,0.3)]"}},h=u.useMemo(()=>{let S=t.filter(k=>!l.includes(k.type));return n==="unread"&&(S=S.filter(k=>!k.isRead)),n==="important"&&(S=S.filter(k=>k.type==="risk_alert")),S},[t,n]),b=u.useMemo(()=>{const S=[],k=h.filter(g=>so(g.createdAt)),N=h.filter(g=>ao(g.createdAt)),v=h.filter(g=>!so(g.createdAt)&&!ao(g.createdAt));return k.length>0&&S.push({title:"Today",icon:As,items:k}),N.length>0&&S.push({title:"Yesterday",icon:Bn,items:N}),v.length>0&&S.push({title:"Earlier",icon:Bn,items:v}),S},[h]);return e.jsx("div",{className:"w-full h-full flex flex-col bg-[#f8fafc]/50",children:e.jsxs("div",{className:"max-w-[900px] mx-auto w-full p-[24px] xl:p-[32px] space-y-[24px] flex-1 overflow-y-auto no-scrollbar pb-12",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx("button",{onClick:()=>i("all"),className:`px-6 py-2.5 text-[13px] rounded-full whitespace-nowrap transition-all duration-300 border ${n==="all"?"bg-purple-50 text-[#9333ea] border-purple-200 shadow-md font-bold":"bg-white/80 text-[#64748b] border-white hover:border-[#e2e8f0] shadow-sm font-medium"}`,children:"All"}),e.jsxs("button",{onClick:()=>i("unread"),className:`px-6 py-2.5 text-[13px] rounded-full whitespace-nowrap transition-all duration-300 border flex items-center gap-2 ${n==="unread"?"bg-purple-50 text-[#9333ea] border-purple-200 shadow-md font-bold":"bg-white/80 text-[#64748b] border-white hover:border-[#e2e8f0] shadow-sm font-medium"}`,children:["Unread",e.jsx("span",{className:"w-5 h-5 rounded-full bg-slate-100 text-[10px] font-bold flex items-center justify-center text-slate-500",children:c})]}),e.jsxs("button",{onClick:()=>i("important"),className:`px-6 py-2.5 text-[13px] rounded-full whitespace-nowrap transition-all duration-300 border flex items-center gap-2 ${n==="important"?"bg-purple-50 text-[#9333ea] border-purple-200 shadow-md font-bold":"bg-white/80 text-[#64748b] border-white hover:border-[#e2e8f0] shadow-sm font-medium"}`,children:["Important",t.some(S=>S.type==="risk_alert"&&!S.isRead)&&e.jsx("span",{className:"w-2.5 h-2.5 rounded-full bg-rose-500 shadow-[0_0_8px_rgba(244,63,94,0.6)]"})]}),e.jsxs("div",{className:"ml-auto flex items-center gap-3 shrink-0",children:[e.jsx("span",{className:"text-[13px] font-bold text-[#64748b]",children:c>0?`${c} unread`:"No unread"}),e.jsxs("button",{onClick:o,disabled:c===0,className:"bg-white hover:bg-slate-50 border border-slate-200 text-[#475569] text-[13px] font-bold rounded-full px-5 py-2 shadow-sm transition-all hover:shadow-md hover:-translate-y-0.5 flex items-center gap-2 group disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:translate-y-0 disabled:hover:shadow-sm",children:[e.jsx(Ic,{className:"w-4 h-4 text-[#94a3b8] group-hover:text-emerald-500 transition-colors"}),"Mark all as read"]})]})]}),e.jsx("div",{className:"space-y-8",children:a?e.jsxs("div",{className:"bg-white/80 backdrop-blur-[12px] rounded-[24px] border border-white p-12 flex flex-col items-center justify-center gap-4",children:[e.jsx(gt,{className:"w-8 h-8 text-[#a855f7] animate-spin"}),e.jsx("p",{className:"text-[14px] font-medium text-[#64748b]",children:"Syncing notifications..."})]}):b.length===0?e.jsxs("div",{className:"bg-white/80 backdrop-blur-[12px] rounded-[24px] border border-white p-16 flex flex-col items-center justify-center text-center",children:[e.jsx("div",{className:"w-20 h-20 bg-slate-50 rounded-full flex items-center justify-center mb-6 border border-slate-100",children:e.jsx(dr,{className:"w-10 h-10 text-slate-300"})}),e.jsx("h3",{className:"text-[18px] font-bold text-[#1e293b] mb-2",children:"All clear!"}),e.jsx("p",{className:"text-[14px] text-[#64748b] max-w-sm",children:"No notifications found for this filter. New alerts will appear here automatically."})]}):b.map(S=>e.jsxs("div",{children:[e.jsxs("h3",{className:"text-[12px] font-bold text-[#94a3b8] uppercase tracking-wider mb-3 ml-2 flex items-center gap-2",children:[e.jsx(S.icon,{className:"w-4 h-4"})," ",S.title]}),e.jsx("div",{className:"bg-white/80 backdrop-blur-[12px] rounded-[24px] border border-white shadow-[0_4px_24px_rgba(0,0,0,0.03)] overflow-hidden divide-y divide-[#f1f5f9]",children:S.items.map(k=>{const N=d(k.type),v=k.type==="risk_alert";return e.jsxs(Le.div,{layout:!0,onClick:()=>!k.isRead&&r(k.id),className:`relative p-5 flex gap-5 group cursor-pointer hover:bg-white transition-all duration-300 ${k.isRead?"opacity-80":m(k.type)}`,children:[e.jsx("div",{className:`absolute left-0 top-0 w-1.5 h-full transition-colors ${k.isRead?"bg-transparent":v?"bg-rose-500":"bg-[#a855f7]"}`}),e.jsx("div",{className:`w-12 h-12 rounded-full flex items-center justify-center text-white shrink-0 group-hover:scale-110 transition-transform bg-gradient-to-br ${p(k.type)}`,children:e.jsx(N,{className:"w-6 h-6"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex justify-between items-start mb-1",children:[e.jsxs("h4",{className:"text-[15px] font-bold text-[#1e293b] flex items-center gap-2 truncate pr-4",children:[k.title,!k.isRead&&e.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${v?"bg-rose-500 shadow-[0_0_6px_rgba(244,63,94,0.8)]":"bg-[#a855f7] shadow-[0_0_6px_rgba(168,85,247,0.8)]"}`})]}),e.jsxs("span",{className:`text-[12px] font-bold whitespace-nowrap ${k.isRead?"text-[#94a3b8]":v?"text-rose-600":"text-[#a855f7]"}`,children:[Tc(k.createdAt)," ago"]})]}),e.jsx("p",{className:"text-[14px] text-[#475569] font-medium leading-relaxed",children:k.message}),!k.isRead&&k.actionUrl&&e.jsx("div",{className:"mt-3 flex gap-2",children:e.jsx("button",{className:`px-5 py-2 bg-white border rounded-full text-[12px] font-bold shadow-sm transition-all hover:-translate-y-0.5 ${v?"border-rose-200 text-rose-600 hover:bg-rose-50":"border-purple-200 text-[#9333ea] hover:bg-purple-50"}`,children:"Review Plan"})})]}),e.jsx("button",{className:"opacity-0 group-hover:opacity-100 p-2 text-slate-400 hover:text-slate-600 transition-all rounded-full hover:bg-slate-100 shrink-0 self-start",children:e.jsx(Gc,{size:18})})]},k.id)})})]},S.title))})]})})},zm=t=>{const s=t.data(),a=s.startTime,r=s.endTime,o=s.createdAt,n=s.updatedAt,i=l=>{if(l){if(typeof l?.toDate=="function")return l.toDate();if(l instanceof Date)return l}};return{...s,id:t.id,startTime:i(a)||new Date,endTime:i(r),createdAt:i(o)||new Date,updatedAt:i(n)}},Dm=async(t,s)=>{const a=pt(Mt(He,"calendarEvents")),r={id:a.id,userId:t,title:s.title,description:s.description,startTime:s.startTime,endTime:s.endTime,color:s.color,createdAt:new Date};return await ts(a,{...r,createdAt:it(),updatedAt:it()}),r},$m=async(t,s)=>{const a=pt(He,"calendarEvents",t);await es(a,{...s,updatedAt:it()})},Fm=async t=>{await hi(pt(He,"calendarEvents",t))},vl=(t,s={},a,r)=>{if(!t)return a([]),()=>{};const{limitCount:o=500}=s,n=At(Mt(He,"calendarEvents"),Et("userId","==",t),or(o));return fi(n,i=>{a(i.docs.map(l=>zm(l)))},i=>{console.error("Error subscribing to calendar events:",i),r?.(i)})};function Om({className:t,...s}){return e.jsx("textarea",{"data-slot":"textarea",className:ui("resize-none border-input placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 flex field-sizing-content min-h-16 w-full rounded-md border bg-input-background px-3 py-2 text-base transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",t),...s})}const ra=t=>String(t).padStart(2,"0"),Gs=t=>`${t.getFullYear()}-${ra(t.getMonth()+1)}-${ra(t.getDate())}`,nn=t=>new Date(t.getFullYear(),t.getMonth(),1),Go=t=>new Date(t.getFullYear(),t.getMonth()+1,0),Pm=t=>{const s=nn(t),a=s.getDay(),r=new Date(s);return r.setDate(s.getDate()-a),r.setHours(0,0,0,0),r},Bm=(t,s)=>{const a=new Date(t);return a.setDate(a.getDate()+s),a},Qo=(t,s)=>t.getFullYear()===s.getFullYear()&&t.getMonth()===s.getMonth()&&t.getDate()===s.getDate(),Hm=(t,s)=>t.getFullYear()===s.getFullYear()&&t.getMonth()===s.getMonth(),Um=t=>t.toLocaleDateString(void 0,{month:"long",year:"numeric"}),qa=t=>t.toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"}),Vo=(t,s)=>{const[a,r,o]=t.split("-").map(l=>parseInt(l,10)),[n,i]=s.split(":").map(l=>parseInt(l,10));return new Date(a,(r||1)-1,o||1,n||0,i||0,0,0)},Gm=["purple","blue","emerald","amber","rose"],Or=t=>{switch(t){case"blue":return"#3b82f6";case"emerald":return"#10b981";case"amber":return"#f59e0b";case"rose":return"#f43f5e";case"purple":default:return"#a855f7"}},Qm=(t,s=!1)=>{if(s)return"bg-blue-50 text-blue-700 border-blue-100 opacity-80";switch(t){case"blue":return"bg-blue-50 text-blue-700 border-blue-100 opacity-90 hover:bg-blue-100";case"emerald":return"bg-emerald-50 text-emerald-700 border-emerald-100 opacity-90 hover:bg-emerald-100";case"amber":return"bg-amber-50 text-amber-700 border-amber-100 opacity-90 hover:bg-amber-100";case"rose":return"bg-rose-50 text-rose-700 border-rose-100 opacity-90 hover:bg-rose-100";case"purple":default:return"bg-purple-50 text-purple-700 border-purple-100 opacity-90 hover:bg-purple-100"}},Vm=(t,s=!1)=>{if(s)return{dot:"bg-[#3b82f6]",border:"border-l-blue-400",time:"text-blue-600 border-blue-50"};switch(t){case"blue":return{dot:"bg-blue-500",border:"border-l-blue-400",time:"text-blue-600 border-blue-50"};case"emerald":return{dot:"bg-emerald-500",border:"border-l-emerald-400",time:"text-emerald-600 border-emerald-50"};case"amber":return{dot:"bg-amber-500",border:"border-l-amber-400",time:"text-amber-600 border-amber-50"};case"rose":return{dot:"bg-rose-500",border:"border-l-rose-400",time:"text-rose-600 border-rose-50"};case"purple":default:return{dot:"bg-[#a855f7]",border:"border-l-[#a855f7]",time:"text-[#a855f7] border-purple-50"}}},Pr=[{names:["sun","sunday"],day:0},{names:["mon","monday"],day:1},{names:["tue","tues","tuesday"],day:2},{names:["wed","wednesday"],day:3},{names:["thu","thurs","thursday"],day:4},{names:["fri","friday"],day:5},{names:["sat","saturday"],day:6}];function Wm(t){const s=t.toLowerCase(),a=new Set;if(s.includes("daily")||s.includes("everyday"))return[0,1,2,3,4,5,6];if(s.includes("weekends"))return[0,6];if(s.includes("weekdays"))return[1,2,3,4,5];const r=s.match(/(mon|tue|wed|thu|fri|sat|sun)[\s/-]*(mon|tue|wed|thu|fri|sat|sun)/);if(r){const o=Pr.find(i=>i.names.includes(r[1]))?.day,n=Pr.find(i=>i.names.includes(r[2]))?.day;if(o!==void 0&&n!==void 0){let i=o;for(;a.add(i),i!==n;)i=(i+1)%7;return Array.from(a)}}return Pr.forEach(({names:o,day:n})=>{o.some(i=>s.includes(i))&&a.add(n)}),Array.from(a).sort((o,n)=>o-n)}const qm=({classes:t,teacherId:s})=>{const{currentUser:a}=hs(),[r,o]=u.useState([]),[n,i]=u.useState(!0),[l,c]=u.useState(""),[d,m]=u.useState(!0),[p,h]=u.useState(()=>{const T=new Date;return T.setHours(0,0,0,0),T}),[b,S]=u.useState(()=>{const T=new Date;return T.setHours(0,0,0,0),T}),[k,N]=u.useState(new Set),[v,g]=u.useState(!1),[I,z]=u.useState(null),[R,W]=u.useState(!1),[f,C]=u.useState(""),[w,$]=u.useState(""),[A,y]=u.useState(()=>Gs(new Date)),[q,J]=u.useState("09:00"),[re,le]=u.useState(""),[ne,be]=u.useState("purple"),[Ie,de]=u.useState(!1),[fe,H]=u.useState(null);u.useEffect(()=>{if(!a?.uid){o([]),i(!1);return}c(""),i(!0);const T=vl(a.uid,{limitCount:500},Q=>{o(Q),i(!1)},()=>{c("Unable to load calendar events right now."),i(!1)});return()=>T()},[a?.uid]);const ee=u.useMemo(()=>{const T=nn(p);return T.setHours(0,0,0,0),T},[p]),oe=u.useMemo(()=>{const T=Go(p);return T.setHours(23,59,59,999),T},[p]),Re=u.useMemo(()=>{if(!t||t.length===0)return[];const T=[],Q=nn(p),ue=Go(p),ce=new Date(Q);for(;ce<=ue;){const ae=ce.getDay();t.forEach(Ce=>{if(Wm(Ce.schedule).includes(ae)){const Je=`schedule-${Ce.id}-${Gs(ce)}`;k.has(Je)||T.push({id:Je,userId:s||"",title:Ce.name,startTime:new Date(ce),createdAt:new Date})}}),ce.setDate(ce.getDate()+1)}return T},[t,p,s,k]),Fe=u.useMemo(()=>[...r,...Re],[r,Re]),Pe=u.useMemo(()=>Fe.filter(T=>T.startTime>=ee&&T.startTime<=oe).sort((T,Q)=>T.startTime.getTime()-Q.startTime.getTime()),[Fe,ee,oe]),G=u.useMemo(()=>{const T=new Map;for(const Q of Pe){const ue=Gs(Q.startTime),ce=T.get(ue)||[];ce.push(Q),T.set(ue,ce)}return T},[Pe]),te=u.useMemo(()=>Gs(b),[b]),E=u.useMemo(()=>[...G.get(te)||[]].sort((Q,ue)=>Q.startTime.getTime()-ue.startTime.getTime()),[G,te]),Y=u.useMemo(()=>{const T=Pm(p);return Array.from({length:42}).map((Q,ue)=>Bm(T,ue))},[p]),V=T=>{const Q=Gs(T);z(null),C(""),$(""),y(Q),J("09:00"),le(""),be("purple"),g(!0)},pe=T=>{T.id.startsWith("schedule-")?(N(Q=>new Set(Q).add(T.id)),z(null)):z(T.id),C(T.title),$(T.description||""),y(Gs(T.startTime)),J(ra(T.startTime.getHours())+":"+ra(T.startTime.getMinutes())),le(T.endTime?ra(T.endTime.getHours())+":"+ra(T.endTime.getMinutes()):""),be(T.color||"purple"),de(!1),g(!0)},D=(T,Q)=>{T.stopPropagation(),H(Q),de(!0)},j=async()=>{const T=a?.uid||s||"local-user";if(!f.trim()){c("Event title is required.");return}W(!0),c("");const Q=Vo(A,q),ue=re?Vo(A,re):void 0,ce={title:f.trim(),description:w.trim()?w.trim():void 0,startTime:Q,endTime:ue&&ue.getTime()>Q.getTime()?ue:void 0,color:ne};try{if(I)o(ae=>ae.map(Ce=>Ce.id===I?{...Ce,...ce}:Ce)),await $m(I,ce);else{const ae=`temp-${Date.now()}`;o(Ce=>[...Ce,{id:ae,userId:T,createdAt:new Date,...ce}]),await Dm(T,ce)}g(!1)}catch(ae){console.error(ae),g(!1)}finally{W(!1)}},_=async T=>{if(T.startsWith("schedule-")){N(Q=>new Set(Q).add(T)),fe?.id===T&&de(!1);return}c(""),o(Q=>Q.filter(ue=>ue.id!==T)),fe?.id===T&&de(!1);try{await Fm(T)}catch(Q){console.error(Q)}};return e.jsxs("div",{className:"w-full h-full flex flex-col px-[24px] xl:px-[32px] py-[24px] xl:py-[32px] overflow-hidden",children:[e.jsxs("div",{className:"flex flex-col lg:flex-row gap-6 flex-1 min-h-0 w-full max-w-[1400px] mx-auto",children:[e.jsx("div",{className:`flex flex-col flex-1 min-w-0 transition-all duration-500 ${d?"lg:w-[65%] xl:w-[70%]":"lg:w-full"}`,children:e.jsxs("div",{className:"bg-white/90 backdrop-blur-[12px] rounded-[24px] border border-white shadow-[0_8px_32px_rgba(0,0,0,0.04)] overflow-hidden flex flex-col h-full",children:[e.jsxs("div",{className:"p-6 border-b border-[#a855f7] bg-[#a855f7] shrink-0 flex justify-between items-center rounded-t-[24px] relative overflow-hidden group",children:[e.jsx("div",{className:"absolute -bottom-24 -right-12 w-64 h-64 bg-white/10 rounded-full"}),e.jsx("div",{className:"absolute -top-20 left-1/4 w-40 h-40 bg-white/5 rounded-full"}),e.jsxs("div",{className:"flex items-center gap-5 relative z-10",children:[e.jsx("button",{onClick:()=>h(new Date(p.getFullYear(),p.getMonth()-1,1)),"aria-label":"Previous month",className:"w-9 h-9 rounded-full flex items-center justify-center text-[#6d28d9] bg-white hover:bg-slate-50 transition-colors shadow-sm hover:shadow-md active:scale-90",children:e.jsx(zs,{className:"w-5 h-5"})}),e.jsx("h2",{className:"text-[22px] font-bold text-white w-44 text-center tracking-tight",children:Um(p)}),e.jsx("button",{onClick:()=>h(new Date(p.getFullYear(),p.getMonth()+1,1)),"aria-label":"Next month",className:"w-9 h-9 rounded-full flex items-center justify-center text-[#6d28d9] bg-white hover:bg-slate-50 transition-colors shadow-sm hover:shadow-md active:scale-90",children:e.jsx(Ms,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"flex items-center gap-3 relative z-10",children:[e.jsxs("span",{className:"text-[13px] font-bold text-[#6d28d9] bg-white px-4 py-1.5 rounded-full shadow-sm",children:[Pe.length," events"]}),e.jsx("button",{onClick:()=>m(!d),className:`w-9 h-9 rounded-full flex items-center justify-center transition-all shadow-sm hover:shadow-md border ${d?"text-[#6d28d9] bg-white border-white":"text-white bg-white/20 border-white/30 backdrop-blur-md"}`,title:d?"Hide Sidebar":"Show Sidebar","aria-label":d?"Hide Sidebar":"Show Sidebar",children:e.jsx(ed,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"flex-1 flex flex-col min-h-0 overflow-y-auto custom-scrollbar",children:[e.jsx("div",{className:"grid grid-cols-7 text-center border-b border-slate-200/60 pb-5 shrink-0 sticky top-0 bg-white z-20 shadow-[0_10px_10px_-10px_rgba(0,0,0,0.05)] px-4 pt-6",children:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"].map(T=>e.jsx("div",{className:"text-[12px] font-bold text-[#475569] uppercase tracking-widest",children:T},T))}),e.jsx("div",{className:"grid grid-cols-7 gap-2 pb-6 px-4",children:Y.map(T=>{const Q=Gs(T),ue=G.get(Q)||[],ce=Qo(T,b),ae=Qo(T,new Date),Ce=Hm(T,p);return e.jsxs("div",{onClick:()=>S(new Date(T)),className:`group p-2 rounded-lg transition-all cursor-pointer border-2 flex flex-col relative min-h-[100px] xl:min-h-[120px] ${ce?"bg-purple-50/50 border-[#a855f7] shadow-sm z-10":ae?"bg-purple-50/20 border-purple-300 shadow-[inset_0_0_20px_rgba(168,85,247,0.05)] hover:bg-purple-50/40 hover:border-purple-400":"border-transparent hover:bg-slate-50 hover:border-slate-200"} ${Ce?"":"opacity-30 grayscale"}`,children:[e.jsx("div",{className:"flex justify-between items-start",children:e.jsx("span",{className:`w-7 h-7 rounded-full flex items-center justify-center font-bold text-[14px] transition-all ${ae?"bg-gradient-to-br from-[#a855f7] to-[#9333ea] text-white shadow-md":ce?"text-[#9333ea]":"text-[#1e293b]"}`,children:T.getDate()})}),e.jsxs("div",{className:"mt-1 space-y-1",children:[ue.slice(0,3).map(Ne=>{const Je=Ne.id.startsWith("schedule-");return e.jsx("div",{onClick:$e=>D($e,Ne),className:`w-full truncate text-[11px] font-bold px-2 py-1.5 rounded border shadow-sm transition-all hover:-translate-y-[1px] hover:shadow-md cursor-pointer ${Qm(Ne.color,Je)}`,children:Ne.title},Ne.id)}),ue.length>3&&e.jsxs("div",{className:"text-[10px] font-bold text-[#64748b] pl-1 pt-0.5",children:["+",ue.length-3," more"]})]})]},Q)})})]})]})}),e.jsx(zt,{children:d&&e.jsx(Le.div,{initial:{opacity:0,x:20},animate:{opacity:1,x:0},exit:{opacity:0,x:20},className:"lg:w-[35%] xl:w-[30%] h-full shrink-0",children:e.jsxs("div",{className:"bg-white/90 backdrop-blur-[12px] rounded-[24px] border border-white shadow-[0_8px_32px_rgba(0,0,0,0.04)] overflow-hidden flex flex-col h-full",children:[e.jsxs("div",{className:"p-6 border-b border-[#f1f5f9] bg-white shrink-0 flex justify-between items-center relative overflow-hidden group",children:[e.jsx("div",{className:"absolute top-[-30px] right-[-30px] w-24 h-24 bg-purple-50 rounded-full mix-blend-multiply filter blur-2xl opacity-50 transition-transform duration-700 group-hover:scale-150"}),e.jsxs("div",{className:"relative z-10",children:[e.jsx("h2",{className:"text-[20px] font-bold text-[#1e293b]",children:b.toLocaleDateString(void 0,{weekday:"long"})}),e.jsx("p",{className:"text-[13px] font-medium text-[#64748b]",children:b.toLocaleDateString(void 0,{day:"numeric",month:"long",year:"numeric"})})]}),e.jsx("button",{onClick:()=>V(b),title:"Add Event",className:"w-10 h-10 flex items-center justify-center rounded-full bg-[#a855f7] text-white hover:bg-[#9333ea] shadow-md shadow-purple-200 transition-all hover:scale-105 active:scale-95 relative z-10",children:e.jsx(da,{className:"w-5 h-5"})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-6 space-y-6 custom-scrollbar pb-12",children:E.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-20 text-center opacity-40",children:[e.jsx(Er,{className:"w-12 h-12 text-slate-300 mb-4"}),e.jsx("p",{className:"text-[14px] font-bold text-[#1e293b]",children:"No events today"}),e.jsx("p",{className:"text-[12px] text-[#64748b]",children:"Schedule a meeting or add a class."})]}):E.map(T=>{const Q=T.id.startsWith("schedule-"),ue=Vm(T.color,Q);return e.jsxs("div",{className:"relative pl-6 before:absolute before:left-2 before:top-2 before:bottom-[-24px] before:w-[2px] before:bg-slate-100 last:before:hidden",children:[e.jsx("div",{className:`absolute left-0 top-1.5 w-4 h-4 rounded-full border-[3px] border-white shadow-sm z-10 ${ue.dot}`}),e.jsxs("div",{onClick:ce=>D(ce,T),className:`group relative bg-white border border-[#e2e8f0] rounded-[20px] p-5 shadow-sm hover:shadow-md hover:-translate-y-0.5 transition-all border-l-[6px] cursor-pointer ${ue.border}`,children:[e.jsx("div",{className:"flex justify-between items-start mb-2",children:e.jsx("h4",{className:"text-[15px] font-bold text-[#1e293b] group-hover:text-[#9333ea] transition-colors break-words line-clamp-2 w-full pr-2",children:T.title})}),e.jsxs("div",{className:`flex items-center gap-2 text-[11px] font-bold bg-slate-50 w-max px-2.5 py-1 rounded-lg border mb-3 ${ue.time}`,children:[e.jsx(As,{className:"w-3.5 h-3.5"})," ",e.jsxs("span",{children:[qa(T.startTime),T.endTime?` - ${qa(T.endTime)}`:""]})]}),T.description&&e.jsx("p",{className:"text-[13px] font-medium text-[#64748b] bg-slate-50/50 px-3 py-2 rounded-xl border border-slate-100/30 break-words whitespace-normal w-full overflow-hidden",children:T.description})]})]},T.id)})})]})})})]}),e.jsx(Qn,{open:v,onOpenChange:g,children:e.jsx(Vn,{className:"sm:max-w-[500px] p-0 overflow-hidden rounded-[28px] border-none shadow-2xl [&>button]:hidden",children:e.jsxs("div",{className:"p-8 bg-white",children:[e.jsxs(_c,{className:"mb-6",children:[e.jsx(Ec,{className:"text-[24px] font-bold text-[#1e293b] tracking-tight",children:I?"Edit Event":"Add New Event"}),e.jsx(Rc,{className:"text-[14px] text-[#64748b]",children:"Schedule a classroom activity or reminder."})]}),l&&e.jsx("p",{className:"text-rose-500 text-sm font-semibold mb-4",children:l}),e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-[13px] font-bold text-[#1e293b] ml-1",children:"Event Title"}),e.jsx(Is,{value:f,onChange:T=>C(T.target.value),placeholder:"e.g., Mathematics Quiz - Grade 11",className:"bg-white border-slate-200 focus:border-[#a855f7] focus:ring-4 focus:ring-purple-50 rounded-xl h-12 px-4 transition-all text-[14px]"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-[13px] font-bold text-[#1e293b] ml-1",children:"Date"}),e.jsx(Is,{type:"date",value:A,onChange:T=>y(T.target.value),className:"bg-white border-slate-200 focus:border-[#a855f7] rounded-xl h-12 px-4 text-[14px]"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-[13px] font-bold text-[#1e293b] ml-1",children:"Start Time"}),e.jsx(Is,{type:"time",value:q,onChange:T=>J(T.target.value),className:"bg-white border-slate-200 focus:border-[#a855f7] rounded-xl h-12 px-4 text-[14px]"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-[13px] font-bold text-[#1e293b] ml-1",children:"Notes (Optional)"}),e.jsx(Om,{value:w,onChange:T=>$(T.target.value),placeholder:"Additional details about this event...",className:"bg-white border-slate-200 focus:border-[#a855f7] rounded-xl min-h-[100px] p-4 transition-all text-[14px] break-all"})]}),e.jsxs("div",{className:"space-y-2 pt-2",children:[e.jsx("label",{className:"text-[13px] font-bold text-[#1e293b] ml-1",children:"Color Theme"}),e.jsx("div",{className:"flex gap-3 ml-1",children:Gm.map(T=>e.jsx("button",{onClick:()=>be(T),className:`w-8 h-8 rounded-full flex items-center justify-center transition-all ${ne===T?"ring-2 ring-offset-2 ring-slate-800 scale-110 shadow-sm":"hover:scale-110 opacity-80 hover:opacity-100"}`,style:{backgroundColor:Or(T)},title:T,children:ne===T&&e.jsx(Ht,{className:"w-4 h-4 text-white"})},T))})]})]}),e.jsxs("div",{className:"flex gap-3 mt-8",children:[e.jsx(St,{variant:"outline",onClick:()=>g(!1),className:"flex-1 h-12 rounded-xl font-bold border-slate-200 hover:bg-slate-100 transition-all text-[14px]",children:"Cancel"}),e.jsx(St,{onClick:j,disabled:R,className:"flex-[1.5] h-12 rounded-xl font-bold bg-[#a855f7] hover:bg-[#9333ea] text-white shadow-lg shadow-purple-200 transition-all hover:scale-[1.02] text-[14px]",children:R?e.jsx(gt,{className:"w-5 h-5 animate-spin"}):"Save Event"})]})]})})}),e.jsx(Qn,{open:Ie,onOpenChange:de,children:e.jsx(Vn,{className:"sm:max-w-[400px] p-0 overflow-hidden rounded-[24px] border-none shadow-2xl [&>button]:hidden",children:fe&&e.jsxs("div",{className:"p-8 bg-white relative",children:[e.jsx("button",{onClick:()=>de(!1),"aria-label":"Close event details",className:"absolute top-4 right-4 p-2 text-slate-400 hover:text-slate-600 hover:bg-slate-100 rounded-full transition-colors",children:e.jsx(Xt,{size:18})}),e.jsxs("div",{className:"flex items-start gap-4 mb-6",children:[e.jsx("div",{className:"w-12 h-12 rounded-2xl flex items-center justify-center shrink-0",style:{backgroundColor:Or(fe.color||"purple")+"20",color:Or(fe.color||"purple")},children:fe.id.startsWith("schedule-")?e.jsx(nr,{size:24}):e.jsx(Er,{size:24})}),e.jsxs("div",{className:"pr-6",children:[e.jsx("h3",{className:"text-[18px] font-bold text-[#1e293b] leading-tight mb-2",children:fe.title}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2.5 py-1 rounded-md bg-slate-100 text-slate-600 text-[12px] font-semibold border border-slate-200",children:[e.jsx(Er,{size:12}),fe.startTime.toLocaleDateString(void 0,{weekday:"short",month:"short",day:"numeric"})]}),e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2.5 py-1 rounded-md bg-slate-100 text-slate-600 text-[12px] font-semibold border border-slate-200",children:[e.jsx(As,{size:12}),qa(fe.startTime),fe.endTime?` - ${qa(fe.endTime)}`:""]})]})]})]}),fe.description&&e.jsxs("div",{className:"mb-8",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(Oc,{size:16,className:"text-slate-400"}),e.jsx("h4",{className:"text-[13px] font-bold text-slate-700",children:"Details"})]}),e.jsx("p",{className:"text-[14px] text-slate-600 leading-relaxed bg-slate-50/50 p-4 rounded-xl border border-slate-100/50 break-words",children:fe.description})]}),e.jsxs("div",{className:"flex gap-3 pt-2 border-t border-slate-100",children:[e.jsxs(St,{variant:"outline",onClick:()=>_(fe.id),className:"flex-1 h-11 rounded-xl font-bold border-rose-200 text-rose-600 hover:bg-rose-50 hover:text-rose-700 transition-all text-[13px]",children:[e.jsx(wi,{className:"w-4 h-4 mr-2"})," Delete"]}),e.jsxs(St,{onClick:()=>pe(fe),className:"flex-1 h-11 rounded-xl font-bold bg-[#1e293b] hover:bg-slate-800 text-white shadow-lg shadow-slate-200 transition-all hover:scale-[1.02] text-[13px]",children:[e.jsx(ki,{className:"w-4 h-4 mr-2"})," Edit Event"]})]})]})})})]})},hr=[{hex:"#9956DE",bg:"bg-[#9956DE]/10",border:"border-[#9956DE]/20",borderLeft:"border-l-[#9956DE]",text:"text-[#9956DE]",groupHover:"group-hover:text-[#9956DE]"},{hex:"#7274ED",bg:"bg-[#7274ED]/10",border:"border-[#7274ED]/20",borderLeft:"border-l-[#7274ED]",text:"text-[#7274ED]",groupHover:"group-hover:text-[#7274ED]"},{hex:"#1FA7E1",bg:"bg-[#1FA7E1]/10",border:"border-[#1FA7E1]/20",borderLeft:"border-l-[#1FA7E1]",text:"text-[#1FA7E1]",groupHover:"group-hover:text-[#1FA7E1]"},{hex:"#6ED1CF",bg:"bg-[#6ED1CF]/10",border:"border-[#6ED1CF]/20",borderLeft:"border-l-[#6ED1CF]",text:"text-[#6ED1CF]",groupHover:"group-hover:text-[#6ED1CF]"},{hex:"#FFB356",bg:"bg-[#FFB356]/10",border:"border-[#FFB356]/20",borderLeft:"border-l-[#FFB356]",text:"text-[#FFB356]",groupHover:"group-hover:text-[#FFB356]"}],Wo=({classes:t,onSelectClass:s,onOpenNotifications:a,onOpenProfile:r,insightDismissed:o,onOpenInsightModal:n,viewType:i="analytics",onCreateClass:l})=>{const{currentUser:c,userProfile:d}=hs(),[m,p]=u.useState(""),h=i==="competency",b=t.reduce((g,I)=>g+(I.studentCount||0),0),S=t.reduce((g,I)=>g+(I.atRiskCount||0),0),k=t.length>0?(t.reduce((g,I)=>g+(I.avgScore||0),0)/t.length).toFixed(1):0,N=u.useMemo(()=>{const g=[],I=t.filter(R=>R.atRiskCount>0);if(I.length>0){const R=[...I].sort((W,f)=>f.atRiskCount-W.atRiskCount)[0];g.push({icon:Kr,text:e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"font-bold text-white",children:R.name})," has ",R.atRiskCount," at-risk student",R.atRiskCount>1?"s":""," needing intervention."]})})}const z=t.filter(R=>R.avgScore>0&&R.avgScore<60);return z.length>0&&g.push({icon:Kr,text:e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"font-bold text-white",children:[z.length," class",z.length>1?"es":""]})," below 60% average — consider review sessions."]})}),S===0&&b>0&&g.push({icon:ps,text:e.jsxs(e.Fragment,{children:["All ",e.jsxs("span",{className:"font-bold text-white",children:[b," students"]})," are on track. Great work!"]})}),t.length>0&&Number(k)===0&&g.push({icon:Gt,text:e.jsxs(e.Fragment,{children:["No quiz data yet. ",e.jsx("span",{className:"font-bold text-white",children:"Assign assessments"})," to start tracking progress."]})}),g.length===0&&g.push({icon:ps,text:e.jsx(e.Fragment,{children:"No action items right now. Check back after students complete activities."})}),g},[t,S,b,k]),v=t.filter(g=>g.name.toLowerCase().includes(m.toLowerCase())||(g.gradeLevel||"").toLowerCase().includes(m.toLowerCase()));return e.jsx("div",{className:"h-full overflow-y-auto w-full block",children:e.jsxs("div",{className:"max-w-[1400px] mx-auto p-3 sm:p-[24px] xl:p-[32px] space-y-3 sm:space-y-[24px]",children:[e.jsx("div",{className:"flex flex-col md:flex-row md:items-center justify-between gap-4",children:e.jsx("div",{className:"flex-1 max-w-xl",children:e.jsxs("div",{className:"flex items-center bg-white/80 px-4 py-2.5 rounded-[16px] shadow-[0_1px_4px_rgba(0,0,0,0.04)] border border-white backdrop-blur-[12px] group focus-within:ring-2 focus-within:ring-indigo-500/20 transition-all",children:[e.jsx(qs,{className:"w-4 h-4 text-[#64748b] shrink-0 group-focus-within:text-[#4f46e5] transition-colors"}),e.jsx("input",{type:"text",placeholder:"Global search for a student across all classes...",value:m,onChange:g=>p(g.target.value),className:"bg-transparent border-none focus:outline-none ml-3 text-[13px] w-full text-[#475569] placeholder:text-[#94a3b8]"})]})})}),h?e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-[16px]",children:[e.jsxs("div",{className:"relative overflow-hidden bg-gradient-to-br from-[#a855f7] to-[#9333ea] rounded-[16px] p-[20px] shadow-[0_4px_12px_rgba(168,85,247,0.2)] flex flex-col justify-between h-full group text-white",children:[e.jsx("div",{className:"absolute -right-12 -bottom-12 w-40 h-40 bg-white/10 rounded-full"}),e.jsxs("div",{className:"flex items-start justify-between relative z-10 mb-4",children:[e.jsx("span",{className:"text-[13px] font-medium text-white/90",children:"Total Students Evaluated"}),e.jsx("div",{className:"w-8 h-8 rounded-full border border-white/30 flex items-center justify-center bg-white/10",children:e.jsx(us,{className:"w-4 h-4 text-white"})})]}),e.jsx("div",{className:"text-[32px] font-bold relative z-10 leading-none mb-6",children:b}),e.jsx("div",{className:"flex items-center justify-between relative z-10 border-t border-white/20 pt-3",children:e.jsx("span",{className:"text-[12px] font-medium text-white/90",children:"Active across all classes"})})]}),e.jsxs("div",{className:"relative overflow-hidden bg-gradient-to-br from-[#0ea5e9] to-[#0284c7] rounded-[16px] p-[20px] shadow-[0_4px_12px_rgba(14,165,233,0.2)] flex flex-col justify-between h-full group text-white",children:[e.jsx("div",{className:"absolute -right-12 -bottom-12 w-40 h-40 bg-white/10 rounded-full"}),e.jsxs("div",{className:"flex items-start justify-between relative z-10 mb-4",children:[e.jsx("span",{className:"text-[13px] font-medium text-white/90",children:"Global Avg Competency"}),e.jsx("div",{className:"w-8 h-8 rounded-full border border-white/30 flex items-center justify-center bg-white/10",children:e.jsx(ms,{className:"w-4 h-4 text-white"})})]}),e.jsxs("div",{className:"text-[32px] font-bold relative z-10 leading-none mb-6",children:[k,"%"]}),e.jsx("div",{className:"flex items-center justify-between relative z-10 border-t border-white/20 pt-3",children:e.jsxs("span",{className:"text-[12px] font-medium text-white/90",children:["Across ",t.length," ",t.length===1?"class":"classes"]})})]}),e.jsxs("div",{className:"relative overflow-hidden bg-gradient-to-br from-[#f97316] to-[#ea580c] rounded-[16px] p-[20px] shadow-[0_4px_12px_rgba(249,115,22,0.2)] flex flex-col justify-between h-full group text-white",children:[e.jsx("div",{className:"absolute -right-12 -bottom-12 w-40 h-40 bg-white/10 rounded-full"}),e.jsxs("div",{className:"flex items-start justify-between relative z-10 mb-4",children:[e.jsx("span",{className:"text-[13px] font-medium text-white/90",children:"Universal Weakness"}),e.jsx("div",{className:"w-8 h-8 rounded-full border border-white/30 flex items-center justify-center bg-white/10",children:e.jsx(ms,{className:"w-4 h-4 text-white"})})]}),e.jsx("div",{className:"text-[20px] font-bold relative z-10 leading-tight mb-2 truncate",children:"Foundational Skills"}),e.jsx("div",{className:"flex items-center justify-between relative z-10 border-t border-white/20 pt-3 mt-auto",children:e.jsxs("span",{className:"text-[12px] font-medium text-white/90",children:["Identified in ",t.length," classes"]})})]})]}):e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-12 gap-2 sm:gap-[16px]",children:[e.jsxs("div",{className:"lg:col-span-8 grid grid-cols-3 sm:grid-cols-3 gap-2 sm:gap-[16px]",children:[e.jsxs("div",{className:"relative overflow-hidden bg-gradient-to-br from-[#10b981] to-[#059669] rounded-[14px] sm:rounded-[16px] p-[14px] sm:p-[20px] shadow-[0_4px_12px_rgba(16,185,129,0.2)] flex flex-col justify-between h-full group text-white",children:[e.jsx("div",{className:"absolute -right-12 -bottom-12 w-40 h-40 bg-white/10 rounded-full"}),e.jsxs("div",{className:"flex items-start justify-between relative z-10 mb-2 sm:mb-4",children:[e.jsx("span",{className:"text-[11px] sm:text-[13px] font-medium text-white/90",children:"Total Students"}),e.jsx("div",{className:"w-8 h-8 rounded-full border border-white/30 flex items-center justify-center bg-white/10",children:e.jsx(us,{className:"w-4 h-4 text-white"})})]}),e.jsx("div",{className:"text-[24px] sm:text-[32px] font-bold relative z-10 leading-none mb-3 sm:mb-6",children:b}),e.jsx("div",{className:"flex items-center justify-between relative z-10 border-t border-white/20 pt-3",children:e.jsxs("span",{className:"text-[12px] font-medium text-white/90",children:["Across ",t.length," ",t.length===1?"class":"classes"]})})]}),e.jsxs("div",{className:"relative overflow-hidden bg-gradient-to-br from-[#0ea5e9] to-[#0284c7] rounded-[14px] sm:rounded-[16px] p-[14px] sm:p-[20px] shadow-[0_4px_12px_rgba(14,165,233,0.2)] flex flex-col justify-between h-full group text-white",children:[e.jsx("div",{className:"absolute -right-12 -bottom-12 w-40 h-40 bg-white/10 rounded-full"}),e.jsxs("div",{className:"flex items-start justify-between relative z-10 mb-2 sm:mb-4",children:[e.jsx("span",{className:"text-[11px] sm:text-[13px] font-medium text-white/90",children:"Class average"}),e.jsx("div",{className:"w-8 h-8 rounded-full border border-white/30 flex items-center justify-center bg-white/10",children:e.jsx(ms,{className:"w-4 h-4 text-white"})})]}),e.jsxs("div",{className:"text-[24px] sm:text-[32px] font-bold relative z-10 leading-none mb-3 sm:mb-6",children:[k,"%"]}),e.jsx("div",{className:"flex items-center justify-between relative z-10 border-t border-white/20 pt-3",children:e.jsxs("span",{className:"text-[12px] font-medium text-white/90",children:["Across ",t.length," ",t.length===1?"class":"classes"]})})]}),e.jsxs("div",{className:"relative overflow-hidden bg-gradient-to-br from-[#f97316] to-[#ea580c] rounded-[14px] sm:rounded-[16px] p-[14px] sm:p-[20px] shadow-[0_4px_12px_rgba(249,115,22,0.2)] flex flex-col justify-between h-full group text-white",children:[e.jsx("div",{className:"absolute -right-12 -bottom-12 w-40 h-40 bg-white/10 rounded-full"}),e.jsxs("div",{className:"flex items-start justify-between relative z-10 mb-2 sm:mb-4",children:[e.jsx("span",{className:"text-[11px] sm:text-[13px] font-medium text-white/90",children:"At risk"}),e.jsx("div",{className:"w-8 h-8 rounded-full border border-white/30 flex items-center justify-center bg-white/10",children:e.jsx(br,{className:"w-4 h-4 text-white"})})]}),e.jsx("div",{className:"text-[24px] sm:text-[32px] font-bold relative z-10 leading-none mb-3 sm:mb-6",children:S}),e.jsxs("div",{className:"flex items-center justify-between relative z-10 border-t border-white/20 pt-3",children:[e.jsx("span",{className:"text-[12px] font-medium text-white/90",children:"Requires attention"}),e.jsxs("span",{className:"text-[11px] font-bold bg-white/20 px-2 py-0.5 rounded-[4px] backdrop-blur-sm",children:[b>0?Math.round(S/b*100):0,"%"]})]})]})]}),e.jsxs("div",{className:"lg:col-span-4 relative overflow-hidden bg-gradient-to-br from-[#a855f7] to-[#9333ea] rounded-[16px] p-[20px] shadow-[0_4px_12px_rgba(168,85,247,0.2)] flex flex-col text-white",children:[e.jsx("div",{className:"absolute -right-12 -top-12 w-40 h-40 bg-white/10 rounded-full"}),e.jsxs("div",{className:"flex justify-between items-center mb-4 relative z-10 border-b border-white/20 pb-3",children:[e.jsxs("h3",{className:"text-[14px] font-semibold text-white flex items-center gap-2",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-white animate-pulse shadow-[0_0_8px_rgba(255,255,255,0.8)]"}),"AI Action Items"]}),e.jsxs("span",{className:"text-[10px] font-bold text-[#9333ea] bg-white px-2 py-0.5 rounded-[4px]",children:[N.length," Pending"]})]}),e.jsx("div",{className:"space-y-[8px] flex-1 overflow-y-auto no-scrollbar relative z-10",children:N.map((g,I)=>e.jsxs("div",{className:"bg-white/10 hover:bg-white/20 rounded-[8px] p-3 text-[12px] border border-white/10 transition-colors backdrop-blur-sm group cursor-pointer flex gap-3 items-start",children:[e.jsx("div",{className:"mt-0.5 shrink-0 text-white/80 group-hover:text-white transition-colors",children:e.jsx(g.icon,{className:"w-4 h-4"})}),e.jsx("div",{className:"leading-snug text-white/90",children:g.text})]},I))})]})]}),e.jsxs("div",{className:"bg-white/60 backdrop-blur-[12px] rounded-[24px] p-3 sm:p-[24px] shadow-[0_1px_4px_rgba(0,0,0,0.02)] border border-white mt-3 sm:mt-[24px]",children:[e.jsxs("div",{className:"mb-6 border-b border-[#f1f5f9] pb-4 flex items-center justify-between",children:[e.jsx("h2",{className:"text-[18px] font-semibold text-[#1e293b]",children:h?"Select a Class":"My Classes"}),l&&!h&&e.jsxs("button",{onClick:l,className:"flex items-center gap-1.5 px-3 py-1.5 text-[12px] font-semibold text-[#9956DE] bg-[#9956DE]/10 rounded-lg hover:bg-[#9956DE]/20 transition-colors",children:[e.jsx(da,{size:14}),"Create Class"]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-[16px]",children:[v.map((g,I)=>{const z=hr[I%hr.length];let R=null;return g.riskLevel==="high"?R=e.jsx("span",{className:"inline-flex px-2 py-1 bg-rose-50 text-rose-600 text-[10px] font-bold rounded-md border border-rose-100/50 uppercase",children:"High Risk"}):g.riskLevel==="medium"?R=e.jsx("span",{className:"inline-flex px-2 py-1 bg-amber-50 text-amber-600 text-[10px] font-bold rounded-md border border-amber-100/50 uppercase",children:"Medium Risk"}):R=e.jsx("span",{className:"inline-flex px-2 py-1 bg-emerald-50 text-emerald-600 text-[10px] font-bold rounded-md border border-emerald-100/50 uppercase",children:"On Track"}),e.jsxs("div",{onClick:()=>s(g),className:`flex flex-col p-[16px] bg-white shadow-[0_1px_4px_rgba(0,0,0,0.04)] hover:shadow-md hover:-translate-y-0.5 rounded-[18px] transition-all cursor-pointer group border border-[#f1f5f9] border-l-[6px] ${z.borderLeft}`,children:[e.jsxs("div",{className:"flex justify-between items-start mb-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`w-10 h-10 rounded-[12px] ${z.bg} flex items-center justify-center border ${z.border}`,children:e.jsx(Gt,{className:`w-5 h-5 ${z.text}`})}),e.jsxs("div",{children:[e.jsx("h4",{className:`font-bold text-[14px] text-[#1e293b] mb-0.5 transition-colors ${z.groupHover}`,children:g.name}),e.jsx("p",{className:"text-[11px] font-semibold text-[#64748b] uppercase tracking-wider",children:g.gradeLevel||"Senior High"})]})]}),R]}),e.jsxs("div",{className:"flex items-center justify-between text-[13px] text-[#475569] bg-[#f8fafc] rounded-[12px] p-3 border border-[#f1f5f9]",children:[e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-[10px] font-semibold text-[#64748b] uppercase tracking-wider mb-1",children:"Students"}),e.jsx("span",{className:"font-semibold text-[#1e293b]",children:g.studentCount})]}),e.jsx("div",{className:"w-[1px] h-8 bg-[#e2e8f0]"}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-[10px] font-semibold text-[#64748b] uppercase tracking-wider mb-1",children:h?"Avg Competency":"Average"}),e.jsxs("span",{className:"font-semibold text-[#1e293b]",children:[g.avgScore,"%"]})]}),!h&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-[1px] h-8 bg-[#e2e8f0]"}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-[10px] font-semibold text-[#64748b] uppercase tracking-wider mb-1",children:"Schedule"}),e.jsx("span",{className:"font-semibold text-[#1e293b]",children:g.schedule||"Mon-Fri"})]})]})]})]},g.id)}),v.length===0&&e.jsx("div",{className:"col-span-full py-8 text-center text-[#64748b] text-[13px] bg-[#f8fafc] rounded-[18px] border border-[#e2e8f0]",children:"No classes match your search."})]})]})]})})},wl="PH_SHS_OFFICIAL_CLASS_RECORD",Ym=.85,on=.85,Km="2026.04.24",Nl=4,sr=["INPUT DATA","SENIOR HIGH SCHOOL CLASS RECORD","LEARNERS NAMES","WRITTEN WORK","PERFORMANCE TASKS","QUARTERLY ASSESSMENT","REMARK","FINAL SEMESTRAL GRADES"],Xm=[...sr,"Pursuant to DepEd Order 8 series of 2015","INITIAL GRADE","QUARTERLY GRADE","ADDITIONAL REMARKS","MALE","FEMALE","SUBMITTED BY","CHECKED BY","VERIFIED BY","RECOMMENDED BY","APPROVED BY","WEIGHT OF COMPONENTS","LOOK UP","HELPER","ATTACHMENTS"],Jm=["SUBMITTED BY","CHECKED BY","VERIFIED BY","RECOMMENDED BY","APPROVED BY"],Fa=["WITH ATTACHMENTS","OFFICIALLY DROPPED","WITHDRAWN","UNOFFICIALLY DROPPED","TRANSFEREE","SHIFTER"],Zm=["TOTAL","SUBMITTED BY","CHECKED BY","VERIFIED BY","RECOMMENDED BY","APPROVED BY","WEIGHT OF COMPONENTS"],ex={SECOND:["SECOND QUARTER","2ND QUARTER","Q2"]},sa={inputData:["input data"],firstQuarter:["first quarter","1st quarter","q1"],secondQuarter:["second quarter","2nd quarter","q2"],finalSemestral:["final semestral","final grades","semestral"],helper:["helper","weight","attachments"],lookup:["look up","lookup","reference"]},Wt={region:["REGION"],division:["DIVISION"],schoolName:["SCHOOL NAME"],schoolId:["SCHOOL ID"],schoolYear:["SCHOOL YEAR"],gradeSection:["GRADE / SECTION","GRADE/SECTION"],semester:["SEMESTER"],track:["TRACK"],subjectCode:["SUBJECT CODE"],subjectName:["SUBJECT NAME","SUBJECT"],teacherName:["TEACHER","NAME OF TEACHER"]},Ue={learnerNo:["NO","NO.","#"],learnerName:["LEARNERS NAMES","LEARNER NAME","NAME"],writtenWork:["WRITTEN WORK","WW"],performanceTasks:["PERFORMANCE TASKS","PT"],quarterlyAssessment:["QUARTERLY ASSESSMENT","QA"],total:["TOTAL"],ps:["PS"],ws:["WS"],initialGrade:["INITIAL GRADE"],quarterlyGrade:["QUARTERLY GRADE"],firstQuarter:["FIRST QUARTER","1ST QUARTER"],secondQuarter:["SECOND QUARTER","2ND QUARTER"],firstSemester:["FIRST SEMESTER"],finalGrades:["FINAL GRADES","FINAL GRADE"],remark:["REMARK","REMARKS"],additionalRemarks:["ADDITIONAL REMARKS","ADDITIONAL REMARK"]};function tx(t){return t==null?null:typeof t=="string"||typeof t=="number"||typeof t=="boolean"?t:String(t)}function It(t){return String(t??"").replace(/[\u00a0\t\r\n]+/g," ").replace(/[|]+/g," ").replace(/\s+/g," ").trim().toUpperCase()}function qo(t){return It(t).replace(/[^A-Z0-9]+/g,"")}function _e(t,s){const a=It(t),r=It(s);if(!a||!r)return!1;if(a.includes(r))return!0;const o=qo(t),n=qo(s);return!o||!n?!1:o.includes(n)}function ar(t){if(typeof t=="number"&&Number.isFinite(t))return t;if(typeof t=="string"){const s=t.replace(/,/g,"").trim();if(!s)return;const a=Number(s);if(Number.isFinite(a))return a}}function Br(t){return It(t).toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"").slice(0,80)}function jl(t){const s={};return t.forEach(a=>{const r=Kt.encode_cell(a.s);for(let o=a.s.r;o<=a.e.r;o+=1)for(let n=a.s.c;n<=a.e.c;n+=1){const i=Kt.encode_cell({r:o,c:n});s[i]=r}}),s}function sx(t,s,a){const o=(a||jl(t.merges))[s]||s;return t.cells[o]||t.cells[s]}const yl="A1:A1",Yo=1200,Ko=200,Xo=2e5;function ax(t){const s=Math.max(0,t.s.r),a=Math.max(0,t.s.c);let r=Math.max(s,t.e.r),o=Math.max(a,t.e.c);r-s+1>Yo&&(r=s+Yo-1),o-a+1>Ko&&(o=a+Ko-1);const n=r-s+1,i=o-a+1;if(n*i>Xo){const c=Math.max(1,Math.floor(Xo/i));r=s+Math.min(n,c)-1}return{s:{r:s,c:a},e:{r,c:o}}}function rx(t){try{return Kt.decode_range(t)}catch{return Kt.decode_range(yl)}}function nx(t){let s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY,o=Number.NEGATIVE_INFINITY;return Object.keys(t.cells).forEach(n=>{try{const i=Kt.decode_cell(n);s=Math.min(s,i.r),a=Math.min(a,i.c),r=Math.max(r,i.r),o=Math.max(o,i.c)}catch{}}),t.merges.forEach(n=>{s=Math.min(s,n.s.r,n.e.r),a=Math.min(a,n.s.c,n.e.c),r=Math.max(r,n.s.r,n.e.r),o=Math.max(o,n.s.c,n.e.c)}),!Number.isFinite(s)||!Number.isFinite(a)||!Number.isFinite(r)||!Number.isFinite(o)?null:{s:{r:Math.max(0,Math.trunc(s)),c:Math.max(0,Math.trunc(a))},e:{r:Math.max(0,Math.trunc(r)),c:Math.max(0,Math.trunc(o))}}}function ox(t){const s=rx(t.ref||yl),a=nx(t);return ax(a||s)}function ix(t,s){const a=ox(s),r=`${Kt.encode_cell(a.s)}:${Kt.encode_cell(a.e)}`,o=jl(s.merges),n=a.e.r-a.s.r+1,i=a.e.c-a.s.c+1,l=[];for(let c=0;ct.endRow||at.endCol?null:t.cells[s-t.startRow]?.[a-t.startCol]??null}function Ps(t,s){return st.endRow?"":(t.cells[s-t.startRow]||[]).map(r=>r?.normalizedText||"").filter(Boolean).join(" ").trim()}function Na(t){return Kt.encode_col(t)}function Ya(t){const s=String(t||"").trim().toUpperCase();if(!s||!/^[A-Z]+$/.test(s))return-1;try{return Kt.decode_col(s)}catch{return-1}}function lx(t){return`${Kt.encode_cell(t.s)}:${Kt.encode_cell(t.e)}`}function cx(t,s){const a=[];for(let r=s.s.r;r<=s.e.r;r+=1){const o=[];for(let n=s.s.c;n<=s.e.c;n+=1){const i=Ve(t,r,n);o.push(i?.displayValue??null)}a.push(o)}return a}function dx(t,s){const a=It(t),r=It(s);return!a||!r?0:a===r?1:a.includes(r)?.9:.75}function yn(t,s){const a=[];for(let r=0;r{_e(l.normalizedText,c)&&a.push({sheetName:t.sheetName,anchor:c,row:l.row,col:l.col,address:l.address,value:String(l.displayValue??""),confidence:dx(l.displayValue,c)})})}const o=t.startRow+r,n=Ps(t,o);n&&s.forEach(i=>{if(!_e(n,i))return;const l=t.cells[r].find(c=>c?.normalizedText);l&&a.push({sheetName:t.sheetName,anchor:i,row:o,col:l.col,address:l.address,value:n,confidence:.8})})}return a}function ux(t,s){return Object.values(t).flatMap(a=>yn(a,s))}function Tt(t,s){return yn(t,[s]).sort((a,r)=>a.row-r.row||a.col-r.col)}function Sl(t,s,a,r=6){for(let o=1;o<=r;o+=1){const i=Ve(t,s,a+o)?.displayValue;if(i!=null&&String(i).trim())return String(i).trim()}for(let o=1;o<=r;o+=1){const i=Ve(t,s+o,a)?.displayValue;if(i!=null&&String(i).trim())return String(i).trim()}}function kl(t,s,a=5){let r=s,o=-1;for(let n=Math.max(t.startRow,s-a);n<=Math.min(t.endRow,s+a);n+=1){const i=Ps(t,n),l=["LEARNERS NAMES","WRITTEN WORK","PERFORMANCE TASKS","QUARTERLY ASSESSMENT","REMARK"].reduce((c,d)=>i.includes(d)?c+1:c,0);l>o&&(o=l,r=n)}return r}function mx(t,s){const a=It(t).toLowerCase(),r=o=>[...s].some(n=>_e(n,o));return sa.inputData.some(o=>a.includes(o))||r("INPUT DATA")?"inputData":sa.finalSemestral.some(o=>a.includes(o))||r("FINAL SEMESTRAL GRADES")||r("FINAL GRADES")?"finalSemestral":sa.firstQuarter.some(o=>a.includes(o))||r("FIRST QUARTER")?"firstQuarter":sa.secondQuarter.some(o=>a.includes(o))||r("SECOND QUARTER")?"secondQuarter":r("SENIOR HIGH SCHOOL CLASS RECORD")||r("WRITTEN WORK")&&r("PERFORMANCE TASKS")?"firstQuarter":sa.helper.some(o=>a.includes(o))||r("WEIGHT OF COMPONENTS")||r("ATTACHMENTS")||r("HELPER")?"helper":sa.lookup.some(o=>a.includes(o))||r("LOOK UP")?"lookup":"other"}function xx(t){const s=t.criticalTotal>0?t.criticalFound/t.criticalTotal:0,a=t.totalSheets>0?t.recognizedSheets/t.totalSheets:0,r=t.hasDepedAnchor?1:0,o=.65*s+.2*a+.15*r;return Number(Math.max(0,Math.min(1,o)).toFixed(4))}function px(t){const s=ux(t.matrices,Xm),a=new Set,r=[];sr.forEach(b=>{s.some(k=>_e(k.anchor,b))&&(a.add(b),r.push(`Found critical anchor: ${b}`))});const o=sr.filter(b=>!a.has(b)),n=new Map;s.forEach(b=>{n.has(b.sheetName)||n.set(b.sheetName,new Set),n.get(b.sheetName)?.add(b.anchor)});const i=t.sheetNames.map(b=>{const S=n.get(b)||new Set,k=mx(b,S),N=Math.min(1,.35+Math.min(.55,S.size*.08)),v=[`sheet:${b}`,`signals:${S.size}`,...[...S].slice(0,5)];return{sheetName:b,role:k,confidence:Number(N.toFixed(3)),evidence:v}}),l={firstQuarter:[],secondQuarter:[],finalSemestral:[],helper:[],lookup:[],other:[]};i.forEach(b=>{switch(b.role){case"inputData":l.inputData?l.other.push(b.sheetName):l.inputData=b.sheetName;break;case"firstQuarter":l.firstQuarter.push(b.sheetName);break;case"secondQuarter":l.secondQuarter.push(b.sheetName);break;case"finalSemestral":l.finalSemestral.push(b.sheetName);break;case"helper":l.helper.push(b.sheetName);break;case"lookup":l.lookup.push(b.sheetName);break;case"other":default:l.other.push(b.sheetName);break}});const c=(l.inputData?1:0)+l.firstQuarter.length+l.secondQuarter.length+l.finalSemestral.length+l.helper.length+l.lookup.length,d=xx({criticalFound:a.size,criticalTotal:sr.length,recognizedSheets:c,totalSheets:t.sheetNames.length,hasDepedAnchor:s.some(b=>_e(b.anchor,"Pursuant to DepEd Order 8 series of 2015"))}),m=l.firstQuarter.length>0||l.secondQuarter.length>0,p=!!l.inputData&&m&&l.finalSemestral.length>0,h=d>=.55&&p;return l.inputData||r.push("Input Data sheet not confidently detected."),m||r.push("No quarter class record sheet detected."),l.finalSemestral.length===0&&r.push("No Final Semestral Grades sheet detected."),{format:wl,isOfficialFormatLikely:h,confidence:d,evidence:r,missingCriticalAnchors:o,detectedSheets:l,anchorMatches:s}}function fr(t){if(typeof t=="number"&&Number.isFinite(t))return t;const s=String(t??"").trim();if(!s)return;const a=Number(s.replace(/[^0-9]/g,""));if(!(!Number.isFinite(a)||a<=0))return a}function Sn(t){const s=It(t);if(s.includes("FEMALE"))return"FEMALE";if(s.includes("MALE"))return"MALE"}function kn(t){const s=It(t.rowText);return s?s==="MALE"||s==="FEMALE"?"sex-header":Jm.some(a=>s.includes(a))?"signature":Zm.some(a=>s.includes(a))?"helper":s.includes("LEARNERS NAMES")||s.includes("WRITTEN WORK")||s.includes("PERFORMANCE TASKS")||s.includes("QUARTERLY ASSESSMENT")||s.includes("INITIAL GRADE")||s.includes("QUARTERLY GRADE")?"header":t.hasLearnerName||t.hasLearnerNumber?"learner":s.includes("ATTACHMENTS")||s.includes("LOOK UP")?"helper":"unknown":"blank"}function hx(t){const s=["SUBMITTED BY","CHECKED BY","VERIFIED BY","RECOMMENDED BY","APPROVED BY"],a=[];return s.forEach(r=>{Tt(t,r).forEach(o=>{a.push({role:r,name:String(Ve(t,o.row,o.col+1)?.displayValue||"").trim()||void 0,sourceSheet:t.sheetName,sourceRow:o.row+1})})}),a}function fx(t){const s=[],a=Tt(t,"LEARNERS NAMES")[0],r=a?kl(t,a.row,5):t.startRow,o=(N,v)=>Tt(t,N).find(I=>Math.abs(I.row-r)<=2)?.col??v,n=o(Ue.learnerNo[0],t.startCol),i=o(Ue.learnerName[0],t.startCol+1),l=o(Ue.firstQuarter[0],i+1),c=o(Ue.secondQuarter[0],l+1),d=o(Ue.firstSemester[0],c+1),m=o(Ue.finalGrades[0],d+1),p=o(Ue.remark[0],m+1),h=o(Ue.additionalRemarks[0],p+1),b=[];let S="UNKNOWN",k=0;for(let N=r+1;N<=t.endRow;N+=1){const v=Ps(t,N),g=kn({rowText:v,hasLearnerNumber:/\b\d{1,2}\b/.test(v),hasLearnerName:/[A-Z]{2,}/.test(v)});if(g==="sex-header"){S=Sn(v)||S;continue}if(g==="signature"||g==="helper")break;if(g==="blank"){if(k+=1,k>=Nl)break;continue}if(g!=="learner")continue;k=0;const I=fr(Ve(t,N,n)?.displayValue),z=String(Ve(t,N,i)?.displayValue||"").trim();if(!z&&I===void 0)continue;const R=Ve(t,N,l)?.displayValue??null,W=Ve(t,N,c)?.displayValue??null,f=Ve(t,N,d)?.displayValue??null,C=Ve(t,N,m)?.displayValue??null,w=Ve(t,N,p)?.displayValue??null;let $=Ve(t,N,h)?.displayValue??null;const A=Fa.filter(y=>_e(v,y));A.length>0&&($=[$,A.join("; ")].filter(Boolean).join("; ")||null),!z&&I!==void 0&&s.push(`Row ${N+1} has learner number ${I} but empty learner name.`),b.push({learnerNo:I,fullName:z||`Unnamed Learner ${I||N+1}`,sex:S,firstQuarter:R,secondQuarter:W,firstSemester:f,finalGrades:C,remark:w,additionalRemarks:$,sourceRow:N+1})}return{sheetName:t.sheetName,learnerGrades:b,signatures:hx(t),warnings:s}}function Zt(t,s){for(const a of s){const r=Tt(t,a);for(const o of r){const n=Sl(t,o.row,o.col,8);if(n&&n.trim())return n.trim()}}}function gx(t){const s=["SUBMITTED BY","CHECKED BY","VERIFIED BY","RECOMMENDED BY","APPROVED BY"],a=[];return s.forEach(r=>{Tt(t,r).forEach(n=>{const i=Sl(t,n.row,n.col,10);a.push({role:r,name:i,sourceSheet:t.sheetName,sourceRow:n.row+1})})}),a}function bx(t){const s=Tt(t,"LEARNERS NAMES")[0];if(!s)return[];const a=s.row+1,r=s.col,o=Math.max(t.startCol,r-1),n=Math.min(t.endCol,r+1),i=Math.min(t.endCol,r+2),l=[];let c="UNKNOWN",d=0;for(let m=a;m<=t.endRow;m+=1){const p=Ps(t,m),h=kn({rowText:p,hasLearnerNumber:!!fr(Ve(t,m,o)?.displayValue),hasLearnerName:!!String(Ve(t,m,r)?.displayValue||"").trim()});if(h==="sex-header"){c=Sn(p)||c,d=0;continue}if(h==="signature"||h==="helper")break;if(h!=="learner"){if(h==="blank"&&(d+=1),d>=5)break;continue}d=0;const b=fr(Ve(t,m,o)?.displayValue),S=String(Ve(t,m,r)?.displayValue||"").trim(),k=String(Ve(t,m,n)?.displayValue||"").trim()||void 0,N=String(Ve(t,m,i)?.displayValue||"").trim()||void 0,v=Fa.filter(g=>_e(p,g));!S&&b===void 0||l.push({learnerNo:b,sex:c,fullName:S||`Unnamed Learner ${b||m}`,sourceSheet:t.sheetName,sourceRow:m+1,remarks:k,additionalRemarks:N,statuses:v.length>0?v:void 0})}return l}function vx(t){const s=[],a=[];for(let r=t.startRow;r<=t.endRow;r+=1){const o=Ps(t,r);if(o){if(Fa.some(n=>_e(o,n))){s.push(o);continue}(_e(o,"IMPORTANT")||_e(o,"NOTE")||_e(o,"ATTACHMENT")||_e(o,"LOOK UP"))&&a.push(o)}}return{attachmentRules:Array.from(new Set(s)),helperNotes:Array.from(new Set(a))}}function wx(t){const s=[],a={region:Zt(t,Wt.region),division:Zt(t,Wt.division),schoolName:Zt(t,Wt.schoolName),schoolId:Zt(t,Wt.schoolId),schoolYear:Zt(t,Wt.schoolYear),gradeSection:Zt(t,Wt.gradeSection),semester:Zt(t,Wt.semester),track:Zt(t,Wt.track),subjectCode:Zt(t,Wt.subjectCode),subjectName:Zt(t,Wt.subjectName),teacherName:Zt(t,Wt.teacherName)},r=bx(t),o=gx(t),{attachmentRules:n,helperNotes:i}=vx(t);return a.schoolName||s.push("Input Data metadata is missing School Name."),a.schoolYear||s.push("Input Data metadata is missing School Year."),r.length===0&&s.push("No learners detected in Input Data sheet."),yn(t,Object.values(Wt).flat()).length<4&&s.push("Input Data sheet contains limited metadata anchors; layout may have drifted."),{sheetName:t.sheetName,schoolContext:a,learners:r,signatures:o,attachmentRules:n,helperNotes:i,warnings:s}}function Nx(t){const s=It(t.sheetName);return ex.SECOND.some(a=>_e(s,a))?"SECOND":"FIRST"}function jx(t,s){const a=[],r=[],o=[];let n,i="NONE";for(let l=t.startCol;l<=t.endCol;l+=1){const c=Ve(t,s,l),d=It(c?.displayValue||""),m=Ve(t,s+1,l),p=String(m?.displayValue||c?.displayValue||"").trim();if(!d&&!p)continue;if(_e(d,Ue.writtenWork[0])){i="WW";continue}if(_e(d,Ue.performanceTasks[0])){i="PT";continue}if(_e(d,Ue.quarterlyAssessment[0])){n={key:Br(p||"quarterly_assessment"),label:p||"Quarterly Assessment",column:Na(l)},i="DERIVED";continue}if(_e(d,Ue.initialGrade[0])||_e(d,Ue.quarterlyGrade[0])||_e(d,Ue.remark[0])||_e(d,Ue.additionalRemarks[0])||_e(d,Ue.firstQuarter[0])||_e(d,Ue.secondQuarter[0])||_e(d,Ue.firstSemester[0])||_e(d,Ue.finalGrades[0])||_e(d,Ue.ps[0])||_e(d,Ue.ws[0])||_e(d,Ue.total[0])){i="DERIVED",o.push({key:Br(p||d),label:p||d,column:Na(l)});continue}const h={key:Br(p||d||Na(l)),label:p||d||Na(l),maxScore:ar(m?.displayValue),column:Na(l)};i==="WW"?a.push(h):i==="PT"?r.push(h):i==="DERIVED"&&o.push(h)}return{writtenWorks:a,performanceTasks:r,quarterlyAssessment:n,derived:o}}function yx(t){const s=["SUBMITTED BY","CHECKED BY","VERIFIED BY","RECOMMENDED BY","APPROVED BY"],a=[];return s.forEach(r=>{Tt(t,r).forEach(o=>{const n=Ve(t,o.row,o.col+1),i=String(n?.displayValue||"").trim()||void 0;a.push({role:r,name:i,sourceSheet:t.sheetName,sourceRow:o.row+1})})}),a}function Jo(t,s,a){for(let r=t.startCol;r<=t.endCol;r+=1){const o=It(Ve(t,s,r)?.displayValue||""),n=It(Ve(t,s+1,r)?.displayValue||"");if(a.some(i=>_e(o,i)||_e(n,i)))return r}}function Sx(t,s,a,r){const o={learnerNo:fr(Ve(t,s,r.numberCol)?.displayValue),fullName:String(Ve(t,s,r.nameCol)?.displayValue||"").trim(),sourceRow:s+1},n={};a.writtenWorks.forEach(d=>{const m=d.column?Ya(d.column):-1;if(m<0)return;const p=Ve(t,s,m)?.displayValue;n[d.key]=p??null}),Object.keys(n).length>0&&(o.writtenWorks=n);const i={};if(a.performanceTasks.forEach(d=>{const m=d.column?Ya(d.column):-1;if(m<0)return;const p=Ve(t,s,m)?.displayValue;i[d.key]=p??null}),Object.keys(i).length>0&&(o.performanceTasks=i),a.quarterlyAssessment?.column){const d=Ya(a.quarterlyAssessment.column);o.quarterlyAssessment=Ve(t,s,d)?.displayValue??null}const l=a.derived||[],c={};return l.forEach(d=>{if(!d.column)return;const m=Ya(d.column);if(m<0)return;const p=Ve(t,s,m)?.displayValue??null;c[d.key]=p,_e(d.label,Ue.initialGrade[0])&&(o.initialGrade=p),_e(d.label,Ue.quarterlyGrade[0])&&(o.quarterlyGrade=p),_e(d.label,Ue.firstQuarter[0])&&(o.firstQuarter=p),_e(d.label,Ue.secondQuarter[0])&&(o.secondQuarter=p),_e(d.label,Ue.firstSemester[0])&&(o.firstSemester=p),_e(d.label,Ue.finalGrades[0])&&(o.finalGrades=p),_e(d.label,Ue.remark[0])&&(o.remark=p!==null?String(p):null),_e(d.label,Ue.additionalRemarks[0])&&(o.additionalRemarks=p!==null?String(p):null)}),Object.keys(c).length>0&&(o.totals=c),o}function kx(t){const s=Nx(t),a=[],r=Tt(t,Ue.learnerName[0])[0]||Tt(t,Ue.learnerName[1])[0],o=r?kl(t,r.row,4):t.startRow,n=jx(t,o),i=Jo(t,o,Ue.learnerNo)??t.startCol,l=Jo(t,o,Ue.learnerName)??Math.min(t.endCol,i+1),c=[];let d="UNKNOWN",m=0;for(let S=o+1;S<=t.endRow;S+=1){const k=Ps(t,S),N=kn({rowText:k,hasLearnerNumber:/\b\d{1,2}\b/.test(k),hasLearnerName:/[A-Z]{2,}/.test(k)});if(N==="sex-header"){d=Sn(k)||d;continue}if(N==="signature"||N==="helper")break;if(N==="blank"){if(m+=1,m>=Nl)break;continue}if(N!=="learner")continue;m=0;const v=Sx(t,S,n,{numberCol:i,nameCol:l});if(v.sex=d,!v.fullName&&v.learnerNo===void 0)continue;const g=Fa.filter(I=>_e(k,I));g.length>0&&!v.additionalRemarks&&(v.additionalRemarks=g.join("; ")),!v.fullName&&v.learnerNo!==void 0&&(a.push(`Row ${S+1} has learner number ${v.learnerNo} but empty name.`),v.fullName=`Unnamed Learner ${v.learnerNo}`),c.push(v)}n.writtenWorks.length===0&&n.performanceTasks.length===0&&a.push(`No detailed assessment columns detected in ${t.sheetName}.`);const p=ar(Tt(t,"WRITTEN WORK %")[0]?.value||Tt(t,"WRITTEN WORK")[0]?.value),h=ar(Tt(t,"PERFORMANCE TASKS %")[0]?.value||Tt(t,"PERFORMANCE TASKS")[0]?.value),b=ar(Tt(t,"QUARTERLY ASSESSMENT %")[0]?.value||Tt(t,"QUARTERLY ASSESSMENT")[0]?.value);return{sheetName:t.sheetName,quarter:s,gradingWeights:{writtenWork:p,performanceTasks:h,quarterlyAssessment:b},assessmentColumns:n,learnerGrades:c,signatures:yx(t),warnings:a}}function Cx(t){const s=["SUBMITTED BY","CHECKED BY","VERIFIED BY","RECOMMENDED BY","APPROVED BY"],a=[];return s.forEach(r=>{Tt(t,r).forEach(o=>{a.push({role:r,name:String(Ve(t,o.row,o.col+1)?.displayValue||"").trim()||void 0,sourceSheet:t.sheetName,sourceRow:o.row+1})})}),a}function Ix(t){const s=[];let a=!1;for(let r=t.startRow;r<=t.endRow;r+=1){const o=Ps(t,r);if(!o){if(a&&s.length>0)break;continue}if(_e(o,"WEIGHT OF COMPONENTS")){a=!0;continue}if(!a)continue;const n={sourceRow:r+1,raw:o};for(let i=t.startCol;i<=t.endCol;i+=1){const l=Ve(t,r,i)?.displayValue;l==null||String(l).trim()===""||(n[`c${i}`]=l)}Object.keys(n).length>2&&s.push(n)}return s}function Tx(t){const s=[],a=[],r=[],o=[],n=[];return t.forEach(i=>{Cx(i).forEach(l=>a.push(l)),Ix(i).forEach(l=>r.push({...l,sourceSheet:i.sheetName}));for(let l=i.startRow;l<=i.endRow;l+=1){const c=Ps(i,l);if(c){if(Fa.some(d=>_e(c,d))){o.push(`${i.sheetName}: ${c}`);continue}(_e(c,"HELPER")||_e(c,"LOOK UP")||_e(c,"IMPORTANT")||_e(c,"REFERENCE")||_e(c,"ATTACHMENT"))&&n.push(`${i.sheetName}: ${c}`)}}}),r.length===0&&s.push("No component weight rows were parsed from reference sheets."),{sheetName:t.map(i=>i.sheetName).join(", "),componentWeights:r,attachmentRules:Array.from(new Set(o)),helperNotes:Array.from(new Set(n)),signatures:a,warnings:s}}function _x(t,s,a){const r=new Map,o=n=>{const i=`${It(n.fullName)}|${n.learnerNo||""}|${n.sourceSheet}`,l=r.get(i);if(!l){r.set(i,n);return}const c=Array.from(new Set([...l.statuses||[],...n.statuses||[]]));r.set(i,{...l,...n,remarks:n.remarks||l.remarks,additionalRemarks:n.additionalRemarks||l.additionalRemarks,statuses:c.length>0?c:void 0})};return t.forEach(o),s.forEach(n=>{n.learnerGrades.forEach(i=>{o({learnerNo:i.learnerNo,sex:i.sex,fullName:i.fullName,sourceSheet:n.sheetName,sourceRow:i.sourceRow,remarks:i.remark||void 0,additionalRemarks:i.additionalRemarks||void 0})})}),a.forEach(n=>{n.learnerGrades.forEach(i=>{o({learnerNo:i.learnerNo,sex:i.sex,fullName:i.fullName,sourceSheet:n.sheetName,sourceRow:i.sourceRow,remarks:i.remark||void 0,additionalRemarks:i.additionalRemarks||void 0})})}),Array.from(r.values())}function Ex(t,s,a,r){const o=[...t.signatures,...s.flatMap(i=>i.signatures),...a.flatMap(i=>i.signatures),...r.signatures],n=new Map;return o.forEach(i=>{const l=`${It(i.role)}|${It(i.name||"")}|${i.sourceSheet}`;n.set(l,i)}),Array.from(n.values())}function Rx(t){const s=_x(t.inputData.learners,t.quarterSheets,t.finalSheets);return{format:wl,version:Km,workbookMeta:{fileName:t.workbook.fileName,sheetNames:t.workbook.sheetNames,detectedSheets:{inputData:t.detection.detectedSheets.inputData,firstQuarter:t.detection.detectedSheets.firstQuarter,secondQuarter:t.detection.detectedSheets.secondQuarter,finalSemestral:t.detection.detectedSheets.finalSemestral,helper:t.detection.detectedSheets.helper,lookup:t.detection.detectedSheets.lookup,other:t.detection.detectedSheets.other}},schoolContext:{...t.inputData.schoolContext},learners:s,quarterlyRecords:t.quarterSheets.map(a=>({sheetName:a.sheetName,quarter:a.quarter,gradingWeights:a.gradingWeights,assessmentColumns:a.assessmentColumns,learnerGrades:a.learnerGrades})),finalSemestralRecords:t.finalSheets.map(a=>({sheetName:a.sheetName,learnerGrades:a.learnerGrades})),references:{componentWeights:t.references.componentWeights,attachmentRules:Array.from(new Set([...t.inputData.attachmentRules||[],...t.references.attachmentRules||[]])),helperNotes:Array.from(new Set([...t.inputData.helperNotes||[],...t.references.helperNotes||[]])),signatures:Ex(t.inputData,t.quarterSheets,t.finalSheets,t.references),unclassifiedBlocks:t.unclassifiedBlocks},validation:t.validation,raw:t.workbook.raw}}function Mx(t){return!t||t.length===0?[]:t.map(s=>({s:{r:s.s.r,c:s.s.c},e:{r:s.e.r,c:s.e.c}}))}function Ax(t){const s={ref:t["!ref"],merges:Mx(t["!merges"]),cells:{}};return Object.keys(t).filter(a=>!a.startsWith("!")).forEach(a=>{const r=t[a];!r||!(r.v!==void 0||typeof r.w=="string"&&r.w.trim().length>0||typeof r.f=="string"&&r.f.trim().length>0)||(s.cells[a]={v:r.v,w:r.w,t:r.t,f:r.f})}),s}function Lx(t,s){const a=Ac(s,{type:"array",cellFormula:!0,cellNF:!0,cellText:!0,cellDates:!0,raw:!1}),r={},o={};return a.SheetNames.forEach(n=>{const i=a.Sheets[n];if(!i)return;const l=Ax(i);o[n]=l,r[n]=ix(n,l)}),{fileName:t,sheetNames:a.SheetNames,raw:{sheets:o},matrices:r}}async function zx(t){const s=await t.arrayBuffer();return Lx(t.name,s)}class Dx{state={};markRange(s,a,r){const o=s;this.state[o]||(this.state[o]={mappedAddresses:new Set,mappings:[]});for(let n=a.s.r;n<=a.e.r;n+=1)for(let i=a.s.c;i<=a.e.c;i+=1)this.state[o].mappedAddresses.add(`${n}:${i}`);this.state[o].mappings.push({sheetName:s,range:a,reason:r})}getMappings(){return Object.values(this.state).flatMap(s=>s.mappings)}getMappedRegionCount(){return this.getMappings().length}getUnmappedBlocks(s,a="unclassified"){const r=[];return Object.values(s).forEach(o=>{const n=new Set,i=this.state[o.sheetName]?.mappedAddresses??new Set;for(let l=o.startRow;l<=o.endRow;l+=1)for(let c=o.startCol;c<=o.endCol;c+=1){const d=`${l}:${c}`;if(n.has(d)||i.has(d))continue;const m=Ve(o,l,c);if(!(m&&m.displayValue!==null&&m.displayValue!==void 0&&String(m.displayValue).trim())){n.add(d);continue}const h=this.collectComponent(o,l,c,i,n);h&&r.push({sheetName:o.sheetName,range:lx(h),purposeGuess:a,raw2D:cx(o,h)})}}),r}collectComponent(s,a,r,o,n){const i=[{row:a,col:r}];let l=a,c=a,d=r,m=r,p=!1;for(;i.length>0;){const h=i.shift();if(!h)break;const b=`${h.row}:${h.col}`;if(n.has(b)||o.has(b))continue;n.add(b);const S=Ve(s,h.row,h.col);S&&S.displayValue!==null&&S.displayValue!==void 0&&String(S.displayValue).trim()&&(p=!0,l=Math.min(l,h.row),c=Math.max(c,h.row),d=Math.min(d,h.col),m=Math.max(m,h.col),[{row:h.row-1,col:h.col},{row:h.row+1,col:h.col},{row:h.row,col:h.col-1},{row:h.row,col:h.col+1}].forEach(N=>{N.rows.endRow||N.cols.endCol||i.push(N)}))}return p?{s:{r:l,c:d},e:{r:c,c:m}}:null}}function $x(t){const s=t.detection.detectedSheets,a=[s.inputData?1:0,s.firstQuarter.length,s.secondQuarter.length,s.finalSemestral.length,s.helper.length,s.lookup.length].reduce((r,o)=>r+o,0);return{totalSheets:t.totalSheets,recognizedSheets:a,unclassifiedSheets:s.other.length,mappedCellRegions:t.mappedCellRegions,unmappedCellRegions:t.unmappedCellRegions}}function Fx(t){const s=new Map;t.forEach(r=>{const o=`${r.learnerNo||""}|${r.fullName.trim().toUpperCase()}`;s.has(o)||s.set(o,[]),s.get(o)?.push(r.sourceRow)});const a=[];return s.forEach((r,o)=>{r.length>1&&a.push(`Duplicate learner entry detected for ${o} at rows ${r.join(", ")}.`)}),a}function Ox(t){const s=[];return t.forEach(a=>{a.learnerGrades.forEach(r=>{r.fullName.trim()||s.push(`${a.sheetName} row ${r.sourceRow}: learner name is blank.`);const o=r.writtenWorks&&Object.values(r.writtenWorks).some(i=>i!==null&&i!==""),n=r.performanceTasks&&Object.values(r.performanceTasks).some(i=>i!==null&&i!=="");!o&&!n&&r.quarterlyAssessment==null&&s.push(`${a.sheetName} row ${r.sourceRow}: all grade blocks are empty.`)})}),s}function Px(t){const s=[];return t.forEach(a=>{a.learnerGrades.forEach(r=>{r.fullName.trim()||s.push(`${a.sheetName} row ${r.sourceRow}: learner name is blank.`),r.finalGrades==null&&r.firstSemester==null&&r.firstQuarter==null&&r.secondQuarter==null&&s.push(`${a.sheetName} row ${r.sourceRow}: no semestral/final values detected.`)})}),s}function Bx(t){const s=[],a=[];t.detection.detectedSheets.inputData||a.push("Missing Input Data sheet."),t.quarterSheets.length===0&&a.push("No quarter class record sheets were extracted."),t.finalSheets.length===0&&a.push("No Final Semestral sheet was extracted."),t.detection.missingCriticalAnchors.length>0&&s.push(`Missing critical anchors: ${t.detection.missingCriticalAnchors.join(", ")}.`),Fx(t.inputData.learners).forEach(n=>s.push(n)),Ox(t.quarterSheets).forEach(n=>s.push(n)),Px(t.finalSheets).forEach(n=>s.push(n)),s.push(...t.inputData.warnings),t.quarterSheets.forEach(n=>s.push(...n.warnings)),t.finalSheets.forEach(n=>s.push(...n.warnings)),t.unmappedCellRegions>t.mappedCellRegions&&s.push("A significant portion of workbook regions are unclassified; review diagnostics before confirming import.");const r=t.detection.confidence,o=t.detection.isOfficialFormatLikely&&a.length===0;return r({fullName:i.fullName,learnerNo:i.learnerNo,sex:i.sex,remarks:i.remarks,additionalRemarks:i.additionalRemarks,statuses:i.statuses,sourceSheet:i.sourceSheet,sourceRow:i.sourceRow})),r=t.quarterlyRecords.flatMap(i=>i.learnerGrades.map(l=>({fullName:l.fullName,sourceSheet:i.sheetName,sourceRow:l.sourceRow,quarter:i.quarter,firstQuarter:l.firstQuarter,secondQuarter:l.secondQuarter,firstSemester:l.firstSemester,finalGrades:l.finalGrades,quarterlyGrade:l.quarterlyGrade,initialGrade:l.initialGrade,remark:l.remark,additionalRemarks:l.additionalRemarks}))),o=t.finalSemestralRecords.flatMap(i=>i.learnerGrades.map(l=>({fullName:l.fullName,sourceSheet:i.sheetName,sourceRow:l.sourceRow,firstQuarter:l.firstQuarter,secondQuarter:l.secondQuarter,firstSemester:l.firstSemester,finalGrades:l.finalGrades,remark:l.remark,additionalRemarks:l.additionalRemarks}))),n=[...t.learners,...t.quarterlyRecords.flatMap(i=>i.learnerGrades.map(l=>({learnerNo:l.learnerNo,sex:l.sex,fullName:l.fullName,sourceSheet:i.sheetName,sourceRow:l.sourceRow,remarks:l.remark||void 0,additionalRemarks:l.additionalRemarks||void 0})))].map(i=>({fullName:i.fullName,remark:i.remarks||null,additionalRemarks:i.additionalRemarks||null,statuses:"statuses"in i?i.statuses:void 0,sourceSheet:i.sourceSheet,sourceRow:i.sourceRow}));return{classEntity:s,studentEntities:a,gradeEntities:[...r,...o],remarksEntities:n}}const Zo=1500;function ei(t){return t?Object.values(t.matrices).reduce((s,a)=>s+a.rowCount*a.colCount,0):0}function ti(t){const s=`[shs-import] parse ${t.stage} file=${t.fileName} duration=${t.durationMs}ms sheets=${t.sheetCount} matrixCells=${t.matrixCellCount}`;if(t.stage==="failed"){console.error(`${s}${t.errorMessage?` error=${t.errorMessage}`:""}`);return}if(t.durationMs>=Zo){console.warn(`${s} slow=true threshold=${Zo}ms`);return}}function Qs(t,s){t?.onProgress?.(s)}function Ux(t,s){return Array.from(new Set(t.filter(a=>Number.isFinite(a)).map(a=>Math.max(s.startRow,Math.min(s.endRow,Math.trunc(a))))))}function ja(t,s,a,r){Ux(a,s).forEach(o=>{t.markRange(s.sheetName,{s:{r:o,c:s.startCol},e:{r:o,c:s.endCol}},r)})}async function Gx(t,s){const a=s?.confidenceThreshold??Ym,r=Date.now();let o=null;try{if(Qs(s,{stage:"reading",message:"Reading workbook structure and raw sheets..."}),o=await zx(t),!o)throw new Error("Workbook read returned null");Qs(s,{stage:"detecting-format",message:"Detecting DepEd SHS workbook format..."});const n=px(o);Qs(s,{stage:"extracting",message:"Extracting metadata, learners, grades, and references..."});const i=n.detectedSheets.inputData||o.sheetNames[0],l=o.matrices[i],c=l?wx(l):{sheetName:i,schoolContext:{},learners:[],signatures:[],attachmentRules:[],helperNotes:[],warnings:["Input data sheet was not available in matrix map."]},m=[...n.detectedSheets.firstQuarter||[],...n.detectedSheets.secondQuarter||[]].map(I=>o.matrices[I]).filter(I=>!!I).map(I=>kx(I)),p=(n.detectedSheets.finalSemestral||[]).map(I=>o.matrices[I]).filter(I=>!!I).map(I=>fx(I)),h=[...n.detectedSheets.helper||[],...n.detectedSheets.lookup||[]].map(I=>o.matrices[I]).filter(I=>!!I),b=Tx(h),S=new Dx;n.anchorMatches.forEach(I=>{const z=o.matrices[I.sheetName];z&&ja(S,z,[I.row],`Anchor match: ${I.anchor}`)}),[c.sheetName].forEach(I=>{const z=o.matrices[I];if(!z)return;const R=Array.from({length:Math.min(14,z.rowCount)},(C,w)=>z.startRow+w),W=c.learners.map(C=>C.sourceRow-1),f=c.signatures.map(C=>C.sourceRow).filter(C=>typeof C=="number").map(C=>C-1);ja(S,z,[...R,...W,...f],"Input Data parsed rows")}),m.forEach(I=>{const z=o.matrices[I.sheetName];if(!z)return;const R=I.learnerGrades.map(C=>C.sourceRow-1),W=I.signatures.map(C=>C.sourceRow).filter(C=>typeof C=="number").map(C=>C-1),f=R.length>0?Math.max(z.startRow,Math.min(...R)-2):z.startRow;ja(S,z,[f,f+1,...R,...W],"Quarter sheet parsed rows")}),p.forEach(I=>{const z=o.matrices[I.sheetName];if(!z)return;const R=I.learnerGrades.map(C=>C.sourceRow-1),W=I.signatures.map(C=>C.sourceRow).filter(C=>typeof C=="number").map(C=>C-1),f=R.length>0?Math.max(z.startRow,Math.min(...R)-2):z.startRow;ja(S,z,[f,f+1,...R,...W],"Final semestral parsed rows")}),h.forEach(I=>{const z=b.componentWeights.filter(f=>f.sourceSheet===I.sheetName).map(f=>f.sourceRow).filter(f=>typeof f=="number").map(f=>f-1),R=b.signatures?.filter(f=>f.sourceSheet===I.sheetName).map(f=>f.sourceRow).filter(f=>typeof f=="number").map(f=>f-1)||[],W=z.length===0&&R.length===0?[I.startRow,I.startRow+1,I.startRow+2]:[];ja(S,I,[...z,...R,...W],"Reference/helper parsed rows")});const k=S.getUnmappedBlocks(o.matrices);Qs(s,{stage:"validating",message:"Validating completeness and structural integrity..."});const N=Bx({detection:n,inputData:c,quarterSheets:m,finalSheets:p,mappedCellRegions:S.getMappedRegionCount(),unmappedCellRegions:k.length,totalSheets:o.sheetNames.length});Qs(s,{stage:"normalizing",message:"Normalizing parsed workbook and creating entity mapping..."});const v=Rx({workbook:o,detection:n,inputData:c,quarterSheets:m,finalSheets:p,references:b,validation:N,unclassifiedBlocks:k});v.validation.confidenceD.trim().toLowerCase().replace(/\s+/g," "),be=D=>{if(typeof D=="number"&&Number.isFinite(D))return D;const j=Number(String(D??"").replace(/[^0-9.-]+/g,""));return Number.isFinite(j)?j:null},Ie=(D,j)=>{const _=Number.isFinite(D)?D:j;return Math.max(0,Math.min(100,_))},de=D=>{const j=String(D??"");return/[",\n]/.test(j)?`"${j.replace(/"/g,'""')}"`:j},fe=(D,j)=>{const _=new Map,T=["quarterlyGrade","finalGrades","firstSemester","firstQuarter","secondQuarter","initialGrade"];D.mapping.gradeEntities.forEach($e=>{const Ge=ne($e.fullName||"");if(!Ge)return;const ft=T.map(dt=>be($e[dt])).filter(dt=>dt!==null);if(ft.length===0)return;const Nt=_.get(Ge)||[];_.set(Ge,Nt.concat(ft))});const Q=D.mapping.studentEntities||[];if(Q.length===0)return null;const ue=(D.imported.schoolContext.semester||D.imported.schoolContext.schoolYear||"First Semester").trim(),ce=(D.imported.schoolContext.subjectName||"Class Record Import").trim(),ae=(t||s||"import").replace(/[^a-zA-Z0-9]+/g,"").toUpperCase().slice(0,12)||"IMPORT",Ne=[["name","lrn","email","engagementScore","avgQuizScore","attendance","assignmentCompletion","term","assessmentName"].join(",")];if(Q.forEach(($e,Ge)=>{const ft=ne($e.fullName||""),Nt=_.get(ft)||[],dt=Nt.length>0?Nt.reduce((vs,os)=>vs+os,0)/Nt.length:75,jt=Ie(dt,75),Lt=Ie(jt+5,85),rs=Ie(jt*.7+Lt*.3,80),Ts=Ie(Lt*.6+jt*.4,82),bs=$e.learnerNo||Ge+1,Bs=`IMP-${ae}-${String(bs).padStart(4,"0")}`,ns=$e.fullName||`Learner ${Ge+1}`;Ne.push([de(ns),de(Bs),de(""),de(Number(rs.toFixed(1))),de(Number(jt.toFixed(1))),de(Number(Lt.toFixed(1))),de(Number(Ts.toFixed(1))),de(ue),de(ce)].join(","))}),Ne.length<=1)return null;const Je=j.replace(/\.(xlsx|xls)$/i,"");return new File([Ne.join(` -`)],`${Je}-normalized.csv`,{type:"text/csv"})},H=async D=>{C(!0),y(""),J(null);let j=D;if(/\.(xlsx|xls)$/i.test(D.name))try{const _=await Gx(D,{confidenceThreshold:on});g(_);const T=fe(_,D.name);T&&(j=T)}catch{g(null)}else g(null);try{const _=await xt.uploadClassRecords(j,{classSectionId:t,className:s,datasetIntent:"synthetic_student_records"}),T=_.students.length,ue=((ce,ae,Ce,Ne)=>({classSectionId:ce.classSectionId||ae||"imported_class",className:ce.className||Ce||"Imported Class",classMetadata:ce.classMetadata||Ne}))(_,t,s,a);T>0&&l?.({students:_.students,classSectionId:ue.classSectionId,className:ue.className,classMetadata:ue.classMetadata}),_.success?(ie.success(`Successfully imported ${T} student records.`),J({datasetIntent:_.datasetIntent,summary:_.interpretationSummary,columns:_.columnInterpretations?.map(ce=>({columnName:ce.columnName,mappedField:ce.mappedField,usagePolicy:ce.usagePolicy,confidenceBand:ce.confidenceBand,domainSignals:ce.domainSignals}))||[]}),c?.()):ie.error("Import completed but no usable student rows were detected. Check required columns and retry.")}catch(_){ie.error(_ instanceof Error?_.message:"Upload failed")}finally{C(!1)}},ee=async D=>{$(!0);try{const j=await xt.uploadCourseMaterials(D,{classSectionId:t,className:s});if(j.success){const _=j.topics?.length??0;ie.success(`Course material imported (${_} topics extracted).`),c?.()}}catch(j){ie.error(j instanceof Error?j.message:"Course material upload failed")}finally{$(!1)}},[oe,Re]=u.useState(r),[Fe,Pe]=u.useState(!1),[G,te]=u.useState(null),E=u.useMemo(()=>{let D=oe;if(o.length>0){const j=new Set(o.map(_=>js(_.classSectionId||_.id)));D=D.filter(_=>j.has(js(_.classSectionId))||j.has(js(_.classroomId)))}else return[];return t&&(D=D.filter(j=>js(j.classSectionId)===js(t)||js(j.classroomId)===js(t))),D},[oe,t,o]);u.useEffect(()=>{Re(r),V(Object.fromEntries(r.map(D=>[Ka(D),{grade:D.grade||"",section:D.section||""}])))},[r]);const[Y,V]=u.useState({}),pe=async()=>{Pe(!0);let D=0,j=0;try{for(const T of E){const Q=Y[Ka(T)],ue=Q?.grade||T.grade,ce=Q?.section||T.section;try{n&&(ue!==T.grade||ce!==T.section)&&(await yr(T.id,ue,ce,n,new Date().getFullYear().toString(),i),await il(T.id,ue,ce),D++)}catch(ae){console.warn(`[EditRecords] Failed to save ${T.name}:`,ae),j++}}const _=oe.map(T=>{const Q=Y[Ka(T)];if(!Q)return T;const ue=Ct({metadata:T.classMetadata,classSectionId:T.classSectionId,className:[Q.grade,Q.section].filter(Boolean).join(" - "),grade:Q.grade,section:Q.section});return{...T,grade:Q.grade,section:Q.section,className:ue.className||[Q.grade,Q.section].filter(Boolean).join(" - "),classSectionId:ue.classSectionId||T.classSectionId,classMetadata:ue}});Re(_),m?.(_),j>0?ie.warning(`Saved ${D} records, ${j} failed`):ie.success("Records saved successfully")}catch{ie.error("Failed to save changes")}finally{Pe(!1)}};return e.jsx("div",{className:"h-full overflow-y-auto w-full block",children:e.jsxs("div",{className:"w-full p-[24px] xl:p-[32px] space-y-[24px]",children:[k==="main"&&e.jsxs("div",{className:"block space-y-[24px]",children:[e.jsxs("div",{className:"bg-white/80 backdrop-blur-[12px] rounded-[16px] p-4 shadow-[0_1px_4px_rgba(0,0,0,0.04)] border border-slate-200 flex flex-col md:flex-row items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-indigo-50 flex items-center justify-center border border-indigo-100/50",children:e.jsx(lr,{className:"w-5 h-5 text-indigo-500"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-[14px] font-bold text-[#1e293b]",children:"Upload Context"}),e.jsx("p",{className:"text-[12px] text-[#64748b]",children:"Select where the imported data should be applied"})]})]}),e.jsxs("div",{className:"relative w-full md:w-[300px]",children:[e.jsxs("select",{className:"appearance-none bg-[#f8fafc] border border-[#e2e8f0] text-[#1e293b] font-bold text-[13px] rounded-lg pl-4 pr-10 py-2.5 outline-none focus:border-[#4f46e5] focus:ring-2 focus:ring-[#4f46e5]/20 shadow-[0_1px_4px_rgba(0,0,0,0.02)] cursor-pointer w-full transition-colors",value:s||t||"All Classes",onChange:()=>{},children:[e.jsx("option",{value:"All Classes",children:"All Classes"}),o.map(D=>e.jsx("option",{value:D.classSectionId||D.id,children:D.name},D.id))]}),e.jsx($t,{className:"w-4 h-4 text-[#64748b] absolute right-3 top-1/2 -translate-y-1/2 pointer-events-none"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-[24px]",children:[e.jsxs("div",{onDragOver:D=>{D.preventDefault(),z(!0)},onDragLeave:()=>z(!1),onDrop:D=>{D.preventDefault(),z(!1);const j=D.dataTransfer.files[0];j&&H(j)},onClick:()=>re.current?.click(),className:`border-2 border-dashed transition-all rounded-[24px] p-8 flex flex-col items-center justify-center text-center cursor-pointer group shadow-[0_4px_20px_rgba(0,0,0,0.02)] relative overflow-hidden h-[280px] ${I?"border-[#1FA7E1] bg-[#1FA7E1]/10":"border-[#1FA7E1]/30 hover:border-[#1FA7E1] bg-white hover:bg-[#1FA7E1]/5"}`,children:[e.jsx("input",{ref:re,type:"file",accept:".csv,.xlsx,.xls",onChange:D=>{const j=D.target.files?.[0];j&&H(j)},className:"hidden"}),e.jsx("div",{className:"w-16 h-16 rounded-full bg-[#1FA7E1]/10 flex items-center justify-center mb-4 group-hover:scale-110 transition-transform duration-300 shadow-sm border border-[#1FA7E1]/20",children:f?e.jsx("span",{className:"animate-spin text-[#1FA7E1]",children:"..."}):e.jsx(ld,{className:"w-8 h-8 text-[#1FA7E1]"})}),e.jsx("h3",{className:"text-[18px] font-bold text-[#1e293b] mb-2",children:f?"Uploading...":"Class Records"}),e.jsx("p",{className:"text-[13px] text-[#64748b] max-w-sm mb-6",children:"Upload student grades, attendance logs, and quiz scores to power predictive analytics."}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("span",{className:"px-3 py-1 bg-slate-100 text-slate-500 text-[11px] font-semibold rounded-full border border-slate-200",children:".csv"}),e.jsx("span",{className:"px-3 py-1 bg-slate-100 text-slate-500 text-[11px] font-semibold rounded-full border border-slate-200",children:".xlsx"})]})]}),e.jsxs("div",{onDragOver:D=>{D.preventDefault(),W(!0)},onDragLeave:()=>W(!1),onDrop:D=>{D.preventDefault(),W(!1);const j=D.dataTransfer.files[0];j&&ee(j)},onClick:()=>le.current?.click(),className:`border-2 border-dashed transition-all rounded-[24px] p-8 flex flex-col items-center justify-center text-center cursor-pointer group shadow-[0_4px_20px_rgba(0,0,0,0.02)] relative overflow-hidden h-[280px] ${R?"border-[#9956DE] bg-[#9956DE]/10":"border-[#9956DE]/30 hover:border-[#9956DE] bg-white hover:bg-[#9956DE]/5"}`,children:[e.jsx("input",{ref:le,type:"file",accept:".pdf,.docx,.txt",onChange:D=>{const j=D.target.files?.[0];j&&ee(j)},className:"hidden"}),e.jsx("div",{className:"w-16 h-16 rounded-full bg-[#9956DE]/10 flex items-center justify-center mb-4 group-hover:scale-110 transition-transform duration-300 shadow-sm border border-[#9956DE]/20",children:w?e.jsx("span",{className:"animate-spin text-[#9956DE]",children:"..."}):e.jsx(Rs,{className:"w-8 h-8 text-[#9956DE]"})}),e.jsx("h3",{className:"text-[18px] font-bold text-[#1e293b] mb-2",children:w?"Uploading...":"Course Materials"}),e.jsx("p",{className:"text-[13px] text-[#64748b] max-w-sm mb-6",children:"Upload syllabus, lesson plans, and curriculum docs to ground AI lesson generation."}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("span",{className:"px-3 py-1 bg-slate-100 text-slate-500 text-[11px] font-semibold rounded-full border border-slate-200",children:".pdf"}),e.jsx("span",{className:"px-3 py-1 bg-slate-100 text-slate-500 text-[11px] font-semibold rounded-full border border-slate-200",children:".docx"}),e.jsx("span",{className:"px-3 py-1 bg-slate-100 text-slate-500 text-[11px] font-semibold rounded-full border border-slate-200",children:".txt"})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-[16px]",children:[e.jsxs("div",{className:"relative overflow-hidden bg-gradient-to-br from-[#0ea5e9] to-[#0284c7] rounded-[16px] p-[20px] shadow-[0_4px_12px_rgba(14,165,233,0.2)] flex flex-col text-white group transition-all duration-300 hover:-translate-y-1 hover:shadow-lg hover:shadow-sky-500/30",children:[e.jsx("div",{className:"absolute -right-8 -bottom-8 w-24 h-24 bg-white/10 rounded-full"}),e.jsx("div",{className:"w-10 h-10 rounded-full bg-white/10 border border-white/20 flex items-center justify-center shrink-0 mb-3 relative z-10 transition-transform group-hover:scale-110",children:e.jsx(od,{className:"w-5 h-5 text-white"})}),e.jsx("h4",{className:"font-bold text-[14px] mb-1.5 relative z-10",children:"Smart Parsing"}),e.jsx("p",{className:"text-[12px] text-white/90 leading-relaxed relative z-10",children:"AI automatically understands varied spreadsheet formats and maps column names securely."})]}),e.jsxs("div",{className:"relative overflow-hidden bg-gradient-to-br from-[#f97316] to-[#ea580c] rounded-[16px] p-[20px] shadow-[0_4px_12px_rgba(249,115,22,0.2)] flex flex-col text-white group transition-all duration-300 hover:-translate-y-1 hover:shadow-lg hover:shadow-orange-500/30",children:[e.jsx("div",{className:"absolute -right-8 -bottom-8 w-24 h-24 bg-white/10 rounded-full"}),e.jsx("div",{className:"w-10 h-10 rounded-full bg-white/10 border border-white/20 flex items-center justify-center shrink-0 mb-3 relative z-10 transition-transform group-hover:scale-110",children:e.jsx(Kr,{className:"w-5 h-5 text-white"})}),e.jsx("h4",{className:"font-bold text-[14px] mb-1.5 relative z-10",children:"Risk Prediction"}),e.jsx("p",{className:"text-[12px] text-white/90 leading-relaxed relative z-10",children:"Analyzes historical performance patterns across your data to predict at-risk students."})]}),e.jsxs("div",{className:"relative overflow-hidden bg-gradient-to-br from-[#a855f7] to-[#9333ea] rounded-[16px] p-[20px] shadow-[0_4px_12px_rgba(168,85,247,0.2)] flex flex-col text-white group transition-all duration-300 hover:-translate-y-1 hover:shadow-lg hover:shadow-purple-500/30",children:[e.jsx("div",{className:"absolute -right-8 -bottom-8 w-24 h-24 bg-white/10 rounded-full"}),e.jsx("div",{className:"w-10 h-10 rounded-full bg-white/10 border border-white/20 flex items-center justify-center shrink-0 mb-3 relative z-10 transition-transform group-hover:scale-110",children:e.jsx(ps,{className:"w-5 h-5 text-white"})}),e.jsx("h4",{className:"font-bold text-[14px] mb-1.5 relative z-10",children:"Contextual AI"}),e.jsx("p",{className:"text-[12px] text-white/90 leading-relaxed relative z-10",children:"Maps curriculum topics to generate highly personalized remedial lesson paths."})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-[24px]",children:[e.jsxs("div",{className:"bg-white/80 backdrop-blur-[12px] rounded-[24px] p-[24px] shadow-[0_1px_4px_rgba(0,0,0,0.02)] border border-white flex flex-col justify-between h-full",children:[e.jsx("h2",{className:"text-[16px] font-semibold text-[#1e293b] mb-4",children:"Data Health"}),e.jsxs("div",{className:"flex-1 bg-emerald-50/50 border border-emerald-100 rounded-[16px] p-6 flex flex-col items-center justify-center text-center transition-all duration-300 hover:bg-emerald-50 hover:shadow-md hover:border-emerald-200",children:[e.jsx("div",{className:"w-12 h-12 rounded-full bg-emerald-100 flex items-center justify-center mb-3 text-emerald-600 transition-transform duration-300 hover:scale-110 hover:-translate-y-1",children:e.jsx(ya,{className:"w-6 h-6"})}),e.jsx("h3",{className:"text-emerald-700 font-bold text-[15px] mb-1",children:"All Records Synced"}),e.jsx("p",{className:"text-emerald-600/80 text-[12px] max-w-[200px]",children:"AI parsing completed successfully with no anomalies detected."})]}),e.jsxs("div",{className:"flex flex-col gap-2 mt-4",children:[e.jsxs("button",{onClick:()=>N("edit-records"),className:"w-full flex items-center justify-center gap-2 bg-[#1e293b] hover:bg-black text-white text-[13px] font-semibold rounded-full px-4 py-3 shadow-[0_1px_4px_rgba(0,0,0,0.04)] transition-transform hover:scale-[1.02]",children:[e.jsx(sd,{className:"w-4 h-4"})," Edit Class Records"]}),e.jsx("button",{onClick:()=>N("mapping-logs"),className:"w-full flex items-center justify-center gap-2 bg-white text-[#475569] border border-slate-300 hover:bg-slate-50 text-[13px] font-semibold rounded-full px-4 py-3 shadow-[0_1px_4px_rgba(0,0,0,0.04)] transition-colors",children:"View Mapping Logs"})]})]}),e.jsxs("div",{className:"bg-white/80 backdrop-blur-[12px] rounded-[24px] p-[24px] shadow-[0_1px_4px_rgba(0,0,0,0.02)] border border-white flex flex-col h-full",children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsx("h2",{className:"text-[16px] font-semibold text-[#1e293b]",children:"Recent Uploads"}),e.jsx("button",{onClick:()=>N("mapping-logs"),className:"text-[13px] font-semibold text-[#4f46e5] hover:text-[#3730a3] transition-colors",children:"View All"})]}),e.jsxs("div",{className:"flex-1 space-y-[12px] overflow-y-auto no-scrollbar flex flex-col justify-center items-center h-[120px]",children:[e.jsx("div",{className:"w-12 h-12 rounded-full bg-slate-50 flex items-center justify-center mb-2 border border-slate-100",children:e.jsx(Yc,{className:"w-5 h-5 text-slate-300"})}),e.jsx("p",{className:"text-[13px] font-medium text-slate-500",children:"There are no recent uploads yet."})]})]})]})]}),k==="mapping-logs"&&e.jsxs("div",{className:"space-y-[16px]",children:[e.jsx("div",{className:"shrink-0 mb-2",children:e.jsxs("button",{onClick:()=>N("main"),className:"flex items-center gap-2 text-[13px] font-semibold text-[#4f46e5] hover:text-[#3730a3] transition-colors w-max bg-white px-[18px] py-2 rounded-full shadow-sm border border-slate-200",children:[e.jsx(cr,{className:"w-4 h-4"})," Back to Uploads"]})}),e.jsxs("div",{className:"bg-white rounded-[18px] border border-[#f1f5f9] overflow-hidden shadow-sm",children:[e.jsx("div",{className:"p-5 border-b border-[#f1f5f9] bg-slate-50 flex justify-between items-center",children:e.jsx("h2",{className:"text-[15px] font-semibold text-[#1e293b]",children:"Latest Import Mapping"})}),e.jsx("div",{className:"p-5",children:q?e.jsx("div",{className:"space-y-3",children:q.columns.map((D,j)=>e.jsxs("div",{className:"flex justify-between p-3 border rounded bg-slate-50",children:[e.jsx("span",{className:"font-semibold text-sm",children:D.columnName}),e.jsx("span",{className:"text-sm text-indigo-600",children:D.mappedField||"Unmapped"})]},j))}):e.jsx("p",{className:"text-slate-500 text-sm",children:"No recent mapping logs to display."})})]})]}),k==="edit-records"&&e.jsxs("div",{className:"space-y-[16px] h-full flex flex-col",children:[e.jsx("div",{className:"shrink-0 mb-2",children:e.jsxs("button",{onClick:()=>N("main"),className:"flex items-center gap-2 text-[13px] font-semibold text-[#4f46e5] hover:text-[#3730a3] transition-colors w-max bg-white px-[18px] py-2 rounded-full shadow-sm border border-slate-200",children:[e.jsx(cr,{className:"w-4 h-4"})," Back to Uploads"]})}),e.jsxs("div",{className:"bg-white rounded-[18px] border border-slate-200 shadow-sm overflow-hidden flex flex-col flex-1",children:[e.jsxs("div",{className:"p-5 border-b border-slate-200 flex justify-between items-center bg-white",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-[18px] font-bold text-[#1e293b]",children:"Edit Class Records"}),e.jsx("p",{className:"text-[13px] text-[#64748b]",children:"Review and modify student data manually"})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx("button",{onClick:()=>N("main"),className:"px-5 py-2 rounded-full border border-slate-300 text-slate-700 font-semibold text-[13px] hover:bg-slate-50",children:"Cancel"}),e.jsx("button",{onClick:pe,disabled:Fe,className:"px-5 py-2 rounded-full bg-emerald-500 text-white font-semibold text-[13px] hover:bg-emerald-600 flex items-center gap-2 disabled:opacity-50",children:Fe?"Saving...":e.jsxs(e.Fragment,{children:[e.jsx(Ni,{className:"w-4 h-4"})," Save Changes"]})})]})]}),e.jsxs("div",{className:"px-5 py-3 border-b border-slate-200 flex justify-between items-center bg-slate-50/50 shrink-0 text-slate-500 text-[13px]",children:[e.jsxs("span",{className:"flex items-center gap-2 font-medium",children:[e.jsx(na,{className:"w-4 h-4"})," Click on any field to edit"]}),e.jsxs("span",{children:["Showing ",E.length," records"]})]}),e.jsx("div",{className:"overflow-auto flex-1 table-scrollbar bg-white relative",children:e.jsxs("div",{className:"min-w-[1100px] w-full flex flex-col min-h-full",children:[e.jsxs("div",{className:"flex items-center w-full bg-slate-100/90 border-b border-slate-200 text-[12px] font-semibold text-slate-500 tracking-wide sticky top-0 z-20 shadow-[0_1px_2px_rgba(0,0,0,0.02)] h-12",children:[e.jsx("div",{className:"flex-[1.5] min-w-[240px] px-6 sticky left-0 z-30 bg-slate-100/90 backdrop-blur-sm border-r border-slate-200 h-full flex items-center shadow-[2px_0_4px_rgba(0,0,0,0.02)]",children:"Student Name"}),e.jsx("div",{className:"w-[100px] shrink-0 px-4 h-full flex items-center justify-center",children:"LRN"}),e.jsx("div",{className:"w-[140px] shrink-0 px-4 h-full flex items-center justify-center",children:"Grade"}),e.jsx("div",{className:"w-[140px] shrink-0 px-4 h-full flex items-center justify-center",children:"Section"}),e.jsx("div",{className:"w-[100px] shrink-0 px-4 h-full flex items-center justify-center",children:"Avg Score"}),e.jsx("div",{className:"w-[120px] shrink-0 px-4 h-full flex items-center justify-center",children:"Risk Level"}),e.jsx("div",{className:"flex-1 min-w-[180px] px-4 h-full flex items-center justify-center",children:"Weakest Topic"}),e.jsx("div",{className:"w-[80px] shrink-0 px-4 h-full flex items-center justify-center border-r border-transparent",children:"Action"})]}),e.jsx("div",{className:"flex flex-col w-full pb-4",children:E.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 px-6 text-center",children:[e.jsx("div",{className:"w-16 h-16 rounded-full bg-slate-100 flex items-center justify-center mb-4",children:e.jsx(na,{className:"w-7 h-7 text-slate-400"})}),e.jsx("h3",{className:"text-[16px] font-bold text-slate-700 mb-2",children:"No managed classes found"}),e.jsx("p",{className:"text-[13px] text-slate-500 max-w-sm",children:"You don't currently manage any classes. Ask your administrator to assign you as a section manager, or create a new class from the Dashboard."})]}):E.map((D,j)=>{const _=Ka(D),T=D.name.split(" "),Q=T.length>1?`${T[0][0]}${T[T.length-1][0]}`.toUpperCase():D.name.substring(0,2).toUpperCase(),ue=["bg-[#be185d]","bg-[#3b82f6]","bg-[#f43f5e]","bg-[#2563eb]","bg-[#059669]","bg-[#d946ef]"],ce=ue[j%ue.length],ae=(D.avgScore??0)>=75?"text-emerald-500":(D.avgScore??0)>=60?"text-orange-500":"text-rose-500";let Ce="bg-slate-50 text-slate-600 border-slate-200";const Ne=(D.riskLevel||"").toLowerCase();return Ne==="low"?Ce="bg-emerald-50 text-emerald-600 border-emerald-200":Ne==="high"?Ce="bg-rose-50 text-rose-600 border-rose-200":Ne==="medium"&&(Ce="bg-orange-50 text-orange-600 border-orange-200"),e.jsxs("div",{className:"flex items-center w-full border-b border-slate-100 hover:bg-slate-50 transition-colors group min-h-[64px]",children:[e.jsxs("div",{className:"flex-[1.5] min-w-[240px] px-6 sticky left-0 z-10 bg-white group-hover:bg-slate-50 border-r border-slate-100 h-full flex items-center gap-4 shadow-[2px_0_4px_rgba(0,0,0,0.01)]",children:[e.jsx("div",{className:`w-8 h-8 rounded-full ${ce} text-white flex items-center justify-center font-bold text-[12px] shrink-0`,children:Q}),e.jsx("span",{className:"font-semibold text-slate-800 text-[14px] truncate",children:D.name})]}),e.jsx("div",{className:"w-[100px] shrink-0 px-4 flex justify-center text-[13px] text-slate-500",children:D.lrn||"—"}),e.jsx("div",{className:"w-[140px] shrink-0 px-4 flex justify-center",children:e.jsx("input",{type:"text",value:Y[_]?.grade||D.grade||"",onChange:Je=>V($e=>({...$e,[_]:{...$e[_],grade:Je.target.value}})),readOnly:G!==_,className:`outline-none px-4 py-1.5 rounded-full text-[13px] font-medium text-slate-600 w-full transition-all text-center ${G===_?"bg-white border border-purple-500 ring-2 ring-purple-500/20":"bg-slate-100 border border-transparent cursor-default"}`})}),e.jsx("div",{className:"w-[140px] shrink-0 px-4 flex justify-center",children:e.jsx("input",{type:"text",value:Y[_]?.section||D.section||"",onChange:Je=>V($e=>({...$e,[_]:{...$e[_],section:Je.target.value}})),readOnly:G!==_,className:`outline-none px-4 py-1.5 rounded-full text-[13px] font-medium text-slate-600 w-full transition-all text-center ${G===_?"bg-white border border-purple-500 ring-2 ring-purple-500/20":"bg-slate-100 border border-transparent cursor-default"}`})}),e.jsx("div",{className:"w-[100px] shrink-0 px-4 flex justify-center",children:e.jsxs("span",{className:`${ae} font-bold text-[14px]`,children:[D.avgScore,"%"]})}),e.jsx("div",{className:"w-[120px] shrink-0 px-4 flex justify-center",children:e.jsx("span",{className:`px-3 py-1 text-[10px] font-bold rounded uppercase border ${Ce}`,children:D.riskLevel||"Unknown"})}),e.jsx("div",{className:"flex-1 min-w-[180px] px-4 flex justify-center text-[13px] text-slate-600 truncate",children:D.weakestTopic||"Foundational Skills"}),e.jsx("div",{className:"w-[80px] shrink-0 px-4 flex justify-center border-r border-transparent",children:e.jsx("button",{onClick:()=>te(G===_?null:_),className:`w-8 h-8 rounded-full flex items-center justify-center transition-colors ${G===_?"bg-purple-100 text-purple-600":"hover:bg-slate-200 text-slate-400"}`,children:e.jsx(ki,{className:"w-4 h-4"})})})]},_)})})]})})]})]})]})})}const Vx=[{value:"available",label:"Available",icon:e.jsx(La,{size:14}),color:"text-emerald-600"},{value:"teacher_uploaded",label:"Teacher Material",icon:e.jsx(Wr,{size:14}),color:"text-blue-600"},{value:"coming_soon",label:"Coming Soon",icon:e.jsx(As,{size:14}),color:"text-amber-600"},{value:"unavailable",label:"Unavailable",icon:e.jsx(wc,{size:14}),color:"text-slate-400"}],Wx=({teacherId:t})=>{const[s,a]=u.useState(""),[r,o]=u.useState("teacher_uploaded"),[n,i]=u.useState(!1),[l,c]=u.useState(null),d=async()=>{if(!s){ie.error("Select a module first.");return}i(!0);try{let m;if(l&&r==="teacher_uploaded"){const p=zc(Ul,`teacher_modules/${t}/${s}/${l.name}`);await Dc(p,l),m=await $c(p)}await Lc(s,r,t,m),ie.success(`Module status updated to "${r}".`),c(null)}catch(m){ie.error(m.message||"Failed to update module status.")}finally{i(!1)}};return e.jsxs("div",{className:"rounded-2xl border border-slate-200 bg-white p-5 space-y-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-slate-800",children:"Module Availability Control"}),e.jsx("p",{className:"text-xs text-slate-500 mt-0.5",children:"Set module status or upload alternative PDF when DepEd content is unavailable."})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold text-slate-600 mb-1 block",children:"Module"}),e.jsxs("select",{value:s,onChange:m=>a(m.target.value),className:"w-full rounded-lg border border-slate-200 px-3 py-2 text-sm",children:[e.jsx("option",{value:"",children:"Select module..."}),Hl.map(m=>e.jsxs("option",{value:m.id,children:[m.moduleTitle," (",m.quarter,")"]},m.id))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold text-slate-600 mb-1 block",children:"Status"}),e.jsx("select",{value:r,onChange:m=>o(m.target.value),className:"w-full rounded-lg border border-slate-200 px-3 py-2 text-sm",children:Vx.map(m=>e.jsx("option",{value:m.value,children:m.label},m.value))})]})]}),r==="teacher_uploaded"&&e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold text-slate-600 mb-1 block",children:"Upload Alternative PDF (optional)"}),e.jsx("input",{type:"file",accept:".pdf",onChange:m=>c(m.target.files?.[0]||null),className:"text-sm text-slate-600"})]}),e.jsx("button",{type:"button",onClick:d,disabled:!s||n,className:"px-4 py-2 rounded-lg bg-indigo-600 hover:bg-indigo-700 text-white text-sm font-bold disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:n?"Updating...":"Update Status"})]})},Xa="ABCDEFGHJKMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz23456789",si="school.mathpulse.local";function ai(t=10){const s=typeof globalThis<"u"&&typeof globalThis.crypto<"u"?globalThis.crypto:void 0;if(s&&typeof s.getRandomValues=="function"){const r=new Uint32Array(t);s.getRandomValues(r);let o="";for(let n=0;n{const[l,c]=u.useState(""),[d,m]=u.useState(""),[p,h]=u.useState(!1),[b,S]=u.useState(null),[k,N]=u.useState(null),[v,g]=u.useState(!1);u.useEffect(()=>{t&&(S(null),g(!1),h(!1),N(null),c((a?.email||qx(a)).trim()),m(ai()))},[t,a]);const I=u.useMemo(()=>a?[a.grade,a.section].filter(Boolean).join(" · ")||"Unassigned section":null,[a]),z=()=>{m(ai()),g(!1)},R=async()=>{try{const C=k?.temporaryPassword||d;if(!C)return;typeof navigator<"u"&&navigator.clipboard&&await navigator.clipboard.writeText(C),g(!0),ie.success("Temporary password copied. Share it with the student now — it will not be shown again."),window.setTimeout(()=>g(!1),2500)}catch(C){console.warn("Clipboard write failed:",C),ie.error("Unable to copy password. Please copy it manually.")}},W=async()=>{if(!a)return;const C=l.trim();if(!Yx(C)){S("Enter a valid email address before creating the account.");return}if(!d||d.length<8){S("Temporary password must be at least 8 characters.");return}if(!r){S("Missing teacher context. Please refresh and try again.");return}h(!0),S(null);try{const w=await Yu({name:a.name,lrn:a.lrn,email:C,grade:a.grade,section:a.section,classSectionId:a.classSectionId,adviserTeacherId:r,adviserTeacherName:o,schoolYear:n,temporaryPassword:d});N(w),i?.({...w,rosterId:a.rosterId}),ie.success(`Account created for ${a.name}.`)}catch(w){const $=w instanceof Error?w.message:"Failed to create account.";S($)}finally{h(!1)}},f=k?.temporaryPassword||d;return e.jsx(zt,{children:t&&a&&e.jsx(Le.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-[60] flex items-center justify-center bg-black/50 backdrop-blur-sm p-4",onClick:()=>{p||s()},children:e.jsxs(Le.div,{initial:{opacity:0,scale:.95,y:12},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:12},transition:{type:"spring",damping:28,stiffness:320},onClick:C=>C.stopPropagation(),className:"bg-[#f7f9fc] rounded-3xl shadow-2xl w-full max-w-lg overflow-hidden border border-[#dde3eb]",role:"dialog","aria-modal":"true","aria-labelledby":"create-student-account-modal-title",children:[e.jsxs("div",{className:"flex items-start justify-between px-6 pt-6",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-12 h-12 rounded-2xl bg-indigo-100 text-indigo-600 flex items-center justify-center shrink-0",children:e.jsx(ci,{size:22})}),e.jsxs("div",{children:[e.jsx("h2",{id:"create-student-account-modal-title",className:"text-[16px] font-bold text-[#0a1628]",children:k?"Account Created":"Create Student Account"}),e.jsx("p",{className:"text-[12px] text-[#5a6578] mt-0.5",children:k?"Share these credentials with the student. The password will not be shown again.":`Provision a system account for ${a.name}.`})]})]}),e.jsx("button",{type:"button",onClick:()=>{p||s()},className:"p-1.5 rounded-lg hover:bg-[#dde3eb] transition-colors","aria-label":"Close",children:e.jsx(Xt,{className:"w-4 h-4 text-[#5a6578]"})})]}),e.jsxs("div",{className:"px-6 py-5 space-y-4",children:[e.jsxs("div",{className:"bg-white border border-[#e2e8f0] rounded-2xl p-4",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wider text-[#64748b]",children:"Roster Row"}),e.jsx("p",{className:"text-[14px] font-semibold text-[#0a1628] mt-1",children:a.name}),e.jsxs("p",{className:"text-[12px] text-[#475569] mt-0.5",children:[a.lrn?`LRN ${a.lrn} · `:"",I]})]}),!k&&e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-[12px] font-semibold text-[#0a1628]",children:"Email address"}),e.jsx("input",{type:"email",value:l,onChange:C=>c(C.target.value),disabled:p,className:"mt-1 w-full rounded-xl border border-[#dde3eb] bg-white px-3 py-2 text-[13px] text-[#0a1628] focus:border-indigo-500 focus:outline-none focus:ring-2 focus:ring-indigo-200",placeholder:"student@school.example",autoComplete:"off",spellCheck:!1}),e.jsx("span",{className:"text-[11px] text-[#64748b] mt-1 block",children:"Auto-generated from LRN if available. The student will sign in with this address."})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[12px] font-semibold text-[#0a1628] block",children:"Temporary password"}),e.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[e.jsx("input",{type:"text",value:d,readOnly:!0,className:"flex-1 rounded-xl border border-[#dde3eb] bg-white px-3 py-2 text-[13px] font-mono tracking-wide text-[#0a1628] focus:outline-none"}),e.jsx("button",{type:"button",onClick:z,disabled:p,className:"p-2 rounded-xl border border-[#dde3eb] bg-white hover:bg-[#f1f5f9] transition-colors disabled:opacity-60","aria-label":"Regenerate temporary password",children:e.jsx(cs,{className:"w-4 h-4 text-[#475569]"})}),e.jsx("button",{type:"button",onClick:R,className:"p-2 rounded-xl border border-[#dde3eb] bg-white hover:bg-[#f1f5f9] transition-colors","aria-label":"Copy temporary password",children:v?e.jsx(Ht,{className:"w-4 h-4 text-emerald-600"}):e.jsx(Vr,{className:"w-4 h-4 text-[#475569]"})})]}),e.jsx("span",{className:"text-[11px] text-[#64748b] mt-1 block",children:"The student should change this on first sign-in. Share it once — it will not be persisted."})]}),b&&e.jsxs("div",{className:"flex items-start gap-2 rounded-xl bg-rose-50 border border-rose-200 px-3 py-2 text-[12px] text-rose-700",children:[e.jsx(Mc,{className:"w-4 h-4 mt-0.5 shrink-0"}),e.jsx("span",{children:b})]})]}),k&&e.jsxs("div",{className:"rounded-2xl border border-emerald-200 bg-emerald-50 p-4 space-y-2",children:[e.jsx("p",{className:"text-[12px] font-semibold text-emerald-800",children:"Credentials"}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-xl bg-white border border-emerald-100 px-3 py-2",children:[e.jsx("span",{className:"text-[12px] text-[#475569]",children:"Email"}),e.jsx("span",{className:"text-[13px] font-semibold text-[#0a1628]",children:k.email})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-xl bg-white border border-emerald-100 px-3 py-2",children:[e.jsx("span",{className:"text-[12px] text-[#475569]",children:"Temporary password"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[13px] font-semibold font-mono text-[#0a1628]",children:f}),e.jsx("button",{type:"button",onClick:R,className:"p-1.5 rounded-lg border border-emerald-200 bg-white hover:bg-emerald-100 transition-colors","aria-label":"Copy temporary password",children:v?e.jsx(Ht,{className:"w-4 h-4 text-emerald-600"}):e.jsx(Vr,{className:"w-4 h-4 text-emerald-700"})})]})]}),e.jsx("p",{className:"text-[11px] text-emerald-800",children:"This password is not stored anywhere. If you close this dialog without copying, you will need to reset it from the admin tools."})]})]}),e.jsx("div",{className:"flex items-center justify-end gap-2 px-6 pb-6",children:k?e.jsx(St,{type:"button",onClick:s,className:"bg-indigo-600 hover:bg-indigo-700 text-white text-[13px] font-semibold rounded-xl px-5 py-2",children:"Done"}):e.jsxs(e.Fragment,{children:[e.jsx(St,{type:"button",variant:"ghost",onClick:s,disabled:p,className:"text-[13px] font-semibold text-[#475569] rounded-xl px-4 py-2 hover:bg-[#dde3eb]",children:"Cancel"}),e.jsx(St,{type:"button",onClick:W,disabled:p,className:"bg-indigo-600 hover:bg-indigo-700 text-white text-[13px] font-semibold rounded-xl px-5 py-2 disabled:opacity-60",children:p?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(gt,{className:"w-4 h-4 animate-spin"}),"Creating…"]}):"Create account"})]})})]})})})};function Xx(t){const s=t.atRiskCount>=5?"high":t.atRiskCount>=2?"medium":"low",a=Ct({metadata:t.classMetadata,classSectionId:t.classSectionId,className:t.name,grade:t.grade,gradeLevel:t.gradeLevel,classification:t.classification,strand:t.strand,section:t.section,schoolYear:t.schoolYear,ownerTeacherId:t.ownerTeacherId||t.teacherId,ownerTeacherName:t.ownerTeacherName,adviserTeacherId:t.adviserTeacherId||t.teacherId,adviserTeacherName:t.adviserTeacherName||t.ownerTeacherName,managerId:t.managerId,managerName:t.managerName});return{id:t.id,name:a.className||t.name,classSectionId:a.classSectionId||t.classSectionId,classMetadata:a,gradeLevel:a.gradeLevel||void 0,classification:a.classification||void 0,strand:a.strand||void 0,managerId:a.managerId||void 0,managerName:a.managerName||void 0,schedule:t.schedule,studentCount:t.studentCount,avgScore:t.avgScore,atRiskCount:t.atRiskCount,riskLevel:s}}function Hr(t,s){const a=t.riskStatus?["intervene","critical","at_risk"].includes(t.riskStatus)?"high":t.riskStatus==="watch"?"medium":"low":(t.riskLevel||"Low").toLowerCase(),r=t.lastActive?Cl(t.lastActive.toDate()):"Unknown",o=t.className||s||"Imported Class",n=xs(o),i=t.grade||n.grade,l=t.section||n.section,c=Ct({metadata:t.classMetadata,classSectionId:t.classSectionId||t.classroomId,className:[i,l].filter(Boolean).join(" - ")||o,grade:i,gradeLevel:t.gradeLevel,classification:t.classification,strand:t.strand,section:l,adviserTeacherId:t.teacherId,ownerTeacherId:t.teacherId,managerId:t.classMetadata?.managerId||t.managerId,managerName:t.classMetadata?.managerName||t.managerName});return{id:t.id,lrn:t.lrn,name:t.name,avatar:t.avatar||`https://ui-avatars.com/api/?name=${encodeURIComponent(t.name)}&background=random`,avgScore:t.avgQuizScore,riskLevel:a,riskStatus:t.riskStatus||null,wri:t.wri??null,weakestTopic:t.weakestTopic||"N/A",classroomId:t.classroomId||c.classSectionId||o,className:c.className||[i,l].filter(Boolean).join(" - ")||o,grade:i,gradeLevel:c.gradeLevel||gs(i)||void 0,classification:c.classification||xa(c.gradeLevel||i)||void 0,strand:c.strand||pa(c.className,l)||void 0,section:l,classSectionId:c.classSectionId||t.classSectionId,classMetadata:c,managerId:c.managerId||void 0,managerName:c.managerName||void 0,lastActive:r,struggles:t.struggles||[],engagementScore:t.engagementScore,attendance:t.attendance,assignmentCompletion:t.assignmentCompletion,hasRegisteredAccount:t.hasRegisteredAccount,source:t.source,accountUid:t.accountUid,email:t.email}}function Jx(t){const s=t.atRiskCount>=5?"high":t.atRiskCount>=2?"medium":"low",a=Ct({metadata:t.classMetadata,classSectionId:t.classSectionId,className:t.name,grade:t.grade,gradeLevel:t.gradeLevel||t.classMetadata?.gradeLevel,classification:t.classification||t.classMetadata?.classification,strand:t.strand||t.classMetadata?.strand,section:t.section,managerId:t.managerId||t.classMetadata?.managerId,managerName:t.managerName||t.classMetadata?.managerName});return{id:t.id,name:a.className||t.name,classSectionId:a.classSectionId||t.classSectionId||void 0,classMetadata:a,gradeLevel:a.gradeLevel||void 0,classification:a.classification||void 0,strand:a.strand||void 0,managerId:a.managerId||void 0,managerName:a.managerName||void 0,schedule:t.schedule||"Mon-Fri",studentCount:t.studentCount,avgScore:t.avgScore,atRiskCount:t.atRiskCount,riskLevel:s}}function Zx(t){const s=(t.riskLevel||"Low").toLowerCase(),a=Ct({metadata:t.classMetadata,classSectionId:t.classSectionId,className:t.className||[t.grade,t.section].filter(Boolean).join(" - ")||"Imported Class",grade:t.grade,gradeLevel:t.gradeLevel||t.classMetadata?.gradeLevel,classification:t.classification||t.classMetadata?.classification,strand:t.strand||t.classMetadata?.strand,section:t.section,managerId:t.managerId||t.classMetadata?.managerId,managerName:t.managerName||t.classMetadata?.managerName}),r=a.className||"Imported Class";return{id:t.id,lrn:t.lrn||void 0,name:t.name,avatar:`https://ui-avatars.com/api/?name=${encodeURIComponent(t.name)}&background=random`,avgScore:t.avgQuizScore,riskLevel:s,weakestTopic:t.weakestTopic||"Foundational Skills",classroomId:a.classSectionId||t.classSectionId||r,className:r,grade:a.grade||xs(r).grade,gradeLevel:a.gradeLevel||gs(a.grade||xs(r).grade)||void 0,classification:a.classification||xa(a.gradeLevel||a.grade)||void 0,strand:a.strand||pa(r,a.section||t.section)||void 0,section:a.section||xs(r).section,classSectionId:a.classSectionId||t.classSectionId||void 0,classMetadata:a,managerId:a.managerId||void 0,managerName:a.managerName||void 0,lastActive:"Recently imported",struggles:[t.weakestTopic||"Foundational Skills"],engagementScore:t.engagementScore,attendance:t.attendance,assignmentCompletion:t.assignmentCompletion}}function ep(t,s,a){return t<60||s<75||a<55?"high":t<75||s<85||a<70?"medium":"low"}function tp(t,s,a,r){const o=Ct({metadata:r,classSectionId:s,className:a}),n=o.className||"Imported Class",i=o.classSectionId||"imported_class",l=Number(t.avgQuizScore||0),c=Number(t.attendance||0),d=Number(t.engagementScore||0),m=Number(t.assignmentCompletion||0),p=t.unknownFields?.weakestTopic||t.unknownFields?.topic||"Foundational Skills",h=ep(l,c,d),b=t.studentId||t.lrn||t.email||t.name||Math.random().toString(36).slice(2);return{id:`upload-${i}-${b}`,lrn:t.lrn,name:t.name,avatar:`https://ui-avatars.com/api/?name=${encodeURIComponent(t.name)}&background=random`,avgScore:l,riskLevel:h,weakestTopic:p,classroomId:i,className:n,grade:o.grade||xs(n).grade,gradeLevel:o.gradeLevel||gs(o.grade||xs(n).grade)||void 0,classification:o.classification||xa(o.gradeLevel||o.grade)||void 0,strand:o.strand||pa(n,o.section)||void 0,section:o.section||xs(n).section,classSectionId:i,classMetadata:o,managerId:o.managerId||void 0,managerName:o.managerName||void 0,lastActive:"Recently imported",struggles:[p],engagementScore:d,attendance:c,assignmentCompletion:m}}function Cl(t){const s=Date.now()-t.getTime(),a=Math.floor(s/6e4);if(a<1)return"Just now";if(a<60)return`${a} min${a>1?"s":""} ago`;const r=Math.floor(a/60);if(r<24)return`${r} hour${r>1?"s":""} ago`;const o=Math.floor(r/24);return`${o} day${o>1?"s":""} ago`}function ct(t){return(t||"").trim().toLowerCase()}function ri(t){const s=ct(t.classSectionId);if(s)return`section:${s}`;const a=(t.id||"").trim().toLowerCase();return a?`id:${a}`:`name:${(t.name||"").trim().toLowerCase()}`}function ni(t,s){const a=new Map;return t.forEach(r=>{a.set(ri(r),r)}),s.forEach(r=>{const o=ri(r),n=a.get(o);if(!n){a.set(o,r);return}const i=Math.max(n.atRiskCount||0,r.atRiskCount||0),l=Math.max(n.studentCount||0,r.studentCount||0),c=r.avgScore>0?r.avgScore:n.avgScore,d=i>=5?"high":i>=2?"medium":"low",m=Ct({metadata:n.classMetadata,classSectionId:n.classSectionId||r.classSectionId,className:n.name||r.name,grade:n.classMetadata?.grade||r.classMetadata?.grade,gradeLevel:n.classMetadata?.gradeLevel||r.classMetadata?.gradeLevel,classification:n.classMetadata?.classification||r.classMetadata?.classification,strand:n.classMetadata?.strand||r.classMetadata?.strand,section:n.classMetadata?.section||r.classMetadata?.section,schoolYear:n.classMetadata?.schoolYear||r.classMetadata?.schoolYear,ownerTeacherId:n.classMetadata?.ownerTeacherId||r.classMetadata?.ownerTeacherId,ownerTeacherName:n.classMetadata?.ownerTeacherName||r.classMetadata?.ownerTeacherName,adviserTeacherId:n.classMetadata?.adviserTeacherId||r.classMetadata?.adviserTeacherId,adviserTeacherName:n.classMetadata?.adviserTeacherName||r.classMetadata?.adviserTeacherName,managerId:n.classMetadata?.managerId||r.classMetadata?.managerId,managerName:n.classMetadata?.managerName||r.classMetadata?.managerName});a.set(o,{...n,classSectionId:m.classSectionId||n.classSectionId||r.classSectionId,name:m.className||n.name||r.name,classMetadata:m,gradeLevel:m.gradeLevel||void 0,classification:m.classification||void 0,strand:m.strand||void 0,managerId:m.managerId||void 0,managerName:m.managerName||void 0,schedule:n.schedule||r.schedule,studentCount:l,atRiskCount:i,avgScore:c,riskLevel:d})}),Array.from(a.values())}function gr(t){const s=(t.lrn||"").trim().toLowerCase();if(s)return`lrn:${s}`;const a=t.name.trim().toLowerCase();if(a)return`name:${a}`;const r=ct(t.classSectionId)||ct(t.classroomId),o=(t.id||"").trim().toLowerCase();return r&&o?`${r}|id:${o}`:`${r}|anonymous`}function ln(t){const s=ct(t.classSectionId)||ct(t.classroomId),a=(t.lrn||"").trim().toLowerCase(),r=(t.id||"").trim().toLowerCase(),o=t.name.trim().toLowerCase().replace(/\s+/g,"_");return s&&a?`${s}|lrn:${a}`:s&&r?`${s}|id:${r}`:a?`lrn:${a}`:r&&o?`id:${r}|name:${o}`:r?`id:${r}`:s&&o?`${s}|name:${o}`:`name:${o||"unknown"}`}function oi(t,s){const a=new Map;return t.forEach(r=>{a.set(gr(r),r)}),s.forEach(r=>{const o=gr(r),n=a.get(o);if(!n){a.set(o,r);return}const i=[n.riskLevel,r.riskLevel].includes("high")?"high":[n.riskLevel,r.riskLevel].includes("medium")?"medium":"low",l=Ct({metadata:n.classMetadata,classSectionId:n.classSectionId||r.classSectionId,className:n.className||r.className,grade:n.grade||r.grade,gradeLevel:n.gradeLevel||r.gradeLevel,classification:n.classification||r.classification,strand:n.strand||r.strand,section:n.section||r.section,managerId:n.managerId||r.managerId,managerName:n.managerName||r.managerName});a.set(o,{...n,lrn:n.lrn||r.lrn,classSectionId:l.classSectionId||n.classSectionId||r.classSectionId,classroomId:n.classroomId||r.classroomId,className:l.className||n.className||r.className,grade:l.grade||n.grade||r.grade,gradeLevel:l.gradeLevel||n.gradeLevel||r.gradeLevel,classification:l.classification||n.classification||r.classification,strand:l.strand||n.strand||r.strand,section:l.section||n.section||r.section,managerId:l.managerId||n.managerId||r.managerId,managerName:l.managerName||n.managerName||r.managerName,classMetadata:l,avgScore:r.avgScore>0?r.avgScore:n.avgScore,attendance:r.attendance>0?r.attendance:n.attendance,engagementScore:r.engagementScore>0?r.engagementScore:n.engagementScore,assignmentCompletion:r.assignmentCompletion>0?r.assignmentCompletion:n.assignmentCompletion,weakestTopic:n.weakestTopic&&n.weakestTopic!=="N/A"?n.weakestTopic:r.weakestTopic,riskLevel:i,struggles:n.struggles.length>0?n.struggles:r.struggles,hasRegisteredAccount:n.hasRegisteredAccount===!0||r.hasRegisteredAccount===!0?!0:n.hasRegisteredAccount??r.hasRegisteredAccount,source:n.source==="registered"&&r.source==="import"||n.source==="import"&&r.source==="registered"||n.source==="both"||r.source==="both"?"both":n.source||r.source,accountUid:n.accountUid||r.accountUid,email:n.email||r.email})}),Array.from(a.values())}const oh=({onLogout:t,onOpenProfile:s,onOpenSettings:a})=>{const{currentUser:r,userProfile:o}=hs(),[n,i]=u.useState("dashboard"),[l,c]=u.useState(!1),[d,m]=u.useState(!1),[p,h]=u.useState(!1),[b,S]=u.useState(!1),[k,N]=u.useState(!1),[v,g]=u.useState(!1),[I,z]=u.useState(!1),R=["streak_reminder","daily_checkin","streak_milestone","achievement_unlocked","level_up","xp_earned","quiz_result"],{notifications:W}=pi(),f=W.filter(M=>!M.isRead&&!R.includes(M.type)).length,[C,w]=u.useState(null),[$,A]=u.useState(null),[y,q]=u.useState(!1),[J,re]=u.useState(!1),[le,ne]=u.useState(!1),[be,Ie]=u.useState(!1),[de,fe]=u.useState([]),[H,ee]=u.useState([]),oe=u.useMemo(()=>r?.uid?de.filter(M=>M.managerId===r.uid||M.classMetadata?.managerId===r.uid):de,[de,r?.uid]),[Re,Fe]=u.useState([]),[Pe,G]=u.useState(""),[te,E]=u.useState(!0),[Y,V]=u.useState(!1),[pe,D]=u.useState(0),[j,_]=u.useState([]),[T,Q]=u.useState(!1),[ue,ce]=u.useState(null),[ae,Ce]=u.useState(null),Ne=o?.name||"Teacher",Je=u.useRef(new Map);u.useEffect(()=>{const M=()=>S(window.innerWidth<1024);return M(),window.addEventListener("resize",M),()=>window.removeEventListener("resize",M)},[]),u.useEffect(()=>{if(!r)return;const M=r.uid;let F=!0,ve;return(async()=>{E(!0);try{const qe=await ll(M);let je=qe.map(Xx);const yt=await Ju(M).catch(()=>[]),lt=new Map;yt.forEach(P=>{const X=ct(P.classSectionId);X&<.set(X,P)}),je=je.map(P=>{const X=lt.get(ct(P.classSectionId));if(!X)return P;const Ee=Ct({metadata:P.classMetadata,classSectionId:X.classSectionId||P.classSectionId,className:X.className||P.name,grade:X.grade||P.classMetadata?.grade,gradeLevel:X.gradeLevel||P.classMetadata?.gradeLevel,classification:X.classification||P.classMetadata?.classification,strand:X.strand||P.classMetadata?.strand,section:X.section||P.classMetadata?.section,schoolYear:X.schoolYear||P.classMetadata?.schoolYear,ownerTeacherId:X.ownerTeacherId||P.classMetadata?.ownerTeacherId,ownerTeacherName:X.ownerTeacherName||P.classMetadata?.ownerTeacherName,managerId:X.managerId||P.classMetadata?.managerId,managerName:X.managerName||P.classMetadata?.managerName});return{...P,name:Ee.className||P.name,classSectionId:Ee.classSectionId||P.classSectionId,classMetadata:Ee,gradeLevel:Ee.gradeLevel||P.gradeLevel,classification:Ee.classification||P.classification,strand:Ee.strand||P.strand,managerId:Ee.managerId||P.managerId,managerName:Ee.managerName||P.managerName}});const se=new Map,rt=new Map;qe.forEach(P=>{const X=Ct({metadata:P.classMetadata,classSectionId:P.classSectionId,className:P.name,grade:P.grade,gradeLevel:P.gradeLevel,classification:P.classification,strand:P.strand,section:P.section,schoolYear:P.schoolYear,ownerTeacherId:P.ownerTeacherId||P.teacherId,ownerTeacherName:P.ownerTeacherName,adviserTeacherId:P.adviserTeacherId||P.teacherId,adviserTeacherName:P.adviserTeacherName,managerId:P.managerId,managerName:P.managerName});se.set(P.id,X.className||P.name),rt.set(P.id,X);const Ee=ct(P.classSectionId);if(Ee){const Oe=lt.get(Ee),Pt=Ct({metadata:X,classSectionId:Oe?.classSectionId||Ee,className:Oe?.className||X.className,grade:Oe?.grade||X.grade,gradeLevel:Oe?.gradeLevel||X.gradeLevel,classification:Oe?.classification||X.classification,strand:Oe?.strand||X.strand,section:Oe?.section||X.section,schoolYear:Oe?.schoolYear||X.schoolYear,ownerTeacherId:Oe?.ownerTeacherId||X.ownerTeacherId,ownerTeacherName:Oe?.ownerTeacherName||X.ownerTeacherName,managerId:Oe?.managerId||X.managerId,managerName:Oe?.managerName||X.managerName});se.set(Ee,Pt.className||P.name),rt.set(Ee,Pt)}});const nt=P=>{const X=ct(P.classSectionId||P.classroomId);if(!X)return P;const Ee=rt.get(X);if(!Ee)return P;const Oe=Ct({metadata:Ee,classSectionId:P.classSectionId||Ee.classSectionId,className:P.className||Ee.className,grade:P.grade||Ee.grade,gradeLevel:P.gradeLevel||Ee.gradeLevel,classification:P.classification||Ee.classification,strand:P.strand||Ee.strand,section:P.section||Ee.section,managerId:P.managerId||Ee.managerId,managerName:P.managerName||Ee.managerName});return{...P,className:Oe.className||P.className,grade:Oe.grade||P.grade,gradeLevel:Oe.gradeLevel||P.gradeLevel,classification:Oe.classification||P.classification,strand:Oe.strand||P.strand,section:Oe.section||P.section,classSectionId:Oe.classSectionId||P.classSectionId,classMetadata:Oe,managerId:Oe.managerId||P.managerId,managerName:Oe.managerName||P.managerName}},ut=(P,X,Ee)=>se.get(P)||(X?se.get(X):void 0)||Ee||"Unknown",ws=Array.from(new Set([...yt.map(P=>P.classSectionId),...qe.map(P=>P.classSectionId).filter(Boolean),...je.map(P=>P.classSectionId).filter(Boolean)].map(P=>(P||"").trim()).filter(P=>!!P))),[Xs,_s]=await Promise.all([jn(M).catch(P=>(console.warn("[TeacherDashboard] managed-student fetch failed:",P),[])),Vu(M,ws).catch(P=>(console.warn("[TeacherDashboard] registered-student fetch failed:",P),[]))]);let Oa=_s;if(_s.length===0&&Xs.length===0)try{const{collection:P,query:X,where:Ee,getDocs:Oe}=await Ss(async()=>{const{collection:Bt,query:Ye,where:fa,getDocs:ga}=await import("./vendor-firebase-firestore-CNv3xXal.js");return{collection:Bt,query:Ye,where:fa,getDocs:ga}},__vite__mapDeps([2,3])),{db:Pt}=await Ss(async()=>{const{db:Bt}=await import("./index-BufUS6SI.js").then(Ye=>Ye.b7);return{db:Bt}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11])),De=X(P(Pt,"users"),Ee("role","==","student"));Oa=(await Oe(De)).docs.map(Bt=>{const Ye=Bt.data();return{uid:Bt.id,name:String(Ye.name||Ye.displayName||"").trim()||"Student",email:String(Ye.email||"").trim(),lrn:Ye.lrn?String(Ye.lrn).trim():void 0,photo:Ye.photo?String(Ye.photo).trim():Ye.photoURL?String(Ye.photoURL).trim():void 0,grade:Ye.grade?String(Ye.grade).trim():void 0,section:Ye.section?String(Ye.section).trim():void 0,classSectionId:Ye.classSectionId?String(Ye.classSectionId).trim():void 0,adviserTeacherId:Ye.adviserTeacherId?String(Ye.adviserTeacherId).trim():void 0,role:"student",createdAt:Ye.createdAt||void 0}}).filter(Bt=>Bt.name!=="Student"||Bt.email)}catch(P){console.warn("[TeacherDashboard] fallback all-students fetch failed:",P)}const Js=new Map,Hs=new Map,Pa=new Map;Xs.forEach(P=>{Js.set(P.id,P),P.lrn&&Hs.set(P.lrn.trim().toLowerCase(),P);const X=Ro(P.name),Ee=ct(P.classSectionId||P.classroomId);X&&Pa.set(`${X}|${Ee}`,P)});const Ba=new Set,Ha=Oa.map(P=>{const X=Wu(P),Ee=(P.lrn||"").trim().toLowerCase(),Oe=Ro(P.name),Pt=ct(P.classSectionId);let De;if(Js.has(P.uid))De=Js.get(P.uid);else if(Ee&&Hs.has(Ee))De=Hs.get(Ee);else if(Oe){const Ye=`${Oe}|${Pt}`;De=Pa.get(Ye)}if(De){Ba.add(De.id);const Ye={...X,id:P.uid,accountUid:P.uid,email:X.email||De.email,lrn:X.lrn||De.lrn,name:X.name||De.name,avatar:X.avatar||De.avatar,riskLevel:De.riskLevel||X.riskLevel,avgQuizScore:De.avgQuizScore||X.avgQuizScore,engagementScore:De.engagementScore||X.engagementScore,attendance:De.attendance||X.attendance,assignmentCompletion:De.assignmentCompletion||X.assignmentCompletion,weakestTopic:De.weakestTopic||X.weakestTopic,struggles:De.struggles||X.struggles,lastActive:De.lastActive||X.lastActive,wri:De.wri??null,riskStatus:De.riskStatus??null,riskUpdatedAt:De.riskUpdatedAt??null,diagnosticScore:De.diagnosticScore??null,externalGradesAvg:De.externalGradesAvg??null,systemPerformanceAvg:De.systemPerformanceAvg??null,riskHistory:De.riskHistory,grade:X.grade||De.grade,gradeLevel:X.gradeLevel||De.gradeLevel,section:X.section||De.section,classSectionId:X.classSectionId||De.classSectionId,classroomId:X.classroomId||De.classroomId,classMetadata:De.classMetadata||X.classMetadata,hasRegisteredAccount:!0,source:"both"},fa=ct(Ye.classSectionId||Ye.classroomId),ga=ut(Ye.classroomId||"",fa,Ye.className);return nt(Hr(Ye,ga))}const Ga=ct(X.classSectionId||X.classroomId),Bt=ut(X.classroomId||"",Ga,X.className);return nt(Hr(X,Bt))}),Ua=Xs.filter(P=>!Ba.has(P.id)).map(P=>{const X={...P,hasRegisteredAccount:!1,source:"import"},Ee=ct(X.classSectionId||X.classroomId),Oe=ut(X.classroomId,Ee,X.className);return nt(Hr(X,Oe))}),Us=[...Ha,...Ua];if(!F)return;fe(P=>je.length===0&&P.length>0?P:je),ee(P=>Us.length===0&&P.length>0?P:Us),xt.getImportedClassOverview({limit:3e3,forceRefresh:pe>0}).then(P=>{F&&(P.warnings.length>0&&console.warn("Imported class overview warnings:",P.warnings.join(" ")),fe(X=>ni(X,P.classrooms.map(Jx))),ee(X=>{if(X.length===0)return X;const Ee=P.students.map(Zx),Oe=new Set;X.forEach(De=>Oe.add(gr(De)));const Pt=Ee.filter(De=>Oe.has(gr(De)));return Pt.length===0?X:oi(X,Pt)}))}).catch(P=>{console.warn("Imported class overview merge unavailable:",P)});const ha=qe.map(P=>P.id);ha.length>0&&(ve=em(ha,P=>{F&&Fe(P.map(X=>({id:X.id,student:X.studentName,action:X.action,topic:X.topic,time:Cl(X.timestamp.toDate()),type:X.type})))}))}catch(qe){console.error("Failed to load teacher data:",qe),ie.error("Failed to load dashboard data")}finally{E(!1)}})(),()=>{F=!1,ve&&ve()}},[r,pe]),u.useEffect(()=>{if(!r)return;let M=!0;return Zu("",80).then(F=>{M&&_(F)}).catch(F=>{console.warn("Failed to load teacher directory options:",F)}),()=>{M=!1}},[r]),u.useEffect(()=>{if(H.length===0)return;(async()=>{if(H.length===0){G("");return}V(!0);try{const F=H.map(we=>({name:we.name,engagementScore:we.engagementScore,avgQuizScore:we.avgScore,attendance:we.attendance,riskLevel:we.riskLevel})),ve=await xt.getDailyInsight({students:F});G(ve.insight)}catch{G(`${H.filter(F=>F.riskLevel==="high").length} students are at high risk of falling behind. Review their progress in the analytics view.`)}finally{V(!1)}})()},[H]);const $e=de.reduce((M,F)=>M+F.studentCount,0),Ge=H.filter(M=>M.riskLevel==="high").length,ft=(()=>{const M=H.map(F=>F.avgScore).filter(F=>F>0);return M.length>0?Math.round(M.reduce((F,ve)=>F+ve,0)/M.length):0})(),Nt=[{name:"High Risk",value:H.filter(M=>M.riskLevel==="high").length,color:"#FF8B8B"},{name:"Medium Risk",value:H.filter(M=>M.riskLevel==="medium").length,color:"#F08386"},{name:"Low Risk",value:H.filter(M=>M.riskLevel==="low").length,color:"#75D06A"}],dt={};H.forEach(M=>{M.weakestTopic&&M.weakestTopic!=="N/A"&&(dt[M.weakestTopic]||(dt[M.weakestTopic]={total:0,sum:0}),dt[M.weakestTopic].total+=1,dt[M.weakestTopic].sum+=M.avgScore)});const jt=Object.entries(dt).map(([M,F])=>({topic:M,score:Math.round(F.sum/F.total)})).sort((M,F)=>M.score-F.score).slice(0,6),Lt=M=>{w(M),i("analytics")},rs=M=>{A(M),i("intervention")},Ts=()=>{A(null),i("analytics")},bs=()=>{w(null),A(null),i("dashboard")},Bs=async(M,F)=>{if(!r){ie.error("Unable to assign manager: teacher context is missing.");return}const ve=xs(M.classMetadata?.className||M.name),we=Ct({metadata:M.classMetadata,classSectionId:M.classSectionId,className:M.name,grade:M.classMetadata?.grade||ve.grade,gradeLevel:M.classMetadata?.gradeLevel,classification:M.classMetadata?.classification,strand:M.classMetadata?.strand,section:M.classMetadata?.section||ve.section,schoolYear:M.classMetadata?.schoolYear||String(new Date().getFullYear()),ownerTeacherId:M.classMetadata?.ownerTeacherId||r.uid,ownerTeacherName:M.classMetadata?.ownerTeacherName||Ne,adviserTeacherId:M.classMetadata?.adviserTeacherId||r.uid,adviserTeacherName:M.classMetadata?.adviserTeacherName||Ne,managerId:F.uid,managerName:F.name}),qe=we.classSectionId||Ft(we.grade||ve.grade,we.section||ve.section);if(!qe){ie.error("Unable to assign manager: missing class section ID.");return}Q(!0);try{await cl({classSectionId:qe,className:we.className||M.name,grade:we.grade||ve.grade,gradeLevel:we.gradeLevel||gs(we.grade||ve.grade)||we.grade||ve.grade,classification:we.classification||xa(we.gradeLevel||we.grade)||void 0,strand:we.strand||pa(we.className,we.section)||void 0,section:we.section||ve.section,schoolYear:we.schoolYear||String(new Date().getFullYear()),ownerTeacherId:we.ownerTeacherId||r.uid,ownerTeacherName:we.ownerTeacherName||Ne,managerId:F.uid,managerName:F.name});const je=Ct({metadata:we,classSectionId:qe,managerId:F.uid,managerName:F.name}),yt=ct(qe);fe(lt=>lt.map(se=>ct(se.classSectionId)!==yt?se:{...se,name:je.className||se.name,classSectionId:je.classSectionId||se.classSectionId,classMetadata:je,gradeLevel:je.gradeLevel||se.gradeLevel,classification:je.classification||se.classification,strand:je.strand||se.strand,managerId:F.uid,managerName:F.name})),ee(lt=>lt.map(se=>{if(ct(se.classSectionId||se.classroomId)!==yt)return se;const nt=Ct({metadata:se.classMetadata,classSectionId:je.classSectionId||se.classSectionId,className:se.className||je.className,grade:se.grade||je.grade,gradeLevel:se.gradeLevel||je.gradeLevel,classification:se.classification||je.classification,strand:se.strand||je.strand,section:se.section||je.section,managerId:F.uid,managerName:F.name});return{...se,classMetadata:nt,gradeLevel:nt.gradeLevel||se.gradeLevel,classification:nt.classification||se.classification,strand:nt.strand||se.strand,managerId:F.uid,managerName:F.name}})),w(lt=>!lt||ct(lt.classSectionId)!==yt?lt:{...lt,classMetadata:je,managerId:F.uid,managerName:F.name,gradeLevel:je.gradeLevel||lt.gradeLevel,classification:je.classification||lt.classification,strand:je.strand||lt.strand}),ie.success(`Assigned ${F.name} as section manager.`)}catch(je){console.error("Failed to assign class manager:",je),ie.error(je instanceof Error?je.message:"Failed to assign class manager")}finally{Q(!1)}},ns=u.useCallback(M=>{ce({rosterId:M.id,name:M.name,lrn:M.lrn,email:M.email,grade:M.grade,section:M.section,classSectionId:M.classSectionId})},[]),vs=u.useCallback(M=>{ee(F=>F.map(ve=>ve.id===M.rosterId?{...ve,hasRegisteredAccount:!0,source:"both",accountUid:M.uid,email:M.email||ve.email}:ve)),D(F=>F+1)},[]),os=u.useCallback(async(M,F)=>{if(!r){ie.error("Cannot reassign section without an authenticated teacher.");return}const ve=r.uid,we=(F.classSectionId||"").trim();if(!we){ie.error("Pick a target section first.");return}Ce(M.id);try{await qu({studentId:M.accountUid||M.id,isRegisteredAccount:!!M.hasRegisteredAccount,newClassSectionId:we,newGrade:F.grade,newSection:F.section,previousClassSectionId:M.classSectionId,teacherId:ve,teacherName:Ne,schoolYear:M.classMetadata?.schoolYear||String(new Date().getFullYear())}),ee(qe=>qe.map(je=>{if(je.id!==M.id)return je;const yt=Ct({metadata:je.classMetadata,classSectionId:we,className:je.className,grade:F.grade,section:F.section});return{...je,grade:F.grade,section:F.section,classSectionId:we,classroomId:we,classMetadata:yt}})),ie.success(`Moved ${M.name} to ${F.grade} - ${F.section}.`)}catch(qe){console.error("Section reassignment failed:",qe),ie.error(qe instanceof Error?qe.message:"Failed to reassign section.")}finally{Ce(null)}},[r,Ne]),L=u.useCallback(async M=>{if(!r||!window.confirm(`Remove ${M.name} from this class? This cannot be undone.`))return;const F=M.classSectionId||M.classroomId||"";if(!F){ie.error("Cannot determine class section for this student.");return}try{await Ku(M.accountUid||M.id,F),ee(ve=>ve.filter(we=>we.id!==M.id)),ie.success(`Removed ${M.name} from class.`)}catch(ve){console.error("Remove student failed:",ve),ie.error("Failed to remove student.")}},[r]);u.useEffect(()=>{const M=()=>{const F=window.innerWidth<1024;S(F),F?c(!1):h(!1)};return M(),window.addEventListener("resize",M),()=>window.removeEventListener("resize",M)},[]),u.useEffect(()=>{b&&h(!1)},[n,b]);const me=M=>{i(M),w(null),A(null)},We=u.useMemo(()=>{if(!C)return;if(C.classMetadata?.classSectionId)return C.classMetadata.classSectionId||void 0;if(C.classSectionId)return C.classSectionId;const M=xs(C.classMetadata?.className||C.name);return Ft(M.grade,M.section)||void 0},[C]),B=u.useMemo(()=>C||null,[C]),kt=u.useMemo(()=>{if(!B)return;const M=de.findIndex(F=>F.id===B.id);return hr[Math.max(0,M)%hr.length]},[B,de]),Me=u.useMemo(()=>{if(!B)return H;const M=(B.id||"").trim().toLowerCase(),F=ct(B.classSectionId),ve=(B.name||"").trim().toLowerCase();return H.filter(we=>{const qe=ct(we.classroomId),je=ct(we.classSectionId),yt=(we.className||"").trim().toLowerCase();return F&&(je===F||qe===F)||M&&(qe===M||je===M)||ve&&yt===ve})},[B,H]);return te?e.jsx(Gl,{message:"Loading dashboard..."}):e.jsxs("div",{className:"relative flex h-screen w-full bg-background overflow-hidden",children:[b&&p&&e.jsx("button",{"aria-label":"Close navigation",className:"fixed inset-0 z-30 bg-slate-900/40 backdrop-blur-[1px]",onClick:()=>h(!1)}),e.jsxs(Le.aside,{initial:!1,animate:{width:b?280:l&&!d?80:280,x:b?p?0:-300:0},transition:{type:"spring",stiffness:360,damping:34},onMouseEnter:()=>!b&&l&&m(!0),onMouseLeave:()=>m(!1),className:"fixed inset-y-0 left-0 z-40 bg-[#f7f9fc] rounded-3xl border border-[#dde3eb] flex flex-col shadow-sm lg:static lg:z-auto p-5",children:[e.jsxs("div",{className:`mb-8 flex items-center ${l&&!d?"justify-center":"justify-between"}`,children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-12 h-12 bg-gradient-to-r from-[#7274ED] to-[#9956DE] rounded-2xl flex items-center justify-center shadow-md flex-shrink-0",children:e.jsx("img",{src:"/avatar/avatar_icon.png",alt:"MathPulse AI",className:"w-10 h-10 object-contain drop-shadow-md"})}),(!l||d)&&e.jsx("div",{children:e.jsx("h1",{className:"text-base font-semibold font-display text-[#0a1628] whitespace-nowrap",children:"MathPulse AI"})})]}),!b&&(!l||d)&&e.jsx(Le.button,{whileHover:{scale:1.1},whileTap:{scale:.95},onClick:()=>c(!l),className:"p-2 hover:bg-[#dde3eb] rounded-lg transition-colors text-[#5a6578]","aria-label":l?"Expand sidebar":"Collapse sidebar",children:l?e.jsx(Ms,{size:20}):e.jsx(zs,{size:20})}),b&&e.jsx("button",{onClick:()=>h(!1),className:"p-2 hover:bg-[#dde3eb] rounded-lg transition-colors text-[#5a6578]","aria-label":"Close navigation",children:e.jsx(Xt,{size:20})})]}),e.jsxs("nav",{className:"flex-1 space-y-5",children:[e.jsxs("div",{children:[l&&!d?e.jsx("div",{className:"px-4 mb-2 flex items-center gap-2",children:e.jsx("div",{className:"flex-1 h-[1px] bg-[#dde3eb]"})}):e.jsx("p",{className:"px-4 mb-2 text-[10px] font-semibold text-[#5a6578] uppercase tracking-widest",children:"Overview"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(Es,{icon:tc,label:"Dashboard",active:n==="dashboard",collapsed:l&&!d,onClick:bs,forceExpanded:b}),e.jsx(Es,{icon:Ls,label:"Class Analytics",active:n==="analytics"||n==="intervention",collapsed:l&&!d,onClick:()=>me("analytics"),forceExpanded:b})]})]}),e.jsxs("div",{children:[l&&!d?e.jsx("div",{className:"px-4 mb-2 flex items-center gap-2",children:e.jsx("div",{className:"flex-1 h-[1px] bg-[#dde3eb]"})}):e.jsx("p",{className:"px-4 mb-2 text-[10px] font-semibold text-[#5a6578] uppercase tracking-widest",children:"Students"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(Es,{icon:ms,label:"Topic Mastery",active:n==="topic_mastery",collapsed:l&&!d,onClick:()=>me("topic_mastery"),forceExpanded:b}),e.jsx(Es,{icon:us,label:"Competency",active:n==="competency",collapsed:l&&!d,onClick:()=>me("competency"),forceExpanded:b})]})]}),e.jsxs("div",{children:[l&&!d?e.jsx("div",{className:"px-4 mb-2 flex items-center gap-2",children:e.jsx("div",{className:"flex-1 h-[1px] bg-[#dde3eb]"})}):e.jsx("p",{className:"px-4 mb-2 text-[10px] font-semibold text-[#5a6578] uppercase tracking-widest",children:"Tools"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(Es,{icon:sc,label:"Data Import",active:n==="import",collapsed:l&&!d,onClick:()=>i("import"),forceExpanded:b}),e.jsx(Es,{icon:qr,label:"AI Quiz Maker",active:n==="quiz_maker",collapsed:l&&!d,onClick:()=>i("quiz_maker"),forceExpanded:b}),e.jsx(Es,{icon:Gt,label:"Question Bank",active:n==="question_bank",collapsed:l&&!d,onClick:()=>i("question_bank"),forceExpanded:b}),e.jsx(Es,{icon:nr,label:"Calendar",active:n==="calendar",collapsed:l&&!d,onClick:()=>i("calendar"),forceExpanded:b})]})]})]}),e.jsxs("div",{className:"space-y-2 border-t border-[#dde3eb] pt-4",children:[e.jsxs(Le.button,{whileHover:{x:2},whileTap:{scale:.98},className:`w-full flex items-center gap-3 px-4 py-3 rounded-2xl text-[#5a6578] font-semibold border border-transparent hover:bg-[#dde3eb] hover:border-[#dde3eb] hover:text-[#0a1628] transition-all duration-200 whitespace-nowrap ${l&&!d?"justify-center":""}`,onClick:a,title:l&&!d?"Settings":"",children:[e.jsx(ac,{size:18,strokeWidth:2,className:"flex-shrink-0"}),(!l||d)&&e.jsx("span",{className:"font-body text-xs",children:"Settings"})]}),e.jsx("div",{className:"text-[#5a6578]",children:e.jsx(rc,{onClick:()=>N(!0),collapsed:l&&!d})})]})]}),e.jsxs("div",{className:"flex-1 flex overflow-hidden bg-gradient-to-br from-[#eef2ff] via-[#f5f3ff] to-[#fff7ed]",children:[e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[["dashboard","analytics","intervention","competency","topic_mastery","calendar","notifications","question_bank","import","quiz_maker"].includes(n)&&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-row items-center justify-between gap-2 mb-0",children:[e.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-2",children:[b&&e.jsx("button",{onClick:()=>h(!0),className:"mt-1 p-2 rounded-lg border border-border text-muted-foreground hover:text-[#9956DE] hover:border-[#9956DE]/30 hover:bg-[#9956DE]/12 transition-colors","aria-label":"Open navigation",children:e.jsx(Ql,{size:18})}),e.jsxs("div",{children:[e.jsxs("h1",{className:"text-lg sm:text-[26px] font-bold text-[#1e293b] tracking-tight leading-tight truncate",children:[n==="dashboard"&&"Teacher Dashboard",n==="analytics"&&"Class Analytics",n==="intervention"&&"Intervention Center",n==="competency"&&"Student Competency",n==="topic_mastery"&&"Topic Mastery",n==="calendar"&&"Academic Calendar",n==="notifications"&&"Notifications",n==="question_bank"&&"Question Bank",n==="import"&&"Data Import",n==="quiz_maker"&&"AI Quiz Maker"]}),e.jsxs("p",{className:"text-[13px] text-[#64748b] mt-1",children:[n==="dashboard"&&`Welcome back, ${Ne}`,n==="analytics"&&"Analyze performance and risk across your classes.",n==="intervention"&&"Identify and support students who need immediate help.",n==="competency"&&"Track individual student progress against learning goals.",n==="topic_mastery"&&"Overview of student mastery levels across different math topics.",n==="calendar"&&"Manage your schedules and academic events.",n==="notifications"&&"Stay updated with student activity and system alerts.",n==="question_bank"&&"Manage and create math questions for your quizzes.",n==="import"&&"Upload class records and materials to power AI analytics.",n==="quiz_maker"&&"Create AI-powered quizzes based on your curriculum."]})]}),n==="dashboard"&&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-[#9956DE]/12 border border-[#9956DE]/30 rounded-lg",children:[e.jsx(us,{size:13,className:"text-[#9956DE]"}),e.jsxs("span",{className:"text-xs font-display font-semibold text-[#9956DE]",children:[$e," students"]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1.5 bg-[#F08386]/12 border border-[#F08386]/30 rounded-lg",children:[e.jsx(ca,{size:13,className:"text-[#F08386]"}),e.jsxs("span",{className:"text-xs font-display font-semibold text-[#C65E63]",children:[Ge," at risk"]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1.5 bg-[#75D06A]/14 border border-[#75D06A]/35 rounded-lg",children:[e.jsx(la,{size:13,className:"text-[#75D06A]"}),e.jsxs("span",{className:"text-xs font-display font-semibold text-[#4D9F46]",children:[ft,"% avg"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsxs("div",{className:"relative group",children:[e.jsxs("button",{onClick:()=>{re(!0),q(!0)},className:"relative w-10 h-10 flex items-center justify-center bg-[#eef2ff]/80 hover:bg-[#e0e7ff] rounded-full backdrop-blur-[12px] shadow-[0_1px_4px_rgba(0,0,0,0.04)] border border-[#a5b4fc]/60 text-[#4f46e5] hover:border-[#818cf8] transition-colors cursor-pointer hover:scale-[1.02]","aria-label":"View AI Insight",children:[e.jsx(ps,{size:18}),!y&&Pe&&e.jsx("div",{className:"absolute top-2.5 right-2.5 w-2 h-2 bg-rose-500 rounded-full border border-white animate-pulse"})]}),e.jsx("span",{className:"absolute -bottom-8 left-1/2 -translate-x-1/2 text-[10px] bg-[#1e293b] text-white px-2 py-1 rounded opacity-0 group-hover:opacity-100 transition-opacity whitespace-nowrap z-50 pointer-events-none",children:"AI Insight"})]}),b&&n==="dashboard"&&e.jsx("button",{onClick:()=>Ie(M=>!M),className:`relative w-10 h-10 flex items-center justify-center rounded-full backdrop-blur-[12px] shadow-[0_1px_4px_rgba(0,0,0,0.04)] border transition-colors cursor-pointer hover:scale-[1.02] ${be?"bg-[#818cf8] border-[#6366f1] text-white":"bg-white/60 hover:bg-white/80 border-white/50 text-[#64748b] hover:text-[#1e293b]"}`,"aria-label":be?"Close calendar panel":"Open calendar panel",title:be?"Close calendar":"View calendar",children:e.jsx(nr,{size:18})}),e.jsxs("div",{className:"relative",children:[e.jsxs("button",{onClick:()=>ne(!le),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",title:"Notifications",children:[e.jsx(dr,{size:18}),f>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(Zl,{isOpen:le,onClose:()=>ne(!1),onViewAll:()=>i("notifications")})]}),n!=="dashboard"&&e.jsxs("div",{onClick:s,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("img",{src:o?.photo||`https://ui-avatars.com/api/?name=${encodeURIComponent(Ne)}&background=e0e7ff&color=4f46e5`,alt:"Profile",className:"w-full h-full object-cover"})}),e.jsx("span",{className:"text-[13px] font-semibold text-[#1e293b]",children:Ne})]})]})]})}),e.jsx("main",{className:`flex-1 flex flex-col ${n==="intervention"||n==="analytics"?"overflow-hidden":"overflow-y-auto"}`,children:e.jsxs(zt,{mode:"wait",children:[n==="dashboard"&&e.jsx(ap,{classes:oe,liveActivity:Re,onViewClass:Lt,onViewAllClasses:()=>i("analytics"),onViewActivityStudent:M=>{const F=H.find(ve=>ve.name===M);F&&rs(F)},dailyInsight:Pe,insightLoading:Y,isInsightDismissed:y,onDismissInsight:()=>q(!0),onOpenInsightModal:()=>{re(!0),q(!0)},totalStudents:$e,totalAtRisk:Ge,avgPerformance:ft,onCreateClass:()=>g(!0)}),n==="analytics"&&B&&e.jsx(op,{selectedClass:B,students:Me,allClasses:de,riskDistribution:Nt,topicPerformance:jt,onViewStudent:rs,onCreateAccount:ns,onReassignSection:os,reassignBusyId:ae,onBack:()=>w(null),teacherOptions:j,managerUpdating:T,onAssignManager:M=>Bs(B,M),onOpenNotifications:()=>i("notifications"),onOpenProfile:s,classColor:kt,insightDismissed:y,onOpenInsightModal:()=>re(!0),onAddStudents:()=>z(!0),onRemoveStudent:L}),n==="analytics"&&!B&&oe.length>0&&e.jsx(Wo,{classes:oe,onSelectClass:Lt,onOpenNotifications:()=>i("notifications"),onOpenProfile:s,insightDismissed:y,onOpenInsightModal:()=>re(!0),onCreateClass:()=>g(!0)}),n==="analytics"&&!B&&oe.length===0&&e.jsx(Le.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},exit:{opacity:0,y:-20},className:"p-6",children:e.jsxs("div",{className:"bg-card border border-border rounded-2xl p-8 shadow-sm max-w-2xl",children:[e.jsx("div",{className:"w-12 h-12 rounded-xl bg-[#9956DE]/20 text-[#9956DE] flex items-center justify-center mb-4",children:e.jsx(Ls,{size:24})}),e.jsx("h2",{className:"text-2xl font-display font-semibold text-foreground mb-2",children:"Class Analytics"}),e.jsx("p",{className:"text-sm text-muted-foreground font-body leading-relaxed mb-4",children:"No classes available yet. Create a class or import class records to unlock analytics views."}),e.jsxs(St,{onClick:()=>g(!0),className:"bg-[#9956DE] hover:bg-[#7c3aed] text-white",children:[e.jsx(da,{size:16,className:"mr-1.5"}),"Create Class"]})]})}),n==="intervention"&&$&&e.jsx(ip,{student:$,teacherId:r?.uid||"",teacherName:Ne,initialCache:Je.current.get($.id),onCacheUpdate:(M,F)=>Je.current.set(M,F),onStudentUpdated:M=>{const F=$?ln($):null;A(M),ee(ve=>ve.map(we=>{const qe=ln(we),je=F?qe===F:!1,yt=we.id===M.id&&ct(we.classSectionId)===ct(M.classSectionId);return je||yt?M:we}))},onBack:Ts,onNavigateToQuizMaker:M=>{i("quiz_maker"),M&&sessionStorage.setItem("quizMakerInitialTab",M)}}),n==="topic_mastery"&&e.jsx(Tm,{classSectionId:We,onOpenNotifications:()=>i("notifications"),onOpenProfile:s}),n==="competency"&&B&&e.jsx(Mm,{classSectionId:We,className:C?.name,fallbackStudents:H,onBack:()=>w(null),onOpenNotifications:()=>i("notifications"),onOpenProfile:s,insightDismissed:y,onOpenInsightModal:()=>re(!0)}),n==="competency"&&!B&&de.length>0&&e.jsx(Wo,{classes:oe,onSelectClass:M=>w(M),onOpenNotifications:()=>i("notifications"),onOpenProfile:s,insightDismissed:y,onOpenInsightModal:()=>re(!0),viewType:"competency"}),n==="competency"&&!B&&de.length===0&&e.jsx(sp,{icon:us,title:"Student Competency",description:"No classes available yet. Import class records to view competency breakdowns."}),n==="import"&&e.jsxs(e.Fragment,{children:[e.jsx(Qx,{classSectionId:We,className:C?.name,classMetadata:C?.classMetadata,students:H,classes:oe.map(M=>({id:M.id,name:M.name,classSectionId:M.classSectionId})),teacherId:r?.uid||"",teacherName:Ne,onStudentsUpdated:M=>ee(M),onBackToClasses:()=>i("dashboard"),onOpenNotifications:()=>i("notifications"),onOpenProfile:s,onOpenInsightModal:()=>{re(!0),q(!0)},userPhoto:o?.photo,onImportedClassRecords:M=>{const F=M.students.map(se=>tp(se,M.classSectionId,M.className,M.classMetadata)),ve=Ct({metadata:M.classMetadata,classSectionId:M.classSectionId,className:M.className}),we=ve.classSectionId||"imported_class",qe=ve.className||"Imported Class",je=F.filter(se=>se.riskLevel==="high").length,yt=F.length>0?Math.round(F.reduce((se,rt)=>se+rt.avgScore,0)/F.length):0,lt={id:we,name:qe,classSectionId:we,classMetadata:{...ve,classSectionId:we,className:qe},schedule:"Mon-Fri",studentCount:F.length,avgScore:yt,atRiskCount:je,riskLevel:je>=5?"high":je>=2?"medium":"low"};ee(se=>oi(se,F)),fe(se=>ni(se,[lt]))},onDataChanged:()=>D(M=>M+1)}),e.jsx("div",{className:"mt-6",children:e.jsx(Wx,{teacherId:r?.uid||""})})]}),n==="notifications"&&e.jsx(Lm,{liveActivity:Re,atRiskStudents:H.filter(M=>M.riskLevel==="high").map(M=>({name:M.name,riskLevel:M.riskLevel,weakestTopic:M.weakestTopic})),onOpenNotifications:()=>i("notifications"),onOpenProfile:s,onOpenInsightModal:()=>{re(!0),q(!0)},userPhoto:o?.photo,teacherName:Ne}),n==="calendar"&&e.jsx(qm,{classes:de,teacherId:r?.uid}),n==="quiz_maker"&&e.jsx(fl,{onBack:()=>{const M=sessionStorage.getItem("quizMakerReturnTo");sessionStorage.removeItem("quizMakerReturnTo"),sessionStorage.removeItem("quizMakerInitialTab"),i(M==="intervention"?"intervention":"dashboard")},onOpenNotifications:()=>i("notifications"),onOpenProfile:s,onOpenInsightModal:()=>{re(!0),q(!0)},userPhoto:o?.photo,teacherName:Ne}),n==="question_bank"&&e.jsx(Cm,{onOpenNotifications:()=>i("notifications"),onOpenProfile:s,onOpenInsightModal:()=>{re(!0),q(!0)},userPhoto:o?.photo,teacherName:Ne})]})})]}),n==="dashboard"&&!b&&e.jsx(li,{onViewCalendar:()=>i("calendar"),onOpenProfile:s,userProfile:o,teacherName:Ne,liveActivity:Re})]}),e.jsx(zt,{children:b&&n==="dashboard"&&be&&e.jsxs(e.Fragment,{children:[e.jsx(Le.button,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.2},className:"fixed inset-0 z-40 bg-slate-900/40 backdrop-blur-[2px]","aria-label":"Close calendar panel",onClick:()=>Ie(!1)},"cal-backdrop"),e.jsx(Le.div,{initial:{x:"100%"},animate:{x:0},exit:{x:"100%"},transition:{type:"spring",stiffness:320,damping:32},className:"fixed top-0 right-0 bottom-0 z-50 w-[300px] max-w-[85vw] shadow-2xl",children:e.jsx(li,{onViewCalendar:()=>{i("calendar"),Ie(!1)},onOpenProfile:()=>{s?.(),Ie(!1)},userProfile:o,teacherName:Ne,liveActivity:Re})},"cal-drawer")]})}),e.jsx(zt,{children:J&&e.jsx("div",{className:"fixed inset-0 bg-slate-900/40 backdrop-blur-sm z-50 flex items-center justify-center p-4",children:e.jsxs(Le.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.95},className:"bg-white rounded-2xl shadow-xl w-full max-w-lg overflow-hidden border border-slate-200",children:[e.jsxs("div",{className:"p-4 border-b border-slate-100 flex items-center justify-between bg-slate-50/50",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-indigo-100 flex items-center justify-center text-indigo-600",children:e.jsx(ps,{size:16})}),e.jsx("h3",{className:"font-semibold text-slate-800",children:"Detailed AI Insight"})]}),e.jsx("button",{onClick:()=>{re(!1)},className:"p-2 text-slate-400 hover:text-slate-600 hover:bg-slate-100 rounded-full transition-colors",children:e.jsx(Xt,{size:18})})]}),e.jsx("div",{className:"p-6",children:e.jsx("div",{className:"text-sm text-slate-600 leading-relaxed",children:e.jsx(kc,{children:Pe?.replace(/[*_]*\s*\(?Word\s*count\s*:\s*[*_]*\s*\d+\)?\s*[*_]*/gi,"").trim()||`**${Ge} students (${$e>0?Math.round(Ge/$e*100):0}%)** are currently at high risk of falling behind in recent topics. Review their progress in the analytics view to plan interventions.`})})}),e.jsx("div",{className:"p-4 border-t border-slate-100 bg-slate-50 flex justify-end gap-2",children:e.jsx("button",{onClick:()=>{re(!1)},className:"px-4 py-2 text-sm font-medium text-slate-600 hover:text-slate-800 hover:bg-slate-200 rounded-lg transition-colors",children:"Minimize to Menu"})})]})})}),e.jsx(Yl,{isOpen:k,onClose:()=>N(!1),onConfirm:t,title:"Logout",message:"Are you sure you want to logout?",confirmText:"Logout",cancelText:"Cancel"}),e.jsx(tm,{open:v,onClose:()=>g(!1),onCreated:()=>D(M=>M+1),teacherName:Ne}),e.jsx(sm,{open:I,onClose:()=>z(!1),onAdded:()=>D(M=>M+1),grade:B?.gradeLevel||B?.classMetadata?.grade||"Grade 11",section:B?.classMetadata?.section||B?.name?.split(" - ")[1]||"",teacherName:Ne,existingStudentUids:Me.map(M=>M.id)}),e.jsx(Kx,{isOpen:!!ue,onClose:()=>ce(null),seed:ue,adviserTeacherId:r?.uid||"",adviserTeacherName:Ne,schoolYear:ue?H.find(M=>M.id===ue.rosterId)?.classMetadata?.schoolYear||String(new Date().getFullYear()):void 0,onCreated:vs})]})},Es=({icon:t,label:s,active:a,collapsed:r,forceExpanded:o=!1,onClick:n})=>e.jsxs(Le.button,{onClick:n,whileHover:{x:2},whileTap:{scale:.98},className:`w-full flex items-center gap-3 px-4 py-3 rounded-2xl cursor-pointer transition-all duration-200 border whitespace-nowrap ${r&&!o?"justify-center":""} ${a?"bg-[#9956DE]/12 border-[#9956DE]/30 shadow-sm text-[#9956DE]":"bg-transparent border-transparent text-[#5a6578] hover:bg-[#dde3eb] hover:border-[#dde3eb] hover:text-[#0a1628]"}`,children:[e.jsx(t,{size:18,strokeWidth:a?2.5:2,className:"flex-shrink-0"}),(!r||o)&&e.jsx("span",{className:"font-body font-semibold text-xs",children:s}),a&&!r&&e.jsx(Le.div,{layoutId:"sidebar-active-indicator",className:"ml-auto w-2 h-2 rounded-full bg-[#9956DE]",transition:{type:"spring",duration:.4}})]}),sp=({icon:t,title:s,description:a})=>e.jsx(Le.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},exit:{opacity:0,y:-20},className:"p-6",children:e.jsxs("div",{className:"bg-card border border-border rounded-2xl p-8 shadow-sm max-w-2xl",children:[e.jsx("div",{className:"w-12 h-12 rounded-xl bg-[#9956DE]/20 text-[#9956DE] flex items-center justify-center mb-4",children:e.jsx(t,{size:24})}),e.jsx("h2",{className:"text-2xl font-display font-semibold text-foreground mb-2",children:s}),e.jsx("p",{className:"text-sm text-muted-foreground font-body leading-relaxed",children:a})]})}),ap=({classes:t,liveActivity:s,onViewClass:a,onViewAllClasses:r,onViewActivityStudent:o,dailyInsight:n,insightLoading:i,isInsightDismissed:l,onDismissInsight:c,onOpenInsightModal:d,totalStudents:m,totalAtRisk:p,avgPerformance:h,onCreateClass:b})=>{const S=m>0?Math.round(p/m*100):0,k=m>0?Math.round((m-p)/m*100):0;return e.jsxs(Le.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},exit:{opacity:0,y:-20},className:"p-3 sm:p-6 space-y-4",children:[!l&&n&&e.jsxs("div",{onClick:d,className:"bg-white/80 backdrop-blur-[12px] rounded-[18px] border border-white p-[14px_16px] sm:p-[18px_20px] flex flex-col sm:flex-row items-start sm:items-center gap-3 sm:gap-4 shadow-[0_1px_4px_rgba(0,0,0,0.04)] cursor-pointer hover:shadow-md transition-shadow group",children:[e.jsxs("div",{className:"relative flex-shrink-0",children:[e.jsx("div",{className:"absolute -inset-[5px] rounded-full border-2 border-[#a5b4fc] opacity-50 animate-pulse"}),e.jsx("div",{className:"w-[46px] h-[46px] rounded-full bg-[#eef2ff] border-2 border-[#c7d2fe] flex items-center justify-center text-[#4f46e5] text-xl relative overflow-hidden group-hover:scale-[1.05] transition-transform",children:e.jsx("img",{src:"/avatar/avatar_icon.png",alt:"AI Mascot",className:"w-[85%] h-[85%] object-contain"})})]}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"text-[13.5px] font-semibold text-[#1e1b4b] flex flex-wrap items-center gap-2 mb-1",children:[e.jsx(ps,{size:14,className:"text-[#818cf8]"}),"MathPulse AI insight",e.jsx("span",{className:"bg-[#fee2e2] text-[#b91c1c] text-[10px] font-semibold px-2 py-0.5 rounded-full border border-[#fca5a5]",children:"Attention needed"})]}),e.jsx("div",{className:"text-[12.5px] text-[#475569] leading-[1.55]",children:"Some students may be at risk of falling behind. Click to view detailed analysis."})]}),e.jsxs("div",{className:"flex gap-2 flex-shrink-0 self-end sm:self-auto",children:[e.jsx("button",{onClick:N=>{N.stopPropagation(),c()},className:"px-[15px] py-[7px] rounded-[10px] text-xs font-medium cursor-pointer border border-[#e2e8f0] bg-white text-[#475569] hover:bg-[#f8fafc] transition-colors",children:"Dismiss"}),e.jsx("button",{onClick:N=>{N.stopPropagation(),r()},className:"px-[15px] py-[7px] rounded-[10px] text-xs font-medium cursor-pointer border border-[#4f46e5] bg-[#4f46e5] text-white shadow-[0_2px_8px_rgba(79,70,229,0.13)] hover:bg-[#4338ca] transition-colors",children:"Review students"})]})]}),e.jsxs("div",{className:"grid grid-cols-4 gap-1.5 sm:gap-3",children:[e.jsxs("div",{className:"group relative overflow-hidden bg-[#10b981] shadow-[0_4px_16px_rgba(16,185,129,0.13)] rounded-sm sm:rounded-lg p-[10px] sm:p-[15px] text-white flex flex-col gap-[6px] sm:gap-[10px]",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-500 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-500 delay-75 ease-out"}),e.jsxs("div",{className:"relative z-10 flex justify-between items-start",children:[e.jsx("span",{className:"text-[9px] sm:text-[11px] opacity-90 leading-tight",children:"Total students"}),e.jsx("div",{className:"hidden sm:flex bg-white/20 p-1.5 rounded-lg",children:e.jsx(us,{size:15})})]}),e.jsx("div",{className:"relative z-10 text-[18px] sm:text-[26px] font-semibold tracking-tight",children:m}),e.jsxs("div",{className:"relative z-10 border-t border-white/30 pt-1.5 sm:pt-2 flex justify-between items-center text-[9px] sm:text-[10px] opacity-90",children:[e.jsx("span",{className:"hidden sm:block",children:"Added this year"}),e.jsx("span",{className:"bg-black/15 px-[5px] sm:px-[7px] py-[2px] rounded font-semibold",children:m>0?"+1":"0"})]})]}),e.jsxs("div",{className:"group relative overflow-hidden bg-[#0ea5e9] shadow-[0_4px_16px_rgba(14,165,233,0.13)] rounded-sm sm:rounded-lg p-[10px] sm:p-[15px] text-white flex flex-col gap-[6px] sm:gap-[10px]",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-500 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-500 delay-75 ease-out"}),e.jsxs("div",{className:"relative z-10 flex justify-between items-start",children:[e.jsx("span",{className:"text-[9px] sm:text-[11px] opacity-90 leading-tight",children:"Class average"}),e.jsx("div",{className:"hidden sm:flex bg-white/20 p-1.5 rounded-lg",children:e.jsx(ms,{size:15})})]}),e.jsxs("div",{className:"relative z-10 text-[18px] sm:text-[26px] font-semibold tracking-tight",children:[h,"%"]}),e.jsxs("div",{className:"relative z-10 border-t border-white/30 pt-1.5 sm:pt-2 flex justify-between items-center text-[9px] sm:text-[10px] opacity-90",children:[e.jsx("span",{className:"hidden sm:block",children:"Vs. last month"}),e.jsx("span",{className:"bg-black/15 px-[5px] sm:px-[7px] py-[2px] rounded font-semibold",children:"+2.5%"})]})]}),e.jsxs("div",{className:"group relative overflow-hidden bg-[#a855f7] shadow-[0_4px_16px_rgba(168,85,247,0.13)] rounded-sm sm:rounded-lg p-[10px] sm:p-[15px] text-white flex flex-col gap-[6px] sm:gap-[10px]",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-500 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-500 delay-75 ease-out"}),e.jsxs("div",{className:"relative z-10 flex justify-between items-start",children:[e.jsx("span",{className:"text-[9px] sm:text-[11px] opacity-90 leading-tight",children:"Engage­ment"}),e.jsx("div",{className:"hidden sm:flex bg-white/20 p-1.5 rounded-lg",children:e.jsx(bi,{size:15})})]}),e.jsxs("div",{className:"relative z-10 text-[18px] sm:text-[26px] font-semibold tracking-tight",children:[k,"%"]}),e.jsxs("div",{className:"relative z-10 border-t border-white/30 pt-1.5 sm:pt-2 flex justify-between items-center text-[9px] sm:text-[10px] opacity-90",children:[e.jsx("span",{className:"hidden sm:block",children:"Active participants"}),e.jsx("span",{className:"bg-black/15 px-[5px] sm:px-[7px] py-[2px] rounded font-semibold",children:Math.round(k/100*m)})]})]}),e.jsxs("div",{className:"group relative overflow-hidden bg-[#f97316] shadow-[0_4px_16px_rgba(249,115,22,0.13)] rounded-sm sm:rounded-lg p-[10px] sm:p-[15px] text-white flex flex-col gap-[6px] sm:gap-[10px]",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-500 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-500 delay-75 ease-out"}),e.jsxs("div",{className:"relative z-10 flex justify-between items-start",children:[e.jsx("span",{className:"text-[9px] sm:text-[11px] opacity-90 leading-tight",children:"At risk"}),e.jsx("div",{className:"hidden sm:flex bg-white/20 p-1.5 rounded-lg",children:e.jsx(br,{size:15})})]}),e.jsx("div",{className:"relative z-10 text-[18px] sm:text-[26px] font-semibold tracking-tight",children:p}),e.jsxs("div",{className:"relative z-10 border-t border-white/30 pt-1.5 sm:pt-2 flex justify-between items-center text-[9px] sm:text-[10px] opacity-90",children:[e.jsx("span",{className:"hidden sm:block",children:"Requires attention"}),e.jsxs("span",{className:"bg-black/15 px-[5px] sm:px-[7px] py-[2px] rounded font-semibold",children:[S,"%"]})]})]})]}),e.jsxs("div",{className:"bg-white/80 backdrop-blur-[12px] rounded-[18px] border border-white p-[18px_20px] shadow-[0_1px_4px_rgba(0,0,0,0.04)]",children:[e.jsxs("div",{className:"flex justify-between items-center mb-[14px]",children:[e.jsx("h2",{className:"text-[15px] font-semibold text-[#1e293b]",children:"My classes"}),e.jsx("span",{onClick:r,className:"text-[12px] text-[#10b981] font-semibold cursor-pointer hover:underline",children:"View all"})]}),e.jsxs("div",{className:"space-y-[9px]",children:[t.length===0&&e.jsxs("div",{className:"text-center py-4",children:[e.jsx("p",{className:"text-sm text-slate-500 mb-3",children:"No classes imported yet."}),b&&e.jsx("button",{onClick:b,className:"text-sm text-[#9956DE] font-semibold hover:underline",children:"+ Create a class"})]}),t.map((N,v)=>{const g=[{bg:"bg-[#f3e8ff]",text:"text-[#a855f7]",borderHover:"hover:border-[#d8b4fe]",stripe:"bg-[#a855f7]"},{bg:"bg-[#eff6ff]",text:"text-[#3b82f6]",borderHover:"hover:border-[#bfdbfe]",stripe:"bg-[#3b82f6]"},{bg:"bg-[#f0fdf4]",text:"text-[#22c55e]",borderHover:"hover:border-[#bbf7d0]",stripe:"bg-[#22c55e]"},{bg:"bg-[#fff7ed]",text:"text-[#f97316]",borderHover:"hover:border-[#fed7aa]",stripe:"bg-[#f97316]"},{bg:"bg-[#fff1f2]",text:"text-[#f43f5e]",borderHover:"hover:border-[#fecdd3]",stripe:"bg-[#f43f5e]"}],I=g[v%g.length];return e.jsxs("div",{onClick:()=>a(N),className:`relative overflow-hidden flex items-center gap-3 p-[12px_13px] pl-[16px] border border-[#f1f5f9] rounded-[14px] cursor-pointer ${I.borderHover} hover:shadow-[0_2px_10px_rgba(0,0,0,0.04)] hover:bg-[#fafbff] transition-all group`,children:[e.jsx("div",{className:`absolute left-0 top-0 bottom-0 w-[5px] ${I.stripe}`}),e.jsx("div",{className:`w-[38px] h-[38px] rounded-[10px] flex items-center justify-center flex-shrink-0 text-[17px] ${I.bg} ${I.text} group-hover:scale-110 transition-transform duration-300`,children:e.jsx(Gt,{size:18})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-[12.5px] font-medium text-[#1e293b]",children:N.name}),e.jsx("div",{className:"text-[11px] text-[#94a3b8] mt-[1px]",children:N.classification||"High School"})]}),e.jsx("div",{className:"hidden sm:block text-[12px] text-[#64748b] min-w-[65px]",children:N.schedule||"Mon-Fri"}),e.jsxs("div",{className:"hidden sm:block text-[12px] text-[#64748b] min-w-[85px]",children:[N.studentCount," students"]}),e.jsx("span",{className:`text-[10px] font-semibold px-[9px] py-[3px] rounded-[6px] ${N.riskLevel==="high"?"bg-[#fee2e2] text-[#b91c1c] border border-[#fca5a5]":N.riskLevel==="medium"?"bg-[#fffbeb] text-[#b45309] border border-[#fcd34d]":"bg-[#ecfdf5] text-[#065f46] border border-[#6ee7b7]"}`,children:N.riskLevel==="high"?"High risk":N.riskLevel==="medium"?"Medium risk":"On track"}),e.jsx(Yr,{size:16,className:"text-[#cbd5e1] ml-auto hover:text-[#64748b]"})]},N.id)})]})]})]})},rp=he.memo(({student:t,onViewStudent:s,onCreateAccount:a,onRemoveStudent:r})=>{const n=t.riskLevel==="high"?{borderLeft:"border-l-rose-500",bgAvatar:"bg-rose-50 text-rose-600 border-rose-100/50",badge:"text-rose-600 bg-rose-50",progress:"bg-rose-500"}:t.riskLevel==="medium"?{borderLeft:"border-l-amber-500",bgAvatar:"bg-amber-50 text-amber-600 border-amber-100/50",badge:"text-amber-600 bg-amber-50",progress:"bg-amber-500"}:{borderLeft:"border-l-emerald-500",bgAvatar:"bg-emerald-50 text-emerald-600 border-emerald-100/50",badge:"text-emerald-600 bg-emerald-50",progress:"bg-emerald-500"},i=t.hasRegisteredAccount===!1&&t.source==="import",l=t.hasRegisteredAccount===!0;return e.jsxs("div",{onClick:()=>s(t),className:`p-[12px] bg-white rounded-[14px] shadow-[0_1px_4px_rgba(0,0,0,0.04)] border border-[#f1f5f9] border-l-[4px] ${n.borderLeft} hover:scale-[1.02] transition-transform cursor-pointer group flex flex-col justify-between`,children:[e.jsxs("div",{className:"flex justify-between items-start mb-[10px]",children:[e.jsxs("div",{className:"flex gap-[8px] items-center min-w-0 pr-2",children:[t.avatar?e.jsx("img",{src:t.avatar,alt:t.name,className:`w-8 h-8 rounded-full border ${n.bgAvatar.split(" ")[2]} object-cover shrink-0`}):e.jsx("div",{className:`w-8 h-8 rounded-full flex items-center justify-center font-semibold text-[11px] shrink-0 border ${n.bgAvatar}`,children:t.name.substring(0,2).toUpperCase()}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("p",{className:"text-[13px] font-semibold text-[#1e293b] leading-tight truncate",children:t.name}),l&&e.jsx("span",{title:"Registered student account",className:"w-1.5 h-1.5 rounded-full bg-emerald-500 shrink-0"})]}),e.jsxs("p",{className:"text-[10px] text-[#64748b] flex items-center gap-[4px] mt-0.5 truncate",children:[e.jsx(As,{className:"w-[10px] h-[10px] shrink-0"})," ",t.lastActive||"recently"]})]})]}),e.jsxs("span",{className:`font-semibold text-[11px] px-[6px] py-[2px] rounded-[14px] shrink-0 ${n.badge}`,children:[t.avgScore,"%"]}),r&&e.jsx("button",{type:"button",onClick:c=>{c.stopPropagation(),r(t)},className:"opacity-0 group-hover:opacity-100 transition-opacity text-slate-400 hover:text-red-500 p-1 rounded shrink-0","aria-label":`Remove ${t.name} from class`,title:"Remove from class",children:e.jsx(Xt,{size:14})})]}),i&&e.jsxs("div",{className:"flex items-center justify-between gap-2 mb-2 px-2 py-1 rounded-[10px] bg-amber-50 border border-amber-100/80",children:[e.jsx("span",{className:"text-[10px] font-semibold text-amber-700 uppercase tracking-wider",children:"No Account"}),a&&e.jsxs("button",{type:"button",onClick:c=>{c.stopPropagation(),a(t)},className:"flex items-center gap-1 px-2 py-0.5 rounded-full bg-white text-amber-700 border border-amber-200 hover:bg-amber-100 text-[10px] font-semibold transition-colors","aria-label":`Create system account for ${t.name}`,children:[e.jsx("span",{"aria-hidden":!0,children:"+"}),"Create"]})]}),e.jsx("div",{className:"w-full bg-[#f1f5f9] h-1.5 rounded-full overflow-hidden mt-auto",children:e.jsx("div",{className:`h-full rounded-full ${n.progress}`,style:{width:`${t.avgScore}%`}})})]})}),np=({students:t,allClasses:s,currentClass:a,onReassignSection:r,reassignBusyId:o})=>{const[n,i]=u.useState(!1),l=u.useMemo(()=>{const d=new Map;return s.forEach(m=>{const p=(m.classSectionId||m.id||"").trim();if(!p)return;const h=(m.classMetadata?.grade||"").trim(),b=(m.classMetadata?.section||"").trim();if(!h||!b)return;const S=m.name||`${h} - ${b}`;d.set(p,{classSectionId:p,grade:h,section:b,label:S})}),Array.from(d.values()).sort((m,p)=>m.label.localeCompare(p.label))},[s]),c=u.useMemo(()=>{const d=new Map,m=[];return t.forEach(p=>{const h=(p.classSectionId||"").trim();if(!h){m.push(p);return}const b=p.section||p.className||h,S=d.get(h)||{label:b,students:[]};S.students=[...S.students,p],d.set(h,S)}),{assigned:Array.from(d.entries()).map(([p,h])=>({sectionId:p,...h})).sort((p,h)=>p.label.localeCompare(h.label)),unassigned:m}},[t]);return e.jsxs("div",{className:"bg-white/80 backdrop-blur-[12px] rounded-[18px] border border-white shadow-[0_1px_4px_rgba(0,0,0,0.04)] overflow-hidden",children:[e.jsxs("button",{type:"button",onClick:()=>i(d=>!d),className:"w-full flex items-center justify-between px-6 py-4 text-left","aria-expanded":n,children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-[15px] font-semibold text-[#1e293b]",children:"Section Management"}),e.jsxs("p",{className:"text-[12px] text-[#64748b] mt-0.5",children:["Move students between sections. Showing ",t.length," students across ",c.assigned.length," section",c.assigned.length===1?"":"s",c.unassigned.length>0?` · ${c.unassigned.length} unassigned`:"","."]})]}),e.jsx($t,{className:`w-4 h-4 text-[#64748b] transition-transform ${n?"rotate-180":""}`})]}),n&&e.jsxs("div",{className:"border-t border-[#f1f5f9] divide-y divide-[#f1f5f9]",children:[c.assigned.length===0&&c.unassigned.length===0&&e.jsx("p",{className:"text-[12px] text-[#64748b] px-6 py-5",children:"No students yet. Add students to this teacher to manage section assignments."}),c.assigned.map(d=>e.jsxs("div",{className:"px-6 py-4",children:[e.jsxs("p",{className:"text-[11px] font-semibold uppercase tracking-wider text-[#64748b] mb-2",children:[d.label," ",e.jsxs("span",{className:"text-[10px] font-normal text-[#94a3b8]",children:["(",d.students.length,")"]})]}),e.jsx("div",{className:"space-y-1.5",children:d.students.map(m=>e.jsx(ii,{student:m,sectionTargets:l,currentSectionId:a.classSectionId,onReassign:r,isBusy:o===m.id},`section-row-${m.id}`))})]},d.sectionId)),c.unassigned.length>0&&e.jsxs("div",{className:"px-6 py-4 bg-amber-50/40",children:[e.jsxs("p",{className:"text-[11px] font-semibold uppercase tracking-wider text-amber-700 mb-2",children:["Unassigned ",e.jsxs("span",{className:"text-[10px] font-normal text-amber-600/80",children:["(",c.unassigned.length,")"]})]}),e.jsx("div",{className:"space-y-1.5",children:c.unassigned.map(d=>e.jsx(ii,{student:d,sectionTargets:l,currentSectionId:a.classSectionId,onReassign:r,isBusy:o===d.id},`section-row-${d.id}`))})]})]})]})},ii=({student:t,sectionTargets:s,currentSectionId:a,onReassign:r,isBusy:o})=>{const[n,i]=u.useState(t.classSectionId||"");u.useEffect(()=>{i(t.classSectionId||"")},[t.classSectionId]);const l=()=>{const d=s.find(m=>m.classSectionId===n);d&&d.classSectionId!==t.classSectionId&&r(t,d)},c=n===(t.classSectionId||"");return e.jsxs("div",{className:"flex flex-col md:flex-row md:items-center gap-2 md:gap-3 px-3 py-2 rounded-[12px] bg-white border border-[#f1f5f9]",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-[13px] font-semibold text-[#1e293b] truncate",children:t.name}),e.jsxs("p",{className:"text-[11px] text-[#64748b] truncate",children:[t.lrn?`LRN ${t.lrn} · `:"",t.classMetadata?.className||t.className||"Unassigned section",a&&t.classSectionId===a?" · current":""]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("select",{value:n,onChange:d=>i(d.target.value),disabled:o||s.length===0,className:"text-[12px] rounded-xl border border-[#dde3eb] bg-white px-3 py-1.5 text-[#0a1628] focus:border-indigo-500 focus:outline-none focus:ring-2 focus:ring-indigo-200 disabled:opacity-60",children:[e.jsx("option",{value:"",children:"Select section…"}),s.map(d=>e.jsx("option",{value:d.classSectionId,children:d.label},d.classSectionId))]}),e.jsx("button",{type:"button",onClick:l,disabled:o||c||!n,className:"text-[12px] font-semibold rounded-xl px-3 py-1.5 bg-indigo-600 text-white hover:bg-indigo-700 transition-colors disabled:opacity-50 disabled:hover:bg-indigo-600",children:o?"Saving…":"Move"})]})]})},op=({selectedClass:t,students:s,allClasses:a,riskDistribution:r,topicPerformance:o,onViewStudent:n,onCreateAccount:i,onReassignSection:l,reassignBusyId:c,onBack:d,teacherOptions:m,managerUpdating:p,onAssignManager:h,onOpenNotifications:b,onOpenProfile:S,classColor:k,insightDismissed:N,onOpenInsightModal:v,onAddStudents:g,onRemoveStudent:I})=>{const{currentUser:z,userProfile:R}=hs(),[W,f]=u.useState(""),[C,w]=u.useState(""),[$,A]=u.useState("All"),[y,q]=u.useState(null),[J,re]=u.useState(!0),[le,ne]=u.useState(!1),[be,Ie]=u.useState(!0);u.useEffect(()=>{let j=!1;return re(!0),Mo(t.id).then(_=>{j||q(_)}).catch(_=>console.warn("[AnalyticsView] Backend fetch failed, using local data:",_)).finally(()=>{j||re(!1)}),()=>{j=!0}},[t.id]),u.useEffect(()=>{let j,_;return(async()=>{try{const{collection:T,onSnapshot:Q}=await Ss(async()=>{const{collection:Ce,onSnapshot:Ne}=await import("./vendor-firebase-firestore-CNv3xXal.js");return{collection:Ce,onSnapshot:Ne}},__vite__mapDeps([2,3])),{db:ue}=await Ss(async()=>{const{db:Ce}=await import("./index-BufUS6SI.js").then(Ne=>Ne.b7);return{db:Ce}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11])),ce=T(ue,"classes",t.id,"student_summaries");let ae=!0;j=Q(ce,()=>{if(ae){ae=!1;return}_&&clearTimeout(_),_=setTimeout(()=>{Mo(t.id).then(q).catch(()=>{})},2e3)})}catch{}})(),()=>{j?.(),_&&clearTimeout(_)}},[t.id]);const[de,fe]=u.useState(new Map);u.useEffect(()=>{let j=!1;const _=s.filter(T=>T.accountUid||T.hasRegisteredAccount);if(_.length!==0)return(async()=>{try{const{doc:T,getDoc:Q}=await Ss(async()=>{const{doc:Ce,getDoc:Ne}=await import("./vendor-firebase-firestore-CNv3xXal.js");return{doc:Ce,getDoc:Ne}},__vite__mapDeps([2,3])),{db:ue}=await Ss(async()=>{const{db:Ce}=await import("./index-BufUS6SI.js").then(Ne=>Ne.b7);return{db:Ce}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11])),ce=new Map,ae=_.slice(0,50);await Promise.all(ae.map(async Ce=>{const Ne=Ce.accountUid||Ce.id;try{const Je=await Q(T(ue,"progress",Ne));if(Je.exists()){const Ge=Je.data().averageScore||0;Ge>0&&ce.set(Ce.id,Ge)}}catch{}})),j||fe(ce)}catch{}})(),()=>{j=!0}},[s]);const H=y!=null&&y.students.some(j=>j.quiz_attempt_count>0),ee=(()=>{if(H)return y.class_average;if(t.avgScore>0)return t.avgScore;if(s.length===0)return 0;const j=s.map(_=>de.get(_.id)||_.avgScore).filter(_=>_>0);return j.length>0?Math.round(j.reduce((_,T)=>_+T,0)/j.length):0})(),oe=(()=>{if(H)return y.completion_rate;if(s.length===0)return 0;const j=s.filter(_=>de.has(_.id)||_.assignmentCompletion>0).length;return Math.round(j/s.length*100)})(),Re=(()=>{if(H)return y.participation_rate;if(s.length===0)return 0;const j=s.filter(_=>de.has(_.id)||_.engagementScore>0||_.avgScore>0).length;return s.length>0?Math.round(j/s.length*100):0})(),Fe=y?.insights?.risk_distribution?[{name:"Critical",value:y.insights.risk_distribution.Critical||0,color:"#dc2626"},{name:"High Risk",value:y.insights.risk_distribution["High Risk"]||0,color:"#f43f5e"},{name:"Medium Risk",value:y.insights.risk_distribution["Medium Risk"]||0,color:"#f59e0b"},{name:"Low Risk",value:y.insights.risk_distribution["Low Risk"]||0,color:"#10b981"},{name:"Unassessed",value:y.insights.risk_distribution.Unassessed||0,color:"#94a3b8"}].filter(j=>j.value>0):[{name:"High Risk",value:s.filter(j=>j.riskLevel==="high").length,color:"#FF8B8B"},{name:"Medium Risk",value:s.filter(j=>j.riskLevel==="medium").length,color:"#F08386"},{name:"Low Risk",value:s.filter(j=>j.riskLevel==="low").length,color:"#75D06A"}];u.useEffect(()=>{w(t.classMetadata?.managerId||t.managerId||"")},[t]);const Pe=u.useMemo(()=>{const j=W.trim().toLowerCase();let _=s;if(j&&(_=_.filter(T=>T.name.toLowerCase().includes(j)||(T.lrn||"").toLowerCase().includes(j)||(T.weakestTopic||"").toLowerCase().includes(j))),$==="Good")if(y){const T=new Set(y.students.filter(Q=>Q.quiz_attempt_count>0&&Q.avg_score>=75).map(Q=>Q.student_id));_=_.filter(Q=>T.has(Q.id))}else _=_.filter(T=>T.avgScore>=85&&T.riskLevel!=="high");else if($==="Risk")if(y){const T=new Set(y.students.filter(Q=>["High Risk","Critical","Unassessed"].includes(Q.risk_level)).map(Q=>Q.student_id));_=_.filter(Q=>T.has(Q.id))}else _=_.filter(T=>T.riskLevel==="high"||T.avgScore<75);return _},[W,s,$,y]),G=u.useMemo(()=>H?y.students.filter(j=>j.quiz_attempt_count>0).sort((j,_)=>_.avg_score-j.avg_score).slice(0,5).map(j=>{const _=s.find(T=>T.id===j.student_id);return _?{..._,avgScore:j.avg_score}:null}).filter(Boolean):[...s].map(j=>({...j,avgScore:de.get(j.id)||j.avgScore})).sort((j,_)=>_.avgScore-j.avgScore).slice(0,5),[s,y,H,de]),te=u.useMemo(()=>H?y.students.filter(j=>["High Risk","Critical"].includes(j.risk_level)).sort((j,_)=>j.avg_score-_.avg_score).map(j=>{const _=s.find(T=>T.id===j.student_id);return _?{..._,avgScore:j.avg_score,_backendRisk:j.risk_level}:null}).filter(Boolean):[...s].filter(j=>j.riskLevel==="high"||(de.get(j.id)||j.avgScore)<70||j.assignmentCompletion<65),[s,y,H,de]),E=u.useMemo(()=>y?.insights?.topic_performance?.length?y.insights.topic_performance.map(j=>({topic:j.topic,score:j.class_accuracy})):o,[y,o]),Y=j=>{if(H){const _=y.students.find(T=>T.student_id===j);if(_&&_.avg_score>0)return _.avg_score}return de.has(j)?de.get(j):null},V=j=>{if(!y)return null;const _=y.students.find(T=>T.student_id===j);return _?_.risk_level:null},pe=async()=>{ne(!0);try{const j=await am(t.id);q(_=>_&&{..._,insights:j})}catch(j){console.warn("[AnalyticsView] Refresh insights failed:",j?.message)}finally{ne(!1)}};u.useMemo(()=>m.find(j=>j.uid===C),[m,C]);const D=[t.classMetadata?.gradeLevel||t.gradeLevel,t.classMetadata?.classification||t.classification,t.classMetadata?.strand||t.strand].filter(Boolean);return e.jsxs(Le.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},exit:{opacity:0,y:-20},className:"p-3 sm:p-[24px] xl:p-[32px] space-y-3 sm:space-y-[24px] h-full overflow-y-auto",children:[e.jsx("div",{className:"flex items-center justify-between mb-3 sm:mb-6",children:e.jsxs("button",{onClick:d,className:"flex items-center gap-2 text-[13px] font-semibold text-[#4f46e5] hover:text-[#3730a3] transition-colors bg-white/60 hover:bg-white/80 px-[18px] py-2 rounded-full backdrop-blur-[12px] shadow-[0_1px_4px_rgba(0,0,0,0.04)] border border-white/50",children:[e.jsx(zs,{className:"w-4 h-4"}),"Back to Classes"]})}),e.jsxs("header",{style:{backgroundColor:k?.hex||"#6366f1"},className:"rounded-[24px] p-4 sm:p-[24px] lg:p-[32px] shadow-[0_8px_32px_rgba(0,0,0,0.08)] flex flex-col lg:flex-row lg:items-center justify-between gap-4 sm:gap-6 relative overflow-hidden group text-white",children:[e.jsx("div",{className:"absolute -right-10 -bottom-10 w-48 h-48 rounded-full bg-white/10 group-hover:scale-[1.3] transition-transform duration-700 ease-out pointer-events-none"}),e.jsx("div",{className:"absolute -left-10 -top-10 w-32 h-32 rounded-full bg-white/10 group-hover:scale-[1.2] transition-transform duration-700 delay-75 ease-out pointer-events-none"}),e.jsxs("div",{className:"shrink-0 relative z-10",children:[e.jsx("h1",{className:"text-xl sm:text-[28px] font-bold mb-2 sm:mb-3 tracking-tight",children:t.name}),e.jsx("div",{className:"flex flex-wrap items-center gap-2 mb-3",children:D.map((j,_)=>e.jsx("span",{className:"px-3 py-1 bg-white/20 backdrop-blur-md text-white text-[12px] font-semibold rounded-full shadow-sm border border-white/20",children:j},j))}),e.jsxs("p",{className:"text-[13px] text-white/80 font-medium",children:["Manager: ",t.classMetadata?.managerName||t.managerName||"Not assigned"]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-2 sm:gap-[18px] w-full",children:[e.jsxs("div",{className:"group relative overflow-hidden bg-[#0ea5e9] shadow-[0_4px_16px_rgba(14,165,233,0.13)] rounded-lg sm:rounded-2xl p-[12px] sm:p-[15px] text-white flex flex-col gap-[8px] sm:gap-[10px]",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-500 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-500 delay-75 ease-out"}),e.jsxs("div",{className:"relative z-10 flex justify-between items-start",children:[e.jsx("span",{className:"text-[10px] sm:text-[11px] opacity-90 uppercase tracking-wider font-semibold",children:"Class Average"}),e.jsx("div",{className:"bg-white/20 p-1.5 rounded-lg flex",children:e.jsx(ms,{size:14})})]}),e.jsxs("div",{className:"relative z-10 text-[22px] sm:text-[26px] font-semibold tracking-tight",children:[Math.round(ee),"%"]})]}),e.jsxs("div",{className:"group relative overflow-hidden bg-[#10b981] shadow-[0_4px_16px_rgba(16,185,129,0.13)] rounded-lg sm:rounded-2xl p-[12px] sm:p-[15px] text-white flex flex-col gap-[8px] sm:gap-[10px]",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-500 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-500 delay-75 ease-out"}),e.jsxs("div",{className:"relative z-10 flex justify-between items-start",children:[e.jsx("span",{className:"text-[10px] sm:text-[11px] opacity-90 uppercase tracking-wider font-semibold",children:"Completion"}),e.jsx("div",{className:"bg-white/20 p-1.5 rounded-lg flex",children:e.jsx(La,{size:14})})]}),e.jsxs("div",{className:"relative z-10 text-[22px] sm:text-[26px] font-semibold tracking-tight",children:[Math.round(oe),"%"]})]}),e.jsxs("div",{className:"group relative overflow-hidden bg-[#a855f7] shadow-[0_4px_16px_rgba(168,85,247,0.13)] rounded-lg sm:rounded-2xl p-[12px] sm:p-[15px] text-white flex flex-col gap-[8px] sm:gap-[10px]",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-500 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-500 delay-75 ease-out"}),e.jsxs("div",{className:"relative z-10 flex justify-between items-start",children:[e.jsx("span",{className:"text-[10px] sm:text-[11px] opacity-90 uppercase tracking-wider font-semibold",children:"Participation"}),e.jsx("div",{className:"bg-white/20 p-1.5 rounded-lg flex",children:e.jsx(us,{size:14})})]}),e.jsxs("div",{className:"relative z-10 text-[22px] sm:text-[26px] font-semibold tracking-tight",children:[Math.round(Re),"%"]})]}),e.jsxs("div",{className:"group relative overflow-hidden bg-[#f97316] shadow-[0_4px_16px_rgba(249,115,22,0.13)] rounded-lg sm:rounded-2xl p-[12px] sm:p-[15px] text-white flex flex-col gap-[8px] sm:gap-[10px]",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-500 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-500 delay-75 ease-out"}),e.jsxs("div",{className:"relative z-10 flex justify-between items-start",children:[e.jsx("span",{className:"text-[10px] sm:text-[11px] opacity-90 uppercase tracking-wider font-semibold",children:"Attention"}),e.jsx("div",{className:"bg-white/20 p-1.5 rounded-lg flex",children:e.jsx(ca,{size:14})})]}),e.jsxs("div",{className:"relative z-10 text-[22px] sm:text-[26px] font-semibold tracking-tight",children:[te.length," ",e.jsx("span",{className:"text-[12px] opacity-90 font-medium",children:"students"})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-3 gap-3 sm:gap-[24px] h-auto xl:h-[600px]",children:[e.jsxs("div",{className:"xl:col-span-1 bg-white/80 backdrop-blur-[12px] rounded-[18px] shadow-[0_1px_4px_rgba(0,0,0,0.04)] border border-white flex flex-col overflow-hidden h-[500px] xl:h-full",children:[e.jsxs("div",{className:"p-5 border-b border-[#f1f5f9] shrink-0",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("h2",{className:"text-[15px] font-semibold text-[#1e293b]",children:["Students ",e.jsxs("span",{className:"text-[#64748b] text-[13px]",children:["(",Pe.length,")"]})]}),e.jsx("button",{onClick:()=>g?.(),className:"text-[11px] font-semibold text-[#9956DE] hover:text-[#7c3aed] bg-[#9956DE]/10 hover:bg-[#9956DE]/20 px-3 py-1.5 rounded-lg transition-colors",children:"+ Add"})]}),e.jsxs("div",{className:"flex items-center bg-white px-4 py-2 rounded-[14px] shadow-[0_1px_4px_rgba(0,0,0,0.04)] border border-[#f1f5f9] group",children:[e.jsx(qs,{className:"w-4 h-4 text-[#64748b] shrink-0 group-focus-within:text-[#4f46e5] transition-colors"}),e.jsx("input",{type:"text",placeholder:"Search students...",value:W,onChange:j=>f(j.target.value),className:"bg-transparent border-none focus:outline-none ml-2 text-[13px] w-full text-[#475569] placeholder:text-[#64748b]"})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-4 overflow-x-auto no-scrollbar pb-1",children:[e.jsx("button",{onClick:()=>A("All"),className:`px-3 py-1.5 text-[11px] font-semibold rounded-[14px] whitespace-nowrap transition-all hover:scale-[1.02] ${$==="All"?"bg-[#4f46e5] text-white shadow-[0_1px_4px_rgba(0,0,0,0.04)]":"bg-[#f8fafc] text-[#64748b] hover:bg-[#f1f5f9]"}`,children:"All Students"}),e.jsx("button",{onClick:()=>A("Good"),className:`px-3 py-1.5 text-[11px] font-semibold rounded-[14px] whitespace-nowrap transition-all hover:scale-[1.02] ${$==="Good"?"bg-emerald-50 text-emerald-600 border border-emerald-100/50 shadow-[0_1px_4px_rgba(0,0,0,0.04)]":"bg-emerald-50/40 text-emerald-600 border border-emerald-50 hover:bg-emerald-50"}`,children:"Top Performers"}),e.jsx("button",{onClick:()=>A("Risk"),className:`px-3 py-1.5 text-[11px] font-semibold rounded-[14px] whitespace-nowrap transition-all hover:scale-[1.02] ${$==="Risk"?"bg-rose-50 text-rose-600 border border-rose-100/50 shadow-[0_1px_4px_rgba(0,0,0,0.04)]":"bg-rose-50/40 text-rose-600 border border-rose-50 hover:bg-rose-50"}`,children:"Needs Attention"})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto px-4 pb-4 flex flex-col no-scrollbar",children:e.jsx(yu,{style:{height:"100%"},data:Pe,className:"no-scrollbar",itemContent:(j,_)=>{const T=Y(_.id),Q=T!==null?{..._,avgScore:T}:_;return e.jsx("div",{className:"py-[6px] px-[8px]",children:e.jsx(rp,{student:Q,onViewStudent:n,onCreateAccount:i,onRemoveStudent:I})})},computeItemKey:(j,_)=>ln(_)})})]}),e.jsxs("div",{className:"xl:col-span-2 flex flex-col gap-[24px] h-full overflow-y-auto no-scrollbar pb-10 xl:pb-0",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-[24px]",children:[e.jsxs("div",{className:"bg-white/80 backdrop-blur-[12px] rounded-[18px] p-6 shadow-[0_1px_4px_rgba(0,0,0,0.04)] border border-white flex flex-col group h-[280px]",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsx("h3",{className:"font-semibold text-[15px] text-[#1e293b]",children:"Risk Distribution"}),e.jsx(Yr,{className:"w-4 h-4 text-[#64748b] cursor-pointer group-hover:scale-110 transition-transform"})]}),e.jsx("div",{className:"relative w-full flex-1 min-h-[180px]",children:e.jsx(Wn,{width:"100%",height:"100%",children:e.jsxs(qn,{data:Fe,children:[e.jsx(Yn,{strokeDasharray:"4 4",stroke:"#f1f5f9",vertical:!1}),e.jsx(Kn,{dataKey:"name",axisLine:{stroke:"#cbd5e1",strokeWidth:2},tickLine:!1,tick:{fill:"#475569",fontSize:11,fontWeight:600},dy:10}),e.jsx(Xn,{axisLine:!1,tickLine:!1,tick:{fill:"#64748b",fontSize:10,fontWeight:600}}),e.jsx(Jn,{cursor:{fill:"#f8fafc"},contentStyle:{borderRadius:"12px",border:"none",boxShadow:"0 4px 6px -1px rgb(0 0 0 / 0.1)"}}),e.jsx(Zn,{dataKey:"value",radius:[6,6,0,0],barSize:80,children:Fe.map((j,_)=>{const T={Critical:"#dc2626","High Risk":"#f43f5e","Medium Risk":"#f59e0b","Low Risk":"#10b981",Unassessed:"#94a3b8"};return e.jsx(eo,{fill:T[j.name]||j.color},`cell-${_}`)})})]})})})]}),e.jsxs("div",{className:"bg-white/80 backdrop-blur-[12px] rounded-[18px] p-6 shadow-[0_1px_4px_rgba(0,0,0,0.04)] border border-white flex flex-col group h-[280px]",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsx("h3",{className:"font-semibold text-[15px] text-[#1e293b]",children:"Topic Performance"}),e.jsx(Yr,{className:"w-4 h-4 text-[#64748b] cursor-pointer group-hover:scale-110 transition-transform"})]}),e.jsx("div",{className:"relative w-full flex-1 min-h-[180px] -ml-8",children:e.jsx(Wn,{width:"100%",height:"100%",children:e.jsxs(qn,{data:E,layout:"vertical",margin:{top:0,right:10,left:40,bottom:0},children:[e.jsx(Yn,{strokeDasharray:"4 4",stroke:"#f1f5f9",horizontal:!1}),e.jsx(Kn,{type:"number",domain:[0,100],axisLine:!1,tickLine:!1,tick:{fill:"#64748b",fontSize:10,fontWeight:600},tickFormatter:j=>`${j}%`}),e.jsx(Xn,{dataKey:"topic",type:"category",axisLine:{stroke:"#cbd5e1",strokeWidth:2},tickLine:!1,tick:{fill:"#1e293b",fontSize:11,fontWeight:600},dx:-10}),e.jsx(Jn,{cursor:{fill:"#f8fafc"},contentStyle:{borderRadius:"12px",border:"none",boxShadow:"0 4px 6px -1px rgb(0 0 0 / 0.1)"}}),e.jsx(Zn,{dataKey:"score",radius:[0,6,6,0],barSize:28,children:E.map((j,_)=>{const T=j.score>=75?"#10b981":j.score>=60?"#f59e0b":"#f43f5e";return e.jsx(eo,{fill:T},`cell-${_}`)})})]})})})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-[24px]",children:[e.jsxs("div",{className:"bg-white/80 backdrop-blur-[12px] rounded-[18px] p-6 shadow-[0_1px_4px_rgba(0,0,0,0.04)] border border-white",children:[e.jsx("div",{className:"flex items-center justify-between mb-4",children:e.jsxs("h3",{className:"font-semibold text-[15px] text-[#1e293b] flex items-center gap-2",children:[e.jsx(la,{className:"w-4 h-4 text-emerald-500"}),"Top Performers"]})}),e.jsxs("div",{className:"space-y-[8px]",children:[G.map(j=>e.jsxs("div",{onClick:()=>n(j),className:"flex justify-between items-center p-3 bg-emerald-50/40 rounded-[14px] border border-emerald-50 group hover:scale-[1.02] transition-transform cursor-pointer",children:[e.jsx("span",{className:"text-[13px] font-semibold text-[#1e293b]",children:j.name}),e.jsxs("span",{className:"text-[13px] font-semibold text-emerald-600",children:[Y(j.id)??j.avgScore,"%"]})]},`top-${j.id}`)),G.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"No students available yet."})]})]}),e.jsxs("div",{className:"bg-white/80 backdrop-blur-[12px] rounded-[18px] p-6 shadow-[0_1px_4px_rgba(0,0,0,0.04)] border border-white",children:[e.jsx("div",{className:"flex items-center justify-between mb-4",children:e.jsxs("h3",{className:"font-semibold text-[15px] text-[#1e293b] flex items-center gap-2",children:[e.jsx(ca,{className:"w-4 h-4 text-rose-500"}),"Needs Attention"]})}),e.jsxs("div",{className:"space-y-[8px]",children:[te.slice(0,4).map(j=>{const _=V(j.id),T=_||(j.riskLevel==="high"?"HIGH RISK":"MEDIUM RISK"),Q=_==="Critical"||j.avgScore===0&&j.riskLevel==="high",ue=_==="High Risk"||j.riskLevel==="high",ce=Q?"bg-red-50/60 border-red-100":ue?"bg-rose-50/40 border-rose-50":"bg-amber-50/40 border-amber-50",ae=Q?"text-red-700":ue?"text-rose-600":"text-amber-600";return e.jsxs("div",{onClick:()=>n(j),className:`flex justify-between items-center p-3 rounded-[14px] border group hover:scale-[1.02] transition-transform cursor-pointer ${ce}`,children:[e.jsx("span",{className:"text-[13px] font-semibold text-[#1e293b]",children:j.name}),e.jsx("span",{className:`text-[11px] font-semibold bg-white px-2 py-0.5 rounded-[14px] shadow-[0_1px_4px_rgba(0,0,0,0.04)] border border-[#f1f5f9] ${ae}`,children:T.toUpperCase()})]},`attn-${j.id}`)}),te.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"No urgent students."})]})]})]})]})]}),y?.insights&&e.jsxs("div",{className:"bg-gradient-to-br from-indigo-50/80 to-purple-50/60 backdrop-blur-[12px] rounded-[18px] p-5 sm:p-6 shadow-[0_1px_4px_rgba(0,0,0,0.04)] border border-indigo-100/50",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("button",{onClick:()=>Ie(!be),className:"flex items-center gap-2 text-[15px] font-semibold text-[#1e293b]",children:[e.jsx(ps,{className:"w-4 h-4 text-indigo-500"}),"AI Class Insights",e.jsx($t,{className:`w-4 h-4 text-[#64748b] transition-transform ${be?"":"-rotate-90"}`})]}),e.jsxs("button",{onClick:pe,disabled:le,className:"flex items-center gap-1.5 text-[11px] font-semibold text-indigo-600 hover:text-indigo-700 bg-white/70 hover:bg-white px-3 py-1.5 rounded-lg transition-colors disabled:opacity-50",children:[e.jsx(cs,{className:`w-3 h-3 ${le?"animate-spin":""}`}),le?"Refreshing...":"Refresh AI Analysis"]})]}),be&&e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[e.jsxs("div",{className:"bg-white/70 rounded-[14px] p-4 border border-white",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(Ls,{size:18,className:"text-indigo-600"}),e.jsx("h4",{className:"text-[13px] font-semibold text-[#1e293b]",children:"Class Overview"})]}),e.jsx("p",{className:"text-[12px] text-[#475569] leading-relaxed",children:y.insights.class_summary})]}),e.jsxs("div",{className:"bg-white/70 rounded-[14px] p-4 border border-white",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(la,{size:18,className:"text-emerald-600"}),e.jsx("h4",{className:"text-[13px] font-semibold text-[#1e293b]",children:"What's Working"})]}),e.jsx("p",{className:"text-[12px] text-[#475569] leading-relaxed",children:y.insights.class_strengths})]}),e.jsxs("div",{className:"bg-white/70 rounded-[14px] p-4 border border-white",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(ms,{size:18,className:"text-amber-600"}),e.jsx("h4",{className:"text-[13px] font-semibold text-[#1e293b]",children:"Recommended Actions"})]}),e.jsx("ul",{className:"space-y-1.5",children:y.insights.recommended_actions.map((j,_)=>e.jsxs("li",{className:"text-[12px] text-[#475569] leading-relaxed flex items-start gap-1.5",children:[e.jsx("span",{className:"text-indigo-500 mt-0.5 shrink-0",children:"•"}),j]},_))})]})]})]}),e.jsx(np,{students:s,allClasses:a,currentClass:t,onReassignSection:l,reassignBusyId:c})]})},ip=({student:t,teacherId:s,teacherName:a,onStudentUpdated:r,onBack:o,onNavigateToQuizMaker:n,initialCache:i,onCacheUpdate:l})=>{const c=(t.riskLevel||"low").toLowerCase(),d=c==="high"||c==="medium",m=u.useMemo(()=>xt.getImportGroundedRolloutFlags(),[]),[p,h]=u.useState(null),[b,S]=u.useState(!0),[k,N]=u.useState(null),[v,g]=u.useState(i?.learningPath||""),[I,z]=u.useState(!0),[R,W]=u.useState(i?.gradeDraft||t.grade||"Grade 11"),[f,C]=u.useState(i?.sectionDraft||t.section||"Section A"),[w,$]=u.useState(!1),[A,y]=u.useState(i?.lessonPlan??null),[q,J]=u.useState([]),[re,le]=u.useState(""),[ne,be]=u.useState(!1),[Ie,de]=u.useState(""),[fe,H]=u.useState("all"),[ee,oe]=u.useState("all"),[Re,Fe]=u.useState(!1),[Pe,G]=u.useState(!1),[te,E]=u.useState(null),[Y,V]=u.useState(!1),[pe,D]=u.useState(!1),[j,_]=u.useState(0),[T,Q]=u.useState(!1),[ue,ce]=u.useState("choose"),[ae,Ce]=u.useState([]),[Ne,Je]=u.useState(!1),[$e,Ge]=u.useState(!1),[ft,Nt]=u.useState(!1),[dt,jt]=u.useState(!1);u.useEffect(()=>{W(t.grade||"Grade 11"),C(t.section||"Section A")},[t.grade,t.section]),u.useEffect(()=>{let L=!1;return S(!0),rn(t.id).then(me=>{L||h(me)}).catch(me=>console.warn("[InterventionView] Backend fetch failed:",me)).finally(()=>{L||S(!1)}),()=>{L=!0}},[t.id]);const[Lt,rs]=u.useState(null);u.useEffect(()=>{let L=!1;const me=t.accountUid||t.id;return Gr(me).then(We=>{!L&&We?.averageScore&&rs(Math.round(We.averageScore))}).catch(()=>{}),()=>{L=!0}},[t.id,t.accountUid]),u.useEffect(()=>{const L=me=>{if(me.key==="Escape"){if(dt){jt(!1);return}if($e){ft?jt(!0):Ge(!1);return}T&&Q(!1)}};return document.addEventListener("keydown",L),()=>document.removeEventListener("keydown",L)},[$e,T,ft,dt]),u.useEffect(()=>{if($e){const L=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.body.style.overflow=L}}},[$e]),u.useEffect(()=>{l?.(t.id,{lessonPlan:A,learningPath:v,gradeDraft:R,sectionDraft:f})},[A,v,R,f,t.id,l]),u.useEffect(()=>{(async()=>{z(!0);try{let me="";try{me=await Wl(t.struggles.length>0?t.struggles:[t.weakestTopic],"general_math"),le(me)}catch{le("")}const We=await xt.getLearningPath({weaknesses:t.struggles.length>0?t.struggles:[t.weakestTopic],gradeLevel:"High School",subject:"general_math"}),B=me?`${We.learningPath} +`);navigator.clipboard.writeText(x),Nt(!0),setTimeout(()=>Nt(!1),2e3)},_l=()=>{if(!ae)return;const x=new Blob([JSON.stringify(ae,null,2)],{type:"application/json"}),O=URL.createObjectURL(x),U=document.createElement("a");U.href=O,U.download=`quiz_${I.replace(/\s/g,"_")}_${Date.now()}.json`,U.click(),URL.revokeObjectURL(O)};f.length>0||Object.values(X).flat().length>0;const In=(x,O)=>{const U=O?.gradeLevel||I,ye=O?.topics||f,Qe=x.questions.map((Ze,Vt)=>({id:`q_${Date.now()}_${Vt}`,questionType:Ze.questionType||"identification",question:Ze.question,...Ze.options?{options:Ze.options}:{},correctAnswer:Ze.correctAnswer,bloomLevel:Ze.bloomLevel||"understand",difficulty:Ze.difficulty||"medium",topic:Ze.topic,subject:U,points:Ze.points,explanation:Ze.explanation}));return{title:`${U} Quiz – ${ye.length>0?ye.slice(0,2).join(", "):"Mixed Topics"}`,gradeLevel:U,questions:Qe,totalPoints:x.totalPoints,metadata:{topicsCovered:Object.keys(x.metadata.topicsCovered),difficultyBreakdown:{easy:x.metadata.difficultyBreakdown.easy??0,medium:x.metadata.difficultyBreakdown.medium??0,hard:x.metadata.difficultyBreakdown.hard??0},bloomDistribution:x.metadata.bloomTaxonomyDistribution,questionTypeBreakdown:x.metadata.questionTypeBreakdown,supplementalPurpose:x.metadata.supplementalPurpose,recommendedTeacherActions:x.metadata.recommendedTeacherActions??[],generatedAt:new Date().toISOString(),generatedBy:"teacher_generated"},status:"draft",source:"teacher_generated"}},Tn=u.useCallback(x=>{_s(O=>[x,...O.filter(U=>U.id!==x.id)])},[]);async function _n(x,O){if(!h)return null;const U=In(x,O),ye=await On(U,h.uid,B?{documentId:B}:void 0);return kt(ye),Tn({id:ye,...U,teacherId:h.uid}),ye}const El=async()=>{if(!ae){ie.error("No quiz to save. Generate a quiz first.");return}if(!h){ie.error("You must be signed in to save quizzes.");return}We(!0);try{const x=In(ae),O=await On(x,h.uid,B?{documentId:B}:void 0);kt(O),Tn({id:O,...x,teacherId:h.uid}),ie.success("Quiz saved to your library!"),m?.(O)}catch(x){ie.error(x instanceof Error?x.message:"Failed to save quiz")}finally{We(!1)}},Rl=async()=>{if(B){M(!0);try{await lc(B),_s(x=>x.map(O=>O.id===B?{...O,status:"published"}:O)),ie.success("Quiz published to Quiz Bank!")}catch(x){ie.error(x instanceof Error?x.message:"Failed to publish quiz")}finally{M(!1)}}},Ir=async x=>{const O=x??B;if(!O){ie.error("Save the quiz first before assigning.");return}if(Ha(O),ve(!0),ws(null),nt(""),je.length===0&&h){se(!0);try{const U=await jn(h.uid);yt(U)}catch{ie.error("Failed to load students")}finally{se(!1)}}},Ml=async()=>{const x=Ba??B;if(!(!ut||!x||!h)){qe(!0);try{await cc(x,ut,h.uid),_s(O=>O.map(U=>U.id===x?{...U,status:"assigned",metadata:{...U.metadata,assignedTo:ut}}:U)),ie.success("Quiz assigned to student!"),ve(!1),Ha(null),k==="bank"&&Tr()}catch(O){ie.error(O instanceof Error?O.message:"Failed to assign quiz")}finally{qe(!1)}}},Tr=u.useCallback(async()=>{if(h){Js(!0);try{const x=await vi(h.uid);_s(x)}catch{ie.error("Failed to load quiz bank")}finally{Js(!1)}}},[h]);u.useEffect(()=>{k==="bank"&&Tr()},[k,Tr]);const Al=async x=>{try{await ic(x),_s(O=>O.filter(U=>U.id!==x)),ie.success("Quiz deleted")}catch{ie.error("Failed to delete quiz")}},En=je.filter(x=>x.name.toLowerCase().includes(rt.toLowerCase())||x.email.toLowerCase().includes(rt.toLowerCase())),Rn=Hs==="all"?Xs:Xs.filter(x=>x.status===Hs),Ll=x=>{const O=(x.metadata.topicsCovered||[]).reduce((U,ye)=>(U[ye]=(U[ye]||0)+1,U),{});return{questions:x.questions.map(U=>({questionType:U.questionType,question:U.question,correctAnswer:U.correctAnswer,options:U.options??null,bloomLevel:U.bloomLevel,difficulty:U.difficulty,topic:U.topic,points:U.points,explanation:U.explanation})),totalPoints:x.totalPoints,metadata:{topicsCovered:O,difficultyBreakdown:x.metadata.difficultyBreakdown,bloomTaxonomyDistribution:x.metadata.bloomDistribution,questionTypeBreakdown:x.metadata.questionTypeBreakdown,gradeLevel:x.gradeLevel,totalQuestions:x.questions.length,includesGraphQuestions:!1,supplementalPurpose:x.metadata.supplementalPurpose,bloomTaxonomyRationale:"Loaded from saved quiz bank entry.",recommendedTeacherActions:x.metadata.recommendedTeacherActions||[]}}},_r=x=>{kt(x.id),Ce(Ll(x)),Je(null),Us(x.id),vs("all"),L("all"),Ts(null),g("results"),N("create")},Mn={remember:{badge:"border-purple-200 text-purple-700 bg-purple-50",card:"from-[#a855f7] to-[#9333ea]",num:"text-purple-700 bg-purple-100 border-purple-200"},understand:{badge:"border-blue-200 text-blue-700 bg-blue-50",card:"from-[#3b82f6] to-[#2563eb]",num:"text-blue-700 bg-blue-100 border-blue-200"},apply:{badge:"border-amber-200 text-amber-700 bg-amber-50",card:"from-[#f59e0b] to-[#d97706]",num:"text-amber-700 bg-amber-100 border-amber-200"},analyze:{badge:"border-orange-200 text-orange-700 bg-orange-50",card:"from-[#f97316] to-[#ea580c]",num:"text-orange-700 bg-orange-100 border-orange-200"},evaluate:{badge:"border-rose-200 text-rose-700 bg-rose-50",card:"from-[#f43f5e] to-[#e11d48]",num:"text-rose-700 bg-rose-100 border-rose-200"},create:{badge:"border-emerald-200 text-emerald-700 bg-emerald-50",card:"from-[#10b981] to-[#059669]",num:"text-emerald-700 bg-emerald-100 border-emerald-200"}},zl=(x,O,U)=>{const ye=rs===O,Qe=Mn[x.bloomLevel?.toLowerCase()]||Mn.remember,Ze=x.bloomLevel?.toLowerCase()==="remember"?"hover:border-purple-200":x.bloomLevel?.toLowerCase()==="understand"?"hover:border-blue-200":x.bloomLevel?.toLowerCase()==="apply"?"hover:border-amber-200":"hover:border-slate-200";return e.jsxs(Le.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:O*.05},className:`border border-[#e2e8f0] rounded-[20px] overflow-hidden bg-white shadow-sm hover:shadow-md ${Ze} transition-all duration-300`,children:[e.jsxs("div",{className:"p-6 flex justify-between items-start cursor-pointer hover:bg-slate-50/50 transition-colors",onClick:()=>Ts(ye?null:O),children:[e.jsxs("div",{className:"space-y-3 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2.5 flex-wrap mb-1",children:[e.jsxs("span",{className:`w-8 h-8 rounded-lg bg-gradient-to-br ${Qe.card} text-white flex items-center justify-center font-bold text-[13px] shadow-sm`,children:["Q",O+1]}),e.jsx("span",{className:`px-2.5 py-1 rounded-md border text-[10px] font-bold uppercase tracking-wider shadow-sm ${Qe.badge}`,children:x.bloomLevel}),e.jsx("span",{className:`px-2.5 py-1 rounded-md border text-[10px] font-bold uppercase tracking-wider shadow-sm ${x.difficulty==="easy"?"border-emerald-200 text-emerald-700 bg-emerald-50":x.difficulty==="hard"?"border-rose-200 text-rose-700 bg-rose-50":"border-amber-200 text-amber-700 bg-amber-50"}`,children:x.difficulty}),e.jsxs("span",{className:"text-[12px] font-bold text-[#64748b] bg-slate-100 px-2 py-1 rounded-md",children:[x.points," pts"]}),x.topic&&e.jsx("span",{className:"text-[12px] font-semibold text-[#64748b] px-2 py-1 hidden sm:inline-block border-l border-slate-200",children:x.topic})]}),e.jsx("p",{className:"text-[16px] font-bold text-[#1e293b] pr-4 leading-relaxed",children:x.question})]}),e.jsxs("div",{className:"flex flex-col items-end justify-between h-full gap-4 shrink-0 mt-1",children:[e.jsx("span",{className:`px-3 py-1.5 rounded-md text-[10px] font-bold uppercase tracking-widest hidden sm:block border shadow-sm ${Qe.badge}`,children:x.bloomLevel}),e.jsx("div",{className:"w-8 h-8 rounded-full bg-slate-50 flex items-center justify-center border border-slate-200 mt-2",children:ye?e.jsx(Ca,{size:16,className:"text-[#64748b] transition-transform duration-300"}):e.jsx($t,{size:16,className:"text-[#64748b]"})})]})]}),e.jsx(zt,{children:ye&&e.jsx(Le.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},className:"overflow-hidden",children:e.jsxs("div",{className:"p-6 pt-0 bg-white",children:[e.jsx("div",{className:"h-px w-full bg-gradient-to-r from-transparent via-[#e2e8f0] to-transparent mb-6"}),x.options&&e.jsxs("div",{className:"mb-6",children:[e.jsx("p",{className:"text-[13px] font-bold text-[#64748b] mb-3 uppercase tracking-wider",children:"Options:"}),e.jsx("div",{className:"space-y-3",children:x.options.map((Vt,Zs)=>{const mt=Vt.includes(x.correctAnswer);return e.jsxs("div",{className:`rounded-[12px] p-4 text-[14px] font-medium transition-all cursor-pointer relative overflow-hidden ${mt?"bg-gradient-to-r from-emerald-50 to-emerald-100/30 border-2 border-emerald-400 text-emerald-800 font-bold shadow-sm":"bg-white border border-[#e2e8f0] text-[#475569] hover:border-[#a855f7] hover:shadow-[0_2px_8px_rgba(168,85,247,0.1)]"}`,children:[mt&&e.jsx("div",{className:"absolute left-0 top-0 w-1 h-full bg-emerald-500"}),e.jsx("span",{className:mt?"pl-2":"",children:Vt}),mt&&e.jsx("div",{className:"w-6 h-6 rounded-full bg-emerald-500 text-white flex items-center justify-center shadow-sm absolute right-4 top-1/2 -translate-y-1/2",children:e.jsx(Ht,{size:13})})]},Zs)})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4 mb-5",children:[e.jsxs("div",{className:"bg-emerald-50/80 border border-emerald-200/60 rounded-[16px] p-5 shadow-sm",children:[e.jsxs("p",{className:"text-[11px] font-bold text-emerald-700 uppercase tracking-wider mb-2 flex items-center gap-1.5",children:[e.jsx(ya,{size:14})," Correct Answer"]}),e.jsx("p",{className:"text-[16px] font-bold text-[#1e293b]",children:x.correctAnswer})]}),e.jsxs("div",{className:"bg-purple-50/80 border border-purple-200/60 rounded-[16px] p-5 shadow-sm",children:[e.jsxs("p",{className:"text-[11px] font-bold text-purple-700 uppercase tracking-wider mb-2 flex items-center gap-1.5",children:[e.jsx(ps,{size:14})," AI Explanation"]}),e.jsx("p",{className:"text-[13px] text-[#475569] leading-relaxed font-medium",children:x.explanation})]})]}),e.jsxs("div",{className:"flex gap-6 text-[12px] font-medium text-[#64748b] mt-5 pt-4 border-t border-slate-100",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Rs,{size:14})," ",e.jsx("strong",{className:"text-[#1e293b]",children:"Type:"})," ",Wa[x.questionType]?.label||x.questionType]}),e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ur,{size:14})," ",e.jsx("strong",{className:"text-[#1e293b]",children:"Bloom:"})," ",x.bloomLevel]})]})]})})})]},O)},An=e.jsxs("div",{className:"w-full h-full flex flex-col overflow-y-auto bg-gradient-to-br from-[#eef2ff] via-[#f5f3ff] to-[#fff7ed]",children:[e.jsx("div",{className:"w-full px-[24px] xl:px-[32px] pt-[12px] pb-4",children:e.jsxs("div",{className:"flex items-center gap-1 bg-white/50 backdrop-blur-md p-1.5 rounded-full border border-white shadow-[0_2px_8px_rgba(0,0,0,0.04)] w-max",children:[e.jsxs("button",{onClick:()=>N("create"),className:`px-6 py-2 rounded-full text-[13px] font-bold flex items-center gap-2 transition-all duration-300 ease-out ${k==="create"?"bg-white text-[#a855f7] shadow-[0_2px_8px_rgba(168,85,247,0.15)] scale-100":"bg-transparent text-[#64748b] hover:text-[#1e293b] hover:bg-white/60 scale-95 hover:scale-100"}`,children:[e.jsx(Xr,{size:16})," Create Quiz"]}),e.jsxs("button",{onClick:()=>N("bank"),className:`px-6 py-2 rounded-full text-[13px] font-bold flex items-center gap-2 transition-all duration-300 ease-out ${k==="bank"?"bg-white text-[#a855f7] shadow-[0_2px_8px_rgba(168,85,247,0.15)] scale-100":"bg-transparent text-[#64748b] hover:text-[#1e293b] hover:bg-white/60 scale-95 hover:scale-100"}`,children:[e.jsx(ur,{size:16})," Quiz Bank"]})]})}),e.jsxs("div",{className:"w-full px-[24px] xl:px-[32px] pb-[32px] flex-1",children:[k==="bank"&&e.jsxs("div",{className:"w-full space-y-[24px]",children:[e.jsx("div",{className:"flex items-center gap-3 overflow-x-auto pb-2 border-b border-[#e2e8f0] mb-6",style:{scrollbarWidth:"none"},children:["all","draft","published","assigned","completed"].map(x=>e.jsx("button",{onClick:()=>Pa(x),className:`px-5 py-2 text-[13px] font-bold rounded-full whitespace-nowrap transition-all duration-300 mb-4 capitalize ${Hs===x?"bg-purple-50 text-[#9333ea] border border-purple-200 shadow-[0_2px_8px_rgba(168,85,247,0.15)] hover:scale-105":"bg-white/80 text-[#64748b] border border-white hover:border-[#e2e8f0] hover:bg-white shadow-sm hover:shadow-md hover:-translate-y-0.5"}`,children:x==="all"?"All":x.charAt(0).toUpperCase()+x.slice(1)},x))}),Oa?e.jsxs("div",{className:"flex items-center justify-center py-16",children:[e.jsx(gt,{size:24,className:"animate-spin text-sky-500"}),e.jsx("span",{className:"ml-2 text-sm text-[#5a6578]",children:"Loading quiz bank…"})]}):Rn.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-slate-500",children:[e.jsx(ur,{size:40,className:"mb-3"}),e.jsx("p",{className:"font-medium",children:"No quizzes found"}),e.jsx("p",{className:"text-xs mt-1",children:"Generate your first quiz in the Create tab"})]}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:Rn.map(x=>e.jsxs(Le.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},onClick:()=>_r(x),role:"button",tabIndex:0,onKeyDown:O=>{(O.key==="Enter"||O.key===" ")&&(O.preventDefault(),_r(x))},className:`relative bg-white/80 backdrop-blur-md rounded-[20px] p-6 shadow-sm border flex flex-col group hover:-translate-y-1 transition-all duration-300 cursor-pointer overflow-hidden focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#a855f7] ${x.status==="assigned"||x.status==="published"?"border-white hover:border-purple-100 hover:shadow-[0_8px_24px_rgba(168,85,247,0.1)]":"border-white hover:border-slate-200 hover:shadow-[0_8px_24px_rgba(0,0,0,0.06)]"}`,children:[e.jsx("div",{className:`absolute top-0 left-0 w-[6px] h-full transition-colors duration-300 ${x.status==="assigned"||x.status==="published"?"bg-purple-300 group-hover:bg-[#a855f7]":"bg-slate-200 group-hover:bg-slate-400"}`}),e.jsxs("div",{className:"flex justify-between items-start mb-4 gap-4 pl-3",children:[e.jsx("h3",{className:`font-bold text-[15px] text-[#1e293b] leading-tight transition-colors ${x.status==="assigned"||x.status==="published"?"group-hover:text-[#9333ea]":"group-hover:text-slate-700"}`,children:x.title}),e.jsx("span",{className:`px-2.5 py-1 rounded-[6px] text-[10px] font-bold uppercase tracking-wider shrink-0 shadow-sm ${Nm[x.status]}`,children:x.status})]}),e.jsx("div",{className:"flex flex-wrap gap-2 mb-5 pl-3",children:x.metadata.topicsCovered.slice(0,3).map(O=>e.jsx("span",{className:"px-2.5 py-1 bg-[#f8fafc] text-slate-600 text-[11px] font-medium rounded-md border border-slate-200 group-hover:border-slate-300 transition-colors",children:O},O))}),e.jsxs("div",{className:"flex items-center gap-5 text-[13px] text-[#64748b] font-medium mb-6 pl-3",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(hc,{size:14})," ",x.questions.length," questions"]}),e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(xi,{size:14})," ",x.totalPoints," pts"]}),e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(us,{size:14})," ",x.gradeLevel]})]}),e.jsxs("div",{className:"flex items-center gap-4 mt-auto pt-5 border-t border-[#f1f5f9] pl-3",children:[e.jsxs("button",{onClick:O=>{O.stopPropagation(),_r(x)},className:"flex items-center gap-1.5 text-[13px] font-semibold text-[#64748b] hover:text-[#1e293b] transition-colors bg-slate-50 hover:bg-slate-100 border border-slate-200 px-4 py-2 rounded-full shadow-sm",children:[e.jsx(fc,{size:14})," View"]}),e.jsxs("button",{onClick:O=>{O.stopPropagation(),Ir(x.id)},className:"flex items-center gap-1.5 text-[13px] font-bold text-[#a855f7] hover:text-[#9333ea] transition-colors",children:[e.jsx(aa,{size:14})," Assign"]}),e.jsxs("button",{onClick:O=>{O.stopPropagation(),Al(x.id)},className:"flex items-center gap-1.5 text-[13px] font-semibold text-rose-500 hover:text-rose-700 transition-colors ml-auto opacity-60 group-hover:opacity-100",children:[e.jsx(wi,{size:14})," Delete"]})]})]},x.id))})]}),k==="create"&&e.jsxs(e.Fragment,{children:[$e&&e.jsx("div",{className:"w-full px-[24px] xl:px-[32px] pt-4",children:e.jsxs(Le.div,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},className:"bg-red-50 border border-red-200 rounded-xl p-4 flex items-start gap-3",children:[e.jsx(br,{size:18,className:"text-red-500 flex-shrink-0 mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-red-800 font-medium",children:"Error"}),e.jsx("p",{className:"text-sm text-red-600",children:$e})]}),e.jsx("button",{onClick:()=>Ge(""),className:"ml-auto",children:e.jsx(Xt,{size:14,className:"text-red-400"})})]})}),te&&e.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center p-[24px] xl:p-[32px]",children:[e.jsxs("div",{className:"bg-white p-8 rounded-[16px] shadow-sm border border-[#e2e8f0] w-full max-w-3xl",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("h3",{className:"text-[16px] font-bold text-[#1e293b] flex items-center gap-3",children:[e.jsx(gt,{size:20,className:"animate-spin text-[#a855f7]"}),"Generating Quiz in Background"]}),e.jsxs("span",{className:"text-[14px] font-extrabold text-[#9333ea]",children:[j,"%"]})]}),e.jsx("div",{className:"w-full bg-slate-100 h-2.5 rounded-full overflow-hidden mb-6",children:e.jsx(Le.div,{animate:{width:`${j}%`},transition:{duration:.35,ease:"easeOut"},className:"bg-gradient-to-r from-sky-400 via-indigo-500 to-purple-500 h-full rounded-full"})}),e.jsxs("div",{className:"text-[13px] text-[#64748b]",children:[e.jsxs("p",{className:"font-medium text-[#475569] mb-1",children:["Stage: ",e.jsx("span",{className:"font-bold text-[#1e293b] capitalize",children:T.replace(/_/g," ")})]}),e.jsx("p",{children:ue}),pe&&e.jsxs("p",{className:"text-[11px] mt-3 opacity-60 font-mono",children:["Task ID: ",pe]})]})]}),e.jsxs("p",{className:"mt-8 text-[14px] font-medium text-[#64748b] flex items-center gap-2 animate-pulse",children:[e.jsx(gt,{size:16,className:"animate-spin"})," Generating quiz... Please wait."]})]}),!te&&v!=="results"&&e.jsx("div",{className:"w-full px-[24px] xl:px-[32px] mb-8",children:e.jsx("div",{className:"flex items-center justify-between bg-white/80 backdrop-blur-[12px] rounded-2xl border border-white shadow-[0_4px_16px_rgba(0,0,0,0.03)] p-1.5",children:[{id:"setup",label:"Setup"},{id:"topics",label:"Topics"},{id:"style",label:"Question Style"},{id:"preview",label:"Preview"}].map((x,O)=>{const ye=["setup","topics","style","preview"].indexOf(v),Qe=ye>O,Ze=ye===O;return e.jsxs("div",{className:`flex-1 flex items-center justify-center gap-2 py-3 px-4 rounded-xl transition-all duration-500 ${Ze?"bg-purple-50/80 shadow-[0_1px_3px_rgba(168,85,247,0.1)]":Qe?"bg-transparent":"bg-transparent opacity-60"}`,children:[e.jsx("div",{className:`w-6 h-6 rounded-full flex items-center justify-center text-[12px] font-bold shrink-0 ${Ze?"bg-gradient-to-br from-[#a855f7] to-[#9333ea] text-white shadow-md":Qe?"bg-emerald-500 text-white shadow-sm":"bg-slate-100 text-[#64748b]"}`,children:Qe?e.jsx(Ht,{size:13,strokeWidth:3}):O+1}),e.jsx("span",{className:`text-[13px] font-bold whitespace-nowrap ${Ze?"text-[#9333ea]":Qe?"text-[#1e293b]":"text-[#64748b]"}`,children:x.label})]},x.id)})})}),v==="setup"&&!te&&e.jsxs("div",{className:"w-full px-[24px] xl:px-[32px] flex-1 space-y-[24px] pb-8",children:[e.jsxs("div",{className:"bg-gradient-to-r from-purple-50/80 to-indigo-50/80 backdrop-blur-sm border border-purple-100/50 rounded-[16px] p-5 flex items-start gap-4 shadow-sm hover:shadow-md transition-shadow duration-300",children:[e.jsx("div",{className:"bg-white p-2 rounded-full shadow-sm shrink-0",children:e.jsx(na,{size:18,className:"text-[#9333ea]"})}),e.jsxs("p",{className:"text-[13px] text-[#475569] leading-relaxed pt-0.5",children:["This quiz maker generates ",e.jsx("span",{className:"font-bold text-[#9333ea]",children:"supplemental assessments"})," to support classroom instruction. Questions follow Bloom's Taxonomy for comprehensive skill evaluation. Generation limit: up to ",va," questions and ",wa," topics per quiz."]})]}),e.jsxs("div",{className:"bg-white/80 backdrop-blur-[12px] rounded-[20px] border border-white shadow-[0_4px_16px_rgba(0,0,0,0.03)] overflow-hidden hover:shadow-[0_8px_24px_rgba(0,0,0,0.06)] transition-all duration-300",children:[e.jsx("div",{className:"p-5 border-b border-[#f1f5f9] bg-white/50",children:e.jsx("h3",{className:"text-[11px] font-bold text-[#64748b] uppercase tracking-wider",children:"Basic Settings"})}),e.jsxs("div",{className:"p-8 flex flex-col md:flex-row gap-8",children:[e.jsxs("div",{className:"flex-1 group",children:[e.jsx("label",{htmlFor:"quiz-grade-level",className:"text-[13px] font-bold text-[#1e293b] mb-2 block group-hover:text-[#a855f7] transition-colors",children:"Grade level"}),e.jsxs("div",{className:"relative",children:[e.jsx("select",{id:"quiz-grade-level",value:I,onChange:x=>z(Dr(x.target.value)),className:"appearance-none w-full bg-white border border-[#e2e8f0] hover:border-[#cbd5e1] text-[#475569] text-[14px] font-medium rounded-xl px-4 py-3.5 outline-none focus:border-[#a855f7] focus:ring-4 focus:ring-[#a855f7]/10 cursor-pointer transition-all duration-200 shadow-sm",children:jm.map(x=>e.jsx("option",{value:x,children:x},x))}),e.jsx($t,{size:18,className:"text-[#64748b] absolute right-4 top-1/2 -translate-y-1/2 pointer-events-none"})]})]}),e.jsxs("div",{className:"flex-1 group",children:[e.jsx("label",{htmlFor:"quiz-num-questions",className:"text-[13px] font-bold text-[#1e293b] mb-2 block group-hover:text-[#a855f7] transition-colors",children:"Number of questions"}),e.jsxs("div",{className:"flex items-center bg-white border border-[#e2e8f0] rounded-xl overflow-hidden focus-within:border-[#a855f7] focus-within:ring-4 focus-within:ring-[#a855f7]/10 transition-all duration-200 h-[50px] shadow-sm hover:border-[#cbd5e1]",children:[e.jsx("button",{onClick:()=>W(Math.max(1,R-1)),className:"w-14 h-full flex items-center justify-center text-[#64748b] bg-slate-50 hover:bg-slate-100 hover:text-[#1e293b] transition-colors border-r border-[#e2e8f0] active:bg-slate-200",children:e.jsx(Pn,{size:16})}),e.jsx("input",{id:"quiz-num-questions",type:"number",min:1,max:va,value:R,onChange:x=>W(Math.min(va,Math.max(1,parseInt(x.target.value)||1))),className:"flex-1 text-center font-bold text-[16px] text-[#1e293b] border-none outline-none focus:ring-0 w-full h-full p-0"}),e.jsx("button",{onClick:()=>W(Math.min(va,R+1)),className:"w-14 h-full flex items-center justify-center text-[#64748b] bg-slate-50 hover:bg-slate-100 hover:text-[#1e293b] transition-colors border-l border-[#e2e8f0] active:bg-slate-200",children:e.jsx(da,{size:16})})]})]})]})]})]}),v==="topics"&&!te&&e.jsxs("div",{className:"w-full px-[24px] xl:px-[32px] flex-1 space-y-[24px] pb-8",children:[e.jsxs("div",{className:"flex items-end justify-between mb-2",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-[20px] font-bold text-[#1e293b] mb-1",children:"Select topics"}),e.jsxs("p",{className:"text-[13px] text-[#64748b]",children:["Choose up to ",wa," topics across all strands"]})]}),e.jsxs("div",{className:"bg-purple-50 border border-purple-100 px-3 py-1.5 rounded-full flex items-center gap-2 shadow-sm",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-[#a855f7] animate-pulse"}),e.jsxs("span",{className:"text-[12px] font-bold text-[#a855f7]",children:[f.filter(x=>!w.includes(x)).length," of ",wa," selected"]})]})]}),fe?e.jsxs("div",{className:"flex items-center justify-center py-10 text-sm text-[#5a6578]",children:[e.jsx(gt,{size:24,className:"animate-spin text-[#9b51e0] mr-2"})," Loading topics..."]}):e.jsx("div",{className:"space-y-3",children:Object.entries(X).map(([x,O])=>{const U=O.filter(Qe=>f.includes(Qe)&&!w.includes(Qe)).length,ye=jt===x;return e.jsxs("div",{className:"border border-[#dde3eb] rounded-xl bg-white overflow-hidden shadow-sm",children:[e.jsxs("button",{onClick:()=>Lt(ye?null:x),className:"w-full flex items-center justify-between p-4 hover:bg-[#f7f9fc] transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-1 h-6 bg-[#9b51e0] rounded-full"}),e.jsxs("div",{className:"text-left",children:[e.jsx("p",{className:"font-bold text-[#0a1628] text-sm",children:x}),e.jsxs("p",{className:"text-xs text-slate-500",children:[O.length," topics"]})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("span",{className:"bg-purple-100 text-[#9b51e0] px-2.5 py-0.5 rounded-full text-xs font-semibold",children:[U," selected"]}),ye?e.jsx(Ca,{size:18,className:"text-slate-400"}):e.jsx($t,{size:18,className:"text-slate-400"})]})]}),e.jsx(zt,{children:ye&&e.jsx(Le.div,{initial:{height:0},animate:{height:"auto"},exit:{height:0},className:"overflow-hidden border-t border-[#edf1f7]",children:e.jsx("div",{className:"py-2",children:O.map((Qe,Ze)=>{const Vt=f.includes(Qe),Zs=w.includes(Qe),mt=Vt&&!Zs;let Jt="Core";return Ze%3===0&&(Jt="Foundation"),Ze%3===2&&(Jt="Advanced"),e.jsxs("div",{className:"flex items-center justify-between px-6 py-3 hover:bg-[#f7f9fc]",children:[e.jsxs("label",{className:"flex items-center gap-3 cursor-pointer flex-1",children:[e.jsx("div",{className:`w-5 h-5 rounded flex items-center justify-center transition-colors ${mt?"bg-[#9b51e0] border-[#9b51e0]":"border-2 border-[#dde3eb] bg-white"}`,children:mt&&e.jsx(Ht,{size:14,className:"text-white"})}),e.jsx("input",{type:"checkbox",className:"hidden",checked:mt,onChange:()=>Ga(Qe)}),e.jsx("span",{className:`text-sm font-semibold ${mt?"text-[#0a1628]":"text-[#5a6578]"}`,children:Qe})]}),e.jsx("span",{className:`border px-3 py-1 rounded-full text-[10px] uppercase font-bold tracking-wider ${Jt==="Advanced"?"bg-white text-slate-400 border-[#dde3eb]":"bg-purple-50 text-[#9b51e0] border-purple-100"}`,children:Jt})]},Qe)})})})})]},x)})})]}),v==="style"&&!te&&e.jsxs("div",{className:"w-full px-[24px] xl:px-[32px] flex-1 space-y-[24px] pb-8",children:[e.jsxs("div",{className:"bg-white/80 backdrop-blur-[12px] rounded-[20px] border border-[#e2e8f0] shadow-sm overflow-hidden hover:shadow-[0_8px_24px_rgba(0,0,0,0.04)] transition-shadow duration-300",children:[e.jsx("div",{className:"p-5 border-b border-[#f1f5f9] bg-white/50",children:e.jsx("h3",{className:"text-[11px] font-bold text-[#64748b] uppercase tracking-wider",children:"Question Types"})}),e.jsx("div",{className:"p-4 grid grid-cols-2 sm:grid-cols-5 gap-3",children:Object.entries(Wa).map(([x,O])=>{const U=A.includes(x);return e.jsxs("button",{onClick:()=>Bt(x),className:`border-2 rounded-[16px] p-4 flex flex-col items-center justify-center text-center cursor-pointer transition-all duration-300 relative overflow-hidden group hover:-translate-y-1 ${U?"border-[#a855f7] bg-gradient-to-b from-purple-50/80 to-white/80 shadow-[0_4px_12px_rgba(168,85,247,0.12)]":"border-slate-100 bg-slate-50/50 shadow-sm hover:shadow-md hover:border-purple-200"}`,children:[U&&e.jsx("div",{className:"absolute top-2 right-2 w-5 h-5 bg-gradient-to-br from-[#a855f7] to-[#9333ea] rounded-full flex items-center justify-center shadow-md",children:e.jsx(Ht,{size:11,className:"text-white"})}),e.jsx("div",{className:`w-12 h-12 rounded-full flex items-center justify-center mb-3 group-hover:scale-110 transition-transform duration-300 ${U?"bg-white border border-purple-200 shadow-md":"bg-white border border-slate-200 shadow-sm group-hover:shadow-md"}`,children:e.jsx("span",{className:U?"text-[#a855f7]":"text-slate-500",children:O.icon})}),e.jsx("span",{className:`font-bold text-[12px] leading-tight ${U?"text-[#9333ea]":"text-slate-700"}`,children:O.label})]},x)})})]}),e.jsxs("div",{className:"bg-white/80 backdrop-blur-[12px] rounded-[20px] border border-[#e2e8f0] shadow-sm overflow-hidden hover:shadow-[0_8px_24px_rgba(0,0,0,0.04)] transition-shadow duration-300",children:[e.jsx("div",{className:"p-5 border-b border-[#f1f5f9] bg-white/50",children:e.jsx("h3",{className:"text-[11px] font-bold text-[#64748b] uppercase tracking-wider",children:"Bloom's Taxonomy Levels"})}),e.jsx("div",{className:"p-6 flex flex-wrap gap-4",children:Object.entries(Do).map(([x,O])=>{const U=q.includes(x);return e.jsx("button",{onClick:()=>Ye(x),className:`px-6 py-2.5 rounded-full border-2 font-bold text-[13px] transition-all duration-200 hover:-translate-y-0.5 capitalize ${U?"border-[#a855f7] text-[#9333ea] bg-purple-50/80 shadow-[0_2px_8px_rgba(168,85,247,0.15)]":"border-slate-200 text-[#64748b] bg-white shadow-sm hover:border-slate-300 hover:bg-slate-50"}`,children:x},x)})})]}),e.jsxs("div",{className:"bg-white/80 backdrop-blur-[12px] rounded-[20px] border border-[#e2e8f0] shadow-sm overflow-hidden hover:shadow-[0_8px_24px_rgba(0,0,0,0.04)] transition-shadow duration-300",children:[e.jsx("div",{className:"p-5 border-b border-[#f1f5f9] bg-white/50",children:e.jsx("h3",{className:"text-[11px] font-bold text-[#64748b] uppercase tracking-wider",children:"Difficulty Distribution"})}),e.jsx("div",{className:"p-8 space-y-8",children:Object.entries(ne).map(([x,O])=>{const U={easy:"bg-emerald-400",medium:"bg-amber-400",hard:"bg-rose-400"},ye={easy:"text-emerald-600",medium:"text-amber-500",hard:"text-rose-500"},Qe={easy:"group-hover:border-emerald-200",medium:"group-hover:border-amber-200",hard:"group-hover:border-rose-200"};return e.jsxs("div",{className:"flex items-center gap-6 group",children:[e.jsx("span",{className:`w-16 text-[13px] font-bold text-[#475569] capitalize group-hover:${ye[x]} transition-colors`,children:x}),e.jsx("div",{className:"flex-1 bg-slate-100 h-3 rounded-full overflow-hidden shadow-inner",children:e.jsx(Le.div,{animate:{width:`${O}%`},className:`h-full rounded-full transition-all duration-500 ease-out ${U[x]}`})}),e.jsxs("div",{className:`flex items-center bg-white border border-[#e2e8f0] rounded-xl shadow-sm overflow-hidden p-0.5 w-28 h-10 transition-colors ${Qe[x]}`,children:[e.jsx("button",{onClick:()=>De(x,-5),className:`w-8 h-full flex items-center justify-center text-[#64748b] hover:bg-slate-50 hover:${ye[x]} rounded-lg transition-colors`,children:e.jsx(Pn,{className:"w-3.5 h-3.5"})}),e.jsx("input",{type:"text",value:`${O}%`,readOnly:!0,className:"flex-1 text-center font-bold text-[14px] text-[#1e293b] border-none outline-none focus:ring-0 w-full p-0 pointer-events-none"}),e.jsx("button",{onClick:()=>De(x,5),className:`w-8 h-full flex items-center justify-center text-[#64748b] hover:bg-slate-50 hover:${ye[x]} rounded-lg transition-colors`,children:e.jsx(da,{className:"w-3.5 h-3.5"})})]})]},x)})})]})]}),v==="preview"&&!te&&!ae&&e.jsx("div",{className:"w-full px-[24px] xl:px-[32px] flex-1 space-y-[24px] pb-8",children:e.jsxs("div",{className:"bg-white/80 backdrop-blur-md rounded-[20px] border border-[#e2e8f0] shadow-[0_8px_24px_rgba(0,0,0,0.04)] overflow-hidden p-8",children:[e.jsxs("h3",{className:"text-[12px] font-bold text-[#64748b] uppercase tracking-wider mb-6 flex items-center gap-2",children:[e.jsx(Ls,{size:16,className:"text-[#a855f7]"})," Quiz Summary"]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-6 mb-6",children:[{label:"Questions",value:R},{label:"Topics",value:f.filter(x=>!w.includes(x)).length},{label:"Level",value:I.replace("Grade ","Gr. ")}].map(x=>e.jsxs("div",{className:"relative overflow-hidden bg-gradient-to-br from-purple-50 to-indigo-50 rounded-[16px] p-6 text-center border border-purple-100/50 shadow-sm flex flex-col items-center justify-center group hover:-translate-y-1 transition-transform",children:[e.jsx("div",{className:"absolute -right-4 -top-4 w-16 h-16 bg-purple-200/30 rounded-full group-hover:scale-150 transition-transform duration-500"}),e.jsx("span",{className:"text-[36px] font-extrabold text-transparent bg-clip-text bg-gradient-to-r from-[#a855f7] to-[#9333ea] leading-none mb-1 relative z-10",children:x.value}),e.jsx("span",{className:"text-[13px] font-bold text-[#64748b] relative z-10",children:x.label})]},x.label))}),e.jsxs("div",{className:"bg-slate-50/80 rounded-[14px] p-5 border border-slate-200/60 text-[#475569] text-[14px] leading-relaxed flex gap-4 items-start shadow-inner",children:[e.jsx(na,{size:18,className:"text-[#94a3b8] shrink-0 mt-0.5"}),e.jsxs("p",{children:[A.map(x=>Wa[x]?.label).join(" and ")," questions across"," ",e.jsxs("span",{className:"font-bold text-[#1e293b]",children:[f.filter(x=>!w.includes(x)).length," topics"]})," ","— aligned to ",e.jsx("span",{className:"font-semibold",children:q.map(x=>Do[x]?.label).join(", ")})," levels of Bloom's Taxonomy."," ",e.jsxs("span",{className:"font-semibold text-emerald-600",children:["Easy ",ne.easy,"%"]})," • ",e.jsxs("span",{className:"font-semibold text-amber-500",children:["Medium ",ne.medium,"%"]})," • ",e.jsxs("span",{className:"font-semibold text-rose-500",children:["Hard ",ne.hard,"%"]}),"."]})]})]})}),v==="results"&&ae&&e.jsxs("div",{className:"w-full px-[24px] xl:px-[32px] space-y-[24px] pb-8",children:[e.jsxs("div",{className:"bg-white/80 backdrop-blur-md rounded-[20px] border border-[#e2e8f0] shadow-[0_8px_24px_rgba(0,0,0,0.04)] p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h3",{className:"text-lg font-bold font-display text-[#0a1628]",children:"Quiz Generated"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:Tl,className:"flex items-center gap-1.5 px-3 py-1.5 bg-white border border-[#dde3eb] rounded-lg text-xs font-medium text-[#5a6578] hover:bg-[#edf1f7] transition-colors",children:[ft?e.jsx(Ht,{size:14,className:"text-green-500"}):e.jsx(Vr,{size:14}),ft?"Copied!":"Copy All"]}),e.jsxs("button",{onClick:_l,className:"flex items-center gap-1.5 px-3 py-1.5 bg-white border border-[#dde3eb] rounded-lg text-xs font-medium text-[#5a6578] hover:bg-[#edf1f7] transition-colors",children:[e.jsx(bc,{size:14}),"Export JSON"]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4 md:gap-6",children:[e.jsxs("div",{className:"relative overflow-hidden bg-gradient-to-br from-[#a855f7] to-[#9333ea] text-white shadow-[0_8px_16px_rgba(168,85,247,0.25)] rounded-[20px] p-6 text-center flex flex-col items-center justify-center group hover:-translate-y-1 transition-transform",children:[e.jsx("div",{className:"absolute -right-4 -top-4 w-20 h-20 bg-white/10 rounded-full group-hover:scale-150 transition-transform duration-500"}),e.jsx(Rs,{size:22,className:"text-white/80 mb-2 relative z-10"}),e.jsx("span",{className:"text-[32px] font-extrabold leading-none mb-1 relative z-10 drop-shadow-sm",children:ae.questions.length}),e.jsx("span",{className:"text-[12px] font-bold text-white/90 uppercase tracking-widest relative z-10",children:"Questions"})]}),e.jsxs("div",{className:"relative overflow-hidden bg-gradient-to-br from-[#f43f5e] to-[#e11d48] text-white shadow-[0_8px_16px_rgba(244,63,94,0.25)] rounded-[20px] p-6 text-center flex flex-col items-center justify-center group hover:-translate-y-1 transition-transform",children:[e.jsx("div",{className:"absolute -right-4 -top-4 w-20 h-20 bg-white/10 rounded-full group-hover:scale-150 transition-transform duration-500"}),e.jsx(ms,{size:22,className:"text-white/80 mb-2 relative z-10"}),e.jsx("span",{className:"text-[32px] font-extrabold leading-none mb-1 relative z-10 drop-shadow-sm",children:ae.totalPoints}),e.jsx("span",{className:"text-[12px] font-bold text-white/90 uppercase tracking-widest relative z-10",children:"Total Points"})]}),e.jsxs("div",{className:"relative overflow-hidden bg-gradient-to-br from-[#f59e0b] to-[#d97706] text-white shadow-[0_8px_16px_rgba(245,158,11,0.25)] rounded-[20px] p-6 text-center flex flex-col items-center justify-center group hover:-translate-y-1 transition-transform",children:[e.jsx("div",{className:"absolute -right-4 -top-4 w-20 h-20 bg-white/10 rounded-full group-hover:scale-150 transition-transform duration-500"}),e.jsx(Gt,{size:22,className:"text-white/80 mb-2 relative z-10"}),e.jsx("span",{className:"text-[32px] font-extrabold leading-none mb-1 relative z-10 drop-shadow-sm",children:Object.keys(ae.metadata.topicsCovered).length}),e.jsx("span",{className:"text-[12px] font-bold text-white/90 uppercase tracking-widest relative z-10",children:"Topics"})]}),e.jsxs("div",{className:"relative overflow-hidden bg-gradient-to-br from-[#10b981] to-[#059669] text-white shadow-[0_8px_16px_rgba(16,185,129,0.25)] rounded-[20px] p-6 text-center flex flex-col items-center justify-center group hover:-translate-y-1 transition-transform",children:[e.jsx("div",{className:"absolute -right-4 -top-4 w-20 h-20 bg-white/10 rounded-full group-hover:scale-150 transition-transform duration-500"}),e.jsx(lr,{size:22,className:"text-white/80 mb-2 relative z-10"}),e.jsx("span",{className:"text-[32px] font-extrabold leading-none mb-1 relative z-10 drop-shadow-sm",children:Object.keys(ae.metadata.bloomTaxonomyDistribution).length}),e.jsx("span",{className:"text-[12px] font-bold text-white/90 uppercase tracking-widest relative z-10",children:"Bloom Levels"})]})]}),(ae.metadata.usedImportedTopics||(ae.metadata.topicProvenance||[]).length>0)&&e.jsxs("div",{className:"mt-4 bg-white rounded-lg p-3 border border-[#dde3eb]",children:[e.jsx("p",{className:"text-xs font-semibold text-[#5a6578] mb-2",children:"Imported Topic Provenance"}),e.jsxs("p",{className:"text-xs text-[#5a6578] mb-2",children:["Imported topics used: ",ae.metadata.usedImportedTopics?"Yes":"No"," • ","Materials: ",ae.metadata.importedMaterialsCount??0," • ","Topics: ",ae.metadata.importedTopicCount??0]}),(ae.metadata.topicProvenance||[]).slice(0,5).map((x,O)=>e.jsxs("div",{className:"text-xs text-[#5a6578]",children:[x.title||"Untitled topic",x.sourceFile?` • ${x.sourceFile}`:""]},`${x.topicId||x.title||"topic"}_${O}`)),(Ee.length>0||Oe.length>0)&&e.jsxs("div",{className:"mt-3 grid grid-cols-1 md:grid-cols-2 gap-2",children:[e.jsxs("label",{className:"text-xs text-[#5a6578] flex flex-col gap-1",children:[e.jsx("span",{className:"font-semibold",children:"Filter by Source File"}),e.jsxs("select",{value:ns,onChange:x=>vs(x.target.value),className:"bg-white border border-[#dde3eb] rounded-md px-2 py-1.5 text-xs",children:[e.jsx("option",{value:"all",children:"All sources"}),Ee.map(x=>e.jsx("option",{value:x,children:x},x))]})]}),e.jsxs("label",{className:"text-xs text-[#5a6578] flex flex-col gap-1",children:[e.jsx("span",{className:"font-semibold",children:"Filter by Material ID"}),e.jsxs("select",{value:os,onChange:x=>L(x.target.value),className:"bg-white border border-[#dde3eb] rounded-md px-2 py-1.5 text-xs",children:[e.jsx("option",{value:"all",children:"All materials"}),Oe.map(x=>e.jsx("option",{value:x,children:x},x))]})]})]}),e.jsxs("p",{className:"text-[11px] text-[#5a6578] mt-2",children:["Showing ",Pt.length," of ",ae.questions.length," questions after provenance filters."]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-6 mt-8 mb-10",children:[e.jsxs("div",{className:"bg-white border border-[#e2e8f0] rounded-[16px] p-6 shadow-sm border-t-[4px] border-t-[#10b981] hover:shadow-md transition-shadow",children:[e.jsxs("h4",{className:"text-[12px] font-bold text-[#64748b] uppercase tracking-wider mb-5 flex items-center gap-2",children:[e.jsx(Ls,{size:14})," Difficulty"]}),e.jsx("div",{className:"space-y-3 text-[14px] font-medium text-[#475569]",children:Object.entries(ae.metadata.difficultyBreakdown).map(([x,O])=>e.jsxs("div",{className:"flex justify-between items-center bg-slate-50 px-3 py-2 rounded-lg",children:[e.jsx("span",{className:`font-bold capitalize ${km[x]||"text-[#475569]"}`,children:x}),e.jsx("span",{className:"font-bold text-[#1e293b] bg-white px-2 py-0.5 rounded shadow-sm border border-slate-100",children:O})]},x))})]}),e.jsxs("div",{className:"bg-white border border-[#e2e8f0] rounded-[16px] p-6 shadow-sm border-t-[4px] border-t-[#a855f7] hover:shadow-md transition-shadow",children:[e.jsxs("h4",{className:"text-[12px] font-bold text-[#64748b] uppercase tracking-wider mb-5 flex items-center gap-2",children:[e.jsx(Ur,{size:14})," Bloom's Taxonomy"]}),e.jsx("div",{className:"space-y-3 text-[14px] font-medium text-[#475569]",children:Object.entries(ae.metadata.bloomTaxonomyDistribution).map(([x,O])=>e.jsxs("div",{className:"flex justify-between items-center bg-slate-50 px-3 py-2 rounded-lg",children:[e.jsx("span",{className:"text-[#1e293b] font-semibold capitalize",children:x}),e.jsx("span",{className:"font-bold text-[#1e293b] bg-white px-2 py-0.5 rounded shadow-sm border border-slate-100",children:O})]},x))})]}),e.jsxs("div",{className:"bg-white border border-[#e2e8f0] rounded-[16px] p-6 shadow-sm border-t-[4px] border-t-[#0ea5e9] hover:shadow-md transition-shadow",children:[e.jsxs("h4",{className:"text-[12px] font-bold text-[#64748b] uppercase tracking-wider mb-5 flex items-center gap-2",children:[e.jsx(lr,{size:14})," Question Types"]}),e.jsx("div",{className:"space-y-3 text-[14px] font-medium text-[#475569]",children:Object.entries(ae.metadata.questionTypeBreakdown).map(([x,O])=>e.jsxs("div",{className:"flex justify-between items-center bg-slate-50 px-3 py-2 rounded-lg",children:[e.jsx("span",{className:"text-[#1e293b] font-semibold",children:Wa[x]?.label||x}),e.jsx("span",{className:"font-bold text-[#1e293b] bg-white px-2 py-0.5 rounded shadow-sm border border-slate-100",children:O})]},x))})]})]}),e.jsxs("div",{className:"bg-gradient-to-r from-purple-50 to-indigo-50/50 border border-purple-100 rounded-[16px] p-6 mb-10 flex items-start gap-4 shadow-sm relative overflow-hidden",children:[e.jsx("div",{className:"absolute top-0 left-0 w-1.5 h-full bg-[#a855f7]"}),e.jsx("div",{className:"bg-white p-2 rounded-full shadow-sm shrink-0",children:e.jsx(na,{size:18,className:"text-[#9333ea]"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[14px] font-bold text-[#9333ea] mb-3",children:ae.metadata.supplementalPurpose||"This quiz is designed to supplement classroom instruction, not replace teacher-led learning."}),ae.metadata.recommendedTeacherActions&&ae.metadata.recommendedTeacherActions.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] font-bold text-[#1e293b] mb-2",children:"Recommended Actions:"}),e.jsx("ul",{className:"list-disc pl-5 text-[13px] font-medium text-[#475569] space-y-1.5",children:ae.metadata.recommendedTeacherActions.map((x,O)=>e.jsx("li",{children:x},O))})]})]})]})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("h3",{className:"text-[18px] font-bold text-[#1e293b] flex items-center gap-2",children:[e.jsx(yi,{size:20,className:"text-[#a855f7]"})," Review Questions"]}),e.jsx("div",{className:"space-y-4",children:Pt.length>0?Pt.map((x,O)=>zl(x,O)):e.jsx("div",{className:"border border-[#dde3eb] rounded-xl p-4 bg-white text-sm text-[#5a6578]",children:"No questions match the selected provenance filters. Clear one or both filters to view all questions."})})]})]})]})]}),k==="create"&&e.jsx("div",{className:"sticky bottom-0 mt-auto w-full bg-white/90 backdrop-blur-[12px] border-t border-[#e2e8f0] z-30 shadow-[0_-4px_12px_rgba(0,0,0,0.03)]",children:e.jsxs("div",{className:"w-full px-6 xl:px-8 py-4 flex items-center justify-between",children:[e.jsxs("div",{children:[v==="topics"&&!te&&e.jsx("button",{onClick:()=>{C([]),$([])},className:"text-[13px] font-semibold text-[#a855f7] hover:underline",children:"Clear all"}),(v==="style"||v==="preview")&&!te&&e.jsxs("button",{onClick:()=>g(v==="preview"?"style":"topics"),className:"bg-white hover:bg-slate-50 border border-slate-200 text-[#475569] text-[14px] font-semibold rounded-full px-6 py-2.5 shadow-sm transition-transform hover:scale-[1.02] flex items-center gap-2",children:[e.jsx(zs,{size:16})," Back"]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[v==="setup"&&!te&&e.jsxs("button",{onClick:()=>g("topics"),className:"bg-[#a855f7] hover:bg-[#9333ea] text-white text-[14px] font-semibold rounded-full px-8 py-2.5 shadow-[0_4px_12px_rgba(168,85,247,0.3)] transition-transform hover:scale-[1.02] flex items-center gap-2",children:["Next: Topics ",e.jsx(Ms,{size:16})]}),v==="topics"&&!te&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:()=>g("setup"),className:"bg-white hover:bg-slate-50 border border-slate-200 text-[#475569] text-[14px] font-semibold rounded-full px-6 py-2.5 shadow-sm transition-transform hover:scale-[1.02] flex items-center gap-2",children:[e.jsx(zs,{size:16})," Back"]}),e.jsxs("button",{onClick:()=>g("style"),className:"bg-[#a855f7] hover:bg-[#9333ea] text-white text-[14px] font-semibold rounded-full px-6 py-2.5 shadow-[0_4px_12px_rgba(168,85,247,0.3)] transition-transform hover:scale-[1.02] flex items-center gap-2",children:["Next: Question Style ",e.jsx(Ms,{size:16})]})]}),v==="style"&&!te&&e.jsxs("button",{onClick:()=>g("preview"),className:"bg-[#a855f7] hover:bg-[#9333ea] text-white text-[14px] font-semibold rounded-full px-8 py-2.5 shadow-[0_4px_12px_rgba(168,85,247,0.3)] transition-transform hover:scale-[1.02] flex items-center gap-2",children:["Next: Preview ",e.jsx(Ms,{size:16})]}),v==="preview"&&!te&&!ae&&e.jsxs("button",{onClick:Il,className:"bg-[#a855f7] hover:bg-[#9333ea] text-white text-[14px] font-bold rounded-full px-8 py-2.5 shadow-[0_4px_12px_rgba(168,85,247,0.3)] transition-all hover:scale-[1.02] flex items-center gap-2",children:[e.jsx(Ht,{size:16})," Generate Quiz"]}),te&&e.jsxs("div",{className:"flex items-center gap-3 text-slate-500 font-medium text-sm",children:[e.jsx(gt,{size:16,className:"animate-spin"})," Generating quiz... Please wait."]}),v==="results"&&(Ua?e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>{N("bank"),Us(null)},className:"bg-white hover:bg-slate-50 border border-slate-200 text-[#475569] text-[14px] font-semibold rounded-full px-6 py-2.5 shadow-sm transition-transform hover:scale-[1.02]",children:"Back to Quiz Bank"}),e.jsxs("button",{onClick:()=>Ir(Ua),className:"bg-white border border-[#a855f7] text-[#9333ea] hover:bg-purple-50 text-[14px] font-bold rounded-full px-8 py-2.5 shadow-sm transition-transform hover:scale-[1.02] flex items-center gap-2",children:[e.jsx(aa,{size:16})," Assign"]}),e.jsx("button",{onClick:Cn,className:"bg-[#a855f7] hover:bg-[#9333ea] text-white text-[14px] font-bold rounded-full px-10 py-2.5 shadow-[0_4px_12px_rgba(168,85,247,0.3)] transition-transform hover:scale-[1.02]",children:"Done"})]}):e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>{g("setup"),Ce(null),Je(null),kt(null),Us(null)},className:"bg-white hover:bg-slate-50 border border-slate-200 text-[#475569] text-[14px] font-semibold rounded-full px-6 py-2.5 shadow-sm transition-transform hover:scale-[1.02]",children:"Create Another"}),B?e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:Rl,disabled:Me,className:"bg-white border border-[#a855f7] text-[#9333ea] hover:bg-purple-50 text-[14px] font-bold rounded-full px-8 py-2.5 shadow-sm transition-transform hover:scale-[1.02] flex items-center gap-2",children:[Me?e.jsx(gt,{size:16,className:"animate-spin"}):e.jsx(la,{size:16})," Publish"]}),e.jsxs("button",{onClick:()=>Ir(),className:"bg-[#a855f7] hover:bg-[#9333ea] text-white text-[14px] font-bold rounded-full px-8 py-2.5 shadow-[0_4px_12px_rgba(168,85,247,0.3)] transition-transform hover:scale-[1.02] flex items-center gap-2",children:[e.jsx(aa,{size:16})," Assign to Class"]})]}):e.jsxs("button",{onClick:El,disabled:me,className:"bg-emerald-600 hover:bg-emerald-700 text-white px-8 py-2.5 rounded-full font-bold shadow-lg shadow-emerald-500/30 hover:-translate-y-1 transition-all flex items-center gap-2 text-[14px]",children:[me?e.jsx(gt,{size:16,className:"animate-spin"}):e.jsx(Ni,{size:16})," Save to Library"]}),e.jsx("button",{onClick:Cn,className:"bg-[#a855f7] hover:bg-[#9333ea] text-white text-[14px] font-bold rounded-full px-10 py-2.5 shadow-[0_4px_12px_rgba(168,85,247,0.3)] transition-transform hover:scale-[1.02]",children:"Done"})]}))]})]})}),e.jsx(wm,{isOpen:bs,onClose:()=>Bs(!1)}),e.jsx(zt,{children:F&&e.jsx(Le.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 bg-black/40 z-[60] flex items-center justify-center p-4",onClick:()=>ve(!1),children:e.jsxs(Le.div,{initial:{scale:.95,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.95,opacity:0},className:"bg-[#f7f9fc] rounded-2xl shadow-2xl w-full max-w-md max-h-[70vh] flex flex-col overflow-hidden border border-[#dde3eb]",onClick:x=>x.stopPropagation(),children:[e.jsxs("div",{className:"px-5 py-4 border-b border-[#dde3eb] flex items-center justify-between",children:[e.jsxs("h3",{className:"text-base font-bold font-display text-[#0a1628] flex items-center gap-2",children:[e.jsx(us,{size:18,className:"text-sky-600"}),"Assign to Student"]}),e.jsx("button",{onClick:()=>ve(!1),className:"p-1 hover:bg-[#edf1f7] rounded-lg transition-colors",children:e.jsx(Xt,{size:16,className:"text-slate-500"})})]}),e.jsx("div",{className:"px-5 py-3 border-b border-[#dde3eb]",children:e.jsxs("div",{className:"flex items-center gap-2 bg-[#edf1f7] rounded-xl px-3 py-2",children:[e.jsx(qs,{size:14,className:"text-slate-500"}),e.jsx("input",{type:"text",placeholder:"Search students…",value:rt,onChange:x=>nt(x.target.value),className:"flex-1 bg-transparent text-sm outline-none placeholder:text-slate-500"})]})}),e.jsx("div",{className:"flex-1 overflow-y-auto p-3 space-y-1",children:lt?e.jsx("div",{className:"flex items-center justify-center py-10",children:e.jsx(gt,{size:20,className:"animate-spin text-sky-500"})}):En.length===0?e.jsx("p",{className:"text-center text-sm text-slate-500 py-10",children:"No students found"}):En.map(x=>e.jsxs("button",{onClick:()=>ws(x.id),className:`w-full flex items-center gap-3 px-3 py-2.5 rounded-xl text-left transition-colors ${ut===x.id?"bg-sky-50 border border-sky-300":"hover:bg-[#edf1f7] border border-transparent"}`,children:[e.jsx("img",{src:x.avatar&&!x.avatar.includes("ui-avatars.com")?x.avatar:Ja(x.gender),alt:x.name,className:"w-8 h-8 rounded-lg object-cover"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-semibold text-[#0a1628] truncate",children:x.name}),e.jsx("p",{className:"text-xs text-slate-500 truncate",children:x.email})]}),ut===x.id&&e.jsx(Ht,{size:16,className:"text-sky-600 flex-shrink-0"})]},x.id))}),e.jsxs("div",{className:"px-5 py-3 border-t border-[#dde3eb] flex justify-end gap-2",children:[e.jsx("button",{onClick:()=>ve(!1),className:"px-4 py-2 text-sm font-medium text-[#5a6578] hover:bg-[#edf1f7] rounded-xl transition-colors",children:"Cancel"}),e.jsxs("button",{onClick:Ml,disabled:!ut||we,className:`flex items-center gap-2 px-4 py-2 rounded-xl text-sm font-bold transition-all ${ut&&!we?"bg-gradient-to-r from-sky-600 to-sky-500 text-white shadow-sm":"bg-[#dde3eb] text-slate-500 cursor-not-allowed"}`,children:[we?e.jsx(gt,{size:14,className:"animate-spin"}):e.jsx(aa,{size:14}),"Assign"]})]})]})})})]});return d?e.jsx("div",{className:"w-full h-full flex flex-col overflow-hidden bg-white",children:An}):An},Cm=({onOpenNotifications:t,onOpenProfile:s,onOpenInsightModal:a,userPhoto:r,teacherName:o})=>{const[n,i]=u.useState([]),[l,c]=u.useState(!1),[d,m]=u.useState(!1),[p,h]=u.useState(""),[b,S]=u.useState(11),[k,N]=u.useState("general_mathematics"),[v,g]=u.useState([]),[I,z]=u.useState(!1),[R,W]=u.useState(null),f=u.useCallback(async()=>{z(!0);try{const y=At(Mt(He,"question_bank",String(b),k,"questions","questions"),or(50));let J=(await Ot(y)).docs.map(re=>{const le=re.data();return{id:re.id,question:le.question||"",choices:le.choices||[],correct_answer:le.correct_answer||"",explanation:le.explanation||"",topic:le.topic||"",difficulty:le.difficulty||"medium",grade_level:le.grade_level||11}});if(J.length===0){const re=At(Mt(He,"quizBattleQuestionBank"),or(50));J=(await Ot(re)).docs.map(ne=>{const be=ne.data();return{id:ne.id,question:be.question||"",choices:be.choices||[],correct_answer:be.correct_answer||"",explanation:be.explanation||"",topic:be.topic||"",difficulty:be.difficulty||"medium",grade_level:be.grade_level||11}})}g(J)}catch(y){console.warn("[QuestionBankPanel] Failed to load questions:",y)}finally{z(!1)}},[b,k]);u.useEffect(()=>{f()},[f]);const C=u.useCallback(async()=>{c(!0);try{const y=await Dn("/api/quiz-battle/bank-status");i(y.pdfs)}catch(y){const q=y instanceof rr?y.message:"Failed to load bank status";ie.error(q)}finally{c(!1)}},[]);u.useEffect(()=>{C()},[C]);const w=async()=>{if(!p.trim()){ie.error("Please enter a storage path");return}m(!0);try{await Dn("/api/quiz-battle/ingest-pdf",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({storage_path:p.trim(),grade_level:b,topic:k.trim(),force_reingest:!1})}),ie.success("PDF ingestion completed"),await C(),h("")}catch(y){const q=y instanceof rr?y.message:"Ingestion failed";ie.error(q)}finally{m(!1)}},$=n.reduce((y,q)=>y+q.question_count,0),A=n.filter(y=>y.processed).length;return e.jsxs("div",{className:"w-full h-full flex flex-col overflow-y-auto bg-gradient-to-br from-[#f8fafc] to-[#f1f5f9]",children:[e.jsx("div",{className:"w-full px-[24px] xl:px-[32px] pt-[12px] pb-2"}),e.jsxs("div",{className:"w-full px-[24px] xl:px-[32px] pb-[32px] space-y-[32px]",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-6",children:[e.jsxs("div",{className:"relative overflow-hidden bg-gradient-to-br from-[#3b82f6] to-[#2563eb] rounded-[16px] p-[20px] shadow-[0_4px_12px_rgba(59,130,246,0.2)] hover:shadow-[0_8px_24px_rgba(59,130,246,0.3)] hover:-translate-y-1 transition-all duration-300 flex flex-col justify-between group text-white",children:[e.jsx("div",{className:"absolute -right-12 -bottom-12 w-40 h-40 bg-white/10 rounded-full transition-transform duration-500 group-hover:scale-[1.8] group-hover:-translate-y-4 group-hover:-translate-x-4"}),e.jsxs("div",{className:"flex items-start justify-between relative z-10 mb-4",children:[e.jsx("span",{className:"text-[13px] font-medium text-white/90",children:"Total PDFs"}),e.jsx("div",{className:"w-8 h-8 rounded-full border border-white/30 flex items-center justify-center bg-white/10",children:e.jsx(Rs,{size:16,className:"text-white"})})]}),e.jsx("div",{className:"text-[32px] font-bold relative z-10 leading-none",children:n.length})]}),e.jsxs("div",{className:"relative overflow-hidden bg-gradient-to-br from-[#a855f7] to-[#9333ea] rounded-[16px] p-[20px] shadow-[0_4px_12px_rgba(168,85,247,0.2)] hover:shadow-[0_8px_24px_rgba(168,85,247,0.3)] hover:-translate-y-1 transition-all duration-300 flex flex-col justify-between group text-white",children:[e.jsx("div",{className:"absolute -right-12 -bottom-12 w-40 h-40 bg-white/10 rounded-full transition-transform duration-500 group-hover:scale-[1.8] group-hover:-translate-y-4 group-hover:-translate-x-4"}),e.jsxs("div",{className:"flex items-start justify-between relative z-10 mb-4",children:[e.jsx("span",{className:"text-[13px] font-medium text-white/90",children:"Total Questions"}),e.jsx("div",{className:"w-8 h-8 rounded-full border border-white/30 flex items-center justify-center bg-white/10",children:e.jsx(Gt,{size:16,className:"text-white"})})]}),e.jsx("div",{className:"text-[32px] font-bold relative z-10 leading-none",children:$})]}),e.jsxs("div",{className:"relative overflow-hidden bg-gradient-to-br from-[#10b981] to-[#059669] rounded-[16px] p-[20px] shadow-[0_4px_12px_rgba(16,185,129,0.2)] hover:shadow-[0_8px_24px_rgba(16,185,129,0.3)] hover:-translate-y-1 transition-all duration-300 flex flex-col justify-between group text-white",children:[e.jsx("div",{className:"absolute -right-12 -bottom-12 w-40 h-40 bg-white/10 rounded-full transition-transform duration-500 group-hover:scale-[1.8] group-hover:-translate-y-4 group-hover:-translate-x-4"}),e.jsxs("div",{className:"flex items-start justify-between relative z-10 mb-4",children:[e.jsx("span",{className:"text-[13px] font-medium text-white/90",children:"Processed"}),e.jsx("div",{className:"w-8 h-8 rounded-full border border-white/30 flex items-center justify-center bg-white/10",children:e.jsx(cs,{size:16,className:"text-white"})})]}),e.jsx("div",{className:"text-[32px] font-bold relative z-10 leading-none",children:A})]})]}),e.jsx("div",{className:"bg-white/80 backdrop-blur-[12px] rounded-[24px] border border-white shadow-[0_8px_32px_rgba(0,0,0,0.04)] overflow-hidden",children:e.jsxs("div",{className:"p-[24px] sm:p-[32px]",children:[e.jsxs("h2",{className:"text-[20px] font-bold text-[#1e293b] mb-6 flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-[10px] bg-gradient-to-br from-[#a855f7] to-[#9333ea] flex items-center justify-center shadow-md shadow-purple-500/20",children:e.jsx(Wr,{className:"w-4 h-4 text-white"})}),"Ingest New PDF"]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-12 gap-6 items-end",children:[e.jsxs("div",{className:"md:col-span-6 group",children:[e.jsx("label",{className:"text-[13px] font-bold text-[#1e293b] mb-2 block group-hover:text-[#a855f7] transition-colors",children:"Firebase Storage Path"}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-y-0 left-0 pl-4 flex items-center pointer-events-none",children:e.jsx(Rs,{className:"h-4 w-4 text-[#94a3b8] group-hover:text-[#a855f7] transition-colors"})}),e.jsx("input",{type:"text",placeholder:"quiz_pdfs/grade_11/gen_math_q1.pdf",value:p,onChange:y=>h(y.target.value),className:"w-full bg-slate-50 border border-slate-200 hover:border-[#cbd5e1] text-[#475569] text-[14px] font-medium rounded-xl pl-11 pr-4 py-3.5 outline-none focus:bg-white focus:border-[#a855f7] focus:ring-4 focus:ring-[#a855f7]/10 transition-all shadow-inner"})]})]}),e.jsxs("div",{className:"md:col-span-2 group",children:[e.jsx("label",{className:"text-[13px] font-bold text-[#1e293b] mb-2 block group-hover:text-[#a855f7] transition-colors",children:"Grade Level"}),e.jsx("input",{type:"number",placeholder:"11",min:7,max:12,value:b,onChange:y=>S(Number(y.target.value)),className:"w-full bg-slate-50 border border-slate-200 hover:border-[#cbd5e1] text-[#475569] text-[14px] font-medium rounded-xl px-4 py-3.5 outline-none focus:bg-white focus:border-[#a855f7] focus:ring-4 focus:ring-[#a855f7]/10 transition-all shadow-inner"})]}),e.jsxs("div",{className:"md:col-span-4 group",children:[e.jsx("label",{className:"text-[13px] font-bold text-[#1e293b] mb-2 block group-hover:text-[#a855f7] transition-colors",children:"Topic Slug"}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-y-0 left-0 pl-4 flex items-center pointer-events-none",children:e.jsx(Gt,{className:"h-4 w-4 text-[#94a3b8] group-hover:text-[#a855f7] transition-colors"})}),e.jsx("input",{type:"text",placeholder:"general_mathematics",value:k,onChange:y=>N(y.target.value),className:"w-full bg-slate-50 border border-slate-200 hover:border-[#cbd5e1] text-[#475569] text-[14px] font-medium rounded-xl pl-11 pr-4 py-3.5 outline-none focus:bg-white focus:border-[#a855f7] focus:ring-4 focus:ring-[#a855f7]/10 transition-all shadow-inner"})]})]})]}),e.jsx("div",{className:"mt-6 flex justify-end pt-6 border-t border-slate-100",children:e.jsxs("button",{onClick:w,disabled:d,className:"bg-gradient-to-r from-[#a855f7] to-[#9333ea] hover:from-[#9333ea] hover:to-[#7e22ce] text-white text-[14px] font-bold rounded-full px-8 py-3 shadow-[0_4px_16px_rgba(168,85,247,0.3)] transition-all hover:scale-[1.02] flex items-center gap-2 hover:shadow-[0_8px_24px_rgba(168,85,247,0.4)] disabled:opacity-50 disabled:hover:scale-100",children:[d?e.jsx(gt,{className:"w-4 h-4 animate-spin"}):e.jsx(Wr,{className:"w-4 h-4"}),"Ingest PDF"]})})]})}),e.jsxs("div",{className:"bg-white/80 backdrop-blur-[12px] rounded-[24px] border border-white shadow-[0_8px_32px_rgba(0,0,0,0.04)] p-[24px] sm:p-[32px]",children:[e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsx("h2",{className:"text-[20px] font-bold text-[#1e293b]",children:"Processing Status"}),e.jsx("button",{onClick:C,disabled:l,className:"w-9 h-9 rounded-full bg-white border border-slate-200 flex items-center justify-center text-[#64748b] hover:text-[#9333ea] hover:border-purple-200 shadow-sm transition-all hover:scale-105 active:scale-95 disabled:opacity-50",children:e.jsx(cs,{className:`w-4 h-4 ${l?"animate-spin":""}`})})]}),e.jsx("div",{className:"bg-white rounded-[16px] border border-[#f1f5f9] overflow-hidden shadow-[0_1px_4px_rgba(0,0,0,0.02)]",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-left border-collapse",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-[#9956DE] border-b border-[#8b5cf6] shadow-md relative z-10",children:[e.jsx("th",{className:"h-12 px-6 text-[11px] font-bold text-white uppercase tracking-wider whitespace-nowrap",children:"Filename"}),e.jsx("th",{className:"h-12 px-6 text-[11px] font-bold text-white uppercase tracking-wider whitespace-nowrap",children:"Grade"}),e.jsx("th",{className:"h-12 px-6 text-[11px] font-bold text-white uppercase tracking-wider whitespace-nowrap",children:"Topic"}),e.jsx("th",{className:"h-12 px-6 text-[11px] font-bold text-white uppercase tracking-wider whitespace-nowrap text-center",children:"Questions"}),e.jsx("th",{className:"h-12 px-6 text-[11px] font-bold text-white uppercase tracking-wider whitespace-nowrap",children:"Status"}),e.jsx("th",{className:"h-12 px-6 text-[11px] font-bold text-white uppercase tracking-wider whitespace-nowrap",children:"Processed At"})]})}),e.jsxs("tbody",{className:"divide-y divide-[#f1f5f9] bg-white",children:[n.map(y=>e.jsxs("tr",{className:"hover:bg-slate-50/50 transition-colors group",children:[e.jsx("td",{className:"py-4 px-6",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`w-8 h-8 rounded-lg flex items-center justify-center shrink-0 ${y.processed?"bg-indigo-50 text-indigo-500":"bg-amber-50 text-amber-500"}`,children:e.jsx(Rs,{className:"w-4 h-4"})}),e.jsx("span",{className:"text-[13px] font-bold text-[#1e293b] group-hover:text-purple-600 transition-colors line-clamp-1",children:y.filename})]})}),e.jsx("td",{className:"py-4 px-6 text-[13px] font-semibold text-[#475569]",children:y.grade_level}),e.jsx("td",{className:"py-4 px-6",children:e.jsx("span",{className:"text-[12px] font-medium bg-slate-100 text-slate-600 px-2.5 py-1 rounded-md line-clamp-1",children:y.topic})}),e.jsx("td",{className:"py-4 px-6 text-[13px] font-bold text-[#1e293b] text-center",children:y.question_count||"-"}),e.jsx("td",{className:"py-4 px-6",children:e.jsxs("span",{className:`inline-flex items-center gap-1.5 px-3 py-1 text-[11px] font-bold rounded-full border shadow-sm ${y.processed?"bg-emerald-50 text-emerald-600 border-emerald-200/50":"bg-amber-50 text-amber-600 border-amber-200/50"}`,children:[y.processed?e.jsx(cs,{className:"w-3 h-3"}):e.jsx(gt,{className:"w-3 h-3 animate-spin"}),y.processed?"Completed":"Processing..."]})}),e.jsx("td",{className:"py-4 px-6 text-[13px] font-medium text-[#64748b]",children:y.timestamp?new Date(y.timestamp).toLocaleDateString():"-"})]},y.filename)),n.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:6,className:"py-12 px-6 text-center",children:e.jsxs("div",{className:"flex flex-col items-center justify-center text-[#64748b]",children:[e.jsx("div",{className:"w-16 h-16 bg-slate-50 rounded-full flex items-center justify-center mb-4 border border-slate-100",children:e.jsx(Rs,{className:"w-8 h-8 text-slate-300"})}),e.jsx("p",{className:"text-[14px] font-bold text-[#1e293b] mb-1",children:"No PDFs processed yet"}),e.jsx("p",{className:"text-[13px]",children:"Upload a PDF using the form above to get started."})]})})})]})]})})})]}),e.jsxs("div",{className:"bg-white/80 backdrop-blur-[12px] rounded-[24px] border border-white shadow-[0_8px_32px_rgba(0,0,0,0.04)] p-[24px] sm:p-[32px]",children:[e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsxs("h2",{className:"text-[20px] font-bold text-[#1e293b] flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-[10px] bg-gradient-to-br from-[#3b82f6] to-[#2563eb] flex items-center justify-center shadow-md shadow-blue-500/20",children:e.jsx(Gt,{className:"w-4 h-4 text-white"})}),"Question Bank (",v.length,")"]}),e.jsx("button",{onClick:f,disabled:I,className:"w-9 h-9 rounded-full bg-white border border-slate-200 flex items-center justify-center text-[#64748b] hover:text-[#9333ea] hover:border-purple-200 shadow-sm transition-all hover:scale-105 active:scale-95 disabled:opacity-50",children:e.jsx(cs,{className:`w-4 h-4 ${I?"animate-spin":""}`})})]}),I?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(gt,{className:"w-6 h-6 animate-spin text-[#9956DE]"})}):v.length===0?e.jsxs("div",{className:"text-center py-12 text-[#64748b]",children:[e.jsx(Gt,{className:"w-10 h-10 mx-auto mb-3 text-slate-300"}),e.jsx("p",{className:"text-[14px] font-bold text-[#1e293b] mb-1",children:"No questions in the bank yet"}),e.jsx("p",{className:"text-[13px]",children:"Ingest a PDF above to populate the question bank."})]}):e.jsx("div",{className:"space-y-2 max-h-[500px] overflow-y-auto",children:v.map(y=>e.jsxs("div",{className:"border border-[#f1f5f9] rounded-xl p-4 hover:border-purple-200 transition-colors bg-white",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 cursor-pointer",onClick:()=>W(R===y.id?null:y.id),children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-[13px] font-medium text-[#1e293b] line-clamp-2",children:y.question}),e.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[e.jsxs("span",{className:"text-[11px] px-2 py-0.5 rounded-md bg-blue-50 text-blue-600 font-semibold",children:["Grade ",y.grade_level]}),e.jsx("span",{className:"text-[11px] px-2 py-0.5 rounded-md bg-slate-100 text-slate-600 font-medium",children:y.topic}),e.jsx("span",{className:`text-[11px] px-2 py-0.5 rounded-md font-semibold ${y.difficulty==="easy"?"bg-green-50 text-green-600":y.difficulty==="hard"?"bg-rose-50 text-rose-600":"bg-amber-50 text-amber-600"}`,children:y.difficulty})]})]}),R===y.id?e.jsx(Ca,{size:16,className:"text-[#94a3b8] shrink-0"}):e.jsx($t,{size:16,className:"text-[#94a3b8] shrink-0"})]}),R===y.id&&e.jsxs("div",{className:"mt-3 pt-3 border-t border-[#f1f5f9] space-y-2",children:[e.jsx("div",{className:"space-y-1",children:y.choices.map((q,J)=>e.jsxs("p",{className:`text-[12px] px-3 py-1.5 rounded-lg ${q===y.correct_answer?"bg-green-50 text-green-700 font-semibold border border-green-200":"bg-slate-50 text-[#475569]"}`,children:[String.fromCharCode(65+J),". ",q]},J))}),y.explanation&&e.jsxs("p",{className:"text-[12px] text-[#64748b] italic mt-2 flex items-center gap-1",children:[e.jsx(vc,{size:12})," ",y.explanation]})]})]},y.id))})]})]})]})},Fo={totalTopicsTracked:0,masteredCount:0,needsAttentionCount:0,excludedCount:0},Im={"gen-math":{label:"General Mathematics",color:"bg-sky-100 text-sky-700"},"stats-prob":{label:"Statistics & Probability",color:"bg-sky-100 text-sky-700"},"pre-calc":{label:"Pre-Calculus",color:"bg-orange-100 text-orange-700"},"basic-calc":{label:"Basic Calculus",color:"bg-red-100 text-red-700"}},Oo={mastered:{label:"Mastered",color:"text-emerald-600 bg-emerald-50 border-emerald-100"},on_track:{label:"On Track",color:"text-amber-600 bg-amber-50 border-amber-100"},needs_attention:{label:"Needs Work",color:"text-rose-600 bg-rose-50 border-rose-100"},no_data:{label:"No Data",color:"text-slate-600 bg-slate-50 border-slate-200"}},Po={needs_attention:0,on_track:1,no_data:2,mastered:3},Tm=({classSectionId:t,onOpenNotifications:s,onOpenProfile:a})=>{const{currentUser:r,userProfile:o}=hs(),[n,i]=u.useState([]),[l,c]=u.useState(Fo),[d,m]=u.useState(!0),[p,h]=u.useState("all"),[b,S]=u.useState("all"),[k,N]=u.useState(""),[v,g]=u.useState("classAverage"),[I,z]=u.useState("asc"),R=Hn.map(H=>H.id),W=Hn.reduce((H,ee)=>(H[ee.id]=ee.name,H),{}),{isLoading:f,refetch:C}=Sc();u.useEffect(()=>{f||(console.log("[TopicMasteryView] Curriculum ready"),C())},[f,C]);const[w,$]=u.useState(new Set),[A,y]=u.useState([]),q=Nc({queryKey:Pl.topicMastery(r?.uid||"anonymous",t),enabled:!!r,staleTime:120*1e3,gcTime:900*1e3,queryFn:async()=>{try{if(!r)return{excluded:[],topics:[],summary:{totalTopicsTracked:0,masteredCount:0,needsAttentionCount:0,excludedCount:0}};const H=pt(He,"teachers",r.uid,"settings","quizSettings"),ee=await ks(H),oe=ee.exists()?ee.data()?.excludedTopics||[]:[],Re="https://deign86-mathpulse-api-v3test.hf.space",Fe=new URLSearchParams({teacherId:r.uid});t&&Fe.set("classSectionId",t);const Pe=await r.getIdToken(),G=await fetch(`${Re}/api/analytics/topic-mastery?${Fe.toString()}`,{headers:{Authorization:`Bearer ${Pe}`}});if(!G.ok)return{excluded:oe,topics:[],summary:{totalTopicsTracked:0,masteredCount:0,needsAttentionCount:0,excludedCount:oe.length}};const te=await G.json(),E=(te.topics||[]).map(Y=>({...Y,isExcluded:oe.includes(Y.topicName)}));return{excluded:oe,topics:E,summary:te.summary||{totalTopicsTracked:0,masteredCount:0,needsAttentionCount:0,excludedCount:oe.length}}}catch{return{excluded:[],topics:[],summary:{totalTopicsTracked:0,masteredCount:0,needsAttentionCount:0,excludedCount:0}}}}});u.useEffect(()=>{if(m(q.isLoading||q.isFetching),!q.data){y([]),i([]),c(Fo),$(new Set);return}y(q.data.excluded),i(q.data.topics),c(q.data.summary)},[q.data,q.isFetching,q.isLoading]);const J=async H=>{if(!r)return;const ee=A.includes(H)?A.filter(oe=>oe!==H):[...A,H];y(ee),i(oe=>oe.map(Re=>Re.topicName===H?{...Re,isExcluded:!Re.isExcluded}:Re)),c(oe=>({...oe,excludedCount:ee.length}));try{const oe=pt(He,"teachers",r.uid,"settings","quizSettings");(await ks(oe)).exists()?await es(oe,{excludedTopics:ee}):await ts(oe,{excludedTopics:ee})}catch{ie.error("Failed to update excluded topics")}},re=async()=>{if(!r)return;const H=[...new Set([...A,...w])];y(H),i(ee=>ee.map(oe=>w.has(oe.topicName)?{...oe,isExcluded:!0}:oe)),c(ee=>({...ee,excludedCount:H.length})),$(new Set);try{const ee=pt(He,"teachers",r.uid,"settings","quizSettings");(await ks(ee)).exists()?await es(ee,{excludedTopics:H}):await ts(ee,{excludedTopics:H}),ie.success(`${w.size} topics excluded from quizzes`)}catch{ie.error("Failed to update")}},le=async()=>{if(!r)return;const H=A.filter(ee=>!w.has(ee));y(H),i(ee=>ee.map(oe=>w.has(oe.topicName)?{...oe,isExcluded:!1}:oe)),c(ee=>({...ee,excludedCount:H.length})),$(new Set);try{const ee=pt(He,"teachers",r.uid,"settings","quizSettings");(await ks(ee)).exists()?await es(ee,{excludedTopics:H}):await ts(ee,{excludedTopics:H}),ie.success(`${w.size} topics re-included in quizzes`)}catch{ie.error("Failed to update")}},ne=H=>{v===H?z(ee=>ee==="asc"?"desc":"asc"):(g(H),z("asc"))},be=b==="all"?R:jc(b);u.useEffect(()=>{p!=="all"&&(be.includes(p)||h("all"))},[be,p]);const Ie=n.filter(H=>!(p!=="all"&&H.subjectId!==p||!be.includes(H.subjectId)||k&&!H.topicName.toLowerCase().includes(k.toLowerCase()))).sort((H,ee)=>{const oe=I==="asc"?1:-1;switch(v){case"topicName":return oe*H.topicName.localeCompare(ee.topicName);case"classAverage":return oe*(H.classAverage-ee.classAverage);case"studentsAttempted":return oe*(H.studentsAttempted-ee.studentsAttempted);case"masteryStatus":return oe*((Po[H.masteryStatus]||0)-(Po[ee.masteryStatus]||0));default:return 0}}),de=()=>{w.size===Ie.length?$(new Set):$(new Set(Ie.map(H=>H.topicName)))},fe=({field:H})=>v!==H?e.jsx($t,{size:14,className:"text-white/40"}):I==="asc"?e.jsx(Ca,{size:14,className:"text-white font-bold"}):e.jsx($t,{size:14,className:"text-white font-bold"});return d?e.jsxs("div",{className:"flex items-center justify-center py-20",children:[e.jsx(gt,{size:24,className:"animate-spin text-indigo-500"}),e.jsx("span",{className:"ml-2 text-[#64748b]",children:"Loading topic mastery data..."})]}):e.jsxs(Le.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},exit:{opacity:0,y:-20},className:"w-full p-[24px] xl:p-[32px] space-y-[24px]",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-[16px]",children:[e.jsxs("div",{className:"relative overflow-hidden bg-gradient-to-br from-[#a855f7] to-[#9333ea] rounded-[16px] p-[20px] shadow-[0_4px_12px_rgba(168,85,247,0.2)] flex flex-col justify-between h-full group text-white",children:[e.jsx("div",{className:"absolute -right-12 -bottom-12 w-40 h-40 bg-white/10 rounded-full"}),e.jsxs("div",{className:"flex items-start justify-between relative z-10 mb-4",children:[e.jsx("span",{className:"text-[13px] font-medium text-white/90",children:"Total Topics Tracked"}),e.jsx("div",{className:"w-8 h-8 rounded-full border border-white/30 flex items-center justify-center bg-white/10",children:e.jsx(Ls,{size:16,className:"text-white"})})]}),e.jsx("div",{className:"text-[32px] font-bold relative z-10 leading-none",children:l.totalTopicsTracked})]}),e.jsxs("div",{className:"relative overflow-hidden bg-gradient-to-br from-[#10b981] to-[#059669] rounded-[16px] p-[20px] shadow-[0_4px_12px_rgba(16,185,129,0.2)] flex flex-col justify-between h-full group text-white",children:[e.jsx("div",{className:"absolute -right-12 -bottom-12 w-40 h-40 bg-white/10 rounded-full"}),e.jsxs("div",{className:"flex items-start justify-between relative z-10 mb-4",children:[e.jsx("span",{className:"text-[13px] font-medium text-white/90",children:"Mastered by Class"}),e.jsx("div",{className:"w-8 h-8 rounded-full border border-white/30 flex items-center justify-center bg-white/10",children:e.jsx(La,{size:16,className:"text-white"})})]}),e.jsx("div",{className:"text-[32px] font-bold relative z-10 leading-none",children:l.masteredCount})]}),e.jsxs("div",{className:"relative overflow-hidden bg-gradient-to-br from-[#f43f5e] to-[#e11d48] rounded-[16px] p-[20px] shadow-[0_4px_12px_rgba(244,63,94,0.2)] flex flex-col justify-between h-full group text-white",children:[e.jsx("div",{className:"absolute -right-12 -bottom-12 w-40 h-40 bg-white/10 rounded-full"}),e.jsxs("div",{className:"flex items-start justify-between relative z-10 mb-4",children:[e.jsx("span",{className:"text-[13px] font-medium text-white/90",children:"Needs Work"}),e.jsx("div",{className:"w-8 h-8 rounded-full border border-white/30 flex items-center justify-center bg-white/10",children:e.jsx(ca,{size:16,className:"text-white"})})]}),e.jsx("div",{className:"text-[32px] font-bold relative z-10 leading-none",children:l.needsAttentionCount})]}),e.jsxs("div",{className:"relative overflow-hidden bg-gradient-to-br from-[#64748b] to-[#475569] rounded-[16px] p-[20px] shadow-[0_4px_12px_rgba(100,116,139,0.2)] flex flex-col justify-between h-full group text-white",children:[e.jsx("div",{className:"absolute -right-12 -bottom-12 w-40 h-40 bg-white/10 rounded-full"}),e.jsxs("div",{className:"flex items-start justify-between relative z-10 mb-4",children:[e.jsx("span",{className:"text-[13px] font-medium text-white/90",children:"Excluded Topics"}),e.jsx("div",{className:"w-8 h-8 rounded-full border border-white/30 flex items-center justify-center bg-white/10",children:e.jsx(gc,{size:16,className:"text-white"})})]}),e.jsx("div",{className:"text-[32px] font-bold relative z-10 leading-none",children:l.excludedCount})]})]}),e.jsxs("div",{className:"bg-white/80 backdrop-blur-[12px] rounded-[24px] p-[24px] shadow-[0_1px_4px_rgba(0,0,0,0.02)] border border-white",children:[e.jsxs("div",{className:"flex flex-col md:flex-row gap-4 mb-6",children:[e.jsxs("div",{className:"flex items-center bg-white px-4 py-2.5 rounded-[12px] shadow-[0_1px_4px_rgba(0,0,0,0.02)] border border-[#e2e8f0] group focus-within:ring-2 focus-within:ring-indigo-500/20 transition-all w-full md:w-64",children:[e.jsx(qs,{size:16,className:"text-[#64748b] shrink-0 group-focus-within:text-[#4f46e5] transition-colors"}),e.jsx("input",{type:"text",placeholder:"Search topics...",value:k,onChange:H=>N(H.target.value),className:"bg-transparent border-none focus:outline-none ml-2 text-[13px] w-full text-[#475569] placeholder:text-[#94a3b8]"})]}),e.jsxs("div",{className:"relative w-full md:w-48",children:[e.jsxs("select",{value:p,onChange:H=>h(H.target.value),className:"appearance-none w-full bg-white border border-[#e2e8f0] text-[#475569] text-[13px] font-medium rounded-[12px] pl-4 pr-10 py-2.5 outline-none focus:border-[#a855f7] focus:ring-2 focus:ring-[#a855f7]/20 shadow-[0_1px_4px_rgba(0,0,0,0.02)] cursor-pointer",children:[e.jsx("option",{value:"all",children:"All Subjects"}),be.map(H=>e.jsx("option",{value:H,children:W[H]||H},H))]}),e.jsx($t,{size:16,className:"text-[#64748b] absolute right-3 top-1/2 -translate-y-1/2 pointer-events-none"})]}),e.jsxs("div",{className:"relative w-full md:w-48",children:[e.jsxs("select",{value:b,onChange:H=>S(H.target.value),className:"appearance-none w-full bg-white border border-[#e2e8f0] text-[#475569] text-[13px] font-medium rounded-[12px] pl-4 pr-10 py-2.5 outline-none focus:border-[#a855f7] focus:ring-2 focus:ring-[#a855f7]/20 shadow-[0_1px_4px_rgba(0,0,0,0.02)] cursor-pointer",children:[e.jsx("option",{value:"all",children:"All Grades"}),yc.map(H=>e.jsx("option",{value:H,children:H},H))]}),e.jsx($t,{size:16,className:"text-[#64748b] absolute right-3 top-1/2 -translate-y-1/2 pointer-events-none"})]})]}),e.jsx(zt,{children:w.size>0&&e.jsxs(Le.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},className:"mb-4 bg-indigo-50 border border-indigo-200 rounded-[12px] p-3 flex items-center gap-3 flex-wrap overflow-hidden",children:[e.jsxs("span",{className:"text-[13px] font-semibold text-indigo-700",children:[w.size," topics selected"]}),e.jsx("button",{onClick:re,className:"px-4 py-1.5 bg-[#475569] text-white text-[11px] font-bold rounded-full hover:bg-[#334155] transition-colors shadow-sm",children:"Exclude Selected"}),e.jsx("button",{onClick:le,className:"px-4 py-1.5 bg-emerald-600 text-white text-[11px] font-bold rounded-full hover:bg-emerald-700 transition-colors shadow-sm",children:"Include Selected"}),e.jsx("button",{onClick:()=>$(new Set),className:"px-4 py-1.5 bg-white border border-[#e2e8f0] text-[#64748b] text-[11px] font-bold rounded-full hover:bg-[#f8fafc] transition-colors shadow-sm",children:"Clear Selection"})]})}),e.jsx("div",{className:"bg-white rounded-[16px] border border-[#f1f5f9] overflow-hidden shadow-[0_1px_4px_rgba(0,0,0,0.02)]",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("div",{className:"min-w-[800px]",children:[e.jsxs("div",{className:"bg-[#9956DE] grid grid-cols-12 gap-4 p-4 border-b border-[#8b5cf6] items-center text-[11px] font-bold text-white tracking-wider uppercase shadow-md relative z-10 h-12",children:[e.jsx("div",{className:"col-span-1 flex justify-center",children:e.jsx("input",{type:"checkbox",checked:w.size===Ie.length&&Ie.length>0,onChange:de,className:"rounded text-[#4f46e5] focus:ring-[#4f46e5] w-4 h-4 border-white/30 bg-white/10 cursor-pointer"})}),e.jsxs("div",{className:"col-span-3 flex items-center gap-1 cursor-pointer hover:text-white/80 select-none",onClick:()=>ne("topicName"),children:["TOPIC NAME ",e.jsx(fe,{field:"topicName"})]}),e.jsx("div",{className:"col-span-2",children:"UNIT"}),e.jsxs("div",{className:"col-span-2 flex items-center gap-1 cursor-pointer hover:text-white/80 select-none",onClick:()=>ne("classAverage"),children:["CLASS AVG % ",e.jsx(fe,{field:"classAverage"})]}),e.jsxs("div",{className:"col-span-2 flex items-center gap-1 cursor-pointer hover:text-white/80 select-none",onClick:()=>ne("studentsAttempted"),children:["STUDENTS ",e.jsx(fe,{field:"studentsAttempted"})]}),e.jsxs("div",{className:"col-span-1 flex items-center gap-1 cursor-pointer hover:text-white/80 select-none",onClick:()=>ne("masteryStatus"),children:["STATUS ",e.jsx(fe,{field:"masteryStatus"})]}),e.jsx("div",{className:"col-span-1 text-center",children:"EXCLUDE"})]}),e.jsx("div",{className:"flex flex-col",children:Ie.length===0?e.jsx("div",{className:"p-16 text-center border-b border-[#f1f5f9]",children:n.length===0?e.jsxs("div",{className:"flex flex-col items-center gap-2",children:[e.jsx(Ls,{size:32,className:"text-[#cbd5e1]"}),e.jsx("p",{className:"text-[13px] font-semibold text-[#64748b]",children:"No topic data available yet"}),e.jsx("p",{className:"text-[11px] text-[#94a3b8]",children:"Import student quiz data to see class topic mastery analytics."})]}):e.jsx("span",{className:"text-[13px] text-[#64748b]",children:"No topics match the current filters."})}):Ie.map(H=>{const ee=w.has(H.topicName),oe=Oo[H.masteryStatus]||Oo.no_data,Re=Im[H.subjectId]||{label:H.subjectId.toUpperCase(),color:"bg-[#f8fafc] text-[#64748b]"},Fe=H.classAverage<60?"bg-rose-500":H.classAverage<85?"bg-amber-500":"bg-emerald-500",Pe=H.isExcluded?"bg-slate-50/60 opacity-70":H.masteryStatus==="needs_attention"?"bg-rose-50/30":H.masteryStatus==="mastered"?"bg-emerald-50/20":"";return e.jsxs("div",{className:`grid grid-cols-12 gap-4 p-4 border-b border-[#f1f5f9] items-center hover:bg-slate-50/80 transition-colors group ${Pe} ${H.isExcluded?"line-through decoration-slate-400":""}`,children:[e.jsx("div",{className:"col-span-1 flex justify-center",children:e.jsx("input",{type:"checkbox",checked:ee,onChange:()=>{const G=new Set(w);ee?G.delete(H.topicName):G.add(H.topicName),$(G)},className:"rounded text-[#4f46e5] focus:ring-[#4f46e5] w-4 h-4 border-gray-300 cursor-pointer"})}),e.jsxs("div",{className:"col-span-3 flex flex-col sm:flex-row sm:items-center gap-1.5 pr-2 min-w-0",children:[e.jsx("span",{className:"font-semibold text-[#1e293b] text-[13px] truncate",children:H.topicName}),e.jsx("span",{className:`text-[9px] font-bold px-1.5 py-0.5 rounded shrink-0 ${Re.color}`,children:Re.label})]}),e.jsx("div",{className:"col-span-2 text-[#475569] text-[13px] truncate pr-2",children:H.unit}),e.jsx("div",{className:"col-span-2",children:e.jsxs("span",{className:"font-bold text-[#1e293b] text-[14px]",children:[H.classAverage,"%"]})}),e.jsxs("div",{className:"col-span-2 pr-4",children:[e.jsx("div",{className:"flex justify-between items-center text-[11px] mb-1",children:e.jsxs("span",{className:"font-semibold text-[#1e293b]",children:[H.studentsAttempted," / ",H.totalStudents]})}),e.jsx("div",{className:"w-full bg-[#f1f5f9] h-1.5 rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full transition-all duration-500 ${Fe}`,style:{width:`${H.classAverage}%`}})})]}),e.jsx("div",{className:"col-span-1",children:e.jsx("span",{className:`text-[10px] font-bold px-2.5 py-1 rounded-full border whitespace-nowrap ${oe.color}`,children:oe.label})}),e.jsxs("div",{className:"col-span-1 flex justify-center relative",children:[e.jsxs("label",{className:"relative inline-flex items-center cursor-pointer group/toggle",children:[e.jsx("input",{type:"checkbox",checked:H.isExcluded,onChange:()=>J(H.topicName),className:"sr-only peer"}),e.jsx("div",{className:"w-9 h-5 bg-slate-200 peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-[#4f46e5]"})]}),e.jsx("div",{className:"hidden group-hover/toggle:block absolute z-20 bottom-full left-1/2 -translate-x-1/2 mb-2 px-2 py-1 bg-slate-800 text-white text-[10px] rounded whitespace-nowrap shadow-lg",children:H.isExcluded?"Include in generation":"Exclude from generation"})]})]},H.topicName)})})]})})})]})]})};function gl(t){return(t||"").trim().toLowerCase()}function Bo(t){const s=(t.lrn||"").trim().toLowerCase();if(s)return`lrn:${s}`;const a=(t.email||"").trim().toLowerCase();if(a)return`email:${a}`;const r=t.name.trim().toLowerCase();if(r)return`name:${r}`;const o=gl(t.classSectionId),n=(t.id||"").trim().toLowerCase();return o&&n?`${o}|id:${n}`:n?`id:${n}`:`${o}|anonymous`}function _m(t,s){const a=[],r=(t.lrn||"").trim().toLowerCase(),o=(t.email||"").trim().toLowerCase(),n=t.name.trim().toLowerCase(),i=(t.id||"").trim().toLowerCase();return r&&a.push(`${s}|lrn:${r}`),o&&a.push(`${s}|email:${o}`),n&&a.push(`${s}|name:${n}`),i&&a.push(`${s}|id:${i}`),a.length===0&&a.push(`${s}|anonymous`),a}function Em(t,s){const a=[t.riskLevel,s.riskLevel].includes("High")?"High":[t.riskLevel,s.riskLevel].includes("Medium")?"Medium":"Low";return{...t,lrn:t.lrn||s.lrn,classSectionId:t.classSectionId??s.classSectionId,avgQuizScore:s.avgQuizScore>0?s.avgQuizScore:t.avgQuizScore,engagementScore:s.engagementScore>0?s.engagementScore:t.engagementScore,weakestTopic:t.weakestTopic&&t.weakestTopic!=="Foundational Skills"?t.weakestTopic:s.weakestTopic,riskLevel:a}}function bl(t,s){const a=new Map,r=new Map,o=s?gl(s):"all";return t.forEach(n=>{const i=_m(n,o),l=i.map(m=>r.get(m)).find(Boolean)||i[0],c=a.get(l),d=c?Em(c,n):n;a.set(l,d),i.forEach(m=>r.set(m,l))}),Array.from(a.values())}function Ho(t,s){return bl([...t,...s])}function ta(t){return Number.isFinite(t)?Math.max(0,Math.min(100,t)):0}function Rm(t){if(!t)return null;const s="gen-math",a=Un.find(i=>i.id===s)?.modules||[];if(a.length===0)return null;const r={mastery:0,concept:0,application:0,engagement:0,consistency:0},o=t.lessons??{};a.forEach(i=>{const l=Un.find(N=>N.modules.some(v=>v.id===i.id)),c=l?t?.subjects?.[l.id]?.modulesProgress?.[i.id]:null,d=ta(c?.progress||0),m=i.lessons.length?i.lessons.reduce((N,v)=>{const g=o?.[v.id]?.score;if(typeof g=="number"&&Number.isFinite(g))return N+ta(g);const I=!!c?.lessonsCompleted?.includes?.(v.id);return N+(I?100:0)},0)/i.lessons.length:0,p=i.quizzes.length?(c?.quizzesCompleted?.length||0)/i.quizzes.length*100:0,h=ta(m),b=ta(p),S=ta(Math.min(100,(h+b*2)/1.5)),k=ta(Math.min(100,40+d*.6));r.mastery+=d,r.concept+=h,r.application+=b,r.engagement+=S,r.consistency+=k});const n=a.length;return{mastery:Math.round(r.mastery/n),concept:Math.round(r.concept/n),application:Math.round(r.application/n),engagement:Math.round(r.engagement/n),consistency:Math.round(r.consistency/n)}}const Uo={advanced:{bg:"bg-emerald-100",text:"text-emerald-700",bar:"bg-emerald-500"},proficient:{bg:"bg-sky-100",text:"text-sky-700",bar:"bg-sky-500"},developing:{bg:"bg-rose-100",text:"text-rose-700",bar:"bg-rose-500"},beginner:{bg:"bg-red-100",text:"text-red-700",bar:"bg-red-500"}},Fr=[{key:"mastery",short:"M",label:"Overall Mastery",header:"Mastery"},{key:"concept",short:"C",label:"Concept Grasp",header:"Concept"},{key:"application",short:"A",label:"Application",header:"Applications"},{key:"consistency",short:"S",label:"Consistency",header:"Consistency"}],Mm=({classSectionId:t,className:s,fallbackStudents:a=[],onBack:r,onOpenNotifications:o,onOpenProfile:n,insightDismissed:i,onOpenInsightModal:l})=>{const{currentUser:c,userProfile:d}=hs(),m=u.useRef(0),[p,h]=u.useState([]),[b,S]=u.useState(!0),[k,N]=u.useState(""),[v,g]=u.useState("riskLevel"),[I,z]=u.useState("desc"),[R,W]=u.useState("all"),[f,C]=u.useState([]),[w,$]=u.useState(!1),[A,y]=u.useState(""),[q,J]=u.useState(""),re=u.useCallback(E=>({id:E.id,lrn:E.lrn||void 0,name:E.name,email:E.email||"",avatar:Ja(E.gender),classSectionId:E.classSectionId??null,riskLevel:E.riskLevel||"Low",engagementScore:E.engagementScore,avgQuizScore:E.avgQuizScore,weakestTopic:E.weakestTopic||"Foundational Skills"}),[]),le=u.useCallback(E=>({id:E.id,lrn:E.lrn,name:E.name,email:E.email||"",avatar:E.avatar&&!E.avatar.includes("ui-avatars.com")?E.avatar:Ja(E.gender),classSectionId:E.classSectionId??null,riskLevel:String(E.riskLevel).charAt(0).toUpperCase()+String(E.riskLevel).slice(1).toLowerCase(),engagementScore:Number(E.engagementScore)||0,avgQuizScore:Number(E.avgQuizScore??E.avgScore??0)||0,weakestTopic:E.weakestTopic||"Foundational Skills",accountUid:E.accountUid}),[]),ne=u.useCallback(async(E,Y)=>{const V=new Map,pe=new Map;E.forEach(j=>V.set(j.id,null));const D=25;for(let j=0;j{const ue=Q.accountUid||Q.id;try{const ce=await Gr(ue),ae=ce?.averageScore||0;return{studentId:Q.id,summary:Rm(ce),avgScore:ae}}catch{return{studentId:Q.id,summary:null,avgScore:0}}}))).forEach((Q,ue)=>{const ce=_[ue]?.id;ce&&(Q.status==="fulfilled"?(V.set(ce,Q.value.summary),Q.value.avgScore>0&&pe.set(ce,Q.value.avgScore)):V.set(ce,null))})}m.current===Y&&h(j=>j.map(_=>{if(!V.has(_.student.id))return _;const T=pe.get(_.student.id);return{..._,student:T!=null&&T>_.student.avgQuizScore?{..._.student,avgQuizScore:Math.round(T)}:_.student,competencyMatrix:V.get(_.student.id)??null,competencyMatrixLoading:!1}}))},[]),be=u.useCallback(async()=>{if(c?.uid){S(!0),J("");try{let Y=(await jn(c.uid)).map(j=>({id:j.id,name:j.name,email:j.email||"",avatar:j.avatar&&!j.avatar.includes("ui-avatars.com")?j.avatar:Ja(j.gender),classSectionId:j.classSectionId??null,riskLevel:j.riskLevel,engagementScore:Number(j.engagementScore)||0,avgQuizScore:Number(j.avgQuizScore)||0,weakestTopic:j.weakestTopic||"Foundational Skills",accountUid:j.accountUid}));a.length>0&&(Y=Ho(Y,a.map(le))),t&&(Y=Y.filter(j=>j.classSectionId===t));const V=await xt.getImportedClassOverview({classSectionId:t,limit:3e3});V.warnings.length>0&&J(V.warnings.join(" ")),Y=Ho(Y,V.students.map(re));const pe=bl(Y,t),D=m.current+=1;h(pe.map((j,_)=>({rowKey:`${Bo(j)}|row:${_}`,student:j,competency:null,competencyMatrix:null,competencyMatrixLoading:!0,loading:!1,expanded:!1}))),ne(pe,D)}catch(E){if(console.error("Failed to load students:",E),a.length>0){const Y=a.map(le).filter(V=>!t||V.classSectionId===t).map((V,pe)=>({rowKey:`${Bo(V)}|row:${pe}`,student:V,competency:null,competencyMatrix:null,competencyMatrixLoading:!1,loading:!1,expanded:!1}));h(Y),J("Showing recently imported students while backend roster sync catches up.")}else h([]),J("Student competency roster is unavailable right now.")}finally{S(!1)}}},[t,c?.uid,a,ne,le,re]);u.useEffect(()=>{be()},[be]),u.useEffect(()=>{(async()=>{if(!t){C([]),y("");return}$(!0),y("");try{const Y=await xt.getCourseMaterialTopics({classSectionId:t,limit:20}),V=(Y.topics||[]).filter(pe=>pe.title?.trim());C(V),Y.warnings.length>0&&y(Y.warnings.join(" "))}catch{C([]),y("Imported topic context is unavailable right now.")}finally{$(!1)}})()},[t]);const Ie=async E=>{h(Y=>Y.map(V=>{if(V.rowKey!==E)return V;const pe=!V.expanded,D=V.student.id,j={weakestTopic:V.student.weakestTopic,avgQuizScore:V.student.avgQuizScore};return pe&&!V.competency&&!V.loading?(de(E,D,j),{...V,expanded:!0,loading:!0}):{...V,expanded:pe}}))},de=async(E,Y,V)=>{try{const D=((await Gr(Y))?.quizAttempts??[]).map(_=>({topic:_.quizId,score:_.score,total:100,timeTaken:_.timeSpent})),j=await xt.getStudentCompetency(Y,D.length>0?D:void 0);h(_=>_.map(T=>T.rowKey===E?{...T,competency:j,loading:!1}:T))}catch{const D=V.avgQuizScore||50,j={studentId:Y,competencies:[{topic:V.weakestTopic||"Unknown",efficiencyScore:Math.max(15,D-20),competencyLevel:D<50?"beginner":"developing",perspective:`Student needs focused practice in ${V.weakestTopic}.`},{topic:"Functions and Relations",efficiencyScore:Math.min(95,D+10),competencyLevel:D>70?"proficient":"developing",perspective:"Shows solid understanding of function concepts."},{topic:"Problem Solving",efficiencyScore:D,competencyLevel:D>80?"advanced":D>60?"proficient":"developing",perspective:"Applies mathematical reasoning consistently."}],recommendedTopics:[V.weakestTopic||"Review fundamentals"],excludeTopics:[]};h(_=>_.map(T=>T.rowKey===E?{...T,competency:j,loading:!1}:T))}},fe=E=>{v===E?z(Y=>Y==="asc"?"desc":"asc"):(g(E),z("asc"))},H={High:0,Medium:1,Low:2},ee=p.filter(E=>{if(R!=="all"&&E.student.riskLevel!==R)return!1;if(k){const Y=k.toLowerCase();return E.student.name.toLowerCase().includes(Y)||E.student.email.toLowerCase().includes(Y)}return!0}).sort((E,Y)=>{let V=0;switch(v){case"name":V=E.student.name.localeCompare(Y.student.name);break;case"avgQuizScore":V=E.student.avgQuizScore-Y.student.avgQuizScore;break;case"riskLevel":V=H[E.student.riskLevel]-H[Y.student.riskLevel];break;case"engagementScore":V=E.student.engagementScore-Y.student.engagementScore;break}return I==="asc"?V:-V}),oe=p.length,Re=p.filter(E=>E.student.riskLevel==="High").length,Fe=oe>0?Math.round(p.reduce((E,Y)=>E+(Number(Y.student.avgQuizScore)||0),0)/oe):0,Pe=oe>0?Math.round(p.reduce((E,Y)=>E+(Number(Y.student.engagementScore)||0),0)/oe):0,G=Array.from(new Set(f.map(E=>E.title).filter(Boolean))).slice(0,10),te=({field:E})=>v!==E?e.jsx($t,{size:14,className:"text-white/40"}):I==="asc"?e.jsx(Ca,{size:14,className:"text-white font-bold"}):e.jsx($t,{size:14,className:"text-white font-bold"});return b?e.jsxs("div",{className:"flex items-center justify-center py-20 p-6",children:[e.jsx(gt,{size:32,className:"animate-spin text-[var(--primary)]"}),e.jsx("span",{className:"ml-3 text-muted-foreground",children:"Loading student data..."})]}):e.jsxs(Le.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},exit:{opacity:0,y:-20},className:"p-6 space-y-6",children:[r&&e.jsx("div",{className:"flex items-center justify-between mb-2",children:e.jsxs("button",{onClick:r,className:"flex items-center gap-2 text-[13px] font-semibold text-[#4f46e5] hover:text-[#3730a3] transition-colors bg-white/60 hover:bg-white/80 px-[18px] py-2 rounded-full backdrop-blur-[12px] shadow-[0_1px_4px_rgba(0,0,0,0.04)] border border-white/50",children:[e.jsx(zs,{className:"w-4 h-4"}),"Back to Classes"]})}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-[16px] mb-6",children:[e.jsxs("div",{className:"relative overflow-hidden bg-gradient-to-br from-[#a855f7] to-[#9333ea] rounded-[16px] p-5 shadow-[0_4px_12px_rgba(168,85,247,0.2)] hover:shadow-[0_8px_24px_rgba(168,85,247,0.3)] hover:-translate-y-1 transition-all duration-300 flex flex-col justify-between group text-white",children:[e.jsx("div",{className:"absolute -right-8 -bottom-8 w-24 h-24 bg-white/10 rounded-full transition-transform duration-500 group-hover:scale-[1.8] group-hover:-translate-y-4 group-hover:-translate-x-4"}),e.jsxs("div",{className:"flex items-start justify-between relative z-10 mb-2",children:[e.jsx("span",{className:"text-[13px] font-medium text-white/90",children:"Total Students"}),e.jsx("div",{className:"w-8 h-8 rounded-full border border-white/30 flex items-center justify-center bg-white/10",children:e.jsx($n,{className:"w-4 h-4 text-white"})})]}),e.jsx("div",{className:"text-[28px] font-bold relative z-10 leading-none mb-4",children:oe}),e.jsx("div",{className:"flex items-center justify-between relative z-10 border-t border-white/20 pt-3 mt-auto",children:e.jsx("span",{className:"text-[12px] font-medium text-white/90",children:"Evaluated in this class"})})]}),e.jsxs("div",{className:"relative overflow-hidden bg-gradient-to-br from-[#f97316] to-[#ea580c] rounded-[16px] p-5 shadow-[0_4px_12px_rgba(249,115,22,0.2)] hover:shadow-[0_8px_24px_rgba(249,115,22,0.3)] hover:-translate-y-1 transition-all duration-300 flex flex-col justify-between group text-white",children:[e.jsx("div",{className:"absolute -right-8 -bottom-8 w-24 h-24 bg-white/10 rounded-full transition-transform duration-500 group-hover:scale-[1.8] group-hover:-translate-y-4 group-hover:-translate-x-4"}),e.jsxs("div",{className:"flex items-start justify-between relative z-10 mb-2",children:[e.jsx("span",{className:"text-[13px] font-medium text-white/90",children:"At-Risk Students"}),e.jsx("div",{className:"w-8 h-8 rounded-full border border-white/30 flex items-center justify-center bg-white/10",children:e.jsx(ca,{className:"w-4 h-4 text-white"})})]}),e.jsx("div",{className:"text-[28px] font-bold relative z-10 leading-none mb-4",children:Re}),e.jsx("div",{className:"flex items-center justify-between relative z-10 border-t border-white/20 pt-3 mt-auto",children:e.jsx("span",{className:"text-[12px] font-medium text-white/90",children:"Need immediate intervention"})})]}),e.jsxs("div",{className:"relative overflow-hidden bg-gradient-to-br from-[#0ea5e9] to-[#0284c7] rounded-[16px] p-5 shadow-[0_4px_12px_rgba(14,165,233,0.2)] hover:shadow-[0_8px_24px_rgba(14,165,233,0.3)] hover:-translate-y-1 transition-all duration-300 flex flex-col justify-between group text-white",children:[e.jsx("div",{className:"absolute -right-8 -bottom-8 w-24 h-24 bg-white/10 rounded-full transition-transform duration-500 group-hover:scale-[1.8] group-hover:-translate-y-4 group-hover:-translate-x-4"}),e.jsxs("div",{className:"flex items-start justify-between relative z-10 mb-2",children:[e.jsx("span",{className:"text-[13px] font-medium text-white/90",children:"Class Average"}),e.jsx("div",{className:"w-8 h-8 rounded-full border border-white/30 flex items-center justify-center bg-white/10",children:e.jsx(Ls,{className:"w-4 h-4 text-white"})})]}),e.jsxs("div",{className:"text-[28px] font-bold relative z-10 leading-none mb-4",children:[Fe,"%"]}),e.jsx("div",{className:"flex items-center justify-between relative z-10 border-t border-white/20 pt-3 mt-auto",children:e.jsx("span",{className:"text-[12px] font-medium text-white/90",children:"Vs. expected benchmark"})})]}),e.jsxs("div",{className:"relative overflow-hidden bg-gradient-to-br from-[#10b981] to-[#059669] rounded-[16px] p-5 shadow-[0_4px_12px_rgba(16,185,129,0.2)] hover:shadow-[0_8px_24px_rgba(16,185,129,0.3)] hover:-translate-y-1 transition-all duration-300 flex flex-col justify-between group text-white",children:[e.jsx("div",{className:"absolute -right-8 -bottom-8 w-24 h-24 bg-white/10 rounded-full transition-transform duration-500 group-hover:scale-[1.8] group-hover:-translate-y-4 group-hover:-translate-x-4"}),e.jsxs("div",{className:"flex items-start justify-between relative z-10 mb-2",children:[e.jsx("span",{className:"text-[13px] font-medium text-white/90",children:"Avg. Engagement"}),e.jsx("div",{className:"w-8 h-8 rounded-full border border-white/30 flex items-center justify-center bg-white/10",children:e.jsx(la,{className:"w-4 h-4 text-white"})})]}),e.jsxs("div",{className:"text-[28px] font-bold relative z-10 leading-none mb-4",children:[Pe,"%"]}),e.jsx("div",{className:"flex items-center justify-between relative z-10 border-t border-white/20 pt-3 mt-auto",children:e.jsx("span",{className:"text-[12px] font-medium text-white/90",children:"Activity completion rate"})})]})]}),e.jsx("div",{className:"sticky top-0 z-30 py-4 -my-4 bg-[#f8fafc]/80 backdrop-blur-[16px] border-b border-slate-200/50 shadow-[0_4px_20px_rgba(0,0,0,0.02)] px-2 sm:-mx-6 sm:px-6 mb-6 rounded-b-[18px]",children:e.jsxs("div",{className:"flex flex-col md:flex-row gap-4 items-center justify-between",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row gap-4 w-full md:w-auto items-center",children:[e.jsxs("div",{className:"flex items-center bg-white px-4 py-2.5 rounded-full shadow-[0_1px_4px_rgba(0,0,0,0.04)] border border-[#e2e8f0] group focus-within:ring-2 focus-within:ring-indigo-500/20 transition-all w-full sm:w-64",children:[e.jsx(qs,{className:"w-4 h-4 text-[#64748b] shrink-0 group-focus-within:text-[#9956DE] transition-colors"}),e.jsx("input",{type:"text",placeholder:"Search students...",value:k,onChange:E=>N(E.target.value),className:"bg-transparent border-none focus:outline-none ml-2 text-[13px] w-full text-[#475569] placeholder:text-[#94a3b8]"})]}),e.jsx("div",{className:"flex items-center gap-2 overflow-x-auto no-scrollbar w-full sm:w-auto p-2 -m-2",children:["all","High","Medium","Low"].map(E=>e.jsx("button",{onClick:()=>W(E),className:`px-4 py-1.5 text-[13px] font-semibold rounded-full whitespace-nowrap transition-colors shadow-md ${R===E?"bg-[#9956DE] text-white":"bg-white text-slate-500 hover:text-slate-700 hover:bg-slate-50"}`,children:E==="all"?"All":`${E} Risk`},E))})]}),e.jsxs("button",{onClick:be,className:"flex items-center gap-2 text-[13px] font-semibold text-slate-500 hover:text-slate-700 transition-colors shrink-0 bg-white px-4 py-2 rounded-full shadow-md hover:bg-slate-50 self-end sm:self-auto",children:[e.jsx(cs,{className:"w-4 h-4"})," Refresh"]})]})}),e.jsxs("div",{className:"bg-[#f5f3ff]/60 border border-[#e0e7ff] rounded-[14px] px-5 py-3 mb-6 flex items-start sm:items-center gap-3",children:[e.jsx("div",{className:"mt-0.5 sm:mt-0 shrink-0",children:e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-[#9956DE]",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("path",{d:"M12 16v-4"}),e.jsx("path",{d:"M12 8h.01"})]})}),e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center flex-1",children:[e.jsxs("span",{className:"text-[#9956DE] font-semibold text-[13px] whitespace-nowrap mr-1",children:["Imported Topic Context",s?` for ${s}`:"",":"]}),w?e.jsx("span",{className:"text-[#8b5cf6] text-[13px]",children:"Loading class-scoped imported topics..."}):G.length>0?e.jsx("div",{className:"flex flex-wrap items-center gap-1.5 mt-1 sm:mt-0",children:G.map((E,Y)=>e.jsxs(he.Fragment,{children:[e.jsx("span",{className:"text-[#8b5cf6] text-[13px]",children:E}),Yfe("name"),children:["Student ",e.jsx(te,{field:"name"})]}),e.jsxs("div",{className:"w-[120px] shrink-0 px-4 flex justify-center cursor-pointer hover:text-white/80 transition-colors",onClick:()=>fe("riskLevel"),children:["Risk Level ",e.jsx(te,{field:"riskLevel"})]}),e.jsxs("div",{className:"w-[200px] shrink-0 px-4 flex items-center gap-1 cursor-pointer hover:text-white/80 transition-colors",onClick:()=>fe("avgQuizScore"),children:["Avg. Score ",e.jsx(te,{field:"avgQuizScore"})]}),e.jsxs("div",{className:"w-[180px] shrink-0 px-4 flex items-center gap-1 cursor-pointer hover:text-white/80 transition-colors",onClick:()=>fe("engagementScore"),children:["Engagement ",e.jsx(te,{field:"engagementScore"})]}),e.jsx("div",{className:"w-[160px] shrink-0 px-4 flex justify-center cursor-pointer hover:text-white/80 transition-colors",children:"Weakest Topic"}),Fr.map((E,Y)=>e.jsx("div",{className:`w-[100px] shrink-0 px-2 flex justify-center ${Y===Fr.length-1?"border-r border-transparent":""}`,children:E.header},E.key))]}),ee.length===0?e.jsxs("div",{className:"py-12 text-center text-slate-500",children:[e.jsx($n,{size:32,className:"mx-auto mb-2 opacity-50"}),e.jsx("p",{className:"text-sm",children:"No students match the current filters"})]}):e.jsx("div",{className:"divide-y divide-border",children:ee.map(E=>(E.student.riskLevel==="High"||E.student.riskLevel,e.jsxs("div",{className:"flex flex-col border-b border-slate-100 group",children:[e.jsxs("div",{className:"flex items-center min-h-[64px] hover:bg-slate-50/60 transition-colors cursor-pointer relative",onClick:()=>void Ie(E.rowKey),children:[e.jsxs("div",{className:"w-[260px] shrink-0 sticky left-0 z-10 bg-white group-hover:bg-slate-50/90 transition-colors px-5 h-full min-h-[64px] flex items-center border-r border-slate-100 shadow-[2px_0_4px_rgba(0,0,0,0.01)]",children:[e.jsx("div",{className:`transition-transform duration-200 mr-3 shrink-0 ${E.expanded?"rotate-90":""}`,children:e.jsx(Ms,{className:"w-4 h-4 text-slate-400"})}),e.jsx("img",{src:E.student.avatar,alt:E.student.name,className:"w-8 h-8 rounded-full bg-border object-cover shrink-0 mr-3"}),e.jsx("span",{className:"font-semibold text-slate-800 text-[14px] truncate",children:E.student.name})]}),e.jsx("div",{className:"w-[120px] shrink-0 px-4 flex justify-center",children:e.jsx("span",{className:`px-3 py-1 rounded-full border text-[11px] font-bold uppercase tracking-wider ${E.student.riskLevel==="High"?"bg-rose-50 text-rose-600 border-rose-200":E.student.riskLevel==="Medium"?"bg-amber-50 text-amber-600 border-amber-200":"bg-emerald-50 text-emerald-600 border-emerald-200"}`,children:E.student.riskLevel})}),e.jsxs("div",{className:"w-[200px] shrink-0 px-4 flex items-center gap-3",children:[e.jsx("div",{className:"flex-1 bg-slate-100 h-2.5 rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full ${E.student.avgQuizScore>=80?"bg-emerald-500":E.student.avgQuizScore>=60?"bg-amber-400":"bg-rose-500"}`,style:{width:`${E.student.avgQuizScore}%`}})}),e.jsxs("span",{className:"text-[13px] font-bold text-slate-800 w-8",children:[E.student.avgQuizScore,"%"]})]}),e.jsxs("div",{className:"w-[180px] shrink-0 px-4 flex items-center gap-3",children:[e.jsx("div",{className:"flex-1 bg-slate-100 h-2.5 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full bg-[#9956DE]",style:{width:`${E.student.engagementScore}%`}})}),e.jsxs("span",{className:"text-[13px] font-bold text-slate-800 w-8",children:[E.student.engagementScore,"%"]})]}),e.jsx("div",{className:"w-[160px] shrink-0 px-4 flex justify-center",children:e.jsx("span",{className:"px-3 py-1 bg-slate-100 text-slate-600 text-[11px] font-medium rounded-full truncate max-w-full border border-slate-200",children:E.student.weakestTopic})}),Fr.map(Y=>{const V=E.competencyMatrix?.[Y.key]??0;return e.jsx("div",{className:"w-[100px] shrink-0 px-2 flex justify-center",children:E.competencyMatrixLoading?e.jsx(gt,{size:12,className:"animate-spin text-muted-foreground"}):E.competencyMatrix?e.jsxs("span",{className:`text-[12px] font-medium px-2 rounded-full border ${V>=80?"text-emerald-600 bg-emerald-50 border-emerald-100":V>=60?"text-amber-600 bg-amber-50 border-amber-100":"text-rose-500 bg-rose-50 border-rose-100"}`,children:[V,"%"]}):e.jsx("span",{className:"text-xs text-muted-foreground",children:"—"})},Y.key)})]}),e.jsx(zt,{children:E.expanded&&e.jsx(Le.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},className:"overflow-hidden bg-slate-50/80 border-t border-slate-100 shadow-inner",children:e.jsxs("div",{className:"flex min-w-[1320px]",children:[e.jsx("div",{className:"w-[260px] shrink-0 sticky left-0 z-10 bg-slate-50/90 border-r border-slate-100 flex items-start justify-end pr-4 py-4",children:e.jsx("div",{className:"w-1.5 h-full rounded-full bg-[#9956DE]/30"})}),e.jsx("div",{className:"flex-1 py-4 pl-6 pr-6",children:E.loading?e.jsxs("div",{className:"flex items-center py-4",children:[e.jsx(gt,{size:16,className:"animate-spin text-indigo-500 mr-2"}),e.jsx("span",{className:"text-sm text-slate-500",children:"Analyzing competency data..."})]}):E.competency?e.jsxs("div",{className:"space-y-4 max-w-4xl",children:[E.competency.recommendedTopics.length>0&&e.jsxs("div",{className:"bg-[#f5f3ff] rounded-[12px] p-4 border border-[#e0e7ff] inline-block shadow-sm mb-4",children:[e.jsxs("h4",{className:"text-[#7274ED] font-semibold text-[13px] flex items-center gap-2 mb-1.5",children:[e.jsx(Gt,{className:"w-4 h-4"})," Recommended Focus Areas"]}),e.jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:E.competency.recommendedTopics.map((Y,V)=>e.jsx("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full border border-indigo-100 bg-white text-indigo-700 text-xs font-medium shadow-sm",children:Y},V))})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:E.competency.competencies.map((Y,V)=>e.jsx(Am,{competency:Y},V))})]}):e.jsx("div",{className:"text-sm text-slate-500 py-4",children:"Failed to load competency details."})})]})})})]},E.rowKey)))})]})})]})},Am=({competency:t})=>{const s=Uo[t.competencyLevel]||Uo.developing;return e.jsxs("div",{className:"bg-card rounded-lg border border-border p-3",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("h6",{className:"text-xs font-bold text-foreground truncate flex-1",children:t.topic}),e.jsx("span",{className:`ml-2 px-2 py-0.5 rounded text-[10px] font-bold uppercase ${s.bg} ${s.text}`,children:t.competencyLevel})]}),e.jsxs("div",{className:"mb-2",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs mb-1",children:[e.jsx("span",{className:"text-slate-500",children:"Efficiency"}),e.jsxs("span",{className:"font-bold text-muted-foreground",children:[t.efficiencyScore,"%"]})]}),e.jsx("div",{className:"h-1.5 bg-muted rounded-full overflow-hidden",children:e.jsx(Le.div,{initial:{width:0},animate:{width:`${t.efficiencyScore}%`},transition:{duration:.6,delay:.1},className:`h-full rounded-full ${s.bar}`})})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground leading-snug line-clamp-2",children:t.perspective})]})},Lm=()=>{const{notifications:t,unreadCount:s,isLoading:a,markAsRead:r,markAllAsRead:o}=pi(),[n,i]=u.useState("all"),l=["streak_reminder","daily_checkin","streak_milestone","achievement_unlocked","level_up","xp_earned","quiz_result"],c=t.filter(S=>!S.isRead&&!l.includes(S.type)).length,d=S=>{switch(S){case"achievement_unlocked":case"achievement":return Bl;case"message":return ec;case"grade":case"quiz_result":return mi;case"reminder":case"streak_reminder":case"daily_checkin":return As;case"risk_alert":return ca;case"sparkles":case"lesson_plan_ready":return ps;case"users":case"student_import":return us;default:return dr}},m=(S,k)=>{switch(S){case"risk_alert":return"bg-rose-50/30 text-rose-500 border-rose-100";case"sparkles":case"lesson_plan_ready":return"bg-purple-50/30 text-[#a855f7] border-purple-100";case"daily_checkin":return"bg-amber-50/20 text-amber-500 border-amber-100";case"users":case"student_import":return"bg-blue-50/30 text-blue-500 border-blue-100";default:return"bg-slate-50 text-slate-500 border-slate-100"}},p=S=>{switch(S){case"risk_alert":return"from-rose-400 to-rose-600 shadow-[0_4px_12px_rgba(244,63,94,0.3)]";case"sparkles":case"lesson_plan_ready":return"from-[#a855f7] to-[#9333ea] shadow-[0_4px_12px_rgba(168,85,247,0.3)]";case"daily_checkin":return"from-amber-300 to-amber-500 shadow-[0_4px_12px_rgba(245,158,11,0.3)]";case"users":case"student_import":return"from-blue-400 to-blue-600 shadow-[0_4px_12px_rgba(59,130,246,0.3)]";default:return"from-slate-400 to-slate-600 shadow-[0_4px_12px_rgba(100,116,139,0.3)]"}},h=u.useMemo(()=>{let S=t.filter(k=>!l.includes(k.type));return n==="unread"&&(S=S.filter(k=>!k.isRead)),n==="important"&&(S=S.filter(k=>k.type==="risk_alert")),S},[t,n]),b=u.useMemo(()=>{const S=[],k=h.filter(g=>so(g.createdAt)),N=h.filter(g=>ao(g.createdAt)),v=h.filter(g=>!so(g.createdAt)&&!ao(g.createdAt));return k.length>0&&S.push({title:"Today",icon:As,items:k}),N.length>0&&S.push({title:"Yesterday",icon:Gn,items:N}),v.length>0&&S.push({title:"Earlier",icon:Gn,items:v}),S},[h]);return e.jsx("div",{className:"w-full h-full flex flex-col bg-[#f8fafc]/50",children:e.jsxs("div",{className:"max-w-[900px] mx-auto w-full p-[24px] xl:p-[32px] space-y-[24px] flex-1 overflow-y-auto no-scrollbar pb-12",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx("button",{onClick:()=>i("all"),className:`px-6 py-2.5 text-[13px] rounded-full whitespace-nowrap transition-all duration-300 border ${n==="all"?"bg-purple-50 text-[#9333ea] border-purple-200 shadow-md font-bold":"bg-white/80 text-[#64748b] border-white hover:border-[#e2e8f0] shadow-sm font-medium"}`,children:"All"}),e.jsxs("button",{onClick:()=>i("unread"),className:`px-6 py-2.5 text-[13px] rounded-full whitespace-nowrap transition-all duration-300 border flex items-center gap-2 ${n==="unread"?"bg-purple-50 text-[#9333ea] border-purple-200 shadow-md font-bold":"bg-white/80 text-[#64748b] border-white hover:border-[#e2e8f0] shadow-sm font-medium"}`,children:["Unread",e.jsx("span",{className:"w-5 h-5 rounded-full bg-slate-100 text-[10px] font-bold flex items-center justify-center text-slate-500",children:c})]}),e.jsxs("button",{onClick:()=>i("important"),className:`px-6 py-2.5 text-[13px] rounded-full whitespace-nowrap transition-all duration-300 border flex items-center gap-2 ${n==="important"?"bg-purple-50 text-[#9333ea] border-purple-200 shadow-md font-bold":"bg-white/80 text-[#64748b] border-white hover:border-[#e2e8f0] shadow-sm font-medium"}`,children:["Important",t.some(S=>S.type==="risk_alert"&&!S.isRead)&&e.jsx("span",{className:"w-2.5 h-2.5 rounded-full bg-rose-500 shadow-[0_0_8px_rgba(244,63,94,0.6)]"})]}),e.jsxs("div",{className:"ml-auto flex items-center gap-3 shrink-0",children:[e.jsx("span",{className:"text-[13px] font-bold text-[#64748b]",children:c>0?`${c} unread`:"No unread"}),e.jsxs("button",{onClick:o,disabled:c===0,className:"bg-white hover:bg-slate-50 border border-slate-200 text-[#475569] text-[13px] font-bold rounded-full px-5 py-2 shadow-sm transition-all hover:shadow-md hover:-translate-y-0.5 flex items-center gap-2 group disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:translate-y-0 disabled:hover:shadow-sm",children:[e.jsx(Ic,{className:"w-4 h-4 text-[#94a3b8] group-hover:text-emerald-500 transition-colors"}),"Mark all as read"]})]})]}),e.jsx("div",{className:"space-y-8",children:a?e.jsxs("div",{className:"bg-white/80 backdrop-blur-[12px] rounded-[24px] border border-white p-12 flex flex-col items-center justify-center gap-4",children:[e.jsx(gt,{className:"w-8 h-8 text-[#a855f7] animate-spin"}),e.jsx("p",{className:"text-[14px] font-medium text-[#64748b]",children:"Syncing notifications..."})]}):b.length===0?e.jsxs("div",{className:"bg-white/80 backdrop-blur-[12px] rounded-[24px] border border-white p-16 flex flex-col items-center justify-center text-center",children:[e.jsx("div",{className:"w-20 h-20 bg-slate-50 rounded-full flex items-center justify-center mb-6 border border-slate-100",children:e.jsx(dr,{className:"w-10 h-10 text-slate-300"})}),e.jsx("h3",{className:"text-[18px] font-bold text-[#1e293b] mb-2",children:"All clear!"}),e.jsx("p",{className:"text-[14px] text-[#64748b] max-w-sm",children:"No notifications found for this filter. New alerts will appear here automatically."})]}):b.map(S=>e.jsxs("div",{children:[e.jsxs("h3",{className:"text-[12px] font-bold text-[#94a3b8] uppercase tracking-wider mb-3 ml-2 flex items-center gap-2",children:[e.jsx(S.icon,{className:"w-4 h-4"})," ",S.title]}),e.jsx("div",{className:"bg-white/80 backdrop-blur-[12px] rounded-[24px] border border-white shadow-[0_4px_24px_rgba(0,0,0,0.03)] overflow-hidden divide-y divide-[#f1f5f9]",children:S.items.map(k=>{const N=d(k.type),v=k.type==="risk_alert";return e.jsxs(Le.div,{layout:!0,onClick:()=>!k.isRead&&r(k.id),className:`relative p-5 flex gap-5 group cursor-pointer hover:bg-white transition-all duration-300 ${k.isRead?"opacity-80":m(k.type)}`,children:[e.jsx("div",{className:`absolute left-0 top-0 w-1.5 h-full transition-colors ${k.isRead?"bg-transparent":v?"bg-rose-500":"bg-[#a855f7]"}`}),e.jsx("div",{className:`w-12 h-12 rounded-full flex items-center justify-center text-white shrink-0 group-hover:scale-110 transition-transform bg-gradient-to-br ${p(k.type)}`,children:e.jsx(N,{className:"w-6 h-6"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex justify-between items-start mb-1",children:[e.jsxs("h4",{className:"text-[15px] font-bold text-[#1e293b] flex items-center gap-2 truncate pr-4",children:[k.title,!k.isRead&&e.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${v?"bg-rose-500 shadow-[0_0_6px_rgba(244,63,94,0.8)]":"bg-[#a855f7] shadow-[0_0_6px_rgba(168,85,247,0.8)]"}`})]}),e.jsxs("span",{className:`text-[12px] font-bold whitespace-nowrap ${k.isRead?"text-[#94a3b8]":v?"text-rose-600":"text-[#a855f7]"}`,children:[Tc(k.createdAt)," ago"]})]}),e.jsx("p",{className:"text-[14px] text-[#475569] font-medium leading-relaxed",children:k.message}),!k.isRead&&k.actionUrl&&e.jsx("div",{className:"mt-3 flex gap-2",children:e.jsx("button",{className:`px-5 py-2 bg-white border rounded-full text-[12px] font-bold shadow-sm transition-all hover:-translate-y-0.5 ${v?"border-rose-200 text-rose-600 hover:bg-rose-50":"border-purple-200 text-[#9333ea] hover:bg-purple-50"}`,children:"Review Plan"})})]}),e.jsx("button",{className:"opacity-0 group-hover:opacity-100 p-2 text-slate-400 hover:text-slate-600 transition-all rounded-full hover:bg-slate-100 shrink-0 self-start",children:e.jsx(Gc,{size:18})})]},k.id)})})]},S.title))})]})})},zm=t=>{const s=t.data(),a=s.startTime,r=s.endTime,o=s.createdAt,n=s.updatedAt,i=l=>{if(l){if(typeof l?.toDate=="function")return l.toDate();if(l instanceof Date)return l}};return{...s,id:t.id,startTime:i(a)||new Date,endTime:i(r),createdAt:i(o)||new Date,updatedAt:i(n)}},Dm=async(t,s)=>{const a=pt(Mt(He,"calendarEvents")),r={id:a.id,userId:t,title:s.title,description:s.description,startTime:s.startTime,endTime:s.endTime,color:s.color,createdAt:new Date};return await ts(a,{...r,createdAt:it(),updatedAt:it()}),r},$m=async(t,s)=>{const a=pt(He,"calendarEvents",t);await es(a,{...s,updatedAt:it()})},Fm=async t=>{await hi(pt(He,"calendarEvents",t))},vl=(t,s={},a,r)=>{if(!t)return a([]),()=>{};const{limitCount:o=500}=s,n=At(Mt(He,"calendarEvents"),Et("userId","==",t),or(o));return fi(n,i=>{a(i.docs.map(l=>zm(l)))},i=>{console.error("Error subscribing to calendar events:",i),r?.(i)})};function Om({className:t,...s}){return e.jsx("textarea",{"data-slot":"textarea",className:ui("resize-none border-input placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 flex field-sizing-content min-h-16 w-full rounded-md border bg-input-background px-3 py-2 text-base transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",t),...s})}const ra=t=>String(t).padStart(2,"0"),Gs=t=>`${t.getFullYear()}-${ra(t.getMonth()+1)}-${ra(t.getDate())}`,nn=t=>new Date(t.getFullYear(),t.getMonth(),1),Go=t=>new Date(t.getFullYear(),t.getMonth()+1,0),Pm=t=>{const s=nn(t),a=s.getDay(),r=new Date(s);return r.setDate(s.getDate()-a),r.setHours(0,0,0,0),r},Bm=(t,s)=>{const a=new Date(t);return a.setDate(a.getDate()+s),a},Qo=(t,s)=>t.getFullYear()===s.getFullYear()&&t.getMonth()===s.getMonth()&&t.getDate()===s.getDate(),Hm=(t,s)=>t.getFullYear()===s.getFullYear()&&t.getMonth()===s.getMonth(),Um=t=>t.toLocaleDateString(void 0,{month:"long",year:"numeric"}),qa=t=>t.toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"}),Vo=(t,s)=>{const[a,r,o]=t.split("-").map(l=>parseInt(l,10)),[n,i]=s.split(":").map(l=>parseInt(l,10));return new Date(a,(r||1)-1,o||1,n||0,i||0,0,0)},Gm=["purple","blue","emerald","amber","rose"],Or=t=>{switch(t){case"blue":return"#3b82f6";case"emerald":return"#10b981";case"amber":return"#f59e0b";case"rose":return"#f43f5e";case"purple":default:return"#a855f7"}},Qm=(t,s=!1)=>{if(s)return"bg-blue-50 text-blue-700 border-blue-100 opacity-80";switch(t){case"blue":return"bg-blue-50 text-blue-700 border-blue-100 opacity-90 hover:bg-blue-100";case"emerald":return"bg-emerald-50 text-emerald-700 border-emerald-100 opacity-90 hover:bg-emerald-100";case"amber":return"bg-amber-50 text-amber-700 border-amber-100 opacity-90 hover:bg-amber-100";case"rose":return"bg-rose-50 text-rose-700 border-rose-100 opacity-90 hover:bg-rose-100";case"purple":default:return"bg-purple-50 text-purple-700 border-purple-100 opacity-90 hover:bg-purple-100"}},Vm=(t,s=!1)=>{if(s)return{dot:"bg-[#3b82f6]",border:"border-l-blue-400",time:"text-blue-600 border-blue-50"};switch(t){case"blue":return{dot:"bg-blue-500",border:"border-l-blue-400",time:"text-blue-600 border-blue-50"};case"emerald":return{dot:"bg-emerald-500",border:"border-l-emerald-400",time:"text-emerald-600 border-emerald-50"};case"amber":return{dot:"bg-amber-500",border:"border-l-amber-400",time:"text-amber-600 border-amber-50"};case"rose":return{dot:"bg-rose-500",border:"border-l-rose-400",time:"text-rose-600 border-rose-50"};case"purple":default:return{dot:"bg-[#a855f7]",border:"border-l-[#a855f7]",time:"text-[#a855f7] border-purple-50"}}},Pr=[{names:["sun","sunday"],day:0},{names:["mon","monday"],day:1},{names:["tue","tues","tuesday"],day:2},{names:["wed","wednesday"],day:3},{names:["thu","thurs","thursday"],day:4},{names:["fri","friday"],day:5},{names:["sat","saturday"],day:6}];function Wm(t){const s=t.toLowerCase(),a=new Set;if(s.includes("daily")||s.includes("everyday"))return[0,1,2,3,4,5,6];if(s.includes("weekends"))return[0,6];if(s.includes("weekdays"))return[1,2,3,4,5];const r=s.match(/(mon|tue|wed|thu|fri|sat|sun)[\s/-]*(mon|tue|wed|thu|fri|sat|sun)/);if(r){const o=Pr.find(i=>i.names.includes(r[1]))?.day,n=Pr.find(i=>i.names.includes(r[2]))?.day;if(o!==void 0&&n!==void 0){let i=o;for(;a.add(i),i!==n;)i=(i+1)%7;return Array.from(a)}}return Pr.forEach(({names:o,day:n})=>{o.some(i=>s.includes(i))&&a.add(n)}),Array.from(a).sort((o,n)=>o-n)}const qm=({classes:t,teacherId:s})=>{const{currentUser:a}=hs(),[r,o]=u.useState([]),[n,i]=u.useState(!0),[l,c]=u.useState(""),[d,m]=u.useState(!0),[p,h]=u.useState(()=>{const T=new Date;return T.setHours(0,0,0,0),T}),[b,S]=u.useState(()=>{const T=new Date;return T.setHours(0,0,0,0),T}),[k,N]=u.useState(new Set),[v,g]=u.useState(!1),[I,z]=u.useState(null),[R,W]=u.useState(!1),[f,C]=u.useState(""),[w,$]=u.useState(""),[A,y]=u.useState(()=>Gs(new Date)),[q,J]=u.useState("09:00"),[re,le]=u.useState(""),[ne,be]=u.useState("purple"),[Ie,de]=u.useState(!1),[fe,H]=u.useState(null);u.useEffect(()=>{if(!a?.uid){o([]),i(!1);return}c(""),i(!0);const T=vl(a.uid,{limitCount:500},Q=>{o(Q),i(!1)},()=>{c("Unable to load calendar events right now."),i(!1)});return()=>T()},[a?.uid]);const ee=u.useMemo(()=>{const T=nn(p);return T.setHours(0,0,0,0),T},[p]),oe=u.useMemo(()=>{const T=Go(p);return T.setHours(23,59,59,999),T},[p]),Re=u.useMemo(()=>{if(!t||t.length===0)return[];const T=[],Q=nn(p),ue=Go(p),ce=new Date(Q);for(;ce<=ue;){const ae=ce.getDay();t.forEach(Ce=>{if(Wm(Ce.schedule).includes(ae)){const Je=`schedule-${Ce.id}-${Gs(ce)}`;k.has(Je)||T.push({id:Je,userId:s||"",title:Ce.name,startTime:new Date(ce),createdAt:new Date})}}),ce.setDate(ce.getDate()+1)}return T},[t,p,s,k]),Fe=u.useMemo(()=>[...r,...Re],[r,Re]),Pe=u.useMemo(()=>Fe.filter(T=>T.startTime>=ee&&T.startTime<=oe).sort((T,Q)=>T.startTime.getTime()-Q.startTime.getTime()),[Fe,ee,oe]),G=u.useMemo(()=>{const T=new Map;for(const Q of Pe){const ue=Gs(Q.startTime),ce=T.get(ue)||[];ce.push(Q),T.set(ue,ce)}return T},[Pe]),te=u.useMemo(()=>Gs(b),[b]),E=u.useMemo(()=>[...G.get(te)||[]].sort((Q,ue)=>Q.startTime.getTime()-ue.startTime.getTime()),[G,te]),Y=u.useMemo(()=>{const T=Pm(p);return Array.from({length:42}).map((Q,ue)=>Bm(T,ue))},[p]),V=T=>{const Q=Gs(T);z(null),C(""),$(""),y(Q),J("09:00"),le(""),be("purple"),g(!0)},pe=T=>{T.id.startsWith("schedule-")?(N(Q=>new Set(Q).add(T.id)),z(null)):z(T.id),C(T.title),$(T.description||""),y(Gs(T.startTime)),J(ra(T.startTime.getHours())+":"+ra(T.startTime.getMinutes())),le(T.endTime?ra(T.endTime.getHours())+":"+ra(T.endTime.getMinutes()):""),be(T.color||"purple"),de(!1),g(!0)},D=(T,Q)=>{T.stopPropagation(),H(Q),de(!0)},j=async()=>{const T=a?.uid||s||"local-user";if(!f.trim()){c("Event title is required.");return}W(!0),c("");const Q=Vo(A,q),ue=re?Vo(A,re):void 0,ce={title:f.trim(),description:w.trim()?w.trim():void 0,startTime:Q,endTime:ue&&ue.getTime()>Q.getTime()?ue:void 0,color:ne};try{if(I)o(ae=>ae.map(Ce=>Ce.id===I?{...Ce,...ce}:Ce)),await $m(I,ce);else{const ae=`temp-${Date.now()}`;o(Ce=>[...Ce,{id:ae,userId:T,createdAt:new Date,...ce}]),await Dm(T,ce)}g(!1)}catch(ae){console.error(ae),g(!1)}finally{W(!1)}},_=async T=>{if(T.startsWith("schedule-")){N(Q=>new Set(Q).add(T)),fe?.id===T&&de(!1);return}c(""),o(Q=>Q.filter(ue=>ue.id!==T)),fe?.id===T&&de(!1);try{await Fm(T)}catch(Q){console.error(Q)}};return e.jsxs("div",{className:"w-full h-full flex flex-col px-[24px] xl:px-[32px] py-[24px] xl:py-[32px] overflow-hidden",children:[e.jsxs("div",{className:"flex flex-col lg:flex-row gap-6 flex-1 min-h-0 w-full max-w-[1400px] mx-auto",children:[e.jsx("div",{className:`flex flex-col flex-1 min-w-0 transition-all duration-500 ${d?"lg:w-[65%] xl:w-[70%]":"lg:w-full"}`,children:e.jsxs("div",{className:"bg-white/90 backdrop-blur-[12px] rounded-[24px] border border-white shadow-[0_8px_32px_rgba(0,0,0,0.04)] overflow-hidden flex flex-col h-full",children:[e.jsxs("div",{className:"p-6 border-b border-[#a855f7] bg-[#a855f7] shrink-0 flex justify-between items-center rounded-t-[24px] relative overflow-hidden group",children:[e.jsx("div",{className:"absolute -bottom-24 -right-12 w-64 h-64 bg-white/10 rounded-full"}),e.jsx("div",{className:"absolute -top-20 left-1/4 w-40 h-40 bg-white/5 rounded-full"}),e.jsxs("div",{className:"flex items-center gap-5 relative z-10",children:[e.jsx("button",{onClick:()=>h(new Date(p.getFullYear(),p.getMonth()-1,1)),"aria-label":"Previous month",className:"w-9 h-9 rounded-full flex items-center justify-center text-[#6d28d9] bg-white hover:bg-slate-50 transition-colors shadow-sm hover:shadow-md active:scale-90",children:e.jsx(zs,{className:"w-5 h-5"})}),e.jsx("h2",{className:"text-[22px] font-bold text-white w-44 text-center tracking-tight",children:Um(p)}),e.jsx("button",{onClick:()=>h(new Date(p.getFullYear(),p.getMonth()+1,1)),"aria-label":"Next month",className:"w-9 h-9 rounded-full flex items-center justify-center text-[#6d28d9] bg-white hover:bg-slate-50 transition-colors shadow-sm hover:shadow-md active:scale-90",children:e.jsx(Ms,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"flex items-center gap-3 relative z-10",children:[e.jsxs("span",{className:"text-[13px] font-bold text-[#6d28d9] bg-white px-4 py-1.5 rounded-full shadow-sm",children:[Pe.length," events"]}),e.jsx("button",{onClick:()=>m(!d),className:`w-9 h-9 rounded-full flex items-center justify-center transition-all shadow-sm hover:shadow-md border ${d?"text-[#6d28d9] bg-white border-white":"text-white bg-white/20 border-white/30 backdrop-blur-md"}`,title:d?"Hide Sidebar":"Show Sidebar","aria-label":d?"Hide Sidebar":"Show Sidebar",children:e.jsx(ed,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"flex-1 flex flex-col min-h-0 overflow-y-auto custom-scrollbar",children:[e.jsx("div",{className:"grid grid-cols-7 text-center border-b border-slate-200/60 pb-5 shrink-0 sticky top-0 bg-white z-20 shadow-[0_10px_10px_-10px_rgba(0,0,0,0.05)] px-4 pt-6",children:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"].map(T=>e.jsx("div",{className:"text-[12px] font-bold text-[#475569] uppercase tracking-widest",children:T},T))}),e.jsx("div",{className:"grid grid-cols-7 gap-2 pb-6 px-4",children:Y.map(T=>{const Q=Gs(T),ue=G.get(Q)||[],ce=Qo(T,b),ae=Qo(T,new Date),Ce=Hm(T,p);return e.jsxs("div",{onClick:()=>S(new Date(T)),className:`group p-2 rounded-lg transition-all cursor-pointer border-2 flex flex-col relative min-h-[100px] xl:min-h-[120px] ${ce?"bg-purple-50/50 border-[#a855f7] shadow-sm z-10":ae?"bg-purple-50/20 border-purple-300 shadow-[inset_0_0_20px_rgba(168,85,247,0.05)] hover:bg-purple-50/40 hover:border-purple-400":"border-transparent hover:bg-slate-50 hover:border-slate-200"} ${Ce?"":"opacity-30 grayscale"}`,children:[e.jsx("div",{className:"flex justify-between items-start",children:e.jsx("span",{className:`w-7 h-7 rounded-full flex items-center justify-center font-bold text-[14px] transition-all ${ae?"bg-gradient-to-br from-[#a855f7] to-[#9333ea] text-white shadow-md":ce?"text-[#9333ea]":"text-[#1e293b]"}`,children:T.getDate()})}),e.jsxs("div",{className:"mt-1 space-y-1",children:[ue.slice(0,3).map(Ne=>{const Je=Ne.id.startsWith("schedule-");return e.jsx("div",{onClick:$e=>D($e,Ne),className:`w-full truncate text-[11px] font-bold px-2 py-1.5 rounded border shadow-sm transition-all hover:-translate-y-[1px] hover:shadow-md cursor-pointer ${Qm(Ne.color,Je)}`,children:Ne.title},Ne.id)}),ue.length>3&&e.jsxs("div",{className:"text-[10px] font-bold text-[#64748b] pl-1 pt-0.5",children:["+",ue.length-3," more"]})]})]},Q)})})]})]})}),e.jsx(zt,{children:d&&e.jsx(Le.div,{initial:{opacity:0,x:20},animate:{opacity:1,x:0},exit:{opacity:0,x:20},className:"lg:w-[35%] xl:w-[30%] h-full shrink-0",children:e.jsxs("div",{className:"bg-white/90 backdrop-blur-[12px] rounded-[24px] border border-white shadow-[0_8px_32px_rgba(0,0,0,0.04)] overflow-hidden flex flex-col h-full",children:[e.jsxs("div",{className:"p-6 border-b border-[#f1f5f9] bg-white shrink-0 flex justify-between items-center relative overflow-hidden group",children:[e.jsx("div",{className:"absolute top-[-30px] right-[-30px] w-24 h-24 bg-purple-50 rounded-full mix-blend-multiply filter blur-2xl opacity-50 transition-transform duration-700 group-hover:scale-150"}),e.jsxs("div",{className:"relative z-10",children:[e.jsx("h2",{className:"text-[20px] font-bold text-[#1e293b]",children:b.toLocaleDateString(void 0,{weekday:"long"})}),e.jsx("p",{className:"text-[13px] font-medium text-[#64748b]",children:b.toLocaleDateString(void 0,{day:"numeric",month:"long",year:"numeric"})})]}),e.jsx("button",{onClick:()=>V(b),title:"Add Event",className:"w-10 h-10 flex items-center justify-center rounded-full bg-[#a855f7] text-white hover:bg-[#9333ea] shadow-md shadow-purple-200 transition-all hover:scale-105 active:scale-95 relative z-10",children:e.jsx(da,{className:"w-5 h-5"})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-6 space-y-6 custom-scrollbar pb-12",children:E.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-20 text-center opacity-40",children:[e.jsx(Er,{className:"w-12 h-12 text-slate-300 mb-4"}),e.jsx("p",{className:"text-[14px] font-bold text-[#1e293b]",children:"No events today"}),e.jsx("p",{className:"text-[12px] text-[#64748b]",children:"Schedule a meeting or add a class."})]}):E.map(T=>{const Q=T.id.startsWith("schedule-"),ue=Vm(T.color,Q);return e.jsxs("div",{className:"relative pl-6 before:absolute before:left-2 before:top-2 before:bottom-[-24px] before:w-[2px] before:bg-slate-100 last:before:hidden",children:[e.jsx("div",{className:`absolute left-0 top-1.5 w-4 h-4 rounded-full border-[3px] border-white shadow-sm z-10 ${ue.dot}`}),e.jsxs("div",{onClick:ce=>D(ce,T),className:`group relative bg-white border border-[#e2e8f0] rounded-[20px] p-5 shadow-sm hover:shadow-md hover:-translate-y-0.5 transition-all border-l-[6px] cursor-pointer ${ue.border}`,children:[e.jsx("div",{className:"flex justify-between items-start mb-2",children:e.jsx("h4",{className:"text-[15px] font-bold text-[#1e293b] group-hover:text-[#9333ea] transition-colors break-words line-clamp-2 w-full pr-2",children:T.title})}),e.jsxs("div",{className:`flex items-center gap-2 text-[11px] font-bold bg-slate-50 w-max px-2.5 py-1 rounded-lg border mb-3 ${ue.time}`,children:[e.jsx(As,{className:"w-3.5 h-3.5"})," ",e.jsxs("span",{children:[qa(T.startTime),T.endTime?` - ${qa(T.endTime)}`:""]})]}),T.description&&e.jsx("p",{className:"text-[13px] font-medium text-[#64748b] bg-slate-50/50 px-3 py-2 rounded-xl border border-slate-100/30 break-words whitespace-normal w-full overflow-hidden",children:T.description})]})]},T.id)})})]})})})]}),e.jsx(Qn,{open:v,onOpenChange:g,children:e.jsx(Vn,{className:"sm:max-w-[500px] p-0 overflow-hidden rounded-[28px] border-none shadow-2xl [&>button]:hidden",children:e.jsxs("div",{className:"p-8 bg-white",children:[e.jsxs(_c,{className:"mb-6",children:[e.jsx(Ec,{className:"text-[24px] font-bold text-[#1e293b] tracking-tight",children:I?"Edit Event":"Add New Event"}),e.jsx(Rc,{className:"text-[14px] text-[#64748b]",children:"Schedule a classroom activity or reminder."})]}),l&&e.jsx("p",{className:"text-rose-500 text-sm font-semibold mb-4",children:l}),e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-[13px] font-bold text-[#1e293b] ml-1",children:"Event Title"}),e.jsx(Is,{value:f,onChange:T=>C(T.target.value),placeholder:"e.g., Mathematics Quiz - Grade 11",className:"bg-white border-slate-200 focus:border-[#a855f7] focus:ring-4 focus:ring-purple-50 rounded-xl h-12 px-4 transition-all text-[14px]"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-[13px] font-bold text-[#1e293b] ml-1",children:"Date"}),e.jsx(Is,{type:"date",value:A,onChange:T=>y(T.target.value),className:"bg-white border-slate-200 focus:border-[#a855f7] rounded-xl h-12 px-4 text-[14px]"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-[13px] font-bold text-[#1e293b] ml-1",children:"Start Time"}),e.jsx(Is,{type:"time",value:q,onChange:T=>J(T.target.value),className:"bg-white border-slate-200 focus:border-[#a855f7] rounded-xl h-12 px-4 text-[14px]"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-[13px] font-bold text-[#1e293b] ml-1",children:"Notes (Optional)"}),e.jsx(Om,{value:w,onChange:T=>$(T.target.value),placeholder:"Additional details about this event...",className:"bg-white border-slate-200 focus:border-[#a855f7] rounded-xl min-h-[100px] p-4 transition-all text-[14px] break-all"})]}),e.jsxs("div",{className:"space-y-2 pt-2",children:[e.jsx("label",{className:"text-[13px] font-bold text-[#1e293b] ml-1",children:"Color Theme"}),e.jsx("div",{className:"flex gap-3 ml-1",children:Gm.map(T=>e.jsx("button",{onClick:()=>be(T),className:`w-8 h-8 rounded-full flex items-center justify-center transition-all ${ne===T?"ring-2 ring-offset-2 ring-slate-800 scale-110 shadow-sm":"hover:scale-110 opacity-80 hover:opacity-100"}`,style:{backgroundColor:Or(T)},title:T,children:ne===T&&e.jsx(Ht,{className:"w-4 h-4 text-white"})},T))})]})]}),e.jsxs("div",{className:"flex gap-3 mt-8",children:[e.jsx(St,{variant:"outline",onClick:()=>g(!1),className:"flex-1 h-12 rounded-xl font-bold border-slate-200 hover:bg-slate-100 transition-all text-[14px]",children:"Cancel"}),e.jsx(St,{onClick:j,disabled:R,className:"flex-[1.5] h-12 rounded-xl font-bold bg-[#a855f7] hover:bg-[#9333ea] text-white shadow-lg shadow-purple-200 transition-all hover:scale-[1.02] text-[14px]",children:R?e.jsx(gt,{className:"w-5 h-5 animate-spin"}):"Save Event"})]})]})})}),e.jsx(Qn,{open:Ie,onOpenChange:de,children:e.jsx(Vn,{className:"sm:max-w-[400px] p-0 overflow-hidden rounded-[24px] border-none shadow-2xl [&>button]:hidden",children:fe&&e.jsxs("div",{className:"p-8 bg-white relative",children:[e.jsx("button",{onClick:()=>de(!1),"aria-label":"Close event details",className:"absolute top-4 right-4 p-2 text-slate-400 hover:text-slate-600 hover:bg-slate-100 rounded-full transition-colors",children:e.jsx(Xt,{size:18})}),e.jsxs("div",{className:"flex items-start gap-4 mb-6",children:[e.jsx("div",{className:"w-12 h-12 rounded-2xl flex items-center justify-center shrink-0",style:{backgroundColor:Or(fe.color||"purple")+"20",color:Or(fe.color||"purple")},children:fe.id.startsWith("schedule-")?e.jsx(nr,{size:24}):e.jsx(Er,{size:24})}),e.jsxs("div",{className:"pr-6",children:[e.jsx("h3",{className:"text-[18px] font-bold text-[#1e293b] leading-tight mb-2",children:fe.title}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2.5 py-1 rounded-md bg-slate-100 text-slate-600 text-[12px] font-semibold border border-slate-200",children:[e.jsx(Er,{size:12}),fe.startTime.toLocaleDateString(void 0,{weekday:"short",month:"short",day:"numeric"})]}),e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2.5 py-1 rounded-md bg-slate-100 text-slate-600 text-[12px] font-semibold border border-slate-200",children:[e.jsx(As,{size:12}),qa(fe.startTime),fe.endTime?` - ${qa(fe.endTime)}`:""]})]})]})]}),fe.description&&e.jsxs("div",{className:"mb-8",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(Oc,{size:16,className:"text-slate-400"}),e.jsx("h4",{className:"text-[13px] font-bold text-slate-700",children:"Details"})]}),e.jsx("p",{className:"text-[14px] text-slate-600 leading-relaxed bg-slate-50/50 p-4 rounded-xl border border-slate-100/50 break-words",children:fe.description})]}),e.jsxs("div",{className:"flex gap-3 pt-2 border-t border-slate-100",children:[e.jsxs(St,{variant:"outline",onClick:()=>_(fe.id),className:"flex-1 h-11 rounded-xl font-bold border-rose-200 text-rose-600 hover:bg-rose-50 hover:text-rose-700 transition-all text-[13px]",children:[e.jsx(wi,{className:"w-4 h-4 mr-2"})," Delete"]}),e.jsxs(St,{onClick:()=>pe(fe),className:"flex-1 h-11 rounded-xl font-bold bg-[#1e293b] hover:bg-slate-800 text-white shadow-lg shadow-slate-200 transition-all hover:scale-[1.02] text-[13px]",children:[e.jsx(ki,{className:"w-4 h-4 mr-2"})," Edit Event"]})]})]})})})]})},hr=[{hex:"#9956DE",bg:"bg-[#9956DE]/10",border:"border-[#9956DE]/20",borderLeft:"border-l-[#9956DE]",text:"text-[#9956DE]",groupHover:"group-hover:text-[#9956DE]"},{hex:"#7274ED",bg:"bg-[#7274ED]/10",border:"border-[#7274ED]/20",borderLeft:"border-l-[#7274ED]",text:"text-[#7274ED]",groupHover:"group-hover:text-[#7274ED]"},{hex:"#1FA7E1",bg:"bg-[#1FA7E1]/10",border:"border-[#1FA7E1]/20",borderLeft:"border-l-[#1FA7E1]",text:"text-[#1FA7E1]",groupHover:"group-hover:text-[#1FA7E1]"},{hex:"#6ED1CF",bg:"bg-[#6ED1CF]/10",border:"border-[#6ED1CF]/20",borderLeft:"border-l-[#6ED1CF]",text:"text-[#6ED1CF]",groupHover:"group-hover:text-[#6ED1CF]"},{hex:"#FFB356",bg:"bg-[#FFB356]/10",border:"border-[#FFB356]/20",borderLeft:"border-l-[#FFB356]",text:"text-[#FFB356]",groupHover:"group-hover:text-[#FFB356]"}],Wo=({classes:t,onSelectClass:s,onOpenNotifications:a,onOpenProfile:r,insightDismissed:o,onOpenInsightModal:n,viewType:i="analytics",onCreateClass:l})=>{const{currentUser:c,userProfile:d}=hs(),[m,p]=u.useState(""),h=i==="competency",b=t.reduce((g,I)=>g+(I.studentCount||0),0),S=t.reduce((g,I)=>g+(I.atRiskCount||0),0),k=t.length>0?(t.reduce((g,I)=>g+(I.avgScore||0),0)/t.length).toFixed(1):0,N=u.useMemo(()=>{const g=[],I=t.filter(R=>R.atRiskCount>0);if(I.length>0){const R=[...I].sort((W,f)=>f.atRiskCount-W.atRiskCount)[0];g.push({icon:Kr,text:e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"font-bold text-white",children:R.name})," has ",R.atRiskCount," at-risk student",R.atRiskCount>1?"s":""," needing intervention."]})})}const z=t.filter(R=>R.avgScore>0&&R.avgScore<60);return z.length>0&&g.push({icon:Kr,text:e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"font-bold text-white",children:[z.length," class",z.length>1?"es":""]})," below 60% average — consider review sessions."]})}),S===0&&b>0&&g.push({icon:ps,text:e.jsxs(e.Fragment,{children:["All ",e.jsxs("span",{className:"font-bold text-white",children:[b," students"]})," are on track. Great work!"]})}),t.length>0&&Number(k)===0&&g.push({icon:Gt,text:e.jsxs(e.Fragment,{children:["No quiz data yet. ",e.jsx("span",{className:"font-bold text-white",children:"Assign assessments"})," to start tracking progress."]})}),g.length===0&&g.push({icon:ps,text:e.jsx(e.Fragment,{children:"No action items right now. Check back after students complete activities."})}),g},[t,S,b,k]),v=t.filter(g=>g.name.toLowerCase().includes(m.toLowerCase())||(g.gradeLevel||"").toLowerCase().includes(m.toLowerCase()));return e.jsx("div",{className:"h-full overflow-y-auto w-full block",children:e.jsxs("div",{className:"max-w-[1400px] mx-auto p-3 sm:p-[24px] xl:p-[32px] space-y-3 sm:space-y-[24px]",children:[e.jsx("div",{className:"flex flex-col md:flex-row md:items-center justify-between gap-4",children:e.jsx("div",{className:"flex-1 max-w-xl",children:e.jsxs("div",{className:"flex items-center bg-white/80 px-4 py-2.5 rounded-[16px] shadow-[0_1px_4px_rgba(0,0,0,0.04)] border border-white backdrop-blur-[12px] group focus-within:ring-2 focus-within:ring-indigo-500/20 transition-all",children:[e.jsx(qs,{className:"w-4 h-4 text-[#64748b] shrink-0 group-focus-within:text-[#4f46e5] transition-colors"}),e.jsx("input",{type:"text",placeholder:"Global search for a student across all classes...",value:m,onChange:g=>p(g.target.value),className:"bg-transparent border-none focus:outline-none ml-3 text-[13px] w-full text-[#475569] placeholder:text-[#94a3b8]"})]})})}),h?e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-[16px]",children:[e.jsxs("div",{className:"relative overflow-hidden bg-gradient-to-br from-[#a855f7] to-[#9333ea] rounded-[16px] p-[20px] shadow-[0_4px_12px_rgba(168,85,247,0.2)] flex flex-col justify-between h-full group text-white",children:[e.jsx("div",{className:"absolute -right-12 -bottom-12 w-40 h-40 bg-white/10 rounded-full"}),e.jsxs("div",{className:"flex items-start justify-between relative z-10 mb-4",children:[e.jsx("span",{className:"text-[13px] font-medium text-white/90",children:"Total Students Evaluated"}),e.jsx("div",{className:"w-8 h-8 rounded-full border border-white/30 flex items-center justify-center bg-white/10",children:e.jsx(us,{className:"w-4 h-4 text-white"})})]}),e.jsx("div",{className:"text-[32px] font-bold relative z-10 leading-none mb-6",children:b}),e.jsx("div",{className:"flex items-center justify-between relative z-10 border-t border-white/20 pt-3",children:e.jsx("span",{className:"text-[12px] font-medium text-white/90",children:"Active across all classes"})})]}),e.jsxs("div",{className:"relative overflow-hidden bg-gradient-to-br from-[#0ea5e9] to-[#0284c7] rounded-[16px] p-[20px] shadow-[0_4px_12px_rgba(14,165,233,0.2)] flex flex-col justify-between h-full group text-white",children:[e.jsx("div",{className:"absolute -right-12 -bottom-12 w-40 h-40 bg-white/10 rounded-full"}),e.jsxs("div",{className:"flex items-start justify-between relative z-10 mb-4",children:[e.jsx("span",{className:"text-[13px] font-medium text-white/90",children:"Global Avg Competency"}),e.jsx("div",{className:"w-8 h-8 rounded-full border border-white/30 flex items-center justify-center bg-white/10",children:e.jsx(ms,{className:"w-4 h-4 text-white"})})]}),e.jsxs("div",{className:"text-[32px] font-bold relative z-10 leading-none mb-6",children:[k,"%"]}),e.jsx("div",{className:"flex items-center justify-between relative z-10 border-t border-white/20 pt-3",children:e.jsxs("span",{className:"text-[12px] font-medium text-white/90",children:["Across ",t.length," ",t.length===1?"class":"classes"]})})]}),e.jsxs("div",{className:"relative overflow-hidden bg-gradient-to-br from-[#f97316] to-[#ea580c] rounded-[16px] p-[20px] shadow-[0_4px_12px_rgba(249,115,22,0.2)] flex flex-col justify-between h-full group text-white",children:[e.jsx("div",{className:"absolute -right-12 -bottom-12 w-40 h-40 bg-white/10 rounded-full"}),e.jsxs("div",{className:"flex items-start justify-between relative z-10 mb-4",children:[e.jsx("span",{className:"text-[13px] font-medium text-white/90",children:"Universal Weakness"}),e.jsx("div",{className:"w-8 h-8 rounded-full border border-white/30 flex items-center justify-center bg-white/10",children:e.jsx(ms,{className:"w-4 h-4 text-white"})})]}),e.jsx("div",{className:"text-[20px] font-bold relative z-10 leading-tight mb-2 truncate",children:"Foundational Skills"}),e.jsx("div",{className:"flex items-center justify-between relative z-10 border-t border-white/20 pt-3 mt-auto",children:e.jsxs("span",{className:"text-[12px] font-medium text-white/90",children:["Identified in ",t.length," classes"]})})]})]}):e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-12 gap-2 sm:gap-[16px]",children:[e.jsxs("div",{className:"lg:col-span-8 grid grid-cols-3 sm:grid-cols-3 gap-2 sm:gap-[16px]",children:[e.jsxs("div",{className:"relative overflow-hidden bg-gradient-to-br from-[#10b981] to-[#059669] rounded-[14px] sm:rounded-[16px] p-[14px] sm:p-[20px] shadow-[0_4px_12px_rgba(16,185,129,0.2)] flex flex-col justify-between h-full group text-white",children:[e.jsx("div",{className:"absolute -right-12 -bottom-12 w-40 h-40 bg-white/10 rounded-full"}),e.jsxs("div",{className:"flex items-start justify-between relative z-10 mb-2 sm:mb-4",children:[e.jsx("span",{className:"text-[11px] sm:text-[13px] font-medium text-white/90",children:"Total Students"}),e.jsx("div",{className:"w-8 h-8 rounded-full border border-white/30 flex items-center justify-center bg-white/10",children:e.jsx(us,{className:"w-4 h-4 text-white"})})]}),e.jsx("div",{className:"text-[24px] sm:text-[32px] font-bold relative z-10 leading-none mb-3 sm:mb-6",children:b}),e.jsx("div",{className:"flex items-center justify-between relative z-10 border-t border-white/20 pt-3",children:e.jsxs("span",{className:"text-[12px] font-medium text-white/90",children:["Across ",t.length," ",t.length===1?"class":"classes"]})})]}),e.jsxs("div",{className:"relative overflow-hidden bg-gradient-to-br from-[#0ea5e9] to-[#0284c7] rounded-[14px] sm:rounded-[16px] p-[14px] sm:p-[20px] shadow-[0_4px_12px_rgba(14,165,233,0.2)] flex flex-col justify-between h-full group text-white",children:[e.jsx("div",{className:"absolute -right-12 -bottom-12 w-40 h-40 bg-white/10 rounded-full"}),e.jsxs("div",{className:"flex items-start justify-between relative z-10 mb-2 sm:mb-4",children:[e.jsx("span",{className:"text-[11px] sm:text-[13px] font-medium text-white/90",children:"Class average"}),e.jsx("div",{className:"w-8 h-8 rounded-full border border-white/30 flex items-center justify-center bg-white/10",children:e.jsx(ms,{className:"w-4 h-4 text-white"})})]}),e.jsxs("div",{className:"text-[24px] sm:text-[32px] font-bold relative z-10 leading-none mb-3 sm:mb-6",children:[k,"%"]}),e.jsx("div",{className:"flex items-center justify-between relative z-10 border-t border-white/20 pt-3",children:e.jsxs("span",{className:"text-[12px] font-medium text-white/90",children:["Across ",t.length," ",t.length===1?"class":"classes"]})})]}),e.jsxs("div",{className:"relative overflow-hidden bg-gradient-to-br from-[#f97316] to-[#ea580c] rounded-[14px] sm:rounded-[16px] p-[14px] sm:p-[20px] shadow-[0_4px_12px_rgba(249,115,22,0.2)] flex flex-col justify-between h-full group text-white",children:[e.jsx("div",{className:"absolute -right-12 -bottom-12 w-40 h-40 bg-white/10 rounded-full"}),e.jsxs("div",{className:"flex items-start justify-between relative z-10 mb-2 sm:mb-4",children:[e.jsx("span",{className:"text-[11px] sm:text-[13px] font-medium text-white/90",children:"At risk"}),e.jsx("div",{className:"w-8 h-8 rounded-full border border-white/30 flex items-center justify-center bg-white/10",children:e.jsx(br,{className:"w-4 h-4 text-white"})})]}),e.jsx("div",{className:"text-[24px] sm:text-[32px] font-bold relative z-10 leading-none mb-3 sm:mb-6",children:S}),e.jsxs("div",{className:"flex items-center justify-between relative z-10 border-t border-white/20 pt-3",children:[e.jsx("span",{className:"text-[12px] font-medium text-white/90",children:"Requires attention"}),e.jsxs("span",{className:"text-[11px] font-bold bg-white/20 px-2 py-0.5 rounded-[4px] backdrop-blur-sm",children:[b>0?Math.round(S/b*100):0,"%"]})]})]})]}),e.jsxs("div",{className:"lg:col-span-4 relative overflow-hidden bg-gradient-to-br from-[#a855f7] to-[#9333ea] rounded-[16px] p-[20px] shadow-[0_4px_12px_rgba(168,85,247,0.2)] flex flex-col text-white",children:[e.jsx("div",{className:"absolute -right-12 -top-12 w-40 h-40 bg-white/10 rounded-full"}),e.jsxs("div",{className:"flex justify-between items-center mb-4 relative z-10 border-b border-white/20 pb-3",children:[e.jsxs("h3",{className:"text-[14px] font-semibold text-white flex items-center gap-2",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-white animate-pulse shadow-[0_0_8px_rgba(255,255,255,0.8)]"}),"AI Action Items"]}),e.jsxs("span",{className:"text-[10px] font-bold text-[#9333ea] bg-white px-2 py-0.5 rounded-[4px]",children:[N.length," Pending"]})]}),e.jsx("div",{className:"space-y-[8px] flex-1 overflow-y-auto no-scrollbar relative z-10",children:N.map((g,I)=>e.jsxs("div",{className:"bg-white/10 hover:bg-white/20 rounded-[8px] p-3 text-[12px] border border-white/10 transition-colors backdrop-blur-sm group cursor-pointer flex gap-3 items-start",children:[e.jsx("div",{className:"mt-0.5 shrink-0 text-white/80 group-hover:text-white transition-colors",children:e.jsx(g.icon,{className:"w-4 h-4"})}),e.jsx("div",{className:"leading-snug text-white/90",children:g.text})]},I))})]})]}),e.jsxs("div",{className:"bg-white/60 backdrop-blur-[12px] rounded-[24px] p-3 sm:p-[24px] shadow-[0_1px_4px_rgba(0,0,0,0.02)] border border-white mt-3 sm:mt-[24px]",children:[e.jsxs("div",{className:"mb-6 border-b border-[#f1f5f9] pb-4 flex items-center justify-between",children:[e.jsx("h2",{className:"text-[18px] font-semibold text-[#1e293b]",children:h?"Select a Class":"My Classes"}),l&&!h&&e.jsxs("button",{onClick:l,className:"flex items-center gap-1.5 px-3 py-1.5 text-[12px] font-semibold text-[#9956DE] bg-[#9956DE]/10 rounded-lg hover:bg-[#9956DE]/20 transition-colors",children:[e.jsx(da,{size:14}),"Create Class"]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-[16px]",children:[v.map((g,I)=>{const z=hr[I%hr.length];let R=null;return g.riskLevel==="high"?R=e.jsx("span",{className:"inline-flex px-2 py-1 bg-rose-50 text-rose-600 text-[10px] font-bold rounded-md border border-rose-100/50 uppercase",children:"High Risk"}):g.riskLevel==="medium"?R=e.jsx("span",{className:"inline-flex px-2 py-1 bg-amber-50 text-amber-600 text-[10px] font-bold rounded-md border border-amber-100/50 uppercase",children:"Medium Risk"}):R=e.jsx("span",{className:"inline-flex px-2 py-1 bg-emerald-50 text-emerald-600 text-[10px] font-bold rounded-md border border-emerald-100/50 uppercase",children:"On Track"}),e.jsxs("div",{onClick:()=>s(g),className:`flex flex-col p-[16px] bg-white shadow-[0_1px_4px_rgba(0,0,0,0.04)] hover:shadow-md hover:-translate-y-0.5 rounded-[18px] transition-all cursor-pointer group border border-[#f1f5f9] border-l-[6px] ${z.borderLeft}`,children:[e.jsxs("div",{className:"flex justify-between items-start mb-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`w-10 h-10 rounded-[12px] ${z.bg} flex items-center justify-center border ${z.border}`,children:e.jsx(Gt,{className:`w-5 h-5 ${z.text}`})}),e.jsxs("div",{children:[e.jsx("h4",{className:`font-bold text-[14px] text-[#1e293b] mb-0.5 transition-colors ${z.groupHover}`,children:g.name}),e.jsx("p",{className:"text-[11px] font-semibold text-[#64748b] uppercase tracking-wider",children:g.gradeLevel||"Senior High"})]})]}),R]}),e.jsxs("div",{className:"flex items-center justify-between text-[13px] text-[#475569] bg-[#f8fafc] rounded-[12px] p-3 border border-[#f1f5f9]",children:[e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-[10px] font-semibold text-[#64748b] uppercase tracking-wider mb-1",children:"Students"}),e.jsx("span",{className:"font-semibold text-[#1e293b]",children:g.studentCount})]}),e.jsx("div",{className:"w-[1px] h-8 bg-[#e2e8f0]"}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-[10px] font-semibold text-[#64748b] uppercase tracking-wider mb-1",children:h?"Avg Competency":"Average"}),e.jsxs("span",{className:"font-semibold text-[#1e293b]",children:[g.avgScore,"%"]})]}),!h&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-[1px] h-8 bg-[#e2e8f0]"}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-[10px] font-semibold text-[#64748b] uppercase tracking-wider mb-1",children:"Schedule"}),e.jsx("span",{className:"font-semibold text-[#1e293b]",children:g.schedule||"Mon-Fri"})]})]})]})]},g.id)}),v.length===0&&e.jsx("div",{className:"col-span-full py-8 text-center text-[#64748b] text-[13px] bg-[#f8fafc] rounded-[18px] border border-[#e2e8f0]",children:"No classes match your search."})]})]})]})})},wl="PH_SHS_OFFICIAL_CLASS_RECORD",Ym=.85,on=.85,Km="2026.04.24",Nl=4,sr=["INPUT DATA","SENIOR HIGH SCHOOL CLASS RECORD","LEARNERS NAMES","WRITTEN WORK","PERFORMANCE TASKS","QUARTERLY ASSESSMENT","REMARK","FINAL SEMESTRAL GRADES"],Xm=[...sr,"Pursuant to DepEd Order 8 series of 2015","INITIAL GRADE","QUARTERLY GRADE","ADDITIONAL REMARKS","MALE","FEMALE","SUBMITTED BY","CHECKED BY","VERIFIED BY","RECOMMENDED BY","APPROVED BY","WEIGHT OF COMPONENTS","LOOK UP","HELPER","ATTACHMENTS"],Jm=["SUBMITTED BY","CHECKED BY","VERIFIED BY","RECOMMENDED BY","APPROVED BY"],Fa=["WITH ATTACHMENTS","OFFICIALLY DROPPED","WITHDRAWN","UNOFFICIALLY DROPPED","TRANSFEREE","SHIFTER"],Zm=["TOTAL","SUBMITTED BY","CHECKED BY","VERIFIED BY","RECOMMENDED BY","APPROVED BY","WEIGHT OF COMPONENTS"],ex={SECOND:["SECOND QUARTER","2ND QUARTER","Q2"]},sa={inputData:["input data"],firstQuarter:["first quarter","1st quarter","q1"],secondQuarter:["second quarter","2nd quarter","q2"],finalSemestral:["final semestral","final grades","semestral"],helper:["helper","weight","attachments"],lookup:["look up","lookup","reference"]},Wt={region:["REGION"],division:["DIVISION"],schoolName:["SCHOOL NAME"],schoolId:["SCHOOL ID"],schoolYear:["SCHOOL YEAR"],gradeSection:["GRADE / SECTION","GRADE/SECTION"],semester:["SEMESTER"],track:["TRACK"],subjectCode:["SUBJECT CODE"],subjectName:["SUBJECT NAME","SUBJECT"],teacherName:["TEACHER","NAME OF TEACHER"]},Ue={learnerNo:["NO","NO.","#"],learnerName:["LEARNERS NAMES","LEARNER NAME","NAME"],writtenWork:["WRITTEN WORK","WW"],performanceTasks:["PERFORMANCE TASKS","PT"],quarterlyAssessment:["QUARTERLY ASSESSMENT","QA"],total:["TOTAL"],ps:["PS"],ws:["WS"],initialGrade:["INITIAL GRADE"],quarterlyGrade:["QUARTERLY GRADE"],firstQuarter:["FIRST QUARTER","1ST QUARTER"],secondQuarter:["SECOND QUARTER","2ND QUARTER"],firstSemester:["FIRST SEMESTER"],finalGrades:["FINAL GRADES","FINAL GRADE"],remark:["REMARK","REMARKS"],additionalRemarks:["ADDITIONAL REMARKS","ADDITIONAL REMARK"]};function tx(t){return t==null?null:typeof t=="string"||typeof t=="number"||typeof t=="boolean"?t:String(t)}function It(t){return String(t??"").replace(/[\u00a0\t\r\n]+/g," ").replace(/[|]+/g," ").replace(/\s+/g," ").trim().toUpperCase()}function qo(t){return It(t).replace(/[^A-Z0-9]+/g,"")}function _e(t,s){const a=It(t),r=It(s);if(!a||!r)return!1;if(a.includes(r))return!0;const o=qo(t),n=qo(s);return!o||!n?!1:o.includes(n)}function ar(t){if(typeof t=="number"&&Number.isFinite(t))return t;if(typeof t=="string"){const s=t.replace(/,/g,"").trim();if(!s)return;const a=Number(s);if(Number.isFinite(a))return a}}function Br(t){return It(t).toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"").slice(0,80)}function jl(t){const s={};return t.forEach(a=>{const r=Kt.encode_cell(a.s);for(let o=a.s.r;o<=a.e.r;o+=1)for(let n=a.s.c;n<=a.e.c;n+=1){const i=Kt.encode_cell({r:o,c:n});s[i]=r}}),s}function sx(t,s,a){const o=(a||jl(t.merges))[s]||s;return t.cells[o]||t.cells[s]}const yl="A1:A1",Yo=1200,Ko=200,Xo=2e5;function ax(t){const s=Math.max(0,t.s.r),a=Math.max(0,t.s.c);let r=Math.max(s,t.e.r),o=Math.max(a,t.e.c);r-s+1>Yo&&(r=s+Yo-1),o-a+1>Ko&&(o=a+Ko-1);const n=r-s+1,i=o-a+1;if(n*i>Xo){const c=Math.max(1,Math.floor(Xo/i));r=s+Math.min(n,c)-1}return{s:{r:s,c:a},e:{r,c:o}}}function rx(t){try{return Kt.decode_range(t)}catch{return Kt.decode_range(yl)}}function nx(t){let s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY,o=Number.NEGATIVE_INFINITY;return Object.keys(t.cells).forEach(n=>{try{const i=Kt.decode_cell(n);s=Math.min(s,i.r),a=Math.min(a,i.c),r=Math.max(r,i.r),o=Math.max(o,i.c)}catch{}}),t.merges.forEach(n=>{s=Math.min(s,n.s.r,n.e.r),a=Math.min(a,n.s.c,n.e.c),r=Math.max(r,n.s.r,n.e.r),o=Math.max(o,n.s.c,n.e.c)}),!Number.isFinite(s)||!Number.isFinite(a)||!Number.isFinite(r)||!Number.isFinite(o)?null:{s:{r:Math.max(0,Math.trunc(s)),c:Math.max(0,Math.trunc(a))},e:{r:Math.max(0,Math.trunc(r)),c:Math.max(0,Math.trunc(o))}}}function ox(t){const s=rx(t.ref||yl),a=nx(t);return ax(a||s)}function ix(t,s){const a=ox(s),r=`${Kt.encode_cell(a.s)}:${Kt.encode_cell(a.e)}`,o=jl(s.merges),n=a.e.r-a.s.r+1,i=a.e.c-a.s.c+1,l=[];for(let c=0;ct.endRow||at.endCol?null:t.cells[s-t.startRow]?.[a-t.startCol]??null}function Ps(t,s){return st.endRow?"":(t.cells[s-t.startRow]||[]).map(r=>r?.normalizedText||"").filter(Boolean).join(" ").trim()}function Na(t){return Kt.encode_col(t)}function Ya(t){const s=String(t||"").trim().toUpperCase();if(!s||!/^[A-Z]+$/.test(s))return-1;try{return Kt.decode_col(s)}catch{return-1}}function lx(t){return`${Kt.encode_cell(t.s)}:${Kt.encode_cell(t.e)}`}function cx(t,s){const a=[];for(let r=s.s.r;r<=s.e.r;r+=1){const o=[];for(let n=s.s.c;n<=s.e.c;n+=1){const i=Ve(t,r,n);o.push(i?.displayValue??null)}a.push(o)}return a}function dx(t,s){const a=It(t),r=It(s);return!a||!r?0:a===r?1:a.includes(r)?.9:.75}function yn(t,s){const a=[];for(let r=0;r{_e(l.normalizedText,c)&&a.push({sheetName:t.sheetName,anchor:c,row:l.row,col:l.col,address:l.address,value:String(l.displayValue??""),confidence:dx(l.displayValue,c)})})}const o=t.startRow+r,n=Ps(t,o);n&&s.forEach(i=>{if(!_e(n,i))return;const l=t.cells[r].find(c=>c?.normalizedText);l&&a.push({sheetName:t.sheetName,anchor:i,row:o,col:l.col,address:l.address,value:n,confidence:.8})})}return a}function ux(t,s){return Object.values(t).flatMap(a=>yn(a,s))}function Tt(t,s){return yn(t,[s]).sort((a,r)=>a.row-r.row||a.col-r.col)}function Sl(t,s,a,r=6){for(let o=1;o<=r;o+=1){const i=Ve(t,s,a+o)?.displayValue;if(i!=null&&String(i).trim())return String(i).trim()}for(let o=1;o<=r;o+=1){const i=Ve(t,s+o,a)?.displayValue;if(i!=null&&String(i).trim())return String(i).trim()}}function kl(t,s,a=5){let r=s,o=-1;for(let n=Math.max(t.startRow,s-a);n<=Math.min(t.endRow,s+a);n+=1){const i=Ps(t,n),l=["LEARNERS NAMES","WRITTEN WORK","PERFORMANCE TASKS","QUARTERLY ASSESSMENT","REMARK"].reduce((c,d)=>i.includes(d)?c+1:c,0);l>o&&(o=l,r=n)}return r}function mx(t,s){const a=It(t).toLowerCase(),r=o=>[...s].some(n=>_e(n,o));return sa.inputData.some(o=>a.includes(o))||r("INPUT DATA")?"inputData":sa.finalSemestral.some(o=>a.includes(o))||r("FINAL SEMESTRAL GRADES")||r("FINAL GRADES")?"finalSemestral":sa.firstQuarter.some(o=>a.includes(o))||r("FIRST QUARTER")?"firstQuarter":sa.secondQuarter.some(o=>a.includes(o))||r("SECOND QUARTER")?"secondQuarter":r("SENIOR HIGH SCHOOL CLASS RECORD")||r("WRITTEN WORK")&&r("PERFORMANCE TASKS")?"firstQuarter":sa.helper.some(o=>a.includes(o))||r("WEIGHT OF COMPONENTS")||r("ATTACHMENTS")||r("HELPER")?"helper":sa.lookup.some(o=>a.includes(o))||r("LOOK UP")?"lookup":"other"}function xx(t){const s=t.criticalTotal>0?t.criticalFound/t.criticalTotal:0,a=t.totalSheets>0?t.recognizedSheets/t.totalSheets:0,r=t.hasDepedAnchor?1:0,o=.65*s+.2*a+.15*r;return Number(Math.max(0,Math.min(1,o)).toFixed(4))}function px(t){const s=ux(t.matrices,Xm),a=new Set,r=[];sr.forEach(b=>{s.some(k=>_e(k.anchor,b))&&(a.add(b),r.push(`Found critical anchor: ${b}`))});const o=sr.filter(b=>!a.has(b)),n=new Map;s.forEach(b=>{n.has(b.sheetName)||n.set(b.sheetName,new Set),n.get(b.sheetName)?.add(b.anchor)});const i=t.sheetNames.map(b=>{const S=n.get(b)||new Set,k=mx(b,S),N=Math.min(1,.35+Math.min(.55,S.size*.08)),v=[`sheet:${b}`,`signals:${S.size}`,...[...S].slice(0,5)];return{sheetName:b,role:k,confidence:Number(N.toFixed(3)),evidence:v}}),l={firstQuarter:[],secondQuarter:[],finalSemestral:[],helper:[],lookup:[],other:[]};i.forEach(b=>{switch(b.role){case"inputData":l.inputData?l.other.push(b.sheetName):l.inputData=b.sheetName;break;case"firstQuarter":l.firstQuarter.push(b.sheetName);break;case"secondQuarter":l.secondQuarter.push(b.sheetName);break;case"finalSemestral":l.finalSemestral.push(b.sheetName);break;case"helper":l.helper.push(b.sheetName);break;case"lookup":l.lookup.push(b.sheetName);break;case"other":default:l.other.push(b.sheetName);break}});const c=(l.inputData?1:0)+l.firstQuarter.length+l.secondQuarter.length+l.finalSemestral.length+l.helper.length+l.lookup.length,d=xx({criticalFound:a.size,criticalTotal:sr.length,recognizedSheets:c,totalSheets:t.sheetNames.length,hasDepedAnchor:s.some(b=>_e(b.anchor,"Pursuant to DepEd Order 8 series of 2015"))}),m=l.firstQuarter.length>0||l.secondQuarter.length>0,p=!!l.inputData&&m&&l.finalSemestral.length>0,h=d>=.55&&p;return l.inputData||r.push("Input Data sheet not confidently detected."),m||r.push("No quarter class record sheet detected."),l.finalSemestral.length===0&&r.push("No Final Semestral Grades sheet detected."),{format:wl,isOfficialFormatLikely:h,confidence:d,evidence:r,missingCriticalAnchors:o,detectedSheets:l,anchorMatches:s}}function fr(t){if(typeof t=="number"&&Number.isFinite(t))return t;const s=String(t??"").trim();if(!s)return;const a=Number(s.replace(/[^0-9]/g,""));if(!(!Number.isFinite(a)||a<=0))return a}function Sn(t){const s=It(t);if(s.includes("FEMALE"))return"FEMALE";if(s.includes("MALE"))return"MALE"}function kn(t){const s=It(t.rowText);return s?s==="MALE"||s==="FEMALE"?"sex-header":Jm.some(a=>s.includes(a))?"signature":Zm.some(a=>s.includes(a))?"helper":s.includes("LEARNERS NAMES")||s.includes("WRITTEN WORK")||s.includes("PERFORMANCE TASKS")||s.includes("QUARTERLY ASSESSMENT")||s.includes("INITIAL GRADE")||s.includes("QUARTERLY GRADE")?"header":t.hasLearnerName||t.hasLearnerNumber?"learner":s.includes("ATTACHMENTS")||s.includes("LOOK UP")?"helper":"unknown":"blank"}function hx(t){const s=["SUBMITTED BY","CHECKED BY","VERIFIED BY","RECOMMENDED BY","APPROVED BY"],a=[];return s.forEach(r=>{Tt(t,r).forEach(o=>{a.push({role:r,name:String(Ve(t,o.row,o.col+1)?.displayValue||"").trim()||void 0,sourceSheet:t.sheetName,sourceRow:o.row+1})})}),a}function fx(t){const s=[],a=Tt(t,"LEARNERS NAMES")[0],r=a?kl(t,a.row,5):t.startRow,o=(N,v)=>Tt(t,N).find(I=>Math.abs(I.row-r)<=2)?.col??v,n=o(Ue.learnerNo[0],t.startCol),i=o(Ue.learnerName[0],t.startCol+1),l=o(Ue.firstQuarter[0],i+1),c=o(Ue.secondQuarter[0],l+1),d=o(Ue.firstSemester[0],c+1),m=o(Ue.finalGrades[0],d+1),p=o(Ue.remark[0],m+1),h=o(Ue.additionalRemarks[0],p+1),b=[];let S="UNKNOWN",k=0;for(let N=r+1;N<=t.endRow;N+=1){const v=Ps(t,N),g=kn({rowText:v,hasLearnerNumber:/\b\d{1,2}\b/.test(v),hasLearnerName:/[A-Z]{2,}/.test(v)});if(g==="sex-header"){S=Sn(v)||S;continue}if(g==="signature"||g==="helper")break;if(g==="blank"){if(k+=1,k>=Nl)break;continue}if(g!=="learner")continue;k=0;const I=fr(Ve(t,N,n)?.displayValue),z=String(Ve(t,N,i)?.displayValue||"").trim();if(!z&&I===void 0)continue;const R=Ve(t,N,l)?.displayValue??null,W=Ve(t,N,c)?.displayValue??null,f=Ve(t,N,d)?.displayValue??null,C=Ve(t,N,m)?.displayValue??null,w=Ve(t,N,p)?.displayValue??null;let $=Ve(t,N,h)?.displayValue??null;const A=Fa.filter(y=>_e(v,y));A.length>0&&($=[$,A.join("; ")].filter(Boolean).join("; ")||null),!z&&I!==void 0&&s.push(`Row ${N+1} has learner number ${I} but empty learner name.`),b.push({learnerNo:I,fullName:z||`Unnamed Learner ${I||N+1}`,sex:S,firstQuarter:R,secondQuarter:W,firstSemester:f,finalGrades:C,remark:w,additionalRemarks:$,sourceRow:N+1})}return{sheetName:t.sheetName,learnerGrades:b,signatures:hx(t),warnings:s}}function Zt(t,s){for(const a of s){const r=Tt(t,a);for(const o of r){const n=Sl(t,o.row,o.col,8);if(n&&n.trim())return n.trim()}}}function gx(t){const s=["SUBMITTED BY","CHECKED BY","VERIFIED BY","RECOMMENDED BY","APPROVED BY"],a=[];return s.forEach(r=>{Tt(t,r).forEach(n=>{const i=Sl(t,n.row,n.col,10);a.push({role:r,name:i,sourceSheet:t.sheetName,sourceRow:n.row+1})})}),a}function bx(t){const s=Tt(t,"LEARNERS NAMES")[0];if(!s)return[];const a=s.row+1,r=s.col,o=Math.max(t.startCol,r-1),n=Math.min(t.endCol,r+1),i=Math.min(t.endCol,r+2),l=[];let c="UNKNOWN",d=0;for(let m=a;m<=t.endRow;m+=1){const p=Ps(t,m),h=kn({rowText:p,hasLearnerNumber:!!fr(Ve(t,m,o)?.displayValue),hasLearnerName:!!String(Ve(t,m,r)?.displayValue||"").trim()});if(h==="sex-header"){c=Sn(p)||c,d=0;continue}if(h==="signature"||h==="helper")break;if(h!=="learner"){if(h==="blank"&&(d+=1),d>=5)break;continue}d=0;const b=fr(Ve(t,m,o)?.displayValue),S=String(Ve(t,m,r)?.displayValue||"").trim(),k=String(Ve(t,m,n)?.displayValue||"").trim()||void 0,N=String(Ve(t,m,i)?.displayValue||"").trim()||void 0,v=Fa.filter(g=>_e(p,g));!S&&b===void 0||l.push({learnerNo:b,sex:c,fullName:S||`Unnamed Learner ${b||m}`,sourceSheet:t.sheetName,sourceRow:m+1,remarks:k,additionalRemarks:N,statuses:v.length>0?v:void 0})}return l}function vx(t){const s=[],a=[];for(let r=t.startRow;r<=t.endRow;r+=1){const o=Ps(t,r);if(o){if(Fa.some(n=>_e(o,n))){s.push(o);continue}(_e(o,"IMPORTANT")||_e(o,"NOTE")||_e(o,"ATTACHMENT")||_e(o,"LOOK UP"))&&a.push(o)}}return{attachmentRules:Array.from(new Set(s)),helperNotes:Array.from(new Set(a))}}function wx(t){const s=[],a={region:Zt(t,Wt.region),division:Zt(t,Wt.division),schoolName:Zt(t,Wt.schoolName),schoolId:Zt(t,Wt.schoolId),schoolYear:Zt(t,Wt.schoolYear),gradeSection:Zt(t,Wt.gradeSection),semester:Zt(t,Wt.semester),track:Zt(t,Wt.track),subjectCode:Zt(t,Wt.subjectCode),subjectName:Zt(t,Wt.subjectName),teacherName:Zt(t,Wt.teacherName)},r=bx(t),o=gx(t),{attachmentRules:n,helperNotes:i}=vx(t);return a.schoolName||s.push("Input Data metadata is missing School Name."),a.schoolYear||s.push("Input Data metadata is missing School Year."),r.length===0&&s.push("No learners detected in Input Data sheet."),yn(t,Object.values(Wt).flat()).length<4&&s.push("Input Data sheet contains limited metadata anchors; layout may have drifted."),{sheetName:t.sheetName,schoolContext:a,learners:r,signatures:o,attachmentRules:n,helperNotes:i,warnings:s}}function Nx(t){const s=It(t.sheetName);return ex.SECOND.some(a=>_e(s,a))?"SECOND":"FIRST"}function jx(t,s){const a=[],r=[],o=[];let n,i="NONE";for(let l=t.startCol;l<=t.endCol;l+=1){const c=Ve(t,s,l),d=It(c?.displayValue||""),m=Ve(t,s+1,l),p=String(m?.displayValue||c?.displayValue||"").trim();if(!d&&!p)continue;if(_e(d,Ue.writtenWork[0])){i="WW";continue}if(_e(d,Ue.performanceTasks[0])){i="PT";continue}if(_e(d,Ue.quarterlyAssessment[0])){n={key:Br(p||"quarterly_assessment"),label:p||"Quarterly Assessment",column:Na(l)},i="DERIVED";continue}if(_e(d,Ue.initialGrade[0])||_e(d,Ue.quarterlyGrade[0])||_e(d,Ue.remark[0])||_e(d,Ue.additionalRemarks[0])||_e(d,Ue.firstQuarter[0])||_e(d,Ue.secondQuarter[0])||_e(d,Ue.firstSemester[0])||_e(d,Ue.finalGrades[0])||_e(d,Ue.ps[0])||_e(d,Ue.ws[0])||_e(d,Ue.total[0])){i="DERIVED",o.push({key:Br(p||d),label:p||d,column:Na(l)});continue}const h={key:Br(p||d||Na(l)),label:p||d||Na(l),maxScore:ar(m?.displayValue),column:Na(l)};i==="WW"?a.push(h):i==="PT"?r.push(h):i==="DERIVED"&&o.push(h)}return{writtenWorks:a,performanceTasks:r,quarterlyAssessment:n,derived:o}}function yx(t){const s=["SUBMITTED BY","CHECKED BY","VERIFIED BY","RECOMMENDED BY","APPROVED BY"],a=[];return s.forEach(r=>{Tt(t,r).forEach(o=>{const n=Ve(t,o.row,o.col+1),i=String(n?.displayValue||"").trim()||void 0;a.push({role:r,name:i,sourceSheet:t.sheetName,sourceRow:o.row+1})})}),a}function Jo(t,s,a){for(let r=t.startCol;r<=t.endCol;r+=1){const o=It(Ve(t,s,r)?.displayValue||""),n=It(Ve(t,s+1,r)?.displayValue||"");if(a.some(i=>_e(o,i)||_e(n,i)))return r}}function Sx(t,s,a,r){const o={learnerNo:fr(Ve(t,s,r.numberCol)?.displayValue),fullName:String(Ve(t,s,r.nameCol)?.displayValue||"").trim(),sourceRow:s+1},n={};a.writtenWorks.forEach(d=>{const m=d.column?Ya(d.column):-1;if(m<0)return;const p=Ve(t,s,m)?.displayValue;n[d.key]=p??null}),Object.keys(n).length>0&&(o.writtenWorks=n);const i={};if(a.performanceTasks.forEach(d=>{const m=d.column?Ya(d.column):-1;if(m<0)return;const p=Ve(t,s,m)?.displayValue;i[d.key]=p??null}),Object.keys(i).length>0&&(o.performanceTasks=i),a.quarterlyAssessment?.column){const d=Ya(a.quarterlyAssessment.column);o.quarterlyAssessment=Ve(t,s,d)?.displayValue??null}const l=a.derived||[],c={};return l.forEach(d=>{if(!d.column)return;const m=Ya(d.column);if(m<0)return;const p=Ve(t,s,m)?.displayValue??null;c[d.key]=p,_e(d.label,Ue.initialGrade[0])&&(o.initialGrade=p),_e(d.label,Ue.quarterlyGrade[0])&&(o.quarterlyGrade=p),_e(d.label,Ue.firstQuarter[0])&&(o.firstQuarter=p),_e(d.label,Ue.secondQuarter[0])&&(o.secondQuarter=p),_e(d.label,Ue.firstSemester[0])&&(o.firstSemester=p),_e(d.label,Ue.finalGrades[0])&&(o.finalGrades=p),_e(d.label,Ue.remark[0])&&(o.remark=p!==null?String(p):null),_e(d.label,Ue.additionalRemarks[0])&&(o.additionalRemarks=p!==null?String(p):null)}),Object.keys(c).length>0&&(o.totals=c),o}function kx(t){const s=Nx(t),a=[],r=Tt(t,Ue.learnerName[0])[0]||Tt(t,Ue.learnerName[1])[0],o=r?kl(t,r.row,4):t.startRow,n=jx(t,o),i=Jo(t,o,Ue.learnerNo)??t.startCol,l=Jo(t,o,Ue.learnerName)??Math.min(t.endCol,i+1),c=[];let d="UNKNOWN",m=0;for(let S=o+1;S<=t.endRow;S+=1){const k=Ps(t,S),N=kn({rowText:k,hasLearnerNumber:/\b\d{1,2}\b/.test(k),hasLearnerName:/[A-Z]{2,}/.test(k)});if(N==="sex-header"){d=Sn(k)||d;continue}if(N==="signature"||N==="helper")break;if(N==="blank"){if(m+=1,m>=Nl)break;continue}if(N!=="learner")continue;m=0;const v=Sx(t,S,n,{numberCol:i,nameCol:l});if(v.sex=d,!v.fullName&&v.learnerNo===void 0)continue;const g=Fa.filter(I=>_e(k,I));g.length>0&&!v.additionalRemarks&&(v.additionalRemarks=g.join("; ")),!v.fullName&&v.learnerNo!==void 0&&(a.push(`Row ${S+1} has learner number ${v.learnerNo} but empty name.`),v.fullName=`Unnamed Learner ${v.learnerNo}`),c.push(v)}n.writtenWorks.length===0&&n.performanceTasks.length===0&&a.push(`No detailed assessment columns detected in ${t.sheetName}.`);const p=ar(Tt(t,"WRITTEN WORK %")[0]?.value||Tt(t,"WRITTEN WORK")[0]?.value),h=ar(Tt(t,"PERFORMANCE TASKS %")[0]?.value||Tt(t,"PERFORMANCE TASKS")[0]?.value),b=ar(Tt(t,"QUARTERLY ASSESSMENT %")[0]?.value||Tt(t,"QUARTERLY ASSESSMENT")[0]?.value);return{sheetName:t.sheetName,quarter:s,gradingWeights:{writtenWork:p,performanceTasks:h,quarterlyAssessment:b},assessmentColumns:n,learnerGrades:c,signatures:yx(t),warnings:a}}function Cx(t){const s=["SUBMITTED BY","CHECKED BY","VERIFIED BY","RECOMMENDED BY","APPROVED BY"],a=[];return s.forEach(r=>{Tt(t,r).forEach(o=>{a.push({role:r,name:String(Ve(t,o.row,o.col+1)?.displayValue||"").trim()||void 0,sourceSheet:t.sheetName,sourceRow:o.row+1})})}),a}function Ix(t){const s=[];let a=!1;for(let r=t.startRow;r<=t.endRow;r+=1){const o=Ps(t,r);if(!o){if(a&&s.length>0)break;continue}if(_e(o,"WEIGHT OF COMPONENTS")){a=!0;continue}if(!a)continue;const n={sourceRow:r+1,raw:o};for(let i=t.startCol;i<=t.endCol;i+=1){const l=Ve(t,r,i)?.displayValue;l==null||String(l).trim()===""||(n[`c${i}`]=l)}Object.keys(n).length>2&&s.push(n)}return s}function Tx(t){const s=[],a=[],r=[],o=[],n=[];return t.forEach(i=>{Cx(i).forEach(l=>a.push(l)),Ix(i).forEach(l=>r.push({...l,sourceSheet:i.sheetName}));for(let l=i.startRow;l<=i.endRow;l+=1){const c=Ps(i,l);if(c){if(Fa.some(d=>_e(c,d))){o.push(`${i.sheetName}: ${c}`);continue}(_e(c,"HELPER")||_e(c,"LOOK UP")||_e(c,"IMPORTANT")||_e(c,"REFERENCE")||_e(c,"ATTACHMENT"))&&n.push(`${i.sheetName}: ${c}`)}}}),r.length===0&&s.push("No component weight rows were parsed from reference sheets."),{sheetName:t.map(i=>i.sheetName).join(", "),componentWeights:r,attachmentRules:Array.from(new Set(o)),helperNotes:Array.from(new Set(n)),signatures:a,warnings:s}}function _x(t,s,a){const r=new Map,o=n=>{const i=`${It(n.fullName)}|${n.learnerNo||""}|${n.sourceSheet}`,l=r.get(i);if(!l){r.set(i,n);return}const c=Array.from(new Set([...l.statuses||[],...n.statuses||[]]));r.set(i,{...l,...n,remarks:n.remarks||l.remarks,additionalRemarks:n.additionalRemarks||l.additionalRemarks,statuses:c.length>0?c:void 0})};return t.forEach(o),s.forEach(n=>{n.learnerGrades.forEach(i=>{o({learnerNo:i.learnerNo,sex:i.sex,fullName:i.fullName,sourceSheet:n.sheetName,sourceRow:i.sourceRow,remarks:i.remark||void 0,additionalRemarks:i.additionalRemarks||void 0})})}),a.forEach(n=>{n.learnerGrades.forEach(i=>{o({learnerNo:i.learnerNo,sex:i.sex,fullName:i.fullName,sourceSheet:n.sheetName,sourceRow:i.sourceRow,remarks:i.remark||void 0,additionalRemarks:i.additionalRemarks||void 0})})}),Array.from(r.values())}function Ex(t,s,a,r){const o=[...t.signatures,...s.flatMap(i=>i.signatures),...a.flatMap(i=>i.signatures),...r.signatures],n=new Map;return o.forEach(i=>{const l=`${It(i.role)}|${It(i.name||"")}|${i.sourceSheet}`;n.set(l,i)}),Array.from(n.values())}function Rx(t){const s=_x(t.inputData.learners,t.quarterSheets,t.finalSheets);return{format:wl,version:Km,workbookMeta:{fileName:t.workbook.fileName,sheetNames:t.workbook.sheetNames,detectedSheets:{inputData:t.detection.detectedSheets.inputData,firstQuarter:t.detection.detectedSheets.firstQuarter,secondQuarter:t.detection.detectedSheets.secondQuarter,finalSemestral:t.detection.detectedSheets.finalSemestral,helper:t.detection.detectedSheets.helper,lookup:t.detection.detectedSheets.lookup,other:t.detection.detectedSheets.other}},schoolContext:{...t.inputData.schoolContext},learners:s,quarterlyRecords:t.quarterSheets.map(a=>({sheetName:a.sheetName,quarter:a.quarter,gradingWeights:a.gradingWeights,assessmentColumns:a.assessmentColumns,learnerGrades:a.learnerGrades})),finalSemestralRecords:t.finalSheets.map(a=>({sheetName:a.sheetName,learnerGrades:a.learnerGrades})),references:{componentWeights:t.references.componentWeights,attachmentRules:Array.from(new Set([...t.inputData.attachmentRules||[],...t.references.attachmentRules||[]])),helperNotes:Array.from(new Set([...t.inputData.helperNotes||[],...t.references.helperNotes||[]])),signatures:Ex(t.inputData,t.quarterSheets,t.finalSheets,t.references),unclassifiedBlocks:t.unclassifiedBlocks},validation:t.validation,raw:t.workbook.raw}}function Mx(t){return!t||t.length===0?[]:t.map(s=>({s:{r:s.s.r,c:s.s.c},e:{r:s.e.r,c:s.e.c}}))}function Ax(t){const s={ref:t["!ref"],merges:Mx(t["!merges"]),cells:{}};return Object.keys(t).filter(a=>!a.startsWith("!")).forEach(a=>{const r=t[a];!r||!(r.v!==void 0||typeof r.w=="string"&&r.w.trim().length>0||typeof r.f=="string"&&r.f.trim().length>0)||(s.cells[a]={v:r.v,w:r.w,t:r.t,f:r.f})}),s}function Lx(t,s){const a=Ac(s,{type:"array",cellFormula:!0,cellNF:!0,cellText:!0,cellDates:!0,raw:!1}),r={},o={};return a.SheetNames.forEach(n=>{const i=a.Sheets[n];if(!i)return;const l=Ax(i);o[n]=l,r[n]=ix(n,l)}),{fileName:t,sheetNames:a.SheetNames,raw:{sheets:o},matrices:r}}async function zx(t){const s=await t.arrayBuffer();return Lx(t.name,s)}class Dx{state={};markRange(s,a,r){const o=s;this.state[o]||(this.state[o]={mappedAddresses:new Set,mappings:[]});for(let n=a.s.r;n<=a.e.r;n+=1)for(let i=a.s.c;i<=a.e.c;i+=1)this.state[o].mappedAddresses.add(`${n}:${i}`);this.state[o].mappings.push({sheetName:s,range:a,reason:r})}getMappings(){return Object.values(this.state).flatMap(s=>s.mappings)}getMappedRegionCount(){return this.getMappings().length}getUnmappedBlocks(s,a="unclassified"){const r=[];return Object.values(s).forEach(o=>{const n=new Set,i=this.state[o.sheetName]?.mappedAddresses??new Set;for(let l=o.startRow;l<=o.endRow;l+=1)for(let c=o.startCol;c<=o.endCol;c+=1){const d=`${l}:${c}`;if(n.has(d)||i.has(d))continue;const m=Ve(o,l,c);if(!(m&&m.displayValue!==null&&m.displayValue!==void 0&&String(m.displayValue).trim())){n.add(d);continue}const h=this.collectComponent(o,l,c,i,n);h&&r.push({sheetName:o.sheetName,range:lx(h),purposeGuess:a,raw2D:cx(o,h)})}}),r}collectComponent(s,a,r,o,n){const i=[{row:a,col:r}];let l=a,c=a,d=r,m=r,p=!1;for(;i.length>0;){const h=i.shift();if(!h)break;const b=`${h.row}:${h.col}`;if(n.has(b)||o.has(b))continue;n.add(b);const S=Ve(s,h.row,h.col);S&&S.displayValue!==null&&S.displayValue!==void 0&&String(S.displayValue).trim()&&(p=!0,l=Math.min(l,h.row),c=Math.max(c,h.row),d=Math.min(d,h.col),m=Math.max(m,h.col),[{row:h.row-1,col:h.col},{row:h.row+1,col:h.col},{row:h.row,col:h.col-1},{row:h.row,col:h.col+1}].forEach(N=>{N.rows.endRow||N.cols.endCol||i.push(N)}))}return p?{s:{r:l,c:d},e:{r:c,c:m}}:null}}function $x(t){const s=t.detection.detectedSheets,a=[s.inputData?1:0,s.firstQuarter.length,s.secondQuarter.length,s.finalSemestral.length,s.helper.length,s.lookup.length].reduce((r,o)=>r+o,0);return{totalSheets:t.totalSheets,recognizedSheets:a,unclassifiedSheets:s.other.length,mappedCellRegions:t.mappedCellRegions,unmappedCellRegions:t.unmappedCellRegions}}function Fx(t){const s=new Map;t.forEach(r=>{const o=`${r.learnerNo||""}|${r.fullName.trim().toUpperCase()}`;s.has(o)||s.set(o,[]),s.get(o)?.push(r.sourceRow)});const a=[];return s.forEach((r,o)=>{r.length>1&&a.push(`Duplicate learner entry detected for ${o} at rows ${r.join(", ")}.`)}),a}function Ox(t){const s=[];return t.forEach(a=>{a.learnerGrades.forEach(r=>{r.fullName.trim()||s.push(`${a.sheetName} row ${r.sourceRow}: learner name is blank.`);const o=r.writtenWorks&&Object.values(r.writtenWorks).some(i=>i!==null&&i!==""),n=r.performanceTasks&&Object.values(r.performanceTasks).some(i=>i!==null&&i!=="");!o&&!n&&r.quarterlyAssessment==null&&s.push(`${a.sheetName} row ${r.sourceRow}: all grade blocks are empty.`)})}),s}function Px(t){const s=[];return t.forEach(a=>{a.learnerGrades.forEach(r=>{r.fullName.trim()||s.push(`${a.sheetName} row ${r.sourceRow}: learner name is blank.`),r.finalGrades==null&&r.firstSemester==null&&r.firstQuarter==null&&r.secondQuarter==null&&s.push(`${a.sheetName} row ${r.sourceRow}: no semestral/final values detected.`)})}),s}function Bx(t){const s=[],a=[];t.detection.detectedSheets.inputData||a.push("Missing Input Data sheet."),t.quarterSheets.length===0&&a.push("No quarter class record sheets were extracted."),t.finalSheets.length===0&&a.push("No Final Semestral sheet was extracted."),t.detection.missingCriticalAnchors.length>0&&s.push(`Missing critical anchors: ${t.detection.missingCriticalAnchors.join(", ")}.`),Fx(t.inputData.learners).forEach(n=>s.push(n)),Ox(t.quarterSheets).forEach(n=>s.push(n)),Px(t.finalSheets).forEach(n=>s.push(n)),s.push(...t.inputData.warnings),t.quarterSheets.forEach(n=>s.push(...n.warnings)),t.finalSheets.forEach(n=>s.push(...n.warnings)),t.unmappedCellRegions>t.mappedCellRegions&&s.push("A significant portion of workbook regions are unclassified; review diagnostics before confirming import.");const r=t.detection.confidence,o=t.detection.isOfficialFormatLikely&&a.length===0;return r({fullName:i.fullName,learnerNo:i.learnerNo,sex:i.sex,remarks:i.remarks,additionalRemarks:i.additionalRemarks,statuses:i.statuses,sourceSheet:i.sourceSheet,sourceRow:i.sourceRow})),r=t.quarterlyRecords.flatMap(i=>i.learnerGrades.map(l=>({fullName:l.fullName,sourceSheet:i.sheetName,sourceRow:l.sourceRow,quarter:i.quarter,firstQuarter:l.firstQuarter,secondQuarter:l.secondQuarter,firstSemester:l.firstSemester,finalGrades:l.finalGrades,quarterlyGrade:l.quarterlyGrade,initialGrade:l.initialGrade,remark:l.remark,additionalRemarks:l.additionalRemarks}))),o=t.finalSemestralRecords.flatMap(i=>i.learnerGrades.map(l=>({fullName:l.fullName,sourceSheet:i.sheetName,sourceRow:l.sourceRow,firstQuarter:l.firstQuarter,secondQuarter:l.secondQuarter,firstSemester:l.firstSemester,finalGrades:l.finalGrades,remark:l.remark,additionalRemarks:l.additionalRemarks}))),n=[...t.learners,...t.quarterlyRecords.flatMap(i=>i.learnerGrades.map(l=>({learnerNo:l.learnerNo,sex:l.sex,fullName:l.fullName,sourceSheet:i.sheetName,sourceRow:l.sourceRow,remarks:l.remark||void 0,additionalRemarks:l.additionalRemarks||void 0})))].map(i=>({fullName:i.fullName,remark:i.remarks||null,additionalRemarks:i.additionalRemarks||null,statuses:"statuses"in i?i.statuses:void 0,sourceSheet:i.sourceSheet,sourceRow:i.sourceRow}));return{classEntity:s,studentEntities:a,gradeEntities:[...r,...o],remarksEntities:n}}const Zo=1500;function ei(t){return t?Object.values(t.matrices).reduce((s,a)=>s+a.rowCount*a.colCount,0):0}function ti(t){const s=`[shs-import] parse ${t.stage} file=${t.fileName} duration=${t.durationMs}ms sheets=${t.sheetCount} matrixCells=${t.matrixCellCount}`;if(t.stage==="failed"){console.error(`${s}${t.errorMessage?` error=${t.errorMessage}`:""}`);return}if(t.durationMs>=Zo){console.warn(`${s} slow=true threshold=${Zo}ms`);return}}function Qs(t,s){t?.onProgress?.(s)}function Ux(t,s){return Array.from(new Set(t.filter(a=>Number.isFinite(a)).map(a=>Math.max(s.startRow,Math.min(s.endRow,Math.trunc(a))))))}function ja(t,s,a,r){Ux(a,s).forEach(o=>{t.markRange(s.sheetName,{s:{r:o,c:s.startCol},e:{r:o,c:s.endCol}},r)})}async function Gx(t,s){const a=s?.confidenceThreshold??Ym,r=Date.now();let o=null;try{if(Qs(s,{stage:"reading",message:"Reading workbook structure and raw sheets..."}),o=await zx(t),!o)throw new Error("Workbook read returned null");Qs(s,{stage:"detecting-format",message:"Detecting DepEd SHS workbook format..."});const n=px(o);Qs(s,{stage:"extracting",message:"Extracting metadata, learners, grades, and references..."});const i=n.detectedSheets.inputData||o.sheetNames[0],l=o.matrices[i],c=l?wx(l):{sheetName:i,schoolContext:{},learners:[],signatures:[],attachmentRules:[],helperNotes:[],warnings:["Input data sheet was not available in matrix map."]},m=[...n.detectedSheets.firstQuarter||[],...n.detectedSheets.secondQuarter||[]].map(I=>o.matrices[I]).filter(I=>!!I).map(I=>kx(I)),p=(n.detectedSheets.finalSemestral||[]).map(I=>o.matrices[I]).filter(I=>!!I).map(I=>fx(I)),h=[...n.detectedSheets.helper||[],...n.detectedSheets.lookup||[]].map(I=>o.matrices[I]).filter(I=>!!I),b=Tx(h),S=new Dx;n.anchorMatches.forEach(I=>{const z=o.matrices[I.sheetName];z&&ja(S,z,[I.row],`Anchor match: ${I.anchor}`)}),[c.sheetName].forEach(I=>{const z=o.matrices[I];if(!z)return;const R=Array.from({length:Math.min(14,z.rowCount)},(C,w)=>z.startRow+w),W=c.learners.map(C=>C.sourceRow-1),f=c.signatures.map(C=>C.sourceRow).filter(C=>typeof C=="number").map(C=>C-1);ja(S,z,[...R,...W,...f],"Input Data parsed rows")}),m.forEach(I=>{const z=o.matrices[I.sheetName];if(!z)return;const R=I.learnerGrades.map(C=>C.sourceRow-1),W=I.signatures.map(C=>C.sourceRow).filter(C=>typeof C=="number").map(C=>C-1),f=R.length>0?Math.max(z.startRow,Math.min(...R)-2):z.startRow;ja(S,z,[f,f+1,...R,...W],"Quarter sheet parsed rows")}),p.forEach(I=>{const z=o.matrices[I.sheetName];if(!z)return;const R=I.learnerGrades.map(C=>C.sourceRow-1),W=I.signatures.map(C=>C.sourceRow).filter(C=>typeof C=="number").map(C=>C-1),f=R.length>0?Math.max(z.startRow,Math.min(...R)-2):z.startRow;ja(S,z,[f,f+1,...R,...W],"Final semestral parsed rows")}),h.forEach(I=>{const z=b.componentWeights.filter(f=>f.sourceSheet===I.sheetName).map(f=>f.sourceRow).filter(f=>typeof f=="number").map(f=>f-1),R=b.signatures?.filter(f=>f.sourceSheet===I.sheetName).map(f=>f.sourceRow).filter(f=>typeof f=="number").map(f=>f-1)||[],W=z.length===0&&R.length===0?[I.startRow,I.startRow+1,I.startRow+2]:[];ja(S,I,[...z,...R,...W],"Reference/helper parsed rows")});const k=S.getUnmappedBlocks(o.matrices);Qs(s,{stage:"validating",message:"Validating completeness and structural integrity..."});const N=Bx({detection:n,inputData:c,quarterSheets:m,finalSheets:p,mappedCellRegions:S.getMappedRegionCount(),unmappedCellRegions:k.length,totalSheets:o.sheetNames.length});Qs(s,{stage:"normalizing",message:"Normalizing parsed workbook and creating entity mapping..."});const v=Rx({workbook:o,detection:n,inputData:c,quarterSheets:m,finalSheets:p,references:b,validation:N,unclassifiedBlocks:k});v.validation.confidenceD.trim().toLowerCase().replace(/\s+/g," "),be=D=>{if(typeof D=="number"&&Number.isFinite(D))return D;const j=Number(String(D??"").replace(/[^0-9.-]+/g,""));return Number.isFinite(j)?j:null},Ie=(D,j)=>{const _=Number.isFinite(D)?D:j;return Math.max(0,Math.min(100,_))},de=D=>{const j=String(D??"");return/[",\n]/.test(j)?`"${j.replace(/"/g,'""')}"`:j},fe=(D,j)=>{const _=new Map,T=["quarterlyGrade","finalGrades","firstSemester","firstQuarter","secondQuarter","initialGrade"];D.mapping.gradeEntities.forEach($e=>{const Ge=ne($e.fullName||"");if(!Ge)return;const ft=T.map(dt=>be($e[dt])).filter(dt=>dt!==null);if(ft.length===0)return;const Nt=_.get(Ge)||[];_.set(Ge,Nt.concat(ft))});const Q=D.mapping.studentEntities||[];if(Q.length===0)return null;const ue=(D.imported.schoolContext.semester||D.imported.schoolContext.schoolYear||"First Semester").trim(),ce=(D.imported.schoolContext.subjectName||"Class Record Import").trim(),ae=(t||s||"import").replace(/[^a-zA-Z0-9]+/g,"").toUpperCase().slice(0,12)||"IMPORT",Ne=[["name","lrn","email","engagementScore","avgQuizScore","attendance","assignmentCompletion","term","assessmentName"].join(",")];if(Q.forEach(($e,Ge)=>{const ft=ne($e.fullName||""),Nt=_.get(ft)||[],dt=Nt.length>0?Nt.reduce((vs,os)=>vs+os,0)/Nt.length:75,jt=Ie(dt,75),Lt=Ie(jt+5,85),rs=Ie(jt*.7+Lt*.3,80),Ts=Ie(Lt*.6+jt*.4,82),bs=$e.learnerNo||Ge+1,Bs=`IMP-${ae}-${String(bs).padStart(4,"0")}`,ns=$e.fullName||`Learner ${Ge+1}`;Ne.push([de(ns),de(Bs),de(""),de(Number(rs.toFixed(1))),de(Number(jt.toFixed(1))),de(Number(Lt.toFixed(1))),de(Number(Ts.toFixed(1))),de(ue),de(ce)].join(","))}),Ne.length<=1)return null;const Je=j.replace(/\.(xlsx|xls)$/i,"");return new File([Ne.join(` +`)],`${Je}-normalized.csv`,{type:"text/csv"})},H=async D=>{C(!0),y(""),J(null);let j=D;if(/\.(xlsx|xls)$/i.test(D.name))try{const _=await Gx(D,{confidenceThreshold:on});g(_);const T=fe(_,D.name);T&&(j=T)}catch{g(null)}else g(null);try{const _=await xt.uploadClassRecords(j,{classSectionId:t,className:s,datasetIntent:"synthetic_student_records"}),T=_.students.length,ue=((ce,ae,Ce,Ne)=>({classSectionId:ce.classSectionId||ae||"imported_class",className:ce.className||Ce||"Imported Class",classMetadata:ce.classMetadata||Ne}))(_,t,s,a);T>0&&l?.({students:_.students,classSectionId:ue.classSectionId,className:ue.className,classMetadata:ue.classMetadata}),_.success?(ie.success(`Successfully imported ${T} student records.`),J({datasetIntent:_.datasetIntent,summary:_.interpretationSummary,columns:_.columnInterpretations?.map(ce=>({columnName:ce.columnName,mappedField:ce.mappedField,usagePolicy:ce.usagePolicy,confidenceBand:ce.confidenceBand,domainSignals:ce.domainSignals}))||[]}),c?.()):ie.error("Import completed but no usable student rows were detected. Check required columns and retry.")}catch(_){ie.error(_ instanceof Error?_.message:"Upload failed")}finally{C(!1)}},ee=async D=>{$(!0);try{const j=await xt.uploadCourseMaterials(D,{classSectionId:t,className:s});if(j.success){const _=j.topics?.length??0;ie.success(`Course material imported (${_} topics extracted).`),c?.()}}catch(j){ie.error(j instanceof Error?j.message:"Course material upload failed")}finally{$(!1)}},[oe,Re]=u.useState(r),[Fe,Pe]=u.useState(!1),[G,te]=u.useState(null),E=u.useMemo(()=>{let D=oe;if(o.length>0){const j=new Set(o.map(_=>js(_.classSectionId||_.id)));D=D.filter(_=>j.has(js(_.classSectionId))||j.has(js(_.classroomId)))}else return[];return t&&(D=D.filter(j=>js(j.classSectionId)===js(t)||js(j.classroomId)===js(t))),D},[oe,t,o]);u.useEffect(()=>{Re(r),V(Object.fromEntries(r.map(D=>[Ka(D),{grade:D.grade||"",section:D.section||""}])))},[r]);const[Y,V]=u.useState({}),pe=async()=>{Pe(!0);let D=0,j=0;try{for(const T of E){const Q=Y[Ka(T)],ue=Q?.grade||T.grade,ce=Q?.section||T.section;try{n&&(ue!==T.grade||ce!==T.section)&&(await yr(T.id,ue,ce,n,new Date().getFullYear().toString(),i),await il(T.id,ue,ce),D++)}catch(ae){console.warn(`[EditRecords] Failed to save ${T.name}:`,ae),j++}}const _=oe.map(T=>{const Q=Y[Ka(T)];if(!Q)return T;const ue=Ct({metadata:T.classMetadata,classSectionId:T.classSectionId,className:[Q.grade,Q.section].filter(Boolean).join(" - "),grade:Q.grade,section:Q.section});return{...T,grade:Q.grade,section:Q.section,className:ue.className||[Q.grade,Q.section].filter(Boolean).join(" - "),classSectionId:ue.classSectionId||T.classSectionId,classMetadata:ue}});Re(_),m?.(_),j>0?ie.warning(`Saved ${D} records, ${j} failed`):ie.success("Records saved successfully")}catch{ie.error("Failed to save changes")}finally{Pe(!1)}};return e.jsx("div",{className:"h-full overflow-y-auto w-full block",children:e.jsxs("div",{className:"w-full p-[24px] xl:p-[32px] space-y-[24px]",children:[k==="main"&&e.jsxs("div",{className:"block space-y-[24px]",children:[e.jsxs("div",{className:"bg-white/80 backdrop-blur-[12px] rounded-[16px] p-4 shadow-[0_1px_4px_rgba(0,0,0,0.04)] border border-slate-200 flex flex-col md:flex-row items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-indigo-50 flex items-center justify-center border border-indigo-100/50",children:e.jsx(lr,{className:"w-5 h-5 text-indigo-500"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-[14px] font-bold text-[#1e293b]",children:"Upload Context"}),e.jsx("p",{className:"text-[12px] text-[#64748b]",children:"Select where the imported data should be applied"})]})]}),e.jsxs("div",{className:"relative w-full md:w-[300px]",children:[e.jsxs("select",{className:"appearance-none bg-[#f8fafc] border border-[#e2e8f0] text-[#1e293b] font-bold text-[13px] rounded-lg pl-4 pr-10 py-2.5 outline-none focus:border-[#4f46e5] focus:ring-2 focus:ring-[#4f46e5]/20 shadow-[0_1px_4px_rgba(0,0,0,0.02)] cursor-pointer w-full transition-colors",value:s||t||"All Classes",onChange:()=>{},children:[e.jsx("option",{value:"All Classes",children:"All Classes"}),o.map(D=>e.jsx("option",{value:D.classSectionId||D.id,children:D.name},D.id))]}),e.jsx($t,{className:"w-4 h-4 text-[#64748b] absolute right-3 top-1/2 -translate-y-1/2 pointer-events-none"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-[24px]",children:[e.jsxs("div",{onDragOver:D=>{D.preventDefault(),z(!0)},onDragLeave:()=>z(!1),onDrop:D=>{D.preventDefault(),z(!1);const j=D.dataTransfer.files[0];j&&H(j)},onClick:()=>re.current?.click(),className:`border-2 border-dashed transition-all rounded-[24px] p-8 flex flex-col items-center justify-center text-center cursor-pointer group shadow-[0_4px_20px_rgba(0,0,0,0.02)] relative overflow-hidden h-[280px] ${I?"border-[#1FA7E1] bg-[#1FA7E1]/10":"border-[#1FA7E1]/30 hover:border-[#1FA7E1] bg-white hover:bg-[#1FA7E1]/5"}`,children:[e.jsx("input",{ref:re,type:"file",accept:".csv,.xlsx,.xls",onChange:D=>{const j=D.target.files?.[0];j&&H(j)},className:"hidden"}),e.jsx("div",{className:"w-16 h-16 rounded-full bg-[#1FA7E1]/10 flex items-center justify-center mb-4 group-hover:scale-110 transition-transform duration-300 shadow-sm border border-[#1FA7E1]/20",children:f?e.jsx("span",{className:"animate-spin text-[#1FA7E1]",children:"..."}):e.jsx(ld,{className:"w-8 h-8 text-[#1FA7E1]"})}),e.jsx("h3",{className:"text-[18px] font-bold text-[#1e293b] mb-2",children:f?"Uploading...":"Class Records"}),e.jsx("p",{className:"text-[13px] text-[#64748b] max-w-sm mb-6",children:"Upload student grades, attendance logs, and quiz scores to power predictive analytics."}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("span",{className:"px-3 py-1 bg-slate-100 text-slate-500 text-[11px] font-semibold rounded-full border border-slate-200",children:".csv"}),e.jsx("span",{className:"px-3 py-1 bg-slate-100 text-slate-500 text-[11px] font-semibold rounded-full border border-slate-200",children:".xlsx"})]})]}),e.jsxs("div",{onDragOver:D=>{D.preventDefault(),W(!0)},onDragLeave:()=>W(!1),onDrop:D=>{D.preventDefault(),W(!1);const j=D.dataTransfer.files[0];j&&ee(j)},onClick:()=>le.current?.click(),className:`border-2 border-dashed transition-all rounded-[24px] p-8 flex flex-col items-center justify-center text-center cursor-pointer group shadow-[0_4px_20px_rgba(0,0,0,0.02)] relative overflow-hidden h-[280px] ${R?"border-[#9956DE] bg-[#9956DE]/10":"border-[#9956DE]/30 hover:border-[#9956DE] bg-white hover:bg-[#9956DE]/5"}`,children:[e.jsx("input",{ref:le,type:"file",accept:".pdf,.docx,.txt",onChange:D=>{const j=D.target.files?.[0];j&&ee(j)},className:"hidden"}),e.jsx("div",{className:"w-16 h-16 rounded-full bg-[#9956DE]/10 flex items-center justify-center mb-4 group-hover:scale-110 transition-transform duration-300 shadow-sm border border-[#9956DE]/20",children:w?e.jsx("span",{className:"animate-spin text-[#9956DE]",children:"..."}):e.jsx(Rs,{className:"w-8 h-8 text-[#9956DE]"})}),e.jsx("h3",{className:"text-[18px] font-bold text-[#1e293b] mb-2",children:w?"Uploading...":"Course Materials"}),e.jsx("p",{className:"text-[13px] text-[#64748b] max-w-sm mb-6",children:"Upload syllabus, lesson plans, and curriculum docs to ground AI lesson generation."}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("span",{className:"px-3 py-1 bg-slate-100 text-slate-500 text-[11px] font-semibold rounded-full border border-slate-200",children:".pdf"}),e.jsx("span",{className:"px-3 py-1 bg-slate-100 text-slate-500 text-[11px] font-semibold rounded-full border border-slate-200",children:".docx"}),e.jsx("span",{className:"px-3 py-1 bg-slate-100 text-slate-500 text-[11px] font-semibold rounded-full border border-slate-200",children:".txt"})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-[16px]",children:[e.jsxs("div",{className:"relative overflow-hidden bg-gradient-to-br from-[#0ea5e9] to-[#0284c7] rounded-[16px] p-[20px] shadow-[0_4px_12px_rgba(14,165,233,0.2)] flex flex-col text-white group transition-all duration-300 hover:-translate-y-1 hover:shadow-lg hover:shadow-sky-500/30",children:[e.jsx("div",{className:"absolute -right-8 -bottom-8 w-24 h-24 bg-white/10 rounded-full"}),e.jsx("div",{className:"w-10 h-10 rounded-full bg-white/10 border border-white/20 flex items-center justify-center shrink-0 mb-3 relative z-10 transition-transform group-hover:scale-110",children:e.jsx(od,{className:"w-5 h-5 text-white"})}),e.jsx("h4",{className:"font-bold text-[14px] mb-1.5 relative z-10",children:"Smart Parsing"}),e.jsx("p",{className:"text-[12px] text-white/90 leading-relaxed relative z-10",children:"AI automatically understands varied spreadsheet formats and maps column names securely."})]}),e.jsxs("div",{className:"relative overflow-hidden bg-gradient-to-br from-[#f97316] to-[#ea580c] rounded-[16px] p-[20px] shadow-[0_4px_12px_rgba(249,115,22,0.2)] flex flex-col text-white group transition-all duration-300 hover:-translate-y-1 hover:shadow-lg hover:shadow-orange-500/30",children:[e.jsx("div",{className:"absolute -right-8 -bottom-8 w-24 h-24 bg-white/10 rounded-full"}),e.jsx("div",{className:"w-10 h-10 rounded-full bg-white/10 border border-white/20 flex items-center justify-center shrink-0 mb-3 relative z-10 transition-transform group-hover:scale-110",children:e.jsx(Kr,{className:"w-5 h-5 text-white"})}),e.jsx("h4",{className:"font-bold text-[14px] mb-1.5 relative z-10",children:"Risk Prediction"}),e.jsx("p",{className:"text-[12px] text-white/90 leading-relaxed relative z-10",children:"Analyzes historical performance patterns across your data to predict at-risk students."})]}),e.jsxs("div",{className:"relative overflow-hidden bg-gradient-to-br from-[#a855f7] to-[#9333ea] rounded-[16px] p-[20px] shadow-[0_4px_12px_rgba(168,85,247,0.2)] flex flex-col text-white group transition-all duration-300 hover:-translate-y-1 hover:shadow-lg hover:shadow-purple-500/30",children:[e.jsx("div",{className:"absolute -right-8 -bottom-8 w-24 h-24 bg-white/10 rounded-full"}),e.jsx("div",{className:"w-10 h-10 rounded-full bg-white/10 border border-white/20 flex items-center justify-center shrink-0 mb-3 relative z-10 transition-transform group-hover:scale-110",children:e.jsx(ps,{className:"w-5 h-5 text-white"})}),e.jsx("h4",{className:"font-bold text-[14px] mb-1.5 relative z-10",children:"Contextual AI"}),e.jsx("p",{className:"text-[12px] text-white/90 leading-relaxed relative z-10",children:"Maps curriculum topics to generate highly personalized remedial lesson paths."})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-[24px]",children:[e.jsxs("div",{className:"bg-white/80 backdrop-blur-[12px] rounded-[24px] p-[24px] shadow-[0_1px_4px_rgba(0,0,0,0.02)] border border-white flex flex-col justify-between h-full",children:[e.jsx("h2",{className:"text-[16px] font-semibold text-[#1e293b] mb-4",children:"Data Health"}),e.jsxs("div",{className:"flex-1 bg-emerald-50/50 border border-emerald-100 rounded-[16px] p-6 flex flex-col items-center justify-center text-center transition-all duration-300 hover:bg-emerald-50 hover:shadow-md hover:border-emerald-200",children:[e.jsx("div",{className:"w-12 h-12 rounded-full bg-emerald-100 flex items-center justify-center mb-3 text-emerald-600 transition-transform duration-300 hover:scale-110 hover:-translate-y-1",children:e.jsx(ya,{className:"w-6 h-6"})}),e.jsx("h3",{className:"text-emerald-700 font-bold text-[15px] mb-1",children:"All Records Synced"}),e.jsx("p",{className:"text-emerald-600/80 text-[12px] max-w-[200px]",children:"AI parsing completed successfully with no anomalies detected."})]}),e.jsxs("div",{className:"flex flex-col gap-2 mt-4",children:[e.jsxs("button",{onClick:()=>N("edit-records"),className:"w-full flex items-center justify-center gap-2 bg-[#1e293b] hover:bg-black text-white text-[13px] font-semibold rounded-full px-4 py-3 shadow-[0_1px_4px_rgba(0,0,0,0.04)] transition-transform hover:scale-[1.02]",children:[e.jsx(sd,{className:"w-4 h-4"})," Edit Class Records"]}),e.jsx("button",{onClick:()=>N("mapping-logs"),className:"w-full flex items-center justify-center gap-2 bg-white text-[#475569] border border-slate-300 hover:bg-slate-50 text-[13px] font-semibold rounded-full px-4 py-3 shadow-[0_1px_4px_rgba(0,0,0,0.04)] transition-colors",children:"View Mapping Logs"})]})]}),e.jsxs("div",{className:"bg-white/80 backdrop-blur-[12px] rounded-[24px] p-[24px] shadow-[0_1px_4px_rgba(0,0,0,0.02)] border border-white flex flex-col h-full",children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsx("h2",{className:"text-[16px] font-semibold text-[#1e293b]",children:"Recent Uploads"}),e.jsx("button",{onClick:()=>N("mapping-logs"),className:"text-[13px] font-semibold text-[#4f46e5] hover:text-[#3730a3] transition-colors",children:"View All"})]}),e.jsxs("div",{className:"flex-1 space-y-[12px] overflow-y-auto no-scrollbar flex flex-col justify-center items-center h-[120px]",children:[e.jsx("div",{className:"w-12 h-12 rounded-full bg-slate-50 flex items-center justify-center mb-2 border border-slate-100",children:e.jsx(Yc,{className:"w-5 h-5 text-slate-300"})}),e.jsx("p",{className:"text-[13px] font-medium text-slate-500",children:"There are no recent uploads yet."})]})]})]})]}),k==="mapping-logs"&&e.jsxs("div",{className:"space-y-[16px]",children:[e.jsx("div",{className:"shrink-0 mb-2",children:e.jsxs("button",{onClick:()=>N("main"),className:"flex items-center gap-2 text-[13px] font-semibold text-[#4f46e5] hover:text-[#3730a3] transition-colors w-max bg-white px-[18px] py-2 rounded-full shadow-sm border border-slate-200",children:[e.jsx(cr,{className:"w-4 h-4"})," Back to Uploads"]})}),e.jsxs("div",{className:"bg-white rounded-[18px] border border-[#f1f5f9] overflow-hidden shadow-sm",children:[e.jsx("div",{className:"p-5 border-b border-[#f1f5f9] bg-slate-50 flex justify-between items-center",children:e.jsx("h2",{className:"text-[15px] font-semibold text-[#1e293b]",children:"Latest Import Mapping"})}),e.jsx("div",{className:"p-5",children:q?e.jsx("div",{className:"space-y-3",children:q.columns.map((D,j)=>e.jsxs("div",{className:"flex justify-between p-3 border rounded bg-slate-50",children:[e.jsx("span",{className:"font-semibold text-sm",children:D.columnName}),e.jsx("span",{className:"text-sm text-indigo-600",children:D.mappedField||"Unmapped"})]},j))}):e.jsx("p",{className:"text-slate-500 text-sm",children:"No recent mapping logs to display."})})]})]}),k==="edit-records"&&e.jsxs("div",{className:"space-y-[16px] h-full flex flex-col",children:[e.jsx("div",{className:"shrink-0 mb-2",children:e.jsxs("button",{onClick:()=>N("main"),className:"flex items-center gap-2 text-[13px] font-semibold text-[#4f46e5] hover:text-[#3730a3] transition-colors w-max bg-white px-[18px] py-2 rounded-full shadow-sm border border-slate-200",children:[e.jsx(cr,{className:"w-4 h-4"})," Back to Uploads"]})}),e.jsxs("div",{className:"bg-white rounded-[18px] border border-slate-200 shadow-sm overflow-hidden flex flex-col flex-1",children:[e.jsxs("div",{className:"p-5 border-b border-slate-200 flex justify-between items-center bg-white",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-[18px] font-bold text-[#1e293b]",children:"Edit Class Records"}),e.jsx("p",{className:"text-[13px] text-[#64748b]",children:"Review and modify student data manually"})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx("button",{onClick:()=>N("main"),className:"px-5 py-2 rounded-full border border-slate-300 text-slate-700 font-semibold text-[13px] hover:bg-slate-50",children:"Cancel"}),e.jsx("button",{onClick:pe,disabled:Fe,className:"px-5 py-2 rounded-full bg-emerald-500 text-white font-semibold text-[13px] hover:bg-emerald-600 flex items-center gap-2 disabled:opacity-50",children:Fe?"Saving...":e.jsxs(e.Fragment,{children:[e.jsx(Ni,{className:"w-4 h-4"})," Save Changes"]})})]})]}),e.jsxs("div",{className:"px-5 py-3 border-b border-slate-200 flex justify-between items-center bg-slate-50/50 shrink-0 text-slate-500 text-[13px]",children:[e.jsxs("span",{className:"flex items-center gap-2 font-medium",children:[e.jsx(na,{className:"w-4 h-4"})," Click on any field to edit"]}),e.jsxs("span",{children:["Showing ",E.length," records"]})]}),e.jsx("div",{className:"overflow-auto flex-1 table-scrollbar bg-white relative",children:e.jsxs("div",{className:"min-w-[1100px] w-full flex flex-col min-h-full",children:[e.jsxs("div",{className:"flex items-center w-full bg-slate-100/90 border-b border-slate-200 text-[12px] font-semibold text-slate-500 tracking-wide sticky top-0 z-20 shadow-[0_1px_2px_rgba(0,0,0,0.02)] h-12",children:[e.jsx("div",{className:"flex-[1.5] min-w-[240px] px-6 sticky left-0 z-30 bg-slate-100/90 backdrop-blur-sm border-r border-slate-200 h-full flex items-center shadow-[2px_0_4px_rgba(0,0,0,0.02)]",children:"Student Name"}),e.jsx("div",{className:"w-[100px] shrink-0 px-4 h-full flex items-center justify-center",children:"LRN"}),e.jsx("div",{className:"w-[140px] shrink-0 px-4 h-full flex items-center justify-center",children:"Grade"}),e.jsx("div",{className:"w-[140px] shrink-0 px-4 h-full flex items-center justify-center",children:"Section"}),e.jsx("div",{className:"w-[100px] shrink-0 px-4 h-full flex items-center justify-center",children:"Avg Score"}),e.jsx("div",{className:"w-[120px] shrink-0 px-4 h-full flex items-center justify-center",children:"Risk Level"}),e.jsx("div",{className:"flex-1 min-w-[180px] px-4 h-full flex items-center justify-center",children:"Weakest Topic"}),e.jsx("div",{className:"w-[80px] shrink-0 px-4 h-full flex items-center justify-center border-r border-transparent",children:"Action"})]}),e.jsx("div",{className:"flex flex-col w-full pb-4",children:E.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 px-6 text-center",children:[e.jsx("div",{className:"w-16 h-16 rounded-full bg-slate-100 flex items-center justify-center mb-4",children:e.jsx(na,{className:"w-7 h-7 text-slate-400"})}),e.jsx("h3",{className:"text-[16px] font-bold text-slate-700 mb-2",children:"No managed classes found"}),e.jsx("p",{className:"text-[13px] text-slate-500 max-w-sm",children:"You don't currently manage any classes. Ask your administrator to assign you as a section manager, or create a new class from the Dashboard."})]}):E.map((D,j)=>{const _=Ka(D),T=D.name.split(" "),Q=T.length>1?`${T[0][0]}${T[T.length-1][0]}`.toUpperCase():D.name.substring(0,2).toUpperCase(),ue=["bg-[#be185d]","bg-[#3b82f6]","bg-[#f43f5e]","bg-[#2563eb]","bg-[#059669]","bg-[#d946ef]"],ce=ue[j%ue.length],ae=(D.avgScore??0)>=75?"text-emerald-500":(D.avgScore??0)>=60?"text-orange-500":"text-rose-500";let Ce="bg-slate-50 text-slate-600 border-slate-200";const Ne=(D.riskLevel||"").toLowerCase();return Ne==="low"?Ce="bg-emerald-50 text-emerald-600 border-emerald-200":Ne==="high"?Ce="bg-rose-50 text-rose-600 border-rose-200":Ne==="medium"&&(Ce="bg-orange-50 text-orange-600 border-orange-200"),e.jsxs("div",{className:"flex items-center w-full border-b border-slate-100 hover:bg-slate-50 transition-colors group min-h-[64px]",children:[e.jsxs("div",{className:"flex-[1.5] min-w-[240px] px-6 sticky left-0 z-10 bg-white group-hover:bg-slate-50 border-r border-slate-100 h-full flex items-center gap-4 shadow-[2px_0_4px_rgba(0,0,0,0.01)]",children:[e.jsx("div",{className:`w-8 h-8 rounded-full ${ce} text-white flex items-center justify-center font-bold text-[12px] shrink-0`,children:Q}),e.jsx("span",{className:"font-semibold text-slate-800 text-[14px] truncate",children:D.name})]}),e.jsx("div",{className:"w-[100px] shrink-0 px-4 flex justify-center text-[13px] text-slate-500",children:D.lrn||"—"}),e.jsx("div",{className:"w-[140px] shrink-0 px-4 flex justify-center",children:e.jsx("input",{type:"text",value:Y[_]?.grade||D.grade||"",onChange:Je=>V($e=>({...$e,[_]:{...$e[_],grade:Je.target.value}})),readOnly:G!==_,className:`outline-none px-4 py-1.5 rounded-full text-[13px] font-medium text-slate-600 w-full transition-all text-center ${G===_?"bg-white border border-purple-500 ring-2 ring-purple-500/20":"bg-slate-100 border border-transparent cursor-default"}`})}),e.jsx("div",{className:"w-[140px] shrink-0 px-4 flex justify-center",children:e.jsx("input",{type:"text",value:Y[_]?.section||D.section||"",onChange:Je=>V($e=>({...$e,[_]:{...$e[_],section:Je.target.value}})),readOnly:G!==_,className:`outline-none px-4 py-1.5 rounded-full text-[13px] font-medium text-slate-600 w-full transition-all text-center ${G===_?"bg-white border border-purple-500 ring-2 ring-purple-500/20":"bg-slate-100 border border-transparent cursor-default"}`})}),e.jsx("div",{className:"w-[100px] shrink-0 px-4 flex justify-center",children:e.jsxs("span",{className:`${ae} font-bold text-[14px]`,children:[D.avgScore,"%"]})}),e.jsx("div",{className:"w-[120px] shrink-0 px-4 flex justify-center",children:e.jsx("span",{className:`px-3 py-1 text-[10px] font-bold rounded uppercase border ${Ce}`,children:D.riskLevel||"Unknown"})}),e.jsx("div",{className:"flex-1 min-w-[180px] px-4 flex justify-center text-[13px] text-slate-600 truncate",children:D.weakestTopic||"Foundational Skills"}),e.jsx("div",{className:"w-[80px] shrink-0 px-4 flex justify-center border-r border-transparent",children:e.jsx("button",{onClick:()=>te(G===_?null:_),className:`w-8 h-8 rounded-full flex items-center justify-center transition-colors ${G===_?"bg-purple-100 text-purple-600":"hover:bg-slate-200 text-slate-400"}`,children:e.jsx(ki,{className:"w-4 h-4"})})})]},_)})})]})})]})]})]})})}const Vx=[{value:"available",label:"Available",icon:e.jsx(La,{size:14}),color:"text-emerald-600"},{value:"teacher_uploaded",label:"Teacher Material",icon:e.jsx(Wr,{size:14}),color:"text-blue-600"},{value:"coming_soon",label:"Coming Soon",icon:e.jsx(As,{size:14}),color:"text-amber-600"},{value:"unavailable",label:"Unavailable",icon:e.jsx(wc,{size:14}),color:"text-slate-400"}],Wx=({teacherId:t})=>{const[s,a]=u.useState(""),[r,o]=u.useState("teacher_uploaded"),[n,i]=u.useState(!1),[l,c]=u.useState(null),d=async()=>{if(!s){ie.error("Select a module first.");return}i(!0);try{let m;if(l&&r==="teacher_uploaded"){const p=zc(Ul,`teacher_modules/${t}/${s}/${l.name}`);await Dc(p,l),m=await $c(p)}await Lc(s,r,t,m),ie.success(`Module status updated to "${r}".`),c(null)}catch(m){ie.error(m.message||"Failed to update module status.")}finally{i(!1)}};return e.jsxs("div",{className:"rounded-2xl border border-slate-200 bg-white p-5 space-y-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-slate-800",children:"Module Availability Control"}),e.jsx("p",{className:"text-xs text-slate-500 mt-0.5",children:"Set module status or upload alternative PDF when DepEd content is unavailable."})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold text-slate-600 mb-1 block",children:"Module"}),e.jsxs("select",{value:s,onChange:m=>a(m.target.value),className:"w-full rounded-lg border border-slate-200 px-3 py-2 text-sm",children:[e.jsx("option",{value:"",children:"Select module..."}),Hl.map(m=>e.jsxs("option",{value:m.id,children:[m.moduleTitle," (",m.quarter,")"]},m.id))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold text-slate-600 mb-1 block",children:"Status"}),e.jsx("select",{value:r,onChange:m=>o(m.target.value),className:"w-full rounded-lg border border-slate-200 px-3 py-2 text-sm",children:Vx.map(m=>e.jsx("option",{value:m.value,children:m.label},m.value))})]})]}),r==="teacher_uploaded"&&e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold text-slate-600 mb-1 block",children:"Upload Alternative PDF (optional)"}),e.jsx("input",{type:"file",accept:".pdf",onChange:m=>c(m.target.files?.[0]||null),className:"text-sm text-slate-600"})]}),e.jsx("button",{type:"button",onClick:d,disabled:!s||n,className:"px-4 py-2 rounded-lg bg-indigo-600 hover:bg-indigo-700 text-white text-sm font-bold disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:n?"Updating...":"Update Status"})]})},Xa="ABCDEFGHJKMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz23456789",si="school.mathpulse.local";function ai(t=10){const s=typeof globalThis<"u"&&typeof globalThis.crypto<"u"?globalThis.crypto:void 0;if(s&&typeof s.getRandomValues=="function"){const r=new Uint32Array(t);s.getRandomValues(r);let o="";for(let n=0;n{const[l,c]=u.useState(""),[d,m]=u.useState(""),[p,h]=u.useState(!1),[b,S]=u.useState(null),[k,N]=u.useState(null),[v,g]=u.useState(!1);u.useEffect(()=>{t&&(S(null),g(!1),h(!1),N(null),c((a?.email||qx(a)).trim()),m(ai()))},[t,a]);const I=u.useMemo(()=>a?[a.grade,a.section].filter(Boolean).join(" · ")||"Unassigned section":null,[a]),z=()=>{m(ai()),g(!1)},R=async()=>{try{const C=k?.temporaryPassword||d;if(!C)return;typeof navigator<"u"&&navigator.clipboard&&await navigator.clipboard.writeText(C),g(!0),ie.success("Temporary password copied. Share it with the student now — it will not be shown again."),window.setTimeout(()=>g(!1),2500)}catch(C){console.warn("Clipboard write failed:",C),ie.error("Unable to copy password. Please copy it manually.")}},W=async()=>{if(!a)return;const C=l.trim();if(!Yx(C)){S("Enter a valid email address before creating the account.");return}if(!d||d.length<8){S("Temporary password must be at least 8 characters.");return}if(!r){S("Missing teacher context. Please refresh and try again.");return}h(!0),S(null);try{const w=await Yu({name:a.name,lrn:a.lrn,email:C,grade:a.grade,section:a.section,classSectionId:a.classSectionId,adviserTeacherId:r,adviserTeacherName:o,schoolYear:n,temporaryPassword:d});N(w),i?.({...w,rosterId:a.rosterId}),ie.success(`Account created for ${a.name}.`)}catch(w){const $=w instanceof Error?w.message:"Failed to create account.";S($)}finally{h(!1)}},f=k?.temporaryPassword||d;return e.jsx(zt,{children:t&&a&&e.jsx(Le.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-[60] flex items-center justify-center bg-black/50 backdrop-blur-sm p-4",onClick:()=>{p||s()},children:e.jsxs(Le.div,{initial:{opacity:0,scale:.95,y:12},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:12},transition:{type:"spring",damping:28,stiffness:320},onClick:C=>C.stopPropagation(),className:"bg-[#f7f9fc] rounded-3xl shadow-2xl w-full max-w-lg overflow-hidden border border-[#dde3eb]",role:"dialog","aria-modal":"true","aria-labelledby":"create-student-account-modal-title",children:[e.jsxs("div",{className:"flex items-start justify-between px-6 pt-6",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-12 h-12 rounded-2xl bg-indigo-100 text-indigo-600 flex items-center justify-center shrink-0",children:e.jsx(ci,{size:22})}),e.jsxs("div",{children:[e.jsx("h2",{id:"create-student-account-modal-title",className:"text-[16px] font-bold text-[#0a1628]",children:k?"Account Created":"Create Student Account"}),e.jsx("p",{className:"text-[12px] text-[#5a6578] mt-0.5",children:k?"Share these credentials with the student. The password will not be shown again.":`Provision a system account for ${a.name}.`})]})]}),e.jsx("button",{type:"button",onClick:()=>{p||s()},className:"p-1.5 rounded-lg hover:bg-[#dde3eb] transition-colors","aria-label":"Close",children:e.jsx(Xt,{className:"w-4 h-4 text-[#5a6578]"})})]}),e.jsxs("div",{className:"px-6 py-5 space-y-4",children:[e.jsxs("div",{className:"bg-white border border-[#e2e8f0] rounded-2xl p-4",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wider text-[#64748b]",children:"Roster Row"}),e.jsx("p",{className:"text-[14px] font-semibold text-[#0a1628] mt-1",children:a.name}),e.jsxs("p",{className:"text-[12px] text-[#475569] mt-0.5",children:[a.lrn?`LRN ${a.lrn} · `:"",I]})]}),!k&&e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-[12px] font-semibold text-[#0a1628]",children:"Email address"}),e.jsx("input",{type:"email",value:l,onChange:C=>c(C.target.value),disabled:p,className:"mt-1 w-full rounded-xl border border-[#dde3eb] bg-white px-3 py-2 text-[13px] text-[#0a1628] focus:border-indigo-500 focus:outline-none focus:ring-2 focus:ring-indigo-200",placeholder:"student@school.example",autoComplete:"off",spellCheck:!1}),e.jsx("span",{className:"text-[11px] text-[#64748b] mt-1 block",children:"Auto-generated from LRN if available. The student will sign in with this address."})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[12px] font-semibold text-[#0a1628] block",children:"Temporary password"}),e.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[e.jsx("input",{type:"text",value:d,readOnly:!0,className:"flex-1 rounded-xl border border-[#dde3eb] bg-white px-3 py-2 text-[13px] font-mono tracking-wide text-[#0a1628] focus:outline-none"}),e.jsx("button",{type:"button",onClick:z,disabled:p,className:"p-2 rounded-xl border border-[#dde3eb] bg-white hover:bg-[#f1f5f9] transition-colors disabled:opacity-60","aria-label":"Regenerate temporary password",children:e.jsx(cs,{className:"w-4 h-4 text-[#475569]"})}),e.jsx("button",{type:"button",onClick:R,className:"p-2 rounded-xl border border-[#dde3eb] bg-white hover:bg-[#f1f5f9] transition-colors","aria-label":"Copy temporary password",children:v?e.jsx(Ht,{className:"w-4 h-4 text-emerald-600"}):e.jsx(Vr,{className:"w-4 h-4 text-[#475569]"})})]}),e.jsx("span",{className:"text-[11px] text-[#64748b] mt-1 block",children:"The student should change this on first sign-in. Share it once — it will not be persisted."})]}),b&&e.jsxs("div",{className:"flex items-start gap-2 rounded-xl bg-rose-50 border border-rose-200 px-3 py-2 text-[12px] text-rose-700",children:[e.jsx(Mc,{className:"w-4 h-4 mt-0.5 shrink-0"}),e.jsx("span",{children:b})]})]}),k&&e.jsxs("div",{className:"rounded-2xl border border-emerald-200 bg-emerald-50 p-4 space-y-2",children:[e.jsx("p",{className:"text-[12px] font-semibold text-emerald-800",children:"Credentials"}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-xl bg-white border border-emerald-100 px-3 py-2",children:[e.jsx("span",{className:"text-[12px] text-[#475569]",children:"Email"}),e.jsx("span",{className:"text-[13px] font-semibold text-[#0a1628]",children:k.email})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-xl bg-white border border-emerald-100 px-3 py-2",children:[e.jsx("span",{className:"text-[12px] text-[#475569]",children:"Temporary password"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[13px] font-semibold font-mono text-[#0a1628]",children:f}),e.jsx("button",{type:"button",onClick:R,className:"p-1.5 rounded-lg border border-emerald-200 bg-white hover:bg-emerald-100 transition-colors","aria-label":"Copy temporary password",children:v?e.jsx(Ht,{className:"w-4 h-4 text-emerald-600"}):e.jsx(Vr,{className:"w-4 h-4 text-emerald-700"})})]})]}),e.jsx("p",{className:"text-[11px] text-emerald-800",children:"This password is not stored anywhere. If you close this dialog without copying, you will need to reset it from the admin tools."})]})]}),e.jsx("div",{className:"flex items-center justify-end gap-2 px-6 pb-6",children:k?e.jsx(St,{type:"button",onClick:s,className:"bg-indigo-600 hover:bg-indigo-700 text-white text-[13px] font-semibold rounded-xl px-5 py-2",children:"Done"}):e.jsxs(e.Fragment,{children:[e.jsx(St,{type:"button",variant:"ghost",onClick:s,disabled:p,className:"text-[13px] font-semibold text-[#475569] rounded-xl px-4 py-2 hover:bg-[#dde3eb]",children:"Cancel"}),e.jsx(St,{type:"button",onClick:W,disabled:p,className:"bg-indigo-600 hover:bg-indigo-700 text-white text-[13px] font-semibold rounded-xl px-5 py-2 disabled:opacity-60",children:p?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(gt,{className:"w-4 h-4 animate-spin"}),"Creating…"]}):"Create account"})]})})]})})})};function Xx(t){const s=t.atRiskCount>=5?"high":t.atRiskCount>=2?"medium":"low",a=Ct({metadata:t.classMetadata,classSectionId:t.classSectionId,className:t.name,grade:t.grade,gradeLevel:t.gradeLevel,classification:t.classification,strand:t.strand,section:t.section,schoolYear:t.schoolYear,ownerTeacherId:t.ownerTeacherId||t.teacherId,ownerTeacherName:t.ownerTeacherName,adviserTeacherId:t.adviserTeacherId||t.teacherId,adviserTeacherName:t.adviserTeacherName||t.ownerTeacherName,managerId:t.managerId,managerName:t.managerName});return{id:t.id,name:a.className||t.name,classSectionId:a.classSectionId||t.classSectionId,classMetadata:a,gradeLevel:a.gradeLevel||void 0,classification:a.classification||void 0,strand:a.strand||void 0,managerId:a.managerId||void 0,managerName:a.managerName||void 0,schedule:t.schedule,studentCount:t.studentCount,avgScore:t.avgScore,atRiskCount:t.atRiskCount,riskLevel:s}}function Hr(t,s){const a=t.riskStatus?["intervene","critical","at_risk"].includes(t.riskStatus)?"high":t.riskStatus==="watch"?"medium":"low":(t.riskLevel||"Low").toLowerCase(),r=t.lastActive?Cl(t.lastActive.toDate()):"Unknown",o=t.className||s||"Imported Class",n=xs(o),i=t.grade||n.grade,l=t.section||n.section,c=Ct({metadata:t.classMetadata,classSectionId:t.classSectionId||t.classroomId,className:[i,l].filter(Boolean).join(" - ")||o,grade:i,gradeLevel:t.gradeLevel,classification:t.classification,strand:t.strand,section:l,adviserTeacherId:t.teacherId,ownerTeacherId:t.teacherId,managerId:t.classMetadata?.managerId||t.managerId,managerName:t.classMetadata?.managerName||t.managerName});return{id:t.id,lrn:t.lrn,name:t.name,avatar:t.avatar||`https://ui-avatars.com/api/?name=${encodeURIComponent(t.name)}&background=random`,avgScore:t.avgQuizScore,riskLevel:a,riskStatus:t.riskStatus||null,wri:t.wri??null,weakestTopic:t.weakestTopic||"N/A",classroomId:t.classroomId||c.classSectionId||o,className:c.className||[i,l].filter(Boolean).join(" - ")||o,grade:i,gradeLevel:c.gradeLevel||gs(i)||void 0,classification:c.classification||xa(c.gradeLevel||i)||void 0,strand:c.strand||pa(c.className,l)||void 0,section:l,classSectionId:c.classSectionId||t.classSectionId,classMetadata:c,managerId:c.managerId||void 0,managerName:c.managerName||void 0,lastActive:r,struggles:t.struggles||[],engagementScore:t.engagementScore,attendance:t.attendance,assignmentCompletion:t.assignmentCompletion,hasRegisteredAccount:t.hasRegisteredAccount,source:t.source,accountUid:t.accountUid,email:t.email}}function Jx(t){const s=t.atRiskCount>=5?"high":t.atRiskCount>=2?"medium":"low",a=Ct({metadata:t.classMetadata,classSectionId:t.classSectionId,className:t.name,grade:t.grade,gradeLevel:t.gradeLevel||t.classMetadata?.gradeLevel,classification:t.classification||t.classMetadata?.classification,strand:t.strand||t.classMetadata?.strand,section:t.section,managerId:t.managerId||t.classMetadata?.managerId,managerName:t.managerName||t.classMetadata?.managerName});return{id:t.id,name:a.className||t.name,classSectionId:a.classSectionId||t.classSectionId||void 0,classMetadata:a,gradeLevel:a.gradeLevel||void 0,classification:a.classification||void 0,strand:a.strand||void 0,managerId:a.managerId||void 0,managerName:a.managerName||void 0,schedule:t.schedule||"Mon-Fri",studentCount:t.studentCount,avgScore:t.avgScore,atRiskCount:t.atRiskCount,riskLevel:s}}function Zx(t){const s=(t.riskLevel||"Low").toLowerCase(),a=Ct({metadata:t.classMetadata,classSectionId:t.classSectionId,className:t.className||[t.grade,t.section].filter(Boolean).join(" - ")||"Imported Class",grade:t.grade,gradeLevel:t.gradeLevel||t.classMetadata?.gradeLevel,classification:t.classification||t.classMetadata?.classification,strand:t.strand||t.classMetadata?.strand,section:t.section,managerId:t.managerId||t.classMetadata?.managerId,managerName:t.managerName||t.classMetadata?.managerName}),r=a.className||"Imported Class";return{id:t.id,lrn:t.lrn||void 0,name:t.name,avatar:`https://ui-avatars.com/api/?name=${encodeURIComponent(t.name)}&background=random`,avgScore:t.avgQuizScore,riskLevel:s,weakestTopic:t.weakestTopic||"Foundational Skills",classroomId:a.classSectionId||t.classSectionId||r,className:r,grade:a.grade||xs(r).grade,gradeLevel:a.gradeLevel||gs(a.grade||xs(r).grade)||void 0,classification:a.classification||xa(a.gradeLevel||a.grade)||void 0,strand:a.strand||pa(r,a.section||t.section)||void 0,section:a.section||xs(r).section,classSectionId:a.classSectionId||t.classSectionId||void 0,classMetadata:a,managerId:a.managerId||void 0,managerName:a.managerName||void 0,lastActive:"Recently imported",struggles:[t.weakestTopic||"Foundational Skills"],engagementScore:t.engagementScore,attendance:t.attendance,assignmentCompletion:t.assignmentCompletion}}function ep(t,s,a){return t<60||s<75||a<55?"high":t<75||s<85||a<70?"medium":"low"}function tp(t,s,a,r){const o=Ct({metadata:r,classSectionId:s,className:a}),n=o.className||"Imported Class",i=o.classSectionId||"imported_class",l=Number(t.avgQuizScore||0),c=Number(t.attendance||0),d=Number(t.engagementScore||0),m=Number(t.assignmentCompletion||0),p=t.unknownFields?.weakestTopic||t.unknownFields?.topic||"Foundational Skills",h=ep(l,c,d),b=t.studentId||t.lrn||t.email||t.name||Math.random().toString(36).slice(2);return{id:`upload-${i}-${b}`,lrn:t.lrn,name:t.name,avatar:`https://ui-avatars.com/api/?name=${encodeURIComponent(t.name)}&background=random`,avgScore:l,riskLevel:h,weakestTopic:p,classroomId:i,className:n,grade:o.grade||xs(n).grade,gradeLevel:o.gradeLevel||gs(o.grade||xs(n).grade)||void 0,classification:o.classification||xa(o.gradeLevel||o.grade)||void 0,strand:o.strand||pa(n,o.section)||void 0,section:o.section||xs(n).section,classSectionId:i,classMetadata:o,managerId:o.managerId||void 0,managerName:o.managerName||void 0,lastActive:"Recently imported",struggles:[p],engagementScore:d,attendance:c,assignmentCompletion:m}}function Cl(t){const s=Date.now()-t.getTime(),a=Math.floor(s/6e4);if(a<1)return"Just now";if(a<60)return`${a} min${a>1?"s":""} ago`;const r=Math.floor(a/60);if(r<24)return`${r} hour${r>1?"s":""} ago`;const o=Math.floor(r/24);return`${o} day${o>1?"s":""} ago`}function ct(t){return(t||"").trim().toLowerCase()}function ri(t){const s=ct(t.classSectionId);if(s)return`section:${s}`;const a=(t.id||"").trim().toLowerCase();return a?`id:${a}`:`name:${(t.name||"").trim().toLowerCase()}`}function ni(t,s){const a=new Map;return t.forEach(r=>{a.set(ri(r),r)}),s.forEach(r=>{const o=ri(r),n=a.get(o);if(!n){a.set(o,r);return}const i=Math.max(n.atRiskCount||0,r.atRiskCount||0),l=Math.max(n.studentCount||0,r.studentCount||0),c=r.avgScore>0?r.avgScore:n.avgScore,d=i>=5?"high":i>=2?"medium":"low",m=Ct({metadata:n.classMetadata,classSectionId:n.classSectionId||r.classSectionId,className:n.name||r.name,grade:n.classMetadata?.grade||r.classMetadata?.grade,gradeLevel:n.classMetadata?.gradeLevel||r.classMetadata?.gradeLevel,classification:n.classMetadata?.classification||r.classMetadata?.classification,strand:n.classMetadata?.strand||r.classMetadata?.strand,section:n.classMetadata?.section||r.classMetadata?.section,schoolYear:n.classMetadata?.schoolYear||r.classMetadata?.schoolYear,ownerTeacherId:n.classMetadata?.ownerTeacherId||r.classMetadata?.ownerTeacherId,ownerTeacherName:n.classMetadata?.ownerTeacherName||r.classMetadata?.ownerTeacherName,adviserTeacherId:n.classMetadata?.adviserTeacherId||r.classMetadata?.adviserTeacherId,adviserTeacherName:n.classMetadata?.adviserTeacherName||r.classMetadata?.adviserTeacherName,managerId:n.classMetadata?.managerId||r.classMetadata?.managerId,managerName:n.classMetadata?.managerName||r.classMetadata?.managerName});a.set(o,{...n,classSectionId:m.classSectionId||n.classSectionId||r.classSectionId,name:m.className||n.name||r.name,classMetadata:m,gradeLevel:m.gradeLevel||void 0,classification:m.classification||void 0,strand:m.strand||void 0,managerId:m.managerId||void 0,managerName:m.managerName||void 0,schedule:n.schedule||r.schedule,studentCount:l,atRiskCount:i,avgScore:c,riskLevel:d})}),Array.from(a.values())}function gr(t){const s=(t.lrn||"").trim().toLowerCase();if(s)return`lrn:${s}`;const a=t.name.trim().toLowerCase();if(a)return`name:${a}`;const r=ct(t.classSectionId)||ct(t.classroomId),o=(t.id||"").trim().toLowerCase();return r&&o?`${r}|id:${o}`:`${r}|anonymous`}function ln(t){const s=ct(t.classSectionId)||ct(t.classroomId),a=(t.lrn||"").trim().toLowerCase(),r=(t.id||"").trim().toLowerCase(),o=t.name.trim().toLowerCase().replace(/\s+/g,"_");return s&&a?`${s}|lrn:${a}`:s&&r?`${s}|id:${r}`:a?`lrn:${a}`:r&&o?`id:${r}|name:${o}`:r?`id:${r}`:s&&o?`${s}|name:${o}`:`name:${o||"unknown"}`}function oi(t,s){const a=new Map;return t.forEach(r=>{a.set(gr(r),r)}),s.forEach(r=>{const o=gr(r),n=a.get(o);if(!n){a.set(o,r);return}const i=[n.riskLevel,r.riskLevel].includes("high")?"high":[n.riskLevel,r.riskLevel].includes("medium")?"medium":"low",l=Ct({metadata:n.classMetadata,classSectionId:n.classSectionId||r.classSectionId,className:n.className||r.className,grade:n.grade||r.grade,gradeLevel:n.gradeLevel||r.gradeLevel,classification:n.classification||r.classification,strand:n.strand||r.strand,section:n.section||r.section,managerId:n.managerId||r.managerId,managerName:n.managerName||r.managerName});a.set(o,{...n,lrn:n.lrn||r.lrn,classSectionId:l.classSectionId||n.classSectionId||r.classSectionId,classroomId:n.classroomId||r.classroomId,className:l.className||n.className||r.className,grade:l.grade||n.grade||r.grade,gradeLevel:l.gradeLevel||n.gradeLevel||r.gradeLevel,classification:l.classification||n.classification||r.classification,strand:l.strand||n.strand||r.strand,section:l.section||n.section||r.section,managerId:l.managerId||n.managerId||r.managerId,managerName:l.managerName||n.managerName||r.managerName,classMetadata:l,avgScore:r.avgScore>0?r.avgScore:n.avgScore,attendance:r.attendance>0?r.attendance:n.attendance,engagementScore:r.engagementScore>0?r.engagementScore:n.engagementScore,assignmentCompletion:r.assignmentCompletion>0?r.assignmentCompletion:n.assignmentCompletion,weakestTopic:n.weakestTopic&&n.weakestTopic!=="N/A"?n.weakestTopic:r.weakestTopic,riskLevel:i,struggles:n.struggles.length>0?n.struggles:r.struggles,hasRegisteredAccount:n.hasRegisteredAccount===!0||r.hasRegisteredAccount===!0?!0:n.hasRegisteredAccount??r.hasRegisteredAccount,source:n.source==="registered"&&r.source==="import"||n.source==="import"&&r.source==="registered"||n.source==="both"||r.source==="both"?"both":n.source||r.source,accountUid:n.accountUid||r.accountUid,email:n.email||r.email})}),Array.from(a.values())}const ih=({onLogout:t,onOpenProfile:s,onOpenSettings:a})=>{const{currentUser:r,userProfile:o}=hs(),[n,i]=u.useState("dashboard"),[l,c]=u.useState(!1),[d,m]=u.useState(!1),[p,h]=u.useState(!1),[b,S]=u.useState(!1),[k,N]=u.useState(!1),[v,g]=u.useState(!1),[I,z]=u.useState(!1),R=["streak_reminder","daily_checkin","streak_milestone","achievement_unlocked","level_up","xp_earned","quiz_result"],{notifications:W}=pi(),f=W.filter(M=>!M.isRead&&!R.includes(M.type)).length,[C,w]=u.useState(null),[$,A]=u.useState(null),[y,q]=u.useState(!1),[J,re]=u.useState(!1),[le,ne]=u.useState(!1),[be,Ie]=u.useState(!1),[de,fe]=u.useState([]),[H,ee]=u.useState([]),oe=u.useMemo(()=>r?.uid?de.filter(M=>M.managerId===r.uid||M.classMetadata?.managerId===r.uid):de,[de,r?.uid]),[Re,Fe]=u.useState([]),[Pe,G]=u.useState(""),[te,E]=u.useState(!0),[Y,V]=u.useState(!1),[pe,D]=u.useState(0),[j,_]=u.useState([]),[T,Q]=u.useState(!1),[ue,ce]=u.useState(null),[ae,Ce]=u.useState(null),Ne=o?.name||"Teacher",Je=u.useRef(new Map);u.useEffect(()=>{const M=()=>S(window.innerWidth<1024);return M(),window.addEventListener("resize",M),()=>window.removeEventListener("resize",M)},[]),u.useEffect(()=>{if(!r)return;const M=r.uid;let F=!0,ve;return(async()=>{E(!0);try{const qe=await ll(M);let je=qe.map(Xx);const yt=await Ju(M).catch(()=>[]),lt=new Map;yt.forEach(P=>{const X=ct(P.classSectionId);X&<.set(X,P)}),je=je.map(P=>{const X=lt.get(ct(P.classSectionId));if(!X)return P;const Ee=Ct({metadata:P.classMetadata,classSectionId:X.classSectionId||P.classSectionId,className:X.className||P.name,grade:X.grade||P.classMetadata?.grade,gradeLevel:X.gradeLevel||P.classMetadata?.gradeLevel,classification:X.classification||P.classMetadata?.classification,strand:X.strand||P.classMetadata?.strand,section:X.section||P.classMetadata?.section,schoolYear:X.schoolYear||P.classMetadata?.schoolYear,ownerTeacherId:X.ownerTeacherId||P.classMetadata?.ownerTeacherId,ownerTeacherName:X.ownerTeacherName||P.classMetadata?.ownerTeacherName,managerId:X.managerId||P.classMetadata?.managerId,managerName:X.managerName||P.classMetadata?.managerName});return{...P,name:Ee.className||P.name,classSectionId:Ee.classSectionId||P.classSectionId,classMetadata:Ee,gradeLevel:Ee.gradeLevel||P.gradeLevel,classification:Ee.classification||P.classification,strand:Ee.strand||P.strand,managerId:Ee.managerId||P.managerId,managerName:Ee.managerName||P.managerName}});const se=new Map,rt=new Map;qe.forEach(P=>{const X=Ct({metadata:P.classMetadata,classSectionId:P.classSectionId,className:P.name,grade:P.grade,gradeLevel:P.gradeLevel,classification:P.classification,strand:P.strand,section:P.section,schoolYear:P.schoolYear,ownerTeacherId:P.ownerTeacherId||P.teacherId,ownerTeacherName:P.ownerTeacherName,adviserTeacherId:P.adviserTeacherId||P.teacherId,adviserTeacherName:P.adviserTeacherName,managerId:P.managerId,managerName:P.managerName});se.set(P.id,X.className||P.name),rt.set(P.id,X);const Ee=ct(P.classSectionId);if(Ee){const Oe=lt.get(Ee),Pt=Ct({metadata:X,classSectionId:Oe?.classSectionId||Ee,className:Oe?.className||X.className,grade:Oe?.grade||X.grade,gradeLevel:Oe?.gradeLevel||X.gradeLevel,classification:Oe?.classification||X.classification,strand:Oe?.strand||X.strand,section:Oe?.section||X.section,schoolYear:Oe?.schoolYear||X.schoolYear,ownerTeacherId:Oe?.ownerTeacherId||X.ownerTeacherId,ownerTeacherName:Oe?.ownerTeacherName||X.ownerTeacherName,managerId:Oe?.managerId||X.managerId,managerName:Oe?.managerName||X.managerName});se.set(Ee,Pt.className||P.name),rt.set(Ee,Pt)}});const nt=P=>{const X=ct(P.classSectionId||P.classroomId);if(!X)return P;const Ee=rt.get(X);if(!Ee)return P;const Oe=Ct({metadata:Ee,classSectionId:P.classSectionId||Ee.classSectionId,className:P.className||Ee.className,grade:P.grade||Ee.grade,gradeLevel:P.gradeLevel||Ee.gradeLevel,classification:P.classification||Ee.classification,strand:P.strand||Ee.strand,section:P.section||Ee.section,managerId:P.managerId||Ee.managerId,managerName:P.managerName||Ee.managerName});return{...P,className:Oe.className||P.className,grade:Oe.grade||P.grade,gradeLevel:Oe.gradeLevel||P.gradeLevel,classification:Oe.classification||P.classification,strand:Oe.strand||P.strand,section:Oe.section||P.section,classSectionId:Oe.classSectionId||P.classSectionId,classMetadata:Oe,managerId:Oe.managerId||P.managerId,managerName:Oe.managerName||P.managerName}},ut=(P,X,Ee)=>se.get(P)||(X?se.get(X):void 0)||Ee||"Unknown",ws=Array.from(new Set([...yt.map(P=>P.classSectionId),...qe.map(P=>P.classSectionId).filter(Boolean),...je.map(P=>P.classSectionId).filter(Boolean)].map(P=>(P||"").trim()).filter(P=>!!P))),[Xs,_s]=await Promise.all([jn(M).catch(P=>(console.warn("[TeacherDashboard] managed-student fetch failed:",P),[])),Vu(M,ws).catch(P=>(console.warn("[TeacherDashboard] registered-student fetch failed:",P),[]))]);let Oa=_s;if(_s.length===0&&Xs.length===0)try{const{collection:P,query:X,where:Ee,getDocs:Oe}=await Ss(async()=>{const{collection:Bt,query:Ye,where:fa,getDocs:ga}=await import("./vendor-firebase-firestore-CNv3xXal.js");return{collection:Bt,query:Ye,where:fa,getDocs:ga}},__vite__mapDeps([2,3])),{db:Pt}=await Ss(async()=>{const{db:Bt}=await import("./index-Bp7MiGcW.js").then(Ye=>Ye.b7);return{db:Bt}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11])),De=X(P(Pt,"users"),Ee("role","==","student"));Oa=(await Oe(De)).docs.map(Bt=>{const Ye=Bt.data();return{uid:Bt.id,name:String(Ye.name||Ye.displayName||"").trim()||"Student",email:String(Ye.email||"").trim(),lrn:Ye.lrn?String(Ye.lrn).trim():void 0,photo:Ye.photo?String(Ye.photo).trim():Ye.photoURL?String(Ye.photoURL).trim():void 0,grade:Ye.grade?String(Ye.grade).trim():void 0,section:Ye.section?String(Ye.section).trim():void 0,classSectionId:Ye.classSectionId?String(Ye.classSectionId).trim():void 0,adviserTeacherId:Ye.adviserTeacherId?String(Ye.adviserTeacherId).trim():void 0,role:"student",createdAt:Ye.createdAt||void 0}}).filter(Bt=>Bt.name!=="Student"||Bt.email)}catch(P){console.warn("[TeacherDashboard] fallback all-students fetch failed:",P)}const Js=new Map,Hs=new Map,Pa=new Map;Xs.forEach(P=>{Js.set(P.id,P),P.lrn&&Hs.set(P.lrn.trim().toLowerCase(),P);const X=Ro(P.name),Ee=ct(P.classSectionId||P.classroomId);X&&Pa.set(`${X}|${Ee}`,P)});const Ba=new Set,Ha=Oa.map(P=>{const X=Wu(P),Ee=(P.lrn||"").trim().toLowerCase(),Oe=Ro(P.name),Pt=ct(P.classSectionId);let De;if(Js.has(P.uid))De=Js.get(P.uid);else if(Ee&&Hs.has(Ee))De=Hs.get(Ee);else if(Oe){const Ye=`${Oe}|${Pt}`;De=Pa.get(Ye)}if(De){Ba.add(De.id);const Ye={...X,id:P.uid,accountUid:P.uid,email:X.email||De.email,lrn:X.lrn||De.lrn,name:X.name||De.name,avatar:X.avatar||De.avatar,riskLevel:De.riskLevel||X.riskLevel,avgQuizScore:De.avgQuizScore||X.avgQuizScore,engagementScore:De.engagementScore||X.engagementScore,attendance:De.attendance||X.attendance,assignmentCompletion:De.assignmentCompletion||X.assignmentCompletion,weakestTopic:De.weakestTopic||X.weakestTopic,struggles:De.struggles||X.struggles,lastActive:De.lastActive||X.lastActive,wri:De.wri??null,riskStatus:De.riskStatus??null,riskUpdatedAt:De.riskUpdatedAt??null,diagnosticScore:De.diagnosticScore??null,externalGradesAvg:De.externalGradesAvg??null,systemPerformanceAvg:De.systemPerformanceAvg??null,riskHistory:De.riskHistory,grade:X.grade||De.grade,gradeLevel:X.gradeLevel||De.gradeLevel,section:X.section||De.section,classSectionId:X.classSectionId||De.classSectionId,classroomId:X.classroomId||De.classroomId,classMetadata:De.classMetadata||X.classMetadata,hasRegisteredAccount:!0,source:"both"},fa=ct(Ye.classSectionId||Ye.classroomId),ga=ut(Ye.classroomId||"",fa,Ye.className);return nt(Hr(Ye,ga))}const Ga=ct(X.classSectionId||X.classroomId),Bt=ut(X.classroomId||"",Ga,X.className);return nt(Hr(X,Bt))}),Ua=Xs.filter(P=>!Ba.has(P.id)).map(P=>{const X={...P,hasRegisteredAccount:!1,source:"import"},Ee=ct(X.classSectionId||X.classroomId),Oe=ut(X.classroomId,Ee,X.className);return nt(Hr(X,Oe))}),Us=[...Ha,...Ua];if(!F)return;fe(P=>je.length===0&&P.length>0?P:je),ee(P=>Us.length===0&&P.length>0?P:Us),xt.getImportedClassOverview({limit:3e3,forceRefresh:pe>0}).then(P=>{F&&(P.warnings.length>0&&console.warn("Imported class overview warnings:",P.warnings.join(" ")),fe(X=>ni(X,P.classrooms.map(Jx))),ee(X=>{if(X.length===0)return X;const Ee=P.students.map(Zx),Oe=new Set;X.forEach(De=>Oe.add(gr(De)));const Pt=Ee.filter(De=>Oe.has(gr(De)));return Pt.length===0?X:oi(X,Pt)}))}).catch(P=>{console.warn("Imported class overview merge unavailable:",P)});const ha=qe.map(P=>P.id);ha.length>0&&(ve=em(ha,P=>{F&&Fe(P.map(X=>({id:X.id,student:X.studentName,action:X.action,topic:X.topic,time:Cl(X.timestamp.toDate()),type:X.type})))}))}catch(qe){console.error("Failed to load teacher data:",qe),ie.error("Failed to load dashboard data")}finally{E(!1)}})(),()=>{F=!1,ve&&ve()}},[r,pe]),u.useEffect(()=>{if(!r)return;let M=!0;return Zu("",80).then(F=>{M&&_(F)}).catch(F=>{console.warn("Failed to load teacher directory options:",F)}),()=>{M=!1}},[r]),u.useEffect(()=>{if(H.length===0)return;(async()=>{if(H.length===0){G("");return}V(!0);try{const F=H.map(we=>({name:we.name,engagementScore:we.engagementScore,avgQuizScore:we.avgScore,attendance:we.attendance,riskLevel:we.riskLevel})),ve=await xt.getDailyInsight({students:F});G(ve.insight)}catch{G(`${H.filter(F=>F.riskLevel==="high").length} students are at high risk of falling behind. Review their progress in the analytics view.`)}finally{V(!1)}})()},[H]);const $e=de.reduce((M,F)=>M+F.studentCount,0),Ge=H.filter(M=>M.riskLevel==="high").length,ft=(()=>{const M=H.map(F=>F.avgScore).filter(F=>F>0);return M.length>0?Math.round(M.reduce((F,ve)=>F+ve,0)/M.length):0})(),Nt=[{name:"High Risk",value:H.filter(M=>M.riskLevel==="high").length,color:"#FF8B8B"},{name:"Medium Risk",value:H.filter(M=>M.riskLevel==="medium").length,color:"#F08386"},{name:"Low Risk",value:H.filter(M=>M.riskLevel==="low").length,color:"#75D06A"}],dt={};H.forEach(M=>{M.weakestTopic&&M.weakestTopic!=="N/A"&&(dt[M.weakestTopic]||(dt[M.weakestTopic]={total:0,sum:0}),dt[M.weakestTopic].total+=1,dt[M.weakestTopic].sum+=M.avgScore)});const jt=Object.entries(dt).map(([M,F])=>({topic:M,score:Math.round(F.sum/F.total)})).sort((M,F)=>M.score-F.score).slice(0,6),Lt=M=>{w(M),i("analytics")},rs=M=>{A(M),i("intervention")},Ts=()=>{A(null),i("analytics")},bs=()=>{w(null),A(null),i("dashboard")},Bs=async(M,F)=>{if(!r){ie.error("Unable to assign manager: teacher context is missing.");return}const ve=xs(M.classMetadata?.className||M.name),we=Ct({metadata:M.classMetadata,classSectionId:M.classSectionId,className:M.name,grade:M.classMetadata?.grade||ve.grade,gradeLevel:M.classMetadata?.gradeLevel,classification:M.classMetadata?.classification,strand:M.classMetadata?.strand,section:M.classMetadata?.section||ve.section,schoolYear:M.classMetadata?.schoolYear||String(new Date().getFullYear()),ownerTeacherId:M.classMetadata?.ownerTeacherId||r.uid,ownerTeacherName:M.classMetadata?.ownerTeacherName||Ne,adviserTeacherId:M.classMetadata?.adviserTeacherId||r.uid,adviserTeacherName:M.classMetadata?.adviserTeacherName||Ne,managerId:F.uid,managerName:F.name}),qe=we.classSectionId||Ft(we.grade||ve.grade,we.section||ve.section);if(!qe){ie.error("Unable to assign manager: missing class section ID.");return}Q(!0);try{await cl({classSectionId:qe,className:we.className||M.name,grade:we.grade||ve.grade,gradeLevel:we.gradeLevel||gs(we.grade||ve.grade)||we.grade||ve.grade,classification:we.classification||xa(we.gradeLevel||we.grade)||void 0,strand:we.strand||pa(we.className,we.section)||void 0,section:we.section||ve.section,schoolYear:we.schoolYear||String(new Date().getFullYear()),ownerTeacherId:we.ownerTeacherId||r.uid,ownerTeacherName:we.ownerTeacherName||Ne,managerId:F.uid,managerName:F.name});const je=Ct({metadata:we,classSectionId:qe,managerId:F.uid,managerName:F.name}),yt=ct(qe);fe(lt=>lt.map(se=>ct(se.classSectionId)!==yt?se:{...se,name:je.className||se.name,classSectionId:je.classSectionId||se.classSectionId,classMetadata:je,gradeLevel:je.gradeLevel||se.gradeLevel,classification:je.classification||se.classification,strand:je.strand||se.strand,managerId:F.uid,managerName:F.name})),ee(lt=>lt.map(se=>{if(ct(se.classSectionId||se.classroomId)!==yt)return se;const nt=Ct({metadata:se.classMetadata,classSectionId:je.classSectionId||se.classSectionId,className:se.className||je.className,grade:se.grade||je.grade,gradeLevel:se.gradeLevel||je.gradeLevel,classification:se.classification||je.classification,strand:se.strand||je.strand,section:se.section||je.section,managerId:F.uid,managerName:F.name});return{...se,classMetadata:nt,gradeLevel:nt.gradeLevel||se.gradeLevel,classification:nt.classification||se.classification,strand:nt.strand||se.strand,managerId:F.uid,managerName:F.name}})),w(lt=>!lt||ct(lt.classSectionId)!==yt?lt:{...lt,classMetadata:je,managerId:F.uid,managerName:F.name,gradeLevel:je.gradeLevel||lt.gradeLevel,classification:je.classification||lt.classification,strand:je.strand||lt.strand}),ie.success(`Assigned ${F.name} as section manager.`)}catch(je){console.error("Failed to assign class manager:",je),ie.error(je instanceof Error?je.message:"Failed to assign class manager")}finally{Q(!1)}},ns=u.useCallback(M=>{ce({rosterId:M.id,name:M.name,lrn:M.lrn,email:M.email,grade:M.grade,section:M.section,classSectionId:M.classSectionId})},[]),vs=u.useCallback(M=>{ee(F=>F.map(ve=>ve.id===M.rosterId?{...ve,hasRegisteredAccount:!0,source:"both",accountUid:M.uid,email:M.email||ve.email}:ve)),D(F=>F+1)},[]),os=u.useCallback(async(M,F)=>{if(!r){ie.error("Cannot reassign section without an authenticated teacher.");return}const ve=r.uid,we=(F.classSectionId||"").trim();if(!we){ie.error("Pick a target section first.");return}Ce(M.id);try{await qu({studentId:M.accountUid||M.id,isRegisteredAccount:!!M.hasRegisteredAccount,newClassSectionId:we,newGrade:F.grade,newSection:F.section,previousClassSectionId:M.classSectionId,teacherId:ve,teacherName:Ne,schoolYear:M.classMetadata?.schoolYear||String(new Date().getFullYear())}),ee(qe=>qe.map(je=>{if(je.id!==M.id)return je;const yt=Ct({metadata:je.classMetadata,classSectionId:we,className:je.className,grade:F.grade,section:F.section});return{...je,grade:F.grade,section:F.section,classSectionId:we,classroomId:we,classMetadata:yt}})),ie.success(`Moved ${M.name} to ${F.grade} - ${F.section}.`)}catch(qe){console.error("Section reassignment failed:",qe),ie.error(qe instanceof Error?qe.message:"Failed to reassign section.")}finally{Ce(null)}},[r,Ne]),L=u.useCallback(async M=>{if(!r||!window.confirm(`Remove ${M.name} from this class? This cannot be undone.`))return;const F=M.classSectionId||M.classroomId||"";if(!F){ie.error("Cannot determine class section for this student.");return}try{await Ku(M.accountUid||M.id,F),ee(ve=>ve.filter(we=>we.id!==M.id)),ie.success(`Removed ${M.name} from class.`)}catch(ve){console.error("Remove student failed:",ve),ie.error("Failed to remove student.")}},[r]);u.useEffect(()=>{const M=()=>{const F=window.innerWidth<1024;S(F),F?c(!1):h(!1)};return M(),window.addEventListener("resize",M),()=>window.removeEventListener("resize",M)},[]),u.useEffect(()=>{b&&h(!1)},[n,b]);const me=M=>{i(M),w(null),A(null)},We=u.useMemo(()=>{if(!C)return;if(C.classMetadata?.classSectionId)return C.classMetadata.classSectionId||void 0;if(C.classSectionId)return C.classSectionId;const M=xs(C.classMetadata?.className||C.name);return Ft(M.grade,M.section)||void 0},[C]),B=u.useMemo(()=>C||null,[C]),kt=u.useMemo(()=>{if(!B)return;const M=de.findIndex(F=>F.id===B.id);return hr[Math.max(0,M)%hr.length]},[B,de]),Me=u.useMemo(()=>{if(!B)return H;const M=(B.id||"").trim().toLowerCase(),F=ct(B.classSectionId),ve=(B.name||"").trim().toLowerCase();return H.filter(we=>{const qe=ct(we.classroomId),je=ct(we.classSectionId),yt=(we.className||"").trim().toLowerCase();return F&&(je===F||qe===F)||M&&(qe===M||je===M)||ve&&yt===ve})},[B,H]);return te?e.jsx(Gl,{message:"Loading dashboard..."}):e.jsxs("div",{className:"relative flex h-screen w-full bg-background overflow-hidden",children:[b&&p&&e.jsx("button",{"aria-label":"Close navigation",className:"fixed inset-0 z-30 bg-slate-900/40 backdrop-blur-[1px]",onClick:()=>h(!1)}),e.jsxs(Le.aside,{initial:!1,animate:{width:b?280:l&&!d?80:280,x:b?p?0:-300:0},transition:{type:"spring",stiffness:360,damping:34},onMouseEnter:()=>!b&&l&&m(!0),onMouseLeave:()=>m(!1),className:"fixed inset-y-0 left-0 z-40 bg-[#f7f9fc] rounded-3xl border border-[#dde3eb] flex flex-col shadow-sm lg:static lg:z-auto p-5",children:[e.jsxs("div",{className:`mb-8 flex items-center ${l&&!d?"justify-center":"justify-between"}`,children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-12 h-12 bg-gradient-to-r from-[#7274ED] to-[#9956DE] rounded-2xl flex items-center justify-center shadow-md flex-shrink-0",children:e.jsx("img",{src:"/avatar/avatar_icon.png",alt:"MathPulse AI",className:"w-10 h-10 object-contain drop-shadow-md"})}),(!l||d)&&e.jsx("div",{children:e.jsx("h1",{className:"text-base font-semibold font-display text-[#0a1628] whitespace-nowrap",children:"MathPulse AI"})})]}),!b&&(!l||d)&&e.jsx(Le.button,{whileHover:{scale:1.1},whileTap:{scale:.95},onClick:()=>c(!l),className:"p-2 hover:bg-[#dde3eb] rounded-lg transition-colors text-[#5a6578]","aria-label":l?"Expand sidebar":"Collapse sidebar",children:l?e.jsx(Ms,{size:20}):e.jsx(zs,{size:20})}),b&&e.jsx("button",{onClick:()=>h(!1),className:"p-2 hover:bg-[#dde3eb] rounded-lg transition-colors text-[#5a6578]","aria-label":"Close navigation",children:e.jsx(Xt,{size:20})})]}),e.jsxs("nav",{className:"flex-1 space-y-5",children:[e.jsxs("div",{children:[l&&!d?e.jsx("div",{className:"px-4 mb-2 flex items-center gap-2",children:e.jsx("div",{className:"flex-1 h-[1px] bg-[#dde3eb]"})}):e.jsx("p",{className:"px-4 mb-2 text-[10px] font-semibold text-[#5a6578] uppercase tracking-widest",children:"Overview"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(Es,{icon:tc,label:"Dashboard",active:n==="dashboard",collapsed:l&&!d,onClick:bs,forceExpanded:b}),e.jsx(Es,{icon:Ls,label:"Class Analytics",active:n==="analytics"||n==="intervention",collapsed:l&&!d,onClick:()=>me("analytics"),forceExpanded:b})]})]}),e.jsxs("div",{children:[l&&!d?e.jsx("div",{className:"px-4 mb-2 flex items-center gap-2",children:e.jsx("div",{className:"flex-1 h-[1px] bg-[#dde3eb]"})}):e.jsx("p",{className:"px-4 mb-2 text-[10px] font-semibold text-[#5a6578] uppercase tracking-widest",children:"Students"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(Es,{icon:ms,label:"Topic Mastery",active:n==="topic_mastery",collapsed:l&&!d,onClick:()=>me("topic_mastery"),forceExpanded:b}),e.jsx(Es,{icon:us,label:"Competency",active:n==="competency",collapsed:l&&!d,onClick:()=>me("competency"),forceExpanded:b})]})]}),e.jsxs("div",{children:[l&&!d?e.jsx("div",{className:"px-4 mb-2 flex items-center gap-2",children:e.jsx("div",{className:"flex-1 h-[1px] bg-[#dde3eb]"})}):e.jsx("p",{className:"px-4 mb-2 text-[10px] font-semibold text-[#5a6578] uppercase tracking-widest",children:"Tools"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(Es,{icon:sc,label:"Data Import",active:n==="import",collapsed:l&&!d,onClick:()=>i("import"),forceExpanded:b}),e.jsx(Es,{icon:qr,label:"AI Quiz Maker",active:n==="quiz_maker",collapsed:l&&!d,onClick:()=>i("quiz_maker"),forceExpanded:b}),e.jsx(Es,{icon:Gt,label:"Question Bank",active:n==="question_bank",collapsed:l&&!d,onClick:()=>i("question_bank"),forceExpanded:b}),e.jsx(Es,{icon:nr,label:"Calendar",active:n==="calendar",collapsed:l&&!d,onClick:()=>i("calendar"),forceExpanded:b})]})]})]}),e.jsxs("div",{className:"space-y-2 border-t border-[#dde3eb] pt-4",children:[e.jsxs(Le.button,{whileHover:{x:2},whileTap:{scale:.98},className:`w-full flex items-center gap-3 px-4 py-3 rounded-2xl text-[#5a6578] font-semibold border border-transparent hover:bg-[#dde3eb] hover:border-[#dde3eb] hover:text-[#0a1628] transition-all duration-200 whitespace-nowrap ${l&&!d?"justify-center":""}`,onClick:a,title:l&&!d?"Settings":"",children:[e.jsx(ac,{size:18,strokeWidth:2,className:"flex-shrink-0"}),(!l||d)&&e.jsx("span",{className:"font-body text-xs",children:"Settings"})]}),e.jsx("div",{className:"text-[#5a6578]",children:e.jsx(rc,{onClick:()=>N(!0),collapsed:l&&!d})})]})]}),e.jsxs("div",{className:"flex-1 flex overflow-hidden bg-gradient-to-br from-[#eef2ff] via-[#f5f3ff] to-[#fff7ed]",children:[e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[["dashboard","analytics","intervention","competency","topic_mastery","calendar","notifications","question_bank","import","quiz_maker"].includes(n)&&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-row items-center justify-between gap-2 mb-0",children:[e.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-2",children:[b&&e.jsx("button",{onClick:()=>h(!0),className:"mt-1 p-2 rounded-lg border border-border text-muted-foreground hover:text-[#9956DE] hover:border-[#9956DE]/30 hover:bg-[#9956DE]/12 transition-colors","aria-label":"Open navigation",children:e.jsx(Ql,{size:18})}),e.jsxs("div",{children:[e.jsxs("h1",{className:"text-lg sm:text-[26px] font-bold text-[#1e293b] tracking-tight leading-tight truncate",children:[n==="dashboard"&&"Teacher Dashboard",n==="analytics"&&"Class Analytics",n==="intervention"&&"Intervention Center",n==="competency"&&"Student Competency",n==="topic_mastery"&&"Topic Mastery",n==="calendar"&&"Academic Calendar",n==="notifications"&&"Notifications",n==="question_bank"&&"Question Bank",n==="import"&&"Data Import",n==="quiz_maker"&&"AI Quiz Maker"]}),e.jsxs("p",{className:"text-[13px] text-[#64748b] mt-1",children:[n==="dashboard"&&`Welcome back, ${Ne}`,n==="analytics"&&"Analyze performance and risk across your classes.",n==="intervention"&&"Identify and support students who need immediate help.",n==="competency"&&"Track individual student progress against learning goals.",n==="topic_mastery"&&"Overview of student mastery levels across different math topics.",n==="calendar"&&"Manage your schedules and academic events.",n==="notifications"&&"Stay updated with student activity and system alerts.",n==="question_bank"&&"Manage and create math questions for your quizzes.",n==="import"&&"Upload class records and materials to power AI analytics.",n==="quiz_maker"&&"Create AI-powered quizzes based on your curriculum."]})]}),n==="dashboard"&&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-[#9956DE]/12 border border-[#9956DE]/30 rounded-lg",children:[e.jsx(us,{size:13,className:"text-[#9956DE]"}),e.jsxs("span",{className:"text-xs font-display font-semibold text-[#9956DE]",children:[$e," students"]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1.5 bg-[#F08386]/12 border border-[#F08386]/30 rounded-lg",children:[e.jsx(ca,{size:13,className:"text-[#F08386]"}),e.jsxs("span",{className:"text-xs font-display font-semibold text-[#C65E63]",children:[Ge," at risk"]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1.5 bg-[#75D06A]/14 border border-[#75D06A]/35 rounded-lg",children:[e.jsx(la,{size:13,className:"text-[#75D06A]"}),e.jsxs("span",{className:"text-xs font-display font-semibold text-[#4D9F46]",children:[ft,"% avg"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsxs("div",{className:"relative group",children:[e.jsxs("button",{onClick:()=>{re(!0),q(!0)},className:"relative w-10 h-10 flex items-center justify-center bg-[#eef2ff]/80 hover:bg-[#e0e7ff] rounded-full backdrop-blur-[12px] shadow-[0_1px_4px_rgba(0,0,0,0.04)] border border-[#a5b4fc]/60 text-[#4f46e5] hover:border-[#818cf8] transition-colors cursor-pointer hover:scale-[1.02]","aria-label":"View AI Insight",children:[e.jsx(ps,{size:18}),!y&&Pe&&e.jsx("div",{className:"absolute top-2.5 right-2.5 w-2 h-2 bg-rose-500 rounded-full border border-white animate-pulse"})]}),e.jsx("span",{className:"absolute -bottom-8 left-1/2 -translate-x-1/2 text-[10px] bg-[#1e293b] text-white px-2 py-1 rounded opacity-0 group-hover:opacity-100 transition-opacity whitespace-nowrap z-50 pointer-events-none",children:"AI Insight"})]}),b&&n==="dashboard"&&e.jsx("button",{onClick:()=>Ie(M=>!M),className:`relative w-10 h-10 flex items-center justify-center rounded-full backdrop-blur-[12px] shadow-[0_1px_4px_rgba(0,0,0,0.04)] border transition-colors cursor-pointer hover:scale-[1.02] ${be?"bg-[#818cf8] border-[#6366f1] text-white":"bg-white/60 hover:bg-white/80 border-white/50 text-[#64748b] hover:text-[#1e293b]"}`,"aria-label":be?"Close calendar panel":"Open calendar panel",title:be?"Close calendar":"View calendar",children:e.jsx(nr,{size:18})}),e.jsxs("div",{className:"relative",children:[e.jsxs("button",{onClick:()=>ne(!le),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",title:"Notifications",children:[e.jsx(dr,{size:18}),f>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(Zl,{isOpen:le,onClose:()=>ne(!1),onViewAll:()=>i("notifications")})]}),n!=="dashboard"&&e.jsxs("div",{onClick:s,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("img",{src:o?.photo||`https://ui-avatars.com/api/?name=${encodeURIComponent(Ne)}&background=e0e7ff&color=4f46e5`,alt:"Profile",className:"w-full h-full object-cover"})}),e.jsx("span",{className:"text-[13px] font-semibold text-[#1e293b]",children:Ne})]})]})]})}),e.jsx("main",{className:`flex-1 flex flex-col ${n==="intervention"||n==="analytics"?"overflow-hidden":"overflow-y-auto"}`,children:e.jsxs(zt,{mode:"wait",children:[n==="dashboard"&&e.jsx(ap,{classes:oe,liveActivity:Re,onViewClass:Lt,onViewAllClasses:()=>i("analytics"),onViewActivityStudent:M=>{const F=H.find(ve=>ve.name===M);F&&rs(F)},dailyInsight:Pe,insightLoading:Y,isInsightDismissed:y,onDismissInsight:()=>q(!0),onOpenInsightModal:()=>{re(!0),q(!0)},totalStudents:$e,totalAtRisk:Ge,avgPerformance:ft,onCreateClass:()=>g(!0)}),n==="analytics"&&B&&e.jsx(op,{selectedClass:B,students:Me,allClasses:de,riskDistribution:Nt,topicPerformance:jt,onViewStudent:rs,onCreateAccount:ns,onReassignSection:os,reassignBusyId:ae,onBack:()=>w(null),teacherOptions:j,managerUpdating:T,onAssignManager:M=>Bs(B,M),onOpenNotifications:()=>i("notifications"),onOpenProfile:s,classColor:kt,insightDismissed:y,onOpenInsightModal:()=>re(!0),onAddStudents:()=>z(!0),onRemoveStudent:L}),n==="analytics"&&!B&&oe.length>0&&e.jsx(Wo,{classes:oe,onSelectClass:Lt,onOpenNotifications:()=>i("notifications"),onOpenProfile:s,insightDismissed:y,onOpenInsightModal:()=>re(!0),onCreateClass:()=>g(!0)}),n==="analytics"&&!B&&oe.length===0&&e.jsx(Le.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},exit:{opacity:0,y:-20},className:"p-6",children:e.jsxs("div",{className:"bg-card border border-border rounded-2xl p-8 shadow-sm max-w-2xl",children:[e.jsx("div",{className:"w-12 h-12 rounded-xl bg-[#9956DE]/20 text-[#9956DE] flex items-center justify-center mb-4",children:e.jsx(Ls,{size:24})}),e.jsx("h2",{className:"text-2xl font-display font-semibold text-foreground mb-2",children:"Class Analytics"}),e.jsx("p",{className:"text-sm text-muted-foreground font-body leading-relaxed mb-4",children:"No classes available yet. Create a class or import class records to unlock analytics views."}),e.jsxs(St,{onClick:()=>g(!0),className:"bg-[#9956DE] hover:bg-[#7c3aed] text-white",children:[e.jsx(da,{size:16,className:"mr-1.5"}),"Create Class"]})]})}),n==="intervention"&&$&&e.jsx(ip,{student:$,teacherId:r?.uid||"",teacherName:Ne,initialCache:Je.current.get($.id),onCacheUpdate:(M,F)=>Je.current.set(M,F),onStudentUpdated:M=>{const F=$?ln($):null;A(M),ee(ve=>ve.map(we=>{const qe=ln(we),je=F?qe===F:!1,yt=we.id===M.id&&ct(we.classSectionId)===ct(M.classSectionId);return je||yt?M:we}))},onBack:Ts,onNavigateToQuizMaker:M=>{i("quiz_maker"),M&&sessionStorage.setItem("quizMakerInitialTab",M)}}),n==="topic_mastery"&&e.jsx(Tm,{classSectionId:We,onOpenNotifications:()=>i("notifications"),onOpenProfile:s}),n==="competency"&&B&&e.jsx(Mm,{classSectionId:We,className:C?.name,fallbackStudents:H,onBack:()=>w(null),onOpenNotifications:()=>i("notifications"),onOpenProfile:s,insightDismissed:y,onOpenInsightModal:()=>re(!0)}),n==="competency"&&!B&&de.length>0&&e.jsx(Wo,{classes:oe,onSelectClass:M=>w(M),onOpenNotifications:()=>i("notifications"),onOpenProfile:s,insightDismissed:y,onOpenInsightModal:()=>re(!0),viewType:"competency"}),n==="competency"&&!B&&de.length===0&&e.jsx(sp,{icon:us,title:"Student Competency",description:"No classes available yet. Import class records to view competency breakdowns."}),n==="import"&&e.jsxs(e.Fragment,{children:[e.jsx(Qx,{classSectionId:We,className:C?.name,classMetadata:C?.classMetadata,students:H,classes:oe.map(M=>({id:M.id,name:M.name,classSectionId:M.classSectionId})),teacherId:r?.uid||"",teacherName:Ne,onStudentsUpdated:M=>ee(M),onBackToClasses:()=>i("dashboard"),onOpenNotifications:()=>i("notifications"),onOpenProfile:s,onOpenInsightModal:()=>{re(!0),q(!0)},userPhoto:o?.photo,onImportedClassRecords:M=>{const F=M.students.map(se=>tp(se,M.classSectionId,M.className,M.classMetadata)),ve=Ct({metadata:M.classMetadata,classSectionId:M.classSectionId,className:M.className}),we=ve.classSectionId||"imported_class",qe=ve.className||"Imported Class",je=F.filter(se=>se.riskLevel==="high").length,yt=F.length>0?Math.round(F.reduce((se,rt)=>se+rt.avgScore,0)/F.length):0,lt={id:we,name:qe,classSectionId:we,classMetadata:{...ve,classSectionId:we,className:qe},schedule:"Mon-Fri",studentCount:F.length,avgScore:yt,atRiskCount:je,riskLevel:je>=5?"high":je>=2?"medium":"low"};ee(se=>oi(se,F)),fe(se=>ni(se,[lt]))},onDataChanged:()=>D(M=>M+1)}),e.jsx("div",{className:"mt-6",children:e.jsx(Wx,{teacherId:r?.uid||""})})]}),n==="notifications"&&e.jsx(Lm,{liveActivity:Re,atRiskStudents:H.filter(M=>M.riskLevel==="high").map(M=>({name:M.name,riskLevel:M.riskLevel,weakestTopic:M.weakestTopic})),onOpenNotifications:()=>i("notifications"),onOpenProfile:s,onOpenInsightModal:()=>{re(!0),q(!0)},userPhoto:o?.photo,teacherName:Ne}),n==="calendar"&&e.jsx(qm,{classes:de,teacherId:r?.uid}),n==="quiz_maker"&&e.jsx(fl,{onBack:()=>{const M=sessionStorage.getItem("quizMakerReturnTo");sessionStorage.removeItem("quizMakerReturnTo"),sessionStorage.removeItem("quizMakerInitialTab"),i(M==="intervention"?"intervention":"dashboard")},onOpenNotifications:()=>i("notifications"),onOpenProfile:s,onOpenInsightModal:()=>{re(!0),q(!0)},userPhoto:o?.photo,teacherName:Ne}),n==="question_bank"&&e.jsx(Cm,{onOpenNotifications:()=>i("notifications"),onOpenProfile:s,onOpenInsightModal:()=>{re(!0),q(!0)},userPhoto:o?.photo,teacherName:Ne})]})})]}),n==="dashboard"&&!b&&e.jsx(li,{onViewCalendar:()=>i("calendar"),onOpenProfile:s,userProfile:o,teacherName:Ne,liveActivity:Re})]}),e.jsx(zt,{children:b&&n==="dashboard"&&be&&e.jsxs(e.Fragment,{children:[e.jsx(Le.button,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.2},className:"fixed inset-0 z-40 bg-slate-900/40 backdrop-blur-[2px]","aria-label":"Close calendar panel",onClick:()=>Ie(!1)},"cal-backdrop"),e.jsx(Le.div,{initial:{x:"100%"},animate:{x:0},exit:{x:"100%"},transition:{type:"spring",stiffness:320,damping:32},className:"fixed top-0 right-0 bottom-0 z-50 w-[300px] max-w-[85vw] shadow-2xl",children:e.jsx(li,{onViewCalendar:()=>{i("calendar"),Ie(!1)},onOpenProfile:()=>{s?.(),Ie(!1)},userProfile:o,teacherName:Ne,liveActivity:Re})},"cal-drawer")]})}),e.jsx(zt,{children:J&&e.jsx("div",{className:"fixed inset-0 bg-slate-900/40 backdrop-blur-sm z-50 flex items-center justify-center p-4",children:e.jsxs(Le.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.95},className:"bg-white rounded-2xl shadow-xl w-full max-w-lg overflow-hidden border border-slate-200",children:[e.jsxs("div",{className:"p-4 border-b border-slate-100 flex items-center justify-between bg-slate-50/50",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-indigo-100 flex items-center justify-center text-indigo-600",children:e.jsx(ps,{size:16})}),e.jsx("h3",{className:"font-semibold text-slate-800",children:"Detailed AI Insight"})]}),e.jsx("button",{onClick:()=>{re(!1)},className:"p-2 text-slate-400 hover:text-slate-600 hover:bg-slate-100 rounded-full transition-colors",children:e.jsx(Xt,{size:18})})]}),e.jsx("div",{className:"p-6",children:e.jsx("div",{className:"text-sm text-slate-600 leading-relaxed",children:e.jsx(kc,{children:Pe?.replace(/[*_]*\s*\(?Word\s*count\s*:\s*[*_]*\s*\d+\)?\s*[*_]*/gi,"").trim()||`**${Ge} students (${$e>0?Math.round(Ge/$e*100):0}%)** are currently at high risk of falling behind in recent topics. Review their progress in the analytics view to plan interventions.`})})}),e.jsx("div",{className:"p-4 border-t border-slate-100 bg-slate-50 flex justify-end gap-2",children:e.jsx("button",{onClick:()=>{re(!1)},className:"px-4 py-2 text-sm font-medium text-slate-600 hover:text-slate-800 hover:bg-slate-200 rounded-lg transition-colors",children:"Minimize to Menu"})})]})})}),e.jsx(Yl,{isOpen:k,onClose:()=>N(!1),onConfirm:t,title:"Logout",message:"Are you sure you want to logout?",confirmText:"Logout",cancelText:"Cancel"}),e.jsx(tm,{open:v,onClose:()=>g(!1),onCreated:()=>D(M=>M+1),teacherName:Ne}),e.jsx(sm,{open:I,onClose:()=>z(!1),onAdded:()=>D(M=>M+1),grade:B?.gradeLevel||B?.classMetadata?.grade||"Grade 11",section:B?.classMetadata?.section||B?.name?.split(" - ")[1]||"",teacherName:Ne,existingStudentUids:Me.map(M=>M.id)}),e.jsx(Kx,{isOpen:!!ue,onClose:()=>ce(null),seed:ue,adviserTeacherId:r?.uid||"",adviserTeacherName:Ne,schoolYear:ue?H.find(M=>M.id===ue.rosterId)?.classMetadata?.schoolYear||String(new Date().getFullYear()):void 0,onCreated:vs})]})},Es=({icon:t,label:s,active:a,collapsed:r,forceExpanded:o=!1,onClick:n})=>e.jsxs(Le.button,{onClick:n,whileHover:{x:2},whileTap:{scale:.98},className:`w-full flex items-center gap-3 px-4 py-3 rounded-2xl cursor-pointer transition-all duration-200 border whitespace-nowrap ${r&&!o?"justify-center":""} ${a?"bg-[#9956DE]/12 border-[#9956DE]/30 shadow-sm text-[#9956DE]":"bg-transparent border-transparent text-[#5a6578] hover:bg-[#dde3eb] hover:border-[#dde3eb] hover:text-[#0a1628]"}`,children:[e.jsx(t,{size:18,strokeWidth:a?2.5:2,className:"flex-shrink-0"}),(!r||o)&&e.jsx("span",{className:"font-body font-semibold text-xs",children:s}),a&&!r&&e.jsx(Le.div,{layoutId:"sidebar-active-indicator",className:"ml-auto w-2 h-2 rounded-full bg-[#9956DE]",transition:{type:"spring",duration:.4}})]}),sp=({icon:t,title:s,description:a})=>e.jsx(Le.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},exit:{opacity:0,y:-20},className:"p-6",children:e.jsxs("div",{className:"bg-card border border-border rounded-2xl p-8 shadow-sm max-w-2xl",children:[e.jsx("div",{className:"w-12 h-12 rounded-xl bg-[#9956DE]/20 text-[#9956DE] flex items-center justify-center mb-4",children:e.jsx(t,{size:24})}),e.jsx("h2",{className:"text-2xl font-display font-semibold text-foreground mb-2",children:s}),e.jsx("p",{className:"text-sm text-muted-foreground font-body leading-relaxed",children:a})]})}),ap=({classes:t,liveActivity:s,onViewClass:a,onViewAllClasses:r,onViewActivityStudent:o,dailyInsight:n,insightLoading:i,isInsightDismissed:l,onDismissInsight:c,onOpenInsightModal:d,totalStudents:m,totalAtRisk:p,avgPerformance:h,onCreateClass:b})=>{const S=m>0?Math.round(p/m*100):0,k=m>0?Math.round((m-p)/m*100):0;return e.jsxs(Le.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},exit:{opacity:0,y:-20},className:"p-3 sm:p-6 space-y-4",children:[!l&&n&&e.jsxs("div",{onClick:d,className:"bg-white/80 backdrop-blur-[12px] rounded-[18px] border border-white p-[14px_16px] sm:p-[18px_20px] flex flex-col sm:flex-row items-start sm:items-center gap-3 sm:gap-4 shadow-[0_1px_4px_rgba(0,0,0,0.04)] cursor-pointer hover:shadow-md transition-shadow group",children:[e.jsxs("div",{className:"relative flex-shrink-0",children:[e.jsx("div",{className:"absolute -inset-[5px] rounded-full border-2 border-[#a5b4fc] opacity-50 animate-pulse"}),e.jsx("div",{className:"w-[46px] h-[46px] rounded-full bg-[#eef2ff] border-2 border-[#c7d2fe] flex items-center justify-center text-[#4f46e5] text-xl relative overflow-hidden group-hover:scale-[1.05] transition-transform",children:e.jsx("img",{src:"/avatar/avatar_icon.png",alt:"AI Mascot",className:"w-[85%] h-[85%] object-contain"})})]}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"text-[13.5px] font-semibold text-[#1e1b4b] flex flex-wrap items-center gap-2 mb-1",children:[e.jsx(ps,{size:14,className:"text-[#818cf8]"}),"MathPulse AI insight",e.jsx("span",{className:"bg-[#fee2e2] text-[#b91c1c] text-[10px] font-semibold px-2 py-0.5 rounded-full border border-[#fca5a5]",children:"Attention needed"})]}),e.jsx("div",{className:"text-[12.5px] text-[#475569] leading-[1.55]",children:"Some students may be at risk of falling behind. Click to view detailed analysis."})]}),e.jsxs("div",{className:"flex gap-2 flex-shrink-0 self-end sm:self-auto",children:[e.jsx("button",{onClick:N=>{N.stopPropagation(),c()},className:"px-[15px] py-[7px] rounded-[10px] text-xs font-medium cursor-pointer border border-[#e2e8f0] bg-white text-[#475569] hover:bg-[#f8fafc] transition-colors",children:"Dismiss"}),e.jsx("button",{onClick:N=>{N.stopPropagation(),r()},className:"px-[15px] py-[7px] rounded-[10px] text-xs font-medium cursor-pointer border border-[#4f46e5] bg-[#4f46e5] text-white shadow-[0_2px_8px_rgba(79,70,229,0.13)] hover:bg-[#4338ca] transition-colors",children:"Review students"})]})]}),e.jsxs("div",{className:"grid grid-cols-4 gap-1.5 sm:gap-3",children:[e.jsxs("div",{className:"group relative overflow-hidden bg-[#10b981] shadow-[0_4px_16px_rgba(16,185,129,0.13)] rounded-sm sm:rounded-lg p-[10px] sm:p-[15px] text-white flex flex-col gap-[6px] sm:gap-[10px]",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-500 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-500 delay-75 ease-out"}),e.jsxs("div",{className:"relative z-10 flex justify-between items-start",children:[e.jsx("span",{className:"text-[9px] sm:text-[11px] opacity-90 leading-tight",children:"Total students"}),e.jsx("div",{className:"hidden sm:flex bg-white/20 p-1.5 rounded-lg",children:e.jsx(us,{size:15})})]}),e.jsx("div",{className:"relative z-10 text-[18px] sm:text-[26px] font-semibold tracking-tight",children:m}),e.jsxs("div",{className:"relative z-10 border-t border-white/30 pt-1.5 sm:pt-2 flex justify-between items-center text-[9px] sm:text-[10px] opacity-90",children:[e.jsx("span",{className:"hidden sm:block",children:"Added this year"}),e.jsx("span",{className:"bg-black/15 px-[5px] sm:px-[7px] py-[2px] rounded font-semibold",children:m>0?"+1":"0"})]})]}),e.jsxs("div",{className:"group relative overflow-hidden bg-[#0ea5e9] shadow-[0_4px_16px_rgba(14,165,233,0.13)] rounded-sm sm:rounded-lg p-[10px] sm:p-[15px] text-white flex flex-col gap-[6px] sm:gap-[10px]",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-500 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-500 delay-75 ease-out"}),e.jsxs("div",{className:"relative z-10 flex justify-between items-start",children:[e.jsx("span",{className:"text-[9px] sm:text-[11px] opacity-90 leading-tight",children:"Class average"}),e.jsx("div",{className:"hidden sm:flex bg-white/20 p-1.5 rounded-lg",children:e.jsx(ms,{size:15})})]}),e.jsxs("div",{className:"relative z-10 text-[18px] sm:text-[26px] font-semibold tracking-tight",children:[h,"%"]}),e.jsxs("div",{className:"relative z-10 border-t border-white/30 pt-1.5 sm:pt-2 flex justify-between items-center text-[9px] sm:text-[10px] opacity-90",children:[e.jsx("span",{className:"hidden sm:block",children:"Vs. last month"}),e.jsx("span",{className:"bg-black/15 px-[5px] sm:px-[7px] py-[2px] rounded font-semibold",children:"+2.5%"})]})]}),e.jsxs("div",{className:"group relative overflow-hidden bg-[#a855f7] shadow-[0_4px_16px_rgba(168,85,247,0.13)] rounded-sm sm:rounded-lg p-[10px] sm:p-[15px] text-white flex flex-col gap-[6px] sm:gap-[10px]",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-500 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-500 delay-75 ease-out"}),e.jsxs("div",{className:"relative z-10 flex justify-between items-start",children:[e.jsx("span",{className:"text-[9px] sm:text-[11px] opacity-90 leading-tight",children:"Engage­ment"}),e.jsx("div",{className:"hidden sm:flex bg-white/20 p-1.5 rounded-lg",children:e.jsx(bi,{size:15})})]}),e.jsxs("div",{className:"relative z-10 text-[18px] sm:text-[26px] font-semibold tracking-tight",children:[k,"%"]}),e.jsxs("div",{className:"relative z-10 border-t border-white/30 pt-1.5 sm:pt-2 flex justify-between items-center text-[9px] sm:text-[10px] opacity-90",children:[e.jsx("span",{className:"hidden sm:block",children:"Active participants"}),e.jsx("span",{className:"bg-black/15 px-[5px] sm:px-[7px] py-[2px] rounded font-semibold",children:Math.round(k/100*m)})]})]}),e.jsxs("div",{className:"group relative overflow-hidden bg-[#f97316] shadow-[0_4px_16px_rgba(249,115,22,0.13)] rounded-sm sm:rounded-lg p-[10px] sm:p-[15px] text-white flex flex-col gap-[6px] sm:gap-[10px]",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-500 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-500 delay-75 ease-out"}),e.jsxs("div",{className:"relative z-10 flex justify-between items-start",children:[e.jsx("span",{className:"text-[9px] sm:text-[11px] opacity-90 leading-tight",children:"At risk"}),e.jsx("div",{className:"hidden sm:flex bg-white/20 p-1.5 rounded-lg",children:e.jsx(br,{size:15})})]}),e.jsx("div",{className:"relative z-10 text-[18px] sm:text-[26px] font-semibold tracking-tight",children:p}),e.jsxs("div",{className:"relative z-10 border-t border-white/30 pt-1.5 sm:pt-2 flex justify-between items-center text-[9px] sm:text-[10px] opacity-90",children:[e.jsx("span",{className:"hidden sm:block",children:"Requires attention"}),e.jsxs("span",{className:"bg-black/15 px-[5px] sm:px-[7px] py-[2px] rounded font-semibold",children:[S,"%"]})]})]})]}),e.jsxs("div",{className:"bg-white/80 backdrop-blur-[12px] rounded-[18px] border border-white p-[18px_20px] shadow-[0_1px_4px_rgba(0,0,0,0.04)]",children:[e.jsxs("div",{className:"flex justify-between items-center mb-[14px]",children:[e.jsx("h2",{className:"text-[15px] font-semibold text-[#1e293b]",children:"My classes"}),e.jsx("span",{onClick:r,className:"text-[12px] text-[#10b981] font-semibold cursor-pointer hover:underline",children:"View all"})]}),e.jsxs("div",{className:"space-y-[9px]",children:[t.length===0&&e.jsxs("div",{className:"text-center py-4",children:[e.jsx("p",{className:"text-sm text-slate-500 mb-3",children:"No classes imported yet."}),b&&e.jsx("button",{onClick:b,className:"text-sm text-[#9956DE] font-semibold hover:underline",children:"+ Create a class"})]}),t.map((N,v)=>{const g=[{bg:"bg-[#f3e8ff]",text:"text-[#a855f7]",borderHover:"hover:border-[#d8b4fe]",stripe:"bg-[#a855f7]"},{bg:"bg-[#eff6ff]",text:"text-[#3b82f6]",borderHover:"hover:border-[#bfdbfe]",stripe:"bg-[#3b82f6]"},{bg:"bg-[#f0fdf4]",text:"text-[#22c55e]",borderHover:"hover:border-[#bbf7d0]",stripe:"bg-[#22c55e]"},{bg:"bg-[#fff7ed]",text:"text-[#f97316]",borderHover:"hover:border-[#fed7aa]",stripe:"bg-[#f97316]"},{bg:"bg-[#fff1f2]",text:"text-[#f43f5e]",borderHover:"hover:border-[#fecdd3]",stripe:"bg-[#f43f5e]"}],I=g[v%g.length];return e.jsxs("div",{onClick:()=>a(N),className:`relative overflow-hidden flex items-center gap-3 p-[12px_13px] pl-[16px] border border-[#f1f5f9] rounded-[14px] cursor-pointer ${I.borderHover} hover:shadow-[0_2px_10px_rgba(0,0,0,0.04)] hover:bg-[#fafbff] transition-all group`,children:[e.jsx("div",{className:`absolute left-0 top-0 bottom-0 w-[5px] ${I.stripe}`}),e.jsx("div",{className:`w-[38px] h-[38px] rounded-[10px] flex items-center justify-center flex-shrink-0 text-[17px] ${I.bg} ${I.text} group-hover:scale-110 transition-transform duration-300`,children:e.jsx(Gt,{size:18})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-[12.5px] font-medium text-[#1e293b]",children:N.name}),e.jsx("div",{className:"text-[11px] text-[#94a3b8] mt-[1px]",children:N.classification||"High School"})]}),e.jsx("div",{className:"hidden sm:block text-[12px] text-[#64748b] min-w-[65px]",children:N.schedule||"Mon-Fri"}),e.jsxs("div",{className:"hidden sm:block text-[12px] text-[#64748b] min-w-[85px]",children:[N.studentCount," students"]}),e.jsx("span",{className:`text-[10px] font-semibold px-[9px] py-[3px] rounded-[6px] ${N.riskLevel==="high"?"bg-[#fee2e2] text-[#b91c1c] border border-[#fca5a5]":N.riskLevel==="medium"?"bg-[#fffbeb] text-[#b45309] border border-[#fcd34d]":"bg-[#ecfdf5] text-[#065f46] border border-[#6ee7b7]"}`,children:N.riskLevel==="high"?"High risk":N.riskLevel==="medium"?"Medium risk":"On track"}),e.jsx(Yr,{size:16,className:"text-[#cbd5e1] ml-auto hover:text-[#64748b]"})]},N.id)})]})]})]})},rp=he.memo(({student:t,onViewStudent:s,onCreateAccount:a,onRemoveStudent:r})=>{const n=t.riskLevel==="high"?{borderLeft:"border-l-rose-500",bgAvatar:"bg-rose-50 text-rose-600 border-rose-100/50",badge:"text-rose-600 bg-rose-50",progress:"bg-rose-500"}:t.riskLevel==="medium"?{borderLeft:"border-l-amber-500",bgAvatar:"bg-amber-50 text-amber-600 border-amber-100/50",badge:"text-amber-600 bg-amber-50",progress:"bg-amber-500"}:{borderLeft:"border-l-emerald-500",bgAvatar:"bg-emerald-50 text-emerald-600 border-emerald-100/50",badge:"text-emerald-600 bg-emerald-50",progress:"bg-emerald-500"},i=t.hasRegisteredAccount===!1&&t.source==="import",l=t.hasRegisteredAccount===!0;return e.jsxs("div",{onClick:()=>s(t),className:`p-[12px] bg-white rounded-[14px] shadow-[0_1px_4px_rgba(0,0,0,0.04)] border border-[#f1f5f9] border-l-[4px] ${n.borderLeft} hover:scale-[1.02] transition-transform cursor-pointer group flex flex-col justify-between`,children:[e.jsxs("div",{className:"flex justify-between items-start mb-[10px]",children:[e.jsxs("div",{className:"flex gap-[8px] items-center min-w-0 pr-2",children:[t.avatar?e.jsx("img",{src:t.avatar,alt:t.name,className:`w-8 h-8 rounded-full border ${n.bgAvatar.split(" ")[2]} object-cover shrink-0`}):e.jsx("div",{className:`w-8 h-8 rounded-full flex items-center justify-center font-semibold text-[11px] shrink-0 border ${n.bgAvatar}`,children:t.name.substring(0,2).toUpperCase()}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("p",{className:"text-[13px] font-semibold text-[#1e293b] leading-tight truncate",children:t.name}),l&&e.jsx("span",{title:"Registered student account",className:"w-1.5 h-1.5 rounded-full bg-emerald-500 shrink-0"})]}),e.jsxs("p",{className:"text-[10px] text-[#64748b] flex items-center gap-[4px] mt-0.5 truncate",children:[e.jsx(As,{className:"w-[10px] h-[10px] shrink-0"})," ",t.lastActive||"recently"]})]})]}),e.jsxs("span",{className:`font-semibold text-[11px] px-[6px] py-[2px] rounded-[14px] shrink-0 ${n.badge}`,children:[t.avgScore,"%"]}),r&&e.jsx("button",{type:"button",onClick:c=>{c.stopPropagation(),r(t)},className:"opacity-0 group-hover:opacity-100 transition-opacity text-slate-400 hover:text-red-500 p-1 rounded shrink-0","aria-label":`Remove ${t.name} from class`,title:"Remove from class",children:e.jsx(Xt,{size:14})})]}),i&&e.jsxs("div",{className:"flex items-center justify-between gap-2 mb-2 px-2 py-1 rounded-[10px] bg-amber-50 border border-amber-100/80",children:[e.jsx("span",{className:"text-[10px] font-semibold text-amber-700 uppercase tracking-wider",children:"No Account"}),a&&e.jsxs("button",{type:"button",onClick:c=>{c.stopPropagation(),a(t)},className:"flex items-center gap-1 px-2 py-0.5 rounded-full bg-white text-amber-700 border border-amber-200 hover:bg-amber-100 text-[10px] font-semibold transition-colors","aria-label":`Create system account for ${t.name}`,children:[e.jsx("span",{"aria-hidden":!0,children:"+"}),"Create"]})]}),e.jsx("div",{className:"w-full bg-[#f1f5f9] h-1.5 rounded-full overflow-hidden mt-auto",children:e.jsx("div",{className:`h-full rounded-full ${n.progress}`,style:{width:`${t.avgScore}%`}})})]})}),np=({students:t,allClasses:s,currentClass:a,onReassignSection:r,reassignBusyId:o})=>{const[n,i]=u.useState(!1),l=u.useMemo(()=>{const d=new Map;return s.forEach(m=>{const p=(m.classSectionId||m.id||"").trim();if(!p)return;const h=(m.classMetadata?.grade||"").trim(),b=(m.classMetadata?.section||"").trim();if(!h||!b)return;const S=m.name||`${h} - ${b}`;d.set(p,{classSectionId:p,grade:h,section:b,label:S})}),Array.from(d.values()).sort((m,p)=>m.label.localeCompare(p.label))},[s]),c=u.useMemo(()=>{const d=new Map,m=[];return t.forEach(p=>{const h=(p.classSectionId||"").trim();if(!h){m.push(p);return}const b=p.section||p.className||h,S=d.get(h)||{label:b,students:[]};S.students=[...S.students,p],d.set(h,S)}),{assigned:Array.from(d.entries()).map(([p,h])=>({sectionId:p,...h})).sort((p,h)=>p.label.localeCompare(h.label)),unassigned:m}},[t]);return e.jsxs("div",{className:"bg-white/80 backdrop-blur-[12px] rounded-[18px] border border-white shadow-[0_1px_4px_rgba(0,0,0,0.04)] overflow-hidden",children:[e.jsxs("button",{type:"button",onClick:()=>i(d=>!d),className:"w-full flex items-center justify-between px-6 py-4 text-left","aria-expanded":n,children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-[15px] font-semibold text-[#1e293b]",children:"Section Management"}),e.jsxs("p",{className:"text-[12px] text-[#64748b] mt-0.5",children:["Move students between sections. Showing ",t.length," students across ",c.assigned.length," section",c.assigned.length===1?"":"s",c.unassigned.length>0?` · ${c.unassigned.length} unassigned`:"","."]})]}),e.jsx($t,{className:`w-4 h-4 text-[#64748b] transition-transform ${n?"rotate-180":""}`})]}),n&&e.jsxs("div",{className:"border-t border-[#f1f5f9] divide-y divide-[#f1f5f9]",children:[c.assigned.length===0&&c.unassigned.length===0&&e.jsx("p",{className:"text-[12px] text-[#64748b] px-6 py-5",children:"No students yet. Add students to this teacher to manage section assignments."}),c.assigned.map(d=>e.jsxs("div",{className:"px-6 py-4",children:[e.jsxs("p",{className:"text-[11px] font-semibold uppercase tracking-wider text-[#64748b] mb-2",children:[d.label," ",e.jsxs("span",{className:"text-[10px] font-normal text-[#94a3b8]",children:["(",d.students.length,")"]})]}),e.jsx("div",{className:"space-y-1.5",children:d.students.map(m=>e.jsx(ii,{student:m,sectionTargets:l,currentSectionId:a.classSectionId,onReassign:r,isBusy:o===m.id},`section-row-${m.id}`))})]},d.sectionId)),c.unassigned.length>0&&e.jsxs("div",{className:"px-6 py-4 bg-amber-50/40",children:[e.jsxs("p",{className:"text-[11px] font-semibold uppercase tracking-wider text-amber-700 mb-2",children:["Unassigned ",e.jsxs("span",{className:"text-[10px] font-normal text-amber-600/80",children:["(",c.unassigned.length,")"]})]}),e.jsx("div",{className:"space-y-1.5",children:c.unassigned.map(d=>e.jsx(ii,{student:d,sectionTargets:l,currentSectionId:a.classSectionId,onReassign:r,isBusy:o===d.id},`section-row-${d.id}`))})]})]})]})},ii=({student:t,sectionTargets:s,currentSectionId:a,onReassign:r,isBusy:o})=>{const[n,i]=u.useState(t.classSectionId||"");u.useEffect(()=>{i(t.classSectionId||"")},[t.classSectionId]);const l=()=>{const d=s.find(m=>m.classSectionId===n);d&&d.classSectionId!==t.classSectionId&&r(t,d)},c=n===(t.classSectionId||"");return e.jsxs("div",{className:"flex flex-col md:flex-row md:items-center gap-2 md:gap-3 px-3 py-2 rounded-[12px] bg-white border border-[#f1f5f9]",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-[13px] font-semibold text-[#1e293b] truncate",children:t.name}),e.jsxs("p",{className:"text-[11px] text-[#64748b] truncate",children:[t.lrn?`LRN ${t.lrn} · `:"",t.classMetadata?.className||t.className||"Unassigned section",a&&t.classSectionId===a?" · current":""]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("select",{value:n,onChange:d=>i(d.target.value),disabled:o||s.length===0,className:"text-[12px] rounded-xl border border-[#dde3eb] bg-white px-3 py-1.5 text-[#0a1628] focus:border-indigo-500 focus:outline-none focus:ring-2 focus:ring-indigo-200 disabled:opacity-60",children:[e.jsx("option",{value:"",children:"Select section…"}),s.map(d=>e.jsx("option",{value:d.classSectionId,children:d.label},d.classSectionId))]}),e.jsx("button",{type:"button",onClick:l,disabled:o||c||!n,className:"text-[12px] font-semibold rounded-xl px-3 py-1.5 bg-indigo-600 text-white hover:bg-indigo-700 transition-colors disabled:opacity-50 disabled:hover:bg-indigo-600",children:o?"Saving…":"Move"})]})]})},op=({selectedClass:t,students:s,allClasses:a,riskDistribution:r,topicPerformance:o,onViewStudent:n,onCreateAccount:i,onReassignSection:l,reassignBusyId:c,onBack:d,teacherOptions:m,managerUpdating:p,onAssignManager:h,onOpenNotifications:b,onOpenProfile:S,classColor:k,insightDismissed:N,onOpenInsightModal:v,onAddStudents:g,onRemoveStudent:I})=>{const{currentUser:z,userProfile:R}=hs(),[W,f]=u.useState(""),[C,w]=u.useState(""),[$,A]=u.useState("All"),[y,q]=u.useState(null),[J,re]=u.useState(!0),[le,ne]=u.useState(!1),[be,Ie]=u.useState(!0);u.useEffect(()=>{let j=!1;return re(!0),Mo(t.id).then(_=>{j||q(_)}).catch(_=>console.warn("[AnalyticsView] Backend fetch failed, using local data:",_)).finally(()=>{j||re(!1)}),()=>{j=!0}},[t.id]),u.useEffect(()=>{let j,_;return(async()=>{try{const{collection:T,onSnapshot:Q}=await Ss(async()=>{const{collection:Ce,onSnapshot:Ne}=await import("./vendor-firebase-firestore-CNv3xXal.js");return{collection:Ce,onSnapshot:Ne}},__vite__mapDeps([2,3])),{db:ue}=await Ss(async()=>{const{db:Ce}=await import("./index-Bp7MiGcW.js").then(Ne=>Ne.b7);return{db:Ce}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11])),ce=T(ue,"classes",t.id,"student_summaries");let ae=!0;j=Q(ce,()=>{if(ae){ae=!1;return}_&&clearTimeout(_),_=setTimeout(()=>{Mo(t.id).then(q).catch(()=>{})},2e3)})}catch{}})(),()=>{j?.(),_&&clearTimeout(_)}},[t.id]);const[de,fe]=u.useState(new Map);u.useEffect(()=>{let j=!1;const _=s.filter(T=>T.accountUid||T.hasRegisteredAccount);if(_.length!==0)return(async()=>{try{const{doc:T,getDoc:Q}=await Ss(async()=>{const{doc:Ce,getDoc:Ne}=await import("./vendor-firebase-firestore-CNv3xXal.js");return{doc:Ce,getDoc:Ne}},__vite__mapDeps([2,3])),{db:ue}=await Ss(async()=>{const{db:Ce}=await import("./index-Bp7MiGcW.js").then(Ne=>Ne.b7);return{db:Ce}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11])),ce=new Map,ae=_.slice(0,50);await Promise.all(ae.map(async Ce=>{const Ne=Ce.accountUid||Ce.id;try{const Je=await Q(T(ue,"progress",Ne));if(Je.exists()){const Ge=Je.data().averageScore||0;Ge>0&&ce.set(Ce.id,Ge)}}catch{}})),j||fe(ce)}catch{}})(),()=>{j=!0}},[s]);const H=y!=null&&y.students.some(j=>j.quiz_attempt_count>0),ee=(()=>{if(H)return y.class_average;if(t.avgScore>0)return t.avgScore;if(s.length===0)return 0;const j=s.map(_=>de.get(_.id)||_.avgScore).filter(_=>_>0);return j.length>0?Math.round(j.reduce((_,T)=>_+T,0)/j.length):0})(),oe=(()=>{if(H)return y.completion_rate;if(s.length===0)return 0;const j=s.filter(_=>de.has(_.id)||_.assignmentCompletion>0).length;return Math.round(j/s.length*100)})(),Re=(()=>{if(H)return y.participation_rate;if(s.length===0)return 0;const j=s.filter(_=>de.has(_.id)||_.engagementScore>0||_.avgScore>0).length;return s.length>0?Math.round(j/s.length*100):0})(),Fe=y?.insights?.risk_distribution?[{name:"Critical",value:y.insights.risk_distribution.Critical||0,color:"#dc2626"},{name:"High Risk",value:y.insights.risk_distribution["High Risk"]||0,color:"#f43f5e"},{name:"Medium Risk",value:y.insights.risk_distribution["Medium Risk"]||0,color:"#f59e0b"},{name:"Low Risk",value:y.insights.risk_distribution["Low Risk"]||0,color:"#10b981"},{name:"Unassessed",value:y.insights.risk_distribution.Unassessed||0,color:"#94a3b8"}].filter(j=>j.value>0):[{name:"High Risk",value:s.filter(j=>j.riskLevel==="high").length,color:"#FF8B8B"},{name:"Medium Risk",value:s.filter(j=>j.riskLevel==="medium").length,color:"#F08386"},{name:"Low Risk",value:s.filter(j=>j.riskLevel==="low").length,color:"#75D06A"}];u.useEffect(()=>{w(t.classMetadata?.managerId||t.managerId||"")},[t]);const Pe=u.useMemo(()=>{const j=W.trim().toLowerCase();let _=s;if(j&&(_=_.filter(T=>T.name.toLowerCase().includes(j)||(T.lrn||"").toLowerCase().includes(j)||(T.weakestTopic||"").toLowerCase().includes(j))),$==="Good")if(y){const T=new Set(y.students.filter(Q=>Q.quiz_attempt_count>0&&Q.avg_score>=75).map(Q=>Q.student_id));_=_.filter(Q=>T.has(Q.id))}else _=_.filter(T=>T.avgScore>=85&&T.riskLevel!=="high");else if($==="Risk")if(y){const T=new Set(y.students.filter(Q=>["High Risk","Critical","Unassessed"].includes(Q.risk_level)).map(Q=>Q.student_id));_=_.filter(Q=>T.has(Q.id))}else _=_.filter(T=>T.riskLevel==="high"||T.avgScore<75);return _},[W,s,$,y]),G=u.useMemo(()=>H?y.students.filter(j=>j.quiz_attempt_count>0).sort((j,_)=>_.avg_score-j.avg_score).slice(0,5).map(j=>{const _=s.find(T=>T.id===j.student_id);return _?{..._,avgScore:j.avg_score}:null}).filter(Boolean):[...s].map(j=>({...j,avgScore:de.get(j.id)||j.avgScore})).sort((j,_)=>_.avgScore-j.avgScore).slice(0,5),[s,y,H,de]),te=u.useMemo(()=>H?y.students.filter(j=>["High Risk","Critical"].includes(j.risk_level)).sort((j,_)=>j.avg_score-_.avg_score).map(j=>{const _=s.find(T=>T.id===j.student_id);return _?{..._,avgScore:j.avg_score,_backendRisk:j.risk_level}:null}).filter(Boolean):[...s].filter(j=>j.riskLevel==="high"||(de.get(j.id)||j.avgScore)<70||j.assignmentCompletion<65),[s,y,H,de]),E=u.useMemo(()=>y?.insights?.topic_performance?.length?y.insights.topic_performance.map(j=>({topic:j.topic,score:j.class_accuracy})):o,[y,o]),Y=j=>{if(H){const _=y.students.find(T=>T.student_id===j);if(_&&_.avg_score>0)return _.avg_score}return de.has(j)?de.get(j):null},V=j=>{if(!y)return null;const _=y.students.find(T=>T.student_id===j);return _?_.risk_level:null},pe=async()=>{ne(!0);try{const j=await am(t.id);q(_=>_&&{..._,insights:j})}catch(j){console.warn("[AnalyticsView] Refresh insights failed:",j?.message)}finally{ne(!1)}};u.useMemo(()=>m.find(j=>j.uid===C),[m,C]);const D=[t.classMetadata?.gradeLevel||t.gradeLevel,t.classMetadata?.classification||t.classification,t.classMetadata?.strand||t.strand].filter(Boolean);return e.jsxs(Le.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},exit:{opacity:0,y:-20},className:"p-3 sm:p-[24px] xl:p-[32px] space-y-3 sm:space-y-[24px] h-full overflow-y-auto",children:[e.jsx("div",{className:"flex items-center justify-between mb-3 sm:mb-6",children:e.jsxs("button",{onClick:d,className:"flex items-center gap-2 text-[13px] font-semibold text-[#4f46e5] hover:text-[#3730a3] transition-colors bg-white/60 hover:bg-white/80 px-[18px] py-2 rounded-full backdrop-blur-[12px] shadow-[0_1px_4px_rgba(0,0,0,0.04)] border border-white/50",children:[e.jsx(zs,{className:"w-4 h-4"}),"Back to Classes"]})}),e.jsxs("header",{style:{backgroundColor:k?.hex||"#6366f1"},className:"rounded-[24px] p-4 sm:p-[24px] lg:p-[32px] shadow-[0_8px_32px_rgba(0,0,0,0.08)] flex flex-col lg:flex-row lg:items-center justify-between gap-4 sm:gap-6 relative overflow-hidden group text-white",children:[e.jsx("div",{className:"absolute -right-10 -bottom-10 w-48 h-48 rounded-full bg-white/10 group-hover:scale-[1.3] transition-transform duration-700 ease-out pointer-events-none"}),e.jsx("div",{className:"absolute -left-10 -top-10 w-32 h-32 rounded-full bg-white/10 group-hover:scale-[1.2] transition-transform duration-700 delay-75 ease-out pointer-events-none"}),e.jsxs("div",{className:"shrink-0 relative z-10",children:[e.jsx("h1",{className:"text-xl sm:text-[28px] font-bold mb-2 sm:mb-3 tracking-tight",children:t.name}),e.jsx("div",{className:"flex flex-wrap items-center gap-2 mb-3",children:D.map((j,_)=>e.jsx("span",{className:"px-3 py-1 bg-white/20 backdrop-blur-md text-white text-[12px] font-semibold rounded-full shadow-sm border border-white/20",children:j},j))}),e.jsxs("p",{className:"text-[13px] text-white/80 font-medium",children:["Manager: ",t.classMetadata?.managerName||t.managerName||"Not assigned"]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-2 sm:gap-[18px] w-full",children:[e.jsxs("div",{className:"group relative overflow-hidden bg-[#0ea5e9] shadow-[0_4px_16px_rgba(14,165,233,0.13)] rounded-lg sm:rounded-2xl p-[12px] sm:p-[15px] text-white flex flex-col gap-[8px] sm:gap-[10px]",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-500 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-500 delay-75 ease-out"}),e.jsxs("div",{className:"relative z-10 flex justify-between items-start",children:[e.jsx("span",{className:"text-[10px] sm:text-[11px] opacity-90 uppercase tracking-wider font-semibold",children:"Class Average"}),e.jsx("div",{className:"bg-white/20 p-1.5 rounded-lg flex",children:e.jsx(ms,{size:14})})]}),e.jsxs("div",{className:"relative z-10 text-[22px] sm:text-[26px] font-semibold tracking-tight",children:[Math.round(ee),"%"]})]}),e.jsxs("div",{className:"group relative overflow-hidden bg-[#10b981] shadow-[0_4px_16px_rgba(16,185,129,0.13)] rounded-lg sm:rounded-2xl p-[12px] sm:p-[15px] text-white flex flex-col gap-[8px] sm:gap-[10px]",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-500 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-500 delay-75 ease-out"}),e.jsxs("div",{className:"relative z-10 flex justify-between items-start",children:[e.jsx("span",{className:"text-[10px] sm:text-[11px] opacity-90 uppercase tracking-wider font-semibold",children:"Completion"}),e.jsx("div",{className:"bg-white/20 p-1.5 rounded-lg flex",children:e.jsx(La,{size:14})})]}),e.jsxs("div",{className:"relative z-10 text-[22px] sm:text-[26px] font-semibold tracking-tight",children:[Math.round(oe),"%"]})]}),e.jsxs("div",{className:"group relative overflow-hidden bg-[#a855f7] shadow-[0_4px_16px_rgba(168,85,247,0.13)] rounded-lg sm:rounded-2xl p-[12px] sm:p-[15px] text-white flex flex-col gap-[8px] sm:gap-[10px]",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-500 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-500 delay-75 ease-out"}),e.jsxs("div",{className:"relative z-10 flex justify-between items-start",children:[e.jsx("span",{className:"text-[10px] sm:text-[11px] opacity-90 uppercase tracking-wider font-semibold",children:"Participation"}),e.jsx("div",{className:"bg-white/20 p-1.5 rounded-lg flex",children:e.jsx(us,{size:14})})]}),e.jsxs("div",{className:"relative z-10 text-[22px] sm:text-[26px] font-semibold tracking-tight",children:[Math.round(Re),"%"]})]}),e.jsxs("div",{className:"group relative overflow-hidden bg-[#f97316] shadow-[0_4px_16px_rgba(249,115,22,0.13)] rounded-lg sm:rounded-2xl p-[12px] sm:p-[15px] text-white flex flex-col gap-[8px] sm:gap-[10px]",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-500 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-500 delay-75 ease-out"}),e.jsxs("div",{className:"relative z-10 flex justify-between items-start",children:[e.jsx("span",{className:"text-[10px] sm:text-[11px] opacity-90 uppercase tracking-wider font-semibold",children:"Attention"}),e.jsx("div",{className:"bg-white/20 p-1.5 rounded-lg flex",children:e.jsx(ca,{size:14})})]}),e.jsxs("div",{className:"relative z-10 text-[22px] sm:text-[26px] font-semibold tracking-tight",children:[te.length," ",e.jsx("span",{className:"text-[12px] opacity-90 font-medium",children:"students"})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-3 gap-3 sm:gap-[24px] h-auto xl:h-[600px]",children:[e.jsxs("div",{className:"xl:col-span-1 bg-white/80 backdrop-blur-[12px] rounded-[18px] shadow-[0_1px_4px_rgba(0,0,0,0.04)] border border-white flex flex-col overflow-hidden h-[500px] xl:h-full",children:[e.jsxs("div",{className:"p-5 border-b border-[#f1f5f9] shrink-0",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("h2",{className:"text-[15px] font-semibold text-[#1e293b]",children:["Students ",e.jsxs("span",{className:"text-[#64748b] text-[13px]",children:["(",Pe.length,")"]})]}),e.jsx("button",{onClick:()=>g?.(),className:"text-[11px] font-semibold text-[#9956DE] hover:text-[#7c3aed] bg-[#9956DE]/10 hover:bg-[#9956DE]/20 px-3 py-1.5 rounded-lg transition-colors",children:"+ Add"})]}),e.jsxs("div",{className:"flex items-center bg-white px-4 py-2 rounded-[14px] shadow-[0_1px_4px_rgba(0,0,0,0.04)] border border-[#f1f5f9] group",children:[e.jsx(qs,{className:"w-4 h-4 text-[#64748b] shrink-0 group-focus-within:text-[#4f46e5] transition-colors"}),e.jsx("input",{type:"text",placeholder:"Search students...",value:W,onChange:j=>f(j.target.value),className:"bg-transparent border-none focus:outline-none ml-2 text-[13px] w-full text-[#475569] placeholder:text-[#64748b]"})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-4 overflow-x-auto no-scrollbar pb-1",children:[e.jsx("button",{onClick:()=>A("All"),className:`px-3 py-1.5 text-[11px] font-semibold rounded-[14px] whitespace-nowrap transition-all hover:scale-[1.02] ${$==="All"?"bg-[#4f46e5] text-white shadow-[0_1px_4px_rgba(0,0,0,0.04)]":"bg-[#f8fafc] text-[#64748b] hover:bg-[#f1f5f9]"}`,children:"All Students"}),e.jsx("button",{onClick:()=>A("Good"),className:`px-3 py-1.5 text-[11px] font-semibold rounded-[14px] whitespace-nowrap transition-all hover:scale-[1.02] ${$==="Good"?"bg-emerald-50 text-emerald-600 border border-emerald-100/50 shadow-[0_1px_4px_rgba(0,0,0,0.04)]":"bg-emerald-50/40 text-emerald-600 border border-emerald-50 hover:bg-emerald-50"}`,children:"Top Performers"}),e.jsx("button",{onClick:()=>A("Risk"),className:`px-3 py-1.5 text-[11px] font-semibold rounded-[14px] whitespace-nowrap transition-all hover:scale-[1.02] ${$==="Risk"?"bg-rose-50 text-rose-600 border border-rose-100/50 shadow-[0_1px_4px_rgba(0,0,0,0.04)]":"bg-rose-50/40 text-rose-600 border border-rose-50 hover:bg-rose-50"}`,children:"Needs Attention"})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto px-4 pb-4 flex flex-col no-scrollbar",children:e.jsx(yu,{style:{height:"100%"},data:Pe,className:"no-scrollbar",itemContent:(j,_)=>{const T=Y(_.id),Q=T!==null?{..._,avgScore:T}:_;return e.jsx("div",{className:"py-[6px] px-[8px]",children:e.jsx(rp,{student:Q,onViewStudent:n,onCreateAccount:i,onRemoveStudent:I})})},computeItemKey:(j,_)=>ln(_)})})]}),e.jsxs("div",{className:"xl:col-span-2 flex flex-col gap-[24px] h-full overflow-y-auto no-scrollbar pb-10 xl:pb-0",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-[24px]",children:[e.jsxs("div",{className:"bg-white/80 backdrop-blur-[12px] rounded-[18px] p-6 shadow-[0_1px_4px_rgba(0,0,0,0.04)] border border-white flex flex-col group h-[280px]",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsx("h3",{className:"font-semibold text-[15px] text-[#1e293b]",children:"Risk Distribution"}),e.jsx(Yr,{className:"w-4 h-4 text-[#64748b] cursor-pointer group-hover:scale-110 transition-transform"})]}),e.jsx("div",{className:"relative w-full flex-1 min-h-[180px]",children:e.jsx(Wn,{width:"100%",height:"100%",children:e.jsxs(qn,{data:Fe,children:[e.jsx(Yn,{strokeDasharray:"4 4",stroke:"#f1f5f9",vertical:!1}),e.jsx(Kn,{dataKey:"name",axisLine:{stroke:"#cbd5e1",strokeWidth:2},tickLine:!1,tick:{fill:"#475569",fontSize:11,fontWeight:600},dy:10}),e.jsx(Xn,{axisLine:!1,tickLine:!1,tick:{fill:"#64748b",fontSize:10,fontWeight:600}}),e.jsx(Jn,{cursor:{fill:"#f8fafc"},contentStyle:{borderRadius:"12px",border:"none",boxShadow:"0 4px 6px -1px rgb(0 0 0 / 0.1)"}}),e.jsx(Zn,{dataKey:"value",radius:[6,6,0,0],barSize:80,children:Fe.map((j,_)=>{const T={Critical:"#dc2626","High Risk":"#f43f5e","Medium Risk":"#f59e0b","Low Risk":"#10b981",Unassessed:"#94a3b8"};return e.jsx(eo,{fill:T[j.name]||j.color},`cell-${_}`)})})]})})})]}),e.jsxs("div",{className:"bg-white/80 backdrop-blur-[12px] rounded-[18px] p-6 shadow-[0_1px_4px_rgba(0,0,0,0.04)] border border-white flex flex-col group h-[280px]",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsx("h3",{className:"font-semibold text-[15px] text-[#1e293b]",children:"Topic Performance"}),e.jsx(Yr,{className:"w-4 h-4 text-[#64748b] cursor-pointer group-hover:scale-110 transition-transform"})]}),e.jsx("div",{className:"relative w-full flex-1 min-h-[180px] -ml-8",children:e.jsx(Wn,{width:"100%",height:"100%",children:e.jsxs(qn,{data:E,layout:"vertical",margin:{top:0,right:10,left:40,bottom:0},children:[e.jsx(Yn,{strokeDasharray:"4 4",stroke:"#f1f5f9",horizontal:!1}),e.jsx(Kn,{type:"number",domain:[0,100],axisLine:!1,tickLine:!1,tick:{fill:"#64748b",fontSize:10,fontWeight:600},tickFormatter:j=>`${j}%`}),e.jsx(Xn,{dataKey:"topic",type:"category",axisLine:{stroke:"#cbd5e1",strokeWidth:2},tickLine:!1,tick:{fill:"#1e293b",fontSize:11,fontWeight:600},dx:-10}),e.jsx(Jn,{cursor:{fill:"#f8fafc"},contentStyle:{borderRadius:"12px",border:"none",boxShadow:"0 4px 6px -1px rgb(0 0 0 / 0.1)"}}),e.jsx(Zn,{dataKey:"score",radius:[0,6,6,0],barSize:28,children:E.map((j,_)=>{const T=j.score>=75?"#10b981":j.score>=60?"#f59e0b":"#f43f5e";return e.jsx(eo,{fill:T},`cell-${_}`)})})]})})})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-[24px]",children:[e.jsxs("div",{className:"bg-white/80 backdrop-blur-[12px] rounded-[18px] p-6 shadow-[0_1px_4px_rgba(0,0,0,0.04)] border border-white",children:[e.jsx("div",{className:"flex items-center justify-between mb-4",children:e.jsxs("h3",{className:"font-semibold text-[15px] text-[#1e293b] flex items-center gap-2",children:[e.jsx(la,{className:"w-4 h-4 text-emerald-500"}),"Top Performers"]})}),e.jsxs("div",{className:"space-y-[8px]",children:[G.map(j=>e.jsxs("div",{onClick:()=>n(j),className:"flex justify-between items-center p-3 bg-emerald-50/40 rounded-[14px] border border-emerald-50 group hover:scale-[1.02] transition-transform cursor-pointer",children:[e.jsx("span",{className:"text-[13px] font-semibold text-[#1e293b]",children:j.name}),e.jsxs("span",{className:"text-[13px] font-semibold text-emerald-600",children:[Y(j.id)??j.avgScore,"%"]})]},`top-${j.id}`)),G.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"No students available yet."})]})]}),e.jsxs("div",{className:"bg-white/80 backdrop-blur-[12px] rounded-[18px] p-6 shadow-[0_1px_4px_rgba(0,0,0,0.04)] border border-white",children:[e.jsx("div",{className:"flex items-center justify-between mb-4",children:e.jsxs("h3",{className:"font-semibold text-[15px] text-[#1e293b] flex items-center gap-2",children:[e.jsx(ca,{className:"w-4 h-4 text-rose-500"}),"Needs Attention"]})}),e.jsxs("div",{className:"space-y-[8px]",children:[te.slice(0,4).map(j=>{const _=V(j.id),T=_||(j.riskLevel==="high"?"HIGH RISK":"MEDIUM RISK"),Q=_==="Critical"||j.avgScore===0&&j.riskLevel==="high",ue=_==="High Risk"||j.riskLevel==="high",ce=Q?"bg-red-50/60 border-red-100":ue?"bg-rose-50/40 border-rose-50":"bg-amber-50/40 border-amber-50",ae=Q?"text-red-700":ue?"text-rose-600":"text-amber-600";return e.jsxs("div",{onClick:()=>n(j),className:`flex justify-between items-center p-3 rounded-[14px] border group hover:scale-[1.02] transition-transform cursor-pointer ${ce}`,children:[e.jsx("span",{className:"text-[13px] font-semibold text-[#1e293b]",children:j.name}),e.jsx("span",{className:`text-[11px] font-semibold bg-white px-2 py-0.5 rounded-[14px] shadow-[0_1px_4px_rgba(0,0,0,0.04)] border border-[#f1f5f9] ${ae}`,children:T.toUpperCase()})]},`attn-${j.id}`)}),te.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"No urgent students."})]})]})]})]})]}),y?.insights&&e.jsxs("div",{className:"bg-gradient-to-br from-indigo-50/80 to-purple-50/60 backdrop-blur-[12px] rounded-[18px] p-5 sm:p-6 shadow-[0_1px_4px_rgba(0,0,0,0.04)] border border-indigo-100/50",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("button",{onClick:()=>Ie(!be),className:"flex items-center gap-2 text-[15px] font-semibold text-[#1e293b]",children:[e.jsx(ps,{className:"w-4 h-4 text-indigo-500"}),"AI Class Insights",e.jsx($t,{className:`w-4 h-4 text-[#64748b] transition-transform ${be?"":"-rotate-90"}`})]}),e.jsxs("button",{onClick:pe,disabled:le,className:"flex items-center gap-1.5 text-[11px] font-semibold text-indigo-600 hover:text-indigo-700 bg-white/70 hover:bg-white px-3 py-1.5 rounded-lg transition-colors disabled:opacity-50",children:[e.jsx(cs,{className:`w-3 h-3 ${le?"animate-spin":""}`}),le?"Refreshing...":"Refresh AI Analysis"]})]}),be&&e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[e.jsxs("div",{className:"bg-white/70 rounded-[14px] p-4 border border-white",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(Ls,{size:18,className:"text-indigo-600"}),e.jsx("h4",{className:"text-[13px] font-semibold text-[#1e293b]",children:"Class Overview"})]}),e.jsx("p",{className:"text-[12px] text-[#475569] leading-relaxed",children:y.insights.class_summary})]}),e.jsxs("div",{className:"bg-white/70 rounded-[14px] p-4 border border-white",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(la,{size:18,className:"text-emerald-600"}),e.jsx("h4",{className:"text-[13px] font-semibold text-[#1e293b]",children:"What's Working"})]}),e.jsx("p",{className:"text-[12px] text-[#475569] leading-relaxed",children:y.insights.class_strengths})]}),e.jsxs("div",{className:"bg-white/70 rounded-[14px] p-4 border border-white",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(ms,{size:18,className:"text-amber-600"}),e.jsx("h4",{className:"text-[13px] font-semibold text-[#1e293b]",children:"Recommended Actions"})]}),e.jsx("ul",{className:"space-y-1.5",children:y.insights.recommended_actions.map((j,_)=>e.jsxs("li",{className:"text-[12px] text-[#475569] leading-relaxed flex items-start gap-1.5",children:[e.jsx("span",{className:"text-indigo-500 mt-0.5 shrink-0",children:"•"}),j]},_))})]})]})]}),e.jsx(np,{students:s,allClasses:a,currentClass:t,onReassignSection:l,reassignBusyId:c})]})},ip=({student:t,teacherId:s,teacherName:a,onStudentUpdated:r,onBack:o,onNavigateToQuizMaker:n,initialCache:i,onCacheUpdate:l})=>{const c=(t.riskLevel||"low").toLowerCase(),d=c==="high"||c==="medium",m=u.useMemo(()=>xt.getImportGroundedRolloutFlags(),[]),[p,h]=u.useState(null),[b,S]=u.useState(!0),[k,N]=u.useState(null),[v,g]=u.useState(i?.learningPath||""),[I,z]=u.useState(!0),[R,W]=u.useState(i?.gradeDraft||t.grade||"Grade 11"),[f,C]=u.useState(i?.sectionDraft||t.section||"Section A"),[w,$]=u.useState(!1),[A,y]=u.useState(i?.lessonPlan??null),[q,J]=u.useState([]),[re,le]=u.useState(""),[ne,be]=u.useState(!1),[Ie,de]=u.useState(""),[fe,H]=u.useState("all"),[ee,oe]=u.useState("all"),[Re,Fe]=u.useState(!1),[Pe,G]=u.useState(!1),[te,E]=u.useState(null),[Y,V]=u.useState(!1),[pe,D]=u.useState(!1),[j,_]=u.useState(0),[T,Q]=u.useState(!1),[ue,ce]=u.useState("choose"),[ae,Ce]=u.useState([]),[Ne,Je]=u.useState(!1),[$e,Ge]=u.useState(!1),[ft,Nt]=u.useState(!1),[dt,jt]=u.useState(!1);u.useEffect(()=>{W(t.grade||"Grade 11"),C(t.section||"Section A")},[t.grade,t.section]),u.useEffect(()=>{let L=!1;return S(!0),rn(t.id).then(me=>{L||h(me)}).catch(me=>console.warn("[InterventionView] Backend fetch failed:",me)).finally(()=>{L||S(!1)}),()=>{L=!0}},[t.id]);const[Lt,rs]=u.useState(null);u.useEffect(()=>{let L=!1;const me=t.accountUid||t.id;return Gr(me).then(We=>{!L&&We?.averageScore&&rs(Math.round(We.averageScore))}).catch(()=>{}),()=>{L=!0}},[t.id,t.accountUid]),u.useEffect(()=>{const L=me=>{if(me.key==="Escape"){if(dt){jt(!1);return}if($e){ft?jt(!0):Ge(!1);return}T&&Q(!1)}};return document.addEventListener("keydown",L),()=>document.removeEventListener("keydown",L)},[$e,T,ft,dt]),u.useEffect(()=>{if($e){const L=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.body.style.overflow=L}}},[$e]),u.useEffect(()=>{l?.(t.id,{lessonPlan:A,learningPath:v,gradeDraft:R,sectionDraft:f})},[A,v,R,f,t.id,l]),u.useEffect(()=>{(async()=>{z(!0);try{let me="";try{me=await Wl(t.struggles.length>0?t.struggles:[t.weakestTopic],"general_math"),le(me)}catch{le("")}const We=await xt.getLearningPath({weaknesses:t.struggles.length>0?t.struggles:[t.weakestTopic],gradeLevel:"High School",subject:"general_math"}),B=me?`${We.learningPath} -${me}`:We.learningPath;g(B)}catch{g("Unable to generate learning path. Please try again later."),le("")}finally{z(!1)}})()},[t]);const Ts=u.useCallback(async()=>{be(!0),de("");try{const L=t.classSectionId||Ft(R||"Grade 11",f||"Section A"),me=t.struggles.length>0?t.struggles[0]:t.weakestTopic,We=await Lo({gradeLevel:R||t.grade||"Grade 11",subject:"general_math",quarter:1,moduleUnit:[R,f].filter(Boolean).join(" - ")||t.className,lessonTitle:`Grounded Lesson: ${me}`,learningCompetency:me,learnerLevel:t.avgScore<60?"support":t.avgScore<80?"developing":"advanced",classSectionId:L,className:[R,f].filter(Boolean).join(" - ")||t.className,focusTopics:t.struggles.length>0?t.struggles:[t.weakestTopic],topicCount:5,preferImportedTopics:m.lessonEnabled,allowReviewSources:Re,allowUnverifiedLesson:Pe},!0);y(We),J(We.curriculumSources||[]),E(null),xt.reportImportGroundedFeedback({flow:"lesson",status:"success",classSectionId:L,className:[R,f].filter(Boolean).join(" - ")||t.className,metadata:{usedImportedTopics:We.usedImportedTopics,importedTopicCount:We.importedTopicCount,blockCount:We.blocks.length,publishReady:We.publishReady,sourceLegitimacyStatus:We.sourceLegitimacy.status,selfValidationPassed:We.selfValidation.passed,importGroundingEnabled:m.lessonEnabled}})}catch(L){let me=L instanceof Error?L.message:"Unable to generate lesson plan at this time.";if(L instanceof rr&&L.status===422)try{const B=JSON.parse(L.responseBody)?.detail;if(B?.selfValidation&&!Pe)try{const F=t.classSectionId||Ft(R||"Grade 11",f||"Section A"),ve=t.struggles.length>0?t.struggles[0]:t.weakestTopic,we=await Lo({gradeLevel:R||t.grade||"Grade 11",subject:"general_math",quarter:1,moduleUnit:[R,f].filter(Boolean).join(" - ")||t.className,lessonTitle:`Grounded Lesson: ${ve}`,learningCompetency:ve,learnerLevel:t.avgScore<60?"support":t.avgScore<80?"developing":"advanced",classSectionId:F,className:[R,f].filter(Boolean).join(" - ")||t.className,focusTopics:t.struggles.length>0?t.struggles:[t.weakestTopic],topicCount:5,preferImportedTopics:m.lessonEnabled,allowReviewSources:Re,allowUnverifiedLesson:!0},!0);y(we),J(we.curriculumSources||[]),E(null),de("");return}catch{}B?.message&&(me=B.message);const kt=B?.sourceLegitimacy?.issues||[],Me=B?.selfValidation?.issues||[],M=[...kt,...Me].filter(Boolean).slice(0,3);M.length>0&&(me=`${me} ${M.join(" ")}`)}catch{}de(me),y(null),J([]),xt.reportImportGroundedFeedback({flow:"lesson",status:"failed",classSectionId:t.classSectionId||Ft(R||"Grade 11",f||"Section A"),className:[R,f].filter(Boolean).join(" - ")||t.className,metadata:{error:me,allowReviewSources:Re,allowUnverifiedLesson:Pe,importGroundingEnabled:m.lessonEnabled}})}finally{be(!1)}},[t,R,f,m.lessonEnabled,Re,Pe]),bs=u.useCallback(async()=>{if(!A)return ie.error("Generate a lesson plan first."),null;V(!0);try{const L=await pm(A,s,{teacherName:a,studentId:t.id,studentName:t.name});return E(L),ie.success("Lesson plan saved as draft."),L}catch(L){return console.error("Failed to save lesson draft:",L),ie.error(L instanceof Error?L.message:"Failed to save lesson draft."),null}finally{V(!1)}},[A,s,a,t.id,t.name]),Bs=u.useCallback(async()=>{if(!A){ie.error("Generate a lesson plan first.");return}if(!A.publishReady){const L=[...A.sourceLegitimacy.issues,...A.selfValidation.issues].filter(Boolean).slice(0,2).join(" ");ie.error(L||"Lesson is not publish-ready. Resolve legitimacy and validation checks first.");return}D(!0);try{let L=te;if(L||(L=await bs()),!L)return;await hm(L),ie.success("Lesson plan published to class content."),xt.reportImportGroundedFeedback({flow:"lesson",status:"success",classSectionId:A.classSectionId||t.classSectionId,className:A.className||t.className,metadata:{action:"publish_lesson_plan",lessonPlanId:L,publishReady:A.publishReady,sourceLegitimacyStatus:A.sourceLegitimacy.status,selfValidationPassed:A.selfValidation.passed}})}catch(L){console.error("Failed to publish lesson plan:",L),ie.error(L instanceof Error?L.message:"Failed to publish lesson plan."),xt.reportImportGroundedFeedback({flow:"lesson",status:"failed",classSectionId:A.classSectionId||t.classSectionId,className:A.className||t.className,metadata:{action:"publish_lesson_plan",error:L instanceof Error?L.message:"Failed to publish lesson plan."}})}finally{D(!1)}},[A,te,bs,t.className,t.classSectionId]);u.useEffect(()=>{Ts()},[j]),u.useEffect(()=>{_(L=>L+1)},[t.id]),u.useEffect(()=>{H("all"),oe("all")},[A]),u.useMemo(()=>A?Array.from(new Set(A.blocks.map(L=>L.provenance?.sourceFile?.trim()).filter(L=>!!L))).sort((L,me)=>L.localeCompare(me)):[],[A]),u.useMemo(()=>A?Array.from(new Set(A.blocks.map(L=>L.provenance?.materialId?.trim()).filter(L=>!!L))).sort((L,me)=>L.localeCompare(me)):[],[A]);const ns=u.useMemo(()=>A?A.blocks.filter(L=>{const me=fe==="all"||(L.provenance?.sourceFile||"").trim()===fe,We=ee==="all"||(L.provenance?.materialId||"").trim()===ee;return me&&We}):[],[A,fe,ee]),vs=u.useMemo(()=>p?.learning_path?.steps?.length?p.learning_path.steps.map(L=>({id:L.step_number,type:L.type==="video_lesson"?"video":L.type==="assessment"?"assessment":"quiz",title:L.title,duration:`${L.duration_minutes} mins`,questions:L.num_items||void 0,icon:L.type==="video_lesson"?Za:L.type==="assessment"?ya:L.type==="review"?cs:qr,competency:L.competency_tag,difficulty:L.difficulty,is_completed:L.is_completed})):[{id:1,type:"video",title:`${t.weakestTopic} Fundamentals`,duration:"8 mins",questions:void 0,icon:Za,competency:"",difficulty:"easy",is_completed:!1},{id:2,type:"quiz",title:`${t.weakestTopic} Practice`,duration:"12 mins",questions:10,icon:qr,competency:"",difficulty:"easy",is_completed:!1},{id:3,type:"assessment",title:"Final Check",duration:"10 mins",questions:5,icon:ya,competency:"",difficulty:"medium",is_completed:!1}],[p,t.weakestTopic]),os=async()=>{if(!s){ie.error("Unable to update section: teacher context missing");return}$(!0);try{await yr(t.id,R,f,s,new Date().getFullYear().toString(),a),await il(t.id,R,f);const L={...t,grade:R,section:f,className:[R,f].filter(Boolean).join(" - "),classSectionId:Ft(R,f)};r(L),ie.success("Student section assignment updated")}catch(L){console.error("Failed to update student section assignment:",L),ie.error("Failed to update section assignment")}finally{$(!1)}};return e.jsxs(Le.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"w-full h-full flex overflow-hidden relative",children:[e.jsx("div",{className:"flex-1 overflow-y-auto p-[24px] xl:p-[32px] no-scrollbar",children:e.jsxs("div",{className:"max-w-[1000px] mx-auto space-y-[24px]",children:[e.jsx("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4 mb-[8px]",children:e.jsx("div",{children:e.jsxs("button",{onClick:o,className:"flex items-center gap-2 text-[13px] font-semibold text-[#4f46e5] hover:text-[#3730a3] transition-colors bg-white/60 hover:bg-white/80 px-[18px] py-2 rounded-full backdrop-blur-[12px] mb-[16px] w-max shadow-[0_1px_4px_rgba(0,0,0,0.04)] border border-white/50",children:[e.jsx(cr,{className:"w-4 h-4"}),"Back to Analytics"]})})}),e.jsxs("div",{className:"bg-gradient-to-br from-[#ecfdf5] via-[#f0fdf4] to-[#f7fdf9] backdrop-blur-[12px] rounded-[20px] p-[24px] border border-emerald-100 shadow-[0_4px_16px_rgba(16,185,129,0.08)] relative overflow-hidden",children:[e.jsx("div",{className:"absolute right-[-20px] bottom-[-20px] opacity-[0.06] pointer-events-none",children:e.jsx(Fn,{className:"w-48 h-48 text-emerald-600"})}),e.jsxs("div",{className:"flex items-center gap-3 mb-5 relative z-10",children:[e.jsx("div",{className:"w-10 h-10 rounded-[12px] bg-gradient-to-br from-[#059669] to-[#10b981] flex items-center justify-center shrink-0 shadow-[0_4px_10px_rgba(5,150,105,0.3)]",children:e.jsx(Fn,{className:"w-5 h-5 text-white"})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"text-[15px] font-bold text-[#1e293b]",children:"AI Analysis"}),e.jsxs("span",{className:"flex items-center gap-1 px-2.5 py-0.5 bg-emerald-500 text-white text-[10px] font-bold rounded-full uppercase tracking-wider shadow-sm",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-white animate-pulse"}),"Insights Active"]})]})]}),re&&e.jsx(zo,{sources:q,className:"mb-4 relative z-10"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4 w-full relative z-10",children:[e.jsxs("div",{className:"bg-white/70 backdrop-blur-sm rounded-[14px] p-4 border border-emerald-100/60 shadow-[0_1px_4px_rgba(0,0,0,0.04)] relative overflow-hidden",children:[e.jsx("div",{className:"absolute left-0 top-0 w-1 h-full bg-emerald-400 rounded-l-[14px]"}),e.jsxs("h4",{className:"text-[11px] font-bold text-emerald-600 uppercase tracking-wider mb-2.5 flex items-center gap-1.5 pl-2",children:[e.jsx(la,{className:"w-3.5 h-3.5"})," Learning Strengths"]}),e.jsx("p",{className:"text-[13px] text-[#475569] leading-relaxed pl-2",children:p?.learning_strengths||(d?e.jsx(e.Fragment,{children:"Demonstrates engagement but faces challenges. Needs support with foundational topics."}):e.jsxs(e.Fragment,{children:["Excels in ",e.jsx("span",{className:"font-semibold text-[#1e293b]",children:t.weakestTopic}),". Demonstrates high engagement during interactive tests."]}))})]}),e.jsxs("div",{className:"bg-white/70 backdrop-blur-sm rounded-[14px] p-4 border border-rose-100/60 shadow-[0_1px_4px_rgba(0,0,0,0.04)] relative overflow-hidden",children:[e.jsx("div",{className:"absolute left-0 top-0 w-1 h-full bg-rose-400 rounded-l-[14px]"}),e.jsxs("h4",{className:"text-[11px] font-bold text-rose-500 uppercase tracking-wider mb-2.5 flex items-center gap-1.5 pl-2",children:[e.jsx(ms,{className:"w-3.5 h-3.5"})," Next Steps"]}),e.jsx("ul",{className:"text-[13px] text-[#475569] leading-relaxed list-none p-0 m-0 space-y-1 pl-2",children:p?.next_steps_summary?e.jsx("li",{children:p.next_steps_summary}):t.struggles.length>0?t.struggles.map((L,me)=>e.jsxs("li",{children:["Must continue strengthening ",e.jsx("span",{className:"font-semibold text-[#1e293b]",children:L}),"."]},me)):e.jsxs("li",{children:["Focus on repetitive practice modules for ",e.jsx("span",{className:"font-semibold text-[#1e293b]",children:t.weakestTopic}),"."]})})]})]})]}),e.jsxs("div",{className:"bg-white/80 backdrop-blur-[12px] rounded-[18px] p-[24px] shadow-[0_1px_4px_rgba(0,0,0,0.04)] border border-white",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6 border-b border-[#f1f5f9] pb-4",children:[e.jsx("h3",{className:"text-[15px] font-semibold text-[#1e293b]",children:"Generated Learning Path"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{disabled:!p?.learning_path,onClick:async()=>{if(p)try{await xl(p,s),ie.success(`Learning path assigned to ${t.name}'s modules.`)}catch(L){console.error("[InterventionView] Assign failed:",L),ie.error("Failed to assign learning path.")}},className:"bg-emerald-50 hover:bg-emerald-100 text-emerald-700 border border-emerald-200 text-[11px] font-semibold rounded-full px-4 py-1.5 transition-colors shadow-[0_1px_4px_rgba(0,0,0,0.02)] flex items-center gap-1.5 disabled:opacity-50",children:[e.jsx(aa,{className:"w-3 h-3"})," Assign to Student"]}),e.jsxs("button",{disabled:I||b,onClick:async()=>{S(!0);try{const L=await ml(t.id);h(L)}catch(L){console.warn("[InterventionView] Regenerate failed:",L)}finally{S(!1)}_(L=>L+1)},className:"bg-[#f8fafc] hover:bg-white text-[#4f46e5] border border-[#e0e7ff] text-[11px] font-semibold rounded-full px-4 py-1.5 transition-colors shadow-[0_1px_4px_rgba(0,0,0,0.02)] flex items-center gap-1.5 disabled:opacity-50",children:[e.jsx(cs,{className:`w-3 h-3 ${b?"animate-spin":""}`})," ",b?"Analyzing...":"Regenerate"]})]})]}),e.jsxs(Eo,{name:"teacher-intervention-learning-path",loading:!1,fixture:null,fallback:null,children:[e.jsxs("div",{className:"mb-8 flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"text-[11px] font-semibold text-[#64748b] uppercase tracking-wider mr-2",children:"Methodology:"}),(p?.learning_path?.methodology_tags||["Interactive","Video","Practice","Quiz"]).map(L=>e.jsx("span",{className:"px-3 py-1 bg-[#f8fafc] text-[#475569] text-[11px] font-semibold rounded-full border border-[#e2e8f0]",children:L},L))]}),e.jsx("div",{className:"relative border-l-2 border-[#e2e8f0] ml-[20px] space-y-[28px] pb-4",children:vs.map((L,me)=>{let We=e.jsx(Za,{className:"w-4 h-4"}),B="bg-[#8b5cf6] shadow-[0_4px_10px_rgba(139,92,246,0.3)]",kt="text-purple-600",Me="group-hover:border-purple-200",M="hover:bg-[#4f46e5]",F=e.jsx(dc,{className:"w-4 h-4 ml-0.5"});return L.type==="quiz"?(We=e.jsx(ir,{className:"w-4 h-4"}),B="bg-sky-500 shadow-[0_4px_10px_rgba(14,165,233,0.3)]",kt="text-sky-600",Me="group-hover:border-sky-200",M="hover:bg-sky-500",F=e.jsx(Ms,{className:"w-4 h-4"})):L.type==="assessment"&&(We=e.jsx(ya,{className:"w-4 h-4"}),B="bg-emerald-500 shadow-[0_4px_10px_rgba(16,185,129,0.3)]",kt="text-emerald-600",Me="group-hover:bg-emerald-50"),e.jsxs(Le.div,{initial:{opacity:0,x:-20},animate:{opacity:1,x:0},transition:{delay:me*.1},className:"relative pl-[32px] group",children:[e.jsx("div",{className:`absolute -left-[17px] top-1 w-8 h-8 rounded-full ${B} text-white flex items-center justify-center ring-4 ring-white group-hover:scale-110 transition-transform`,children:We}),e.jsxs("div",{onClick:()=>{p?.learning_path?.steps?.[me]&&N(p.learning_path.steps[me])},className:`${L.type==="assessment"?"bg-emerald-50/50 border-emerald-100":"bg-white border-[#f1f5f9]"} rounded-[14px] p-[18px] border shadow-[0_1px_4px_rgba(0,0,0,0.04)] flex justify-between items-center transition-colors cursor-pointer ${Me}`,children:[e.jsxs("div",{children:[e.jsxs("span",{className:`text-[10px] font-semibold uppercase tracking-wider mb-1 block ${kt}`,children:["Step ",me+1," • ",L.type==="video"?"Video Lesson":L.type==="quiz"?"Practice":"Assessment"]}),e.jsx("p",{className:"font-semibold text-[#1e293b] text-[13px] mb-0.5",children:ys(L.title)}),e.jsxs("p",{className:"text-[#64748b] text-[11px] flex items-center gap-1.5",children:[L.type==="video"&&e.jsxs(e.Fragment,{children:[e.jsx(As,{className:"w-3 h-3"})," ",L.duration]}),L.type==="quiz"&&e.jsxs(e.Fragment,{children:[e.jsx(yi,{className:"w-3 h-3"})," ",L.questions?`${L.questions} questions`:L.duration]}),L.type==="assessment"&&e.jsxs(e.Fragment,{children:[e.jsx(ms,{className:"w-3 h-3"})," ",L.questions?`${L.questions} assessment questions`:L.duration]}),L.competency&&e.jsx("span",{className:"ml-2 px-1.5 py-0.5 bg-indigo-50 text-indigo-600 text-[9px] font-mono rounded",children:L.competency})]})]}),L.type==="assessment"?e.jsx(xi,{className:"w-6 h-6 text-emerald-400"}):e.jsx("button",{className:`w-8 h-8 rounded-full bg-[#f8fafc] flex items-center justify-center text-[#64748b] ${M} hover:text-white transition-colors border border-[#e2e8f0]`,children:F})]})]},L.id)})})]})]}),e.jsxs("div",{className:"relative bg-white/80 backdrop-blur-[12px] rounded-[18px] p-[24px] shadow-[0_1px_4px_rgba(0,0,0,0.04)] border border-white overflow-hidden",children:[e.jsx("div",{className:"absolute inset-0 z-10 bg-white/70 backdrop-blur-[2px] flex items-center justify-center rounded-[18px]",children:e.jsxs("div",{className:"text-center",children:[e.jsx("span",{className:"inline-block px-4 py-2 bg-slate-100 border border-slate-200 rounded-full text-[13px] font-semibold text-slate-500",children:"🔒 Coming Soon"}),e.jsx("p",{className:"text-[11px] text-slate-400 mt-2",children:"This feature is temporarily locked."})]})}),e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("h3",{className:"text-[15px] font-semibold text-[#1e293b]",children:"Targeted Lesson Generation"}),e.jsx(St,{onClick:()=>_(L=>L+1),disabled:ne,className:"bg-[#4f46e5] hover:bg-[#3730a3] text-white h-8 text-[11px] rounded-full px-4",children:ne?"Loading...":"Regenerate"})]}),e.jsx("p",{className:"text-[13px] text-[#64748b] mb-6",children:"Configure inputs and requirements for AI lesson generation."}),e.jsxs("div",{className:"bg-[#f8fafc]/80 rounded-[14px] p-[20px] border border-[#f1f5f9] mb-6",children:[e.jsxs("div",{className:"flex items-start gap-3 mb-4",children:[e.jsx(na,{className:"w-4 h-4 text-[#4f46e5] shrink-0 mt-0.5"}),e.jsxs("p",{className:"text-[13px] text-[#475569] leading-relaxed",children:["Class records alone are not enough for import-grounded lesson plans. Ensure course materials are uploaded via ",e.jsx("span",{className:"text-[#4f46e5] font-semibold",children:"Data Import"}),"."]})]}),e.jsxs("div",{className:"space-y-4 border-t border-[#e2e8f0] pt-5 mt-5",children:[e.jsxs("label",{className:"flex items-center justify-between cursor-pointer group",children:[e.jsx("span",{className:"text-[13px] font-medium text-[#1e293b] group-hover:text-[#4f46e5] transition-colors",children:"Allow sources requiring manual review"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:"checkbox",className:"sr-only peer",checked:Re,onChange:L=>Fe(L.target.checked)}),e.jsx("div",{className:"w-10 h-5 bg-slate-200 peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-[#4f46e5]"})]})]}),e.jsxs("label",{className:"flex items-center justify-between cursor-pointer group",children:[e.jsx("span",{className:"text-[13px] font-medium text-[#1e293b] group-hover:text-[#4f46e5] transition-colors",children:"Allow unverified lesson draft"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:"checkbox",className:"sr-only peer",checked:Pe,onChange:L=>G(L.target.checked)}),e.jsx("div",{className:"w-10 h-5 bg-slate-200 peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-[#4f46e5]"})]})]})]})]}),e.jsxs(Eo,{name:"teacher-intervention-lesson-plan",loading:!1,fixture:null,fallback:null,children:[Ie&&e.jsx("div",{className:"bg-[#FF8B8B]/14 border border-[#FF8B8B]/35 rounded-xl p-3 text-sm text-[#D66A6A] mb-4",children:Ie}),A&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"bg-[#f8fafc] border border-[#f1f5f9] rounded-[14px] p-5 shadow-[0_1px_4px_rgba(0,0,0,0.02)]",children:[e.jsx("div",{className:"mb-3",children:e.jsx(zo,{sources:q})}),e.jsx("p",{className:"text-[14px] font-semibold text-[#1e293b]",children:A.lessonTitle}),e.jsxs("div",{className:"flex flex-wrap gap-x-4 gap-y-2 mt-2",children:[e.jsxs("p",{className:"text-[11px] text-[#64748b]",children:[e.jsx("span",{className:"font-semibold text-[#475569]",children:"Imported topics:"})," ",A.usedImportedTopics?"Yes":"No"," (",A.importedTopicCount,")"]}),e.jsxs("p",{className:"text-[11px] text-[#64748b]",children:[e.jsx("span",{className:"font-semibold text-[#475569]",children:"Subject:"})," ",A.subject||"General Math"," (Q",A.quarter||1,")"]})]}),A.curriculumCompetency&&e.jsxs("p",{className:"text-[11px] text-[#4f46e5] font-semibold mt-2 bg-indigo-50/50 px-2 py-1 rounded inline-block",children:["Competency: ",A.curriculumCompetency]}),e.jsx("div",{className:"mt-3 flex items-center justify-between",children:e.jsxs("p",{className:"text-[11px] text-[#64748b]",children:["Publish readiness: ",e.jsx("span",{className:`font-semibold ${A.publishReady?"text-emerald-600":"text-rose-500"}`,children:A.publishReady?"Ready":"Blocked"})]})}),A.warnings.length>0&&e.jsx("p",{className:"text-[11px] text-amber-600 mt-2 bg-amber-50 px-2 py-1.5 rounded",children:A.warnings.join(" ")})]}),A.lessonObjective&&e.jsxs("div",{className:"bg-white border border-[#e2e8f0] rounded-[14px] p-4 shadow-[0_1px_4px_rgba(0,0,0,0.02)]",children:[e.jsx("p",{className:"text-[10px] font-semibold text-[#64748b] uppercase tracking-wider mb-1.5",children:"Lesson objective"}),e.jsx("p",{className:"text-[13px] text-[#1e293b]",children:A.lessonObjective})]}),A.realWorldHook&&e.jsxs("div",{className:"bg-indigo-50/50 border border-indigo-100 rounded-[14px] p-4 shadow-[0_1px_4px_rgba(0,0,0,0.02)]",children:[e.jsx("p",{className:"text-[10px] font-semibold text-[#4f46e5] uppercase tracking-wider mb-1.5",children:"Real-life application"}),e.jsx("p",{className:"text-[13px] text-[#1e293b]",children:A.realWorldHook})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3 mt-4",children:ns.map(L=>e.jsxs("div",{className:"border border-[#e2e8f0] rounded-[14px] p-4 bg-white shadow-[0_1px_4px_rgba(0,0,0,0.02)]",children:[e.jsx("h3",{className:"text-[13px] font-semibold text-[#1e293b]",children:L.title}),e.jsxs("p",{className:"text-[11px] text-[#64748b] mt-1",children:[L.estimatedMinutes," mins "," • "," ",L.strategy]}),e.jsx("p",{className:"text-[12px] text-[#475569] mt-2 bg-[#f8fafc] p-2 rounded-lg",children:L.objective}),e.jsxs("div",{className:"mt-3",children:[e.jsx("p",{className:"text-[10px] font-semibold text-[#64748b] uppercase tracking-wider mb-1.5",children:"Activities"}),L.activities.slice(0,2).map((me,We)=>e.jsxs("p",{className:"text-[11px] text-[#475569] mb-1 flex items-start gap-1",children:[e.jsx("span",{className:"text-[#94a3b8] mt-0.5",children:"•"})," ",e.jsx("span",{children:me})]},We))]})]},L.blockId))}),e.jsxs("div",{className:"flex flex-wrap gap-2 pt-4",children:[e.jsx(St,{variant:"outline",onClick:()=>void bs(),disabled:Y||!A,className:"border-[#cbd5e1] text-[#475569] hover:bg-[#f8fafc] text-[12px] h-9 rounded-full px-5",children:Y?e.jsx(Hn,{className:"h-4 w-16"}):"Save Draft"}),e.jsx(St,{onClick:()=>void Bs(),disabled:pe||!A||!A.publishReady,className:"bg-[#10b981] hover:bg-[#059669] text-white text-[12px] h-9 rounded-full px-5",children:pe?e.jsx(Hn,{className:"h-4 w-24 bg-white/35"}):"Publish Lesson Plan"})]})]})]})]})]})}),e.jsx("aside",{className:"w-[320px] 2xl:w-[340px] bg-white/70 backdrop-blur-[24px] border-l border-white shadow-[-4px_0_24px_rgba(0,0,0,0.02)] flex flex-col h-full shrink-0 overflow-y-auto z-10 no-scrollbar relative",children:e.jsxs("div",{className:"p-[24px] space-y-[24px] flex flex-col items-center",children:[e.jsxs("div",{className:"flex flex-col items-center text-center w-full",children:[e.jsx("img",{src:t.avatar,alt:t.name,className:"w-[96px] h-[96px] rounded-full object-cover shadow-[0_8px_16px_rgba(0,0,0,0.1)] mb-4 border-4 border-white z-10 relative"}),e.jsx("h2",{className:"text-[20px] font-semibold text-[#1e293b] mb-1",children:t.name}),e.jsxs("p",{className:"text-[11px] font-semibold text-[#64748b] mb-3 uppercase tracking-wider",children:["ID: ",t.id.substring(0,8)]}),e.jsx("span",{className:`text-[11px] font-semibold px-3 py-1 rounded-[14px] border ${(p?.risk_level||"").includes("Critical")?"text-red-700 bg-red-50 border-red-200 animate-pulse":t.riskLevel==="high"||(p?.risk_level||"").includes("High")?"text-rose-600 bg-rose-50 border-rose-100":t.riskLevel==="medium"||(p?.risk_level||"").includes("Medium")?"text-amber-600 bg-amber-50 border-amber-100":"text-emerald-600 bg-emerald-50 border-emerald-100"}`,children:p?.risk_level||(t.riskLevel==="high"?"High Risk":t.riskLevel==="medium"?"Medium Risk":"Low Risk")})]}),e.jsxs("div",{className:"w-full grid grid-cols-2 gap-[12px]",children:[e.jsxs("div",{className:"bg-white/80 rounded-[14px] p-4 border border-white shadow-[0_1px_4px_rgba(0,0,0,0.02)] text-left flex flex-col justify-center",children:[e.jsx("p",{className:"text-[11px] font-semibold text-[#64748b] uppercase tracking-wider mb-1",children:"Avg Score"}),e.jsxs("p",{className:"text-[20px] font-bold text-[#4f46e5]",children:[p?.avg_score||Lt||t.avgScore,"%"]})]}),e.jsxs("div",{className:"bg-white/80 rounded-[14px] p-4 border border-white shadow-[0_1px_4px_rgba(0,0,0,0.02)] text-left flex flex-col justify-center",children:[e.jsx("p",{className:"text-[11px] font-semibold text-[#64748b] uppercase tracking-wider mb-1",children:"Engagement"}),e.jsx("p",{className:"text-[20px] font-bold text-[#1e293b]",children:p?.engagement_level||((Lt||t.avgScore)>80?"High":(Lt||t.avgScore)>50?"Medium":"Low")})]}),e.jsxs("div",{className:"bg-white/80 rounded-[14px] p-4 border border-white shadow-[0_1px_4px_rgba(0,0,0,0.02)] text-left flex flex-col justify-center",children:[e.jsx("p",{className:"text-[11px] font-semibold text-[#64748b] uppercase tracking-wider mb-1",children:"Last Active"}),e.jsx("p",{className:"text-[13px] font-semibold text-[#1e293b] mt-1",children:p?.last_active?new Date(p.last_active).toLocaleDateString():t.lastActive})]}),e.jsxs("div",{className:"bg-rose-50/60 rounded-[14px] p-4 border border-rose-100 text-left flex flex-col justify-center",children:[e.jsx("p",{className:"text-[11px] font-semibold text-rose-600 uppercase tracking-wider mb-1",children:"Weakest Topic"}),e.jsx("p",{className:"text-[12px] font-semibold text-[#1e293b] mt-1 leading-snug break-words",title:p?.weakest_topic||t.weakestTopic,children:ys(p?.weakest_topic||t.weakestTopic||"")})]})]}),e.jsx("div",{className:"w-full flex flex-col gap-[10px]",children:e.jsxs("button",{onClick:async()=>{ce("choose"),Q(!0)},className:"w-full flex items-center justify-center gap-2 bg-white hover:bg-[#f8fafc] text-[#475569] border border-[#cbd5e1] hover:border-[#94a3b8] text-[13px] font-semibold rounded-full px-4 py-3 shadow-[0_1px_4px_rgba(0,0,0,0.04)] transition-transform hover:scale-[1.02]",children:[e.jsx(to,{className:"w-4 h-4"})," Export Materials"]})}),T&&Qr.createPortal(e.jsxs("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center p-4",onClick:()=>Q(!1),children:[e.jsx("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm"}),e.jsxs("div",{className:"relative bg-white rounded-[24px] shadow-[0_24px_64px_rgba(0,0,0,0.18)] w-full max-w-[460px] z-10 overflow-hidden",onClick:L=>L.stopPropagation(),children:[e.jsx("div",{className:"bg-gradient-to-r from-[#a855f7] to-[#9333ea] px-6 pt-5 pb-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[ue==="bank"&&e.jsx("button",{onClick:()=>ce("choose"),className:"w-7 h-7 rounded-full bg-white/20 hover:bg-white/30 flex items-center justify-center text-white transition-colors mr-1",children:e.jsx(zs,{className:"w-4 h-4"})}),e.jsx("div",{className:"w-8 h-8 rounded-[8px] bg-white/20 flex items-center justify-center",children:e.jsx(Xr,{className:"w-4 h-4 text-white"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-[15px] font-bold text-white leading-tight",children:ue==="choose"?"Export Materials":"Choose a Quiz"}),e.jsx("p",{className:"text-[11px] text-white/70 font-medium",children:ue==="choose"?`For ${t.name}`:"Select a quiz from your bank"})]})]}),e.jsx("button",{onClick:()=>Q(!1),className:"w-7 h-7 rounded-full bg-white/20 hover:bg-white/30 flex items-center justify-center text-white transition-colors",children:e.jsx(Xt,{className:"w-4 h-4"})})]})}),e.jsx("div",{className:"p-6",children:ue==="choose"?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] text-[#64748b] mb-5 font-medium",children:"How would you like to proceed?"}),e.jsxs("button",{onClick:async()=>{Q(!1),ie.info("Generating PDF report...");try{const{getExportPDFData:L}=await Ss(async()=>{const{getExportPDFData:se}=await Promise.resolve().then(()=>om);return{getExportPDFData:se}},void 0),me=await L(t.id),{default:We}=await Ss(async()=>{const{default:se}=await import("./jspdf.es.min-C77sCDH3.js").then(rt=>rt.j);return{default:se}},__vite__mapDeps([12,0,1,2,3,4,5,6,7,8,9,10,11])),B=new We,kt=B.internal.pageSize.getWidth(),Me=20,M=kt-Me*2;let F=20;const ve=se=>{F+se>275&&(B.addPage(),F=20)},we=()=>{B.setDrawColor(200,200,200),B.line(Me,F,kt-Me,F),F+=6},qe=(se,rt=0)=>{const nt=B.splitTextToSize(se,M-rt);for(const ut of nt)ve(5),B.text(ut,Me+rt,F),F+=5},je=se=>{ve(16),F+=4,B.setFillColor(99,102,241),B.roundedRect(Me,F-4,M,10,2,2,"F"),B.setTextColor(255,255,255),B.setFontSize(11),B.setFont("helvetica","bold"),B.text(se,Me+4,F+3),B.setTextColor(0,0,0),F+=12};B.setFillColor(79,70,229),B.rect(0,0,kt,38,"F"),B.setTextColor(255,255,255),B.setFontSize(20),B.setFont("helvetica","bold"),B.text("MathPulse AI",Me,16),B.setFontSize(11),B.setFont("helvetica","normal"),B.text("Student Intervention Report",Me,24),B.setFontSize(9),B.text(`Generated: ${new Date().toLocaleDateString("en-US",{year:"numeric",month:"long",day:"numeric"})}`,Me,32),B.setTextColor(0,0,0),F=48,je("Student Profile"),B.setFontSize(10),B.setFont("helvetica","normal");const yt=[["Name",me.student_name],["Grade Level",me.grade_level||"N/A"],["Section",me.section||"N/A"],["Risk Level",me.risk_level],["Average Score",`${me.avg_score}%`],["Engagement",me.engagement_level],["Weakest Topic",ys(me.weakest_topic||"N/A")],["Last Active",me.last_active?new Date(me.last_active).toLocaleDateString():"Unknown"]];for(const[se,rt]of yt)ve(6),B.setFont("helvetica","bold"),B.text(`${se}:`,Me+2,F),B.setFont("helvetica","normal"),B.text(String(rt),Me+45,F),F+=6;if(F+=4,me.weak_topics?.length||Object.keys(me.accuracy_by_topic||{}).length){if(je("Risk Assessment & Topic Analysis"),B.setFontSize(10),me.weak_topics?.length){B.setFont("helvetica","bold"),B.text("Weak Topics:",Me+2,F),F+=6,B.setFont("helvetica","normal");for(const rt of me.weak_topics)ve(6),B.text(` • ${ys(rt)}`,Me+4,F),F+=5;F+=3}const se=Object.entries(me.accuracy_by_topic||{});if(se.length>0){B.setFont("helvetica","bold"),B.text("Topic Accuracy Breakdown:",Me+2,F),F+=7,B.setFontSize(9),B.setFont("helvetica","normal");for(const[rt,nt]of se.sort(([,ut],[,ws])=>ut-ws)){ve(7);const ut=60,ws=nt/100*ut;B.text(rt,Me+4,F),B.setFillColor(226,232,240),B.roundedRect(Me+70,F-3,ut,4,1,1,"F"),B.setFillColor(nt>=70?34:nt>=50?245:239,nt>=70?197:nt>=50?158:68,nt>=70?94:nt>=50?11:68),ws>0&&B.roundedRect(Me+70,F-3,ws,4,1,1,"F"),B.text(`${Math.round(nt)}%`,Me+70+ut+3,F),F+=7}F+=3}}if(je("AI Analysis & Insights"),B.setFontSize(10),me.learning_strengths&&(B.setFont("helvetica","bold"),B.text("Learning Strengths:",Me+2,F),F+=6,B.setFont("helvetica","normal"),qe(me.learning_strengths,4),F+=4),me.next_steps_summary&&(B.setFont("helvetica","bold"),ve(8),B.text("Recommended Next Steps:",Me+2,F),F+=6,B.setFont("helvetica","normal"),qe(me.next_steps_summary,4),F+=4),me.learning_path?.steps?.length){je("Personalized Learning Path"),B.setFontSize(9),B.setFont("helvetica","italic"),B.text(`Estimated Duration: ${me.learning_path.estimated_duration_days} days | Primary Focus: ${ys(me.learning_path.primary_weak_topic)}`,Me+2,F),F+=8,B.setFont("helvetica","normal"),B.setFontSize(10);for(const se of me.learning_path.steps){ve(18),B.setFillColor(99,102,241),B.circle(Me+6,F,3,"F"),B.setTextColor(255,255,255),B.setFontSize(8),B.text(String(se.step_number),Me+4.5,F+1.5),B.setTextColor(0,0,0),B.setFontSize(10),B.setFont("helvetica","bold"),B.text(ys(se.title),Me+14,F+1),B.setFont("helvetica","normal"),B.setFontSize(9);const rt=`${se.type.replace("_"," ")} • ${se.duration_minutes} min • ${se.difficulty}${se.competency_tag?` • ${se.competency_tag}`:""}`;if(B.setTextColor(100,116,139),B.text(rt,Me+14,F+6),B.setTextColor(0,0,0),F+=8,se.description){B.setFontSize(9);const nt=B.splitTextToSize(se.description,M-16);for(const ut of nt.slice(0,2))F+=5,ve(5),B.text(ut,Me+14,F)}F+=10}}if(me.teacher_recommendations?.length){je("Teacher Recommendations"),B.setFontSize(10),B.setFont("helvetica","normal");for(let se=0;se{Je(!0),ce("bank");try{const L=await vi(s);Ce(L)}catch{Ce([])}finally{Je(!1)}},className:"w-full flex items-start gap-4 p-4 rounded-[16px] border border-slate-200 hover:border-[#a855f7] hover:shadow-[0_4px_12px_rgba(168,85,247,0.08)] hover:bg-purple-50/30 transition-all group mb-3 text-left",children:[e.jsx("div",{className:"w-10 h-10 rounded-[10px] bg-purple-50 border border-purple-100 flex items-center justify-center shrink-0 group-hover:bg-purple-100 transition-colors",children:e.jsx(ur,{className:"w-5 h-5 text-[#a855f7]"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[14px] font-bold text-[#1e293b] mb-0.5",children:"Choose from existing quizzes"}),e.jsx("p",{className:"text-[12px] text-[#64748b] font-medium",children:"Pick a quiz already in your Quiz Bank."})]})]}),e.jsxs("button",{onClick:()=>{Q(!1),Nt(!1),Ge(!0)},className:"w-full flex items-start gap-4 p-4 rounded-[16px] border border-slate-200 hover:border-[#a855f7] hover:shadow-[0_4px_12px_rgba(168,85,247,0.08)] hover:bg-purple-50/30 transition-all group text-left",children:[e.jsx("div",{className:"w-10 h-10 rounded-[10px] bg-purple-50 border border-purple-100 flex items-center justify-center shrink-0 group-hover:bg-purple-100 transition-colors",children:e.jsx(ps,{className:"w-5 h-5 text-[#a855f7]"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[14px] font-bold text-[#1e293b] mb-0.5",children:"Create a new quiz"}),e.jsx("p",{className:"text-[12px] text-[#64748b] font-medium",children:"Use AI Quiz Maker. You can return here when done."})]})]})]}):e.jsx("div",{children:Ne?e.jsxs("div",{className:"flex flex-col items-center justify-center py-10 gap-3",children:[e.jsx("div",{className:"w-8 h-8 border-2 border-[#a855f7] border-t-transparent rounded-full animate-spin"}),e.jsx("p",{className:"text-[13px] text-[#64748b] font-medium",children:"Loading quizzes..."})]}):ae.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-10 gap-3 text-center",children:[e.jsx("div",{className:"w-12 h-12 rounded-full bg-purple-50 flex items-center justify-center",children:e.jsx(ur,{className:"w-6 h-6 text-[#a855f7]"})}),e.jsx("p",{className:"text-[14px] font-semibold text-[#1e293b]",children:"No quizzes yet"}),e.jsx("p",{className:"text-[12px] text-[#64748b]",children:"Create your first quiz using the AI Quiz Maker."})]}):e.jsx("div",{className:"space-y-3 max-h-[320px] overflow-y-auto pr-1",children:ae.map(L=>e.jsxs("div",{className:"flex items-center justify-between gap-3 p-4 rounded-[14px] border border-slate-200 hover:border-[#a855f7] hover:shadow-[0_2px_8px_rgba(168,85,247,0.08)] transition-all group",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-[13px] font-bold text-[#1e293b] truncate",children:L.title}),e.jsxs("p",{className:"text-[11px] text-[#64748b] font-medium mt-0.5",children:[L.questions?.length??0," questions",L.gradeLevel?` · ${L.gradeLevel}`:"",L.metadata?.topicsCovered?.[0]?` · ${L.metadata.topicsCovered[0]}`:""]})]}),e.jsx("button",{onClick:()=>{Q(!1),ie.success(`"${L.title}" selected for ${t.name}`)},className:"shrink-0 px-3 py-1.5 rounded-full bg-[#a855f7] text-white text-[11px] font-bold hover:bg-[#9333ea] transition-colors shadow-sm",children:"Assign"})]},L.id))})})})]})]}),document.body),$e&&Qr.createPortal(e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[9998] bg-black/40 backdrop-blur-sm",onClick:()=>{ft?jt(!0):Ge(!1)}}),e.jsxs("div",{className:"fixed top-0 right-0 z-[9999] h-full w-full max-w-[88vw] xl:max-w-[1080px] bg-white shadow-[-8px_0_40px_rgba(0,0,0,0.15)] flex flex-col",style:{animation:"slideInFromRight 0.3s cubic-bezier(0.16,1,0.3,1)"},children:[e.jsxs("div",{className:"flex items-center gap-3 px-6 py-4 border-b border-slate-100 bg-white shrink-0",children:[e.jsxs("button",{onClick:()=>{ft?jt(!0):Ge(!1)},className:"flex items-center gap-2 text-[13px] font-semibold text-[#4f46e5] hover:text-[#3730a3] transition-colors bg-indigo-50 hover:bg-indigo-100 px-4 py-2 rounded-full",children:[e.jsx(cr,{className:"w-4 h-4"}),"Back to ",t.name]}),e.jsx("div",{className:"h-5 w-px bg-slate-200"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-7 h-7 rounded-[8px] bg-gradient-to-br from-[#a855f7] to-[#9333ea] flex items-center justify-center",children:e.jsx(Xr,{className:"w-3.5 h-3.5 text-white"})}),e.jsx("span",{className:"text-[14px] font-bold text-[#1e293b]",children:"AI Quiz Maker"})]}),ft&&e.jsx("span",{className:"ml-auto text-[11px] font-semibold text-amber-600 bg-amber-50 border border-amber-200 px-2.5 py-0.5 rounded-full",children:"Quiz in progress"})]}),e.jsx("div",{className:"flex-1 overflow-hidden",children:e.jsx(fl,{onBack:()=>Ge(!1),drawerMode:!0,gradeLevel:t.grade,onQuizGenerating:()=>Nt(!0),onQuizSaved:L=>{Nt(!1),ie.success("Quiz saved! Close this panel or create another.",{action:{label:"Close Panel",onClick:()=>Ge(!1)}})}})})]}),dt&&e.jsxs("div",{className:"fixed inset-0 z-[10000] flex items-center justify-center p-4",children:[e.jsx("div",{className:"absolute inset-0 bg-black/60",onClick:()=>jt(!1)}),e.jsxs("div",{className:"relative bg-white rounded-[20px] shadow-[0_24px_60px_rgba(0,0,0,0.2)] w-full max-w-[380px] p-7 z-10",children:[e.jsx("div",{className:"w-11 h-11 rounded-full bg-amber-50 border border-amber-200 flex items-center justify-center mb-4",children:e.jsx(br,{className:"w-5 h-5 text-amber-500"})}),e.jsx("h3",{className:"text-[16px] font-bold text-[#1e293b] mb-2",children:"Discard quiz progress?"}),e.jsx("p",{className:"text-[13px] text-[#64748b] font-medium mb-6",children:"Your current quiz session will be lost if you close this panel. This cannot be undone."}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx("button",{onClick:()=>jt(!1),className:"flex-1 py-2.5 rounded-full border border-slate-200 text-[13px] font-semibold text-[#475569] hover:bg-slate-50 transition-colors",children:"Keep editing"}),e.jsx("button",{onClick:()=>{jt(!1),Ge(!1),Nt(!1)},className:"flex-1 py-2.5 rounded-full bg-rose-500 hover:bg-rose-600 text-white text-[13px] font-semibold transition-colors",children:"Discard & close"})]})]})]}),e.jsx("style",{children:` +${me}`:We.learningPath;g(B)}catch{g("Unable to generate learning path. Please try again later."),le("")}finally{z(!1)}})()},[t]);const Ts=u.useCallback(async()=>{be(!0),de("");try{const L=t.classSectionId||Ft(R||"Grade 11",f||"Section A"),me=t.struggles.length>0?t.struggles[0]:t.weakestTopic,We=await Lo({gradeLevel:R||t.grade||"Grade 11",subject:"general_math",quarter:1,moduleUnit:[R,f].filter(Boolean).join(" - ")||t.className,lessonTitle:`Grounded Lesson: ${me}`,learningCompetency:me,learnerLevel:t.avgScore<60?"support":t.avgScore<80?"developing":"advanced",classSectionId:L,className:[R,f].filter(Boolean).join(" - ")||t.className,focusTopics:t.struggles.length>0?t.struggles:[t.weakestTopic],topicCount:5,preferImportedTopics:m.lessonEnabled,allowReviewSources:Re,allowUnverifiedLesson:Pe},!0);y(We),J(We.curriculumSources||[]),E(null),xt.reportImportGroundedFeedback({flow:"lesson",status:"success",classSectionId:L,className:[R,f].filter(Boolean).join(" - ")||t.className,metadata:{usedImportedTopics:We.usedImportedTopics,importedTopicCount:We.importedTopicCount,blockCount:We.blocks.length,publishReady:We.publishReady,sourceLegitimacyStatus:We.sourceLegitimacy.status,selfValidationPassed:We.selfValidation.passed,importGroundingEnabled:m.lessonEnabled}})}catch(L){let me=L instanceof Error?L.message:"Unable to generate lesson plan at this time.";if(L instanceof rr&&L.status===422)try{const B=JSON.parse(L.responseBody)?.detail;if(B?.selfValidation&&!Pe)try{const F=t.classSectionId||Ft(R||"Grade 11",f||"Section A"),ve=t.struggles.length>0?t.struggles[0]:t.weakestTopic,we=await Lo({gradeLevel:R||t.grade||"Grade 11",subject:"general_math",quarter:1,moduleUnit:[R,f].filter(Boolean).join(" - ")||t.className,lessonTitle:`Grounded Lesson: ${ve}`,learningCompetency:ve,learnerLevel:t.avgScore<60?"support":t.avgScore<80?"developing":"advanced",classSectionId:F,className:[R,f].filter(Boolean).join(" - ")||t.className,focusTopics:t.struggles.length>0?t.struggles:[t.weakestTopic],topicCount:5,preferImportedTopics:m.lessonEnabled,allowReviewSources:Re,allowUnverifiedLesson:!0},!0);y(we),J(we.curriculumSources||[]),E(null),de("");return}catch{}B?.message&&(me=B.message);const kt=B?.sourceLegitimacy?.issues||[],Me=B?.selfValidation?.issues||[],M=[...kt,...Me].filter(Boolean).slice(0,3);M.length>0&&(me=`${me} ${M.join(" ")}`)}catch{}de(me),y(null),J([]),xt.reportImportGroundedFeedback({flow:"lesson",status:"failed",classSectionId:t.classSectionId||Ft(R||"Grade 11",f||"Section A"),className:[R,f].filter(Boolean).join(" - ")||t.className,metadata:{error:me,allowReviewSources:Re,allowUnverifiedLesson:Pe,importGroundingEnabled:m.lessonEnabled}})}finally{be(!1)}},[t,R,f,m.lessonEnabled,Re,Pe]),bs=u.useCallback(async()=>{if(!A)return ie.error("Generate a lesson plan first."),null;V(!0);try{const L=await pm(A,s,{teacherName:a,studentId:t.id,studentName:t.name});return E(L),ie.success("Lesson plan saved as draft."),L}catch(L){return console.error("Failed to save lesson draft:",L),ie.error(L instanceof Error?L.message:"Failed to save lesson draft."),null}finally{V(!1)}},[A,s,a,t.id,t.name]),Bs=u.useCallback(async()=>{if(!A){ie.error("Generate a lesson plan first.");return}if(!A.publishReady){const L=[...A.sourceLegitimacy.issues,...A.selfValidation.issues].filter(Boolean).slice(0,2).join(" ");ie.error(L||"Lesson is not publish-ready. Resolve legitimacy and validation checks first.");return}D(!0);try{let L=te;if(L||(L=await bs()),!L)return;await hm(L),ie.success("Lesson plan published to class content."),xt.reportImportGroundedFeedback({flow:"lesson",status:"success",classSectionId:A.classSectionId||t.classSectionId,className:A.className||t.className,metadata:{action:"publish_lesson_plan",lessonPlanId:L,publishReady:A.publishReady,sourceLegitimacyStatus:A.sourceLegitimacy.status,selfValidationPassed:A.selfValidation.passed}})}catch(L){console.error("Failed to publish lesson plan:",L),ie.error(L instanceof Error?L.message:"Failed to publish lesson plan."),xt.reportImportGroundedFeedback({flow:"lesson",status:"failed",classSectionId:A.classSectionId||t.classSectionId,className:A.className||t.className,metadata:{action:"publish_lesson_plan",error:L instanceof Error?L.message:"Failed to publish lesson plan."}})}finally{D(!1)}},[A,te,bs,t.className,t.classSectionId]);u.useEffect(()=>{Ts()},[j]),u.useEffect(()=>{_(L=>L+1)},[t.id]),u.useEffect(()=>{H("all"),oe("all")},[A]),u.useMemo(()=>A?Array.from(new Set(A.blocks.map(L=>L.provenance?.sourceFile?.trim()).filter(L=>!!L))).sort((L,me)=>L.localeCompare(me)):[],[A]),u.useMemo(()=>A?Array.from(new Set(A.blocks.map(L=>L.provenance?.materialId?.trim()).filter(L=>!!L))).sort((L,me)=>L.localeCompare(me)):[],[A]);const ns=u.useMemo(()=>A?A.blocks.filter(L=>{const me=fe==="all"||(L.provenance?.sourceFile||"").trim()===fe,We=ee==="all"||(L.provenance?.materialId||"").trim()===ee;return me&&We}):[],[A,fe,ee]),vs=u.useMemo(()=>p?.learning_path?.steps?.length?p.learning_path.steps.map(L=>({id:L.step_number,type:L.type==="video_lesson"?"video":L.type==="assessment"?"assessment":"quiz",title:L.title,duration:`${L.duration_minutes} mins`,questions:L.num_items||void 0,icon:L.type==="video_lesson"?Za:L.type==="assessment"?ya:L.type==="review"?cs:qr,competency:L.competency_tag,difficulty:L.difficulty,is_completed:L.is_completed})):[{id:1,type:"video",title:`${t.weakestTopic} Fundamentals`,duration:"8 mins",questions:void 0,icon:Za,competency:"",difficulty:"easy",is_completed:!1},{id:2,type:"quiz",title:`${t.weakestTopic} Practice`,duration:"12 mins",questions:10,icon:qr,competency:"",difficulty:"easy",is_completed:!1},{id:3,type:"assessment",title:"Final Check",duration:"10 mins",questions:5,icon:ya,competency:"",difficulty:"medium",is_completed:!1}],[p,t.weakestTopic]),os=async()=>{if(!s){ie.error("Unable to update section: teacher context missing");return}$(!0);try{await yr(t.id,R,f,s,new Date().getFullYear().toString(),a),await il(t.id,R,f);const L={...t,grade:R,section:f,className:[R,f].filter(Boolean).join(" - "),classSectionId:Ft(R,f)};r(L),ie.success("Student section assignment updated")}catch(L){console.error("Failed to update student section assignment:",L),ie.error("Failed to update section assignment")}finally{$(!1)}};return e.jsxs(Le.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"w-full h-full flex overflow-hidden relative",children:[e.jsx("div",{className:"flex-1 overflow-y-auto p-[24px] xl:p-[32px] no-scrollbar",children:e.jsxs("div",{className:"max-w-[1000px] mx-auto space-y-[24px]",children:[e.jsx("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4 mb-[8px]",children:e.jsx("div",{children:e.jsxs("button",{onClick:o,className:"flex items-center gap-2 text-[13px] font-semibold text-[#4f46e5] hover:text-[#3730a3] transition-colors bg-white/60 hover:bg-white/80 px-[18px] py-2 rounded-full backdrop-blur-[12px] mb-[16px] w-max shadow-[0_1px_4px_rgba(0,0,0,0.04)] border border-white/50",children:[e.jsx(cr,{className:"w-4 h-4"}),"Back to Analytics"]})})}),e.jsxs("div",{className:"bg-gradient-to-br from-[#ecfdf5] via-[#f0fdf4] to-[#f7fdf9] backdrop-blur-[12px] rounded-[20px] p-[24px] border border-emerald-100 shadow-[0_4px_16px_rgba(16,185,129,0.08)] relative overflow-hidden",children:[e.jsx("div",{className:"absolute right-[-20px] bottom-[-20px] opacity-[0.06] pointer-events-none",children:e.jsx(Fn,{className:"w-48 h-48 text-emerald-600"})}),e.jsxs("div",{className:"flex items-center gap-3 mb-5 relative z-10",children:[e.jsx("div",{className:"w-10 h-10 rounded-[12px] bg-gradient-to-br from-[#059669] to-[#10b981] flex items-center justify-center shrink-0 shadow-[0_4px_10px_rgba(5,150,105,0.3)]",children:e.jsx(Fn,{className:"w-5 h-5 text-white"})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"text-[15px] font-bold text-[#1e293b]",children:"AI Analysis"}),e.jsxs("span",{className:"flex items-center gap-1 px-2.5 py-0.5 bg-emerald-500 text-white text-[10px] font-bold rounded-full uppercase tracking-wider shadow-sm",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-white animate-pulse"}),"Insights Active"]})]})]}),re&&e.jsx(zo,{sources:q,className:"mb-4 relative z-10"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4 w-full relative z-10",children:[e.jsxs("div",{className:"bg-white/70 backdrop-blur-sm rounded-[14px] p-4 border border-emerald-100/60 shadow-[0_1px_4px_rgba(0,0,0,0.04)] relative overflow-hidden",children:[e.jsx("div",{className:"absolute left-0 top-0 w-1 h-full bg-emerald-400 rounded-l-[14px]"}),e.jsxs("h4",{className:"text-[11px] font-bold text-emerald-600 uppercase tracking-wider mb-2.5 flex items-center gap-1.5 pl-2",children:[e.jsx(la,{className:"w-3.5 h-3.5"})," Learning Strengths"]}),e.jsx("p",{className:"text-[13px] text-[#475569] leading-relaxed pl-2",children:p?.learning_strengths||(d?e.jsx(e.Fragment,{children:"Demonstrates engagement but faces challenges. Needs support with foundational topics."}):e.jsxs(e.Fragment,{children:["Excels in ",e.jsx("span",{className:"font-semibold text-[#1e293b]",children:t.weakestTopic}),". Demonstrates high engagement during interactive tests."]}))})]}),e.jsxs("div",{className:"bg-white/70 backdrop-blur-sm rounded-[14px] p-4 border border-rose-100/60 shadow-[0_1px_4px_rgba(0,0,0,0.04)] relative overflow-hidden",children:[e.jsx("div",{className:"absolute left-0 top-0 w-1 h-full bg-rose-400 rounded-l-[14px]"}),e.jsxs("h4",{className:"text-[11px] font-bold text-rose-500 uppercase tracking-wider mb-2.5 flex items-center gap-1.5 pl-2",children:[e.jsx(ms,{className:"w-3.5 h-3.5"})," Next Steps"]}),e.jsx("ul",{className:"text-[13px] text-[#475569] leading-relaxed list-none p-0 m-0 space-y-1 pl-2",children:p?.next_steps_summary?e.jsx("li",{children:p.next_steps_summary}):t.struggles.length>0?t.struggles.map((L,me)=>e.jsxs("li",{children:["Must continue strengthening ",e.jsx("span",{className:"font-semibold text-[#1e293b]",children:L}),"."]},me)):e.jsxs("li",{children:["Focus on repetitive practice modules for ",e.jsx("span",{className:"font-semibold text-[#1e293b]",children:t.weakestTopic}),"."]})})]})]})]}),e.jsxs("div",{className:"bg-white/80 backdrop-blur-[12px] rounded-[18px] p-[24px] shadow-[0_1px_4px_rgba(0,0,0,0.04)] border border-white",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6 border-b border-[#f1f5f9] pb-4",children:[e.jsx("h3",{className:"text-[15px] font-semibold text-[#1e293b]",children:"Generated Learning Path"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{disabled:!p?.learning_path,onClick:async()=>{if(p)try{await xl(p,s),ie.success(`Learning path assigned to ${t.name}'s modules.`)}catch(L){console.error("[InterventionView] Assign failed:",L),ie.error("Failed to assign learning path.")}},className:"bg-emerald-50 hover:bg-emerald-100 text-emerald-700 border border-emerald-200 text-[11px] font-semibold rounded-full px-4 py-1.5 transition-colors shadow-[0_1px_4px_rgba(0,0,0,0.02)] flex items-center gap-1.5 disabled:opacity-50",children:[e.jsx(aa,{className:"w-3 h-3"})," Assign to Student"]}),e.jsxs("button",{disabled:I||b,onClick:async()=>{S(!0);try{const L=await ml(t.id);h(L)}catch(L){console.warn("[InterventionView] Regenerate failed:",L)}finally{S(!1)}_(L=>L+1)},className:"bg-[#f8fafc] hover:bg-white text-[#4f46e5] border border-[#e0e7ff] text-[11px] font-semibold rounded-full px-4 py-1.5 transition-colors shadow-[0_1px_4px_rgba(0,0,0,0.02)] flex items-center gap-1.5 disabled:opacity-50",children:[e.jsx(cs,{className:`w-3 h-3 ${b?"animate-spin":""}`})," ",b?"Analyzing...":"Regenerate"]})]})]}),e.jsxs(Eo,{name:"teacher-intervention-learning-path",loading:!1,fixture:null,fallback:null,children:[e.jsxs("div",{className:"mb-8 flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"text-[11px] font-semibold text-[#64748b] uppercase tracking-wider mr-2",children:"Methodology:"}),(p?.learning_path?.methodology_tags||["Interactive","Video","Practice","Quiz"]).map(L=>e.jsx("span",{className:"px-3 py-1 bg-[#f8fafc] text-[#475569] text-[11px] font-semibold rounded-full border border-[#e2e8f0]",children:L},L))]}),e.jsx("div",{className:"relative border-l-2 border-[#e2e8f0] ml-[20px] space-y-[28px] pb-4",children:vs.map((L,me)=>{let We=e.jsx(Za,{className:"w-4 h-4"}),B="bg-[#8b5cf6] shadow-[0_4px_10px_rgba(139,92,246,0.3)]",kt="text-purple-600",Me="group-hover:border-purple-200",M="hover:bg-[#4f46e5]",F=e.jsx(dc,{className:"w-4 h-4 ml-0.5"});return L.type==="quiz"?(We=e.jsx(ir,{className:"w-4 h-4"}),B="bg-sky-500 shadow-[0_4px_10px_rgba(14,165,233,0.3)]",kt="text-sky-600",Me="group-hover:border-sky-200",M="hover:bg-sky-500",F=e.jsx(Ms,{className:"w-4 h-4"})):L.type==="assessment"&&(We=e.jsx(ya,{className:"w-4 h-4"}),B="bg-emerald-500 shadow-[0_4px_10px_rgba(16,185,129,0.3)]",kt="text-emerald-600",Me="group-hover:bg-emerald-50"),e.jsxs(Le.div,{initial:{opacity:0,x:-20},animate:{opacity:1,x:0},transition:{delay:me*.1},className:"relative pl-[32px] group",children:[e.jsx("div",{className:`absolute -left-[17px] top-1 w-8 h-8 rounded-full ${B} text-white flex items-center justify-center ring-4 ring-white group-hover:scale-110 transition-transform`,children:We}),e.jsxs("div",{onClick:()=>{p?.learning_path?.steps?.[me]&&N(p.learning_path.steps[me])},className:`${L.type==="assessment"?"bg-emerald-50/50 border-emerald-100":"bg-white border-[#f1f5f9]"} rounded-[14px] p-[18px] border shadow-[0_1px_4px_rgba(0,0,0,0.04)] flex justify-between items-center transition-colors cursor-pointer ${Me}`,children:[e.jsxs("div",{children:[e.jsxs("span",{className:`text-[10px] font-semibold uppercase tracking-wider mb-1 block ${kt}`,children:["Step ",me+1," • ",L.type==="video"?"Video Lesson":L.type==="quiz"?"Practice":"Assessment"]}),e.jsx("p",{className:"font-semibold text-[#1e293b] text-[13px] mb-0.5",children:ys(L.title)}),e.jsxs("p",{className:"text-[#64748b] text-[11px] flex items-center gap-1.5",children:[L.type==="video"&&e.jsxs(e.Fragment,{children:[e.jsx(As,{className:"w-3 h-3"})," ",L.duration]}),L.type==="quiz"&&e.jsxs(e.Fragment,{children:[e.jsx(yi,{className:"w-3 h-3"})," ",L.questions?`${L.questions} questions`:L.duration]}),L.type==="assessment"&&e.jsxs(e.Fragment,{children:[e.jsx(ms,{className:"w-3 h-3"})," ",L.questions?`${L.questions} assessment questions`:L.duration]}),L.competency&&e.jsx("span",{className:"ml-2 px-1.5 py-0.5 bg-indigo-50 text-indigo-600 text-[9px] font-mono rounded",children:L.competency})]})]}),L.type==="assessment"?e.jsx(xi,{className:"w-6 h-6 text-emerald-400"}):e.jsx("button",{className:`w-8 h-8 rounded-full bg-[#f8fafc] flex items-center justify-center text-[#64748b] ${M} hover:text-white transition-colors border border-[#e2e8f0]`,children:F})]})]},L.id)})})]})]}),e.jsxs("div",{className:"relative bg-white/80 backdrop-blur-[12px] rounded-[18px] p-[24px] shadow-[0_1px_4px_rgba(0,0,0,0.04)] border border-white overflow-hidden",children:[e.jsx("div",{className:"absolute inset-0 z-10 bg-white/70 backdrop-blur-[2px] flex items-center justify-center rounded-[18px]",children:e.jsxs("div",{className:"text-center",children:[e.jsx("span",{className:"inline-block px-4 py-2 bg-slate-100 border border-slate-200 rounded-full text-[13px] font-semibold text-slate-500",children:"🔒 Coming Soon"}),e.jsx("p",{className:"text-[11px] text-slate-400 mt-2",children:"This feature is temporarily locked."})]})}),e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("h3",{className:"text-[15px] font-semibold text-[#1e293b]",children:"Targeted Lesson Generation"}),e.jsx(St,{onClick:()=>_(L=>L+1),disabled:ne,className:"bg-[#4f46e5] hover:bg-[#3730a3] text-white h-8 text-[11px] rounded-full px-4",children:ne?"Loading...":"Regenerate"})]}),e.jsx("p",{className:"text-[13px] text-[#64748b] mb-6",children:"Configure inputs and requirements for AI lesson generation."}),e.jsxs("div",{className:"bg-[#f8fafc]/80 rounded-[14px] p-[20px] border border-[#f1f5f9] mb-6",children:[e.jsxs("div",{className:"flex items-start gap-3 mb-4",children:[e.jsx(na,{className:"w-4 h-4 text-[#4f46e5] shrink-0 mt-0.5"}),e.jsxs("p",{className:"text-[13px] text-[#475569] leading-relaxed",children:["Class records alone are not enough for import-grounded lesson plans. Ensure course materials are uploaded via ",e.jsx("span",{className:"text-[#4f46e5] font-semibold",children:"Data Import"}),"."]})]}),e.jsxs("div",{className:"space-y-4 border-t border-[#e2e8f0] pt-5 mt-5",children:[e.jsxs("label",{className:"flex items-center justify-between cursor-pointer group",children:[e.jsx("span",{className:"text-[13px] font-medium text-[#1e293b] group-hover:text-[#4f46e5] transition-colors",children:"Allow sources requiring manual review"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:"checkbox",className:"sr-only peer",checked:Re,onChange:L=>Fe(L.target.checked)}),e.jsx("div",{className:"w-10 h-5 bg-slate-200 peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-[#4f46e5]"})]})]}),e.jsxs("label",{className:"flex items-center justify-between cursor-pointer group",children:[e.jsx("span",{className:"text-[13px] font-medium text-[#1e293b] group-hover:text-[#4f46e5] transition-colors",children:"Allow unverified lesson draft"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:"checkbox",className:"sr-only peer",checked:Pe,onChange:L=>G(L.target.checked)}),e.jsx("div",{className:"w-10 h-5 bg-slate-200 peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-[#4f46e5]"})]})]})]})]}),e.jsxs(Eo,{name:"teacher-intervention-lesson-plan",loading:!1,fixture:null,fallback:null,children:[Ie&&e.jsx("div",{className:"bg-[#FF8B8B]/14 border border-[#FF8B8B]/35 rounded-xl p-3 text-sm text-[#D66A6A] mb-4",children:Ie}),A&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"bg-[#f8fafc] border border-[#f1f5f9] rounded-[14px] p-5 shadow-[0_1px_4px_rgba(0,0,0,0.02)]",children:[e.jsx("div",{className:"mb-3",children:e.jsx(zo,{sources:q})}),e.jsx("p",{className:"text-[14px] font-semibold text-[#1e293b]",children:A.lessonTitle}),e.jsxs("div",{className:"flex flex-wrap gap-x-4 gap-y-2 mt-2",children:[e.jsxs("p",{className:"text-[11px] text-[#64748b]",children:[e.jsx("span",{className:"font-semibold text-[#475569]",children:"Imported topics:"})," ",A.usedImportedTopics?"Yes":"No"," (",A.importedTopicCount,")"]}),e.jsxs("p",{className:"text-[11px] text-[#64748b]",children:[e.jsx("span",{className:"font-semibold text-[#475569]",children:"Subject:"})," ",A.subject||"General Math"," (Q",A.quarter||1,")"]})]}),A.curriculumCompetency&&e.jsxs("p",{className:"text-[11px] text-[#4f46e5] font-semibold mt-2 bg-indigo-50/50 px-2 py-1 rounded inline-block",children:["Competency: ",A.curriculumCompetency]}),e.jsx("div",{className:"mt-3 flex items-center justify-between",children:e.jsxs("p",{className:"text-[11px] text-[#64748b]",children:["Publish readiness: ",e.jsx("span",{className:`font-semibold ${A.publishReady?"text-emerald-600":"text-rose-500"}`,children:A.publishReady?"Ready":"Blocked"})]})}),A.warnings.length>0&&e.jsx("p",{className:"text-[11px] text-amber-600 mt-2 bg-amber-50 px-2 py-1.5 rounded",children:A.warnings.join(" ")})]}),A.lessonObjective&&e.jsxs("div",{className:"bg-white border border-[#e2e8f0] rounded-[14px] p-4 shadow-[0_1px_4px_rgba(0,0,0,0.02)]",children:[e.jsx("p",{className:"text-[10px] font-semibold text-[#64748b] uppercase tracking-wider mb-1.5",children:"Lesson objective"}),e.jsx("p",{className:"text-[13px] text-[#1e293b]",children:A.lessonObjective})]}),A.realWorldHook&&e.jsxs("div",{className:"bg-indigo-50/50 border border-indigo-100 rounded-[14px] p-4 shadow-[0_1px_4px_rgba(0,0,0,0.02)]",children:[e.jsx("p",{className:"text-[10px] font-semibold text-[#4f46e5] uppercase tracking-wider mb-1.5",children:"Real-life application"}),e.jsx("p",{className:"text-[13px] text-[#1e293b]",children:A.realWorldHook})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3 mt-4",children:ns.map(L=>e.jsxs("div",{className:"border border-[#e2e8f0] rounded-[14px] p-4 bg-white shadow-[0_1px_4px_rgba(0,0,0,0.02)]",children:[e.jsx("h3",{className:"text-[13px] font-semibold text-[#1e293b]",children:L.title}),e.jsxs("p",{className:"text-[11px] text-[#64748b] mt-1",children:[L.estimatedMinutes," mins "," • "," ",L.strategy]}),e.jsx("p",{className:"text-[12px] text-[#475569] mt-2 bg-[#f8fafc] p-2 rounded-lg",children:L.objective}),e.jsxs("div",{className:"mt-3",children:[e.jsx("p",{className:"text-[10px] font-semibold text-[#64748b] uppercase tracking-wider mb-1.5",children:"Activities"}),L.activities.slice(0,2).map((me,We)=>e.jsxs("p",{className:"text-[11px] text-[#475569] mb-1 flex items-start gap-1",children:[e.jsx("span",{className:"text-[#94a3b8] mt-0.5",children:"•"})," ",e.jsx("span",{children:me})]},We))]})]},L.blockId))}),e.jsxs("div",{className:"flex flex-wrap gap-2 pt-4",children:[e.jsx(St,{variant:"outline",onClick:()=>void bs(),disabled:Y||!A,className:"border-[#cbd5e1] text-[#475569] hover:bg-[#f8fafc] text-[12px] h-9 rounded-full px-5",children:Y?e.jsx(Bn,{className:"h-4 w-16"}):"Save Draft"}),e.jsx(St,{onClick:()=>void Bs(),disabled:pe||!A||!A.publishReady,className:"bg-[#10b981] hover:bg-[#059669] text-white text-[12px] h-9 rounded-full px-5",children:pe?e.jsx(Bn,{className:"h-4 w-24 bg-white/35"}):"Publish Lesson Plan"})]})]})]})]})]})}),e.jsx("aside",{className:"w-[320px] 2xl:w-[340px] bg-white/70 backdrop-blur-[24px] border-l border-white shadow-[-4px_0_24px_rgba(0,0,0,0.02)] flex flex-col h-full shrink-0 overflow-y-auto z-10 no-scrollbar relative",children:e.jsxs("div",{className:"p-[24px] space-y-[24px] flex flex-col items-center",children:[e.jsxs("div",{className:"flex flex-col items-center text-center w-full",children:[e.jsx("img",{src:t.avatar,alt:t.name,className:"w-[96px] h-[96px] rounded-full object-cover shadow-[0_8px_16px_rgba(0,0,0,0.1)] mb-4 border-4 border-white z-10 relative"}),e.jsx("h2",{className:"text-[20px] font-semibold text-[#1e293b] mb-1",children:t.name}),e.jsxs("p",{className:"text-[11px] font-semibold text-[#64748b] mb-3 uppercase tracking-wider",children:["ID: ",t.id.substring(0,8)]}),e.jsx("span",{className:`text-[11px] font-semibold px-3 py-1 rounded-[14px] border ${(p?.risk_level||"").includes("Critical")?"text-red-700 bg-red-50 border-red-200 animate-pulse":t.riskLevel==="high"||(p?.risk_level||"").includes("High")?"text-rose-600 bg-rose-50 border-rose-100":t.riskLevel==="medium"||(p?.risk_level||"").includes("Medium")?"text-amber-600 bg-amber-50 border-amber-100":"text-emerald-600 bg-emerald-50 border-emerald-100"}`,children:p?.risk_level||(t.riskLevel==="high"?"High Risk":t.riskLevel==="medium"?"Medium Risk":"Low Risk")})]}),e.jsxs("div",{className:"w-full grid grid-cols-2 gap-[12px]",children:[e.jsxs("div",{className:"bg-white/80 rounded-[14px] p-4 border border-white shadow-[0_1px_4px_rgba(0,0,0,0.02)] text-left flex flex-col justify-center",children:[e.jsx("p",{className:"text-[11px] font-semibold text-[#64748b] uppercase tracking-wider mb-1",children:"Avg Score"}),e.jsxs("p",{className:"text-[20px] font-bold text-[#4f46e5]",children:[p?.avg_score||Lt||t.avgScore,"%"]})]}),e.jsxs("div",{className:"bg-white/80 rounded-[14px] p-4 border border-white shadow-[0_1px_4px_rgba(0,0,0,0.02)] text-left flex flex-col justify-center",children:[e.jsx("p",{className:"text-[11px] font-semibold text-[#64748b] uppercase tracking-wider mb-1",children:"Engagement"}),e.jsx("p",{className:"text-[20px] font-bold text-[#1e293b]",children:p?.engagement_level||((Lt||t.avgScore)>80?"High":(Lt||t.avgScore)>50?"Medium":"Low")})]}),e.jsxs("div",{className:"bg-white/80 rounded-[14px] p-4 border border-white shadow-[0_1px_4px_rgba(0,0,0,0.02)] text-left flex flex-col justify-center",children:[e.jsx("p",{className:"text-[11px] font-semibold text-[#64748b] uppercase tracking-wider mb-1",children:"Last Active"}),e.jsx("p",{className:"text-[13px] font-semibold text-[#1e293b] mt-1",children:p?.last_active?new Date(p.last_active).toLocaleDateString():t.lastActive})]}),e.jsxs("div",{className:"bg-rose-50/60 rounded-[14px] p-4 border border-rose-100 text-left flex flex-col justify-center",children:[e.jsx("p",{className:"text-[11px] font-semibold text-rose-600 uppercase tracking-wider mb-1",children:"Weakest Topic"}),e.jsx("p",{className:"text-[12px] font-semibold text-[#1e293b] mt-1 leading-snug break-words",title:p?.weakest_topic||t.weakestTopic,children:ys(p?.weakest_topic||t.weakestTopic||"")})]})]}),e.jsx("div",{className:"w-full flex flex-col gap-[10px]",children:e.jsxs("button",{onClick:async()=>{ce("choose"),Q(!0)},className:"w-full flex items-center justify-center gap-2 bg-white hover:bg-[#f8fafc] text-[#475569] border border-[#cbd5e1] hover:border-[#94a3b8] text-[13px] font-semibold rounded-full px-4 py-3 shadow-[0_1px_4px_rgba(0,0,0,0.04)] transition-transform hover:scale-[1.02]",children:[e.jsx(to,{className:"w-4 h-4"})," Export Materials"]})}),T&&Qr.createPortal(e.jsxs("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center p-4",onClick:()=>Q(!1),children:[e.jsx("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm"}),e.jsxs("div",{className:"relative bg-white rounded-[24px] shadow-[0_24px_64px_rgba(0,0,0,0.18)] w-full max-w-[460px] z-10 overflow-hidden",onClick:L=>L.stopPropagation(),children:[e.jsx("div",{className:"bg-gradient-to-r from-[#a855f7] to-[#9333ea] px-6 pt-5 pb-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[ue==="bank"&&e.jsx("button",{onClick:()=>ce("choose"),className:"w-7 h-7 rounded-full bg-white/20 hover:bg-white/30 flex items-center justify-center text-white transition-colors mr-1",children:e.jsx(zs,{className:"w-4 h-4"})}),e.jsx("div",{className:"w-8 h-8 rounded-[8px] bg-white/20 flex items-center justify-center",children:e.jsx(Xr,{className:"w-4 h-4 text-white"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-[15px] font-bold text-white leading-tight",children:ue==="choose"?"Export Materials":"Choose a Quiz"}),e.jsx("p",{className:"text-[11px] text-white/70 font-medium",children:ue==="choose"?`For ${t.name}`:"Select a quiz from your bank"})]})]}),e.jsx("button",{onClick:()=>Q(!1),className:"w-7 h-7 rounded-full bg-white/20 hover:bg-white/30 flex items-center justify-center text-white transition-colors",children:e.jsx(Xt,{className:"w-4 h-4"})})]})}),e.jsx("div",{className:"p-6",children:ue==="choose"?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] text-[#64748b] mb-5 font-medium",children:"How would you like to proceed?"}),e.jsxs("button",{onClick:async()=>{Q(!1),ie.info("Generating PDF report...");try{const{getExportPDFData:L}=await Ss(async()=>{const{getExportPDFData:se}=await Promise.resolve().then(()=>om);return{getExportPDFData:se}},void 0),me=await L(t.id),{default:We}=await Ss(async()=>{const{default:se}=await import("./jspdf.es.min-IqJLf-7q.js").then(rt=>rt.j);return{default:se}},__vite__mapDeps([12,0,1,2,3,4,5,6,7,8,9,10,11])),B=new We,kt=B.internal.pageSize.getWidth(),Me=20,M=kt-Me*2;let F=20;const ve=se=>{F+se>275&&(B.addPage(),F=20)},we=()=>{B.setDrawColor(200,200,200),B.line(Me,F,kt-Me,F),F+=6},qe=(se,rt=0)=>{const nt=B.splitTextToSize(se,M-rt);for(const ut of nt)ve(5),B.text(ut,Me+rt,F),F+=5},je=se=>{ve(16),F+=4,B.setFillColor(99,102,241),B.roundedRect(Me,F-4,M,10,2,2,"F"),B.setTextColor(255,255,255),B.setFontSize(11),B.setFont("helvetica","bold"),B.text(se,Me+4,F+3),B.setTextColor(0,0,0),F+=12};B.setFillColor(79,70,229),B.rect(0,0,kt,38,"F"),B.setTextColor(255,255,255),B.setFontSize(20),B.setFont("helvetica","bold"),B.text("MathPulse AI",Me,16),B.setFontSize(11),B.setFont("helvetica","normal"),B.text("Student Intervention Report",Me,24),B.setFontSize(9),B.text(`Generated: ${new Date().toLocaleDateString("en-US",{year:"numeric",month:"long",day:"numeric"})}`,Me,32),B.setTextColor(0,0,0),F=48,je("Student Profile"),B.setFontSize(10),B.setFont("helvetica","normal");const yt=[["Name",me.student_name],["Grade Level",me.grade_level||"N/A"],["Section",me.section||"N/A"],["Risk Level",me.risk_level],["Average Score",`${me.avg_score}%`],["Engagement",me.engagement_level],["Weakest Topic",ys(me.weakest_topic||"N/A")],["Last Active",me.last_active?new Date(me.last_active).toLocaleDateString():"Unknown"]];for(const[se,rt]of yt)ve(6),B.setFont("helvetica","bold"),B.text(`${se}:`,Me+2,F),B.setFont("helvetica","normal"),B.text(String(rt),Me+45,F),F+=6;if(F+=4,me.weak_topics?.length||Object.keys(me.accuracy_by_topic||{}).length){if(je("Risk Assessment & Topic Analysis"),B.setFontSize(10),me.weak_topics?.length){B.setFont("helvetica","bold"),B.text("Weak Topics:",Me+2,F),F+=6,B.setFont("helvetica","normal");for(const rt of me.weak_topics)ve(6),B.text(` • ${ys(rt)}`,Me+4,F),F+=5;F+=3}const se=Object.entries(me.accuracy_by_topic||{});if(se.length>0){B.setFont("helvetica","bold"),B.text("Topic Accuracy Breakdown:",Me+2,F),F+=7,B.setFontSize(9),B.setFont("helvetica","normal");for(const[rt,nt]of se.sort(([,ut],[,ws])=>ut-ws)){ve(7);const ut=60,ws=nt/100*ut;B.text(rt,Me+4,F),B.setFillColor(226,232,240),B.roundedRect(Me+70,F-3,ut,4,1,1,"F"),B.setFillColor(nt>=70?34:nt>=50?245:239,nt>=70?197:nt>=50?158:68,nt>=70?94:nt>=50?11:68),ws>0&&B.roundedRect(Me+70,F-3,ws,4,1,1,"F"),B.text(`${Math.round(nt)}%`,Me+70+ut+3,F),F+=7}F+=3}}if(je("AI Analysis & Insights"),B.setFontSize(10),me.learning_strengths&&(B.setFont("helvetica","bold"),B.text("Learning Strengths:",Me+2,F),F+=6,B.setFont("helvetica","normal"),qe(me.learning_strengths,4),F+=4),me.next_steps_summary&&(B.setFont("helvetica","bold"),ve(8),B.text("Recommended Next Steps:",Me+2,F),F+=6,B.setFont("helvetica","normal"),qe(me.next_steps_summary,4),F+=4),me.learning_path?.steps?.length){je("Personalized Learning Path"),B.setFontSize(9),B.setFont("helvetica","italic"),B.text(`Estimated Duration: ${me.learning_path.estimated_duration_days} days | Primary Focus: ${ys(me.learning_path.primary_weak_topic)}`,Me+2,F),F+=8,B.setFont("helvetica","normal"),B.setFontSize(10);for(const se of me.learning_path.steps){ve(18),B.setFillColor(99,102,241),B.circle(Me+6,F,3,"F"),B.setTextColor(255,255,255),B.setFontSize(8),B.text(String(se.step_number),Me+4.5,F+1.5),B.setTextColor(0,0,0),B.setFontSize(10),B.setFont("helvetica","bold"),B.text(ys(se.title),Me+14,F+1),B.setFont("helvetica","normal"),B.setFontSize(9);const rt=`${se.type.replace("_"," ")} • ${se.duration_minutes} min • ${se.difficulty}${se.competency_tag?` • ${se.competency_tag}`:""}`;if(B.setTextColor(100,116,139),B.text(rt,Me+14,F+6),B.setTextColor(0,0,0),F+=8,se.description){B.setFontSize(9);const nt=B.splitTextToSize(se.description,M-16);for(const ut of nt.slice(0,2))F+=5,ve(5),B.text(ut,Me+14,F)}F+=10}}if(me.teacher_recommendations?.length){je("Teacher Recommendations"),B.setFontSize(10),B.setFont("helvetica","normal");for(let se=0;se{Je(!0),ce("bank");try{const L=await vi(s);Ce(L)}catch{Ce([])}finally{Je(!1)}},className:"w-full flex items-start gap-4 p-4 rounded-[16px] border border-slate-200 hover:border-[#a855f7] hover:shadow-[0_4px_12px_rgba(168,85,247,0.08)] hover:bg-purple-50/30 transition-all group mb-3 text-left",children:[e.jsx("div",{className:"w-10 h-10 rounded-[10px] bg-purple-50 border border-purple-100 flex items-center justify-center shrink-0 group-hover:bg-purple-100 transition-colors",children:e.jsx(ur,{className:"w-5 h-5 text-[#a855f7]"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[14px] font-bold text-[#1e293b] mb-0.5",children:"Choose from existing quizzes"}),e.jsx("p",{className:"text-[12px] text-[#64748b] font-medium",children:"Pick a quiz already in your Quiz Bank."})]})]}),e.jsxs("button",{onClick:()=>{Q(!1),Nt(!1),Ge(!0)},className:"w-full flex items-start gap-4 p-4 rounded-[16px] border border-slate-200 hover:border-[#a855f7] hover:shadow-[0_4px_12px_rgba(168,85,247,0.08)] hover:bg-purple-50/30 transition-all group text-left",children:[e.jsx("div",{className:"w-10 h-10 rounded-[10px] bg-purple-50 border border-purple-100 flex items-center justify-center shrink-0 group-hover:bg-purple-100 transition-colors",children:e.jsx(ps,{className:"w-5 h-5 text-[#a855f7]"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[14px] font-bold text-[#1e293b] mb-0.5",children:"Create a new quiz"}),e.jsx("p",{className:"text-[12px] text-[#64748b] font-medium",children:"Use AI Quiz Maker. You can return here when done."})]})]})]}):e.jsx("div",{children:Ne?e.jsxs("div",{className:"flex flex-col items-center justify-center py-10 gap-3",children:[e.jsx("div",{className:"w-8 h-8 border-2 border-[#a855f7] border-t-transparent rounded-full animate-spin"}),e.jsx("p",{className:"text-[13px] text-[#64748b] font-medium",children:"Loading quizzes..."})]}):ae.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-10 gap-3 text-center",children:[e.jsx("div",{className:"w-12 h-12 rounded-full bg-purple-50 flex items-center justify-center",children:e.jsx(ur,{className:"w-6 h-6 text-[#a855f7]"})}),e.jsx("p",{className:"text-[14px] font-semibold text-[#1e293b]",children:"No quizzes yet"}),e.jsx("p",{className:"text-[12px] text-[#64748b]",children:"Create your first quiz using the AI Quiz Maker."})]}):e.jsx("div",{className:"space-y-3 max-h-[320px] overflow-y-auto pr-1",children:ae.map(L=>e.jsxs("div",{className:"flex items-center justify-between gap-3 p-4 rounded-[14px] border border-slate-200 hover:border-[#a855f7] hover:shadow-[0_2px_8px_rgba(168,85,247,0.08)] transition-all group",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-[13px] font-bold text-[#1e293b] truncate",children:L.title}),e.jsxs("p",{className:"text-[11px] text-[#64748b] font-medium mt-0.5",children:[L.questions?.length??0," questions",L.gradeLevel?` · ${L.gradeLevel}`:"",L.metadata?.topicsCovered?.[0]?` · ${L.metadata.topicsCovered[0]}`:""]})]}),e.jsx("button",{onClick:()=>{Q(!1),ie.success(`"${L.title}" selected for ${t.name}`)},className:"shrink-0 px-3 py-1.5 rounded-full bg-[#a855f7] text-white text-[11px] font-bold hover:bg-[#9333ea] transition-colors shadow-sm",children:"Assign"})]},L.id))})})})]})]}),document.body),$e&&Qr.createPortal(e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[9998] bg-black/40 backdrop-blur-sm",onClick:()=>{ft?jt(!0):Ge(!1)}}),e.jsxs("div",{className:"fixed top-0 right-0 z-[9999] h-full w-full max-w-[88vw] xl:max-w-[1080px] bg-white shadow-[-8px_0_40px_rgba(0,0,0,0.15)] flex flex-col",style:{animation:"slideInFromRight 0.3s cubic-bezier(0.16,1,0.3,1)"},children:[e.jsxs("div",{className:"flex items-center gap-3 px-6 py-4 border-b border-slate-100 bg-white shrink-0",children:[e.jsxs("button",{onClick:()=>{ft?jt(!0):Ge(!1)},className:"flex items-center gap-2 text-[13px] font-semibold text-[#4f46e5] hover:text-[#3730a3] transition-colors bg-indigo-50 hover:bg-indigo-100 px-4 py-2 rounded-full",children:[e.jsx(cr,{className:"w-4 h-4"}),"Back to ",t.name]}),e.jsx("div",{className:"h-5 w-px bg-slate-200"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-7 h-7 rounded-[8px] bg-gradient-to-br from-[#a855f7] to-[#9333ea] flex items-center justify-center",children:e.jsx(Xr,{className:"w-3.5 h-3.5 text-white"})}),e.jsx("span",{className:"text-[14px] font-bold text-[#1e293b]",children:"AI Quiz Maker"})]}),ft&&e.jsx("span",{className:"ml-auto text-[11px] font-semibold text-amber-600 bg-amber-50 border border-amber-200 px-2.5 py-0.5 rounded-full",children:"Quiz in progress"})]}),e.jsx("div",{className:"flex-1 overflow-hidden",children:e.jsx(fl,{onBack:()=>Ge(!1),drawerMode:!0,gradeLevel:t.grade,onQuizGenerating:()=>Nt(!0),onQuizSaved:L=>{Nt(!1),ie.success("Quiz saved! Close this panel or create another.",{action:{label:"Close Panel",onClick:()=>Ge(!1)}})}})})]}),dt&&e.jsxs("div",{className:"fixed inset-0 z-[10000] flex items-center justify-center p-4",children:[e.jsx("div",{className:"absolute inset-0 bg-black/60",onClick:()=>jt(!1)}),e.jsxs("div",{className:"relative bg-white rounded-[20px] shadow-[0_24px_60px_rgba(0,0,0,0.2)] w-full max-w-[380px] p-7 z-10",children:[e.jsx("div",{className:"w-11 h-11 rounded-full bg-amber-50 border border-amber-200 flex items-center justify-center mb-4",children:e.jsx(br,{className:"w-5 h-5 text-amber-500"})}),e.jsx("h3",{className:"text-[16px] font-bold text-[#1e293b] mb-2",children:"Discard quiz progress?"}),e.jsx("p",{className:"text-[13px] text-[#64748b] font-medium mb-6",children:"Your current quiz session will be lost if you close this panel. This cannot be undone."}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx("button",{onClick:()=>jt(!1),className:"flex-1 py-2.5 rounded-full border border-slate-200 text-[13px] font-semibold text-[#475569] hover:bg-slate-50 transition-colors",children:"Keep editing"}),e.jsx("button",{onClick:()=>{jt(!1),Ge(!1),Nt(!1)},className:"flex-1 py-2.5 rounded-full bg-rose-500 hover:bg-rose-600 text-white text-[13px] font-semibold transition-colors",children:"Discard & close"})]})]})]}),e.jsx("style",{children:` @keyframes slideInFromRight { from { transform: translateX(100%); opacity: 0.6; } to { transform: translateX(0); opacity: 1; } } `})]}),document.body),e.jsxs("div",{className:"w-full bg-white/80 rounded-[18px] p-[20px] shadow-[0_1px_4px_rgba(0,0,0,0.02)] border border-white mt-auto",children:[e.jsx("h3",{className:"text-[13px] font-semibold text-[#1e293b] mb-4",children:"Section Assignment"}),e.jsxs("div",{className:"space-y-[12px]",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] font-semibold text-[#64748b] uppercase tracking-wider mb-1.5 block ml-1",children:"Grade Level"}),e.jsx("div",{className:"relative",children:e.jsx(Is,{value:R,onChange:L=>W(L.target.value),placeholder:"Grade",className:"appearance-none w-full bg-[#f8fafc] border border-[#e2e8f0] text-[#475569] text-[13px] font-medium rounded-[14px] px-4 py-2.5 outline-none focus:border-[#a855f7] focus:ring-1 focus:ring-[#a855f7] h-auto"})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] font-semibold text-[#64748b] uppercase tracking-wider mb-1.5 block ml-1",children:"Section"}),e.jsx("div",{className:"relative",children:e.jsx(Is,{value:f,onChange:L=>C(L.target.value),placeholder:"Section",className:"appearance-none w-full bg-[#f8fafc] border border-[#e2e8f0] text-[#475569] text-[13px] font-medium rounded-[14px] px-4 py-2.5 outline-none focus:border-[#a855f7] focus:ring-1 focus:ring-[#a855f7] h-auto"})})]}),e.jsx("button",{onClick:os,disabled:w||!R.trim()||!f.trim(),className:"w-full bg-white hover:bg-[#f8fafc] disabled:opacity-50 text-[#4f46e5] border border-[#e0e7ff] text-[13px] font-semibold rounded-[14px] px-4 py-2.5 transition-colors shadow-[0_1px_4px_rgba(0,0,0,0.02)] mt-2",children:w?"Updating...":"Update Assignment"})]})]})]})}),k&&e.jsx(xm,{step:k,studentId:t.id,studentName:t.name,teacherId:s,totalSteps:p?.learning_path?.steps?.length||3,onClose:()=>N(null),onStepCompleted:()=>{N(null),rn(t.id).then(h).catch(()=>{})}})]})},li=({onViewCalendar:t,onOpenProfile:s,userProfile:a,teacherName:r,liveActivity:o=[]})=>{const{currentUser:n}=hs(),[i,l]=u.useState(new Date),[c,d]=u.useState("pulse"),[m,p]=u.useState([]),[h,b]=u.useState(!1);u.useEffect(()=>{if(!n?.uid)return;const w=vl(n.uid,{limitCount:100},$=>p($),()=>{});return()=>w()},[n?.uid]);const S=w=>new Date(w.getFullYear(),w.getMonth()+1,0).getDate(),k=w=>new Date(w.getFullYear(),w.getMonth(),1).getDay(),N=()=>i.toLocaleDateString(void 0,{month:"long",year:"numeric"}),v=()=>l(new Date(i.getFullYear(),i.getMonth()-1)),g=()=>l(new Date(i.getFullYear(),i.getMonth()+1)),I=()=>{const w=S(i),$=k(i),A=[];for(let y=$-1;y>=0;y--)A.unshift(null);for(let y=1;y<=w;y++)A.push(y);return A},z=w=>{if(!w)return!1;const $=new Date;return w===$.getDate()&&i.getMonth()===$.getMonth()&&i.getFullYear()===$.getFullYear()},R=I(),W=["Mo","Tu","We","Th","Fr","Sa","Su"],f=w=>{if(!w)return!1;const $=`${i.getFullYear()}-${String(i.getMonth()+1).padStart(2,"0")}-${String(w).padStart(2,"0")}`;return m.some(A=>{const y=new Date(A.startTime);return`${y.getFullYear()}-${String(y.getMonth()+1).padStart(2,"0")}-${String(y.getDate()).padStart(2,"0")}`===$})},C=w=>{if(!w)return;const $=`${i.getFullYear()}-${String(i.getMonth()+1).padStart(2,"0")}-${String(w).padStart(2,"0")}`,A=m.filter(y=>{const q=new Date(y.startTime);return`${q.getFullYear()}-${String(q.getMonth()+1).padStart(2,"0")}-${String(q.getDate()).padStart(2,"0")}`===$});if(A.length!==0)return A.map(y=>`• ${y.title}`).join(` -`)};return e.jsxs("aside",{className:"w-[280px] bg-white border-l border-[#e2e8f0] flex flex-col flex-shrink-0 overflow-hidden",children:[e.jsxs("div",{className:"p-[22px_16px_10px] border-b border-[#f1f5f9] flex flex-col items-center gap-[5px]",children:[e.jsx("div",{className:"w-[48px] h-[48px] rounded-full bg-[#e0e7ff] flex items-center justify-center text-[22px] text-[#4f46e5] shadow-[0_0_0_3px_#c7d2fe] flex-shrink-0",children:e.jsx(Vl,{src:a?.photo,name:r,className:"w-full h-full rounded-full"})}),e.jsx("div",{className:"text-[13.5px] font-semibold text-[#1e293b] mt-1",children:r}),e.jsx("div",{className:"text-[11px] text-[#94a3b8]",children:"Teacher"}),e.jsx("button",{onClick:s,className:"mt-[4px] py-[6px] px-[22px] bg-[#818cf8] hover:bg-[#6366f1] text-white rounded-full text-[11.5px] font-medium transition-colors",children:"Profile"})]}),e.jsxs("div",{className:"border-b border-[#f1f5f9]",children:[e.jsxs("div",{className:"p-[10px_16px_8px] flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:w=>{w.stopPropagation(),v()},className:"w-6 h-6 flex items-center justify-center bg-white border border-[#e2e8f0] rounded-[7px] text-[#64748b] hover:bg-[#f8fafc] cursor-pointer text-[14px] z-10",children:e.jsx(zs,{size:14})}),e.jsx("span",{className:"text-[12px] font-semibold text-[#1e293b] hover:text-[#4f46e5] transition-colors cursor-pointer",onClick:t,children:N()}),e.jsx("button",{onClick:w=>{w.stopPropagation(),g()},className:"w-6 h-6 flex items-center justify-center bg-white border border-[#e2e8f0] rounded-[7px] text-[#64748b] hover:bg-[#f8fafc] cursor-pointer text-[14px] z-10",children:e.jsx(Ms,{size:14})})]}),e.jsx("button",{onClick:()=>b(w=>!w),className:"w-6 h-6 flex items-center justify-center rounded-[7px] text-[#94a3b8] hover:bg-[#f1f5f9] hover:text-[#64748b] transition-colors",title:h?"Show calendar":"Hide calendar","aria-label":h?"Expand calendar":"Collapse calendar",children:e.jsx($t,{size:14,className:`transition-transform duration-200 ${h?"":"rotate-180"}`})})]}),e.jsx(zt,{initial:!1,children:!h&&e.jsx(Le.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.22,ease:"easeInOut"},className:"overflow-hidden",children:e.jsx("div",{className:"px-[16px] pb-[10px] cursor-pointer hover:bg-slate-50 transition-colors group/cal",onClick:t,children:e.jsxs("div",{className:"grid grid-cols-7 gap-[2px] text-center mb-1",children:[W.map(w=>e.jsx("div",{className:"text-[10px] font-semibold text-[#94a3b8] p-[2px_0_4px]",children:w},w)),R.map((w,$)=>e.jsxs("div",{className:"relative flex flex-col items-center justify-center h-[28px]",title:C(w),children:[e.jsx("div",{className:`text-[11px] leading-[22px] w-[22px] h-[22px] flex items-center justify-center rounded-full transition-all ${w===null?"text-[#cbd5e1]":z(w)?"bg-[#818cf8] text-white font-semibold":"text-[#475569] group-hover/cal:bg-slate-100"}`,children:w}),w!==null&&f(w)&&e.jsx("div",{className:`absolute bottom-0 w-1 h-1 rounded-full ${z(w)?"bg-white":"bg-[#a855f7]"}`})]},`${i.getMonth()}-${$}`))]})})},"cal-grid")})]}),e.jsxs("div",{className:"flex gap-[18px] p-[12px_16px_0] border-b border-[#f1f5f9] flex-shrink-0",children:[e.jsx("button",{onClick:()=>d("pulse"),className:`text-[11.5px] font-semibold pb-[9px] border-b-[2.5px] transition-colors ${c==="pulse"?"text-[#10b981] border-[#10b981]":"text-[#94a3b8] border-transparent"}`,children:"Live pulse"}),e.jsx("button",{onClick:()=>d("reminders"),className:`text-[11.5px] font-semibold pb-[9px] border-b-[2.5px] transition-colors ${c==="reminders"?"text-[#10b981] border-[#10b981]":"text-[#94a3b8] border-transparent"}`,children:"Reminders"})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-[14px_16px]",children:[c==="pulse"&&e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("div",{className:"text-[10px] font-bold text-[#64748b] uppercase tracking-wider",children:"Live Activity Stream"}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-emerald-500 animate-pulse"}),e.jsx("span",{className:"text-[9px] font-bold text-emerald-600",children:"LIVE"})]})]}),o.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-10 text-center opacity-40",children:[e.jsx(bi,{size:32,className:"text-slate-300 mb-2"}),e.jsx("p",{className:"text-[11px] font-bold text-[#1e293b]",children:"No recent activity"})]}):e.jsx("div",{className:"space-y-4",children:o.slice(0,5).map(w=>e.jsxs("div",{className:"relative pl-5 before:absolute before:left-1.5 before:top-2 before:bottom-[-16px] before:w-[1px] before:bg-slate-100 last:before:hidden",children:[e.jsx("div",{className:"absolute left-0 top-1.5 w-3 h-3 rounded-full border-2 border-white bg-indigo-500 shadow-sm z-10"}),e.jsxs("div",{className:"bg-white border border-[#f1f5f9] rounded-xl p-3 shadow-sm hover:shadow-md transition-shadow",children:[e.jsxs("div",{className:"flex justify-between items-start mb-1",children:[e.jsx("span",{className:"text-[12px] font-bold text-[#1e293b] truncate",children:w.student}),e.jsx("span",{className:"text-[9px] font-medium text-[#94a3b8] shrink-0",children:w.time})]}),e.jsxs("p",{className:"text-[11px] text-[#64748b] leading-snug",children:[w.action," ",e.jsx("span",{className:"font-bold text-[#4f46e5]",children:w.topic})]})]})]},w.id))})]}),c==="reminders"&&e.jsxs("div",{className:"space-y-3",children:[m.filter(w=>{const $=new Date;return $.setHours(0,0,0,0),new Date(w.startTime).getTime()>=$.getTime()}).sort((w,$)=>new Date(w.startTime).getTime()-new Date($.startTime).getTime()).slice(0,5).map(w=>{const $=new Date(w.startTime).toDateString()===new Date().toDateString();return e.jsxs("div",{onClick:t,className:"flex items-start gap-3 p-3 border border-[#f1f5f9] rounded-[14px] cursor-pointer hover:bg-slate-50 transition-colors group",children:[e.jsx("div",{className:`p-2 rounded-xl border border-[#f1f5f9] bg-white text-[14px] flex-shrink-0 shadow-sm transition-transform group-hover:scale-105 ${$?"text-rose-500":"text-[#4f46e5]"}`,children:e.jsx(nr,{size:14})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[12px] font-bold text-[#1e293b] mb-0.5 truncate",children:w.title}),e.jsxs("div",{className:`text-[10px] font-medium ${$?"text-rose-500 font-bold":"text-[#94a3b8]"}`,children:[$?"Today, ":"",new Date(w.startTime).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})]})]})]},w.id)}),m.filter(w=>new Date(w.startTime).getTime()>=new Date().setHours(0,0,0,0)).length===0&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-10 text-center opacity-40",children:[e.jsx(dr,{size:32,className:"text-slate-300 mb-2"}),e.jsx("p",{className:"text-[11px] font-bold text-[#1e293b]",children:"No upcoming tasks"})]})]})]})]})};export{oh as default}; +`)};return e.jsxs("aside",{className:"w-[280px] bg-white border-l border-[#e2e8f0] flex flex-col flex-shrink-0 overflow-hidden",children:[e.jsxs("div",{className:"p-[22px_16px_10px] border-b border-[#f1f5f9] flex flex-col items-center gap-[5px]",children:[e.jsx("div",{className:"w-[48px] h-[48px] rounded-full bg-[#e0e7ff] flex items-center justify-center text-[22px] text-[#4f46e5] shadow-[0_0_0_3px_#c7d2fe] flex-shrink-0",children:e.jsx(Vl,{src:a?.photo,name:r,className:"w-full h-full rounded-full"})}),e.jsx("div",{className:"text-[13.5px] font-semibold text-[#1e293b] mt-1",children:r}),e.jsx("div",{className:"text-[11px] text-[#94a3b8]",children:"Teacher"}),e.jsx("button",{onClick:s,className:"mt-[4px] py-[6px] px-[22px] bg-[#818cf8] hover:bg-[#6366f1] text-white rounded-full text-[11.5px] font-medium transition-colors",children:"Profile"})]}),e.jsxs("div",{className:"border-b border-[#f1f5f9]",children:[e.jsxs("div",{className:"p-[10px_16px_8px] flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:w=>{w.stopPropagation(),v()},className:"w-6 h-6 flex items-center justify-center bg-white border border-[#e2e8f0] rounded-[7px] text-[#64748b] hover:bg-[#f8fafc] cursor-pointer text-[14px] z-10",children:e.jsx(zs,{size:14})}),e.jsx("span",{className:"text-[12px] font-semibold text-[#1e293b] hover:text-[#4f46e5] transition-colors cursor-pointer",onClick:t,children:N()}),e.jsx("button",{onClick:w=>{w.stopPropagation(),g()},className:"w-6 h-6 flex items-center justify-center bg-white border border-[#e2e8f0] rounded-[7px] text-[#64748b] hover:bg-[#f8fafc] cursor-pointer text-[14px] z-10",children:e.jsx(Ms,{size:14})})]}),e.jsx("button",{onClick:()=>b(w=>!w),className:"w-6 h-6 flex items-center justify-center rounded-[7px] text-[#94a3b8] hover:bg-[#f1f5f9] hover:text-[#64748b] transition-colors",title:h?"Show calendar":"Hide calendar","aria-label":h?"Expand calendar":"Collapse calendar",children:e.jsx($t,{size:14,className:`transition-transform duration-200 ${h?"":"rotate-180"}`})})]}),e.jsx(zt,{initial:!1,children:!h&&e.jsx(Le.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.22,ease:"easeInOut"},className:"overflow-hidden",children:e.jsx("div",{className:"px-[16px] pb-[10px] cursor-pointer hover:bg-slate-50 transition-colors group/cal",onClick:t,children:e.jsxs("div",{className:"grid grid-cols-7 gap-[2px] text-center mb-1",children:[W.map(w=>e.jsx("div",{className:"text-[10px] font-semibold text-[#94a3b8] p-[2px_0_4px]",children:w},w)),R.map((w,$)=>e.jsxs("div",{className:"relative flex flex-col items-center justify-center h-[28px]",title:C(w),children:[e.jsx("div",{className:`text-[11px] leading-[22px] w-[22px] h-[22px] flex items-center justify-center rounded-full transition-all ${w===null?"text-[#cbd5e1]":z(w)?"bg-[#818cf8] text-white font-semibold":"text-[#475569] group-hover/cal:bg-slate-100"}`,children:w}),w!==null&&f(w)&&e.jsx("div",{className:`absolute bottom-0 w-1 h-1 rounded-full ${z(w)?"bg-white":"bg-[#a855f7]"}`})]},`${i.getMonth()}-${$}`))]})})},"cal-grid")})]}),e.jsxs("div",{className:"flex gap-[18px] p-[12px_16px_0] border-b border-[#f1f5f9] flex-shrink-0",children:[e.jsx("button",{onClick:()=>d("pulse"),className:`text-[11.5px] font-semibold pb-[9px] border-b-[2.5px] transition-colors ${c==="pulse"?"text-[#10b981] border-[#10b981]":"text-[#94a3b8] border-transparent"}`,children:"Live pulse"}),e.jsx("button",{onClick:()=>d("reminders"),className:`text-[11.5px] font-semibold pb-[9px] border-b-[2.5px] transition-colors ${c==="reminders"?"text-[#10b981] border-[#10b981]":"text-[#94a3b8] border-transparent"}`,children:"Reminders"})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-[14px_16px]",children:[c==="pulse"&&e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("div",{className:"text-[10px] font-bold text-[#64748b] uppercase tracking-wider",children:"Live Activity Stream"}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-emerald-500 animate-pulse"}),e.jsx("span",{className:"text-[9px] font-bold text-emerald-600",children:"LIVE"})]})]}),o.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-10 text-center opacity-40",children:[e.jsx(bi,{size:32,className:"text-slate-300 mb-2"}),e.jsx("p",{className:"text-[11px] font-bold text-[#1e293b]",children:"No recent activity"})]}):e.jsx("div",{className:"space-y-4",children:o.slice(0,5).map(w=>e.jsxs("div",{className:"relative pl-5 before:absolute before:left-1.5 before:top-2 before:bottom-[-16px] before:w-[1px] before:bg-slate-100 last:before:hidden",children:[e.jsx("div",{className:"absolute left-0 top-1.5 w-3 h-3 rounded-full border-2 border-white bg-indigo-500 shadow-sm z-10"}),e.jsxs("div",{className:"bg-white border border-[#f1f5f9] rounded-xl p-3 shadow-sm hover:shadow-md transition-shadow",children:[e.jsxs("div",{className:"flex justify-between items-start mb-1",children:[e.jsx("span",{className:"text-[12px] font-bold text-[#1e293b] truncate",children:w.student}),e.jsx("span",{className:"text-[9px] font-medium text-[#94a3b8] shrink-0",children:w.time})]}),e.jsxs("p",{className:"text-[11px] text-[#64748b] leading-snug",children:[w.action," ",e.jsx("span",{className:"font-bold text-[#4f46e5]",children:w.topic})]})]})]},w.id))})]}),c==="reminders"&&e.jsxs("div",{className:"space-y-3",children:[m.filter(w=>{const $=new Date;return $.setHours(0,0,0,0),new Date(w.startTime).getTime()>=$.getTime()}).sort((w,$)=>new Date(w.startTime).getTime()-new Date($.startTime).getTime()).slice(0,5).map(w=>{const $=new Date(w.startTime).toDateString()===new Date().toDateString();return e.jsxs("div",{onClick:t,className:"flex items-start gap-3 p-3 border border-[#f1f5f9] rounded-[14px] cursor-pointer hover:bg-slate-50 transition-colors group",children:[e.jsx("div",{className:`p-2 rounded-xl border border-[#f1f5f9] bg-white text-[14px] flex-shrink-0 shadow-sm transition-transform group-hover:scale-105 ${$?"text-rose-500":"text-[#4f46e5]"}`,children:e.jsx(nr,{size:14})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[12px] font-bold text-[#1e293b] mb-0.5 truncate",children:w.title}),e.jsxs("div",{className:`text-[10px] font-medium ${$?"text-rose-500 font-bold":"text-[#94a3b8]"}`,children:[$?"Today, ":"",new Date(w.startTime).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})]})]})]},w.id)}),m.filter(w=>new Date(w.startTime).getTime()>=new Date().setHours(0,0,0,0)).length===0&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-10 text-center opacity-40",children:[e.jsx(dr,{size:32,className:"text-slate-300 mb-2"}),e.jsx("p",{className:"text-[11px] font-bold text-[#1e293b]",children:"No upcoming tasks"})]})]})]})]})};export{ih as default}; diff --git a/assets/XPNotification-Ba3kZbWo.js b/assets/XPNotification-GHNILw26.js similarity index 92% rename from assets/XPNotification-Ba3kZbWo.js rename to assets/XPNotification-GHNILw26.js index 232a8c59c81500049801cfa321e6a09751a36105..cb05289e3dd94544760e94f844c7dc46141d665c 100644 --- a/assets/XPNotification-Ba3kZbWo.js +++ b/assets/XPNotification-GHNILw26.js @@ -1 +1 @@ -import{r as l,b as n,j as e}from"./vendor-react-B4AQeu28.js";import{h as c,m as r,a7 as m}from"./index-BufUS6SI.js";import{S as x}from"./sparkles-DYlMf97S.js";import"./vendor-firebase-firestore-CNv3xXal.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-radix-C5nwdvGr.js";import"./vendor-charts-CAmziV1y.js";import"./vendor-markdown-yqZQ_iQm.js";const w=({xp:i,message:a,show:t,onComplete:s})=>(l.useEffect(()=>{if(t){const o=setTimeout(()=>{s()},3e3);return()=>clearTimeout(o)}},[t,s]),n.createPortal(e.jsx(c,{children:t&&e.jsx(r.div,{initial:{opacity:0,y:-50,scale:.8},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-20,scale:.9},transition:{type:"spring",damping:25,stiffness:200},className:"fixed top-8 left-1/2 -translate-x-1/2 z-[300]",style:{willChange:"transform, opacity"},children:e.jsxs("div",{className:"bg-gradient-to-r from-rose-400 via-orange-500 to-rose-500 text-white px-6 py-4 rounded-2xl shadow-2xl border-2 border-rose-300 flex items-center gap-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"w-10 h-10 bg-white/20 rounded-xl flex items-center justify-center",children:e.jsx(m,{size:20,className:"text-white",fill:"currentColor"})}),e.jsx(r.div,{className:"absolute -top-1 -right-1",animate:{rotate:[0,360]},transition:{duration:2,repeat:1/0,ease:"linear"},style:{willChange:"transform"},children:e.jsx(x,{size:16,className:"text-rose-200"})})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-bold",children:a}),e.jsxs("p",{className:"text-2xl font-black",children:["+",i," XP"]})]})]})})}),document.body));export{w as default}; +import{r as l,b as n,j as e}from"./vendor-react-B4AQeu28.js";import{h as c,m as r,a7 as m}from"./index-Bp7MiGcW.js";import{S as x}from"./sparkles-fLB3ltj1.js";import"./vendor-firebase-firestore-CNv3xXal.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-radix-C5nwdvGr.js";import"./vendor-charts-CAmziV1y.js";import"./vendor-markdown-yqZQ_iQm.js";const w=({xp:i,message:a,show:t,onComplete:s})=>(l.useEffect(()=>{if(t){const o=setTimeout(()=>{s()},3e3);return()=>clearTimeout(o)}},[t,s]),n.createPortal(e.jsx(c,{children:t&&e.jsx(r.div,{initial:{opacity:0,y:-50,scale:.8},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-20,scale:.9},transition:{type:"spring",damping:25,stiffness:200},className:"fixed top-8 left-1/2 -translate-x-1/2 z-[300]",style:{willChange:"transform, opacity"},children:e.jsxs("div",{className:"bg-gradient-to-r from-rose-400 via-orange-500 to-rose-500 text-white px-6 py-4 rounded-2xl shadow-2xl border-2 border-rose-300 flex items-center gap-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"w-10 h-10 bg-white/20 rounded-xl flex items-center justify-center",children:e.jsx(m,{size:20,className:"text-white",fill:"currentColor"})}),e.jsx(r.div,{className:"absolute -top-1 -right-1",animate:{rotate:[0,360]},transition:{duration:2,repeat:1/0,ease:"linear"},style:{willChange:"transform"},children:e.jsx(x,{size:16,className:"text-rose-200"})})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-bold",children:a}),e.jsxs("p",{className:"text-2xl font-black",children:["+",i," XP"]})]})]})})}),document.body));export{w as default}; diff --git a/assets/automationService-KQFQd_ic.js b/assets/automationService-g67Xos9d.js similarity index 98% rename from assets/automationService-KQFQd_ic.js rename to assets/automationService-g67Xos9d.js index 69878415c833e33d6dbd0d32890c19f3cf25235f..ca7f1c4d011da6b06d2fa143af1bdc605c00d572 100644 --- a/assets/automationService-KQFQd_ic.js +++ b/assets/automationService-g67Xos9d.js @@ -1 +1 @@ -import{doc as g,collection as a,serverTimestamp as c,setDoc as l,addDoc as D,query as b,where as z,getDocs as A,updateDoc as Q,writeBatch as $}from"./vendor-firebase-firestore-CNv3xXal.js";import{g as r,b5 as _}from"./index-BufUS6SI.js";import"./vendor-firebase-core-D7GXCeNu.js";import"./vendor-react-B4AQeu28.js";import"./vendor-firebase-auth-T_wvTOvf.js";import"./vendor-firebase-storage-Bi7H_66d.js";import"./vendor-firebase-analytics-rHarj5hR.js";import"./vendor-radix-C5nwdvGr.js";import"./vendor-charts-CAmziV1y.js";import"./vendor-markdown-yqZQ_iQm.js";const m=async(e,n,o,u,i)=>{try{const t=g(a(r,"notifications")),s={id:t.id,userId:e,type:n,title:o,message:u,read:!1,...i?{actionUrl:i}:{},createdAt:new Date},d={id:s.id,userId:s.userId,type:s.type,title:s.title,message:s.message,read:s.read,createdAt:c(),link:i||null};return await l(t,{...d}),s}catch(t){throw console.error("Error creating notification:",t),t}};async function M(e){if(!e)return 0;const n=a(r,"deepDiagnosticAssignments"),o=b(n,z("lrn","==",e));return(await A(o)).docs.filter(i=>{const t=i.data().status;return t==="pending"||t==="queued"||t==="in_progress"||t==="expired"}).length}async function x(e,n,o="Grade 11",u,i="iar_only",t="initial_assessment",s){if(t==="followup_diagnostic"){const d=a(r,"deepDiagnosticAssignments"),C=b(d,z("lrn","==",e)),f=await A(C);if(!f.empty){const p=$(r);let w=!1;for(const h of f.docs){const I=h.data().status;(I==="pending"||I==="queued")&&(p.update(h.ref,{status:"in_progress",startedAt:c()}),w=!0)}w&&await p.commit()}}return await l(g(r,"diagnosticResults",e),{lrn:e,results:n,gradeLevel:o,workflowMode:i,assessmentType:t,questionBreakdown:u||null,topicBreakdown:s||null,completedAt:c(),processed:!1,processing:!1}),{success:!0,event:"diagnostic_completed",lrn:e,message:`Diagnostic submitted for ${e}. Processing will begin automatically.`,remedialQuizzesCreated:0,notifications:["Your diagnostic results are being processed. Check back shortly!"]}}async function N(e){return await D(a(r,"quizResults"),{lrn:e.lrn,studentId:e.lrn,quizId:e.quizId,subject:e.subject,score:e.score,totalQuestions:e.totalQuestions,correctAnswers:e.correctAnswers,timeSpentSeconds:e.timeSpentSeconds,answers:e.answers||null,submittedAt:c()}),{success:!0,event:"quiz_submitted",lrn:e.lrn,message:`Quiz submitted for ${e.lrn}. Risk recalculation will run automatically.`,remedialQuizzesCreated:0,notifications:[`Quiz result recorded for ${e.subject}.`]}}async function W(e){return await _(e.lrn),await m(e.lrn,"reminder","Welcome to MathPulse AI!","Complete your diagnostic assessment to get started with personalised learning."),e.teacherId&&await m(e.teacherId,"message","New Student Enrolled",`${e.name} has joined. Diagnostic assessment is pending.`),{success:!0,event:"student_enrolled",lrn:e.lrn,message:`Student ${e.name} enrolled and initialised`,remedialQuizzesCreated:0,notifications:[`Welcome ${e.name}! Please complete the diagnostic assessment.`]}}async function G(e){return await D(a(r,"dataImports"),{teacherId:e.teacherId,studentCount:e.students.length,columnMapping:e.columnMapping,importedAt:c(),processed:!1}),await m(e.teacherId,"message","Data Import Processed",`Data import complete — ${e.students.length} student records processed.`),{success:!0,event:"data_imported",message:`Data import processed for ${e.students.length} students`,remedialQuizzesCreated:0,notifications:[`Data import complete — ${e.students.length} student records processed.`]}}async function Y(e){const n=g(r,"curriculumContent",e.contentId);return e.action==="delete"?await Q(n,{deleted:!0,deletedBy:e.adminId,deletedAt:c(),contentType:e.contentType,subjectId:e.subjectId||null}):await l(n,{contentType:e.contentType,subjectId:e.subjectId||null,details:e.details||null,updatedBy:e.adminId,action:e.action,updatedAt:c()},{merge:!0}),{success:!0,event:"content_updated",message:`Content ${e.action} processed for ${e.contentType}`,remedialQuizzesCreated:0,notifications:[]}}export{M as getPendingDeepDiagnosticCount,Y as triggerContentUpdated,G as triggerDataImported,x as triggerDiagnosticCompleted,N as triggerQuizSubmitted,W as triggerStudentEnrolled}; +import{doc as g,collection as a,serverTimestamp as c,setDoc as l,addDoc as D,query as b,where as z,getDocs as A,updateDoc as Q,writeBatch as $}from"./vendor-firebase-firestore-CNv3xXal.js";import{g as r,b5 as _}from"./index-Bp7MiGcW.js";import"./vendor-firebase-core-D7GXCeNu.js";import"./vendor-react-B4AQeu28.js";import"./vendor-firebase-auth-T_wvTOvf.js";import"./vendor-firebase-storage-Bi7H_66d.js";import"./vendor-firebase-analytics-rHarj5hR.js";import"./vendor-radix-C5nwdvGr.js";import"./vendor-charts-CAmziV1y.js";import"./vendor-markdown-yqZQ_iQm.js";const m=async(e,n,o,u,i)=>{try{const t=g(a(r,"notifications")),s={id:t.id,userId:e,type:n,title:o,message:u,read:!1,...i?{actionUrl:i}:{},createdAt:new Date},d={id:s.id,userId:s.userId,type:s.type,title:s.title,message:s.message,read:s.read,createdAt:c(),link:i||null};return await l(t,{...d}),s}catch(t){throw console.error("Error creating notification:",t),t}};async function M(e){if(!e)return 0;const n=a(r,"deepDiagnosticAssignments"),o=b(n,z("lrn","==",e));return(await A(o)).docs.filter(i=>{const t=i.data().status;return t==="pending"||t==="queued"||t==="in_progress"||t==="expired"}).length}async function x(e,n,o="Grade 11",u,i="iar_only",t="initial_assessment",s){if(t==="followup_diagnostic"){const d=a(r,"deepDiagnosticAssignments"),C=b(d,z("lrn","==",e)),f=await A(C);if(!f.empty){const p=$(r);let w=!1;for(const h of f.docs){const I=h.data().status;(I==="pending"||I==="queued")&&(p.update(h.ref,{status:"in_progress",startedAt:c()}),w=!0)}w&&await p.commit()}}return await l(g(r,"diagnosticResults",e),{lrn:e,results:n,gradeLevel:o,workflowMode:i,assessmentType:t,questionBreakdown:u||null,topicBreakdown:s||null,completedAt:c(),processed:!1,processing:!1}),{success:!0,event:"diagnostic_completed",lrn:e,message:`Diagnostic submitted for ${e}. Processing will begin automatically.`,remedialQuizzesCreated:0,notifications:["Your diagnostic results are being processed. Check back shortly!"]}}async function N(e){return await D(a(r,"quizResults"),{lrn:e.lrn,studentId:e.lrn,quizId:e.quizId,subject:e.subject,score:e.score,totalQuestions:e.totalQuestions,correctAnswers:e.correctAnswers,timeSpentSeconds:e.timeSpentSeconds,answers:e.answers||null,submittedAt:c()}),{success:!0,event:"quiz_submitted",lrn:e.lrn,message:`Quiz submitted for ${e.lrn}. Risk recalculation will run automatically.`,remedialQuizzesCreated:0,notifications:[`Quiz result recorded for ${e.subject}.`]}}async function W(e){return await _(e.lrn),await m(e.lrn,"reminder","Welcome to MathPulse AI!","Complete your diagnostic assessment to get started with personalised learning."),e.teacherId&&await m(e.teacherId,"message","New Student Enrolled",`${e.name} has joined. Diagnostic assessment is pending.`),{success:!0,event:"student_enrolled",lrn:e.lrn,message:`Student ${e.name} enrolled and initialised`,remedialQuizzesCreated:0,notifications:[`Welcome ${e.name}! Please complete the diagnostic assessment.`]}}async function G(e){return await D(a(r,"dataImports"),{teacherId:e.teacherId,studentCount:e.students.length,columnMapping:e.columnMapping,importedAt:c(),processed:!1}),await m(e.teacherId,"message","Data Import Processed",`Data import complete — ${e.students.length} student records processed.`),{success:!0,event:"data_imported",message:`Data import processed for ${e.students.length} students`,remedialQuizzesCreated:0,notifications:[`Data import complete — ${e.students.length} student records processed.`]}}async function Y(e){const n=g(r,"curriculumContent",e.contentId);return e.action==="delete"?await Q(n,{deleted:!0,deletedBy:e.adminId,deletedAt:c(),contentType:e.contentType,subjectId:e.subjectId||null}):await l(n,{contentType:e.contentType,subjectId:e.subjectId||null,details:e.details||null,updatedBy:e.adminId,action:e.action,updatedAt:c()},{merge:!0}),{success:!0,event:"content_updated",message:`Content ${e.action} processed for ${e.contentType}`,remedialQuizzesCreated:0,notifications:[]}}export{M as getPendingDeepDiagnosticCount,Y as triggerContentUpdated,G as triggerDataImported,x as triggerDiagnosticCompleted,N as triggerQuizSubmitted,W as triggerStudentEnrolled}; diff --git a/assets/avatarData-BuQSOXo3.js b/assets/avatarData-BuQSOXo3.js deleted file mode 100644 index 803f185d6bbc4a6f3599185c54de2b85852d32fb..0000000000000000000000000000000000000000 --- a/assets/avatarData-BuQSOXo3.js +++ /dev/null @@ -1 +0,0 @@ -const r=[{id:"top_blue",name:"Blue Uniform",category:"top",src:"/avatar/uniform_blue.png",thumbnail:"/avatar/uniform_blue_thumbnail.png",price:0},{id:"top_pink",name:"Pink Uniform",category:"top",src:"/avatar/uniform_pink.png",thumbnail:"/avatar/uniform_pink_thumbnail.png",price:200},{id:"bot_black",name:"Black Pants",category:"bottom",src:"/avatar/pants_black.png",thumbnail:"/avatar/pants_black_thumbnail.png",price:0},{id:"shoe_black",name:"Black Shoes",category:"shoes",src:"/avatar/shoes_black.png",thumbnail:"/avatar/shoes_black_thumbnail.png",price:0},{id:"acc_leaf_clip",name:"Leaf Clip",category:"accessory",src:"/avatar/leaf_clip.png",thumbnail:"/avatar/leaf_clip_thumbnail.png",price:0},{id:"acc_red_cap",name:"Red Cap",category:"accessory",src:"/avatar/red_cap.png",thumbnail:"/avatar/red_cap_thumbnail.png",price:250},{id:"acc_traffic_cone",name:"Traffic Cone",category:"accessory",src:"/avatar/traffic_cone.png",thumbnail:"/avatar/traffic_cone_thumbnail.png",price:500},{id:"acc_blue_cap",name:"Blue Cap",category:"accessory",src:"/avatar/blue_cap.png",thumbnail:"/avatar/blue_cap_thumbnail.png",isReward:!0},{id:"acc_crown",name:"Gold Crown",category:"accessory",src:"/avatar/crown.png",thumbnail:"/avatar/crown_thumbnail.png",isReward:!0},{id:"acc_mathsquad_badge",name:"MathSquad Badge",category:"accessory",src:"/avatar/mathsquad_badge.png",thumbnail:"/avatar/mathsquad_badge_thumbnail.png",isReward:!0},{id:"acc_calc_crown",name:"Calculus Crown",category:"accessory",src:"/avatar/calc_crown.png",thumbnail:"/avatar/calc_crown_thumbnail.png",isReward:!0}],n=a=>{if(a)return r.find(c=>c.id===a)?.src};export{r as M,n as g}; diff --git a/assets/avatarData-ChByUhv2.js b/assets/avatarData-ChByUhv2.js new file mode 100644 index 0000000000000000000000000000000000000000..9ca983bc00fb2ffed18ed0863c31687348265dc0 --- /dev/null +++ b/assets/avatarData-ChByUhv2.js @@ -0,0 +1 @@ +const t=[{id:"top_blue",name:"Blue Uniform",category:"top",src:"/avatar/uniform_blue.png",thumbnail:"/avatar/uniform_blue_thumbnail.png",price:0},{id:"top_pink",name:"Pink Uniform",category:"top",src:"/avatar/uniform_pink.png",thumbnail:"/avatar/uniform_pink_thumbnail.png",price:200},{id:"top_brown_vest",name:"Brown Vest",category:"top",src:"/avatar/brown_vest.png",thumbnail:"/avatar/brown_vest_thumbnail.png",price:150},{id:"bot_black",name:"Black Pants",category:"bottom",src:"/avatar/pants_black.png",thumbnail:"/avatar/pants_black_thumbnail.png",price:0},{id:"shoe_black",name:"Black Shoes",category:"shoes",src:"/avatar/shoes_black.png",thumbnail:"/avatar/shoes_black_thumbnail.png",price:0},{id:"shoe_slippers",name:"Slippers",category:"shoes",src:"/avatar/slippers.png",thumbnail:"/avatar/slippers_thumbnail.png",price:100},{id:"acc_leaf_clip",name:"Leaf Clip",category:"accessory",src:"/avatar/leaf_clip.png",thumbnail:"/avatar/leaf_clip_thumbnail.png",price:0},{id:"acc_blue_cap",name:"Blue Cap",category:"accessory",src:"/avatar/blue_cap.png",thumbnail:"/avatar/blue_cap_thumbnail.png",price:300},{id:"acc_red_cap",name:"Red Cap",category:"accessory",src:"/avatar/red_cap.png",thumbnail:"/avatar/red_cap_thumbnail.png",price:250},{id:"acc_traffic_cone",name:"Traffic Cone",category:"accessory",src:"/avatar/traffic_cone.png",thumbnail:"/avatar/traffic_cone_thumbnail.png",price:500},{id:"acc_crown",name:"Gold Crown",category:"accessory",src:"/avatar/crown.png",thumbnail:"/avatar/crown_thumbnail.png",isReward:!0,isExclusive:!0},{id:"exc_naruto_set",name:"Naruto Set",category:"top",src:"/avatar/naruto_top.png",thumbnail:"/avatar/exclusive_naruto_set_thumbnail.png",isReward:!0,isExclusive:!0,setLayers:{top:"exc_naruto_top",bottom:"exc_naruto_pants",shoes:"exc_naruto_shoes",accessory:"exc_forehead_protector"}},{id:"exc_naruto_top",name:"Naruto Top",category:"top",src:"/avatar/naruto_top.png",thumbnail:"/avatar/exclusive_naruto_set_thumbnail.png",isReward:!0,isExclusive:!0},{id:"exc_naruto_pants",name:"Naruto Pants",category:"bottom",src:"/avatar/naruto_pants.png",thumbnail:"/avatar/exclusive_naruto_set_thumbnail.png",isReward:!0,isExclusive:!0},{id:"exc_naruto_shoes",name:"Naruto Shoes",category:"shoes",src:"/avatar/naruto_shoes.png",thumbnail:"/avatar/exclusive_naruto_set_thumbnail.png",isReward:!0,isExclusive:!0},{id:"exc_forehead_protector",name:"Forehead Protector",category:"accessory",src:"/avatar/forehead_protector.png",thumbnail:"/avatar/exclusive_naruto_set_thumbnail.png",isReward:!0,isExclusive:!0}],e=t.filter(a=>a.isExclusive&&a.id!=="exc_naruto_top"&&a.id!=="exc_naruto_pants"&&a.id!=="exc_naruto_shoes"&&a.id!=="exc_forehead_protector"),n=a=>{if(a)return t.find(r=>r.id===a)?.src};export{e as E,t as M,n as g}; diff --git a/assets/bell-D9j1Gy0m.js b/assets/bell-DyLbgepV.js similarity index 91% rename from assets/bell-D9j1Gy0m.js rename to assets/bell-DyLbgepV.js index 877648c34c1655fad45664d6fba836c0788fd63d..7445bf67da0474f762fe8be69f0b5362bf9ad295 100644 --- a/assets/bell-D9j1Gy0m.js +++ b/assets/bell-DyLbgepV.js @@ -1,4 +1,4 @@ -import{e}from"./index-BufUS6SI.js";/** +import{e}from"./index-Bp7MiGcW.js";/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. diff --git a/assets/button-DsnZWCoA.js b/assets/button-BMVm9YQO.js similarity index 97% rename from assets/button-DsnZWCoA.js rename to assets/button-BMVm9YQO.js index 1e3169a58e86a596ba46e0f125567b3bc9039638..74bf7f2b2e7438a88c4a184f181b7f452f22a827 100644 --- a/assets/button-DsnZWCoA.js +++ b/assets/button-BMVm9YQO.js @@ -1 +1 @@ -import{j as y}from"./vendor-react-B4AQeu28.js";import{S as k}from"./vendor-radix-C5nwdvGr.js";import{c as V}from"./vendor-charts-CAmziV1y.js";import{o as p}from"./index-BufUS6SI.js";const g=n=>typeof n=="boolean"?`${n}`:n===0?"0":n,m=V,j=(n,r)=>e=>{var o;if(r?.variants==null)return m(n,e?.class,e?.className);const{variants:u,defaultVariants:i}=r,b=Object.keys(u).map(t=>{const a=e?.[t],d=i?.[t];if(a===null)return null;const s=g(a)||g(d);return u[t][s]}),v=e&&Object.entries(e).reduce((t,a)=>{let[d,s]=a;return s===void 0||(t[d]=s),t},{}),f=r==null||(o=r.compoundVariants)===null||o===void 0?void 0:o.reduce((t,a)=>{let{class:d,className:s,...h}=a;return Object.entries(h).every(x=>{let[c,l]=x;return Array.isArray(l)?l.includes({...i,...v}[c]):{...i,...v}[c]===l})?[...t,d,s]:t},[]);return m(n,b,f,e?.class,e?.className)},N=j("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",outline:"border bg-background text-foreground hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-9 px-4 py-2 has-[>svg]:px-3",sm:"h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",lg:"h-10 rounded-md px-6 has-[>svg]:px-4",icon:"size-9 rounded-md"}},defaultVariants:{variant:"default",size:"default"}});function w({className:n,variant:r,size:e,asChild:o=!1,...u}){const i=o?k:"button";return y.jsx(i,{"data-slot":"button",className:p(N({variant:r,size:e,className:n})),...u})}export{w as B,j as c}; +import{j as y}from"./vendor-react-B4AQeu28.js";import{S as k}from"./vendor-radix-C5nwdvGr.js";import{c as V}from"./vendor-charts-CAmziV1y.js";import{o as p}from"./index-Bp7MiGcW.js";const g=n=>typeof n=="boolean"?`${n}`:n===0?"0":n,m=V,j=(n,r)=>e=>{var o;if(r?.variants==null)return m(n,e?.class,e?.className);const{variants:u,defaultVariants:i}=r,b=Object.keys(u).map(t=>{const a=e?.[t],d=i?.[t];if(a===null)return null;const s=g(a)||g(d);return u[t][s]}),v=e&&Object.entries(e).reduce((t,a)=>{let[d,s]=a;return s===void 0||(t[d]=s),t},{}),f=r==null||(o=r.compoundVariants)===null||o===void 0?void 0:o.reduce((t,a)=>{let{class:d,className:s,...h}=a;return Object.entries(h).every(x=>{let[c,l]=x;return Array.isArray(l)?l.includes({...i,...v}[c]):{...i,...v}[c]===l})?[...t,d,s]:t},[]);return m(n,b,f,e?.class,e?.className)},N=j("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",outline:"border bg-background text-foreground hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-9 px-4 py-2 has-[>svg]:px-3",sm:"h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",lg:"h-10 rounded-md px-6 has-[>svg]:px-4",icon:"size-9 rounded-md"}},defaultVariants:{variant:"default",size:"default"}});function w({className:n,variant:r,size:e,asChild:o=!1,...u}){const i=o?k:"button";return y.jsx(i,{"data-slot":"button",className:p(N({variant:r,size:e,className:n})),...u})}export{w as B,j as c}; diff --git a/assets/chart-column-BcVJ31XT.js b/assets/chart-column-Dyv8TfXk.js similarity index 89% rename from assets/chart-column-BcVJ31XT.js rename to assets/chart-column-Dyv8TfXk.js index d326728f40b268c2e803babe4fb6ba5cdbefa46a..0bdc4d612cf91c2cd424c1ea3acbab18cabcd06d 100644 --- a/assets/chart-column-BcVJ31XT.js +++ b/assets/chart-column-Dyv8TfXk.js @@ -1,4 +1,4 @@ -import{e as t}from"./index-BufUS6SI.js";/** +import{e as t}from"./index-Bp7MiGcW.js";/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. diff --git a/assets/chatService-BcZzFY2v.js b/assets/chatService-DgvwP4xj.js similarity index 97% rename from assets/chatService-BcZzFY2v.js rename to assets/chatService-DgvwP4xj.js index 298f25e28655946e874385e98dfd2e717a8f56bb..0e58852ab4182325fca08c761de6c7fd72d33682 100644 --- a/assets/chatService-BcZzFY2v.js +++ b/assets/chatService-DgvwP4xj.js @@ -1 +1 @@ -import{doc as c,collection as u,getDoc as g,serverTimestamp as i,setDoc as w,updateDoc as p,query as l,where as d,orderBy as y,getDocs as A}from"./vendor-firebase-firestore-CNv3xXal.js";import{g as a}from"./index-BufUS6SI.js";import"./vendor-firebase-core-D7GXCeNu.js";import"./vendor-react-B4AQeu28.js";import"./vendor-firebase-auth-T_wvTOvf.js";import"./vendor-firebase-storage-Bi7H_66d.js";import"./vendor-firebase-analytics-rHarj5hR.js";import"./vendor-radix-C5nwdvGr.js";import"./vendor-charts-CAmziV1y.js";import"./vendor-markdown-yqZQ_iQm.js";const Q=async(s,t="New Conversation")=>{try{const e=c(u(a,"chatSessions")),n={id:e.id,userId:s,title:t,messages:[],createdAt:new Date,updatedAt:new Date,isActive:!0};return await w(e,{...n,createdAt:i(),updatedAt:i()}),n}catch(e){throw console.error("Error creating chat session:",e),e}},R=async s=>{try{const t=l(u(a,"chatSessions"),d("userId","==",s),d("isActive","==",!0),y("updatedAt","desc"));return(await A(t)).docs.map(n=>{const r=n.data();return{...r,createdAt:r.createdAt?.toDate()||new Date,updatedAt:r.updatedAt?.toDate()||new Date}})}catch(t){return console.error("Error getting chat sessions:",t),[]}},b=async s=>{try{const t=await g(c(a,"chatSessions",s));if(t.exists()){const e=t.data();return{...e,createdAt:e.createdAt?.toDate()||new Date,updatedAt:e.updatedAt?.toDate()||new Date}}return null}catch(t){return console.error("Error getting chat session:",t),null}},q=async(s,t,e,n)=>{try{const r=c(u(a,"chatMessages")),o={id:r.id,userId:"",role:t,content:e,timestamp:new Date,...n?{context:n}:{}},m=await g(c(a,"chatSessions",s));m.exists()&&(o.userId=m.data().userId);const h={id:o.id,userId:o.userId,role:o.role,content:o.content,sessionId:s,timestamp:i()};return o.context&&(h.context=o.context),await w(r,h),await p(c(a,"chatSessions",s),{updatedAt:i()}),o}catch(r){throw console.error("Error adding message:",r),r}},B=async(s,t)=>{try{const e=l(u(a,"chatMessages"),d("sessionId","==",s),d("userId","==",t),y("timestamp","asc"));return(await A(e)).docs.map(r=>{const o=r.data();return{...o,timestamp:o.timestamp?.toDate()||new Date}})}catch(e){return console.error("Error getting session messages:",e),[]}},N=async(s,t)=>{try{await p(c(a,"chatSessions",s),{title:t,updatedAt:i()})}catch(e){throw console.error("Error updating session title:",e),e}},U=async s=>{try{await p(c(a,"chatSessions",s),{isActive:!1,updatedAt:i()})}catch(t){throw console.error("Error deleting session:",t),t}};export{q as addMessageToSession,Q as createChatSession,U as deleteSession,b as getChatSession,B as getSessionMessages,R as getUserChatSessions,N as updateSessionTitle}; +import{doc as c,collection as u,getDoc as g,serverTimestamp as i,setDoc as w,updateDoc as p,query as l,where as d,orderBy as y,getDocs as A}from"./vendor-firebase-firestore-CNv3xXal.js";import{g as a}from"./index-Bp7MiGcW.js";import"./vendor-firebase-core-D7GXCeNu.js";import"./vendor-react-B4AQeu28.js";import"./vendor-firebase-auth-T_wvTOvf.js";import"./vendor-firebase-storage-Bi7H_66d.js";import"./vendor-firebase-analytics-rHarj5hR.js";import"./vendor-radix-C5nwdvGr.js";import"./vendor-charts-CAmziV1y.js";import"./vendor-markdown-yqZQ_iQm.js";const Q=async(s,t="New Conversation")=>{try{const e=c(u(a,"chatSessions")),n={id:e.id,userId:s,title:t,messages:[],createdAt:new Date,updatedAt:new Date,isActive:!0};return await w(e,{...n,createdAt:i(),updatedAt:i()}),n}catch(e){throw console.error("Error creating chat session:",e),e}},R=async s=>{try{const t=l(u(a,"chatSessions"),d("userId","==",s),d("isActive","==",!0),y("updatedAt","desc"));return(await A(t)).docs.map(n=>{const r=n.data();return{...r,createdAt:r.createdAt?.toDate()||new Date,updatedAt:r.updatedAt?.toDate()||new Date}})}catch(t){return console.error("Error getting chat sessions:",t),[]}},b=async s=>{try{const t=await g(c(a,"chatSessions",s));if(t.exists()){const e=t.data();return{...e,createdAt:e.createdAt?.toDate()||new Date,updatedAt:e.updatedAt?.toDate()||new Date}}return null}catch(t){return console.error("Error getting chat session:",t),null}},q=async(s,t,e,n)=>{try{const r=c(u(a,"chatMessages")),o={id:r.id,userId:"",role:t,content:e,timestamp:new Date,...n?{context:n}:{}},m=await g(c(a,"chatSessions",s));m.exists()&&(o.userId=m.data().userId);const h={id:o.id,userId:o.userId,role:o.role,content:o.content,sessionId:s,timestamp:i()};return o.context&&(h.context=o.context),await w(r,h),await p(c(a,"chatSessions",s),{updatedAt:i()}),o}catch(r){throw console.error("Error adding message:",r),r}},B=async(s,t)=>{try{const e=l(u(a,"chatMessages"),d("sessionId","==",s),d("userId","==",t),y("timestamp","asc"));return(await A(e)).docs.map(r=>{const o=r.data();return{...o,timestamp:o.timestamp?.toDate()||new Date}})}catch(e){return console.error("Error getting session messages:",e),[]}},N=async(s,t)=>{try{await p(c(a,"chatSessions",s),{title:t,updatedAt:i()})}catch(e){throw console.error("Error updating session title:",e),e}},U=async s=>{try{await p(c(a,"chatSessions",s),{isActive:!1,updatedAt:i()})}catch(t){throw console.error("Error deleting session:",t),t}};export{q as addMessageToSession,Q as createChatSession,U as deleteSession,b as getChatSession,B as getSessionMessages,R as getUserChatSessions,N as updateSessionTitle}; diff --git a/assets/check-B-qbiSF7.js b/assets/check-qsSFTYCr.js similarity index 85% rename from assets/check-B-qbiSF7.js rename to assets/check-qsSFTYCr.js index 8001a5912b9d67bc1b9d0a8a4f50f822d6359eaf..c646483b109c5608cafa29283cec7cfac21d382a 100644 --- a/assets/check-B-qbiSF7.js +++ b/assets/check-qsSFTYCr.js @@ -1,4 +1,4 @@ -import{e as c}from"./index-BufUS6SI.js";/** +import{e as c}from"./index-Bp7MiGcW.js";/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. diff --git a/assets/chevron-left-DMbkPbec.js b/assets/chevron-left-Be5knpOV.js similarity index 86% rename from assets/chevron-left-DMbkPbec.js rename to assets/chevron-left-Be5knpOV.js index a0a505f54dab9ee57e7aae334f1cc72781d0b177..8e2b95dfa76e83b41549616641208633ff9e542f 100644 --- a/assets/chevron-left-DMbkPbec.js +++ b/assets/chevron-left-Be5knpOV.js @@ -1,4 +1,4 @@ -import{e}from"./index-BufUS6SI.js";/** +import{e}from"./index-Bp7MiGcW.js";/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. diff --git a/assets/chevron-right-DADygX42.js b/assets/chevron-right-BxoysOas.js similarity index 85% rename from assets/chevron-right-DADygX42.js rename to assets/chevron-right-BxoysOas.js index 3eaf509860656ac360bf27b8cff2fddafd92e05c..9e81b5e0a1db5569c5e133f977aa28cfeb3c65b8 100644 --- a/assets/chevron-right-DADygX42.js +++ b/assets/chevron-right-BxoysOas.js @@ -1,4 +1,4 @@ -import{e as o}from"./index-BufUS6SI.js";/** +import{e as o}from"./index-Bp7MiGcW.js";/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. diff --git a/assets/chevron-up-CoNRuMZ7.js b/assets/chevron-up-DtS9MvUZ.js similarity index 92% rename from assets/chevron-up-CoNRuMZ7.js rename to assets/chevron-up-DtS9MvUZ.js index 98896a9d2b4dac5fc62a0c5683c2fd5a78130aa3..b662f014b8a794f6b90eacec562753858267c3b2 100644 --- a/assets/chevron-up-CoNRuMZ7.js +++ b/assets/chevron-up-DtS9MvUZ.js @@ -1,4 +1,4 @@ -import{e as o}from"./index-BufUS6SI.js";/** +import{e as o}from"./index-Bp7MiGcW.js";/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. diff --git a/assets/circle-alert-DDdeEgNa.js b/assets/circle-alert-CHGy8HcB.js similarity index 90% rename from assets/circle-alert-DDdeEgNa.js rename to assets/circle-alert-CHGy8HcB.js index 759fc1c971ac759c03a27c541c7cd2a230e7c89c..34b1c863923d6b34c51512e24b648d7dc002cfef 100644 --- a/assets/circle-alert-DDdeEgNa.js +++ b/assets/circle-alert-CHGy8HcB.js @@ -1,4 +1,4 @@ -import{e}from"./index-BufUS6SI.js";/** +import{e}from"./index-Bp7MiGcW.js";/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. diff --git a/assets/circle-check-BzgmgbHa.js b/assets/circle-check-DzQphSnP.js similarity index 87% rename from assets/circle-check-BzgmgbHa.js rename to assets/circle-check-DzQphSnP.js index 46a0956137ebb91717af7eed700b0284ef85aef3..a18c2ca45c58cbbb1ebdfb3cab28f19c50b123b2 100644 --- a/assets/circle-check-BzgmgbHa.js +++ b/assets/circle-check-DzQphSnP.js @@ -1,4 +1,4 @@ -import{e as c}from"./index-BufUS6SI.js";/** +import{e as c}from"./index-Bp7MiGcW.js";/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. diff --git a/assets/circle-check-big-CDg2qLfH.js b/assets/circle-check-big-JdaMs3bP.js similarity index 88% rename from assets/circle-check-big-CDg2qLfH.js rename to assets/circle-check-big-JdaMs3bP.js index 83c071d8a28ca9b8602e4d6184a4e7e0151787d1..1fd67f5889b3ec865ca16d4822bee5a73ac944fc 100644 --- a/assets/circle-check-big-CDg2qLfH.js +++ b/assets/circle-check-big-JdaMs3bP.js @@ -1,4 +1,4 @@ -import{e as c}from"./index-BufUS6SI.js";/** +import{e as c}from"./index-Bp7MiGcW.js";/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. diff --git a/assets/circle-help-DNA0h1v1.js b/assets/circle-help-CLCoBWDy.js similarity index 89% rename from assets/circle-help-DNA0h1v1.js rename to assets/circle-help-CLCoBWDy.js index b390388aaf9e11d683b2488e5482539ef2a4f39d..a85e7e3c1414d2ef37dfbd3a33577959063996cc 100644 --- a/assets/circle-help-DNA0h1v1.js +++ b/assets/circle-help-CLCoBWDy.js @@ -1,4 +1,4 @@ -import{e as c}from"./index-BufUS6SI.js";/** +import{e as c}from"./index-Bp7MiGcW.js";/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. diff --git a/assets/clipboard-check-UJ1-0W8j.js b/assets/clipboard-check-Cb8JdEuA.js similarity index 91% rename from assets/clipboard-check-UJ1-0W8j.js rename to assets/clipboard-check-Cb8JdEuA.js index 9b97b8c8ae0e987753f7fa04de5ffa72aecc6c40..381df1c1831a072ccb745ec9b4bf61a712c0cf1e 100644 --- a/assets/clipboard-check-UJ1-0W8j.js +++ b/assets/clipboard-check-Cb8JdEuA.js @@ -1,4 +1,4 @@ -import{e}from"./index-BufUS6SI.js";/** +import{e}from"./index-Bp7MiGcW.js";/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. diff --git a/assets/clock-CooTZK0X.js b/assets/clock-Cc6sJz1J.js similarity index 87% rename from assets/clock-CooTZK0X.js rename to assets/clock-Cc6sJz1J.js index c2365a31c2f6841c90df6655b4ae7ef539c90f34..734293f9a50983914fa20b11ed8b036eb3562091 100644 --- a/assets/clock-CooTZK0X.js +++ b/assets/clock-Cc6sJz1J.js @@ -1,4 +1,4 @@ -import{e as c}from"./index-BufUS6SI.js";/** +import{e as c}from"./index-Bp7MiGcW.js";/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. diff --git a/assets/diagnosticService-B5t8MYB4.js b/assets/diagnosticService-E5zPXoFs.js similarity index 91% rename from assets/diagnosticService-B5t8MYB4.js rename to assets/diagnosticService-E5zPXoFs.js index c69235c75f8c409108b6c4f1b955dbeed49500ec..c985589d6df845e6b99e74c0b04f183dad5ba259 100644 --- a/assets/diagnosticService-B5t8MYB4.js +++ b/assets/diagnosticService-E5zPXoFs.js @@ -1,2 +1,2 @@ -const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-BufUS6SI.js","assets/vendor-react-B4AQeu28.js","assets/vendor-firebase-firestore-CNv3xXal.js","assets/vendor-firebase-core-D7GXCeNu.js","assets/vendor-firebase-auth-T_wvTOvf.js","assets/vendor-firebase-storage-Bi7H_66d.js","assets/vendor-firebase-analytics-rHarj5hR.js","assets/vendor-radix-C5nwdvGr.js","assets/vendor-charts-CAmziV1y.js","assets/vendor-markdown-yqZQ_iQm.js","assets/vendor-markdown-CfVKi3_s.css","assets/index-CIg5rXpX.css"])))=>i.map(i=>d[i]); -import{_ as w}from"./index-BufUS6SI.js";const y="https://deign86-mathpulse-api-v3test.hf.space";async function P(g,h){const f=`${y}/api/diagnostic/generate`,{auth:i}=await w(async()=>{const{auth:e}=await import("./index-BufUS6SI.js").then(a=>a.b7);return{auth:e}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11])),c=i.currentUser,l=async()=>{const e=new Headers({"Content-Type":"application/json"});if(c){const a=await c.getIdToken(!1);a&&e.set("Authorization",`Bearer ${a}`)}return e},u=async e=>fetch(f,{method:"POST",headers:await l(),body:JSON.stringify({strand:g,grade_level:h}),signal:e}),d=(e,a)=>{let t="Something went wrong. Please try again.";try{const s=JSON.parse(a);if(s.detail){const o=String(s.detail);o.includes("Database unavailable")||o.includes("unavailable")?t="Our servers are temporarily busy. Please try again in a moment.":o.includes("timeout")||o.includes("timed out")?t="The request timed out. Please check your connection and try again.":t=o}}catch{!e.ok&&a&&(t="Failed to start assessment. Please try again.")}return t},n=2,r=3e4;for(let e=1;e<=n;e++){const a=new AbortController,t=setTimeout(()=>a.abort(),r);try{const s=await u(a.signal);if(s.ok)return clearTimeout(t),s.json();if(s.status>=400&&s.status<500){clearTimeout(t);const m=await s.text().catch(()=>"");throw new Error(d(s,m))}const o=await s.text().catch(()=>""),p=d(s,o);if(clearTimeout(t),esetTimeout(T,m));continue}throw new Error(p)}catch(s){if(clearTimeout(t),s instanceof DOMException&&s.name==="AbortError"){if(e{const{auth:n}=await import("./index-BufUS6SI.js").then(r=>r.b7);return{auth:n}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11])),l=c.currentUser;if(l){const n=await l.getIdToken(!1);n&&i.set("Authorization",`Bearer ${n}`)}const u=new AbortController,d=setTimeout(()=>u.abort(),6e4);try{const n=await fetch(f,{method:"POST",headers:i,body:JSON.stringify({test_id:g,responses:h}),signal:u.signal});if(!n.ok){const r=await n.text().catch(()=>"");let e="Something went wrong. Please try again.";try{const a=JSON.parse(r);if(a.detail){const t=String(a.detail);t.includes("session")||t.includes("not found")?e="Your assessment session has expired. Please restart the assessment.":t.includes("Database unavailable")||t.includes("unavailable")?e="Our servers are temporarily busy. Please try again in a moment.":t.includes("timeout")||t.includes("timed out")?e="The request timed out. Please check your connection and try again.":e=t}}catch{r.includes("404")||r.includes("not found")?e="Your assessment session has expired. Please restart the assessment.":r&&(e="Something went wrong. Please try again.")}throw new Error(e)}return n.json()}finally{clearTimeout(d)}}export{P as g,_ as s}; +const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-Bp7MiGcW.js","assets/vendor-react-B4AQeu28.js","assets/vendor-firebase-firestore-CNv3xXal.js","assets/vendor-firebase-core-D7GXCeNu.js","assets/vendor-firebase-auth-T_wvTOvf.js","assets/vendor-firebase-storage-Bi7H_66d.js","assets/vendor-firebase-analytics-rHarj5hR.js","assets/vendor-radix-C5nwdvGr.js","assets/vendor-charts-CAmziV1y.js","assets/vendor-markdown-yqZQ_iQm.js","assets/vendor-markdown-CfVKi3_s.css","assets/index-Dja0MwoB.css"])))=>i.map(i=>d[i]); +import{_ as w}from"./index-Bp7MiGcW.js";const y="https://deign86-mathpulse-api-v3test.hf.space";async function P(g,h){const f=`${y}/api/diagnostic/generate`,{auth:i}=await w(async()=>{const{auth:e}=await import("./index-Bp7MiGcW.js").then(a=>a.b7);return{auth:e}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11])),c=i.currentUser,l=async()=>{const e=new Headers({"Content-Type":"application/json"});if(c){const a=await c.getIdToken(!1);a&&e.set("Authorization",`Bearer ${a}`)}return e},u=async e=>fetch(f,{method:"POST",headers:await l(),body:JSON.stringify({strand:g,grade_level:h}),signal:e}),d=(e,a)=>{let t="Something went wrong. Please try again.";try{const s=JSON.parse(a);if(s.detail){const o=String(s.detail);o.includes("Database unavailable")||o.includes("unavailable")?t="Our servers are temporarily busy. Please try again in a moment.":o.includes("timeout")||o.includes("timed out")?t="The request timed out. Please check your connection and try again.":t=o}}catch{!e.ok&&a&&(t="Failed to start assessment. Please try again.")}return t},n=2,r=3e4;for(let e=1;e<=n;e++){const a=new AbortController,t=setTimeout(()=>a.abort(),r);try{const s=await u(a.signal);if(s.ok)return clearTimeout(t),s.json();if(s.status>=400&&s.status<500){clearTimeout(t);const m=await s.text().catch(()=>"");throw new Error(d(s,m))}const o=await s.text().catch(()=>""),p=d(s,o);if(clearTimeout(t),esetTimeout(T,m));continue}throw new Error(p)}catch(s){if(clearTimeout(t),s instanceof DOMException&&s.name==="AbortError"){if(e{const{auth:n}=await import("./index-Bp7MiGcW.js").then(r=>r.b7);return{auth:n}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11])),l=c.currentUser;if(l){const n=await l.getIdToken(!1);n&&i.set("Authorization",`Bearer ${n}`)}const u=new AbortController,d=setTimeout(()=>u.abort(),6e4);try{const n=await fetch(f,{method:"POST",headers:i,body:JSON.stringify({test_id:g,responses:h}),signal:u.signal});if(!n.ok){const r=await n.text().catch(()=>"");let e="Something went wrong. Please try again.";try{const a=JSON.parse(r);if(a.detail){const t=String(a.detail);t.includes("session")||t.includes("not found")?e="Your assessment session has expired. Please restart the assessment.":t.includes("Database unavailable")||t.includes("unavailable")?e="Our servers are temporarily busy. Please try again in a moment.":t.includes("timeout")||t.includes("timed out")?e="The request timed out. Please check your connection and try again.":e=t}}catch{r.includes("404")||r.includes("not found")?e="Your assessment session has expired. Please restart the assessment.":r&&(e="Something went wrong. Please try again.")}throw new Error(e)}return n.json()}finally{clearTimeout(d)}}export{P as g,_ as s}; diff --git a/assets/dialog-JRlpFJpo.js b/assets/dialog-C3ON9pD8.js similarity index 96% rename from assets/dialog-JRlpFJpo.js rename to assets/dialog-C3ON9pD8.js index fb58f9552d409bd30d4f031c2d700f367c533d9f..4eb59e60b376d8675d0fea31e242d0714153bde8 100644 --- a/assets/dialog-JRlpFJpo.js +++ b/assets/dialog-C3ON9pD8.js @@ -1,4 +1,4 @@ -import{e as g,o as s}from"./index-BufUS6SI.js";import{j as t,r as d}from"./vendor-react-B4AQeu28.js";import{b as m,c as l,d as p,T as n,D as i,P as u,O as r}from"./vendor-radix-C5nwdvGr.js";import{X as x}from"./x-BuBjuj2Y.js";/** +import{e as g,o as s}from"./index-Bp7MiGcW.js";import{j as t,r as d}from"./vendor-react-B4AQeu28.js";import{b as m,c as l,d as p,T as n,D as i,P as u,O as r}from"./vendor-radix-C5nwdvGr.js";import{X as x}from"./x-k8d6VLEw.js";/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. diff --git a/assets/dollar-sign-DWySnopv.js b/assets/dollar-sign-Dm4HJ6Ci.js similarity index 89% rename from assets/dollar-sign-DWySnopv.js rename to assets/dollar-sign-Dm4HJ6Ci.js index 9ee24e2c7c0cd209da643e8234f166c6b43f8ba4..b028861fd1c5c1970236bbc8320f1668285c3295 100644 --- a/assets/dollar-sign-DWySnopv.js +++ b/assets/dollar-sign-Dm4HJ6Ci.js @@ -1,4 +1,4 @@ -import{e}from"./index-BufUS6SI.js";/** +import{e}from"./index-Bp7MiGcW.js";/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. diff --git a/assets/download-DGNoiQkf.js b/assets/download-DFL4ZCXr.js similarity index 89% rename from assets/download-DGNoiQkf.js rename to assets/download-DFL4ZCXr.js index 5e19e4fedc1c4291d6ed88bfedddc7dfd1251705..3d986bf7d3fde5bf23fb6a7e9270741cca30565e 100644 --- a/assets/download-DGNoiQkf.js +++ b/assets/download-DFL4ZCXr.js @@ -1,4 +1,4 @@ -import{e as o}from"./index-BufUS6SI.js";/** +import{e as o}from"./index-Bp7MiGcW.js";/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. diff --git a/assets/eye-CDIJHn8i.js b/assets/eye-B_U0s6fm.js similarity index 96% rename from assets/eye-CDIJHn8i.js rename to assets/eye-B_U0s6fm.js index 621faeb8ea7f34fb419456773ef56739decec02e..aeaf048ffcb7ad8046f4ad52bc4baa2f27ca707a 100644 --- a/assets/eye-CDIJHn8i.js +++ b/assets/eye-B_U0s6fm.js @@ -1,4 +1,4 @@ -import{e}from"./index-BufUS6SI.js";/** +import{e}from"./index-Bp7MiGcW.js";/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. diff --git a/assets/formatDistanceToNow-cESSXRCA.js b/assets/formatDistanceToNow-D-5-www2.js similarity index 99% rename from assets/formatDistanceToNow-cESSXRCA.js rename to assets/formatDistanceToNow-D-5-www2.js index 288bf05c3099a2a9634735bbb347d500b5171370..01991daa4d11e22af59513c90a5ccb40af276ac7 100644 --- a/assets/formatDistanceToNow-cESSXRCA.js +++ b/assets/formatDistanceToNow-D-5-www2.js @@ -1,4 +1,4 @@ -import{e as W,t as u,aa as S}from"./index-BufUS6SI.js";/** +import{e as W,t as u,aa as S}from"./index-Bp7MiGcW.js";/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. diff --git a/assets/funnel-zhOTiCKD.js b/assets/funnel-KPSYPixk.js similarity index 90% rename from assets/funnel-zhOTiCKD.js rename to assets/funnel-KPSYPixk.js index 2eb84cfe6de0bdcd891cce05e42bfa1c075bd2a2..e39a30571702fa97fb4b6ff9dc016149d768dc22 100644 --- a/assets/funnel-zhOTiCKD.js +++ b/assets/funnel-KPSYPixk.js @@ -1,4 +1,4 @@ -import{e}from"./index-BufUS6SI.js";/** +import{e}from"./index-Bp7MiGcW.js";/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. diff --git a/assets/gift-D-3Burw1.js b/assets/gift-CnT2c-5r.js similarity index 91% rename from assets/gift-D-3Burw1.js rename to assets/gift-CnT2c-5r.js index 4cf6248111a8817973f2b8860021f63ebbd5b794..402a29750a0d15005eff77dbf47673f76eb5fab3 100644 --- a/assets/gift-D-3Burw1.js +++ b/assets/gift-CnT2c-5r.js @@ -1,4 +1,4 @@ -import{e as t}from"./index-BufUS6SI.js";/** +import{e as t}from"./index-Bp7MiGcW.js";/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. diff --git a/assets/history-DVu_-tNM.js b/assets/history-DVu_-tNM.js new file mode 100644 index 0000000000000000000000000000000000000000..f53e727135563543d3afac80685d410c08bba9ab --- /dev/null +++ b/assets/history-DVu_-tNM.js @@ -0,0 +1,6 @@ +import{e}from"./index-Bp7MiGcW.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 o=[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}],["path",{d:"M12 7v5l4 2",key:"1fdv2h"}]],a=e("history",o);export{a as H}; diff --git a/assets/index-Bp7MiGcW.js b/assets/index-Bp7MiGcW.js new file mode 100644 index 0000000000000000000000000000000000000000..f7dca9e4e65c92d2de3de78794fc7e225c3c76cf --- /dev/null +++ b/assets/index-Bp7MiGcW.js @@ -0,0 +1,717 @@ +const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/automationService-g67Xos9d.js","assets/vendor-firebase-firestore-CNv3xXal.js","assets/vendor-firebase-core-D7GXCeNu.js","assets/vendor-react-B4AQeu28.js","assets/vendor-firebase-auth-T_wvTOvf.js","assets/vendor-firebase-storage-Bi7H_66d.js","assets/vendor-firebase-analytics-rHarj5hR.js","assets/vendor-radix-C5nwdvGr.js","assets/vendor-charts-CAmziV1y.js","assets/vendor-markdown-yqZQ_iQm.js","assets/vendor-markdown-CfVKi3_s.css","assets/pipelineService-D7yl0SJO.js","assets/chatService-DgvwP4xj.js","assets/trackingService-C66NvvrU.js","assets/LoginPage-LAyBJ2QS.js","assets/button-BMVm9YQO.js","assets/input-Co0dljwe.js","assets/sparkles-fLB3ltj1.js","assets/mail-jAg7cqFw.js","assets/eye-B_U0s6fm.js","assets/shield-check-qhTHRSP5.js","assets/TeacherDashboard-Dqx3gqwf.js","assets/ConfirmModal-CH3zQe0u.js","assets/x-k8d6VLEw.js","assets/trash-2-BhUbBhdb.js","assets/log-out-DrAbcVI9.js","assets/search-DbD51Zen.js","assets/check-qsSFTYCr.js","assets/plus-D4SEqrVj.js","assets/NotificationDropdown-DNm6nFOm.js","assets/formatDistanceToNow-D-5-www2.js","assets/bell-DyLbgepV.js","assets/circle-check-DzQphSnP.js","assets/circle-alert-CHGy8HcB.js","assets/LogoutActionButton-BlHbD8Uf.js","assets/quizService-DrftrnKO.js","assets/clock-Cc6sJz1J.js","assets/send-BA-OOIJf.js","assets/circle-check-big-JdaMs3bP.js","assets/tooltip-nLNeX3nd.js","assets/circle-help-CLCoBWDy.js","assets/info-Bcg_cBHY.js","assets/chevron-up-DtS9MvUZ.js","assets/minus-BK7K7Pi2.js","assets/chart-column-Dyv8TfXk.js","assets/skeleton-BM3FTF2K.js","assets/download-DFL4ZCXr.js","assets/chevron-left-Be5knpOV.js","assets/chevron-right-BxoysOas.js","assets/save-D7oNX_Ki.js","assets/upload-CP6O7WIX.js","assets/lightbulb-DG1NwVgr.js","assets/useQuery-DN_XJYxl.js","assets/subjects-DNoBzeBL.js","assets/useCurriculum-BaLeFz19.js","assets/ChatMarkdown-Cwsa2RCx.js","assets/history-DVu_-tNM.js","assets/dialog-C3ON9pD8.js","assets/vendor-xlsx-uZelXSz_.js","assets/moduleWatchService-Cyzc6bn4.js","assets/clipboard-check-Cb8JdEuA.js","assets/AdminDashboard-BbvhhwJY.js","assets/Sidebar-BzRsh0CN.js","assets/shirt-C1GQiNvP.js","assets/select-CNQuOudF.js","assets/dollar-sign-Dm4HJ6Ci.js","assets/switch-C4JL2ii9.js","assets/useSubjectAvailability-Dm-85m8R.js","assets/HeroBanner-BMkaVujy.js","assets/RightSidebar-D6kbBdAu.js","assets/quiz_battle_avatar-BXHPSput.js","assets/XPNotification-GHNILw26.js","assets/index-CXlUCfM9.js","assets/megaphone-3N3DDeq6.js","assets/SupplementalBanner-BiW4WQHX.js","assets/SupplementalPillCarousel-BpO68D9M.js","assets/deepseekRagService-Bke9fSTt.js","assets/LearningPath-8IT3WoMT.js","assets/ModuleFolderCard-BaBw0Pd9.js","assets/CompetencyRadarChart-BbKzMlR1.js","assets/ModulesPage-CTVBRDaK.js","assets/ScientificCalculator-BCm13p89.js","assets/volume-x-DCLZlWDn.js","assets/confetti.module-C94ZD2ww.js","assets/gift-CnT2c-5r.js","assets/funnel-KPSYPixk.js","assets/AIChatPage-DesRqPBP.js","assets/GradesPage-CTmxSKZ7.js","assets/LeaderboardPage-Cl1rvXzo.js","assets/useFeatureAccess-O2Vj4dYD.js","assets/QuizBattlePage-R77VTOls.js","assets/CompositeAvatar-DoKZfi7O.js","assets/avatarData-ChByUhv2.js","assets/AvatarShop-DqyERXR_.js","assets/FloatingAITutor-wfjL9MBE.js","assets/maximize-2-CWmKKmit.js","assets/RewardsModal-C2mMOy8T.js","assets/ProfileModal-c1MJMwBW.js","assets/ProfilePictureUploader-Cdp-MoCI.js","assets/SettingsModal-DNhoMuH7.js","assets/InitialAssessmentModal-CnFHhYba.js","assets/diagnosticService-E5zPXoFs.js","assets/AssessmentPage-D6fgX4f6.js","assets/DiagnosticBreakdown-DkqMV9oI.js","assets/testResetService-tV_QRXFm.js"])))=>i.map(i=>d[i]); +import{r as h,j as b,d as I,c as Rp,f as Mp}from"./vendor-react-B4AQeu28.js";import{initializeFirestore as Ip,memoryLocalCache as Dp,doc as U,getDoc as me,setDoc as Ce,serverTimestamp as ae,getDocFromServer as Xo,onSnapshot as en,query as Dt,limit as ks,orderBy as Sn,collection as et,getDocs as Fn,updateDoc as dt,arrayUnion as Fu,increment as fs,where as Rt,deleteDoc as br,Timestamp as jn,runTransaction as Op}from"./vendor-firebase-firestore-CNv3xXal.js";import{U as Lp,V as zp,Y as jp,Z as Np,$ as $p,a0 as Fp,a1 as Vp,a2 as Bp,a3 as Up}from"./vendor-firebase-core-D7GXCeNu.js";import{browserLocalPersistence as Ya,initializeAuth as Ja,browserSessionPersistence as qp,inMemoryPersistence as ec,GoogleAuthProvider as Gp,createUserWithEmailAndPassword as Wp,updateProfile as Hp,signInWithEmailAndPassword as Zp,signOut as Kp,onAuthStateChanged as Qp,updatePassword as Xp,updateEmail as Yp,deleteUser as Jp,EmailAuthProvider as em,reauthenticateWithCredential as tm}from"./vendor-firebase-auth-T_wvTOvf.js";import{g as nm}from"./vendor-firebase-storage-Bi7H_66d.js";import{g as sm}from"./vendor-firebase-analytics-rHarj5hR.js";import{R as rm,I as om,F as im}from"./vendor-radix-C5nwdvGr.js";import{c as am}from"./vendor-charts-CAmziV1y.js";import"./vendor-markdown-yqZQ_iQm.js";(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const r of document.querySelectorAll('link[rel="modulepreload"]'))s(r);new MutationObserver(r=>{for(const o of r)if(o.type==="childList")for(const i of o.addedNodes)i.tagName==="LINK"&&i.rel==="modulepreload"&&s(i)}).observe(document,{childList:!0,subtree:!0});function n(r){const o={};return r.integrity&&(o.integrity=r.integrity),r.referrerPolicy&&(o.referrerPolicy=r.referrerPolicy),r.crossOrigin==="use-credentials"?o.credentials="include":r.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function s(r){if(r.ep)return;r.ep=!0;const o=n(r);fetch(r.href,o)}})();var $r=class{constructor(){this.listeners=new Set,this.subscribe=this.subscribe.bind(this)}subscribe(e){return this.listeners.add(e),this.onSubscribe(),()=>{this.listeners.delete(e),this.onUnsubscribe()}}hasListeners(){return this.listeners.size>0}onSubscribe(){}onUnsubscribe(){}},cm=class extends $r{#e;#t;#n;constructor(){super(),this.#n=e=>{if(typeof window<"u"&&window.addEventListener){const t=()=>e();return window.addEventListener("visibilitychange",t,!1),()=>{window.removeEventListener("visibilitychange",t)}}}}onSubscribe(){this.#t||this.setEventListener(this.#n)}onUnsubscribe(){this.hasListeners()||(this.#t?.(),this.#t=void 0)}setEventListener(e){this.#n=e,this.#t?.(),this.#t=e(t=>{typeof t=="boolean"?this.setFocused(t):this.onFocus()})}setFocused(e){this.#e!==e&&(this.#e=e,this.onFocus())}onFocus(){const e=this.isFocused();this.listeners.forEach(t=>{t(e)})}isFocused(){return typeof this.#e=="boolean"?this.#e:globalThis.document?.visibilityState!=="hidden"}},Vu=new cm,lm={setTimeout:(e,t)=>setTimeout(e,t),clearTimeout:e=>clearTimeout(e),setInterval:(e,t)=>setInterval(e,t),clearInterval:e=>clearInterval(e)},um=class{#e=lm;#t=!1;setTimeoutProvider(e){this.#e=e}setTimeout(e,t){return this.#e.setTimeout(e,t)}clearTimeout(e){this.#e.clearTimeout(e)}setInterval(e,t){return this.#e.setInterval(e,t)}clearInterval(e){this.#e.clearInterval(e)}},Yo=new um;function dm(e){setTimeout(e,0)}var fm=typeof window>"u"||"Deno"in globalThis;function wt(){}function hm(e,t){return typeof e=="function"?e(t):e}function pm(e){return typeof e=="number"&&e>=0&&e!==1/0}function mm(e,t){return Math.max(e+(t||0)-Date.now(),0)}function Jo(e,t){return typeof e=="function"?e(t):e}function gm(e,t){return typeof e=="function"?e(t):e}function tc(e,t){const{type:n="all",exact:s,fetchStatus:r,predicate:o,queryKey:i,stale:a}=e;if(i){if(s){if(t.queryHash!==Vi(i,t.options))return!1}else if(!ps(t.queryKey,i))return!1}if(n!=="all"){const c=t.isActive();if(n==="active"&&!c||n==="inactive"&&c)return!1}return!(typeof a=="boolean"&&t.isStale()!==a||r&&r!==t.state.fetchStatus||o&&!o(t))}function nc(e,t){const{exact:n,status:s,predicate:r,mutationKey:o}=e;if(o){if(!t.options.mutationKey)return!1;if(n){if(hs(t.options.mutationKey)!==hs(o))return!1}else if(!ps(t.options.mutationKey,o))return!1}return!(s&&t.state.status!==s||r&&!r(t))}function Vi(e,t){return(t?.queryKeyHashFn||hs)(e)}function hs(e){return JSON.stringify(e,(t,n)=>ei(n)?Object.keys(n).sort().reduce((s,r)=>(s[r]=n[r],s),{}):n)}function ps(e,t){return e===t?!0:typeof e!=typeof t?!1:e&&t&&typeof e=="object"&&typeof t=="object"?Object.keys(t).every(n=>ps(e[n],t[n])):!1}var ym=Object.prototype.hasOwnProperty;function Bu(e,t,n=0){if(e===t)return e;if(n>500)return t;const s=sc(e)&&sc(t);if(!s&&!(ei(e)&&ei(t)))return t;const o=(s?e:Object.keys(e)).length,i=s?t:Object.keys(t),a=i.length,c=s?new Array(a):{};let u=0;for(let d=0;d{Yo.setTimeout(t,e)})}function vm(e,t,n){return typeof n.structuralSharing=="function"?n.structuralSharing(e,t):n.structuralSharing!==!1?Bu(e,t):t}function wm(e,t,n=0){const s=[...e,t];return n&&s.length>n?s.slice(1):s}function xm(e,t,n=0){const s=[t,...e];return n&&s.length>n?s.slice(0,-1):s}var Bi=Symbol();function Uu(e,t){return!e.queryFn&&t?.initialPromise?()=>t.initialPromise:!e.queryFn||e.queryFn===Bi?()=>Promise.reject(new Error(`Missing queryFn: '${e.queryHash}'`)):e.queryFn}function MR(e,t){return typeof e=="function"?e(...t):!!e}function Sm(e,t,n){let s=!1,r;return Object.defineProperty(e,"signal",{enumerable:!0,get:()=>(r??=t(),s||(s=!0,r.aborted?n():r.addEventListener("abort",n,{once:!0})),r)}),e}var qu=(()=>{let e=()=>fm;return{isServer(){return e()},setIsServer(t){e=t}}})();function km(){let e,t;const n=new Promise((r,o)=>{e=r,t=o});n.status="pending",n.catch(()=>{});function s(r){Object.assign(n,r),delete n.resolve,delete n.reject}return n.resolve=r=>{s({status:"fulfilled",value:r}),e(r)},n.reject=r=>{s({status:"rejected",reason:r}),t(r)},n}var Tm=dm;function _m(){let e=[],t=0,n=a=>{a()},s=a=>{a()},r=Tm;const o=a=>{t?e.push(a):r(()=>{n(a)})},i=()=>{const a=e;e=[],a.length&&r(()=>{s(()=>{a.forEach(c=>{n(c)})})})};return{batch:a=>{let c;t++;try{c=a()}finally{t--,t||i()}return c},batchCalls:a=>(...c)=>{o(()=>{a(...c)})},schedule:o,setNotifyFunction:a=>{n=a},setBatchNotifyFunction:a=>{s=a},setScheduler:a=>{r=a}}}var Xe=_m(),Pm=class extends $r{#e=!0;#t;#n;constructor(){super(),this.#n=e=>{if(typeof window<"u"&&window.addEventListener){const t=()=>e(!0),n=()=>e(!1);return window.addEventListener("online",t,!1),window.addEventListener("offline",n,!1),()=>{window.removeEventListener("online",t),window.removeEventListener("offline",n)}}}}onSubscribe(){this.#t||this.setEventListener(this.#n)}onUnsubscribe(){this.hasListeners()||(this.#t?.(),this.#t=void 0)}setEventListener(e){this.#n=e,this.#t?.(),this.#t=e(this.setOnline.bind(this))}setOnline(e){this.#e!==e&&(this.#e=e,this.listeners.forEach(n=>{n(e)}))}isOnline(){return this.#e}},vr=new Pm;function Em(e){return Math.min(1e3*2**e,3e4)}function Gu(e){return(e??"online")==="online"?vr.isOnline():!0}var ti=class extends Error{constructor(e){super("CancelledError"),this.revert=e?.revert,this.silent=e?.silent}};function Wu(e){let t=!1,n=0,s;const r=km(),o=()=>r.status!=="pending",i=g=>{if(!o()){const y=new ti(g);f(y),e.onCancel?.(y)}},a=()=>{t=!0},c=()=>{t=!1},u=()=>Vu.isFocused()&&(e.networkMode==="always"||vr.isOnline())&&e.canRun(),d=()=>Gu(e.networkMode)&&e.canRun(),l=g=>{o()||(s?.(),r.resolve(g))},f=g=>{o()||(s?.(),r.reject(g))},p=()=>new Promise(g=>{s=y=>{(o()||u())&&g(y)},e.onPause?.()}).then(()=>{s=void 0,o()||e.onContinue?.()}),m=()=>{if(o())return;let g;const y=n===0?e.initialPromise:void 0;try{g=y??e.fn()}catch(v){g=Promise.reject(v)}Promise.resolve(g).then(l).catch(v=>{if(o())return;const k=e.retry??(qu.isServer()?0:3),S=e.retryDelay??Em,w=typeof S=="function"?S(n,v):S,T=k===!0||typeof k=="number"&&nu()?void 0:p()).then(()=>{t?f(v):m()})})};return{promise:r,status:()=>r.status,cancel:i,continue:()=>(s?.(),r),cancelRetry:a,continueRetry:c,canStart:d,start:()=>(d()?m():p().then(m),r)}}var Hu=class{#e;destroy(){this.clearGcTimeout()}scheduleGc(){this.clearGcTimeout(),pm(this.gcTime)&&(this.#e=Yo.setTimeout(()=>{this.optionalRemove()},this.gcTime))}updateGcTime(e){this.gcTime=Math.max(this.gcTime||0,e??(qu.isServer()?1/0:300*1e3))}clearGcTimeout(){this.#e!==void 0&&(Yo.clearTimeout(this.#e),this.#e=void 0)}};function Cm(e){return{onFetch:(t,n)=>{const s=t.options,r=t.fetchOptions?.meta?.fetchMore?.direction,o=t.state.data?.pages||[],i=t.state.data?.pageParams||[];let a={pages:[],pageParams:[]},c=0;const u=async()=>{let d=!1;const l=m=>{Sm(m,()=>t.signal,()=>d=!0)},f=Uu(t.options,t.fetchOptions),p=async(m,g,y)=>{if(d)return Promise.reject(t.signal.reason);if(g==null&&m.pages.length)return Promise.resolve(m);const k=(()=>{const _={client:t.client,queryKey:t.queryKey,pageParam:g,direction:y?"backward":"forward",meta:t.options.meta};return l(_),_})(),S=await f(k),{maxPages:w}=t.options,T=y?xm:wm;return{pages:T(m.pages,S,w),pageParams:T(m.pageParams,g,w)}};if(r&&o.length){const m=r==="backward",g=m?Am:oc,y={pages:o,pageParams:i},v=g(s,y);a=await p(y,v,m)}else{const m=e??o.length;do{const g=c===0?i[0]??s.initialPageParam:oc(s,a);if(c>0&&g==null)break;a=await p(a,g),c++}while(ct.options.persister?.(u,{client:t.client,queryKey:t.queryKey,meta:t.options.meta,signal:t.signal},n):t.fetchFn=u}}}function oc(e,{pages:t,pageParams:n}){const s=t.length-1;return t.length>0?e.getNextPageParam(t[s],t,n[s],n):void 0}function Am(e,{pages:t,pageParams:n}){return t.length>0?e.getPreviousPageParam?.(t[0],t,n[0],n):void 0}var Rm=class extends Hu{#e;#t;#n;#r;#o;#s;#c;#i;constructor(e){super(),this.#i=!1,this.#c=e.defaultOptions,this.setOptions(e.options),this.observers=[],this.#o=e.client,this.#r=this.#o.getQueryCache(),this.queryKey=e.queryKey,this.queryHash=e.queryHash,this.#t=ac(this.options),this.state=e.state??this.#t,this.scheduleGc()}get meta(){return this.options.meta}get queryType(){return this.#e}get promise(){return this.#s?.promise}setOptions(e){if(this.options={...this.#c,...e},e?._type&&(this.#e=e._type),this.updateGcTime(this.options.gcTime),this.state&&this.state.data===void 0){const t=ac(this.options);t.data!==void 0&&(this.setState(ic(t.data,t.dataUpdatedAt)),this.#t=t)}}optionalRemove(){!this.observers.length&&this.state.fetchStatus==="idle"&&this.#r.remove(this)}setData(e,t){const n=vm(this.state.data,e,this.options);return this.#a({data:n,type:"success",dataUpdatedAt:t?.updatedAt,manual:t?.manual}),n}setState(e){this.#a({type:"setState",state:e})}cancel(e){const t=this.#s?.promise;return this.#s?.cancel(e),t?t.then(wt).catch(wt):Promise.resolve()}destroy(){super.destroy(),this.cancel({silent:!0})}get resetState(){return this.#t}reset(){this.destroy(),this.setState(this.resetState)}isActive(){return this.observers.some(e=>gm(e.options.enabled,this)!==!1)}isDisabled(){return this.getObserversCount()>0?!this.isActive():this.options.queryFn===Bi||!this.isFetched()}isFetched(){return this.state.dataUpdateCount+this.state.errorUpdateCount>0}isStatic(){return this.getObserversCount()>0?this.observers.some(e=>Jo(e.options.staleTime,this)==="static"):!1}isStale(){return this.getObserversCount()>0?this.observers.some(e=>e.getCurrentResult().isStale):this.state.data===void 0||this.state.isInvalidated}isStaleByTime(e=0){return this.state.data===void 0?!0:e==="static"?!1:this.state.isInvalidated?!0:!mm(this.state.dataUpdatedAt,e)}onFocus(){this.observers.find(t=>t.shouldFetchOnWindowFocus())?.refetch({cancelRefetch:!1}),this.#s?.continue()}onOnline(){this.observers.find(t=>t.shouldFetchOnReconnect())?.refetch({cancelRefetch:!1}),this.#s?.continue()}addObserver(e){this.observers.includes(e)||(this.observers.push(e),this.clearGcTimeout(),this.#r.notify({type:"observerAdded",query:this,observer:e}))}removeObserver(e){this.observers.includes(e)&&(this.observers=this.observers.filter(t=>t!==e),this.observers.length||(this.#s&&(this.#i||this.#l()?this.#s.cancel({revert:!0}):this.#s.cancelRetry()),this.scheduleGc()),this.#r.notify({type:"observerRemoved",query:this,observer:e}))}getObserversCount(){return this.observers.length}#l(){return this.state.fetchStatus==="paused"&&this.state.status==="pending"}invalidate(){this.state.isInvalidated||this.#a({type:"invalidate"})}async fetch(e,t){if(this.state.fetchStatus!=="idle"&&this.#s?.status()!=="rejected"){if(this.state.data!==void 0&&t?.cancelRefetch)this.cancel({silent:!0});else if(this.#s)return this.#s.continueRetry(),this.#s.promise}if(e&&this.setOptions(e),!this.options.queryFn){const c=this.observers.find(u=>u.options.queryFn);c&&this.setOptions(c.options)}const n=new AbortController,s=c=>{Object.defineProperty(c,"signal",{enumerable:!0,get:()=>(this.#i=!0,n.signal)})},r=()=>{const c=Uu(this.options,t),d=(()=>{const l={client:this.#o,queryKey:this.queryKey,meta:this.meta};return s(l),l})();return this.#i=!1,this.options.persister?this.options.persister(c,d,this):c(d)},i=(()=>{const c={fetchOptions:t,options:this.options,queryKey:this.queryKey,client:this.#o,state:this.state,fetchFn:r};return s(c),c})();(this.#e==="infinite"?Cm(this.options.pages):this.options.behavior)?.onFetch(i,this),this.#n=this.state,(this.state.fetchStatus==="idle"||this.state.fetchMeta!==i.fetchOptions?.meta)&&this.#a({type:"fetch",meta:i.fetchOptions?.meta}),this.#s=Wu({initialPromise:t?.initialPromise,fn:i.fetchFn,onCancel:c=>{c instanceof ti&&c.revert&&this.setState({...this.#n,fetchStatus:"idle"}),n.abort()},onFail:(c,u)=>{this.#a({type:"failed",failureCount:c,error:u})},onPause:()=>{this.#a({type:"pause"})},onContinue:()=>{this.#a({type:"continue"})},retry:i.options.retry,retryDelay:i.options.retryDelay,networkMode:i.options.networkMode,canRun:()=>!0});try{const c=await this.#s.start();if(c===void 0)throw new Error(`${this.queryHash} data is undefined`);return this.setData(c),this.#r.config.onSuccess?.(c,this),this.#r.config.onSettled?.(c,this.state.error,this),c}catch(c){if(c instanceof ti){if(c.silent)return this.#s.promise;if(c.revert){if(this.state.data===void 0)throw c;return this.state.data}}throw this.#a({type:"error",error:c}),this.#r.config.onError?.(c,this),this.#r.config.onSettled?.(this.state.data,c,this),c}finally{this.scheduleGc()}}#a(e){const t=n=>{switch(e.type){case"failed":return{...n,fetchFailureCount:e.failureCount,fetchFailureReason:e.error};case"pause":return{...n,fetchStatus:"paused"};case"continue":return{...n,fetchStatus:"fetching"};case"fetch":return{...n,...Mm(n.data,this.options),fetchMeta:e.meta??null};case"success":const s={...n,...ic(e.data,e.dataUpdatedAt),dataUpdateCount:n.dataUpdateCount+1,...!e.manual&&{fetchStatus:"idle",fetchFailureCount:0,fetchFailureReason:null}};return this.#n=e.manual?s:void 0,s;case"error":const r=e.error;return{...n,error:r,errorUpdateCount:n.errorUpdateCount+1,errorUpdatedAt:Date.now(),fetchFailureCount:n.fetchFailureCount+1,fetchFailureReason:r,fetchStatus:"idle",status:"error",isInvalidated:!0};case"invalidate":return{...n,isInvalidated:!0};case"setState":return{...n,...e.state}}};this.state=t(this.state),Xe.batch(()=>{this.observers.forEach(n=>{n.onQueryUpdate()}),this.#r.notify({query:this,type:"updated",action:e})})}};function Mm(e,t){return{fetchFailureCount:0,fetchFailureReason:null,fetchStatus:Gu(t.networkMode)?"fetching":"paused",...e===void 0&&{error:null,status:"pending"}}}function ic(e,t){return{data:e,dataUpdatedAt:t??Date.now(),error:null,isInvalidated:!1,status:"success"}}function ac(e){const t=typeof e.initialData=="function"?e.initialData():e.initialData,n=t!==void 0,s=n?typeof e.initialDataUpdatedAt=="function"?e.initialDataUpdatedAt():e.initialDataUpdatedAt:0;return{data:t,dataUpdateCount:0,dataUpdatedAt:n?s??Date.now():0,error:null,errorUpdateCount:0,errorUpdatedAt:0,fetchFailureCount:0,fetchFailureReason:null,fetchMeta:null,isInvalidated:!1,status:n?"success":"pending",fetchStatus:"idle"}}var Im=class extends Hu{#e;#t;#n;#r;constructor(e){super(),this.#e=e.client,this.mutationId=e.mutationId,this.#n=e.mutationCache,this.#t=[],this.state=e.state||Dm(),this.setOptions(e.options),this.scheduleGc()}setOptions(e){this.options=e,this.updateGcTime(this.options.gcTime)}get meta(){return this.options.meta}addObserver(e){this.#t.includes(e)||(this.#t.push(e),this.clearGcTimeout(),this.#n.notify({type:"observerAdded",mutation:this,observer:e}))}removeObserver(e){this.#t=this.#t.filter(t=>t!==e),this.scheduleGc(),this.#n.notify({type:"observerRemoved",mutation:this,observer:e})}optionalRemove(){this.#t.length||(this.state.status==="pending"?this.scheduleGc():this.#n.remove(this))}continue(){return this.#r?.continue()??this.execute(this.state.variables)}async execute(e){const t=()=>{this.#o({type:"continue"})},n={client:this.#e,meta:this.options.meta,mutationKey:this.options.mutationKey};this.#r=Wu({fn:()=>this.options.mutationFn?this.options.mutationFn(e,n):Promise.reject(new Error("No mutationFn found")),onFail:(o,i)=>{this.#o({type:"failed",failureCount:o,error:i})},onPause:()=>{this.#o({type:"pause"})},onContinue:t,retry:this.options.retry??0,retryDelay:this.options.retryDelay,networkMode:this.options.networkMode,canRun:()=>this.#n.canRun(this)});const s=this.state.status==="pending",r=!this.#r.canStart();try{if(s)t();else{this.#o({type:"pending",variables:e,isPaused:r}),this.#n.config.onMutate&&await this.#n.config.onMutate(e,this,n);const i=await this.options.onMutate?.(e,n);i!==this.state.context&&this.#o({type:"pending",context:i,variables:e,isPaused:r})}const o=await this.#r.start();return await this.#n.config.onSuccess?.(o,e,this.state.context,this,n),await this.options.onSuccess?.(o,e,this.state.context,n),await this.#n.config.onSettled?.(o,null,this.state.variables,this.state.context,this,n),await this.options.onSettled?.(o,null,e,this.state.context,n),this.#o({type:"success",data:o}),o}catch(o){try{await this.#n.config.onError?.(o,e,this.state.context,this,n)}catch(i){Promise.reject(i)}try{await this.options.onError?.(o,e,this.state.context,n)}catch(i){Promise.reject(i)}try{await this.#n.config.onSettled?.(void 0,o,this.state.variables,this.state.context,this,n)}catch(i){Promise.reject(i)}try{await this.options.onSettled?.(void 0,o,e,this.state.context,n)}catch(i){Promise.reject(i)}throw this.#o({type:"error",error:o}),o}finally{this.#n.runNext(this)}}#o(e){const t=n=>{switch(e.type){case"failed":return{...n,failureCount:e.failureCount,failureReason:e.error};case"pause":return{...n,isPaused:!0};case"continue":return{...n,isPaused:!1};case"pending":return{...n,context:e.context,data:void 0,failureCount:0,failureReason:null,error:null,isPaused:e.isPaused,status:"pending",variables:e.variables,submittedAt:Date.now()};case"success":return{...n,data:e.data,failureCount:0,failureReason:null,error:null,status:"success",isPaused:!1};case"error":return{...n,data:void 0,error:e.error,failureCount:n.failureCount+1,failureReason:e.error,isPaused:!1,status:"error"}}};this.state=t(this.state),Xe.batch(()=>{this.#t.forEach(n=>{n.onMutationUpdate(e)}),this.#n.notify({mutation:this,type:"updated",action:e})})}};function Dm(){return{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:"idle",variables:void 0,submittedAt:0}}var Om=class extends $r{constructor(e={}){super(),this.config=e,this.#e=new Set,this.#t=new Map,this.#n=0}#e;#t;#n;build(e,t,n){const s=new Im({client:e,mutationCache:this,mutationId:++this.#n,options:e.defaultMutationOptions(t),state:n});return this.add(s),s}add(e){this.#e.add(e);const t=$s(e);if(typeof t=="string"){const n=this.#t.get(t);n?n.push(e):this.#t.set(t,[e])}this.notify({type:"added",mutation:e})}remove(e){if(this.#e.delete(e)){const t=$s(e);if(typeof t=="string"){const n=this.#t.get(t);if(n)if(n.length>1){const s=n.indexOf(e);s!==-1&&n.splice(s,1)}else n[0]===e&&this.#t.delete(t)}}this.notify({type:"removed",mutation:e})}canRun(e){const t=$s(e);if(typeof t=="string"){const s=this.#t.get(t)?.find(r=>r.state.status==="pending");return!s||s===e}else return!0}runNext(e){const t=$s(e);return typeof t=="string"?this.#t.get(t)?.find(s=>s!==e&&s.state.isPaused)?.continue()??Promise.resolve():Promise.resolve()}clear(){Xe.batch(()=>{this.#e.forEach(e=>{this.notify({type:"removed",mutation:e})}),this.#e.clear(),this.#t.clear()})}getAll(){return Array.from(this.#e)}find(e){const t={exact:!0,...e};return this.getAll().find(n=>nc(t,n))}findAll(e={}){return this.getAll().filter(t=>nc(e,t))}notify(e){Xe.batch(()=>{this.listeners.forEach(t=>{t(e)})})}resumePausedMutations(){const e=this.getAll().filter(t=>t.state.isPaused);return Xe.batch(()=>Promise.all(e.map(t=>t.continue().catch(wt))))}};function $s(e){return e.options.scope?.id}var Lm=class extends $r{constructor(e={}){super(),this.config=e,this.#e=new Map}#e;build(e,t,n){const s=t.queryKey,r=t.queryHash??Vi(s,t);let o=this.get(r);return o||(o=new Rm({client:e,queryKey:s,queryHash:r,options:e.defaultQueryOptions(t),state:n,defaultOptions:e.getQueryDefaults(s)}),this.add(o)),o}add(e){this.#e.has(e.queryHash)||(this.#e.set(e.queryHash,e),this.notify({type:"added",query:e}))}remove(e){const t=this.#e.get(e.queryHash);t&&(e.destroy(),t===e&&this.#e.delete(e.queryHash),this.notify({type:"removed",query:e}))}clear(){Xe.batch(()=>{this.getAll().forEach(e=>{this.remove(e)})})}get(e){return this.#e.get(e)}getAll(){return[...this.#e.values()]}find(e){const t={exact:!0,...e};return this.getAll().find(n=>tc(t,n))}findAll(e={}){const t=this.getAll();return Object.keys(e).length>0?t.filter(n=>tc(e,n)):t}notify(e){Xe.batch(()=>{this.listeners.forEach(t=>{t(e)})})}onFocus(){Xe.batch(()=>{this.getAll().forEach(e=>{e.onFocus()})})}onOnline(){Xe.batch(()=>{this.getAll().forEach(e=>{e.onOnline()})})}},zm=class{#e;#t;#n;#r;#o;#s;#c;#i;constructor(e={}){this.#e=e.queryCache||new Lm,this.#t=e.mutationCache||new Om,this.#n=e.defaultOptions||{},this.#r=new Map,this.#o=new Map,this.#s=0}mount(){this.#s++,this.#s===1&&(this.#c=Vu.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onFocus())}),this.#i=vr.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onOnline())}))}unmount(){this.#s--,this.#s===0&&(this.#c?.(),this.#c=void 0,this.#i?.(),this.#i=void 0)}isFetching(e){return this.#e.findAll({...e,fetchStatus:"fetching"}).length}isMutating(e){return this.#t.findAll({...e,status:"pending"}).length}getQueryData(e){const t=this.defaultQueryOptions({queryKey:e});return this.#e.get(t.queryHash)?.state.data}ensureQueryData(e){const t=this.defaultQueryOptions(e),n=this.#e.build(this,t),s=n.state.data;return s===void 0?this.fetchQuery(e):(e.revalidateIfStale&&n.isStaleByTime(Jo(t.staleTime,n))&&this.prefetchQuery(t),Promise.resolve(s))}getQueriesData(e){return this.#e.findAll(e).map(({queryKey:t,state:n})=>{const s=n.data;return[t,s]})}setQueryData(e,t,n){const s=this.defaultQueryOptions({queryKey:e}),o=this.#e.get(s.queryHash)?.state.data,i=hm(t,o);if(i!==void 0)return this.#e.build(this,s).setData(i,{...n,manual:!0})}setQueriesData(e,t,n){return Xe.batch(()=>this.#e.findAll(e).map(({queryKey:s})=>[s,this.setQueryData(s,t,n)]))}getQueryState(e){const t=this.defaultQueryOptions({queryKey:e});return this.#e.get(t.queryHash)?.state}removeQueries(e){const t=this.#e;Xe.batch(()=>{t.findAll(e).forEach(n=>{t.remove(n)})})}resetQueries(e,t){const n=this.#e;return Xe.batch(()=>(n.findAll(e).forEach(s=>{s.reset()}),this.refetchQueries({type:"active",...e},t)))}cancelQueries(e,t={}){const n={revert:!0,...t},s=Xe.batch(()=>this.#e.findAll(e).map(r=>r.cancel(n)));return Promise.all(s).then(wt).catch(wt)}invalidateQueries(e,t={}){return Xe.batch(()=>(this.#e.findAll(e).forEach(n=>{n.invalidate()}),e?.refetchType==="none"?Promise.resolve():this.refetchQueries({...e,type:e?.refetchType??e?.type??"active"},t)))}refetchQueries(e,t={}){const n={...t,cancelRefetch:t.cancelRefetch??!0},s=Xe.batch(()=>this.#e.findAll(e).filter(r=>!r.isDisabled()&&!r.isStatic()).map(r=>{let o=r.fetch(void 0,n);return n.throwOnError||(o=o.catch(wt)),r.state.fetchStatus==="paused"?Promise.resolve():o}));return Promise.all(s).then(wt)}fetchQuery(e){const t=this.defaultQueryOptions(e);t.retry===void 0&&(t.retry=!1);const n=this.#e.build(this,t);return n.isStaleByTime(Jo(t.staleTime,n))?n.fetch(t):Promise.resolve(n.state.data)}prefetchQuery(e){return this.fetchQuery(e).then(wt).catch(wt)}fetchInfiniteQuery(e){return e._type="infinite",this.fetchQuery(e)}prefetchInfiniteQuery(e){return this.fetchInfiniteQuery(e).then(wt).catch(wt)}ensureInfiniteQueryData(e){return e._type="infinite",this.ensureQueryData(e)}resumePausedMutations(){return vr.isOnline()?this.#t.resumePausedMutations():Promise.resolve()}getQueryCache(){return this.#e}getMutationCache(){return this.#t}getDefaultOptions(){return this.#n}setDefaultOptions(e){this.#n=e}setQueryDefaults(e,t){this.#r.set(hs(e),{queryKey:e,defaultOptions:t})}getQueryDefaults(e){const t=[...this.#r.values()],n={};return t.forEach(s=>{ps(e,s.queryKey)&&Object.assign(n,s.defaultOptions)}),n}setMutationDefaults(e,t){this.#o.set(hs(e),{mutationKey:e,defaultOptions:t})}getMutationDefaults(e){const t=[...this.#o.values()],n={};return t.forEach(s=>{ps(e,s.mutationKey)&&Object.assign(n,s.defaultOptions)}),n}defaultQueryOptions(e){if(e._defaulted)return e;const t={...this.#n.queries,...this.getQueryDefaults(e.queryKey),...e,_defaulted:!0};return t.queryHash||(t.queryHash=Vi(t.queryKey,t)),t.refetchOnReconnect===void 0&&(t.refetchOnReconnect=t.networkMode!=="always"),t.throwOnError===void 0&&(t.throwOnError=!!t.suspense),!t.networkMode&&t.persister&&(t.networkMode="offlineFirst"),t.queryFn===Bi&&(t.enabled=!1),t}defaultMutationOptions(e){return e?._defaulted?e:{...this.#n.mutations,...e?.mutationKey&&this.getMutationDefaults(e.mutationKey),...e,_defaulted:!0}}clear(){this.#e.clear(),this.#t.clear()}},Zu=h.createContext(void 0),IR=e=>{const t=h.useContext(Zu);if(!t)throw new Error("No QueryClient set, use QueryClientProvider to set one");return t},jm=({client:e,children:t})=>(h.useEffect(()=>(e.mount(),()=>{e.unmount()}),[e]),b.jsx(Zu.Provider,{value:e,children:t}));/** + * react-router v7.14.2 + * + * Copyright (c) Remix Software Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE.md file in the root directory of this source tree. + * + * @license MIT + */var cc="popstate";function lc(e){return typeof e=="object"&&e!=null&&"pathname"in e&&"search"in e&&"hash"in e&&"state"in e&&"key"in e}function Nm(e={}){function t(s,r){let o=r.state?.masked,{pathname:i,search:a,hash:c}=o||s.location;return ni("",{pathname:i,search:a,hash:c},r.state&&r.state.usr||null,r.state&&r.state.key||"default",o?{pathname:s.location.pathname,search:s.location.search,hash:s.location.hash}:void 0)}function n(s,r){return typeof r=="string"?r:ms(r)}return Fm(t,n,null,e)}function Le(e,t){if(e===!1||e===null||typeof e>"u")throw new Error(t)}function Ot(e,t){if(!e){typeof console<"u"&&console.warn(t);try{throw new Error(t)}catch{}}}function $m(){return Math.random().toString(36).substring(2,10)}function uc(e,t){return{usr:e.state,key:e.key,idx:t,masked:e.unstable_mask?{pathname:e.pathname,search:e.search,hash:e.hash}:void 0}}function ni(e,t,n=null,s,r){return{pathname:typeof e=="string"?e:e.pathname,search:"",hash:"",...typeof t=="string"?Ts(t):t,state:n,key:t&&t.key||s||$m(),unstable_mask:r}}function ms({pathname:e="/",search:t="",hash:n=""}){return t&&t!=="?"&&(e+=t.charAt(0)==="?"?t:"?"+t),n&&n!=="#"&&(e+=n.charAt(0)==="#"?n:"#"+n),e}function Ts(e){let t={};if(e){let n=e.indexOf("#");n>=0&&(t.hash=e.substring(n),e=e.substring(0,n));let s=e.indexOf("?");s>=0&&(t.search=e.substring(s),e=e.substring(0,s)),e&&(t.pathname=e)}return t}function Fm(e,t,n,s={}){let{window:r=document.defaultView,v5Compat:o=!1}=s,i=r.history,a="POP",c=null,u=d();u==null&&(u=0,i.replaceState({...i.state,idx:u},""));function d(){return(i.state||{idx:null}).idx}function l(){a="POP";let y=d(),v=y==null?null:y-u;u=y,c&&c({action:a,location:g.location,delta:v})}function f(y,v){a="PUSH";let k=lc(y)?y:ni(g.location,y,v);u=d()+1;let S=uc(k,u),w=g.createHref(k.unstable_mask||k);try{i.pushState(S,"",w)}catch(T){if(T instanceof DOMException&&T.name==="DataCloneError")throw T;r.location.assign(w)}o&&c&&c({action:a,location:g.location,delta:1})}function p(y,v){a="REPLACE";let k=lc(y)?y:ni(g.location,y,v);u=d();let S=uc(k,u),w=g.createHref(k.unstable_mask||k);i.replaceState(S,"",w),o&&c&&c({action:a,location:g.location,delta:0})}function m(y){return Vm(y)}let g={get action(){return a},get location(){return e(r,i)},listen(y){if(c)throw new Error("A history only accepts one active listener");return r.addEventListener(cc,l),c=y,()=>{r.removeEventListener(cc,l),c=null}},createHref(y){return t(r,y)},createURL:m,encodeLocation(y){let v=m(y);return{pathname:v.pathname,search:v.search,hash:v.hash}},push:f,replace:p,go(y){return i.go(y)}};return g}function Vm(e,t=!1){let n="http://localhost";typeof window<"u"&&(n=window.location.origin!=="null"?window.location.origin:window.location.href),Le(n,"No window.location.(origin|href) available to create URL");let s=typeof e=="string"?e:ms(e);return s=s.replace(/ $/,"%20"),!t&&s.startsWith("//")&&(s=n+s),new URL(s,n)}function Ku(e,t,n="/"){return Bm(e,t,n,!1)}function Bm(e,t,n,s){let r=typeof t=="string"?Ts(t):t,o=Bt(r.pathname||"/",n);if(o==null)return null;let i=Qu(e);Um(i);let a=null;for(let c=0;a==null&&c{let d={relativePath:u===void 0?i.path||"":u,caseSensitive:i.caseSensitive===!0,childrenIndex:a,route:i};if(d.relativePath.startsWith("/")){if(!d.relativePath.startsWith(s)&&c)return;Le(d.relativePath.startsWith(s),`Absolute route path "${d.relativePath}" nested under path "${s}" is not valid. An absolute child route path must start with the combined path of all its parent routes.`),d.relativePath=d.relativePath.slice(s.length)}let l=xt([s,d.relativePath]),f=n.concat(d);i.children&&i.children.length>0&&(Le(i.index!==!0,`Index routes must not have child routes. Please remove all child routes from route path "${l}".`),Qu(i.children,t,f,l,c)),!(i.path==null&&!i.index)&&t.push({path:l,score:Qm(l,i.index),routesMeta:f})};return e.forEach((i,a)=>{if(i.path===""||!i.path?.includes("?"))o(i,a);else for(let c of Xu(i.path))o(i,a,!0,c)}),t}function Xu(e){let t=e.split("/");if(t.length===0)return[];let[n,...s]=t,r=n.endsWith("?"),o=n.replace(/\?$/,"");if(s.length===0)return r?[o,""]:[o];let i=Xu(s.join("/")),a=[];return a.push(...i.map(c=>c===""?o:[o,c].join("/"))),r&&a.push(...i),a.map(c=>e.startsWith("/")&&c===""?"/":c)}function Um(e){e.sort((t,n)=>t.score!==n.score?n.score-t.score:Xm(t.routesMeta.map(s=>s.childrenIndex),n.routesMeta.map(s=>s.childrenIndex)))}var qm=/^:[\w-]+$/,Gm=3,Wm=2,Hm=1,Zm=10,Km=-2,dc=e=>e==="*";function Qm(e,t){let n=e.split("/"),s=n.length;return n.some(dc)&&(s+=Km),t&&(s+=Wm),n.filter(r=>!dc(r)).reduce((r,o)=>r+(qm.test(o)?Gm:o===""?Hm:Zm),s)}function Xm(e,t){return e.length===t.length&&e.slice(0,-1).every((s,r)=>s===t[r])?e[e.length-1]-t[t.length-1]:0}function Ym(e,t,n=!1){let{routesMeta:s}=e,r={},o="/",i=[];for(let a=0;a{if(d==="*"){let m=a[f]||"";i=o.slice(0,o.length-m.length).replace(/(.)\/+$/,"$1")}const p=a[f];return l&&!p?u[d]=void 0:u[d]=(p||"").replace(/%2F/g,"/"),u},{}),pathname:o,pathnameBase:i,pattern:e}}function Jm(e,t=!1,n=!0){Ot(e==="*"||!e.endsWith("*")||e.endsWith("/*"),`Route path "${e}" will be treated as if it were "${e.replace(/\*$/,"/*")}" because the \`*\` character must always follow a \`/\` in the pattern. To get rid of this warning, please change the route path to "${e.replace(/\*$/,"/*")}".`);let s=[],r="^"+e.replace(/\/*\*?$/,"").replace(/^\/*/,"/").replace(/[\\.*+^${}|()[\]]/g,"\\$&").replace(/\/:([\w-]+)(\?)?/g,(i,a,c,u,d)=>{if(s.push({paramName:a,isOptional:c!=null}),c){let l=d.charAt(u+i.length);return l&&l!=="/"?"/([^\\/]*)":"(?:/([^\\/]*))?"}return"/([^\\/]+)"}).replace(/\/([\w-]+)\?(\/|$)/g,"(/$1)?$2");return e.endsWith("*")?(s.push({paramName:"*"}),r+=e==="*"||e==="/*"?"(.*)$":"(?:\\/(.+)|\\/*)$"):n?r+="\\/*$":e!==""&&e!=="/"&&(r+="(?:(?=\\/|$))"),[new RegExp(r,t?void 0:"i"),s]}function eg(e){try{return e.split("/").map(t=>decodeURIComponent(t).replace(/\//g,"%2F")).join("/")}catch(t){return Ot(!1,`The URL path "${e}" could not be decoded because it is a malformed URL segment. This is probably due to a bad percent encoding (${t}).`),e}}function Bt(e,t){if(t==="/")return e;if(!e.toLowerCase().startsWith(t.toLowerCase()))return null;let n=t.endsWith("/")?t.length-1:t.length,s=e.charAt(n);return s&&s!=="/"?null:e.slice(n)||"/"}var tg=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;function ng(e,t="/"){let{pathname:n,search:s="",hash:r=""}=typeof e=="string"?Ts(e):e,o;return n?(n=Ju(n),n.startsWith("/")?o=fc(n.substring(1),"/"):o=fc(n,t)):o=t,{pathname:o,search:og(s),hash:ig(r)}}function fc(e,t){let n=xr(t).split("/");return e.split("/").forEach(r=>{r===".."?n.length>1&&n.pop():r!=="."&&n.push(r)}),n.length>1?n.join("/"):"/"}function mo(e,t,n,s){return`Cannot include a '${e}' character in a manually specified \`to.${t}\` field [${JSON.stringify(s)}]. Please separate it out to the \`to.${n}\` field. Alternatively you may provide the full path as a string in and the router will parse it for you.`}function sg(e){return e.filter((t,n)=>n===0||t.route.path&&t.route.path.length>0)}function Yu(e){let t=sg(e);return t.map((n,s)=>s===t.length-1?n.pathname:n.pathnameBase)}function Ui(e,t,n,s=!1){let r;typeof e=="string"?r=Ts(e):(r={...e},Le(!r.pathname||!r.pathname.includes("?"),mo("?","pathname","search",r)),Le(!r.pathname||!r.pathname.includes("#"),mo("#","pathname","hash",r)),Le(!r.search||!r.search.includes("#"),mo("#","search","hash",r)));let o=e===""||r.pathname==="",i=o?"/":r.pathname,a;if(i==null)a=n;else{let l=t.length-1;if(!s&&i.startsWith("..")){let f=i.split("/");for(;f[0]==="..";)f.shift(),l-=1;r.pathname=f.join("/")}a=l>=0?t[l]:"/"}let c=ng(r,a),u=i&&i!=="/"&&i.endsWith("/"),d=(o||i===".")&&n.endsWith("/");return!c.pathname.endsWith("/")&&(u||d)&&(c.pathname+="/"),c}var Ju=e=>e.replace(/\/\/+/g,"/"),xt=e=>Ju(e.join("/")),xr=e=>e.replace(/\/+$/,""),rg=e=>xr(e).replace(/^\/*/,"/"),og=e=>!e||e==="?"?"":e.startsWith("?")?e:"?"+e,ig=e=>!e||e==="#"?"":e.startsWith("#")?e:"#"+e,ag=class{constructor(e,t,n,s=!1){this.status=e,this.statusText=t||"",this.internal=s,n instanceof Error?(this.data=n.toString(),this.error=n):this.data=n}};function cg(e){return e!=null&&typeof e.status=="number"&&typeof e.statusText=="string"&&typeof e.internal=="boolean"&&"data"in e}function lg(e){let t=e.map(n=>n.route.path).filter(Boolean);return xt(t)||"/"}var ed=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function td(e,t){let n=e;if(typeof n!="string"||!tg.test(n))return{absoluteURL:void 0,isExternal:!1,to:n};let s=n,r=!1;if(ed)try{let o=new URL(window.location.href),i=n.startsWith("//")?new URL(o.protocol+n):new URL(n),a=Bt(i.pathname,t);i.origin===o.origin&&a!=null?n=a+i.search+i.hash:r=!0}catch{Ot(!1,` contains an invalid URL which will probably break when clicked - please update to a valid URL path.`)}return{absoluteURL:s,isExternal:r,to:n}}Object.getOwnPropertyNames(Object.prototype).sort().join("\0");var nd=["POST","PUT","PATCH","DELETE"];new Set(nd);var ug=["GET",...nd];new Set(ug);var qn=h.createContext(null);qn.displayName="DataRouter";var Fr=h.createContext(null);Fr.displayName="DataRouterState";var sd=h.createContext(!1);function dg(){return h.useContext(sd)}var rd=h.createContext({isTransitioning:!1});rd.displayName="ViewTransition";var fg=h.createContext(new Map);fg.displayName="Fetchers";var hg=h.createContext(null);hg.displayName="Await";var ft=h.createContext(null);ft.displayName="Navigation";var Vr=h.createContext(null);Vr.displayName="Location";var qt=h.createContext({outlet:null,matches:[],isDataRoute:!1});qt.displayName="Route";var qi=h.createContext(null);qi.displayName="RouteError";var od="REACT_ROUTER_ERROR",pg="REDIRECT",mg="ROUTE_ERROR_RESPONSE";function gg(e){if(e.startsWith(`${od}:${pg}:{`))try{let t=JSON.parse(e.slice(28));if(typeof t=="object"&&t&&typeof t.status=="number"&&typeof t.statusText=="string"&&typeof t.location=="string"&&typeof t.reloadDocument=="boolean"&&typeof t.replace=="boolean")return t}catch{}}function yg(e){if(e.startsWith(`${od}:${mg}:{`))try{let t=JSON.parse(e.slice(40));if(typeof t=="object"&&t&&typeof t.status=="number"&&typeof t.statusText=="string")return new ag(t.status,t.statusText,t.data)}catch{}}function bg(e,{relative:t}={}){Le(_s(),"useHref() may be used only in the context of a component.");let{basename:n,navigator:s}=h.useContext(ft),{hash:r,pathname:o,search:i}=Ps(e,{relative:t}),a=o;return n!=="/"&&(a=o==="/"?n:xt([n,o])),s.createHref({pathname:a,search:i,hash:r})}function _s(){return h.useContext(Vr)!=null}function zt(){return Le(_s(),"useLocation() may be used only in the context of a component."),h.useContext(Vr).location}var id="You should call navigate() in a React.useEffect(), not when your component is first rendered.";function ad(e){h.useContext(ft).static||h.useLayoutEffect(e)}function Gi(){let{isDataRoute:e}=h.useContext(qt);return e?Mg():vg()}function vg(){Le(_s(),"useNavigate() may be used only in the context of a component.");let e=h.useContext(qn),{basename:t,navigator:n}=h.useContext(ft),{matches:s}=h.useContext(qt),{pathname:r}=zt(),o=JSON.stringify(Yu(s)),i=h.useRef(!1);return ad(()=>{i.current=!0}),h.useCallback((c,u={})=>{if(Ot(i.current,id),!i.current)return;if(typeof c=="number"){n.go(c);return}let d=Ui(c,JSON.parse(o),r,u.relative==="path");e==null&&t!=="/"&&(d.pathname=d.pathname==="/"?t:xt([t,d.pathname])),(u.replace?n.replace:n.push)(d,u.state,u)},[t,n,o,r,e])}h.createContext(null);function Ps(e,{relative:t}={}){let{matches:n}=h.useContext(qt),{pathname:s}=zt(),r=JSON.stringify(Yu(n));return h.useMemo(()=>Ui(e,JSON.parse(r),s,t==="path"),[e,r,s,t])}function wg(e,t,n){Le(_s(),"useRoutes() may be used only in the context of a component.");let{navigator:s}=h.useContext(ft),{matches:r}=h.useContext(qt),o=r[r.length-1],i=o?o.params:{},a=o?o.pathname:"/",c=o?o.pathnameBase:"/",u=o&&o.route;{let y=u&&u.path||"";ld(a,!u||y.endsWith("*")||y.endsWith("*?"),`You rendered descendant (or called \`useRoutes()\`) at "${a}" (under ) but the parent route path has no trailing "*". This means if you navigate deeper, the parent won't match anymore and therefore the child routes will never render. + +Please change the parent to .`)}let d=zt(),l;l=d;let f=l.pathname||"/",p=f;if(c!=="/"){let y=c.replace(/^\//,"").split("/");p="/"+f.replace(/^\//,"").split("/").slice(y.length).join("/")}let m=Ku(e,{pathname:p});return Ot(u||m!=null,`No routes matched location "${l.pathname}${l.search}${l.hash}" `),Ot(m==null||m[m.length-1].route.element!==void 0||m[m.length-1].route.Component!==void 0||m[m.length-1].route.lazy!==void 0,`Matched leaf route at location "${l.pathname}${l.search}${l.hash}" does not have an element or Component. This means it will render an with a null value by default resulting in an "empty" page.`),_g(m&&m.map(y=>Object.assign({},y,{params:Object.assign({},i,y.params),pathname:xt([c,s.encodeLocation?s.encodeLocation(y.pathname.replace(/%/g,"%25").replace(/\?/g,"%3F").replace(/#/g,"%23")).pathname:y.pathname]),pathnameBase:y.pathnameBase==="/"?c:xt([c,s.encodeLocation?s.encodeLocation(y.pathnameBase.replace(/%/g,"%25").replace(/\?/g,"%3F").replace(/#/g,"%23")).pathname:y.pathnameBase])})),r,n)}function xg(){let e=Rg(),t=cg(e)?`${e.status} ${e.statusText}`:e instanceof Error?e.message:JSON.stringify(e),n=e instanceof Error?e.stack:null,s="rgba(200,200,200, 0.5)",r={padding:"0.5rem",backgroundColor:s},o={padding:"2px 4px",backgroundColor:s},i=null;return console.error("Error handled by React Router default ErrorBoundary:",e),i=h.createElement(h.Fragment,null,h.createElement("p",null,"💿 Hey developer 👋"),h.createElement("p",null,"You can provide a way better UX than this when your app throws errors by providing your own ",h.createElement("code",{style:o},"ErrorBoundary")," or"," ",h.createElement("code",{style:o},"errorElement")," prop on your route.")),h.createElement(h.Fragment,null,h.createElement("h2",null,"Unexpected Application Error!"),h.createElement("h3",{style:{fontStyle:"italic"}},t),n?h.createElement("pre",{style:r},n):null,i)}var Sg=h.createElement(xg,null),cd=class extends h.Component{constructor(e){super(e),this.state={location:e.location,revalidation:e.revalidation,error:e.error}}static getDerivedStateFromError(e){return{error:e}}static getDerivedStateFromProps(e,t){return t.location!==e.location||t.revalidation!=="idle"&&e.revalidation==="idle"?{error:e.error,location:e.location,revalidation:e.revalidation}:{error:e.error!==void 0?e.error:t.error,location:t.location,revalidation:e.revalidation||t.revalidation}}componentDidCatch(e,t){this.props.onError?this.props.onError(e,t):console.error("React Router caught the following error during render",e)}render(){let e=this.state.error;if(this.context&&typeof e=="object"&&e&&"digest"in e&&typeof e.digest=="string"){const n=yg(e.digest);n&&(e=n)}let t=e!==void 0?h.createElement(qt.Provider,{value:this.props.routeContext},h.createElement(qi.Provider,{value:e,children:this.props.component})):this.props.children;return this.context?h.createElement(kg,{error:e},t):t}};cd.contextType=sd;var go=new WeakMap;function kg({children:e,error:t}){let{basename:n}=h.useContext(ft);if(typeof t=="object"&&t&&"digest"in t&&typeof t.digest=="string"){let s=gg(t.digest);if(s){let r=go.get(t);if(r)throw r;let o=td(s.location,n);if(ed&&!go.get(t))if(o.isExternal||s.reloadDocument)window.location.href=o.absoluteURL||o.to;else{const i=Promise.resolve().then(()=>window.__reactRouterDataRouter.navigate(o.to,{replace:s.replace}));throw go.set(t,i),i}return h.createElement("meta",{httpEquiv:"refresh",content:`0;url=${o.absoluteURL||o.to}`})}}return e}function Tg({routeContext:e,match:t,children:n}){let s=h.useContext(qn);return s&&s.static&&s.staticContext&&(t.route.errorElement||t.route.ErrorBoundary)&&(s.staticContext._deepestRenderedBoundaryId=t.route.id),h.createElement(qt.Provider,{value:e},n)}function _g(e,t=[],n){let s=n?.state;if(e==null){if(!s)return null;if(s.errors)e=s.matches;else if(t.length===0&&!s.initialized&&s.matches.length>0)e=s.matches;else return null}let r=e,o=s?.errors;if(o!=null){let d=r.findIndex(l=>l.route.id&&o?.[l.route.id]!==void 0);Le(d>=0,`Could not find a matching route for errors on route IDs: ${Object.keys(o).join(",")}`),r=r.slice(0,Math.min(r.length,d+1))}let i=!1,a=-1;if(n&&s){i=s.renderFallback;for(let d=0;d=0?r=r.slice(0,a+1):r=[r[0]];break}}}}let c=n?.onError,u=s&&c?(d,l)=>{c(d,{location:s.location,params:s.matches?.[0]?.params??{},unstable_pattern:lg(s.matches),errorInfo:l})}:void 0;return r.reduceRight((d,l,f)=>{let p,m=!1,g=null,y=null;s&&(p=o&&l.route.id?o[l.route.id]:void 0,g=l.route.errorElement||Sg,i&&(a<0&&f===0?(ld("route-fallback",!1,"No `HydrateFallback` element provided to render during initial hydration"),m=!0,y=null):a===f&&(m=!0,y=l.route.hydrateFallbackElement||null)));let v=t.concat(r.slice(0,f+1)),k=()=>{let S;return p?S=g:m?S=y:l.route.Component?S=h.createElement(l.route.Component,null):l.route.element?S=l.route.element:S=d,h.createElement(Tg,{match:l,routeContext:{outlet:d,matches:v,isDataRoute:s!=null},children:S})};return s&&(l.route.ErrorBoundary||l.route.errorElement||f===0)?h.createElement(cd,{location:s.location,revalidation:s.revalidation,component:g,error:p,children:k(),routeContext:{outlet:null,matches:v,isDataRoute:!0},onError:u}):k()},null)}function Wi(e){return`${e} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`}function Pg(e){let t=h.useContext(qn);return Le(t,Wi(e)),t}function Eg(e){let t=h.useContext(Fr);return Le(t,Wi(e)),t}function Cg(e){let t=h.useContext(qt);return Le(t,Wi(e)),t}function Hi(e){let t=Cg(e),n=t.matches[t.matches.length-1];return Le(n.route.id,`${e} can only be used on routes that contain a unique "id"`),n.route.id}function Ag(){return Hi("useRouteId")}function Rg(){let e=h.useContext(qi),t=Eg("useRouteError"),n=Hi("useRouteError");return e!==void 0?e:t.errors?.[n]}function Mg(){let{router:e}=Pg("useNavigate"),t=Hi("useNavigate"),n=h.useRef(!1);return ad(()=>{n.current=!0}),h.useCallback(async(r,o={})=>{Ot(n.current,id),n.current&&(typeof r=="number"?await e.navigate(r):await e.navigate(r,{fromRouteId:t,...o}))},[e,t])}var hc={};function ld(e,t,n){!t&&!hc[e]&&(hc[e]=!0,Ot(!1,n))}h.memo(Ig);function Ig({routes:e,future:t,state:n,isStatic:s,onError:r}){return wg(e,void 0,{state:n,isStatic:s,onError:r})}function Dg({basename:e="/",children:t=null,location:n,navigationType:s="POP",navigator:r,static:o=!1,unstable_useTransitions:i}){Le(!_s(),"You cannot render a inside another . You should never have more than one in your app.");let a=e.replace(/^\/*/,"/"),c=h.useMemo(()=>({basename:a,navigator:r,static:o,unstable_useTransitions:i,future:{}}),[a,r,o,i]);typeof n=="string"&&(n=Ts(n));let{pathname:u="/",search:d="",hash:l="",state:f=null,key:p="default",unstable_mask:m}=n,g=h.useMemo(()=>{let y=Bt(u,a);return y==null?null:{location:{pathname:y,search:d,hash:l,state:f,key:p,unstable_mask:m},navigationType:s}},[a,u,d,l,f,p,s,m]);return Ot(g!=null,` is not able to match the URL "${u}${d}${l}" because it does not start with the basename, so the won't render anything.`),g==null?null:h.createElement(ft.Provider,{value:c},h.createElement(Vr.Provider,{children:t,value:g}))}var rr="get",or="application/x-www-form-urlencoded";function Br(e){return typeof HTMLElement<"u"&&e instanceof HTMLElement}function Og(e){return Br(e)&&e.tagName.toLowerCase()==="button"}function Lg(e){return Br(e)&&e.tagName.toLowerCase()==="form"}function zg(e){return Br(e)&&e.tagName.toLowerCase()==="input"}function jg(e){return!!(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)}function Ng(e,t){return e.button===0&&(!t||t==="_self")&&!jg(e)}var Fs=null;function $g(){if(Fs===null)try{new FormData(document.createElement("form"),0),Fs=!1}catch{Fs=!0}return Fs}var Fg=new Set(["application/x-www-form-urlencoded","multipart/form-data","text/plain"]);function yo(e){return e!=null&&!Fg.has(e)?(Ot(!1,`"${e}" is not a valid \`encType\` for \`
\`/\`\` and will default to "${or}"`),null):e}function Vg(e,t){let n,s,r,o,i;if(Lg(e)){let a=e.getAttribute("action");s=a?Bt(a,t):null,n=e.getAttribute("method")||rr,r=yo(e.getAttribute("enctype"))||or,o=new FormData(e)}else if(Og(e)||zg(e)&&(e.type==="submit"||e.type==="image")){let a=e.form;if(a==null)throw new Error('Cannot submit a