import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { apiConfig } from '@/config/api.config'; import { useCallApi } from '@/hooks'; import { CreditCard, Wallet } from 'lucide-react'; import { useEffect, useState } from 'react'; type WalletResponse = { amount: number; id_wallet: string; wallet: string; credit_limit: number; monthly_limit: number; }; interface BalanceCardProps { id: string; } const API_URL_WALLET = apiConfig.service_wallet; const BalanceCard = ({ id }: BalanceCardProps) => { const { GetData } = useCallApi(); const [wallets, setWallets] = useState([]); const formatCurrency = (value: number) => { return new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(value); }; const formatNumberWithDots = (value: number) => { return value.toLocaleString('id-ID'); }; const getColorClass = (amount: number) => { if (amount > 0) return 'bg-amber-300'; if (amount > 500) return 'bg-blue-500'; return 'bg-red-500'; }; useEffect(() => { async function fetchAccountBalances() { try { const response = await GetData(`${API_URL_WALLET}/dashboard/balance/account/${id}`, { id: id }); if (response?.status === true) { setWallets(response.data); } } catch (error) { console.error('Error fetching account balances', error); } } fetchAccountBalances(); }, [id]); return (
{wallets.map((wallet) => { const colorClass = getColorClass(wallet.amount); const isNegative = wallet.amount < 0; return (

{wallet.wallet}

{wallet.wallet.includes('Credit') ? ( ) : ( )}

{formatCurrency(wallet.amount)}

Credit Limit:
{formatNumberWithDots(wallet.credit_limit)}
Monthly Limit:
{formatNumberWithDots(wallet.monthly_limit)}
); })}
); }; export default BalanceCard;