'use client' import { useState, useEffect } from 'react' import { motion } from 'framer-motion' import { Globe, Zap, TrendingUp, Clock, BarChart3, CheckCircle } from 'lucide-react' import { AggregatedStats } from '@/types' interface StatItemProps { icon: React.ElementType value: string | number label: string index: number } function StatItem({ icon: Icon, value, label, index }: StatItemProps) { return (
{value}
{label}
) } export default function Stats() { const [stats, setStats] = useState(null) const [loading, setLoading] = useState(true) useEffect(() => { async function fetchStats() { try { const response = await fetch('/api/analytics') if (response.ok) { const data = await response.json() setStats(data.stats) } } catch (error) { console.error('Failed to fetch stats:', error) } finally { setLoading(false) } } fetchStats() // Refresh stats every 30 seconds const interval = setInterval(fetchStats, 30000) return () => clearInterval(interval) }, []) // Show placeholder stats while loading or if no real data yet const displayStats = stats && stats.totalExtractions > 0 return (
{displayStats ? ( <> {/* Real stats when available */}
0 ? `${(stats.avgProcessingTime / 1000).toFixed(1)}s` : '-'} label="Avg processing time" index={2} /> 1000000 ? `${(stats.totalTokensProcessed / 1000000).toFixed(1)}M` : stats.totalTokensProcessed > 1000 ? `${(stats.totalTokensProcessed / 1000).toFixed(0)}K` : stats.totalTokensProcessed} label="Tokens processed" index={3} />
{/* Popular sites */} {stats.popularSites && stats.popularSites.length > 0 && (

Most extracted sites

{stats.popularSites.slice(0, 5).map((site, index) => ( {index + 1}. {site.host} ({site.count}) ))}
)} ) : ( /* Placeholder highlights when no stats available */
)}
) }