import React from 'react'; interface UsageProgressBarProps { label: string; current: number; limit: number; unit?: string; showOverage?: boolean; } export const UsageProgressBar: React.FC = ({ label, current, limit, unit = '', showOverage = true, }) => { const isUnlimited = limit === -1; const percent = isUnlimited ? 0 : Math.min((current / limit) * 100, 100); const overage = !isUnlimited && current > limit ? current - limit : 0; const getColorClass = () => { if (isUnlimited) return 'bg-gray-400'; if (percent >= 100) return 'bg-red-500'; if (percent >= 80) return 'bg-yellow-500'; return 'bg-blue-500'; }; const formatValue = (value: number) => { if (value >= 1000000) return `${(value / 1000000).toFixed(1)}M`; if (value >= 1000) return `${(value / 1000).toFixed(1)}K`; return value.toString(); }; return (
{label} {formatValue(current)} {unit && ` ${unit}`} {!isUnlimited && ( <> {' / '} {formatValue(limit)} {unit && ` ${unit}`} )} {isUnlimited && ' (ilimitado)'}
{isUnlimited ? 'Sin lĂ­mite' : `${percent.toFixed(1)}% usado`} {showOverage && overage > 0 && ( +{formatValue(overage)} excedente )}
); };