import { useState, useEffect } from 'react' import { useNavigate } from 'react-router-dom' import { CheckCircle, Clock, TrendingUp, Timer } from 'lucide-react' import type { LucideIcon } from 'lucide-react' import { sidebarApi } from '@/api' import { cn } from '@/lib/utils' import { Skeleton } from '@/components/ui/Skeleton' interface StatCard { label: string value: string | number icon: LucideIcon iconColor: string href: string highlight?: boolean } export function PerformanceCards() { const navigate = useNavigate() const [resolved, setResolved] = useState(0) const [active, setActive] = useState(0) const [totalMinutes, setTotalMinutes] = useState(0) const [loading, setLoading] = useState(true) const [error, setError] = useState(false) useEffect(() => { sidebarApi.getStats() .then((stats) => { setResolved(stats.resolved_today) setActive(stats.active_count) setTotalMinutes(stats.total_session_minutes_today) }) .catch(() => setError(true)) .finally(() => setLoading(false)) }, []) if (loading) { return (
{Array.from({ length: 4 }).map((_, i) => (
))}
) } if (error) { return (

Unable to load performance data

) } const avgMttr = resolved > 0 ? Math.round(totalMinutes / resolved) : 0 const cards: StatCard[] = [ { label: 'Resolved Today', value: resolved, icon: CheckCircle, iconColor: '#34d399', href: '/analytics', highlight: true, }, { label: 'Avg Resolution', value: avgMttr > 0 ? `${avgMttr}m` : '\u2014', icon: Clock, iconColor: '#60a5fa', href: '/analytics', }, { label: 'Active Now', value: active, icon: TrendingUp, iconColor: '#848b9b', href: '/sessions?filter=active', }, { label: 'Session Time', value: totalMinutes > 0 ? `${totalMinutes}m` : '\u2014', icon: Timer, iconColor: '#fbbf24', href: '/analytics', }, ] return (
{cards.map((card, i) => ( ))}
) }