"use client"; import type { RedLine } from "@/types/nspd"; interface Props { redLines: RedLine[] | null | undefined; } function formatLength(m: number | null): string | null { if (m === null) return null; if (m >= 1000) return `${(m / 1000).toFixed(2)} км`; return `${Math.round(m)} м`; } function formatDistance(m: number | null): string | null { if (m === null) return null; if (m < 1000) return `${Math.round(m)} м`; return `${(m / 1000).toFixed(1)} км`; } export function NspdRedLinesBlock({ redLines }: Props) { const lines = redLines ?? []; if (lines.length === 0) { return null; } const intersecting = lines.filter((l) => l.intersection_length_m !== null); const nearbyOnly = lines.filter((l) => l.intersection_length_m === null); const hasIntersect = intersecting.length > 0; return (
{/* Alert banner when red lines intersect the parcel */} {hasIntersect && (
ПЕРЕСЕЧЕНИЕ
Красные линии пересекают участок — отступы могут быть критичны
{intersecting.map((l, idx) => { const lenStr = formatLength(l.intersection_length_m); return (
Линия {idx + 1} {lenStr ? `: длина пересечения ${lenStr}` : ""}
); })}
)} {/* Nearby-only red lines */} {nearbyOnly.length > 0 && (
РЯДОМ
{nearbyOnly.length} кр. лини{nearbyOnly.length === 1 ? "я" : "и"}{" "} вблизи участка
{nearbyOnly.map((l, idx) => { const distStr = formatDistance(l.distance_m); return (
Линия {idx + 1} {distStr ? `: ${distStr} от границы` : ""}
); })}
)} {/* Summary line */}
Итого: {lines.length} красн. лини{lines.length === 1 ? "я" : "и"} {hasIntersect ? `, из них ${intersecting.length} пересека${intersecting.length === 1 ? "ет" : "ют"} участок` : ""}
); }