"use client"; import type { CianValuationSummary } from "@/types/trade-in"; interface Props { data: CianValuationSummary | null | undefined; } function formatRub(n: number | null | undefined): string { if (n == null) return "—"; if (n >= 1_000_000) return `${(n / 1_000_000).toFixed(2)} млн ₽`; return new Intl.NumberFormat("ru-RU").format(n) + " ₽"; } function Sparkline({ points }: { points: Array<{ date: string; price: number }> }) { if (points.length < 2) return null; const W = 240, H = 60, PAD = 4; const xs = points.map((_, i) => PAD + (i * (W - 2 * PAD)) / (points.length - 1)); const prices = points.map((p) => p.price); const min = Math.min(...prices), max = Math.max(...prices); const range = max - min || 1; const ys = prices.map((p) => H - PAD - ((p - min) / range) * (H - 2 * PAD)); const d = xs.map((x, i) => `${i === 0 ? "M" : "L"}${x},${ys[i]}`).join(" "); const firstDate = points[0].date.slice(0, 7); // "YYYY-MM" const lastDate = points[points.length - 1].date.slice(0, 7); return (