"use client"; import { useState } from "react"; import Link from "next/link"; import { useParams } from "next/navigation"; import ProgressBar from "@/components/ProgressBar"; import { getPracticeBySlug, mockPracticeModules } from "@/lib/data/mockPractice"; export default function PracticeExercisePage() { const params = useParams<{ slug: string }>(); const practiceModule = getPracticeBySlug(params.slug); const [index, setIndex] = useState(0); const [score, setScore] = useState(0); const [finished, setFinished] = useState(false); const [selected, setSelected] = useState(null); if (!practiceModule) { return (

Practice module not found

The requested practice slug does not exist in mock data.

Back to practice
); } if (!practiceModule.isInteractive || !practiceModule.questions?.length) { return (

{practiceModule.title}

This practice module is scaffolded and will be enabled in a later iteration.

); } const total = practiceModule.questions.length; const current = practiceModule.questions[index]; const progress = Math.round((index / total) * 100); const pick = (choiceIndex: number) => { if (selected !== null) return; setSelected(choiceIndex); if (choiceIndex === current.answerIndex) { setScore((value) => value + 1); } }; const next = () => { if (index + 1 >= total) { setFinished(true); return; } setIndex((value) => value + 1); setSelected(null); }; const restart = () => { setIndex(0); setScore(0); setSelected(null); setFinished(false); }; if (finished) { return (

Exercise complete

Final score: {score}/{total}

); } return (

Practice and Exercises

Master Your Skills

{mockPracticeModules.map((module, moduleIndex) => { const isActive = module.slug === practiceModule.slug; return (
{moduleIndex === 0 ? "A/" : moduleIndex === 1 ? "[]" : "O"}

{module.title}

{module.description}

); })}

Question {index + 1} / {total}

Score: {score}/{total}

Spanish Term

{current.prompt.replace("Spanish term: ", "")}

{current.choices.map((choice, choiceIndex) => { const isPicked = selected === choiceIndex; const isCorrect = choiceIndex === current.answerIndex; const stateClass = selected === null ? "border-slate-300 hover:bg-slate-50" : isCorrect ? "border-[#2f9d73] bg-[#edf9f4]" : isPicked ? "border-[#bf3c5f] bg-[#fff1f4]" : "border-slate-300"; return ( ); })}
); }