import { cn } from '@/lib/utils';
import { Plus } from 'lucide-react';
interface Milestone {
target: number;
description: string;
created_at: string;
}
interface StatsBoxProps {
stats: {
totalShares: number;
totalInvestment: number;
averageCostPerShare: number;
currentPrice?: number;
currentValue?: number;
profitLoss?: number;
profitLossPercentage?: number;
};
milestones?: Milestone[];
className?: string;
onAddPurchase?: () => void;
onAddMilestone?: () => void;
}
export default function StatsBox({
stats,
milestones = [],
className,
onAddPurchase,
onAddMilestone
}: StatsBoxProps) {
const formatCurrency = (amount: number) => {
return new Intl.NumberFormat('de-DE', {
style: 'currency',
currency: 'EUR',
minimumFractionDigits: 2,
maximumFractionDigits: 2,
}).format(amount);
};
const formatCurrencyDetailed = (amount: number) => {
return new Intl.NumberFormat('de-DE', {
style: 'currency',
currency: 'EUR',
minimumFractionDigits: 4,
}).format(amount);
};
return (
{/* Current Price */}
{stats.currentPrice && (
current price
{formatCurrencyDetailed(stats.currentPrice)}
)}
{/* Portfolio Stats Grid */}
{/* Total Investment */}
Total Investment
{formatCurrency(stats.totalInvestment)}
{/* Current Value */}
{stats.currentValue && (
Current Value
{formatCurrency(stats.currentValue)}
)}
{/* Average Cost */}
Avg Cost/Share
{formatCurrencyDetailed(stats.averageCostPerShare)}
{/* Profit/Loss */}
{stats.profitLoss !== undefined && (
P&L
= 0 ? "text-green-400" : "text-red-400"
)}>
{stats.profitLoss >= 0 ? '+' : ''}{formatCurrency(stats.profitLoss)}
)}
{/* Withdrawal Estimates */}
{stats.currentValue && (
Annual Withdrawal (Safe)
3% Rule
{formatCurrency(stats.currentValue * 0.03)}
4% Rule
{formatCurrency(stats.currentValue * 0.04)}
)}
{/* Milestones */}
{milestones.length > 0 && (
Milestones
{milestones.map((milestone, index) => {
const isReached = stats.totalShares >= milestone.target;
return (
{milestone.target.toLocaleString()}
{milestone.description}
);
})}
)}
{/* Action Buttons */}
{/* Add Purchase Button */}
{onAddPurchase && (
)}
{/* Add Milestone Button */}
{onAddMilestone && (
)}
);
}