import * as React from "react" import { CountingNumber } from "@/components/animate-ui/primitives/texts/counting-number" import { useUser } from "@/contexts/user-context" /** 颜色配置 - 统一管理主题色 */ const COLORS = { available: "bg-primary/80", pending: "bg-zinc-400/80", emptyState: "bg-muted/50", } as const /** * 计算积分余额百分比 */ function calculatePercentages(available: number, total: number) { if (total <= 0) { return { available: 0, pending: 0 } } const pending = total - available return { available: (available / total) * 100, pending: (pending / total) * 100, } } /** * 安全转换数字,避免 NaN */ function safeNumber(value: number): number { return typeof value === 'number' && !isNaN(value) ? value : 0 } /** * 积分余额摘要组件 * * 显示积分余额的可视化摘要,包括可视化进度条和详细的积分余额分类列表 */ export function BalanceSummary() { const { user, loading } = useUser() const available = parseFloat(user?.available_balance || '0') const pending = parseFloat(user?.pending_balance || '0') const total = available + pending const percentages = React.useMemo( () => calculatePercentages(available, total), [available, total] ) return (