"use client"; import type { AggregatedEstimate, ConfidenceLevel } from "@/types/trade-in"; import type { TradeInEstimateInput } from "@/types/trade-in"; import { PriceRangeBar } from "./PriceRangeBar"; import { AnalogsTable } from "./AnalogsTable"; // ── helpers ──────────────────────────────────────────────────────────────────── function fmtRub(value: number): string { return value.toLocaleString("ru-RU", { style: "currency", currency: "RUB", maximumFractionDigits: 0, }); } function fmtRubM(value: number): string { const m = value / 1_000_000; return `${m.toFixed(2).replace(".", ",")} млн ₽`; } const CONFIDENCE_COLOR: Record< ConfidenceLevel, { bg: string; fg: string; border: string; label: string } > = { high: { bg: "#dcfce7", fg: "#15803d", border: "#86efac", label: "Высокая" }, medium: { bg: "#fef9c3", fg: "#a16207", border: "#fde68a", label: "Средняя" }, low: { bg: "#fee2e2", fg: "#b91c1c", border: "#fca5a5", label: "Низкая" }, }; const HOUSE_TYPE_LABELS: Record = { panel: "Панель", brick: "Кирпич", monolith: "Монолит", monolith_brick: "Монолит-кирпич", other: "Другое", }; const REPAIR_STATE_LABELS: Record = { needs_repair: "Требует ремонта", standard: "Стандартный", good: "Хороший", excellent: "Евроремонт", }; // ── sub-components ──────────────────────────────────────────────────────────── function SectionHeader({ icon, title, }: { icon: React.ReactNode; title: string; }) { return (
{icon}

{title}

); } function Card({ children }: { children: React.ReactNode }) { return (
{children}
); } // ── main component ──────────────────────────────────────────────────────────── interface Props { estimate: AggregatedEstimate; input: TradeInEstimateInput; } export function EstimateResult({ estimate, input }: Props) { const conf = CONFIDENCE_COLOR[estimate.confidence]; return (
{/* Hero card */}
Оценочная стоимость
{fmtRubM(estimate.median_price_rub)}
{fmtRub(estimate.median_price_per_m2)} / м²
{/* Confidence badge */}
Достоверность {conf.label} {estimate.n_analogs} аналог{ending(estimate.n_analogs)}
{/* Price range bar */}
Диапазон: {fmtRubM(estimate.range_low_rub)} —{" "} {fmtRubM(estimate.range_high_rub)} · данные за{" "} {estimate.period_months} мес.
{/* Section 1 — Cover / input snapshot */} {/* Section 2 — Listings (analogs) */} {/* Section 3 — Actual deals */} {/* Section 4 — Trade-in cost placeholder */} {/* PDF button (disabled) */}
); } function ending(n: number): string { const mod10 = n % 10; const mod100 = n % 100; if (mod10 === 1 && mod100 !== 11) return ""; if (mod10 >= 2 && mod10 <= 4 && !(mod100 >= 12 && mod100 <= 14)) return "а"; return "ов"; }