import { SettingsCard, SettingsSection } from '@emdash/ui/react/patterns'; import { CountdownTime, Heading, Icon, Meter, Text } from '@emdash/ui/react/primitives'; import { AgentIcon } from '@core/features/agents/contributions/browser/agent-icon'; import type { UsageAccountView } from '../api/schemas'; type LimitWindow = UsageAccountView['windows'][number]; const percent = (value: number) => `${Number(value.toFixed(1))}%`; const providerName = (id: string) => (id === 'claude' ? 'Claude' : id === 'codex' ? 'Codex' : id); const windowName = (window: LimitWindow) => window.label.replace(/(^| ยท )5-hour$/, '$1Session'); export function usageAccountTitle(view: UsageAccountView): string { const plan = view.account.plan ?.trim() .replace(/^(?:claude|codex|chatgpt)\s+/i, '') .replace(/\s+subscription$/i, '') .replaceAll('_', ' '); const name = providerName(view.providerId); const subscription = plan ? `${name} ${plan.charAt(0).toUpperCase()}${plan.slice(1)}` : name; const identity = view.account.organization?.trim() || view.account.email?.trim(); return identity ? `${subscription} (${identity})` : subscription; } export function UsageAccountSection({ view, title }: { view: UsageAccountView; title: string }) { return (
{title}
{view.windows.length ? ( view.windows.map((window) => ( )) ) : ( {view.message ?? 'Subscription limits are unavailable.'} )}
); } function LimitRow({ window, title }: { window: LimitWindow; title: string }) { const remaining = window.usedPercent === null ? null : 100 - window.usedPercent; const label = windowName(window); const reset = window.resetsAt === null ? ( 'Reset time unavailable' ) : ( ); return (
{label} {window.stale && ( Stale )}
{remaining === null ? (
Usage unavailable {reset}
) : ( )}
); }