"use client"; import { useState } from "react"; import type { NeighborsSummary } from "@/types/site-finder"; interface Props { data: NeighborsSummary; } function fmtPrice(n: number | null | undefined): string { if (n == null) return "—"; if (n >= 1000) { return `${(n / 1000).toFixed(0)} тыс ₽/м²`; } return `${n.toLocaleString("ru-RU")} ₽/м²`; } function fmtYearBuilt(y: number | null | undefined): string { if (y == null || y === 0) return "—"; return String(y); } // Русский plural: 1 → "здание", 2-4 → "здания", 5+ → "зданий". // Также корректно для 11-14 (zданий), 21 (здание), 22 (здания) etc. function pluralBuildings(n: number): string { const mod10 = n % 10; const mod100 = n % 100; if (mod100 >= 11 && mod100 <= 14) return "зданий"; if (mod10 === 1) return "здание"; if (mod10 >= 2 && mod10 <= 4) return "здания"; return "зданий"; } export function NeighborsBlock({ data }: Props) { const [expanded, setExpanded] = useState(false); if (!data.data_available) { return (
| Здание | Эт. | Год | ₽/м² | Дист. |
|---|---|---|---|---|
|
{n.building_name ?? n.readable_address ?? n.cad_num}
{(n.purpose || n.status) && (
{n.purpose}
{n.purpose && n.status ? " · " : ""}
{n.status}
)}
|
{n.floors ?? "—"} | {fmtYearBuilt(n.year_built)} | {fmtPrice(n.cost_per_m2)} | {n.distance_m} м |