"use client"; import Link from "next/link"; import { useEffect, useRef } from "react"; import AnswerResultLine from "@/components/game/AnswerResultLine"; import KatexRenderer from "@/components/math/KatexRenderer"; import type { DistributedVariableTerm, VariableGradeResult, VariableParenthesisProblem, } from "@/lib/engine/variable-types"; import { formatVariableExpressionLatex } from "@/lib/engine/variable-parenthesis"; interface VariableScoreSummaryProps { correctCount: number; totalCount: number; problems: VariableParenthesisProblem[]; results: (VariableGradeResult | null)[]; onRestart: () => void; } function renderTermPair( terms: (DistributedVariableTerm | null)[], comparisonTerms: (DistributedVariableTerm | null)[], mode: "user" | "correct", ) { return ( {terms.map((term, index) => { if (!term) { return ( ? ); } const correct = term.coefficient === comparisonTerms[index]?.coefficient; const className = mode === "user" ? correct ? undefined : "text-red-700" : correct ? undefined : "font-bold text-blue-700"; const operator = term.coefficient < 0 ? "-" : "+"; const displayLatex = index === 0 ? term.latex : `${operator} ${term.latex.replace(/^-/, "")}`; return ( ); })} ); } export default function VariableScoreSummary({ correctCount, totalCount, problems, results, onRestart, }: VariableScoreSummaryProps) { const restartButtonRef = useRef(null); const solvedItems = problems .map((problem, index) => ({ problem, result: results[index], })) .filter( ( item, ): item is { problem: VariableParenthesisProblem; result: VariableGradeResult; } => item.result !== null, ); useEffect(() => { restartButtonRef.current?.focus(); }, []); return (

미지수 괄호 풀기

풀이 결과

{correctCount} / {totalCount} 정답

    {solvedItems.map(({ problem, result }, index) => ( result.userAnswer[termIndex] ?? term, ), ])} correctAnswerLatex={problem.latexAfter} correct={result.correct} userAnswerContent={renderTermPair( result.userAnswer, result.correctAnswer, "user", )} correctAnswerContent={renderTermPair( result.correctAnswer, result.userAnswer, "correct", )} prefix={ {index + 1}. } /> ))}
처음으로
); }