"use client"; import { useState, useEffect, useCallback } from "react"; import { motion } from "framer-motion"; import { format } from "date-fns"; import { AreaChart, Area, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer, PieChart, Pie, Cell, } from "recharts"; import { CATEGORIES, CATEGORY_LABELS, CATEGORY_COLORS, } from "@/config/xp"; import type { Category } from "@/config/xp"; import { apiClient, ApiClientError } from "@/lib/api-client"; import type { BestScoreEntry, BestScoresResponse, PersonalBestRecord, StatsResponse, StatsDailyXp, } from "@/lib/api-client"; // ─── Helpers ────────────────────────────────────────────────────────────────── function fmtDuration(secs: number): string { if (secs < 60) return `${secs}s`; if (secs < 3600) return `${Math.round(secs / 60)}m`; const h = Math.floor(secs / 3600); const m = Math.round((secs % 3600) / 60); return m > 0 ? `${h}h ${m}m` : `${h}h`; } function getCategoryColor(cat: string): string { return CATEGORY_COLORS[cat as Category] ?? "#6366f1"; } function getCategoryLabel(cat: string): string { return CATEGORY_LABELS[cat as Category] ?? cat; } // ─── Custom Tooltip ─────────────────────────────────────────────────────────── function ChartTooltip({ active, payload, label, }: { active?: boolean; payload?: Array<{ value: number; payload: StatsDailyXp }>; label?: string; }) { if (!active || !payload?.length) return null; const d = payload[0].payload; return (
Your training history and performance breakdown.
Fastest correct solves per puzzle type and difficulty
{/* Group records by exerciseType */} {(() => { const grouped = new MapAll-time highest quality scores by category and exercise type
{/* Category summary row */}