import { cn } from '@/lib/utils'; import { useState } from 'react'; interface StatsData { totalShares: number; totalInvestment: number; averageCostPerShare: number; currentPrice?: number; currentValue?: number; profitLoss?: number; profitLossPercentage?: number; } interface StatsPanelProps { stats: StatsData; isVisible: boolean; className?: string; } export default function StatsPanel({ stats, isVisible, className }: StatsPanelProps) { const [withdrawalRate, setWithdrawalRate] = useState(0.03); // 3% default const calculateWithdrawal = (rate: number) => { if (!stats.currentValue) return 0; return stats.currentValue * rate; }; const formatCurrency = (amount: number) => { return new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR', minimumFractionDigits: 2, }).format(amount); }; const formatPercentage = (percentage: number) => { return `${percentage >= 0 ? '+' : ''}${percentage.toFixed(2)}%`; }; return (
{/* Portfolio Overview */}

Portfolio

Shares: {stats.totalShares.toFixed(6)}
Invested: {formatCurrency(stats.totalInvestment)}
Avg Cost: {formatCurrency(stats.averageCostPerShare)}
{/* Current Value */} {stats.currentPrice && (

Current Value

Price: {formatCurrency(stats.currentPrice)}
Value: {formatCurrency(stats.currentValue || 0)}
{stats.profitLoss !== undefined && (
P&L: = 0 ? "text-green-400" : "text-red-500" )}> {formatCurrency(stats.profitLoss)}
)} {stats.profitLossPercentage !== undefined && (
Return: = 0 ? "text-green-400" : "text-red-500" )}> {formatPercentage(stats.profitLossPercentage)}
)}
)} {/* Withdrawal Estimates */} {stats.currentValue && (

Annual Withdrawal

3%: {formatCurrency(calculateWithdrawal(0.03))}
4%: {formatCurrency(calculateWithdrawal(0.04))}
Custom:
setWithdrawalRate(Number(e.target.value) / 100)} className="w-12 bg-transparent text-red-400 text-right text-xs border-b border-red-500/30 focus:border-red-400 outline-none" min="0" max="10" step="0.1" /> %
{formatCurrency(calculateWithdrawal(withdrawalRate))}
)} {/* Monthly Breakdown */} {stats.currentValue && (

Monthly Income

3%: {formatCurrency(calculateWithdrawal(0.03) / 12)}
4%: {formatCurrency(calculateWithdrawal(0.04) / 12)}
Custom: {formatCurrency(calculateWithdrawal(withdrawalRate) / 12)}
)}
); }