"use client"; import { useEffect, useState } from "react"; import Link from "next/link"; import { useRouter, useSearchParams } from "next/navigation"; import { AnimatePresence, animate, motion } from "framer-motion"; import { X, Play } from "lucide-react"; import type { GameCard as GameCardData } from "@spinza/shared"; import { STARTING_BALANCE } from "@spinza/shared"; import { useSession } from "@/lib/store"; import { Button } from "@/components/ui"; import { GameArt } from "./game-art"; import { VolatilityMeter } from "./game-card"; /** First-time experience shown after registration (`/?welcome=1`). */ export function WelcomeOverlay({ picks }: { picks: GameCardData[] }) { const params = useSearchParams(); const router = useRouter(); const user = useSession((s) => s.user); const reduceMotion = useSession((s) => s.settings?.reduceMotion) ?? false; const [open, setOpen] = useState(params.get("welcome") === "1"); const [phase, setPhase] = useState<"credits" | "choose">("credits"); const [count, setCount] = useState(0); useEffect(() => { if (!open) return; document.body.style.overflow = "hidden"; const ctrl = animate(0, STARTING_BALANCE, { duration: reduceMotion ? 0.2 : 1.8, ease: [0.16, 1, 0.3, 1], onUpdate: (v) => setCount(Math.round(v)) }); const t = setTimeout(() => setPhase("choose"), reduceMotion ? 600 : 2600); return () => { ctrl.stop(); clearTimeout(t); document.body.style.overflow = ""; }; }, [open, reduceMotion]); const dismiss = () => { setOpen(false); router.replace("/", { scroll: false }); }; return ( {open ? (
{user ? `@${user.username}` : "New player"}

Welcome to Spinza.

+{count.toLocaleString("en-US")} SC

Your starting Spinza Credits. Fictional, free, and refilled every day you come back.

{phase === "choose" ? (

Choose your first game

Three picks to start with. You can always come back to the lobby.

{picks.map((g, i) => ( setOpen(false)} className="group block overflow-hidden rounded-lg border border-line bg-bg-1 text-left shadow-card transition-transform hover:-translate-y-1 focus-ring" aria-label={`Play ${g.name}`}>
{g.tagline}
))}
) : null}
) : null} ); }