import React from 'react'; import { cn } from '../../utils/classNames'; interface UsageMeterProps { used: number; limit: number; unlimited?: boolean; label?: string; className?: string; } /** A compact usage bar: "X of Y messages" with a progress fill that warns as it fills. */ const UsageMeter: React.FC = ({ used, limit, unlimited = false, label = 'Messages used', className }) => { const ratio = unlimited || limit <= 0 ? 0 : Math.min(1, used / limit); const pct = Math.round(ratio * 100); const tone = ratio >= 1 ? 'bg-danger' : ratio >= 0.85 ? 'bg-warning' : 'bg-brand'; return (
{label} {unlimited ? 'Unlimited' : `${used.toLocaleString()} / ${limit.toLocaleString()}`}
{!unlimited && (
)}
); }; export default UsageMeter;