"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 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 (
{/* Header */}
{title}
Subject: {subject}
Grade: {grade}
Time: {durationMin} mins
Total: {totalScore} pts
{/* Content */}
{nodes.length === 0 ? (
Empty Exam Paper
) : (
nodes.map(node => renderNode(node))
)}
)
}