/* Copyright (C) 2023-2026 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 { ArrowDownRight, ArrowUpRight, ExternalLink, Trophy, } from 'lucide-react' import { useTranslation } from 'react-i18next' import { cn } from '@/lib/utils' import { StaticDataTable, staticDataTableClassNames as tableStyles, } from '@/components/data-table' import { buildAppRankings, formatTokenVolume, type AppRanking, } from '../lib/mock-stats' import type { PricingModel } from '../types' const COMPACT_NUMBER = new Intl.NumberFormat(undefined, { notation: 'compact', maximumFractionDigits: 1, }) function RankBadge(props: { rank: number }) { const rank = props.rank const isPodium = rank <= 3 const palette = rank === 1 ? 'bg-amber-100 text-amber-700 dark:bg-amber-500/20 dark:text-amber-300' : rank === 2 ? 'bg-slate-100 text-slate-700 dark:bg-slate-500/20 dark:text-slate-300' : rank === 3 ? 'bg-orange-100 text-orange-700 dark:bg-orange-500/20 dark:text-orange-300' : 'bg-muted text-muted-foreground' return ( {isPodium ? : rank} ) } function GrowthChip(props: { value: number }) { const value = props.value const isUp = value > 0 const isDown = value < 0 const palette = isUp ? 'bg-emerald-100 text-emerald-700 dark:bg-emerald-500/20 dark:text-emerald-300' : isDown ? 'bg-rose-100 text-rose-700 dark:bg-rose-500/20 dark:text-rose-300' : 'bg-muted text-muted-foreground' const Icon = isUp ? ArrowUpRight : isDown ? ArrowDownRight : null const formatted = `${value > 0 ? '+' : ''}${value.toFixed(1)}%` return ( {Icon && } {formatted} ) } function AppLink(props: { app: AppRanking }) { if (!props.app.url) { return {props.app.name} } return ( {props.app.name} ) } export function ModelDetailsApps(props: { model: PricingModel }) { const { t } = useTranslation() const apps = useMemo(() => buildAppRankings(props.model, 12), [props.model]) if (apps.length === 0) { return (
{t('No app usage data available for this model.')}
) } const totalMonthlyTokens = apps.reduce((s, a) => s + a.monthly_tokens, 0) const top = apps[0] return (
{t('Tracked apps')}
{apps.length}

{t('Top integrations using this model')}

{t('Monthly tokens')}
{COMPACT_NUMBER.format(totalMonthlyTokens)}

{t('Aggregated across the apps below')}

{t('#1 by usage')}
{top.name}

{top.category} ยท {formatTokenVolume(top.monthly_tokens)}{' '} {t('tokens / mo')}

`${app.rank}-${app.name}`} columns={[ { id: 'rank', header: '#', className: cn(tableStyles.compactHeaderCell, 'w-12'), cellClassName: tableStyles.compactCell, cell: (app) => , }, { id: 'app', header: t('App'), className: tableStyles.compactHeaderCell, cellClassName: tableStyles.compactCell, cell: (app) => (
{app.initial}

{app.description}

), }, { id: 'category', header: t('Category'), className: cn( tableStyles.compactHeaderCell, 'hidden md:table-cell' ), cellClassName: cn( tableStyles.compactMutedCell, 'hidden md:table-cell' ), cell: (app) => app.category, }, { id: 'monthly-tokens', header: t('Monthly tokens'), className: tableStyles.compactHeaderCellRight, cellClassName: cn(tableStyles.compactNumericCell, 'tabular-nums'), cell: (app) => formatTokenVolume(app.monthly_tokens), }, { id: 'growth', header: t('30d change'), className: tableStyles.compactHeaderCellRight, cellClassName: cn(tableStyles.compactCell, 'text-right'), cell: (app) => , }, ]} />

{t( 'App rankings shown here are simulated for preview purposes and will be replaced with live usage data once the backend integration is complete.' )}

) }