"use client"; import { cn } from "@/lib/utils"; interface UsageProgressProps { label: string; current: number; limit: number; unit?: string; className?: string; } export function UsageProgress({ label, current, limit, unit = "", className }: UsageProgressProps) { const isUnlimited = limit === -1; const percentage = isUnlimited ? 0 : limit > 0 ? Math.min((current / limit) * 100, 100) : 0; const isWarning = !isUnlimited && percentage > 80; const isCritical = !isUnlimited && percentage > 95; const barColor = isCritical ? "bg-red-500" : isWarning ? "bg-amber-500" : "bg-primary"; const textColor = isCritical ? "text-red-600" : isWarning ? "text-amber-600" : "text-gray-900"; return (
{isCritical ? "额度即将用尽" : "额度使用已超过80%"}
)}