"use client"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/common/card"; import { Skeleton } from "@/components/common/skeleton"; import { Area, AreaChart, ResponsiveContainer, Tooltip, TooltipProps } from "recharts"; import { TrendIndicator } from "./TrendIndicator"; import { cn } from "@/lib/utils"; import { LucideIcon } from "lucide-react"; import { formatGBP } from "@/lib/utils/format"; interface ChartDataPoint { formattedDate: string; value: number; orders?: number; revenue?: number; [key: string]: any; } interface AdminStatCardProps { title: string; icon: LucideIcon; iconColorClass: string; iconBgClass: string; value: string | number; subtext?: React.ReactNode; trend?: { current: number; previous: number; }; loading?: boolean; chartData?: ChartDataPoint[]; chartColor: string; chartGradientId: string; tooltipPrefix?: string; // "£" or "" hideChart?: boolean; children?: React.ReactNode; } const CustomTooltip = ({ active, payload, label, prefix = "" }: TooltipProps & { prefix?: string }) => { if (active && payload && payload.length) { const data = payload[0].payload; return (

{data.formattedDate || label}

{prefix === "£" ? "Revenue" : "Count"} {prefix}{prefix === "£" ? (data.value || 0).toFixed(2) : data.value}
); } return null; }; export function AdminStatCard({ title, icon: Icon, iconColorClass, iconBgClass, value, subtext, trend, loading, chartData, chartColor, chartGradientId, tooltipPrefix = "", hideChart = false, children, }: AdminStatCardProps) { if (loading) { return (
{!hideChart && }
); } return (
{title}
{value}
{subtext} {trend && (
)}
{children &&
{children}
} {!hideChart && ( chartData && chartData.length > 0 ? (
} cursor={{ stroke: 'rgba(255,255,255,0.1)', strokeWidth: 1 }} />
) : (
No chart data
) )} {/* Fill space if chart is hidden but we want structure consistency */} {hideChart &&
} ); }