"use client"; import { AnimatePresence, motion } from "framer-motion"; import { Loader2 } from "lucide-react"; import { ScreenShell } from "@/components/online/ScreenHeader"; import { useGameStore } from "@/lib/game-store"; import { useOnlineStore } from "@/lib/online-store"; import { useUIStore } from "@/lib/ui-store"; import { useI18n } from "@/lib/i18n"; import { getService } from "@/lib/online/service"; import { avatarEmoji } from "@/lib/online/types"; export function MatchmakingScreen() { const { t } = useI18n(); const mm = useOnlineStore((s) => s.matchmaking); const cancelMatchmaking = useOnlineStore((s) => s.cancelMatchmaking); const newOnlineMatch = useGameStore((s) => s.newOnlineMatch); const goGame = useUIStore((s) => s.goGame); const go = useUIStore((s) => s.go); const ready = mm.phase === "ready"; const slots = [0, 1, 2, 3]; const cancel = async () => { await cancelMatchmaking(); go("online"); }; const enter = () => { const players = getService().getMatchPlayers(); if (!players) return; newOnlineMatch({ players: players.map((p) => ({ displayName: p.displayName, avatar: p.avatar, level: p.level, })), targetScore: 7, stake: mm.stake, ranked: mm.ranked, }); goGame("home"); }; return (
{ready ? ( ) : ( )}

{ready ? t("mm.ready") : mm.phase === "found" ? t("mm.found") : t("mm.searching")}

{slots.map((i) => { const p = mm.players[i]; return (
{p ? ( {avatarEmoji(p.avatar)} {p.displayName} {t("common.level")} {p.level} ) : ( ? )}
); })}
{ready && ( {t("mm.start")} )}
); }