"use client" import { Plus, Trash2 } from "lucide-react" import { Button } from "@/shared/components/ui/button" import { Input } from "@/shared/components/ui/input" import { Label } from "@/shared/components/ui/label" import { Checkbox } from "@/shared/components/ui/checkbox" import type { ExamNode } from "./assembly/selected-question-list" import type { EditableQuestionContent } from "./exam-form-types" type QuestionOptionsEditorProps = { selectedQuestionId: string selectedContent: EditableQuestionContent questionType: string updatePreviewQuestionNode: (questionId: string, updater: (node: ExamNode) => ExamNode) => void parseEditableContent: (raw: unknown) => EditableQuestionContent } export function QuestionOptionsEditor({ selectedQuestionId, selectedContent, questionType, updatePreviewQuestionNode, parseEditableContent, }: QuestionOptionsEditorProps) { return (
{selectedContent.options.map((option, optionIndex) => (
{ const nextId = event.target.value updatePreviewQuestionNode(selectedQuestionId, (node) => { if (!node.question) return node const current = parseEditableContent(node.question.content) const options = current.options.map((item, idx) => idx === optionIndex ? { ...item, id: nextId } : item) return { ...node, question: { ...node.question, content: { ...current, options } } } }) }} /> { const text = event.target.value updatePreviewQuestionNode(selectedQuestionId, (node) => { if (!node.question) return node const current = parseEditableContent(node.question.content) const options = current.options.map((item, idx) => idx === optionIndex ? { ...item, text } : item) return { ...node, question: { ...node.question, content: { ...current, options } } } }) }} />
{ const isCorrect = Boolean(checked) updatePreviewQuestionNode(selectedQuestionId, (node) => { if (!node.question) return node const current = parseEditableContent(node.question.content) const options = current.options.map((item, idx) => { if (idx !== optionIndex) { if (questionType === "single_choice") { return { ...item, isCorrect: false } } return item } return { ...item, isCorrect } }) return { ...node, question: { ...node.question, content: { ...current, options } } } }) }} /> 正确
))}
) }