'use client'; import { Reorder } from 'motion/react'; import { useEffect, useRef, useState } from 'react'; import { ListChecks, Plus } from 'lucide-react'; import { useI18n } from '@/lib/hooks/use-i18n'; import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'; import { AddQuestionMenu } from './AddQuestionMenu'; import { QuestionCard } from './QuestionCard'; import { reorderQuizQuestions, useQuizSurfaceLifecycle, useResolvedQuizContent, } from './use-quiz-surface'; /** * The quiz `SceneEditorSurface` center component — a single-column accordion * of question cards. Self-contained: owns its expansion state, seeds/tears * down the quiz-edit session, and dispatches every edit through the bound * mutations in `use-quiz-surface`. Renders inside the EditShell's studio-frame * card (full height, own scroll) and contributes no canvas-style selection. * * "Add question" sits after the question list, keeping this structured * editor's primary action in the content flow instead of the slide toolbar. */ export function QuizForm() { useQuizSurfaceLifecycle(); const content = useResolvedQuizContent(); const questions = content.questions; const [expandedId, setExpandedId] = useState(null); // Auto-expand a question added DURING the session: when exactly one new id // appears since the last render, open it (and collapse whatever was open). // `prevIds` is seeded null and baselined on the first run so the questions // already present at mount don't count as "added" (no surprise expansion). const prevIds = useRef(null); useEffect(() => { const ids = questions.map((q) => q.id); if (prevIds.current === null) { prevIds.current = ids; return; } const added = ids.filter((id) => !prevIds.current!.includes(id)); if (added.length === 1) setExpandedId(added[0]); prevIds.current = ids; }, [questions]); return (
{questions.length === 0 ? ( ) : ( q.id)} onReorder={reorderQuizQuestions} className="m-0 flex list-none flex-col gap-2.5 p-0" > {questions.map((q, index) => ( setExpandedId((id) => (id === q.id ? null : q.id))} /> ))} )}
); } function AddQuestionButton() { const { t } = useI18n(); return ( ); } function EmptyState() { const { t } = useI18n(); return (

{t('edit.quiz.empty')}

{t('edit.quiz.emptyHint')}

); }