/** * Shared Email Marketing dashboard widgets — a KPI stat tile and a * delivery-health segmented bar. Used by both the Overview tab and the * Campaign detail (Statistics) drawer so the two stay visually consistent. */ import { type ReactElement } from "react"; import { ArrowDown, ArrowUp } from "lucide-react"; import { Card, CardContent, CardHeader, CardTitle } from "./card"; export interface EmailOverviewStat { label: string; value: string; hint?: string; /** Change vs last month, magnitude only (e.g. "12%", "0.3pp"). */ delta?: string; trend?: "up" | "down"; /** Whether the change is favourable — drives green (good) vs red (bad). */ positive?: boolean; } export interface EmailDeliverySegment { label: string; count: number; /** Tailwind bg-* token for the segment bar + legend swatch. */ colorClass: string; } /** Single KPI tile: label + value + optional trend delta and context hint. */ export function EmailStatTile({ stat, }: { stat: EmailOverviewStat; }): ReactElement { return ( {stat.label} {stat.value} {(stat.delta || stat.hint) ?
{stat.delta ? {stat.trend === "down" ? ( ) : ( )} {stat.delta} : null} {stat.hint ? {stat.hint} : null}
: null}
); } /** Delivery-health breakdown: a segmented bar + a legend with counts and %. */ export function EmailDeliveryHealth({ segments, }: { segments: EmailDeliverySegment[]; }): ReactElement { const total = segments.reduce((sum, s) => sum + s.count, 0) || 1; return ( Delivery health
{segments.map((s) => (
))}
{segments.map((s) => (
{s.label}
{s.count.toLocaleString()} {((s.count / total) * 100).toFixed(1)}%
))}
); }