/* Copyright (C) 2025 QuantumNous This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . For commercial licensing, please contact support@quantumnous.com */ import { useMemo } from 'react'; import { Wallet, Activity, Gauge, Cpu } from 'lucide-react'; import { IconMoneyExchangeStroked, IconHistogram, IconPulse, IconStopwatchStroked, IconTypograph, IconSend, } from '@/components/ui/icons'; import { renderNumber, renderQuota } from '../../helpers'; import { createSectionTitle } from '../../helpers/dashboard'; export const useDashboardStats = ( userState, consumeQuota, consumeTokens, times, performanceMetrics, navigate, t, tokenUsage = null, ) => { const groupedStatsData = useMemo( () => [ { title: createSectionTitle(Wallet, t('钱包概况')), color: 'bg-blue-50', items: [ { title: t('可用余额'), value: renderQuota(userState?.user?.quota), icon: , avatarColor: 'blue', }, { title: t('累计支出'), value: renderQuota(userState?.user?.used_quota), icon: , avatarColor: 'purple', }, ], }, { title: createSectionTitle(Activity, t('调用活跃度')), color: 'bg-green-50', items: [ { title: t('总调用次数'), value: userState.user?.request_count, icon: , avatarColor: 'green', }, { title: t('有效记录'), value: times, icon: , avatarColor: 'cyan', }, ], }, ...(tokenUsage ? [ { title: createSectionTitle(Cpu, t('Token 流量')), color: 'bg-amber-50', layout: 'two-column', items: [ { title: t('输入 Token'), value: renderNumber(tokenUsage.input_tokens || 0), icon: , avatarColor: 'blue', }, { title: t('输出 Token'), value: renderNumber(tokenUsage.output_tokens || 0), icon: , avatarColor: 'green', }, { title: t('缓存命中'), value: renderNumber(tokenUsage.cache_tokens || 0), icon: , avatarColor: 'cyan', }, { title: t('缓存写入'), value: renderNumber(tokenUsage.cache_creation_tokens || 0), icon: , avatarColor: 'orange', }, ], }, ] : []), { title: createSectionTitle(Gauge, t('实时速率')), color: 'bg-brand/5', items: [ { title: t('请求速率'), value: performanceMetrics.avgRPM, icon: , avatarColor: 'indigo', }, { title: t('Token 速率'), value: performanceMetrics.avgTPM, icon: , avatarColor: 'orange', }, ], }, ], [ userState?.user?.quota, userState?.user?.used_quota, userState?.user?.request_count, times, performanceMetrics, tokenUsage, t, ], ); return { groupedStatsData, }; };