import { useState } from "react"; import type { GameQuestion, AnswerResult } from "@lila/shared"; import { OptionButton } from "./OptionButton"; type QuestionCardProps = { question: GameQuestion; questionNumber: number; totalQuestions: number; currentResult: AnswerResult | null; onAnswer: (optionId: number) => void; onNext: () => void; }; export const QuestionCard = ({ question, questionNumber, totalQuestions, currentResult, onAnswer, onNext, }: QuestionCardProps) => { const [selectedOptionId, setSelectedOptionId] = useState(null); const getOptionState = (optionId: number) => { if (currentResult) { if (optionId === currentResult.correctOptionId) return "correct" as const; if (optionId === currentResult.selectedOptionId) return "wrong" as const; return "disabled" as const; } if (optionId === selectedOptionId) return "selected" as const; return "idle" as const; }; const handleSelect = (optionId: number) => { if (currentResult) return; setSelectedOptionId(optionId); }; const handleSubmit = () => { if (selectedOptionId === null) return; onAnswer(selectedOptionId); }; const handleNext = () => { setSelectedOptionId(null); onNext(); }; return (
Round {questionNumber}/{totalQuestions}
{currentResult ? "Checked" : selectedOptionId !== null ? "Ready" : "Pick one"}

{question.prompt}

{question.gloss && (

{question.gloss}

)}
{question.options.map((option) => ( handleSelect(option.optionId)} /> ))}
{!currentResult && selectedOptionId !== null && ( )} {currentResult && ( )}
); };