'use client'; import React, { useMemo } from 'react'; import { TrendingUp, CreditCard, Star, Home, BarChart3 } from 'lucide-react'; import { useI18n } from '@/i18n/I18nContext'; interface Bottle { id: string; purchase_price?: number | null; status: 'sealed' | 'open' | 'sampled' | 'empty'; distillery?: string; tastings?: { rating: number }[]; } interface StatsDashboardProps { bottles: Bottle[]; } export default function StatsDashboard({ bottles }: StatsDashboardProps) { const { t, locale } = useI18n(); const stats = useMemo(() => { const activeBottles = bottles.filter(b => b.status !== 'empty'); const totalValue = bottles.reduce((sum, b) => sum + (Number(b.purchase_price) || 0), 0); const ratings = bottles.flatMap(b => b.tastings?.map(t => t.rating) || []); const avgRating = ratings.length > 0 ? Math.round(ratings.reduce((sum, r) => sum + r, 0) / ratings.length) : 0; const distilleries = bottles .filter(b => b.distillery) .reduce((acc, b) => { acc[b.distillery!] = (acc[b.distillery!] || 0) + 1; return acc; }, {} as Record); const topDistillery = Object.entries(distilleries).sort((a, b) => b[1] - a[1])[0]?.[0] || 'N/A'; return { totalValue, activeCount: activeBottles.length, avgRating, topDistillery, totalCount: bottles.length }; }, [bottles]); const statItems = [ { label: t('home.stats.totalValue'), value: stats.totalValue.toLocaleString(locale === 'de' ? 'de-DE' : 'en-US', { style: 'currency', currency: 'EUR' }), icon: CreditCard, color: 'text-green-600', bg: 'bg-green-50 dark:bg-green-900/20' }, { label: t('home.stats.activeBottles'), value: stats.activeCount, icon: Home, color: 'text-blue-600', bg: 'bg-blue-50 dark:bg-blue-900/20' }, { label: t('home.stats.avgRating'), value: `${stats.avgRating}/100`, icon: Star, color: 'text-amber-600', bg: 'bg-amber-50 dark:bg-amber-900/20' }, { label: t('home.stats.topDistillery'), value: stats.topDistillery, icon: BarChart3, color: 'text-purple-600', bg: 'bg-purple-50 dark:bg-purple-900/20' }, ]; return (
{statItems.map((item, idx) => { const Icon = item.icon; return (
{item.label}
{item.value}
); })}
); }