"use client"; import { useI18n } from "@/components/I18nProvider"; import { useEffect, useState } from "react"; import Link from "next/link"; import { useRouter } from "next/navigation"; import { api } from "./StartGame"; import { GuessMap } from "./GuessMap"; import type { SessionView } from "./Game"; import { difficulties } from "@/shared/protocol"; export function Results({ id }: { id: string }) { const { t, formatNumber } = useI18n(); const [session, setSession] = useState(null), [selected, setSelected] = useState(0), [error, setError] = useState(""); const router = useRouter(); useEffect(() => { let disposed = false; setSession(null); setSelected(0); setError(""); api("sessions/" + id) .then((s) => { if (disposed) return; if (s.round < 5) router.replace("/play/" + id); else setSession(s); }) .catch((e) => { if (!disposed) setError(e.message); }); return () => { disposed = true; }; }, [id, router]); if (error) return

{t(error)}

; if (!session) return

{t("Unpacking your expedition…")}

; const total = session.rounds.reduce((n, r) => n + (r.result?.score || 0), 0); const current = session.rounds[selected].result; return ( <> {t("EXPEDITION COMPLETE ·")}{" "} {session.difficultySettings.id in difficulties ? t(session.difficultySettings.name) : session.difficultySettings.name}

{t("Every guess is a story.")}

{session.name} {t("· Here’s where your instincts took you.")}

{formatNumber(total)} / 25,000

{t("Your five-round journey")}

{session.rounds.map((r, i) => ( ))}
{session.rounds.map((r, i) => ( ))}
{t("ROUND")} {t("DISTANCE")} {t("POINTS")}
{i + 1} {r.result?.timedOut ? t("Timed out") : t("{count} blocks", { count: formatNumber( Math.round(r.result?.distance || 0), ), })} {r.result ? formatNumber(r.result.score) : "—"}
{t("Another adventure →")} {t("My maps")} {t("View leaderboard →")}
); }