import { cn } from '@/lib/utils'; import { Plus, ChevronRight } from 'lucide-react'; import { useState } from 'react'; import ComponentTitle from '@/components/ui/ComponentTitle'; 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[]; selectedMilestoneIndex?: number; onMilestoneSelect?: (index: number) => void; className?: string; onAddPurchase?: () => void; onAddMilestone?: () => void; onUpdatePrice?: () => void; } export default function StatsBox({ stats, milestones = [], selectedMilestoneIndex = 0, onMilestoneSelect, className, onAddPurchase, onAddMilestone, onUpdatePrice }: StatsBoxProps) { const [isDropdownOpen, setIsDropdownOpen] = useState(false); const handleCycleMilestone = () => { if (milestones.length === 0 || !onMilestoneSelect) return; const nextIndex = (selectedMilestoneIndex + 1) % milestones.length; onMilestoneSelect(nextIndex); }; 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 (
{/* STATS Title and Current Price */}
Stats
{stats.currentPrice && (
VWCE: {formatCurrencyDetailed(stats.currentPrice)}
)} {/* Action Dropdown */}
{/* Dropdown Menu */} {isDropdownOpen && (
{onAddPurchase && ( )} {onAddMilestone && ( )} {onUpdatePrice && ( )}
)}
{/* Milestone Cycle Button */} {milestones.length > 1 && ( )}
{/* Milestone Table */}
MILESTONES
{/* Current position row */} {/* Render milestones after current */} {milestones.map((milestone, index) => { const swr3 = stats.currentPrice ? milestone.target * stats.currentPrice * 0.03 : 0; const swr4 = stats.currentPrice ? milestone.target * stats.currentPrice * 0.04 : 0; const isSelectedMilestone = index === selectedMilestoneIndex; return ( ); })}
DESCRIPTION SHARES SWR 3% SWR 4%
CURRENT {Math.floor(stats.totalShares).toLocaleString()} {stats.currentPrice ? formatCurrency(stats.totalShares * stats.currentPrice * 0.03) : 'N/A'} {stats.currentPrice ? formatCurrency(stats.totalShares * stats.currentPrice * 0.04) : 'N/A'}
{milestone.description} {Math.floor(milestone.target).toLocaleString()} {stats.currentPrice ? formatCurrency(swr3) : 'N/A'} {stats.currentPrice ? formatCurrency(swr4) : 'N/A'}
); }