1import{a as Ke,u as Xe,e as Je,d as l,t as q,j as e,L as We,B as $,m as S,A as Ze}from"./index-DGkCV18M.js";import{r as i,v as O,w as ue,V as Fe,ab as es,B as He,ac as ss,aa as ts,C as as,A as rs,ad as ns,y as is,k as os,s as cs,H as ls,ae as ds,x as ms}from"./icons-B5hbgZbc.js";import{s as Be}from"./course-slug-lookup-Vfq_IjAy.js";import{s as G}from"./sanitize-BfZfo6cs.js";/* empty css */import{I as us}from"./input-Djs9V4hI.js";import{C as T,d as D,a as ie,b as oe}from"./card-CccqfwSN.js";import{B as Y}from"./badge-DqPzbhq4.js";import{P as xs}from"./progress-tUl4MqjX.js";import{A as ps,a as hs,b as fs,c as gs,d as _s,e as js,f as ws,g as bs}from"./alert-dialog-SEU3HsBF.js";import"./purify.es-C5KSVp3G.js";import"./index-pMG5Nshn.js";const Is=()=>{var Ie,Le;const{user:o,isLoading:v}=Ke(),m=Xe(),[K]=Je(),[R,ce]=i.useState(""),[ae,P]=i.useState(!1),[_,F]=i.useState(null),[E,B]=i.useState(null),[c,j]=i.useState([]),[w,p]=i.useState(0),[h,Q]=i.useState({}),[z,X]=i.useState(0),[xe,pe]=i.useState(!1),[re,he]=i.useState(null),[fe,Oe]=i.useState([]),[Ge,ge]=i.useState(!1),[V,_e]=i.useState(null),[k,I]=i.useState("voucher"),[ne,Ye]=i.useState(!1),[je,we]=i.useState(!1),be=K.get("trial"),A=K.get("course"),[le,ye]=i.useState(!!A),[de,Re]=i.useState(!1),[ve,Ne]=i.useState(!1),[ze,me]=i.useState(!1),U=i.useRef(null),L=i.useRef(0),Se=i.useRef(()=>{}),H=i.useRef(!1),ke=i.useRef(!1),J=i.useMemo(()=>{if(!c.length)return[];const s=[],t=new Map,r=[];for(const a of c)if(a.parent_id){const d=t.get(a.parent_id)||[];d.push(a),t.set(a.parent_id,d)}else r.push(a);const n=new Set;for(const a of r){if(n.has(a.id))continue;const d=t.get(a.id);d&&d.length>0?(s.push({type:"reading_group",passage:a,questions:d}),n.add(a.id)):(s.push({type:"standalone",questions:[a]}),n.add(a.id))}return s},[c]);i.useEffect(()=>{!v&&!o&&m("/auth?redirect=/flp-exam",{replace:!0})},[o,v]),i.useEffect(()=>{o&&Ce()},[o]),i.useEffect(()=>{if(!o||!A)return;let s=!1;return(async()=>{ye(!0);try{const{data:t}=await l.from("course_catalog").select("course_id").ilike("course_slug",Be(A)).maybeSingle();if(!(t!=null&&t.course_id))return;const r=t.course_id,[{data:n},{data:a},{data:d}]=await Promise.all([l.from("course_access").select("status, expires_at").eq("user_id",o.id).eq("course_id",r),l.from("course_component_access").select("component, status, expires_at").eq("user_id",o.id).eq("course_id",r),l.from("flp_access").select("status, flp_exams!inner(course_id)").eq("user_id",o.id).eq("status","approved")]),f=(n??[]).some(u=>u.status==="approved"&&(!u.expires_at||new Date(u.expires_at).getTime()>Date.now()))||(a??[]).some(u=>u.status==="approved"&&(!u.expires_at||new Date(u.expires_at).getTime()>Date.now())&&["flp","past_papers","all_access"].includes(u.component))||(d??[]).some(u=>{var N;return((N=u.flp_exams)==null?void 0:N.course_id)===r});s||Re(f)}finally{s||ye(!1)}})(),()=>{s=!0}},[o,A]),i.useEffect(()=>{if(k==="exam"&&z>0)return L.current||(L.current=Date.now()+z*1e3),U.current=window.setInterval(()=>{const s=Math.max(0,Math.ceil((L.current-Date.now())/1e3));X(s),s<=0&&(clearInterval(U.current),Se.current())},1e3),()=>{U.current&&clearInterval(U.current)}},[k,z>0]),i.useEffect(()=>{if(k!=="exam"||ne||!(_!=null&&_.id))return;const s=window.setTimeout(()=>{l.from("flp_attempts").update({answers:h}).eq("id",_.id).eq("status","in_progress").then(()=>{})},1500);return()=>clearTimeout(s)},[h,k,ne,_==null?void 0:_.id]),i.useEffect(()=>{!o||ke.current||k!=="voucher"||(ke.current=!0,(async()=>{const{data:s}=await l.from("flp_attempts").select("*, flp_exams(*)").eq("user_id",o.id).eq("status","in_progress").order("started_at",{ascending:!1}).limit(1).maybeSingle(),t=s;if(!(t!=null&&t.flp_exams)||!Array.isArray(t.generated_questions)||!t.generated_questions.length)return;const r=Date.parse(t.started_at)+te(t.flp_exams)*6e4;if(!Number.isFinite(r)||Date.now()>r+24*3600*1e3)return;const n={};if(t.answers&&typeof t.answers=="object"&&!Array.isArray(t.answers))for(const[f,u]of Object.entries(t.answers))Number.isFinite(Number(u))&&(n[Number(f)]=Number(u));const{flp_exams:a,...d}=t;H.current=!1,L.current=r,F(d),B(a),j(t.generated_questions),Q(n),p(0),X(Math.max(1,Math.ceil((r-Date.now())/1e3))),I("exam"),Date.now()<r&&q({title:"Paper resumed",description:"Your answers and remaining time were kept."})})())},[o,k]);const Ce=async()=>
1{if(o){ge(!0);try{const{data:s}=await l.from("flp_attempts").select("*, flp_exams(title, course_filename)").eq("user_id",o.id).eq("status","completed").order("submitted_at",{ascending:!1});Oe(s||[])}finally{ge(!1)}}},Ee=async()=>{if(!(!R.trim()||!o)){P(!0);try{const{data:s,error:t}=await l.rpc("lookup_flp_voucher",{_code:R.trim().toUpperCase()}),r=s;if(t||!r)throw new Error("Invalid voucher code");if(!r.ok)throw r.code==="already_used"?new Error("This voucher has already been used"):new Error("Invalid voucher code");const n={id:r.voucher_id};let a=r.exam;const{data:d}=await l.from("flp_exams").select("*").eq("id",a==null?void 0:a.id).maybeSingle();if(d&&(a={...a,...d}),!(a!=null&&a.is_active))throw new Error("This exam is not currently active");const{data:f,error:u}=await l.rpc("get_flp_questions",{_exam_id:a.id,_voucher_id:n.id});if(u||!(f!=null&&f.course_data))throw new Error("Course data not found. Please contact admin.");const N={course_data:f.course_data},{data:ee}=await l.from("flp_sections").select("*").eq("exam_id",a.id).order("sort_order"),g=qe(ee||[],N.course_data);if(g.length===0)throw new Error("No questions could be generated. Please contact admin.");const{data:b,error:se}=await l.rpc("claim_flp_voucher",{_voucher_id:n.id,_exam_id:a.id});if(se||!(b!=null&&b.ok))throw new Error("Failed to claim voucher");const{data:Me,error:x}=await l.from("flp_attempts").insert({exam_id:a.id,user_id:o.id,voucher_id:n.id,generated_questions:g.map(y=>({id:y.id,text:y.text,parent_id:y.parent_id||null,answers:y.answers,explanation:y.explanation,topic_name:y.topic_name,section_title:y.section_title})),total_questions:g.length,status:"in_progress"}).select().single();if(x)throw x;F(Me),B(a),j(g),H.current=!1,L.current=0,X(te(a)*60),Q({}),p(0),I("exam"),q({title:"Exam Started!",description:`You have ${te(a)} minutes. Good luck!`})}catch(s){q({title:"Error",description:s.message,variant:"destructive"})}finally{P(!1)}}},Ve=async s=>{if(o){Ne(!0);try{const{data:t}=await l.from("course_catalog").select("course_id").ilike("course_slug",Be(s)).maybeSingle(),r=t==null?void 0:t.course_id;if(!r)throw new Error("Course data not found. Please contact admin.");const{data:n}=await l.from("flp_exams").select("*").eq("course_id",r).eq("is_active",!0).order("created_at",{ascending:!1}).limit(1).maybeSingle();if(!n)throw new Error("No active full-length paper for this course yet.");const{data:a,error:d}=await l.rpc("get_flp_questions",{_exam_id:n.id});if(d||!(a!=null&&a.course_data))throw new Error("You don't have access to this paper yet.");const f={course_data:a.course_data},{data:u}=await l.from("flp_sections").select("*").eq("exam_id",n.id).order("sort_order"),N=qe(u||[],f.course_data);if(N.length===0)throw new Error("No questions could be generated. Please contact admin.");const{data:ee,error:g}=await l.from("flp_attempts").insert({exam_id:n.id,user_id:o.id,voucher_id:null,generated_questions:N.map(b=>({id:b.id,text:b.text,parent_id:b.parent_id||null,answers:b.answers,explanation:b.explanation,topic_name:b.topic_name,section_title:b.section_title})),total_questions:N.length,status:"in_progress"}).select().single();if(g)throw g;F(ee),B(n),j(N),H.current=!1,L.current=0,X(te(n)*60),Q({}),p(0),I("exam"),q({title:"Exam Started!",description:`You have ${te(n)} minutes. Good luck!`})}catch(t){q({title:"Error",description:t.message,variant:"destructive"})}finally{Ne(!1)}}},Ae=10,Ue=async s=>{we(!0);try{const{data:t,error:r}=await l.rpc("get_flp_trial_questions",{_slug:s,_limit:Ae});if(r||!t)throw new Error("Course not found.");const n={course_name:t.course_name,display_name:null},a=t.questions||[];if(!a.length)throw new Error("No trial questions available for this course yet.");const d=a.sort(()=>Math.random()-.5).slice(0,Ae);Ye(!0),F(null),B({title:`${n.display_name||n.course_name} â Free FLP Trial`,time_limit_minutes:12}),j(d),H.current=!1,L.current=0,X(12*60),Q({}),p(0),I("exam"),q({title:"Trial started",description:`${d.length} free questions. Results are not saved.`})}catch(t){q({title:"Error",description:t.message,variant:"destructive"})}finally{we(!1)}},qe=(s,t)=>{const r=[],n=t.subjects||[];for(const a of s){const d=(a.topic_ids||[]).map(Number),f=[];for(const ee of n)for(const g of ee.topics||[])if(d.includes(g.id))for(const b of g.subcategories||[]){const se=(b.questions||[]).filter(x=>!x.is_hidden);if(se.some(x=>x.type==="group")){let x=null,y=[];const $e=()=>{if(x&&y.length>0){r.push({...x,topic_name:g.name,section_title:a.title});for(const M of y)r.push({...M,parent_id:x.id,topic_name:g.name,section_title:a.title})}x=null,y=[]};for(const M of se)M.type==="group"?($e(),x=M,y=[]):M.type==="mcq"&&x?y.push(M):M.type==="mcq"&&f.push({...M,topic_name:g.name,section_title:a.title});$e()}else for(const x of se)x.type==="mcq"&&!x.parent_id&&f.push({...x,topic_name:g.name,section_title:a.title})}const N=f.sort(()=>Math.random()-.5).slice(0,a.num_questions);r.push(...N)}return r},Te=(s,t)=>{Q(r=>({...r,[s]:t}))},De=async()=>
1{if(!H.current){H.current=!0,U.current&&clearInterval(U.current),L.current=0,pe(!0);try{let s=0;for(const r of c){const n=h[r.id];n&&r.answers.some(a=>a.id===n&&a.is_correct)&&s++}let t=null;try{const{data:r,error:n}=await l.functions.invoke("flp-ai-review",{body:{questions:c,answers:h,courseName:(E==null?void 0:E.title)||"Course"}});!n&&(r!=null&&r.review)&&(t=r.review)}catch(r){console.error("AI review failed:",r)}!ne&&(_!=null&&_.id)&&await l.from("flp_attempts").update({answers:h,score:s,submitted_at:new Date().toISOString(),ai_review:t,status:"completed"}).eq("id",_.id),he({score:s,total:c.length,aiReview:t}),I("results"),q({title:"Exam Submitted!",description:`Score: ${s}/${c.length}`}),ne||await Ce()}catch(s){H.current=!1,q({title:"Error",description:s.message,variant:"destructive"})}finally{pe(!1)}}};Se.current=De;const Pe=s=>{const t=Number.isFinite(s)&&s>0?Math.floor(s):0,r=Math.floor(t/60),n=t%60;return`${r.toString().padStart(2,"0")}:${n.toString().padStart(2,"0")}`},C=J[w],W=Object.keys(h).length,Z=c.filter(s=>s.answers&&s.answers.length>0);return v?e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background",children:e.jsx(O,{className:"w-8 h-8 animate-spin text-primary"})}):e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsxs("div",{className:"absolute inset-0 pointer-events-none overflow-hidden",children:[e.jsx("div",{className:"absolute top-20 right-10 w-80 h-80 bg-highlight-lime/10 rounded-full blur-3xl"}),e.jsx("div",{className:"absolute bottom-20 left-10 w-[400px] h-[400px] bg-highlight-sky/10 rounded-full blur-3xl"})]}),e.jsxs("div",{className:"relative z-10",children:[k==="voucher"&&e.jsxs("div",{className:"max-w-2xl mx-auto px-4 py-12",children:[e.jsx(We,{to:"/dashboard",children:e.jsxs($,{variant:"ghost",size:"sm",className:"gap-2 mb-8",children:[e.jsx(ue,{className:"w-4 h-4"})," Back to Dashboard"]})}),e.jsx(S.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},children:e.jsxs(T,{className:"glass-card overflow-hidden",children:[e.jsxs("div",{className:"bg-gradient-to-r from-primary to-primary/80 p-8 text-primary-foreground",children:[e.jsx(Fe,{className:"w-12 h-12 mb-4"}),e.jsx("h1",{className:"text-3xl font-bold mb-2",children:"Full-Length Paper"}),e.jsx("p",{className:"text-primary-foreground/80",children:A&&(le||de)?"Your paper is ready when you are":"Enter your voucher code to start an exam"})]}),e.jsxs(D,{className:"p-8 space-y-6",children:[A&&le&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(O,{className:"w-4 h-4 animate-spin"})," Checking your accessâ¦"]}),A&&de&&e.jsxs("div",{className:"rounded-2xl border border-primary/40 bg-primary/10 p-5",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.18em] text-muted-foreground",children:"Included with your course"}),e.jsx("p",{className:"mt-1 font-semibold text-foreground",children:"You already have access to this paper"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"No voucher needed â start whenever you're ready."}),e.jsxs($,{onClick:()=>Ve(A),disabled:ve,className:"mt-4 gap-2",children:[ve?e.jsx(O,{className:"w-4 h-4 animate-spin"}):e.jsx(Fe,{className:"w-4 h-4"}),"Start exam"]})]}),!(A&&(le||de))&&e.jsxs("div",{className:"flex gap-3",children:[e.jsx(us,{placeholder:"Enter voucher code (e.g., ABCD1234)",value:R,onChange:s=>ce(s.target.value.toUpperCase()),onKeyDown:s=>s.key==="Enter"&&Ee(),className:"font-mono text-lg tracking-widest text-center uppercase"}),e.jsxs($,{onClick:Ee,disabled:ae||!R.trim(),className:"gap-2 shrink-0",children:[ae?e.jsx(O,{className:"w-4 h-4 animate-spin"}):e.jsx(es,{className:"w-4 h-4"}),"Start Exam"]})]}),be&&e.jsxs("div",{className:"rounded-2xl border border-highlight-lime/40 bg-highlight-lime/10 p-5",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.18em] text-muted-foreground",children:"Free trial"}),e.jsx("p",{className:"mt-1 font-semibold text-foreground",children:"Try 10 questions, no voucher needed"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"A short taste of the real paper. Results are not saved and there is no ranking."}),e.jsxs($,{onClick:()=>Ue(be),disabled:je,className:"mt-4 gap-2",children:[je?e.jsx(O,{className:"w-4 h-4 animate-spin"}):e.jsx(He,{className:"w-4 h-4"}),"Start 10 free questions"]})]})]})]})}),e.jsxs(S.div,{initial:{opacity:0,y:20}
1,animate:{opacity:1,y:0},transition:{delay:.1},className:"mt-8",children:[e.jsxs("h2",{className:"text-xl font-bold text-foreground mb-4 flex items-center gap-2",children:[e.jsx(ss,{className:"w-5 h-5"})," Previous Attempts"]}),Ge?e.jsx(O,{className:"w-6 h-6 animate-spin text-muted-foreground"}):fe.length===0?e.jsx(T,{className:"glass-card",children:e.jsx(D,{className:"py-8 text-center text-muted-foreground",children:"No previous attempts yet."})}):e.jsx("div",{className:"space-y-3",children:fe.map(s=>{var t;return e.jsx(T,{className:"glass-card hover:shadow-md transition-shadow cursor-pointer",onClick:()=>{_e(s),I("history")},children:e.jsxs(D,{className:"p-4 flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-foreground",children:((t=s.flp_exams)==null?void 0:t.title)||"Exam"}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[new Date(s.submitted_at).toLocaleDateString()," ⢠Score: ",s.score,"/",s.total_questions]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(Y,{variant:s.score/s.total_questions>=.7?"default":"destructive",children:[Math.round(s.score/s.total_questions*100),"%"]}),e.jsx(ts,{className:"w-4 h-4 text-muted-foreground"})]})]})},s.id)})})]})]}),k==="exam"&&C&&e.jsxs("div",{className:"h-screen flex flex-col",children:[e.jsxs("div",{className:"border-b border-border/40 bg-card/90 backdrop-blur-sm px-3 md:px-4 py-2 md:py-3 flex flex-col sm:flex-row items-start sm:items-center justify-between sticky top-0 z-50 gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 md:gap-4 min-w-0 w-full sm:w-auto",children:[e.jsx("h2",{className:"font-bold text-foreground text-sm md:text-base truncate",children:E==null?void 0:E.title}),e.jsx(Y,{variant:"outline",className:"shrink-0 text-[10px] md:text-xs hidden sm:inline-flex",children:C.type==="reading_group"?(Ie=C.questions[0])==null?void 0:Ie.section_title:(Le=C.questions[0])==null?void 0:Le.section_title})]}),e.jsxs("div",{className:"flex items-center gap-2 md:gap-4 w-full sm:w-auto justify-between sm:justify-end",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-xs md:text-sm text-muted-foreground",children:[W,"/",Z.length]}),e.jsx(xs,{value:W/Z.length*100,className:"w-16 md:w-24 h-2"})]}),e.jsxs("div",{className:`flex items-center gap-1 font-mono font-bold text-base md:text-lg ${z<300?"text-destructive animate-pulse":"text-foreground"}`,children:[e.jsx(as,{className:"w-4 h-4"}),Pe(z)]})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:e.jsx("div",{className:"max-w-3xl mx-auto px-3 md:px-4 pt-4 md:pt-8 pb-40 md:pb-28",children:e.jsx(Ze,{mode:"wait",children:e.jsxs(S.div,{initial:{opacity:0,x:20},animate:{opacity:1,x:0},exit:{opacity:0,x:-20},transition:{duration:.2},className:"space-y-6",children:[C.type==="reading_group"&&C.passage&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"p-3 md:p-5 rounded-xl bg-muted/40 border border-border/50",children:[e.jsx(Y,{variant:"secondary",className:"mb-3",children:"Reading Passage"}),e.jsx("div",{className:"prose prose-sm max-w-none text-foreground leading-relaxed",dangerouslySetInnerHTML:{__html:G(C.passage.text)}})]}),C.questions.map((s,t)=>e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(Y,{variant:"secondary",children:["Q",t+1]}),e.jsx("span",{className:"text-sm text-muted-foreground",children:s.topic_name})]}),e.jsx("div",{className:"text-base font-medium text-foreground prose prose-sm max-w-none",dangerouslySetInnerHTML:{__html:G(s.text)}}),e.jsx("div",{className:"space-y-2",children:s.answers.map((r,n)=>{const a=h[s.id]===r.id;return e.jsx(S.button,{whileHover:{scale:1.01},whileTap:{scale:.99},onClick:()=>
1Te(s.id,r.id),className:`w-full text-left p-3 md:p-4 rounded-xl border-2 transition-all ${a?"border-primary bg-primary/5 shadow-md":"border-border/50 bg-card hover:border-border hover:shadow-sm"}`,children:e.jsxs("div",{className:"flex items-start gap-2 md:gap-3",children:[e.jsx("span",{className:`w-6 h-6 md:w-8 md:h-8 rounded-full flex items-center justify-center text-xs md:text-sm font-bold shrink-0 ${a?"bg-primary text-primary-foreground":"bg-muted text-muted-foreground"}`,children:String.fromCharCode(65+n)}),e.jsx("span",{className:"text-sm md:text-base text-foreground prose prose-sm max-w-none pt-0.5",dangerouslySetInnerHTML:{__html:G(r.text)}})]})},r.id)})})]},s.id))]}),C.type==="standalone"&&(()=>{const s=C.questions[0];return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(Y,{variant:"secondary",children:["Q",w+1]}),e.jsx("span",{className:"text-xs md:text-sm text-muted-foreground truncate",children:s.topic_name})]}),e.jsx("div",{className:"text-base md:text-xl font-semibold text-foreground leading-relaxed prose prose-sm max-w-none",dangerouslySetInnerHTML:{__html:G(s.text)}}),e.jsx("div",{className:"space-y-2 md:space-y-3",children:s.answers.map((t,r)=>{const n=h[s.id]===t.id;return e.jsx(S.button,{whileHover:{scale:1.01},whileTap:{scale:.99},onClick:()=>
1Te(s.id,t.id),className:`w-full text-left p-3 md:p-4 rounded-xl border-2 transition-all ${n?"border-primary bg-primary/5 shadow-md":"border-border/50 bg-card hover:border-border hover:shadow-sm"}`,children:e.jsxs("div",{className:"flex items-start gap-2 md:gap-3",children:[e.jsx("span",{className:`w-6 h-6 md:w-8 md:h-8 rounded-full flex items-center justify-center text-xs md:text-sm font-bold shrink-0 ${n?"bg-primary text-primary-foreground":"bg-muted text-muted-foreground"}`,children:String.fromCharCode(65+r)}),e.jsx("span",{className:"text-sm md:text-base text-foreground prose prose-sm max-w-none pt-0.5",dangerouslySetInnerHTML:{__html:G(t.text)}})]})},t.id)})})]})})()]},w)})})}),e.jsx("div",{className:"fixed inset-x-0 bottom-0 z-50 border-t border-border/40 bg-card/95 backdrop-blur-sm px-3 md:px-4 pt-2 md:pt-3 pb-[max(0.5rem,env(safe-area-inset-bottom))] md:pb-3",children:e.jsxs("div",{className:"max-w-5xl mx-auto flex flex-col sm:flex-row items-center justify-between gap-2",children:[e.jsx("div",{className:"flex gap-1 overflow-x-auto max-w-full sm:max-w-[50%] pb-1 sm:pb-0 w-full sm:w-auto",children:J.map((s,t)=>{const r=s.questions.every(n=>h[n.id]!==void 0);return e.jsx("button",{onClick:()=>p(t),"aria-label":`Go to page ${t+1}`,className:`w-7 h-7 md:w-8 md:h-8 rounded-lg text-[10px] md:text-xs font-medium shrink-0 transition-all ${t===w?"bg-primary text-primary-foreground":r?"bg-accent/30 text-accent-foreground":"bg-muted text-muted-foreground"}`,children:t+1},t)})}),e.jsxs("div",{className:"flex items-center gap-2 w-full sm:w-auto",children:[e.jsxs($,{variant:"outline",className:"flex-1 sm:flex-none",disabled:w===0,onClick:()=>p(s=>s-1),children:[e.jsx(ue,{className:"w-4 h-4 mr-1"})," Previous"]}),w<J.length-1&&e.jsxs($,{className:"flex-1 sm:flex-none",onClick:()=>p(s=>s+1),children:["Next ",e.jsx(rs,{className:"w-4 h-4 ml-1"})]}),e.jsxs($,{variant:w<J.length-1?"outline":"default",onClick:()=>me(!0),disabled:xe,className:`gap-2 ${w<J.length-1?"":"flex-1 sm:flex-none bg-accent text-accent-foreground hover:bg-accent/90"}`,children:[xe?e.jsx(O,{className:"w-4 h-4 animate-spin"}):e.jsx(ns,{className:"w-4 h-4"}),"Submit"]})]})]})}),e.jsx(ps,{open:ze,onOpenChange:me,children:e.jsxs(hs,{children:[e.jsxs(fs,{children:[e.jsx(gs,{children:"Submit your paper?"}),e.jsxs(_s,{children:["You have answered ",W," of ",Z.length," questions",Z.length-W>0?` â ${Z.length-W} still unanswered`:"",". Time left: ",Pe(z),". You can't change answers after submitting."]})]}),e.jsxs(js,{children:[e.jsx(ws,{children:"Keep working"}),e.jsx(bs,{onClick:()=>{me(!1),De()},children:"Submit paper"})]})]})})]}),k==="results"&&re&&e.jsx(Qe,{score:re.score,total:re.total,aiReview:re.aiReview,questions:c,answers:h,onBack:()=>{I("voucher"),he(null)}}),k==="history"&&V&&e.jsx(Qe,{score:V.score,total:V.total_questions,aiReview:V.ai_review,questions:V.generated_questions||[],answers:V.answers||{},onBack:()=>{I("voucher"),_e(null)},isPast:!0})]})]})},Qe=({score:o,total:v,aiReview:m,questions:K,answers:R,onBack:ce,isPast:ae})=>{var F,E,B;const P=v>0?Math.round(o/v*100):0,_=(m==null?void 0:m.overall_grade)||(P>=90?"A":P>=80?"B":P>=70?"C":P>=60?"D":"F");return e.jsxs("div",{className:"max-w-4xl mx-auto px-3 md:px-4 py-4 md:py-8",children:[e.jsxs($,{variant:"ghost",size:"sm",onClick:ce,className:"gap-2 mb-6",children:[e.jsx(ue,{className:"w-4 h-4"})," ",ae?"Back to History":"Back"]}),e.jsx(S.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},children:e.jsxs(T,{className:"overflow-hidden mb-8",children:[e.jsxs("div",{className:"bg-gradient-to-r from-primary to-primary/80 p-4 md:p-8 text-primary-foreground text-center",children:[e.jsxs("div",{className:"text-3xl md:text-6xl font-bold mb-2",children:[P,"%"]}),e.jsxs("div",{className:"text-lg md:text-2xl font-semibold mb-1",children:["Grade: ",_]}),e.jsxs("p",{className:"text-primary-foreground/70 text-sm md:text-base",children:[o," correct out of ",v," questions"]})]}),(m==null?void 0:m.overall_feedback)&&e.jsx(D,{className:"p-6",children:e.jsx("p",{className:"text-foreground text-lg",children:m.overall_feedback})})]})}),m&&e.jsxs("div",{className:"space-y-6",children:[((F=m.weak_topics)==null?void 0:F.length)>0&&e.jsx(S.div,{initial:{opacity:0,y:20}
1,animate:{opacity:1,y:0},transition:{delay:.1},children:e.jsxs(T,{children:[e.jsx(ie,{children:e.jsxs(oe,{className:"flex items-center gap-2 text-destructive",children:[e.jsx(is,{className:"w-5 h-5"})," Areas to Improve"]})}),e.jsx(D,{className:"space-y-4",children:m.weak_topics.map((c,j)=>{var w;return e.jsxs("div",{className:"p-4 rounded-lg bg-destructive/5 border border-destructive/20",children:[e.jsx("h4",{className:"font-semibold text-foreground mb-1",children:c.topic}),e.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:c.weakness_description}),((w=c.formulas_to_practice)==null?void 0:w.length)>0&&e.jsx("div",{className:"flex flex-wrap gap-2 mb-2",children:c.formulas_to_practice.map((p,h)=>e.jsx(Y,{variant:"outline",className:"text-xs",children:p},h))}),c.study_tips&&e.jsxs("p",{className:"text-sm text-foreground/80 italic",children:["ð¡ ",c.study_tips]})]},j)})})]})}),((E=m.strong_topics)==null?void 0:E.length)>0&&e.jsx(S.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.2},children:e.jsxs(T,{children:[e.jsx(ie,{children:e.jsxs(oe,{className:"flex items-center gap-2 text-accent-foreground",children:[e.jsx(os,{className:"w-5 h-5 text-accent"})," Strong Areas"]})}),e.jsx(D,{children:e.jsx("div",{className:"flex flex-wrap gap-2",children:m.strong_topics.map((c,j)=>e.jsx(Y,{className:"bg-accent/20 text-accent-foreground",children:c},j))})})]})}),((B=m.recommended_actions)==null?void 0:B.length)>0&&e.jsx(S.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.3},children:e.jsxs(T,{children:[e.jsx(ie,{children:e.jsxs(oe,{className:"flex items-center gap-2",children:[e.jsx(cs,{className:"w-5 h-5"})," Next Steps"]})}),e.jsx(D,{children:e.jsx("ol",{className:"space-y-2",children:m.recommended_actions.map((c,j)=>e.jsxs("li",{className:"flex items-start gap-3 text-foreground",children:[e.jsx("span",{className:"w-6 h-6 rounded-full bg-primary text-primary-foreground flex items-center justify-center text-xs font-bold shrink-0",children:j+1}),c]},j))})})]})}),m.encouragement&&e.jsx(S.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.4},children:e.jsx(T,{className:"bg-gradient-to-r from-accent/10 to-accent/5 border-accent/20",children:e.jsxs(D,{className:"p-6 text-center",children:[e.jsx(He,{className:"w-8 h-8 mx-auto mb-3 text-accent"}),e.jsx("p",{className:"text-lg font-medium text-foreground",children:m.encouragement})]})})})]}),K.length>0&&e.jsx(S.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.5},className:"mt-8",children:e.jsxs(T,{children:[e.jsx(ie,{children:e.jsxs(oe,{className:"flex items-center gap-2",children:[e.jsx(ls,{className:"w-5 h-5"})," Question Review"]})}),e.jsx(D,{className:"space-y-4",children:K.filter(c=>c.answers&&c.answers.length>0).map((c,j)=>{const w=R[c.id],p=c.answers.find(Q=>Q.is_correct),h=w===(p==null?void 0:p.id);
1return e.jsx("div",{className:`p-3 md:p-4 rounded-lg border ${h?"border-accent/30 bg-accent/5":"border-destructive/30 bg-destructive/5"}`,children:e.jsxs("div",{className:"flex items-start gap-2 mb-2",children:[h?e.jsx(ds,{className:"w-4 h-4 md:w-5 md:h-5 text-accent shrink-0 mt-0.5"}):e.jsx(ms,{className:"w-4 h-4 md:w-5 md:h-5 text-destructive shrink-0 mt-0.5"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"font-medium text-foreground prose prose-sm max-w-none",dangerouslySetInnerHTML:{__html:`Q${j+1}: ${G(c.text)}`}}),!h&&e.jsxs("div",{className:"text-sm text-muted-foreground mt-1 flex items-center gap-1",children:[e.jsx("span",{children:"Correct:"}),e.jsx("span",{className:"text-accent font-medium prose prose-sm max-w-none",dangerouslySetInnerHTML:{__html:G((p==null?void 0:p.text)||"")}})]})]})]})},c.id)})})]})})]})},te=o=>{const v=Number(o==null?void 0:o.time_limit_minutes);return Number.isFinite(v)&&v>0?v:(console.warn("[FLP] Paper has no valid time limit; using 120 minutes",o==null?void 0:o.id),120)};export{Is as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.