"use client" import * as React from "react" import { Button } from "@/components/ui/button" import { Shortcut } from "@/components/ui/dropdown-menu" import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group" import { Tip } from "@/components/ui/tip" import { cn } from "@/lib/utils" import type { ExamLockStemMedia } from "./exam-lock-delivery-types" import { EXAM_OPTION_LABEL_CLASS, EXAM_OPTION_LETTERS, EXAM_OPTION_ROW, examOptionIndexClass, } from "./exam-lock-option-primitives" import { ExamLockQuestionStem, ExamLockQuestionResponseLayout } from "./exam-lock-question-stem" export interface ExamLockMcqQuestionProps { questionNumber: number questionId: string stem: string stemMedia?: ExamLockStemMedia options: readonly string[] value: string onValueChange: (value: string) => void eliminatedOptions?: readonly string[] onToggleEliminated?: (option: string) => void allowEliminate?: boolean allowClear?: boolean shortcutsDisabled?: boolean className?: string } export function ExamLockMcqQuestion({ questionNumber, questionId, stem, stemMedia, options, value, onValueChange, eliminatedOptions = [], onToggleEliminated, allowEliminate = true, allowClear = true, shortcutsDisabled = false, className, }: ExamLockMcqQuestionProps) { const headingId = `${questionId}-heading` const eliminatedSet = React.useMemo(() => new Set(eliminatedOptions), [eliminatedOptions]) const selectByIndex = React.useCallback( (index: number) => { const option = options[index] if (!option) return if (allowClear && value === option) { onValueChange("") return } onValueChange(option) }, [allowClear, options, onValueChange, value], ) const clearAnswer = React.useCallback(() => { onValueChange("") }, [onValueChange]) return (
{options.map((option, index) => { const letter = EXAM_OPTION_LETTERS[index] if (!letter) return null return ( selectByIndex(index)} /> ) })} {options.map((option, index) => { const letter = EXAM_OPTION_LETTERS[index] ?? `${index + 1}` const optionId = `${questionId}-opt-${index}` const selected = value === option const eliminated = eliminatedSet.has(option) const ruleOutLabel = eliminated ? `Restore option ${letter}` : `Rule out option ${letter}` return (