'use client'; import { getFormattingLocale } from '@/i18n/format'; import { useMemo } from 'react'; import { useTranslations } from 'next-intl'; import { cn } from '@/lib/utils'; type RankChartItem = { label: string; value: number; }; type RankChartProps = { items: RankChartItem[]; color: string; valueFormatter?: (value: number) => string; emptyMessage?: string; className?: string; }; const defaultFormatter = (value: number) => { if (value >= 1000000) { return `${Number((value / 1000000).toFixed(2))}M`; } if (value >= 1000) { return `${Number((value / 1000).toFixed(2))}k`; } return value.toLocaleString(getFormattingLocale()); }; export function RankChart({ items, color, valueFormatter = defaultFormatter, emptyMessage, className, }: RankChartProps) { const t = useTranslations('dataComponents'); const maxValue = useMemo( () => Math.max(0, ...items.map((item) => item.value)), [items], ); if (items.length === 0) { return (