"use client"; import React from "react"; import { ChartBarIcon, ExclamationTriangleIcon } from "@heroicons/react/24/outline"; export interface SimUsage { account: string; todayUsageKb: number; todayUsageMb: number; recentDaysUsage: Array<{ date: string; usageKb: number; usageMb: number; }>; isBlacklisted: boolean; } interface DataUsageChartProps { usage: SimUsage; remainingQuotaMb: number; isLoading?: boolean; error?: string | null; embedded?: boolean; // when true, render content without card container } export function DataUsageChart({ usage, remainingQuotaMb, isLoading, error, embedded = false, }: DataUsageChartProps) { const formatUsage = (usageMb: number) => { if (usageMb >= 1000) { return `${(usageMb / 1000).toFixed(1)} GB`; } return `${usageMb.toFixed(0)} MB`; }; const getUsageColor = (percentage: number) => { if (percentage >= 90) return "bg-red-500"; if (percentage >= 75) return "bg-yellow-500"; if (percentage >= 50) return "bg-orange-500"; return "bg-green-500"; }; const getUsageTextColor = (percentage: number) => { if (percentage >= 90) return "text-red-600"; if (percentage >= 75) return "text-yellow-600"; if (percentage >= 50) return "text-orange-600"; return "text-green-600"; }; if (isLoading) { return (
); } if (error) { return (

Error Loading Usage Data

{error}

); } // Calculate total usage from recent days (assume it includes today) const totalRecentUsage = usage.recentDaysUsage.reduce((sum, day) => sum + day.usageMb, 0) + usage.todayUsageMb; const totalQuota = remainingQuotaMb + totalRecentUsage; const usagePercentage = totalQuota > 0 ? (totalRecentUsage / totalQuota) * 100 : 0; return (
{/* Header */}

Data Usage

Current month usage and remaining quota

{/* Content */}
{/* Current Usage Overview */}
Used this month {formatUsage(totalRecentUsage)} of {formatUsage(totalQuota)}
{/* Progress Bar */}
0% {usagePercentage.toFixed(1)}% used 100%
{/* Today's Usage */}
{formatUsage(usage.todayUsageMb)}
Used today
{formatUsage(remainingQuotaMb)}
Remaining
{/* Recent Days Usage */} {usage.recentDaysUsage.length > 0 && (

Recent Usage History

{usage.recentDaysUsage.slice(0, 5).map((day, index) => { const dayPercentage = totalQuota > 0 ? (day.usageMb / totalQuota) * 100 : 0; return (
{new Date(day.date).toLocaleDateString("en-US", { month: "short", day: "numeric", })}
{formatUsage(day.usageMb)}
); })}
)} {/* Warnings */} {usagePercentage >= 90 && (

High Usage Warning

You have used {usagePercentage.toFixed(1)}% of your data quota. Consider topping up to avoid service interruption.

)} {usagePercentage >= 75 && usagePercentage < 90 && (

Usage Notice

You have used {usagePercentage.toFixed(1)}% of your data quota. Consider monitoring your usage.

)}
); }