"use client"; import type { ReactNode } from "react"; import { ArrowDown, ArrowRight, ArrowUp } from "lucide-react"; type KPITone = "default" | "primary" | "accent" | "warning" | "danger"; type KPIStatProps = { /** Eyebrow label above the value (e.g. "Today's Orders") */ label: string; /** The primary value to display. Accepts a node so callers can pass formatted strings, JSX, etc. */ value: ReactNode; /** Optional icon element (typically a lucide-react icon) shown in the leading tile. */ icon?: ReactNode; /** Controls the icon tile's background + icon color. Defaults to "default". */ tone?: KPITone; /** Optional trend indicator rendered next to the value. */ trend?: { value: string; direction: "up" | "down" | "flat" }; /** Extra class names appended to the card. */ className?: string; }; // Tone -> icon-tile background / icon color. Pulled from --admin-* tokens // introduced in the Phase 1 palette unification. No hardcoded hex values. const toneStyles: Record = { default: { bg: "var(--admin-bg-subtle)", fg: "var(--admin-text-secondary)" }, primary: { bg: "var(--admin-primary-soft)", fg: "var(--admin-primary)" }, accent: { bg: "var(--admin-accent-soft)", fg: "var(--admin-accent)" }, warning: { bg: "var(--admin-warning-soft)", fg: "var(--admin-warning)" }, danger: { bg: "var(--admin-danger-soft)", fg: "var(--admin-danger)" }, }; // Trend direction -> icon + color. "up" reads as positive (primary), // "down" as negative (danger), "flat" as neutral. const trendStyles: Record<"up" | "down" | "flat", { Icon: typeof ArrowUp; color: string }> = { up: { Icon: ArrowUp, color: "var(--admin-primary)" }, down: { Icon: ArrowDown, color: "var(--admin-danger)" }, flat: { Icon: ArrowRight, color: "var(--admin-text-muted)" }, }; /** * KPIStat — compact metric card for admin surfaces. * * Extracted from the inline pattern previously duplicated four times in * `DashboardClient.tsx`. Reuses the `.admin-stat-card*` classes from * `admin-design-system.css` for the shell, then applies tone-aware * background/foreground via inline `var(--admin-*)` styles. */ export default function KPIStat({ label, value, icon, tone = "default", trend, className = "", }: KPIStatProps) { const { bg, fg } = toneStyles[tone]; return (
{icon && (
{icon}
)}
{label}
{value} {trend && }
); } function TrendIndicator({ trend, }: { trend: { value: string; direction: "up" | "down" | "flat" }; }) { const { Icon, color } = trendStyles[trend.direction]; return ( ); }