"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 (
可视化对比关键指标,帮你做出最佳选择