diff --git a/assets/AIChatPage-CI1qQgCG.js b/assets/AIChatPage-mgDEqx28.js similarity index 86% rename from assets/AIChatPage-CI1qQgCG.js rename to assets/AIChatPage-mgDEqx28.js index 327630cda83ada3637486933722a9d4ac7db04d0..0917612eeede71fe1288a1cf3455638d827fb1bf 100644 --- a/assets/AIChatPage-CI1qQgCG.js +++ b/assets/AIChatPage-mgDEqx28.js @@ -1,2 +1,2 @@ -const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-BaOs5Ayg.js","assets/vendor-react-B4AQeu28.js","assets/vendor-firebase-firestore-CH1lNiRF.js","assets/vendor-firebase-core-CO26nNq6.js","assets/vendor-firebase-auth-BLpRW_zO.js","assets/vendor-firebase-storage-B3igpVVS.js","assets/vendor-firebase-analytics-CTiUNb0-.js","assets/vendor-radix-BorKzPz9.js","assets/vendor-charts-D8hf8tI0.js","assets/vendor-markdown-yqZQ_iQm.js","assets/vendor-markdown-CfVKi3_s.css","assets/index-DdX2rVyy.css"])))=>i.map(i=>d[i]); -import{ay as D,u as F,_ as $,j as S,m as C,D as z}from"./index-BaOs5Ayg.js";import{r as a,j as e}from"./vendor-react-B4AQeu28.js";import{B as O}from"./button-DCfeFHoH.js";import{I}from"./input-D28h_UTJ.js";import H from"./ChatMarkdown-fgwaycBR.js";import{P as Y}from"./plus-DkG35AoH.js";import{S as G}from"./search-Bq99THgc.js";import{T as Q}from"./trash-2-HTnKafZd.js";import{S as W}from"./send-CwwDU3uJ.js";import"./vendor-firebase-firestore-CH1lNiRF.js";import"./vendor-firebase-core-CO26nNq6.js";import"./vendor-firebase-auth-BLpRW_zO.js";import"./vendor-firebase-storage-B3igpVVS.js";import"./vendor-firebase-analytics-CTiUNb0-.js";import"./vendor-radix-BorKzPz9.js";import"./vendor-charts-D8hf8tI0.js";import"./vendor-markdown-yqZQ_iQm.js";function q(r){return r?r instanceof Date?r.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):typeof r=="object"&&"toDate"in r?r.toDate().toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):String(r):""}const xe=()=>{const{sessions:r,activeSessionId:o,isLoading:l,loadingSessionId:A,setActiveSessionId:d,createNewSession:b,sendMessage:L,deleteSession:T,getActiveSession:_}=D(),{userProfile:c}=F(),[x,P]=a.useState(""),[n,g]=a.useState(""),[y,j]=a.useState(!1),m=a.useRef(null),h=a.useRef(!0),u=a.useRef(!1),i=_(),f=i?.messages||[],M=f.some(t=>t.sender==="ai"&&t.id.startsWith("stream-")),v=l&&o===A&&!M,w=(t="auto")=>{const s=m.current;s&&s.scrollTo({top:s.scrollHeight,behavior:t})},E=()=>{const t=m.current;return t?t.scrollHeight-t.scrollTop-t.clientHeight<=120:!0},R=()=>{h.current=E()};a.useEffect(()=>{$(async()=>{const{warmupBackend:t}=await import("./index-BaOs5Ayg.js").then(s=>s.b2);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)})},[]),a.useEffect(()=>{if(!h.current)return;const t=window.requestAnimationFrame(()=>w("auto"));return()=>window.cancelAnimationFrame(t)},[f,v]),a.useEffect(()=>{h.current=!0,w("auto")},[o]);const N=async()=>{if(!(!n.trim()||l||y||u.current)){u.current=!0,j(!0);try{let t=o;t||(t=b(),d(t));const s=n.trim();g(""),await L(t,s)}finally{u.current=!1,j(!1)}}},k=()=>{const t=b();d(t)},B=(t,s)=>{s.stopPropagation(),T(t)},p=r.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 gap-4 px-4 sm:px-6 xl:px-10 py-6",children:[e.jsxs("div",{className:"w-80 min-h-0 flex flex-col bg-[#f7f9fc] rounded-3xl 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 gap-3 mb-4",children:[e.jsx("div",{className:"w-12 h-12 bg-gradient-to-r from-sky-600 to-sky-500 rounded-2xl flex items-center justify-center",children:e.jsx("img",{src:"/avatar/avatar_icon.png",alt:"AI Tutor",className:"w-10 h-10 object-contain drop-shadow-md"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"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:k,className:"w-full bg-gradient-to-r from-sky-600 to-sky-500 hover:from-sky-700 hover:to-sky-600 text-white px-4 py-3 rounded-xl text-sm font-bold transition-all shadow-md hover:shadow-lg flex items-center justify-center gap-2",children:[e.jsx(Y,{size:18}),"New Chat"]}),e.jsxs("div",{className:"relative mt-3",children:[e.jsx(G,{className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-500",size:14}),e.jsx(I,{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:[p.length," Conversations"]})}),e.jsx(S,{children:p.map(t=>e.jsxs(C.div,{initial:{opacity:0,x:-20},animate:{opacity:1,x:0},exit:{opacity:0,x:-20},onClick:()=>d(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=>B(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))}),p.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:"flex-1 min-h-0 flex flex-col bg-[#f7f9fc] rounded-3xl border border-[#dde3eb] overflow-hidden",children:o?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"p-4 border-b border-[#dde3eb] flex items-center justify-between flex-shrink-0",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"font-bold font-display text-[#0a1628]",children:i?.title}),e.jsx("p",{className:"text-xs text-[#5a6578]",children:i?.date})]}),e.jsx("div",{className:"flex items-center gap-2",children:i?.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:m,onScroll:R,className:"flex-1 overflow-y-auto overscroll-contain p-6 space-y-4 bg-[#edf1f7] min-h-0",children:[e.jsx(S,{children:f.map(t=>e.jsxs(C.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(H,{children:t.text}),e.jsx("p",{className:`text-[10px] mt-1.5 ${t.sender==="user"?"text-sky-200":"text-slate-500"}`,children:q(t.timestamp)})]}),t.sender==="user"&&e.jsx(z,{src:c?.photo,name:c?.name,gender:c?.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-4 border-t border-[#dde3eb] bg-white flex-shrink-0",children:e.jsxs("div",{className:"flex gap-3",children:[e.jsx(I,{type:"text",value:n,onChange:t=>g(t.target.value),onKeyPress:t=>t.key==="Enter"&&N(),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:N,disabled:!n.trim()||l||y,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(W,{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:k,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{xe as default}; +const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-uASBzalf.js","assets/vendor-react-B4AQeu28.js","assets/vendor-firebase-firestore-CP9q7ISf.js","assets/vendor-firebase-core-DCQrgkxC.js","assets/vendor-firebase-auth-Bcpr4O6E.js","assets/vendor-firebase-storage-dc5X5yTv.js","assets/vendor-firebase-analytics-CHPyhRzk.js","assets/vendor-radix-xDOIcVzp.js","assets/vendor-charts-Ckgeb0nY.js","assets/vendor-markdown-yqZQ_iQm.js","assets/vendor-markdown-CfVKi3_s.css","assets/index-D9pRNq5G.css"])))=>i.map(i=>d[i]); +import{az as F,l as $,_ as z,g as S,m as C,F as D}from"./index-uASBzalf.js";import{r as a,j as e}from"./vendor-react-B4AQeu28.js";import{B as O}from"./button-BPmLcOpC.js";import{I}from"./input--XHWlmp1.js";import H from"./ChatMarkdown-BSQ2GO-C.js";import{P as Y}from"./plus-Cy6hz5PP.js";import{S as G}from"./search-Col42W4Q.js";import{T as Q}from"./trash-2-D7q6y9vT.js";import{S as W}from"./send-bMgoXVnc.js";import"./vendor-firebase-firestore-CP9q7ISf.js";import"./vendor-firebase-core-DCQrgkxC.js";import"./vendor-firebase-auth-Bcpr4O6E.js";import"./vendor-firebase-storage-dc5X5yTv.js";import"./vendor-firebase-analytics-CHPyhRzk.js";import"./vendor-radix-xDOIcVzp.js";import"./vendor-charts-Ckgeb0nY.js";import"./vendor-markdown-yqZQ_iQm.js";function q(r){return r?r instanceof Date?r.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):typeof r=="object"&&"toDate"in r?r.toDate().toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):String(r):""}const xe=()=>{const{sessions:r,activeSessionId:o,isLoading:l,loadingSessionId:A,setActiveSessionId:d,createNewSession:b,sendMessage:L,deleteSession:T,getActiveSession:_}=F(),{userProfile:c}=$(),[x,P]=a.useState(""),[n,g]=a.useState(""),[y,j]=a.useState(!1),m=a.useRef(null),h=a.useRef(!0),u=a.useRef(!1),i=_(),f=i?.messages||[],M=f.some(t=>t.sender==="ai"&&t.id.startsWith("stream-")),v=l&&o===A&&!M,w=(t="auto")=>{const s=m.current;s&&s.scrollTo({top:s.scrollHeight,behavior:t})},E=()=>{const t=m.current;return t?t.scrollHeight-t.scrollTop-t.clientHeight<=120:!0},R=()=>{h.current=E()};a.useEffect(()=>{z(async()=>{const{warmupBackend:t}=await import("./index-uASBzalf.js").then(s=>s.b3);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)})},[]),a.useEffect(()=>{if(!h.current)return;const t=window.requestAnimationFrame(()=>w("auto"));return()=>window.cancelAnimationFrame(t)},[f,v]),a.useEffect(()=>{h.current=!0,w("auto")},[o]);const N=async()=>{if(!(!n.trim()||l||y||u.current)){u.current=!0,j(!0);try{let t=o;t||(t=b(),d(t));const s=n.trim();g(""),await L(t,s)}finally{u.current=!1,j(!1)}}},k=()=>{const t=b();d(t)},B=(t,s)=>{s.stopPropagation(),T(t)},p=r.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 gap-4 px-4 sm:px-6 xl:px-10 py-6",children:[e.jsxs("div",{className:"w-80 min-h-0 flex flex-col bg-[#f7f9fc] rounded-3xl 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 gap-3 mb-4",children:[e.jsx("div",{className:"w-12 h-12 bg-gradient-to-r from-sky-600 to-sky-500 rounded-2xl flex items-center justify-center",children:e.jsx("img",{src:"/avatar/avatar_icon.png",alt:"AI Tutor",className:"w-10 h-10 object-contain drop-shadow-md"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"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:k,className:"w-full bg-gradient-to-r from-sky-600 to-sky-500 hover:from-sky-700 hover:to-sky-600 text-white px-4 py-3 rounded-xl text-sm font-bold transition-all shadow-md hover:shadow-lg flex items-center justify-center gap-2",children:[e.jsx(Y,{size:18}),"New Chat"]}),e.jsxs("div",{className:"relative mt-3",children:[e.jsx(G,{className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-500",size:14}),e.jsx(I,{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:[p.length," Conversations"]})}),e.jsx(S,{children:p.map(t=>e.jsxs(C.div,{initial:{opacity:0,x:-20},animate:{opacity:1,x:0},exit:{opacity:0,x:-20},onClick:()=>d(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=>B(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))}),p.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:"flex-1 min-h-0 flex flex-col bg-[#f7f9fc] rounded-3xl border border-[#dde3eb] overflow-hidden",children:o?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"p-4 border-b border-[#dde3eb] flex items-center justify-between flex-shrink-0",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"font-bold font-display text-[#0a1628]",children:i?.title}),e.jsx("p",{className:"text-xs text-[#5a6578]",children:i?.date})]}),e.jsx("div",{className:"flex items-center gap-2",children:i?.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:m,onScroll:R,className:"flex-1 overflow-y-auto overscroll-contain p-6 space-y-4 bg-[#edf1f7] min-h-0",children:[e.jsx(S,{children:f.map(t=>e.jsxs(C.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(H,{children:t.text}),e.jsx("p",{className:`text-[10px] mt-1.5 ${t.sender==="user"?"text-sky-200":"text-slate-500"}`,children:q(t.timestamp)})]}),t.sender==="user"&&e.jsx(D,{src:c?.photo,name:c?.name,gender:c?.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-4 border-t border-[#dde3eb] bg-white flex-shrink-0",children:e.jsxs("div",{className:"flex gap-3",children:[e.jsx(I,{type:"text",value:n,onChange:t=>g(t.target.value),onKeyPress:t=>t.key==="Enter"&&N(),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:N,disabled:!n.trim()||l||y,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(W,{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:k,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{xe as default}; diff --git a/assets/AdminDashboard-B2eiYi-q.js b/assets/AdminDashboard-DrvV_gE1.js similarity index 58% rename from assets/AdminDashboard-B2eiYi-q.js rename to assets/AdminDashboard-DrvV_gE1.js index 51b05c24f774ba8552f8660627e728a6e261a9e0..692c2dece8bd23dc400a641bd4dd711a7aea3849 100644 --- a/assets/AdminDashboard-B2eiYi-q.js +++ b/assets/AdminDashboard-DrvV_gE1.js @@ -1,64 +1,59 @@ -import{r as i,d as Jt,j as e}from"./vendor-react-B4AQeu28.js";import Fs from"./Sidebar-2LZAqf7E.js";import vs from"./ConfirmModal-6cgkqXAT.js";import{e as ce,h as ye,t as z,l as _,R as Ie,p as me,f as X,F as Zt,H as Yt,I as ea,k as ct,u as Re,m as U,z as Ns,L as ot,S as Ke,Z as mt,i as sa,J as Bs,K as qs,N as Os,U as Je,G as ks,y as xt,A as Ze,O as ut,B as ta,a as je,T as ht,o as aa,M as ra,D as ia}from"./index-BaOs5Ayg.js";import{B as M}from"./button-DCfeFHoH.js";import{S as re,a as ie,b as le,c as ne,d as P}from"./select-DIjxRWza.js";import{I as R}from"./input-D28h_UTJ.js";import{S as Xe}from"./subjects-BFghB0SQ.js";import{U as fs}from"./upload-DayXhGwD.js";import{F as Ye,I as we,D as qe,T as la,a as na,b as Gs,c as De,d as da,e as Te,f as ca}from"./table-xeOJ8ZAA.js";import{C as Hs,L as oa}from"./lightbulb-Ce2KQzGM.js";import{C as es}from"./chart-column-B3jJOD5i.js";import{C as ss}from"./circle-check-big-m1SvzGFL.js";import{D as gt,a as pt,b as ft,c as bt,d as jt,e as ma}from"./dialog-CHtYkwVl.js";import{getDocs as de,collection as se,query as ts,orderBy as vt,limit as ys,where as ws,addDoc as xa,serverTimestamp as Nt,doc as Cs,getDoc as yt,setDoc as ua,onSnapshot as ha}from"./vendor-firebase-firestore-CH1lNiRF.js";import{C as Se}from"./circle-alert-CP9K3300.js";import{S as wt}from"./search-Bq99THgc.js";import{E as as,a as _s}from"./eye-Ig3S6mOs.js";import{S as be}from"./switch-CblAJO7o.js";import{S as St,M as ga}from"./LogoutActionButton-lUNItet6.js";import{B as pa}from"./bell-clcSMJn6.js";import{C as fa,b as ba}from"./vendor-radix-BorKzPz9.js";import{C as ja}from"./check-BLSo9L0H.js";import{P as va}from"./plus-DkG35AoH.js";import{C as Na}from"./check-check-B_HghS1Z.js";import{M as ya}from"./mail-BbG1phxL.js";import{D as kt}from"./download-DX_YebqQ.js";import{T as Qs}from"./trash-2-HTnKafZd.js";import{C as Ct}from"./clock-D1Ecvltm.js";import{F as wa}from"./funnel-BT77sgnz.js";import{S as Z}from"./skeleton-Bo6ISWhm.js";import{u as Sa,t as ka,a as Ca}from"./useSubjectAvailability-Bvu3fXaT.js";import{S as Aa}from"./save-CQIJrhLf.js";import{u as za}from"./useQuery-BnRttv09.js";import{a as Pa}from"./chevron-up-Cdvz2TMJ.js";import{M as Da}from"./minus-DfrEv-SC.js";import"./tooltip-ChRIOid3.js";import"./x-TNvtuOD9.js";import"./chevron-right-COqGruhh.js";import"./chevron-left-BWpgclqc.js";import"./shirt-S3NBuaPm.js";import"./log-out-BenDMDly.js";import"./vendor-firebase-core-CO26nNq6.js";import"./vendor-firebase-auth-BLpRW_zO.js";import"./vendor-firebase-storage-B3igpVVS.js";import"./vendor-firebase-analytics-CTiUNb0-.js";import"./vendor-charts-D8hf8tI0.js";import"./vendor-markdown-yqZQ_iQm.js";/** +import{r as l,d as Zt,j as e}from"./vendor-react-B4AQeu28.js";import Bs from"./Sidebar-BxInp2XA.js";import Ns from"./ConfirmModal-D2z4s_BB.js";import{e as me,j as ye,n as z,p as H,R as Re,w as oe,h as X,I as Yt,J as ea,K as sa,o as ot,l as Ee,m as U,D as ys,L as mt,S as Je,Z as xt,k as ke,N as qs,O as Os,P as Gs,U as Ze,G as Cs,q as ut,A as Ye,Q as ht,B as ta,a as je,T as gt,v as aa,M as ra,F as la}from"./index-uASBzalf.js";import{B as M}from"./button-BPmLcOpC.js";import{S as re,a as le,b as ie,c as ne,d as P}from"./select--QYuvUGV.js";import{I as R}from"./input--XHWlmp1.js";import{S as Ke}from"./subjects-F8wTuRgo.js";import{U as bs}from"./upload-Ds5w3QNw.js";import{F as es,I as we,A as ws,D as Oe,T as ia}from"./trending-down-DQ2ZPRUy.js";import{C as _s,L as na}from"./lightbulb-CtjAK_uP.js";import{C as ss}from"./chart-column-CLoxLorp.js";import{C as ts}from"./circle-check-big-BNRlH5pv.js";import{D as pt,a as ft,b as bt,c as jt,d as vt,e as da}from"./dialog-CNHSYTtM.js";import{getDocs as de,collection as se,query as as,orderBy as Nt,limit as Ss,where as ks,addDoc as ca,serverTimestamp as yt,doc as As,getDoc as wt,setDoc as oa,onSnapshot as ma}from"./vendor-firebase-firestore-CP9q7ISf.js";import{C as Se}from"./circle-alert-DDOZHhZK.js";import{S as St}from"./search-Col42W4Q.js";import{E as rs,a as Hs}from"./eye-DIwMshM-.js";import{S as be}from"./switch-CZbBlSot.js";import{S as kt,M as xa}from"./LogoutActionButton-Dl6IiDHd.js";import{B as ua}from"./bell-CiUaN6S3.js";import{C as ha,a as ga}from"./vendor-radix-xDOIcVzp.js";import{C as pa}from"./check-Dk6iwDFI.js";import{P as fa}from"./plus-Cy6hz5PP.js";import{C as ba}from"./check-check-DFG24Nyg.js";import{M as ja}from"./mail-BF4xxwnI.js";import{D as Ct}from"./download-CVrPjUr0.js";import{T as Qs}from"./trash-2-D7q6y9vT.js";import{C as At}from"./clock-8t0UYgg3.js";import{F as va}from"./funnel-CSHS_tp4.js";import{S as Z}from"./skeleton-Ds4RcTr4.js";import{u as Na,t as ya,a as wa}from"./useSubjectAvailability-jmWCWhoq.js";import{S as Sa}from"./save-CoDXj-im.js";import{u as ka}from"./useQuery-CNXEt8jj.js";import{C as Ca}from"./chevron-up-BpMhRyJp.js";import{M as Aa}from"./minus-Bfei9C79.js";import"./tooltip-1ASn-3cE.js";import"./x-CBb03rh3.js";import"./chevron-right-U0AqPOPj.js";import"./chevron-left-CzSo_K0d.js";import"./shirt-DFJQeZbT.js";import"./log-out-Dr0BHRO4.js";import"./vendor-firebase-core-DCQrgkxC.js";import"./vendor-firebase-auth-Bcpr4O6E.js";import"./vendor-firebase-storage-dc5X5yTv.js";import"./vendor-firebase-analytics-CHPyhRzk.js";import"./vendor-charts-Ckgeb0nY.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 Ta=[["path",{d:"M22 12h-2.48a2 2 0 0 0-1.93 1.46l-2.35 8.36a.25.25 0 0 1-.48 0L9.24 2.18a.25.25 0 0 0-.48 0l-2.35 8.36A2 2 0 0 1 4.49 12H2",key:"169zse"}]],Ss=ce("activity",Ta);/** + */const za=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m4.9 4.9 14.2 14.2",key:"1m5liu"}]],Vs=me("ban",za);/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. - */const La=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m4.9 4.9 14.2 14.2",key:"1m5liu"}]],Vs=ce("ban",La);/** + */const Pa=[["path",{d:"M10 2v8l3-3 3 3V2",key:"sqw3rj"}],["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"}]],Da=me("book-marked",Pa);/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. - */const Ma=[["path",{d:"M10 2v8l3-3 3 3V2",key:"sqw3rj"}],["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"}]],Ia=ce("book-marked",Ma);/** + */const Ta=[["path",{d:"M21 12c.552 0 1.005-.449.95-.998a10 10 0 0 0-8.953-8.951c-.55-.055-.998.398-.998.95v8a1 1 0 0 0 1 1z",key:"pzmjnu"}],["path",{d:"M21.21 15.89A10 10 0 1 1 8 2.83",key:"k2fpak"}]],La=me("chart-pie",Ta);/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. - */const Ra=[["path",{d:"M21 12c.552 0 1.005-.449.95-.998a10 10 0 0 0-8.953-8.951c-.55-.055-.998.398-.998.95v8a1 1 0 0 0 1 1z",key:"pzmjnu"}],["path",{d:"M21.21 15.89A10 10 0 1 1 8 2.83",key:"k2fpak"}]],Ea=ce("chart-pie",Ra);/** + */const Ma=[["line",{x1:"12",x2:"12",y1:"2",y2:"22",key:"7eqyqh"}],["path",{d:"M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6",key:"1b0p4s"}]],Ws=me("dollar-sign",Ma);/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. - */const Ua=[["line",{x1:"12",x2:"12",y1:"2",y2:"22",key:"7eqyqh"}],["path",{d:"M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6",key:"1b0p4s"}]],Ws=ce("dollar-sign",Ua);/** + */const Ia=[["line",{x1:"6",x2:"10",y1:"11",y2:"11",key:"1gktln"}],["line",{x1:"8",x2:"8",y1:"9",y2:"13",key:"qnk9ow"}],["line",{x1:"15",x2:"15.01",y1:"12",y2:"12",key:"krot7o"}],["line",{x1:"18",x2:"18.01",y1:"10",y2:"10",key:"1lcuu1"}],["path",{d:"M17.32 5H6.68a4 4 0 0 0-3.978 3.59c-.006.052-.01.101-.017.152C2.604 9.416 2 14.456 2 16a3 3 0 0 0 3 3c1 0 1.5-.5 2-1l1.414-1.414A2 2 0 0 1 9.828 16h4.344a2 2 0 0 1 1.414.586L17 18c.5.5 1 1 2 1a3 3 0 0 0 3-3c0-1.545-.604-6.584-.685-7.258-.007-.05-.011-.1-.017-.151A4 4 0 0 0 17.32 5z",key:"mfqc10"}]],Ra=me("gamepad-2",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 $a=[["line",{x1:"6",x2:"10",y1:"11",y2:"11",key:"1gktln"}],["line",{x1:"8",x2:"8",y1:"9",y2:"13",key:"qnk9ow"}],["line",{x1:"15",x2:"15.01",y1:"12",y2:"12",key:"krot7o"}],["line",{x1:"18",x2:"18.01",y1:"10",y2:"10",key:"1lcuu1"}],["path",{d:"M17.32 5H6.68a4 4 0 0 0-3.978 3.59c-.006.052-.01.101-.017.152C2.604 9.416 2 14.456 2 16a3 3 0 0 0 3 3c1 0 1.5-.5 2-1l1.414-1.414A2 2 0 0 1 9.828 16h4.344a2 2 0 0 1 1.414.586L17 18c.5.5 1 1 2 1a3 3 0 0 0 3-3c0-1.545-.604-6.584-.685-7.258-.007-.05-.011-.1-.017-.151A4 4 0 0 0 17.32 5z",key:"mfqc10"}]],Fa=ce("gamepad-2",$a);/** + */const Ea=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M3 9h18",key:"1pudct"}],["path",{d:"M3 15h18",key:"5xshup"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"M15 3v18",key:"14nvp0"}]],Ua=me("grid-3x3",Ea);/** * @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 Ba=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M3 9h18",key:"1pudct"}],["path",{d:"M3 15h18",key:"5xshup"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"M15 3v18",key:"14nvp0"}]],qa=ce("grid-3x3",Ba);/** + */const $a=[["rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2",key:"1w4ew1"}],["path",{d:"M7 11V7a5 5 0 0 1 9.9-1",key:"1mm8w8"}]],Fa=me("lock-open",$a);/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. - */const Oa=[["rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2",key:"1w4ew1"}],["path",{d:"M7 11V7a5 5 0 0 1 9.9-1",key:"1mm8w8"}]],Ga=ce("lock-open",Oa);/** + */const Ba=[["path",{d:"M14 22v-4a2 2 0 1 0-4 0v4",key:"hhkicm"}],["path",{d:"m18 10 3.447 1.724a1 1 0 0 1 .553.894V20a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-7.382a1 1 0 0 1 .553-.894L6 10",key:"1xqip1"}],["path",{d:"M18 5v17",key:"1sw6gf"}],["path",{d:"m4 6 7.106-3.553a2 2 0 0 1 1.788 0L20 6",key:"9d2mlk"}],["path",{d:"M6 5v17",key:"1xfsm0"}],["circle",{cx:"12",cy:"9",r:"2",key:"1092wv"}]],qa=me("school",Ba);/** * @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=[["path",{d:"M14 22v-4a2 2 0 1 0-4 0v4",key:"hhkicm"}],["path",{d:"m18 10 3.447 1.724a1 1 0 0 1 .553.894V20a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-7.382a1 1 0 0 1 .553-.894L6 10",key:"1xqip1"}],["path",{d:"M18 5v17",key:"1sw6gf"}],["path",{d:"m4 6 7.106-3.553a2 2 0 0 1 1.788 0L20 6",key:"9d2mlk"}],["path",{d:"M6 5v17",key:"1xfsm0"}],["circle",{cx:"12",cy:"9",r:"2",key:"1092wv"}]],_a=ce("school",Ha);/** + */const Oa=[["path",{d:"M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7",key:"1m0v6g"}],["path",{d:"M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z",key:"ohrbg2"}]],Ga=me("square-pen",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 Qa=[["path",{d:"M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7",key:"1m0v6g"}],["path",{d:"M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z",key:"ohrbg2"}]],Va=ce("square-pen",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:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["polyline",{points:"16 11 18 13 22 9",key:"1pwet4"}]],Xs=ce("user-check",Wa),Xa=({onUploadSuccess:s})=>{const[t,l]=i.useState(!1),[r,h]=i.useState(null),[n,o]=i.useState(!1),[m,v]=i.useState(null),[p,S]=i.useState(""),[f,j]=i.useState(""),[w,A]=i.useState("1"),[k,d]=i.useState(0),[y,L]=i.useState(null),[C,B]=i.useState(!1),q=i.useRef(null),O=i.useCallback(async()=>{B(!0);try{const x=await ye.getRagHealth();L({subjects:x.subjects||{},chunkCount:x.chunkCount||0,lastIngested:x.lastIngested||""})}catch{z.error("Failed to load RAG health status")}finally{B(!1)}},[]);Jt.useEffect(()=>{O()},[O]);const G=x=>{if(x.type!=="application/pdf"){z.error("Only PDF files are allowed");return}if(x.size>50*1024*1024){z.error("File size must be under 50MB");return}if(v(x),p){const E=Xe.find(c=>c.id===p);E&&j(E.name)}},Y=i.useCallback(x=>{x.preventDefault(),o(!1);const E=x.dataTransfer.files[0];E&&G(E)},[p]),H=i.useCallback(x=>{x.preventDefault(),o(!0)},[]),ee=i.useCallback(()=>o(!1),[]),Q=x=>{S(x);const E=Xe.find(c=>c.id===x);E&&j(E.name)},oe=async()=>{if(!m||!p||!f.trim()){z.error("Please select a PDF file, subject, and enter a subject name");return}l(!0),d(0);try{const x=new FormData;x.append("file",m),x.append("subjectId",p),x.append("subjectName",f.trim()),x.append("quarter",w);const E=setInterval(()=>{d(u=>Math.min(u+15,85))},300),c=await ye.uploadModulePdf(x);clearInterval(E),d(100),c.success?(z.success(`${m.name} uploaded! ${c.chunkCount??0} chunks indexed.`),v(null),c.chunkCount!==void 0&&s?.(p,c.chunkCount),O()):z.error(c.error||"Upload failed")}catch(x){z.error(x instanceof Error?x.message:"Upload failed")}finally{l(!1),setTimeout(()=>d(0),500)}},b=async(x,E)=>{h(x);try{const c=await ye.reingestModulePdf(x,E);c.success?(z.success(`Re-ingestion complete for ${x}: ${c.chunkCount??0} chunks`),O()):z.error(c.error||"Re-ingestion failed")}catch(c){z.error(c instanceof Error?c.message:"Re-ingestion failed")}finally{h(null)}},V=y?Object.entries(y.subjects).map(([x,E])=>({name:x,chunks:E,storagePath:"",status:E>0?"active":"missing"})).filter(x=>x.chunks>0):[];return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"bg-white rounded-2xl border border-[#dde3eb] shadow-sm p-6",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-5",children:[e.jsx("div",{className:"w-10 h-10 bg-sky-100 rounded-xl flex items-center justify-center",children:e.jsx(fs,{size:20,className:"text-sky-600"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-bold text-[#0a1628]",children:"Upload Module PDF"}),e.jsx("p",{className:"text-xs text-[#5a6578]",children:"Upload a DepEd teaching module PDF and trigger RAG ingestion"})]})]}),e.jsxs("div",{onDrop:Y,onDragOver:H,onDragLeave:ee,onClick:()=>!t&&q.current?.click(),className:` + */const _a=[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["polyline",{points:"16 11 18 13 22 9",key:"1pwet4"}]],Xs=me("user-check",_a),Ha=({onUploadSuccess:s})=>{const[t,i]=l.useState(!1),[r,h]=l.useState(null),[n,o]=l.useState(!1),[m,v]=l.useState(null),[p,S]=l.useState(""),[f,j]=l.useState(""),[w,A]=l.useState("1"),[k,d]=l.useState(0),[y,L]=l.useState(null),[C,B]=l.useState(!1),q=l.useRef(null),O=l.useCallback(async()=>{B(!0);try{const x=await ye.getRagHealth();L({subjects:x.subjects||{},chunkCount:x.chunkCount||0,lastIngested:x.lastIngested||""})}catch{z.error("Failed to load RAG health status")}finally{B(!1)}},[]);Zt.useEffect(()=>{O()},[O]);const G=x=>{if(x.type!=="application/pdf"){z.error("Only PDF files are allowed");return}if(x.size>50*1024*1024){z.error("File size must be under 50MB");return}if(v(x),p){const E=Ke.find(c=>c.id===p);E&&j(E.name)}},Y=l.useCallback(x=>{x.preventDefault(),o(!1);const E=x.dataTransfer.files[0];E&&G(E)},[p]),_=l.useCallback(x=>{x.preventDefault(),o(!0)},[]),ee=l.useCallback(()=>o(!1),[]),Q=x=>{S(x);const E=Ke.find(c=>c.id===x);E&&j(E.name)},ce=async()=>{if(!m||!p||!f.trim()){z.error("Please select a PDF file, subject, and enter a subject name");return}i(!0),d(0);try{const x=new FormData;x.append("file",m),x.append("subjectId",p),x.append("subjectName",f.trim()),x.append("quarter",w);const E=setInterval(()=>{d(u=>Math.min(u+15,85))},300),c=await ye.uploadModulePdf(x);clearInterval(E),d(100),c.success?(z.success(`${m.name} uploaded! ${c.chunkCount??0} chunks indexed.`),v(null),c.chunkCount!==void 0&&s?.(p,c.chunkCount),O()):z.error(c.error||"Upload failed")}catch(x){z.error(x instanceof Error?x.message:"Upload failed")}finally{i(!1),setTimeout(()=>d(0),500)}},b=async(x,E)=>{h(x);try{const c=await ye.reingestModulePdf(x,E);c.success?(z.success(`Re-ingestion complete for ${x}: ${c.chunkCount??0} chunks`),O()):z.error(c.error||"Re-ingestion failed")}catch(c){z.error(c instanceof Error?c.message:"Re-ingestion failed")}finally{h(null)}},V=y?Object.entries(y.subjects).map(([x,E])=>({name:x,chunks:E,storagePath:"",status:E>0?"active":"missing"})).filter(x=>x.chunks>0):[];return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"bg-white rounded-2xl border border-[#dde3eb] shadow-sm p-6",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-5",children:[e.jsx("div",{className:"w-10 h-10 bg-sky-100 rounded-xl flex items-center justify-center",children:e.jsx(bs,{size:20,className:"text-sky-600"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-bold text-[#0a1628]",children:"Upload Module PDF"}),e.jsx("p",{className:"text-xs text-[#5a6578]",children:"Upload a DepEd teaching module PDF and trigger RAG ingestion"})]})]}),e.jsxs("div",{onDrop:Y,onDragOver:_,onDragLeave:ee,onClick:()=>!t&&q.current?.click(),className:` border-2 border-dashed rounded-xl p-8 text-center cursor-pointer transition-all mb-4 ${n?"border-sky-500 bg-sky-50":"border-[#dde3eb] hover:border-sky-400 hover:bg-sky-50/50"} ${t?"cursor-not-allowed opacity-60":""} - `,children:[e.jsx("input",{ref:q,type:"file",accept:".pdf",className:"hidden",onChange:x=>x.target.files?.[0]&&G(x.target.files[0])}),m?e.jsxs("div",{className:"flex items-center justify-center gap-3",children:[e.jsx(Ye,{size:24,className:"text-sky-600"}),e.jsxs("div",{className:"text-left",children:[e.jsx("p",{className:"font-semibold text-[#0a1628]",children:m.name}),e.jsxs("p",{className:"text-xs text-[#5a6578]",children:[(m.size/1024/1024).toFixed(2)," MB"]})]}),!t&&e.jsx("button",{onClick:x=>{x.stopPropagation(),v(null)},className:"ml-4 p-1.5 hover:bg-rose-50 rounded-lg text-rose-500","aria-label":"Remove file",children:e.jsx(Hs,{size:18})})]}):e.jsxs(e.Fragment,{children:[e.jsx(fs,{size:28,className:"mx-auto mb-2 text-[#dde3eb]"}),e.jsx("p",{className:"font-semibold text-[#0a1628]",children:"Drop PDF here or click to browse"}),e.jsx("p",{className:"text-xs text-[#5a6578] mt-1",children:"PDF files only, max 50MB"})]})]}),k>0&&e.jsxs("div",{className:"mb-4",children:[e.jsxs("div",{className:"flex justify-between text-xs text-[#5a6578] mb-1",children:[e.jsx("span",{children:t?"Uploading...":"Complete"}),e.jsxs("span",{children:[k,"%"]})]}),e.jsx("div",{className:"h-2 bg-[#edf1f7] rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-sky-500 rounded-full transition-all duration-300",style:{width:`${k}%`}})})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4 mb-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-[#5a6578] mb-1.5 block",children:"Subject"}),e.jsxs(re,{value:p,onValueChange:Q,disabled:t,children:[e.jsx(ie,{className:"w-full",children:e.jsx(le,{placeholder:"Select subject"})}),e.jsx(ne,{children:Xe.map(x=>e.jsxs(P,{value:x.id,children:[x.name," (",x.gradeLevel," — ",x.semester,")"]},x.id))})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-[#5a6578] mb-1.5 block",children:"Subject Name (display)"}),e.jsx(R,{value:f,onChange:x=>j(x.target.value),placeholder:"e.g. General Mathematics",disabled:t})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-[#5a6578] mb-1.5 block",children:"Semester"}),e.jsxs(re,{value:w,onValueChange:A,disabled:t,children:[e.jsx(ie,{className:"w-full",children:e.jsx(le,{})}),e.jsxs(ne,{children:[e.jsx(P,{value:"1",children:"Q1"}),e.jsx(P,{value:"2",children:"Q2"}),e.jsx(P,{value:"3",children:"Q3"}),e.jsx(P,{value:"4",children:"Q4"})]})]})]})]}),e.jsx(M,{onClick:oe,disabled:t||!m||!p||!f.trim(),className:"w-full gap-2 bg-sky-600 hover:bg-sky-700 text-white",children:t?e.jsxs(e.Fragment,{children:[e.jsx(_,{size:16,className:"animate-spin"})," Uploading & Indexing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(fs,{size:16})," Upload & Ingest"]})})]}),e.jsxs("div",{className:"bg-white rounded-2xl border border-[#dde3eb] shadow-sm overflow-hidden",children:[e.jsxs("div",{className:"p-6 border-b border-[#dde3eb] 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-teal-100 rounded-xl flex items-center justify-center",children:e.jsx(es,{size:20,className:"text-teal-600"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-bold text-[#0a1628]",children:"RAG Index Status"}),e.jsx("p",{className:"text-xs text-[#5a6578]",children:C?"Loading...":`${y?.chunkCount??0} total chunks across ${V.length} subjects`})]})]}),e.jsxs(M,{variant:"outline",size:"sm",className:"gap-2",onClick:O,disabled:C,children:[e.jsx(Ie,{size:14,className:C?"animate-spin":""}),"Refresh"]})]}),C?e.jsx("div",{className:"flex items-center justify-center h-32",children:e.jsx(_,{size:20,className:"animate-spin text-sky-500"})}):V.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 gap-2",children:[e.jsx(me,{size:24,className:"text-[#dde3eb]"}),e.jsx("p",{className:"text-sm text-[#5a6578]",children:"No PDFs indexed yet"})]}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-left",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-[#edf1f7] border-b border-[#dde3eb]",children:[e.jsx("th",{className:"p-4 text-xs font-bold text-[#5a6578] uppercase tracking-wider",children:"Subject"}),e.jsx("th",{className:"p-4 text-xs font-bold text-[#5a6578] uppercase tracking-wider",children:"Chunks"}),e.jsx("th",{className:"p-4 text-xs font-bold text-[#5a6578] uppercase tracking-wider",children:"Status"}),e.jsx("th",{className:"p-4 text-xs font-bold text-[#5a6578] uppercase tracking-wider text-right",children:"Actions"})]})}),e.jsx("tbody",{className:"divide-y divide-[#dde3eb]",children:V.map(x=>e.jsxs("tr",{className:"hover:bg-[#f8fafc] transition-colors",children:[e.jsx("td",{className:"p-4",children:e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(Ye,{size:16,className:"text-[#5a6578]"}),e.jsx("span",{className:"font-semibold text-sm text-[#0a1628]",children:x.name})]})}),e.jsx("td",{className:"p-4",children:e.jsx("span",{className:"text-sm font-bold text-[#0a1628]",children:x.chunks})}),e.jsx("td",{className:"p-4",children:e.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-1 rounded-full text-xs font-bold border ${x.status==="active"?"bg-green-50 text-green-700 border-green-200":x.status==="locked"?"bg-amber-50 text-amber-700 border-amber-200":"bg-rose-50 text-rose-700 border-rose-200"}`,children:[x.status==="active"?e.jsx(ss,{size:12}):e.jsx(Hs,{size:12}),x.status.charAt(0).toUpperCase()+x.status.slice(1)]})}),e.jsx("td",{className:"p-4 text-right",children:e.jsxs(M,{variant:"outline",size:"sm",className:"gap-1.5 text-xs",onClick:()=>b(x.name.toLowerCase().replace(/\s+/g,"-").replace("&",""),x.storagePath),disabled:r===x.name.toLowerCase().replace(/\s+/g,"-").replace("&",""),children:[r===x.name.toLowerCase().replace(/\s+/g,"-").replace("&","")?e.jsx(_,{size:12,className:"animate-spin"}):e.jsx(Ie,{size:12}),"Re-ingest"]})})]},x.name))})]})}),y?.lastIngested&&e.jsx("div",{className:"p-4 border-t border-[#dde3eb] bg-[#f8fafc]",children:e.jsxs("p",{className:"text-xs text-[#5a6578]",children:["Last ingestion: ",new Date(y.lastIngested).toLocaleString()]})})]})]})};function Ka(s){return s?s.charAt(0).toUpperCase()+s.slice(1):"Student"}function At(s){if(!s||!s.toDate)return new Date().toISOString().replace("T"," ").slice(0,19);const t=s.toDate();return`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,"0")}-${String(t.getDate()).padStart(2,"0")} ${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}:${String(t.getSeconds()).padStart(2,"0")}`}function Ja(){return At({toDate:()=>new Date})}function Za(s){if(!s)return"Never";const t=new Date(s);if(Number.isNaN(t.getTime()))return s;const r=Date.now()-t.getTime(),h=Math.floor(r/6e4);if(h<1)return"Just now";if(h<60)return`${h} minute${h!==1?"s":""} ago`;const n=Math.floor(h/60);if(n<24)return`${n} hour${n!==1?"s":""} ago`;const o=Math.floor(n/24);return o<7?`${o} day${o!==1?"s":""} ago`:t.toLocaleDateString()}function Ya(s){const t=(s.grade||"").trim(),l=(s.section||"").trim(),r=[t,l].filter(Boolean).join(" - ");return{id:s.uid,name:s.name||"Unknown",email:s.email||"",role:Ka(s.role||""),status:s.status||"Active",department:s.department||(s.role?.toLowerCase()==="student"?r||"Student":""),grade:t,section:l,classSectionId:s.classSectionId||void 0,classSection:r,lrn:(s.lrn||"").trim(),photo:(s.photo||"").trim(),lastLogin:Za(s.lastLogin),createdAt:s.createdAt||void 0}}function is(s){if(s instanceof ct){try{const t=JSON.parse(s.responseBody);if(t?.detail&&typeof t.detail=="string")return t.detail}catch{}return`Request failed (${s.status}).`}return s instanceof Error?s.message:"Request failed."}async function er(s={}){try{const t=await ye.getAdminUsers({page:s.page??1,pageSize:s.pageSize??25,search:s.searchQuery,role:s.roleFilter,status:s.statusFilter,grade:s.gradeFilter,section:s.sectionFilter,classSectionId:s.classSectionId});if(!t.success)throw new Error("Failed to load admin users");return{users:(t.users||[]).map(Ya),page:t.page,pageSize:t.pageSize,total:t.total,totalPages:t.totalPages,hasNextPage:t.hasNextPage}}catch(t){throw console.error("[adminService] getAdminUsersPage error:",t),t instanceof Yt?new Error("Loading users timed out. Please refresh and try again."):t instanceof ea?new Error("Unable to reach the server. Please check your connection and retry."):t instanceof ct&&t.status===504?new Error("Loading users took too long. Try narrowing your filters and retrying."):new Error(is(t))}}async function sr(s,t){try{await ye.updateAdminUser(s,{...t.name!==void 0?{name:t.name}:{},...t.role!==void 0?{role:t.role}:{},...t.status!==void 0?{status:t.status}:{},...t.department!==void 0?{department:t.department}:{},...t.grade!==void 0?{grade:t.grade}:{},...t.section!==void 0?{section:t.section}:{},...t.lrn!==void 0?{lrn:t.lrn}:{}})}catch(l){throw new Error(is(l))}}async function tr(s){try{const t=await ye.createAdminUser({name:s.name.trim(),email:s.email.trim().toLowerCase(),password:s.password,confirmPassword:s.confirmPassword,role:s.role,status:s.status,grade:s.grade.trim(),section:s.section.trim(),...s.lrn?.trim()?{lrn:s.lrn.trim()}:{}});if(!t.success||!t.userCreated||!t.uid)throw new Error(t.message||"Failed to create user account.");return{uid:t.uid,userCreated:t.userCreated,emailSent:t.emailSent,resultCode:t.resultCode,message:t.message,warnings:t.warnings??[],emailError:t.emailError}}catch(t){throw new Error(is(t))}}async function ar(s){try{const t=await ye.bulkAdminUsers({action:s.action,userIds:s.userIds??[],excludeUserIds:s.excludeUserIds??[],filters:s.filters,role:s.role,status:s.status,grade:s.grade,section:s.section,lrn:s.lrn,dryRun:s.dryRun,exportFormat:s.exportFormat??"csv"});return{success:t.success,action:t.action,summary:t.summary,results:t.results,warnings:t.warnings||[],exportRows:t.export?.rows||[]}}catch(t){throw new Error(is(t))}}async function zt(){try{if(!Zt.currentUser)return[];const s=ts(se(X,"accessAuditLogs"),vt("timestamp","desc"),ys(100));return(await de(s)).docs.map(l=>{const r=l.data(),n=r.success!==!1?"Info":"Error",o=r.action||"";let m="System";return r.module==="admin"||o.startsWith("admin_")?m="User":o.includes("login")||o.includes("auth")?m="Auth":(o.includes("upload")||o.includes("course"))&&(m="Content"),{id:l.id,severity:n,timestamp:typeof r.timestamp=="string"?r.timestamp:At(r.timestamp),user:{name:r.actorName||r.teacherEmail||"System",role:r.actorRole||r.role||"Admin",avatar:null},action:o,category:m,details:r.description||(r.status?`Status: ${r.status}`:"")}})}catch(s){const t=s;return t?.code==="permission-denied"||t?.code==="firestore/permission-denied"?[]:(console.error("[adminService] getAuditLogs error:",s),[])}}async function bs(s,t,l,r,h){await xa(se(X,"auditLogs"),{severity:l,timestamp:Ja(),timestampRaw:Nt(),user:h,action:s,category:t,details:r})}async function rr(){try{const s=await de(se(X,"users"));let t=0,l=0,r=0;s.docs.forEach(m=>{const v=m.data();v.role==="student"&&(t++,v.overallRisk==="High"&&r++),v.role==="teacher"&&v.status!=="Inactive"&&l++});let h=0;try{h=(await de(se(X,"classrooms"))).size}catch{}let n=0;try{n=(await de(se(X,"xpActivities"))).size}catch{}let o=0;try{const m=await de(se(X,"progress")),v=[];m.docs.forEach(p=>{const S=p.data();typeof S.averageScore=="number"&&v.push(S.averageScore)}),o=v.length>0?Math.round(v.reduce((p,S)=>p+S,0)/v.length):0}catch{}return{totalStudents:t,activeTeachers:l,totalClasses:h,atRiskStudents:r,avgPerformance:o,aiPredictions:n}}catch(s){return console.error("[adminService] getDashboardStats error:",s),{totalStudents:0,activeTeachers:0,totalClasses:0,atRiskStudents:0,avgPerformance:0,aiPredictions:0}}}async function ir(s=3){const t=r=>{const h=r.data(),n=h.level||1,o=h.currentXP||0,m=Math.min(100,n*8+Math.round(o/100));return{id:r.id,name:h.name||"Student",avatar:h.photo||h.photoURL||`https://ui-avatars.com/api/?name=${encodeURIComponent(h.name||"S")}&background=0d9488&color=fff`,class:h.grade||"Math",performance:m,level:n}},l=r=>r.sort((h,n)=>n.level!==h.level?n.level-h.level:n.performance-h.performance).slice(0,s);try{const r=ts(se(X,"users"),ws("role","==","student"),vt("level","desc"),ys(s)),h=await de(r);return l(h.docs.map(t))}catch(r){if(r?.code==="failed-precondition")try{const n=ts(se(X,"users"),ws("role","==","student"),ys(Math.max(50,s))),o=await de(n);return l(o.docs.map(t))}catch(n){return console.error("[adminService] getTopPerformers fallback error:",n),[]}return console.error("[adminService] getTopPerformers error:",r),[]}}async function lr(){try{const s=await de(se(X,"users"));let t=0,l=0,r=0,h=0,n=0;s.docs.forEach(v=>{const p=v.data();p.role==="student"&&(t++,p.overallRisk==="High"&&r++,p.streak>0&&n++,h+=p.totalXP||0),p.role==="teacher"&&l++});let o=0;try{o=(await de(se(X,"achievements"))).size}catch{}let m=0;try{m=(await de(se(X,"chatSessions"))).size}catch{}return{totalActiveUsers:t+l,totalStudents:t,totalTeachers:l,atRiskStudents:r,achievementsUnlocked:o,totalXPEarned:h,activeStreaks:n,aiTutorSessions:m}}catch(s){return console.error("[adminService] getAnalyticsSummary error:",s),{totalActiveUsers:0,totalStudents:0,totalTeachers:0,atRiskStudents:0,achievementsUnlocked:0,totalXPEarned:0,activeStreaks:0,aiTutorSessions:0}}}const nr=()=>{const{userProfile:s,loading:t}=Re(),[l,r]=i.useState([]),[h,n]=i.useState(!0),[o,m]=i.useState(!1),[v,p]=i.useState(""),[S,f]=i.useState("All Categories"),[j,w]=i.useState("All Severity"),[A,k]=i.useState("All Roles"),[d,y]=i.useState(25),[L,C]=i.useState(null),B=i.useCallback(async()=>{if(t||!s)return;const b=String(s.role||"").toLowerCase();if(b!=="admin"&&b!=="teacher"){n(!1),m(!0);return}m(!1),n(!0);try{const V=await zt();r(V)}catch{z.error("Failed to load audit logs")}finally{n(!1)}},[t,s]);i.useEffect(()=>{B()},[B]),i.useEffect(()=>{y(25)},[v,S,j,A,l.length]);const q=l.filter(b=>b.severity==="Info").length,O=l.filter(b=>b.severity==="Warning").length,G=l.filter(b=>b.severity==="Error"||b.severity==="Critical").length,Y=b=>{switch(b){case"Info":return e.jsx(we,{size:16,className:"text-sky-600"});case"Warning":return e.jsx(me,{size:16,className:"text-rose-600"});case"Error":return e.jsx(Se,{size:16,className:"text-red-600"});case"Critical":return e.jsx(Se,{size:16,className:"text-red-600"});default:return e.jsx(we,{size:16,className:"text-[#5a6578]"})}},H=b=>{switch(b){case"Info":return"bg-sky-100 text-sky-700 border-sky-200";case"Warning":return"bg-rose-100 text-rose-700 border-rose-200";case"Error":return"bg-red-100 text-red-700 border-red-200";case"Critical":return"bg-red-100 text-red-700 border-red-200 ring-2 ring-red-500";default:return"bg-[#edf1f7] text-[#0a1628] border-[#dde3eb]"}},ee=b=>{switch(b){case"Auth":return"bg-sky-100 text-sky-700";case"Data":return"bg-rose-100 text-rose-700";case"User":return"bg-sky-100 text-sky-700";case"System":return"bg-[#edf1f7] text-[#0a1628]";case"Content":return"bg-green-100 text-green-700";default:return"bg-[#edf1f7] text-[#0a1628]"}},Q=l.filter(b=>{const V=b.action.toLowerCase().includes(v.toLowerCase())||b.details.toLowerCase().includes(v.toLowerCase())||b.user.name.toLowerCase().includes(v.toLowerCase()),x=S==="All Categories"||b.category===S,E=j==="All Severity"||b.severity===j,c=A==="All Roles"||b.user.role===A;return V&&x&&E&&c}),oe=Q.slice(0,d);return e.jsxs(U.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("h2",{className:"text-lg font-bold text-[#0a1628]",children:"Audit Log"}),e.jsx("p",{className:"text-sm text-[#5a6578]",children:"System activity monitoring and security events"})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-start sm:items-center gap-3",children:[e.jsxs("div",{className:"bg-white px-3 py-2 rounded-xl border border-[#dde3eb] flex items-center gap-2 text-[#5a6578] text-sm font-medium",children:[e.jsx(Ns,{size:16}),e.jsx("span",{children:"Last 100 events"})]}),e.jsxs(M,{variant:"outline",className:"gap-2 border-[#dde3eb] hover:bg-[#edf1f7]",onClick:B,children:[e.jsx(Ie,{size:16}),"Refresh"]}),e.jsx(M,{variant:"outline",disabled:!0,title:"Audit log export is not implemented yet",className:"gap-2 border-[#dde3eb] opacity-60 cursor-not-allowed",children:"Export (Unavailable)"})]}),h?e.jsx("div",{className:"flex items-center justify-center h-24",children:e.jsx(_,{size:24,className:"animate-spin text-sky-500"})}):o?e.jsxs("div",{className:"flex flex-col items-center justify-center h-24 text-center",children:[e.jsx(ot,{size:24,className:"text-[#a0aec0] mb-2"}),e.jsx("p",{className:"text-sm font-medium text-[#5a6578]",children:"Audit logs are available only to teachers and admins."})]}):null,!o&&!h&&e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"bg-white p-4 rounded-xl border border-[#dde3eb] shadow-sm",children:[e.jsx("p",{className:"text-xs font-bold text-[#5a6578] mb-1",children:"Total Events"}),e.jsx("p",{className:"text-2xl font-bold text-[#0a1628]",children:l.length})]}),e.jsxs("div",{className:"bg-white p-4 rounded-xl border border-sky-200 shadow-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(we,{size:14,className:"text-sky-600"}),e.jsx("p",{className:"text-xs font-bold text-[#5a6578]",children:"Info"})]}),e.jsx("p",{className:"text-2xl font-bold text-sky-600",children:q})]}),e.jsxs("div",{className:"bg-white p-4 rounded-xl border border-rose-200 shadow-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(me,{size:14,className:"text-rose-600"}),e.jsx("p",{className:"text-xs font-bold text-[#5a6578]",children:"Warnings"})]}),e.jsx("p",{className:"text-2xl font-bold text-rose-600",children:O})]}),e.jsxs("div",{className:"bg-white p-4 rounded-xl border border-red-200 shadow-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(Se,{size:14,className:"text-red-600"}),e.jsx("p",{className:"text-xs font-bold text-[#5a6578]",children:"Errors"})]}),e.jsx("p",{className:"text-2xl font-bold text-red-600",children:G})]})]}),!o&&e.jsxs("div",{className:"bg-white p-4 rounded-xl border border-[#dde3eb] shadow-sm space-y-4",children:[e.jsxs("div",{className:"relative",children:[e.jsx(wt,{className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-500",size:18}),e.jsx(R,{type:"text",placeholder:"Search by user, action, or details...",className:"pl-10 bg-[#edf1f7] border-[#dde3eb]",value:v,onChange:b=>p(b.target.value)})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-start sm:items-center gap-3",children:[e.jsxs(re,{value:S,onValueChange:f,children:[e.jsx(ie,{className:"w-full sm:w-[170px]",children:e.jsx(le,{placeholder:"All Categories"})}),e.jsxs(ne,{children:[e.jsx(P,{value:"All Categories",children:"All Categories"}),e.jsx(P,{value:"Auth",children:"Auth"}),e.jsx(P,{value:"Data",children:"Data"}),e.jsx(P,{value:"User",children:"User"}),e.jsx(P,{value:"System",children:"System"}),e.jsx(P,{value:"Content",children:"Content"})]})]}),e.jsxs(re,{value:j,onValueChange:w,children:[e.jsx(ie,{className:"w-full sm:w-[170px]",children:e.jsx(le,{placeholder:"All Severity"})}),e.jsxs(ne,{children:[e.jsx(P,{value:"All Severity",children:"All Severity"}),e.jsx(P,{value:"Info",children:"Info"}),e.jsx(P,{value:"Warning",children:"Warning"}),e.jsx(P,{value:"Error",children:"Error"}),e.jsx(P,{value:"Critical",children:"Critical"})]})]}),e.jsxs(re,{value:A,onValueChange:k,children:[e.jsx(ie,{className:"w-full sm:w-[170px]",children:e.jsx(le,{placeholder:"All Roles"})}),e.jsxs(ne,{children:[e.jsx(P,{value:"All Roles",children:"All Roles"}),e.jsx(P,{value:"Admin",children:"Admin"}),e.jsx(P,{value:"Teacher",children:"Teacher"}),e.jsx(P,{value:"Student",children:"Student"})]})]})]})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-[#dde3eb] shadow-sm overflow-hidden",children:[e.jsx("div",{className:"md:hidden divide-y divide-[#dde3eb]",children:oe.map(b=>e.jsxs("div",{className:"p-4 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:`inline-flex items-center gap-2 px-3 py-1 rounded-full text-xs font-bold border ${H(b.severity)}`,children:[Y(b.severity),b.severity]}),e.jsx("button",{type:"button",onClick:()=>C(b),className:"p-2 hover:bg-[#dde3eb] rounded-lg text-slate-500 hover:text-sky-600 transition-colors","aria-label":`View audit event ${b.action}`,children:e.jsx(as,{size:16})})]}),e.jsx("p",{className:"text-sm font-semibold text-[#0a1628]",children:b.action}),e.jsx("p",{className:"text-xs text-[#5a6578]",children:b.timestamp}),e.jsxs("p",{className:"text-xs text-[#5a6578]",children:[b.user.name," (",b.user.role,")"]}),e.jsx("p",{className:"text-xs text-[#5a6578]",children:b.details})]},`mobile-${b.id}`))}),e.jsx("div",{className:"hidden md:block overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[980px] text-left border-collapse",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-[#edf1f7] border-b border-[#dde3eb]",children:[e.jsx("th",{className:"p-4 text-xs font-bold text-[#5a6578] uppercase tracking-wider",children:"Severity"}),e.jsx("th",{className:"p-4 text-xs font-bold text-[#5a6578] uppercase tracking-wider",children:"Timestamp"}),e.jsx("th",{className:"p-4 text-xs font-bold text-[#5a6578] uppercase tracking-wider",children:"User"}),e.jsx("th",{className:"p-4 text-xs font-bold text-[#5a6578] uppercase tracking-wider",children:"Action"}),e.jsx("th",{className:"p-4 text-xs font-bold text-[#5a6578] uppercase tracking-wider",children:"Category"}),e.jsx("th",{className:"p-4 text-xs font-bold text-[#5a6578] uppercase tracking-wider",children:"Details"}),e.jsx("th",{className:"p-4 text-xs font-bold text-[#5a6578] uppercase tracking-wider text-right",children:"View"})]})}),e.jsx("tbody",{className:"divide-y divide-[#dde3eb]",children:oe.map(b=>e.jsxs("tr",{className:"hover:bg-[#edf1f7] transition-colors",children:[e.jsx("td",{className:"p-4",children:e.jsxs("div",{className:`inline-flex items-center gap-2 px-3 py-1 rounded-full text-xs font-bold border ${H(b.severity)}`,children:[Y(b.severity),b.severity]})}),e.jsx("td",{className:"p-4",children:e.jsxs("div",{className:"flex items-center gap-2 text-[#5a6578] text-sm",children:[e.jsx("div",{className:"p-1 bg-[#edf1f7] rounded",children:e.jsx(Ns,{size:12})}),b.timestamp]})}),e.jsx("td",{className:"p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[b.user.avatar?e.jsx("img",{src:b.user.avatar,alt:b.user.name,className:"w-8 h-8 rounded-full object-cover"}):e.jsx("div",{className:"w-8 h-8 bg-sky-100 rounded-full flex items-center justify-center",children:e.jsx(Ke,{size:16,className:"text-sky-600"})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-bold text-[#0a1628] text-sm",children:b.user.name}),e.jsx("p",{className:"text-xs text-[#5a6578]",children:b.user.role})]})]})}),e.jsx("td",{className:"p-4",children:e.jsx("p",{className:"font-medium text-[#0a1628] text-sm",children:b.action})}),e.jsx("td",{className:"p-4",children:e.jsx("span",{className:`px-2 py-1 rounded text-xs font-bold ${ee(b.category)}`,children:b.category})}),e.jsx("td",{className:"p-4 text-sm text-[#5a6578] max-w-xs truncate",title:b.details,children:b.details}),e.jsx("td",{className:"p-4 text-right",children:e.jsx("button",{type:"button",onClick:()=>C(b),className:"p-2 hover:bg-[#dde3eb] rounded-lg text-slate-500 hover:text-sky-600 transition-colors","aria-label":`View audit event ${b.action}`,children:e.jsx(as,{size:16})})})]},b.id))})]})}),Q.length>d?e.jsx("div",{className:"border-t border-[#dde3eb] p-4 flex justify-center",children:e.jsx(M,{variant:"outline",className:"border-[#dde3eb]",onClick:()=>y(b=>b+25),children:"Load more events"})}):null,Q.length===0&&!h&&e.jsxs("div",{className:"p-12 text-center text-[#5a6578]",children:[e.jsx(Ke,{size:48,className:"mx-auto mb-4 text-slate-500"}),e.jsx("p",{className:"font-medium",children:"No logs found"}),e.jsx("p",{className:"text-sm",children:l.length===0?"Audit events will appear here as actions are performed":"Try adjusting your search or filters"})]})]}),e.jsx(gt,{open:!!L,onOpenChange:b=>{b||C(null)},children:e.jsxs(pt,{children:[e.jsxs(ft,{children:[e.jsx(bt,{children:L?.action||"Audit Event Details"}),e.jsx(jt,{children:"Detailed audit information for operational review."})]}),L?e.jsxs("div",{className:"space-y-2 text-sm",children:[e.jsxs("p",{children:[e.jsx("span",{className:"font-semibold text-[#0a1628]",children:"Severity:"})," ",L.severity]}),e.jsxs("p",{children:[e.jsx("span",{className:"font-semibold text-[#0a1628]",children:"Category:"})," ",L.category]}),e.jsxs("p",{children:[e.jsx("span",{className:"font-semibold text-[#0a1628]",children:"Timestamp:"})," ",L.timestamp]}),e.jsxs("p",{children:[e.jsx("span",{className:"font-semibold text-[#0a1628]",children:"User:"})," ",L.user.name," (",L.user.role,")"]}),e.jsxs("p",{children:[e.jsx("span",{className:"font-semibold text-[#0a1628]",children:"Details:"})," ",L.details]})]}):null]})})]})},rs="—";function ve(s,t=rs){return s==null?t:String(s)}function dr(s){return s?s instanceof Date?s.toLocaleString():typeof s.toDate=="function"?s.toDate().toLocaleString():rs:rs}function ke({label:s,value:t,accent:l}){return e.jsxs("div",{className:`rounded-xl border p-4 ${l?"bg-sky-50 border-sky-200":"bg-white border-[#dde3eb]"}`,children:[e.jsx("p",{className:"text-xs font-medium text-[#5a6578] uppercase tracking-wide mb-1",children:s}),e.jsx("p",{className:`text-base font-semibold ${t===rs?"text-slate-400":"text-[#0a1628]"}`,children:t})]})}function cr(){const[s,t]=i.useState(null),[l,r]=i.useState(!0),[h,n]=i.useState(null);return i.useEffect(()=>{(async()=>{r(!0),n(null);try{const m=Cs(X,"settings","modelConfig"),v=await yt(m);v.exists()?t(v.data()):t({})}catch(m){n(m.message??"Failed to load model configuration")}finally{r(!1)}})()},[]),l?e.jsx("div",{className:"space-y-4",children:e.jsx("p",{className:"text-sm text-[#5a6578]",children:"Loading model configuration..."})}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-start gap-2 p-3 bg-blue-50 border border-blue-200 rounded-xl text-blue-800",children:[e.jsx(we,{size:16,className:"mt-0.5 flex-shrink-0"}),e.jsx("p",{className:"text-xs leading-relaxed",children:"This configuration is managed by the system and cannot be edited here."})]}),h&&e.jsxs("p",{className:"text-sm text-red-600",children:["Error: ",h]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4",children:[e.jsx(ke,{label:"Active Model Name",value:ve(s?.activeModelName)}),e.jsx(ke,{label:"Provider / Endpoint",value:s?.endpoint?`${ve(s?.provider)} — ${s.endpoint}`:ve(s?.provider)}),e.jsx(ke,{label:"Max Tokens",value:ve(s?.maxTokens)}),e.jsx(ke,{label:"Temperature",value:ve(s?.temperature)}),e.jsx(ke,{label:"Context Window",value:ve(s?.contextWindow)}),e.jsx(ke,{label:"Fine-tune Status",value:ve(s?.fineTuneStatus),accent:!0})]}),e.jsx("div",{className:"pt-4 border-t border-[#dde3eb]",children:e.jsxs("p",{className:"text-xs text-[#5a6578]",children:["Last updated:"," ",e.jsx("span",{className:"font-medium text-[#0a1628]",children:dr(s?.lastUpdated)})]})})]})}const Pt="settings",Ks="general",Js="notifications",Zs="gamification",Ys="content",et={platformName:"MathPulse AI",institutionName:"",logoUrl:"",maintenanceMode:!1},st={emailAlertsOnRegistration:!1,alertOnQuizCompletionThreshold:!1,quizCompletionThresholdPercent:80,announcementBannerEnabled:!1,announcementBannerMessage:""},tt={xpPerCorrectAnswer:10,xpPerQuizCompletion:50,streakBonusMultiplier:1,leaderboardVisibility:!0},at={defaultQuizTimeLimitMinutes:30,maxQuestionsPerQuiz:20,allowStudentRetries:!0,difficultyAutoAdjustment:!1};async function Oe(s,t){try{const l=Cs(X,Pt,s),r=await yt(l);return r.exists()?{...t,...r.data()}:t}catch(l){return console.error(`[settings] Failed to load ${s}:`,l),t}}async function Ge(s,t){await ua(Cs(X,Pt,s),{...t,updatedAt:Nt()},{merge:!0})}const or=[{id:"General",label:"General",icon:St},{id:"Notifications",label:"Notifications",icon:pa},{id:"Gamification",label:"Gamification",icon:Fa},{id:"Content",label:"Content",icon:Ye},{id:"Model Config",label:"Model Configuration",icon:mt}],mr=({onDirtyChange:s})=>{const{userProfile:t}=Re(),[l,r]=i.useState("General"),[h,n]=i.useState(et),[o,m]=i.useState(st),[v,p]=i.useState(tt),[S,f]=i.useState(at),[j,w]=i.useState(!1),[A,k]=i.useState(!1),[d,y]=i.useState(!1),[L,C]=i.useState(!1),[B,q]=i.useState(!1),[O,G]=i.useState(!1),[Y,H]=i.useState(!1),[ee,Q]=i.useState(!1);i.useEffect(()=>{t?.uid&&(w(!0),k(!0),y(!0),C(!0),Promise.all([Oe(Ks,et),Oe(Js,st),Oe(Zs,tt),Oe(Ys,at)]).then(([c,u,$,te])=>{n(c),m(u),p($),f(te)}).catch(c=>{console.error("[AdminSettings] Failed to load settings:",c),z.error("Failed to load admin settings")}).finally(()=>{w(!1),k(!1),y(!1),C(!1)}))},[t?.uid]);const oe=async()=>{q(!0);try{await Ge(Ks,h),z.success("General settings saved")}catch(c){console.error("[AdminSettings] Failed to save general:",c),z.error("Failed to save general settings")}finally{q(!1)}},b=async()=>{G(!0);try{await Ge(Js,o),z.success("Notification settings saved")}catch(c){console.error("[AdminSettings] Failed to save notifications:",c),z.error("Failed to save notification settings")}finally{G(!1)}},V=async()=>{H(!0);try{await Ge(Zs,v),z.success("Gamification settings saved")}catch(c){console.error("[AdminSettings] Failed to save gamification:",c),z.error("Failed to save gamification settings")}finally{H(!1)}},x=async()=>{Q(!0);try{await Ge(Ys,S),z.success("Content settings saved")}catch(c){console.error("[AdminSettings] Failed to save content:",c),z.error("Failed to save content settings")}finally{Q(!1)}},E=j||A||d||L;return e.jsx(U.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:"space-y-6",children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-12 gap-4 md:gap-6",children:[e.jsx("div",{className:"md:col-span-3",children:e.jsx("div",{className:"bg-white rounded-xl shadow-sm border border-[#dde3eb] overflow-hidden",children:e.jsx("nav",{className:"grid grid-cols-2 sm:grid-cols-3 md:flex md:flex-col py-2",children:or.map(c=>{const u=c.icon,$=l===c.id;return e.jsxs("button",{onClick:()=>r(c.id),className:`flex items-center gap-3 px-4 py-3 text-sm font-medium transition-all relative ${$?"text-sky-600 bg-sky-50/50":"text-[#5a6578] hover:bg-[#edf1f7] hover:text-[#0a1628]"}`,children:[$&&e.jsx("div",{className:"absolute left-0 top-0 bottom-0 w-1 bg-sky-600 rounded-r-full"}),e.jsx(u,{size:18,className:$?"text-sky-600":"text-slate-500"}),c.label]},c.id)})})})}),e.jsx("div",{className:"md:col-span-9",children:e.jsx(U.div,{initial:{opacity:0},animate:{opacity:1},transition:{duration:.2},className:"space-y-6",children:e.jsx("div",{className:"bg-white rounded-xl shadow-sm border border-[#dde3eb] p-6",children:E?e.jsx("p",{className:"text-sm text-[#5a6578]",children:"Loading settings..."}):e.jsxs(e.Fragment,{children:[l==="General"&&e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-sm font-medium text-[#0a1628]",children:"Platform Name"}),e.jsx(R,{value:h.platformName,onChange:c=>n(u=>({...u,platformName:c.target.value})),className:"bg-white max-w-md"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-sm font-medium text-[#0a1628]",children:"School / Institution Name"}),e.jsx(R,{value:h.institutionName,onChange:c=>n(u=>({...u,institutionName:c.target.value})),placeholder:"Enter institution name",className:"bg-white max-w-md"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-sm font-medium text-[#0a1628]",children:"Logo URL"}),e.jsx(R,{value:h.logoUrl,onChange:c=>n(u=>({...u,logoUrl:c.target.value})),placeholder:"https://example.com/logo.png",className:"bg-white max-w-md"})]}),e.jsxs("div",{className:"mt-6 p-4 bg-red-50 border border-red-100 rounded-xl flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"p-2 bg-white rounded-lg text-red-600 shadow-sm border border-red-100",children:e.jsx(St,{size:18})}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-red-900",children:"Maintenance Mode"}),e.jsx("p",{className:"text-xs text-red-700 mt-0.5",children:"Temporarily disable access for non-admins"})]})]}),e.jsx(be,{checked:h.maintenanceMode,onCheckedChange:c=>n(u=>({...u,maintenanceMode:c})),className:"data-[state=checked]:bg-red-600 data-[state=unchecked]:bg-[#dde3eb]"})]}),e.jsx("div",{className:"pt-4 border-t border-[#dde3eb] flex justify-end",children:e.jsxs(M,{className:`bg-sky-600 hover:bg-sky-700 text-white gap-2 ${B?"opacity-70 cursor-not-allowed":""}`,onClick:oe,disabled:B,children:[B&&e.jsx(_,{size:16,className:"animate-spin"}),B?"Saving...":"Save Changes"]})})]}),l==="Notifications"&&e.jsxs("div",{className:"space-y-5",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]",children:"Email Alerts on New User Registrations"}),e.jsx("p",{className:"text-xs text-slate-500",children:"Send email notification when a new user signs up"})]}),e.jsx(be,{checked:o.emailAlertsOnRegistration,onCheckedChange:c=>m(u=>({...u,emailAlertsOnRegistration:c})),className:"data-[state=checked]:bg-sky-600 data-[state=unchecked]:bg-[#dde3eb]"})]}),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]",children:"Alert on Quiz Completion Threshold"}),e.jsx("p",{className:"text-xs text-slate-500",children:"Notify when a student's quiz score crosses a threshold"})]}),e.jsx(be,{checked:o.alertOnQuizCompletionThreshold,onCheckedChange:c=>m(u=>({...u,alertOnQuizCompletionThreshold:c})),className:"data-[state=checked]:bg-sky-600 data-[state=unchecked]:bg-[#dde3eb]"})]}),o.alertOnQuizCompletionThreshold&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-sm font-medium text-[#0a1628]",children:"Threshold Percentage (%)"}),e.jsx(R,{type:"number",min:0,max:100,value:o.quizCompletionThresholdPercent,onChange:c=>m(u=>({...u,quizCompletionThresholdPercent:Number(c.target.value||0)})),className:"max-w-xs bg-white"})]}),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]",children:"Announcement Banner"}),e.jsx("p",{className:"text-xs text-slate-500",children:"Show a platform-wide banner message"})]}),e.jsx(be,{checked:o.announcementBannerEnabled,onCheckedChange:c=>m(u=>({...u,announcementBannerEnabled:c})),className:"data-[state=checked]:bg-sky-600 data-[state=unchecked]:bg-[#dde3eb]"})]}),o.announcementBannerEnabled&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-sm font-medium text-[#0a1628]",children:"Banner Message"}),e.jsx(R,{value:o.announcementBannerMessage,onChange:c=>m(u=>({...u,announcementBannerMessage:c.target.value})),placeholder:"Enter banner message text",className:"bg-white"})]}),e.jsx("div",{className:"pt-4 border-t border-[#dde3eb] flex justify-end",children:e.jsxs(M,{className:`bg-sky-600 hover:bg-sky-700 text-white gap-2 ${O?"opacity-70 cursor-not-allowed":""}`,onClick:b,disabled:O,children:[O&&e.jsx(_,{size:16,className:"animate-spin"}),O?"Saving...":"Save Changes"]})})]}),l==="Gamification"&&e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-sm font-medium text-[#0a1628]",children:"XP Earned per Correct Answer"}),e.jsx(R,{type:"number",min:0,value:v.xpPerCorrectAnswer,onChange:c=>p(u=>({...u,xpPerCorrectAnswer:Number(c.target.value||0)})),className:"max-w-xs bg-white"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-sm font-medium text-[#0a1628]",children:"XP Earned per Quiz Completion"}),e.jsx(R,{type:"number",min:0,value:v.xpPerQuizCompletion,onChange:c=>p(u=>({...u,xpPerQuizCompletion:Number(c.target.value||0)})),className:"max-w-xs bg-white"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-sm font-medium text-[#0a1628]",children:"Streak Bonus Multiplier"}),e.jsx(R,{type:"number",min:0,step:.1,value:v.streakBonusMultiplier,onChange:c=>p(u=>({...u,streakBonusMultiplier:Number(c.target.value||0)})),className:"max-w-xs bg-white"}),e.jsx("p",{className:"text-xs text-slate-500 mt-1",children:"Applied as a multiplier to streak XP rewards."})]}),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]",children:"Leaderboard Visibility"}),e.jsx("p",{className:"text-xs text-slate-500",children:"Show the leaderboard to students"})]}),e.jsx(be,{checked:v.leaderboardVisibility,onCheckedChange:c=>p(u=>({...u,leaderboardVisibility:c})),className:"data-[state=checked]:bg-sky-600 data-[state=unchecked]:bg-[#dde3eb]"})]}),e.jsx("div",{className:"pt-4 border-t border-[#dde3eb] flex justify-end",children:e.jsxs(M,{className:`bg-sky-600 hover:bg-sky-700 text-white gap-2 ${Y?"opacity-70 cursor-not-allowed":""}`,onClick:V,disabled:Y,children:[Y&&e.jsx(_,{size:16,className:"animate-spin"}),Y?"Saving...":"Save Changes"]})})]}),l==="Content"&&e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-sm font-medium text-[#0a1628]",children:"Default Quiz Time Limit (minutes)"}),e.jsx(R,{type:"number",min:1,value:S.defaultQuizTimeLimitMinutes,onChange:c=>f(u=>({...u,defaultQuizTimeLimitMinutes:Number(c.target.value||1)})),className:"max-w-xs bg-white"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-sm font-medium text-[#0a1628]",children:"Max Questions Per Quiz"}),e.jsx(R,{type:"number",min:1,value:S.maxQuestionsPerQuiz,onChange:c=>f(u=>({...u,maxQuestionsPerQuiz:Number(c.target.value||1)})),className:"max-w-xs bg-white"})]}),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]",children:"Allow Student Retries"}),e.jsx("p",{className:"text-xs text-slate-500",children:"Let students retry quizzes"})]}),e.jsx(be,{checked:S.allowStudentRetries,onCheckedChange:c=>f(u=>({...u,allowStudentRetries:c})),className:"data-[state=checked]:bg-sky-600 data-[state=unchecked]:bg-[#dde3eb]"})]}),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]",children:"Difficulty Auto-Adjustment"}),e.jsx("p",{className:"text-xs text-slate-500",children:"Automatically adjust quiz difficulty based on performance"})]}),e.jsx(be,{checked:S.difficultyAutoAdjustment,onCheckedChange:c=>f(u=>({...u,difficultyAutoAdjustment:c})),className:"data-[state=checked]:bg-sky-600 data-[state=unchecked]:bg-[#dde3eb]"})]}),e.jsx("div",{className:"pt-4 border-t border-[#dde3eb] flex justify-end",children:e.jsxs(M,{className:`bg-sky-600 hover:bg-sky-700 text-white gap-2 ${ee?"opacity-70 cursor-not-allowed":""}`,onClick:x,disabled:ee,children:[ee&&e.jsx(_,{size:16,className:"animate-spin"}),ee?"Saving...":"Save Changes"]})})]}),l==="Model Config"&&e.jsx(cr,{})]})})})})]})})};function He({className:s,...t}){return e.jsx(fa,{"data-slot":"checkbox",className:sa("peer border bg-input-background dark:bg-input/30 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=checked]:border-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive size-4 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",s),...t,children:e.jsx(ba,{"data-slot":"checkbox-indicator",className:"flex items-center justify-center text-current transition-none",children:e.jsx(ja,{className:"size-3.5"})})})}const xr=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,ur=/[A-Z]/,hr=/[a-z]/,gr=/\d/,pr=/[^A-Za-z0-9]/;function fr(s){const t={};s.name.trim()||(t.name="Name is required.");const l=s.email.trim().toLowerCase();l?xr.test(l)||(t.email="Enter a valid email address."):t.email="Email is required.";const r=s.password;return r.length<8?t.password="Password must be at least 8 characters.":ur.test(r)?hr.test(r)?gr.test(r)?pr.test(r)||(t.password="Password must include at least one special character."):t.password="Password must include at least one number.":t.password="Password must include at least one lowercase letter.":t.password="Password must include at least one uppercase letter.",s.confirmPassword?s.confirmPassword!==r&&(t.confirmPassword="Passwords do not match."):t.confirmPassword="Confirm password is required.",s.role.trim()||(t.role="Role is required."),s.status.trim()||(t.status="Status is required."),s.grade.trim()||(t.grade="Grade is required."),s.section.trim()||(t.section="Section is required."),s.role.trim().toLowerCase()==="student"&&!s.lrn.trim()&&(t.lrn="LRN is required for student accounts."),t}function br(s){return Object.values(s).find(l=>!!l)??null}const rt=(s="Student")=>({name:"",email:"",password:"",confirmPassword:"",role:s,status:"Active",department:s==="Teacher"?"Mathematics":s==="Admin"?"System":"",grade:"Grade 11",section:"Section A",lrn:""}),jr=["10","25","50","100"];function it(s,t){const l=s.trim();if(!(!l||l===t))return l}function lt(s){const t=String(s??"");return/[",\n]/.test(t)?`"${t.replace(/"/g,'""')}"`:t}const vr=({createIntentRole:s=null,onCreateIntentConsumed:t})=>{const{userProfile:l}=Re(),[r,h]=i.useState([]),[n,o]=i.useState(!0),[m,v]=i.useState(null),[p,S]=i.useState(!1),[f,j]=i.useState(!1),[w,A]=i.useState(null),[k,d]=i.useState(1),[y,L]=i.useState(25),[C,B]=i.useState(0),[q,O]=i.useState(1),[G,Y]=i.useState(!1),[H,ee]=i.useState(""),[Q,oe]=i.useState("All Roles"),[b,V]=i.useState("All Status"),[x,E]=i.useState(new Set),[c,u]=i.useState(!1),[$,te]=i.useState(new Set),[Ee,ls]=i.useState({}),[Ce,Dt]=i.useState("Student"),[ns,Tt]=i.useState("Active"),[ds,Lt]=i.useState("Grade 11"),[cs,Mt]=i.useState("Section A"),[It,Ae]=i.useState(!1),[Rt,os]=i.useState(!1),[Ue,As]=i.useState(!1),[xe,ms]=i.useState(null),[J,zs]=i.useState(null),[D,ae]=i.useState({}),[xs,ze]=i.useState(!1),[us,Pe]=i.useState(!1),[N,K]=i.useState(rt()),F=i.useMemo(()=>({search:H.trim()||void 0,role:it(Q,"All Roles"),status:it(b,"All Status")}),[H,Q,b]),ge=i.useCallback(()=>{E(new Set),u(!1),te(new Set)},[]),$e=i.useCallback(a=>c?!$.has(a):x.has(a),[c,$,x]),W=i.useMemo(()=>c?Math.max(C-$.size,0):x.size,[c,$,x,C]),Ps=i.useMemo(()=>r.length===0?!1:r.every(a=>$e(a.id)),[r,$e]),ue=i.useMemo(()=>c?[]:Array.from(x).map(a=>Ee[a]).filter(a=>!!a),[c,x,Ee]),Ds=i.useMemo(()=>W===0?!1:c?!F.role||F.role.toLowerCase()==="student":ue.length!==x.size?!1:ue.every(a=>a.role==="Student"),[c,W,ue,x.size,F.role]),Ts=i.useMemo(()=>W===0?!1:c?F.status?.toLowerCase()!=="active":ue.length!==x.size?!1:ue.some(a=>a.status!=="Active"),[c,W,ue,x.size,F.status]),Ls=i.useMemo(()=>W===0?!1:c?F.status?.toLowerCase()!=="inactive":ue.length!==x.size?!1:ue.some(a=>a.status!=="Inactive"),[c,W,ue,x.size,F.status]),pe=i.useCallback(async a=>{o(!0),v(null);try{const g=await er({page:a,pageSize:y,searchQuery:F.search,roleFilter:F.role,statusFilter:F.status});h(g.users),d(g.total===0?1:g.page),B(g.total),O(g.totalPages||1),Y(g.hasNextPage),ls(I=>{const fe={...I};return g.users.forEach(T=>{fe[T.id]=T}),fe})}catch(g){const I=g instanceof Error?g.message:"Failed to load users";v(I),z.error(I)}finally{o(!1)}},[y,F.search,F.role,F.status]);i.useEffect(()=>{pe(k)},[pe,k]);const hs=i.useCallback((a="Student")=>{zs(null),ae({}),ze(!1),Pe(!1),K(rt(a)),Ae(!0)},[]);i.useEffect(()=>{s&&(hs(s),t?.())},[s,hs,t]);const Ms=i.useCallback(a=>{if(c){te(g=>{const I=new Set(g);return I.has(a)?I.delete(a):I.add(a),I});return}E(g=>{const I=new Set(g);return I.has(a)?I.delete(a):I.add(a),I})},[c]),Is=i.useCallback(()=>{if(r.length===0)return;const a=r.map(g=>g.id);if(c){te(g=>{const I=new Set(g);return a.every(T=>!I.has(T))?a.forEach(T=>I.add(T)):a.forEach(T=>I.delete(T)),I});return}E(g=>{const I=new Set(g);return a.every(T=>I.has(T))?a.forEach(T=>I.delete(T)):a.forEach(T=>I.add(T)),I})},[r,c]),Et=i.useCallback(()=>{u(!0),E(new Set),te(new Set)},[]),Rs=i.useCallback(a=>{if(!a.length){z.info("No rows were returned for export.");return}const g=Array.from(a.reduce((Be,ps)=>(Object.keys(ps).forEach(Kt=>Be.add(Kt)),Be),new Set)),I=[g.map(lt).join(","),...a.map(Be=>g.map(ps=>lt(Be[ps])).join(","))].join(` -`),fe=new Blob([I],{type:"text/csv;charset=utf-8;"}),T=URL.createObjectURL(fe),gs=document.createElement("a");gs.href=T,gs.download=`admin-users-export-${Date.now()}.csv`,gs.click(),URL.revokeObjectURL(T)},[]),he=i.useCallback(async(a,g)=>{const I=g.userIds,fe={...F.search?{search:F.search}:{},...F.role?{role:F.role}:{},...F.status?{status:F.status}:{}};if(!I&&W===0){z.error("Select at least one user before applying a bulk action.");return}j(!0);try{const T=await ar({action:a,...I?{userIds:I}:c?{userIds:[],excludeUserIds:Array.from($),filters:fe}:{userIds:Array.from(x)},...g.role?{role:g.role}:{},...g.status?{status:g.status}:{},...g.grade?{grade:g.grade}:{},...g.section?{section:g.section}:{},...g.exportFormat?{exportFormat:g.exportFormat}:{}});a==="export"&&Rs(T.exportRows),T.summary.failed>0?z.warning(`Completed with partial failures. ${T.summary.succeeded} succeeded, ${T.summary.failed} failed, ${T.summary.skipped} skipped.`):z.success(`Action completed. ${T.summary.succeeded} user(s) updated.`),T.warnings.length>0&&z.info(T.warnings[0]),await bs(g.auditAction,"User",a==="delete"||a==="deactivate"?"Warning":"Info",`${g.auditDetail}; targeted=${T.summary.targeted}, succeeded=${T.summary.succeeded}, failed=${T.summary.failed}, skipped=${T.summary.skipped}`,{name:l?.name||"Admin",role:"Admin",avatar:l?.photo||null}),g.skipSelectionReset||ge(),await pe(k)}catch(T){z.error(T instanceof Error?T.message:"Bulk action failed")}finally{j(!1)}},[F.search,F.role,F.status,c,$,x,W,l?.name,l?.photo,ge,pe,k,Rs]),Fe=i.useCallback(a=>{ms(a),os(!0)},[]),Ut=i.useCallback(async()=>{if(!(!xe||Ue)){As(!0);try{await he(xe.action,{...xe.params||{},auditAction:xe.auditAction,auditDetail:xe.auditDetail}),os(!1),ms(null)}finally{As(!1)}}},[xe,Ue,he]),Es=a=>{zs(a),ae({}),ze(!1),Pe(!1),K({name:a.name,email:a.email,password:"",confirmPassword:"",role:a.role,status:a.status,department:a.department,grade:a.grade||"Grade 11",section:a.section||"Section A",lrn:a.lrn||""}),Ae(!0)},$t=async()=>{if(!N.name.trim()||!N.email.trim()){z.error("Name and email are required");return}if(!J){const a=fr({name:N.name,email:N.email,password:N.password,confirmPassword:N.confirmPassword,role:N.role,status:N.status,grade:N.grade,section:N.section,lrn:N.lrn}),g=br(a);if(g){ae(a),z.error(g);return}}S(!0);try{if(J){const a={name:N.name,role:N.role,status:N.status,grade:N.grade,section:N.section,lrn:N.role==="Student"?N.lrn:void 0};N.role!=="Student"&&(a.department=N.department),await sr(J.id,a),await bs("User Updated","User","Info",`Updated user: ${N.name} (${J.email})`,{name:l?.name||"Admin",role:"Admin",avatar:l?.photo||null}),z.success("User updated successfully")}else{const a=await tr({email:N.email,name:N.name,password:N.password,confirmPassword:N.confirmPassword,role:N.role,status:N.status,grade:N.grade,section:N.section,lrn:N.role==="Student"?N.lrn:void 0});await bs("Created New User","User","Info",`Created new ${N.role.toLowerCase()} account: ${N.name} (${N.email}), emailSent=${a.emailSent}`,{name:l?.name||"Admin",role:"Admin",avatar:l?.photo||null}),a.emailSent?z.success("User created and welcome email sent"):(z.warning("User created, but welcome email failed to send"),a.emailError?.message&&z.error(a.emailError.message))}J?await pe(k):(ge(),d(1),await pe(1)),Ae(!1),ze(!1),Pe(!1)}finally{S(!1)}},Us=(a,g)=>{Fe({title:"Delete User?",message:`Delete user "${g}"? This cannot be undone.`,confirmText:"Delete",action:"delete",params:{userIds:[a]},auditAction:"User Deleted",auditDetail:`Deleted user account: ${g}`})},$s=async a=>{if(w||f)return;if(a.status==="Active"){Fe({title:"Deactivate User?",message:`Deactivate "${a.name}"? They will lose access until reactivated.`,confirmText:"Deactivate",action:"deactivate",params:{userIds:[a.id]},auditAction:"User Status Changed",auditDetail:`Deactivated user: ${a.email}`});return}A(a.id);try{await he("activate",{userIds:[a.id],auditAction:"User Status Changed",auditDetail:`Activated user: ${a.email}`,skipSelectionReset:!0})}finally{A(null)}},Ft=async()=>{await he("change_role",{role:Ce,auditAction:"Bulk Role Update",auditDetail:`Updated selected users to role ${Ce}`})},Bt=async()=>{await he("change_status",{status:ns,auditAction:"Bulk Status Update",auditDetail:`Updated selected users to status ${ns}`})},qt=async()=>{if(!Ds){z.error("Class/section assignment is only available for student selections.");return}await he("assign_class_section",{grade:ds,section:cs,auditAction:"Bulk Class Assignment",auditDetail:`Assigned class section ${ds} - ${cs}`})},Ot=async()=>{await he("reset_password_email",{auditAction:"Bulk Password Reset",auditDetail:"Sent password reset emails to selected users"})},Gt=async()=>{await he("export",{exportFormat:"csv",auditAction:"Bulk Export Users",auditDetail:"Exported selected users"})},Ht=()=>{Ts&&he("activate",{auditAction:"Bulk User Activation",auditDetail:"Activated selected users"})},_t=()=>{Ls&&Fe({title:"Deactivate Selected Users?",message:`Deactivate ${W} selected user(s)? They will lose access until reactivated.`,confirmText:"Deactivate Users",action:"deactivate",auditAction:"Bulk User Deactivation",auditDetail:`Deactivated ${W} selected users`})},Qt=()=>{Fe({title:"Delete Selected Users?",message:`Delete ${W} selected user(s)? This action cannot be undone.`,confirmText:"Delete Users",action:"delete",auditAction:"Bulk User Deletion",auditDetail:`Deleted ${W} selected users`})},Vt=[{label:"Total Users",value:C,color:"text-[#0a1628]"},{label:"Active (Page)",value:r.filter(a=>a.status==="Active").length,color:"text-green-600"},{label:"Admins (Page)",value:r.filter(a=>a.role==="Admin").length,color:"text-sky-600"},{label:"Teachers (Page)",value:r.filter(a=>a.role==="Teacher").length,color:"text-sky-600"},{label:"Students (Page)",value:r.filter(a=>a.role==="Student").length,color:"text-emerald-600"}],Wt=C===0?0:(k-1)*y+1,Xt=C===0?0:Math.min(k*y,C);return e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 md:grid-cols-5 gap-4",children:n?Array.from({length:5}).map((a,g)=>e.jsxs("div",{className:"bg-white p-4 rounded-xl border border-[#dde3eb] shadow-sm",children:[e.jsx("div",{className:"h-7 w-16 bg-[#edf1f7] rounded animate-pulse mb-2"}),e.jsx("div",{className:"h-4 w-24 bg-[#edf1f7] rounded animate-pulse"})]},`stats-skeleton-${g}`)):Vt.map((a,g)=>e.jsxs("div",{className:"bg-white p-4 rounded-xl border border-[#dde3eb] shadow-sm",children:[e.jsx("h3",{className:`text-2xl font-bold ${a.color}`,children:a.value}),e.jsx("p",{className:"text-sm text-[#5a6578]",children:a.label})]},g))}),e.jsxs("div",{className:"bg-white p-4 rounded-xl border border-[#dde3eb] shadow-sm space-y-4",children:[e.jsxs("div",{className:"relative",children:[e.jsx(wt,{className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-500",size:18}),e.jsx(R,{placeholder:"Search users by name or email...",className:"pl-10 bg-[#edf1f7] border-[#dde3eb]",value:H,onChange:a=>{ee(a.target.value),d(1),ge()}})]}),e.jsxs("div",{className:"flex flex-col md:flex-row justify-between gap-4",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3",children:[e.jsxs(re,{value:Q,onValueChange:a=>{oe(a),d(1),ge()},children:[e.jsx(ie,{className:"w-full sm:w-[140px] bg-[#edf1f7] border-[#dde3eb]",children:e.jsx(le,{placeholder:"All Roles"})}),e.jsxs(ne,{children:[e.jsx(P,{value:"All Roles",children:"All Roles"}),e.jsx(P,{value:"Admin",children:"Admin"}),e.jsx(P,{value:"Teacher",children:"Teacher"}),e.jsx(P,{value:"Student",children:"Student"})]})]}),e.jsxs(re,{value:b,onValueChange:a=>{V(a),d(1),ge()},children:[e.jsx(ie,{className:"w-full sm:w-[140px] bg-[#edf1f7] border-[#dde3eb]",children:e.jsx(le,{placeholder:"All Status"})}),e.jsxs(ne,{children:[e.jsx(P,{value:"All Status",children:"All Status"}),e.jsx(P,{value:"Active",children:"Active"}),e.jsx(P,{value:"Inactive",children:"Inactive"})]})]}),e.jsxs(re,{value:String(y),onValueChange:a=>{const g=Number(a);Number.isNaN(g)||(L(g),d(1),ge())},children:[e.jsx(ie,{className:"w-full sm:w-[150px] bg-[#edf1f7] border-[#dde3eb]",children:e.jsx(le,{placeholder:"Rows per page"})}),e.jsx(ne,{children:jr.map(a=>e.jsxs(P,{value:a,children:[a," / page"]},a))})]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3",children:[e.jsxs(M,{variant:"outline",className:"gap-2 border-[#dde3eb] text-[#5a6578]",onClick:()=>pe(k),disabled:n||f,children:[e.jsx(Ie,{size:16}),"Refresh"]}),e.jsxs(M,{className:"gap-2 bg-sky-500 hover:bg-sky-600 text-white",onClick:()=>hs(),disabled:f,children:[e.jsx(va,{size:16}),"Add User"]})]})]}),W>0?e.jsxs("div",{className:"border-t border-[#dde3eb] pt-4 space-y-3",children:[e.jsxs("div",{className:"flex flex-col lg:flex-row lg:items-center lg:justify-between gap-3",children:[e.jsxs("div",{className:"text-sm text-[#5a6578]",children:[e.jsx("span",{className:"font-semibold text-[#0a1628]",children:W})," user(s) selected",c?" across filtered results":""]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[!c&&W>0&&WDt(a),children:[e.jsx(ie,{className:"bg-[#edf1f7] border-[#dde3eb] sm:w-[160px]",children:e.jsx(le,{placeholder:"Role target"})}),e.jsxs(ne,{children:[e.jsx(P,{value:"Student",children:"Student"}),e.jsx(P,{value:"Teacher",children:"Teacher"}),e.jsx(P,{value:"Admin",children:"Admin"})]})]}),e.jsx(M,{variant:"outline",size:"sm",className:"border-[#dde3eb]",onClick:()=>void Ft(),disabled:f,children:"Change Role"})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[e.jsxs(re,{value:ns,onValueChange:a=>Tt(a),children:[e.jsx(ie,{className:"bg-[#edf1f7] border-[#dde3eb] sm:w-[160px]",children:e.jsx(le,{placeholder:"Status target"})}),e.jsxs(ne,{children:[e.jsx(P,{value:"Active",children:"Active"}),e.jsx(P,{value:"Inactive",children:"Inactive"})]})]}),e.jsx(M,{variant:"outline",size:"sm",className:"border-[#dde3eb]",onClick:()=>void Bt(),disabled:f,children:"Change Status"})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[e.jsx(R,{value:ds,onChange:a=>Lt(a.target.value),className:"bg-[#edf1f7] border-[#dde3eb] sm:w-[140px]",placeholder:"Grade"}),e.jsx(R,{value:cs,onChange:a=>Mt(a.target.value),className:"bg-[#edf1f7] border-[#dde3eb] sm:w-[140px]",placeholder:"Section"}),e.jsx(M,{variant:"outline",size:"sm",className:"border-[#dde3eb]",onClick:()=>void qt(),disabled:f||!Ds,children:"Assign Class"})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(M,{variant:"outline",size:"sm",className:"border-[#dde3eb]",onClick:Ht,disabled:f||!Ts,children:[e.jsx(Xs,{size:14,className:"mr-2"}),"Activate"]}),e.jsxs(M,{variant:"outline",size:"sm",className:"border-[#dde3eb]",onClick:_t,disabled:f||!Ls,children:[e.jsx(Vs,{size:14,className:"mr-2"}),"Deactivate"]}),e.jsxs(M,{variant:"outline",size:"sm",className:"border-[#dde3eb]",onClick:()=>void Ot(),disabled:f,children:[e.jsx(ya,{size:14,className:"mr-2"}),"Send Reset Email"]}),e.jsxs(M,{variant:"outline",size:"sm",className:"border-[#dde3eb]",onClick:()=>void Gt(),disabled:f,children:[e.jsx(kt,{size:14,className:"mr-2"}),"Export Selection"]}),e.jsxs(M,{variant:"destructive",size:"sm",onClick:Qt,disabled:f,children:[e.jsx(Qs,{size:14,className:"mr-2"}),"Delete"]})]})]}):null]}),m?e.jsxs("div",{className:"rounded-xl border border-red-200 bg-red-50 px-4 py-3 flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex items-start gap-2 min-w-0",children:[e.jsx(Se,{size:18,className:"text-red-600 mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-semibold text-red-700",children:"Unable to load users"}),e.jsx("p",{className:"text-sm text-red-600 break-words",children:m})]})]}),e.jsx(M,{type:"button",variant:"outline",className:"border-red-200 text-red-700 hover:bg-red-100",onClick:()=>pe(k),disabled:n||f,children:"Retry"})]}):null,e.jsxs("div",{className:"bg-white rounded-xl border border-[#dde3eb] shadow-sm overflow-hidden",children:[e.jsxs("div",{className:"md:hidden divide-y divide-[#dde3eb]",children:[e.jsxs("div",{className:"px-4 py-3 bg-[#edf1f7] border-b border-[#dde3eb] flex items-center justify-between",children:[e.jsxs("label",{className:"flex items-center gap-2 text-xs text-[#5a6578]",children:[e.jsx(He,{checked:Ps,onCheckedChange:Is}),"Select visible (",r.length,")"]}),e.jsxs("span",{className:"text-xs text-[#5a6578]",children:["Page ",k," / ",q]})]}),n&&r.length===0?e.jsx("div",{className:"px-6 py-10 text-center text-[#5a6578]",children:"Loading users..."}):r.length>0?r.map(a=>{const g=w===a.id;return e.jsxs("div",{className:"p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(He,{checked:$e(a.id),onCheckedChange:()=>Ms(a.id)}),e.jsxs(Bs,{children:[e.jsx(qs,{src:a.photo}),e.jsx(Os,{children:a.name.charAt(0)})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-semibold text-[#0a1628] truncate",children:a.name}),e.jsx("p",{className:"text-xs text-[#5a6578] truncate",children:a.email})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-xs",children:[e.jsxs("div",{className:"rounded-lg bg-[#edf1f7] px-2 py-1.5 text-[#5a6578]",children:["Role: ",e.jsx("span",{className:"font-semibold text-[#0a1628]",children:a.role})]}),e.jsxs("div",{className:"rounded-lg bg-[#edf1f7] px-2 py-1.5 text-[#5a6578]",children:["Status: ",e.jsx("span",{className:"font-semibold text-[#0a1628]",children:a.status})]}),e.jsxs("div",{className:"rounded-lg bg-[#edf1f7] px-2 py-1.5 text-[#5a6578] col-span-2",children:["Last Login: ",e.jsx("span",{className:"font-semibold text-[#0a1628]",children:a.lastLogin||"Never"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>Es(a),"aria-label":`Edit ${a.name}`,className:"px-3 py-2 rounded-lg border border-[#dde3eb] text-[#5a6578] hover:bg-[#edf1f7]",children:"Edit"}),e.jsx("button",{type:"button",onClick:()=>$s(a),"aria-label":a.status==="Active"?`Deactivate ${a.name}`:`Activate ${a.name}`,disabled:g||f,className:"px-3 py-2 rounded-lg border border-[#dde3eb] text-[#5a6578] disabled:opacity-60 disabled:cursor-not-allowed",children:g?"Updating...":a.status==="Active"?"Deactivate":"Activate"}),e.jsx("button",{type:"button",onClick:()=>Us(a.id,a.name),"aria-label":`Delete ${a.name}`,disabled:f,className:"px-3 py-2 rounded-lg border border-red-200 text-red-600 disabled:opacity-60 disabled:cursor-not-allowed",children:"Delete"})]})]},`mobile-${a.id}`)}):m?e.jsx("div",{className:"px-6 py-12 text-center text-red-600",children:e.jsxs("div",{className:"flex flex-col items-center gap-3",children:[e.jsx(Se,{size:24,className:"text-red-500"}),e.jsx("p",{children:"Users could not be loaded."})]})}):e.jsx("div",{className:"px-6 py-12 text-center text-[#5a6578]",children:e.jsxs("div",{className:"flex flex-col items-center gap-3",children:[e.jsx("div",{className:"p-3 bg-[#edf1f7] rounded-full",children:e.jsx(Je,{size:24,className:"text-slate-500"})}),e.jsx("p",{children:"No users found matching your filters"})]})})]}),e.jsx("div",{className:"hidden md:block overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm text-left",children:[e.jsx("thead",{className:"text-xs text-[#5a6578] uppercase bg-[#edf1f7] border-b border-[#dde3eb]",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-4 font-semibold w-[56px]",children:e.jsx(He,{checked:Ps,onCheckedChange:Is})}),e.jsx("th",{className:"px-6 py-4 font-semibold",children:"User"}),e.jsx("th",{className:"px-6 py-4 font-semibold",children:"Role"}),e.jsx("th",{className:"px-6 py-4 font-semibold",children:"Status"}),e.jsx("th",{className:"px-6 py-4 font-semibold",children:"Class/Department"}),e.jsx("th",{className:"px-6 py-4 font-semibold",children:"Last Login"}),e.jsx("th",{className:"px-6 py-4 font-semibold text-right",children:"Actions"})]})}),e.jsx("tbody",{className:"divide-y divide-[#dde3eb]",children:n&&r.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"px-6 py-12 text-center text-[#5a6578]",children:"Loading users..."})}):r.length>0?r.map(a=>{const g=w===a.id;return e.jsxs("tr",{className:"hover:bg-[#edf1f7]/50 transition-colors",children:[e.jsx("td",{className:"px-4 py-4",children:e.jsx(He,{checked:$e(a.id),onCheckedChange:()=>Ms(a.id)})}),e.jsx("td",{className:"px-6 py-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs(Bs,{children:[e.jsx(qs,{src:a.photo}),e.jsx(Os,{children:a.name.charAt(0)})]}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-[#0a1628]",children:a.name}),e.jsx("p",{className:"text-xs text-[#5a6578]",children:a.email})]})]})}),e.jsx("td",{className:"px-6 py-4",children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[a.role==="Admin"&&e.jsx(Ke,{size:14,className:"text-sky-600"}),a.role==="Teacher"&&e.jsx(ks,{size:14,className:"text-sky-600"}),a.role==="Student"&&e.jsx(_a,{size:14,className:"text-emerald-600"}),e.jsx("span",{className:` + `,children:[e.jsx("input",{ref:q,type:"file",accept:".pdf",className:"hidden",onChange:x=>x.target.files?.[0]&&G(x.target.files[0])}),m?e.jsxs("div",{className:"flex items-center justify-center gap-3",children:[e.jsx(es,{size:24,className:"text-sky-600"}),e.jsxs("div",{className:"text-left",children:[e.jsx("p",{className:"font-semibold text-[#0a1628]",children:m.name}),e.jsxs("p",{className:"text-xs text-[#5a6578]",children:[(m.size/1024/1024).toFixed(2)," MB"]})]}),!t&&e.jsx("button",{onClick:x=>{x.stopPropagation(),v(null)},className:"ml-4 p-1.5 hover:bg-rose-50 rounded-lg text-rose-500","aria-label":"Remove file",children:e.jsx(_s,{size:18})})]}):e.jsxs(e.Fragment,{children:[e.jsx(bs,{size:28,className:"mx-auto mb-2 text-[#dde3eb]"}),e.jsx("p",{className:"font-semibold text-[#0a1628]",children:"Drop PDF here or click to browse"}),e.jsx("p",{className:"text-xs text-[#5a6578] mt-1",children:"PDF files only, max 50MB"})]})]}),k>0&&e.jsxs("div",{className:"mb-4",children:[e.jsxs("div",{className:"flex justify-between text-xs text-[#5a6578] mb-1",children:[e.jsx("span",{children:t?"Uploading...":"Complete"}),e.jsxs("span",{children:[k,"%"]})]}),e.jsx("div",{className:"h-2 bg-[#edf1f7] rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-sky-500 rounded-full transition-all duration-300",style:{width:`${k}%`}})})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4 mb-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-[#5a6578] mb-1.5 block",children:"Subject"}),e.jsxs(re,{value:p,onValueChange:Q,disabled:t,children:[e.jsx(le,{className:"w-full",children:e.jsx(ie,{placeholder:"Select subject"})}),e.jsx(ne,{children:Ke.map(x=>e.jsxs(P,{value:x.id,children:[x.name," (",x.gradeLevel," — ",x.semester,")"]},x.id))})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-[#5a6578] mb-1.5 block",children:"Subject Name (display)"}),e.jsx(R,{value:f,onChange:x=>j(x.target.value),placeholder:"e.g. General Mathematics",disabled:t})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-[#5a6578] mb-1.5 block",children:"Semester"}),e.jsxs(re,{value:w,onValueChange:A,disabled:t,children:[e.jsx(le,{className:"w-full",children:e.jsx(ie,{})}),e.jsxs(ne,{children:[e.jsx(P,{value:"1",children:"Q1"}),e.jsx(P,{value:"2",children:"Q2"}),e.jsx(P,{value:"3",children:"Q3"}),e.jsx(P,{value:"4",children:"Q4"})]})]})]})]}),e.jsx(M,{onClick:ce,disabled:t||!m||!p||!f.trim(),className:"w-full gap-2 bg-sky-600 hover:bg-sky-700 text-white",children:t?e.jsxs(e.Fragment,{children:[e.jsx(H,{size:16,className:"animate-spin"})," Uploading & Indexing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(bs,{size:16})," Upload & Ingest"]})})]}),e.jsxs("div",{className:"bg-white rounded-2xl border border-[#dde3eb] shadow-sm overflow-hidden",children:[e.jsxs("div",{className:"p-6 border-b border-[#dde3eb] 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-teal-100 rounded-xl flex items-center justify-center",children:e.jsx(ss,{size:20,className:"text-teal-600"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-bold text-[#0a1628]",children:"RAG Index Status"}),e.jsx("p",{className:"text-xs text-[#5a6578]",children:C?"Loading...":`${y?.chunkCount??0} total chunks across ${V.length} subjects`})]})]}),e.jsxs(M,{variant:"outline",size:"sm",className:"gap-2",onClick:O,disabled:C,children:[e.jsx(Re,{size:14,className:C?"animate-spin":""}),"Refresh"]})]}),C?e.jsx("div",{className:"flex items-center justify-center h-32",children:e.jsx(H,{size:20,className:"animate-spin text-sky-500"})}):V.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 gap-2",children:[e.jsx(oe,{size:24,className:"text-[#dde3eb]"}),e.jsx("p",{className:"text-sm text-[#5a6578]",children:"No PDFs indexed yet"})]}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-left",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-[#edf1f7] border-b border-[#dde3eb]",children:[e.jsx("th",{className:"p-4 text-xs font-bold text-[#5a6578] uppercase tracking-wider",children:"Subject"}),e.jsx("th",{className:"p-4 text-xs font-bold text-[#5a6578] uppercase tracking-wider",children:"Chunks"}),e.jsx("th",{className:"p-4 text-xs font-bold text-[#5a6578] uppercase tracking-wider",children:"Status"}),e.jsx("th",{className:"p-4 text-xs font-bold text-[#5a6578] uppercase tracking-wider text-right",children:"Actions"})]})}),e.jsx("tbody",{className:"divide-y divide-[#dde3eb]",children:V.map(x=>e.jsxs("tr",{className:"hover:bg-[#f8fafc] transition-colors",children:[e.jsx("td",{className:"p-4",children:e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(es,{size:16,className:"text-[#5a6578]"}),e.jsx("span",{className:"font-semibold text-sm text-[#0a1628]",children:x.name})]})}),e.jsx("td",{className:"p-4",children:e.jsx("span",{className:"text-sm font-bold text-[#0a1628]",children:x.chunks})}),e.jsx("td",{className:"p-4",children:e.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-1 rounded-full text-xs font-bold border ${x.status==="active"?"bg-green-50 text-green-700 border-green-200":x.status==="locked"?"bg-amber-50 text-amber-700 border-amber-200":"bg-rose-50 text-rose-700 border-rose-200"}`,children:[x.status==="active"?e.jsx(ts,{size:12}):e.jsx(_s,{size:12}),x.status.charAt(0).toUpperCase()+x.status.slice(1)]})}),e.jsx("td",{className:"p-4 text-right",children:e.jsxs(M,{variant:"outline",size:"sm",className:"gap-1.5 text-xs",onClick:()=>b(x.name.toLowerCase().replace(/\s+/g,"-").replace("&",""),x.storagePath),disabled:r===x.name.toLowerCase().replace(/\s+/g,"-").replace("&",""),children:[r===x.name.toLowerCase().replace(/\s+/g,"-").replace("&","")?e.jsx(H,{size:12,className:"animate-spin"}):e.jsx(Re,{size:12}),"Re-ingest"]})})]},x.name))})]})}),y?.lastIngested&&e.jsx("div",{className:"p-4 border-t border-[#dde3eb] bg-[#f8fafc]",children:e.jsxs("p",{className:"text-xs text-[#5a6578]",children:["Last ingestion: ",new Date(y.lastIngested).toLocaleString()]})})]})]})};function Qa(s){return s?s.charAt(0).toUpperCase()+s.slice(1):"Student"}function zt(s){if(!s||!s.toDate)return new Date().toISOString().replace("T"," ").slice(0,19);const t=s.toDate();return`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,"0")}-${String(t.getDate()).padStart(2,"0")} ${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}:${String(t.getSeconds()).padStart(2,"0")}`}function Va(){return zt({toDate:()=>new Date})}function Wa(s){if(!s)return"Never";const t=new Date(s);if(Number.isNaN(t.getTime()))return s;const r=Date.now()-t.getTime(),h=Math.floor(r/6e4);if(h<1)return"Just now";if(h<60)return`${h} minute${h!==1?"s":""} ago`;const n=Math.floor(h/60);if(n<24)return`${n} hour${n!==1?"s":""} ago`;const o=Math.floor(n/24);return o<7?`${o} day${o!==1?"s":""} ago`:t.toLocaleDateString()}function Xa(s){const t=(s.grade||"").trim(),i=(s.section||"").trim(),r=[t,i].filter(Boolean).join(" - ");return{id:s.uid,name:s.name||"Unknown",email:s.email||"",role:Qa(s.role||""),status:s.status||"Active",department:s.department||(s.role?.toLowerCase()==="student"?r||"Student":""),grade:t,section:i,classSectionId:s.classSectionId||void 0,classSection:r,lrn:(s.lrn||"").trim(),photo:(s.photo||"").trim(),lastLogin:Wa(s.lastLogin),createdAt:s.createdAt||void 0}}function is(s){if(s instanceof ot){try{const t=JSON.parse(s.responseBody);if(t?.detail&&typeof t.detail=="string")return t.detail}catch{}return`Request failed (${s.status}).`}return s instanceof Error?s.message:"Request failed."}async function Ka(s={}){try{const t=await ye.getAdminUsers({page:s.page??1,pageSize:s.pageSize??25,search:s.searchQuery,role:s.roleFilter,status:s.statusFilter,grade:s.gradeFilter,section:s.sectionFilter,classSectionId:s.classSectionId});if(!t.success)throw new Error("Failed to load admin users");return{users:(t.users||[]).map(Xa),page:t.page,pageSize:t.pageSize,total:t.total,totalPages:t.totalPages,hasNextPage:t.hasNextPage}}catch(t){throw console.error("[adminService] getAdminUsersPage error:",t),t instanceof ea?new Error("Loading users timed out. Please refresh and try again."):t instanceof sa?new Error("Unable to reach the server. Please check your connection and retry."):t instanceof ot&&t.status===504?new Error("Loading users took too long. Try narrowing your filters and retrying."):new Error(is(t))}}async function Ja(s,t){try{await ye.updateAdminUser(s,{...t.name!==void 0?{name:t.name}:{},...t.role!==void 0?{role:t.role}:{},...t.status!==void 0?{status:t.status}:{},...t.department!==void 0?{department:t.department}:{},...t.grade!==void 0?{grade:t.grade}:{},...t.section!==void 0?{section:t.section}:{},...t.lrn!==void 0?{lrn:t.lrn}:{}})}catch(i){throw new Error(is(i))}}async function Za(s){try{const t=await ye.createAdminUser({name:s.name.trim(),email:s.email.trim().toLowerCase(),password:s.password,confirmPassword:s.confirmPassword,role:s.role,status:s.status,grade:s.grade.trim(),section:s.section.trim(),...s.lrn?.trim()?{lrn:s.lrn.trim()}:{}});if(!t.success||!t.userCreated||!t.uid)throw new Error(t.message||"Failed to create user account.");return{uid:t.uid,userCreated:t.userCreated,emailSent:t.emailSent,resultCode:t.resultCode,message:t.message,warnings:t.warnings??[],emailError:t.emailError}}catch(t){throw new Error(is(t))}}async function Ya(s){try{const t=await ye.bulkAdminUsers({action:s.action,userIds:s.userIds??[],excludeUserIds:s.excludeUserIds??[],filters:s.filters,role:s.role,status:s.status,grade:s.grade,section:s.section,lrn:s.lrn,dryRun:s.dryRun,exportFormat:s.exportFormat??"csv"});return{success:t.success,action:t.action,summary:t.summary,results:t.results,warnings:t.warnings||[],exportRows:t.export?.rows||[]}}catch(t){throw new Error(is(t))}}async function Pt(){try{if(!Yt.currentUser)return[];const s=as(se(X,"accessAuditLogs"),Nt("timestamp","desc"),Ss(100));return(await de(s)).docs.map(i=>{const r=i.data(),n=r.success!==!1?"Info":"Error",o=r.action||"";let m="System";return r.module==="admin"||o.startsWith("admin_")?m="User":o.includes("login")||o.includes("auth")?m="Auth":(o.includes("upload")||o.includes("course"))&&(m="Content"),{id:i.id,severity:n,timestamp:typeof r.timestamp=="string"?r.timestamp:zt(r.timestamp),user:{name:r.actorName||r.teacherEmail||"System",role:r.actorRole||r.role||"Admin",avatar:null},action:o,category:m,details:r.description||(r.status?`Status: ${r.status}`:"")}})}catch(s){const t=s;return t?.code==="permission-denied"||t?.code==="firestore/permission-denied"?[]:(console.error("[adminService] getAuditLogs error:",s),[])}}async function js(s,t,i,r,h){await ca(se(X,"auditLogs"),{severity:i,timestamp:Va(),timestampRaw:yt(),user:h,action:s,category:t,details:r})}async function er(){try{const s=await de(se(X,"users"));let t=0,i=0,r=0;s.docs.forEach(m=>{const v=m.data();v.role==="student"&&(t++,v.overallRisk==="High"&&r++),v.role==="teacher"&&v.status!=="Inactive"&&i++});let h=0;try{h=(await de(se(X,"classrooms"))).size}catch{}let n=0;try{n=(await de(se(X,"xpActivities"))).size}catch{}let o=0;try{const m=await de(se(X,"progress")),v=[];m.docs.forEach(p=>{const S=p.data();typeof S.averageScore=="number"&&v.push(S.averageScore)}),o=v.length>0?Math.round(v.reduce((p,S)=>p+S,0)/v.length):0}catch{}return{totalStudents:t,activeTeachers:i,totalClasses:h,atRiskStudents:r,avgPerformance:o,aiPredictions:n}}catch(s){return console.error("[adminService] getDashboardStats error:",s),{totalStudents:0,activeTeachers:0,totalClasses:0,atRiskStudents:0,avgPerformance:0,aiPredictions:0}}}async function sr(s=3){const t=r=>{const h=r.data(),n=h.level||1,o=h.currentXP||0,m=Math.min(100,n*8+Math.round(o/100));return{id:r.id,name:h.name||"Student",avatar:h.photo||h.photoURL||`https://ui-avatars.com/api/?name=${encodeURIComponent(h.name||"S")}&background=0d9488&color=fff`,class:h.grade||"Math",performance:m,level:n}},i=r=>r.sort((h,n)=>n.level!==h.level?n.level-h.level:n.performance-h.performance).slice(0,s);try{const r=as(se(X,"users"),ks("role","==","student"),Nt("level","desc"),Ss(s)),h=await de(r);return i(h.docs.map(t))}catch(r){if(r?.code==="failed-precondition")try{const n=as(se(X,"users"),ks("role","==","student"),Ss(Math.max(50,s))),o=await de(n);return i(o.docs.map(t))}catch(n){return console.error("[adminService] getTopPerformers fallback error:",n),[]}return console.error("[adminService] getTopPerformers error:",r),[]}}async function tr(){try{const s=await de(se(X,"users"));let t=0,i=0,r=0,h=0,n=0;s.docs.forEach(v=>{const p=v.data();p.role==="student"&&(t++,p.overallRisk==="High"&&r++,p.streak>0&&n++,h+=p.totalXP||0),p.role==="teacher"&&i++});let o=0;try{o=(await de(se(X,"achievements"))).size}catch{}let m=0;try{m=(await de(se(X,"chatSessions"))).size}catch{}return{totalActiveUsers:t+i,totalStudents:t,totalTeachers:i,atRiskStudents:r,achievementsUnlocked:o,totalXPEarned:h,activeStreaks:n,aiTutorSessions:m}}catch(s){return console.error("[adminService] getAnalyticsSummary error:",s),{totalActiveUsers:0,totalStudents:0,totalTeachers:0,atRiskStudents:0,achievementsUnlocked:0,totalXPEarned:0,activeStreaks:0,aiTutorSessions:0}}}const ar=()=>{const{userProfile:s,loading:t}=Ee(),[i,r]=l.useState([]),[h,n]=l.useState(!0),[o,m]=l.useState(!1),[v,p]=l.useState(""),[S,f]=l.useState("All Categories"),[j,w]=l.useState("All Severity"),[A,k]=l.useState("All Roles"),[d,y]=l.useState(25),[L,C]=l.useState(null),B=l.useCallback(async()=>{if(t||!s)return;const b=String(s.role||"").toLowerCase();if(b!=="admin"&&b!=="teacher"){n(!1),m(!0);return}m(!1),n(!0);try{const V=await Pt();r(V)}catch{z.error("Failed to load audit logs")}finally{n(!1)}},[t,s]);l.useEffect(()=>{B()},[B]),l.useEffect(()=>{y(25)},[v,S,j,A,i.length]);const q=i.filter(b=>b.severity==="Info").length,O=i.filter(b=>b.severity==="Warning").length,G=i.filter(b=>b.severity==="Error"||b.severity==="Critical").length,Y=b=>{switch(b){case"Info":return e.jsx(we,{size:16,className:"text-sky-600"});case"Warning":return e.jsx(oe,{size:16,className:"text-rose-600"});case"Error":return e.jsx(Se,{size:16,className:"text-red-600"});case"Critical":return e.jsx(Se,{size:16,className:"text-red-600"});default:return e.jsx(we,{size:16,className:"text-[#5a6578]"})}},_=b=>{switch(b){case"Info":return"bg-sky-100 text-sky-700 border-sky-200";case"Warning":return"bg-rose-100 text-rose-700 border-rose-200";case"Error":return"bg-red-100 text-red-700 border-red-200";case"Critical":return"bg-red-100 text-red-700 border-red-200 ring-2 ring-red-500";default:return"bg-[#edf1f7] text-[#0a1628] border-[#dde3eb]"}},ee=b=>{switch(b){case"Auth":return"bg-sky-100 text-sky-700";case"Data":return"bg-rose-100 text-rose-700";case"User":return"bg-sky-100 text-sky-700";case"System":return"bg-[#edf1f7] text-[#0a1628]";case"Content":return"bg-green-100 text-green-700";default:return"bg-[#edf1f7] text-[#0a1628]"}},Q=i.filter(b=>{const V=b.action.toLowerCase().includes(v.toLowerCase())||b.details.toLowerCase().includes(v.toLowerCase())||b.user.name.toLowerCase().includes(v.toLowerCase()),x=S==="All Categories"||b.category===S,E=j==="All Severity"||b.severity===j,c=A==="All Roles"||b.user.role===A;return V&&x&&E&&c}),ce=Q.slice(0,d);return e.jsxs(U.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("h2",{className:"text-lg font-bold text-[#0a1628]",children:"Audit Log"}),e.jsx("p",{className:"text-sm text-[#5a6578]",children:"System activity monitoring and security events"})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-start sm:items-center gap-3",children:[e.jsxs("div",{className:"bg-white px-3 py-2 rounded-xl border border-[#dde3eb] flex items-center gap-2 text-[#5a6578] text-sm font-medium",children:[e.jsx(ys,{size:16}),e.jsx("span",{children:"Last 100 events"})]}),e.jsxs(M,{variant:"outline",className:"gap-2 border-[#dde3eb] hover:bg-[#edf1f7]",onClick:B,children:[e.jsx(Re,{size:16}),"Refresh"]}),e.jsx(M,{variant:"outline",disabled:!0,title:"Audit log export is not implemented yet",className:"gap-2 border-[#dde3eb] opacity-60 cursor-not-allowed",children:"Export (Unavailable)"})]}),h?e.jsx("div",{className:"flex items-center justify-center h-24",children:e.jsx(H,{size:24,className:"animate-spin text-sky-500"})}):o?e.jsxs("div",{className:"flex flex-col items-center justify-center h-24 text-center",children:[e.jsx(mt,{size:24,className:"text-[#a0aec0] mb-2"}),e.jsx("p",{className:"text-sm font-medium text-[#5a6578]",children:"Audit logs are available only to teachers and admins."})]}):null,!o&&!h&&e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"bg-white p-4 rounded-xl border border-[#dde3eb] shadow-sm",children:[e.jsx("p",{className:"text-xs font-bold text-[#5a6578] mb-1",children:"Total Events"}),e.jsx("p",{className:"text-2xl font-bold text-[#0a1628]",children:i.length})]}),e.jsxs("div",{className:"bg-white p-4 rounded-xl border border-sky-200 shadow-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(we,{size:14,className:"text-sky-600"}),e.jsx("p",{className:"text-xs font-bold text-[#5a6578]",children:"Info"})]}),e.jsx("p",{className:"text-2xl font-bold text-sky-600",children:q})]}),e.jsxs("div",{className:"bg-white p-4 rounded-xl border border-rose-200 shadow-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(oe,{size:14,className:"text-rose-600"}),e.jsx("p",{className:"text-xs font-bold text-[#5a6578]",children:"Warnings"})]}),e.jsx("p",{className:"text-2xl font-bold text-rose-600",children:O})]}),e.jsxs("div",{className:"bg-white p-4 rounded-xl border border-red-200 shadow-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(Se,{size:14,className:"text-red-600"}),e.jsx("p",{className:"text-xs font-bold text-[#5a6578]",children:"Errors"})]}),e.jsx("p",{className:"text-2xl font-bold text-red-600",children:G})]})]}),!o&&e.jsxs("div",{className:"bg-white p-4 rounded-xl border border-[#dde3eb] shadow-sm space-y-4",children:[e.jsxs("div",{className:"relative",children:[e.jsx(St,{className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-500",size:18}),e.jsx(R,{type:"text",placeholder:"Search by user, action, or details...",className:"pl-10 bg-[#edf1f7] border-[#dde3eb]",value:v,onChange:b=>p(b.target.value)})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-start sm:items-center gap-3",children:[e.jsxs(re,{value:S,onValueChange:f,children:[e.jsx(le,{className:"w-full sm:w-[170px]",children:e.jsx(ie,{placeholder:"All Categories"})}),e.jsxs(ne,{children:[e.jsx(P,{value:"All Categories",children:"All Categories"}),e.jsx(P,{value:"Auth",children:"Auth"}),e.jsx(P,{value:"Data",children:"Data"}),e.jsx(P,{value:"User",children:"User"}),e.jsx(P,{value:"System",children:"System"}),e.jsx(P,{value:"Content",children:"Content"})]})]}),e.jsxs(re,{value:j,onValueChange:w,children:[e.jsx(le,{className:"w-full sm:w-[170px]",children:e.jsx(ie,{placeholder:"All Severity"})}),e.jsxs(ne,{children:[e.jsx(P,{value:"All Severity",children:"All Severity"}),e.jsx(P,{value:"Info",children:"Info"}),e.jsx(P,{value:"Warning",children:"Warning"}),e.jsx(P,{value:"Error",children:"Error"}),e.jsx(P,{value:"Critical",children:"Critical"})]})]}),e.jsxs(re,{value:A,onValueChange:k,children:[e.jsx(le,{className:"w-full sm:w-[170px]",children:e.jsx(ie,{placeholder:"All Roles"})}),e.jsxs(ne,{children:[e.jsx(P,{value:"All Roles",children:"All Roles"}),e.jsx(P,{value:"Admin",children:"Admin"}),e.jsx(P,{value:"Teacher",children:"Teacher"}),e.jsx(P,{value:"Student",children:"Student"})]})]})]})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-[#dde3eb] shadow-sm overflow-hidden",children:[e.jsx("div",{className:"md:hidden divide-y divide-[#dde3eb]",children:ce.map(b=>e.jsxs("div",{className:"p-4 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:`inline-flex items-center gap-2 px-3 py-1 rounded-full text-xs font-bold border ${_(b.severity)}`,children:[Y(b.severity),b.severity]}),e.jsx("button",{type:"button",onClick:()=>C(b),className:"p-2 hover:bg-[#dde3eb] rounded-lg text-slate-500 hover:text-sky-600 transition-colors","aria-label":`View audit event ${b.action}`,children:e.jsx(rs,{size:16})})]}),e.jsx("p",{className:"text-sm font-semibold text-[#0a1628]",children:b.action}),e.jsx("p",{className:"text-xs text-[#5a6578]",children:b.timestamp}),e.jsxs("p",{className:"text-xs text-[#5a6578]",children:[b.user.name," (",b.user.role,")"]}),e.jsx("p",{className:"text-xs text-[#5a6578]",children:b.details})]},`mobile-${b.id}`))}),e.jsx("div",{className:"hidden md:block overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[980px] text-left border-collapse",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-[#edf1f7] border-b border-[#dde3eb]",children:[e.jsx("th",{className:"p-4 text-xs font-bold text-[#5a6578] uppercase tracking-wider",children:"Severity"}),e.jsx("th",{className:"p-4 text-xs font-bold text-[#5a6578] uppercase tracking-wider",children:"Timestamp"}),e.jsx("th",{className:"p-4 text-xs font-bold text-[#5a6578] uppercase tracking-wider",children:"User"}),e.jsx("th",{className:"p-4 text-xs font-bold text-[#5a6578] uppercase tracking-wider",children:"Action"}),e.jsx("th",{className:"p-4 text-xs font-bold text-[#5a6578] uppercase tracking-wider",children:"Category"}),e.jsx("th",{className:"p-4 text-xs font-bold text-[#5a6578] uppercase tracking-wider",children:"Details"}),e.jsx("th",{className:"p-4 text-xs font-bold text-[#5a6578] uppercase tracking-wider text-right",children:"View"})]})}),e.jsx("tbody",{className:"divide-y divide-[#dde3eb]",children:ce.map(b=>e.jsxs("tr",{className:"hover:bg-[#edf1f7] transition-colors",children:[e.jsx("td",{className:"p-4",children:e.jsxs("div",{className:`inline-flex items-center gap-2 px-3 py-1 rounded-full text-xs font-bold border ${_(b.severity)}`,children:[Y(b.severity),b.severity]})}),e.jsx("td",{className:"p-4",children:e.jsxs("div",{className:"flex items-center gap-2 text-[#5a6578] text-sm",children:[e.jsx("div",{className:"p-1 bg-[#edf1f7] rounded",children:e.jsx(ys,{size:12})}),b.timestamp]})}),e.jsx("td",{className:"p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[b.user.avatar?e.jsx("img",{src:b.user.avatar,alt:b.user.name,className:"w-8 h-8 rounded-full object-cover"}):e.jsx("div",{className:"w-8 h-8 bg-sky-100 rounded-full flex items-center justify-center",children:e.jsx(Je,{size:16,className:"text-sky-600"})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-bold text-[#0a1628] text-sm",children:b.user.name}),e.jsx("p",{className:"text-xs text-[#5a6578]",children:b.user.role})]})]})}),e.jsx("td",{className:"p-4",children:e.jsx("p",{className:"font-medium text-[#0a1628] text-sm",children:b.action})}),e.jsx("td",{className:"p-4",children:e.jsx("span",{className:`px-2 py-1 rounded text-xs font-bold ${ee(b.category)}`,children:b.category})}),e.jsx("td",{className:"p-4 text-sm text-[#5a6578] max-w-xs truncate",title:b.details,children:b.details}),e.jsx("td",{className:"p-4 text-right",children:e.jsx("button",{type:"button",onClick:()=>C(b),className:"p-2 hover:bg-[#dde3eb] rounded-lg text-slate-500 hover:text-sky-600 transition-colors","aria-label":`View audit event ${b.action}`,children:e.jsx(rs,{size:16})})})]},b.id))})]})}),Q.length>d?e.jsx("div",{className:"border-t border-[#dde3eb] p-4 flex justify-center",children:e.jsx(M,{variant:"outline",className:"border-[#dde3eb]",onClick:()=>y(b=>b+25),children:"Load more events"})}):null,Q.length===0&&!h&&e.jsxs("div",{className:"p-12 text-center text-[#5a6578]",children:[e.jsx(Je,{size:48,className:"mx-auto mb-4 text-slate-500"}),e.jsx("p",{className:"font-medium",children:"No logs found"}),e.jsx("p",{className:"text-sm",children:i.length===0?"Audit events will appear here as actions are performed":"Try adjusting your search or filters"})]})]}),e.jsx(pt,{open:!!L,onOpenChange:b=>{b||C(null)},children:e.jsxs(ft,{children:[e.jsxs(bt,{children:[e.jsx(jt,{children:L?.action||"Audit Event Details"}),e.jsx(vt,{children:"Detailed audit information for operational review."})]}),L?e.jsxs("div",{className:"space-y-2 text-sm",children:[e.jsxs("p",{children:[e.jsx("span",{className:"font-semibold text-[#0a1628]",children:"Severity:"})," ",L.severity]}),e.jsxs("p",{children:[e.jsx("span",{className:"font-semibold text-[#0a1628]",children:"Category:"})," ",L.category]}),e.jsxs("p",{children:[e.jsx("span",{className:"font-semibold text-[#0a1628]",children:"Timestamp:"})," ",L.timestamp]}),e.jsxs("p",{children:[e.jsx("span",{className:"font-semibold text-[#0a1628]",children:"User:"})," ",L.user.name," (",L.user.role,")"]}),e.jsxs("p",{children:[e.jsx("span",{className:"font-semibold text-[#0a1628]",children:"Details:"})," ",L.details]})]}):null]})})]})},ls="—";function ve(s,t=ls){return s==null?t:String(s)}function rr(s){return s?s instanceof Date?s.toLocaleString():typeof s.toDate=="function"?s.toDate().toLocaleString():ls:ls}function Ce({label:s,value:t,accent:i}){return e.jsxs("div",{className:`rounded-xl border p-4 ${i?"bg-sky-50 border-sky-200":"bg-white border-[#dde3eb]"}`,children:[e.jsx("p",{className:"text-xs font-medium text-[#5a6578] uppercase tracking-wide mb-1",children:s}),e.jsx("p",{className:`text-base font-semibold ${t===ls?"text-slate-400":"text-[#0a1628]"}`,children:t})]})}function lr(){const[s,t]=l.useState(null),[i,r]=l.useState(!0),[h,n]=l.useState(null);return l.useEffect(()=>{(async()=>{r(!0),n(null);try{const m=As(X,"settings","modelConfig"),v=await wt(m);v.exists()?t(v.data()):t({})}catch(m){n(m.message??"Failed to load model configuration")}finally{r(!1)}})()},[]),i?e.jsx("div",{className:"space-y-4",children:e.jsx("p",{className:"text-sm text-[#5a6578]",children:"Loading model configuration..."})}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-start gap-2 p-3 bg-blue-50 border border-blue-200 rounded-xl text-blue-800",children:[e.jsx(we,{size:16,className:"mt-0.5 flex-shrink-0"}),e.jsx("p",{className:"text-xs leading-relaxed",children:"This configuration is managed by the system and cannot be edited here."})]}),h&&e.jsxs("p",{className:"text-sm text-red-600",children:["Error: ",h]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4",children:[e.jsx(Ce,{label:"Active Model Name",value:ve(s?.activeModelName)}),e.jsx(Ce,{label:"Provider / Endpoint",value:s?.endpoint?`${ve(s?.provider)} — ${s.endpoint}`:ve(s?.provider)}),e.jsx(Ce,{label:"Max Tokens",value:ve(s?.maxTokens)}),e.jsx(Ce,{label:"Temperature",value:ve(s?.temperature)}),e.jsx(Ce,{label:"Context Window",value:ve(s?.contextWindow)}),e.jsx(Ce,{label:"Fine-tune Status",value:ve(s?.fineTuneStatus),accent:!0})]}),e.jsx("div",{className:"pt-4 border-t border-[#dde3eb]",children:e.jsxs("p",{className:"text-xs text-[#5a6578]",children:["Last updated:"," ",e.jsx("span",{className:"font-medium text-[#0a1628]",children:rr(s?.lastUpdated)})]})})]})}const Dt="settings",Ks="general",Js="notifications",Zs="gamification",Ys="content",et={platformName:"MathPulse AI",institutionName:"",logoUrl:"",maintenanceMode:!1},st={emailAlertsOnRegistration:!1,alertOnQuizCompletionThreshold:!1,quizCompletionThresholdPercent:80,announcementBannerEnabled:!1,announcementBannerMessage:""},tt={xpPerCorrectAnswer:10,xpPerQuizCompletion:50,streakBonusMultiplier:1,leaderboardVisibility:!0},at={defaultQuizTimeLimitMinutes:30,maxQuestionsPerQuiz:20,allowStudentRetries:!0,difficultyAutoAdjustment:!1};async function Ge(s,t){try{const i=As(X,Dt,s),r=await wt(i);return r.exists()?{...t,...r.data()}:t}catch(i){return console.error(`[settings] Failed to load ${s}:`,i),t}}async function _e(s,t){await oa(As(X,Dt,s),{...t,updatedAt:yt()},{merge:!0})}const ir=[{id:"General",label:"General",icon:kt},{id:"Notifications",label:"Notifications",icon:ua},{id:"Gamification",label:"Gamification",icon:Ra},{id:"Content",label:"Content",icon:es},{id:"Model Config",label:"Model Configuration",icon:xt}],nr=({onDirtyChange:s})=>{const{userProfile:t}=Ee(),[i,r]=l.useState("General"),[h,n]=l.useState(et),[o,m]=l.useState(st),[v,p]=l.useState(tt),[S,f]=l.useState(at),[j,w]=l.useState(!1),[A,k]=l.useState(!1),[d,y]=l.useState(!1),[L,C]=l.useState(!1),[B,q]=l.useState(!1),[O,G]=l.useState(!1),[Y,_]=l.useState(!1),[ee,Q]=l.useState(!1);l.useEffect(()=>{t?.uid&&(w(!0),k(!0),y(!0),C(!0),Promise.all([Ge(Ks,et),Ge(Js,st),Ge(Zs,tt),Ge(Ys,at)]).then(([c,u,$,te])=>{n(c),m(u),p($),f(te)}).catch(c=>{console.error("[AdminSettings] Failed to load settings:",c),z.error("Failed to load admin settings")}).finally(()=>{w(!1),k(!1),y(!1),C(!1)}))},[t?.uid]);const ce=async()=>{q(!0);try{await _e(Ks,h),z.success("General settings saved")}catch(c){console.error("[AdminSettings] Failed to save general:",c),z.error("Failed to save general settings")}finally{q(!1)}},b=async()=>{G(!0);try{await _e(Js,o),z.success("Notification settings saved")}catch(c){console.error("[AdminSettings] Failed to save notifications:",c),z.error("Failed to save notification settings")}finally{G(!1)}},V=async()=>{_(!0);try{await _e(Zs,v),z.success("Gamification settings saved")}catch(c){console.error("[AdminSettings] Failed to save gamification:",c),z.error("Failed to save gamification settings")}finally{_(!1)}},x=async()=>{Q(!0);try{await _e(Ys,S),z.success("Content settings saved")}catch(c){console.error("[AdminSettings] Failed to save content:",c),z.error("Failed to save content settings")}finally{Q(!1)}},E=j||A||d||L;return e.jsx(U.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:"space-y-6",children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-12 gap-4 md:gap-6",children:[e.jsx("div",{className:"md:col-span-3",children:e.jsx("div",{className:"bg-white rounded-xl shadow-sm border border-[#dde3eb] overflow-hidden",children:e.jsx("nav",{className:"grid grid-cols-2 sm:grid-cols-3 md:flex md:flex-col py-2",children:ir.map(c=>{const u=c.icon,$=i===c.id;return e.jsxs("button",{onClick:()=>r(c.id),className:`flex items-center gap-3 px-4 py-3 text-sm font-medium transition-all relative ${$?"text-sky-600 bg-sky-50/50":"text-[#5a6578] hover:bg-[#edf1f7] hover:text-[#0a1628]"}`,children:[$&&e.jsx("div",{className:"absolute left-0 top-0 bottom-0 w-1 bg-sky-600 rounded-r-full"}),e.jsx(u,{size:18,className:$?"text-sky-600":"text-slate-500"}),c.label]},c.id)})})})}),e.jsx("div",{className:"md:col-span-9",children:e.jsx(U.div,{initial:{opacity:0},animate:{opacity:1},transition:{duration:.2},className:"space-y-6",children:e.jsx("div",{className:"bg-white rounded-xl shadow-sm border border-[#dde3eb] p-6",children:E?e.jsx("p",{className:"text-sm text-[#5a6578]",children:"Loading settings..."}):e.jsxs(e.Fragment,{children:[i==="General"&&e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-sm font-medium text-[#0a1628]",children:"Platform Name"}),e.jsx(R,{value:h.platformName,onChange:c=>n(u=>({...u,platformName:c.target.value})),className:"bg-white max-w-md"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-sm font-medium text-[#0a1628]",children:"School / Institution Name"}),e.jsx(R,{value:h.institutionName,onChange:c=>n(u=>({...u,institutionName:c.target.value})),placeholder:"Enter institution name",className:"bg-white max-w-md"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-sm font-medium text-[#0a1628]",children:"Logo URL"}),e.jsx(R,{value:h.logoUrl,onChange:c=>n(u=>({...u,logoUrl:c.target.value})),placeholder:"https://example.com/logo.png",className:"bg-white max-w-md"})]}),e.jsxs("div",{className:"mt-6 p-4 bg-red-50 border border-red-100 rounded-xl flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"p-2 bg-white rounded-lg text-red-600 shadow-sm border border-red-100",children:e.jsx(kt,{size:18})}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-red-900",children:"Maintenance Mode"}),e.jsx("p",{className:"text-xs text-red-700 mt-0.5",children:"Temporarily disable access for non-admins"})]})]}),e.jsx(be,{checked:h.maintenanceMode,onCheckedChange:c=>n(u=>({...u,maintenanceMode:c})),className:"data-[state=checked]:bg-red-600 data-[state=unchecked]:bg-[#dde3eb]"})]}),e.jsx("div",{className:"pt-4 border-t border-[#dde3eb] flex justify-end",children:e.jsxs(M,{className:`bg-sky-600 hover:bg-sky-700 text-white gap-2 ${B?"opacity-70 cursor-not-allowed":""}`,onClick:ce,disabled:B,children:[B&&e.jsx(H,{size:16,className:"animate-spin"}),B?"Saving...":"Save Changes"]})})]}),i==="Notifications"&&e.jsxs("div",{className:"space-y-5",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]",children:"Email Alerts on New User Registrations"}),e.jsx("p",{className:"text-xs text-slate-500",children:"Send email notification when a new user signs up"})]}),e.jsx(be,{checked:o.emailAlertsOnRegistration,onCheckedChange:c=>m(u=>({...u,emailAlertsOnRegistration:c})),className:"data-[state=checked]:bg-sky-600 data-[state=unchecked]:bg-[#dde3eb]"})]}),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]",children:"Alert on Quiz Completion Threshold"}),e.jsx("p",{className:"text-xs text-slate-500",children:"Notify when a student's quiz score crosses a threshold"})]}),e.jsx(be,{checked:o.alertOnQuizCompletionThreshold,onCheckedChange:c=>m(u=>({...u,alertOnQuizCompletionThreshold:c})),className:"data-[state=checked]:bg-sky-600 data-[state=unchecked]:bg-[#dde3eb]"})]}),o.alertOnQuizCompletionThreshold&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-sm font-medium text-[#0a1628]",children:"Threshold Percentage (%)"}),e.jsx(R,{type:"number",min:0,max:100,value:o.quizCompletionThresholdPercent,onChange:c=>m(u=>({...u,quizCompletionThresholdPercent:Number(c.target.value||0)})),className:"max-w-xs bg-white"})]}),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]",children:"Announcement Banner"}),e.jsx("p",{className:"text-xs text-slate-500",children:"Show a platform-wide banner message"})]}),e.jsx(be,{checked:o.announcementBannerEnabled,onCheckedChange:c=>m(u=>({...u,announcementBannerEnabled:c})),className:"data-[state=checked]:bg-sky-600 data-[state=unchecked]:bg-[#dde3eb]"})]}),o.announcementBannerEnabled&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-sm font-medium text-[#0a1628]",children:"Banner Message"}),e.jsx(R,{value:o.announcementBannerMessage,onChange:c=>m(u=>({...u,announcementBannerMessage:c.target.value})),placeholder:"Enter banner message text",className:"bg-white"})]}),e.jsx("div",{className:"pt-4 border-t border-[#dde3eb] flex justify-end",children:e.jsxs(M,{className:`bg-sky-600 hover:bg-sky-700 text-white gap-2 ${O?"opacity-70 cursor-not-allowed":""}`,onClick:b,disabled:O,children:[O&&e.jsx(H,{size:16,className:"animate-spin"}),O?"Saving...":"Save Changes"]})})]}),i==="Gamification"&&e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-sm font-medium text-[#0a1628]",children:"XP Earned per Correct Answer"}),e.jsx(R,{type:"number",min:0,value:v.xpPerCorrectAnswer,onChange:c=>p(u=>({...u,xpPerCorrectAnswer:Number(c.target.value||0)})),className:"max-w-xs bg-white"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-sm font-medium text-[#0a1628]",children:"XP Earned per Quiz Completion"}),e.jsx(R,{type:"number",min:0,value:v.xpPerQuizCompletion,onChange:c=>p(u=>({...u,xpPerQuizCompletion:Number(c.target.value||0)})),className:"max-w-xs bg-white"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-sm font-medium text-[#0a1628]",children:"Streak Bonus Multiplier"}),e.jsx(R,{type:"number",min:0,step:.1,value:v.streakBonusMultiplier,onChange:c=>p(u=>({...u,streakBonusMultiplier:Number(c.target.value||0)})),className:"max-w-xs bg-white"}),e.jsx("p",{className:"text-xs text-slate-500 mt-1",children:"Applied as a multiplier to streak XP rewards."})]}),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]",children:"Leaderboard Visibility"}),e.jsx("p",{className:"text-xs text-slate-500",children:"Show the leaderboard to students"})]}),e.jsx(be,{checked:v.leaderboardVisibility,onCheckedChange:c=>p(u=>({...u,leaderboardVisibility:c})),className:"data-[state=checked]:bg-sky-600 data-[state=unchecked]:bg-[#dde3eb]"})]}),e.jsx("div",{className:"pt-4 border-t border-[#dde3eb] flex justify-end",children:e.jsxs(M,{className:`bg-sky-600 hover:bg-sky-700 text-white gap-2 ${Y?"opacity-70 cursor-not-allowed":""}`,onClick:V,disabled:Y,children:[Y&&e.jsx(H,{size:16,className:"animate-spin"}),Y?"Saving...":"Save Changes"]})})]}),i==="Content"&&e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-sm font-medium text-[#0a1628]",children:"Default Quiz Time Limit (minutes)"}),e.jsx(R,{type:"number",min:1,value:S.defaultQuizTimeLimitMinutes,onChange:c=>f(u=>({...u,defaultQuizTimeLimitMinutes:Number(c.target.value||1)})),className:"max-w-xs bg-white"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-sm font-medium text-[#0a1628]",children:"Max Questions Per Quiz"}),e.jsx(R,{type:"number",min:1,value:S.maxQuestionsPerQuiz,onChange:c=>f(u=>({...u,maxQuestionsPerQuiz:Number(c.target.value||1)})),className:"max-w-xs bg-white"})]}),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]",children:"Allow Student Retries"}),e.jsx("p",{className:"text-xs text-slate-500",children:"Let students retry quizzes"})]}),e.jsx(be,{checked:S.allowStudentRetries,onCheckedChange:c=>f(u=>({...u,allowStudentRetries:c})),className:"data-[state=checked]:bg-sky-600 data-[state=unchecked]:bg-[#dde3eb]"})]}),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]",children:"Difficulty Auto-Adjustment"}),e.jsx("p",{className:"text-xs text-slate-500",children:"Automatically adjust quiz difficulty based on performance"})]}),e.jsx(be,{checked:S.difficultyAutoAdjustment,onCheckedChange:c=>f(u=>({...u,difficultyAutoAdjustment:c})),className:"data-[state=checked]:bg-sky-600 data-[state=unchecked]:bg-[#dde3eb]"})]}),e.jsx("div",{className:"pt-4 border-t border-[#dde3eb] flex justify-end",children:e.jsxs(M,{className:`bg-sky-600 hover:bg-sky-700 text-white gap-2 ${ee?"opacity-70 cursor-not-allowed":""}`,onClick:x,disabled:ee,children:[ee&&e.jsx(H,{size:16,className:"animate-spin"}),ee?"Saving...":"Save Changes"]})})]}),i==="Model Config"&&e.jsx(lr,{})]})})})})]})})};function He({className:s,...t}){return e.jsx(ha,{"data-slot":"checkbox",className:ke("peer border bg-input-background dark:bg-input/30 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=checked]:border-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive size-4 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",s),...t,children:e.jsx(ga,{"data-slot":"checkbox-indicator",className:"flex items-center justify-center text-current transition-none",children:e.jsx(pa,{className:"size-3.5"})})})}const dr=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,cr=/[A-Z]/,or=/[a-z]/,mr=/\d/,xr=/[^A-Za-z0-9]/;function ur(s){const t={};s.name.trim()||(t.name="Name is required.");const i=s.email.trim().toLowerCase();i?dr.test(i)||(t.email="Enter a valid email address."):t.email="Email is required.";const r=s.password;return r.length<8?t.password="Password must be at least 8 characters.":cr.test(r)?or.test(r)?mr.test(r)?xr.test(r)||(t.password="Password must include at least one special character."):t.password="Password must include at least one number.":t.password="Password must include at least one lowercase letter.":t.password="Password must include at least one uppercase letter.",s.confirmPassword?s.confirmPassword!==r&&(t.confirmPassword="Passwords do not match."):t.confirmPassword="Confirm password is required.",s.role.trim()||(t.role="Role is required."),s.status.trim()||(t.status="Status is required."),s.grade.trim()||(t.grade="Grade is required."),s.section.trim()||(t.section="Section is required."),s.role.trim().toLowerCase()==="student"&&!s.lrn.trim()&&(t.lrn="LRN is required for student accounts."),t}function hr(s){return Object.values(s).find(i=>!!i)??null}const rt=(s="Student")=>({name:"",email:"",password:"",confirmPassword:"",role:s,status:"Active",department:s==="Teacher"?"Mathematics":s==="Admin"?"System":"",grade:"Grade 11",section:"Section A",lrn:""}),gr=["10","25","50","100"];function lt(s,t){const i=s.trim();if(!(!i||i===t))return i}function it(s){const t=String(s??"");return/[",\n]/.test(t)?`"${t.replace(/"/g,'""')}"`:t}const pr=({createIntentRole:s=null,onCreateIntentConsumed:t})=>{const{userProfile:i}=Ee(),[r,h]=l.useState([]),[n,o]=l.useState(!0),[m,v]=l.useState(null),[p,S]=l.useState(!1),[f,j]=l.useState(!1),[w,A]=l.useState(null),[k,d]=l.useState(1),[y,L]=l.useState(25),[C,B]=l.useState(0),[q,O]=l.useState(1),[G,Y]=l.useState(!1),[_,ee]=l.useState(""),[Q,ce]=l.useState("All Roles"),[b,V]=l.useState("All Status"),[x,E]=l.useState(new Set),[c,u]=l.useState(!1),[$,te]=l.useState(new Set),[Ue,ns]=l.useState({}),[Ae,Tt]=l.useState("Student"),[ds,Lt]=l.useState("Active"),[cs,Mt]=l.useState("Grade 11"),[os,It]=l.useState("Section A"),[Rt,ze]=l.useState(!1),[Et,ms]=l.useState(!1),[$e,zs]=l.useState(!1),[xe,xs]=l.useState(null),[J,Ps]=l.useState(null),[D,ae]=l.useState({}),[us,Pe]=l.useState(!1),[hs,De]=l.useState(!1),[N,K]=l.useState(rt()),F=l.useMemo(()=>({search:_.trim()||void 0,role:lt(Q,"All Roles"),status:lt(b,"All Status")}),[_,Q,b]),ge=l.useCallback(()=>{E(new Set),u(!1),te(new Set)},[]),Fe=l.useCallback(a=>c?!$.has(a):x.has(a),[c,$,x]),W=l.useMemo(()=>c?Math.max(C-$.size,0):x.size,[c,$,x,C]),Ds=l.useMemo(()=>r.length===0?!1:r.every(a=>Fe(a.id)),[r,Fe]),ue=l.useMemo(()=>c?[]:Array.from(x).map(a=>Ue[a]).filter(a=>!!a),[c,x,Ue]),Ts=l.useMemo(()=>W===0?!1:c?!F.role||F.role.toLowerCase()==="student":ue.length!==x.size?!1:ue.every(a=>a.role==="Student"),[c,W,ue,x.size,F.role]),Ls=l.useMemo(()=>W===0?!1:c?F.status?.toLowerCase()!=="active":ue.length!==x.size?!1:ue.some(a=>a.status!=="Active"),[c,W,ue,x.size,F.status]),Ms=l.useMemo(()=>W===0?!1:c?F.status?.toLowerCase()!=="inactive":ue.length!==x.size?!1:ue.some(a=>a.status!=="Inactive"),[c,W,ue,x.size,F.status]),pe=l.useCallback(async a=>{o(!0),v(null);try{const g=await Ka({page:a,pageSize:y,searchQuery:F.search,roleFilter:F.role,statusFilter:F.status});h(g.users),d(g.total===0?1:g.page),B(g.total),O(g.totalPages||1),Y(g.hasNextPage),ns(I=>{const fe={...I};return g.users.forEach(T=>{fe[T.id]=T}),fe})}catch(g){const I=g instanceof Error?g.message:"Failed to load users";v(I),z.error(I)}finally{o(!1)}},[y,F.search,F.role,F.status]);l.useEffect(()=>{pe(k)},[pe,k]);const gs=l.useCallback((a="Student")=>{Ps(null),ae({}),Pe(!1),De(!1),K(rt(a)),ze(!0)},[]);l.useEffect(()=>{s&&(gs(s),t?.())},[s,gs,t]);const Is=l.useCallback(a=>{if(c){te(g=>{const I=new Set(g);return I.has(a)?I.delete(a):I.add(a),I});return}E(g=>{const I=new Set(g);return I.has(a)?I.delete(a):I.add(a),I})},[c]),Rs=l.useCallback(()=>{if(r.length===0)return;const a=r.map(g=>g.id);if(c){te(g=>{const I=new Set(g);return a.every(T=>!I.has(T))?a.forEach(T=>I.add(T)):a.forEach(T=>I.delete(T)),I});return}E(g=>{const I=new Set(g);return a.every(T=>I.has(T))?a.forEach(T=>I.delete(T)):a.forEach(T=>I.add(T)),I})},[r,c]),Ut=l.useCallback(()=>{u(!0),E(new Set),te(new Set)},[]),Es=l.useCallback(a=>{if(!a.length){z.info("No rows were returned for export.");return}const g=Array.from(a.reduce((qe,fs)=>(Object.keys(fs).forEach(Jt=>qe.add(Jt)),qe),new Set)),I=[g.map(it).join(","),...a.map(qe=>g.map(fs=>it(qe[fs])).join(","))].join(` +`),fe=new Blob([I],{type:"text/csv;charset=utf-8;"}),T=URL.createObjectURL(fe),ps=document.createElement("a");ps.href=T,ps.download=`admin-users-export-${Date.now()}.csv`,ps.click(),URL.revokeObjectURL(T)},[]),he=l.useCallback(async(a,g)=>{const I=g.userIds,fe={...F.search?{search:F.search}:{},...F.role?{role:F.role}:{},...F.status?{status:F.status}:{}};if(!I&&W===0){z.error("Select at least one user before applying a bulk action.");return}j(!0);try{const T=await Ya({action:a,...I?{userIds:I}:c?{userIds:[],excludeUserIds:Array.from($),filters:fe}:{userIds:Array.from(x)},...g.role?{role:g.role}:{},...g.status?{status:g.status}:{},...g.grade?{grade:g.grade}:{},...g.section?{section:g.section}:{},...g.exportFormat?{exportFormat:g.exportFormat}:{}});a==="export"&&Es(T.exportRows),T.summary.failed>0?z.warning(`Completed with partial failures. ${T.summary.succeeded} succeeded, ${T.summary.failed} failed, ${T.summary.skipped} skipped.`):z.success(`Action completed. ${T.summary.succeeded} user(s) updated.`),T.warnings.length>0&&z.info(T.warnings[0]),await js(g.auditAction,"User",a==="delete"||a==="deactivate"?"Warning":"Info",`${g.auditDetail}; targeted=${T.summary.targeted}, succeeded=${T.summary.succeeded}, failed=${T.summary.failed}, skipped=${T.summary.skipped}`,{name:i?.name||"Admin",role:"Admin",avatar:i?.photo||null}),g.skipSelectionReset||ge(),await pe(k)}catch(T){z.error(T instanceof Error?T.message:"Bulk action failed")}finally{j(!1)}},[F.search,F.role,F.status,c,$,x,W,i?.name,i?.photo,ge,pe,k,Es]),Be=l.useCallback(a=>{xs(a),ms(!0)},[]),$t=l.useCallback(async()=>{if(!(!xe||$e)){zs(!0);try{await he(xe.action,{...xe.params||{},auditAction:xe.auditAction,auditDetail:xe.auditDetail}),ms(!1),xs(null)}finally{zs(!1)}}},[xe,$e,he]),Us=a=>{Ps(a),ae({}),Pe(!1),De(!1),K({name:a.name,email:a.email,password:"",confirmPassword:"",role:a.role,status:a.status,department:a.department,grade:a.grade||"Grade 11",section:a.section||"Section A",lrn:a.lrn||""}),ze(!0)},Ft=async()=>{if(!N.name.trim()||!N.email.trim()){z.error("Name and email are required");return}if(!J){const a=ur({name:N.name,email:N.email,password:N.password,confirmPassword:N.confirmPassword,role:N.role,status:N.status,grade:N.grade,section:N.section,lrn:N.lrn}),g=hr(a);if(g){ae(a),z.error(g);return}}S(!0);try{if(J){const a={name:N.name,role:N.role,status:N.status,grade:N.grade,section:N.section,lrn:N.role==="Student"?N.lrn:void 0};N.role!=="Student"&&(a.department=N.department),await Ja(J.id,a),await js("User Updated","User","Info",`Updated user: ${N.name} (${J.email})`,{name:i?.name||"Admin",role:"Admin",avatar:i?.photo||null}),z.success("User updated successfully")}else{const a=await Za({email:N.email,name:N.name,password:N.password,confirmPassword:N.confirmPassword,role:N.role,status:N.status,grade:N.grade,section:N.section,lrn:N.role==="Student"?N.lrn:void 0});await js("Created New User","User","Info",`Created new ${N.role.toLowerCase()} account: ${N.name} (${N.email}), emailSent=${a.emailSent}`,{name:i?.name||"Admin",role:"Admin",avatar:i?.photo||null}),a.emailSent?z.success("User created and welcome email sent"):(z.warning("User created, but welcome email failed to send"),a.emailError?.message&&z.error(a.emailError.message))}J?await pe(k):(ge(),d(1),await pe(1)),ze(!1),Pe(!1),De(!1)}finally{S(!1)}},$s=(a,g)=>{Be({title:"Delete User?",message:`Delete user "${g}"? This cannot be undone.`,confirmText:"Delete",action:"delete",params:{userIds:[a]},auditAction:"User Deleted",auditDetail:`Deleted user account: ${g}`})},Fs=async a=>{if(w||f)return;if(a.status==="Active"){Be({title:"Deactivate User?",message:`Deactivate "${a.name}"? They will lose access until reactivated.`,confirmText:"Deactivate",action:"deactivate",params:{userIds:[a.id]},auditAction:"User Status Changed",auditDetail:`Deactivated user: ${a.email}`});return}A(a.id);try{await he("activate",{userIds:[a.id],auditAction:"User Status Changed",auditDetail:`Activated user: ${a.email}`,skipSelectionReset:!0})}finally{A(null)}},Bt=async()=>{await he("change_role",{role:Ae,auditAction:"Bulk Role Update",auditDetail:`Updated selected users to role ${Ae}`})},qt=async()=>{await he("change_status",{status:ds,auditAction:"Bulk Status Update",auditDetail:`Updated selected users to status ${ds}`})},Ot=async()=>{if(!Ts){z.error("Class/section assignment is only available for student selections.");return}await he("assign_class_section",{grade:cs,section:os,auditAction:"Bulk Class Assignment",auditDetail:`Assigned class section ${cs} - ${os}`})},Gt=async()=>{await he("reset_password_email",{auditAction:"Bulk Password Reset",auditDetail:"Sent password reset emails to selected users"})},_t=async()=>{await he("export",{exportFormat:"csv",auditAction:"Bulk Export Users",auditDetail:"Exported selected users"})},Ht=()=>{Ls&&he("activate",{auditAction:"Bulk User Activation",auditDetail:"Activated selected users"})},Qt=()=>{Ms&&Be({title:"Deactivate Selected Users?",message:`Deactivate ${W} selected user(s)? They will lose access until reactivated.`,confirmText:"Deactivate Users",action:"deactivate",auditAction:"Bulk User Deactivation",auditDetail:`Deactivated ${W} selected users`})},Vt=()=>{Be({title:"Delete Selected Users?",message:`Delete ${W} selected user(s)? This action cannot be undone.`,confirmText:"Delete Users",action:"delete",auditAction:"Bulk User Deletion",auditDetail:`Deleted ${W} selected users`})},Wt=[{label:"Total Users",value:C,color:"text-[#0a1628]"},{label:"Active (Page)",value:r.filter(a=>a.status==="Active").length,color:"text-green-600"},{label:"Admins (Page)",value:r.filter(a=>a.role==="Admin").length,color:"text-sky-600"},{label:"Teachers (Page)",value:r.filter(a=>a.role==="Teacher").length,color:"text-sky-600"},{label:"Students (Page)",value:r.filter(a=>a.role==="Student").length,color:"text-emerald-600"}],Xt=C===0?0:(k-1)*y+1,Kt=C===0?0:Math.min(k*y,C);return e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 md:grid-cols-5 gap-4",children:n?Array.from({length:5}).map((a,g)=>e.jsxs("div",{className:"bg-white p-4 rounded-xl border border-[#dde3eb] shadow-sm",children:[e.jsx("div",{className:"h-7 w-16 bg-[#edf1f7] rounded animate-pulse mb-2"}),e.jsx("div",{className:"h-4 w-24 bg-[#edf1f7] rounded animate-pulse"})]},`stats-skeleton-${g}`)):Wt.map((a,g)=>e.jsxs("div",{className:"bg-white p-4 rounded-xl border border-[#dde3eb] shadow-sm",children:[e.jsx("h3",{className:`text-2xl font-bold ${a.color}`,children:a.value}),e.jsx("p",{className:"text-sm text-[#5a6578]",children:a.label})]},g))}),e.jsxs("div",{className:"bg-white p-4 rounded-xl border border-[#dde3eb] shadow-sm space-y-4",children:[e.jsxs("div",{className:"relative",children:[e.jsx(St,{className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-500",size:18}),e.jsx(R,{placeholder:"Search users by name or email...",className:"pl-10 bg-[#edf1f7] border-[#dde3eb]",value:_,onChange:a=>{ee(a.target.value),d(1),ge()}})]}),e.jsxs("div",{className:"flex flex-col md:flex-row justify-between gap-4",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3",children:[e.jsxs(re,{value:Q,onValueChange:a=>{ce(a),d(1),ge()},children:[e.jsx(le,{className:"w-full sm:w-[140px] bg-[#edf1f7] border-[#dde3eb]",children:e.jsx(ie,{placeholder:"All Roles"})}),e.jsxs(ne,{children:[e.jsx(P,{value:"All Roles",children:"All Roles"}),e.jsx(P,{value:"Admin",children:"Admin"}),e.jsx(P,{value:"Teacher",children:"Teacher"}),e.jsx(P,{value:"Student",children:"Student"})]})]}),e.jsxs(re,{value:b,onValueChange:a=>{V(a),d(1),ge()},children:[e.jsx(le,{className:"w-full sm:w-[140px] bg-[#edf1f7] border-[#dde3eb]",children:e.jsx(ie,{placeholder:"All Status"})}),e.jsxs(ne,{children:[e.jsx(P,{value:"All Status",children:"All Status"}),e.jsx(P,{value:"Active",children:"Active"}),e.jsx(P,{value:"Inactive",children:"Inactive"})]})]}),e.jsxs(re,{value:String(y),onValueChange:a=>{const g=Number(a);Number.isNaN(g)||(L(g),d(1),ge())},children:[e.jsx(le,{className:"w-full sm:w-[150px] bg-[#edf1f7] border-[#dde3eb]",children:e.jsx(ie,{placeholder:"Rows per page"})}),e.jsx(ne,{children:gr.map(a=>e.jsxs(P,{value:a,children:[a," / page"]},a))})]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3",children:[e.jsxs(M,{variant:"outline",className:"gap-2 border-[#dde3eb] text-[#5a6578]",onClick:()=>pe(k),disabled:n||f,children:[e.jsx(Re,{size:16}),"Refresh"]}),e.jsxs(M,{className:"gap-2 bg-sky-500 hover:bg-sky-600 text-white",onClick:()=>gs(),disabled:f,children:[e.jsx(fa,{size:16}),"Add User"]})]})]}),W>0?e.jsxs("div",{className:"border-t border-[#dde3eb] pt-4 space-y-3",children:[e.jsxs("div",{className:"flex flex-col lg:flex-row lg:items-center lg:justify-between gap-3",children:[e.jsxs("div",{className:"text-sm text-[#5a6578]",children:[e.jsx("span",{className:"font-semibold text-[#0a1628]",children:W})," user(s) selected",c?" across filtered results":""]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[!c&&W>0&&WTt(a),children:[e.jsx(le,{className:"bg-[#edf1f7] border-[#dde3eb] sm:w-[160px]",children:e.jsx(ie,{placeholder:"Role target"})}),e.jsxs(ne,{children:[e.jsx(P,{value:"Student",children:"Student"}),e.jsx(P,{value:"Teacher",children:"Teacher"}),e.jsx(P,{value:"Admin",children:"Admin"})]})]}),e.jsx(M,{variant:"outline",size:"sm",className:"border-[#dde3eb]",onClick:()=>void Bt(),disabled:f,children:"Change Role"})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[e.jsxs(re,{value:ds,onValueChange:a=>Lt(a),children:[e.jsx(le,{className:"bg-[#edf1f7] border-[#dde3eb] sm:w-[160px]",children:e.jsx(ie,{placeholder:"Status target"})}),e.jsxs(ne,{children:[e.jsx(P,{value:"Active",children:"Active"}),e.jsx(P,{value:"Inactive",children:"Inactive"})]})]}),e.jsx(M,{variant:"outline",size:"sm",className:"border-[#dde3eb]",onClick:()=>void qt(),disabled:f,children:"Change Status"})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[e.jsx(R,{value:cs,onChange:a=>Mt(a.target.value),className:"bg-[#edf1f7] border-[#dde3eb] sm:w-[140px]",placeholder:"Grade"}),e.jsx(R,{value:os,onChange:a=>It(a.target.value),className:"bg-[#edf1f7] border-[#dde3eb] sm:w-[140px]",placeholder:"Section"}),e.jsx(M,{variant:"outline",size:"sm",className:"border-[#dde3eb]",onClick:()=>void Ot(),disabled:f||!Ts,children:"Assign Class"})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(M,{variant:"outline",size:"sm",className:"border-[#dde3eb]",onClick:Ht,disabled:f||!Ls,children:[e.jsx(Xs,{size:14,className:"mr-2"}),"Activate"]}),e.jsxs(M,{variant:"outline",size:"sm",className:"border-[#dde3eb]",onClick:Qt,disabled:f||!Ms,children:[e.jsx(Vs,{size:14,className:"mr-2"}),"Deactivate"]}),e.jsxs(M,{variant:"outline",size:"sm",className:"border-[#dde3eb]",onClick:()=>void Gt(),disabled:f,children:[e.jsx(ja,{size:14,className:"mr-2"}),"Send Reset Email"]}),e.jsxs(M,{variant:"outline",size:"sm",className:"border-[#dde3eb]",onClick:()=>void _t(),disabled:f,children:[e.jsx(Ct,{size:14,className:"mr-2"}),"Export Selection"]}),e.jsxs(M,{variant:"destructive",size:"sm",onClick:Vt,disabled:f,children:[e.jsx(Qs,{size:14,className:"mr-2"}),"Delete"]})]})]}):null]}),m?e.jsxs("div",{className:"rounded-xl border border-red-200 bg-red-50 px-4 py-3 flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex items-start gap-2 min-w-0",children:[e.jsx(Se,{size:18,className:"text-red-600 mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-semibold text-red-700",children:"Unable to load users"}),e.jsx("p",{className:"text-sm text-red-600 break-words",children:m})]})]}),e.jsx(M,{type:"button",variant:"outline",className:"border-red-200 text-red-700 hover:bg-red-100",onClick:()=>pe(k),disabled:n||f,children:"Retry"})]}):null,e.jsxs("div",{className:"bg-white rounded-xl border border-[#dde3eb] shadow-sm overflow-hidden",children:[e.jsxs("div",{className:"md:hidden divide-y divide-[#dde3eb]",children:[e.jsxs("div",{className:"px-4 py-3 bg-[#edf1f7] border-b border-[#dde3eb] flex items-center justify-between",children:[e.jsxs("label",{className:"flex items-center gap-2 text-xs text-[#5a6578]",children:[e.jsx(He,{checked:Ds,onCheckedChange:Rs}),"Select visible (",r.length,")"]}),e.jsxs("span",{className:"text-xs text-[#5a6578]",children:["Page ",k," / ",q]})]}),n&&r.length===0?e.jsx("div",{className:"px-6 py-10 text-center text-[#5a6578]",children:"Loading users..."}):r.length>0?r.map(a=>{const g=w===a.id;return e.jsxs("div",{className:"p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(He,{checked:Fe(a.id),onCheckedChange:()=>Is(a.id)}),e.jsxs(qs,{children:[e.jsx(Os,{src:a.photo}),e.jsx(Gs,{children:a.name.charAt(0)})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-semibold text-[#0a1628] truncate",children:a.name}),e.jsx("p",{className:"text-xs text-[#5a6578] truncate",children:a.email})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-xs",children:[e.jsxs("div",{className:"rounded-lg bg-[#edf1f7] px-2 py-1.5 text-[#5a6578]",children:["Role: ",e.jsx("span",{className:"font-semibold text-[#0a1628]",children:a.role})]}),e.jsxs("div",{className:"rounded-lg bg-[#edf1f7] px-2 py-1.5 text-[#5a6578]",children:["Status: ",e.jsx("span",{className:"font-semibold text-[#0a1628]",children:a.status})]}),e.jsxs("div",{className:"rounded-lg bg-[#edf1f7] px-2 py-1.5 text-[#5a6578] col-span-2",children:["Last Login: ",e.jsx("span",{className:"font-semibold text-[#0a1628]",children:a.lastLogin||"Never"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>Us(a),"aria-label":`Edit ${a.name}`,className:"px-3 py-2 rounded-lg border border-[#dde3eb] text-[#5a6578] hover:bg-[#edf1f7]",children:"Edit"}),e.jsx("button",{type:"button",onClick:()=>Fs(a),"aria-label":a.status==="Active"?`Deactivate ${a.name}`:`Activate ${a.name}`,disabled:g||f,className:"px-3 py-2 rounded-lg border border-[#dde3eb] text-[#5a6578] disabled:opacity-60 disabled:cursor-not-allowed",children:g?"Updating...":a.status==="Active"?"Deactivate":"Activate"}),e.jsx("button",{type:"button",onClick:()=>$s(a.id,a.name),"aria-label":`Delete ${a.name}`,disabled:f,className:"px-3 py-2 rounded-lg border border-red-200 text-red-600 disabled:opacity-60 disabled:cursor-not-allowed",children:"Delete"})]})]},`mobile-${a.id}`)}):m?e.jsx("div",{className:"px-6 py-12 text-center text-red-600",children:e.jsxs("div",{className:"flex flex-col items-center gap-3",children:[e.jsx(Se,{size:24,className:"text-red-500"}),e.jsx("p",{children:"Users could not be loaded."})]})}):e.jsx("div",{className:"px-6 py-12 text-center text-[#5a6578]",children:e.jsxs("div",{className:"flex flex-col items-center gap-3",children:[e.jsx("div",{className:"p-3 bg-[#edf1f7] rounded-full",children:e.jsx(Ze,{size:24,className:"text-slate-500"})}),e.jsx("p",{children:"No users found matching your filters"})]})})]}),e.jsx("div",{className:"hidden md:block overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm text-left",children:[e.jsx("thead",{className:"text-xs text-[#5a6578] uppercase bg-[#edf1f7] border-b border-[#dde3eb]",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-4 font-semibold w-[56px]",children:e.jsx(He,{checked:Ds,onCheckedChange:Rs})}),e.jsx("th",{className:"px-6 py-4 font-semibold",children:"User"}),e.jsx("th",{className:"px-6 py-4 font-semibold",children:"Role"}),e.jsx("th",{className:"px-6 py-4 font-semibold",children:"Status"}),e.jsx("th",{className:"px-6 py-4 font-semibold",children:"Class/Department"}),e.jsx("th",{className:"px-6 py-4 font-semibold",children:"Last Login"}),e.jsx("th",{className:"px-6 py-4 font-semibold text-right",children:"Actions"})]})}),e.jsx("tbody",{className:"divide-y divide-[#dde3eb]",children:n&&r.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"px-6 py-12 text-center text-[#5a6578]",children:"Loading users..."})}):r.length>0?r.map(a=>{const g=w===a.id;return e.jsxs("tr",{className:"hover:bg-[#edf1f7]/50 transition-colors",children:[e.jsx("td",{className:"px-4 py-4",children:e.jsx(He,{checked:Fe(a.id),onCheckedChange:()=>Is(a.id)})}),e.jsx("td",{className:"px-6 py-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs(qs,{children:[e.jsx(Os,{src:a.photo}),e.jsx(Gs,{children:a.name.charAt(0)})]}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-[#0a1628]",children:a.name}),e.jsx("p",{className:"text-xs text-[#5a6578]",children:a.email})]})]})}),e.jsx("td",{className:"px-6 py-4",children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[a.role==="Admin"&&e.jsx(Je,{size:14,className:"text-sky-600"}),a.role==="Teacher"&&e.jsx(Cs,{size:14,className:"text-sky-600"}),a.role==="Student"&&e.jsx(qa,{size:14,className:"text-emerald-600"}),e.jsx("span",{className:` font-medium text-xs px-2 py-0.5 rounded-full ${a.role==="Admin"?"bg-sky-100 text-sky-700":""} ${a.role==="Teacher"?"bg-sky-100 text-sky-700":""} @@ -66,4 +61,4 @@ import{r as i,d as Jt,j as e}from"./vendor-react-B4AQeu28.js";import Fs from"./S `,children:a.role})]})}),e.jsx("td",{className:"px-6 py-4",children:e.jsxs("span",{className:` inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium border ${a.status==="Active"?"bg-green-50 text-green-700 border-green-200":"bg-[#edf1f7] text-[#5a6578] border-[#dde3eb]"} - `,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${a.status==="Active"?"bg-green-500":"bg-[#a8a5b3]"}`}),a.status]})}),e.jsx("td",{className:"px-6 py-4 text-[#5a6578]",children:a.role==="Student"&&a.classSection||a.department}),e.jsx("td",{className:"px-6 py-4 text-[#5a6578]",children:a.lastLogin||"Never"}),e.jsx("td",{className:"px-6 py-4 text-right",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:()=>Es(a),"aria-label":`Edit ${a.name}`,className:"p-1.5 text-slate-500 hover:text-sky-600 hover:bg-sky-50 rounded-lg transition-colors",children:e.jsx(Va,{size:16})}),e.jsx("button",{type:"button",onClick:()=>$s(a),"aria-label":a.status==="Active"?`Deactivate ${a.name}`:`Activate ${a.name}`,disabled:g||f,className:`p-1.5 rounded-lg transition-colors ${g?"opacity-60 cursor-not-allowed":""} ${a.status==="Active"?"text-slate-500 hover:text-orange-600 hover:bg-orange-50":"text-orange-500 hover:text-green-600 hover:bg-green-50"}`,title:a.status==="Active"?"Deactivate User":"Activate User",children:g?e.jsx(_,{size:16,className:"animate-spin"}):a.status==="Active"?e.jsx(Vs,{size:16}):e.jsx(Xs,{size:16})}),e.jsx("button",{type:"button",onClick:()=>Us(a.id,a.name),"aria-label":`Delete ${a.name}`,disabled:f,className:"p-1.5 text-slate-500 hover:text-red-600 hover:bg-red-50 rounded-lg transition-colors",children:e.jsx(Qs,{size:16})})]})})]},a.id)}):m?e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"px-6 py-12 text-center text-red-600",children:e.jsxs("div",{className:"flex flex-col items-center gap-3",children:[e.jsx(Se,{size:24,className:"text-red-500"}),e.jsx("p",{children:"Users could not be loaded."})]})})}):e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"px-6 py-12 text-center text-[#5a6578]",children:e.jsxs("div",{className:"flex flex-col items-center gap-3",children:[e.jsx("div",{className:"p-3 bg-[#edf1f7] rounded-full",children:e.jsx(Je,{size:24,className:"text-slate-500"})}),e.jsx("p",{children:"No users found matching your filters"})]})})})})]})})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3 px-1",children:[e.jsxs("p",{className:"text-sm text-[#5a6578]",children:["Showing ",e.jsxs("span",{className:"font-semibold text-[#0a1628]",children:[Wt,"-",Xt]})," of"," ",e.jsx("span",{className:"font-semibold text-[#0a1628]",children:C})," users"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(M,{variant:"outline",size:"sm",className:"border-[#dde3eb]",disabled:k<=1||n||f,onClick:()=>d(a=>Math.max(a-1,1)),children:"Previous"}),e.jsxs("span",{className:"text-xs text-[#5a6578] min-w-[72px] text-center",children:["Page ",k," / ",Math.max(q,1)]}),e.jsx(M,{variant:"outline",size:"sm",className:"border-[#dde3eb]",disabled:!G||n||f||k>=q,onClick:()=>d(a=>Math.min(a+1,q||1)),children:"Next"})]})]}),e.jsx(gt,{open:It,onOpenChange:Ae,children:e.jsxs(pt,{className:"sm:max-w-[425px]",children:[e.jsxs(ft,{children:[e.jsx(bt,{children:J?"Edit User Access":"Add New User"}),e.jsx(jt,{children:J?"Update user details and manage access permissions.":"Create a new account and send welcome credentials by email."})]}),e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsxs("div",{className:"grid gap-2 sm:grid-cols-4 sm:items-start sm:gap-4",children:[e.jsx("label",{htmlFor:"name",className:"text-left sm:text-right text-sm font-medium text-[#0a1628]",children:"Name"}),e.jsxs("div",{className:"sm:col-span-3",children:[e.jsx(R,{id:"name",value:N.name,onChange:a=>{K({...N,name:a.target.value}),D.name&&ae(g=>({...g,name:void 0}))},className:D.name?"border-red-500 focus-visible:ring-red-500":""}),D.name?e.jsx("p",{className:"mt-1 text-xs text-red-600",children:D.name}):null]})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-4 sm:items-start sm:gap-4",children:[e.jsx("label",{htmlFor:"email",className:"text-left sm:text-right text-sm font-medium text-[#0a1628]",children:"Email"}),e.jsxs("div",{className:"sm:col-span-3",children:[e.jsx(R,{id:"email",type:"email",value:N.email,onChange:a=>{J||(K({...N,email:a.target.value}),D.email&&ae(g=>({...g,email:void 0})))},readOnly:!!J,"aria-readonly":!!J,className:`${D.email?"border-red-500 focus-visible:ring-red-500":""} ${J?"bg-[#edf1f7] text-[#5a6578] cursor-not-allowed":""}`}),D.email?e.jsx("p",{className:"mt-1 text-xs text-red-600",children:D.email}):null,J?e.jsx("p",{className:"mt-1 text-xs text-[#5a6578]",children:"Email changes are disabled because authentication email updates are not supported in this panel."}):null]})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-4 sm:items-start sm:gap-4",children:[e.jsx("label",{htmlFor:"role",className:"text-left sm:text-right text-sm font-medium text-[#0a1628]",children:"Role"}),e.jsxs("div",{className:"sm:col-span-3",children:[e.jsxs(re,{value:N.role,onValueChange:a=>{K({...N,role:a,lrn:a==="Student"?N.lrn:""}),ae(g=>({...g,role:void 0,lrn:void 0}))},children:[e.jsx(ie,{className:D.role?"border-red-500 focus:ring-red-500":"",children:e.jsx(le,{placeholder:"Select role"})}),e.jsxs(ne,{children:[e.jsx(P,{value:"Student",children:"Student"}),e.jsx(P,{value:"Teacher",children:"Teacher"}),e.jsx(P,{value:"Admin",children:"Admin"})]})]}),D.role?e.jsx("p",{className:"mt-1 text-xs text-red-600",children:D.role}):null]})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-4 sm:items-start sm:gap-4",children:[e.jsx("label",{htmlFor:"status",className:"text-left sm:text-right text-sm font-medium text-[#0a1628]",children:"Status"}),e.jsxs("div",{className:"sm:col-span-3",children:[e.jsxs(re,{value:N.status,onValueChange:a=>{K({...N,status:a}),D.status&&ae(g=>({...g,status:void 0}))},children:[e.jsx(ie,{className:D.status?"border-red-500 focus:ring-red-500":"",children:e.jsx(le,{placeholder:"Select status"})}),e.jsxs(ne,{children:[e.jsx(P,{value:"Active",children:"Active"}),e.jsx(P,{value:"Inactive",children:"Inactive"})]})]}),D.status?e.jsx("p",{className:"mt-1 text-xs text-red-600",children:D.status}):null]})]}),J?N.role==="Student"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-2 sm:grid-cols-4 sm:items-center sm:gap-4",children:[e.jsx("label",{htmlFor:"lrn",className:"text-left sm:text-right text-sm font-medium text-[#0a1628]",children:"LRN"}),e.jsx(R,{id:"lrn",value:N.lrn,onChange:a=>K({...N,lrn:a.target.value}),placeholder:"12-digit learner reference",className:"sm:col-span-3"})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-4 sm:items-center sm:gap-4",children:[e.jsx("label",{htmlFor:"grade",className:"text-left sm:text-right text-sm font-medium text-[#0a1628]",children:"Grade"}),e.jsx(R,{id:"grade",value:N.grade,onChange:a=>K({...N,grade:a.target.value}),placeholder:"e.g. Grade 11",className:"sm:col-span-3"})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-4 sm:items-center sm:gap-4",children:[e.jsx("label",{htmlFor:"section",className:"text-left sm:text-right text-sm font-medium text-[#0a1628]",children:"Section"}),e.jsx(R,{id:"section",value:N.section,onChange:a=>K({...N,section:a.target.value}),placeholder:"e.g. STEM A",className:"sm:col-span-3"})]})]}):e.jsxs("div",{className:"grid gap-2 sm:grid-cols-4 sm:items-center sm:gap-4",children:[e.jsx("label",{htmlFor:"department",className:"text-left sm:text-right text-sm font-medium text-[#0a1628]",children:"Department"}),e.jsx(R,{id:"department",value:N.department,onChange:a=>K({...N,department:a.target.value}),placeholder:"e.g. Mathematics",className:"sm:col-span-3"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-2 sm:grid-cols-4 sm:items-start sm:gap-4",children:[e.jsx("label",{htmlFor:"grade",className:"text-left sm:text-right text-sm font-medium text-[#0a1628]",children:"Grade"}),e.jsxs("div",{className:"sm:col-span-3",children:[e.jsx(R,{id:"grade",value:N.grade,onChange:a=>{K({...N,grade:a.target.value}),D.grade&&ae(g=>({...g,grade:void 0}))},placeholder:"e.g. Grade 11",className:D.grade?"border-red-500 focus-visible:ring-red-500":""}),D.grade?e.jsx("p",{className:"mt-1 text-xs text-red-600",children:D.grade}):null]})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-4 sm:items-start sm:gap-4",children:[e.jsx("label",{htmlFor:"section",className:"text-left sm:text-right text-sm font-medium text-[#0a1628]",children:"Section"}),e.jsxs("div",{className:"sm:col-span-3",children:[e.jsx(R,{id:"section",value:N.section,onChange:a=>{K({...N,section:a.target.value}),D.section&&ae(g=>({...g,section:void 0}))},placeholder:"e.g. STEM A",className:D.section?"border-red-500 focus-visible:ring-red-500":""}),D.section?e.jsx("p",{className:"mt-1 text-xs text-red-600",children:D.section}):null]})]}),N.role==="Student"?e.jsxs("div",{className:"grid gap-2 sm:grid-cols-4 sm:items-start sm:gap-4",children:[e.jsx("label",{htmlFor:"lrn",className:"text-left sm:text-right text-sm font-medium text-[#0a1628]",children:"LRN"}),e.jsxs("div",{className:"sm:col-span-3",children:[e.jsx(R,{id:"lrn",value:N.lrn,onChange:a=>{K({...N,lrn:a.target.value}),D.lrn&&ae(g=>({...g,lrn:void 0}))},placeholder:"Required for student accounts",className:D.lrn?"border-red-500 focus-visible:ring-red-500":""}),D.lrn?e.jsx("p",{className:"mt-1 text-xs text-red-600",children:D.lrn}):null]})]}):null,e.jsxs("div",{className:"grid gap-2 sm:grid-cols-4 sm:items-start sm:gap-4",children:[e.jsx("label",{htmlFor:"password",className:"text-left sm:text-right text-sm font-medium text-[#0a1628]",children:"Password"}),e.jsxs("div",{className:"sm:col-span-3 relative",children:[e.jsx(R,{id:"password",type:xs?"text":"password",value:N.password,onChange:a=>{K({...N,password:a.target.value}),D.password&&ae(g=>({...g,password:void 0}))},placeholder:"Min 8 chars, upper/lowercase, number, and symbol",className:D.password?"border-red-500 focus-visible:ring-red-500 pr-10 ":"pr-10 "}),e.jsx("button",{type:"button",onClick:()=>ze(!xs),className:"absolute right-3 top-1/2 -translate-y-1/2 text-slate-400 hover:text-slate-600 transition-colors",tabIndex:-1,children:xs?e.jsx(as,{size:16}):e.jsx(_s,{size:16})}),D.password?e.jsx("p",{className:"mt-1 text-xs text-red-600",children:D.password}):null]})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-4 sm:items-start sm:gap-4",children:[e.jsx("label",{htmlFor:"confirmPassword",className:"text-left sm:text-right text-sm font-medium text-[#0a1628]",children:"Confirm"}),e.jsxs("div",{className:"sm:col-span-3 relative",children:[e.jsx(R,{id:"confirmPassword",type:us?"text":"password",value:N.confirmPassword,onChange:a=>{K({...N,confirmPassword:a.target.value}),D.confirmPassword&&ae(g=>({...g,confirmPassword:void 0}))},placeholder:"Retype password",className:D.confirmPassword?"border-red-500 focus-visible:ring-red-500 pr-10 ":"pr-10 "}),e.jsx("button",{type:"button",onClick:()=>Pe(!us),className:"absolute right-3 top-1/2 -translate-y-1/2 text-slate-400 hover:text-slate-600 transition-colors",tabIndex:-1,children:us?e.jsx(as,{size:16}):e.jsx(_s,{size:16})}),D.confirmPassword?e.jsx("p",{className:"mt-1 text-xs text-red-600",children:D.confirmPassword}):null]})]})]})]}),e.jsxs(ma,{children:[e.jsx(M,{variant:"outline",onClick:()=>{Ae(!1),ze(!1),Pe(!1)},disabled:p,children:"Cancel"}),e.jsxs(M,{onClick:$t,className:"bg-sky-600 hover:bg-sky-700 text-white",disabled:p,children:[p?e.jsx(_,{size:16,className:"animate-spin mr-2"}):null,J?"Save Changes":"Create User & Send Email"]})]})]})}),e.jsx(vs,{isOpen:Rt,onClose:()=>{Ue||(os(!1),ms(null))},onConfirm:Ut,title:xe?.title||"Confirm Action",message:xe?.message||"Proceed with this action?",confirmText:Ue?"Processing...":xe?.confirmText||"Confirm",cancelText:"Cancel",type:"danger",icon:"delete"})]})},Le=({icon:s,title:t,subtitle:l})=>e.jsxs("div",{className:"flex flex-col items-center justify-center gap-3 py-10 text-center",children:[e.jsx("div",{className:"w-12 h-12 rounded-full bg-[#edf1f7] flex items-center justify-center",children:s}),e.jsx("p",{className:"text-sm font-semibold text-[#5a6578]",children:t}),l&&e.jsx("p",{className:"text-xs text-[#a0aec0] max-w-xs",children:l})]}),Nr=()=>{const[s,t]=i.useState("30d"),[l,r]=i.useState(null),[h,n]=i.useState(!0);i.useEffect(()=>{lr().then(r).catch(console.error).finally(()=>n(!1))},[]);const o={"7d":"Last 7 Days","30d":"Last 30 Days","90d":"Last 90 Days","12m":"Last 12 Months"},m=[{label:"Total Active Users",value:h?null:(l?.totalActiveUsers??0).toLocaleString(),icon:Je,color:"from-sky-500 to-blue-600"},{label:"Avg. Completion Rate",value:"N/A",icon:xt,color:"from-teal-500 to-emerald-600"},{label:"Avg. Session Duration",value:"N/A",icon:Ct,color:"from-violet-500 to-purple-600"},{label:"At-Risk Students",value:h?null:(l?.atRiskStudents??0).toString(),icon:Ss,color:"from-rose-500 to-orange-600"}],v=[{label:"Achievements Unlocked",icon:Ze,color:"text-rose-600",bg:"bg-rose-50",value:h?null:(l?.achievementsUnlocked??0).toLocaleString()},{label:"XP Earned (Platform)",icon:mt,color:"text-violet-600",bg:"bg-violet-50",value:h?null:(l?.totalXPEarned??0)>=1e6?`${((l?.totalXPEarned??0)/1e6).toFixed(1)}M`:(l?.totalXPEarned??0)>=1e3?`${Math.round((l?.totalXPEarned??0)/1e3)}K`:(l?.totalXPEarned??0).toLocaleString()},{label:"Active Streaks",icon:ut,color:"text-orange-600",bg:"bg-orange-50",value:h?null:(l?.activeStreaks??0).toLocaleString()},{label:"AI Tutor Sessions",icon:ta,color:"text-sky-600",bg:"bg-sky-50",value:h?null:(l?.aiTutorSessions??0).toLocaleString()}];return e.jsxs("div",{className:"space-y-6",children:[e.jsxs(U.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.3},className:"flex items-center justify-between",children:[e.jsx("div",{className:"flex items-center gap-2 bg-white rounded-xl p-1 shadow-sm border border-[#dde3eb]",children:Object.entries(o).map(([p,S])=>e.jsx("button",{onClick:()=>t(p),disabled:!0,title:"Range selection is unavailable until backend range queries are supported.",className:`px-4 py-2 rounded-lg text-sm font-semibold transition-all ${s===p?"bg-sky-600 text-white shadow-sm":"text-[#5a6578] hover:bg-[#edf1f7]"} opacity-60 cursor-not-allowed`,children:S},p))}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(M,{variant:"outline",disabled:!0,title:"Advanced analytics filters are not implemented yet",className:"px-4 py-2 gap-2 rounded-xl border-[#dde3eb] font-semibold text-sm opacity-50 cursor-not-allowed",children:[e.jsx(wa,{size:16}),"Filters"]}),e.jsxs(M,{variant:"outline",disabled:!0,title:"Export is unavailable until backend report generation is implemented",className:"px-4 py-2 gap-2 rounded-xl border-[#dde3eb] font-semibold text-sm opacity-50 cursor-not-allowed",children:[e.jsx(kt,{size:16}),"Export"]})]})]}),e.jsx("p",{className:"text-xs text-[#5a6578] -mt-3",children:"Time-range filtering is currently disabled because analytics range queries are not yet supported by the backend."}),!h&&!l?.totalActiveUsers&&e.jsxs(U.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{duration:.35},className:"flex items-center gap-3 bg-rose-50 border border-rose-200 rounded-2xl px-5 py-4",children:[e.jsx(qe,{size:18,className:"text-rose-600 shrink-0"}),e.jsxs("p",{className:"text-sm text-rose-800",children:[e.jsx("span",{className:"font-semibold",children:"Limited analytics data."})," ","KPI cards will populate automatically as students, quizzes, and sessions accumulate in the platform. Chart visualisations require time-series data."]})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-4 gap-4",children:m.map((p,S)=>{const f=p.icon;return e.jsxs(U.div,{initial:{opacity:0,y:16},animate:{opacity:1,y:0},transition:{duration:.35,delay:S*.06},className:"bg-white rounded-2xl p-5 shadow-sm border border-[#dde3eb]",children:[e.jsx("div",{className:"flex items-start justify-between mb-3",children:e.jsx("div",{className:`w-11 h-11 rounded-xl bg-gradient-to-br ${p.color} flex items-center justify-center shadow-sm`,children:e.jsx(f,{size:20,className:"text-white"})})}),h?e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(_,{size:16,className:"animate-spin text-[#a0aec0]"}),e.jsx("div",{className:"w-14 h-6 bg-[#edf1f7] rounded-lg animate-pulse"})]}):e.jsx("p",{className:"text-2xl font-bold text-[#0a1628] mb-2",children:p.value}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"text-sm text-[#5a6578] font-medium",children:p.label}),e.jsx("span",{className:"text-xs text-[#a0aec0] font-medium",children:o[s]})]})]},p.label)})}),e.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-12 gap-6",children:[e.jsxs(U.div,{initial:{opacity:0,y:16},animate:{opacity:1,y:0},transition:{duration:.4,delay:.15},className:"xl:col-span-8 bg-white rounded-2xl p-6 shadow-sm border border-[#dde3eb]",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-bold text-[#0a1628]",children:"Performance Trends"}),e.jsx("p",{className:"text-sm text-[#5a6578]",children:"Average scores — students vs. teacher targets"})]}),e.jsxs("div",{className:"flex items-center gap-4 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-3 h-3 rounded-full bg-sky-300"}),e.jsx("span",{className:"text-[#a0aec0] font-medium",children:"Students"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-3 h-3 rounded-full bg-violet-300"}),e.jsx("span",{className:"text-[#a0aec0] font-medium",children:"Teacher Targets"})]})]})]}),e.jsx(Le,{icon:e.jsx(es,{size:24,className:"text-[#c2cad8]"}),title:"No performance data yet",subtitle:"Import student and class records to generate trend charts."})]}),e.jsxs(U.div,{initial:{opacity:0,y:16},animate:{opacity:1,y:0},transition:{duration:.4,delay:.2},className:"xl:col-span-4 bg-white rounded-2xl p-6 shadow-sm border border-[#dde3eb]",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx("div",{className:"w-10 h-10 bg-violet-100 rounded-xl flex items-center justify-center",children:e.jsx(Ea,{size:20,className:"text-violet-400"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-bold text-[#0a1628]",children:"Grade Distribution"}),e.jsx("p",{className:"text-xs text-[#5a6578]",children:"All students, current term"})]})]}),e.jsx(Le,{icon:e.jsx(qe,{size:24,className:"text-[#c2cad8]"}),title:"No grade data",subtitle:"Import quiz and assessment results to see grade breakdowns."})]})]}),e.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-12 gap-6",children:[e.jsxs(U.div,{initial:{opacity:0,y:16},animate:{opacity:1,y:0},transition:{duration:.4,delay:.25},className:"xl:col-span-7 bg-white rounded-2xl p-6 shadow-sm border border-[#dde3eb]",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx("div",{className:"w-10 h-10 bg-sky-100 rounded-xl flex items-center justify-center",children:e.jsx(je,{size:20,className:"text-sky-400"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-bold text-[#0a1628]",children:"Subject Engagement"}),e.jsx("p",{className:"text-xs text-[#5a6578]",children:"Enrollment, completion, and average scores"})]})]}),e.jsx("div",{className:"overflow-hidden rounded-xl border border-[#dde3eb]",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-[#f7f9fc]",children:[e.jsx("th",{className:"text-left text-xs font-semibold text-[#5a6578] px-4 py-3",children:"Subject"}),e.jsx("th",{className:"text-right text-xs font-semibold text-[#5a6578] px-4 py-3",children:"Enrolled"}),e.jsx("th",{className:"text-right text-xs font-semibold text-[#5a6578] px-4 py-3",children:"Completion"}),e.jsx("th",{className:"text-right text-xs font-semibold text-[#5a6578] px-4 py-3",children:"Avg. Score"}),e.jsx("th",{className:"text-left text-xs font-semibold text-[#5a6578] px-4 py-3 w-36",children:"Progress"})]})}),e.jsx("tbody",{children:e.jsx("tr",{children:e.jsx("td",{colSpan:5,className:"px-4 py-10",children:e.jsx(Le,{icon:e.jsx(qe,{size:22,className:"text-[#c2cad8]"}),title:"No subject data available",subtitle:"Import class enrollment records to view subject engagement."})})})})]})})]}),e.jsxs(U.div,{initial:{opacity:0,y:16},animate:{opacity:1,y:0},transition:{duration:.4,delay:.3},className:"xl:col-span-5 bg-white rounded-2xl p-6 shadow-sm border border-[#dde3eb]",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx("div",{className:"w-10 h-10 bg-orange-100 rounded-xl flex items-center justify-center",children:e.jsx(Ns,{size:20,className:"text-orange-400"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-bold text-[#0a1628]",children:"Weekly Activity"}),e.jsx("p",{className:"text-xs text-[#5a6578]",children:"Sessions per day of week"})]})]}),e.jsx(Le,{icon:e.jsx(Ss,{size:24,className:"text-[#c2cad8]"}),title:"No session activity yet",subtitle:"Student logins and session data will appear here after data is imported."})]})]}),e.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-12 gap-6",children:[e.jsxs(U.div,{initial:{opacity:0,y:16},animate:{opacity:1,y:0},transition:{duration:.4,delay:.35},className:"xl:col-span-5 bg-white rounded-2xl p-6 shadow-sm border border-[#dde3eb]",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx("div",{className:"w-10 h-10 bg-rose-100 rounded-xl flex items-center justify-center",children:e.jsx(Ze,{size:20,className:"text-rose-400"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-bold text-[#0a1628]",children:"Gamification Overview"}),e.jsx("p",{className:"text-xs text-[#5a6578]",children:"Engagement & motivation metrics"})]})]}),e.jsx("div",{className:"grid grid-cols-2 gap-3",children:v.map(p=>{const S=p.icon;return e.jsxs("div",{className:`${p.bg} border border-[#dde3eb] rounded-xl p-4`,children:[e.jsx(S,{size:20,className:p.color}),h?e.jsx("div",{className:"w-12 h-5 bg-white/60 rounded mt-2 mb-1 animate-pulse"}):e.jsx("p",{className:"text-lg font-bold text-[#0a1628] mt-2 mb-1",children:p.value}),e.jsx("p",{className:"text-xs text-[#5a6578] font-medium",children:p.label})]},p.label)})})]}),e.jsxs(U.div,{initial:{opacity:0,y:16},animate:{opacity:1,y:0},transition:{duration:.4,delay:.4},className:"xl:col-span-7 bg-white rounded-2xl p-6 shadow-sm border border-[#dde3eb]",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx("div",{className:"w-10 h-10 bg-teal-100 rounded-xl flex items-center justify-center",children:e.jsx(ks,{size:20,className:"text-teal-400"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-bold text-[#0a1628]",children:"Top Performing Classes"}),e.jsx("p",{className:"text-xs text-[#5a6578]",children:"Ranked by average score this term"})]})]}),e.jsx(Le,{icon:e.jsx(qe,{size:24,className:"text-[#c2cad8]"}),title:"No class data yet",subtitle:"Import class and student records to see top performers ranked here."})]})]})]})};function yr(s){return!s||s.length===0?"Healthy":s.some(t=>t.status==="Down")?"Down":s.some(t=>t.status==="Degraded")?"Degraded":"Healthy"}function wr(s){return s.reduce((t,l)=>t+(l.estimatedCostUSD||0),0)}function Sr(s){return!s||s.length===0?null:s.reduce((t,l)=>t.estimatedCostUSD>l.estimatedCostUSD?t:l)}function kr(s){return!s||s.length===0?null:s.reduce((t,l)=>t.requestCount>l.requestCount?t:l)}function Cr(s){const t=new Date().toISOString().slice(0,7),[l,r]=i.useState([]),[h,n]=i.useState(!0),[o,m]=i.useState(null),[v,p]=i.useState(0),S=i.useCallback(()=>{p(f=>f+1)},[]);return i.useEffect(()=>{let f=!0;n(!0),m(null);const j=ts(se(X,"aiUsageLogs"),ws("month","==",t)),w=ha(j,A=>{if(!f)return;const k=[];A.forEach(d=>{const y=d.data();k.push(y)}),r(k),n(!1)},A=>{f&&(console.error("[useAIMonitoring] Firestore error:",A),m("Failed to load AI usage data. Please try again."),n(!1))});return()=>{f=!1,w()}},[t,v]),{stats:l,systemHealth:yr(l),totalSpend:wr(l),highestCostFeature:Sr(l),mostActiveFeature:kr(l),isLoading:h,error:o,refresh:S}}const Ar=[{id:"ai-chat",name:"AI Chat Tutor",description:"On-demand math help for students via DeepSeek with streaming responses"},{id:"quiz-generation",name:"Quiz Generation",description:"AI-powered quiz creation from imported topics and curriculum"},{id:"lesson-generation",name:"Lesson Generation",description:"AI-generated lesson plans grounded on imported topics and class signals"},{id:"learning-paths",name:"Learning Paths",description:"Personalized study plan generation based on student weaknesses"},{id:"risk-classification",name:"Risk Classification",description:"Student at-risk identification using AI structured output and ML scoring"},{id:"daily-insights",name:"Daily AI Insights",description:"Daily AI-powered analytics and recommendations for teachers"},{id:"solution-verification",name:"Solution Verification",description:"Multi-method math solution checking with self-consistency and code execution"},{id:"curriculum-search",name:"Curriculum Search",description:"Embedding-based search over lesson content and curriculum materials"},{id:"content-processing",name:"Content Processing",description:"AI column detection and topic extraction from uploaded files"},{id:"auto-feedback",name:"Auto Feedback",description:"Instant feedback and explanations for student quiz responses"}],_e={"ai-chat":35,"quiz-generation":18,"lesson-generation":12,"learning-paths":8,"risk-classification":6,"daily-insights":5,"solution-verification":6,"curriculum-search":4,"content-processing":3,"auto-feedback":3};function zr(s){if(!s)return"N/A";try{return new Date(s).toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}catch{return"N/A"}}function Ne(s){return s>=1?`$${s.toFixed(2)}`:`$${s.toFixed(4)}`}function Qe(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function Pr(s){const t=s.reduce((o,m)=>o+m.requestCount,0),l=s.reduce((o,m)=>o+m.estimatedCostUSD,0),r=new Date().toISOString(),h=Ar.map(o=>{const m=s.find(j=>{const w=j.featureName.toLowerCase().replace(/[^a-z0-9]/g,""),A=o.name.toLowerCase().replace(/[^a-z0-9]/g,"");return w.includes(A)||A.includes(w)}),v=m?.requestCount??Math.round(t*(_e[o.id]??1)/100),p=m?.estimatedCostUSD??l*(_e[o.id]??1)/100,S=m?m.status==="Degraded"?"Warning":m.status==="Down"?"Offline":"Healthy":"Healthy",f=m?m.priority==="High"?"High":m.priority==="Medium"?"Medium":"Low":_e[o.id]>=20?"High":_e[o.id]>=8?"Medium":"Low";return{...o,status:S,requests:v,estimatedCost:p,avgCostPerRequest:v>0?p/v:0,usageLevel:f,lastActiveAt:m?.lastUpdated?.toDate().toISOString()??r,trend:"Stable"}}),n=h.reduce((o,m)=>o+m.estimatedCost,0);return h.map(o=>({...o,costPercent:n>0?o.estimatedCost/n*100:0}))}function Dr(s,t){const l=[],r=t.filter(m=>m.status==="Degraded");r.length>0&&l.push({id:"degraded",severity:"warning",message:`${r.length} AI feature(s) are in degraded state`});const h=t.filter(m=>m.status==="Down");h.length>0&&l.push({id:"offline",severity:"critical",message:`${h[0].featureName} is currently unavailable`});const n=s.find(m=>m.id==="ai-chat");n&&n.costPercent&&n.costPercent>40&&l.push({id:"chatcost",severity:"info",message:"AI Chat Tutor is driving most of the AI spend this period"});const o=s.find(m=>m.id==="quiz-generation");return o&&o.costPercent&&o.costPercent>25&&l.push({id:"quizcost",severity:"info",message:"Quiz Generation is using more AI resources than usual"}),l}function Ve({status:s,loading:t}){const r={Healthy:{label:"Healthy",className:"text-emerald-700 bg-emerald-50 border-emerald-200",icon:ss,iconClass:"text-emerald-500"},Warning:{label:"Needs Attention",className:"text-amber-700 bg-amber-50 border-amber-200",icon:me,iconClass:"text-amber-500"},Offline:{label:"Offline",className:"text-rose-700 bg-rose-50 border-rose-200",icon:me,iconClass:"text-rose-500"}}[s];return t?e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-3 py-1 rounded-full text-xs font-bold bg-slate-100 text-slate-400 border border-slate-200",children:[e.jsx(Ss,{size:12,className:"animate-pulse"}),"Checking..."]}):e.jsxs("span",{className:`inline-flex items-center gap-1.5 px-3 py-1 rounded-full text-xs font-bold border ${r.className}`,children:[e.jsx(r.icon,{size:12,className:r.iconClass}),r.label]})}function nt({level:s}){const t={Low:"bg-slate-100 text-slate-600 border-slate-200",Medium:"bg-sky-50 text-sky-700 border-sky-200",High:"bg-violet-50 text-violet-700 border-violet-200"};return e.jsx("span",{className:`inline-flex px-2 py-0.5 rounded-full text-xs font-semibold border ${t[s]}`,children:s})}function Tr({trend:s}){if(!s)return null;const l={Up:{label:"↑ Up",className:"text-emerald-600 bg-emerald-50"},Stable:{label:"→ Stable",className:"text-slate-600 bg-slate-50"},Down:{label:"↓ Down",className:"text-rose-600 bg-rose-50"}}[s];return e.jsx("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-semibold ${l.className}`,children:l.label})}function Me({title:s,subtitle:t,testId:l}){return e.jsxs("div",{className:"mb-4","data-testid":l,children:[e.jsx("h2",{className:"text-base font-semibold text-[#0a1628]",children:s}),t&&e.jsx("p",{className:"text-sm text-[#5a6578] mt-0.5",children:t})]})}const Lr=()=>{const{stats:s,systemHealth:t,totalSpend:l,highestCostFeature:r,mostActiveFeature:h,isLoading:n,error:o,refresh:m}=Cr(),v=new Date().toLocaleString("default",{month:"long",year:"numeric"}),p=i.useMemo(()=>Pr(s),[s]),S=i.useMemo(()=>Dr(p,s),[p,s]),f=l,j=i.useMemo(()=>[...p].sort((d,y)=>y.estimatedCost-d.estimatedCost),[p]),w=i.useMemo(()=>[...p].sort((d,y)=>y.requests-d.requests),[p]),A=r?{name:r.featureName,estimatedCost:r.estimatedCostUSD,costPercent:f>0?r.estimatedCostUSD/f*100:0}:null,k=h?{name:h.featureName,requests:h.requestCount}:null;return e.jsxs("div",{className:"space-y-8","data-testid":"ai-usage-dashboard",children:[e.jsxs(U.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.3},className:"flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-[#0a1628]",children:"AI Usage Dashboard"}),e.jsx("p",{className:"text-sm text-[#5a6578]",children:"Track where AI is being used, what it costs, and what needs attention"})]}),e.jsxs(M,{variant:"outline",size:"sm",className:"text-xs gap-1.5 shrink-0",onClick:m,disabled:n,"data-testid":"refresh-btn",children:[e.jsx(Ie,{size:13,className:n?"animate-spin":""}),"Refresh"]})]}),o&&e.jsxs(U.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:"flex items-center gap-3 bg-rose-50 border border-rose-200 rounded-2xl px-5 py-4",children:[e.jsx(me,{size:18,className:"text-rose-600 shrink-0"}),e.jsx("p",{className:"text-sm text-rose-800",children:o})]}),!n&&!o&&s.length===0&&e.jsxs("div",{className:"mb-6 bg-sky-50 border border-sky-200 rounded-2xl px-5 py-4 flex items-center gap-3",children:[e.jsx(we,{size:18,className:"text-sky-600 shrink-0"}),e.jsxs("p",{className:"text-sm text-sky-800",children:["No AI usage data recorded yet for ",v,". Data will appear here once AI features are used."]})]}),e.jsxs(U.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.35,delay:.05},className:"grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"bg-white rounded-2xl p-5 shadow-sm border border-[#dde3eb]","data-testid":"summary-ai-status",children:[e.jsx("div",{className:"flex items-center gap-2 mb-3",children:e.jsx("div",{className:`w-10 h-10 rounded-xl flex items-center justify-center shadow-sm ${t==="Healthy"?"bg-gradient-to-br from-emerald-400 to-emerald-600":t==="Degraded"?"bg-gradient-to-br from-amber-400 to-amber-600":"bg-gradient-to-br from-rose-400 to-rose-600"}`,children:t==="Healthy"?e.jsx(ss,{size:18,className:"text-white"}):t==="Degraded"?e.jsx(me,{size:18,className:"text-white"}):e.jsx(me,{size:18,className:"text-white"})})}),n?e.jsx(Z,{className:"w-28 h-8 rounded-lg mb-2"}):e.jsx("p",{className:"text-2xl font-bold text-[#0a1628] mb-1",children:t==="Healthy"?"Healthy":t==="Degraded"?"Needs Attention":"Partial Outage"}),e.jsx("p",{className:"text-xs text-[#5a6578] font-medium",children:t==="Healthy"?"Most AI features are working normally":t==="Degraded"?"Some AI features need attention":"Several AI features are unavailable"})]}),e.jsxs("div",{className:"bg-white rounded-2xl p-5 shadow-sm border border-[#dde3eb]","data-testid":"summary-ai-cost",children:[e.jsx("div",{className:"flex items-center gap-2 mb-3",children:e.jsx("div",{className:"w-10 h-10 rounded-xl bg-gradient-to-br from-violet-500 to-purple-700 flex items-center justify-center shadow-sm",children:e.jsx(Ws,{size:18,className:"text-white"})})}),n?e.jsx(Z,{className:"w-24 h-8 rounded-lg mb-2"}):e.jsx("p",{className:"text-2xl font-bold text-[#0a1628] mb-1",children:s.length===0?"No data":Ne(f)}),e.jsx("p",{className:"text-xs text-[#5a6578] font-medium",children:n?"...":"Total AI spend this month"}),!n&&l>0&&e.jsx("p",{className:"text-xs text-[#a0aec0] mt-1",children:"Cumulative AI cost for current period"})]}),e.jsxs("div",{className:"bg-white rounded-2xl p-5 shadow-sm border border-[#dde3eb]","data-testid":"summary-most-expensive",children:[e.jsx("div",{className:"flex items-center gap-2 mb-3",children:e.jsx("div",{className:"w-10 h-10 rounded-xl bg-gradient-to-br from-amber-400 to-orange-600 flex items-center justify-center shadow-sm",children:e.jsx(ht,{size:18,className:"text-white"})})}),n?e.jsx(Z,{className:"w-32 h-8 rounded-lg mb-2"}):e.jsx("p",{className:"text-2xl font-bold text-[#0a1628] mb-1 truncate",children:A?.name??"N/A"}),e.jsx("p",{className:"text-xs text-[#5a6578] font-medium",children:n?"...":"Highest AI cost this month"}),!n&&A&&e.jsxs("p",{className:"text-xs text-[#a0aec0] mt-1",children:[Ne(A.estimatedCost)," ·"," ",A.costPercent?.toFixed(0),"% of total"]})]}),e.jsxs("div",{className:"bg-white rounded-2xl p-5 shadow-sm border border-[#dde3eb]","data-testid":"summary-top-activity",children:[e.jsx("div",{className:"flex items-center gap-2 mb-3",children:e.jsx("div",{className:"w-10 h-10 rounded-xl bg-gradient-to-br from-sky-400 to-blue-600 flex items-center justify-center shadow-sm",children:e.jsx(ut,{size:18,className:"text-white"})})}),n?e.jsx(Z,{className:"w-32 h-8 rounded-lg mb-2"}):e.jsx("p",{className:"text-2xl font-bold text-[#0a1628] mb-1 truncate",children:k?.name??"N/A"}),e.jsx("p",{className:"text-xs text-[#5a6578] font-medium",children:n?"...":"Most active AI feature"}),!n&&k&&e.jsxs("p",{className:"text-xs text-[#a0aec0] mt-1",children:[Qe(k.requests)," requests"]})]})]}),e.jsxs("section",{"data-testid":"section-ai-usage-areas",children:[e.jsx(Me,{title:"Where AI is used",subtitle:"All AI-powered features in the platform",testId:"section-ai-usage-areas-header"}),n?e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4",children:Array.from({length:6}).map((d,y)=>e.jsxs("div",{className:"bg-white rounded-2xl p-5 shadow-sm border border-[#dde3eb]",children:[e.jsx(Z,{className:"w-32 h-5 rounded mb-3"}),e.jsx(Z,{className:"w-full h-4 rounded mb-2"}),e.jsx(Z,{className:"w-24 h-4 rounded"})]},y))}):e.jsx(U.div,{initial:"hidden",animate:"show",variants:{hidden:{},show:{transition:{staggerChildren:.05}}},className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4",children:p.map(d=>e.jsxs(U.div,{variants:{hidden:{opacity:0,y:8},show:{opacity:1,y:0}},className:"bg-white rounded-2xl p-5 shadow-sm border border-[#dde3eb] hover:shadow-md transition-shadow",children:[e.jsxs("div",{className:"flex items-start justify-between mb-2",children:[e.jsx("h3",{className:"text-sm font-semibold text-[#0a1628] leading-tight",children:d.name}),e.jsx(Ve,{status:d.status})]}),e.jsx("p",{className:"text-xs text-[#5a6578] mb-3 leading-relaxed",children:d.description}),e.jsxs("div",{className:"flex items-center gap-3 text-xs text-[#5a6578]",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(ga,{size:12}),Qe(d.requests)," requests"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Ws,{size:12}),Ne(d.estimatedCost)]}),e.jsx(nt,{level:d.usageLevel})]})]},d.id))})]}),e.jsxs("section",{"data-testid":"section-highest-cost",children:[e.jsx(Me,{title:"What costs the most",subtitle:"AI features ranked by estimated spend this month",testId:"section-highest-cost-header"}),n?e.jsx("div",{className:"space-y-3",children:Array.from({length:5}).map((d,y)=>e.jsx("div",{className:"bg-white rounded-2xl p-4 shadow-sm border border-[#dde3eb]",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(Z,{className:"w-6 h-6 rounded-full"}),e.jsxs("div",{className:"flex-1",children:[e.jsx(Z,{className:"w-40 h-4 rounded mb-2"}),e.jsx(Z,{className:"w-full h-2 rounded-full"})]})]})},y))}):e.jsx("div",{className:"space-y-3",children:j.slice(0,7).map((d,y)=>e.jsxs(U.div,{initial:{opacity:0,x:-8},animate:{opacity:1,x:0},transition:{duration:.25,delay:y*.04},className:"bg-white rounded-2xl p-4 shadow-sm border border-[#dde3eb] flex items-center gap-4",children:[e.jsx("div",{className:`w-8 h-8 rounded-full flex items-center justify-center shrink-0 text-xs font-bold ${y===0?"bg-amber-100 text-amber-700":y===1?"bg-slate-100 text-slate-600":y===2?"bg-orange-100 text-orange-700":"bg-slate-50 text-slate-400"}`,children:y+1}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-semibold text-[#0a1628]",children:d.name}),e.jsx(Ve,{status:d.status})]}),e.jsxs("div",{className:"flex items-center gap-3 text-xs",children:[e.jsx("span",{className:"font-semibold text-[#0a1628]",children:Ne(d.estimatedCost)}),e.jsxs("span",{className:"text-[#5a6578] min-w-[40px] text-right",children:[d.costPercent?.toFixed(1),"%"]})]})]}),e.jsx("div",{className:"h-2 bg-slate-100 rounded-full overflow-hidden",children:e.jsx(U.div,{initial:{width:0},animate:{width:`${d.costPercent??0}%`},transition:{duration:.6,delay:.1+y*.04},className:`h-full rounded-full ${y===0?"bg-amber-400":y===1?"bg-slate-400":y===2?"bg-orange-400":"bg-violet-400"}`})})]})]},d.id))})]}),e.jsxs("section",{"data-testid":"section-highest-usage",children:[e.jsx(Me,{title:"Most active AI features",subtitle:"Features with the highest request volume this month",testId:"section-highest-usage-header"}),n?e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-3 gap-4",children:Array.from({length:6}).map((d,y)=>e.jsxs("div",{className:"bg-white rounded-2xl p-4 shadow-sm border border-[#dde3eb]",children:[e.jsx(Z,{className:"w-32 h-5 rounded mb-3"}),e.jsx(Z,{className:"w-24 h-8 rounded"})]},y))}):e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-3 gap-4",children:w.slice(0,6).map((d,y)=>e.jsxs(U.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},transition:{duration:.25,delay:y*.04},className:"bg-white rounded-2xl p-4 shadow-sm border border-[#dde3eb]",children:[e.jsxs("div",{className:"flex items-start justify-between mb-2",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-[#0a1628] mb-0.5",children:d.name}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ve,{status:d.status}),e.jsx(Tr,{trend:d.trend})]})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("p",{className:"text-lg font-bold text-[#0a1628]",children:Qe(d.requests)}),e.jsx("p",{className:"text-xs text-[#5a6578]",children:"requests"})]})]}),e.jsxs("div",{className:"pt-2 border-t border-slate-100 flex items-center justify-between",children:[e.jsxs("p",{className:"text-xs text-[#5a6578]",children:["Avg cost: ",Ne(d.avgCostPerRequest),"/request"]}),e.jsx(nt,{level:d.usageLevel})]})]},d.id))})]}),e.jsxs("section",{"data-testid":"section-needs-attention",children:[e.jsx(Me,{title:"Needs attention",subtitle:"Actionable issues that may need review",testId:"section-needs-attention-header"}),n?e.jsx("div",{className:"bg-white rounded-2xl p-6 shadow-sm border border-[#dde3eb]",children:e.jsx("div",{className:"space-y-3",children:[1,2].map(d=>e.jsx(Z,{className:"w-full h-12 rounded-xl"},d))})}):S.length===0?e.jsxs(U.div,{initial:{opacity:0,scale:.98},animate:{opacity:1,scale:1},className:"bg-emerald-50 border border-emerald-200 rounded-2xl p-6 flex items-center gap-4",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-emerald-100 flex items-center justify-center shrink-0",children:e.jsx(ss,{size:20,className:"text-emerald-600"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-emerald-800",children:"Everything looks normal"}),e.jsx("p",{className:"text-xs text-emerald-600 mt-0.5",children:"No issues detected with AI features right now"})]})]}):e.jsx("div",{className:"space-y-3",children:S.map(d=>e.jsxs(U.div,{initial:{opacity:0,x:-8},animate:{opacity:1,x:0},className:`rounded-2xl p-4 flex items-start gap-3 border ${d.severity==="critical"?"bg-rose-50 border-rose-200":d.severity==="warning"?"bg-amber-50 border-amber-200":"bg-sky-50 border-sky-200"}`,children:[e.jsx("div",{className:`w-8 h-8 rounded-xl flex items-center justify-center shrink-0 ${d.severity==="critical"?"bg-rose-100":d.severity==="warning"?"bg-amber-100":"bg-sky-100"}`,children:d.severity==="critical"?e.jsx(me,{size:16,className:"text-rose-600"}):d.severity==="warning"?e.jsx(oa,{size:16,className:"text-amber-600"}):e.jsx(we,{size:16,className:"text-sky-600"})}),e.jsx("p",{className:`text-sm font-medium ${d.severity==="critical"?"text-rose-800":d.severity==="warning"?"text-amber-800":"text-sky-800"}`,children:d.message})]},d.id))})]}),e.jsxs("section",{"data-testid":"section-ai-breakdown-table",children:[e.jsx(Me,{title:"AI activity breakdown",subtitle:"Detailed view of all AI features and their usage",testId:"section-ai-breakdown-table-header"}),e.jsx("div",{className:"bg-white rounded-2xl shadow-sm border border-[#dde3eb] overflow-hidden",children:n?e.jsx("div",{className:"p-4 space-y-3",children:Array.from({length:5}).map((d,y)=>e.jsx(Z,{className:"w-full h-12 rounded-lg"},y))}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-[#dde3eb] bg-slate-50",children:[e.jsx("th",{className:"text-left px-5 py-3 text-xs font-semibold text-[#5a6578] uppercase tracking-wide",children:"Feature"}),e.jsx("th",{className:"text-left px-4 py-3 text-xs font-semibold text-[#5a6578] uppercase tracking-wide",children:"Status"}),e.jsx("th",{className:"text-right px-4 py-3 text-xs font-semibold text-[#5a6578] uppercase tracking-wide",children:"Requests"}),e.jsx("th",{className:"text-right px-4 py-3 text-xs font-semibold text-[#5a6578] uppercase tracking-wide",children:"Est. Cost"}),e.jsx("th",{className:"text-right px-4 py-3 text-xs font-semibold text-[#5a6578] uppercase tracking-wide",children:"Avg / Request"}),e.jsx("th",{className:"text-left px-4 py-3 text-xs font-semibold text-[#5a6578] uppercase tracking-wide",children:"Last Active"})]})}),e.jsx("tbody",{className:"divide-y divide-[#dde3eb]",children:p.map(d=>e.jsxs("tr",{className:"hover:bg-slate-50 transition-colors",children:[e.jsx("td",{className:"px-5 py-3",children:e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-[#0a1628]",children:d.name}),e.jsx("p",{className:"text-xs text-[#5a6578] hidden sm:block",children:d.description})]})}),e.jsx("td",{className:"px-4 py-3",children:e.jsx(Ve,{status:d.status})}),e.jsx("td",{className:"px-4 py-3 text-right font-medium text-[#0a1628]",children:Qe(d.requests)}),e.jsx("td",{className:"px-4 py-3 text-right font-medium text-[#0a1628]",children:Ne(d.estimatedCost)}),e.jsx("td",{className:"px-4 py-3 text-right text-[#5a6578]",children:Ne(d.avgCostPerRequest)}),e.jsx("td",{className:"px-4 py-3 text-[#5a6578]",children:zr(d.lastActiveAt)})]},d.id))})]})})})]})]})},dt=Xe.map(s=>({id:s.id,name:s.name,code:s.code,gradeLevel:s.gradeLevel,semester:s.semester,color:s.color})),Mr=()=>{const{userProfile:s}=Re(),{availability:t,loading:l,error:r}=Sa(),[h,n]=i.useState(null),[o,m]=i.useState({}),v=i.useCallback(async(f,j)=>{if(!s?.uid){z.error("You must be logged in as admin to change availability");return}n(f);try{await ka(f,j,s.uid),z.success(`${dt.find(w=>w.id===f)?.name||f} is now ${j?"available":"locked"}`)}catch(w){z.error("Failed to update subject availability"),console.error(w)}finally{n(null)}},[s?.uid]),p=i.useCallback((f,j)=>{m(w=>({...w,[f]:j}))},[]),S=i.useCallback(async f=>{if(!s?.uid){z.error("You must be logged in as admin");return}const j=o[f]?.trim()||null;n(f);try{await Ca(f,j,s.uid),z.success("PDF path updated")}catch(w){z.error("Failed to update PDF path"),console.error(w)}finally{n(null)}},[o,s?.uid]);return e.jsxs(U.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.3},className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-display font-bold text-[#0a1628]",children:"Subject Availability"}),e.jsx("p",{className:"text-sm text-[#5a6578]",children:"Toggle subjects on or off to control student access. Changes take effect immediately across the platform."})]}),l&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-slate-500",children:[e.jsx(_,{size:16,className:"animate-spin"}),"Syncing..."]})]}),r&&e.jsx("div",{className:"rounded-xl border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-700",children:r}),e.jsx("div",{className:"rounded-2xl border border-slate-200 bg-white shadow-sm overflow-hidden",children:e.jsxs(la,{children:[e.jsx(na,{children:e.jsxs(Gs,{className:"bg-slate-50/80 hover:bg-slate-50/80",children:[e.jsx(De,{className:"text-xs font-black uppercase tracking-wider text-slate-500",children:"Subject"}),e.jsx(De,{className:"text-xs font-black uppercase tracking-wider text-slate-500",children:"Grade / Sem"}),e.jsx(De,{className:"text-xs font-black uppercase tracking-wider text-slate-500",children:"Status"}),e.jsx(De,{className:"text-xs font-black uppercase tracking-wider text-slate-500",children:"Available"}),e.jsx(De,{className:"text-xs font-black uppercase tracking-wider text-slate-500 w-[320px]",children:"PDF Path"})]})}),e.jsx(da,{children:dt.map(f=>{const j=t[f.id],w=j?.available??!0,A=o[f.id]??j?.pdfPath??"",k=j?.lastUpdated,d=h===f.id;return e.jsxs(Gs,{className:"group",children:[e.jsx(Te,{children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`w-8 h-8 rounded-lg bg-gradient-to-br ${f.color} flex items-center justify-center text-white shadow-sm`,children:e.jsx(je,{size:14})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-bold text-sm text-[#0a1628]",children:f.name}),e.jsx("p",{className:"text-[11px] text-slate-400 font-semibold",children:f.code})]})]})}),e.jsxs(Te,{children:[e.jsx("p",{className:"text-sm text-slate-600",children:f.gradeLevel}),e.jsx("p",{className:"text-[11px] text-slate-400",children:f.semester})]}),e.jsxs(Te,{children:[e.jsx("div",{className:"flex items-center gap-1.5",children:w?e.jsxs(e.Fragment,{children:[e.jsx(Ga,{size:14,className:"text-teal-500"}),e.jsx("span",{className:"text-xs font-bold text-teal-600",children:"Unlocked"})]}):e.jsxs(e.Fragment,{children:[e.jsx(ot,{size:14,className:"text-slate-400"}),e.jsx("span",{className:"text-xs font-bold text-slate-500",children:"Locked"})]})}),k&&e.jsxs("p",{className:"text-[10px] text-slate-400 mt-0.5 flex items-center gap-1",children:[e.jsx(Ct,{size:10}),k.toLocaleString()]})]}),e.jsx(Te,{children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(be,{checked:w,onCheckedChange:y=>v(f.id,y),disabled:d,"aria-label":`Toggle ${f.name} availability`}),d&&e.jsx(_,{size:14,className:"animate-spin text-slate-400"})]})}),e.jsx(Te,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(Ye,{size:14,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-slate-400"}),e.jsx(R,{value:A,onChange:y=>p(f.id,y.target.value),placeholder:"Firebase Storage path (optional)",className:"pl-8 h-8 text-xs",disabled:d})]}),e.jsx(M,{variant:"ghost",size:"sm",className:"h-8 px-2 text-xs",onClick:()=>S(f.id),disabled:d,children:d?e.jsx(_,{size:14,className:"animate-spin"}):e.jsx(Aa,{size:14})})]})})]},f.id)})})]})}),e.jsxs("div",{className:"rounded-xl border border-sky-200 bg-sky-50 px-5 py-4",children:[e.jsx("p",{className:"text-xs font-black uppercase tracking-wide text-sky-700 mb-2",children:"How it works"}),e.jsxs("ul",{className:"text-sm text-sky-800 space-y-1 list-disc list-inside",children:[e.jsxs("li",{children:["Turning a subject ",e.jsx("strong",{children:"off"})," immediately locks its modules and removes it from Quiz Battle."]}),e.jsxs("li",{children:["Turning a subject ",e.jsx("strong",{children:"on"})," unlocks it everywhere — no redeployment required."]}),e.jsxs("li",{children:["The ",e.jsx("strong",{children:"PDF Path"})," field is optional and references the RAG source in Firebase Storage."]}),e.jsx("li",{children:"All changes are logged with timestamps and your admin user ID."})]})]})]})},We=[{id:"gen-math",name:"Gen Math",shortName:"GM",color:"#3B82F6"},{id:"stats-prob",name:"Stats & Prob",shortName:"SP",color:"#0ea5e9"},{id:"pre-calc",name:"Pre-Calc",shortName:"PC",color:"#F97316"},{id:"basic-calc",name:"Basic Calc",shortName:"BC",color:"#EF4444"}],js={"gen-math":[{name:"Functions & Relations",unit:"Functions"},{name:"Rational Functions",unit:"Functions"},{name:"Exponential Functions",unit:"Functions"},{name:"Logarithmic Functions",unit:"Functions"},{name:"Simple Interest",unit:"Business Math"},{name:"Compound Interest",unit:"Business Math"},{name:"Annuities",unit:"Business Math"},{name:"Propositions",unit:"Logic"},{name:"Truth Tables",unit:"Logic"}],"stats-prob":[{name:"Random Variables",unit:"Random Variables"},{name:"Probability Distributions",unit:"Random Variables"},{name:"Normal Distribution",unit:"Normal Dist"},{name:"Z-scores",unit:"Normal Dist"},{name:"Sampling Distributions",unit:"Sampling"},{name:"Central Limit Theorem",unit:"Sampling"},{name:"Confidence Intervals",unit:"Estimation"},{name:"Hypothesis Testing",unit:"Testing"},{name:"Correlation",unit:"Regression"}],"pre-calc":[{name:"Parabola",unit:"Conics"},{name:"Ellipse",unit:"Conics"},{name:"Hyperbola",unit:"Conics"},{name:"Arithmetic Seq",unit:"Series"},{name:"Geometric Seq",unit:"Series"},{name:"Math Induction",unit:"Series"},{name:"Trig Functions",unit:"Trigonometry"},{name:"Trig Identities",unit:"Trigonometry"},{name:"Polar Coords",unit:"Trigonometry"}],"basic-calc":[{name:"Limits",unit:"Limits"},{name:"Continuity",unit:"Limits"},{name:"Definition of Deriv.",unit:"Derivatives"},{name:"Diff. Rules",unit:"Derivatives"},{name:"Chain Rule",unit:"Derivatives"},{name:"Related Rates",unit:"Derivatives"},{name:"Optimization",unit:"Derivatives"},{name:"Antiderivatives",unit:"Integration"},{name:"Definite Integrals",unit:"Integration"}]};function Ir(s){return s>=85?"bg-emerald-500":s>=70?"bg-emerald-300":s>=55?"bg-rose-300":s>=40?"bg-orange-400":s>=20?"bg-red-400":"bg-red-600"}function Rr(s){return s>=70||s>=40,"text-white"}const Er=({title:s="Platform-Wide Subject Mastery"})=>{const[t,l]=i.useState(null),[r,h]=i.useState("all"),{data:n=[],isLoading:o}=za({queryKey:aa.masteryHeatmap(),staleTime:180*1e3,gcTime:1200*1e3,queryFn:async()=>{try{const j=await de(se(X,"progress")),w={};j.forEach(k=>{const y=k.data().subjects||{};for(const[L,C]of Object.entries(y)){const B=js[L]||[],q=C?.progress??0;for(const O of B){const G=`${L}::${O.name}`;w[G]||(w[G]={totalMastery:0,count:0}),w[G].totalMastery+=q,w[G].count+=1}}});const A=[];for(const k of We){const d=js[k.id]||[];for(const y of d){const L=`${k.id}::${y.name}`,C=w[L];A.push({subject:k.id,topic:y.name,mastery:C&&C.count>0?Math.round(C.totalMastery/C.count):0,students:C?.count??0})}}return A}catch(j){return console.error("[MasteryHeatmap] Error fetching progress data:",j),[]}}}),m=r==="all"?We:We.filter(j=>j.id===r),v=n.filter(j=>j.students>0),p=v.length>0?Math.round(v.reduce((j,w)=>j+w.mastery,0)/v.length):0,S=v.length>0?v.reduce((j,w)=>w.mastery0?v.reduce((j,w)=>w.mastery>j.mastery?w:j,v[0]):null;return o?e.jsx("div",{className:"bg-white rounded-3xl p-6 shadow-sm border border-[#dde3eb] flex items-center justify-center min-h-[200px]",children:e.jsxs("div",{className:"flex flex-col items-center gap-3",children:[e.jsx(_,{size:28,className:"text-sky-500 animate-spin"}),e.jsx("p",{className:"text-sm text-[#5a6578]",children:"Loading mastery data..."})]})}):e.jsxs("div",{className:"bg-white rounded-3xl p-6 shadow-sm border border-[#dde3eb]",children:[e.jsxs("div",{className:"flex items-center justify-between mb-5",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 bg-gradient-to-br from-indigo-500 to-sky-500 rounded-xl flex items-center justify-center",children:e.jsx(qa,{size:20,className:"text-white"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-bold text-[#0a1628]",children:s}),e.jsxs("p",{className:"text-xs text-[#5a6578]",children:["Aggregated mastery levels across all classes • ",n.filter(j=>j.students>0).length," tracked combinations"]})]})]}),e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:r,onChange:j=>h(j.target.value),className:"appearance-none bg-[#edf1f7] border border-[#dde3eb] rounded-lg px-3 py-1.5 pr-8 text-xs font-semibold text-[#5a6578] focus:outline-none focus:ring-2 focus:ring-sky-500/20",children:[e.jsx("option",{value:"all",children:"All Subjects"}),We.map(j=>e.jsx("option",{value:j.id,children:j.name},j.id))]}),e.jsx(Pa,{size:12,className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-slate-500 pointer-events-none"})]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3 mb-5",children:[e.jsxs("div",{className:"bg-[#edf1f7] rounded-xl p-3 flex items-center gap-3",children:[e.jsx("div",{className:`w-8 h-8 rounded-lg flex items-center justify-center ${p>=70?"bg-emerald-100":"bg-rose-100"}`,children:e.jsx(Da,{size:16,className:p>=70?"text-emerald-600":"text-rose-600"})}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-lg font-bold text-[#0a1628]",children:[p,"%"]}),e.jsx("p",{className:"text-[10px] text-[#5a6578] uppercase tracking-wider",children:"Platform Average"})]})]}),e.jsxs("div",{className:"bg-red-50 rounded-xl p-3 flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 bg-red-100 rounded-lg flex items-center justify-center",children:e.jsx(ca,{size:16,className:"text-red-600"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-bold text-[#0a1628] truncate",children:S?.topic}),e.jsxs("p",{className:"text-[10px] text-red-600 font-semibold",children:[S?.mastery,"% — Lowest"]})]})]}),e.jsxs("div",{className:"bg-emerald-50 rounded-xl p-3 flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 bg-emerald-100 rounded-lg flex items-center justify-center",children:e.jsx(ht,{size:16,className:"text-emerald-600"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-bold text-[#0a1628] truncate",children:f?.topic}),e.jsxs("p",{className:"text-[10px] text-emerald-600 font-semibold",children:[f?.mastery,"% — Highest"]})]})]})]}),e.jsx("div",{className:"overflow-x-auto",children:m.map(j=>{const w=js[j.id]||[],A=n.filter(d=>d.subject===j.id),k=A.length>0?Math.round(A.reduce((d,y)=>d+y.mastery,0)/A.length):0;return e.jsxs("div",{className:"mb-5 last:mb-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("div",{className:"w-3 h-3 rounded-sm e-bg",style:{"--bg":j.color}}),e.jsx("span",{className:"text-xs font-bold text-[#0a1628]",children:j.name}),e.jsxs("span",{className:"text-[10px] text-slate-500 ml-1",children:["Avg: ",k,"%"]})]}),e.jsxs("div",{className:"grid gap-1 e-grid-cols",style:{"--grid-cols":`repeat(${w.length}, minmax(0, 1fr))`},children:[w.map((d,y)=>e.jsx("div",{className:"text-center",children:e.jsx("p",{className:"text-[9px] text-slate-500 truncate px-0.5 mb-1",title:d.name,children:d.name})},`label-${y}`)),w.map((d,y)=>{const L=A.find(q=>q.topic===d.name),C=L?.mastery||0,B=t?.topic===d.name&&t?.subject===j.id;return e.jsxs(U.div,{onMouseEnter:()=>L&&l(L),onMouseLeave:()=>l(null),whileHover:{scale:1.05},className:`relative h-10 rounded-lg flex items-center justify-center cursor-pointer transition-all ${Ir(C)} ${B?"ring-2 ring-white shadow-lg z-10":""}`,children:[e.jsxs("span",{className:`text-xs font-bold ${Rr(C)}`,children:[C,"%"]}),B&&L&&e.jsxs("div",{className:"absolute bottom-full left-1/2 -translate-x-1/2 mb-2 bg-slate-800 text-white rounded-lg px-3 py-2 text-xs whitespace-nowrap z-20 shadow-xl pointer-events-none",children:[e.jsx("p",{className:"font-bold mb-0.5",children:L.topic}),e.jsxs("p",{children:["Mastery: ",e.jsxs("strong",{children:[L.mastery,"%"]})]}),e.jsxs("p",{children:["Students: ",e.jsx("strong",{children:L.students})]}),e.jsx("div",{className:"absolute bottom-0 left-1/2 -translate-x-1/2 translate-y-full w-0 h-0 border-l-[6px] border-l-transparent border-r-[6px] border-r-transparent border-t-[6px] border-t-slate-800"})]})]},`cell-${y}`)})]})]},j.id)})}),e.jsxs("div",{className:"flex items-center justify-center gap-4 mt-5 pt-4 border-t border-[#dde3eb]",children:[e.jsxs("div",{className:"flex items-center gap-1 text-[10px] text-[#5a6578]",children:[e.jsx(we,{size:10}),e.jsx("span",{children:"Color scale:"})]}),[{label:"0-19%",color:"bg-red-600"},{label:"20-39%",color:"bg-red-400"},{label:"40-54%",color:"bg-orange-400"},{label:"55-69%",color:"bg-rose-300"},{label:"70-84%",color:"bg-emerald-300"},{label:"85-100%",color:"bg-emerald-500"}].map((j,w)=>e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("div",{className:`w-3 h-3 rounded-sm ${j.color}`}),e.jsx("span",{className:"text-[10px] text-[#5a6578]",children:j.label})]},w))]})]})},Ur=[{id:"gen-math",title:"General Mathematics",icon:je,bg:"bg-[#9956DE]",tags:["Algebra","Fractions","Integers"],level:1,progress:25,isAtRisk:!0},{id:"pre-calc",title:"Pre-Calculus",icon:je,bg:"bg-[#1FA7E1]",tags:["Functions","Limits","Graphs"],level:2,progress:15,isAtRisk:!0},{id:"stats-prob",title:"Statistics & Probability",icon:je,bg:"bg-[#FFB356]",tags:["Probability","Mean/Median"],level:2,progress:40,isAtRisk:!1},{id:"basic-calc",title:"Basic Calculus",icon:je,bg:"bg-[#FB96BB]",tags:["Derivatives","Integrals"],level:3,progress:50,isAtRisk:!1},{id:"adv-math",title:"Advanced Algebra",icon:je,bg:"bg-[#7274ED]",tags:["Math","Logic"],level:4,progress:10,isAtRisk:!0}].slice(0,5),$r=()=>{const s=i.useRef(null),[t,l]=i.useState(0),r=()=>{if(!s.current)return;const{scrollLeft:n,scrollWidth:o,clientWidth:m}=s.current,v=n/(o-m),p=3;let S=Math.round(v*(p-1));S<0&&(S=0),S>=p&&(S=p-1),l(S)},h=n=>{if(!s.current)return;const{scrollWidth:o,clientWidth:m}=s.current,p=(o-m)/2*n;s.current.scrollTo({left:p,behavior:"smooth"}),l(n)};return e.jsxs("div",{className:"bg-white rounded-3xl p-6 shadow-sm border border-[#dde3eb] mb-6",children:[e.jsx("div",{className:"flex items-center justify-between mb-5",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-bold text-[#0a1628] mb-1",children:"Priority Attention Modules"}),e.jsx("p",{className:"text-sm text-[#5a6578]",children:"Highly recommended to be reviewed (lowest performance)."})]})}),e.jsx("div",{className:"relative",children:e.jsx("div",{ref:s,onScroll:r,className:"flex overflow-x-auto snap-x snap-mandatory gap-5 pb-6 no-scrollbar",children:Ur.map(n=>{const o=n.icon;return e.jsxs("div",{className:`snap-center shrink-0 w-[280px] sm:w-[300px] ${n.bg} rounded-[2rem] p-5 min-h-[290px] relative overflow-hidden transition-all duration-300 flex flex-col group shadow-sm`,children:[e.jsx("div",{className:"absolute -bottom-8 right-[-20%] w-32 h-32 bg-white opacity-10 rounded-full"}),e.jsx("div",{className:"absolute bottom-4 right-12 w-20 h-20 bg-white opacity-10 rounded-full"}),e.jsxs("div",{className:"flex justify-between items-start mb-4 relative z-10",children:[e.jsx("div",{className:"w-12 h-12 rounded-[1rem] bg-white/20 flex flex-shrink-0 items-center justify-center text-white backdrop-blur-sm",children:e.jsx(o,{size:24,className:"opacity-90"})}),e.jsxs("div",{className:"px-4 py-1.5 rounded-full bg-white/20 text-white/90 text-sm font-bold backdrop-blur-sm",children:["Lv ",n.level]})]}),e.jsxs("div",{className:"relative z-10 flex-1",children:[e.jsx("h3",{className:"text-2xl font-display font-black text-white leading-[1.1] mb-3 drop-shadow-sm pr-4 line-clamp-2",children:n.title}),e.jsx("div",{className:"flex flex-wrap gap-2 pb-4",children:n.tags.map(m=>e.jsx("span",{className:"px-3 py-1 rounded-full bg-white/20 text-white text-[13px] font-bold shadow-sm backdrop-blur-sm",children:m},m))})]}),e.jsxs("div",{className:"relative z-10 mt-auto pt-4 flex flex-col gap-2.5",children:[e.jsxs("div",{className:"flex justify-between text-white/90 text-[13px] font-bold",children:[e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsx("span",{children:"Avg Mastery"})}),e.jsxs("span",{children:[n.progress,"%"]})]}),e.jsx("div",{className:"w-full h-2 rounded-full bg-white/30 overflow-hidden shadow-inner mt-1",children:e.jsx("div",{className:"h-full bg-white rounded-full e-w",style:{"--w":`${n.progress}%`}})}),n.isAtRisk&&e.jsxs("div",{className:"absolute -top-12 right-0 bg-red-500 text-white px-3 py-1 rounded-full text-[11px] font-bold flex items-center gap-1 shadow-lg animate-pulse",children:[e.jsx(me,{size:12})," At Risk"]})]})]},n.id)})})}),e.jsx("div",{className:"flex justify-center items-center gap-2 mt-2",children:[0,1,2].map(n=>e.jsx("button",{onClick:()=>h(n),className:`w-2.5 h-2.5 rounded-full transition-all duration-300 ${t===n?"bg-sky-600 w-6":"bg-sky-200 hover:bg-sky-300"}`,"aria-label":`Go to slide ${n+1}`},n))})]})},Mi=({onLogout:s,onOpenProfile:t})=>{const{userProfile:l}=Re(),[r,h]=i.useState("Overview"),[n,o]=i.useState(!1),[m,v]=i.useState(!1),[p,S]=i.useState(null),[f,j]=i.useState(!1),[w,A]=i.useState(!1),[k,d]=i.useState(!1),[y,L]=i.useState(null),[C,B]=i.useState(null),[q,O]=i.useState([]),[G,Y]=i.useState([]),[H,ee]=i.useState(!0),Q=u=>r===u?!0:r==="Settings"&&u!=="Settings"&&k?(S(u),v(!0),!1):(h(u),!0),oe=()=>{p&&h(p),d(!1),S(null),v(!1),A(!1)},b=()=>{S(null),v(!1)},V=u=>{Q(u)&&A(!1)},x=u=>{L(u),Q("User Management")};i.useEffect(()=>{if(r!=="Overview"||!l)return;const u=String(l.role||"").toLowerCase(),$=u==="admin"||u==="teacher";let te=!1;return ee(!0),Promise.all([rr(),$?zt():Promise.resolve([]),ir(3)]).then(([Ee,ls,Ce])=>{te||(B(Ee),O(ls.slice(0,4)),Y(Ce))}).catch(console.error).finally(()=>{te||ee(!1)}),()=>{te=!0}},[r,l]);const E=[{label:"Total Students",value:(C?.totalStudents??0).toLocaleString(),icon:Je,color:"bg-sky-100",iconColor:"text-sky-600"},{label:"Active Teachers",value:(C?.activeTeachers??0).toString(),icon:ks,color:"bg-teal-100",iconColor:"text-teal-600"},{label:"Total Classes",value:(C?.totalClasses??0).toString(),icon:je,color:"bg-sky-100",iconColor:"text-sky-600"},{label:"At-Risk Students",value:(C?.atRiskStudents??0).toString(),icon:Se,color:"bg-red-100",iconColor:"text-red-600"},{label:"Avg Performance",value:`${C?.avgPerformance??0}%`,icon:es,color:"bg-orange-100",iconColor:"text-orange-600"},{label:"AI Interactions",value:(C?.aiPredictions??0).toLocaleString(),icon:xt,color:"bg-sky-100",iconColor:"text-sky-600"}],c=u=>u==="Error"||u==="Critical"?{text:"text-red-600",bg:"bg-red-50"}:u==="Warning"?{text:"text-rose-600",bg:"bg-rose-50"}:{text:"text-sky-600",bg:"bg-sky-50"};return e.jsxs("div",{className:"flex h-screen w-full bg-[#edf1f7] overflow-hidden",children:[e.jsx("div",{className:"hidden lg:block",children:e.jsx(Fs,{activeTab:r,setActiveTab:V,userRole:"admin",onOpenSettings:()=>V("Settings"),onLogout:()=>o(!0),sidebarCollapsed:f,setSidebarCollapsed:j})}),w&&e.jsxs(e.Fragment,{children:[e.jsx("button",{"aria-label":"Close navigation",className:"fixed inset-0 z-40 bg-slate-900/40 backdrop-blur-[1px] lg:hidden",onClick:()=>A(!1)}),e.jsx("div",{className:"fixed inset-y-0 left-0 z-50 p-3 lg:hidden",children:e.jsx(Fs,{mode:"mobile",onRequestClose:()=>A(!1),activeTab:r,setActiveTab:V,userRole:"admin",onOpenSettings:()=>V("Settings"),onLogout:()=>{o(!0),A(!1)},sidebarCollapsed:!1})})]}),e.jsxs("div",{className:"flex-1 flex flex-col",children:[e.jsxs("header",{className:"bg-white/80 backdrop-blur-md border-b border-[#dde3eb] px-6 py-3 flex items-center justify-between sticky top-0 z-30",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("button",{type:"button",onClick:()=>A(!0),className:"inline-flex lg:hidden items-center justify-center w-10 h-10 rounded-xl border border-[#dde3eb] bg-white text-[#5a6578] hover:bg-[#edf1f7]","aria-label":"Open navigation",children:e.jsx(ra,{size:18})}),e.jsxs("div",{children:[e.jsxs("h1",{className:"text-xl font-display font-bold text-[#0a1628] leading-tight",children:[r==="Overview"&&"Admin Dashboard",r==="Content"&&"Content & RAG",r==="Audit Log"&&"Audit Log",r==="User Management"&&"User Management",r==="Analytics"&&"Analytics",r==="AI Monitoring"&&"AI Monitoring",r==="Settings"&&"Settings",r==="Subjects"&&"Subjects"]}),e.jsxs("p",{className:"text-xs text-[#5a6578] font-body",children:[r==="Overview"&&"System Overview & Management",r==="Content"&&"Upload PDFs for AI-powered content",r==="Audit Log"&&"Monitor system activity",r==="User Management"&&"Manage all user accounts",r==="Analytics"&&"Detailed performance metrics",r==="AI Monitoring"&&"Platform AI usage and system health",r==="Settings"&&"Configure platform settings",r==="Subjects"&&"Manage subjects and module availability"]})]})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs("button",{onClick:t,className:"flex items-center gap-2.5 h-11 shrink-0 bg-[#edf1f7] p-1.5 pr-3 rounded-lg cursor-pointer hover:bg-[#dde3eb] transition-all group",children:[e.jsx(ia,{src:l?.photo,name:l?.name||"Admin",gender:l?.gender,className:"w-8 h-8 rounded-lg"}),e.jsx("div",{className:"min-w-0 flex-1 text-left",children:e.jsx("p",{className:"text-sm font-semibold text-[#0a1628] leading-none group-hover:text-sky-600 transition-colors truncate",children:l?.name||"Admin"})})]})})]}),e.jsxs("main",{className:"flex-1 overflow-y-auto p-6",children:[r==="Overview"&&e.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-12 gap-6",children:[e.jsxs("div",{className:"xl:col-span-8 space-y-6",children:[e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4",children:E.map((u,$)=>{const te=u.icon;return e.jsxs("div",{className:"bg-white rounded-2xl p-5 shadow-sm border border-[#dde3eb] hover:shadow-md transition-all",children:[e.jsx("div",{className:"flex items-start justify-between mb-3",children:e.jsx("div",{className:`w-12 h-12 ${u.color} rounded-xl flex items-center justify-center`,children:e.jsx(te,{size:24,className:u.iconColor})})}),e.jsx("h3",{className:"text-2xl font-bold text-[#0a1628] mb-1",children:H?e.jsx("div",{className:"h-8 w-20 bg-[#edf1f7] rounded animate-pulse"}):u.value}),e.jsx("p",{className:"text-sm text-[#5a6578] font-medium",children:u.label})]},$)})}),e.jsxs("div",{className:"bg-white rounded-3xl p-6 shadow-sm border border-[#dde3eb]",children:[e.jsx("div",{className:"flex items-center justify-between mb-6",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-bold text-[#0a1628] mb-1",children:"System Performance Overview"}),e.jsx("p",{className:"text-sm text-[#5a6578]",children:"Trend visualization"})]})}),e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 gap-3",children:[e.jsx(es,{size:32,className:"text-[#dde3eb]"}),e.jsx("p",{className:"text-sm font-medium text-[#5a6578]",children:"Performance trend chart is currently unavailable"}),e.jsx("p",{className:"text-xs text-[#a0aec0]",children:"Live KPI totals are shown above. Time-series backend support is required for chart rendering."})]})]}),e.jsx($r,{}),e.jsx(Er,{}),e.jsxs("div",{className:"bg-white rounded-3xl p-6 shadow-sm border border-[#dde3eb]",children:[e.jsx("h2",{className:"text-lg font-bold text-[#0a1628] mb-5",children:"Recent System Activity"}),H?e.jsx("div",{className:"flex justify-center py-8",children:e.jsx(_,{className:"animate-spin text-sky-500"})}):q.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-10 gap-3",children:[e.jsx(Ia,{size:28,className:"text-[#dde3eb]"}),e.jsx("p",{className:"text-sm text-[#5a6578]",children:"No audit events yet"})]}):e.jsx("div",{className:"space-y-3",children:q.map(u=>{const $=c(u.severity);return e.jsxs("div",{className:`${$.bg} border border-[#dde3eb] rounded-2xl p-4 flex items-start gap-4`,children:[e.jsx("div",{className:"w-10 h-10 bg-white rounded-xl flex items-center justify-center flex-shrink-0",children:e.jsx(Ke,{size:18,className:$.text})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-bold text-[#0a1628] mb-0.5",children:u.action}),e.jsx("p",{className:"text-xs text-[#5a6578] truncate",children:u.details}),e.jsxs("p",{className:"text-xs text-[#5a6578] mt-1",children:[u.timestamp," · ",u.user.name]})]})]},u.id)})})]})]}),e.jsxs("div",{className:"xl:col-span-4 space-y-6",children:[e.jsxs("div",{className:"bg-gradient-to-br from-indigo-600 to-sky-600 rounded-3xl p-6 text-white shadow-lg",children:[e.jsx("h2",{className:"text-lg font-bold mb-4",children:"Quick Actions"}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("button",{type:"button",onClick:()=>x("Teacher"),className:"w-full bg-white/20 hover:bg-white/30 backdrop-blur-sm border border-slate-300 rounded-xl p-3 text-left transition-all",children:[e.jsx("p",{className:"text-sm font-bold",children:"Add New Teacher"}),e.jsx("p",{className:"text-xs text-sky-100",children:"Create teacher account"})]}),e.jsxs("button",{type:"button",onClick:()=>x("Student"),className:"w-full bg-white/20 hover:bg-white/30 backdrop-blur-sm border border-slate-300 rounded-xl p-3 text-left transition-all",children:[e.jsx("p",{className:"text-sm font-bold",children:"Add New Student"}),e.jsx("p",{className:"text-xs text-sky-100",children:"Register new student"})]}),e.jsxs("button",{type:"button",onClick:()=>Q("Settings"),className:"w-full bg-white/20 hover:bg-white/30 backdrop-blur-sm border border-slate-300 rounded-xl p-3 text-left transition-all",children:[e.jsx("p",{className:"text-sm font-bold",children:"System Settings"}),e.jsx("p",{className:"text-xs text-sky-100",children:"Configure platform"})]}),e.jsxs("button",{type:"button",disabled:!0,"aria-disabled":"true",title:"Report export is not available yet",className:"w-full bg-white/10 border border-slate-300/70 rounded-xl p-3 text-left opacity-60 cursor-not-allowed",children:[e.jsx("p",{className:"text-sm font-bold",children:"Generate Report"}),e.jsx("p",{className:"text-xs text-sky-100",children:"Export support is not available yet"})]})]})]}),e.jsxs("div",{className:"bg-white rounded-3xl p-6 shadow-sm border border-[#dde3eb]",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-5",children:[e.jsx("div",{className:"w-10 h-10 bg-rose-100 rounded-xl flex items-center justify-center",children:e.jsx(Ze,{size:20,className:"text-rose-600"})}),e.jsx("h2",{className:"text-lg font-bold text-[#0a1628]",children:"Top Performers"})]}),H?e.jsx("div",{className:"flex justify-center py-8",children:e.jsx(_,{className:"animate-spin text-sky-500"})}):G.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-10 gap-3",children:[e.jsx(Ze,{size:28,className:"text-[#dde3eb]"}),e.jsx("p",{className:"text-sm text-[#5a6578]",children:"No student data yet"}),e.jsx("p",{className:"text-xs text-[#a0aec0]",children:"Students will appear here as they progress."})]}):e.jsx("div",{className:"space-y-3",children:G.map((u,$)=>e.jsxs("div",{className:"bg-gradient-to-r from-rose-50 to-orange-50 border border-rose-200 rounded-2xl p-4",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx("img",{src:u.avatar,alt:u.name,className:"w-12 h-12 rounded-xl object-cover"}),e.jsx("span",{className:"absolute -top-1 -right-1 w-6 h-6 bg-rose-500 text-white text-xs font-bold rounded-full flex items-center justify-center",children:$+1})]}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h4",{className:"text-sm font-bold text-[#0a1628]",children:u.name}),e.jsx("p",{className:"text-xs text-[#5a6578]",children:u.class})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"bg-white rounded-xl p-2",children:[e.jsx("p",{className:"text-[10px] text-[#5a6578] mb-1",children:"Performance"}),e.jsxs("p",{className:"text-lg font-bold text-teal-600",children:[u.performance,"%"]})]}),e.jsxs("div",{className:"bg-white rounded-xl p-2",children:[e.jsx("p",{className:"text-[10px] text-[#5a6578] mb-1",children:"Level"}),e.jsx("p",{className:"text-lg font-bold text-sky-600",children:u.level})]})]})]},u.id))})]}),e.jsxs("div",{className:"bg-white rounded-3xl p-6 shadow-sm border border-[#dde3eb]",children:[e.jsx("h2",{className:"text-lg font-bold text-[#0a1628] mb-5",children:"AI Model Status"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-[#5a6578]",children:"AI Interactions Logged"}),e.jsx("span",{className:"text-sm font-bold text-[#0a1628]",children:H?"...":(C?.aiPredictions??0).toLocaleString()})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-[#5a6578]",children:"At-Risk Students Tracked"}),e.jsx("span",{className:"text-sm font-bold text-[#0a1628]",children:H?"...":(C?.atRiskStudents??0).toLocaleString()})]}),e.jsx("div",{className:"mt-4 p-3 bg-sky-50 border border-sky-200 rounded-xl",children:e.jsxs("p",{className:"text-xs text-sky-800",children:[e.jsx("strong",{children:"Status:"})," Model quality metrics (accuracy/drift) are unavailable in the current backend and are intentionally hidden."]})})]})]})]})]}),r==="Content"&&e.jsx(Xa,{}),r==="Audit Log"&&e.jsx(nr,{}),r==="User Management"&&e.jsx(vr,{createIntentRole:y,onCreateIntentConsumed:()=>L(null)}),r==="Analytics"&&e.jsx(Nr,{}),r==="AI Monitoring"&&e.jsx(Lr,{}),r==="Settings"&&e.jsx(mr,{onDirtyChange:d}),r==="Subjects"&&e.jsx(Mr,{})]})]}),e.jsx(vs,{isOpen:n,onClose:()=>o(!1),onConfirm:s,title:"Logout Confirmation",message:"Are you sure you want to log out? This will end your current session.",confirmText:"Logout",cancelText:"Cancel"}),e.jsx(vs,{isOpen:m,onClose:b,onConfirm:oe,title:"Discard Unsaved Changes?",message:"You have unsaved settings changes. If you continue, your edits will be discarded.",confirmText:"Discard Changes",cancelText:"Keep Editing",type:"warning",icon:"warning"})]})};export{Mi as default}; + `,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${a.status==="Active"?"bg-green-500":"bg-[#a8a5b3]"}`}),a.status]})}),e.jsx("td",{className:"px-6 py-4 text-[#5a6578]",children:a.role==="Student"&&a.classSection||a.department}),e.jsx("td",{className:"px-6 py-4 text-[#5a6578]",children:a.lastLogin||"Never"}),e.jsx("td",{className:"px-6 py-4 text-right",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:()=>Us(a),"aria-label":`Edit ${a.name}`,className:"p-1.5 text-slate-500 hover:text-sky-600 hover:bg-sky-50 rounded-lg transition-colors",children:e.jsx(Ga,{size:16})}),e.jsx("button",{type:"button",onClick:()=>Fs(a),"aria-label":a.status==="Active"?`Deactivate ${a.name}`:`Activate ${a.name}`,disabled:g||f,className:`p-1.5 rounded-lg transition-colors ${g?"opacity-60 cursor-not-allowed":""} ${a.status==="Active"?"text-slate-500 hover:text-orange-600 hover:bg-orange-50":"text-orange-500 hover:text-green-600 hover:bg-green-50"}`,title:a.status==="Active"?"Deactivate User":"Activate User",children:g?e.jsx(H,{size:16,className:"animate-spin"}):a.status==="Active"?e.jsx(Vs,{size:16}):e.jsx(Xs,{size:16})}),e.jsx("button",{type:"button",onClick:()=>$s(a.id,a.name),"aria-label":`Delete ${a.name}`,disabled:f,className:"p-1.5 text-slate-500 hover:text-red-600 hover:bg-red-50 rounded-lg transition-colors",children:e.jsx(Qs,{size:16})})]})})]},a.id)}):m?e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"px-6 py-12 text-center text-red-600",children:e.jsxs("div",{className:"flex flex-col items-center gap-3",children:[e.jsx(Se,{size:24,className:"text-red-500"}),e.jsx("p",{children:"Users could not be loaded."})]})})}):e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"px-6 py-12 text-center text-[#5a6578]",children:e.jsxs("div",{className:"flex flex-col items-center gap-3",children:[e.jsx("div",{className:"p-3 bg-[#edf1f7] rounded-full",children:e.jsx(Ze,{size:24,className:"text-slate-500"})}),e.jsx("p",{children:"No users found matching your filters"})]})})})})]})})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3 px-1",children:[e.jsxs("p",{className:"text-sm text-[#5a6578]",children:["Showing ",e.jsxs("span",{className:"font-semibold text-[#0a1628]",children:[Xt,"-",Kt]})," of"," ",e.jsx("span",{className:"font-semibold text-[#0a1628]",children:C})," users"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(M,{variant:"outline",size:"sm",className:"border-[#dde3eb]",disabled:k<=1||n||f,onClick:()=>d(a=>Math.max(a-1,1)),children:"Previous"}),e.jsxs("span",{className:"text-xs text-[#5a6578] min-w-[72px] text-center",children:["Page ",k," / ",Math.max(q,1)]}),e.jsx(M,{variant:"outline",size:"sm",className:"border-[#dde3eb]",disabled:!G||n||f||k>=q,onClick:()=>d(a=>Math.min(a+1,q||1)),children:"Next"})]})]}),e.jsx(pt,{open:Rt,onOpenChange:ze,children:e.jsxs(ft,{className:"sm:max-w-[425px]",children:[e.jsxs(bt,{children:[e.jsx(jt,{children:J?"Edit User Access":"Add New User"}),e.jsx(vt,{children:J?"Update user details and manage access permissions.":"Create a new account and send welcome credentials by email."})]}),e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsxs("div",{className:"grid gap-2 sm:grid-cols-4 sm:items-start sm:gap-4",children:[e.jsx("label",{htmlFor:"name",className:"text-left sm:text-right text-sm font-medium text-[#0a1628]",children:"Name"}),e.jsxs("div",{className:"sm:col-span-3",children:[e.jsx(R,{id:"name",value:N.name,onChange:a=>{K({...N,name:a.target.value}),D.name&&ae(g=>({...g,name:void 0}))},className:D.name?"border-red-500 focus-visible:ring-red-500":""}),D.name?e.jsx("p",{className:"mt-1 text-xs text-red-600",children:D.name}):null]})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-4 sm:items-start sm:gap-4",children:[e.jsx("label",{htmlFor:"email",className:"text-left sm:text-right text-sm font-medium text-[#0a1628]",children:"Email"}),e.jsxs("div",{className:"sm:col-span-3",children:[e.jsx(R,{id:"email",type:"email",value:N.email,onChange:a=>{J||(K({...N,email:a.target.value}),D.email&&ae(g=>({...g,email:void 0})))},readOnly:!!J,"aria-readonly":!!J,className:`${D.email?"border-red-500 focus-visible:ring-red-500":""} ${J?"bg-[#edf1f7] text-[#5a6578] cursor-not-allowed":""}`}),D.email?e.jsx("p",{className:"mt-1 text-xs text-red-600",children:D.email}):null,J?e.jsx("p",{className:"mt-1 text-xs text-[#5a6578]",children:"Email changes are disabled because authentication email updates are not supported in this panel."}):null]})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-4 sm:items-start sm:gap-4",children:[e.jsx("label",{htmlFor:"role",className:"text-left sm:text-right text-sm font-medium text-[#0a1628]",children:"Role"}),e.jsxs("div",{className:"sm:col-span-3",children:[e.jsxs(re,{value:N.role,onValueChange:a=>{K({...N,role:a,lrn:a==="Student"?N.lrn:""}),ae(g=>({...g,role:void 0,lrn:void 0}))},children:[e.jsx(le,{className:D.role?"border-red-500 focus:ring-red-500":"",children:e.jsx(ie,{placeholder:"Select role"})}),e.jsxs(ne,{children:[e.jsx(P,{value:"Student",children:"Student"}),e.jsx(P,{value:"Teacher",children:"Teacher"}),e.jsx(P,{value:"Admin",children:"Admin"})]})]}),D.role?e.jsx("p",{className:"mt-1 text-xs text-red-600",children:D.role}):null]})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-4 sm:items-start sm:gap-4",children:[e.jsx("label",{htmlFor:"status",className:"text-left sm:text-right text-sm font-medium text-[#0a1628]",children:"Status"}),e.jsxs("div",{className:"sm:col-span-3",children:[e.jsxs(re,{value:N.status,onValueChange:a=>{K({...N,status:a}),D.status&&ae(g=>({...g,status:void 0}))},children:[e.jsx(le,{className:D.status?"border-red-500 focus:ring-red-500":"",children:e.jsx(ie,{placeholder:"Select status"})}),e.jsxs(ne,{children:[e.jsx(P,{value:"Active",children:"Active"}),e.jsx(P,{value:"Inactive",children:"Inactive"})]})]}),D.status?e.jsx("p",{className:"mt-1 text-xs text-red-600",children:D.status}):null]})]}),J?N.role==="Student"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-2 sm:grid-cols-4 sm:items-center sm:gap-4",children:[e.jsx("label",{htmlFor:"lrn",className:"text-left sm:text-right text-sm font-medium text-[#0a1628]",children:"LRN"}),e.jsx(R,{id:"lrn",value:N.lrn,onChange:a=>K({...N,lrn:a.target.value}),placeholder:"12-digit learner reference",className:"sm:col-span-3"})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-4 sm:items-center sm:gap-4",children:[e.jsx("label",{htmlFor:"grade",className:"text-left sm:text-right text-sm font-medium text-[#0a1628]",children:"Grade"}),e.jsx(R,{id:"grade",value:N.grade,onChange:a=>K({...N,grade:a.target.value}),placeholder:"e.g. Grade 11",className:"sm:col-span-3"})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-4 sm:items-center sm:gap-4",children:[e.jsx("label",{htmlFor:"section",className:"text-left sm:text-right text-sm font-medium text-[#0a1628]",children:"Section"}),e.jsx(R,{id:"section",value:N.section,onChange:a=>K({...N,section:a.target.value}),placeholder:"e.g. STEM A",className:"sm:col-span-3"})]})]}):e.jsxs("div",{className:"grid gap-2 sm:grid-cols-4 sm:items-center sm:gap-4",children:[e.jsx("label",{htmlFor:"department",className:"text-left sm:text-right text-sm font-medium text-[#0a1628]",children:"Department"}),e.jsx(R,{id:"department",value:N.department,onChange:a=>K({...N,department:a.target.value}),placeholder:"e.g. Mathematics",className:"sm:col-span-3"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-2 sm:grid-cols-4 sm:items-start sm:gap-4",children:[e.jsx("label",{htmlFor:"grade",className:"text-left sm:text-right text-sm font-medium text-[#0a1628]",children:"Grade"}),e.jsxs("div",{className:"sm:col-span-3",children:[e.jsx(R,{id:"grade",value:N.grade,onChange:a=>{K({...N,grade:a.target.value}),D.grade&&ae(g=>({...g,grade:void 0}))},placeholder:"e.g. Grade 11",className:D.grade?"border-red-500 focus-visible:ring-red-500":""}),D.grade?e.jsx("p",{className:"mt-1 text-xs text-red-600",children:D.grade}):null]})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-4 sm:items-start sm:gap-4",children:[e.jsx("label",{htmlFor:"section",className:"text-left sm:text-right text-sm font-medium text-[#0a1628]",children:"Section"}),e.jsxs("div",{className:"sm:col-span-3",children:[e.jsx(R,{id:"section",value:N.section,onChange:a=>{K({...N,section:a.target.value}),D.section&&ae(g=>({...g,section:void 0}))},placeholder:"e.g. STEM A",className:D.section?"border-red-500 focus-visible:ring-red-500":""}),D.section?e.jsx("p",{className:"mt-1 text-xs text-red-600",children:D.section}):null]})]}),N.role==="Student"?e.jsxs("div",{className:"grid gap-2 sm:grid-cols-4 sm:items-start sm:gap-4",children:[e.jsx("label",{htmlFor:"lrn",className:"text-left sm:text-right text-sm font-medium text-[#0a1628]",children:"LRN"}),e.jsxs("div",{className:"sm:col-span-3",children:[e.jsx(R,{id:"lrn",value:N.lrn,onChange:a=>{K({...N,lrn:a.target.value}),D.lrn&&ae(g=>({...g,lrn:void 0}))},placeholder:"Required for student accounts",className:D.lrn?"border-red-500 focus-visible:ring-red-500":""}),D.lrn?e.jsx("p",{className:"mt-1 text-xs text-red-600",children:D.lrn}):null]})]}):null,e.jsxs("div",{className:"grid gap-2 sm:grid-cols-4 sm:items-start sm:gap-4",children:[e.jsx("label",{htmlFor:"password",className:"text-left sm:text-right text-sm font-medium text-[#0a1628]",children:"Password"}),e.jsxs("div",{className:"sm:col-span-3 relative",children:[e.jsx(R,{id:"password",type:us?"text":"password",value:N.password,onChange:a=>{K({...N,password:a.target.value}),D.password&&ae(g=>({...g,password:void 0}))},placeholder:"Min 8 chars, upper/lowercase, number, and symbol",className:D.password?"border-red-500 focus-visible:ring-red-500 pr-10 ":"pr-10 "}),e.jsx("button",{type:"button",onClick:()=>Pe(!us),className:"absolute right-3 top-1/2 -translate-y-1/2 text-slate-400 hover:text-slate-600 transition-colors",tabIndex:-1,children:us?e.jsx(rs,{size:16}):e.jsx(Hs,{size:16})}),D.password?e.jsx("p",{className:"mt-1 text-xs text-red-600",children:D.password}):null]})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-4 sm:items-start sm:gap-4",children:[e.jsx("label",{htmlFor:"confirmPassword",className:"text-left sm:text-right text-sm font-medium text-[#0a1628]",children:"Confirm"}),e.jsxs("div",{className:"sm:col-span-3 relative",children:[e.jsx(R,{id:"confirmPassword",type:hs?"text":"password",value:N.confirmPassword,onChange:a=>{K({...N,confirmPassword:a.target.value}),D.confirmPassword&&ae(g=>({...g,confirmPassword:void 0}))},placeholder:"Retype password",className:D.confirmPassword?"border-red-500 focus-visible:ring-red-500 pr-10 ":"pr-10 "}),e.jsx("button",{type:"button",onClick:()=>De(!hs),className:"absolute right-3 top-1/2 -translate-y-1/2 text-slate-400 hover:text-slate-600 transition-colors",tabIndex:-1,children:hs?e.jsx(rs,{size:16}):e.jsx(Hs,{size:16})}),D.confirmPassword?e.jsx("p",{className:"mt-1 text-xs text-red-600",children:D.confirmPassword}):null]})]})]})]}),e.jsxs(da,{children:[e.jsx(M,{variant:"outline",onClick:()=>{ze(!1),Pe(!1),De(!1)},disabled:p,children:"Cancel"}),e.jsxs(M,{onClick:Ft,className:"bg-sky-600 hover:bg-sky-700 text-white",disabled:p,children:[p?e.jsx(H,{size:16,className:"animate-spin mr-2"}):null,J?"Save Changes":"Create User & Send Email"]})]})]})}),e.jsx(Ns,{isOpen:Et,onClose:()=>{$e||(ms(!1),xs(null))},onConfirm:$t,title:xe?.title||"Confirm Action",message:xe?.message||"Proceed with this action?",confirmText:$e?"Processing...":xe?.confirmText||"Confirm",cancelText:"Cancel",type:"danger",icon:"delete"})]})},Te=({icon:s,title:t,subtitle:i})=>e.jsxs("div",{className:"flex flex-col items-center justify-center gap-3 py-10 text-center",children:[e.jsx("div",{className:"w-12 h-12 rounded-full bg-[#edf1f7] flex items-center justify-center",children:s}),e.jsx("p",{className:"text-sm font-semibold text-[#5a6578]",children:t}),i&&e.jsx("p",{className:"text-xs text-[#a0aec0] max-w-xs",children:i})]}),fr=()=>{const[s,t]=l.useState("30d"),[i,r]=l.useState(null),[h,n]=l.useState(!0);l.useEffect(()=>{tr().then(r).catch(console.error).finally(()=>n(!1))},[]);const o={"7d":"Last 7 Days","30d":"Last 30 Days","90d":"Last 90 Days","12m":"Last 12 Months"},m=[{label:"Total Active Users",value:h?null:(i?.totalActiveUsers??0).toLocaleString(),icon:Ze,color:"from-sky-500 to-blue-600"},{label:"Avg. Completion Rate",value:"N/A",icon:ut,color:"from-teal-500 to-emerald-600"},{label:"Avg. Session Duration",value:"N/A",icon:At,color:"from-violet-500 to-purple-600"},{label:"At-Risk Students",value:h?null:(i?.atRiskStudents??0).toString(),icon:ws,color:"from-rose-500 to-orange-600"}],v=[{label:"Achievements Unlocked",icon:Ye,color:"text-rose-600",bg:"bg-rose-50",value:h?null:(i?.achievementsUnlocked??0).toLocaleString()},{label:"XP Earned (Platform)",icon:xt,color:"text-violet-600",bg:"bg-violet-50",value:h?null:(i?.totalXPEarned??0)>=1e6?`${((i?.totalXPEarned??0)/1e6).toFixed(1)}M`:(i?.totalXPEarned??0)>=1e3?`${Math.round((i?.totalXPEarned??0)/1e3)}K`:(i?.totalXPEarned??0).toLocaleString()},{label:"Active Streaks",icon:ht,color:"text-orange-600",bg:"bg-orange-50",value:h?null:(i?.activeStreaks??0).toLocaleString()},{label:"AI Tutor Sessions",icon:ta,color:"text-sky-600",bg:"bg-sky-50",value:h?null:(i?.aiTutorSessions??0).toLocaleString()}];return e.jsxs("div",{className:"space-y-6",children:[e.jsxs(U.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.3},className:"flex items-center justify-between",children:[e.jsx("div",{className:"flex items-center gap-2 bg-white rounded-xl p-1 shadow-sm border border-[#dde3eb]",children:Object.entries(o).map(([p,S])=>e.jsx("button",{onClick:()=>t(p),disabled:!0,title:"Range selection is unavailable until backend range queries are supported.",className:`px-4 py-2 rounded-lg text-sm font-semibold transition-all ${s===p?"bg-sky-600 text-white shadow-sm":"text-[#5a6578] hover:bg-[#edf1f7]"} opacity-60 cursor-not-allowed`,children:S},p))}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(M,{variant:"outline",disabled:!0,title:"Advanced analytics filters are not implemented yet",className:"px-4 py-2 gap-2 rounded-xl border-[#dde3eb] font-semibold text-sm opacity-50 cursor-not-allowed",children:[e.jsx(va,{size:16}),"Filters"]}),e.jsxs(M,{variant:"outline",disabled:!0,title:"Export is unavailable until backend report generation is implemented",className:"px-4 py-2 gap-2 rounded-xl border-[#dde3eb] font-semibold text-sm opacity-50 cursor-not-allowed",children:[e.jsx(Ct,{size:16}),"Export"]})]})]}),e.jsx("p",{className:"text-xs text-[#5a6578] -mt-3",children:"Time-range filtering is currently disabled because analytics range queries are not yet supported by the backend."}),!h&&!i?.totalActiveUsers&&e.jsxs(U.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{duration:.35},className:"flex items-center gap-3 bg-rose-50 border border-rose-200 rounded-2xl px-5 py-4",children:[e.jsx(Oe,{size:18,className:"text-rose-600 shrink-0"}),e.jsxs("p",{className:"text-sm text-rose-800",children:[e.jsx("span",{className:"font-semibold",children:"Limited analytics data."})," ","KPI cards will populate automatically as students, quizzes, and sessions accumulate in the platform. Chart visualisations require time-series data."]})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-4 gap-4",children:m.map((p,S)=>{const f=p.icon;return e.jsxs(U.div,{initial:{opacity:0,y:16},animate:{opacity:1,y:0},transition:{duration:.35,delay:S*.06},className:"bg-white rounded-2xl p-5 shadow-sm border border-[#dde3eb]",children:[e.jsx("div",{className:"flex items-start justify-between mb-3",children:e.jsx("div",{className:`w-11 h-11 rounded-xl bg-gradient-to-br ${p.color} flex items-center justify-center shadow-sm`,children:e.jsx(f,{size:20,className:"text-white"})})}),h?e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(H,{size:16,className:"animate-spin text-[#a0aec0]"}),e.jsx("div",{className:"w-14 h-6 bg-[#edf1f7] rounded-lg animate-pulse"})]}):e.jsx("p",{className:"text-2xl font-bold text-[#0a1628] mb-2",children:p.value}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"text-sm text-[#5a6578] font-medium",children:p.label}),e.jsx("span",{className:"text-xs text-[#a0aec0] font-medium",children:o[s]})]})]},p.label)})}),e.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-12 gap-6",children:[e.jsxs(U.div,{initial:{opacity:0,y:16},animate:{opacity:1,y:0},transition:{duration:.4,delay:.15},className:"xl:col-span-8 bg-white rounded-2xl p-6 shadow-sm border border-[#dde3eb]",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-bold text-[#0a1628]",children:"Performance Trends"}),e.jsx("p",{className:"text-sm text-[#5a6578]",children:"Average scores — students vs. teacher targets"})]}),e.jsxs("div",{className:"flex items-center gap-4 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-3 h-3 rounded-full bg-sky-300"}),e.jsx("span",{className:"text-[#a0aec0] font-medium",children:"Students"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-3 h-3 rounded-full bg-violet-300"}),e.jsx("span",{className:"text-[#a0aec0] font-medium",children:"Teacher Targets"})]})]})]}),e.jsx(Te,{icon:e.jsx(ss,{size:24,className:"text-[#c2cad8]"}),title:"No performance data yet",subtitle:"Import student and class records to generate trend charts."})]}),e.jsxs(U.div,{initial:{opacity:0,y:16},animate:{opacity:1,y:0},transition:{duration:.4,delay:.2},className:"xl:col-span-4 bg-white rounded-2xl p-6 shadow-sm border border-[#dde3eb]",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx("div",{className:"w-10 h-10 bg-violet-100 rounded-xl flex items-center justify-center",children:e.jsx(La,{size:20,className:"text-violet-400"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-bold text-[#0a1628]",children:"Grade Distribution"}),e.jsx("p",{className:"text-xs text-[#5a6578]",children:"All students, current term"})]})]}),e.jsx(Te,{icon:e.jsx(Oe,{size:24,className:"text-[#c2cad8]"}),title:"No grade data",subtitle:"Import quiz and assessment results to see grade breakdowns."})]})]}),e.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-12 gap-6",children:[e.jsxs(U.div,{initial:{opacity:0,y:16},animate:{opacity:1,y:0},transition:{duration:.4,delay:.25},className:"xl:col-span-7 bg-white rounded-2xl p-6 shadow-sm border border-[#dde3eb]",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx("div",{className:"w-10 h-10 bg-sky-100 rounded-xl flex items-center justify-center",children:e.jsx(je,{size:20,className:"text-sky-400"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-bold text-[#0a1628]",children:"Subject Engagement"}),e.jsx("p",{className:"text-xs text-[#5a6578]",children:"Enrollment, completion, and average scores"})]})]}),e.jsx("div",{className:"overflow-hidden rounded-xl border border-[#dde3eb]",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-[#f7f9fc]",children:[e.jsx("th",{className:"text-left text-xs font-semibold text-[#5a6578] px-4 py-3",children:"Subject"}),e.jsx("th",{className:"text-right text-xs font-semibold text-[#5a6578] px-4 py-3",children:"Enrolled"}),e.jsx("th",{className:"text-right text-xs font-semibold text-[#5a6578] px-4 py-3",children:"Completion"}),e.jsx("th",{className:"text-right text-xs font-semibold text-[#5a6578] px-4 py-3",children:"Avg. Score"}),e.jsx("th",{className:"text-left text-xs font-semibold text-[#5a6578] px-4 py-3 w-36",children:"Progress"})]})}),e.jsx("tbody",{children:e.jsx("tr",{children:e.jsx("td",{colSpan:5,className:"px-4 py-10",children:e.jsx(Te,{icon:e.jsx(Oe,{size:22,className:"text-[#c2cad8]"}),title:"No subject data available",subtitle:"Import class enrollment records to view subject engagement."})})})})]})})]}),e.jsxs(U.div,{initial:{opacity:0,y:16},animate:{opacity:1,y:0},transition:{duration:.4,delay:.3},className:"xl:col-span-5 bg-white rounded-2xl p-6 shadow-sm border border-[#dde3eb]",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx("div",{className:"w-10 h-10 bg-orange-100 rounded-xl flex items-center justify-center",children:e.jsx(ys,{size:20,className:"text-orange-400"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-bold text-[#0a1628]",children:"Weekly Activity"}),e.jsx("p",{className:"text-xs text-[#5a6578]",children:"Sessions per day of week"})]})]}),e.jsx(Te,{icon:e.jsx(ws,{size:24,className:"text-[#c2cad8]"}),title:"No session activity yet",subtitle:"Student logins and session data will appear here after data is imported."})]})]}),e.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-12 gap-6",children:[e.jsxs(U.div,{initial:{opacity:0,y:16},animate:{opacity:1,y:0},transition:{duration:.4,delay:.35},className:"xl:col-span-5 bg-white rounded-2xl p-6 shadow-sm border border-[#dde3eb]",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx("div",{className:"w-10 h-10 bg-rose-100 rounded-xl flex items-center justify-center",children:e.jsx(Ye,{size:20,className:"text-rose-400"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-bold text-[#0a1628]",children:"Gamification Overview"}),e.jsx("p",{className:"text-xs text-[#5a6578]",children:"Engagement & motivation metrics"})]})]}),e.jsx("div",{className:"grid grid-cols-2 gap-3",children:v.map(p=>{const S=p.icon;return e.jsxs("div",{className:`${p.bg} border border-[#dde3eb] rounded-xl p-4`,children:[e.jsx(S,{size:20,className:p.color}),h?e.jsx("div",{className:"w-12 h-5 bg-white/60 rounded mt-2 mb-1 animate-pulse"}):e.jsx("p",{className:"text-lg font-bold text-[#0a1628] mt-2 mb-1",children:p.value}),e.jsx("p",{className:"text-xs text-[#5a6578] font-medium",children:p.label})]},p.label)})})]}),e.jsxs(U.div,{initial:{opacity:0,y:16},animate:{opacity:1,y:0},transition:{duration:.4,delay:.4},className:"xl:col-span-7 bg-white rounded-2xl p-6 shadow-sm border border-[#dde3eb]",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx("div",{className:"w-10 h-10 bg-teal-100 rounded-xl flex items-center justify-center",children:e.jsx(Cs,{size:20,className:"text-teal-400"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-bold text-[#0a1628]",children:"Top Performing Classes"}),e.jsx("p",{className:"text-xs text-[#5a6578]",children:"Ranked by average score this term"})]})]}),e.jsx(Te,{icon:e.jsx(Oe,{size:24,className:"text-[#c2cad8]"}),title:"No class data yet",subtitle:"Import class and student records to see top performers ranked here."})]})]})]})};function br(s){return!s||s.length===0?"Healthy":s.some(t=>t.status==="Down")?"Down":s.some(t=>t.status==="Degraded")?"Degraded":"Healthy"}function jr(s){return s.reduce((t,i)=>t+(i.estimatedCostUSD||0),0)}function vr(s){return!s||s.length===0?null:s.reduce((t,i)=>t.estimatedCostUSD>i.estimatedCostUSD?t:i)}function Nr(s){return!s||s.length===0?null:s.reduce((t,i)=>t.requestCount>i.requestCount?t:i)}function yr(s){const t=new Date().toISOString().slice(0,7),[i,r]=l.useState([]),[h,n]=l.useState(!0),[o,m]=l.useState(null),[v,p]=l.useState(0),S=l.useCallback(()=>{p(f=>f+1)},[]);return l.useEffect(()=>{let f=!0;n(!0),m(null);const j=as(se(X,"aiUsageLogs"),ks("month","==",t)),w=ma(j,A=>{if(!f)return;const k=[];A.forEach(d=>{const y=d.data();k.push(y)}),r(k),n(!1)},A=>{f&&(console.error("[useAIMonitoring] Firestore error:",A),m("Failed to load AI usage data. Please try again."),n(!1))});return()=>{f=!1,w()}},[t,v]),{stats:i,systemHealth:br(i),totalSpend:jr(i),highestCostFeature:vr(i),mostActiveFeature:Nr(i),isLoading:h,error:o,refresh:S}}const wr=[{id:"ai-chat",name:"AI Chat Tutor",description:"On-demand math help for students via DeepSeek with streaming responses"},{id:"quiz-generation",name:"Quiz Generation",description:"AI-powered quiz creation from imported topics and curriculum"},{id:"lesson-generation",name:"Lesson Generation",description:"AI-generated lesson plans grounded on imported topics and class signals"},{id:"learning-paths",name:"Learning Paths",description:"Personalized study plan generation based on student weaknesses"},{id:"risk-classification",name:"Risk Classification",description:"Student at-risk identification using AI structured output and ML scoring"},{id:"daily-insights",name:"Daily AI Insights",description:"Daily AI-powered analytics and recommendations for teachers"},{id:"solution-verification",name:"Solution Verification",description:"Multi-method math solution checking with self-consistency and code execution"},{id:"curriculum-search",name:"Curriculum Search",description:"Embedding-based search over lesson content and curriculum materials"},{id:"content-processing",name:"Content Processing",description:"AI column detection and topic extraction from uploaded files"},{id:"auto-feedback",name:"Auto Feedback",description:"Instant feedback and explanations for student quiz responses"}],Qe={"ai-chat":35,"quiz-generation":18,"lesson-generation":12,"learning-paths":8,"risk-classification":6,"daily-insights":5,"solution-verification":6,"curriculum-search":4,"content-processing":3,"auto-feedback":3};function Sr(s){if(!s)return"N/A";try{return new Date(s).toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}catch{return"N/A"}}function Ne(s){return s>=1?`$${s.toFixed(2)}`:`$${s.toFixed(4)}`}function Ve(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function kr(s){const t=s.reduce((o,m)=>o+m.requestCount,0),i=s.reduce((o,m)=>o+m.estimatedCostUSD,0),r=new Date().toISOString(),h=wr.map(o=>{const m=s.find(j=>{const w=j.featureName.toLowerCase().replace(/[^a-z0-9]/g,""),A=o.name.toLowerCase().replace(/[^a-z0-9]/g,"");return w.includes(A)||A.includes(w)}),v=m?.requestCount??Math.round(t*(Qe[o.id]??1)/100),p=m?.estimatedCostUSD??i*(Qe[o.id]??1)/100,S=m?m.status==="Degraded"?"Warning":m.status==="Down"?"Offline":"Healthy":"Healthy",f=m?m.priority==="High"?"High":m.priority==="Medium"?"Medium":"Low":Qe[o.id]>=20?"High":Qe[o.id]>=8?"Medium":"Low";return{...o,status:S,requests:v,estimatedCost:p,avgCostPerRequest:v>0?p/v:0,usageLevel:f,lastActiveAt:m?.lastUpdated?.toDate().toISOString()??r,trend:"Stable"}}),n=h.reduce((o,m)=>o+m.estimatedCost,0);return h.map(o=>({...o,costPercent:n>0?o.estimatedCost/n*100:0}))}function Cr(s,t){const i=[],r=t.filter(m=>m.status==="Degraded");r.length>0&&i.push({id:"degraded",severity:"warning",message:`${r.length} AI feature(s) are in degraded state`});const h=t.filter(m=>m.status==="Down");h.length>0&&i.push({id:"offline",severity:"critical",message:`${h[0].featureName} is currently unavailable`});const n=s.find(m=>m.id==="ai-chat");n&&n.costPercent&&n.costPercent>40&&i.push({id:"chatcost",severity:"info",message:"AI Chat Tutor is driving most of the AI spend this period"});const o=s.find(m=>m.id==="quiz-generation");return o&&o.costPercent&&o.costPercent>25&&i.push({id:"quizcost",severity:"info",message:"Quiz Generation is using more AI resources than usual"}),i}function We({status:s,loading:t}){const r={Healthy:{label:"Healthy",className:"text-emerald-700 bg-emerald-50 border-emerald-200",icon:ts,iconClass:"text-emerald-500"},Warning:{label:"Needs Attention",className:"text-amber-700 bg-amber-50 border-amber-200",icon:oe,iconClass:"text-amber-500"},Offline:{label:"Offline",className:"text-rose-700 bg-rose-50 border-rose-200",icon:oe,iconClass:"text-rose-500"}}[s];return t?e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-3 py-1 rounded-full text-xs font-bold bg-slate-100 text-slate-400 border border-slate-200",children:[e.jsx(ws,{size:12,className:"animate-pulse"}),"Checking..."]}):e.jsxs("span",{className:`inline-flex items-center gap-1.5 px-3 py-1 rounded-full text-xs font-bold border ${r.className}`,children:[e.jsx(r.icon,{size:12,className:r.iconClass}),r.label]})}function nt({level:s}){const t={Low:"bg-slate-100 text-slate-600 border-slate-200",Medium:"bg-sky-50 text-sky-700 border-sky-200",High:"bg-violet-50 text-violet-700 border-violet-200"};return e.jsx("span",{className:`inline-flex px-2 py-0.5 rounded-full text-xs font-semibold border ${t[s]}`,children:s})}function Ar({trend:s}){if(!s)return null;const i={Up:{label:"↑ Up",className:"text-emerald-600 bg-emerald-50"},Stable:{label:"→ Stable",className:"text-slate-600 bg-slate-50"},Down:{label:"↓ Down",className:"text-rose-600 bg-rose-50"}}[s];return e.jsx("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-semibold ${i.className}`,children:i.label})}function Le({title:s,subtitle:t,testId:i}){return e.jsxs("div",{className:"mb-4","data-testid":i,children:[e.jsx("h2",{className:"text-base font-semibold text-[#0a1628]",children:s}),t&&e.jsx("p",{className:"text-sm text-[#5a6578] mt-0.5",children:t})]})}const zr=()=>{const{stats:s,systemHealth:t,totalSpend:i,highestCostFeature:r,mostActiveFeature:h,isLoading:n,error:o,refresh:m}=yr(),v=new Date().toLocaleString("default",{month:"long",year:"numeric"}),p=l.useMemo(()=>kr(s),[s]),S=l.useMemo(()=>Cr(p,s),[p,s]),f=i,j=l.useMemo(()=>[...p].sort((d,y)=>y.estimatedCost-d.estimatedCost),[p]),w=l.useMemo(()=>[...p].sort((d,y)=>y.requests-d.requests),[p]),A=r?{name:r.featureName,estimatedCost:r.estimatedCostUSD,costPercent:f>0?r.estimatedCostUSD/f*100:0}:null,k=h?{name:h.featureName,requests:h.requestCount}:null;return e.jsxs("div",{className:"space-y-8","data-testid":"ai-usage-dashboard",children:[e.jsxs(U.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.3},className:"flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-[#0a1628]",children:"AI Usage Dashboard"}),e.jsx("p",{className:"text-sm text-[#5a6578]",children:"Track where AI is being used, what it costs, and what needs attention"})]}),e.jsxs(M,{variant:"outline",size:"sm",className:"text-xs gap-1.5 shrink-0",onClick:m,disabled:n,"data-testid":"refresh-btn",children:[e.jsx(Re,{size:13,className:n?"animate-spin":""}),"Refresh"]})]}),o&&e.jsxs(U.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:"flex items-center gap-3 bg-rose-50 border border-rose-200 rounded-2xl px-5 py-4",children:[e.jsx(oe,{size:18,className:"text-rose-600 shrink-0"}),e.jsx("p",{className:"text-sm text-rose-800",children:o})]}),!n&&!o&&s.length===0&&e.jsxs("div",{className:"mb-6 bg-sky-50 border border-sky-200 rounded-2xl px-5 py-4 flex items-center gap-3",children:[e.jsx(we,{size:18,className:"text-sky-600 shrink-0"}),e.jsxs("p",{className:"text-sm text-sky-800",children:["No AI usage data recorded yet for ",v,". Data will appear here once AI features are used."]})]}),e.jsxs(U.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.35,delay:.05},className:"grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"bg-white rounded-2xl p-5 shadow-sm border border-[#dde3eb]","data-testid":"summary-ai-status",children:[e.jsx("div",{className:"flex items-center gap-2 mb-3",children:e.jsx("div",{className:`w-10 h-10 rounded-xl flex items-center justify-center shadow-sm ${t==="Healthy"?"bg-gradient-to-br from-emerald-400 to-emerald-600":t==="Degraded"?"bg-gradient-to-br from-amber-400 to-amber-600":"bg-gradient-to-br from-rose-400 to-rose-600"}`,children:t==="Healthy"?e.jsx(ts,{size:18,className:"text-white"}):t==="Degraded"?e.jsx(oe,{size:18,className:"text-white"}):e.jsx(oe,{size:18,className:"text-white"})})}),n?e.jsx(Z,{className:"w-28 h-8 rounded-lg mb-2"}):e.jsx("p",{className:"text-2xl font-bold text-[#0a1628] mb-1",children:t==="Healthy"?"Healthy":t==="Degraded"?"Needs Attention":"Partial Outage"}),e.jsx("p",{className:"text-xs text-[#5a6578] font-medium",children:t==="Healthy"?"Most AI features are working normally":t==="Degraded"?"Some AI features need attention":"Several AI features are unavailable"})]}),e.jsxs("div",{className:"bg-white rounded-2xl p-5 shadow-sm border border-[#dde3eb]","data-testid":"summary-ai-cost",children:[e.jsx("div",{className:"flex items-center gap-2 mb-3",children:e.jsx("div",{className:"w-10 h-10 rounded-xl bg-gradient-to-br from-violet-500 to-purple-700 flex items-center justify-center shadow-sm",children:e.jsx(Ws,{size:18,className:"text-white"})})}),n?e.jsx(Z,{className:"w-24 h-8 rounded-lg mb-2"}):e.jsx("p",{className:"text-2xl font-bold text-[#0a1628] mb-1",children:s.length===0?"No data":Ne(f)}),e.jsx("p",{className:"text-xs text-[#5a6578] font-medium",children:n?"...":"Total AI spend this month"}),!n&&i>0&&e.jsx("p",{className:"text-xs text-[#a0aec0] mt-1",children:"Cumulative AI cost for current period"})]}),e.jsxs("div",{className:"bg-white rounded-2xl p-5 shadow-sm border border-[#dde3eb]","data-testid":"summary-most-expensive",children:[e.jsx("div",{className:"flex items-center gap-2 mb-3",children:e.jsx("div",{className:"w-10 h-10 rounded-xl bg-gradient-to-br from-amber-400 to-orange-600 flex items-center justify-center shadow-sm",children:e.jsx(gt,{size:18,className:"text-white"})})}),n?e.jsx(Z,{className:"w-32 h-8 rounded-lg mb-2"}):e.jsx("p",{className:"text-2xl font-bold text-[#0a1628] mb-1 truncate",children:A?.name??"N/A"}),e.jsx("p",{className:"text-xs text-[#5a6578] font-medium",children:n?"...":"Highest AI cost this month"}),!n&&A&&e.jsxs("p",{className:"text-xs text-[#a0aec0] mt-1",children:[Ne(A.estimatedCost)," ·"," ",A.costPercent?.toFixed(0),"% of total"]})]}),e.jsxs("div",{className:"bg-white rounded-2xl p-5 shadow-sm border border-[#dde3eb]","data-testid":"summary-top-activity",children:[e.jsx("div",{className:"flex items-center gap-2 mb-3",children:e.jsx("div",{className:"w-10 h-10 rounded-xl bg-gradient-to-br from-sky-400 to-blue-600 flex items-center justify-center shadow-sm",children:e.jsx(ht,{size:18,className:"text-white"})})}),n?e.jsx(Z,{className:"w-32 h-8 rounded-lg mb-2"}):e.jsx("p",{className:"text-2xl font-bold text-[#0a1628] mb-1 truncate",children:k?.name??"N/A"}),e.jsx("p",{className:"text-xs text-[#5a6578] font-medium",children:n?"...":"Most active AI feature"}),!n&&k&&e.jsxs("p",{className:"text-xs text-[#a0aec0] mt-1",children:[Ve(k.requests)," requests"]})]})]}),e.jsxs("section",{"data-testid":"section-ai-usage-areas",children:[e.jsx(Le,{title:"Where AI is used",subtitle:"All AI-powered features in the platform",testId:"section-ai-usage-areas-header"}),n?e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4",children:Array.from({length:6}).map((d,y)=>e.jsxs("div",{className:"bg-white rounded-2xl p-5 shadow-sm border border-[#dde3eb]",children:[e.jsx(Z,{className:"w-32 h-5 rounded mb-3"}),e.jsx(Z,{className:"w-full h-4 rounded mb-2"}),e.jsx(Z,{className:"w-24 h-4 rounded"})]},y))}):e.jsx(U.div,{initial:"hidden",animate:"show",variants:{hidden:{},show:{transition:{staggerChildren:.05}}},className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4",children:p.map(d=>e.jsxs(U.div,{variants:{hidden:{opacity:0,y:8},show:{opacity:1,y:0}},className:"bg-white rounded-2xl p-5 shadow-sm border border-[#dde3eb] hover:shadow-md transition-shadow",children:[e.jsxs("div",{className:"flex items-start justify-between mb-2",children:[e.jsx("h3",{className:"text-sm font-semibold text-[#0a1628] leading-tight",children:d.name}),e.jsx(We,{status:d.status})]}),e.jsx("p",{className:"text-xs text-[#5a6578] mb-3 leading-relaxed",children:d.description}),e.jsxs("div",{className:"flex items-center gap-3 text-xs text-[#5a6578]",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(xa,{size:12}),Ve(d.requests)," requests"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Ws,{size:12}),Ne(d.estimatedCost)]}),e.jsx(nt,{level:d.usageLevel})]})]},d.id))})]}),e.jsxs("section",{"data-testid":"section-highest-cost",children:[e.jsx(Le,{title:"What costs the most",subtitle:"AI features ranked by estimated spend this month",testId:"section-highest-cost-header"}),n?e.jsx("div",{className:"space-y-3",children:Array.from({length:5}).map((d,y)=>e.jsx("div",{className:"bg-white rounded-2xl p-4 shadow-sm border border-[#dde3eb]",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(Z,{className:"w-6 h-6 rounded-full"}),e.jsxs("div",{className:"flex-1",children:[e.jsx(Z,{className:"w-40 h-4 rounded mb-2"}),e.jsx(Z,{className:"w-full h-2 rounded-full"})]})]})},y))}):e.jsx("div",{className:"space-y-3",children:j.slice(0,7).map((d,y)=>e.jsxs(U.div,{initial:{opacity:0,x:-8},animate:{opacity:1,x:0},transition:{duration:.25,delay:y*.04},className:"bg-white rounded-2xl p-4 shadow-sm border border-[#dde3eb] flex items-center gap-4",children:[e.jsx("div",{className:`w-8 h-8 rounded-full flex items-center justify-center shrink-0 text-xs font-bold ${y===0?"bg-amber-100 text-amber-700":y===1?"bg-slate-100 text-slate-600":y===2?"bg-orange-100 text-orange-700":"bg-slate-50 text-slate-400"}`,children:y+1}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-semibold text-[#0a1628]",children:d.name}),e.jsx(We,{status:d.status})]}),e.jsxs("div",{className:"flex items-center gap-3 text-xs",children:[e.jsx("span",{className:"font-semibold text-[#0a1628]",children:Ne(d.estimatedCost)}),e.jsxs("span",{className:"text-[#5a6578] min-w-[40px] text-right",children:[d.costPercent?.toFixed(1),"%"]})]})]}),e.jsx("div",{className:"h-2 bg-slate-100 rounded-full overflow-hidden",children:e.jsx(U.div,{initial:{width:0},animate:{width:`${d.costPercent??0}%`},transition:{duration:.6,delay:.1+y*.04},className:`h-full rounded-full ${y===0?"bg-amber-400":y===1?"bg-slate-400":y===2?"bg-orange-400":"bg-violet-400"}`})})]})]},d.id))})]}),e.jsxs("section",{"data-testid":"section-highest-usage",children:[e.jsx(Le,{title:"Most active AI features",subtitle:"Features with the highest request volume this month",testId:"section-highest-usage-header"}),n?e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-3 gap-4",children:Array.from({length:6}).map((d,y)=>e.jsxs("div",{className:"bg-white rounded-2xl p-4 shadow-sm border border-[#dde3eb]",children:[e.jsx(Z,{className:"w-32 h-5 rounded mb-3"}),e.jsx(Z,{className:"w-24 h-8 rounded"})]},y))}):e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-3 gap-4",children:w.slice(0,6).map((d,y)=>e.jsxs(U.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},transition:{duration:.25,delay:y*.04},className:"bg-white rounded-2xl p-4 shadow-sm border border-[#dde3eb]",children:[e.jsxs("div",{className:"flex items-start justify-between mb-2",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-[#0a1628] mb-0.5",children:d.name}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(We,{status:d.status}),e.jsx(Ar,{trend:d.trend})]})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("p",{className:"text-lg font-bold text-[#0a1628]",children:Ve(d.requests)}),e.jsx("p",{className:"text-xs text-[#5a6578]",children:"requests"})]})]}),e.jsxs("div",{className:"pt-2 border-t border-slate-100 flex items-center justify-between",children:[e.jsxs("p",{className:"text-xs text-[#5a6578]",children:["Avg cost: ",Ne(d.avgCostPerRequest),"/request"]}),e.jsx(nt,{level:d.usageLevel})]})]},d.id))})]}),e.jsxs("section",{"data-testid":"section-needs-attention",children:[e.jsx(Le,{title:"Needs attention",subtitle:"Actionable issues that may need review",testId:"section-needs-attention-header"}),n?e.jsx("div",{className:"bg-white rounded-2xl p-6 shadow-sm border border-[#dde3eb]",children:e.jsx("div",{className:"space-y-3",children:[1,2].map(d=>e.jsx(Z,{className:"w-full h-12 rounded-xl"},d))})}):S.length===0?e.jsxs(U.div,{initial:{opacity:0,scale:.98},animate:{opacity:1,scale:1},className:"bg-emerald-50 border border-emerald-200 rounded-2xl p-6 flex items-center gap-4",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-emerald-100 flex items-center justify-center shrink-0",children:e.jsx(ts,{size:20,className:"text-emerald-600"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-emerald-800",children:"Everything looks normal"}),e.jsx("p",{className:"text-xs text-emerald-600 mt-0.5",children:"No issues detected with AI features right now"})]})]}):e.jsx("div",{className:"space-y-3",children:S.map(d=>e.jsxs(U.div,{initial:{opacity:0,x:-8},animate:{opacity:1,x:0},className:`rounded-2xl p-4 flex items-start gap-3 border ${d.severity==="critical"?"bg-rose-50 border-rose-200":d.severity==="warning"?"bg-amber-50 border-amber-200":"bg-sky-50 border-sky-200"}`,children:[e.jsx("div",{className:`w-8 h-8 rounded-xl flex items-center justify-center shrink-0 ${d.severity==="critical"?"bg-rose-100":d.severity==="warning"?"bg-amber-100":"bg-sky-100"}`,children:d.severity==="critical"?e.jsx(oe,{size:16,className:"text-rose-600"}):d.severity==="warning"?e.jsx(na,{size:16,className:"text-amber-600"}):e.jsx(we,{size:16,className:"text-sky-600"})}),e.jsx("p",{className:`text-sm font-medium ${d.severity==="critical"?"text-rose-800":d.severity==="warning"?"text-amber-800":"text-sky-800"}`,children:d.message})]},d.id))})]}),e.jsxs("section",{"data-testid":"section-ai-breakdown-table",children:[e.jsx(Le,{title:"AI activity breakdown",subtitle:"Detailed view of all AI features and their usage",testId:"section-ai-breakdown-table-header"}),e.jsx("div",{className:"bg-white rounded-2xl shadow-sm border border-[#dde3eb] overflow-hidden",children:n?e.jsx("div",{className:"p-4 space-y-3",children:Array.from({length:5}).map((d,y)=>e.jsx(Z,{className:"w-full h-12 rounded-lg"},y))}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-[#dde3eb] bg-slate-50",children:[e.jsx("th",{className:"text-left px-5 py-3 text-xs font-semibold text-[#5a6578] uppercase tracking-wide",children:"Feature"}),e.jsx("th",{className:"text-left px-4 py-3 text-xs font-semibold text-[#5a6578] uppercase tracking-wide",children:"Status"}),e.jsx("th",{className:"text-right px-4 py-3 text-xs font-semibold text-[#5a6578] uppercase tracking-wide",children:"Requests"}),e.jsx("th",{className:"text-right px-4 py-3 text-xs font-semibold text-[#5a6578] uppercase tracking-wide",children:"Est. Cost"}),e.jsx("th",{className:"text-right px-4 py-3 text-xs font-semibold text-[#5a6578] uppercase tracking-wide",children:"Avg / Request"}),e.jsx("th",{className:"text-left px-4 py-3 text-xs font-semibold text-[#5a6578] uppercase tracking-wide",children:"Last Active"})]})}),e.jsx("tbody",{className:"divide-y divide-[#dde3eb]",children:p.map(d=>e.jsxs("tr",{className:"hover:bg-slate-50 transition-colors",children:[e.jsx("td",{className:"px-5 py-3",children:e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-[#0a1628]",children:d.name}),e.jsx("p",{className:"text-xs text-[#5a6578] hidden sm:block",children:d.description})]})}),e.jsx("td",{className:"px-4 py-3",children:e.jsx(We,{status:d.status})}),e.jsx("td",{className:"px-4 py-3 text-right font-medium text-[#0a1628]",children:Ve(d.requests)}),e.jsx("td",{className:"px-4 py-3 text-right font-medium text-[#0a1628]",children:Ne(d.estimatedCost)}),e.jsx("td",{className:"px-4 py-3 text-right text-[#5a6578]",children:Ne(d.avgCostPerRequest)}),e.jsx("td",{className:"px-4 py-3 text-[#5a6578]",children:Sr(d.lastActiveAt)})]},d.id))})]})})})]})]})};function Pr({className:s,...t}){return e.jsx("div",{"data-slot":"table-container",className:"relative w-full overflow-x-auto",children:e.jsx("table",{"data-slot":"table",className:ke("w-full caption-bottom text-sm",s),...t})})}function Dr({className:s,...t}){return e.jsx("thead",{"data-slot":"table-header",className:ke("[&_tr]:border-b",s),...t})}function Tr({className:s,...t}){return e.jsx("tbody",{"data-slot":"table-body",className:ke("[&_tr:last-child]:border-0",s),...t})}function dt({className:s,...t}){return e.jsx("tr",{"data-slot":"table-row",className:ke("hover:bg-muted/50 data-[state=selected]:bg-muted border-b transition-colors",s),...t})}function Me({className:s,...t}){return e.jsx("th",{"data-slot":"table-head",className:ke("text-foreground h-10 px-2 text-left align-middle font-medium whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",s),...t})}function Ie({className:s,...t}){return e.jsx("td",{"data-slot":"table-cell",className:ke("p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",s),...t})}const ct=Ke.map(s=>({id:s.id,name:s.name,code:s.code,gradeLevel:s.gradeLevel,semester:s.semester,color:s.color})),Lr=()=>{const{userProfile:s}=Ee(),{availability:t,loading:i,error:r}=Na(),[h,n]=l.useState(null),[o,m]=l.useState({}),v=l.useCallback(async(f,j)=>{if(!s?.uid){z.error("You must be logged in as admin to change availability");return}n(f);try{await ya(f,j,s.uid),z.success(`${ct.find(w=>w.id===f)?.name||f} is now ${j?"available":"locked"}`)}catch(w){z.error("Failed to update subject availability"),console.error(w)}finally{n(null)}},[s?.uid]),p=l.useCallback((f,j)=>{m(w=>({...w,[f]:j}))},[]),S=l.useCallback(async f=>{if(!s?.uid){z.error("You must be logged in as admin");return}const j=o[f]?.trim()||null;n(f);try{await wa(f,j,s.uid),z.success("PDF path updated")}catch(w){z.error("Failed to update PDF path"),console.error(w)}finally{n(null)}},[o,s?.uid]);return e.jsxs(U.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.3},className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-display font-bold text-[#0a1628]",children:"Subject Availability"}),e.jsx("p",{className:"text-sm text-[#5a6578]",children:"Toggle subjects on or off to control student access. Changes take effect immediately across the platform."})]}),i&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-slate-500",children:[e.jsx(H,{size:16,className:"animate-spin"}),"Syncing..."]})]}),r&&e.jsx("div",{className:"rounded-xl border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-700",children:r}),e.jsx("div",{className:"rounded-2xl border border-slate-200 bg-white shadow-sm overflow-hidden",children:e.jsxs(Pr,{children:[e.jsx(Dr,{children:e.jsxs(dt,{className:"bg-slate-50/80 hover:bg-slate-50/80",children:[e.jsx(Me,{className:"text-xs font-black uppercase tracking-wider text-slate-500",children:"Subject"}),e.jsx(Me,{className:"text-xs font-black uppercase tracking-wider text-slate-500",children:"Grade / Sem"}),e.jsx(Me,{className:"text-xs font-black uppercase tracking-wider text-slate-500",children:"Status"}),e.jsx(Me,{className:"text-xs font-black uppercase tracking-wider text-slate-500",children:"Available"}),e.jsx(Me,{className:"text-xs font-black uppercase tracking-wider text-slate-500 w-[320px]",children:"PDF Path"})]})}),e.jsx(Tr,{children:ct.map(f=>{const j=t[f.id],w=j?.available??!0,A=o[f.id]??j?.pdfPath??"",k=j?.lastUpdated,d=h===f.id;return e.jsxs(dt,{className:"group",children:[e.jsx(Ie,{children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`w-8 h-8 rounded-lg bg-gradient-to-br ${f.color} flex items-center justify-center text-white shadow-sm`,children:e.jsx(je,{size:14})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-bold text-sm text-[#0a1628]",children:f.name}),e.jsx("p",{className:"text-[11px] text-slate-400 font-semibold",children:f.code})]})]})}),e.jsxs(Ie,{children:[e.jsx("p",{className:"text-sm text-slate-600",children:f.gradeLevel}),e.jsx("p",{className:"text-[11px] text-slate-400",children:f.semester})]}),e.jsxs(Ie,{children:[e.jsx("div",{className:"flex items-center gap-1.5",children:w?e.jsxs(e.Fragment,{children:[e.jsx(Fa,{size:14,className:"text-teal-500"}),e.jsx("span",{className:"text-xs font-bold text-teal-600",children:"Unlocked"})]}):e.jsxs(e.Fragment,{children:[e.jsx(mt,{size:14,className:"text-slate-400"}),e.jsx("span",{className:"text-xs font-bold text-slate-500",children:"Locked"})]})}),k&&e.jsxs("p",{className:"text-[10px] text-slate-400 mt-0.5 flex items-center gap-1",children:[e.jsx(At,{size:10}),k.toLocaleString()]})]}),e.jsx(Ie,{children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(be,{checked:w,onCheckedChange:y=>v(f.id,y),disabled:d,"aria-label":`Toggle ${f.name} availability`}),d&&e.jsx(H,{size:14,className:"animate-spin text-slate-400"})]})}),e.jsx(Ie,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(es,{size:14,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-slate-400"}),e.jsx(R,{value:A,onChange:y=>p(f.id,y.target.value),placeholder:"Firebase Storage path (optional)",className:"pl-8 h-8 text-xs",disabled:d})]}),e.jsx(M,{variant:"ghost",size:"sm",className:"h-8 px-2 text-xs",onClick:()=>S(f.id),disabled:d,children:d?e.jsx(H,{size:14,className:"animate-spin"}):e.jsx(Sa,{size:14})})]})})]},f.id)})})]})}),e.jsxs("div",{className:"rounded-xl border border-sky-200 bg-sky-50 px-5 py-4",children:[e.jsx("p",{className:"text-xs font-black uppercase tracking-wide text-sky-700 mb-2",children:"How it works"}),e.jsxs("ul",{className:"text-sm text-sky-800 space-y-1 list-disc list-inside",children:[e.jsxs("li",{children:["Turning a subject ",e.jsx("strong",{children:"off"})," immediately locks its modules and removes it from Quiz Battle."]}),e.jsxs("li",{children:["Turning a subject ",e.jsx("strong",{children:"on"})," unlocks it everywhere — no redeployment required."]}),e.jsxs("li",{children:["The ",e.jsx("strong",{children:"PDF Path"})," field is optional and references the RAG source in Firebase Storage."]}),e.jsx("li",{children:"All changes are logged with timestamps and your admin user ID."})]})]})]})},Xe=[{id:"gen-math",name:"Gen Math",shortName:"GM",color:"#3B82F6"},{id:"stats-prob",name:"Stats & Prob",shortName:"SP",color:"#0ea5e9"},{id:"pre-calc",name:"Pre-Calc",shortName:"PC",color:"#F97316"},{id:"basic-calc",name:"Basic Calc",shortName:"BC",color:"#EF4444"}],vs={"gen-math":[{name:"Functions & Relations",unit:"Functions"},{name:"Rational Functions",unit:"Functions"},{name:"Exponential Functions",unit:"Functions"},{name:"Logarithmic Functions",unit:"Functions"},{name:"Simple Interest",unit:"Business Math"},{name:"Compound Interest",unit:"Business Math"},{name:"Annuities",unit:"Business Math"},{name:"Propositions",unit:"Logic"},{name:"Truth Tables",unit:"Logic"}],"stats-prob":[{name:"Random Variables",unit:"Random Variables"},{name:"Probability Distributions",unit:"Random Variables"},{name:"Normal Distribution",unit:"Normal Dist"},{name:"Z-scores",unit:"Normal Dist"},{name:"Sampling Distributions",unit:"Sampling"},{name:"Central Limit Theorem",unit:"Sampling"},{name:"Confidence Intervals",unit:"Estimation"},{name:"Hypothesis Testing",unit:"Testing"},{name:"Correlation",unit:"Regression"}],"pre-calc":[{name:"Parabola",unit:"Conics"},{name:"Ellipse",unit:"Conics"},{name:"Hyperbola",unit:"Conics"},{name:"Arithmetic Seq",unit:"Series"},{name:"Geometric Seq",unit:"Series"},{name:"Math Induction",unit:"Series"},{name:"Trig Functions",unit:"Trigonometry"},{name:"Trig Identities",unit:"Trigonometry"},{name:"Polar Coords",unit:"Trigonometry"}],"basic-calc":[{name:"Limits",unit:"Limits"},{name:"Continuity",unit:"Limits"},{name:"Definition of Deriv.",unit:"Derivatives"},{name:"Diff. Rules",unit:"Derivatives"},{name:"Chain Rule",unit:"Derivatives"},{name:"Related Rates",unit:"Derivatives"},{name:"Optimization",unit:"Derivatives"},{name:"Antiderivatives",unit:"Integration"},{name:"Definite Integrals",unit:"Integration"}]};function Mr(s){return s>=85?"bg-emerald-500":s>=70?"bg-emerald-300":s>=55?"bg-rose-300":s>=40?"bg-orange-400":s>=20?"bg-red-400":"bg-red-600"}function Ir(s){return s>=70||s>=40,"text-white"}const Rr=({title:s="Platform-Wide Subject Mastery"})=>{const[t,i]=l.useState(null),[r,h]=l.useState("all"),{data:n=[],isLoading:o}=ka({queryKey:aa.masteryHeatmap(),staleTime:180*1e3,gcTime:1200*1e3,queryFn:async()=>{try{const j=await de(se(X,"progress")),w={};j.forEach(k=>{const y=k.data().subjects||{};for(const[L,C]of Object.entries(y)){const B=vs[L]||[],q=C?.progress??0;for(const O of B){const G=`${L}::${O.name}`;w[G]||(w[G]={totalMastery:0,count:0}),w[G].totalMastery+=q,w[G].count+=1}}});const A=[];for(const k of Xe){const d=vs[k.id]||[];for(const y of d){const L=`${k.id}::${y.name}`,C=w[L];A.push({subject:k.id,topic:y.name,mastery:C&&C.count>0?Math.round(C.totalMastery/C.count):0,students:C?.count??0})}}return A}catch(j){return console.error("[MasteryHeatmap] Error fetching progress data:",j),[]}}}),m=r==="all"?Xe:Xe.filter(j=>j.id===r),v=n.filter(j=>j.students>0),p=v.length>0?Math.round(v.reduce((j,w)=>j+w.mastery,0)/v.length):0,S=v.length>0?v.reduce((j,w)=>w.mastery0?v.reduce((j,w)=>w.mastery>j.mastery?w:j,v[0]):null;return o?e.jsx("div",{className:"bg-white rounded-3xl p-6 shadow-sm border border-[#dde3eb] flex items-center justify-center min-h-[200px]",children:e.jsxs("div",{className:"flex flex-col items-center gap-3",children:[e.jsx(H,{size:28,className:"text-sky-500 animate-spin"}),e.jsx("p",{className:"text-sm text-[#5a6578]",children:"Loading mastery data..."})]})}):e.jsxs("div",{className:"bg-white rounded-3xl p-6 shadow-sm border border-[#dde3eb]",children:[e.jsxs("div",{className:"flex items-center justify-between mb-5",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 bg-gradient-to-br from-indigo-500 to-sky-500 rounded-xl flex items-center justify-center",children:e.jsx(Ua,{size:20,className:"text-white"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-bold text-[#0a1628]",children:s}),e.jsxs("p",{className:"text-xs text-[#5a6578]",children:["Aggregated mastery levels across all classes • ",n.filter(j=>j.students>0).length," tracked combinations"]})]})]}),e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:r,onChange:j=>h(j.target.value),className:"appearance-none bg-[#edf1f7] border border-[#dde3eb] rounded-lg px-3 py-1.5 pr-8 text-xs font-semibold text-[#5a6578] focus:outline-none focus:ring-2 focus:ring-sky-500/20",children:[e.jsx("option",{value:"all",children:"All Subjects"}),Xe.map(j=>e.jsx("option",{value:j.id,children:j.name},j.id))]}),e.jsx(Ca,{size:12,className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-slate-500 pointer-events-none"})]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3 mb-5",children:[e.jsxs("div",{className:"bg-[#edf1f7] rounded-xl p-3 flex items-center gap-3",children:[e.jsx("div",{className:`w-8 h-8 rounded-lg flex items-center justify-center ${p>=70?"bg-emerald-100":"bg-rose-100"}`,children:e.jsx(Aa,{size:16,className:p>=70?"text-emerald-600":"text-rose-600"})}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-lg font-bold text-[#0a1628]",children:[p,"%"]}),e.jsx("p",{className:"text-[10px] text-[#5a6578] uppercase tracking-wider",children:"Platform Average"})]})]}),e.jsxs("div",{className:"bg-red-50 rounded-xl p-3 flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 bg-red-100 rounded-lg flex items-center justify-center",children:e.jsx(ia,{size:16,className:"text-red-600"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-bold text-[#0a1628] truncate",children:S?.topic}),e.jsxs("p",{className:"text-[10px] text-red-600 font-semibold",children:[S?.mastery,"% — Lowest"]})]})]}),e.jsxs("div",{className:"bg-emerald-50 rounded-xl p-3 flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 bg-emerald-100 rounded-lg flex items-center justify-center",children:e.jsx(gt,{size:16,className:"text-emerald-600"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-bold text-[#0a1628] truncate",children:f?.topic}),e.jsxs("p",{className:"text-[10px] text-emerald-600 font-semibold",children:[f?.mastery,"% — Highest"]})]})]})]}),e.jsx("div",{className:"overflow-x-auto",children:m.map(j=>{const w=vs[j.id]||[],A=n.filter(d=>d.subject===j.id),k=A.length>0?Math.round(A.reduce((d,y)=>d+y.mastery,0)/A.length):0;return e.jsxs("div",{className:"mb-5 last:mb-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("div",{className:"w-3 h-3 rounded-sm e-bg",style:{"--bg":j.color}}),e.jsx("span",{className:"text-xs font-bold text-[#0a1628]",children:j.name}),e.jsxs("span",{className:"text-[10px] text-slate-500 ml-1",children:["Avg: ",k,"%"]})]}),e.jsxs("div",{className:"grid gap-1 e-grid-cols",style:{"--grid-cols":`repeat(${w.length}, minmax(0, 1fr))`},children:[w.map((d,y)=>e.jsx("div",{className:"text-center",children:e.jsx("p",{className:"text-[9px] text-slate-500 truncate px-0.5 mb-1",title:d.name,children:d.name})},`label-${y}`)),w.map((d,y)=>{const L=A.find(q=>q.topic===d.name),C=L?.mastery||0,B=t?.topic===d.name&&t?.subject===j.id;return e.jsxs(U.div,{onMouseEnter:()=>L&&i(L),onMouseLeave:()=>i(null),whileHover:{scale:1.05},className:`relative h-10 rounded-lg flex items-center justify-center cursor-pointer transition-all ${Mr(C)} ${B?"ring-2 ring-white shadow-lg z-10":""}`,children:[e.jsxs("span",{className:`text-xs font-bold ${Ir(C)}`,children:[C,"%"]}),B&&L&&e.jsxs("div",{className:"absolute bottom-full left-1/2 -translate-x-1/2 mb-2 bg-slate-800 text-white rounded-lg px-3 py-2 text-xs whitespace-nowrap z-20 shadow-xl pointer-events-none",children:[e.jsx("p",{className:"font-bold mb-0.5",children:L.topic}),e.jsxs("p",{children:["Mastery: ",e.jsxs("strong",{children:[L.mastery,"%"]})]}),e.jsxs("p",{children:["Students: ",e.jsx("strong",{children:L.students})]}),e.jsx("div",{className:"absolute bottom-0 left-1/2 -translate-x-1/2 translate-y-full w-0 h-0 border-l-[6px] border-l-transparent border-r-[6px] border-r-transparent border-t-[6px] border-t-slate-800"})]})]},`cell-${y}`)})]})]},j.id)})}),e.jsxs("div",{className:"flex items-center justify-center gap-4 mt-5 pt-4 border-t border-[#dde3eb]",children:[e.jsxs("div",{className:"flex items-center gap-1 text-[10px] text-[#5a6578]",children:[e.jsx(we,{size:10}),e.jsx("span",{children:"Color scale:"})]}),[{label:"0-19%",color:"bg-red-600"},{label:"20-39%",color:"bg-red-400"},{label:"40-54%",color:"bg-orange-400"},{label:"55-69%",color:"bg-rose-300"},{label:"70-84%",color:"bg-emerald-300"},{label:"85-100%",color:"bg-emerald-500"}].map((j,w)=>e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("div",{className:`w-3 h-3 rounded-sm ${j.color}`}),e.jsx("span",{className:"text-[10px] text-[#5a6578]",children:j.label})]},w))]})]})},Er=[{id:"gen-math",title:"General Mathematics",icon:je,bg:"bg-[#9956DE]",tags:["Algebra","Fractions","Integers"],level:1,progress:25,isAtRisk:!0},{id:"pre-calc",title:"Pre-Calculus",icon:je,bg:"bg-[#1FA7E1]",tags:["Functions","Limits","Graphs"],level:2,progress:15,isAtRisk:!0},{id:"stats-prob",title:"Statistics & Probability",icon:je,bg:"bg-[#FFB356]",tags:["Probability","Mean/Median"],level:2,progress:40,isAtRisk:!1},{id:"basic-calc",title:"Basic Calculus",icon:je,bg:"bg-[#FB96BB]",tags:["Derivatives","Integrals"],level:3,progress:50,isAtRisk:!1},{id:"adv-math",title:"Advanced Algebra",icon:je,bg:"bg-[#7274ED]",tags:["Math","Logic"],level:4,progress:10,isAtRisk:!0}].slice(0,5),Ur=()=>{const s=l.useRef(null),[t,i]=l.useState(0),r=()=>{if(!s.current)return;const{scrollLeft:n,scrollWidth:o,clientWidth:m}=s.current,v=n/(o-m),p=3;let S=Math.round(v*(p-1));S<0&&(S=0),S>=p&&(S=p-1),i(S)},h=n=>{if(!s.current)return;const{scrollWidth:o,clientWidth:m}=s.current,p=(o-m)/2*n;s.current.scrollTo({left:p,behavior:"smooth"}),i(n)};return e.jsxs("div",{className:"bg-white rounded-3xl p-6 shadow-sm border border-[#dde3eb] mb-6",children:[e.jsx("div",{className:"flex items-center justify-between mb-5",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-bold text-[#0a1628] mb-1",children:"Priority Attention Modules"}),e.jsx("p",{className:"text-sm text-[#5a6578]",children:"Highly recommended to be reviewed (lowest performance)."})]})}),e.jsx("div",{className:"relative",children:e.jsx("div",{ref:s,onScroll:r,className:"flex overflow-x-auto snap-x snap-mandatory gap-5 pb-6 no-scrollbar",children:Er.map(n=>{const o=n.icon;return e.jsxs("div",{className:`snap-center shrink-0 w-[280px] sm:w-[300px] ${n.bg} rounded-[2rem] p-5 min-h-[290px] relative overflow-hidden transition-all duration-300 flex flex-col group shadow-sm`,children:[e.jsx("div",{className:"absolute -bottom-8 right-[-20%] w-32 h-32 bg-white opacity-10 rounded-full"}),e.jsx("div",{className:"absolute bottom-4 right-12 w-20 h-20 bg-white opacity-10 rounded-full"}),e.jsxs("div",{className:"flex justify-between items-start mb-4 relative z-10",children:[e.jsx("div",{className:"w-12 h-12 rounded-[1rem] bg-white/20 flex flex-shrink-0 items-center justify-center text-white backdrop-blur-sm",children:e.jsx(o,{size:24,className:"opacity-90"})}),e.jsxs("div",{className:"px-4 py-1.5 rounded-full bg-white/20 text-white/90 text-sm font-bold backdrop-blur-sm",children:["Lv ",n.level]})]}),e.jsxs("div",{className:"relative z-10 flex-1",children:[e.jsx("h3",{className:"text-2xl font-display font-black text-white leading-[1.1] mb-3 drop-shadow-sm pr-4 line-clamp-2",children:n.title}),e.jsx("div",{className:"flex flex-wrap gap-2 pb-4",children:n.tags.map(m=>e.jsx("span",{className:"px-3 py-1 rounded-full bg-white/20 text-white text-[13px] font-bold shadow-sm backdrop-blur-sm",children:m},m))})]}),e.jsxs("div",{className:"relative z-10 mt-auto pt-4 flex flex-col gap-2.5",children:[e.jsxs("div",{className:"flex justify-between text-white/90 text-[13px] font-bold",children:[e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsx("span",{children:"Avg Mastery"})}),e.jsxs("span",{children:[n.progress,"%"]})]}),e.jsx("div",{className:"w-full h-2 rounded-full bg-white/30 overflow-hidden shadow-inner mt-1",children:e.jsx("div",{className:"h-full bg-white rounded-full e-w",style:{"--w":`${n.progress}%`}})}),n.isAtRisk&&e.jsxs("div",{className:"absolute -top-12 right-0 bg-red-500 text-white px-3 py-1 rounded-full text-[11px] font-bold flex items-center gap-1 shadow-lg animate-pulse",children:[e.jsx(oe,{size:12})," At Risk"]})]})]},n.id)})})}),e.jsx("div",{className:"flex justify-center items-center gap-2 mt-2",children:[0,1,2].map(n=>e.jsx("button",{onClick:()=>h(n),className:`w-2.5 h-2.5 rounded-full transition-all duration-300 ${t===n?"bg-sky-600 w-6":"bg-sky-200 hover:bg-sky-300"}`,"aria-label":`Go to slide ${n+1}`},n))})]})},Ll=({onLogout:s,onOpenProfile:t})=>{const{userProfile:i}=Ee(),[r,h]=l.useState("Overview"),[n,o]=l.useState(!1),[m,v]=l.useState(!1),[p,S]=l.useState(null),[f,j]=l.useState(!1),[w,A]=l.useState(!1),[k,d]=l.useState(!1),[y,L]=l.useState(null),[C,B]=l.useState(null),[q,O]=l.useState([]),[G,Y]=l.useState([]),[_,ee]=l.useState(!0),Q=u=>r===u?!0:r==="Settings"&&u!=="Settings"&&k?(S(u),v(!0),!1):(h(u),!0),ce=()=>{p&&h(p),d(!1),S(null),v(!1),A(!1)},b=()=>{S(null),v(!1)},V=u=>{Q(u)&&A(!1)},x=u=>{L(u),Q("User Management")};l.useEffect(()=>{if(r!=="Overview"||!i)return;const u=String(i.role||"").toLowerCase(),$=u==="admin"||u==="teacher";let te=!1;return ee(!0),Promise.all([er(),$?Pt():Promise.resolve([]),sr(3)]).then(([Ue,ns,Ae])=>{te||(B(Ue),O(ns.slice(0,4)),Y(Ae))}).catch(console.error).finally(()=>{te||ee(!1)}),()=>{te=!0}},[r,i]);const E=[{label:"Total Students",value:(C?.totalStudents??0).toLocaleString(),icon:Ze,color:"bg-sky-100",iconColor:"text-sky-600"},{label:"Active Teachers",value:(C?.activeTeachers??0).toString(),icon:Cs,color:"bg-teal-100",iconColor:"text-teal-600"},{label:"Total Classes",value:(C?.totalClasses??0).toString(),icon:je,color:"bg-sky-100",iconColor:"text-sky-600"},{label:"At-Risk Students",value:(C?.atRiskStudents??0).toString(),icon:Se,color:"bg-red-100",iconColor:"text-red-600"},{label:"Avg Performance",value:`${C?.avgPerformance??0}%`,icon:ss,color:"bg-orange-100",iconColor:"text-orange-600"},{label:"AI Interactions",value:(C?.aiPredictions??0).toLocaleString(),icon:ut,color:"bg-sky-100",iconColor:"text-sky-600"}],c=u=>u==="Error"||u==="Critical"?{text:"text-red-600",bg:"bg-red-50"}:u==="Warning"?{text:"text-rose-600",bg:"bg-rose-50"}:{text:"text-sky-600",bg:"bg-sky-50"};return e.jsxs("div",{className:"flex h-screen w-full bg-[#edf1f7] overflow-hidden",children:[e.jsx("div",{className:"hidden lg:block",children:e.jsx(Bs,{activeTab:r,setActiveTab:V,userRole:"admin",onOpenSettings:()=>V("Settings"),onLogout:()=>o(!0),sidebarCollapsed:f,setSidebarCollapsed:j})}),w&&e.jsxs(e.Fragment,{children:[e.jsx("button",{"aria-label":"Close navigation",className:"fixed inset-0 z-40 bg-slate-900/40 backdrop-blur-[1px] lg:hidden",onClick:()=>A(!1)}),e.jsx("div",{className:"fixed inset-y-0 left-0 z-50 p-3 lg:hidden",children:e.jsx(Bs,{mode:"mobile",onRequestClose:()=>A(!1),activeTab:r,setActiveTab:V,userRole:"admin",onOpenSettings:()=>V("Settings"),onLogout:()=>{o(!0),A(!1)},sidebarCollapsed:!1})})]}),e.jsxs("div",{className:"flex-1 flex flex-col",children:[e.jsxs("header",{className:"bg-white/80 backdrop-blur-md border-b border-[#dde3eb] px-6 py-3 flex items-center justify-between sticky top-0 z-30",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("button",{type:"button",onClick:()=>A(!0),className:"inline-flex lg:hidden items-center justify-center w-10 h-10 rounded-xl border border-[#dde3eb] bg-white text-[#5a6578] hover:bg-[#edf1f7]","aria-label":"Open navigation",children:e.jsx(ra,{size:18})}),e.jsxs("div",{children:[e.jsxs("h1",{className:"text-xl font-display font-bold text-[#0a1628] leading-tight",children:[r==="Overview"&&"Admin Dashboard",r==="Content"&&"Content & RAG",r==="Audit Log"&&"Audit Log",r==="User Management"&&"User Management",r==="Analytics"&&"Analytics",r==="AI Monitoring"&&"AI Monitoring",r==="Settings"&&"Settings",r==="Subjects"&&"Subjects"]}),e.jsxs("p",{className:"text-xs text-[#5a6578] font-body",children:[r==="Overview"&&"System Overview & Management",r==="Content"&&"Upload PDFs for AI-powered content",r==="Audit Log"&&"Monitor system activity",r==="User Management"&&"Manage all user accounts",r==="Analytics"&&"Detailed performance metrics",r==="AI Monitoring"&&"Platform AI usage and system health",r==="Settings"&&"Configure platform settings",r==="Subjects"&&"Manage subjects and module availability"]})]})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs("button",{onClick:t,className:"flex items-center gap-2.5 h-11 shrink-0 bg-[#edf1f7] p-1.5 pr-3 rounded-lg cursor-pointer hover:bg-[#dde3eb] transition-all group",children:[e.jsx(la,{src:i?.photo,name:i?.name||"Admin",gender:i?.gender,className:"w-8 h-8 rounded-lg"}),e.jsx("div",{className:"min-w-0 flex-1 text-left",children:e.jsx("p",{className:"text-sm font-semibold text-[#0a1628] leading-none group-hover:text-sky-600 transition-colors truncate",children:i?.name||"Admin"})})]})})]}),e.jsxs("main",{className:"flex-1 overflow-y-auto p-6",children:[r==="Overview"&&e.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-12 gap-6",children:[e.jsxs("div",{className:"xl:col-span-8 space-y-6",children:[e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4",children:E.map((u,$)=>{const te=u.icon;return e.jsxs("div",{className:"bg-white rounded-2xl p-5 shadow-sm border border-[#dde3eb] hover:shadow-md transition-all",children:[e.jsx("div",{className:"flex items-start justify-between mb-3",children:e.jsx("div",{className:`w-12 h-12 ${u.color} rounded-xl flex items-center justify-center`,children:e.jsx(te,{size:24,className:u.iconColor})})}),e.jsx("h3",{className:"text-2xl font-bold text-[#0a1628] mb-1",children:_?e.jsx("div",{className:"h-8 w-20 bg-[#edf1f7] rounded animate-pulse"}):u.value}),e.jsx("p",{className:"text-sm text-[#5a6578] font-medium",children:u.label})]},$)})}),e.jsxs("div",{className:"bg-white rounded-3xl p-6 shadow-sm border border-[#dde3eb]",children:[e.jsx("div",{className:"flex items-center justify-between mb-6",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-bold text-[#0a1628] mb-1",children:"System Performance Overview"}),e.jsx("p",{className:"text-sm text-[#5a6578]",children:"Trend visualization"})]})}),e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 gap-3",children:[e.jsx(ss,{size:32,className:"text-[#dde3eb]"}),e.jsx("p",{className:"text-sm font-medium text-[#5a6578]",children:"Performance trend chart is currently unavailable"}),e.jsx("p",{className:"text-xs text-[#a0aec0]",children:"Live KPI totals are shown above. Time-series backend support is required for chart rendering."})]})]}),e.jsx(Ur,{}),e.jsx(Rr,{}),e.jsxs("div",{className:"bg-white rounded-3xl p-6 shadow-sm border border-[#dde3eb]",children:[e.jsx("h2",{className:"text-lg font-bold text-[#0a1628] mb-5",children:"Recent System Activity"}),_?e.jsx("div",{className:"flex justify-center py-8",children:e.jsx(H,{className:"animate-spin text-sky-500"})}):q.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-10 gap-3",children:[e.jsx(Da,{size:28,className:"text-[#dde3eb]"}),e.jsx("p",{className:"text-sm text-[#5a6578]",children:"No audit events yet"})]}):e.jsx("div",{className:"space-y-3",children:q.map(u=>{const $=c(u.severity);return e.jsxs("div",{className:`${$.bg} border border-[#dde3eb] rounded-2xl p-4 flex items-start gap-4`,children:[e.jsx("div",{className:"w-10 h-10 bg-white rounded-xl flex items-center justify-center flex-shrink-0",children:e.jsx(Je,{size:18,className:$.text})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-bold text-[#0a1628] mb-0.5",children:u.action}),e.jsx("p",{className:"text-xs text-[#5a6578] truncate",children:u.details}),e.jsxs("p",{className:"text-xs text-[#5a6578] mt-1",children:[u.timestamp," · ",u.user.name]})]})]},u.id)})})]})]}),e.jsxs("div",{className:"xl:col-span-4 space-y-6",children:[e.jsxs("div",{className:"bg-gradient-to-br from-indigo-600 to-sky-600 rounded-3xl p-6 text-white shadow-lg",children:[e.jsx("h2",{className:"text-lg font-bold mb-4",children:"Quick Actions"}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("button",{type:"button",onClick:()=>x("Teacher"),className:"w-full bg-white/20 hover:bg-white/30 backdrop-blur-sm border border-slate-300 rounded-xl p-3 text-left transition-all",children:[e.jsx("p",{className:"text-sm font-bold",children:"Add New Teacher"}),e.jsx("p",{className:"text-xs text-sky-100",children:"Create teacher account"})]}),e.jsxs("button",{type:"button",onClick:()=>x("Student"),className:"w-full bg-white/20 hover:bg-white/30 backdrop-blur-sm border border-slate-300 rounded-xl p-3 text-left transition-all",children:[e.jsx("p",{className:"text-sm font-bold",children:"Add New Student"}),e.jsx("p",{className:"text-xs text-sky-100",children:"Register new student"})]}),e.jsxs("button",{type:"button",onClick:()=>Q("Settings"),className:"w-full bg-white/20 hover:bg-white/30 backdrop-blur-sm border border-slate-300 rounded-xl p-3 text-left transition-all",children:[e.jsx("p",{className:"text-sm font-bold",children:"System Settings"}),e.jsx("p",{className:"text-xs text-sky-100",children:"Configure platform"})]}),e.jsxs("button",{type:"button",disabled:!0,"aria-disabled":"true",title:"Report export is not available yet",className:"w-full bg-white/10 border border-slate-300/70 rounded-xl p-3 text-left opacity-60 cursor-not-allowed",children:[e.jsx("p",{className:"text-sm font-bold",children:"Generate Report"}),e.jsx("p",{className:"text-xs text-sky-100",children:"Export support is not available yet"})]})]})]}),e.jsxs("div",{className:"bg-white rounded-3xl p-6 shadow-sm border border-[#dde3eb]",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-5",children:[e.jsx("div",{className:"w-10 h-10 bg-rose-100 rounded-xl flex items-center justify-center",children:e.jsx(Ye,{size:20,className:"text-rose-600"})}),e.jsx("h2",{className:"text-lg font-bold text-[#0a1628]",children:"Top Performers"})]}),_?e.jsx("div",{className:"flex justify-center py-8",children:e.jsx(H,{className:"animate-spin text-sky-500"})}):G.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-10 gap-3",children:[e.jsx(Ye,{size:28,className:"text-[#dde3eb]"}),e.jsx("p",{className:"text-sm text-[#5a6578]",children:"No student data yet"}),e.jsx("p",{className:"text-xs text-[#a0aec0]",children:"Students will appear here as they progress."})]}):e.jsx("div",{className:"space-y-3",children:G.map((u,$)=>e.jsxs("div",{className:"bg-gradient-to-r from-rose-50 to-orange-50 border border-rose-200 rounded-2xl p-4",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx("img",{src:u.avatar,alt:u.name,className:"w-12 h-12 rounded-xl object-cover"}),e.jsx("span",{className:"absolute -top-1 -right-1 w-6 h-6 bg-rose-500 text-white text-xs font-bold rounded-full flex items-center justify-center",children:$+1})]}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h4",{className:"text-sm font-bold text-[#0a1628]",children:u.name}),e.jsx("p",{className:"text-xs text-[#5a6578]",children:u.class})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"bg-white rounded-xl p-2",children:[e.jsx("p",{className:"text-[10px] text-[#5a6578] mb-1",children:"Performance"}),e.jsxs("p",{className:"text-lg font-bold text-teal-600",children:[u.performance,"%"]})]}),e.jsxs("div",{className:"bg-white rounded-xl p-2",children:[e.jsx("p",{className:"text-[10px] text-[#5a6578] mb-1",children:"Level"}),e.jsx("p",{className:"text-lg font-bold text-sky-600",children:u.level})]})]})]},u.id))})]}),e.jsxs("div",{className:"bg-white rounded-3xl p-6 shadow-sm border border-[#dde3eb]",children:[e.jsx("h2",{className:"text-lg font-bold text-[#0a1628] mb-5",children:"AI Model Status"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-[#5a6578]",children:"AI Interactions Logged"}),e.jsx("span",{className:"text-sm font-bold text-[#0a1628]",children:_?"...":(C?.aiPredictions??0).toLocaleString()})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-[#5a6578]",children:"At-Risk Students Tracked"}),e.jsx("span",{className:"text-sm font-bold text-[#0a1628]",children:_?"...":(C?.atRiskStudents??0).toLocaleString()})]}),e.jsx("div",{className:"mt-4 p-3 bg-sky-50 border border-sky-200 rounded-xl",children:e.jsxs("p",{className:"text-xs text-sky-800",children:[e.jsx("strong",{children:"Status:"})," Model quality metrics (accuracy/drift) are unavailable in the current backend and are intentionally hidden."]})})]})]})]})]}),r==="Content"&&e.jsx(Ha,{}),r==="Audit Log"&&e.jsx(ar,{}),r==="User Management"&&e.jsx(pr,{createIntentRole:y,onCreateIntentConsumed:()=>L(null)}),r==="Analytics"&&e.jsx(fr,{}),r==="AI Monitoring"&&e.jsx(zr,{}),r==="Settings"&&e.jsx(nr,{onDirtyChange:d}),r==="Subjects"&&e.jsx(Lr,{})]})]}),e.jsx(Ns,{isOpen:n,onClose:()=>o(!1),onConfirm:s,title:"Logout Confirmation",message:"Are you sure you want to log out? This will end your current session.",confirmText:"Logout",cancelText:"Cancel"}),e.jsx(Ns,{isOpen:m,onClose:b,onConfirm:ce,title:"Discard Unsaved Changes?",message:"You have unsaved settings changes. If you continue, your edits will be discarded.",confirmText:"Discard Changes",cancelText:"Keep Editing",type:"warning",icon:"warning"})]})};export{Ll as default}; diff --git a/assets/AssessmentPage-YsCyxvJJ.js b/assets/AssessmentPage-Zx-Hx4dd.js similarity index 93% rename from assets/AssessmentPage-YsCyxvJJ.js rename to assets/AssessmentPage-Zx-Hx4dd.js index f219eba9b89c223c637b70cb60467e44ec71f6d8..394d5773b7e238cac2cbf0c2f6ddf54820ed0967 100644 --- a/assets/AssessmentPage-YsCyxvJJ.js +++ b/assets/AssessmentPage-Zx-Hx4dd.js @@ -1,4 +1,4 @@ -import{r as n,j as e}from"./vendor-react-B4AQeu28.js";import{B as P}from"./button-DCfeFHoH.js";import{s as Q}from"./diagnosticService-BDYTUoqk.js";import{e as Y,m as a,Z as J,j as O,T as U,x as Z,y as G}from"./index-BaOs5Ayg.js";import{M as H}from"./maximize-2-EHa6JURc.js";import{X as W}from"./x-TNvtuOD9.js";import{C as X}from"./clock-D1Ecvltm.js";import{C as K}from"./circle-check-big-m1SvzGFL.js";import{C as V}from"./chevron-right-COqGruhh.js";import"./vendor-radix-BorKzPz9.js";import"./vendor-charts-D8hf8tI0.js";import"./vendor-firebase-firestore-CH1lNiRF.js";import"./vendor-firebase-core-CO26nNq6.js";import"./vendor-firebase-auth-BLpRW_zO.js";import"./vendor-firebase-storage-B3igpVVS.js";import"./vendor-firebase-analytics-CTiUNb0-.js";import"./vendor-markdown-yqZQ_iQm.js";/** +import{r as n,j as e}from"./vendor-react-B4AQeu28.js";import{B as P}from"./button-BPmLcOpC.js";import{s as Q}from"./diagnosticService-DacNtsbN.js";import{e as Y,m as a,Z as J,g as O,T as U,z as Z,q as G}from"./index-uASBzalf.js";import{M as H}from"./maximize-2-B2yMqxTx.js";import{X as W}from"./x-CBb03rh3.js";import{C as X}from"./clock-8t0UYgg3.js";import{C as K}from"./circle-check-big-BNRlH5pv.js";import{C as V}from"./chevron-right-U0AqPOPj.js";import"./vendor-radix-xDOIcVzp.js";import"./vendor-charts-Ckgeb0nY.js";import"./vendor-firebase-firestore-CP9q7ISf.js";import"./vendor-firebase-core-DCQrgkxC.js";import"./vendor-firebase-auth-Bcpr4O6E.js";import"./vendor-firebase-storage-dc5X5yTv.js";import"./vendor-firebase-analytics-CHPyhRzk.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/AvatarShop-BeFk31yM.js b/assets/AvatarShop-Bl68yioD.js similarity index 91% rename from assets/AvatarShop-BeFk31yM.js rename to assets/AvatarShop-Bl68yioD.js index c8cc0a350edc81d588a572326d72901a108d966c..0ef449c388628e67c782f37dae47ecaa55eee563 100644 --- a/assets/AvatarShop-BeFk31yM.js +++ b/assets/AvatarShop-Bl68yioD.js @@ -1,4 +1,4 @@ -import{r as i,j as e}from"./vendor-react-B4AQeu28.js";import{f as se,L as ae,h as re,g as oe}from"./vendor-radix-BorKzPz9.js";import{e as S,u as le,L as w,W as R,m as y,j as ie,t as c,aG as ne,aH as ce}from"./index-BaOs5Ayg.js";import{u as de}from"./useFeatureAccess-BSpfx3vY.js";import{T as me,a as ue,b as xe}from"./tooltip-ChRIOid3.js";import{C as pe}from"./CompositeAvatar-Col05lJc.js";import{M as j}from"./avatarData-BuQSOXo3.js";import{S as O}from"./save-CQIJrhLf.js";import{S as V}from"./sparkles-By-vFjpv.js";import{S as fe}from"./shirt-S3NBuaPm.js";import"./vendor-firebase-firestore-CH1lNiRF.js";import"./vendor-firebase-core-CO26nNq6.js";import"./vendor-firebase-auth-BLpRW_zO.js";import"./vendor-firebase-storage-B3igpVVS.js";import"./vendor-firebase-analytics-CTiUNb0-.js";import"./vendor-charts-D8hf8tI0.js";import"./vendor-markdown-yqZQ_iQm.js";/** +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-xDOIcVzp.js";import{e as S,l as le,L as w,Y as R,m as y,g as ie,n as c,aH as ne,aI as ce}from"./index-uASBzalf.js";import{u as de}from"./useFeatureAccess-C_Ctl5Sh.js";import{T as me,a as ue,b as xe}from"./tooltip-1ASn-3cE.js";import{C as pe}from"./CompositeAvatar-Col05lJc.js";import{M as j}from"./avatarData-BuQSOXo3.js";import{S as O}from"./save-CoDXj-im.js";import{S as V}from"./sparkles-DHVr5IP1.js";import{S as fe}from"./shirt-DFJQeZbT.js";import"./vendor-firebase-firestore-CP9q7ISf.js";import"./vendor-firebase-core-DCQrgkxC.js";import"./vendor-firebase-auth-Bcpr4O6E.js";import"./vendor-firebase-storage-dc5X5yTv.js";import"./vendor-firebase-analytics-CHPyhRzk.js";import"./vendor-charts-Ckgeb0nY.js";import"./vendor-markdown-yqZQ_iQm.js";/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. @@ -28,4 +28,4 @@ import{r as i,j as e}from"./vendor-react-B4AQeu28.js";import{f as se,L as ae,h a .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:H,loading:B}=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),[_,I]=i.useState(null),[d,h]=i.useState(null),[P,z]=i.useState(j),[W,Z]=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 J=(t,o)=>{const s=P.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})},Q=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}I(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{I(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 B?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..."})]}):H?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:W,onValueChange:t=>Z(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=P.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&&J(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=>Q(u,s.id,s.price||0),disabled:_===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:_===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}; +`,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:H,loading:B}=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),[I,_]=i.useState(null),[d,h]=i.useState(null),[P,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 W=(t,o)=>{const s=P.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})},Q=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 B?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..."})]}):H?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=P.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&&W(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=>Q(u,s.id,s.price||0),disabled:I===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:I===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/ChatMarkdown-fgwaycBR.js b/assets/ChatMarkdown-BSQ2GO-C.js similarity index 84% rename from assets/ChatMarkdown-fgwaycBR.js rename to assets/ChatMarkdown-BSQ2GO-C.js index ecbd393e7abddbfe266ac2cab1fd8893d1db1a48..26250d9e760c0e142dd540c58b600229fa338617 100644 --- a/assets/ChatMarkdown-fgwaycBR.js +++ b/assets/ChatMarkdown-BSQ2GO-C.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{b0 as d,_ as c}from"./index-BaOs5Ayg.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-CH1lNiRF.js";import"./vendor-firebase-core-CO26nNq6.js";import"./vendor-firebase-auth-BLpRW_zO.js";import"./vendor-firebase-storage-B3igpVVS.js";import"./vendor-firebase-analytics-CTiUNb0-.js";import"./vendor-radix-BorKzPz9.js";import"./vendor-charts-D8hf8tI0.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{b1 as d,_ as c}from"./index-uASBzalf.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-CP9q7ISf.js";import"./vendor-firebase-core-DCQrgkxC.js";import"./vendor-firebase-auth-Bcpr4O6E.js";import"./vendor-firebase-storage-dc5X5yTv.js";import"./vendor-firebase-analytics-CHPyhRzk.js";import"./vendor-radix-xDOIcVzp.js";import"./vendor-charts-Ckgeb0nY.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-CBuH8ru8.js b/assets/CompetencyRadarChart-CsWJvNpV.js similarity index 94% rename from assets/CompetencyRadarChart-CBuH8ru8.js rename to assets/CompetencyRadarChart-CsWJvNpV.js index 97ce394c3d42a295a452e9b5c473a81849630ef6..9e3ac508880ab9d75dfcf36ebfef004c25229600 100644 --- a/assets/CompetencyRadarChart-CBuH8ru8.js +++ b/assets/CompetencyRadarChart-CsWJvNpV.js @@ -1 +1 @@ -import{r as g,j as t}from"./vendor-react-B4AQeu28.js";import{f as A,a4 as I,u as B,m as L,B as O,a as W}from"./index-BaOs5Ayg.js";import{collection as E,getDocs as R,query as H,orderBy as K,limit as U,Timestamp as G,getDoc as Y,doc as $}from"./vendor-firebase-firestore-CH1lNiRF.js";import{g as J,s as V}from"./subjects-BFghB0SQ.js";import{S as X}from"./sparkles-By-vFjpv.js";import{R as Z,f as ee,P as te,g as se,h as ne,i as ae,T as oe}from"./vendor-charts-D8hf8tI0.js";import"./vendor-firebase-core-CO26nNq6.js";import"./vendor-firebase-auth-BLpRW_zO.js";import"./vendor-firebase-storage-B3igpVVS.js";import"./vendor-firebase-analytics-CTiUNb0-.js";import"./vendor-radix-BorKzPz9.js";import"./vendor-markdown-yqZQ_iQm.js";import"./chart-column-B3jJOD5i.js";const P=["#1FA7E1","#9956DE","#75D06A","#FFB356","#7274ED","#FF8B8B","#6ED1CF","#FB96BB"];async function re(a){try{const r=E(A,"users",a,"quizResults"),u=H(r,K("timestamp","desc"),U(500)),d=await R(u);return d.empty?F(a):d.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 Y($(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 ie(a){try{const r=E(A,"users",a,"moduleProgress"),u=await R(r);if(u.empty)return{};const d={};return u.forEach(s=>{const e=s.data();d[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||[]}}),d}catch(r){return console.error("[competencyService] fetchModuleProgress failed:",r),{}}}function _(a,r,u,d){const s=r.filter(m=>m.moduleId===a),e=s.length>0?s.reduce((m,b)=>m+b.score,0)/s.length:0,h=["identification","multiple_choice"],p=s.filter(m=>h.includes(m.questionType)),i=p.length>0?p.reduce((m,b)=>m+b.score,0)/p.length:e*.9,o=["word_problem","equation_based","enumeration"],l=s.filter(m=>o.includes(m.questionType)),n=l.length>0?l.reduce((m,b)=>m+b.score,0)/l.length:e*.85,f=u,c=f?.lessonsCompleted?.length||0,k=f?.quizzesCompleted?.length||0,S=f?.sessionsCompleted||0,y=d.find(m=>m.id===a),x=y?.lessons?.length||1,N=y?.quizzes?.length||1,C=Math.min(100,c/x*100),M=Math.min(100,k/N*100),v=Math.min(100,(C+M+S*5)/2.5);if(s.length<2){const m=v>50?60+v*.3:v*.8;return{overallMastery:e,conceptGrasp:i,application:n,engagement:v,consistency:Math.min(100,m)}}const w=s.map(m=>m.score),z=w.reduce((m,b)=>m+b,0)/w.length,D=w.reduce((m,b)=>m+Math.pow(b-z,2),0)/w.length,j=Math.sqrt(D)/Math.max(z,1),q=Math.max(0,Math.min(100,(1-j)*100));return{overallMastery:Math.round(e),conceptGrasp:Math.round(i),application:Math.round(n),engagement:Math.round(v),consistency:Math.round(q)}}async function le(a){try{const r=E(A,"users",a,"competencyMatrix"),u=await R(r);if(u.empty)return{};const d={};return u.forEach(s=>{const e=s.data();d[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}}),d}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 ce(a){const[r,u]=g.useState([]),[d,s]=g.useState([]),[e,h]=g.useState("N/A"),[p,i]=g.useState(!0),[o,l]=g.useState(null),[n,f]=g.useState(!1),c=g.useRef(0),k=g.useCallback(async(y,x)=>{if(x!==c.current)return;const C=J(null)[0]??"gen-math",M=V.find(j=>j.id===C)?.modules||[],v=M.map((j,q)=>({id:j.id,name:j.title.length>15?j.title.substring(0,15).trim()+"...":j.title,color:P[q%P.length]})),w=await le(a);if(x!==c.current)return;if(Object.keys(w).length>0){de(w,v,u,h),f(!1),i(!1);return}const z=await re(a),D=await ie(a);if(x!==c.current)return;const T=z.length>0;f(!T),ue(z,D,v,M,u,h),i(!1)},[a]),S=g.useCallback(async()=>{if(!a){i(!1);return}const y=++c.current;i(!0),l(null);try{const x=await new Promise(N=>{const C=I(a,M=>{C(),N(M)})});if(y!==c.current)return;await k(x,y)}catch(x){console.error("[useCompetencyMatrix] Failed to load:",x),y===c.current&&(l("Failed to load competency data. Please try again."),i(!1))}},[a,k]);return g.useEffect(()=>{if(!a)return;const y=I(a,x=>{const N=++c.current;k(x,N)});return()=>y()},[a,k]),{data:r,modulesList:d,topModule:e,loading:p,error:o,isEmpty:n,refresh:S}}function de(a,r,u,d){let s=-1,e="N/A";const h=Q.map(p=>{const i={metric:p.label,fullMark:100};return r.forEach(o=>{const l=a[o.id];l&&(p.key==="progress"?i[o.id]=l.overallMastery:p.key==="concept"?i[o.id]=l.conceptGrasp:p.key==="application"?i[o.id]=l.application:p.key==="engagement"?i[o.id]=l.engagement:p.key==="consistency"&&(i[o.id]=l.consistency))}),i});r.forEach(p=>{const i=a[p.id];if(i){const o=(i.overallMastery+i.conceptGrasp+i.application+i.engagement+i.consistency)/5;o>s&&(s=o,e=p.name)}}),d(e),u(h)}function ue(a,r,u,d,s,e){let h=-1,p="N/A";const i=Q.map(o=>{const l={metric:o.label,fullMark:100};return d.forEach(n=>{const f=r[n.id],c=_(n.id,a,f??{moduleId:n.id,sessionsCompleted:0,moduleTitle:n.title,lessonsCompleted:[],quizzesCompleted:[]},d);o.key==="progress"?l[n.id]=c.overallMastery:o.key==="concept"?l[n.id]=c.conceptGrasp:o.key==="application"?l[n.id]=c.application:o.key==="engagement"?l[n.id]=c.engagement:o.key==="consistency"&&(l[n.id]=c.consistency)}),l});d.forEach(o=>{const l=r[o.id],n=_(o.id,a,l??{moduleId:o.id,sessionsCompleted:0,moduleTitle:o.title,lessonsCompleted:[],quizzesCompleted:[]},d),f=(n.overallMastery+n.conceptGrasp+n.application+n.engagement+n.consistency)/5;f>h&&(h=f,p=u.find(c=>c.id===o.id)?.name||"N/A")}),e(p),s(i)}const Me=()=>{const{userProfile:a}=B(),{data:r,modulesList:u,topModule:d,loading:s,error:e,isEmpty:h,refresh:p}=ce(a?.uid??""),[i,o]=g.useState(!1),l=()=>{p()};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/80 backdrop-blur-xl border border-white/50 shadow-[0_8px_30px_rgb(0,0,0,0.04)] rounded-[2rem] p-6 lg:p-8 isolate group",onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!1),children:[t.jsx("div",{className:"absolute top-0 right-0 w-64 h-64 bg-violet-400/5 rounded-full blur-3xl -translate-y-1/2 translate-x-1/4"}),t.jsx("div",{className:"absolute bottom-0 left-0 w-48 h-48 bg-rose-400/5 rounded-full blur-3xl translate-y-1/3 -translate-x-1/3"}),t.jsxs("div",{className:"flex flex-col sm:flex-row items-start sm:items-center justify-between mb-8 relative z-10 gap-4",children:[t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[t.jsx("span",{className:"p-2 bg-violet-100 text-violet-600 rounded-xl",children:t.jsx(O,{size:20,className:"stroke-[2.5]"})}),t.jsx("h3",{className:"text-xl font-display font-extrabold text-[#0a1628] tracking-tight",children:"Competency Matrix"})]}),t.jsx("p",{className:"text-sm text-[#5a6578] font-body ml-12",children:"Your realtime performance across modules"})]}),!s&&!h&&!e&&t.jsxs("div",{className:"flex items-center gap-3 bg-slate-50 border border-slate-100 px-4 py-2 rounded-2xl ml-12 sm:ml-0",children:[t.jsx("div",{className:"flex items-center justify-center w-8 h-8 rounded-full bg-white shadow-sm border border-slate-100",children:t.jsx(X,{size:14,className:"text-amber-500"})}),t.jsxs("div",{children:[t.jsx("p",{className:"text-[10px] font-bold text-slate-400 uppercase tracking-wider",children:"Top Module"}),t.jsx("p",{className:"text-sm font-bold text-slate-700",children:d})]})]}),!s&&t.jsx("button",{onClick:l,className:"sm:ml-auto text-xs font-semibold text-slate-400 hover:text-violet-600 transition-colors px-2 py-1 rounded-lg hover:bg-violet-50",title:"Refresh competency data",children:"Refresh"})]}),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-violet-200 border-t-violet-500 rounded-full animate-spin"}),t.jsx("p",{className:"text-sm 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-16 h-16 rounded-2xl bg-slate-100 flex items-center justify-center",children:t.jsx(W,{size:28,className:"text-slate-400"})}),t.jsxs("div",{className:"text-center",children:[t.jsx("p",{className:"text-sm font-semibold text-slate-600 mb-1",children:e?"Unable to load competency data":"No activity yet"}),t.jsx("p",{className:"text-xs text-slate-400 max-w-[260px]",children:e||"Complete quizzes and lessons to see your competency matrix here."})]}),e&&t.jsx("button",{onClick:l,className:"px-4 py-2 text-xs font-semibold bg-violet-100 text-violet-700 rounded-xl hover:bg-violet-200 transition-colors",children:"Try Again"})]}):t.jsx(Z,{width:"100%",height:"100%",children:t.jsxs(ee,{cx:"50%",cy:"50%",outerRadius:i?"75%":"70%",data:r,children:[t.jsx(te,{stroke:"#e2e8f0",strokeDasharray:"4 4",polarRadius:[20,40,60,80,100]}),t.jsx(se,{dataKey:"metric",tick:{fill:"#475569",fontSize:12,fontWeight:600,fontFamily:"Inter, sans-serif"}}),t.jsx(ne,{angle:90,domain:[0,100],tick:{fill:"#94a3b8",fontSize:10},tickCount:6,axisLine:!1}),u.map(n=>t.jsx(ae,{name:n.name,dataKey:n.id,stroke:n.color,strokeWidth:2,fill:n.color,fillOpacity:.35,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(oe,{cursor:!1,content:({active:n,payload:f})=>n&&f&&f.length?t.jsxs("div",{className:"bg-white/95 backdrop-blur shadow-[0_10px_40px_-10px_rgba(0,0,0,0.15)] border border-slate-100 rounded-xl p-4",children:[t.jsx("p",{className:"font-display font-bold text-slate-800 text-sm mb-3",children:f[0].payload.metric}),t.jsx("div",{className:"flex flex-col gap-2",children:f.map(c=>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:c.stroke}}),t.jsx("span",{className:"text-xs font-bold text-slate-600 uppercase tracking-wide truncate max-w-[120px]",title:String(c.name),children:String(c.name)})]}),t.jsxs("span",{className:"text-sm font-black",style:{color:c.stroke},children:[Math.round(c.value),"%"]})]},c.name))})]}):null})]})})}),!s&&!h&&!e&&u.length>0&&t.jsx("div",{className:"flex flex-wrap justify-center items-center gap-3 md:gap-5 mt-[5px] z-10 relative",children:u.map(n=>t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("div",{className:"w-2.5 h-2.5 rounded-full",style:{backgroundColor:n.color}}),t.jsx("span",{className:"text-[10px] font-bold text-slate-600 uppercase tracking-widest",children:n.name.length>15?n.name.substring(0,12)+"...":n.name})]},n.id))})]})};export{Me as CompetencyRadarChart}; +import{r as g,j as t}from"./vendor-react-B4AQeu28.js";import{h as A,a5 as I,l as B,m as L,B as O,a as W}from"./index-uASBzalf.js";import{collection as E,getDocs as R,query as H,orderBy as K,limit as U,Timestamp as G,getDoc as Y,doc as $}from"./vendor-firebase-firestore-CP9q7ISf.js";import{g as J,s as V}from"./subjects-F8wTuRgo.js";import{S as X}from"./sparkles-DHVr5IP1.js";import{R as Z,e as ee,P as te,f as se,g as ne,h as ae,T as oe}from"./vendor-charts-Ckgeb0nY.js";import"./vendor-firebase-core-DCQrgkxC.js";import"./vendor-firebase-auth-Bcpr4O6E.js";import"./vendor-firebase-storage-dc5X5yTv.js";import"./vendor-firebase-analytics-CHPyhRzk.js";import"./vendor-radix-xDOIcVzp.js";import"./vendor-markdown-yqZQ_iQm.js";import"./chart-column-CLoxLorp.js";const P=["#1FA7E1","#9956DE","#75D06A","#FFB356","#7274ED","#FF8B8B","#6ED1CF","#FB96BB"];async function re(a){try{const r=E(A,"users",a,"quizResults"),u=H(r,K("timestamp","desc"),U(500)),d=await R(u);return d.empty?F(a):d.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 Y($(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 ie(a){try{const r=E(A,"users",a,"moduleProgress"),u=await R(r);if(u.empty)return{};const d={};return u.forEach(s=>{const e=s.data();d[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||[]}}),d}catch(r){return console.error("[competencyService] fetchModuleProgress failed:",r),{}}}function _(a,r,u,d){const s=r.filter(m=>m.moduleId===a),e=s.length>0?s.reduce((m,b)=>m+b.score,0)/s.length:0,h=["identification","multiple_choice"],p=s.filter(m=>h.includes(m.questionType)),i=p.length>0?p.reduce((m,b)=>m+b.score,0)/p.length:e*.9,o=["word_problem","equation_based","enumeration"],l=s.filter(m=>o.includes(m.questionType)),n=l.length>0?l.reduce((m,b)=>m+b.score,0)/l.length:e*.85,f=u,c=f?.lessonsCompleted?.length||0,k=f?.quizzesCompleted?.length||0,S=f?.sessionsCompleted||0,y=d.find(m=>m.id===a),x=y?.lessons?.length||1,N=y?.quizzes?.length||1,C=Math.min(100,c/x*100),M=Math.min(100,k/N*100),v=Math.min(100,(C+M+S*5)/2.5);if(s.length<2){const m=v>50?60+v*.3:v*.8;return{overallMastery:e,conceptGrasp:i,application:n,engagement:v,consistency:Math.min(100,m)}}const w=s.map(m=>m.score),z=w.reduce((m,b)=>m+b,0)/w.length,D=w.reduce((m,b)=>m+Math.pow(b-z,2),0)/w.length,j=Math.sqrt(D)/Math.max(z,1),q=Math.max(0,Math.min(100,(1-j)*100));return{overallMastery:Math.round(e),conceptGrasp:Math.round(i),application:Math.round(n),engagement:Math.round(v),consistency:Math.round(q)}}async function le(a){try{const r=E(A,"users",a,"competencyMatrix"),u=await R(r);if(u.empty)return{};const d={};return u.forEach(s=>{const e=s.data();d[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}}),d}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 ce(a){const[r,u]=g.useState([]),[d,s]=g.useState([]),[e,h]=g.useState("N/A"),[p,i]=g.useState(!0),[o,l]=g.useState(null),[n,f]=g.useState(!1),c=g.useRef(0),k=g.useCallback(async(y,x)=>{if(x!==c.current)return;const C=J(null)[0]??"gen-math",M=V.find(j=>j.id===C)?.modules||[],v=M.map((j,q)=>({id:j.id,name:j.title.length>15?j.title.substring(0,15).trim()+"...":j.title,color:P[q%P.length]})),w=await le(a);if(x!==c.current)return;if(Object.keys(w).length>0){de(w,v,u,h),f(!1),i(!1);return}const z=await re(a),D=await ie(a);if(x!==c.current)return;const T=z.length>0;f(!T),ue(z,D,v,M,u,h),i(!1)},[a]),S=g.useCallback(async()=>{if(!a){i(!1);return}const y=++c.current;i(!0),l(null);try{const x=await new Promise(N=>{const C=I(a,M=>{C(),N(M)})});if(y!==c.current)return;await k(x,y)}catch(x){console.error("[useCompetencyMatrix] Failed to load:",x),y===c.current&&(l("Failed to load competency data. Please try again."),i(!1))}},[a,k]);return g.useEffect(()=>{if(!a)return;const y=I(a,x=>{const N=++c.current;k(x,N)});return()=>y()},[a,k]),{data:r,modulesList:d,topModule:e,loading:p,error:o,isEmpty:n,refresh:S}}function de(a,r,u,d){let s=-1,e="N/A";const h=Q.map(p=>{const i={metric:p.label,fullMark:100};return r.forEach(o=>{const l=a[o.id];l&&(p.key==="progress"?i[o.id]=l.overallMastery:p.key==="concept"?i[o.id]=l.conceptGrasp:p.key==="application"?i[o.id]=l.application:p.key==="engagement"?i[o.id]=l.engagement:p.key==="consistency"&&(i[o.id]=l.consistency))}),i});r.forEach(p=>{const i=a[p.id];if(i){const o=(i.overallMastery+i.conceptGrasp+i.application+i.engagement+i.consistency)/5;o>s&&(s=o,e=p.name)}}),d(e),u(h)}function ue(a,r,u,d,s,e){let h=-1,p="N/A";const i=Q.map(o=>{const l={metric:o.label,fullMark:100};return d.forEach(n=>{const f=r[n.id],c=_(n.id,a,f??{moduleId:n.id,sessionsCompleted:0,moduleTitle:n.title,lessonsCompleted:[],quizzesCompleted:[]},d);o.key==="progress"?l[n.id]=c.overallMastery:o.key==="concept"?l[n.id]=c.conceptGrasp:o.key==="application"?l[n.id]=c.application:o.key==="engagement"?l[n.id]=c.engagement:o.key==="consistency"&&(l[n.id]=c.consistency)}),l});d.forEach(o=>{const l=r[o.id],n=_(o.id,a,l??{moduleId:o.id,sessionsCompleted:0,moduleTitle:o.title,lessonsCompleted:[],quizzesCompleted:[]},d),f=(n.overallMastery+n.conceptGrasp+n.application+n.engagement+n.consistency)/5;f>h&&(h=f,p=u.find(c=>c.id===o.id)?.name||"N/A")}),e(p),s(i)}const Me=()=>{const{userProfile:a}=B(),{data:r,modulesList:u,topModule:d,loading:s,error:e,isEmpty:h,refresh:p}=ce(a?.uid??""),[i,o]=g.useState(!1),l=()=>{p()};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/80 backdrop-blur-xl border border-white/50 shadow-[0_8px_30px_rgb(0,0,0,0.04)] rounded-[2rem] p-6 lg:p-8 isolate group",onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!1),children:[t.jsx("div",{className:"absolute top-0 right-0 w-64 h-64 bg-violet-400/5 rounded-full blur-3xl -translate-y-1/2 translate-x-1/4"}),t.jsx("div",{className:"absolute bottom-0 left-0 w-48 h-48 bg-rose-400/5 rounded-full blur-3xl translate-y-1/3 -translate-x-1/3"}),t.jsxs("div",{className:"flex flex-col sm:flex-row items-start sm:items-center justify-between mb-8 relative z-10 gap-4",children:[t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[t.jsx("span",{className:"p-2 bg-violet-100 text-violet-600 rounded-xl",children:t.jsx(O,{size:20,className:"stroke-[2.5]"})}),t.jsx("h3",{className:"text-xl font-display font-extrabold text-[#0a1628] tracking-tight",children:"Competency Matrix"})]}),t.jsx("p",{className:"text-sm text-[#5a6578] font-body ml-12",children:"Your realtime performance across modules"})]}),!s&&!h&&!e&&t.jsxs("div",{className:"flex items-center gap-3 bg-slate-50 border border-slate-100 px-4 py-2 rounded-2xl ml-12 sm:ml-0",children:[t.jsx("div",{className:"flex items-center justify-center w-8 h-8 rounded-full bg-white shadow-sm border border-slate-100",children:t.jsx(X,{size:14,className:"text-amber-500"})}),t.jsxs("div",{children:[t.jsx("p",{className:"text-[10px] font-bold text-slate-400 uppercase tracking-wider",children:"Top Module"}),t.jsx("p",{className:"text-sm font-bold text-slate-700",children:d})]})]}),!s&&t.jsx("button",{onClick:l,className:"sm:ml-auto text-xs font-semibold text-slate-400 hover:text-violet-600 transition-colors px-2 py-1 rounded-lg hover:bg-violet-50",title:"Refresh competency data",children:"Refresh"})]}),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-violet-200 border-t-violet-500 rounded-full animate-spin"}),t.jsx("p",{className:"text-sm 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-16 h-16 rounded-2xl bg-slate-100 flex items-center justify-center",children:t.jsx(W,{size:28,className:"text-slate-400"})}),t.jsxs("div",{className:"text-center",children:[t.jsx("p",{className:"text-sm font-semibold text-slate-600 mb-1",children:e?"Unable to load competency data":"No activity yet"}),t.jsx("p",{className:"text-xs text-slate-400 max-w-[260px]",children:e||"Complete quizzes and lessons to see your competency matrix here."})]}),e&&t.jsx("button",{onClick:l,className:"px-4 py-2 text-xs font-semibold bg-violet-100 text-violet-700 rounded-xl hover:bg-violet-200 transition-colors",children:"Try Again"})]}):t.jsx(Z,{width:"100%",height:"100%",children:t.jsxs(ee,{cx:"50%",cy:"50%",outerRadius:i?"75%":"70%",data:r,children:[t.jsx(te,{stroke:"#e2e8f0",strokeDasharray:"4 4",polarRadius:[20,40,60,80,100]}),t.jsx(se,{dataKey:"metric",tick:{fill:"#475569",fontSize:12,fontWeight:600,fontFamily:"Inter, sans-serif"}}),t.jsx(ne,{angle:90,domain:[0,100],tick:{fill:"#94a3b8",fontSize:10},tickCount:6,axisLine:!1}),u.map(n=>t.jsx(ae,{name:n.name,dataKey:n.id,stroke:n.color,strokeWidth:2,fill:n.color,fillOpacity:.35,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(oe,{cursor:!1,content:({active:n,payload:f})=>n&&f&&f.length?t.jsxs("div",{className:"bg-white/95 backdrop-blur shadow-[0_10px_40px_-10px_rgba(0,0,0,0.15)] border border-slate-100 rounded-xl p-4",children:[t.jsx("p",{className:"font-display font-bold text-slate-800 text-sm mb-3",children:f[0].payload.metric}),t.jsx("div",{className:"flex flex-col gap-2",children:f.map(c=>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:c.stroke}}),t.jsx("span",{className:"text-xs font-bold text-slate-600 uppercase tracking-wide truncate max-w-[120px]",title:String(c.name),children:String(c.name)})]}),t.jsxs("span",{className:"text-sm font-black",style:{color:c.stroke},children:[Math.round(c.value),"%"]})]},c.name))})]}):null})]})})}),!s&&!h&&!e&&u.length>0&&t.jsx("div",{className:"flex flex-wrap justify-center items-center gap-3 md:gap-5 mt-[5px] z-10 relative",children:u.map(n=>t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("div",{className:"w-2.5 h-2.5 rounded-full",style:{backgroundColor:n.color}}),t.jsx("span",{className:"text-[10px] font-bold text-slate-600 uppercase tracking-widest",children:n.name.length>15?n.name.substring(0,12)+"...":n.name})]},n.id))})]})};export{Me as CompetencyRadarChart}; diff --git a/assets/ConfirmModal-6cgkqXAT.js b/assets/ConfirmModal-D2z4s_BB.js similarity index 78% rename from assets/ConfirmModal-6cgkqXAT.js rename to assets/ConfirmModal-D2z4s_BB.js index 79a8b6b0e609f553ade4ef358d52a65752708fba..cb8ee0ea052a7bf7023d2222757359581e0147e9 100644 --- a/assets/ConfirmModal-6cgkqXAT.js +++ b/assets/ConfirmModal-D2z4s_BB.js @@ -1 +1 @@ -import{j as e}from"./vendor-react-B4AQeu28.js";import{B as i}from"./button-DCfeFHoH.js";import{j as f,m as r,p as h}from"./index-BaOs5Ayg.js";import{X as j}from"./x-TNvtuOD9.js";import{T as y}from"./trash-2-HTnKafZd.js";import{L as w}from"./log-out-BenDMDly.js";import"./vendor-radix-BorKzPz9.js";import"./vendor-charts-D8hf8tI0.js";import"./vendor-firebase-firestore-CH1lNiRF.js";import"./vendor-firebase-core-CO26nNq6.js";import"./vendor-firebase-auth-BLpRW_zO.js";import"./vendor-firebase-storage-B3igpVVS.js";import"./vendor-firebase-analytics-CTiUNb0-.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(y,{size:32});case"warning":default:return e.jsx(h,{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(f,{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:u=>u.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(j,{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-BPmLcOpC.js";import{g as f,m as r,w as h}from"./index-uASBzalf.js";import{X as y}from"./x-CBb03rh3.js";import{T as j}from"./trash-2-D7q6y9vT.js";import{L as w}from"./log-out-Dr0BHRO4.js";import"./vendor-radix-xDOIcVzp.js";import"./vendor-charts-Ckgeb0nY.js";import"./vendor-firebase-firestore-CP9q7ISf.js";import"./vendor-firebase-core-DCQrgkxC.js";import"./vendor-firebase-auth-Bcpr4O6E.js";import"./vendor-firebase-storage-dc5X5yTv.js";import"./vendor-firebase-analytics-CHPyhRzk.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(h,{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(f,{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:u=>u.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/FloatingAITutor-BIdguqCV.js b/assets/FloatingAITutor-D0ZeNKA0.js similarity index 86% rename from assets/FloatingAITutor-BIdguqCV.js rename to assets/FloatingAITutor-D0ZeNKA0.js index cc087afc351e5c6a5ca8c68a9624c51cd66691d6..ad72b9a39b54f0b66745a55e203de1c5c7794869 100644 --- a/assets/FloatingAITutor-BIdguqCV.js +++ b/assets/FloatingAITutor-D0ZeNKA0.js @@ -1,2 +1,2 @@ -const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ChatMarkdown-fgwaycBR.js","assets/index-BaOs5Ayg.js","assets/vendor-react-B4AQeu28.js","assets/vendor-firebase-firestore-CH1lNiRF.js","assets/vendor-firebase-core-CO26nNq6.js","assets/vendor-firebase-auth-BLpRW_zO.js","assets/vendor-firebase-storage-B3igpVVS.js","assets/vendor-firebase-analytics-CTiUNb0-.js","assets/vendor-radix-BorKzPz9.js","assets/vendor-charts-D8hf8tI0.js","assets/vendor-markdown-yqZQ_iQm.js","assets/vendor-markdown-CfVKi3_s.css","assets/index-DdX2rVyy.css"])))=>i.map(i=>d[i]); -import{ay as C,_ as y,m as b,w as A}from"./index-BaOs5Ayg.js";import{r as i,j as e}from"./vendor-react-B4AQeu28.js";import{M}from"./maximize-2-EHa6JURc.js";import{M as w}from"./minus-DfrEv-SC.js";import{X as g}from"./x-TNvtuOD9.js";import{S as L}from"./send-CwwDU3uJ.js";import"./vendor-firebase-firestore-CH1lNiRF.js";import"./vendor-firebase-core-CO26nNq6.js";import"./vendor-firebase-auth-BLpRW_zO.js";import"./vendor-firebase-storage-B3igpVVS.js";import"./vendor-firebase-analytics-CTiUNb0-.js";import"./vendor-radix-BorKzPz9.js";import"./vendor-charts-D8hf8tI0.js";import"./vendor-markdown-yqZQ_iQm.js";const E=i.lazy(()=>y(()=>import("./ChatMarkdown-fgwaycBR.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12])));function O(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 Q=({constraintsRef:a,onFullScreen:j})=>{const{activeSessionId:r,setActiveSessionId:v,createNewSession:N,getActiveSession:k,sendMessage:I,isLoading:o}=C(),[s,l]=i.useState(!1),[c,u]=i.useState(()=>typeof window>"u"?!1:window.localStorage.getItem("floating_ai_tutor_minimized")==="1"),[n,m]=i.useState(""),h=i.useRef(null);i.useEffect(()=>{typeof window>"u"||window.localStorage.setItem("floating_ai_tutor_minimized",c?"1":"0")},[c]),i.useEffect(()=>{s&&y(async()=>{const{warmupBackend:t}=await import("./index-BaOs5Ayg.js").then(d=>d.b2);return{warmupBackend:t}},__vite__mapDeps([1,2,3,4,5,6,7,8,9,10,11,12])).then(({warmupBackend:t})=>{t()}).catch(t=>{console.warn("Floating tutor warmup skipped:",t)})},[s]),i.useEffect(()=>{if(s&&!r){const t={id:"1",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"})},d=N(t);v(d)}},[s]);const x=k()?.messages||[],S=()=>{h.current?.scrollIntoView({behavior:"smooth"})};i.useEffect(()=>{S()},[x]);const p=async()=>{if(!n.trim()||!r||o)return;const t=n.trim();m(""),await I(r,t)},_=()=>{j()},f=()=>{l(!1),u(!0)},z=()=>{u(!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 ${s?"opacity-100 scale-100 translate-y-0":"opacity-0 scale-95 translate-y-10 pointer-events-none h-0"}`,style:{"--max-h":s?"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:_,type:"button","aria-label":"Open fullscreen",className:"p-2 hover:bg-white/20 rounded-lg transition-colors",title:"Open fullscreen",children:e.jsx(M,{size:16,className:"text-white"})}),e.jsx("button",{type:"button","aria-label":"Minimize AI tutor launcher",onClick:f,className:"p-2 hover:bg-white/20 rounded-lg transition-colors",title:"Minimize",children:e.jsx(w,{size:16,className:"text-white"})}),e.jsx("button",{type:"button","aria-label":"Close chat",onClick:()=>l(!1),className:"p-2 hover:bg-white/20 rounded-lg transition-colors",children:e.jsx(g,{size:16,className:"text-white"})})]})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-4 space-y-3 bg-[#edf1f7]",children:[x.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(i.Suspense,{fallback:e.jsx("p",{className:"text-sm whitespace-pre-wrap",children:t.text}),children:e.jsx(E,{children:t.text})}),e.jsx("p",{className:`text-[10px] mt-1 ${t.sender==="user"?"text-sky-200":"text-slate-500"}`,children:O(t.timestamp)})]})},t.id)),o&&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:h})]}),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:n,onChange:t=>m(t.target.value),onKeyPress:t=>t.key==="Enter"&&p(),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:p,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:!n.trim()||o,children:e.jsx(L,{size:18})})]})})]}),e.jsx("div",{className:"pointer-events-auto relative self-end",children:c?e.jsx(b.button,{type:"button",onClick:z,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(A,{size:14})}):e.jsxs("div",{className:"relative group",children:[!s&&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"})]}),!s&&e.jsx("button",{type:"button","aria-label":"Minimize AI tutor launcher",title:"Minimize",onClick:f,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(w,{size:12})}),e.jsx(b.button,{type:"button",onClick:()=>l(!s),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":s?"Close AI tutor chat":"Open AI tutor chat",style:{willChange:"transform"},children:s?e.jsx(g,{size:28}):e.jsx("img",{src:"/avatar/avatar_icon.png",alt:"AI Tutor",className:"w-14 h-14 object-contain drop-shadow-lg"})})]})})]})};export{Q as default}; +const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ChatMarkdown-BSQ2GO-C.js","assets/index-uASBzalf.js","assets/vendor-react-B4AQeu28.js","assets/vendor-firebase-firestore-CP9q7ISf.js","assets/vendor-firebase-core-DCQrgkxC.js","assets/vendor-firebase-auth-Bcpr4O6E.js","assets/vendor-firebase-storage-dc5X5yTv.js","assets/vendor-firebase-analytics-CHPyhRzk.js","assets/vendor-radix-xDOIcVzp.js","assets/vendor-charts-Ckgeb0nY.js","assets/vendor-markdown-yqZQ_iQm.js","assets/vendor-markdown-CfVKi3_s.css","assets/index-D9pRNq5G.css"])))=>i.map(i=>d[i]); +import{az as C,_ as y,m as b,E as A}from"./index-uASBzalf.js";import{r as i,j as e}from"./vendor-react-B4AQeu28.js";import{M}from"./maximize-2-B2yMqxTx.js";import{M as w}from"./minus-Bfei9C79.js";import{X as g}from"./x-CBb03rh3.js";import{S as L}from"./send-bMgoXVnc.js";import"./vendor-firebase-firestore-CP9q7ISf.js";import"./vendor-firebase-core-DCQrgkxC.js";import"./vendor-firebase-auth-Bcpr4O6E.js";import"./vendor-firebase-storage-dc5X5yTv.js";import"./vendor-firebase-analytics-CHPyhRzk.js";import"./vendor-radix-xDOIcVzp.js";import"./vendor-charts-Ckgeb0nY.js";import"./vendor-markdown-yqZQ_iQm.js";const E=i.lazy(()=>y(()=>import("./ChatMarkdown-BSQ2GO-C.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12])));function O(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 Q=({constraintsRef:a,onFullScreen:j})=>{const{activeSessionId:r,setActiveSessionId:v,createNewSession:N,getActiveSession:k,sendMessage:I,isLoading:o}=C(),[s,l]=i.useState(!1),[c,u]=i.useState(()=>typeof window>"u"?!1:window.localStorage.getItem("floating_ai_tutor_minimized")==="1"),[n,m]=i.useState(""),h=i.useRef(null);i.useEffect(()=>{typeof window>"u"||window.localStorage.setItem("floating_ai_tutor_minimized",c?"1":"0")},[c]),i.useEffect(()=>{s&&y(async()=>{const{warmupBackend:t}=await import("./index-uASBzalf.js").then(d=>d.b3);return{warmupBackend:t}},__vite__mapDeps([1,2,3,4,5,6,7,8,9,10,11,12])).then(({warmupBackend:t})=>{t()}).catch(t=>{console.warn("Floating tutor warmup skipped:",t)})},[s]),i.useEffect(()=>{if(s&&!r){const t={id:"1",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"})},d=N(t);v(d)}},[s]);const x=k()?.messages||[],S=()=>{h.current?.scrollIntoView({behavior:"smooth"})};i.useEffect(()=>{S()},[x]);const p=async()=>{if(!n.trim()||!r||o)return;const t=n.trim();m(""),await I(r,t)},_=()=>{j()},f=()=>{l(!1),u(!0)},z=()=>{u(!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 ${s?"opacity-100 scale-100 translate-y-0":"opacity-0 scale-95 translate-y-10 pointer-events-none h-0"}`,style:{"--max-h":s?"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:_,type:"button","aria-label":"Open fullscreen",className:"p-2 hover:bg-white/20 rounded-lg transition-colors",title:"Open fullscreen",children:e.jsx(M,{size:16,className:"text-white"})}),e.jsx("button",{type:"button","aria-label":"Minimize AI tutor launcher",onClick:f,className:"p-2 hover:bg-white/20 rounded-lg transition-colors",title:"Minimize",children:e.jsx(w,{size:16,className:"text-white"})}),e.jsx("button",{type:"button","aria-label":"Close chat",onClick:()=>l(!1),className:"p-2 hover:bg-white/20 rounded-lg transition-colors",children:e.jsx(g,{size:16,className:"text-white"})})]})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-4 space-y-3 bg-[#edf1f7]",children:[x.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(i.Suspense,{fallback:e.jsx("p",{className:"text-sm whitespace-pre-wrap",children:t.text}),children:e.jsx(E,{children:t.text})}),e.jsx("p",{className:`text-[10px] mt-1 ${t.sender==="user"?"text-sky-200":"text-slate-500"}`,children:O(t.timestamp)})]})},t.id)),o&&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:h})]}),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:n,onChange:t=>m(t.target.value),onKeyPress:t=>t.key==="Enter"&&p(),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:p,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:!n.trim()||o,children:e.jsx(L,{size:18})})]})})]}),e.jsx("div",{className:"pointer-events-auto relative self-end",children:c?e.jsx(b.button,{type:"button",onClick:z,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(A,{size:14})}):e.jsxs("div",{className:"relative group",children:[!s&&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"})]}),!s&&e.jsx("button",{type:"button","aria-label":"Minimize AI tutor launcher",title:"Minimize",onClick:f,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(w,{size:12})}),e.jsx(b.button,{type:"button",onClick:()=>l(!s),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":s?"Close AI tutor chat":"Open AI tutor chat",style:{willChange:"transform"},children:s?e.jsx(g,{size:28}):e.jsx("img",{src:"/avatar/avatar_icon.png",alt:"AI Tutor",className:"w-14 h-14 object-contain drop-shadow-lg"})})]})})]})};export{Q as default}; diff --git a/assets/GradesPage-Y0HsmLPP.js b/assets/GradesPage-BAqThNDB.js similarity index 90% rename from assets/GradesPage-Y0HsmLPP.js rename to assets/GradesPage-BAqThNDB.js index bf953ceb69a27230744bd73e7ab8612d5069c1a7..3b0b9ee43d611144857f896e1460b2ea0f7d76b1 100644 --- a/assets/GradesPage-Y0HsmLPP.js +++ b/assets/GradesPage-BAqThNDB.js @@ -1,2 +1,2 @@ -import{r as o,j as e}from"./vendor-react-B4AQeu28.js";import{B as v}from"./button-DCfeFHoH.js";import{u as J,az as K,aA as W,z as X,A as Z,y as z,T as R}from"./index-BaOs5Ayg.js";import{g as q,S as E}from"./subjects-BFghB0SQ.js";import{u as ee}from"./useCurriculum-DDCuCvMR.js";import{D as te}from"./download-DX_YebqQ.js";import{F as P}from"./funnel-BT77sgnz.js";import"./vendor-radix-BorKzPz9.js";import"./vendor-charts-D8hf8tI0.js";import"./vendor-firebase-firestore-CH1lNiRF.js";import"./vendor-firebase-core-CO26nNq6.js";import"./vendor-firebase-auth-BLpRW_zO.js";import"./vendor-firebase-storage-B3igpVVS.js";import"./vendor-firebase-analytics-CTiUNb0-.js";import"./vendor-markdown-yqZQ_iQm.js";import"./chart-column-B3jJOD5i.js";const ge=()=>{const{currentUser:i,userProfile:w}=J(),[n,N]=o.useState("all"),[x,D]=o.useState("all"),[M,u]=o.useState(!0),[h,L]=o.useState(null),[F,G]=o.useState([]),y=w?.grade,S=q(y),_=new Set(S),{isLoading:Q}=ee(y);o.useEffect(()=>{},[Q]);const O=t=>{if(t==null)return"N/A";const s=t instanceof Date?t:new Date(t);return Number.isNaN(s.getTime())?"N/A":s.toISOString().split("T")[0]};o.useEffect(()=>{if(!i)return;u(!0);const t=K(i.uid,a=>{L(a),u(!1)}),s=W(i.uid,a=>{G(a),u(!1)});return()=>{t(),s()}},[i]);const b=h?.averageScore?Math.round(h.averageScore):0,U=h?.quizzesCompleted??0,B=b>0?(b/100*4).toFixed(2):"0.00",I={"gen-math":"indigo","stats-prob":"violet"},k={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"}},A=E.reduce((t,s)=>(t[s.id]={label:s.name,color:I[s.id]||"slate"},t),{}),c=E.filter(t=>_.has(t.id)).map(t=>t.name),T=Object.entries({}).filter(([t])=>_.has(t)).map(([t,s])=>{const a=A[t]||{label:t,color:"slate"},r=[],f=r.length>0?Math.round(r.reduce((g,p)=>g+p.score,0)/r.length):Math.round(s?.progress??0);return{subject:a.label,average:f,quizzes:r.length||s?.completedModules,color:a.color}}),H=S.map(t=>{const s=A[t]||{label:t,color:"slate"};return{subject:s.label,average:0,quizzes:0,color:s.color}}),C=T.length>0?T:H,$=F.slice().sort((t,s)=>{const a=t.completedAt?.toDate?.()?.getTime()??0;return(s.completedAt?.toDate?.()?.getTime()??0)-a}).slice(0,10).map((t,s)=>({id:s+1,title:t.title||`Assessment ${s+1}`,subject:t.subject||"General",score:t.score,date:t.completedAt?O(t.completedAt.toDate()):"N/A",type:t.type==="practice"?"practice":(t.type==="diagnostic","module"),status:t.score>=80?"Excellent":t.score>=60?"Passing":"Needs Review"})).filter(t=>c.includes(t.subject)),m=$.filter(t=>{if(!c.includes(t.subject))return!1;const s=n==="all"||t.subject===n,a=x==="all"||t.type===x;return s&&a});o.useEffect(()=>{n!=="all"&&(c.includes(n)||N("all"))},[c,n]);const V=()=>{const t=l=>{const j=String(l??"");return/[",\n]/.test(j)?`"${j.replace(/"/g,'""')}"`:j},s=[],a=w?.name||i?.displayName||i?.email||"Student",r=new Date().toISOString().split("T")[0];s.push("Grade Report"),s.push(`Student,${t(a)}`),s.push(`Export Date,${t(r)}`),s.push(`Subject Filter,${t(n)}`),s.push(`Type Filter,${t(x)}`),s.push(""),s.push("Subject Performance"),s.push("Subject,Average Score"),C.forEach(l=>{s.push([t(l.subject),t(l.average)].join(","))}),s.push(""),s.push("Recent Quizzes"),s.push("Title,Subject,Score,Date,Type,Status"),m.length===0?s.push("No quiz data available for the selected filters"):m.forEach(l=>{s.push([t(l.title),t(l.subject),t(l.score),t(l.date),t(l.type),t(l.status)].join(","))});const f=s.join(` -`),g=new Blob([f],{type:"text/csv;charset=utf-8;"}),p=window.URL.createObjectURL(g),d=document.createElement("a"),Y=a.replace(/[^a-z0-9]+/gi,"-").replace(/^-+|-+$/g,"").toLowerCase()||"student";d.href=p,d.setAttribute("download",`grade-report-${Y}-${r}.csv`),document.body.appendChild(d),d.click(),document.body.removeChild(d),window.URL.revokeObjectURL(p)};return M?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-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-6 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(v,{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(X,{className:"w-4 h-4 mr-2 text-slate-400"}),"This Semester"]}),e.jsxs(v,{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:V,children:[e.jsx(te,{className:"w-4 h-4 mr-2"}),"Report"]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-6",children:[e.jsxs("div",{className:"bg-white rounded-[2rem] border border-slate-100 p-6 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-8 -top-8 w-32 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-14 h-14 bg-indigo-100 text-indigo-600 rounded-2xl flex items-center justify-center mb-6 shadow-sm",children:e.jsx(Z,{className:"w-7 h-7"})}),e.jsx("p",{className:"text-slate-400 font-bold text-sm tracking-wide uppercase",children:"Overall GPA"}),e.jsx("div",{className:"flex items-end gap-2 mt-2",children:e.jsx("h3",{className:"text-4xl font-display font-black text-slate-800",children:B})})]})]}),e.jsxs("div",{className:"bg-white rounded-[2rem] border border-slate-100 p-6 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-8 -top-8 w-32 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-14 h-14 bg-emerald-100 text-emerald-600 rounded-2xl flex items-center justify-center mb-6 shadow-sm",children:e.jsx(z,{className:"w-7 h-7"})}),e.jsx("p",{className:"text-slate-400 font-bold text-sm tracking-wide uppercase",children:"Average Score"}),e.jsx("div",{className:"flex items-end gap-2 mt-2",children:e.jsxs("h3",{className:"text-4xl font-display font-black text-slate-800",children:[b,"%"]})})]})]}),e.jsxs("div",{className:"bg-white rounded-[2rem] border border-slate-100 p-6 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-8 -top-8 w-32 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-14 h-14 bg-violet-100 text-violet-600 rounded-2xl flex items-center justify-center mb-6 shadow-sm",children:e.jsx(R,{className:"w-7 h-7"})}),e.jsx("p",{className:"text-slate-400 font-bold text-sm tracking-wide uppercase",children:"Quizzes Completed"}),e.jsx("div",{className:"flex items-end gap-2 mt-2",children:e.jsx("h3",{className:"text-4xl font-display font-black text-slate-800",children:U})})]})]})]}),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-[2rem] border border-slate-100 shadow-[0_8px_30px_-12px_rgba(0,0,0,0.06)] overflow-hidden flex flex-col h-full",children:[e.jsxs("div",{className:"p-6 sm:p-8 border-b border-slate-50 flex flex-col sm:flex-row justify-between items-start sm:items-center 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-3 w-full sm:w-auto",children:[e.jsxs("div",{className:"relative flex-1 sm:flex-none",children:[e.jsxs("select",{value:n,onChange:t=>N(t.target.value),className:"appearance-none w-full pl-4 pr-10 py-2.5 border-none bg-slate-50 rounded-xl text-sm font-bold text-slate-600 focus:ring-2 focus:ring-indigo-500/30 transition-all cursor-pointer min-w-[140px] shadow-sm",children:[e.jsx("option",{value:"all",children:"All Subjects"}),c.map(t=>e.jsx("option",{value:t,children:t},t))]}),e.jsx(P,{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:x,onChange:t=>D(t.target.value),className:"appearance-none w-full pl-4 pr-10 py-2.5 border-none bg-slate-50 rounded-xl text-sm font-bold text-slate-600 focus:ring-2 focus:ring-indigo-500/30 transition-all cursor-pointer min-w-[120px] shadow-sm",children:[e.jsx("option",{value:"all",children:"All Types"}),e.jsx("option",{value:"module",children:"Module Quiz"}),e.jsx("option",{value:"practice",children:"Practice"})]}),e.jsx(P,{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 flex-1 p-2",children:e.jsxs("table",{className:"w-full text-left border-separate border-spacing-y-2 px-4 sm:px-6 mb-4",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:m.length>0?m.map(t=>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:t.title}),e.jsx("p",{className:"text-[11px] font-bold text-slate-400 mt-1",children:t.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:t.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 ${t.type==="practice"?"bg-emerald-100/50 text-emerald-600":"bg-indigo-100/50 text-indigo-600"}`,children:t.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 ${t.score>=80?"bg-emerald-100 text-emerald-700":t.score>=60?"bg-amber-100 text-amber-700":"bg-rose-100 text-rose-700"}`,children:[t.score,"%"]})})]},t.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(z,{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-[2rem] border border-slate-100 p-6 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:C.map((t,s)=>{const a=k[t.color]||k.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 ${a.dot} group-hover:scale-125 transition-transform`}),t.subject]}),e.jsxs("p",{className:"text-[11px] text-slate-400 font-bold ml-4 mt-0.5",children:[t.quizzes," activities"]})]}),e.jsxs("span",{className:"text-[15px] font-black text-slate-800",children:[t.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 ${a.bar} shadow-sm relative overflow-hidden transition-all duration-1000`,style:{"--w":`${Math.max(t.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]"})})})]},s)})})]}),e.jsxs("div",{className:"relative bg-gradient-to-br from-indigo-600 to-violet-700 rounded-[2rem] p-6 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(R,{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:$.length})," activities recently. Try a practice session to boost your lowest scores."]}),e.jsx(v,{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"})]})]})]})]})]})};export{ge as default}; +import{r as o,j as e}from"./vendor-react-B4AQeu28.js";import{B as v}from"./button-BPmLcOpC.js";import{l as J,aA as K,aB as W,D as X,A as Z,q as R,T as D}from"./index-uASBzalf.js";import{g as q,S as E}from"./subjects-F8wTuRgo.js";import{u as ee}from"./useCurriculum-DZVkK6Ec.js";import{D as te}from"./download-CVrPjUr0.js";import{F as P}from"./funnel-CSHS_tp4.js";import"./vendor-radix-xDOIcVzp.js";import"./vendor-charts-Ckgeb0nY.js";import"./vendor-firebase-firestore-CP9q7ISf.js";import"./vendor-firebase-core-DCQrgkxC.js";import"./vendor-firebase-auth-Bcpr4O6E.js";import"./vendor-firebase-storage-dc5X5yTv.js";import"./vendor-firebase-analytics-CHPyhRzk.js";import"./vendor-markdown-yqZQ_iQm.js";import"./chart-column-CLoxLorp.js";const ge=()=>{const{currentUser:i,userProfile:w}=J(),[n,N]=o.useState("all"),[x,z]=o.useState("all"),[M,u]=o.useState(!0),[h,L]=o.useState(null),[F,G]=o.useState([]),y=w?.grade,S=q(y),_=new Set(S),{isLoading:Q}=ee(y);o.useEffect(()=>{},[Q]);const B=t=>{if(t==null)return"N/A";const s=t instanceof Date?t:new Date(t);return Number.isNaN(s.getTime())?"N/A":s.toISOString().split("T")[0]};o.useEffect(()=>{if(!i)return;u(!0);const t=K(i.uid,a=>{L(a),u(!1)}),s=W(i.uid,a=>{G(a),u(!1)});return()=>{t(),s()}},[i]);const b=h?.averageScore?Math.round(h.averageScore):0,O=h?.quizzesCompleted??0,U=b>0?(b/100*4).toFixed(2):"0.00",I={"gen-math":"indigo","stats-prob":"violet"},k={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"}},A=E.reduce((t,s)=>(t[s.id]={label:s.name,color:I[s.id]||"slate"},t),{}),c=E.filter(t=>_.has(t.id)).map(t=>t.name),T=Object.entries({}).filter(([t])=>_.has(t)).map(([t,s])=>{const a=A[t]||{label:t,color:"slate"},r=[],f=r.length>0?Math.round(r.reduce((g,p)=>g+p.score,0)/r.length):Math.round(s?.progress??0);return{subject:a.label,average:f,quizzes:r.length||s?.completedModules,color:a.color}}),H=S.map(t=>{const s=A[t]||{label:t,color:"slate"};return{subject:s.label,average:0,quizzes:0,color:s.color}}),C=T.length>0?T:H,$=F.slice().sort((t,s)=>{const a=t.completedAt?.toDate?.()?.getTime()??0;return(s.completedAt?.toDate?.()?.getTime()??0)-a}).slice(0,10).map((t,s)=>({id:s+1,title:t.title||`Assessment ${s+1}`,subject:t.subject||"General",score:t.score,date:t.completedAt?B(t.completedAt.toDate()):"N/A",type:t.type==="practice"?"practice":(t.type==="diagnostic","module"),status:t.score>=80?"Excellent":t.score>=60?"Passing":"Needs Review"})).filter(t=>c.includes(t.subject)),m=$.filter(t=>{if(!c.includes(t.subject))return!1;const s=n==="all"||t.subject===n,a=x==="all"||t.type===x;return s&&a});o.useEffect(()=>{n!=="all"&&(c.includes(n)||N("all"))},[c,n]);const V=()=>{const t=l=>{const j=String(l??"");return/[",\n]/.test(j)?`"${j.replace(/"/g,'""')}"`:j},s=[],a=w?.name||i?.displayName||i?.email||"Student",r=new Date().toISOString().split("T")[0];s.push("Grade Report"),s.push(`Student,${t(a)}`),s.push(`Export Date,${t(r)}`),s.push(`Subject Filter,${t(n)}`),s.push(`Type Filter,${t(x)}`),s.push(""),s.push("Subject Performance"),s.push("Subject,Average Score"),C.forEach(l=>{s.push([t(l.subject),t(l.average)].join(","))}),s.push(""),s.push("Recent Quizzes"),s.push("Title,Subject,Score,Date,Type,Status"),m.length===0?s.push("No quiz data available for the selected filters"):m.forEach(l=>{s.push([t(l.title),t(l.subject),t(l.score),t(l.date),t(l.type),t(l.status)].join(","))});const f=s.join(` +`),g=new Blob([f],{type:"text/csv;charset=utf-8;"}),p=window.URL.createObjectURL(g),d=document.createElement("a"),Y=a.replace(/[^a-z0-9]+/gi,"-").replace(/^-+|-+$/g,"").toLowerCase()||"student";d.href=p,d.setAttribute("download",`grade-report-${Y}-${r}.csv`),document.body.appendChild(d),d.click(),document.body.removeChild(d),window.URL.revokeObjectURL(p)};return M?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-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-6 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(v,{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(X,{className:"w-4 h-4 mr-2 text-slate-400"}),"This Semester"]}),e.jsxs(v,{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:V,children:[e.jsx(te,{className:"w-4 h-4 mr-2"}),"Report"]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-6",children:[e.jsxs("div",{className:"bg-white rounded-[2rem] border border-slate-100 p-6 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-8 -top-8 w-32 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-14 h-14 bg-indigo-100 text-indigo-600 rounded-2xl flex items-center justify-center mb-6 shadow-sm",children:e.jsx(Z,{className:"w-7 h-7"})}),e.jsx("p",{className:"text-slate-400 font-bold text-sm tracking-wide uppercase",children:"Overall GPA"}),e.jsx("div",{className:"flex items-end gap-2 mt-2",children:e.jsx("h3",{className:"text-4xl font-display font-black text-slate-800",children:U})})]})]}),e.jsxs("div",{className:"bg-white rounded-[2rem] border border-slate-100 p-6 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-8 -top-8 w-32 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-14 h-14 bg-emerald-100 text-emerald-600 rounded-2xl flex items-center justify-center mb-6 shadow-sm",children:e.jsx(R,{className:"w-7 h-7"})}),e.jsx("p",{className:"text-slate-400 font-bold text-sm tracking-wide uppercase",children:"Average Score"}),e.jsx("div",{className:"flex items-end gap-2 mt-2",children:e.jsxs("h3",{className:"text-4xl font-display font-black text-slate-800",children:[b,"%"]})})]})]}),e.jsxs("div",{className:"bg-white rounded-[2rem] border border-slate-100 p-6 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-8 -top-8 w-32 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-14 h-14 bg-violet-100 text-violet-600 rounded-2xl flex items-center justify-center mb-6 shadow-sm",children:e.jsx(D,{className:"w-7 h-7"})}),e.jsx("p",{className:"text-slate-400 font-bold text-sm tracking-wide uppercase",children:"Quizzes Completed"}),e.jsx("div",{className:"flex items-end gap-2 mt-2",children:e.jsx("h3",{className:"text-4xl font-display font-black text-slate-800",children:O})})]})]})]}),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-[2rem] border border-slate-100 shadow-[0_8px_30px_-12px_rgba(0,0,0,0.06)] overflow-hidden flex flex-col h-full",children:[e.jsxs("div",{className:"p-6 sm:p-8 border-b border-slate-50 flex flex-col sm:flex-row justify-between items-start sm:items-center 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-3 w-full sm:w-auto",children:[e.jsxs("div",{className:"relative flex-1 sm:flex-none",children:[e.jsxs("select",{value:n,onChange:t=>N(t.target.value),className:"appearance-none w-full pl-4 pr-10 py-2.5 border-none bg-slate-50 rounded-xl text-sm font-bold text-slate-600 focus:ring-2 focus:ring-indigo-500/30 transition-all cursor-pointer min-w-[140px] shadow-sm",children:[e.jsx("option",{value:"all",children:"All Subjects"}),c.map(t=>e.jsx("option",{value:t,children:t},t))]}),e.jsx(P,{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:x,onChange:t=>z(t.target.value),className:"appearance-none w-full pl-4 pr-10 py-2.5 border-none bg-slate-50 rounded-xl text-sm font-bold text-slate-600 focus:ring-2 focus:ring-indigo-500/30 transition-all cursor-pointer min-w-[120px] shadow-sm",children:[e.jsx("option",{value:"all",children:"All Types"}),e.jsx("option",{value:"module",children:"Module Quiz"}),e.jsx("option",{value:"practice",children:"Practice"})]}),e.jsx(P,{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 flex-1 p-2",children:e.jsxs("table",{className:"w-full text-left border-separate border-spacing-y-2 px-4 sm:px-6 mb-4",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:m.length>0?m.map(t=>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:t.title}),e.jsx("p",{className:"text-[11px] font-bold text-slate-400 mt-1",children:t.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:t.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 ${t.type==="practice"?"bg-emerald-100/50 text-emerald-600":"bg-indigo-100/50 text-indigo-600"}`,children:t.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 ${t.score>=80?"bg-emerald-100 text-emerald-700":t.score>=60?"bg-amber-100 text-amber-700":"bg-rose-100 text-rose-700"}`,children:[t.score,"%"]})})]},t.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(R,{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-[2rem] border border-slate-100 p-6 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:C.map((t,s)=>{const a=k[t.color]||k.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 ${a.dot} group-hover:scale-125 transition-transform`}),t.subject]}),e.jsxs("p",{className:"text-[11px] text-slate-400 font-bold ml-4 mt-0.5",children:[t.quizzes," activities"]})]}),e.jsxs("span",{className:"text-[15px] font-black text-slate-800",children:[t.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 ${a.bar} shadow-sm relative overflow-hidden transition-all duration-1000`,style:{"--w":`${Math.max(t.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]"})})})]},s)})})]}),e.jsxs("div",{className:"relative bg-gradient-to-br from-indigo-600 to-violet-700 rounded-[2rem] p-6 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(D,{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:$.length})," activities recently. Try a practice session to boost your lowest scores."]}),e.jsx(v,{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"})]})]})]})]})]})};export{ge as default}; diff --git a/assets/HeroBanner-CKiXGluA.js b/assets/HeroBanner-DQ9n4La7.js similarity index 94% rename from assets/HeroBanner-CKiXGluA.js rename to assets/HeroBanner-DQ9n4La7.js index 6db03c737326a0ae9b030683451288d4d5ccfca1..6a8fa4d7a44c4021563bd0c82d56d4c8ea324d2d 100644 --- a/assets/HeroBanner-CKiXGluA.js +++ b/assets/HeroBanner-DQ9n4La7.js @@ -1,5 +1,5 @@ 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{e as y,T as v,f as w,Q as k,j as M,m as p,A as P,B as u,y as A,Z as T,b as _,_ as E}from"./index-BaOs5Ayg.js";import{j as e,r as o}from"./vendor-react-B4AQeu28.js";import{D as V,a as Q}from"./dialog-CHtYkwVl.js";import{R as $,L as G,C as q,X as Y,Y as W,T as X,b as F}from"./vendor-charts-D8hf8tI0.js";import{collection as S,query as C,limit as L,orderBy as R,getDocs as D}from"./vendor-firebase-firestore-CH1lNiRF.js";import{X as K}from"./x-TNvtuOD9.js";import{C as z}from"./circle-alert-CP9K3300.js";import{C as U}from"./circle-check-C0FPGTrp.js";import{S as Z}from"./sparkles-By-vFjpv.js";import"./vendor-firebase-core-CO26nNq6.js";import"./vendor-firebase-auth-BLpRW_zO.js";import"./vendor-firebase-storage-B3igpVVS.js";import"./vendor-firebase-analytics-CTiUNb0-.js";import"./vendor-radix-BorKzPz9.js";import"./vendor-markdown-yqZQ_iQm.js";/** +import{e as y,T as v,h as w,W as k,g as M,m as p,A as P,B as u,q as A,Z as T,b as _,_ as E}from"./index-uASBzalf.js";import{j as e,r as o}from"./vendor-react-B4AQeu28.js";import{D as V,a as $}from"./dialog-CNHSYTtM.js";import{R as Q,L as q,C as G,X as W,Y,T as X,d as F}from"./vendor-charts-Ckgeb0nY.js";import{collection as S,query as C,limit as L,orderBy as R,getDocs as D}from"./vendor-firebase-firestore-CP9q7ISf.js";import{X as K}from"./x-CBb03rh3.js";import{C as z}from"./circle-alert-DDOZHhZK.js";import{C as U}from"./circle-check-C5Psopk3.js";import{S as Z}from"./sparkles-DHVr5IP1.js";import"./vendor-firebase-core-DCQrgkxC.js";import"./vendor-firebase-auth-Bcpr4O6E.js";import"./vendor-firebase-storage-dc5X5yTv.js";import"./vendor-firebase-analytics-CHPyhRzk.js";import"./vendor-radix-xDOIcVzp.js";import"./vendor-markdown-yqZQ_iQm.js";/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. @@ -9,5 +9,5 @@ import{e as y,T as v,f as w,Q as k,j as M,m as p,A as P,B as u,y as A,Z as T,b a * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. - */const I=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M12 8v4",key:"1got3b"}],["path",{d:"M12 16h.01",key:"1drbdi"}]],ee=y("shield-alert",I),se=({history:s})=>{if(s.length===0)return e.jsxs("div",{className:"text-center py-12 text-slate-400",children:[e.jsx(v,{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 t=s.map(a=>({date:new Date(a.completedAt).toLocaleDateString("en-US",{month:"short",day:"numeric"}),score:a.percentage,level:a.proficiencyLevel}));return e.jsx("div",{className:"w-full",children:e.jsx($,{width:"100%",height:250,children:e.jsxs(G,{data:t,margin:{top:10,right:20,left:0,bottom:5},children:[e.jsx(q,{strokeDasharray:"3 3",stroke:"#e2e8f0"}),e.jsx(Y,{dataKey:"date",tick:{fontSize:12,fill:"#64748b"}}),e.jsx(W,{domain:[0,100],tick:{fontSize:12,fill:"#64748b"}}),e.jsx(X,{contentStyle:{borderRadius:"12px",border:"1px solid #e2e8f0",boxShadow:"0 4px 12px rgba(0,0,0,0.08)"}}),e.jsx(F,{type:"monotone",dataKey:"score",stroke:"#0ea5e9",strokeWidth:3,dot:{fill:"#0ea5e9",strokeWidth:2,r:5},activeDot:{r:7,fill:"#0284c7"}})]})})})};async function te(s){const t=S(w,"assessmentResults",s,"attempts"),a=C(t,R("completedAt","desc"),L(10));return(await D(a)).docs.map(n=>{const r=n.data();return{attemptId:r.attemptId,score:r.score,totalQuestions:r.totalQuestions,percentage:r.percentage,completedAt:r.completedAt?.toDate?.()?.toISOString()||r.completedAt,proficiencyLevel:r.proficiencyLevel}})}async function ae(s){const t=S(w,"assessmentResults",s,"attempts"),a=C(t,R("completedAt","desc"),L(1)),i=await D(a);if(i.empty)return null;const r=i.docs[0].data();return{...r,completedAt:r.completedAt?.toDate?.()?.toISOString()||r.completedAt}}const re={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"},le=({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 ${re[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(u,{className:"w-4 h-4 text-sky-500"}),"Competency Breakdown"]}),e.jsx("div",{className:"space-y-2",children:s.competencyBreakdown.map((t,a)=>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:t.topic}),e.jsxs("p",{className:"text-xs text-slate-500",children:[t.correctAnswers,"/",t.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 ${t.accuracyPercent>=70?"bg-emerald-500":"bg-red-400"}`,style:{width:`${t.accuracyPercent}%`}})}),e.jsxs("span",{className:"text-sm font-semibold text-slate-600 w-10 text-right",children:[t.accuracyPercent,"%"]})]},a))})]}),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(Z,{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(A,{className:"w-4 h-4 text-sky-500"}),"Question Breakdown"]}),e.jsx("div",{className:"space-y-3",children:s.answers.map((t,a)=>e.jsxs("div",{className:`p-4 rounded-xl border-2 ${t.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",a+1,". ",t.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:t.isCorrect?"text-emerald-600 font-medium":"text-red-500 font-medium",children:t.userAnswer||"—"})]}),!t.isCorrect&&e.jsxs("span",{className:"text-slate-500",children:["Correct: ",e.jsx("span",{className:"text-emerald-600 font-medium",children:t.correctAnswer})]})]}),t.explanation&&e.jsx("p",{className:"text-xs text-slate-500 mt-2 leading-relaxed",children:t.explanation})]},a))})]})]}),oe=({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(ee,{className:"w-4 h-4"}):s.latestRiskLevel==="Needs Attention"?e.jsx(z,{className:"w-4 h-4"}):e.jsx(U,{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(v,{className:"w-4 h-4"}),"Strengths"]}),e.jsx("ul",{className:"space-y-2",children:s.strengths.map((t,a)=>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:t})]},a))})]}),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(A,{className:"w-4 h-4"}),"Focus Areas"]}),e.jsx("ul",{className:"space-y-2",children:s.weaknesses.map((t,a)=>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:t})]},a))})]})]}),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(u,{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})]})]}),ie=({heroBannerSummary:s,latestResult:t,loading:a})=>a?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&&!t?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(u,{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(oe,{summary:s}):t?e.jsx(le,{result:t}):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(z,{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."})]}),ne=({isOpen:s,onClose:t,studentId:a,latestResult:i,heroBannerSummary:n})=>{const[r,d]=o.useState("latest"),[f,c]=o.useState(i||null),[m,j]=o.useState([]),[b,g]=o.useState(!1),[x,N]=o.useState(null);o.useEffect(()=>{if(s&&a&&!n){const l=k(a,h=>{N(h)});return()=>l()}},[s,a,n]);const H=n||x;o.useEffect(()=>{s&&a&&(g(!0),Promise.all([i?Promise.resolve(i):ae(a),te(a)]).then(([l,h])=>{c(l),j(h)}).catch(console.error).finally(()=>g(!1)))},[s,a,i]);const B=[{key:"latest",label:"Last Results",icon:e.jsx(P,{className:"w-4 h-4"})},{key:"history",label:"History & Trends",icon:e.jsx(v,{className:"w-4 h-4"})}];return e.jsx(V,{open:s,onOpenChange:l=>!l&&t(),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:t,className:"p-1.5 rounded-lg hover:bg-slate-100 transition-colors",children:e.jsx(K,{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(l=>e.jsxs("button",{onClick:()=>d(l.key),className:`flex items-center gap-2 px-4 py-2 rounded-md text-sm font-medium transition-all ${r===l.key?"bg-white text-sky-600 shadow-sm":"text-slate-600 hover:text-slate-800"}`,children:[l.icon,l.label]},l.key))})]}),e.jsx("div",{className:"px-6 py-5",children:e.jsxs(M,{mode:"wait",children:[r==="latest"&&e.jsx(p.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},children:e.jsx(ie,{heroBannerSummary:H,latestResult:f,loading:b})},"latest"),r==="history"&&e.jsxs(p.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},children:[e.jsx(se,{history:m}),m.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"}),m.map((l,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 ",m.length-h]}),e.jsx("p",{className:"text-xs text-slate-500",children:new Date(l.completedAt).toLocaleDateString()})]}),e.jsxs("div",{className:"text-right",children:[e.jsxs("p",{className:"text-sm font-semibold text-sky-600",children:[l.percentage,"%"]}),e.jsx("p",{className:"text-xs text-slate-500",children:l.proficiencyLevel})]})]},h))]})]},"history")]})})]})})},de=o.lazy(()=>E(()=>import("./DashboardAvatar-CbAKGmA6.js"),__vite__mapDeps([0,1,2]))),Ae=({userName:s="Student",userLevel:t=1,avatarLayers:a,onContinueLearning:i,showAssessmentTooltip:n,onOpenAssessment:r,studentId:d,assessmentCompleted:f=!1})=>{const[c,m]=o.useState(!1),[j,b]=o.useState(null);o.useEffect(()=>{if(!c||!d)return;const x=k(d,N=>{b(N)});return()=>x()},[c,d]),o.useEffect(()=>{c||b(null)},[c]);const g=()=>{const x=new Date().getHours();return x<12?"Good Morning":x<18?"Good Afternoon":"Good Evening"};return e.jsxs(p.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-[2rem] 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-[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 min-h-[140px] lg:min-h-[160px] items-center justify-between gap-6 pb-0",children:e.jsxs("div",{className:"flex-1 min-w-0 pr-40 lg:pr-[280px] py-1",children:[e.jsxs("div",{className:"flex items-center gap-2 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 ",t]})}),e.jsxs("div",{className:"px-3 md:px-4 py-1.5 rounded-full bg-rose-50 border border-rose-200",children:[e.jsx(T,{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-xl md:text-2xl lg:text-3xl font-display font-black text-[#0a1628] mb-1.5 tracking-tight leading-[1.1]",children:[g(),", ",s,"! ",e.jsx(J,{size:20,className:"inline -mt-1 ml-1"})]}),e.jsx("p",{className:"text-slate-500 mb-1 text-xs md:text-sm font-body font-bold",children:"Today is a great day to move one step forward in math mastery."}),e.jsx("p",{className:"text-[11px] md:text-xs text-slate-400 font-body mb-4",children:"Focus on your next recommended lesson and keep your momentum."}),e.jsxs(p.button,{onClick:i,whileHover:{scale:1.03},whileTap:{scale:.97},className:"mt-2 bg-gradient-to-r from-purple-600 to-[#9956DE] text-white px-5 py-2 rounded-xl font-body font-bold text-sm shadow-lg shadow-purple-500/20 hover:shadow-purple-500/30 transition-all flex items-center gap-2 group",children:["Continue Learning",e.jsx(_,{size:14,className:"group-hover:translate-x-1 transition-transform"})]})]})}),n&&e.jsx(p.div,{initial:{opacity:0,scale:.9,x:10},animate:{opacity:1,scale:1,x:0},transition:{delay:.5,type:"spring"},onClick:r,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(u,{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"})]})}),f&&!n&&e.jsx(p.div,{initial:{opacity:0,scale:.9,x:10},animate:{opacity:1,scale:1,x:0},transition:{delay:.5,type:"spring"},onClick:()=>d&&m(!0),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"})]})}),c&&d&&e.jsx(ne,{isOpen:c,onClose:()=>m(!1),studentId:d,heroBannerSummary:j}),e.jsx("div",{className:"hidden md:block absolute right-0 lg:right-10 bottom-0 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-[21%] lg:translate-y-[19%] drop-shadow-2xl",children:e.jsx(o.Suspense,{fallback:e.jsx("div",{className:"w-full h-full scale-[1.25] lg:scale-[1.3] origin-bottom"}),children:e.jsx(de,{layers:a,className:"w-full h-full scale-[1.25] lg:scale-[1.3] origin-bottom"})})})})]})};export{Ae as default}; + */const I=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M12 8v4",key:"1got3b"}],["path",{d:"M12 16h.01",key:"1drbdi"}]],ee=y("shield-alert",I),se=({history:s})=>{if(s.length===0)return e.jsxs("div",{className:"text-center py-12 text-slate-400",children:[e.jsx(v,{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 t=s.map(a=>({date:new Date(a.completedAt).toLocaleDateString("en-US",{month:"short",day:"numeric"}),score:a.percentage,level:a.proficiencyLevel}));return e.jsx("div",{className:"w-full",children:e.jsx(Q,{width:"100%",height:250,children:e.jsxs(q,{data:t,margin:{top:10,right:20,left:0,bottom:5},children:[e.jsx(G,{strokeDasharray:"3 3",stroke:"#e2e8f0"}),e.jsx(W,{dataKey:"date",tick:{fontSize:12,fill:"#64748b"}}),e.jsx(Y,{domain:[0,100],tick:{fontSize:12,fill:"#64748b"}}),e.jsx(X,{contentStyle:{borderRadius:"12px",border:"1px solid #e2e8f0",boxShadow:"0 4px 12px rgba(0,0,0,0.08)"}}),e.jsx(F,{type:"monotone",dataKey:"score",stroke:"#0ea5e9",strokeWidth:3,dot:{fill:"#0ea5e9",strokeWidth:2,r:5},activeDot:{r:7,fill:"#0284c7"}})]})})})};async function te(s){const t=S(w,"assessmentResults",s,"attempts"),a=C(t,R("completedAt","desc"),L(10));return(await D(a)).docs.map(n=>{const r=n.data();return{attemptId:r.attemptId,score:r.score,totalQuestions:r.totalQuestions,percentage:r.percentage,completedAt:r.completedAt?.toDate?.()?.toISOString()||r.completedAt,proficiencyLevel:r.proficiencyLevel}})}async function ae(s){const t=S(w,"assessmentResults",s,"attempts"),a=C(t,R("completedAt","desc"),L(1)),i=await D(a);if(i.empty)return null;const r=i.docs[0].data();return{...r,completedAt:r.completedAt?.toDate?.()?.toISOString()||r.completedAt}}const re={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"},le=({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 ${re[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(u,{className:"w-4 h-4 text-sky-500"}),"Competency Breakdown"]}),e.jsx("div",{className:"space-y-2",children:s.competencyBreakdown.map((t,a)=>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:t.topic}),e.jsxs("p",{className:"text-xs text-slate-500",children:[t.correctAnswers,"/",t.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 ${t.accuracyPercent>=70?"bg-emerald-500":"bg-red-400"}`,style:{width:`${t.accuracyPercent}%`}})}),e.jsxs("span",{className:"text-sm font-semibold text-slate-600 w-10 text-right",children:[t.accuracyPercent,"%"]})]},a))})]}),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(Z,{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(A,{className:"w-4 h-4 text-sky-500"}),"Question Breakdown"]}),e.jsx("div",{className:"space-y-3",children:s.answers.map((t,a)=>e.jsxs("div",{className:`p-4 rounded-xl border-2 ${t.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",a+1,". ",t.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:t.isCorrect?"text-emerald-600 font-medium":"text-red-500 font-medium",children:t.userAnswer||"—"})]}),!t.isCorrect&&e.jsxs("span",{className:"text-slate-500",children:["Correct: ",e.jsx("span",{className:"text-emerald-600 font-medium",children:t.correctAnswer})]})]}),t.explanation&&e.jsx("p",{className:"text-xs text-slate-500 mt-2 leading-relaxed",children:t.explanation})]},a))})]})]}),oe=({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(ee,{className:"w-4 h-4"}):s.latestRiskLevel==="Needs Attention"?e.jsx(z,{className:"w-4 h-4"}):e.jsx(U,{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(v,{className:"w-4 h-4"}),"Strengths"]}),e.jsx("ul",{className:"space-y-2",children:s.strengths.map((t,a)=>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:t})]},a))})]}),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(A,{className:"w-4 h-4"}),"Focus Areas"]}),e.jsx("ul",{className:"space-y-2",children:s.weaknesses.map((t,a)=>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:t})]},a))})]})]}),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(u,{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})]})]}),ie=({heroBannerSummary:s,latestResult:t,loading:a})=>a?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&&!t?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(u,{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(oe,{summary:s}):t?e.jsx(le,{result:t}):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(z,{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."})]}),ne=({isOpen:s,onClose:t,studentId:a,latestResult:i,heroBannerSummary:n})=>{const[r,d]=o.useState("latest"),[f,c]=o.useState(i||null),[m,j]=o.useState([]),[b,g]=o.useState(!1),[x,N]=o.useState(null);o.useEffect(()=>{if(s&&a&&!n){const l=k(a,h=>{N(h)});return()=>l()}},[s,a,n]);const H=n||x;o.useEffect(()=>{s&&a&&(g(!0),Promise.all([i?Promise.resolve(i):ae(a),te(a)]).then(([l,h])=>{c(l),j(h)}).catch(console.error).finally(()=>g(!1)))},[s,a,i]);const B=[{key:"latest",label:"Last Results",icon:e.jsx(P,{className:"w-4 h-4"})},{key:"history",label:"History & Trends",icon:e.jsx(v,{className:"w-4 h-4"})}];return e.jsx(V,{open:s,onOpenChange:l=>!l&&t(),children:e.jsxs($,{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:t,className:"p-1.5 rounded-lg hover:bg-slate-100 transition-colors",children:e.jsx(K,{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(l=>e.jsxs("button",{onClick:()=>d(l.key),className:`flex items-center gap-2 px-4 py-2 rounded-md text-sm font-medium transition-all ${r===l.key?"bg-white text-sky-600 shadow-sm":"text-slate-600 hover:text-slate-800"}`,children:[l.icon,l.label]},l.key))})]}),e.jsx("div",{className:"px-6 py-5",children:e.jsxs(M,{mode:"wait",children:[r==="latest"&&e.jsx(p.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},children:e.jsx(ie,{heroBannerSummary:H,latestResult:f,loading:b})},"latest"),r==="history"&&e.jsxs(p.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},children:[e.jsx(se,{history:m}),m.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"}),m.map((l,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 ",m.length-h]}),e.jsx("p",{className:"text-xs text-slate-500",children:new Date(l.completedAt).toLocaleDateString()})]}),e.jsxs("div",{className:"text-right",children:[e.jsxs("p",{className:"text-sm font-semibold text-sky-600",children:[l.percentage,"%"]}),e.jsx("p",{className:"text-xs text-slate-500",children:l.proficiencyLevel})]})]},h))]})]},"history")]})})]})})},de=o.lazy(()=>E(()=>import("./DashboardAvatar-CbAKGmA6.js"),__vite__mapDeps([0,1,2]))),Ae=({userName:s="Student",userLevel:t=1,avatarLayers:a,onContinueLearning:i,showAssessmentTooltip:n,onOpenAssessment:r,studentId:d,assessmentCompleted:f=!1})=>{const[c,m]=o.useState(!1),[j,b]=o.useState(null);o.useEffect(()=>{if(!c||!d)return;const x=k(d,N=>{b(N)});return()=>x()},[c,d]),o.useEffect(()=>{c||b(null)},[c]);const g=()=>{const x=new Date().getHours();return x<12?"Good Morning":x<18?"Good Afternoon":"Good Evening"};return e.jsxs(p.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-[2rem] 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-[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 min-h-[140px] lg:min-h-[160px] items-center justify-between gap-6 pb-0",children:e.jsxs("div",{className:"flex-1 min-w-0 pr-40 lg:pr-[280px] py-1",children:[e.jsxs("div",{className:"flex items-center gap-2 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 ",t]})}),e.jsxs("div",{className:"px-3 md:px-4 py-1.5 rounded-full bg-rose-50 border border-rose-200",children:[e.jsx(T,{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-xl md:text-2xl lg:text-3xl font-display font-black text-[#0a1628] mb-1.5 tracking-tight leading-[1.1]",children:[g(),", ",s,"! ",e.jsx(J,{size:20,className:"inline -mt-1 ml-1"})]}),e.jsx("p",{className:"text-slate-500 mb-1 text-xs md:text-sm font-body font-bold",children:"Today is a great day to move one step forward in math mastery."}),e.jsx("p",{className:"text-[11px] md:text-xs text-slate-400 font-body mb-4",children:"Focus on your next recommended lesson and keep your momentum."}),e.jsxs(p.button,{onClick:i,whileHover:{scale:1.03},whileTap:{scale:.97},className:"mt-2 bg-gradient-to-r from-purple-600 to-[#9956DE] text-white px-5 py-2 rounded-xl font-body font-bold text-sm shadow-lg shadow-purple-500/20 hover:shadow-purple-500/30 transition-all flex items-center gap-2 group",children:["Continue Learning",e.jsx(_,{size:14,className:"group-hover:translate-x-1 transition-transform"})]})]})}),n&&e.jsx(p.div,{initial:{opacity:0,scale:.9,x:10},animate:{opacity:1,scale:1,x:0},transition:{delay:.5,type:"spring"},onClick:r,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(u,{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"})]})}),f&&!n&&e.jsx(p.div,{initial:{opacity:0,scale:.9,x:10},animate:{opacity:1,scale:1,x:0},transition:{delay:.5,type:"spring"},onClick:()=>d&&m(!0),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"})]})}),c&&d&&e.jsx(ne,{isOpen:c,onClose:()=>m(!1),studentId:d,heroBannerSummary:j}),e.jsx("div",{className:"hidden md:block absolute right-0 lg:right-10 bottom-0 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-[21%] lg:translate-y-[19%] drop-shadow-2xl",children:e.jsx(o.Suspense,{fallback:e.jsx("div",{className:"w-full h-full scale-[1.25] lg:scale-[1.3] origin-bottom"}),children:e.jsx(de,{layers:a,className:"w-full h-full scale-[1.25] lg:scale-[1.3] origin-bottom"})})})})]})};export{Ae as default}; diff --git a/assets/InitialAssessmentModal-CknVaqMx.js b/assets/InitialAssessmentModal-D5CEKMhd.js similarity index 89% rename from assets/InitialAssessmentModal-CknVaqMx.js rename to assets/InitialAssessmentModal-D5CEKMhd.js index 8ea2b6e5a6229ab48d6f8ded67a543fe4513c01e..8ce673e45fa7765759f7fc1e5fc1d8b09226f593 100644 --- a/assets/InitialAssessmentModal-CknVaqMx.js +++ b/assets/InitialAssessmentModal-D5CEKMhd.js @@ -1 +1 @@ -import{r as l,j as e}from"./vendor-react-B4AQeu28.js";import{B as j}from"./button-DCfeFHoH.js";import{g as y}from"./diagnosticService-BDYTUoqk.js";import{updateDoc as N,doc as v,serverTimestamp as w}from"./vendor-firebase-firestore-CH1lNiRF.js";import{m as o,B as k,p as C,l as L,f as z}from"./index-BaOs5Ayg.js";import{X as S}from"./x-TNvtuOD9.js";import{C as A}from"./circle-check-big-m1SvzGFL.js";import"./vendor-radix-BorKzPz9.js";import"./vendor-charts-D8hf8tI0.js";import"./vendor-firebase-core-CO26nNq6.js";import"./vendor-firebase-auth-BLpRW_zO.js";import"./vendor-firebase-storage-B3igpVVS.js";import"./vendor-firebase-analytics-CTiUNb0-.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-[36rem] 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-[19rem] 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-[22rem] 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-[320px] 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-[18rem] 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-BPmLcOpC.js";import{g as y}from"./diagnosticService-DacNtsbN.js";import{updateDoc as N,doc as v,serverTimestamp as w}from"./vendor-firebase-firestore-CP9q7ISf.js";import{m as o,B as k,w as C,p as L,h as z}from"./index-uASBzalf.js";import{X as S}from"./x-CBb03rh3.js";import{C as A}from"./circle-check-big-BNRlH5pv.js";import"./vendor-radix-xDOIcVzp.js";import"./vendor-charts-Ckgeb0nY.js";import"./vendor-firebase-core-DCQrgkxC.js";import"./vendor-firebase-auth-Bcpr4O6E.js";import"./vendor-firebase-storage-dc5X5yTv.js";import"./vendor-firebase-analytics-CHPyhRzk.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-[36rem] 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-[19rem] 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-[22rem] 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-[320px] 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-[18rem] 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-D9eaC9ey.js b/assets/LeaderboardPage-IhqEnbdk.js similarity index 93% rename from assets/LeaderboardPage-D9eaC9ey.js rename to assets/LeaderboardPage-IhqEnbdk.js index b206d6f79e76945931f40c7fb831093987f92676..23d4cf6db5bac518f900949a103e1d1896d2f257 100644 --- a/assets/LeaderboardPage-D9eaC9ey.js +++ b/assets/LeaderboardPage-IhqEnbdk.js @@ -1,8 +1,8 @@ -import{r as l,j as e}from"./vendor-react-B4AQeu28.js";import{e as Y,aC as W,j as H,m as c,a as y,y as P,A as k,x as m,T as E,l as z,W as X,X as U,O as q,u as $,aD as G,R as K,L as Q,r as T}from"./index-BaOs5Ayg.js";import{X as V}from"./x-TNvtuOD9.js";import{C as Z}from"./clock-D1Ecvltm.js";import{u as J}from"./useFeatureAccess-BSpfx3vY.js";import"./vendor-firebase-firestore-CH1lNiRF.js";import"./vendor-firebase-core-CO26nNq6.js";import"./vendor-firebase-auth-BLpRW_zO.js";import"./vendor-firebase-storage-B3igpVVS.js";import"./vendor-firebase-analytics-CTiUNb0-.js";import"./vendor-radix-BorKzPz9.js";import"./vendor-charts-D8hf8tI0.js";import"./vendor-markdown-yqZQ_iQm.js";/** +import{r as l,j as e}from"./vendor-react-B4AQeu28.js";import{e as O,aD as q,g as H,m as c,a as y,q as P,A as k,z as m,T as E,p as z,Y as X,$ as U,Q as W,l as $,aE as Q,R as G,L as K,y as T}from"./index-uASBzalf.js";import{X as V}from"./x-CBb03rh3.js";import{C as Z}from"./clock-8t0UYgg3.js";import{u as J}from"./useFeatureAccess-C_Ctl5Sh.js";import"./vendor-firebase-firestore-CP9q7ISf.js";import"./vendor-firebase-core-DCQrgkxC.js";import"./vendor-firebase-auth-Bcpr4O6E.js";import"./vendor-firebase-storage-dc5X5yTv.js";import"./vendor-firebase-analytics-CHPyhRzk.js";import"./vendor-radix-xDOIcVzp.js";import"./vendor-charts-Ckgeb0nY.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 ee=[["path",{d:"M3.85 8.62a4 4 0 0 1 4.78-4.77 4 4 0 0 1 6.74 0 4 4 0 0 1 4.78 4.78 4 4 0 0 1 0 6.74 4 4 0 0 1-4.77 4.78 4 4 0 0 1-6.75 0 4 4 0 0 1-4.78-4.77 4 4 0 0 1 0-6.76Z",key:"3c2336"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]],se=Y("badge-check",ee),te=({student:t,onClose:b})=>{const[i,u]=l.useState([]),[p,h]=l.useState(!1);if(l.useEffect(()=>{t?.uid&&(h(!0),W(t.uid).then(u).catch(d=>console.error("Failed to load achievements:",d)).finally(()=>h(!1)))},[t?.uid]),!t)return null;const j={trophy:e.jsx(m,{size:24,className:"text-rose-500"}),flame:e.jsx(q,{size:24,className:"text-orange-500"}),star:e.jsx(U,{size:24,className:"text-rose-400"}),"book-open":e.jsx(y,{size:24,className:"text-sky-600"}),"badge-check":e.jsx(se,{size:24,className:"text-emerald-600"}),crown:e.jsx(X,{size:24,className:"text-rose-500"}),target:e.jsx(P,{size:24,className:"text-rose-500"})};return e.jsx(H,{children:e.jsxs("div",{className:"fixed inset-0 z-[100] flex items-center justify-center p-4",children:[e.jsx(c.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},onClick:b,className:"absolute inset-0 bg-black/50 backdrop-blur-sm"}),e.jsxs(c.div,{initial:{opacity:0,scale:.95,y:20},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:20},className:"relative bg-[#f7f9fc] rounded-2xl shadow-2xl border border-[#dde3eb] w-full max-w-2xl max-h-[90vh] overflow-hidden",children:[e.jsxs("div",{className:"bg-gradient-to-r from-sky-600 to-sky-500 p-8 text-white relative overflow-hidden",children:[e.jsx("div",{className:"accent-line absolute top-0 left-0 right-0"}),e.jsx("button",{onClick:b,className:"absolute top-4 right-4 p-2 hover:bg-slate-100 rounded-xl transition-colors z-10",children:e.jsx(V,{size:20})}),e.jsx("div",{className:"relative z-10",children:e.jsxs("div",{className:"flex items-start gap-6",children:[e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"w-24 h-24 bg-white/10 backdrop-blur-sm rounded-2xl flex items-center justify-center text-6xl border border-slate-300",children:t.avatar}),t.isOnline&&e.jsx("div",{className:"absolute -bottom-2 -right-2 w-6 h-6 bg-green-500 rounded-full border-4 border-white"})]}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h2",{className:"text-3xl font-display font-bold mb-2",children:t.name}),e.jsx("p",{className:"text-slate-500 mb-4",children:t.section}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"bg-slate-100 backdrop-blur-sm rounded-xl px-4 py-2 border border-slate-200",children:[e.jsx("p",{className:"text-xs text-slate-500",children:"Level"}),e.jsx("p",{className:"text-xl font-bold",children:t.level})]}),e.jsxs("div",{className:"bg-slate-100 backdrop-blur-sm rounded-xl px-4 py-2 border border-slate-200",children:[e.jsx("p",{className:"text-xs text-slate-500",children:"Total XP"}),e.jsx("p",{className:"text-xl font-bold",children:t.totalXP})]})]})]})]})}),e.jsx("div",{className:"absolute top-0 right-0 w-64 h-64 bg-sky-500/5 rounded-full -translate-y-1/2 translate-x-1/2"}),e.jsx("div",{className:"absolute bottom-0 left-0 w-48 h-48 bg-rose-500/5 rounded-full translate-y-1/2 -translate-x-1/2"})]}),e.jsxs("div",{className:"p-6 overflow-y-auto max-h-[calc(90vh-320px)]",children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h3",{className:"font-display font-bold text-lg text-[#0a1628] mb-4",children:"Performance Stats"}),e.jsxs("div",{className:"grid grid-cols-4 gap-4",children:[e.jsxs("div",{className:"bg-white rounded-xl border border-[#dde3eb] p-4 text-center",children:[e.jsx(y,{size:24,className:"text-sky-600 mx-auto mb-2"}),e.jsx("p",{className:"text-2xl font-bold text-[#0a1628]",children:t.stats.quizzesCompleted}),e.jsx("p",{className:"text-xs text-slate-500 mt-1 font-body",children:"Quizzes"})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-[#dde3eb] p-4 text-center",children:[e.jsx(P,{size:24,className:"text-emerald-600 mx-auto mb-2"}),e.jsxs("p",{className:"text-2xl font-bold text-[#0a1628]",children:[t.stats.averageScore,"%"]}),e.jsx("p",{className:"text-xs text-slate-500 mt-1 font-body",children:"Avg Score"})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-[#dde3eb] p-4 text-center",children:[e.jsx(k,{size:24,className:"text-rose-600 mx-auto mb-2"}),e.jsx("p",{className:"text-2xl font-bold text-[#0a1628]",children:t.stats.modulesCompleted}),e.jsx("p",{className:"text-xs text-slate-500 mt-1 font-body",children:"Modules"})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-[#dde3eb] p-4 text-center",children:[e.jsx(Z,{size:24,className:"text-rose-600 mx-auto mb-2"}),e.jsx("p",{className:"text-2xl font-bold text-[#0a1628]",children:t.stats.studyHours}),e.jsx("p",{className:"text-xs text-slate-500 mt-1 font-body",children:"Hours"})]})]})]}),e.jsxs("div",{className:"mb-6",children:[e.jsx("h3",{className:"font-display font-bold text-lg text-[#0a1628] mb-4",children:"Rankings"}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsxs("div",{className:"bg-rose-50 border border-rose-200 rounded-xl p-4",children:[e.jsx(m,{size:20,className:"text-rose-600 mb-2"}),e.jsxs("p",{className:"text-2xl font-bold text-rose-900",children:["#",t.rank.global]}),e.jsx("p",{className:"text-xs text-rose-700 mt-1 font-body",children:"School"})]}),e.jsxs("div",{className:"bg-sky-50 border border-sky-200 rounded-xl p-4",children:[e.jsx(m,{size:20,className:"text-sky-600 mb-2"}),e.jsxs("p",{className:"text-2xl font-bold text-sky-900",children:["#",t.rank.section]}),e.jsx("p",{className:"text-xs text-sky-700 mt-1 font-body",children:"Section"})]}),e.jsxs("div",{className:"bg-rose-50 border border-rose-200 rounded-xl p-4",children:[e.jsx(m,{size:20,className:"text-rose-600 mb-2"}),e.jsx("p",{className:"text-2xl font-bold text-rose-900",children:t.rank.change>0?e.jsxs("span",{className:"flex items-center gap-1 text-emerald-600",children:[e.jsx(E,{size:20}),"+",t.rank.change]}):t.rank.change<0?e.jsxs("span",{className:"flex items-center gap-1 text-red-600",children:[e.jsx(E,{size:20,className:"rotate-180"}),t.rank.change]}):"0"}),e.jsx("p",{className:"text-xs text-rose-700 mt-1 font-body",children:"This Week"})]})]})]}),e.jsxs("div",{className:"mb-6",children:[e.jsx("h3",{className:"font-display font-bold text-lg text-[#0a1628] mb-4",children:"Achievements"}),p?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(z,{size:24,className:"text-sky-500 animate-spin"})}):i.length>0?e.jsx("div",{className:"grid grid-cols-3 gap-3",children:i.map(d=>e.jsxs("div",{className:"rounded-xl p-4 text-center transition-all bg-white border-2 border-sky-200",children:[e.jsx("div",{className:"text-3xl mb-2",children:j[d.icon]||e.jsx(k,{size:24,className:"text-slate-500 mx-auto"})}),e.jsx("p",{className:"font-bold text-xs text-[#0a1628] mb-1 font-body",children:d.title}),e.jsx("p",{className:"text-xs text-[#5a6578]",children:d.description})]},d.id))}):e.jsxs("div",{className:"flex flex-col items-center py-8 gap-2",children:[e.jsx(k,{size:32,className:"text-[#d1cec6]"}),e.jsx("p",{className:"text-sm text-[#5a6578] font-body",children:"No achievements unlocked yet"})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-display font-bold text-lg text-[#0a1628] mb-4",children:"Recent Activity"}),e.jsxs("div",{className:"flex flex-col items-center py-8 gap-2",children:[e.jsx(y,{size:32,className:"text-[#d1cec6]"}),e.jsx("p",{className:"text-sm text-[#5a6578] font-body",children:"Activity history coming soon"})]})]})]})]})]})})},ue=({currentUserPhoto:t,onBack:b})=>{const{currentUser:i,userProfile:u}=$(),p=u,{leaderboard:h,loading:j}=J(i?.uid||null),[d]=l.useState("section"),[g,M]=l.useState("weekly"),[I,_]=l.useState(null),[D,v]=l.useState(!0),[F,C]=l.useState(null),[R,S]=l.useState([]),N=[p?.grade,p?.section].filter(Boolean).join(" - "),w=l.useCallback(async()=>{if(!i){v(!1);return}v(!0),C(null);try{const s=g==="all"?"all":"week",r=await G(i.uid,!1,s,20);if(!r||r.length===0){S([]);return}const n=r.map(a=>({id:a.userId,uid:a.userId,name:a.name,avatar:a.userId===i.uid?t||a.photo||"":a.photo||"",level:a.level,totalXP:a.xp,section:N||"Grade 11 - STEM A",rank:{global:a.rank,section:a.rank,change:0},stats:{quizzesCompleted:0,averageScore:0,modulesCompleted:0,studyHours:0},isOnline:!1,isYou:a.userId===i.uid}));S(n)}catch(s){console.error("Error loading leaderboard:",s),C(s instanceof Error?s.message:"Failed to load leaderboard")}finally{v(!1)}},[i,N,g,t]);l.useEffect(()=>{w()},[w]);const x=(()=>{let s=R;if(d==="section"){const n=N||"";n&&(s=s.filter(a=>a.section===n))}return s.sort((n,a)=>{const B=d==="section"?"section":"global";return(n.rank[B]||999)-(a.rank[B]||999)})})(),A=x.find(s=>s.isYou)?.rank.section||x.length+1,O=x.length>1?Math.max(10,Math.min(99,100-A/Math.max(1,x.length)*100)):90,o=x.slice(0,3),L=x.slice(3),f=(s,r)=>s?s.startsWith("http")||s.startsWith("data:")?e.jsx("img",{src:s,alt:"Avatar",className:"w-full h-full object-cover rounded-full"}):e.jsx(T,{size:r,className:"text-slate-400 opacity-70"}):e.jsx(T,{size:r,className:"text-slate-400 opacity-70"});return D?e.jsxs("div",{className:"flex flex-col justify-center items-center h-[500px] gap-3",children:[e.jsx(z,{className:"w-8 h-8 animate-spin text-purple-600"}),e.jsx("p",{className:"text-sm text-slate-400 font-medium",children:"Loading leaderboard..."})]}):F?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-red-50 flex items-center justify-center",children:e.jsx(m,{className:"w-7 h-7 text-red-400"})}),e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-sm font-semibold text-slate-700 mb-1",children:"Couldn't load leaderboard"}),e.jsx("p",{className:"text-xs text-slate-400",children:F})]}),e.jsxs("button",{onClick:w,className:"flex items-center gap-2 px-4 py-2 bg-purple-600 text-white text-sm font-medium rounded-xl hover:bg-purple-700 transition-colors",children:[e.jsx(K,{size:14}),"Try Again"]})]}):j?e.jsxs("div",{className:"flex flex-col justify-center items-center h-[500px] gap-3",children:[e.jsx(z,{className:"w-8 h-8 animate-spin text-purple-600"}),e.jsx("p",{className:"text-sm text-slate-400 font-medium",children:"Loading..."})]}):h?e.jsxs("div",{className:"w-full min-h-screen relative flex flex-col items-center font-body text-white",children:[e.jsxs("div",{className:"absolute inset-x-[-30px] top-[-30px] bottom-0 z-[-1] pointer-events-none overflow-hidden bg-[#f5ecff]",children:[e.jsx("div",{className:"absolute inset-0 bg-[radial-gradient(ellipse_at_50%_100%,#9333ea_0%,#c084fc_50%,transparent_100%)]"}),e.jsx("div",{className:"absolute inset-x-[-30px] top-[-30px] bottom-0 opacity-50 pointer-events-none mix-blend-plus-lighter overflow-hidden",children:e.jsx("div",{className:"animate-sunburst-spin absolute top-[540px] md:top-[600px] left-1/2",style:{width:"2000px",height:"2000px",marginLeft:"-1000px",marginTop:"-1000px",willChange:"transform",background:`repeating-conic-gradient(from 0deg at 50% 50%, + */const ee=[["path",{d:"M3.85 8.62a4 4 0 0 1 4.78-4.77 4 4 0 0 1 6.74 0 4 4 0 0 1 4.78 4.78 4 4 0 0 1 0 6.74 4 4 0 0 1-4.77 4.78 4 4 0 0 1-6.75 0 4 4 0 0 1-4.78-4.77 4 4 0 0 1 0-6.76Z",key:"3c2336"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]],se=O("badge-check",ee),te=({student:t,onClose:b})=>{const[i,u]=l.useState([]),[p,h]=l.useState(!1);if(l.useEffect(()=>{t?.uid&&(h(!0),q(t.uid).then(u).catch(d=>console.error("Failed to load achievements:",d)).finally(()=>h(!1)))},[t?.uid]),!t)return null;const j={trophy:e.jsx(m,{size:24,className:"text-rose-500"}),flame:e.jsx(W,{size:24,className:"text-orange-500"}),star:e.jsx(U,{size:24,className:"text-rose-400"}),"book-open":e.jsx(y,{size:24,className:"text-sky-600"}),"badge-check":e.jsx(se,{size:24,className:"text-emerald-600"}),crown:e.jsx(X,{size:24,className:"text-rose-500"}),target:e.jsx(P,{size:24,className:"text-rose-500"})};return e.jsx(H,{children:e.jsxs("div",{className:"fixed inset-0 z-[100] flex items-center justify-center p-4",children:[e.jsx(c.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},onClick:b,className:"absolute inset-0 bg-black/50 backdrop-blur-sm"}),e.jsxs(c.div,{initial:{opacity:0,scale:.95,y:20},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:20},className:"relative bg-[#f7f9fc] rounded-2xl shadow-2xl border border-[#dde3eb] w-full max-w-2xl max-h-[90vh] overflow-hidden",children:[e.jsxs("div",{className:"bg-gradient-to-r from-sky-600 to-sky-500 p-8 text-white relative overflow-hidden",children:[e.jsx("div",{className:"accent-line absolute top-0 left-0 right-0"}),e.jsx("button",{onClick:b,className:"absolute top-4 right-4 p-2 hover:bg-slate-100 rounded-xl transition-colors z-10",children:e.jsx(V,{size:20})}),e.jsx("div",{className:"relative z-10",children:e.jsxs("div",{className:"flex items-start gap-6",children:[e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"w-24 h-24 bg-white/10 backdrop-blur-sm rounded-2xl flex items-center justify-center text-6xl border border-slate-300",children:t.avatar}),t.isOnline&&e.jsx("div",{className:"absolute -bottom-2 -right-2 w-6 h-6 bg-green-500 rounded-full border-4 border-white"})]}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h2",{className:"text-3xl font-display font-bold mb-2",children:t.name}),e.jsx("p",{className:"text-slate-500 mb-4",children:t.section}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"bg-slate-100 backdrop-blur-sm rounded-xl px-4 py-2 border border-slate-200",children:[e.jsx("p",{className:"text-xs text-slate-500",children:"Level"}),e.jsx("p",{className:"text-xl font-bold",children:t.level})]}),e.jsxs("div",{className:"bg-slate-100 backdrop-blur-sm rounded-xl px-4 py-2 border border-slate-200",children:[e.jsx("p",{className:"text-xs text-slate-500",children:"Total XP"}),e.jsx("p",{className:"text-xl font-bold",children:t.totalXP})]})]})]})]})}),e.jsx("div",{className:"absolute top-0 right-0 w-64 h-64 bg-sky-500/5 rounded-full -translate-y-1/2 translate-x-1/2"}),e.jsx("div",{className:"absolute bottom-0 left-0 w-48 h-48 bg-rose-500/5 rounded-full translate-y-1/2 -translate-x-1/2"})]}),e.jsxs("div",{className:"p-6 overflow-y-auto max-h-[calc(90vh-320px)]",children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h3",{className:"font-display font-bold text-lg text-[#0a1628] mb-4",children:"Performance Stats"}),e.jsxs("div",{className:"grid grid-cols-4 gap-4",children:[e.jsxs("div",{className:"bg-white rounded-xl border border-[#dde3eb] p-4 text-center",children:[e.jsx(y,{size:24,className:"text-sky-600 mx-auto mb-2"}),e.jsx("p",{className:"text-2xl font-bold text-[#0a1628]",children:t.stats.quizzesCompleted}),e.jsx("p",{className:"text-xs text-slate-500 mt-1 font-body",children:"Quizzes"})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-[#dde3eb] p-4 text-center",children:[e.jsx(P,{size:24,className:"text-emerald-600 mx-auto mb-2"}),e.jsxs("p",{className:"text-2xl font-bold text-[#0a1628]",children:[t.stats.averageScore,"%"]}),e.jsx("p",{className:"text-xs text-slate-500 mt-1 font-body",children:"Avg Score"})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-[#dde3eb] p-4 text-center",children:[e.jsx(k,{size:24,className:"text-rose-600 mx-auto mb-2"}),e.jsx("p",{className:"text-2xl font-bold text-[#0a1628]",children:t.stats.modulesCompleted}),e.jsx("p",{className:"text-xs text-slate-500 mt-1 font-body",children:"Modules"})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-[#dde3eb] p-4 text-center",children:[e.jsx(Z,{size:24,className:"text-rose-600 mx-auto mb-2"}),e.jsx("p",{className:"text-2xl font-bold text-[#0a1628]",children:t.stats.studyHours}),e.jsx("p",{className:"text-xs text-slate-500 mt-1 font-body",children:"Hours"})]})]})]}),e.jsxs("div",{className:"mb-6",children:[e.jsx("h3",{className:"font-display font-bold text-lg text-[#0a1628] mb-4",children:"Rankings"}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsxs("div",{className:"bg-rose-50 border border-rose-200 rounded-xl p-4",children:[e.jsx(m,{size:20,className:"text-rose-600 mb-2"}),e.jsxs("p",{className:"text-2xl font-bold text-rose-900",children:["#",t.rank.global]}),e.jsx("p",{className:"text-xs text-rose-700 mt-1 font-body",children:"School"})]}),e.jsxs("div",{className:"bg-sky-50 border border-sky-200 rounded-xl p-4",children:[e.jsx(m,{size:20,className:"text-sky-600 mb-2"}),e.jsxs("p",{className:"text-2xl font-bold text-sky-900",children:["#",t.rank.section]}),e.jsx("p",{className:"text-xs text-sky-700 mt-1 font-body",children:"Section"})]}),e.jsxs("div",{className:"bg-rose-50 border border-rose-200 rounded-xl p-4",children:[e.jsx(m,{size:20,className:"text-rose-600 mb-2"}),e.jsx("p",{className:"text-2xl font-bold text-rose-900",children:t.rank.change>0?e.jsxs("span",{className:"flex items-center gap-1 text-emerald-600",children:[e.jsx(E,{size:20}),"+",t.rank.change]}):t.rank.change<0?e.jsxs("span",{className:"flex items-center gap-1 text-red-600",children:[e.jsx(E,{size:20,className:"rotate-180"}),t.rank.change]}):"0"}),e.jsx("p",{className:"text-xs text-rose-700 mt-1 font-body",children:"This Week"})]})]})]}),e.jsxs("div",{className:"mb-6",children:[e.jsx("h3",{className:"font-display font-bold text-lg text-[#0a1628] mb-4",children:"Achievements"}),p?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(z,{size:24,className:"text-sky-500 animate-spin"})}):i.length>0?e.jsx("div",{className:"grid grid-cols-3 gap-3",children:i.map(d=>e.jsxs("div",{className:"rounded-xl p-4 text-center transition-all bg-white border-2 border-sky-200",children:[e.jsx("div",{className:"text-3xl mb-2",children:j[d.icon]||e.jsx(k,{size:24,className:"text-slate-500 mx-auto"})}),e.jsx("p",{className:"font-bold text-xs text-[#0a1628] mb-1 font-body",children:d.title}),e.jsx("p",{className:"text-xs text-[#5a6578]",children:d.description})]},d.id))}):e.jsxs("div",{className:"flex flex-col items-center py-8 gap-2",children:[e.jsx(k,{size:32,className:"text-[#d1cec6]"}),e.jsx("p",{className:"text-sm text-[#5a6578] font-body",children:"No achievements unlocked yet"})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-display font-bold text-lg text-[#0a1628] mb-4",children:"Recent Activity"}),e.jsxs("div",{className:"flex flex-col items-center py-8 gap-2",children:[e.jsx(y,{size:32,className:"text-[#d1cec6]"}),e.jsx("p",{className:"text-sm text-[#5a6578] font-body",children:"Activity history coming soon"})]})]})]})]})]})})},ue=({currentUserPhoto:t,onBack:b})=>{const{currentUser:i,userProfile:u}=$(),p=u,{leaderboard:h,loading:j}=J(i?.uid||null),[d]=l.useState("section"),[g,M]=l.useState("weekly"),[I,_]=l.useState(null),[D,v]=l.useState(!0),[F,S]=l.useState(null),[R,C]=l.useState([]),N=[p?.grade,p?.section].filter(Boolean).join(" - "),w=l.useCallback(async()=>{if(!i){v(!1);return}v(!0),S(null);try{const s=g==="all"?"all":"week",r=await Q(i.uid,!1,s,20);if(!r||r.length===0){C([]);return}const n=r.map(a=>({id:a.userId,uid:a.userId,name:a.name,avatar:a.userId===i.uid?t||a.photo||"":a.photo||"",level:a.level,totalXP:a.xp,section:N||"Grade 11 - STEM A",rank:{global:a.rank,section:a.rank,change:0},stats:{quizzesCompleted:0,averageScore:0,modulesCompleted:0,studyHours:0},isOnline:!1,isYou:a.userId===i.uid}));C(n)}catch(s){console.error("Error loading leaderboard:",s),S(s instanceof Error?s.message:"Failed to load leaderboard")}finally{v(!1)}},[i,N,g,t]);l.useEffect(()=>{w()},[w]);const x=(()=>{let s=R;if(d==="section"){const n=N||"";n&&(s=s.filter(a=>a.section===n))}return s.sort((n,a)=>{const B=d==="section"?"section":"global";return(n.rank[B]||999)-(a.rank[B]||999)})})(),A=x.find(s=>s.isYou)?.rank.section||x.length+1,Y=x.length>1?Math.max(10,Math.min(99,100-A/Math.max(1,x.length)*100)):90,o=x.slice(0,3),L=x.slice(3),f=(s,r)=>s?s.startsWith("http")||s.startsWith("data:")?e.jsx("img",{src:s,alt:"Avatar",className:"w-full h-full object-cover rounded-full"}):e.jsx(T,{size:r,className:"text-slate-400 opacity-70"}):e.jsx(T,{size:r,className:"text-slate-400 opacity-70"});return D?e.jsxs("div",{className:"flex flex-col justify-center items-center h-[500px] gap-3",children:[e.jsx(z,{className:"w-8 h-8 animate-spin text-purple-600"}),e.jsx("p",{className:"text-sm text-slate-400 font-medium",children:"Loading leaderboard..."})]}):F?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-red-50 flex items-center justify-center",children:e.jsx(m,{className:"w-7 h-7 text-red-400"})}),e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-sm font-semibold text-slate-700 mb-1",children:"Couldn't load leaderboard"}),e.jsx("p",{className:"text-xs text-slate-400",children:F})]}),e.jsxs("button",{onClick:w,className:"flex items-center gap-2 px-4 py-2 bg-purple-600 text-white text-sm font-medium rounded-xl hover:bg-purple-700 transition-colors",children:[e.jsx(G,{size:14}),"Try Again"]})]}):j?e.jsxs("div",{className:"flex flex-col justify-center items-center h-[500px] gap-3",children:[e.jsx(z,{className:"w-8 h-8 animate-spin text-purple-600"}),e.jsx("p",{className:"text-sm text-slate-400 font-medium",children:"Loading..."})]}):h?e.jsxs("div",{className:"w-full min-h-screen relative flex flex-col items-center font-body text-white",children:[e.jsxs("div",{className:"absolute inset-x-[-30px] top-[-30px] bottom-0 z-[-1] pointer-events-none overflow-hidden bg-[#f5ecff]",children:[e.jsx("div",{className:"absolute inset-0 bg-[radial-gradient(ellipse_at_50%_100%,#9333ea_0%,#c084fc_50%,transparent_100%)]"}),e.jsx("div",{className:"absolute inset-x-[-30px] top-[-30px] bottom-0 opacity-50 pointer-events-none mix-blend-plus-lighter overflow-hidden",children:e.jsx("div",{className:"animate-sunburst-spin absolute top-[540px] md:top-[600px] left-1/2",style:{width:"2000px",height:"2000px",marginLeft:"-1000px",marginTop:"-1000px",willChange:"transform",background:`repeating-conic-gradient(from 0deg at 50% 50%, rgba(255, 250, 193, 1) 0deg, rgba(255, 250, 193, 0.7) 4deg, - transparent 4deg, transparent 8deg)`}})}),e.jsx("div",{className:"absolute bottom-0 left-1/2 -translate-x-1/2 w-[150vw] h-[100vh] bg-[radial-gradient(ellipse_at_50%_100%,#7e22ce_10%,transparent_60%)] mix-blend-overlay"})]}),e.jsx("div",{className:"absolute inset-0 bg-math-pattern opacity-[0.03] mix-blend-overlay pointer-events-none z-[-1] leaderboard-mask"}),e.jsxs("div",{className:"relative z-10 w-full px-4 sm:px-8 py-4 md:py-6 flex flex-col items-center",children:[e.jsx("div",{className:"w-full flex justify-center items-center mb-4 mt-2",children:e.jsx("h1",{className:"text-3xl md:text-4xl font-display font-bold tracking-wide text-slate-800 drop-shadow-sm",children:"Leaderboard"})}),e.jsx("div",{className:"bg-slate-800/5 backdrop-blur-md rounded-full p-1 flex gap-1 mb-3 shadow-[inset_0_2px_4px_rgba(0,0,0,0.05)] border border-slate-800/10 w-full max-w-[340px]",children:["daily","weekly","all"].map(s=>e.jsx("button",{onClick:()=>M(s),className:`flex-1 py-1.5 rounded-full text-[13px] md:text-sm font-semibold transition-all capitalize inline-flex justify-center items-center ${g===s?"bg-white text-purple-700 shadow-md border border-white/50 backdrop-blur-lg":"text-slate-600 hover:text-purple-700 hover:bg-white/50"}`,children:s==="all"?"All Time":s},s))}),e.jsxs(c.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},className:"w-full max-w-[420px] mb-4 bg-[#FFB356] p-2.5 md:p-3 rounded-full shadow-lg flex items-center gap-3 relative overflow-hidden ring-1 ring-white/20",children:[e.jsx("div",{className:"absolute inset-0 bg-noise opacity-[0.15] mix-blend-overlay pointer-events-none"}),e.jsx("div",{className:"bg-white/25 backdrop-blur-md px-4 py-2 min-w-[60px] rounded-full flex flex-col items-center justify-center shadow-sm z-10 border border-white/20",children:e.jsxs("span",{className:"text-xl md:text-2xl font-display font-bold text-white leading-none",children:["#",A]})}),e.jsx("div",{className:"z-10 flex-1 pr-2 md:pr-4",children:e.jsxs("p",{className:"font-medium text-white/90 text-sm md:text-[15px] leading-snug text-center",children:["You are doing better than ",e.jsxs("span",{className:"font-black text-white drop-shadow-sm",children:[Math.round(O),"%"]})," of other players!"]})})]}),e.jsxs("div",{className:"w-full max-w-[800px] flex items-end justify-center gap-2 md:gap-4 h-[280px] md:h-[310px] relative z-20 mt-8 md:mt-12 mx-auto px-2 sm:px-4 group perspective-1000",children:[e.jsxs(c.div,{initial:{opacity:0,y:40},animate:{opacity:1,y:0},transition:{delay:.15,type:"spring",stiffness:90},className:"flex flex-col items-center relative z-10 w-[28%] sm:w-[30%] max-w-[145px] mx-1 md:mr-2",children:[e.jsxs("div",{className:"flex flex-col items-center mb-2 md:mb-4 relative z-40 w-full",children:[e.jsx("div",{className:"w-14 h-14 md:w-[72px] md:h-[72px] rounded-full border-[3px] border-[#FF8B8B] bg-[#111827] flex items-center justify-center shadow-[0_0_18px_rgba(255,139,139,0.6)] overflow-hidden",children:f(o[1]?.avatar,26)}),e.jsx("h3",{className:"font-semibold text-white mt-1.5 md:mt-2 text-xs md:text-sm drop-shadow-md w-full text-center pb-1 px-1 whitespace-normal break-words leading-tight relative z-50",children:o[1]?.name||"---"})]}),e.jsxs("div",{className:"w-[90%] relative mt-2",children:[e.jsx("div",{className:"w-full h-10 md:h-14 absolute -bottom-5 md:-bottom-7 bg-[#D96C6A] rounded-[50%] shadow-[0_15px_25px_rgba(0,0,0,0.4)] z-0"}),e.jsx("div",{className:"w-full h-[100px] md:h-[130px] bg-[#D96C6A] relative z-10 flex flex-col items-center justify-start overflow-hidden",children:e.jsx("span",{className:"absolute inset-x-0 top-3 flex items-center justify-center text-[60px] md:text-[80px] font-black text-white/10 drop-shadow",children:"2"})}),e.jsx("div",{className:"w-full h-10 md:h-14 absolute -top-5 md:-top-7 bg-[#FF8B8B] rounded-[50%] z-20 shadow-[0_4px_8px_rgba(0,0,0,0.3)] flex flex-col items-center justify-center",children:e.jsxs("div",{className:"text-black/25 font-black text-[18px] md:text-[26px] transform scale-y-75 uppercase tracking-widest pointer-events-none z-30",children:[o[1]?.totalXP||0," XP"]})})]})]}),e.jsxs(c.div,{initial:{opacity:0,y:60},animate:{opacity:1,y:0},transition:{delay:.05,type:"spring",stiffness:100},className:"flex flex-col items-center relative z-30 w-[35%] sm:w-[38%] max-w-[190px]",children:[e.jsxs("div",{className:"flex flex-col items-center mb-3 md:mb-5 relative z-40 w-full",children:[e.jsx(c.div,{animate:{y:[0,-6,0]},transition:{repeat:1/0,duration:2.2,ease:"easeInOut"},className:"mb-[-10px] z-30",children:e.jsx(X,{size:30,className:"text-yellow-300 fill-yellow-300 drop-shadow-[0_0_12px_rgba(250,204,21,0.9)] md:w-9 md:h-9"})}),e.jsx("div",{className:"w-16 h-16 md:w-[86px] md:h-[86px] rounded-full border-[4px] border-[#fde68a] bg-[#111827] flex items-center justify-center shadow-[0_0_24px_rgba(250,204,21,0.6)] overflow-hidden",children:f(o[0]?.avatar,34)}),e.jsx("h3",{className:"font-semibold text-white mt-1.5 md:mt-2 text-sm md:text-base drop-shadow-md w-full text-center pb-1 px-1 whitespace-normal break-words leading-tight relative z-50",children:o[0]?.name||"---"})]}),e.jsxs("div",{className:"w-[95%] relative mt-2",children:[e.jsx("div",{className:"w-full h-12 md:h-16 absolute -bottom-6 md:-bottom-8 bg-[#6F2BAF] rounded-[50%] shadow-[0_20px_30px_rgba(0,0,0,0.5)] z-0"}),e.jsx("div",{className:"w-full h-[140px] md:h-[180px] bg-[#6F2BAF] relative z-10 flex flex-col items-center justify-start overflow-hidden",children:e.jsx("span",{className:"absolute inset-x-0 top-4 flex items-center justify-center text-[80px] md:text-[110px] font-black text-white/10 drop-shadow",children:"1"})}),e.jsx("div",{className:"w-full h-12 md:h-16 absolute -top-6 md:-top-8 bg-[#9956DE] rounded-[50%] z-20 shadow-[0_5px_12px_rgba(0,0,0,0.4)] flex flex-col items-center justify-center",children:e.jsxs("div",{className:"text-black/25 font-black text-[22px] md:text-[32px] transform scale-y-75 uppercase tracking-widest pointer-events-none z-30",children:[o[0]?.totalXP||0," XP"]})})]})]}),e.jsxs(c.div,{initial:{opacity:0,y:40},animate:{opacity:1,y:0},transition:{delay:.25,type:"spring",stiffness:90},className:"flex flex-col items-center relative z-10 w-[28%] sm:w-[30%] max-w-[145px] mx-1 md:ml-2",children:[e.jsxs("div",{className:"flex flex-col items-center mb-2 md:mb-4 relative z-40 w-full",children:[e.jsx("div",{className:"w-14 h-14 md:w-[72px] md:h-[72px] rounded-full border-[3px] border-[#FFB356] bg-[#111827] flex items-center justify-center shadow-[0_0_18px_rgba(255,179,86,0.6)] overflow-hidden",children:f(o[2]?.avatar,26)}),e.jsx("h3",{className:"font-semibold text-white mt-1.5 md:mt-2 text-xs md:text-sm drop-shadow-md w-full text-center pb-1 px-1 whitespace-normal break-words leading-tight relative z-50",children:o[2]?.name||"---"})]}),e.jsxs("div",{className:"w-[90%] relative mt-2",children:[e.jsx("div",{className:"w-full h-10 md:h-14 absolute -bottom-5 md:-bottom-7 bg-[#DE7949] rounded-[50%] shadow-[0_15px_25px_rgba(0,0,0,0.4)] z-0"}),e.jsx("div",{className:"w-full h-[75px] md:h-[100px] bg-[#DE7949] relative z-10 flex flex-col items-center justify-start overflow-hidden",children:e.jsx("span",{className:"absolute inset-x-0 top-1 flex items-center justify-center text-[50px] md:text-[70px] font-black text-white/10 drop-shadow",children:"3"})}),e.jsx("div",{className:"w-full h-10 md:h-14 absolute -top-5 md:-top-7 bg-[#FFB356] rounded-[50%] z-20 shadow-[0_4px_8px_rgba(0,0,0,0.3)] flex flex-col items-center justify-center",children:e.jsxs("div",{className:"text-black/25 font-black text-[16px] md:text-[22px] transform scale-y-75 uppercase tracking-widest pointer-events-none z-30",children:[o[2]?.totalXP||0," XP"]})})]})]})]})]}),e.jsxs("div",{className:"w-full flex-grow relative z-20 pt-6 pb-8 px-4 sm:px-10 flex flex-col items-center mt-[-15px] md:mt-[-30px] bg-white rounded-t-[2.5rem] shadow-[0_-10px_30px_rgba(0,0,0,0.1)] border-t border-slate-100 min-h-[50vh]",children:[e.jsx("div",{className:"w-12 h-1.5 bg-slate-200 rounded-full mb-6 mt-[-5px]"}),e.jsxs("div",{className:"w-full max-w-4xl space-y-3.5",children:[L.map((s,r)=>{const n=s.rank.global||r+4;return e.jsxs(c.div,{initial:{opacity:0,y:15},animate:{opacity:1,y:0},transition:{delay:r*.05+.3},onClick:()=>_(s),className:`flex items-center gap-4 p-3.5 md:p-4 rounded-3xl cursor-pointer bg-white border transition-all duration-300 ${s.isYou?"border-[#8B5CF6]/40 shadow-xl shadow-[#8B5CF6]/20 ring-2 ring-[#8B5CF6]/10":"border-slate-100 shadow-[0_12px_25px_rgba(0,0,0,0.08)] hover:shadow-[0_16px_30px_rgba(0,0,0,0.12)]"}`,children:[e.jsx("div",{className:"w-9 h-9 md:w-11 md:h-11 rounded-full border-2 border-slate-100 bg-white flex items-center justify-center font-display font-bold text-slate-500 shadow-sm text-sm",children:n}),e.jsx("div",{className:"w-11 h-11 md:w-14 md:h-14 bg-slate-100 rounded-full flex items-center justify-center text-xl overflow-hidden shadow-sm relative border-[3px] border-[#F1F5F9]",children:f(s.avatar,24)}),e.jsxs("div",{className:"flex-1 flex justify-between items-center pr-2",children:[e.jsx("div",{children:e.jsxs("h4",{className:"font-display font-bold text-[#1E293B] text-[15px] md:text-lg flex items-center gap-2 tracking-wide",children:[s.name,s.isYou&&e.jsx("span",{className:"text-[9px] uppercase tracking-wider bg-[#8B5CF6] text-white px-1.5 py-0.5 rounded font-bold",children:"You"})]})}),e.jsx("div",{children:e.jsxs("p",{className:"text-[13px] md:text-[15px] font-bold text-slate-500 text-right",children:[s.totalXP," ",e.jsx("span",{className:"text-[10px] text-slate-400 font-normal uppercase",children:"XP"})]})})]})]},s.id)}),L.length===0&&e.jsx("div",{className:"text-center py-12",children:e.jsx("p",{className:"text-slate-400 font-medium",children:"No other participants found in this view."})})]})]}),e.jsx(te,{student:I,onClose:()=>_(null)})]}):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(Q,{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:"Leaderboard Locked"}),e.jsx("p",{className:"text-xs text-slate-400",children:"This feature is temporarily unavailable while you focus on your learning."})]})]})};export{ue as default}; + transparent 4deg, transparent 8deg)`}})}),e.jsx("div",{className:"absolute bottom-0 left-1/2 -translate-x-1/2 w-[150vw] h-[100vh] bg-[radial-gradient(ellipse_at_50%_100%,#7e22ce_10%,transparent_60%)] mix-blend-overlay"})]}),e.jsx("div",{className:"absolute inset-0 bg-math-pattern opacity-[0.03] mix-blend-overlay pointer-events-none z-[-1] leaderboard-mask"}),e.jsxs("div",{className:"relative z-10 w-full px-4 sm:px-8 py-4 md:py-6 flex flex-col items-center",children:[e.jsx("div",{className:"w-full flex justify-center items-center mb-4 mt-2",children:e.jsx("h1",{className:"text-3xl md:text-4xl font-display font-bold tracking-wide text-slate-800 drop-shadow-sm",children:"Leaderboard"})}),e.jsx("div",{className:"bg-slate-800/5 backdrop-blur-md rounded-full p-1 flex gap-1 mb-3 shadow-[inset_0_2px_4px_rgba(0,0,0,0.05)] border border-slate-800/10 w-full max-w-[340px]",children:["daily","weekly","all"].map(s=>e.jsx("button",{onClick:()=>M(s),className:`flex-1 py-1.5 rounded-full text-[13px] md:text-sm font-semibold transition-all capitalize inline-flex justify-center items-center ${g===s?"bg-white text-purple-700 shadow-md border border-white/50 backdrop-blur-lg":"text-slate-600 hover:text-purple-700 hover:bg-white/50"}`,children:s==="all"?"All Time":s},s))}),e.jsxs(c.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},className:"w-full max-w-[420px] mb-4 bg-[#FFB356] p-2.5 md:p-3 rounded-full shadow-lg flex items-center gap-3 relative overflow-hidden ring-1 ring-white/20",children:[e.jsx("div",{className:"absolute inset-0 bg-noise opacity-[0.15] mix-blend-overlay pointer-events-none"}),e.jsx("div",{className:"bg-white/25 backdrop-blur-md px-4 py-2 min-w-[60px] rounded-full flex flex-col items-center justify-center shadow-sm z-10 border border-white/20",children:e.jsxs("span",{className:"text-xl md:text-2xl font-display font-bold text-white leading-none",children:["#",A]})}),e.jsx("div",{className:"z-10 flex-1 pr-2 md:pr-4",children:e.jsxs("p",{className:"font-medium text-white/90 text-sm md:text-[15px] leading-snug text-center",children:["You are doing better than ",e.jsxs("span",{className:"font-black text-white drop-shadow-sm",children:[Math.round(Y),"%"]})," of other players!"]})})]}),e.jsxs("div",{className:"w-full max-w-[800px] flex items-end justify-center gap-2 md:gap-4 h-[280px] md:h-[310px] relative z-20 mt-8 md:mt-12 mx-auto px-2 sm:px-4 group perspective-1000",children:[e.jsxs(c.div,{initial:{opacity:0,y:40},animate:{opacity:1,y:0},transition:{delay:.15,type:"spring",stiffness:90},className:"flex flex-col items-center relative z-10 w-[28%] sm:w-[30%] max-w-[145px] mx-1 md:mr-2",children:[e.jsxs("div",{className:"flex flex-col items-center mb-2 md:mb-4 relative z-40 w-full",children:[e.jsx("div",{className:"w-14 h-14 md:w-[72px] md:h-[72px] rounded-full border-[3px] border-[#FF8B8B] bg-[#111827] flex items-center justify-center shadow-[0_0_18px_rgba(255,139,139,0.6)] overflow-hidden",children:f(o[1]?.avatar,26)}),e.jsx("h3",{className:"font-semibold text-white mt-1.5 md:mt-2 text-xs md:text-sm drop-shadow-md w-full text-center pb-1 px-1 whitespace-normal break-words leading-tight relative z-50",children:o[1]?.name||"---"})]}),e.jsxs("div",{className:"w-[90%] relative mt-2",children:[e.jsx("div",{className:"w-full h-10 md:h-14 absolute -bottom-5 md:-bottom-7 bg-[#D96C6A] rounded-[50%] shadow-[0_15px_25px_rgba(0,0,0,0.4)] z-0"}),e.jsx("div",{className:"w-full h-[100px] md:h-[130px] bg-[#D96C6A] relative z-10 flex flex-col items-center justify-start overflow-hidden",children:e.jsx("span",{className:"absolute inset-x-0 top-3 flex items-center justify-center text-[60px] md:text-[80px] font-black text-white/10 drop-shadow",children:"2"})}),e.jsx("div",{className:"w-full h-10 md:h-14 absolute -top-5 md:-top-7 bg-[#FF8B8B] rounded-[50%] z-20 shadow-[0_4px_8px_rgba(0,0,0,0.3)] flex flex-col items-center justify-center",children:e.jsxs("div",{className:"text-black/25 font-black text-[18px] md:text-[26px] transform scale-y-75 uppercase tracking-widest pointer-events-none z-30",children:[o[1]?.totalXP||0," XP"]})})]})]}),e.jsxs(c.div,{initial:{opacity:0,y:60},animate:{opacity:1,y:0},transition:{delay:.05,type:"spring",stiffness:100},className:"flex flex-col items-center relative z-30 w-[35%] sm:w-[38%] max-w-[190px]",children:[e.jsxs("div",{className:"flex flex-col items-center mb-3 md:mb-5 relative z-40 w-full",children:[e.jsx(c.div,{animate:{y:[0,-6,0]},transition:{repeat:1/0,duration:2.2,ease:"easeInOut"},className:"mb-[-10px] z-30",children:e.jsx(X,{size:30,className:"text-yellow-300 fill-yellow-300 drop-shadow-[0_0_12px_rgba(250,204,21,0.9)] md:w-9 md:h-9"})}),e.jsx("div",{className:"w-16 h-16 md:w-[86px] md:h-[86px] rounded-full border-[4px] border-[#fde68a] bg-[#111827] flex items-center justify-center shadow-[0_0_24px_rgba(250,204,21,0.6)] overflow-hidden",children:f(o[0]?.avatar,34)}),e.jsx("h3",{className:"font-semibold text-white mt-1.5 md:mt-2 text-sm md:text-base drop-shadow-md w-full text-center pb-1 px-1 whitespace-normal break-words leading-tight relative z-50",children:o[0]?.name||"---"})]}),e.jsxs("div",{className:"w-[95%] relative mt-2",children:[e.jsx("div",{className:"w-full h-12 md:h-16 absolute -bottom-6 md:-bottom-8 bg-[#6F2BAF] rounded-[50%] shadow-[0_20px_30px_rgba(0,0,0,0.5)] z-0"}),e.jsx("div",{className:"w-full h-[140px] md:h-[180px] bg-[#6F2BAF] relative z-10 flex flex-col items-center justify-start overflow-hidden",children:e.jsx("span",{className:"absolute inset-x-0 top-4 flex items-center justify-center text-[80px] md:text-[110px] font-black text-white/10 drop-shadow",children:"1"})}),e.jsx("div",{className:"w-full h-12 md:h-16 absolute -top-6 md:-top-8 bg-[#9956DE] rounded-[50%] z-20 shadow-[0_5px_12px_rgba(0,0,0,0.4)] flex flex-col items-center justify-center",children:e.jsxs("div",{className:"text-black/25 font-black text-[22px] md:text-[32px] transform scale-y-75 uppercase tracking-widest pointer-events-none z-30",children:[o[0]?.totalXP||0," XP"]})})]})]}),e.jsxs(c.div,{initial:{opacity:0,y:40},animate:{opacity:1,y:0},transition:{delay:.25,type:"spring",stiffness:90},className:"flex flex-col items-center relative z-10 w-[28%] sm:w-[30%] max-w-[145px] mx-1 md:ml-2",children:[e.jsxs("div",{className:"flex flex-col items-center mb-2 md:mb-4 relative z-40 w-full",children:[e.jsx("div",{className:"w-14 h-14 md:w-[72px] md:h-[72px] rounded-full border-[3px] border-[#FFB356] bg-[#111827] flex items-center justify-center shadow-[0_0_18px_rgba(255,179,86,0.6)] overflow-hidden",children:f(o[2]?.avatar,26)}),e.jsx("h3",{className:"font-semibold text-white mt-1.5 md:mt-2 text-xs md:text-sm drop-shadow-md w-full text-center pb-1 px-1 whitespace-normal break-words leading-tight relative z-50",children:o[2]?.name||"---"})]}),e.jsxs("div",{className:"w-[90%] relative mt-2",children:[e.jsx("div",{className:"w-full h-10 md:h-14 absolute -bottom-5 md:-bottom-7 bg-[#DE7949] rounded-[50%] shadow-[0_15px_25px_rgba(0,0,0,0.4)] z-0"}),e.jsx("div",{className:"w-full h-[75px] md:h-[100px] bg-[#DE7949] relative z-10 flex flex-col items-center justify-start overflow-hidden",children:e.jsx("span",{className:"absolute inset-x-0 top-1 flex items-center justify-center text-[50px] md:text-[70px] font-black text-white/10 drop-shadow",children:"3"})}),e.jsx("div",{className:"w-full h-10 md:h-14 absolute -top-5 md:-top-7 bg-[#FFB356] rounded-[50%] z-20 shadow-[0_4px_8px_rgba(0,0,0,0.3)] flex flex-col items-center justify-center",children:e.jsxs("div",{className:"text-black/25 font-black text-[16px] md:text-[22px] transform scale-y-75 uppercase tracking-widest pointer-events-none z-30",children:[o[2]?.totalXP||0," XP"]})})]})]})]})]}),e.jsxs("div",{className:"w-full flex-grow relative z-20 pt-6 pb-8 px-4 sm:px-10 flex flex-col items-center mt-[-15px] md:mt-[-30px] bg-white rounded-t-[2.5rem] shadow-[0_-10px_30px_rgba(0,0,0,0.1)] border-t border-slate-100 min-h-[50vh]",children:[e.jsx("div",{className:"w-12 h-1.5 bg-slate-200 rounded-full mb-6 mt-[-5px]"}),e.jsxs("div",{className:"w-full max-w-4xl space-y-3.5",children:[L.map((s,r)=>{const n=s.rank.global||r+4;return e.jsxs(c.div,{initial:{opacity:0,y:15},animate:{opacity:1,y:0},transition:{delay:r*.05+.3},onClick:()=>_(s),className:`flex items-center gap-4 p-3.5 md:p-4 rounded-3xl cursor-pointer bg-white border transition-all duration-300 ${s.isYou?"border-[#8B5CF6]/40 shadow-xl shadow-[#8B5CF6]/20 ring-2 ring-[#8B5CF6]/10":"border-slate-100 shadow-[0_12px_25px_rgba(0,0,0,0.08)] hover:shadow-[0_16px_30px_rgba(0,0,0,0.12)]"}`,children:[e.jsx("div",{className:"w-9 h-9 md:w-11 md:h-11 rounded-full border-2 border-slate-100 bg-white flex items-center justify-center font-display font-bold text-slate-500 shadow-sm text-sm",children:n}),e.jsx("div",{className:"w-11 h-11 md:w-14 md:h-14 bg-slate-100 rounded-full flex items-center justify-center text-xl overflow-hidden shadow-sm relative border-[3px] border-[#F1F5F9]",children:f(s.avatar,24)}),e.jsxs("div",{className:"flex-1 flex justify-between items-center pr-2",children:[e.jsx("div",{children:e.jsxs("h4",{className:"font-display font-bold text-[#1E293B] text-[15px] md:text-lg flex items-center gap-2 tracking-wide",children:[s.name,s.isYou&&e.jsx("span",{className:"text-[9px] uppercase tracking-wider bg-[#8B5CF6] text-white px-1.5 py-0.5 rounded font-bold",children:"You"})]})}),e.jsx("div",{children:e.jsxs("p",{className:"text-[13px] md:text-[15px] font-bold text-slate-500 text-right",children:[s.totalXP," ",e.jsx("span",{className:"text-[10px] text-slate-400 font-normal uppercase",children:"XP"})]})})]})]},s.id)}),L.length===0&&e.jsx("div",{className:"text-center py-12",children:e.jsx("p",{className:"text-slate-400 font-medium",children:"No other participants found in this view."})})]})]}),e.jsx(te,{student:I,onClose:()=>_(null)})]}):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(K,{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:"Leaderboard Locked"}),e.jsx("p",{className:"text-xs text-slate-400",children:"This feature is temporarily unavailable while you focus on your learning."})]})]})};export{ue as default}; diff --git a/assets/LearningPath-BBE0vZ0S.js b/assets/LearningPath-COPS3nvD.js similarity index 76% rename from assets/LearningPath-BBE0vZ0S.js rename to assets/LearningPath-COPS3nvD.js index 6e98d8c8a29d14a371f7c4cfbe2a8b21369deed4..1fc32b8735403452039e699ca89fe5c071693231 100644 --- a/assets/LearningPath-BBE0vZ0S.js +++ b/assets/LearningPath-COPS3nvD.js @@ -1 +1 @@ -import{r as m,d as p,j as r}from"./vendor-react-B4AQeu28.js";import{u as j,a2 as P,a3 as I,q as N,a as k,b as L}from"./index-BaOs5Ayg.js";import{M as S}from"./ModuleFolderCard-DKBrO5a8.js";import"./vendor-firebase-firestore-CH1lNiRF.js";import"./vendor-firebase-core-CO26nNq6.js";import"./vendor-firebase-auth-BLpRW_zO.js";import"./vendor-firebase-storage-B3igpVVS.js";import"./vendor-firebase-analytics-CTiUNb0-.js";import"./vendor-radix-BorKzPz9.js";import"./vendor-charts-D8hf8tI0.js";import"./vendor-markdown-yqZQ_iQm.js";import"./useSubjectAvailability-Bvu3fXaT.js";import"./clock-D1Ecvltm.js";const V=({onNavigateToModules:c,atRiskSubjects:d=[],priorityTopics:o=[],modules:a})=>{const{userProfile:l}=j(),[u,h]=m.useState(null),i=p.useMemo(()=>{const e=o.length>0?o:d.map(s=>P(s)).filter(s=>s!==null),t=new Set;return e.filter(s=>t.has(s)?!1:(t.add(s),!0))},[o,d]),x=p.useMemo(()=>{if(i.length===0)return a.slice(0,3);const e=new Map(i.map((t,s)=>[I[t],s]));return[...a].sort((t,s)=>{const n=e.get(t.id)??Number.POSITIVE_INFINITY,b=e.get(s.id)??Number.POSITIVE_INFINITY;return n-b}).slice(0,3)},[a,i]);m.useEffect(()=>{l?.uid&&N(l.uid).then(h).catch(console.error)},[l?.uid]);const g=x.slice(0,3).map(e=>{const t=u?.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=g.some(e=>e.progress>0)?"Continue Learning":"Start Learning";return r.jsxs("div",{children:[r.jsxs("div",{className:"flex justify-between items-center mb-6 px-1",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("div",{className:"w-10 h-10 rounded-[14px] bg-indigo-50 border border-indigo-100 flex items-center justify-center text-indigo-500 shadow-inner",children:r.jsx(k,{size:20,strokeWidth:2.5})}),r.jsx("h2",{className:"font-display font-black text-[24px] text-slate-800 tracking-tight",children:f})]}),r.jsxs("button",{onClick:()=>c?.(),className:"text-primary font-bold text-sm flex items-center gap-1 hover:gap-2 transition-all bg-primary/10 px-4 py-2 rounded-xl hover:bg-primary/20",children:["View All ",r.jsx(L,{size:16})]})]}),r.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-3 gap-6",children:g.map((e,t)=>r.jsx(S,{module:e,index:t,onClick:()=>c?.(e.id),isAtRisk:i.length>0,badgeLabel:e.status!=="Not Started"?e.status:void 0},e.id))})]})};export{V as default}; +import{r as m,d as p,j as r}from"./vendor-react-B4AQeu28.js";import{l as j,a3 as P,a4 as I,x as N,a as k,b as L}from"./index-uASBzalf.js";import{M as S}from"./ModuleFolderCard-Du9VPsWG.js";import"./vendor-firebase-firestore-CP9q7ISf.js";import"./vendor-firebase-core-DCQrgkxC.js";import"./vendor-firebase-auth-Bcpr4O6E.js";import"./vendor-firebase-storage-dc5X5yTv.js";import"./vendor-firebase-analytics-CHPyhRzk.js";import"./vendor-radix-xDOIcVzp.js";import"./vendor-charts-Ckgeb0nY.js";import"./vendor-markdown-yqZQ_iQm.js";import"./useSubjectAvailability-jmWCWhoq.js";import"./clock-8t0UYgg3.js";const V=({onNavigateToModules:c,atRiskSubjects:d=[],priorityTopics:o=[],modules:a})=>{const{userProfile:l}=j(),[u,h]=m.useState(null),i=p.useMemo(()=>{const e=o.length>0?o:d.map(s=>P(s)).filter(s=>s!==null),t=new Set;return e.filter(s=>t.has(s)?!1:(t.add(s),!0))},[o,d]),x=p.useMemo(()=>{if(i.length===0)return a.slice(0,3);const e=new Map(i.map((t,s)=>[I[t],s]));return[...a].sort((t,s)=>{const n=e.get(t.id)??Number.POSITIVE_INFINITY,b=e.get(s.id)??Number.POSITIVE_INFINITY;return n-b}).slice(0,3)},[a,i]);m.useEffect(()=>{l?.uid&&N(l.uid).then(h).catch(console.error)},[l?.uid]);const g=x.slice(0,3).map(e=>{const t=u?.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=g.some(e=>e.progress>0)?"Continue Learning":"Start Learning";return r.jsxs("div",{children:[r.jsxs("div",{className:"flex justify-between items-center mb-6 px-1",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("div",{className:"w-10 h-10 rounded-[14px] bg-indigo-50 border border-indigo-100 flex items-center justify-center text-indigo-500 shadow-inner",children:r.jsx(k,{size:20,strokeWidth:2.5})}),r.jsx("h2",{className:"font-display font-black text-[24px] text-slate-800 tracking-tight",children:f})]}),r.jsxs("button",{onClick:()=>c?.(),className:"text-primary font-bold text-sm flex items-center gap-1 hover:gap-2 transition-all bg-primary/10 px-4 py-2 rounded-xl hover:bg-primary/20",children:["View All ",r.jsx(L,{size:16})]})]}),r.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-3 gap-6",children:g.map((e,t)=>r.jsx(S,{module:e,index:t,onClick:()=>c?.(e.id),isAtRisk:i.length>0,badgeLabel:e.status!=="Not Started"?e.status:void 0},e.id))})]})};export{V as default}; diff --git a/assets/LoginPage-DLaoyzV8.js b/assets/LoginPage-LluNGRPB.js similarity index 96% rename from assets/LoginPage-DLaoyzV8.js rename to assets/LoginPage-LluNGRPB.js index 06195d04e574f31319a9663306e6859bbf6fc249..cc16aecf6e75caa5656a9ecd2884e65e3c699c2c 100644 --- a/assets/LoginPage-DLaoyzV8.js +++ b/assets/LoginPage-LluNGRPB.js @@ -1 +1 @@ -import{r as s,j as e}from"./vendor-react-B4AQeu28.js";import{B as Me}from"./button-DCfeFHoH.js";import{I as D}from"./input-D28h_UTJ.js";import{m as r,B as Ee,T as Te,A as Re,U as te,G as se,a as ae,L as re,b as ie,s as oe,c as Ce,d as le}from"./index-BaOs5Ayg.js";import{S as Ie}from"./sparkles-By-vFjpv.js";import{M as Le}from"./mail-BbG1phxL.js";import{E as De,a as ze}from"./eye-Ig3S6mOs.js";import{S as qe}from"./shield-check-Dgisjfmb.js";import"./vendor-radix-BorKzPz9.js";import"./vendor-charts-D8hf8tI0.js";import"./vendor-firebase-firestore-CH1lNiRF.js";import"./vendor-firebase-core-CO26nNq6.js";import"./vendor-firebase-auth-BLpRW_zO.js";import"./vendor-firebase-storage-B3igpVVS.js";import"./vendor-firebase-analytics-CTiUNb0-.js";import"./vendor-markdown-yqZQ_iQm.js";const ne="/assets/shader-bg-DA7bEbBA.mp4",Be=[{id:"length",label:"At least 8 characters",test:i=>i.length>=8},{id:"upper-lower",label:"Contains uppercase and lowercase letters",test:i=>/[A-Z]/.test(i)&&/[a-z]/.test(i)},{id:"number",label:"Contains at least one number",test:i=>/\d/.test(i)},{id:"special",label:"Contains at least one special character",test:i=>/[^A-Za-z0-9]/.test(i)}],z="Use at least 8 characters with uppercase, lowercase, number, and special character.",Oe=i=>{const c=typeof i=="object"&&i!==null?i:null,o=i instanceof Error?i.message:"";if(c?.code&&typeof c.code=="string")return{code:c.code.toLowerCase(),message:o};const d=o.match(/auth\/[a-z-]+/i);return{code:d?d[0].toLowerCase():"",message:o}},_e=i=>i.replace(/^Firebase:\s*/i,"").replace(/\s*\(auth\/[a-z-]+\)\.?/i,"").trim(),ce=(i,c)=>{const{code:o,message:d}=Oe(i),h=_e(d);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. ${z}`: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:d.includes("Firebase:")||d.includes("auth/")?c:d||c},rt=()=>{const i=["Grade 11"],c={"Grade 11":["STEM A","STEM B","ABM A","HUMSS A"]},o={teacher:["Mathematics","Science","English","Technology","Humanities"]},[d,h]=s.useState(""),[f,q]=s.useState(""),[A,de]=s.useState(!1),[l,B]=s.useState(!1),[M,ue]=s.useState(""),[n,O]=s.useState("student"),[b,me]=s.useState("Grade 11"),[w,_]=s.useState(c["Grade 11"][0]),[g,V]=s.useState("Mathematics"),[G,x]=s.useState(!1),[v,m]=s.useState(null),[pe,xe]=s.useState(!1),[ye,he]=s.useState(!1),[E,be]=s.useState(16),[F,U]=s.useState("primary"),[$,T]=s.useState(0),R=s.useRef(null),C=s.useRef(null),N=pe&&ye,j=s.useRef("primary"),k=s.useRef(0),S=s.useRef(!1),W=1.1,H=.34,Y=t=>{const a=Math.max(0,Math.min(1,t));Math.abs(k.current-a)<.02||(k.current=a,T(a))},Z=t=>{!Number.isFinite(t)||t<=0||Math.abs(E-t)>.05&&be(t)},I=s.useMemo(()=>Be.map(t=>({...t,met:t.test(f)})),[f]),fe=s.useMemo(()=>I.every(t=>t.met),[I]),J=s.useMemo(()=>{if(!l||!v)return!1;const t=v.toLowerCase();return t.includes("password requirements not met")||t.includes("password does not meet")},[v,l]),ge=()=>{const t=R.current?.duration;t&&Number.isFinite(t)&&t>0&&Z(t)},ve=()=>{const t=C.current?.duration;t&&Number.isFinite(t)&&t>0&&Z(t)};s.useEffect(()=>{if(!N)return;const t=R.current,a=C.current;if(!t||!a)return;let u=!1,p=0;j.current="primary",U("primary"),S.current=!1,k.current=0,T(0),t.loop=!1,a.loop=!1,t.currentTime=0,a.currentTime=0,a.pause(),t.play().catch(()=>{});const P=()=>{if(u)return;const y=j.current==="primary"?t:a,K=j.current==="primary"?a:t,Pe=Number.isFinite(y.duration)&&y.duration>0?y.duration:E,L=Math.max(Pe-y.currentTime,0);if(L<=W){S.current||(S.current=!0,K.currentTime=0,K.play().catch(()=>{}));const Ae=1-L/W;if(Y(Ae),L<=.03||y.ended){y.pause(),y.currentTime=0;const ee=j.current==="primary"?"secondary":"primary";j.current=ee,U(ee),S.current=!1,k.current=0,T(0)}}else Y(0);p=window.requestAnimationFrame(P)};return p=window.requestAnimationFrame(P),()=>{u=!0,p&&window.cancelAnimationFrame(p)}},[E,N]);const Q=N?H*(1-$):0,X=N?H*$:0,je=F==="primary"?Q:X,we=F==="secondary"?Q:X;s.useEffect(()=>{n==="teacher"&&!o.teacher.includes(g)&&V(o.teacher[0])},[g,n]),s.useEffect(()=>{const t=c[b]||[];t.length>0&&!t.includes(w)&&_(t[0])},[b,w]);const Ne=[{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:ae,color:"emerald"},{label:"Admin",role:"admin",email:"testadmin@school.edu",password:"TestPass123!",icon:qe,color:"rose"}],ke=async(t,a,u)=>{m(null),x(!0),h(t),q(a),O(u),B(!1);try{oe(u),await le(t,a)}catch(p){m(ce(p,"Demo sign-in failed. Please try again.")),x(!1)}},Se=async t=>{t.preventDefault(),m(null),x(!0);try{if(l){if(!M.trim()){m("Please enter your name"),x(!1);return}if(n==="student"&&!b){m("Please select a grade level"),x(!1);return}if(n!=="student"&&!g){m("Please select a department"),x(!1);return}if(n==="admin"){m("Admin account creation is restricted. Please contact an existing administrator."),x(!1);return}if(!fe){m(`Password does not meet signup requirements. ${z}`),x(!1);return}oe(n),await Ce(d,f,M,n,n==="student"?{grade:b,section:w}:{department:g})}else await le(d,f)}catch(a){const u=l?`Sign-up failed. ${z}`:"Sign-in failed. Please check your credentials and try again.";m(ce(a,u)),x(!1)}};return e.jsxs("div",{className:"h-screen w-full flex items-center justify-center px-6 overflow-hidden relative login-bg",children:[e.jsx("video",{ref:R,autoPlay:!0,muted:!0,playsInline:!0,preload:"auto",onCanPlay:()=>xe(!0),onLoadedMetadata:ge,className:"absolute inset-0 w-full h-full object-cover transition-opacity duration-150 e-opacity",style:{"--o":je},src:ne}),e.jsx("video",{ref:C,autoPlay:!0,muted:!0,playsInline:!0,preload:"auto",onCanPlay:()=>he(!0),onLoadedMetadata:ve,className:"absolute inset-0 w-full h-full object-cover transition-opacity duration-150 e-opacity",style:{"--o":we},src:ne}),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(r.div,{initial:{opacity:0,x:-40},animate:{opacity:1,x:0},transition:{duration:.8,ease:[.22,1,.36,1]},className:"flex flex-col justify-center space-y-8",children:[e.jsxs(r.div,{className:"flex items-center gap-2.5",children:[e.jsx(r.div,{className:"relative flex items-center justify-center drop-shadow-md",children:e.jsx("img",{src:"/mathpulse_logo.png",alt:"MathPulse AI Logo",className:"w-16 h-16 object-contain flex-shrink-0"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"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(Ie,{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(r.div,{className:"space-y-5",initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.2,duration:.8},children:[e.jsxs("h2",{className:"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-base text-slate-500 leading-relaxed max-w-md 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-3",children:[{icon:Ee,label:"AI Predictions",desc:"Smart detection",color:"sky"},{icon:Te,label:"Analytics",desc:"Real-time data",color:"rose"},{icon:Re,label:"Gamified",desc:"Learn & earn",color:"emerald"}].map((t,a)=>{const u=t.icon,p={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"},P={sky:"text-sky-600",rose:"text-rose-500",emerald:"text-emerald-600"},y={sky:"bg-sky-100",rose:"bg-rose-100",emerald:"bg-emerald-100"};return e.jsxs(r.div,{className:`bg-white/80 backdrop-blur-xl border ${p[t.color]} rounded-xl 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+a*.1},whileHover:{scale:1.03,y:-4},children:[e.jsx("div",{className:`w-9 h-9 rounded-lg ${y[t.color]} flex items-center justify-center mb-3`,children:e.jsx(u,{size:18,className:P[t.color]})}),e.jsx("h3",{className:"text-sm font-display font-semibold text-slate-800 mb-0.5",children:t.label}),e.jsx("p",{className:"text-xs text-slate-400 font-body",children:t.desc})]},a)})})]}),e.jsx(r.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-7 w-full max-w-md relative overflow-hidden shadow-[0_20px_60px_-15px_rgba(168,85,247,0.15)]",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-6 relative",children:[e.jsx(r.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(r.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:Se,className:"space-y-4 mb-5 relative",children:[v&&!J&&e.jsx(r.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:v}),l&&e.jsxs(r.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(te,{size:16,className:"absolute left-4 top-1/2 -translate-y-1/2 text-slate-400"}),e.jsx(D,{type:"text",placeholder:"Your Name",value:M,onChange:t=>ue(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(r.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 a=n===t.role;return e.jsx("button",{type:"button",onClick:()=>O(t.role),className:`rounded-lg border px-3 py-2 text-xs font-body font-semibold transition-all ${a?"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&&n==="student"&&e.jsxs(r.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:"Grade Level"}),e.jsxs("div",{className:"relative",children:[e.jsx(se,{size:16,className:"absolute left-4 top-1/2 -translate-y-1/2 text-slate-400"}),e.jsx("select",{value:b,onChange:t=>me(t.target.value),className:"w-full pl-11 pr-4 py-3 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:i.map(t=>e.jsx("option",{value:t,children:t},t))})]})]}),l&&n==="student"&&e.jsxs(r.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:"Section"}),e.jsxs("div",{className:"relative",children:[e.jsx(te,{size:16,className:"absolute left-4 top-1/2 -translate-y-1/2 text-slate-400"}),e.jsx("select",{value:w,onChange:t=>_(t.target.value),className:"w-full pl-11 pr-4 py-3 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:(c[b]||[]).map(t=>e.jsx("option",{value:t,children:t},t))})]})]}),l&&n!=="student"&&e.jsxs(r.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:"Department"}),e.jsxs("div",{className:"relative",children:[e.jsx(ae,{size:16,className:"absolute left-4 top-1/2 -translate-y-1/2 text-slate-400"}),e.jsx("select",{value:g,onChange:t=>V(t.target.value),className:"w-full pl-11 pr-4 py-3 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:o.teacher.map(t=>e.jsx("option",{value:t,children:t},t))})]})]}),e.jsxs(r.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(Le,{size:16,className:"absolute left-4 top-1/2 -translate-y-1/2 text-slate-400"}),e.jsx(D,{type:"email",placeholder:"your.email@school.edu",value:d,onChange:t=>h(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(r.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(re,{size:16,className:"absolute left-4 top-1/2 -translate-y-1/2 text-slate-400"}),e.jsx(D,{type:A?"text":"password",placeholder:"••••••••",value:f,onChange:t=>q(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(r.button,{type:"button",onClick:()=>de(!A),className:"absolute right-3 top-1/2 -translate-y-1/2 text-slate-400 hover:text-slate-600 transition-colors",whileTap:{scale:.9},children:A?e.jsx(De,{size:16}):e.jsx(ze,{size:16})})]}),l&&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:I.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))}),J&&e.jsx("p",{className:"mt-2 text-[11px] font-body font-semibold text-rose-600",children:"Password does not meet signup requirements."})]})]}),e.jsx(r.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:.7},children:e.jsxs(Me,{type:"submit",disabled:G,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(r.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:[G?"Please wait...":l?"Create Account":"Sign In",e.jsx(ie,{size:16,className:"group-hover:translate-x-1 transition-transform"})]})]})}),e.jsx("div",{className:"text-center",children:e.jsx("button",{type:"button",onClick:()=>{B(!l),m(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(r.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:Ne.map(t=>{const a=t.icon,u={sky:"bg-sky-100",emerald:"bg-emerald-100",rose:"bg-rose-100"},p={sky:"text-sky-600",emerald:"text-emerald-600",rose:"text-rose-500"};return e.jsxs(r.button,{type:"button",onClick:()=>ke(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 ${u[t.color]}`,children:e.jsx(a,{size:15,className:p[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(ie,{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(r.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(re,{size:10,className:"inline mr-1 -mt-0.5"})," Your data is encrypted and secure"]})]})})]})})]})};export{rt as default}; +import{r as s,j as e}from"./vendor-react-B4AQeu28.js";import{B as Me}from"./button-BPmLcOpC.js";import{I as D}from"./input--XHWlmp1.js";import{m as r,B as Ee,T as Te,A as Re,U as te,G as se,a as ae,L as re,b as ie,s as oe,c as Ce,d as le}from"./index-uASBzalf.js";import{S as Ie}from"./sparkles-DHVr5IP1.js";import{M as Le}from"./mail-BF4xxwnI.js";import{E as De,a as ze}from"./eye-DIwMshM-.js";import{S as qe}from"./shield-check-vm2tbr1-.js";import"./vendor-radix-xDOIcVzp.js";import"./vendor-charts-Ckgeb0nY.js";import"./vendor-firebase-firestore-CP9q7ISf.js";import"./vendor-firebase-core-DCQrgkxC.js";import"./vendor-firebase-auth-Bcpr4O6E.js";import"./vendor-firebase-storage-dc5X5yTv.js";import"./vendor-firebase-analytics-CHPyhRzk.js";import"./vendor-markdown-yqZQ_iQm.js";const ne="/assets/shader-bg-DA7bEbBA.mp4",Be=[{id:"length",label:"At least 8 characters",test:i=>i.length>=8},{id:"upper-lower",label:"Contains uppercase and lowercase letters",test:i=>/[A-Z]/.test(i)&&/[a-z]/.test(i)},{id:"number",label:"Contains at least one number",test:i=>/\d/.test(i)},{id:"special",label:"Contains at least one special character",test:i=>/[^A-Za-z0-9]/.test(i)}],z="Use at least 8 characters with uppercase, lowercase, number, and special character.",Oe=i=>{const c=typeof i=="object"&&i!==null?i:null,o=i instanceof Error?i.message:"";if(c?.code&&typeof c.code=="string")return{code:c.code.toLowerCase(),message:o};const d=o.match(/auth\/[a-z-]+/i);return{code:d?d[0].toLowerCase():"",message:o}},_e=i=>i.replace(/^Firebase:\s*/i,"").replace(/\s*\(auth\/[a-z-]+\)\.?/i,"").trim(),ce=(i,c)=>{const{code:o,message:d}=Oe(i),h=_e(d);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. ${z}`: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:d.includes("Firebase:")||d.includes("auth/")?c:d||c},rt=()=>{const i=["Grade 11"],c={"Grade 11":["STEM A","STEM B","ABM A","HUMSS A"]},o={teacher:["Mathematics","Science","English","Technology","Humanities"]},[d,h]=s.useState(""),[f,q]=s.useState(""),[A,de]=s.useState(!1),[l,B]=s.useState(!1),[M,ue]=s.useState(""),[n,O]=s.useState("student"),[b,me]=s.useState("Grade 11"),[w,_]=s.useState(c["Grade 11"][0]),[g,V]=s.useState("Mathematics"),[G,x]=s.useState(!1),[v,m]=s.useState(null),[pe,xe]=s.useState(!1),[ye,he]=s.useState(!1),[E,be]=s.useState(16),[F,U]=s.useState("primary"),[$,T]=s.useState(0),R=s.useRef(null),C=s.useRef(null),N=pe&&ye,j=s.useRef("primary"),k=s.useRef(0),S=s.useRef(!1),W=1.1,H=.34,Y=t=>{const a=Math.max(0,Math.min(1,t));Math.abs(k.current-a)<.02||(k.current=a,T(a))},Z=t=>{!Number.isFinite(t)||t<=0||Math.abs(E-t)>.05&&be(t)},I=s.useMemo(()=>Be.map(t=>({...t,met:t.test(f)})),[f]),fe=s.useMemo(()=>I.every(t=>t.met),[I]),J=s.useMemo(()=>{if(!l||!v)return!1;const t=v.toLowerCase();return t.includes("password requirements not met")||t.includes("password does not meet")},[v,l]),ge=()=>{const t=R.current?.duration;t&&Number.isFinite(t)&&t>0&&Z(t)},ve=()=>{const t=C.current?.duration;t&&Number.isFinite(t)&&t>0&&Z(t)};s.useEffect(()=>{if(!N)return;const t=R.current,a=C.current;if(!t||!a)return;let u=!1,p=0;j.current="primary",U("primary"),S.current=!1,k.current=0,T(0),t.loop=!1,a.loop=!1,t.currentTime=0,a.currentTime=0,a.pause(),t.play().catch(()=>{});const P=()=>{if(u)return;const y=j.current==="primary"?t:a,K=j.current==="primary"?a:t,Pe=Number.isFinite(y.duration)&&y.duration>0?y.duration:E,L=Math.max(Pe-y.currentTime,0);if(L<=W){S.current||(S.current=!0,K.currentTime=0,K.play().catch(()=>{}));const Ae=1-L/W;if(Y(Ae),L<=.03||y.ended){y.pause(),y.currentTime=0;const ee=j.current==="primary"?"secondary":"primary";j.current=ee,U(ee),S.current=!1,k.current=0,T(0)}}else Y(0);p=window.requestAnimationFrame(P)};return p=window.requestAnimationFrame(P),()=>{u=!0,p&&window.cancelAnimationFrame(p)}},[E,N]);const Q=N?H*(1-$):0,X=N?H*$:0,je=F==="primary"?Q:X,we=F==="secondary"?Q:X;s.useEffect(()=>{n==="teacher"&&!o.teacher.includes(g)&&V(o.teacher[0])},[g,n]),s.useEffect(()=>{const t=c[b]||[];t.length>0&&!t.includes(w)&&_(t[0])},[b,w]);const Ne=[{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:ae,color:"emerald"},{label:"Admin",role:"admin",email:"testadmin@school.edu",password:"TestPass123!",icon:qe,color:"rose"}],ke=async(t,a,u)=>{m(null),x(!0),h(t),q(a),O(u),B(!1);try{oe(u),await le(t,a)}catch(p){m(ce(p,"Demo sign-in failed. Please try again.")),x(!1)}},Se=async t=>{t.preventDefault(),m(null),x(!0);try{if(l){if(!M.trim()){m("Please enter your name"),x(!1);return}if(n==="student"&&!b){m("Please select a grade level"),x(!1);return}if(n!=="student"&&!g){m("Please select a department"),x(!1);return}if(n==="admin"){m("Admin account creation is restricted. Please contact an existing administrator."),x(!1);return}if(!fe){m(`Password does not meet signup requirements. ${z}`),x(!1);return}oe(n),await Ce(d,f,M,n,n==="student"?{grade:b,section:w}:{department:g})}else await le(d,f)}catch(a){const u=l?`Sign-up failed. ${z}`:"Sign-in failed. Please check your credentials and try again.";m(ce(a,u)),x(!1)}};return e.jsxs("div",{className:"h-screen w-full flex items-center justify-center px-6 overflow-hidden relative login-bg",children:[e.jsx("video",{ref:R,autoPlay:!0,muted:!0,playsInline:!0,preload:"auto",onCanPlay:()=>xe(!0),onLoadedMetadata:ge,className:"absolute inset-0 w-full h-full object-cover transition-opacity duration-150 e-opacity",style:{"--o":je},src:ne}),e.jsx("video",{ref:C,autoPlay:!0,muted:!0,playsInline:!0,preload:"auto",onCanPlay:()=>he(!0),onLoadedMetadata:ve,className:"absolute inset-0 w-full h-full object-cover transition-opacity duration-150 e-opacity",style:{"--o":we},src:ne}),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(r.div,{initial:{opacity:0,x:-40},animate:{opacity:1,x:0},transition:{duration:.8,ease:[.22,1,.36,1]},className:"flex flex-col justify-center space-y-8",children:[e.jsxs(r.div,{className:"flex items-center gap-2.5",children:[e.jsx(r.div,{className:"relative flex items-center justify-center drop-shadow-md",children:e.jsx("img",{src:"/mathpulse_logo.png",alt:"MathPulse AI Logo",className:"w-16 h-16 object-contain flex-shrink-0"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"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(Ie,{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(r.div,{className:"space-y-5",initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.2,duration:.8},children:[e.jsxs("h2",{className:"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-base text-slate-500 leading-relaxed max-w-md 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-3",children:[{icon:Ee,label:"AI Predictions",desc:"Smart detection",color:"sky"},{icon:Te,label:"Analytics",desc:"Real-time data",color:"rose"},{icon:Re,label:"Gamified",desc:"Learn & earn",color:"emerald"}].map((t,a)=>{const u=t.icon,p={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"},P={sky:"text-sky-600",rose:"text-rose-500",emerald:"text-emerald-600"},y={sky:"bg-sky-100",rose:"bg-rose-100",emerald:"bg-emerald-100"};return e.jsxs(r.div,{className:`bg-white/80 backdrop-blur-xl border ${p[t.color]} rounded-xl 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+a*.1},whileHover:{scale:1.03,y:-4},children:[e.jsx("div",{className:`w-9 h-9 rounded-lg ${y[t.color]} flex items-center justify-center mb-3`,children:e.jsx(u,{size:18,className:P[t.color]})}),e.jsx("h3",{className:"text-sm font-display font-semibold text-slate-800 mb-0.5",children:t.label}),e.jsx("p",{className:"text-xs text-slate-400 font-body",children:t.desc})]},a)})})]}),e.jsx(r.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-7 w-full max-w-md relative overflow-hidden shadow-[0_20px_60px_-15px_rgba(168,85,247,0.15)]",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-6 relative",children:[e.jsx(r.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(r.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:Se,className:"space-y-4 mb-5 relative",children:[v&&!J&&e.jsx(r.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:v}),l&&e.jsxs(r.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(te,{size:16,className:"absolute left-4 top-1/2 -translate-y-1/2 text-slate-400"}),e.jsx(D,{type:"text",placeholder:"Your Name",value:M,onChange:t=>ue(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(r.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 a=n===t.role;return e.jsx("button",{type:"button",onClick:()=>O(t.role),className:`rounded-lg border px-3 py-2 text-xs font-body font-semibold transition-all ${a?"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&&n==="student"&&e.jsxs(r.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:"Grade Level"}),e.jsxs("div",{className:"relative",children:[e.jsx(se,{size:16,className:"absolute left-4 top-1/2 -translate-y-1/2 text-slate-400"}),e.jsx("select",{value:b,onChange:t=>me(t.target.value),className:"w-full pl-11 pr-4 py-3 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:i.map(t=>e.jsx("option",{value:t,children:t},t))})]})]}),l&&n==="student"&&e.jsxs(r.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:"Section"}),e.jsxs("div",{className:"relative",children:[e.jsx(te,{size:16,className:"absolute left-4 top-1/2 -translate-y-1/2 text-slate-400"}),e.jsx("select",{value:w,onChange:t=>_(t.target.value),className:"w-full pl-11 pr-4 py-3 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:(c[b]||[]).map(t=>e.jsx("option",{value:t,children:t},t))})]})]}),l&&n!=="student"&&e.jsxs(r.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:"Department"}),e.jsxs("div",{className:"relative",children:[e.jsx(ae,{size:16,className:"absolute left-4 top-1/2 -translate-y-1/2 text-slate-400"}),e.jsx("select",{value:g,onChange:t=>V(t.target.value),className:"w-full pl-11 pr-4 py-3 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:o.teacher.map(t=>e.jsx("option",{value:t,children:t},t))})]})]}),e.jsxs(r.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(Le,{size:16,className:"absolute left-4 top-1/2 -translate-y-1/2 text-slate-400"}),e.jsx(D,{type:"email",placeholder:"your.email@school.edu",value:d,onChange:t=>h(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(r.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(re,{size:16,className:"absolute left-4 top-1/2 -translate-y-1/2 text-slate-400"}),e.jsx(D,{type:A?"text":"password",placeholder:"••••••••",value:f,onChange:t=>q(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(r.button,{type:"button",onClick:()=>de(!A),className:"absolute right-3 top-1/2 -translate-y-1/2 text-slate-400 hover:text-slate-600 transition-colors",whileTap:{scale:.9},children:A?e.jsx(De,{size:16}):e.jsx(ze,{size:16})})]}),l&&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:I.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))}),J&&e.jsx("p",{className:"mt-2 text-[11px] font-body font-semibold text-rose-600",children:"Password does not meet signup requirements."})]})]}),e.jsx(r.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:.7},children:e.jsxs(Me,{type:"submit",disabled:G,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(r.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:[G?"Please wait...":l?"Create Account":"Sign In",e.jsx(ie,{size:16,className:"group-hover:translate-x-1 transition-transform"})]})]})}),e.jsx("div",{className:"text-center",children:e.jsx("button",{type:"button",onClick:()=>{B(!l),m(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(r.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:Ne.map(t=>{const a=t.icon,u={sky:"bg-sky-100",emerald:"bg-emerald-100",rose:"bg-rose-100"},p={sky:"text-sky-600",emerald:"text-emerald-600",rose:"text-rose-500"};return e.jsxs(r.button,{type:"button",onClick:()=>ke(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 ${u[t.color]}`,children:e.jsx(a,{size:15,className:p[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(ie,{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(r.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(re,{size:10,className:"inline mr-1 -mt-0.5"})," Your data is encrypted and secure"]})]})})]})})]})};export{rt as default}; diff --git a/assets/LogoutActionButton-lUNItet6.js b/assets/LogoutActionButton-Dl6IiDHd.js similarity index 93% rename from assets/LogoutActionButton-lUNItet6.js rename to assets/LogoutActionButton-Dl6IiDHd.js index 2063687e6b4283da1411fde4ee6ab366cd313454..c33a8979a8b237a0fc0353816694a3d005c48c4e 100644 --- a/assets/LogoutActionButton-lUNItet6.js +++ b/assets/LogoutActionButton-Dl6IiDHd.js @@ -1,4 +1,4 @@ -import{e as a,m as s,i}from"./index-BaOs5Ayg.js";import{j as t}from"./vendor-react-B4AQeu28.js";import{L as l}from"./log-out-BenDMDly.js";/** +import{e as a,m as s,k as i}from"./index-uASBzalf.js";import{j as t}from"./vendor-react-B4AQeu28.js";import{L as l}from"./log-out-Dr0BHRO4.js";/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. diff --git a/assets/ModuleFolderCard-DKBrO5a8.js b/assets/ModuleFolderCard-Du9VPsWG.js similarity index 97% rename from assets/ModuleFolderCard-DKBrO5a8.js rename to assets/ModuleFolderCard-Du9VPsWG.js index 9796d9ab5b38875074d1b3188e52cb9a62e40308..306e3da26582b620f3a9ba48cbfa7d0956caab42 100644 --- a/assets/ModuleFolderCard-DKBrO5a8.js +++ b/assets/ModuleFolderCard-Du9VPsWG.js @@ -1,4 +1,4 @@ -import{j as e}from"./vendor-react-B4AQeu28.js";import{u as g}from"./useSubjectAvailability-Bvu3fXaT.js";import{e as w,m as f,a as j,p as v,L as k}from"./index-BaOs5Ayg.js";import{C as y}from"./clock-D1Ecvltm.js";/** +import{j as e}from"./vendor-react-B4AQeu28.js";import{u as g}from"./useSubjectAvailability-jmWCWhoq.js";import{e as w,m as f,a as j,w as v,L as k}from"./index-uASBzalf.js";import{C as y}from"./clock-8t0UYgg3.js";/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. diff --git a/assets/ModulesPage-cZJm_yoJ.js b/assets/ModulesPage-Bm1A4Op1.js similarity index 85% rename from assets/ModulesPage-cZJm_yoJ.js rename to assets/ModulesPage-Bm1A4Op1.js index 267af58c340940410b206ab0512d77f1aff2dad8..50294469c4840a961d90130e1223085891ad4ed7 100644 --- a/assets/ModulesPage-cZJm_yoJ.js +++ b/assets/ModulesPage-Bm1A4Op1.js @@ -1,105 +1,95 @@ -const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/vendor-firebase-auth-BLpRW_zO.js","assets/vendor-firebase-core-CO26nNq6.js"])))=>i.map(i=>d[i]); -import{r as s,j as e,b as ut,d as Ae}from"./vendor-react-B4AQeu28.js";import{u as Gs}from"./useQuery-BnRttv09.js";import{getDoc as qt,doc as bt,onSnapshot as Gt,runTransaction as Vs,serverTimestamp as Ys,query as Ks,where as Zs,collection as Js}from"./vendor-firebase-firestore-CH1lNiRF.js";import{e as ie,m as v,Z as Re,C as mt,j as $e,O as As,M as ea,b as pt,T as Pt,y as qe,X as Es,R as Ps,x as Ct,_ as Lt,B as ns,F as ta,u as Ft,A as It,a as Je,i as At,p as Ts,n as sa,a4 as is,a5 as aa,a6 as os,a7 as ra,a8 as la,L as Vt,f as We,q as na,a9 as ia,aa as oa,ab as Ls,ac as ca,ad as da,ae as xa,a2 as ma,o as ua,af as cs,ag as pa,ah as ds,G as ha,a1 as fa,t as Bt,a3 as ba}from"./index-BaOs5Ayg.js";import{M as Wt}from"./ModuleFolderCard-DKBrO5a8.js";import{B as ze}from"./button-DCfeFHoH.js";import Fs from"./ScientificCalculator-DRuSfTXj.js";import{C as lt}from"./check-BLSo9L0H.js";import{X as De}from"./x-TNvtuOD9.js";import{V as Is,a as Ds,M as Rs,b as $s}from"./volume-x-Chtf_bSj.js";import{C as Yt}from"./chevron-left-BWpgclqc.js";import{C as ht}from"./chevron-right-COqGruhh.js";import{C as ga}from"./circle-help-B8apTIdU.js";import{S as xs,b as wa,L as ya}from"./quizService-8JHQlvu9.js";import{L as Kt,C as Ht}from"./lightbulb-Ce2KQzGM.js";import{logLessonView as ja}from"./trackingService-DQ12buWG.js";import{C as ft}from"./clock-D1Ecvltm.js";import{C as Bs}from"./clipboard-check-DqBu2Pqb.js";import{C as zt}from"./circle-check-big-m1SvzGFL.js";import{s as Tt}from"./subjects-BFghB0SQ.js";import{C as va}from"./circle-check-C0FPGTrp.js";import{triggerQuizSubmitted as Na}from"./automationService-7m3RFJA3.js";import ms from"./confetti.module-C94ZD2ww.js";import{u as ka}from"./useCurriculum-DDCuCvMR.js";import{S as Sa}from"./search-Bq99THgc.js";import{F as Ca}from"./funnel-BT77sgnz.js";import{S as za}from"./sparkles-By-vFjpv.js";import"./vendor-firebase-core-CO26nNq6.js";import"./vendor-firebase-auth-BLpRW_zO.js";import"./vendor-firebase-storage-B3igpVVS.js";import"./vendor-firebase-analytics-CTiUNb0-.js";import"./vendor-radix-BorKzPz9.js";import"./vendor-charts-D8hf8tI0.js";import"./vendor-markdown-yqZQ_iQm.js";import"./useSubjectAvailability-Bvu3fXaT.js";import"./chevron-up-Cdvz2TMJ.js";import"./chart-column-B3jJOD5i.js";/** +const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/vendor-firebase-auth-Bcpr4O6E.js","assets/vendor-firebase-core-DCQrgkxC.js"])))=>i.map(i=>d[i]); +import{r as s,j as e,b as ut,d as Ae}from"./vendor-react-B4AQeu28.js";import{u as Gs}from"./useQuery-CNXEt8jj.js";import{getDoc as Ot,doc as bt,onSnapshot as Gt,runTransaction as Vs,serverTimestamp as Ys,query as Ks,where as Zs,collection as Js}from"./vendor-firebase-firestore-CP9q7ISf.js";import{e as me,m as v,Z as Re,C as mt,g as $e,Q as As,M as ea,b as pt,T as Pt,q as Oe,$ as Es,R as Ps,z as Ct,_ as Lt,B as ns,I as ta,l as It,A as Ft,a as Je,k as At,w as Ts,r as sa,a5 as is,a6 as aa,a7 as os,a8 as ra,a9 as la,L as Vt,h as We,x as na,aa as ia,ab as oa,ac as Ls,ad as ca,ae as da,af as xa,a3 as ma,v as ua,ag as cs,ah as pa,ai as ds,G as ha,a1 as fa,n as Bt,a4 as ba}from"./index-uASBzalf.js";import{M as Wt}from"./ModuleFolderCard-Du9VPsWG.js";import{B as ze}from"./button-BPmLcOpC.js";import Is from"./ScientificCalculator-DNPhV2R9.js";import{C as lt}from"./check-Dk6iwDFI.js";import{X as De}from"./x-CBb03rh3.js";import{V as Fs,a as Ds,M as Rs,b as $s}from"./volume-x-b1BHmkg3.js";import{C as Yt}from"./chevron-left-CzSo_K0d.js";import{C as ht}from"./chevron-right-U0AqPOPj.js";import{C as ga}from"./circle-help-PS1uII8x.js";import{P as Bs,A as Ut,b as Xt,c as wa,L as ya}from"./quizService-D738RDcZ.js";import{L as Kt,C as Ht}from"./lightbulb-CtjAK_uP.js";import{logLessonView as ja}from"./trackingService-B7l_om1u.js";import{C as ft}from"./clock-8t0UYgg3.js";import{C as Hs}from"./clipboard-check-RuPght2T.js";import{C as zt}from"./circle-check-big-BNRlH5pv.js";import{s as Tt}from"./subjects-F8wTuRgo.js";import{C as va}from"./circle-check-C5Psopk3.js";import{triggerQuizSubmitted as Na}from"./automationService-rXKxA-Jx.js";import xs from"./confetti.module-C94ZD2ww.js";import{u as ka}from"./useCurriculum-DZVkK6Ec.js";import{S as Sa}from"./search-Col42W4Q.js";import{F as Ca}from"./funnel-CSHS_tp4.js";import{S as za}from"./sparkles-DHVr5IP1.js";import"./vendor-firebase-core-DCQrgkxC.js";import"./vendor-firebase-auth-Bcpr4O6E.js";import"./vendor-firebase-storage-dc5X5yTv.js";import"./vendor-firebase-analytics-CHPyhRzk.js";import"./vendor-radix-xDOIcVzp.js";import"./vendor-charts-Ckgeb0nY.js";import"./vendor-markdown-yqZQ_iQm.js";import"./useSubjectAvailability-jmWCWhoq.js";import"./chevron-up-BpMhRyJp.js";import"./chart-column-CLoxLorp.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 _a=[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]],Ut=ie("arrow-left",_a);/** + */const _a=[["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"}]],Ma=me("binary",_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 Ma=[["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"}]],Aa=ie("binary",Ma);/** + */const Aa=[["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"}]],ms=me("book-user",Aa);/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. - */const Ea=[["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"}]],us=ie("book-user",Ea);/** + */const Ea=[["path",{d:"m19 21-7-4-7 4V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16z",key:"1fy3hk"}]],us=me("bookmark",Ea);/** * @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 Pa=[["path",{d:"m19 21-7-4-7 4V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16z",key:"1fy3hk"}]],ps=ie("bookmark",Pa);/** + */const Pa=[["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"}]],ps=me("box",Pa);/** * @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 Ta=[["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"}]],hs=ie("box",Ta);/** + */const Ta=[["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"}]],hs=me("braces",Ta);/** * @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 La=[["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"}]],fs=ie("braces",La);/** + */const La=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]],fs=me("circle",La);/** * @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=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]],bs=ie("circle",Fa);/** + */const Ia=[["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"}]],Qt=me("divide",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 Ia=[["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"}]],Qt=ie("divide",Ia);/** + */const Fa=[["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"}]],bs=me("hash",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 Da=[["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=ie("hash",Da);/** + */const Da=[["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"}]],Ra=me("key",Da);/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. - */const Ra=[["path",{d:"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"}]],$a=ie("key",Ra);/** + */const $a=[["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"}]],Ba=me("notebook-pen",$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 Ba=[["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"}]],Ha=ie("notebook-pen",Ba);/** + */const Ha=[["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"}]],gs=me("percent",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 Qa=[["path",{d:"M15.707 21.293a1 1 0 0 1-1.414 0l-1.586-1.586a1 1 0 0 1 0-1.414l5.586-5.586a1 1 0 0 1 1.414 0l1.586 1.586a1 1 0 0 1 0 1.414z",key:"nt11vn"}],["path",{d:"m18 13-1.375-6.874a1 1 0 0 0-.746-.776L3.235 2.028a1 1 0 0 0-1.207 1.207L5.35 15.879a1 1 0 0 0 .776.746L13 18",key:"15qc1e"}],["path",{d:"m2.3 2.3 7.286 7.286",key:"1wuzzi"}],["circle",{cx:"11",cy:"11",r:"2",key:"xmgehs"}]],Xt=ie("pen-tool",Qa);/** + */const Qa=[["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"}]],qa=me("ruler",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=[["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"}]],ws=ie("percent",Oa);/** + */const Oa=[["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"}]],Wa=me("scaling",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 qa=[["polygon",{points:"6 3 20 12 6 21 6 3",key:"1oa8hb"}]],Hs=ie("play",qa);/** + */const Ua=[["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"}]],ws=me("sigma",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 Wa=[["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"}]],Ua=ie("ruler",Wa);/** + */const Xa=[["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"}]],qt=me("square-function",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 Xa=[["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"}]],Ga=ie("scaling",Xa);/** + */const Ga=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]],ys=me("square",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 Va=[["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"}]],ys=ie("sigma",Va);/** + */const Va=[["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"}]],Ya=me("timer",Va);/** * @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=[["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"}]],Ot=ie("square-function",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=[["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"}]],Za=ie("timer",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=[["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"}]],js=ie("triangle",Ja);function er(t){let a=t>>>0;return()=>{a+=1831565813;let l=Math.imul(a^a>>>15,a|1);return l^=l+Math.imul(l^l>>>7,l|61),((l^l>>>14)>>>0)/4294967296}}function tr(t,a){const l=[...t],o=er(a);for(let n=l.length-1;n>0;n--){const r=Math.floor(o()*(n+1));[l[n],l[r]]=[l[r],l[n]]}return l}function Zt(t){const a=t??new Date;return new Intl.DateTimeFormat("en-CA",{timeZone:"Asia/Manila",year:"numeric",month:"2-digit",day:"2-digit"}).format(a)}function Jt(t){const a=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(a),o=n=>parseInt(l.find(r=>r.type===n)?.value??"0",10);return new Date(o("year"),o("month")-1,o("day"),o("hour"),o("minute"),o("second"))}function es(t){const a=Jt(),l=a.getFullYear(),o=(a.getDay()+6)%7,n=new Date(a);n.setDate(a.getDate()-o+3);const r=new Date(n.getFullYear(),0,1),i=Math.floor((n.getTime()-r.getTime())/(1440*60*1e3)),x=Math.floor(i/7)+1;return l*100+x}function ts(t){return(Jt().getDay()+6)%7}function sr(t){const a=new Date,l=480*60*1e3,o=a.getTime()+l,r=(new Date(o).getUTCDay()+6)%7,i=r===0?7:7-r,p=o-o%(1440*60*1e3)+i*24*60*60*1e3;return new Date(p-l)}const ar=[{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 rr(t){return tr(ar,t).slice(0,7).map((o,n)=>({...o,day:n}))}function ss(){return rr(es())}function lr(){const t=ss(),a=ts();return t[a]}const vs=({value:t,label:a,delay:l=0,icon:o})=>{const[n,r]=Ae.useState(0);return Ae.useEffect(()=>{if(t<=0)return;const i=1e3,x=30,p=Math.abs(Math.floor(i/x));let b=0;const g=setTimeout(()=>{const M=setInterval(()=>{b+=Math.max(1,Math.floor(t/x)),b>=t?(r(t),clearInterval(M)):r(b)},p);return()=>clearInterval(M)},l);return()=>clearTimeout(g)},[t,l]),t<0?null:e.jsxs(v.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:[o,a]}),e.jsxs("div",{className:"text-xl font-black text-purple-600 tabular-nums",children:["+",n]})]})},nr=({viewportHeight:t})=>{const a=Ae.useMemo(()=>[...Array(40)].map((l,o)=>({id:o,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:a.map(l=>e.jsx(v.div,{className:"absolute w-0.5 h-16 bg-blue-400/40 rounded-full",style:{left:l.left,top:"-10%"},animate:{y:[0,t*1.2]},transition:{duration:l.duration,ease:"linear",delay:l.delay}},l.id))})},ir=({viewportHeight:t,viewportWidth:a})=>{const l=Ae.useMemo(()=>[...Array(30)].map((o,n)=>({id:n,xShift:(Math.random()-.5)*a*.8,yShift:(Math.random()-.5)*t*.8,scale:Math.random()*1.5+.5,duration:2+Math.random()*1.5,delay:Math.random()*.35})),[t,a]);return e.jsx("div",{className:"absolute inset-0 pointer-events-none z-[250] overflow-hidden flex items-center justify-center",children:l.map(o=>e.jsx(v.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,o.yShift],x:[0,o.xShift],scale:[0,o.scale,0],opacity:[0,1,0]},transition:{duration:o.duration,ease:"easeOut",delay:o.delay}},o.id))})},or=()=>{const t=Ae.useMemo(()=>[...Array(60)].map((a,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.jsxs("div",{className:"absolute inset-0 pointer-events-none z-[250] overflow-hidden",children:[e.jsx("style",{children:` + */const Ka=[["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"}]],js=me("triangle",Ka);function Za(t){let a=t>>>0;return()=>{a+=1831565813;let l=Math.imul(a^a>>>15,a|1);return l^=l+Math.imul(l^l>>>7,l|61),((l^l>>>14)>>>0)/4294967296}}function Ja(t,a){const l=[...t],o=Za(a);for(let n=l.length-1;n>0;n--){const r=Math.floor(o()*(n+1));[l[n],l[r]]=[l[r],l[n]]}return l}function Zt(t){const a=t??new Date;return new Intl.DateTimeFormat("en-CA",{timeZone:"Asia/Manila",year:"numeric",month:"2-digit",day:"2-digit"}).format(a)}function Jt(t){const a=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(a),o=n=>parseInt(l.find(r=>r.type===n)?.value??"0",10);return new Date(o("year"),o("month")-1,o("day"),o("hour"),o("minute"),o("second"))}function es(t){const a=Jt(),l=a.getFullYear(),o=(a.getDay()+6)%7,n=new Date(a);n.setDate(a.getDate()-o+3);const r=new Date(n.getFullYear(),0,1),i=Math.floor((n.getTime()-r.getTime())/(1440*60*1e3)),x=Math.floor(i/7)+1;return l*100+x}function ts(t){return(Jt().getDay()+6)%7}function er(t){const a=new Date,l=480*60*1e3,o=a.getTime()+l,r=(new Date(o).getUTCDay()+6)%7,i=r===0?7:7-r,p=o-o%(1440*60*1e3)+i*24*60*60*1e3;return new Date(p-l)}const tr=[{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 sr(t){return Ja(tr,t).slice(0,7).map((o,n)=>({...o,day:n}))}function ss(){return sr(es())}function ar(){const t=ss(),a=ts();return t[a]}const vs=({value:t,label:a,delay:l=0,icon:o})=>{const[n,r]=Ae.useState(0);return Ae.useEffect(()=>{if(t<=0)return;const i=1e3,x=30,p=Math.abs(Math.floor(i/x));let b=0;const g=setTimeout(()=>{const M=setInterval(()=>{b+=Math.max(1,Math.floor(t/x)),b>=t?(r(t),clearInterval(M)):r(b)},p);return()=>clearInterval(M)},l);return()=>clearTimeout(g)},[t,l]),t<0?null:e.jsxs(v.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:[o,a]}),e.jsxs("div",{className:"text-xl font-black text-purple-600 tabular-nums",children:["+",n]})]})},rr=({viewportHeight:t})=>{const a=Ae.useMemo(()=>[...Array(40)].map((l,o)=>({id:o,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:a.map(l=>e.jsx(v.div,{className:"absolute w-0.5 h-16 bg-blue-400/40 rounded-full",style:{left:l.left,top:"-10%"},animate:{y:[0,t*1.2]},transition:{duration:l.duration,ease:"linear",delay:l.delay}},l.id))})},lr=({viewportHeight:t,viewportWidth:a})=>{const l=Ae.useMemo(()=>[...Array(30)].map((o,n)=>({id:n,xShift:(Math.random()-.5)*a*.8,yShift:(Math.random()-.5)*t*.8,scale:Math.random()*1.5+.5,duration:2+Math.random()*1.5,delay:Math.random()*.35})),[t,a]);return e.jsx("div",{className:"absolute inset-0 pointer-events-none z-[250] overflow-hidden flex items-center justify-center",children:l.map(o=>e.jsx(v.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,o.yShift],x:[0,o.xShift],scale:[0,o.scale,0],opacity:[0,1,0]},transition:{duration:o.duration,ease:"easeOut",delay:o.delay}},o.id))})},nr=()=>{const t=Ae.useMemo(()=>[...Array(60)].map((a,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.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; } @@ -109,19 +99,19 @@ import{r as s,j as e,b as ut,d as Ae}from"./vendor-react-B4AQeu28.js";import{u a animation-timing-function: linear; animation-fill-mode: forwards; } - `}),t.map(a=>e.jsx("div",{className:"confetti-piece absolute",style:{left:a.left,top:"-10%",backgroundColor:a.backgroundColor,width:a.size,height:a.size,borderRadius:a.borderRadius,animationDuration:`${a.duration}s`,animationDelay:`${a.delay}s`}},a.id))]})},cr=({lesson:t,questions:a,onComplete:l,onBack:o})=>{const[n,r]=s.useState(0),[i,x]=s.useState(0),[p,b]=s.useState(null),[g,M]=s.useState(""),[z,d]=s.useState(!1),[A,N]=s.useState(!1),[_,R]=s.useState(0),[m,y]=s.useState(0),[j,E]=s.useState(0),[k,U]=s.useState(!1),[q,Y]=s.useState([]),[$,te]=s.useState(!1),[xe,_e]=s.useState(!1),[re,W]=s.useState(null),[Z,ge]=s.useState(null),[K,we]=s.useState(!1),[Me,F]=s.useState(!1),[u,P]=s.useState(!1),[f,T]=s.useState(!1),[I,ee]=s.useState(!1),[ne,Be]=s.useState(typeof window<"u"?window.innerHeight:800),[gt,Ue]=s.useState(typeof window<"u"?window.innerWidth:1200),[et,je]=s.useState([]),[nt]=s.useState(Date.now()),[_t,Xe]=s.useState(0),[wt,Ge]=s.useState(!1),[tt,it]=s.useState(!0),[He,Ve]=s.useState(!1),[ye,ve]=s.useState(!1),[Ne,st]=s.useState(!1),[Qe,ot]=s.useState(!1),[Ye,Ke]=s.useState(0),[c,D]=s.useState({}),[X,le]=s.useState(5),[L,ke]=s.useState(15),[Se,Le]=s.useState(null),[oe,ue]=s.useState(!1),[at,Fe]=s.useState(900*1e3),[fe,yt]=s.useState({}),[pe,Mt]=s.useState({}),[jt,ct]=s.useState(!1),[vt,ce]=s.useState(!1),[se,dt]=s.useState(null),[S]=s.useState(Array.from({length:15},(w,C)=>({id:C,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)]}))),h=a[i],H=i{if(tt)try{const C=window.AudioContext||window.webkitAudioContext;if(!C)return;const O=new C,V=O.currentTime,de=(J,G,ae,Pe=.1,xt="sine")=>{const Ze=O.createOscillator(),rt=O.createGain();Ze.type=xt,Ze.frequency.value=J,rt.gain.setValueAtTime(0,G),rt.gain.linearRampToValueAtTime(Pe,G+.05),rt.gain.exponentialRampToValueAtTime(.001,G+ae),Ze.connect(rt),rt.connect(O.destination),Ze.start(G),Ze.stop(G+ae)};w==="correct"?(de(880,V,.1,.1,"sine"),de(1108.73,V+.1,.2,.1,"sine")):w==="incorrect"?(de(300,V,.2,.05,"sawtooth"),de(250,V+.15,.3,.05,"sawtooth")):w==="streak"?(de(440,V,.1,.05,"square"),de(554.37,V+.1,.1,.05,"square"),de(659.25,V+.2,.1,.05,"square"),de(880,V+.3,.4,.05,"square")):w==="complete"&&(de(523.25,V,.1,.1),de(659.25,V+.15,.1,.1),de(783.99,V+.3,.1,.1),de(1046.5,V+.45,.5,.1))}catch{}};s.useEffect(()=>{const w=()=>{Be(window.innerHeight),Ue(window.innerWidth)};return window.addEventListener("resize",w),()=>window.removeEventListener("resize",w)},[]),s.useEffect(()=>{if(h?.type==="multiple-choice"&&h.options){const w=h.options.map((C,O)=>({id:`${h.id}-${O}`,text:C}));for(let C=w.length-1;C>0;C--){const O=Math.floor(Math.random()*(C+1));[w[C],w[O]]=[w[O],w[C]]}Y(w)}else Y([])},[n,h]),s.useEffect(()=>{ve(!1),st(!1)},[n]);const Ee=()=>{document.fullscreenElement?(document.exitFullscreen().catch(()=>{}),Ve(!1)):(document.documentElement.requestFullscreen().catch(()=>{}),Ve(!0))},he=()=>st(w=>!w);s.useEffect(()=>{const w=C=>{C.key==="Enter"&&(!z&&Ie()?Oe():z&&Nt())};return window.addEventListener("keypress",w),()=>window.removeEventListener("keypress",w)},[z,p,g]),s.useEffect(()=>{L===0&&!Se&&(Le(Date.now()),ue(!0))},[L,Se]),s.useEffect(()=>{if(!oe||!Se)return;const w=setInterval(()=>{const C=Date.now()-Se,O=Math.max(0,900*1e3-C);Fe(O)},1e3);return()=>clearInterval(w)},[oe,Se]);const Ie=()=>h.type==="fill-in-blank"?g.trim().length>0:p!==null,be=()=>{if(X<=0||z||fe[n]||Ne)return;const w=c[n]||[],C=q.filter(V=>V.text!==h.correctAnswer).filter(V=>!w.includes(V.text));if(C.length===0)return;const O=C[Math.floor(Math.random()*C.length)];D(V=>({...V,[n]:[...w,O.text]})),le(V=>Math.max(0,V-1)),Ke(V=>Math.max(0,V-5)),Ce("correct")},me=()=>{fe[n]||z||Ne||(yt(w=>({...w,[n]:!0})),ve(!0))},Oe=w=>{if($||iae.id===p);O=G?G.text:""}else{te(!1);return}C=O===h.correctAnswer}if(!C){ct(!0),Ce("incorrect"),setTimeout(()=>ct(!1),500),ke(ae=>Math.max(0,ae-1)),y(0);const G=[...pe[n]||[],O];if(Mt(ae=>({...ae,[n]:G})),h.type==="multiple-choice"||h.type==="true-false"){const ae=h.options?h.options.length-1:1;G.length>=ae&&(N(!1),d(!0),je(Pe=>{const xt=[...Pe];return xt[i]=!1,xt}))}else G.length>=3&&(N(!1),d(!0),je(ae=>{const Pe=[...ae];return Pe[i]=!1,Pe}));te(!1);return}N(!0),d(!0),je(G=>{const ae=[...G];return ae[i]=!0,ae});const de=(c[n]||[]).length>0?5:10;Ke(G=>G+de),R(G=>G+1);const J=m+1;if(y(J),E(Math.max(j,J)),J===2?dt("streak"):J===3&&ls<2?dt("multiplier2"):J===5&&ls<3&&dt("multiplier3"),J>0&&J%3===0){const G=J*5;Xe(ae=>ae+G),Ce("streak")}else Ce("correct");ot(!0),setTimeout(()=>{ot(!1),dt(null),setTimeout(()=>Nt(),500)},1200),Lt(()=>import("./confetti.module-C94ZD2ww.js"),[]).then(G=>{G.default({particleCount:30,spread:40,colors:["#75D06A","#6ED1CF"],origin:{y:.6}})}).finally(()=>te(!1))},Nt=()=>{nw+1),x(w=>w+1),d(!1),b(null),M(""),N(!1)):Us()},Us=()=>{const w=Math.round(_/a.length*100);U(!0),w>=80||(w>=50?(T(!0),setTimeout(()=>T(!1),5e3)):(P(!0),setTimeout(()=>P(!1),5e3))),Ce("complete")},rs=Q==="quiz"?{gradient:"bg-gradient-to-br from-[#7274ED] via-[#9956DE] to-[#7274ED]"}:{gradient:"bg-gradient-to-br from-[#75D06A] via-[#6ED1CF] to-[#75D06A]"},Rt=(()=>{const w=B.toLowerCase();return w.includes("geometry")||w.includes("shape")?[js,bs,xs,hs,Ua,Ga]:w.includes("algebra")||w.includes("equation")?[De,Qt,fs,Ot,mt,ws]:w.includes("calculus")||w.includes("derivative")||w.includes("integral")?[ys,Ot,Pt,mt,Qt,fs]:w.includes("statistics")||w.includes("probability")?[qe,Pt,hs,bs,js,xs]:[mt,ys,Qt,ws,Ot,Aa]})();Rt[0];const ls=Math.min(2,1+m*.1);if(k){const w=Math.round(_/a.length*100),C=w>=80,O=w>=50&&w<80,V=Q==="quiz"?100:50,de=Math.round(_/a.length*100),J=V+de+_t,G=document.getElementById("modal-root"),ae=e.jsxs("div",{className:"fixed inset-0 z-[200] flex items-center justify-center p-4 bg-slate-900/40",children:[f&&e.jsx(ir,{viewportHeight:ne,viewportWidth:gt}),u&&e.jsx(nr,{viewportHeight:ne}),C&&e.jsx(or,{}),e.jsxs(v.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(v.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(v.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 ${C?"text-emerald-500":O?"text-amber-500":"text-rose-500"}`,children:C?"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: ",_,"/",a.length]}),e.jsx(v.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(vs,{value:_,label:"Correct Answers",delay:500,icon:e.jsx(lt,{size:14,className:"h-3 w-3 text-emerald-500"})}),e.jsx(vs,{value:Ye,label:"Total XP Earned",delay:800,icon:e.jsx(Re,{size:14,className:"h-3 w-3 text-amber-500"})}),e.jsxs(v.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:[w,"%"]})]})]})]})}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(ze,{size:"lg",onClick:()=>{r(0),x(0),b(null),M(""),R(0),y(0),E(0),Ke(0),je([]),d(!1),N(!1),U(!1),D({}),yt({}),Mt({}),ee(!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(ze,{size:"lg",onClick:()=>l(w,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:"BACK TO MODULE"})]})]})]});return ut.createPortal(ae,G)}return e.jsxs(e.Fragment,{children:[vt&&ut.createPortal(e.jsx(v.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(mt,{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(De,{size:12})})]}),e.jsx(Fs,{isOpen:!0,onClose:()=>ce(!1),inline:!0})]})}),document.getElementById("modal-root")),oe&&ut.createPortal(e.jsx("div",{className:"fixed inset-0 z-[200] flex items-center justify-center p-4 bg-slate-900/50",children:e.jsxs(v.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(v.div,{animate:{scale:[1,1.1,1]},transition:{duration:1,repeat:1/0},className:"text-6xl mb-4",children:"💔"}),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(at/6e4),":",Math.floor(at%6e4/1e3).toString().padStart(2,"0")]})," (15 minutes per heart)"]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(ze,{onClick:o,className:"w-full py-3 bg-rose-500 hover:bg-rose-600 text-white font-bold rounded-full",children:"Exit Quiz"}),e.jsx(ze,{onClick:()=>{ue(!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($e,{children:[K&&Z&&e.jsx(v.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:Z})},"popup"),Qe&&e.jsx(v.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 ${A?"text-emerald-500":"text-rose-500"}`,children:A?"Correct!":"Incorrect"}),A?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:["+ ",(c[n]||[]).length>0?5:10," XP"]})}),se==="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(As,{size:14})," Streak Started!"]}),se==="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(Re,{size:14})," Multiplier ×2!"]}),se==="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(Re,{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: ",h.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 ${rs.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"}),Rt.map((w,C)=>e.jsx("div",{className:"absolute text-white/10",style:{top:`${10+C*15}%`,left:`${10+C*25%80}%`,transform:`rotate(${C*45}deg) scale(${1+C%3*.2})`},children:e.jsx(w,{size:48+C%2*32})},C))]}),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:()=>it(!tt),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:tt?e.jsx(Is,{size:20}):e.jsx(Ds,{size:20})}),e.jsx("button",{onClick:Ee,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:He?e.jsx(Rs,{size:20}):e.jsx($s,{size:20})}),e.jsx("button",{onClick:()=>Ge(!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(ea,{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:a.map((w,C)=>e.jsx("div",{className:`h-1.5 sm:h-2 rounded-full flex-1 transition-all ${C<=n?"bg-white shadow-[0_0_8px_rgba(255,255,255,0.8)]":"bg-white/20"}`},C))})})]}),e.jsx($e,{children:wt&&e.jsx(v.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:()=>Ge(!1),children:e.jsxs(v.div,{onClick:w=>w.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-[32px] p-6 sm:p-8 max-w-sm w-full shadow-2xl border border-slate-200 flex flex-col gap-4 text-center",children:[e.jsx("h2",{className:"text-2xl font-black text-[#0a1628]",children:"Pause Menu"}),e.jsx(ze,{onClick:()=>Ge(!1),className:"w-full py-6 rounded-2xl bg-slate-100 text-slate-700 font-bold",children:"Continue Quiz"}),e.jsx(ze,{onClick:o,className:"w-full py-6 rounded-2xl bg-red-500 text-white font-bold",children:"Exit Quiz"})]})})}),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:()=>x(w=>Math.max(0,w-1)),disabled:i===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 ${i===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(Yt,{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"}),L]}),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"}),X]}),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"})," ",m]}),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:["+ ",Ye," pts"]})]})]}),e.jsx("button",{onClick:()=>x(w=>Math.min(n,w+1)),disabled:i>=n,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 ${i>=n?"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(ht,{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(v.div,{initial:{opacity:0,x:20},animate:jt?{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 C=[{label:"New",color:"bg-blue-100 text-blue-700",icon:e.jsx(Es,{size:14,className:"mr-1.5"})},{label:"Learning",color:"bg-amber-100 text-amber-700",icon:e.jsx(Pt,{size:14,className:"mr-1.5"})},{label:"Retry",color:"bg-rose-100 text-rose-700",icon:e.jsx(Ps,{size:14,className:"mr-1.5"})},{label:"Mastered",color:"bg-emerald-100 text-emerald-700",icon:e.jsx(Ct,{size:14,className:"mr-1.5"})}][i%4];return e.jsxs("div",{className:`${C.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:[C.icon," ",C.label]})})(),e.jsx("h2",{className:"text-xl sm:text-2xl font-extrabold text-[#0a1628] leading-tight w-full",children:h.question.includes("___")?e.jsx("span",{children:h.question.split("___").map((w,C,O)=>e.jsxs(Ae.Fragment,{children:[w,C0,value:g,onChange:V=>M(V.target.value),className:`inline-block w-24 mx-2 border-b-4 outline-none text-center bg-transparent font-bold ${H?et[i]?"border-[#75D06A] text-[#75D06A]":"border-rose-500 text-rose-500":"border-[#7C3AED] text-[#7C3AED] focus:border-[#75D06A]"}`})]},C))}):h.question})]}),e.jsxs("div",{className:"w-full flex flex-col items-center",children:[(h.type==="multiple-choice"||h.type==="true-false")&&e.jsx("div",{className:"w-full grid grid-cols-1 sm:grid-cols-2 gap-3 sm:gap-5",children:(h.type==="true-false"?["True","False"]:q).map((w,C)=>{const O=typeof w=="string"?w:w.text,V=typeof w=="string"?`${h.id}-${C}`:w.id,J=(pe[i]||[]).includes(O),G=fe[i]||Ne,ae=c[n]||[],Pe=ae.includes(O),xt=ae.length,Ze=q.filter(Xs=>Xs.text!==h.correctAnswer).length,rt=i===n&&Ze>0&&xt>=Ze;let Te="bg-white hover:bg-slate-50 border-transparent text-slate-700 hover:border-slate-200",$t=!1;return rt?($t=!0,O===h.correctAnswer?Te="bg-emerald-50 border-emerald-400 text-emerald-800":J?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"):Pe?Te="bg-slate-100 border-slate-200 text-slate-400 opacity-40 line-through cursor-not-allowed":G?O===h.correctAnswer?Te="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="bg-slate-50 border-slate-200 text-slate-400 opacity-60":H?O===h.correctAnswer?Te="bg-emerald-50 border-emerald-400 text-emerald-800 shadow-[0_0_15px_rgba(16,185,129,0.2)] scale-[1.02] z-10":J?Te="bg-rose-50 border-rose-400 text-rose-800 opacity-60":Te="bg-slate-50 border-slate-200 text-slate-400 opacity-60":J?Te="bg-rose-50 border-rose-400 text-rose-800 opacity-60":p===V&&(Te="bg-purple-50 border-[#9956DE] text-[#9956DE]"),e.jsxs("button",{disabled:$t||H||J||G||Pe,onClick:()=>{$t||H||$||J||G||Pe||(b(V),Oe(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 ${Te} ${H||G||Pe?"cursor-default":"hover:shadow-md hover:-translate-y-0.5 active:translate-y-0"}`,children:[e.jsx("span",{className:"truncate pr-4",children:O}),Pe&&e.jsx(De,{size:20,className:"text-slate-400 shrink-0"}),G&&O===h.correctAnswer&&e.jsx(lt,{size:24,className:"text-emerald-500 shrink-0"}),H&&O===h.correctAnswer&&!G&&e.jsx(lt,{size:24,className:"text-emerald-500 shrink-0"}),(H||J)&&J&&e.jsx(De,{size:24,className:"text-rose-500 shrink-0"})]},V)})}),Ne&&e.jsx(v.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:h.explanation||`The correct answer is: ${h.correctAnswer}`})]})]})})]})]},i)}),e.jsxs("footer",{className:`shrink-0 relative z-[60] flex flex-col items-center justify-center p-4 sm:p-6 ${rs.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:Rt.slice(0,3).map((w,C)=>e.jsx("div",{className:"absolute text-white",style:{top:`${20+C*20}%`,left:`${20+C*30}%`,transform:`rotate(${C*30}deg) scale(1.5)`},children:e.jsx(w,{size:32})},C))}),e.jsx("div",{className:"relative z-10 flex flex-col gap-3",children:ix(n),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(ht,{size:20,className:"sm:w-6 sm:h-6"}),"Back to Current Question"]})]}):e.jsx(e.Fragment,{children:(()=>{const w=(c[n]||[]).length,C=q.filter(J=>J.text!==h.correctAnswer).length,O=C>0&&w>=C,V=z&&!A||fe[n]||Ne||O;if(Ne)return e.jsxs("button",{onClick:Nt,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:[n0&&!z&&!fe[n]&&!Ne&&!O;return e.jsxs("div",{className:"flex flex-wrap justify-center gap-3 sm:gap-4",children:[e.jsxs("button",{onClick:be,disabled:!de,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:me,disabled:fe[n]||z||Ne,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(ga,{size:18,className:"text-purple-500"}),"Reveal"]}),e.jsxs("button",{onClick:he,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:()=>ce(J=>!J),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 ${vt?"bg-purple-100 text-purple-600 border-purple-300":"bg-white hover:bg-slate-50 text-slate-700"}`,children:e.jsx(mt,{size:20})})]})})()})})]})]})]})};function dr(){return e.jsxs("div",{className:"rounded-2xl overflow-hidden bg-slate-900 shadow-lg",children:[e.jsx("div",{className:"relative w-full aspect-video bg-slate-800 animate-pulse"}),e.jsxs("div",{className:"px-4 py-3 bg-slate-800 space-y-2",children:[e.jsx("div",{className:"h-4 bg-slate-700 rounded w-3/4 animate-pulse"}),e.jsx("div",{className:"h-3 bg-slate-700 rounded w-1/2 animate-pulse"})]})]})}const xr=({videos:t,topic:a})=>{const[l,o]=s.useState(0);if(!t||t.length===0)return e.jsx(dr,{});const n=t[l],r=t.filter((i,x)=>x!==l);return e.jsxs("div",{className:"space-y-4",children:[e.jsx($e,{mode:"wait",children:e.jsxs(v.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.2},className:"rounded-2xl overflow-hidden bg-slate-900 shadow-lg",children:[e.jsx("div",{className:"relative w-full aspect-video",children:e.jsx("iframe",{src:`https://www.youtube.com/embed/${n.videoId}?rel=0&modestbranding=1`,title:n.title,allow:"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture",allowFullScreen:!0,className:"absolute inset-0 w-full h-full border-0"})}),e.jsxs("div",{className:"px-4 py-3 bg-slate-800",children:[e.jsx("p",{className:"text-slate-200 text-sm font-medium truncate",children:n.title}),e.jsx("p",{className:"text-slate-400 text-xs mt-0.5",children:n.channelTitle})]})]},n.videoId)}),r.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-xs text-slate-500 font-medium uppercase tracking-wide",children:"More videos"}),e.jsx("div",{className:"grid grid-cols-2 gap-3",children:r.slice(0,2).map(i=>{const x=t.findIndex(p=>p.videoId===i.videoId);return e.jsxs("button",{onClick:()=>o(x),className:"group text-left rounded-xl overflow-hidden border border-slate-200 hover:border-rose-300 hover:shadow-md transition-all duration-200 bg-white",children:[e.jsxs("div",{className:"relative aspect-video",children:[e.jsx("img",{src:i.thumbnailUrl,alt:i.title,loading:"lazy",className:"w-full h-full object-cover"}),e.jsx("div",{className:"absolute inset-0 bg-black/0 group-hover:bg-black/20 transition-colors flex items-center justify-center",children:e.jsx("div",{className:"w-8 h-8 rounded-full bg-white/90 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity shadow-sm",children:e.jsx(Hs,{size:14,className:"text-rose-500 ml-0.5"})})})]}),e.jsxs("div",{className:"p-2.5",children:[e.jsx("p",{className:"text-slate-700 text-xs font-medium line-clamp-2 leading-snug",children:i.title}),e.jsx("p",{className:"text-slate-400 text-[10px] mt-0.5 truncate",children:i.channelTitle})]})]},i.videoId)})})]})]})},mr=({lessonId:t,lessonTitle:a,topic:l,subjectId:o,competencyCode:n,onComplete:r,onQuizComplete:i,onClose:x,onContinueLearning:p})=>{const[b,g]=s.useState([]),[M,z]=s.useState(!0),[d,A]=s.useState(null),[N,_]=s.useState(0),[R,m]=s.useState(null),[y,j]=s.useState(!1),[E,k]=s.useState(!1),[U,q]=s.useState([]),[Y,$]=s.useState(!1),[te,xe]=s.useState(!1),_e=U.reduce((F,u)=>F+(u?.correct?1:0),0),re=s.useCallback(async()=>{z(!0),A(null);try{const{generateLessonQuiz:F}=await Lt(async()=>{const{generateLessonQuiz:P}=await Promise.resolve().then(()=>Cr);return{generateLessonQuiz:P}},void 0),u=await F({lessonId:t,lessonTitle:a,topic:l,subjectId:o,competencyCode:n,questionCount:10});if(u.length===0){A("No questions available for this topic.");return}g(u)}catch(F){console.error("[TryItYourselfQuiz] Generation failed:",F),A("Failed to generate quiz. Please try again.")}finally{z(!1)}},[t,a,l,o,n]);s.useEffect(()=>{if(b.length>0&&U.length>0)try{const F=U.every(u=>u!==void 0);sessionStorage.setItem(`quiz_${t}`,JSON.stringify({answers:U,currentIndex:N,questions:b,isCompleted:F}))}catch{}},[U,N,t,b]),s.useEffect(()=>{if(!te){try{const F=sessionStorage.getItem(`quiz_${t}`);if(F){const{answers:u,currentIndex:P,questions:f,isCompleted:T}=JSON.parse(F);if(u?.length&&f?.length){q(u),_(P),g(f),z(!1);const I=u[P];I&&(m(I.userAnswer),j(!0),k(I.correct)),T&&$(!0),xe(!0);return}}}catch{}re()}},[t]);const W=s.useCallback(F=>{if(y)return;const u=b[N],P=F.toLowerCase().trim(),f=u.correctAnswer?.toLowerCase().trim()||"";let T=P===f;if(!T&&u.options&&u.options.length>0){const I=u.options.map(ne=>ne.toLowerCase().trim()),ee=I.includes(P);(ee&&I.includes(f)||ee&&I.length===2)&&(T=!0)}m(F),j(!0),k(T),q(I=>{const ee=[...I];return ee[N]={correct:T,userAnswer:F},ee})},[N,y,b]),Z=()=>{if(Nu+1);const F=U[N+1];F?(m(F.userAnswer),j(!0),k(F.correct)):(m(null),j(!1),k(!1))}else{const F=U.reduce((P,f)=>P+(f?.correct?1:0),0),u=Math.round(F/b.length*100);r?.(F,b.length),i?.(u),$(!0)}},ge=()=>{if(N>0){_(u=>u-1);const F=U[N-1];F?(m(F.userAnswer),j(!0),k(F.correct)):(m(null),j(!1),k(!1))}},K=b[N],we=(N+1)/b.length*100;if(M)return e.jsx("div",{className:"bg-white rounded-2xl p-6 border border-slate-200 shadow-sm",children:e.jsxs("div",{className:"flex flex-col items-center justify-center py-8",children:[e.jsx("div",{className:"w-12 h-12 rounded-full border-4 border-rose-400 border-t-transparent animate-spin mb-4"}),e.jsx("p",{className:"text-slate-600 font-medium",children:"Generating your practice quiz..."}),e.jsx("p",{className:"text-slate-400 text-sm mt-1",children:"Creating 10 unique questions with variance"})]})});if(d)return e.jsx("div",{className:"bg-white rounded-2xl p-6 border border-slate-200 shadow-sm",children:e.jsxs("div",{className:"text-center py-6",children:[e.jsx("div",{className:"w-12 h-12 rounded-full bg-rose-100 flex items-center justify-center mx-auto mb-4",children:e.jsx(De,{className:"text-rose-500",size:24})}),e.jsx("p",{className:"text-slate-700 font-medium mb-2",children:d}),e.jsx("button",{onClick:re,className:"px-4 py-2 bg-rose-500 text-white rounded-lg font-semibold text-sm hover:bg-rose-600 transition-colors",children:"Try Again"})]})});if(!K)return null;const Me=N===b.length-1;return e.jsxs("div",{className:"bg-white rounded-2xl border border-slate-200 shadow-sm overflow-hidden",children:[e.jsxs("div",{className:"bg-gradient-to-r from-rose-500 to-orange-400 p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-white",children:[e.jsx(ns,{size:20}),e.jsx("span",{className:"font-bold",children:"Practice Quiz"})]}),e.jsxs("div",{className:"text-white/90 text-sm font-semibold",children:[_e,"/",b.length," correct"]})]}),e.jsx("div",{className:"h-2 bg-white/30 rounded-full overflow-hidden",children:e.jsx(v.div,{className:"h-full bg-white rounded-full",initial:{width:0},animate:{width:`${we}%`},transition:{duration:.3}})}),e.jsxs("div",{className:"flex justify-between text-white/80 text-xs mt-1",children:[e.jsxs("span",{children:["Question ",N+1," of ",b.length]}),e.jsxs("span",{children:[Math.round(we),"% complete"]})]})]}),e.jsxs("div",{className:"p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[N<2&&e.jsxs("span",{className:"px-2 py-0.5 bg-blue-100 text-blue-700 text-xs font-semibold rounded-full flex items-center gap-1",children:[e.jsx(Kt,{size:12})," Recall"]}),N>=2&&N<6&&e.jsxs("span",{className:"px-2 py-0.5 bg-emerald-100 text-emerald-700 text-xs font-semibold rounded-full flex items-center gap-1",children:[e.jsx(qe,{size:12})," Application"]}),N>=6&&N<9&&e.jsxs("span",{className:"px-2 py-0.5 bg-purple-100 text-purple-700 text-xs font-semibold rounded-full flex items-center gap-1",children:[e.jsx(Re,{size:12})," Mixed"]}),N===9&&e.jsxs("span",{className:"px-2 py-0.5 bg-amber-100 text-amber-700 text-xs font-semibold rounded-full flex items-center gap-1",children:[e.jsx(ns,{size:12})," Metacognitive"]}),K.type==="true-false"&&e.jsx("span",{className:"px-2 py-0.5 bg-slate-100 text-slate-700 text-xs font-semibold rounded-full uppercase tracking-wide border border-slate-200",children:"True or False"})]}),e.jsx("p",{className:"text-slate-800 text-base font-medium leading-relaxed mb-5",children:K.question}),e.jsx("div",{className:"space-y-2",children:K.type==="true-false"?e.jsxs("div",{className:"flex gap-3",children:[e.jsx("button",{onClick:()=>W("True"),disabled:y,className:`flex-1 py-4 rounded-xl font-bold text-lg transition-all ${y?R==="True"?K.correctAnswer==="True"?"bg-emerald-500 text-white":"bg-rose-500 text-white":"bg-slate-200 text-slate-400":"bg-purple-100 text-purple-700 hover:bg-purple-200"}`,children:"True"}),e.jsx("button",{onClick:()=>W("False"),disabled:y,className:`flex-1 py-4 rounded-xl font-bold text-lg transition-all ${y?R==="False"?K.correctAnswer==="False"?"bg-emerald-500 text-white":"bg-rose-500 text-white":"bg-slate-200 text-slate-400":"bg-purple-100 text-purple-700 hover:bg-purple-200"}`,children:"False"})]}):K.options?K.options.map((F,u)=>e.jsx(v.button,{whileHover:{scale:y?1:1.01},whileTap:{scale:y?1:.99},onClick:()=>W(F),disabled:y,className:` + `}),t.map(a=>e.jsx("div",{className:"confetti-piece absolute",style:{left:a.left,top:"-10%",backgroundColor:a.backgroundColor,width:a.size,height:a.size,borderRadius:a.borderRadius,animationDuration:`${a.duration}s`,animationDelay:`${a.delay}s`}},a.id))]})},ir=({lesson:t,questions:a,onComplete:l,onBack:o})=>{const[n,r]=s.useState(0),[i,x]=s.useState(0),[p,b]=s.useState(null),[g,M]=s.useState(""),[z,d]=s.useState(!1),[A,N]=s.useState(!1),[_,R]=s.useState(0),[m,y]=s.useState(0),[j,E]=s.useState(0),[k,U]=s.useState(!1),[O,Y]=s.useState([]),[$,te]=s.useState(!1),[de,_e]=s.useState(!1),[re,W]=s.useState(null),[Z,ge]=s.useState(null),[K,we]=s.useState(!1),[Me,I]=s.useState(!1),[u,P]=s.useState(!1),[f,T]=s.useState(!1),[F,ee]=s.useState(!1),[ne,Be]=s.useState(typeof window<"u"?window.innerHeight:800),[gt,Ue]=s.useState(typeof window<"u"?window.innerWidth:1200),[et,je]=s.useState([]),[nt]=s.useState(Date.now()),[_t,Xe]=s.useState(0),[wt,Ge]=s.useState(!1),[tt,it]=s.useState(!0),[He,Ve]=s.useState(!1),[ye,ve]=s.useState(!1),[Ne,st]=s.useState(!1),[Qe,ot]=s.useState(!1),[Ye,Ke]=s.useState(0),[c,D]=s.useState({}),[X,le]=s.useState(5),[L,ke]=s.useState(15),[Se,Le]=s.useState(null),[ie,ue]=s.useState(!1),[at,Ie]=s.useState(900*1e3),[fe,yt]=s.useState({}),[pe,Mt]=s.useState({}),[jt,ct]=s.useState(!1),[vt,oe]=s.useState(!1),[se,dt]=s.useState(null),[S]=s.useState(Array.from({length:15},(w,C)=>({id:C,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)]}))),h=a[i],H=i{if(tt)try{const C=window.AudioContext||window.webkitAudioContext;if(!C)return;const q=new C,V=q.currentTime,ce=(J,G,ae,Pe=.1,xt="sine")=>{const Ze=q.createOscillator(),rt=q.createGain();Ze.type=xt,Ze.frequency.value=J,rt.gain.setValueAtTime(0,G),rt.gain.linearRampToValueAtTime(Pe,G+.05),rt.gain.exponentialRampToValueAtTime(.001,G+ae),Ze.connect(rt),rt.connect(q.destination),Ze.start(G),Ze.stop(G+ae)};w==="correct"?(ce(880,V,.1,.1,"sine"),ce(1108.73,V+.1,.2,.1,"sine")):w==="incorrect"?(ce(300,V,.2,.05,"sawtooth"),ce(250,V+.15,.3,.05,"sawtooth")):w==="streak"?(ce(440,V,.1,.05,"square"),ce(554.37,V+.1,.1,.05,"square"),ce(659.25,V+.2,.1,.05,"square"),ce(880,V+.3,.4,.05,"square")):w==="complete"&&(ce(523.25,V,.1,.1),ce(659.25,V+.15,.1,.1),ce(783.99,V+.3,.1,.1),ce(1046.5,V+.45,.5,.1))}catch{}};s.useEffect(()=>{const w=()=>{Be(window.innerHeight),Ue(window.innerWidth)};return window.addEventListener("resize",w),()=>window.removeEventListener("resize",w)},[]),s.useEffect(()=>{if(h?.type==="multiple-choice"&&h.options){const w=h.options.map((C,q)=>({id:`${h.id}-${q}`,text:C}));for(let C=w.length-1;C>0;C--){const q=Math.floor(Math.random()*(C+1));[w[C],w[q]]=[w[q],w[C]]}Y(w)}else Y([])},[n,h]),s.useEffect(()=>{ve(!1),st(!1)},[n]);const Ee=()=>{document.fullscreenElement?(document.exitFullscreen().catch(()=>{}),Ve(!1)):(document.documentElement.requestFullscreen().catch(()=>{}),Ve(!0))},he=()=>st(w=>!w);s.useEffect(()=>{const w=C=>{C.key==="Enter"&&(!z&&Fe()?qe():z&&Nt())};return window.addEventListener("keypress",w),()=>window.removeEventListener("keypress",w)},[z,p,g]),s.useEffect(()=>{L===0&&!Se&&(Le(Date.now()),ue(!0))},[L,Se]),s.useEffect(()=>{if(!ie||!Se)return;const w=setInterval(()=>{const C=Date.now()-Se,q=Math.max(0,900*1e3-C);Ie(q)},1e3);return()=>clearInterval(w)},[ie,Se]);const Fe=()=>h.type==="fill-in-blank"?g.trim().length>0:p!==null,be=()=>{if(X<=0||z||fe[n]||Ne)return;const w=c[n]||[],C=O.filter(V=>V.text!==h.correctAnswer).filter(V=>!w.includes(V.text));if(C.length===0)return;const q=C[Math.floor(Math.random()*C.length)];D(V=>({...V,[n]:[...w,q.text]})),le(V=>Math.max(0,V-1)),Ke(V=>Math.max(0,V-5)),Ce("correct")},xe=()=>{fe[n]||z||Ne||(yt(w=>({...w,[n]:!0})),ve(!0))},qe=w=>{if($||iae.id===p);q=G?G.text:""}else{te(!1);return}C=q===h.correctAnswer}if(!C){ct(!0),Ce("incorrect"),setTimeout(()=>ct(!1),500),ke(ae=>Math.max(0,ae-1)),y(0);const G=[...pe[n]||[],q];if(Mt(ae=>({...ae,[n]:G})),h.type==="multiple-choice"||h.type==="true-false"){const ae=h.options?h.options.length-1:1;G.length>=ae&&(N(!1),d(!0),je(Pe=>{const xt=[...Pe];return xt[i]=!1,xt}))}else G.length>=3&&(N(!1),d(!0),je(ae=>{const Pe=[...ae];return Pe[i]=!1,Pe}));te(!1);return}N(!0),d(!0),je(G=>{const ae=[...G];return ae[i]=!0,ae});const ce=(c[n]||[]).length>0?5:10;Ke(G=>G+ce),R(G=>G+1);const J=m+1;if(y(J),E(Math.max(j,J)),J===2?dt("streak"):J===3&&ls<2?dt("multiplier2"):J===5&&ls<3&&dt("multiplier3"),J>0&&J%3===0){const G=J*5;Xe(ae=>ae+G),Ce("streak")}else Ce("correct");ot(!0),setTimeout(()=>{ot(!1),dt(null),setTimeout(()=>Nt(),500)},1200),Lt(()=>import("./confetti.module-C94ZD2ww.js"),[]).then(G=>{G.default({particleCount:30,spread:40,colors:["#75D06A","#6ED1CF"],origin:{y:.6}})}).finally(()=>te(!1))},Nt=()=>{nw+1),x(w=>w+1),d(!1),b(null),M(""),N(!1)):Us()},Us=()=>{const w=Math.round(_/a.length*100);U(!0),w>=80||(w>=50?(T(!0),setTimeout(()=>T(!1),5e3)):(P(!0),setTimeout(()=>P(!1),5e3))),Ce("complete")},rs=Q==="quiz"?{gradient:"bg-gradient-to-br from-[#7274ED] via-[#9956DE] to-[#7274ED]"}:{gradient:"bg-gradient-to-br from-[#75D06A] via-[#6ED1CF] to-[#75D06A]"},Rt=(()=>{const w=B.toLowerCase();return w.includes("geometry")||w.includes("shape")?[js,fs,ys,ps,qa,Wa]:w.includes("algebra")||w.includes("equation")?[De,Qt,hs,qt,mt,gs]:w.includes("calculus")||w.includes("derivative")||w.includes("integral")?[ws,qt,Pt,mt,Qt,hs]:w.includes("statistics")||w.includes("probability")?[Oe,Pt,ps,fs,js,ys]:[mt,ws,Qt,gs,qt,Ma]})();Rt[0];const ls=Math.min(2,1+m*.1);if(k){const w=Math.round(_/a.length*100),C=w>=80,q=w>=50&&w<80,V=Q==="quiz"?100:50,ce=Math.round(_/a.length*100),J=V+ce+_t,G=document.getElementById("modal-root"),ae=e.jsxs("div",{className:"fixed inset-0 z-[200] flex items-center justify-center p-4 bg-slate-900/40",children:[f&&e.jsx(lr,{viewportHeight:ne,viewportWidth:gt}),u&&e.jsx(rr,{viewportHeight:ne}),C&&e.jsx(nr,{}),e.jsxs(v.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(v.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(v.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 ${C?"text-emerald-500":q?"text-amber-500":"text-rose-500"}`,children:C?"EXCELLENT!":q?"GOOD JOB!":"KEEP TRYING!"}),e.jsxs("p",{className:"text-slate-400 font-bold text-[10px] mb-3 uppercase tracking-widest",children:["Quiz Complete • Score: ",_,"/",a.length]}),e.jsx(v.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(vs,{value:_,label:"Correct Answers",delay:500,icon:e.jsx(lt,{size:14,className:"h-3 w-3 text-emerald-500"})}),e.jsx(vs,{value:Ye,label:"Total XP Earned",delay:800,icon:e.jsx(Re,{size:14,className:"h-3 w-3 text-amber-500"})}),e.jsxs(v.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:[w,"%"]})]})]})]})}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(ze,{size:"lg",onClick:()=>{r(0),x(0),b(null),M(""),R(0),y(0),E(0),Ke(0),je([]),d(!1),N(!1),U(!1),D({}),yt({}),Mt({}),ee(!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(ze,{size:"lg",onClick:()=>l(w,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:"BACK TO MODULE"})]})]})]});return ut.createPortal(ae,G)}return e.jsxs(e.Fragment,{children:[vt&&ut.createPortal(e.jsx(v.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(mt,{size:14,className:"text-purple-600"})," Calculator"]}),e.jsx("button",{onClick:()=>oe(!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(De,{size:12})})]}),e.jsx(Is,{isOpen:!0,onClose:()=>oe(!1),inline:!0})]})}),document.getElementById("modal-root")),ie&&ut.createPortal(e.jsx("div",{className:"fixed inset-0 z-[200] flex items-center justify-center p-4 bg-slate-900/50",children:e.jsxs(v.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(v.div,{animate:{scale:[1,1.1,1]},transition:{duration:1,repeat:1/0},className:"text-6xl mb-4",children:"💔"}),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(at/6e4),":",Math.floor(at%6e4/1e3).toString().padStart(2,"0")]})," (15 minutes per heart)"]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(ze,{onClick:o,className:"w-full py-3 bg-rose-500 hover:bg-rose-600 text-white font-bold rounded-full",children:"Exit Quiz"}),e.jsx(ze,{onClick:()=>{ue(!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($e,{children:[K&&Z&&e.jsx(v.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:Z})},"popup"),Qe&&e.jsx(v.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 ${A?"text-emerald-500":"text-rose-500"}`,children:A?"Correct!":"Incorrect"}),A?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:["+ ",(c[n]||[]).length>0?5:10," XP"]})}),se==="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(As,{size:14})," Streak Started!"]}),se==="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(Re,{size:14})," Multiplier ×2!"]}),se==="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(Re,{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: ",h.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 ${rs.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"}),Rt.map((w,C)=>e.jsx("div",{className:"absolute text-white/10",style:{top:`${10+C*15}%`,left:`${10+C*25%80}%`,transform:`rotate(${C*45}deg) scale(${1+C%3*.2})`},children:e.jsx(w,{size:48+C%2*32})},C))]}),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:()=>it(!tt),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:tt?e.jsx(Fs,{size:20}):e.jsx(Ds,{size:20})}),e.jsx("button",{onClick:Ee,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:He?e.jsx(Rs,{size:20}):e.jsx($s,{size:20})}),e.jsx("button",{onClick:()=>Ge(!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(ea,{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:a.map((w,C)=>e.jsx("div",{className:`h-1.5 sm:h-2 rounded-full flex-1 transition-all ${C<=n?"bg-white shadow-[0_0_8px_rgba(255,255,255,0.8)]":"bg-white/20"}`},C))})})]}),e.jsx($e,{children:wt&&e.jsx(v.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:()=>Ge(!1),children:e.jsxs(v.div,{onClick:w=>w.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-[32px] p-6 sm:p-8 max-w-sm w-full shadow-2xl border border-slate-200 flex flex-col gap-4 text-center",children:[e.jsx("h2",{className:"text-2xl font-black text-[#0a1628]",children:"Pause Menu"}),e.jsx(ze,{onClick:()=>Ge(!1),className:"w-full py-6 rounded-2xl bg-slate-100 text-slate-700 font-bold",children:"Continue Quiz"}),e.jsx(ze,{onClick:o,className:"w-full py-6 rounded-2xl bg-red-500 text-white font-bold",children:"Exit Quiz"})]})})}),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:()=>x(w=>Math.max(0,w-1)),disabled:i===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 ${i===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(Yt,{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"}),L]}),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"}),X]}),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"})," ",m]}),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:["+ ",Ye," pts"]})]})]}),e.jsx("button",{onClick:()=>x(w=>Math.min(n,w+1)),disabled:i>=n,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 ${i>=n?"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(ht,{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(v.div,{initial:{opacity:0,x:20},animate:jt?{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 C=[{label:"New",color:"bg-blue-100 text-blue-700",icon:e.jsx(Es,{size:14,className:"mr-1.5"})},{label:"Learning",color:"bg-amber-100 text-amber-700",icon:e.jsx(Pt,{size:14,className:"mr-1.5"})},{label:"Retry",color:"bg-rose-100 text-rose-700",icon:e.jsx(Ps,{size:14,className:"mr-1.5"})},{label:"Mastered",color:"bg-emerald-100 text-emerald-700",icon:e.jsx(Ct,{size:14,className:"mr-1.5"})}][i%4];return e.jsxs("div",{className:`${C.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:[C.icon," ",C.label]})})(),e.jsx("h2",{className:"text-xl sm:text-2xl font-extrabold text-[#0a1628] leading-tight w-full",children:h.question.includes("___")?e.jsx("span",{children:h.question.split("___").map((w,C,q)=>e.jsxs(Ae.Fragment,{children:[w,C0,value:g,onChange:V=>M(V.target.value),className:`inline-block w-24 mx-2 border-b-4 outline-none text-center bg-transparent font-bold ${H?et[i]?"border-[#75D06A] text-[#75D06A]":"border-rose-500 text-rose-500":"border-[#7C3AED] text-[#7C3AED] focus:border-[#75D06A]"}`})]},C))}):h.question})]}),e.jsxs("div",{className:"w-full flex flex-col items-center",children:[(h.type==="multiple-choice"||h.type==="true-false")&&e.jsx("div",{className:"w-full grid grid-cols-1 sm:grid-cols-2 gap-3 sm:gap-5",children:(h.type==="true-false"?["True","False"]:O).map((w,C)=>{const q=typeof w=="string"?w:w.text,V=typeof w=="string"?`${h.id}-${C}`:w.id,J=(pe[i]||[]).includes(q),G=fe[i]||Ne,ae=c[n]||[],Pe=ae.includes(q),xt=ae.length,Ze=O.filter(Xs=>Xs.text!==h.correctAnswer).length,rt=i===n&&Ze>0&&xt>=Ze;let Te="bg-white hover:bg-slate-50 border-transparent text-slate-700 hover:border-slate-200",$t=!1;return rt?($t=!0,q===h.correctAnswer?Te="bg-emerald-50 border-emerald-400 text-emerald-800":J?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"):Pe?Te="bg-slate-100 border-slate-200 text-slate-400 opacity-40 line-through cursor-not-allowed":G?q===h.correctAnswer?Te="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="bg-slate-50 border-slate-200 text-slate-400 opacity-60":H?q===h.correctAnswer?Te="bg-emerald-50 border-emerald-400 text-emerald-800 shadow-[0_0_15px_rgba(16,185,129,0.2)] scale-[1.02] z-10":J?Te="bg-rose-50 border-rose-400 text-rose-800 opacity-60":Te="bg-slate-50 border-slate-200 text-slate-400 opacity-60":J?Te="bg-rose-50 border-rose-400 text-rose-800 opacity-60":p===V&&(Te="bg-purple-50 border-[#9956DE] text-[#9956DE]"),e.jsxs("button",{disabled:$t||H||J||G||Pe,onClick:()=>{$t||H||$||J||G||Pe||(b(V),qe(q))},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 ${Te} ${H||G||Pe?"cursor-default":"hover:shadow-md hover:-translate-y-0.5 active:translate-y-0"}`,children:[e.jsx("span",{className:"truncate pr-4",children:q}),Pe&&e.jsx(De,{size:20,className:"text-slate-400 shrink-0"}),G&&q===h.correctAnswer&&e.jsx(lt,{size:24,className:"text-emerald-500 shrink-0"}),H&&q===h.correctAnswer&&!G&&e.jsx(lt,{size:24,className:"text-emerald-500 shrink-0"}),(H||J)&&J&&e.jsx(De,{size:24,className:"text-rose-500 shrink-0"})]},V)})}),Ne&&e.jsx(v.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:h.explanation||`The correct answer is: ${h.correctAnswer}`})]})]})})]})]},i)}),e.jsxs("footer",{className:`shrink-0 relative z-[60] flex flex-col items-center justify-center p-4 sm:p-6 ${rs.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:Rt.slice(0,3).map((w,C)=>e.jsx("div",{className:"absolute text-white",style:{top:`${20+C*20}%`,left:`${20+C*30}%`,transform:`rotate(${C*30}deg) scale(1.5)`},children:e.jsx(w,{size:32})},C))}),e.jsx("div",{className:"relative z-10 flex flex-col gap-3",children:ix(n),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(ht,{size:20,className:"sm:w-6 sm:h-6"}),"Back to Current Question"]})]}):e.jsx(e.Fragment,{children:(()=>{const w=(c[n]||[]).length,C=O.filter(J=>J.text!==h.correctAnswer).length,q=C>0&&w>=C,V=z&&!A||fe[n]||Ne||q;if(Ne)return e.jsxs("button",{onClick:Nt,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:[n0&&!z&&!fe[n]&&!Ne&&!q;return e.jsxs("div",{className:"flex flex-wrap justify-center gap-3 sm:gap-4",children:[e.jsxs("button",{onClick:be,disabled:!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("img",{src:"/icons/quiz_key.png",alt:"Hint",className:"w-5 h-5 object-contain"}),"Hint"]}),e.jsxs("button",{onClick:xe,disabled:fe[n]||z||Ne,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(ga,{size:18,className:"text-purple-500"}),"Reveal"]}),e.jsxs("button",{onClick:he,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:()=>oe(J=>!J),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 ${vt?"bg-purple-100 text-purple-600 border-purple-300":"bg-white hover:bg-slate-50 text-slate-700"}`,children:e.jsx(mt,{size:20})})]})})()})})]})]})]})};function or(){return e.jsxs("div",{className:"rounded-2xl overflow-hidden bg-slate-900 shadow-lg",children:[e.jsx("div",{className:"relative w-full aspect-video bg-slate-800 animate-pulse"}),e.jsxs("div",{className:"px-4 py-3 bg-slate-800 space-y-2",children:[e.jsx("div",{className:"h-4 bg-slate-700 rounded w-3/4 animate-pulse"}),e.jsx("div",{className:"h-3 bg-slate-700 rounded w-1/2 animate-pulse"})]})]})}const cr=({videos:t,topic:a})=>{const[l,o]=s.useState(0);if(!t||t.length===0)return e.jsx(or,{});const n=t[l],r=t.filter((i,x)=>x!==l);return e.jsxs("div",{className:"space-y-4",children:[e.jsx($e,{mode:"wait",children:e.jsxs(v.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.2},className:"rounded-2xl overflow-hidden bg-slate-900 shadow-lg",children:[e.jsx("div",{className:"relative w-full aspect-video",children:e.jsx("iframe",{src:`https://www.youtube.com/embed/${n.videoId}?rel=0&modestbranding=1`,title:n.title,allow:"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture",allowFullScreen:!0,className:"absolute inset-0 w-full h-full border-0"})}),e.jsxs("div",{className:"px-4 py-3 bg-slate-800",children:[e.jsx("p",{className:"text-slate-200 text-sm font-medium truncate",children:n.title}),e.jsx("p",{className:"text-slate-400 text-xs mt-0.5",children:n.channelTitle})]})]},n.videoId)}),r.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-xs text-slate-500 font-medium uppercase tracking-wide",children:"More videos"}),e.jsx("div",{className:"grid grid-cols-2 gap-3",children:r.slice(0,2).map(i=>{const x=t.findIndex(p=>p.videoId===i.videoId);return e.jsxs("button",{onClick:()=>o(x),className:"group text-left rounded-xl overflow-hidden border border-slate-200 hover:border-rose-300 hover:shadow-md transition-all duration-200 bg-white",children:[e.jsxs("div",{className:"relative aspect-video",children:[e.jsx("img",{src:i.thumbnailUrl,alt:i.title,loading:"lazy",className:"w-full h-full object-cover"}),e.jsx("div",{className:"absolute inset-0 bg-black/0 group-hover:bg-black/20 transition-colors flex items-center justify-center",children:e.jsx("div",{className:"w-8 h-8 rounded-full bg-white/90 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity shadow-sm",children:e.jsx(Bs,{size:14,className:"text-rose-500 ml-0.5"})})})]}),e.jsxs("div",{className:"p-2.5",children:[e.jsx("p",{className:"text-slate-700 text-xs font-medium line-clamp-2 leading-snug",children:i.title}),e.jsx("p",{className:"text-slate-400 text-[10px] mt-0.5 truncate",children:i.channelTitle})]})]},i.videoId)})})]})]})},dr=({lessonId:t,lessonTitle:a,topic:l,subjectId:o,competencyCode:n,onComplete:r,onQuizComplete:i,onClose:x,onContinueLearning:p})=>{const[b,g]=s.useState([]),[M,z]=s.useState(!0),[d,A]=s.useState(null),[N,_]=s.useState(0),[R,m]=s.useState(null),[y,j]=s.useState(!1),[E,k]=s.useState(!1),[U,O]=s.useState([]),[Y,$]=s.useState(!1),[te,de]=s.useState(!1),_e=U.reduce((I,u)=>I+(u?.correct?1:0),0),re=s.useCallback(async()=>{z(!0),A(null);try{const{generateLessonQuiz:I}=await Lt(async()=>{const{generateLessonQuiz:P}=await Promise.resolve().then(()=>kr);return{generateLessonQuiz:P}},void 0),u=await I({lessonId:t,lessonTitle:a,topic:l,subjectId:o,competencyCode:n,questionCount:10});if(u.length===0){A("No questions available for this topic.");return}g(u)}catch(I){console.error("[TryItYourselfQuiz] Generation failed:",I),A("Failed to generate quiz. Please try again.")}finally{z(!1)}},[t,a,l,o,n]);s.useEffect(()=>{if(b.length>0&&U.length>0)try{const I=U.every(u=>u!==void 0);sessionStorage.setItem(`quiz_${t}`,JSON.stringify({answers:U,currentIndex:N,questions:b,isCompleted:I}))}catch{}},[U,N,t,b]),s.useEffect(()=>{if(!te){try{const I=sessionStorage.getItem(`quiz_${t}`);if(I){const{answers:u,currentIndex:P,questions:f,isCompleted:T}=JSON.parse(I);if(u?.length&&f?.length){O(u),_(P),g(f),z(!1);const F=u[P];F&&(m(F.userAnswer),j(!0),k(F.correct)),T&&$(!0),de(!0);return}}}catch{}re()}},[t]);const W=s.useCallback(I=>{if(y)return;const u=b[N],P=I.toLowerCase().trim(),f=u.correctAnswer?.toLowerCase().trim()||"";let T=P===f;if(!T&&u.options&&u.options.length>0){const F=u.options.map(ne=>ne.toLowerCase().trim()),ee=F.includes(P);(ee&&F.includes(f)||ee&&F.length===2)&&(T=!0)}m(I),j(!0),k(T),O(F=>{const ee=[...F];return ee[N]={correct:T,userAnswer:I},ee})},[N,y,b]),Z=()=>{if(Nu+1);const I=U[N+1];I?(m(I.userAnswer),j(!0),k(I.correct)):(m(null),j(!1),k(!1))}else{const I=U.reduce((P,f)=>P+(f?.correct?1:0),0),u=Math.round(I/b.length*100);r?.(I,b.length),i?.(u),$(!0)}},ge=()=>{if(N>0){_(u=>u-1);const I=U[N-1];I?(m(I.userAnswer),j(!0),k(I.correct)):(m(null),j(!1),k(!1))}},K=b[N],we=(N+1)/b.length*100;if(M)return e.jsx("div",{className:"bg-white rounded-2xl p-6 border border-slate-200 shadow-sm",children:e.jsxs("div",{className:"flex flex-col items-center justify-center py-8",children:[e.jsx("div",{className:"w-12 h-12 rounded-full border-4 border-rose-400 border-t-transparent animate-spin mb-4"}),e.jsx("p",{className:"text-slate-600 font-medium",children:"Generating your practice quiz..."}),e.jsx("p",{className:"text-slate-400 text-sm mt-1",children:"Creating 10 unique questions with variance"})]})});if(d)return e.jsx("div",{className:"bg-white rounded-2xl p-6 border border-slate-200 shadow-sm",children:e.jsxs("div",{className:"text-center py-6",children:[e.jsx("div",{className:"w-12 h-12 rounded-full bg-rose-100 flex items-center justify-center mx-auto mb-4",children:e.jsx(De,{className:"text-rose-500",size:24})}),e.jsx("p",{className:"text-slate-700 font-medium mb-2",children:d}),e.jsx("button",{onClick:re,className:"px-4 py-2 bg-rose-500 text-white rounded-lg font-semibold text-sm hover:bg-rose-600 transition-colors",children:"Try Again"})]})});if(!K)return null;const Me=N===b.length-1;return e.jsxs("div",{className:"bg-white rounded-2xl border border-slate-200 shadow-sm overflow-hidden",children:[e.jsxs("div",{className:"bg-gradient-to-r from-rose-500 to-orange-400 p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-white",children:[e.jsx(ns,{size:20}),e.jsx("span",{className:"font-bold",children:"Practice Quiz"})]}),e.jsxs("div",{className:"text-white/90 text-sm font-semibold",children:[_e,"/",b.length," correct"]})]}),e.jsx("div",{className:"h-2 bg-white/30 rounded-full overflow-hidden",children:e.jsx(v.div,{className:"h-full bg-white rounded-full",initial:{width:0},animate:{width:`${we}%`},transition:{duration:.3}})}),e.jsxs("div",{className:"flex justify-between text-white/80 text-xs mt-1",children:[e.jsxs("span",{children:["Question ",N+1," of ",b.length]}),e.jsxs("span",{children:[Math.round(we),"% complete"]})]})]}),e.jsxs("div",{className:"p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[N<2&&e.jsxs("span",{className:"px-2 py-0.5 bg-blue-100 text-blue-700 text-xs font-semibold rounded-full flex items-center gap-1",children:[e.jsx(Kt,{size:12})," Recall"]}),N>=2&&N<6&&e.jsxs("span",{className:"px-2 py-0.5 bg-emerald-100 text-emerald-700 text-xs font-semibold rounded-full flex items-center gap-1",children:[e.jsx(Oe,{size:12})," Application"]}),N>=6&&N<9&&e.jsxs("span",{className:"px-2 py-0.5 bg-purple-100 text-purple-700 text-xs font-semibold rounded-full flex items-center gap-1",children:[e.jsx(Re,{size:12})," Mixed"]}),N===9&&e.jsxs("span",{className:"px-2 py-0.5 bg-amber-100 text-amber-700 text-xs font-semibold rounded-full flex items-center gap-1",children:[e.jsx(ns,{size:12})," Metacognitive"]}),K.type==="true-false"&&e.jsx("span",{className:"px-2 py-0.5 bg-slate-100 text-slate-700 text-xs font-semibold rounded-full uppercase tracking-wide border border-slate-200",children:"True or False"})]}),e.jsx("p",{className:"text-slate-800 text-base font-medium leading-relaxed mb-5",children:K.question}),e.jsx("div",{className:"space-y-2",children:K.type==="true-false"?e.jsxs("div",{className:"flex gap-3",children:[e.jsx("button",{onClick:()=>W("True"),disabled:y,className:`flex-1 py-4 rounded-xl font-bold text-lg transition-all ${y?R==="True"?K.correctAnswer==="True"?"bg-emerald-500 text-white":"bg-rose-500 text-white":"bg-slate-200 text-slate-400":"bg-purple-100 text-purple-700 hover:bg-purple-200"}`,children:"True"}),e.jsx("button",{onClick:()=>W("False"),disabled:y,className:`flex-1 py-4 rounded-xl font-bold text-lg transition-all ${y?R==="False"?K.correctAnswer==="False"?"bg-emerald-500 text-white":"bg-rose-500 text-white":"bg-slate-200 text-slate-400":"bg-purple-100 text-purple-700 hover:bg-purple-200"}`,children:"False"})]}):K.options?K.options.map((I,u)=>e.jsx(v.button,{whileHover:{scale:y?1:1.01},whileTap:{scale:y?1:.99},onClick:()=>W(I),disabled:y,className:` w-full p-4 rounded-xl text-left font-medium transition-all border-2 - ${y?F===K.correctAnswer?"bg-emerald-50 border-emerald-500 text-emerald-700":F===R?"bg-rose-50 border-rose-500 text-rose-700":"bg-slate-50 border-slate-200 text-slate-500 opacity-50":"bg-slate-50 border-slate-200 text-slate-700 hover:border-rose-300 hover:bg-rose-50"} + ${y?I===K.correctAnswer?"bg-emerald-50 border-emerald-500 text-emerald-700":I===R?"bg-rose-50 border-rose-500 text-rose-700":"bg-slate-50 border-slate-200 text-slate-500 opacity-50":"bg-slate-50 border-slate-200 text-slate-700 hover:border-rose-300 hover:bg-rose-50"} `,children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:` w-7 h-7 rounded-full flex items-center justify-center text-sm font-bold shrink-0 - ${y&&F===K.correctAnswer?"bg-emerald-500 text-white":y&&F===R?"bg-rose-500 text-white":"bg-slate-200 text-slate-600"} - `,children:String.fromCharCode(65+u)}),e.jsx("span",{className:"flex-1",children:F}),y&&F===K.correctAnswer&&e.jsx(lt,{className:"text-emerald-500",size:20}),y&&F===R&&F!==K.correctAnswer&&e.jsx(De,{className:"text-rose-500",size:20})]})},u)):e.jsxs("div",{className:"space-y-3",children:[e.jsx("input",{type:"text",value:R||"",onChange:F=>!y&&m(F.target.value),onKeyDown:F=>{F.key==="Enter"&&!y&&R?.trim()?W(R.trim()):F.key==="Enter"&&y&&Z()},disabled:y,placeholder:"Type your answer and press Enter or click Submit...",className:` + ${y&&I===K.correctAnswer?"bg-emerald-500 text-white":y&&I===R?"bg-rose-500 text-white":"bg-slate-200 text-slate-600"} + `,children:String.fromCharCode(65+u)}),e.jsx("span",{className:"flex-1",children:I}),y&&I===K.correctAnswer&&e.jsx(lt,{className:"text-emerald-500",size:20}),y&&I===R&&I!==K.correctAnswer&&e.jsx(De,{className:"text-rose-500",size:20})]})},u)):e.jsxs("div",{className:"space-y-3",children:[e.jsx("input",{type:"text",value:R||"",onChange:I=>!y&&m(I.target.value),onKeyDown:I=>{I.key==="Enter"&&!y&&R?.trim()?W(R.trim()):I.key==="Enter"&&y&&Z()},disabled:y,placeholder:"Type your answer and press Enter or click Submit...",className:` w-full p-4 rounded-xl text-slate-700 font-medium border-2 transition-all ${y?E?"bg-emerald-50 border-emerald-500":"bg-rose-50 border-rose-500":"bg-slate-50 border-slate-200 focus:border-rose-400 focus:outline-none"} `}),y?e.jsx("button",{onClick:Z,className:"w-full py-3 bg-rose-500 text-white rounded-xl font-bold hover:bg-rose-600 transition-colors",children:Me?"Finish Quiz":"Next Question"}):e.jsxs("button",{onClick:()=>{R?.trim()&&W(R.trim())},disabled:!R?.trim(),className:"w-full py-3 bg-rose-500 text-white rounded-xl font-bold hover:bg-rose-600 transition-colors disabled:opacity-40 disabled:cursor-not-allowed flex items-center justify-center gap-2",children:[e.jsx(lt,{size:16}),"Submit Answer"]})]})}),e.jsx($e,{children:y&&e.jsx(v.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`mt-4 p-4 rounded-xl ${E?"bg-emerald-50 border border-emerald-200":"bg-rose-50 border border-rose-200"}`,children:e.jsxs("div",{className:"flex items-start gap-3",children:[E?e.jsx(lt,{className:"text-emerald-500 mt-0.5 shrink-0",size:20}):e.jsx(De,{className:"text-rose-500 mt-0.5 shrink-0",size:20}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:`font-bold text-sm ${E?"text-emerald-700":"text-rose-700"}`,children:E?"Correct!":"Not quite right"}),K.explanation&&e.jsx("p",{className:"text-slate-600 text-sm mt-1 leading-relaxed",children:K.explanation}),!E&&e.jsxs("p",{className:"text-rose-600 text-sm mt-1 font-medium",children:["Correct answer: ",K.correctAnswer]})]})]})})}),y&&e.jsxs("div",{className:"flex items-center justify-between mt-5 pt-4 border-t border-slate-100",children:[e.jsxs("button",{onClick:ge,disabled:N===0,className:` flex items-center gap-1 px-4 py-2 rounded-lg font-semibold text-sm transition-colors ${N===0?"text-slate-300 cursor-not-allowed":"text-slate-600 hover:bg-slate-100"} - `,children:[e.jsx(Yt,{size:18}),"Previous"]}),e.jsxs("button",{onClick:Z,className:"flex items-center gap-1 px-6 py-2.5 bg-rose-500 text-white rounded-xl font-bold text-sm hover:bg-rose-600 transition-colors shadow-md",children:[Me?"Finish":"Next",e.jsx(ht,{size:18})]})]})]}),Y&&e.jsx(v.div,{initial:{opacity:0},animate:{opacity:1},className:"fixed inset-0 bg-black/60 backdrop-blur-sm z-50 flex items-center justify-center p-4",children:e.jsxs(v.div,{initial:{scale:.9,opacity:0},animate:{scale:1,opacity:1},className:"bg-white rounded-3xl p-8 max-w-sm w-full text-center shadow-2xl",children:[e.jsx("div",{className:"w-20 h-20 rounded-full bg-gradient-to-br from-rose-400 to-orange-400 flex items-center justify-center mx-auto mb-5",children:e.jsx(Ct,{className:"text-white",size:40})}),e.jsx("h2",{className:"text-2xl font-black text-slate-800 mb-2",children:"Quiz Complete!"}),e.jsxs("p",{className:"text-slate-500 text-sm mb-6",children:["You got ",e.jsx("span",{className:"font-bold text-rose-500",children:_e})," out of ",e.jsx("span",{className:"font-bold",children:b.length})," correct"]}),e.jsx("div",{className:"mb-6",children:e.jsx("div",{className:"w-full h-4 bg-slate-100 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-gradient-to-r from-rose-400 to-orange-400 rounded-full transition-all duration-1000",style:{width:`${_e/b.length*100}%`}})})}),e.jsx("button",{onClick:()=>{$(!1),x?.(),p?.()},className:"w-full py-3 bg-rose-500 text-white rounded-xl font-bold hover:bg-rose-600 transition-colors",children:"Continue Learning"})]})})]})},ur="https://deign86-mathpulse-api-v3test.hf.space";async function Qs(t,a,l=!1){const o={"Content-Type":"application/json",...a?.headers||{}},n=ta.currentUser;if(n)try{const i=await n.getIdToken(l);i&&(o.Authorization=`Bearer ${i}`)}catch(i){throw console.error("[lessonService] Failed to get Firebase ID token:",i),new Error("Authentication failed. Please sign in again.")}const r=await fetch(`${ur}${t}`,{...a,headers:o});if(r.status===401&&n&&!l)return Qs(t,a,!0);if(!r.ok){let i;try{i=await r.json()}catch{i=await r.text()}const x=new Error(typeof i=="object"?JSON.stringify(i):i);throw x.status=r.status,x.body=i,x}return r.json()}async function pr(t){return Qs("/api/rag/lesson",{method:"POST",body:JSON.stringify(t)})}const hr="rag_lesson_";function as(t){return`${hr}${t}`}function fr(t){try{const a=sessionStorage.getItem(as(t));if(a)return JSON.parse(a)}catch{}return null}function br(t,a){try{sessionStorage.setItem(as(t),JSON.stringify(a))}catch{}}function gr(t,a,l=!0){const[o,n]=s.useState([]),[r,i]=s.useState(!0),[x,p]=s.useState(null),[b,g]=s.useState([]),[M,z]=s.useState("low"),[d,A]=s.useState(0),[N,_]=s.useState(!1),[R,m]=s.useState(void 0),[y,j]=s.useState(!1),E=s.useCallback(async()=>{if(!l||!t)return;const U=fr(t);if(U){n(U.sections),g(U.sources),z(U.retrievalBand),A(U.retrievalConfidence),_(U.needsReview),m(U.activeModel),i(!1),p(null),j(!1);return}i(!0),p(null),j(!1);try{const Y=(await Lt(()=>import("./vendor-firebase-auth-BLpRW_zO.js"),__vite__mapDeps([0,1])).then(te=>te.getAuth().currentUser))?.uid,$=await pr({...a,lessonId:t,userId:Y});n($.sections),g($.sources||[]),z($.retrievalBand),A($.retrievalConfidence),_($.needsReview),m($.activeModel),br(t,$),p(null),j(!1)}catch(q){const Y=q.status||q.response?.status,$=q.body||q.response;let te="Failed to load lesson content.",xe=!1;Y===404&&$?.error==="no_curriculum_context"?(te=$.message||"Lesson source PDF not found or not yet ingested.",xe=!0):Y===401?te="Please sign in again to access lessons.":navigator.onLine||(te="No internet connection. Please try again when online.",xe=!0),p(te),j(xe),n([])}finally{i(!1)}},[t,l,JSON.stringify(a)]);s.useEffect(()=>{E()},[E]);const k=s.useCallback(()=>{t&&sessionStorage.removeItem(as(t)),i(!0),p(null),E()},[E,t]);return{sections:o,isLoading:r,error:x,retry:k,sources:b,retrievalBand:M,retrievalConfidence:d,needsReview:N,activeModel:R,isOffline:y}}function wr(){return e.jsxs("div",{className:"fixed inset-0 z-50 flex flex-col items-center justify-center bg-slate-50 gap-5",children:[e.jsx("div",{className:"w-12 h-12 rounded-full border-4 border-rose-400 border-t-transparent animate-spin"}),e.jsxs("div",{className:"space-y-2 text-center",children:[e.jsx("p",{className:"text-slate-700 font-semibold text-base",children:"Loading lesson from DepEd curriculum..."}),e.jsx("p",{className:"text-slate-400 text-xs max-w-xs",children:"This may take a moment while the AI retrieves curriculum content."})]}),e.jsx("div",{className:"w-64 h-2 bg-slate-200 rounded-full overflow-hidden",children:e.jsx(v.div,{className:"h-full bg-rose-300 rounded-full",animate:{x:["-100%","100%"]},transition:{duration:1.2,repeat:1/0,ease:"easeInOut"},style:{width:"50%"}})})]})}function yr({message:t,onRetry:a,isOffline:l}){return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-slate-50 p-6",children:e.jsxs(v.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},className:"bg-white rounded-3xl p-8 max-w-md w-full shadow-xl border border-slate-200 text-center",children:[e.jsx("div",{className:"w-16 h-16 bg-red-50 rounded-2xl flex items-center justify-center mx-auto mb-5",children:e.jsx(Ts,{className:"text-red-500",size:32})}),e.jsx("h2",{className:"text-xl font-bold text-slate-800 mb-2",children:l?"Lesson Source Unavailable":"Failed to Load Lesson"}),e.jsx("p",{className:"text-slate-500 text-sm leading-relaxed mb-6",children:t}),e.jsxs(ze,{onClick:a,className:"w-full py-3 rounded-xl font-bold bg-rose-500 hover:bg-rose-600 text-white flex items-center justify-center gap-2",children:[e.jsx(Ps,{size:16}),"Try Again"]}),e.jsx("button",{onClick:a,className:"mt-3 text-slate-400 text-xs hover:text-slate-600 underline",children:"Retry"})]})})}function jr({section:t,sectionIndex:a,onShowSolution:l,expandedIndex:o,lesson:n,practiceQuiz:r,practiceQuizCompleted:i,practiceQuizScore:x,onStartPractice:p,lessonSpecificTopic:b,onTryItQuizComplete:g,onContinueLearning:M}){switch(t.type){case"introduction":return e.jsx("div",{className:"space-y-4",children:t.content?.trim()?e.jsx("p",{className:"text-slate-700 leading-relaxed text-base whitespace-pre-line",children:t.content}):e.jsx("p",{className:"text-slate-400 text-sm italic",children:"Introduction content is being prepared. Please proceed to the next section or try refreshing the lesson."})});case"key_concepts":return e.jsxs("div",{className:"space-y-4",children:[t.content?.trim()?e.jsx("p",{className:"text-slate-700 leading-relaxed text-base whitespace-pre-line mb-4",children: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-2",children:t.callouts.map((z,d)=>e.jsxs("div",{className:`rounded-xl p-4 border-l-4 flex items-start gap-3 ${z.type==="important"?"bg-rose-50 border-rose-400":z.type==="tip"?"bg-emerald-50 border-emerald-400":"bg-amber-50 border-amber-400"}`,children:[e.jsx(Kt,{size:18,className:z.type==="important"?"text-rose-500 mt-0.5":z.type==="tip"?"text-emerald-500 mt-0.5":"text-amber-500 mt-0.5"}),e.jsx("p",{className:"text-sm text-slate-700",children:z.text})]},d))})]});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(xr,{videos:t.videos||[],topic:n.title})]});case"worked_examples":return e.jsx("div",{className:"space-y-4",children:t.examples&&t.examples.length>0?t.examples.map((z,d)=>e.jsxs("div",{className:"bg-gradient-to-br from-rose-50 to-orange-50 rounded-2xl p-5 border border-rose-100",children:[e.jsxs("div",{className:"flex items-start gap-3 mb-3",children:[e.jsx("div",{className:"w-8 h-8 bg-rose-500 rounded-lg flex items-center justify-center flex-shrink-0",children:e.jsx(mt,{size:16,className:"text-white"})}),e.jsx("p",{className:"font-semibold text-slate-800 text-sm pt-1",children:z.problem})]}),e.jsxs("div",{className:"space-y-1.5 ml-11",children:[z.steps.map((A,N)=>e.jsxs("p",{className:"text-slate-600 text-sm",children:[N+1,". ",A]},N)),z.answer&&e.jsxs("p",{className:"text-slate-800 text-sm font-semibold mt-2 pt-2 border-t border-rose-100",children:["Answer: ",z.answer]})]})]},d)):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-2",children:t.bulletPoints&&t.bulletPoints.length>0?t.bulletPoints.map((z,d)=>e.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-xl bg-slate-50 border border-slate-100",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-rose-400 mt-2 flex-shrink-0"}),e.jsx("p",{className:"text-slate-700 text-sm leading-relaxed",children:z})]},d)):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-4",children:[r&&e.jsx("div",{className:"bg-white rounded-2xl p-5 border border-slate-200 shadow-sm",children:i?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(zt,{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 x=="number"&&e.jsxs("span",{className:"ml-2 text-emerald-600",children:[x,"%"]})]}),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",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 bg-gradient-to-br from-rose-400 to-orange-400 rounded-xl flex items-center justify-center",children:e.jsx(Re,{size:20,className:"text-white"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-bold text-slate-800",children:"Practice Quiz"}),e.jsxs("p",{className:"text-xs text-slate-500",children:[r.questions," questions · ",r.duration]})]})]}),e.jsxs("button",{onClick:p,className:"w-full sm:w-auto px-5 py-2.5 rounded-xl bg-gradient-to-r from-rose-500 to-orange-400 text-white text-sm font-bold hover:opacity-90 transition-opacity shadow-md flex items-center justify-center gap-2",children:[e.jsx(Bs,{size:16}),"Start Practice Quiz"]})]})}),e.jsx(mr,{lessonId:n.id?.toString()||"unknown",lessonTitle:n.title,topic:b||t.title||n.title,subjectId:n.subjectId,competencyCode:n.competencyCode,onComplete:(z,d)=>{},onQuizComplete:g,onClose:M,onContinueLearning:M})]});case"summary":return e.jsx("div",{className:"space-y-3",children:t.content?.trim()?e.jsx("p",{className:"text-slate-700 text-base leading-relaxed whitespace-pre-line",children: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 kt=[{type:"introduction",label:"Intro",helper:"Welcome note",icon:ft,accent:"from-[#1a85a4] to-[#126b84]",tint:"bg-[#1a85a4] text-white border-transparent",tabBg:"bg-[#1a85a4]"},{type:"key_concepts",label:"Concepts",helper:"Core ideas",icon:$a,accent:"from-[#fbab41] to-[#e0983a]",tint:"bg-[#fbab41] text-white border-transparent",tabBg:"bg-[#fbab41]"},{type:"video",label:"Video",helper:"Watch and learn",icon:Kt,accent:"from-[#e66a5e] to-[#ce5e53]",tint:"bg-[#e66a5e] text-white border-transparent",tabBg:"bg-[#e66a5e]"},{type:"worked_examples",label:"Examples",helper:"Guided solving",icon:Bs,accent:"from-[#7ec16d] to-[#71ad62]",tint:"bg-[#7ec16d] text-white border-transparent",tabBg:"bg-[#7ec16d]"},{type:"important_notes",label:"Notes",helper:"Key reminders",icon:Ha,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:It,accent:"from-[#48bca6] to-[#40a794]",tint:"bg-[#48bca6] text-white border-transparent",tabBg:"bg-[#48bca6]"}],vr=({lesson:t,lessonCompletionXP:a=10,practiceQuiz:l,practiceQuizCompleted:o=!1,practiceQuizScore:n,initialSection:r=0,onStartPractice:i,onBack:x,onComplete:p,onProgressUpdate:b,onTryItQuizComplete:g,onContinueLearning:M})=>{const{userProfile:z}=Ft(),[d,A]=s.useState(0),[N,_]=s.useState(1),[R,m]=s.useState(!1),[y,j]=s.useState(null),E={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:k,isLoading:U,error:q,retry:Y,sources:$,retrievalBand:te,activeModel:xe,isOffline:_e}=gr(t.id,E,!0),[re,W]=s.useState(null);s.useEffect(()=>{if(k.length>0){const f=k.find(T=>T.type==="introduction");if(f?.title){const I=f.title.replace(/^Introduction\s+(to|-|:|—)\s+/i,"").replace(/\s*[-:—]\s*Introduction$/i,"").replace(/\s+Introduction$/i,"").trim();I&&I.toLowerCase()!=="introduction"&&W(I)}}},[k]),s.useEffect(()=>{k.length>0&&z?.uid&&t.id&&ja(z.uid,t.id,re||t.title).catch(()=>{})},[k.length,z?.uid,t.id,re,t.title]);const Z=k.length||kt.length;if(s.useEffect(()=>{r>=0&&r{const f=k.findIndex(T=>T.type==="try_it_yourself");r===-1&&f>=0&&A(f)},[k,r]),s.useEffect(()=>{const f=Z>0?(d+1)/Z*100:0;b?.(f)},[d,Z,b]),U)return e.jsx(wr,{});if(q&&k.length===0)return e.jsx(yr,{message:q,onRetry:Y,isOffline:_e});const ge=k[d]||{type:"introduction",title:"Loading...",content:"Lesson content is loading. Please wait a moment."},K=()=>{df+1)):(!l||o)&&m(!0)},we=()=>{d>0&&(_(-1),A(f=>f-1))},Me=f=>{p(void 0,void 0,f)},F=!!(l&&!o),u=kt[d]||kt[0],P=u.icon;return 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-4 sm:px-8 py-6 relative z-40",children:e.jsxs("div",{className:"max-w-6xl mx-auto flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-4 min-w-0",children:[e.jsx("button",{onClick:x,className:"w-10 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(Ut,{size:18})}),e.jsxs("div",{className:"min-w-0 flex flex-col justify-center",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[10px] font-bold text-slate-500 uppercase tracking-widest mb-0.5",children:[e.jsx(Je,{size:12}),e.jsx("span",{children:"NOTEBOOK LESSON"}),xe&&e.jsx("span",{className:"text-slate-400 bg-slate-100 px-1.5 py-0.5 rounded font-mono",children:xe.split("/").pop()}),te==="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.jsx("h1",{className:"font-bold text-slate-800 text-sm truncate",children:t.title})]})]}),e.jsxs("div",{className:"flex items-center gap-4 flex-shrink-0",children:[e.jsxs("div",{className:"text-right",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((d+1)/Z*100),"%"]})]}),e.jsx("div",{className:"w-24 sm:w-32 h-2 bg-slate-200 rounded-full overflow-hidden",children:e.jsx(v.div,{className:"h-full bg-[#7ec16d] rounded-full",animate:{width:`${(d+1)/Z*100}%`},transition:{duration:.25}})})]})]})}),e.jsx("main",{className:"flex-1 overflow-hidden px-4 sm:px-8 pb-8 relative flex justify-center",children:e.jsxs("div",{className:"w-full max-w-5xl h-full relative flex md:pl-16",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:kt.map((f,T)=>{const I=T===d,ee=f.icon;return e.jsxs("button",{onClick:()=>{_(T>d?1:-1),A(T)},className:At("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,I?"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:At("transition-all duration-300 rounded-xl",I?"bg-white/30 p-2.5":"bg-white/20 p-2 group-hover:bg-white/30 group-hover:p-2.5"),children:e.jsx(ee,{size:I?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.jsxs("div",{className:At("flex-1 rounded-[2rem] shadow-2xl flex flex-col overflow-hidden relative z-10 transition-colors duration-500",u.tabBg),children:[e.jsxs("div",{className:"px-6 sm:px-8 py-5 flex items-center gap-4 text-white",children:[e.jsx("div",{className:"bg-white/20 p-2.5 rounded-xl shrink-0",children:e.jsx(P,{size:28,className:"text-white"})}),e.jsxs("div",{className:"flex flex-col min-w-0",children:[e.jsx("h2",{className:"text-2xl sm:text-3xl font-bold truncate",title:ge.title,children:ge.title}),e.jsx("p",{className:"text-white/90 text-sm font-medium truncate mt-0.5",title:t.title,children:t.title})]})]}),e.jsxs("div",{className:"flex-1 bg-[#fdfdfd] rounded-[1.5rem] m-2 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-12 md:left-16 w-[2px] bg-rose-300/60 pointer-events-none z-0"}),e.jsxs("div",{className:"relative z-10 flex-1 overflow-y-auto px-6 md:pl-24 md:pr-12 py-8",children:[e.jsx("div",{className:"md:hidden flex gap-2 overflow-x-auto pb-4 mb-4 [-ms-overflow-style:none] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",children:kt.map((f,T)=>{const I=T===d,ee=f.icon;return e.jsx("button",{onClick:()=>{_(T>d?1:-1),A(T)},className:At("min-w-[100px] rounded-2xl px-3 py-2 text-left transition-all duration-200",I?`${f.tabBg} text-white shadow-md`:"bg-slate-100 text-slate-600 border border-slate-200"),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ee,{size:14}),e.jsx("span",{className:"text-xs font-bold",children:f.label})]})},f.type)})}),e.jsx($e,{mode:"wait",children:e.jsxs(v.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},transition:{duration:.2},className:"space-y-6",children:[e.jsx("div",{className:"bg-white/90 backdrop-blur-sm rounded-[1.5rem] p-6 sm:p-8 shadow-sm border border-slate-100/50",children:e.jsx(jr,{section:ge,sectionIndex:d,onShowSolution:f=>j(y===f?null:f),expandedIndex:y,lesson:t,lessonSpecificTopic:re,onTryItQuizComplete:g,onContinueLearning:M})}),$.length>0&&(z?.role==="admin"||z?.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:[$.length," source",$.length>1?"s":""," used"]}),e.jsx("div",{className:"mt-2 space-y-1 pl-2",children:$.slice(0,3).map((f,T)=>e.jsxs("p",{className:"font-mono truncate",children:[f.source_file," p.",f.page," (",Math.round((f.score||0)*100),"%)"]},T))})]})]},d)})]},d)]})]})]})}),e.jsx("footer",{className:"bg-transparent px-4 sm:px-8 flex-shrink-0 relative z-40 w-full flex justify-center items-center h-20",children:e.jsxs("div",{className:"w-full max-w-5xl flex flex-col items-center",children:[e.jsxs("div",{className:"flex items-center justify-center gap-8 w-full md:ml-16",children:[e.jsxs(ze,{onClick:we,disabled:d===0,variant:"outline",className:"px-6 py-3 rounded-full font-bold 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-2",children:[e.jsx(Ut,{size:16}),"Previous"]}),e.jsxs("p",{className:"text-sm text-slate-500 font-bold tabular-nums",children:[d+1," / ",Z]}),e.jsx(ze,{onClick:K,disabled:d===Z-1&&F,className:"px-8 py-3 rounded-full font-bold text-sm bg-[#7ec16d] text-white hover:bg-[#6ab359] shadow-md transition-colors disabled:opacity-40 flex items-center gap-2",children:d===Z-1?e.jsxs(e.Fragment,{children:["Complete",e.jsx(zt,{size:16})]}):e.jsxs(e.Fragment,{children:["Next",e.jsx(pt,{size:16})]})})]}),d===Z-1&&F&&e.jsx("p",{className:"text-center text-xs font-semibold text-amber-600 mt-3 md:ml-16",children:"Complete the practice quiz first to unlock lesson completion."})]})}),e.jsx($e,{children:R&&e.jsx(v.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(v.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(zt,{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(It,{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:["+",a]})]}),e.jsxs("div",{className:"space-y-2.5",children:[e.jsx("button",{onClick:()=>Me(!0),disabled:F,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:()=>Me(!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"})]})]})})})]})},Nr=[{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 kr(t){const{lessonTitle:a,topic:l,subjectId:o,competencyCode:n,questionCount:r=6}=t,i=Sr(o)||"General Mathematics",x=t.lessonId?Math.abs(t.lessonId.split("").reduce((p,b)=>Math.imul(31,p)+b.charCodeAt(0)|0,0))%1e6:Math.floor(Math.random()*1e6);try{const p=await sa("/api/quiz/generate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({topic:l||a,subject:i,lessonTitle:a,questionCount:r,questionTypes:["multiple-choice","true-false","fill-in-blank"],difficulty:"medium",competencyCode:n,varianceSeed:x})});return!p.questions||p.questions.length===0?(console.warn("[lessonQuizService] API returned empty questions, using fallback"),Ns(r)):p.questions.map(b=>({id:b.id,type:b.type,question:b.question,options:b.options||void 0,correctAnswer:b.correctAnswer,explanation:b.explanation}))}catch(p){return console.error("[lessonQuizService] Failed to generate quiz via API:",p),console.warn("[lessonQuizService] Using fallback questions"),Ns(r)}}function Os(t){return t==="quiz"?8:6}function Sr(t){if(!t)return null;const a=t.toLowerCase();return a.includes("gen-math")||a.includes("gen_math")?"General Mathematics":a.includes("stats")||a.includes("prob")?"Statistics and Probability":a.includes("pre-calc")||a.includes("pre_calc")?"Pre-Calculus":a.includes("basic-calc")||a.includes("basic_calc")||a.includes("calculus")?"Basic Calculus":null}function Ns(t){const a=[...Nr].sort(()=>Math.random()-.5);return a.slice(0,Math.min(t,a.length)).map((l,o)=>({...l,id:o+1}))}const Cr=Object.freeze(Object.defineProperty({__proto__:null,generateLessonQuiz:kr,getQuestionCountForQuiz:Os},Symbol.toStringTag,{value:"Module"})),Et={},zr=(t,a)=>{if(Et[t]&&Et[t].length)return Et[t];const o=Array.from({length:8}).map((n,r)=>{const i=r+2,x=r+3,p=(i+x).toString();return{id:r+1,type:"multiple-choice",question:`Compute: ${i} + ${x}`,options:[p,(i*x).toString(),Math.abs(i-x).toString(),(i+x+1).toString()],correctAnswer:p,explanation:`Add ${i} and ${x} to get ${p}.`}});return Et[t]=o,o},_r=({module:t,onBack:a,onEarnXP:l,isInQuizMode:o=!1,setIsInQuizMode:n})=>{const[i,x]=s.useState(null),{userProfile:p}=Ft(),[b,g]=s.useState(null),[M,z]=s.useState(!1);s.useEffect(()=>{if(!p?.uid)return;(async()=>{try{const[P,f]=await Promise.all([qt(bt(We,"diagnosticResults",p.uid)),qt(bt(We,"competencyProfiles",p.uid))]),T=P.exists()&&P.data()?.status==="completed",I=f.exists()&&(f.data()?.overallScore??0)>0;z(T||I)}catch{z(!1)}})()},[p?.uid]);const d=s.useRef(l);s.useEffect(()=>{d.current=l},[l]);const A=s.useRef(i);s.useEffect(()=>{A.current=i},[i]),s.useEffect(()=>{try{const u=sessionStorage.getItem(`mathpulse_module_${t.id}_selectedLesson`);if(u){const{lessonId:P}=JSON.parse(u),f=t.lessons.find(T=>T.id===P);f&&x({lesson:f,type:"lesson"})}}catch{}},[]),s.useEffect(()=>{if(i?.type==="lesson"&&i.lesson)try{sessionStorage.setItem(`mathpulse_module_${t.id}_selectedLesson`,JSON.stringify({lessonId:i.lesson.id}))}catch{}else if(i===null)try{sessionStorage.removeItem(`mathpulse_module_${t.id}_selectedLesson`)}catch{}},[i,t.id]);const N=s.useMemo(()=>{const u=Number(t.id.split("-").pop());return Number.isFinite(u)&&u>0?u:1},[t.id]),_=s.useMemo(()=>{const u=t.subjectId;return u||(Tt.find(f=>f.modules.some(T=>T.id===t.id))?.id??null)},[t.id]),R=["#1FA7E1","#9956DE","#75D06A","#FFB356","#7274ED","#FF8B8B","#6ED1CF","#FB96BB"];s.useMemo(()=>{const u=t.subjectAccentColor;if(u)return u;const f=(_?Tt.find(I=>I.id===_):null)?.modules?.findIndex(I=>I.id===t.id)??0,T=f>=0?f:0;return R[T%R.length]},[t,t.id,_]),s.useEffect(()=>{if(p?.uid)return is(p.uid,g)},[p?.uid]);const m=s.useMemo(()=>_?b?.subjects?.[_]?.modulesProgress?.[t.id]??null:null,[t.id,_,b?.subjects]),[y,j]=s.useState(null),E=s.useMemo(()=>{const u=m?.lessonsCompleted??[];return new Set(u)},[m?.lessonsCompleted]),k=s.useMemo(()=>{const u=m?.quizzesCompleted??[];return new Set(u)},[m?.quizzesCompleted]),U=m?.lessonsCompleted?.length??t.lessons.filter(u=>u.completed).length,q=m?.quizzesCompleted?.length??t.quizzes.filter(u=>u.completed).length,Y=m?.progress??t.progress,$=t.lessons.length+t.quizzes.length,te=U+q;t.lessons.length&&U/t.lessons.length*100,t.quizzes.length&&q/t.quizzes.length*100;const xe=(u,P)=>{const f=b?.lessons?.[u]?.score;return typeof f=="number"&&Number.isFinite(f)?Math.max(0,Math.min(100,f)):P?100:0},_e=s.useMemo(()=>{if(!$)return 0;const u=t.lessons.reduce((f,T)=>{const I=E.has(T.id)||T.completed;return f+xe(T.id,I)},0),P=q*100;return Math.round((u+P)/$)},[E,q,t.lessons,t.quizzes.length,$,b?.lessons]),re=Y>0?Y:_e,W=s.useMemo(()=>{const u=t.quizzes.find(f=>f.type==="final"||/module\s+quiz|general\s+quiz/i.test(f.title));if(u)return u;const P=t.quizzes.find(f=>f.isStandalone===!0);return P||(t.quizzes.length?t.quizzes[0]:null)},[t.quizzes]),Z=s.useMemo(()=>{const u=new Map;t.lessons.forEach(f=>{u.set(f.id,[])});const P=t.lessons.length;return P===0||t.quizzes.forEach((f,T)=>{if(W?.id===f.id)return;const I=Math.min(T,P-1),ee=t.lessons[I];if(!ee)return;const ne=u.get(ee.id)??[];ne.push(f),u.set(ee.id,ne)}),u},[t.lessons,t.quizzes,W?.id]),ge=s.useMemo(()=>Math.max(1,Math.ceil(t.lessons.length/2)),[t.lessons.length]),K=s.useCallback(()=>{x(null),j(null)},[]),we=s.useCallback(()=>{const u=A.current?.type==="lesson"?A.current.lesson:null;if(!u)return;const P={id:`${u.id}-practice`,title:`Practice Quiz: ${u.title}`,questions:Os("practice"),duration:u.duration,completed:!1,locked:!1,type:"practice"};j(u),x({type:"quiz",quiz:P})},[]),Me=s.useCallback((u,P,f)=>{const T=A.current;if(T?.type!=="lesson"||!T.lesson)return;const I=T.lesson,ee=10;if(d.current?.(ee,`Completed "${I.title}"`),p?.uid&&_&&(async()=>{try{await aa(p.uid,_,t.id,I.id,0,ee),await os(p.uid,_,t.id,t.lessons.length,t.quizzes.length)}catch(ne){console.error("[LessonComplete] Failed to persist progress:",ne)}})(),f){const ne=t.lessons.findIndex(Be=>Be.id===I.id);ne!==-1&&ne0?x({type:"quiz",quiz:t.quizzes[0]}):x(null)}else x(null)},[_,t.id,t.lessons.length,t.quizzes.length]),F=s.useCallback(u=>{if(!p?.uid||!A.current||A.current.type!=="lesson")return;const P=A.current.lesson.id;(async()=>{try{await ra(p.uid,P,u)}catch(f){console.warn("[ModuleDetailView] Failed to persist lesson progress:",f)}})()},[p?.uid,t.id]);if(i)if(i.type==="lesson"){const u=Z.get(i.lesson.id)?.[0]??null,P=u?k.has(u.id)||u.completed:!1;return e.jsx(vr,{lesson:i.lesson,lessonCompletionXP:10,practiceQuiz:u,practiceQuizCompleted:P,initialSection:i.returnFromQuiz?-1:0,onBack:K,onStartPractice:we,onProgressUpdate:F,onComplete:Me})}else{const u=zr(i.quiz.id);return e.jsx(cr,{lesson:{id:parseInt(i.quiz.id.split("-").pop()||"1"),title:i.quiz.title,duration:i.quiz.duration,type:"quiz",completed:i.quiz.completed,locked:i.quiz.locked},questions:u,onBack:()=>{y?(x({type:"lesson",lesson:y,returnFromQuiz:!0}),j(null)):x(null),n&&n(!1)},onComplete:(P,f)=>{p?.uid&&_&&(async()=>{try{await la(p.uid,_,t.id,i.quiz.id,P,[],0,f),await os(p.uid,_,t.id,t.lessons.length,t.quizzes.length),await is(p.uid,g)}catch(T){console.warn("[Quiz] Progress persist failed:",T)}l&&l(f??0,`Quiz Complete! +${f??0} XP`)})(),y?(x({type:"lesson",lesson:y,returnFromQuiz:!0}),j(null)):x(null),n&&n(!1)}})}return e.jsxs("div",{className:"h-full overflow-y-auto scrollbar-hide px-4 sm:px-6 xl:px-10 py-6 sm:py-8 relative",children:[e.jsx("div",{className:"relative mb-6 xl:mb-8 w-full sm:w-max",children:e.jsxs("button",{onClick:a,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(Ut,{size:18}),"Back"]})}),e.jsxs(v.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 sm:p-7 md:p-10 flex flex-col md:flex-row md:items-center justify-between gap-6 md:gap-8",children:[e.jsxs("div",{className:"flex-1 text-white",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3 mb-4 md:mb-5",children:[e.jsxs("div",{className:"px-3 py-1 bg-white/10 backdrop-blur-md rounded-full text-[11px] font-black uppercase tracking-widest text-[#f8fafc] border border-white/20 shadow-sm flex items-center gap-1.5",children:[e.jsx(ps,{size:14})," Chapter ",t.id.split("-").pop()||"1"]}),e.jsxs("div",{className:"px-3 py-1 bg-white/10 backdrop-blur-md rounded-full text-[11px] font-black uppercase tracking-widest text-emerald-400 border border-emerald-400/30",children:["Lv ",N]})]}),e.jsx("h1",{className:"text-3xl md:text-4xl lg:text-5xl font-display font-black text-white mb-3 md:mb-4 tracking-[-0.02em] leading-tight",children:t.title}),e.jsx("p",{className:"text-slate-300 text-sm md:text-[15px] max-w-2xl font-medium leading-relaxed mb-6 md:mb-8",children:t.description}),e.jsxs("div",{className:"bg-black/20 backdrop-blur-md rounded-2xl p-4 md:p-5 border border-white/10 max-w-xl",children:[e.jsxs("div",{className:"flex justify-between items-end mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(It,{size:20,className:"text-emerald-400"}),e.jsx("span",{className:"text-[12px] md:text-[13px] font-black text-white uppercase tracking-wider",children:"Module Mastery"})]}),e.jsxs("div",{className:"flex items-baseline gap-2",children:[e.jsxs("span",{className:"text-[12px] md:text-[13px] font-bold text-slate-400 mb-0.5",children:[te,"/",$," steps"]}),e.jsxs("span",{className:"text-xl md:text-2xl font-black text-white shrink-0 leading-none",children:[Math.round(re),"%"]})]})]}),e.jsx("div",{className:"h-3 bg-black/40 rounded-full overflow-hidden shadow-inner ring-1 ring-white/10 p-0.5",children:e.jsx(v.div,{initial:{width:0},animate:{width:`${re}%`},transition:{duration:1.5,ease:"easeOut",delay:.2},className:`h-full rounded-full relative ${re===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-48 h-48 bg-white/5 rounded-[2rem] 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-[2rem] ${t.progress===100?"bg-gradient-to-br from-emerald-400 to-teal-600":t.accentColor}`}),re===100?e.jsx(Ct,{size:80,className:"text-white drop-shadow-xl z-10 scale-100 group-hover:scale-110 transition-transform duration-500",strokeWidth:1}):e.jsx(Je,{size:80,className:"text-white drop-shadow-xl z-10 scale-100 group-hover:scale-110 transition-transform duration-500",strokeWidth:1}),e.jsx(v.div,{animate:{y:[-5,5,-5],rotate:[-10,10,-10]},transition:{duration:4,repeat:1/0},className:"absolute top-6 left-6 text-emerald-300 z-20",children:e.jsx(Es,{size:20,fill:"currentColor"})}),e.jsx(v.div,{animate:{y:[5,-5,5],rotate:[10,-10,10]},transition:{duration:3.5,repeat:1/0},className:"absolute bottom-8 right-6 text-sky-300 z-20",children:e.jsx(gs,{size:24})})]})]})]}),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(Je,{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 ",U,"/",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 ",q,"/",t.quizzes.length]})]})]}),e.jsxs("div",{className:"relative z-10 px-4 sm:px-6 md:px-8 py-5 md:py-6 space-y-5",children:[t.lessons.map((u,P)=>{const f=E.has(u.id)||u.completed,T=xe(u.id,f),I=R[P%R.length];return e.jsxs(Ae.Fragment,{children:[e.jsxs(v.div,{initial:{opacity:0,y:14},animate:{opacity:1,y:0},transition:{delay:P*.05},className:`relative rounded-[1.5rem] border overflow-hidden group transition-all duration-500 mb-6 ${u.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(v.div,{initial:{width:0},animate:{width:`${Math.max(2,T)}%`},transition:{duration:1.2,ease:"easeOut",delay:.1+P*.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(Je,{size:40,strokeWidth:1})}),e.jsxs("div",{className:"relative z-10 p-4 md:p-5 pt-6 space-y-4",children:[e.jsxs("button",{type:"button",onClick:()=>!u.locked&&x({lesson:u,type:"lesson"}),className:`w-full text-left flex flex-wrap items-center justify-between gap-3 rounded-2xl px-5 py-4 transition shadow-sm ${u.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-4 min-w-0",children:[e.jsx("div",{className:`w-12 h-12 rounded-full flex items-center justify-center shrink-0 transition-colors shadow-sm ${u.locked?"bg-slate-100 text-slate-400":"text-white"}`,style:u.locked?{}:f?{backgroundColor:"#0ea5e9"}:{backgroundColor:I},children:u.locked?e.jsx(Vt,{size:18}):f?e.jsx(va,{size:24}):e.jsx(Hs,{size:20,className:"ml-0.5"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"text-[11px] md:text-[12px] font-black uppercase tracking-wider text-slate-500 mb-0.5",children:["Lesson ",P+1]}),e.jsx("h3",{className:"font-bold text-[16px] md:text-[18px] text-[#0a1628] truncate",children:u.title})]})]}),e.jsx("div",{className:"flex items-center justify-end",children:e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-slate-500 text-xs md:text-sm font-semibold bg-slate-100/80 px-3 py-1.5 rounded-xl",children:[e.jsx(ft,{size:14}),u.duration]})})]}),e.jsxs("div",{className:"flex flex-wrap gap-3 px-1",children:[e.jsxs("button",{type:"button",className:"inline-flex items-center gap-1.5 rounded-full bg-white px-4 py-1.5 text-[12px] font-bold shadow-sm transition hover:-translate-y-0.5",style:{color:I},children:[e.jsx(Je,{size:14})," Study Materials"]}),e.jsxs("button",{type:"button",className:"inline-flex items-center gap-1.5 rounded-full bg-white px-4 py-1.5 text-[12px] font-bold shadow-sm transition hover:-translate-y-0.5",style:{color:I},children:[e.jsx(ps,{size:14})," Quiz"]})]})]})]}),W&&P===ge-1&&e.jsxs(v.div,{initial:{opacity:0,y:16},animate:{opacity:1,y:0},transition:{delay:.15+P*.03},className:"mt-8 mb-6",children:[e.jsxs("div",{className:"flex items-center gap-4 mb-6",children:[e.jsx("div",{className:"flex-1 h-px bg-slate-200"}),e.jsx("span",{className:"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-5 shadow-lg overflow-hidden group transition-all hover:shadow-xl hover:-translate-y-1",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 gap-4 md:gap-5",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",{className:"flex-1 min-w-0",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:W.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(Xt,{size:12})," ",W.questions," Qs"]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(ft,{size:12})," ",W.duration]}),e.jsxs("span",{className:"inline-flex items-center gap-1 text-amber-300 drop-shadow-md",children:[e.jsx(Re,{size:12,className:"fill-amber-300"})," +50 XP"]})]})]}),e.jsx("button",{type:"button",onClick:()=>!W.locked&&(x({quiz:W,type:"quiz"}),n&&n(!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 ${W.locked?"bg-white/5 text-white/30 border border-white/10 cursor-not-allowed":M&&(k.has(W.id)||W.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&&(k.has(W.id)||W.completed)?"REVIEW":"START"})]})]})]})]},u.id)}),t.lessons.length===0&&W&&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:W.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(Xt,{size:12})," ",W.questions," Qs"]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(ft,{size:12})," ",W.duration]}),e.jsxs("span",{className:"inline-flex items-center gap-1 text-amber-300 drop-shadow-md",children:[e.jsx(Re,{size:12,className:"fill-amber-300"})," +50 XP"]})]})]})]}),e.jsx("button",{type:"button",onClick:()=>!W.locked&&(x({quiz:W,type:"quiz"}),n&&n(!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 ${W.locked?"bg-white/5 text-white/30 border border-white/10 cursor-not-allowed":M&&(k.has(W.id)||W.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&&(k.has(W.id)||W.completed)?"REVIEW":"START"})]})]})]})]})})]})},Mr=({onStartQuiz:t,searchQuery:a="",allowedSubjectIds:l})=>{const{userProfile:o}=Ft(),[n,r]=s.useState("all"),[i,x]=s.useState("all"),[p,b]=s.useState(null),g=s.useMemo(()=>!l||l.length===0?Tt:Tt.filter(m=>l.includes(m.id)),[l]);s.useEffect(()=>{o?.uid&&na(o.uid).then(b).catch(console.error)},[o?.uid]),s.useEffect(()=>{if(i==="all")return;g.some(y=>y.title===i)||x("all")},[g,i]);const M=p?.totalQuizzesCompleted||0,z=o?.totalXP||0,d=p?.averageScore?Math.round(p.averageScore):0,A=new Set(p?.quizAttempts?.map(m=>m.quizId)||[]),N={};if(p?.quizAttempts)for(const m of p.quizAttempts)(!N[m.quizId]||m.score>N[m.quizId])&&(N[m.quizId]=m.score);const R=g.flatMap(m=>m.modules.flatMap(y=>y.quizzes.map(j=>({id:j.id,title:j.title,subject:m.title,difficulty:j.type==="module"?"Medium":"Easy",questions:j.questions,duration:j.duration,xpReward:j.questions*5,type:j.type==="module"?"challenge":"practice",completed:A.has(j.id),bestScore:N[j.id],locked:j.locked})))).filter(m=>{const y=n==="all"||m.type===n,j=i==="all"||m.subject===i,E=!a||m.title.toLowerCase().includes(a.toLowerCase())||m.subject.toLowerCase().includes(a.toLowerCase());return y&&j&&E});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-4 mb-6",children:[e.jsxs(v.div,{whileHover:{scale:1.02},className:"bg-gradient-to-br from-sky-700 to-sky-500 rounded-2xl p-5 text-white shadow-lg",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("div",{className:"w-12 h-12 bg-white/20 rounded-xl flex items-center justify-center",children:e.jsx(It,{size:24})}),e.jsx("span",{className:"text-3xl font-bold",children:M})]}),e.jsx("p",{className:"text-sm font-medium text-sky-100",children:"Quizzes Completed"})]}),e.jsxs(v.div,{whileHover:{scale:1.02},className:"bg-gradient-to-br from-rose-500 to-rose-600 rounded-2xl p-5 text-white shadow-lg",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("div",{className:"w-12 h-12 bg-white/20 rounded-xl flex items-center justify-center",children:e.jsx(Re,{size:24})}),e.jsx("span",{className:"text-3xl font-bold",children:z.toLocaleString()})]}),e.jsx("p",{className:"text-sm font-medium text-cyan-100",children:"Total XP Earned"})]}),e.jsxs(v.div,{whileHover:{scale:1.02},className:"bg-gradient-to-br from-indigo-600 to-indigo-700 rounded-2xl p-5 text-white shadow-lg",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("div",{className:"w-12 h-12 bg-white/20 rounded-xl flex items-center justify-center",children:e.jsx(qe,{size:24})}),e.jsxs("span",{className:"text-3xl font-bold",children:[d,"%"]})]}),e.jsx("p",{className:"text-sm font-medium text-sky-100",children:"Average Score"})]})]}),e.jsxs("div",{className:"flex items-center gap-3 mb-6",children:[e.jsxs("div",{className:"flex items-center gap-2 bg-white rounded-xl p-1 shadow-sm",children:[e.jsx("button",{onClick:()=>r("all"),className:`px-4 py-2 rounded-lg text-sm font-bold transition-all ${n==="all"?"bg-sky-600 text-white shadow-md":"text-[#5a6578] hover:bg-[#edf1f7]"}`,children:"All"}),e.jsx("button",{onClick:()=>r("practice"),className:`px-4 py-2 rounded-lg text-sm font-bold transition-all ${n==="practice"?"bg-sky-500 text-white shadow-md":"text-[#5a6578] hover:bg-[#edf1f7]"}`,children:"Practice"}),e.jsx("button",{onClick:()=>r("challenge"),className:`px-4 py-2 rounded-lg text-sm font-bold transition-all ${n==="challenge"?"bg-orange-500 text-white shadow-md":"text-[#5a6578] hover:bg-[#edf1f7]"}`,children:"Challenge"}),e.jsx("button",{onClick:()=>r("mastery"),className:`px-4 py-2 rounded-lg text-sm font-bold transition-all ${n==="mastery"?"bg-sky-500 text-white shadow-md":"text-[#5a6578] hover:bg-[#edf1f7]"}`,children:"Mastery"})]}),e.jsxs("select",{value:i,onChange:m=>x(m.target.value),className:"px-4 py-2.5 bg-white border-2 border-[#dde3eb] rounded-xl text-sm font-bold text-[#0a1628] focus:border-indigo-600 focus:outline-none",children:[e.jsx("option",{value:"all",children:"All Subjects"}),g.map(m=>e.jsx("option",{value:m.title,children:m.title},m.id))]})]}),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:R.map((m,y)=>{const j=m.locked,E=m.difficulty==="Hard",k=m.type==="challenge";return e.jsx(v.div,{initial:{opacity:0,x:-20},animate:{opacity:1,x:0},transition:{delay:y*.05},onClick:()=>!j&&t?.(m),className:`bg-white/90 backdrop-blur-sm rounded-2xl p-4 md:p-5 border-2 relative select-none transition-all duration-300 ${j?"border-slate-200 opacity-60 saturate-50 cursor-not-allowed":m.completed?"border-teal-200 shadow-sm hover:border-teal-300 hover:shadow-md cursor-pointer":E?"border-indigo-200 shadow-sm hover:border-indigo-300 hover:shadow-md cursor-pointer":"border-orange-200 shadow-sm hover:border-orange-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:[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 ${j?"bg-slate-100 text-slate-400":m.completed?"bg-teal-500 text-white":E?"bg-indigo-500 text-white":"bg-orange-500 text-white"}`,children:j?e.jsx(Vt,{size:18}):m.completed?e.jsx(Ct,{size:18}):e.jsx(Xt,{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 ${E?"bg-indigo-100 text-indigo-700":k?"bg-orange-100 text-orange-700":"bg-sky-100 text-sky-700"}`,children:[m.type," ΓÇó ",m.difficulty]}),!j&&!m.completed&&e.jsx("span",{className:"w-1.5 h-1.5 md:w-2 md:h-2 rounded-full bg-rose-500 animate-pulse"})]}),e.jsx("h3",{className:`font-bold text-[14px] md:text-[16px] leading-tight mb-1 md:mb-1.5 transition-colors ${j?"text-slate-600":"text-[#0a1628]"}`,children:m.title}),e.jsx("p",{className:"text-[11px] md:text-[12px] text-slate-500 mb-1.5 line-clamp-1",children:m.subject}),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(Je,{size:12})," ",m.questions," Qs"]}),e.jsx("span",{className:"hidden sm:inline",children:"ΓÇó"}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(ft,{size:12})," ",m.duration]}),e.jsx("span",{className:"hidden sm:inline",children:"ΓÇó"}),e.jsxs("span",{className:"flex items-center gap-1 text-rose-500",children:[e.jsx(Ct,{size:12})," +",m.xpReward," XP"]})]})]})]}),e.jsxs("div",{className:"flex flex-col items-end gap-2 shrink-0",children:[m.bestScore!==void 0&&e.jsxs("div",{className:"text-right",children:[e.jsxs("div",{className:`text-xl md:text-2xl font-black leading-none ${m.bestScore>=80?"text-teal-600":"text-orange-500"}`,children:[m.bestScore,"%"]}),e.jsx("div",{className:"text-[9px] uppercase tracking-wide text-slate-400 font-bold mt-1",children:"Best Score"})]}),!j&&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.completed?"bg-white border border-slate-200 text-slate-600 group-hover:bg-slate-50":"bg-slate-900 text-white group-hover:bg-slate-600"}`,children:m.completed?"Review":"Start"})]})]})},m.id)})}),R.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 quizzes found"}),e.jsx("p",{className:"text-sm",children:"Try adjusting your filters or search query"})]})]})]})},Ar=` + `,children:[e.jsx(Yt,{size:18}),"Previous"]}),e.jsxs("button",{onClick:Z,className:"flex items-center gap-1 px-6 py-2.5 bg-rose-500 text-white rounded-xl font-bold text-sm hover:bg-rose-600 transition-colors shadow-md",children:[Me?"Finish":"Next",e.jsx(ht,{size:18})]})]})]}),Y&&e.jsx(v.div,{initial:{opacity:0},animate:{opacity:1},className:"fixed inset-0 bg-black/60 backdrop-blur-sm z-50 flex items-center justify-center p-4",children:e.jsxs(v.div,{initial:{scale:.9,opacity:0},animate:{scale:1,opacity:1},className:"bg-white rounded-3xl p-8 max-w-sm w-full text-center shadow-2xl",children:[e.jsx("div",{className:"w-20 h-20 rounded-full bg-gradient-to-br from-rose-400 to-orange-400 flex items-center justify-center mx-auto mb-5",children:e.jsx(Ct,{className:"text-white",size:40})}),e.jsx("h2",{className:"text-2xl font-black text-slate-800 mb-2",children:"Quiz Complete!"}),e.jsxs("p",{className:"text-slate-500 text-sm mb-6",children:["You got ",e.jsx("span",{className:"font-bold text-rose-500",children:_e})," out of ",e.jsx("span",{className:"font-bold",children:b.length})," correct"]}),e.jsx("div",{className:"mb-6",children:e.jsx("div",{className:"w-full h-4 bg-slate-100 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-gradient-to-r from-rose-400 to-orange-400 rounded-full transition-all duration-1000",style:{width:`${_e/b.length*100}%`}})})}),e.jsx("button",{onClick:()=>{$(!1),x?.(),p?.()},className:"w-full py-3 bg-rose-500 text-white rounded-xl font-bold hover:bg-rose-600 transition-colors",children:"Continue Learning"})]})})]})},xr="https://deign86-mathpulse-api-v3test.hf.space";async function Qs(t,a,l=!1){const o={"Content-Type":"application/json",...a?.headers||{}},n=ta.currentUser;if(n)try{const i=await n.getIdToken(l);i&&(o.Authorization=`Bearer ${i}`)}catch(i){throw console.error("[lessonService] Failed to get Firebase ID token:",i),new Error("Authentication failed. Please sign in again.")}const r=await fetch(`${xr}${t}`,{...a,headers:o});if(r.status===401&&n&&!l)return Qs(t,a,!0);if(!r.ok){let i;try{i=await r.json()}catch{i=await r.text()}const x=new Error(typeof i=="object"?JSON.stringify(i):i);throw x.status=r.status,x.body=i,x}return r.json()}async function mr(t){return Qs("/api/rag/lesson",{method:"POST",body:JSON.stringify(t)})}const ur="rag_lesson_";function as(t){return`${ur}${t}`}function pr(t){try{const a=sessionStorage.getItem(as(t));if(a)return JSON.parse(a)}catch{}return null}function hr(t,a){try{sessionStorage.setItem(as(t),JSON.stringify(a))}catch{}}function fr(t,a,l=!0){const[o,n]=s.useState([]),[r,i]=s.useState(!0),[x,p]=s.useState(null),[b,g]=s.useState([]),[M,z]=s.useState("low"),[d,A]=s.useState(0),[N,_]=s.useState(!1),[R,m]=s.useState(void 0),[y,j]=s.useState(!1),E=s.useCallback(async()=>{if(!l||!t)return;const U=pr(t);if(U){n(U.sections),g(U.sources),z(U.retrievalBand),A(U.retrievalConfidence),_(U.needsReview),m(U.activeModel),i(!1),p(null),j(!1);return}i(!0),p(null),j(!1);try{const Y=(await Lt(()=>import("./vendor-firebase-auth-Bcpr4O6E.js"),__vite__mapDeps([0,1])).then(te=>te.getAuth().currentUser))?.uid,$=await mr({...a,lessonId:t,userId:Y});n($.sections),g($.sources||[]),z($.retrievalBand),A($.retrievalConfidence),_($.needsReview),m($.activeModel),hr(t,$),p(null),j(!1)}catch(O){const Y=O.status||O.response?.status,$=O.body||O.response;let te="Failed to load lesson content.",de=!1;Y===404&&$?.error==="no_curriculum_context"?(te=$.message||"Lesson source PDF not found or not yet ingested.",de=!0):Y===401?te="Please sign in again to access lessons.":navigator.onLine||(te="No internet connection. Please try again when online.",de=!0),p(te),j(de),n([])}finally{i(!1)}},[t,l,JSON.stringify(a)]);s.useEffect(()=>{E()},[E]);const k=s.useCallback(()=>{t&&sessionStorage.removeItem(as(t)),i(!0),p(null),E()},[E,t]);return{sections:o,isLoading:r,error:x,retry:k,sources:b,retrievalBand:M,retrievalConfidence:d,needsReview:N,activeModel:R,isOffline:y}}function br(){return e.jsxs("div",{className:"fixed inset-0 z-50 flex flex-col items-center justify-center bg-slate-50 gap-5",children:[e.jsx("div",{className:"w-12 h-12 rounded-full border-4 border-rose-400 border-t-transparent animate-spin"}),e.jsxs("div",{className:"space-y-2 text-center",children:[e.jsx("p",{className:"text-slate-700 font-semibold text-base",children:"Loading lesson from DepEd curriculum..."}),e.jsx("p",{className:"text-slate-400 text-xs max-w-xs",children:"This may take a moment while the AI retrieves curriculum content."})]}),e.jsx("div",{className:"w-64 h-2 bg-slate-200 rounded-full overflow-hidden",children:e.jsx(v.div,{className:"h-full bg-rose-300 rounded-full",animate:{x:["-100%","100%"]},transition:{duration:1.2,repeat:1/0,ease:"easeInOut"},style:{width:"50%"}})})]})}function gr({message:t,onRetry:a,isOffline:l}){return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-slate-50 p-6",children:e.jsxs(v.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},className:"bg-white rounded-3xl p-8 max-w-md w-full shadow-xl border border-slate-200 text-center",children:[e.jsx("div",{className:"w-16 h-16 bg-red-50 rounded-2xl flex items-center justify-center mx-auto mb-5",children:e.jsx(Ts,{className:"text-red-500",size:32})}),e.jsx("h2",{className:"text-xl font-bold text-slate-800 mb-2",children:l?"Lesson Source Unavailable":"Failed to Load Lesson"}),e.jsx("p",{className:"text-slate-500 text-sm leading-relaxed mb-6",children:t}),e.jsxs(ze,{onClick:a,className:"w-full py-3 rounded-xl font-bold bg-rose-500 hover:bg-rose-600 text-white flex items-center justify-center gap-2",children:[e.jsx(Ps,{size:16}),"Try Again"]}),e.jsx("button",{onClick:a,className:"mt-3 text-slate-400 text-xs hover:text-slate-600 underline",children:"Retry"})]})})}function wr({section:t,sectionIndex:a,onShowSolution:l,expandedIndex:o,lesson:n,practiceQuiz:r,practiceQuizCompleted:i,practiceQuizScore:x,onStartPractice:p,lessonSpecificTopic:b,onTryItQuizComplete:g,onContinueLearning:M}){switch(t.type){case"introduction":return e.jsx("div",{className:"space-y-4",children:t.content?.trim()?e.jsx("p",{className:"text-slate-700 leading-relaxed text-base whitespace-pre-line",children:t.content}):e.jsx("p",{className:"text-slate-400 text-sm italic",children:"Introduction content is being prepared. Please proceed to the next section or try refreshing the lesson."})});case"key_concepts":return e.jsxs("div",{className:"space-y-4",children:[t.content?.trim()?e.jsx("p",{className:"text-slate-700 leading-relaxed text-base whitespace-pre-line mb-4",children: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-2",children:t.callouts.map((z,d)=>e.jsxs("div",{className:`rounded-xl p-4 border-l-4 flex items-start gap-3 ${z.type==="important"?"bg-rose-50 border-rose-400":z.type==="tip"?"bg-emerald-50 border-emerald-400":"bg-amber-50 border-amber-400"}`,children:[e.jsx(Kt,{size:18,className:z.type==="important"?"text-rose-500 mt-0.5":z.type==="tip"?"text-emerald-500 mt-0.5":"text-amber-500 mt-0.5"}),e.jsx("p",{className:"text-sm text-slate-700",children:z.text})]},d))})]});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(cr,{videos:t.videos||[],topic:n.title})]});case"worked_examples":return e.jsx("div",{className:"space-y-4",children:t.examples&&t.examples.length>0?t.examples.map((z,d)=>e.jsxs("div",{className:"bg-gradient-to-br from-rose-50 to-orange-50 rounded-2xl p-5 border border-rose-100",children:[e.jsxs("div",{className:"flex items-start gap-3 mb-3",children:[e.jsx("div",{className:"w-8 h-8 bg-rose-500 rounded-lg flex items-center justify-center flex-shrink-0",children:e.jsx(mt,{size:16,className:"text-white"})}),e.jsx("p",{className:"font-semibold text-slate-800 text-sm pt-1",children:z.problem})]}),e.jsxs("div",{className:"space-y-1.5 ml-11",children:[z.steps.map((A,N)=>e.jsxs("p",{className:"text-slate-600 text-sm",children:[N+1,". ",A]},N)),z.answer&&e.jsxs("p",{className:"text-slate-800 text-sm font-semibold mt-2 pt-2 border-t border-rose-100",children:["Answer: ",z.answer]})]})]},d)):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-2",children:t.bulletPoints&&t.bulletPoints.length>0?t.bulletPoints.map((z,d)=>e.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-xl bg-slate-50 border border-slate-100",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-rose-400 mt-2 flex-shrink-0"}),e.jsx("p",{className:"text-slate-700 text-sm leading-relaxed",children:z})]},d)):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-4",children:[r&&e.jsx("div",{className:"bg-white rounded-2xl p-5 border border-slate-200 shadow-sm",children:i?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(zt,{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 x=="number"&&e.jsxs("span",{className:"ml-2 text-emerald-600",children:[x,"%"]})]}),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",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 bg-gradient-to-br from-rose-400 to-orange-400 rounded-xl flex items-center justify-center",children:e.jsx(Re,{size:20,className:"text-white"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-bold text-slate-800",children:"Practice Quiz"}),e.jsxs("p",{className:"text-xs text-slate-500",children:[r.questions," questions · ",r.duration]})]})]}),e.jsxs("button",{onClick:p,className:"w-full sm:w-auto px-5 py-2.5 rounded-xl bg-gradient-to-r from-rose-500 to-orange-400 text-white text-sm font-bold hover:opacity-90 transition-opacity shadow-md flex items-center justify-center gap-2",children:[e.jsx(Hs,{size:16}),"Start Practice Quiz"]})]})}),e.jsx(dr,{lessonId:n.id?.toString()||"unknown",lessonTitle:n.title,topic:b||t.title||n.title,subjectId:n.subjectId,competencyCode:n.competencyCode,onComplete:(z,d)=>{},onQuizComplete:g,onClose:M,onContinueLearning:M})]});case"summary":return e.jsx("div",{className:"space-y-3",children:t.content?.trim()?e.jsx("p",{className:"text-slate-700 text-base leading-relaxed whitespace-pre-line",children: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 kt=[{type:"introduction",label:"Intro",helper:"Welcome note",icon:ft,accent:"from-[#1a85a4] to-[#126b84]",tint:"bg-[#1a85a4] text-white border-transparent",tabBg:"bg-[#1a85a4]"},{type:"key_concepts",label:"Concepts",helper:"Core ideas",icon:Ra,accent:"from-[#fbab41] to-[#e0983a]",tint:"bg-[#fbab41] text-white border-transparent",tabBg:"bg-[#fbab41]"},{type:"video",label:"Video",helper:"Watch and learn",icon:Kt,accent:"from-[#e66a5e] to-[#ce5e53]",tint:"bg-[#e66a5e] text-white border-transparent",tabBg:"bg-[#e66a5e]"},{type:"worked_examples",label:"Examples",helper:"Guided solving",icon:Hs,accent:"from-[#7ec16d] to-[#71ad62]",tint:"bg-[#7ec16d] text-white border-transparent",tabBg:"bg-[#7ec16d]"},{type:"important_notes",label:"Notes",helper:"Key reminders",icon:Ba,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:Oe,accent:"from-[#eb74a6] to-[#d46895]",tint:"bg-[#eb74a6] text-white border-transparent",tabBg:"bg-[#eb74a6]"},{type:"summary",label:"Summary",helper:"Wrap-up",icon:Ft,accent:"from-[#48bca6] to-[#40a794]",tint:"bg-[#48bca6] text-white border-transparent",tabBg:"bg-[#48bca6]"}],yr=({lesson:t,lessonCompletionXP:a=10,practiceQuiz:l,practiceQuizCompleted:o=!1,practiceQuizScore:n,initialSection:r=0,onStartPractice:i,onBack:x,onComplete:p,onProgressUpdate:b,onTryItQuizComplete:g,onContinueLearning:M})=>{const{userProfile:z}=It(),[d,A]=s.useState(0),[N,_]=s.useState(1),[R,m]=s.useState(!1),[y,j]=s.useState(null),E={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:k,isLoading:U,error:O,retry:Y,sources:$,retrievalBand:te,activeModel:de,isOffline:_e}=fr(t.id,E,!0),[re,W]=s.useState(null);s.useEffect(()=>{if(k.length>0){const f=k.find(T=>T.type==="introduction");if(f?.title){const F=f.title.replace(/^Introduction\s+(to|-|:|—)\s+/i,"").replace(/\s*[-:—]\s*Introduction$/i,"").replace(/\s+Introduction$/i,"").trim();F&&F.toLowerCase()!=="introduction"&&W(F)}}},[k]),s.useEffect(()=>{k.length>0&&z?.uid&&t.id&&ja(z.uid,t.id,re||t.title).catch(()=>{})},[k.length,z?.uid,t.id,re,t.title]);const Z=k.length||kt.length;if(s.useEffect(()=>{r>=0&&r{const f=k.findIndex(T=>T.type==="try_it_yourself");r===-1&&f>=0&&A(f)},[k,r]),s.useEffect(()=>{const f=Z>0?(d+1)/Z*100:0;b?.(f)},[d,Z,b]),U)return e.jsx(br,{});if(O&&k.length===0)return e.jsx(gr,{message:O,onRetry:Y,isOffline:_e});const ge=k[d]||{type:"introduction",title:"Loading...",content:"Lesson content is loading. Please wait a moment."},K=()=>{df+1)):(!l||o)&&m(!0)},we=()=>{d>0&&(_(-1),A(f=>f-1))},Me=f=>{p(void 0,void 0,f)},I=!!(l&&!o),u=kt[d]||kt[0],P=u.icon;return 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-4 sm:px-8 py-6 relative z-40",children:e.jsxs("div",{className:"max-w-6xl mx-auto flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-4 min-w-0",children:[e.jsx("button",{onClick:x,className:"w-10 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(Ut,{size:18})}),e.jsxs("div",{className:"min-w-0 flex flex-col justify-center",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[10px] font-bold text-slate-500 uppercase tracking-widest mb-0.5",children:[e.jsx(Je,{size:12}),e.jsx("span",{children:"NOTEBOOK LESSON"}),de&&e.jsx("span",{className:"text-slate-400 bg-slate-100 px-1.5 py-0.5 rounded font-mono",children:de.split("/").pop()}),te==="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.jsx("h1",{className:"font-bold text-slate-800 text-sm truncate",children:t.title})]})]}),e.jsxs("div",{className:"flex items-center gap-4 flex-shrink-0",children:[e.jsxs("div",{className:"text-right",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((d+1)/Z*100),"%"]})]}),e.jsx("div",{className:"w-24 sm:w-32 h-2 bg-slate-200 rounded-full overflow-hidden",children:e.jsx(v.div,{className:"h-full bg-[#7ec16d] rounded-full",animate:{width:`${(d+1)/Z*100}%`},transition:{duration:.25}})})]})]})}),e.jsx("main",{className:"flex-1 overflow-hidden px-4 sm:px-8 pb-8 relative flex justify-center",children:e.jsxs("div",{className:"w-full max-w-5xl h-full relative flex md:pl-16",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:kt.map((f,T)=>{const F=T===d,ee=f.icon;return e.jsxs("button",{onClick:()=>{_(T>d?1:-1),A(T)},className:At("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,F?"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:At("transition-all duration-300 rounded-xl",F?"bg-white/30 p-2.5":"bg-white/20 p-2 group-hover:bg-white/30 group-hover:p-2.5"),children:e.jsx(ee,{size:F?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.jsxs("div",{className:At("flex-1 rounded-[2rem] shadow-2xl flex flex-col overflow-hidden relative z-10 transition-colors duration-500",u.tabBg),children:[e.jsxs("div",{className:"px-6 sm:px-8 py-5 flex items-center gap-4 text-white",children:[e.jsx("div",{className:"bg-white/20 p-2.5 rounded-xl shrink-0",children:e.jsx(P,{size:28,className:"text-white"})}),e.jsxs("div",{className:"flex flex-col min-w-0",children:[e.jsx("h2",{className:"text-2xl sm:text-3xl font-bold truncate",title:ge.title,children:ge.title}),e.jsx("p",{className:"text-white/90 text-sm font-medium truncate mt-0.5",title:t.title,children:t.title})]})]}),e.jsxs("div",{className:"flex-1 bg-[#fdfdfd] rounded-[1.5rem] m-2 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-12 md:left-16 w-[2px] bg-rose-300/60 pointer-events-none z-0"}),e.jsxs("div",{className:"relative z-10 flex-1 overflow-y-auto px-6 md:pl-24 md:pr-12 py-8",children:[e.jsx("div",{className:"md:hidden flex gap-2 overflow-x-auto pb-4 mb-4 [-ms-overflow-style:none] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",children:kt.map((f,T)=>{const F=T===d,ee=f.icon;return e.jsx("button",{onClick:()=>{_(T>d?1:-1),A(T)},className:At("min-w-[100px] rounded-2xl px-3 py-2 text-left transition-all duration-200",F?`${f.tabBg} text-white shadow-md`:"bg-slate-100 text-slate-600 border border-slate-200"),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ee,{size:14}),e.jsx("span",{className:"text-xs font-bold",children:f.label})]})},f.type)})}),e.jsx($e,{mode:"wait",children:e.jsxs(v.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},transition:{duration:.2},className:"space-y-6",children:[e.jsx("div",{className:"bg-white/90 backdrop-blur-sm rounded-[1.5rem] p-6 sm:p-8 shadow-sm border border-slate-100/50",children:e.jsx(wr,{section:ge,sectionIndex:d,onShowSolution:f=>j(y===f?null:f),expandedIndex:y,lesson:t,lessonSpecificTopic:re,onTryItQuizComplete:g,onContinueLearning:M})}),$.length>0&&(z?.role==="admin"||z?.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:[$.length," source",$.length>1?"s":""," used"]}),e.jsx("div",{className:"mt-2 space-y-1 pl-2",children:$.slice(0,3).map((f,T)=>e.jsxs("p",{className:"font-mono truncate",children:[f.source_file," p.",f.page," (",Math.round((f.score||0)*100),"%)"]},T))})]})]},d)})]},d)]})]})]})}),e.jsx("footer",{className:"bg-transparent px-4 sm:px-8 flex-shrink-0 relative z-40 w-full flex justify-center items-center h-20",children:e.jsxs("div",{className:"w-full max-w-5xl flex flex-col items-center",children:[e.jsxs("div",{className:"flex items-center justify-center gap-8 w-full md:ml-16",children:[e.jsxs(ze,{onClick:we,disabled:d===0,variant:"outline",className:"px-6 py-3 rounded-full font-bold 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-2",children:[e.jsx(Ut,{size:16}),"Previous"]}),e.jsxs("p",{className:"text-sm text-slate-500 font-bold tabular-nums",children:[d+1," / ",Z]}),e.jsx(ze,{onClick:K,disabled:d===Z-1&&I,className:"px-8 py-3 rounded-full font-bold text-sm bg-[#7ec16d] text-white hover:bg-[#6ab359] shadow-md transition-colors disabled:opacity-40 flex items-center gap-2",children:d===Z-1?e.jsxs(e.Fragment,{children:["Complete",e.jsx(zt,{size:16})]}):e.jsxs(e.Fragment,{children:["Next",e.jsx(pt,{size:16})]})})]}),d===Z-1&&I&&e.jsx("p",{className:"text-center text-xs font-semibold text-amber-600 mt-3 md:ml-16",children:"Complete the practice quiz first to unlock lesson completion."})]})}),e.jsx($e,{children:R&&e.jsx(v.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(v.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(zt,{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(Ft,{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:["+",a]})]}),e.jsxs("div",{className:"space-y-2.5",children:[e.jsx("button",{onClick:()=>Me(!0),disabled:I,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:()=>Me(!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"})]})]})})})]})},jr=[{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 vr(t){const{lessonTitle:a,topic:l,subjectId:o,competencyCode:n,questionCount:r=6}=t,i=Nr(o)||"General Mathematics",x=t.lessonId?Math.abs(t.lessonId.split("").reduce((p,b)=>Math.imul(31,p)+b.charCodeAt(0)|0,0))%1e6:Math.floor(Math.random()*1e6);try{const p=await sa("/api/quiz/generate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({topic:l||a,subject:i,lessonTitle:a,questionCount:r,questionTypes:["multiple-choice","true-false","fill-in-blank"],difficulty:"medium",competencyCode:n,varianceSeed:x})});return!p.questions||p.questions.length===0?(console.warn("[lessonQuizService] API returned empty questions, using fallback"),Ns(r)):p.questions.map(b=>({id:b.id,type:b.type,question:b.question,options:b.options||void 0,correctAnswer:b.correctAnswer,explanation:b.explanation}))}catch(p){return console.error("[lessonQuizService] Failed to generate quiz via API:",p),console.warn("[lessonQuizService] Using fallback questions"),Ns(r)}}function qs(t){return t==="quiz"?8:6}function Nr(t){if(!t)return null;const a=t.toLowerCase();return a.includes("gen-math")||a.includes("gen_math")?"General Mathematics":a.includes("stats")||a.includes("prob")?"Statistics and Probability":a.includes("pre-calc")||a.includes("pre_calc")?"Pre-Calculus":a.includes("basic-calc")||a.includes("basic_calc")||a.includes("calculus")?"Basic Calculus":null}function Ns(t){const a=[...jr].sort(()=>Math.random()-.5);return a.slice(0,Math.min(t,a.length)).map((l,o)=>({...l,id:o+1}))}const kr=Object.freeze(Object.defineProperty({__proto__:null,generateLessonQuiz:vr,getQuestionCountForQuiz:qs},Symbol.toStringTag,{value:"Module"})),Et={},Sr=(t,a)=>{if(Et[t]&&Et[t].length)return Et[t];const o=Array.from({length:8}).map((n,r)=>{const i=r+2,x=r+3,p=(i+x).toString();return{id:r+1,type:"multiple-choice",question:`Compute: ${i} + ${x}`,options:[p,(i*x).toString(),Math.abs(i-x).toString(),(i+x+1).toString()],correctAnswer:p,explanation:`Add ${i} and ${x} to get ${p}.`}});return Et[t]=o,o},Cr=({module:t,onBack:a,onEarnXP:l,isInQuizMode:o=!1,setIsInQuizMode:n})=>{const[i,x]=s.useState(null),{userProfile:p}=It(),[b,g]=s.useState(null),[M,z]=s.useState(!1);s.useEffect(()=>{if(!p?.uid)return;(async()=>{try{const[P,f]=await Promise.all([Ot(bt(We,"diagnosticResults",p.uid)),Ot(bt(We,"competencyProfiles",p.uid))]),T=P.exists()&&P.data()?.status==="completed",F=f.exists()&&(f.data()?.overallScore??0)>0;z(T||F)}catch{z(!1)}})()},[p?.uid]);const d=s.useRef(l);s.useEffect(()=>{d.current=l},[l]);const A=s.useRef(i);s.useEffect(()=>{A.current=i},[i]),s.useEffect(()=>{try{const u=sessionStorage.getItem(`mathpulse_module_${t.id}_selectedLesson`);if(u){const{lessonId:P}=JSON.parse(u),f=t.lessons.find(T=>T.id===P);f&&x({lesson:f,type:"lesson"})}}catch{}},[]),s.useEffect(()=>{if(i?.type==="lesson"&&i.lesson)try{sessionStorage.setItem(`mathpulse_module_${t.id}_selectedLesson`,JSON.stringify({lessonId:i.lesson.id}))}catch{}else if(i===null)try{sessionStorage.removeItem(`mathpulse_module_${t.id}_selectedLesson`)}catch{}},[i,t.id]);const N=s.useMemo(()=>{const u=Number(t.id.split("-").pop());return Number.isFinite(u)&&u>0?u:1},[t.id]),_=s.useMemo(()=>{const u=t.subjectId;return u||(Tt.find(f=>f.modules.some(T=>T.id===t.id))?.id??null)},[t.id]),R=["#1FA7E1","#9956DE","#75D06A","#FFB356","#7274ED","#FF8B8B","#6ED1CF","#FB96BB"];s.useMemo(()=>{const u=t.subjectAccentColor;if(u)return u;const f=(_?Tt.find(F=>F.id===_):null)?.modules?.findIndex(F=>F.id===t.id)??0,T=f>=0?f:0;return R[T%R.length]},[t,t.id,_]),s.useEffect(()=>{if(p?.uid)return is(p.uid,g)},[p?.uid]);const m=s.useMemo(()=>_?b?.subjects?.[_]?.modulesProgress?.[t.id]??null:null,[t.id,_,b?.subjects]),[y,j]=s.useState(null),E=s.useMemo(()=>{const u=m?.lessonsCompleted??[];return new Set(u)},[m?.lessonsCompleted]),k=s.useMemo(()=>{const u=m?.quizzesCompleted??[];return new Set(u)},[m?.quizzesCompleted]),U=m?.lessonsCompleted?.length??t.lessons.filter(u=>u.completed).length,O=m?.quizzesCompleted?.length??t.quizzes.filter(u=>u.completed).length,Y=m?.progress??t.progress,$=t.lessons.length+t.quizzes.length,te=U+O;t.lessons.length&&U/t.lessons.length*100,t.quizzes.length&&O/t.quizzes.length*100;const de=(u,P)=>{const f=b?.lessons?.[u]?.score;return typeof f=="number"&&Number.isFinite(f)?Math.max(0,Math.min(100,f)):P?100:0},_e=s.useMemo(()=>{if(!$)return 0;const u=t.lessons.reduce((f,T)=>{const F=E.has(T.id)||T.completed;return f+de(T.id,F)},0),P=O*100;return Math.round((u+P)/$)},[E,O,t.lessons,t.quizzes.length,$,b?.lessons]),re=Y>0?Y:_e,W=s.useMemo(()=>{const u=t.quizzes.find(f=>f.type==="final"||/module\s+quiz|general\s+quiz/i.test(f.title));if(u)return u;const P=t.quizzes.find(f=>f.isStandalone===!0);return P||(t.quizzes.length?t.quizzes[0]:null)},[t.quizzes]),Z=s.useMemo(()=>{const u=new Map;t.lessons.forEach(f=>{u.set(f.id,[])});const P=t.lessons.length;return P===0||t.quizzes.forEach((f,T)=>{if(W?.id===f.id)return;const F=Math.min(T,P-1),ee=t.lessons[F];if(!ee)return;const ne=u.get(ee.id)??[];ne.push(f),u.set(ee.id,ne)}),u},[t.lessons,t.quizzes,W?.id]),ge=s.useMemo(()=>Math.max(1,Math.ceil(t.lessons.length/2)),[t.lessons.length]),K=s.useCallback(()=>{x(null),j(null)},[]),we=s.useCallback(()=>{const u=A.current?.type==="lesson"?A.current.lesson:null;if(!u)return;const P={id:`${u.id}-practice`,title:`Practice Quiz: ${u.title}`,questions:qs("practice"),duration:u.duration,completed:!1,locked:!1,type:"practice"};j(u),x({type:"quiz",quiz:P})},[]),Me=s.useCallback((u,P,f)=>{const T=A.current;if(T?.type!=="lesson"||!T.lesson)return;const F=T.lesson,ee=10;if(d.current?.(ee,`Completed "${F.title}"`),p?.uid&&_&&(async()=>{try{await aa(p.uid,_,t.id,F.id,0,ee),await os(p.uid,_,t.id,t.lessons.length,t.quizzes.length)}catch(ne){console.error("[LessonComplete] Failed to persist progress:",ne)}})(),f){const ne=t.lessons.findIndex(Be=>Be.id===F.id);ne!==-1&&ne0?x({type:"quiz",quiz:t.quizzes[0]}):x(null)}else x(null)},[_,t.id,t.lessons.length,t.quizzes.length]),I=s.useCallback(u=>{if(!p?.uid||!A.current||A.current.type!=="lesson")return;const P=A.current.lesson.id;(async()=>{try{await ra(p.uid,P,u)}catch(f){console.warn("[ModuleDetailView] Failed to persist lesson progress:",f)}})()},[p?.uid,t.id]);if(i)if(i.type==="lesson"){const u=Z.get(i.lesson.id)?.[0]??null,P=u?k.has(u.id)||u.completed:!1;return e.jsx(yr,{lesson:i.lesson,lessonCompletionXP:10,practiceQuiz:u,practiceQuizCompleted:P,initialSection:i.returnFromQuiz?-1:0,onBack:K,onStartPractice:we,onProgressUpdate:I,onComplete:Me})}else{const u=Sr(i.quiz.id);return e.jsx(ir,{lesson:{id:parseInt(i.quiz.id.split("-").pop()||"1"),title:i.quiz.title,duration:i.quiz.duration,type:"quiz",completed:i.quiz.completed,locked:i.quiz.locked},questions:u,onBack:()=>{y?(x({type:"lesson",lesson:y,returnFromQuiz:!0}),j(null)):x(null),n&&n(!1)},onComplete:(P,f)=>{p?.uid&&_&&(async()=>{try{await la(p.uid,_,t.id,i.quiz.id,P,[],0,f),await os(p.uid,_,t.id,t.lessons.length,t.quizzes.length),await is(p.uid,g)}catch(T){console.warn("[Quiz] Progress persist failed:",T)}l&&l(f??0,`Quiz Complete! +${f??0} XP`)})(),y?(x({type:"lesson",lesson:y,returnFromQuiz:!0}),j(null)):x(null),n&&n(!1)}})}return e.jsxs("div",{className:"h-full overflow-y-auto scrollbar-hide px-4 sm:px-6 xl:px-10 py-6 sm:py-8 relative",children:[e.jsx("div",{className:"relative mb-6 xl:mb-8 w-full sm:w-max",children:e.jsxs("button",{onClick:a,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(Ut,{size:18}),"Back"]})}),e.jsxs(v.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 sm:p-7 md:p-10 flex flex-col md:flex-row md:items-center justify-between gap-6 md:gap-8",children:[e.jsxs("div",{className:"flex-1 text-white",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3 mb-4 md:mb-5",children:[e.jsxs("div",{className:"px-3 py-1 bg-white/10 backdrop-blur-md rounded-full text-[11px] font-black uppercase tracking-widest text-[#f8fafc] border border-white/20 shadow-sm flex items-center gap-1.5",children:[e.jsx(us,{size:14})," Chapter ",t.id.split("-").pop()||"1"]}),e.jsxs("div",{className:"px-3 py-1 bg-white/10 backdrop-blur-md rounded-full text-[11px] font-black uppercase tracking-widest text-emerald-400 border border-emerald-400/30",children:["Lv ",N]})]}),e.jsx("h1",{className:"text-3xl md:text-4xl lg:text-5xl font-display font-black text-white mb-3 md:mb-4 tracking-[-0.02em] leading-tight",children:t.title}),e.jsx("p",{className:"text-slate-300 text-sm md:text-[15px] max-w-2xl font-medium leading-relaxed mb-6 md:mb-8",children:t.description}),e.jsxs("div",{className:"bg-black/20 backdrop-blur-md rounded-2xl p-4 md:p-5 border border-white/10 max-w-xl",children:[e.jsxs("div",{className:"flex justify-between items-end mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(Ft,{size:20,className:"text-emerald-400"}),e.jsx("span",{className:"text-[12px] md:text-[13px] font-black text-white uppercase tracking-wider",children:"Module Mastery"})]}),e.jsxs("div",{className:"flex items-baseline gap-2",children:[e.jsxs("span",{className:"text-[12px] md:text-[13px] font-bold text-slate-400 mb-0.5",children:[te,"/",$," steps"]}),e.jsxs("span",{className:"text-xl md:text-2xl font-black text-white shrink-0 leading-none",children:[Math.round(re),"%"]})]})]}),e.jsx("div",{className:"h-3 bg-black/40 rounded-full overflow-hidden shadow-inner ring-1 ring-white/10 p-0.5",children:e.jsx(v.div,{initial:{width:0},animate:{width:`${re}%`},transition:{duration:1.5,ease:"easeOut",delay:.2},className:`h-full rounded-full relative ${re===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-48 h-48 bg-white/5 rounded-[2rem] 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-[2rem] ${t.progress===100?"bg-gradient-to-br from-emerald-400 to-teal-600":t.accentColor}`}),re===100?e.jsx(Ct,{size:80,className:"text-white drop-shadow-xl z-10 scale-100 group-hover:scale-110 transition-transform duration-500",strokeWidth:1}):e.jsx(Je,{size:80,className:"text-white drop-shadow-xl z-10 scale-100 group-hover:scale-110 transition-transform duration-500",strokeWidth:1}),e.jsx(v.div,{animate:{y:[-5,5,-5],rotate:[-10,10,-10]},transition:{duration:4,repeat:1/0},className:"absolute top-6 left-6 text-emerald-300 z-20",children:e.jsx(Es,{size:20,fill:"currentColor"})}),e.jsx(v.div,{animate:{y:[5,-5,5],rotate:[10,-10,10]},transition:{duration:3.5,repeat:1/0},className:"absolute bottom-8 right-6 text-sky-300 z-20",children:e.jsx(bs,{size:24})})]})]})]}),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(Je,{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 ",U,"/",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 ",O,"/",t.quizzes.length]})]})]}),e.jsxs("div",{className:"relative z-10 px-4 sm:px-6 md:px-8 py-5 md:py-6 space-y-5",children:[t.lessons.map((u,P)=>{const f=E.has(u.id)||u.completed,T=de(u.id,f),F=R[P%R.length];return e.jsxs(Ae.Fragment,{children:[e.jsxs(v.div,{initial:{opacity:0,y:14},animate:{opacity:1,y:0},transition:{delay:P*.05},className:`relative rounded-[1.5rem] border overflow-hidden group transition-all duration-500 mb-6 ${u.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(v.div,{initial:{width:0},animate:{width:`${Math.max(2,T)}%`},transition:{duration:1.2,ease:"easeOut",delay:.1+P*.05},className:"h-full relative",style:{backgroundColor:F},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, ${F}44 0%, ${F}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, ${F} 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:`${F}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:`${F}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:F},children:e.jsx(bs,{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:F},children:e.jsx(Je,{size:40,strokeWidth:1})}),e.jsxs("div",{className:"relative z-10 p-4 md:p-5 pt-6 space-y-4",children:[e.jsxs("button",{type:"button",onClick:()=>!u.locked&&x({lesson:u,type:"lesson"}),className:`w-full text-left flex flex-wrap items-center justify-between gap-3 rounded-2xl px-5 py-4 transition shadow-sm ${u.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-4 min-w-0",children:[e.jsx("div",{className:`w-12 h-12 rounded-full flex items-center justify-center shrink-0 transition-colors shadow-sm ${u.locked?"bg-slate-100 text-slate-400":"text-white"}`,style:u.locked?{}:f?{backgroundColor:"#0ea5e9"}:{backgroundColor:F},children:u.locked?e.jsx(Vt,{size:18}):f?e.jsx(va,{size:24}):e.jsx(Bs,{size:20,className:"ml-0.5"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"text-[11px] md:text-[12px] font-black uppercase tracking-wider text-slate-500 mb-0.5",children:["Lesson ",P+1]}),e.jsx("h3",{className:"font-bold text-[16px] md:text-[18px] text-[#0a1628] truncate",children:u.title})]})]}),e.jsx("div",{className:"flex items-center justify-end",children:e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-slate-500 text-xs md:text-sm font-semibold bg-slate-100/80 px-3 py-1.5 rounded-xl",children:[e.jsx(ft,{size:14}),u.duration]})})]}),e.jsxs("div",{className:"flex flex-wrap gap-3 px-1",children:[e.jsxs("button",{type:"button",className:"inline-flex items-center gap-1.5 rounded-full bg-white px-4 py-1.5 text-[12px] font-bold shadow-sm transition hover:-translate-y-0.5",style:{color:F},children:[e.jsx(Je,{size:14})," Study Materials"]}),e.jsxs("button",{type:"button",className:"inline-flex items-center gap-1.5 rounded-full bg-white px-4 py-1.5 text-[12px] font-bold shadow-sm transition hover:-translate-y-0.5",style:{color:F},children:[e.jsx(us,{size:14})," Quiz"]})]})]})]}),W&&P===ge-1&&e.jsxs(v.div,{initial:{opacity:0,y:16},animate:{opacity:1,y:0},transition:{delay:.15+P*.03},className:"mt-8 mb-6",children:[e.jsxs("div",{className:"flex items-center gap-4 mb-6",children:[e.jsx("div",{className:"flex-1 h-px bg-slate-200"}),e.jsx("span",{className:"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-5 shadow-lg overflow-hidden group transition-all hover:shadow-xl hover:-translate-y-1",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 gap-4 md:gap-5",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(Oe,{size:28,className:"text-rose-400"})}),e.jsxs("div",{className:"flex-1 min-w-0",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:W.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(Xt,{size:12})," ",W.questions," Qs"]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(ft,{size:12})," ",W.duration]}),e.jsxs("span",{className:"inline-flex items-center gap-1 text-amber-300 drop-shadow-md",children:[e.jsx(Re,{size:12,className:"fill-amber-300"})," +50 XP"]})]})]}),e.jsx("button",{type:"button",onClick:()=>!W.locked&&(x({quiz:W,type:"quiz"}),n&&n(!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 ${W.locked?"bg-white/5 text-white/30 border border-white/10 cursor-not-allowed":M&&(k.has(W.id)||W.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&&(k.has(W.id)||W.completed)?"REVIEW":"START"})]})]})]})]},u.id)}),t.lessons.length===0&&W&&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(Oe,{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:W.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(Xt,{size:12})," ",W.questions," Qs"]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(ft,{size:12})," ",W.duration]}),e.jsxs("span",{className:"inline-flex items-center gap-1 text-amber-300 drop-shadow-md",children:[e.jsx(Re,{size:12,className:"fill-amber-300"})," +50 XP"]})]})]})]}),e.jsx("button",{type:"button",onClick:()=>!W.locked&&(x({quiz:W,type:"quiz"}),n&&n(!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 ${W.locked?"bg-white/5 text-white/30 border border-white/10 cursor-not-allowed":M&&(k.has(W.id)||W.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&&(k.has(W.id)||W.completed)?"REVIEW":"START"})]})]})]})]})})]})},zr=({onStartQuiz:t,searchQuery:a="",allowedSubjectIds:l})=>{const{userProfile:o}=It(),[n,r]=s.useState("all"),[i,x]=s.useState("all"),[p,b]=s.useState(null),g=s.useMemo(()=>!l||l.length===0?Tt:Tt.filter(m=>l.includes(m.id)),[l]);s.useEffect(()=>{o?.uid&&na(o.uid).then(b).catch(console.error)},[o?.uid]),s.useEffect(()=>{if(i==="all")return;g.some(y=>y.title===i)||x("all")},[g,i]);const M=p?.totalQuizzesCompleted||0,z=o?.totalXP||0,d=p?.averageScore?Math.round(p.averageScore):0,A=new Set(p?.quizAttempts?.map(m=>m.quizId)||[]),N={};if(p?.quizAttempts)for(const m of p.quizAttempts)(!N[m.quizId]||m.score>N[m.quizId])&&(N[m.quizId]=m.score);const R=g.flatMap(m=>m.modules.flatMap(y=>y.quizzes.map(j=>({id:j.id,title:j.title,subject:m.title,difficulty:j.type==="module"?"Medium":"Easy",questions:j.questions,duration:j.duration,xpReward:j.questions*5,type:j.type==="module"?"challenge":"practice",completed:A.has(j.id),bestScore:N[j.id],locked:j.locked})))).filter(m=>{const y=n==="all"||m.type===n,j=i==="all"||m.subject===i,E=!a||m.title.toLowerCase().includes(a.toLowerCase())||m.subject.toLowerCase().includes(a.toLowerCase());return y&&j&&E});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-4 mb-6",children:[e.jsxs(v.div,{whileHover:{scale:1.02},className:"bg-gradient-to-br from-sky-700 to-sky-500 rounded-2xl p-5 text-white shadow-lg",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("div",{className:"w-12 h-12 bg-white/20 rounded-xl flex items-center justify-center",children:e.jsx(Ft,{size:24})}),e.jsx("span",{className:"text-3xl font-bold",children:M})]}),e.jsx("p",{className:"text-sm font-medium text-sky-100",children:"Quizzes Completed"})]}),e.jsxs(v.div,{whileHover:{scale:1.02},className:"bg-gradient-to-br from-rose-500 to-rose-600 rounded-2xl p-5 text-white shadow-lg",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("div",{className:"w-12 h-12 bg-white/20 rounded-xl flex items-center justify-center",children:e.jsx(Re,{size:24})}),e.jsx("span",{className:"text-3xl font-bold",children:z.toLocaleString()})]}),e.jsx("p",{className:"text-sm font-medium text-cyan-100",children:"Total XP Earned"})]}),e.jsxs(v.div,{whileHover:{scale:1.02},className:"bg-gradient-to-br from-indigo-600 to-indigo-700 rounded-2xl p-5 text-white shadow-lg",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("div",{className:"w-12 h-12 bg-white/20 rounded-xl flex items-center justify-center",children:e.jsx(Oe,{size:24})}),e.jsxs("span",{className:"text-3xl font-bold",children:[d,"%"]})]}),e.jsx("p",{className:"text-sm font-medium text-sky-100",children:"Average Score"})]})]}),e.jsxs("div",{className:"flex items-center gap-3 mb-6",children:[e.jsxs("div",{className:"flex items-center gap-2 bg-white rounded-xl p-1 shadow-sm",children:[e.jsx("button",{onClick:()=>r("all"),className:`px-4 py-2 rounded-lg text-sm font-bold transition-all ${n==="all"?"bg-sky-600 text-white shadow-md":"text-[#5a6578] hover:bg-[#edf1f7]"}`,children:"All"}),e.jsx("button",{onClick:()=>r("practice"),className:`px-4 py-2 rounded-lg text-sm font-bold transition-all ${n==="practice"?"bg-sky-500 text-white shadow-md":"text-[#5a6578] hover:bg-[#edf1f7]"}`,children:"Practice"}),e.jsx("button",{onClick:()=>r("challenge"),className:`px-4 py-2 rounded-lg text-sm font-bold transition-all ${n==="challenge"?"bg-orange-500 text-white shadow-md":"text-[#5a6578] hover:bg-[#edf1f7]"}`,children:"Challenge"}),e.jsx("button",{onClick:()=>r("mastery"),className:`px-4 py-2 rounded-lg text-sm font-bold transition-all ${n==="mastery"?"bg-sky-500 text-white shadow-md":"text-[#5a6578] hover:bg-[#edf1f7]"}`,children:"Mastery"})]}),e.jsxs("select",{value:i,onChange:m=>x(m.target.value),className:"px-4 py-2.5 bg-white border-2 border-[#dde3eb] rounded-xl text-sm font-bold text-[#0a1628] focus:border-indigo-600 focus:outline-none",children:[e.jsx("option",{value:"all",children:"All Subjects"}),g.map(m=>e.jsx("option",{value:m.title,children:m.title},m.id))]})]}),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:R.map((m,y)=>{const j=m.locked,E=m.difficulty==="Hard",k=m.type==="challenge";return e.jsx(v.div,{initial:{opacity:0,x:-20},animate:{opacity:1,x:0},transition:{delay:y*.05},onClick:()=>!j&&t?.(m),className:`bg-white/90 backdrop-blur-sm rounded-2xl p-4 md:p-5 border-2 relative select-none transition-all duration-300 ${j?"border-slate-200 opacity-60 saturate-50 cursor-not-allowed":m.completed?"border-teal-200 shadow-sm hover:border-teal-300 hover:shadow-md cursor-pointer":E?"border-indigo-200 shadow-sm hover:border-indigo-300 hover:shadow-md cursor-pointer":"border-orange-200 shadow-sm hover:border-orange-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:[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 ${j?"bg-slate-100 text-slate-400":m.completed?"bg-teal-500 text-white":E?"bg-indigo-500 text-white":"bg-orange-500 text-white"}`,children:j?e.jsx(Vt,{size:18}):m.completed?e.jsx(Ct,{size:18}):e.jsx(Xt,{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 ${E?"bg-indigo-100 text-indigo-700":k?"bg-orange-100 text-orange-700":"bg-sky-100 text-sky-700"}`,children:[m.type," ΓÇó ",m.difficulty]}),!j&&!m.completed&&e.jsx("span",{className:"w-1.5 h-1.5 md:w-2 md:h-2 rounded-full bg-rose-500 animate-pulse"})]}),e.jsx("h3",{className:`font-bold text-[14px] md:text-[16px] leading-tight mb-1 md:mb-1.5 transition-colors ${j?"text-slate-600":"text-[#0a1628]"}`,children:m.title}),e.jsx("p",{className:"text-[11px] md:text-[12px] text-slate-500 mb-1.5 line-clamp-1",children:m.subject}),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(Je,{size:12})," ",m.questions," Qs"]}),e.jsx("span",{className:"hidden sm:inline",children:"ΓÇó"}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(ft,{size:12})," ",m.duration]}),e.jsx("span",{className:"hidden sm:inline",children:"ΓÇó"}),e.jsxs("span",{className:"flex items-center gap-1 text-rose-500",children:[e.jsx(Ct,{size:12})," +",m.xpReward," XP"]})]})]})]}),e.jsxs("div",{className:"flex flex-col items-end gap-2 shrink-0",children:[m.bestScore!==void 0&&e.jsxs("div",{className:"text-right",children:[e.jsxs("div",{className:`text-xl md:text-2xl font-black leading-none ${m.bestScore>=80?"text-teal-600":"text-orange-500"}`,children:[m.bestScore,"%"]}),e.jsx("div",{className:"text-[9px] uppercase tracking-wide text-slate-400 font-bold mt-1",children:"Best Score"})]}),!j&&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.completed?"bg-white border border-slate-200 text-slate-600 group-hover:bg-slate-50":"bg-slate-900 text-white group-hover:bg-slate-600"}`,children:m.completed?"Review":"Start"})]})]})},m.id)})}),R.length===0&&e.jsxs("div",{className:"flex flex-col items-center justify-center h-64 text-slate-500 relative z-10",children:[e.jsx(Oe,{size:48,className:"mb-3"}),e.jsx("p",{className:"font-medium",children:"No quizzes found"}),e.jsx("p",{className:"text-sm",children:"Try adjusting your filters or search query"})]})]})]})},_r=` @keyframes head-sway { 0%, 100% { transform: rotate(-2deg) translateY(0); } 50% { transform: rotate(2deg) translateY(-2px); } @@ -164,7 +154,7 @@ import{r as s,j as e,b as ut,d as Ae}from"./vendor-react-B4AQeu28.js";import{u a transform-origin: 50% 55%; animation: mouth-talk 3s ease-in-out infinite; } -`,Er=({assessmentDismissed:t,initialAssessmentCompleted:a})=>{const l="absolute inset-0 w-full h-full object-contain",[o,n]=s.useState(!1);s.useEffect(()=>{t&&!a&&!sessionStorage.getItem("mathpulse_assessment_reminder_shown")?n(!0):n(!1)},[t,a]);const r=()=>{sessionStorage.setItem("mathpulse_assessment_reminder_shown","true"),n(!1),window.dispatchEvent(new CustomEvent("mathpulse:open-assessment"))};return e.jsxs(e.Fragment,{children:[e.jsx("style",{children:Ar}),e.jsxs("div",{className:"relative w-full h-[250px] flex items-end justify-center drop-shadow-sm select-none pointer-events-none",children:[o&&e.jsxs(v.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:r,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`})]})]})]})};function Pr(t){const[a,l]=s.useState({extraHintsEnabled:!1,hintTokens:0,totalHintsAvailable:0,loading:!0});return s.useEffect(()=>{if(!t){l({extraHintsEnabled:!1,hintTokens:0,totalHintsAvailable:0,loading:!1});return}const o=bt(We,"users",t);return Gt(o,r=>{if(!r.exists()){l({extraHintsEnabled:!1,hintTokens:0,totalHintsAvailable:0,loading:!1});return}const i=r.data(),x=i?.extraHintsEnabled===!0,p=i?.hintTokens||0,b=x?p+3:p;l({extraHintsEnabled:x,hintTokens:p,totalHintsAvailable:b,loading:!1})},r=>{console.error("[useExtraHints] snapshot error:",r),l({extraHintsEnabled:!1,hintTokens:0,totalHintsAvailable:0,loading:!1})})},[t]),a}const ks=` +`,Mr=({assessmentDismissed:t,initialAssessmentCompleted:a})=>{const l="absolute inset-0 w-full h-full object-contain",[o,n]=s.useState(!1);s.useEffect(()=>{t&&!a&&!sessionStorage.getItem("mathpulse_assessment_reminder_shown")?n(!0):n(!1)},[t,a]);const r=()=>{sessionStorage.setItem("mathpulse_assessment_reminder_shown","true"),n(!1),window.dispatchEvent(new CustomEvent("mathpulse:open-assessment"))};return e.jsxs(e.Fragment,{children:[e.jsx("style",{children:_r}),e.jsxs("div",{className:"relative w-full h-[250px] flex items-end justify-center drop-shadow-sm select-none pointer-events-none",children:[o&&e.jsxs(v.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:r,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`})]})]})]})};function Ar(t){const[a,l]=s.useState({extraHintsEnabled:!1,hintTokens:0,totalHintsAvailable:0,loading:!0});return s.useEffect(()=>{if(!t){l({extraHintsEnabled:!1,hintTokens:0,totalHintsAvailable:0,loading:!1});return}const o=bt(We,"users",t);return Gt(o,r=>{if(!r.exists()){l({extraHintsEnabled:!1,hintTokens:0,totalHintsAvailable:0,loading:!1});return}const i=r.data(),x=i?.extraHintsEnabled===!0,p=i?.hintTokens||0,b=x?p+3:p;l({extraHintsEnabled:x,hintTokens:p,totalHintsAvailable:b,loading:!1})},r=>{console.error("[useExtraHints] snapshot error:",r),l({extraHintsEnabled:!1,hintTokens:0,totalHintsAvailable:0,loading:!1})})},[t]),a}const ks=` @keyframes score-pop { 0% { transform: scale(1); } 50% { transform: scale(1.4); } @@ -186,4 +176,4 @@ import{r as s,j as e,b as ut,d as Ae}from"./vendor-react-B4AQeu28.js";import{u a height: 10px; animation: confetti-fall linear forwards; } -`,Tr=({viewportHeight:t})=>e.jsx("div",{className:"absolute inset-0 pointer-events-none z-[250] overflow-hidden flex justify-between bg-slate-900/5",children:Ae.useMemo(()=>[...Array(40)].map((a,l)=>({id:l,left:`${Math.random()*100}%`,duration:.6+Math.random()*.4,delay:Math.random()*.4})),[t]).map(a=>e.jsx(v.div,{className:"absolute w-0.5 h-16 bg-blue-400/30 rounded-full",style:{left:a.left,top:"-10%"},animate:{y:[0,t*1.2]},transition:{duration:a.duration,ease:"linear",delay:a.delay}},a.id))}),Lr=()=>{const t=Ae.useMemo(()=>[...Array(60)].map((a,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(a=>e.jsx("div",{className:"confetti-piece",style:{left:a.left,top:"-10%",backgroundColor:a.backgroundColor,width:a.size,height:a.size,borderRadius:a.borderRadius,animationDuration:`${a.duration}s`,animationDelay:`${a.delay}s`}},a.id))})},Fr=({viewportHeight:t,viewportWidth:a})=>{const l=Ae.useMemo(()=>[...Array(30)].map((o,n)=>({id:n,xShift:(Math.random()-.5)*a*.8,yShift:(Math.random()-.5)*t*.8,scale:Math.random()*1.5+.5,duration:2+Math.random()*1.5,delay:Math.random()*.35})),[t,a]);return e.jsx("div",{className:"absolute inset-0 pointer-events-none z-[250] overflow-hidden flex items-center justify-center",children:l.map(o=>e.jsx(v.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,o.yShift],x:[0,o.xShift],scale:[0,o.scale,0],opacity:[0,1,0]},transition:{duration:o.duration,ease:"easeOut",delay:o.delay}},o.id))})},Ss=({value:t,label:a,delay:l=0,icon:o})=>{const[n,r]=Ae.useState(0);return Ae.useEffect(()=>{if(t<=0)return;const i=1e3,x=30,p=Math.abs(Math.floor(i/x));let b=0;const g=setTimeout(()=>{const M=setInterval(()=>{b+=Math.max(1,Math.floor(t/x)),b>=t?(r(t),clearInterval(M)):r(b)},p);return()=>clearInterval(M)},l);return()=>clearTimeout(g)},[t,l]),t<0?null:e.jsxs(v.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:[o,a]}),e.jsxs("div",{className:"text-xl font-black text-purple-600 tabular-nums",children:["+",n]})]})};function Ir(t){if(t.questionType==="multiple_choice"&&t.options&&t.options.length>0){const a=t.options.findIndex(l=>l.trim().toLowerCase()===t.correctAnswer.trim().toLowerCase());return{id:t.id,question:t.question,options:t.options,correctAnswer:a>=0?a: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 Cs(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 Dr(t,a,l){const o=n=>n.trim().toLowerCase().replace(/\s+/g," ");switch(l){case"identification":return o(t)===o(a);case"enumeration":{const n=t.split(",").map(i=>o(i)).filter(Boolean).sort(),r=a.split(",").map(i=>o(i)).filter(Boolean).sort();return JSON.stringify(n)===JSON.stringify(r)}case"word_problem":case"equation_based":{const n=Cs(t),r=Cs(a);if(n===r)return!0;const i=parseFloat(t.replace(/[^\d.\-]/g,"")),x=parseFloat(a.replace(/[^\d.\-]/g,""));return!isNaN(i)&&!isNaN(x)?Math.abs(i-x)<=.01:o(t)===o(a)}default:return o(t)===o(a)}}const Rr=({quiz:t,onClose:a,onComplete:l,studentId:o,atRiskSubjects:n=[]})=>{const[r,i]=s.useState(0),[x,p]=s.useState(null),[b,g]=s.useState(""),[M,z]=s.useState(!1),[d,A]=s.useState(!1),[N,_]=s.useState(!1),[R,m]=s.useState(0),[y,j]=s.useState(0),[E,k]=s.useState(1),[U,q]=s.useState([]),[Y,$]=s.useState([]),[te,xe]=s.useState(Date.now()),[_e,re]=s.useState(!1),[W,Z]=s.useState(!1),[ge,K]=s.useState(null),[we,Me]=s.useState(0),[F,u]=s.useState(0),[P,f]=s.useState(!1),[T,I]=s.useState(!0),[ee,ne]=s.useState(!1),[Be,gt]=s.useState({width:1280,height:720});s.useEffect(()=>{const S=()=>gt({width:window.innerWidth,height:window.innerHeight});return S(),window.addEventListener("resize",S),()=>window.removeEventListener("resize",S)},[]);const[Ue,et]=s.useState(0),[je,nt]=s.useState({}),[_t,Xe]=s.useState(!1),[wt,Ge]=s.useState(!1),[tt,it]=s.useState(!1),{totalHintsAvailable:He}=Pr(o||null),[Ve,ye]=s.useState(5),[ve,Ne]=s.useState(15),st=Ve+He,[Qe,ot]=s.useState(null),[Ye,Ke]=s.useState(!1),[c,D]=s.useState(900*1e3),[X,le]=s.useState([]),[L,ke]=s.useState(0),[Se,Le]=s.useState(null),[oe]=s.useState(()=>t.loadedQuestions&&t.loadedQuestions.length>0?t.loadedQuestions.map(Ir):Array.from({length:t.questions},(S,h)=>({id:`q${h+1}`,question:$r(t.subject,h),options:Br(t.subject,h),correctAnswer:Hr(t.subject,h),explanation:Qr(t.subject,h,t.difficulty)})));s.useEffect(()=>{nt({}),le([]),ye(5),Ne(15),et(0),m(0),j(0),k(1)},[t.id]);const ue=oe[r];s.useEffect(()=>{const S=parseInt(t.duration)||10;Me(S*60);const h=setInterval(()=>{Me(H=>H<=1?(clearInterval(h),yt(),0):H-1)},1e3);return()=>clearInterval(h)},[]),s.useEffect(()=>{ve===0&&!Qe&&(ot(Date.now()),Ke(!0))},[ve,Qe]),s.useEffect(()=>{if(!Ye||!Qe)return;const S=setInterval(()=>{const h=Date.now()-Qe,H=Math.max(0,900*1e3-h);D(H)},1e3);return()=>clearInterval(S)},[Ye,Qe]);const[at,Fe]=s.useState(Array.from({length:15},(S,h)=>({id:h,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=S=>{if(T)try{const h=window.AudioContext||window.webkitAudioContext;if(!h)return;const H=new h,B=H.currentTime,Q=(Ce,Ee,he,Ie=.1,be="sine")=>{const me=H.createOscillator(),Oe=H.createGain();me.type=be,me.frequency.value=Ce,Oe.gain.setValueAtTime(0,Ee),Oe.gain.linearRampToValueAtTime(Ie,Ee+.05),Oe.gain.exponentialRampToValueAtTime(.001,Ee+he),me.connect(Oe),Oe.connect(H.destination),me.start(Ee),me.stop(Ee+he)};S==="correct"?(Q(880,B,.1,.1,"sine"),Q(1108.73,B+.1,.2,.1,"sine")):S==="incorrect"?(Q(300,B,.2,.05,"sawtooth"),Q(250,B+.15,.3,.05,"sawtooth")):S==="combo"?(Q(440,B,.1,.05,"square"),Q(554.37,B+.1,.1,.05,"square"),Q(659.25,B+.2,.1,.05,"square"),Q(880,B+.3,.4,.05,"square")):S==="complete"&&(Q(523.25,B,.1,.1),Q(659.25,B+.15,.1,.1),Q(783.99,B+.3,.1,.1),Q(1046.5,B+.45,.5,.1))}catch{}},yt=()=>{re(!0),vt()},pe=()=>{if(Ve<=0||d)return;const S=je[r]||[],h=ue.options.filter(B=>B!==ue.correctAnswerText).filter(B=>!S.includes(B));if(h.length===0)return;const H=h[Math.floor(Math.random()*h.length)];nt(B=>({...B,[r]:[...S,H]})),ye(B=>Math.max(0,B-1)),fe("correct")},Mt=S=>{d||ce||(p(S),setTimeout(()=>{jt(S)},150))},jt=S=>{const h=ue.questionType!=null&&ue.questionType!=="multiple_choice",H=S!==void 0?S:x;if(h){if(!b.trim())return}else if(H===null)return;const B=h?Dr(b,ue.correctAnswerText||"",ue.questionType||""):H===ue.correctAnswer,Q=h?b:String(H),Ce=Math.round((Date.now()-te)/1e3);$(me=>[...me,{questionId:ue.id,answer:Q,correct:B,timeSpent:Ce}]);const Ee=[...U];if(Ee[r]=B?1:0,q(Ee),z(B),A(!0),!B){Ge(!0),fe("incorrect"),setTimeout(()=>Ge(!1),500),Ne(me=>Math.max(0,me-1)),j(0),k(1),setTimeout(()=>{ct()},1500);return}fe("correct");const Ie=(je[r]||[]).length>0?5:10;et(me=>me+Ie),m(R+1);const be=y+1;j(be),be===2?Le("streak"):be===3&&E<2?Le("multiplier2"):be===5&&E<3&&Le("multiplier3"),be>0&&be%3===0&&fe("combo"),be>=5?k(3):be>=3?k(2):k(1),Lt(()=>import("./confetti.module-C94ZD2ww.js"),[]).then(me=>{me.default({particleCount:30,spread:40,colors:["#75D06A","#6ED1CF"],origin:{y:.6}})}),it(!0),setTimeout(()=>{it(!1),Le(null),setTimeout(()=>ct(),300)},1500)},ct=()=>{if(r{const S=Math.round(R/oe.length*100);let h=t.xpReward;S>=90?h=Math.round(h*1.5):S>=80&&(h=Math.round(h*1.25));const H=parseInt(t.duration)*60;we>H*.5&&(h=Math.round(h*1.2)),u(h);const B=H-we;o&&Na({lrn:o,quizId:t.id,subject:t.subject,score:S,totalQuestions:oe.length,correctAnswers:R,timeSpentSeconds:B}).catch(Q=>console.error("[WARN] Automation: quiz pipeline failed:",Q)),t.source==="ai_generated"&&o?wa(o,t.id,t.generatedQuizId,t.subject,t.source,S,h,B,Y,oe.map(Q=>({topic:Q.topic||t.subject,difficulty:Q.difficulty||"medium",bloomLevel:Q.bloomLevel||"understand"}))).catch(Q=>console.error("[WARN] Quiz result save failed:",Q)):o&&ia(o,t.id,t.subject,S,Y.map(Q=>({questionId:Q.questionId,selectedAnswer:Q.answer,isCorrect:Q.correct})),B).catch(Q=>console.error("[WARN] Practice quiz persist failed:",Q)),fe("complete")},ce=L{document.fullscreenElement?(document.exitFullscreen().catch(()=>{}),ne(!1)):(document.documentElement.requestFullscreen().catch(()=>{}),ne(!0))};if(_e){const S=Math.round(R/oe.length*100),h=S>=80,H=S>=50&&S<80,B=S<50,Q=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:ks}),h&&e.jsx(Lr,{}),H&&e.jsx(Fr,{viewportHeight:Be.height,viewportWidth:Be.width}),B&&e.jsx(Tr,{viewportHeight:Be.height}),e.jsxs(v.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(v.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(v.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 ${h?"text-emerald-500":H?"text-amber-500":"text-rose-500"}`,children:h?"EXCELLENT!":H?"GOOD JOB!":"KEEP TRYING!"}),e.jsxs("p",{className:"text-slate-400 font-bold text-[10px] mb-3 uppercase tracking-widest",children:["Quiz Complete • Score: ",R,"/",oe.length]}),e.jsx(v.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(Ss,{value:R,label:"Correct Answers",delay:500,icon:e.jsx(lt,{className:"h-3 w-3 text-emerald-500"})}),e.jsx(Ss,{value:Ue,label:"Total XP Earned",delay:800,icon:e.jsx(Re,{className:"h-3 w-3 text-amber-500"})}),e.jsxs(v.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:[S,"%"]})]})]})]})}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(ze,{size:"lg",onClick:()=>{i(0),ke(0),p(null),g(""),m(0),j(0),k(1),q([]),$([]),et(0),re(!1),A(!1),_(!1),xe(Date.now()),nt({}),le([]),Xe(!1),ye(5),Z(!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(ze,{size:"lg",onClick:a,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 PRACTICE CENTER"})]})]})]});return ut.createPortal(Ce,Q)}return e.jsxs(e.Fragment,{children:[e.jsx("style",{children:ks}),P&&ut.createPortal(e.jsx(v.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:()=>f(!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(De,{size:12})})]}),e.jsx(Fs,{isOpen:!0,onClose:()=>f(!1),inline:!0})]})}),document.getElementById("modal-root")),Ye&&ut.createPortal(e.jsx("div",{className:"fixed inset-0 z-[200] flex items-center justify-center p-4 bg-slate-900/50",children:e.jsxs(v.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(v.div,{animate:{scale:[1,1.1,1]},transition:{duration:1,repeat:1/0},className:"text-6xl mb-4",children:"💔"}),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(c/6e4),":",Math.floor(c%6e4/1e3).toString().padStart(2,"0")]})," (15 minutes per heart)"]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(ze,{onClick:a,className:"w-full py-3 bg-rose-500 hover:bg-rose-600 text-white font-bold rounded-full",children:"Exit Quiz"}),e.jsx(ze,{onClick:()=>{Ke(!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($e,{children:tt&&M&&e.jsx(v.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:["+ ",(je[r]||[]).length>0?5:10," XP"]})}),Se==="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(As,{size:14})," Streak Started!"]}),Se==="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(Re,{size:14})," Multiplier ×2!"]}),Se==="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(Re,{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-start justify-between relative z-10 mb-4 sm:mb-6",children:[e.jsx("div",{className:"flex-1 flex items-center gap-2",children:e.jsxs("div",{className:"flex items-center gap-1 bg-white/20 px-3 py-1.5 rounded-full text-white text-sm font-bold",children:[e.jsx(ft,{size:16})," ",Or(we)]})}),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:t.title||t.subject})]})]}),e.jsxs("div",{className:"flex-1 flex justify-end gap-2 sm:gap-3 relative pointer-events-auto",children:[e.jsx("button",{onClick:()=>I(!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(Is,{size:20}):e.jsx(Ds,{size:20})}),e.jsx("button",{onClick:dt,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:ee?e.jsx(Rs,{size:20}):e.jsx($s,{size:20})}),e.jsx("button",{onClick:a,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(De,{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:oe.map((S,h)=>{let H=h<=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 ${H}`},h)})})})]}),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-8",children:[e.jsx("button",{onClick:()=>ke(S=>Math.max(0,S-1)),disabled:L===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 ${L===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(Yt,{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"})," ",ve]}),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"})," ",Ve]}),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"})," ",y]}),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:["+ ",Ue," pts"]})]})]}),e.jsx("button",{onClick:()=>ke(S=>Math.min(r,S+1)),disabled:L>=r,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 ${L>=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(ht,{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(v.div,{initial:{opacity:0,x:20},animate:wt?{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.jsxs("div",{className:"bg-slate-100 text-slate-600 px-4 py-1.5 rounded-full text-[11px] sm:text-xs font-black uppercase tracking-widest mb-4 flex items-center shadow-sm",children:["Q",L+1," of ",oe.length]}),e.jsx("h2",{className:"text-xl sm:text-2xl font-extrabold text-[#0a1628] leading-tight w-full",children:se.question.includes("___")?e.jsx("span",{children:se.question.split("___").map((S,h,H)=>e.jsxs(Ae.Fragment,{children:[S,hg(B.target.value),onKeyDown:B=>{B.key==="Enter"&&!d&&jt()},className:`inline-block w-24 mx-2 border-b-4 outline-none text-center bg-transparent font-bold ${ce?"border-slate-300 text-slate-500":"border-[#7C3AED] text-[#7C3AED] focus:border-[#75D06A]"}`})]},h))}):se.question})]}),e.jsxs("div",{className:"w-full flex flex-col items-center",children:[se.questionType==="multiple_choice"||!se.questionType?e.jsx("div",{className:"w-full grid grid-cols-1 sm:grid-cols-2 gap-3 sm:gap-5",children:(se.options||[]).map((S,h)=>{const H=je[r]||[],B=H.includes(S),Q=H.length,Ce=(se.options||[]).length-1,Ee=Ce>0&&Q>=Ce;let he="bg-white hover:bg-slate-50 border-transparent text-slate-700 hover:border-slate-200",Ie=!1;if(Ee){Ie=!0;const be=se.options?.[se.correctAnswer];S===be?he="bg-emerald-50 border-emerald-400 text-emerald-800":Y[L]?.answer===String(h)?he="bg-rose-50 border-rose-400 text-rose-800 opacity-80":he="bg-slate-100 border-slate-200 text-slate-400 opacity-40 line-through"}else if(B)he="bg-slate-100 border-slate-200 text-slate-400 opacity-40 line-through cursor-not-allowed";else if(ce){const be=h===se.correctAnswer,me=L===r&&(x===h||ge===h)||L{Ie||ce||B||Mt(h)},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 ${he} ${Ie||ce||B?"cursor-default":"hover:shadow-md hover:-translate-y-0.5 active:translate-y-0"}`,children:[e.jsx("span",{className:"truncate pr-4",children:S}),B&&e.jsx(Ht,{size:20,className:"text-slate-400 shrink-0"}),ce&&h===se.correctAnswer&&e.jsx(zt,{size:22,className:"text-emerald-500 shrink-0"}),ce&&x===h&&h!==se.correctAnswer&&e.jsx(Ht,{size:22,className:"text-rose-500 shrink-0"})]},h)})}):e.jsx("div",{className:"w-full max-w-2xl mx-auto flex flex-col gap-4",children:!se.question.includes("___")&&e.jsx("input",{type:"text",disabled:ce,value:L===r?b:"",onChange:S=>g(S.target.value),onKeyDown:S=>{S.key==="Enter"&&!d&&jt()},placeholder:"Type your answer here...",className:`w-full p-4 sm:p-5 rounded-2xl border-[3px] font-extrabold text-lg text-center outline-none transition-colors ${ce?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"}`})}),ce&&N&&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:se.topic||t?.subject||"General Math"}),e.jsxs("p",{className:"text-sm text-slate-500",children:["Question ",L+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"})]}),ce&&N&&e.jsx(v.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 ${(L===r?M:Y[L]?.correct)?"bg-emerald-50 border-emerald-200":"bg-rose-50 border-rose-200"}`,children:[(L===r?M:Y[L]?.correct)?e.jsx(zt,{size:28,className:"text-emerald-500 shrink-0 mt-0.5"}):e.jsx(Ht,{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 ${(L===r?M:Y[L]?.correct)?"text-emerald-700":"text-rose-700"}`,children:(L===r?M:Y[L]?.correct)?"Correct!":"Incorrect"}),e.jsx("p",{className:`text-base leading-relaxed ${(L===r?M:Y[L]?.correct)?"text-emerald-800":"text-rose-800"}`,children:se.explanation||`Correct Answer: ${se.correctAnswerText||se.options?.[se.correctAnswer]}`})]})]})})]})]},L)}),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 S=(je[r]||[]).length,h=(ue.options||[]).length-1,H=h>0&&S>=h;return H||ce&&!M?e.jsxs("button",{onClick:ct,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 max-w-md mx-auto",children:[r{const Q=st>0&&!d&&!H;return e.jsxs("button",{onClick:pe,disabled:!Q,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:"Key",className:"w-5 h-5 object-contain"})," Hint"]})})(),ce&&e.jsxs("button",{onClick:()=>_(!0),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(Je,{size:20})," Explain"]}),e.jsx("button",{onClick:()=>f(Q=>!Q),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 ${P?"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"})]})})]}):Lke(r),className:"bg-white text-slate-700 font-extrabold text-lg px-6 sm:px-8 py-3 sm:py-4 rounded-full inline-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(ht,{size:20}),"Back to Current Question"]}):null})()})]})]})};function $r(t,a){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"]},o=Dt(t),n=l[o]||l["General Mathematics"];return n[a%n.length]}function Dt(t){const a=t.toLowerCase();return a.includes("pre-calc")||a.includes("pre calc")||a.includes("precalc")?"Pre-Calculus":a.includes("statistic")||a.includes("probability")?"Statistics and Probability":a.includes("calculus")&&!a.includes("pre")?"Basic Calculus":a.includes("general")||a.includes("math")||a.includes("algebra")||a.includes("fraction")||a.includes("percent")||a.includes("ratio")||a.includes("geometry")?"General Mathematics":a.includes("derivative")||a.includes("integral")||a.includes("limit")?"Basic Calculus":a.includes("trig")||a.includes("function")||a.includes("log")?"Pre-Calculus":a.includes("mean")||a.includes("median")||a.includes("data")?"Statistics and Probability":"General Mathematics"}function Br(t,a){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²"]]},o=Dt(t),n=l[o]||l["General Mathematics"];return n[a%n.length]}function Hr(t,a){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]},o=Dt(t),n=l[o]||l["General Mathematics"];return n[a%n.length]}function Qr(t,a,l){const o={"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."]},n=Dt(t),r=o[n]||o["General Mathematics"];return r[a%r.length]}function Or(t){const a=Math.floor(t/60),l=t%60;return`${a}:${l.toString().padStart(2,"0")}`}const 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"],qr=({isOpen:t,onClose:a,onClaim:l,weekRewards:o,todayReward:n,canClaim:r,isClaiming:i,claimedDays:x,currentDayIndex:p,timeUntilReset:b})=>{const[g,M]=s.useState(!1);if(!t)return null;const z=()=>{if(!r||g)return;M(!0),n?.rarity==="epic"?ms({particleCount:150,spread:80,origin:{y:.6},colors:["#FFD700","#FFA500","#FF8C00","#FF6B6B","#4ade80"]}):ms({particleCount:100,spread:70,origin:{y:.6},colors:["#FFD700","#FFA500","#FF8C00"]}),setTimeout(()=>{M(!1),l()},1200)},d=y=>y+1,A=y=>y===p,N=y=>x.includes(y),_=y=>y>p,R=o.slice(0,6),m=o[6];return e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4 sm:p-8",children:[e.jsx($e,{children:t&&e.jsx(v.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"absolute inset-0 bg-slate-900/60 backdrop-blur-sm",onClick:a})}),e.jsxs(v.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:a,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(De,{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:[R.map((y,j)=>{const E=d(j),k=N(j),U=A(j),q=_(j);return e.jsxs("div",{className:`relative rounded-xl flex flex-col overflow-hidden border-[1.5px] transition-all ${U&&!k?"border-amber-400 shadow-[0_0_15px_rgba(251,191,36,0.25)] scale-105 z-10 bg-amber-50":k?"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 ${U&&!k?"bg-amber-400 text-amber-900":_s[j]}`,children:["Day ",E]}),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[y.rarity]}`,children:y.rarity})}),e.jsxs("div",{className:"flex-1 p-2 flex flex-col items-center justify-center relative min-h-[75px]",children:[k&&e.jsxs(v.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-rose-200/50"})}),e.jsxs("div",{className:"relative w-14 h-14 rounded-full border-[3px] 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-10 h-10 object-contain drop-shadow-md"}),e.jsx("div",{className:"absolute -bottom-2.5 left-1/2 -translate-x-1/2 bg-rose-500 rounded-md px-2 py-0.5 border-2 border-rose-300 shadow-md",children:e.jsx("span",{className:"text-[9px] font-black text-white uppercase tracking-wider leading-none whitespace-nowrap",children:"Claimed"})})]})]}),q&&e.jsx("div",{className:"absolute top-1 right-1 bg-slate-200 rounded-full p-0.5 z-10",children:e.jsx(Vt,{size:8,className:"text-slate-400"})}),e.jsxs("div",{className:`flex flex-col items-center transition-all w-full ${k?"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:y.color+"20",borderColor:y.color+"40"},children:e.jsx("span",{className:"text-lg",children:y.icon})}),e.jsx("div",{className:`font-black text-xs leading-none mt-0.5 text-center ${U?"text-amber-600":k?"text-slate-500":"text-slate-600"}`,children:y.label})]})]})]},y.id)}),m&&e.jsxs("div",{className:`col-span-3 relative rounded-xl flex flex-col overflow-hidden border-[1.5px] transition-all mt-1 ${A(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 ${A(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[m.rarity]}`,children:m.rarity})}),e.jsxs("div",{className:"flex items-center justify-center gap-5 p-3 relative",children:[N(6)&&e.jsxs(v.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:m.color+"20",borderColor:m.color+"40"},children:e.jsx("span",{className:"text-2xl",children:m.icon})}),e.jsx("span",{className:`font-black text-sm ${A(6)?"text-amber-600":"text-slate-600"}`,children:m.label})]}),m.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("span",{className:"text-3xl drop-shadow-md",children:"🎁"})}),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(Za,{size:14}),e.jsx("span",{className:"font-mono font-medium",children:b}),e.jsx("span",{children:"until next reset"})]}),e.jsx(v.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:z,disabled:!r||i||g,className:`w-[85%] py-3 rounded-full font-black text-base tracking-wide uppercase shadow-lg transition-all mt-2 ${!r||i||g?"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:i||g?"Claiming...":r?"Claim!":"Claimed"})]})]})};function Wr(t){const[a,l]=s.useState({difficulty:"normal",loading:!0});return s.useEffect(()=>{if(!t){l({difficulty:"normal",loading:!1});return}const o=bt(We,"users",t);return Gt(o,r=>{if(!r.exists()){l({difficulty:"normal",loading:!1});return}const x=r.data()?.moduleDifficulty||"normal";l({difficulty:["normal","easier","remedial"].includes(x)?x:"normal",loading:!1})},r=>{console.error("[useModuleDifficulty] snapshot error:",r),l({difficulty:"normal",loading:!1})})},[t]),a}function Ur(t,a){return a==="normal"?t:a==="easier"?t.filter(l=>{const o=l.tags||[],n=l.difficulty||"";return o.some(r=>["foundation","basic","introductory"].includes(r.toLowerCase()))||["foundation","basic","introductory"].includes(n.toLowerCase())||!o.includes("advanced")&&!n.toLowerCase().includes("advanced")}):a==="remedial"?t.filter(l=>{const o=l.tags||[],n=l.difficulty||"";return o.some(r=>["remedial","review","catch-up"].includes(r.toLowerCase()))||["remedial","review","catch-up"].includes(n.toLowerCase())}):t}const Xr=new Set([7,14,30,60,100]),St={lastClaimedDate:"",lastClaimedWeekSeed:0,claimedDays:[],currentStreak:0,longestStreak:0,totalClaimed:0,hintTokens:0,streakShields:0,activeMultiplier:null};function Gr(t){if(t<=0)return"00:00:00";const a=Math.floor(t/1e3),l=Math.floor(a/3600),o=Math.floor(a%3600/60),n=a%60;return`${String(l).padStart(2,"0")}:${String(o).padStart(2,"0")}:${String(n).padStart(2,"0")}`}function Vr(){const t=Jt();return t.setDate(t.getDate()-1),Zt(t)}function qs(t){return t?new Date(t.expiresAt).getTime()>Date.now():!1}function Ws(t){return bt(We,"users",t,"dailyRewards",t)}function Yr(t){return bt(We,"users",t)}async function Ms(t){try{const a=Ws(t),l=await qt(a);if(!l.exists())return{...St};const o=l.data(),n=es();return o.lastClaimedWeekSeed&&o.lastClaimedWeekSeed!==n?{...o,claimedDays:[],lastClaimedWeekSeed:n}:{...St,...o,activeMultiplier:o.activeMultiplier&&qs(o.activeMultiplier)?o.activeMultiplier:null}}catch(a){return console.error("[dailyRewardService] Error getting state:",a),{...St}}}function Kr(t){const a=Zt();return t.lastClaimedDate!==a}async function Zr(t){const a=Zt(),l=es(),o=ts(),r=ss()[o];if(!r)throw new Error(`No reward found for day index ${o}`);try{const i=await Vs(We,async p=>{const b=Ws(t),g=Yr(t),M=await p.get(b),z=await p.get(g);let d;if(M.exists()?d={...St,...M.data()}:(d={...St,lastClaimedWeekSeed:l},p.set(b,d)),d.lastClaimedWeekSeed!==l&&(d.claimedDays=[],d.lastClaimedWeekSeed=l),d.lastClaimedDate===a)return{code:"ALREADY_CLAIMED",state:d};let A=d.currentStreak,N=!1;if(!d.lastClaimedDate||d.currentStreak===0)A=1;else{const j=Vr();d.lastClaimedDate===j?A=d.currentStreak+1:d.streakShields>0?(d.streakShields-=1,A=d.currentStreak+1,N=!0):A=1}const _=Math.max(d.longestStreak,A);let R=0,m=1;switch(r.type){case"xp":{const j=typeof r.value=="number"?r.value:parseInt(r.value,10)||0;m=qs(d.activeMultiplier)?d.activeMultiplier?.multiplier??1:1,R=Math.floor(j*m);break}case"hint_token":{const j=typeof r.value=="number"?r.value:parseInt(r.value,10)||0;d.hintTokens+=j;break}case"streak_shield":{const j=typeof r.value=="number"?r.value:parseInt(r.value,10)||0;d.streakShields+=j;break}case"xp_multiplier":{const j=typeof r.value=="number"?r.value:parseInt(r.value,10)||60,E=r.id.includes("2")?2:1.5,k=new Date;k.setMinutes(k.getMinutes()+j),d.activeMultiplier={multiplier:E,expiresAt:k.toISOString()};break}case"badge_unlock":break}const y=[...d.claimedDays,o];return d.lastClaimedDate=a,d.currentStreak=A,d.longestStreak=_,d.totalClaimed+=1,p.set(b,d,{merge:!0}),z.exists()&&p.update(g,{hintTokens:d.hintTokens,streakShields:d.streakShields,activeMultiplier:d.activeMultiplier,lastClaimedDate:d.lastClaimedDate,updatedAt:Ys()}),{code:"SUCCESS",state:d,newClaimedDays:y,newStreak:A,newLongestStreak:_,xpAwarded:R,multiplierApplied:m,streakPreserved:N}});if(i.code==="ALREADY_CLAIMED")return{success:!1,reward:r,dayIndex:o,streakAfter:i.state.currentStreak,longestStreakAfter:i.state.longestStreak,hintTokensAfter:i.state.hintTokens,streakShieldsAfter:i.state.streakShields,streakPreserved:!1,xpAwarded:0,multiplierApplied:1,isMilestone:!1,error:"Already claimed today"};if(i.xpAwarded>0)try{await oa(t,i.xpAwarded,"daily_reward",`Daily Reward Day ${o+1}! +${i.xpAwarded} XP`)}catch(p){console.error("[dailyRewardService] Error awarding XP:",p)}if(r.type==="badge_unlock"&&typeof r.value=="string")try{await Ls(t,r.value)}catch(p){console.error("[dailyRewardService] Error unlocking avatar item:",p)}const x=Xr.has(i.newStreak);return{success:!0,reward:r,dayIndex:o,streakAfter:i.newStreak,longestStreakAfter:i.newLongestStreak,hintTokensAfter:i.state.hintTokens,streakShieldsAfter:i.state.streakShields,streakPreserved:i.streakPreserved,xpAwarded:i.xpAwarded,multiplierApplied:i.multiplierApplied,isMilestone:x}}catch(i){throw console.error("[dailyRewardService] Error claiming daily reward:",i),i}}function Jr(t){const[a,l]=s.useState(null),[o,n]=s.useState(!1),[r,i]=s.useState(!1),[x,p]=s.useState(null),[b,g]=s.useState(null),[M,z]=s.useState("00:00:00"),d=s.useRef(null),A=s.useMemo(()=>ss(),[]),N=s.useMemo(()=>lr(),[]),_=s.useCallback(async()=>{if(!t){l(null);return}try{g(null);const E=await Ms(t);l(E)}catch(E){const k=E instanceof Error?E.message:"Failed to load rewards";g(k),console.error("[useDailyReward] refresh error:",E)}},[t]);s.useEffect(()=>{_()},[_]),s.useEffect(()=>{const E=()=>{const U=sr().getTime()-Date.now();z(Gr(U))};return E(),d.current=setInterval(E,1e3),()=>{d.current&&(clearInterval(d.current),d.current=null)}},[]);const R=s.useMemo(()=>!a||o?!1:Kr(a),[a,o]),m=s.useMemo(()=>!a?.activeMultiplier||new Date(a.activeMultiplier.expiresAt).getTime()<=Date.now()?null:a.activeMultiplier,[a?.activeMultiplier]),y=s.useCallback(async()=>{if(!(!t||!R)){n(!0),g(null);try{const E=await Zr(t);if(p(E),E.success){i(!0);const k=await Ms(t);l(k)}else g(E.error||"Claim failed")}catch(E){const k=E instanceof Error?E.message:"Claim failed";g(k),console.error("[useDailyReward] claim error:",E)}finally{n(!1)}}},[t,R]),j=s.useCallback(()=>{i(!1)},[]);return{weekRewards:A,todayReward:N,canClaim:R,isClaiming:o,claimedDays:a?.claimedDays??[],currentStreak:a?.currentStreak??0,longestStreak:a?.longestStreak??0,totalClaimed:a?.totalClaimed??0,hintTokens:a?.hintTokens??0,streakShields:a?.streakShields??0,activeMultiplier:m,timeUntilReset:M,showModal:r,lastClaimResult:x,error:b,claim:y,dismissModal:j,refresh:_}}const el=["all","Q1","Q2","Q3","Q4"],Hl=({onEarnXP:t,atRiskSubjects:a=[],priorityTopics:l=[],initialModuleId:o=null,isInQuizMode:n=!1,setIsInQuizMode:r,hasCompletedDiagnostic:i=!1})=>{const{userProfile:x,currentUser:p}=Ft(),[b,g]=s.useState("modules"),M=x,z=M?.grade,d=ca(z);ka(d);const[A,N]=s.useState(""),[_,R]=s.useState("all"),[m,y]=s.useState("all"),[j,E]=s.useState("all"),[k,U]=s.useState(!1),[q,Y]=s.useState(null),[$,te]=s.useState(null),xe=s.useMemo(()=>{const c=M?.learnerCurriculumAssignments?.subjects??M?.assignedSubjects??M?.curriculumAssignedSubjects??[];return Array.isArray(c)?c:[]},[M]),{difficulty:_e}=Wr(p?.uid||null),re=s.useMemo(()=>{const c=da(d,xe);return Ur(c,_e)},[d,xe,_e]),W=o&&re.find(c=>c.id===o)||null,[Z,ge]=s.useState(W),[K,we]=s.useState(null),[Me,F]=s.useState(null),[u,P]=s.useState(!1),[f,T]=s.useState(null),[I,ee]=s.useState(!1),[ne,Be]=s.useState([]),[gt,Ue]=s.useState(!1);s.useEffect(()=>{if(b!=="teacher_uploaded"||!We)return;Ue(!0);const c=Gt(Ks(Js(We,"modules"),Zs("moduleType","==","teacher_uploaded")),D=>{const X=D.docs.map(le=>({...le.data(),moduleId:le.id}));Be(X),Ue(!1)},D=>{console.error("Error fetching teacher modules:",D),Ue(!1)});return()=>c()},[b]);const[et,je]=s.useState(!1),{weekRewards:nt,todayReward:_t,canClaim:Xe,isClaiming:wt,claimedDays:Ge,timeUntilReset:tt,claim:it,lastClaimResult:He}=Jr(x?.uid??null);s.useEffect(()=>{if(!x?.uid)return;let c=!1;const D=async L=>{c||(Xe||L)&&je(!0)},X=L=>{L.detail?.tab==="Modules"&&D(!0)},le=setTimeout(()=>D(),500);return window.addEventListener("mathpulse:navigate",X),()=>{c=!0,clearTimeout(le),window.removeEventListener("mathpulse:navigate",X)}},[x?.uid,Xe]);const Ve=async()=>{if(x?.uid)try{await it(),He?.success&&(fa({userId:x.uid,type:"daily_checkin",title:"Daily Reward Claimed!",message:`You earned ${He.reward.label} and kept your streak alive!`,metadata:{rewardId:He.reward.id,streakDay:He.dayIndex+1}}).catch(console.error),He.reward.rarity==="epic"&&Ls(x.uid,"acc_crown").then(()=>Bt.success("👑 Epic reward unlocked!")).catch(console.error)),setTimeout(()=>je(!1),1e3)}catch(c){const D=c instanceof Error?c.message:"";console.error("Failed to claim daily reward:",c),D.includes("Already claimed")?Bt.info("You already claimed your reward today!"):Bt.error("Failed to claim daily reward. Please try again.")}};s.useEffect(()=>{if(o){const c=re.find(D=>D.id===o);c&&ge(c)}},[o,re]),s.useEffect(()=>{x?.uid&&(ee(!0),xa(x.uid).then(c=>{T(c)}).catch(c=>{console.error("Failed to load competency profile:",c)}).finally(()=>{ee(!1)}))},[x?.uid]);const ye=s.useMemo(()=>{const c=l.length>0?l:a.map(X=>ma(X)).filter(X=>X!==null),D=new Set;return c.filter(X=>D.has(X)?!1:(D.add(X),!0))},[l,a]),{data:ve=[]}=Gs({queryKey:ua.modules(d,ye),enabled:!0,staleTime:600*1e3,gcTime:1800*1e3,queryFn:async()=>{const c=re;if(ye.length===0)return c;const D=new Map(ye.map((X,le)=>[ba[X],le]));return[...c].sort((X,le)=>{const L=D.get(X.id)??Number.POSITIVE_INFINITY,ke=D.get(le.id)??Number.POSITIVE_INFINITY;return L-ke})}}),Ne=s.useMemo(()=>{const c=new Set;return ve.forEach(D=>c.add(D.competency_group)),Array.from(c)},[ve]),st=s.useMemo(()=>{const c=A.trim().toLowerCase(),D=ve.filter(X=>{const le=!c||X.title.toLowerCase().includes(c),L=!c||X.description.toLowerCase().includes(c),ke=!c||X.lessons.some(Fe=>Fe.title.toLowerCase().includes(c)),Se=!c||X.quizzes.some(Fe=>Fe.title.toLowerCase().includes(c)),Le=c?X.competencies.some(Fe=>Fe.outcome.toLowerCase().includes(c)||Fe.code.toLowerCase().includes(c)):!0,oe=_==="all"||X.subjectId===_,ue=m==="all"||X.quarter===m,at=j==="all"||X.competency_group===j;return(le||L||ke||Se||Le)&&oe&&ue&&at});if(f?.competencies){const X=new Set(Object.entries(f.competencies).filter(([,L])=>L.score<50).map(([L])=>L)),le=new Set(Object.entries(f.competencies).filter(([,L])=>L.score>=80).map(([L])=>L));return D.sort((L,ke)=>{const Se=L.competencies.map(pe=>pe.code),Le=ke.competencies.map(pe=>pe.code),oe=Se.some(pe=>X.has(pe))?1:0,ue=Le.some(pe=>X.has(pe))?1:0,at=Se.some(pe=>le.has(pe))?1:0,Fe=Le.some(pe=>le.has(pe))?1:0,fe=oe*2+at;return ue*2+Fe-fe})}return D},[ve,A,_,m,j,f]),Qe=s.useMemo(()=>{const c=m==="all"?"All Quarters":m,D=_==="all"?"All Subjects":cs[_]?.label??"Subject";return`${d} · ${D} · ${c}`},[d,_,m]),ot=s.useMemo(()=>{const c=new Set(ve.map(D=>D.subjectId));return Array.from(c)},[ve]),Ye=()=>{R("all"),y("all"),E("all"),N("")};s.useEffect(()=>{b!=="recommended"||ye.length===0||(P(!0),pa({weakTopics:ye.map(c=>ds[c]),subject:_!=="all"?_:"General Mathematics",userId:x?.uid}).then(c=>{F(c.curriculumContext),P(!1)}).catch(()=>P(!1)))},[b,ye]);const Ke=(c,D)=>{t&&t(D,`Quiz Completed! +${D} XP`),we(null),r&&r(!1)};return K?(r&&r(!0),e.jsx(Rr,{quiz:K,onClose:()=>we(null),onComplete:Ke,studentId:x?.uid})):Z?e.jsx(_r,{module:Z,onBack:()=>ge(null),onEarnXP:t,isInQuizMode:n,setIsInQuizMode:r}):$?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:()=>te(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(pt,{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"}),$.quarter&&e.jsx("span",{className:"px-2 py-1 rounded-md bg-slate-100 text-slate-600 text-xs",children:$.quarter})]}),e.jsx("h1",{className:"text-2xl md:text-3xl font-display font-black text-slate-900 mb-2",children:$.title}),e.jsxs("p",{className:"text-sm text-slate-600 mb-6",children:[$.subject," · ",$.gradeLevel]}),$.summary&&e.jsx("p",{className:"text-slate-700 text-base leading-relaxed mb-6",children:$.summary}),$.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:$.learningObjectives.map((c,D)=>e.jsx("li",{children:c},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:$.sections.map((c,D)=>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:c.title}),e.jsx("p",{className:"text-sm text-slate-600 leading-relaxed",children:c.content})]},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:$.practice.map((c,D)=>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:c.question}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2 mb-2",children:c.options.map((X,le)=>e.jsxs("div",{className:"text-xs text-slate-600 bg-slate-50 rounded-lg px-3 py-2",children:[X.label,". ",X.text]},le))}),e.jsxs("p",{className:"text-xs text-emerald-700 font-semibold",children:["Answer: ",c.answer]}),e.jsx("p",{className:"text-xs text-slate-500 mt-1",children:c.explanation})]},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",onScroll:c=>U(c.currentTarget.scrollTop>100),children:[e.jsx(qr,{isOpen:et,onClose:()=>je(!1),onClaim:Ve,weekRewards:nt,todayReward:_t,canClaim:Xe,isClaiming:wt,claimedDays:Ge,currentDayIndex:ts(),timeUntilReset:tt}),e.jsxs("div",{className:"flex flex-col lg:flex-row justify-between items-start lg:items-center py-6 gap-6",children:[e.jsxs("div",{className:"flex-1 max-w-3xl",children:[e.jsx("h1",{className:"text-[36px] md:text-[44px] font-display font-black text-[#202124] tracking-tight leading-[1.1] mb-4",children:"Curriculum Modules"}),e.jsx("p",{className:"text-[#3c4043] text-[16px] md:text-[17px] 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:Qe})})]}),e.jsx("div",{className:"flex flex-shrink-0 items-center justify-center lg:justify-end w-full lg:w-[350px] mt-4 lg:mt-0",children:e.jsx(Er,{assessmentDismissed:x?.assessmentDismissed,initialAssessmentCompleted:x?.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 ${k?"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(Sa,{size:16,strokeWidth:2.5})}),e.jsx("input",{id:"modules-search",name:"modules-search","aria-label":"Search modules",type:"text",value:A,onChange:c=>N(c.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-wrap md:flex-nowrap items-center gap-2 w-full lg:w-auto shrink-0",children:[e.jsxs("select",{value:_,onChange:c=>R(c.target.value),className:"w-full md:w-auto 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"}),ot.map(c=>e.jsx("option",{value:c,children:cs[c].label},c))]}),e.jsx("select",{value:m,onChange:c=>y(c.target.value),className:"w-full md:w-auto 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:el.map(c=>e.jsx("option",{value:c,children:c==="all"?"All Quarters":c},c))}),e.jsxs("select",{value:j,onChange:c=>E(c.target.value),className:"w-full md:w-auto 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"}),Ne.map(c=>e.jsx("option",{value:c,children:c},c))]}),e.jsxs("button",{type:"button",onClick:Ye,className:"inline-flex w-full md:w-auto 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 shrink-0",children:[e.jsx(Ca,{size:14}),"Reset"]})]})]}),e.jsxs("div",{className:"flex items-center gap-3",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",children:[{id:"modules",label:"Modules",icon:Je,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:ha,color:"text-[#F08386]"}].map(c=>{const D=b===c.id;return e.jsxs("button",{onClick:()=>g(c.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 ${D?"shadow-sm":"text-slate-500 hover:text-slate-700 hover:bg-slate-200/50"}`,children:[D&&e.jsx(v.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 ${D?c.color:""}`,children:[e.jsx(c.icon,{size:15,strokeWidth:D?2.5:2}),c.label]})]},c.id)})}),e.jsxs("div",{className:"flex items-center gap-2 ml-1",children:[b==="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(ya,{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"})]}),b==="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(za,{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"})]}),b==="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"})]}),b==="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(us,{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.jsxs("div",{className:"pt-4",children:[ye.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(Ts,{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:()=>g("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(pt,{size:14})]})]}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:ye.map((c,D)=>e.jsxs("span",{className:"rounded-full bg-white px-3 py-1 text-xs font-semibold text-amber-900 shadow-sm",children:[D+1,". ",ds[c]]},c))})]}),e.jsx($e,{mode:"wait",children:e.jsx(v.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:b==="practice"?e.jsx(Mr,{onStartQuiz:we,searchQuery:A}):b==="teacher_uploaded"?gt?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(c=>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"})]},c))}):ne.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(us,{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-1 md:grid-cols-2 lg:grid-cols-3 gap-6 mt-6",children:ne.map(c=>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:()=>te(c),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"}),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("h3",{className:"text-lg font-bold text-slate-900 mb-2 line-clamp-2",children:c.title}),e.jsxs("p",{className:"text-sm text-slate-600 mb-3",children:[c.subject," · ",c.gradeLevel]}),c.summary&&e.jsx("p",{className:"text-xs text-slate-500 line-clamp-3",children:c.summary})]},c.moduleId))}):b==="modules"?e.jsx(tl,{modules:st,onSelectModule:ge,onPreviewSources:Y,isAtRisk:ye.length>0&&i,weakTopics:M?.assessmentResults?.weakTopics||[]}):e.jsx(sl,{modules:st,fullPool:ve,onSelectModule:ge,onPreviewSources:Y,isAtRisk:ye.length>0&&i,learningPathContext:Me,learningPathLoading:u,weakTopics:M?.assessmentResults?.weakTopics||[]})},b)})]}),e.jsx($e,{children:q&&e.jsxs(v.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:q.title}),e.jsxs("p",{className:"mt-1 text-sm text-slate-600",children:[q.active_grade_level," · ",q.subject," · ",q.quarter]})]}),e.jsx("button",{type:"button",onClick:()=>Y(null),className:"rounded-lg border border-slate-200 p-2 text-slate-500 hover:bg-slate-50",children:e.jsx(De,{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:q.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:q.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:q.competencies.map(c=>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:c.code}),e.jsx("p",{className:"mt-1 text-sm text-slate-700",children:c.outcome})]},c.code))})]})]})]})})]})},tl=({modules:t,onSelectModule:a,onPreviewSources:l,isAtRisk:o=!1,weakTopics:n=[]})=>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-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-3 gap-6",children:t.map((r,i)=>{const x=n.some(p=>r.content_domain&&r.content_domain.toLowerCase().includes(p.toLowerCase())||r.title&&r.title.toLowerCase().includes(p.toLowerCase())||r.competency_group&&r.competency_group.toLowerCase().includes(p.toLowerCase())||r.subject&&r.subject.toLowerCase().includes(p.toLowerCase()));return e.jsx(Wt,{module:r,index:i,onClick:()=>a(r),onPreviewSources:()=>l(r),isAtRisk:o,isRecommended:x},r.id)})})})}),sl=({modules:t,fullPool:a,onSelectModule:l,onPreviewSources:o,isAtRisk:n=!1,learningPathContext:r=null,learningPathLoading:i=!1,weakTopics:x=[]})=>{const p=t.filter(g=>g.progress>0&&g.progress<100),b=(t.length>0?t:a).filter(g=>g.progress===0).slice(0,6);return e.jsxs("div",{className:"pr-2 space-y-10",children:[i&&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..."})]}),r&&!i&&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:r})]}),p.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-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-3 gap-6",children:p.slice(0,4).map((g,M)=>{const z=x.some(d=>g.content_domain&&g.content_domain.toLowerCase().includes(d.toLowerCase())||g.title&&g.title.toLowerCase().includes(d.toLowerCase())||g.competency_group&&g.competency_group.toLowerCase().includes(d.toLowerCase())||g.subject&&g.subject.toLowerCase().includes(d.toLowerCase()));return e.jsx(Wt,{module:g,index:M,onClick:()=>l(g),onPreviewSources:()=>o(g),isAtRisk:n,badgeLabel:"In Progress",isRecommended:z},g.id)})})]}),e.jsx("div",{children:b.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-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-3 gap-6",children:b.map((g,M)=>{const z=x.some(d=>g.content_domain&&g.content_domain.toLowerCase().includes(d.toLowerCase())||g.title&&g.title.toLowerCase().includes(d.toLowerCase())||g.competency_group&&g.competency_group.toLowerCase().includes(d.toLowerCase())||g.subject&&g.subject.toLowerCase().includes(d.toLowerCase()));return e.jsx(Wt,{module:g,index:M,onClick:()=>l(g),onPreviewSources:()=>o(g),isAtRisk:n,badgeLabel:"Start",isRecommended:z},g.id)})})})]})};export{Hl as default}; +`,Er=({viewportHeight:t})=>e.jsx("div",{className:"absolute inset-0 pointer-events-none z-[250] overflow-hidden flex justify-between bg-slate-900/5",children:Ae.useMemo(()=>[...Array(40)].map((a,l)=>({id:l,left:`${Math.random()*100}%`,duration:.6+Math.random()*.4,delay:Math.random()*.4})),[t]).map(a=>e.jsx(v.div,{className:"absolute w-0.5 h-16 bg-blue-400/30 rounded-full",style:{left:a.left,top:"-10%"},animate:{y:[0,t*1.2]},transition:{duration:a.duration,ease:"linear",delay:a.delay}},a.id))}),Pr=()=>{const t=Ae.useMemo(()=>[...Array(60)].map((a,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(a=>e.jsx("div",{className:"confetti-piece",style:{left:a.left,top:"-10%",backgroundColor:a.backgroundColor,width:a.size,height:a.size,borderRadius:a.borderRadius,animationDuration:`${a.duration}s`,animationDelay:`${a.delay}s`}},a.id))})},Tr=({viewportHeight:t,viewportWidth:a})=>{const l=Ae.useMemo(()=>[...Array(30)].map((o,n)=>({id:n,xShift:(Math.random()-.5)*a*.8,yShift:(Math.random()-.5)*t*.8,scale:Math.random()*1.5+.5,duration:2+Math.random()*1.5,delay:Math.random()*.35})),[t,a]);return e.jsx("div",{className:"absolute inset-0 pointer-events-none z-[250] overflow-hidden flex items-center justify-center",children:l.map(o=>e.jsx(v.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,o.yShift],x:[0,o.xShift],scale:[0,o.scale,0],opacity:[0,1,0]},transition:{duration:o.duration,ease:"easeOut",delay:o.delay}},o.id))})},Ss=({value:t,label:a,delay:l=0,icon:o})=>{const[n,r]=Ae.useState(0);return Ae.useEffect(()=>{if(t<=0)return;const i=1e3,x=30,p=Math.abs(Math.floor(i/x));let b=0;const g=setTimeout(()=>{const M=setInterval(()=>{b+=Math.max(1,Math.floor(t/x)),b>=t?(r(t),clearInterval(M)):r(b)},p);return()=>clearInterval(M)},l);return()=>clearTimeout(g)},[t,l]),t<0?null:e.jsxs(v.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:[o,a]}),e.jsxs("div",{className:"text-xl font-black text-purple-600 tabular-nums",children:["+",n]})]})};function Lr(t){if(t.questionType==="multiple_choice"&&t.options&&t.options.length>0){const a=t.options.findIndex(l=>l.trim().toLowerCase()===t.correctAnswer.trim().toLowerCase());return{id:t.id,question:t.question,options:t.options,correctAnswer:a>=0?a: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 Cs(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 Ir(t,a,l){const o=n=>n.trim().toLowerCase().replace(/\s+/g," ");switch(l){case"identification":return o(t)===o(a);case"enumeration":{const n=t.split(",").map(i=>o(i)).filter(Boolean).sort(),r=a.split(",").map(i=>o(i)).filter(Boolean).sort();return JSON.stringify(n)===JSON.stringify(r)}case"word_problem":case"equation_based":{const n=Cs(t),r=Cs(a);if(n===r)return!0;const i=parseFloat(t.replace(/[^\d.\-]/g,"")),x=parseFloat(a.replace(/[^\d.\-]/g,""));return!isNaN(i)&&!isNaN(x)?Math.abs(i-x)<=.01:o(t)===o(a)}default:return o(t)===o(a)}}const Fr=({quiz:t,onClose:a,onComplete:l,studentId:o,atRiskSubjects:n=[]})=>{const[r,i]=s.useState(0),[x,p]=s.useState(null),[b,g]=s.useState(""),[M,z]=s.useState(!1),[d,A]=s.useState(!1),[N,_]=s.useState(!1),[R,m]=s.useState(0),[y,j]=s.useState(0),[E,k]=s.useState(1),[U,O]=s.useState([]),[Y,$]=s.useState([]),[te,de]=s.useState(Date.now()),[_e,re]=s.useState(!1),[W,Z]=s.useState(!1),[ge,K]=s.useState(null),[we,Me]=s.useState(0),[I,u]=s.useState(0),[P,f]=s.useState(!1),[T,F]=s.useState(!0),[ee,ne]=s.useState(!1),[Be,gt]=s.useState({width:1280,height:720});s.useEffect(()=>{const S=()=>gt({width:window.innerWidth,height:window.innerHeight});return S(),window.addEventListener("resize",S),()=>window.removeEventListener("resize",S)},[]);const[Ue,et]=s.useState(0),[je,nt]=s.useState({}),[_t,Xe]=s.useState(!1),[wt,Ge]=s.useState(!1),[tt,it]=s.useState(!1),{totalHintsAvailable:He}=Ar(o||null),[Ve,ye]=s.useState(5),[ve,Ne]=s.useState(15),st=Ve+He,[Qe,ot]=s.useState(null),[Ye,Ke]=s.useState(!1),[c,D]=s.useState(900*1e3),[X,le]=s.useState([]),[L,ke]=s.useState(0),[Se,Le]=s.useState(null),[ie]=s.useState(()=>t.loadedQuestions&&t.loadedQuestions.length>0?t.loadedQuestions.map(Lr):Array.from({length:t.questions},(S,h)=>({id:`q${h+1}`,question:Dr(t.subject,h),options:Rr(t.subject,h),correctAnswer:$r(t.subject,h),explanation:Br(t.subject,h,t.difficulty)})));s.useEffect(()=>{nt({}),le([]),ye(5),Ne(15),et(0),m(0),j(0),k(1)},[t.id]);const ue=ie[r];s.useEffect(()=>{const S=parseInt(t.duration)||10;Me(S*60);const h=setInterval(()=>{Me(H=>H<=1?(clearInterval(h),yt(),0):H-1)},1e3);return()=>clearInterval(h)},[]),s.useEffect(()=>{ve===0&&!Qe&&(ot(Date.now()),Ke(!0))},[ve,Qe]),s.useEffect(()=>{if(!Ye||!Qe)return;const S=setInterval(()=>{const h=Date.now()-Qe,H=Math.max(0,900*1e3-h);D(H)},1e3);return()=>clearInterval(S)},[Ye,Qe]);const[at,Ie]=s.useState(Array.from({length:15},(S,h)=>({id:h,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=S=>{if(T)try{const h=window.AudioContext||window.webkitAudioContext;if(!h)return;const H=new h,B=H.currentTime,Q=(Ce,Ee,he,Fe=.1,be="sine")=>{const xe=H.createOscillator(),qe=H.createGain();xe.type=be,xe.frequency.value=Ce,qe.gain.setValueAtTime(0,Ee),qe.gain.linearRampToValueAtTime(Fe,Ee+.05),qe.gain.exponentialRampToValueAtTime(.001,Ee+he),xe.connect(qe),qe.connect(H.destination),xe.start(Ee),xe.stop(Ee+he)};S==="correct"?(Q(880,B,.1,.1,"sine"),Q(1108.73,B+.1,.2,.1,"sine")):S==="incorrect"?(Q(300,B,.2,.05,"sawtooth"),Q(250,B+.15,.3,.05,"sawtooth")):S==="combo"?(Q(440,B,.1,.05,"square"),Q(554.37,B+.1,.1,.05,"square"),Q(659.25,B+.2,.1,.05,"square"),Q(880,B+.3,.4,.05,"square")):S==="complete"&&(Q(523.25,B,.1,.1),Q(659.25,B+.15,.1,.1),Q(783.99,B+.3,.1,.1),Q(1046.5,B+.45,.5,.1))}catch{}},yt=()=>{re(!0),vt()},pe=()=>{if(Ve<=0||d)return;const S=je[r]||[],h=ue.options.filter(B=>B!==ue.correctAnswerText).filter(B=>!S.includes(B));if(h.length===0)return;const H=h[Math.floor(Math.random()*h.length)];nt(B=>({...B,[r]:[...S,H]})),ye(B=>Math.max(0,B-1)),fe("correct")},Mt=S=>{d||oe||(p(S),setTimeout(()=>{jt(S)},150))},jt=S=>{const h=ue.questionType!=null&&ue.questionType!=="multiple_choice",H=S!==void 0?S:x;if(h){if(!b.trim())return}else if(H===null)return;const B=h?Ir(b,ue.correctAnswerText||"",ue.questionType||""):H===ue.correctAnswer,Q=h?b:String(H),Ce=Math.round((Date.now()-te)/1e3);$(xe=>[...xe,{questionId:ue.id,answer:Q,correct:B,timeSpent:Ce}]);const Ee=[...U];if(Ee[r]=B?1:0,O(Ee),z(B),A(!0),!B){Ge(!0),fe("incorrect"),setTimeout(()=>Ge(!1),500),Ne(xe=>Math.max(0,xe-1)),j(0),k(1),setTimeout(()=>{ct()},1500);return}fe("correct");const Fe=(je[r]||[]).length>0?5:10;et(xe=>xe+Fe),m(R+1);const be=y+1;j(be),be===2?Le("streak"):be===3&&E<2?Le("multiplier2"):be===5&&E<3&&Le("multiplier3"),be>0&&be%3===0&&fe("combo"),be>=5?k(3):be>=3?k(2):k(1),Lt(()=>import("./confetti.module-C94ZD2ww.js"),[]).then(xe=>{xe.default({particleCount:30,spread:40,colors:["#75D06A","#6ED1CF"],origin:{y:.6}})}),it(!0),setTimeout(()=>{it(!1),Le(null),setTimeout(()=>ct(),300)},1500)},ct=()=>{if(r{const S=Math.round(R/ie.length*100);let h=t.xpReward;S>=90?h=Math.round(h*1.5):S>=80&&(h=Math.round(h*1.25));const H=parseInt(t.duration)*60;we>H*.5&&(h=Math.round(h*1.2)),u(h);const B=H-we;o&&Na({lrn:o,quizId:t.id,subject:t.subject,score:S,totalQuestions:ie.length,correctAnswers:R,timeSpentSeconds:B}).catch(Q=>console.error("[WARN] Automation: quiz pipeline failed:",Q)),t.source==="ai_generated"&&o?wa(o,t.id,t.generatedQuizId,t.subject,t.source,S,h,B,Y,ie.map(Q=>({topic:Q.topic||t.subject,difficulty:Q.difficulty||"medium",bloomLevel:Q.bloomLevel||"understand"}))).catch(Q=>console.error("[WARN] Quiz result save failed:",Q)):o&&ia(o,t.id,t.subject,S,Y.map(Q=>({questionId:Q.questionId,selectedAnswer:Q.answer,isCorrect:Q.correct})),B).catch(Q=>console.error("[WARN] Practice quiz persist failed:",Q)),fe("complete")},oe=L{document.fullscreenElement?(document.exitFullscreen().catch(()=>{}),ne(!1)):(document.documentElement.requestFullscreen().catch(()=>{}),ne(!0))};if(_e){const S=Math.round(R/ie.length*100),h=S>=80,H=S>=50&&S<80,B=S<50,Q=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:ks}),h&&e.jsx(Pr,{}),H&&e.jsx(Tr,{viewportHeight:Be.height,viewportWidth:Be.width}),B&&e.jsx(Er,{viewportHeight:Be.height}),e.jsxs(v.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(v.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(v.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 ${h?"text-emerald-500":H?"text-amber-500":"text-rose-500"}`,children:h?"EXCELLENT!":H?"GOOD JOB!":"KEEP TRYING!"}),e.jsxs("p",{className:"text-slate-400 font-bold text-[10px] mb-3 uppercase tracking-widest",children:["Quiz Complete • Score: ",R,"/",ie.length]}),e.jsx(v.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(Ss,{value:R,label:"Correct Answers",delay:500,icon:e.jsx(lt,{className:"h-3 w-3 text-emerald-500"})}),e.jsx(Ss,{value:Ue,label:"Total XP Earned",delay:800,icon:e.jsx(Re,{className:"h-3 w-3 text-amber-500"})}),e.jsxs(v.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:[S,"%"]})]})]})]})}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(ze,{size:"lg",onClick:()=>{i(0),ke(0),p(null),g(""),m(0),j(0),k(1),O([]),$([]),et(0),re(!1),A(!1),_(!1),de(Date.now()),nt({}),le([]),Xe(!1),ye(5),Z(!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(ze,{size:"lg",onClick:a,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 PRACTICE CENTER"})]})]})]});return ut.createPortal(Ce,Q)}return e.jsxs(e.Fragment,{children:[e.jsx("style",{children:ks}),P&&ut.createPortal(e.jsx(v.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:()=>f(!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(De,{size:12})})]}),e.jsx(Is,{isOpen:!0,onClose:()=>f(!1),inline:!0})]})}),document.getElementById("modal-root")),Ye&&ut.createPortal(e.jsx("div",{className:"fixed inset-0 z-[200] flex items-center justify-center p-4 bg-slate-900/50",children:e.jsxs(v.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(v.div,{animate:{scale:[1,1.1,1]},transition:{duration:1,repeat:1/0},className:"text-6xl mb-4",children:"💔"}),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(c/6e4),":",Math.floor(c%6e4/1e3).toString().padStart(2,"0")]})," (15 minutes per heart)"]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(ze,{onClick:a,className:"w-full py-3 bg-rose-500 hover:bg-rose-600 text-white font-bold rounded-full",children:"Exit Quiz"}),e.jsx(ze,{onClick:()=>{Ke(!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($e,{children:tt&&M&&e.jsx(v.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:["+ ",(je[r]||[]).length>0?5:10," XP"]})}),Se==="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(As,{size:14})," Streak Started!"]}),Se==="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(Re,{size:14})," Multiplier ×2!"]}),Se==="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(Re,{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-start justify-between relative z-10 mb-4 sm:mb-6",children:[e.jsx("div",{className:"flex-1 flex items-center gap-2",children:e.jsxs("div",{className:"flex items-center gap-1 bg-white/20 px-3 py-1.5 rounded-full text-white text-sm font-bold",children:[e.jsx(ft,{size:16})," ",Hr(we)]})}),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:t.title||t.subject})]})]}),e.jsxs("div",{className:"flex-1 flex justify-end gap-2 sm:gap-3 relative pointer-events-auto",children:[e.jsx("button",{onClick:()=>F(!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(Fs,{size:20}):e.jsx(Ds,{size:20})}),e.jsx("button",{onClick:dt,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:ee?e.jsx(Rs,{size:20}):e.jsx($s,{size:20})}),e.jsx("button",{onClick:a,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(De,{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:ie.map((S,h)=>{let H=h<=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 ${H}`},h)})})})]}),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-8",children:[e.jsx("button",{onClick:()=>ke(S=>Math.max(0,S-1)),disabled:L===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 ${L===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(Yt,{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"})," ",ve]}),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"})," ",Ve]}),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"})," ",y]}),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:["+ ",Ue," pts"]})]})]}),e.jsx("button",{onClick:()=>ke(S=>Math.min(r,S+1)),disabled:L>=r,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 ${L>=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(ht,{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(v.div,{initial:{opacity:0,x:20},animate:wt?{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.jsxs("div",{className:"bg-slate-100 text-slate-600 px-4 py-1.5 rounded-full text-[11px] sm:text-xs font-black uppercase tracking-widest mb-4 flex items-center shadow-sm",children:["Q",L+1," of ",ie.length]}),e.jsx("h2",{className:"text-xl sm:text-2xl font-extrabold text-[#0a1628] leading-tight w-full",children:se.question.includes("___")?e.jsx("span",{children:se.question.split("___").map((S,h,H)=>e.jsxs(Ae.Fragment,{children:[S,hg(B.target.value),onKeyDown:B=>{B.key==="Enter"&&!d&&jt()},className:`inline-block w-24 mx-2 border-b-4 outline-none text-center bg-transparent font-bold ${oe?"border-slate-300 text-slate-500":"border-[#7C3AED] text-[#7C3AED] focus:border-[#75D06A]"}`})]},h))}):se.question})]}),e.jsxs("div",{className:"w-full flex flex-col items-center",children:[se.questionType==="multiple_choice"||!se.questionType?e.jsx("div",{className:"w-full grid grid-cols-1 sm:grid-cols-2 gap-3 sm:gap-5",children:(se.options||[]).map((S,h)=>{const H=je[r]||[],B=H.includes(S),Q=H.length,Ce=(se.options||[]).length-1,Ee=Ce>0&&Q>=Ce;let he="bg-white hover:bg-slate-50 border-transparent text-slate-700 hover:border-slate-200",Fe=!1;if(Ee){Fe=!0;const be=se.options?.[se.correctAnswer];S===be?he="bg-emerald-50 border-emerald-400 text-emerald-800":Y[L]?.answer===String(h)?he="bg-rose-50 border-rose-400 text-rose-800 opacity-80":he="bg-slate-100 border-slate-200 text-slate-400 opacity-40 line-through"}else if(B)he="bg-slate-100 border-slate-200 text-slate-400 opacity-40 line-through cursor-not-allowed";else if(oe){const be=h===se.correctAnswer,xe=L===r&&(x===h||ge===h)||L{Fe||oe||B||Mt(h)},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 ${he} ${Fe||oe||B?"cursor-default":"hover:shadow-md hover:-translate-y-0.5 active:translate-y-0"}`,children:[e.jsx("span",{className:"truncate pr-4",children:S}),B&&e.jsx(Ht,{size:20,className:"text-slate-400 shrink-0"}),oe&&h===se.correctAnswer&&e.jsx(zt,{size:22,className:"text-emerald-500 shrink-0"}),oe&&x===h&&h!==se.correctAnswer&&e.jsx(Ht,{size:22,className:"text-rose-500 shrink-0"})]},h)})}):e.jsx("div",{className:"w-full max-w-2xl mx-auto flex flex-col gap-4",children:!se.question.includes("___")&&e.jsx("input",{type:"text",disabled:oe,value:L===r?b:"",onChange:S=>g(S.target.value),onKeyDown:S=>{S.key==="Enter"&&!d&&jt()},placeholder:"Type your answer here...",className:`w-full p-4 sm:p-5 rounded-2xl border-[3px] font-extrabold text-lg text-center outline-none transition-colors ${oe?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"}`})}),oe&&N&&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:se.topic||t?.subject||"General Math"}),e.jsxs("p",{className:"text-sm text-slate-500",children:["Question ",L+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"})]}),oe&&N&&e.jsx(v.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 ${(L===r?M:Y[L]?.correct)?"bg-emerald-50 border-emerald-200":"bg-rose-50 border-rose-200"}`,children:[(L===r?M:Y[L]?.correct)?e.jsx(zt,{size:28,className:"text-emerald-500 shrink-0 mt-0.5"}):e.jsx(Ht,{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 ${(L===r?M:Y[L]?.correct)?"text-emerald-700":"text-rose-700"}`,children:(L===r?M:Y[L]?.correct)?"Correct!":"Incorrect"}),e.jsx("p",{className:`text-base leading-relaxed ${(L===r?M:Y[L]?.correct)?"text-emerald-800":"text-rose-800"}`,children:se.explanation||`Correct Answer: ${se.correctAnswerText||se.options?.[se.correctAnswer]}`})]})]})})]})]},L)}),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 S=(je[r]||[]).length,h=(ue.options||[]).length-1,H=h>0&&S>=h;return H||oe&&!M?e.jsxs("button",{onClick:ct,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 max-w-md mx-auto",children:[r{const Q=st>0&&!d&&!H;return e.jsxs("button",{onClick:pe,disabled:!Q,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:"Key",className:"w-5 h-5 object-contain"})," Hint"]})})(),oe&&e.jsxs("button",{onClick:()=>_(!0),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(Je,{size:20})," Explain"]}),e.jsx("button",{onClick:()=>f(Q=>!Q),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 ${P?"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"})]})})]}):Lke(r),className:"bg-white text-slate-700 font-extrabold text-lg px-6 sm:px-8 py-3 sm:py-4 rounded-full inline-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(ht,{size:20}),"Back to Current Question"]}):null})()})]})]})};function Dr(t,a){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"]},o=Dt(t),n=l[o]||l["General Mathematics"];return n[a%n.length]}function Dt(t){const a=t.toLowerCase();return a.includes("pre-calc")||a.includes("pre calc")||a.includes("precalc")?"Pre-Calculus":a.includes("statistic")||a.includes("probability")?"Statistics and Probability":a.includes("calculus")&&!a.includes("pre")?"Basic Calculus":a.includes("general")||a.includes("math")||a.includes("algebra")||a.includes("fraction")||a.includes("percent")||a.includes("ratio")||a.includes("geometry")?"General Mathematics":a.includes("derivative")||a.includes("integral")||a.includes("limit")?"Basic Calculus":a.includes("trig")||a.includes("function")||a.includes("log")?"Pre-Calculus":a.includes("mean")||a.includes("median")||a.includes("data")?"Statistics and Probability":"General Mathematics"}function Rr(t,a){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²"]]},o=Dt(t),n=l[o]||l["General Mathematics"];return n[a%n.length]}function $r(t,a){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]},o=Dt(t),n=l[o]||l["General Mathematics"];return n[a%n.length]}function Br(t,a,l){const o={"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."]},n=Dt(t),r=o[n]||o["General Mathematics"];return r[a%r.length]}function Hr(t){const a=Math.floor(t/60),l=t%60;return`${a}:${l.toString().padStart(2,"0")}`}const 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"],Qr=({isOpen:t,onClose:a,onClaim:l,weekRewards:o,todayReward:n,canClaim:r,isClaiming:i,claimedDays:x,currentDayIndex:p,timeUntilReset:b})=>{const[g,M]=s.useState(!1);if(!t)return null;const z=()=>{if(!r||g)return;M(!0),n?.rarity==="epic"?xs({particleCount:150,spread:80,origin:{y:.6},colors:["#FFD700","#FFA500","#FF8C00","#FF6B6B","#4ade80"]}):xs({particleCount:100,spread:70,origin:{y:.6},colors:["#FFD700","#FFA500","#FF8C00"]}),setTimeout(()=>{M(!1),l()},1200)},d=y=>y+1,A=y=>y===p,N=y=>x.includes(y),_=y=>y>p,R=o.slice(0,6),m=o[6];return e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4 sm:p-8",children:[e.jsx($e,{children:t&&e.jsx(v.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"absolute inset-0 bg-slate-900/60 backdrop-blur-sm",onClick:a})}),e.jsxs(v.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:a,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(De,{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:[R.map((y,j)=>{const E=d(j),k=N(j),U=A(j),O=_(j);return e.jsxs("div",{className:`relative rounded-xl flex flex-col overflow-hidden border-[1.5px] transition-all ${U&&!k?"border-amber-400 shadow-[0_0_15px_rgba(251,191,36,0.25)] scale-105 z-10 bg-amber-50":k?"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 ${U&&!k?"bg-amber-400 text-amber-900":_s[j]}`,children:["Day ",E]}),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[y.rarity]}`,children:y.rarity})}),e.jsxs("div",{className:"flex-1 p-2 flex flex-col items-center justify-center relative min-h-[75px]",children:[k&&e.jsxs(v.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-rose-200/50"})}),e.jsxs("div",{className:"relative w-14 h-14 rounded-full border-[3px] 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-10 h-10 object-contain drop-shadow-md"}),e.jsx("div",{className:"absolute -bottom-2.5 left-1/2 -translate-x-1/2 bg-rose-500 rounded-md px-2 py-0.5 border-2 border-rose-300 shadow-md",children:e.jsx("span",{className:"text-[9px] font-black text-white uppercase tracking-wider leading-none whitespace-nowrap",children:"Claimed"})})]})]}),O&&e.jsx("div",{className:"absolute top-1 right-1 bg-slate-200 rounded-full p-0.5 z-10",children:e.jsx(Vt,{size:8,className:"text-slate-400"})}),e.jsxs("div",{className:`flex flex-col items-center transition-all w-full ${k?"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:y.color+"20",borderColor:y.color+"40"},children:e.jsx("span",{className:"text-lg",children:y.icon})}),e.jsx("div",{className:`font-black text-xs leading-none mt-0.5 text-center ${U?"text-amber-600":k?"text-slate-500":"text-slate-600"}`,children:y.label})]})]})]},y.id)}),m&&e.jsxs("div",{className:`col-span-3 relative rounded-xl flex flex-col overflow-hidden border-[1.5px] transition-all mt-1 ${A(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 ${A(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[m.rarity]}`,children:m.rarity})}),e.jsxs("div",{className:"flex items-center justify-center gap-5 p-3 relative",children:[N(6)&&e.jsxs(v.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:m.color+"20",borderColor:m.color+"40"},children:e.jsx("span",{className:"text-2xl",children:m.icon})}),e.jsx("span",{className:`font-black text-sm ${A(6)?"text-amber-600":"text-slate-600"}`,children:m.label})]}),m.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("span",{className:"text-3xl drop-shadow-md",children:"🎁"})}),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(Ya,{size:14}),e.jsx("span",{className:"font-mono font-medium",children:b}),e.jsx("span",{children:"until next reset"})]}),e.jsx(v.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:z,disabled:!r||i||g,className:`w-[85%] py-3 rounded-full font-black text-base tracking-wide uppercase shadow-lg transition-all mt-2 ${!r||i||g?"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:i||g?"Claiming...":r?"Claim!":"Claimed"})]})]})};function qr(t){const[a,l]=s.useState({difficulty:"normal",loading:!0});return s.useEffect(()=>{if(!t){l({difficulty:"normal",loading:!1});return}const o=bt(We,"users",t);return Gt(o,r=>{if(!r.exists()){l({difficulty:"normal",loading:!1});return}const x=r.data()?.moduleDifficulty||"normal";l({difficulty:["normal","easier","remedial"].includes(x)?x:"normal",loading:!1})},r=>{console.error("[useModuleDifficulty] snapshot error:",r),l({difficulty:"normal",loading:!1})})},[t]),a}function Or(t,a){return a==="normal"?t:a==="easier"?t.filter(l=>{const o=l.tags||[],n=l.difficulty||"";return o.some(r=>["foundation","basic","introductory"].includes(r.toLowerCase()))||["foundation","basic","introductory"].includes(n.toLowerCase())||!o.includes("advanced")&&!n.toLowerCase().includes("advanced")}):a==="remedial"?t.filter(l=>{const o=l.tags||[],n=l.difficulty||"";return o.some(r=>["remedial","review","catch-up"].includes(r.toLowerCase()))||["remedial","review","catch-up"].includes(n.toLowerCase())}):t}const Wr=new Set([7,14,30,60,100]),St={lastClaimedDate:"",lastClaimedWeekSeed:0,claimedDays:[],currentStreak:0,longestStreak:0,totalClaimed:0,hintTokens:0,streakShields:0,activeMultiplier:null};function Ur(t){if(t<=0)return"00:00:00";const a=Math.floor(t/1e3),l=Math.floor(a/3600),o=Math.floor(a%3600/60),n=a%60;return`${String(l).padStart(2,"0")}:${String(o).padStart(2,"0")}:${String(n).padStart(2,"0")}`}function Xr(){const t=Jt();return t.setDate(t.getDate()-1),Zt(t)}function Os(t){return t?new Date(t.expiresAt).getTime()>Date.now():!1}function Ws(t){return bt(We,"users",t,"dailyRewards",t)}function Gr(t){return bt(We,"users",t)}async function Ms(t){try{const a=Ws(t),l=await Ot(a);if(!l.exists())return{...St};const o=l.data(),n=es();return o.lastClaimedWeekSeed&&o.lastClaimedWeekSeed!==n?{...o,claimedDays:[],lastClaimedWeekSeed:n}:{...St,...o,activeMultiplier:o.activeMultiplier&&Os(o.activeMultiplier)?o.activeMultiplier:null}}catch(a){return console.error("[dailyRewardService] Error getting state:",a),{...St}}}function Vr(t){const a=Zt();return t.lastClaimedDate!==a}async function Yr(t){const a=Zt(),l=es(),o=ts(),r=ss()[o];if(!r)throw new Error(`No reward found for day index ${o}`);try{const i=await Vs(We,async p=>{const b=Ws(t),g=Gr(t),M=await p.get(b),z=await p.get(g);let d;if(M.exists()?d={...St,...M.data()}:(d={...St,lastClaimedWeekSeed:l},p.set(b,d)),d.lastClaimedWeekSeed!==l&&(d.claimedDays=[],d.lastClaimedWeekSeed=l),d.lastClaimedDate===a)return{code:"ALREADY_CLAIMED",state:d};let A=d.currentStreak,N=!1;if(!d.lastClaimedDate||d.currentStreak===0)A=1;else{const j=Xr();d.lastClaimedDate===j?A=d.currentStreak+1:d.streakShields>0?(d.streakShields-=1,A=d.currentStreak+1,N=!0):A=1}const _=Math.max(d.longestStreak,A);let R=0,m=1;switch(r.type){case"xp":{const j=typeof r.value=="number"?r.value:parseInt(r.value,10)||0;m=Os(d.activeMultiplier)?d.activeMultiplier?.multiplier??1:1,R=Math.floor(j*m);break}case"hint_token":{const j=typeof r.value=="number"?r.value:parseInt(r.value,10)||0;d.hintTokens+=j;break}case"streak_shield":{const j=typeof r.value=="number"?r.value:parseInt(r.value,10)||0;d.streakShields+=j;break}case"xp_multiplier":{const j=typeof r.value=="number"?r.value:parseInt(r.value,10)||60,E=r.id.includes("2")?2:1.5,k=new Date;k.setMinutes(k.getMinutes()+j),d.activeMultiplier={multiplier:E,expiresAt:k.toISOString()};break}case"badge_unlock":break}const y=[...d.claimedDays,o];return d.lastClaimedDate=a,d.currentStreak=A,d.longestStreak=_,d.totalClaimed+=1,p.set(b,d,{merge:!0}),z.exists()&&p.update(g,{hintTokens:d.hintTokens,streakShields:d.streakShields,activeMultiplier:d.activeMultiplier,lastClaimedDate:d.lastClaimedDate,updatedAt:Ys()}),{code:"SUCCESS",state:d,newClaimedDays:y,newStreak:A,newLongestStreak:_,xpAwarded:R,multiplierApplied:m,streakPreserved:N}});if(i.code==="ALREADY_CLAIMED")return{success:!1,reward:r,dayIndex:o,streakAfter:i.state.currentStreak,longestStreakAfter:i.state.longestStreak,hintTokensAfter:i.state.hintTokens,streakShieldsAfter:i.state.streakShields,streakPreserved:!1,xpAwarded:0,multiplierApplied:1,isMilestone:!1,error:"Already claimed today"};if(i.xpAwarded>0)try{await oa(t,i.xpAwarded,"daily_reward",`Daily Reward Day ${o+1}! +${i.xpAwarded} XP`)}catch(p){console.error("[dailyRewardService] Error awarding XP:",p)}if(r.type==="badge_unlock"&&typeof r.value=="string")try{await Ls(t,r.value)}catch(p){console.error("[dailyRewardService] Error unlocking avatar item:",p)}const x=Wr.has(i.newStreak);return{success:!0,reward:r,dayIndex:o,streakAfter:i.newStreak,longestStreakAfter:i.newLongestStreak,hintTokensAfter:i.state.hintTokens,streakShieldsAfter:i.state.streakShields,streakPreserved:i.streakPreserved,xpAwarded:i.xpAwarded,multiplierApplied:i.multiplierApplied,isMilestone:x}}catch(i){throw console.error("[dailyRewardService] Error claiming daily reward:",i),i}}function Kr(t){const[a,l]=s.useState(null),[o,n]=s.useState(!1),[r,i]=s.useState(!1),[x,p]=s.useState(null),[b,g]=s.useState(null),[M,z]=s.useState("00:00:00"),d=s.useRef(null),A=s.useMemo(()=>ss(),[]),N=s.useMemo(()=>ar(),[]),_=s.useCallback(async()=>{if(!t){l(null);return}try{g(null);const E=await Ms(t);l(E)}catch(E){const k=E instanceof Error?E.message:"Failed to load rewards";g(k),console.error("[useDailyReward] refresh error:",E)}},[t]);s.useEffect(()=>{_()},[_]),s.useEffect(()=>{const E=()=>{const U=er().getTime()-Date.now();z(Ur(U))};return E(),d.current=setInterval(E,1e3),()=>{d.current&&(clearInterval(d.current),d.current=null)}},[]);const R=s.useMemo(()=>!a||o?!1:Vr(a),[a,o]),m=s.useMemo(()=>!a?.activeMultiplier||new Date(a.activeMultiplier.expiresAt).getTime()<=Date.now()?null:a.activeMultiplier,[a?.activeMultiplier]),y=s.useCallback(async()=>{if(!(!t||!R)){n(!0),g(null);try{const E=await Yr(t);if(p(E),E.success){i(!0);const k=await Ms(t);l(k)}else g(E.error||"Claim failed")}catch(E){const k=E instanceof Error?E.message:"Claim failed";g(k),console.error("[useDailyReward] claim error:",E)}finally{n(!1)}}},[t,R]),j=s.useCallback(()=>{i(!1)},[]);return{weekRewards:A,todayReward:N,canClaim:R,isClaiming:o,claimedDays:a?.claimedDays??[],currentStreak:a?.currentStreak??0,longestStreak:a?.longestStreak??0,totalClaimed:a?.totalClaimed??0,hintTokens:a?.hintTokens??0,streakShields:a?.streakShields??0,activeMultiplier:m,timeUntilReset:M,showModal:r,lastClaimResult:x,error:b,claim:y,dismissModal:j,refresh:_}}const Zr=["all","Q1","Q2","Q3","Q4"],$l=({onEarnXP:t,atRiskSubjects:a=[],priorityTopics:l=[],initialModuleId:o=null,isInQuizMode:n=!1,setIsInQuizMode:r,hasCompletedDiagnostic:i=!1})=>{const{userProfile:x,currentUser:p}=It(),[b,g]=s.useState("modules"),M=x,z=M?.grade,d=ca(z);ka(d);const[A,N]=s.useState(""),[_,R]=s.useState("all"),[m,y]=s.useState("all"),[j,E]=s.useState("all"),[k,U]=s.useState(!1),[O,Y]=s.useState(null),[$,te]=s.useState(null),de=s.useMemo(()=>{const c=M?.learnerCurriculumAssignments?.subjects??M?.assignedSubjects??M?.curriculumAssignedSubjects??[];return Array.isArray(c)?c:[]},[M]),{difficulty:_e}=qr(p?.uid||null),re=s.useMemo(()=>{const c=da(d,de);return Or(c,_e)},[d,de,_e]),W=o&&re.find(c=>c.id===o)||null,[Z,ge]=s.useState(W),[K,we]=s.useState(null),[Me,I]=s.useState(null),[u,P]=s.useState(!1),[f,T]=s.useState(null),[F,ee]=s.useState(!1),[ne,Be]=s.useState([]),[gt,Ue]=s.useState(!1);s.useEffect(()=>{if(b!=="teacher_uploaded"||!We)return;Ue(!0);const c=Gt(Ks(Js(We,"modules"),Zs("moduleType","==","teacher_uploaded")),D=>{const X=D.docs.map(le=>({...le.data(),moduleId:le.id}));Be(X),Ue(!1)},D=>{console.error("Error fetching teacher modules:",D),Ue(!1)});return()=>c()},[b]);const[et,je]=s.useState(!1),{weekRewards:nt,todayReward:_t,canClaim:Xe,isClaiming:wt,claimedDays:Ge,timeUntilReset:tt,claim:it,lastClaimResult:He}=Kr(x?.uid??null);s.useEffect(()=>{if(!x?.uid)return;let c=!1;const D=async L=>{c||(Xe||L)&&je(!0)},X=L=>{L.detail?.tab==="Modules"&&D(!0)},le=setTimeout(()=>D(),500);return window.addEventListener("mathpulse:navigate",X),()=>{c=!0,clearTimeout(le),window.removeEventListener("mathpulse:navigate",X)}},[x?.uid,Xe]);const Ve=async()=>{if(x?.uid)try{await it(),He?.success&&(fa({userId:x.uid,type:"daily_checkin",title:"Daily Reward Claimed!",message:`You earned ${He.reward.label} and kept your streak alive!`,metadata:{rewardId:He.reward.id,streakDay:He.dayIndex+1}}).catch(console.error),He.reward.rarity==="epic"&&Ls(x.uid,"acc_crown").then(()=>Bt.success("👑 Epic reward unlocked!")).catch(console.error)),setTimeout(()=>je(!1),1e3)}catch(c){const D=c instanceof Error?c.message:"";console.error("Failed to claim daily reward:",c),D.includes("Already claimed")?Bt.info("You already claimed your reward today!"):Bt.error("Failed to claim daily reward. Please try again.")}};s.useEffect(()=>{if(o){const c=re.find(D=>D.id===o);c&&ge(c)}},[o,re]),s.useEffect(()=>{x?.uid&&(ee(!0),xa(x.uid).then(c=>{T(c)}).catch(c=>{console.error("Failed to load competency profile:",c)}).finally(()=>{ee(!1)}))},[x?.uid]);const ye=s.useMemo(()=>{const c=l.length>0?l:a.map(X=>ma(X)).filter(X=>X!==null),D=new Set;return c.filter(X=>D.has(X)?!1:(D.add(X),!0))},[l,a]),{data:ve=[]}=Gs({queryKey:ua.modules(d,ye),enabled:!0,staleTime:600*1e3,gcTime:1800*1e3,queryFn:async()=>{const c=re;if(ye.length===0)return c;const D=new Map(ye.map((X,le)=>[ba[X],le]));return[...c].sort((X,le)=>{const L=D.get(X.id)??Number.POSITIVE_INFINITY,ke=D.get(le.id)??Number.POSITIVE_INFINITY;return L-ke})}}),Ne=s.useMemo(()=>{const c=new Set;return ve.forEach(D=>c.add(D.competency_group)),Array.from(c)},[ve]),st=s.useMemo(()=>{const c=A.trim().toLowerCase(),D=ve.filter(X=>{const le=!c||X.title.toLowerCase().includes(c),L=!c||X.description.toLowerCase().includes(c),ke=!c||X.lessons.some(Ie=>Ie.title.toLowerCase().includes(c)),Se=!c||X.quizzes.some(Ie=>Ie.title.toLowerCase().includes(c)),Le=c?X.competencies.some(Ie=>Ie.outcome.toLowerCase().includes(c)||Ie.code.toLowerCase().includes(c)):!0,ie=_==="all"||X.subjectId===_,ue=m==="all"||X.quarter===m,at=j==="all"||X.competency_group===j;return(le||L||ke||Se||Le)&&ie&&ue&&at});if(f?.competencies){const X=new Set(Object.entries(f.competencies).filter(([,L])=>L.score<50).map(([L])=>L)),le=new Set(Object.entries(f.competencies).filter(([,L])=>L.score>=80).map(([L])=>L));return D.sort((L,ke)=>{const Se=L.competencies.map(pe=>pe.code),Le=ke.competencies.map(pe=>pe.code),ie=Se.some(pe=>X.has(pe))?1:0,ue=Le.some(pe=>X.has(pe))?1:0,at=Se.some(pe=>le.has(pe))?1:0,Ie=Le.some(pe=>le.has(pe))?1:0,fe=ie*2+at;return ue*2+Ie-fe})}return D},[ve,A,_,m,j,f]),Qe=s.useMemo(()=>{const c=m==="all"?"All Quarters":m,D=_==="all"?"All Subjects":cs[_]?.label??"Subject";return`${d} · ${D} · ${c}`},[d,_,m]),ot=s.useMemo(()=>{const c=new Set(ve.map(D=>D.subjectId));return Array.from(c)},[ve]),Ye=()=>{R("all"),y("all"),E("all"),N("")};s.useEffect(()=>{b!=="recommended"||ye.length===0||(P(!0),pa({weakTopics:ye.map(c=>ds[c]),subject:_!=="all"?_:"General Mathematics",userId:x?.uid}).then(c=>{I(c.curriculumContext),P(!1)}).catch(()=>P(!1)))},[b,ye]);const Ke=(c,D)=>{t&&t(D,`Quiz Completed! +${D} XP`),we(null),r&&r(!1)};return K?(r&&r(!0),e.jsx(Fr,{quiz:K,onClose:()=>we(null),onComplete:Ke,studentId:x?.uid})):Z?e.jsx(Cr,{module:Z,onBack:()=>ge(null),onEarnXP:t,isInQuizMode:n,setIsInQuizMode:r}):$?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:()=>te(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(pt,{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"}),$.quarter&&e.jsx("span",{className:"px-2 py-1 rounded-md bg-slate-100 text-slate-600 text-xs",children:$.quarter})]}),e.jsx("h1",{className:"text-2xl md:text-3xl font-display font-black text-slate-900 mb-2",children:$.title}),e.jsxs("p",{className:"text-sm text-slate-600 mb-6",children:[$.subject," · ",$.gradeLevel]}),$.summary&&e.jsx("p",{className:"text-slate-700 text-base leading-relaxed mb-6",children:$.summary}),$.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:$.learningObjectives.map((c,D)=>e.jsx("li",{children:c},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:$.sections.map((c,D)=>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:c.title}),e.jsx("p",{className:"text-sm text-slate-600 leading-relaxed",children:c.content})]},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:$.practice.map((c,D)=>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:c.question}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2 mb-2",children:c.options.map((X,le)=>e.jsxs("div",{className:"text-xs text-slate-600 bg-slate-50 rounded-lg px-3 py-2",children:[X.label,". ",X.text]},le))}),e.jsxs("p",{className:"text-xs text-emerald-700 font-semibold",children:["Answer: ",c.answer]}),e.jsx("p",{className:"text-xs text-slate-500 mt-1",children:c.explanation})]},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",onScroll:c=>U(c.currentTarget.scrollTop>100),children:[e.jsx(Qr,{isOpen:et,onClose:()=>je(!1),onClaim:Ve,weekRewards:nt,todayReward:_t,canClaim:Xe,isClaiming:wt,claimedDays:Ge,currentDayIndex:ts(),timeUntilReset:tt}),e.jsxs("div",{className:"flex flex-col lg:flex-row justify-between items-start lg:items-center py-6 gap-6",children:[e.jsxs("div",{className:"flex-1 max-w-3xl",children:[e.jsx("h1",{className:"text-[36px] md:text-[44px] font-display font-black text-[#202124] tracking-tight leading-[1.1] mb-4",children:"Curriculum Modules"}),e.jsx("p",{className:"text-[#3c4043] text-[16px] md:text-[17px] 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:Qe})})]}),e.jsx("div",{className:"flex flex-shrink-0 items-center justify-center lg:justify-end w-full lg:w-[350px] mt-4 lg:mt-0",children:e.jsx(Mr,{assessmentDismissed:x?.assessmentDismissed,initialAssessmentCompleted:x?.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 ${k?"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(Sa,{size:16,strokeWidth:2.5})}),e.jsx("input",{id:"modules-search",name:"modules-search","aria-label":"Search modules",type:"text",value:A,onChange:c=>N(c.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-wrap md:flex-nowrap items-center gap-2 w-full lg:w-auto shrink-0",children:[e.jsxs("select",{value:_,onChange:c=>R(c.target.value),className:"w-full md:w-auto 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"}),ot.map(c=>e.jsx("option",{value:c,children:cs[c].label},c))]}),e.jsx("select",{value:m,onChange:c=>y(c.target.value),className:"w-full md:w-auto 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:Zr.map(c=>e.jsx("option",{value:c,children:c==="all"?"All Quarters":c},c))}),e.jsxs("select",{value:j,onChange:c=>E(c.target.value),className:"w-full md:w-auto 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"}),Ne.map(c=>e.jsx("option",{value:c,children:c},c))]}),e.jsxs("button",{type:"button",onClick:Ye,className:"inline-flex w-full md:w-auto 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 shrink-0",children:[e.jsx(Ca,{size:14}),"Reset"]})]})]}),e.jsxs("div",{className:"flex items-center gap-3",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",children:[{id:"modules",label:"Modules",icon:Je,color:"text-[#1FA7E1]"},{id:"recommended",label:"Recommended",icon:Pt,color:"text-[#75D06A]"},{id:"practice",label:"Practice",icon:Oe,color:"text-[#FFB356]"},{id:"teacher_uploaded",label:"Teacher Uploaded",icon:ha,color:"text-[#F08386]"}].map(c=>{const D=b===c.id;return e.jsxs("button",{onClick:()=>g(c.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 ${D?"shadow-sm":"text-slate-500 hover:text-slate-700 hover:bg-slate-200/50"}`,children:[D&&e.jsx(v.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 ${D?c.color:""}`,children:[e.jsx(c.icon,{size:15,strokeWidth:D?2.5:2}),c.label]})]},c.id)})}),e.jsxs("div",{className:"flex items-center gap-2 ml-1",children:[b==="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(ya,{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"})]}),b==="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(za,{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"})]}),b==="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(Oe,{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"})]}),b==="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(ms,{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.jsxs("div",{className:"pt-4",children:[ye.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(Ts,{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:()=>g("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(pt,{size:14})]})]}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:ye.map((c,D)=>e.jsxs("span",{className:"rounded-full bg-white px-3 py-1 text-xs font-semibold text-amber-900 shadow-sm",children:[D+1,". ",ds[c]]},c))})]}),e.jsx($e,{mode:"wait",children:e.jsx(v.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:b==="practice"?e.jsx(zr,{onStartQuiz:we,searchQuery:A}):b==="teacher_uploaded"?gt?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(c=>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"})]},c))}):ne.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(ms,{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-1 md:grid-cols-2 lg:grid-cols-3 gap-6 mt-6",children:ne.map(c=>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:()=>te(c),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"}),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("h3",{className:"text-lg font-bold text-slate-900 mb-2 line-clamp-2",children:c.title}),e.jsxs("p",{className:"text-sm text-slate-600 mb-3",children:[c.subject," · ",c.gradeLevel]}),c.summary&&e.jsx("p",{className:"text-xs text-slate-500 line-clamp-3",children:c.summary})]},c.moduleId))}):b==="modules"?e.jsx(Jr,{modules:st,onSelectModule:ge,onPreviewSources:Y,isAtRisk:ye.length>0&&i,weakTopics:M?.assessmentResults?.weakTopics||[]}):e.jsx(el,{modules:st,fullPool:ve,onSelectModule:ge,onPreviewSources:Y,isAtRisk:ye.length>0&&i,learningPathContext:Me,learningPathLoading:u,weakTopics:M?.assessmentResults?.weakTopics||[]})},b)})]}),e.jsx($e,{children:O&&e.jsxs(v.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:O.title}),e.jsxs("p",{className:"mt-1 text-sm text-slate-600",children:[O.active_grade_level," · ",O.subject," · ",O.quarter]})]}),e.jsx("button",{type:"button",onClick:()=>Y(null),className:"rounded-lg border border-slate-200 p-2 text-slate-500 hover:bg-slate-50",children:e.jsx(De,{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:O.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:O.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:O.competencies.map(c=>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:c.code}),e.jsx("p",{className:"mt-1 text-sm text-slate-700",children:c.outcome})]},c.code))})]})]})]})})]})},Jr=({modules:t,onSelectModule:a,onPreviewSources:l,isAtRisk:o=!1,weakTopics:n=[]})=>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-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-3 gap-6",children:t.map((r,i)=>{const x=n.some(p=>r.content_domain&&r.content_domain.toLowerCase().includes(p.toLowerCase())||r.title&&r.title.toLowerCase().includes(p.toLowerCase())||r.competency_group&&r.competency_group.toLowerCase().includes(p.toLowerCase())||r.subject&&r.subject.toLowerCase().includes(p.toLowerCase()));return e.jsx(Wt,{module:r,index:i,onClick:()=>a(r),onPreviewSources:()=>l(r),isAtRisk:o,isRecommended:x},r.id)})})})}),el=({modules:t,fullPool:a,onSelectModule:l,onPreviewSources:o,isAtRisk:n=!1,learningPathContext:r=null,learningPathLoading:i=!1,weakTopics:x=[]})=>{const p=t.filter(g=>g.progress>0&&g.progress<100),b=(t.length>0?t:a).filter(g=>g.progress===0).slice(0,6);return e.jsxs("div",{className:"pr-2 space-y-10",children:[i&&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..."})]}),r&&!i&&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:r})]}),p.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-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-3 gap-6",children:p.slice(0,4).map((g,M)=>{const z=x.some(d=>g.content_domain&&g.content_domain.toLowerCase().includes(d.toLowerCase())||g.title&&g.title.toLowerCase().includes(d.toLowerCase())||g.competency_group&&g.competency_group.toLowerCase().includes(d.toLowerCase())||g.subject&&g.subject.toLowerCase().includes(d.toLowerCase()));return e.jsx(Wt,{module:g,index:M,onClick:()=>l(g),onPreviewSources:()=>o(g),isAtRisk:n,badgeLabel:"In Progress",isRecommended:z},g.id)})})]}),e.jsx("div",{children:b.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-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-3 gap-6",children:b.map((g,M)=>{const z=x.some(d=>g.content_domain&&g.content_domain.toLowerCase().includes(d.toLowerCase())||g.title&&g.title.toLowerCase().includes(d.toLowerCase())||g.competency_group&&g.competency_group.toLowerCase().includes(d.toLowerCase())||g.subject&&g.subject.toLowerCase().includes(d.toLowerCase()));return e.jsx(Wt,{module:g,index:M,onClick:()=>l(g),onPreviewSources:()=>o(g),isAtRisk:n,badgeLabel:"Start",isRecommended:z},g.id)})})})]})};export{$l as default}; diff --git a/assets/ProfileModal-Gwxh5tYO.js b/assets/ProfileModal-bQKyq1JA.js similarity index 92% rename from assets/ProfileModal-Gwxh5tYO.js rename to assets/ProfileModal-bQKyq1JA.js index b11dc6766a1cf1c86a086ef2b61b97cdba8d8c1d..d22227a056f0524def9180825309c3675b3662cf 100644 --- a/assets/ProfileModal-Gwxh5tYO.js +++ b/assets/ProfileModal-bQKyq1JA.js @@ -1,11 +1,11 @@ -import{r,j as e}from"./vendor-react-B4AQeu28.js";import{B as c}from"./button-DCfeFHoH.js";import{I as d}from"./input-D28h_UTJ.js";import{S as _,a as R,c as U,d as h}from"./select-DIjxRWza.js";import{e as S,j as D,m as k,U as u,A as x,a as w,z as B,aM as T,aD as q,aO as G}from"./index-BaOs5Ayg.js";import{P as V,M as z,V as C}from"./ProfilePictureUploader-CX_IZAwE.js";import{X}from"./x-TNvtuOD9.js";import{M as Y}from"./mail-BbG1phxL.js";import{C as L}from"./circle-help-B8apTIdU.js";import{S as $}from"./save-CQIJrhLf.js";import"./vendor-radix-BorKzPz9.js";import"./vendor-charts-D8hf8tI0.js";import"./chevron-up-Cdvz2TMJ.js";import"./check-BLSo9L0H.js";import"./vendor-firebase-firestore-CH1lNiRF.js";import"./vendor-firebase-core-CO26nNq6.js";import"./vendor-firebase-auth-BLpRW_zO.js";import"./vendor-firebase-storage-B3igpVVS.js";import"./vendor-firebase-analytics-CTiUNb0-.js";import"./vendor-markdown-yqZQ_iQm.js";import"./minus-DfrEv-SC.js";import"./plus-DkG35AoH.js";import"./upload-DayXhGwD.js";/** +import{r,j as e}from"./vendor-react-B4AQeu28.js";import{B as c}from"./button-BPmLcOpC.js";import{I as d}from"./input--XHWlmp1.js";import{S as _,a as R,c as U,d as h}from"./select--QYuvUGV.js";import{e as S,g as D,m as k,U as u,A as x,a as w,D as B,aN as T,aE as q,aP as G}from"./index-uASBzalf.js";import{P as V,M as z,V as C}from"./ProfilePictureUploader-CyCaD4jN.js";import{X}from"./x-CBb03rh3.js";import{M as Y}from"./mail-BF4xxwnI.js";import{C as L}from"./circle-help-PS1uII8x.js";import{S as $}from"./save-CoDXj-im.js";import"./vendor-radix-xDOIcVzp.js";import"./vendor-charts-Ckgeb0nY.js";import"./chevron-up-BpMhRyJp.js";import"./check-Dk6iwDFI.js";import"./vendor-firebase-firestore-CP9q7ISf.js";import"./vendor-firebase-core-DCQrgkxC.js";import"./vendor-firebase-auth-Bcpr4O6E.js";import"./vendor-firebase-storage-dc5X5yTv.js";import"./vendor-firebase-analytics-CHPyhRzk.js";import"./vendor-markdown-yqZQ_iQm.js";import"./minus-Bfei9C79.js";import"./plus-Cy6hz5PP.js";import"./upload-Ds5w3QNw.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=[["rect",{width:"16",height:"20",x:"4",y:"2",rx:"2",ry:"2",key:"76otgf"}],["path",{d:"M9 22v-4h6v4",key:"r93iot"}],["path",{d:"M8 6h.01",key:"1dz90k"}],["path",{d:"M16 6h.01",key:"1x0f13"}],["path",{d:"M12 6h.01",key:"1vi96p"}],["path",{d:"M12 10h.01",key:"1nrarc"}],["path",{d:"M12 14h.01",key:"1etili"}],["path",{d:"M16 10h.01",key:"1m94wz"}],["path",{d:"M16 14h.01",key:"1gbofw"}],["path",{d:"M8 10h.01",key:"19clt8"}],["path",{d:"M8 14h.01",key:"6423bh"}]],H=S("building",O);/** + */const H=[["rect",{width:"16",height:"20",x:"4",y:"2",rx:"2",ry:"2",key:"76otgf"}],["path",{d:"M9 22v-4h6v4",key:"r93iot"}],["path",{d:"M8 6h.01",key:"1dz90k"}],["path",{d:"M16 6h.01",key:"1x0f13"}],["path",{d:"M12 6h.01",key:"1vi96p"}],["path",{d:"M12 10h.01",key:"1nrarc"}],["path",{d:"M12 14h.01",key:"1etili"}],["path",{d:"M16 10h.01",key:"1m94wz"}],["path",{d:"M16 14h.01",key:"1gbofw"}],["path",{d:"M8 10h.01",key:"19clt8"}],["path",{d:"M8 14h.01",key:"6423bh"}]],K=S("building",H);/** * @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 K=[["path",{d:"M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z",key:"foiqr5"}]],Q=S("phone",K),ye=({isOpen:i,onClose:o,profileData:p,onSave:M})=>{const[s,t]=r.useState(p),[l,b]=r.useState(!1),[E,g]=r.useState(!1),[m,j]=r.useState([]),[y,v]=r.useState(0);r.useEffect(()=>{if(!i)return;const a=n=>{n.key==="Escape"&&o()};return window.addEventListener("keydown",a),()=>window.removeEventListener("keydown",a)},[i,o]),r.useEffect(()=>{if(!i||s.role!=="student"||!s.uid)return;const a=s.uid;(async()=>{g(!0);try{const[f,F]=await Promise.all([q(void 0,!1,"all",5),G(a)]);j(f),v(F)}catch(f){console.error("Failed to load leaderboard for profile modal:",f),j([]),v(0)}finally{g(!1)}})()},[i,s.role,s.uid]);const I=()=>{M(s),b(!1)},P=()=>{t(p),b(!1)},A=a=>{switch(a){case"student":return"bg-sky-100 text-sky-700 border-sky-200";case"teacher":return"bg-rose-100 text-rose-700 border-rose-200";case"admin":return"bg-rose-100 text-rose-700 border-rose-200";default:return"bg-zinc-100 text-zinc-700 border-zinc-200"}},N=m.find(a=>a.userId===s.uid);return e.jsx(D,{children:i&&e.jsxs(e.Fragment,{children:[e.jsx(k.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},onClick:o,className:"fixed inset-0 bg-black/50 backdrop-blur-sm z-50"}),e.jsx(k.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},className:"fixed inset-0 z-50 flex items-center justify-center p-4",onClick:a=>a.stopPropagation(),children:e.jsxs("div",{className:"bg-[#f7f9fc] rounded-2xl shadow-2xl w-full max-w-3xl max-h-[90vh] overflow-hidden border border-[#dde3eb]",children:[e.jsxs("div",{className:"bg-gradient-to-r from-sky-600 to-sky-500 p-6 relative overflow-hidden",children:[e.jsx("div",{className:"absolute top-0 left-0 right-0 h-px bg-gradient-to-r from-transparent via-white/30 to-transparent"}),e.jsx("div",{className:"absolute top-0 right-0 w-48 h-48 bg-white/10 rounded-full -mr-24 -mt-24"}),e.jsx("div",{className:"absolute bottom-0 left-0 w-36 h-36 bg-white/5 rounded-full -ml-18 -mb-18"}),e.jsxs("div",{className:"relative z-10 flex items-start justify-between",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("h2",{className:"text-xl font-display font-bold text-white mb-1",children:"Profile Settings"}),e.jsx("p",{className:"text-white/90 text-sm font-body",children:"Manage your account information"})]}),e.jsx("button",{onClick:o,className:"text-white/80 hover:text-white hover:bg-white/10 p-2 rounded-lg transition-all",children:e.jsx(X,{size:20})})]})]}),e.jsxs("div",{className:"overflow-y-auto max-h-[calc(90vh-200px)] p-6 scrollbar-thin scrollbar-thumb-[#d1cec6] scrollbar-track-[#edf1f7]",children:[e.jsxs("div",{className:"mb-8 space-y-4",children:[e.jsx(V,{uid:s.uid,photoURL:s.photo,displayName:s.name,onUploaded:a=>t(n=>({...n,photo:a}))}),e.jsxs("div",{className:"text-center",children:[e.jsx("h3",{className:"text-lg font-display font-bold text-[#0a1628]",children:s.name}),e.jsx("span",{className:`inline-block mt-2 px-3 py-1 rounded-full text-xs font-body font-semibold border ${A(s.role)}`,children:s.role.charAt(0).toUpperCase()+s.role.slice(1)})]})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsxs("h4",{className:"text-sm font-display font-bold text-[#0a1628] mb-4 flex items-center gap-2",children:[e.jsx("div",{className:"w-1 h-4 bg-sky-600 rounded-full"}),"Basic Information"]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-body font-semibold text-[#5a6578] mb-2 uppercase tracking-wider",children:"Full Name"}),e.jsxs("div",{className:"relative",children:[e.jsx(u,{size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-500"}),e.jsx(d,{value:s.name,onChange:a=>t({...s,name:a.target.value}),disabled:!l,className:"pl-10 bg-white border-[#dde3eb] rounded-lg font-body text-[#0a1628] focus:border-sky-400 focus:ring-sky-400/20 disabled:opacity-100 disabled:cursor-default"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-body font-semibold text-[#5a6578] mb-2 uppercase tracking-wider",children:"Email Address"}),e.jsxs("div",{className:"relative",children:[e.jsx(Y,{size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-500"}),e.jsx(d,{type:"email",value:s.email,onChange:a=>t({...s,email:a.target.value}),disabled:!l,className:"pl-10 bg-white border-[#dde3eb] rounded-lg font-body text-[#0a1628] focus:border-sky-400 focus:ring-sky-400/20 disabled:opacity-100 disabled:cursor-default"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-body font-semibold text-[#5a6578] mb-2 uppercase tracking-wider",children:"Phone Number"}),e.jsxs("div",{className:"relative",children:[e.jsx(Q,{size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-500"}),e.jsx(d,{value:s.phone,onChange:a=>t({...s,phone:a.target.value}),disabled:!l,className:"pl-10 bg-white border-[#dde3eb] rounded-lg font-body text-[#0a1628] focus:border-sky-400 focus:ring-sky-400/20 disabled:opacity-100 disabled:cursor-default"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-body font-semibold text-[#5a6578] mb-2 uppercase tracking-wider",children:"Gender"}),e.jsxs(_,{value:s.gender||"",onValueChange:a=>{t({...s,gender:a||void 0})},disabled:!l,children:[e.jsx(R,{className:"w-full bg-white border-[#dde3eb] rounded-lg [&>span]:flex [&>span]:items-center [&>span]:gap-2",children:e.jsxs("span",{className:"flex items-center gap-2",children:[s.gender==="male"&&e.jsxs(e.Fragment,{children:[e.jsx(z,{className:"size-4 text-blue-500"}),e.jsx("span",{children:"Male"})]}),s.gender==="female"&&e.jsxs(e.Fragment,{children:[e.jsx(C,{className:"size-4 text-pink-500"}),e.jsx("span",{children:"Female"})]}),s.gender==="prefer_not_to_say"&&e.jsxs(e.Fragment,{children:[e.jsx(L,{className:"size-4 text-gray-500"}),e.jsx("span",{children:"Prefer not to say"})]}),!s.gender&&e.jsx("span",{className:"text-muted-foreground",children:"Select gender (optional)"})]})}),e.jsxs(U,{children:[e.jsx(h,{value:"male",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(z,{className:"size-4 text-blue-500"}),e.jsx("span",{children:"Male"})]})}),e.jsx(h,{value:"female",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(C,{className:"size-4 text-pink-500"}),e.jsx("span",{children:"Female"})]})}),e.jsx(h,{value:"prefer_not_to_say",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(L,{className:"size-4 text-gray-500"}),e.jsx("span",{children:"Prefer not to say"})]})})]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-body font-semibold text-[#5a6578] mb-2 uppercase tracking-wider",children:s.role==="student"?"School":s.role==="teacher"?"Department":"Office Location"}),e.jsxs("div",{className:"relative",children:[e.jsx(H,{size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-500"}),e.jsx(d,{value:s.school||s.department||s.office||"",onChange:a=>{s.role==="student"?t({...s,school:a.target.value}):s.role==="teacher"?t({...s,department:a.target.value}):t({...s,office:a.target.value})},disabled:!l,className:"pl-10 bg-white border-[#dde3eb] rounded-lg font-body text-[#0a1628] focus:border-sky-400 focus:ring-sky-400/20 disabled:opacity-100 disabled:cursor-default"})]})]})]})]}),s.role==="student"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsxs("h4",{className:"text-sm font-bold text-[#0a1628] mb-4 flex items-center gap-2",children:[e.jsx("div",{className:"w-1 h-4 bg-teal-600 rounded-full"}),"Academic Information"]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"md:col-span-2",children:[e.jsx("label",{className:"block text-xs font-body font-semibold text-[#5a6578] mb-2 uppercase tracking-wider",children:"Learner's Reference Number (LRN)"}),e.jsxs("div",{className:"relative",children:[e.jsx(x,{size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-500"}),e.jsx(d,{value:s.lrn||"",onChange:a=>t({...s,lrn:a.target.value}),disabled:!l,className:"pl-10 bg-[#edf1f7] border-[#dde3eb] rounded-xl disabled:opacity-100 disabled:cursor-default"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-body font-semibold text-[#5a6578] mb-2 uppercase tracking-wider",children:"Grade Level"}),e.jsxs("div",{className:"relative",children:[e.jsx(w,{size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-500"}),e.jsx(d,{value:s.grade||"",onChange:a=>t({...s,grade:a.target.value}),disabled:!l,className:"pl-10 bg-white border-[#dde3eb] rounded-lg font-body text-[#0a1628] focus:border-sky-400 focus:ring-sky-400/20 disabled:opacity-100 disabled:cursor-default"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-body font-semibold text-[#5a6578] mb-2 uppercase tracking-wider",children:"Section"}),e.jsxs("div",{className:"relative",children:[e.jsx(u,{size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-500"}),e.jsx(d,{value:s.section||"",onChange:a=>t({...s,section:a.target.value}),disabled:!l,className:"pl-10 bg-white border-[#dde3eb] rounded-lg font-body text-[#0a1628] focus:border-sky-400 focus:ring-sky-400/20 disabled:opacity-100 disabled:cursor-default"})]})]})]})]}),e.jsxs("div",{children:[e.jsxs("h4",{className:"text-sm font-bold text-[#0a1628] mb-4 flex items-center gap-2",children:[e.jsx("div",{className:"w-1 h-4 bg-rose-600 rounded-full"}),"Leaderboard Overview"]}),E?e.jsx("div",{className:"rounded-lg border border-[#dde3eb] bg-white p-4 text-sm font-body text-[#5a6578]",children:"Loading leaderboard data..."}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-3",children:[e.jsxs("div",{className:"rounded-lg border border-rose-200 bg-rose-50 p-3",children:[e.jsx("p",{className:"text-xs font-body font-semibold text-rose-700 uppercase tracking-wider",children:"Your Rank"}),e.jsx("p",{className:"text-2xl font-display font-bold text-rose-800 mt-1",children:y>0?`#${y}`:"Unranked"})]}),e.jsxs("div",{className:"rounded-lg border border-sky-200 bg-sky-50 p-3",children:[e.jsx("p",{className:"text-xs font-body font-semibold text-sky-700 uppercase tracking-wider",children:"Total XP"}),e.jsx("p",{className:"text-2xl font-display font-bold text-sky-800 mt-1",children:N?.xp??0})]}),e.jsxs("div",{className:"rounded-lg border border-emerald-200 bg-emerald-50 p-3",children:[e.jsx("p",{className:"text-xs font-body font-semibold text-emerald-700 uppercase tracking-wider",children:"Level"}),e.jsx("p",{className:"text-2xl font-display font-bold text-emerald-800 mt-1",children:N?.level??"-"})]})]}),e.jsxs("div",{className:"rounded-lg border border-[#dde3eb] bg-white overflow-hidden",children:[e.jsx("div",{className:"px-4 py-2 border-b border-[#dde3eb] bg-[#f7f9fc]",children:e.jsx("p",{className:"text-xs font-body font-semibold text-[#5a6578] uppercase tracking-wider",children:"Top Students"})}),e.jsx("div",{className:"divide-y divide-[#edf1f7]",children:m.length>0?m.map(a=>e.jsxs("div",{className:"px-4 py-3 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx("div",{className:"w-7 h-7 rounded-full bg-[#edf1f7] text-[#0a1628] text-xs font-display font-bold flex items-center justify-center",children:a.rank}),e.jsxs("p",{className:"text-sm font-body font-semibold text-[#0a1628] truncate",children:[a.name,a.userId===s.uid?" (You)":""]})]}),e.jsxs("div",{className:"text-right",children:[e.jsxs("p",{className:"text-sm font-body font-semibold text-[#0a1628]",children:[a.xp," XP"]}),e.jsxs("p",{className:"text-xs font-body text-[#5a6578]",children:["Lv ",a.level]})]})]},a.userId)):e.jsx("div",{className:"px-4 py-6 text-center text-sm font-body text-[#5a6578]",children:"No leaderboard data available yet."})})]})]})]})]}),s.role==="teacher"&&e.jsxs("div",{children:[e.jsxs("h4",{className:"text-sm font-display font-bold text-[#0a1628] mb-4 flex items-center gap-2",children:[e.jsx("div",{className:"w-1 h-4 bg-rose-500 rounded-full"}),"Teaching Information"]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-body font-semibold text-[#5a6578] mb-2 uppercase tracking-wider",children:"Teacher ID"}),e.jsxs("div",{className:"relative",children:[e.jsx(x,{size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-500"}),e.jsx(d,{value:s.teacherId||"",onChange:a=>t({...s,teacherId:a.target.value}),disabled:!l,className:"pl-10 bg-white border-[#dde3eb] rounded-lg font-body text-[#0a1628] focus:border-sky-400 focus:ring-sky-400/20 disabled:opacity-100 disabled:cursor-default"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-body font-semibold text-[#5a6578] mb-2 uppercase tracking-wider",children:"Subject/Specialization"}),e.jsxs("div",{className:"relative",children:[e.jsx(w,{size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-500"}),e.jsx(d,{value:s.subject||"",onChange:a=>t({...s,subject:a.target.value}),disabled:!l,className:"pl-10 bg-white border-[#dde3eb] rounded-lg font-body text-[#0a1628] focus:border-sky-400 focus:ring-sky-400/20 disabled:opacity-100 disabled:cursor-default"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-body font-semibold text-[#5a6578] mb-2 uppercase tracking-wider",children:"Years of Experience"}),e.jsxs("div",{className:"relative",children:[e.jsx(B,{size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-500"}),e.jsx(d,{value:s.yearsOfExperience||"",onChange:a=>t({...s,yearsOfExperience:a.target.value}),disabled:!l,className:"pl-10 bg-white border-[#dde3eb] rounded-lg font-body text-[#0a1628] focus:border-sky-400 focus:ring-sky-400/20 disabled:opacity-100 disabled:cursor-default"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-body font-semibold text-[#5a6578] mb-2 uppercase tracking-wider",children:"Qualification"}),e.jsxs("div",{className:"relative",children:[e.jsx(x,{size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-500"}),e.jsx(d,{value:s.qualification||"",onChange:a=>t({...s,qualification:a.target.value}),disabled:!l,className:"pl-10 bg-white border-[#dde3eb] rounded-lg font-body text-[#0a1628] focus:border-sky-400 focus:ring-sky-400/20 disabled:opacity-100 disabled:cursor-default"})]})]})]})]}),s.role==="admin"&&e.jsxs("div",{children:[e.jsxs("h4",{className:"text-sm font-display font-bold text-[#0a1628] mb-4 flex items-center gap-2",children:[e.jsx("div",{className:"w-1 h-4 bg-rose-600 rounded-full"}),"Administrative Information"]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-body font-semibold text-[#5a6578] mb-2 uppercase tracking-wider",children:"Admin ID"}),e.jsxs("div",{className:"relative",children:[e.jsx(x,{size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-500"}),e.jsx(d,{value:s.adminId||"",onChange:a=>t({...s,adminId:a.target.value}),disabled:!l,className:"pl-10 bg-white border-[#dde3eb] rounded-lg font-body text-[#0a1628] focus:border-sky-400 focus:ring-sky-400/20 disabled:opacity-100 disabled:cursor-default"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-body font-semibold text-[#5a6578] mb-2 uppercase tracking-wider",children:"Position/Title"}),e.jsxs("div",{className:"relative",children:[e.jsx(u,{size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-500"}),e.jsx(d,{value:s.position||"",onChange:a=>t({...s,position:a.target.value}),disabled:!l,className:"pl-10 bg-white border-[#dde3eb] rounded-lg font-body text-[#0a1628] focus:border-sky-400 focus:ring-sky-400/20 disabled:opacity-100 disabled:cursor-default"})]})]}),e.jsxs("div",{className:"md:col-span-2",children:[e.jsx("label",{className:"block text-xs font-body font-semibold text-[#5a6578] mb-2 uppercase tracking-wider",children:"Access Level/Permissions"}),e.jsxs("div",{className:"relative",children:[e.jsx(T,{size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-500"}),e.jsx(d,{value:s.permissions||"",onChange:a=>t({...s,permissions:a.target.value}),disabled:!l,className:"pl-10 bg-white border-[#dde3eb] rounded-lg font-body text-[#0a1628] focus:border-sky-400 focus:ring-sky-400/20 disabled:opacity-100 disabled:cursor-default"})]})]})]})]})]})]}),e.jsx("div",{className:"border-t border-[#dde3eb] p-5 bg-[#edf1f7]",children:e.jsx("div",{className:"flex gap-3 justify-end",children:l?e.jsxs(e.Fragment,{children:[e.jsx(c,{onClick:P,variant:"outline",className:"px-5 py-2 rounded-lg border-[#d1cec6] hover:bg-white font-body font-medium text-[#5a6578]",children:"Cancel"}),e.jsxs(c,{onClick:I,className:"px-5 py-2 rounded-lg bg-sky-600 hover:bg-sky-700 text-white font-body font-semibold flex items-center gap-2",children:[e.jsx($,{size:16}),"Save Changes"]})]}):e.jsxs(e.Fragment,{children:[e.jsx(c,{onClick:o,variant:"outline",className:"px-5 py-2 rounded-lg border-[#d1cec6] hover:bg-white font-body font-medium text-[#5a6578]",children:"Close"}),e.jsx(c,{onClick:()=>b(!0),className:"px-5 py-2 rounded-lg bg-sky-600 hover:bg-sky-700 text-white font-body font-semibold",children:"Edit Profile"})]})})})]})})]})})};export{ye as default}; + */const O=[["path",{d:"M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z",key:"foiqr5"}]],Q=S("phone",O),ye=({isOpen:i,onClose:o,profileData:p,onSave:E})=>{const[s,t]=r.useState(p),[l,b]=r.useState(!1),[M,g]=r.useState(!1),[m,j]=r.useState([]),[y,v]=r.useState(0);r.useEffect(()=>{if(!i)return;const a=n=>{n.key==="Escape"&&o()};return window.addEventListener("keydown",a),()=>window.removeEventListener("keydown",a)},[i,o]),r.useEffect(()=>{if(!i||s.role!=="student"||!s.uid)return;const a=s.uid;(async()=>{g(!0);try{const[f,F]=await Promise.all([q(void 0,!1,"all",5),G(a)]);j(f),v(F)}catch(f){console.error("Failed to load leaderboard for profile modal:",f),j([]),v(0)}finally{g(!1)}})()},[i,s.role,s.uid]);const I=()=>{E(s),b(!1)},P=()=>{t(p),b(!1)},A=a=>{switch(a){case"student":return"bg-sky-100 text-sky-700 border-sky-200";case"teacher":return"bg-rose-100 text-rose-700 border-rose-200";case"admin":return"bg-rose-100 text-rose-700 border-rose-200";default:return"bg-zinc-100 text-zinc-700 border-zinc-200"}},N=m.find(a=>a.userId===s.uid);return e.jsx(D,{children:i&&e.jsxs(e.Fragment,{children:[e.jsx(k.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},onClick:o,className:"fixed inset-0 bg-black/50 backdrop-blur-sm z-50"}),e.jsx(k.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},className:"fixed inset-0 z-50 flex items-center justify-center p-4",onClick:a=>a.stopPropagation(),children:e.jsxs("div",{className:"bg-[#f7f9fc] rounded-2xl shadow-2xl w-full max-w-3xl max-h-[90vh] overflow-hidden border border-[#dde3eb]",children:[e.jsxs("div",{className:"bg-gradient-to-r from-sky-600 to-sky-500 p-6 relative overflow-hidden",children:[e.jsx("div",{className:"absolute top-0 left-0 right-0 h-px bg-gradient-to-r from-transparent via-white/30 to-transparent"}),e.jsx("div",{className:"absolute top-0 right-0 w-48 h-48 bg-white/10 rounded-full -mr-24 -mt-24"}),e.jsx("div",{className:"absolute bottom-0 left-0 w-36 h-36 bg-white/5 rounded-full -ml-18 -mb-18"}),e.jsxs("div",{className:"relative z-10 flex items-start justify-between",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("h2",{className:"text-xl font-display font-bold text-white mb-1",children:"Profile Settings"}),e.jsx("p",{className:"text-white/90 text-sm font-body",children:"Manage your account information"})]}),e.jsx("button",{onClick:o,className:"text-white/80 hover:text-white hover:bg-white/10 p-2 rounded-lg transition-all",children:e.jsx(X,{size:20})})]})]}),e.jsxs("div",{className:"overflow-y-auto max-h-[calc(90vh-200px)] p-6 scrollbar-thin scrollbar-thumb-[#d1cec6] scrollbar-track-[#edf1f7]",children:[e.jsxs("div",{className:"mb-8 space-y-4",children:[e.jsx(V,{uid:s.uid,photoURL:s.photo,displayName:s.name,onUploaded:a=>t(n=>({...n,photo:a}))}),e.jsxs("div",{className:"text-center",children:[e.jsx("h3",{className:"text-lg font-display font-bold text-[#0a1628]",children:s.name}),e.jsx("span",{className:`inline-block mt-2 px-3 py-1 rounded-full text-xs font-body font-semibold border ${A(s.role)}`,children:s.role.charAt(0).toUpperCase()+s.role.slice(1)})]})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsxs("h4",{className:"text-sm font-display font-bold text-[#0a1628] mb-4 flex items-center gap-2",children:[e.jsx("div",{className:"w-1 h-4 bg-sky-600 rounded-full"}),"Basic Information"]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-body font-semibold text-[#5a6578] mb-2 uppercase tracking-wider",children:"Full Name"}),e.jsxs("div",{className:"relative",children:[e.jsx(u,{size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-500"}),e.jsx(d,{value:s.name,onChange:a=>t({...s,name:a.target.value}),disabled:!l,className:"pl-10 bg-white border-[#dde3eb] rounded-lg font-body text-[#0a1628] focus:border-sky-400 focus:ring-sky-400/20 disabled:opacity-100 disabled:cursor-default"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-body font-semibold text-[#5a6578] mb-2 uppercase tracking-wider",children:"Email Address"}),e.jsxs("div",{className:"relative",children:[e.jsx(Y,{size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-500"}),e.jsx(d,{type:"email",value:s.email,onChange:a=>t({...s,email:a.target.value}),disabled:!l,className:"pl-10 bg-white border-[#dde3eb] rounded-lg font-body text-[#0a1628] focus:border-sky-400 focus:ring-sky-400/20 disabled:opacity-100 disabled:cursor-default"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-body font-semibold text-[#5a6578] mb-2 uppercase tracking-wider",children:"Phone Number"}),e.jsxs("div",{className:"relative",children:[e.jsx(Q,{size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-500"}),e.jsx(d,{value:s.phone,onChange:a=>t({...s,phone:a.target.value}),disabled:!l,className:"pl-10 bg-white border-[#dde3eb] rounded-lg font-body text-[#0a1628] focus:border-sky-400 focus:ring-sky-400/20 disabled:opacity-100 disabled:cursor-default"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-body font-semibold text-[#5a6578] mb-2 uppercase tracking-wider",children:"Gender"}),e.jsxs(_,{value:s.gender||"",onValueChange:a=>{t({...s,gender:a||void 0})},disabled:!l,children:[e.jsx(R,{className:"w-full bg-white border-[#dde3eb] rounded-lg [&>span]:flex [&>span]:items-center [&>span]:gap-2",children:e.jsxs("span",{className:"flex items-center gap-2",children:[s.gender==="male"&&e.jsxs(e.Fragment,{children:[e.jsx(z,{className:"size-4 text-blue-500"}),e.jsx("span",{children:"Male"})]}),s.gender==="female"&&e.jsxs(e.Fragment,{children:[e.jsx(C,{className:"size-4 text-pink-500"}),e.jsx("span",{children:"Female"})]}),s.gender==="prefer_not_to_say"&&e.jsxs(e.Fragment,{children:[e.jsx(L,{className:"size-4 text-gray-500"}),e.jsx("span",{children:"Prefer not to say"})]}),!s.gender&&e.jsx("span",{className:"text-muted-foreground",children:"Select gender (optional)"})]})}),e.jsxs(U,{children:[e.jsx(h,{value:"male",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(z,{className:"size-4 text-blue-500"}),e.jsx("span",{children:"Male"})]})}),e.jsx(h,{value:"female",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(C,{className:"size-4 text-pink-500"}),e.jsx("span",{children:"Female"})]})}),e.jsx(h,{value:"prefer_not_to_say",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(L,{className:"size-4 text-gray-500"}),e.jsx("span",{children:"Prefer not to say"})]})})]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-body font-semibold text-[#5a6578] mb-2 uppercase tracking-wider",children:s.role==="student"?"School":s.role==="teacher"?"Department":"Office Location"}),e.jsxs("div",{className:"relative",children:[e.jsx(K,{size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-500"}),e.jsx(d,{value:s.school||s.department||s.office||"",onChange:a=>{s.role==="student"?t({...s,school:a.target.value}):s.role==="teacher"?t({...s,department:a.target.value}):t({...s,office:a.target.value})},disabled:!l,className:"pl-10 bg-white border-[#dde3eb] rounded-lg font-body text-[#0a1628] focus:border-sky-400 focus:ring-sky-400/20 disabled:opacity-100 disabled:cursor-default"})]})]})]})]}),s.role==="student"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsxs("h4",{className:"text-sm font-bold text-[#0a1628] mb-4 flex items-center gap-2",children:[e.jsx("div",{className:"w-1 h-4 bg-teal-600 rounded-full"}),"Academic Information"]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"md:col-span-2",children:[e.jsx("label",{className:"block text-xs font-body font-semibold text-[#5a6578] mb-2 uppercase tracking-wider",children:"Learner's Reference Number (LRN)"}),e.jsxs("div",{className:"relative",children:[e.jsx(x,{size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-500"}),e.jsx(d,{value:s.lrn||"",onChange:a=>t({...s,lrn:a.target.value}),disabled:!l,className:"pl-10 bg-[#edf1f7] border-[#dde3eb] rounded-xl disabled:opacity-100 disabled:cursor-default"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-body font-semibold text-[#5a6578] mb-2 uppercase tracking-wider",children:"Grade Level"}),e.jsxs("div",{className:"relative",children:[e.jsx(w,{size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-500"}),e.jsx(d,{value:s.grade||"",onChange:a=>t({...s,grade:a.target.value}),disabled:!l,className:"pl-10 bg-white border-[#dde3eb] rounded-lg font-body text-[#0a1628] focus:border-sky-400 focus:ring-sky-400/20 disabled:opacity-100 disabled:cursor-default"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-body font-semibold text-[#5a6578] mb-2 uppercase tracking-wider",children:"Section"}),e.jsxs("div",{className:"relative",children:[e.jsx(u,{size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-500"}),e.jsx(d,{value:s.section||"",onChange:a=>t({...s,section:a.target.value}),disabled:!l,className:"pl-10 bg-white border-[#dde3eb] rounded-lg font-body text-[#0a1628] focus:border-sky-400 focus:ring-sky-400/20 disabled:opacity-100 disabled:cursor-default"})]})]})]})]}),e.jsxs("div",{children:[e.jsxs("h4",{className:"text-sm font-bold text-[#0a1628] mb-4 flex items-center gap-2",children:[e.jsx("div",{className:"w-1 h-4 bg-rose-600 rounded-full"}),"Leaderboard Overview"]}),M?e.jsx("div",{className:"rounded-lg border border-[#dde3eb] bg-white p-4 text-sm font-body text-[#5a6578]",children:"Loading leaderboard data..."}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-3",children:[e.jsxs("div",{className:"rounded-lg border border-rose-200 bg-rose-50 p-3",children:[e.jsx("p",{className:"text-xs font-body font-semibold text-rose-700 uppercase tracking-wider",children:"Your Rank"}),e.jsx("p",{className:"text-2xl font-display font-bold text-rose-800 mt-1",children:y>0?`#${y}`:"Unranked"})]}),e.jsxs("div",{className:"rounded-lg border border-sky-200 bg-sky-50 p-3",children:[e.jsx("p",{className:"text-xs font-body font-semibold text-sky-700 uppercase tracking-wider",children:"Total XP"}),e.jsx("p",{className:"text-2xl font-display font-bold text-sky-800 mt-1",children:N?.xp??0})]}),e.jsxs("div",{className:"rounded-lg border border-emerald-200 bg-emerald-50 p-3",children:[e.jsx("p",{className:"text-xs font-body font-semibold text-emerald-700 uppercase tracking-wider",children:"Level"}),e.jsx("p",{className:"text-2xl font-display font-bold text-emerald-800 mt-1",children:N?.level??"-"})]})]}),e.jsxs("div",{className:"rounded-lg border border-[#dde3eb] bg-white overflow-hidden",children:[e.jsx("div",{className:"px-4 py-2 border-b border-[#dde3eb] bg-[#f7f9fc]",children:e.jsx("p",{className:"text-xs font-body font-semibold text-[#5a6578] uppercase tracking-wider",children:"Top Students"})}),e.jsx("div",{className:"divide-y divide-[#edf1f7]",children:m.length>0?m.map(a=>e.jsxs("div",{className:"px-4 py-3 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx("div",{className:"w-7 h-7 rounded-full bg-[#edf1f7] text-[#0a1628] text-xs font-display font-bold flex items-center justify-center",children:a.rank}),e.jsxs("p",{className:"text-sm font-body font-semibold text-[#0a1628] truncate",children:[a.name,a.userId===s.uid?" (You)":""]})]}),e.jsxs("div",{className:"text-right",children:[e.jsxs("p",{className:"text-sm font-body font-semibold text-[#0a1628]",children:[a.xp," XP"]}),e.jsxs("p",{className:"text-xs font-body text-[#5a6578]",children:["Lv ",a.level]})]})]},a.userId)):e.jsx("div",{className:"px-4 py-6 text-center text-sm font-body text-[#5a6578]",children:"No leaderboard data available yet."})})]})]})]})]}),s.role==="teacher"&&e.jsxs("div",{children:[e.jsxs("h4",{className:"text-sm font-display font-bold text-[#0a1628] mb-4 flex items-center gap-2",children:[e.jsx("div",{className:"w-1 h-4 bg-rose-500 rounded-full"}),"Teaching Information"]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-body font-semibold text-[#5a6578] mb-2 uppercase tracking-wider",children:"Teacher ID"}),e.jsxs("div",{className:"relative",children:[e.jsx(x,{size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-500"}),e.jsx(d,{value:s.teacherId||"",onChange:a=>t({...s,teacherId:a.target.value}),disabled:!l,className:"pl-10 bg-white border-[#dde3eb] rounded-lg font-body text-[#0a1628] focus:border-sky-400 focus:ring-sky-400/20 disabled:opacity-100 disabled:cursor-default"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-body font-semibold text-[#5a6578] mb-2 uppercase tracking-wider",children:"Subject/Specialization"}),e.jsxs("div",{className:"relative",children:[e.jsx(w,{size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-500"}),e.jsx(d,{value:s.subject||"",onChange:a=>t({...s,subject:a.target.value}),disabled:!l,className:"pl-10 bg-white border-[#dde3eb] rounded-lg font-body text-[#0a1628] focus:border-sky-400 focus:ring-sky-400/20 disabled:opacity-100 disabled:cursor-default"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-body font-semibold text-[#5a6578] mb-2 uppercase tracking-wider",children:"Years of Experience"}),e.jsxs("div",{className:"relative",children:[e.jsx(B,{size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-500"}),e.jsx(d,{value:s.yearsOfExperience||"",onChange:a=>t({...s,yearsOfExperience:a.target.value}),disabled:!l,className:"pl-10 bg-white border-[#dde3eb] rounded-lg font-body text-[#0a1628] focus:border-sky-400 focus:ring-sky-400/20 disabled:opacity-100 disabled:cursor-default"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-body font-semibold text-[#5a6578] mb-2 uppercase tracking-wider",children:"Qualification"}),e.jsxs("div",{className:"relative",children:[e.jsx(x,{size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-500"}),e.jsx(d,{value:s.qualification||"",onChange:a=>t({...s,qualification:a.target.value}),disabled:!l,className:"pl-10 bg-white border-[#dde3eb] rounded-lg font-body text-[#0a1628] focus:border-sky-400 focus:ring-sky-400/20 disabled:opacity-100 disabled:cursor-default"})]})]})]})]}),s.role==="admin"&&e.jsxs("div",{children:[e.jsxs("h4",{className:"text-sm font-display font-bold text-[#0a1628] mb-4 flex items-center gap-2",children:[e.jsx("div",{className:"w-1 h-4 bg-rose-600 rounded-full"}),"Administrative Information"]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-body font-semibold text-[#5a6578] mb-2 uppercase tracking-wider",children:"Admin ID"}),e.jsxs("div",{className:"relative",children:[e.jsx(x,{size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-500"}),e.jsx(d,{value:s.adminId||"",onChange:a=>t({...s,adminId:a.target.value}),disabled:!l,className:"pl-10 bg-white border-[#dde3eb] rounded-lg font-body text-[#0a1628] focus:border-sky-400 focus:ring-sky-400/20 disabled:opacity-100 disabled:cursor-default"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-body font-semibold text-[#5a6578] mb-2 uppercase tracking-wider",children:"Position/Title"}),e.jsxs("div",{className:"relative",children:[e.jsx(u,{size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-500"}),e.jsx(d,{value:s.position||"",onChange:a=>t({...s,position:a.target.value}),disabled:!l,className:"pl-10 bg-white border-[#dde3eb] rounded-lg font-body text-[#0a1628] focus:border-sky-400 focus:ring-sky-400/20 disabled:opacity-100 disabled:cursor-default"})]})]}),e.jsxs("div",{className:"md:col-span-2",children:[e.jsx("label",{className:"block text-xs font-body font-semibold text-[#5a6578] mb-2 uppercase tracking-wider",children:"Access Level/Permissions"}),e.jsxs("div",{className:"relative",children:[e.jsx(T,{size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-500"}),e.jsx(d,{value:s.permissions||"",onChange:a=>t({...s,permissions:a.target.value}),disabled:!l,className:"pl-10 bg-white border-[#dde3eb] rounded-lg font-body text-[#0a1628] focus:border-sky-400 focus:ring-sky-400/20 disabled:opacity-100 disabled:cursor-default"})]})]})]})]})]})]}),e.jsx("div",{className:"border-t border-[#dde3eb] p-5 bg-[#edf1f7]",children:e.jsx("div",{className:"flex gap-3 justify-end",children:l?e.jsxs(e.Fragment,{children:[e.jsx(c,{onClick:P,variant:"outline",className:"px-5 py-2 rounded-lg border-[#d1cec6] hover:bg-white font-body font-medium text-[#5a6578]",children:"Cancel"}),e.jsxs(c,{onClick:I,className:"px-5 py-2 rounded-lg bg-sky-600 hover:bg-sky-700 text-white font-body font-semibold flex items-center gap-2",children:[e.jsx($,{size:16}),"Save Changes"]})]}):e.jsxs(e.Fragment,{children:[e.jsx(c,{onClick:o,variant:"outline",className:"px-5 py-2 rounded-lg border-[#d1cec6] hover:bg-white font-body font-medium text-[#5a6578]",children:"Close"}),e.jsx(c,{onClick:()=>b(!0),className:"px-5 py-2 rounded-lg bg-sky-600 hover:bg-sky-700 text-white font-body font-semibold",children:"Edit Profile"})]})})})]})})]})})};export{ye as default}; diff --git a/assets/ProfilePictureUploader-CX_IZAwE.js b/assets/ProfilePictureUploader-CyCaD4jN.js similarity index 83% rename from assets/ProfilePictureUploader-CX_IZAwE.js rename to assets/ProfilePictureUploader-CyCaD4jN.js index 1a44729889afab89d916e237319c9b317d66b52d..df83f901e53dfdba61b5f6ad1f807d4b97c2acda 100644 --- a/assets/ProfilePictureUploader-CX_IZAwE.js +++ b/assets/ProfilePictureUploader-CyCaD4jN.js @@ -1,4 +1,4 @@ -import{e as X,i as B,F as V,aZ as ve,a_ as ge,u as we,J as xe,K as ye,N as be,j as Ce,m as K,t as J}from"./index-BaOs5Ayg.js";import{g as Pe,r as g,j as p}from"./vendor-react-B4AQeu28.js";import{_ as Re,p as b,q as Ee,r as Se,s as _e,t as ze}from"./vendor-radix-BorKzPz9.js";import{B as Q}from"./button-DCfeFHoH.js";import{updateProfile as De}from"./vendor-firebase-auth-BLpRW_zO.js";import"./vendor-firebase-core-CO26nNq6.js";import{r as Me,u as Ae,a as Ne}from"./vendor-firebase-storage-B3igpVVS.js";import{X as Te}from"./x-TNvtuOD9.js";import{M as je}from"./minus-DfrEv-SC.js";import{P as Ue}from"./plus-DkG35AoH.js";import{U as Fe}from"./upload-DayXhGwD.js";/** +import{e as X,k as B,I as V,a_ as ve,a$ as ge,l as we,N as xe,O as ye,P as be,g as Ce,m as K,n as J}from"./index-uASBzalf.js";import{g as Pe,r as g,j as u}from"./vendor-react-B4AQeu28.js";import{_ as Re,o as b,p as Ee,q as Se,r as _e,s as ze}from"./vendor-radix-xDOIcVzp.js";import{B as Q}from"./button-BPmLcOpC.js";import{updateProfile as De}from"./vendor-firebase-auth-Bcpr4O6E.js";import"./vendor-firebase-core-DCQrgkxC.js";import{r as Me,u as Ae,a as Ne}from"./vendor-firebase-storage-dc5X5yTv.js";import{X as Te}from"./x-CBb03rh3.js";import{M as je}from"./minus-Bfei9C79.js";import{P as Ue}from"./plus-Cy6hz5PP.js";import{U as Fe}from"./upload-Ds5w3QNw.js";/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. @@ -13,7 +13,7 @@ import{e as X,i as B,F as V,aZ as ve,a_ as ge,u as we,J as xe,K as ye,N as be,j * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. - */const ke=[["path",{d:"M12 15v7",key:"t2xh3l"}],["path",{d:"M9 19h6",key:"456am0"}],["circle",{cx:"12",cy:"9",r:"6",key:"1nw4tq"}]],At=X("venus",ke);var $,ee;function We(){if(ee)return $;ee=1;var a=!1,o,e,t,r,i,n,s,c,l,u,d,h,m,w,y;function f(){if(!a){a=!0;var x=navigator.userAgent,v=/(?:MSIE.(\d+\.\d+))|(?:(?:Firefox|GranParadiso|Iceweasel).(\d+\.\d+))|(?:Opera(?:.+Version.|.)(\d+\.\d+))|(?:AppleWebKit.(\d+(?:\.\d+)?))|(?:Trident\/\d+\.\d+.*rv:(\d+\.\d+))/.exec(x),E=/(Mac OS X)|(Windows)|(Linux)/.exec(x);if(h=/\b(iPhone|iP[ao]d)/.exec(x),m=/\b(iP[ao]d)/.exec(x),u=/Android/i.exec(x),w=/FBAN\/\w+;/i.exec(x),y=/Mobile/i.exec(x),d=!!/Win64/.exec(x),v){o=v[1]?parseFloat(v[1]):v[5]?parseFloat(v[5]):NaN,o&&document&&document.documentMode&&(o=document.documentMode);var _=/(?:Trident\/(\d+.\d+))/.exec(x);n=_?parseFloat(_[1])+4:o,e=v[2]?parseFloat(v[2]):NaN,t=v[3]?parseFloat(v[3]):NaN,r=v[4]?parseFloat(v[4]):NaN,r?(v=/(?:Chrome\/(\d+\.\d+))/.exec(x),i=v&&v[1]?parseFloat(v[1]):NaN):i=NaN}else o=e=t=i=r=NaN;if(E){if(E[1]){var P=/(?:Mac OS X (\d+(?:[._]\d+)?))/.exec(x);s=P?parseFloat(P[1].replace("_",".")):!0}else s=!1;c=!!E[2],l=!!E[3]}else s=c=l=!1}}var R={ie:function(){return f()||o},ieCompatibilityMode:function(){return f()||n>o},ie64:function(){return R.ie()&&d},firefox:function(){return f()||e},opera:function(){return f()||t},webkit:function(){return f()||r},safari:function(){return R.webkit()},chrome:function(){return f()||i},windows:function(){return f()||c},osx:function(){return f()||s},linux:function(){return f()||l},iphone:function(){return f()||h},mobile:function(){return f()||h||m||u||y},nativeApp:function(){return f()||w},android:function(){return f()||u},ipad:function(){return f()||m}};return $=R,$}var H,te;function Ze(){if(te)return H;te=1;var a=!!(typeof window<"u"&&window.document&&window.document.createElement),o={canUseDOM:a,canUseWorkers:typeof Worker<"u",canUseEventListeners:a&&!!(window.addEventListener||window.attachEvent),canUseViewport:a&&!!window.screen,isInWorker:!a};return H=o,H}var q,re;function Be(){if(re)return q;re=1;var a=Ze(),o;a.canUseDOM&&(o=document.implementation&&document.implementation.hasFeature&&document.implementation.hasFeature("","")!==!0);/** + */const ke=[["path",{d:"M12 15v7",key:"t2xh3l"}],["path",{d:"M9 19h6",key:"456am0"}],["circle",{cx:"12",cy:"9",r:"6",key:"1nw4tq"}]],At=X("venus",ke);var $,ee;function We(){if(ee)return $;ee=1;var a=!1,o,e,t,r,i,n,s,c,l,p,d,h,m,w,y;function f(){if(!a){a=!0;var x=navigator.userAgent,v=/(?:MSIE.(\d+\.\d+))|(?:(?:Firefox|GranParadiso|Iceweasel).(\d+\.\d+))|(?:Opera(?:.+Version.|.)(\d+\.\d+))|(?:AppleWebKit.(\d+(?:\.\d+)?))|(?:Trident\/\d+\.\d+.*rv:(\d+\.\d+))/.exec(x),E=/(Mac OS X)|(Windows)|(Linux)/.exec(x);if(h=/\b(iPhone|iP[ao]d)/.exec(x),m=/\b(iP[ao]d)/.exec(x),p=/Android/i.exec(x),w=/FBAN\/\w+;/i.exec(x),y=/Mobile/i.exec(x),d=!!/Win64/.exec(x),v){o=v[1]?parseFloat(v[1]):v[5]?parseFloat(v[5]):NaN,o&&document&&document.documentMode&&(o=document.documentMode);var _=/(?:Trident\/(\d+.\d+))/.exec(x);n=_?parseFloat(_[1])+4:o,e=v[2]?parseFloat(v[2]):NaN,t=v[3]?parseFloat(v[3]):NaN,r=v[4]?parseFloat(v[4]):NaN,r?(v=/(?:Chrome\/(\d+\.\d+))/.exec(x),i=v&&v[1]?parseFloat(v[1]):NaN):i=NaN}else o=e=t=i=r=NaN;if(E){if(E[1]){var P=/(?:Mac OS X (\d+(?:[._]\d+)?))/.exec(x);s=P?parseFloat(P[1].replace("_",".")):!0}else s=!1;c=!!E[2],l=!!E[3]}else s=c=l=!1}}var R={ie:function(){return f()||o},ieCompatibilityMode:function(){return f()||n>o},ie64:function(){return R.ie()&&d},firefox:function(){return f()||e},opera:function(){return f()||t},webkit:function(){return f()||r},safari:function(){return R.webkit()},chrome:function(){return f()||i},windows:function(){return f()||c},osx:function(){return f()||s},linux:function(){return f()||l},iphone:function(){return f()||h},mobile:function(){return f()||h||m||p||y},nativeApp:function(){return f()||w},android:function(){return f()||p},ipad:function(){return f()||m}};return $=R,$}var H,te;function Ze(){if(te)return H;te=1;var a=!!(typeof window<"u"&&window.document&&window.document.createElement),o={canUseDOM:a,canUseWorkers:typeof Worker<"u",canUseEventListeners:a&&!!(window.addEventListener||window.attachEvent),canUseViewport:a&&!!window.screen,isInWorker:!a};return H=o,H}var q,re;function Be(){if(re)return q;re=1;var a=Ze(),o;a.canUseDOM&&(o=document.implementation&&document.implementation.hasFeature&&document.implementation.hasFeature("","")!==!0);/** * Checks if an event is supported in the current execution environment. * * NOTE: This will not work correctly for non-generic events such as `change`, @@ -26,7 +26,7 @@ import{e as X,i as B,F as V,aZ as ve,a_ as ge,u as we,J as xe,K as ye,N as be,j * @return {boolean} True if the event is supported. * @internal * @license Modernizr 3.0.0pre (Custom Build) | MIT - */function e(t,r){if(!a.canUseDOM||r&&!("addEventListener"in document))return!1;var i="on"+t,n=i in document;if(!n){var s=document.createElement("div");s.setAttribute(i,"return;"),n=typeof s[i]=="function"}return!n&&o&&t==="wheel"&&(n=document.implementation.hasFeature("Events.wheel","3.0")),n}return q=e,q}var G,oe;function $e(){if(oe)return G;oe=1;var a=We(),o=Be(),e=10,t=40,r=800;function i(n){var s=0,c=0,l=0,u=0;return"detail"in n&&(c=n.detail),"wheelDelta"in n&&(c=-n.wheelDelta/120),"wheelDeltaY"in n&&(c=-n.wheelDeltaY/120),"wheelDeltaX"in n&&(s=-n.wheelDeltaX/120),"axis"in n&&n.axis===n.HORIZONTAL_AXIS&&(s=c,c=0),l=s*e,u=c*e,"deltaY"in n&&(u=n.deltaY),"deltaX"in n&&(l=n.deltaX),(l||u)&&n.deltaMode&&(n.deltaMode==1?(l*=t,u*=t):(l*=r,u*=r)),l&&!s&&(s=l<1?-1:1),u&&!c&&(c=u<1?-1:1),{spinX:s,spinY:c,pixelX:l,pixelY:u}}return i.getEventType=function(){return a.firefox()?"DOMMouseScroll":o("wheel")?"wheel":"mousewheel"},G=i,G}var Y,ie;function He(){return ie||(ie=1,Y=$e()),Y}var qe=He();const Ge=Pe(qe);function Ye(a,o,e,t,r,i){i===void 0&&(i=0);var n=A(a,o,i),s=n.width,c=n.height,l=Math.min(s,e),u=Math.min(c,t);return l>u*r?{width:u*r,height:u}:{width:l,height:l/r}}function Xe(a){return a.width>a.height?a.width/a.naturalWidth:a.height/a.naturalHeight}function T(a,o,e,t,r){r===void 0&&(r=0);var i=A(o.width,o.height,r),n=i.width,s=i.height;return{x:ne(a.x,n,e.width,t),y:ne(a.y,s,e.height,t)}}function ne(a,o,e,t){var r=Math.abs(o*t/2-e/2);return O(a,-r,r)}function ae(a,o){return Math.sqrt(Math.pow(a.y-o.y,2)+Math.pow(a.x-o.x,2))}function se(a,o){return Math.atan2(o.y-a.y,o.x-a.x)*180/Math.PI}function Ve(a,o,e,t,r,i,n){i===void 0&&(i=0),n===void 0&&(n=!0);var s=n?Ke:Je,c=A(o.width,o.height,i),l=A(o.naturalWidth,o.naturalHeight,i),u={x:s(100,((c.width-e.width/r)/2-a.x/r)/c.width*100),y:s(100,((c.height-e.height/r)/2-a.y/r)/c.height*100),width:s(100,e.width/c.width*100/r),height:s(100,e.height/c.height*100/r)},d=Math.round(s(l.width,u.width*l.width/100)),h=Math.round(s(l.height,u.height*l.height/100)),m=l.width>=l.height*t,w=m?{width:Math.round(h*t),height:h}:{width:d,height:Math.round(d/t)},y=b(b({},w),{x:Math.round(s(l.width-w.width,u.x*l.width/100)),y:Math.round(s(l.height-w.height,u.y*l.height/100))});return{croppedAreaPercentages:u,croppedAreaPixels:y}}function Ke(a,o){return Math.min(a,Math.max(0,o))}function Je(a,o){return o}function Qe(a,o,e,t,r,i){var n=A(o.width,o.height,e),s=O(t.width/n.width*(100/a.width),r,i),c={x:s*n.width/2-t.width/2-n.width*s*(a.x/100),y:s*n.height/2-t.height/2-n.height*s*(a.y/100)};return{crop:c,zoom:s}}function et(a,o,e){var t=Xe(o);return e.height>e.width?e.height/(a.height*t):e.width/(a.width*t)}function tt(a,o,e,t,r,i){e===void 0&&(e=0);var n=A(o.naturalWidth,o.naturalHeight,e),s=O(et(a,o,t),r,i),c=t.height>t.width?t.height/a.height:t.width/a.width,l={x:((n.width-a.width)/2-a.x)*c,y:((n.height-a.height)/2-a.y)*c};return{crop:l,zoom:s}}function ce(a,o){return{x:(o.x+a.x)/2,y:(o.y+a.y)/2}}function rt(a){return a*Math.PI/180}function A(a,o,e){var t=rt(e);return{width:Math.abs(Math.cos(t)*a)+Math.abs(Math.sin(t)*o),height:Math.abs(Math.sin(t)*a)+Math.abs(Math.cos(t)*o)}}function O(a,o,e){return Math.min(Math.max(a,o),e)}function L(){for(var a=[],o=0;o0}).join(" ").trim()}var ot=`.reactEasyCrop_Container { + */function e(t,r){if(!a.canUseDOM||r&&!("addEventListener"in document))return!1;var i="on"+t,n=i in document;if(!n){var s=document.createElement("div");s.setAttribute(i,"return;"),n=typeof s[i]=="function"}return!n&&o&&t==="wheel"&&(n=document.implementation.hasFeature("Events.wheel","3.0")),n}return q=e,q}var G,oe;function $e(){if(oe)return G;oe=1;var a=We(),o=Be(),e=10,t=40,r=800;function i(n){var s=0,c=0,l=0,p=0;return"detail"in n&&(c=n.detail),"wheelDelta"in n&&(c=-n.wheelDelta/120),"wheelDeltaY"in n&&(c=-n.wheelDeltaY/120),"wheelDeltaX"in n&&(s=-n.wheelDeltaX/120),"axis"in n&&n.axis===n.HORIZONTAL_AXIS&&(s=c,c=0),l=s*e,p=c*e,"deltaY"in n&&(p=n.deltaY),"deltaX"in n&&(l=n.deltaX),(l||p)&&n.deltaMode&&(n.deltaMode==1?(l*=t,p*=t):(l*=r,p*=r)),l&&!s&&(s=l<1?-1:1),p&&!c&&(c=p<1?-1:1),{spinX:s,spinY:c,pixelX:l,pixelY:p}}return i.getEventType=function(){return a.firefox()?"DOMMouseScroll":o("wheel")?"wheel":"mousewheel"},G=i,G}var Y,ie;function He(){return ie||(ie=1,Y=$e()),Y}var qe=He();const Ge=Pe(qe);function Ye(a,o,e,t,r,i){i===void 0&&(i=0);var n=A(a,o,i),s=n.width,c=n.height,l=Math.min(s,e),p=Math.min(c,t);return l>p*r?{width:p*r,height:p}:{width:l,height:l/r}}function Xe(a){return a.width>a.height?a.width/a.naturalWidth:a.height/a.naturalHeight}function T(a,o,e,t,r){r===void 0&&(r=0);var i=A(o.width,o.height,r),n=i.width,s=i.height;return{x:ne(a.x,n,e.width,t),y:ne(a.y,s,e.height,t)}}function ne(a,o,e,t){var r=Math.abs(o*t/2-e/2);return O(a,-r,r)}function ae(a,o){return Math.sqrt(Math.pow(a.y-o.y,2)+Math.pow(a.x-o.x,2))}function se(a,o){return Math.atan2(o.y-a.y,o.x-a.x)*180/Math.PI}function Ve(a,o,e,t,r,i,n){i===void 0&&(i=0),n===void 0&&(n=!0);var s=n?Ke:Je,c=A(o.width,o.height,i),l=A(o.naturalWidth,o.naturalHeight,i),p={x:s(100,((c.width-e.width/r)/2-a.x/r)/c.width*100),y:s(100,((c.height-e.height/r)/2-a.y/r)/c.height*100),width:s(100,e.width/c.width*100/r),height:s(100,e.height/c.height*100/r)},d=Math.round(s(l.width,p.width*l.width/100)),h=Math.round(s(l.height,p.height*l.height/100)),m=l.width>=l.height*t,w=m?{width:Math.round(h*t),height:h}:{width:d,height:Math.round(d/t)},y=b(b({},w),{x:Math.round(s(l.width-w.width,p.x*l.width/100)),y:Math.round(s(l.height-w.height,p.y*l.height/100))});return{croppedAreaPercentages:p,croppedAreaPixels:y}}function Ke(a,o){return Math.min(a,Math.max(0,o))}function Je(a,o){return o}function Qe(a,o,e,t,r,i){var n=A(o.width,o.height,e),s=O(t.width/n.width*(100/a.width),r,i),c={x:s*n.width/2-t.width/2-n.width*s*(a.x/100),y:s*n.height/2-t.height/2-n.height*s*(a.y/100)};return{crop:c,zoom:s}}function et(a,o,e){var t=Xe(o);return e.height>e.width?e.height/(a.height*t):e.width/(a.width*t)}function tt(a,o,e,t,r,i){e===void 0&&(e=0);var n=A(o.naturalWidth,o.naturalHeight,e),s=O(et(a,o,t),r,i),c=t.height>t.width?t.height/a.height:t.width/a.width,l={x:((n.width-a.width)/2-a.x)*c,y:((n.height-a.height)/2-a.y)*c};return{crop:l,zoom:s}}function ce(a,o){return{x:(o.x+a.x)/2,y:(o.y+a.y)/2}}function rt(a){return a*Math.PI/180}function A(a,o,e){var t=rt(e);return{width:Math.abs(Math.cos(t)*a)+Math.abs(Math.sin(t)*o),height:Math.abs(Math.sin(t)*a)+Math.abs(Math.cos(t)*o)}}function O(a,o,e){return Math.min(Math.max(a,o),e)}function L(){for(var a=[],o=0;o0}).join(" ").trim()}var ot=`.reactEasyCrop_Container { position: absolute; top: 0; left: 0; @@ -106,4 +106,4 @@ import{e as X,i as B,F as V,aZ as ve,a_ as ge,u as we,J as xe,K as ye,N as be,j border-left: 0; border-right: 0; } -`,it=1,nt=3,at=1,st=(function(a){Re(o,a);function o(){var e=a!==null&&a.apply(this,arguments)||this;return e.cropperRef=g.createRef(),e.imageRef=g.createRef(),e.videoRef=g.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=Qe(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=tt(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,d=((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,h=((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":y={width:e.containerRect.width,height:e.containerRect.width/w};break;case"vertical-cover":y={width:e.containerRect.height*w,height:e.containerRect.height};break}else y={width:l.offsetWidth,height:l.offsetHeight};e.mediaSize=b(b({},y),{naturalWidth:d,naturalHeight:h}),e.props.setMediaSize&&e.props.setMediaSize(e.mediaSize);var f=e.props.cropSize?e.props.cropSize:Ye(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?T(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=Ge(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),d=e.getPointOnMedia(u),h={x:d.x*l-u.x,y:d.y*l-u.y},m=e.props.restrictPosition?T(h,e.mediaSize,e.state.cropSize,l,e.props.rotation):h;e.props.onCropChange(m)}e.props.onZoomChange(l)}},e.getCropData=function(){if(!e.state.cropSize)return null;var t=e.props.restrictPosition?T(e.props.crop,e.mediaSize,e.state.cropSize,e.props.zoom,e.props.rotation):e.props.crop;return Ve(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?T(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,d=n.rotation,h=l;if(e.state.cropSize){t.shiftKey&&(h*=.2);var m=b({},s);switch(t.key){case"ArrowUp":m.y-=h,t.preventDefault();break;case"ArrowDown":m.y+=h,t.preventDefault();break;case"ArrowLeft":m.x-=h,t.preventDefault();break;case"ArrowRight":m.x+=h,t.preventDefault();break;default:return}e.props.restrictPosition&&(m=T(m,e.mediaSize,e.state.cropSize,u,d)),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=ot,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,d;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&&((d=this.videoRef.current)===null||d===void 0||d.load());var h=this.getObjectFit();h!==this.state.mediaObjectFit&&this.setState({mediaObjectFit:h},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(Ee,{"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(Se,{"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(_e,{"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(ze,{"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 pe=["image/png","image/jpeg","image/webp"],he=2*1024*1024,de=256,lt=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}`},ut=(a,o,e=Date.now())=>`profile-pictures/${a}/${e}-${lt(o)}`,fe=a=>pe.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.",pt=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}),le=(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=de)=>{const e=await pt(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 le(t,"image/webp",.9)}catch{return await le(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))},dt=async(a,o,e)=>{const t=ge.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}`)}},ft=async({file:a,uid:o,currentUser:e=V.currentUser,syncFirestore:t=!0})=>{const r=fe(a);if(r)throw new Error(r);const i=e??V.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,de),2e4,"Image processing"),c=ut(n,a.name),l=Me(ve,c),u=await j(Ae(l,s,{contentType:s.type||"image/webp",cacheControl:"public, max-age=31536000, immutable"}),3e4,"Storage upload"),d=await j(Ne(u.ref),1e4,"Download URL retrieval");try{await j(De(i,{photoURL:d}),1e4,"Auth profile update")}catch(h){console.warn("[PROFILE UPLOAD] Auth profile update failed (non-fatal):",h)}if(t)try{await j(dt(i,n,d),1e4,"Firestore profile sync")}catch(h){console.error("[PROFILE UPLOAD] Firestore REST sync failed:",h),console.warn("[PROFILE UPLOAD] Photo was uploaded but the database record may be stale. It will refresh on next login.")}return d},mt=a=>`${(a/(1024*1024)).toFixed(1)} MB`,vt=a=>{const o=(a||"").trim();return o?o.split(/\s+/).slice(0,2).map(e=>e[0]?.toUpperCase()).join(""):"U"},gt=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}),ue=(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)}),wt=async(a,o,e)=>{const t=await gt(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 ue(r,"image/webp",.92)}catch{s=await ue(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}=we(),[c,l]=g.useState(null),[u,d]=g.useState(null),[h,m]=g.useState({x:0,y:0}),[w,y]=g.useState(1),[f,R]=g.useState(null),[x,v]=g.useState(""),[E,_]=g.useState(!1),P=g.useRef(null);g.useEffect(()=>{if(!c){d(null);return}const C=URL.createObjectURL(c);return d(C),()=>URL.revokeObjectURL(C)},[c]);const k=u||o||"",W=g.useMemo(()=>`${pe.map(S=>S.replace("image/","").toUpperCase()).join(", ")} up to ${mt(he)}. The image will be cropped to a circular avatar.`,[]),D=()=>{l(null),m({x:0,y:0}),y(1),R(null),v(""),P.current&&(P.current.value="")},z=C=>{const S=C.target.files?.[0]||null;if(!S)return;const M=fe(S);if(M){v(M),l(null),C.target.value="";return}v(""),l(S),m({x:0,y:0}),y(1),R(null)},N=async()=>{if(!c){v("Choose an image before saving.");return}_(!0),v("");const C=6e4;let S;try{const M=(async()=>{const I=u&&f?await wt(u,f,c):c,Z=a||n?.uid;return ft({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)}),me=await Promise.race([M,F]);r?.(me),s().catch(I=>console.warn("[ProfilePictureUploader] refreshProfile failed:",I)),J.success("Profile picture updated."),D()}catch(M){const F=M instanceof Error?M.message:"Failed to update your profile picture.";v(F),J.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(xe,{className:"size-16 sm:size-20 ring-4 ring-sky-50 shadow-sm transition-transform duration-200 group-hover:scale-105",children:[p.jsx(ye,{src:k,alt:`${e||"User"} profile picture`}),p.jsx(be,{className:"bg-gradient-to-br from-sky-600 to-cyan-500 text-lg font-semibold text-white",children:vt(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(Le,{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."}),x&&p.jsx("p",{className:"text-xs font-medium text-rose-600 mt-1",children:x})]}),p.jsx("input",{ref:P,type:"file",accept:"image/*",onChange:z,className:"sr-only","aria-label":"Choose profile picture"})]}),p.jsx(Ce,{children:u&&p.jsxs(p.Fragment,{children:[p.jsx(K.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(K.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(Te,{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(st,{image:u,crop:h,zoom:w,aspect:1,cropShape:"round",showGrid:!1,objectFit:"cover",restrictPosition:!0,onCropChange:m,onZoomChange:y,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(je,{size:18,className:"text-slate-500"}),p.jsx(ct,{value:[w],min:1,max:3,step:.05,onValueChange:C=>y(C[0]||1),"aria-label":"Profile picture zoom",className:"flex-1 cursor-pointer"}),p.jsx(Ue,{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(Q,{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(Q,{type:"button",onClick:N,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(Fe,{size:16,className:"animate-pulse"}),"Saving..."]}):"Save picture"})]})]})})]})})]})};export{Mt as M,Nt as P,At as V}; +`,it=1,nt=3,at=1,st=(function(a){Re(o,a);function o(){var e=a!==null&&a.apply(this,arguments)||this;return e.cropperRef=g.createRef(),e.imageRef=g.createRef(),e.videoRef=g.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=Qe(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=tt(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 p=e.containerRect.width/e.containerRect.height,d=((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,h=((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":y={width:e.containerRect.width,height:e.containerRect.width/w};break;case"vertical-cover":y={width:e.containerRect.height*w,height:e.containerRect.height};break}else y={width:l.offsetWidth,height:l.offsetHeight};e.mediaSize=b(b({},y),{naturalWidth:d,naturalHeight:h}),e.props.setMediaSize&&e.props.setMediaSize(e.mediaSize);var f=e.props.cropSize?e.props.cropSize:Ye(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?T(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=Ge(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 p=e.getPointOnContainer(r,e.containerPosition),d=e.getPointOnMedia(p),h={x:d.x*l-p.x,y:d.y*l-p.y},m=e.props.restrictPosition?T(h,e.mediaSize,e.state.cropSize,l,e.props.rotation):h;e.props.onCropChange(m)}e.props.onZoomChange(l)}},e.getCropData=function(){if(!e.state.cropSize)return null;var t=e.props.restrictPosition?T(e.props.crop,e.mediaSize,e.state.cropSize,e.props.zoom,e.props.rotation):e.props.crop;return Ve(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?T(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,p=n.zoom,d=n.rotation,h=l;if(e.state.cropSize){t.shiftKey&&(h*=.2);var m=b({},s);switch(t.key){case"ArrowUp":m.y-=h,t.preventDefault();break;case"ArrowDown":m.y+=h,t.preventDefault();break;case"ArrowLeft":m.x-=h,t.preventDefault();break;case"ArrowRight":m.x+=h,t.preventDefault();break;default:return}e.props.restrictPosition&&(m=T(m,e.mediaSize,e.state.cropSize,p,d)),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=ot,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,p,d;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)!==((p=this.props.crop)===null||p===void 0?void 0:p.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&&((d=this.videoRef.current)===null||d===void 0||d.load());var h=this.getObjectFit();h!==this.state.mediaObjectFit&&this.setState({mediaObjectFit:h},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,p=c/l;return pArray.isArray(e)?e:Array.isArray(o)?o:[t,r],[e,o,t,r]);return u.jsxs(Ee,{"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:[u.jsx(Se,{"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:u.jsx(_e,{"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)=>u.jsx(ze,{"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 ue=["image/png","image/jpeg","image/webp"],he=2*1024*1024,de=256,lt=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}-${lt(o)}`,fe=a=>ue.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.",ut=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}),le=(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=de)=>{const e=await ut(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 le(t,"image/webp",.9)}catch{return await le(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))},dt=async(a,o,e)=>{const t=ge.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}`)}},ft=async({file:a,uid:o,currentUser:e=V.currentUser,syncFirestore:t=!0})=>{const r=fe(a);if(r)throw new Error(r);const i=e??V.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,de),2e4,"Image processing"),c=pt(n,a.name),l=Me(ve,c),p=await j(Ae(l,s,{contentType:s.type||"image/webp",cacheControl:"public, max-age=31536000, immutable"}),3e4,"Storage upload"),d=await j(Ne(p.ref),1e4,"Download URL retrieval");try{await j(De(i,{photoURL:d}),1e4,"Auth profile update")}catch(h){console.warn("[PROFILE UPLOAD] Auth profile update failed (non-fatal):",h)}if(t)try{await j(dt(i,n,d),1e4,"Firestore profile sync")}catch(h){console.error("[PROFILE UPLOAD] Firestore REST sync failed:",h),console.warn("[PROFILE UPLOAD] Photo was uploaded but the database record may be stale. It will refresh on next login.")}return d},mt=a=>`${(a/(1024*1024)).toFixed(1)} MB`,vt=a=>{const o=(a||"").trim();return o?o.split(/\s+/).slice(0,2).map(e=>e[0]?.toUpperCase()).join(""):"U"},gt=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)}),wt=async(a,o,e)=>{const t=await gt(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",p=`${e.name.replace(/\.[^/.]+$/,"")||"profile-picture"}-cropped.${c}`;return new File([s],p,{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}=we(),[c,l]=g.useState(null),[p,d]=g.useState(null),[h,m]=g.useState({x:0,y:0}),[w,y]=g.useState(1),[f,R]=g.useState(null),[x,v]=g.useState(""),[E,_]=g.useState(!1),P=g.useRef(null);g.useEffect(()=>{if(!c){d(null);return}const C=URL.createObjectURL(c);return d(C),()=>URL.revokeObjectURL(C)},[c]);const k=p||o||"",W=g.useMemo(()=>`${ue.map(S=>S.replace("image/","").toUpperCase()).join(", ")} up to ${mt(he)}. The image will be cropped to a circular avatar.`,[]),D=()=>{l(null),m({x:0,y:0}),y(1),R(null),v(""),P.current&&(P.current.value="")},z=C=>{const S=C.target.files?.[0]||null;if(!S)return;const M=fe(S);if(M){v(M),l(null),C.target.value="";return}v(""),l(S),m({x:0,y:0}),y(1),R(null)},N=async()=>{if(!c){v("Choose an image before saving.");return}_(!0),v("");const C=6e4;let S;try{const M=(async()=>{const I=p&&f?await wt(p,f,c):c,Z=a||n?.uid;return ft({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)}),me=await Promise.race([M,F]);r?.(me),s().catch(I=>console.warn("[ProfilePictureUploader] refreshProfile failed:",I)),J.success("Profile picture updated."),D()}catch(M){const F=M instanceof Error?M.message:"Failed to update your profile picture.";v(F),J.error(F)}finally{clearTimeout(S),_(!1)}},U=()=>{P.current?.click()};return u.jsxs(u.Fragment,{children:[u.jsxs("section",{className:`flex items-center gap-4 rounded-xl border border-slate-200 bg-white p-4 shadow-sm ${t}`,children:[u.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:[u.jsxs(xe,{className:"size-16 sm:size-20 ring-4 ring-sky-50 shadow-sm transition-transform duration-200 group-hover:scale-105",children:[u.jsx(ye,{src:k,alt:`${e||"User"} profile picture`}),u.jsx(be,{className:"bg-gradient-to-br from-sky-600 to-cyan-500 text-lg font-semibold text-white",children:vt(e)})]}),u.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:u.jsx(Le,{size:14})})]}),u.jsxs("div",{className:"space-y-1 flex-1",children:[u.jsx("p",{className:"text-sm font-semibold text-slate-900",children:"Profile picture"}),u.jsx("p",{className:"text-xs text-slate-500",children:"Click your avatar to upload a new photo."}),x&&u.jsx("p",{className:"text-xs font-medium text-rose-600 mt-1",children:x})]}),u.jsx("input",{ref:P,type:"file",accept:"image/*",onChange:z,className:"sr-only","aria-label":"Choose profile picture"})]}),u.jsx(Ce,{children:p&&u.jsxs(u.Fragment,{children:[u.jsx(K.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 bg-black/60 backdrop-blur-sm z-[60]",onClick:D}),u.jsx(K.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:u.jsxs("div",{className:"bg-white rounded-2xl shadow-xl w-full max-w-lg overflow-hidden flex flex-col",children:[u.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-slate-100",children:[u.jsx("h3",{className:"text-lg font-bold text-slate-900",children:"Update profile picture"}),u.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:u.jsx(Te,{size:20})})]}),u.jsxs("div",{className:"p-4 sm:p-6 bg-slate-50 flex flex-col items-center",children:[u.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:u.jsx(st,{image:p,crop:h,zoom:w,aspect:1,cropShape:"round",showGrid:!1,objectFit:"cover",restrictPosition:!0,onCropChange:m,onZoomChange:y,onCropComplete:(C,S)=>R(S),style:{containerStyle:{backgroundColor:"#f8fafc"}}})}),u.jsxs("div",{className:"mt-6 w-full max-w-xs flex items-center gap-4",children:[u.jsx(je,{size:18,className:"text-slate-500"}),u.jsx(ct,{value:[w],min:1,max:3,step:.05,onValueChange:C=>y(C[0]||1),"aria-label":"Profile picture zoom",className:"flex-1 cursor-pointer"}),u.jsx(Ue,{size:18,className:"text-slate-500"})]}),u.jsx("p",{className:"mt-4 text-xs text-slate-500 text-center",children:W})]}),u.jsxs("div",{className:"p-4 border-t border-slate-100 flex items-center justify-end gap-3 bg-white",children:[u.jsx(Q,{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"}),u.jsx(Q,{type:"button",onClick:N,disabled:E||!c,className:"bg-sky-600 hover:bg-sky-700 text-white min-w-[120px] gap-2 shadow-sm",children:E?u.jsxs(u.Fragment,{children:[u.jsx(Fe,{size:16,className:"animate-pulse"}),"Saving..."]}):"Save picture"})]})]})})]})})]})};export{Mt as M,Nt as P,At as V}; diff --git a/assets/QuizBattlePage-Bwu0snEF.js b/assets/QuizBattlePage-BaCri_Ce.js similarity index 62% rename from assets/QuizBattlePage-Bwu0snEF.js rename to assets/QuizBattlePage-BaCri_Ce.js index 51395bef32cf584d80f526077ccea397c65ba65c..2fa62148ddbef359a4f749997a0e6536306753a7 100644 --- a/assets/QuizBattlePage-Bwu0snEF.js +++ b/assets/QuizBattlePage-BaCri_Ce.js @@ -1,19 +1,14 @@ -import{e as Et,i as x,m as y,f as tt,aE as De,F as rt,aF as Q,O as Va,y as Ct,M as Wa,w as Pe,U as ve,j as Ke,l as Je,u as Ua,_ as Ya,P as wt,X as vt,x as jt,W as Xa}from"./index-BaOs5Ayg.js";import{r as i,j as e,d as Rt}from"./vendor-react-B4AQeu28.js";import{q as yt}from"./quiz_battle_avatar-BXHPSput.js";import{g as Ga,s as ea}from"./subjects-BFghB0SQ.js";import{doc as Za,getDoc as Ka,where as ta,orderBy as pa,limit as zt,getDocs as It,query as Mt,collection as Bt}from"./vendor-firebase-firestore-CH1lNiRF.js";import{$ as q,a0 as ha,a1 as ba,a2 as Ie,a3 as Ja}from"./vendor-firebase-core-CO26nNq6.js";import{B as A}from"./button-DCfeFHoH.js";import{a as te,b as le,c as ie,e as pe,d as ge,C as aa}from"./card-D4dmQVNb.js";import{f as es,g as ts}from"./vendor-radix-BorKzPz9.js";import{S as _e,a as Se,b as Ae,c as Ce,d as J}from"./select-DIjxRWza.js";import{I as as}from"./input-D28h_UTJ.js";import{S as sa}from"./switch-CblAJO7o.js";import{S as we}from"./skeleton-Bo6ISWhm.js";import{V as fa,a as ga,M as ss,b as rs}from"./volume-x-Chtf_bSj.js";import{C as ns}from"./CompositeAvatar-Col05lJc.js";import{S as et}from"./sparkles-By-vFjpv.js";import{C as kt}from"./check-BLSo9L0H.js";import{C as Ye}from"./chevron-right-COqGruhh.js";import{S as os}from"./shield-check-Dgisjfmb.js";import"./vendor-firebase-auth-BLpRW_zO.js";import"./vendor-firebase-storage-B3igpVVS.js";import"./vendor-firebase-analytics-CTiUNb0-.js";import"./vendor-charts-D8hf8tI0.js";import"./vendor-markdown-yqZQ_iQm.js";import"./chart-column-B3jJOD5i.js";import"./chevron-up-Cdvz2TMJ.js";import"./avatarData-BuQSOXo3.js";/** +import{e as xa,k as u,m as y,h as tt,aF as De,I as rt,aG as Q,Q as Va,q as Ct,M as Wa,E as Pe,U as ve,g as Ke,p as Je,l as Ua,_ as Ya,V as wt,$ as vt,z as jt,Y as Xa}from"./index-uASBzalf.js";import{r as i,j as e,d as Et}from"./vendor-react-B4AQeu28.js";import{q as yt}from"./quiz_battle_avatar-BXHPSput.js";import{g as Ga,s as Jt}from"./subjects-F8wTuRgo.js";import{doc as Za,getDoc as Ka,where as ea,orderBy as pa,limit as zt,getDocs as It,query as Bt,collection as Mt}from"./vendor-firebase-firestore-CP9q7ISf.js";import{a4 as q,a5 as ha,a6 as ba,a7 as Ie,a8 as Ja}from"./vendor-firebase-core-DCQrgkxC.js";import{B as A}from"./button-BPmLcOpC.js";import{e as es,f as ts}from"./vendor-radix-xDOIcVzp.js";import{S as _e,a as Se,b as Ae,c as Ce,d as J}from"./select--QYuvUGV.js";import{I as as}from"./input--XHWlmp1.js";import{S as ta}from"./switch-CZbBlSot.js";import{S as ge}from"./skeleton-Ds4RcTr4.js";import{V as fa,a as ga,M as ss,b as rs}from"./volume-x-b1BHmkg3.js";import{C as ns}from"./CompositeAvatar-Col05lJc.js";import{S as et}from"./sparkles-DHVr5IP1.js";import{C as kt}from"./check-Dk6iwDFI.js";import{H as aa,C as sa}from"./history-UFBxnE6Z.js";import{C as Ye}from"./chevron-right-U0AqPOPj.js";import{S as os}from"./shield-check-vm2tbr1-.js";import"./vendor-firebase-auth-Bcpr4O6E.js";import"./vendor-firebase-storage-dc5X5yTv.js";import"./vendor-firebase-analytics-CHPyhRzk.js";import"./vendor-charts-Ckgeb0nY.js";import"./vendor-markdown-yqZQ_iQm.js";import"./chart-column-CLoxLorp.js";import"./chevron-up-BpMhRyJp.js";import"./avatarData-BuQSOXo3.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 ls=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["polyline",{points:"12 6 12 12 16.5 12",key:"1aq6pp"}]],ra=Et("clock-3",ls);/** + */const ls=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["polyline",{points:"12 6 12 12 16.5 12",key:"1aq6pp"}]],ra=xa("clock-3",ls);/** * @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 is=[["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"}]],na=Et("history",is);/** - * @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 ds=[["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"}]],cs=Et("pause",ds),Xe=({width:a,x:r,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":`${r}`,"--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"}})},oa=({children:a,perspective:r=100,className:n,bgVideo:c,beamsPerSide:d=6,beamSize:l=4,beamDelayMax:w=1.5,beamDelayMin:z=0,beamDuration:g=4,gridColor:k="rgba(100, 116, 139, 0.08)",...b})=>{const j=i.useCallback(()=>{const S=[],Y=Math.floor(100/l)/d;for(let ae=0;aej(),[j]),u=i.useMemo(()=>j(),[j]),v=i.useMemo(()=>j(),[j]),U=i.useMemo(()=>j(),[j]);return e.jsxs("div",{className:x("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":`${r}px`,"--grid-color":k,"--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,E)=>e.jsx(Xe,{width:`${l}%`,x:`${S.x*l}%`,delay:S.delay,duration:g},`top-${E}`))}),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,E)=>e.jsx(Xe,{width:`${l}%`,x:`${S.x*l}%`,delay:S.delay,duration:g},`bottom-${E}`))}),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:U.map((S,E)=>e.jsx(Xe,{width:`${l}%`,x:`${S.x*l}%`,delay:S.delay,duration:g},`left-${E}`))}),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:u.map((S,E)=>e.jsx(Xe,{width:`${l}%`,x:`${S.x*l}%`,delay:S.delay,duration:g},`right-${E}`))})]}),e.jsx("div",{className:"relative z-10 w-full h-full",children:a})]})},us=15e3,ms="mathpulse.quizBattle.local",la="".toLowerCase()==="true",nt=typeof window<"u",at=()=>nt&&!1,Tt=()=>{const a=rt.currentUser?.uid;return a||"local-student"},wa=a=>`${ms}.${a}`,Qe=a=>{const r={stats:Me(a),history:[],queueStatus:"idle"};if(!nt)return r;try{const n=window.localStorage.getItem(wa(a));if(!n)return r;const c=JSON.parse(n),d=Array.isArray(c.history)?c.history.map(w=>Ft(w.matchId||"local-match",w)):[];return{stats:c.stats?{...Me(a),...c.stats,userId:a,updatedAt:st(c.stats.updatedAt)}:Me(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),r}},va=(a,r)=>{if(nt)try{window.localStorage.setItem(wa(a),JSON.stringify(r))}catch(n){console.error("Error writing local Quiz Battle fallback store:",n)}},ja=a=>{const r=a||{},n=typeof r.code=="string"?r.code:"";return n?n.startsWith("functions/")?n.replace("functions/",""):n:""},ce=a=>{if(!at())return!1;const r=ja(a);if(["internal","not-found","unavailable","deadline-exceeded"].includes(r))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},Ge=(a,r)=>Math.floor(Math.random()*(r-a+1))+a,xs=(a,r)=>{const n=Math.max(3,a),c=r==="easy"?0:r==="medium"?1:r==="hard"?2:1,d=Ge(Math.max(0,n-3-c),n),l=Ge(Math.max(0,n-4+c),n),w=Math.min(n,Math.max(0,d)),z=Math.min(n,Math.max(0,l)),g=Math.max(0,Math.min(100,w/n*100+Ge(-8,6))),k=Ge(1800,6200);return{scoreFor:w,scoreAgainst:z,accuracy:g,averageResponseMs:k}},ps=a=>{const r=Tt(),n=Qe(r),c=`local-bot-${Date.now()}-${Math.random().toString(16).slice(2,8)}`,d=xs(a.rounds,a.botDifficulty),l=d.scoreFor>d.scoreAgainst?"win":d.scoreFor0?u/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:E,favoriteTopicId:a.topicId,leaderboardScore:n.stats.leaderboardScore+j.xpEarned,updatedAt:w};return va(r,{stats:Y,history:[j,...n.history].slice(0,50),queueStatus:"idle"}),{success:!0,matchId:c,status:"ready",botDifficulty:a.botDifficulty}},ya=a=>{const r=Tt(),n=Qe(r);va(r,{...n,queueStatus:a})},hs=()=>Math.random().toString(36).slice(2,8).toUpperCase(),Pt=a=>{const r=Tt();return{roomId:`local-room-${Date.now()}`,roomCode:a||hs(),ownerStudentId:r,participantIds:[r],participantCount:1,status:"waiting",subjectId:"gen-math",topicId:"functions",difficulty:"medium",rounds:5,timePerQuestionSec:30,isOwner:!0}},ka=()=>nt&&!!rt.currentUser?.uid&&!!De,Na=(a,r,n)=>`quizBattlePresence/${a}/${r}/${n}`,bs=async(a,r)=>{if(!ka()||!r.trim()||!De)return;const n=rt.currentUser?.uid;if(!n)return;const c=ha(De,Na(a,r,n));try{await ba(c,{studentId:n,scope:a,resourceId:r,online:!0,heartbeatAt:Ie(),updatedAt:Ie()}),await Ja(c).update({online:!1,updatedAt:Ie(),disconnectedAt:Ie()})}catch(d){console.warn("Realtime presence connect failed:",d)}},fs=async(a,r)=>{if(!ka()||!r.trim()||!De)return;const n=rt.currentUser?.uid;if(!n)return;const c=ha(De,Na(a,r,n));try{await ba(c,{studentId:n,scope:a,resourceId:r,online:!1,updatedAt:Ie(),disconnectedAt:Ie()})}catch(d){console.warn("Realtime presence disconnect failed:",d)}},H=(a,r)=>{const n=`Unable to continue while ${a}. Please try again.`;if(r instanceof Error&&r.message.startsWith("Timed out while"))return r.message;const c=r||{},d=ja(r),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},L=async(a,r,n=us)=>{let c;try{return await Promise.race([r,new Promise((d,l)=>{c=setTimeout(()=>{l(new Error(`Timed out while ${a}. Please try again.`))},n)})])}finally{c&&clearTimeout(c)}},st=a=>{if(!a)return new Date;if(a instanceof Date)return a;if(typeof a=="string"){const r=Date.parse(a);return Number.isNaN(r)?new Date:new Date(r)}if(typeof a=="number")return new Date(a);if(typeof a=="object"){const r=a;if(typeof r.toDate=="function")return r.toDate();if(typeof r.seconds=="number")return new Date(r.seconds*1e3)}return new Date},gs=()=>({mode:"online",subjectId:"gen-math",topicId:"",difficulty:"medium",rounds:5,timePerQuestionSec:30,queueType:"public_matchmaking",botDifficulty:"medium",adaptiveBot:!1}),ws=a=>{const r=[];return a.subjectId.trim()||r.push({field:"subjectId",message:"Choose a category before starting."}),a.topicId.trim()||r.push({field:"topicId",message:"Choose a strand or topic before starting."}),(a.rounds<3||a.rounds>20)&&r.push({field:"rounds",message:"Questions must be between 3 and 20."}),(a.timePerQuestionSec<10||a.timePerQuestionSec>180)&&r.push({field:"timePerQuestionSec",message:"Timer must be between 10s and 180s."}),a.mode==="bot"&&a.queueType!=="public_matchmaking"&&r.push({field:"queueType",message:"Bot battles use instant start and do not support private room mode."}),r},Me=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}),vs=async a=>{try{const r=Za(tt,"studentBattleStats",a),n=await Ka(r),c=at()?Qe(a).stats:null;if(!n.exists())return c&&c.matchesPlayed>0?c:Me(a);const d=n.data(),l={...Me(a),...d,userId:a,updatedAt:st(d.updatedAt)};return c&&c.matchesPlayed>l.matchesPlayed?c:l}catch(r){if(console.error("Error loading battle stats:",r),at()){const n=Qe(a).stats;if(n.matchesPlayed>0)return n}return Me(a)}},Ft=(a,r)=>({matchId:r.matchId||a,mode:r.mode||"online",status:r.status||"completed",subjectId:r.subjectId||"gen-math",topicId:r.topicId||"unknown-topic",difficulty:r.difficulty||"medium",rounds:r.rounds||0,timePerQuestionSec:r.timePerQuestionSec||0,scoreFor:r.scoreFor||0,scoreAgainst:r.scoreAgainst||0,outcome:r.outcome||"draw",accuracy:r.accuracy||0,averageResponseMs:r.averageResponseMs||0,bestStreak:r.bestStreak||0,xpEarned:r.xpEarned||0,opponentName:r.opponentName||"Unknown opponent",opponentType:r.opponentType||"student",createdAt:st(r.createdAt),endedAt:st(r.endedAt)}),js=async(a,r={})=>{const n=r.limitCount||25,c=at()?Qe(a).history:[],d=w=>w.filter(g=>!(r.mode&&r.mode!=="all"&&g.mode!==r.mode||r.subjectId&&g.subjectId!==r.subjectId||r.startDate&&g.endedAtr.endDate)).sort((g,k)=>k.endedAt.getTime()-g.endedAt.getTime()).slice(0,n),l=w=>{if(c.length===0)return d(w);const z=new Map;return[...c,...w].forEach(g=>{z.set(g.matchId,g)}),d(Array.from(z.values()))};try{const w=[ta("studentId","==",a),pa("endedAt","desc"),zt(n)],g=(await It(Mt(Bt(tt,"quizBattleHistory"),...w))).docs.map(k=>Ft(k.id,k.data()));return l(g)}catch(w){try{const g=(await It(Mt(Bt(tt,"quizBattleHistory"),ta("studentId","==",a),zt(n)))).docs.map(k=>Ft(k.id,k.data())).sort((k,b)=>b.endedAt.getTime()-k.endedAt.getTime());return l(g)}catch(z){return console.error("Error loading battle history:",w,z),d(c)}}},ys=async a=>{const r=q(Q,"quizBattleJoinQueue");try{return(await L("joining Quiz Battle matchmaking queue",r({setup:a}))).data}catch(n){if(ce(n))return ya("queued"),{success:!0,status:"queued",queueEntryId:`local-queue-${Date.now()}`};throw new Error(H("joining Quiz Battle matchmaking queue",n))}},ia=async()=>{const a=q(Q,"quizBattleLeaveQueue");try{return(await L("leaving Quiz Battle matchmaking queue",a({}))).data}catch(r){if(ce(r))return ya("idle"),{success:!0,status:"idle"};throw new Error(H("leaving Quiz Battle matchmaking queue",r))}},ks=async a=>{const r=q(Q,"quizBattleCreatePrivateRoom");try{return(await L("creating Quiz Battle private room",r({setup:a}))).data}catch(n){if(ce(n))return{success:!0,room:Pt()};throw new Error(H("creating Quiz Battle private room",n))}},Ns=async a=>{const r=q(Q,"quizBattleJoinPrivateRoom");try{return(await L("joining Quiz Battle private room",r({roomCode:a}),2e4)).data}catch(n){if(ce(n))return{success:!0,room:Pt(a.trim().toUpperCase()||void 0)};throw new Error(H("joining Quiz Battle private room",n))}},_s=async a=>{const r=q(Q,"quizBattleGetPrivateRoomState");try{return(await L("loading Quiz Battle private room state",r(a),2e4)).data}catch(n){if(ce(n))return{success:!0,room:Pt(a.roomCode?.trim().toUpperCase()||void 0)};throw new Error(H("loading Quiz Battle private room state",n))}},Ss=async(a={})=>{const r=q(Q,"quizBattleLeavePrivateRoom");try{return(await L("leaving Quiz Battle private room",r(a),2e4)).data}catch(n){if(ce(n))return{success:!0,status:"idle"};throw new Error(H("leaving Quiz Battle private room",n))}},da=async()=>{const a=q(Q,"quizBattleResumeSession");try{return(await L("resuming Quiz Battle session",a({}),2e4)).data}catch(r){if(ce(r))return{success:!0,sessionType:"idle"};throw new Error(H("resuming Quiz Battle session",r))}},As=async(a,r)=>{if(!r.trim())return;const n=q(Q,"quizBattleHeartbeat");await bs(a,r);try{await L("sending Quiz Battle heartbeat",n({scope:a,resourceId:r}),12e3)}catch(c){if(!ce(c))throw new Error(H("sending Quiz Battle heartbeat",c))}},Cs=async a=>{const r=q(Q,"quizBattleCreateBotMatch");try{return(await L("starting Quiz Battle bot match",r({setup:a}))).data}catch(n){if(ce(n))return ps(a);throw new Error(H("starting Quiz Battle bot match",n))}},zs=async a=>{const r=q(Q,"quizBattleGetGenerationAudit");return(await L("verifying Quiz Battle generation metadata",r({matchId:a}),2e4)).data},de=async a=>{const r=q(Q,"quizBattleStartMatch");try{const c=(await L("starting Quiz Battle match",r({matchId:a}),2e4)).data.match;if(c.mode==="online")try{const d=await zs(a);if(la&&!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),la)throw new Error("Unable to verify Quiz Battle generation metadata. Please retry in a moment.")}return c}catch(n){throw new Error(H("starting Quiz Battle match",n))}},Nt=async a=>{const r=q(Q,"quizBattleGetMatchState");try{return(await L("loading Quiz Battle match state",r({matchId:a}),2e4)).data.match}catch(n){throw new Error(H("loading Quiz Battle match state",n))}},Is=async a=>{const r=q(Q,"quizBattleSubmitAnswer");try{return(await L("submitting Quiz Battle answer",r({...a,idempotencyKey:a.idempotencyKey||`client-${Date.now()}-${Math.random().toString(16).slice(2,8)}`}),2e4)).data}catch(n){throw new Error(H("submitting Quiz Battle answer",n))}},Ms=async a=>{const r=q(Q,"quizBattleRequestRematch");try{return(await L("creating Quiz Battle rematch",r({matchId:a}),2e4)).data}catch(n){throw new Error(H("creating Quiz Battle rematch",n))}},Bs=async(a=20)=>{try{const r=Mt(Bt(tt,"studentBattleLeaderboard"),pa("leaderboardScore","desc"),zt(a));return(await It(r)).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(r){return console.error("Error loading Quiz Battle leaderboard:",r),[]}};function Fs({className:a,...r}){return e.jsx(es,{"data-slot":"tabs",className:x("flex flex-col gap-2",a),...r})}function ze({className:a,...r}){return e.jsx(ts,{"data-slot":"tabs-content",className:x("flex-1 outline-none",a),...r})}const _a=Rt.memo(({playerRoundStreak:a,playerVisualMultiplier:r,liveXpEarned:n,activeMatch:c,subjects:d,battleSoundEnabled:l,onToggleSound:w,isFullscreen:z,onToggleFullscreen:g,isDesignPauseAvailable:k,onTogglePause:b})=>e.jsxs("header",{className:"flex items-center justify-between shrink-0 h-16 relative gap-4",children:[e.jsx("div",{className:"flex items-center min-w-0",children:e.jsxs("div",{className:"flex items-center gap-3 md:gap-4 px-4 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.5 text-amber-400 font-bold text-sm shrink-0",children:[e.jsx(Va,{className:"w-4 h-4"})," ",a]}),e.jsx("div",{className:"w-px h-4 bg-white/10 shrink-0"}),e.jsxs("div",{className:"flex items-center gap-1.5 text-violet-300 font-bold text-sm shrink-0",children:[e.jsx(Ct,{className:"w-4 h-4"})," ",r.toFixed(2),"x"]}),e.jsx("div",{className:"w-px 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-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-sm leading-none tabular-nums",children:[n," pts"]}),e.jsx("span",{className:"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(u=>u.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-3",children:[e.jsx(A,{variant:"outline",size:"icon",className:"h-12 w-12 rounded-full border-white/20 bg-black/20 hover:bg-white/10 text-white",onClick:w,children:l?e.jsx(fa,{className:"h-5 w-5"}):e.jsx(ga,{className:"h-5 w-5"})}),e.jsx(A,{variant:"outline",size:"icon",className:"h-12 w-12 rounded-full border-white/20 bg-black/20 hover:bg-white/10 text-white",onClick:g,children:z?e.jsx(ss,{className:"h-5 w-5"}):e.jsx(rs,{className:"h-5 w-5"})}),e.jsx(A,{variant:"outline",size:"icon",className:x("h-12 w-12 rounded-full border-white/20 text-white",k?"bg-black/20 hover:bg-white/10":"bg-black/10 opacity-50 cursor-not-allowed"),onClick:b,disabled:!k,children:e.jsx(Wa,{className:"h-5 w-5"})})]})]}));_a.displayName="BattleHeader";const Sa=Rt.memo(({studentProfile:a,activeMatch:r,scorePulseTarget:n,quizBattleAvatar:c})=>e.jsxs("div",{className:"absolute bottom-0 left-0 right-0 w-full xl:max-w-[1400px] mx-auto px-4 md:px-8 shrink-0 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-3 sm:gap-6 relative pointer-events-auto",children:[e.jsx("div",{className:"relative w-28 h-28 md:w-40 md:h-40 rounded-t-[40px] flex items-end",children:e.jsx(ns,{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-2xl px-4 py-3 md:px-5 shadow-[0_8px_30px_rgba(0,0,0,0.5)] flex items-center gap-3 md:gap-4 mb-4 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-base md:text-lg truncate tracking-wide",children:a?.name||"Player"}),e.jsxs("span",{className:"text-xs md:text-sm text-white/50 font-bold uppercase tracking-wider",children:["Level ",a?.level||1]})]}),e.jsx("div",{className:"h-10 w-px bg-white/20"}),e.jsxs("div",{className:"flex flex-col items-center justify-center shrink-0 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-2xl md:text-3xl font-black text-white leading-none",children:r.scoreFor}),e.jsx("span",{className:"text-[9px] md:text-[10px] text-emerald-400 font-bold uppercase tracking-widest mt-1 leading-none",children:"Score"})]})]})]}),e.jsxs("div",{className:"flex items-end gap-3 sm:gap-6 relative flex-row-reverse pointer-events-auto",children:[e.jsx("div",{className:"relative w-28 h-28 md:w-40 md:h-40 bg-[#1a2030] rounded-t-[40px] flex items-end justify-center border-t-4 border-slate-700/50 shadow-inner",children:r.mode==="bot"?e.jsx(Pe,{className:"h-16 w-16 md:h-20 md:w-20 text-rose-400 mb-6 drop-shadow-xl",strokeWidth:1.5}):e.jsx(ve,{className:"h-16 w-16 md:h-20 md:w-20 text-slate-500 mb-6 drop-shadow-xl",strokeWidth:1.5})}),e.jsxs("div",{className:"bg-black/40 backdrop-blur-xl border border-white/20 rounded-2xl px-4 py-3 md:px-5 shadow-[0_8px_30px_rgba(0,0,0,0.5)] flex items-center gap-3 md:gap-4 mb-4 flex-row-reverse text-right 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-base md:text-lg truncate tracking-wide",children:r.opponentName||"Anonymous"}),e.jsx("span",{className:"text-xs md:text-sm text-rose-400 font-bold uppercase tracking-wider",children:r.mode==="bot"?"System Bot":"Challenger"})]}),e.jsx("div",{className:"h-10 w-px bg-white/20"}),e.jsxs("div",{className:"flex flex-col items-center justify-center shrink-0 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-2xl md:text-3xl font-black text-white leading-none",children:r.scoreAgainst}),e.jsx("span",{className:"text-[9px] md:text-[10px] text-rose-400 font-bold uppercase tracking-widest mt-1 leading-none",children:"Score"})]})]})]})]}));Sa.displayName="BattleFooter";const Aa=Rt.memo(({activeMatch:a,roundSecondsLeft:r,lastRoundResult:n,selectedOptionIndex:c,roundLocked:d,answerSubmitting:l,designPauseActive:w,onOptionSelect:z,floatingMomentum:g,lastRoundMomentumDelta:k,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:x("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",r<=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(Ke,{children:g&&g.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:x("absolute -top-12 rounded-full border px-3 py-1 text-[10px] font-black uppercase tracking-[0.15em] backdrop-blur-lg",g.tone==="positive"?"border-emerald-300/70 bg-emerald-500/20 text-emerald-100":g.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:g.label},g.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,u)=>{const v=c===u,U=l||d,S=!!n&&n.roundNumber===a.currentRound,E=S&&n.correctOptionIndex===u;let Y=-1;if(S)if(a.mode==="bot")if(n.botCorrect)Y=n.correctOptionIndex;else{const V=[0,1,2,3].filter(C=>C!==n.correctOptionIndex);Y=V[n.roundNumber%V.length]}else Y=typeof n.botSelectedIndex=="number"?n.botSelectedIndex:-1;const ae=Y===u;let T="bg-[#1e2433] hover:bg-[#283042] border-[#2f384e] text-white shadow-[0_6px_0_rgba(15,20,30,0.5)]";return S?E?T="bg-emerald-500 text-emerald-950 border-emerald-400 shadow-[0_6px_0_rgba(5,150,105,1)]":v?T="bg-rose-500 text-white border-rose-400 shadow-[0_6px_0_rgba(225,29,72,1)]":T="bg-[#1e2433] opacity-40 border-[#2f384e] shadow-[0_6px_0_rgba(15,20,30,0.5)] text-white":v&&(T="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&&!U?{scale:1.02}:{},disabled:U||d||w,onClick:()=>z(u),className:x("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",T,v&&!S?"ring-[4px] ring-white/20 ring-offset-[4px] ring-offset-[#0B0F19]":"",r<=3&&!U&&!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+u)}),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:[ae&&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(Pe,{className:"w-4 h-4 md:w-5 md:h-5 text-white"}):e.jsx(ve,{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"})})]})]},u)})}),e.jsx(Ke,{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(Je,{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(Ke,{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:x("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"})}),k!==null&&k>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:["+ ",k," ",e.jsx(et,{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)]})]})})})]}));Aa.displayName="BattleActiveContent";const _t={width:1280,height:720},St=` + */const is=[["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"}]],ds=xa("pause",is),Xe=({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:z=0,beamDuration:g=4,gridColor:k="rgba(100, 116, 139, 0.08)",...b})=>{const j=i.useCallback(()=>{const S=[],Y=Math.floor(100/l)/d;for(let ae=0;aej(),[j]),m=i.useMemo(()=>j(),[j]),v=i.useMemo(()=>j(),[j]),U=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":k,"--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,E)=>e.jsx(Xe,{width:`${l}%`,x:`${S.x*l}%`,delay:S.delay,duration:g},`top-${E}`))}),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,E)=>e.jsx(Xe,{width:`${l}%`,x:`${S.x*l}%`,delay:S.delay,duration:g},`bottom-${E}`))}),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:U.map((S,E)=>e.jsx(Xe,{width:`${l}%`,x:`${S.x*l}%`,delay:S.delay,duration:g},`left-${E}`))}),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,E)=>e.jsx(Xe,{width:`${l}%`,x:`${S.x*l}%`,delay:S.delay,duration:g},`right-${E}`))})]}),e.jsx("div",{className:"relative z-10 w-full h-full",children:a})]})},cs=15e3,us="mathpulse.quizBattle.local",oa="".toLowerCase()==="true",nt=typeof window<"u",at=()=>nt&&!1,Rt=()=>{const a=rt.currentUser?.uid;return a||"local-student"},wa=a=>`${us}.${a}`,Qe=a=>{const s={stats:Be(a),history:[],queueStatus:"idle"};if(!nt)return s;try{const n=window.localStorage.getItem(wa(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?{...Be(a),...c.stats,userId:a,updatedAt:st(c.stats.updatedAt)}:Be(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}},va=(a,s)=>{if(nt)try{window.localStorage.setItem(wa(a),JSON.stringify(s))}catch(n){console.error("Error writing local Quiz Battle fallback store:",n)}},ja=a=>{const s=a||{},n=typeof s.code=="string"?s.code:"";return n?n.startsWith("functions/")?n.replace("functions/",""):n:""},ce=a=>{if(!at())return!1;const s=ja(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},Ge=(a,s)=>Math.floor(Math.random()*(s-a+1))+a,ms=(a,s)=>{const n=Math.max(3,a),c=s==="easy"?0:s==="medium"?1:s==="hard"?2:1,d=Ge(Math.max(0,n-3-c),n),l=Ge(Math.max(0,n-4+c),n),w=Math.min(n,Math.max(0,d)),z=Math.min(n,Math.max(0,l)),g=Math.max(0,Math.min(100,w/n*100+Ge(-8,6))),k=Ge(1800,6200);return{scoreFor:w,scoreAgainst:z,accuracy:g,averageResponseMs:k}},xs=a=>{const s=Rt(),n=Qe(s),c=`local-bot-${Date.now()}-${Math.random().toString(16).slice(2,8)}`,d=ms(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:E,favoriteTopicId:a.topicId,leaderboardScore:n.stats.leaderboardScore+j.xpEarned,updatedAt:w};return va(s,{stats:Y,history:[j,...n.history].slice(0,50),queueStatus:"idle"}),{success:!0,matchId:c,status:"ready",botDifficulty:a.botDifficulty}},ya=a=>{const s=Rt(),n=Qe(s);va(s,{...n,queueStatus:a})},ps=()=>Math.random().toString(36).slice(2,8).toUpperCase(),Tt=a=>{const s=Rt();return{roomId:`local-room-${Date.now()}`,roomCode:a||ps(),ownerStudentId:s,participantIds:[s],participantCount:1,status:"waiting",subjectId:"gen-math",topicId:"functions",difficulty:"medium",rounds:5,timePerQuestionSec:30,isOwner:!0}},ka=()=>nt&&!!rt.currentUser?.uid&&!!De,Na=(a,s,n)=>`quizBattlePresence/${a}/${s}/${n}`,hs=async(a,s)=>{if(!ka()||!s.trim()||!De)return;const n=rt.currentUser?.uid;if(!n)return;const c=ha(De,Na(a,s,n));try{await ba(c,{studentId:n,scope:a,resourceId:s,online:!0,heartbeatAt:Ie(),updatedAt:Ie()}),await Ja(c).update({online:!1,updatedAt:Ie(),disconnectedAt:Ie()})}catch(d){console.warn("Realtime presence connect failed:",d)}},bs=async(a,s)=>{if(!ka()||!s.trim()||!De)return;const n=rt.currentUser?.uid;if(!n)return;const c=ha(De,Na(a,s,n));try{await ba(c,{studentId:n,scope:a,resourceId:s,online:!1,updatedAt:Ie(),disconnectedAt:Ie()})}catch(d){console.warn("Realtime presence disconnect failed:",d)}},O=(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=ja(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},L=async(a,s,n=cs)=>{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)}},st=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},fs=()=>({mode:"online",subjectId:"gen-math",topicId:"",difficulty:"medium",rounds:5,timePerQuestionSec:30,queueType:"public_matchmaking",botDifficulty:"medium",adaptiveBot:!1}),gs=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},Be=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}),ws=async a=>{try{const s=Za(tt,"studentBattleStats",a),n=await Ka(s),c=at()?Qe(a).stats:null;if(!n.exists())return c&&c.matchesPlayed>0?c:Be(a);const d=n.data(),l={...Be(a),...d,userId:a,updatedAt:st(d.updatedAt)};return c&&c.matchesPlayed>l.matchesPlayed?c:l}catch(s){if(console.error("Error loading battle stats:",s),at()){const n=Qe(a).stats;if(n.matchesPlayed>0)return n}return Be(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:st(s.createdAt),endedAt:st(s.endedAt)}),vs=async(a,s={})=>{const n=s.limitCount||25,c=at()?Qe(a).history:[],d=w=>w.filter(g=>!(s.mode&&s.mode!=="all"&&g.mode!==s.mode||s.subjectId&&g.subjectId!==s.subjectId||s.startDate&&g.endedAts.endDate)).sort((g,k)=>k.endedAt.getTime()-g.endedAt.getTime()).slice(0,n),l=w=>{if(c.length===0)return d(w);const z=new Map;return[...c,...w].forEach(g=>{z.set(g.matchId,g)}),d(Array.from(z.values()))};try{const w=[ea("studentId","==",a),pa("endedAt","desc"),zt(n)],g=(await It(Bt(Mt(tt,"quizBattleHistory"),...w))).docs.map(k=>Ft(k.id,k.data()));return l(g)}catch(w){try{const g=(await It(Bt(Mt(tt,"quizBattleHistory"),ea("studentId","==",a),zt(n)))).docs.map(k=>Ft(k.id,k.data())).sort((k,b)=>b.endedAt.getTime()-k.endedAt.getTime());return l(g)}catch(z){return console.error("Error loading battle history:",w,z),d(c)}}},js=async a=>{const s=q(Q,"quizBattleJoinQueue");try{return(await L("joining Quiz Battle matchmaking queue",s({setup:a}))).data}catch(n){if(ce(n))return ya("queued"),{success:!0,status:"queued",queueEntryId:`local-queue-${Date.now()}`};throw new Error(O("joining Quiz Battle matchmaking queue",n))}},la=async()=>{const a=q(Q,"quizBattleLeaveQueue");try{return(await L("leaving Quiz Battle matchmaking queue",a({}))).data}catch(s){if(ce(s))return ya("idle"),{success:!0,status:"idle"};throw new Error(O("leaving Quiz Battle matchmaking queue",s))}},ys=async a=>{const s=q(Q,"quizBattleCreatePrivateRoom");try{return(await L("creating Quiz Battle private room",s({setup:a}))).data}catch(n){if(ce(n))return{success:!0,room:Tt()};throw new Error(O("creating Quiz Battle private room",n))}},ks=async a=>{const s=q(Q,"quizBattleJoinPrivateRoom");try{return(await L("joining Quiz Battle private room",s({roomCode:a}),2e4)).data}catch(n){if(ce(n))return{success:!0,room:Tt(a.trim().toUpperCase()||void 0)};throw new Error(O("joining Quiz Battle private room",n))}},Ns=async a=>{const s=q(Q,"quizBattleGetPrivateRoomState");try{return(await L("loading Quiz Battle private room state",s(a),2e4)).data}catch(n){if(ce(n))return{success:!0,room:Tt(a.roomCode?.trim().toUpperCase()||void 0)};throw new Error(O("loading Quiz Battle private room state",n))}},_s=async(a={})=>{const s=q(Q,"quizBattleLeavePrivateRoom");try{return(await L("leaving Quiz Battle private room",s(a),2e4)).data}catch(n){if(ce(n))return{success:!0,status:"idle"};throw new Error(O("leaving Quiz Battle private room",n))}},ia=async()=>{const a=q(Q,"quizBattleResumeSession");try{return(await L("resuming Quiz Battle session",a({}),2e4)).data}catch(s){if(ce(s))return{success:!0,sessionType:"idle"};throw new Error(O("resuming Quiz Battle session",s))}},Ss=async(a,s)=>{if(!s.trim())return;const n=q(Q,"quizBattleHeartbeat");await hs(a,s);try{await L("sending Quiz Battle heartbeat",n({scope:a,resourceId:s}),12e3)}catch(c){if(!ce(c))throw new Error(O("sending Quiz Battle heartbeat",c))}},As=async a=>{const s=q(Q,"quizBattleCreateBotMatch");try{return(await L("starting Quiz Battle bot match",s({setup:a}))).data}catch(n){if(ce(n))return xs(a);throw new Error(O("starting Quiz Battle bot match",n))}},Cs=async a=>{const s=q(Q,"quizBattleGetGenerationAudit");return(await L("verifying Quiz Battle generation metadata",s({matchId:a}),2e4)).data},le=async a=>{const s=q(Q,"quizBattleStartMatch");try{const c=(await L("starting Quiz Battle match",s({matchId:a}),2e4)).data.match;if(c.mode==="online")try{const d=await Cs(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(O("starting Quiz Battle match",n))}},Nt=async a=>{const s=q(Q,"quizBattleGetMatchState");try{return(await L("loading Quiz Battle match state",s({matchId:a}),2e4)).data.match}catch(n){throw new Error(O("loading Quiz Battle match state",n))}},zs=async a=>{const s=q(Q,"quizBattleSubmitAnswer");try{return(await L("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(O("submitting Quiz Battle answer",n))}},Is=async a=>{const s=q(Q,"quizBattleRequestRematch");try{return(await L("creating Quiz Battle rematch",s({matchId:a}),2e4)).data}catch(n){throw new Error(O("creating Quiz Battle rematch",n))}},Bs=async(a=20)=>{try{const s=Bt(Mt(tt,"studentBattleLeaderboard"),pa("leaderboardScore","desc"),zt(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 te({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 ie({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 de({className:a,...s}){return e.jsx("h4",{"data-slot":"card-title",className:u("leading-none",a),...s})}function pe({className:a,...s}){return e.jsx("p",{"data-slot":"card-description",className:u("text-muted-foreground",a),...s})}function we({className:a,...s}){return e.jsx("div",{"data-slot":"card-content",className:u("px-6 [&:last-child]:pb-6",a),...s})}function Ms({className:a,...s}){return e.jsx(es,{"data-slot":"tabs",className:u("flex flex-col gap-2",a),...s})}function ze({className:a,...s}){return e.jsx(ts,{"data-slot":"tabs-content",className:u("flex-1 outline-none",a),...s})}const _a=Et.memo(({playerRoundStreak:a,playerVisualMultiplier:s,liveXpEarned:n,activeMatch:c,subjects:d,battleSoundEnabled:l,onToggleSound:w,isFullscreen:z,onToggleFullscreen:g,isDesignPauseAvailable:k,onTogglePause:b})=>e.jsxs("header",{className:"flex items-center justify-between shrink-0 h-16 relative gap-4",children:[e.jsx("div",{className:"flex items-center min-w-0",children:e.jsxs("div",{className:"flex items-center gap-3 md:gap-4 px-4 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.5 text-amber-400 font-bold text-sm shrink-0",children:[e.jsx(Va,{className:"w-4 h-4"})," ",a]}),e.jsx("div",{className:"w-px h-4 bg-white/10 shrink-0"}),e.jsxs("div",{className:"flex items-center gap-1.5 text-violet-300 font-bold text-sm shrink-0",children:[e.jsx(Ct,{className:"w-4 h-4"})," ",s.toFixed(2),"x"]}),e.jsx("div",{className:"w-px 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-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-sm leading-none tabular-nums",children:[n," pts"]}),e.jsx("span",{className:"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-3",children:[e.jsx(A,{variant:"outline",size:"icon",className:"h-12 w-12 rounded-full border-white/20 bg-black/20 hover:bg-white/10 text-white",onClick:w,children:l?e.jsx(fa,{className:"h-5 w-5"}):e.jsx(ga,{className:"h-5 w-5"})}),e.jsx(A,{variant:"outline",size:"icon",className:"h-12 w-12 rounded-full border-white/20 bg-black/20 hover:bg-white/10 text-white",onClick:g,children:z?e.jsx(ss,{className:"h-5 w-5"}):e.jsx(rs,{className:"h-5 w-5"})}),e.jsx(A,{variant:"outline",size:"icon",className:u("h-12 w-12 rounded-full border-white/20 text-white",k?"bg-black/20 hover:bg-white/10":"bg-black/10 opacity-50 cursor-not-allowed"),onClick:b,disabled:!k,children:e.jsx(Wa,{className:"h-5 w-5"})})]})]}));_a.displayName="BattleHeader";const Sa=Et.memo(({studentProfile:a,activeMatch:s,scorePulseTarget:n,quizBattleAvatar:c})=>e.jsxs("div",{className:"absolute bottom-0 left-0 right-0 w-full xl:max-w-[1400px] mx-auto px-4 md:px-8 shrink-0 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-3 sm:gap-6 relative pointer-events-auto",children:[e.jsx("div",{className:"relative w-28 h-28 md:w-40 md:h-40 rounded-t-[40px] flex items-end",children:e.jsx(ns,{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-2xl px-4 py-3 md:px-5 shadow-[0_8px_30px_rgba(0,0,0,0.5)] flex items-center gap-3 md:gap-4 mb-4 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-base md:text-lg truncate tracking-wide",children:a?.name||"Player"}),e.jsxs("span",{className:"text-xs md:text-sm text-white/50 font-bold uppercase tracking-wider",children:["Level ",a?.level||1]})]}),e.jsx("div",{className:"h-10 w-px bg-white/20"}),e.jsxs("div",{className:"flex flex-col items-center justify-center shrink-0 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-2xl md:text-3xl font-black text-white leading-none",children:s.scoreFor}),e.jsx("span",{className:"text-[9px] md:text-[10px] text-emerald-400 font-bold uppercase tracking-widest mt-1 leading-none",children:"Score"})]})]})]}),e.jsxs("div",{className:"flex items-end gap-3 sm:gap-6 relative flex-row-reverse pointer-events-auto",children:[e.jsx("div",{className:"relative w-28 h-28 md:w-40 md:h-40 bg-[#1a2030] rounded-t-[40px] flex items-end justify-center border-t-4 border-slate-700/50 shadow-inner",children:s.mode==="bot"?e.jsx(Pe,{className:"h-16 w-16 md:h-20 md:w-20 text-rose-400 mb-6 drop-shadow-xl",strokeWidth:1.5}):e.jsx(ve,{className:"h-16 w-16 md:h-20 md:w-20 text-slate-500 mb-6 drop-shadow-xl",strokeWidth:1.5})}),e.jsxs("div",{className:"bg-black/40 backdrop-blur-xl border border-white/20 rounded-2xl px-4 py-3 md:px-5 shadow-[0_8px_30px_rgba(0,0,0,0.5)] flex items-center gap-3 md:gap-4 mb-4 flex-row-reverse text-right 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-base md:text-lg truncate tracking-wide",children:s.opponentName||"Anonymous"}),e.jsx("span",{className:"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-10 w-px bg-white/20"}),e.jsxs("div",{className:"flex flex-col items-center justify-center shrink-0 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-2xl md:text-3xl font-black text-white leading-none",children:s.scoreAgainst}),e.jsx("span",{className:"text-[9px] md:text-[10px] text-rose-400 font-bold uppercase tracking-widest mt-1 leading-none",children:"Score"})]})]})]})]}));Sa.displayName="BattleFooter";const Aa=Et.memo(({activeMatch:a,roundSecondsLeft:s,lastRoundResult:n,selectedOptionIndex:c,roundLocked:d,answerSubmitting:l,designPauseActive:w,onOptionSelect:z,floatingMomentum:g,lastRoundMomentumDelta:k,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(Ke,{children:g&&g.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",g.tone==="positive"?"border-emerald-300/70 bg-emerald-500/20 text-emerald-100":g.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:g.label},g.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,U=l||d,S=!!n&&n.roundNumber===a.currentRound,E=S&&n.correctOptionIndex===m;let Y=-1;if(S)if(a.mode==="bot")if(n.botCorrect)Y=n.correctOptionIndex;else{const V=[0,1,2,3].filter(C=>C!==n.correctOptionIndex);Y=V[n.roundNumber%V.length]}else Y=typeof n.botSelectedIndex=="number"?n.botSelectedIndex:-1;const ae=Y===m;let T="bg-[#1e2433] hover:bg-[#283042] border-[#2f384e] text-white shadow-[0_6px_0_rgba(15,20,30,0.5)]";return S?E?T="bg-emerald-500 text-emerald-950 border-emerald-400 shadow-[0_6px_0_rgba(5,150,105,1)]":v?T="bg-rose-500 text-white border-rose-400 shadow-[0_6px_0_rgba(225,29,72,1)]":T="bg-[#1e2433] opacity-40 border-[#2f384e] shadow-[0_6px_0_rgba(15,20,30,0.5)] text-white":v&&(T="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&&!U?{scale:1.02}:{},disabled:U||d||w,onClick:()=>z(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",T,v&&!S?"ring-[4px] ring-white/20 ring-offset-[4px] ring-offset-[#0B0F19]":"",s<=3&&!U&&!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:[ae&&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(Pe,{className:"w-4 h-4 md:w-5 md:h-5 text-white"}):e.jsx(ve,{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(Ke,{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(Je,{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(Ke,{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"})}),k!==null&&k>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:["+ ",k," ",e.jsx(et,{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)]})]})})})]}));Aa.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); } @@ -107,5 +102,5 @@ import{e as Et,i as x,m as y,f as tt,aE as De,F as rt,aF as Q,O as Va,y as Ct,M .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; } -`,Es=300*1e3,Rs=({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((r,n)=>({id:n,left:`${Math.random()*100}%`,duration:.6+Math.random()*.4,delay:Math.random()*.4})),[a]).map(r=>e.jsx(y.div,{className:"absolute w-0.5 h-16 bg-blue-300/40 rounded-full e-left-top",style:{"--left":r.left,"--top":"-10%"},animate:{y:[0,a*1.2]},transition:{duration:r.duration,ease:"linear",delay:r.delay}},r.id))}),Ts=({viewportHeight:a,viewportWidth:r})=>{const n=i.useMemo(()=>[...Array(30)].map((c,d)=>({id:d,xShift:(Math.random()-.5)*r*.8,yShift:(Math.random()-.5)*a*.8,scale:Math.random()*1.5+.5,duration:2+Math.random()*1.5,delay:Math.random()*.35})),[a,r]);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))})},ca=({value:a,label:r,delay:n=0,icon:c})=>{const[d,l]=i.useState(0);return i.useEffect(()=>{if(a<=0)return;const w=1e3,z=30,g=Math.abs(Math.floor(w/z));let k=0;const b=setTimeout(()=>{const j=setInterval(()=>{k+=Math.max(1,Math.floor(a/z)),k>=a?(l(a),clearInterval(j)):l(k)},g);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,r]}),e.jsxs("div",{className:"text-2xl font-black text-amber-400 tabular-nums",children:["+",d]})]})},O="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)]",Ps=a=>a<=0?"--":`${(a/1e3).toFixed(2)}s`,Ds=a=>a==="win"?"Win":a==="loss"?"Loss":"Draw",Ze=(a,r,n)=>Math.max(r,Math.min(n,a)),ua=a=>{const r=Math.floor(a/60),n=a%60;return`${r}:${String(n).padStart(2,"0")}`},Qs=a=>{const r=a.trim().split(/\s+/).filter(Boolean).slice(0,2);return r.length===0?"ST":r.map(n=>n[0]?.toUpperCase()||"").join("")},ma=(a,r)=>a?a.eventType==="round_started"?`Round ${a.roundNumber} started.`:a.eventType==="answer_locked"?a.lockedByStudentId&&r&&a.lockedByStudentId===r?`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 xa=()=>{if(typeof window>"u")return null;if(!At){const a=window.AudioContext||window.webkitAudioContext;a&&(At=new a)}return At},xr=()=>{const{userProfile:a,userRole:r}=Ua(),n=a,[c,d]=i.useState("hub"),[l,w]=i.useState(gs),[z,g]=i.useState([]),[k,b]=i.useState({status:"idle"}),[j,h]=i.useState(!1),[u,v]=i.useState(null),[U,S]=i.useState(""),[E,Y]=i.useState(null),[ae,T]=i.useState(0),[V,C]=i.useState(null),[ee,Dt]=i.useState(()=>typeof window>"u"?!0:window.localStorage.getItem("quiz_battle_sound_enabled")!=="0"),[he,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)?Ze(t,0,1):.7}),[Qt,I]=i.useState("connected"),[je,za]=i.useState("all"),[qt,ot]=i.useState(!0),[se,lt]=i.useState(null),[it,dt]=i.useState([]),[Ia,Lt]=i.useState(!1),[$t,Ma]=i.useState([]),[qe,Ba]=i.useState("alias"),[ct,Fa]=i.useState(!1),[s,_]=i.useState(null),[ye,X]=i.useState(null),[G,Be]=i.useState(!1),[P,Fe]=i.useState(0),[Z,K]=i.useState(!1),[B,ut]=i.useState(!1),[Ea,Ra]=i.useState(!1),[mt,Ta]=i.useState(_t),[M,re]=i.useState(null),[Pa,xt]=i.useState(!1),[Le,pt]=i.useState(null),[Da,ht]=i.useState(null),[Qa,$e]=i.useState(null),Ot=i.useRef(""),bt=i.useRef(null),ke=i.useRef(null),ue=i.useRef(0),Ht=i.useRef(""),Ee=i.useRef(0),ft=i.useRef(0),Oe=i.useRef(null),Re=i.useRef(null),He=i.useRef(-1),gt=!1,me=i.useMemo(()=>{const t=Ga(n?.grade);return ea.filter(o=>t.includes(o.id))},[n?.grade]),qa=i.useMemo(()=>(me.find(o=>o.id===l.subjectId)?.modules||[]).map(o=>({value:o.id,label:o.title})),[me,l.subjectId]),$=i.useMemo(()=>{const t=s?.roundResults||[];let o=0;return t.forEach(p=>{o=p.studentCorrect?o+1:0}),o},[s?.roundResults]),La=i.useMemo(()=>{const t=Math.max(0,$-1)*.12;return Number((1+Math.min(.72,t)).toFixed(2))},[$]),$a=i.useMemo(()=>{if(!s)return 0;if(s.status==="completed")return s.xpEarned||0;const t=s.roundResults||[];let o=0,p=0;for(const m of t)if(m.studentCorrect){o++;const N=o>=2?Math.min(25,(o-1)*5):0;p+=10+N}else o=0;return p},[s?.status,s?.xpEarned,s?.roundResults]),Vt=i.useMemo(()=>{const t=s?.roundResults||[];let o=0;return t.forEach(p=>{o=p.botCorrect?o+1:0}),o},[s?.roundResults]);i.useMemo(()=>{const t=Math.max(0,Vt-1)*.1;return Number((1+Math.min(.5,t)).toFixed(2))},[Vt]),i.useMemo(()=>$>=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)]"}:$>=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)]"}:M?.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)]"},[M?.studentCorrect,$]);const xe=i.useMemo(()=>{if(!M)return null;const t=M.studentCorrect?12:-8,o=M.studentCorrect&&!M.botCorrect?6:0,p=M.studentCorrect?Math.max(0,($-1)*2):0;return t+o+p},[M,$]),D=i.useCallback(t=>{if(!(!ee||he<=0||typeof window>"u"))try{const o=xa();if(!o)return;o.state==="suspended"&&o.resume().catch(()=>{});const m={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],N=o.currentTime,R=.07,f=Ze(m.volume*he,.004,.08);m.notes.forEach((F,oe)=>{const fe=o.createOscillator(),Te=o.createGain(),Ne=N+oe*R;fe.type=m.type,fe.frequency.setValueAtTime(F,Ne),Te.gain.setValueAtTime(1e-4,Ne),Te.gain.exponentialRampToValueAtTime(f,Ne+.012),Te.gain.exponentialRampToValueAtTime(1e-4,Ne+m.duration),fe.connect(Te),Te.connect(o.destination),fe.start(Ne),fe.stop(Ne+m.duration+.02)})}catch(o){console.warn("Battle tone playback skipped or blocked:",o)}},[ee,he]),Wt=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."})}},[]),Ut=i.useCallback(()=>{},[gt]),Yt=i.useCallback(t=>{h(!1),v(null),_(null),T(0),C(null),b({status:"error",message:t}),d("setup")},[]),ne=i.useCallback(async()=>{if(!n?.uid)return null;const[t,o]=await Promise.all([vs(n.uid),js(n.uid,{mode:je,limitCount:8})]);return{stats:t,history:o}},[je,n?.uid]);i.useEffect(()=>{if(me.length===0)return;const o=me.some(N=>N.id===l.subjectId)?l.subjectId:me[0].id,p=me.find(N=>N.id===o),m=p?.modules?.[0]?.id||"";w(N=>{const R=p?.modules?.some(f=>f.id===N.topicId)?N.topicId:m;return N.subjectId===o&&N.topicId===R?N:{...N,subjectId:o,topicId:R}})},[me,l.subjectId]),i.useEffect(()=>{if(!n?.uid){lt(null),dt([]),ot(!1);return}let t=!0;return ot(!0),(async()=>{const p=await ne();t&&(p&&(lt(p.stats),dt(p.history)),ot(!1))})(),()=>{t=!1}},[ne,n?.uid]);const Ve=i.useMemo(()=>je==="all"?it:it.filter(t=>t.mode===je),[it,je]),Xt=i.useMemo(()=>$t.map((t,o)=>{const p=t.rank||o+1,m=t.userId===n?.uid,N=`Student-${t.userId.slice(-4).toUpperCase()}`,R=qe==="full"?t.displayName:qe==="initials"?Qs(t.displayName):N,f=Math.floor(t.leaderboardScore/25)*25,F=ct||m?`${t.leaderboardScore} pts`:`${f}-${f+24} pts`;return{...t,rank:p,isSelf:m,displayName:R,scoreLabel:F}}),[$t,qe,ct,n?.uid]);i.useEffect(()=>{if(c!=="leaderboard"&&c!=="hub")return;let t=!0;return Lt(!0),(async()=>{const p=await Bs(20);t&&(Ma(p),Lt(!1))})(),()=>{t=!1}},[c]);const We=i.useCallback(async()=>{if(n?.uid)try{const t=await da();if(t.sessionType==="match"&&t.match){let o=t.match;if(t.match.mode==="bot"&&t.match.status==="ready")try{o=await de(t.match.matchId),Ee.current=0}catch(p){const m=p;h(!1),v(null),_(null),d("setup"),I(typeof window<"u"&&window.navigator.onLine?"connected":"disconnected"),b({status:"error",message:m?.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&&We()},[n?.uid,We]),i.useEffect(()=>{typeof window>"u"||window.localStorage.setItem("quiz_battle_sound_enabled",ee?"1":"0")},[ee]),i.useEffect(()=>{typeof window>"u"||window.localStorage.setItem("quiz_battle_sound_volume",he.toFixed(2))},[he]),i.useEffect(()=>{if(typeof window>"u")return;const t=()=>{const o=window.innerWidth,p=window.innerHeight;Ta({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=()=>{Ra(!!document.fullscreenElement)};return t(),document.addEventListener("fullscreenchange",t),()=>{document.removeEventListener("fullscreenchange",t)}},[]),i.useEffect(()=>{const t=V!==null;if(!(j||u&&(u.status==="waiting"||u.status==="ready")||t)){T(0);return}const o=()=>{if(!V){T(m=>m+1);return}T(Math.max(0,Math.ceil((V-Date.now())/1e3)))};o();const p=window.setInterval(o,1e3);return()=>{window.clearInterval(p)}},[j,u?.status,u?.roomId,V]),i.useEffect(()=>{if(!V)return;const t=window.setInterval(()=>{V-Date.now()<=0&&(window.clearInterval(t),(async()=>{try{(j||!u)&&await ia()}catch{}finally{Yt("Public matchmaking timed out after 5 minutes. Please start again.")}})())},1e3);return()=>{window.clearInterval(t)}},[u,Yt,j,V]),i.useEffect(()=>{if(typeof window>"u")return;I(window.navigator.onLine?"connected":"disconnected");const t=()=>{I("reconnecting"),We()},o=()=>{I("disconnected")};return window.addEventListener("online",t),window.addEventListener("offline",o),()=>{window.removeEventListener("online",t),window.removeEventListener("offline",o)}},[We]),i.useEffect(()=>{const t=s?.mode==="online"&&(s.status==="ready"||s.status==="in_progress"),o=s?.mode==="bot"&&s.status==="ready",p=!!(u&&(u.status==="waiting"||u.status==="ready"));if(o||(Ee.current=0),!j&&!p&&!t&&!o||B)return;let m=!1;const N=async()=>{try{if(s?.mode==="bot"&&s.status==="ready"){const f=await de(s.matchId);if(m)return;_(f),I("connected"),C(f.expiresAtMs||null),Ee.current=0,f.status==="in_progress"&&b({status:"queued",message:"Practice bot match started."});return}if(s?.mode==="online"){if(s.status==="ready"){const oe=await de(s.matchId);if(m)return;_(oe),I("connected"),C(oe.expiresAtMs||null),oe.status==="in_progress"&&b({status:"queued",message:"Match started. Round timer is live."});return}const f=await Nt(s.matchId);if(m)return;const F=f.roundResults.filter(oe=>oe.roundNumber>He.current).sort((oe,fe)=>oe.roundNumber-fe.roundNumber)[0];F?(He.current=F.roundNumber,re(F),pt(f)):(_(f),f.status==="completed"&&(h(!1),v(null),C(null)),f.status==="cancelled"&&s.status==="in_progress"&&(xt(!0),K(!1))),I("connected");return}if(u?.roomId){const f=await _s({roomId:u.roomId});if(m)return;if(v(f.room),f.match){const F=await de(f.match.matchId);if(m)return;_(F),v(f.room),h(!1),C(F.expiresAtMs||null),d("battle"),I("connected"),b({status:"queued",message:F.status==="ready"?"Opponent connected. Waiting for synchronized start...":"Private room match started."})}return}if(j){const f=await da();if(m)return;if(f.sessionType==="match"&&f.match){const F=await de(f.match.matchId);if(m)return;_(F),v(f.room||null),h(!1),C(F.expiresAtMs||null),d("battle"),I("connected"),b({status:"queued",message:"Opponent found. Preparing synchronized start..."});return}if(f.sessionType==="room"&&f.room){h(!1),v(f.room),C(null),I("connected");return}I("connected")}}catch(f){if(!m){if(console.warn("Quiz Battle sync poll failed:",f),s?.mode==="bot"&&s.status==="ready"&&(Ee.current+=1,Ee.current>=3)){const F=f;h(!1),v(null),_(null),d("setup"),b({status:"error",message:F?.message||"Unable to start bot battle. Please try again."}),I("disconnected");return}I("reconnecting")}}};N();const R=window.setInterval(()=>{N()},3e3);return()=>{m=!0,window.clearInterval(R)}},[s?.matchId,s?.mode,s?.status,u?.roomId,u?.status,B,j]);const be=i.useMemo(()=>s?.mode==="online"&&(s.status==="ready"||s.status==="in_progress")?{scope:"match",resourceId:s.matchId}:u&&(u.status==="waiting"||u.status==="ready")?{scope:"room",resourceId:u.roomId}:j&&n?.uid?{scope:"queue",resourceId:n.uid}:null,[s,u,j,n?.uid]);i.useEffect(()=>{if(!be)return;let t=!1;const o=async()=>{try{await As(be.scope,be.resourceId),t||I("connected")}catch(m){t||(console.warn("Quiz Battle heartbeat failed:",m),I("reconnecting"))}};o();const p=window.setInterval(()=>{o()},8e3);return()=>{t=!0,window.clearInterval(p),fs(be.scope,be.resourceId)}},[be?.scope,be?.resourceId]),i.useEffect(()=>{if(!s||s.status!=="in_progress"){K(!1),ke.current=null,ue.current=0;return}ke.current=null,ue.current=0;const t=s.roundDeadlineAtMs?Math.max(0,Math.ceil((s.roundDeadlineAtMs-Date.now())/1e3)):s.timePerQuestionSec;Fe(t),X(null),K(!1)},[s?.matchId,s?.status,s?.currentRound,s?.timePerQuestionSec]),i.useEffect(()=>{B&&(!s||s.status!=="in_progress")&&ut(!1)},[s?.matchId,s?.status,B]),i.useEffect(()=>{const t=s?.lifecycle;if(!t?.eventType)return;const o=`${t.eventType}:${t.sequence}`;Ot.current!==o&&(Ot.current=o,t.eventType==="answer_locked"?D("lock"):t.eventType==="round_result"&&D("result"))},[s?.lifecycle?.eventType,s?.lifecycle?.sequence,D]),i.useEffect(()=>{!s||s.status!=="completed"||Ht.current!==s.matchId&&(Ht.current=s.matchId,D(s.outcome==="loss"?"loss":"win"),s.outcome==="win"&&Ya(()=>import("./confetti.module-C94ZD2ww.js"),[]).then(t=>{t.default({particleCount:110,spread:78,origin:{y:.62},ticks:160})}).catch(()=>{}))},[s?.matchId,s?.status,s?.outcome,D]),i.useEffect(()=>{if(!s||s.status!=="in_progress"||Z||G||B){bt.current=null;return}P<=3&&P>0&&bt.current!==P&&(bt.current=P,D("tick"))},[s?.status,P,Z,G,B,D]),i.useEffect(()=>{if(!s||s.status!=="in_progress"){ft.current=0;return}$>ft.current&&$>=2&&D($>=4?"multiplier":"streak"),ft.current=$},[s?.matchId,s?.status,$,D]),i.useEffect(()=>{if(!s){Oe.current=null,$e(null);return}const t=Oe.current;if(!t||t.matchId!==s.matchId){Oe.current={matchId:s.matchId,scoreFor:s.scoreFor,scoreAgainst:s.scoreAgainst},$e(null);return}if(s.scoreFor!==t.scoreFor||s.scoreAgainst!==t.scoreAgainst){const o=s.scoreFor>t.scoreFor?"player":"opponent";$e(o),Re.current&&window.clearTimeout(Re.current),Re.current=window.setTimeout(()=>{$e(null)},850)}Oe.current={matchId:s.matchId,scoreFor:s.scoreFor,scoreAgainst:s.scoreAgainst}},[s?.matchId,s?.scoreAgainst,s?.scoreFor]),i.useEffect(()=>()=>{Re.current&&window.clearTimeout(Re.current)},[]),i.useEffect(()=>{if(!M?.studentCorrect||xe===null||xe<=0){ht(null);return}const t=xe>0?"positive":xe<0?"negative":"neutral";ht({id:Date.now(),label:`${xe>=0?"+":""}${xe} Momentum`,tone:t});const o=window.setTimeout(()=>{ht(null)},1400);return()=>{window.clearTimeout(o)}},[xe,M]),i.useEffect(()=>{if(M&&Le){M.studentCorrect?D("win"):D("loss");const t=window.setTimeout(()=>{_(Le),re(null),X(null),K(!1),pt(null),Le.status==="completed"&&(h(!1),v(null),ne(),He.current=-1)},1500);return()=>window.clearTimeout(t)}},[M,Le,D,ne]);const Ue=i.useCallback(async t=>{if(!s||s.status!=="in_progress"||Z||B)return;Be(!0);const o=window.setTimeout(()=>{Be(!1),b({status:"error",message:"Submission took too long. Syncing latest match state now..."}),Nt(s.matchId).then(p=>{_(p),p.status==="completed"&&(h(!1),v(null),C(null))}).catch(()=>{})},12e3);try{const p=s.roundDeadlineAtMs?Ze(s.timePerQuestionSec*1e3-Math.max(0,s.roundDeadlineAtMs-Date.now()),0,s.timePerQuestionSec*1e3):Math.max(0,(s.timePerQuestionSec-P)*1e3),m=await Is({matchId:s.matchId,roundNumber:s.currentRound,selectedOptionIndex:t,responseMs:p});ke.current=null,ue.current=0,m.roundResult?(He.current=m.roundResult.roundNumber,re(m.roundResult),pt(m.match)):(_(m.match),re(null),m.match.mode==="online"&&m.match.status==="in_progress"?(K(!0),b({status:"queued",message:"Answer locked. Waiting for opponent to finish the round..."})):X(null)),m.match.status==="completed"&&(h(!1),v(null),C(null),ne(),b({status:"queued",message:m.completion?`Match finished (${m.completion.outcome.toUpperCase()}) +${m.completion.xpEarned} XP`:"Match finished. Results saved."}))}catch(p){const N=p?.message||"Unable to submit answer right now. Please try again.";if(t===null||N.includes("Round timer elapsed")||N.includes("Expected round")||N.includes("Match is not currently active"))try{const f=await Nt(s.matchId),F=f.currentRound!==s.currentRound;if(_(f),X(null),K(!1),F||f.status==="completed"?(ke.current=null,ue.current=0):t===null&&(ue.current=Date.now()+3e3),f.status==="completed"){h(!1),v(null),C(null),ne(),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&&(ue.current=Date.now()+3e3),b({status:"error",message:N})}finally{window.clearTimeout(o),Be(!1)}},[s,B,ne,Z,P]);i.useEffect(()=>{if(!s||s.status!=="in_progress"||B||G||Z)return;const t=s.roundDeadlineAtMs?Math.max(0,Math.ceil((s.roundDeadlineAtMs-Date.now())/1e3)):P;if(s.roundDeadlineAtMs&&t!==P&&Fe(t),ye===null?t<=1:t<=0){if(ke.current===s.currentRound&&Date.now(){s.roundDeadlineAtMs?Fe(Math.max(0,Math.ceil((s.roundDeadlineAtMs-Date.now())/1e3))):Fe(m=>Math.max(0,m-1))},1e3);return()=>{window.clearTimeout(p)}},[s,G,B,Z,P,ye,Ue]);const Gt=i.useCallback(async()=>{if(!(!s||s.mode!=="bot")){Be(!0),b({status:"validating"});try{const t=await Ms(s.matchId),o=await de(t.matchId);_(o),v(null),h(!1),C(null),re(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{Be(!1)}}},[s]);if(r!=="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(te,{className:x(O,"max-w-2xl"),children:e.jsxs(le,{children:[e.jsx(ie,{children:"Quiz Battle is student-only"}),e.jsx(pe,{className:"text-muted-foreground dark:text-[#aab3c7]",children:"Your account role does not have access to this module."})]})})})]});const Zt=t=>{g([]),b({status:"idle"}),ut(!1),h(!1),v(null),S(""),_(null),re(null),X(null),K(!1),C(null),w(o=>({...o,mode:t,queueType:t==="online"?o.queueType:"public_matchmaking"})),T(0),d("setup")},Kt=async()=>{b({status:"validating"});try{u?.roomId?await Ss({roomId:u.roomId}):await ia(),h(!1),v(null),_(t=>!t||t.mode!=="online"?t:t.status==="ready"||t.status==="cancelled"?null:t),S(""),T(0),C(null),b({status:"queued",message:u?.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."})}},Oa=async()=>{b({status:"validating"});const t=ws(l);if(t.length>0){g(t),b({status:"error",message:"Fix the highlighted setup fields before starting."});return}g([]);try{if(l.mode==="online"){if(l.queueType==="private_room"){const N=U.trim().toUpperCase(),R=N?await Ns(N):await ks(l);if(h(!1),v(R.room),S(""),C(R.match?.expiresAtMs||null),R.match){const f=await de(R.match.matchId);_(f),re(null),X(null),K(!1),d("battle"),C(f.expiresAtMs||null),b({status:"queued",message:f.status==="ready"?`Room ${R.room.roomCode} linked. Waiting for synchronized start...`:"Private room match started."});return}_(null),C(null),b({status:"queued",message:N?"Joined private room. Waiting for opponent...":"Private room created. Share code:"});return}const m=await ys(l);if(m.status==="matched"&&m.matchId){const N=await de(m.matchId);h(!1),v(null),_(N),re(null),X(null),K(!1),d("battle"),C(N.expiresAtMs||null),b({status:"queued",message:"Opponent found. Preparing synchronized start..."});return}h(!0),v(null),_(null),C(m.expiresAtMs||Date.now()+Es),T(0),b({status:"queued",message:"Joined matchmaking queue. Waiting for an opponent..."});return}const o=await Cs(l),p=await de(o.matchId);h(!1),v(null),_(p),re(null),X(null),K(!1),Fe(p.timePerQuestionSec),C(null),d("battle"),b({status:"queued",message:`Bot match ${o.matchId.slice(0,8)} live (${o.botDifficulty}).`}),ne().then(m=>{m&&(lt(m.stats),dt(m.history))})}catch(o){h(!1),b({status:"error",message:o?.message||"Unable to start battle. Please try again."})}},W=t=>z.find(o=>o.field===t)?.message;se?.winRate;const Jt=!!(l.mode==="online"&&u&&(u.status==="waiting"||u.status==="ready")&&(!s||s.status!=="completed")),Ha=!!(j||u&&(u.status==="waiting"||u.status==="ready")&&(!s||s.status==="ready"||s.status==="cancelled"));return s&&(s.status==="in_progress"||s.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:[s.status==="completed"&&s.outcome==="loss"&&e.jsx(Rs,{viewportHeight:mt.height}),s.status==="completed"&&s.outcome==="draw"&&e.jsx(Ts,{viewportHeight:mt.height,viewportWidth:mt.width}),e.jsx("div",{className:"absolute inset-0 z-0 opacity-40",children:e.jsx(oa,{children:e.jsx("div",{className:"h-full w-full"})})}),e.jsx(Ke,{children:Pa&&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:s.mode==="bot"?e.jsx(Pe,{className:"h-16 w-16 text-rose-400 mb-2",strokeWidth:1.5}):e.jsx(ve,{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:s.opponentName||"Your opponent"})," left the match. You win! 🏆"]})]}),e.jsxs("div",{className:"flex flex-col gap-3 w-full",children:[e.jsx(A,{size:"lg",className:"w-full h-12 bg-emerald-500 hover:bg-emerald-400 text-white font-black rounded-xl",onClick:()=>{xt(!1),_(null),v(null),h(!1),b({status:"idle"}),d("hub"),ne()},children:"🏆 Claim Victory"}),e.jsx(A,{size:"lg",variant:"outline",className:"w-full h-12 border-white/20 text-white/70 hover:bg-white/10 rounded-xl",onClick:()=>{xt(!1),_(null),v(null),h(!1),b({status:"idle"}),d("hub")},children:"Back to Arena"})]})]})})}),B&&e.jsx("div",{className:"absolute inset-0 z-[110] bg-black/60 backdrop-blur-md flex items-center justify-center",children:e.jsxs(te,{className:"w-full max-w-sm border-border/50 bg-[#181d27] shadow-[0_20px_50px_rgba(0,0,0,0.5)]",children:[e.jsxs(le,{className:"text-center",children:[e.jsx(ie,{className:"text-3xl font-black text-white",children:"PAUSED"}),e.jsx(pe,{className:"text-base text-muted-foreground mt-2",children:s.mode==="online"?"Online match - timer continues in the background! Hurry!":"Bot match - round timer frozen."})]}),e.jsxs(ge,{className:"flex flex-col gap-3",children:[e.jsx(A,{variant:"default",size:"lg",className:"w-full text-lg h-12",onClick:Ut,children:"Resume Match"}),e.jsx(A,{variant:"outline",size:"lg",className:"w-full text-lg h-12 border-rose-500/20 text-rose-500 hover:bg-rose-500/10",onClick:()=>{ut(!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(_a,{playerRoundStreak:$,playerVisualMultiplier:La,liveXpEarned:$a,activeMatch:s,subjects:ea,battleSoundEnabled:ee,onToggleSound:()=>Dt(t=>!t),isFullscreen:Ea,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:gt,onTogglePause:Ut}),s.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/s.timePerQuestionSec*100)}%`,backgroundColor:P>Math.floor(s.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:s.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:x("text-3xl font-black uppercase tracking-widest drop-shadow-md mb-2",s.outcome==="win"?"text-emerald-400":s.outcome==="loss"?"text-rose-400":"text-amber-400"),children:s.outcome==="win"?"VICTORY!":s.outcome==="loss"?"DEFEAT":"DRAW MATCH"}),e.jsxs("p",{className:"text-white/80 font-bold text-sm mb-4 uppercase tracking-widest",children:["Final Score: ",s.scoreFor," - ",s.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=s.roundResults||[];let o=0,p=0,m=0;for(const N of t)if(N.studentCorrect){o++;const R=o>=2?Math.min(15,(o-1)*5):0;p+=10,m+=R}else o=0;return e.jsxs(e.Fragment,{children:[e.jsx(ca,{value:p,label:"Correct Answers",delay:300,icon:e.jsx(kt,{className:"h-3 w-3 text-emerald-400"})}),e.jsx(ca,{value:m,label:"Streak Bonus",delay:900,icon:e.jsx(et,{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+m," 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:s.outcome==="win"?"🏆 Victory Reward":s.outcome==="draw"?"🤝 Draw Reward":"📘 Participation Reward"}),e.jsxs("span",{className:"text-2xl font-black text-amber-400 drop-shadow-md",children:["+",s.xpEarned||(s.outcome==="win"?80:s.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(A,{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"}),s.mode==="bot"&&e.jsx(A,{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(Aa,{activeMatch:s,roundSecondsLeft:P,lastRoundResult:M,selectedOptionIndex:ye,roundLocked:Z,answerSubmitting:G,designPauseActive:B,onOptionSelect:t=>{M&&M.roundNumber===s.currentRound||G||Z||(xa()?.resume().catch(()=>{}),D("lock"),X(t),Ue(t))},floatingMomentum:Da,lastRoundMomentumDelta:xe,studentProfile:n,quizBattleAvatar:yt})}),e.jsx(Sa,{studentProfile:n,activeMatch:s,scorePulseTarget:Qa,quizBattleAvatar:yt})]})]})]}):e.jsxs(e.Fragment,{children:[e.jsx("style",{children:St}),e.jsx(oa,{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(Fs,{value:c,onValueChange:t=>d(t),children:[e.jsx(ze,{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:Qt==="connected"?"text-emerald-400":"text-amber-400",children:Qt})]})]})}),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:yt,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-1 sm:grid-cols-2 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-[205px] 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-[70px] 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-[120px] 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-[-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-[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-5 py-3 sm:py-4 text-center bg-[#662AA8]",children:e.jsx("p",{className:"text-[13px] font-bold text-white leading-[1.45] 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-[205px] 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-[70px] 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-[125px] 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-[45px] 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-[45px] 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-5 py-3 sm:py-4 text-center bg-[#127DA6]",children:e.jsx("p",{className:"text-[13px] font-bold text-white leading-[1.45] 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 h-[155px] sm:h-[165px] cursor-pointer group flex items-end justify-center overflow-visible mt-1 mb-2 scale-[0.75] origin-bottom sm:scale-[0.80] lg:scale-[0.85] lg:origin-center",children:e.jsxs(y.div,{className:"relative w-full h-full flex flex-col items-center justify-end",whileHover:{scale:1.03},whileTap:{scale:.98},children:[e.jsxs("div",{className:"absolute top-[1px] sm:-top-[30px] w-full flex justify-center items-end px-2 z-0",children:[e.jsx(vt,{strokeWidth:0,fill:"currentColor",className:"w-[35px] h-[35px] text-[#fde047] -rotate-[15deg] -mr-3 mb-1 z-0 drop-shadow-[0_0_15px_rgba(253,224,71,0.6)]"}),e.jsx("div",{className:"z-10 relative animate-star-float",children:e.jsx(vt,{strokeWidth:0,fill:"currentColor",className:"w-[60px] h-[60px] text-[#fcd34d] drop-shadow-[0_0_25px_rgba(252,211,77,0.9)]"})}),e.jsx(vt,{strokeWidth:0,fill:"currentColor",className:"w-[35px] h-[35px] text-[#fde047] rotate-[15deg] -ml-3 mb-1 z-0 drop-shadow-[0_0_15px_rgba(253,224,71,0.6)]"})]}),e.jsx("div",{className:`absolute inset-x-0 bottom-[40px] top-0 z-10 flex flex-col items-center justify-end - filter drop-shadow-[0px_3px_0px_white] drop-shadow-[0px_-3px_0px_white] drop-shadow-[3px_0px_0px_white] drop-shadow-[-3px_0px_0px_white] drop-shadow-[2px_2px_0px_white] drop-shadow-[-2px_-2px_0px_white] drop-shadow-[2px_-2px_0px_white] drop-shadow-[-2px_2px_0px_white]`,children:e.jsxs("div",{className:"flex items-end justify-center z-20 relative px-4",children:[e.jsxs("div",{className:"flex flex-col items-center w-[65px] relative",children:[e.jsx("div",{className:"w-full h-[14px] bg-[#d24b4b] rounded-[2px] relative z-10 -mb-[1px]"}),e.jsxs("div",{className:"w-[85%] h-[50px] bg-[#fe5c5c] rounded-b-[2px] flex flex-col justify-center items-center gap-1.5 pb-1.5",children:[e.jsx("div",{className:"w-6 h-1.5 bg-white rounded-full opacity-95"}),e.jsx("div",{className:"w-6 h-1.5 bg-white rounded-full opacity-95"})]})]}),e.jsxs("div",{className:"flex flex-col items-center w-[75px] -mx-[4px] z-20 relative",children:[e.jsx("div",{className:"w-full h-[18px] bg-[#f2812d] rounded-[2px] relative z-10 -mb-[1px]"}),e.jsxs("div",{className:"w-[85%] h-[75px] bg-[#fa9746] rounded-b-[2px] flex flex-col justify-start items-center pt-4 gap-1.5",children:[e.jsx("div",{className:"w-9 h-1.5 bg-white rounded-full opacity-95"}),e.jsx("div",{className:"w-9 h-1.5 bg-white rounded-full opacity-95"})]})]}),e.jsxs("div",{className:"flex flex-col items-center w-[65px] relative",children:[e.jsx("div",{className:"w-full h-[14px] bg-[#d24b4b] rounded-[2px] relative z-10 -mb-[1px]"}),e.jsxs("div",{className:"w-[85%] h-[50px] bg-[#fe5c5c] rounded-b-[2px] flex flex-col justify-center items-center gap-1.5 pb-1.5",children:[e.jsx("div",{className:"w-6 h-1.5 bg-white rounded-full opacity-95"}),e.jsx("div",{className:"w-6 h-1.5 bg-white rounded-full opacity-95"})]})]})]})}),e.jsx("div",{className:"absolute bottom-2 w-[110%] max-w-[280px] z-30 drop-shadow-2xl",children:e.jsxs("div",{className:"relative w-full h-[52px] flex justify-center items-center",children:[e.jsx("div",{className:"absolute -left-1 top-2 w-[55px] h-[40px] bg-[#8b0d0d] z-0 clip-poly-left"}),e.jsx("div",{className:"absolute -right-1 top-2 w-[55px] h-[40px] bg-[#8b0d0d] z-0 clip-poly-right"}),e.jsxs("div",{className:"absolute inset-x-6 top-0 bottom-0 bg-[#b61515] shadow-[inset_0_2px_4px_rgba(255,255,255,0.1),_inset_0_-4px_4px_rgba(0,0,0,0.2)] z-10 flex flex-col items-center justify-center",children:[e.jsx("h3",{className:"text-lg sm:text-xl font-black text-white tracking-widest leading-none drop-shadow-md font-nunito",children:"Hall of Fame"}),e.jsx("span",{className:"text-[9px] sm:text-[10px] font-bold text-white/90 tracking-widest mt-0.5",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-end justify-between px-5 pt-4 pb-2 relative z-10",children:[e.jsx("h3",{className:"text-[18px] font-black text-white tracking-wide leading-none drop-shadow-md font-nunito",children:"My Stats"}),e.jsx(A,{variant:"link",className:"text-white/80 hover:text-white p-0 h-auto font-semibold text-[13px] tracking-wide",onClick:()=>d("stats"),children:"View Stats >"})]}),e.jsxs("div",{className:"relative z-10 w-full overflow-hidden pb-4",children:[e.jsx("div",{className:"absolute left-0 top-0 bottom-0 w-6 bg-gradient-to-r from-[#3b3a82] to-transparent z-20 pointer-events-none dark:from-[#2b2b5f]"}),e.jsx("div",{className:"absolute right-0 top-0 bottom-0 w-6 bg-gradient-to-l from-[#3b3a82] to-transparent z-20 pointer-events-none dark:from-[#2b2b5f]"}),e.jsx("div",{className:"flex w-max pl-3 animate-marquee",children:[0,1].map(t=>e.jsxs("div",{className:"flex gap-2.5 pr-2.5",children:[e.jsxs("div",{className:"flex-none w-[60px] sm:w-[65px] lg:w-[70px] xl:w-[75px] aspect-square rounded-[12px] bg-[#f0eaff] p-1.5 flex flex-col justify-between relative overflow-hidden group shadow-sm dark:bg-[#d6ccf5]",children:[e.jsx(jt,{className:"absolute -bottom-1 -right-2 w-6 h-6 sm:w-8 sm:h-8 text-[#a06aec]/10 -rotate-12 transition-transform group-hover:scale-110"}),e.jsx("span",{className:"text-[12px] drop-shadow-sm leading-none",children:"🏆"}),e.jsxs("div",{className:"relative z-10 space-y-[1px]",children:[e.jsxs("h4",{className:"text-[12px] sm:text-[14px] lg:text-[16px] font-black text-[#8f5ae2] leading-none tracking-tight",children:[Math.round(se?.winRate||0)," %"]}),e.jsx("p",{className:"text-[6px] lg:text-[7px] font-extrabold text-[#baa4df] uppercase tracking-wider leading-none",children:"Win Rate"})]})]}),e.jsxs("div",{className:"flex-none w-[60px] sm:w-[65px] lg:w-[70px] xl:w-[75px] aspect-square rounded-[12px] bg-[#e1f5f7] p-1.5 flex flex-col justify-between relative overflow-hidden group shadow-sm dark:bg-[#b0e6eb]",children:[e.jsx(Ct,{className:"absolute -bottom-1 -right-2 w-6 h-6 sm:w-8 sm:h-8 text-[#35a8bc]/10 rotate-12 transition-transform group-hover:scale-110"}),e.jsx("span",{className:"text-[12px] drop-shadow-sm leading-none",children:"🎯"}),e.jsxs("div",{className:"relative z-10 space-y-[1px]",children:[e.jsx("h4",{className:"text-[12px] sm:text-[14px] lg:text-[16px] font-black text-[#319ab4] leading-none tracking-tight",children:se?.matchesPlayed||0}),e.jsx("p",{className:"text-[6px] lg:text-[7px] font-extrabold text-[#7eafbe] uppercase tracking-wider leading-none",children:"Matches"})]})]}),e.jsxs("div",{className:"flex-none w-[60px] sm:w-[65px] lg:w-[70px] xl:w-[75px] aspect-square rounded-[12px] bg-[#fef5e7] p-1.5 flex flex-col justify-between relative overflow-hidden group shadow-sm dark:bg-[#f6ebd2]",children:[e.jsx(ra,{className:"absolute -bottom-1 -right-2 w-6 h-6 sm:w-8 sm:h-8 text-[#e87a42]/10 -rotate-12 transition-transform group-hover:scale-110"}),e.jsx("span",{className:"text-[12px] drop-shadow-sm leading-none",children:"⏱️"}),e.jsxs("div",{className:"relative z-10 space-y-[1px]",children:[e.jsxs("h4",{className:"text-[12px] sm:text-[14px] lg:text-[16px] font-black text-[#db734b] leading-none tracking-tight",children:[se?.averageResponseMs?(se.averageResponseMs/1e3).toFixed(1):0,"s"]}),e.jsx("p",{className:"text-[6px] lg:text-[7px] font-extrabold text-[#d2a893] uppercase tracking-wider leading-none whitespace-nowrap",children:"Response"})]})]}),e.jsxs("div",{className:"flex-none w-[60px] sm:w-[65px] lg:w-[70px] xl:w-[75px] aspect-square rounded-[12px] bg-[#fdeceb] p-1.5 flex flex-col justify-between relative overflow-hidden group shadow-sm dark:bg-[#fbd3d3]",children:[e.jsx(et,{className:"absolute -bottom-1 -right-2 w-6 h-6 sm:w-8 sm:h-8 text-[#df655a]/10 rotate-12 transition-transform group-hover:scale-110"}),e.jsx("span",{className:"text-[12px] drop-shadow-sm leading-none",children:"✨"}),e.jsxs("div",{className:"relative z-10 space-y-[1px]",children:[e.jsx("h4",{className:"text-[12px] sm:text-[14px] lg:text-[16px] font-black text-[#d05c54] leading-none tracking-tight",children:n?.currentXP||0}),e.jsx("p",{className:"text-[6px] lg:text-[7px] font-extrabold text-[#dd9a9a] uppercase tracking-wider leading-none whitespace-nowrap",children:"Total XP"})]})]})]},t))})]})]}),e.jsxs(te,{className:x(O,"rounded-[18px] flex flex-col min-h-[200px]"),children:[e.jsxs(le,{className:"pb-0 pt-3 px-4 flex flex-row items-center justify-between",children:[e.jsxs(ie,{className:"text-[14px] font-black flex items-center gap-2 text-[#2e2b5e] dark:text-[#f5f7fb]",children:[e.jsx(na,{className:"h-[16px] w-[16px] text-[#2e2b5e] dark:text-[#9e8fff]"})," Match History"]}),e.jsx(A,{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(ge,{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(we,{className:"h-10 w-full rounded-xl bg-muted dark:bg-[#2a3143]"}),e.jsx(we,{className:"h-10 w-full rounded-xl bg-muted dark:bg-[#2a3143]"})]}):Ve.length===0?e.jsx("p",{className:"text-xs text-center text-muted-foreground dark:text-[#a8b2c9] py-2",children:"No battle history yet."}):Ve.slice(0,3).map(t=>{const o=t.outcome==="win",p=t.outcome==="loss",m=t.opponentName.split(" ").map(N=>N[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:x("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:x("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:m}),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:x("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(ze,{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:x(O,"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:x("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:x("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:x("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(A,{variant:"ghost",onClick:()=>d("hub"),className:x("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(Ye,{className:x("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:x("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:x("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(ve,{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(Pe,{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:x("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:x("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(_e,{value:l.subjectId,onValueChange:t=>w(o=>({...o,subjectId:t})),children:[e.jsx(Se,{className:x("rounded-xl h-11 border-white/20 bg-white/60 dark:bg-black/50 dark:border-white/10 transition-colors shadow-inner",l.mode==="online"?"hover:border-[#8A3FD3]/50":"hover:border-[#1FA7E1]/50",W("subjectId")&&"border-rose-400"),children:e.jsx(Ae,{placeholder:"Select category"})}),e.jsx(Ce,{className:"rounded-xl backdrop-blur-xl bg-white/90 dark:bg-[#1a1f2e]/90",children:me.map(t=>e.jsx(J,{value:t.id,className:"rounded-lg",children:t.title},t.id))})]}),W("subjectId")&&e.jsx("p",{className:"text-xs text-destructive dark:text-rose-300 ml-1",children:W("subjectId")})]}),e.jsxs("div",{className:"space-y-1.5 group",children:[e.jsx("label",{className:x("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(_e,{value:l.topicId,onValueChange:t=>w(o=>({...o,topicId:t})),children:[e.jsx(Se,{className:x("rounded-xl h-11 border-white/20 bg-white/60 dark:bg-black/50 dark:border-white/10 transition-colors shadow-inner",l.mode==="online"?"hover:border-[#8A3FD3]/50":"hover:border-[#1FA7E1]/50",W("topicId")&&"border-rose-400"),children:e.jsx(Ae,{placeholder:"Select topic group"})}),e.jsx(Ce,{className:"rounded-xl backdrop-blur-xl bg-white/90 dark:bg-[#1a1f2e]/90",children:qa.map(t=>e.jsx(J,{value:t.value,className:"rounded-lg",children:t.label},t.value))})]}),W("topicId")&&e.jsx("p",{className:"text-xs text-destructive dark:text-rose-300 ml-1",children:W("topicId")})]}),e.jsxs("div",{className:"space-y-1.5 group",children:[e.jsx("label",{className:x("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(_e,{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(Se,{className:x("rounded-xl h-11 border-white/20 bg-white/60 dark:bg-black/50 dark:border-white/10 transition-colors shadow-inner",l.mode==="online"?"hover:border-[#8A3FD3]/50":"hover:border-[#1FA7E1]/50"),children:e.jsx(Ae,{})}),e.jsxs(Ce,{className:"rounded-xl backdrop-blur-xl bg-white/90 dark:bg-[#1a1f2e]/90",children:[e.jsx(J,{value:"easy",className:"rounded-lg",children:"Easy"}),e.jsx(J,{value:"medium",className:"rounded-lg",children:"Medium"}),e.jsx(J,{value:"hard",className:"rounded-lg",children:"Hard"}),l.mode==="bot"&&e.jsx(J,{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:x("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(_e,{value:String(l.rounds),onValueChange:t=>w(o=>({...o,rounds:Number(t)})),children:[e.jsx(Se,{className:x("rounded-xl h-11 border-white/20 bg-white/60 dark:bg-black/50 dark:border-white/10 transition-colors shadow-inner",l.mode==="online"?"hover:border-[#8A3FD3]/50":"hover:border-[#1FA7E1]/50",W("rounds")&&"border-rose-400"),children:e.jsx(Ae,{})}),e.jsx(Ce,{className:"rounded-xl backdrop-blur-xl bg-white/90 dark:bg-[#1a1f2e]/90",children:[3,5,7,10,12,15].map(t=>e.jsx(J,{value:String(t),className:"rounded-lg",children:t},t))})]}),W("rounds")&&e.jsx("p",{className:"text-xs text-destructive dark:text-rose-300 ml-1",children:W("rounds")})]}),e.jsxs("div",{className:"space-y-1.5 group",children:[e.jsx("label",{className:x("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(_e,{value:String(l.timePerQuestionSec),onValueChange:t=>w(o=>({...o,timePerQuestionSec:Number(t)})),children:[e.jsx(Se,{className:x("rounded-xl h-11 border-white/20 bg-white/60 dark:bg-black/50 dark:border-white/10 transition-colors shadow-inner",l.mode==="online"?"hover:border-[#8A3FD3]/50":"hover:border-[#1FA7E1]/50",W("timePerQuestionSec")&&"border-rose-400"),children:e.jsx(Ae,{})}),e.jsx(Ce,{className:"rounded-xl backdrop-blur-xl bg-white/90 dark:bg-[#1a1f2e]/90",children:[15,20,30,45,60,90].map(t=>e.jsxs(J,{value:String(t),className:"rounded-lg",children:[t," sec"]},t))})]}),W("timePerQuestionSec")&&e.jsx("p",{className:"text-xs text-destructive dark:text-rose-300 ml-1",children:W("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(A,{type:"button",variant:l.queueType===t.value?"default":"outline",className:x("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(as,{value:U,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:x("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:x("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:ee?e.jsx(fa,{className:"h-5 w-5"}):e.jsx(ga,{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(sa,{checked:ee,onCheckedChange:Dt})]}),e.jsxs(y.div,{initial:!1,animate:{opacity:ee?1:.45,y:ee?0:-2},className:x("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(he*100),"%"]})]}),e.jsx("input",{type:"range",min:0,max:100,step:1,value:Math.round(he*100),disabled:!ee,onChange:t=>{const o=Ze(Number(t.target.value)/100,0,1);Ca(o)},onMouseUp:()=>D("tick"),onTouchEnd:()=>D("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:[k.status==="queued"&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:x("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:k.message}),l.mode==="online"&&l.queueType==="private_room"&&u?.roomCode&&e.jsxs(A,{type:"button",variant:"outline",className:x("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",E===u.roomCode&&"scale-105 bg-emerald-200 dark:bg-emerald-500/30"),onClick:()=>void Wt(u.roomCode),"aria-label":`Copy room code ${u.roomCode}`,children:[E===u.roomCode?e.jsx(kt,{className:"h-4 w-4"}):e.jsx(aa,{className:"h-4 w-4"}),u.roomCode]}),(j||Jt)&&ae>0&&e.jsxs("span",{className:x("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 ",ua(ae)]})]}),k.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:k.message}),k.status==="validating"&&e.jsxs("span",{className:x("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(Je,{className:"h-4 w-4 animate-spin"})," Validating..."]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[Ha&&e.jsx(A,{type:"button",variant:"outline",onClick:Kt,disabled:k.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:u?"Cancel room":"Leave queue"}),e.jsx(A,{type:"button",onClick:Oa,disabled:k.status==="validating"||j||Jt,className:x("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:k.status==="validating"?e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx(Je,{className:"h-5 w-5 animate-spin"})," Starting..."]}):l.mode==="online"&&l.queueType==="private_room"?U.trim()?"Join Room":"Create Room":"Start Battle"})]})]})]})]})})]},"setup")}),e.jsx(ze,{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:s?e.jsxs(te,{className:x(O,"rounded-[18px]"),children:[e.jsxs(le,{children:[e.jsxs(ie,{className:"text-base flex items-center justify-between gap-3",children:[e.jsxs("span",{className:"inline-flex items-center gap-2",children:[s.mode==="bot"?e.jsx(Pe,{className:"h-4 w-4 text-primary dark:text-[#9e8fff]"}):e.jsx(ve,{className:"h-4 w-4 text-primary dark:text-[#9e8fff]"}),"vs ",s.opponentName]}),e.jsxs("div",{className:"inline-flex items-center gap-2",children:[gt,e.jsxs("span",{className:"text-sm font-bold tabular-nums",children:[s.scoreFor," - ",s.scoreAgainst]})]})]}),e.jsx(pe,{className:"text-muted-foreground dark:text-[#b2bad0]",children:s.status==="completed"?`Completed in ${s.totalRounds} rounds.`:s.status==="ready"?s.mode==="online"?"Waiting for both players to confirm and start together.":"Finalizing practice bot session start.":`Round ${s.currentRound} of ${s.totalRounds}${B?" (paused for design)":""}`}),ma(s.lifecycle,n?.uid)&&e.jsx("p",{className:"text-xs font-medium text-muted-foreground dark:text-[#9aa4be]",children:ma(s.lifecycle,n?.uid)})]}),e.jsxs(ge,{className:"space-y-4",children:[s.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:s.mode==="online"?"Waiting for both players to lock in start...":"Starting practice bot round..."}),s.mode==="online"&&s.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:ua(ae)})," if the synchronized start does not happen."]}),e.jsx(A,{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"})]}),s.status==="in_progress"&&s.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"]}),B?" (paused)":""]}),B&&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:s.currentQuestion.prompt}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2",children:s.currentQuestion.choices.map((t,o)=>e.jsxs(A,{type:"button",variant:ye===o?"default":"outline",onClick:()=>X(o),disabled:G||Z||B,className:x("h-auto min-h-[48px] justify-start text-left font-medium px-4 py-3 rounded-xl whitespace-normal",ye===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(A,{type:"button",onClick:()=>void Ue(ye),disabled:G||Z||B,className:"rounded-xl",children:B?e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx(cs,{className:"h-4 w-4"})," Paused for design"]}):G?e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx(Je,{className:"h-4 w-4 animate-spin"})," Submitting..."]}):Z?"Waiting for opponent...":"Lock Answer"})})]}),M&&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: ",M.studentCorrect?"Correct":"Incorrect"," · ",s.mode==="bot"?"Bot":"Opponent"," ",M.botCorrect?"Correct":"Incorrect"]}),e.jsxs("p",{className:"text-xs text-muted-foreground dark:text-[#9aa4be]",children:["Correct option: ",String.fromCharCode(65+M.correctOptionIndex)]})]}),s.status==="completed"&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:x("rounded-2xl border p-4",s.outcome==="win"?"border-emerald-300 bg-emerald-50 dark:border-emerald-400/40 dark:bg-emerald-900/20":s.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:s.outcome==="win"?"Victory!":s.outcome==="loss"?"Match Complete":"Draw Match"}),e.jsxs("p",{className:"mt-1 text-sm font-semibold text-foreground dark:text-[#ecf0fb]",children:["Final Score: ",s.scoreFor," - ",s.scoreAgainst]}),e.jsxs("p",{className:"text-xs text-muted-foreground dark:text-[#9aa4be]",children:["XP Earned: +",s.xpBreakdown?.totalXPAwarded??s.xpEarned??0,s.xpBreakdown&&e.jsxs("span",{className:"block",children:["Base: +",s.xpBreakdown.baseMatchXP," + Performance: +",s.xpBreakdown.performanceXP]})]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(A,{type:"button",variant:"outline",onClick:()=>{_(null),v(null),h(!1),d("setup")},className:"rounded-xl",children:"Start New Match"}),s.mode==="bot"&&e.jsx(A,{type:"button",onClick:()=>void Gt(),disabled:G,className:"rounded-xl",children:"Rematch"})]})]})]})]}):u?e.jsxs(te,{className:x(O,"rounded-[18px]"),children:[e.jsxs(le,{children:[e.jsxs(ie,{className:"text-base flex items-center gap-2",children:[e.jsx(ve,{className:"h-4 w-4 text-primary dark:text-[#9e8fff]"}),"Private Room Lobby"]}),e.jsxs(pe,{className:"text-muted-foreground dark:text-[#b2bad0]",children:["Room ",u.roomCode," · ",u.participantCount,"/2 students connected."]})]}),e.jsx(ge,{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:u.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 ",u.roomCode," with your classmate."]}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center justify-end gap-2",children:[(u.status==="waiting"||u.status==="ready")&&e.jsx(A,{type:"button",variant:"outline",className:"h-8 rounded-lg",onClick:Kt,disabled:k.status==="validating",children:"Cancel room"}),e.jsxs(A,{type:"button",variant:"outline",className:"h-8 rounded-lg",onClick:()=>void Wt(u.roomCode),children:[E===u.roomCode?e.jsx(kt,{className:"h-4 w-4"}):e.jsx(aa,{className:"h-4 w-4"}),E===u.roomCode?"Copied":"Copy code"]})]})]})})]}):j?e.jsx(te,{className:x(O,"rounded-[18px]"),children:e.jsxs(le,{children:[e.jsxs(ie,{className:"text-base flex items-center gap-2",children:[e.jsx(ve,{className:"h-4 w-4 text-primary dark:text-[#9e8fff]"}),"Public Matchmaking"]}),e.jsx(pe,{className:"text-muted-foreground dark:text-[#b2bad0]",children:"Searching for a student with the same setup..."})]})}):e.jsx(te,{className:x(O,"rounded-[18px]"),children:e.jsxs(le,{children:[e.jsxs(ie,{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(pe,{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(ze,{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:x(O,"relative overflow-hidden rounded-[24px] mb-6 border-emerald-500/20 shadow-[0_0_40px_-10px_rgba(16,185,129,0.2)]"),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/20 via-teal-500/10 to-emerald-600/5 dark:from-emerald-500/20 dark:via-teal-500/10 dark:to-teal-900/10"}),e.jsx("div",{className:"pointer-events-none absolute -top-24 -right-24 h-64 w-64 rounded-full bg-emerald-400/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-400/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(A,{variant:"ghost",onClick:()=>d("hub"),className:"h-12 w-12 p-0 rounded-full bg-white/50 dark:bg-black/40 hover:bg-white/80 dark:hover:bg-black/60 hover:scale-105 transition-all backdrop-blur-md border border-emerald-500/30 shadow-[0_0_15px_rgba(16,185,129,0.2)] shrink-0",children:e.jsx(Ye,{className:"h-6 w-6 rotate-180 text-emerald-800 dark: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-transparent bg-clip-text bg-gradient-to-br from-emerald-600 to-teal-500 dark:from-emerald-300 dark:to-teal-200 drop-shadow-sm",children:[e.jsx("div",{className:"bg-emerald-100 dark:bg-emerald-900/50 p-2 rounded-2xl shadow-inner border border-emerald-200 dark:border-emerald-700/50 animate-icon-rotate",children:e.jsx(na,{className:"h-8 w-8 text-emerald-600 dark:text-emerald-400 drop-shadow-[0_0_8px_rgba(16,185,129,0.5)]"})}),"Matches History"]}),e.jsx("p",{className:"text-sm font-bold text-emerald-800/80 dark:text-emerald-100/70 mt-2 tracking-wide uppercase",children:"Review your past duels and track your progress."})]})]})})]}),e.jsxs(te,{className:x(O,"rounded-[18px]"),children:[e.jsxs(le,{children:[e.jsx(ie,{className:"text-base",children:"Match History"}),e.jsx(pe,{className:"text-muted-foreground dark:text-[#b2bad0]",children:"Your recent student battles only."})]}),e.jsxs(ge,{className:"space-y-3",children:[e.jsx("div",{className:"flex gap-2",children:[{value:"all",label:"All"},{value:"online",label:"Online"},{value:"bot",label:"Bot"}].map(t=>e.jsx(A,{type:"button",variant:je===t.value?"default":"outline",onClick:()=>za(t.value),className:"rounded-xl h-8 px-3",children:t.label},t.value))}),qt?e.jsxs("div",{className:"space-y-2",children:[e.jsx(we,{className:"h-12 w-full rounded-xl bg-muted dark:bg-[#2a3143]"}),e.jsx(we,{className:"h-12 w-full rounded-xl bg-muted dark:bg-[#2a3143]"})]}):Ve.length===0?e.jsx("p",{className:"text-sm text-muted-foreground dark:text-[#a8b2c9]",children:"No matches in this filter yet."}):Ve.map(t=>e.jsxs("div",{className:"rounded-xl border border-border bg-muted/40 px-3 py-2 flex items-center justify-between gap-3 dark:border-[#2f3547] dark:bg-[#11151d]",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"text-sm font-semibold text-foreground dark:text-[#f5f7fb]",children:["vs ",t.opponentName]}),e.jsxs("p",{className:"text-xs text-muted-foreground dark:text-[#95a0bb] tabular-nums",children:[t.scoreFor,"-",t.scoreAgainst," · ",t.accuracy.toFixed(0),"% · +",t.xpEarned," XP"]})]}),e.jsx("span",{className:x("text-xs font-semibold rounded-full px-2.5 py-1 border",t.outcome==="win"?"text-emerald-700 border-emerald-200 bg-emerald-50 dark:text-emerald-300 dark:border-emerald-300/40 dark:bg-emerald-900/20":t.outcome==="loss"?"text-rose-700 border-rose-200 bg-rose-50 dark:text-rose-300 dark:border-rose-300/40 dark:bg-rose-900/20":"text-amber-700 border-amber-200 bg-amber-50 dark:text-amber-300 dark:border-amber-300/40 dark:bg-amber-900/20"),children:Ds(t.outcome)})]},t.matchId))]})]})]},"history")}),e.jsx(ze,{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:x(O,"relative overflow-hidden rounded-[24px] mb-6 border-indigo-500/20 shadow-[0_0_40px_-10px_rgba(99,102,241,0.2)]"),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/20 via-purple-500/10 to-indigo-600/5 dark:from-indigo-500/20 dark:via-purple-500/10 dark:to-purple-900/10"}),e.jsx("div",{className:"pointer-events-none absolute -top-24 -right-24 h-64 w-64 rounded-full bg-indigo-400/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-400/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(A,{variant:"ghost",onClick:()=>d("hub"),className:"h-12 w-12 p-0 rounded-full bg-white/50 dark:bg-black/40 hover:bg-white/80 dark:hover:bg-black/60 hover:scale-105 transition-all backdrop-blur-md border border-indigo-500/30 shadow-[0_0_15px_rgba(99,102,241,0.2)] shrink-0",children:e.jsx(Ye,{className:"h-6 w-6 rotate-180 text-indigo-800 dark: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-transparent bg-clip-text bg-gradient-to-br from-indigo-600 to-purple-500 dark:from-indigo-300 dark:to-purple-200 drop-shadow-sm",children:[e.jsx("div",{className:"bg-indigo-100 dark:bg-indigo-900/50 p-2 rounded-2xl shadow-inner border border-indigo-200 dark:border-indigo-700/50 animate-icon-bob",children:e.jsx(Ct,{className:"h-8 w-8 text-indigo-600 dark:text-indigo-400 drop-shadow-[0_0_8px_rgba(99,102,241,0.5)]"})}),"My Statistics"]}),e.jsx("p",{className:"text-sm font-bold text-indigo-800/80 dark:text-indigo-100/70 mt-2 tracking-wide uppercase",children:"Analyzing your battlefield performance."})]})]})})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-4 gap-4",children:[{label:"Wins",value:se?.wins??0,icon:jt},{label:"Current streak",value:se?.currentStreak??0,icon:et},{label:"Avg accuracy",value:`${(se?.averageAccuracy||0).toFixed(1)}%`,icon:os},{label:"Avg response",value:Ps(se?.averageResponseMs||0),icon:ra}].map(t=>e.jsx(te,{className:x(O,"rounded-[18px]"),children:e.jsxs(ge,{className:"pt-6",children:[e.jsx("p",{className:"text-xs text-muted-foreground dark:text-[#9da7bf]",children:t.label}),e.jsx("p",{className:"mt-1 tabular-nums text-2xl font-black text-foreground dark:text-[#f5f7fb]",children:t.value}),e.jsx(t.icon,{className:"mt-3 h-4 w-4 text-primary dark:text-[#9e8fff]"})]})},t.label))})]},"stats")}),e.jsx(ze,{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:x(O,"relative overflow-hidden rounded-[24px] mb-6 border-amber-500/20 shadow-[0_0_40px_-10px_rgba(245,158,11,0.2)]"),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/20 via-orange-500/10 to-amber-600/5 dark:from-amber-600/20 dark:via-orange-500/10 dark:to-orange-900/10"}),e.jsx("div",{className:"pointer-events-none absolute -top-24 -right-24 h-64 w-64 rounded-full bg-amber-400/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-400/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(A,{variant:"ghost",onClick:()=>d("hub"),className:"h-12 w-12 p-0 rounded-full bg-white/50 dark:bg-black/40 hover:bg-white/80 dark:hover:bg-black/60 hover:scale-105 transition-all backdrop-blur-md border border-amber-500/30 shadow-[0_0_15px_rgba(245,158,11,0.2)] shrink-0",children:e.jsx(Ye,{className:"h-6 w-6 rotate-180 text-amber-800 dark: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-transparent bg-clip-text bg-gradient-to-br from-amber-600 to-orange-500 dark:from-amber-300 dark:to-orange-200 drop-shadow-sm",children:[e.jsx(y.div,{animate:{scale:[1,1.1,1]},transition:{duration:2,repeat:1/0,ease:"easeInOut"},className:"bg-amber-100 dark:bg-amber-900/50 p-2 rounded-2xl shadow-inner border border-amber-200 dark:border-amber-700/50",children:e.jsx(jt,{className:"h-8 w-8 text-amber-600 dark:text-amber-400 drop-shadow-[0_0_12px_rgba(245,158,11,0.6)]"})}),"Hall of Fame"]}),e.jsx("p",{className:"text-sm font-bold text-amber-800/80 dark:text-amber-100/70 mt-2 tracking-wide uppercase",children:"The top-ranked minds across the globe."})]})]})})]}),e.jsxs(te,{className:x(O,"rounded-[18px]"),children:[e.jsxs(le,{children:[e.jsxs(ie,{className:"text-base flex items-center gap-2",children:[e.jsx(Xa,{className:"h-4 w-4 text-primary dark:text-[#9e8fff]"})," Hall of Fame"]}),e.jsx(pe,{className:"text-muted-foreground dark:text-[#b2bad0]",children:"Student-only ranking using trusted backend aggregates."})]}),e.jsx(ge,{children:Ia?e.jsxs("div",{className:"space-y-2",children:[e.jsx(we,{className:"h-12 w-full rounded-xl bg-muted dark:bg-[#2a3143]"}),e.jsx(we,{className:"h-12 w-full rounded-xl bg-muted dark:bg-[#2a3143]"}),e.jsx(we,{className:"h-12 w-full rounded-xl bg-muted dark:bg-[#2a3143]"})]}):Xt.length===0?e.jsx("p",{className:"text-sm text-muted-foreground dark:text-[#a9b3ca]",children:"No leaderboard entries yet. Finish a battle to place on the board."}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-2",children:[e.jsxs("div",{className:"rounded-xl border border-border bg-muted/30 p-2.5 dark:border-[#2f3547] dark:bg-[#11151d]",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wide text-muted-foreground dark:text-[#98a2bc]",children:"Name display"}),e.jsxs(_e,{value:qe,onValueChange:t=>Ba(t),children:[e.jsx(Se,{className:"mt-1 h-8 rounded-lg",children:e.jsx(Ae,{})}),e.jsxs(Ce,{children:[e.jsx(J,{value:"alias",children:"Alias"}),e.jsx(J,{value:"initials",children:"Initials"}),e.jsx(J,{value:"full",children:"Full name"})]})]})]}),e.jsxs("label",{className:"rounded-xl border border-border bg-muted/30 p-2.5 flex items-center justify-between gap-3 dark:border-[#2f3547] dark:bg-[#11151d]",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wide text-muted-foreground dark:text-[#98a2bc]",children:"Score detail"}),e.jsx("p",{className:"text-xs text-muted-foreground dark:text-[#98a2bc]",children:"Show exact score values"})]}),e.jsx(sa,{checked:ct,onCheckedChange:Fa})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground dark:text-[#95a0bb]",children:"Privacy mode keeps classmate identities and scores obfuscated by default while preserving your own exact rank and score."}),Xt.map(t=>e.jsxs("div",{className:x("rounded-xl border bg-muted/30 px-3 py-2 flex items-center justify-between dark:bg-[#11151d]",t.isSelf?"border-primary/60 dark:border-[#8d7fff]":"border-border dark:border-[#2f3547]"),children:[e.jsxs("div",{children:[e.jsxs("p",{className:"text-sm font-semibold text-foreground dark:text-[#f5f7fb]",children:["#",t.rank," ",t.displayName,t.isSelf?" (You)":""]}),e.jsxs("p",{className:"text-xs text-muted-foreground dark:text-[#95a0bb]",children:["Win rate ",t.winRate.toFixed(1),"% · Best streak ",t.bestStreak]})]}),e.jsx("p",{className:"tabular-nums text-sm font-semibold text-foreground dark:text-[#f5f7fb]",children:t.scoreLabel})]},t.userId))]})})]})]},"leaderboard")})]})})})})]})};export{xr as default}; +`,Fs=300*1e3,Es=({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))}),Rs=({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,z=30,g=Math.abs(Math.floor(w/z));let k=0;const b=setTimeout(()=>{const j=setInterval(()=>{k+=Math.max(1,Math.floor(a/z)),k>=a?(l(a),clearInterval(j)):l(k)},g);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]})]})},H="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)]",Ts=a=>a<=0?"--":`${(a/1e3).toFixed(2)}s`,Ps=a=>a==="win"?"Win":a==="loss"?"Loss":"Draw",Ze=(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")}`},Ds=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},mr=()=>{const{userProfile:a,userRole:s}=Ua(),n=a,[c,d]=i.useState("hub"),[l,w]=i.useState(fs),[z,g]=i.useState([]),[k,b]=i.useState({status:"idle"}),[j,h]=i.useState(!1),[m,v]=i.useState(null),[U,S]=i.useState(""),[E,Y]=i.useState(null),[ae,T]=i.useState(0),[V,C]=i.useState(null),[ee,Pt]=i.useState(()=>typeof window>"u"?!0:window.localStorage.getItem("quiz_battle_sound_enabled")!=="0"),[he,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)?Ze(t,0,1):.7}),[Dt,I]=i.useState("connected"),[je,za]=i.useState("all"),[Qt,ot]=i.useState(!0),[se,lt]=i.useState(null),[it,dt]=i.useState([]),[Ia,qt]=i.useState(!1),[Lt,Ba]=i.useState([]),[qe,Ma]=i.useState("alias"),[ct,Fa]=i.useState(!1),[r,_]=i.useState(null),[ye,X]=i.useState(null),[G,Me]=i.useState(!1),[P,Fe]=i.useState(0),[Z,K]=i.useState(!1),[M,ut]=i.useState(!1),[Ea,Ra]=i.useState(!1),[mt,Ta]=i.useState(_t),[B,re]=i.useState(null),[Pa,xt]=i.useState(!1),[Le,pt]=i.useState(null),[Da,ht]=i.useState(null),[Qa,$e]=i.useState(null),$t=i.useRef(""),bt=i.useRef(null),ke=i.useRef(null),ue=i.useRef(0),Ht=i.useRef(""),Ee=i.useRef(0),ft=i.useRef(0),He=i.useRef(null),Re=i.useRef(null),Oe=i.useRef(-1),gt=!1,me=i.useMemo(()=>{const t=Ga(n?.grade);return Jt.filter(o=>t.includes(o.id))},[n?.grade]),qa=i.useMemo(()=>(me.find(o=>o.id===l.subjectId)?.modules||[]).map(o=>({value:o.id,label:o.title})),[me,l.subjectId]),$=i.useMemo(()=>{const t=r?.roundResults||[];let o=0;return t.forEach(p=>{o=p.studentCorrect?o+1:0}),o},[r?.roundResults]),La=i.useMemo(()=>{const t=Math.max(0,$-1)*.12;return Number((1+Math.min(.72,t)).toFixed(2))},[$]),$a=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 N=o>=2?Math.min(25,(o-1)*5):0;p+=10+N}else o=0;return p},[r?.status,r?.xpEarned,r?.roundResults]),Ot=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,Ot-1)*.1;return Number((1+Math.min(.5,t)).toFixed(2))},[Ot]),i.useMemo(()=>$>=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)]"}:$>=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,$]);const xe=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,($-1)*2):0;return t+o+p},[B,$]),D=i.useCallback(t=>{if(!(!ee||he<=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],N=o.currentTime,R=.07,f=Ze(x.volume*he,.004,.08);x.notes.forEach((F,oe)=>{const fe=o.createOscillator(),Te=o.createGain(),Ne=N+oe*R;fe.type=x.type,fe.frequency.setValueAtTime(F,Ne),Te.gain.setValueAtTime(1e-4,Ne),Te.gain.exponentialRampToValueAtTime(f,Ne+.012),Te.gain.exponentialRampToValueAtTime(1e-4,Ne+x.duration),fe.connect(Te),Te.connect(o.destination),fe.start(Ne),fe.stop(Ne+x.duration+.02)})}catch(o){console.warn("Battle tone playback skipped or blocked:",o)}},[ee,he]),Vt=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(()=>{},[gt]),Ut=i.useCallback(t=>{h(!1),v(null),_(null),T(0),C(null),b({status:"error",message:t}),d("setup")},[]),ne=i.useCallback(async()=>{if(!n?.uid)return null;const[t,o]=await Promise.all([ws(n.uid),vs(n.uid,{mode:je,limitCount:8})]);return{stats:t,history:o}},[je,n?.uid]);i.useEffect(()=>{if(me.length===0)return;const o=me.some(N=>N.id===l.subjectId)?l.subjectId:me[0].id,p=me.find(N=>N.id===o),x=p?.modules?.[0]?.id||"";w(N=>{const R=p?.modules?.some(f=>f.id===N.topicId)?N.topicId:x;return N.subjectId===o&&N.topicId===R?N:{...N,subjectId:o,topicId:R}})},[me,l.subjectId]),i.useEffect(()=>{if(!n?.uid){lt(null),dt([]),ot(!1);return}let t=!0;return ot(!0),(async()=>{const p=await ne();t&&(p&&(lt(p.stats),dt(p.history)),ot(!1))})(),()=>{t=!1}},[ne,n?.uid]);const Ve=i.useMemo(()=>je==="all"?it:it.filter(t=>t.mode===je),[it,je]),Yt=i.useMemo(()=>Lt.map((t,o)=>{const p=t.rank||o+1,x=t.userId===n?.uid,N=`Student-${t.userId.slice(-4).toUpperCase()}`,R=qe==="full"?t.displayName:qe==="initials"?Ds(t.displayName):N,f=Math.floor(t.leaderboardScore/25)*25,F=ct||x?`${t.leaderboardScore} pts`:`${f}-${f+24} pts`;return{...t,rank:p,isSelf:x,displayName:R,scoreLabel:F}}),[Lt,qe,ct,n?.uid]);i.useEffect(()=>{if(c!=="leaderboard"&&c!=="hub")return;let t=!0;return qt(!0),(async()=>{const p=await Bs(20);t&&(Ba(p),qt(!1))})(),()=>{t=!1}},[c]);const We=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 le(t.match.matchId),Ee.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&&We()},[n?.uid,We]),i.useEffect(()=>{typeof window>"u"||window.localStorage.setItem("quiz_battle_sound_enabled",ee?"1":"0")},[ee]),i.useEffect(()=>{typeof window>"u"||window.localStorage.setItem("quiz_battle_sound_volume",he.toFixed(2))},[he]),i.useEffect(()=>{if(typeof window>"u")return;const t=()=>{const o=window.innerWidth,p=window.innerHeight;Ta({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=()=>{Ra(!!document.fullscreenElement)};return t(),document.addEventListener("fullscreenchange",t),()=>{document.removeEventListener("fullscreenchange",t)}},[]),i.useEffect(()=>{const t=V!==null;if(!(j||m&&(m.status==="waiting"||m.status==="ready")||t)){T(0);return}const o=()=>{if(!V){T(x=>x+1);return}T(Math.max(0,Math.ceil((V-Date.now())/1e3)))};o();const p=window.setInterval(o,1e3);return()=>{window.clearInterval(p)}},[j,m?.status,m?.roomId,V]),i.useEffect(()=>{if(!V)return;const t=window.setInterval(()=>{V-Date.now()<=0&&(window.clearInterval(t),(async()=>{try{(j||!m)&&await la()}catch{}finally{Ut("Public matchmaking timed out after 5 minutes. Please start again.")}})())},1e3);return()=>{window.clearInterval(t)}},[m,Ut,j,V]),i.useEffect(()=>{if(typeof window>"u")return;I(window.navigator.onLine?"connected":"disconnected");const t=()=>{I("reconnecting"),We()},o=()=>{I("disconnected")};return window.addEventListener("online",t),window.addEventListener("offline",o),()=>{window.removeEventListener("online",t),window.removeEventListener("offline",o)}},[We]),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||(Ee.current=0),!j&&!p&&!t&&!o||M)return;let x=!1;const N=async()=>{try{if(r?.mode==="bot"&&r.status==="ready"){const f=await le(r.matchId);if(x)return;_(f),I("connected"),C(f.expiresAtMs||null),Ee.current=0,f.status==="in_progress"&&b({status:"queued",message:"Practice bot match started."});return}if(r?.mode==="online"){if(r.status==="ready"){const oe=await le(r.matchId);if(x)return;_(oe),I("connected"),C(oe.expiresAtMs||null),oe.status==="in_progress"&&b({status:"queued",message:"Match started. Round timer is live."});return}const f=await Nt(r.matchId);if(x)return;const F=f.roundResults.filter(oe=>oe.roundNumber>Oe.current).sort((oe,fe)=>oe.roundNumber-fe.roundNumber)[0];F?(Oe.current=F.roundNumber,re(F),pt(f)):(_(f),f.status==="completed"&&(h(!1),v(null),C(null)),f.status==="cancelled"&&r.status==="in_progress"&&(xt(!0),K(!1))),I("connected");return}if(m?.roomId){const f=await Ns({roomId:m.roomId});if(x)return;if(v(f.room),f.match){const F=await le(f.match.matchId);if(x)return;_(F),v(f.room),h(!1),C(F.expiresAtMs||null),d("battle"),I("connected"),b({status:"queued",message:F.status==="ready"?"Opponent connected. Waiting for synchronized start...":"Private room match started."})}return}if(j){const f=await ia();if(x)return;if(f.sessionType==="match"&&f.match){const F=await le(f.match.matchId);if(x)return;_(F),v(f.room||null),h(!1),C(F.expiresAtMs||null),d("battle"),I("connected"),b({status:"queued",message:"Opponent found. Preparing synchronized start..."});return}if(f.sessionType==="room"&&f.room){h(!1),v(f.room),C(null),I("connected");return}I("connected")}}catch(f){if(!x){if(console.warn("Quiz Battle sync poll failed:",f),r?.mode==="bot"&&r.status==="ready"&&(Ee.current+=1,Ee.current>=3)){const F=f;h(!1),v(null),_(null),d("setup"),b({status:"error",message:F?.message||"Unable to start bot battle. Please try again."}),I("disconnected");return}I("reconnecting")}}};N();const R=window.setInterval(()=>{N()},3e3);return()=>{x=!0,window.clearInterval(R)}},[r?.matchId,r?.mode,r?.status,m?.roomId,m?.status,M,j]);const be=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(!be)return;let t=!1;const o=async()=>{try{await Ss(be.scope,be.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),bs(be.scope,be.resourceId)}},[be?.scope,be?.resourceId]),i.useEffect(()=>{if(!r||r.status!=="in_progress"){K(!1),ke.current=null,ue.current=0;return}ke.current=null,ue.current=0;const t=r.roundDeadlineAtMs?Math.max(0,Math.ceil((r.roundDeadlineAtMs-Date.now())/1e3)):r.timePerQuestionSec;Fe(t),X(null),K(!1)},[r?.matchId,r?.status,r?.currentRound,r?.timePerQuestionSec]),i.useEffect(()=>{M&&(!r||r.status!=="in_progress")&&ut(!1)},[r?.matchId,r?.status,M]),i.useEffect(()=>{const t=r?.lifecycle;if(!t?.eventType)return;const o=`${t.eventType}:${t.sequence}`;$t.current!==o&&($t.current=o,t.eventType==="answer_locked"?D("lock"):t.eventType==="round_result"&&D("result"))},[r?.lifecycle?.eventType,r?.lifecycle?.sequence,D]),i.useEffect(()=>{!r||r.status!=="completed"||Ht.current!==r.matchId&&(Ht.current=r.matchId,D(r.outcome==="loss"?"loss":"win"),r.outcome==="win"&&Ya(()=>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,D]),i.useEffect(()=>{if(!r||r.status!=="in_progress"||Z||G||M){bt.current=null;return}P<=3&&P>0&&bt.current!==P&&(bt.current=P,D("tick"))},[r?.status,P,Z,G,M,D]),i.useEffect(()=>{if(!r||r.status!=="in_progress"){ft.current=0;return}$>ft.current&&$>=2&&D($>=4?"multiplier":"streak"),ft.current=$},[r?.matchId,r?.status,$,D]),i.useEffect(()=>{if(!r){He.current=null,$e(null);return}const t=He.current;if(!t||t.matchId!==r.matchId){He.current={matchId:r.matchId,scoreFor:r.scoreFor,scoreAgainst:r.scoreAgainst},$e(null);return}if(r.scoreFor!==t.scoreFor||r.scoreAgainst!==t.scoreAgainst){const o=r.scoreFor>t.scoreFor?"player":"opponent";$e(o),Re.current&&window.clearTimeout(Re.current),Re.current=window.setTimeout(()=>{$e(null)},850)}He.current={matchId:r.matchId,scoreFor:r.scoreFor,scoreAgainst:r.scoreAgainst}},[r?.matchId,r?.scoreAgainst,r?.scoreFor]),i.useEffect(()=>()=>{Re.current&&window.clearTimeout(Re.current)},[]),i.useEffect(()=>{if(!B?.studentCorrect||xe===null||xe<=0){ht(null);return}const t=xe>0?"positive":xe<0?"negative":"neutral";ht({id:Date.now(),label:`${xe>=0?"+":""}${xe} Momentum`,tone:t});const o=window.setTimeout(()=>{ht(null)},1400);return()=>{window.clearTimeout(o)}},[xe,B]),i.useEffect(()=>{if(B&&Le){B.studentCorrect?D("win"):D("loss");const t=window.setTimeout(()=>{_(Le),re(null),X(null),K(!1),pt(null),Le.status==="completed"&&(h(!1),v(null),ne(),Oe.current=-1)},1500);return()=>window.clearTimeout(t)}},[B,Le,D,ne]);const Ue=i.useCallback(async t=>{if(!r||r.status!=="in_progress"||Z||M)return;Me(!0);const o=window.setTimeout(()=>{Me(!1),b({status:"error",message:"Submission took too long. Syncing latest match state now..."}),Nt(r.matchId).then(p=>{_(p),p.status==="completed"&&(h(!1),v(null),C(null))}).catch(()=>{})},12e3);try{const p=r.roundDeadlineAtMs?Ze(r.timePerQuestionSec*1e3-Math.max(0,r.roundDeadlineAtMs-Date.now()),0,r.timePerQuestionSec*1e3):Math.max(0,(r.timePerQuestionSec-P)*1e3),x=await zs({matchId:r.matchId,roundNumber:r.currentRound,selectedOptionIndex:t,responseMs:p});ke.current=null,ue.current=0,x.roundResult?(Oe.current=x.roundResult.roundNumber,re(x.roundResult),pt(x.match)):(_(x.match),re(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),ne(),b({status:"queued",message:x.completion?`Match finished (${x.completion.outcome.toUpperCase()}) +${x.completion.xpEarned} XP`:"Match finished. Results saved."}))}catch(p){const N=p?.message||"Unable to submit answer right now. Please try again.";if(t===null||N.includes("Round timer elapsed")||N.includes("Expected round")||N.includes("Match is not currently active"))try{const f=await Nt(r.matchId),F=f.currentRound!==r.currentRound;if(_(f),X(null),K(!1),F||f.status==="completed"?(ke.current=null,ue.current=0):t===null&&(ue.current=Date.now()+3e3),f.status==="completed"){h(!1),v(null),C(null),ne(),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&&(ue.current=Date.now()+3e3),b({status:"error",message:N})}finally{window.clearTimeout(o),Me(!1)}},[r,M,ne,Z,P]);i.useEffect(()=>{if(!r||r.status!=="in_progress"||M||G||Z)return;const t=r.roundDeadlineAtMs?Math.max(0,Math.ceil((r.roundDeadlineAtMs-Date.now())/1e3)):P;if(r.roundDeadlineAtMs&&t!==P&&Fe(t),ye===null?t<=1:t<=0){if(ke.current===r.currentRound&&Date.now(){r.roundDeadlineAtMs?Fe(Math.max(0,Math.ceil((r.roundDeadlineAtMs-Date.now())/1e3))):Fe(x=>Math.max(0,x-1))},1e3);return()=>{window.clearTimeout(p)}},[r,G,M,Z,P,ye,Ue]);const Xt=i.useCallback(async()=>{if(!(!r||r.mode!=="bot")){Me(!0),b({status:"validating"});try{const t=await Is(r.matchId),o=await le(t.matchId);_(o),v(null),h(!1),C(null),re(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{Me(!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(te,{className:u(H,"max-w-2xl"),children:e.jsxs(ie,{children:[e.jsx(de,{children:"Quiz Battle is student-only"}),e.jsx(pe,{className:"text-muted-foreground dark:text-[#aab3c7]",children:"Your account role does not have access to this module."})]})})})]});const Gt=t=>{g([]),b({status:"idle"}),ut(!1),h(!1),v(null),S(""),_(null),re(null),X(null),K(!1),C(null),w(o=>({...o,mode:t,queueType:t==="online"?o.queueType:"public_matchmaking"})),T(0),d("setup")},Zt=async()=>{b({status:"validating"});try{m?.roomId?await _s({roomId:m.roomId}):await la(),h(!1),v(null),_(t=>!t||t.mode!=="online"?t:t.status==="ready"||t.status==="cancelled"?null:t),S(""),T(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."})}},Ha=async()=>{b({status:"validating"});const t=gs(l);if(t.length>0){g(t),b({status:"error",message:"Fix the highlighted setup fields before starting."});return}g([]);try{if(l.mode==="online"){if(l.queueType==="private_room"){const N=U.trim().toUpperCase(),R=N?await ks(N):await ys(l);if(h(!1),v(R.room),S(""),C(R.match?.expiresAtMs||null),R.match){const f=await le(R.match.matchId);_(f),re(null),X(null),K(!1),d("battle"),C(f.expiresAtMs||null),b({status:"queued",message:f.status==="ready"?`Room ${R.room.roomCode} linked. Waiting for synchronized start...`:"Private room match started."});return}_(null),C(null),b({status:"queued",message:N?"Joined private room. Waiting for opponent...":"Private room created. Share code:"});return}const x=await js(l);if(x.status==="matched"&&x.matchId){const N=await le(x.matchId);h(!1),v(null),_(N),re(null),X(null),K(!1),d("battle"),C(N.expiresAtMs||null),b({status:"queued",message:"Opponent found. Preparing synchronized start..."});return}h(!0),v(null),_(null),C(x.expiresAtMs||Date.now()+Fs),T(0),b({status:"queued",message:"Joined matchmaking queue. Waiting for an opponent..."});return}const o=await As(l),p=await le(o.matchId);h(!1),v(null),_(p),re(null),X(null),K(!1),Fe(p.timePerQuestionSec),C(null),d("battle"),b({status:"queued",message:`Bot match ${o.matchId.slice(0,8)} live (${o.botDifficulty}).`}),ne().then(x=>{x&&(lt(x.stats),dt(x.history))})}catch(o){h(!1),b({status:"error",message:o?.message||"Unable to start battle. Please try again."})}},W=t=>z.find(o=>o.field===t)?.message;se?.winRate;const Kt=!!(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(Es,{viewportHeight:mt.height}),r.status==="completed"&&r.outcome==="draw"&&e.jsx(Rs,{viewportHeight:mt.height,viewportWidth:mt.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(Ke,{children:Pa&&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(Pe,{className:"h-16 w-16 text-rose-400 mb-2",strokeWidth:1.5}):e.jsx(ve,{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.jsx(A,{size:"lg",className:"w-full h-12 bg-emerald-500 hover:bg-emerald-400 text-white font-black rounded-xl",onClick:()=>{xt(!1),_(null),v(null),h(!1),b({status:"idle"}),d("hub"),ne()},children:"🏆 Claim Victory"}),e.jsx(A,{size:"lg",variant:"outline",className:"w-full h-12 border-white/20 text-white/70 hover:bg-white/10 rounded-xl",onClick:()=>{xt(!1),_(null),v(null),h(!1),b({status:"idle"}),d("hub")},children:"Back to Arena"})]})]})})}),M&&e.jsx("div",{className:"absolute inset-0 z-[110] bg-black/60 backdrop-blur-md flex items-center justify-center",children:e.jsxs(te,{className:"w-full max-w-sm border-border/50 bg-[#181d27] shadow-[0_20px_50px_rgba(0,0,0,0.5)]",children:[e.jsxs(ie,{className:"text-center",children:[e.jsx(de,{className:"text-3xl font-black text-white",children:"PAUSED"}),e.jsx(pe,{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(we,{className:"flex flex-col gap-3",children:[e.jsx(A,{variant:"default",size:"lg",className:"w-full text-lg h-12",onClick:Wt,children:"Resume Match"}),e.jsx(A,{variant:"outline",size:"lg",className:"w-full text-lg h-12 border-rose-500/20 text-rose-500 hover:bg-rose-500/10",onClick:()=>{ut(!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(_a,{playerRoundStreak:$,playerVisualMultiplier:La,liveXpEarned:$a,activeMatch:r,subjects:Jt,battleSoundEnabled:ee,onToggleSound:()=>Pt(t=>!t),isFullscreen:Ea,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:gt,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 N of t)if(N.studentCorrect){o++;const R=o>=2?Math.min(15,(o-1)*5):0;p+=10,x+=R}else o=0;return e.jsxs(e.Fragment,{children:[e.jsx(da,{value:p,label:"Correct Answers",delay:300,icon:e.jsx(kt,{className:"h-3 w-3 text-emerald-400"})}),e.jsx(da,{value:x,label:"Streak Bonus",delay:900,icon:e.jsx(et,{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(A,{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(A,{size:"lg",onClick:()=>void Xt(),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(Aa,{activeMatch:r,roundSecondsLeft:P,lastRoundResult:B,selectedOptionIndex:ye,roundLocked:Z,answerSubmitting:G,designPauseActive:M,onOptionSelect:t=>{B&&B.roundNumber===r.currentRound||G||Z||(ma()?.resume().catch(()=>{}),D("lock"),X(t),Ue(t))},floatingMomentum:Da,lastRoundMomentumDelta:xe,studentProfile:n,quizBattleAvatar:yt})}),e.jsx(Sa,{studentProfile:n,activeMatch:r,scorePulseTarget:Qa,quizBattleAvatar:yt})]})]})]}):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(Ms,{value:c,onValueChange:t=>d(t),children:[e.jsx(ze,{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:Dt==="connected"?"text-emerald-400":"text-amber-400",children:Dt})]})]})}),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:yt,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-1 sm:grid-cols-2 gap-4 lg:gap-6 relative z-10 w-full mb-2",children:[e.jsxs(y.button,{type:"button",onClick:()=>Gt("online"),whileHover:{scale:1.025},whileTap:{scale:.98},transition:{type:"spring",stiffness:400,damping:15},className:"w-full h-[205px] 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-[70px] 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-[120px] 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-[-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-[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-5 py-3 sm:py-4 text-center bg-[#662AA8]",children:e.jsx("p",{className:"text-[13px] font-bold text-white leading-[1.45] font-nunito",children:"Queue or room-code match with another student."})})]})]}),e.jsxs(y.button,{type:"button",onClick:()=>Gt("bot"),whileHover:{scale:1.025},whileTap:{scale:.98},transition:{type:"spring",stiffness:400,damping:15},className:"w-full h-[205px] 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-[70px] 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-[125px] 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-[45px] 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-[45px] 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-5 py-3 sm:py-4 text-center bg-[#127DA6]",children:e.jsx("p",{className:"text-[13px] font-bold text-white leading-[1.45] 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 h-[155px] sm:h-[165px] cursor-pointer group flex items-end justify-center overflow-visible mt-1 mb-2 scale-[0.75] origin-bottom sm:scale-[0.80] lg:scale-[0.85] lg:origin-center",children:e.jsxs(y.div,{className:"relative w-full h-full flex flex-col items-center justify-end",whileHover:{scale:1.03},whileTap:{scale:.98},children:[e.jsxs("div",{className:"absolute top-[1px] sm:-top-[30px] w-full flex justify-center items-end px-2 z-0",children:[e.jsx(vt,{strokeWidth:0,fill:"currentColor",className:"w-[35px] h-[35px] text-[#fde047] -rotate-[15deg] -mr-3 mb-1 z-0 drop-shadow-[0_0_15px_rgba(253,224,71,0.6)]"}),e.jsx("div",{className:"z-10 relative animate-star-float",children:e.jsx(vt,{strokeWidth:0,fill:"currentColor",className:"w-[60px] h-[60px] text-[#fcd34d] drop-shadow-[0_0_25px_rgba(252,211,77,0.9)]"})}),e.jsx(vt,{strokeWidth:0,fill:"currentColor",className:"w-[35px] h-[35px] text-[#fde047] rotate-[15deg] -ml-3 mb-1 z-0 drop-shadow-[0_0_15px_rgba(253,224,71,0.6)]"})]}),e.jsx("div",{className:`absolute inset-x-0 bottom-[40px] top-0 z-10 flex flex-col items-center justify-end + filter drop-shadow-[0px_3px_0px_white] drop-shadow-[0px_-3px_0px_white] drop-shadow-[3px_0px_0px_white] drop-shadow-[-3px_0px_0px_white] drop-shadow-[2px_2px_0px_white] drop-shadow-[-2px_-2px_0px_white] drop-shadow-[2px_-2px_0px_white] drop-shadow-[-2px_2px_0px_white]`,children:e.jsxs("div",{className:"flex items-end justify-center z-20 relative px-4",children:[e.jsxs("div",{className:"flex flex-col items-center w-[65px] relative",children:[e.jsx("div",{className:"w-full h-[14px] bg-[#d24b4b] rounded-[2px] relative z-10 -mb-[1px]"}),e.jsxs("div",{className:"w-[85%] h-[50px] bg-[#fe5c5c] rounded-b-[2px] flex flex-col justify-center items-center gap-1.5 pb-1.5",children:[e.jsx("div",{className:"w-6 h-1.5 bg-white rounded-full opacity-95"}),e.jsx("div",{className:"w-6 h-1.5 bg-white rounded-full opacity-95"})]})]}),e.jsxs("div",{className:"flex flex-col items-center w-[75px] -mx-[4px] z-20 relative",children:[e.jsx("div",{className:"w-full h-[18px] bg-[#f2812d] rounded-[2px] relative z-10 -mb-[1px]"}),e.jsxs("div",{className:"w-[85%] h-[75px] bg-[#fa9746] rounded-b-[2px] flex flex-col justify-start items-center pt-4 gap-1.5",children:[e.jsx("div",{className:"w-9 h-1.5 bg-white rounded-full opacity-95"}),e.jsx("div",{className:"w-9 h-1.5 bg-white rounded-full opacity-95"})]})]}),e.jsxs("div",{className:"flex flex-col items-center w-[65px] relative",children:[e.jsx("div",{className:"w-full h-[14px] bg-[#d24b4b] rounded-[2px] relative z-10 -mb-[1px]"}),e.jsxs("div",{className:"w-[85%] h-[50px] bg-[#fe5c5c] rounded-b-[2px] flex flex-col justify-center items-center gap-1.5 pb-1.5",children:[e.jsx("div",{className:"w-6 h-1.5 bg-white rounded-full opacity-95"}),e.jsx("div",{className:"w-6 h-1.5 bg-white rounded-full opacity-95"})]})]})]})}),e.jsx("div",{className:"absolute bottom-2 w-[110%] max-w-[280px] z-30 drop-shadow-2xl",children:e.jsxs("div",{className:"relative w-full h-[52px] flex justify-center items-center",children:[e.jsx("div",{className:"absolute -left-1 top-2 w-[55px] h-[40px] bg-[#8b0d0d] z-0 clip-poly-left"}),e.jsx("div",{className:"absolute -right-1 top-2 w-[55px] h-[40px] bg-[#8b0d0d] z-0 clip-poly-right"}),e.jsxs("div",{className:"absolute inset-x-6 top-0 bottom-0 bg-[#b61515] shadow-[inset_0_2px_4px_rgba(255,255,255,0.1),_inset_0_-4px_4px_rgba(0,0,0,0.2)] z-10 flex flex-col items-center justify-center",children:[e.jsx("h3",{className:"text-lg sm:text-xl font-black text-white tracking-widest leading-none drop-shadow-md font-nunito",children:"Hall of Fame"}),e.jsx("span",{className:"text-[9px] sm:text-[10px] font-bold text-white/90 tracking-widest mt-0.5",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-end justify-between px-5 pt-4 pb-2 relative z-10",children:[e.jsx("h3",{className:"text-[18px] font-black text-white tracking-wide leading-none drop-shadow-md font-nunito",children:"My Stats"}),e.jsx(A,{variant:"link",className:"text-white/80 hover:text-white p-0 h-auto font-semibold text-[13px] tracking-wide",onClick:()=>d("stats"),children:"View Stats >"})]}),e.jsxs("div",{className:"relative z-10 w-full overflow-hidden pb-4",children:[e.jsx("div",{className:"absolute left-0 top-0 bottom-0 w-6 bg-gradient-to-r from-[#3b3a82] to-transparent z-20 pointer-events-none dark:from-[#2b2b5f]"}),e.jsx("div",{className:"absolute right-0 top-0 bottom-0 w-6 bg-gradient-to-l from-[#3b3a82] to-transparent z-20 pointer-events-none dark:from-[#2b2b5f]"}),e.jsx("div",{className:"flex w-max pl-3 animate-marquee",children:[0,1].map(t=>e.jsxs("div",{className:"flex gap-2.5 pr-2.5",children:[e.jsxs("div",{className:"flex-none w-[60px] sm:w-[65px] lg:w-[70px] xl:w-[75px] aspect-square rounded-[12px] bg-[#f0eaff] p-1.5 flex flex-col justify-between relative overflow-hidden group shadow-sm dark:bg-[#d6ccf5]",children:[e.jsx(jt,{className:"absolute -bottom-1 -right-2 w-6 h-6 sm:w-8 sm:h-8 text-[#a06aec]/10 -rotate-12 transition-transform group-hover:scale-110"}),e.jsx("span",{className:"text-[12px] drop-shadow-sm leading-none",children:"🏆"}),e.jsxs("div",{className:"relative z-10 space-y-[1px]",children:[e.jsxs("h4",{className:"text-[12px] sm:text-[14px] lg:text-[16px] font-black text-[#8f5ae2] leading-none tracking-tight",children:[Math.round(se?.winRate||0)," %"]}),e.jsx("p",{className:"text-[6px] lg:text-[7px] font-extrabold text-[#baa4df] uppercase tracking-wider leading-none",children:"Win Rate"})]})]}),e.jsxs("div",{className:"flex-none w-[60px] sm:w-[65px] lg:w-[70px] xl:w-[75px] aspect-square rounded-[12px] bg-[#e1f5f7] p-1.5 flex flex-col justify-between relative overflow-hidden group shadow-sm dark:bg-[#b0e6eb]",children:[e.jsx(Ct,{className:"absolute -bottom-1 -right-2 w-6 h-6 sm:w-8 sm:h-8 text-[#35a8bc]/10 rotate-12 transition-transform group-hover:scale-110"}),e.jsx("span",{className:"text-[12px] drop-shadow-sm leading-none",children:"🎯"}),e.jsxs("div",{className:"relative z-10 space-y-[1px]",children:[e.jsx("h4",{className:"text-[12px] sm:text-[14px] lg:text-[16px] font-black text-[#319ab4] leading-none tracking-tight",children:se?.matchesPlayed||0}),e.jsx("p",{className:"text-[6px] lg:text-[7px] font-extrabold text-[#7eafbe] uppercase tracking-wider leading-none",children:"Matches"})]})]}),e.jsxs("div",{className:"flex-none w-[60px] sm:w-[65px] lg:w-[70px] xl:w-[75px] aspect-square rounded-[12px] bg-[#fef5e7] p-1.5 flex flex-col justify-between relative overflow-hidden group shadow-sm dark:bg-[#f6ebd2]",children:[e.jsx(ra,{className:"absolute -bottom-1 -right-2 w-6 h-6 sm:w-8 sm:h-8 text-[#e87a42]/10 -rotate-12 transition-transform group-hover:scale-110"}),e.jsx("span",{className:"text-[12px] drop-shadow-sm leading-none",children:"⏱️"}),e.jsxs("div",{className:"relative z-10 space-y-[1px]",children:[e.jsxs("h4",{className:"text-[12px] sm:text-[14px] lg:text-[16px] font-black text-[#db734b] leading-none tracking-tight",children:[se?.averageResponseMs?(se.averageResponseMs/1e3).toFixed(1):0,"s"]}),e.jsx("p",{className:"text-[6px] lg:text-[7px] font-extrabold text-[#d2a893] uppercase tracking-wider leading-none whitespace-nowrap",children:"Response"})]})]}),e.jsxs("div",{className:"flex-none w-[60px] sm:w-[65px] lg:w-[70px] xl:w-[75px] aspect-square rounded-[12px] bg-[#fdeceb] p-1.5 flex flex-col justify-between relative overflow-hidden group shadow-sm dark:bg-[#fbd3d3]",children:[e.jsx(et,{className:"absolute -bottom-1 -right-2 w-6 h-6 sm:w-8 sm:h-8 text-[#df655a]/10 rotate-12 transition-transform group-hover:scale-110"}),e.jsx("span",{className:"text-[12px] drop-shadow-sm leading-none",children:"✨"}),e.jsxs("div",{className:"relative z-10 space-y-[1px]",children:[e.jsx("h4",{className:"text-[12px] sm:text-[14px] lg:text-[16px] font-black text-[#d05c54] leading-none tracking-tight",children:n?.currentXP||0}),e.jsx("p",{className:"text-[6px] lg:text-[7px] font-extrabold text-[#dd9a9a] uppercase tracking-wider leading-none whitespace-nowrap",children:"Total XP"})]})]})]},t))})]})]}),e.jsxs(te,{className:u(H,"rounded-[18px] flex flex-col min-h-[200px]"),children:[e.jsxs(ie,{className:"pb-0 pt-3 px-4 flex flex-row items-center justify-between",children:[e.jsxs(de,{className:"text-[14px] font-black flex items-center gap-2 text-[#2e2b5e] dark:text-[#f5f7fb]",children:[e.jsx(aa,{className:"h-[16px] w-[16px] text-[#2e2b5e] dark:text-[#9e8fff]"})," Match History"]}),e.jsx(A,{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(we,{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(ge,{className:"h-10 w-full rounded-xl bg-muted dark:bg-[#2a3143]"}),e.jsx(ge,{className:"h-10 w-full rounded-xl bg-muted dark:bg-[#2a3143]"})]}):Ve.length===0?e.jsx("p",{className:"text-xs text-center text-muted-foreground dark:text-[#a8b2c9] py-2",children:"No battle history yet."}):Ve.slice(0,3).map(t=>{const o=t.outcome==="win",p=t.outcome==="loss",x=t.opponentName.split(" ").map(N=>N[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(ze,{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(H,"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(A,{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(Ye,{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(ve,{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(Pe,{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(_e,{value:l.subjectId,onValueChange:t=>w(o=>({...o,subjectId:t})),children:[e.jsx(Se,{className:u("rounded-xl h-11 border-white/20 bg-white/60 dark:bg-black/50 dark:border-white/10 transition-colors shadow-inner",l.mode==="online"?"hover:border-[#8A3FD3]/50":"hover:border-[#1FA7E1]/50",W("subjectId")&&"border-rose-400"),children:e.jsx(Ae,{placeholder:"Select category"})}),e.jsx(Ce,{className:"rounded-xl backdrop-blur-xl bg-white/90 dark:bg-[#1a1f2e]/90",children:me.map(t=>e.jsx(J,{value:t.id,className:"rounded-lg",children:t.title},t.id))})]}),W("subjectId")&&e.jsx("p",{className:"text-xs text-destructive dark:text-rose-300 ml-1",children:W("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(_e,{value:l.topicId,onValueChange:t=>w(o=>({...o,topicId:t})),children:[e.jsx(Se,{className:u("rounded-xl h-11 border-white/20 bg-white/60 dark:bg-black/50 dark:border-white/10 transition-colors shadow-inner",l.mode==="online"?"hover:border-[#8A3FD3]/50":"hover:border-[#1FA7E1]/50",W("topicId")&&"border-rose-400"),children:e.jsx(Ae,{placeholder:"Select topic group"})}),e.jsx(Ce,{className:"rounded-xl backdrop-blur-xl bg-white/90 dark:bg-[#1a1f2e]/90",children:qa.map(t=>e.jsx(J,{value:t.value,className:"rounded-lg",children:t.label},t.value))})]}),W("topicId")&&e.jsx("p",{className:"text-xs text-destructive dark:text-rose-300 ml-1",children:W("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(_e,{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(Se,{className:u("rounded-xl h-11 border-white/20 bg-white/60 dark:bg-black/50 dark:border-white/10 transition-colors shadow-inner",l.mode==="online"?"hover:border-[#8A3FD3]/50":"hover:border-[#1FA7E1]/50"),children:e.jsx(Ae,{})}),e.jsxs(Ce,{className:"rounded-xl backdrop-blur-xl bg-white/90 dark:bg-[#1a1f2e]/90",children:[e.jsx(J,{value:"easy",className:"rounded-lg",children:"Easy"}),e.jsx(J,{value:"medium",className:"rounded-lg",children:"Medium"}),e.jsx(J,{value:"hard",className:"rounded-lg",children:"Hard"}),l.mode==="bot"&&e.jsx(J,{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(_e,{value:String(l.rounds),onValueChange:t=>w(o=>({...o,rounds:Number(t)})),children:[e.jsx(Se,{className:u("rounded-xl h-11 border-white/20 bg-white/60 dark:bg-black/50 dark:border-white/10 transition-colors shadow-inner",l.mode==="online"?"hover:border-[#8A3FD3]/50":"hover:border-[#1FA7E1]/50",W("rounds")&&"border-rose-400"),children:e.jsx(Ae,{})}),e.jsx(Ce,{className:"rounded-xl backdrop-blur-xl bg-white/90 dark:bg-[#1a1f2e]/90",children:[3,5,7,10,12,15].map(t=>e.jsx(J,{value:String(t),className:"rounded-lg",children:t},t))})]}),W("rounds")&&e.jsx("p",{className:"text-xs text-destructive dark:text-rose-300 ml-1",children:W("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(_e,{value:String(l.timePerQuestionSec),onValueChange:t=>w(o=>({...o,timePerQuestionSec:Number(t)})),children:[e.jsx(Se,{className:u("rounded-xl h-11 border-white/20 bg-white/60 dark:bg-black/50 dark:border-white/10 transition-colors shadow-inner",l.mode==="online"?"hover:border-[#8A3FD3]/50":"hover:border-[#1FA7E1]/50",W("timePerQuestionSec")&&"border-rose-400"),children:e.jsx(Ae,{})}),e.jsx(Ce,{className:"rounded-xl backdrop-blur-xl bg-white/90 dark:bg-[#1a1f2e]/90",children:[15,20,30,45,60,90].map(t=>e.jsxs(J,{value:String(t),className:"rounded-lg",children:[t," sec"]},t))})]}),W("timePerQuestionSec")&&e.jsx("p",{className:"text-xs text-destructive dark:text-rose-300 ml-1",children:W("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(A,{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(as,{value:U,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:ee?e.jsx(fa,{className:"h-5 w-5"}):e.jsx(ga,{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(ta,{checked:ee,onCheckedChange:Pt})]}),e.jsxs(y.div,{initial:!1,animate:{opacity:ee?1:.45,y:ee?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(he*100),"%"]})]}),e.jsx("input",{type:"range",min:0,max:100,step:1,value:Math.round(he*100),disabled:!ee,onChange:t=>{const o=Ze(Number(t.target.value)/100,0,1);Ca(o)},onMouseUp:()=>D("tick"),onTouchEnd:()=>D("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:[k.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:k.message}),l.mode==="online"&&l.queueType==="private_room"&&m?.roomCode&&e.jsxs(A,{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",E===m.roomCode&&"scale-105 bg-emerald-200 dark:bg-emerald-500/30"),onClick:()=>void Vt(m.roomCode),"aria-label":`Copy room code ${m.roomCode}`,children:[E===m.roomCode?e.jsx(kt,{className:"h-4 w-4"}):e.jsx(sa,{className:"h-4 w-4"}),m.roomCode]}),(j||Kt)&&ae>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(ae)]})]}),k.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:k.message}),k.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(Je,{className:"h-4 w-4 animate-spin"})," Validating..."]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[Oa&&e.jsx(A,{type:"button",variant:"outline",onClick:Zt,disabled:k.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(A,{type:"button",onClick:Ha,disabled:k.status==="validating"||j||Kt,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:k.status==="validating"?e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx(Je,{className:"h-5 w-5 animate-spin"})," Starting..."]}):l.mode==="online"&&l.queueType==="private_room"?U.trim()?"Join Room":"Create Room":"Start Battle"})]})]})]})]})})]},"setup")}),e.jsx(ze,{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(te,{className:u(H,"rounded-[18px]"),children:[e.jsxs(ie,{children:[e.jsxs(de,{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(Pe,{className:"h-4 w-4 text-primary dark:text-[#9e8fff]"}):e.jsx(ve,{className:"h-4 w-4 text-primary dark:text-[#9e8fff]"}),"vs ",r.opponentName]}),e.jsxs("div",{className:"inline-flex items-center gap-2",children:[gt,e.jsxs("span",{className:"text-sm font-bold tabular-nums",children:[r.scoreFor," - ",r.scoreAgainst]})]})]}),e.jsx(pe,{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}${M?" (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(we,{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(ae)})," if the synchronized start does not happen."]}),e.jsx(A,{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"]}),M?" (paused)":""]}),M&&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(A,{type:"button",variant:ye===o?"default":"outline",onClick:()=>X(o),disabled:G||Z||M,className:u("h-auto min-h-[48px] justify-start text-left font-medium px-4 py-3 rounded-xl whitespace-normal",ye===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(A,{type:"button",onClick:()=>void Ue(ye),disabled:G||Z||M,className:"rounded-xl",children:M?e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx(ds,{className:"h-4 w-4"})," Paused for design"]}):G?e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx(Je,{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(A,{type:"button",variant:"outline",onClick:()=>{_(null),v(null),h(!1),d("setup")},className:"rounded-xl",children:"Start New Match"}),r.mode==="bot"&&e.jsx(A,{type:"button",onClick:()=>void Xt(),disabled:G,className:"rounded-xl",children:"Rematch"})]})]})]})]}):m?e.jsxs(te,{className:u(H,"rounded-[18px]"),children:[e.jsxs(ie,{children:[e.jsxs(de,{className:"text-base flex items-center gap-2",children:[e.jsx(ve,{className:"h-4 w-4 text-primary dark:text-[#9e8fff]"}),"Private Room Lobby"]}),e.jsxs(pe,{className:"text-muted-foreground dark:text-[#b2bad0]",children:["Room ",m.roomCode," · ",m.participantCount,"/2 students connected."]})]}),e.jsx(we,{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(A,{type:"button",variant:"outline",className:"h-8 rounded-lg",onClick:Zt,disabled:k.status==="validating",children:"Cancel room"}),e.jsxs(A,{type:"button",variant:"outline",className:"h-8 rounded-lg",onClick:()=>void Vt(m.roomCode),children:[E===m.roomCode?e.jsx(kt,{className:"h-4 w-4"}):e.jsx(sa,{className:"h-4 w-4"}),E===m.roomCode?"Copied":"Copy code"]})]})]})})]}):j?e.jsx(te,{className:u(H,"rounded-[18px]"),children:e.jsxs(ie,{children:[e.jsxs(de,{className:"text-base flex items-center gap-2",children:[e.jsx(ve,{className:"h-4 w-4 text-primary dark:text-[#9e8fff]"}),"Public Matchmaking"]}),e.jsx(pe,{className:"text-muted-foreground dark:text-[#b2bad0]",children:"Searching for a student with the same setup..."})]})}):e.jsx(te,{className:u(H,"rounded-[18px]"),children:e.jsxs(ie,{children:[e.jsxs(de,{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(pe,{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(ze,{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:u(H,"relative overflow-hidden rounded-[24px] mb-6 border-emerald-500/20 shadow-[0_0_40px_-10px_rgba(16,185,129,0.2)]"),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/20 via-teal-500/10 to-emerald-600/5 dark:from-emerald-500/20 dark:via-teal-500/10 dark:to-teal-900/10"}),e.jsx("div",{className:"pointer-events-none absolute -top-24 -right-24 h-64 w-64 rounded-full bg-emerald-400/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-400/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(A,{variant:"ghost",onClick:()=>d("hub"),className:"h-12 w-12 p-0 rounded-full bg-white/50 dark:bg-black/40 hover:bg-white/80 dark:hover:bg-black/60 hover:scale-105 transition-all backdrop-blur-md border border-emerald-500/30 shadow-[0_0_15px_rgba(16,185,129,0.2)] shrink-0",children:e.jsx(Ye,{className:"h-6 w-6 rotate-180 text-emerald-800 dark: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-transparent bg-clip-text bg-gradient-to-br from-emerald-600 to-teal-500 dark:from-emerald-300 dark:to-teal-200 drop-shadow-sm",children:[e.jsx("div",{className:"bg-emerald-100 dark:bg-emerald-900/50 p-2 rounded-2xl shadow-inner border border-emerald-200 dark:border-emerald-700/50 animate-icon-rotate",children:e.jsx(aa,{className:"h-8 w-8 text-emerald-600 dark:text-emerald-400 drop-shadow-[0_0_8px_rgba(16,185,129,0.5)]"})}),"Matches History"]}),e.jsx("p",{className:"text-sm font-bold text-emerald-800/80 dark:text-emerald-100/70 mt-2 tracking-wide uppercase",children:"Review your past duels and track your progress."})]})]})})]}),e.jsxs(te,{className:u(H,"rounded-[18px]"),children:[e.jsxs(ie,{children:[e.jsx(de,{className:"text-base",children:"Match History"}),e.jsx(pe,{className:"text-muted-foreground dark:text-[#b2bad0]",children:"Your recent student battles only."})]}),e.jsxs(we,{className:"space-y-3",children:[e.jsx("div",{className:"flex gap-2",children:[{value:"all",label:"All"},{value:"online",label:"Online"},{value:"bot",label:"Bot"}].map(t=>e.jsx(A,{type:"button",variant:je===t.value?"default":"outline",onClick:()=>za(t.value),className:"rounded-xl h-8 px-3",children:t.label},t.value))}),Qt?e.jsxs("div",{className:"space-y-2",children:[e.jsx(ge,{className:"h-12 w-full rounded-xl bg-muted dark:bg-[#2a3143]"}),e.jsx(ge,{className:"h-12 w-full rounded-xl bg-muted dark:bg-[#2a3143]"})]}):Ve.length===0?e.jsx("p",{className:"text-sm text-muted-foreground dark:text-[#a8b2c9]",children:"No matches in this filter yet."}):Ve.map(t=>e.jsxs("div",{className:"rounded-xl border border-border bg-muted/40 px-3 py-2 flex items-center justify-between gap-3 dark:border-[#2f3547] dark:bg-[#11151d]",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"text-sm font-semibold text-foreground dark:text-[#f5f7fb]",children:["vs ",t.opponentName]}),e.jsxs("p",{className:"text-xs text-muted-foreground dark:text-[#95a0bb] tabular-nums",children:[t.scoreFor,"-",t.scoreAgainst," · ",t.accuracy.toFixed(0),"% · +",t.xpEarned," XP"]})]}),e.jsx("span",{className:u("text-xs font-semibold rounded-full px-2.5 py-1 border",t.outcome==="win"?"text-emerald-700 border-emerald-200 bg-emerald-50 dark:text-emerald-300 dark:border-emerald-300/40 dark:bg-emerald-900/20":t.outcome==="loss"?"text-rose-700 border-rose-200 bg-rose-50 dark:text-rose-300 dark:border-rose-300/40 dark:bg-rose-900/20":"text-amber-700 border-amber-200 bg-amber-50 dark:text-amber-300 dark:border-amber-300/40 dark:bg-amber-900/20"),children:Ps(t.outcome)})]},t.matchId))]})]})]},"history")}),e.jsx(ze,{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:u(H,"relative overflow-hidden rounded-[24px] mb-6 border-indigo-500/20 shadow-[0_0_40px_-10px_rgba(99,102,241,0.2)]"),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/20 via-purple-500/10 to-indigo-600/5 dark:from-indigo-500/20 dark:via-purple-500/10 dark:to-purple-900/10"}),e.jsx("div",{className:"pointer-events-none absolute -top-24 -right-24 h-64 w-64 rounded-full bg-indigo-400/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-400/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(A,{variant:"ghost",onClick:()=>d("hub"),className:"h-12 w-12 p-0 rounded-full bg-white/50 dark:bg-black/40 hover:bg-white/80 dark:hover:bg-black/60 hover:scale-105 transition-all backdrop-blur-md border border-indigo-500/30 shadow-[0_0_15px_rgba(99,102,241,0.2)] shrink-0",children:e.jsx(Ye,{className:"h-6 w-6 rotate-180 text-indigo-800 dark: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-transparent bg-clip-text bg-gradient-to-br from-indigo-600 to-purple-500 dark:from-indigo-300 dark:to-purple-200 drop-shadow-sm",children:[e.jsx("div",{className:"bg-indigo-100 dark:bg-indigo-900/50 p-2 rounded-2xl shadow-inner border border-indigo-200 dark:border-indigo-700/50 animate-icon-bob",children:e.jsx(Ct,{className:"h-8 w-8 text-indigo-600 dark:text-indigo-400 drop-shadow-[0_0_8px_rgba(99,102,241,0.5)]"})}),"My Statistics"]}),e.jsx("p",{className:"text-sm font-bold text-indigo-800/80 dark:text-indigo-100/70 mt-2 tracking-wide uppercase",children:"Analyzing your battlefield performance."})]})]})})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-4 gap-4",children:[{label:"Wins",value:se?.wins??0,icon:jt},{label:"Current streak",value:se?.currentStreak??0,icon:et},{label:"Avg accuracy",value:`${(se?.averageAccuracy||0).toFixed(1)}%`,icon:os},{label:"Avg response",value:Ts(se?.averageResponseMs||0),icon:ra}].map(t=>e.jsx(te,{className:u(H,"rounded-[18px]"),children:e.jsxs(we,{className:"pt-6",children:[e.jsx("p",{className:"text-xs text-muted-foreground dark:text-[#9da7bf]",children:t.label}),e.jsx("p",{className:"mt-1 tabular-nums text-2xl font-black text-foreground dark:text-[#f5f7fb]",children:t.value}),e.jsx(t.icon,{className:"mt-3 h-4 w-4 text-primary dark:text-[#9e8fff]"})]})},t.label))})]},"stats")}),e.jsx(ze,{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:u(H,"relative overflow-hidden rounded-[24px] mb-6 border-amber-500/20 shadow-[0_0_40px_-10px_rgba(245,158,11,0.2)]"),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/20 via-orange-500/10 to-amber-600/5 dark:from-amber-600/20 dark:via-orange-500/10 dark:to-orange-900/10"}),e.jsx("div",{className:"pointer-events-none absolute -top-24 -right-24 h-64 w-64 rounded-full bg-amber-400/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-400/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(A,{variant:"ghost",onClick:()=>d("hub"),className:"h-12 w-12 p-0 rounded-full bg-white/50 dark:bg-black/40 hover:bg-white/80 dark:hover:bg-black/60 hover:scale-105 transition-all backdrop-blur-md border border-amber-500/30 shadow-[0_0_15px_rgba(245,158,11,0.2)] shrink-0",children:e.jsx(Ye,{className:"h-6 w-6 rotate-180 text-amber-800 dark: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-transparent bg-clip-text bg-gradient-to-br from-amber-600 to-orange-500 dark:from-amber-300 dark:to-orange-200 drop-shadow-sm",children:[e.jsx(y.div,{animate:{scale:[1,1.1,1]},transition:{duration:2,repeat:1/0,ease:"easeInOut"},className:"bg-amber-100 dark:bg-amber-900/50 p-2 rounded-2xl shadow-inner border border-amber-200 dark:border-amber-700/50",children:e.jsx(jt,{className:"h-8 w-8 text-amber-600 dark:text-amber-400 drop-shadow-[0_0_12px_rgba(245,158,11,0.6)]"})}),"Hall of Fame"]}),e.jsx("p",{className:"text-sm font-bold text-amber-800/80 dark:text-amber-100/70 mt-2 tracking-wide uppercase",children:"The top-ranked minds across the globe."})]})]})})]}),e.jsxs(te,{className:u(H,"rounded-[18px]"),children:[e.jsxs(ie,{children:[e.jsxs(de,{className:"text-base flex items-center gap-2",children:[e.jsx(Xa,{className:"h-4 w-4 text-primary dark:text-[#9e8fff]"})," Hall of Fame"]}),e.jsx(pe,{className:"text-muted-foreground dark:text-[#b2bad0]",children:"Student-only ranking using trusted backend aggregates."})]}),e.jsx(we,{children:Ia?e.jsxs("div",{className:"space-y-2",children:[e.jsx(ge,{className:"h-12 w-full rounded-xl bg-muted dark:bg-[#2a3143]"}),e.jsx(ge,{className:"h-12 w-full rounded-xl bg-muted dark:bg-[#2a3143]"}),e.jsx(ge,{className:"h-12 w-full rounded-xl bg-muted dark:bg-[#2a3143]"})]}):Yt.length===0?e.jsx("p",{className:"text-sm text-muted-foreground dark:text-[#a9b3ca]",children:"No leaderboard entries yet. Finish a battle to place on the board."}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-2",children:[e.jsxs("div",{className:"rounded-xl border border-border bg-muted/30 p-2.5 dark:border-[#2f3547] dark:bg-[#11151d]",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wide text-muted-foreground dark:text-[#98a2bc]",children:"Name display"}),e.jsxs(_e,{value:qe,onValueChange:t=>Ma(t),children:[e.jsx(Se,{className:"mt-1 h-8 rounded-lg",children:e.jsx(Ae,{})}),e.jsxs(Ce,{children:[e.jsx(J,{value:"alias",children:"Alias"}),e.jsx(J,{value:"initials",children:"Initials"}),e.jsx(J,{value:"full",children:"Full name"})]})]})]}),e.jsxs("label",{className:"rounded-xl border border-border bg-muted/30 p-2.5 flex items-center justify-between gap-3 dark:border-[#2f3547] dark:bg-[#11151d]",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wide text-muted-foreground dark:text-[#98a2bc]",children:"Score detail"}),e.jsx("p",{className:"text-xs text-muted-foreground dark:text-[#98a2bc]",children:"Show exact score values"})]}),e.jsx(ta,{checked:ct,onCheckedChange:Fa})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground dark:text-[#95a0bb]",children:"Privacy mode keeps classmate identities and scores obfuscated by default while preserving your own exact rank and score."}),Yt.map(t=>e.jsxs("div",{className:u("rounded-xl border bg-muted/30 px-3 py-2 flex items-center justify-between dark:bg-[#11151d]",t.isSelf?"border-primary/60 dark:border-[#8d7fff]":"border-border dark:border-[#2f3547]"),children:[e.jsxs("div",{children:[e.jsxs("p",{className:"text-sm font-semibold text-foreground dark:text-[#f5f7fb]",children:["#",t.rank," ",t.displayName,t.isSelf?" (You)":""]}),e.jsxs("p",{className:"text-xs text-muted-foreground dark:text-[#95a0bb]",children:["Win rate ",t.winRate.toFixed(1),"% · Best streak ",t.bestStreak]})]}),e.jsx("p",{className:"tabular-nums text-sm font-semibold text-foreground dark:text-[#f5f7fb]",children:t.scoreLabel})]},t.userId))]})})]})]},"leaderboard")})]})})})})]})};export{mr as default}; diff --git a/assets/RewardsModal-CPyFRkMy.js b/assets/RewardsModal-kuski-56.js similarity index 86% rename from assets/RewardsModal-CPyFRkMy.js rename to assets/RewardsModal-kuski-56.js index 3f79103ac4c71fe5bc83150b53257cb507844dee..5b981d9072d74eca7bdd650cf8c6a1c22986a0f5 100644 --- a/assets/RewardsModal-CPyFRkMy.js +++ b/assets/RewardsModal-kuski-56.js @@ -1 +1 @@ -import{r as d,j as e}from"./vendor-react-B4AQeu28.js";import{getDoc as F,doc as S}from"./vendor-firebase-firestore-CH1lNiRF.js";import{aI as u,A as j,aJ as U,aK as P,U as B,z as I,aL as $,r as R,aM as L,T as g,aN as M,W as N,R as T,S as q,P as X,O as w,X as v,B as G,Z as H,y as W,x as Z,G as J,a as K,aC as O,f as Q}from"./index-BaOs5Ayg.js";import{X as V}from"./x-TNvtuOD9.js";import"./vendor-firebase-core-CO26nNq6.js";import"./vendor-firebase-auth-BLpRW_zO.js";import"./vendor-firebase-storage-B3igpVVS.js";import"./vendor-firebase-analytics-CTiUNb0-.js";import"./vendor-radix-BorKzPz9.js";import"./vendor-charts-D8hf8tI0.js";import"./vendor-markdown-yqZQ_iQm.js";const Y={BookOpen:K,GraduationCap:J,Trophy:Z,Target:W,Zap:H,Brain:G,Star:v,Flame:w,Swords:X,Shield:q,RefreshCw:T,Crown:N,Sun:M,TrendingUp:g,Globe:L,User:R,UserPlus:$,Calendar:I,Users:B,Compass:P,Heart:U,Award:j},me=({isOpen:o,onClose:c,userLevel:n,currentXP:x,xpToNextLevel:m,totalXP:p,userId:i})=>{const[y,b]=d.useState(!0),[k,_]=d.useState(new Set),[C,E]=d.useState({});d.useEffect(()=>{if(!o||!i)return;(async()=>{b(!0);try{const t=await O(i);_(new Set(t.map(a=>a.id)));const r=await F(S(Q,"progress",i));r.exists()&&E(r.data())}catch(t){console.error("Error loading achievements:",t)}finally{b(!1)}})()},[o,i]);const D=s=>{const{condition:t,threshold:r}=s,a=C;let l=0,f=r??1;switch(t){case"lesson_complete":l=a.totalLessonsCompleted||0;break;case"quiz_complete":l=a.totalQuizzesCompleted||0;break;case"battle_win":case"battle_undefeated":l=a.battleWins||0;break;case"mastery_10":case"social_streak_30":case"social_daily_return":l=a.consecutiveDaysActive||0;break;case"mastery_xp":l=p;break;case"explore_friend_added":case"social_friend":case"explore_social":l=a.friendsAdded||0;break;case"perfect_score":{l=(a.quizAttempts||[]).filter(A=>A.score===100).length;break}default:return}return{progress:Math.min(l,f),total:f}},h=u.map(s=>{const t=Y[s.icon.name]??j,r=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:r,color:r?s.iconColor:"text-slate-500",bgColor:r?s.iconColor.replace("text-","bg-").replace("-500","/10").replace("-400","/10").replace("-600","/10"):"bg-slate-100"}}),z=h.filter(s=>s.unlocked).length;return o?e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center 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-[85vh] flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"bg-gradient-to-r from-[#9956DE] via-[#7274ED] to-[#1FA7E1] 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-2xl font-display font-bold",children:"Rewards & Achievements"}),e.jsxs("p",{className:"text-white/90 text-sm font-body",children:[z," / ",u.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(V,{size:24})})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3 relative z-10",children:[e.jsxs("div",{className:"bg-white/15 backdrop-blur-sm rounded-xl p-4 border border-white/25",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(N,{size:18,className:"text-[#FFB356]"}),e.jsx("span",{className:"text-xs font-medium text-white/90 font-body",children:"Level"})]}),e.jsx("p",{className:"text-2xl font-bold",children:n})]}),e.jsxs("div",{className:"bg-white/15 backdrop-blur-sm rounded-xl p-4 border border-white/25",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(v,{size:18,className:"text-[#6ED1CF]"}),e.jsx("span",{className:"text-xs font-medium text-white/90 font-body",children:"Total XP"})]}),e.jsx("p",{className:"text-2xl font-bold",children:p.toLocaleString()})]}),e.jsxs("div",{className:"bg-white/15 backdrop-blur-sm rounded-xl p-4 border border-white/25",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(w,{size:18,className:"text-[#FF8B8B]"}),e.jsx("span",{className:"text-xs font-medium text-white/90 font-body",children:"Daily Rewards"})]}),e.jsx("p",{className:"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-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-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(g,{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-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 d,j as e}from"./vendor-react-B4AQeu28.js";import{getDoc as F,doc as S}from"./vendor-firebase-firestore-CP9q7ISf.js";import{aJ as u,A as j,aK as U,aL as P,U as $,D as B,aM as I,y as R,aN as q,T as g,aO as L,Y as N,R as M,S as T,V as G,Q as w,$ as v,B as H,Z as X,q as Q,z as V,G as Z,a as J,aD as K,h as O}from"./index-uASBzalf.js";import{X as W}from"./x-CBb03rh3.js";import"./vendor-firebase-core-DCQrgkxC.js";import"./vendor-firebase-auth-Bcpr4O6E.js";import"./vendor-firebase-storage-dc5X5yTv.js";import"./vendor-firebase-analytics-CHPyhRzk.js";import"./vendor-radix-xDOIcVzp.js";import"./vendor-charts-Ckgeb0nY.js";import"./vendor-markdown-yqZQ_iQm.js";const Y={BookOpen:J,GraduationCap:Z,Trophy:V,Target:Q,Zap:X,Brain:H,Star:v,Flame:w,Swords:G,Shield:T,RefreshCw:M,Crown:N,Sun:L,TrendingUp:g,Globe:q,User:R,UserPlus:I,Calendar:B,Users:$,Compass:P,Heart:U,Award:j},me=({isOpen:o,onClose:c,userLevel:n,currentXP:x,xpToNextLevel:m,totalXP:p,userId:i})=>{const[y,b]=d.useState(!0),[k,_]=d.useState(new Set),[E,C]=d.useState({});d.useEffect(()=>{if(!o||!i)return;(async()=>{b(!0);try{const t=await K(i);_(new Set(t.map(a=>a.id)));const r=await F(S(O,"progress",i));r.exists()&&C(r.data())}catch(t){console.error("Error loading achievements:",t)}finally{b(!1)}})()},[o,i]);const D=s=>{const{condition:t,threshold:r}=s,a=E;let l=0,f=r??1;switch(t){case"lesson_complete":l=a.totalLessonsCompleted||0;break;case"quiz_complete":l=a.totalQuizzesCompleted||0;break;case"battle_win":case"battle_undefeated":l=a.battleWins||0;break;case"mastery_10":case"social_streak_30":case"social_daily_return":l=a.consecutiveDaysActive||0;break;case"mastery_xp":l=p;break;case"explore_friend_added":case"social_friend":case"explore_social":l=a.friendsAdded||0;break;case"perfect_score":{l=(a.quizAttempts||[]).filter(A=>A.score===100).length;break}default:return}return{progress:Math.min(l,f),total:f}},h=u.map(s=>{const t=Y[s.icon.name]??j,r=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:r,color:r?s.iconColor:"text-slate-500",bgColor:r?s.iconColor.replace("text-","bg-").replace("-500","/10").replace("-400","/10").replace("-600","/10"):"bg-slate-100"}}),z=h.filter(s=>s.unlocked).length;return o?e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center 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-[85vh] flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"bg-gradient-to-r from-[#9956DE] via-[#7274ED] to-[#1FA7E1] 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-2xl font-display font-bold",children:"Rewards & Achievements"}),e.jsxs("p",{className:"text-white/90 text-sm font-body",children:[z," / ",u.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(W,{size:24})})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3 relative z-10",children:[e.jsxs("div",{className:"bg-white/15 backdrop-blur-sm rounded-xl p-4 border border-white/25",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(N,{size:18,className:"text-[#FFB356]"}),e.jsx("span",{className:"text-xs font-medium text-white/90 font-body",children:"Level"})]}),e.jsx("p",{className:"text-2xl font-bold",children:n})]}),e.jsxs("div",{className:"bg-white/15 backdrop-blur-sm rounded-xl p-4 border border-white/25",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(v,{size:18,className:"text-[#6ED1CF]"}),e.jsx("span",{className:"text-xs font-medium text-white/90 font-body",children:"Total XP"})]}),e.jsx("p",{className:"text-2xl font-bold",children:p.toLocaleString()})]}),e.jsxs("div",{className:"bg-white/15 backdrop-blur-sm rounded-xl p-4 border border-white/25",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(w,{size:18,className:"text-[#FF8B8B]"}),e.jsx("span",{className:"text-xs font-medium text-white/90 font-body",children:"Daily Rewards"})]}),e.jsx("p",{className:"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-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-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(g,{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-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-CmYzVUKQ.js b/assets/RightSidebar-CmYzVUKQ.js deleted file mode 100644 index f210c82d273333f64ab1ae0e635e30b655fed416..0000000000000000000000000000000000000000 --- a/assets/RightSidebar-CmYzVUKQ.js +++ /dev/null @@ -1 +0,0 @@ -import{r as l,j as e}from"./vendor-react-B4AQeu28.js";import{q as S}from"./quiz_battle_avatar-BXHPSput.js";import{j as B,m as c,Z as _,P,V as q,x as W,W as v,X,l as Y,r as k}from"./index-BaOs5Ayg.js";import{C as M}from"./circle-check-big-m1SvzGFL.js";import{T as O,a as Z,b as H}from"./tooltip-ChRIOid3.js";import{C as T}from"./chevron-right-COqGruhh.js";import"./vendor-firebase-firestore-CH1lNiRF.js";import"./vendor-firebase-core-CO26nNq6.js";import"./vendor-firebase-auth-BLpRW_zO.js";import"./vendor-firebase-storage-B3igpVVS.js";import"./vendor-firebase-analytics-CTiUNb0-.js";import"./vendor-radix-BorKzPz9.js";import"./vendor-charts-D8hf8tI0.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(P,{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]=l.useState(0);l.useEffect(()=>{const r=setInterval(()=>{m(o=>(o+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(B,{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}`},V=({entry:s,rank:a,isYou:x,userPhoto:m,rankColor:t})=>{const r=x?s?.photo||m:s?.photo,o=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:o,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:o}),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:o,currentXP:h,xpToNextLevel:f})=>{const N=h/f*100,[$,D]=l.useState([]),[F,u]=l.useState(!0),[y,g]=l.useState(null),p=l.useRef(null),n=l.useRef(null);l.useEffect(()=>{if(!s){u(!1);return}u(!0),g(null);const d=q(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]"],j=(d,b,C,R,w)=>e.jsxs("div",{className:"flex flex-col items-center relative z-10",children:[e.jsx(V,{entry:d,rank:C,isYou:R==="You",userPhoto:o,rankColor:z[w]}),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[w].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:`${w===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:o})}),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:[j(i[1],1,2,i[1]?.name||"---",1),j(i[0],0,1,i[0]?.name||"---",0),j(i[2],2,3,i[2]?.name||"---",2)]})})]})]})};export{ce as default}; diff --git a/assets/RightSidebar-u-5bXOuZ.js b/assets/RightSidebar-u-5bXOuZ.js new file mode 100644 index 0000000000000000000000000000000000000000..80827ef9f90d7062251deb219157f92d81a4312d --- /dev/null +++ b/assets/RightSidebar-u-5bXOuZ.js @@ -0,0 +1 @@ +import{r as o,j as e}from"./vendor-react-B4AQeu28.js";import{q as S}from"./quiz_battle_avatar-BXHPSput.js";import{g as B,m as c,Z as _,V as q,X as P,z as W,Y as v,$ as X,p as Y,y as k}from"./index-uASBzalf.js";import{C as M}from"./circle-check-big-BNRlH5pv.js";import{T as O,a as Z,b as H}from"./tooltip-1ASn-3cE.js";import{C as T}from"./chevron-right-U0AqPOPj.js";import"./vendor-firebase-firestore-CP9q7ISf.js";import"./vendor-firebase-core-DCQrgkxC.js";import"./vendor-firebase-auth-Bcpr4O6E.js";import"./vendor-firebase-storage-dc5X5yTv.js";import"./vendor-firebase-analytics-CHPyhRzk.js";import"./vendor-radix-xDOIcVzp.js";import"./vendor-charts-Ckgeb0nY.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(q,{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(B,{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}`},V=({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(V,{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-DRuSfTXj.js b/assets/ScientificCalculator-DNPhV2R9.js similarity index 97% rename from assets/ScientificCalculator-DRuSfTXj.js rename to assets/ScientificCalculator-DNPhV2R9.js index 49ec7e4983172fef51db8c50523103ef035acfae..998216c40a87e7de61f57b451ac1bf65bd4c3630 100644 --- a/assets/ScientificCalculator-DRuSfTXj.js +++ b/assets/ScientificCalculator-DNPhV2R9.js @@ -1,4 +1,4 @@ -import{r as c,j as e}from"./vendor-react-B4AQeu28.js";import{e as Z,h as de,j as U,m as ue}from"./index-BaOs5Ayg.js";import{C as fe,a as pe}from"./chevron-up-Cdvz2TMJ.js";import{X as be}from"./x-TNvtuOD9.js";import"./vendor-firebase-firestore-CH1lNiRF.js";import"./vendor-firebase-core-CO26nNq6.js";import"./vendor-firebase-auth-BLpRW_zO.js";import"./vendor-firebase-storage-B3igpVVS.js";import"./vendor-firebase-analytics-CTiUNb0-.js";import"./vendor-radix-BorKzPz9.js";import"./vendor-charts-D8hf8tI0.js";import"./vendor-markdown-yqZQ_iQm.js";/** +import{r as c,j as e}from"./vendor-react-B4AQeu28.js";import{e as Z,j as de,g as U,m as ue}from"./index-uASBzalf.js";import{a as fe,C as pe}from"./chevron-up-BpMhRyJp.js";import{X as be}from"./x-CBb03rh3.js";import"./vendor-firebase-firestore-CP9q7ISf.js";import"./vendor-firebase-core-DCQrgkxC.js";import"./vendor-firebase-auth-Bcpr4O6E.js";import"./vendor-firebase-storage-dc5X5yTv.js";import"./vendor-firebase-analytics-CHPyhRzk.js";import"./vendor-radix-xDOIcVzp.js";import"./vendor-charts-Ckgeb0nY.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-BbkSqdYG.js b/assets/SettingsModal-BbkSqdYG.js deleted file mode 100644 index 68b97312b1f97b6c194e8bef66daafb284f86f42..0000000000000000000000000000000000000000 --- a/assets/SettingsModal-BbkSqdYG.js +++ /dev/null @@ -1,16 +0,0 @@ -import{r as a,j as e}from"./vendor-react-B4AQeu28.js";import{S as Se,a as Ae,b as Pe,c as Ee,d as J}from"./select-DIjxRWza.js";import{e as K,u as ze,aP as Re,aQ as Te,aR as Me,aS as Le,aT as qe,aU as De,r as Ie,S as Fe,aM as Ve,a as Oe,j as _e,m as V,L as He,aV as Ge,t as u,aW as Ue,aX as Xe,aY as Qe}from"./index-BaOs5Ayg.js";import{B as p}from"./button-DCfeFHoH.js";import{I as n}from"./input-D28h_UTJ.js";import{S as d}from"./switch-CblAJO7o.js";import me from"./ConfirmModal-6cgkqXAT.js";import{P as We,M as Be,V as Ye}from"./ProfilePictureUploader-CX_IZAwE.js";import{B as Je}from"./bell-clcSMJn6.js";import{D as he}from"./download-DX_YebqQ.js";import{X as ue}from"./x-TNvtuOD9.js";import{C as $e}from"./circle-help-B8apTIdU.js";import{C as Ke}from"./clock-D1Ecvltm.js";import{T as Ze}from"./trash-2-HTnKafZd.js";import{E as es,a as ss}from"./eye-Ig3S6mOs.js";import"./vendor-radix-BorKzPz9.js";import"./chevron-up-Cdvz2TMJ.js";import"./check-BLSo9L0H.js";import"./vendor-firebase-firestore-CH1lNiRF.js";import"./vendor-firebase-core-CO26nNq6.js";import"./vendor-firebase-auth-BLpRW_zO.js";import"./vendor-firebase-storage-B3igpVVS.js";import"./vendor-firebase-analytics-CTiUNb0-.js";import"./vendor-charts-D8hf8tI0.js";import"./vendor-markdown-yqZQ_iQm.js";import"./log-out-BenDMDly.js";import"./minus-DfrEv-SC.js";import"./plus-DkG35AoH.js";import"./upload-DayXhGwD.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 ts=[["circle",{cx:"13.5",cy:"6.5",r:".5",fill:"currentColor",key:"1okk4w"}],["circle",{cx:"17.5",cy:"10.5",r:".5",fill:"currentColor",key:"f64h9f"}],["circle",{cx:"8.5",cy:"7.5",r:".5",fill:"currentColor",key:"fotxhn"}],["circle",{cx:"6.5",cy:"12.5",r:".5",fill:"currentColor",key:"qy21gx"}],["path",{d:"M12 2C6.5 2 2 6.5 2 12s4.5 10 10 10c.926 0 1.648-.746 1.648-1.688 0-.437-.18-.835-.437-1.125-.29-.289-.438-.652-.438-1.125a1.64 1.64 0 0 1 1.668-1.668h1.996c3.051 0 5.555-2.503 5.555-5.554C21.965 6.012 17.461 2 12 2z",key:"12rzf8"}]],as=K("palette",ts);/** - * @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 ns=[["rect",{width:"20",height:"8",x:"2",y:"2",rx:"2",ry:"2",key:"ngkwjq"}],["rect",{width:"20",height:"8",x:"2",y:"14",rx:"2",ry:"2",key:"iecqi9"}],["line",{x1:"6",x2:"6.01",y1:"6",y2:"6",key:"16zg32"}],["line",{x1:"6",x2:"6.01",y1:"18",y2:"18",key:"nzw8ys"}]],is=K("server",ns);/** - * @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 ls=[["rect",{width:"14",height:"20",x:"5",y:"2",rx:"2",ry:"2",key:"1yt0o3"}],["path",{d:"M12 18h.01",key:"mhygvu"}]],rs=K("smartphone",ls),cs=()=>{const{userProfile:x,userRole:j}=ze(),[l,P]=a.useState(Re),[E,z]=a.useState(Te),[k,R]=a.useState(!1),[L,S]=a.useState(null);a.useEffect(()=>{if(!x?.uid)return;(async()=>{R(!0),S(null);try{if(j==="teacher"){const h=await qe(x.uid);P(h)}if(j==="admin"){const h=await De();z(h)}}catch(h){S(h instanceof Error?h.message:"Failed to load settings")}finally{R(!1)}})()},[x?.uid,j]);const r=a.useCallback(async w=>{if(!x?.uid)return;const h=await Me(x.uid,w);P(h)},[x?.uid]),T=a.useCallback(async w=>{const h=await Le(w);z(h)},[]);return{teacherPrefs:l,adminConfig:E,loading:k,error:L,saveTeacherPrefs:r,saveAdminConfig:T}},$=()=>JSON.parse(JSON.stringify(Ge)),Vs=({isOpen:x,onClose:j,profileData:l,onSave:P,settingsData:E,onSaveSettings:z,onApplySettingsPreview:k,onExportData:R,onClearCache:L,onResetData:S})=>{const r=l?.role||"student",{teacherPrefs:T,adminConfig:w,saveTeacherPrefs:h,saveAdminConfig:be}=cs(),[f,fe]=a.useState("account"),[o,m]=a.useState({}),[i,Z]=a.useState($()),[y,g]=a.useState(T),[v,N]=a.useState(w),[O,ee]=a.useState(!1),[q,se]=a.useState(!1),[_,te]=a.useState(!1),[H,ae]=a.useState(!1),[ne,os]=a.useState(!1),[pe,D]=a.useState(!1),[je,I]=a.useState(!1),[ye,A]=a.useState(!1),[M,ie]=a.useState(""),[b,ge]=a.useState(null),[C,le]=a.useState(!1),[G,re]=a.useState(!1),[U,ce]=a.useState(""),[F,oe]=a.useState(""),X=a.useRef(!1),Q=a.useRef($());a.useEffect(()=>{if(!x){X.current=!1;return}if(X.current)return;X.current=!0;const s=E?JSON.parse(JSON.stringify(E)):$();Q.current=s,m({uid:l?.uid,name:l?.name||"",email:l?.email||"",phone:l?.phone||"",photo:l?.photo||"",avatarLayers:l?.avatarLayers,role:l?.role,gender:l?.gender,lrn:l?.lrn||"",grade:l?.grade||"",section:l?.section||"",school:l?.school||"",department:l?.department||"",subject:l?.subject||"",yearsOfExperience:l?.yearsOfExperience||"",qualification:l?.qualification||"",position:l?.position||""}),Z(s),g(T),N(w)},[x,l,E,T,w]),a.useEffect(()=>{x&&k?.(i)},[x,i,k]),a.useEffect(()=>{if(!x)return;const s=t=>{t.key==="Escape"&&(k?.(Q.current),j())};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[x,j,k]);const de=a.useMemo(()=>{const s=[{id:"account",label:"Account",icon:Ie},{id:"notifications",label:"Notifications",icon:Je},{id:"appearance",label:"Appearance",icon:as},{id:"privacy",label:"Privacy & Security",icon:Fe}];return r==="student"&&s.push({id:"learning",label:"Learning",icon:Ve}),r==="teacher"&&s.push({id:"teaching",label:"Teaching",icon:Oe}),r==="admin"&&s.push({id:"system",label:"System",icon:is}),s.push({id:"data",label:"Data & Storage",icon:he}),s},[r]),c=s=>{Z(t=>s(t))},W=s=>{ge(s),ie(""),re(!1),s==="password"&&ce(""),s==="email"&&oe(o.email||""),A(!0)},xe=async()=>{if(!M.trim()){u.error("Current password is required");return}le(!0);try{if(b==="password"){if(U.length<8){u.error("New password must be at least 8 characters");return}await Ue(M,U),u.success("Password updated")}else if(b==="email"){if(!F.includes("@")){u.error("Enter a valid email");return}await Xe(M,F),m(s=>({...s,email:F})),u.success("Email updated")}else if(b==="delete"){await Qe(M,o.uid||""),u.success("Account deleted"),j();return}A(!1)}catch(s){u.error(s instanceof Error?s.message:"Authentication failed")}finally{le(!1)}},ve=async()=>{ee(!0);try{P&&await P(o),z&&await z(i),r==="teacher"&&await h(y),r==="admin"&&await be(v),j()}catch(s){u.error(s instanceof Error?s.message:"Failed to save settings")}finally{ee(!1)}},B=()=>{A(!1),D(!1),I(!1),k?.(Q.current),j()},Ne=async()=>{if(!(!R||_)){te(!0);try{await R()}catch(s){u.error(s instanceof Error?s.message:"Failed to export data")}finally{te(!1)}}},we=async()=>{if(!(!L||H)){ae(!0);try{await L()}catch(s){u.error(s instanceof Error?s.message:"Failed to clear cache")}finally{ae(!1)}}},Ce=async()=>{if(!(!S||q)){D(!1),se(!0);try{await S(),u.success("Testing data reset completed")}catch(s){u.error(s instanceof Error?s.message:"Failed to reset testing data")}finally{se(!1)}}},ke=()=>{I(!1),W("delete")};return x?e.jsx(_e,{children:e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"fixed inset-0 z-[100] flex items-center justify-center p-4",children:[e.jsx(V.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},onClick:B,className:"absolute inset-0 bg-black/50 backdrop-blur-sm"}),e.jsxs(V.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-2xl shadow-2xl border border-[#dde3eb] w-full max-w-4xl max-h-[85vh] overflow-hidden flex",children:[e.jsxs("div",{className:"w-64 bg-slate-50 border-r border-slate-200 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:de.map(s=>{const t=s.icon;return e.jsxs("button",{onClick:()=>fe(s.id),className:`w-full flex items-center gap-3 px-4 py-3 rounded-xl text-left transition-all ${f===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",children:[e.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-[#dde3eb]",children:[e.jsx("h3",{className:"text-lg font-display font-bold text-[#0a1628]",children:de.find(s=>s.id===f)?.label}),e.jsx("button",{onClick:B,className:"p-2 hover:bg-[#edf1f7] rounded-xl transition-colors",children:e.jsx(ue,{size:20,className:"text-[#5a6578]"})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-6",children:[f==="account"&&e.jsxs("div",{className:"space-y-6",children:[e.jsx(We,{uid:o.uid,photoURL:o.photo,displayName:o.name,onUploaded:s=>m(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:o.name||"",onChange:s=>m(t=>({...t,name: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:"Email Address"}),e.jsxs("div",{className:"flex items-center gap-2 max-w-md",children:[e.jsx(n,{type:"email",value:o.email||"",disabled:!0,className:"flex-1 bg-slate-100"}),e.jsx(p,{variant:"outline",size:"sm",onClick:()=>W("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:o.phone||"",onChange:s=>m(t=>({...t,phone: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:"Gender"}),e.jsxs(Se,{value:o.gender||"",onValueChange:s=>m(t=>({...t,gender:s})),children:[e.jsx(Ae,{className:"max-w-md bg-white border-[#dde3eb] rounded-lg",children:e.jsx(Pe,{placeholder:"Select gender (optional)"})}),e.jsxs(Ee,{children:[e.jsx(J,{value:"male",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Be,{className:"size-4 text-blue-500"}),e.jsx("span",{children:"Male"})]})}),e.jsx(J,{value:"female",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ye,{className:"size-4 text-pink-500"}),e.jsx("span",{children:"Female"})]})}),e.jsx(J,{value:"prefer_not_to_say",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($e,{className:"size-4 text-gray-500"}),e.jsx("span",{children:"Prefer not to say"})]})})]})]})]}),r==="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:o.lrn||"",onChange:s=>m(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:o.grade||"",onChange:s=>m(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:o.section||"",onChange:s=>m(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:o.school||"",onChange:s=>m(t=>({...t,school:s.target.value})),className:"max-w-md"})]})]}),r==="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:o.department||"",onChange:s=>m(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:o.subject||"",onChange:s=>m(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:o.yearsOfExperience||"",onChange:s=>m(t=>({...t,yearsOfExperience:s.target.value})),className:"max-w-md"})]})]}),r==="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:o.position||"",onChange:s=>m(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:()=>W("password"),children:[e.jsx(He,{size:16,className:"mr-2"}),"Update Password"]})]})]}),f==="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:"Email Notifications"}),e.jsx("p",{className:"text-xs text-slate-500 mt-1",children:"Receive updates via email"})]}),e.jsx(d,{checked:i.notifications.emailNotifications,onCheckedChange:s=>c(t=>({...t,notifications:{...t.notifications,emailNotifications: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:"Push Notifications"}),e.jsx("p",{className:"text-xs text-slate-500 mt-1",children:"Get notified on your device"})]}),e.jsx(d,{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(d,{checked:i.notifications.soundEnabled,onCheckedChange:s=>c(t=>({...t,notifications:{...t.notifications,soundEnabled:s}}))})]}),r==="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(d,{checked:y.notifyOnSubmission,onCheckedChange:s=>g(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(d,{checked:y.notifyOnStudentActivity,onCheckedChange:s=>g(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(Y=>({...Y,notifications:{...Y.notifications,notificationTypes:{...Y.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.jsxs("label",{className:"text-sm font-bold text-[#5a6578] mb-2 block font-body uppercase tracking-wider text-xs",children:[e.jsx(Ke,{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"})]})]})]}),f==="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(d,{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(d,{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(d,{checked:i.appearance.reduceAnimations,onCheckedChange:s=>c(t=>({...t,appearance:{...t.appearance,reduceAnimations:s}}))})]})]}),f==="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(d,{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(d,{checked:i.privacy.dataSharing,onCheckedChange:s=>c(t=>({...t,privacy:{...t.privacy,dataSharing:s}}))})]})]}),f==="learning"&&r==="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(d,{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(d,{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(rs,{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"})]})]}),f==="teaching"&&r==="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:y.quizDefaults.timeLimitMinutes,onChange:s=>g(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:y.quizDefaults.passingScore,onChange:s=>g(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:y.quizDefaults.maxAttempts,onChange:s=>g(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-b border-[#dde3eb]",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-[#0a1628] font-body",children:"Auto-Enroll Students"}),e.jsx("p",{className:"text-xs text-slate-500 mt-1",children:"Automatically enroll new students"})]}),e.jsx(d,{checked:y.classPreferences.autoEnroll,onCheckedChange:s=>g(t=>({...t,classPreferences:{...t.classPreferences,autoEnroll:s}}))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-[#5a6578] block mb-1",children:"Class Visibility"}),e.jsxs("select",{value:y.classPreferences.classVisibility,onChange:s=>g(t=>({...t,classPreferences:{...t.classPreferences,classVisibility:s.target.value}})),className:"px-3 py-2 border border-[#dde3eb] rounded-lg text-sm bg-white text-[#0a1628]",children:[e.jsx("option",{value:"public",children:"Public"}),e.jsx("option",{value:"private",children:"Private"}),e.jsx("option",{value:"invite_only",children:"Invite Only"})]})]}),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(d,{checked:y.studentAnalyticsVisibility,onCheckedChange:s=>g(t=>({...t,studentAnalyticsVisibility:s}))})]})]}),f==="system"&&r==="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(d,{checked:v.maintenanceMode,onCheckedChange:s=>N(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:v.defaultGradeLevel,onChange:s=>N(t=>({...t,defaultGradeLevel:s.target.value}))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-[#5a6578] block mb-1",children:"Default Curriculum"}),e.jsx(n,{value:v.defaultCurriculum,onChange:s=>N(t=>({...t,defaultCurriculum:s.target.value}))})]}),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:v.maxClassSize,onChange:s=>N(t=>({...t,maxClassSize:Number(s.target.value)}))})]})]}),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(d,{checked:v.auditLogVisible,onCheckedChange:s=>N(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:v.aiConfig.modelName,onChange:s=>N(t=>({...t,aiConfig:{...t.aiConfig,modelName:s.target.value}}))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-[#5a6578] block mb-1",children:"Temperature"}),e.jsx(n,{type:"number",step:"0.1",min:"0",max:"2",value:v.aiConfig.temperature,onChange:s=>N(t=>({...t,aiConfig:{...t.aiConfig,temperature:Number(s.target.value)}}))})]}),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:v.aiConfig.endpoint,onChange:s=>N(t=>({...t,aiConfig:{...t.aiConfig,endpoint:s.target.value}}))})]})]})]}),f==="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:Ne,disabled:_,children:[e.jsx(he,{size:16,className:"mr-2"}),_?"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:we,disabled:H,children:H?"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:[r==="student"&&"Reset quizzes, diagnostic state, XP, and learning progress for retesting.",r==="teacher"&&"Reset imported records, managed classrooms, and teacher-generated quiz artifacts.",r==="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:!S||q,onClick:()=>D(!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:()=>I(!0),disabled:ne,children:[e.jsx(Ze,{size:16,className:"mr-2"}),ne?"Deleting...":"Delete Account"]})]})]})]}),e.jsxs("div",{className:"p-6 border-t border-[#dde3eb] bg-[#edf1f7] flex items-center justify-between",children:[e.jsx("p",{className:"text-xs text-slate-500 font-body",children:"MathPulse AI v2.1.0"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(p,{variant:"outline",onClick:B,className:"rounded-lg border-[#dde3eb]",disabled:O,children:"Cancel"}),e.jsx(p,{onClick:ve,className:"rounded-lg bg-sky-600 hover:bg-sky-700 text-white",disabled:O,children:O?"Saving...":"Save Changes"})]})]})]})]})]}),ye&&e.jsx(V.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:()=>{C||A(!1)},children:e.jsxs(V.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:[b==="password"&&"Change Password",b==="email"&&"Change Email",b==="delete"&&"Delete Account"]}),e.jsx("button",{onClick:()=>{C||A(!1)},className:"p-2 rounded-xl hover:bg-[#edf1f7] transition-colors","aria-label":"Close",children:e.jsx(ue,{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:G?"text":"password",value:M,onChange:s=>ie(s.target.value),placeholder:"Current password",autoFocus:!0,className:"pr-10",disabled:C,onKeyDown:s=>{s.key==="Enter"&&xe()}}),e.jsx("button",{type:"button",onClick:()=>re(!G),className:"absolute right-3 top-1/2 -translate-y-1/2 text-slate-400 hover:text-slate-600",tabIndex:-1,children:G?e.jsx(es,{size:16}):e.jsx(ss,{size:16})})]}),b==="password"&&e.jsx("div",{className:"relative",children:e.jsx(n,{type:"password",value:U,onChange:s=>ce(s.target.value),placeholder:"New password (min 8 chars)",disabled:C})}),b==="email"&&e.jsx(n,{type:"email",value:F,onChange:s=>oe(s.target.value),placeholder:"New email address",disabled:C}),b==="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:()=>A(!1),disabled:C,children:"Cancel"}),e.jsx(p,{onClick:()=>void xe(),className:b==="delete"?"bg-red-600 hover:bg-red-700 text-white":"bg-sky-600 hover:bg-sky-700 text-white",disabled:C,children:C?"Processing...":b==="delete"?"Delete Forever":"Confirm"})]})]})]})}),e.jsx(me,{isOpen:pe,onClose:()=>D(!1),onConfirm:Ce,title:"Reset Testing Data?",message:`Reset ${r} 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(me,{isOpen:je,onClose:()=>I(!1),onConfirm:ke,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{Vs as default}; diff --git a/assets/SettingsModal-tD3B9SgO.js b/assets/SettingsModal-tD3B9SgO.js new file mode 100644 index 0000000000000000000000000000000000000000..d6e62c52f6e2b6509b7fc1d002c546035894e516 --- /dev/null +++ b/assets/SettingsModal-tD3B9SgO.js @@ -0,0 +1,17 @@ +const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-uASBzalf.js","assets/vendor-react-B4AQeu28.js","assets/vendor-firebase-firestore-CP9q7ISf.js","assets/vendor-firebase-core-DCQrgkxC.js","assets/vendor-firebase-auth-Bcpr4O6E.js","assets/vendor-firebase-storage-dc5X5yTv.js","assets/vendor-firebase-analytics-CHPyhRzk.js","assets/vendor-radix-xDOIcVzp.js","assets/vendor-charts-Ckgeb0nY.js","assets/vendor-markdown-yqZQ_iQm.js","assets/vendor-markdown-CfVKi3_s.css","assets/index-D9pRNq5G.css"])))=>i.map(i=>d[i]); +import{e as se,l as Te,aQ as Le,aR as Me,aS as _e,aT as De,aU as qe,aV as Ie,y as Fe,S as Ve,aN as Oe,a as Ge,g as He,m as V,L as Ue,_ as fe,n as x,aW as Qe,aX as Xe,aY as Be,aZ as We}from"./index-uASBzalf.js";import{r as a,j as e}from"./vendor-react-B4AQeu28.js";import{S as Ye,a as $e,b as Je,c as Ke,d as Z}from"./select--QYuvUGV.js";import{B as f}from"./button-BPmLcOpC.js";import{I as n}from"./input--XHWlmp1.js";import{S as d}from"./switch-CZbBlSot.js";import pe from"./ConfirmModal-D2z4s_BB.js";import{P as Ze,M as es,V as ss}from"./ProfilePictureUploader-CyCaD4jN.js";import{B as ye}from"./bell-CiUaN6S3.js";import{D as je}from"./download-CVrPjUr0.js";import{X as ge}from"./x-CBb03rh3.js";import{C as ts}from"./circle-help-PS1uII8x.js";import{C as as}from"./clock-8t0UYgg3.js";import{T as ns}from"./trash-2-D7q6y9vT.js";import{E as is,a as ls}from"./eye-DIwMshM-.js";import"./vendor-firebase-firestore-CP9q7ISf.js";import"./vendor-firebase-core-DCQrgkxC.js";import"./vendor-firebase-auth-Bcpr4O6E.js";import"./vendor-firebase-storage-dc5X5yTv.js";import"./vendor-firebase-analytics-CHPyhRzk.js";import"./vendor-radix-xDOIcVzp.js";import"./vendor-charts-Ckgeb0nY.js";import"./vendor-markdown-yqZQ_iQm.js";import"./chevron-up-BpMhRyJp.js";import"./check-Dk6iwDFI.js";import"./log-out-Dr0BHRO4.js";import"./minus-Bfei9C79.js";import"./plus-Cy6hz5PP.js";import"./upload-Ds5w3QNw.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 rs=[["circle",{cx:"13.5",cy:"6.5",r:".5",fill:"currentColor",key:"1okk4w"}],["circle",{cx:"17.5",cy:"10.5",r:".5",fill:"currentColor",key:"f64h9f"}],["circle",{cx:"8.5",cy:"7.5",r:".5",fill:"currentColor",key:"fotxhn"}],["circle",{cx:"6.5",cy:"12.5",r:".5",fill:"currentColor",key:"qy21gx"}],["path",{d:"M12 2C6.5 2 2 6.5 2 12s4.5 10 10 10c.926 0 1.648-.746 1.648-1.688 0-.437-.18-.835-.437-1.125-.29-.289-.438-.652-.438-1.125a1.64 1.64 0 0 1 1.668-1.668h1.996c3.051 0 5.555-2.503 5.555-5.554C21.965 6.012 17.461 2 12 2z",key:"12rzf8"}]],cs=se("palette",rs);/** + * @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 os=[["rect",{width:"20",height:"8",x:"2",y:"2",rx:"2",ry:"2",key:"ngkwjq"}],["rect",{width:"20",height:"8",x:"2",y:"14",rx:"2",ry:"2",key:"iecqi9"}],["line",{x1:"6",x2:"6.01",y1:"6",y2:"6",key:"16zg32"}],["line",{x1:"6",x2:"6.01",y1:"18",y2:"18",key:"nzw8ys"}]],ds=se("server",os);/** + * @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 xs=[["rect",{width:"14",height:"20",x:"5",y:"2",rx:"2",ry:"2",key:"1yt0o3"}],["path",{d:"M12 18h.01",key:"mhygvu"}]],ms=se("smartphone",xs),hs=()=>{const{userProfile:m,userRole:y}=Te(),[l,E]=a.useState(Le),[z,R]=a.useState(Me),[C,T]=a.useState(!1),[_,S]=a.useState(null);a.useEffect(()=>{if(!m?.uid)return;(async()=>{T(!0),S(null);try{if(y==="teacher"){const u=await qe(m.uid);E(u)}if(y==="admin"){const u=await Ie();R(u)}}catch(u){S(u instanceof Error?u.message:"Failed to load settings")}finally{T(!1)}})()},[m?.uid,y]);const c=a.useCallback(async k=>{if(!m?.uid)return;const u=await _e(m.uid,k);E(u)},[m?.uid]),L=a.useCallback(async k=>{const u=await De(k);R(u)},[]);return{teacherPrefs:l,adminConfig:z,loading:C,error:_,saveTeacherPrefs:c,saveAdminConfig:L}},ee=()=>JSON.parse(JSON.stringify(Qe)),Us=({isOpen:m,onClose:y,profileData:l,onSave:E,settingsData:z,onSaveSettings:R,onApplySettingsPreview:C,onExportData:T,onClearCache:_,onResetData:S})=>{const c=l?.role||"student",{teacherPrefs:L,adminConfig:k,saveTeacherPrefs:u,saveAdminConfig:ve}=hs(),[p,Ne]=a.useState("account"),[o,h]=a.useState({}),[i,te]=a.useState(ee()),[j,g]=a.useState(L),[v,N]=a.useState(k),[O,ae]=a.useState(!1),[D,ne]=a.useState(!1),[G,ie]=a.useState(!1),[H,le]=a.useState(!1),[re,us]=a.useState(!1),[ke,q]=a.useState(!1),[we,I]=a.useState(!1),[Ce,P]=a.useState(!1),[M,ce]=a.useState(""),[b,Se]=a.useState(null),[w,oe]=a.useState(!1),[U,de]=a.useState(!1),[Q,xe]=a.useState(""),[F,me]=a.useState(""),X=a.useRef(!1),B=a.useRef(ee());a.useEffect(()=>{if(!m){X.current=!1;return}if(X.current)return;X.current=!0;const s=z?JSON.parse(JSON.stringify(z)):ee();B.current=s,h({uid:l?.uid,name:l?.name||"",email:l?.email||"",phone:l?.phone||"",photo:l?.photo||"",avatarLayers:l?.avatarLayers,role:l?.role,gender:l?.gender,lrn:l?.lrn||"",grade:l?.grade||"",section:l?.section||"",school:l?.school||"",department:l?.department||"",subject:l?.subject||"",yearsOfExperience:l?.yearsOfExperience||"",qualification:l?.qualification||"",position:l?.position||""}),te(s),g(L),N(k)},[m,l,z,L,k]),a.useEffect(()=>{m&&C?.(i)},[m,i,C]),a.useEffect(()=>{if(!m)return;const s=t=>{t.key==="Escape"&&(C?.(B.current),y())};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[m,y,C]);const he=a.useMemo(()=>{const s=[{id:"account",label:"Account",icon:Fe},{id:"notifications",label:"Notifications",icon:ye},{id:"appearance",label:"Appearance",icon:cs},{id:"privacy",label:"Privacy & Security",icon:Ve}];return c==="student"&&s.push({id:"learning",label:"Learning",icon:Oe}),c==="teacher"&&s.push({id:"teaching",label:"Teaching",icon:Ge}),c==="admin"&&s.push({id:"system",label:"System",icon:ds}),s.push({id:"data",label:"Data & Storage",icon:je}),s},[c]),r=s=>{te(t=>s(t))},W=s=>{Se(s),ce(""),de(!1),s==="password"&&xe(""),s==="email"&&me(o.email||""),P(!0)},ue=async()=>{if(!M.trim()){x.error("Current password is required");return}oe(!0);try{if(b==="password"){if(Q.length<8){x.error("New password must be at least 8 characters");return}await Xe(M,Q),x.success("Password updated")}else if(b==="email"){if(!F.includes("@")){x.error("Enter a valid email");return}await Be(M,F),h(s=>({...s,email:F})),x.success("Email updated")}else if(b==="delete"){await We(M,o.uid||""),x.success("Account deleted"),y();return}P(!1)}catch(s){x.error(s instanceof Error?s.message:"Authentication failed")}finally{oe(!1)}},Pe=async()=>{ae(!0);try{E&&await E(o),R&&await R(i),c==="teacher"&&await u(j),c==="admin"&&await ve(v),y()}catch(s){x.error(s instanceof Error?s.message:"Failed to save settings")}finally{ae(!1)}},Y=()=>{P(!1),q(!1),I(!1),C?.(B.current),y()},Ae=async()=>{if(!(!T||G)){ie(!0);try{await T()}catch(s){x.error(s instanceof Error?s.message:"Failed to export data")}finally{ie(!1)}}},Ee=async()=>{if(!(!_||H)){le(!0);try{await _()}catch(s){x.error(s instanceof Error?s.message:"Failed to clear cache")}finally{le(!1)}}},ze=async()=>{if(!(!S||D)){q(!1),ne(!0);try{await S(),x.success("Testing data reset completed")}catch(s){x.error(s instanceof Error?s.message:"Failed to reset testing data")}finally{ne(!1)}}},Re=()=>{I(!1),W("delete")};return m?e.jsx(He,{children:e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"fixed inset-0 z-[100] flex items-center justify-center p-4",children:[e.jsx(V.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},onClick:Y,className:"absolute inset-0 bg-black/50 backdrop-blur-sm"}),e.jsxs(V.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-2xl shadow-2xl border border-[#dde3eb] w-full max-w-4xl max-h-[85vh] overflow-hidden flex",children:[e.jsxs("div",{className:"w-64 bg-slate-50 border-r border-slate-200 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:he.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 ${p===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",children:[e.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-[#dde3eb]",children:[e.jsx("h3",{className:"text-lg font-display font-bold text-[#0a1628]",children:he.find(s=>s.id===p)?.label}),e.jsx("button",{onClick:Y,className:"p-2 hover:bg-[#edf1f7] rounded-xl transition-colors",children:e.jsx(ge,{size:20,className:"text-[#5a6578]"})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-6",children:[p==="account"&&e.jsxs("div",{className:"space-y-6",children:[e.jsx(Ze,{uid:o.uid,photoURL:o.photo,displayName:o.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:o.name||"",onChange:s=>h(t=>({...t,name: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:"Email Address"}),e.jsxs("div",{className:"flex items-center gap-2 max-w-md",children:[e.jsx(n,{type:"email",value:o.email||"",disabled:!0,className:"flex-1 bg-slate-100"}),e.jsx(f,{variant:"outline",size:"sm",onClick:()=>W("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:o.phone||"",onChange:s=>h(t=>({...t,phone: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:"Gender"}),e.jsxs(Ye,{value:o.gender||"",onValueChange:s=>h(t=>({...t,gender:s})),children:[e.jsx($e,{className:"max-w-md bg-white border-[#dde3eb] rounded-lg",children:e.jsx(Je,{placeholder:"Select gender (optional)"})}),e.jsxs(Ke,{children:[e.jsx(Z,{value:"male",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(es,{className:"size-4 text-blue-500"}),e.jsx("span",{children:"Male"})]})}),e.jsx(Z,{value:"female",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ss,{className:"size-4 text-pink-500"}),e.jsx("span",{children:"Female"})]})}),e.jsx(Z,{value:"prefer_not_to_say",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ts,{className:"size-4 text-gray-500"}),e.jsx("span",{children:"Prefer not to say"})]})})]})]})]}),c==="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:o.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:o.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:o.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:o.school||"",onChange:s=>h(t=>({...t,school:s.target.value})),className:"max-w-md"})]})]}),c==="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:o.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:o.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:o.yearsOfExperience||"",onChange:s=>h(t=>({...t,yearsOfExperience:s.target.value})),className:"max-w-md"})]})]}),c==="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:o.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(f,{variant:"outline",className:"rounded-xl",onClick:()=>W("password"),children:[e.jsx(Ue,{size:16,className:"mr-2"}),"Update Password"]})]})]}),p==="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:"Email Notifications"}),e.jsx("p",{className:"text-xs text-slate-500 mt-1",children:"Receive updates via email"})]}),e.jsx(d,{checked:i.notifications.emailNotifications,onCheckedChange:s=>r(t=>({...t,notifications:{...t.notifications,emailNotifications: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:"Push Notifications"}),e.jsx("p",{className:"text-xs text-slate-500 mt-1",children:"Get notified on your device"})]}),e.jsx(d,{checked:i.notifications.pushNotifications,onCheckedChange:s=>r(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(d,{checked:i.notifications.soundEnabled,onCheckedChange:s=>r(t=>({...t,notifications:{...t.notifications,soundEnabled:s}}))})]}),c==="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(d,{checked:j.notifyOnSubmission,onCheckedChange:s=>g(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(d,{checked:j.notifyOnStudentActivity,onCheckedChange:s=>g(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=>r(A=>({...A,notifications:{...A.notifications,notificationTypes:{...A.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(d,{checked:i.pushPreferences.pushEnabled,onCheckedChange:s=>r(t=>({...t,pushPreferences:{...t.pushPreferences,pushEnabled:s}}))})]}),e.jsx("div",{className:"space-y-2",children:[{key:"achievement",label:"🏆 Achievements unlocked"},{key:"quiz_battle",label:"⚔️ Quiz battle invites & results"},{key:"daily_reward",label:"🎁 Daily reward reminders"},{key:"assignment",label:"📚 New assignments / deadlines"},{key:"grade_posted",label:"📝 Grades posted"},{key:"streak_reminder",label:"🔥 Streak reminders"},{key:"leaderboard",label:"📊 Leaderboard updates"},{key:"system",label:"🔔 System announcements"}].map(s=>{const t=s.key;return e.jsxs("label",{className:"flex items-center justify-between py-1.5",children:[e.jsx("span",{className:"text-sm text-[#0a1628] font-body",children:s.label}),e.jsx(d,{checked:!!i.pushPreferences[t],onCheckedChange:A=>r($=>({...$,pushPreferences:{...$.pushPreferences,[s.key]:A}})),disabled:!i.pushPreferences.pushEnabled&&t!=="pushEnabled"})]},s.key)})}),e.jsx("div",{className:"mt-4",children:e.jsxs(f,{type:"button",variant:"outline",size:"sm",onClick:async()=>{try{const{httpsCallable:s}=await fe(async()=>{const{httpsCallable:J}=await import("./vendor-firebase-core-DCQrgkxC.js").then(K=>K.a9);return{httpsCallable:J}},[]),{cloudFunctions:t}=await fe(async()=>{const{cloudFunctions:J}=await import("./index-uASBzalf.js").then(K=>K.b2);return{cloudFunctions:J}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11])),be=(await s(t,"sendTestPush")({}))?.data?.sent??0;be>0?x.success(`Sent test push to ${be} device(s).`):x.message("No active devices found. Enable browser notifications first.")}catch(s){x.error(s instanceof Error?s.message:"Failed to send test push")}},children:[e.jsx(ye,{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(as,{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=>r(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=>r(t=>({...t,notifications:{...t.notifications,quietHours:{...t.notifications.quietHours,end:s.target.value}}})),className:"w-32"})]})]})]}),p==="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(d,{checked:i.appearance.darkMode,onCheckedChange:s=>r(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=>r(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(d,{checked:i.appearance.compactView,onCheckedChange:s=>r(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(d,{checked:i.appearance.reduceAnimations,onCheckedChange:s=>r(t=>({...t,appearance:{...t.appearance,reduceAnimations:s}}))})]})]}),p==="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=>r(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(d,{checked:i.privacy.showActivityStatus,onCheckedChange:s=>r(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(d,{checked:i.privacy.dataSharing,onCheckedChange:s=>r(t=>({...t,privacy:{...t.privacy,dataSharing:s}}))})]})]}),p==="learning"&&c==="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=>r(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=>r(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(d,{checked:i.learning.autoPlayLessons,onCheckedChange:s=>r(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(d,{checked:i.learning.showHints,onCheckedChange:s=>r(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=>r(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(ms,{size:16,className:"inline mr-2"}),"Study Reminders"]}),e.jsx(n,{type:"time",value:i.learning.studyReminderTime,onChange:s=>r(t=>({...t,learning:{...t.learning,studyReminderTime:s.target.value}})),className:"w-32"})]})]}),p==="teaching"&&c==="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:j.quizDefaults.timeLimitMinutes,onChange:s=>g(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:j.quizDefaults.passingScore,onChange:s=>g(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:j.quizDefaults.maxAttempts,onChange:s=>g(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-b border-[#dde3eb]",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-[#0a1628] font-body",children:"Auto-Enroll Students"}),e.jsx("p",{className:"text-xs text-slate-500 mt-1",children:"Automatically enroll new students"})]}),e.jsx(d,{checked:j.classPreferences.autoEnroll,onCheckedChange:s=>g(t=>({...t,classPreferences:{...t.classPreferences,autoEnroll:s}}))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-[#5a6578] block mb-1",children:"Class Visibility"}),e.jsxs("select",{value:j.classPreferences.classVisibility,onChange:s=>g(t=>({...t,classPreferences:{...t.classPreferences,classVisibility:s.target.value}})),className:"px-3 py-2 border border-[#dde3eb] rounded-lg text-sm bg-white text-[#0a1628]",children:[e.jsx("option",{value:"public",children:"Public"}),e.jsx("option",{value:"private",children:"Private"}),e.jsx("option",{value:"invite_only",children:"Invite Only"})]})]}),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(d,{checked:j.studentAnalyticsVisibility,onCheckedChange:s=>g(t=>({...t,studentAnalyticsVisibility:s}))})]})]}),p==="system"&&c==="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(d,{checked:v.maintenanceMode,onCheckedChange:s=>N(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:v.defaultGradeLevel,onChange:s=>N(t=>({...t,defaultGradeLevel:s.target.value}))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-[#5a6578] block mb-1",children:"Default Curriculum"}),e.jsx(n,{value:v.defaultCurriculum,onChange:s=>N(t=>({...t,defaultCurriculum:s.target.value}))})]}),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:v.maxClassSize,onChange:s=>N(t=>({...t,maxClassSize:Number(s.target.value)}))})]})]}),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(d,{checked:v.auditLogVisible,onCheckedChange:s=>N(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:v.aiConfig.modelName,onChange:s=>N(t=>({...t,aiConfig:{...t.aiConfig,modelName:s.target.value}}))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-[#5a6578] block mb-1",children:"Temperature"}),e.jsx(n,{type:"number",step:"0.1",min:"0",max:"2",value:v.aiConfig.temperature,onChange:s=>N(t=>({...t,aiConfig:{...t.aiConfig,temperature:Number(s.target.value)}}))})]}),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:v.aiConfig.endpoint,onChange:s=>N(t=>({...t,aiConfig:{...t.aiConfig,endpoint:s.target.value}}))})]})]})]}),p==="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(f,{variant:"outline",size:"sm",className:"rounded-xl",onClick:Ae,disabled:G,children:[e.jsx(je,{size:16,className:"mr-2"}),G?"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(f,{variant:"outline",size:"sm",className:"rounded-xl",onClick:Ee,disabled:H,children:H?"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:[c==="student"&&"Reset quizzes, diagnostic state, XP, and learning progress for retesting.",c==="teacher"&&"Reset imported records, managed classrooms, and teacher-generated quiz artifacts.",c==="admin"&&"Reset admin testing artifacts like personal audit/content update records."]}),e.jsx(f,{variant:"outline",size:"sm",className:"rounded-xl text-rose-700 border-rose-300",disabled:!S||D,onClick:()=>q(!0),children:D?"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(f,{variant:"outline",size:"sm",className:"rounded-xl text-red-700 border-red-300",onClick:()=>I(!0),disabled:re,children:[e.jsx(ns,{size:16,className:"mr-2"}),re?"Deleting...":"Delete Account"]})]})]})]}),e.jsxs("div",{className:"p-6 border-t border-[#dde3eb] bg-[#edf1f7] flex items-center justify-between",children:[e.jsx("p",{className:"text-xs text-slate-500 font-body",children:"MathPulse AI v2.1.0"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(f,{variant:"outline",onClick:Y,className:"rounded-lg border-[#dde3eb]",disabled:O,children:"Cancel"}),e.jsx(f,{onClick:Pe,className:"rounded-lg bg-sky-600 hover:bg-sky-700 text-white",disabled:O,children:O?"Saving...":"Save Changes"})]})]})]})]})]}),Ce&&e.jsx(V.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:()=>{w||P(!1)},children:e.jsxs(V.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:[b==="password"&&"Change Password",b==="email"&&"Change Email",b==="delete"&&"Delete Account"]}),e.jsx("button",{onClick:()=>{w||P(!1)},className:"p-2 rounded-xl hover:bg-[#edf1f7] transition-colors","aria-label":"Close",children:e.jsx(ge,{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:U?"text":"password",value:M,onChange:s=>ce(s.target.value),placeholder:"Current password",autoFocus:!0,className:"pr-10",disabled:w,onKeyDown:s=>{s.key==="Enter"&&ue()}}),e.jsx("button",{type:"button",onClick:()=>de(!U),className:"absolute right-3 top-1/2 -translate-y-1/2 text-slate-400 hover:text-slate-600",tabIndex:-1,children:U?e.jsx(is,{size:16}):e.jsx(ls,{size:16})})]}),b==="password"&&e.jsx("div",{className:"relative",children:e.jsx(n,{type:"password",value:Q,onChange:s=>xe(s.target.value),placeholder:"New password (min 8 chars)",disabled:w})}),b==="email"&&e.jsx(n,{type:"email",value:F,onChange:s=>me(s.target.value),placeholder:"New email address",disabled:w}),b==="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(f,{variant:"outline",onClick:()=>P(!1),disabled:w,children:"Cancel"}),e.jsx(f,{onClick:()=>void ue(),className:b==="delete"?"bg-red-600 hover:bg-red-700 text-white":"bg-sky-600 hover:bg-sky-700 text-white",disabled:w,children:w?"Processing...":b==="delete"?"Delete Forever":"Confirm"})]})]})]})}),e.jsx(pe,{isOpen:ke,onClose:()=>q(!1),onConfirm:ze,title:"Reset Testing Data?",message:`Reset ${c} testing data? This will clear quizzes, diagnostic assessments, assessment history, XP, and learning progress. This action cannot be undone.`,confirmText:D?"Resetting...":"Reset Data",cancelText:"Cancel",type:"warning",icon:"warning",zIndexClass:"z-[130]"}),e.jsx(pe,{isOpen:we,onClose:()=>I(!1),onConfirm:Re,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{Us as default}; diff --git a/assets/Sidebar-2LZAqf7E.js b/assets/Sidebar-BxInp2XA.js similarity index 68% rename from assets/Sidebar-2LZAqf7E.js rename to assets/Sidebar-BxInp2XA.js index e5302d42cb4839e4b0158469b9b096a2c6ea09c9..61d28378c20b88a5f171265956d680d34b200cfc 100644 --- a/assets/Sidebar-2LZAqf7E.js +++ b/assets/Sidebar-BxInp2XA.js @@ -1,6 +1,6 @@ -import{r as p,j as e}from"./vendor-react-B4AQeu28.js";import{S as N,a as $,L as u,M as P}from"./LogoutActionButton-lUNItet6.js";import{e as D,m as c,i as G,U as S,G as M,a as f,S as U,P as _,x as q}from"./index-BaOs5Ayg.js";import{T as L,a as C,b as A}from"./tooltip-ChRIOid3.js";import{X as F}from"./x-TNvtuOD9.js";import{C as Q}from"./chevron-right-COqGruhh.js";import{C as W}from"./chevron-left-BWpgclqc.js";import{C as z}from"./chart-column-B3jJOD5i.js";import{S as X}from"./shirt-S3NBuaPm.js";import"./log-out-BenDMDly.js";import"./vendor-firebase-firestore-CH1lNiRF.js";import"./vendor-firebase-core-CO26nNq6.js";import"./vendor-firebase-auth-BLpRW_zO.js";import"./vendor-firebase-storage-B3igpVVS.js";import"./vendor-firebase-analytics-CTiUNb0-.js";import"./vendor-radix-BorKzPz9.js";import"./vendor-charts-D8hf8tI0.js";import"./vendor-markdown-yqZQ_iQm.js";/** +import{r as p,j as e}from"./vendor-react-B4AQeu28.js";import{S as N,a as $,L as u,M as D}from"./LogoutActionButton-Dl6IiDHd.js";import{e as G,m as c,k as P,U as S,G as M,a as f,S as U,V as _,z as q}from"./index-uASBzalf.js";import{T as L,a as C,b as z}from"./tooltip-1ASn-3cE.js";import{X as F}from"./x-CBb03rh3.js";import{C as Q}from"./chevron-right-U0AqPOPj.js";import{C as W}from"./chevron-left-CzSo_K0d.js";import{C as A}from"./chart-column-CLoxLorp.js";import{S as V}from"./shirt-DFJQeZbT.js";import"./log-out-Dr0BHRO4.js";import"./vendor-firebase-firestore-CP9q7ISf.js";import"./vendor-firebase-core-DCQrgkxC.js";import"./vendor-firebase-auth-Bcpr4O6E.js";import"./vendor-firebase-storage-dc5X5yTv.js";import"./vendor-firebase-analytics-CHPyhRzk.js";import"./vendor-radix-xDOIcVzp.js";import"./vendor-charts-Ckgeb0nY.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 J=[["rect",{width:"16",height:"16",x:"4",y:"4",rx:"2",key:"14l7u7"}],["rect",{width:"6",height:"6",x:"9",y:"9",rx:"1",key:"5aljv4"}],["path",{d:"M15 2v2",key:"13l42r"}],["path",{d:"M15 20v2",key:"15mkzm"}],["path",{d:"M2 15h2",key:"1gxd5l"}],["path",{d:"M2 9h2",key:"1bbxkp"}],["path",{d:"M20 15h2",key:"19e6y8"}],["path",{d:"M20 9h2",key:"19tzq7"}],["path",{d:"M9 2v2",key:"165o2o"}],["path",{d:"M9 20v2",key:"i2bqo8"}]],K=D("cpu",J),me=({activeTab:b,setActiveTab:E,userRole:x="student",onOpenSettings:g,onLogout:y,sidebarCollapsed:i=!1,setSidebarCollapsed:j,mode:T="desktop",onRequestClose:v,forceCollapsed:o=!1})=>{const[I,m]=p.useState(!1),[k,t]=p.useState(null),n=T==="mobile",r=!o&&I,h=typeof g=="function",a=!n&&(o||i&&!r),l=a,H=!n&&!o;p.useEffect(()=>{o&&(m(!1),t(null))},[o]),p.useEffect(()=>{l||t(null)},[l]);const O=x==="admin"?[{label:"Management",items:[{icon:u,label:"Overview"},{icon:S,label:"User Management"},{icon:M,label:"Subjects"},{icon:f,label:"Content"}]},{label:"Insights",items:[{icon:z,label:"Analytics"},{icon:K,label:"AI Monitoring"},{icon:U,label:"Audit Log"},{icon:N,label:"Settings"}]}]:x==="teacher"?[{label:"Teaching",items:[{icon:u,label:"Dashboard"},{icon:S,label:"My Students"},{icon:f,label:"Classes"}]},{label:"Insights",items:[{icon:z,label:"Analytics"}]}]:[{label:"Learn",items:[{icon:u,label:"Dashboard"},{icon:f,label:"Modules"},{icon:P,label:"AI Chat"}]},{label:"Progress",items:[{icon:M,label:"Grades",displayLabel:"Assessment"},{icon:_,label:"Quiz Battle",displayLabel:"Quiz Battle"},{icon:q,label:"Leaderboard",displayLabel:"Leadership Board"}]},{label:"Customization",items:[{icon:X,label:"Avatar Studio",displayLabel:"Avatar Studio"}]}];return e.jsxs(c.aside,{initial:!1,animate:n?{width:280}:{width:a?80:280},transition:{type:"spring",stiffness:360,damping:34},onMouseEnter:()=>H&&i&&m(!0),onMouseLeave:()=>{m(!1),t(null)},className:G("h-full bg-[#f7f9fc] border border-[#dde3eb] shadow-sm flex flex-col",n?"rounded-2xl p-4":"rounded-3xl p-5"),children:[e.jsxs("div",{className:"flex-1 flex flex-col min-h-0",children:[e.jsxs("div",{className:`mb-8 flex items-center ${a?"justify-center":"justify-between"}`,children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("img",{src:"/mathpulse_logo.png",alt:"MathPulse AI",className:"w-12 h-12 object-contain drop-shadow-md flex-shrink-0"}),(!a||r)&&e.jsx("div",{children:e.jsx("h2",{className:"text-base font-bold font-display text-[#0a1628] whitespace-nowrap",children:"MathPulse AI"})})]}),n&&v&&e.jsx("button",{onClick:v,className:"p-2 hover:bg-[#dde3eb] rounded-lg transition-colors text-[#5a6578]","aria-label":"Close navigation",children:e.jsx(F,{size:20})}),!n&&!o&&j&&(!i||r)&&e.jsx(c.button,{whileHover:{scale:1.1},whileTap:{scale:.95},onClick:()=>j(!i),className:"p-2 hover:bg-[#dde3eb] rounded-lg transition-colors text-[#5a6578]","aria-label":i?"Expand sidebar":"Collapse sidebar",title:i?"Expand sidebar":"Collapse sidebar",children:i?e.jsx(Q,{size:20}):e.jsx(W,{size:20})})]}),e.jsx("nav",{className:"flex-1 min-h-0 overflow-y-auto space-y-5 pr-1",children:O.map((d,B)=>e.jsxs("div",{children:[a?e.jsx("div",{className:"px-4 mb-2 flex items-center gap-2",children:e.jsx("div",{className:"flex-1 h-[1px] bg-[#dde3eb]"})}):d.label&&e.jsx("p",{className:"px-4 mb-2 text-[10px] font-bold text-[#5a6578] uppercase tracking-widest",children:d.label}),e.jsx("div",{className:"space-y-1",children:d.items.map(s=>e.jsxs(L,{open:l&&k===s.label,children:[e.jsx(C,{asChild:!0,children:e.jsxs(c.button,{whileHover:{x:2},whileTap:{scale:.98},onMouseEnter:()=>{l&&t(s.label)},onMouseLeave:()=>{t(w=>w===s.label?null:w)},onFocus:()=>t(null),onClick:()=>E(s.label),className:`w-full flex items-center gap-3 px-4 py-3 rounded-2xl cursor-pointer transition-all duration-200 border whitespace-nowrap ${a?"justify-center":""} ${b===s.label?"bg-sky-50 border-sky-200 shadow-sm text-sky-700":"bg-transparent border-transparent text-[#5a6578] hover:bg-[#dde3eb] hover:border-[#dde3eb] hover:text-[#0a1628]"}`,children:[e.jsx(s.icon,{size:18,strokeWidth:b===s.label?2.5:2,className:"flex-shrink-0"}),(!a||r)&&e.jsx("span",{className:"font-body font-bold text-xs",children:s.displayLabel||s.label}),b===s.label&&(!a||r)&&e.jsx(c.div,{layoutId:"sidebar-active-indicator",className:"ml-auto w-2 h-2 rounded-full bg-sky-500",transition:{type:"spring",duration:.4}})]})}),l&&e.jsx(A,{side:"right",sideOffset:16,className:"font-bold text-xs",children:s.displayLabel||s.label})]},s.label))})]},B))})]}),e.jsxs("div",{className:"mt-4 space-y-2 border-t border-[#dde3eb] pt-4",children:[x!=="admin"?e.jsxs(L,{open:l&&k==="Settings",children:[e.jsx(C,{asChild:!0,children:e.jsxs(c.button,{whileHover:{x:2},whileTap:{scale:.98},onMouseEnter:()=>{l&&t("Settings")},onMouseLeave:()=>{t(d=>d==="Settings"?null:d)},onFocus:()=>t(null),className:`w-full flex items-center gap-3 px-4 py-3 rounded-2xl font-bold border transition-all duration-200 whitespace-nowrap ${a?"justify-center":""} ${b==="Settings"?"bg-sky-50 border-sky-200 text-sky-700 shadow-sm":h?"border-transparent text-[#5a6578] hover:bg-[#dde3eb] hover:border-[#dde3eb] hover:text-[#0a1628]":"border-transparent text-[#a0aec0] cursor-not-allowed opacity-60"}`,onClick:h?g:void 0,disabled:!h,"aria-disabled":!h,"aria-label":"Open settings",children:[e.jsx(N,{size:18,strokeWidth:2,className:"flex-shrink-0"}),(!a||r)&&e.jsx("span",{className:"font-body text-xs",children:"Settings"})]})}),l&&e.jsx(A,{side:"right",sideOffset:16,className:"font-bold text-xs",children:"Settings"})]}):null,y&&e.jsx("div",{className:"text-[#5a6578]",children:e.jsx($,{onClick:y,collapsed:a})})]})]})};export{me as default}; + */const X=[["rect",{width:"16",height:"16",x:"4",y:"4",rx:"2",key:"14l7u7"}],["rect",{width:"6",height:"6",x:"9",y:"9",rx:"1",key:"5aljv4"}],["path",{d:"M15 2v2",key:"13l42r"}],["path",{d:"M15 20v2",key:"15mkzm"}],["path",{d:"M2 15h2",key:"1gxd5l"}],["path",{d:"M2 9h2",key:"1bbxkp"}],["path",{d:"M20 15h2",key:"19e6y8"}],["path",{d:"M20 9h2",key:"19tzq7"}],["path",{d:"M9 2v2",key:"165o2o"}],["path",{d:"M9 20v2",key:"i2bqo8"}]],J=G("cpu",X),me=({activeTab:b,setActiveTab:E,userRole:x="student",onOpenSettings:g,onLogout:y,sidebarCollapsed:o=!1,setSidebarCollapsed:j,mode:T="desktop",onRequestClose:v,forceCollapsed:i=!1})=>{const[I,m]=p.useState(!1),[k,t]=p.useState(null),n=T==="mobile",r=!i&&I,h=typeof g=="function",a=!n&&(i||o&&!r),l=a,H=!n&&!i;p.useEffect(()=>{i&&(m(!1),t(null))},[i]),p.useEffect(()=>{l||t(null)},[l]);const O=x==="admin"?[{label:"Management",items:[{icon:u,label:"Overview"},{icon:S,label:"User Management"},{icon:M,label:"Subjects"},{icon:f,label:"Content"}]},{label:"Insights",items:[{icon:A,label:"Analytics"},{icon:J,label:"AI Monitoring"},{icon:U,label:"Audit Log"},{icon:N,label:"Settings"}]}]:x==="teacher"?[{label:"Teaching",items:[{icon:u,label:"Dashboard"},{icon:S,label:"My Students"},{icon:f,label:"Classes"}]},{label:"Insights",items:[{icon:A,label:"Analytics"}]}]:[{label:"Learn",items:[{icon:u,label:"Dashboard"},{icon:f,label:"Modules"},{icon:D,label:"AI Chat"}]},{label:"Progress",items:[{icon:M,label:"Grades",displayLabel:"Assessment"},{icon:_,label:"Quiz Battle",displayLabel:"Quiz Battle"},{icon:q,label:"Leaderboard",displayLabel:"Leadership Board"}]},{label:"Customization",items:[{icon:V,label:"Avatar Studio",displayLabel:"Avatar Studio"}]}];return e.jsxs(c.aside,{initial:!1,animate:n?{width:280}:{width:a?80:280},transition:{type:"spring",stiffness:360,damping:34},onMouseEnter:()=>H&&o&&m(!0),onMouseLeave:()=>{m(!1),t(null)},className:P("h-full bg-[#f7f9fc] border border-[#dde3eb] shadow-sm flex flex-col",n?"rounded-2xl p-4":"rounded-3xl p-5"),children:[e.jsxs("div",{className:"flex-1 flex flex-col min-h-0",children:[e.jsxs("div",{className:`mb-8 flex items-center ${a?"justify-center":"justify-between"}`,children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("img",{src:"/mathpulse_logo.png",alt:"MathPulse AI",className:"w-12 h-12 object-contain drop-shadow-md flex-shrink-0"}),(!a||r)&&e.jsx("div",{children:e.jsx("h2",{className:"text-base font-bold font-display text-[#0a1628] whitespace-nowrap",children:"MathPulse AI"})})]}),n&&v&&e.jsx("button",{onClick:v,className:"p-2 hover:bg-[#dde3eb] rounded-lg transition-colors text-[#5a6578]","aria-label":"Close navigation",children:e.jsx(F,{size:20})}),!n&&!i&&j&&(!o||r)&&e.jsx(c.button,{whileHover:{scale:1.1},whileTap:{scale:.95},onClick:()=>j(!o),className:"p-2 hover:bg-[#dde3eb] rounded-lg transition-colors text-[#5a6578]","aria-label":o?"Expand sidebar":"Collapse sidebar",title:o?"Expand sidebar":"Collapse sidebar",children:o?e.jsx(Q,{size:20}):e.jsx(W,{size:20})})]}),e.jsx("nav",{className:"flex-1 min-h-0 overflow-y-auto space-y-5 pr-1",children:O.map((d,B)=>e.jsxs("div",{children:[a?e.jsx("div",{className:"px-4 mb-2 flex items-center gap-2",children:e.jsx("div",{className:"flex-1 h-[1px] bg-[#dde3eb]"})}):d.label&&e.jsx("p",{className:"px-4 mb-2 text-[10px] font-bold text-[#5a6578] uppercase tracking-widest",children:d.label}),e.jsx("div",{className:"space-y-1",children:d.items.map(s=>e.jsxs(L,{open:l&&k===s.label,children:[e.jsx(C,{asChild:!0,children:e.jsxs(c.button,{whileHover:{x:2},whileTap:{scale:.98},onMouseEnter:()=>{l&&t(s.label)},onMouseLeave:()=>{t(w=>w===s.label?null:w)},onFocus:()=>t(null),onClick:()=>E(s.label),className:`w-full flex items-center gap-3 px-4 py-3 rounded-2xl cursor-pointer transition-all duration-200 border whitespace-nowrap ${a?"justify-center":""} ${b===s.label?"bg-sky-50 border-sky-200 shadow-sm text-sky-700":"bg-transparent border-transparent text-[#5a6578] hover:bg-[#dde3eb] hover:border-[#dde3eb] hover:text-[#0a1628]"}`,children:[e.jsx(s.icon,{size:18,strokeWidth:b===s.label?2.5:2,className:"flex-shrink-0"}),(!a||r)&&e.jsx("span",{className:"font-body font-bold text-xs",children:s.displayLabel||s.label}),b===s.label&&(!a||r)&&e.jsx(c.div,{layoutId:"sidebar-active-indicator",className:"ml-auto w-2 h-2 rounded-full bg-sky-500",transition:{type:"spring",duration:.4}})]})}),l&&e.jsx(z,{side:"right",sideOffset:16,className:"font-bold text-xs",children:s.displayLabel||s.label})]},s.label))})]},B))})]}),e.jsxs("div",{className:"mt-4 space-y-2 border-t border-[#dde3eb] pt-4",children:[x!=="admin"?e.jsxs(L,{open:l&&k==="Settings",children:[e.jsx(C,{asChild:!0,children:e.jsxs(c.button,{whileHover:{x:2},whileTap:{scale:.98},onMouseEnter:()=>{l&&t("Settings")},onMouseLeave:()=>{t(d=>d==="Settings"?null:d)},onFocus:()=>t(null),className:`w-full flex items-center gap-3 px-4 py-3 rounded-2xl font-bold border transition-all duration-200 whitespace-nowrap ${a?"justify-center":""} ${b==="Settings"?"bg-sky-50 border-sky-200 text-sky-700 shadow-sm":h?"border-transparent text-[#5a6578] hover:bg-[#dde3eb] hover:border-[#dde3eb] hover:text-[#0a1628]":"border-transparent text-[#a0aec0] cursor-not-allowed opacity-60"}`,onClick:h?g:void 0,disabled:!h,"aria-disabled":!h,"aria-label":"Open settings",children:[e.jsx(N,{size:18,strokeWidth:2,className:"flex-shrink-0"}),(!a||r)&&e.jsx("span",{className:"font-body text-xs",children:"Settings"})]})}),l&&e.jsx(z,{side:"right",sideOffset:16,className:"font-bold text-xs",children:"Settings"})]}):null,y&&e.jsx("div",{className:"text-[#5a6578]",children:e.jsx($,{onClick:y,collapsed:a})})]})]})};export{me as default}; diff --git a/assets/SupplementalBanner-DFkcXPOZ.js b/assets/SupplementalBanner-B_AwC-uH.js similarity index 89% rename from assets/SupplementalBanner-DFkcXPOZ.js rename to assets/SupplementalBanner-B_AwC-uH.js index b6c3a323aeac7a1ed31cff246f790767a7840ccf..bd528733b4e13acf33efc9c74a70df48de2cba60 100644 --- a/assets/SupplementalBanner-DFkcXPOZ.js +++ b/assets/SupplementalBanner-B_AwC-uH.js @@ -1 +1 @@ -import{j as e,r as j}from"./vendor-react-B4AQeu28.js";import{j as y,m as p,p as h,a as f,T as m,B as x}from"./index-BaOs5Ayg.js";import{X as v}from"./x-TNvtuOD9.js";import{S as w}from"./sparkles-By-vFjpv.js";import{C as g}from"./chevron-right-COqGruhh.js";import"./vendor-firebase-firestore-CH1lNiRF.js";import"./vendor-firebase-core-CO26nNq6.js";import"./vendor-firebase-auth-BLpRW_zO.js";import"./vendor-firebase-storage-B3igpVVS.js";import"./vendor-firebase-analytics-CTiUNb0-.js";import"./vendor-radix-BorKzPz9.js";import"./vendor-charts-D8hf8tI0.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]=j.useState(!1);if(l||i.length===0)return null;const r=()=>{a(!0),n?.()};return e.jsx(y,{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{g as j,m as p,w as h,a as f,T as m,B as x}from"./index-uASBzalf.js";import{X as v}from"./x-CBb03rh3.js";import{S as w}from"./sparkles-DHVr5IP1.js";import{C as g}from"./chevron-right-U0AqPOPj.js";import"./vendor-firebase-firestore-CP9q7ISf.js";import"./vendor-firebase-core-DCQrgkxC.js";import"./vendor-firebase-auth-Bcpr4O6E.js";import"./vendor-firebase-storage-dc5X5yTv.js";import"./vendor-firebase-analytics-CHPyhRzk.js";import"./vendor-radix-xDOIcVzp.js";import"./vendor-charts-Ckgeb0nY.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-BqNTelmK.js b/assets/SupplementalPillCarousel-dQl-2GJp.js similarity index 84% rename from assets/SupplementalPillCarousel-BqNTelmK.js rename to assets/SupplementalPillCarousel-dQl-2GJp.js index c486bc7e7f68eea02b2fcd3080bce57b48525d5f..de6e80b0987b4b4cff3545fd122febb3bc8bfff9 100644 --- a/assets/SupplementalPillCarousel-BqNTelmK.js +++ b/assets/SupplementalPillCarousel-dQl-2GJp.js @@ -1,4 +1,4 @@ -import{r as a,j as e}from"./vendor-react-B4AQeu28.js";import{m as f,p as x}from"./index-BaOs5Ayg.js";import{C as n}from"./chevron-right-COqGruhh.js";import"./vendor-firebase-firestore-CH1lNiRF.js";import"./vendor-firebase-core-CO26nNq6.js";import"./vendor-firebase-auth-BLpRW_zO.js";import"./vendor-firebase-storage-B3igpVVS.js";import"./vendor-firebase-analytics-CTiUNb0-.js";import"./vendor-radix-BorKzPz9.js";import"./vendor-charts-D8hf8tI0.js";import"./vendor-markdown-yqZQ_iQm.js";const o={pillBg:"#E9D5FF",pillText:"#6B21A8",headerText:"#1F2937",arrowBg:"#F3F4F6"},b={functions:"Functions & Graphs",businessmath:"Business Math",logic:"Logic & Reasoning",statistics:"Statistics",probability:"Probability",precalc:"Pre-Calculus",calculus:"Basic Calculus",geometry:"Geometry",trigonometry:"Trigonometry",algebra:"Algebra"};function g(t){const s=t.toLowerCase().trim();return b[s]||t.split(/[-_]/).map(l=>l.charAt(0).toUpperCase()+l.slice(1)).join(" ")}const L=({atRiskSubjects:t=[],onTopicClick:s})=>{const l=a.useRef(null),[c,m]=a.useState(!1);if(t.length===0)return null;const h=()=>{if(l.current){const{scrollLeft:r,scrollWidth:i,clientWidth:d}=l.current;m(r+d{s?.(r)},u=()=>{l.current&&l.current.scrollBy({left:200,behavior:"smooth"})};return e.jsxs(f.div,{initial:{opacity:0,y:-8},animate:{opacity:1,y:0},className:"mb-4",children:[e.jsx("h3",{className:"text-base font-bold mb-3",style:{color:o.headerText},children:"Recommended for Review"}),e.jsxs("div",{className:"relative flex items-center",children:[e.jsx("div",{ref:l,onScroll:h,className:"flex gap-2 overflow-x-auto scrollbar-hide pb-1",style:{scrollbarWidth:"none",msOverflowStyle:"none"},children:t.slice(0,8).map((r,i)=>e.jsxs("button",{onClick:()=>p(r),className:"flex items-center gap-1.5 px-4 py-2 rounded-full text-sm font-semibold transition-all hover:scale-[1.02] whitespace-nowrap",style:{backgroundColor:o.pillBg,color:o.pillText},children:[e.jsx(x,{size:14}),g(r),e.jsx(n,{size:14})]},`${r}-${i}`))}),c&&e.jsx("button",{onClick:u,className:"flex-shrink-0 ml-2 w-8 h-8 rounded-full flex items-center justify-center transition-colors",style:{backgroundColor:o.arrowBg},"aria-label":"Scroll right",children:e.jsx(n,{size:16,className:"text-gray-600"})})]}),e.jsx("style",{children:` +import{r as a,j as e}from"./vendor-react-B4AQeu28.js";import{m as f,w as x}from"./index-uASBzalf.js";import{C as n}from"./chevron-right-U0AqPOPj.js";import"./vendor-firebase-firestore-CP9q7ISf.js";import"./vendor-firebase-core-DCQrgkxC.js";import"./vendor-firebase-auth-Bcpr4O6E.js";import"./vendor-firebase-storage-dc5X5yTv.js";import"./vendor-firebase-analytics-CHPyhRzk.js";import"./vendor-radix-xDOIcVzp.js";import"./vendor-charts-Ckgeb0nY.js";import"./vendor-markdown-yqZQ_iQm.js";const o={pillBg:"#E9D5FF",pillText:"#6B21A8",headerText:"#1F2937",arrowBg:"#F3F4F6"},b={functions:"Functions & Graphs",businessmath:"Business Math",logic:"Logic & Reasoning",statistics:"Statistics",probability:"Probability",precalc:"Pre-Calculus",calculus:"Basic Calculus",geometry:"Geometry",trigonometry:"Trigonometry",algebra:"Algebra"};function g(t){const s=t.toLowerCase().trim();return b[s]||t.split(/[-_]/).map(l=>l.charAt(0).toUpperCase()+l.slice(1)).join(" ")}const L=({atRiskSubjects:t=[],onTopicClick:s})=>{const l=a.useRef(null),[c,m]=a.useState(!1);if(t.length===0)return null;const h=()=>{if(l.current){const{scrollLeft:r,scrollWidth:i,clientWidth:d}=l.current;m(r+d{s?.(r)},u=()=>{l.current&&l.current.scrollBy({left:200,behavior:"smooth"})};return e.jsxs(f.div,{initial:{opacity:0,y:-8},animate:{opacity:1,y:0},className:"mb-4",children:[e.jsx("h3",{className:"text-base font-bold mb-3",style:{color:o.headerText},children:"Recommended for Review"}),e.jsxs("div",{className:"relative flex items-center",children:[e.jsx("div",{ref:l,onScroll:h,className:"flex gap-2 overflow-x-auto scrollbar-hide pb-1",style:{scrollbarWidth:"none",msOverflowStyle:"none"},children:t.slice(0,8).map((r,i)=>e.jsxs("button",{onClick:()=>p(r),className:"flex items-center gap-1.5 px-4 py-2 rounded-full text-sm font-semibold transition-all hover:scale-[1.02] whitespace-nowrap",style:{backgroundColor:o.pillBg,color:o.pillText},children:[e.jsx(x,{size:14}),g(r),e.jsx(n,{size:14})]},`${r}-${i}`))}),c&&e.jsx("button",{onClick:u,className:"flex-shrink-0 ml-2 w-8 h-8 rounded-full flex items-center justify-center transition-colors",style:{backgroundColor:o.arrowBg},"aria-label":"Scroll right",children:e.jsx(n,{size:16,className:"text-gray-600"})})]}),e.jsx("style",{children:` .scrollbar-hide::-webkit-scrollbar { display: none; } diff --git a/assets/TeacherDashboard-BmaSDmQs.js b/assets/TeacherDashboard-BmaSDmQs.js new file mode 100644 index 0000000000000000000000000000000000000000..884b3dcebbec2f9abefc84668797105b5521f3ee --- /dev/null +++ b/assets/TeacherDashboard-BmaSDmQs.js @@ -0,0 +1,102 @@ +import{d as le,j as e,r as h,c as sr}from"./vendor-react-B4AQeu28.js";import{c as ol,B as ms}from"./button-BPmLcOpC.js";import{I as Qs}from"./input--XHWlmp1.js";import il from"./ConfirmModal-D2z4s_BB.js";import{e as ut,t as ll,f as rn,u as Io,g as Bt,m as Pe,b as cl,U as Rt,h as st,i as dl,j as Ze,k as Eo,a as Lt,G as _o,B as ar,Z as ul,l as gs,n as me,o as ja,p as ct,A as Ro,q as Yt,T as sa,C as ml,r as nn,R as Vs,v as xl,w as _s,x as on,y as ln,z as pl,D as Mo,M as hl,E as cn,F as fl,H as gl}from"./index-uASBzalf.js";import{collection as Xt,query as Ht,limit as zo,where as Gt,getDocs as ts,orderBy as bl,onSnapshot as Lo,setDoc as Zt,doc as vt,updateDoc as Kt,getDoc as Cs,serverTimestamp as ft,deleteDoc as vl}from"./vendor-firebase-firestore-CP9q7ISf.js";import{C as Ao}from"./check-check-DFG24Nyg.js";import{c as wl,a as Do,f as Fo}from"./formatDistanceToNow-BinvfoNW.js";import{B as Rs}from"./bell-CiUaN6S3.js";import{C as Ra}from"./circle-check-C5Psopk3.js";import{C as aa}from"./circle-alert-DDOZHhZK.js";import{S as ss}from"./sparkles-DHVr5IP1.js";import{M as Nl,L as jl,S as yl,a as Sl}from"./LogoutActionButton-Dl6IiDHd.js";import{s as dn,f as $o,L as ya,d as kl,p as Cl,a as Tl,A as Sa,P as Il,b as El}from"./quizService-D738RDcZ.js";import{S as _l}from"./vendor-radix-xDOIcVzp.js";import{T as Rl,a as Ml,b as zl}from"./tooltip-1ASn-3cE.js";import{X as ps}from"./x-CBb03rh3.js";import{C as Ll}from"./circle-help-PS1uII8x.js";import{E as Al,a as Dl}from"./eye-DIwMshM-.js";import{S as da}from"./send-bMgoXVnc.js";import{T as Oo}from"./trash-2-D7q6y9vT.js";import{C as Ut}from"./check-Dk6iwDFI.js";import{I as Us,F as Wt,T as Bo,D as Fl,A as $l}from"./trending-down-DQ2ZPRUy.js";import{C as _t,a as ka}from"./chevron-up-BpMhRyJp.js";import{M as un}from"./minus-Bfei9C79.js";import{P as rr}from"./plus-Cy6hz5PP.js";import{C as hs}from"./chart-column-CLoxLorp.js";import{C as Ol,H as mn}from"./history-UFBxnE6Z.js";import{D as Bl}from"./download-CVrPjUr0.js";import{C as as}from"./chevron-left-CzSo_K0d.js";import{C as es}from"./chevron-right-U0AqPOPj.js";import{S as Po}from"./save-CoDXj-im.js";import{S as ra}from"./search-Col42W4Q.js";import{U as xn}from"./upload-Ds5w3QNw.js";import{u as Pl}from"./useQuery-CNXEt8jj.js";import{S as pn,g as Hl,G as Gl,s as hn}from"./subjects-F8wTuRgo.js";import{u as Ql}from"./useCurriculum-DZVkK6Ec.js";import{C as gr}from"./circle-check-big-BNRlH5pv.js";import Vl from"./ChatMarkdown-BSQ2GO-C.js";import{C as Ms}from"./clock-8t0UYgg3.js";import{D as fn,a as gn,b as Ul,c as Wl,d as ql}from"./dialog-CNHSYTtM.js";import{S as Me}from"./skeleton-Ds4RcTr4.js";import{u as Tt,r as Yl}from"./vendor-xlsx-uZelXSz_.js";import{C as Ho}from"./clipboard-check-RuPght2T.js";import{R as bn,B as vn,C as wn,X as Nn,Y as jn,T as yn,a as Sn,b as kn}from"./vendor-charts-Ckgeb0nY.js";import"./log-out-Dr0BHRO4.js";import"./vendor-firebase-core-DCQrgkxC.js";import"./vendor-firebase-auth-Bcpr4O6E.js";import"./vendor-firebase-storage-dc5X5yTv.js";import"./vendor-firebase-analytics-CHPyhRzk.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 Kl=[["path",{d:"M15 12H3",key:"6jk70r"}],["path",{d:"M17 18H3",key:"1amg6g"}],["path",{d:"M21 6H3",key:"1jwq7v"}]],Xl=ut("align-left",Kl);/** + * @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 Jl=[["path",{d:"M8 2v4",key:"1cmpym"}],["path",{d:"M16 2v4",key:"4m81vk"}],["rect",{width:"18",height:"18",x:"3",y:"4",rx:"2",key:"1hopcy"}],["path",{d:"M3 10h18",key:"8toen8"}],["path",{d:"M8 14h.01",key:"6423bh"}],["path",{d:"M12 14h.01",key:"1etili"}],["path",{d:"M16 14h.01",key:"1gbofw"}],["path",{d:"M8 18h.01",key:"lrp35t"}],["path",{d:"M12 18h.01",key:"mhygvu"}],["path",{d:"M16 18h.01",key:"kzsmim"}]],Qa=ut("calendar-days",Jl);/** + * @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 Zl=[["line",{x1:"18",x2:"18",y1:"20",y2:"10",key:"1xfpm4"}],["line",{x1:"12",x2:"12",y1:"20",y2:"4",key:"be30l9"}],["line",{x1:"6",x2:"6",y1:"20",y2:"14",key:"1r4le6"}]],ec=ut("chart-no-axes-column",Zl);/** + * @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 tc=[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"12",cy:"5",r:"1",key:"gxeob9"}],["circle",{cx:"12",cy:"19",r:"1",key:"lyex9k"}]],sc=ut("ellipsis-vertical",tc);/** + * @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 ac=[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"19",cy:"12",r:"1",key:"1wjl8i"}],["circle",{cx:"5",cy:"12",r:"1",key:"1pcz8c"}]],nr=ut("ellipsis",ac);/** + * @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 rc=[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"M10 14 21 3",key:"gplh6r"}],["path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6",key:"a6xqqp"}]],nc=ut("external-link",rc);/** + * @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 oc=[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M8 13h2",key:"yr2amv"}],["path",{d:"M14 13h2",key:"un5t4a"}],["path",{d:"M8 17h2",key:"2yhykz"}],["path",{d:"M14 17h2",key:"10kma7"}]],ic=ut("file-spreadsheet",oc);/** + * @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 lc=[["path",{d:"m16 6 4 14",key:"ji33uf"}],["path",{d:"M12 6v14",key:"1n7gus"}],["path",{d:"M8 8v12",key:"1gg7y9"}],["path",{d:"M4 4v16",key:"6qkkli"}]],Ca=ut("library",lc);/** + * @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 cc=[["path",{d:"m3 17 2 2 4-4",key:"1jhpwq"}],["path",{d:"m3 7 2 2 4-4",key:"1obspn"}],["path",{d:"M13 6h8",key:"15sg57"}],["path",{d:"M13 12h8",key:"h98zly"}],["path",{d:"M13 18h8",key:"oe0vm4"}]],Go=ut("list-checks",cc);/** + * @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 dc=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M15 3v18",key:"14nvp0"}]],uc=ut("panel-right",dc);/** + * @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 mc=[["path",{d:"M12 20h9",key:"t2du7b"}],["path",{d:"M16.376 3.622a1 1 0 0 1 3.002 3.002L7.368 18.635a2 2 0 0 1-.855.506l-2.872.838a.5.5 0 0 1-.62-.62l.838-2.872a2 2 0 0 1 .506-.854z",key:"1ykcvy"}]],xc=ut("pen-line",mc);/** + * @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 pc=[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}]],Qo=ut("pen",pc);/** + * @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 hc=[["path",{d:"M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2",key:"143wyd"}],["path",{d:"M6 9V3a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v6",key:"1itne7"}],["rect",{x:"6",y:"14",width:"12",height:"8",rx:"1",key:"1ue0tg"}]],fc=ut("printer",hc);/** + * @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 gc=[["path",{d:"M3 7V5a2 2 0 0 1 2-2h2",key:"aa7l1z"}],["path",{d:"M17 3h2a2 2 0 0 1 2 2v2",key:"4qcy5o"}],["path",{d:"M21 17v2a2 2 0 0 1-2 2h-2",key:"6vwrx8"}],["path",{d:"M7 21H5a2 2 0 0 1-2-2v-2",key:"ioqczr"}],["path",{d:"M7 12h10",key:"b7w52i"}]],bc=ut("scan-line",gc);/** + * @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 vc=[["path",{d:"M12 3v18",key:"108xh3"}],["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M3 9h18",key:"1pudct"}],["path",{d:"M3 15h18",key:"5xshup"}]],wc=ut("table",vc);/** + * @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 Nc=[["path",{d:"m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5",key:"ftymec"}],["rect",{x:"2",y:"6",width:"14",height:"12",rx:"2",key:"158x01"}]],Cn=ut("video",Nc);/** + * @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 jc=[["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"}]],or=ut("wand-sparkles",jc);function yc(t,s){const a=ll(t);return isNaN(s)?wl(t,NaN):(a.setDate(a.getDate()+s),a)}function Vo(t,s){const a=rn(t),r=rn(s);return+a==+r}function Tn(t){return Vo(t,Do(t))}function Sc(t,s){return yc(t,-1)}function In(t){return Vo(t,Sc(Do(t)))}const Ma=0,ns=1,zs=2,Uo=4;function En(t){return()=>t}function kc(t){t()}function Wo(t,s){return a=>t(s(a))}function _n(t,s){return()=>t(s)}function Cc(t,s){return a=>t(s,a)}function br(t){return t!==void 0}function Tc(...t){return()=>{t.map(kc)}}function Ls(){}function za(t,s){return s(t),t}function Ic(t,s){return s(t)}function Ke(...t){return t}function He(t,s){return t(ns,s)}function Te(t,s){t(Ma,s)}function vr(t){t(zs)}function Xe(t){return t(Uo)}function ce(t,s){return He(t,Cc(s,Ma))}function Mt(t,s){const a=t(ns,r=>{a(),s(r)});return a}function Rn(t){let s,a;return r=>n=>{s=n,a&&clearTimeout(a),a=setTimeout(()=>{r(s)},t)}}function qo(t,s){return t===s}function Ye(t=qo){let s;return a=>r=>{t(s,r)||(s=r,a(r))}}function fe(t){return s=>a=>{t(a)&&s(a)}}function re(t){return s=>Wo(s,t)}function $t(t){return s=>()=>{s(t)}}function P(t,...s){const a=Ec(...s);return((r,n)=>{switch(r){case zs:vr(t);return;case ns:return He(t,a(n))}})}function Ot(t,s){return a=>r=>{a(s=t(s,r))}}function fs(t){return s=>a=>{t>0?t--:s(a)}}function qt(t){let s=null,a;return r=>n=>{s=n,!a&&(a=setTimeout(()=>{a=void 0,r(s)},t))}}function Ie(...t){const s=new Array(t.length);let a=0,r=null;const n=2**t.length-1;return t.forEach((o,i)=>{const l=2**i;He(o,c=>{const d=a;a|=l,s[i]=c,d!==n&&a===n&&r&&(r(),r=null)})}),o=>i=>{const l=()=>{o([i].concat(s))};a===n?l():r=l}}function Ec(...t){return s=>t.reduceRight(Ic,s)}function _c(t){let s,a;const r=()=>s?.();return function(n,o){switch(n){case ns:return o?a===o?void 0:(r(),a=o,s=He(t,o),s):(r(),Ls);case zs:r(),a=null;return}}}function G(t){let s=t;const a=ze();return((r,n)=>{switch(r){case Ma:s=n;break;case ns:{n(s);break}case Uo:return s}return a(r,n)})}function ht(t,s){return za(G(s),a=>ce(t,a))}function ze(){const t=[];return((s,a)=>{switch(s){case Ma:t.slice().forEach(r=>{r(a)});return;case zs:t.splice(0,t.length);return;case ns:return t.push(a),()=>{const r=t.indexOf(a);r>-1&&t.splice(r,1)}}})}function jt(t){return za(ze(),s=>ce(t,s))}function Be(t,s=[],{singleton:a}={singleton:!0}){return{constructor:t,dependencies:s,id:Rc(),singleton:a}}const Rc=()=>Symbol();function Mc(t){const s=new Map,a=({constructor:r,dependencies:n,id:o,singleton:i})=>{if(i&&s.has(o))return s.get(o);const l=r(n.map(c=>a(c)));return i&&s.set(o,l),l};return a(t)}function at(...t){const s=ze(),a=new Array(t.length);let r=0;const n=2**t.length-1;return t.forEach((o,i)=>{const l=2**i;He(o,c=>{a[i]=c,r|=l,r===n&&Te(s,a)})}),function(o,i){switch(o){case zs:{vr(s);return}case ns:return r===n&&i(a),He(s,i)}}}function he(t,s=qo){return P(t,Ye(s))}function ir(...t){return function(s,a){switch(s){case zs:return;case ns:return Tc(...t.map(r=>He(r,a)))}}}const nt={DEBUG:0,INFO:1,WARN:2,ERROR:3},zc={[nt.DEBUG]:"debug",[nt.ERROR]:"error",[nt.INFO]:"log",[nt.WARN]:"warn"},Lc=()=>typeof globalThis>"u"?window:globalThis,os=Be(()=>{const t=G(nt.ERROR);return{log:G((s,a,r=nt.INFO)=>{const n=Lc().VIRTUOSO_LOG_LEVEL??Xe(t);r>=n&&console[zc[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",s,a)}),logLevel:t}},[],{singleton:!0});function bs(t,s,a){return wr(t,s,a).callbackRef}function wr(t,s,a){const r=le.useRef(null);let n=i=>{};const o=le.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 n=i=>{i&&s?(o?.observe(i),r.current=i):(r.current&&o?.unobserve(r.current),r.current=null)},{callbackRef:n,ref:r}}function Ac(t,s,a,r,n,o,i,l,c){const d=le.useCallback(x=>{const b=Dc(x.children,s,l?"offsetWidth":"offsetHeight",n);let p=x.parentElement;for(;p.dataset.virtuosoScroller===void 0;)p=p.parentElement;const g=p.lastElementChild.dataset.viewportType==="window";let C;g&&(C=p.ownerDocument.defaultView);const S=i?l?i.scrollLeft:i.scrollTop:g?l?C.scrollX||C.document.documentElement.scrollLeft:C.scrollY||C.document.documentElement.scrollTop:l?p.scrollLeft:p.scrollTop,N=i?l?i.scrollWidth:i.scrollHeight:g?l?C.document.documentElement.scrollWidth:C.document.documentElement.scrollHeight:l?p.scrollWidth:p.scrollHeight,m=i?l?i.offsetWidth:i.offsetHeight:g?l?C.innerWidth:C.innerHeight:l?p.offsetWidth:p.offsetHeight;r({scrollHeight:N,scrollTop:Math.max(S,0),viewportHeight:m}),o?.(l?Mn("column-gap",getComputedStyle(x).columnGap,n):Mn("row-gap",getComputedStyle(x).rowGap,n)),b!==null&&t(b)},[t,s,n,o,i,r,l]);return wr(d,a,c)}function Dc(t,s,a,r){const n=t.length;if(n===0)return null;const o=[];for(let i=0;i{if(!c?.offsetParent)return;const d=c.getBoundingClientRect(),x=d.width;let b,p;if(s){const g=s.getBoundingClientRect(),C=d.top-g.top;p=g.height-Math.max(0,C),b=C+s.scrollTop}else{const g=i.current.ownerDocument.defaultView;p=g.innerHeight-Math.max(0,d.top),b=d.top+g.scrollY}r.current={listHeight:d.height,offsetTop:b,visibleHeight:p,visibleWidth:x},t(r.current)},[t,s]),{callbackRef:o,ref:i}=wr(n,!0,a),l=le.useCallback(()=>{n(i.current)},[n,i]);return le.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]),o}const bt=Be(()=>{const t=ze(),s=ze(),a=G(0),r=ze(),n=G(0),o=ze(),i=ze(),l=G(0),c=G(0),d=G(0),x=G(0),b=ze(),p=ze(),g=G(!1),C=G(!1),S=G(!1);return ce(P(t,re(({scrollTop:N})=>N)),s),ce(P(t,re(({scrollHeight:N})=>N)),i),ce(s,n),{deviation:a,fixedFooterHeight:d,fixedHeaderHeight:c,footerHeight:x,headerHeight:l,horizontalDirection:C,scrollBy:p,scrollContainerState:t,scrollHeight:i,scrollingInProgress:g,scrollTo:b,scrollTop:s,skipAnimationFrameInResizeObserver:S,smoothScrollTargetReached:r,statefulScrollTop:n,viewportHeight:o}},[],{singleton:!0}),Ys={lvl:0};function Ko(t,s){const a=t.length;if(a===0)return[];let{index:r,value:n}=s(t[0]);const o=[];for(let i=1;is&&(l=l.concat(cr(n,s,a))),r>=s&&r<=a&&l.push({k:r,v:i}),r<=a&&(l=l.concat(cr(o,s,a))),l}function ga(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(Va(s))return ei(rt(t,{lvl:a-1}));if(!Ve(s)&&!Ve(s.r))return rt(s.r,{l:rt(s,{r:s.r.l}),lvl:a,r:rt(t,{l:s.r.r,lvl:a-1})});throw new Error("Unexpected empty nodes")}if(Va(t))return dr(rt(t,{lvl:a-1}));if(!Ve(r)&&!Ve(r.l)){const n=r.l,o=Va(n)?r.lvl-1:r.lvl;return rt(n,{l:rt(t,{lvl:a-1,r:n.l}),lvl:n.lvl+1,r:dr(rt(r,{l:n.r,lvl:o}))})}throw new Error("Unexpected empty nodes")}function rt(t,s){return Zo(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 Xo(t){return Ve(t.r)?t.l:ga(rt(t,{r:Xo(t.r)}))}function Va(t){return Ve(t)||t.lvl>t.r.lvl}function Jo(t){return Ve(t.r)?[t.k,t.v]:Jo(t.r)}function Zo(t,s,a,r=Ys,n=Ys){return{k:t,l:r,lvl:a,r:n,v:s}}function zn(t){return dr(ei(t))}function ei(t){const{l:s}=t;return!Ve(s)&&s.lvl===t.lvl?rt(s,{r:rt(t,{l:s.r})}):t}function dr(t){const{lvl:s,r:a}=t;return!Ve(a)&&!Ve(a.r)&&a.lvl===s&&a.r.lvl===s?rt(a,{l:rt(t,{r:a.l}),lvl:s+1}):t}function Fc(t){return Ko(t,({k:s,v:a})=>({index:s,value:a}))}function ti(t,s){return!!(t&&t.startIndex===s.startIndex&&t.endIndex===s.endIndex)}function Xs(t,s){return!!(t&&t[0]===s[0]&&t[1]===s[1])}const Nr=Be(()=>({recalcInProgress:G(!1)}),[],{singleton:!0});function si(t,s,a){return t[Ta(t,s,a)]}function Ta(t,s,a,r=0){let n=t.length-1;for(;r<=n;){const o=Math.floor((r+n)/2),i=t[o],l=a(i,s);if(l===0)return o;if(l===-1){if(n-r<2)return o-1;n=o-1}else{if(n===r)return o;r=o+1}}throw new Error(`Failed binary finding record in array - ${t.join(",")}, searched for ${s}`)}function $c(t,s,a,r){const n=Ta(t,s,r),o=Ta(t,a,r,n);return t.slice(n,o+1)}function rs(t,s){return Math.round(t.getBoundingClientRect()[s])}function La(t){return!Ve(t.groupOffsetTree)}function jr({index:t},s){return s===t?0:s=b||o===p)&&(t=lr(t,b)):(d=p!==o,c=!0),x>n&&n>=b&&p!==o&&(t=Nt(t,n+1,p));d&&(t=Nt(t,i,o))}return[t,a]}function Pc(t){return typeof t.groupIndex<"u"}function Hc({offset:t},s){return s===t?0:s0?l+a:l}function ai(t,s){if(!La(s))return t;let a=0;for(;s.groupIndices[a]<=t+a;)a++;return t+a}function ri(t,s,a){if(Pc(t))return s.groupIndices[t.groupIndex]+1;const r=t.index==="LAST"?a:t.index;let n=ai(r,s);return n=Math.max(0,n,Math.min(a,n)),n}function Gc(t,s,a,r=0){return r>0&&(s=Math.max(s,si(t,r,jr).offset)),Ko($c(t,s,a,Hc),Uc)}function Qc(t,[s,a,r,n]){s.length>0&&r("received item sizes",s,nt.DEBUG);const o=t.sizeTree;let i=o,l=0;if(a.length>0&&Ve(o)&&s.length===2){const p=s[0].size,g=s[1].size;i=a.reduce((C,S)=>Nt(Nt(C,S,p),S+1,g),i)}else[i,l]=Bc(i,s);if(i===o)return t;const{lastIndex:c,lastOffset:d,lastSize:x,offsetTree:b}=ur(t.offsetTree,l,i,n);return{groupIndices:a,groupOffsetTree:a.reduce((p,g)=>Nt(p,g,Js(g,b,n)),Is()),lastIndex:c,lastOffset:d,lastSize:x,offsetTree:b,sizeTree:i}}function Vc(t){return xs(t).map(({k:s,v:a},r,n)=>{const o=n[r+1];return{endIndex:o!==void 0?o.k-1:1/0,size:a,startIndex:s}})}function Ln(t,s){let a=0,r=0;for(;an.start===r&&(n.end===s||n.end===1/0)&&n.value===a}const qc={offsetHeight:"height",offsetWidth:"width"},Qt=Be(([{log:t},{recalcInProgress:s}])=>{const a=ze(),r=ze(),n=ht(r,0),o=ze(),i=ze(),l=G(0),c=G([]),d=G(void 0),x=G(void 0),b=G(void 0),p=G(void 0),g=G((v,k)=>rs(v,qc[k])),C=G(void 0),S=G(0),N=Oc(),m=ht(P(a,Ie(c,t,S),Ot(Qc,N),Ye()),N),w=ht(P(c,Ye(),Ot((v,k)=>({current:k,prev:v.current}),{current:[],prev:[]}),re(({prev:v})=>v)),[]);ce(P(c,fe(v=>v.length>0),Ie(m,S),re(([v,k,I])=>{const $=v.reduce((D,q,Q)=>Nt(D,q,Js(q,k.offsetTree,I)||Q),Is());return{...k,groupIndices:v,groupOffsetTree:$}})),m),ce(P(r,Ie(m),fe(([v,{lastIndex:k}])=>v[{endIndex:k,size:I,startIndex:v}])),a),ce(d,x);const y=ht(P(d,re(v=>v===void 0)),!0);ce(P(x,fe(v=>v!==void 0&&Ve(Xe(m).sizeTree)),re(v=>{const k=Xe(b),I=Xe(c).length>0;return k!==void 0&&k!==0?I?[{endIndex:0,size:k,startIndex:0},{endIndex:1,size:v,startIndex:1}]:[]:[{endIndex:0,size:v,startIndex:0}]})),a),ce(P(p,fe(v=>v!==void 0&&v.length>0&&Ve(Xe(m).sizeTree)),re(v=>{const k=[];let I=v[0],$=0;for(let D=1;Dv!==void 0&&k!==void 0),re(([v,k,I])=>{const $=[];for(let D=0;D({changed:I!==v,sizes:I}),{changed:!1,sizes:N}),re(v=>v.changed)));He(P(l,Ot((v,k)=>({diff:v.prev-k,prev:k}),{diff:0,prev:0}),re(v=>v.diff)),v=>{const{groupIndices:k}=Xe(m);if(v>0)Te(s,!0),Te(o,v+Ln(v,k));else if(v<0){const I=Xe(w);I.length>0&&(v-=Ln(-v,I)),Te(i,v)}}),He(P(l,Ie(t)),([v,k])=>{v<0&&k("`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},nt.ERROR)});const j=jt(o);ce(P(o,Ie(m),re(([v,k])=>{const I=k.groupIndices.length>0,$=[],D=k.lastSize;if(I){const q=Ks(k.sizeTree,0);let Q=0,A=0;for(;Q{let ge=ee.ranges;return ee.prevSize!==0&&(ge=[...ee.ranges,{endIndex:ie+v-1,size:ee.prevSize,startIndex:ee.prevIndex}]),{prevIndex:ie+v,prevSize:je,ranges:ge}},{prevIndex:v,prevSize:0,ranges:$}).ranges}return xs(k.sizeTree).reduce((q,{k:Q,v:A})=>({prevIndex:Q+v,prevSize:A,ranges:[...q.ranges,{endIndex:Q+v-1,size:q.prevSize,startIndex:q.prevIndex}]}),{prevIndex:0,prevSize:D,ranges:[]}).ranges})),a);const H=jt(P(i,Ie(m,S),re(([v,{offsetTree:k},I])=>{const $=-v;return Js($,k,I)})));return ce(P(i,Ie(m,S),re(([v,k,I])=>{if(k.groupIndices.length>0){if(Ve(k.sizeTree))return k;let D=Is();const q=Xe(w);let Q=0,A=0,U=0;for(;Q<-v;){U=q[A];const ee=q[A+1]-U-1;A++,Q+=ee+1}if(D=xs(k.sizeTree).reduce((ee,{k:ie,v:je})=>Nt(ee,Math.max(0,ie+v),je),D),Q!==-v){const ee=Ks(k.sizeTree,U);D=Nt(D,0,ee);const ie=At(k.sizeTree,-v+1)[1];D=Nt(D,1,ie)}return{...k,sizeTree:D,...ur(k.offsetTree,0,D,I)}}const $=xs(k.sizeTree).reduce((D,{k:q,v:Q})=>Nt(D,Math.max(0,q+v),Q),Is());return{...k,sizeTree:$,...ur(k.offsetTree,0,$,I)}})),m),{beforeUnshiftWith:j,data:C,defaultItemSize:x,firstItemIndex:l,fixedItemSize:d,fixedGroupSize:b,gap:S,groupIndices:c,heightEstimates:p,itemSize:g,listRefresh:R,shiftWith:i,shiftWithOffset:H,sizeRanges:a,sizes:m,statefulTotalCount:n,totalCount:r,trackItemSizes:y,unshiftWith:o}},Ke(os,Nr),{singleton:!0});function Yc(t){return t.reduce((s,a)=>(s.groupIndices.push(s.totalCount),s.totalCount+=a+1,s),{groupIndices:[],totalCount:0})}const ni=Be(([{groupIndices:t,sizes:s,totalCount:a},{headerHeight:r,scrollTop:n}])=>{const o=ze(),i=ze(),l=jt(P(o,re(Yc)));return ce(P(l,re(c=>c.totalCount)),a),ce(P(l,re(c=>c.groupIndices)),t),ce(P(at(n,s,r),fe(([c,d])=>La(d)),re(([c,d,x])=>At(d.groupOffsetTree,Math.max(c-x,0),"v")[0]),Ye(),re(c=>[c])),i),{groupCounts:o,topItemsIndexes:i}},Ke(Qt,bt)),is=Be(([{log:t}])=>{const s=G(!1),a=jt(P(s,fe(r=>r),Ye()));return He(s,r=>{r&&Xe(t)("props updated",{},nt.DEBUG)}),{didMount:a,propsReady:s}},Ke(os),{singleton:!0}),Kc=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function oi(t){const s=typeof t=="number"?{index:t}:t;return s.align||(s.align="start"),(!s.behavior||!Kc)&&(s.behavior="auto"),s.offset===void 0&&(s.offset=0),s}const na=Be(([{gap:t,listRefresh:s,sizes:a,totalCount:r},{fixedFooterHeight:n,fixedHeaderHeight:o,footerHeight:i,headerHeight:l,scrollingInProgress:c,scrollTo:d,smoothScrollTargetReached:x,viewportHeight:b},{log:p}])=>{const g=ze(),C=ze(),S=G(0);let N=null,m=null,w=null;function y(){N!==null&&(N(),N=null),w!==null&&(w(),w=null),m&&(clearTimeout(m),m=null),Te(c,!1)}return ce(P(g,Ie(a,b,r,S,l,i,p),Ie(t,o,n),re(([[R,j,H,v,k,I,$,D],q,Q,A])=>{const U=oi(R),{align:ee,behavior:ie,offset:je}=U,ge=v-1,Ce=ri(U,j,ge);let de=Js(Ce,j.offsetTree,q)+I;ee==="end"?(de+=Q+At(j.sizeTree,Ce)[1]-H+A,Ce===ge&&(de+=$)):ee==="center"?de+=(Q+At(j.sizeTree,Ce)[1]-H+A)/2:de-=k,je!==void 0&&je!==0&&(de+=je);const B=Y=>{y(),Y?(D("retrying to scroll to",{location:R},nt.DEBUG),Te(g,R)):(Te(C,!0),D("list did not change, scroll successful",{},nt.DEBUG))};if(y(),ie==="smooth"){let Y=!1;w=He(s,ne=>{Y=Y||ne}),N=Mt(x,()=>{B(Y)})}else N=Mt(P(s,Xc(150)),B);return m=setTimeout(()=>{y()},1200),Te(c,!0),D("scrolling from index to",{behavior:ie,index:Ce,top:de},nt.DEBUG),{behavior:ie,top:de}})),d),{scrollTargetReached:C,scrollToIndex:g,topListHeight:S}},Ke(Qt,bt,os),{singleton:!0});function Xc(t){return s=>{const a=setTimeout(()=>{s(!1)},t);return r=>{r&&(s(!0),clearTimeout(a))}}}function yr(t,s){t===0?s():requestAnimationFrame(()=>{yr(t-1,s)})}function Sr(t,s){const a=s-1;return typeof t=="number"?t:t.index==="LAST"?a:t.index}const oa=Be(([{defaultItemSize:t,listRefresh:s,sizes:a},{scrollTop:r},{scrollTargetReached:n,scrollToIndex:o},{didMount:i}])=>{const l=G(!0),c=G(0),d=G(!0);return ce(P(i,Ie(c),fe(([x,b])=>b!==0),$t(!1)),l),ce(P(i,Ie(c),fe(([x,b])=>b!==0),$t(!1)),d),He(P(at(s,i),Ie(l,a,t,d),fe(([[,x],b,{sizeTree:p},g,C])=>x&&(!Ve(p)||br(g))&&!b&&!C),Ie(c)),([,x])=>{Mt(n,()=>{Te(d,!0)}),yr(4,()=>{Mt(r,()=>{Te(l,!0)}),Te(o,x)})}),{initialItemFinalLocationReached:d,initialTopMostItemIndex:c,scrolledToInitialItem:l}},Ke(Qt,bt,na,is),{singleton:!0});function ii(t,s){return Math.abs(t-s)<1.01}const Zs="up",Ws="down",Jc="none",Zc={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},ed=0,ia=Be(([{footerHeight:t,headerHeight:s,scrollBy:a,scrollContainerState:r,scrollTop:n,viewportHeight:o}])=>{const i=G(!1),l=G(!0),c=ze(),d=ze(),x=G(4),b=G(ed),p=ht(P(ir(P(he(n),fs(1),$t(!0)),P(he(n),fs(1),$t(!1),Rn(100))),Ye()),!1),g=ht(P(ir(P(a,$t(!0)),P(a,$t(!1),Rn(200))),Ye()),!1);ce(P(at(he(n),he(b)),re(([w,y])=>w<=y),Ye()),l),ce(P(l,qt(50)),d);const C=jt(P(at(r,he(o),he(s),he(t),he(x)),Ot((w,[{scrollHeight:y,scrollTop:R},j,H,v,k])=>{const I=R+j-y>-k,$={scrollHeight:y,scrollTop:R,viewportHeight:j};if(I){let q,Q;return R>w.state.scrollTop?(q="SCROLLED_DOWN",Q=w.state.scrollTop-R):(q="SIZE_DECREASED",Q=w.state.scrollTop-R||w.scrollTopDelta),{atBottom:!0,atBottomBecause:q,scrollTopDelta:Q,state:$}}let D;return $.scrollHeight>w.state.scrollHeight?D="SIZE_INCREASED":jw!==void 0&&w.atBottom===y.atBottom))),S=ht(P(r,Ot((w,{scrollHeight:y,scrollTop:R,viewportHeight:j})=>{if(!ii(w.scrollHeight,y)){const H=y-(R+j)<1;return w.scrollTop!==R&&H?{changed:!0,jump:w.scrollTop-R,scrollHeight:y,scrollTop:R}:{changed:!0,jump:0,scrollHeight:y,scrollTop:R}}return{changed:!1,jump:0,scrollHeight:y,scrollTop:R}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),fe(w=>w.changed),re(w=>w.jump)),0);ce(P(C,re(w=>w.atBottom)),i),ce(P(i,qt(50)),c);const N=G(Ws);ce(P(r,re(({scrollTop:w})=>w),Ye(),Ot((w,y)=>Xe(g)?{direction:w.direction,prevScrollTop:y}:{direction:yw.direction)),N),ce(P(r,qt(50),$t(Jc)),N);const m=G(0);return ce(P(p,fe(w=>!w),$t(0)),m),ce(P(n,qt(100),Ie(p),fe(([w,y])=>y),Ot(([w,y],[R])=>[y,R],[0,0]),re(([w,y])=>y-w)),m),{atBottomState:C,atBottomStateChange:c,atBottomThreshold:x,atTopStateChange:d,atTopThreshold:b,isAtBottom:i,isAtTop:l,isScrolling:p,lastJumpDueToItemResize:S,scrollDirection:N,scrollVelocity:m}},Ke(bt)),ea="top",ta="bottom",An="none";function Dn(t,s,a){return typeof t=="number"?a===Zs&&s===ea||a===Ws&&s===ta?t:0:a===Zs?s===ea?t.main:t.reverse:s===ta?t.main:t.reverse}function Fn(t,s){return typeof t=="number"?t:t[s]??0}const kr=Be(([{deviation:t,fixedHeaderHeight:s,headerHeight:a,scrollTop:r,viewportHeight:n}])=>{const o=ze(),i=G(0),l=G(0),c=G(0),d=ht(P(at(he(r),he(n),he(a),he(o,Xs),he(c),he(i),he(s),he(t),he(l)),re(([x,b,p,[g,C],S,N,m,w,y])=>{const R=x-w,j=N+m,H=Math.max(p-R,0);let v=An;const k=Fn(y,ea),I=Fn(y,ta);return g-=w,g+=p+m,C+=p+m,C-=w,g>x+j-k&&(v=Zs),Cx!==null),Ye(Xs)),[0,0]);return{increaseViewportBy:l,listBoundary:o,overscan:c,topListHeight:i,visibleRange:d}},Ke(bt),{singleton:!0});function td(t,s,a){if(La(s)){const r=ai(t,s);return[{index:At(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 Ua={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function ba(t,s,a,r,n,o){const{lastIndex:i,lastOffset:l,lastSize:c}=n;let d=0,x=0;if(t.length>0){d=t[0].offset;const S=t[t.length-1];x=S.offset+S.size}const b=a-i,p=l+b*c+(b-1)*r,g=d,C=p-x;return{bottom:x,firstItemIndex:o,items:$n(t,n,o),offsetBottom:C,offsetTop:d,top:g,topItems:$n(s,n,o),topListHeight:s.reduce((S,N)=>N.size+S,0),totalCount:a}}function li(t,s,a,r,n,o){let i=0;if(a.groupIndices.length>0)for(const x of a.groupIndices){if(x-i>=t)break;i++}const l=t+i,c=Sr(s,l),d=Array.from({length:l}).map((x,b)=>({data:o[b+c],index:b+c,offset:0,size:0}));return ba(d,[],l,n,a,r)}function $n(t,s,a){if(t.length===0)return[];if(!La(s))return t.map(d=>({...d,index:d.index+a,originalIndex:d.index}));const r=t[0].index,n=t[t.length-1].index,o=[],i=Es(s.groupOffsetTree,r,n);let l,c=0;for(const d of t){(!l||l.end{const S=G([]),N=G(0),m=ze(),w=G(0);ce(o.topItemsIndexes,S);const y=ht(P(at(g,C,he(c,Xs),he(n),he(r),he(d),x,he(S),he(s),he(a),he(w),t),fe(([v,k,,I,,,,,,,,$])=>{const D=$!==void 0&&$.length!==I;return v&&!k&&!D}),re(([,,[v,k],I,$,D,q,Q,A,U,ee,ie])=>{const je=$,{offsetTree:ge,sizeTree:Ce}=je,de=Xe(N);if(I===0)return{...Ua,totalCount:I};if(v===0&&k===0)return de===0?{...Ua,totalCount:I}:li(de,D,$,A,U,ie||[]);if(Ve(Ce))return de>0?null:ba(td(Sr(D,I),je,ie),[],I,U,je,A);const B=[];if(Q.length>0){const X=Q[0],f=Q[Q.length-1];let T=0;for(const E of Es(Ce,X,f)){const W=E.value,V=Math.max(E.start,X),se=Math.min(E.end,f);for(let ae=V;ae<=se;ae++)B.push({data:ie?.[ae],index:ae,offset:T,size:W}),T+=W}}if(!q)return ba([],B,I,U,je,A);const Y=Q.length>0?Q[Q.length-1]+1:0,ne=Gc(ge,v,k,Y);if(ne.length===0)return null;const De=I-1,Le=za([],X=>{for(const f of ne){const T=f.value;let E=T.offset,W=f.start;const V=T.size;if(T.offset=k);ae++)X.push({data:ie?.[ae],index:ae,offset:E,size:V}),E+=V+U}}),Ge=On(ee,ea),O=On(ee,ta);if(Le.length>0&&(Ge>0||O>0)){const X=Le[0],f=Le[Le.length-1];if(Ge>0&&X.index>Y){const T=Math.min(Ge,X.index-Y),E=[];let W=X.offset;for(let V=X.index-1;V>=X.index-T;V--){const se=Es(Ce,V,V)[0]?.value??X.size;W-=se+U,E.unshift({data:ie?.[V],index:V,offset:W,size:se})}Le.unshift(...E)}if(O>0&&f.indexv!==null),Ye()),Ua);ce(P(t,fe(br),re(v=>v?.length)),n),ce(P(y,re(v=>v.topListHeight)),b),ce(b,l),ce(P(y,re(v=>[v.top,v.bottom])),i),ce(P(y,re(v=>v.items)),m);const R=jt(P(y,fe(({items:v})=>v.length>0),Ie(n,t),fe(([{items:v},k])=>v[v.length-1].originalIndex===k-1),re(([,v,k])=>[v-1,k]),Ye(Xs),re(([v])=>v))),j=jt(P(y,qt(200),fe(({items:v,topItems:k})=>v.length>0&&v[0].originalIndex===k.length),re(({items:v})=>v[0].index),Ye())),H=jt(P(y,fe(({items:v})=>v.length>0),re(({items:v})=>{let k=0,I=v.length-1;for(;v[k].type==="group"&&kk;)I--;return{endIndex:v[I].index,startIndex:v[k].index}}),Ye(ti)));return{endReached:R,initialItemCount:N,itemsRendered:m,listState:y,minOverscanItemCount:w,rangeChanged:H,startReached:j,topItemsIndexes:S,...p}},Ke(Qt,ni,kr,oa,na,ia,is,Nr),{singleton:!0}),ci=Be(([{fixedFooterHeight:t,fixedHeaderHeight:s,footerHeight:a,headerHeight:r},{listState:n}])=>{const o=ze(),i=ht(P(at(a,t,r,s,n),re(([l,c,d,x,b])=>l+c+d+x+b.offsetBottom+b.bottom)),0);return ce(he(i),o),{totalListHeight:i,totalListHeightChanged:o}},Ke(bt,vs),{singleton:!0}),sd=Be(([{viewportHeight:t},{totalListHeight:s}])=>{const a=G(!1),r=ht(P(at(a,t,s),fe(([n])=>n),re(([,n,o])=>Math.max(0,n-o)),qt(0),Ye()),0);return{alignToBottom:a,paddingTopAddition:r}},Ke(bt,ci),{singleton:!0}),di=Be(()=>({context:G(null)})),ad=({itemBottom:t,itemTop:s,locationParams:{align:a,behavior:r,...n},viewportBottom:o,viewportTop:i})=>so?{...n,align:a??"end",...r!==void 0?{behavior:r}:{}}:null,ui=Be(([{gap:t,sizes:s,totalCount:a},{fixedFooterHeight:r,fixedHeaderHeight:n,headerHeight:o,scrollingInProgress:i,scrollTop:l,viewportHeight:c},{scrollToIndex:d}])=>{const x=ze();return ce(P(x,Ie(s,c,a,o,n,r,l),Ie(t),re(([[b,p,g,C,S,N,m,w],y])=>{const{calculateViewLocation:R=ad,done:j,...H}=b,v=ri(b,p,C-1),k=Js(v,p.offsetTree,y)+S+N,I=k+At(p.sizeTree,v)[1],$=w+N,D=w+g-m,q=R({itemBottom:I,itemTop:k,locationParams:H,viewportBottom:D,viewportTop:$});return q!==null?j&&Mt(P(i,fe(Q=>!Q),fs(Xe(i)?1:2)),j):j?.(),q}),fe(b=>b!==null)),d),{scrollIntoView:x}},Ke(Qt,bt,na,vs,os),{singleton:!0});function Bn(t){return t===!1?!1:t==="smooth"?"smooth":"auto"}const rd=(t,s)=>typeof t=="function"?Bn(t(s)):s&&Bn(t),nd=Be(([{listRefresh:t,totalCount:s,fixedItemSize:a,data:r},{atBottomState:n,isAtBottom:o},{scrollToIndex:i},{scrolledToInitialItem:l},{didMount:c,propsReady:d},{log:x},{scrollingInProgress:b},{context:p},{scrollIntoView:g}])=>{const C=G(!1),S=ze();let N=null;function m(j){Te(i,{align:"end",behavior:j,index:"LAST"})}He(P(at(P(he(s),fs(1)),c),Ie(he(C),o,l,b),re(([[j,H],v,k,I,$])=>{let D=H&&I,q="auto";return D&&(q=rd(v,k||$),D=D&&q!==!1),{followOutputBehavior:q,shouldFollow:D,totalCount:j}}),fe(({shouldFollow:j})=>j)),({followOutputBehavior:j,totalCount:H})=>{N!==null&&(N(),N=null),Xe(a)!==void 0?requestAnimationFrame(()=>{Xe(x)("following output to ",{totalCount:H},nt.DEBUG),m(j)}):N=Mt(t,()=>{Xe(x)("following output to ",{totalCount:H},nt.DEBUG),m(j),N=null})});function w(j){const H=Mt(n,v=>{j&&!v.atBottom&&v.notAtBottomBecause==="SIZE_INCREASED"&&N===null&&(Xe(x)("scrolling to bottom due to increased size",{},nt.DEBUG),m("auto"))});setTimeout(H,100)}He(P(at(he(C),s,d),fe(([j,,H])=>j!==!1&&H),Ot(({value:j},[,H])=>({refreshed:j===H,value:H}),{refreshed:!1,value:0}),fe(({refreshed:j})=>j),Ie(C,s)),([,j])=>{Xe(l)&&w(j!==!1)}),He(S,()=>{w(Xe(C)!==!1)}),He(at(he(C),n),([j,H])=>{j!==!1&&!H.atBottom&&H.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&m("auto")});const y=G(null),R=ze();return ce(ir(P(he(r),re(j=>j?.length??0)),P(he(s))),R),He(P(at(P(R,fs(1)),c),Ie(he(y),l,b,p),re(([[j,H],v,k,I,$])=>H&&k&&v?.({context:$,totalCount:j,scrollingInProgress:I})),fe(j=>!!j),qt(0)),j=>{N!==null&&(N(),N=null),Xe(a)!==void 0?requestAnimationFrame(()=>{Xe(x)("scrolling into view",{}),Te(g,j)}):N=Mt(t,()=>{Xe(x)("scrolling into view",{}),Te(g,j),N=null})}),{autoscrollToBottom:S,followOutput:C,scrollIntoViewOnChange:y}},Ke(Qt,ia,na,oa,is,os,bt,di,ui)),od=Be(([{data:t,firstItemIndex:s,gap:a,sizes:r},{initialTopMostItemIndex:n},{initialItemCount:o,listState:i},{didMount:l}])=>(ce(P(l,Ie(o),fe(([,c])=>c!==0),Ie(n,r,s,a,t),re(([[,c],d,x,b,p,g=[]])=>li(c,d,x,b,p,g))),i),{}),Ke(Qt,oa,vs,is),{singleton:!0}),id=Be(([{didMount:t},{scrollTo:s},{listState:a}])=>{const r=G(0);return He(P(t,Ie(r),fe(([,n])=>n!==0),re(([,n])=>({top:n}))),n=>{Mt(P(a,fs(1),fe(o=>o.items.length>1)),()=>{requestAnimationFrame(()=>{Te(s,n)})})}),{initialScrollTop:r}},Ke(is,bt,vs),{singleton:!0}),mi=Be(([{scrollVelocity:t}])=>{const s=G(!1),a=ze(),r=G(!1);return ce(P(t,Ie(r,s,a),fe(([n,o])=>o!==!1&&o!==void 0),re(([n,o,i,l])=>{const{enter:c,exit:d}=o;if(i){if(d(n,l))return!1}else if(c(n,l))return!0;return i}),Ye()),s),He(P(at(s,t,a),Ie(r)),([[n,o,i],l])=>{n&&l!==!1&&l!==void 0&&l.change&&l.change(o,i)}),{isSeeking:s,scrollSeekConfiguration:r,scrollSeekRangeChanged:a,scrollVelocity:t}},Ke(ia),{singleton:!0}),Cr=Be(([{scrollContainerState:t,scrollTo:s}])=>{const a=ze(),r=ze(),n=ze(),o=G(!1),i=G(void 0);return ce(P(at(a,r),re(([{scrollTop:l,viewportHeight:c},{offsetTop:d,listHeight:x}])=>({scrollHeight:x,scrollTop:Math.max(0,l-d),viewportHeight:c}))),t),ce(P(s,Ie(r),re(([l,{offsetTop:c}])=>({...l,top:l.top+c}))),n),{customScrollParent:i,useWindowScroll:o,windowScrollContainerState:a,windowScrollTo:n,windowViewportRect:r}},Ke(bt)),ld=Be(([{sizeRanges:t,sizes:s},{headerHeight:a,scrollTop:r},{initialTopMostItemIndex:n},{didMount:o},{useWindowScroll:i,windowScrollContainerState:l,windowViewportRect:c}])=>{const d=ze(),x=G(void 0),b=G(null),p=G(null);return ce(l,b),ce(c,p),He(P(d,Ie(s,r,i,b,p,a)),([g,C,S,N,m,w,y])=>{const R=Vc(C.sizeTree);N&&m!==null&&w!==null&&(S=m.scrollTop-w.offsetTop),S-=y,g({ranges:R,scrollTop:S})}),ce(P(x,fe(br),re(cd)),n),ce(P(o,Ie(x),fe(([,g])=>g!==void 0),Ye(),re(([,g])=>g.ranges)),t),{getState:d,restoreStateFrom:x}},Ke(Qt,bt,oa,is,Cr));function cd(t){return{align:"start",index:0,offset:t.scrollTop}}const dd=Be(([{topItemsIndexes:t}])=>{const s=G(0);return ce(P(s,fe(a=>a>=0),re(a=>Array.from({length:a}).map((r,n)=>n))),t),{topItemCount:s}},Ke(vs));function xi(t){let s=!1,a;return(()=>(s||(s=!0,a=t()),a))}const ud=xi(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),md=Be(([{deviation:t,scrollBy:s,scrollingInProgress:a,scrollTop:r},{isAtBottom:n,isScrolling:o,lastJumpDueToItemResize:i,scrollDirection:l},{listState:c},{beforeUnshiftWith:d,gap:x,shiftWithOffset:b,sizes:p},{log:g},{recalcInProgress:C}])=>{const S=jt(P(c,Ie(i),Ot(([,m,w,y],[{bottom:R,items:j,offsetBottom:H,totalCount:v},k])=>{const I=R+H;let $=0;return w===v&&m.length>0&&j.length>0&&(j[0].originalIndex===0&&m[0].originalIndex===0||($=I-y,$!==0&&($+=k))),[$,j,v,I]},[0,[],0,0]),fe(([m])=>m!==0),Ie(r,l,a,n,g,C),fe(([,m,w,y,,,R])=>!R&&!y&&m!==0&&w===Zs),re(([[m],,,,,w])=>(w("Upward scrolling compensation",{amount:m},nt.DEBUG),m))));function N(m){m>0?(Te(s,{behavior:"auto",top:-m}),Te(t,0)):(Te(t,0),Te(s,{behavior:"auto",top:-m}))}return He(P(S,Ie(t,o)),([m,w,y])=>{y&&ud()?Te(t,w-m):N(-m)}),He(P(at(ht(o,!1),t,C),fe(([m,w,y])=>!m&&!y&&w!==0),re(([m,w])=>w),qt(1)),N),ce(P(b,re(m=>({top:-m}))),s),He(P(d,Ie(p,x),re(([m,{groupIndices:w,lastSize:y,sizeTree:R},j])=>{function H(D){return D*(y+j)}if(w.length===0)return H(m);let v=0;const k=Ks(R,0);let I=0,$=0;for(;Im&&(v-=k,D=m-I+1),I+=D,v+=H(D),$++}return v})),m=>{Te(t,m),requestAnimationFrame(()=>{Te(s,{top:m}),requestAnimationFrame(()=>{Te(t,0),Te(C,!1)})})}),{deviation:t}},Ke(bt,ia,vs,Qt,os,Nr)),xd=Be(([t,s,a,r,n,o,i,l,c,d,x])=>({...t,...s,...a,...r,...n,...o,...i,...l,...c,...d,...x}),Ke(kr,od,is,mi,ci,id,sd,Cr,ui,os,di)),pi=Be(([{data:t,defaultItemSize:s,firstItemIndex:a,fixedItemSize:r,fixedGroupSize:n,gap:o,groupIndices:i,heightEstimates:l,itemSize:c,sizeRanges:d,sizes:x,statefulTotalCount:b,totalCount:p,trackItemSizes:g},{initialItemFinalLocationReached:C,initialTopMostItemIndex:S,scrolledToInitialItem:N},m,w,y,R,{scrollToIndex:j},H,{topItemCount:v},{groupCounts:k},I])=>{const{listState:$,minOverscanItemCount:D,topItemsIndexes:q,rangeChanged:Q,...A}=R;return ce(Q,I.scrollSeekRangeChanged),ce(P(I.windowViewportRect,re(U=>U.visibleHeight)),m.viewportHeight),{data:t,defaultItemHeight:s,firstItemIndex:a,fixedItemHeight:r,fixedGroupHeight:n,gap:o,groupCounts:k,heightEstimates:l,initialItemFinalLocationReached:C,initialTopMostItemIndex:S,scrolledToInitialItem:N,sizeRanges:d,topItemCount:v,topItemsIndexes:q,totalCount:p,...y,groupIndices:i,itemSize:c,listState:$,minOverscanItemCount:D,scrollToIndex:j,statefulTotalCount:b,trackItemSizes:g,rangeChanged:Q,...A,...I,...m,sizes:x,...w}},Ke(Qt,oa,bt,ld,nd,vs,na,md,dd,ni,xd));function pd(t,s){const a={},r={};let n=0;const o=t.length;for(;n(m[w]=y=>{const R=N[s.methods[w]];Te(R,y)},m),{})}function x(N){return i.reduce((m,w)=>(m[w]=_c(N[s.events[w]]),m),{})}const b=le.forwardRef(function(N,m){const{children:w,...y}=N,[R]=le.useState(()=>za(Mc(t),v=>{c(v,y)})),[j]=le.useState(_n(x,R));ua(()=>{for(const v of i)v in y&&He(j[v],y[v]);return()=>{Object.values(j).map(vr)}},[y,j,R]),ua(()=>{c(R,y)}),le.useImperativeHandle(m,En(d(R)));const H=a;return e.jsx(l.Provider,{value:R,children:a!==void 0?e.jsx(H,{...pd([...r,...n,...i],y),children:w}):w})}),p=N=>{const m=le.useContext(l);return le.useCallback(w=>{Te(m[N],w)},[m,N])},g=N=>{const m=le.useContext(l)[N],w=le.useCallback(y=>He(m,y),[m]);return le.useSyncExternalStore(w,()=>Xe(m),()=>Xe(m))},C=N=>{const m=le.useContext(l)[N],[w,y]=le.useState(_n(Xe,m));return ua(()=>He(m,R=>{R!==w&&y(En(R))}),[m,w]),w},S=parseInt(le.version)>=18?g:C;return{Component:b,useEmitter:(N,m)=>{const w=le.useContext(l)[N];ua(()=>He(w,m),[m,w])},useEmitterValue:S,usePublisher:p}}const fi=le.createContext(void 0),gi=le.createContext(void 0),Wa="-webkit-sticky",Pn="sticky",Tr=xi(()=>{if(typeof document>"u")return Pn;const t=document.createElement("div");return t.style.position=Wa,t.style.position===Wa?Wa:Pn}),bi=typeof document<"u"?le.useLayoutEffect:le.useEffect;function qa(t){return"self"in t}function hd(t){return"body"in t}function vi(t,s,a,r=Ls,n,o){const i=le.useRef(null),l=le.useRef(null),c=le.useRef(null),d=le.useCallback(p=>{let g,C,S;const N=p.target;if(hd(N)||qa(N)){const w=qa(N)?N:N.defaultView;S=o===!0?w.scrollX:w.scrollY,g=o===!0?w.document.documentElement.scrollWidth:w.document.documentElement.scrollHeight,C=o===!0?w.innerWidth:w.innerHeight}else S=o===!0?N.scrollLeft:N.scrollTop,g=o===!0?N.scrollWidth:N.scrollHeight,C=o===!0?N.offsetWidth:N.offsetHeight;const m=()=>{t({scrollHeight:g,scrollTop:Math.max(S,0),viewportHeight:C})};p.suppressFlushSync===!0?m():sr.flushSync(m),l.current!==null&&(S===l.current||S<=0||S===g-C)&&(l.current=null,s(!0),c.current&&(clearTimeout(c.current),c.current=null))},[t,s,o]);le.useEffect(()=>{const p=n||i.current;return r(n||i.current),d({suppressFlushSync:!0,target:p}),p.addEventListener("scroll",d,{passive:!0}),()=>{r(null),p.removeEventListener("scroll",d)}},[i,d,a,r,n]);function x(p){const g=i.current;if(!g||(o===!0?"offsetWidth"in g&&g.offsetWidth===0:"offsetHeight"in g&&g.offsetHeight===0))return;const C=p.behavior==="smooth";let S,N,m;qa(g)?(N=Math.max(rs(g.document.documentElement,o===!0?"width":"height"),o===!0?g.document.documentElement.scrollWidth:g.document.documentElement.scrollHeight),S=o===!0?g.innerWidth:g.innerHeight,m=o===!0?window.scrollX:window.scrollY):(N=g[o===!0?"scrollWidth":"scrollHeight"],S=rs(g,o===!0?"width":"height"),m=g[o===!0?"scrollLeft":"scrollTop"]);const w=N-S;if(p.top=Math.ceil(Math.max(Math.min(w,p.top),0)),ii(S,N)||p.top===m){t({scrollHeight:N,scrollTop:m,viewportHeight:S}),C&&s(!0);return}C?(l.current=p.top,c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{c.current=null,l.current=null,s(!0)},1e3)):l.current=null,o===!0&&(p={...p.behavior!==void 0?{behavior:p.behavior}:{},left:p.top}),g.scrollTo(p)}function b(p){o===!0&&(p={...p.behavior!==void 0?{behavior:p.behavior}:{},...p.top!==void 0?{left:p.top}:{}}),i.current.scrollBy(p)}return{scrollByCallback:b,scrollerRef:i,scrollToCallback:x}}function Ir(t){return t}const fd=Be(()=>{const t=G(l=>`Item ${l}`),s=G(l=>`Group ${l}`),a=G({}),r=G(Ir),n=G("div"),o=G(Ls),i=(l,c=null)=>ht(P(a,re(d=>d[l]),Ye()),c);return{components:a,computeItemKey:r,EmptyPlaceholder:i("EmptyPlaceholder"),FooterComponent:i("Footer"),GroupComponent:i("Group","div"),groupContent:s,HeaderComponent:i("Header"),HeaderFooterTag:n,ItemComponent:i("Item","div"),itemContent:t,ListComponent:i("List","div"),ScrollerComponent:i("Scroller","div"),scrollerRef:o,ScrollSeekPlaceholder:i("ScrollSeekPlaceholder"),TopItemListComponent:i("TopItemList")}}),gd=Be(([t,s])=>({...t,...s}),Ke(pi,fd)),bd=({height:t})=>e.jsx("div",{style:{height:t}}),vd={overflowAnchor:"none",position:Tr(),zIndex:1},wi={overflowAnchor:"none"},wd={...wi,display:"inline-block",height:"100%"},Hn=le.memo(function({showTopList:t=!1}){const s=ye("listState"),a=kt("sizeRanges"),r=ye("useWindowScroll"),n=ye("customScrollParent"),o=kt("windowScrollContainerState"),i=kt("scrollContainerState"),l=n||r?o:i,c=ye("itemContent"),d=ye("context"),x=ye("groupContent"),b=ye("trackItemSizes"),p=ye("itemSize"),g=ye("log"),C=kt("gap"),S=ye("horizontalDirection"),{callbackRef:N}=Ac(a,p,b,t?Ls:l,g,C,n,S,ye("skipAnimationFrameInResizeObserver")),[m,w]=le.useState(0);_r("deviation",A=>{m!==A&&w(A)});const y=ye("EmptyPlaceholder"),R=ye("ScrollSeekPlaceholder")??bd,j=ye("ListComponent"),H=ye("ItemComponent"),v=ye("GroupComponent"),k=ye("computeItemKey"),I=ye("isSeeking"),$=ye("groupIndices").length>0,D=ye("alignToBottom"),q=ye("initialItemFinalLocationReached"),Q=t?{}:{boxSizing:"border-box",...S?{display:"inline-block",height:"100%",marginLeft:m!==0?m:D?"auto":0,paddingLeft:s.offsetTop,paddingRight:s.offsetBottom,whiteSpace:"nowrap"}:{marginTop:m!==0?m:D?"auto":0,paddingBottom:s.offsetBottom,paddingTop:s.offsetTop},...q?{}:{visibility:"hidden"}};return!t&&s.totalCount===0&&y!==null&&y!==void 0?e.jsx(y,{...pt(y,d)}):e.jsx(j,{...pt(j,d),"data-testid":t?"virtuoso-top-item-list":"virtuoso-item-list",ref:N,style:Q,children:(t?s.topItems:s.items).map(A=>{const U=A.originalIndex,ee=k(U+s.firstItemIndex,A.data,d);return I?h.createElement(R,{...pt(R,d),height:A.size,index:A.index,key:ee,type:A.type||"item",...A.type==="group"?{}:{groupIndex:A.groupIndex}}):A.type==="group"?h.createElement(v,{...pt(v,d),"data-index":U,"data-item-index":A.index,"data-known-size":A.size,key:ee,style:vd},x(A.index,d)):h.createElement(H,{...pt(H,d),...Sd(H,A.data),"data-index":U,"data-item-group-index":A.groupIndex,"data-item-index":A.index,"data-known-size":A.size,key:ee,style:S?wd:wi},$?c(A.index,A.groupIndex,A.data,d):c(A.index,A.data,d))})})}),Nd={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},jd={outline:"none",overflowX:"auto",position:"relative"},Er=t=>({height:"100%",position:"absolute",top:0,width:"100%",...t?{display:"flex",flexDirection:"column"}:void 0}),Ni=(t,s,a=0)=>({...Er(t),position:s?"relative":"absolute",top:s?-a:0}),yd={position:Tr(),top:0,width:"100%",zIndex:1};function pt(t,s){if(typeof t!="string")return{context:s}}function Sd(t,s){return{item:typeof t=="string"?void 0:s}}const kd=le.memo(function(){const t=ye("HeaderComponent"),s=kt("headerHeight"),a=ye("HeaderFooterTag"),r=bs(le.useMemo(()=>o=>{s(rs(o,"height"))},[s]),!0,ye("skipAnimationFrameInResizeObserver")),n=ye("context");return t!=null?e.jsx(a,{ref:r,children:e.jsx(t,{...pt(t,n)})}):null}),Cd=le.memo(function(){const t=ye("FooterComponent"),s=kt("footerHeight"),a=ye("HeaderFooterTag"),r=bs(le.useMemo(()=>o=>{s(rs(o,"height"))},[s]),!0,ye("skipAnimationFrameInResizeObserver")),n=ye("context");return t!=null?e.jsx(a,{ref:r,children:e.jsx(t,{...pt(t,n)})}):null});function ji({useEmitter:t,useEmitterValue:s,usePublisher:a}){return le.memo(function({children:r,style:n,context:o,...i}){const l=a("scrollContainerState"),c=s("ScrollerComponent"),d=a("smoothScrollTargetReached"),x=s("scrollerRef"),b=s("horizontalDirection")||!1,{scrollByCallback:p,scrollerRef:g,scrollToCallback:C}=vi(l,d,c,x,void 0,b);return t("scrollTo",C),t("scrollBy",p),e.jsx(c,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:g,style:{...b?jd:Nd,...n},tabIndex:0,...i,...pt(c,o),children:r})})}function yi({useEmitter:t,useEmitterValue:s,usePublisher:a}){return le.memo(function({children:r,style:n,context:o,...i}){const l=a("windowScrollContainerState"),c=s("ScrollerComponent"),d=a("smoothScrollTargetReached"),x=s("totalListHeight"),b=s("deviation"),p=s("customScrollParent"),g=le.useRef(null),C=s("scrollerRef"),{scrollByCallback:S,scrollerRef:N,scrollToCallback:m}=vi(l,d,c,C,p);return bi(()=>(N.current=p||g.current?.ownerDocument.defaultView,()=>{N.current=null}),[N,p]),t("windowScrollTo",m),t("scrollBy",S),e.jsx(c,{ref:g,"data-virtuoso-scroller":!0,style:{position:"relative",...n,...x!==0?{height:x+b}:void 0},...i,...pt(c,o),children:r})})}const Td=({children:t})=>{const s=le.useContext(fi),a=kt("viewportHeight"),r=kt("fixedItemHeight"),n=ye("alignToBottom"),o=ye("horizontalDirection"),i=le.useMemo(()=>Wo(a,c=>rs(c,o?"width":"height")),[a,o]),l=bs(i,!0,ye("skipAnimationFrameInResizeObserver"));return le.useEffect(()=>{s&&(a(s.viewportHeight),r(s.itemHeight))},[s,a,r]),e.jsx("div",{"data-viewport-type":"element",ref:l,style:Er(n),children:t})},Id=({children:t})=>{const s=le.useContext(fi),a=kt("windowViewportRect"),r=kt("fixedItemHeight"),n=ye("customScrollParent"),o=ye("useWindowScroll"),i=ye("topListHeight"),l=Yo(a,n,ye("skipAnimationFrameInResizeObserver")),c=ye("alignToBottom");return le.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:Ni(c,o,i),children:t})},Ed=({children:t})=>{const s=ye("TopItemListComponent")??"div",a=ye("headerHeight"),r={...yd,marginTop:`${a}px`},n=ye("context");return e.jsx(s,{style:r,...pt(s,n),children:t})},_d=le.memo(function(t){const s=ye("useWindowScroll"),a=ye("topItemsIndexes").length>0,r=ye("customScrollParent"),n=ye("context");return e.jsxs(r||s?zd:Md,{...t,context:n,children:[a&&e.jsx(Ed,{children:e.jsx(Hn,{showTopList:!0})}),e.jsxs(r||s?Id:Td,{children:[e.jsx(kd,{}),e.jsx(Hn,{}),e.jsx(Cd,{})]})]})}),{Component:Rd,useEmitter:_r,useEmitterValue:ye,usePublisher:kt}=hi(gd,{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"}},_d),Md=ji({useEmitter:_r,useEmitterValue:ye,usePublisher:kt}),zd=yi({useEmitter:_r,useEmitterValue:ye,usePublisher:kt}),Ld=Rd,Ad=Be(()=>{const t=G(d=>e.jsxs("td",{children:["Item $",d]})),s=G(null),a=G(d=>e.jsxs("td",{colSpan:1e3,children:["Group ",d]})),r=G(null),n=G(null),o=G({}),i=G(Ir),l=G(Ls),c=(d,x=null)=>ht(P(o,re(b=>b[d]),Ye()),x);return{components:o,computeItemKey:i,context:s,EmptyPlaceholder:c("EmptyPlaceholder"),FillerRow:c("FillerRow"),fixedFooterContent:n,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")}});Ke(pi,Ad);Tr();const Gn={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},Dd={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:Qn,floor:Ia,max:qs,min:Ya,round:Vn}=Math;function Un(t,s,a){return Array.from({length:s-t+1}).map((r,n)=>({data:a===null?null:a[n+t],index:n+t}))}function Fd(t){return{...Dd,items:t}}function ma(t,s){return t!==void 0&&t.width===s.width&&t.height===s.height}function $d(t,s){return t!==void 0&&t.column===s.column&&t.row===s.row}const Od=Be(([{increaseViewportBy:t,listBoundary:s,overscan:a,visibleRange:r},{footerHeight:n,headerHeight:o,scrollBy:i,scrollContainerState:l,scrollTo:c,scrollTop:d,smoothScrollTargetReached:x,viewportHeight:b},p,g,{didMount:C,propsReady:S},{customScrollParent:N,useWindowScroll:m,windowScrollContainerState:w,windowScrollTo:y,windowViewportRect:R},j])=>{const H=G(0),v=G(0),k=G(Gn),I=G({height:0,width:0}),$=G({height:0,width:0}),D=ze(),q=ze(),Q=G(0),A=G(null),U=G({column:0,row:0}),ee=ze(),ie=ze(),je=G(!1),ge=G(0),Ce=G(!0),de=G(!1),B=G(!1);He(P(C,Ie(ge),fe(([O,X])=>X!==0)),()=>{Te(Ce,!1)}),He(P(at(C,Ce,$,I,ge,de),fe(([O,X,f,T,,E])=>O&&!X&&f.height!==0&&T.height!==0&&!E)),([,,,,O])=>{Te(de,!0),yr(1,()=>{Te(D,O)}),Mt(P(d),()=>{Te(s,[0,0]),Te(Ce,!0)})}),ce(P(ie,fe(O=>O!=null&&O.scrollTop>0),$t(0)),v),He(P(C,Ie(ie),fe(([,O])=>O!=null)),([,O])=>{O&&(Te(I,O.viewport),Te($,O.item),Te(U,O.gap),O.scrollTop>0&&(Te(je,!0),Mt(P(d,fs(1)),X=>{Te(je,!1)}),Te(c,{top:O.scrollTop})))}),ce(P(I,re(({height:O})=>O)),b),ce(P(at(he(I,ma),he($,ma),he(U,(O,X)=>O!==void 0&&O.column===X.column&&O.row===X.row),he(d)),re(([O,X,f,T])=>({gap:f,item:X,scrollTop:T,viewport:O}))),ee),ce(P(at(he(H),r,he(U,$d),he($,ma),he(I,ma),he(A),he(v),he(je),he(Ce),he(ge)),fe(([,,,,,,,O])=>!O),re(([O,[X,f],T,E,W,V,se,,ae,z])=>{const{column:oe,row:ue}=T,{height:ve,width:K}=E,{width:we}=W;if(se===0&&(O===0||we===0))return Gn;if(K===0){const M=Sr(z,O),te=M+Math.max(se-1,0);return Fd(Un(M,te,V))}const We=Si(we,K,oe);let Se,Je;ae?X===0&&f===0&&se>0?(Se=0,Je=se-1):(Se=We*Ia((X+ue)/(ve+ue)),Je=We*Qn((f+ue)/(ve+ue))-1,Je=Ya(O-1,qs(Je,We-1)),Se=Ya(Je,qs(0,Se))):(Se=0,Je=-1);const et=Un(Se,Je,V),{bottom:F,top:Z}=Wn(W,T,E,et),Re=Qn(O/We),Ne=Re*ve+(Re-1)*ue-F;return{bottom:F,itemHeight:ve,items:et,itemWidth:K,offsetBottom:Ne,offsetTop:Z,top:Z}})),k),ce(P(A,fe(O=>O!==null),re(O=>O.length)),H),ce(P(at(I,$,k,U),fe(([O,X,{items:f}])=>f.length>0&&X.height!==0&&O.height!==0),re(([O,X,{items:f},T])=>{const{bottom:E,top:W}=Wn(O,T,X,f);return[W,E]}),Ye(Xs)),s);const Y=G(!1);ce(P(d,Ie(Y),re(([O,X])=>X||O!==0)),Y);const ne=jt(P(at(k,H),fe(([{items:O}])=>O.length>0),Ie(Y),fe(([[O,X],f])=>{const T=O.items[O.items.length-1].index===X-1;return(f||O.bottom>0&&O.itemHeight>0&&O.offsetBottom===0&&O.items.length===X)&&T}),re(([[,O]])=>O-1),Ye())),De=jt(P(he(k),fe(({items:O})=>O.length>0&&O[0].index===0),$t(0),Ye())),Le=jt(P(he(k),Ie(je),fe(([{items:O},X])=>O.length>0&&!X),re(([{items:O}])=>({endIndex:O[O.length-1].index,startIndex:O[0].index})),Ye(ti),qt(0)));ce(Le,g.scrollSeekRangeChanged),ce(P(D,Ie(I,$,H,U),re(([O,X,f,T,E])=>{const W=oi(O),{align:V,behavior:se,offset:ae}=W;let z=W.index;z==="LAST"&&(z=T-1),z=qs(0,z,Ya(T-1,z));let oe=mr(X,E,f,z);return V==="end"?oe=Vn(oe-X.height+f.height):V==="center"&&(oe=Vn(oe-X.height/2+f.height/2)),ae!==void 0&&ae!==0&&(oe+=ae),{behavior:se,top:oe}})),c);const Ge=ht(P(k,re(O=>O.offsetBottom+O.bottom)),0);return ce(P(R,re(O=>({height:O.visibleHeight,width:O.visibleWidth}))),I),{customScrollParent:N,data:A,deviation:Q,footerHeight:n,gap:U,headerHeight:o,increaseViewportBy:t,initialItemCount:v,itemDimensions:$,overscan:a,restoreStateFrom:ie,scrollBy:i,scrollContainerState:l,scrollHeight:q,scrollTo:c,scrollToIndex:D,scrollTop:d,smoothScrollTargetReached:x,totalCount:H,useWindowScroll:m,viewportDimensions:I,windowScrollContainerState:w,windowScrollTo:y,windowViewportRect:R,...g,gridState:k,horizontalDirection:B,initialTopMostItemIndex:ge,totalListHeight:Ge,...p,endReached:ne,propsReady:S,rangeChanged:Le,startReached:De,stateChanged:ee,stateRestoreInProgress:je,...j}},Ke(kr,bt,ia,mi,is,Cr,os));function Si(t,s,a){return qs(1,Ia((t+a)/(Ia(s)+a)))}function Wn(t,s,a,r){const{height:n}=a;if(n===void 0||r.length===0)return{bottom:0,top:0};const o=mr(t,s,a,r[0].index);return{bottom:mr(t,s,a,r[r.length-1].index)+n,top:o}}function mr(t,s,a,r){const n=Si(t.width,a.width,s.column),o=Ia(r/n),i=o*a.height+qs(0,o-1)*s.row;return i>0?i+s.row:i}const Bd=Be(()=>{const t=G(b=>`Item ${b}`),s=G({}),a=G(null),r=G("virtuoso-grid-item"),n=G("virtuoso-grid-list"),o=G(Ir),i=G("div"),l=G(Ls),c=(b,p=null)=>ht(P(s,re(g=>g[b]),Ye()),p),d=G(!1),x=G(!1);return ce(he(x),d),{components:s,computeItemKey:o,context:a,FooterComponent:c("Footer"),HeaderComponent:c("Header"),headerFooterTag:i,itemClassName:r,ItemComponent:c("Item","div"),itemContent:t,listClassName:n,ListComponent:c("List","div"),readyStateChanged:d,reportReadyState:x,ScrollerComponent:c("Scroller","div"),scrollerRef:l,ScrollSeekPlaceholder:c("ScrollSeekPlaceholder","div")}}),Pd=Be(([t,s])=>({...t,...s}),Ke(Od,Bd)),Hd=le.memo(function(){const t=qe("gridState"),s=qe("listClassName"),a=qe("itemClassName"),r=qe("itemContent"),n=qe("computeItemKey"),o=qe("isSeeking"),i=Ct("scrollHeight"),l=qe("ItemComponent"),c=qe("ListComponent"),d=qe("ScrollSeekPlaceholder"),x=qe("context"),b=Ct("itemDimensions"),p=Ct("gap"),g=qe("log"),C=qe("stateRestoreInProgress"),S=Ct("reportReadyState"),N=bs(le.useMemo(()=>m=>{const w=m.parentElement.parentElement.scrollHeight;i(w);const y=m.firstChild;if(y!==null){const{height:R,width:j}=y.getBoundingClientRect();b({height:R,width:j})}p({column:qn("column-gap",getComputedStyle(m).columnGap,g),row:qn("row-gap",getComputedStyle(m).rowGap,g)})},[i,b,p,g]),!0,!1);return bi(()=>{t.itemHeight>0&&t.itemWidth>0&&S(!0)},[t]),C?null:e.jsx(c,{className:s,ref:N,...pt(c,x),"data-testid":"virtuoso-item-list",style:{paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},children:t.items.map(m=>{const w=n(m.index,m.data,x);return o?e.jsx(d,{...pt(d,x),height:t.itemHeight,index:m.index,width:t.itemWidth},w):h.createElement(l,{...pt(l,x),className:a,"data-index":m.index,key:w},r(m.index,m.data,x))})})}),Gd=le.memo(function(){const t=qe("HeaderComponent"),s=Ct("headerHeight"),a=qe("headerFooterTag"),r=bs(le.useMemo(()=>o=>{s(rs(o,"height"))},[s]),!0,!1),n=qe("context");return t!=null?e.jsx(a,{ref:r,children:e.jsx(t,{...pt(t,n)})}):null}),Qd=le.memo(function(){const t=qe("FooterComponent"),s=Ct("footerHeight"),a=qe("headerFooterTag"),r=bs(le.useMemo(()=>o=>{s(rs(o,"height"))},[s]),!0,!1),n=qe("context");return t!=null?e.jsx(a,{ref:r,children:e.jsx(t,{...pt(t,n)})}):null}),Vd=({children:t})=>{const s=le.useContext(gi),a=Ct("itemDimensions"),r=Ct("viewportDimensions"),n=bs(le.useMemo(()=>o=>{r(o.getBoundingClientRect())},[r]),!0,!1);return le.useEffect(()=>{s&&(r({height:s.viewportHeight,width:s.viewportWidth}),a({height:s.itemHeight,width:s.itemWidth}))},[s,r,a]),e.jsx("div",{ref:n,style:Er(!1),children:t})},Ud=({children:t})=>{const s=le.useContext(gi),a=Ct("windowViewportRect"),r=Ct("itemDimensions"),n=qe("customScrollParent"),o=qe("useWindowScroll"),i=Yo(a,n,!1);return le.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:Ni(!1,o),children:t})},Wd=le.memo(function({...t}){const s=qe("useWindowScroll"),a=qe("customScrollParent"),r=a||s?Yd:qd,n=a||s?Ud:Vd,o=qe("context");return e.jsx(r,{...t,...pt(r,o),children:e.jsxs(n,{children:[e.jsx(Gd,{}),e.jsx(Hd,{}),e.jsx(Qd,{})]})})}),{useEmitter:ki,useEmitterValue:qe,usePublisher:Ct}=hi(Pd,{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"}},Wd),qd=ji({useEmitter:ki,useEmitterValue:qe,usePublisher:Ct}),Yd=yi({useEmitter:ki,useEmitterValue:qe,usePublisher:Ct});function qn(t,s,a){return s!=="normal"&&s?.endsWith("px")!==!0&&a(`${t} was not resolved to pixel value correctly`,s,nt.WARN),s==="normal"?0:parseInt(s??"0",10)}function Yn(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 Kn=new Set(["p","h1","h2","h3","h4","h5","h6","li","td","th"]);function Kd(t,s="component",a){const r=t.getBoundingClientRect(),n=[],o=a?.leafTags?new Set([...Kn,...a.leafTags]):Kn,i=a?.captureRoundedBorders??!0,l=a?.excludeTags?new Set(a.excludeTags):null,c=a?.excludeSelectors??null;function d(x){const b=getComputedStyle(x);if(b.display==="none"||b.visibility==="hidden"||b.opacity==="0")return;const p=x.tagName.toLowerCase();if(l?.has(p)||c?.some(I=>x.matches(I)))return;const g=[...x.children].filter(I=>{const $=getComputedStyle(I);return $.display!=="none"&&$.visibility!=="hidden"&&$.opacity!=="0"}),C=p==="img"||p==="svg"||p==="video"||p==="canvas",S=p==="input"||p==="button"||p==="textarea"||p==="select",N=g.length===0||C||S||o.has(p),m=b.backgroundColor,w=m!=="rgba(0, 0, 0, 0)"&&m!=="transparent",y=b.backgroundImage!=="none",R=parseFloat(b.borderTopWidth)||0,j=i&&R>0&&b.borderTopColor!=="rgba(0, 0, 0, 0)"&&b.borderTopColor!=="transparent",H=(parseFloat(b.borderTopLeftRadius)||0)>0,v=w||y||j&&H,k=p==="tr"||p==="td"||p==="th"||p==="thead"||p==="tbody"||p==="table";if(N){const I=x.getBoundingClientRect();if(I.width<1||I.height<1)return;const $=C&&I.width>0&&I.height>0&&Math.abs(I.width-I.height)<4,D=k?0:$?"50%":Xn(b,x)??8,q=r.width;n.push({x:q>0?+((I.left-r.left)/q*100).toFixed(4):0,y:Math.round(I.top-r.top),w:q>0?+(I.width/q*100).toFixed(4):0,h:Math.round(I.height),r:D});return}if(v){const I=x.getBoundingClientRect();if(I.width>=1&&I.height>=1){const $=k?0:Xn(b,x)??8,D=r.width;n.push({x:D>0?+((I.left-r.left)/D*100).toFixed(4):0,y:Math.round(I.top-r.top),w:D>0?+(I.width/D*100).toFixed(4):0,h:Math.round(I.height),r:$,c:!0})}}for(const I of g)d(I)}for(const x of t.children)d(x);return{name:s,viewportWidth:Math.round(r.width),width:Math.round(r.width),height:Math.round(r.height),bones:n}}function Xn(t,s){const a=parseFloat(t.borderTopLeftRadius)||0,r=parseFloat(t.borderTopRightRadius)||0,n=parseFloat(t.borderBottomRightRadius)||0,o=parseFloat(t.borderBottomLeftRadius)||0;if(a===0&&r===0&&n===0&&o===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,n,o)>9998?i?"50%":9999:a===r&&r===n&&n===o?a!==8?a:void 0:`${a}px ${r}px ${n}px ${o}px`}const Xd=new Map;function Jd(t){return Xd.get(t)}function Zd(){typeof window<"u"&&window.__BONEYARD_BUILD&&(window.__BONEYARD_SNAPSHOT=Kd)}function eu(){return typeof window<"u"&&window.__BONEYARD_BUILD===!0}function tu(t,s){if(!("breakpoints"in t))return t;const a=Object.keys(t.breakpoints).map(Number).sort((n,o)=>n-o);if(a.length===0)return null;const r=[...a].reverse().find(n=>s>=n)??a[0];return t.breakpoints[r]??null}const ys={angle:110,start:30,end:70,speed:"2s",lightHighlight:"#f7f7f7",darkHighlight:"#2c2c2c"},Os={speed:"1.8s",lightAdjust:.3,darkAdjust:.02},Jn={web:{light:"#f0f0f0",dark:"#222222"}},su=/rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*(?:,\s*([\d.]+))?\s*\)/;function Zn(t,s){const a=t.match(su);if(a){const[,r,n,o,i="1"]=a,l=Math.min(1,parseFloat(i)+s*.5);return`rgba(${r},${n},${o},${l.toFixed(3)})`}if(t.startsWith("#")&&t.length>=7){const r=parseInt(t.slice(1,3),16),n=parseInt(t.slice(3,5),16),o=parseInt(t.slice(5,7),16);if(!isNaN(r)&&!isNaN(n)&&!isNaN(o)){const i=Math.round(r+(255-r)*s),l=Math.round(n+(255-n)*s),c=Math.round(o+(255-o)*s);return`#${i.toString(16).padStart(2,"0")}${l.toString(16).padStart(2,"0")}${c.toString(16).padStart(2,"0")}`}}return t}Zd();let Ft={};function va({loading:t,children:s,name:a,initialBones:r,color:n,darkColor:o,animate:i,stagger:l=!1,transition:c=!1,boneClass:d,className:x,fallback:b,fixture:p,snapshotConfig:g}){const C=h.useRef(null),S=h.useRef(Math.random().toString(36).slice(2,8)).current,[N,m]=h.useState(0),[w,y]=h.useState(0),[R,j]=h.useState(!1);h.useEffect(()=>{if(typeof window>"u")return;const f=()=>{const W=document.documentElement.classList.contains("dark")||!!C.current?.closest(".dark");j(W)};f();const T=new MutationObserver(f);T.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]});const E=window.matchMedia("(prefers-color-scheme: dark)");return E.addEventListener("change",f),()=>{T.disconnect(),E.removeEventListener("change",f)}},[]);const H=n??Ft.color??Jn.web.light,v=o??Ft.darkColor??Jn.web.dark,k=R?v:H,I=i??Ft.animate??"pulse",$=I===!0?"pulse":I===!1?"solid":I;h.useEffect(()=>{const f=C.current;if(!f)return;const T=new ResizeObserver(W=>{const V=W[0]?.contentRect;m(Math.round(V?.width??0)),V&&V.height>0&&y(Math.round(V.height))});T.observe(f);const E=f.getBoundingClientRect();return m(Math.round(E.width)),E.height>0&&y(Math.round(E.height)),()=>T.disconnect()},[]);const D={};if(a&&(D["data-boneyard"]=a,g&&(D["data-boneyard-config"]=JSON.stringify(g))),eu())return e.jsx("div",{ref:C,className:x,style:{position:"relative"},...D,children:e.jsx("div",{children:p??s})});const[q,Q]=h.useState(!1);h.useLayoutEffect(()=>{Q(!0)},[]);const A=r??(a?Jd(a):void 0),U=q&&typeof window<"u"?window.innerWidth:0,ee=N>0?N:U,ie=A&&ee>0?tu(A,ee):null,je=d??Ft.boneClass,ge=(()=>{const f=l??Ft.stagger;return f===!0?80:f===!1||!f?0:f})(),Ce=(()=>{const f=c??Ft.transition;return f===!0?300:f===!1||!f?0:f})(),[de,B]=h.useState(!1),Y=h.useRef(t),ne=h.useRef(null);h.useEffect(()=>(Y.current&&!t&&Ce>0&&ie&&(ne.current&&clearTimeout(ne.current),B(!0),ne.current=setTimeout(()=>{B(!1),ne.current=null},Ce)),Y.current=t,()=>{ne.current&&clearTimeout(ne.current)}),[t,Ce,ie]);const De=(t||de)&&ie,Le=t&&!ie&&!de,Ge=w>0?w:ie?.height??0,O=ie?.height??0,X=Ge>0&&O>0?Ge/O:1;return e.jsxs("div",{ref:C,className:x,style:{position:"relative"},...D,children:[e.jsx("div",{"data-boneyard-content":"true",style:De&&!de?{visibility:"hidden"}:void 0,children:Le?b:s}),De&&e.jsx("div",{"data-boneyard-overlay":"true",style:{position:"absolute",inset:0,overflow:"hidden",opacity:de?0:1,transition:Ce>0?`opacity ${Ce}ms ease-out`:void 0},children:e.jsxs("div",{style:{position:"relative",width:"100%",height:"100%"},children:[ie.bones.filter(f=>!Yn(f).c).map((f,T)=>{const E=Yn(f),W=k;Zn(k,R?Os.darkAdjust:Os.lightAdjust);const V=E.w/100*(ie.width??0),se=E.r==="50%"&&Math.abs(V-E.h)<4,ae={position:"absolute",left:`${E.x}%`,top:E.y*X,width:se?E.h*X:`${E.w}%`,height:E.h*X,borderRadius:typeof E.r=="string"?E.r:`${E.r}px`,backgroundColor:W},z=Ft.speed;if($==="pulse")ae.animation=`bp-${S} ${z??Os.speed} ease-in-out infinite`;else if($==="shimmer"){const oe=R?Ft.darkShimmerColor??ys.darkHighlight:Ft.shimmerColor??ys.lightHighlight,ue=Ft.shimmerAngle??ys.angle;delete ae.backgroundColor,ae.backgroundImage=`linear-gradient(${ue}deg, ${W} ${ys.start}%, ${oe} 50%, ${W} ${ys.end}%)`,ae.backgroundSize="200% 100%",ae.animation=`bs-${S} ${z??ys.speed} linear infinite`}return ge>0&&(ae.opacity=0,ae.animation=`${ae.animation?ae.animation+",":""} by-${S} 0.3s ease-out ${T*ge}ms forwards`),e.jsx("div",{"data-boneyard-bone":"true",className:je,style:ae},T)}),$==="pulse"&&e.jsx("style",{children:`@keyframes bp-${S}{0%,100%{background-color:${k}}50%{background-color:${Zn(k,R?Os.darkAdjust:Os.lightAdjust)}}}`}),$==="shimmer"&&e.jsx("style",{children:`@keyframes bs-${S}{0%{background-position:200% 0}100%{background-position:-200% 0}}`}),ge>0&&e.jsx("style",{children:`@keyframes by-${S}{from{opacity:0}to{opacity:1}}`})]})})]})}const au=({isOpen:t,onClose:s,onViewAll:a})=>{const{notifications:r,markAsRead:n,markAllAsRead:o,unreadCount:i}=Io(),l=r.slice(0,5),c=x=>{switch(x){case"sparkles":case"achievement_unlocked":case"level_up":return e.jsx(ss,{className:"w-4 h-4"});case"alert-circle":case"risk_alert":case"system_alert":return e.jsx(aa,{className:"w-4 h-4"});case"check-circle-2":case"quiz_result":return e.jsx(Ra,{className:"w-4 h-4"});case"users":case"new_assignment":return e.jsx(Rt,{className:"w-4 h-4"});default:return e.jsx(Rs,{className:"w-4 h-4"})}},d=x=>{switch(x){case"sparkles":case"achievement_unlocked":case"level_up":return"from-[#a855f7] to-[#9333ea] text-white bg-purple-50/30";case"alert-circle":case"risk_alert":case"system_alert":return"from-[#f43f5e] to-[#e11d48] text-white bg-rose-50/30";case"check-circle-2":case"quiz_result":return"bg-emerald-50 text-emerald-500 border border-emerald-100";case"users":case"new_assignment":return"bg-blue-50 text-blue-500 border border-blue-100";default:return"bg-slate-50 text-slate-500 border border-slate-100"}};return e.jsx(Bt,{children:t&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[90]",onClick:s}),e.jsxs(Pe.div,{initial:{opacity:0,scale:.95,y:-10,x:10},animate:{opacity:1,scale:1,y:0,x:0},exit:{opacity:0,scale:.95,y:-10,x:10},className:"fixed top-[80px] right-[24px] xl:right-[32px] w-[380px] bg-white/95 backdrop-blur-xl rounded-[20px] shadow-[0_8px_32px_rgba(0,0,0,0.12)] border border-white z-[100] flex flex-col overflow-hidden origin-top-right",children:[e.jsxs("div",{className:"p-4 border-b border-[#f1f5f9] flex justify-between items-center bg-white/50",children:[e.jsx("h3",{className:"text-[16px] font-bold text-[#1e293b]",children:"Notifications"}),e.jsxs("button",{onClick:()=>o(),disabled:i===0,className:"text-[12px] font-bold text-[#a855f7] hover:text-[#9333ea] transition-colors flex items-center gap-1.5 disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:text-[#a855f7]",children:[e.jsx(Ao,{className:"w-3.5 h-3.5"})," Mark all as read"]})]}),e.jsx("div",{className:"max-h-[360px] overflow-y-auto no-scrollbar flex flex-col divide-y divide-[#f1f5f9]",children:l.length>0?l.map(x=>e.jsxs("div",{onClick:()=>{n(x.id)},className:`p-4 hover:bg-slate-50 transition-colors cursor-pointer flex gap-3 ${x.isRead?"opacity-70":d(x.type).split(" ")[2]}`,children:[e.jsx("div",{className:`w-8 h-8 rounded-full flex items-center justify-center shrink-0 shadow-sm ${d(x.type).split(" ").slice(0,2).join(" ")}`,children:c(x.type)}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex justify-between items-start mb-0.5",children:[e.jsx("h4",{className:"text-[13px] font-bold text-[#1e293b]",children:x.title}),!x.isRead&&e.jsx("span",{className:"w-2 h-2 rounded-full bg-[#a855f7] shadow-[0_0_4px_rgba(168,85,247,0.6)] mt-1"})]}),e.jsx("p",{className:"text-[12px] text-[#475569] line-clamp-2 leading-relaxed",children:x.message}),e.jsxs("span",{className:`text-[10px] font-bold mt-1 block ${x.isRead?"text-[#94a3b8]":"text-[#a855f7]"}`,children:[Fo(x.createdAt)," ago"]})]})]},x.id)):e.jsxs("div",{className:"p-8 text-center",children:[e.jsx(Rs,{className:"w-8 h-8 text-[#94a3b8] mx-auto mb-2 opacity-20"}),e.jsx("p",{className:"text-[13px] font-medium text-[#64748b]",children:"No new notifications"})]})}),e.jsx("div",{className:"p-3 border-t border-[#f1f5f9] bg-white",children:e.jsxs("button",{onClick:()=>{a(),s()},className:"w-full py-2 bg-purple-50 text-[#9333ea] hover:bg-purple-100 transition-colors rounded-xl text-[13px] font-bold flex items-center justify-center gap-2",children:["View All Notifications ",e.jsx(cl,{className:"w-4 h-4"})]})})]})]})})};async function Rr(t){const s=Xt(st,"managedStudents");try{const o=Ht(s,Gt("teacherId","==",t)),i=await ts(o);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 Ti(t)).map(o=>o.id);if(r.length===0)return[];const n=new Map;for(let o=0;o{n.set(d.id,{id:d.id,...d.data()})})}return Array.from(n.values()).sort((o,i)=>String(o.name||"").localeCompare(String(i.name||"")))}async function ru(t,s,a){const r=vt(st,"managedStudents",t);await Kt(r,{riskLevel:s,...a!==void 0?{riskConfidence:a}:{},updatedAt:ft()})}async function Ci(t,s,a){const r=zt(s,a),n=vt(st,"managedStudents",t);await Kt(n,{grade:s,section:a,classSectionId:r,updatedAt:ft()})}function zt(t,s){return[t,s].filter(Boolean).join("_").replace(/\s+/g,"_").toLowerCase()}function xr(t){const s=Object.entries(t).filter(([,a])=>a!==void 0);return Object.fromEntries(s)}function ws(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 As(t){const a=ws(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 Ds(t,s){const a=`${t||""} ${s||""}`.toUpperCase();if(!a.trim())return null;const r=["STEM","ABM","HUMSS","GAS","TVL","ICT"];for(const n of r)if(new RegExp(`\\b${n}\\b`).test(a))return n;return null}function Pt(t){const s=(t||"").trim();if(!s)return{grade:"Grade 11",section:"Section A"};const[a="Grade 11",r="Section A"]=s.split(" - ").map(n=>n.trim());return{grade:a||"Grade 11",section:r||"Section A"}}function mt(t){const s=t.metadata||{},a=t.className||s.className,r=Pt(a),n=(t.grade||s.grade||r.grade||"").trim()||null,o=(t.section||s.section||r.section||"").trim()||null,i=(t.classSectionId||s.classSectionId||"").trim()||(n&&o?zt(n,o):"")||null,l=(a||"").trim()||(n&&o?`${n} - ${o}`:"")||null,c=ws(t.gradeLevel||s.gradeLevel||n),d=(t.classification||s.classification||"").trim()||As(c)||null,x=(t.strand||s.strand||"").trim()||Ds(l,o)||null;return{classSectionId:i,className:l,grade:n,section:o,gradeLevel:c,classification:d,strand:x,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 nu(t){const s=(t.className||"").trim(),[a="",r=""]=s.split(" - "),n=(t.grade||a||"").trim()||null,o=(t.section||r||"").trim()||null,i=(t.classSectionId||"").trim()||(n&&o?zt(n,o):"")||null,l=s||(n&&o?`${n} - ${o}`:null),c=ws(t.gradeLevel||n),d=(t.classification||"").trim()||As(c),x=(t.strand||"").trim()||Ds(l,o);return{classSectionId:i,className:l,grade:n,section:o,gradeLevel:c,classification:d,strand:x,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 Ti(t){const s=Xt(st,"classrooms"),a=new Map,r=Ht(s,Gt("teacherId","==",t));(await ts(r)).docs.forEach(l=>{a.set(l.id,{id:l.id,...l.data()})});const o=Ht(s,Gt("managerId","==",t));return(await ts(o)).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 Ii(t){const s=t.classSectionId||zt(t.grade,t.section),a=vt(st,"classSectionOwnership",s),r=await Cs(a),n=r.exists()?r.data().studentUids||[]:[],o=Array.from(new Set([...t.studentUids||[],...n])),i=xr(t);return r.exists()?await Kt(a,{...i,classSectionId:s,studentUids:o,updatedAt:ft()}):await Zt(a,{...i,classSectionId:s,studentUids:o,createdAt:ft(),updatedAt:ft()}),s}async function ou(t){const s=(t.classSectionId||"").trim()||zt(t.grade,t.section),a=(t.className||"").trim()||`${t.grade} - ${t.section}`,r=nu({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 Ii({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 n=Xt(st,"classrooms"),o=Ht(n,Gt("classSectionId","==",s)),i=await ts(o);if(i.empty){const l=xr({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:ft(),updatedAt:ft()});await Zt(vt(st,"classrooms",s),l,{merge:!0})}else for(const l of i.docs){const c=xr({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:ft()});await Kt(l.ref,c)}return s}async function Ei(t,s,a,r,n,o){const i=zt(s,a);await Ii({classSectionId:i,grade:s,section:a,schoolYear:n,ownerTeacherId:r,ownerTeacherName:o,studentUids:[t]}),await Zt(vt(st,"users",t),{grade:s,section:a,classSectionId:i,adviserTeacherId:r,adviserTeacherName:o||"",updatedAt:ft()},{merge:!0})}async function iu(t){const s=Xt(st,"classSectionOwnership"),a=new Map,r=Ht(s,Gt("ownerTeacherId","==",t));(await ts(r)).docs.forEach(l=>{a.set(l.id,{id:l.id,...l.data()})});const o=Ht(s,Gt("managerId","==",t));return(await ts(o)).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 lu(t="",s=25){const a=Xt(st,"users"),r=Math.max(1,Math.min(100,s)),n=Ht(a,Gt("role","==","teacher"),zo(r*4)),o=await ts(n),i=t.trim().toLowerCase();return o.docs.map(c=>{const d=c.data(),x=String(d.name||"").trim(),b=String(d.email||"").trim();return{uid:c.id,name:x||"Teacher",email:b,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 cu(t,s,a=20){if(t.length===0)return s([]),()=>{};const r=Xt(st,"activities"),n=Ht(r,Gt("classroomId","in",t),bl("timestamp","desc"));return Lo(n,o=>{const i=o.docs.slice(0,a).map(l=>({id:l.id,...l.data()}));s(i)})}async function du(t,s,a){const r=vt(Xt(st,"generatedLessonPlans"));return await Zt(r,{...t,teacherId:s,teacherName:a?.teacherName||null,studentId:a?.studentId||null,studentName:a?.studentName||null,status:"draft",createdAt:ft(),updatedAt:ft()}),r.id}async function uu(t){const s=vt(st,"generatedLessonPlans",t),a=await Cs(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 Kt(s,{status:"published",publishedAt:ft(),updatedAt:ft()})}async function mu(t,s=!0){const a=t.learningCompetency||t.lessonTitle||t.focusTopics&&t.focusTopics[0]||"general mathematics",r=t.subject||"general_math",n=t.quarter??1;let o="",i=[],l,c,d,x=!1;if(s)try{const g=await dl(a,r,n,{lessonTitle:t.lessonTitle,learningCompetency:t.learningCompetency,moduleUnit:t.moduleUnit,learnerLevel:t.learnerLevel});i=g.sources||[],o=g.explanation||"",l=g.retrievalConfidence,c=g.retrievalBand,d=g.retrievalQuery,x=g.needsReview??!1}catch{o="",i=[]}const b={...t,subject:r,quarter:n,curriculumContext:o?`[CURRICULUM CONTEXT] +${o}`:void 0,curriculumRetrievalConfidence:l,curriculumRetrievalBand:c,curriculumRetrievalQuery:d,needsReview:x};return{...await Ze.generateLessonPlan(b),curriculumSources:i,curriculumContext:o}}const xu=ol("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 pu({className:t,variant:s,asChild:a=!1,...r}){const n=a?_l:"span";return e.jsx(n,{"data-slot":"badge",className:Eo(xu({variant:s}),t),...r})}function hu(t){return t.length<=42?t:`${t.slice(0,18)}...${t.slice(-20)}`}const eo=({sources:t=[],className:s})=>t.length?e.jsxs(Rl,{children:[e.jsx(Ml,{asChild:!0,children:e.jsxs(pu,{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(Lt,{size:12}),"DepEd Aligned"]})}),e.jsxs(zl,{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:[hu(a.sourceFile)," | p.",a.page]}),e.jsxs("p",{className:"text-[#5a6578]",children:["Similarity: ",(a.score*100).toFixed(1),"%"]})]},`${a.sourceFile}-${a.page}-${r}`))})]})]}):null,fu=[{level:"Remember",icon:ar,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:Lt,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:ul,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:ec,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"}],gu=({isOpen:t,onClose:s})=>t?e.jsx(Bt,{children:t&&e.jsx(Pe.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(Pe.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(_o,{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(ps,{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:fu.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(nc,{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,bu={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"},xa={identification:{label:"Identification",icon:e.jsx(Wt,{size:16}),description:"Define or identify concepts"},enumeration:{label:"Enumeration",icon:e.jsx(ya,{size:16}),description:"List steps or properties"},multiple_choice:{label:"Multiple Choice",icon:e.jsx(Ut,{size:16}),description:"Choose from 4 options"},word_problem:{label:"Word Problem",icon:e.jsx(Lt,{size:16}),description:"Real-world scenarios"},equation_based:{label:"Equation-Based",icon:e.jsx(ml,{size:16}),description:"Solve equations"}},to={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"}},vu=["Grade 11","Grade 12"],Ka=t=>{const s=(t||"").trim().toLowerCase();return s==="grade 12"||s==="12"||s.includes("12")?"Grade 12":"Grade 11"},wu={"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"]}},Nu={"Grade 11":["General Mathematics - "],"Grade 12":["Pre-Calculus - ","Basic Calculus - "]},so=(t,s)=>{const a=Nu[s];return Object.fromEntries(Object.entries(t).filter(([r])=>a.some(n=>r.startsWith(n))))},Bs=30,Ps=12,Xa="mathpulse:quiz-maker:active-task",ju={easy:"text-green-600",medium:"text-rose-600",hard:"text-red-600"},_i=({onBack:t,gradeLevel:s,selectedClassId:a,selectedClassName:r,onOpenNotifications:n,onOpenProfile:o,onOpenInsightModal:i,userPhoto:l,teacherName:c,drawerMode:d=!1,onQuizSaved:x,onQuizGenerating:b})=>{const{currentUser:p,loading:g}=gs(),C=h.useMemo(()=>Ze.getImportGroundedRolloutFlags(),[]),[S,N]=h.useState("create"),[m,w]=h.useState("setup"),[y,R]=h.useState(Ka(s)),[j,H]=h.useState(10),[v,k]=h.useState([]),[I,$]=h.useState([]),[D,q]=h.useState(["multiple_choice","word_problem","identification"]),[Q,A]=h.useState(["remember","understand","apply","analyze"]),[U,ee]=h.useState(!1),[ie,je]=h.useState({easy:30,medium:50,hard:20}),[ge,Ce]=h.useState({}),[de,B]=h.useState(!1),[Y,ne]=h.useState([]),[De,Le]=h.useState(!1),[Ge,O]=h.useState(""),[X,f]=h.useState(!1),[T,E]=h.useState(!1),[W,V]=h.useState(null),[se,ae]=h.useState(0),[z,oe]=h.useState("queued"),[ue,ve]=h.useState("Waiting to start generation..."),[K,we]=h.useState(null),[We,Se]=h.useState(null),[Je,et]=h.useState(""),[F,Z]=h.useState(!1),Re=h.useRef(!1),[Ne,M]=h.useState("topics"),[te,_e]=h.useState(null),[Fe,be]=h.useState(!1),[ot,gt]=h.useState("all"),[Dt,Ns]=h.useState("all"),[J,xe]=h.useState(!1),[Ue,Ee]=h.useState(null),[lt,wt]=h.useState(!1),[Bi,Fs]=h.useState(!1),[Aa,Ar]=h.useState(!1),[Dr,Pi]=h.useState([]),[Hi,Fr]=h.useState(!1),[Da,$r]=h.useState(""),[cs,Or]=h.useState(null),[Br,$s]=h.useState([]),[Gi,Pr]=h.useState(!1),[Fa,Qi]=h.useState("all"),[Vi,Hr]=h.useState(null),[Gr,ca]=h.useState(null),Qr=h.useCallback(async()=>{B(!0);const u=Ka(y);try{const _=await Ze.getQuizTopics(u);_.topics&&Ce(so(_.topics,u))}catch{Ce(so(wu[u],u))}finally{B(!1)}},[y]),Vr=h.useCallback(async()=>{if(!C.quizEnabled){ne([]),O("Import-grounded quiz generation is disabled by rollout flag; using curriculum defaults."),Le(!1);return}Le(!0),O("");try{const u=await Ze.getCourseMaterialTopics({classSectionId:a,limit:20}),_=(u.topics||[]).filter(L=>L.title?.trim());ne(_),u.warnings&&u.warnings.length>0&&O(u.warnings.join(" "))}catch{ne([]),O("Imported topics are currently unavailable; quiz generation will use curriculum defaults.")}finally{Le(!1)}},[a,C.quizEnabled]);h.useEffect(()=>{Qr(),k([]),$([])},[Qr]),h.useEffect(()=>{Vr()},[Vr]);const $a=h.useMemo(()=>{const u=Array.from(new Set(Y.map(_=>_.title.trim()).filter(Boolean)));return u.length===0?ge:{"Imported Course Materials":u,...ge}},[ge,Y]);h.useEffect(()=>{gt("all"),Ns("all")},[K]);const Ur=h.useMemo(()=>{if(!K)return[];const u=K.questions.map(L=>L.provenance?.sourceFile?.trim()).filter(L=>!!L),_=(K.metadata.topicProvenance||[]).map(L=>L.sourceFile?.trim()).filter(L=>!!L);return Array.from(new Set([...u,..._])).sort((L,pe)=>L.localeCompare(pe))},[K]),Wr=h.useMemo(()=>{if(!K)return[];const u=K.questions.map(L=>L.provenance?.materialId?.trim()).filter(L=>!!L),_=(K.metadata.topicProvenance||[]).map(L=>L.materialId?.trim()).filter(L=>!!L);return Array.from(new Set([...u,..._])).sort((L,pe)=>L.localeCompare(pe))},[K]),Oa=h.useMemo(()=>K?K.questions.filter(u=>{const _=ot==="all"||(u.provenance?.sourceFile||"").trim()===ot,L=Dt==="all"||(u.provenance?.materialId||"").trim()===Dt;return _&&L}):[],[K,ot,Dt]),qr=(u,_)=>{const L={...ie},pe=Math.max(0,Math.min(100,L[u]+_)),$e=pe-L[u];L[u]=pe;const Qe=Object.keys(L).filter(tt=>tt!==u),yt=Qe.reduce((tt,It)=>tt+L[It],0);if(yt>0)for(const tt of Qe)L[tt]=Math.max(0,Math.round(L[tt]-$e*L[tt]/yt));const js=Object.values(L).reduce((tt,It)=>tt+It,0);if(js!==100){const tt=Qe.reduce((It,an)=>L[It]>=L[an]?It:an);L[tt]+=100-js}je(L)},Ui=u=>{k(_=>_.includes(u)?_.filter(L=>L!==u):[..._,u]),$(_=>_.filter(L=>L!==u))},Wi=u=>{q(_=>_.includes(u)?_.length>1?_.filter(L=>L!==u):_:[..._,u])},qi=u=>{A(_=>_.includes(u)?_.length>1?_.filter(L=>L!==u):_:[..._,u])},Yi=()=>{let u=v.length>0?v.filter(L=>!I.includes(L)):Object.values($a).flat().filter(L=>!I.includes(L)).slice(0,3);u.length>Ps&&(u=u.slice(0,Ps));const _=Math.min(j,Bs);return{topics:u,gradeLevel:y,numQuestions:_,questionTypes:D,includeGraphs:U,difficultyDistribution:ie,bloomLevels:Q,excludeTopics:I,classSectionId:a,className:r,preferImportedTopics:C.quizEnabled}},Ki=h.useCallback((u,_)=>{const L={taskId:u,request:_,createdAt:new Date().toISOString(),ownerUid:p?.uid};try{sessionStorage.setItem(Xa,JSON.stringify(L))}catch{}},[p]),Vt=h.useCallback(()=>{try{sessionStorage.removeItem(Xa)}catch{}},[]),Ba=h.useCallback(u=>{const _=Math.max(0,Math.min(100,Math.round(typeof u.progressPercent=="number"?u.progressPercent:u.status==="queued"?10:u.status==="running"?65:u.status==="completed"?100:u.status==="cancelling"?95:100)));ae(L=>{let pe=Math.max(L,_);if(u.status==="running"&&_<=L){const $e=String(u.progressStage||"").toLowerCase(),Qe=$e.includes("assembling")||$e.includes("final")?97:$e.includes("generating")?89:95;pe=Math.min(Qe,L+1)}return pe}),oe(u.progressStage||u.status),ve(u.progressMessage||(u.status==="queued"?"Task queued for generation.":u.status==="running"?"Generating quiz in the background...":u.status==="completed"?"Generation complete.":u.status==="cancelling"?"Cancelling generation...":"Generation finished with an error."))},[]);h.useEffect(()=>{if(g||Re.current)return;if(Re.current=!0,!p){Vt();return}let u=!1;const _=sessionStorage.getItem(Xa);if(!_)return;let L=null;try{L=JSON.parse(_)}catch{Vt();return}if(!L?.taskId){Vt();return}if(L.ownerUid&&L.ownerUid!==p.uid){Vt();return}return f(!0),V(L.taskId),et(""),Ze.waitForTaskResult(L.taskId,{timeoutMs:24e4,pollIntervalMs:1500,onProgress:Ba}).then(async pe=>{if(u)return;const $e=pe.result;if(!$e||typeof $e!="object")throw new Error("Quiz generation completed without a valid result payload.");const Qe=$e;we(Qe),w("results"),ae(100),oe("completed"),ve("Generation complete."),V(null),Vt();try{await Jr(Qe,L.request),me.success("Quiz auto-saved to your library as draft.")}catch(yt){me.error(yt instanceof Error?yt.message:"Quiz generated but failed to save to library")}}).catch(pe=>{if(!u){if(pe instanceof ja&&(pe.status===401||pe.status===403)){Re.current=!1,f(!1);return}et(pe instanceof Error?pe.message:"Failed to resume quiz generation"),V(null),Vt()}}).finally(()=>{u||f(!1)}),()=>{u=!0}},[Ba,g,Vt,p]);const Yr=()=>{if(X){window.confirm("Quiz generation is in progress. Are you sure you want to leave?")&&(w("setup"),we(null),et(""),t());return}w("setup"),we(null),et(""),t()},Xi=async()=>{b?.(),et(""),f(!0),ca(null),ae(8),oe("queued"),ve("Submitting quiz generation task..."),we(null);const u=Yi();try{const _=await Ze.generateQuiz(u,{onTaskCreated:L=>{V(L),Ki(L,u),ae(pe=>Math.max(pe,12)),oe("queued"),ve("Task queued. Generation is running in the background.")},onProgress:L=>{Ba(L),L.taskId&&L.taskId!==W&&V(L.taskId)}});we(_),w("results"),ae(100),oe("completed"),ve("Generation complete."),V(null),Vt();try{await Jr(_,u),me.success("Quiz auto-saved to your library as draft.")}catch(L){me.error(L instanceof Error?L.message:"Quiz generated but failed to save to library")}Ze.reportImportGroundedFeedback({flow:"quiz",status:"success",classSectionId:u.classSectionId,className:u.className,metadata:{totalQuestions:_.metadata.totalQuestions,usedImportedTopics:!!_.metadata.usedImportedTopics,importedTopicCount:_.metadata.importedTopicCount??0,importGroundingEnabled:C.quizEnabled}})}catch(_){et(_ instanceof Error?_.message:"Quiz generation failed"),ae(100),oe("failed"),ve("Generation failed."),V(null),Vt(),Ze.reportImportGroundedFeedback({flow:"quiz",status:"failed",classSectionId:u.classSectionId,className:u.className,metadata:{error:_ instanceof Error?_.message:"Quiz generation failed",importGroundingEnabled:C.quizEnabled}})}finally{f(!1)}},Ji=()=>{if(!K)return;const u=K.questions.map((_,L)=>{let pe=`${L+1}. [${_.difficulty.toUpperCase()}] [${_.bloomLevel}] (${_.points} pts) +`;return pe+=` ${_.question} +`,_.options&&(pe+=_.options.map($e=>` ${$e}`).join(` +`)+` +`),pe+=` Answer: ${_.correctAnswer} +`,pe+=` Explanation: ${_.explanation} +`,pe}).join(` +`);navigator.clipboard.writeText(u),Z(!0),setTimeout(()=>Z(!1),2e3)},Zi=()=>{if(!K)return;const u=new Blob([JSON.stringify(K,null,2)],{type:"application/json"}),_=URL.createObjectURL(u),L=document.createElement("a");L.href=_,L.download=`quiz_${y.replace(/\s/g,"_")}_${Date.now()}.json`,L.click(),URL.revokeObjectURL(_)};v.length>0||Object.values($a).flat().length>0;const Kr=(u,_)=>{const L=_?.gradeLevel||y,pe=_?.topics||v,$e=u.questions.map((Qe,yt)=>({id:`q_${Date.now()}_${yt}`,questionType:Qe.questionType||"identification",question:Qe.question,...Qe.options?{options:Qe.options}:{},correctAnswer:Qe.correctAnswer,bloomLevel:Qe.bloomLevel||"understand",difficulty:Qe.difficulty||"medium",topic:Qe.topic,subject:L,points:Qe.points,explanation:Qe.explanation}));return{title:`${L} Quiz – ${pe.length>0?pe.slice(0,2).join(", "):"Mixed Topics"}`,gradeLevel:L,questions:$e,totalPoints:u.totalPoints,metadata:{topicsCovered:Object.keys(u.metadata.topicsCovered),difficultyBreakdown:{easy:u.metadata.difficultyBreakdown.easy??0,medium:u.metadata.difficultyBreakdown.medium??0,hard:u.metadata.difficultyBreakdown.hard??0},bloomDistribution:u.metadata.bloomTaxonomyDistribution,questionTypeBreakdown:u.metadata.questionTypeBreakdown,supplementalPurpose:u.metadata.supplementalPurpose,recommendedTeacherActions:u.metadata.recommendedTeacherActions??[],generatedAt:new Date().toISOString(),generatedBy:"teacher_generated"},status:"draft",source:"teacher_generated"}},Xr=h.useCallback(u=>{$s(_=>[u,..._.filter(L=>L.id!==u.id)])},[]);async function Jr(u,_){if(!p)return null;const L=Kr(u,_),pe=await dn(L,p.uid,Ue?{documentId:Ue}:void 0);return Ee(pe),Xr({id:pe,...L,teacherId:p.uid}),pe}const el=async()=>{if(!K){me.error("No quiz to save. Generate a quiz first.");return}if(!p){me.error("You must be signed in to save quizzes.");return}xe(!0);try{const u=Kr(K),_=await dn(u,p.uid,Ue?{documentId:Ue}:void 0);Ee(_),Xr({id:_,...u,teacherId:p.uid}),me.success("Quiz saved to your library!"),x?.(_)}catch(u){me.error(u instanceof Error?u.message:"Failed to save quiz")}finally{xe(!1)}},tl=async()=>{if(Ue){wt(!0);try{await Cl(Ue),$s(u=>u.map(_=>_.id===Ue?{..._,status:"published"}:_)),me.success("Quiz published to Quiz Bank!")}catch(u){me.error(u instanceof Error?u.message:"Failed to publish quiz")}finally{wt(!1)}}},Pa=async u=>{const _=u??Ue;if(!_){me.error("Save the quiz first before assigning.");return}if(Hr(_),Fs(!0),Or(null),$r(""),Dr.length===0&&p){Fr(!0);try{const L=await Rr(p.uid);Pi(L)}catch{me.error("Failed to load students")}finally{Fr(!1)}}},sl=async()=>{const u=Vi??Ue;if(!(!cs||!u||!p)){Ar(!0);try{await Tl(u,cs,p.uid),$s(_=>_.map(L=>L.id===u?{...L,status:"assigned",metadata:{...L.metadata,assignedTo:cs}}:L)),me.success("Quiz assigned to student!"),Fs(!1),Hr(null),S==="bank"&&Ha()}catch(_){me.error(_ instanceof Error?_.message:"Failed to assign quiz")}finally{Ar(!1)}}},Ha=h.useCallback(async()=>{if(p){Pr(!0);try{const u=await $o(p.uid);$s(u)}catch{me.error("Failed to load quiz bank")}finally{Pr(!1)}}},[p]);h.useEffect(()=>{S==="bank"&&Ha()},[S,Ha]);const al=async u=>{try{await kl(u),$s(_=>_.filter(L=>L.id!==u)),me.success("Quiz deleted")}catch{me.error("Failed to delete quiz")}},Zr=Dr.filter(u=>u.name.toLowerCase().includes(Da.toLowerCase())||u.email.toLowerCase().includes(Da.toLowerCase())),en=Fa==="all"?Br:Br.filter(u=>u.status===Fa),rl=u=>{const _=(u.metadata.topicsCovered||[]).reduce((L,pe)=>(L[pe]=(L[pe]||0)+1,L),{});return{questions:u.questions.map(L=>({questionType:L.questionType,question:L.question,correctAnswer:L.correctAnswer,options:L.options??null,bloomLevel:L.bloomLevel,difficulty:L.difficulty,topic:L.topic,points:L.points,explanation:L.explanation})),totalPoints:u.totalPoints,metadata:{topicsCovered:_,difficultyBreakdown:u.metadata.difficultyBreakdown,bloomTaxonomyDistribution:u.metadata.bloomDistribution,questionTypeBreakdown:u.metadata.questionTypeBreakdown,gradeLevel:u.gradeLevel,totalQuestions:u.questions.length,includesGraphQuestions:!1,supplementalPurpose:u.metadata.supplementalPurpose,bloomTaxonomyRationale:"Loaded from saved quiz bank entry.",recommendedTeacherActions:u.metadata.recommendedTeacherActions||[]}}},Ga=u=>{Ee(u.id),we(rl(u)),Se(null),ca(u.id),gt("all"),Ns("all"),_e(null),w("results"),N("create")},tn={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"}},nl=(u,_,L)=>{const pe=te===_,$e=tn[u.bloomLevel?.toLowerCase()]||tn.remember,Qe=u.bloomLevel?.toLowerCase()==="remember"?"hover:border-purple-200":u.bloomLevel?.toLowerCase()==="understand"?"hover:border-blue-200":u.bloomLevel?.toLowerCase()==="apply"?"hover:border-amber-200":"hover:border-slate-200";return e.jsxs(Pe.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:_*.05},className:`border border-[#e2e8f0] rounded-[20px] overflow-hidden bg-white shadow-sm hover:shadow-md ${Qe} 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:()=>_e(pe?null:_),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 ${$e.card} text-white flex items-center justify-center font-bold text-[13px] shadow-sm`,children:["Q",_+1]}),e.jsx("span",{className:`px-2.5 py-1 rounded-md border text-[10px] font-bold uppercase tracking-wider shadow-sm ${$e.badge}`,children:u.bloomLevel}),e.jsx("span",{className:`px-2.5 py-1 rounded-md border text-[10px] font-bold uppercase tracking-wider shadow-sm ${u.difficulty==="easy"?"border-emerald-200 text-emerald-700 bg-emerald-50":u.difficulty==="hard"?"border-rose-200 text-rose-700 bg-rose-50":"border-amber-200 text-amber-700 bg-amber-50"}`,children:u.difficulty}),e.jsxs("span",{className:"text-[12px] font-bold text-[#64748b] bg-slate-100 px-2 py-1 rounded-md",children:[u.points," pts"]}),u.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:u.topic})]}),e.jsx("p",{className:"text-[16px] font-bold text-[#1e293b] pr-4 leading-relaxed",children:u.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 ${$e.badge}`,children:u.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:pe?e.jsx(ka,{size:16,className:"text-[#64748b] transition-transform duration-300"}):e.jsx(_t,{size:16,className:"text-[#64748b]"})})]})]}),e.jsx(Bt,{children:pe&&e.jsx(Pe.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"}),u.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:u.options.map((yt,js)=>{const tt=yt.includes(u.correctAnswer);return e.jsxs("div",{className:`rounded-[12px] p-4 text-[14px] font-medium transition-all cursor-pointer relative overflow-hidden ${tt?"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:[tt&&e.jsx("div",{className:"absolute left-0 top-0 w-1 h-full bg-emerald-500"}),e.jsx("span",{className:tt?"pl-2":"",children:yt}),tt&&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(Ut,{size:13})})]},js)})})]}),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(Ra,{size:14})," Correct Answer"]}),e.jsx("p",{className:"text-[16px] font-bold text-[#1e293b]",children:u.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(ss,{size:14})," AI Explanation"]}),e.jsx("p",{className:"text-[13px] text-[#475569] leading-relaxed font-medium",children:u.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(Wt,{size:14})," ",e.jsx("strong",{className:"text-[#1e293b]",children:"Type:"})," ",xa[u.questionType]?.label||u.questionType]}),e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ar,{size:14})," ",e.jsx("strong",{className:"text-[#1e293b]",children:"Bloom:"})," ",u.bloomLevel]})]})]})})})]},_)},sn=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 ${S==="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(or,{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 ${S==="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(Ca,{size:16})," Quiz Bank"]})]})}),e.jsxs("div",{className:"w-full px-[24px] xl:px-[32px] pb-[32px] flex-1",children:[S==="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(u=>e.jsx("button",{onClick:()=>Qi(u),className:`px-5 py-2 text-[13px] font-bold rounded-full whitespace-nowrap transition-all duration-300 mb-4 capitalize ${Fa===u?"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:u==="all"?"All":u.charAt(0).toUpperCase()+u.slice(1)},u))}),Gi?e.jsxs("div",{className:"flex items-center justify-center py-16",children:[e.jsx(ct,{size:24,className:"animate-spin text-sky-500"}),e.jsx("span",{className:"ml-2 text-sm text-[#5a6578]",children:"Loading quiz bank…"})]}):en.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-slate-500",children:[e.jsx(Ca,{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:en.map(u=>e.jsxs(Pe.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},onClick:()=>Ga(u),role:"button",tabIndex:0,onKeyDown:_=>{(_.key==="Enter"||_.key===" ")&&(_.preventDefault(),Ga(u))},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] ${u.status==="assigned"||u.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 ${u.status==="assigned"||u.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 ${u.status==="assigned"||u.status==="published"?"group-hover:text-[#9333ea]":"group-hover:text-slate-700"}`,children:u.title}),e.jsx("span",{className:`px-2.5 py-1 rounded-[6px] text-[10px] font-bold uppercase tracking-wider shrink-0 shadow-sm ${bu[u.status]}`,children:u.status})]}),e.jsx("div",{className:"flex flex-wrap gap-2 mb-5 pl-3",children:u.metadata.topicsCovered.slice(0,3).map(_=>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:_},_))}),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(Ll,{size:14})," ",u.questions.length," questions"]}),e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ro,{size:14})," ",u.totalPoints," pts"]}),e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Rt,{size:14})," ",u.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:_=>{_.stopPropagation(),Ga(u)},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(Al,{size:14})," View"]}),e.jsxs("button",{onClick:_=>{_.stopPropagation(),Pa(u.id)},className:"flex items-center gap-1.5 text-[13px] font-bold text-[#a855f7] hover:text-[#9333ea] transition-colors",children:[e.jsx(da,{size:14})," Assign"]}),e.jsxs("button",{onClick:_=>{_.stopPropagation(),al(u.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(Oo,{size:14})," Delete"]})]})]},u.id))})]}),S==="create"&&e.jsxs(e.Fragment,{children:[Je&&e.jsx("div",{className:"w-full px-[24px] xl:px-[32px] pt-4",children:e.jsxs(Pe.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(aa,{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:Je})]}),e.jsx("button",{onClick:()=>et(""),className:"ml-auto",children:e.jsx(ps,{size:14,className:"text-red-400"})})]})}),X&&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(ct,{size:20,className:"animate-spin text-[#a855f7]"}),"Generating Quiz in Background"]}),e.jsxs("span",{className:"text-[14px] font-extrabold text-[#9333ea]",children:[se,"%"]})]}),e.jsx("div",{className:"w-full bg-slate-100 h-2.5 rounded-full overflow-hidden mb-6",children:e.jsx(Pe.div,{animate:{width:`${se}%`},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:z.replace(/_/g," ")})]}),e.jsx("p",{children:ue}),W&&e.jsxs("p",{className:"text-[11px] mt-3 opacity-60 font-mono",children:["Task ID: ",W]})]})]}),e.jsxs("p",{className:"mt-8 text-[14px] font-medium text-[#64748b] flex items-center gap-2 animate-pulse",children:[e.jsx(ct,{size:16,className:"animate-spin"})," Generating quiz... Please wait."]})]}),!X&&m!=="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((u,_)=>{const pe=["setup","topics","style","preview"].indexOf(m),$e=pe>_,Qe=pe===_;return e.jsxs("div",{className:`flex-1 flex items-center justify-center gap-2 py-3 px-4 rounded-xl transition-all duration-500 ${Qe?"bg-purple-50/80 shadow-[0_1px_3px_rgba(168,85,247,0.1)]":$e?"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 ${Qe?"bg-gradient-to-br from-[#a855f7] to-[#9333ea] text-white shadow-md":$e?"bg-emerald-500 text-white shadow-sm":"bg-slate-100 text-[#64748b]"}`,children:$e?e.jsx(Ut,{size:13,strokeWidth:3}):_+1}),e.jsx("span",{className:`text-[13px] font-bold whitespace-nowrap ${Qe?"text-[#9333ea]":$e?"text-[#1e293b]":"text-[#64748b]"}`,children:u.label})]},u.id)})})}),m==="setup"&&!X&&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(Us,{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 ",Bs," questions and ",Ps," 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:y,onChange:u=>R(Ka(u.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:vu.map(u=>e.jsx("option",{value:u,children:u},u))}),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:()=>H(Math.max(1,j-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(un,{size:16})}),e.jsx("input",{id:"quiz-num-questions",type:"number",min:1,max:Bs,value:j,onChange:u=>H(Math.min(Bs,Math.max(1,parseInt(u.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:()=>H(Math.min(Bs,j+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(rr,{size:16})})]})]})]})]})]}),m==="topics"&&!X&&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 ",Ps," 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:[v.filter(u=>!I.includes(u)).length," of ",Ps," selected"]})]})]}),de?e.jsxs("div",{className:"flex items-center justify-center py-10 text-sm text-[#5a6578]",children:[e.jsx(ct,{size:24,className:"animate-spin text-[#9b51e0] mr-2"})," Loading topics..."]}):e.jsx("div",{className:"space-y-3",children:Object.entries($a).map(([u,_])=>{const L=_.filter($e=>v.includes($e)&&!I.includes($e)).length,pe=Ne===u;return e.jsxs("div",{className:"border border-[#dde3eb] rounded-xl bg-white overflow-hidden shadow-sm",children:[e.jsxs("button",{onClick:()=>M(pe?null:u),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:u}),e.jsxs("p",{className:"text-xs text-slate-500",children:[_.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:[L," selected"]}),pe?e.jsx(ka,{size:18,className:"text-slate-400"}):e.jsx(_t,{size:18,className:"text-slate-400"})]})]}),e.jsx(Bt,{children:pe&&e.jsx(Pe.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:_.map(($e,Qe)=>{const yt=v.includes($e),js=I.includes($e),tt=yt&&!js;let It="Core";return Qe%3===0&&(It="Foundation"),Qe%3===2&&(It="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 ${tt?"bg-[#9b51e0] border-[#9b51e0]":"border-2 border-[#dde3eb] bg-white"}`,children:tt&&e.jsx(Ut,{size:14,className:"text-white"})}),e.jsx("input",{type:"checkbox",className:"hidden",checked:tt,onChange:()=>Ui($e)}),e.jsx("span",{className:`text-sm font-semibold ${tt?"text-[#0a1628]":"text-[#5a6578]"}`,children:$e})]}),e.jsx("span",{className:`border px-3 py-1 rounded-full text-[10px] uppercase font-bold tracking-wider ${It==="Advanced"?"bg-white text-slate-400 border-[#dde3eb]":"bg-purple-50 text-[#9b51e0] border-purple-100"}`,children:It})]},$e)})})})})]},u)})})]}),m==="style"&&!X&&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(xa).map(([u,_])=>{const L=D.includes(u);return e.jsxs("button",{onClick:()=>Wi(u),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 ${L?"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:[L&&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(Ut,{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 ${L?"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:L?"text-[#a855f7]":"text-slate-500",children:_.icon})}),e.jsx("span",{className:`font-bold text-[12px] leading-tight ${L?"text-[#9333ea]":"text-slate-700"}`,children:_.label})]},u)})})]}),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(to).map(([u,_])=>{const L=Q.includes(u);return e.jsx("button",{onClick:()=>qi(u),className:`px-6 py-2.5 rounded-full border-2 font-bold text-[13px] transition-all duration-200 hover:-translate-y-0.5 capitalize ${L?"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:u},u)})})]}),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(ie).map(([u,_])=>{const L={easy:"bg-emerald-400",medium:"bg-amber-400",hard:"bg-rose-400"},pe={easy:"text-emerald-600",medium:"text-amber-500",hard:"text-rose-500"},$e={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:${pe[u]} transition-colors`,children:u}),e.jsx("div",{className:"flex-1 bg-slate-100 h-3 rounded-full overflow-hidden shadow-inner",children:e.jsx(Pe.div,{animate:{width:`${_}%`},className:`h-full rounded-full transition-all duration-500 ease-out ${L[u]}`})}),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 ${$e[u]}`,children:[e.jsx("button",{onClick:()=>qr(u,-5),className:`w-8 h-full flex items-center justify-center text-[#64748b] hover:bg-slate-50 hover:${pe[u]} rounded-lg transition-colors`,children:e.jsx(un,{className:"w-3.5 h-3.5"})}),e.jsx("input",{type:"text",value:`${_}%`,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:()=>qr(u,5),className:`w-8 h-full flex items-center justify-center text-[#64748b] hover:bg-slate-50 hover:${pe[u]} rounded-lg transition-colors`,children:e.jsx(rr,{className:"w-3.5 h-3.5"})})]})]},u)})})]})]}),m==="preview"&&!X&&!K&&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(hs,{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:j},{label:"Topics",value:v.filter(u=>!I.includes(u)).length},{label:"Level",value:y.replace("Grade ","Gr. ")}].map(u=>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:u.value}),e.jsx("span",{className:"text-[13px] font-bold text-[#64748b] relative z-10",children:u.label})]},u.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(Us,{size:18,className:"text-[#94a3b8] shrink-0 mt-0.5"}),e.jsxs("p",{children:[D.map(u=>xa[u]?.label).join(" and ")," questions across"," ",e.jsxs("span",{className:"font-bold text-[#1e293b]",children:[v.filter(u=>!I.includes(u)).length," topics"]})," ","— aligned to ",e.jsx("span",{className:"font-semibold",children:Q.map(u=>to[u]?.label).join(", ")})," levels of Bloom's Taxonomy."," ",e.jsxs("span",{className:"font-semibold text-emerald-600",children:["Easy ",ie.easy,"%"]})," • ",e.jsxs("span",{className:"font-semibold text-amber-500",children:["Medium ",ie.medium,"%"]})," • ",e.jsxs("span",{className:"font-semibold text-rose-500",children:["Hard ",ie.hard,"%"]}),"."]})]})]})}),m==="results"&&K&&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:Ji,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:[F?e.jsx(Ut,{size:14,className:"text-green-500"}):e.jsx(Ol,{size:14}),F?"Copied!":"Copy All"]}),e.jsxs("button",{onClick:Zi,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(Bl,{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(Wt,{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:K.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(Yt,{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:K.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(Lt,{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(K.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(ya,{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(K.metadata.bloomTaxonomyDistribution).length}),e.jsx("span",{className:"text-[12px] font-bold text-white/90 uppercase tracking-widest relative z-10",children:"Bloom Levels"})]})]}),(K.metadata.usedImportedTopics||(K.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: ",K.metadata.usedImportedTopics?"Yes":"No"," • ","Materials: ",K.metadata.importedMaterialsCount??0," • ","Topics: ",K.metadata.importedTopicCount??0]}),(K.metadata.topicProvenance||[]).slice(0,5).map((u,_)=>e.jsxs("div",{className:"text-xs text-[#5a6578]",children:[u.title||"Untitled topic",u.sourceFile?` • ${u.sourceFile}`:""]},`${u.topicId||u.title||"topic"}_${_}`)),(Ur.length>0||Wr.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:ot,onChange:u=>gt(u.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"}),Ur.map(u=>e.jsx("option",{value:u,children:u},u))]})]}),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:Dt,onChange:u=>Ns(u.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"}),Wr.map(u=>e.jsx("option",{value:u,children:u},u))]})]})]}),e.jsxs("p",{className:"text-[11px] text-[#5a6578] mt-2",children:["Showing ",Oa.length," of ",K.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(hs,{size:14})," Difficulty"]}),e.jsx("div",{className:"space-y-3 text-[14px] font-medium text-[#475569]",children:Object.entries(K.metadata.difficultyBreakdown).map(([u,_])=>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 ${ju[u]||"text-[#475569]"}`,children:u}),e.jsx("span",{className:"font-bold text-[#1e293b] bg-white px-2 py-0.5 rounded shadow-sm border border-slate-100",children:_})]},u))})]}),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(ar,{size:14})," Bloom's Taxonomy"]}),e.jsx("div",{className:"space-y-3 text-[14px] font-medium text-[#475569]",children:Object.entries(K.metadata.bloomTaxonomyDistribution).map(([u,_])=>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:u}),e.jsx("span",{className:"font-bold text-[#1e293b] bg-white px-2 py-0.5 rounded shadow-sm border border-slate-100",children:_})]},u))})]}),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(ya,{size:14})," Question Types"]}),e.jsx("div",{className:"space-y-3 text-[14px] font-medium text-[#475569]",children:Object.entries(K.metadata.questionTypeBreakdown).map(([u,_])=>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:xa[u]?.label||u}),e.jsx("span",{className:"font-bold text-[#1e293b] bg-white px-2 py-0.5 rounded shadow-sm border border-slate-100",children:_})]},u))})]})]}),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(Us,{size:18,className:"text-[#9333ea]"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[14px] font-bold text-[#9333ea] mb-3",children:K.metadata.supplementalPurpose||"This quiz is designed to supplement classroom instruction, not replace teacher-led learning."}),K.metadata.recommendedTeacherActions&&K.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:K.metadata.recommendedTeacherActions.map((u,_)=>e.jsx("li",{children:u},_))})]})]})]})]}),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(Go,{size:20,className:"text-[#a855f7]"})," Review Questions"]}),e.jsx("div",{className:"space-y-4",children:Oa.length>0?Oa.map((u,_)=>nl(u,_)):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."})})]})]})]})]}),S==="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:[m==="topics"&&!X&&e.jsx("button",{onClick:()=>{k([]),$([])},className:"text-[13px] font-semibold text-[#a855f7] hover:underline",children:"Clear all"}),(m==="style"||m==="preview")&&!X&&e.jsxs("button",{onClick:()=>w(m==="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(as,{size:16})," Back"]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[m==="setup"&&!X&&e.jsxs("button",{onClick:()=>w("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(es,{size:16})]}),m==="topics"&&!X&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:()=>w("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(as,{size:16})," Back"]}),e.jsxs("button",{onClick:()=>w("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(es,{size:16})]})]}),m==="style"&&!X&&e.jsxs("button",{onClick:()=>w("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(es,{size:16})]}),m==="preview"&&!X&&!K&&e.jsxs("button",{onClick:Xi,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(Ut,{size:16})," Generate Quiz"]}),X&&e.jsxs("div",{className:"flex items-center gap-3 text-slate-500 font-medium text-sm",children:[e.jsx(ct,{size:16,className:"animate-spin"})," Generating quiz... Please wait."]}),m==="results"&&(Gr?e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>{N("bank"),ca(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:()=>Pa(Gr),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(da,{size:16})," Assign"]}),e.jsx("button",{onClick:Yr,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:()=>{w("setup"),we(null),Se(null),Ee(null),ca(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"}),Ue?e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:tl,disabled:lt,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:[lt?e.jsx(ct,{size:16,className:"animate-spin"}):e.jsx(sa,{size:16})," Publish"]}),e.jsxs("button",{onClick:()=>Pa(),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(da,{size:16})," Assign to Class"]})]}):e.jsxs("button",{onClick:el,disabled:J,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:[J?e.jsx(ct,{size:16,className:"animate-spin"}):e.jsx(Po,{size:16})," Save to Library"]}),e.jsx("button",{onClick:Yr,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(gu,{isOpen:Fe,onClose:()=>be(!1)}),e.jsx(Bt,{children:Bi&&e.jsx(Pe.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:()=>Fs(!1),children:e.jsxs(Pe.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:u=>u.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(Rt,{size:18,className:"text-sky-600"}),"Assign to Student"]}),e.jsx("button",{onClick:()=>Fs(!1),className:"p-1 hover:bg-[#edf1f7] rounded-lg transition-colors",children:e.jsx(ps,{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(ra,{size:14,className:"text-slate-500"}),e.jsx("input",{type:"text",placeholder:"Search students…",value:Da,onChange:u=>$r(u.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:Hi?e.jsx("div",{className:"flex items-center justify-center py-10",children:e.jsx(ct,{size:20,className:"animate-spin text-sky-500"})}):Zr.length===0?e.jsx("p",{className:"text-center text-sm text-slate-500 py-10",children:"No students found"}):Zr.map(u=>e.jsxs("button",{onClick:()=>Or(u.id),className:`w-full flex items-center gap-3 px-3 py-2.5 rounded-xl text-left transition-colors ${cs===u.id?"bg-sky-50 border border-sky-300":"hover:bg-[#edf1f7] border border-transparent"}`,children:[e.jsx("img",{src:u.avatar||`https://ui-avatars.com/api/?name=${encodeURIComponent(u.name)}&background=random&size=32`,alt:u.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:u.name}),e.jsx("p",{className:"text-xs text-slate-500 truncate",children:u.email})]}),cs===u.id&&e.jsx(Ut,{size:16,className:"text-sky-600 flex-shrink-0"})]},u.id))}),e.jsxs("div",{className:"px-5 py-3 border-t border-[#dde3eb] flex justify-end gap-2",children:[e.jsx("button",{onClick:()=>Fs(!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:sl,disabled:!cs||Aa,className:`flex items-center gap-2 px-4 py-2 rounded-xl text-sm font-bold transition-all ${cs&&!Aa?"bg-gradient-to-r from-sky-600 to-sky-500 text-white shadow-sm":"bg-[#dde3eb] text-slate-500 cursor-not-allowed"}`,children:[Aa?e.jsx(ct,{size:14,className:"animate-spin"}):e.jsx(da,{size:14}),"Assign"]})]})]})})})]});return d?e.jsx("div",{className:"w-full h-full flex flex-col overflow-hidden bg-white",children:sn}):sn},yu=({onOpenNotifications:t,onOpenProfile:s,onOpenInsightModal:a,userPhoto:r,teacherName:n})=>{const[o,i]=h.useState([]),[l,c]=h.useState(!1),[d,x]=h.useState(!1),[b,p]=h.useState(""),[g,C]=h.useState(11),[S,N]=h.useState("general_mathematics"),m=h.useCallback(async()=>{c(!0);try{const j=await nn("/api/quiz-battle/bank-status");i(j.pdfs)}catch(j){const H=j instanceof ja?j.message:"Failed to load bank status";me.error(H)}finally{c(!1)}},[]);h.useEffect(()=>{m()},[m]);const w=async()=>{if(!b.trim()){me.error("Please enter a storage path");return}x(!0);try{await nn("/api/quiz-battle/ingest-pdf",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({storage_path:b.trim(),grade_level:g,topic:S.trim(),force_reingest:!1})}),me.success("PDF ingestion completed"),await m(),p("")}catch(j){const H=j instanceof ja?j.message:"Ingestion failed";me.error(H)}finally{x(!1)}},y=o.reduce((j,H)=>j+H.question_count,0),R=o.filter(j=>j.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(Wt,{size:16,className:"text-white"})})]}),e.jsx("div",{className:"text-[32px] font-bold relative z-10 leading-none",children:o.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(Lt,{size:16,className:"text-white"})})]}),e.jsx("div",{className:"text-[32px] font-bold relative z-10 leading-none",children:y})]}),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(Vs,{size:16,className:"text-white"})})]}),e.jsx("div",{className:"text-[32px] font-bold relative z-10 leading-none",children:R})]})]}),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(xn,{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(Wt,{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:b,onChange:j=>p(j.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:g,onChange:j=>C(Number(j.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(Lt,{className:"h-4 w-4 text-[#94a3b8] group-hover:text-[#a855f7] transition-colors"})}),e.jsx("input",{type:"text",placeholder:"general_mathematics",value:S,onChange:j=>N(j.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(ct,{className:"w-4 h-4 animate-spin"}):e.jsx(xn,{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:m,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(Vs,{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:[o.map(j=>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 ${j.processed?"bg-indigo-50 text-indigo-500":"bg-amber-50 text-amber-500"}`,children:e.jsx(Wt,{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:j.filename})]})}),e.jsx("td",{className:"py-4 px-6 text-[13px] font-semibold text-[#475569]",children:j.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:j.topic})}),e.jsx("td",{className:"py-4 px-6 text-[13px] font-bold text-[#1e293b] text-center",children:j.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 ${j.processed?"bg-emerald-50 text-emerald-600 border-emerald-200/50":"bg-amber-50 text-amber-600 border-amber-200/50"}`,children:[j.processed?e.jsx(Vs,{className:"w-3 h-3"}):e.jsx(ct,{className:"w-3 h-3 animate-spin"}),j.processed?"Completed":"Processing..."]})}),e.jsx("td",{className:"py-4 px-6 text-[13px] font-medium text-[#64748b]",children:j.timestamp?new Date(j.timestamp).toLocaleDateString():"-"})]},j.filename)),o.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(Wt,{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."})]})})})]})]})})})]})]})]})},ao={totalTopicsTracked:0,masteredCount:0,needsAttentionCount:0,excludedCount:0},Su={"gen-math":{label:"GEN MATH",color:"bg-sky-100 text-sky-700"},"stats-prob":{label:"STAT&PROB",color:"bg-sky-100 text-sky-700"},"pre-calc":{label:"PRE-CALC",color:"bg-orange-100 text-orange-700"},"basic-calc":{label:"BASIC CALC",color:"bg-red-100 text-red-700"}},ro={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"}},no={needs_attention:0,on_track:1,no_data:2,mastered:3},ku=({classSectionId:t,onOpenNotifications:s,onOpenProfile:a})=>{const{currentUser:r,userProfile:n}=gs(),[o,i]=h.useState([]),[l,c]=h.useState(ao),[d,x]=h.useState(!0),[b,p]=h.useState("all"),[g,C]=h.useState("all"),[S,N]=h.useState(""),[m,w]=h.useState("classAverage"),[y,R]=h.useState("asc"),j=pn.map(B=>B.id),H=pn.reduce((B,Y)=>(B[Y.id]=Y.name,B),{}),{isLoading:v,refetch:k}=Ql();h.useEffect(()=>{v||(console.log("[TopicMasteryView] Curriculum ready"),k())},[v,k]);const[I,$]=h.useState(new Set),[D,q]=h.useState([]),Q=Pl({queryKey:xl.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 B=vt(st,"teachers",r.uid,"settings","quizSettings"),Y=await Cs(B),ne=Y.exists()?Y.data()?.excludedTopics||[]:[],De="https://deign86-mathpulse-api-v3test.hf.space",Le=new URLSearchParams({teacherId:r.uid});t&&Le.set("classSectionId",t);const Ge=await r.getIdToken(),O=await fetch(`${De}/api/analytics/topic-mastery?${Le.toString()}`,{headers:{Authorization:`Bearer ${Ge}`}});if(!O.ok)return{excluded:ne,topics:[],summary:{totalTopicsTracked:0,masteredCount:0,needsAttentionCount:0,excludedCount:ne.length}};const X=await O.json(),f=(X.topics||[]).map(T=>({...T,isExcluded:ne.includes(T.topicName)}));return{excluded:ne,topics:f,summary:X.summary||{totalTopicsTracked:0,masteredCount:0,needsAttentionCount:0,excludedCount:ne.length}}}catch{return{excluded:[],topics:[],summary:{totalTopicsTracked:0,masteredCount:0,needsAttentionCount:0,excludedCount:0}}}}});h.useEffect(()=>{if(x(Q.isLoading||Q.isFetching),!Q.data){q([]),i([]),c(ao),$(new Set);return}q(Q.data.excluded),i(Q.data.topics),c(Q.data.summary)},[Q.data,Q.isFetching,Q.isLoading]);const A=async B=>{if(!r)return;const Y=D.includes(B)?D.filter(ne=>ne!==B):[...D,B];q(Y),i(ne=>ne.map(De=>De.topicName===B?{...De,isExcluded:!De.isExcluded}:De)),c(ne=>({...ne,excludedCount:Y.length}));try{const ne=vt(st,"teachers",r.uid,"settings","quizSettings");(await Cs(ne)).exists()?await Kt(ne,{excludedTopics:Y}):await Zt(ne,{excludedTopics:Y})}catch{me.error("Failed to update excluded topics")}},U=async()=>{if(!r)return;const B=[...new Set([...D,...I])];q(B),i(Y=>Y.map(ne=>I.has(ne.topicName)?{...ne,isExcluded:!0}:ne)),c(Y=>({...Y,excludedCount:B.length})),$(new Set);try{const Y=vt(st,"teachers",r.uid,"settings","quizSettings");(await Cs(Y)).exists()?await Kt(Y,{excludedTopics:B}):await Zt(Y,{excludedTopics:B}),me.success(`${I.size} topics excluded from quizzes`)}catch{me.error("Failed to update")}},ee=async()=>{if(!r)return;const B=D.filter(Y=>!I.has(Y));q(B),i(Y=>Y.map(ne=>I.has(ne.topicName)?{...ne,isExcluded:!1}:ne)),c(Y=>({...Y,excludedCount:B.length})),$(new Set);try{const Y=vt(st,"teachers",r.uid,"settings","quizSettings");(await Cs(Y)).exists()?await Kt(Y,{excludedTopics:B}):await Zt(Y,{excludedTopics:B}),me.success(`${I.size} topics re-included in quizzes`)}catch{me.error("Failed to update")}},ie=B=>{m===B?R(Y=>Y==="asc"?"desc":"asc"):(w(B),R("asc"))},je=g==="all"?j:Hl(g);h.useEffect(()=>{b!=="all"&&(je.includes(b)||p("all"))},[je,b]);const ge=o.filter(B=>!(b!=="all"&&B.subjectId!==b||!je.includes(B.subjectId)||S&&!B.topicName.toLowerCase().includes(S.toLowerCase()))).sort((B,Y)=>{const ne=y==="asc"?1:-1;switch(m){case"topicName":return ne*B.topicName.localeCompare(Y.topicName);case"classAverage":return ne*(B.classAverage-Y.classAverage);case"studentsAttempted":return ne*(B.studentsAttempted-Y.studentsAttempted);case"masteryStatus":return ne*((no[B.masteryStatus]||0)-(no[Y.masteryStatus]||0));default:return 0}}),Ce=()=>{I.size===ge.length?$(new Set):$(new Set(ge.map(B=>B.topicName)))},de=({field:B})=>m!==B?e.jsx(_t,{size:14,className:"text-white/40"}):y==="asc"?e.jsx(ka,{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(ct,{size:24,className:"animate-spin text-indigo-500"}),e.jsx("span",{className:"ml-2 text-[#64748b]",children:"Loading topic mastery data..."})]}):e.jsxs(Pe.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(hs,{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(gr,{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(_s,{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(Dl,{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(ra,{size:16,className:"text-[#64748b] shrink-0 group-focus-within:text-[#4f46e5] transition-colors"}),e.jsx("input",{type:"text",placeholder:"Search topics...",value:S,onChange:B=>N(B.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:b,onChange:B=>p(B.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"}),je.map(B=>e.jsx("option",{value:B,children:H[B]||B},B))]}),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:g,onChange:B=>C(B.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"}),Gl.map(B=>e.jsx("option",{value:B,children:B},B))]}),e.jsx(_t,{size:16,className:"text-[#64748b] absolute right-3 top-1/2 -translate-y-1/2 pointer-events-none"})]})]}),e.jsx(Bt,{children:I.size>0&&e.jsxs(Pe.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:[I.size," topics selected"]}),e.jsx("button",{onClick:U,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:ee,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:I.size===ge.length&&ge.length>0,onChange:Ce,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:()=>ie("topicName"),children:["TOPIC NAME ",e.jsx(de,{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:()=>ie("classAverage"),children:["CLASS AVG % ",e.jsx(de,{field:"classAverage"})]}),e.jsxs("div",{className:"col-span-2 flex items-center gap-1 cursor-pointer hover:text-white/80 select-none",onClick:()=>ie("studentsAttempted"),children:["STUDENTS ",e.jsx(de,{field:"studentsAttempted"})]}),e.jsxs("div",{className:"col-span-1 flex items-center gap-1 cursor-pointer hover:text-white/80 select-none",onClick:()=>ie("masteryStatus"),children:["STATUS ",e.jsx(de,{field:"masteryStatus"})]}),e.jsx("div",{className:"col-span-1 text-center",children:"EXCLUDE"})]}),e.jsx("div",{className:"flex flex-col",children:ge.length===0?e.jsx("div",{className:"p-16 text-center border-b border-[#f1f5f9]",children:o.length===0?e.jsxs("div",{className:"flex flex-col items-center gap-2",children:[e.jsx(hs,{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."})}):ge.map(B=>{const Y=I.has(B.topicName),ne=ro[B.masteryStatus]||ro.no_data,De=Su[B.subjectId]||{label:B.subjectId.toUpperCase(),color:"bg-[#f8fafc] text-[#64748b]"},Le=B.classAverage<60?"bg-rose-500":B.classAverage<85?"bg-amber-500":"bg-emerald-500",Ge=B.isExcluded?"bg-slate-50/60 opacity-70":B.masteryStatus==="needs_attention"?"bg-rose-50/30":B.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 ${Ge} ${B.isExcluded?"line-through decoration-slate-400":""}`,children:[e.jsx("div",{className:"col-span-1 flex justify-center",children:e.jsx("input",{type:"checkbox",checked:Y,onChange:()=>{const O=new Set(I);Y?O.delete(B.topicName):O.add(B.topicName),$(O)},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:B.topicName}),e.jsx("span",{className:`text-[9px] font-bold px-1.5 py-0.5 rounded shrink-0 ${De.color}`,children:De.label})]}),e.jsx("div",{className:"col-span-2 text-[#475569] text-[13px] truncate pr-2",children:B.unit}),e.jsx("div",{className:"col-span-2",children:e.jsxs("span",{className:"font-bold text-[#1e293b] text-[14px]",children:[B.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:[B.studentsAttempted," / ",B.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 ${Le}`,style:{width:`${B.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 ${ne.color}`,children:ne.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:B.isExcluded,onChange:()=>A(B.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:B.isExcluded?"Include in generation":"Exclude from generation"})]})]},B.topicName)})})]})})})]})]})};function Ri(t){return(t||"").trim().toLowerCase()}function oo(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 n=Ri(t.classSectionId),o=(t.id||"").trim().toLowerCase();return n&&o?`${n}|id:${o}`:o?`id:${o}`:`${n}|anonymous`}function Cu(t,s){const a=[],r=(t.lrn||"").trim().toLowerCase(),n=(t.email||"").trim().toLowerCase(),o=t.name.trim().toLowerCase(),i=(t.id||"").trim().toLowerCase();return r&&a.push(`${s}|lrn:${r}`),n&&a.push(`${s}|email:${n}`),o&&a.push(`${s}|name:${o}`),i&&a.push(`${s}|id:${i}`),a.length===0&&a.push(`${s}|anonymous`),a}function Tu(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 Mi(t,s){const a=new Map,r=new Map,n=s?Ri(s):"all";return t.forEach(o=>{const i=Cu(o,n),l=i.map(x=>r.get(x)).find(Boolean)||i[0],c=a.get(l),d=c?Tu(c,o):o;a.set(l,d),i.forEach(x=>r.set(x,l))}),Array.from(a.values())}function io(t,s){return Mi([...t,...s])}function Ss(t){return Number.isFinite(t)?Math.max(0,Math.min(100,t)):0}function Iu(t){if(!t)return null;const s="gen-math",a=hn.find(i=>i.id===s)?.modules||[];if(a.length===0)return null;const r={mastery:0,concept:0,application:0,engagement:0,consistency:0},n=t.lessons??{};a.forEach(i=>{const l=hn.find(N=>N.modules.some(m=>m.id===i.id)),c=l?t?.subjects?.[l.id]?.modulesProgress?.[i.id]:null,d=Ss(c?.progress||0),x=i.lessons.length?i.lessons.reduce((N,m)=>{const w=n?.[m.id]?.score;if(typeof w=="number"&&Number.isFinite(w))return N+Ss(w);const y=!!c?.lessonsCompleted?.includes?.(m.id);return N+(y?100:0)},0)/i.lessons.length:0,b=i.quizzes.length?(c?.quizzesCompleted?.length||0)/i.quizzes.length*100:0,p=Ss(x),g=Ss(b),C=Ss(Math.min(100,(p+g*2)/1.5)),S=Ss(Math.min(100,40+d*.6));r.mastery+=d,r.concept+=p,r.application+=g,r.engagement+=C,r.consistency+=S});const o=a.length;return{mastery:Math.round(r.mastery/o),concept:Math.round(r.concept/o),application:Math.round(r.application/o),engagement:Math.round(r.engagement/o),consistency:Math.round(r.consistency/o)}}const lo={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"}},Ja=[{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"}],Eu=({classSectionId:t,className:s,fallbackStudents:a=[],onBack:r,onOpenNotifications:n,onOpenProfile:o,insightDismissed:i,onOpenInsightModal:l})=>{const{currentUser:c,userProfile:d}=gs(),x=h.useRef(0),[b,p]=h.useState([]),[g,C]=h.useState(!0),[S,N]=h.useState(""),[m,w]=h.useState("riskLevel"),[y,R]=h.useState("desc"),[j,H]=h.useState("all"),[v,k]=h.useState([]),[I,$]=h.useState(!1),[D,q]=h.useState(""),[Q,A]=h.useState(""),U=h.useCallback(f=>({id:f.id,lrn:f.lrn||void 0,name:f.name,email:f.email||"",avatar:`https://ui-avatars.com/api/?name=${encodeURIComponent(f.name)}&background=random`,classSectionId:f.classSectionId??null,riskLevel:f.riskLevel||"Low",engagementScore:f.engagementScore,avgQuizScore:f.avgQuizScore,weakestTopic:f.weakestTopic||"Foundational Skills"}),[]),ee=h.useCallback(f=>({id:f.id,lrn:f.lrn,name:f.name,email:f.email||"",avatar:f.avatar||`https://ui-avatars.com/api/?name=${encodeURIComponent(f.name)}&background=random`,classSectionId:f.classSectionId??null,riskLevel:String(f.riskLevel).charAt(0).toUpperCase()+String(f.riskLevel).slice(1).toLowerCase(),engagementScore:f.engagementScore,avgQuizScore:Number(f.avgQuizScore??f.avgScore??0),weakestTopic:f.weakestTopic||"Foundational Skills"}),[]),ie=h.useCallback(async(f,T)=>{const E=new Map;f.forEach(V=>E.set(V.id,null));const W=25;for(let V=0;V{try{const oe=await on(z.id);return{studentId:z.id,summary:Iu(oe)}}catch{return{studentId:z.id,summary:null}}}))).forEach((z,oe)=>{const ue=se[oe]?.id;ue&&(z.status==="fulfilled"?E.set(ue,z.value.summary):E.set(ue,null))})}x.current===T&&p(V=>V.map(se=>E.has(se.student.id)?{...se,competencyMatrix:E.get(se.student.id)??null,competencyMatrixLoading:!1}:se))},[]),je=h.useCallback(async()=>{if(c?.uid){C(!0),A("");try{let T=(await Rr(c.uid)).map(se=>({id:se.id,name:se.name,email:se.email||"",avatar:se.avatar||`https://ui-avatars.com/api/?name=${encodeURIComponent(se.name)}&background=random`,classSectionId:se.classSectionId??null,riskLevel:se.riskLevel,engagementScore:se.engagementScore,avgQuizScore:se.avgQuizScore,weakestTopic:se.weakestTopic||"Foundational Skills"}));a.length>0&&(T=io(T,a.map(ee))),t&&(T=T.filter(se=>se.classSectionId===t));const E=await Ze.getImportedClassOverview({classSectionId:t,limit:3e3});E.warnings.length>0&&A(E.warnings.join(" ")),T=io(T,E.students.map(U));const W=Mi(T,t),V=x.current+=1;p(W.map((se,ae)=>({rowKey:`${oo(se)}|row:${ae}`,student:se,competency:null,competencyMatrix:null,competencyMatrixLoading:!0,loading:!1,expanded:!1}))),ie(W,V)}catch(f){if(console.error("Failed to load students:",f),a.length>0){const T=a.map(ee).filter(E=>!t||E.classSectionId===t).map((E,W)=>({rowKey:`${oo(E)}|row:${W}`,student:E,competency:null,competencyMatrix:null,competencyMatrixLoading:!1,loading:!1,expanded:!1}));p(T),A("Showing recently imported students while backend roster sync catches up.")}else p([]),A("Student competency roster is unavailable right now.")}finally{C(!1)}}},[t,c?.uid,a,ie,ee,U]);h.useEffect(()=>{je()},[je]),h.useEffect(()=>{(async()=>{if(!t){k([]),q("");return}$(!0),q("");try{const T=await Ze.getCourseMaterialTopics({classSectionId:t,limit:20}),E=(T.topics||[]).filter(W=>W.title?.trim());k(E),T.warnings.length>0&&q(T.warnings.join(" "))}catch{k([]),q("Imported topic context is unavailable right now.")}finally{$(!1)}})()},[t]);const ge=async f=>{p(T=>T.map(E=>{if(E.rowKey!==f)return E;const W=!E.expanded,V=E.student.id,se={weakestTopic:E.student.weakestTopic,avgQuizScore:E.student.avgQuizScore};return W&&!E.competency&&!E.loading?(Ce(f,V,se),{...E,expanded:!0,loading:!0}):{...E,expanded:W}}))},Ce=async(f,T,E)=>{try{const V=((await on(T))?.quizAttempts??[]).map(ae=>({topic:ae.quizId,score:ae.score,total:100,timeTaken:ae.timeSpent})),se=await Ze.getStudentCompetency(T,V.length>0?V:void 0);p(ae=>ae.map(z=>z.rowKey===f?{...z,competency:se,loading:!1}:z))}catch{const V=E.avgQuizScore||50,se={studentId:T,competencies:[{topic:E.weakestTopic||"Unknown",efficiencyScore:Math.max(15,V-20),competencyLevel:V<50?"beginner":"developing",perspective:`Student needs focused practice in ${E.weakestTopic}.`},{topic:"Functions and Relations",efficiencyScore:Math.min(95,V+10),competencyLevel:V>70?"proficient":"developing",perspective:"Shows solid understanding of function concepts."},{topic:"Problem Solving",efficiencyScore:V,competencyLevel:V>80?"advanced":V>60?"proficient":"developing",perspective:"Applies mathematical reasoning consistently."}],recommendedTopics:[E.weakestTopic||"Review fundamentals"],excludeTopics:[]};p(ae=>ae.map(z=>z.rowKey===f?{...z,competency:se,loading:!1}:z))}},de=f=>{m===f?R(T=>T==="asc"?"desc":"asc"):(w(f),R("asc"))},B={High:0,Medium:1,Low:2},Y=b.filter(f=>{if(j!=="all"&&f.student.riskLevel!==j)return!1;if(S){const T=S.toLowerCase();return f.student.name.toLowerCase().includes(T)||f.student.email.toLowerCase().includes(T)}return!0}).sort((f,T)=>{let E=0;switch(m){case"name":E=f.student.name.localeCompare(T.student.name);break;case"avgQuizScore":E=f.student.avgQuizScore-T.student.avgQuizScore;break;case"riskLevel":E=B[f.student.riskLevel]-B[T.student.riskLevel];break;case"engagementScore":E=f.student.engagementScore-T.student.engagementScore;break}return y==="asc"?E:-E}),ne=b.length,De=b.filter(f=>f.student.riskLevel==="High").length,Le=ne>0?Math.round(b.reduce((f,T)=>f+T.student.avgQuizScore,0)/ne):0,Ge=ne>0?Math.round(b.reduce((f,T)=>f+T.student.engagementScore,0)/ne):0,O=Array.from(new Set(v.map(f=>f.title).filter(Boolean))).slice(0,10),X=({field:f})=>m!==f?e.jsx(_t,{size:14,className:"text-white/40"}):y==="asc"?e.jsx(ka,{size:14,className:"text-white font-bold"}):e.jsx(_t,{size:14,className:"text-white font-bold"});return g?e.jsxs("div",{className:"flex items-center justify-center py-20 p-6",children:[e.jsx(ct,{size:32,className:"animate-spin text-[var(--primary)]"}),e.jsx("span",{className:"ml-3 text-muted-foreground",children:"Loading student data..."})]}):e.jsxs(Pe.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(as,{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(ln,{className:"w-4 h-4 text-white"})})]}),e.jsx("div",{className:"text-[28px] font-bold relative z-10 leading-none mb-4",children:ne}),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(_s,{className:"w-4 h-4 text-white"})})]}),e.jsx("div",{className:"text-[28px] font-bold relative z-10 leading-none mb-4",children:De}),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(hs,{className:"w-4 h-4 text-white"})})]}),e.jsxs("div",{className:"text-[28px] font-bold relative z-10 leading-none mb-4",children:[Le,"%"]}),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(sa,{className:"w-4 h-4 text-white"})})]}),e.jsxs("div",{className:"text-[28px] font-bold relative z-10 leading-none mb-4",children:[Ge,"%"]}),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(ra,{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:S,onChange:f=>N(f.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(f=>e.jsx("button",{onClick:()=>H(f),className:`px-4 py-1.5 text-[13px] font-semibold rounded-full whitespace-nowrap transition-colors shadow-md ${j===f?"bg-[#9956DE] text-white":"bg-white text-slate-500 hover:text-slate-700 hover:bg-slate-50"}`,children:f==="all"?"All":`${f} Risk`},f))})]}),e.jsxs("button",{onClick:je,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(Vs,{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}`:"",":"]}),I?e.jsx("span",{className:"text-[#8b5cf6] text-[13px]",children:"Loading class-scoped imported topics..."}):O.length>0?e.jsx("div",{className:"flex flex-wrap items-center gap-1.5 mt-1 sm:mt-0",children:O.map((f,T)=>e.jsxs(le.Fragment,{children:[e.jsx("span",{className:"text-[#8b5cf6] text-[13px]",children:f}),Tde("name"),children:["Student ",e.jsx(X,{field:"name"})]}),e.jsxs("div",{className:"w-[120px] shrink-0 px-4 flex justify-center cursor-pointer hover:text-white/80 transition-colors",onClick:()=>de("riskLevel"),children:["Risk Level ",e.jsx(X,{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:()=>de("avgQuizScore"),children:["Avg. Score ",e.jsx(X,{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:()=>de("engagementScore"),children:["Engagement ",e.jsx(X,{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"}),Ja.map((f,T)=>e.jsx("div",{className:`w-[100px] shrink-0 px-2 flex justify-center ${T===Ja.length-1?"border-r border-transparent":""}`,children:f.header},f.key))]}),Y.length===0?e.jsxs("div",{className:"py-12 text-center text-slate-500",children:[e.jsx(ln,{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:Y.map(f=>(f.student.riskLevel==="High"||f.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 ge(f.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 ${f.expanded?"rotate-90":""}`,children:e.jsx(es,{className:"w-4 h-4 text-slate-400"})}),e.jsx("img",{src:f.student.avatar,alt:f.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:f.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 ${f.student.riskLevel==="High"?"bg-rose-50 text-rose-600 border-rose-200":f.student.riskLevel==="Medium"?"bg-amber-50 text-amber-600 border-amber-200":"bg-emerald-50 text-emerald-600 border-emerald-200"}`,children:f.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 ${f.student.avgQuizScore>=80?"bg-emerald-500":f.student.avgQuizScore>=60?"bg-amber-400":"bg-rose-500"}`,style:{width:`${f.student.avgQuizScore}%`}})}),e.jsxs("span",{className:"text-[13px] font-bold text-slate-800 w-8",children:[f.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:`${f.student.engagementScore}%`}})}),e.jsxs("span",{className:"text-[13px] font-bold text-slate-800 w-8",children:[f.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:f.student.weakestTopic})}),Ja.map(T=>{const E=f.competencyMatrix?.[T.key]??0;return e.jsx("div",{className:"w-[100px] shrink-0 px-2 flex justify-center",children:f.competencyMatrixLoading?e.jsx(ct,{size:12,className:"animate-spin text-muted-foreground"}):f.competencyMatrix?e.jsxs("span",{className:`text-[12px] font-medium px-2 rounded-full border ${E>=80?"text-emerald-600 bg-emerald-50 border-emerald-100":E>=60?"text-amber-600 bg-amber-50 border-amber-100":"text-rose-500 bg-rose-50 border-rose-100"}`,children:[E,"%"]}):e.jsx("span",{className:"text-xs text-muted-foreground",children:"—"})},T.key)})]}),e.jsx(Bt,{children:f.expanded&&e.jsx(Pe.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:f.loading?e.jsxs("div",{className:"flex items-center py-4",children:[e.jsx(ct,{size:16,className:"animate-spin text-indigo-500 mr-2"}),e.jsx("span",{className:"text-sm text-slate-500",children:"Analyzing competency data..."})]}):f.competency?e.jsxs("div",{className:"space-y-4 max-w-4xl",children:[f.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(Lt,{className:"w-4 h-4"})," Recommended Focus Areas"]}),e.jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:f.competency.recommendedTopics.map((T,E)=>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:T},E))})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:f.competency.competencies.map((T,E)=>e.jsx(_u,{competency:T},E))})]}):e.jsx("div",{className:"text-sm text-slate-500 py-4",children:"Failed to load competency details."})})]})})})]},f.rowKey)))})]})})]})},_u=({competency:t})=>{const s=lo[t.competencyLevel]||lo.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(Pe.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})]})},Ru=()=>{const{notifications:t,unreadCount:s,isLoading:a,markAsRead:r,markAllAsRead:n}=Io(),[o,i]=h.useState("all"),l=p=>{switch(p){case"achievement_unlocked":case"achievement":return pl;case"message":return Nl;case"grade":case"quiz_result":return _o;case"reminder":case"streak_reminder":case"daily_checkin":return Ms;case"risk_alert":return _s;case"sparkles":case"lesson_plan_ready":return ss;case"users":case"student_import":return Rt;default:return Rs}},c=(p,g)=>{switch(p){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"}},d=p=>{switch(p){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)]"}},x=h.useMemo(()=>{let p=t;return o==="unread"&&(p=p.filter(g=>!g.isRead)),o==="important"&&(p=p.filter(g=>g.type==="risk_alert")),p},[t,o]),b=h.useMemo(()=>{const p=[],g=x.filter(N=>Tn(N.createdAt)),C=x.filter(N=>In(N.createdAt)),S=x.filter(N=>!Tn(N.createdAt)&&!In(N.createdAt));return g.length>0&&p.push({title:"Today",icon:Ms,items:g}),C.length>0&&p.push({title:"Yesterday",icon:mn,items:C}),S.length>0&&p.push({title:"Earlier",icon:mn,items:S}),p},[x]);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 ${o==="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 ${o==="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:s})]}),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 ${o==="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",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:s>0?`${s} unread`:"No unread"}),e.jsxs("button",{onClick:n,disabled:s===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(Ao,{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(ct,{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(Rs,{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(p=>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(p.icon,{className:"w-4 h-4"})," ",p.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:p.items.map(g=>{const C=l(g.type),S=g.type==="risk_alert";return e.jsxs(Pe.div,{layout:!0,onClick:()=>!g.isRead&&r(g.id),className:`relative p-5 flex gap-5 group cursor-pointer hover:bg-white transition-all duration-300 ${g.isRead?"opacity-80":c(g.type)}`,children:[e.jsx("div",{className:`absolute left-0 top-0 w-1.5 h-full transition-colors ${g.isRead?"bg-transparent":S?"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 ${d(g.type)}`,children:e.jsx(C,{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:[g.title,!g.isRead&&e.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${S?"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 ${g.isRead?"text-[#94a3b8]":S?"text-rose-600":"text-[#a855f7]"}`,children:[Fo(g.createdAt)," ago"]})]}),e.jsx("p",{className:"text-[14px] text-[#475569] font-medium leading-relaxed",children:g.message}),!g.isRead&&g.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 ${S?"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(sc,{size:18})})]},g.id)})})]},p.title))})]})})},Mu=t=>{const s=t.data(),a=s.startTime,r=s.endTime,n=s.createdAt,o=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(n)||new Date,updatedAt:i(o)}},zu=async(t,s)=>{const a=vt(Xt(st,"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 Zt(a,{...r,createdAt:ft(),updatedAt:ft()}),r},Lu=async(t,s)=>{const a=vt(st,"calendarEvents",t);await Kt(a,{...s,updatedAt:ft()})},Au=async t=>{await vl(vt(st,"calendarEvents",t))},Du=(t,s={},a,r)=>{if(!t)return a([]),()=>{};const{limitCount:n=500}=s,o=Ht(Xt(st,"calendarEvents"),Gt("userId","==",t),zo(n));return Lo(o,i=>{a(i.docs.map(l=>Mu(l)))},i=>{console.error("Error subscribing to calendar events:",i),r?.(i)})};function Fu({className:t,...s}){return e.jsx("textarea",{"data-slot":"textarea",className:Eo("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 Ts=t=>String(t).padStart(2,"0"),ds=t=>`${t.getFullYear()}-${Ts(t.getMonth()+1)}-${Ts(t.getDate())}`,pr=t=>new Date(t.getFullYear(),t.getMonth(),1),co=t=>new Date(t.getFullYear(),t.getMonth()+1,0),$u=t=>{const s=pr(t),a=s.getDay(),r=new Date(s);return r.setDate(s.getDate()-a),r.setHours(0,0,0,0),r},Ou=(t,s)=>{const a=new Date(t);return a.setDate(a.getDate()+s),a},uo=(t,s)=>t.getFullYear()===s.getFullYear()&&t.getMonth()===s.getMonth()&&t.getDate()===s.getDate(),Bu=(t,s)=>t.getFullYear()===s.getFullYear()&&t.getMonth()===s.getMonth(),Pu=t=>t.toLocaleDateString(void 0,{month:"long",year:"numeric"}),pa=t=>t.toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"}),mo=(t,s)=>{const[a,r,n]=t.split("-").map(l=>parseInt(l,10)),[o,i]=s.split(":").map(l=>parseInt(l,10));return new Date(a,(r||1)-1,n||1,o||0,i||0,0,0)},Hu=["purple","blue","emerald","amber","rose"],Za=t=>{switch(t){case"blue":return"#3b82f6";case"emerald":return"#10b981";case"amber":return"#f59e0b";case"rose":return"#f43f5e";case"purple":default:return"#a855f7"}},Gu=(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"}},Qu=(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"}}},er=[{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 Vu(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 n=er.find(i=>i.names.includes(r[1]))?.day,o=er.find(i=>i.names.includes(r[2]))?.day;if(n!==void 0&&o!==void 0){let i=n;for(;a.add(i),i!==o;)i=(i+1)%7;return Array.from(a)}}return er.forEach(({names:n,day:o})=>{n.some(i=>s.includes(i))&&a.add(o)}),Array.from(a).sort((n,o)=>n-o)}const Uu=({classes:t,teacherId:s})=>{const{currentUser:a}=gs(),[r,n]=h.useState([]),[o,i]=h.useState(!0),[l,c]=h.useState(""),[d,x]=h.useState(!0),[b,p]=h.useState(()=>{const z=new Date;return z.setHours(0,0,0,0),z}),[g,C]=h.useState(()=>{const z=new Date;return z.setHours(0,0,0,0),z}),[S,N]=h.useState(new Set),[m,w]=h.useState(!1),[y,R]=h.useState(null),[j,H]=h.useState(!1),[v,k]=h.useState(""),[I,$]=h.useState(""),[D,q]=h.useState(()=>ds(new Date)),[Q,A]=h.useState("09:00"),[U,ee]=h.useState(""),[ie,je]=h.useState("purple"),[ge,Ce]=h.useState(!1),[de,B]=h.useState(null);h.useEffect(()=>{if(!a?.uid){n([]),i(!1);return}c(""),i(!0);const z=Du(a.uid,{limitCount:500},oe=>{n(oe),i(!1)},()=>{c("Unable to load calendar events right now."),i(!1)});return()=>z()},[a?.uid]);const Y=h.useMemo(()=>{const z=pr(b);return z.setHours(0,0,0,0),z},[b]),ne=h.useMemo(()=>{const z=co(b);return z.setHours(23,59,59,999),z},[b]),De=h.useMemo(()=>{if(!t||t.length===0)return[];const z=[],oe=pr(b),ue=co(b),ve=new Date(oe);for(;ve<=ue;){const K=ve.getDay();t.forEach(we=>{if(Vu(we.schedule).includes(K)){const Se=`schedule-${we.id}-${ds(ve)}`;S.has(Se)||z.push({id:Se,userId:s||"",title:we.name,startTime:new Date(ve),createdAt:new Date})}}),ve.setDate(ve.getDate()+1)}return z},[t,b,s,S]),Le=h.useMemo(()=>[...r,...De],[r,De]),Ge=h.useMemo(()=>Le.filter(z=>z.startTime>=Y&&z.startTime<=ne).sort((z,oe)=>z.startTime.getTime()-oe.startTime.getTime()),[Le,Y,ne]),O=h.useMemo(()=>{const z=new Map;for(const oe of Ge){const ue=ds(oe.startTime),ve=z.get(ue)||[];ve.push(oe),z.set(ue,ve)}return z},[Ge]),X=h.useMemo(()=>ds(g),[g]),f=h.useMemo(()=>[...O.get(X)||[]].sort((oe,ue)=>oe.startTime.getTime()-ue.startTime.getTime()),[O,X]),T=h.useMemo(()=>{const z=$u(b);return Array.from({length:42}).map((oe,ue)=>Ou(z,ue))},[b]),E=z=>{const oe=ds(z);R(null),k(""),$(""),q(oe),A("09:00"),ee(""),je("purple"),w(!0)},W=z=>{z.id.startsWith("schedule-")?(N(oe=>new Set(oe).add(z.id)),R(null)):R(z.id),k(z.title),$(z.description||""),q(ds(z.startTime)),A(Ts(z.startTime.getHours())+":"+Ts(z.startTime.getMinutes())),ee(z.endTime?Ts(z.endTime.getHours())+":"+Ts(z.endTime.getMinutes()):""),je(z.color||"purple"),Ce(!1),w(!0)},V=(z,oe)=>{z.stopPropagation(),B(oe),Ce(!0)},se=async()=>{const z=a?.uid||s||"local-user";if(!v.trim()){c("Event title is required.");return}H(!0),c("");const oe=mo(D,Q),ue=U?mo(D,U):void 0,ve={title:v.trim(),description:I.trim()?I.trim():void 0,startTime:oe,endTime:ue&&ue.getTime()>oe.getTime()?ue:void 0,color:ie};try{if(y)n(K=>K.map(we=>we.id===y?{...we,...ve}:we)),await Lu(y,ve);else{const K=`temp-${Date.now()}`;n(we=>[...we,{id:K,userId:z,createdAt:new Date,...ve}]),await zu(z,ve)}w(!1)}catch(K){console.error(K),w(!1)}finally{H(!1)}},ae=async z=>{if(z.startsWith("schedule-")){N(oe=>new Set(oe).add(z)),de?.id===z&&Ce(!1);return}c(""),n(oe=>oe.filter(ue=>ue.id!==z)),de?.id===z&&Ce(!1);try{await Au(z)}catch(oe){console.error(oe)}};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:()=>p(new Date(b.getFullYear(),b.getMonth()-1,1)),className:"w-9 h-9 rounded-full flex items-center justify-center text-[#a855f7] bg-white hover:bg-slate-50 transition-colors shadow-sm hover:shadow-md active:scale-90",children:e.jsx(as,{className:"w-5 h-5"})}),e.jsx("h2",{className:"text-[22px] font-bold text-white w-44 text-center tracking-tight",children:Pu(b)}),e.jsx("button",{onClick:()=>p(new Date(b.getFullYear(),b.getMonth()+1,1)),className:"w-9 h-9 rounded-full flex items-center justify-center text-[#a855f7] bg-white hover:bg-slate-50 transition-colors shadow-sm hover:shadow-md active:scale-90",children:e.jsx(es,{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-[#a855f7] bg-white px-4 py-1.5 rounded-full shadow-sm",children:[Ge.length," events"]}),e.jsx("button",{onClick:()=>x(!d),className:`w-9 h-9 rounded-full flex items-center justify-center transition-all shadow-sm hover:shadow-md border ${d?"text-[#a855f7] bg-white border-white":"text-white bg-white/20 border-white/30 backdrop-blur-md"}`,title:d?"Hide Sidebar":"Show Sidebar",children:e.jsx(uc,{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(z=>e.jsx("div",{className:"text-[12px] font-bold text-[#94a3b8] uppercase tracking-widest",children:z},z))}),e.jsx("div",{className:"grid grid-cols-7 gap-2 pb-6 px-4",children:T.map(z=>{const oe=ds(z),ue=O.get(oe)||[],ve=uo(z,g),K=uo(z,new Date),we=Bu(z,b);return e.jsxs("div",{onClick:()=>C(new Date(z)),className:`group p-2 rounded-lg transition-all cursor-pointer border-2 flex flex-col relative min-h-[100px] xl:min-h-[120px] ${ve?"bg-purple-50/50 border-[#a855f7] shadow-sm z-10":K?"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"} ${we?"":"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 ${K?"bg-gradient-to-br from-[#a855f7] to-[#9333ea] text-white shadow-md":ve?"text-[#9333ea]":"text-[#1e293b]"}`,children:z.getDate()})}),e.jsxs("div",{className:"mt-1 space-y-1",children:[ue.slice(0,3).map(We=>{const Se=We.id.startsWith("schedule-");return e.jsx("div",{onClick:Je=>V(Je,We),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 ${Gu(We.color,Se)}`,children:We.title},We.id)}),ue.length>3&&e.jsxs("div",{className:"text-[10px] font-bold text-[#64748b] pl-1 pt-0.5",children:["+",ue.length-3," more"]})]})]},oe)})})]})]})}),e.jsx(Bt,{children:d&&e.jsx(Pe.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:g.toLocaleDateString(void 0,{weekday:"long"})}),e.jsx("p",{className:"text-[13px] font-medium text-[#64748b]",children:g.toLocaleDateString(void 0,{day:"numeric",month:"long",year:"numeric"})})]}),e.jsx("button",{onClick:()=>E(g),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(rr,{className:"w-5 h-5"})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-6 space-y-6 custom-scrollbar pb-12",children:f.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-20 text-center opacity-40",children:[e.jsx(Qa,{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."})]}):f.map(z=>{const oe=z.id.startsWith("schedule-"),ue=Qu(z.color,oe);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:ve=>V(ve,z),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:z.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(Ms,{className:"w-3.5 h-3.5"})," ",e.jsxs("span",{children:[pa(z.startTime),z.endTime?` - ${pa(z.endTime)}`:""]})]}),z.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:z.description})]})]},z.id)})})]})})})]}),e.jsx(fn,{open:m,onOpenChange:w,children:e.jsx(gn,{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(Ul,{className:"mb-6",children:[e.jsx(Wl,{className:"text-[24px] font-bold text-[#1e293b] tracking-tight",children:y?"Edit Event":"Add New Event"}),e.jsx(ql,{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(Qs,{value:v,onChange:z=>k(z.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(Qs,{type:"date",value:D,onChange:z=>q(z.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(Qs,{type:"time",value:Q,onChange:z=>A(z.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(Fu,{value:I,onChange:z=>$(z.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:Hu.map(z=>e.jsx("button",{onClick:()=>je(z),className:`w-8 h-8 rounded-full flex items-center justify-center transition-all ${ie===z?"ring-2 ring-offset-2 ring-slate-800 scale-110 shadow-sm":"hover:scale-110 opacity-80 hover:opacity-100"}`,style:{backgroundColor:Za(z)},title:z,children:ie===z&&e.jsx(Ut,{className:"w-4 h-4 text-white"})},z))})]})]}),e.jsxs("div",{className:"flex gap-3 mt-8",children:[e.jsx(ms,{variant:"outline",onClick:()=>w(!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(ms,{onClick:se,disabled:j,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:j?e.jsx(ct,{className:"w-5 h-5 animate-spin"}):"Save Event"})]})]})})}),e.jsx(fn,{open:ge,onOpenChange:Ce,children:e.jsx(gn,{className:"sm:max-w-[400px] p-0 overflow-hidden rounded-[24px] border-none shadow-2xl [&>button]:hidden",children:de&&e.jsxs("div",{className:"p-8 bg-white relative",children:[e.jsx("button",{onClick:()=>Ce(!1),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(ps,{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:Za(de.color||"purple")+"20",color:Za(de.color||"purple")},children:de.id.startsWith("schedule-")?e.jsx(Mo,{size:24}):e.jsx(Qa,{size:24})}),e.jsxs("div",{className:"pr-6",children:[e.jsx("h3",{className:"text-[18px] font-bold text-[#1e293b] leading-tight mb-2",children:de.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(Qa,{size:12}),de.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(Ms,{size:12}),pa(de.startTime),de.endTime?` - ${pa(de.endTime)}`:""]})]})]})]}),de.description&&e.jsxs("div",{className:"mb-8",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(Xl,{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:de.description})]}),e.jsxs("div",{className:"flex gap-3 pt-2 border-t border-slate-100",children:[e.jsxs(ms,{variant:"outline",onClick:()=>ae(de.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(Oo,{className:"w-4 h-4 mr-2"})," Delete"]}),e.jsxs(ms,{onClick:()=>W(de),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(Qo,{className:"w-4 h-4 mr-2"})," Edit Event"]})]})]})})})]})},Ea=[{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]"}],xo=({classes:t,onSelectClass:s,onOpenNotifications:a,onOpenProfile:r,insightDismissed:n,onOpenInsightModal:o,viewType:i="analytics"})=>{const{currentUser:l,userProfile:c}=gs(),[d,x]=h.useState(""),b=i==="competency",p=t.reduce((N,m)=>N+(m.studentCount||0),0),g=t.reduce((N,m)=>N+(m.atRiskCount||0),0),C=t.length>0?(t.reduce((N,m)=>N+(m.avgScore||0),0)/t.length).toFixed(1):0,S=t.filter(N=>N.name.toLowerCase().includes(d.toLowerCase())||(N.gradeLevel||"").toLowerCase().includes(d.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-[24px] xl:p-[32px] 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(ra,{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:d,onChange:N=>x(N.target.value),className:"bg-transparent border-none focus:outline-none ml-3 text-[13px] w-full text-[#475569] placeholder:text-[#94a3b8]"})]})})}),b?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(Rt,{className:"w-4 h-4 text-white"})})]}),e.jsx("div",{className:"text-[32px] font-bold relative z-10 leading-none mb-6",children:p}),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(Yt,{className:"w-4 h-4 text-white"})})]}),e.jsxs("div",{className:"text-[32px] font-bold relative z-10 leading-none mb-6",children:[C,"%"]}),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:"Vs. expected benchmark"}),e.jsx("span",{className:"text-[11px] font-bold bg-white/20 px-2 py-0.5 rounded-[4px] backdrop-blur-sm",children:"+1.4%"})]})]}),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(Yt,{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-[16px]",children:[e.jsxs("div",{className:"lg:col-span-8 grid grid-cols-1 sm:grid-cols-3 gap-[16px]",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)] 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:"Attendance rate"}),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(Rt,{className:"w-4 h-4 text-white"})})]}),e.jsx("div",{className:"text-[32px] font-bold relative z-10 leading-none mb-6",children:"94%"}),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:"Active participants"}),e.jsx("span",{className:"text-[11px] font-bold bg-white/20 px-2 py-0.5 rounded-[4px] backdrop-blur-sm",children:p>0?Math.round(p*.94):0})]})]}),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:"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(Yt,{className:"w-4 h-4 text-white"})})]}),e.jsxs("div",{className:"text-[32px] font-bold relative z-10 leading-none mb-6",children:[C,"%"]}),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:"Vs. last month"}),e.jsx("span",{className:"text-[11px] font-bold bg-white/20 px-2 py-0.5 rounded-[4px] backdrop-blur-sm",children:"+2.1%"})]})]}),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:"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(aa,{className:"w-4 h-4 text-white"})})]}),e.jsx("div",{className:"text-[32px] font-bold relative z-10 leading-none mb-6",children:g}),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:[p>0?Math.round(g/p*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.jsx("span",{className:"text-[10px] font-bold text-[#9333ea] bg-white px-2 py-0.5 rounded-[4px]",children:"2 Pending"})]}),e.jsxs("div",{className:"space-y-[8px] flex-1 overflow-y-auto no-scrollbar relative z-10",children:[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(Bo,{className:"w-4 h-4"})}),e.jsxs("div",{className:"leading-snug text-white/90",children:[e.jsx("span",{className:"font-bold text-white",children:"Grade 11 - Section B"})," average dropped by 4% after the last quiz."]})]}),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(Wt,{className:"w-4 h-4"})}),e.jsxs("div",{className:"leading-snug text-white/90",children:[e.jsx("span",{className:"font-bold text-white",children:"3 Lesson Plans"})," generated and awaiting your review."]})]})]})]})]}),e.jsxs("div",{className:"bg-white/60 backdrop-blur-[12px] rounded-[24px] p-[24px] shadow-[0_1px_4px_rgba(0,0,0,0.02)] border border-white mt-[24px]",children:[e.jsx("div",{className:"mb-6 border-b border-[#f1f5f9] pb-4",children:e.jsx("h2",{className:"text-[18px] font-semibold text-[#1e293b]",children:b?"Select a Class":"My Classes"})}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-[16px]",children:[S.map((N,m)=>{const w=Ea[m%Ea.length];let y=null;return N.riskLevel==="high"?y=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"}):N.riskLevel==="medium"?y=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"}):y=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(N),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] ${w.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] ${w.bg} flex items-center justify-center border ${w.border}`,children:e.jsx(Lt,{className:`w-5 h-5 ${w.text}`})}),e.jsxs("div",{children:[e.jsx("h4",{className:`font-bold text-[14px] text-[#1e293b] mb-0.5 transition-colors ${w.groupHover}`,children:N.name}),e.jsx("p",{className:"text-[11px] font-semibold text-[#64748b] uppercase tracking-wider",children:N.gradeLevel||"Senior High"})]})]}),y]}),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:N.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:b?"Avg Competency":"Average"}),e.jsxs("span",{className:"font-semibold text-[#1e293b]",children:[N.avgScore,"%"]})]}),!b&&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:N.schedule||"Mon-Fri"})]})]})]})]},N.id)}),S.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."})]})]})]})})},zi="PH_SHS_OFFICIAL_CLASS_RECORD",Wu=.85,hr=.85,qu="2026.04.24",Li=4,wa=["INPUT DATA","SENIOR HIGH SCHOOL CLASS RECORD","LEARNERS NAMES","WRITTEN WORK","PERFORMANCE TASKS","QUARTERLY ASSESSMENT","REMARK","FINAL SEMESTRAL GRADES"],Yu=[...wa,"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"],Ku=["SUBMITTED BY","CHECKED BY","VERIFIED BY","RECOMMENDED BY","APPROVED BY"],la=["WITH ATTACHMENTS","OFFICIALLY DROPPED","WITHDRAWN","UNOFFICIALLY DROPPED","TRANSFEREE","SHIFTER"],Xu=["TOTAL","SUBMITTED BY","CHECKED BY","VERIFIED BY","RECOMMENDED BY","APPROVED BY","WEIGHT OF COMPONENTS"],Ju={SECOND:["SECOND QUARTER","2ND QUARTER","Q2"]},ks={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"]},St={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"]},Ae={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 Zu(t){return t==null?null:typeof t=="string"||typeof t=="number"||typeof t=="boolean"?t:String(t)}function dt(t){return String(t??"").replace(/[\u00a0\t\r\n]+/g," ").replace(/[|]+/g," ").replace(/\s+/g," ").trim().toUpperCase()}function po(t){return dt(t).replace(/[^A-Z0-9]+/g,"")}function ke(t,s){const a=dt(t),r=dt(s);if(!a||!r)return!1;if(a.includes(r))return!0;const n=po(t),o=po(s);return!n||!o?!1:n.includes(o)}function Na(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 tr(t){return dt(t).toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"").slice(0,80)}function Ai(t){const s={};return t.forEach(a=>{const r=Tt.encode_cell(a.s);for(let n=a.s.r;n<=a.e.r;n+=1)for(let o=a.s.c;o<=a.e.c;o+=1){const i=Tt.encode_cell({r:n,c:o});s[i]=r}}),s}function em(t,s,a){const n=(a||Ai(t.merges))[s]||s;return t.cells[n]||t.cells[s]}const Di="A1:A1",ho=1200,fo=200,go=2e5;function tm(t){const s=Math.max(0,t.s.r),a=Math.max(0,t.s.c);let r=Math.max(s,t.e.r),n=Math.max(a,t.e.c);r-s+1>ho&&(r=s+ho-1),n-a+1>fo&&(n=a+fo-1);const o=r-s+1,i=n-a+1;if(o*i>go){const c=Math.max(1,Math.floor(go/i));r=s+Math.min(o,c)-1}return{s:{r:s,c:a},e:{r,c:n}}}function sm(t){try{return Tt.decode_range(t)}catch{return Tt.decode_range(Di)}}function am(t){let s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY,n=Number.NEGATIVE_INFINITY;return Object.keys(t.cells).forEach(o=>{try{const i=Tt.decode_cell(o);s=Math.min(s,i.r),a=Math.min(a,i.c),r=Math.max(r,i.r),n=Math.max(n,i.c)}catch{}}),t.merges.forEach(o=>{s=Math.min(s,o.s.r,o.e.r),a=Math.min(a,o.s.c,o.e.c),r=Math.max(r,o.s.r,o.e.r),n=Math.max(n,o.s.c,o.e.c)}),!Number.isFinite(s)||!Number.isFinite(a)||!Number.isFinite(r)||!Number.isFinite(n)?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(n))}}}function rm(t){const s=sm(t.ref||Di),a=am(t);return tm(a||s)}function nm(t,s){const a=rm(s),r=`${Tt.encode_cell(a.s)}:${Tt.encode_cell(a.e)}`,n=Ai(s.merges),o=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 ls(t,s){return st.endRow?"":(t.cells[s-t.startRow]||[]).map(r=>r?.normalizedText||"").filter(Boolean).join(" ").trim()}function Hs(t){return Tt.encode_col(t)}function ha(t){const s=String(t||"").trim().toUpperCase();if(!s||!/^[A-Z]+$/.test(s))return-1;try{return Tt.decode_col(s)}catch{return-1}}function om(t){return`${Tt.encode_cell(t.s)}:${Tt.encode_cell(t.e)}`}function im(t,s){const a=[];for(let r=s.s.r;r<=s.e.r;r+=1){const n=[];for(let o=s.s.c;o<=s.e.c;o+=1){const i=Oe(t,r,o);n.push(i?.displayValue??null)}a.push(n)}return a}function lm(t,s){const a=dt(t),r=dt(s);return!a||!r?0:a===r?1:a.includes(r)?.9:.75}function Mr(t,s){const a=[];for(let r=0;r{ke(l.normalizedText,c)&&a.push({sheetName:t.sheetName,anchor:c,row:l.row,col:l.col,address:l.address,value:String(l.displayValue??""),confidence:lm(l.displayValue,c)})})}const n=t.startRow+r,o=ls(t,n);o&&s.forEach(i=>{if(!ke(o,i))return;const l=t.cells[r].find(c=>c?.normalizedText);l&&a.push({sheetName:t.sheetName,anchor:i,row:n,col:l.col,address:l.address,value:o,confidence:.8})})}return a}function cm(t,s){return Object.values(t).flatMap(a=>Mr(a,s))}function xt(t,s){return Mr(t,[s]).sort((a,r)=>a.row-r.row||a.col-r.col)}function Fi(t,s,a,r=6){for(let n=1;n<=r;n+=1){const i=Oe(t,s,a+n)?.displayValue;if(i!=null&&String(i).trim())return String(i).trim()}for(let n=1;n<=r;n+=1){const i=Oe(t,s+n,a)?.displayValue;if(i!=null&&String(i).trim())return String(i).trim()}}function $i(t,s,a=5){let r=s,n=-1;for(let o=Math.max(t.startRow,s-a);o<=Math.min(t.endRow,s+a);o+=1){const i=ls(t,o),l=["LEARNERS NAMES","WRITTEN WORK","PERFORMANCE TASKS","QUARTERLY ASSESSMENT","REMARK"].reduce((c,d)=>i.includes(d)?c+1:c,0);l>n&&(n=l,r=o)}return r}function dm(t,s){const a=dt(t).toLowerCase(),r=n=>[...s].some(o=>ke(o,n));return ks.inputData.some(n=>a.includes(n))||r("INPUT DATA")?"inputData":ks.finalSemestral.some(n=>a.includes(n))||r("FINAL SEMESTRAL GRADES")||r("FINAL GRADES")?"finalSemestral":ks.firstQuarter.some(n=>a.includes(n))||r("FIRST QUARTER")?"firstQuarter":ks.secondQuarter.some(n=>a.includes(n))||r("SECOND QUARTER")?"secondQuarter":r("SENIOR HIGH SCHOOL CLASS RECORD")||r("WRITTEN WORK")&&r("PERFORMANCE TASKS")?"firstQuarter":ks.helper.some(n=>a.includes(n))||r("WEIGHT OF COMPONENTS")||r("ATTACHMENTS")||r("HELPER")?"helper":ks.lookup.some(n=>a.includes(n))||r("LOOK UP")?"lookup":"other"}function um(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,n=.65*s+.2*a+.15*r;return Number(Math.max(0,Math.min(1,n)).toFixed(4))}function mm(t){const s=cm(t.matrices,Yu),a=new Set,r=[];wa.forEach(g=>{s.some(S=>ke(S.anchor,g))&&(a.add(g),r.push(`Found critical anchor: ${g}`))});const n=wa.filter(g=>!a.has(g)),o=new Map;s.forEach(g=>{o.has(g.sheetName)||o.set(g.sheetName,new Set),o.get(g.sheetName)?.add(g.anchor)});const i=t.sheetNames.map(g=>{const C=o.get(g)||new Set,S=dm(g,C),N=Math.min(1,.35+Math.min(.55,C.size*.08)),m=[`sheet:${g}`,`signals:${C.size}`,...[...C].slice(0,5)];return{sheetName:g,role:S,confidence:Number(N.toFixed(3)),evidence:m}}),l={firstQuarter:[],secondQuarter:[],finalSemestral:[],helper:[],lookup:[],other:[]};i.forEach(g=>{switch(g.role){case"inputData":l.inputData?l.other.push(g.sheetName):l.inputData=g.sheetName;break;case"firstQuarter":l.firstQuarter.push(g.sheetName);break;case"secondQuarter":l.secondQuarter.push(g.sheetName);break;case"finalSemestral":l.finalSemestral.push(g.sheetName);break;case"helper":l.helper.push(g.sheetName);break;case"lookup":l.lookup.push(g.sheetName);break;case"other":default:l.other.push(g.sheetName);break}});const c=(l.inputData?1:0)+l.firstQuarter.length+l.secondQuarter.length+l.finalSemestral.length+l.helper.length+l.lookup.length,d=um({criticalFound:a.size,criticalTotal:wa.length,recognizedSheets:c,totalSheets:t.sheetNames.length,hasDepedAnchor:s.some(g=>ke(g.anchor,"Pursuant to DepEd Order 8 series of 2015"))}),x=l.firstQuarter.length>0||l.secondQuarter.length>0,b=!!l.inputData&&x&&l.finalSemestral.length>0,p=d>=.55&&b;return l.inputData||r.push("Input Data sheet not confidently detected."),x||r.push("No quarter class record sheet detected."),l.finalSemestral.length===0&&r.push("No Final Semestral Grades sheet detected."),{format:zi,isOfficialFormatLikely:p,confidence:d,evidence:r,missingCriticalAnchors:n,detectedSheets:l,anchorMatches:s}}function _a(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 zr(t){const s=dt(t);if(s.includes("FEMALE"))return"FEMALE";if(s.includes("MALE"))return"MALE"}function Lr(t){const s=dt(t.rowText);return s?s==="MALE"||s==="FEMALE"?"sex-header":Ku.some(a=>s.includes(a))?"signature":Xu.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 xm(t){const s=["SUBMITTED BY","CHECKED BY","VERIFIED BY","RECOMMENDED BY","APPROVED BY"],a=[];return s.forEach(r=>{xt(t,r).forEach(n=>{a.push({role:r,name:String(Oe(t,n.row,n.col+1)?.displayValue||"").trim()||void 0,sourceSheet:t.sheetName,sourceRow:n.row+1})})}),a}function pm(t){const s=[],a=xt(t,"LEARNERS NAMES")[0],r=a?$i(t,a.row,5):t.startRow,n=(N,m)=>xt(t,N).find(y=>Math.abs(y.row-r)<=2)?.col??m,o=n(Ae.learnerNo[0],t.startCol),i=n(Ae.learnerName[0],t.startCol+1),l=n(Ae.firstQuarter[0],i+1),c=n(Ae.secondQuarter[0],l+1),d=n(Ae.firstSemester[0],c+1),x=n(Ae.finalGrades[0],d+1),b=n(Ae.remark[0],x+1),p=n(Ae.additionalRemarks[0],b+1),g=[];let C="UNKNOWN",S=0;for(let N=r+1;N<=t.endRow;N+=1){const m=ls(t,N),w=Lr({rowText:m,hasLearnerNumber:/\b\d{1,2}\b/.test(m),hasLearnerName:/[A-Z]{2,}/.test(m)});if(w==="sex-header"){C=zr(m)||C;continue}if(w==="signature"||w==="helper")break;if(w==="blank"){if(S+=1,S>=Li)break;continue}if(w!=="learner")continue;S=0;const y=_a(Oe(t,N,o)?.displayValue),R=String(Oe(t,N,i)?.displayValue||"").trim();if(!R&&y===void 0)continue;const j=Oe(t,N,l)?.displayValue??null,H=Oe(t,N,c)?.displayValue??null,v=Oe(t,N,d)?.displayValue??null,k=Oe(t,N,x)?.displayValue??null,I=Oe(t,N,b)?.displayValue??null;let $=Oe(t,N,p)?.displayValue??null;const D=la.filter(q=>ke(m,q));D.length>0&&($=[$,D.join("; ")].filter(Boolean).join("; ")||null),!R&&y!==void 0&&s.push(`Row ${N+1} has learner number ${y} but empty learner name.`),g.push({learnerNo:y,fullName:R||`Unnamed Learner ${y||N+1}`,sex:C,firstQuarter:j,secondQuarter:H,firstSemester:v,finalGrades:k,remark:I,additionalRemarks:$,sourceRow:N+1})}return{sheetName:t.sheetName,learnerGrades:g,signatures:xm(t),warnings:s}}function Et(t,s){for(const a of s){const r=xt(t,a);for(const n of r){const o=Fi(t,n.row,n.col,8);if(o&&o.trim())return o.trim()}}}function hm(t){const s=["SUBMITTED BY","CHECKED BY","VERIFIED BY","RECOMMENDED BY","APPROVED BY"],a=[];return s.forEach(r=>{xt(t,r).forEach(o=>{const i=Fi(t,o.row,o.col,10);a.push({role:r,name:i,sourceSheet:t.sheetName,sourceRow:o.row+1})})}),a}function fm(t){const s=xt(t,"LEARNERS NAMES")[0];if(!s)return[];const a=s.row+1,r=s.col,n=Math.max(t.startCol,r-1),o=Math.min(t.endCol,r+1),i=Math.min(t.endCol,r+2),l=[];let c="UNKNOWN",d=0;for(let x=a;x<=t.endRow;x+=1){const b=ls(t,x),p=Lr({rowText:b,hasLearnerNumber:!!_a(Oe(t,x,n)?.displayValue),hasLearnerName:!!String(Oe(t,x,r)?.displayValue||"").trim()});if(p==="sex-header"){c=zr(b)||c,d=0;continue}if(p==="signature"||p==="helper")break;if(p!=="learner"){if(p==="blank"&&(d+=1),d>=5)break;continue}d=0;const g=_a(Oe(t,x,n)?.displayValue),C=String(Oe(t,x,r)?.displayValue||"").trim(),S=String(Oe(t,x,o)?.displayValue||"").trim()||void 0,N=String(Oe(t,x,i)?.displayValue||"").trim()||void 0,m=la.filter(w=>ke(b,w));!C&&g===void 0||l.push({learnerNo:g,sex:c,fullName:C||`Unnamed Learner ${g||x}`,sourceSheet:t.sheetName,sourceRow:x+1,remarks:S,additionalRemarks:N,statuses:m.length>0?m:void 0})}return l}function gm(t){const s=[],a=[];for(let r=t.startRow;r<=t.endRow;r+=1){const n=ls(t,r);if(n){if(la.some(o=>ke(n,o))){s.push(n);continue}(ke(n,"IMPORTANT")||ke(n,"NOTE")||ke(n,"ATTACHMENT")||ke(n,"LOOK UP"))&&a.push(n)}}return{attachmentRules:Array.from(new Set(s)),helperNotes:Array.from(new Set(a))}}function bm(t){const s=[],a={region:Et(t,St.region),division:Et(t,St.division),schoolName:Et(t,St.schoolName),schoolId:Et(t,St.schoolId),schoolYear:Et(t,St.schoolYear),gradeSection:Et(t,St.gradeSection),semester:Et(t,St.semester),track:Et(t,St.track),subjectCode:Et(t,St.subjectCode),subjectName:Et(t,St.subjectName),teacherName:Et(t,St.teacherName)},r=fm(t),n=hm(t),{attachmentRules:o,helperNotes:i}=gm(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."),Mr(t,Object.values(St).flat()).length<4&&s.push("Input Data sheet contains limited metadata anchors; layout may have drifted."),{sheetName:t.sheetName,schoolContext:a,learners:r,signatures:n,attachmentRules:o,helperNotes:i,warnings:s}}function vm(t){const s=dt(t.sheetName);return Ju.SECOND.some(a=>ke(s,a))?"SECOND":"FIRST"}function wm(t,s){const a=[],r=[],n=[];let o,i="NONE";for(let l=t.startCol;l<=t.endCol;l+=1){const c=Oe(t,s,l),d=dt(c?.displayValue||""),x=Oe(t,s+1,l),b=String(x?.displayValue||c?.displayValue||"").trim();if(!d&&!b)continue;if(ke(d,Ae.writtenWork[0])){i="WW";continue}if(ke(d,Ae.performanceTasks[0])){i="PT";continue}if(ke(d,Ae.quarterlyAssessment[0])){o={key:tr(b||"quarterly_assessment"),label:b||"Quarterly Assessment",column:Hs(l)},i="DERIVED";continue}if(ke(d,Ae.initialGrade[0])||ke(d,Ae.quarterlyGrade[0])||ke(d,Ae.remark[0])||ke(d,Ae.additionalRemarks[0])||ke(d,Ae.firstQuarter[0])||ke(d,Ae.secondQuarter[0])||ke(d,Ae.firstSemester[0])||ke(d,Ae.finalGrades[0])||ke(d,Ae.ps[0])||ke(d,Ae.ws[0])||ke(d,Ae.total[0])){i="DERIVED",n.push({key:tr(b||d),label:b||d,column:Hs(l)});continue}const p={key:tr(b||d||Hs(l)),label:b||d||Hs(l),maxScore:Na(x?.displayValue),column:Hs(l)};i==="WW"?a.push(p):i==="PT"?r.push(p):i==="DERIVED"&&n.push(p)}return{writtenWorks:a,performanceTasks:r,quarterlyAssessment:o,derived:n}}function Nm(t){const s=["SUBMITTED BY","CHECKED BY","VERIFIED BY","RECOMMENDED BY","APPROVED BY"],a=[];return s.forEach(r=>{xt(t,r).forEach(n=>{const o=Oe(t,n.row,n.col+1),i=String(o?.displayValue||"").trim()||void 0;a.push({role:r,name:i,sourceSheet:t.sheetName,sourceRow:n.row+1})})}),a}function bo(t,s,a){for(let r=t.startCol;r<=t.endCol;r+=1){const n=dt(Oe(t,s,r)?.displayValue||""),o=dt(Oe(t,s+1,r)?.displayValue||"");if(a.some(i=>ke(n,i)||ke(o,i)))return r}}function jm(t,s,a,r){const n={learnerNo:_a(Oe(t,s,r.numberCol)?.displayValue),fullName:String(Oe(t,s,r.nameCol)?.displayValue||"").trim(),sourceRow:s+1},o={};a.writtenWorks.forEach(d=>{const x=d.column?ha(d.column):-1;if(x<0)return;const b=Oe(t,s,x)?.displayValue;o[d.key]=b??null}),Object.keys(o).length>0&&(n.writtenWorks=o);const i={};if(a.performanceTasks.forEach(d=>{const x=d.column?ha(d.column):-1;if(x<0)return;const b=Oe(t,s,x)?.displayValue;i[d.key]=b??null}),Object.keys(i).length>0&&(n.performanceTasks=i),a.quarterlyAssessment?.column){const d=ha(a.quarterlyAssessment.column);n.quarterlyAssessment=Oe(t,s,d)?.displayValue??null}const l=a.derived||[],c={};return l.forEach(d=>{if(!d.column)return;const x=ha(d.column);if(x<0)return;const b=Oe(t,s,x)?.displayValue??null;c[d.key]=b,ke(d.label,Ae.initialGrade[0])&&(n.initialGrade=b),ke(d.label,Ae.quarterlyGrade[0])&&(n.quarterlyGrade=b),ke(d.label,Ae.firstQuarter[0])&&(n.firstQuarter=b),ke(d.label,Ae.secondQuarter[0])&&(n.secondQuarter=b),ke(d.label,Ae.firstSemester[0])&&(n.firstSemester=b),ke(d.label,Ae.finalGrades[0])&&(n.finalGrades=b),ke(d.label,Ae.remark[0])&&(n.remark=b!==null?String(b):null),ke(d.label,Ae.additionalRemarks[0])&&(n.additionalRemarks=b!==null?String(b):null)}),Object.keys(c).length>0&&(n.totals=c),n}function ym(t){const s=vm(t),a=[],r=xt(t,Ae.learnerName[0])[0]||xt(t,Ae.learnerName[1])[0],n=r?$i(t,r.row,4):t.startRow,o=wm(t,n),i=bo(t,n,Ae.learnerNo)??t.startCol,l=bo(t,n,Ae.learnerName)??Math.min(t.endCol,i+1),c=[];let d="UNKNOWN",x=0;for(let C=n+1;C<=t.endRow;C+=1){const S=ls(t,C),N=Lr({rowText:S,hasLearnerNumber:/\b\d{1,2}\b/.test(S),hasLearnerName:/[A-Z]{2,}/.test(S)});if(N==="sex-header"){d=zr(S)||d;continue}if(N==="signature"||N==="helper")break;if(N==="blank"){if(x+=1,x>=Li)break;continue}if(N!=="learner")continue;x=0;const m=jm(t,C,o,{numberCol:i,nameCol:l});if(m.sex=d,!m.fullName&&m.learnerNo===void 0)continue;const w=la.filter(y=>ke(S,y));w.length>0&&!m.additionalRemarks&&(m.additionalRemarks=w.join("; ")),!m.fullName&&m.learnerNo!==void 0&&(a.push(`Row ${C+1} has learner number ${m.learnerNo} but empty name.`),m.fullName=`Unnamed Learner ${m.learnerNo}`),c.push(m)}o.writtenWorks.length===0&&o.performanceTasks.length===0&&a.push(`No detailed assessment columns detected in ${t.sheetName}.`);const b=Na(xt(t,"WRITTEN WORK %")[0]?.value||xt(t,"WRITTEN WORK")[0]?.value),p=Na(xt(t,"PERFORMANCE TASKS %")[0]?.value||xt(t,"PERFORMANCE TASKS")[0]?.value),g=Na(xt(t,"QUARTERLY ASSESSMENT %")[0]?.value||xt(t,"QUARTERLY ASSESSMENT")[0]?.value);return{sheetName:t.sheetName,quarter:s,gradingWeights:{writtenWork:b,performanceTasks:p,quarterlyAssessment:g},assessmentColumns:o,learnerGrades:c,signatures:Nm(t),warnings:a}}function Sm(t){const s=["SUBMITTED BY","CHECKED BY","VERIFIED BY","RECOMMENDED BY","APPROVED BY"],a=[];return s.forEach(r=>{xt(t,r).forEach(n=>{a.push({role:r,name:String(Oe(t,n.row,n.col+1)?.displayValue||"").trim()||void 0,sourceSheet:t.sheetName,sourceRow:n.row+1})})}),a}function km(t){const s=[];let a=!1;for(let r=t.startRow;r<=t.endRow;r+=1){const n=ls(t,r);if(!n){if(a&&s.length>0)break;continue}if(ke(n,"WEIGHT OF COMPONENTS")){a=!0;continue}if(!a)continue;const o={sourceRow:r+1,raw:n};for(let i=t.startCol;i<=t.endCol;i+=1){const l=Oe(t,r,i)?.displayValue;l==null||String(l).trim()===""||(o[`c${i}`]=l)}Object.keys(o).length>2&&s.push(o)}return s}function Cm(t){const s=[],a=[],r=[],n=[],o=[];return t.forEach(i=>{Sm(i).forEach(l=>a.push(l)),km(i).forEach(l=>r.push({...l,sourceSheet:i.sheetName}));for(let l=i.startRow;l<=i.endRow;l+=1){const c=ls(i,l);if(c){if(la.some(d=>ke(c,d))){n.push(`${i.sheetName}: ${c}`);continue}(ke(c,"HELPER")||ke(c,"LOOK UP")||ke(c,"IMPORTANT")||ke(c,"REFERENCE")||ke(c,"ATTACHMENT"))&&o.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(n)),helperNotes:Array.from(new Set(o)),signatures:a,warnings:s}}function Tm(t,s,a){const r=new Map,n=o=>{const i=`${dt(o.fullName)}|${o.learnerNo||""}|${o.sourceSheet}`,l=r.get(i);if(!l){r.set(i,o);return}const c=Array.from(new Set([...l.statuses||[],...o.statuses||[]]));r.set(i,{...l,...o,remarks:o.remarks||l.remarks,additionalRemarks:o.additionalRemarks||l.additionalRemarks,statuses:c.length>0?c:void 0})};return t.forEach(n),s.forEach(o=>{o.learnerGrades.forEach(i=>{n({learnerNo:i.learnerNo,sex:i.sex,fullName:i.fullName,sourceSheet:o.sheetName,sourceRow:i.sourceRow,remarks:i.remark||void 0,additionalRemarks:i.additionalRemarks||void 0})})}),a.forEach(o=>{o.learnerGrades.forEach(i=>{n({learnerNo:i.learnerNo,sex:i.sex,fullName:i.fullName,sourceSheet:o.sheetName,sourceRow:i.sourceRow,remarks:i.remark||void 0,additionalRemarks:i.additionalRemarks||void 0})})}),Array.from(r.values())}function Im(t,s,a,r){const n=[...t.signatures,...s.flatMap(i=>i.signatures),...a.flatMap(i=>i.signatures),...r.signatures],o=new Map;return n.forEach(i=>{const l=`${dt(i.role)}|${dt(i.name||"")}|${i.sourceSheet}`;o.set(l,i)}),Array.from(o.values())}function Em(t){const s=Tm(t.inputData.learners,t.quarterSheets,t.finalSheets);return{format:zi,version:qu,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:Im(t.inputData,t.quarterSheets,t.finalSheets,t.references),unclassifiedBlocks:t.unclassifiedBlocks},validation:t.validation,raw:t.workbook.raw}}function _m(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 Rm(t){const s={ref:t["!ref"],merges:_m(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 Mm(t,s){const a=Yl(s,{type:"array",cellFormula:!0,cellNF:!0,cellText:!0,cellDates:!0,raw:!1}),r={},n={};return a.SheetNames.forEach(o=>{const i=a.Sheets[o];if(!i)return;const l=Rm(i);n[o]=l,r[o]=nm(o,l)}),{fileName:t,sheetNames:a.SheetNames,raw:{sheets:n},matrices:r}}async function zm(t){const s=await t.arrayBuffer();return Mm(t.name,s)}class Lm{state={};markRange(s,a,r){const n=s;this.state[n]||(this.state[n]={mappedAddresses:new Set,mappings:[]});for(let o=a.s.r;o<=a.e.r;o+=1)for(let i=a.s.c;i<=a.e.c;i+=1)this.state[n].mappedAddresses.add(`${o}:${i}`);this.state[n].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(n=>{const o=new Set,i=this.state[n.sheetName]?.mappedAddresses??new Set;for(let l=n.startRow;l<=n.endRow;l+=1)for(let c=n.startCol;c<=n.endCol;c+=1){const d=`${l}:${c}`;if(o.has(d)||i.has(d))continue;const x=Oe(n,l,c);if(!(x&&x.displayValue!==null&&x.displayValue!==void 0&&String(x.displayValue).trim())){o.add(d);continue}const p=this.collectComponent(n,l,c,i,o);p&&r.push({sheetName:n.sheetName,range:om(p),purposeGuess:a,raw2D:im(n,p)})}}),r}collectComponent(s,a,r,n,o){const i=[{row:a,col:r}];let l=a,c=a,d=r,x=r,b=!1;for(;i.length>0;){const p=i.shift();if(!p)break;const g=`${p.row}:${p.col}`;if(o.has(g)||n.has(g))continue;o.add(g);const C=Oe(s,p.row,p.col);C&&C.displayValue!==null&&C.displayValue!==void 0&&String(C.displayValue).trim()&&(b=!0,l=Math.min(l,p.row),c=Math.max(c,p.row),d=Math.min(d,p.col),x=Math.max(x,p.col),[{row:p.row-1,col:p.col},{row:p.row+1,col:p.col},{row:p.row,col:p.col-1},{row:p.row,col:p.col+1}].forEach(N=>{N.rows.endRow||N.cols.endCol||i.push(N)}))}return b?{s:{r:l,c:d},e:{r:c,c:x}}:null}}function Am(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,n)=>r+n,0);return{totalSheets:t.totalSheets,recognizedSheets:a,unclassifiedSheets:s.other.length,mappedCellRegions:t.mappedCellRegions,unmappedCellRegions:t.unmappedCellRegions}}function Dm(t){const s=new Map;t.forEach(r=>{const n=`${r.learnerNo||""}|${r.fullName.trim().toUpperCase()}`;s.has(n)||s.set(n,[]),s.get(n)?.push(r.sourceRow)});const a=[];return s.forEach((r,n)=>{r.length>1&&a.push(`Duplicate learner entry detected for ${n} at rows ${r.join(", ")}.`)}),a}function Fm(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 n=r.writtenWorks&&Object.values(r.writtenWorks).some(i=>i!==null&&i!==""),o=r.performanceTasks&&Object.values(r.performanceTasks).some(i=>i!==null&&i!=="");!n&&!o&&r.quarterlyAssessment==null&&s.push(`${a.sheetName} row ${r.sourceRow}: all grade blocks are empty.`)})}),s}function $m(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 Om(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(", ")}.`),Dm(t.inputData.learners).forEach(o=>s.push(o)),Fm(t.quarterSheets).forEach(o=>s.push(o)),$m(t.finalSheets).forEach(o=>s.push(o)),s.push(...t.inputData.warnings),t.quarterSheets.forEach(o=>s.push(...o.warnings)),t.finalSheets.forEach(o=>s.push(...o.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,n=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}))),n=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}))),o=[...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,...n],remarksEntities:o}}const vo=1500;function wo(t){return t?Object.values(t.matrices).reduce((s,a)=>s+a.rowCount*a.colCount,0):0}function No(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>=vo){console.warn(`${s} slow=true threshold=${vo}ms`);return}}function us(t,s){t?.onProgress?.(s)}function Pm(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 Gs(t,s,a,r){Pm(a,s).forEach(n=>{t.markRange(s.sheetName,{s:{r:n,c:s.startCol},e:{r:n,c:s.endCol}},r)})}async function Hm(t,s){const a=s?.confidenceThreshold??Wu,r=Date.now();let n=null;try{if(us(s,{stage:"reading",message:"Reading workbook structure and raw sheets..."}),n=await zm(t),!n)throw new Error("Workbook read returned null");us(s,{stage:"detecting-format",message:"Detecting DepEd SHS workbook format..."});const o=mm(n);us(s,{stage:"extracting",message:"Extracting metadata, learners, grades, and references..."});const i=o.detectedSheets.inputData||n.sheetNames[0],l=n.matrices[i],c=l?bm(l):{sheetName:i,schoolContext:{},learners:[],signatures:[],attachmentRules:[],helperNotes:[],warnings:["Input data sheet was not available in matrix map."]},x=[...o.detectedSheets.firstQuarter||[],...o.detectedSheets.secondQuarter||[]].map(y=>n.matrices[y]).filter(y=>!!y).map(y=>ym(y)),b=(o.detectedSheets.finalSemestral||[]).map(y=>n.matrices[y]).filter(y=>!!y).map(y=>pm(y)),p=[...o.detectedSheets.helper||[],...o.detectedSheets.lookup||[]].map(y=>n.matrices[y]).filter(y=>!!y),g=Cm(p),C=new Lm;o.anchorMatches.forEach(y=>{const R=n.matrices[y.sheetName];R&&Gs(C,R,[y.row],`Anchor match: ${y.anchor}`)}),[c.sheetName].forEach(y=>{const R=n.matrices[y];if(!R)return;const j=Array.from({length:Math.min(14,R.rowCount)},(k,I)=>R.startRow+I),H=c.learners.map(k=>k.sourceRow-1),v=c.signatures.map(k=>k.sourceRow).filter(k=>typeof k=="number").map(k=>k-1);Gs(C,R,[...j,...H,...v],"Input Data parsed rows")}),x.forEach(y=>{const R=n.matrices[y.sheetName];if(!R)return;const j=y.learnerGrades.map(k=>k.sourceRow-1),H=y.signatures.map(k=>k.sourceRow).filter(k=>typeof k=="number").map(k=>k-1),v=j.length>0?Math.max(R.startRow,Math.min(...j)-2):R.startRow;Gs(C,R,[v,v+1,...j,...H],"Quarter sheet parsed rows")}),b.forEach(y=>{const R=n.matrices[y.sheetName];if(!R)return;const j=y.learnerGrades.map(k=>k.sourceRow-1),H=y.signatures.map(k=>k.sourceRow).filter(k=>typeof k=="number").map(k=>k-1),v=j.length>0?Math.max(R.startRow,Math.min(...j)-2):R.startRow;Gs(C,R,[v,v+1,...j,...H],"Final semestral parsed rows")}),p.forEach(y=>{const R=g.componentWeights.filter(v=>v.sourceSheet===y.sheetName).map(v=>v.sourceRow).filter(v=>typeof v=="number").map(v=>v-1),j=g.signatures?.filter(v=>v.sourceSheet===y.sheetName).map(v=>v.sourceRow).filter(v=>typeof v=="number").map(v=>v-1)||[],H=R.length===0&&j.length===0?[y.startRow,y.startRow+1,y.startRow+2]:[];Gs(C,y,[...R,...j,...H],"Reference/helper parsed rows")});const S=C.getUnmappedBlocks(n.matrices);us(s,{stage:"validating",message:"Validating completeness and structural integrity..."});const N=Om({detection:o,inputData:c,quarterSheets:x,finalSheets:b,mappedCellRegions:C.getMappedRegionCount(),unmappedCellRegions:S.length,totalSheets:n.sheetNames.length});us(s,{stage:"normalizing",message:"Normalizing parsed workbook and creating entity mapping..."});const m=Em({workbook:n,detection:o,inputData:c,quarterSheets:x,finalSheets:b,references:g,validation:N,unclassifiedBlocks:S});m.validation.confidencef.trim().toLowerCase().replace(/\s+/g," "),ie=f=>{if(typeof f=="number"&&Number.isFinite(f))return f;const T=Number(String(f??"").replace(/[^0-9.-]+/g,""));return Number.isFinite(T)?T:null},je=(f,T)=>{const E=Number.isFinite(f)?f:T;return Math.max(0,Math.min(100,E))},ge=f=>{const T=String(f??"");return/[",\n]/.test(T)?`"${T.replace(/"/g,'""')}"`:T},Ce=(f,T)=>{const E=new Map,W=["quarterlyGrade","finalGrades","firstSemester","firstQuarter","secondQuarter","initialGrade"];f.mapping.gradeEntities.forEach(K=>{const we=ee(K.fullName||"");if(!we)return;const We=W.map(Je=>ie(K[Je])).filter(Je=>Je!==null);if(We.length===0)return;const Se=E.get(we)||[];E.set(we,Se.concat(We))});const V=f.mapping.studentEntities||[];if(V.length===0)return null;const se=(f.imported.schoolContext.semester||f.imported.schoolContext.schoolYear||"First Semester").trim(),ae=(f.imported.schoolContext.subjectName||"Class Record Import").trim(),z=(t||s||"import").replace(/[^a-zA-Z0-9]+/g,"").toUpperCase().slice(0,12)||"IMPORT",ue=[["name","lrn","email","engagementScore","avgQuizScore","attendance","assignmentCompletion","term","assessmentName"].join(",")];if(V.forEach((K,we)=>{const We=ee(K.fullName||""),Se=E.get(We)||[],Je=Se.length>0?Se.reduce((_e,Fe)=>_e+Fe,0)/Se.length:75,et=je(Je,75),F=je(et+5,85),Z=je(et*.7+F*.3,80),Re=je(F*.6+et*.4,82),Ne=K.learnerNo||we+1,M=`IMP-${z}-${String(Ne).padStart(4,"0")}`,te=K.fullName||`Learner ${we+1}`;ue.push([ge(te),ge(M),ge(""),ge(Number(Z.toFixed(1))),ge(Number(et.toFixed(1))),ge(Number(F.toFixed(1))),ge(Number(Re.toFixed(1))),ge(se),ge(ae)].join(","))}),ue.length<=1)return null;const ve=T.replace(/\.(xlsx|xls)$/i,"");return new File([ue.join(` +`)],`${ve}-normalized.csv`,{type:"text/csv"})},de=async f=>{v(!0),D(""),Q(null);let T=f;if(/\.(xlsx|xls)$/i.test(f.name))try{const E=await Hm(f,{confidenceThreshold:hr});m(E);const W=Ce(E,f.name);W&&(T=W)}catch{m(null)}else m(null);try{const E=await Ze.uploadClassRecords(T,{classSectionId:t,className:s,datasetIntent:"synthetic_student_records"}),W=E.students.length,se=((ae,z,oe,ue)=>({classSectionId:ae.classSectionId||z||"imported_class",className:ae.className||oe||"Imported Class",classMetadata:ae.classMetadata||ue}))(E,t,s,a);W>0&&i?.({students:E.students,classSectionId:se.classSectionId,className:se.className,classMetadata:se.classMetadata}),E.success?(me.success(`Successfully imported ${W} student records.`),Q({datasetIntent:E.datasetIntent,summary:E.interpretationSummary,columns:E.columnInterpretations?.map(ae=>({columnName:ae.columnName,mappedField:ae.mappedField,usagePolicy:ae.usagePolicy,confidenceBand:ae.confidenceBand,domainSignals:ae.domainSignals}))||[]}),l?.()):me.error("Import completed but no usable student rows were detected. Check required columns and retry.")}catch(E){me.error(E instanceof Error?E.message:"Upload failed")}finally{v(!1)}},B=async f=>{I(!0);try{const T=await Ze.uploadCourseMaterials(f,{classSectionId:t,className:s});if(T.success){const E=T.topics?.length??0;me.success(`Course material imported (${E} topics extracted).`),l?.()}}catch(T){me.error(T instanceof Error?T.message:"Course material upload failed")}finally{I(!1)}},[Y,ne]=h.useState(r),[De,Le]=h.useState(!1);h.useEffect(()=>{ne(r),O(Object.fromEntries(r.map(f=>[fa(f),{grade:f.grade||"Grade 11",section:f.section||"Section A"}])))},[r]);const[Ge,O]=h.useState({}),X=async()=>{Le(!0);try{for(const T of Y){const E=Ge[fa(T)],W=E?.grade||T.grade,V=E?.section||T.section;n&&(W!==T.grade||V!==T.section)&&(await Ei(T.id,W,V,n,new Date().getFullYear().toString(),o),await Ci(T.id,W,V));try{const se=await Ze.predictRisk({engagementScore:T.engagementScore,avgQuizScore:T.avgScore,attendance:T.attendance,assignmentCompletion:T.assignmentCompletion});await ru(T.id,se.riskLevel,se.confidence)}catch(se){console.error("Failed to update risk:",se)}}const f=Y.map(T=>{const E=Ge[fa(T)];if(!E)return T;const W=mt({metadata:T.classMetadata,classSectionId:T.classSectionId,className:[E.grade,E.section].filter(Boolean).join(" - "),grade:E.grade,section:E.section});return{...T,grade:E.grade,section:E.section,className:W.className||[E.grade,E.section].filter(Boolean).join(" - "),classSectionId:W.classSectionId||T.classSectionId,classMetadata:W}});ne(f),d?.(f),me.success("Records saved and risk levels updated"),S("main")}catch{me.error("Failed to save changes")}finally{Le(!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:[C==="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(ya,{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:s||t||"All Classes",children:s||t?`${s} ${t?`(${t})`:""}`:"All Classes"}),e.jsx("option",{value:"Grade 11 - Section A",children:"Grade 11 - Section A"}),e.jsx("option",{value:"Grade 11 - Section B",children:"Grade 11 - Section B"})]}),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:f=>{f.preventDefault(),y(!0)},onDragLeave:()=>y(!1),onDrop:f=>{f.preventDefault(),y(!1);const T=f.dataTransfer.files[0];T&&de(T)},onClick:()=>A.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] ${w?"border-[#1FA7E1] bg-[#1FA7E1]/10":"border-[#1FA7E1]/30 hover:border-[#1FA7E1] bg-white hover:bg-[#1FA7E1]/5"}`,children:[e.jsx("input",{ref:A,type:"file",accept:".csv,.xlsx,.xls",onChange:f=>{const T=f.target.files?.[0];T&&de(T)},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:H?e.jsx("span",{className:"animate-spin text-[#1FA7E1]",children:"..."}):e.jsx(wc,{className:"w-8 h-8 text-[#1FA7E1]"})}),e.jsx("h3",{className:"text-[18px] font-bold text-[#1e293b] mb-2",children:H?"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:f=>{f.preventDefault(),j(!0)},onDragLeave:()=>j(!1),onDrop:f=>{f.preventDefault(),j(!1);const T=f.dataTransfer.files[0];T&&B(T)},onClick:()=>U.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:U,type:"file",accept:".pdf,.docx,.txt",onChange:f=>{const T=f.target.files?.[0];T&&B(T)},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:k?e.jsx("span",{className:"animate-spin text-[#9956DE]",children:"..."}):e.jsx(Wt,{className:"w-8 h-8 text-[#9956DE]"})}),e.jsx("h3",{className:"text-[18px] font-bold text-[#1e293b] mb-2",children:k?"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(bc,{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(Bo,{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(ss,{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(Ra,{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:()=>S("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(xc,{className:"w-4 h-4"})," Edit Class Records"]}),e.jsx("button",{onClick:()=>S("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:()=>S("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(ic,{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."})]})]})]})]}),C==="mapping-logs"&&e.jsxs("div",{className:"space-y-[16px]",children:[e.jsx("div",{className:"shrink-0 mb-2",children:e.jsxs("button",{onClick:()=>S("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(Sa,{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((f,T)=>e.jsxs("div",{className:"flex justify-between p-3 border rounded bg-slate-50",children:[e.jsx("span",{className:"font-semibold text-sm",children:f.columnName}),e.jsx("span",{className:"text-sm text-indigo-600",children:f.mappedField||"Unmapped"})]},T))}):e.jsx("p",{className:"text-slate-500 text-sm",children:"No recent mapping logs to display."})})]})]}),C==="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:()=>S("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(Sa,{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:()=>S("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:X,disabled:De,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:De?"Saving...":e.jsxs(e.Fragment,{children:[e.jsx(Po,{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(Us,{className:"w-4 h-4"})," Click on any field to edit"]}),e.jsxs("span",{children:["Showing ",Y.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:Y.map((f,T)=>{const E=fa(f),W=f.name.split(" "),V=W.length>1?`${W[0][0]}${W[W.length-1][0]}`.toUpperCase():f.name.substring(0,2).toUpperCase(),se=["bg-[#be185d]","bg-[#3b82f6]","bg-[#f43f5e]","bg-[#2563eb]","bg-[#059669]","bg-[#d946ef]"],ae=se[T%se.length],z=(f.avgScore??0)>=75?"text-emerald-500":(f.avgScore??0)>=60?"text-orange-500":"text-rose-500";let oe="bg-slate-50 text-slate-600 border-slate-200";const ue=(f.riskLevel||"").toLowerCase();return ue==="low"?oe="bg-emerald-50 text-emerald-600 border-emerald-200":ue==="high"?oe="bg-rose-50 text-rose-600 border-rose-200":ue==="medium"&&(oe="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 ${ae} text-white flex items-center justify-center font-bold text-[12px] shrink-0`,children:V}),e.jsx("span",{className:"font-semibold text-slate-800 text-[14px] truncate",children:f.name})]}),e.jsx("div",{className:"w-[100px] shrink-0 px-4 flex justify-center text-[13px] text-slate-500",children:f.lrn||"—"}),e.jsx("div",{className:"w-[140px] shrink-0 px-4 flex justify-center",children:e.jsx("input",{type:"text",value:Ge[E]?.grade||f.grade||"",onChange:ve=>O(K=>({...K,[E]:{...K[E],grade:ve.target.value}})),className:"bg-slate-100 focus:bg-white outline-none px-4 py-1.5 rounded-full text-[13px] font-medium text-slate-600 w-full transition-all border border-transparent focus:border-purple-500 focus:ring-2 focus:ring-purple-500/20 text-center"})}),e.jsx("div",{className:"w-[140px] shrink-0 px-4 flex justify-center",children:e.jsx("input",{type:"text",value:Ge[E]?.section||f.section||"",onChange:ve=>O(K=>({...K,[E]:{...K[E],section:ve.target.value}})),className:"bg-slate-100 focus:bg-white outline-none px-4 py-1.5 rounded-full text-[13px] font-medium text-slate-600 w-full transition-all border border-transparent focus:border-purple-500 focus:ring-2 focus:ring-purple-500/20 text-center"})}),e.jsx("div",{className:"w-[100px] shrink-0 px-4 flex justify-center",children:e.jsxs("span",{className:`${z} font-bold text-[14px]`,children:[f.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 ${oe}`,children:f.riskLevel||"Unknown"})}),e.jsx("div",{className:"flex-1 min-w-[180px] px-4 flex justify-center text-[13px] text-slate-600 truncate",children:f.weakestTopic||"Foundational Skills"}),e.jsx("div",{className:"w-[80px] shrink-0 px-4 flex justify-center border-r border-transparent",children:e.jsx("button",{className:"w-8 h-8 rounded-full hover:bg-slate-200 flex items-center justify-center transition-colors",children:e.jsx(Qo,{className:"w-4 h-4 text-slate-400"})})})]},E)})})]})})]})]})]})})}function Qm(t){const s=t.atRiskCount>=5?"high":t.atRiskCount>=2?"medium":"low",a=mt({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 Vm(t,s){const a=t.riskLevel.toLowerCase(),r=t.lastActive?Oi(t.lastActive.toDate()):"Unknown",n=t.className||s||"Imported Class",o=Pt(n),i=t.grade||o.grade,l=t.section||o.section,c=mt({metadata:t.classMetadata,classSectionId:t.classSectionId||t.classroomId,className:[i,l].filter(Boolean).join(" - ")||n,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,weakestTopic:t.weakestTopic||"N/A",classroomId:t.classroomId||c.classSectionId||n,className:c.className||[i,l].filter(Boolean).join(" - ")||n,grade:i,gradeLevel:c.gradeLevel||ws(i)||void 0,classification:c.classification||As(c.gradeLevel||i)||void 0,strand:c.strand||Ds(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}}function Um(t){const s=t.atRiskCount>=5?"high":t.atRiskCount>=2?"medium":"low",a=mt({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 Wm(t){const s=(t.riskLevel||"Low").toLowerCase(),a=mt({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||Pt(r).grade,gradeLevel:a.gradeLevel||ws(a.grade||Pt(r).grade)||void 0,classification:a.classification||As(a.gradeLevel||a.grade)||void 0,strand:a.strand||Ds(r,a.section||t.section)||void 0,section:a.section||Pt(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 qm(t,s,a){return t<60||s<75||a<55?"high":t<75||s<85||a<70?"medium":"low"}function Ym(t,s,a,r){const n=mt({metadata:r,classSectionId:s,className:a}),o=n.className||"Imported Class",i=n.classSectionId||"imported_class",l=Number(t.avgQuizScore||0),c=Number(t.attendance||0),d=Number(t.engagementScore||0),x=Number(t.assignmentCompletion||0),b=t.unknownFields?.weakestTopic||t.unknownFields?.topic||"Foundational Skills",p=qm(l,c,d),g=t.studentId||t.lrn||t.email||t.name||Math.random().toString(36).slice(2);return{id:`upload-${i}-${g}`,lrn:t.lrn,name:t.name,avatar:`https://ui-avatars.com/api/?name=${encodeURIComponent(t.name)}&background=random`,avgScore:l,riskLevel:p,weakestTopic:b,classroomId:i,className:o,grade:n.grade||Pt(o).grade,gradeLevel:n.gradeLevel||ws(n.grade||Pt(o).grade)||void 0,classification:n.classification||As(n.gradeLevel||n.grade)||void 0,strand:n.strand||Ds(o,n.section)||void 0,section:n.section||Pt(o).section,classSectionId:i,classMetadata:n,managerId:n.managerId||void 0,managerName:n.managerName||void 0,lastActive:"Recently imported",struggles:[b],engagementScore:d,attendance:c,assignmentCompletion:x}}function Oi(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 n=Math.floor(r/24);return`${n} day${n>1?"s":""} ago`}function it(t){return(t||"").trim().toLowerCase()}function yo(t){const s=it(t.classSectionId);if(s)return`section:${s}`;const a=(t.id||"").trim().toLowerCase();return a?`id:${a}`:`name:${(t.name||"").trim().toLowerCase()}`}function So(t,s){const a=new Map;return t.forEach(r=>{a.set(yo(r),r)}),s.forEach(r=>{const n=yo(r),o=a.get(n);if(!o){a.set(n,r);return}const i=Math.max(o.atRiskCount||0,r.atRiskCount||0),l=Math.max(o.studentCount||0,r.studentCount||0),c=r.avgScore>0?r.avgScore:o.avgScore,d=i>=5?"high":i>=2?"medium":"low",x=mt({metadata:o.classMetadata,classSectionId:o.classSectionId||r.classSectionId,className:o.name||r.name,grade:o.classMetadata?.grade||r.classMetadata?.grade,gradeLevel:o.classMetadata?.gradeLevel||r.classMetadata?.gradeLevel,classification:o.classMetadata?.classification||r.classMetadata?.classification,strand:o.classMetadata?.strand||r.classMetadata?.strand,section:o.classMetadata?.section||r.classMetadata?.section,schoolYear:o.classMetadata?.schoolYear||r.classMetadata?.schoolYear,ownerTeacherId:o.classMetadata?.ownerTeacherId||r.classMetadata?.ownerTeacherId,ownerTeacherName:o.classMetadata?.ownerTeacherName||r.classMetadata?.ownerTeacherName,adviserTeacherId:o.classMetadata?.adviserTeacherId||r.classMetadata?.adviserTeacherId,adviserTeacherName:o.classMetadata?.adviserTeacherName||r.classMetadata?.adviserTeacherName,managerId:o.classMetadata?.managerId||r.classMetadata?.managerId,managerName:o.classMetadata?.managerName||r.classMetadata?.managerName});a.set(n,{...o,classSectionId:x.classSectionId||o.classSectionId||r.classSectionId,name:x.className||o.name||r.name,classMetadata:x,gradeLevel:x.gradeLevel||void 0,classification:x.classification||void 0,strand:x.strand||void 0,managerId:x.managerId||void 0,managerName:x.managerName||void 0,schedule:o.schedule||r.schedule,studentCount:l,atRiskCount:i,avgScore:c,riskLevel:d})}),Array.from(a.values())}function ko(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=it(t.classSectionId)||it(t.classroomId),n=(t.id||"").trim().toLowerCase();return r&&n?`${r}|id:${n}`:`${r}|anonymous`}function fr(t){const s=it(t.classSectionId)||it(t.classroomId),a=(t.lrn||"").trim().toLowerCase(),r=(t.id||"").trim().toLowerCase(),n=t.name.trim().toLowerCase().replace(/\s+/g,"_");return s&&a?`${s}|lrn:${a}`:s&&r?`${s}|id:${r}`:a?`lrn:${a}`:r&&n?`id:${r}|name:${n}`:r?`id:${r}`:s&&n?`${s}|name:${n}`:`name:${n||"unknown"}`}function Co(t,s){const a=new Map;return t.forEach(r=>{a.set(ko(r),r)}),s.forEach(r=>{const n=ko(r),o=a.get(n);if(!o){a.set(n,r);return}const i=[o.riskLevel,r.riskLevel].includes("high")?"high":[o.riskLevel,r.riskLevel].includes("medium")?"medium":"low",l=mt({metadata:o.classMetadata,classSectionId:o.classSectionId||r.classSectionId,className:o.className||r.className,grade:o.grade||r.grade,gradeLevel:o.gradeLevel||r.gradeLevel,classification:o.classification||r.classification,strand:o.strand||r.strand,section:o.section||r.section,managerId:o.managerId||r.managerId,managerName:o.managerName||r.managerName});a.set(n,{...o,lrn:o.lrn||r.lrn,classSectionId:l.classSectionId||o.classSectionId||r.classSectionId,classroomId:o.classroomId||r.classroomId,className:l.className||o.className||r.className,grade:l.grade||o.grade||r.grade,gradeLevel:l.gradeLevel||o.gradeLevel||r.gradeLevel,classification:l.classification||o.classification||r.classification,strand:l.strand||o.strand||r.strand,section:l.section||o.section||r.section,managerId:l.managerId||o.managerId||r.managerId,managerName:l.managerName||o.managerName||r.managerName,classMetadata:l,avgScore:r.avgScore>0?r.avgScore:o.avgScore,attendance:r.attendance>0?r.attendance:o.attendance,engagementScore:r.engagementScore>0?r.engagementScore:o.engagementScore,assignmentCompletion:r.assignmentCompletion>0?r.assignmentCompletion:o.assignmentCompletion,weakestTopic:o.weakestTopic&&o.weakestTopic!=="N/A"?o.weakestTopic:r.weakestTopic,riskLevel:i,struggles:o.struggles.length>0?o.struggles:r.struggles})}),Array.from(a.values())}const Jx=({onLogout:t,onOpenProfile:s,onOpenSettings:a})=>{const{currentUser:r,userProfile:n}=gs(),[o,i]=h.useState("dashboard"),[l,c]=h.useState(!1),[d,x]=h.useState(!1),[b,p]=h.useState(!1),[g,C]=h.useState(!1),[S,N]=h.useState(!1),[m,w]=h.useState(null),[y,R]=h.useState(null),[j,H]=h.useState(!1),[v,k]=h.useState(!1),[I,$]=h.useState(!1),[D,q]=h.useState([]),[Q,A]=h.useState([]),[U,ee]=h.useState([]),[ie,je]=h.useState(""),[ge,Ce]=h.useState(!0),[de,B]=h.useState(!1),[Y,ne]=h.useState(0),[De,Le]=h.useState([]),[Ge,O]=h.useState(!1),X=h.useRef(new Map);h.useEffect(()=>{if(!r)return;const F=r.uid;let Z=!0,Re;return(async()=>{Ce(!0);try{const M=await Ti(F);let te=M.map(Qm);const _e=await iu(F).catch(()=>[]),Fe=new Map;_e.forEach(J=>{const xe=it(J.classSectionId);xe&&Fe.set(xe,J)}),te=te.map(J=>{const xe=Fe.get(it(J.classSectionId));if(!xe)return J;const Ue=mt({metadata:J.classMetadata,classSectionId:xe.classSectionId||J.classSectionId,className:xe.className||J.name,grade:xe.grade||J.classMetadata?.grade,gradeLevel:xe.gradeLevel||J.classMetadata?.gradeLevel,classification:xe.classification||J.classMetadata?.classification,strand:xe.strand||J.classMetadata?.strand,section:xe.section||J.classMetadata?.section,schoolYear:xe.schoolYear||J.classMetadata?.schoolYear,ownerTeacherId:xe.ownerTeacherId||J.classMetadata?.ownerTeacherId,ownerTeacherName:xe.ownerTeacherName||J.classMetadata?.ownerTeacherName,managerId:xe.managerId||J.classMetadata?.managerId,managerName:xe.managerName||J.classMetadata?.managerName});return{...J,name:Ue.className||J.name,classSectionId:Ue.classSectionId||J.classSectionId,classMetadata:Ue,gradeLevel:Ue.gradeLevel||J.gradeLevel,classification:Ue.classification||J.classification,strand:Ue.strand||J.strand,managerId:Ue.managerId||J.managerId,managerName:Ue.managerName||J.managerName}});const be=new Map,ot=new Map;M.forEach(J=>{const xe=mt({metadata:J.classMetadata,classSectionId:J.classSectionId,className:J.name,grade:J.grade,gradeLevel:J.gradeLevel,classification:J.classification,strand:J.strand,section:J.section,schoolYear:J.schoolYear,ownerTeacherId:J.ownerTeacherId||J.teacherId,ownerTeacherName:J.ownerTeacherName,adviserTeacherId:J.adviserTeacherId||J.teacherId,adviserTeacherName:J.adviserTeacherName,managerId:J.managerId,managerName:J.managerName});be.set(J.id,xe.className||J.name),ot.set(J.id,xe);const Ue=it(J.classSectionId);if(Ue){const Ee=Fe.get(Ue),lt=mt({metadata:xe,classSectionId:Ee?.classSectionId||Ue,className:Ee?.className||xe.className,grade:Ee?.grade||xe.grade,gradeLevel:Ee?.gradeLevel||xe.gradeLevel,classification:Ee?.classification||xe.classification,strand:Ee?.strand||xe.strand,section:Ee?.section||xe.section,schoolYear:Ee?.schoolYear||xe.schoolYear,ownerTeacherId:Ee?.ownerTeacherId||xe.ownerTeacherId,ownerTeacherName:Ee?.ownerTeacherName||xe.ownerTeacherName,managerId:Ee?.managerId||xe.managerId,managerName:Ee?.managerName||xe.managerName});be.set(Ue,lt.className||J.name),ot.set(Ue,lt)}});const Dt=(await Rr(F)).map(J=>{const xe=it(J.classSectionId||J.classroomId),Ue=be.get(J.classroomId)||(xe?be.get(xe):void 0)||J.className||"Unknown",Ee=Vm(J,Ue);if(!xe)return Ee;const lt=ot.get(xe);if(!lt)return Ee;const wt=mt({metadata:lt,classSectionId:Ee.classSectionId||lt.classSectionId,className:Ee.className||lt.className,grade:Ee.grade||lt.grade,gradeLevel:Ee.gradeLevel||lt.gradeLevel,classification:Ee.classification||lt.classification,strand:Ee.strand||lt.strand,section:Ee.section||lt.section,managerId:Ee.managerId||lt.managerId,managerName:Ee.managerName||lt.managerName});return{...Ee,className:wt.className||Ee.className,grade:wt.grade||Ee.grade,gradeLevel:wt.gradeLevel||Ee.gradeLevel,classification:wt.classification||Ee.classification,strand:wt.strand||Ee.strand,section:wt.section||Ee.section,classSectionId:wt.classSectionId||Ee.classSectionId,classMetadata:wt,managerId:wt.managerId||Ee.managerId,managerName:wt.managerName||Ee.managerName}});if(!Z)return;q(J=>te.length===0&&J.length>0?J:te),A(J=>Dt.length===0&&J.length>0?J:Dt),Ze.getImportedClassOverview({limit:3e3,forceRefresh:Y>0}).then(J=>{Z&&(J.warnings.length>0&&console.warn("Imported class overview warnings:",J.warnings.join(" ")),q(xe=>So(xe,J.classrooms.map(Um))),A(xe=>Co(xe,J.students.map(Wm))))}).catch(J=>{console.warn("Imported class overview merge unavailable:",J)});const Ns=M.map(J=>J.id);Ns.length>0&&(Re=cu(Ns,J=>{Z&&ee(J.map(xe=>({id:xe.id,student:xe.studentName,action:xe.action,topic:xe.topic,time:Oi(xe.timestamp.toDate()),type:xe.type})))}))}catch(M){console.error("Failed to load teacher data:",M),me.error("Failed to load dashboard data")}finally{Ce(!1)}})(),()=>{Z=!1,Re&&Re()}},[r,Y]),h.useEffect(()=>{if(!r)return;let F=!0;return lu("",80).then(Z=>{F&&Le(Z)}).catch(Z=>{console.warn("Failed to load teacher directory options:",Z)}),()=>{F=!1}},[r]),h.useEffect(()=>{if(Q.length===0)return;(async()=>{B(!0);try{const Z=Q.map(Ne=>({name:Ne.name,engagementScore:Ne.engagementScore,avgQuizScore:Ne.avgScore,attendance:Ne.attendance,riskLevel:Ne.riskLevel})),Re=await Ze.getDailyInsight({students:Z});je(Re.insight)}catch{je(`${Q.filter(Z=>Z.riskLevel==="high").length} students are at high risk of falling behind. Review their progress in the analytics view.`)}finally{B(!1)}})()},[Q]);const f=D.reduce((F,Z)=>F+Z.studentCount,0),T=D.reduce((F,Z)=>F+Z.atRiskCount,0),E=D.length>0?Math.round(D.reduce((F,Z)=>F+Z.avgScore,0)/D.length):0,W=[{name:"High Risk",value:Q.filter(F=>F.riskLevel==="high").length,color:"#FF8B8B"},{name:"Medium Risk",value:Q.filter(F=>F.riskLevel==="medium").length,color:"#F08386"},{name:"Low Risk",value:Q.filter(F=>F.riskLevel==="low").length,color:"#75D06A"}],V={};Q.forEach(F=>{F.weakestTopic&&F.weakestTopic!=="N/A"&&(V[F.weakestTopic]||(V[F.weakestTopic]={total:0,sum:0}),V[F.weakestTopic].total+=1,V[F.weakestTopic].sum+=F.avgScore)});const se=Object.entries(V).map(([F,Z])=>({topic:F,score:Math.round(Z.sum/Z.total)})).sort((F,Z)=>F.score-Z.score).slice(0,6),ae=F=>{w(F),i("analytics")},z=F=>{R(F),i("intervention")},oe=()=>{R(null),i("analytics")},ue=()=>{w(null),R(null),i("dashboard")},ve=async(F,Z)=>{if(!r){me.error("Unable to assign manager: teacher context is missing.");return}const Re=Pt(F.classMetadata?.className||F.name),Ne=mt({metadata:F.classMetadata,classSectionId:F.classSectionId,className:F.name,grade:F.classMetadata?.grade||Re.grade,gradeLevel:F.classMetadata?.gradeLevel,classification:F.classMetadata?.classification,strand:F.classMetadata?.strand,section:F.classMetadata?.section||Re.section,schoolYear:F.classMetadata?.schoolYear||String(new Date().getFullYear()),ownerTeacherId:F.classMetadata?.ownerTeacherId||r.uid,ownerTeacherName:F.classMetadata?.ownerTeacherName||we,adviserTeacherId:F.classMetadata?.adviserTeacherId||r.uid,adviserTeacherName:F.classMetadata?.adviserTeacherName||we,managerId:Z.uid,managerName:Z.name}),M=Ne.classSectionId||zt(Ne.grade||Re.grade,Ne.section||Re.section);if(!M){me.error("Unable to assign manager: missing class section ID.");return}O(!0);try{await ou({classSectionId:M,className:Ne.className||F.name,grade:Ne.grade||Re.grade,gradeLevel:Ne.gradeLevel||ws(Ne.grade||Re.grade)||Ne.grade||Re.grade,classification:Ne.classification||As(Ne.gradeLevel||Ne.grade)||void 0,strand:Ne.strand||Ds(Ne.className,Ne.section)||void 0,section:Ne.section||Re.section,schoolYear:Ne.schoolYear||String(new Date().getFullYear()),ownerTeacherId:Ne.ownerTeacherId||r.uid,ownerTeacherName:Ne.ownerTeacherName||we,managerId:Z.uid,managerName:Z.name});const te=mt({metadata:Ne,classSectionId:M,managerId:Z.uid,managerName:Z.name}),_e=it(M);q(Fe=>Fe.map(be=>it(be.classSectionId)!==_e?be:{...be,name:te.className||be.name,classSectionId:te.classSectionId||be.classSectionId,classMetadata:te,gradeLevel:te.gradeLevel||be.gradeLevel,classification:te.classification||be.classification,strand:te.strand||be.strand,managerId:Z.uid,managerName:Z.name})),A(Fe=>Fe.map(be=>{if(it(be.classSectionId||be.classroomId)!==_e)return be;const gt=mt({metadata:be.classMetadata,classSectionId:te.classSectionId||be.classSectionId,className:be.className||te.className,grade:be.grade||te.grade,gradeLevel:be.gradeLevel||te.gradeLevel,classification:be.classification||te.classification,strand:be.strand||te.strand,section:be.section||te.section,managerId:Z.uid,managerName:Z.name});return{...be,classMetadata:gt,gradeLevel:gt.gradeLevel||be.gradeLevel,classification:gt.classification||be.classification,strand:gt.strand||be.strand,managerId:Z.uid,managerName:Z.name}})),w(Fe=>!Fe||it(Fe.classSectionId)!==_e?Fe:{...Fe,classMetadata:te,managerId:Z.uid,managerName:Z.name,gradeLevel:te.gradeLevel||Fe.gradeLevel,classification:te.classification||Fe.classification,strand:te.strand||Fe.strand}),me.success(`Assigned ${Z.name} as section manager.`)}catch(te){console.error("Failed to assign class manager:",te),me.error(te instanceof Error?te.message:"Failed to assign class manager")}finally{O(!1)}};h.useEffect(()=>{const F=()=>{const Z=window.innerWidth<1024;C(Z),Z?c(!1):p(!1)};return F(),window.addEventListener("resize",F),()=>window.removeEventListener("resize",F)},[]),h.useEffect(()=>{g&&p(!1)},[o,g]);const K=F=>{i(F),w(null),R(null)},we=n?.name||"Teacher",We=h.useMemo(()=>{if(!m)return;if(m.classMetadata?.classSectionId)return m.classMetadata.classSectionId||void 0;if(m.classSectionId)return m.classSectionId;const F=Pt(m.classMetadata?.className||m.name);return zt(F.grade,F.section)||void 0},[m]),Se=h.useMemo(()=>m||null,[m]),Je=h.useMemo(()=>{if(!Se)return;const F=D.findIndex(Z=>Z.id===Se.id);return Ea[Math.max(0,F)%Ea.length]},[Se,D]),et=h.useMemo(()=>{if(!Se)return Q;const F=(Se.id||"").trim().toLowerCase(),Z=it(Se.classSectionId),Re=(Se.name||"").trim().toLowerCase();return Q.filter(Ne=>{const M=it(Ne.classroomId),te=it(Ne.classSectionId),_e=(Ne.className||"").trim().toLowerCase();return Z&&(te===Z||M===Z)||F&&(M===F||te===F)||Re&&_e===Re})},[Se,Q]);return ge?e.jsxs("div",{className:"flex h-screen w-full bg-background p-6",children:[e.jsx("div",{className:"hidden lg:flex w-[280px] shrink-0 rounded-3xl border border-border bg-card p-5",children:e.jsxs("div",{className:"w-full space-y-4",children:[e.jsx(Me,{className:"h-12 w-40"}),e.jsx(Me,{className:"h-10 w-full"}),e.jsx(Me,{className:"h-10 w-full"}),e.jsx(Me,{className:"h-10 w-full"}),e.jsx(Me,{className:"h-10 w-full"})]})}),e.jsxs("div",{className:"flex-1 space-y-4 lg:pl-6",children:[e.jsx(Me,{className:"h-20 w-full rounded-2xl"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[e.jsx(Me,{className:"h-28 w-full rounded-2xl"}),e.jsx(Me,{className:"h-28 w-full rounded-2xl"}),e.jsx(Me,{className:"h-28 w-full rounded-2xl"})]}),e.jsx(Me,{className:"h-[420px] w-full rounded-2xl"})]})]}):e.jsxs("div",{className:"relative flex h-screen w-full bg-background overflow-hidden",children:[g&&b&&e.jsx("button",{"aria-label":"Close navigation",className:"fixed inset-0 z-30 bg-slate-900/40 backdrop-blur-[1px]",onClick:()=>p(!1)}),e.jsxs(Pe.aside,{initial:!1,animate:{width:g?280:l&&!d?80:280,x:g?b?0:-300:0},transition:{type:"spring",stiffness:360,damping:34},onMouseEnter:()=>!g&&l&&x(!0),onMouseLeave:()=>x(!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"})})]}),!g&&(!l||d)&&e.jsx(Pe.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(es,{size:20}):e.jsx(as,{size:20})}),g&&e.jsx("button",{onClick:()=>p(!1),className:"p-2 hover:bg-[#dde3eb] rounded-lg transition-colors text-[#5a6578]","aria-label":"Close navigation",children:e.jsx(ps,{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(Jt,{icon:jl,label:"Dashboard",active:o==="dashboard",collapsed:l&&!d,onClick:ue,forceExpanded:g}),e.jsx(Jt,{icon:hs,label:"Class Analytics",active:o==="analytics",collapsed:l&&!d,onClick:()=>K("analytics"),forceExpanded:g})]})]}),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(Jt,{icon:Yt,label:"Topic Mastery",active:o==="topic_mastery",collapsed:l&&!d,onClick:()=>K("topic_mastery"),forceExpanded:g}),e.jsx(Jt,{icon:Rt,label:"Competency",active:o==="competency",collapsed:l&&!d,onClick:()=>K("competency"),forceExpanded:g})]})]}),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(Jt,{icon:Fl,label:"Data Import",active:o==="import",collapsed:l&&!d,onClick:()=>i("import"),forceExpanded:g}),e.jsx(Jt,{icon:Ho,label:"AI Quiz Maker",active:o==="quiz_maker",collapsed:l&&!d,onClick:()=>i("quiz_maker"),forceExpanded:g}),e.jsx(Jt,{icon:Lt,label:"Question Bank",active:o==="question_bank",collapsed:l&&!d,onClick:()=>i("question_bank"),forceExpanded:g}),e.jsx(Jt,{icon:Mo,label:"Calendar",active:o==="calendar",collapsed:l&&!d,onClick:()=>i("calendar"),forceExpanded:g})]})]})]}),e.jsxs("div",{className:"space-y-2 border-t border-[#dde3eb] pt-4",children:[e.jsxs(Pe.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(yl,{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(Sl,{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(o)&&e.jsx("header",{className:"bg-transparent border-b border-[#e2e8f0]/40 px-[24px] xl:px-[32px] pt-[24px] pb-[16px] flex-shrink-0 z-30",children:e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-start justify-between gap-4 mb-0",children:[e.jsxs("div",{className:"flex-1 flex items-start gap-3",children:[g&&e.jsx("button",{onClick:()=>p(!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(hl,{size:18})}),e.jsxs("div",{children:[e.jsxs("h1",{className:"text-[26px] font-bold text-[#1e293b] tracking-tight leading-tight",children:[o==="dashboard"&&"Teacher Dashboard",o==="analytics"&&"Class Analytics",o==="intervention"&&"Intervention Center",o==="competency"&&"Student Competency",o==="topic_mastery"&&"Topic Mastery",o==="calendar"&&"Academic Calendar",o==="notifications"&&"Notifications",o==="question_bank"&&"Question Bank",o==="import"&&"Data Import",o==="quiz_maker"&&"AI Quiz Maker"]}),e.jsxs("p",{className:"text-[13px] text-[#64748b] mt-1",children:[o==="dashboard"&&`Welcome back, ${we}`,o==="analytics"&&"Analyze performance and risk across your classes.",o==="intervention"&&"Identify and support students who need immediate help.",o==="competency"&&"Track individual student progress against learning goals.",o==="topic_mastery"&&"Overview of student mastery levels across different math topics.",o==="calendar"&&"Manage your schedules and academic events.",o==="notifications"&&"Stay updated with student activity and system alerts.",o==="question_bank"&&"Manage and create math questions for your quizzes.",o==="import"&&"Upload class records and materials to power AI analytics.",o==="quiz_maker"&&"Create AI-powered quizzes based on your curriculum."]})]}),o==="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(Rt,{size:13,className:"text-[#9956DE]"}),e.jsxs("span",{className:"text-xs font-display font-semibold text-[#9956DE]",children:[f," 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(_s,{size:13,className:"text-[#F08386]"}),e.jsxs("span",{className:"text-xs font-display font-semibold text-[#C65E63]",children:[T," 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(sa,{size:13,className:"text-[#75D06A]"}),e.jsxs("span",{className:"text-xs font-display font-semibold text-[#4D9F46]",children:[E,"% avg"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-3 shrink-0 self-end sm:self-auto",children:[e.jsxs("div",{className:"relative group",children:[e.jsxs("button",{onClick:()=>{k(!0),H(!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(ss,{size:18}),!j&&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"})]}),e.jsxs("div",{className:"relative",children:[e.jsxs("button",{onClick:()=>$(!I),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(Rs,{size:18}),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(au,{isOpen:I,onClose:()=>$(!1),onViewAll:()=>i("notifications")})]}),o!=="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:n?.photo||`https://ui-avatars.com/api/?name=${encodeURIComponent(we)}&background=e0e7ff&color=4f46e5`,alt:"Profile",className:"w-full h-full object-cover"})}),e.jsx("span",{className:"text-[13px] font-semibold text-[#1e293b]",children:we})]})]})]})}),e.jsx("main",{className:`flex-1 flex flex-col ${o==="intervention"||o==="analytics"?"overflow-hidden":"overflow-y-auto"}`,children:e.jsxs(Bt,{mode:"wait",children:[o==="dashboard"&&e.jsx(Km,{classes:D,liveActivity:U,onViewClass:ae,onViewAllClasses:()=>i("analytics"),onViewActivityStudent:F=>{const Z=Q.find(Re=>Re.name===F);Z&&z(Z)},dailyInsight:ie,insightLoading:de,isInsightDismissed:j,onDismissInsight:()=>H(!0),onOpenInsightModal:()=>{k(!0),H(!0)},totalStudents:f,totalAtRisk:T,avgPerformance:E}),o==="analytics"&&Se&&e.jsx(Jm,{selectedClass:Se,students:et,riskDistribution:W,topicPerformance:se,onViewStudent:z,onBack:()=>w(null),teacherOptions:De,managerUpdating:Ge,onAssignManager:F=>ve(Se,F),onOpenNotifications:()=>i("notifications"),onOpenProfile:s,classColor:Je,insightDismissed:j,onOpenInsightModal:()=>k(!0)}),o==="analytics"&&!Se&&D.length>0&&e.jsx(xo,{classes:D,onSelectClass:ae,onOpenNotifications:()=>i("notifications"),onOpenProfile:s,insightDismissed:j,onOpenInsightModal:()=>k(!0)}),o==="analytics"&&!Se&&D.length===0&&e.jsx(To,{icon:hs,title:"Class Analytics",description:"No classes available yet. Import class records to unlock analytics views."}),o==="intervention"&&y&&e.jsx(Zm,{student:y,teacherId:r?.uid||"",teacherName:we,initialCache:X.current.get(y.id),onCacheUpdate:(F,Z)=>X.current.set(F,Z),onStudentUpdated:F=>{const Z=y?fr(y):null;R(F),A(Re=>Re.map(Ne=>{const M=fr(Ne),te=Z?M===Z:!1,_e=Ne.id===F.id&&it(Ne.classSectionId)===it(F.classSectionId);return te||_e?F:Ne}))},onBack:oe,onNavigateToQuizMaker:F=>{i("quiz_maker"),F&&sessionStorage.setItem("quizMakerInitialTab",F)}}),o==="topic_mastery"&&e.jsx(ku,{classSectionId:We,onOpenNotifications:()=>i("notifications"),onOpenProfile:s}),o==="competency"&&Se&&e.jsx(Eu,{classSectionId:We,className:m?.name,fallbackStudents:Q,onBack:()=>w(null),onOpenNotifications:()=>i("notifications"),onOpenProfile:s,insightDismissed:j,onOpenInsightModal:()=>k(!0)}),o==="competency"&&!Se&&D.length>0&&e.jsx(xo,{classes:D,onSelectClass:F=>w(F),onOpenNotifications:()=>i("notifications"),onOpenProfile:s,insightDismissed:j,onOpenInsightModal:()=>k(!0),viewType:"competency"}),o==="competency"&&!Se&&D.length===0&&e.jsx(To,{icon:Rt,title:"Student Competency",description:"No classes available yet. Import class records to view competency breakdowns."}),o==="import"&&e.jsx(Gm,{classSectionId:We,className:m?.name,classMetadata:m?.classMetadata,students:Q,teacherId:r?.uid||"",teacherName:we,onStudentsUpdated:F=>A(F),onBackToClasses:()=>i("dashboard"),onOpenNotifications:()=>i("notifications"),onOpenProfile:s,onOpenInsightModal:()=>{k(!0),H(!0)},userPhoto:n?.photo,onImportedClassRecords:F=>{const Z=F.students.map(be=>Ym(be,F.classSectionId,F.className,F.classMetadata)),Re=mt({metadata:F.classMetadata,classSectionId:F.classSectionId,className:F.className}),Ne=Re.classSectionId||"imported_class",M=Re.className||"Imported Class",te=Z.filter(be=>be.riskLevel==="high").length,_e=Z.length>0?Math.round(Z.reduce((be,ot)=>be+ot.avgScore,0)/Z.length):0,Fe={id:Ne,name:M,classSectionId:Ne,classMetadata:{...Re,classSectionId:Ne,className:M},schedule:"Mon-Fri",studentCount:Z.length,avgScore:_e,atRiskCount:te,riskLevel:te>=5?"high":te>=2?"medium":"low"};A(be=>Co(be,Z)),q(be=>So(be,[Fe]))},onDataChanged:()=>ne(F=>F+1)}),o==="notifications"&&e.jsx(Ru,{liveActivity:U,atRiskStudents:Q.filter(F=>F.riskLevel==="high").map(F=>({name:F.name,riskLevel:F.riskLevel,weakestTopic:F.weakestTopic})),onOpenNotifications:()=>i("notifications"),onOpenProfile:s,onOpenInsightModal:()=>{k(!0),H(!0)},userPhoto:n?.photo,teacherName:we}),o==="calendar"&&e.jsx(Uu,{classes:D,teacherId:r?.uid}),o==="quiz_maker"&&e.jsx(_i,{onBack:()=>{const F=sessionStorage.getItem("quizMakerReturnTo");sessionStorage.removeItem("quizMakerReturnTo"),sessionStorage.removeItem("quizMakerInitialTab"),i(F==="intervention"?"intervention":"dashboard")},onOpenNotifications:()=>i("notifications"),onOpenProfile:s,onOpenInsightModal:()=>{k(!0),H(!0)},userPhoto:n?.photo,teacherName:we}),o==="question_bank"&&e.jsx(yu,{onOpenNotifications:()=>i("notifications"),onOpenProfile:s,onOpenInsightModal:()=>{k(!0),H(!0)},userPhoto:n?.photo,teacherName:we})]})})]}),o==="dashboard"&&e.jsx(ex,{onViewCalendar:()=>i("calendar"),onOpenProfile:s,userProfile:n,teacherName:we})]}),e.jsx(Bt,{children:v&&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(Pe.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(ss,{size:16})}),e.jsx("h3",{className:"font-semibold text-slate-800",children:"Detailed AI Insight"})]}),e.jsx("button",{onClick:()=>{k(!1)},className:"p-2 text-slate-400 hover:text-slate-600 hover:bg-slate-100 rounded-full transition-colors",children:e.jsx(ps,{size:18})})]}),e.jsx("div",{className:"p-6",children:e.jsx(va,{name:"teacher-dashboard-ai-insight-modal",loading:de,fixture:e.jsx(Me,{className:"h-32 w-full bg-slate-200"}),fallback:e.jsx(Me,{className:"h-32 w-full bg-slate-200"}),children:e.jsx("div",{className:"text-sm text-slate-600 leading-relaxed",children:e.jsx(Vl,{children:ie?.replace(/[*_]*\s*\(?Word\s*count\s*:\s*[*_]*\s*\d+\)?\s*[*_]*/gi,"").trim()||`I've noticed **${T} students (${f>0?Math.round(T/f*100):0}%)** are currently showing a high risk of falling behind in recent topics. Shall I draft an intervention plan?`})})})}),e.jsx("div",{className:"p-4 border-t border-slate-100 bg-slate-50 flex justify-end gap-2",children:e.jsx("button",{onClick:()=>{k(!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(il,{isOpen:S,onClose:()=>N(!1),onConfirm:t,title:"Logout",message:"Are you sure you want to logout?",confirmText:"Logout",cancelText:"Cancel"})]})},Jt=({icon:t,label:s,active:a,collapsed:r,forceExpanded:n=!1,onClick:o})=>e.jsxs(Pe.button,{onClick:o,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&&!n?"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||n)&&e.jsx("span",{className:"font-body font-semibold text-xs",children:s}),a&&!r&&e.jsx(Pe.div,{layoutId:"sidebar-active-indicator",className:"ml-auto w-2 h-2 rounded-full bg-[#9956DE]",transition:{type:"spring",duration:.4}})]}),To=({icon:t,title:s,description:a})=>e.jsx(Pe.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})]})}),Km=({classes:t,liveActivity:s,onViewClass:a,onViewAllClasses:r,onViewActivityStudent:n,dailyInsight:o,insightLoading:i,isInsightDismissed:l,onDismissInsight:c,onOpenInsightModal:d,totalStudents:x,totalAtRisk:b,avgPerformance:p})=>{const g=x>0?Math.round(b/x*100):0,C=x>0?Math.round((x-b)/x*100):0;return e.jsxs(Pe.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},exit:{opacity:0,y:-20},className:"p-6 space-y-4",children:[!l&&e.jsxs("div",{onClick:d,className:"bg-white/80 backdrop-blur-[12px] rounded-[18px] border border-white p-[18px_20px] flex items-center 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 items-center gap-2 mb-1",children:[e.jsx(ss,{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:"I've noticed some students are currently showing a high risk of falling behind. Click to view detailed analysis..."})]}),e.jsxs("div",{className:"flex gap-2 flex-shrink-0",children:[e.jsx("button",{onClick:S=>{S.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:S=>{S.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-3",children:[e.jsxs("div",{className:"group relative overflow-hidden bg-[#10b981] shadow-[0_4px_16px_rgba(16,185,129,0.13)] rounded-2xl p-[15px] text-white flex flex-col 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-[11px] opacity-90",children:"Total students"}),e.jsx("div",{className:"bg-white/20 p-1.5 rounded-lg flex",children:e.jsx(Rt,{size:15})})]}),e.jsx("div",{className:"relative z-10 text-[26px] font-semibold tracking-tight",children:x}),e.jsxs("div",{className:"relative z-10 border-t border-white/30 pt-2 flex justify-between items-center text-[10px] opacity-90",children:[e.jsx("span",{children:"Added this year"}),e.jsx("span",{className:"bg-black/15 px-[7px] py-[2px] rounded font-semibold",children:x>0?"+1":"0"})]})]}),e.jsxs("div",{className:"group relative overflow-hidden bg-[#0ea5e9] shadow-[0_4px_16px_rgba(14,165,233,0.13)] rounded-2xl p-[15px] text-white flex flex-col 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-[11px] opacity-90",children:"Class average"}),e.jsx("div",{className:"bg-white/20 p-1.5 rounded-lg flex",children:e.jsx(Yt,{size:15})})]}),e.jsxs("div",{className:"relative z-10 text-[26px] font-semibold tracking-tight",children:[p,"%"]}),e.jsxs("div",{className:"relative z-10 border-t border-white/30 pt-2 flex justify-between items-center text-[10px] opacity-90",children:[e.jsx("span",{children:"Vs. last month"}),e.jsx("span",{className:"bg-black/15 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-2xl p-[15px] text-white flex flex-col 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-[11px] opacity-90",children:"Engagement rate"}),e.jsx("div",{className:"bg-white/20 p-1.5 rounded-lg flex",children:e.jsx($l,{size:15})})]}),e.jsxs("div",{className:"relative z-10 text-[26px] font-semibold tracking-tight",children:[C,"%"]}),e.jsxs("div",{className:"relative z-10 border-t border-white/30 pt-2 flex justify-between items-center text-[10px] opacity-90",children:[e.jsx("span",{children:"Active participants"}),e.jsx("span",{className:"bg-black/15 px-[7px] py-[2px] rounded font-semibold",children:Math.round(C/100*x)})]})]}),e.jsxs("div",{className:"group relative overflow-hidden bg-[#f97316] shadow-[0_4px_16px_rgba(249,115,22,0.13)] rounded-2xl p-[15px] text-white flex flex-col 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-[11px] opacity-90",children:"At risk"}),e.jsx("div",{className:"bg-white/20 p-1.5 rounded-lg flex",children:e.jsx(aa,{size:15})})]}),e.jsx("div",{className:"relative z-10 text-[26px] font-semibold tracking-tight",children:b}),e.jsxs("div",{className:"relative z-10 border-t border-white/30 pt-2 flex justify-between items-center text-[10px] opacity-90",children:[e.jsx("span",{children:"Requires attention"}),e.jsxs("span",{className:"bg-black/15 px-[7px] py-[2px] rounded font-semibold",children:[g,"%"]})]})]})]}),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.jsx("p",{className:"text-sm text-slate-500 text-center py-4",children:"No classes imported yet."}),t.map((S,N)=>{const m=[{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]"}],w=m[N%m.length];return e.jsxs("div",{onClick:()=>a(S),className:`relative overflow-hidden flex items-center gap-3 p-[12px_13px] pl-[16px] border border-[#f1f5f9] rounded-[14px] cursor-pointer ${w.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] ${w.stripe}`}),e.jsx("div",{className:`w-[38px] h-[38px] rounded-[10px] flex items-center justify-center flex-shrink-0 text-[17px] ${w.bg} ${w.text} group-hover:scale-110 transition-transform duration-300`,children:e.jsx(Lt,{size:18})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-[12.5px] font-medium text-[#1e293b]",children:S.name}),e.jsx("div",{className:"text-[11px] text-[#94a3b8] mt-[1px]",children:S.classification||"High School"})]}),e.jsx("div",{className:"text-[12px] text-[#64748b] min-w-[65px]",children:S.schedule||"Mon-Fri"}),e.jsxs("div",{className:"text-[12px] text-[#64748b] min-w-[85px]",children:[S.studentCount," students"]}),e.jsx("span",{className:`text-[10px] font-semibold px-[9px] py-[3px] rounded-[6px] ${S.riskLevel==="high"?"bg-[#fee2e2] text-[#b91c1c] border border-[#fca5a5]":S.riskLevel==="medium"?"bg-[#fffbeb] text-[#b45309] border border-[#fcd34d]":"bg-[#ecfdf5] text-[#065f46] border border-[#6ee7b7]"}`,children:S.riskLevel==="high"?"High risk":S.riskLevel==="medium"?"Medium risk":"On track"}),e.jsx(nr,{size:16,className:"text-[#cbd5e1] ml-auto hover:text-[#64748b]"})]},S.id)})]})]})]})},Xm=le.memo(({student:t,onViewStudent:s})=>{const r=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"};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] ${r.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 ${r.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 ${r.bgAvatar}`,children:t.name.substring(0,2).toUpperCase()}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-[13px] font-semibold text-[#1e293b] leading-tight truncate",children:t.name}),e.jsxs("p",{className:"text-[10px] text-[#64748b] flex items-center gap-[4px] mt-0.5 truncate",children:[e.jsx(Ms,{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 ${r.badge}`,children:[t.avgScore,"%"]})]}),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 ${r.progress}`,style:{width:`${t.avgScore}%`}})})]})}),Jm=({selectedClass:t,students:s,riskDistribution:a,topicPerformance:r,onViewStudent:n,onBack:o,teacherOptions:i,managerUpdating:l,onAssignManager:c,onOpenNotifications:d,onOpenProfile:x,classColor:b,insightDismissed:p,onOpenInsightModal:g})=>{const{currentUser:C,userProfile:S}=gs(),[N,m]=h.useState(""),[w,y]=h.useState(""),[R,j]=h.useState("All");h.useEffect(()=>{y(t.classMetadata?.managerId||t.managerId||"")},[t]);const H=h.useMemo(()=>{const A=N.trim().toLowerCase();let U=s;return A&&(U=U.filter(ee=>ee.name.toLowerCase().includes(A)||(ee.lrn||"").toLowerCase().includes(A)||(ee.weakestTopic||"").toLowerCase().includes(A))),R==="Good"?U=U.filter(ee=>ee.avgScore>=85&&ee.riskLevel!=="high"):R==="Risk"&&(U=U.filter(ee=>ee.riskLevel==="high"||ee.avgScore<75)),U},[N,s,R]),v=h.useMemo(()=>{if(s.length===0)return 0;const A=s.reduce((U,ee)=>U+(ee.assignmentCompletion||0),0);return Math.round(A/s.length)},[s]),k=h.useMemo(()=>{if(s.length===0)return 0;const A=s.reduce((ee,ie)=>ee+(ie.attendance||0),0)/s.length,U=s.reduce((ee,ie)=>ee+(ie.engagementScore||0),0)/s.length;return Math.round(A*.6+U*.4)},[s]),I=h.useMemo(()=>[...s].sort((A,U)=>U.avgScore-A.avgScore).slice(0,5),[s]),$=h.useMemo(()=>[...s].filter(A=>A.riskLevel==="high"||A.avgScore<70||A.assignmentCompletion<65),[s]),D=h.useMemo(()=>i.find(A=>A.uid===w),[i,w]),q=()=>{if(!D){me.error("Select a teacher manager first.");return}c(D)},Q=[t.classMetadata?.gradeLevel||t.gradeLevel,t.classMetadata?.classification||t.classification,t.classMetadata?.strand||t.strand].filter(Boolean);return e.jsxs(Pe.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},exit:{opacity:0,y:-20},className:"p-[24px] xl:p-[32px] space-y-[24px] h-full overflow-y-auto",children:[e.jsx("div",{className:"flex items-center justify-between mb-6",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] shadow-[0_1px_4px_rgba(0,0,0,0.04)] border border-white/50",children:[e.jsx(as,{className:"w-4 h-4"}),"Back to Classes"]})}),e.jsxs("header",{style:{backgroundColor:b?.hex||"#6366f1"},className:"rounded-[24px] 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-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-[28px] font-bold mb-3 tracking-tight",children:t.name}),e.jsx("div",{className:"flex flex-wrap items-center gap-2 mb-3",children:Q.map((A,U)=>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:A},A))}),e.jsxs("p",{className:"text-[13px] text-white/80 font-medium",children:["Manager: ",t.classMetadata?.managerName||t.managerName||"Not assigned"]})]}),e.jsxs("div",{className:"bg-white/10 border border-white/20 rounded-[18px] p-[16px] backdrop-blur-md flex flex-col w-full md:w-auto shrink-0 relative z-10 shadow-inner",children:[e.jsx("label",{className:"text-[11px] font-bold text-white/90 uppercase tracking-wider mb-2 ml-1",children:"Section Manager"}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"relative w-full md:w-[320px]",children:[e.jsxs("select",{value:w||"",onChange:A=>y(A.target.value),className:"appearance-none bg-white/20 border border-white/30 text-white text-[13px] font-bold rounded-xl pl-4 pr-10 py-2.5 outline-none focus:border-white/50 focus:ring-2 focus:ring-white/20 w-full shadow-sm cursor-pointer [&>option]:text-[#1e293b]",children:[e.jsx("option",{value:"",children:"Select teacher"}),i.map(A=>e.jsxs("option",{value:A.uid,children:[A.name," (",A.email,")"]},A.uid))]}),e.jsx(_t,{className:"w-4 h-4 text-white/70 absolute right-3 top-1/2 -translate-y-1/2 pointer-events-none"})]}),e.jsx("button",{onClick:q,disabled:!w||l,className:"bg-white text-[#6366f1] hover:bg-white/90 text-[13px] font-bold rounded-full px-6 py-2.5 shadow-md transition-transform hover:scale-[1.02] whitespace-nowrap disabled:opacity-50 disabled:hover:scale-100",style:{color:b?.hex||"#6366f1"},children:l?"Updating...":"Assign"})]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 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-2xl p-[15px] text-white flex flex-col 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-[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(Yt,{size:15})})]}),e.jsxs("div",{className:"relative z-10 text-[26px] font-semibold tracking-tight",children:[t.avgScore,"%"]})]}),e.jsxs("div",{className:"group relative overflow-hidden bg-[#10b981] shadow-[0_4px_16px_rgba(16,185,129,0.13)] rounded-2xl p-[15px] text-white flex flex-col 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-[11px] opacity-90 uppercase tracking-wider font-semibold",children:"Completion Rate"}),e.jsx("div",{className:"bg-white/20 p-1.5 rounded-lg flex",children:e.jsx(gr,{size:15})})]}),e.jsxs("div",{className:"relative z-10 text-[26px] font-semibold tracking-tight",children:[v,"%"]})]}),e.jsxs("div",{className:"group relative overflow-hidden bg-[#a855f7] shadow-[0_4px_16px_rgba(168,85,247,0.13)] rounded-2xl p-[15px] text-white flex flex-col 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-[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(Rt,{size:15})})]}),e.jsxs("div",{className:"relative z-10 text-[26px] font-semibold tracking-tight",children:[k,"%"]})]}),e.jsxs("div",{className:"group relative overflow-hidden bg-[#f97316] shadow-[0_4px_16px_rgba(249,115,22,0.13)] rounded-2xl p-[15px] text-white flex flex-col 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-[11px] opacity-90 uppercase tracking-wider font-semibold",children:"Needs Attention"}),e.jsx("div",{className:"bg-white/20 p-1.5 rounded-lg flex",children:e.jsx(_s,{size:15})})]}),e.jsxs("div",{className:"relative z-10 text-[26px] font-semibold tracking-tight",children:[$.length," ",e.jsx("span",{className:"text-[13px] opacity-90 font-medium",children:"students"})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-3 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.jsx("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:["(",H.length,")"]})]})}),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(ra,{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:N,onChange:A=>m(A.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:()=>j("All"),className:`px-3 py-1.5 text-[11px] font-semibold rounded-[14px] whitespace-nowrap transition-all hover:scale-[1.02] ${R==="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:()=>j("Good"),className:`px-3 py-1.5 text-[11px] font-semibold rounded-[14px] whitespace-nowrap transition-all hover:scale-[1.02] ${R==="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:()=>j("Risk"),className:`px-3 py-1.5 text-[11px] font-semibold rounded-[14px] whitespace-nowrap transition-all hover:scale-[1.02] ${R==="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(Ld,{style:{height:"100%"},data:H,className:"no-scrollbar",itemContent:(A,U)=>e.jsx("div",{className:"py-[6px] px-[8px]",children:e.jsx(Xm,{student:U,onViewStudent:n})}),computeItemKey:(A,U)=>fr(U)})})]}),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(nr,{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(bn,{width:"100%",height:"100%",children:e.jsxs(vn,{data:a,children:[e.jsx(wn,{strokeDasharray:"4 4",stroke:"#f1f5f9",vertical:!1}),e.jsx(Nn,{dataKey:"name",axisLine:{stroke:"#cbd5e1",strokeWidth:2},tickLine:!1,tick:{fill:"#475569",fontSize:11,fontWeight:600},dy:10}),e.jsx(jn,{axisLine:!1,tickLine:!1,tick:{fill:"#64748b",fontSize:10,fontWeight:600}}),e.jsx(yn,{cursor:{fill:"#f8fafc"},contentStyle:{borderRadius:"12px",border:"none",boxShadow:"0 4px 6px -1px rgb(0 0 0 / 0.1)"}}),e.jsx(Sn,{dataKey:"value",radius:[6,6,0,0],barSize:80,children:a.map((A,U)=>{const ee={"High Risk":"#f43f5e","Medium Risk":"#f59e0b","Low Risk":"#10b981"};return e.jsx(kn,{fill:ee[A.name]||A.color},`cell-${U}`)})})]})})})]}),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(nr,{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(bn,{width:"100%",height:"100%",children:e.jsxs(vn,{data:r,layout:"vertical",margin:{top:0,right:10,left:40,bottom:0},children:[e.jsx(wn,{strokeDasharray:"4 4",stroke:"#f1f5f9",horizontal:!1}),e.jsx(Nn,{type:"number",domain:[0,100],axisLine:!1,tickLine:!1,tick:{fill:"#64748b",fontSize:10,fontWeight:600},tickFormatter:A=>`${A}%`}),e.jsx(jn,{dataKey:"topic",type:"category",axisLine:{stroke:"#cbd5e1",strokeWidth:2},tickLine:!1,tick:{fill:"#1e293b",fontSize:11,fontWeight:600},dx:-10}),e.jsx(yn,{cursor:{fill:"#f8fafc"},contentStyle:{borderRadius:"12px",border:"none",boxShadow:"0 4px 6px -1px rgb(0 0 0 / 0.1)"}}),e.jsx(Sn,{dataKey:"score",radius:[0,6,6,0],barSize:28,children:r.map((A,U)=>{const ee=["#6366f1","#a855f7","#10b981","#f59e0b","#ec4899"];return e.jsx(kn,{fill:ee[U%ee.length]},`cell-${U}`)})})]})})})]})]}),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(sa,{className:"w-4 h-4 text-emerald-500"}),"Top Performers"]})}),e.jsxs("div",{className:"space-y-[8px]",children:[I.map(A=>e.jsxs("div",{onClick:()=>n(A),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:A.name}),e.jsxs("span",{className:"text-[13px] font-semibold text-emerald-600",children:[A.avgScore,"%"]})]},`top-${A.id}`)),I.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(_s,{className:"w-4 h-4 text-rose-500"}),"Needs Attention"]})}),e.jsxs("div",{className:"space-y-[8px]",children:[$.slice(0,4).map(A=>{const U=A.riskLevel==="high",ee=U?"bg-rose-50/40 border-rose-50":"bg-amber-50/40 border-amber-50";return e.jsxs("div",{onClick:()=>n(A),className:`flex justify-between items-center p-3 rounded-[14px] border group hover:scale-[1.02] transition-transform cursor-pointer ${ee}`,children:[e.jsx("span",{className:"text-[13px] font-semibold text-[#1e293b]",children:A.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] ${U?"text-rose-600":"text-amber-600"}`,children:U?"HIGH RISK":"MEDIUM RISK"})]},`attn-${A.id}`)}),$.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"No urgent students."})]})]})]})]})]})]})},Zm=({student:t,teacherId:s,teacherName:a,onStudentUpdated:r,onBack:n,onNavigateToQuizMaker:o,initialCache:i,onCacheUpdate:l})=>{const c=(t.riskLevel||"low").toLowerCase(),d=c==="high"||c==="medium",x=h.useMemo(()=>Ze.getImportGroundedRolloutFlags(),[]),[b,p]=h.useState(i?.learningPath||""),[g,C]=h.useState(!0),[S,N]=h.useState(i?.gradeDraft||t.grade||"Grade 11"),[m,w]=h.useState(i?.sectionDraft||t.section||"Section A"),[y,R]=h.useState(!1),[j,H]=h.useState(i?.lessonPlan??null),[v,k]=h.useState([]),[I,$]=h.useState(""),[D,q]=h.useState(!1),[Q,A]=h.useState(""),[U,ee]=h.useState("all"),[ie,je]=h.useState("all"),[ge,Ce]=h.useState(!1),[de,B]=h.useState(!1),[Y,ne]=h.useState(null),[De,Le]=h.useState(!1),[Ge,O]=h.useState(!1),[X,f]=h.useState(0),[T,E]=h.useState(!1),[W,V]=h.useState("choose"),[se,ae]=h.useState([]),[z,oe]=h.useState(!1),[ue,ve]=h.useState(!1),[K,we]=h.useState(!1),[We,Se]=h.useState(!1);h.useEffect(()=>{N(t.grade||"Grade 11"),w(t.section||"Section A")},[t.grade,t.section]),h.useEffect(()=>{const M=te=>{if(te.key==="Escape"){if(We){Se(!1);return}if(ue){K?Se(!0):ve(!1);return}T&&E(!1)}};return document.addEventListener("keydown",M),()=>document.removeEventListener("keydown",M)},[ue,T,K,We]),h.useEffect(()=>{if(ue){const M=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.body.style.overflow=M}}},[ue]),h.useEffect(()=>{l?.(t.id,{lessonPlan:j,learningPath:b,gradeDraft:S,sectionDraft:m})},[j,b,S,m,t.id,l]),h.useEffect(()=>{(async()=>{C(!0);try{let te="";try{te=await gl(t.struggles.length>0?t.struggles:[t.weakestTopic],"general_math"),$(te)}catch{$("")}const _e=await Ze.getLearningPath({weaknesses:t.struggles.length>0?t.struggles:[t.weakestTopic],gradeLevel:"High School",subject:"general_math"}),Fe=te?`${_e.learningPath} + +${te}`:_e.learningPath;p(Fe)}catch{p("Unable to generate learning path. Please try again later."),$("")}finally{C(!1)}})()},[t]);const Je=h.useCallback(async()=>{q(!0),A("");try{const M=t.classSectionId||zt(S||"Grade 11",m||"Section A"),te=t.struggles.length>0?t.struggles[0]:t.weakestTopic,_e=await mu({gradeLevel:S||t.grade||"Grade 11",subject:"general_math",quarter:1,moduleUnit:[S,m].filter(Boolean).join(" - ")||t.className,lessonTitle:`Grounded Lesson: ${te}`,learningCompetency:te,learnerLevel:t.avgScore<60?"support":t.avgScore<80?"developing":"advanced",classSectionId:M,className:[S,m].filter(Boolean).join(" - ")||t.className,focusTopics:t.struggles.length>0?t.struggles:[t.weakestTopic],topicCount:5,preferImportedTopics:x.lessonEnabled,allowReviewSources:ge,allowUnverifiedLesson:de},!0);H(_e),k(_e.curriculumSources||[]),ne(null),Ze.reportImportGroundedFeedback({flow:"lesson",status:"success",classSectionId:M,className:[S,m].filter(Boolean).join(" - ")||t.className,metadata:{usedImportedTopics:_e.usedImportedTopics,importedTopicCount:_e.importedTopicCount,blockCount:_e.blocks.length,publishReady:_e.publishReady,sourceLegitimacyStatus:_e.sourceLegitimacy.status,selfValidationPassed:_e.selfValidation.passed,importGroundingEnabled:x.lessonEnabled}})}catch(M){let te=M instanceof Error?M.message:"Unable to generate lesson plan at this time.";if(M instanceof ja&&M.status===422)try{const Fe=JSON.parse(M.responseBody)?.detail;Fe?.message&&(te=Fe.message);const be=Fe?.sourceLegitimacy?.issues||[],ot=Fe?.selfValidation?.issues||[],gt=[...be,...ot].filter(Boolean).slice(0,3);gt.length>0&&(te=`${te} ${gt.join(" ")}`)}catch{}A(te),H(null),k([]),Ze.reportImportGroundedFeedback({flow:"lesson",status:"failed",classSectionId:t.classSectionId||zt(S||"Grade 11",m||"Section A"),className:[S,m].filter(Boolean).join(" - ")||t.className,metadata:{error:te,allowReviewSources:ge,allowUnverifiedLesson:de,importGroundingEnabled:x.lessonEnabled}})}finally{q(!1)}},[t,S,m,x.lessonEnabled,ge,de]),et=h.useCallback(async()=>{if(!j)return me.error("Generate a lesson plan first."),null;Le(!0);try{const M=await du(j,s,{teacherName:a,studentId:t.id,studentName:t.name});return ne(M),me.success("Lesson plan saved as draft."),M}catch(M){return console.error("Failed to save lesson draft:",M),me.error(M instanceof Error?M.message:"Failed to save lesson draft."),null}finally{Le(!1)}},[j,s,a,t.id,t.name]),F=h.useCallback(async()=>{if(!j){me.error("Generate a lesson plan first.");return}if(!j.publishReady){const M=[...j.sourceLegitimacy.issues,...j.selfValidation.issues].filter(Boolean).slice(0,2).join(" ");me.error(M||"Lesson is not publish-ready. Resolve legitimacy and validation checks first.");return}O(!0);try{let M=Y;if(M||(M=await et()),!M)return;await uu(M),me.success("Lesson plan published to class content."),Ze.reportImportGroundedFeedback({flow:"lesson",status:"success",classSectionId:j.classSectionId||t.classSectionId,className:j.className||t.className,metadata:{action:"publish_lesson_plan",lessonPlanId:M,publishReady:j.publishReady,sourceLegitimacyStatus:j.sourceLegitimacy.status,selfValidationPassed:j.selfValidation.passed}})}catch(M){console.error("Failed to publish lesson plan:",M),me.error(M instanceof Error?M.message:"Failed to publish lesson plan."),Ze.reportImportGroundedFeedback({flow:"lesson",status:"failed",classSectionId:j.classSectionId||t.classSectionId,className:j.className||t.className,metadata:{action:"publish_lesson_plan",error:M instanceof Error?M.message:"Failed to publish lesson plan."}})}finally{O(!1)}},[j,Y,et,t.className,t.classSectionId]);h.useEffect(()=>{Je()},[X]),h.useEffect(()=>{f(M=>M+1)},[t.id]),h.useEffect(()=>{ee("all"),je("all")},[j]),h.useMemo(()=>j?Array.from(new Set(j.blocks.map(M=>M.provenance?.sourceFile?.trim()).filter(M=>!!M))).sort((M,te)=>M.localeCompare(te)):[],[j]),h.useMemo(()=>j?Array.from(new Set(j.blocks.map(M=>M.provenance?.materialId?.trim()).filter(M=>!!M))).sort((M,te)=>M.localeCompare(te)):[],[j]);const Z=h.useMemo(()=>j?j.blocks.filter(M=>{const te=U==="all"||(M.provenance?.sourceFile||"").trim()===U,_e=ie==="all"||(M.provenance?.materialId||"").trim()===ie;return te&&_e}):[],[j,U,ie]),Re=[{id:1,type:"video",title:`${t.weakestTopic} Fundamentals`,duration:"8 mins",icon:Cn},{id:2,type:"quiz",title:`${t.weakestTopic} Practice`,questions:10,icon:Ho},{id:3,type:"assessment",title:"Final Check",questions:5,icon:gr}],Ne=async()=>{if(!s){me.error("Unable to update section: teacher context missing");return}R(!0);try{await Ei(t.id,S,m,s,new Date().getFullYear().toString(),a),await Ci(t.id,S,m);const M={...t,grade:S,section:m,className:[S,m].filter(Boolean).join(" - "),classSectionId:zt(S,m)};r(M),me.success("Student section assignment updated")}catch(M){console.error("Failed to update student section assignment:",M),me.error("Failed to update section assignment")}finally{R(!1)}};return e.jsxs(Pe.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:n,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(Sa,{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(cn,{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(cn,{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"]})]})]}),I&&e.jsx(eo,{sources:v,className:"mb-4 relative z-10"}),e.jsx(va,{name:"teacher-intervention-analysis",loading:g,fixture:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4 w-full relative z-10",children:[e.jsx(Me,{className:"h-24 w-full rounded-[14px]"}),e.jsx(Me,{className:"h-24 w-full rounded-[14px]"})]}),fallback:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4 w-full relative z-10",children:[e.jsx(Me,{className:"h-24 w-full rounded-[14px]"}),e.jsx(Me,{className:"h-24 w-full rounded-[14px]"})]}),children: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(sa,{className:"w-3.5 h-3.5"})," Learning Strengths"]}),e.jsx("p",{className:"text-[13px] text-[#475569] leading-relaxed pl-2",children: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(Yt,{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:t.struggles.length>0?t.struggles.map((M,te)=>e.jsxs("li",{children:["Must continue strengthening ",e.jsx("span",{className:"font-semibold text-[#1e293b]",children:M}),"."]},te)):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("button",{disabled:g,onClick:()=>f(M=>M+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(Vs,{className:"w-3 h-3"})," Regenerate"]})]}),e.jsxs(va,{name:"teacher-intervention-learning-path",loading:g,fixture:e.jsxs("div",{className:"space-y-4",children:[e.jsx(Me,{className:"h-24 w-full rounded-xl"}),e.jsx(Me,{className:"h-20 w-full rounded-[14px]"}),e.jsx(Me,{className:"h-20 w-full rounded-[14px]"}),e.jsx(Me,{className:"h-20 w-full rounded-[14px]"})]}),fallback:e.jsxs("div",{className:"space-y-4",children:[e.jsx(Me,{className:"h-24 w-full rounded-xl"}),e.jsx(Me,{className:"h-20 w-full rounded-[14px]"}),e.jsx(Me,{className:"h-20 w-full rounded-[14px]"}),e.jsx(Me,{className:"h-20 w-full rounded-[14px]"})]}),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:"}),e.jsx("span",{className:"px-3 py-1 bg-[#f8fafc] text-[#475569] text-[11px] font-semibold rounded-full border border-[#e2e8f0]",children:"Interactive"}),e.jsx("span",{className:"px-3 py-1 bg-[#f8fafc] text-[#475569] text-[11px] font-semibold rounded-full border border-[#e2e8f0]",children:"Video"}),e.jsx("span",{className:"px-3 py-1 bg-[#f8fafc] text-[#475569] text-[11px] font-semibold rounded-full border border-[#e2e8f0]",children:"Practice"}),e.jsx("span",{className:"px-3 py-1 bg-[#f8fafc] text-[#475569] text-[11px] font-semibold rounded-full border border-[#e2e8f0]",children:"Quiz"})]}),e.jsx("div",{className:"relative border-l-2 border-[#e2e8f0] ml-[20px] space-y-[28px] pb-4",children:Re.map((M,te)=>{let _e=e.jsx(Cn,{className:"w-4 h-4"}),Fe="bg-[#8b5cf6] shadow-[0_4px_10px_rgba(139,92,246,0.3)]",be="text-purple-600",ot="group-hover:border-purple-200",gt="hover:bg-[#4f46e5]",Dt=e.jsx(Il,{className:"w-4 h-4 ml-0.5"});return M.type==="quiz"?(_e=e.jsx(El,{className:"w-4 h-4"}),Fe="bg-sky-500 shadow-[0_4px_10px_rgba(14,165,233,0.3)]",be="text-sky-600",ot="group-hover:border-sky-200",gt="hover:bg-sky-500",Dt=e.jsx(es,{className:"w-4 h-4"})):M.type==="assessment"&&(_e=e.jsx(Ra,{className:"w-4 h-4"}),Fe="bg-emerald-500 shadow-[0_4px_10px_rgba(16,185,129,0.3)]",be="text-emerald-600",ot="group-hover:bg-emerald-50"),e.jsxs(Pe.div,{initial:{opacity:0,x:-20},animate:{opacity:1,x:0},transition:{delay:te*.1},className:"relative pl-[32px] group",children:[e.jsx("div",{className:`absolute -left-[17px] top-1 w-8 h-8 rounded-full ${Fe} text-white flex items-center justify-center ring-4 ring-white group-hover:scale-110 transition-transform`,children:_e}),e.jsxs("div",{className:`${M.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 ${ot}`,children:[e.jsxs("div",{children:[e.jsxs("span",{className:`text-[10px] font-semibold uppercase tracking-wider mb-1 block ${be}`,children:["Step ",te+1," • ",M.type==="video"?"Video Lesson":M.type==="quiz"?"Practice":"Assessment"]}),e.jsx("p",{className:"font-semibold text-[#1e293b] text-[13px] mb-0.5",children:M.title}),e.jsxs("p",{className:"text-[#64748b] text-[11px] flex items-center gap-1.5",children:[M.type==="video"&&e.jsxs(e.Fragment,{children:[e.jsx(Ms,{className:"w-3 h-3"})," ",M.duration]}),M.type==="quiz"&&e.jsxs(e.Fragment,{children:[e.jsx(Go,{className:"w-3 h-3"})," ",M.questions," questions"]}),M.type==="assessment"&&e.jsxs(e.Fragment,{children:[e.jsx(Yt,{className:"w-3 h-3"})," ",M.questions," assessment questions"]})]})]}),M.type==="assessment"?e.jsx(Ro,{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] ${gt} hover:text-white transition-colors border border-[#e2e8f0]`,children:Dt})]})]},M.id)})})]})]}),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-2",children:[e.jsx("h3",{className:"text-[15px] font-semibold text-[#1e293b]",children:"Targeted Lesson Generation"}),e.jsx(ms,{onClick:()=>f(M=>M+1),disabled:D,className:"bg-[#4f46e5] hover:bg-[#3730a3] text-white h-8 text-[11px] rounded-full px-4",children:D?e.jsx(Me,{className:"h-3 w-16 bg-white/35"}):"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(Us,{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:ge,onChange:M=>Ce(M.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:de,onChange:M=>B(M.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(va,{name:"teacher-intervention-lesson-plan",loading:D,fixture:e.jsxs("div",{className:"space-y-4",children:[e.jsx(Me,{className:"h-20 w-full rounded-xl"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[e.jsx(Me,{className:"h-24 w-full rounded-xl"}),e.jsx(Me,{className:"h-24 w-full rounded-xl"})]}),e.jsx(Me,{className:"h-28 w-full rounded-xl"})]}),fallback:e.jsxs("div",{className:"space-y-4",children:[e.jsx(Me,{className:"h-20 w-full rounded-xl"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[e.jsx(Me,{className:"h-24 w-full rounded-xl"}),e.jsx(Me,{className:"h-24 w-full rounded-xl"})]}),e.jsx(Me,{className:"h-28 w-full rounded-xl"})]}),children:[Q&&e.jsx("div",{className:"bg-[#FF8B8B]/14 border border-[#FF8B8B]/35 rounded-xl p-3 text-sm text-[#D66A6A] mb-4",children:Q}),j&&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(eo,{sources:v})}),e.jsx("p",{className:"text-[14px] font-semibold text-[#1e293b]",children:j.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:"})," ",j.usedImportedTopics?"Yes":"No"," (",j.importedTopicCount,")"]}),e.jsxs("p",{className:"text-[11px] text-[#64748b]",children:[e.jsx("span",{className:"font-semibold text-[#475569]",children:"Subject:"})," ",j.subject||"General Math"," (Q",j.quarter||1,")"]})]}),j.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: ",j.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 ${j.publishReady?"text-emerald-600":"text-rose-500"}`,children:j.publishReady?"Ready":"Blocked"})]})}),j.warnings.length>0&&e.jsx("p",{className:"text-[11px] text-amber-600 mt-2 bg-amber-50 px-2 py-1.5 rounded",children:j.warnings.join(" ")})]}),j.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:j.lessonObjective})]}),j.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:j.realWorldHook})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3 mt-4",children:Z.map(M=>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:M.title}),e.jsxs("p",{className:"text-[11px] text-[#64748b] mt-1",children:[M.estimatedMinutes," mins "," • "," ",M.strategy]}),e.jsx("p",{className:"text-[12px] text-[#475569] mt-2 bg-[#f8fafc] p-2 rounded-lg",children:M.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"}),M.activities.slice(0,2).map((te,_e)=>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:te})]},_e))]})]},M.blockId))}),e.jsxs("div",{className:"flex flex-wrap gap-2 pt-4",children:[e.jsx(ms,{variant:"outline",onClick:()=>void et(),disabled:De||!j,className:"border-[#cbd5e1] text-[#475569] hover:bg-[#f8fafc] text-[12px] h-9 rounded-full px-5",children:De?e.jsx(Me,{className:"h-4 w-16"}):"Save Draft"}),e.jsx(ms,{onClick:()=>void F(),disabled:Ge||!j||!j.publishReady,className:"bg-[#10b981] hover:bg-[#059669] text-white text-[12px] h-9 rounded-full px-5",children:Ge?e.jsx(Me,{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 ${t.riskLevel==="high"?"text-rose-600 bg-rose-50 border-rose-100":t.riskLevel==="medium"?"text-amber-600 bg-amber-50 border-amber-100":"text-emerald-600 bg-emerald-50 border-emerald-100"}`,children: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:[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:t.avgScore>80?"High":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: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:t.weakestTopic,children:t.weakestTopic})]})]}),e.jsx("div",{className:"w-full flex flex-col gap-[10px]",children:e.jsxs("button",{onClick:async()=>{V("choose"),E(!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(fc,{className:"w-4 h-4"})," Export Materials"]})}),T&&sr.createPortal(e.jsxs("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center p-4",onClick:()=>E(!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:M=>M.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:[W==="bank"&&e.jsx("button",{onClick:()=>V("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(as,{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(or,{className:"w-4 h-4 text-white"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-[15px] font-bold text-white leading-tight",children:W==="choose"?"Export Materials":"Choose a Quiz"}),e.jsx("p",{className:"text-[11px] text-white/70 font-medium",children:W==="choose"?`For ${t.name}`:"Select a quiz from your bank"})]})]}),e.jsx("button",{onClick:()=>E(!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(ps,{className:"w-4 h-4"})})]})}),e.jsx("div",{className:"p-6",children:W==="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()=>{oe(!0),V("bank");try{const M=await $o(s);ae(M)}catch{ae([])}finally{oe(!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(Ca,{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:()=>{E(!1),we(!1),ve(!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(ss,{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:z?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..."})]}):se.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(Ca,{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:se.map(M=>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:M.title}),e.jsxs("p",{className:"text-[11px] text-[#64748b] font-medium mt-0.5",children:[M.questions?.length??0," questions",M.gradeLevel?` · ${M.gradeLevel}`:"",M.metadata?.topicsCovered?.[0]?` · ${M.metadata.topicsCovered[0]}`:""]})]}),e.jsx("button",{onClick:()=>{E(!1),me.success(`"${M.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"})]},M.id))})})})]})]}),document.body),ue&&sr.createPortal(e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[9998] bg-black/40 backdrop-blur-sm",onClick:()=>{K?Se(!0):ve(!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:()=>{K?Se(!0):ve(!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(Sa,{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(or,{className:"w-3.5 h-3.5 text-white"})}),e.jsx("span",{className:"text-[14px] font-bold text-[#1e293b]",children:"AI Quiz Maker"})]}),K&&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(_i,{onBack:()=>ve(!1),drawerMode:!0,gradeLevel:t.grade,onQuizGenerating:()=>we(!0),onQuizSaved:M=>{we(!1),me.success("Quiz saved! Close this panel or create another.",{action:{label:"Close Panel",onClick:()=>ve(!1)}})}})})]}),We&&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:()=>Se(!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(aa,{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:()=>Se(!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:()=>{Se(!1),ve(!1),we(!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(Qs,{value:S,onChange:M=>N(M.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(Qs,{value:m,onChange:M=>w(M.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:Ne,disabled:y||!S.trim()||!m.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:y?"Updating...":"Update Assignment"})]})]})]})})]})},ex=({onViewCalendar:t,onOpenProfile:s,userProfile:a,teacherName:r})=>{const[n,o]=h.useState(new Date),[i,l]=h.useState("pulse"),c=m=>new Date(m.getFullYear(),m.getMonth()+1,0).getDate(),d=m=>new Date(m.getFullYear(),m.getMonth(),1).getDay(),x=()=>n.toLocaleDateString(void 0,{month:"long",year:"numeric"}),b=()=>o(new Date(n.getFullYear(),n.getMonth()-1)),p=()=>o(new Date(n.getFullYear(),n.getMonth()+1)),g=()=>{const m=c(n),w=d(n),y=[];for(let R=w-1;R>=0;R--)y.unshift(null);for(let R=1;R<=m;R++)y.push(R);return y},C=m=>{if(!m)return!1;const w=new Date;return m===w.getDate()&&n.getMonth()===w.getMonth()&&n.getFullYear()===w.getFullYear()},S=g(),N=["Mo","Tu","We","Th","Fr","Sa","Su"];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(fl,{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:"p-[10px_16px] border-b border-[#f1f5f9]",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("button",{onClick:b,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]",children:e.jsx(as,{size:14})}),e.jsx("span",{className:"text-[12px] font-semibold text-[#1e293b]",children:x()}),e.jsx("button",{onClick:p,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]",children:e.jsx(es,{size:14})})]}),e.jsxs("div",{className:"grid grid-cols-7 gap-[2px] text-center mb-1",children:[N.map(m=>e.jsx("div",{className:"text-[10px] font-semibold text-[#94a3b8] p-[2px_0_4px]",children:m},m)),S.map((m,w)=>e.jsx("div",{className:`text-[11px] leading-[22px] w-[22px] h-[22px] m-auto flex items-center justify-center rounded-full ${m===null?"text-[#cbd5e1]":C(m)?"bg-[#818cf8] text-white font-semibold":"text-[#475569]"}`,children:m},`${n.getMonth()}-${w}`))]})]}),e.jsxs("div",{className:"flex gap-[18px] p-[12px_16px_0] border-b border-[#f1f5f9] flex-shrink-0",children:[e.jsx("button",{onClick:()=>l("pulse"),className:`text-[11.5px] font-semibold pb-[9px] border-b-[2.5px] transition-colors ${i==="pulse"?"text-[#10b981] border-[#10b981]":"text-[#94a3b8] border-transparent"}`,children:"Live pulse"}),e.jsx("button",{onClick:()=>l("reminders"),className:`text-[11.5px] font-semibold pb-[9px] border-b-[2.5px] transition-colors ${i==="reminders"?"text-[#10b981] border-[#10b981]":"text-[#94a3b8] border-transparent"}`,children:"Reminders"})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-[14px_16px]",children:[i==="pulse"&&e.jsxs("div",{className:"flex flex-col items-center gap-3",children:[e.jsxs("svg",{className:"w-[96px] h-[96px]",viewBox:"0 0 36 36",children:[e.jsx("circle",{cx:"18",cy:"18",r:"14",fill:"none",stroke:"#e2e8f0",strokeWidth:"4"}),e.jsx("circle",{cx:"18",cy:"18",r:"14",fill:"none",stroke:"#10b981",strokeWidth:"4",strokeDasharray:"78 100",strokeDashoffset:"25",strokeLinecap:"round"}),e.jsx("text",{x:"18",y:"16.5",textAnchor:"middle",fontFamily:"DM Sans,sans-serif",fontSize:"7",fontWeight:"600",fill:"#1e293b",children:"78%"}),e.jsx("text",{x:"18",y:"23",textAnchor:"middle",fontFamily:"DM Sans,sans-serif",fontSize:"3.8",fill:"#94a3b8",letterSpacing:"0.3",children:"ENGAGED"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-[7px] w-full",children:[e.jsxs("div",{className:"flex items-center gap-[6px] text-[11px] text-[#64748b]",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-[#10b981] flex-shrink-0"}),"Engaged",e.jsx("span",{className:"ml-auto font-semibold text-[#1e293b]",children:"78%"})]}),e.jsxs("div",{className:"flex items-center gap-[6px] text-[11px] text-[#64748b]",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-[#e2e8f0] flex-shrink-0"}),"Inactive",e.jsx("span",{className:"ml-auto font-semibold text-[#1e293b]",children:"22%"})]})]}),e.jsxs("div",{className:"bg-[#f8fafc] rounded-[11px] p-[11px_12px] text-center w-full mt-1",children:[e.jsx("div",{className:"text-[9px] font-semibold text-[#94a3b8] uppercase tracking-[0.07em] mb-[3px]",children:"Current activity"}),e.jsx("div",{className:"text-[12px] font-medium text-[#1e293b] mb-[2px]",children:"Quadratic equations quiz"}),e.jsx("div",{className:"text-[11.5px] text-[#4f46e5] font-medium",children:"10 / 12 students active"})]})]}),i==="reminders"&&e.jsxs("div",{className:"space-y-[8px]",children:[e.jsxs("div",{className:"flex items-start gap-[10px] p-[10px_11px] border border-[#f1f5f9] rounded-[12px] cursor-pointer hover:bg-[#f8fafc] transition-colors",children:[e.jsx("div",{className:"p-[7px] rounded-[8px] border border-[#f1f5f9] bg-white text-[14px] text-[#4f46e5] flex-shrink-0",children:e.jsx(Rs,{size:14})}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[12px] font-medium text-[#1e293b] mb-[2px]",children:"Eng – Vocabulary test"}),e.jsx("div",{className:"text-[10.5px] text-[#94a3b8]",children:"12 May 2026, Friday"})]})]}),e.jsxs("div",{className:"flex items-start gap-[10px] p-[10px_11px] border border-[#f1f5f9] rounded-[12px] cursor-pointer hover:bg-[#f8fafc] transition-colors",children:[e.jsx("div",{className:"p-[7px] rounded-[8px] border border-[#f1f5f9] bg-white text-[14px] text-[#10b981] flex-shrink-0",children:e.jsx(Lt,{size:14})}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[12px] font-medium text-[#1e293b] mb-[2px]",children:"Eng – Essay review"}),e.jsx("div",{className:"text-[10.5px] text-[#94a3b8]",children:"12 May 2026, Friday"})]})]})]})]})]})};export{Jx as default}; diff --git a/assets/TeacherDashboard-CZdYfdg9.js b/assets/TeacherDashboard-CZdYfdg9.js deleted file mode 100644 index 18f428c6b8f9dcc4d04f8a5de0c4c967b98b5a2a..0000000000000000000000000000000000000000 --- a/assets/TeacherDashboard-CZdYfdg9.js +++ /dev/null @@ -1,83 +0,0 @@ -const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/vendor-firebase-firestore-CH1lNiRF.js","assets/vendor-firebase-core-CO26nNq6.js","assets/index-BaOs5Ayg.js","assets/vendor-react-B4AQeu28.js","assets/vendor-firebase-auth-BLpRW_zO.js","assets/vendor-firebase-storage-B3igpVVS.js","assets/vendor-firebase-analytics-CTiUNb0-.js","assets/vendor-radix-BorKzPz9.js","assets/vendor-charts-D8hf8tI0.js","assets/vendor-markdown-yqZQ_iQm.js","assets/vendor-markdown-CfVKi3_s.css","assets/index-DdX2rVyy.css"])))=>i.map(i=>d[i]); -import{e as pt,f as Ge,g as Wl,h as Ve,i as hr,a as Vt,j as Qt,m as Re,G as mo,B as uo,Z as $s,u as Ks,t as ce,k as Os,l as nt,T as ka,U as Ps,C as Vl,n as en,R as _s,o as ql,p as Gt,q as tn,r as sn,A as Yl,v as Kl,w as Xl,x as Jl,y as Zl,z as ei,M as ti,D as si,_ as ba,E as ai}from"./index-BaOs5Ayg.js";import{d as oe,j as e,r as p,c as ri}from"./vendor-react-B4AQeu28.js";import{c as ni,B as $e}from"./button-DCfeFHoH.js";import{I as vt}from"./input-D28h_UTJ.js";import{D as xo,a as ho,b as po,c as fo,d as go,e as bo,f as oi}from"./dialog-CHtYkwVl.js";import li from"./ConfirmModal-6cgkqXAT.js";import{M as ii,L as ci,S as di,a as mi}from"./LogoutActionButton-lUNItet6.js";import{collection as Bt,query as zt,limit as vo,where as Ft,getDocs as qt,orderBy as ui,onSnapshot as Xs,setDoc as Ut,doc as et,updateDoc as yt,getDoc as ns,serverTimestamp as ot,deleteDoc as xi,arrayUnion as hi}from"./vendor-firebase-firestore-CH1lNiRF.js";import{S as pi,a as fi}from"./vendor-radix-BorKzPz9.js";import{T as gi,a as bi,b as vi}from"./tooltip-ChRIOid3.js";import{X as va}from"./x-TNvtuOD9.js";import{s as an,f as Ni,d as ji,L as yi,p as wi,a as Si,S as ki}from"./quizService-8JHQlvu9.js";import{logQuizGeneration as Ci}from"./trackingService-DQ12buWG.js";import{C as Pt}from"./chevron-left-BWpgclqc.js";import{E as pr,a as Ti}from"./eye-Ig3S6mOs.js";import{S as zs}from"./send-CwwDU3uJ.js";import{T as No}from"./trash-2-HTnKafZd.js";import{C as Ca}from"./circle-alert-CP9K3300.js";import{C as gs}from"./check-BLSo9L0H.js";import{I as tr,F as fr,T as Ii,a as Ei,b as _a,c as ms,d as Ri,e as ss,f as Ai,D as Mi}from"./table-xeOJ8ZAA.js";import{C as Na,a as Ht}from"./chevron-up-Cdvz2TMJ.js";import{M as jo}from"./minus-DfrEv-SC.js";import{P as ma}from"./plus-DkG35AoH.js";import{C as Li,a as Ts,b as Is,c as Es,d as Rs}from"./card-D4dmQVNb.js";import{D as gr}from"./download-DX_YebqQ.js";import{C as Wt}from"./chevron-right-COqGruhh.js";import{S as yo}from"./save-CQIJrhLf.js";import{S as Js}from"./search-Bq99THgc.js";import{U as Di}from"./upload-DayXhGwD.js";import{u as zi}from"./useQuery-BnRttv09.js";import{S as rn,g as Fi,G as Bi,s as nn}from"./subjects-BFghB0SQ.js";import{u as $i}from"./useCurriculum-DDCuCvMR.js";import{C as Hs}from"./chart-column-B3jJOD5i.js";import{C as ja}from"./circle-check-big-m1SvzGFL.js";import wo from"./ChatMarkdown-fgwaycBR.js";import{B as ua}from"./bell-clcSMJn6.js";import{C as Oi}from"./check-check-B_HghS1Z.js";import{C as So}from"./clock-D1Ecvltm.js";import{S as he}from"./skeleton-Bo6ISWhm.js";import{u as wt,r as Pi}from"./vendor-xlsx-uZelXSz_.js";import{C as ko}from"./circle-help-B8apTIdU.js";import{S as Co}from"./shield-check-Dgisjfmb.js";import{R as sr,L as _i,Y as ar,a as oa,T as rr,b as Hi,B as on,C as ln,X as cn,d as dn,e as Gi}from"./vendor-charts-D8hf8tI0.js";import{C as To}from"./clipboard-check-DqBu2Pqb.js";import"./vendor-firebase-core-CO26nNq6.js";import"./vendor-firebase-auth-BLpRW_zO.js";import"./vendor-firebase-storage-B3igpVVS.js";import"./vendor-firebase-analytics-CTiUNb0-.js";import"./vendor-markdown-yqZQ_iQm.js";import"./log-out-BenDMDly.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 Qi=[["path",{d:"m3 16 4 4 4-4",key:"1co6wj"}],["path",{d:"M7 20V4",key:"1yoxec"}],["path",{d:"M11 4h10",key:"1w87gc"}],["path",{d:"M11 8h7",key:"djye34"}],["path",{d:"M11 12h4",key:"q8tih4"}]],Ui=pt("arrow-down-wide-narrow",Qi);/** - * @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 Wi=[["path",{d:"m3 8 4-4 4 4",key:"11wl7u"}],["path",{d:"M7 4v16",key:"1glfcx"}],["path",{d:"M11 12h4",key:"q8tih4"}],["path",{d:"M11 16h7",key:"uosisv"}],["path",{d:"M11 20h10",key:"jvxblo"}]],Vi=pt("arrow-up-narrow-wide",Wi);/** - * @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 qi=[["path",{d:"M8 2v4",key:"1cmpym"}],["path",{d:"M16 2v4",key:"4m81vk"}],["rect",{width:"18",height:"18",x:"3",y:"4",rx:"2",key:"1hopcy"}],["path",{d:"M3 10h18",key:"8toen8"}],["path",{d:"M8 14h.01",key:"6423bh"}],["path",{d:"M12 14h.01",key:"1etili"}],["path",{d:"M16 14h.01",key:"1gbofw"}],["path",{d:"M8 18h.01",key:"lrp35t"}],["path",{d:"M12 18h.01",key:"mhygvu"}],["path",{d:"M16 18h.01",key:"kzsmim"}]],Yi=pt("calendar-days",qi);/** - * @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 Ki=[["line",{x1:"18",x2:"18",y1:"20",y2:"10",key:"1xfpm4"}],["line",{x1:"12",x2:"12",y1:"20",y2:"4",key:"be30l9"}],["line",{x1:"6",x2:"6",y1:"20",y2:"14",key:"1r4le6"}]],Xi=pt("chart-no-axes-column",Ki);/** - * @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 Ji=[["rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1",key:"tgr4d6"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2",key:"116196"}],["path",{d:"M12 11h4",key:"1jrz19"}],["path",{d:"M12 16h4",key:"n85exb"}],["path",{d:"M8 11h.01",key:"1dfujw"}],["path",{d:"M8 16h.01",key:"18s6g9"}]],Zi=pt("clipboard-list",Ji);/** - * @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 ec=[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"M10 14 21 3",key:"gplh6r"}],["path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6",key:"a6xqqp"}]],tc=pt("external-link",ec);/** - * @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 sc=[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M8 13h2",key:"yr2amv"}],["path",{d:"M14 13h2",key:"un5t4a"}],["path",{d:"M8 17h2",key:"2yhykz"}],["path",{d:"M14 17h2",key:"10kma7"}]],ac=pt("file-spreadsheet",sc);/** - * @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 rc=[["path",{d:"m16 6 4 14",key:"ji33uf"}],["path",{d:"M12 6v14",key:"1n7gus"}],["path",{d:"M8 8v12",key:"1gg7y9"}],["path",{d:"M4 4v16",key:"6qkkli"}]],mn=pt("library",rc);/** - * @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 nc=[["path",{d:"M12 20h9",key:"t2du7b"}],["path",{d:"M16.376 3.622a1 1 0 0 1 3.002 3.002L7.368 18.635a2 2 0 0 1-.855.506l-2.872.838a.5.5 0 0 1-.62-.62l.838-2.872a2 2 0 0 1 .506-.854z",key:"1ykcvy"}]],Io=pt("pen-line",nc);/** - * @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 oc=[["path",{d:"m16 16 3-8 3 8c-.87.65-1.92 1-3 1s-2.13-.35-3-1Z",key:"7g6ntu"}],["path",{d:"m2 16 3-8 3 8c-.87.65-1.92 1-3 1s-2.13-.35-3-1Z",key:"ijws7r"}],["path",{d:"M7 21h10",key:"1b0cd5"}],["path",{d:"M12 3v18",key:"108xh3"}],["path",{d:"M3 7h2c2 0 5-1 7-2 2 1 5 2 7 2h2",key:"3gwbw2"}]],lc=pt("scale",oc);/** - * @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 ic=[["path",{d:"m12.5 17-.5-1-.5 1h1z",key:"3me087"}],["path",{d:"M15 22a1 1 0 0 0 1-1v-1a2 2 0 0 0 1.56-3.25 8 8 0 1 0-11.12 0A2 2 0 0 0 8 20v1a1 1 0 0 0 1 1z",key:"1o5pge"}],["circle",{cx:"15",cy:"12",r:"1",key:"1tmaij"}],["circle",{cx:"9",cy:"12",r:"1",key:"1vctgf"}]],Eo=pt("skull",ic);/** - * @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 cc=[["path",{d:"M21 10.5V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h12.5",key:"1uzm8b"}],["path",{d:"m9 11 3 3L22 4",key:"1pflzl"}]],dc=pt("square-check-big",cc);/** - * @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 mc=[["path",{d:"m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5",key:"ftymec"}],["rect",{x:"2",y:"6",width:"14",height:"12",rx:"2",key:"158x01"}]],uc=pt("video",mc);/** - * @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 xc=[["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"}]],hc=pt("wand-sparkles",xc),Ta=0,Kt=1,js=2,Ro=4;function un(t){return()=>t}function pc(t){t()}function Ao(t,s){return a=>t(s(a))}function xn(t,s){return()=>t(s)}function fc(t,s){return a=>t(s,a)}function br(t){return t!==void 0}function gc(...t){return()=>{t.map(pc)}}function ys(){}function Ia(t,s){return s(t),t}function bc(t,s){return s(t)}function Ye(...t){return t}function Oe(t,s){return t(Kt,s)}function Ie(t,s){t(Ta,s)}function vr(t){t(js)}function Ke(t){return t(Ro)}function de(t,s){return Oe(t,fc(s,Ta))}function Tt(t,s){const a=t(Kt,r=>{a(),s(r)});return a}function hn(t){let s,a;return r=>n=>{s=n,a&&clearTimeout(a),a=setTimeout(()=>{r(s)},t)}}function Mo(t,s){return t===s}function qe(t=Mo){let s;return a=>r=>{t(s,r)||(s=r,a(r))}}function ve(t){return s=>a=>{t(a)&&s(a)}}function se(t){return s=>Ao(s,t)}function Mt(t){return s=>()=>{s(t)}}function _(t,...s){const a=vc(...s);return((r,n)=>{switch(r){case js:vr(t);return;case Kt:return Oe(t,a(n))}})}function Lt(t,s){return a=>r=>{a(s=t(s,r))}}function ls(t){return s=>a=>{t>0?t--:s(a)}}function _t(t){let s=null,a;return r=>n=>{s=n,!a&&(a=setTimeout(()=>{a=void 0,r(s)},t))}}function Ee(...t){const s=new Array(t.length);let a=0,r=null;const n=2**t.length-1;return t.forEach((o,l)=>{const i=2**l;Oe(o,c=>{const d=a;a|=i,s[l]=c,d!==n&&a===n&&r&&(r(),r=null)})}),o=>l=>{const i=()=>{o([l].concat(s))};a===n?i():r=i}}function vc(...t){return s=>t.reduceRight(bc,s)}function Nc(t){let s,a;const r=()=>s?.();return function(n,o){switch(n){case Kt:return o?a===o?void 0:(r(),a=o,s=Oe(t,o),s):(r(),ys);case js:r(),a=null;return}}}function Q(t){let s=t;const a=Ae();return((r,n)=>{switch(r){case Ta:s=n;break;case Kt:{n(s);break}case Ro:return s}return a(r,n)})}function ut(t,s){return Ia(Q(s),a=>de(t,a))}function Ae(){const t=[];return((s,a)=>{switch(s){case Ta:t.slice().forEach(r=>{r(a)});return;case js:t.splice(0,t.length);return;case Kt:return t.push(a),()=>{const r=t.indexOf(a);r>-1&&t.splice(r,1)}}})}function gt(t){return Ia(Ae(),s=>de(t,s))}function Fe(t,s=[],{singleton:a}={singleton:!0}){return{constructor:t,dependencies:s,id:jc(),singleton:a}}const jc=()=>Symbol();function yc(t){const s=new Map,a=({constructor:r,dependencies:n,id:o,singleton:l})=>{if(l&&s.has(o))return s.get(o);const i=r(n.map(c=>a(c)));return l&&s.set(o,i),i};return a(t)}function Ze(...t){const s=Ae(),a=new Array(t.length);let r=0;const n=2**t.length-1;return t.forEach((o,l)=>{const i=2**l;Oe(o,c=>{a[l]=c,r|=i,r===n&&Ie(s,a)})}),function(o,l){switch(o){case js:{vr(s);return}case Kt:return r===n&&l(a),Oe(s,l)}}}function be(t,s=Mo){return _(t,qe(s))}function nr(...t){return function(s,a){switch(s){case js:return;case Kt:return gc(...t.map(r=>Oe(r,a)))}}}const at={DEBUG:0,INFO:1,WARN:2,ERROR:3},wc={[at.DEBUG]:"debug",[at.ERROR]:"error",[at.INFO]:"log",[at.WARN]:"warn"},Sc=()=>typeof globalThis>"u"?window:globalThis,Xt=Fe(()=>{const t=Q(at.ERROR);return{log:Q((s,a,r=at.INFO)=>{const n=Sc().VIRTUOSO_LOG_LEVEL??Ke(t);r>=n&&console[wc[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",s,a)}),logLevel:t}},[],{singleton:!0});function is(t,s,a){return Nr(t,s,a).callbackRef}function Nr(t,s,a){const r=oe.useRef(null);let n=l=>{};const o=oe.useMemo(()=>typeof ResizeObserver<"u"?new ResizeObserver(l=>{const i=()=>{const c=l[0].target;c.offsetParent!==null&&t(c)};a?i():requestAnimationFrame(i)}):null,[t,a]);return n=l=>{l&&s?(o?.observe(l),r.current=l):(r.current&&o?.unobserve(r.current),r.current=null)},{callbackRef:n,ref:r}}function kc(t,s,a,r,n,o,l,i,c){const d=oe.useCallback(u=>{const N=Cc(u.children,s,i?"offsetWidth":"offsetHeight",n);let m=u.parentElement;for(;m.dataset.virtuosoScroller===void 0;)m=m.parentElement;const h=m.lastElementChild.dataset.viewportType==="window";let w;h&&(w=m.ownerDocument.defaultView);const k=l?i?l.scrollLeft:l.scrollTop:h?i?w.scrollX||w.document.documentElement.scrollLeft:w.scrollY||w.document.documentElement.scrollTop:i?m.scrollLeft:m.scrollTop,y=l?i?l.scrollWidth:l.scrollHeight:h?i?w.document.documentElement.scrollWidth:w.document.documentElement.scrollHeight:i?m.scrollWidth:m.scrollHeight,f=l?i?l.offsetWidth:l.offsetHeight:h?i?w.innerWidth:w.innerHeight:i?m.offsetWidth:m.offsetHeight;r({scrollHeight:y,scrollTop:Math.max(k,0),viewportHeight:f}),o?.(i?pn("column-gap",getComputedStyle(u).columnGap,n):pn("row-gap",getComputedStyle(u).rowGap,n)),N!==null&&t(N)},[t,s,n,o,l,r,i]);return Nr(d,a,c)}function Cc(t,s,a,r){const n=t.length;if(n===0)return null;const o=[];for(let l=0;l{if(!c?.offsetParent)return;const d=c.getBoundingClientRect(),u=d.width;let N,m;if(s){const h=s.getBoundingClientRect(),w=d.top-h.top;m=h.height-Math.max(0,w),N=w+s.scrollTop}else{const h=l.current.ownerDocument.defaultView;m=h.innerHeight-Math.max(0,d.top),N=d.top+h.scrollY}r.current={listHeight:d.height,offsetTop:N,visibleHeight:m,visibleWidth:u},t(r.current)},[t,s]),{callbackRef:o,ref:l}=Nr(n,!0,a),i=oe.useCallback(()=>{n(l.current)},[n,l]);return oe.useEffect(()=>{if(s){s.addEventListener("scroll",i);const d=new ResizeObserver(()=>{requestAnimationFrame(i)});return d.observe(s),()=>{s.removeEventListener("scroll",i),d.unobserve(s)}}const c=l.current?.ownerDocument.defaultView;return c?.addEventListener("scroll",i),c?.addEventListener("resize",i),()=>{c?.removeEventListener("scroll",i),c?.removeEventListener("resize",i)}},[i,s,l]),o}const ht=Fe(()=>{const t=Ae(),s=Ae(),a=Q(0),r=Ae(),n=Q(0),o=Ae(),l=Ae(),i=Q(0),c=Q(0),d=Q(0),u=Q(0),N=Ae(),m=Ae(),h=Q(!1),w=Q(!1),k=Q(!1);return de(_(t,se(({scrollTop:y})=>y)),s),de(_(t,se(({scrollHeight:y})=>y)),l),de(s,n),{deviation:a,fixedFooterHeight:d,fixedHeaderHeight:c,footerHeight:u,headerHeight:i,horizontalDirection:w,scrollBy:m,scrollContainerState:t,scrollHeight:l,scrollingInProgress:h,scrollTo:N,scrollTop:s,skipAnimationFrameInResizeObserver:k,smoothScrollTargetReached:r,statefulScrollTop:n,viewportHeight:o}},[],{singleton:!0}),Gs={lvl:0};function Do(t,s){const a=t.length;if(a===0)return[];let{index:r,value:n}=s(t[0]);const o=[];for(let l=1;ls&&(i=i.concat(lr(n,s,a))),r>=s&&r<=a&&i.push({k:r,v:l}),r<=a&&(i=i.concat(lr(o,s,a))),i}function xa(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(Ha(s))return $o(st(t,{lvl:a-1}));if(!Qe(s)&&!Qe(s.r))return st(s.r,{l:st(s,{r:s.r.l}),lvl:a,r:st(t,{l:s.r.r,lvl:a-1})});throw new Error("Unexpected empty nodes")}if(Ha(t))return ir(st(t,{lvl:a-1}));if(!Qe(r)&&!Qe(r.l)){const n=r.l,o=Ha(n)?r.lvl-1:r.lvl;return st(n,{l:st(t,{lvl:a-1,r:n.l}),lvl:n.lvl+1,r:ir(st(r,{l:n.r,lvl:o}))})}throw new Error("Unexpected empty nodes")}function st(t,s){return Bo(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 zo(t){return Qe(t.r)?t.l:xa(st(t,{r:zo(t.r)}))}function Ha(t){return Qe(t)||t.lvl>t.r.lvl}function Fo(t){return Qe(t.r)?[t.k,t.v]:Fo(t.r)}function Bo(t,s,a,r=Gs,n=Gs){return{k:t,l:r,lvl:a,r:n,v:s}}function fn(t){return ir($o(t))}function $o(t){const{l:s}=t;return!Qe(s)&&s.lvl===t.lvl?st(s,{r:st(t,{l:s.r})}):t}function ir(t){const{lvl:s,r:a}=t;return!Qe(a)&&!Qe(a.r)&&a.lvl===s&&a.r.lvl===s?st(a,{l:st(t,{r:a.l}),lvl:s+1}):t}function Tc(t){return Do(t,({k:s,v:a})=>({index:s,value:a}))}function Oo(t,s){return!!(t&&t.startIndex===s.startIndex&&t.endIndex===s.endIndex)}function Us(t,s){return!!(t&&t[0]===s[0]&&t[1]===s[1])}const jr=Fe(()=>({recalcInProgress:Q(!1)}),[],{singleton:!0});function Po(t,s,a){return t[ya(t,s,a)]}function ya(t,s,a,r=0){let n=t.length-1;for(;r<=n;){const o=Math.floor((r+n)/2),l=t[o],i=a(l,s);if(i===0)return o;if(i===-1){if(n-r<2)return o-1;n=o-1}else{if(n===r)return o;r=o+1}}throw new Error(`Failed binary finding record in array - ${t.join(",")}, searched for ${s}`)}function Ic(t,s,a,r){const n=ya(t,s,r),o=ya(t,a,r,n);return t.slice(n,o+1)}function Yt(t,s){return Math.round(t.getBoundingClientRect()[s])}function Ea(t){return!Qe(t.groupOffsetTree)}function yr({index:t},s){return s===t?0:s=N||o===m)&&(t=or(t,N)):(d=m!==o,c=!0),u>n&&n>=N&&m!==o&&(t=ft(t,n+1,m));d&&(t=ft(t,l,o))}return[t,a]}function Ac(t){return typeof t.groupIndex<"u"}function Mc({offset:t},s){return s===t?0:s0?i+a:i}function _o(t,s){if(!Ea(s))return t;let a=0;for(;s.groupIndices[a]<=t+a;)a++;return t+a}function Ho(t,s,a){if(Ac(t))return s.groupIndices[t.groupIndex]+1;const r=t.index==="LAST"?a:t.index;let n=_o(r,s);return n=Math.max(0,n,Math.min(a,n)),n}function Lc(t,s,a,r=0){return r>0&&(s=Math.max(s,Po(t,r,yr).offset)),Do(Ic(t,s,a,Mc),Fc)}function Dc(t,[s,a,r,n]){s.length>0&&r("received item sizes",s,at.DEBUG);const o=t.sizeTree;let l=o,i=0;if(a.length>0&&Qe(o)&&s.length===2){const m=s[0].size,h=s[1].size;l=a.reduce((w,k)=>ft(ft(w,k,m),k+1,h),l)}else[l,i]=Rc(l,s);if(l===o)return t;const{lastIndex:c,lastOffset:d,lastSize:u,offsetTree:N}=cr(t.offsetTree,i,l,n);return{groupIndices:a,groupOffsetTree:a.reduce((m,h)=>ft(m,h,Ws(h,N,n)),bs()),lastIndex:c,lastOffset:d,lastSize:u,offsetTree:N,sizeTree:l}}function zc(t){return os(t).map(({k:s,v:a},r,n)=>{const o=n[r+1];return{endIndex:o!==void 0?o.k-1:1/0,size:a,startIndex:s}})}function gn(t,s){let a=0,r=0;for(;an.start===r&&(n.end===s||n.end===1/0)&&n.value===a}const $c={offsetHeight:"height",offsetWidth:"width"},$t=Fe(([{log:t},{recalcInProgress:s}])=>{const a=Ae(),r=Ae(),n=ut(r,0),o=Ae(),l=Ae(),i=Q(0),c=Q([]),d=Q(void 0),u=Q(void 0),N=Q(void 0),m=Q(void 0),h=Q((g,b)=>Yt(g,$c[b])),w=Q(void 0),k=Q(0),y=Ec(),f=ut(_(a,Ee(c,t,k),Lt(Dc,y),qe()),y),v=ut(_(c,qe(),Lt((g,b)=>({current:b,prev:g.current}),{current:[],prev:[]}),se(({prev:g})=>g)),[]);de(_(c,ve(g=>g.length>0),Ee(f,k),se(([g,b,T])=>{const z=g.reduce(($,Z,ae)=>ft($,Z,Ws(Z,b.offsetTree,T)||ae),bs());return{...b,groupIndices:g,groupOffsetTree:z}})),f),de(_(r,Ee(f),ve(([g,{lastIndex:b}])=>g[{endIndex:b,size:T,startIndex:g}])),a),de(d,u);const S=ut(_(d,se(g=>g===void 0)),!0);de(_(u,ve(g=>g!==void 0&&Qe(Ke(f).sizeTree)),se(g=>{const b=Ke(N),T=Ke(c).length>0;return b!==void 0&&b!==0?T?[{endIndex:0,size:b,startIndex:0},{endIndex:1,size:g,startIndex:1}]:[]:[{endIndex:0,size:g,startIndex:0}]})),a),de(_(m,ve(g=>g!==void 0&&g.length>0&&Qe(Ke(f).sizeTree)),se(g=>{const b=[];let T=g[0],z=0;for(let $=1;$g!==void 0&&b!==void 0),se(([g,b,T])=>{const z=[];for(let $=0;$({changed:T!==g,sizes:T}),{changed:!1,sizes:y}),se(g=>g.changed)));Oe(_(i,Lt((g,b)=>({diff:g.prev-b,prev:b}),{diff:0,prev:0}),se(g=>g.diff)),g=>{const{groupIndices:b}=Ke(f);if(g>0)Ie(s,!0),Ie(o,g+gn(g,b));else if(g<0){const T=Ke(v);T.length>0&&(g-=gn(-g,T)),Ie(l,g)}}),Oe(_(i,Ee(t)),([g,b])=>{g<0&&b("`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:i},at.ERROR)});const j=gt(o);de(_(o,Ee(f),se(([g,b])=>{const T=b.groupIndices.length>0,z=[],$=b.lastSize;if(T){const Z=Qs(b.sizeTree,0);let ae=0,H=0;for(;ae{let te=re.ranges;return re.prevSize!==0&&(te=[...re.ranges,{endIndex:ne+g-1,size:re.prevSize,startIndex:re.prevIndex}]),{prevIndex:ne+g,prevSize:D,ranges:te}},{prevIndex:g,prevSize:0,ranges:z}).ranges}return os(b.sizeTree).reduce((Z,{k:ae,v:H})=>({prevIndex:ae+g,prevSize:H,ranges:[...Z.ranges,{endIndex:ae+g-1,size:Z.prevSize,startIndex:Z.prevIndex}]}),{prevIndex:0,prevSize:$,ranges:[]}).ranges})),a);const B=gt(_(l,Ee(f,k),se(([g,{offsetTree:b},T])=>{const z=-g;return Ws(z,b,T)})));return de(_(l,Ee(f,k),se(([g,b,T])=>{if(b.groupIndices.length>0){if(Qe(b.sizeTree))return b;let $=bs();const Z=Ke(v);let ae=0,H=0,ee=0;for(;ae<-g;){ee=Z[H];const re=Z[H+1]-ee-1;H++,ae+=re+1}if($=os(b.sizeTree).reduce((re,{k:ne,v:D})=>ft(re,Math.max(0,ne+g),D),$),ae!==-g){const re=Qs(b.sizeTree,ee);$=ft($,0,re);const ne=Et(b.sizeTree,-g+1)[1];$=ft($,1,ne)}return{...b,sizeTree:$,...cr(b.offsetTree,0,$,T)}}const z=os(b.sizeTree).reduce(($,{k:Z,v:ae})=>ft($,Math.max(0,Z+g),ae),bs());return{...b,sizeTree:z,...cr(b.offsetTree,0,z,T)}})),f),{beforeUnshiftWith:j,data:w,defaultItemSize:u,firstItemIndex:i,fixedItemSize:d,fixedGroupSize:N,gap:k,groupIndices:c,heightEstimates:m,itemSize:h,listRefresh:R,shiftWith:l,shiftWithOffset:B,sizeRanges:a,sizes:f,statefulTotalCount:n,totalCount:r,trackItemSizes:S,unshiftWith:o}},Ye(Xt,jr),{singleton:!0});function Oc(t){return t.reduce((s,a)=>(s.groupIndices.push(s.totalCount),s.totalCount+=a+1,s),{groupIndices:[],totalCount:0})}const Go=Fe(([{groupIndices:t,sizes:s,totalCount:a},{headerHeight:r,scrollTop:n}])=>{const o=Ae(),l=Ae(),i=gt(_(o,se(Oc)));return de(_(i,se(c=>c.totalCount)),a),de(_(i,se(c=>c.groupIndices)),t),de(_(Ze(n,s,r),ve(([c,d])=>Ea(d)),se(([c,d,u])=>Et(d.groupOffsetTree,Math.max(c-u,0),"v")[0]),qe(),se(c=>[c])),l),{groupCounts:o,topItemsIndexes:l}},Ye($t,ht)),Jt=Fe(([{log:t}])=>{const s=Q(!1),a=gt(_(s,ve(r=>r),qe()));return Oe(s,r=>{r&&Ke(t)("props updated",{},at.DEBUG)}),{didMount:a,propsReady:s}},Ye(Xt),{singleton:!0}),Pc=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function Qo(t){const s=typeof t=="number"?{index:t}:t;return s.align||(s.align="start"),(!s.behavior||!Pc)&&(s.behavior="auto"),s.offset===void 0&&(s.offset=0),s}const Zs=Fe(([{gap:t,listRefresh:s,sizes:a,totalCount:r},{fixedFooterHeight:n,fixedHeaderHeight:o,footerHeight:l,headerHeight:i,scrollingInProgress:c,scrollTo:d,smoothScrollTargetReached:u,viewportHeight:N},{log:m}])=>{const h=Ae(),w=Ae(),k=Q(0);let y=null,f=null,v=null;function S(){y!==null&&(y(),y=null),v!==null&&(v(),v=null),f&&(clearTimeout(f),f=null),Ie(c,!1)}return de(_(h,Ee(a,N,r,k,i,l,m),Ee(t,o,n),se(([[R,j,B,g,b,T,z,$],Z,ae,H])=>{const ee=Qo(R),{align:re,behavior:ne,offset:D}=ee,te=g-1,J=Ho(ee,j,te);let me=Ws(J,j.offsetTree,Z)+T;re==="end"?(me+=ae+Et(j.sizeTree,J)[1]-B+H,J===te&&(me+=z)):re==="center"?me+=(ae+Et(j.sizeTree,J)[1]-B+H)/2:me-=b,D!==void 0&&D!==0&&(me+=D);const Ce=F=>{S(),F?($("retrying to scroll to",{location:R},at.DEBUG),Ie(h,R)):(Ie(w,!0),$("list did not change, scroll successful",{},at.DEBUG))};if(S(),ne==="smooth"){let F=!1;v=Oe(s,C=>{F=F||C}),y=Tt(u,()=>{Ce(F)})}else y=Tt(_(s,_c(150)),Ce);return f=setTimeout(()=>{S()},1200),Ie(c,!0),$("scrolling from index to",{behavior:ne,index:J,top:me},at.DEBUG),{behavior:ne,top:me}})),d),{scrollTargetReached:w,scrollToIndex:h,topListHeight:k}},Ye($t,ht,Xt),{singleton:!0});function _c(t){return s=>{const a=setTimeout(()=>{s(!1)},t);return r=>{r&&(s(!0),clearTimeout(a))}}}function wr(t,s){t===0?s():requestAnimationFrame(()=>{wr(t-1,s)})}function Sr(t,s){const a=s-1;return typeof t=="number"?t:t.index==="LAST"?a:t.index}const ea=Fe(([{defaultItemSize:t,listRefresh:s,sizes:a},{scrollTop:r},{scrollTargetReached:n,scrollToIndex:o},{didMount:l}])=>{const i=Q(!0),c=Q(0),d=Q(!0);return de(_(l,Ee(c),ve(([u,N])=>N!==0),Mt(!1)),i),de(_(l,Ee(c),ve(([u,N])=>N!==0),Mt(!1)),d),Oe(_(Ze(s,l),Ee(i,a,t,d),ve(([[,u],N,{sizeTree:m},h,w])=>u&&(!Qe(m)||br(h))&&!N&&!w),Ee(c)),([,u])=>{Tt(n,()=>{Ie(d,!0)}),wr(4,()=>{Tt(r,()=>{Ie(i,!0)}),Ie(o,u)})}),{initialItemFinalLocationReached:d,initialTopMostItemIndex:c,scrolledToInitialItem:i}},Ye($t,ht,Zs,Jt),{singleton:!0});function Uo(t,s){return Math.abs(t-s)<1.01}const Vs="up",Fs="down",Hc="none",Gc={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},Qc=0,ta=Fe(([{footerHeight:t,headerHeight:s,scrollBy:a,scrollContainerState:r,scrollTop:n,viewportHeight:o}])=>{const l=Q(!1),i=Q(!0),c=Ae(),d=Ae(),u=Q(4),N=Q(Qc),m=ut(_(nr(_(be(n),ls(1),Mt(!0)),_(be(n),ls(1),Mt(!1),hn(100))),qe()),!1),h=ut(_(nr(_(a,Mt(!0)),_(a,Mt(!1),hn(200))),qe()),!1);de(_(Ze(be(n),be(N)),se(([v,S])=>v<=S),qe()),i),de(_(i,_t(50)),d);const w=gt(_(Ze(r,be(o),be(s),be(t),be(u)),Lt((v,[{scrollHeight:S,scrollTop:R},j,B,g,b])=>{const T=R+j-S>-b,z={scrollHeight:S,scrollTop:R,viewportHeight:j};if(T){let Z,ae;return R>v.state.scrollTop?(Z="SCROLLED_DOWN",ae=v.state.scrollTop-R):(Z="SIZE_DECREASED",ae=v.state.scrollTop-R||v.scrollTopDelta),{atBottom:!0,atBottomBecause:Z,scrollTopDelta:ae,state:z}}let $;return z.scrollHeight>v.state.scrollHeight?$="SIZE_INCREASED":jv!==void 0&&v.atBottom===S.atBottom))),k=ut(_(r,Lt((v,{scrollHeight:S,scrollTop:R,viewportHeight:j})=>{if(!Uo(v.scrollHeight,S)){const B=S-(R+j)<1;return v.scrollTop!==R&&B?{changed:!0,jump:v.scrollTop-R,scrollHeight:S,scrollTop:R}:{changed:!0,jump:0,scrollHeight:S,scrollTop:R}}return{changed:!1,jump:0,scrollHeight:S,scrollTop:R}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),ve(v=>v.changed),se(v=>v.jump)),0);de(_(w,se(v=>v.atBottom)),l),de(_(l,_t(50)),c);const y=Q(Fs);de(_(r,se(({scrollTop:v})=>v),qe(),Lt((v,S)=>Ke(h)?{direction:v.direction,prevScrollTop:S}:{direction:Sv.direction)),y),de(_(r,_t(50),Mt(Hc)),y);const f=Q(0);return de(_(m,ve(v=>!v),Mt(0)),f),de(_(n,_t(100),Ee(m),ve(([v,S])=>S),Lt(([v,S],[R])=>[S,R],[0,0]),se(([v,S])=>S-v)),f),{atBottomState:w,atBottomStateChange:c,atBottomThreshold:u,atTopStateChange:d,atTopThreshold:N,isAtBottom:l,isAtTop:i,isScrolling:m,lastJumpDueToItemResize:k,scrollDirection:y,scrollVelocity:f}},Ye(ht)),qs="top",Ys="bottom",bn="none";function vn(t,s,a){return typeof t=="number"?a===Vs&&s===qs||a===Fs&&s===Ys?t:0:a===Vs?s===qs?t.main:t.reverse:s===Ys?t.main:t.reverse}function Nn(t,s){return typeof t=="number"?t:t[s]??0}const kr=Fe(([{deviation:t,fixedHeaderHeight:s,headerHeight:a,scrollTop:r,viewportHeight:n}])=>{const o=Ae(),l=Q(0),i=Q(0),c=Q(0),d=ut(_(Ze(be(r),be(n),be(a),be(o,Us),be(c),be(l),be(s),be(t),be(i)),se(([u,N,m,[h,w],k,y,f,v,S])=>{const R=u-v,j=y+f,B=Math.max(m-R,0);let g=bn;const b=Nn(S,qs),T=Nn(S,Ys);return h-=v,h+=m+f,w+=m+f,w-=v,h>u+j-b&&(g=Vs),wu!==null),qe(Us)),[0,0]);return{increaseViewportBy:i,listBoundary:o,overscan:c,topListHeight:l,visibleRange:d}},Ye(ht),{singleton:!0});function Uc(t,s,a){if(Ea(s)){const r=_o(t,s);return[{index:Et(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 Ga={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function ha(t,s,a,r,n,o){const{lastIndex:l,lastOffset:i,lastSize:c}=n;let d=0,u=0;if(t.length>0){d=t[0].offset;const k=t[t.length-1];u=k.offset+k.size}const N=a-l,m=i+N*c+(N-1)*r,h=d,w=m-u;return{bottom:u,firstItemIndex:o,items:jn(t,n,o),offsetBottom:w,offsetTop:d,top:h,topItems:jn(s,n,o),topListHeight:s.reduce((k,y)=>y.size+k,0),totalCount:a}}function Wo(t,s,a,r,n,o){let l=0;if(a.groupIndices.length>0)for(const u of a.groupIndices){if(u-l>=t)break;l++}const i=t+l,c=Sr(s,i),d=Array.from({length:i}).map((u,N)=>({data:o[N+c],index:N+c,offset:0,size:0}));return ha(d,[],i,n,a,r)}function jn(t,s,a){if(t.length===0)return[];if(!Ea(s))return t.map(d=>({...d,index:d.index+a,originalIndex:d.index}));const r=t[0].index,n=t[t.length-1].index,o=[],l=vs(s.groupOffsetTree,r,n);let i,c=0;for(const d of t){(!i||i.end{const k=Q([]),y=Q(0),f=Ae(),v=Q(0);de(o.topItemsIndexes,k);const S=ut(_(Ze(h,w,be(c,Us),be(n),be(r),be(d),u,be(k),be(s),be(a),be(v),t),ve(([g,b,,T,,,,,,,,z])=>{const $=z!==void 0&&z.length!==T;return g&&!b&&!$}),se(([,,[g,b],T,z,$,Z,ae,H,ee,re,ne])=>{const D=z,{offsetTree:te,sizeTree:J}=D,me=Ke(y);if(T===0)return{...Ga,totalCount:T};if(g===0&&b===0)return me===0?{...Ga,totalCount:T}:Wo(me,$,z,H,ee,ne||[]);if(Qe(J))return me>0?null:ha(Uc(Sr($,T),D,ne),[],T,ee,D,H);const Ce=[];if(ae.length>0){const G=ae[0],X=ae[ae.length-1];let le=0;for(const ie of vs(J,G,X)){const V=ie.value,we=Math.max(ie.start,G),Pe=Math.min(ie.end,X);for(let ke=we;ke<=Pe;ke++)Ce.push({data:ne?.[ke],index:ke,offset:le,size:V}),le+=V}}if(!Z)return ha([],Ce,T,ee,D,H);const F=ae.length>0?ae[ae.length-1]+1:0,C=Lc(te,g,b,F);if(C.length===0)return null;const K=T-1,P=Ia([],G=>{for(const X of C){const le=X.value;let ie=le.offset,V=X.start;const we=le.size;if(le.offset=b);ke++)G.push({data:ne?.[ke],index:ke,offset:ie,size:we}),ie+=we+ee}}),xe=yn(re,qs),M=yn(re,Ys);if(P.length>0&&(xe>0||M>0)){const G=P[0],X=P[P.length-1];if(xe>0&&G.index>F){const le=Math.min(xe,G.index-F),ie=[];let V=G.offset;for(let we=G.index-1;we>=G.index-le;we--){const Pe=vs(J,we,we)[0]?.value??G.size;V-=Pe+ee,ie.unshift({data:ne?.[we],index:we,offset:V,size:Pe})}P.unshift(...ie)}if(M>0&&X.indexg!==null),qe()),Ga);de(_(t,ve(br),se(g=>g?.length)),n),de(_(S,se(g=>g.topListHeight)),N),de(N,i),de(_(S,se(g=>[g.top,g.bottom])),l),de(_(S,se(g=>g.items)),f);const R=gt(_(S,ve(({items:g})=>g.length>0),Ee(n,t),ve(([{items:g},b])=>g[g.length-1].originalIndex===b-1),se(([,g,b])=>[g-1,b]),qe(Us),se(([g])=>g))),j=gt(_(S,_t(200),ve(({items:g,topItems:b})=>g.length>0&&g[0].originalIndex===b.length),se(({items:g})=>g[0].index),qe())),B=gt(_(S,ve(({items:g})=>g.length>0),se(({items:g})=>{let b=0,T=g.length-1;for(;g[b].type==="group"&&bb;)T--;return{endIndex:g[T].index,startIndex:g[b].index}}),qe(Oo)));return{endReached:R,initialItemCount:y,itemsRendered:f,listState:S,minOverscanItemCount:v,rangeChanged:B,startReached:j,topItemsIndexes:k,...m}},Ye($t,Go,kr,ea,Zs,ta,Jt,jr),{singleton:!0}),Vo=Fe(([{fixedFooterHeight:t,fixedHeaderHeight:s,footerHeight:a,headerHeight:r},{listState:n}])=>{const o=Ae(),l=ut(_(Ze(a,t,r,s,n),se(([i,c,d,u,N])=>i+c+d+u+N.offsetBottom+N.bottom)),0);return de(be(l),o),{totalListHeight:l,totalListHeightChanged:o}},Ye(ht,cs),{singleton:!0}),Wc=Fe(([{viewportHeight:t},{totalListHeight:s}])=>{const a=Q(!1),r=ut(_(Ze(a,t,s),ve(([n])=>n),se(([,n,o])=>Math.max(0,n-o)),_t(0),qe()),0);return{alignToBottom:a,paddingTopAddition:r}},Ye(ht,Vo),{singleton:!0}),qo=Fe(()=>({context:Q(null)})),Vc=({itemBottom:t,itemTop:s,locationParams:{align:a,behavior:r,...n},viewportBottom:o,viewportTop:l})=>so?{...n,align:a??"end",...r!==void 0?{behavior:r}:{}}:null,Yo=Fe(([{gap:t,sizes:s,totalCount:a},{fixedFooterHeight:r,fixedHeaderHeight:n,headerHeight:o,scrollingInProgress:l,scrollTop:i,viewportHeight:c},{scrollToIndex:d}])=>{const u=Ae();return de(_(u,Ee(s,c,a,o,n,r,i),Ee(t),se(([[N,m,h,w,k,y,f,v],S])=>{const{calculateViewLocation:R=Vc,done:j,...B}=N,g=Ho(N,m,w-1),b=Ws(g,m.offsetTree,S)+k+y,T=b+Et(m.sizeTree,g)[1],z=v+y,$=v+h-f,Z=R({itemBottom:T,itemTop:b,locationParams:B,viewportBottom:$,viewportTop:z});return Z!==null?j&&Tt(_(l,ve(ae=>!ae),ls(Ke(l)?1:2)),j):j?.(),Z}),ve(N=>N!==null)),d),{scrollIntoView:u}},Ye($t,ht,Zs,cs,Xt),{singleton:!0});function wn(t){return t===!1?!1:t==="smooth"?"smooth":"auto"}const qc=(t,s)=>typeof t=="function"?wn(t(s)):s&&wn(t),Yc=Fe(([{listRefresh:t,totalCount:s,fixedItemSize:a,data:r},{atBottomState:n,isAtBottom:o},{scrollToIndex:l},{scrolledToInitialItem:i},{didMount:c,propsReady:d},{log:u},{scrollingInProgress:N},{context:m},{scrollIntoView:h}])=>{const w=Q(!1),k=Ae();let y=null;function f(j){Ie(l,{align:"end",behavior:j,index:"LAST"})}Oe(_(Ze(_(be(s),ls(1)),c),Ee(be(w),o,i,N),se(([[j,B],g,b,T,z])=>{let $=B&&T,Z="auto";return $&&(Z=qc(g,b||z),$=$&&Z!==!1),{followOutputBehavior:Z,shouldFollow:$,totalCount:j}}),ve(({shouldFollow:j})=>j)),({followOutputBehavior:j,totalCount:B})=>{y!==null&&(y(),y=null),Ke(a)!==void 0?requestAnimationFrame(()=>{Ke(u)("following output to ",{totalCount:B},at.DEBUG),f(j)}):y=Tt(t,()=>{Ke(u)("following output to ",{totalCount:B},at.DEBUG),f(j),y=null})});function v(j){const B=Tt(n,g=>{j&&!g.atBottom&&g.notAtBottomBecause==="SIZE_INCREASED"&&y===null&&(Ke(u)("scrolling to bottom due to increased size",{},at.DEBUG),f("auto"))});setTimeout(B,100)}Oe(_(Ze(be(w),s,d),ve(([j,,B])=>j!==!1&&B),Lt(({value:j},[,B])=>({refreshed:j===B,value:B}),{refreshed:!1,value:0}),ve(({refreshed:j})=>j),Ee(w,s)),([,j])=>{Ke(i)&&v(j!==!1)}),Oe(k,()=>{v(Ke(w)!==!1)}),Oe(Ze(be(w),n),([j,B])=>{j!==!1&&!B.atBottom&&B.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&f("auto")});const S=Q(null),R=Ae();return de(nr(_(be(r),se(j=>j?.length??0)),_(be(s))),R),Oe(_(Ze(_(R,ls(1)),c),Ee(be(S),i,N,m),se(([[j,B],g,b,T,z])=>B&&b&&g?.({context:z,totalCount:j,scrollingInProgress:T})),ve(j=>!!j),_t(0)),j=>{y!==null&&(y(),y=null),Ke(a)!==void 0?requestAnimationFrame(()=>{Ke(u)("scrolling into view",{}),Ie(h,j)}):y=Tt(t,()=>{Ke(u)("scrolling into view",{}),Ie(h,j),y=null})}),{autoscrollToBottom:k,followOutput:w,scrollIntoViewOnChange:S}},Ye($t,ta,Zs,ea,Jt,Xt,ht,qo,Yo)),Kc=Fe(([{data:t,firstItemIndex:s,gap:a,sizes:r},{initialTopMostItemIndex:n},{initialItemCount:o,listState:l},{didMount:i}])=>(de(_(i,Ee(o),ve(([,c])=>c!==0),Ee(n,r,s,a,t),se(([[,c],d,u,N,m,h=[]])=>Wo(c,d,u,N,m,h))),l),{}),Ye($t,ea,cs,Jt),{singleton:!0}),Xc=Fe(([{didMount:t},{scrollTo:s},{listState:a}])=>{const r=Q(0);return Oe(_(t,Ee(r),ve(([,n])=>n!==0),se(([,n])=>({top:n}))),n=>{Tt(_(a,ls(1),ve(o=>o.items.length>1)),()=>{requestAnimationFrame(()=>{Ie(s,n)})})}),{initialScrollTop:r}},Ye(Jt,ht,cs),{singleton:!0}),Ko=Fe(([{scrollVelocity:t}])=>{const s=Q(!1),a=Ae(),r=Q(!1);return de(_(t,Ee(r,s,a),ve(([n,o])=>o!==!1&&o!==void 0),se(([n,o,l,i])=>{const{enter:c,exit:d}=o;if(l){if(d(n,i))return!1}else if(c(n,i))return!0;return l}),qe()),s),Oe(_(Ze(s,t,a),Ee(r)),([[n,o,l],i])=>{n&&i!==!1&&i!==void 0&&i.change&&i.change(o,l)}),{isSeeking:s,scrollSeekConfiguration:r,scrollSeekRangeChanged:a,scrollVelocity:t}},Ye(ta),{singleton:!0}),Cr=Fe(([{scrollContainerState:t,scrollTo:s}])=>{const a=Ae(),r=Ae(),n=Ae(),o=Q(!1),l=Q(void 0);return de(_(Ze(a,r),se(([{scrollTop:i,viewportHeight:c},{offsetTop:d,listHeight:u}])=>({scrollHeight:u,scrollTop:Math.max(0,i-d),viewportHeight:c}))),t),de(_(s,Ee(r),se(([i,{offsetTop:c}])=>({...i,top:i.top+c}))),n),{customScrollParent:l,useWindowScroll:o,windowScrollContainerState:a,windowScrollTo:n,windowViewportRect:r}},Ye(ht)),Jc=Fe(([{sizeRanges:t,sizes:s},{headerHeight:a,scrollTop:r},{initialTopMostItemIndex:n},{didMount:o},{useWindowScroll:l,windowScrollContainerState:i,windowViewportRect:c}])=>{const d=Ae(),u=Q(void 0),N=Q(null),m=Q(null);return de(i,N),de(c,m),Oe(_(d,Ee(s,r,l,N,m,a)),([h,w,k,y,f,v,S])=>{const R=zc(w.sizeTree);y&&f!==null&&v!==null&&(k=f.scrollTop-v.offsetTop),k-=S,h({ranges:R,scrollTop:k})}),de(_(u,ve(br),se(Zc)),n),de(_(o,Ee(u),ve(([,h])=>h!==void 0),qe(),se(([,h])=>h.ranges)),t),{getState:d,restoreStateFrom:u}},Ye($t,ht,ea,Jt,Cr));function Zc(t){return{align:"start",index:0,offset:t.scrollTop}}const ed=Fe(([{topItemsIndexes:t}])=>{const s=Q(0);return de(_(s,ve(a=>a>=0),se(a=>Array.from({length:a}).map((r,n)=>n))),t),{topItemCount:s}},Ye(cs));function Xo(t){let s=!1,a;return(()=>(s||(s=!0,a=t()),a))}const td=Xo(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),sd=Fe(([{deviation:t,scrollBy:s,scrollingInProgress:a,scrollTop:r},{isAtBottom:n,isScrolling:o,lastJumpDueToItemResize:l,scrollDirection:i},{listState:c},{beforeUnshiftWith:d,gap:u,shiftWithOffset:N,sizes:m},{log:h},{recalcInProgress:w}])=>{const k=gt(_(c,Ee(l),Lt(([,f,v,S],[{bottom:R,items:j,offsetBottom:B,totalCount:g},b])=>{const T=R+B;let z=0;return v===g&&f.length>0&&j.length>0&&(j[0].originalIndex===0&&f[0].originalIndex===0||(z=T-S,z!==0&&(z+=b))),[z,j,g,T]},[0,[],0,0]),ve(([f])=>f!==0),Ee(r,i,a,n,h,w),ve(([,f,v,S,,,R])=>!R&&!S&&f!==0&&v===Vs),se(([[f],,,,,v])=>(v("Upward scrolling compensation",{amount:f},at.DEBUG),f))));function y(f){f>0?(Ie(s,{behavior:"auto",top:-f}),Ie(t,0)):(Ie(t,0),Ie(s,{behavior:"auto",top:-f}))}return Oe(_(k,Ee(t,o)),([f,v,S])=>{S&&td()?Ie(t,v-f):y(-f)}),Oe(_(Ze(ut(o,!1),t,w),ve(([f,v,S])=>!f&&!S&&v!==0),se(([f,v])=>v),_t(1)),y),de(_(N,se(f=>({top:-f}))),s),Oe(_(d,Ee(m,u),se(([f,{groupIndices:v,lastSize:S,sizeTree:R},j])=>{function B($){return $*(S+j)}if(v.length===0)return B(f);let g=0;const b=Qs(R,0);let T=0,z=0;for(;Tf&&(g-=b,$=f-T+1),T+=$,g+=B($),z++}return g})),f=>{Ie(t,f),requestAnimationFrame(()=>{Ie(s,{top:f}),requestAnimationFrame(()=>{Ie(t,0),Ie(w,!1)})})}),{deviation:t}},Ye(ht,ta,cs,$t,Xt,jr)),ad=Fe(([t,s,a,r,n,o,l,i,c,d,u])=>({...t,...s,...a,...r,...n,...o,...l,...i,...c,...d,...u}),Ye(kr,Kc,Jt,Ko,Vo,Xc,Wc,Cr,Yo,Xt,qo)),Jo=Fe(([{data:t,defaultItemSize:s,firstItemIndex:a,fixedItemSize:r,fixedGroupSize:n,gap:o,groupIndices:l,heightEstimates:i,itemSize:c,sizeRanges:d,sizes:u,statefulTotalCount:N,totalCount:m,trackItemSizes:h},{initialItemFinalLocationReached:w,initialTopMostItemIndex:k,scrolledToInitialItem:y},f,v,S,R,{scrollToIndex:j},B,{topItemCount:g},{groupCounts:b},T])=>{const{listState:z,minOverscanItemCount:$,topItemsIndexes:Z,rangeChanged:ae,...H}=R;return de(ae,T.scrollSeekRangeChanged),de(_(T.windowViewportRect,se(ee=>ee.visibleHeight)),f.viewportHeight),{data:t,defaultItemHeight:s,firstItemIndex:a,fixedItemHeight:r,fixedGroupHeight:n,gap:o,groupCounts:b,heightEstimates:i,initialItemFinalLocationReached:w,initialTopMostItemIndex:k,scrolledToInitialItem:y,sizeRanges:d,topItemCount:g,topItemsIndexes:Z,totalCount:m,...S,groupIndices:l,itemSize:c,listState:z,minOverscanItemCount:$,scrollToIndex:j,statefulTotalCount:N,trackItemSizes:h,rangeChanged:ae,...H,...T,...f,sizes:u,...v}},Ye($t,ea,ht,Jc,Yc,cs,Zs,sd,ed,Go,ad));function rd(t,s){const a={},r={};let n=0;const o=t.length;for(;n(f[v]=S=>{const R=y[s.methods[v]];Ie(R,S)},f),{})}function u(y){return l.reduce((f,v)=>(f[v]=Nc(y[s.events[v]]),f),{})}const N=oe.forwardRef(function(y,f){const{children:v,...S}=y,[R]=oe.useState(()=>Ia(yc(t),g=>{c(g,S)})),[j]=oe.useState(xn(u,R));la(()=>{for(const g of l)g in S&&Oe(j[g],S[g]);return()=>{Object.values(j).map(vr)}},[S,j,R]),la(()=>{c(R,S)}),oe.useImperativeHandle(f,un(d(R)));const B=a;return e.jsx(i.Provider,{value:R,children:a!==void 0?e.jsx(B,{...rd([...r,...n,...l],S),children:v}):v})}),m=y=>{const f=oe.useContext(i);return oe.useCallback(v=>{Ie(f[y],v)},[f,y])},h=y=>{const f=oe.useContext(i)[y],v=oe.useCallback(S=>Oe(f,S),[f]);return oe.useSyncExternalStore(v,()=>Ke(f),()=>Ke(f))},w=y=>{const f=oe.useContext(i)[y],[v,S]=oe.useState(xn(Ke,f));return la(()=>Oe(f,R=>{R!==v&&S(un(R))}),[f,v]),v},k=parseInt(oe.version)>=18?h:w;return{Component:N,useEmitter:(y,f)=>{const v=oe.useContext(i)[y];la(()=>Oe(v,f),[f,v])},useEmitterValue:k,usePublisher:m}}const el=oe.createContext(void 0),tl=oe.createContext(void 0),Qa="-webkit-sticky",Sn="sticky",Tr=Xo(()=>{if(typeof document>"u")return Sn;const t=document.createElement("div");return t.style.position=Qa,t.style.position===Qa?Qa:Sn}),sl=typeof document<"u"?oe.useLayoutEffect:oe.useEffect;function Ua(t){return"self"in t}function nd(t){return"body"in t}function al(t,s,a,r=ys,n,o){const l=oe.useRef(null),i=oe.useRef(null),c=oe.useRef(null),d=oe.useCallback(m=>{let h,w,k;const y=m.target;if(nd(y)||Ua(y)){const v=Ua(y)?y:y.defaultView;k=o===!0?v.scrollX:v.scrollY,h=o===!0?v.document.documentElement.scrollWidth:v.document.documentElement.scrollHeight,w=o===!0?v.innerWidth:v.innerHeight}else k=o===!0?y.scrollLeft:y.scrollTop,h=o===!0?y.scrollWidth:y.scrollHeight,w=o===!0?y.offsetWidth:y.offsetHeight;const f=()=>{t({scrollHeight:h,scrollTop:Math.max(k,0),viewportHeight:w})};m.suppressFlushSync===!0?f():ri.flushSync(f),i.current!==null&&(k===i.current||k<=0||k===h-w)&&(i.current=null,s(!0),c.current&&(clearTimeout(c.current),c.current=null))},[t,s,o]);oe.useEffect(()=>{const m=n||l.current;return r(n||l.current),d({suppressFlushSync:!0,target:m}),m.addEventListener("scroll",d,{passive:!0}),()=>{r(null),m.removeEventListener("scroll",d)}},[l,d,a,r,n]);function u(m){const h=l.current;if(!h||(o===!0?"offsetWidth"in h&&h.offsetWidth===0:"offsetHeight"in h&&h.offsetHeight===0))return;const w=m.behavior==="smooth";let k,y,f;Ua(h)?(y=Math.max(Yt(h.document.documentElement,o===!0?"width":"height"),o===!0?h.document.documentElement.scrollWidth:h.document.documentElement.scrollHeight),k=o===!0?h.innerWidth:h.innerHeight,f=o===!0?window.scrollX:window.scrollY):(y=h[o===!0?"scrollWidth":"scrollHeight"],k=Yt(h,o===!0?"width":"height"),f=h[o===!0?"scrollLeft":"scrollTop"]);const v=y-k;if(m.top=Math.ceil(Math.max(Math.min(v,m.top),0)),Uo(k,y)||m.top===f){t({scrollHeight:y,scrollTop:f,viewportHeight:k}),w&&s(!0);return}w?(i.current=m.top,c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{c.current=null,i.current=null,s(!0)},1e3)):i.current=null,o===!0&&(m={...m.behavior!==void 0?{behavior:m.behavior}:{},left:m.top}),h.scrollTo(m)}function N(m){o===!0&&(m={...m.behavior!==void 0?{behavior:m.behavior}:{},...m.top!==void 0?{left:m.top}:{}}),l.current.scrollBy(m)}return{scrollByCallback:N,scrollerRef:l,scrollToCallback:u}}function Ir(t){return t}const od=Fe(()=>{const t=Q(i=>`Item ${i}`),s=Q(i=>`Group ${i}`),a=Q({}),r=Q(Ir),n=Q("div"),o=Q(ys),l=(i,c=null)=>ut(_(a,se(d=>d[i]),qe()),c);return{components:a,computeItemKey:r,EmptyPlaceholder:l("EmptyPlaceholder"),FooterComponent:l("Footer"),GroupComponent:l("Group","div"),groupContent:s,HeaderComponent:l("Header"),HeaderFooterTag:n,ItemComponent:l("Item","div"),itemContent:t,ListComponent:l("List","div"),ScrollerComponent:l("Scroller","div"),scrollerRef:o,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder"),TopItemListComponent:l("TopItemList")}}),ld=Fe(([t,s])=>({...t,...s}),Ye(Jo,od)),id=({height:t})=>e.jsx("div",{style:{height:t}}),cd={overflowAnchor:"none",position:Tr(),zIndex:1},rl={overflowAnchor:"none"},dd={...rl,display:"inline-block",height:"100%"},kn=oe.memo(function({showTopList:t=!1}){const s=ye("listState"),a=Nt("sizeRanges"),r=ye("useWindowScroll"),n=ye("customScrollParent"),o=Nt("windowScrollContainerState"),l=Nt("scrollContainerState"),i=n||r?o:l,c=ye("itemContent"),d=ye("context"),u=ye("groupContent"),N=ye("trackItemSizes"),m=ye("itemSize"),h=ye("log"),w=Nt("gap"),k=ye("horizontalDirection"),{callbackRef:y}=kc(a,m,N,t?ys:i,h,w,n,k,ye("skipAnimationFrameInResizeObserver")),[f,v]=oe.useState(0);Rr("deviation",H=>{f!==H&&v(H)});const S=ye("EmptyPlaceholder"),R=ye("ScrollSeekPlaceholder")??id,j=ye("ListComponent"),B=ye("ItemComponent"),g=ye("GroupComponent"),b=ye("computeItemKey"),T=ye("isSeeking"),z=ye("groupIndices").length>0,$=ye("alignToBottom"),Z=ye("initialItemFinalLocationReached"),ae=t?{}:{boxSizing:"border-box",...k?{display:"inline-block",height:"100%",marginLeft:f!==0?f:$?"auto":0,paddingLeft:s.offsetTop,paddingRight:s.offsetBottom,whiteSpace:"nowrap"}:{marginTop:f!==0?f:$?"auto":0,paddingBottom:s.offsetBottom,paddingTop:s.offsetTop},...Z?{}:{visibility:"hidden"}};return!t&&s.totalCount===0&&S!==null&&S!==void 0?e.jsx(S,{...mt(S,d)}):e.jsx(j,{...mt(j,d),"data-testid":t?"virtuoso-top-item-list":"virtuoso-item-list",ref:y,style:ae,children:(t?s.topItems:s.items).map(H=>{const ee=H.originalIndex,re=b(ee+s.firstItemIndex,H.data,d);return T?p.createElement(R,{...mt(R,d),height:H.size,index:H.index,key:re,type:H.type||"item",...H.type==="group"?{}:{groupIndex:H.groupIndex}}):H.type==="group"?p.createElement(g,{...mt(g,d),"data-index":ee,"data-item-index":H.index,"data-known-size":H.size,key:re,style:cd},u(H.index,d)):p.createElement(B,{...mt(B,d),...hd(B,H.data),"data-index":ee,"data-item-group-index":H.groupIndex,"data-item-index":H.index,"data-known-size":H.size,key:re,style:k?dd:rl},z?c(H.index,H.groupIndex,H.data,d):c(H.index,H.data,d))})})}),md={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},ud={outline:"none",overflowX:"auto",position:"relative"},Er=t=>({height:"100%",position:"absolute",top:0,width:"100%",...t?{display:"flex",flexDirection:"column"}:void 0}),nl=(t,s,a=0)=>({...Er(t),position:s?"relative":"absolute",top:s?-a:0}),xd={position:Tr(),top:0,width:"100%",zIndex:1};function mt(t,s){if(typeof t!="string")return{context:s}}function hd(t,s){return{item:typeof t=="string"?void 0:s}}const pd=oe.memo(function(){const t=ye("HeaderComponent"),s=Nt("headerHeight"),a=ye("HeaderFooterTag"),r=is(oe.useMemo(()=>o=>{s(Yt(o,"height"))},[s]),!0,ye("skipAnimationFrameInResizeObserver")),n=ye("context");return t!=null?e.jsx(a,{ref:r,children:e.jsx(t,{...mt(t,n)})}):null}),fd=oe.memo(function(){const t=ye("FooterComponent"),s=Nt("footerHeight"),a=ye("HeaderFooterTag"),r=is(oe.useMemo(()=>o=>{s(Yt(o,"height"))},[s]),!0,ye("skipAnimationFrameInResizeObserver")),n=ye("context");return t!=null?e.jsx(a,{ref:r,children:e.jsx(t,{...mt(t,n)})}):null});function ol({useEmitter:t,useEmitterValue:s,usePublisher:a}){return oe.memo(function({children:r,style:n,context:o,...l}){const i=a("scrollContainerState"),c=s("ScrollerComponent"),d=a("smoothScrollTargetReached"),u=s("scrollerRef"),N=s("horizontalDirection")||!1,{scrollByCallback:m,scrollerRef:h,scrollToCallback:w}=al(i,d,c,u,void 0,N);return t("scrollTo",w),t("scrollBy",m),e.jsx(c,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:h,style:{...N?ud:md,...n},tabIndex:0,...l,...mt(c,o),children:r})})}function ll({useEmitter:t,useEmitterValue:s,usePublisher:a}){return oe.memo(function({children:r,style:n,context:o,...l}){const i=a("windowScrollContainerState"),c=s("ScrollerComponent"),d=a("smoothScrollTargetReached"),u=s("totalListHeight"),N=s("deviation"),m=s("customScrollParent"),h=oe.useRef(null),w=s("scrollerRef"),{scrollByCallback:k,scrollerRef:y,scrollToCallback:f}=al(i,d,c,w,m);return sl(()=>(y.current=m||h.current?.ownerDocument.defaultView,()=>{y.current=null}),[y,m]),t("windowScrollTo",f),t("scrollBy",k),e.jsx(c,{ref:h,"data-virtuoso-scroller":!0,style:{position:"relative",...n,...u!==0?{height:u+N}:void 0},...l,...mt(c,o),children:r})})}const gd=({children:t})=>{const s=oe.useContext(el),a=Nt("viewportHeight"),r=Nt("fixedItemHeight"),n=ye("alignToBottom"),o=ye("horizontalDirection"),l=oe.useMemo(()=>Ao(a,c=>Yt(c,o?"width":"height")),[a,o]),i=is(l,!0,ye("skipAnimationFrameInResizeObserver"));return oe.useEffect(()=>{s&&(a(s.viewportHeight),r(s.itemHeight))},[s,a,r]),e.jsx("div",{"data-viewport-type":"element",ref:i,style:Er(n),children:t})},bd=({children:t})=>{const s=oe.useContext(el),a=Nt("windowViewportRect"),r=Nt("fixedItemHeight"),n=ye("customScrollParent"),o=ye("useWindowScroll"),l=ye("topListHeight"),i=Lo(a,n,ye("skipAnimationFrameInResizeObserver")),c=ye("alignToBottom");return oe.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:i,style:nl(c,o,l),children:t})},vd=({children:t})=>{const s=ye("TopItemListComponent")??"div",a=ye("headerHeight"),r={...xd,marginTop:`${a}px`},n=ye("context");return e.jsx(s,{style:r,...mt(s,n),children:t})},Nd=oe.memo(function(t){const s=ye("useWindowScroll"),a=ye("topItemsIndexes").length>0,r=ye("customScrollParent"),n=ye("context");return e.jsxs(r||s?wd:yd,{...t,context:n,children:[a&&e.jsx(vd,{children:e.jsx(kn,{showTopList:!0})}),e.jsxs(r||s?bd:gd,{children:[e.jsx(pd,{}),e.jsx(kn,{}),e.jsx(fd,{})]})]})}),{Component:jd,useEmitter:Rr,useEmitterValue:ye,usePublisher:Nt}=Zo(ld,{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"}},Nd),yd=ol({useEmitter:Rr,useEmitterValue:ye,usePublisher:Nt}),wd=ll({useEmitter:Rr,useEmitterValue:ye,usePublisher:Nt}),Sd=jd,kd=Fe(()=>{const t=Q(d=>e.jsxs("td",{children:["Item $",d]})),s=Q(null),a=Q(d=>e.jsxs("td",{colSpan:1e3,children:["Group ",d]})),r=Q(null),n=Q(null),o=Q({}),l=Q(Ir),i=Q(ys),c=(d,u=null)=>ut(_(o,se(N=>N[d]),qe()),u);return{components:o,computeItemKey:l,context:s,EmptyPlaceholder:c("EmptyPlaceholder"),FillerRow:c("FillerRow"),fixedFooterContent:n,fixedHeaderContent:r,itemContent:t,groupContent:a,ScrollerComponent:c("Scroller","div"),scrollerRef:i,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")}});Ye(Jo,kd);Tr();const Cn={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},Cd={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:Tn,floor:wa,max:Bs,min:Wa,round:In}=Math;function En(t,s,a){return Array.from({length:s-t+1}).map((r,n)=>({data:a===null?null:a[n+t],index:n+t}))}function Td(t){return{...Cd,items:t}}function ia(t,s){return t!==void 0&&t.width===s.width&&t.height===s.height}function Id(t,s){return t!==void 0&&t.column===s.column&&t.row===s.row}const Ed=Fe(([{increaseViewportBy:t,listBoundary:s,overscan:a,visibleRange:r},{footerHeight:n,headerHeight:o,scrollBy:l,scrollContainerState:i,scrollTo:c,scrollTop:d,smoothScrollTargetReached:u,viewportHeight:N},m,h,{didMount:w,propsReady:k},{customScrollParent:y,useWindowScroll:f,windowScrollContainerState:v,windowScrollTo:S,windowViewportRect:R},j])=>{const B=Q(0),g=Q(0),b=Q(Cn),T=Q({height:0,width:0}),z=Q({height:0,width:0}),$=Ae(),Z=Ae(),ae=Q(0),H=Q(null),ee=Q({column:0,row:0}),re=Ae(),ne=Ae(),D=Q(!1),te=Q(0),J=Q(!0),me=Q(!1),Ce=Q(!1);Oe(_(w,Ee(te),ve(([M,G])=>G!==0)),()=>{Ie(J,!1)}),Oe(_(Ze(w,J,z,T,te,me),ve(([M,G,X,le,,ie])=>M&&!G&&X.height!==0&&le.height!==0&&!ie)),([,,,,M])=>{Ie(me,!0),wr(1,()=>{Ie($,M)}),Tt(_(d),()=>{Ie(s,[0,0]),Ie(J,!0)})}),de(_(ne,ve(M=>M!=null&&M.scrollTop>0),Mt(0)),g),Oe(_(w,Ee(ne),ve(([,M])=>M!=null)),([,M])=>{M&&(Ie(T,M.viewport),Ie(z,M.item),Ie(ee,M.gap),M.scrollTop>0&&(Ie(D,!0),Tt(_(d,ls(1)),G=>{Ie(D,!1)}),Ie(c,{top:M.scrollTop})))}),de(_(T,se(({height:M})=>M)),N),de(_(Ze(be(T,ia),be(z,ia),be(ee,(M,G)=>M!==void 0&&M.column===G.column&&M.row===G.row),be(d)),se(([M,G,X,le])=>({gap:X,item:G,scrollTop:le,viewport:M}))),re),de(_(Ze(be(B),r,be(ee,Id),be(z,ia),be(T,ia),be(H),be(g),be(D),be(J),be(te)),ve(([,,,,,,,M])=>!M),se(([M,[G,X],le,ie,V,we,Pe,,ke,O])=>{const{column:q,row:E}=le,{height:W,width:je}=ie,{width:pe}=V;if(Pe===0&&(M===0||pe===0))return Cn;if(je===0){const Xe=Sr(O,M),U=Xe+Math.max(Pe-1,0);return Td(En(Xe,U,we))}const De=il(pe,je,q);let fe,Me;ke?G===0&&X===0&&Pe>0?(fe=0,Me=Pe-1):(fe=De*wa((G+E)/(W+E)),Me=De*Tn((X+E)/(W+E))-1,Me=Wa(M-1,Bs(Me,De-1)),fe=Wa(Me,Bs(0,fe))):(fe=0,Me=-1);const I=En(fe,Me,we),{bottom:Y,top:ge}=Rn(V,le,ie,I),He=Tn(M/De),Je=He*W+(He-1)*E-Y;return{bottom:Y,itemHeight:W,items:I,itemWidth:je,offsetBottom:Je,offsetTop:ge,top:ge}})),b),de(_(H,ve(M=>M!==null),se(M=>M.length)),B),de(_(Ze(T,z,b,ee),ve(([M,G,{items:X}])=>X.length>0&&G.height!==0&&M.height!==0),se(([M,G,{items:X},le])=>{const{bottom:ie,top:V}=Rn(M,le,G,X);return[V,ie]}),qe(Us)),s);const F=Q(!1);de(_(d,Ee(F),se(([M,G])=>G||M!==0)),F);const C=gt(_(Ze(b,B),ve(([{items:M}])=>M.length>0),Ee(F),ve(([[M,G],X])=>{const le=M.items[M.items.length-1].index===G-1;return(X||M.bottom>0&&M.itemHeight>0&&M.offsetBottom===0&&M.items.length===G)&&le}),se(([[,M]])=>M-1),qe())),K=gt(_(be(b),ve(({items:M})=>M.length>0&&M[0].index===0),Mt(0),qe())),P=gt(_(be(b),Ee(D),ve(([{items:M},G])=>M.length>0&&!G),se(([{items:M}])=>({endIndex:M[M.length-1].index,startIndex:M[0].index})),qe(Oo),_t(0)));de(P,h.scrollSeekRangeChanged),de(_($,Ee(T,z,B,ee),se(([M,G,X,le,ie])=>{const V=Qo(M),{align:we,behavior:Pe,offset:ke}=V;let O=V.index;O==="LAST"&&(O=le-1),O=Bs(0,O,Wa(le-1,O));let q=dr(G,ie,X,O);return we==="end"?q=In(q-G.height+X.height):we==="center"&&(q=In(q-G.height/2+X.height/2)),ke!==void 0&&ke!==0&&(q+=ke),{behavior:Pe,top:q}})),c);const xe=ut(_(b,se(M=>M.offsetBottom+M.bottom)),0);return de(_(R,se(M=>({height:M.visibleHeight,width:M.visibleWidth}))),T),{customScrollParent:y,data:H,deviation:ae,footerHeight:n,gap:ee,headerHeight:o,increaseViewportBy:t,initialItemCount:g,itemDimensions:z,overscan:a,restoreStateFrom:ne,scrollBy:l,scrollContainerState:i,scrollHeight:Z,scrollTo:c,scrollToIndex:$,scrollTop:d,smoothScrollTargetReached:u,totalCount:B,useWindowScroll:f,viewportDimensions:T,windowScrollContainerState:v,windowScrollTo:S,windowViewportRect:R,...h,gridState:b,horizontalDirection:Ce,initialTopMostItemIndex:te,totalListHeight:xe,...m,endReached:C,propsReady:k,rangeChanged:P,startReached:K,stateChanged:re,stateRestoreInProgress:D,...j}},Ye(kr,ht,ta,Ko,Jt,Cr,Xt));function il(t,s,a){return Bs(1,wa((t+a)/(wa(s)+a)))}function Rn(t,s,a,r){const{height:n}=a;if(n===void 0||r.length===0)return{bottom:0,top:0};const o=dr(t,s,a,r[0].index);return{bottom:dr(t,s,a,r[r.length-1].index)+n,top:o}}function dr(t,s,a,r){const n=il(t.width,a.width,s.column),o=wa(r/n),l=o*a.height+Bs(0,o-1)*s.row;return l>0?l+s.row:l}const Rd=Fe(()=>{const t=Q(N=>`Item ${N}`),s=Q({}),a=Q(null),r=Q("virtuoso-grid-item"),n=Q("virtuoso-grid-list"),o=Q(Ir),l=Q("div"),i=Q(ys),c=(N,m=null)=>ut(_(s,se(h=>h[N]),qe()),m),d=Q(!1),u=Q(!1);return de(be(u),d),{components:s,computeItemKey:o,context:a,FooterComponent:c("Footer"),HeaderComponent:c("Header"),headerFooterTag:l,itemClassName:r,ItemComponent:c("Item","div"),itemContent:t,listClassName:n,ListComponent:c("List","div"),readyStateChanged:d,reportReadyState:u,ScrollerComponent:c("Scroller","div"),scrollerRef:i,ScrollSeekPlaceholder:c("ScrollSeekPlaceholder","div")}}),Ad=Fe(([t,s])=>({...t,...s}),Ye(Ed,Rd)),Md=oe.memo(function(){const t=We("gridState"),s=We("listClassName"),a=We("itemClassName"),r=We("itemContent"),n=We("computeItemKey"),o=We("isSeeking"),l=jt("scrollHeight"),i=We("ItemComponent"),c=We("ListComponent"),d=We("ScrollSeekPlaceholder"),u=We("context"),N=jt("itemDimensions"),m=jt("gap"),h=We("log"),w=We("stateRestoreInProgress"),k=jt("reportReadyState"),y=is(oe.useMemo(()=>f=>{const v=f.parentElement.parentElement.scrollHeight;l(v);const S=f.firstChild;if(S!==null){const{height:R,width:j}=S.getBoundingClientRect();N({height:R,width:j})}m({column:An("column-gap",getComputedStyle(f).columnGap,h),row:An("row-gap",getComputedStyle(f).rowGap,h)})},[l,N,m,h]),!0,!1);return sl(()=>{t.itemHeight>0&&t.itemWidth>0&&k(!0)},[t]),w?null:e.jsx(c,{className:s,ref:y,...mt(c,u),"data-testid":"virtuoso-item-list",style:{paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},children:t.items.map(f=>{const v=n(f.index,f.data,u);return o?e.jsx(d,{...mt(d,u),height:t.itemHeight,index:f.index,width:t.itemWidth},v):p.createElement(i,{...mt(i,u),className:a,"data-index":f.index,key:v},r(f.index,f.data,u))})})}),Ld=oe.memo(function(){const t=We("HeaderComponent"),s=jt("headerHeight"),a=We("headerFooterTag"),r=is(oe.useMemo(()=>o=>{s(Yt(o,"height"))},[s]),!0,!1),n=We("context");return t!=null?e.jsx(a,{ref:r,children:e.jsx(t,{...mt(t,n)})}):null}),Dd=oe.memo(function(){const t=We("FooterComponent"),s=jt("footerHeight"),a=We("headerFooterTag"),r=is(oe.useMemo(()=>o=>{s(Yt(o,"height"))},[s]),!0,!1),n=We("context");return t!=null?e.jsx(a,{ref:r,children:e.jsx(t,{...mt(t,n)})}):null}),zd=({children:t})=>{const s=oe.useContext(tl),a=jt("itemDimensions"),r=jt("viewportDimensions"),n=is(oe.useMemo(()=>o=>{r(o.getBoundingClientRect())},[r]),!0,!1);return oe.useEffect(()=>{s&&(r({height:s.viewportHeight,width:s.viewportWidth}),a({height:s.itemHeight,width:s.itemWidth}))},[s,r,a]),e.jsx("div",{ref:n,style:Er(!1),children:t})},Fd=({children:t})=>{const s=oe.useContext(tl),a=jt("windowViewportRect"),r=jt("itemDimensions"),n=We("customScrollParent"),o=We("useWindowScroll"),l=Lo(a,n,!1);return oe.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:l,style:nl(!1,o),children:t})},Bd=oe.memo(function({...t}){const s=We("useWindowScroll"),a=We("customScrollParent"),r=a||s?Od:$d,n=a||s?Fd:zd,o=We("context");return e.jsx(r,{...t,...mt(r,o),children:e.jsxs(n,{children:[e.jsx(Ld,{}),e.jsx(Md,{}),e.jsx(Dd,{})]})})}),{useEmitter:cl,useEmitterValue:We,usePublisher:jt}=Zo(Ad,{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"}},Bd),$d=ol({useEmitter:cl,useEmitterValue:We,usePublisher:jt}),Od=ll({useEmitter:cl,useEmitterValue:We,usePublisher:jt});function An(t,s,a){return s!=="normal"&&s?.endsWith("px")!==!0&&a(`${t} was not resolved to pixel value correctly`,s,at.WARN),s==="normal"?0:parseInt(s??"0",10)}function Mn(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 Ln=new Set(["p","h1","h2","h3","h4","h5","h6","li","td","th"]);function Pd(t,s="component",a){const r=t.getBoundingClientRect(),n=[],o=a?.leafTags?new Set([...Ln,...a.leafTags]):Ln,l=a?.captureRoundedBorders??!0,i=a?.excludeTags?new Set(a.excludeTags):null,c=a?.excludeSelectors??null;function d(u){const N=getComputedStyle(u);if(N.display==="none"||N.visibility==="hidden"||N.opacity==="0")return;const m=u.tagName.toLowerCase();if(i?.has(m)||c?.some(T=>u.matches(T)))return;const h=[...u.children].filter(T=>{const z=getComputedStyle(T);return z.display!=="none"&&z.visibility!=="hidden"&&z.opacity!=="0"}),w=m==="img"||m==="svg"||m==="video"||m==="canvas",k=m==="input"||m==="button"||m==="textarea"||m==="select",y=h.length===0||w||k||o.has(m),f=N.backgroundColor,v=f!=="rgba(0, 0, 0, 0)"&&f!=="transparent",S=N.backgroundImage!=="none",R=parseFloat(N.borderTopWidth)||0,j=l&&R>0&&N.borderTopColor!=="rgba(0, 0, 0, 0)"&&N.borderTopColor!=="transparent",B=(parseFloat(N.borderTopLeftRadius)||0)>0,g=v||S||j&&B,b=m==="tr"||m==="td"||m==="th"||m==="thead"||m==="tbody"||m==="table";if(y){const T=u.getBoundingClientRect();if(T.width<1||T.height<1)return;const z=w&&T.width>0&&T.height>0&&Math.abs(T.width-T.height)<4,$=b?0:z?"50%":Dn(N,u)??8,Z=r.width;n.push({x:Z>0?+((T.left-r.left)/Z*100).toFixed(4):0,y:Math.round(T.top-r.top),w:Z>0?+(T.width/Z*100).toFixed(4):0,h:Math.round(T.height),r:$});return}if(g){const T=u.getBoundingClientRect();if(T.width>=1&&T.height>=1){const z=b?0:Dn(N,u)??8,$=r.width;n.push({x:$>0?+((T.left-r.left)/$*100).toFixed(4):0,y:Math.round(T.top-r.top),w:$>0?+(T.width/$*100).toFixed(4):0,h:Math.round(T.height),r:z,c:!0})}}for(const T of h)d(T)}for(const u of t.children)d(u);return{name:s,viewportWidth:Math.round(r.width),width:Math.round(r.width),height:Math.round(r.height),bones:n}}function Dn(t,s){const a=parseFloat(t.borderTopLeftRadius)||0,r=parseFloat(t.borderTopRightRadius)||0,n=parseFloat(t.borderBottomRightRadius)||0,o=parseFloat(t.borderBottomLeftRadius)||0;if(a===0&&r===0&&n===0&&o===0)return;const l=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,n,o)>9998?l?"50%":9999:a===r&&r===n&&n===o?a!==8?a:void 0:`${a}px ${r}px ${n}px ${o}px`}const _d=new Map;function Hd(t){return _d.get(t)}function Gd(){typeof window<"u"&&window.__BONEYARD_BUILD&&(window.__BONEYARD_SNAPSHOT=Pd)}function Qd(){return typeof window<"u"&&window.__BONEYARD_BUILD===!0}function Ud(t,s){if(!("breakpoints"in t))return t;const a=Object.keys(t.breakpoints).map(Number).sort((n,o)=>n-o);if(a.length===0)return null;const r=[...a].reverse().find(n=>s>=n)??a[0];return t.breakpoints[r]??null}const us={angle:110,start:30,end:70,speed:"2s",lightHighlight:"#f7f7f7",darkHighlight:"#2c2c2c"},As={speed:"1.8s",lightAdjust:.3,darkAdjust:.02},zn={web:{light:"#f0f0f0",dark:"#222222"}},Wd=/rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*(?:,\s*([\d.]+))?\s*\)/;function Fn(t,s){const a=t.match(Wd);if(a){const[,r,n,o,l="1"]=a,i=Math.min(1,parseFloat(l)+s*.5);return`rgba(${r},${n},${o},${i.toFixed(3)})`}if(t.startsWith("#")&&t.length>=7){const r=parseInt(t.slice(1,3),16),n=parseInt(t.slice(3,5),16),o=parseInt(t.slice(5,7),16);if(!isNaN(r)&&!isNaN(n)&&!isNaN(o)){const l=Math.round(r+(255-r)*s),i=Math.round(n+(255-n)*s),c=Math.round(o+(255-o)*s);return`#${l.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}${c.toString(16).padStart(2,"0")}`}}return t}Gd();let Rt={};function pa({loading:t,children:s,name:a,initialBones:r,color:n,darkColor:o,animate:l,stagger:i=!1,transition:c=!1,boneClass:d,className:u,fallback:N,fixture:m,snapshotConfig:h}){const w=p.useRef(null),k=p.useRef(Math.random().toString(36).slice(2,8)).current,[y,f]=p.useState(0),[v,S]=p.useState(0),[R,j]=p.useState(!1);p.useEffect(()=>{if(typeof window>"u")return;const X=()=>{const V=document.documentElement.classList.contains("dark")||!!w.current?.closest(".dark");j(V)};X();const le=new MutationObserver(X);le.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]});const ie=window.matchMedia("(prefers-color-scheme: dark)");return ie.addEventListener("change",X),()=>{le.disconnect(),ie.removeEventListener("change",X)}},[]);const B=n??Rt.color??zn.web.light,g=o??Rt.darkColor??zn.web.dark,b=R?g:B,T=l??Rt.animate??"pulse",z=T===!0?"pulse":T===!1?"solid":T;p.useEffect(()=>{const X=w.current;if(!X)return;const le=new ResizeObserver(V=>{const we=V[0]?.contentRect;f(Math.round(we?.width??0)),we&&we.height>0&&S(Math.round(we.height))});le.observe(X);const ie=X.getBoundingClientRect();return f(Math.round(ie.width)),ie.height>0&&S(Math.round(ie.height)),()=>le.disconnect()},[]);const $={};if(a&&($["data-boneyard"]=a,h&&($["data-boneyard-config"]=JSON.stringify(h))),Qd())return e.jsx("div",{ref:w,className:u,style:{position:"relative"},...$,children:e.jsx("div",{children:m??s})});const[Z,ae]=p.useState(!1);p.useLayoutEffect(()=>{ae(!0)},[]);const H=r??(a?Hd(a):void 0),ee=Z&&typeof window<"u"?window.innerWidth:0,re=y>0?y:ee,ne=H&&re>0?Ud(H,re):null,D=d??Rt.boneClass,te=(()=>{const X=i??Rt.stagger;return X===!0?80:X===!1||!X?0:X})(),J=(()=>{const X=c??Rt.transition;return X===!0?300:X===!1||!X?0:X})(),[me,Ce]=p.useState(!1),F=p.useRef(t),C=p.useRef(null);p.useEffect(()=>(F.current&&!t&&J>0&&ne&&(C.current&&clearTimeout(C.current),Ce(!0),C.current=setTimeout(()=>{Ce(!1),C.current=null},J)),F.current=t,()=>{C.current&&clearTimeout(C.current)}),[t,J,ne]);const K=(t||me)&&ne,P=t&&!ne&&!me,xe=v>0?v:ne?.height??0,M=ne?.height??0,G=xe>0&&M>0?xe/M:1;return e.jsxs("div",{ref:w,className:u,style:{position:"relative"},...$,children:[e.jsx("div",{"data-boneyard-content":"true",style:K&&!me?{visibility:"hidden"}:void 0,children:P?N:s}),K&&e.jsx("div",{"data-boneyard-overlay":"true",style:{position:"absolute",inset:0,overflow:"hidden",opacity:me?0:1,transition:J>0?`opacity ${J}ms ease-out`:void 0},children:e.jsxs("div",{style:{position:"relative",width:"100%",height:"100%"},children:[ne.bones.filter(X=>!Mn(X).c).map((X,le)=>{const ie=Mn(X),V=b;Fn(b,R?As.darkAdjust:As.lightAdjust);const we=ie.w/100*(ne.width??0),Pe=ie.r==="50%"&&Math.abs(we-ie.h)<4,ke={position:"absolute",left:`${ie.x}%`,top:ie.y*G,width:Pe?ie.h*G:`${ie.w}%`,height:ie.h*G,borderRadius:typeof ie.r=="string"?ie.r:`${ie.r}px`,backgroundColor:V},O=Rt.speed;if(z==="pulse")ke.animation=`bp-${k} ${O??As.speed} ease-in-out infinite`;else if(z==="shimmer"){const q=R?Rt.darkShimmerColor??us.darkHighlight:Rt.shimmerColor??us.lightHighlight,E=Rt.shimmerAngle??us.angle;delete ke.backgroundColor,ke.backgroundImage=`linear-gradient(${E}deg, ${V} ${us.start}%, ${q} 50%, ${V} ${us.end}%)`,ke.backgroundSize="200% 100%",ke.animation=`bs-${k} ${O??us.speed} linear infinite`}return te>0&&(ke.opacity=0,ke.animation=`${ke.animation?ke.animation+",":""} by-${k} 0.3s ease-out ${le*te}ms forwards`),e.jsx("div",{"data-boneyard-bone":"true",className:D,style:ke},le)}),z==="pulse"&&e.jsx("style",{children:`@keyframes bp-${k}{0%,100%{background-color:${b}}50%{background-color:${Fn(b,R?As.darkAdjust:As.lightAdjust)}}}`}),z==="shimmer"&&e.jsx("style",{children:`@keyframes bs-${k}{0%{background-position:200% 0}100%{background-position:-200% 0}}`}),te>0&&e.jsx("style",{children:`@keyframes by-${k}{from{opacity:0}to{opacity:1}}`})]})})]})}async function Ar(t){const s=Bt(Ge,"managedStudents");try{const o=zt(s,Ft("teacherId","==",t)),l=await qt(o);if(!l.empty)return l.docs.map(c=>({id:c.id,...c.data()})).sort((c,d)=>String(c.name||"").localeCompare(String(d.name||"")))}catch{}const r=(await ml(t)).map(o=>o.id);if(r.length===0)return[];const n=new Map;for(let o=0;o{n.set(d.id,{id:d.id,...d.data()})})}return Array.from(n.values()).sort((o,l)=>String(o.name||"").localeCompare(String(l.name||"")))}async function Vd(t,s,a){const r=et(Ge,"managedStudents",t);await yt(r,{riskLevel:s,...a!==void 0?{riskConfidence:a}:{},updatedAt:ot()})}async function dl(t,s,a){const r=It(s,a),n=et(Ge,"managedStudents",t);await yt(n,{grade:s,section:a,classSectionId:r,updatedAt:ot()})}function It(t,s){return[t,s].filter(Boolean).join("_").replace(/\s+/g,"_").toLowerCase()}function mr(t){const s=Object.entries(t).filter(([,a])=>a!==void 0);return Object.fromEntries(s)}function ds(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 ws(t){const a=ds(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 Ss(t,s){const a=`${t||""} ${s||""}`.toUpperCase();if(!a.trim())return null;const r=["STEM","ABM","HUMSS","GAS","TVL","ICT"];for(const n of r)if(new RegExp(`\\b${n}\\b`).test(a))return n;return null}function Dt(t){const s=(t||"").trim();if(!s)return{grade:"Grade 11",section:"Section A"};const[a="Grade 11",r="Section A"]=s.split(" - ").map(n=>n.trim());return{grade:a||"Grade 11",section:r||"Section A"}}function lt(t){const s=t.metadata||{},a=t.className||s.className,r=Dt(a),n=(t.grade||s.grade||r.grade||"").trim()||null,o=(t.section||s.section||r.section||"").trim()||null,l=(t.classSectionId||s.classSectionId||"").trim()||(n&&o?It(n,o):"")||null,i=(a||"").trim()||(n&&o?`${n} - ${o}`:"")||null,c=ds(t.gradeLevel||s.gradeLevel||n),d=(t.classification||s.classification||"").trim()||ws(c)||null,u=(t.strand||s.strand||"").trim()||Ss(i,o)||null;return{classSectionId:l,className:i,grade:n,section:o,gradeLevel:c,classification:d,strand:u,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 qd(t){const s=(t.className||"").trim(),[a="",r=""]=s.split(" - "),n=(t.grade||a||"").trim()||null,o=(t.section||r||"").trim()||null,l=(t.classSectionId||"").trim()||(n&&o?It(n,o):"")||null,i=s||(n&&o?`${n} - ${o}`:null),c=ds(t.gradeLevel||n),d=(t.classification||"").trim()||ws(c),u=(t.strand||"").trim()||Ss(i,o);return{classSectionId:l,className:i,grade:n,section:o,gradeLevel:c,classification:d,strand:u,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 ml(t){const s=Bt(Ge,"classrooms"),a=new Map,r=zt(s,Ft("teacherId","==",t));(await qt(r)).docs.forEach(i=>{a.set(i.id,{id:i.id,...i.data()})});const o=zt(s,Ft("managerId","==",t));return(await qt(o)).docs.forEach(i=>{a.set(i.id,{id:i.id,...i.data()})}),Array.from(a.values()).sort((i,c)=>String(i.name||"").localeCompare(String(c.name||"")))}async function ul(t){const s=t.classSectionId||It(t.grade,t.section),a=et(Ge,"classSectionOwnership",s),r=await ns(a),n=r.exists()?r.data().studentUids||[]:[],o=Array.from(new Set([...t.studentUids||[],...n])),l=mr(t);return r.exists()?await yt(a,{...l,classSectionId:s,studentUids:o,updatedAt:ot()}):await Ut(a,{...l,classSectionId:s,studentUids:o,createdAt:ot(),updatedAt:ot()}),s}async function Yd(t){const s=(t.classSectionId||"").trim()||It(t.grade,t.section),a=(t.className||"").trim()||`${t.grade} - ${t.section}`,r=qd({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 ul({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 n=Bt(Ge,"classrooms"),o=zt(n,Ft("classSectionId","==",s)),l=await qt(o);if(l.empty){const i=mr({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:ot(),updatedAt:ot()});await Ut(et(Ge,"classrooms",s),i,{merge:!0})}else for(const i of l.docs){const c=mr({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:ot()});await yt(i.ref,c)}return s}async function xl(t,s,a,r,n,o){const l=It(s,a);await ul({classSectionId:l,grade:s,section:a,schoolYear:n,ownerTeacherId:r,ownerTeacherName:o,studentUids:[t]}),await Ut(et(Ge,"users",t),{grade:s,section:a,classSectionId:l,adviserTeacherId:r,adviserTeacherName:o||"",updatedAt:ot()},{merge:!0})}async function Kd(t){const s=Bt(Ge,"classSectionOwnership"),a=new Map,r=zt(s,Ft("ownerTeacherId","==",t));(await qt(r)).docs.forEach(i=>{a.set(i.id,{id:i.id,...i.data()})});const o=zt(s,Ft("managerId","==",t));return(await qt(o)).docs.forEach(i=>{a.set(i.id,{id:i.id,...i.data()})}),Array.from(a.values()).sort((i,c)=>String(i.classSectionId||"").localeCompare(String(c.classSectionId||"")))}async function Xd(t="",s=25){const a=Bt(Ge,"users"),r=Math.max(1,Math.min(100,s)),n=zt(a,Ft("role","==","teacher"),vo(r*4)),o=await qt(n),l=t.trim().toLowerCase();return o.docs.map(c=>{const d=c.data(),u=String(d.name||"").trim(),N=String(d.email||"").trim();return{uid:c.id,name:u||"Teacher",email:N,photo:String(d.photo||d.photoURL||"").trim()||void 0}}).filter(c=>l?c.name.toLowerCase().includes(l)||c.email.toLowerCase().includes(l):!0).sort((c,d)=>c.name.localeCompare(d.name)).slice(0,r)}function Jd(t,s,a=20){if(t.length===0)return s([]),()=>{};const r=Bt(Ge,"activities"),n=zt(r,Ft("classroomId","in",t),ui("timestamp","desc"));return Xs(n,o=>{const l=o.docs.slice(0,a).map(i=>({id:i.id,...i.data()}));s(l)})}async function Zd(t,s,a){const r=et(Bt(Ge,"generatedLessonPlans"));return await Ut(r,{...t,teacherId:s,teacherName:a?.teacherName||null,studentId:a?.studentId||null,studentName:a?.studentName||null,status:"draft",createdAt:ot(),updatedAt:ot()}),r.id}async function em(t){const s=et(Ge,"generatedLessonPlans",t),a=await ns(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 yt(s,{status:"published",publishedAt:ot(),updatedAt:ot()})}async function tm(t,s=!0){const a=t.learningCompetency||t.lessonTitle||t.focusTopics&&t.focusTopics[0]||"general mathematics",r=t.subject||"general_math",n=t.quarter??1;let o="",l=[],i,c,d,u=!1;if(s)try{const h=await Wl(a,r,n,{lessonTitle:t.lessonTitle,learningCompetency:t.learningCompetency,moduleUnit:t.moduleUnit,learnerLevel:t.learnerLevel});l=h.sources||[],o=h.explanation||"",i=h.retrievalConfidence,c=h.retrievalBand,d=h.retrievalQuery,u=h.needsReview??!1}catch{o="",l=[]}const N={...t,subject:r,quarter:n,curriculumContext:o?`[CURRICULUM CONTEXT] -${o}`:void 0,curriculumRetrievalConfidence:i,curriculumRetrievalBand:c,curriculumRetrievalQuery:d,needsReview:u};return{...await Ve.generateLessonPlan(N),curriculumSources:l,curriculumContext:o}}const sm=ni("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 am({className:t,variant:s,asChild:a=!1,...r}){const n=a?pi:"span";return e.jsx(n,{"data-slot":"badge",className:hr(sm({variant:s}),t),...r})}function rm(t){return t.length<=42?t:`${t.slice(0,18)}...${t.slice(-20)}`}const Bn=({sources:t=[],className:s})=>t.length?e.jsxs(gi,{children:[e.jsx(bi,{asChild:!0,children:e.jsxs(am,{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(Vt,{size:12}),"DepEd Aligned"]})}),e.jsxs(vi,{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:[rm(a.sourceFile)," | p.",a.page]}),e.jsxs("p",{className:"text-[#5a6578]",children:["Similarity: ",(a.score*100).toFixed(1),"%"]})]},`${a.sourceFile}-${a.page}-${r}`))})]})]}):null,nm=[{level:"Remember",icon:uo,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:Vt,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:$s,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:Xi,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"}],om=({isOpen:t,onClose:s})=>t?e.jsx(Qt,{children:t&&e.jsx(Re.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(Re.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(mo,{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(va,{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:nm.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(tc,{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,lm={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"},ca={identification:{label:"Identification",icon:e.jsx(fr,{size:16}),description:"Define or identify concepts"},enumeration:{label:"Enumeration",icon:e.jsx(yi,{size:16}),description:"List steps or properties"},multiple_choice:{label:"Multiple Choice",icon:e.jsx(gs,{size:16}),description:"Choose from 4 options"},word_problem:{label:"Word Problem",icon:e.jsx(Vt,{size:16}),description:"Real-world scenarios"},equation_based:{label:"Equation-Based",icon:e.jsx(Vl,{size:16}),description:"Solve equations"}},Va={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"}},im=["Grade 11","Grade 12"],qa=t=>{const s=(t||"").trim().toLowerCase();return s==="grade 12"||s==="12"||s.includes("12")?"Grade 12":"Grade 11"},cm={"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"]}},dm={"Grade 11":["General Mathematics - "],"Grade 12":["Pre-Calculus - ","Basic Calculus - "]},$n=(t,s)=>{const a=dm[s];return Object.fromEntries(Object.entries(t).filter(([r])=>a.some(n=>r.startsWith(n))))},Ms=10,xs=12,Ya="mathpulse:quiz-maker:active-task",On={easy:"text-green-600",medium:"text-rose-600",hard:"text-red-600"},mm=({onBack:t,gradeLevel:s,selectedClassId:a,selectedClassName:r})=>{const{currentUser:n,loading:o}=Ks(),l=p.useMemo(()=>Ve.getImportGroundedRolloutFlags(),[]),[i,c]=p.useState("create"),[d,u]=p.useState("setup"),[N,m]=p.useState(qa(s)),[h,w]=p.useState(10),[k,y]=p.useState([]),[f,v]=p.useState([]),[S,R]=p.useState(["multiple_choice","word_problem","identification"]),[j,B]=p.useState(["remember","understand","apply","analyze"]),[g,b]=p.useState(!1),[T,z]=p.useState({easy:30,medium:50,hard:20}),[$,Z]=p.useState({}),[ae,H]=p.useState(!1),[ee,re]=p.useState([]),[ne,D]=p.useState(!1),[te,J]=p.useState(""),[me,Ce]=p.useState(!1),[F,C]=p.useState(!1),[K,P]=p.useState(null),[xe,M]=p.useState(0),[G,X]=p.useState("queued"),[le,ie]=p.useState("Waiting to start generation..."),[V,we]=p.useState(null),[Pe,ke]=p.useState(null),[O,q]=p.useState(""),[E,W]=p.useState(!1),je=p.useRef(!1),[pe,De]=p.useState("topics"),[fe,Me]=p.useState(null),[I,Y]=p.useState(!1),[ge,He]=p.useState("all"),[Je,Xe]=p.useState("all"),[U,ue]=p.useState(!1),[Be,Te]=p.useState(null),[tt,xt]=p.useState(!1),[Aa,es]=p.useState(!1),[ks,aa]=p.useState(!1),[zr,Cl]=p.useState([]),[Tl,Fr]=p.useState(!1),[Ma,Br]=p.useState(""),[ts,$r]=p.useState(null),[Or,Cs]=p.useState([]),[Il,Pr]=p.useState(!1),[La,El]=p.useState("all"),[Rl,_r]=p.useState(null),[Hr,ra]=p.useState(null),Gr=p.useCallback(async()=>{H(!0);const x=qa(N);try{const A=await Ve.getQuizTopics(x);A.topics&&Z($n(A.topics,x))}catch{Z($n(cm[x],x))}finally{H(!1)}},[N]),Qr=p.useCallback(async()=>{if(!l.quizEnabled){re([]),J("Import-grounded quiz generation is disabled by rollout flag; using curriculum defaults."),D(!1);return}D(!0),J("");try{const x=await Ve.getCourseMaterialTopics({classSectionId:a,limit:20}),A=(x.topics||[]).filter(L=>L.title?.trim());re(A),x.warnings&&x.warnings.length>0&&J(x.warnings.join(" "))}catch{re([]),J("Imported topics are currently unavailable; quiz generation will use curriculum defaults.")}finally{D(!1)}},[a,l.quizEnabled]);p.useEffect(()=>{Gr(),y([]),v([])},[Gr]),p.useEffect(()=>{Qr()},[Qr]);const Da=p.useMemo(()=>{const x=Array.from(new Set(ee.map(A=>A.title.trim()).filter(Boolean)));return x.length===0?$:{"Imported Course Materials":x,...$}},[$,ee]);p.useEffect(()=>{He("all"),Xe("all")},[V]);const Ur=p.useMemo(()=>{if(!V)return[];const x=V.questions.map(L=>L.provenance?.sourceFile?.trim()).filter(L=>!!L),A=(V.metadata.topicProvenance||[]).map(L=>L.sourceFile?.trim()).filter(L=>!!L);return Array.from(new Set([...x,...A])).sort((L,Ne)=>L.localeCompare(Ne))},[V]),Wr=p.useMemo(()=>{if(!V)return[];const x=V.questions.map(L=>L.provenance?.materialId?.trim()).filter(L=>!!L),A=(V.metadata.topicProvenance||[]).map(L=>L.materialId?.trim()).filter(L=>!!L);return Array.from(new Set([...x,...A])).sort((L,Ne)=>L.localeCompare(Ne))},[V]),za=p.useMemo(()=>V?V.questions.filter(x=>{const A=ge==="all"||(x.provenance?.sourceFile||"").trim()===ge,L=Je==="all"||(x.provenance?.materialId||"").trim()===Je;return A&&L}):[],[V,ge,Je]),Vr=(x,A)=>{const L={...T},Ne=Math.max(0,Math.min(100,L[x]+A)),Ue=Ne-L[x];L[x]=Ne;const _e=Object.keys(L).filter(ct=>ct!==x),St=_e.reduce((ct,kt)=>ct+L[kt],0);if(St>0)for(const ct of _e)L[ct]=Math.max(0,Math.round(L[ct]-Ue*L[ct]/St));const na=Object.values(L).reduce((ct,kt)=>ct+kt,0);if(na!==100){const ct=_e.reduce((kt,Zr)=>L[kt]>=L[Zr]?kt:Zr);L[ct]+=100-na}z(L)},Al=x=>{y(A=>A.includes(x)?A.filter(L=>L!==x):[...A,x]),v(A=>A.filter(L=>L!==x))},Ml=x=>{R(A=>A.includes(x)?A.length>1?A.filter(L=>L!==x):A:[...A,x])},Ll=x=>{B(A=>A.includes(x)?A.length>1?A.filter(L=>L!==x):A:[...A,x])},Dl=()=>{let x=k.length>0?k.filter(L=>!f.includes(L)):Object.values(Da).flat().filter(L=>!f.includes(L)).slice(0,3);x.length>xs&&(x=x.slice(0,xs));const A=Math.min(h,Ms);return{topics:x,gradeLevel:N,numQuestions:A,questionTypes:S,includeGraphs:g,difficultyDistribution:T,bloomLevels:j,excludeTopics:f,classSectionId:a,className:r,preferImportedTopics:l.quizEnabled}},zl=p.useCallback((x,A)=>{const L={taskId:x,request:A,createdAt:new Date().toISOString(),ownerUid:n?.uid};try{sessionStorage.setItem(Ya,JSON.stringify(L))}catch{}},[n]),Ot=p.useCallback(()=>{try{sessionStorage.removeItem(Ya)}catch{}},[]),Fa=p.useCallback(x=>{const A=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)));M(L=>{let Ne=Math.max(L,A);if(x.status==="running"&&A<=L){const Ue=String(x.progressStage||"").toLowerCase(),_e=Ue.includes("assembling")||Ue.includes("final")?97:Ue.includes("generating")?89:95;Ne=Math.min(_e,L+1)}return Ne}),X(x.progressStage||x.status),ie(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."))},[]);p.useEffect(()=>{if(o||je.current)return;if(je.current=!0,!n){Ot();return}let x=!1;const A=sessionStorage.getItem(Ya);if(!A)return;let L=null;try{L=JSON.parse(A)}catch{Ot();return}if(!L?.taskId){Ot();return}if(L.ownerUid&&L.ownerUid!==n.uid){Ot();return}return Ce(!0),P(L.taskId),q(""),Ve.waitForTaskResult(L.taskId,{timeoutMs:24e4,pollIntervalMs:1500,onProgress:Fa}).then(async Ne=>{if(x)return;const Ue=Ne.result;if(!Ue||typeof Ue!="object")throw new Error("Quiz generation completed without a valid result payload.");const _e=Ue;we(_e),u("results"),M(100),X("completed"),ie("Generation complete."),P(null),Ot();try{await Kr(_e,L.request),ce.success("Quiz auto-saved to your library as draft.")}catch(St){ce.error(St instanceof Error?St.message:"Quiz generated but failed to save to library")}}).catch(Ne=>{if(!x){if(Ne instanceof Os&&(Ne.status===401||Ne.status===403)){je.current=!1,Ce(!1);return}q(Ne instanceof Error?Ne.message:"Failed to resume quiz generation"),P(null),Ot()}}).finally(()=>{x||Ce(!1)}),()=>{x=!0}},[Fa,o,Ot,n]);const Ba=()=>{if(me){window.confirm("Quiz generation is in progress. Are you sure you want to leave?")&&(u("setup"),we(null),q(""),t());return}u("setup"),we(null),q(""),t()},Fl=async()=>{q(""),Ce(!0),ra(null),M(8),X("queued"),ie("Submitting quiz generation task..."),we(null);const x=Dl();try{const A=await Ve.generateQuiz(x,{onTaskCreated:L=>{P(L),zl(L,x),M(Ne=>Math.max(Ne,12)),X("queued"),ie("Task queued. Generation is running in the background.")},onProgress:L=>{Fa(L),L.taskId&&L.taskId!==K&&P(L.taskId)}});we(A),u("results"),M(100),X("completed"),ie("Generation complete."),P(null),Ot();try{await Kr(A,x),ce.success("Quiz auto-saved to your library as draft."),n?.uid&&x.topics?.[0]&&Ci(n.uid,x.topics[0],A.questions.length).catch(()=>{})}catch(L){ce.error(L instanceof Error?L.message:"Quiz generated but failed to save to library")}Ve.reportImportGroundedFeedback({flow:"quiz",status:"success",classSectionId:x.classSectionId,className:x.className,metadata:{totalQuestions:A.metadata.totalQuestions,usedImportedTopics:!!A.metadata.usedImportedTopics,importedTopicCount:A.metadata.importedTopicCount??0,importGroundingEnabled:l.quizEnabled}})}catch(A){q(A instanceof Error?A.message:"Quiz generation failed"),M(100),X("failed"),ie("Generation failed."),P(null),Ot(),Ve.reportImportGroundedFeedback({flow:"quiz",status:"failed",classSectionId:x.classSectionId,className:x.className,metadata:{error:A instanceof Error?A.message:"Quiz generation failed",importGroundingEnabled:l.quizEnabled}})}finally{Ce(!1)}},Bl=()=>{if(!V)return;const x=V.questions.map((A,L)=>{let Ne=`${L+1}. [${A.difficulty.toUpperCase()}] [${A.bloomLevel}] (${A.points} pts) -`;return Ne+=` ${A.question} -`,A.options&&(Ne+=A.options.map(Ue=>` ${Ue}`).join(` -`)+` -`),Ne+=` Answer: ${A.correctAnswer} -`,Ne+=` Explanation: ${A.explanation} -`,Ne}).join(` -`);navigator.clipboard.writeText(x),W(!0),setTimeout(()=>W(!1),2e3)},$l=()=>{if(!V)return;const x=new Blob([JSON.stringify(V,null,2)],{type:"application/json"}),A=URL.createObjectURL(x),L=document.createElement("a");L.href=A,L.download=`quiz_${N.replace(/\s/g,"_")}_${Date.now()}.json`,L.click(),URL.revokeObjectURL(A)};k.length>0||Object.values(Da).flat().length>0;const qr=(x,A)=>{const L=A?.gradeLevel||N,Ne=A?.topics||k,Ue=x.questions.map((_e,St)=>({id:`q_${Date.now()}_${St}`,questionType:_e.questionType||"identification",question:_e.question,..._e.options?{options:_e.options}:{},correctAnswer:_e.correctAnswer,bloomLevel:_e.bloomLevel||"understand",difficulty:_e.difficulty||"medium",topic:_e.topic,subject:L,points:_e.points,explanation:_e.explanation}));return{title:`${L} Quiz – ${Ne.length>0?Ne.slice(0,2).join(", "):"Mixed Topics"}`,gradeLevel:L,questions:Ue,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"}},Yr=p.useCallback(x=>{Cs(A=>[x,...A.filter(L=>L.id!==x.id)])},[]);async function Kr(x,A){if(!n)return null;const L=qr(x,A),Ne=await an(L,n.uid,Be?{documentId:Be}:void 0);return Te(Ne),Yr({id:Ne,...L,teacherId:n.uid}),Ne}const Ol=async()=>{if(!V){ce.error("No quiz to save. Generate a quiz first.");return}if(!n){ce.error("You must be signed in to save quizzes.");return}ue(!0);try{const x=qr(V),A=await an(x,n.uid,Be?{documentId:Be}:void 0);Te(A),Yr({id:A,...x,teacherId:n.uid}),ce.success("Quiz saved to your library!")}catch(x){ce.error(x instanceof Error?x.message:"Failed to save quiz")}finally{ue(!1)}},Pl=async()=>{if(Be){xt(!0);try{await wi(Be),Cs(x=>x.map(A=>A.id===Be?{...A,status:"published"}:A)),ce.success("Quiz published to Quiz Bank!")}catch(x){ce.error(x instanceof Error?x.message:"Failed to publish quiz")}finally{xt(!1)}}},$a=async x=>{const A=x??Be;if(!A){ce.error("Save the quiz first before assigning.");return}if(_r(A),es(!0),$r(null),Br(""),zr.length===0&&n){Fr(!0);try{const L=await Ar(n.uid);Cl(L)}catch{ce.error("Failed to load students")}finally{Fr(!1)}}},_l=async()=>{const x=Rl??Be;if(!(!ts||!x||!n)){aa(!0);try{await Si(x,ts,n.uid),Cs(A=>A.map(L=>L.id===x?{...L,status:"assigned",metadata:{...L.metadata,assignedTo:ts}}:L)),ce.success("Quiz assigned to student!"),es(!1),_r(null),i==="bank"&&Oa()}catch(A){ce.error(A instanceof Error?A.message:"Failed to assign quiz")}finally{aa(!1)}}},Oa=p.useCallback(async()=>{if(n){Pr(!0);try{const x=await Ni(n.uid);Cs(x)}catch{ce.error("Failed to load quiz bank")}finally{Pr(!1)}}},[n]);p.useEffect(()=>{i==="bank"&&Oa()},[i,Oa]);const Hl=async x=>{try{await ji(x),Cs(A=>A.filter(L=>L.id!==x)),ce.success("Quiz deleted")}catch{ce.error("Failed to delete quiz")}},Xr=zr.filter(x=>x.name.toLowerCase().includes(Ma.toLowerCase())||x.email.toLowerCase().includes(Ma.toLowerCase())),Jr=La==="all"?Or:Or.filter(x=>x.status===La),Gl=x=>{const A=(x.metadata.topicsCovered||[]).reduce((L,Ne)=>(L[Ne]=(L[Ne]||0)+1,L),{});return{questions:x.questions.map(L=>({questionType:L.questionType,question:L.question,correctAnswer:L.correctAnswer,options:L.options??null,bloomLevel:L.bloomLevel,difficulty:L.difficulty,topic:L.topic,points:L.points,explanation:L.explanation})),totalPoints:x.totalPoints,metadata:{topicsCovered:A,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||[]}}},Pa=x=>{Te(x.id),we(Gl(x)),ke(null),ra(x.id),He("all"),Xe("all"),Me(null),u("results"),c("create")},Ql={remember:"bg-sky-100 text-sky-700 border-sky-300",understand:"bg-rose-100 text-rose-700 border-rose-300",apply:"bg-emerald-100 text-emerald-700 border-emerald-300",analyze:"bg-rose-100 text-rose-700 border-rose-300"},Ul=(x,A,L)=>{const Ne=fe===A,Ue=Ql[x.bloomLevel]||"bg-[#edf1f7] text-[#5a6578] border-[#dde3eb]";return e.jsxs(Re.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:A*.05},className:"border border-[#dde3eb] rounded-xl overflow-hidden relative",children:[e.jsx("div",{className:`absolute top-2 right-2 text-[10px] font-bold uppercase px-2 py-0.5 rounded border ${Ue} z-10`,children:x.bloomLevel}),e.jsx("div",{className:"p-4 cursor-pointer hover:bg-[#edf1f7] transition-colors",onClick:()=>Me(Ne?null:A),children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2 flex-wrap",children:[e.jsxs("span",{className:"text-xs font-bold text-white bg-sky-600 px-2 py-0.5 rounded",children:["Q",A+1]}),e.jsx("span",{className:`text-xs font-medium px-2 py-0.5 rounded border ${Va[x.bloomLevel]?.color||"bg-[#edf1f7] text-[#5a6578]"}`,children:x.bloomLevel}),e.jsx("span",{className:`text-xs font-medium ${On[x.difficulty]||"text-[#5a6578]"}`,children:x.difficulty}),e.jsxs("span",{className:"text-xs text-slate-500",children:[x.points," pts"]}),e.jsx("span",{className:"text-xs bg-[#edf1f7] text-[#5a6578] px-2 py-0.5 rounded",children:x.topic})]}),e.jsx("p",{className:"text-sm text-[#0a1628] font-medium",children:x.question})]}),e.jsx("div",{className:"flex-shrink-0 mt-1",children:Ne?e.jsx(Na,{size:16,className:"text-slate-500"}):e.jsx(Ht,{size:16,className:"text-slate-500"})})]})}),e.jsx(Qt,{children:Ne&&e.jsx(Re.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},className:"border-t border-[#dde3eb] overflow-hidden",children:e.jsxs("div",{className:"p-4 space-y-3 bg-[#edf1f7]/50",children:[x.options&&e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold text-[#5a6578] mb-1",children:"Options:"}),e.jsx("div",{className:"space-y-1",children:x.options.map((_e,St)=>e.jsx("div",{className:`text-sm px-3 py-1.5 rounded-lg ${_e.includes(x.correctAnswer)?"bg-green-100 text-green-800 font-medium":"bg-white text-[#0a1628]"}`,children:_e},St))})]}),e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"bg-green-50 border border-green-200 rounded-lg p-3",children:[e.jsx("p",{className:"text-xs font-semibold text-green-700 mb-1",children:"Correct Answer:"}),e.jsx("p",{className:"text-sm text-green-800 font-medium",children:x.correctAnswer})]}),e.jsxs("div",{className:"bg-sky-50 border border-sky-200 rounded-lg p-3",children:[e.jsx("p",{className:"text-xs font-semibold text-sky-700 mb-1",children:"Explanation:"}),e.jsx("p",{className:"text-sm text-sky-800",children:x.explanation})]})]}),e.jsxs("div",{className:"flex items-center gap-3 text-xs text-slate-500",children:[e.jsxs("span",{children:["Type: ",ca[x.questionType]?.label||x.questionType]}),e.jsxs("span",{children:["Bloom: ",x.bloomLevel]})]}),x.provenance&&e.jsxs("div",{className:"bg-[#f7fbff] border border-sky-100 rounded-lg p-3",children:[e.jsx("p",{className:"text-xs font-semibold text-sky-700 mb-1",children:"Item Provenance"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-1 text-xs text-[#5a6578]",children:[x.provenance.title&&e.jsxs("p",{children:["Topic: ",x.provenance.title]}),x.provenance.topicId&&e.jsxs("p",{children:["Topic ID: ",x.provenance.topicId]}),x.provenance.materialId&&e.jsxs("p",{children:["Material ID: ",x.provenance.materialId]}),x.provenance.sourceFile&&e.jsxs("p",{children:["Source File: ",x.provenance.sourceFile]}),x.provenance.sectionId&&e.jsxs("p",{children:["Section ID: ",x.provenance.sectionId]})]})]})]})})})]},A)};return e.jsxs("div",{className:"w-full flex flex-col bg-[#f7f9fc] min-h-screen",children:[e.jsxs("div",{className:"bg-white border-b border-[#dde3eb] px-6 py-4 flex-shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx("button",{onClick:Ba,className:"p-2 hover:bg-[#edf1f7] rounded-lg transition-colors text-slate-500",children:e.jsx(Pt,{size:20})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-display font-bold text-[#0a1628]",children:"AI Quiz Maker"}),e.jsx("p",{className:"text-[#5a6578] text-sm mt-1",children:"Generate AI-powered assessments with Bloom's Taxonomy"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>c("create"),className:`flex items-center gap-1.5 px-4 py-2 rounded-xl text-sm font-semibold transition-colors ${i==="create"?"bg-sky-100 text-sky-700 border border-sky-300":"bg-[#edf1f7] text-[#5a6578] hover:bg-[#dde3eb]"}`,children:[e.jsx(hc,{size:16})," Create Quiz"]}),e.jsxs("button",{onClick:()=>c("bank"),className:`flex items-center gap-1.5 px-4 py-2 rounded-xl text-sm font-semibold transition-colors ${i==="bank"?"bg-sky-100 text-sky-700 border border-sky-300":"bg-[#edf1f7] text-[#5a6578] hover:bg-[#dde3eb]"}`,children:[e.jsx(mn,{size:16})," Quiz Bank"]})]})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-6 sm:px-8 xl:px-10 py-8",children:[i==="bank"&&e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex items-center gap-2 flex-wrap",children:["all","draft","published","assigned","completed"].map(x=>e.jsx("button",{onClick:()=>El(x),className:`px-3 py-1.5 rounded-full text-xs font-semibold capitalize transition-colors ${La===x?"bg-sky-100 text-sky-700 border border-sky-300":"bg-[#edf1f7] text-[#5a6578] hover:bg-[#dde3eb]"}`,children:x},x))}),Il?e.jsxs("div",{className:"flex items-center justify-center py-16",children:[e.jsx(nt,{size:24,className:"animate-spin text-sky-500"}),e.jsx("span",{className:"ml-2 text-sm text-[#5a6578]",children:"Loading quiz bank…"})]}):Jr.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-slate-500",children:[e.jsx(mn,{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:Jr.map(x=>e.jsxs(Re.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},onClick:()=>Pa(x),role:"button",tabIndex:0,onKeyDown:A=>{(A.key==="Enter"||A.key===" ")&&(A.preventDefault(),Pa(x))},className:"border border-[#dde3eb] rounded-xl p-4 hover:shadow-md transition-shadow cursor-pointer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-sky-400",children:[e.jsxs("div",{className:"flex items-start justify-between mb-2",children:[e.jsx("h4",{className:"text-sm font-bold text-[#0a1628] leading-tight",children:x.title}),e.jsx("span",{className:`text-[10px] font-bold px-2 py-0.5 rounded-full capitalize ${lm[x.status]}`,children:x.status})]}),e.jsx("div",{className:"flex flex-wrap gap-1 mb-3",children:x.metadata.topicsCovered.slice(0,3).map(A=>e.jsx("span",{className:"text-[10px] bg-[#edf1f7] text-[#5a6578] px-2 py-0.5 rounded",children:A},A))}),e.jsxs("div",{className:"flex items-center gap-3 text-xs text-[#5a6578] mb-3",children:[e.jsxs("span",{children:[x.questions.length," questions"]}),e.jsxs("span",{children:[x.totalPoints," pts"]}),e.jsx("span",{children:x.gradeLevel})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:A=>{A.stopPropagation(),Pa(x)},className:"flex items-center gap-1 px-3 py-1.5 text-xs font-semibold bg-[#edf1f7] text-[#5a6578] rounded-lg hover:bg-[#dde3eb] transition-colors",children:[e.jsx(pr,{size:12})," View"]}),e.jsxs("button",{onClick:A=>{A.stopPropagation(),$a(x.id)},className:"flex items-center gap-1 px-3 py-1.5 text-xs font-semibold bg-sky-50 text-sky-700 rounded-lg hover:bg-sky-100 transition-colors",children:[e.jsx(zs,{size:12})," Assign"]}),e.jsxs("button",{onClick:A=>{A.stopPropagation(),Hl(x.id)},className:"flex items-center gap-1 px-3 py-1.5 text-xs font-semibold bg-red-50 text-red-600 rounded-lg hover:bg-red-100 transition-colors",children:[e.jsx(No,{size:12})," Delete"]})]})]},x.id))})]}),i==="create"&&e.jsxs(e.Fragment,{children:[O&&e.jsxs(Re.div,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},className:"mb-4 bg-red-50 border border-red-200 rounded-xl p-4 flex items-start gap-3",children:[e.jsx(Ca,{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:O})]}),e.jsx("button",{onClick:()=>q(""),className:"ml-auto",children:e.jsx(va,{size:14,className:"text-red-400"})})]}),me&&e.jsxs(Re.div,{initial:{opacity:0,y:-8},animate:{opacity:1,y:0},className:"mb-4 bg-white border border-sky-200 rounded-xl p-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(nt,{size:16,className:"animate-spin text-sky-600"}),e.jsx("p",{className:"text-sm font-semibold text-[#0a1628]",children:"Generating Quiz in Background"})]}),e.jsxs("span",{className:"text-xs font-bold text-sky-700",children:[xe,"%"]})]}),e.jsx("div",{className:"h-2 bg-[#edf1f7] rounded-full overflow-hidden",children:e.jsx(Re.div,{animate:{width:`${xe}%`},transition:{duration:.35,ease:"easeOut"},className:"h-full bg-gradient-to-r from-sky-600 to-cyan-500"})}),e.jsxs("p",{className:"mt-2 text-xs text-[#5a6578] capitalize",children:["Stage: ",G.replace(/_/g," ")]}),e.jsx("p",{className:"text-xs text-[#5a6578]",children:le}),K&&e.jsxs("p",{className:"text-[11px] text-[#7b8798] mt-1",children:["Task ID: ",K]})]}),!me&&d!=="results"&&e.jsx("div",{className:"flex bg-white rounded-xl border border-[#dde3eb] mb-6 overflow-hidden shadow-sm",children:[{id:"setup",label:"Setup"},{id:"topics",label:"Topics"},{id:"style",label:"Question style"},{id:"preview",label:"Preview"}].map((x,A)=>{const Ne=["setup","topics","style","preview"].indexOf(d),Ue=Ne>A,_e=Ne===A;return e.jsxs("div",{className:`flex-1 flex items-center justify-center py-3 border-r last:border-r-0 border-[#dde3eb] ${_e?"bg-purple-50":"bg-white"}`,children:[Ue?e.jsx("div",{className:"w-5 h-5 rounded-full bg-green-500 text-white flex items-center justify-center mr-2",children:e.jsx(gs,{size:12,strokeWidth:3})}):e.jsx("div",{className:`w-5 h-5 rounded-full flex items-center justify-center text-xs font-bold mr-2 ${_e?"bg-[#9b51e0] text-white":"bg-[#edf1f7] text-slate-500"}`,children:A+1}),e.jsx("span",{className:`text-sm font-semibold ${_e?"text-[#9b51e0]":Ue?"text-slate-700":"text-slate-400"}`,children:x.label})]},x.id)})}),d==="setup"&&!me&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"bg-purple-50 border border-purple-200 rounded-xl p-4 flex items-start gap-3",children:[e.jsx(tr,{size:18,className:"text-[#9b51e0] flex-shrink-0 mt-0.5"}),e.jsx("div",{children:e.jsxs("p",{className:"text-sm text-purple-800",children:["This quiz maker generates ",e.jsx("span",{className:"font-bold",children:"supplemental assessments"})," to support classroom instruction. Questions follow Bloom's Taxonomy for comprehensive skill evaluation. Generation limit: up to ",Ms," questions and ",xs," topics per quiz."]})})]}),e.jsxs("div",{className:"bg-white border border-[#dde3eb] rounded-xl overflow-hidden shadow-sm",children:[e.jsx("div",{className:"px-5 py-4 border-b border-[#dde3eb]",children:e.jsx("p",{className:"text-xs font-bold text-slate-400 uppercase tracking-wider",children:"BASIC SETTINGS"})}),e.jsxs("div",{className:"p-5 grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"quiz-grade-level",className:"text-sm font-semibold text-[#0a1628] mb-2 block",children:"Grade level"}),e.jsx("select",{id:"quiz-grade-level",value:N,onChange:x=>m(qa(x.target.value)),className:"w-full bg-white text-[#0a1628] rounded-lg px-4 py-3 text-sm outline-none border border-[#dde3eb] focus:ring-2 focus:ring-purple-500",children:im.map(x=>e.jsx("option",{value:x,children:x},x))})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"quiz-num-questions",className:"text-sm font-semibold text-[#0a1628] mb-2 block",children:"Number of questions"}),e.jsxs("div",{className:"flex items-center",children:[e.jsx("button",{onClick:()=>w(Math.max(1,h-1)),className:"w-12 h-12 border border-[#dde3eb] rounded-l-lg flex items-center justify-center hover:bg-[#edf1f7] text-[#edf1f7] transition-colors bg-white font-bold text-xl",children:e.jsx("span",{className:"text-[#dde3eb]",children:"-"})}),e.jsx("input",{id:"quiz-num-questions",type:"number",min:1,max:Ms,value:h,onChange:x=>w(Math.min(Ms,Math.max(1,parseInt(x.target.value)||1))),className:"flex-1 h-12 text-center border-y border-[#dde3eb] px-3 text-base font-bold focus:outline-none bg-white text-[#0a1628]"}),e.jsx("button",{onClick:()=>w(Math.min(Ms,h+1)),className:"w-12 h-12 border border-[#dde3eb] rounded-r-lg flex items-center justify-center hover:bg-[#edf1f7] text-[#edf1f7] transition-colors bg-white font-bold text-xl",children:e.jsx("span",{className:"text-[#dde3eb]",children:"+"})})]})]})]})]})]}),d==="topics"&&!me&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-bold text-[#0a1628]",children:"Select topics"}),e.jsxs("p",{className:"text-sm text-[#5a6578]",children:["Choose up to ",xs," topics across all strands"]})]}),e.jsxs("div",{className:"bg-purple-50 text-[#9b51e0] px-3 py-1 rounded-full text-sm font-bold",children:[k.filter(x=>!f.includes(x)).length," of ",xs," selected"]})]}),ae?e.jsxs("div",{className:"flex items-center justify-center py-10 text-sm text-[#5a6578]",children:[e.jsx(nt,{size:24,className:"animate-spin text-[#9b51e0] mr-2"})," Loading topics..."]}):e.jsx("div",{className:"space-y-3",children:Object.entries(Da).map(([x,A])=>{const L=A.filter(Ue=>k.includes(Ue)&&!f.includes(Ue)).length,Ne=pe===x;return e.jsxs("div",{className:"border border-[#dde3eb] rounded-xl bg-white overflow-hidden shadow-sm",children:[e.jsxs("button",{onClick:()=>De(Ne?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:[A.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:[L," selected"]}),Ne?e.jsx(Na,{size:18,className:"text-slate-400"}):e.jsx(Ht,{size:18,className:"text-slate-400"})]})]}),e.jsx(Qt,{children:Ne&&e.jsx(Re.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:A.map((Ue,_e)=>{const St=k.includes(Ue),na=f.includes(Ue),ct=St&&!na;let kt="Core";return _e%3===0&&(kt="Foundation"),_e%3===2&&(kt="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 ${ct?"bg-[#9b51e0] border-[#9b51e0]":"border-2 border-[#dde3eb] bg-white"}`,children:ct&&e.jsx(gs,{size:14,className:"text-white"})}),e.jsx("input",{type:"checkbox",className:"hidden",checked:ct,onChange:()=>Al(Ue)}),e.jsx("span",{className:`text-sm font-semibold ${ct?"text-[#0a1628]":"text-[#5a6578]"}`,children:Ue})]}),e.jsx("span",{className:`border px-3 py-1 rounded-full text-[10px] uppercase font-bold tracking-wider ${kt==="Advanced"?"bg-white text-slate-400 border-[#dde3eb]":"bg-purple-50 text-[#9b51e0] border-purple-100"}`,children:kt})]},Ue)})})})})]},x)})})]}),d==="style"&&!me&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"bg-white border border-[#dde3eb] rounded-xl overflow-hidden shadow-sm",children:[e.jsx("div",{className:"px-5 py-4 border-b border-[#dde3eb]",children:e.jsx("p",{className:"text-xs font-bold text-slate-400 uppercase tracking-wider",children:"QUESTION TYPES"})}),e.jsx("div",{className:"p-5 grid grid-cols-1 md:grid-cols-3 gap-4",children:Object.entries(ca).map(([x,A])=>{const L=S.includes(x);return e.jsxs("button",{onClick:()=>Ml(x),className:`flex flex-col items-center justify-center p-4 rounded-xl border-2 transition-all ${L?"bg-purple-50 border-purple-300":"bg-white border-[#dde3eb] hover:border-purple-200"}`,children:[e.jsx("div",{className:`w-8 h-8 rounded-full flex items-center justify-center mb-2 ${L?"bg-purple-200 text-[#9b51e0]":"bg-[#edf1f7] text-slate-400"}`,children:A.icon}),e.jsx("span",{className:`text-sm font-semibold ${L?"text-purple-800":"text-[#5a6578]"}`,children:A.label})]},x)})})]}),e.jsxs("div",{className:"bg-white border border-[#dde3eb] rounded-xl overflow-hidden shadow-sm",children:[e.jsx("div",{className:"px-5 py-4 border-b border-[#dde3eb]",children:e.jsx("p",{className:"text-xs font-bold text-slate-400 uppercase tracking-wider",children:"BLOOM'S TAXONOMY LEVELS"})}),e.jsx("div",{className:"p-5 flex flex-wrap gap-3",children:Object.entries(Va).map(([x,A])=>{const L=j.includes(x);return e.jsx("button",{onClick:()=>Ll(x),className:`px-5 py-2.5 rounded-full border-2 transition-all text-sm font-semibold capitalize ${L?"bg-white text-[#9b51e0] border-purple-300":"bg-white border-[#dde3eb] text-[#5a6578] hover:border-purple-200"}`,children:x},x)})})]}),e.jsxs("div",{className:"bg-white border border-[#dde3eb] rounded-xl overflow-hidden shadow-sm",children:[e.jsx("div",{className:"px-5 py-4 border-b border-[#dde3eb]",children:e.jsx("p",{className:"text-xs font-bold text-slate-400 uppercase tracking-wider",children:"DIFFICULTY DISTRIBUTION"})}),e.jsx("div",{className:"p-5 space-y-5",children:Object.entries(T).map(([x,A])=>{const Ne={easy:"bg-[#55b963]",medium:"bg-[#faa541]",hard:"bg-[#f47a75]"}[x];return e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("span",{className:"text-sm font-semibold w-16 capitalize text-[#5a6578]",children:x}),e.jsx("div",{className:"flex-1 h-2 bg-[#edf1f7] rounded-full overflow-hidden",children:e.jsx(Re.div,{animate:{width:`${A}%`},className:`h-full rounded-full ${Ne}`})}),e.jsxs("div",{className:"flex items-center gap-1 w-20 justify-end",children:[e.jsx("button",{onClick:()=>Vr(x,-5),className:"w-6 h-6 rounded border border-[#dde3eb] flex items-center justify-center hover:bg-[#edf1f7] text-slate-500",children:e.jsx(jo,{size:10})}),e.jsxs("span",{className:"text-sm font-bold w-10 text-center text-slate-500",children:[A,"%"]}),e.jsx("button",{onClick:()=>Vr(x,5),className:"w-6 h-6 rounded border border-[#dde3eb] flex items-center justify-center hover:bg-[#edf1f7] text-slate-500",children:e.jsx(ma,{size:10})})]})]},x)})})]})]}),d==="preview"&&!me&&!V&&e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"bg-white border border-[#dde3eb] rounded-xl overflow-hidden shadow-sm",children:[e.jsx("div",{className:"px-5 py-4 border-b border-[#dde3eb]",children:e.jsx("p",{className:"text-xs font-bold text-slate-400 uppercase tracking-wider",children:"QUIZ SUMMARY"})}),e.jsxs("div",{className:"p-5",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4 mb-6",children:[e.jsxs("div",{className:"bg-purple-50 rounded-xl p-6 text-center border border-purple-100",children:[e.jsx("p",{className:"text-3xl font-bold text-purple-800 mb-1",children:h}),e.jsx("p",{className:"text-sm text-purple-600 font-medium",children:"questions"})]}),e.jsxs("div",{className:"bg-purple-50 rounded-xl p-6 text-center border border-purple-100",children:[e.jsx("p",{className:"text-3xl font-bold text-purple-800 mb-1",children:k.filter(x=>!f.includes(x)).length}),e.jsx("p",{className:"text-sm text-purple-600 font-medium",children:"topics"})]}),e.jsxs("div",{className:"bg-purple-50 rounded-xl p-6 text-center border border-purple-100",children:[e.jsx("p",{className:"text-3xl font-bold text-purple-800 mb-1",children:N.replace("Grade ","Gr. ")}),e.jsx("p",{className:"text-sm text-purple-600 font-medium",children:"level"})]})]}),e.jsxs("div",{className:"bg-[#f7f9fc] rounded-lg p-5 border border-[#dde3eb] text-sm text-[#5a6578] leading-relaxed",children:[S.map(x=>ca[x]?.label).join(" and ")," questions across ",k.filter(x=>!f.includes(x)).length," topics — aligned to ",j.map(x=>Va[x]?.label).join(", ")," levels of Bloom's Taxonomy. Easy ",T.easy,"% · Medium ",T.medium,"% · Hard ",T.hard,"%."]})]})]})}),d==="results"&&V&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"bg-gradient-to-br from-sky-50 to-cyan-50 border border-sky-200 rounded-xl p-5",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:Bl,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?e.jsx(gs,{size:14,className:"text-green-500"}):e.jsx(Li,{size:14}),E?"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(gr,{size:14}),"Export JSON"]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[e.jsxs("div",{className:"bg-white rounded-xl p-3 text-center",children:[e.jsx("p",{className:"text-2xl font-bold text-sky-600",children:V.questions.length}),e.jsx("p",{className:"text-xs text-[#5a6578]",children:"Questions"})]}),e.jsxs("div",{className:"bg-white rounded-xl p-3 text-center",children:[e.jsx("p",{className:"text-2xl font-bold text-rose-600",children:V.totalPoints}),e.jsx("p",{className:"text-xs text-[#5a6578]",children:"Total Points"})]}),e.jsxs("div",{className:"bg-white rounded-xl p-3 text-center",children:[e.jsx("p",{className:"text-2xl font-bold text-rose-600",children:Object.keys(V.metadata.topicsCovered).length}),e.jsx("p",{className:"text-xs text-[#5a6578]",children:"Topics"})]}),e.jsxs("div",{className:"bg-white rounded-xl p-3 text-center",children:[e.jsx("p",{className:"text-2xl font-bold text-emerald-600",children:Object.keys(V.metadata.bloomTaxonomyDistribution).length}),e.jsx("p",{className:"text-xs text-[#5a6578]",children:"Bloom Levels"})]})]}),(V.metadata.usedImportedTopics||(V.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: ",V.metadata.usedImportedTopics?"Yes":"No"," • ","Materials: ",V.metadata.importedMaterialsCount??0," • ","Topics: ",V.metadata.importedTopicCount??0]}),(V.metadata.topicProvenance||[]).slice(0,5).map((x,A)=>e.jsxs("div",{className:"text-xs text-[#5a6578]",children:[x.title||"Untitled topic",x.sourceFile?` • ${x.sourceFile}`:""]},`${x.topicId||x.title||"topic"}_${A}`)),(Ur.length>0||Wr.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:ge,onChange:x=>He(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"}),Ur.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:Je,onChange:x=>Xe(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"}),Wr.map(x=>e.jsx("option",{value:x,children:x},x))]})]})]}),e.jsxs("p",{className:"text-[11px] text-[#5a6578] mt-2",children:["Showing ",za.length," of ",V.questions.length," questions after provenance filters."]})]}),e.jsxs("div",{className:"mt-4 grid grid-cols-1 md:grid-cols-3 gap-3",children:[e.jsxs("div",{className:"bg-white rounded-lg p-3",children:[e.jsx("p",{className:"text-xs font-semibold text-[#5a6578] mb-2",children:"Difficulty"}),Object.entries(V.metadata.difficultyBreakdown).map(([x,A])=>e.jsxs("div",{className:"flex justify-between text-xs",children:[e.jsx("span",{className:`capitalize ${On[x]||"text-[#5a6578]"}`,children:x}),e.jsx("span",{className:"font-medium",children:A})]},x))]}),e.jsxs("div",{className:"bg-white rounded-lg p-3",children:[e.jsx("p",{className:"text-xs font-semibold text-[#5a6578] mb-2",children:"Bloom's Taxonomy"}),Object.entries(V.metadata.bloomTaxonomyDistribution).map(([x,A])=>e.jsxs("div",{className:"flex justify-between text-xs",children:[e.jsx("span",{className:"capitalize",children:x}),e.jsx("span",{className:"font-medium",children:A})]},x))]}),e.jsxs("div",{className:"bg-white rounded-lg p-3",children:[e.jsx("p",{className:"text-xs font-semibold text-[#5a6578] mb-2",children:"Question Types"}),Object.entries(V.metadata.questionTypeBreakdown).map(([x,A])=>e.jsxs("div",{className:"flex justify-between text-xs",children:[e.jsx("span",{children:ca[x]?.label||x}),e.jsx("span",{className:"font-medium",children:A})]},x))]})]}),e.jsxs("div",{className:"mt-3 bg-sky-50 rounded-lg p-3 flex items-start gap-2",children:[e.jsx(tr,{size:14,className:"text-sky-400 flex-shrink-0 mt-0.5"}),e.jsx("p",{className:"text-xs text-sky-600",children:V.metadata.supplementalPurpose})]}),V.metadata.recommendedTeacherActions&&e.jsxs("div",{className:"mt-3",children:[e.jsx("p",{className:"text-xs font-semibold text-[#5a6578] mb-1",children:"Recommended Actions:"}),e.jsx("ul",{className:"list-disc list-inside text-xs text-[#5a6578] space-y-0.5",children:V.metadata.recommendedTeacherActions.map((x,A)=>e.jsx("li",{children:x},A))})]})]}),e.jsx("div",{className:"space-y-3",children:za.length>0?za.map((x,A)=>Ul(x,A)):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."})})]})]})]}),i==="create"&&e.jsxs("div",{className:"border-t border-[#dde3eb] px-6 sm:px-6 xl:px-10 py-4 bg-[#f7f9fc] flex items-center justify-between flex-shrink-0",children:[d==="setup"&&!me&&e.jsxs(e.Fragment,{children:[e.jsx("div",{}),e.jsxs("button",{onClick:()=>u("topics"),className:"bg-white border border-[#dde3eb] text-[#edf1f7] px-6 py-2.5 rounded-lg text-sm font-semibold transition-colors hover:text-slate-600 flex items-center",children:[e.jsx("span",{className:"text-[#edf1f7]",children:"Next: Topics"})," ",e.jsx(Wt,{size:16,className:"ml-2 text-slate-300"})]})]}),d==="topics"&&!me&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("button",{onClick:()=>{y([]),v([])},className:"text-[#9b51e0] text-sm font-semibold hover:underline",children:"Clear all"}),e.jsxs("span",{className:"text-sm text-[#9b51e0]",children:[k.filter(x=>!f.includes(x)).length," of ",xs," topics selected"]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{onClick:()=>u("setup"),className:"bg-white border border-[#dde3eb] text-[#5a6578] px-5 py-2.5 rounded-lg text-sm font-semibold transition-colors hover:bg-[#edf1f7] flex items-center",children:[e.jsx(Pt,{size:16,className:"mr-2 text-slate-400"})," Back"]}),e.jsxs("button",{onClick:()=>u("style"),className:"bg-[#9b51e0] text-white px-6 py-2.5 rounded-lg text-sm font-semibold transition-colors hover:bg-purple-700 flex items-center shadow-md",children:["Next: Question style ",e.jsx(Wt,{size:16,className:"ml-2 text-purple-200"})]})]})]}),d==="style"&&!me&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:()=>u("topics"),className:"bg-white border border-[#dde3eb] text-[#5a6578] px-5 py-2.5 rounded-lg text-sm font-semibold transition-colors hover:bg-[#edf1f7] flex items-center",children:[e.jsx(Pt,{size:16,className:"mr-2 text-slate-400"})," Back"]}),e.jsxs("button",{onClick:()=>u("preview"),className:"bg-[#9b51e0] text-white px-6 py-2.5 rounded-lg text-sm font-semibold transition-colors hover:bg-purple-700 flex items-center shadow-md",children:["Preview ",e.jsx(Wt,{size:16,className:"ml-2 text-purple-200"})]})]}),d==="preview"&&!me&&!V&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:()=>u("style"),className:"bg-white border border-[#dde3eb] text-[#5a6578] px-5 py-2.5 rounded-lg text-sm font-semibold transition-colors hover:bg-[#edf1f7] flex items-center",children:[e.jsx(Pt,{size:16,className:"mr-2 text-slate-400"})," Back"]}),e.jsxs("button",{onClick:Fl,className:"bg-[#9b51e0] text-white px-6 py-2.5 rounded-lg text-sm font-bold transition-colors hover:bg-purple-700 flex items-center shadow-md",children:[e.jsx(gs,{size:16,className:"mr-2"})," Generate quiz"]})]}),me&&e.jsx("div",{className:"w-full flex items-center justify-center",children:e.jsxs("div",{className:"flex items-center gap-3 text-slate-500 font-medium text-sm",children:[e.jsx(nt,{size:16,className:"animate-spin"})," Generating quiz... Please wait."]})}),d==="results"&&(Hr?e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>{c("bank"),ra(null)},className:"px-4 py-2.5 rounded-xl text-sm font-medium bg-white border border-[#dde3eb] text-[#5a6578] hover:bg-[#edf1f7] transition-colors",children:"Back to Quiz Bank"}),e.jsxs("button",{onClick:()=>$a(Hr),className:"flex items-center gap-2 px-4 py-2.5 rounded-xl text-sm font-semibold bg-sky-50 border border-sky-300 text-sky-700 hover:bg-sky-100 transition-colors",children:[e.jsx(zs,{size:16})," Assign"]}),e.jsx("button",{onClick:Ba,className:"px-5 py-2.5 rounded-xl text-sm font-bold bg-gradient-to-r from-sky-600 to-sky-500 hover:from-sky-700 hover:to-sky-600 text-white transition-all",children:"Done"})]}):e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>{u("setup"),we(null),ke(null),Te(null),ra(null)},className:"px-4 py-2.5 rounded-xl text-sm font-medium bg-white border border-[#dde3eb] text-[#5a6578] hover:bg-[#edf1f7] transition-colors",children:"Create Another"}),Be?e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:Pl,disabled:tt,className:"flex items-center gap-2 px-4 py-2.5 rounded-xl text-sm font-semibold bg-green-50 border border-green-300 text-green-700 hover:bg-green-100 transition-colors",children:[tt?e.jsx(nt,{size:16,className:"animate-spin"}):e.jsx(ka,{size:16}),"Publish"]}),e.jsxs("button",{onClick:()=>$a(),className:"flex items-center gap-2 px-4 py-2.5 rounded-xl text-sm font-semibold bg-sky-50 border border-sky-300 text-sky-700 hover:bg-sky-100 transition-colors",children:[e.jsx(zs,{size:16})," Assign"]})]}):e.jsxs("button",{onClick:Ol,disabled:U,className:"flex items-center gap-2 px-4 py-2.5 rounded-xl text-sm font-semibold bg-emerald-50 border border-emerald-300 text-emerald-700 hover:bg-emerald-100 transition-colors",children:[U?e.jsx(nt,{size:16,className:"animate-spin"}):e.jsx(yo,{size:16}),"Save to Library"]}),e.jsx("button",{onClick:Ba,className:"px-5 py-2.5 rounded-xl text-sm font-bold bg-gradient-to-r from-sky-600 to-sky-500 hover:from-sky-700 hover:to-sky-600 text-white transition-all",children:"Done"})]}))]}),e.jsx(om,{isOpen:I,onClose:()=>Y(!1)}),e.jsx(Qt,{children:Aa&&e.jsx(Re.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:()=>es(!1),children:e.jsxs(Re.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(Ps,{size:18,className:"text-sky-600"}),"Assign to Student"]}),e.jsx("button",{onClick:()=>es(!1),className:"p-1 hover:bg-[#edf1f7] rounded-lg transition-colors",children:e.jsx(va,{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(Js,{size:14,className:"text-slate-500"}),e.jsx("input",{type:"text",placeholder:"Search students…",value:Ma,onChange:x=>Br(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:Tl?e.jsx("div",{className:"flex items-center justify-center py-10",children:e.jsx(nt,{size:20,className:"animate-spin text-sky-500"})}):Xr.length===0?e.jsx("p",{className:"text-center text-sm text-slate-500 py-10",children:"No students found"}):Xr.map(x=>e.jsxs("button",{onClick:()=>$r(x.id),className:`w-full flex items-center gap-3 px-3 py-2.5 rounded-xl text-left transition-colors ${ts===x.id?"bg-sky-50 border border-sky-300":"hover:bg-[#edf1f7] border border-transparent"}`,children:[e.jsx("img",{src:x.avatar||`https://ui-avatars.com/api/?name=${encodeURIComponent(x.name)}&background=random&size=32`,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})]}),ts===x.id&&e.jsx(gs,{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:()=>es(!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:_l,disabled:!ts||ks,className:`flex items-center gap-2 px-4 py-2 rounded-xl text-sm font-bold transition-all ${ts&&!ks?"bg-gradient-to-r from-sky-600 to-sky-500 text-white shadow-sm":"bg-[#dde3eb] text-slate-500 cursor-not-allowed"}`,children:[ks?e.jsx(nt,{size:14,className:"animate-spin"}):e.jsx(zs,{size:14}),"Assign"]})]})]})})})]})};function Ka({className:t,...s}){return e.jsx(fi,{"data-slot":"label",className:hr("flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",t),...s})}const um=()=>{const[t,s]=p.useState([]),[a,r]=p.useState(!1),[n,o]=p.useState(!1),[l,i]=p.useState(""),[c,d]=p.useState(11),[u,N]=p.useState("general_mathematics"),m=p.useCallback(async()=>{r(!0);try{const y=await en("/api/quiz-battle/bank-status");s(y.pdfs)}catch(y){const f=y instanceof Os?y.message:"Failed to load bank status";ce.error(f)}finally{r(!1)}},[]);p.useEffect(()=>{m()},[m]);const h=async()=>{if(!l.trim()){ce.error("Please enter a storage path");return}o(!0);try{await en("/api/quiz-battle/ingest-pdf",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({storage_path:l.trim(),grade_level:c,topic:u.trim(),force_reingest:!1})}),ce.success("PDF ingestion completed"),await m(),i("")}catch(y){const f=y instanceof Os?y.message:"Ingestion failed";ce.error(f)}finally{o(!1)}},w=t.reduce((y,f)=>y+f.question_count,0),k=t.filter(y=>y.processed).length;return e.jsxs("div",{className:"space-y-6 p-6 max-w-6xl mx-auto",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2.5 bg-[#9956DE]/12 rounded-xl border border-[#9956DE]/30",children:e.jsx(Vt,{className:"h-5 w-5 text-[#9956DE]"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-display font-bold text-foreground",children:"Question Bank"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Manage PDF-ingested quiz questions for battle sessions"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:[e.jsxs(Ts,{children:[e.jsx(Is,{className:"pb-2",children:e.jsxs(Es,{className:"text-sm font-medium text-muted-foreground flex items-center gap-2",children:[e.jsx(fr,{className:"h-4 w-4"}),"Total PDFs"]})}),e.jsx(Rs,{children:e.jsx("div",{className:"text-3xl font-display font-bold text-foreground",children:t.length})})]}),e.jsxs(Ts,{children:[e.jsx(Is,{className:"pb-2",children:e.jsxs(Es,{className:"text-sm font-medium text-muted-foreground flex items-center gap-2",children:[e.jsx(Vt,{className:"h-4 w-4"}),"Total Questions"]})}),e.jsx(Rs,{children:e.jsx("div",{className:"text-3xl font-display font-bold text-foreground",children:w})})]}),e.jsxs(Ts,{children:[e.jsx(Is,{className:"pb-2",children:e.jsxs(Es,{className:"text-sm font-medium text-muted-foreground flex items-center gap-2",children:[e.jsx(_s,{className:"h-4 w-4"}),"Processed"]})}),e.jsx(Rs,{children:e.jsx("div",{className:"text-3xl font-display font-bold text-foreground",children:k})})]})]}),e.jsxs(Ts,{children:[e.jsx(Is,{children:e.jsx(Es,{className:"text-base font-display font-bold",children:"Ingest New PDF"})}),e.jsxs(Rs,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ka,{htmlFor:"storagePath",children:"Firebase Storage Path"}),e.jsx(vt,{id:"storagePath",placeholder:"quiz_pdfs/grade_11/general_math.pdf",value:l,onChange:y=>i(y.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ka,{htmlFor:"gradeLevel",children:"Grade Level"}),e.jsx(vt,{id:"gradeLevel",type:"number",min:7,max:12,value:c,onChange:y=>d(Number(y.target.value))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ka,{htmlFor:"topic",children:"Topic Slug"}),e.jsx(vt,{id:"topic",placeholder:"general_mathematics",value:u,onChange:y=>N(y.target.value)})]})]}),e.jsxs($e,{onClick:h,disabled:n,className:"bg-[#9956DE] hover:bg-[#9956DE]/90",children:[n?e.jsx(nt,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(Di,{className:"mr-2 h-4 w-4"}),"Ingest PDF"]})]})]}),e.jsxs(Ts,{children:[e.jsxs(Is,{className:"flex flex-row items-center justify-between",children:[e.jsx(Es,{className:"text-base font-display font-bold",children:"Processing Status"}),e.jsx($e,{variant:"outline",size:"sm",onClick:m,disabled:a,children:e.jsx(_s,{className:`h-4 w-4 ${a?"animate-spin":""}`})})]}),e.jsx(Rs,{children:e.jsxs(Ii,{children:[e.jsx(Ei,{children:e.jsxs(_a,{children:[e.jsx(ms,{children:"Filename"}),e.jsx(ms,{children:"Grade"}),e.jsx(ms,{children:"Topic"}),e.jsx(ms,{children:"Questions"}),e.jsx(ms,{children:"Status"}),e.jsx(ms,{children:"Processed At"})]})}),e.jsxs(Ri,{children:[t.map(y=>e.jsxs(_a,{children:[e.jsx(ss,{className:"font-medium",children:y.filename}),e.jsx(ss,{children:y.grade_level}),e.jsx(ss,{children:y.topic}),e.jsx(ss,{children:y.question_count}),e.jsx(ss,{children:e.jsx("span",{className:`inline-flex items-center px-2 py-1 rounded-full text-xs font-medium ${y.processed?"bg-emerald-100 text-emerald-800 dark:bg-emerald-900/30 dark:text-emerald-300":"bg-yellow-100 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-300"}`,children:y.processed?"Processed":"Pending"})}),e.jsx(ss,{children:y.timestamp?new Date(y.timestamp).toLocaleDateString():"-"})]},y.filename)),t.length===0&&e.jsx(_a,{children:e.jsx(ss,{colSpan:6,className:"text-center text-muted-foreground py-8",children:"No PDFs processed yet. Upload a PDF to get started."})})]})]})})]})]})},Pn={totalTopicsTracked:0,masteredCount:0,needsAttentionCount:0,excludedCount:0},xm={"gen-math":{label:"GEN MATH",color:"bg-sky-100 text-sky-700"},"stats-prob":{label:"STAT&PROB",color:"bg-sky-100 text-sky-700"},"pre-calc":{label:"PRE-CALC",color:"bg-orange-100 text-orange-700"},"basic-calc":{label:"BASIC CALC",color:"bg-red-100 text-red-700"}},hm={mastered:{label:"MASTERED BY CLASS",color:"bg-green-100 text-green-700 border-green-300"},on_track:{label:"ON TRACK",color:"bg-sky-100 text-sky-700 border-sky-300"},needs_attention:{label:"NEEDS ATTENTION",color:"bg-red-100 text-red-700 border-red-300"},no_data:{label:"NO DATA YET",color:"bg-[#edf1f7] text-[#5a6578] border-[#dde3eb]"}},_n={needs_attention:0,on_track:1,no_data:2,mastered:3},pm=({classSectionId:t})=>{const{currentUser:s}=Ks(),[a,r]=p.useState([]),[n,o]=p.useState(Pn),[l,i]=p.useState(!0),[c,d]=p.useState("all"),[u,N]=p.useState("all"),[m,h]=p.useState(""),[w,k]=p.useState("classAverage"),[y,f]=p.useState("asc"),v=rn.map(D=>D.id),S=rn.reduce((D,te)=>(D[te.id]=te.name,D),{}),{isLoading:R}=$i();p.useEffect(()=>{},[R]);const[j,B]=p.useState(new Set),[g,b]=p.useState([]),T=zi({queryKey:ql.topicMastery(s?.uid||"anonymous",t),enabled:!!s,staleTime:120*1e3,gcTime:900*1e3,queryFn:async()=>{try{if(!s)return{excluded:[],topics:[],summary:{totalTopicsTracked:0,masteredCount:0,needsAttentionCount:0,excludedCount:0}};const D=et(Ge,"teachers",s.uid,"settings","quizSettings"),te=await ns(D),J=te.exists()?te.data()?.excludedTopics||[]:[],me="https://deign86-mathpulse-api-v3test.hf.space",Ce=new URLSearchParams({teacherId:s.uid});t&&Ce.set("classSectionId",t);const F=await s.getIdToken(),C=await fetch(`${me}/api/analytics/topic-mastery?${Ce.toString()}`,{headers:{Authorization:`Bearer ${F}`}});if(!C.ok)return{excluded:J,topics:[],summary:{totalTopicsTracked:0,masteredCount:0,needsAttentionCount:0,excludedCount:J.length}};const K=await C.json(),P=(K.topics||[]).map(xe=>({...xe,isExcluded:J.includes(xe.topicName)}));return{excluded:J,topics:P,summary:K.summary||{totalTopicsTracked:0,masteredCount:0,needsAttentionCount:0,excludedCount:J.length}}}catch{return{excluded:[],topics:[],summary:{totalTopicsTracked:0,masteredCount:0,needsAttentionCount:0,excludedCount:0}}}}});p.useEffect(()=>{if(i(T.isLoading||T.isFetching),!T.data){b([]),r([]),o(Pn),B(new Set);return}b(T.data.excluded),r(T.data.topics),o(T.data.summary)},[T.data,T.isFetching,T.isLoading]);const z=async D=>{if(!s)return;const te=g.includes(D)?g.filter(J=>J!==D):[...g,D];b(te),r(J=>J.map(me=>me.topicName===D?{...me,isExcluded:!me.isExcluded}:me)),o(J=>({...J,excludedCount:te.length}));try{const J=et(Ge,"teachers",s.uid,"settings","quizSettings");(await ns(J)).exists()?await yt(J,{excludedTopics:te}):await Ut(J,{excludedTopics:te})}catch{ce.error("Failed to update excluded topics")}},$=async()=>{if(!s)return;const D=[...new Set([...g,...j])];b(D),r(te=>te.map(J=>j.has(J.topicName)?{...J,isExcluded:!0}:J)),o(te=>({...te,excludedCount:D.length})),B(new Set);try{const te=et(Ge,"teachers",s.uid,"settings","quizSettings");(await ns(te)).exists()?await yt(te,{excludedTopics:D}):await Ut(te,{excludedTopics:D}),ce.success(`${j.size} topics excluded from quizzes`)}catch{ce.error("Failed to update")}},Z=async()=>{if(!s)return;const D=g.filter(te=>!j.has(te));b(D),r(te=>te.map(J=>j.has(J.topicName)?{...J,isExcluded:!1}:J)),o(te=>({...te,excludedCount:D.length})),B(new Set);try{const te=et(Ge,"teachers",s.uid,"settings","quizSettings");(await ns(te)).exists()?await yt(te,{excludedTopics:D}):await Ut(te,{excludedTopics:D}),ce.success(`${j.size} topics re-included in quizzes`)}catch{ce.error("Failed to update")}},ae=D=>{w===D?f(te=>te==="asc"?"desc":"asc"):(k(D),f("asc"))},H=u==="all"?v:Fi(u);p.useEffect(()=>{c!=="all"&&(H.includes(c)||d("all"))},[H,c]);const ee=a.filter(D=>!(c!=="all"&&D.subjectId!==c||!H.includes(D.subjectId)||m&&!D.topicName.toLowerCase().includes(m.toLowerCase()))).sort((D,te)=>{const J=y==="asc"?1:-1;switch(w){case"topicName":return J*D.topicName.localeCompare(te.topicName);case"classAverage":return J*(D.classAverage-te.classAverage);case"studentsAttempted":return J*(D.studentsAttempted-te.studentsAttempted);case"masteryStatus":return J*((_n[D.masteryStatus]||0)-(_n[te.masteryStatus]||0));default:return 0}}),re=()=>{j.size===ee.length?B(new Set):B(new Set(ee.map(D=>D.topicName)))},ne=({field:D})=>w!==D?e.jsx(Ht,{size:12,className:"text-slate-500"}):y==="asc"?e.jsx(Na,{size:12,className:"text-sky-600"}):e.jsx(Ht,{size:12,className:"text-sky-600"});return l?e.jsxs("div",{className:"flex items-center justify-center py-20",children:[e.jsx(nt,{size:24,className:"animate-spin text-sky-500"}),e.jsx("span",{className:"ml-2 text-[#5a6578]",children:"Loading topic mastery data..."})]}):e.jsxs(Re.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},exit:{opacity:0,y:-20},className:"p-6 space-y-6",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-bold text-[#0a1628]",children:"Class Topic Mastery"}),e.jsx("p",{className:"text-sm text-[#5a6578] mt-1",children:"Topics where 75% or more of the class scored 85%+ are marked as mastered and can be excluded from future quiz generation."})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"bg-white rounded-2xl p-5 shadow-sm border border-[#dde3eb]",children:[e.jsx("div",{className:"flex items-center gap-3 mb-2",children:e.jsx("div",{className:"w-10 h-10 bg-sky-100 rounded-xl flex items-center justify-center",children:e.jsx(Hs,{size:20,className:"text-sky-600"})})}),e.jsx("p",{className:"text-2xl font-bold text-[#0a1628]",children:n.totalTopicsTracked}),e.jsx("p",{className:"text-xs text-[#5a6578]",children:"Total Topics Tracked"})]}),e.jsxs("div",{className:"bg-white rounded-2xl p-5 shadow-sm border border-green-200",children:[e.jsx("div",{className:"flex items-center gap-3 mb-2",children:e.jsx("div",{className:"w-10 h-10 bg-green-100 rounded-xl flex items-center justify-center",children:e.jsx(ja,{size:20,className:"text-green-600"})})}),e.jsx("p",{className:"text-2xl font-bold text-green-600",children:n.masteredCount}),e.jsx("p",{className:"text-xs text-[#5a6578]",children:"Mastered by Class"})]}),e.jsxs("div",{className:"bg-white rounded-2xl p-5 shadow-sm border border-red-200",children:[e.jsx("div",{className:"flex items-center gap-3 mb-2",children:e.jsx("div",{className:"w-10 h-10 bg-red-100 rounded-xl flex items-center justify-center",children:e.jsx(Gt,{size:20,className:"text-red-600"})})}),e.jsx("p",{className:"text-2xl font-bold text-red-600",children:n.needsAttentionCount}),e.jsx("p",{className:"text-xs text-[#5a6578]",children:"Needs Work"})]}),e.jsxs("div",{className:"bg-white rounded-2xl p-5 shadow-sm border border-[#dde3eb]",children:[e.jsx("div",{className:"flex items-center gap-3 mb-2",children:e.jsx("div",{className:"w-10 h-10 bg-[#edf1f7] rounded-xl flex items-center justify-center",children:e.jsx(Ti,{size:20,className:"text-[#5a6578]"})})}),e.jsx("p",{className:"text-2xl font-bold text-[#5a6578]",children:n.excludedCount}),e.jsx("p",{className:"text-xs text-[#5a6578]",children:"Excluded Topics"})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 bg-white rounded-xl px-3 py-2 border border-[#dde3eb]",children:[e.jsx(Js,{size:14,className:"text-slate-500"}),e.jsx("input",{type:"text",placeholder:"Search topics...",value:m,onChange:D=>h(D.target.value),className:"bg-transparent text-sm outline-none w-40 placeholder:text-slate-500"})]}),e.jsxs("select",{value:c,onChange:D=>d(D.target.value),className:"bg-white border border-[#dde3eb] rounded-xl px-3 py-2 text-sm outline-none",children:[e.jsx("option",{value:"all",children:"All Subjects"}),H.map(D=>e.jsx("option",{value:D,children:S[D]||D},D))]}),e.jsxs("select",{value:u,onChange:D=>N(D.target.value),className:"bg-white border border-[#dde3eb] rounded-xl px-3 py-2 text-sm outline-none",children:[e.jsx("option",{value:"all",children:"All Grades"}),Bi.map(D=>e.jsx("option",{value:D,children:D},D))]})]}),e.jsx(Qt,{children:j.size>0&&e.jsxs(Re.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},className:"bg-sky-50 border border-sky-200 rounded-xl p-3 flex items-center gap-3 flex-wrap overflow-hidden",children:[e.jsxs("span",{className:"text-sm font-semibold text-sky-700",children:[j.size," topics selected"]}),e.jsx("button",{onClick:$,className:"px-3 py-1.5 bg-[#5a6578] text-white text-xs font-bold rounded-lg hover:bg-sky-600 transition-colors",children:"Exclude Selected Topics"}),e.jsx("button",{onClick:Z,className:"px-3 py-1.5 bg-green-600 text-white text-xs font-bold rounded-lg hover:bg-green-700 transition-colors",children:"Include Selected Topics"}),e.jsx("button",{onClick:()=>B(new Set),className:"px-3 py-1.5 bg-white border border-[#dde3eb] text-[#5a6578] text-xs font-bold rounded-lg hover:bg-[#edf1f7] transition-colors",children:"Clear Selection"})]})}),e.jsx("div",{className:"bg-white rounded-2xl shadow-sm border border-[#dde3eb] overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-left",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-[#edf1f7] border-b border-[#dde3eb]",children:[e.jsx("th",{className:"px-4 py-3 w-10",children:e.jsx("input",{type:"checkbox",checked:j.size===ee.length&&ee.length>0,onChange:re,className:"w-4 h-4 rounded border-[#dde3eb] text-sky-600 focus:ring-sky-500"})}),e.jsx("th",{className:"px-4 py-3 text-xs font-bold text-[#5a6578] uppercase tracking-wide cursor-pointer hover:text-sky-600",onClick:()=>ae("topicName"),children:e.jsxs("span",{className:"flex items-center gap-1",children:["Topic Name ",e.jsx(ne,{field:"topicName"})]})}),e.jsx("th",{className:"px-4 py-3 text-xs font-bold text-[#5a6578] uppercase tracking-wide",children:"Unit"}),e.jsx("th",{className:"px-4 py-3 text-xs font-bold text-[#5a6578] uppercase tracking-wide cursor-pointer hover:text-sky-600",onClick:()=>ae("classAverage"),children:e.jsxs("span",{className:"flex items-center gap-1",children:["Class Avg % ",e.jsx(ne,{field:"classAverage"})]})}),e.jsx("th",{className:"px-4 py-3 text-xs font-bold text-[#5a6578] uppercase tracking-wide cursor-pointer hover:text-sky-600",onClick:()=>ae("studentsAttempted"),children:e.jsxs("span",{className:"flex items-center gap-1",children:["Students ",e.jsx(ne,{field:"studentsAttempted"})]})}),e.jsx("th",{className:"px-4 py-3 text-xs font-bold text-[#5a6578] uppercase tracking-wide cursor-pointer hover:text-sky-600",onClick:()=>ae("masteryStatus"),children:e.jsxs("span",{className:"flex items-center gap-1",children:["Status ",e.jsx(ne,{field:"masteryStatus"})]})}),e.jsx("th",{className:"px-4 py-3 text-xs font-bold text-[#5a6578] uppercase tracking-wide",children:"Exclude"})]})}),e.jsx("tbody",{children:ee.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"px-4 py-16 text-center",children:a.length===0?e.jsxs("div",{className:"flex flex-col items-center gap-2",children:[e.jsx(Hs,{size:32,className:"text-[#dde3eb]"}),e.jsx("p",{className:"text-sm font-medium text-[#5a6578]",children:"No topic data available yet"}),e.jsx("p",{className:"text-xs text-[#a0aec0]",children:"Import student quiz data to see class topic mastery analytics."})]}):e.jsx("span",{className:"text-sm text-slate-500",children:"No topics match the current filters."})})}):ee.map(D=>{const te=j.has(D.topicName),J=hm[D.masteryStatus],me=xm[D.subjectId]||{label:D.subjectId.toUpperCase(),color:"bg-[#edf1f7] text-[#5a6578]"},Ce=D.classAverage<60?"bg-red-500":D.classAverage<85?"bg-rose-500":"bg-green-500",F=D.isExcluded?"bg-[#edf1f7] opacity-60":D.masteryStatus==="needs_attention"?"bg-red-50/30":D.masteryStatus==="mastered"?"bg-green-50/30":"";return e.jsxs("tr",{className:`border-b border-[#dde3eb] hover:bg-[#edf1f7] transition-colors ${F} ${D.isExcluded?"line-through decoration-slate-400":""}`,children:[e.jsx("td",{className:"px-4 py-3",children:e.jsx("input",{type:"checkbox",checked:te,onChange:()=>{const C=new Set(j);te?C.delete(D.topicName):C.add(D.topicName),B(C)},className:"w-4 h-4 rounded border-[#dde3eb] text-sky-600 focus:ring-sky-500"})}),e.jsx("td",{className:"px-4 py-3",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium text-[#0a1628]",children:D.topicName}),e.jsx("span",{className:`text-[10px] font-bold px-1.5 py-0.5 rounded ${me.color}`,children:me.label})]})}),e.jsx("td",{className:"px-4 py-3 text-xs text-[#5a6578]",children:D.unit}),e.jsx("td",{className:"px-4 py-3",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex-1 h-2 bg-[#edf1f7] rounded-full overflow-hidden max-w-20",children:e.jsx("div",{className:`h-full rounded-full e-w ${Ce}`,style:{"--w":`${D.classAverage}%`}})}),e.jsxs("span",{className:"text-xs font-bold text-[#0a1628] w-8 text-right",children:[D.classAverage,"%"]})]})}),e.jsxs("td",{className:"px-4 py-3 text-xs text-[#5a6578]",children:[D.studentsAttempted,"/",D.totalStudents]}),e.jsx("td",{className:"px-4 py-3",children:e.jsx("span",{className:`text-[10px] font-bold px-2 py-0.5 rounded border ${J.color}`,children:J.label})}),e.jsx("td",{className:"px-4 py-3",children:e.jsxs("div",{className:"group relative",children:[e.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:D.isExcluded,onChange:()=>z(D.topicName),className:"sr-only peer"}),e.jsx("div",{className:"w-9 h-5 bg-[#dde3eb] peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-0.5 after:left-[2px] after:bg-white after:border-[#dde3eb] after:border after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-[#5a6578]"})]}),e.jsx("div",{className:"hidden group-hover:block absolute z-20 bottom-full left-0 mb-1 px-2 py-1 bg-slate-800 text-white text-[10px] rounded whitespace-nowrap",children:"Excluded topics will not appear in AI-generated quizzes for your class"})]})})]},D.topicName)})})]})})})]})};function hl(t){return(t||"").trim().toLowerCase()}function Hn(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 n=hl(t.classSectionId),o=(t.id||"").trim().toLowerCase();return n&&o?`${n}|id:${o}`:o?`id:${o}`:`${n}|anonymous`}function fm(t,s){const a=[],r=(t.lrn||"").trim().toLowerCase(),n=(t.email||"").trim().toLowerCase(),o=t.name.trim().toLowerCase(),l=(t.id||"").trim().toLowerCase();return r&&a.push(`${s}|lrn:${r}`),n&&a.push(`${s}|email:${n}`),o&&a.push(`${s}|name:${o}`),l&&a.push(`${s}|id:${l}`),a.length===0&&a.push(`${s}|anonymous`),a}function gm(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 pl(t,s){const a=new Map,r=new Map,n=s?hl(s):"all";return t.forEach(o=>{const l=fm(o,n),i=l.map(u=>r.get(u)).find(Boolean)||l[0],c=a.get(i),d=c?gm(c,o):o;a.set(i,d),l.forEach(u=>r.set(u,i))}),Array.from(a.values())}function Gn(t,s){return pl([...t,...s])}function rs(t){return Number.isFinite(t)?Math.max(0,Math.min(100,t)):0}function bm(t){if(!t)return null;const s="gen-math",a=nn.find(l=>l.id===s)?.modules||[];if(a.length===0)return null;const r={mastery:0,concept:0,application:0,engagement:0,consistency:0},n=t.lessons??{};a.forEach(l=>{const i=nn.find(y=>y.modules.some(f=>f.id===l.id)),c=i?t?.subjects?.[i.id]?.modulesProgress?.[l.id]:null,d=rs(c?.progress||0),u=l.lessons.length?l.lessons.reduce((y,f)=>{const v=n?.[f.id]?.score;if(typeof v=="number"&&Number.isFinite(v))return y+rs(v);const S=!!c?.lessonsCompleted?.includes?.(f.id);return y+(S?100:0)},0)/l.lessons.length:0,N=l.quizzes.length?(c?.quizzesCompleted?.length||0)/l.quizzes.length*100:0,m=rs(u),h=rs(N),w=rs(Math.min(100,(m+h*2)/1.5)),k=rs(Math.min(100,40+d*.6));r.mastery+=d,r.concept+=m,r.application+=h,r.engagement+=w,r.consistency+=k});const o=a.length;return{mastery:Math.round(r.mastery/o),concept:Math.round(r.concept/o),application:Math.round(r.application/o),engagement:Math.round(r.engagement/o),consistency:Math.round(r.consistency/o)}}const Xa={High:{bg:"bg-red-100",text:"text-red-700",ring:"ring-red-300"},Medium:{bg:"bg-rose-100",text:"text-rose-700",ring:"ring-rose-300"},Low:{bg:"bg-green-100",text:"text-green-700",ring:"ring-green-300"}},Qn={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"}},Un=[{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:"Application"},{key:"engagement",short:"E",label:"Engagement",header:"Engagement"},{key:"consistency",short:"S",label:"Consistency",header:"Consistency"}];function vm(t){const s=rs(t);return s>=80?{bg:"bg-[color-mix(in_srgb,var(--chart-3)_14%,transparent)]",text:"text-[var(--chart-3)]",ring:"ring-[color-mix(in_srgb,var(--chart-3)_40%,transparent)]"}:s>=60?{bg:"bg-[color-mix(in_srgb,var(--chart-4)_14%,transparent)]",text:"text-[var(--chart-4)]",ring:"ring-[color-mix(in_srgb,var(--chart-4)_40%,transparent)]"}:{bg:"bg-[color-mix(in_srgb,var(--chart-2)_14%,transparent)]",text:"text-[var(--chart-2)]",ring:"ring-[color-mix(in_srgb,var(--chart-2)_40%,transparent)]"}}const Nm=({classSectionId:t,className:s,fallbackStudents:a=[]})=>{const{currentUser:r}=Ks(),n=p.useRef(0),[o,l]=p.useState([]),[i,c]=p.useState(!0),[d,u]=p.useState(""),[N,m]=p.useState("riskLevel"),[h,w]=p.useState("desc"),[k,y]=p.useState("all"),[f,v]=p.useState([]),[S,R]=p.useState(!1),[j,B]=p.useState(""),[g,b]=p.useState(""),T=p.useCallback(C=>({id:C.id,lrn:C.lrn||void 0,name:C.name,email:C.email||"",avatar:`https://ui-avatars.com/api/?name=${encodeURIComponent(C.name)}&background=random`,classSectionId:C.classSectionId??null,riskLevel:C.riskLevel||"Low",engagementScore:C.engagementScore,avgQuizScore:C.avgQuizScore,weakestTopic:C.weakestTopic||"Foundational Skills"}),[]),z=p.useCallback(C=>({id:C.id,lrn:C.lrn,name:C.name,email:C.email||"",avatar:C.avatar||`https://ui-avatars.com/api/?name=${encodeURIComponent(C.name)}&background=random`,classSectionId:C.classSectionId??null,riskLevel:String(C.riskLevel).charAt(0).toUpperCase()+String(C.riskLevel).slice(1).toLowerCase(),engagementScore:C.engagementScore,avgQuizScore:Number(C.avgQuizScore??C.avgScore??0),weakestTopic:C.weakestTopic||"Foundational Skills"}),[]),$=p.useCallback(async(C,K)=>{const P=new Map;C.forEach(M=>P.set(M.id,null));const xe=25;for(let M=0;M{try{const ie=await tn(le.id);return{studentId:le.id,summary:bm(ie)}}catch{return{studentId:le.id,summary:null}}}))).forEach((le,ie)=>{const V=G[ie]?.id;V&&(le.status==="fulfilled"?P.set(V,le.value.summary):P.set(V,null))})}n.current===K&&l(M=>M.map(G=>P.has(G.student.id)?{...G,competencyMatrix:P.get(G.student.id)??null,competencyMatrixLoading:!1}:G))},[]),Z=p.useCallback(async()=>{if(r?.uid){c(!0),b("");try{let K=(await Ar(r.uid)).map(G=>({id:G.id,name:G.name,email:G.email||"",avatar:G.avatar||`https://ui-avatars.com/api/?name=${encodeURIComponent(G.name)}&background=random`,classSectionId:G.classSectionId??null,riskLevel:G.riskLevel,engagementScore:G.engagementScore,avgQuizScore:G.avgQuizScore,weakestTopic:G.weakestTopic||"Foundational Skills"}));a.length>0&&(K=Gn(K,a.map(z))),t&&(K=K.filter(G=>G.classSectionId===t));const P=await Ve.getImportedClassOverview({classSectionId:t,limit:3e3});P.warnings.length>0&&b(P.warnings.join(" ")),K=Gn(K,P.students.map(T));const xe=pl(K,t),M=n.current+=1;l(xe.map((G,X)=>({rowKey:`${Hn(G)}|row:${X}`,student:G,competency:null,competencyMatrix:null,competencyMatrixLoading:!0,loading:!1,expanded:!1}))),$(xe,M)}catch(C){if(console.error("Failed to load students:",C),a.length>0){const K=a.map(z).filter(P=>!t||P.classSectionId===t).map((P,xe)=>({rowKey:`${Hn(P)}|row:${xe}`,student:P,competency:null,competencyMatrix:null,competencyMatrixLoading:!1,loading:!1,expanded:!1}));l(K),b("Showing recently imported students while backend roster sync catches up.")}else l([]),b("Student competency roster is unavailable right now.")}finally{c(!1)}}},[t,r?.uid,a,$,z,T]);p.useEffect(()=>{Z()},[Z]),p.useEffect(()=>{(async()=>{if(!t){v([]),B("");return}R(!0),B("");try{const K=await Ve.getCourseMaterialTopics({classSectionId:t,limit:20}),P=(K.topics||[]).filter(xe=>xe.title?.trim());v(P),K.warnings.length>0&&B(K.warnings.join(" "))}catch{v([]),B("Imported topic context is unavailable right now.")}finally{R(!1)}})()},[t]);const ae=async C=>{l(K=>K.map(P=>{if(P.rowKey!==C)return P;const xe=!P.expanded,M=P.student.id,G={weakestTopic:P.student.weakestTopic,avgQuizScore:P.student.avgQuizScore};return xe&&!P.competency&&!P.loading?(H(C,M,G),{...P,expanded:!0,loading:!0}):{...P,expanded:xe}}))},H=async(C,K,P)=>{try{const M=((await tn(K))?.quizAttempts??[]).map(X=>({topic:X.quizId,score:X.score,total:100,timeTaken:X.timeSpent})),G=await Ve.getStudentCompetency(K,M.length>0?M:void 0);l(X=>X.map(le=>le.rowKey===C?{...le,competency:G,loading:!1}:le))}catch{const M=P.avgQuizScore||50,G={studentId:K,competencies:[{topic:P.weakestTopic||"Unknown",efficiencyScore:Math.max(15,M-20),competencyLevel:M<50?"beginner":"developing",perspective:`Student needs focused practice in ${P.weakestTopic}.`},{topic:"Functions and Relations",efficiencyScore:Math.min(95,M+10),competencyLevel:M>70?"proficient":"developing",perspective:"Shows solid understanding of function concepts."},{topic:"Problem Solving",efficiencyScore:M,competencyLevel:M>80?"advanced":M>60?"proficient":"developing",perspective:"Applies mathematical reasoning consistently."}],recommendedTopics:[P.weakestTopic||"Review fundamentals"],excludeTopics:[]};l(X=>X.map(le=>le.rowKey===C?{...le,competency:G,loading:!1}:le))}},ee=C=>{N===C?w(K=>K==="asc"?"desc":"asc"):(m(C),w("asc"))},re={High:0,Medium:1,Low:2},ne=o.filter(C=>{if(k!=="all"&&C.student.riskLevel!==k)return!1;if(d){const K=d.toLowerCase();return C.student.name.toLowerCase().includes(K)||C.student.email.toLowerCase().includes(K)}return!0}).sort((C,K)=>{let P=0;switch(N){case"name":P=C.student.name.localeCompare(K.student.name);break;case"avgQuizScore":P=C.student.avgQuizScore-K.student.avgQuizScore;break;case"riskLevel":P=re[C.student.riskLevel]-re[K.student.riskLevel];break;case"engagementScore":P=C.student.engagementScore-K.student.engagementScore;break}return h==="asc"?P:-P}),D=o.length,te=o.filter(C=>C.student.riskLevel==="High").length,J=D>0?Math.round(o.reduce((C,K)=>C+K.student.avgQuizScore,0)/D):0,me=D>0?Math.round(o.reduce((C,K)=>C+K.student.engagementScore,0)/D):0,Ce=Array.from(new Set(f.map(C=>C.title).filter(Boolean))).slice(0,10),F=({field:C})=>N!==C?e.jsx(Ht,{size:14,className:"text-slate-500"}):h==="asc"?e.jsx(Na,{size:14,className:"text-sky-600"}):e.jsx(Ht,{size:14,className:"text-sky-600"});return i?e.jsxs("div",{className:"flex items-center justify-center py-20 p-6",children:[e.jsx(nt,{size:32,className:"animate-spin text-[var(--primary)]"}),e.jsx("span",{className:"ml-3 text-muted-foreground",children:"Loading student data..."})]}):e.jsxs(Re.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},exit:{opacity:0,y:-20},className:"p-6 space-y-6",children:[e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-6",children:[{label:"Total Students",value:D,icon:e.jsx(sn,{size:20}),color:"bg-[color-mix(in_srgb,var(--primary)_10%,transparent)] text-[var(--primary)]"},{label:"At-Risk Students",value:te,icon:e.jsx(Gt,{size:20}),color:"bg-[color-mix(in_srgb,var(--chart-2)_10%,transparent)] text-[var(--chart-2)]"},{label:"Class Average",value:`${J}%`,icon:e.jsx(Hs,{size:20}),color:"bg-[color-mix(in_srgb,var(--chart-3)_10%,transparent)] text-[var(--chart-3)]"},{label:"Avg. Engagement",value:`${me}%`,icon:e.jsx(ka,{size:20}),color:"bg-[color-mix(in_srgb,var(--chart-1)_10%,transparent)] text-[var(--chart-1)]"}].map((C,K)=>e.jsxs("div",{className:"bg-card rounded-xl border border-border p-4 flex items-center gap-3",children:[e.jsx("div",{className:`w-10 h-10 rounded-lg flex items-center justify-center ${C.color}`,children:C.icon}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold text-foreground",children:C.value}),e.jsx("p",{className:"text-xs text-muted-foreground",children:C.label})]})]},K))}),e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center",children:[e.jsxs("div",{className:"relative flex-1 w-full sm:max-w-xs",children:[e.jsx("label",{htmlFor:"student-search",className:"sr-only",children:"Search for students by name or email"}),e.jsx(Js,{size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-500"}),e.jsx("input",{id:"student-search",type:"text",placeholder:"Search students...",value:d,onChange:C=>u(C.target.value),className:"w-full pl-9 pr-4 py-2 border border-border rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-sky-500/20 focus:border-sky-400"})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:["all","High","Medium","Low"].map(C=>e.jsx("button",{onClick:()=>y(C),className:`px-3 py-1.5 rounded-lg text-xs font-semibold transition-all ${k===C?"bg-[var(--primary)] text-white":"bg-muted text-muted-foreground hover:bg-accent"}`,children:C==="all"?"All":`${C} Risk`},C))}),e.jsxs("button",{onClick:Z,className:"sm:ml-auto w-full sm:w-auto flex items-center justify-center gap-1.5 px-3 py-1.5 bg-muted hover:bg-accent rounded-lg text-xs font-semibold text-muted-foreground transition-colors",children:[e.jsx(_s,{size:14}),"Refresh"]})]}),e.jsxs("div",{className:"bg-[color-mix(in_srgb,var(--primary)_10%,transparent)] border border-[color-mix(in_srgb,var(--primary)_30%,transparent)] rounded-xl p-4",children:[e.jsxs("p",{className:"text-sm font-semibold text-[var(--primary)]",children:["Imported Topic Context",s?` for ${s}`:""]}),e.jsx("p",{className:"text-xs text-[var(--primary)] mt-1 opacity-80",children:S?"Loading class-scoped imported topics...":Ce.length>0?`${Ce.length} imported topics loaded for competency guidance`:"No imported topics found for this class context"}),j&&e.jsx("p",{className:"text-[11px] text-[var(--chart-4)] mt-1",children:j}),g&&e.jsx("p",{className:"text-[11px] text-[var(--chart-4)] mt-1",children:g}),Ce.length>0&&e.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:Ce.map(C=>e.jsx("span",{className:"text-[11px] bg-[color-mix(in_srgb,var(--primary)_10%,transparent)] text-[var(--primary)] px-2 py-0.5 rounded",children:C},C))})]}),e.jsx("div",{className:"bg-card rounded-xl border border-border",children:e.jsx("div",{className:"overflow-x-auto pb-2",children:e.jsxs("div",{className:"min-w-[1920px]",children:[e.jsxs("div",{className:"grid grid-cols-[48px_280px_120px_120px_120px_120px_120px_140px_170px_170px_220px] items-center gap-6 px-6 py-4 bg-muted/60 border-b border-border text-xs font-semibold text-muted-foreground tracking-normal",children:[e.jsx("div",{}),e.jsxs("button",{className:"flex items-center gap-1 hover:text-foreground",onClick:()=>ee("name"),children:["Student ",e.jsx(F,{field:"name"})]}),Un.map(C=>e.jsx("div",{className:"text-center leading-none whitespace-nowrap tracking-normal",children:C.header},C.key)),e.jsxs("button",{className:"flex items-center gap-1 hover:text-foreground",onClick:()=>ee("riskLevel"),children:["Risk Level ",e.jsx(F,{field:"riskLevel"})]}),e.jsxs("button",{className:"flex items-center gap-1 hover:text-foreground",onClick:()=>ee("avgQuizScore"),children:["Avg. Score ",e.jsx(F,{field:"avgQuizScore"})]}),e.jsxs("button",{className:"flex items-center gap-1 hover:text-foreground",onClick:()=>ee("engagementScore"),children:["Engagement ",e.jsx(F,{field:"engagementScore"})]}),e.jsx("div",{className:"flex justify-end pr-2",children:"Weakest Topic"})]}),ne.length===0?e.jsxs("div",{className:"py-12 text-center text-slate-500",children:[e.jsx(sn,{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:ne.map(C=>{const K=C.student.riskLevel==="High"?{card:"bg-rose-50 border-rose-200",title:"text-rose-800",chip:"bg-rose-100 text-rose-700"}:C.student.riskLevel==="Medium"?{card:"bg-amber-50 border-amber-200",title:"text-amber-800",chip:"bg-amber-100 text-amber-700"}:{card:"bg-sky-50 border-sky-200",title:"text-sky-800",chip:"bg-sky-100 text-sky-700"};return e.jsxs("div",{className:"border-b border-border last:border-0",children:[e.jsxs("button",{onClick:()=>void ae(C.rowKey),className:"w-full grid grid-cols-[48px_280px_120px_120px_120px_120px_120px_140px_170px_170px_220px] gap-6 px-6 py-5 items-center hover:bg-muted transition-colors text-left",children:[e.jsx("div",{className:"flex items-center",children:e.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center text-slate-500",children:C.expanded?e.jsx(Ht,{size:16}):e.jsx(Wt,{size:16})})}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("img",{src:C.student.avatar,alt:C.student.name,className:"w-8 h-8 rounded-full bg-border object-cover"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-foreground",children:C.student.name}),e.jsx("p",{className:"text-xs text-slate-500",children:C.student.email})]})]}),Un.map(P=>{const xe=C.competencyMatrix?.[P.key]??0,M=vm(xe);return e.jsx("div",{className:"flex items-center justify-center",children:C.competencyMatrixLoading?e.jsx(nt,{size:14,className:"animate-spin text-muted-foreground"}):C.competencyMatrix?e.jsxs("span",{title:`${P.label}: ${xe}%`,className:`inline-flex items-center justify-center rounded-md px-2 py-1 text-xs font-semibold ring-1 ${M.bg} ${M.text} ${M.ring}`,children:[xe,"%"]}):e.jsx("span",{className:"text-xs text-muted-foreground",children:"—"})},P.key)}),e.jsx("div",{children:e.jsxs("span",{className:`inline-flex items-center gap-1 px-2.5 py-0.5 rounded-full text-xs font-bold ring-1 ${Xa[C.student.riskLevel]?.bg} ${Xa[C.student.riskLevel]?.text} ${Xa[C.student.riskLevel]?.ring}`,children:[C.student.riskLevel==="High"&&e.jsx(Gt,{size:10}),C.student.riskLevel]})}),e.jsx("div",{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex-1 h-2 bg-muted rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full e-w ${C.student.avgQuizScore>=80?"bg-[var(--chart-3)]":C.student.avgQuizScore>=60?"bg-[var(--chart-4)]":"bg-[var(--chart-2)]"}`,style:{"--w":`${C.student.avgQuizScore}%`}})}),e.jsxs("span",{className:"text-xs font-bold text-muted-foreground w-8 text-right",children:[C.student.avgQuizScore,"%"]})]})}),e.jsx("div",{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex-1 h-2 bg-muted rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full e-w ${C.student.engagementScore>=75?"bg-[var(--primary)]":C.student.engagementScore>=50?"bg-[var(--primary)]/60":"bg-muted-foreground"}`,style:{"--w":`${C.student.engagementScore}%`}})}),e.jsxs("span",{className:"text-xs font-bold text-muted-foreground w-8 text-right",children:[C.student.engagementScore,"%"]})]})}),e.jsx("div",{className:"flex justify-end pr-2",children:e.jsx("span",{className:"text-xs font-medium text-muted-foreground bg-muted px-2 py-1 rounded-md",children:C.student.weakestTopic})})]}),e.jsx(Qt,{children:C.expanded&&e.jsx(Re.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},className:"overflow-hidden",children:e.jsx("div",{className:"px-6 py-4 bg-muted border-t border-border",children:C.loading?e.jsxs("div",{className:"flex items-center justify-center py-6",children:[e.jsx(nt,{size:20,className:"animate-spin text-sky-500"}),e.jsx("span",{className:"ml-2 text-sm text-muted-foreground",children:"Analyzing competency data..."})]}):C.competency?e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3",children:C.competency.competencies.map((P,xe)=>e.jsx(jm,{competency:P},xe))}),C.competency.recommendedTopics.length>0&&e.jsxs("div",{className:`border rounded-lg p-3 ${K.card}`,children:[e.jsxs("h5",{className:`text-xs font-bold mb-1.5 flex items-center gap-1 ${K.title}`,children:[e.jsx(Vt,{size:12}),"Recommended Focus Areas"]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:C.competency.recommendedTopics.map((P,xe)=>e.jsx("span",{className:`inline-flex items-center px-2 py-0.5 rounded text-xs font-medium ${K.chip}`,children:P},xe))})]}),Ce.length>0&&e.jsxs("div",{className:"bg-sky-50 border border-sky-200 rounded-lg p-3",children:[e.jsxs("h5",{className:"text-xs font-bold text-sky-800 mb-1.5 flex items-center gap-1",children:[e.jsx(uo,{size:12}),"Class Imported Topics"]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:Ce.slice(0,8).map((P,xe)=>e.jsx("span",{className:"inline-flex items-center bg-sky-100 text-sky-700 px-2 py-0.5 rounded text-xs font-medium",children:P},`${P}_${xe}`))})]}),C.competency.excludeTopics.length>0&&e.jsxs("div",{className:"bg-emerald-50 border border-emerald-200 rounded-lg p-3",children:[e.jsxs("h5",{className:"text-xs font-bold text-emerald-800 mb-1.5 flex items-center gap-1",children:[e.jsx(Yl,{size:12}),"Mastered Topics (can exclude from quizzes)"]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:C.competency.excludeTopics.map((P,xe)=>e.jsx("span",{className:"inline-flex items-center bg-emerald-100 text-emerald-700 px-2 py-0.5 rounded text-xs font-medium",children:P},xe))})]})]}):e.jsx("p",{className:"text-sm text-slate-500 text-center py-4",children:"No competency data available. Student needs to complete quizzes first."})})})})]},C.rowKey)})})]})})})]})},jm=({competency:t})=>{const s=Qn[t.competencyLevel]||Qn.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(Re.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})]})},ym=({liveActivity:t,atRiskStudents:s})=>{const{notifications:a,unreadCount:r,isLoading:n,markAsRead:o,markAllAsRead:l}=Kl(),i=u=>{const N=Date.now()-u.getTime(),m=Math.floor(N/6e4);if(m<1)return"Just now";if(m<60)return`${m} min ago`;const h=Math.floor(m/60);if(h<24)return`${h} hour${h===1?"":"s"} ago`;const w=Math.floor(h/24);return`${w} day${w===1?"":"s"} ago`},c=u=>{switch(u){case"achievement_unlocked":case"achievement":return Jl;case"message":return ii;case"grade":case"quiz_result":return mo;case"reminder":case"streak_reminder":return So;case"risk_alert":return Gt;case"automation":case"system_alert":return Xl;default:return ua}},d=u=>{switch(u){case"risk_alert":return"bg-destructive/10 text-destructive";case"achievement_unlocked":case"achievement":return"bg-rose-500/10 text-rose-600 dark:text-rose-400";case"message":return"bg-sky-500/10 text-sky-700 dark:text-sky-400";case"grade":case"quiz_result":return"bg-emerald-500/10 text-emerald-700 dark:text-emerald-400";case"reminder":case"streak_reminder":return"bg-amber-500/10 text-amber-700 dark:text-amber-400";case"automation":case"system_alert":return"bg-violet-500/10 text-violet-700 dark:text-violet-400";default:return"bg-muted text-muted-foreground"}};return e.jsxs(Re.div,{initial:{opacity:0,y:18},animate:{opacity:1,y:0},exit:{opacity:0,y:-18},className:"p-4 sm:p-6 space-y-4",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx("div",{className:"min-w-0",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-sky-100 text-sky-700 dark:bg-sky-500/15 dark:text-sky-300 flex items-center justify-center flex-shrink-0",children:e.jsx(ua,{size:20})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h2",{className:"text-2xl font-display font-bold text-foreground",children:"Notifications"}),e.jsx("p",{className:"text-sm text-muted-foreground font-body",children:"Classroom alerts and updates"})]})]})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"text-xs text-muted-foreground font-body",children:r>0?`${r} unread`:"All caught up"}),r>0&&e.jsxs($e,{variant:"outline",size:"sm",onClick:l,children:[e.jsx(Oi,{}),"Mark all as read"]})]})]}),e.jsx("div",{className:"bg-card border border-border rounded-2xl shadow-sm overflow-hidden",children:n?e.jsxs("div",{className:"p-8 flex items-center justify-center gap-2 text-muted-foreground",children:[e.jsx(nt,{size:18,className:"animate-spin"}),e.jsx("span",{className:"text-sm font-body",children:"Loading notifications…"})]}):a.length===0?e.jsx("div",{className:"p-10",children:e.jsxs("div",{className:"max-w-xl",children:[e.jsx("div",{className:"w-12 h-12 rounded-xl bg-muted text-muted-foreground flex items-center justify-center mb-4",children:e.jsx(ua,{size:22})}),e.jsx("h3",{className:"text-lg font-display font-bold text-foreground mb-1",children:"No notifications"}),e.jsx("p",{className:"text-sm text-muted-foreground font-body",children:"Teacher alerts and classroom updates will appear here."})]})}):e.jsxs("div",{children:[t&&t.length>0&&e.jsx("div",{children:t.map(u=>e.jsx("div",{className:"w-full text-left px-4 py-4 border-b border-border transition-colors hover:bg-accent/40",children:e.jsxs("div",{className:"flex gap-3",children:[e.jsx("div",{className:`w-10 h-10 rounded-xl flex items-center justify-center flex-shrink-0 ${u.type==="success"?"bg-[#75D06A]/15 text-[#4D9F46]":u.type==="warning"?"bg-[#F08386]/15 text-[#C65E63]":"bg-[#9956DE]/15 text-[#9956DE]"}`,children:e.jsx($s,{size:18})}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs("h4",{className:"text-sm font-body font-bold text-foreground line-clamp-1",children:[u.student," — ",u.action]})}),e.jsxs("p",{className:"mt-1 text-xs text-muted-foreground font-body leading-relaxed line-clamp-2",children:["Topic: ",u.topic]})]}),e.jsx("div",{className:"text-xs text-muted-foreground font-body flex-shrink-0",children:u.time})]})})]})},u.id))}),a.map(u=>{const N=c(u.type),m=d(u.type),h=i(u.createdAt);return e.jsx("button",{onClick:()=>o(u.id),className:`w-full text-left px-4 py-4 border-b border-border last:border-b-0 transition-colors hover:bg-accent/40 focus:outline-none focus-visible:ring-2 focus-visible:ring-ring/50 ${u.isRead?"":"bg-sky-50/40 dark:bg-sky-500/5"}`,children:e.jsxs("div",{className:"flex gap-3",children:[e.jsx("div",{className:`w-10 h-10 rounded-xl flex items-center justify-center flex-shrink-0 ${m}`,children:e.jsx(N,{size:18})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h4",{className:"text-sm font-body font-bold text-foreground line-clamp-1",children:u.title}),!u.isRead&&e.jsx("span",{className:"w-2 h-2 rounded-full bg-sky-500 flex-shrink-0"})]}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground font-body leading-relaxed line-clamp-2",children:u.message})]}),e.jsx("div",{className:"text-xs text-muted-foreground font-body flex-shrink-0",children:h})]}),u.actionUrl&&e.jsx("div",{className:"mt-2 text-xs text-sky-600 dark:text-sky-400 font-body",children:"Opens link"})]})]})},u.id)})]})})]})},wm=t=>{const s=t.data(),a=s.startTime,r=s.endTime,n=s.createdAt,o=s.updatedAt,l=i=>{if(i){if(typeof i?.toDate=="function")return i.toDate();if(i instanceof Date)return i}};return{...s,id:t.id,startTime:l(a)||new Date,endTime:l(r),createdAt:l(n)||new Date,updatedAt:l(o)}},Sm=async(t,s)=>{const a=et(Bt(Ge,"calendarEvents")),r={id:a.id,userId:t,title:s.title,description:s.description,startTime:s.startTime,endTime:s.endTime,createdAt:new Date};return await Ut(a,{...r,createdAt:ot(),updatedAt:ot()}),r},km=async t=>{await xi(et(Ge,"calendarEvents",t))},Cm=(t,s={},a,r)=>{if(!t)return a([]),()=>{};const{limitCount:n=500}=s,o=zt(Bt(Ge,"calendarEvents"),Ft("userId","==",t),vo(n));return Xs(o,l=>{a(l.docs.map(i=>wm(i)))},l=>{console.error("Error subscribing to calendar events:",l),r?.(l)})};function Tm({className:t,...s}){return e.jsx("textarea",{"data-slot":"textarea",className:hr("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 Wn=t=>String(t).padStart(2,"0"),hs=t=>`${t.getFullYear()}-${Wn(t.getMonth()+1)}-${Wn(t.getDate())}`,ur=t=>new Date(t.getFullYear(),t.getMonth(),1),Vn=t=>new Date(t.getFullYear(),t.getMonth()+1,0),Im=t=>{const s=ur(t),a=s.getDay(),r=new Date(s);return r.setDate(s.getDate()-a),r.setHours(0,0,0,0),r},Em=(t,s)=>{const a=new Date(t);return a.setDate(a.getDate()+s),a},qn=(t,s)=>t.getFullYear()===s.getFullYear()&&t.getMonth()===s.getMonth()&&t.getDate()===s.getDate(),Rm=(t,s)=>t.getFullYear()===s.getFullYear()&&t.getMonth()===s.getMonth(),Am=t=>t.toLocaleDateString(void 0,{month:"long",year:"numeric"}),Yn=t=>t.toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"}),Kn=(t,s)=>{const[a,r,n]=t.split("-").map(i=>parseInt(i,10)),[o,l]=s.split(":").map(i=>parseInt(i,10));return new Date(a,(r||1)-1,n||1,o||0,l||0,0,0)},Ja=[{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 Mm(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 n=Ja.find(l=>l.names.includes(r[1]))?.day,o=Ja.find(l=>l.names.includes(r[2]))?.day;if(n!==void 0&&o!==void 0){let l=n;for(;a.add(l),l!==o;)l=(l+1)%7;return Array.from(a)}}return Ja.forEach(({names:n,day:o})=>{n.some(l=>s.includes(l))&&a.add(o)}),Array.from(a).sort((n,o)=>n-o)}const Lm=({classes:t,teacherId:s})=>{const{currentUser:a}=Ks(),[r,n]=p.useState([]),[o,l]=p.useState(!0),[i,c]=p.useState(""),[d,u]=p.useState(()=>{const F=new Date;return F.setHours(0,0,0,0),F}),[N,m]=p.useState(()=>{const F=new Date;return F.setHours(0,0,0,0),F}),[h,w]=p.useState(!1),[k,y]=p.useState(!1),[f,v]=p.useState(""),[S,R]=p.useState(""),[j,B]=p.useState(()=>hs(new Date)),[g,b]=p.useState("09:00"),[T,z]=p.useState("");p.useEffect(()=>{if(!a?.uid){n([]),l(!1);return}c(""),l(!0);const F=Cm(a.uid,{limitCount:500},C=>{n(C),l(!1)},()=>{c("Unable to load calendar events right now."),l(!1)});return()=>F()},[a?.uid]);const $=p.useMemo(()=>{const F=ur(d);return F.setHours(0,0,0,0),F},[d]),Z=p.useMemo(()=>{const F=Vn(d);return F.setHours(23,59,59,999),F},[d]),ae=p.useMemo(()=>{if(!t||t.length===0)return[];const F=[],C=ur(d),K=Vn(d),P=new Date(C);for(;P<=K;){const xe=P.getDay();t.forEach(M=>{Mm(M.schedule).includes(xe)&&F.push({id:`schedule-${M.id}-${hs(P)}`,userId:s||"",title:M.name,startTime:new Date(P),createdAt:new Date})}),P.setDate(P.getDate()+1)}return F},[t,d,s]),H=p.useMemo(()=>[...r,...ae],[r,ae]),ee=p.useMemo(()=>H.filter(F=>F.startTime>=$&&F.startTime<=Z).sort((F,C)=>F.startTime.getTime()-C.startTime.getTime()),[H,$,Z]),re=p.useMemo(()=>{const F=new Map;for(const C of ee){const K=hs(C.startTime),P=F.get(K)||[];P.push(C),F.set(K,P)}return F},[ee]),ne=p.useMemo(()=>hs(N),[N]),D=p.useMemo(()=>[...re.get(ne)||[]].sort((C,K)=>C.startTime.getTime()-K.startTime.getTime()),[re,ne]),te=p.useMemo(()=>{const F=Im(d);return Array.from({length:42}).map((C,K)=>Em(F,K))},[d]),J=F=>{const C=hs(F);v(""),R(""),B(C),b("09:00"),z(""),w(!0)},me=async()=>{if(a?.uid){if(!f.trim()){c("Event title is required.");return}y(!0),c("");try{const F=Kn(j,g),C=T?Kn(j,T):void 0;await Sm(a.uid,{title:f.trim(),description:S.trim()?S.trim():void 0,startTime:F,endTime:C&&C.getTime()>F.getTime()?C:void 0}),w(!1)}catch(F){console.error(F),c("Failed to create event.")}finally{y(!1)}}},Ce=async F=>{c("");try{await km(F)}catch(C){console.error(C),c("Failed to delete event.")}};return e.jsxs(Re.div,{initial:{opacity:0,y:18},animate:{opacity:1,y:0},exit:{opacity:0,y:-18},className:"p-4 sm:p-6 space-y-4",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx("div",{className:"min-w-0",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-secondary text-secondary-foreground flex items-center justify-center flex-shrink-0",children:e.jsx(Yi,{size:20})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h2",{className:"text-2xl font-display font-bold text-foreground",children:"Calendar"}),e.jsx("p",{className:"text-sm text-muted-foreground font-body",children:"Check upcoming class events and schedule"})]})]})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($e,{variant:"outline",size:"sm",onClick:()=>{const F=new Date;F.setHours(0,0,0,0),u(F),m(F)},children:"Today"}),e.jsxs($e,{size:"sm",onClick:()=>J(N),children:[e.jsx(ma,{}),"Add event"]})]})]}),i&&e.jsx("div",{className:"bg-destructive/10 text-destructive border border-destructive/20 rounded-xl px-4 py-3 text-sm font-body",children:i}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-12 gap-4",children:[e.jsxs("div",{className:"lg:col-span-8 bg-card border border-border rounded-2xl shadow-sm overflow-hidden",children:[e.jsxs("div",{className:"px-4 py-3 border-b border-border flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($e,{variant:"ghost",size:"icon",onClick:()=>{const F=new Date(d.getFullYear(),d.getMonth()-1,1);u(F)},"aria-label":"Previous month",children:e.jsx(Pt,{})}),e.jsx("div",{className:"text-sm sm:text-base font-display font-bold text-foreground",children:Am(d)}),e.jsx($e,{variant:"ghost",size:"icon",onClick:()=>{const F=new Date(d.getFullYear(),d.getMonth()+1,1);u(F)},"aria-label":"Next month",children:e.jsx(Wt,{})})]}),e.jsxs("div",{className:"text-xs text-muted-foreground font-body",children:[ee.length," event",ee.length===1?"":"s"]})]}),e.jsxs("div",{className:"grid grid-cols-7 gap-px bg-border",children:[["Sun","Mon","Tue","Wed","Thu","Fri","Sat"].map(F=>e.jsx("div",{className:"bg-card px-3 py-2 text-xs font-body font-bold text-muted-foreground",children:F},F)),te.map(F=>{const C=hs(F),K=re.get(C)?.length||0,P=qn(F,N),xe=qn(F,new Date),M=Rm(F,d);return e.jsxs("button",{onClick:()=>{const G=new Date(F);G.setHours(0,0,0,0),m(G)},className:"bg-card px-3 py-3 min-h-[78px] text-left transition-colors hover:bg-accent/40 focus:outline-none focus-visible:ring-2 focus-visible:ring-ring/50 "+(P?"ring-2 ring-primary/40 ":"")+(M?"":"opacity-50 "),children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsx("div",{className:"w-7 h-7 rounded-lg flex items-center justify-center text-sm font-body font-bold "+(xe?"bg-primary text-primary-foreground ":"text-foreground ")+(P&&!xe?"bg-secondary text-secondary-foreground ":""),children:F.getDate()}),K>0&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-primary"}),e.jsx("span",{className:"text-xs font-body text-muted-foreground",children:K})]})]}),K>0&&e.jsxs("div",{className:"mt-2 flex flex-wrap gap-1",children:[(re.get(C)||[]).slice(0,3).map(G=>e.jsx("span",{className:"inline-flex items-center rounded-md bg-secondary text-secondary-foreground px-2 py-0.5 text-[10px] font-body font-bold truncate max-w-full",title:G.title,children:G.title},G.id)),(re.get(C)?.length||0)>3&&e.jsxs("span",{className:"text-[10px] font-body text-muted-foreground",children:["+",(re.get(C)?.length||0)-3," more"]})]})]},C)})]}),o&&e.jsxs("div",{className:"px-4 py-4 border-t border-border flex items-center gap-2 text-muted-foreground",children:[e.jsx(nt,{size:18,className:"animate-spin"}),e.jsx("span",{className:"text-sm font-body",children:"Syncing events…"})]})]}),e.jsxs("div",{className:"lg:col-span-4 bg-card border border-border rounded-2xl shadow-sm overflow-hidden",children:[e.jsxs("div",{className:"px-4 py-3 border-b border-border flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-display font-bold text-foreground",children:N.toLocaleDateString(void 0,{weekday:"long"})}),e.jsx("div",{className:"text-xs text-muted-foreground font-body",children:N.toLocaleDateString()})]}),e.jsxs($e,{variant:"outline",size:"sm",onClick:()=>J(N),children:[e.jsx(ma,{}),"Add"]})]}),e.jsx("div",{className:"p-4",children:D.length===0?e.jsxs("div",{className:"rounded-xl border border-border bg-muted/30 p-4",children:[e.jsx("div",{className:"text-sm font-body font-bold text-foreground",children:"No events"}),e.jsx("div",{className:"text-xs text-muted-foreground font-body mt-1",children:"Add reminders for quizzes, meetings, or deadlines."})]}):e.jsx("div",{className:"space-y-2",children:D.map(F=>e.jsxs("div",{className:"rounded-xl border border-border bg-background p-3 flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-primary flex-shrink-0"}),e.jsx("div",{className:"text-sm font-body font-bold text-foreground truncate",children:F.title})]}),e.jsxs("div",{className:"text-xs text-muted-foreground font-body mt-1",children:[Yn(F.startTime),F.endTime?` – ${Yn(F.endTime)}`:""]}),F.description&&e.jsx("div",{className:"text-xs text-muted-foreground font-body mt-2 line-clamp-2",children:F.description})]}),e.jsx($e,{variant:"ghost",size:"icon",onClick:()=>Ce(F.id),"aria-label":"Delete event",children:e.jsx(No,{})})]},F.id))})})]})]}),e.jsx(xo,{open:h,onOpenChange:w,children:e.jsxs(ho,{className:"sm:max-w-xl",children:[e.jsxs(po,{children:[e.jsx(fo,{className:"font-display",children:"Add event"}),e.jsx(go,{className:"font-body",children:"Create a reminder for your class schedule."})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("div",{className:"sm:col-span-2",children:[e.jsx("label",{className:"text-xs font-body font-bold text-muted-foreground",children:"Title"}),e.jsx(vt,{value:f,onChange:F=>v(F.target.value),placeholder:"e.g., Quiz review session"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-body font-bold text-muted-foreground",children:"Date"}),e.jsx(vt,{type:"date",value:j,onChange:F=>B(F.target.value)})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-body font-bold text-muted-foreground",children:"Start time"}),e.jsx(vt,{type:"time",value:g,onChange:F=>b(F.target.value)})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-body font-bold text-muted-foreground",children:"End time (optional)"}),e.jsx(vt,{type:"time",value:T,onChange:F=>z(F.target.value)})]}),e.jsxs("div",{className:"sm:col-span-2",children:[e.jsx("label",{className:"text-xs font-body font-bold text-muted-foreground",children:"Notes (optional)"}),e.jsx(Tm,{value:S,onChange:F=>R(F.target.value),placeholder:"Add context: class, room, agenda…",className:"min-h-24"})]})]}),e.jsxs(bo,{children:[e.jsx($e,{variant:"outline",onClick:()=>w(!1),disabled:k,children:"Cancel"}),e.jsx($e,{onClick:me,disabled:k,children:k?e.jsxs(e.Fragment,{children:[e.jsx(nt,{className:"animate-spin"}),"Saving…"]}):e.jsxs(e.Fragment,{children:[e.jsx(ma,{}),"Create event"]})})]})]})})]})},fl="PH_SHS_OFFICIAL_CLASS_RECORD",Dm=.85,xr=.85,zm="2026.04.24",gl=4,fa=["INPUT DATA","SENIOR HIGH SCHOOL CLASS RECORD","LEARNERS NAMES","WRITTEN WORK","PERFORMANCE TASKS","QUARTERLY ASSESSMENT","REMARK","FINAL SEMESTRAL GRADES"],Fm=[...fa,"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"],Bm=["SUBMITTED BY","CHECKED BY","VERIFIED BY","RECOMMENDED BY","APPROVED BY"],sa=["WITH ATTACHMENTS","OFFICIALLY DROPPED","WITHDRAWN","UNOFFICIALLY DROPPED","TRANSFEREE","SHIFTER"],$m=["TOTAL","SUBMITTED BY","CHECKED BY","VERIFIED BY","RECOMMENDED BY","APPROVED BY","WEIGHT OF COMPONENTS"],Om={SECOND:["SECOND QUARTER","2ND QUARTER","Q2"]},ps={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"]},bt={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"]},Le={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 Pm(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 Xn(t){return it(t).replace(/[^A-Z0-9]+/g,"")}function Se(t,s){const a=it(t),r=it(s);if(!a||!r)return!1;if(a.includes(r))return!0;const n=Xn(t),o=Xn(s);return!n||!o?!1:n.includes(o)}function ga(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 Za(t){return it(t).toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"").slice(0,80)}function bl(t){const s={};return t.forEach(a=>{const r=wt.encode_cell(a.s);for(let n=a.s.r;n<=a.e.r;n+=1)for(let o=a.s.c;o<=a.e.c;o+=1){const l=wt.encode_cell({r:n,c:o});s[l]=r}}),s}function _m(t,s,a){const n=(a||bl(t.merges))[s]||s;return t.cells[n]||t.cells[s]}const vl="A1:A1",Jn=1200,Zn=200,eo=2e5;function Hm(t){const s=Math.max(0,t.s.r),a=Math.max(0,t.s.c);let r=Math.max(s,t.e.r),n=Math.max(a,t.e.c);r-s+1>Jn&&(r=s+Jn-1),n-a+1>Zn&&(n=a+Zn-1);const o=r-s+1,l=n-a+1;if(o*l>eo){const c=Math.max(1,Math.floor(eo/l));r=s+Math.min(o,c)-1}return{s:{r:s,c:a},e:{r,c:n}}}function Gm(t){try{return wt.decode_range(t)}catch{return wt.decode_range(vl)}}function Qm(t){let s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY,n=Number.NEGATIVE_INFINITY;return Object.keys(t.cells).forEach(o=>{try{const l=wt.decode_cell(o);s=Math.min(s,l.r),a=Math.min(a,l.c),r=Math.max(r,l.r),n=Math.max(n,l.c)}catch{}}),t.merges.forEach(o=>{s=Math.min(s,o.s.r,o.e.r),a=Math.min(a,o.s.c,o.e.c),r=Math.max(r,o.s.r,o.e.r),n=Math.max(n,o.s.c,o.e.c)}),!Number.isFinite(s)||!Number.isFinite(a)||!Number.isFinite(r)||!Number.isFinite(n)?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(n))}}}function Um(t){const s=Gm(t.ref||vl),a=Qm(t);return Hm(a||s)}function Wm(t,s){const a=Um(s),r=`${wt.encode_cell(a.s)}:${wt.encode_cell(a.e)}`,n=bl(s.merges),o=a.e.r-a.s.r+1,l=a.e.c-a.s.c+1,i=[];for(let c=0;ct.endRow||at.endCol?null:t.cells[s-t.startRow]?.[a-t.startCol]??null}function Zt(t,s){return st.endRow?"":(t.cells[s-t.startRow]||[]).map(r=>r?.normalizedText||"").filter(Boolean).join(" ").trim()}function Ls(t){return wt.encode_col(t)}function da(t){const s=String(t||"").trim().toUpperCase();if(!s||!/^[A-Z]+$/.test(s))return-1;try{return wt.decode_col(s)}catch{return-1}}function Vm(t){return`${wt.encode_cell(t.s)}:${wt.encode_cell(t.e)}`}function qm(t,s){const a=[];for(let r=s.s.r;r<=s.e.r;r+=1){const n=[];for(let o=s.s.c;o<=s.e.c;o+=1){const l=ze(t,r,o);n.push(l?.displayValue??null)}a.push(n)}return a}function Ym(t,s){const a=it(t),r=it(s);return!a||!r?0:a===r?1:a.includes(r)?.9:.75}function Mr(t,s){const a=[];for(let r=0;r{Se(i.normalizedText,c)&&a.push({sheetName:t.sheetName,anchor:c,row:i.row,col:i.col,address:i.address,value:String(i.displayValue??""),confidence:Ym(i.displayValue,c)})})}const n=t.startRow+r,o=Zt(t,n);o&&s.forEach(l=>{if(!Se(o,l))return;const i=t.cells[r].find(c=>c?.normalizedText);i&&a.push({sheetName:t.sheetName,anchor:l,row:n,col:i.col,address:i.address,value:o,confidence:.8})})}return a}function Km(t,s){return Object.values(t).flatMap(a=>Mr(a,s))}function dt(t,s){return Mr(t,[s]).sort((a,r)=>a.row-r.row||a.col-r.col)}function Nl(t,s,a,r=6){for(let n=1;n<=r;n+=1){const l=ze(t,s,a+n)?.displayValue;if(l!=null&&String(l).trim())return String(l).trim()}for(let n=1;n<=r;n+=1){const l=ze(t,s+n,a)?.displayValue;if(l!=null&&String(l).trim())return String(l).trim()}}function jl(t,s,a=5){let r=s,n=-1;for(let o=Math.max(t.startRow,s-a);o<=Math.min(t.endRow,s+a);o+=1){const l=Zt(t,o),i=["LEARNERS NAMES","WRITTEN WORK","PERFORMANCE TASKS","QUARTERLY ASSESSMENT","REMARK"].reduce((c,d)=>l.includes(d)?c+1:c,0);i>n&&(n=i,r=o)}return r}function Xm(t,s){const a=it(t).toLowerCase(),r=n=>[...s].some(o=>Se(o,n));return ps.inputData.some(n=>a.includes(n))||r("INPUT DATA")?"inputData":ps.finalSemestral.some(n=>a.includes(n))||r("FINAL SEMESTRAL GRADES")||r("FINAL GRADES")?"finalSemestral":ps.firstQuarter.some(n=>a.includes(n))||r("FIRST QUARTER")?"firstQuarter":ps.secondQuarter.some(n=>a.includes(n))||r("SECOND QUARTER")?"secondQuarter":r("SENIOR HIGH SCHOOL CLASS RECORD")||r("WRITTEN WORK")&&r("PERFORMANCE TASKS")?"firstQuarter":ps.helper.some(n=>a.includes(n))||r("WEIGHT OF COMPONENTS")||r("ATTACHMENTS")||r("HELPER")?"helper":ps.lookup.some(n=>a.includes(n))||r("LOOK UP")?"lookup":"other"}function Jm(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,n=.65*s+.2*a+.15*r;return Number(Math.max(0,Math.min(1,n)).toFixed(4))}function Zm(t){const s=Km(t.matrices,Fm),a=new Set,r=[];fa.forEach(h=>{s.some(k=>Se(k.anchor,h))&&(a.add(h),r.push(`Found critical anchor: ${h}`))});const n=fa.filter(h=>!a.has(h)),o=new Map;s.forEach(h=>{o.has(h.sheetName)||o.set(h.sheetName,new Set),o.get(h.sheetName)?.add(h.anchor)});const l=t.sheetNames.map(h=>{const w=o.get(h)||new Set,k=Xm(h,w),y=Math.min(1,.35+Math.min(.55,w.size*.08)),f=[`sheet:${h}`,`signals:${w.size}`,...[...w].slice(0,5)];return{sheetName:h,role:k,confidence:Number(y.toFixed(3)),evidence:f}}),i={firstQuarter:[],secondQuarter:[],finalSemestral:[],helper:[],lookup:[],other:[]};l.forEach(h=>{switch(h.role){case"inputData":i.inputData?i.other.push(h.sheetName):i.inputData=h.sheetName;break;case"firstQuarter":i.firstQuarter.push(h.sheetName);break;case"secondQuarter":i.secondQuarter.push(h.sheetName);break;case"finalSemestral":i.finalSemestral.push(h.sheetName);break;case"helper":i.helper.push(h.sheetName);break;case"lookup":i.lookup.push(h.sheetName);break;case"other":default:i.other.push(h.sheetName);break}});const c=(i.inputData?1:0)+i.firstQuarter.length+i.secondQuarter.length+i.finalSemestral.length+i.helper.length+i.lookup.length,d=Jm({criticalFound:a.size,criticalTotal:fa.length,recognizedSheets:c,totalSheets:t.sheetNames.length,hasDepedAnchor:s.some(h=>Se(h.anchor,"Pursuant to DepEd Order 8 series of 2015"))}),u=i.firstQuarter.length>0||i.secondQuarter.length>0,N=!!i.inputData&&u&&i.finalSemestral.length>0,m=d>=.55&&N;return i.inputData||r.push("Input Data sheet not confidently detected."),u||r.push("No quarter class record sheet detected."),i.finalSemestral.length===0&&r.push("No Final Semestral Grades sheet detected."),{format:fl,isOfficialFormatLikely:m,confidence:d,evidence:r,missingCriticalAnchors:n,detectedSheets:i,anchorMatches:s}}function Sa(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 Lr(t){const s=it(t);if(s.includes("FEMALE"))return"FEMALE";if(s.includes("MALE"))return"MALE"}function Dr(t){const s=it(t.rowText);return s?s==="MALE"||s==="FEMALE"?"sex-header":Bm.some(a=>s.includes(a))?"signature":$m.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 eu(t){const s=["SUBMITTED BY","CHECKED BY","VERIFIED BY","RECOMMENDED BY","APPROVED BY"],a=[];return s.forEach(r=>{dt(t,r).forEach(n=>{a.push({role:r,name:String(ze(t,n.row,n.col+1)?.displayValue||"").trim()||void 0,sourceSheet:t.sheetName,sourceRow:n.row+1})})}),a}function tu(t){const s=[],a=dt(t,"LEARNERS NAMES")[0],r=a?jl(t,a.row,5):t.startRow,n=(y,f)=>dt(t,y).find(S=>Math.abs(S.row-r)<=2)?.col??f,o=n(Le.learnerNo[0],t.startCol),l=n(Le.learnerName[0],t.startCol+1),i=n(Le.firstQuarter[0],l+1),c=n(Le.secondQuarter[0],i+1),d=n(Le.firstSemester[0],c+1),u=n(Le.finalGrades[0],d+1),N=n(Le.remark[0],u+1),m=n(Le.additionalRemarks[0],N+1),h=[];let w="UNKNOWN",k=0;for(let y=r+1;y<=t.endRow;y+=1){const f=Zt(t,y),v=Dr({rowText:f,hasLearnerNumber:/\b\d{1,2}\b/.test(f),hasLearnerName:/[A-Z]{2,}/.test(f)});if(v==="sex-header"){w=Lr(f)||w;continue}if(v==="signature"||v==="helper")break;if(v==="blank"){if(k+=1,k>=gl)break;continue}if(v!=="learner")continue;k=0;const S=Sa(ze(t,y,o)?.displayValue),R=String(ze(t,y,l)?.displayValue||"").trim();if(!R&&S===void 0)continue;const j=ze(t,y,i)?.displayValue??null,B=ze(t,y,c)?.displayValue??null,g=ze(t,y,d)?.displayValue??null,b=ze(t,y,u)?.displayValue??null,T=ze(t,y,N)?.displayValue??null;let z=ze(t,y,m)?.displayValue??null;const $=sa.filter(Z=>Se(f,Z));$.length>0&&(z=[z,$.join("; ")].filter(Boolean).join("; ")||null),!R&&S!==void 0&&s.push(`Row ${y+1} has learner number ${S} but empty learner name.`),h.push({learnerNo:S,fullName:R||`Unnamed Learner ${S||y+1}`,sex:w,firstQuarter:j,secondQuarter:B,firstSemester:g,finalGrades:b,remark:T,additionalRemarks:z,sourceRow:y+1})}return{sheetName:t.sheetName,learnerGrades:h,signatures:eu(t),warnings:s}}function Ct(t,s){for(const a of s){const r=dt(t,a);for(const n of r){const o=Nl(t,n.row,n.col,8);if(o&&o.trim())return o.trim()}}}function su(t){const s=["SUBMITTED BY","CHECKED BY","VERIFIED BY","RECOMMENDED BY","APPROVED BY"],a=[];return s.forEach(r=>{dt(t,r).forEach(o=>{const l=Nl(t,o.row,o.col,10);a.push({role:r,name:l,sourceSheet:t.sheetName,sourceRow:o.row+1})})}),a}function au(t){const s=dt(t,"LEARNERS NAMES")[0];if(!s)return[];const a=s.row+1,r=s.col,n=Math.max(t.startCol,r-1),o=Math.min(t.endCol,r+1),l=Math.min(t.endCol,r+2),i=[];let c="UNKNOWN",d=0;for(let u=a;u<=t.endRow;u+=1){const N=Zt(t,u),m=Dr({rowText:N,hasLearnerNumber:!!Sa(ze(t,u,n)?.displayValue),hasLearnerName:!!String(ze(t,u,r)?.displayValue||"").trim()});if(m==="sex-header"){c=Lr(N)||c,d=0;continue}if(m==="signature"||m==="helper")break;if(m!=="learner"){if(m==="blank"&&(d+=1),d>=5)break;continue}d=0;const h=Sa(ze(t,u,n)?.displayValue),w=String(ze(t,u,r)?.displayValue||"").trim(),k=String(ze(t,u,o)?.displayValue||"").trim()||void 0,y=String(ze(t,u,l)?.displayValue||"").trim()||void 0,f=sa.filter(v=>Se(N,v));!w&&h===void 0||i.push({learnerNo:h,sex:c,fullName:w||`Unnamed Learner ${h||u}`,sourceSheet:t.sheetName,sourceRow:u+1,remarks:k,additionalRemarks:y,statuses:f.length>0?f:void 0})}return i}function ru(t){const s=[],a=[];for(let r=t.startRow;r<=t.endRow;r+=1){const n=Zt(t,r);if(n){if(sa.some(o=>Se(n,o))){s.push(n);continue}(Se(n,"IMPORTANT")||Se(n,"NOTE")||Se(n,"ATTACHMENT")||Se(n,"LOOK UP"))&&a.push(n)}}return{attachmentRules:Array.from(new Set(s)),helperNotes:Array.from(new Set(a))}}function nu(t){const s=[],a={region:Ct(t,bt.region),division:Ct(t,bt.division),schoolName:Ct(t,bt.schoolName),schoolId:Ct(t,bt.schoolId),schoolYear:Ct(t,bt.schoolYear),gradeSection:Ct(t,bt.gradeSection),semester:Ct(t,bt.semester),track:Ct(t,bt.track),subjectCode:Ct(t,bt.subjectCode),subjectName:Ct(t,bt.subjectName),teacherName:Ct(t,bt.teacherName)},r=au(t),n=su(t),{attachmentRules:o,helperNotes:l}=ru(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."),Mr(t,Object.values(bt).flat()).length<4&&s.push("Input Data sheet contains limited metadata anchors; layout may have drifted."),{sheetName:t.sheetName,schoolContext:a,learners:r,signatures:n,attachmentRules:o,helperNotes:l,warnings:s}}function ou(t){const s=it(t.sheetName);return Om.SECOND.some(a=>Se(s,a))?"SECOND":"FIRST"}function lu(t,s){const a=[],r=[],n=[];let o,l="NONE";for(let i=t.startCol;i<=t.endCol;i+=1){const c=ze(t,s,i),d=it(c?.displayValue||""),u=ze(t,s+1,i),N=String(u?.displayValue||c?.displayValue||"").trim();if(!d&&!N)continue;if(Se(d,Le.writtenWork[0])){l="WW";continue}if(Se(d,Le.performanceTasks[0])){l="PT";continue}if(Se(d,Le.quarterlyAssessment[0])){o={key:Za(N||"quarterly_assessment"),label:N||"Quarterly Assessment",column:Ls(i)},l="DERIVED";continue}if(Se(d,Le.initialGrade[0])||Se(d,Le.quarterlyGrade[0])||Se(d,Le.remark[0])||Se(d,Le.additionalRemarks[0])||Se(d,Le.firstQuarter[0])||Se(d,Le.secondQuarter[0])||Se(d,Le.firstSemester[0])||Se(d,Le.finalGrades[0])||Se(d,Le.ps[0])||Se(d,Le.ws[0])||Se(d,Le.total[0])){l="DERIVED",n.push({key:Za(N||d),label:N||d,column:Ls(i)});continue}const m={key:Za(N||d||Ls(i)),label:N||d||Ls(i),maxScore:ga(u?.displayValue),column:Ls(i)};l==="WW"?a.push(m):l==="PT"?r.push(m):l==="DERIVED"&&n.push(m)}return{writtenWorks:a,performanceTasks:r,quarterlyAssessment:o,derived:n}}function iu(t){const s=["SUBMITTED BY","CHECKED BY","VERIFIED BY","RECOMMENDED BY","APPROVED BY"],a=[];return s.forEach(r=>{dt(t,r).forEach(n=>{const o=ze(t,n.row,n.col+1),l=String(o?.displayValue||"").trim()||void 0;a.push({role:r,name:l,sourceSheet:t.sheetName,sourceRow:n.row+1})})}),a}function to(t,s,a){for(let r=t.startCol;r<=t.endCol;r+=1){const n=it(ze(t,s,r)?.displayValue||""),o=it(ze(t,s+1,r)?.displayValue||"");if(a.some(l=>Se(n,l)||Se(o,l)))return r}}function cu(t,s,a,r){const n={learnerNo:Sa(ze(t,s,r.numberCol)?.displayValue),fullName:String(ze(t,s,r.nameCol)?.displayValue||"").trim(),sourceRow:s+1},o={};a.writtenWorks.forEach(d=>{const u=d.column?da(d.column):-1;if(u<0)return;const N=ze(t,s,u)?.displayValue;o[d.key]=N??null}),Object.keys(o).length>0&&(n.writtenWorks=o);const l={};if(a.performanceTasks.forEach(d=>{const u=d.column?da(d.column):-1;if(u<0)return;const N=ze(t,s,u)?.displayValue;l[d.key]=N??null}),Object.keys(l).length>0&&(n.performanceTasks=l),a.quarterlyAssessment?.column){const d=da(a.quarterlyAssessment.column);n.quarterlyAssessment=ze(t,s,d)?.displayValue??null}const i=a.derived||[],c={};return i.forEach(d=>{if(!d.column)return;const u=da(d.column);if(u<0)return;const N=ze(t,s,u)?.displayValue??null;c[d.key]=N,Se(d.label,Le.initialGrade[0])&&(n.initialGrade=N),Se(d.label,Le.quarterlyGrade[0])&&(n.quarterlyGrade=N),Se(d.label,Le.firstQuarter[0])&&(n.firstQuarter=N),Se(d.label,Le.secondQuarter[0])&&(n.secondQuarter=N),Se(d.label,Le.firstSemester[0])&&(n.firstSemester=N),Se(d.label,Le.finalGrades[0])&&(n.finalGrades=N),Se(d.label,Le.remark[0])&&(n.remark=N!==null?String(N):null),Se(d.label,Le.additionalRemarks[0])&&(n.additionalRemarks=N!==null?String(N):null)}),Object.keys(c).length>0&&(n.totals=c),n}function du(t){const s=ou(t),a=[],r=dt(t,Le.learnerName[0])[0]||dt(t,Le.learnerName[1])[0],n=r?jl(t,r.row,4):t.startRow,o=lu(t,n),l=to(t,n,Le.learnerNo)??t.startCol,i=to(t,n,Le.learnerName)??Math.min(t.endCol,l+1),c=[];let d="UNKNOWN",u=0;for(let w=n+1;w<=t.endRow;w+=1){const k=Zt(t,w),y=Dr({rowText:k,hasLearnerNumber:/\b\d{1,2}\b/.test(k),hasLearnerName:/[A-Z]{2,}/.test(k)});if(y==="sex-header"){d=Lr(k)||d;continue}if(y==="signature"||y==="helper")break;if(y==="blank"){if(u+=1,u>=gl)break;continue}if(y!=="learner")continue;u=0;const f=cu(t,w,o,{numberCol:l,nameCol:i});if(f.sex=d,!f.fullName&&f.learnerNo===void 0)continue;const v=sa.filter(S=>Se(k,S));v.length>0&&!f.additionalRemarks&&(f.additionalRemarks=v.join("; ")),!f.fullName&&f.learnerNo!==void 0&&(a.push(`Row ${w+1} has learner number ${f.learnerNo} but empty name.`),f.fullName=`Unnamed Learner ${f.learnerNo}`),c.push(f)}o.writtenWorks.length===0&&o.performanceTasks.length===0&&a.push(`No detailed assessment columns detected in ${t.sheetName}.`);const N=ga(dt(t,"WRITTEN WORK %")[0]?.value||dt(t,"WRITTEN WORK")[0]?.value),m=ga(dt(t,"PERFORMANCE TASKS %")[0]?.value||dt(t,"PERFORMANCE TASKS")[0]?.value),h=ga(dt(t,"QUARTERLY ASSESSMENT %")[0]?.value||dt(t,"QUARTERLY ASSESSMENT")[0]?.value);return{sheetName:t.sheetName,quarter:s,gradingWeights:{writtenWork:N,performanceTasks:m,quarterlyAssessment:h},assessmentColumns:o,learnerGrades:c,signatures:iu(t),warnings:a}}function mu(t){const s=["SUBMITTED BY","CHECKED BY","VERIFIED BY","RECOMMENDED BY","APPROVED BY"],a=[];return s.forEach(r=>{dt(t,r).forEach(n=>{a.push({role:r,name:String(ze(t,n.row,n.col+1)?.displayValue||"").trim()||void 0,sourceSheet:t.sheetName,sourceRow:n.row+1})})}),a}function uu(t){const s=[];let a=!1;for(let r=t.startRow;r<=t.endRow;r+=1){const n=Zt(t,r);if(!n){if(a&&s.length>0)break;continue}if(Se(n,"WEIGHT OF COMPONENTS")){a=!0;continue}if(!a)continue;const o={sourceRow:r+1,raw:n};for(let l=t.startCol;l<=t.endCol;l+=1){const i=ze(t,r,l)?.displayValue;i==null||String(i).trim()===""||(o[`c${l}`]=i)}Object.keys(o).length>2&&s.push(o)}return s}function xu(t){const s=[],a=[],r=[],n=[],o=[];return t.forEach(l=>{mu(l).forEach(i=>a.push(i)),uu(l).forEach(i=>r.push({...i,sourceSheet:l.sheetName}));for(let i=l.startRow;i<=l.endRow;i+=1){const c=Zt(l,i);if(c){if(sa.some(d=>Se(c,d))){n.push(`${l.sheetName}: ${c}`);continue}(Se(c,"HELPER")||Se(c,"LOOK UP")||Se(c,"IMPORTANT")||Se(c,"REFERENCE")||Se(c,"ATTACHMENT"))&&o.push(`${l.sheetName}: ${c}`)}}}),r.length===0&&s.push("No component weight rows were parsed from reference sheets."),{sheetName:t.map(l=>l.sheetName).join(", "),componentWeights:r,attachmentRules:Array.from(new Set(n)),helperNotes:Array.from(new Set(o)),signatures:a,warnings:s}}function hu(t,s,a){const r=new Map,n=o=>{const l=`${it(o.fullName)}|${o.learnerNo||""}|${o.sourceSheet}`,i=r.get(l);if(!i){r.set(l,o);return}const c=Array.from(new Set([...i.statuses||[],...o.statuses||[]]));r.set(l,{...i,...o,remarks:o.remarks||i.remarks,additionalRemarks:o.additionalRemarks||i.additionalRemarks,statuses:c.length>0?c:void 0})};return t.forEach(n),s.forEach(o=>{o.learnerGrades.forEach(l=>{n({learnerNo:l.learnerNo,sex:l.sex,fullName:l.fullName,sourceSheet:o.sheetName,sourceRow:l.sourceRow,remarks:l.remark||void 0,additionalRemarks:l.additionalRemarks||void 0})})}),a.forEach(o=>{o.learnerGrades.forEach(l=>{n({learnerNo:l.learnerNo,sex:l.sex,fullName:l.fullName,sourceSheet:o.sheetName,sourceRow:l.sourceRow,remarks:l.remark||void 0,additionalRemarks:l.additionalRemarks||void 0})})}),Array.from(r.values())}function pu(t,s,a,r){const n=[...t.signatures,...s.flatMap(l=>l.signatures),...a.flatMap(l=>l.signatures),...r.signatures],o=new Map;return n.forEach(l=>{const i=`${it(l.role)}|${it(l.name||"")}|${l.sourceSheet}`;o.set(i,l)}),Array.from(o.values())}function fu(t){const s=hu(t.inputData.learners,t.quarterSheets,t.finalSheets);return{format:fl,version:zm,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:pu(t.inputData,t.quarterSheets,t.finalSheets,t.references),unclassifiedBlocks:t.unclassifiedBlocks},validation:t.validation,raw:t.workbook.raw}}function gu(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 bu(t){const s={ref:t["!ref"],merges:gu(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 vu(t,s){const a=Pi(s,{type:"array",cellFormula:!0,cellNF:!0,cellText:!0,cellDates:!0,raw:!1}),r={},n={};return a.SheetNames.forEach(o=>{const l=a.Sheets[o];if(!l)return;const i=bu(l);n[o]=i,r[o]=Wm(o,i)}),{fileName:t,sheetNames:a.SheetNames,raw:{sheets:n},matrices:r}}async function Nu(t){const s=await t.arrayBuffer();return vu(t.name,s)}class ju{state={};markRange(s,a,r){const n=s;this.state[n]||(this.state[n]={mappedAddresses:new Set,mappings:[]});for(let o=a.s.r;o<=a.e.r;o+=1)for(let l=a.s.c;l<=a.e.c;l+=1)this.state[n].mappedAddresses.add(`${o}:${l}`);this.state[n].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(n=>{const o=new Set,l=this.state[n.sheetName]?.mappedAddresses??new Set;for(let i=n.startRow;i<=n.endRow;i+=1)for(let c=n.startCol;c<=n.endCol;c+=1){const d=`${i}:${c}`;if(o.has(d)||l.has(d))continue;const u=ze(n,i,c);if(!(u&&u.displayValue!==null&&u.displayValue!==void 0&&String(u.displayValue).trim())){o.add(d);continue}const m=this.collectComponent(n,i,c,l,o);m&&r.push({sheetName:n.sheetName,range:Vm(m),purposeGuess:a,raw2D:qm(n,m)})}}),r}collectComponent(s,a,r,n,o){const l=[{row:a,col:r}];let i=a,c=a,d=r,u=r,N=!1;for(;l.length>0;){const m=l.shift();if(!m)break;const h=`${m.row}:${m.col}`;if(o.has(h)||n.has(h))continue;o.add(h);const w=ze(s,m.row,m.col);w&&w.displayValue!==null&&w.displayValue!==void 0&&String(w.displayValue).trim()&&(N=!0,i=Math.min(i,m.row),c=Math.max(c,m.row),d=Math.min(d,m.col),u=Math.max(u,m.col),[{row:m.row-1,col:m.col},{row:m.row+1,col:m.col},{row:m.row,col:m.col-1},{row:m.row,col:m.col+1}].forEach(y=>{y.rows.endRow||y.cols.endCol||l.push(y)}))}return N?{s:{r:i,c:d},e:{r:c,c:u}}:null}}function yu(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,n)=>r+n,0);return{totalSheets:t.totalSheets,recognizedSheets:a,unclassifiedSheets:s.other.length,mappedCellRegions:t.mappedCellRegions,unmappedCellRegions:t.unmappedCellRegions}}function wu(t){const s=new Map;t.forEach(r=>{const n=`${r.learnerNo||""}|${r.fullName.trim().toUpperCase()}`;s.has(n)||s.set(n,[]),s.get(n)?.push(r.sourceRow)});const a=[];return s.forEach((r,n)=>{r.length>1&&a.push(`Duplicate learner entry detected for ${n} at rows ${r.join(", ")}.`)}),a}function Su(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 n=r.writtenWorks&&Object.values(r.writtenWorks).some(l=>l!==null&&l!==""),o=r.performanceTasks&&Object.values(r.performanceTasks).some(l=>l!==null&&l!=="");!n&&!o&&r.quarterlyAssessment==null&&s.push(`${a.sheetName} row ${r.sourceRow}: all grade blocks are empty.`)})}),s}function ku(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 Cu(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(", ")}.`),wu(t.inputData.learners).forEach(o=>s.push(o)),Su(t.quarterSheets).forEach(o=>s.push(o)),ku(t.finalSheets).forEach(o=>s.push(o)),s.push(...t.inputData.warnings),t.quarterSheets.forEach(o=>s.push(...o.warnings)),t.finalSheets.forEach(o=>s.push(...o.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,n=t.detection.isOfficialFormatLikely&&a.length===0;return r({fullName:l.fullName,learnerNo:l.learnerNo,sex:l.sex,remarks:l.remarks,additionalRemarks:l.additionalRemarks,statuses:l.statuses,sourceSheet:l.sourceSheet,sourceRow:l.sourceRow})),r=t.quarterlyRecords.flatMap(l=>l.learnerGrades.map(i=>({fullName:i.fullName,sourceSheet:l.sheetName,sourceRow:i.sourceRow,quarter:l.quarter,firstQuarter:i.firstQuarter,secondQuarter:i.secondQuarter,firstSemester:i.firstSemester,finalGrades:i.finalGrades,quarterlyGrade:i.quarterlyGrade,initialGrade:i.initialGrade,remark:i.remark,additionalRemarks:i.additionalRemarks}))),n=t.finalSemestralRecords.flatMap(l=>l.learnerGrades.map(i=>({fullName:i.fullName,sourceSheet:l.sheetName,sourceRow:i.sourceRow,firstQuarter:i.firstQuarter,secondQuarter:i.secondQuarter,firstSemester:i.firstSemester,finalGrades:i.finalGrades,remark:i.remark,additionalRemarks:i.additionalRemarks}))),o=[...t.learners,...t.quarterlyRecords.flatMap(l=>l.learnerGrades.map(i=>({learnerNo:i.learnerNo,sex:i.sex,fullName:i.fullName,sourceSheet:l.sheetName,sourceRow:i.sourceRow,remarks:i.remark||void 0,additionalRemarks:i.additionalRemarks||void 0})))].map(l=>({fullName:l.fullName,remark:l.remarks||null,additionalRemarks:l.additionalRemarks||null,statuses:"statuses"in l?l.statuses:void 0,sourceSheet:l.sourceSheet,sourceRow:l.sourceRow}));return{classEntity:s,studentEntities:a,gradeEntities:[...r,...n],remarksEntities:o}}const so=1500;function ao(t){return t?Object.values(t.matrices).reduce((s,a)=>s+a.rowCount*a.colCount,0):0}function ro(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>=so){console.warn(`${s} slow=true threshold=${so}ms`);return}}function as(t,s){t?.onProgress?.(s)}function Iu(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 Ds(t,s,a,r){Iu(a,s).forEach(n=>{t.markRange(s.sheetName,{s:{r:n,c:s.startCol},e:{r:n,c:s.endCol}},r)})}async function Eu(t,s){const a=s?.confidenceThreshold??Dm,r=Date.now();let n=null;try{if(as(s,{stage:"reading",message:"Reading workbook structure and raw sheets..."}),n=await Nu(t),!n)throw new Error("Workbook read returned null");as(s,{stage:"detecting-format",message:"Detecting DepEd SHS workbook format..."});const o=Zm(n);as(s,{stage:"extracting",message:"Extracting metadata, learners, grades, and references..."});const l=o.detectedSheets.inputData||n.sheetNames[0],i=n.matrices[l],c=i?nu(i):{sheetName:l,schoolContext:{},learners:[],signatures:[],attachmentRules:[],helperNotes:[],warnings:["Input data sheet was not available in matrix map."]},u=[...o.detectedSheets.firstQuarter||[],...o.detectedSheets.secondQuarter||[]].map(S=>n.matrices[S]).filter(S=>!!S).map(S=>du(S)),N=(o.detectedSheets.finalSemestral||[]).map(S=>n.matrices[S]).filter(S=>!!S).map(S=>tu(S)),m=[...o.detectedSheets.helper||[],...o.detectedSheets.lookup||[]].map(S=>n.matrices[S]).filter(S=>!!S),h=xu(m),w=new ju;o.anchorMatches.forEach(S=>{const R=n.matrices[S.sheetName];R&&Ds(w,R,[S.row],`Anchor match: ${S.anchor}`)}),[c.sheetName].forEach(S=>{const R=n.matrices[S];if(!R)return;const j=Array.from({length:Math.min(14,R.rowCount)},(b,T)=>R.startRow+T),B=c.learners.map(b=>b.sourceRow-1),g=c.signatures.map(b=>b.sourceRow).filter(b=>typeof b=="number").map(b=>b-1);Ds(w,R,[...j,...B,...g],"Input Data parsed rows")}),u.forEach(S=>{const R=n.matrices[S.sheetName];if(!R)return;const j=S.learnerGrades.map(b=>b.sourceRow-1),B=S.signatures.map(b=>b.sourceRow).filter(b=>typeof b=="number").map(b=>b-1),g=j.length>0?Math.max(R.startRow,Math.min(...j)-2):R.startRow;Ds(w,R,[g,g+1,...j,...B],"Quarter sheet parsed rows")}),N.forEach(S=>{const R=n.matrices[S.sheetName];if(!R)return;const j=S.learnerGrades.map(b=>b.sourceRow-1),B=S.signatures.map(b=>b.sourceRow).filter(b=>typeof b=="number").map(b=>b-1),g=j.length>0?Math.max(R.startRow,Math.min(...j)-2):R.startRow;Ds(w,R,[g,g+1,...j,...B],"Final semestral parsed rows")}),m.forEach(S=>{const R=h.componentWeights.filter(g=>g.sourceSheet===S.sheetName).map(g=>g.sourceRow).filter(g=>typeof g=="number").map(g=>g-1),j=h.signatures?.filter(g=>g.sourceSheet===S.sheetName).map(g=>g.sourceRow).filter(g=>typeof g=="number").map(g=>g-1)||[],B=R.length===0&&j.length===0?[S.startRow,S.startRow+1,S.startRow+2]:[];Ds(w,S,[...R,...j,...B],"Reference/helper parsed rows")});const k=w.getUnmappedBlocks(n.matrices);as(s,{stage:"validating",message:"Validating completeness and structural integrity..."});const y=Cu({detection:o,inputData:c,quarterSheets:u,finalSheets:N,mappedCellRegions:w.getMappedRegionCount(),unmappedCellRegions:k.length,totalSheets:n.sheetNames.length});as(s,{stage:"normalizing",message:"Normalizing parsed workbook and creating entity mapping..."});const f=fu({workbook:n,detection:o,inputData:c,quarterSheets:u,finalSheets:N,references:h,validation:y,unclassifiedBlocks:k});f.validation.confidence{const o=Ru[t??"null"],l=o.icon,i=r&&s!==null&&s!==void 0?`${o.label} ${s}`:o.label;return e.jsxs("span",{className:`inline-flex items-center rounded-full border font-medium transition-colors ${o.color} ${Au[a]} ${n}`,title:`WRI: ${s??"N/A"} — ${o.description}`,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${o.dotColor}`}),e.jsx(l,{className:"flex-shrink-0",size:a==="sm"?10:a==="md"?12:14}),i]})},Mu="https://deign86-mathpulse-api-v3test.hf.space";async function Lu(t){const s=et(Ge,"managedStudents",t),a=await ns(s);if(!a.exists())return null;const r=a.data();return{wri:r.wri??null,riskStatus:r.riskStatus??null,riskUpdatedAt:r.riskUpdatedAt?r.riskUpdatedAt.toDate():null,weights:r.weights??{w1:.3,w2:.4,w3:.3},diagnosticScore:r.diagnosticScore??null,externalGradesAvg:r.externalGradesAvg??null,systemPerformanceAvg:r.systemPerformanceAvg??null,riskHistory:r.riskHistory??[],riskRecalcNeeded:r.riskRecalcNeeded??!1}}async function wl(t,s,a="manual"){const r=et(Ge,"managedStudents",t),n={wri:s.wri??0,riskStatus:s.risk_status,computedAt:new Date,trigger:a},o=s.risk_status==="pending_assessment"?null:s.risk_status;await yt(r,{wri:s.wri,riskStatus:o,riskUpdatedAt:ot(),riskHistory:hi(n),riskRecalcNeeded:!1,diagnosticScore:s.inputs.D,externalGradesAvg:s.inputs.G,systemPerformanceAvg:s.inputs.P})}async function Sl(t,s,a,r={w1:.3,w2:.4,w3:.3}){try{const n=new AbortController,o=setTimeout(()=>n.abort(),3e4),l=await fetch(`${Mu}/api/risk/compute`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({d:t,g:s,p:a,weights:r}),signal:n.signal});if(clearTimeout(o),!l.ok)throw new Error(`API error: ${l.status}`);return await l.json()}catch{return Du(t,s,a,r)}}function Du(t,s,a,r){if(t===null)return{wri:null,risk_status:"pending_assessment",inputs:{D:t,G:s,P:a},g_fallback:!1,p_fallback:!1};const n=s??t,o=a??t,l=s===null,i=a===null,c=Math.round((r.w1*t+r.w2*n+r.w3*o)*100)/100;let d;return c>=88?d="safe":c>=80?d="watch":c>=75?d="intervene":c>=68?d="critical":d="at_risk",{wri:c,risk_status:d,inputs:{D:t,G:n,P:o},g_fallback:l,p_fallback:i}}async function no(t){const s=await Lu(t);if(!s)throw new Error(`Student ${t} not found`);const a=await Sl(s.diagnosticScore??null,s.externalGradesAvg??null,s.systemPerformanceAvg??null,s.weights??{w1:.3,w2:.4,w3:.3});await wl(t,a,"manual")}function zu(t,s={}){const{autoRecalc:a=!1}=s,[r,n]=p.useState(null),[o,l]=p.useState(!0),[i,c]=p.useState(null);p.useEffect(()=>{if(!t){n(null),l(!1);return}const N=et(Ge,"managedStudents",t);return Xs(N,h=>{if(!h.exists()){n(null),l(!1);return}const w=h.data(),k={wri:w.wri??null,riskStatus:w.riskStatus??null,riskUpdatedAt:w.riskUpdatedAt?w.riskUpdatedAt.toDate():null,weights:w.weights??{w1:.3,w2:.4,w3:.3},diagnosticScore:w.diagnosticScore??null,externalGradesAvg:w.externalGradesAvg??null,systemPerformanceAvg:w.systemPerformanceAvg??null,riskHistory:w.riskHistory??[],riskRecalcNeeded:w.riskRecalcNeeded??!1};n(k),l(!1),c(null),a&&k.riskRecalcNeeded&&no(t).catch(y=>console.error("[useStudentRisk] auto-recalc failed:",y))},h=>{console.error("[useStudentRisk] snapshot error:",h),c(h instanceof Error?h.message:"Unknown error"),l(!1)})},[t,a]);const d=p.useCallback(async()=>{if(t){l(!0);try{await no(t)}catch(N){c(N instanceof Error?N.message:"Recalculation failed")}finally{l(!1)}}},[t]),u=p.useCallback(async N=>{if(!t||!r)return;n(h=>h&&{...h,weights:N});const m=await Sl(r.diagnosticScore??null,r.externalGradesAvg??null,r.systemPerformanceAvg??null,N);await wl(t,m,"manual")},[t,r]);return{wri:r?.wri??null,riskStatus:r?.riskStatus??null,diagnosticScore:r?.diagnosticScore??null,externalGradesAvg:r?.externalGradesAvg??null,systemPerformanceAvg:r?.systemPerformanceAvg??null,weights:r?.weights??{w1:.3,w2:.4,w3:.3},riskHistory:r?.riskHistory??[],riskUpdatedAt:r?.riskUpdatedAt??null,loading:o,error:i,recalculate:d,updateWeights:u,breakdown:{diagnostic:r?.diagnosticScore??null,external:r?.externalGradesAvg??null,system:r?.systemPerformanceAvg??null},pendingAssessment:r?.diagnosticScore===null}}const er=({label:t,value:s,weight:a,color:r})=>{const n=s??0;return(n*a).toFixed(1),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{className:"text-slate-600 font-medium",children:t}),e.jsxs("span",{className:"text-slate-900 font-semibold tabular-nums",children:[s!==null?`${s.toFixed(0)}%`:"—",e.jsxs("span",{className:"text-slate-400 font-normal text-xs ml-1",children:["(w=",a,")"]})]})]}),e.jsx("div",{className:"h-2 bg-slate-100 rounded-full overflow-hidden",children:e.jsx(Re.div,{className:`h-full rounded-full ${r}`,initial:{width:0},animate:{width:`${n}%`},transition:{duration:.6,ease:"easeOut"}})})]})},Fu=({studentId:t,studentName:s,className:a=""})=>{const[r,n]=p.useState(!1),{wri:o,riskStatus:l,diagnosticScore:i,externalGradesAvg:c,systemPerformanceAvg:d,weights:u,riskHistory:N,riskUpdatedAt:m,loading:h,recalculate:w,pendingAssessment:k}=zu(t),y=(()=>{if(!N||N.length<2)return"stable";const B=N.slice(-2),g=B[1].wri-B[0].wri;return g>2?"improving":g<-2?"declining":"stable"})(),f=y==="improving"?ka:y==="declining"?Ai:jo,v=(N??[]).slice(-10).map(B=>({wri:B.wri,date:B.computedAt})),S=u.w1,R=u.w2,j=u.w3;return e.jsxs("div",{className:`bg-white border border-slate-200 rounded-lg overflow-hidden ${a}`,children:[e.jsxs("button",{onClick:()=>n(!r),className:"w-full flex items-center justify-between p-4 hover:bg-slate-50 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(yl,{status:l,wri:o,size:"md",showScore:!0}),s&&e.jsx("span",{className:"text-sm font-medium text-slate-700",children:s}),o!==null&&e.jsxs("span",{className:`flex items-center gap-1 text-xs ${y==="improving"?"text-emerald-600":y==="declining"?"text-rose-600":"text-slate-500"}`,children:[e.jsx(f,{size:12}),e.jsx("span",{className:"capitalize",children:y})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[!k&&e.jsxs($e,{variant:"ghost",size:"sm",onClick:B=>{B.stopPropagation(),w()},disabled:h,className:"text-xs h-7 px-2",children:[e.jsx(_s,{size:10,className:h?"animate-spin":""}),"Recalc"]}),e.jsx(Ht,{size:16,className:`text-slate-400 transition-transform ${r?"rotate-180":""}`})]})]}),k&&e.jsx("div",{className:"px-4 pb-4",children:e.jsxs("div",{className:"flex items-center gap-2 text-sm text-slate-500 bg-slate-50 rounded-lg p-3",children:[e.jsx(ko,{size:14,className:"text-slate-400"}),e.jsx("span",{children:"Complete the initial diagnostic assessment to calculate WRI."})]})}),e.jsx(Qt,{children:r&&!k&&e.jsx(Re.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.2},className:"overflow-hidden",children:e.jsxs("div",{className:"px-4 pb-4 space-y-4",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs font-semibold text-slate-500 uppercase tracking-wide",children:[e.jsx(lc,{size:12}),"Score Breakdown"]}),e.jsx(er,{label:"Diagnostic (D)",value:i,weight:S,color:"bg-blue-500"}),e.jsx(er,{label:"External Grades (G)",value:c,weight:R,color:"bg-violet-500"}),e.jsx(er,{label:"System Performance (P)",value:d,weight:j,color:"bg-cyan-500"})]}),e.jsxs("div",{className:"bg-slate-50 rounded-lg p-3 space-y-1",children:[e.jsx("div",{className:"text-xs font-medium text-slate-600",children:"Formula"}),e.jsxs("div",{className:"font-mono text-sm text-slate-700",children:["WRI = (",S,")×D + (",R,")×G + (",j,")×P"]}),e.jsxs("div",{className:"text-xs text-slate-500",children:["= (",S,"×",i?.toFixed(0)??"—",") + (",R,"×",c?.toFixed(0)??"—",") + (",j,"×",d?.toFixed(0)??"—",")"," ",e.jsxs("span",{className:"font-semibold text-slate-700",children:["= ",o??"—"]})]})]}),v.length>1&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-xs font-semibold text-slate-500 uppercase tracking-wide",children:"Risk Trend"}),e.jsx("div",{className:"h-16 w-full",children:e.jsx(sr,{width:"100%",height:"100%",children:e.jsxs(_i,{data:v,margin:{top:2,right:2,bottom:2,left:2},children:[e.jsx(ar,{domain:[0,100],hide:!0}),e.jsx(oa,{y:68,stroke:"#000000",strokeDasharray:"3 3",strokeOpacity:.5}),e.jsx(oa,{y:75,stroke:"#f43f5e",strokeDasharray:"3 3",strokeOpacity:.5}),e.jsx(oa,{y:80,stroke:"#3b82f6",strokeDasharray:"3 3",strokeOpacity:.5}),e.jsx(oa,{y:88,stroke:"#10b981",strokeDasharray:"3 3",strokeOpacity:.5}),e.jsx(rr,{formatter:B=>[`${B.toFixed(1)}`,"WRI"],labelFormatter:(B,g)=>g?.[0]?.payload?.date?new Date(g[0].payload.date).toLocaleDateString():""}),e.jsx(Hi,{type:"monotone",dataKey:"wri",stroke:"#6366f1",strokeWidth:2,dot:{r:2,fill:"#6366f1"},activeDot:{r:4}})]})})}),e.jsxs("div",{className:"flex flex-wrap gap-x-4 gap-y-1 text-xs text-slate-400",children:[e.jsx("span",{className:"text-black",children:"— 68 (At-Risk floor)"}),e.jsx("span",{className:"text-rose-500",children:"— 75 (Critical threshold)"}),e.jsx("span",{className:"text-blue-500",children:"— 80 (Watch threshold)"}),e.jsx("span",{className:"text-emerald-500",children:"— 88 (Safe threshold)"})]})]}),m&&e.jsxs("div",{className:"text-xs text-slate-400 text-right",children:["Last computed: ",m.toLocaleString()]}),e.jsx("div",{className:"text-xs text-slate-400 italic border-t border-slate-100 pt-2",children:"WRI thresholds based on DepEd DO No. 8, s. 2015. WRI is a support tool — final decisions remain with the teacher."})]})})})]})},Bu=({studentId:t,studentName:s})=>{const[a,r]=p.useState(null),[n,o]=p.useState(!0),[l,i]=p.useState(!1);p.useEffect(()=>{const m=et(Ge,"interventionChecklists",t);return Xs(m,w=>{if(!w.exists()){r(null),o(!1);return}const k=w.data();r({studentId:k.studentId,items:k.items||[],generatedAt:k.generatedAt?.toDate()||null,acknowledged:k.acknowledged===!0,acknowledgedAt:k.acknowledgedAt?.toDate()||null,acknowledgedBy:k.acknowledgedBy||null}),o(!1)},w=>{console.error("[InterventionChecklistPanel] error:",w),o(!1)})},[t]);const c=async m=>{if(!a||l)return;i(!0);const h=a.items.map(w=>w.id===m?{...w,completed:!w.completed}:w);try{const w=et(Ge,"interventionChecklists",t);await yt(w,{items:h})}catch(w){console.error("[InterventionChecklistPanel] toggle error:",w)}finally{i(!1)}},d=async()=>{if(!(!a||l)){i(!0);try{const m=et(Ge,"interventionChecklists",t);await yt(m,{acknowledged:!0,acknowledgedAt:ot()});const h=et(Ge,"users",t);await yt(h,{teacherAcknowledged:!0,teacherAckRequired:!1,teacherAcknowledgedAt:ot()})}catch(m){console.error("[InterventionChecklistPanel] acknowledge error:",m)}finally{i(!1)}}};if(n)return e.jsxs("div",{className:"flex items-center gap-2 text-sm text-slate-400 py-4",children:[e.jsx(nt,{size:14,className:"animate-spin"}),"Loading intervention checklist..."]});if(!a)return e.jsx("div",{className:"text-sm text-slate-400 py-2",children:"No intervention checklist generated yet."});const u=a.items.filter(m=>m.completed).length,N=u===a.items.length;return e.jsxs(Re.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},className:"bg-white border border-slate-200 rounded-lg p-4 mt-3",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(Zi,{size:16,className:"text-rose-500"}),e.jsxs("h4",{className:"text-sm font-semibold text-slate-800",children:["Intervention Checklist ",s?`— ${s}`:""]}),e.jsxs("span",{className:"text-xs text-slate-400 ml-auto",children:[u,"/",a.items.length," completed"]})]}),e.jsx("div",{className:"space-y-2",children:a.items.map(m=>e.jsxs("button",{onClick:()=>c(m.id),disabled:l||a.acknowledged,className:`w-full flex items-center gap-3 text-left px-3 py-2 rounded-md transition-colors ${m.completed?"bg-emerald-50 text-emerald-700":"bg-slate-50 text-slate-700 hover:bg-slate-100"} ${a.acknowledged?"opacity-60 cursor-not-allowed":"cursor-pointer"}`,children:[m.completed?e.jsx(dc,{size:16,className:"flex-shrink-0"}):e.jsx(ki,{size:16,className:"flex-shrink-0 text-slate-400"}),e.jsx("span",{className:`text-sm ${m.completed?"line-through opacity-70":""}`,children:m.text})]},m.id))}),!a.acknowledged&&e.jsxs("div",{className:"mt-4 flex items-center justify-between",children:[e.jsx("div",{className:"text-xs text-slate-500",children:N?"All items completed. You can now acknowledge.":"Complete all items before acknowledging."}),e.jsxs($e,{size:"sm",onClick:d,disabled:l||!N,className:"text-xs",children:[l?e.jsx(nt,{size:12,className:"animate-spin mr-1"}):e.jsx(ja,{size:12,className:"mr-1"}),"Acknowledge & Unlock"]})]}),a.acknowledged&&e.jsxs("div",{className:"mt-3 flex items-center gap-2 text-sm text-emerald-600 bg-emerald-50 rounded-md px-3 py-2",children:[e.jsx(ja,{size:14}),"Acknowledged on ",a.acknowledgedAt?.toLocaleDateString()||"—"]})]})},fs=({label:t,value:s,icon:a,color:r})=>e.jsxs("div",{className:"flex items-center gap-3 bg-white border border-slate-200 rounded-lg p-4",children:[e.jsx("div",{className:`w-10 h-10 rounded-lg flex items-center justify-center ${r}`,children:a}),e.jsxs("div",{children:[e.jsx("div",{className:"text-2xl font-bold text-slate-900 tabular-nums",children:s}),e.jsx("div",{className:"text-xs text-slate-500 font-medium",children:t})]})]}),$u=()=>{const[t,s]=p.useState([]),[a,r]=p.useState(!0),[n,o]=p.useState("all"),[l,i]=p.useState(""),[c,d]=p.useState("wri"),[u,N]=p.useState("asc"),[m,h]=p.useState(null);p.useEffect(()=>{const v=Bt(Ge,"managedStudents");return Xs(v,R=>{const j=R.docs.map(B=>{const g=B.data();return{id:B.id,...g,wri:g.wri??null,riskStatus:g.riskStatus??null,diagnosticScore:g.diagnosticScore??null,externalGradesAvg:g.externalGradesAvg??null,systemPerformanceAvg:g.systemPerformanceAvg??null}});s(j),r(!1)},R=>{console.error("[AtRiskDashboard] error:",R),r(!1)})},[]);const w=p.useMemo(()=>{let v=[...t];if(n!=="all"&&(v=v.filter(S=>S.riskStatus===n)),l.trim()){const S=l.toLowerCase();v=v.filter(R=>(R.name||"").toLowerCase().includes(S)||(R.email||"").toLowerCase().includes(S)||(R.lrn||"").toLowerCase().includes(S))}return v.sort((S,R)=>{let j=0;return c==="name"?j=String(S.name||S.email||"").localeCompare(String(R.name||R.email||"")):c==="wri"?j=(S.wri??100)-(R.wri??100):c==="updatedAt"&&(j=(S.updatedAt?.seconds??0)-(R.updatedAt?.seconds??0)),u==="asc"?j:-j}),v},[t,n,l,c,u]),k=p.useMemo(()=>{const v=t.length,S=t.filter(b=>b.riskStatus==="safe").length,R=t.filter(b=>b.riskStatus==="watch").length,j=t.filter(b=>b.riskStatus==="intervene").length,B=t.filter(b=>b.riskStatus==="critical").length,g=t.filter(b=>b.riskStatus==="at_risk").length;return{total:v,safe:S,watch:R,intervene:j,critical:B,atRisk:g}},[t]),y=v=>{c===v?N(S=>S==="asc"?"desc":"asc"):(d(v),N("asc"))},f=({field:v})=>c!==v?null:u==="asc"?e.jsx(Vi,{size:12}):e.jsx(Ui,{size:12});return e.jsxs("div",{className:"min-h-screen bg-slate-50",children:[e.jsx("div",{className:"bg-white border-b border-slate-200 px-6 py-4",children:e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-bold text-slate-900",children:"At-Risk Student Monitoring"}),e.jsx("p",{className:"text-sm text-slate-500 mt-0.5",children:"Track student risk using the Weighted Risk Index (WRI) based on DepEd grading standards"})]})})}),e.jsxs("div",{className:"px-6 py-6 space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-4",children:[e.jsx(fs,{label:"Total Students",value:k.total,icon:e.jsx(Ps,{size:20,className:"text-slate-600"}),color:"bg-slate-100"}),e.jsx(fs,{label:"Safe",value:k.safe,icon:e.jsx(Co,{size:20,className:"text-emerald-600"}),color:"bg-emerald-50"}),e.jsx(fs,{label:"Watch",value:k.watch,icon:e.jsx(pr,{size:20,className:"text-blue-600"}),color:"bg-blue-50"}),e.jsx(fs,{label:"Intervene",value:k.intervene,icon:e.jsx(Gt,{size:20,className:"text-amber-600"}),color:"bg-amber-50"}),e.jsx(fs,{label:"Critical",value:k.critical,icon:e.jsx(Ca,{size:20,className:"text-rose-600"}),color:"bg-rose-50"}),e.jsx(fs,{label:"At Risk",value:k.atRisk,icon:e.jsx(Eo,{size:20,className:"text-slate-600"}),color:"bg-slate-100"})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx("div",{className:"flex items-center gap-1 bg-white border border-slate-200 rounded-lg p-1",children:["all","safe","watch","intervene","critical","at_risk"].map(v=>e.jsxs("button",{onClick:()=>o(v),className:`px-3 py-1.5 text-sm rounded-md font-medium transition-colors ${n===v?"bg-slate-900 text-white":"text-slate-600 hover:bg-slate-100"}`,children:[v==="all"?"All":v==="at_risk"?"At Risk":v.charAt(0).toUpperCase()+v.slice(1),v!=="all"&&e.jsxs("span",{className:"ml-1.5 text-xs opacity-70",children:["(",k[v],")"]})]},v))}),e.jsxs("div",{className:"relative flex-1 max-w-xs",children:[e.jsx(Js,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-400"}),e.jsx("input",{type:"text",placeholder:"Search student...",value:l,onChange:v=>i(v.target.value),className:"w-full pl-9 pr-3 py-2 text-sm bg-white border border-slate-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-slate-900/10 focus:border-slate-300"})]}),e.jsxs("div",{className:"text-sm text-slate-500",children:[w.length," student",w.length!==1?"s":""]})]}),e.jsx("div",{className:"bg-white border border-slate-200 rounded-lg overflow-hidden",children:a?e.jsxs("div",{className:"flex items-center justify-center py-16",children:[e.jsx(_s,{size:20,className:"animate-spin text-slate-400"}),e.jsx("span",{className:"ml-2 text-slate-500",children:"Loading students..."})]}):w.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-slate-400",children:[e.jsx(Ps,{size:32}),e.jsx("p",{className:"mt-2 text-sm",children:"No students found"})]}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-slate-50 border-b border-slate-200",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left px-4 py-3 font-semibold text-slate-700",children:e.jsxs("button",{onClick:()=>y("name"),className:"flex items-center gap-1 hover:text-slate-900",children:["Student ",e.jsx(f,{field:"name"})]})}),e.jsx("th",{className:"text-left px-4 py-3 font-semibold text-slate-700",children:"Status"}),e.jsx("th",{className:"text-left px-4 py-3 font-semibold text-slate-700",children:e.jsxs("button",{onClick:()=>y("wri"),className:"flex items-center gap-1 hover:text-slate-900",children:["WRI ",e.jsx(f,{field:"wri"})]})}),e.jsx("th",{className:"text-left px-4 py-3 font-semibold text-slate-700 hidden md:table-cell",children:"Diagnostic"}),e.jsx("th",{className:"text-left px-4 py-3 font-semibold text-slate-700 hidden lg:table-cell",children:"External"}),e.jsx("th",{className:"text-left px-4 py-3 font-semibold text-slate-700 hidden lg:table-cell",children:"System"}),e.jsx("th",{className:"text-right px-4 py-3 font-semibold text-slate-700",children:"Actions"})]})}),e.jsx("tbody",{className:"divide-y divide-slate-100",children:w.map(v=>e.jsxs(oe.Fragment,{children:[e.jsxs("tr",{className:"hover:bg-slate-50/50 transition-colors cursor-pointer",onClick:()=>h(S=>S===v.id?null:v.id),children:[e.jsxs("td",{className:"px-4 py-3",children:[e.jsx("div",{className:"font-medium text-slate-900",children:v.name||"—"}),e.jsx("div",{className:"text-xs text-slate-500",children:v.email})]}),e.jsx("td",{className:"px-4 py-3",children:e.jsx(yl,{status:v.riskStatus,wri:v.wri,size:"sm",showScore:!0})}),e.jsx("td",{className:"px-4 py-3",children:e.jsx("span",{className:"font-mono font-semibold tabular-nums",children:v.wri!==null?v.wri.toFixed(1):"—"})}),e.jsx("td",{className:"px-4 py-3 text-slate-600 hidden md:table-cell tabular-nums",children:v.diagnosticScore!==null?`${v.diagnosticScore.toFixed(0)}%`:"—"}),e.jsx("td",{className:"px-4 py-3 text-slate-600 hidden lg:table-cell tabular-nums",children:v.externalGradesAvg!==null?`${v.externalGradesAvg.toFixed(0)}%`:"—"}),e.jsx("td",{className:"px-4 py-3 text-slate-600 hidden lg:table-cell tabular-nums",children:v.systemPerformanceAvg!==null?`${v.systemPerformanceAvg.toFixed(0)}%`:"—"}),e.jsx("td",{className:"px-4 py-3 text-right",onClick:S=>S.stopPropagation(),children:e.jsx("button",{onClick:()=>h(S=>S===v.id?null:v.id),className:"text-slate-400 hover:text-slate-600 transition-colors",children:e.jsx(Ht,{size:14,className:`transition-transform ${m===v.id?"rotate-180":""}`})})})]}),m===v.id&&e.jsx("tr",{children:e.jsxs("td",{colSpan:7,className:"px-4 py-4 bg-slate-50/50",children:[e.jsx(Fu,{studentId:v.id,studentName:v.name}),(v.riskStatus==="critical"||v.riskStatus==="at_risk")&&e.jsx(Bu,{studentId:v.id,studentName:v.name})]})})]},v.id))})]})})}),e.jsx("div",{className:"text-xs text-slate-400 text-center",children:"WRI classification based on DepEd DO No. 8, s. 2015 (Policy Guidelines on Classroom Assessment). WRI is a support tool — final academic decisions remain with the teacher."})]})]})};function Ou(t){const s=t.atRiskCount>=5?"high":t.atRiskCount>=2?"medium":"low",a=lt({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 Pu(t,s){const a=t.riskLevel.toLowerCase(),r=t.lastActive?kl(t.lastActive.toDate()):"Unknown",n=t.className||s||"Imported Class",o=Dt(n),l=t.grade||o.grade,i=t.section||o.section,c=lt({metadata:t.classMetadata,classSectionId:t.classSectionId||t.classroomId,className:[l,i].filter(Boolean).join(" - ")||n,grade:l,gradeLevel:t.gradeLevel,classification:t.classification,strand:t.strand,section:i,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,weakestTopic:t.weakestTopic||"N/A",classroomId:t.classroomId||c.classSectionId||n,className:c.className||[l,i].filter(Boolean).join(" - ")||n,grade:l,gradeLevel:c.gradeLevel||ds(l)||void 0,classification:c.classification||ws(c.gradeLevel||l)||void 0,strand:c.strand||Ss(c.className,i)||void 0,section:i,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}}function _u(t){const s=t.atRiskCount>=5?"high":t.atRiskCount>=2?"medium":"low",a=lt({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 Hu(t){const s=(t.riskLevel||"Low").toLowerCase(),a=lt({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||Dt(r).grade,gradeLevel:a.gradeLevel||ds(a.grade||Dt(r).grade)||void 0,classification:a.classification||ws(a.gradeLevel||a.grade)||void 0,strand:a.strand||Ss(r,a.section||t.section)||void 0,section:a.section||Dt(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 Gu(t,s,a){return t<60||s<75||a<55?"high":t<75||s<85||a<70?"medium":"low"}function Qu(t,s,a,r){const n=lt({metadata:r,classSectionId:s,className:a}),o=n.className||"Imported Class",l=n.classSectionId||"imported_class",i=Number(t.avgQuizScore||0),c=Number(t.attendance||0),d=Number(t.engagementScore||0),u=Number(t.assignmentCompletion||0),N=t.unknownFields?.weakestTopic||t.unknownFields?.topic||"Foundational Skills",m=Gu(i,c,d),h=t.studentId||t.lrn||t.email||t.name||Math.random().toString(36).slice(2);return{id:`upload-${l}-${h}`,lrn:t.lrn,name:t.name,avatar:`https://ui-avatars.com/api/?name=${encodeURIComponent(t.name)}&background=random`,avgScore:i,riskLevel:m,weakestTopic:N,classroomId:l,className:o,grade:n.grade||Dt(o).grade,gradeLevel:n.gradeLevel||ds(n.grade||Dt(o).grade)||void 0,classification:n.classification||ws(n.gradeLevel||n.grade)||void 0,strand:n.strand||Ss(o,n.section)||void 0,section:n.section||Dt(o).section,classSectionId:l,classMetadata:n,managerId:n.managerId||void 0,managerName:n.managerName||void 0,lastActive:"Recently imported",struggles:[N],engagementScore:d,attendance:c,assignmentCompletion:u}}function Uu(t,s,a,r){const n=lt({metadata:t.dashboardSync?.classMetadata||t.classMetadata||r,classSectionId:t.dashboardSync?.classSectionId||s,className:t.dashboardSync?.className||a}),o=n.classSectionId||"imported_class",l=n.className||"Imported Class";return{classSectionId:o,className:l,classMetadata:{...n,classSectionId:o,className:l}}}function kl(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 n=Math.floor(r/24);return`${n} day${n>1?"s":""} ago`}function rt(t){return(t||"").trim().toLowerCase()}function oo(t){const s=rt(t.classSectionId);if(s)return`section:${s}`;const a=(t.id||"").trim().toLowerCase();return a?`id:${a}`:`name:${(t.name||"").trim().toLowerCase()}`}function lo(t,s){const a=new Map;return t.forEach(r=>{a.set(oo(r),r)}),s.forEach(r=>{const n=oo(r),o=a.get(n);if(!o){a.set(n,r);return}const l=Math.max(o.atRiskCount||0,r.atRiskCount||0),i=Math.max(o.studentCount||0,r.studentCount||0),c=r.avgScore>0?r.avgScore:o.avgScore,d=l>=5?"high":l>=2?"medium":"low",u=lt({metadata:o.classMetadata,classSectionId:o.classSectionId||r.classSectionId,className:o.name||r.name,grade:o.classMetadata?.grade||r.classMetadata?.grade,gradeLevel:o.classMetadata?.gradeLevel||r.classMetadata?.gradeLevel,classification:o.classMetadata?.classification||r.classMetadata?.classification,strand:o.classMetadata?.strand||r.classMetadata?.strand,section:o.classMetadata?.section||r.classMetadata?.section,schoolYear:o.classMetadata?.schoolYear||r.classMetadata?.schoolYear,ownerTeacherId:o.classMetadata?.ownerTeacherId||r.classMetadata?.ownerTeacherId,ownerTeacherName:o.classMetadata?.ownerTeacherName||r.classMetadata?.ownerTeacherName,adviserTeacherId:o.classMetadata?.adviserTeacherId||r.classMetadata?.adviserTeacherId,adviserTeacherName:o.classMetadata?.adviserTeacherName||r.classMetadata?.adviserTeacherName,managerId:o.classMetadata?.managerId||r.classMetadata?.managerId,managerName:o.classMetadata?.managerName||r.classMetadata?.managerName});a.set(n,{...o,classSectionId:u.classSectionId||o.classSectionId||r.classSectionId,name:u.className||o.name||r.name,classMetadata:u,gradeLevel:u.gradeLevel||void 0,classification:u.classification||void 0,strand:u.strand||void 0,managerId:u.managerId||void 0,managerName:u.managerName||void 0,schedule:o.schedule||r.schedule,studentCount:i,atRiskCount:l,avgScore:c,riskLevel:d})}),Array.from(a.values())}function io(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=rt(t.classSectionId)||rt(t.classroomId),n=(t.id||"").trim().toLowerCase();return r&&n?`${r}|id:${n}`:`${r}|anonymous`}function Ns(t){const s=rt(t.classSectionId)||rt(t.classroomId),a=(t.lrn||"").trim().toLowerCase(),r=(t.id||"").trim().toLowerCase(),n=t.name.trim().toLowerCase().replace(/\s+/g,"_");return s&&a?`${s}|lrn:${a}`:s&&r?`${s}|id:${r}`:a?`lrn:${a}`:r&&n?`id:${r}|name:${n}`:r?`id:${r}`:s&&n?`${s}|name:${n}`:`name:${n||"unknown"}`}function co(t,s){const a=new Map;return t.forEach(r=>{a.set(io(r),r)}),s.forEach(r=>{const n=io(r),o=a.get(n);if(!o){a.set(n,r);return}const l=[o.riskLevel,r.riskLevel].includes("high")?"high":[o.riskLevel,r.riskLevel].includes("medium")?"medium":"low",i=lt({metadata:o.classMetadata,classSectionId:o.classSectionId||r.classSectionId,className:o.className||r.className,grade:o.grade||r.grade,gradeLevel:o.gradeLevel||r.gradeLevel,classification:o.classification||r.classification,strand:o.strand||r.strand,section:o.section||r.section,managerId:o.managerId||r.managerId,managerName:o.managerName||r.managerName});a.set(n,{...o,lrn:o.lrn||r.lrn,classSectionId:i.classSectionId||o.classSectionId||r.classSectionId,classroomId:o.classroomId||r.classroomId,className:i.className||o.className||r.className,grade:i.grade||o.grade||r.grade,gradeLevel:i.gradeLevel||o.gradeLevel||r.gradeLevel,classification:i.classification||o.classification||r.classification,strand:i.strand||o.strand||r.strand,section:i.section||o.section||r.section,managerId:i.managerId||o.managerId||r.managerId,managerName:i.managerName||o.managerName||r.managerName,classMetadata:i,avgScore:r.avgScore>0?r.avgScore:o.avgScore,attendance:r.attendance>0?r.attendance:o.attendance,engagementScore:r.engagementScore>0?r.engagementScore:o.engagementScore,assignmentCompletion:r.assignmentCompletion>0?r.assignmentCompletion:o.assignmentCompletion,weakestTopic:o.weakestTopic&&o.weakestTopic!=="N/A"?o.weakestTopic:r.weakestTopic,riskLevel:l,struggles:o.struggles.length>0?o.struggles:r.struggles})}),Array.from(a.values())}const Kx=({onLogout:t,onOpenProfile:s,onOpenSettings:a})=>{const{currentUser:r,userProfile:n}=Ks(),[o,l]=p.useState("dashboard"),[i,c]=p.useState(!1),[d,u]=p.useState(!1),[N,m]=p.useState(!1),[h,w]=p.useState(!1),[k,y]=p.useState(!1),[f,v]=p.useState(null),[S,R]=p.useState(null),[j,B]=p.useState([]),[g,b]=p.useState([]),[T,z]=p.useState([]),[$,Z]=p.useState(""),[ae,H]=p.useState(!0),[ee,re]=p.useState(!1),[ne,D]=p.useState(0),[te,J]=p.useState([]),[me,Ce]=p.useState(!1),F=p.useRef(new Map);p.useEffect(()=>{if(!r)return;const E=r.uid;let W=!0,je;return(async()=>{H(!0);try{const De=await ml(E);let fe=De.map(Ou);const Me=await Kd(E).catch(()=>[]),I=new Map;Me.forEach(U=>{const ue=rt(U.classSectionId);ue&&I.set(ue,U)}),fe=fe.map(U=>{const ue=I.get(rt(U.classSectionId));if(!ue)return U;const Be=lt({metadata:U.classMetadata,classSectionId:ue.classSectionId||U.classSectionId,className:ue.className||U.name,grade:ue.grade||U.classMetadata?.grade,gradeLevel:ue.gradeLevel||U.classMetadata?.gradeLevel,classification:ue.classification||U.classMetadata?.classification,strand:ue.strand||U.classMetadata?.strand,section:ue.section||U.classMetadata?.section,schoolYear:ue.schoolYear||U.classMetadata?.schoolYear,ownerTeacherId:ue.ownerTeacherId||U.classMetadata?.ownerTeacherId,ownerTeacherName:ue.ownerTeacherName||U.classMetadata?.ownerTeacherName,managerId:ue.managerId||U.classMetadata?.managerId,managerName:ue.managerName||U.classMetadata?.managerName});return{...U,name:Be.className||U.name,classSectionId:Be.classSectionId||U.classSectionId,classMetadata:Be,gradeLevel:Be.gradeLevel||U.gradeLevel,classification:Be.classification||U.classification,strand:Be.strand||U.strand,managerId:Be.managerId||U.managerId,managerName:Be.managerName||U.managerName}});const Y=new Map,ge=new Map;De.forEach(U=>{const ue=lt({metadata:U.classMetadata,classSectionId:U.classSectionId,className:U.name,grade:U.grade,gradeLevel:U.gradeLevel,classification:U.classification,strand:U.strand,section:U.section,schoolYear:U.schoolYear,ownerTeacherId:U.ownerTeacherId||U.teacherId,ownerTeacherName:U.ownerTeacherName,adviserTeacherId:U.adviserTeacherId||U.teacherId,adviserTeacherName:U.adviserTeacherName,managerId:U.managerId,managerName:U.managerName});Y.set(U.id,ue.className||U.name),ge.set(U.id,ue);const Be=rt(U.classSectionId);if(Be){const Te=I.get(Be),tt=lt({metadata:ue,classSectionId:Te?.classSectionId||Be,className:Te?.className||ue.className,grade:Te?.grade||ue.grade,gradeLevel:Te?.gradeLevel||ue.gradeLevel,classification:Te?.classification||ue.classification,strand:Te?.strand||ue.strand,section:Te?.section||ue.section,schoolYear:Te?.schoolYear||ue.schoolYear,ownerTeacherId:Te?.ownerTeacherId||ue.ownerTeacherId,ownerTeacherName:Te?.ownerTeacherName||ue.ownerTeacherName,managerId:Te?.managerId||ue.managerId,managerName:Te?.managerName||ue.managerName});Y.set(Be,tt.className||U.name),ge.set(Be,tt)}});const Je=(await Ar(E)).map(U=>{const ue=rt(U.classSectionId||U.classroomId),Be=Y.get(U.classroomId)||(ue?Y.get(ue):void 0)||U.className||"Unknown",Te=Pu(U,Be);if(!ue)return Te;const tt=ge.get(ue);if(!tt)return Te;const xt=lt({metadata:tt,classSectionId:Te.classSectionId||tt.classSectionId,className:Te.className||tt.className,grade:Te.grade||tt.grade,gradeLevel:Te.gradeLevel||tt.gradeLevel,classification:Te.classification||tt.classification,strand:Te.strand||tt.strand,section:Te.section||tt.section,managerId:Te.managerId||tt.managerId,managerName:Te.managerName||tt.managerName});return{...Te,className:xt.className||Te.className,grade:xt.grade||Te.grade,gradeLevel:xt.gradeLevel||Te.gradeLevel,classification:xt.classification||Te.classification,strand:xt.strand||Te.strand,section:xt.section||Te.section,classSectionId:xt.classSectionId||Te.classSectionId,classMetadata:xt,managerId:xt.managerId||Te.managerId,managerName:xt.managerName||Te.managerName}});if(!W)return;B(U=>fe.length===0&&U.length>0?U:fe),b(U=>Je.length===0&&U.length>0?U:Je),Ve.getImportedClassOverview({limit:3e3,forceRefresh:ne>0}).then(U=>{W&&(U.warnings.length>0&&console.warn("Imported class overview warnings:",U.warnings.join(" ")),B(ue=>lo(ue,U.classrooms.map(_u))),b(ue=>co(ue,U.students.map(Hu))))}).catch(U=>{console.warn("Imported class overview merge unavailable:",U)});const Xe=De.map(U=>U.id);Xe.length>0&&(je=Jd(Xe,U=>{W&&z(U.map(ue=>({id:ue.id,student:ue.studentName,action:ue.action,topic:ue.topic,time:kl(ue.timestamp.toDate()),type:ue.type})))}))}catch(De){console.error("Failed to load teacher data:",De),ce.error("Failed to load dashboard data")}finally{H(!1)}})(),()=>{W=!1,je&&je()}},[r,ne]),p.useEffect(()=>{if(!r)return;let E=!0;return Xd("",80).then(W=>{E&&J(W)}).catch(W=>{console.warn("Failed to load teacher directory options:",W)}),()=>{E=!1}},[r]),p.useEffect(()=>{if(g.length===0)return;(async()=>{re(!0);try{const W=g.map(pe=>({name:pe.name,engagementScore:pe.engagementScore,avgQuizScore:pe.avgScore,attendance:pe.attendance,riskLevel:pe.riskLevel})),je=await Ve.getDailyInsight({students:W});Z(je.insight)}catch{Z(`${g.filter(W=>W.riskLevel==="high").length} students are at high risk of falling behind. Review their progress in the analytics view.`)}finally{re(!1)}})()},[g]);const C=j.reduce((E,W)=>E+W.studentCount,0),K=j.reduce((E,W)=>E+W.atRiskCount,0),P=j.length>0?Math.round(j.reduce((E,W)=>E+W.avgScore,0)/j.length):0,xe=[{name:"High Risk",value:g.filter(E=>E.riskLevel==="high").length,color:"#FF8B8B"},{name:"Medium Risk",value:g.filter(E=>E.riskLevel==="medium").length,color:"#F08386"},{name:"Low Risk",value:g.filter(E=>E.riskLevel==="low").length,color:"#75D06A"}],M={};g.forEach(E=>{E.weakestTopic&&E.weakestTopic!=="N/A"&&(M[E.weakestTopic]||(M[E.weakestTopic]={total:0,sum:0}),M[E.weakestTopic].total+=1,M[E.weakestTopic].sum+=E.avgScore)});const G=Object.entries(M).map(([E,W])=>({topic:E,score:Math.round(W.sum/W.total)})).sort((E,W)=>E.score-W.score).slice(0,6),X=E=>{v(E),l("analytics")},le=E=>{R(E),l("intervention")},ie=()=>{R(null),l("analytics")},V=()=>{v(null),R(null),l("dashboard")},we=async(E,W)=>{if(!r){ce.error("Unable to assign manager: teacher context is missing.");return}const je=Dt(E.classMetadata?.className||E.name),pe=lt({metadata:E.classMetadata,classSectionId:E.classSectionId,className:E.name,grade:E.classMetadata?.grade||je.grade,gradeLevel:E.classMetadata?.gradeLevel,classification:E.classMetadata?.classification,strand:E.classMetadata?.strand,section:E.classMetadata?.section||je.section,schoolYear:E.classMetadata?.schoolYear||String(new Date().getFullYear()),ownerTeacherId:E.classMetadata?.ownerTeacherId||r.uid,ownerTeacherName:E.classMetadata?.ownerTeacherName||Pe,adviserTeacherId:E.classMetadata?.adviserTeacherId||r.uid,adviserTeacherName:E.classMetadata?.adviserTeacherName||Pe,managerId:W.uid,managerName:W.name}),De=pe.classSectionId||It(pe.grade||je.grade,pe.section||je.section);if(!De){ce.error("Unable to assign manager: missing class section ID.");return}Ce(!0);try{await Yd({classSectionId:De,className:pe.className||E.name,grade:pe.grade||je.grade,gradeLevel:pe.gradeLevel||ds(pe.grade||je.grade)||pe.grade||je.grade,classification:pe.classification||ws(pe.gradeLevel||pe.grade)||void 0,strand:pe.strand||Ss(pe.className,pe.section)||void 0,section:pe.section||je.section,schoolYear:pe.schoolYear||String(new Date().getFullYear()),ownerTeacherId:pe.ownerTeacherId||r.uid,ownerTeacherName:pe.ownerTeacherName||Pe,managerId:W.uid,managerName:W.name});const fe=lt({metadata:pe,classSectionId:De,managerId:W.uid,managerName:W.name}),Me=rt(De);B(I=>I.map(Y=>rt(Y.classSectionId)!==Me?Y:{...Y,name:fe.className||Y.name,classSectionId:fe.classSectionId||Y.classSectionId,classMetadata:fe,gradeLevel:fe.gradeLevel||Y.gradeLevel,classification:fe.classification||Y.classification,strand:fe.strand||Y.strand,managerId:W.uid,managerName:W.name})),b(I=>I.map(Y=>{if(rt(Y.classSectionId||Y.classroomId)!==Me)return Y;const He=lt({metadata:Y.classMetadata,classSectionId:fe.classSectionId||Y.classSectionId,className:Y.className||fe.className,grade:Y.grade||fe.grade,gradeLevel:Y.gradeLevel||fe.gradeLevel,classification:Y.classification||fe.classification,strand:Y.strand||fe.strand,section:Y.section||fe.section,managerId:W.uid,managerName:W.name});return{...Y,classMetadata:He,gradeLevel:He.gradeLevel||Y.gradeLevel,classification:He.classification||Y.classification,strand:He.strand||Y.strand,managerId:W.uid,managerName:W.name}})),v(I=>!I||rt(I.classSectionId)!==Me?I:{...I,classMetadata:fe,managerId:W.uid,managerName:W.name,gradeLevel:fe.gradeLevel||I.gradeLevel,classification:fe.classification||I.classification,strand:fe.strand||I.strand}),ce.success(`Assigned ${W.name} as section manager.`)}catch(fe){console.error("Failed to assign class manager:",fe),ce.error(fe instanceof Error?fe.message:"Failed to assign class manager")}finally{Ce(!1)}};p.useEffect(()=>{const E=()=>{const W=window.innerWidth<1024;w(W),W?c(!1):m(!1)};return E(),window.addEventListener("resize",E),()=>window.removeEventListener("resize",E)},[]),p.useEffect(()=>{h&&m(!1)},[o,h]);const Pe=n?.name||"Teacher",ke=p.useMemo(()=>{if(!f)return;if(f.classMetadata?.classSectionId)return f.classMetadata.classSectionId||void 0;if(f.classSectionId)return f.classSectionId;const E=Dt(f.classMetadata?.className||f.name);return It(E.grade,E.section)||void 0},[f]),O=p.useMemo(()=>f||j[0]||null,[f,j]),q=p.useMemo(()=>{if(!O)return g;const E=(O.id||"").trim().toLowerCase(),W=rt(O.classSectionId),je=(O.name||"").trim().toLowerCase();return g.filter(pe=>{const De=rt(pe.classroomId),fe=rt(pe.classSectionId),Me=(pe.className||"").trim().toLowerCase();return W&&(fe===W||De===W)||E&&(De===E||fe===E)||je&&Me===je})},[O,g]);return ae?e.jsxs("div",{className:"flex h-screen w-full bg-background p-6",children:[e.jsx("div",{className:"hidden lg:flex w-[280px] shrink-0 rounded-3xl border border-border bg-card p-5",children:e.jsxs("div",{className:"w-full space-y-4",children:[e.jsx(he,{className:"h-12 w-40"}),e.jsx(he,{className:"h-10 w-full"}),e.jsx(he,{className:"h-10 w-full"}),e.jsx(he,{className:"h-10 w-full"}),e.jsx(he,{className:"h-10 w-full"})]})}),e.jsxs("div",{className:"flex-1 space-y-4 lg:pl-6",children:[e.jsx(he,{className:"h-20 w-full rounded-2xl"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[e.jsx(he,{className:"h-28 w-full rounded-2xl"}),e.jsx(he,{className:"h-28 w-full rounded-2xl"}),e.jsx(he,{className:"h-28 w-full rounded-2xl"})]}),e.jsx(he,{className:"h-[420px] w-full rounded-2xl"})]})]}):e.jsxs("div",{className:"relative flex h-screen w-full bg-background overflow-hidden",children:[h&&N&&e.jsx("button",{"aria-label":"Close navigation",className:"fixed inset-0 z-30 bg-slate-900/40 backdrop-blur-[1px]",onClick:()=>m(!1)}),e.jsxs(Re.aside,{initial:!1,animate:{width:h?280:i&&!d?80:280,x:h?N?0:-300:0},transition:{type:"spring",stiffness:360,damping:34},onMouseEnter:()=>!h&&i&&u(!0),onMouseLeave:()=>u(!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 ${i&&!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"})}),(!i||d)&&e.jsx("div",{children:e.jsx("h1",{className:"text-base font-bold font-display text-[#0a1628] whitespace-nowrap",children:"MathPulse AI"})})]}),!h&&(!i||d)&&e.jsx(Re.button,{whileHover:{scale:1.1},whileTap:{scale:.95},onClick:()=>c(!i),className:"p-2 hover:bg-[#dde3eb] rounded-lg transition-colors text-[#5a6578]","aria-label":i?"Expand sidebar":"Collapse sidebar",children:i?e.jsx(Wt,{size:20}):e.jsx(Pt,{size:20})}),h&&e.jsx("button",{onClick:()=>m(!1),className:"p-2 hover:bg-[#dde3eb] rounded-lg transition-colors text-[#5a6578]","aria-label":"Close navigation",children:e.jsx(va,{size:20})})]}),e.jsxs("nav",{className:"flex-1 space-y-5",children:[e.jsxs("div",{children:[i&&!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-bold text-[#5a6578] uppercase tracking-widest",children:"Overview"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(At,{icon:ci,label:"Dashboard",active:o==="dashboard",collapsed:i&&!d,onClick:V,forceExpanded:h}),e.jsx(At,{icon:Hs,label:"Class Analytics",active:o==="analytics",collapsed:i&&!d,onClick:()=>l("analytics"),forceExpanded:h})]})]}),e.jsxs("div",{children:[i&&!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-bold text-[#5a6578] uppercase tracking-widest",children:"Students"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(At,{icon:Zl,label:"Topic Mastery",active:o==="topic_mastery",collapsed:i&&!d,onClick:()=>l("topic_mastery"),forceExpanded:h}),e.jsx(At,{icon:Ps,label:"Competency",active:o==="competency",collapsed:i&&!d,onClick:()=>l("competency"),forceExpanded:h}),e.jsx(At,{icon:Gt,label:"At-Risk Monitor",active:o==="at_risk",collapsed:i&&!d,onClick:()=>l("at_risk"),forceExpanded:h})]})]}),e.jsxs("div",{children:[i&&!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-bold text-[#5a6578] uppercase tracking-widest",children:"Tools"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(At,{icon:Mi,label:"Data Import",active:o==="import",collapsed:i&&!d,onClick:()=>l("import"),forceExpanded:h}),e.jsx(At,{icon:To,label:"AI Quiz Maker",active:o==="quiz_maker",collapsed:i&&!d,onClick:()=>l("quiz_maker"),forceExpanded:h}),e.jsx(At,{icon:Vt,label:"Question Bank",active:o==="question_bank",collapsed:i&&!d,onClick:()=>l("question_bank"),forceExpanded:h}),e.jsx(At,{icon:ua,label:"Notifications",active:o==="notifications",collapsed:i&&!d,onClick:()=>l("notifications"),forceExpanded:h}),e.jsx(At,{icon:ei,label:"Calendar",active:o==="calendar",collapsed:i&&!d,onClick:()=>l("calendar"),forceExpanded:h})]})]})]}),e.jsxs("div",{className:"space-y-2 border-t border-[#dde3eb] pt-4",children:[e.jsxs(Re.button,{whileHover:{x:2},whileTap:{scale:.98},className:`w-full flex items-center gap-3 px-4 py-3 rounded-2xl text-[#5a6578] font-bold border border-transparent hover:bg-[#dde3eb] hover:border-[#dde3eb] hover:text-[#0a1628] transition-all duration-200 whitespace-nowrap ${i&&!d?"justify-center":""}`,onClick:a,title:i&&!d?"Settings":"",children:[e.jsx(di,{size:18,strokeWidth:2,className:"flex-shrink-0"}),(!i||d)&&e.jsx("span",{className:"font-body text-xs",children:"Settings"})]}),e.jsx("div",{className:"text-[#5a6578]",children:e.jsx(mi,{onClick:()=>y(!0),collapsed:i&&!d})})]})]}),e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[e.jsx("header",{className:"bg-card/80 backdrop-blur-md border-b border-border px-6 py-3 sticky top-0 z-30",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex items-start gap-3 min-w-0",children:[h&&e.jsx("button",{onClick:()=>m(!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(ti,{size:18})}),e.jsxs("div",{children:[e.jsxs("h1",{className:"text-xl font-display font-bold text-foreground leading-tight",children:[o==="dashboard"&&"Teacher Dashboard",o==="analytics"&&(f?f.name:"Class Analytics"),o==="intervention"&&"Student Intervention",o==="topic_mastery"&&"Topic Mastery",o==="competency"&&"Student Competency",o==="import"&&"Data Import",o==="notifications"&&"Notifications",o==="calendar"&&"Calendar",o==="quiz_maker"&&"AI Quiz Maker",o==="question_bank"&&"Question Bank",o==="at_risk"&&"At-Risk Monitoring"]}),e.jsxs("p",{className:"text-xs text-muted-foreground font-body",children:[o==="dashboard"&&`Welcome back, ${Pe}`,o==="analytics"&&"Deep dive into class performance",o==="intervention"&&S?.name,o==="topic_mastery"&&"Monitor class-wide topic mastery",o==="competency"&&"Per-student topic-level breakdown",o==="import"&&"Upload class records and materials",o==="quiz_maker"&&"Create and manage AI-powered quizzes",o==="question_bank"&&"Manage RAG-powered quiz question bank",o==="notifications"&&"View classroom alerts and updates",o==="calendar"&&"Check upcoming class events and schedule",o==="at_risk"&&"Track student risk using the Weighted Risk Index (WRI)"]})]}),o==="dashboard"&&e.jsxs("div",{className:"hidden xl:flex items-center gap-2 ml-2",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(Ps,{size:13,className:"text-[#9956DE]"}),e.jsxs("span",{className:"text-xs font-display font-bold text-[#9956DE]",children:[C," 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(Gt,{size:13,className:"text-[#F08386]"}),e.jsxs("span",{className:"text-xs font-display font-bold text-[#C65E63]",children:[K," 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(ka,{size:13,className:"text-[#75D06A]"}),e.jsxs("span",{className:"text-xs font-display font-bold text-[#4D9F46]",children:[P,"% avg"]})]})]})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs("button",{onClick:s,className:"flex items-center gap-2.5 bg-muted p-1.5 pr-3 rounded-lg cursor-pointer hover:bg-accent transition-all group max-w-[220px]",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg overflow-hidden ring-1 ring-[#9956DE]/45 bg-card flex items-center justify-center",children:e.jsx(si,{src:n?.photo,name:Pe,gender:n?.gender,className:"w-full h-full rounded-lg"})}),e.jsxs("div",{className:"hidden md:block min-w-0 text-left",children:[e.jsx("p",{className:"text-sm font-semibold text-foreground leading-none group-hover:text-[#9956DE] transition-colors truncate",children:Pe}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5 leading-none",children:"Teacher"})]})]})})]})}),e.jsx("main",{className:"flex-1 overflow-y-auto",children:e.jsxs(Qt,{mode:"wait",children:[o==="dashboard"&&e.jsx(Vu,{classes:j,liveActivity:T,onViewClass:X,onViewAllClasses:()=>l("analytics"),onViewActivityStudent:E=>{const W=g.find(je=>je.name===E);W&&le(W)},dailyInsight:$,insightLoading:ee,totalStudents:C,totalAtRisk:K,avgPerformance:P}),o==="analytics"&&O&&e.jsx(Yu,{selectedClass:O,students:q,riskDistribution:xe,topicPerformance:G,onViewStudent:le,onBack:V,teacherOptions:te,managerUpdating:me,onAssignManager:E=>we(O,E)}),o==="analytics"&&!O&&e.jsx(Wu,{icon:Hs,title:"Class Analytics",description:"No classes available yet. Import class records to unlock analytics views."}),o==="intervention"&&S&&e.jsx(Ku,{student:S,teacherId:r?.uid||"",teacherName:Pe,initialCache:F.current.get(S.id),onCacheUpdate:(E,W)=>F.current.set(E,W),onStudentUpdated:E=>{const W=S?Ns(S):null;R(E),b(je=>je.map(pe=>{const De=Ns(pe),fe=W?De===W:!1,Me=pe.id===E.id&&rt(pe.classSectionId)===rt(E.classSectionId);return fe||Me?E:pe}))},onBack:ie}),o==="topic_mastery"&&e.jsx(pm,{classSectionId:ke}),o==="competency"&&e.jsx(Nm,{classSectionId:ke,className:f?.name,fallbackStudents:g}),o==="at_risk"&&e.jsx("div",{className:"flex-1 overflow-auto min-h-0",children:e.jsx($u,{})}),o==="import"&&e.jsx(Xu,{onEditRecords:()=>l("edit_records"),classSectionId:ke,className:f?.name,classMetadata:f?.classMetadata,onImportedClassRecords:E=>{const W=E.students.map(Y=>Qu(Y,E.classSectionId,E.className,E.classMetadata)),je=lt({metadata:E.classMetadata,classSectionId:E.classSectionId,className:E.className}),pe=je.classSectionId||"imported_class",De=je.className||"Imported Class",fe=W.filter(Y=>Y.riskLevel==="high").length,Me=W.length>0?Math.round(W.reduce((Y,ge)=>Y+ge.avgScore,0)/W.length):0,I={id:pe,name:De,classSectionId:pe,classMetadata:{...je,classSectionId:pe,className:De},schedule:"Mon-Fri",studentCount:W.length,avgScore:Me,atRiskCount:fe,riskLevel:fe>=5?"high":fe>=2?"medium":"low"};b(Y=>co(Y,W)),B(Y=>lo(Y,[I]))},onDataChanged:()=>D(E=>E+1)}),o==="notifications"&&e.jsx(ym,{liveActivity:T,atRiskStudents:g.filter(E=>E.riskLevel==="high").map(E=>({name:E.name,riskLevel:E.riskLevel,weakestTopic:E.weakestTopic}))}),o==="calendar"&&e.jsx(Lm,{classes:j,teacherId:r?.uid}),o==="edit_records"&&e.jsx(Ju,{students:g,teacherId:r?.uid||"",teacherName:Pe,onBack:()=>l("import")}),o==="quiz_maker"&&e.jsx(mm,{onBack:()=>l("dashboard")}),o==="question_bank"&&e.jsx(um,{})]})})]}),e.jsx(li,{isOpen:k,onClose:()=>y(!1),onConfirm:t,title:"Logout",message:"Are you sure you want to logout?",confirmText:"Logout",cancelText:"Cancel"})]})},At=({icon:t,label:s,active:a,collapsed:r,forceExpanded:n=!1,onClick:o})=>e.jsxs(Re.button,{onClick:o,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&&!n?"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||n)&&e.jsx("span",{className:"font-body font-bold text-xs",children:s}),a&&!r&&e.jsx(Re.div,{layoutId:"sidebar-active-indicator",className:"ml-auto w-2 h-2 rounded-full bg-[#9956DE]",transition:{type:"spring",duration:.4}})]}),Wu=({icon:t,title:s,description:a})=>e.jsx(Re.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-bold text-foreground mb-2",children:s}),e.jsx("p",{className:"text-sm text-muted-foreground font-body leading-relaxed",children:a})]})}),Vu=({classes:t,liveActivity:s,onViewClass:a,onViewAllClasses:r,onViewActivityStudent:n,dailyInsight:o,insightLoading:l,totalStudents:i,totalAtRisk:c,avgPerformance:d})=>{const u=i>0?Math.round(c/i*100):0,N=i>0?Math.round((i-c)/i*100):0;return e.jsxs(Re.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},exit:{opacity:0,y:-20},className:"p-6 space-y-6",children:[e.jsx("div",{className:"bg-gradient-to-r from-[#7274ED] to-[#9956DE] rounded-2xl p-5 text-white shadow-md",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-10 h-10 bg-card/20 rounded-lg flex items-center justify-center flex-shrink-0",children:e.jsx(Gt,{size:20})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h2",{className:"text-base font-display font-bold mb-1",children:"AI Insight"}),e.jsx(pa,{name:"teacher-dashboard-ai-insight",loading:l,fixture:e.jsxs("div",{className:"space-y-2 pt-1",children:[e.jsx(he,{className:"h-3.5 w-11/12 bg-white/25"}),e.jsx(he,{className:"h-3.5 w-10/12 bg-white/20"}),e.jsx(he,{className:"h-3.5 w-8/12 bg-white/15"})]}),fallback:e.jsxs("div",{className:"space-y-2 pt-1",children:[e.jsx(he,{className:"h-3.5 w-11/12 bg-white/25"}),e.jsx(he,{className:"h-3.5 w-10/12 bg-white/20"}),e.jsx(he,{className:"h-3.5 w-8/12 bg-white/15"})]}),children:e.jsx("div",{children:e.jsx("div",{"aria-live":"polite","aria-atomic":"true",className:"text-[#F1E4FF] text-sm leading-relaxed [&_p]:m-0 [&_strong]:font-semibold",children:e.jsx(wo,{children:o||`${c} students (${u}%) are at high risk of falling behind`})})})})]})]})}),e.jsxs("div",{className:"grid grid-cols-2 xl:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"bg-card rounded-xl p-4 border border-border shadow-sm",children:[e.jsx("p",{className:"text-xs text-muted-foreground font-body mb-1",children:"Total Students"}),e.jsx("p",{className:"text-2xl font-display font-bold text-foreground",children:i})]}),e.jsxs("div",{className:"bg-card rounded-xl p-4 border border-border shadow-sm",children:[e.jsx("p",{className:"text-xs text-muted-foreground font-body mb-1",children:"Class Average"}),e.jsxs("p",{className:"text-2xl font-display font-bold text-[#9956DE]",children:[d,"%"]})]}),e.jsxs("div",{className:"bg-card rounded-xl p-4 border border-border shadow-sm",children:[e.jsx("p",{className:"text-xs text-muted-foreground font-body mb-1",children:"Engagement Rate"}),e.jsxs("p",{className:"text-2xl font-display font-bold text-[#75D06A]",children:[N,"%"]})]}),e.jsxs("div",{className:"bg-card rounded-xl p-4 border border-[#FF8B8B]/35 shadow-sm",children:[e.jsx("p",{className:"text-xs text-muted-foreground font-body mb-1",children:"At Risk"}),e.jsx("p",{className:"text-2xl font-display font-bold text-[#FF8B8B]",children:c})]})]}),e.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-3 gap-6",children:[e.jsxs("div",{className:"xl:col-span-2 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h2",{className:"text-xl font-display font-bold text-foreground",children:"My Classes"}),e.jsxs("button",{onClick:r,className:"text-sm font-bold text-[#9956DE] hover:text-[#9956DE] flex items-center gap-1 group",children:["View All",e.jsx(Wt,{size:16,className:"group-hover:translate-x-1 transition-transform"})]})]}),e.jsx("div",{className:"space-y-4",children:t.map(m=>e.jsxs(Re.div,{whileHover:{scale:1.01},className:"bg-card border border-border rounded-2xl p-6 shadow-sm hover:shadow-md transition-all cursor-pointer",onClick:()=>a(m),children:[e.jsxs("div",{className:"flex items-start justify-between mb-4",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("h3",{className:"text-lg font-display font-bold text-foreground",children:m.name}),e.jsx("span",{className:`px-3 py-1 rounded-lg text-xs font-bold border ${Ra(m.riskLevel)}`,children:m.riskLevel==="high"?"High Risk":m.riskLevel==="medium"?"Medium Risk":"Low Risk"})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(So,{size:14}),e.jsx("span",{children:m.schedule})]}),e.jsx("div",{className:"mt-2 flex flex-wrap gap-2",children:[m.gradeLevel,m.classification,m.strand].filter(Boolean).map(h=>e.jsx("span",{className:"px-2 py-0.5 rounded-md bg-[#9956DE]/12 border border-[#9956DE]/30 text-[#9956DE] text-[11px] font-semibold",children:h},`${m.id}-${h}`))}),e.jsxs("p",{className:"mt-2 text-xs text-muted-foreground",children:["Manager: ",m.managerName||m.classMetadata?.managerName||"Not assigned"]})]}),e.jsx($e,{className:"bg-[#9956DE] hover:bg-[#7A44B3] text-white font-bold px-6 py-2 rounded-xl",children:"View Class"})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Total Students"}),e.jsx("p",{className:"text-xl font-bold text-foreground",children:m.studentCount})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"At Risk"}),e.jsx("p",{className:"text-xl font-bold text-[#FF8B8B]",children:m.atRiskCount})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Avg Score"}),e.jsxs("p",{className:"text-xl font-bold text-[#9956DE]",children:[m.avgScore,"%"]})]})]})]},m.id))})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-10 h-10 bg-[#F08386]/20 rounded-xl flex items-center justify-center",children:e.jsx($s,{size:20,className:"text-[#F08386]"})}),e.jsx("h2",{className:"text-xl font-display font-bold text-foreground",children:"Live Classroom Pulse"})]}),e.jsxs("div",{className:"bg-card rounded-2xl p-5 shadow-sm border border-border space-y-3 max-h-[600px] overflow-y-auto",children:[s.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"No live classroom events yet. Activity appears here in real time."}),s.map(m=>e.jsxs("div",{onClick:()=>n?.(m.student),className:`p-4 rounded-xl border-l-4 cursor-pointer hover:shadow-md transition-shadow ${m.type==="success"?"bg-[#75D06A]/14 border-[#75D06A]":m.type==="warning"?"bg-[#F08386]/12 border-[#F08386]":"bg-[#9956DE]/12 border-[#9956DE]"}`,children:[e.jsxs("div",{className:"flex items-start justify-between mb-2",children:[e.jsx("p",{className:"font-bold text-foreground text-sm",children:m.student}),e.jsx("span",{className:"text-xs text-slate-500",children:m.time})]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[m.action," ",e.jsx("span",{className:"font-bold text-foreground",children:m.topic})]})]},m.id))]})]})]})]})},qu=oe.memo(({student:t,onViewStudent:s})=>e.jsxs(Re.div,{whileHover:{scale:1.02},onClick:()=>s(t),className:`p-4 rounded-2xl border-2 cursor-pointer hover:shadow-md transition-all ${Zu(t.riskLevel)}`,children:[e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsx("img",{src:t.avatar,alt:t.name,className:"w-12 h-12 rounded-xl object-cover border-2 border-current"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h4",{className:"font-bold text-foreground",children:t.name}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t.lastActive})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"text-xs font-bold text-muted-foreground",children:"Avg Score"}),e.jsxs("span",{className:"text-xs font-bold text-foreground",children:[t.avgScore,"%"]})]}),e.jsx("div",{className:"h-2 bg-card rounded-full overflow-hidden e-w",style:{"--w":`${t.avgScore}%`},children:e.jsx("div",{className:`h-full rounded-full ${t.riskLevel==="high"?"bg-[#FF8B8B]":t.riskLevel==="medium"?"bg-[#F08386]":"bg-[#75D06A]"}`})})]})]})),Yu=({selectedClass:t,students:s,riskDistribution:a,topicPerformance:r,onViewStudent:n,onBack:o,teacherOptions:l,managerUpdating:i,onAssignManager:c})=>{const[d,u]=p.useState(""),[N,m]=p.useState(""),[h,w]=p.useState([]);p.useEffect(()=>{m(t.classMetadata?.managerId||t.managerId||"")},[t]),p.useEffect(()=>{let b;return(async()=>{const{collection:T,query:z,where:$,onSnapshot:Z}=await ba(async()=>{const{collection:ee,query:re,where:ne,onSnapshot:D}=await import("./vendor-firebase-firestore-CH1lNiRF.js");return{collection:ee,query:re,where:ne,onSnapshot:D}},__vite__mapDeps([0,1])),{db:ae}=await ba(async()=>{const{db:ee}=await import("./index-BaOs5Ayg.js").then(re=>re.b1);return{db:ee}},__vite__mapDeps([2,3,0,1,4,5,6,7,8,9,10,11])),H=z(T(ae,"modules"),$("moduleType","==","teacher_uploaded"));b=Z(H,ee=>{const re=ee.docs.map(ne=>({id:ne.id,...ne.data()}));w(re)})})(),()=>{b?.()}},[]);const k=p.useMemo(()=>{const b=t.classMetadata?.classification||t.classification||"";return!b||h.length===0?[]:h.filter(T=>{const z=T.subject||"";return z.toLowerCase().includes(b.toLowerCase())||b.toLowerCase().includes(z.toLowerCase())}).slice(0,5)},[h,t]),y=p.useMemo(()=>{const b=d.trim().toLowerCase();return b?s.filter(T=>T.name.toLowerCase().includes(b)||(T.lrn||"").toLowerCase().includes(b)||(T.weakestTopic||"").toLowerCase().includes(b)):s},[d,s]),f=p.useMemo(()=>{if(s.length===0)return 0;const b=s.reduce((T,z)=>T+(z.assignmentCompletion||0),0);return Math.round(b/s.length)},[s]),v=p.useMemo(()=>{if(s.length===0)return 0;const b=s.reduce((z,$)=>z+($.attendance||0),0)/s.length,T=s.reduce((z,$)=>z+($.engagementScore||0),0)/s.length;return Math.round(b*.6+T*.4)},[s]),S=p.useMemo(()=>[...s].sort((b,T)=>T.avgScore-b.avgScore).slice(0,5),[s]),R=p.useMemo(()=>[...s].filter(b=>b.riskLevel==="high"||b.avgScore<70||b.assignmentCompletion<65).sort((b,T)=>{if(b.riskLevel!==T.riskLevel){const z={high:3,medium:2,low:1};return z[T.riskLevel]-z[b.riskLevel]}return b.avgScore-T.avgScore}).slice(0,6),[s]),j=p.useMemo(()=>l.find(b=>b.uid===N),[l,N]),B=()=>{if(!j){ce.error("Select a teacher manager first.");return}c(j)},g=[t.classMetadata?.gradeLevel||t.gradeLevel,t.classMetadata?.classification||t.classification,t.classMetadata?.strand||t.strand].filter(Boolean);return e.jsxs(Re.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},exit:{opacity:0,y:-20},className:"p-6",children:[e.jsxs("button",{onClick:o,className:"flex items-center gap-2 text-muted-foreground hover:text-[#9956DE] font-bold mb-6 transition-colors group",children:[e.jsx(Pt,{size:20,className:"group-hover:-translate-x-1 transition-transform"}),"Back to Dashboard"]}),e.jsx("div",{className:"bg-card rounded-2xl border border-border p-5 shadow-sm mb-6",children:e.jsxs("div",{className:"flex flex-col gap-4 lg:flex-row lg:items-start lg:justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h2",{className:"text-2xl font-display font-bold text-foreground",children:t.name}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:`px-3 py-1 rounded-lg text-xs font-bold border ${Ra(t.riskLevel)}`,children:t.riskLevel==="high"?"High Risk Cohort":t.riskLevel==="medium"?"Medium Risk Cohort":"Low Risk Cohort"}),g.map(b=>e.jsx("span",{className:"px-3 py-1 rounded-lg text-xs font-semibold border bg-[#9956DE]/12 border-[#9956DE]/30 text-[#9956DE]",children:b},b))]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Manager: ",t.classMetadata?.managerName||t.managerName||"Not assigned"]})]}),e.jsxs("div",{className:"min-w-[260px] bg-muted rounded-xl p-3 border border-border",children:[e.jsx("p",{className:"text-xs font-semibold text-muted-foreground mb-2 uppercase tracking-wide",children:"Section Manager"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("select",{id:"analytics-section-manager-select",name:"analytics-section-manager-select","aria-label":"Select section manager",value:N||"",onChange:b=>m(b.target.value),className:"h-10 flex-1 rounded-lg border border-border bg-card px-3 text-sm focus:outline-none focus:ring-2 focus:ring-[#9956DE]/40 transition-colors",children:[e.jsx("option",{value:"",children:"Select teacher"}),l.map(b=>e.jsxs("option",{value:b.uid,children:[b.name," (",b.email,")"]},b.uid))]}),e.jsx($e,{onClick:B,disabled:!N||i,className:"bg-[#9956DE] hover:bg-[#7A44B3] text-white",children:i?e.jsx(he,{className:"h-4 w-12 bg-white/35"}):"Assign"})]})]})]})}),e.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4 mb-6",children:[e.jsxs("div",{className:"bg-card border border-border rounded-xl p-4 shadow-sm",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Class Average"}),e.jsxs("p",{className:"text-2xl font-display font-bold text-[#9956DE]",children:[t.avgScore,"%"]})]}),e.jsxs("div",{className:"bg-card border border-border rounded-xl p-4 shadow-sm",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Completion Rate"}),e.jsxs("p",{className:"text-2xl font-display font-bold text-[#75D06A]",children:[f,"%"]})]}),e.jsxs("div",{className:"bg-card border border-border rounded-xl p-4 shadow-sm",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Participation"}),e.jsxs("p",{className:"text-2xl font-display font-bold text-[#9956DE]",children:[v,"%"]})]}),e.jsxs("div",{className:"bg-card border border-[#FF8B8B]/35 rounded-xl p-4 shadow-sm",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Needs Attention"}),e.jsx("p",{className:"text-2xl font-display font-bold text-[#FF8B8B]",children:R.length})]})]}),e.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-5 gap-6",children:[e.jsxs("div",{className:"xl:col-span-2 bg-card rounded-2xl p-6 shadow-sm border border-border",children:[e.jsxs("div",{className:"flex items-center justify-between mb-5",children:[e.jsxs("h2",{className:"text-lg font-display font-bold text-foreground",children:["Students (",y.length,")"]}),e.jsxs("div",{className:"relative",children:[e.jsx(Js,{className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-400",size:16}),e.jsx(vt,{id:"analytics-student-search",name:"analytics-student-search","aria-label":"Search students",type:"text",placeholder:"Search...",value:d,onChange:b=>u(b.target.value),className:"w-40 pl-9 pr-4 py-2 rounded-xl border-border text-sm"})]})]}),y.length===0?e.jsx("div",{className:"border border-dashed border-border rounded-xl p-4 text-sm text-muted-foreground",children:"No students match your search."}):e.jsx(Sd,{style:{height:"700px"},data:y,itemContent:(b,T)=>e.jsx(qu,{student:T,onViewStudent:n}),computeItemKey:(b,T)=>Ns(T)})]}),e.jsxs("div",{className:"xl:col-span-3 space-y-6",children:[e.jsxs("div",{className:"bg-card rounded-2xl p-6 shadow-sm border border-border",children:[e.jsx("h2",{className:"text-lg font-display font-bold text-foreground mb-5",children:"Risk Distribution"}),e.jsx(sr,{width:"100%",height:250,children:e.jsxs(on,{data:a,children:[e.jsx(ln,{strokeDasharray:"3 3",stroke:"#e5e7eb"}),e.jsx(cn,{dataKey:"name",tick:{fontSize:12}}),e.jsx(ar,{tick:{fontSize:12}}),e.jsx(rr,{}),e.jsx(dn,{dataKey:"value",radius:[8,8,0,0],children:a.map((b,T)=>e.jsx(Gi,{fill:b.color},`cell-${T}`))})]})})]}),e.jsxs("div",{className:"bg-card rounded-2xl p-6 shadow-sm border border-border",children:[e.jsx("h2",{className:"text-lg font-display font-bold text-foreground mb-5",children:"Topic Performance"}),e.jsx(sr,{width:"100%",height:250,children:e.jsxs(on,{data:r,children:[e.jsx(ln,{strokeDasharray:"3 3",stroke:"var(--border)"}),e.jsx(cn,{dataKey:"topic",tick:{fontSize:12}}),e.jsx(ar,{tick:{fontSize:12},domain:[0,100]}),e.jsx(rr,{}),e.jsx(dn,{dataKey:"score",fill:"#9956DE",radius:[8,8,0,0]})]})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"bg-card border border-border rounded-2xl p-4",children:[e.jsx("h3",{className:"text-sm font-display font-bold text-foreground mb-3",children:"Top Performers"}),e.jsxs("div",{className:"space-y-2",children:[S.slice(0,4).map(b=>e.jsxs("button",{onClick:()=>n(b),className:"w-full flex items-center justify-between rounded-lg border border-border px-3 py-2 hover:bg-[#9956DE]/12 transition-colors",children:[e.jsx("span",{className:"text-sm font-semibold text-foreground",children:b.name}),e.jsxs("span",{className:"text-xs font-bold text-[#75D06A]",children:[b.avgScore,"%"]})]},`top-${Ns(b)}`)),S.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"No students available yet."})]})]}),e.jsxs("div",{className:"bg-card border border-border rounded-2xl p-4",children:[e.jsx("h3",{className:"text-sm font-display font-bold text-foreground mb-3",children:"Students Needing Attention"}),e.jsxs("div",{className:"space-y-2",children:[R.slice(0,4).map(b=>e.jsxs("button",{onClick:()=>n(b),className:"w-full flex items-center justify-between rounded-lg border border-[#FF8B8B]/35 bg-[#FF8B8B]/14 px-3 py-2 hover:bg-[#FF8B8B]/20 transition-colors",children:[e.jsx("span",{className:"text-sm font-semibold text-foreground",children:b.name}),e.jsx("span",{className:"text-xs font-bold text-[#FF8B8B]",children:b.riskLevel.toUpperCase()})]},`attention-${Ns(b)}`)),R.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"No urgent students in this class right now."})]}),k.length>0&&e.jsxs("div",{className:"mt-4 pt-4 border-t border-border",children:[e.jsxs("h4",{className:"text-xs font-semibold text-muted-foreground mb-2 flex items-center gap-1.5",children:[e.jsx(Vt,{size:12}),"Recommended Modules"]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:k.map(b=>e.jsx("span",{className:"inline-flex items-center px-2 py-1 rounded-md bg-[#9956DE]/10 border border-[#9956DE]/20 text-xs font-medium text-[#9956DE]",children:b.title||"Untitled Module"},b.moduleId||b.id))})]})]})]})]})]})]})},Ku=({student:t,teacherId:s,teacherName:a,onStudentUpdated:r,onBack:n,initialCache:o,onCacheUpdate:l})=>{const i=(t.riskLevel||"low").toLowerCase(),c=i==="high"||i==="medium",d=c?{card:"bg-[#FF8B8B]/14 border-[#FF8B8B]/35",icon:"bg-red-600",bullet:"text-[#FF8B8B]"}:{card:"bg-[#9956DE]/12 border-[#9956DE]/30",icon:"bg-[#9956DE]",bullet:"text-[#9956DE]"},u=p.useMemo(()=>Ve.getImportGroundedRolloutFlags(),[]),[N,m]=p.useState(o?.learningPath||""),[h,w]=p.useState(!0),[k,y]=p.useState(o?.gradeDraft||t.grade||"Grade 11"),[f,v]=p.useState(o?.sectionDraft||t.section||"Section A"),[S,R]=p.useState(!1),[j,B]=p.useState(o?.lessonPlan??null),[g,b]=p.useState([]),[T,z]=p.useState(""),[$,Z]=p.useState(!1),[ae,H]=p.useState(""),[ee,re]=p.useState("all"),[ne,D]=p.useState("all"),[te,J]=p.useState(!1),[me,Ce]=p.useState(!1),[F,C]=p.useState(null),[K,P]=p.useState(!1),[xe,M]=p.useState(!1),[G,X]=p.useState(0),[le,ie]=p.useState(null),[V,we]=p.useState(!1),[Pe,ke]=p.useState(!1);p.useEffect(()=>{y(t.grade||"Grade 11"),v(t.section||"Section A")},[t.grade,t.section]),p.useEffect(()=>{l?.(t.id,{lessonPlan:j,learningPath:N,gradeDraft:k,sectionDraft:f})},[j,N,k,f,t.id,l]),p.useEffect(()=>{(async()=>{w(!0);try{let Y="";try{Y=await ai(t.struggles.length>0?t.struggles:[t.weakestTopic],"general_math"),z(Y)}catch{z("")}const ge=await Ve.getLearningPath({weaknesses:t.struggles.length>0?t.struggles:[t.weakestTopic],gradeLevel:"High School",subject:"general_math"}),He=Y?`${ge.learningPath} - -${Y}`:ge.learningPath;m(He)}catch{m("Unable to generate learning path. Please try again later."),z("")}finally{w(!1)}})()},[t]);const O=p.useCallback(async()=>{Z(!0),H("");try{const I=t.classSectionId||It(k||"Grade 11",f||"Section A"),Y=t.struggles.length>0?t.struggles[0]:t.weakestTopic,ge=await tm({gradeLevel:k||t.grade||"Grade 11",subject:"general_math",quarter:1,moduleUnit:[k,f].filter(Boolean).join(" - ")||t.className,lessonTitle:`Grounded Lesson: ${Y}`,learningCompetency:Y,learnerLevel:t.avgScore<60?"support":t.avgScore<80?"developing":"advanced",classSectionId:I,className:[k,f].filter(Boolean).join(" - ")||t.className,focusTopics:t.struggles.length>0?t.struggles:[t.weakestTopic],topicCount:5,preferImportedTopics:u.lessonEnabled,allowReviewSources:te,allowUnverifiedLesson:me},!0);B(ge),b(ge.curriculumSources||[]),C(null),Ve.reportImportGroundedFeedback({flow:"lesson",status:"success",classSectionId:I,className:[k,f].filter(Boolean).join(" - ")||t.className,metadata:{usedImportedTopics:ge.usedImportedTopics,importedTopicCount:ge.importedTopicCount,blockCount:ge.blocks.length,publishReady:ge.publishReady,sourceLegitimacyStatus:ge.sourceLegitimacy.status,selfValidationPassed:ge.selfValidation.passed,importGroundingEnabled:u.lessonEnabled}})}catch(I){let Y=I instanceof Error?I.message:"Unable to generate lesson plan at this time.";if(I instanceof Os&&I.status===422)try{const He=JSON.parse(I.responseBody)?.detail;He?.message&&(Y=He.message);const Je=He?.sourceLegitimacy?.issues||[],Xe=He?.selfValidation?.issues||[],U=[...Je,...Xe].filter(Boolean).slice(0,3);U.length>0&&(Y=`${Y} ${U.join(" ")}`)}catch{}H(Y),B(null),b([]),Ve.reportImportGroundedFeedback({flow:"lesson",status:"failed",classSectionId:t.classSectionId||It(k||"Grade 11",f||"Section A"),className:[k,f].filter(Boolean).join(" - ")||t.className,metadata:{error:Y,allowReviewSources:te,allowUnverifiedLesson:me,importGroundingEnabled:u.lessonEnabled}})}finally{Z(!1)}},[t,k,f,u.lessonEnabled,te,me]),q=p.useCallback(async()=>{if(!j)return ce.error("Generate a lesson plan first."),null;P(!0);try{const I=await Zd(j,s,{teacherName:a,studentId:t.id,studentName:t.name});return C(I),ce.success("Lesson plan saved as draft."),I}catch(I){return console.error("Failed to save lesson draft:",I),ce.error(I instanceof Error?I.message:"Failed to save lesson draft."),null}finally{P(!1)}},[j,s,a,t.id,t.name]),E=p.useCallback(async()=>{if(!j){ce.error("Generate a lesson plan first.");return}if(!j.publishReady){const I=[...j.sourceLegitimacy.issues,...j.selfValidation.issues].filter(Boolean).slice(0,2).join(" ");ce.error(I||"Lesson is not publish-ready. Resolve legitimacy and validation checks first.");return}M(!0);try{let I=F;if(I||(I=await q()),!I)return;await em(I),ce.success("Lesson plan published to class content."),Ve.reportImportGroundedFeedback({flow:"lesson",status:"success",classSectionId:j.classSectionId||t.classSectionId,className:j.className||t.className,metadata:{action:"publish_lesson_plan",lessonPlanId:I,publishReady:j.publishReady,sourceLegitimacyStatus:j.sourceLegitimacy.status,selfValidationPassed:j.selfValidation.passed}})}catch(I){console.error("Failed to publish lesson plan:",I),ce.error(I instanceof Error?I.message:"Failed to publish lesson plan."),Ve.reportImportGroundedFeedback({flow:"lesson",status:"failed",classSectionId:j.classSectionId||t.classSectionId,className:j.className||t.className,metadata:{action:"publish_lesson_plan",error:I instanceof Error?I.message:"Failed to publish lesson plan."}})}finally{M(!1)}},[j,F,q,t.className,t.classSectionId]);p.useEffect(()=>{O()},[G]),p.useEffect(()=>{X(I=>I+1)},[t.id]),p.useEffect(()=>{re("all"),D("all")},[j]);const W=p.useMemo(()=>j?Array.from(new Set(j.blocks.map(I=>I.provenance?.sourceFile?.trim()).filter(I=>!!I))).sort((I,Y)=>I.localeCompare(Y)):[],[j]),je=p.useMemo(()=>j?Array.from(new Set(j.blocks.map(I=>I.provenance?.materialId?.trim()).filter(I=>!!I))).sort((I,Y)=>I.localeCompare(Y)):[],[j]),pe=p.useMemo(()=>j?j.blocks.filter(I=>{const Y=ee==="all"||(I.provenance?.sourceFile||"").trim()===ee,ge=ne==="all"||(I.provenance?.materialId||"").trim()===ne;return Y&&ge}):[],[j,ee,ne]),De=[{id:1,type:"video",title:`${t.weakestTopic} Fundamentals`,duration:"8 mins",icon:uc},{id:2,type:"quiz",title:`${t.weakestTopic} Practice`,questions:10,icon:To},{id:3,type:"assessment",title:"Final Check",questions:5,icon:ja}],fe=async()=>{if(!s){ce.error("Unable to update section: teacher context missing");return}R(!0);try{await xl(t.id,k,f,s,new Date().getFullYear().toString(),a),await dl(t.id,k,f);const I={...t,grade:k,section:f,className:[k,f].filter(Boolean).join(" - "),classSectionId:It(k,f)};r(I),ce.success("Student section assignment updated")}catch(I){console.error("Failed to update student section assignment:",I),ce.error("Failed to update section assignment")}finally{R(!1)}},Me=async()=>{we(!0);try{const I=t.struggles?.length>0?t.struggles:[t.weakestTopic||"General academic support"],Y=await Ve.generateInterventionPlan({lrn:t.id,subject:"Mathematics",quarter:"Quarter 1",riskFactors:I});ie(Y),ke(!0),ce.success("Intervention plan generated")}catch(I){ce.error(I instanceof Error?I.message:"Failed to generate intervention plan")}finally{we(!1)}};return e.jsxs(Re.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},exit:{opacity:0,y:-20},className:"p-6",children:[e.jsxs("button",{onClick:n,className:"flex items-center gap-2 text-muted-foreground hover:text-[#9956DE] font-bold mb-6 transition-colors group",children:[e.jsx(Pt,{size:20,className:"group-hover:-translate-x-1 transition-transform"}),"Back to Analytics"]}),e.jsxs("div",{className:"max-w-4xl mx-auto space-y-6",children:[e.jsx("div",{className:"bg-card rounded-2xl p-8 shadow-sm border border-border",children:e.jsxs("div",{className:"flex items-start gap-6",children:[e.jsx("img",{src:t.avatar,alt:t.name,className:"w-24 h-24 rounded-2xl object-cover"}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("h1",{className:"text-3xl font-display font-bold text-foreground",children:t.name}),e.jsx("span",{className:`px-4 py-1.5 rounded-xl text-sm font-bold border-2 ${Ra(t.riskLevel)}`,children:t.riskLevel==="high"?"High Risk":t.riskLevel==="medium"?"Medium Risk":"Low Risk"})]}),e.jsx("p",{className:"text-muted-foreground mb-4",children:t.className}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsxs("div",{className:"bg-muted rounded-xl p-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Avg Score"}),e.jsxs("p",{className:"text-2xl font-bold text-foreground",children:[t.avgScore,"%"]})]}),e.jsxs("div",{className:"bg-muted rounded-xl p-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Last Active"}),e.jsx("p",{className:"text-sm font-bold text-foreground",children:t.lastActive})]}),e.jsxs("div",{className:"bg-muted rounded-xl p-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Weakest Topic"}),e.jsx("p",{className:"text-sm font-bold text-[#FF8B8B]",children:t.weakestTopic})]})]}),e.jsxs("div",{className:"mt-5 p-4 bg-[#9956DE]/12 border border-[#9956DE]/30 rounded-xl",children:[e.jsx("p",{className:"text-xs font-semibold text-[#9956DE] mb-3 uppercase tracking-wider",children:"Section Assignment"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-3",children:[e.jsx(vt,{value:k,onChange:I=>y(I.target.value),placeholder:"Grade",className:"h-10"}),e.jsx(vt,{value:f,onChange:I=>v(I.target.value),placeholder:"Section",className:"h-10"}),e.jsx($e,{onClick:fe,disabled:S||!k.trim()||!f.trim(),className:"bg-[#9956DE] hover:bg-[#7A44B3] text-white h-10",children:S?e.jsx(he,{className:"h-4 w-20 bg-white/35"}):"Save Section"})]})]})]})]})}),e.jsx("div",{className:`${d.card} border-2 rounded-2xl p-6`,children:e.jsxs("div",{className:"flex items-start gap-4 mb-4",children:[e.jsx("div",{className:`w-12 h-12 ${d.icon} rounded-xl flex items-center justify-center flex-shrink-0`,children:e.jsx(Ca,{size:24,className:"text-white"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-display font-bold text-foreground mb-2",children:c?"AI Analysis - Learning Barriers":"AI Analysis - Learning Strengths & Next Steps"}),T&&e.jsx(Bn,{sources:g,className:"mt-1"}),e.jsx(pa,{name:"teacher-intervention-analysis",loading:h,fixture:e.jsxs("div",{className:"space-y-2 pt-1",children:[e.jsx(he,{className:"h-3.5 w-64"}),e.jsx(he,{className:"h-3.5 w-56"}),e.jsx(he,{className:"h-3.5 w-44"})]}),fallback:e.jsxs("div",{className:"space-y-2 pt-1",children:[e.jsx(he,{className:"h-3.5 w-64"}),e.jsx(he,{className:"h-3.5 w-56"}),e.jsx(he,{className:"h-3.5 w-44"})]}),children:e.jsx("ul",{className:"space-y-2 text-foreground",children:t.struggles.length>0?t.struggles.map((I,Y)=>e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx("span",{className:`${d.bullet} inline-flex h-5 items-center`,children:"•"}),e.jsxs("span",{children:[c?"Struggles with ":"Continue strengthening ",e.jsx("strong",{children:I})]})]},Y)):e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx("span",{className:`${d.bullet} inline-flex h-5 items-center`,children:"•"}),e.jsxs("span",{children:[c?"Needs support in ":"Maintain momentum in ",e.jsx("strong",{children:t.weakestTopic})]})]})})})]})]})}),e.jsxs("div",{className:"bg-card rounded-2xl p-8 shadow-sm border border-border",children:[e.jsx("h2",{className:"text-xl font-display font-bold text-foreground mb-6",children:"AI-Generated Learning Path"}),e.jsxs(pa,{name:"teacher-intervention-learning-path",loading:h,fixture:e.jsxs("div",{className:"space-y-4",children:[e.jsx(he,{className:"h-24 w-full rounded-xl"}),e.jsx(he,{className:"h-20 w-full rounded-2xl"}),e.jsx(he,{className:"h-20 w-full rounded-2xl"}),e.jsx(he,{className:"h-20 w-full rounded-2xl"})]}),fallback:e.jsxs("div",{className:"space-y-4",children:[e.jsx(he,{className:"h-24 w-full rounded-xl"}),e.jsx(he,{className:"h-20 w-full rounded-2xl"}),e.jsx(he,{className:"h-20 w-full rounded-2xl"}),e.jsx(he,{className:"h-20 w-full rounded-2xl"})]}),children:[N?e.jsx("div",{className:"bg-[#9956DE]/12 border border-[#9956DE]/30 rounded-xl p-5 mb-6 text-sm text-foreground",children:e.jsx(wo,{children:N})}):null,e.jsxs("div",{className:"space-y-4 relative",children:[e.jsx("div",{className:"absolute left-6 top-8 bottom-8 w-0.5 bg-border"}),De.map((I,Y)=>{const ge=I.icon;return e.jsxs(Re.div,{initial:{opacity:0,x:-20},animate:{opacity:1,x:0},transition:{delay:Y*.1},className:"relative pl-16",children:[e.jsx("div",{className:"absolute left-0 w-12 h-12 bg-gradient-to-br from-[#7274ED] to-[#9956DE] rounded-xl flex items-center justify-center shadow-md",children:e.jsx(ge,{size:24,className:"text-white"})}),e.jsx("div",{className:"bg-gradient-to-br from-[#9956DE]/12 to-[#6ED1CF]/18 border border-[#9956DE]/30 rounded-2xl p-5 hover:shadow-md transition-all",children:e.jsxs("div",{className:"flex items-start justify-between mb-2",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-display font-bold text-foreground mb-1",children:I.title}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[I.type==="video"&&`${I.duration} video lesson`,I.type==="quiz"&&`${I.questions} practice questions`,I.type==="assessment"&&`${I.questions} assessment questions`]})]}),e.jsx("span",{className:`px-3 py-1 rounded-lg text-xs font-bold ${I.type==="video"?"bg-[#F08386]/20 text-[#C65E63]":I.type==="quiz"?"bg-[#9956DE]/20 text-[#9956DE]":"bg-[#75D06A]/22 text-[#4D9F46]"}`,children:I.type==="video"?"Video":I.type==="quiz"?"Quiz":"Assessment"})]})})]},I.id)})]})]})]}),e.jsxs("div",{className:"bg-card rounded-2xl p-8 shadow-sm border border-border",children:[e.jsxs("div",{className:"flex items-center justify-between mb-5",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-display font-bold text-foreground",children:"Targeted Lesson Plan"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Class records drive risk signals. Import-grounded lesson generation needs uploaded course materials for topic context."})]}),e.jsx($e,{onClick:()=>X(I=>I+1),disabled:$,className:"bg-[#9956DE] hover:bg-[#7A44B3] text-white",children:$?e.jsx(he,{className:"h-4 w-20 bg-white/35"}):"Regenerate"})]}),e.jsx("p",{className:"mb-4 text-xs text-muted-foreground bg-[#9956DE]/12 border border-[#9956DE]/30 rounded-lg px-3 py-2",children:"Class records alone are not enough for import-grounded lesson plans. Upload course materials in Data Import to provide lesson topic grounding."}),e.jsxs("div",{className:"mb-4 grid grid-cols-1 md:grid-cols-2 gap-2",children:[e.jsxs("label",{className:"flex items-center gap-2 text-xs text-muted-foreground bg-[#f8fafc] border border-border rounded-lg px-3 py-2",children:[e.jsx("input",{type:"checkbox",checked:te,onChange:I=>J(I.target.checked)}),"Allow sources requiring manual review"]}),e.jsxs("label",{className:"flex items-center gap-2 text-xs text-muted-foreground bg-[#f8fafc] border border-border rounded-lg px-3 py-2",children:[e.jsx("input",{type:"checkbox",checked:me,onChange:I=>Ce(I.target.checked)}),"Allow unverified lesson draft (publish remains blocked)"]})]}),e.jsxs(pa,{name:"teacher-intervention-lesson-plan",loading:$,fixture:e.jsxs("div",{className:"space-y-4",children:[e.jsx(he,{className:"h-20 w-full rounded-xl"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[e.jsx(he,{className:"h-24 w-full rounded-xl"}),e.jsx(he,{className:"h-24 w-full rounded-xl"})]}),e.jsx(he,{className:"h-28 w-full rounded-xl"}),e.jsx(he,{className:"h-28 w-full rounded-xl"})]}),fallback:e.jsxs("div",{className:"space-y-4",children:[e.jsx(he,{className:"h-20 w-full rounded-xl"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[e.jsx(he,{className:"h-24 w-full rounded-xl"}),e.jsx(he,{className:"h-24 w-full rounded-xl"})]}),e.jsx(he,{className:"h-28 w-full rounded-xl"}),e.jsx(he,{className:"h-28 w-full rounded-xl"})]}),children:[ae&&e.jsx("div",{className:"bg-[#FF8B8B]/14 border border-[#FF8B8B]/35 rounded-xl p-3 text-sm text-[#D66A6A]",children:ae}),j&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"bg-secondary border border-border rounded-xl p-4",children:[e.jsx("div",{className:"mb-2",children:e.jsx(Bn,{sources:g})}),e.jsx("p",{className:"text-sm font-semibold text-foreground",children:j.lessonTitle}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["Imported topics used: ",j.usedImportedTopics?"Yes":"No"," • ","Imported topic count: ",j.importedTopicCount]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["Subject: ",j.subject||"general_math"," "," • ","Quarter: Q",j.quarter||1]}),j.curriculumCompetency&&e.jsxs("p",{className:"text-xs text-[#9956DE] font-semibold mt-1",children:["Competency: ",j.curriculumCompetency]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["Publish readiness: ",j.publishReady?"Ready":"Blocked"]}),j.warnings.length>0&&e.jsx("p",{className:"text-xs text-[#CC8A37] mt-1",children:j.warnings.join(" ")})]}),e.jsxs("div",{className:"bg-card border border-border rounded-xl p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wider",children:"Curriculum Grounding"}),e.jsx("p",{className:"text-sm font-bold text-foreground mt-1",children:"Source-backed lesson basis"})]}),j.curriculumGrounding&&e.jsxs("span",{className:`px-3 py-1 rounded-full text-[11px] font-semibold border ${j.curriculumGrounding.confidenceBand==="high"?"bg-[#75D06A]/15 text-[#2E7D32] border-[#75D06A]/40":j.curriculumGrounding.confidenceBand==="medium"?"bg-amber-100 text-amber-800 border-amber-200":"bg-[#FF8B8B]/14 text-[#C65E63] border-[#FF8B8B]/35"}`,children:[j.curriculumGrounding.confidenceBand.toUpperCase()," confidence"]})]}),j.lessonObjective&&e.jsxs("div",{className:"bg-muted/60 rounded-xl p-3",children:[e.jsx("p",{className:"text-[11px] font-semibold text-muted-foreground uppercase tracking-wider",children:"Lesson objective"}),e.jsx("p",{className:"text-sm text-foreground mt-1",children:j.lessonObjective})]}),j.realWorldHook&&e.jsxs("div",{className:"bg-[#9956DE]/10 border border-[#9956DE]/20 rounded-xl p-3",children:[e.jsx("p",{className:"text-[11px] font-semibold text-[#9956DE] uppercase tracking-wider",children:"Real-life application"}),e.jsx("p",{className:"text-sm text-foreground mt-1",children:j.realWorldHook})]}),j.curriculumGrounding&&e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3 text-xs",children:[e.jsxs("div",{className:"bg-muted/50 rounded-xl p-3",children:[e.jsx("p",{className:"text-muted-foreground font-semibold",children:"Retrieval confidence"}),e.jsxs("p",{className:"text-sm font-bold text-foreground mt-1",children:[Math.round((j.curriculumGrounding.confidence||0)*100),"%"]})]}),e.jsxs("div",{className:"bg-muted/50 rounded-xl p-3",children:[e.jsx("p",{className:"text-muted-foreground font-semibold",children:"Retrieved chunks"}),e.jsx("p",{className:"text-sm font-bold text-foreground mt-1",children:j.curriculumGrounding.retrievedChunks})]}),e.jsxs("div",{className:"bg-muted/50 rounded-xl p-3",children:[e.jsx("p",{className:"text-muted-foreground font-semibold",children:"Review state"}),e.jsx("p",{className:"text-sm font-bold text-foreground mt-1",children:j.needsReview?"Needs review":"Ready for review"})]})]}),j.explanation&&e.jsxs("div",{className:"bg-card border border-border rounded-xl p-3",children:[e.jsx("p",{className:"text-[11px] font-semibold text-muted-foreground uppercase tracking-wider mb-1",children:"Explanation"}),e.jsx("p",{className:"text-sm text-foreground leading-relaxed",children:j.explanation})]}),e.jsxs("details",{className:"group rounded-xl border border-border bg-card p-3",children:[e.jsxs("summary",{className:"cursor-pointer list-none text-xs font-semibold text-muted-foreground uppercase tracking-wider flex items-center justify-between gap-2",children:["Retrieved source snippets",e.jsx("span",{className:"text-[11px] text-[#9956DE] group-open:rotate-180 transition-transform",children:"▾"})]}),e.jsx("div",{className:"mt-3 space-y-2",children:(j.retrievedEvidence?.length||0)>0?j.retrievedEvidence?.map((I,Y)=>e.jsxs("div",{className:"rounded-xl bg-muted/60 border border-border p-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-[11px] text-muted-foreground",children:[e.jsx("span",{className:"font-semibold text-foreground",children:I.sourceFile||"Curriculum source"}),e.jsxs("span",{children:["p.",I.page||"?"]}),e.jsx("span",{children:I.contentDomain||"n/a"}),e.jsxs("span",{children:["score ",(I.score*100).toFixed(1),"%"]})]}),e.jsx("p",{className:"text-sm text-foreground mt-2 leading-relaxed",children:I.content})]},`${I.sourceFile||"source"}-${I.page||Y}`)):e.jsx("p",{className:"text-xs text-muted-foreground",children:"No retrieved snippets were returned."})})]}),j.sourceCitations&&j.sourceCitations.length>0&&e.jsxs("div",{className:"rounded-xl bg-muted/50 border border-border p-3",children:[e.jsx("p",{className:"text-[11px] font-semibold text-muted-foreground uppercase tracking-wider mb-2",children:"Source citations"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:j.sourceCitations.slice(0,6).map(I=>e.jsx("span",{className:"px-2 py-1 rounded-full bg-card border border-border text-[11px] text-foreground",children:I},I))})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[e.jsxs("div",{className:"bg-card border border-border rounded-xl p-3",children:[e.jsx("p",{className:"text-xs font-semibold text-muted-foreground",children:"Source Legitimacy"}),e.jsxs("p",{className:"text-sm font-bold text-foreground mt-1",children:[j.sourceLegitimacy.status," (",Math.round(j.sourceLegitimacy.score*100),"%)"]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["Verified: ",j.sourceLegitimacy.verifiedMaterials," "," • ","Review: ",j.sourceLegitimacy.reviewMaterials," "," • ","Rejected: ",j.sourceLegitimacy.rejectedMaterials]}),j.sourceLegitimacy.issues.length>0&&e.jsx("p",{className:"text-xs text-[#CC8A37] mt-1",children:j.sourceLegitimacy.issues.slice(0,2).join(" ")})]}),e.jsxs("div",{className:"bg-card border border-border rounded-xl p-3",children:[e.jsx("p",{className:"text-xs font-semibold text-muted-foreground",children:"Self Validation"}),e.jsxs("p",{className:"text-sm font-bold text-foreground mt-1",children:[j.selfValidation.passed?"Passed":"Failed"," (",Math.round(j.selfValidation.score*100),"%)"]}),j.selfValidation.issues.length>0&&e.jsx("p",{className:"text-xs text-[#CC8A37] mt-1",children:j.selfValidation.issues.slice(0,2).join(" ")})]})]}),(W.length>0||je.length>0)&&e.jsxs("div",{className:"bg-card border border-border rounded-xl p-3",children:[e.jsx("p",{className:"text-xs font-semibold text-muted-foreground mb-2",children:"Provenance Filters"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-2",children:[e.jsxs("label",{className:"text-xs text-muted-foreground flex flex-col gap-1",children:[e.jsx("span",{className:"font-semibold",children:"Source File"}),e.jsxs("select",{value:ee,onChange:I=>re(I.target.value),className:"bg-card border border-border rounded-md px-2 py-1.5 text-xs",children:[e.jsx("option",{value:"all",children:"All sources"}),W.map(I=>e.jsx("option",{value:I,children:I},I))]})]}),e.jsxs("label",{className:"text-xs text-muted-foreground flex flex-col gap-1",children:[e.jsx("span",{className:"font-semibold",children:"Material ID"}),e.jsxs("select",{value:ne,onChange:I=>D(I.target.value),className:"bg-card border border-border rounded-md px-2 py-1.5 text-xs",children:[e.jsx("option",{value:"all",children:"All materials"}),je.map(I=>e.jsx("option",{value:I,children:I},I))]})]})]}),e.jsxs("p",{className:"text-[11px] text-muted-foreground mt-2",children:["Showing ",pe.length," of ",j.blocks.length," lesson blocks after provenance filters."]})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:pe.map(I=>e.jsxs("div",{className:"border border-border rounded-xl p-4 bg-[#fcfdff]",children:[e.jsx("h3",{className:"text-sm font-bold text-foreground",children:I.title}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:[I.estimatedMinutes," mins "," • "," ",I.strategy]}),e.jsx("p",{className:"text-sm text-foreground mt-2",children:I.objective}),e.jsxs("div",{className:"mt-3",children:[e.jsx("p",{className:"text-xs font-semibold text-muted-foreground mb-1",children:"Activities"}),I.activities.slice(0,2).map((Y,ge)=>e.jsxs("p",{className:"text-xs text-muted-foreground",children:["•"," ",Y]},ge))]}),I.provenance&&e.jsxs("div",{className:"mt-3 bg-[#9956DE]/12 border border-[#9956DE]/30 rounded-lg p-2",children:[e.jsx("p",{className:"text-[11px] font-semibold text-[#9956DE]",children:"Provenance"}),I.provenance.sourceFile&&e.jsxs("p",{className:"text-[11px] text-[#5E3388]",children:["Source: ",I.provenance.sourceFile]}),I.provenance.materialId&&e.jsxs("p",{className:"text-[11px] text-[#5E3388]",children:["Material: ",I.provenance.materialId]})]})]},I.blockId))}),pe.length===0&&e.jsx("div",{className:"border border-border rounded-xl p-4 bg-card text-sm text-muted-foreground",children:"No lesson blocks match the selected provenance filters. Clear one or both filters to view all blocks."}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx($e,{variant:"outline",onClick:()=>void q(),disabled:K||!j,className:"border-[#9956DE]/45 text-[#9956DE]",children:K?e.jsx(he,{className:"h-4 w-16"}):"Save Draft"}),e.jsx($e,{onClick:()=>void E(),disabled:xe||!j||!j.publishReady,className:"bg-[#75D06A] hover:bg-[#5AB84E] text-white",children:xe?e.jsx(he,{className:"h-4 w-24 bg-white/35"}):"Publish Lesson Plan"}),F&&e.jsxs("p",{className:"text-xs text-muted-foreground self-center",children:["Draft ID: ",F]})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3",children:[e.jsx($e,{onClick:Me,disabled:V,className:"bg-[#9956DE] hover:bg-[#7A44B3] text-white font-bold py-4 rounded-xl flex items-center justify-center gap-2",children:V?e.jsxs(e.Fragment,{children:[e.jsx(he,{className:"h-4 w-4 rounded-full bg-white/30 animate-pulse"}),"Generating..."]}):e.jsxs(e.Fragment,{children:[e.jsx($s,{size:20}),"Generate Intervention Plan"]})}),e.jsxs($e,{className:"bg-[#9956DE] hover:bg-[#7A44B3] text-white font-bold py-4 rounded-xl flex items-center justify-center gap-2",children:[e.jsx(zs,{size:20}),"Schedule One-on-One Session"]}),e.jsxs($e,{variant:"outline",className:"border-2 border-[#9956DE] text-[#9956DE] hover:bg-[#9956DE]/12 font-bold py-4 rounded-xl flex items-center justify-center gap-2",children:[e.jsx(gr,{size:20}),"Export Printed Materials"]})]}),e.jsx(xo,{open:Pe,onOpenChange:ke,children:e.jsxs(ho,{className:"max-w-lg",children:[e.jsxs(po,{children:[e.jsxs(fo,{className:"flex items-center gap-2 text-[#9956DE]",children:[e.jsx($s,{size:20}),"Intervention Plan"]}),e.jsxs(go,{children:["AI-generated 3-step intervention plan for"," ",e.jsx("span",{className:"font-semibold text-foreground",children:t.name})]})]}),le?e.jsxs("div",{className:"space-y-4 py-2",children:[e.jsxs("div",{className:"bg-[#9956DE]/8 border border-[#9956DE]/25 rounded-xl p-4",children:[e.jsx("p",{className:"text-sm font-bold text-foreground mb-1",children:"Overall Plan"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:le.plan})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wider",children:"Recommended Strategies"}),e.jsx("div",{className:"space-y-2",children:le.strategies.map((I,Y)=>e.jsxs("div",{className:"flex items-start gap-3 bg-muted/50 border border-border rounded-lg p-3",children:[e.jsx("span",{className:"flex-shrink-0 w-6 h-6 rounded-full bg-[#9956DE]/15 text-[#9956DE] flex items-center justify-center text-xs font-bold",children:Y+1}),e.jsx("p",{className:"text-sm text-foreground",children:I})]},Y))})]})]}):e.jsx("div",{className:"py-4 text-center text-sm text-muted-foreground",children:'No plan generated yet. Click "Generate Intervention Plan" to create one.'}),e.jsxs(bo,{className:"gap-2 sm:gap-0",children:[e.jsx($e,{variant:"default",size:"sm",className:"bg-emerald-600 hover:bg-emerald-700 text-white",onClick:async()=>{try{const{setDoc:I,doc:Y,serverTimestamp:ge}=await ba(async()=>{const{setDoc:Je,doc:Xe,serverTimestamp:U}=await import("./vendor-firebase-firestore-CH1lNiRF.js");return{setDoc:Je,doc:Xe,serverTimestamp:U}},__vite__mapDeps([0,1])),{db:He}=await ba(async()=>{const{db:Je}=await import("./index-BaOs5Ayg.js").then(Xe=>Xe.b1);return{db:Je}},__vite__mapDeps([2,3,0,1,4,5,6,7,8,9,10,11]));await I(Y(He,"managedStudents",s,"students",t.id),{interventionApplied:!0,interventionAppliedAt:ge()},{merge:!0}),ce.success("Intervention plan marked as applied"),ke(!1)}catch{ce.error("Failed to mark as applied")}},children:"Mark as Applied"}),e.jsx(oi,{asChild:!0,children:e.jsx($e,{variant:"outline",size:"sm",children:"Close"})})]})]})})]})]})]})},Xu=({onEditRecords:t,classSectionId:s,className:a,classMetadata:r,onImportedClassRecords:n,onDataChanged:o})=>{const[l,i]=p.useState(null),[c,d]=p.useState(!1),[u,N]=p.useState(!1),[m,h]=p.useState(!1),[w,k]=p.useState(!1),[y,f]=p.useState(""),[v,S]=p.useState(r?.classification||""),[R,j]=p.useState(""),[B,g]=p.useState(r?.strand||""),[b,T]=p.useState(r?.gradeLevel?.toString()||"");p.useEffect(()=>{const O=()=>{const q=new Date().getMonth()+1;return q<=3?"Quarter 1":q<=6?"Quarter 2":q<=9?"Quarter 3":"Quarter 4"};j(q=>q||O())},[r]);const[z,$]=p.useState(null),Z=p.useRef(null),ae=p.useRef(null),[H,ee]=p.useState(null),[re,ne]=p.useState(!1),[D,te]=p.useState(!1),J=p.useRef(null),[me,Ce]=p.useState(null),F=O=>O.trim().toLowerCase().replace(/\s+/g," "),C=O=>{if(typeof O=="number"&&Number.isFinite(O))return O;const q=Number(String(O??"").replace(/[^0-9.-]+/g,""));return Number.isFinite(q)?q:null},K=(O,q)=>{const E=Number.isFinite(O)?O:q;return Math.max(0,Math.min(100,E))},P=O=>{const q=String(O??"");return/[",\n]/.test(q)?`"${q.replace(/"/g,'""')}"`:q},xe=(O,q)=>{const E=new Map,W=["quarterlyGrade","finalGrades","firstSemester","firstQuarter","secondQuarter","initialGrade"];O.mapping.gradeEntities.forEach(ge=>{const He=F(ge.fullName||"");if(!He)return;const Je=W.map(U=>C(ge[U])).filter(U=>U!==null);if(Je.length===0)return;const Xe=E.get(He)||[];E.set(He,Xe.concat(Je))});const je=O.mapping.studentEntities||[];if(je.length===0)return null;const pe=(O.imported.schoolContext.semester||O.imported.schoolContext.schoolYear||"First Semester").trim(),De=(O.imported.schoolContext.subjectName||"Class Record Import").trim(),fe=(s||a||"import").replace(/[^a-zA-Z0-9]+/g,"").toUpperCase().slice(0,12)||"IMPORT",I=[["name","lrn","email","engagementScore","avgQuizScore","attendance","assignmentCompletion","term","assessmentName"].join(",")];if(je.forEach((ge,He)=>{const Je=F(ge.fullName||""),Xe=E.get(Je)||[],U=Xe.length>0?Xe.reduce((ks,aa)=>ks+aa,0)/Xe.length:75,ue=K(U,75),Be=K(ue+5,85),Te=K(ue*.7+Be*.3,80),tt=K(Be*.6+ue*.4,82),xt=ge.learnerNo||He+1,Aa=`IMP-${fe}-${String(xt).padStart(4,"0")}`,es=ge.fullName||`Learner ${He+1}`;I.push([P(es),P(Aa),P(""),P(Number(Te.toFixed(1))),P(Number(ue.toFixed(1))),P(Number(Be.toFixed(1))),P(Number(tt.toFixed(1))),P(pe),P(De)].join(","))}),I.length<=1)return null;const Y=q.replace(/\.(xlsx|xls)$/i,"");return new File([I.join(` -`)],`${Y}-normalized.csv`,{type:"text/csv"})},M=async O=>{h(!0),f(""),$(null);let q=O;if(/\.(xlsx|xls)$/i.test(O.name))try{const E=await Eu(O,{confidenceThreshold:xr});i(E);const W=xe(E,O.name);W&&(q=W)}catch{i(null)}else i(null);try{const E=await Ve.uploadClassRecords(q,{classSectionId:s,className:a,datasetIntent:"synthetic_student_records"}),W=E.students.length,je=E.warnings&&E.warnings.length>0?E.warnings.slice(0,3).join(" "):"",pe=E.dashboardSync?` Dashboard sync: ${E.dashboardSync.synced?"ok":"pending"} (created ${E.dashboardSync.createdStudents}, updated ${E.dashboardSync.updatedStudents}).`:"",De=Uu(E,s,a,r);if(W>0&&n?.({students:E.students,classSectionId:De.classSectionId,className:De.className,classMetadata:De.classMetadata}),E.success){ce.success(`Successfully imported ${W} student records. Next step: upload course materials for AI lesson-plan grounding.`);const fe=E.riskRefresh?.queued?` Risk refresh queued for ${E.riskRefresh.studentsQueued} students (job ${E.riskRefresh.refreshId||"n/a"}).`:` Risk refresh not queued${E.riskRefresh?.reason?`: ${E.riskRefresh.reason}`:""}.`,Me=E.interpretationSummary,I=Me?` Interpreted columns - scoring: ${Me.scoringColumns}, display: ${Me.displayColumns}, storage-only: ${Me.storageOnlyColumns}, low-confidence: ${Me.lowConfidenceColumns}.`:"",Y=je?` Warnings: ${je}`:"";f(`Imported ${W} students. Next step: upload course materials to give AI lesson generation topic context.${fe}${pe}${I}${Y} Column mapping: ${JSON.stringify(E.columnMapping)}`),$({datasetIntent:E.datasetIntent,summary:E.interpretationSummary,columns:E.columnInterpretations?.map(ge=>({columnName:ge.columnName,mappedField:ge.mappedField,usagePolicy:ge.usagePolicy,confidenceBand:ge.confidenceBand,domainSignals:ge.domainSignals}))||[]}),o?.()}else{const Me=(E.files||[]).flatMap(I=>I.warnings||[]).slice(0,3).join(" ")||je||"Import completed but no usable student rows were detected. Check required columns and retry.";f(Me),ce.error(Me)}}catch(E){let W=E instanceof Error?E.message:"Upload failed";const je=W.toLowerCase();E instanceof Os&&je.includes("missing required educational columns after mapping")&&je.includes("assignmentcompletion")&&(W="Your file matches the minimal import schema, but the connected backend is running an older validator that still requires assignmentCompletion. Update/redeploy the backend or point VITE_API_URL to this updated backend."),ce.error(W),f(W),$(null)}finally{h(!1)}},G=async O=>{k(!0),f(""),Ce(null);try{const q=await Ve.uploadTeacherMaterial(O,{gradeLevel:b||void 0,subject:v||void 0,strandOrTrack:B||void 0,quarter:R||void 0,classId:s});q.success?(ce.success(q.message||"Teacher module created and available to students."),q.moduleId?Ce({title:q.title||"Untitled Module",moduleId:q.moduleId}):f(q.message||"Course material uploaded successfully."),o?.()):(ce.error(q.error||q.message||"Course material upload failed"),f(q.message||"Course material upload failed."))}catch(q){ce.error(q instanceof Error?q.message:"Course material upload failed"),f("Course material upload failed. Please check the file format and try again.")}finally{k(!1)}},X=O=>{O.preventDefault(),d(!1);const q=O.dataTransfer.files[0];q&&M(q)},le=O=>{const q=O.target.files?.[0];q&&M(q)},ie=O=>{O.preventDefault(),N(!1);const q=O.dataTransfer.files[0];q&&G(q)},V=O=>{const q=O.target.files?.[0];q&&G(q)},we=async()=>{te(!0);try{const O=await Ve.downloadClassRecordTemplate({quarter:R||void 0,subject:v||void 0,school_year:r?.schoolYear||void 0}),q=window.URL.createObjectURL(O),E=document.createElement("a");E.href=q,E.download=`class-record-template-${a||"default"}.xlsx`,document.body.appendChild(E),E.click(),document.body.removeChild(E),window.URL.revokeObjectURL(q),ce.success("Template downloaded")}catch(O){ce.error(O instanceof Error?O.message:"Failed to download template")}finally{te(!1)}},Pe=async O=>{ne(!0),ee(null);try{const q=await Ve.uploadClassRecordTemplate(O,{subject:v||void 0,quarter:R||void 0,gradeLevel:b||void 0});ee(q),q.success?ce.success(q.message||"Upload complete"):ce.error(q.error||"Upload failed")}catch(q){ce.error(q instanceof Error?q.message:"Upload failed")}finally{ne(!1),J.current&&(J.current.value="")}},ke=O=>{const q=O.target.files?.[0];q&&Pe(q)};return e.jsx(Re.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},exit:{opacity:0,y:-20},className:"p-6",children:e.jsxs("div",{className:"max-w-5xl mx-auto space-y-6",children:[e.jsxs("div",{className:"mb-2",children:[e.jsx("h2",{className:"text-xl font-display font-bold text-foreground",children:"Import Data"}),e.jsx("p",{className:"text-muted-foreground",children:"Class records drive analytics and at-risk signals. Course materials provide topic grounding for AI lesson plans."}),e.jsxs("div",{className:"mt-2 flex flex-wrap gap-2 items-center text-xs text-muted-foreground",children:[e.jsxs("span",{className:"px-2 py-1 rounded-md bg-muted border border-border",children:["Class scope: ",a||s||"All classes"]}),[r?.gradeLevel,r?.classification,r?.strand].filter(Boolean).map(O=>e.jsx("span",{className:"px-2 py-1 rounded-md bg-[#9956DE]/12 border border-[#9956DE]/30 text-[#9956DE] font-medium",children:O},`import-meta-${O}`))]})]}),e.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-2 gap-6",children:[e.jsxs("div",{className:`bg-card border-4 border-dashed rounded-3xl p-6 transition-all ${c?"border-[#9956DE] bg-[#9956DE]/12":"border-border"}`,children:[e.jsxs("div",{className:"flex items-center justify-between mb-4 pb-4 border-b border-border",onClick:O=>O.stopPropagation(),children:[e.jsxs("button",{onClick:we,disabled:D,className:"flex items-center gap-2 text-sm font-medium text-[#9956DE] hover:text-[#7A44B3] transition-colors disabled:opacity-50",children:[e.jsx(gr,{size:16}),D?"Downloading...":"Download Template"]}),e.jsxs("div",{children:[e.jsx("input",{ref:J,type:"file",accept:".csv,.xlsx",onChange:ke,className:"hidden"}),e.jsx($e,{onClick:()=>J.current?.click(),disabled:re,size:"sm",className:"bg-[#9956DE] hover:bg-[#7A44B3] text-white font-semibold rounded-xl",children:re?"Uploading...":"Upload Filled Template"})]})]}),e.jsxs("div",{onDragOver:O=>{O.preventDefault(),d(!0)},onDragLeave:()=>d(!1),onDrop:X,onClick:()=>Z.current?.click(),className:"rounded-2xl border-2 border-dashed border-border p-8 text-center transition-all cursor-pointer hover:border-[#9956DE]/60 hover:bg-[#9956DE]/8",children:[e.jsx("input",{ref:Z,type:"file",accept:".csv,.xlsx,.pdf",onChange:le,className:"hidden"}),e.jsx("div",{className:"w-20 h-20 bg-[#9956DE]/20 rounded-2xl flex items-center justify-center mx-auto mb-6",children:m?e.jsx(he,{className:"h-10 w-10 rounded-2xl bg-[#9956DE]/32"}):e.jsx(ac,{size:40,className:"text-[#9956DE]"})}),e.jsx("h3",{className:"text-xl font-display font-bold text-foreground mb-2",children:"Class Records"}),e.jsx("p",{className:"text-muted-foreground mb-4",children:m?e.jsxs("span",{className:"inline-flex flex-col items-center gap-2",children:[e.jsx(he,{className:"h-4 w-44 bg-[#9956DE]/32"}),e.jsx(he,{className:"h-4 w-36 bg-[#9956DE]/20"})]}):"Upload student grades, attendance, and quiz scores"}),e.jsxs("p",{className:"text-xs text-muted-foreground mb-4 flex items-center justify-center gap-2",children:[e.jsx("span",{className:"bg-muted px-2 py-1 rounded text-muted-foreground font-medium",children:".csv"}),e.jsx("span",{className:"bg-muted px-2 py-1 rounded text-muted-foreground font-medium",children:".xlsx"}),e.jsx("span",{className:"bg-muted px-2 py-1 rounded text-muted-foreground font-medium",children:".xls"}),e.jsx("span",{className:"bg-muted px-2 py-1 rounded text-muted-foreground font-medium",children:".pdf"})]}),e.jsx($e,{className:"bg-card border-2 border-border text-muted-foreground hover:border-[#9956DE] hover:text-[#9956DE] font-bold px-6 py-3 rounded-xl w-full transition-colors",children:"Click or drag & drop"})]}),H&&e.jsxs("div",{className:"mt-6 space-y-4",onClick:O=>O.stopPropagation(),children:[H.summary&&e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3",children:[e.jsxs("div",{className:"bg-muted rounded-xl p-3 text-center",children:[e.jsx("p",{className:"text-2xl font-bold text-foreground",children:H.summary.totalStudents}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Total Students"})]}),e.jsxs("div",{className:"bg-red-50 dark:bg-red-950/30 rounded-xl p-3 text-center border border-red-200 dark:border-red-800",children:[e.jsx("p",{className:"text-2xl font-bold text-red-600 dark:text-red-400",children:H.summary.atRiskCount}),e.jsx("p",{className:"text-xs text-red-500",children:"At Risk"})]}),e.jsxs("div",{className:"bg-amber-50 dark:bg-amber-950/30 rounded-xl p-3 text-center border border-amber-200 dark:border-amber-800",children:[e.jsx("p",{className:"text-2xl font-bold text-amber-600 dark:text-amber-400",children:H.summary.mediumRiskCount}),e.jsx("p",{className:"text-xs text-amber-500",children:"Medium Risk"})]}),e.jsxs("div",{className:"bg-emerald-50 dark:bg-emerald-950/30 rounded-xl p-3 text-center border border-emerald-200 dark:border-emerald-800",children:[e.jsx("p",{className:"text-2xl font-bold text-emerald-600 dark:text-emerald-400",children:H.summary.lowRiskCount}),e.jsx("p",{className:"text-xs text-emerald-500",children:"Low Risk"})]})]}),H.students&&H.students.length>0&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-semibold text-foreground mb-2",children:"At-Risk Students"}),e.jsx("div",{className:"max-h-48 overflow-y-auto space-y-1",children:H.students.filter(O=>O.riskLevel==="high").slice(0,20).map((O,q)=>e.jsxs("div",{className:"flex items-center justify-between bg-red-50 dark:bg-red-950/20 rounded-lg px-3 py-2 border border-red-100 dark:border-red-900",children:[e.jsx("span",{className:"text-sm font-medium text-foreground",children:O.name}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-xs text-red-500 font-semibold",children:[O.riskScore.toFixed(1),"%"]}),O.topFactors.length>0&&e.jsx("span",{className:"text-[10px] text-muted-foreground truncate max-w-[120px]",children:O.topFactors.slice(0,2).join(", ")})]})]},q))})]}),H.metadata&&e.jsxs("div",{className:"flex flex-wrap gap-2 text-xs text-muted-foreground border-t border-border pt-3",children:[H.metadata.className&&e.jsxs("span",{className:"bg-muted px-2 py-1 rounded",children:["Class: ",H.metadata.className]}),H.metadata.subject&&e.jsxs("span",{className:"bg-muted px-2 py-1 rounded",children:["Subject: ",H.metadata.subject]}),H.metadata.quarter&&e.jsxs("span",{className:"bg-muted px-2 py-1 rounded",children:["Quarter: ",H.metadata.quarter]}),H.metadata.schoolYear&&e.jsxs("span",{className:"bg-muted px-2 py-1 rounded",children:["SY: ",H.metadata.schoolYear]})]})]})]}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3 p-4 bg-muted/30 rounded-2xl border border-border",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-xs font-semibold text-muted-foreground",children:"Subject"}),e.jsxs("select",{value:v,onChange:O=>S(O.target.value),className:"w-full bg-background border border-border rounded-lg px-3 py-1.5 text-sm focus:outline-none focus:ring-2 focus:ring-[#F08386]",children:[e.jsx("option",{value:"",children:"Select subject"}),e.jsx("option",{value:"Mathematics",children:"Mathematics"}),e.jsx("option",{value:"English",children:"English"}),e.jsx("option",{value:"Science",children:"Science"}),e.jsx("option",{value:"Filipino",children:"Filipino"}),e.jsx("option",{value:"Aralin Panlipunan",children:"Aralin Panlipunan"}),e.jsx("option",{value:"ESP",children:"ESP"}),e.jsx("option",{value:"TLE",children:"TLE"}),e.jsx("option",{value:"Music",children:"Music"}),e.jsx("option",{value:"Arts",children:"Arts"}),e.jsx("option",{value:"Physical Education",children:"Physical Education"}),e.jsx("option",{value:"Health",children:"Health"})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-xs font-semibold text-muted-foreground",children:"Quarter"}),e.jsxs("select",{value:R,onChange:O=>j(O.target.value),className:"w-full bg-background border border-border rounded-lg px-3 py-1.5 text-sm focus:outline-none focus:ring-2 focus:ring-[#F08386]",children:[e.jsx("option",{value:"",children:"Select quarter"}),e.jsx("option",{value:"Quarter 1",children:"Quarter 1"}),e.jsx("option",{value:"Quarter 2",children:"Quarter 2"}),e.jsx("option",{value:"Quarter 3",children:"Quarter 3"}),e.jsx("option",{value:"Quarter 4",children:"Quarter 4"})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-xs font-semibold text-muted-foreground",children:"Grade Level"}),e.jsxs("select",{value:b,onChange:O=>T(O.target.value),className:"w-full bg-background border border-border rounded-lg px-3 py-1.5 text-sm focus:outline-none focus:ring-2 focus:ring-[#F08386]",children:[e.jsx("option",{value:"",children:"Select grade"}),e.jsx("option",{value:"Grade 11",children:"Grade 11"}),e.jsx("option",{value:"Grade 12",children:"Grade 12"})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-xs font-semibold text-muted-foreground",children:"Strand/Track"}),e.jsx("input",{type:"text",value:B,onChange:O=>g(O.target.value),placeholder:"e.g. STEM",className:"w-full bg-background border border-border rounded-lg px-3 py-1.5 text-sm focus:outline-none focus:ring-2 focus:ring-[#F08386]"})]})]}),e.jsxs("div",{onDragOver:O=>{O.preventDefault(),N(!0)},onDragLeave:()=>N(!1),onDrop:ie,onClick:()=>ae.current?.click(),className:`bg-card border-4 border-dashed rounded-3xl p-12 text-center transition-all cursor-pointer hover:border-[#F08386]/60 hover:bg-[#F08386]/12 flex-1 ${u?"border-[#F08386] bg-[#F08386]/12 scale-105":"border-border"}`,children:[e.jsx("input",{ref:ae,type:"file",accept:".pdf,.docx,.txt",onChange:V,className:"hidden"}),e.jsx("div",{className:"w-20 h-20 bg-[#F08386]/20 rounded-2xl flex items-center justify-center mx-auto mb-6",children:w?e.jsx(he,{className:"h-10 w-10 rounded-2xl bg-rose-200"}):e.jsx(fr,{size:40,className:"text-[#F08386]"})}),e.jsx("h3",{className:"text-xl font-display font-bold text-foreground mb-2",children:"Course Materials"}),e.jsx("p",{className:"text-muted-foreground mb-4",children:w?e.jsxs("span",{className:"inline-flex flex-col items-center gap-2",children:[e.jsx(he,{className:"h-4 w-48 bg-rose-200"}),e.jsx(he,{className:"h-4 w-40 bg-[#F08386]/20"})]}):"Upload syllabus, lesson plans, and curriculum documents"}),e.jsxs("p",{className:"text-xs text-slate-500 mb-4 flex items-center justify-center gap-2",children:[e.jsx("span",{className:"bg-muted px-2 py-1 rounded text-muted-foreground font-medium",children:".pdf"}),e.jsx("span",{className:"bg-muted px-2 py-1 rounded text-muted-foreground font-medium",children:".docx"}),e.jsx("span",{className:"bg-muted px-2 py-1 rounded text-muted-foreground font-medium",children:".txt"})]}),e.jsx($e,{className:"bg-card border-2 border-border text-muted-foreground hover:border-[#F08386] hover:text-[#F08386] font-bold px-6 py-3 rounded-xl w-full transition-colors",children:"Click or drag & drop"})]})]})]}),l&&e.jsxs("div",{className:"bg-card border border-border rounded-2xl p-4",children:[e.jsx("h3",{className:"text-base font-display font-bold text-foreground mb-2",children:"Workbook Preview Summary"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-3 text-sm",children:[e.jsxs("div",{className:"bg-muted rounded-lg p-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"School"}),e.jsx("p",{className:"font-semibold text-foreground",children:l.imported.schoolContext.schoolName||"N/A"})]}),e.jsxs("div",{className:"bg-muted rounded-lg p-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Subject"}),e.jsx("p",{className:"font-semibold text-foreground",children:l.imported.schoolContext.subjectName||"N/A"})]}),e.jsxs("div",{className:"bg-muted rounded-lg p-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Learners"}),e.jsx("p",{className:"font-semibold text-foreground",children:l.imported.learners.length})]}),e.jsxs("div",{className:"bg-muted rounded-lg p-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Confidence"}),e.jsx("p",{className:"font-semibold text-foreground",children:l.imported.validation.confidence.toFixed(2)})]})]})]}),e.jsxs("div",{className:"bg-[#9956DE]/12 border border-[#9956DE]/30 rounded-2xl p-6",children:[e.jsx("h3",{className:"text-lg font-display font-bold text-[#7A44B3] mb-3",children:"How AI Uses Your Data"}),e.jsxs("div",{className:"space-y-2 text-[#5E3388]/80 text-sm",children:[e.jsxs("p",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"text-[#9956DE] font-bold",children:"•"}),e.jsxs("span",{children:[e.jsx("strong",{className:"text-[#7A44B3]",children:"Smart Format Detection:"})," AI understands various spreadsheet formats and column names"]})]}),e.jsxs("p",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"text-[#9956DE] font-bold",children:"•"}),e.jsx("span",{children:"Analyzes historical performance patterns to predict at-risk students"})]}),e.jsxs("p",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"text-[#9956DE] font-bold",children:"•"}),e.jsx("span",{children:"Maps curriculum topics to student knowledge gaps"})]}),e.jsxs("p",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"text-[#9956DE] font-bold",children:"•"}),e.jsx("span",{children:"Generates personalized remedial learning paths"})]}),e.jsxs("p",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"text-[#9956DE] font-bold",children:"•"}),e.jsx("span",{children:"All data is processed securely and never shared"})]})]})]}),y&&e.jsx("div",{className:"bg-[#75D06A]/14 border border-[#75D06A]/35 rounded-2xl p-4 text-sm text-[#3E8538]",children:y}),me&&e.jsxs("div",{className:"rounded-2xl border border-emerald-200 dark:border-emerald-800 bg-emerald-50 dark:bg-emerald-950/30 p-5 space-y-3",children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("span",{className:"px-2 py-1 rounded-md bg-emerald-100 text-emerald-700 text-xs font-bold",children:"Module Generated ✓"})}),e.jsx("h4",{className:"text-lg font-bold text-foreground",children:me.title}),e.jsx("span",{className:"inline-flex items-center px-2 py-1 rounded-full bg-emerald-100 text-emerald-700 text-xs font-medium",children:"Available to students now"}),e.jsxs("p",{className:"text-xs text-muted-foreground font-mono",children:["ID: ",me.moduleId]}),e.jsxs("div",{className:"flex items-center gap-2 pt-2",children:[e.jsx($e,{size:"sm",onClick:()=>Ce(null),children:"View in Modules tab"}),e.jsx($e,{size:"sm",variant:"outline",onClick:()=>Ce(null),children:"Dismiss"})]})]}),z&&e.jsxs("div",{className:"bg-card rounded-2xl p-6 shadow-sm border border-border",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("h3",{className:"text-lg font-display font-bold text-foreground",children:"Import Interpretation"}),e.jsxs("span",{className:"text-xs px-2 py-1 rounded bg-muted text-[#334155]",children:["Intent: ",z.datasetIntent||"synthetic_student_records"]})]}),z.summary&&e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-5 gap-3 mb-4",children:[e.jsxs("div",{className:"bg-[#f8fbff] border border-border rounded-xl p-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Scoring"}),e.jsx("p",{className:"text-lg font-bold text-foreground",children:z.summary.scoringColumns})]}),e.jsxs("div",{className:"bg-[#f8fbff] border border-border rounded-xl p-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Display"}),e.jsx("p",{className:"text-lg font-bold text-foreground",children:z.summary.displayColumns})]}),e.jsxs("div",{className:"bg-[#FFB356]/16 border border-[#FFB356]/38 rounded-xl p-3",children:[e.jsx("p",{className:"text-xs text-[#CC8A37]",children:"Storage-only"}),e.jsx("p",{className:"text-lg font-bold text-[#A56D29]",children:z.summary.storageOnlyColumns})]}),e.jsxs("div",{className:"bg-[#F08386]/12 border border-[#F08386]/30 rounded-xl p-3",children:[e.jsx("p",{className:"text-xs text-[#C65E63]",children:"Low confidence"}),e.jsx("p",{className:"text-lg font-bold text-[#A74B50]",children:z.summary.lowConfidenceColumns})]}),e.jsxs("div",{className:"bg-[#f8fbff] border border-border rounded-xl p-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Domain warnings"}),e.jsx("p",{className:"text-lg font-bold text-foreground",children:z.summary.domainMismatchWarnings})]})]}),z.columns.length>0?e.jsx("div",{className:"space-y-2 max-h-64 overflow-auto pr-1",children:z.columns.slice(0,40).map(O=>e.jsxs("div",{className:"bg-[#f8fafc] border border-border rounded-lg px-3 py-2",children:[e.jsx("p",{className:"text-sm font-semibold text-foreground",children:O.columnName}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["mapped: ",O.mappedField||"none"," • ","usage: ",O.usagePolicy," • ","confidence: ",O.confidenceBand]}),O.domainSignals&&O.domainSignals.length>0&&e.jsxs("p",{className:"text-xs text-[#CC8A37] mt-1",children:["domain signals: ",O.domainSignals.join(", ")]})]},O.columnName))}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"No per-column interpretation data was returned for this upload."})]}),e.jsxs("div",{className:"bg-card rounded-2xl p-6 shadow-sm border border-border",children:[e.jsx("h3",{className:"text-lg font-display font-bold text-foreground mb-4",children:"Manage Imported Data"}),e.jsxs("button",{onClick:t,className:"w-full bg-[#00a86b] hover:bg-[#008f5d] text-white rounded-xl p-5 flex items-center justify-between transition-all shadow-sm hover:shadow-md group",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"w-12 h-12 bg-card/20 rounded-xl flex items-center justify-center backdrop-blur-sm",children:e.jsx(Io,{size:24,className:"text-white"})}),e.jsxs("div",{className:"text-left",children:[e.jsx("h4",{className:"font-bold text-lg",children:"Edit Class Records"}),e.jsx("p",{className:"text-white/90 text-sm",children:"Review and correct AI-analyzed student data"})]})]}),e.jsx(Wt,{size:24,className:"text-white/80 group-hover:text-[#9956DE] group-hover:translate-x-1 transition-all"})]})]})]})})},Ju=({students:t,teacherId:s,teacherName:a,onBack:r})=>{const[n,o]=p.useState(t),[l,i]=p.useState(!1),c=p.useCallback(m=>Ns(m),[]),[d,u]=p.useState(()=>Object.fromEntries(t.map(m=>[c(m),{grade:m.grade||"Grade 11",section:m.section||"Section A"}])));p.useEffect(()=>{o(t),u(Object.fromEntries(t.map(m=>[c(m),{grade:m.grade||"Grade 11",section:m.section||"Section A"}])))},[c,t]);const N=async()=>{i(!0);try{for(const m of n){const h=d[c(m)],w=h?.grade||m.grade,k=h?.section||m.section;s&&(w!==m.grade||k!==m.section)&&(await xl(m.id,w,k,s,new Date().getFullYear().toString(),a),await dl(m.id,w,k));try{const y=await Ve.predictRisk({engagementScore:m.engagementScore,avgQuizScore:m.avgScore,attendance:m.attendance,assignmentCompletion:m.assignmentCompletion});await Vd(m.id,y.riskLevel,y.confidence)}catch{}}o(m=>m.map(h=>{const w=d[c(h)];if(!w)return h;const k=lt({metadata:h.classMetadata,classSectionId:h.classSectionId,className:[w.grade,w.section].filter(Boolean).join(" - "),grade:w.grade,section:w.section});return{...h,grade:w.grade,section:w.section,className:k.className||[w.grade,w.section].filter(Boolean).join(" - "),classSectionId:k.classSectionId||h.classSectionId,classMetadata:k}})),ce.success("Records saved and risk levels updated"),r()}catch{ce.error("Failed to save changes")}finally{i(!1)}};return e.jsxs(Re.div,{initial:{opacity:0,x:20},animate:{opacity:1,x:0},exit:{opacity:0,x:-20},className:"p-6 h-full flex flex-col",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 mb-6",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("button",{onClick:r,className:"p-2 hover:bg-muted rounded-lg transition-colors text-muted-foreground",children:e.jsx(Pt,{size:24})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-display font-bold text-foreground",children:"Edit Class Records"}),e.jsx("p",{className:"text-muted-foreground",children:"Review and modify student data manually"})]})]}),e.jsxs("div",{className:"flex gap-3 justify-end",children:[e.jsx($e,{variant:"outline",onClick:r,className:"border-border",children:"Cancel"}),e.jsxs($e,{onClick:N,disabled:l,className:"bg-[#75D06A] hover:bg-[#5AB84E] text-white gap-2",children:[l?e.jsx(he,{className:"h-5 w-5 rounded-full bg-white/35"}):e.jsx(yo,{size:18}),l?"Saving...":"Save Changes"]})]})]}),e.jsxs("div",{className:"bg-card border border-border rounded-2xl shadow-sm flex-1 overflow-hidden flex flex-col",children:[e.jsxs("div",{className:"p-4 border-b border-border bg-background flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(tr,{size:18}),e.jsx("span",{className:"text-sm",children:"Click on any field to edit"})]}),e.jsxs("div",{className:"text-sm text-muted-foreground",children:["Showing ",n.length," records"]})]}),e.jsx("div",{className:"overflow-auto flex-1",children:e.jsxs("table",{className:"w-full text-left border-collapse",children:[e.jsx("thead",{className:"bg-background sticky top-0 z-10",children:e.jsxs("tr",{children:[e.jsx("th",{className:"p-4 font-bold text-muted-foreground border-b border-border bg-background",children:"Student Name"}),e.jsx("th",{className:"p-4 font-bold text-muted-foreground border-b border-border bg-background",children:"LRN"}),e.jsx("th",{className:"p-4 font-bold text-muted-foreground border-b border-border bg-background",children:"Grade"}),e.jsx("th",{className:"p-4 font-bold text-muted-foreground border-b border-border bg-background",children:"Section"}),e.jsx("th",{className:"p-4 font-bold text-muted-foreground border-b border-border bg-background",children:"Avg Score"}),e.jsx("th",{className:"p-4 font-bold text-muted-foreground border-b border-border bg-background",children:"Risk Level"}),e.jsx("th",{className:"p-4 font-bold text-muted-foreground border-b border-border bg-background",children:"Weakest Topic"}),e.jsx("th",{className:"p-4 font-bold text-muted-foreground border-b border-border bg-background",children:"Actions"})]})}),e.jsx("tbody",{children:n.map(m=>{const h=c(m);return e.jsxs("tr",{className:"border-b border-border hover:bg-[#9956DE]/12 group transition-colors",children:[e.jsx("td",{className:"p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("img",{src:m.avatar,alt:"",className:"w-8 h-8 rounded-full object-cover"}),e.jsx("span",{className:"font-medium text-foreground",children:m.name})]})}),e.jsx("td",{className:"p-4 text-muted-foreground font-mono text-sm",children:m.lrn||"Not set"}),e.jsx("td",{className:"p-4 min-w-[140px]",children:e.jsx(vt,{id:`edit-record-grade-${h}`,name:`edit-record-grade-${h}`,"aria-label":`Edit grade for ${m.name}`,value:d[h]?.grade||m.grade,onChange:w=>u(k=>({...k,[h]:{...k[h],grade:w.target.value}})),className:"h-9 text-sm"})}),e.jsx("td",{className:"p-4 min-w-[140px]",children:e.jsx(vt,{id:`edit-record-section-${h}`,name:`edit-record-section-${h}`,"aria-label":`Edit section for ${m.name}`,value:d[h]?.section||m.section,onChange:w=>u(k=>({...k,[h]:{...k[h],section:w.target.value}})),className:"h-9 text-sm"})}),e.jsx("td",{className:"p-4",children:e.jsxs("span",{className:`font-bold ${m.avgScore<60?"text-[#FF8B8B]":m.avgScore<80?"text-[#F08386]":"text-green-600"}`,children:[m.avgScore,"%"]})}),e.jsx("td",{className:"p-4",children:e.jsx("span",{className:`px-2 py-1 rounded text-xs font-bold ${Ra(m.riskLevel)}`,children:m.riskLevel.toUpperCase()})}),e.jsx("td",{className:"p-4 text-muted-foreground",children:m.weakestTopic}),e.jsx("td",{className:"p-4",children:e.jsx("button",{className:"p-2 hover:bg-muted rounded-lg text-slate-500 hover:text-[#9956DE] transition-colors",children:e.jsx(Io,{size:16})})})]},h)})})]})})]})]})};function Ra(t){switch(t){case"high":return"bg-[#FF8B8B]/22 text-[#D66A6A] border-[#FF8B8B]/35";case"medium":return"bg-[#F08386]/20 text-[#C65E63] border-[#F08386]/30";case"low":return"bg-[#75D06A]/22 text-[#4D9F46] border-[#75D06A]/35"}}function Zu(t){switch(t){case"high":return"border-red-500 bg-[#FF8B8B]/14";case"medium":return"border-[#F08386] bg-[#F08386]/12";case"low":return"border-[#75D06A] bg-[#75D06A]/14"}}export{Kx as default}; diff --git a/assets/XPNotification-DRsFdUWw.js b/assets/XPNotification-CsIvt8Wa.js similarity index 73% rename from assets/XPNotification-DRsFdUWw.js rename to assets/XPNotification-CsIvt8Wa.js index 25e33a469ce081f79a3576655cb9367475fa14b0..98307107ca22467a91f67bea7c97f7770bbcbbb3 100644 --- a/assets/XPNotification-DRsFdUWw.js +++ b/assets/XPNotification-CsIvt8Wa.js @@ -1 +1 @@ -import{r as l,j as e}from"./vendor-react-B4AQeu28.js";import{j as n,m as i,X as m}from"./index-BaOs5Ayg.js";import{S as c}from"./sparkles-By-vFjpv.js";import"./vendor-firebase-firestore-CH1lNiRF.js";import"./vendor-firebase-core-CO26nNq6.js";import"./vendor-firebase-auth-BLpRW_zO.js";import"./vendor-firebase-storage-B3igpVVS.js";import"./vendor-firebase-analytics-CTiUNb0-.js";import"./vendor-radix-BorKzPz9.js";import"./vendor-charts-D8hf8tI0.js";import"./vendor-markdown-yqZQ_iQm.js";const b=({xp:r,message:a,show:t,onComplete:s})=>(l.useEffect(()=>{if(t){const o=setTimeout(()=>{s()},3e3);return()=>clearTimeout(o)}},[t,s]),e.jsx(n,{children:t&&e.jsx(i.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-50",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(i.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(c,{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:["+",r," XP"]})]})]})})}));export{b as default}; +import{r as l,j as e}from"./vendor-react-B4AQeu28.js";import{g as n,m as i,$ as m}from"./index-uASBzalf.js";import{S as c}from"./sparkles-DHVr5IP1.js";import"./vendor-firebase-firestore-CP9q7ISf.js";import"./vendor-firebase-core-DCQrgkxC.js";import"./vendor-firebase-auth-Bcpr4O6E.js";import"./vendor-firebase-storage-dc5X5yTv.js";import"./vendor-firebase-analytics-CHPyhRzk.js";import"./vendor-radix-xDOIcVzp.js";import"./vendor-charts-Ckgeb0nY.js";import"./vendor-markdown-yqZQ_iQm.js";const b=({xp:r,message:a,show:t,onComplete:s})=>(l.useEffect(()=>{if(t){const o=setTimeout(()=>{s()},3e3);return()=>clearTimeout(o)}},[t,s]),e.jsx(n,{children:t&&e.jsx(i.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-50",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(i.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(c,{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:["+",r," XP"]})]})]})})}));export{b as default}; diff --git a/assets/automationService-7m3RFJA3.js b/assets/automationService-rXKxA-Jx.js similarity index 84% rename from assets/automationService-7m3RFJA3.js rename to assets/automationService-rXKxA-Jx.js index adbc5d2e91e0396513a0efb7bc27459e66fc00d7..d41ab7c6f943303bae212799255bca1e616c10a5 100644 --- a/assets/automationService-7m3RFJA3.js +++ b/assets/automationService-rXKxA-Jx.js @@ -1 +1 @@ -import{doc as g,collection as a,serverTimestamp as c,setDoc as l,addDoc as D,query as z,where as b,getDocs as A,updateDoc as C,writeBatch as Q}from"./vendor-firebase-firestore-CH1lNiRF.js";import{f as r,a$ as $}from"./index-BaOs5Ayg.js";import"./vendor-firebase-core-CO26nNq6.js";import"./vendor-react-B4AQeu28.js";import"./vendor-firebase-auth-BLpRW_zO.js";import"./vendor-firebase-storage-B3igpVVS.js";import"./vendor-firebase-analytics-CTiUNb0-.js";import"./vendor-radix-BorKzPz9.js";import"./vendor-charts-D8hf8tI0.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 E(e){if(!e)return 0;const n=a(r,"deepDiagnosticAssignments"),o=z(n,b("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 M(e,n,o="Grade 11",u,i="iar_only",t="initial_assessment"){if(t==="followup_diagnostic"){const s=a(r,"deepDiagnosticAssignments"),d=z(s,b("lrn","==",e)),f=await A(d);if(!f.empty){const p=Q(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,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 x(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 N(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 W(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 G(e){const n=g(r,"curriculumContent",e.contentId);return e.action==="delete"?await C(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{E as getPendingDeepDiagnosticCount,G as triggerContentUpdated,W as triggerDataImported,M as triggerDiagnosticCompleted,x as triggerQuizSubmitted,N 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 C,writeBatch as Q}from"./vendor-firebase-firestore-CP9q7ISf.js";import{h as r,b0 as $}from"./index-uASBzalf.js";import"./vendor-firebase-core-DCQrgkxC.js";import"./vendor-react-B4AQeu28.js";import"./vendor-firebase-auth-Bcpr4O6E.js";import"./vendor-firebase-storage-dc5X5yTv.js";import"./vendor-firebase-analytics-CHPyhRzk.js";import"./vendor-radix-xDOIcVzp.js";import"./vendor-charts-Ckgeb0nY.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 E(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 M(e,n,o="Grade 11",u,i="iar_only",t="initial_assessment"){if(t==="followup_diagnostic"){const s=a(r,"deepDiagnosticAssignments"),d=b(s,z("lrn","==",e)),f=await A(d);if(!f.empty){const p=Q(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,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 x(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 N(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 W(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 G(e){const n=g(r,"curriculumContent",e.contentId);return e.action==="delete"?await C(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{E as getPendingDeepDiagnosticCount,G as triggerContentUpdated,W as triggerDataImported,M as triggerDiagnosticCompleted,x as triggerQuizSubmitted,N as triggerStudentEnrolled}; diff --git a/assets/bell-clcSMJn6.js b/assets/bell-CiUaN6S3.js similarity index 91% rename from assets/bell-clcSMJn6.js rename to assets/bell-CiUaN6S3.js index aa16175805f0fd1aeffb99f89877aa8d65959fe4..09b1770cce24fbb28e1c8c3b653fe658e1408456 100644 --- a/assets/bell-clcSMJn6.js +++ b/assets/bell-CiUaN6S3.js @@ -1,4 +1,4 @@ -import{e}from"./index-BaOs5Ayg.js";/** +import{e}from"./index-uASBzalf.js";/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. diff --git a/assets/button-DCfeFHoH.js b/assets/button-BPmLcOpC.js similarity index 94% rename from assets/button-DCfeFHoH.js rename to assets/button-BPmLcOpC.js index a0f6d7cb97c1bb4a47aee15b626b407860dacbff..2394e3f3873863fe9d4622a90e160b876f0ca4e1 100644 --- a/assets/button-DCfeFHoH.js +++ b/assets/button-BPmLcOpC.js @@ -1 +1 @@ -import{j as y}from"./vendor-react-B4AQeu28.js";import{S as k}from"./vendor-radix-BorKzPz9.js";import{c as V}from"./vendor-charts-D8hf8tI0.js";import{i as p}from"./index-BaOs5Ayg.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-xDOIcVzp.js";import{c as V}from"./vendor-charts-Ckgeb0nY.js";import{k as p}from"./index-uASBzalf.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/card-D4dmQVNb.js b/assets/card-D4dmQVNb.js deleted file mode 100644 index ccf7888cc17b865038f5afb7296566ce2dae3f7f..0000000000000000000000000000000000000000 --- a/assets/card-D4dmQVNb.js +++ /dev/null @@ -1,6 +0,0 @@ -import{e as o,i as r}from"./index-BaOs5Ayg.js";import{j as e}from"./vendor-react-B4AQeu28.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 d=[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]],n=o("copy",d);function i({className:a,...t}){return e.jsx("div",{"data-slot":"card",className:r("bg-card text-card-foreground flex flex-col gap-6 rounded-xl border",a),...t})}function l({className:a,...t}){return e.jsx("div",{"data-slot":"card-header",className:r("@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),...t})}function u({className:a,...t}){return e.jsx("h4",{"data-slot":"card-title",className:r("leading-none",a),...t})}function x({className:a,...t}){return e.jsx("p",{"data-slot":"card-description",className:r("text-muted-foreground",a),...t})}function p({className:a,...t}){return e.jsx("div",{"data-slot":"card-content",className:r("px-6 [&:last-child]:pb-6",a),...t})}export{n as C,i as a,l as b,u as c,p as d,x as e}; diff --git a/assets/chart-column-B3jJOD5i.js b/assets/chart-column-CLoxLorp.js similarity index 89% rename from assets/chart-column-B3jJOD5i.js rename to assets/chart-column-CLoxLorp.js index 60580c49ed97b3d5d8f5f0b6d220c65cf7755ed4..ca3478b1057d560d489376d3ad26d08e197cbf5c 100644 --- a/assets/chart-column-B3jJOD5i.js +++ b/assets/chart-column-CLoxLorp.js @@ -1,4 +1,4 @@ -import{e as t}from"./index-BaOs5Ayg.js";/** +import{e as t}from"./index-uASBzalf.js";/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. diff --git a/assets/chatService-DwVkLoat.js b/assets/chatService-DL-kTPZE.js similarity index 78% rename from assets/chatService-DwVkLoat.js rename to assets/chatService-DL-kTPZE.js index 0856b0dc9c16faba69ef6b0933f8c67ed9020d89..59b14f182df22bba775863ce45492cb120b99a29 100644 --- a/assets/chatService-DwVkLoat.js +++ b/assets/chatService-DL-kTPZE.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-CH1lNiRF.js";import{f as a}from"./index-BaOs5Ayg.js";import"./vendor-firebase-core-CO26nNq6.js";import"./vendor-react-B4AQeu28.js";import"./vendor-firebase-auth-BLpRW_zO.js";import"./vendor-firebase-storage-B3igpVVS.js";import"./vendor-firebase-analytics-CTiUNb0-.js";import"./vendor-radix-BorKzPz9.js";import"./vendor-charts-D8hf8tI0.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-CP9q7ISf.js";import{h as a}from"./index-uASBzalf.js";import"./vendor-firebase-core-DCQrgkxC.js";import"./vendor-react-B4AQeu28.js";import"./vendor-firebase-auth-Bcpr4O6E.js";import"./vendor-firebase-storage-dc5X5yTv.js";import"./vendor-firebase-analytics-CHPyhRzk.js";import"./vendor-radix-xDOIcVzp.js";import"./vendor-charts-Ckgeb0nY.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}:{}},h=await g(c(a,"chatSessions",s));h.exists()&&(o.userId=h.data().userId);const m={id:o.id,userId:o.userId,role:o.role,content:o.content,sessionId:s,timestamp:i()};return o.context&&(m.context=o.context),await w(r,m),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-BLSo9L0H.js b/assets/check-Dk6iwDFI.js similarity index 85% rename from assets/check-BLSo9L0H.js rename to assets/check-Dk6iwDFI.js index 5b587772781ec2d95dc51c60fdc334f73387f243..b35961aa8162cbaf7e5cac6b1f6fe15f44511a24 100644 --- a/assets/check-BLSo9L0H.js +++ b/assets/check-Dk6iwDFI.js @@ -1,4 +1,4 @@ -import{e as c}from"./index-BaOs5Ayg.js";/** +import{e as c}from"./index-uASBzalf.js";/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. diff --git a/assets/check-check-B_HghS1Z.js b/assets/check-check-DFG24Nyg.js similarity index 88% rename from assets/check-check-B_HghS1Z.js rename to assets/check-check-DFG24Nyg.js index 81f69360d3866b67d4b2c75998d4b532079f7354..0a9f74038698f38af7e199ba1310f2edb5555c8d 100644 --- a/assets/check-check-B_HghS1Z.js +++ b/assets/check-check-DFG24Nyg.js @@ -1,4 +1,4 @@ -import{e}from"./index-BaOs5Ayg.js";/** +import{e}from"./index-uASBzalf.js";/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. diff --git a/assets/chevron-left-BWpgclqc.js b/assets/chevron-left-CzSo_K0d.js similarity index 86% rename from assets/chevron-left-BWpgclqc.js rename to assets/chevron-left-CzSo_K0d.js index 2d861468eab389e7a24615541fff540c1332dd91..464a0560bef3ce6266036edc84329bcec5460bf0 100644 --- a/assets/chevron-left-BWpgclqc.js +++ b/assets/chevron-left-CzSo_K0d.js @@ -1,4 +1,4 @@ -import{e}from"./index-BaOs5Ayg.js";/** +import{e}from"./index-uASBzalf.js";/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. diff --git a/assets/chevron-right-COqGruhh.js b/assets/chevron-right-U0AqPOPj.js similarity index 85% rename from assets/chevron-right-COqGruhh.js rename to assets/chevron-right-U0AqPOPj.js index 15058093259e5c7863ad43de2833e0eb6d723f61..7d535b6c2a1f86ccb5c54d8ebded6b06bfa7a2dd 100644 --- a/assets/chevron-right-COqGruhh.js +++ b/assets/chevron-right-U0AqPOPj.js @@ -1,4 +1,4 @@ -import{e as o}from"./index-BaOs5Ayg.js";/** +import{e as o}from"./index-uASBzalf.js";/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. diff --git a/assets/chevron-up-Cdvz2TMJ.js b/assets/chevron-up-BpMhRyJp.js similarity index 85% rename from assets/chevron-up-Cdvz2TMJ.js rename to assets/chevron-up-BpMhRyJp.js index a41959e097f5b9b055cc56626f535a98a9a5e9bf..23e0231b08089394456721e637b72e4d824471d4 100644 --- a/assets/chevron-up-Cdvz2TMJ.js +++ b/assets/chevron-up-BpMhRyJp.js @@ -1,4 +1,4 @@ -import{e as o}from"./index-BaOs5Ayg.js";/** +import{e as o}from"./index-uASBzalf.js";/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. @@ -8,4 +8,4 @@ import{e as o}from"./index-BaOs5Ayg.js";/** * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. - */const e=[["path",{d:"m18 15-6-6-6 6",key:"153udz"}]],t=o("chevron-up",e);export{t as C,r as a}; + */const e=[["path",{d:"m18 15-6-6-6 6",key:"153udz"}]],t=o("chevron-up",e);export{r as C,t as a}; diff --git a/assets/circle-alert-CP9K3300.js b/assets/circle-alert-DDOZHhZK.js similarity index 90% rename from assets/circle-alert-CP9K3300.js rename to assets/circle-alert-DDOZHhZK.js index 8722e42ab17d19ee8ec1206b8ad03d515ad51325..5af1d3d83bd438a93ee818acfdcf920678bd8654 100644 --- a/assets/circle-alert-CP9K3300.js +++ b/assets/circle-alert-DDOZHhZK.js @@ -1,4 +1,4 @@ -import{e}from"./index-BaOs5Ayg.js";/** +import{e}from"./index-uASBzalf.js";/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. diff --git a/assets/circle-check-C0FPGTrp.js b/assets/circle-check-C5Psopk3.js similarity index 87% rename from assets/circle-check-C0FPGTrp.js rename to assets/circle-check-C5Psopk3.js index 8e21fab99cf8f900dda8299961c04c3034b07a7c..19a98bcee63d4087626642c44e954d4dc913fa7c 100644 --- a/assets/circle-check-C0FPGTrp.js +++ b/assets/circle-check-C5Psopk3.js @@ -1,4 +1,4 @@ -import{e as c}from"./index-BaOs5Ayg.js";/** +import{e as c}from"./index-uASBzalf.js";/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. diff --git a/assets/circle-check-big-m1SvzGFL.js b/assets/circle-check-big-BNRlH5pv.js similarity index 88% rename from assets/circle-check-big-m1SvzGFL.js rename to assets/circle-check-big-BNRlH5pv.js index 2f09b14937ff3a10466409e376650d985e225fb3..2aeb236540cc783ab5003ec7bd102407b5638e44 100644 --- a/assets/circle-check-big-m1SvzGFL.js +++ b/assets/circle-check-big-BNRlH5pv.js @@ -1,4 +1,4 @@ -import{e as c}from"./index-BaOs5Ayg.js";/** +import{e as c}from"./index-uASBzalf.js";/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. diff --git a/assets/circle-help-B8apTIdU.js b/assets/circle-help-PS1uII8x.js similarity index 89% rename from assets/circle-help-B8apTIdU.js rename to assets/circle-help-PS1uII8x.js index df46be8fd99be8bbbcf405815e074ba7cd2bc964..1c4c98694b8283eb0d65722e8efe3fde9f7df879 100644 --- a/assets/circle-help-B8apTIdU.js +++ b/assets/circle-help-PS1uII8x.js @@ -1,4 +1,4 @@ -import{e as c}from"./index-BaOs5Ayg.js";/** +import{e as c}from"./index-uASBzalf.js";/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. diff --git a/assets/clipboard-check-DqBu2Pqb.js b/assets/clipboard-check-RuPght2T.js similarity index 91% rename from assets/clipboard-check-DqBu2Pqb.js rename to assets/clipboard-check-RuPght2T.js index bbf74079d848eaa2f680c61ab60a7624821ab78a..2c3b9207e0515e9767625d043cb8a46dcd1a301d 100644 --- a/assets/clipboard-check-DqBu2Pqb.js +++ b/assets/clipboard-check-RuPght2T.js @@ -1,4 +1,4 @@ -import{e}from"./index-BaOs5Ayg.js";/** +import{e}from"./index-uASBzalf.js";/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. diff --git a/assets/clock-D1Ecvltm.js b/assets/clock-8t0UYgg3.js similarity index 87% rename from assets/clock-D1Ecvltm.js rename to assets/clock-8t0UYgg3.js index f726a73318861f552cb0991a1bad785a2f20bfe9..afbf72d31a6c4cf6a72fd006c9ec13427055671f 100644 --- a/assets/clock-D1Ecvltm.js +++ b/assets/clock-8t0UYgg3.js @@ -1,4 +1,4 @@ -import{e as c}from"./index-BaOs5Ayg.js";/** +import{e as c}from"./index-uASBzalf.js";/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. diff --git a/assets/diagnosticService-BDYTUoqk.js b/assets/diagnosticService-DacNtsbN.js similarity index 82% rename from assets/diagnosticService-BDYTUoqk.js rename to assets/diagnosticService-DacNtsbN.js index 5fdc892ad5360e81ba871f1710b60caf1a016604..bc686095f921334ba1ac38a48083ba1d3fd75294 100644 --- a/assets/diagnosticService-BDYTUoqk.js +++ b/assets/diagnosticService-DacNtsbN.js @@ -1,2 +1,2 @@ -const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-BaOs5Ayg.js","assets/vendor-react-B4AQeu28.js","assets/vendor-firebase-firestore-CH1lNiRF.js","assets/vendor-firebase-core-CO26nNq6.js","assets/vendor-firebase-auth-BLpRW_zO.js","assets/vendor-firebase-storage-B3igpVVS.js","assets/vendor-firebase-analytics-CTiUNb0-.js","assets/vendor-radix-BorKzPz9.js","assets/vendor-charts-D8hf8tI0.js","assets/vendor-markdown-yqZQ_iQm.js","assets/vendor-markdown-CfVKi3_s.css","assets/index-DdX2rVyy.css"])))=>i.map(i=>d[i]); -import{_ as w}from"./index-BaOs5Ayg.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-BaOs5Ayg.js").then(a=>a.b1);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-BaOs5Ayg.js").then(r=>r.b1);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-uASBzalf.js","assets/vendor-react-B4AQeu28.js","assets/vendor-firebase-firestore-CP9q7ISf.js","assets/vendor-firebase-core-DCQrgkxC.js","assets/vendor-firebase-auth-Bcpr4O6E.js","assets/vendor-firebase-storage-dc5X5yTv.js","assets/vendor-firebase-analytics-CHPyhRzk.js","assets/vendor-radix-xDOIcVzp.js","assets/vendor-charts-Ckgeb0nY.js","assets/vendor-markdown-yqZQ_iQm.js","assets/vendor-markdown-CfVKi3_s.css","assets/index-D9pRNq5G.css"])))=>i.map(i=>d[i]); +import{_ as w}from"./index-uASBzalf.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-uASBzalf.js").then(a=>a.b2);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-uASBzalf.js").then(r=>r.b2);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-CHtYkwVl.js b/assets/dialog-CHtYkwVl.js deleted file mode 100644 index b319db804fe887522c78e5d12f7fe16e9a84c98b..0000000000000000000000000000000000000000 --- a/assets/dialog-CHtYkwVl.js +++ /dev/null @@ -1 +0,0 @@ -import{j as t,r as l}from"./vendor-react-B4AQeu28.js";import{c as m,d as n,e as i,T as r,D as d,P as p,O as c}from"./vendor-radix-BorKzPz9.js";import{i as s}from"./index-BaOs5Ayg.js";import{X as u}from"./x-TNvtuOD9.js";function w({...a}){return t.jsx(m,{"data-slot":"dialog",...a})}function x({...a}){return t.jsx(p,{"data-slot":"dialog-portal",...a})}function z({...a}){return t.jsx(i,{"data-slot":"dialog-close",...a})}const f=l.forwardRef(({className:a,...e},o)=>t.jsx(c,{ref:o,"data-slot":"dialog-overlay",className:s("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",a),...e}));f.displayName=c.displayName;const j=l.forwardRef(({className:a,children:e,...o},g)=>t.jsxs(x,{"data-slot":"dialog-portal",children:[t.jsx(f,{}),t.jsxs(n,{ref:g,"data-slot":"dialog-content",className:s("bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 sm:max-w-lg",a),...o,children:[e,t.jsxs(i,{className:"ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",children:[t.jsx(u,{}),t.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));j.displayName=n.displayName;function R({className:a,...e}){return t.jsx("div",{"data-slot":"dialog-header",className:s("flex flex-col gap-2 text-center sm:text-left",a),...e})}function C({className:a,...e}){return t.jsx("div",{"data-slot":"dialog-footer",className:s("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",a),...e})}const y=l.forwardRef(({className:a,...e},o)=>t.jsx(r,{ref:o,"data-slot":"dialog-title",className:s("text-lg leading-none font-semibold",a),...e}));y.displayName=r.displayName;const N=l.forwardRef(({className:a,...e},o)=>t.jsx(d,{ref:o,"data-slot":"dialog-description",className:s("text-muted-foreground text-sm",a),...e}));N.displayName=d.displayName;export{w as D,j as a,R as b,y as c,N as d,C as e,z as f}; diff --git a/assets/dialog-CNHSYTtM.js b/assets/dialog-CNHSYTtM.js new file mode 100644 index 0000000000000000000000000000000000000000..fb4eef66f5e4062811498cb7198e333190eb2073 --- /dev/null +++ b/assets/dialog-CNHSYTtM.js @@ -0,0 +1 @@ +import{j as t,r as l}from"./vendor-react-B4AQeu28.js";import{b as g,c as n,d as m,T as r,D as d,P as p,O as i}from"./vendor-radix-xDOIcVzp.js";import{k as o}from"./index-uASBzalf.js";import{X as u}from"./x-CBb03rh3.js";function w({...a}){return t.jsx(g,{"data-slot":"dialog",...a})}function x({...a}){return t.jsx(p,{"data-slot":"dialog-portal",...a})}const c=l.forwardRef(({className:a,...e},s)=>t.jsx(i,{ref:s,"data-slot":"dialog-overlay",className:o("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",a),...e}));c.displayName=i.displayName;const y=l.forwardRef(({className:a,children:e,...s},f)=>t.jsxs(x,{"data-slot":"dialog-portal",children:[t.jsx(c,{}),t.jsxs(n,{ref:f,"data-slot":"dialog-content",className:o("bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 sm:max-w-lg",a),...s,children:[e,t.jsxs(m,{className:"ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",children:[t.jsx(u,{}),t.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));y.displayName=n.displayName;function z({className:a,...e}){return t.jsx("div",{"data-slot":"dialog-header",className:o("flex flex-col gap-2 text-center sm:text-left",a),...e})}function R({className:a,...e}){return t.jsx("div",{"data-slot":"dialog-footer",className:o("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",a),...e})}const j=l.forwardRef(({className:a,...e},s)=>t.jsx(r,{ref:s,"data-slot":"dialog-title",className:o("text-lg leading-none font-semibold",a),...e}));j.displayName=r.displayName;const N=l.forwardRef(({className:a,...e},s)=>t.jsx(d,{ref:s,"data-slot":"dialog-description",className:o("text-muted-foreground text-sm",a),...e}));N.displayName=d.displayName;export{w as D,y as a,z as b,j as c,N as d,R as e}; diff --git a/assets/download-DX_YebqQ.js b/assets/download-CVrPjUr0.js similarity index 89% rename from assets/download-DX_YebqQ.js rename to assets/download-CVrPjUr0.js index c314154ab0349668c951d2d4b8d254bc50391ac7..1b1cb029796d5a9c085b75426bdddfb9398343ce 100644 --- a/assets/download-DX_YebqQ.js +++ b/assets/download-CVrPjUr0.js @@ -1,4 +1,4 @@ -import{e as o}from"./index-BaOs5Ayg.js";/** +import{e as o}from"./index-uASBzalf.js";/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. diff --git a/assets/eye-Ig3S6mOs.js b/assets/eye-DIwMshM-.js similarity index 96% rename from assets/eye-Ig3S6mOs.js rename to assets/eye-DIwMshM-.js index ead363867eece6258fb2539ea9dd75be49918f87..5fbf5a7f8ffaac46e50e831632262fa585d738cf 100644 --- a/assets/eye-Ig3S6mOs.js +++ b/assets/eye-DIwMshM-.js @@ -1,4 +1,4 @@ -import{e}from"./index-BaOs5Ayg.js";/** +import{e}from"./index-uASBzalf.js";/** * @license lucide-react v0.487.0 - ISC * * This source code is licensed under the ISC license. diff --git a/assets/formatDistanceToNow-BinvfoNW.js b/assets/formatDistanceToNow-BinvfoNW.js new file mode 100644 index 0000000000000000000000000000000000000000..ce8b61f04afcfbd7a0ba6b1d007da98f42a63088 --- /dev/null +++ b/assets/formatDistanceToNow-BinvfoNW.js @@ -0,0 +1 @@ +import{t as u,a2 as W}from"./index-uASBzalf.js";function S(t,n){return t instanceof Date?new t.constructor(n):new Date(n)}const b=43200,p=1440;let k={};function F(){return k}function P(t){const n=u(t),e=new Date(Date.UTC(n.getFullYear(),n.getMonth(),n.getDate(),n.getHours(),n.getMinutes(),n.getSeconds(),n.getMilliseconds()));return e.setUTCFullYear(n.getFullYear()),+t-+e}function w(t,n){const e=u(t),r=u(n),a=e.getTime()-r.getTime();return a<0?-1:a>0?1:a}function T(t){return S(t,Date.now())}function x(t,n){const e=u(t),r=u(n),a=e.getFullYear()-r.getFullYear(),s=e.getMonth()-r.getMonth();return a*12+s}function C(t){return n=>{const r=(t?Math[t]:Math.trunc)(n);return r===0?0:r}}function X(t,n){return+u(t)-+u(n)}function A(t){const n=u(t),e=n.getMonth();return n.setFullYear(n.getFullYear(),e+1,0),n.setHours(23,59,59,999),n}function O(t){const n=u(t);return+W(n)==+A(n)}function Y(t,n){const e=u(t),r=u(n),a=w(e,r),s=Math.abs(x(e,r));let i;if(s<1)i=0;else{e.getMonth()===1&&e.getDate()>27&&e.setDate(30),e.setMonth(e.getMonth()-a*s);let o=w(e,r)===-a;O(u(t))&&s===1&&w(t,r)===1&&(o=!1),i=a*(s-Number(o))}return i===0?0:i}function N(t,n,e){const r=X(t,n)/1e3;return C(e?.roundingMethod)(r)}const j={lessThanXSeconds:{one:"less than a second",other:"less than {{count}} seconds"},xSeconds:{one:"1 second",other:"{{count}} seconds"},halfAMinute:"half a minute",lessThanXMinutes:{one:"less than a minute",other:"less than {{count}} minutes"},xMinutes:{one:"1 minute",other:"{{count}} minutes"},aboutXHours:{one:"about 1 hour",other:"about {{count}} hours"},xHours:{one:"1 hour",other:"{{count}} hours"},xDays:{one:"1 day",other:"{{count}} days"},aboutXWeeks:{one:"about 1 week",other:"about {{count}} weeks"},xWeeks:{one:"1 week",other:"{{count}} weeks"},aboutXMonths:{one:"about 1 month",other:"about {{count}} months"},xMonths:{one:"1 month",other:"{{count}} months"},aboutXYears:{one:"about 1 year",other:"about {{count}} years"},xYears:{one:"1 year",other:"{{count}} years"},overXYears:{one:"over 1 year",other:"over {{count}} years"},almostXYears:{one:"almost 1 year",other:"almost {{count}} years"}},_=(t,n,e)=>{let r;const a=j[t];return typeof a=="string"?r=a:n===1?r=a.one:r=a.other.replace("{{count}}",n.toString()),e?.addSuffix?e.comparison&&e.comparison>0?"in "+r:r+" ago":r};function D(t){return(n={})=>{const e=n.width?String(n.width):t.defaultWidth;return t.formats[e]||t.formats[t.defaultWidth]}}const I={full:"EEEE, MMMM do, y",long:"MMMM do, y",medium:"MMM d, y",short:"MM/dd/yyyy"},R={full:"h:mm:ss a zzzz",long:"h:mm:ss a z",medium:"h:mm:ss a",short:"h:mm a"},V={full:"{{date}} 'at' {{time}}",long:"{{date}} 'at' {{time}}",medium:"{{date}}, {{time}}",short:"{{date}}, {{time}}"},z={date:D({formats:I,defaultWidth:"full"}),time:D({formats:R,defaultWidth:"full"}),dateTime:D({formats:V,defaultWidth:"full"})},L={lastWeek:"'last' eeee 'at' p",yesterday:"'yesterday at' p",today:"'today at' p",tomorrow:"'tomorrow at' p",nextWeek:"eeee 'at' p",other:"P"},q=(t,n,e,r)=>L[t];function y(t){return(n,e)=>{const r=e?.context?String(e.context):"standalone";let a;if(r==="formatting"&&t.formattingValues){const i=t.defaultFormattingWidth||t.defaultWidth,o=e?.width?String(e.width):i;a=t.formattingValues[o]||t.formattingValues[i]}else{const i=t.defaultWidth,o=e?.width?String(e.width):t.defaultWidth;a=t.values[o]||t.values[i]}const s=t.argumentCallback?t.argumentCallback(n):n;return a[s]}}const J={narrow:["B","A"],abbreviated:["BC","AD"],wide:["Before Christ","Anno Domini"]},E={narrow:["1","2","3","4"],abbreviated:["Q1","Q2","Q3","Q4"],wide:["1st quarter","2nd quarter","3rd quarter","4th quarter"]},H={narrow:["J","F","M","A","M","J","J","A","S","O","N","D"],abbreviated:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],wide:["January","February","March","April","May","June","July","August","September","October","November","December"]},Q={narrow:["S","M","T","W","T","F","S"],short:["Su","Mo","Tu","We","Th","Fr","Sa"],abbreviated:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],wide:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]},U={narrow:{am:"a",pm:"p",midnight:"mi",noon:"n",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"},abbreviated:{am:"AM",pm:"PM",midnight:"midnight",noon:"noon",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"},wide:{am:"a.m.",pm:"p.m.",midnight:"midnight",noon:"noon",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"}},B={narrow:{am:"a",pm:"p",midnight:"mi",noon:"n",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"},abbreviated:{am:"AM",pm:"PM",midnight:"midnight",noon:"noon",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"},wide:{am:"a.m.",pm:"p.m.",midnight:"midnight",noon:"noon",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"}},K=(t,n)=>{const e=Number(t),r=e%100;if(r>20||r<10)switch(r%10){case 1:return e+"st";case 2:return e+"nd";case 3:return e+"rd"}return e+"th"},$={ordinalNumber:K,era:y({values:J,defaultWidth:"wide"}),quarter:y({values:E,defaultWidth:"wide",argumentCallback:t=>t-1}),month:y({values:H,defaultWidth:"wide"}),day:y({values:Q,defaultWidth:"wide"}),dayPeriod:y({values:U,defaultWidth:"wide",formattingValues:B,defaultFormattingWidth:"wide"})};function M(t){return(n,e={})=>{const r=e.width,a=r&&t.matchPatterns[r]||t.matchPatterns[t.defaultMatchWidth],s=n.match(a);if(!s)return null;const i=s[0],o=r&&t.parsePatterns[r]||t.parsePatterns[t.defaultParseWidth],l=Array.isArray(o)?Z(o,g=>g.test(i)):G(o,g=>g.test(i));let d;d=t.valueCallback?t.valueCallback(l):l,d=e.valueCallback?e.valueCallback(d):d;const h=n.slice(i.length);return{value:d,rest:h}}}function G(t,n){for(const e in t)if(Object.prototype.hasOwnProperty.call(t,e)&&n(t[e]))return e}function Z(t,n){for(let e=0;e{const r=n.match(t.matchPattern);if(!r)return null;const a=r[0],s=n.match(t.parsePattern);if(!s)return null;let i=t.valueCallback?t.valueCallback(s[0]):s[0];i=e.valueCallback?e.valueCallback(i):i;const o=n.slice(a.length);return{value:i,rest:o}}}const et=/^(\d+)(th|st|nd|rd)?/i,nt=/\d+/i,at={narrow:/^(b|a)/i,abbreviated:/^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i,wide:/^(before christ|before common era|anno domini|common era)/i},rt={any:[/^b/i,/^(a|c)/i]},ot={narrow:/^[1234]/i,abbreviated:/^q[1234]/i,wide:/^[1234](th|st|nd|rd)? quarter/i},it={any:[/1/i,/2/i,/3/i,/4/i]},st={narrow:/^[jfmasond]/i,abbreviated:/^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i,wide:/^(january|february|march|april|may|june|july|august|september|october|november|december)/i},ut={narrow:[/^j/i,/^f/i,/^m/i,/^a/i,/^m/i,/^j/i,/^j/i,/^a/i,/^s/i,/^o/i,/^n/i,/^d/i],any:[/^ja/i,/^f/i,/^mar/i,/^ap/i,/^may/i,/^jun/i,/^jul/i,/^au/i,/^s/i,/^o/i,/^n/i,/^d/i]},ct={narrow:/^[smtwf]/i,short:/^(su|mo|tu|we|th|fr|sa)/i,abbreviated:/^(sun|mon|tue|wed|thu|fri|sat)/i,wide:/^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i},dt={narrow:[/^s/i,/^m/i,/^t/i,/^w/i,/^t/i,/^f/i,/^s/i],any:[/^su/i,/^m/i,/^tu/i,/^w/i,/^th/i,/^f/i,/^sa/i]},lt={narrow:/^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i,any:/^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i},ht={any:{am:/^a/i,pm:/^p/i,midnight:/^mi/i,noon:/^no/i,morning:/morning/i,afternoon:/afternoon/i,evening:/evening/i,night:/night/i}},mt={ordinalNumber:tt({matchPattern:et,parsePattern:nt,valueCallback:t=>parseInt(t,10)}),era:M({matchPatterns:at,defaultMatchWidth:"wide",parsePatterns:rt,defaultParseWidth:"any"}),quarter:M({matchPatterns:ot,defaultMatchWidth:"wide",parsePatterns:it,defaultParseWidth:"any",valueCallback:t=>t+1}),month:M({matchPatterns:st,defaultMatchWidth:"wide",parsePatterns:ut,defaultParseWidth:"any"}),day:M({matchPatterns:ct,defaultMatchWidth:"wide",parsePatterns:dt,defaultParseWidth:"any"}),dayPeriod:M({matchPatterns:lt,defaultMatchWidth:"any",parsePatterns:ht,defaultParseWidth:"any"})},ft={code:"en-US",formatDistance:_,formatLong:z,formatRelative:q,localize:$,match:mt,options:{weekStartsOn:0,firstWeekContainsDate:1}};function gt(t,n,e){const r=F(),a=e?.locale??r.locale??ft,s=2520,i=w(t,n);if(isNaN(i))throw new RangeError("Invalid time value");const o=Object.assign({},e,{addSuffix:e?.addSuffix,comparison:i});let l,d;i>0?(l=u(n),d=u(t)):(l=u(t),d=u(n));const h=N(d,l),g=(P(d)-P(l))/1e3,c=Math.round((h-g)/60);let f;if(c<2)return e?.includeSeconds?h<5?a.formatDistance("lessThanXSeconds",5,o):h<10?a.formatDistance("lessThanXSeconds",10,o):h<20?a.formatDistance("lessThanXSeconds",20,o):h<40?a.formatDistance("halfAMinute",0,o):h<60?a.formatDistance("lessThanXMinutes",1,o):a.formatDistance("xMinutes",1,o):c===0?a.formatDistance("lessThanXMinutes",1,o):a.formatDistance("xMinutes",c,o);if(c<45)return a.formatDistance("xMinutes",c,o);if(c<90)return a.formatDistance("aboutXHours",1,o);if(c{switch(t){case"achievement_unlocked":case"achievement":return"bg-rose-500/10 text-rose-600";case"xp_earned":return"bg-amber-500/10 text-amber-600";case"daily_checkin":case"checkin":return"bg-emerald-500/10 text-emerald-600";case"streak_milestone":case"streak_reminder":return"bg-orange-500/10 text-orange-600";case"teacher_announcement":return"bg-violet-500/10 text-violet-600";case"new_assignment":case"quiz_result":return"bg-sky-500/10 text-sky-600";case"level_up":return"bg-indigo-500/10 text-indigo-600";case"system_alert":return"bg-red-500/10 text-red-600";default:return"bg-[#edf1f7] text-[#5a6578]"}},T=({notification:t})=>{const{markAsRead:r,deleteNotification:a}=m(),o=R[t.type]||d,i=L(t.type),n=()=>{if(t.isRead||r(t.id),t.type==="streak_reminder"||t.type==="daily_checkin"){window.dispatchEvent(new CustomEvent("mathpulse:navigate",{detail:{tab:"Modules"}}));return}t.actionUrl&&(window.location.href=t.actionUrl)},l=N(t.createdAt,{addSuffix:!0});return e.jsx("div",{role:"button",tabIndex:0,onClick:n,onKeyDown:s=>{(s.key==="Enter"||s.key===" ")&&(s.preventDefault(),n())},className:`group text-left p-4 border-b border-[#dde3eb] cursor-pointer transition-colors hover:bg-[#edf1f7]/50 ${t.isRead?"":"bg-sky-50/40"}`,children:e.jsxs("div",{className:"flex gap-3",children:[e.jsx("div",{className:`w-10 h-10 rounded-xl flex items-center justify-center flex-shrink-0 ${i}`,children:e.jsx(o,{size:18})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2 mb-1",children:[e.jsx("h4",{className:"text-sm font-bold text-[#0a1628] line-clamp-1 font-body",children:t.title}),!t.isRead&&e.jsx("span",{className:"w-2 h-2 rounded-full bg-sky-600 flex-shrink-0 mt-1.5"})]}),e.jsx("p",{className:"text-xs text-[#5a6578] mb-2 line-clamp-2 font-body",children:t.message}),e.jsx("p",{className:"text-xs text-slate-500",children:l})]}),e.jsx("button",{onClick:s=>{s.stopPropagation(),a(t.id)},className:"opacity-0 group-hover:opacity-100 transition-opacity text-slate-400 hover:text-red-500","aria-label":"Delete notification",children:e.jsx(w,{size:14})})]})})},A=({onClose:t})=>{const{notifications:r,unreadCount:a,isLoading:o,markAllAsRead:i}=m(),n=c.useRef(null);c.useEffect(()=>{const s=x=>{n.current&&!n.current.contains(x.target)&&t()};return document.addEventListener("mousedown",s),()=>document.removeEventListener("mousedown",s)},[t]);const l=e.jsxs("div",{ref:n,className:"fixed right-4 top-20 w-80 bg-[#f7f9fc] rounded-xl shadow-2xl border border-[#dde3eb] max-h-96 overflow-y-auto z-[9999] overflow-hidden",style:{right:"1rem",top:"5rem"},children:[e.jsxs("div",{className:"p-4 border-b border-[#dde3eb] flex items-center justify-between bg-gradient-to-r from-sky-600 to-sky-500",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-display font-bold text-white text-sm",children:"Notifications"}),e.jsx("p",{className:"text-xs text-sky-100 mt-0.5",children:a>0?`${a} unread`:"No new alerts"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[a>0&&e.jsxs("button",{onClick:i,className:"text-xs text-sky-200 hover:text-white font-bold transition-colors flex items-center gap-1",children:[e.jsx(_,{size:14}),"Mark all read"]}),e.jsx("button",{onClick:t,className:"text-sky-200 hover:text-white transition-colors",title:"Close",children:e.jsx(C,{size:16})})]})]}),e.jsx("div",{className:"max-h-80 overflow-y-auto",children:o?e.jsx("div",{className:"p-4 space-y-3",children:[1,2,3].map(s=>e.jsx("div",{className:"animate-pulse bg-[#dde3eb] rounded h-12"},s))}):r.length===0?e.jsxs("div",{className:"p-8 text-center",children:[e.jsx(d,{size:48,className:"text-[#d1cec6] mx-auto mb-3"}),e.jsx("p",{className:"text-[#5a6578] text-sm font-body",children:"You're all caught up!"})]}):r.map(s=>e.jsx(T,{notification:s},s.id))})]});return v.createPortal(l,document.body)},J=()=>{const{unreadCount:t}=m(),[r,a]=c.useState(!1),o=c.useRef(null);c.useEffect(()=>{const n=l=>{o.current&&!o.current.contains(l.target)&&a(!1)};return r&&document.addEventListener("mousedown",n),()=>{document.removeEventListener("mousedown",n)}},[r]);const i=t>99?"99+":t.toString();return e.jsxs("div",{ref:o,className:"relative",children:[e.jsxs("button",{onClick:()=>a(!r),className:"relative p-3 bg-[#edf1f7] rounded-xl text-[#5a6578] hover:bg-[#dde3eb] transition-colors","aria-label":"Notifications","aria-expanded":r,"aria-haspopup":"true",children:[e.jsx(d,{size:20}),t>0&&e.jsx("span",{className:"absolute -top-1 -right-1 bg-red-500 text-white text-xs font-bold rounded-full min-w-[18px] h-[18px] flex items-center justify-center px-1",children:i})]}),r&&e.jsx(A,{onClose:()=>a(!1)})]})};export{J as NotificationBell,ee as NotificationProvider,te as notify,m as useNotifications}; diff --git a/assets/index-BaOs5Ayg.js b/assets/index-BaOs5Ayg.js deleted file mode 100644 index 77b9a42737da6bd3d7d51924c3bb93a49e9a61b1..0000000000000000000000000000000000000000 --- a/assets/index-BaOs5Ayg.js +++ /dev/null @@ -1,679 +0,0 @@ -const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/automationService-7m3RFJA3.js","assets/vendor-firebase-firestore-CH1lNiRF.js","assets/vendor-firebase-core-CO26nNq6.js","assets/vendor-react-B4AQeu28.js","assets/vendor-firebase-auth-BLpRW_zO.js","assets/vendor-firebase-storage-B3igpVVS.js","assets/vendor-firebase-analytics-CTiUNb0-.js","assets/vendor-radix-BorKzPz9.js","assets/vendor-charts-D8hf8tI0.js","assets/vendor-markdown-yqZQ_iQm.js","assets/vendor-markdown-CfVKi3_s.css","assets/chatService-DwVkLoat.js","assets/trackingService-DQ12buWG.js","assets/LoginPage-DLaoyzV8.js","assets/button-DCfeFHoH.js","assets/input-D28h_UTJ.js","assets/sparkles-By-vFjpv.js","assets/mail-BbG1phxL.js","assets/eye-Ig3S6mOs.js","assets/shield-check-Dgisjfmb.js","assets/TeacherDashboard-CZdYfdg9.js","assets/dialog-CHtYkwVl.js","assets/x-TNvtuOD9.js","assets/ConfirmModal-6cgkqXAT.js","assets/trash-2-HTnKafZd.js","assets/log-out-BenDMDly.js","assets/LogoutActionButton-lUNItet6.js","assets/tooltip-ChRIOid3.js","assets/quizService-8JHQlvu9.js","assets/chevron-left-BWpgclqc.js","assets/send-CwwDU3uJ.js","assets/circle-alert-CP9K3300.js","assets/check-BLSo9L0H.js","assets/table-xeOJ8ZAA.js","assets/chevron-up-Cdvz2TMJ.js","assets/minus-DfrEv-SC.js","assets/plus-DkG35AoH.js","assets/card-D4dmQVNb.js","assets/download-DX_YebqQ.js","assets/chevron-right-COqGruhh.js","assets/save-CQIJrhLf.js","assets/search-Bq99THgc.js","assets/upload-DayXhGwD.js","assets/useQuery-BnRttv09.js","assets/subjects-BFghB0SQ.js","assets/chart-column-B3jJOD5i.js","assets/useCurriculum-DDCuCvMR.js","assets/circle-check-big-m1SvzGFL.js","assets/ChatMarkdown-fgwaycBR.js","assets/bell-clcSMJn6.js","assets/check-check-B_HghS1Z.js","assets/clock-D1Ecvltm.js","assets/skeleton-Bo6ISWhm.js","assets/vendor-xlsx-uZelXSz_.js","assets/circle-help-B8apTIdU.js","assets/clipboard-check-DqBu2Pqb.js","assets/AdminDashboard-B2eiYi-q.js","assets/Sidebar-2LZAqf7E.js","assets/shirt-S3NBuaPm.js","assets/select-DIjxRWza.js","assets/lightbulb-Ce2KQzGM.js","assets/switch-CblAJO7o.js","assets/funnel-BT77sgnz.js","assets/useSubjectAvailability-Bvu3fXaT.js","assets/HeroBanner-CKiXGluA.js","assets/circle-check-C0FPGTrp.js","assets/RightSidebar-CmYzVUKQ.js","assets/quiz_battle_avatar-BXHPSput.js","assets/XPNotification-DRsFdUWw.js","assets/index-CajSaEd0.js","assets/SupplementalBanner-DFkcXPOZ.js","assets/SupplementalPillCarousel-BqNTelmK.js","assets/LearningPath-BBE0vZ0S.js","assets/ModuleFolderCard-DKBrO5a8.js","assets/CompetencyRadarChart-CBuH8ru8.js","assets/ModulesPage-cZJm_yoJ.js","assets/ScientificCalculator-DRuSfTXj.js","assets/volume-x-Chtf_bSj.js","assets/confetti.module-C94ZD2ww.js","assets/AIChatPage-CI1qQgCG.js","assets/GradesPage-Y0HsmLPP.js","assets/LeaderboardPage-D9eaC9ey.js","assets/useFeatureAccess-BSpfx3vY.js","assets/QuizBattlePage-Bwu0snEF.js","assets/CompositeAvatar-Col05lJc.js","assets/avatarData-BuQSOXo3.js","assets/AvatarShop-BeFk31yM.js","assets/FloatingAITutor-BIdguqCV.js","assets/maximize-2-EHa6JURc.js","assets/RewardsModal-CPyFRkMy.js","assets/ProfileModal-Gwxh5tYO.js","assets/ProfilePictureUploader-CX_IZAwE.js","assets/SettingsModal-BbkSqdYG.js","assets/InitialAssessmentModal-CknVaqMx.js","assets/diagnosticService-BDYTUoqk.js","assets/AssessmentPage-YsCyxvJJ.js","assets/testResetService-gpYLnLG7.js"])))=>i.map(i=>d[i]); -import{r as f,j as b,d as D,c as Eh,f as kh}from"./vendor-react-B4AQeu28.js";import{persistentLocalCache as Ka,initializeFirestore as Qa,setDoc as Ne,doc as H,serverTimestamp as ce,getDoc as ge,getDocFromServer as oi,onSnapshot as rn,query as It,limit as Yn,orderBy as Sn,collection as We,getDocs as Tn,updateDoc as _t,arrayUnion as yc,where as At,increment as zn,deleteDoc as li,Timestamp as jn,runTransaction as Ah}from"./vendor-firebase-firestore-CH1lNiRF.js";import{U as Rh,V as Mh,Y as Dh,Z as Ih}from"./vendor-firebase-core-CO26nNq6.js";import{browserLocalPersistence as Xa,initializeAuth as Ya,browserSessionPersistence as _h,inMemoryPersistence as Ja,GoogleAuthProvider as Lh,createUserWithEmailAndPassword as Oh,updateProfile as Nh,signInWithEmailAndPassword as jh,signOut as Fh,onAuthStateChanged as Vh,updatePassword as $h,updateEmail as Bh,deleteUser as zh,EmailAuthProvider as Uh,reauthenticateWithCredential as qh}from"./vendor-firebase-auth-BLpRW_zO.js";import{g as Gh}from"./vendor-firebase-storage-B3igpVVS.js";import{g as Hh}from"./vendor-firebase-analytics-CTiUNb0-.js";import{R as Wh,I as Kh,F as Qh}from"./vendor-radix-BorKzPz9.js";import{c as Xh}from"./vendor-charts-D8hf8tI0.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 i of r)if(i.type==="childList")for(const a of i.addedNodes)a.tagName==="LINK"&&a.rel==="modulepreload"&&s(a)}).observe(document,{childList:!0,subtree:!0});function n(r){const i={};return r.integrity&&(i.integrity=r.integrity),r.referrerPolicy&&(i.referrerPolicy=r.referrerPolicy),r.crossOrigin==="use-credentials"?i.credentials="include":r.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function s(r){if(r.ep)return;r.ep=!0;const i=n(r);fetch(r.href,i)}})();var nr=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(){}},Yh=class extends nr{#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"}},bc=new Yh,Jh={setTimeout:(e,t)=>setTimeout(e,t),clearTimeout:e=>clearTimeout(e),setInterval:(e,t)=>setInterval(e,t),clearInterval:e=>clearInterval(e)},Zh=class{#e=Jh;#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)}},ci=new Zh;function ef(e){setTimeout(e,0)}var tf=typeof window>"u"||"Deno"in globalThis;function lt(){}function nf(e,t){return typeof e=="function"?e(t):e}function sf(e){return typeof e=="number"&&e>=0&&e!==1/0}function rf(e,t){return Math.max(e+(t||0)-Date.now(),0)}function ui(e,t){return typeof e=="function"?e(t):e}function af(e,t){return typeof e=="function"?e(t):e}function Za(e,t){const{type:n="all",exact:s,fetchStatus:r,predicate:i,queryKey:a,stale:o}=e;if(a){if(s){if(t.queryHash!==Ki(a,t.options))return!1}else if(!qn(t.queryKey,a))return!1}if(n!=="all"){const l=t.isActive();if(n==="active"&&!l||n==="inactive"&&l)return!1}return!(typeof o=="boolean"&&t.isStale()!==o||r&&r!==t.state.fetchStatus||i&&!i(t))}function eo(e,t){const{exact:n,status:s,predicate:r,mutationKey:i}=e;if(i){if(!t.options.mutationKey)return!1;if(n){if(Un(t.options.mutationKey)!==Un(i))return!1}else if(!qn(t.options.mutationKey,i))return!1}return!(s&&t.state.status!==s||r&&!r(t))}function Ki(e,t){return(t?.queryKeyHashFn||Un)(e)}function Un(e){return JSON.stringify(e,(t,n)=>di(n)?Object.keys(n).sort().reduce((s,r)=>(s[r]=n[r],s),{}):n)}function qn(e,t){return e===t?!0:typeof e!=typeof t?!1:e&&t&&typeof e=="object"&&typeof t=="object"?Object.keys(t).every(n=>qn(e[n],t[n])):!1}var of=Object.prototype.hasOwnProperty;function vc(e,t,n=0){if(e===t)return e;if(n>500)return t;const s=to(e)&&to(t);if(!s&&!(di(e)&&di(t)))return t;const i=(s?e:Object.keys(e)).length,a=s?t:Object.keys(t),o=a.length,l=s?new Array(o):{};let d=0;for(let u=0;u{ci.setTimeout(t,e)})}function cf(e,t,n){return typeof n.structuralSharing=="function"?n.structuralSharing(e,t):n.structuralSharing!==!1?vc(e,t):t}function uf(e,t,n=0){const s=[...e,t];return n&&s.length>n?s.slice(1):s}function df(e,t,n=0){const s=[t,...e];return n&&s.length>n?s.slice(0,-1):s}var Qi=Symbol();function wc(e,t){return!e.queryFn&&t?.initialPromise?()=>t.initialPromise:!e.queryFn||e.queryFn===Qi?()=>Promise.reject(new Error(`Missing queryFn: '${e.queryHash}'`)):e.queryFn}function GT(e,t){return typeof e=="function"?e(...t):!!e}function hf(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 xc=(()=>{let e=()=>tf;return{isServer(){return e()},setIsServer(t){e=t}}})();function ff(){let e,t;const n=new Promise((r,i)=>{e=r,t=i});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 mf=ef;function pf(){let e=[],t=0,n=o=>{o()},s=o=>{o()},r=mf;const i=o=>{t?e.push(o):r(()=>{n(o)})},a=()=>{const o=e;e=[],o.length&&r(()=>{s(()=>{o.forEach(l=>{n(l)})})})};return{batch:o=>{let l;t++;try{l=o()}finally{t--,t||a()}return l},batchCalls:o=>(...l)=>{i(()=>{o(...l)})},schedule:i,setNotifyFunction:o=>{n=o},setBatchNotifyFunction:o=>{s=o},setScheduler:o=>{r=o}}}var ze=pf(),gf=class extends nr{#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}},Bs=new gf;function yf(e){return Math.min(1e3*2**e,3e4)}function Sc(e){return(e??"online")==="online"?Bs.isOnline():!0}var hi=class extends Error{constructor(e){super("CancelledError"),this.revert=e?.revert,this.silent=e?.silent}};function Tc(e){let t=!1,n=0,s;const r=ff(),i=()=>r.status!=="pending",a=y=>{if(!i()){const g=new hi(y);h(g),e.onCancel?.(g)}},o=()=>{t=!0},l=()=>{t=!1},d=()=>bc.isFocused()&&(e.networkMode==="always"||Bs.isOnline())&&e.canRun(),u=()=>Sc(e.networkMode)&&e.canRun(),c=y=>{i()||(s?.(),r.resolve(y))},h=y=>{i()||(s?.(),r.reject(y))},m=()=>new Promise(y=>{s=g=>{(i()||d())&&y(g)},e.onPause?.()}).then(()=>{s=void 0,i()||e.onContinue?.()}),p=()=>{if(i())return;let y;const g=n===0?e.initialPromise:void 0;try{y=g??e.fn()}catch(v){y=Promise.reject(v)}Promise.resolve(y).then(c).catch(v=>{if(i())return;const T=e.retry??(xc.isServer()?0:3),x=e.retryDelay??yf,S=typeof x=="function"?x(n,v):x,C=T===!0||typeof T=="number"&&nd()?void 0:m()).then(()=>{t?h(v):p()})})};return{promise:r,status:()=>r.status,cancel:a,continue:()=>(s?.(),r),cancelRetry:o,continueRetry:l,canStart:u,start:()=>(u()?p():m().then(p),r)}}var Cc=class{#e;destroy(){this.clearGcTimeout()}scheduleGc(){this.clearGcTimeout(),sf(this.gcTime)&&(this.#e=ci.setTimeout(()=>{this.optionalRemove()},this.gcTime))}updateGcTime(e){this.gcTime=Math.max(this.gcTime||0,e??(xc.isServer()?1/0:300*1e3))}clearGcTimeout(){this.#e!==void 0&&(ci.clearTimeout(this.#e),this.#e=void 0)}};function bf(e){return{onFetch:(t,n)=>{const s=t.options,r=t.fetchOptions?.meta?.fetchMore?.direction,i=t.state.data?.pages||[],a=t.state.data?.pageParams||[];let o={pages:[],pageParams:[]},l=0;const d=async()=>{let u=!1;const c=p=>{hf(p,()=>t.signal,()=>u=!0)},h=wc(t.options,t.fetchOptions),m=async(p,y,g)=>{if(u)return Promise.reject(t.signal.reason);if(y==null&&p.pages.length)return Promise.resolve(p);const T=(()=>{const P={client:t.client,queryKey:t.queryKey,pageParam:y,direction:g?"backward":"forward",meta:t.options.meta};return c(P),P})(),x=await h(T),{maxPages:S}=t.options,C=g?df:uf;return{pages:C(p.pages,x,S),pageParams:C(p.pageParams,y,S)}};if(r&&i.length){const p=r==="backward",y=p?vf:so,g={pages:i,pageParams:a},v=y(s,g);o=await m(g,v,p)}else{const p=e??i.length;do{const y=l===0?a[0]??s.initialPageParam:so(s,o);if(l>0&&y==null)break;o=await m(o,y),l++}while(lt.options.persister?.(d,{client:t.client,queryKey:t.queryKey,meta:t.options.meta,signal:t.signal},n):t.fetchFn=d}}}function so(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 vf(e,{pages:t,pageParams:n}){return t.length>0?e.getPreviousPageParam?.(t[0],t,n[0],n):void 0}var wf=class extends Cc{#e;#t;#n;#r;#i;#s;#l;#a;constructor(e){super(),this.#a=!1,this.#l=e.defaultOptions,this.setOptions(e.options),this.observers=[],this.#i=e.client,this.#r=this.#i.getQueryCache(),this.queryKey=e.queryKey,this.queryHash=e.queryHash,this.#t=io(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.#l,...e},e?._type&&(this.#e=e._type),this.updateGcTime(this.options.gcTime),this.state&&this.state.data===void 0){const t=io(this.options);t.data!==void 0&&(this.setState(ro(t.data,t.dataUpdatedAt)),this.#t=t)}}optionalRemove(){!this.observers.length&&this.state.fetchStatus==="idle"&&this.#r.remove(this)}setData(e,t){const n=cf(this.state.data,e,this.options);return this.#o({data:n,type:"success",dataUpdatedAt:t?.updatedAt,manual:t?.manual}),n}setState(e){this.#o({type:"setState",state:e})}cancel(e){const t=this.#s?.promise;return this.#s?.cancel(e),t?t.then(lt).catch(lt):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=>af(e.options.enabled,this)!==!1)}isDisabled(){return this.getObserversCount()>0?!this.isActive():this.options.queryFn===Qi||!this.isFetched()}isFetched(){return this.state.dataUpdateCount+this.state.errorUpdateCount>0}isStatic(){return this.getObserversCount()>0?this.observers.some(e=>ui(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:!rf(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.#a||this.#c()?this.#s.cancel({revert:!0}):this.#s.cancelRetry()),this.scheduleGc()),this.#r.notify({type:"observerRemoved",query:this,observer:e}))}getObserversCount(){return this.observers.length}#c(){return this.state.fetchStatus==="paused"&&this.state.status==="pending"}invalidate(){this.state.isInvalidated||this.#o({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 l=this.observers.find(d=>d.options.queryFn);l&&this.setOptions(l.options)}const n=new AbortController,s=l=>{Object.defineProperty(l,"signal",{enumerable:!0,get:()=>(this.#a=!0,n.signal)})},r=()=>{const l=wc(this.options,t),u=(()=>{const c={client:this.#i,queryKey:this.queryKey,meta:this.meta};return s(c),c})();return this.#a=!1,this.options.persister?this.options.persister(l,u,this):l(u)},a=(()=>{const l={fetchOptions:t,options:this.options,queryKey:this.queryKey,client:this.#i,state:this.state,fetchFn:r};return s(l),l})();(this.#e==="infinite"?bf(this.options.pages):this.options.behavior)?.onFetch(a,this),this.#n=this.state,(this.state.fetchStatus==="idle"||this.state.fetchMeta!==a.fetchOptions?.meta)&&this.#o({type:"fetch",meta:a.fetchOptions?.meta}),this.#s=Tc({initialPromise:t?.initialPromise,fn:a.fetchFn,onCancel:l=>{l instanceof hi&&l.revert&&this.setState({...this.#n,fetchStatus:"idle"}),n.abort()},onFail:(l,d)=>{this.#o({type:"failed",failureCount:l,error:d})},onPause:()=>{this.#o({type:"pause"})},onContinue:()=>{this.#o({type:"continue"})},retry:a.options.retry,retryDelay:a.options.retryDelay,networkMode:a.options.networkMode,canRun:()=>!0});try{const l=await this.#s.start();if(l===void 0)throw new Error(`${this.queryHash} data is undefined`);return this.setData(l),this.#r.config.onSuccess?.(l,this),this.#r.config.onSettled?.(l,this.state.error,this),l}catch(l){if(l instanceof hi){if(l.silent)return this.#s.promise;if(l.revert){if(this.state.data===void 0)throw l;return this.state.data}}throw this.#o({type:"error",error:l}),this.#r.config.onError?.(l,this),this.#r.config.onSettled?.(this.state.data,l,this),l}finally{this.scheduleGc()}}#o(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,...xf(n.data,this.options),fetchMeta:e.meta??null};case"success":const s={...n,...ro(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),ze.batch(()=>{this.observers.forEach(n=>{n.onQueryUpdate()}),this.#r.notify({query:this,type:"updated",action:e})})}};function xf(e,t){return{fetchFailureCount:0,fetchFailureReason:null,fetchStatus:Sc(t.networkMode)?"fetching":"paused",...e===void 0&&{error:null,status:"pending"}}}function ro(e,t){return{data:e,dataUpdatedAt:t??Date.now(),error:null,isInvalidated:!1,status:"success"}}function io(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 Sf=class extends Cc{#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||Tf(),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.#i({type:"continue"})},n={client:this.#e,meta:this.options.meta,mutationKey:this.options.mutationKey};this.#r=Tc({fn:()=>this.options.mutationFn?this.options.mutationFn(e,n):Promise.reject(new Error("No mutationFn found")),onFail:(i,a)=>{this.#i({type:"failed",failureCount:i,error:a})},onPause:()=>{this.#i({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.#i({type:"pending",variables:e,isPaused:r}),this.#n.config.onMutate&&await this.#n.config.onMutate(e,this,n);const a=await this.options.onMutate?.(e,n);a!==this.state.context&&this.#i({type:"pending",context:a,variables:e,isPaused:r})}const i=await this.#r.start();return await this.#n.config.onSuccess?.(i,e,this.state.context,this,n),await this.options.onSuccess?.(i,e,this.state.context,n),await this.#n.config.onSettled?.(i,null,this.state.variables,this.state.context,this,n),await this.options.onSettled?.(i,null,e,this.state.context,n),this.#i({type:"success",data:i}),i}catch(i){try{await this.#n.config.onError?.(i,e,this.state.context,this,n)}catch(a){Promise.reject(a)}try{await this.options.onError?.(i,e,this.state.context,n)}catch(a){Promise.reject(a)}try{await this.#n.config.onSettled?.(void 0,i,this.state.variables,this.state.context,this,n)}catch(a){Promise.reject(a)}try{await this.options.onSettled?.(void 0,i,e,this.state.context,n)}catch(a){Promise.reject(a)}throw this.#i({type:"error",error:i}),i}finally{this.#n.runNext(this)}}#i(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),ze.batch(()=>{this.#t.forEach(n=>{n.onMutationUpdate(e)}),this.#n.notify({mutation:this,type:"updated",action:e})})}};function Tf(){return{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:"idle",variables:void 0,submittedAt:0}}var Cf=class extends nr{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 Sf({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=hs(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=hs(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=hs(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=hs(e);return typeof t=="string"?this.#t.get(t)?.find(s=>s!==e&&s.state.isPaused)?.continue()??Promise.resolve():Promise.resolve()}clear(){ze.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=>eo(t,n))}findAll(e={}){return this.getAll().filter(t=>eo(e,t))}notify(e){ze.batch(()=>{this.listeners.forEach(t=>{t(e)})})}resumePausedMutations(){const e=this.getAll().filter(t=>t.state.isPaused);return ze.batch(()=>Promise.all(e.map(t=>t.continue().catch(lt))))}};function hs(e){return e.options.scope?.id}var Pf=class extends nr{constructor(e={}){super(),this.config=e,this.#e=new Map}#e;build(e,t,n){const s=t.queryKey,r=t.queryHash??Ki(s,t);let i=this.get(r);return i||(i=new wf({client:e,queryKey:s,queryHash:r,options:e.defaultQueryOptions(t),state:n,defaultOptions:e.getQueryDefaults(s)}),this.add(i)),i}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(){ze.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=>Za(t,n))}findAll(e={}){const t=this.getAll();return Object.keys(e).length>0?t.filter(n=>Za(e,n)):t}notify(e){ze.batch(()=>{this.listeners.forEach(t=>{t(e)})})}onFocus(){ze.batch(()=>{this.getAll().forEach(e=>{e.onFocus()})})}onOnline(){ze.batch(()=>{this.getAll().forEach(e=>{e.onOnline()})})}},Ef=class{#e;#t;#n;#r;#i;#s;#l;#a;constructor(e={}){this.#e=e.queryCache||new Pf,this.#t=e.mutationCache||new Cf,this.#n=e.defaultOptions||{},this.#r=new Map,this.#i=new Map,this.#s=0}mount(){this.#s++,this.#s===1&&(this.#l=bc.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onFocus())}),this.#a=Bs.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onOnline())}))}unmount(){this.#s--,this.#s===0&&(this.#l?.(),this.#l=void 0,this.#a?.(),this.#a=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(ui(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}),i=this.#e.get(s.queryHash)?.state.data,a=nf(t,i);if(a!==void 0)return this.#e.build(this,s).setData(a,{...n,manual:!0})}setQueriesData(e,t,n){return ze.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;ze.batch(()=>{t.findAll(e).forEach(n=>{t.remove(n)})})}resetQueries(e,t){const n=this.#e;return ze.batch(()=>(n.findAll(e).forEach(s=>{s.reset()}),this.refetchQueries({type:"active",...e},t)))}cancelQueries(e,t={}){const n={revert:!0,...t},s=ze.batch(()=>this.#e.findAll(e).map(r=>r.cancel(n)));return Promise.all(s).then(lt).catch(lt)}invalidateQueries(e,t={}){return ze.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=ze.batch(()=>this.#e.findAll(e).filter(r=>!r.isDisabled()&&!r.isStatic()).map(r=>{let i=r.fetch(void 0,n);return n.throwOnError||(i=i.catch(lt)),r.state.fetchStatus==="paused"?Promise.resolve():i}));return Promise.all(s).then(lt)}fetchQuery(e){const t=this.defaultQueryOptions(e);t.retry===void 0&&(t.retry=!1);const n=this.#e.build(this,t);return n.isStaleByTime(ui(t.staleTime,n))?n.fetch(t):Promise.resolve(n.state.data)}prefetchQuery(e){return this.fetchQuery(e).then(lt).catch(lt)}fetchInfiniteQuery(e){return e._type="infinite",this.fetchQuery(e)}prefetchInfiniteQuery(e){return this.fetchInfiniteQuery(e).then(lt).catch(lt)}ensureInfiniteQueryData(e){return e._type="infinite",this.ensureQueryData(e)}resumePausedMutations(){return Bs.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(Un(e),{queryKey:e,defaultOptions:t})}getQueryDefaults(e){const t=[...this.#r.values()],n={};return t.forEach(s=>{qn(e,s.queryKey)&&Object.assign(n,s.defaultOptions)}),n}setMutationDefaults(e,t){this.#i.set(Un(e),{mutationKey:e,defaultOptions:t})}getMutationDefaults(e){const t=[...this.#i.values()],n={};return t.forEach(s=>{qn(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=Ki(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===Qi&&(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()}},Pc=f.createContext(void 0),HT=e=>{const t=f.useContext(Pc);if(!t)throw new Error("No QueryClient set, use QueryClientProvider to set one");return t},kf=({client:e,children:t})=>(f.useEffect(()=>(e.mount(),()=>{e.unmount()}),[e]),b.jsx(Pc.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 ao="popstate";function oo(e){return typeof e=="object"&&e!=null&&"pathname"in e&&"search"in e&&"hash"in e&&"state"in e&&"key"in e}function Af(e={}){function t(s,r){let i=r.state?.masked,{pathname:a,search:o,hash:l}=i||s.location;return fi("",{pathname:a,search:o,hash:l},r.state&&r.state.usr||null,r.state&&r.state.key||"default",i?{pathname:s.location.pathname,search:s.location.search,hash:s.location.hash}:void 0)}function n(s,r){return typeof r=="string"?r:Gn(r)}return Mf(t,n,null,e)}function Ae(e,t){if(e===!1||e===null||typeof e>"u")throw new Error(t)}function wt(e,t){if(!e){typeof console<"u"&&console.warn(t);try{throw new Error(t)}catch{}}}function Rf(){return Math.random().toString(36).substring(2,10)}function lo(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 fi(e,t,n=null,s,r){return{pathname:typeof e=="string"?e:e.pathname,search:"",hash:"",...typeof t=="string"?Jn(t):t,state:n,key:t&&t.key||s||Rf(),unstable_mask:r}}function Gn({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 Jn(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 Mf(e,t,n,s={}){let{window:r=document.defaultView,v5Compat:i=!1}=s,a=r.history,o="POP",l=null,d=u();d==null&&(d=0,a.replaceState({...a.state,idx:d},""));function u(){return(a.state||{idx:null}).idx}function c(){o="POP";let g=u(),v=g==null?null:g-d;d=g,l&&l({action:o,location:y.location,delta:v})}function h(g,v){o="PUSH";let T=oo(g)?g:fi(y.location,g,v);d=u()+1;let x=lo(T,d),S=y.createHref(T.unstable_mask||T);try{a.pushState(x,"",S)}catch(C){if(C instanceof DOMException&&C.name==="DataCloneError")throw C;r.location.assign(S)}i&&l&&l({action:o,location:y.location,delta:1})}function m(g,v){o="REPLACE";let T=oo(g)?g:fi(y.location,g,v);d=u();let x=lo(T,d),S=y.createHref(T.unstable_mask||T);a.replaceState(x,"",S),i&&l&&l({action:o,location:y.location,delta:0})}function p(g){return Df(g)}let y={get action(){return o},get location(){return e(r,a)},listen(g){if(l)throw new Error("A history only accepts one active listener");return r.addEventListener(ao,c),l=g,()=>{r.removeEventListener(ao,c),l=null}},createHref(g){return t(r,g)},createURL:p,encodeLocation(g){let v=p(g);return{pathname:v.pathname,search:v.search,hash:v.hash}},push:h,replace:m,go(g){return a.go(g)}};return y}function Df(e,t=!1){let n="http://localhost";typeof window<"u"&&(n=window.location.origin!=="null"?window.location.origin:window.location.href),Ae(n,"No window.location.(origin|href) available to create URL");let s=typeof e=="string"?e:Gn(e);return s=s.replace(/ $/,"%20"),!t&&s.startsWith("//")&&(s=n+s),new URL(s,n)}function Ec(e,t,n="/"){return If(e,t,n,!1)}function If(e,t,n,s){let r=typeof t=="string"?Jn(t):t,i=Mt(r.pathname||"/",n);if(i==null)return null;let a=kc(e);_f(a);let o=null;for(let l=0;o==null&&l{let u={relativePath:d===void 0?a.path||"":d,caseSensitive:a.caseSensitive===!0,childrenIndex:o,route:a};if(u.relativePath.startsWith("/")){if(!u.relativePath.startsWith(s)&&l)return;Ae(u.relativePath.startsWith(s),`Absolute route path "${u.relativePath}" nested under path "${s}" is not valid. An absolute child route path must start with the combined path of all its parent routes.`),u.relativePath=u.relativePath.slice(s.length)}let c=ct([s,u.relativePath]),h=n.concat(u);a.children&&a.children.length>0&&(Ae(a.index!==!0,`Index routes must not have child routes. Please remove all child routes from route path "${c}".`),kc(a.children,t,h,c,l)),!(a.path==null&&!a.index)&&t.push({path:c,score:$f(c,a.index),routesMeta:h})};return e.forEach((a,o)=>{if(a.path===""||!a.path?.includes("?"))i(a,o);else for(let l of Ac(a.path))i(a,o,!0,l)}),t}function Ac(e){let t=e.split("/");if(t.length===0)return[];let[n,...s]=t,r=n.endsWith("?"),i=n.replace(/\?$/,"");if(s.length===0)return r?[i,""]:[i];let a=Ac(s.join("/")),o=[];return o.push(...a.map(l=>l===""?i:[i,l].join("/"))),r&&o.push(...a),o.map(l=>e.startsWith("/")&&l===""?"/":l)}function _f(e){e.sort((t,n)=>t.score!==n.score?n.score-t.score:Bf(t.routesMeta.map(s=>s.childrenIndex),n.routesMeta.map(s=>s.childrenIndex)))}var Lf=/^:[\w-]+$/,Of=3,Nf=2,jf=1,Ff=10,Vf=-2,co=e=>e==="*";function $f(e,t){let n=e.split("/"),s=n.length;return n.some(co)&&(s+=Vf),t&&(s+=Nf),n.filter(r=>!co(r)).reduce((r,i)=>r+(Lf.test(i)?Of:i===""?jf:Ff),s)}function Bf(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 zf(e,t,n=!1){let{routesMeta:s}=e,r={},i="/",a=[];for(let o=0;o{if(u==="*"){let p=o[h]||"";a=i.slice(0,i.length-p.length).replace(/(.)\/+$/,"$1")}const m=o[h];return c&&!m?d[u]=void 0:d[u]=(m||"").replace(/%2F/g,"/"),d},{}),pathname:i,pathnameBase:a,pattern:e}}function Uf(e,t=!1,n=!0){wt(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,(a,o,l,d,u)=>{if(s.push({paramName:o,isOptional:l!=null}),l){let c=u.charAt(d+a.length);return c&&c!=="/"?"/([^\\/]*)":"(?:/([^\\/]*))?"}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 qf(e){try{return e.split("/").map(t=>decodeURIComponent(t).replace(/\//g,"%2F")).join("/")}catch(t){return wt(!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 Mt(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 Gf=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;function Hf(e,t="/"){let{pathname:n,search:s="",hash:r=""}=typeof e=="string"?Jn(e):e,i;return n?(n=Mc(n),n.startsWith("/")?i=uo(n.substring(1),"/"):i=uo(n,t)):i=t,{pathname:i,search:Qf(s),hash:Xf(r)}}function uo(e,t){let n=Us(t).split("/");return e.split("/").forEach(r=>{r===".."?n.length>1&&n.pop():r!=="."&&n.push(r)}),n.length>1?n.join("/"):"/"}function Ar(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 Wf(e){return e.filter((t,n)=>n===0||t.route.path&&t.route.path.length>0)}function Rc(e){let t=Wf(e);return t.map((n,s)=>s===t.length-1?n.pathname:n.pathnameBase)}function Xi(e,t,n,s=!1){let r;typeof e=="string"?r=Jn(e):(r={...e},Ae(!r.pathname||!r.pathname.includes("?"),Ar("?","pathname","search",r)),Ae(!r.pathname||!r.pathname.includes("#"),Ar("#","pathname","hash",r)),Ae(!r.search||!r.search.includes("#"),Ar("#","search","hash",r)));let i=e===""||r.pathname==="",a=i?"/":r.pathname,o;if(a==null)o=n;else{let c=t.length-1;if(!s&&a.startsWith("..")){let h=a.split("/");for(;h[0]==="..";)h.shift(),c-=1;r.pathname=h.join("/")}o=c>=0?t[c]:"/"}let l=Hf(r,o),d=a&&a!=="/"&&a.endsWith("/"),u=(i||a===".")&&n.endsWith("/");return!l.pathname.endsWith("/")&&(d||u)&&(l.pathname+="/"),l}var Mc=e=>e.replace(/\/\/+/g,"/"),ct=e=>Mc(e.join("/")),Us=e=>e.replace(/\/+$/,""),Kf=e=>Us(e).replace(/^\/*/,"/"),Qf=e=>!e||e==="?"?"":e.startsWith("?")?e:"?"+e,Xf=e=>!e||e==="#"?"":e.startsWith("#")?e:"#"+e,Yf=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 Jf(e){return e!=null&&typeof e.status=="number"&&typeof e.statusText=="string"&&typeof e.internal=="boolean"&&"data"in e}function Zf(e){let t=e.map(n=>n.route.path).filter(Boolean);return ct(t)||"/"}var Dc=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function Ic(e,t){let n=e;if(typeof n!="string"||!Gf.test(n))return{absoluteURL:void 0,isExternal:!1,to:n};let s=n,r=!1;if(Dc)try{let i=new URL(window.location.href),a=n.startsWith("//")?new URL(i.protocol+n):new URL(n),o=Mt(a.pathname,t);a.origin===i.origin&&o!=null?n=o+a.search+a.hash:r=!0}catch{wt(!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 _c=["POST","PUT","PATCH","DELETE"];new Set(_c);var em=["GET",..._c];new Set(em);var Cn=f.createContext(null);Cn.displayName="DataRouter";var sr=f.createContext(null);sr.displayName="DataRouterState";var Lc=f.createContext(!1);function tm(){return f.useContext(Lc)}var Oc=f.createContext({isTransitioning:!1});Oc.displayName="ViewTransition";var nm=f.createContext(new Map);nm.displayName="Fetchers";var sm=f.createContext(null);sm.displayName="Await";var tt=f.createContext(null);tt.displayName="Navigation";var rr=f.createContext(null);rr.displayName="Location";var Lt=f.createContext({outlet:null,matches:[],isDataRoute:!1});Lt.displayName="Route";var Yi=f.createContext(null);Yi.displayName="RouteError";var Nc="REACT_ROUTER_ERROR",rm="REDIRECT",im="ROUTE_ERROR_RESPONSE";function am(e){if(e.startsWith(`${Nc}:${rm}:{`))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 om(e){if(e.startsWith(`${Nc}:${im}:{`))try{let t=JSON.parse(e.slice(40));if(typeof t=="object"&&t&&typeof t.status=="number"&&typeof t.statusText=="string")return new Yf(t.status,t.statusText,t.data)}catch{}}function lm(e,{relative:t}={}){Ae(Zn(),"useHref() may be used only in the context of a component.");let{basename:n,navigator:s}=f.useContext(tt),{hash:r,pathname:i,search:a}=es(e,{relative:t}),o=i;return n!=="/"&&(o=i==="/"?n:ct([n,i])),s.createHref({pathname:o,search:a,hash:r})}function Zn(){return f.useContext(rr)!=null}function St(){return Ae(Zn(),"useLocation() may be used only in the context of a component."),f.useContext(rr).location}var jc="You should call navigate() in a React.useEffect(), not when your component is first rendered.";function Fc(e){f.useContext(tt).static||f.useLayoutEffect(e)}function Vc(){let{isDataRoute:e}=f.useContext(Lt);return e?xm():cm()}function cm(){Ae(Zn(),"useNavigate() may be used only in the context of a component.");let e=f.useContext(Cn),{basename:t,navigator:n}=f.useContext(tt),{matches:s}=f.useContext(Lt),{pathname:r}=St(),i=JSON.stringify(Rc(s)),a=f.useRef(!1);return Fc(()=>{a.current=!0}),f.useCallback((l,d={})=>{if(wt(a.current,jc),!a.current)return;if(typeof l=="number"){n.go(l);return}let u=Xi(l,JSON.parse(i),r,d.relative==="path");e==null&&t!=="/"&&(u.pathname=u.pathname==="/"?t:ct([t,u.pathname])),(d.replace?n.replace:n.push)(u,d.state,d)},[t,n,i,r,e])}f.createContext(null);function es(e,{relative:t}={}){let{matches:n}=f.useContext(Lt),{pathname:s}=St(),r=JSON.stringify(Rc(n));return f.useMemo(()=>Xi(e,JSON.parse(r),s,t==="path"),[e,r,s,t])}function um(e,t,n){Ae(Zn(),"useRoutes() may be used only in the context of a component.");let{navigator:s}=f.useContext(tt),{matches:r}=f.useContext(Lt),i=r[r.length-1],a=i?i.params:{},o=i?i.pathname:"/",l=i?i.pathnameBase:"/",d=i&&i.route;{let g=d&&d.path||"";Bc(o,!d||g.endsWith("*")||g.endsWith("*?"),`You rendered descendant (or called \`useRoutes()\`) at "${o}" (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 u=St(),c;c=u;let h=c.pathname||"/",m=h;if(l!=="/"){let g=l.replace(/^\//,"").split("/");m="/"+h.replace(/^\//,"").split("/").slice(g.length).join("/")}let p=Ec(e,{pathname:m});return wt(d||p!=null,`No routes matched location "${c.pathname}${c.search}${c.hash}" `),wt(p==null||p[p.length-1].route.element!==void 0||p[p.length-1].route.Component!==void 0||p[p.length-1].route.lazy!==void 0,`Matched leaf route at location "${c.pathname}${c.search}${c.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.`),pm(p&&p.map(g=>Object.assign({},g,{params:Object.assign({},a,g.params),pathname:ct([l,s.encodeLocation?s.encodeLocation(g.pathname.replace(/%/g,"%25").replace(/\?/g,"%3F").replace(/#/g,"%23")).pathname:g.pathname]),pathnameBase:g.pathnameBase==="/"?l:ct([l,s.encodeLocation?s.encodeLocation(g.pathnameBase.replace(/%/g,"%25").replace(/\?/g,"%3F").replace(/#/g,"%23")).pathname:g.pathnameBase])})),r,n)}function dm(){let e=wm(),t=Jf(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},i={padding:"2px 4px",backgroundColor:s},a=null;return console.error("Error handled by React Router default ErrorBoundary:",e),a=f.createElement(f.Fragment,null,f.createElement("p",null,"💿 Hey developer 👋"),f.createElement("p",null,"You can provide a way better UX than this when your app throws errors by providing your own ",f.createElement("code",{style:i},"ErrorBoundary")," or"," ",f.createElement("code",{style:i},"errorElement")," prop on your route.")),f.createElement(f.Fragment,null,f.createElement("h2",null,"Unexpected Application Error!"),f.createElement("h3",{style:{fontStyle:"italic"}},t),n?f.createElement("pre",{style:r},n):null,a)}var hm=f.createElement(dm,null),$c=class extends f.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=om(e.digest);n&&(e=n)}let t=e!==void 0?f.createElement(Lt.Provider,{value:this.props.routeContext},f.createElement(Yi.Provider,{value:e,children:this.props.component})):this.props.children;return this.context?f.createElement(fm,{error:e},t):t}};$c.contextType=Lc;var Rr=new WeakMap;function fm({children:e,error:t}){let{basename:n}=f.useContext(tt);if(typeof t=="object"&&t&&"digest"in t&&typeof t.digest=="string"){let s=am(t.digest);if(s){let r=Rr.get(t);if(r)throw r;let i=Ic(s.location,n);if(Dc&&!Rr.get(t))if(i.isExternal||s.reloadDocument)window.location.href=i.absoluteURL||i.to;else{const a=Promise.resolve().then(()=>window.__reactRouterDataRouter.navigate(i.to,{replace:s.replace}));throw Rr.set(t,a),a}return f.createElement("meta",{httpEquiv:"refresh",content:`0;url=${i.absoluteURL||i.to}`})}}return e}function mm({routeContext:e,match:t,children:n}){let s=f.useContext(Cn);return s&&s.static&&s.staticContext&&(t.route.errorElement||t.route.ErrorBoundary)&&(s.staticContext._deepestRenderedBoundaryId=t.route.id),f.createElement(Lt.Provider,{value:e},n)}function pm(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,i=s?.errors;if(i!=null){let u=r.findIndex(c=>c.route.id&&i?.[c.route.id]!==void 0);Ae(u>=0,`Could not find a matching route for errors on route IDs: ${Object.keys(i).join(",")}`),r=r.slice(0,Math.min(r.length,u+1))}let a=!1,o=-1;if(n&&s){a=s.renderFallback;for(let u=0;u=0?r=r.slice(0,o+1):r=[r[0]];break}}}}let l=n?.onError,d=s&&l?(u,c)=>{l(u,{location:s.location,params:s.matches?.[0]?.params??{},unstable_pattern:Zf(s.matches),errorInfo:c})}:void 0;return r.reduceRight((u,c,h)=>{let m,p=!1,y=null,g=null;s&&(m=i&&c.route.id?i[c.route.id]:void 0,y=c.route.errorElement||hm,a&&(o<0&&h===0?(Bc("route-fallback",!1,"No `HydrateFallback` element provided to render during initial hydration"),p=!0,g=null):o===h&&(p=!0,g=c.route.hydrateFallbackElement||null)));let v=t.concat(r.slice(0,h+1)),T=()=>{let x;return m?x=y:p?x=g:c.route.Component?x=f.createElement(c.route.Component,null):c.route.element?x=c.route.element:x=u,f.createElement(mm,{match:c,routeContext:{outlet:u,matches:v,isDataRoute:s!=null},children:x})};return s&&(c.route.ErrorBoundary||c.route.errorElement||h===0)?f.createElement($c,{location:s.location,revalidation:s.revalidation,component:y,error:m,children:T(),routeContext:{outlet:null,matches:v,isDataRoute:!0},onError:d}):T()},null)}function Ji(e){return`${e} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`}function gm(e){let t=f.useContext(Cn);return Ae(t,Ji(e)),t}function ym(e){let t=f.useContext(sr);return Ae(t,Ji(e)),t}function bm(e){let t=f.useContext(Lt);return Ae(t,Ji(e)),t}function Zi(e){let t=bm(e),n=t.matches[t.matches.length-1];return Ae(n.route.id,`${e} can only be used on routes that contain a unique "id"`),n.route.id}function vm(){return Zi("useRouteId")}function wm(){let e=f.useContext(Yi),t=ym("useRouteError"),n=Zi("useRouteError");return e!==void 0?e:t.errors?.[n]}function xm(){let{router:e}=gm("useNavigate"),t=Zi("useNavigate"),n=f.useRef(!1);return Fc(()=>{n.current=!0}),f.useCallback(async(r,i={})=>{wt(n.current,jc),n.current&&(typeof r=="number"?await e.navigate(r):await e.navigate(r,{fromRouteId:t,...i}))},[e,t])}var ho={};function Bc(e,t,n){!t&&!ho[e]&&(ho[e]=!0,wt(!1,n))}f.memo(Sm);function Sm({routes:e,future:t,state:n,isStatic:s,onError:r}){return um(e,void 0,{state:n,isStatic:s,onError:r})}function Tm({basename:e="/",children:t=null,location:n,navigationType:s="POP",navigator:r,static:i=!1,unstable_useTransitions:a}){Ae(!Zn(),"You cannot render a inside another . You should never have more than one in your app.");let o=e.replace(/^\/*/,"/"),l=f.useMemo(()=>({basename:o,navigator:r,static:i,unstable_useTransitions:a,future:{}}),[o,r,i,a]);typeof n=="string"&&(n=Jn(n));let{pathname:d="/",search:u="",hash:c="",state:h=null,key:m="default",unstable_mask:p}=n,y=f.useMemo(()=>{let g=Mt(d,o);return g==null?null:{location:{pathname:g,search:u,hash:c,state:h,key:m,unstable_mask:p},navigationType:s}},[o,d,u,c,h,m,s,p]);return wt(y!=null,` is not able to match the URL "${d}${u}${c}" because it does not start with the basename, so the won't render anything.`),y==null?null:f.createElement(tt.Provider,{value:l},f.createElement(rr.Provider,{children:t,value:y}))}var ks="get",As="application/x-www-form-urlencoded";function ir(e){return typeof HTMLElement<"u"&&e instanceof HTMLElement}function Cm(e){return ir(e)&&e.tagName.toLowerCase()==="button"}function Pm(e){return ir(e)&&e.tagName.toLowerCase()==="form"}function Em(e){return ir(e)&&e.tagName.toLowerCase()==="input"}function km(e){return!!(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)}function Am(e,t){return e.button===0&&(!t||t==="_self")&&!km(e)}var fs=null;function Rm(){if(fs===null)try{new FormData(document.createElement("form"),0),fs=!1}catch{fs=!0}return fs}var Mm=new Set(["application/x-www-form-urlencoded","multipart/form-data","text/plain"]);function Mr(e){return e!=null&&!Mm.has(e)?(wt(!1,`"${e}" is not a valid \`encType\` for \`
\`/\`\` and will default to "${As}"`),null):e}function Dm(e,t){let n,s,r,i,a;if(Pm(e)){let o=e.getAttribute("action");s=o?Mt(o,t):null,n=e.getAttribute("method")||ks,r=Mr(e.getAttribute("enctype"))||As,i=new FormData(e)}else if(Cm(e)||Em(e)&&(e.type==="submit"||e.type==="image")){let o=e.form;if(o==null)throw new Error('Cannot submit a