"use client"; import { useEffect, useRef } from "react"; import AnswerResultLine from "@/components/game/AnswerResultLine"; import type { VariableGradeResult, VariableParenthesisProblem, VariableParenthesisTerm, } from "@/lib/engine/variable-types"; import { formatVariableTermLatex } from "@/lib/engine/variable-parenthesis"; interface VariableFeedbackPanelProps { result: VariableGradeResult; problem: VariableParenthesisProblem; isLastProblem: boolean; onNext: () => void; } function formatSignedNumber(value: number) { return value < 0 ? `(${value})` : `${value}`; } function formatSignedTerm(term: VariableParenthesisTerm, sign: 1 | -1) { const coefficient = term.coefficient * sign; return formatVariableTermLatex({ ...term, coefficient }); } export default function VariableFeedbackPanel({ result, problem, isLastProblem, onNext, }: VariableFeedbackPanelProps) { const nextButtonRef = useRef(null); const signedTerms = [ formatSignedTerm(problem.firstTerm, 1), formatSignedTerm(problem.secondTerm, problem.operator === "-" ? -1 : 1), ] as const; const feedbackItems = signedTerms.map((termLatex, index) => { const termIndex = index as 0 | 1; const userAnswer = result.userAnswer[termIndex]; const correctAnswer = result.correctAnswer[termIndex]; return { formulaLatex: `${formatSignedNumber(problem.multiplier)}\\times ${termLatex}`, userAnswerLatex: userAnswer?.latex ?? "?", correctAnswerLatex: correctAnswer.latex, correct: userAnswer?.coefficient === correctAnswer.coefficient, }; }); useEffect(() => { nextButtonRef.current?.focus(); }, []); return (

{result.correct ? "정답입니다." : "오답입니다."}

); }