"use client"; import { useEffect, useState } from "react"; import Link from "next/link"; import LevelGrid from "@/components/LevelGrid"; import { GameProgress, getGameProgress, nextLevel, allStats } from "@/lib/progress"; import { GameId, GAME_META, TOTAL_LEVELS } from "@/lib/levels"; interface Props { game: GameId; } function fmt(s: number) { return `${String(Math.floor(s / 60)).padStart(2, "0")}:${String(s % 60).padStart(2, "0")}`; } export default function LevelsPageShell({ game }: Props) { const [progress, setProgress] = useState({}); const [next, setNext] = useState(1); const { name, accent } = GAME_META[game]; useEffect(() => { const refresh = () => { setProgress(getGameProgress(game)); setNext(nextLevel(game)); }; refresh(); window.addEventListener("focus", refresh); document.addEventListener("visibilitychange", refresh); return () => { window.removeEventListener("focus", refresh); document.removeEventListener("visibilitychange", refresh); }; }, [game]); const stats = allStats(); const gameStats = stats[game]; const completedCount = Object.keys(progress).length; const pct = Math.round((completedCount / TOTAL_LEVELS) * 100); return (
{/* Header */}
{name}

{name} — Niveaux

100 puzzles · difficulté progressive

{/* Completion ring */}
{completedCount} / {TOTAL_LEVELS} {pct > 0 && ( {pct}% )}
{/* Stats strip */} {gameStats && gameStats.bestTime > 0 && (
Meilleur temps {fmt(gameStats.bestTime)}
Prochain Niv. {next}
Complétés {completedCount}
)} {/* CTA */} {completedCount === 0 ? "Commencer" : "Continuer"} — Niveau {next} {/* Grid */}
); }