import { useState } from 'react'; import { XAxis, YAxis, Tooltip, ResponsiveContainer, Area, AreaChart, ReferenceLine } from 'recharts'; interface Props { data: { date: string; price: number }[]; rrp?: number; } export default function PriceHistoryChart({ data, rrp }: Props) { const [range, setRange] = useState<30 | 90 | 365>(30); const filtered = data.slice(-range); const prices = filtered.map(d => d.price); const uniquePrices = new Set(prices); const isFlat = uniquePrices.size <= 1; if (rrp && rrp > 0) prices.push(rrp); const min = Math.floor(Math.min(...prices) - 5); const max = Math.ceil(Math.max(...prices) + 5); const ranges = [ { value: 30 as const, label: '30D' }, { value: 90 as const, label: '90D' }, { value: 365 as const, label: '1J' }, ]; if (filtered.length === 0) { return (

Prijsverloop

Nog geen prijsgeschiedenis beschikbaar — wordt dagelijks bijgewerkt

); } return (

Prijsverloop

{ranges.map(r => ( ))}
{isFlat && (

Stabiele prijs — geen verandering in de afgelopen {range === 365 ? 'jaar' : `${range} dagen`}

)}
{ const d = new Date(v); return `${d.getDate()}/${d.getMonth() + 1}`; }} axisLine={false} tickLine={false} interval="preserveStartEnd" /> `€${v}`} axisLine={false} tickLine={false} width={50} /> { const d = new Date(v); return d.toLocaleDateString('nl-NL', { day: 'numeric', month: 'long', year: 'numeric' }); }} formatter={(value: number) => [`€${value.toFixed(2).replace('.', ',')}`, 'Prijs']} /> {rrp && rrp > 0 && ( )}
); }