import React, { useState, useMemo } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import { ChevronDown, ChevronUp, Plus, Search, TrendingUp, TrendingDown, Trash2, PieChart as PieIcon, BarChart3, Info } from 'lucide-react'; import { AreaChart, Area, XAxis, YAxis, Tooltip, ResponsiveContainer, ReferenceLine } from 'recharts'; import InvestmentCommittee from './InvestmentCommittee'; export default function HoldingsList({ allocation, prices, onAddClick, onAssetClick, onRemoveAsset }) { const [expandedId, setExpandedId] = useState(null); const [searchTerm, setSearchTerm] = useState(''); const filteredAllocation = useMemo(() => { return allocation.filter(asset => asset.ticker.toLowerCase().includes(searchTerm.toLowerCase()) || asset.name.toLowerCase().includes(searchTerm.toLowerCase()) ); }, [allocation, searchTerm]); const toggleExpand = (ticker) => { setExpandedId(expandedId === ticker ? null : ticker); }; return (
{/* Header section matching the user's requested layout */}

Portfolio Holdings

setSearchTerm(e.target.value)} className="pl-10 pr-4 py-2 bg-white border border-gray-200 rounded-xl text-sm focus:outline-none focus:ring-2 focus:ring-gs-gold/30 focus:border-gs-gold transition-all w-full md:w-64 shadow-sm" />
{/* Table Header */}
{filteredAllocation.length > 0 ? ( filteredAllocation.map((asset) => ( toggleExpand(asset.ticker)} onRemove={() => onRemoveAsset(asset.ticker)} /> )) ) : ( )}
Asset Price Shares Value Avg Cost Gain/Loss Return Alloc

No holdings found matching your search.

); } function HoldingRow({ asset, priceData, isExpanded, onToggle, onRemove }) { const currentPrice = priceData?.price || 0; const marketValue = asset.shares * currentPrice; const totalCost = asset.shares * (asset.avgCost || 0); const gainLoss = marketValue - totalCost; const returnPct = (totalCost > 0 && !isNaN(gainLoss)) ? (gainLoss / totalCost) * 100 : 0; const isPositive = gainLoss >= 0; return ( <> {/* Asset Column */}
{asset.ticker?.substring(0, 2) || '??'}
{asset.ticker} {asset.type === 'mf' ? 'ETF' : 'STOCK'}

{asset.name}

{priceData?.percent !== undefined && !isNaN(priceData.percent) && (
= 0 ? 'text-green-600' : 'text-red-500'}`}> {priceData.percent >= 0 ? '▲' : '▼'} {Math.abs(priceData.percent).toFixed(2)}% today
)}
{/* Price Column */}

${currentPrice.toFixed(2)}

{/* Shares Column */}

{asset.shares}

{/* Value Column */}

${marketValue.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 })}

{/* Avg Cost Column */}

${(asset.avgCost || 0).toFixed(2)}

{/* Gain/Loss Column */}

{isPositive ? '+' : ''}${Math.abs(gainLoss).toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 })}

{/* Return Column */}
{isPositive ? '+' : ''}{returnPct.toFixed(2)}%
{/* Alloc Column */}
{asset.value.toFixed(1)}%
{/* Actions/Expand Column */} e.stopPropagation()}>
{/* Expanded Section */} {isExpanded && (
{/* Visual Analysis */}

Price Performance

Real-time market tracking for {asset.ticker}

1 Month

Volatility

Moderate

Buy Price

${(asset.avgCost || 0).toFixed(2)}

Hold Since

{new Date(asset.dateBought).toLocaleDateString()}

{/* AI Analysis Sidebar */}

AI Investment Thesis

)}
); }