"use client" import * as React from "react" import { Input } from "@/components/ui/input" import { cn } from "@/lib/utils" import { blankIdForIndex, parseFillBlankStem, type ExamLockStemMedia, } from "./exam-lock-delivery-types" import { ExamLockQuestionIndex, ExamLockQuestionResponseLayout } from "./exam-lock-question-stem" export interface ExamLockFillBlankQuestionProps { questionNumber: number questionId: string stem: string stemMedia?: ExamLockStemMedia blankIds?: readonly string[] value: Record onValueChange: (value: Record) => void formatHint?: string className?: string } export function ExamLockFillBlankQuestion({ questionNumber, questionId, stem, stemMedia, blankIds, value, onValueChange, formatHint = "Type the missing word or phrase in each blank.", className, }: ExamLockFillBlankQuestionProps) { const headingId = `${questionId}-heading` const parts = React.useMemo(() => parseFillBlankStem(stem), [stem]) const setBlank = React.useCallback( (blankId: string, next: string) => { onValueChange({ ...value, [blankId]: next }) }, [onValueChange, value], ) return (

{" "} {parts.map((part, index) => { if (part.kind === "text") { return ( {part.text} ) } const blankId = blankIdForIndex(part.blankIndex, blankIds) const inputId = `${questionId}-${blankId}` return ( setBlank(blankId, event.target.value)} aria-label={`Blank ${part.blankIndex + 1}`} className="inline-block h-10 min-w-[8rem] max-w-full border-control-3 bg-background px-2 text-base font-medium md:text-lg" /> ) })}

{formatHint}

) }