import { Bitcoin, History, Plus, Trash2 } from "lucide-react"; import { formatCurrency } from "@/lib/format"; import { useTranslation } from "@/lib/i18n"; import type { CryptoHolding } from "@/types"; interface CryptoHoldingsTableProps { items: CryptoHolding[]; onTrade: (holding: CryptoHolding) => void; onViewHistory: (holding: CryptoHolding) => void; onDelete: (holding: CryptoHolding) => void; } function PercentCell({ value }: { value: string | null }) { if (value === null) return —; const num = Number(value); const color = num > 0 ? "var(--success)" : num < 0 ? "var(--danger)" : "var(--text-muted)"; return ( {num > 0 ? "+" : ""} {num.toFixed(2)}% ); } export function CryptoHoldingsTable({ items, onTrade, onViewHistory, onDelete }: CryptoHoldingsTableProps) { const { t } = useTranslation(); if (items.length === 0) { return

{t("crypto.empty")}

; } return (
{items.map((holding) => { const profitColor = holding.profit_loss === null ? undefined : Number(holding.profit_loss) > 0 ? "var(--success)" : Number(holding.profit_loss) < 0 ? "var(--danger)" : "var(--text-muted)"; const sign = holding.profit_loss !== null && Number(holding.profit_loss) > 0 ? "+" : ""; return ( ); })}
{t("crypto.table.name")} {t("crypto.table.price")} {t("crypto.table.change1h")} {t("crypto.table.change24h")} {t("crypto.table.change7d")} {t("crypto.table.holdings")} {t("crypto.table.avgBuyPrice")} {t("crypto.table.profitLoss")} {t("crypto.table.actions")}
{holding.thumb_url ? ( ) : ( )} {holding.name} {holding.symbol}
{holding.current_price !== null ? formatCurrency(holding.current_price) : t("crypto.pendingPrice")} {holding.value !== null ? formatCurrency(holding.value) : t("crypto.pendingPrice")} {Number(holding.quantity)} {holding.symbol} {holding.avg_buy_price !== null ? formatCurrency(holding.avg_buy_price) : "—"} {holding.profit_loss !== null && holding.profit_loss_percent !== null ? ( <> {sign} {formatCurrency(holding.profit_loss)} {sign} {holding.profit_loss_percent.toFixed(2)}% ) : ( — )}
); }