import {
BarChart,
Bar,
XAxis,
YAxis,
CartesianGrid,
Tooltip,
ResponsiveContainer,
Cell,
} from "recharts";
import { Card, CardContent, CardHeader, CardTitle } from "@pram/ui/components/card";
import { formatLabel } from "@/lib/format";
import { formatTime } from "@/lib/time";
export interface ExamTypeItem {
examTypeId: string;
examTypeName: string;
accuracyPct: number;
avgScorePct: number;
avgTimeSpentSec: number;
attempts: number;
}
export interface SectionTypeItem {
sectionTypeId: string;
sectionTypeName: string;
accuracyPct: number;
avgScorePct: number;
avgTimeSpentSec: number;
attempts: number;
}
export interface FormatItem {
format: string;
accuracyPct: number;
avgTimeSpentSec: number;
totalQuestions: number;
}
interface BreakdownChartsProps {
byExamType: ExamTypeItem[] | undefined;
bySectionType: SectionTypeItem[] | undefined;
byFormat: FormatItem[] | undefined;
}
const COLORS = [
"var(--matcha-600)",
"var(--slushie-600)",
"var(--lemon-700)",
"var(--ube-600)",
"var(--pomegranate-600)",
];
function AccuracyBar({ pct }: { pct: number }) {
return (
= 80
? "var(--matcha-600)"
: pct >= 60
? "var(--lemon-700)"
: "var(--pomegranate-600)",
}}
/>
);
}
export function BreakdownCharts({ byExamType, bySectionType, byFormat }: BreakdownChartsProps) {
return (
Performa per Jenis Ujian
{byExamType && byExamType.length > 0 ? (
{
const num = typeof value === "number" ? value : 0;
const n = typeof name === "string" ? name : "";
if (n === "accuracyPct") return [`${num}%`, "Akurasi"];
if (n === "avgScorePct") return [`${num}%`, "Rata-rata Skor"];
return [num, n];
}}
/>
{byExamType.map((_, i) => (
|
))}
) : (
Belum ada data.
)}
Performa per Section
{bySectionType && bySectionType.length > 0 ? (
{
const num = typeof value === "number" ? value : 0;
const n = typeof name === "string" ? name : "";
if (n === "accuracyPct") return [`${num}%`, "Akurasi"];
if (n === "avgScorePct") return [`${num}%`, "Rata-rata Skor"];
return [num, n];
}}
/>
{bySectionType.map((_, i) => (
|
))}
) : (
Belum ada data.
)}
Performa per Format Soal
{byFormat && byFormat.length > 0 ? (
{byFormat.map((item) => (
{formatLabel(item.format)}
{item.totalQuestions} soal
{item.accuracyPct}%
{formatTime(item.avgTimeSpentSec)}/soal
))}
) : (
Belum ada data.
)}
);
}