import React, { useState } from 'react'; import { createPortal } from 'react-dom'; import { X, DollarSign, TrendingUp, TrendingDown, Download, Search, Filter } from 'lucide-react'; const FinancialSummaryModal = ({ isOpen, onClose, role, data }) => { const [searchTerm, setSearchTerm] = useState(''); const [sortConfig, setSortConfig] = useState({ key: 'date', direction: 'desc' }); // Close on Escape key React.useEffect(() => { const handleKeyDown = (e) => { if (e.key === 'Escape') onClose(); }; if (isOpen) { window.addEventListener('keydown', handleKeyDown); } return () => window.removeEventListener('keydown', handleKeyDown); }, [isOpen, onClose]); if (!isOpen || !data) return null; const formatCurrency = (amount) => { return new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(amount); }; const handleSort = (key) => { let direction = 'asc'; if (sortConfig.key === key && sortConfig.direction === 'asc') { direction = 'desc'; } setSortConfig({ key, direction }); }; // Filter and sort data const filteredData = (data.items || []).filter(item => item.description?.toLowerCase().includes(searchTerm.toLowerCase()) || item.project?.toLowerCase().includes(searchTerm.toLowerCase()) ); const sortedData = [...filteredData].sort((a, b) => { if (a[sortConfig.key] < b[sortConfig.key]) { return sortConfig.direction === 'asc' ? -1 : 1; } if (a[sortConfig.key] > b[sortConfig.key]) { return sortConfig.direction === 'asc' ? 1 : -1; } return 0; }); return createPortal(
{role === 'CONTRACTOR' ? 'Total Budget Managed' : 'Total Earned (YTD)'}: {formatCurrency(data.total || 0)}
{formatCurrency(data.paid || data.total || 0)}
{formatCurrency(data.spent || data.pending || 0)}
{formatCurrency(data.remaining || data.total || 0)}
{item.description || item.project}
{item.project &&{item.project}
}| handleSort(col.key)} className={`px-6 py-4 text-xs font-bold uppercase tracking-wider text-zinc-500 cursor-pointer hover:text-zinc-700 dark:hover:text-zinc-300 transition-colors ${col.align === 'right' ? 'text-right' : ''}`} > {col.label} | ))}|||
|---|---|---|---|
| {item.date} |
{item.description || item.project}
{item.project && {item.project} }
|
{item.status} | {formatCurrency(item.amount)} |
| No transactions found. | |||