"use client"; import Link from "next/link"; import { useRouter } from "next/navigation"; import { useToast } from "@/lib/toast"; import { COMPARE_METRICS, getWinnerIdx, overallScore, compareUrl } from "@/lib/compareScore"; import { mergeDestinationsIntoTrip } from "@/lib/tripActions"; import type { Destination } from "@/lib/types"; interface Props { destinations: Destination[]; onClose: () => void; } export default function CompareModal({ destinations, onClose }: Props) { const router = useRouter(); const { toast } = useToast(); const scores = destinations.map(overallScore); const winnerIdx = scores.indexOf(Math.max(...scores)); const pageHref = compareUrl(destinations.map((d) => d.slug)); const addAllToPlan = () => { const { added, skipped } = mergeDestinationsIntoTrip(destinations, 1); onClose(); if (added === 0) { toast(skipped ? "这些城市已在计划中" : "未能加入", "info"); router.push("/plan"); return; } toast(`已加入 ${added} 座城市到计划${skipped ? `(跳过 ${skipped})` : ""}`); router.push("/plan"); }; const shareCompare = async () => { const url = `${window.location.origin}${pageHref}`; await navigator.clipboard.writeText(url); toast("对比链接已复制"); }; return (
e.target === e.currentTarget && onClose()}>
⚖️ COMPARE

城市对比分析

可视化对比关键指标,帮你做出最佳选择

{destinations.map((d, i) => (
{i === winnerIdx && 👑 综合推荐} {d.emoji}

{d.name}

{d.country}
{scores[i]}
查看详情 →
))}
{COMPARE_METRICS.map((m) => { const values = destinations.map(m.get); const winIdx = getWinnerIdx(values, m.lowerBetter); const maxVal = Math.max(...values); return (
{m.emoji} {m.label}
{destinations.map((d, i) => { const val = m.get(d); const pct = maxVal > 0 ? (val / maxVal) * 100 : 0; return (
{d.emoji} {d.name} {i === winIdx && "🏆 "}{m.format(val)}
); })}
); })}
打开完整对比页
); }