"use client"; import { Check, Copy, X } from "lucide-react"; import type { ComponentType } from "react"; import { useEffect, useRef, useState } from "react"; import { MAP_ICON_CELL_RADIUS_CLASS_NAME, MAP_MAJOR_PANEL_RADIUS_CLASS_NAME } from "@/features/map/core/components/map-control-styles"; import { showMapNotice } from "@/features/map/core/components/notice"; import { cn } from "@/lib/utils"; import type { WaterNetworkSourceId } from "../map/sources"; import type { DetailFeature } from "../types"; import { getFeaturePanelModel, type FeaturePanelBadgeTone } from "../utils/feature-properties"; import { ConduitFeatureIcon, JunctionFeatureIcon, OrificeFeatureIcon, OutfallFeatureIcon, PumpFeatureIcon, type DrainageFeatureIconProps } from "./drainage-feature-icons"; type FeaturePopoverProps = { feature: DetailFeature | null; onClose: () => void; }; const FEATURE_LAYER_META: Record< WaterNetworkSourceId, { icon: ComponentType; label: string } > = { conduits: { icon: ConduitFeatureIcon, label: "管渠" }, junctions: { icon: JunctionFeatureIcon, label: "检查井" }, orifices: { icon: OrificeFeatureIcon, label: "孔口" }, outfalls: { icon: OutfallFeatureIcon, label: "排放口" }, pumps: { icon: PumpFeatureIcon, label: "泵" } }; const BADGE_CLASS_NAMES: Record = { active: "bg-emerald-50 text-emerald-700 ring-emerald-600/15", inactive: "bg-slate-100 text-slate-600 ring-slate-500/15", warning: "bg-orange-50 text-orange-700 ring-orange-600/15", critical: "bg-red-50 text-red-700 ring-red-600/15", info: "bg-blue-50 text-blue-700 ring-blue-600/15" }; const BADGE_DOT_CLASS_NAMES: Record = { active: "bg-emerald-500", inactive: "bg-slate-400", warning: "bg-orange-500", critical: "bg-red-500", info: "bg-blue-500" }; export function FeaturePopover({ feature, onClose }: FeaturePopoverProps) { const [copiedId, setCopiedId] = useState(null); const copyResetTimeoutRef = useRef | null>(null); useEffect(() => () => { if (copyResetTimeoutRef.current) { clearTimeout(copyResetTimeoutRef.current); } }, []); if (!feature) { return null; } const panelModel = getFeaturePanelModel(feature.layer, feature.properties, feature.id); const layerMeta = FEATURE_LAYER_META[feature.layer]; const LayerIcon = layerMeta.icon; const copied = copiedId === panelModel.id; const canCopy = panelModel.id !== "暂无"; const handleCopyId = async () => { try { if (!navigator.clipboard) { throw new Error("Clipboard API unavailable"); } await navigator.clipboard.writeText(panelModel.id); setCopiedId(panelModel.id); if (copyResetTimeoutRef.current) { clearTimeout(copyResetTimeoutRef.current); } copyResetTimeoutRef.current = setTimeout(() => setCopiedId(null), 1500); } catch { showMapNotice({ tone: "error", title: "无法复制编号", message: "请手动选择编号后复制。" }); } }; return ( ); }