'use client'; import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer, } from 'recharts'; import type { PriceHistoryItem } from '@/lib/listings-api'; interface PriceHistoryChartProps { data: PriceHistoryItem[]; height?: number; } function priceToMillions(priceStr: string): number { return Math.round(Number(priceStr) / 1_000_000); } function formatMillions(value: number): string { if (value >= 1000) return `${(value / 1000).toFixed(1)} tỷ`; return `${value} tr`; } export function PriceHistoryChart({ data, height = 280 }: PriceHistoryChartProps) { if (data.length === 0) return null; const chartData = [...data] .sort((a, b) => new Date(a.changedAt).getTime() - new Date(b.changedAt).getTime()) .map((item) => ({ date: new Date(item.changedAt).toLocaleDateString('vi-VN', { day: '2-digit', month: '2-digit', year: 'numeric', }), price: priceToMillions(item.newPrice), })); return ( formatMillions(v)} /> [formatMillions(Number(value)), 'Giá']} /> ); }