'use client'; import React from 'react'; import { Card, CardContent } from '@/components/ui/Card'; import { formatNumber } from '@/lib/utils'; import { useTranslation } from '@/hooks/useTranslation'; import { TrendData } from '@/types/analytics'; interface StatsGridProps { stats: { totalScans: number; activeQRCodes: number; conversionRate: number; }; trends?: { totalScans?: TrendData; comparisonPeriod?: 'week' | 'month'; }; } export const StatsGrid: React.FC = ({ stats, trends }) => { const { t } = useTranslation(); // Build trend display text const getTrendText = () => { if (!trends?.totalScans) { return 'No data yet'; } const trend = trends.totalScans; const sign = trend.isNegative ? '-' : '+'; const period = trends.comparisonPeriod || 'period'; const newLabel = trend.isNew ? ' (new)' : ''; return `${sign}${trend.percentage}%${newLabel} from last ${period}`; }; const getTrendType = (): 'positive' | 'negative' | 'neutral' => { if (!trends?.totalScans) return 'neutral'; if (trends.totalScans.trend === 'up') return 'positive'; if (trends.totalScans.trend === 'down') return 'negative'; return 'neutral'; }; const cards = [ { title: t('dashboard.stats.total_scans'), value: formatNumber(stats.totalScans), change: getTrendText(), changeType: getTrendType(), icon: ( ), }, { title: t('dashboard.stats.active_codes'), value: stats.activeQRCodes.toString(), change: stats.activeQRCodes > 0 ? `${stats.activeQRCodes} active` : 'Create your first', changeType: stats.activeQRCodes > 0 ? 'positive' : 'neutral' as 'positive' | 'negative' | 'neutral', icon: ( ), }, { title: 'Unique Scan Rate', value: `${stats.conversionRate}%`, change: stats.totalScans > 0 ? `${stats.conversionRate}% new users` : 'No scans yet', changeType: stats.conversionRate > 0 ? 'positive' : 'neutral' as 'positive' | 'negative' | 'neutral', icon: ( ), }, ]; return (
{cards.map((card, index) => (

{card.title}

{card.value}

{card.change}

{card.icon}
))}
); };