"use client"; import type { OpportunityParcel } from "@/types/nspd"; interface Props { opportunityParcels: OpportunityParcel[] | null | undefined; } type LayerKey = OpportunityParcel["layer"]; const LAYER_CONFIG: Record< LayerKey, { label: string; bg: string; badgeBg: string; color: string } > = { auction_parcels: { label: "На аукционе", bg: "#fff7ed", badgeBg: "#fed7aa", color: "#c2410c", }, scheme_parcels: { label: "Схема расположения", bg: "#eff6ff", badgeBg: "#bfdbfe", color: "#1d4ed8", }, free_parcels: { label: "Свободный от прав", bg: "#f0fdf4", badgeBg: "#bbf7d0", color: "#15803d", }, future_parcels: { label: "Планируемый (проект межевания)", bg: "#f9fafb", badgeBg: "#e5e7eb", color: "#374151", }, oopt: { label: "ООПТ", bg: "#faf5ff", badgeBg: "#e9d5ff", color: "#7e22ce", }, }; function formatDistance(m: number | null): string { if (m === null) return ""; if (m < 1000) return `${Math.round(m)} м`; return `${(m / 1000).toFixed(1)} км`; } function buildNspdViewerUrl(cadNum: string): string { return `https://nspd.gov.ru/map?cadastralNumber=${encodeURIComponent(cadNum)}`; } export function NspdOpportunityBlock({ opportunityParcels }: Props) { const parcels = opportunityParcels ?? []; if (parcels.length === 0) { return null; } // Group by layer type const grouped = parcels.reduce>( (acc, p) => { const key = p.layer as LayerKey; if (!acc[key]) acc[key] = []; acc[key].push(p); return acc; }, {} as Record, ); // Stable display order: auction first (highest priority) const layerOrder: LayerKey[] = [ "auction_parcels", "free_parcels", "scheme_parcels", "future_parcels", "oopt", ]; return (
{layerOrder.map((layerKey) => { const items = grouped[layerKey]; if (!items || items.length === 0) return null; const cfg = LAYER_CONFIG[layerKey]; return (
1 ? 8 : 0, }} > {cfg.label} {items.length} уч.
{items.map((p, idx) => (
{p.cad_num ? ( {p.cad_num} ) : ( )} {p.distance_m !== null && ( {formatDistance(p.distance_m)} )}
))}
); })}
); }