/** * Stat Card — KPI tile used on Dashboard and Reports pages. * * Two-line content layout: caption (label) on top, value below. A * coloured pill icon sits flush-right. When period-over-period * comparison data is available, a small delta line appears under the * value with up/down arrow + colour-coded percentage and an optional * "vs {period}" caption (previously hard-coded to "vs last month"). * * Optional `tooltip` surfaces a `?` icon next to the title; the * tooltip text appears on hover. Used by Dashboard to disambiguate * confusable metrics ("Booked Revenue" vs "Collected Revenue") that * operators routinely mix up. */ import React from "react"; import { LucideIcon } from "lucide-react"; import { Tooltip } from "../ui/tooltip"; interface StatCardProps { title: string; value: string | number; icon: LucideIcon; trend?: { value: number; isPositive: boolean; /** Caption next to the percentage. Defaults to "vs prev. period". */ label?: string; }; color?: "blue" | "green" | "purple" | "orange" | "red"; loading?: boolean; /** Hover-tooltip text. Renders a `?` icon next to the title. */ tooltip?: string; /** Click handler — turns the card into a navigable surface. */ onClick?: () => void; } /** * Stat Card Component — clean SaaS-style KPI tile. */ export const StatCard: React.FC = ({ title, value, icon: Icon, trend, color = "blue", loading = false, tooltip, onClick, }) => { const interactive = !!onClick; return (
{ if (e.key === "Enter" || e.key === " ") { e.preventDefault(); onClick?.(); } } : undefined } >

{title}

{tooltip && ( // Real hover-popover (see components/ui/tooltip.tsx). Native // `title=` was previously used here but had a ~700ms delay // and an easy-to-miss OS-default style — operators reported // the `?` icon "didn't show anything". The new tooltip // appears instantly on hover/focus and matches admin theme. ? )}
{loading ? (
) : (

{value}

)} {trend && !loading && (
{trend.isPositive ? "↑" : "↓"}{" "} {Math.abs(trend.value).toFixed(1)}% {trend.label || "vs prev. period"}
)}
); }; export default StatCard;