import * as React from 'react' import { cn } from '../../lib/utils' import { SparklineTrend } from './SparklineTrend' export interface MetricCardTrend { value: number isPositive?: boolean label?: string } export interface MetricCardProps { label: string value: string | number icon: React.ComponentType<{ className?: string }> iconColor?: string trend?: MetricCardTrend sparklineData?: number[] href?: string isLoading?: boolean error?: boolean className?: string } export function MetricCard({ label, value, icon: Icon, iconColor = 'text-blue-500', trend, sparklineData, href, isLoading, error, className, }: MetricCardProps) { const content = (
{/* Header: Label and Icon */}

{label}

{/* Value */}

{isLoading ? '\u2014' : error ? 'Error' : value}

{/* Trend Indicator */} {trend && !isLoading && !error && ( )}
{/* Trend Label */} {trend?.label && !isLoading && !error && (

{trend.label}

)} {/* Sparkline */} {sparklineData && sparklineData.length > 1 && !isLoading && !error && (
)}
) if (href) { // Render a plain tag so the component works in any React framework // without requiring a specific router. Consumers using Next.js can wrap // with their own or pass an href and rely on client-side navigation. return ( {content} ) } return content } function TrendIndicator({ trend }: { trend: MetricCardTrend }) { const colorClass = trend.isPositive === true ? 'text-green-600' : trend.isPositive === false ? 'text-red-600' : 'text-gray-500' return (
{trend.isPositive === true && ( )} {trend.isPositive === false && ( )} {trend.isPositive === undefined && ( )} {trend.value > 0 ? '+' : ''}{trend.value}%
) }