"use client"; import type { GeometrySuitability, GeometrySuitabilityBaseLabel, } from "@/types/site-finder"; interface Props { data: GeometrySuitability; } const LABEL_COLOR: Record< GeometrySuitabilityBaseLabel, { bg: string; fg: string; border: string } > = { подходящий: { bg: "#dcfce7", fg: "#15803d", border: "#86efac" }, "сложная форма": { bg: "#fef9c3", fg: "#a16207", border: "#fde68a" }, "слабо подходит": { bg: "#fee2e2", fg: "#b91c1c", border: "#fca5a5" }, микро: { bg: "#fee2e2", fg: "#b91c1c", border: "#fca5a5" }, }; // label может быть combo "микро, узкий" — берём первую часть как ключ для цвета. function colorForLabel(label: string | undefined) { if (!label) return LABEL_COLOR["сложная форма"]; const base = label.split(",")[0].trim() as GeometrySuitabilityBaseLabel; return LABEL_COLOR[base] ?? LABEL_COLOR["сложная форма"]; } function fmtArea(ha: number | undefined, m2: number | undefined): string { if (ha !== undefined && ha >= 0.1) { return `${ha.toFixed(2)} га`; } if (m2 !== undefined) { return `${m2.toLocaleString("ru-RU")} м²`; } return "—"; } export function GeometrySuitabilityBlock({ data }: Props) { if (!data.data_available) { return (
Геометрия участка
{data.note}
); } const c = colorForLabel(data.label); const score = data.suitability_score ?? 0; const scorePct = Math.round(score * 100); return (
Геометрия участка {data.label} · {scorePct}%
{/* Метрики */}
Площадь
{fmtArea(data.area_ha, data.area_m2)}
Периметр
{data.perimeter_m ?? "—"} м
Соотношение сторон
{data.aspect_ratio?.toFixed(2) ?? "—"}
Выпуклость
{data.convex_hull_ratio !== undefined ? `${(data.convex_hull_ratio * 100).toFixed(0)}%` : "—"}
Мин. ширина
{data.min_inscribed_rect_dim_m ?? "—"} м
{/* Penalties */} {data.penalties && data.penalties.length > 0 && (
Проблемы формы: {data.penalties.join(", ")}
)} {/* Recommendation */} {data.recommendation && (
{data.recommendation}
)}
); }