"use client"; import { useEffect, useRef } from "react"; import AnswerResultLine from "@/components/game/AnswerResultLine"; import type { VariableGradeResult, VariableParenthesisProblem, } 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}`; } export default function VariableFeedbackPanel({ result, problem, isLastProblem, onNext, }: VariableFeedbackPanelProps) { const nextButtonRef = useRef(null); const signedTerms = problem.terms.map((term, index) => formatVariableTermLatex({ ...term, coefficient: index > 0 && problem.operators[index - 1] === "-" ? -term.coefficient : term.coefficient, }), ); const feedbackItems = signedTerms.map((termLatex, index) => { const userAnswer = result.userAnswer[index]; const correctAnswer = result.correctAnswer[index]; 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 ? "정답입니다." : "오답입니다."}

); }