"use client"; import { useState } from "react"; import { City } from "../data/cities"; function ratingToPercent(rating: string): number { const m: Record = { 极好: 95, 很好: 80, 好: 60, 一般: 40, 差: 20, }; return m[rating] || 50; } function getBarColor(p: number): string { if (p >= 60) return "#22c55e"; if (p >= 35) return "#eab308"; return "#ef4444"; } function ScoreBar({ icon, label, percent, animate, }: { icon: string; label: string; percent: number; animate: boolean; }) { return (
{icon} {label}
); } export default function CityCard({ city, rank, }: { city: City; rank: number; }) { const [hovered, setHovered] = useState(false); const scores = [ { icon: "⭐", label: "综合", percent: (city.overallScore / 5) * 100, }, { icon: "💵", label: "费用", percent: Math.max(15, 100 - city.costPerMonth / 200), }, { icon: "📡", label: "网速", percent: Math.min(95, (city.internetSpeed / 120) * 100), }, { icon: "👍", label: "好评", percent: ratingToPercent(city.liked), }, { icon: "👮", label: "安全", percent: ratingToPercent(city.safety), }, ]; return (
setHovered(true)} onMouseLeave={() => setHovered(false)} > {/* Icon watermark */} {city.icon} {/* ===== Default state ===== */}
{/* Top row */}
{rank} 📡 {city.internetSpeed}Mbps
{/* Center: city name + country */}

{city.name}

{city.countryEmoji} {city.country}

{/* Bottom: temp + cost + nomads */}
👥 {city.nomadsNow}人在此 🌡 {city.temperature}°C
{city.description} ¥{city.costPerMonth.toLocaleString()}/月
{/* ===== Hover overlay (desktop only) ===== */}
); }