"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[], VariableTermChoice[]]; selectedChoiceIds: [string | null, string | null]; activeTermIndex: 0 | 1; pendingChoiceLabels: [string, string]; onSelectChoice: (termIndex: 0 | 1, 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: 0 | 1) { const selectedChoiceId = selectedChoiceIds[index]; if (!selectedChoiceId) return null; return choices[index].find((choice) => choice.id === selectedChoiceId) ?? null; } return (

{activeTermIndex === 0 ? "첫째 항" : "둘째 항"}을 고르세요.

    {selectedChoiceIds.map((choiceId, index) => { const selected = activeTermIndex === index; const selectedChoice = getSelectedChoice(index as 0 | 1); 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 ( ); })}
); }