import React from "react"; import { Card, CardContent, CardHeader, CardTitle } from "./card"; import { Spinner } from "./spinner"; import { cn } from "@/lib/utils"; import { formatCurrency } from "@/lib/format-currency"; // ─── Types ─────────────────────────────────────────────────────────────────── export interface IncomeSource { id: string; label: string; amount: number; /** 0–100, percentage of total income */ percentage: number; transactionCount?: number; } export interface IncomeSourcesCardProps { sources: IncomeSource[]; totalIncome: number; selectedSourceId?: string | null; onSelectSource?: (id: string | null) => void; /** Display label for the period, e.g. "30 Days" */ period?: string; isLoading?: boolean; className?: string; } // ─── Source row ─────────────────────────────────────────────────────────────── function SourceRow({ source, isSelected, onClick, }: { source: IncomeSource; isSelected: boolean; onClick: () => void; }) { return ( {source.label} {formatCurrency(source.amount)} {source.transactionCount != null ? `${source.transactionCount} ${source.transactionCount === 1 ? "transaction" : "transactions"}` : ""} {source.percentage.toFixed(0)}% ); } // ─── Component ──────────────────────────────────────────────────────────────── export function IncomeSourcesCard({ sources, totalIncome, selectedSourceId, onSelectSource, period, isLoading = false, className, }: IncomeSourcesCardProps) { return ( Income Sources {formatCurrency(totalIncome)} {period && ( {period} )} {isLoading ? ( ) : sources.length === 0 ? ( No income sources available ) : ( sources.map((source) => ( onSelectSource?.( selectedSourceId === source.id ? null : source.id, ) } /> )) )} ); }
No income sources available