import { Link } from "react-router-dom"; import { ArrowRight, TrendingUp, TrendingDown } from "lucide-react"; import { Card, CardContent } from "@/components/ui/card"; import { cn } from "@/lib/utils"; import { usePrivacy } from "@/lib/privacy"; import { formatMoney } from "@/lib/format"; interface CurrencyBreakdown { value: number; gain: number; gainPct: number; } interface Props { name: string; icon: React.ReactNode; to: string; portfolioValue: number; totalGain: number; totalGainPct: number; holdingsCount: number; currency: string; connected: boolean; /** Optional action buttons rendered in the card header (e.g. rename/delete for manual accounts). */ actions?: React.ReactNode; /** * When an account holds multiple currencies, pass a per-currency breakdown * so we avoid displaying a cross-currency sum. When present and length > 1, * the single-figure display is replaced with a stacked per-currency view. */ currencyBreakdown?: Record; } function fmt(v: number, c: string) { return formatMoney(v, c, { decimals: 2 }); } export function SourceCard({ name, icon, to, portfolioValue, totalGain, totalGainPct, holdingsCount, currency, connected, actions, currencyBreakdown }: Props) { // Local formatter reads privacy mode; subscribe so toggling it re-renders. usePrivacy(); const isPositive = totalGain >= 0; const breakdownEntries = currencyBreakdown ? Object.entries(currencyBreakdown) : []; const isMixed = breakdownEntries.length > 1; return (
{icon}

{name}

{connected ? "Connected" : "Disconnected"}
{actions}
{isMixed ? ( <>
{breakdownEntries.map(([c, bd]) => (

{fmt(bd.value, c)}

))}
{breakdownEntries.map(([c, bd]) => (
{bd.gain >= 0 ? : } = 0 ? "text-chart-green" : "text-chart-red")}> {bd.gain >= 0 ? "+" : ""}{fmt(bd.gain, c)} ({bd.gainPct >= 0 ? "+" : ""}{bd.gainPct.toFixed(2)}%)
))}
{holdingsCount} holdings
) : ( <>

{fmt(portfolioValue, currency)}

{isPositive ? : } {isPositive ? "+" : ""}{fmt(totalGain, currency)} ({isPositive ? "+" : ""}{totalGainPct.toFixed(2)}%)
{holdingsCount} holdings
)}
); }