"use client"; import { useSortable } from "@dnd-kit/sortable"; import { CSS } from "@dnd-kit/utilities"; import { Button, Card, CardContent, DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, Input, Label, Switch, } from "@mdxui/primitives"; import { cn } from "@mdxui/primitives/lib/utils"; import { Copy, GripVertical, MoreVertical, Trash2 } from "lucide-react"; import { QuestionPreview } from "./question-preview"; import type { SurveyQuestion } from "./types"; interface QuestionItemProps { question: SurveyQuestion; index: number; onUpdate: (questionId: string, updates: Partial) => void; onDelete: (questionId: string) => void; onDuplicate: (questionId: string) => void; onSelect?: () => void; readOnly: boolean; } export function QuestionItem({ question, index, onUpdate, onDelete, onDuplicate, onSelect: _onSelect, readOnly, }: QuestionItemProps) { const { attributes, listeners, setNodeRef, transform, transition, isDragging, } = useSortable({ id: question.id, disabled: readOnly, }); const style = { transform: CSS.Transform.toString(transform), transition, }; return (
{!readOnly && ( )}
{index + 1}
onUpdate(question.id, { title: e.target.value }) } placeholder="Question title" className="font-medium" disabled={readOnly} /> onUpdate(question.id, { description: e.target.value }) } placeholder="Description (optional)" className="text-sm text-muted-foreground" disabled={readOnly} />
onUpdate(question.id, { required: checked }) } disabled={readOnly} />
{!readOnly && ( onDuplicate(question.id)} > Duplicate onDelete(question.id)} className="text-destructive" > Delete )}
); }