"use client"; import Link from "next/link"; import { GameId, TOTAL_LEVELS, levelMeta, GAME_META } from "@/lib/levels"; import { GameProgress } from "@/lib/progress"; interface Props { game: GameId; progress: GameProgress; currentLevel?: number; } const DIFF_COLORS: Record = { 1: { bg: "#f0fdf4", border: "#86efac", label: "Facile", color: "#16a34a" }, 2: { bg: "#fefce8", border: "#fde047", label: "Normal", color: "#ca8a04" }, 3: { bg: "#fff7ed", border: "#fdba74", label: "Intermédiaire", color: "#ea580c" }, 4: { bg: "#fef2f2", border: "#fca5a5", label: "Difficile", color: "#dc2626" }, 5: { bg: "#faf5ff", border: "#d8b4fe", label: "Expert", color: "#9333ea" }, }; function fmt(s: number): string { return `${String(Math.floor(s / 60)).padStart(2, "0")}:${String(s % 60).padStart(2, "0")}`; } function LevelCell({ game, level, done, isCurrent, accent, diffInfo, bestTime, }: { game: GameId; level: number; done: boolean; isCurrent: boolean; accent: string; diffInfo: typeof DIFF_COLORS[1]; bestTime: number; }) { return ( {done ? ( ) : ( level )} ); } export default function LevelGrid({ game, progress, currentLevel }: Props) { const accent = GAME_META[game].accent; const levels = Array.from({ length: TOTAL_LEVELS }, (_, i) => i + 1); // Group levels by difficulty const groups: { diff: number; levels: number[] }[] = []; let currentDiff = -1; for (const level of levels) { const d = levelMeta(game, level).difficulty; if (d !== currentDiff) { groups.push({ diff: d, levels: [level] }); currentDiff = d; } else { groups[groups.length - 1].levels.push(level); } } // Completion stats const completedCount = Object.keys(progress).length; return (
{/* Difficulty legend */}
{[1, 2, 3, 4, 5].map(d => { const { bg, border, label, color } = DIFF_COLORS[d]; return (
{label}
); })}
{/* Difficulty groups */}
{groups.map(({ diff, levels: groupLevels }) => { const diffInfo = DIFF_COLORS[diff]; const groupDone = groupLevels.filter(l => !!progress[l]).length; return (
{/* Group header */}
{diffInfo.label} {groupDone}/{groupLevels.length}
{/* Grid for this difficulty group */}
{groupLevels.map(level => { const record = progress[level]; const done = !!record; const isCurrent = level === currentLevel; const meta = levelMeta(game, level); return ( ); })}
); })}
{/* Footer stats */}

{completedCount} / {TOTAL_LEVELS} niveaux complétés {completedCount > 0 && ( ({Math.round((completedCount / TOTAL_LEVELS) * 100)}%) )}

); }