import { cn } from '@/lib/utils';
import { Plus } from 'lucide-react';
import { useState } from '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;
onUpdatePrice?: () => void;
}
export default function StatsBox({
stats,
milestones = [],
className,
onAddPurchase,
onAddMilestone,
onUpdatePrice
}: StatsBoxProps) {
const [isDropdownOpen, setIsDropdownOpen] = useState(false);
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 Table */}
MILESTONES
| DESCRIPTION |
SHARES |
SWR 3% |
SWR 4% |
{/* Create combined array with current position and milestones, sorted by target */}
{[
...milestones.map(m => ({ ...m, isCurrent: false })),
{
target: stats.totalShares,
description: 'CURRENT',
created_at: '',
isCurrent: true
}
]
.sort((a, b) => a.target - b.target)
.map((item, index) => {
const swr3 = stats.currentPrice ? item.target * stats.currentPrice * 0.03 : 0;
const swr4 = stats.currentPrice ? item.target * stats.currentPrice * 0.04 : 0;
return (
= item.target
? "text-green-400/80"
: "text-red-400/70"
)}
>
|
{item.isCurrent ? (
{item.description}
) : (
item.description
)}
|
{Math.floor(item.target).toLocaleString()}
|
{stats.currentPrice ? formatCurrency(swr3) : 'N/A'}
|
{stats.currentPrice ? formatCurrency(swr4) : 'N/A'}
|
);
})}
);
}