1import{c as B,u as I,r as i,j as e,L as P,B as z,a as f}from"./index-DqcvASXh.js";const T=()=>{var C;const{id:g}=B(),d=I(),x=localStorage.getItem("token")||"",[A,_]=i.useState(!0),[r,$]=i.useState(null),[a,b]=i.useState(0),[o,j]=i.useState([]),[u,h]=i.useState([]),[y,N]=i.useState(!1);i.useEffect(()=>{(async()=>{var t,n,p;if(!g||!x){d("/login");return}try{const c=await f.getCourse(g);if(!c.success||!((t=c.data)!=null&&t.exam)){d("/student/dashboard");return}const m=c.data.exam,S=await f.getExamResultByExamId(m._id,x);if(S.success&&((n=S.data)!=null&&n.passed)){d(`/student/exam-result/${m._id}`);return}$(m);const E=((p=m.questions)==null?void 0:p.length)||0;j(new Array(E).fill(-1)),h(new Array(E).fill(!1))}catch{d("/student/dashboard")}finally{_(!1)}})()},[g,x,d]);const w=i.useMemo(()=>{var s;return(s=r==null?void 0:r.questions)==null?void 0:s[a]},[r,a]),l=((C=r==null?void 0:r.questions)==null?void 0:C.length)||0,v=o.filter(s=>s>=0).length,k=o.reduce((s,t,n)=>s+(t<0&&u[n]?1:0),0),Q=Math.max(0,l-v-k),q=s=>{const t=[...o];t[a]=s,j(t);const n=[...u];n[a]=!1,h(n)},L=()=>{const s=[...u];s[a]=!0,h(s),a<l-1&&b(t=>t+1)},M=()=>{if(o[a]<0){const s=[...u];s[a]=!0,h(s)}b(s=>Math.min(l-1,s+1))},R=async()=>{if(!(!(r!=null&&r._id)||!x)){N(!0);try{(await f.submitExam(r._id,o,x)).success&&d(`/student/exam-result/${r._id}`)}catch(s){alert(s.message||"Failed to submit exam. Please try again.")}finally{N(!1)}}};return A?e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background-light",role:"status","aria-live":"polite","aria-label":"Loading exam",children:e.jsx("div",{className:"animate-spin rounded-full h-12 w-12 border-b-2 border-primary"})}):!r||l===0?e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background-light",children:e.jsxs("div",{className:"text-center bg-white p-10 rounded-xl border border-slate-200",children:[e.jsx("span",{className:"material-icons text-5xl text-slate-300",children:"assignment"}),e.jsx("h2",{className:"text-2xl font-bold text-slate-700 mt-2",children:"No Exam Available"}),e.jsx("p",{className:"text-slate-500 mt-2",children:"This course does not have an exam yet."}),e.jsxs(P,{to:"/student/dashboard",className:"inline-flex mt-5 items-center gap-2 bg-primary text-white px-4 py-2 rounded-lg",children:[e.jsx("span",{className:"material-icons text-sm",children:"arrow_back"}),"Back to Dashboard"]})]})}):e.jsxs("div",{className:"font-body bg-background-light text-slate-900 min-h-screen relative flex flex-col",role:"main","aria-label":"Student exam page",children:[e.jsx("header",{className:"bg-white border-b border-slate-200 sticky top-0 z-40",children:e.jsx("div",{className:"max-w-7xl mx-auto px-6 h-20 flex items-center justify-between",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg flex items-center justify-center text-white shrink-0",children:e.jsx(z,{sizeClassName:"w-16 h-16",containerClassName:"rounded",imageClassName:"object-contain"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"font-display font-bold text-xl md:text-2xl text-navy-custom leading-none",children:"Final Assessment"}),e.jsx("p",{className:"text-sm text-slate-500 mt-1 font-medium",children:r.title})]})]})})}),e.jsxs("main",{className:"flex-1 w-full max-w-4xl mx-auto px-6 py-8 md:py-12 flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("span",{className:"text-sm font-semibold text-slate-500 uppercase tracking-widest","aria-live":"polite",children:["Question ",a+1," of ",l]}),e.jsx("span",{className:"px-3 py-1 bg-blue-50 text-blue-700 text-xs font-bold rounded-full border border-blue-100",children:"Multiple Choice"})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3 mb-6",children:[e.jsxs("div",{className:"rounded-xl border border-emerald-200 bg-emerald-50 px-3 py-2",children:[e.jsx("p",{className:"text-xs font-semibold text-emerald-700 uppercase",children:"Answered"}),e.jsx("p",{className:"text-lg font-bold text-emerald-800",children:v})]}),e.jsxs("div",{className:"rounded-xl border border-amber-200 bg-amber-50 px-3 py-2",children:[e.jsx("p",{className:"text-xs font-semibold text-amber-700 uppercase",children:"Skipped"}),e.jsx("p",{className:"text-lg font-bold text-amber-800",children:k})]}),e.jsxs("div",{className:"rounded-xl border border-slate-200 bg-slate-50 px-3 py-2",children:[e.jsx("p",{className:"text-xs font-semibold text-slate-600 uppercase",children:"Unanswered"}),e.jsx("p",{className:"text-lg font-bold text-slate-700",children:Q})]})]}),e.jsxs("div",{className:"bg-white rounded-2xl shadow-sm border border-slate-200 p-6 md:p-10 mb-8 flex-1",children:[e.jsx("h2",{className:"font-display font-bold text-2xl md:text-3xl text-slate-900 leading-tight mb-8",children:w.question}),e.jsx("div",{className:"space-y-4",children:(w.options||[]).map((s,t)=>e.jsxs("label",{className:"block cursor-pointer group",children:[e.jsx("input",{className:"custom-radio sr-only peer",name:`answer-${a}`,type:"radio",checked:o[a]===t,onChange:()=>q(t)}),e.jsxs("div",{className:"flex items-center p-4 md:p-5 rounded-xl border-2 border-slate-200 hover:border-navy-custom/50 transition-all peer-checked:border-navy-custom peer-checked:bg-indigo-50",children:[e.jsx("div",{className:"relative w-6 h-6 rounded-full border-2 border-slate-300 mr-4 shrink-0 transition-all peer-checked:border-navy-custom peer-checked:bg-white",children:e.jsx("span",{className:"absolute inset-1 rounded-full bg-navy-custom opacity-0 peer-checked:opacity-100 transition-opacity"})}),e.jsx("span",{className:"font-bold font-display text-lg text-slate-400 mr-4 w-6 peer-checked:text-navy-custom",children:String.fromCharCode(65+t)}),e.jsx("span",{className:"text-lg text-slate-700 font-medium peer-checked:text-navy-custom",children:s})]})]},`${a}-${t}`))})]}),e.jsxs("div",{className:"bg-white rounded-2xl border border-slate-200 p-4 mb-8",children:[e.jsx("p",{className:"text-xs font-semibold text-slate-500 uppercase tracking-wider mb-3",children:"Question Navigator"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:Array.from({length:l}).map((s,t)=>{const n=t===a,p=o[t]>=0,c=!p&&u[t],m=p?"bg-emerald-100 text-emerald-800 border-emerald-300":c?"bg-amber-100 text-amber-800 border-amber-300":"bg-slate-100 text-slate-600 border-slate-300";return e.jsx("button",{type:"button",onClick:()=>b(t),className:`w-9 h-9 rounded-lg border text-sm font-semibold transition-colors ${m} ${n?"ring-2 ring-primary/40":""}`,"aria-label":`Go to question ${t+1}`,children:t+1},`nav-${t}`)})}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-4 text-xs text-slate-600",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-full bg-emerald-500"}),"Answered"]}),e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-full bg-amber-500"}
1),"Skipped"]}),e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-full bg-slate-400"}),"Unanswered"]})]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("button",{onClick:()=>b(s=>Math.max(0,s-1)),disabled:a===0,className:"px-6 py-3 rounded-xl border border-navy-custom text-navy-custom font-semibold hover:bg-navy-custom/5 transition-colors flex items-center gap-2 min-h-44px disabled:opacity-50",children:[e.jsx("span",{className:"material-icons-outlined",children:"arrow_back"}),"Previous"]}),e.jsxs("div",{className:"flex items-center gap-3",children:[a<l-1&&e.jsx("button",{onClick:L,type:"button",className:"px-6 py-3 rounded-xl border border-amber-300 text-amber-700 font-semibold hover:bg-amber-50 transition-colors min-h-44px",children:"Skip for Now"}),a<l-1?e.jsxs("button",{onClick:M,className:"px-8 py-3 rounded-xl bg-navy-custom text-white font-semibold hover:bg-navy-light shadow-lg shadow-navy-custom/20 transition-all flex items-center gap-2 min-h-44px",children:["Next Question",e.jsx("span",{className:"material-icons-outlined",children:"arrow_forward"})]}):e.jsx("button",{onClick:R,disabled:y,className:"px-8 py-3 rounded-xl bg-primary text-white font-semibold hover:bg-primary/90 shadow-lg shadow-primary/20 transition-all flex items-center gap-2 min-h-44px disabled:opacity-50",children:y?"Submitting...":"Submit Exam"})]})]})]})]})};export{T 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.