"use client"; import { CircleMarker, LayerGroup, Popup } from "react-leaflet"; import type { CustomPoi } from "@/types/customPoi"; // --------------------------------------------------------------------------- // Props // --------------------------------------------------------------------------- interface Props { pois: CustomPoi[]; onEdit: (poi: CustomPoi) => void; onDelete: (id: number) => void; } // --------------------------------------------------------------------------- // Color helpers // --------------------------------------------------------------------------- function markerColor(weight: number): string { if (weight > 0) return "#16a34a"; // green — positive if (weight < 0) return "#dc2626"; // red — negative return "#6b7280"; // gray — neutral } function weightLabel(weight: number): string { if (weight > 0) return `+${weight}`; return String(weight); } // Человекочитаемая дата (ru) с guard против null / невалидного ISO. // Repo-convention: inline new Date(...).toLocaleDateString("ru-RU") + NaN-fallback // (см. EgrnPropertyTable.formatDate). function formatDate(raw: string | null | undefined): string | null { if (!raw) return null; const d = new Date(raw); if (Number.isNaN(d.getTime())) return null; return d.toLocaleDateString("ru-RU"); } // --------------------------------------------------------------------------- // Component // --------------------------------------------------------------------------- export function CustomPoiLayer({ pois, onEdit, onDelete }: Props) { if (!pois.length) return null; return ( {pois.map((poi) => { const color = markerColor(poi.weight); const isGlobal = !poi.parcel_cad; const createdStr = formatDate(poi.created_at); const updatedStr = formatDate(poi.updated_at); // «изменена» показываем только если updated_at отличается от created_at. const wasEdited = !!poi.updated_at && !!poi.created_at && poi.updated_at !== poi.created_at; return (
{poi.name}
{poi.category && (
{poi.category}
)}
{isGlobal ? "Глобальная точка" : `Привязана к участку ${poi.parcel_cad}`}
Вес: {weightLabel(poi.weight)}
{poi.notes && (
{poi.notes}
)}
{createdStr && (
Добавлена {createdStr} {wasEdited && updatedStr ? ` · изменена ${updatedStr}` : ""}
)}
); })}
); }