vendor: 4,324 bytes, lines 1-6
1import{c as Re,r as i,aC as ye,ad as we,j as e,aK as Ce,ac as P,ae as D,aL as _e,af as M,aM as ee,ab as ke,ai as se,ag as Se,ah as Pe,a as k,ap as Ae,L as S,C as G,ar as Q,as as q,at as X,f as T,aN as O,B as _,ao as te,A as Ie,a6 as Ee,Y as Le,Z as Ge}from"./index-DMpD5zQ4.js";import{d as ae,a as Qe,g as Te,h as Oe}from"./useQuizzes-CS46BS59.js";import{B as W}from"./badge-bMO3_tW7.js";import{P as Me}from"./progress-DtsVQZGd.js";import{L as De}from"./label-CAB3OdUz.js";import{T as Fe}from"./trophy-CS8PaqVR.js";import{C as Z}from"./circle-x-DAvI2nFZ.js";import{C as J}from"./circle-check-NQcbTjaT.js";import{C as Be}from"./clock-DpH3fNh0.js";import{C as ze}from"./circle-alert-xoMAZWvJ.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const Ke=Re("RotateCcw",[["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"}]]);var F="Radio",[Ve,re]=se(F),[$e,Ue]=Ve(F),ne=i.forwardRef((r,n)=>{const{__scopeRadio:s,name:l,checked:a=!1,required:c,disabled:d,value:u="on",onCheck:x,form:f,...g}=r,[m,j]=i.useState(null),o=D(n,N=>j(N)),p=i.useRef(!1),b=m?f||!!m.closest("form"):!0;return e.jsxs($e,{scope:s,checked:a,disabled:d,children:[e.jsx(P.button,{type:"button",role:"radio","aria-checked":a,"data-state":de(a),"data-disabled":d?"":void 0,disabled:d,value:u,...g,ref:o,onClick:M(r.onClick,N=>{a||x==null||x(),b&&(p.current=N.isPropagationStopped(),p.current||N.stopPropagation())})}),b&&e.jsx(ce,{control:m,bubbles:!p.current,name:l,value:u,checked:a,required:c,disabled:d,form:f,style:{transform:"translateX(-100%)"}})]})});ne.displayName=F;var ie="RadioIndicator",oe=i.forwardRef((r,n)=>{const{__scopeRadio:s,forceMount:l,...a}=r,c=Ue(ie,s);return e.jsx(ke,{present:l||c.checked,children:e.jsx(P.span,{"data-state":de(c.checked),"data-disabled":c.disabled?"":void 0,...a,ref:n})})});oe.displayName=ie;var Ye="RadioBubbleInput",ce=i.forwardRef(({__scopeRadio:r,control:n,checked:s,bubbles:l=!0,...a},c)=>{const d=i.useRef(null),u=D(d,c),x=Se(s),f=Pe(n);return i.useEffect(()=>{const g=d.current;if(!g)return;const m=window.HTMLInputElement.prototype,o=Object.getOwnPropertyDescriptor(m,"checked").set;if(x!==s&&o){const p=new Event("click",{bubbles:l});o.call(g,s),g.dispatchEvent(p)}},[x,s,l]),e.jsx(P.input,{type:"radio","aria-hidden":!0,defaultChecked:s,...a,tabIndex:-1,ref:u,style:{...a.style,...f,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});ce.displayName=Ye;function de(r){return r?"checked":"unchecked"}var He=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],A="RadioGroup",[qe]=se(A,[ee,re]),le=ee(),ue=re(),[Xe,We]=qe(A),me=i.forwardRef((r,n)=>{const{__scopeRadioGroup:s,name:l,defaultValue:a,value:c,required:d=!1,disabled:u=!1,orientation:x,dir:f,loop:g=!0,onValueChange:m,...j}=r,o=le(s),p=ye(f),[b,N]=we({prop:c,defaultProp:a??null,onChange:m,caller:A});return e.jsx(Xe,{scope:s,name:l,required:d,disabled:u,value:b,onValueChange:N,children:e.jsx(Ce,{asChild:!0,...o,orientation:x,dir:p,loop:g,children:e.jsx(P.div,{role:"radiogroup","aria-required":d,"aria-orientation":x,"data-disabled":u?"":void 0,dir:p,...j,ref:n})})})});me.displayName=A;var pe="RadioGroupItem",xe=i.forwardRef((r,n)=>{const{__scopeRadioGroup:s,disabled:l,...a}=r,c=We(pe,s),d=c.disabled||l,u=le(s),x=ue(s),f=i.useRef(null),g=D(n,f),m=c.value===a.value,j=i.useRef(!1);return i.useEffect(()=>{const o=b=>{He.includes(b.key)&&(j.current=!0)},p=()=>j.current=!1;return document.addEventListener("keydown",o),document.addEventListener("keyup",p),()=>{document.removeEventListener("keydown",o),document.removeEventListener("keyup",p)}},[]),e.jsx(_e,{asChild:!0,...u,focusable:!d,active:m,children:e.jsx(ne,{disabled:d,required:c.required,checked:m,...x,...a,name:c.name,ref:g,onCheck:()=>c.onValueChange(a.value),onKeyDown:M(o=>{o.key==="Enter"&&o.preventDefault()}),onFocus:M(a.onFocus,()=>{var o;j.current&&((o=f.current)==null||o.click())})})})});xe.displayName=pe;var Ze="RadioGroupIndicator",fe=i.forwardRef((r,n)=>{const{__scopeRadioGroup:s,...l}=r,a=ue(s);return e.jsx(oe,{...a,...l,ref:n})});fe.displayName=Ze;var he=me,ge=xe,Je=fe;const je=i.forwardRef(({className:r,...n},s)=>e.jsx(he,{className:k("grid gap-2",r),...n,ref:s}));
6je.displayName=he.displayName;const ve=i.forwardRef(({className:r,...n},s)=>e.jsx(ge,{ref:s,className:k("aspect-square h-4 w-4 rounded-full border border-primary text-primary ring-offset-background focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",r),...n,children:e.jsx(Je,{className:"flex items-center justify-center",children:e.jsx(Ae,{className:"h-2.5 w-2.5 fill-current text-current"})})}));ve.displayName=ge.displayName;function es({quizId:r,onComplete:n}){var U;const{data:s,isLoading:l}=ae(r),{data:a}=Qe(r),c=Te(),d=Oe(),[u,x]=i.useState(null),[f,g]=i.useState(0),[m,j]=i.useState({}),[o,p]=i.useState(null),[b,N]=i.useState(!1),[C,B]=i.useState(null),I=a==null?void 0:a[0],E=a==null?void 0:a.some(t=>t.passed);i.useEffect(()=>{if(!u||!(s!=null&&s.time_limit_minutes)||o===null)return;if(o<=0){V();return}const t=setInterval(()=>{p(h=>h!==null?h-1:null)},1e3);return()=>clearInterval(t)},[u,o]);const z=async()=>{const t=await c.mutateAsync(r);x(t.id),j({}),g(0),N(!1),B(null),s!=null&&s.time_limit_minutes&&p(s.time_limit_minutes*60)},K=(t,h)=>{j(v=>({...v,[t]:h}))},V=i.useCallback(async()=>{if(!u||!(s!=null&&s.questions))return;const t=s.questions.map(v=>({questionId:v.id,selectedOptionId:m[v.id]||""})).filter(v=>v.selectedOptionId),h=await d.mutateAsync({attemptId:u,quizId:r,answers:t});B({score:h.score,passed:h.passed,correctOptions:h.correctOptions||[]}),N(!0),x(null),p(null),n==null||n(h.passed,h.score)},[u,s,m,d,r,n]),Ne=t=>{const h=Math.floor(t/60),v=t%60;return`${h}:${v.toString().padStart(2,"0")}`};if(l)return e.jsx("div",{className:"flex items-center justify-center p-8",children:e.jsx(S,{className:"h-8 w-8 animate-spin text-primary"})});if(!s)return null;const R=s.questions||[],y=R[f],$=Object.keys(m).length,be=R.length>0?$/R.length*100:0;return b&&C?e.jsxs(G,{children:[e.jsxs(Q,{className:"text-center",children:[e.jsx("div",{className:k("w-20 h-20 rounded-full mx-auto flex items-center justify-center mb-4",C.passed?"bg-green-500/10":"bg-destructive/10"),children:C.passed?e.jsx(Fe,{className:"h-10 w-10 text-green-500"}):e.jsx(Z,{className:"h-10 w-10 text-destructive"})}),e.jsx(q,{className:"text-2xl",children:C.passed?"Congratulations!":"Keep Trying!"}),e.jsxs(X,{children:["You scored ",C.score,"% (Passing: ",s.passing_score,"%)"]})]}),e.jsx(T,{className:"space-y-4",children:e.jsx("div",{className:"space-y-4",children:R.map((t,h)=>{var H;const v=m[t.id],L=C.correctOptions.find(w=>w.question_id===t.id),Y=v===(L==null?void 0:L.id);return e.jsxs("div",{className:"border rounded-lg p-4",children:[e.jsxs("div",{className:"flex items-start gap-3 mb-3",children:[Y?e.jsx(J,{className:"h-5 w-5 text-green-500 mt-0.5 flex-shrink-0"}):e.jsx(Z,{className:"h-5 w-5 text-destructive mt-0.5 flex-shrink-0"}),e.jsxs("div",{children:[e.jsxs("p",{className:"font-medium",children:["Q",h+1,": ",t.question_text]}),t.explanation&&!Y&&e.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:[e.jsx("span",{className:"font-medium",children:"Explanation:"})," ",t.explanation]})]})]}),e.jsx("div",{className:"ml-8 space-y-1",children:(H=t.options)==null?void 0:H.map(w=>e.jsxs("div",{className:k("px-3 py-1.5 rounded text-sm",w.is_correct&&"bg-green-500/10 text-green-700 dark:text-green-400",w.id===v&&!w.is_correct&&"bg-destructive/10 text-destructive"),children:[w.option_text,w.is_correct&&e.jsx("span",{className:"ml-2",children:"(Correct)"})]},w.id))})]},t.id)})})}),e.jsx(O,{children:e.jsxs(_,{onClick:z,className:"w-full",children:[e.jsx(Ke,{className:"h-4 w-4 mr-2"}),"Try Again"]})})]}):u&&y?e.jsxs(G,{children:[e.jsxs(Q,{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs(W,{variant:"secondary",children:["Question ",f+1," of ",R.length]}),o!==null&&e.jsxs(W,{variant:o<60?"destructive":"outline",className:"gap-1",children:[e.jsx(Be,{className:"h-3 w-3"}),Ne(o)]})]}),e.jsx(Me,{value:be,className:"h-2"})]}),e.jsx(T,{className:"space-y-6",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium mb-4",children:y.question_text}),e.jsx(je,{value:m[y.id]||"",onValueChange:t=>K(y.id,t),className:"space-y-3",children:(U=y.options)==null?void 0:U.map(t=>e.jsxs("div",{className:k("flex items-center space-x-3 p-4 rounded-lg border cursor-pointer transition-colors",m[y.id]===t.id?"border-primary bg-primary/5":"hover:bg-muted"),onClick:()=>K(y.id,t.id),children:[e.jsx(ve,{value:t.id,id:t.id}
6),e.jsx(De,{htmlFor:t.id,className:"flex-1 cursor-pointer",children:t.option_text})]},t.id))})]})}),e.jsxs(O,{className:"flex justify-between gap-4",children:[e.jsxs(_,{variant:"outline",onClick:()=>g(t=>t-1),disabled:f===0,children:[e.jsx(te,{className:"h-4 w-4 mr-2"}),"Previous"]}),f<R.length-1?e.jsxs(_,{onClick:()=>g(t=>t+1),disabled:!m[y.id],children:["Next",e.jsx(Ie,{className:"h-4 w-4 ml-2"})]}):e.jsx(_,{onClick:V,disabled:$<R.length||d.isPending,className:"hero-gradient text-primary-foreground",children:d.isPending?e.jsx(S,{className:"h-4 w-4 animate-spin"}):e.jsx(e.Fragment,{children:"Submit Quiz"})})]})]}):e.jsxs(G,{children:[e.jsxs(Q,{className:"text-center",children:[e.jsx(q,{children:s.title}),s.description&&e.jsx(X,{children:s.description})]}),e.jsxs(T,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-center",children:[e.jsxs("div",{className:"p-4 rounded-lg bg-muted",children:[e.jsx("p",{className:"text-2xl font-bold",children:R.length}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Questions"})]}),e.jsxs("div",{className:"p-4 rounded-lg bg-muted",children:[e.jsxs("p",{className:"text-2xl font-bold",children:[s.passing_score,"%"]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Passing Score"})]}),s.time_limit_minutes&&e.jsxs("div",{className:"p-4 rounded-lg bg-muted col-span-2",children:[e.jsxs("p",{className:"text-2xl font-bold",children:[s.time_limit_minutes," min"]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Time Limit"})]})]}),E&&e.jsxs("div",{className:"flex items-center gap-2 p-3 rounded-lg bg-green-500/10 text-green-700 dark:text-green-400",children:[e.jsx(J,{className:"h-5 w-5"}),e.jsx("span",{children:"You've already passed this quiz!"})]}),I&&!E&&e.jsxs("div",{className:"flex items-center gap-2 p-3 rounded-lg bg-muted",children:[e.jsx(ze,{className:"h-5 w-5 text-muted-foreground"}),e.jsxs("span",{className:"text-sm",children:["Last attempt: ",I.score,"% (",I.passed?"Passed":"Failed",")"]})]})]}),e.jsx(O,{children:e.jsx(_,{onClick:z,className:"w-full hero-gradient text-primary-foreground",disabled:c.isPending,children:c.isPending?e.jsx(S,{className:"h-4 w-4 animate-spin"}):E?"Retake Quiz":"Start Quiz"})})]})}function us(){const{quizId:r}=Ee(),n=Le(),{user:s,loading:l}=Ge(),{data:a,isLoading:c}=ae(r||"");return i.useEffect(()=>{!l&&!s&&n("/login")},[s,l,n]),l||c?e.jsx("div",{className:"min-h-screen flex items-center justify-center",children:e.jsx(S,{className:"h-8 w-8 animate-spin text-primary"})}):!a||!s?null:e.jsx("div",{className:"min-h-screen pt-24 pb-12 bg-background",children:e.jsxs("div",{className:"max-w-2xl mx-auto px-4",children:[e.jsxs(_,{variant:"ghost",onClick:()=>n(-1),className:"mb-6",children:[e.jsx(te,{className:"h-4 w-4 mr-2"}),"Back to Course"]}),e.jsx(es,{quizId:r,onComplete:(d,u)=>{console.log(`Quiz completed: ${u}% (${d?"Passed":"Failed"})`)}})]})})}export{us 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.