import { useMemo } from 'react'; import { useTranslation } from 'react-i18next'; import { Progress, Tag } from 'antd'; import { ClockCircleOutlined, ThunderboltOutlined } from '@ant-design/icons'; import './SubUsageSummary.css'; interface SubUsageSummaryProps { usedByte: number; totalByte: number; usedLabel: string; totalLabel: string; remainedLabel: string; expireMs: number; isActive: boolean; } function pickStrokeColor(pct: number): { from: string; to: string } { if (pct >= 90) return { from: '#ff7875', to: '#ff4d4f' }; if (pct >= 75) return { from: '#ffc53d', to: '#fa8c16' }; return { from: '#5fc983', to: '#36b37e' }; } function formatExpiryChip(expireMs: number): { label: string; color: string } | null { if (expireMs <= 0) return null; const diff = expireMs - Date.now(); if (diff <= 0) return { label: 'Expired', color: 'red' }; const days = Math.floor(diff / 86400000); if (days >= 1) return { label: `${days}d`, color: days <= 3 ? 'orange' : 'blue' }; const hours = Math.max(1, Math.floor(diff / 3600000)); return { label: `${hours}h`, color: 'orange' }; } export default function SubUsageSummary({ usedByte, totalByte, usedLabel, totalLabel, remainedLabel, expireMs, isActive, }: SubUsageSummaryProps) { const { t } = useTranslation(); const pct = useMemo(() => { if (totalByte <= 0) return 0; const v = (usedByte / totalByte) * 100; if (!Number.isFinite(v)) return 0; return Math.max(0, Math.min(100, v)); }, [usedByte, totalByte]); const expiry = formatExpiryChip(expireMs); const isUnlimited = totalByte <= 0; const stroke = pickStrokeColor(pct); return (