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'; // Terminal Theme import { TerminalCard, TerminalCardContent, TerminalTypography, TerminalChip, TerminalChipSuccess, TerminalChipError, TerminalChipWarning, terminalColors } from '../SchedulerDashboard/terminalTheme'; interface BillingOverviewProps { usageStats: UsageStats; onRefresh: () => void; terminalTheme?: boolean; } const BillingOverview: React.FC = ({ usageStats, onRefresh, terminalTheme = false }) => { // Conditional component selection based on terminal theme const CardComponent = terminalTheme ? TerminalCard : Card; const CardContentComponent = terminalTheme ? TerminalCardContent : CardContent; const TypographyComponent = terminalTheme ? TerminalTypography : Typography; // 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: string = usageStats.usage_status; const icon = getUsageStatusIcon(status); // Helper function to format status label const formatStatusLabel = (statusStr: string): string => { return statusStr.charAt(0).toUpperCase() + statusStr.slice(1).replace('_', ' '); }; if (terminalTheme) { if (status === 'active') { return ( {icon}} label={formatStatusLabel(status)} size="small" sx={{ fontWeight: 'bold' }} /> ); } else if (status === 'warning') { return ( {icon}} label={formatStatusLabel(status)} size="small" sx={{ fontWeight: 'bold' }} /> ); } else if (status === 'limit_reached') { return ( {icon}} label={formatStatusLabel(status)} size="small" sx={{ fontWeight: 'bold' }} /> ); } return ( {icon}} label={formatStatusLabel(status)} size="small" sx={{ fontWeight: 'bold' }} /> ); } 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={formatStatusLabel(status)} color={chipColor} size="small" sx={{ fontWeight: 'bold' }} /> ); }; const cardStyles = terminalTheme ? { height: '100%', backgroundColor: terminalColors.background, border: `1px solid ${terminalColors.border}`, borderRadius: 3, position: 'relative' as const, overflow: 'hidden' as const } : { height: '100%', background: 'linear-gradient(135deg, rgba(255,255,255,0.1) 0%, rgba(255,255,255,0.05) 100%)', backdropFilter: 'blur(10px)', border: '1px solid rgba(255,255,255,0.1)', borderRadius: 3, position: 'relative' as const, overflow: 'hidden' as const }; 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 ? terminalColors.error : costUsagePercentage > 60 ? terminalColors.warning : terminalColors.success) : (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 - only show in non-terminal theme */} {!terminalTheme && ( <> )} ); }; export default BillingOverview;