File size: 1,841 Bytes
bc45e54
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { useState } from "react";

interface ParsedDataSummaryProps {
  parsedData: Record<string, unknown>;
}

export function ParsedDataSummary({ parsedData }: ParsedDataSummaryProps) {
  const [expanded, setExpanded] = useState(false);

  const questions = parsedData.questions as { questions?: unknown[] } | undefined;
  const students = parsedData.student_answers as { students?: unknown[] } | undefined;
  const answers = parsedData.teacher_answers as { answers?: unknown[] } | undefined;

  const qCount = questions?.questions?.length ?? 0;
  const sCount = students?.students?.length ?? 0;
  const aCount = answers?.answers?.length ?? 0;

  return (
    <div className="card p-4">
      <button
        onClick={() => setExpanded(!expanded)}
        className="w-full flex items-center justify-between text-left"
      >
        <div className="flex items-center gap-4">
          <h3 className="font-display text-sm font-semibold text-[var(--color-text)]">
            已解析資料
          </h3>
          <div className="flex gap-3 text-xs">
            {qCount > 0 && <span className="badge badge-success">📝 {qCount} 題</span>}
            {sCount > 0 && <span className="badge badge-success">👨‍🎓 {sCount} 位學生</span>}
            {aCount > 0 && <span className="badge badge-success">✅ {aCount} 答案</span>}
          </div>
        </div>
        <span className="text-[var(--color-text-muted)] text-lg">
          {expanded ? "▲" : "▼"}
        </span>
      </button>

      {expanded && (
        <div className="mt-4 pt-4 border-t border-[var(--color-border)] text-sm max-h-64 overflow-y-auto">
          <pre className="text-[var(--color-text-muted)] whitespace-pre-wrap break-words">
            {JSON.stringify(parsedData, null, 2)}
          </pre>
        </div>
      )}
    </div>
  );
}