"use client"; import { useMemo, useState } from "react"; import { useObjectInfrastructure } from "@/lib/analytics-api"; const CATEGORY_COLORS: Record = { Спорт: "#0a7a3a", Продукты: "#1d4ed8", Образование: "#c2410c", Медицина: "#b3261e", Развлечения: "#9333ea", Новостройки: "#0891b2", Транспорт: "#475569", }; interface Props { objId: number | string; centerLat: number | null; centerLon: number | null; } export function ObjectInfraMap({ objId, centerLat, centerLon }: Props) { const [maxDist, setMaxDist] = useState(2000); const [activeCat, setActiveCat] = useState(null); const { data, isLoading } = useObjectInfrastructure(objId, { category: activeCat ?? undefined, max_distance: maxDist, }); const stats = useMemo(() => { const byCat: Record = {}; for (const p of data ?? []) { const c = p.poi_category ?? "—"; byCat[c] = (byCat[c] ?? 0) + 1; } return Object.entries(byCat).sort((a, b) => b[1] - a[1]); }, [data]); return (
{stats.map(([cat, n]) => ( ))}
{isLoading ? (
Загрузка POI…
) : (
Найдено {data?.length ?? 0} POI в радиусе {maxDist} м.{" "} {centerLat && centerLon ? `ЖК: ${centerLat.toFixed(4)}, ${centerLon.toFixed(4)}` : "координаты ЖК не заданы"}
{["POI", "Категория", "Адрес", "Расстояние, м"].map((h) => ( ))} {(data ?? []).slice(0, 50).map((p, i) => ( ))}
{h}
{p.poi_name}
{p.poi_subtitle ? (
{p.poi_subtitle}
) : null}
{p.poi_category ?? "—"} {p.poi_address ?? "—"} {p.distance_m ? Math.round(p.distance_m) : "—"}
)}
); }