"use client"; import { useEffect, useRef } from "react"; import KatexRenderer from "@/components/math/KatexRenderer"; import type { VariableTermChoice } from "@/lib/engine/variable-types"; interface VariableChoiceAnswerFormProps { choices: VariableTermChoice[][]; selectedChoiceIds: (string | null)[]; activeTermIndex: number; pendingChoiceLabels: string[]; onSelectChoice: (termIndex: number, choiceId: string) => void; } export default function VariableChoiceAnswerForm({ choices, selectedChoiceIds, activeTermIndex, pendingChoiceLabels, onSelectChoice, }: VariableChoiceAnswerFormProps) { const firstChoiceRef = useRef(null); const activeChoices = [...choices[activeTermIndex]].sort( (a, b) => a.coefficient - b.coefficient, ); useEffect(() => { firstChoiceRef.current?.focus(); }, [activeTermIndex]); function getSelectedChoice(index: number) { const selectedChoiceId = selectedChoiceIds[index]; if (!selectedChoiceId) return null; return choices[index].find((choice) => choice.id === selectedChoiceId) ?? null; } return (

{activeTermIndex + 1}항을 고르세요.

    {selectedChoiceIds.map((choiceId, index) => { const selected = activeTermIndex === index; const selectedChoice = getSelectedChoice(index); const completed = choiceId !== null && selectedChoice !== null; const statusLabel = completed && selectedChoice ? `선택값 ${selectedChoice.latex}` : `원래 항 ${pendingChoiceLabels[index]}, 미선택`; return (
  1. {completed ? ( ) : ( )}
  2. ); })}
{activeChoices.map((choice, index) => { const selected = selectedChoiceIds[activeTermIndex] === choice.id; return ( ); })}
); }