"use client"; import type { MarketTrend } from "@/types/site-finder"; interface Props { trend?: MarketTrend | null; } const LABEL_COLORS: Record = { "Сильный рост": { bg: "#dcfce7", color: "#15803d" }, "Умеренный рост": { bg: "#dbeafe", color: "#1d4ed8" }, Стагнация: { bg: "#fef3c7", color: "#b45309" }, Падение: { bg: "#fecaca", color: "#b91c1c" }, }; function trendArrow(delta: number): string { if (delta > 1) return "↑"; if (delta < -1) return "↓"; return "→"; } function deltaColor(delta: number): string { if (delta > 1) return "#15803d"; if (delta < -1) return "#b91c1c"; return "#6b7280"; } function fmtPrice(v: number): string { return v.toLocaleString("ru-RU", { maximumFractionDigits: 0 }); } export function MarketTrendBlock({ trend }: Props) { if (!trend) { return (
Тренд рынка
Недостаточно сделок ДДУ в радиусе для тренда
); } const arrow = trendArrow(trend.delta_6m_pct); const arrowColor = deltaColor(trend.delta_6m_pct); const labelStyle = LABEL_COLORS[trend.label] ?? { bg: "#f3f4f6", color: "#374151", }; return (
Тренд рынка в радиусе {trend.radius_km} км
{/* Main price */}
{fmtPrice(trend.recent_avg_price_per_m2)} ₽/м²
за последние 6 мес · {trend.recent_deals_count} сделок
{/* Delta */}
{arrow} {trend.delta_6m_pct > 0 ? "+" : ""} {trend.delta_6m_pct.toFixed(1)}%
{/* Prior comparison */}
vs {fmtPrice(trend.prior_avg_price_per_m2)} ₽/м² за предыдущие 6 мес ( {trend.prior_deals_count}→{trend.recent_deals_count} сделок)
{/* Label badge */}
{trend.label}
); }