import {
AreaChart,
Area,
XAxis,
YAxis,
CartesianGrid,
Tooltip,
ResponsiveContainer,
} from "recharts";
import { Card, CardContent, CardHeader, CardTitle } from "@pram/ui/components/card";
interface TrendPoint {
date: string;
attempts: number;
avgScorePct: number;
}
interface ScoreTrendChartProps {
data: TrendPoint[] | undefined;
}
function formatDateLabel(dateStr: string) {
const d = new Date(dateStr);
return `${d.getDate()}/${d.getMonth() + 1}`;
}
export function ScoreTrendChart({ data }: ScoreTrendChartProps) {
if (!data || data.length === 0) {
return (
Tren Skor
Belum ada data tren.
);
}
const chartData = data.map((d) => ({
...d,
label: formatDateLabel(d.date),
}));
return (
Tren Skor (30 Hari)
{
const num = typeof value === "number" ? value : 0;
const n = typeof name === "string" ? name : "";
if (n === "avgScorePct") return [`${num}%`, "Rata-rata Skor"];
if (n === "attempts") return [num, "Latihan"];
return [num, n];
}}
/>
);
}