import Link from "next/link"; import { Card, CardContent } from "@/components/ui/card"; import { Skeleton } from "@/components/ui/skeleton"; import { LucideIcon, TrendingUp, TrendingDown, Minus } from "lucide-react"; import { cn } from "@/lib/utils"; interface KpiCardProps { title: string; value: string; icon: LucideIcon; iconColor: string; status: "ok" | "warning" | "critical"; hint?: string; loading?: boolean; trend?: number | null; trendLabel?: string; trendInvert?: boolean; href?: string; // optional navigation target } const statusBorder: Record = { ok: "border-l-4 border-l-green-500", warning: "border-l-4 border-l-amber-500", critical: "border-l-4 border-l-destructive", }; export function KpiCard({ title, value, icon: Icon, iconColor, status, hint, loading, trend, trendLabel, trendInvert, href }: KpiCardProps) { const hasTrend = trend !== null && trend !== undefined; const isUp = hasTrend && trend! > 0; const isDown = hasTrend && trend! < 0; const isFlat = hasTrend && trend! === 0; // For temp/alarms: up is bad (red), down is good (green) // For power: up might be warning, down is fine const trendGood = trendInvert ? isDown : isUp; const trendBad = trendInvert ? isUp : false; const trendColor = isFlat ? "text-muted-foreground" : trendGood ? "text-green-400" : trendBad ? "text-destructive" : "text-amber-400"; const inner = (

{title}

{loading ? ( ) : (

{value}

)} {hasTrend && !loading ? (
{isFlat ? : isUp ? : } {trendLabel ?? (trend! > 0 ? `+${trend}` : `${trend}`)} vs prev period
) : ( hint &&

{hint}

)}
); return ( {href ? {inner} : inner} ); }