'use client' import type { FC } from 'react' import React from 'react' import { useTranslation } from 'react-i18next' import ProgressBar from '../progress-bar' import { NUM_INFINITE } from '../config' import Tooltip from '@/app/components/base/tooltip' import cn from '@/utils/classnames' type Props = { className?: string Icon: any name: string tooltip?: string usage: number total: number unit?: string unitPosition?: 'inline' | 'suffix' } const LOW = 50 const MIDDLE = 80 const UsageInfo: FC = ({ className, Icon, name, tooltip, usage, total, unit, unitPosition = 'suffix', }) => { const { t } = useTranslation() const percent = usage / total * 100 const color = (() => { if (percent < LOW) return 'bg-components-progress-bar-progress-solid' if (percent < MIDDLE) return 'bg-components-progress-warning-progress' return 'bg-components-progress-error-progress' })() const isUnlimited = total === NUM_INFINITE let totalDisplay: string | number = isUnlimited ? t('billing.plansCommon.unlimited') : total if (!isUnlimited && unit && unitPosition === 'inline') totalDisplay = `${total}${unit}` const showUnit = !!unit && !isUnlimited && unitPosition === 'suffix' return (
{name}
{tooltip && ( {tooltip}
} /> )}
{usage}
/
{totalDisplay}
{showUnit && (
{unit}
)}
) } export default React.memo(UsageInfo)