// --------------------------------------------------------------------------- // AgingBars — AR aging stacked horizontal bar. // // One bar split into up to 4 segments by aging bucket (0–30 / 31–60 / // 61–90 / 90+ days). Each segment is coloured along a cool-to-warm ramp // so the eye reads left-to-right as "freshest to most stale". Below // the bar, four legend rows show the bucket label, dollar amount, and // share of total. The component is data-driven — pass any four-bucket // distribution. // --------------------------------------------------------------------------- import { fmt } from "@/lib/format"; export interface AgingBucket { /** Bucket id for keying. */ id: string; /** Display label (e.g. "0–30", "31–60", "61–90", "90+"). */ label: string; /** Dollar amount outstanding in this bucket. */ amount: number; /** Tailwind/HSL colour for the segment. */ color: string; } export interface AgingBarsProps { buckets: AgingBucket[]; /** Total AR amount for share calc. Defaults to sum of buckets. */ total?: number; /** Optional caption shown right-aligned above the bar. */ caption?: string; } export function AgingBars({ buckets, total, caption }: AgingBarsProps) { const sum = total ?? buckets.reduce((s, b) => s + b.amount, 0); if (sum <= 0) { return (