"use client" import type { ExamNode } from "./selected-question-list" type ChoiceOption = { id: string text: string } type QuestionContent = { text?: string options?: ChoiceOption[] } type ExamPaperPreviewProps = { title: string subject: string grade: string durationMin: number totalScore: number nodes: ExamNode[] } export function ExamPaperPreview({ title, subject, grade, durationMin, totalScore, nodes }: ExamPaperPreviewProps) { // Helper to flatten questions for continuous numbering let questionCounter = 0 const parseContent = (raw: unknown): QuestionContent => { if (raw && typeof raw === "object") return raw as QuestionContent if (typeof raw === "string") { try { const parsed = JSON.parse(raw) as unknown if (parsed && typeof parsed === "object") return parsed as QuestionContent return { text: raw } } catch { return { text: raw } } } return {} } const renderNode = (node: ExamNode, depth: number = 0) => { if (node.type === 'group') { return (