import React from 'react'; import { Card, CardContent, Typography, Box, LinearProgress, Chip, IconButton, Tooltip, } from '@mui/material'; import { motion } from 'framer-motion'; import { DollarSign, RefreshCw, Info } from 'lucide-react'; // Types import { UsageStats } from '../../types/billing'; // Utils import { formatCurrency, formatNumber, formatPercentage, getUsageStatusIcon, calculateUsagePercentage } from '../../services/billingService'; interface BillingOverviewProps { usageStats: UsageStats; onRefresh: () => void; } const BillingOverview: React.FC = ({ usageStats, onRefresh }) => { // Debug logs removed to reduce console noise const costUsagePercentage = calculateUsagePercentage( usageStats.total_cost, usageStats.limits.limits.monthly_cost || 1 ); // Debug logs removed to reduce console noise const getStatusChip = () => { const status = usageStats.usage_status; const icon = getUsageStatusIcon(status); let chipColor: 'default' | 'primary' | 'secondary' | 'error' | 'info' | 'success' | 'warning' = 'default'; if (status === 'active') chipColor = 'success'; else if (status === 'warning') chipColor = 'warning'; else if (status === 'limit_reached') chipColor = 'error'; return ( {icon}} label={status.charAt(0).toUpperCase() + status.slice(1).replace('_', ' ')} color={chipColor} size="small" sx={{ fontWeight: 'bold' }} /> ); }; return ( {/* Header */} Billing Overview {/* Status Chip */} {getStatusChip()} {/* Current Cost */} {formatCurrency(usageStats.total_cost)} Total Cost This Month {/* Usage Metrics */} API Calls {formatNumber(usageStats.total_calls)} Tokens Used {formatNumber(usageStats.total_tokens)} Avg Response Time {usageStats.avg_response_time.toFixed(0)}ms {/* Cost Usage Progress */} {usageStats.limits.limits.monthly_cost > 0 && ( Monthly Cost Limit {formatPercentage(costUsagePercentage)} 80 ? '#ef4444' : costUsagePercentage > 60 ? '#f59e0b' : '#22c55e', borderRadius: 4, } }} /> {formatCurrency(usageStats.total_cost)} of {formatCurrency(usageStats.limits.limits.monthly_cost)} limit )} {/* Plan Information */} Current Plan {usageStats.limits.plan_name} {usageStats.limits.tier.charAt(0).toUpperCase() + usageStats.limits.tier.slice(1)} Tier {/* Quick Stats */} {usageStats.usage_percentages.gemini_calls.toFixed(0)}% Gemini Usage {usageStats.error_rate.toFixed(1)}% Error Rate {/* Decorative Elements */} ); }; export default BillingOverview;