"use client"; import { useState } from "react"; interface QuizQuestionProps { question: { id: string; text: string; options: string[]; correctAnswer?: number; }; onAnswer: (selectedIndex: number, isCorrect: boolean) => void; } export default function QuizQuestion({ question, onAnswer }: QuizQuestionProps) { const [selectedOption, setSelectedOption] = useState(null); const [submitted, setSubmitted] = useState(false); const handleSubmit = () => { if (selectedOption === null) return; const isCorrect = question.correctAnswer !== undefined ? selectedOption === question.correctAnswer : false; setSubmitted(true); onAnswer(selectedOption, isCorrect); }; const getOptionStyle = (index: number) => { if (!submitted) { return selectedOption === index ? "bg-yellow-500/20 border-yellow-500" : "bg-gray-800 border-gray-700 hover:border-gray-600"; } if (question.correctAnswer !== undefined) { if (index === question.correctAnswer) { return "bg-green-500/20 border-green-500"; } if (index === selectedOption && selectedOption !== question.correctAnswer) { return "bg-red-500/20 border-red-500"; } } return "bg-gray-800 border-gray-700 opacity-50"; }; const getOptionIcon = (index: number) => { if (!submitted) return null; if (question.correctAnswer !== undefined) { if (index === question.correctAnswer) { return ( ); } if (index === selectedOption && selectedOption !== question.correctAnswer) { return ( ); } } return null; }; return (

{question.text}

Select one answer

{question.options.map((option, index) => ( ))}
{submitted ? (

{question.correctAnswer !== undefined && selectedOption === question.correctAnswer ? "Correct! Well done!" : "Incorrect. Try again next time!"}

) : ( )}
); }