"use client"; import { useEstimatePlacementHistory } from "@/lib/trade-in-api"; import type { PlacementHistoryItem } from "@/types/trade-in"; type Props = { estimateId: string }; const fmtPrice = (n: number | null): string => n == null ? "—" : `${(n / 1_000_000).toFixed(2)} М ₽`; const fmtDate = (d: string | null): string => { if (!d) return "—"; try { return new Date(d).toLocaleDateString("ru-RU"); } catch { return d; } }; function lotLabel(it: PlacementHistoryItem): string { if (it.title) return it.title; const rooms = it.rooms != null ? `${it.rooms}к` : "?к"; const area = it.area_m2 != null ? `${it.area_m2} м²` : "? м²"; const floor = it.floor != null && it.total_floors != null ? `, эт. ${it.floor}/${it.total_floors}` : ""; return `${rooms}, ${area}${floor}`; } export function PlacementHistoryCard({ estimateId }: Props) { const { data: items, isPending, isError } = useEstimatePlacementHistory(estimateId); if (isPending || isError) return null; if (!items || items.length === 0) return null; const visible = items.slice(0, 20); return (

История продаж в этом доме

{items.length} лот{items.length === 1 ? "" : "ов"}
{visible.map((it) => ( ))}
Лот Цена нач. → посл. Дата Экспозиция
{lotLabel(it)} {fmtPrice(it.start_price)} →{" "} {fmtPrice(it.last_price)} {fmtDate(it.last_price_date ?? it.start_price_date)} {it.exposure_days ?? "—"} дн.
{items.length > 20 && ( показано 20 из {items.length} )}
); }