import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from '@/components/ui/card'; import { CashflowSummary } from '@/hooks/use-cashflow-data'; import { cn } from '@/lib/utils'; import { __ } from '@/utils/i18n'; import { TrendingDown, TrendingUp } from 'lucide-react'; interface SavingsRateCardProps { current: CashflowSummary; previous: CashflowSummary; loading?: boolean; } export function SavingsRateCard({ current, previous, loading, }: SavingsRateCardProps) { if (loading) { return ( {__('Savings Rate')}
); } const diff = current.savings_rate - previous.savings_rate; const isPositive = diff >= 0; const hasPreviousData = previous.income > 0; // Determine color based on savings rate const rateColor = current.savings_rate >= 20 ? 'text-green-600 dark:text-green-400' : current.savings_rate >= 10 ? 'text-yellow-600 dark:text-yellow-400' : current.savings_rate >= 0 ? 'text-orange-600 dark:text-orange-400' : 'text-red-600 dark:text-red-400'; return ( {__('Savings Rate')} {__('Percentage of income saved')}
{current.savings_rate.toFixed(1)}% {hasPreviousData && (
{isPositive ? ( ) : ( )} {isPositive ? '+' : ''} {diff.toFixed(1)}%
)}

{current.savings_rate >= 20 ? __("Great job! You're saving well.") : current.savings_rate >= 10 ? __('Good progress on your savings.') : current.savings_rate >= 0 ? __('Consider saving more if possible.') : __('Spending exceeds income this period.')}

); }