1import{j as e,r as v}from"./ui-Dt97DcxY.js";import{B as q,A as P,e as I,a2 as S,t as E,a3 as L,u as M,S as Q,am as T,s as _}from"./index-BIn7K3iC.js";import{a as C,h as $}from"./index-BCaLrroO.js";import{C as w}from"./circle-check-big-CkSbjHdV.js";import{R as B}from"./rotate-ccw-CK_y0MVQ.js";import{L as k,N as O}from"./vendor-CHR6bWA7.js";import{C as g,a as f}from"./card-Dvm4-RKF.js";import{T as W}from"./trophy-CP6Bf2XP.js";import{T as D}from"./trending-up-D81yOahd.js";import{P as F}from"./ProgressPagesLayout-DIkG8lII.js";import{C as H}from"./clipboard-check-whr_u057.js";import"./charts-EWnDMYId.js";import"./query-G6P4xjCJ.js";import"./machineLearningQuiz-DzgYX5GK.js";import"./udfsQuiz-B-1DaE3R.js";import"./biIntegrationQuiz-BJergpNr.js";import"./BookSidebar-DI-qLfGJ.js";function U({chapterId:o,title:i,questionCount:n,progress:c,className:j}){const t=c?.quizPassed||!1,m=c?.quizScore;return e.jsxs("div",{className:I("group relative flex flex-col rounded-lg border p-5 transition-all",t?"border-primary/30 bg-primary/5":"border-border bg-card hover:border-primary/50 hover:shadow-md",j),children:[e.jsx("div",{className:"absolute top-3 right-3",children:t?e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs font-medium text-primary bg-primary/10 px-2 py-1 rounded-full",children:[e.jsx(w,{className:"h-3 w-3"}),"Passed"]}):e.jsx("span",{className:"inline-flex items-center gap-1 text-xs font-medium text-amber-600 dark:text-amber-400 bg-amber-100 dark:bg-amber-900/30 px-2 py-1 rounded-full",children:"Ready"})}),e.jsx("h3",{className:"font-semibold text-base mb-2 pr-16 text-foreground",children:i}),e.jsxs("p",{className:"text-xs text-muted-foreground mb-4",children:[n," questions ⢠70% to pass"]}),t&&m!==null&&e.jsxs("div",{className:"mb-4",children:[e.jsxs("div",{className:"text-2xl font-bold text-primary",children:[m,"%"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Your score"})]}),e.jsx("div",{className:"mt-auto",children:t?e.jsx(q,{variant:"outline",size:"sm",asChild:!0,className:"w-full",children:e.jsxs(k,{to:`/quizzes/${o}`,children:[e.jsx(B,{className:"h-3 w-3 mr-2"}),"Retake Quiz"]})}):e.jsx(q,{size:"sm",asChild:!0,className:"w-full",children:e.jsxs(k,{to:`/quizzes/${o}`,children:["Take Quiz",e.jsx(P,{className:"h-3 w-3 ml-2"})]})})})]})}function Y({attempts:o,totalQuizzes:i,passedQuizzes:n,availableQuizzes:c}){const t=(()=>{if(o.length===0)return{averageScore:0,improvementRate:0,totalAttempts:0,bestScore:0,hasImprovement:!1};const x={};o.forEach(s=>{const a=s.chapter_id||"unknown";x[a]||(x[a]=[]),x[a].push(s)});const p=o.map(s=>s.score),z=Math.round(p.reduce((s,a)=>s+a,0)/p.length);let N=0,u=0;Object.values(x).forEach(s=>{if(s.length>=2){const a=[...s].sort((b,r)=>b.attempt_number-r.attempt_number),h=a[0].score,y=a[a.length-1].score;N+=y-h,u++}});const l=u>0?Math.round(N/u):0,d=Math.max(...p);return{averageScore:z,improvementRate:l,totalAttempts:o.length,bestScore:d,hasImprovement:u>0}})(),m=i>0?Math.round(n/i*100):0;return e.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-6 gap-4 mb-10",children:[e.jsx(g,{className:"col-span-1",children:e.jsxs(f,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(W,{className:"h-4 w-4 text-primary"}),e.jsx("span",{className:"text-xs text-muted-foreground font-medium",children:"Passed"})]}),e.jsx("div",{className:"text-2xl font-bold text-primary",children:n}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["of ",i," quizzes"]})]})}),e.jsx(g,{className:"col-span-1",children:e.jsxs(f,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(w,{className:"h-4 w-4 text-amber-500"}),e.jsx("span",{className:"text-xs text-muted-foreground font-medium",children:"Ready"})]}),e.jsx("div",{className:"text-2xl font-bold text-amber-600 dark:text-amber-400",children:c}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"unlocked quizzes"})]})}),e.jsx(g,{className:"col-span-1",children:e.jsxs(f,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(S,{className:"h-4 w-4 text-green-500"}),e.jsx("span",{className:"text-xs text-muted-foreground font-medium",children:"Completion"})]}),e.jsxs("div",{className:"text-2xl font-bold text-green-600 dark:text-green-400",children:[m,"%"]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"complete"})]})}),e.jsx(g,{className:"col-span-1",children:e.jsxs(f,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(E,{className:"h-4 w-4 text-blue-500"}),e.jsx("span",{className:"text-xs text-muted-foreground font-medium",children:"Avg Score"})]}
1),e.jsx("div",{className:"text-2xl font-bold text-blue-600 dark:text-blue-400",children:t.totalAttempts>0?`${t.averageScore}%`:"â"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:t.totalAttempts>0?`${t.totalAttempts} attempts`:"No attempts yet"})]})}),e.jsx(g,{className:"col-span-1",children:e.jsxs(f,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(L,{className:"h-4 w-4 text-purple-500"}),e.jsx("span",{className:"text-xs text-muted-foreground font-medium",children:"Best Score"})]}),e.jsx("div",{className:"text-2xl font-bold text-purple-600 dark:text-purple-400",children:t.totalAttempts>0?`${t.bestScore}%`:"â"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"highest achieved"})]})}),e.jsx(g,{className:"col-span-1",children:e.jsxs(f,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(D,{className:"h-4 w-4 text-emerald-500"}),e.jsx("span",{className:"text-xs text-muted-foreground font-medium",children:"Improvement"})]}),e.jsx("div",{className:`text-2xl font-bold ${t.improvementRate>0?"text-emerald-600 dark:text-emerald-400":t.improvementRate<0?"text-red-600 dark:text-red-400":"text-muted-foreground"}`,children:t.hasImprovement?`${t.improvementRate>0?"+":""}${t.improvementRate}%`:"â"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:t.hasImprovement?"avg per chapter":"Need 2+ attempts"})]})})]})}function me(){const{hasAccess:o,codeId:i,isLoading:n}=M(),[c,j]=v.useState({}),[t,m]=v.useState([]),[x,p]=v.useState(!0);if(v.useEffect(()=>{async function l(){if(!i){p(!1);return}try{const[d,s,a]=await Promise.all([_.from("chapter_badges").select("*").eq("code_id",i),_.from("chapter_exercises").select("*").eq("code_id",i),_.functions.invoke("get-quiz-history",{body:{codeId:i}})]),h=d.data,y=s.data,b={};if(h)for(const r of h){const A=y?.filter(R=>R.chapter_id===r.chapter_id)||[];b[r.chapter_id]={chapterId:r.chapter_id,readingCompleted:!!r.reading_completed_at,readingCompletedAt:r.reading_completed_at,practiceCompleted:!!r.practice_completed_at,practiceCompletedAt:r.practice_completed_at,exercisesCompleted:A.length,exercisesTotal:0,quizPassed:!!r.quiz_passed_at,quizPassedAt:r.quiz_passed_at,quizScore:r.quiz_score,badgeEarned:!!r.badge_earned_at,badgeEarnedAt:r.badge_earned_at}}j(b),a.data?.attempts&&m(a.data.attempts)}catch{}finally{p(!1)}}l()},[i]),!n&&!o)return e.jsx(O,{to:"/read",replace:!0});const z=Object.keys(C).length,N=Object.values(c).filter(l=>l.quizPassed).length,u=Object.values(c).filter(l=>l.readingCompleted&&!l.quizPassed).length;return e.jsxs(e.Fragment,{children:[e.jsx(Q,{title:"Quizzes",noIndex:!0}),e.jsxs(F,{title:"Quizzes",description:"Test your understanding and earn badges. Mark each chapter as complete to unlock its quiz.",icon:H,children:[e.jsx(Y,{attempts:t,totalQuizzes:z,passedQuizzes:N,availableQuizzes:u}),x?e.jsx("div",{className:"text-center py-12 text-muted-foreground",children:"Loading quizzes..."}):e.jsx("div",{className:"space-y-10",children:T.map(l=>{const d=l.lessons.filter(s=>$(s.id));return d.length===0?null:e.jsxs("div",{children:[e.jsxs("h2",{className:"text-lg font-semibold text-foreground mb-4 flex items-center gap-2",children:[l.title,e.jsxs("span",{className:"text-sm font-normal text-muted-foreground",children:["(",d.length," quizzes)"]})]}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4",children:d.map(s=>{const a=C[s.id],h=c[s.id]||null;return e.jsx(U,{chapterId:s.id,title:s.title,questionCount:a?.questions.length||4,progress:h},s.id)})})]},l.id)})}),e.jsx("div",{className:"mt-12 rounded-lg border border-border bg-muted/30 p-6",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx(S,{className:"h-6 w-6 text-primary shrink-0 mt-0.5"}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-foreground mb-2",children:"How Badges & Certificates Work"}),e.jsxs("p",{className:"text-sm text-muted-foreground mb-3",children:[e.jsx("strong",{children:"Badges:"})," Mark a lesson as complete to earn its badge."]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[e.jsx("strong",{children:"Certificates:"})," Pass the quiz with 70% or higher to download your certificate."]})]})]})})]})]})}export{me 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.