"use client"; import { Activity, ChevronRight } from "lucide-react"; import { Card, CardContent, CardHeader, CardTitle, Skeleton } from "../../../../shadcnui"; import { MeterInterface, MeterSummaryInterface } from "../../stripe-usage"; type BillingUsageSummaryCardProps = { meters: MeterInterface[]; summaries: Record; loading?: boolean; error?: string; onViewDetailsClick: () => void; }; function formatNumber(value: number): string { return new Intl.NumberFormat(undefined, { notation: "compact", compactDisplay: "short", }).format(value); } export function BillingUsageSummaryCard({ meters, summaries, loading, error, onViewDetailsClick, }: BillingUsageSummaryCardProps) { if (loading) { return ( Usage This Month ); } if (error) { return ( Usage This Month

{error}

); } // Calculate total usage across all meters const totalUsage = Object.values(summaries).reduce((acc, summary) => { return acc + (summary?.aggregatedValue || 0); }, 0); // Get first meter with data for display const primaryMeter = meters.find((m) => summaries[m.id]?.aggregatedValue); const primarySummary = primaryMeter ? summaries[primaryMeter.id] : null; return ( Usage This Month {meters.length === 0 ? (

No meters

No usage meters are configured

) : (

{formatNumber(totalUsage)} units

{primaryMeter && primarySummary && (

{primaryMeter.displayName}: {formatNumber(primarySummary.aggregatedValue)}

)} {meters.length > 1 &&

Across {meters.length} meters

} View details
)}
); }