import React from 'react'; import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer } from 'recharts'; import { License } from '../types'; interface PriceHistoryChartProps { license: License; } const formatCurrency = (value: number) => new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD', minimumFractionDigits: 0 }).format(value); const PriceHistoryChart: React.FC = ({ license }) => { const data = [ { date: new Date(license.purchaseDate), price: license.purchasePrice }, ...(license.renewals || []).map(r => ({ date: new Date(r.renewalDate), price: r.renewalPrice })) ] .map(i => ({ ...i, time: i.date.getTime(), str: i.date.toLocaleDateString() })) .filter(i => !isNaN(i.time)) .sort((a, b) => a.time - b.time); if (data.length < 2) { return
No price history
; } return ( new Date(t).toLocaleDateString(undefined, {month:'short', year:'2-digit'})} stroke="#9ca3af" tick={{fontSize: 10}} /> `$${v}`} width={40} /> new Date(l).toLocaleDateString()} formatter={(val: number) => [formatCurrency(val), 'Price']} /> ); }; export default PriceHistoryChart;