import { useMemo } from 'react'; import { useTranslation } from 'react-i18next'; import { useTrafficZone } from '../../hooks/useTrafficZone'; import { formatTraffic } from '../../utils/formatTraffic'; import { useTheme } from '../../hooks/useTheme'; import { getGlassColors } from '../../utils/glassTheme'; interface TrafficProgressBarProps { usedGb: number; limitGb: number; percent: number; isUnlimited: boolean; compact?: boolean; } const THRESHOLDS = [50, 75, 90]; export default function TrafficProgressBar({ usedGb: _usedGb, limitGb, percent, isUnlimited, compact = false, }: TrafficProgressBarProps) { const { t } = useTranslation(); const { isDark } = useTheme(); const g = getGlassColors(isDark); const zone = useTrafficZone(percent); // Gradient always starts from the accent color (normal zone) const startColor = 'rgb(var(--color-accent-400))'; const clampedPercent = Math.min(percent, 100); const barHeight = compact ? 8 : 14; // Multi-segment gradient matching prototype // Warning/danger hex colors are intentional — they represent fixed threshold tints, // not theme-dynamic values, and must remain distinct from the zone-based mainVar. const fillGradient = useMemo(() => { if (percent < 50) return `linear-gradient(90deg, ${startColor}, ${zone.mainVar})`; if (percent < 75) return `linear-gradient(90deg, ${startColor}, rgb(var(--color-warning-400)), ${zone.mainVar})`; if (percent < 90) return `linear-gradient(90deg, ${startColor}, rgb(var(--color-warning-400)), rgb(var(--color-warning-300)), ${zone.mainVar})`; return `linear-gradient(90deg, ${startColor}, rgb(var(--color-warning-400)), rgb(var(--color-warning-300)), rgb(var(--color-error-400)))`; }, [percent, zone.mainVar, startColor]); if (isUnlimited) { return (