import { memo, useMemo } from 'react'; import { PieChart, Pie, Cell, Tooltip, ResponsiveContainer } from 'recharts'; import { Card } from '@/components/ui/card'; import { getStockAgeDistribution } from '@/lib/mockData'; const COLORS = ['#4ade80', '#60a5fa', '#fbbf24', '#f87171', '#a78bfa', '#38bdf8', '#fb923c']; export const StockAgeChart = memo(({ data }: { data?: any[] }) => { const stockAgeData = useMemo(() => { if (data && data.length > 0) { return data.map(d => ({ range: d.age_range, value: d.percentage })).filter(d => d.value > 0); // Only show segments with value > 0 } return getStockAgeDistribution(); }, [data]); return (

Stock Age Distribution

{stockAgeData.map((_, index) => ( ))}
{stockAgeData.map((entry, index) => (
{entry.range} Days: {entry.value}%
))} {stockAgeData.length === 0 && (
No stock data available
)}
); }); StockAgeChart.displayName = 'StockAgeChart';