import React, { useEffect, useState } from 'react'; import { FaCheckCircle, FaClock, FaHourglassHalf, FaTasks, FaChevronDown, FaPlus, FaUserPlus, FaFilter, FaCalendarAlt } from 'react-icons/fa'; import { useNavigate } from 'react-router-dom'; // Define a type for card data interface CardData { title: string; count: number; icon: JSX.Element; gradient: string; shadowColor: string; iconBg: string; textColor: string; percentage?: number; trend?: 'up' | 'down' | 'stable'; } // interface CardData { // title: string; // count: number; // icon: React.ReactNode; // gradient: string; // shadowColor: string; // iconBg: string; // textColor: string; // trend: 'up' | 'down'; // } interface CardsProps { type?: 'dashboard' | 'account' | 'transactions'; onOpenModal?: () => void; dashboardData: any; fromDate: string; toDate: string; onDateRangeChange: (range: { from: string; to: string }) => void; cards: CardData[]; isLoading: boolean } const AccountData: CardData[] = [ { title: 'Active Accounts', count: 12, icon: , gradient: 'bg-gradient-to-br from-blue-50 to-blue-100', shadowColor: 'shadow-blue-200/50', iconBg: 'bg-blue-100 border-blue-200', textColor: 'text-blue-700', trend: 'up' }, { title: 'In-Progress', count: 8, icon: , gradient: 'bg-gradient-to-br from-purple-50 to-purple-100', shadowColor: 'shadow-purple-200/50', iconBg: 'bg-purple-100 border-purple-200', textColor: 'text-purple-700', trend: 'stable' }, { title: 'Completed', count: 27, icon: , gradient: 'bg-gradient-to-br from-green-50 to-green-100', shadowColor: 'shadow-green-200/50', iconBg: 'bg-green-100 border-green-200', textColor: 'text-green-700', trend: 'up' }, { title: 'Inactive', count: 5, icon: , gradient: 'bg-gradient-to-br from-gray-50 to-gray-100', shadowColor: 'shadow-gray-200/50', iconBg: 'bg-gray-100 border-gray-200', textColor: 'text-gray-700', trend: 'down' }, ]; const filters = ['Last 7 Days', 'Last 30 Days', 'Last 6 Months', 'This Year']; const accounts = ['All Accounts', 'Account 1', 'Account 2', 'Account 3']; const Cards: React.FC = ({ type = 'dashboard', onOpenModal, onDateRangeChange, cards, isLoading }) => { const navigate = useNavigate(); const [selectedFilter, setSelectedFilter] = useState('Last 7 Days'); // const [isLoading, setIsLoading] = useState(true); // useEffect(() => { // setIsLoading(true); // setTimeout(() => { // if (type == 'account') { // setShowCards(AccountData); // } else { // setShowCards(cards); // } // setIsLoading(false); // }, 500); // }, [type]); useEffect(() => { if (type == 'dashboard') { const now = new Date(); let fromDate = new Date(); switch (selectedFilter) { case 'Last 7 Days': fromDate.setDate(now.getDate() - 7); break; case 'Last 30 Days': fromDate.setDate(now.getDate() - 30); break; case 'Last 6 Months': fromDate.setMonth(now.getMonth() - 6); break; case 'This Year': fromDate = new Date(now.getFullYear(), 0, 1); break; default: fromDate.setDate(now.getDate() - 7); } const from = fromDate.toISOString().split('T')[0]; const to = now.toISOString().split('T')[0]; onDateRangeChange({ from, to }); } }, [selectedFilter]); const getButtonConfig = () => { switch (type) { case 'account': return { text: 'Add Account', icon: , gradient: 'bg-gradient-to-r from-blue-600 to-blue-700 hover:from-blue-700 hover:to-blue-800' }; case 'transactions': return { text: 'Send Invite', icon: , gradient: 'bg-gradient-to-r from-emerald-600 to-emerald-700 hover:from-emerald-700 hover:to-emerald-800' }; default: return null; } }; const buttonConfig = getButtonConfig(); const renderTrendIndicator = (trend: string | undefined, percentage: number | undefined) => { if (!trend || !percentage) return null; const trendColors = { up: 'text-emerald-500', down: 'text-red-500', stable: 'text-gray-500' }; const trendSymbols = { up: '↗', down: '↘', stable: '→' }; return ( {trendSymbols[trend as keyof typeof trendSymbols]} {/* {percentage}% */} ); }; return ( {/* Cards */} {isLoading ? ( {/* */} {[...Array(4)].map((_, i) => ( ))} ) : ( {cards.map((card, index) => ( navigate(card.navigateTo)} className={`flex items-center justify-between bg-white px-4 py-3.5 transition-all duration-300 cursor-pointer ${index > 0 ? "border-l-1 border-gray-200" : ""}`} style={{ animationDelay: `${index * 100}ms`, }} > {/* Left side: Icon + Title */} {card.icon} {card.title} {/* Count */} {card.count} ))} )} ); }; export default Cards;
{card.count}