"use client"; import { useRef, useState } from "react"; import Link from "next/link"; import type { Destination } from "@/lib/types"; interface Props { destinations: Destination[]; } export default function SpinGlobe({ destinations }: Props) { const [spinning, setSpinning] = useState(false); const [result, setResult] = useState(null); const [display, setDisplay] = useState(null); const timerRef = useRef | null>(null); const spin = () => { if (spinning || destinations.length === 0) return; setSpinning(true); setResult(null); let ticks = 0; const total = 18 + Math.floor(Math.random() * 8); const winner = destinations[Math.floor(Math.random() * destinations.length)]; timerRef.current = setInterval(() => { ticks++; setDisplay(destinations[Math.floor(Math.random() * destinations.length)]); if (ticks >= total) { if (timerRef.current) clearInterval(timerRef.current); setDisplay(winner); setResult(winner); setSpinning(false); } }, 90); }; const shown = display || destinations[0]; return (
🎲 SPIN

命运转盘 · 下一站去哪?

不知道去哪?让命运帮你选一座游民城市

{shown?.emoji || "🌍"}

{shown ? `${shown.name}, ${shown.country}` : "准备就绪"}

{shown && !spinning && !result && (

点击下方按钮,开启随机旅居冒险

)} {spinning &&

正在穿越时区… ✈️

} {result && !spinning && (

🎯 命运指引你去

💰 ¥{result.cost.toLocaleString()}/月 📶 {result.speed}Mbps ⭐ {result.rating}

{result.description}

查看详情 →
)} {!result && ( )}
); }