import React from "react"; import { TrendingUp, Home, ShoppingBag, CreditCard, PiggyBank, TrendingDown, } from "lucide-react"; import { Card, CardContent, CardHeader, CardTitle } from "./card"; import { InfoTooltip } from "./info-tooltip"; import { cn } from "@/lib/utils"; import { formatCurrency } from "@/lib/format-currency"; // ─── Types ─────────────────────────────────────────────────────────────────── // The budget-bucket taxonomy (mirrors the FE dashboard card): Total Income at the // top, then where it goes — Essentials, Lifestyle: Discretionary, Debt Repayments — // and whatever is left as Surplus & Future Savings (or Over Spending if consumption // exceeds income). export type IncomingOutgoingsLabel = | "Total Income" | "Essentials" | "Lifestyle: Discretionary" | "Debt Repayments" | "Surplus & Future Savings" | "Over Spending"; export interface IncomingOutgoingsItem { label: IncomingOutgoingsLabel; /** Dollar value */ value: number; /** CSS color string for the bar fill and icon */ color: string; /** CSS color string for the bar track background */ bgColor: string; /** Bar fill width as a percentage 0–100 */ pct: number; /** * Optional "how is this calculated" explainer shown as an info-icon tooltip * next to the label (e.g. why Debt Repayments don't add up exactly to income). */ tooltip?: string; } export interface IncomingOutgoingsCardProps { items: IncomingOutgoingsItem[]; title?: string; /** Optional whole-card explainer shown as an info-icon tooltip next to the title. */ tooltip?: string; className?: string; } // ─── Icon map ───────────────────────────────────────────────────────────────── const ICON_MAP: Record< IncomingOutgoingsLabel, React.ComponentType<{ size?: number; className?: string; style?: React.CSSProperties; }> > = { "Total Income": TrendingUp, Essentials: Home, "Lifestyle: Discretionary": ShoppingBag, "Debt Repayments": CreditCard, "Surplus & Future Savings": PiggyBank, "Over Spending": TrendingDown, }; // ─── Component ──────────────────────────────────────────────────────────────── export function IncomingOutgoingsCard({ items, title = "Incoming and outgoings", tooltip, className, }: IncomingOutgoingsCardProps) { if (!items?.length) return null; return ( {title} {tooltip && } {items.map((item) => { const Icon = ICON_MAP[item.label]; return (
{Icon && ( )} {item.label} {item.tooltip && } {formatCurrency(item.value)}
); })} ); }