"use client" import React from "react" import { ScrollArea } from "@/shared/components/ui/scroll-area" import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from "@/shared/components/ui/dialog" import { Button } from "@/shared/components/ui/button" import { Eye, Printer } from "lucide-react" 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 renderNode = (node: ExamNode, depth: number = 0) => { if (node.type === 'group') { return (

{node.title || "Section"}

{/* Optional: Show section score if needed */}
{node.children?.map(child => renderNode(child, depth + 1))}
) } if (node.type === 'question' && node.question) { questionCounter++ const q = node.question const content = q.content as QuestionContent return (
{questionCounter}.
{content.text ?? ""} ({node.score}分)
{/* Options for Choice Questions */} {(q.type === 'single_choice' || q.type === 'multiple_choice') && content.options && (
{content.options.map((opt) => (
{opt.id}. {opt.text}
))}
)} {/* Space for written answers */} {q.type === 'text' && (
)}
) } return null } return (
Exam Preview
{/* Header */}

{title}

Subject: {subject} Grade: {grade} Time: {durationMin} mins Total: {totalScore} pts
Class:
Name:
No.:
{/* Content */}
{nodes.length === 0 ? (
Empty Exam Paper
) : ( nodes.map(node => renderNode(node)) )}
) }