1import type { KeybindingCommand, ResolvedKeybindingsConfig } from "@t3tools/contracts";
2import type { UsageChartMetric } from "./UsageProviderChart";
3import { resolveShortcutCommand, type ShortcutEventLike } from "../../keybindings";
4
5export type UsageMetric = UsageChartMetric;
6export const METRIC_OPTIONS = [
7 { value: "cost", label: "Cost", command: "usage.cost" },
8 { value: "tokens", label: "Tokens", command: "usage.tokens" },
9] as const satisfies readonly { value: UsageMetric; label: string; command: KeybindingCommand }[];
10
11export const WINDOW_OPTIONS = [
12 { days: 1, label: "Past 24h", command: "usage.period.day" },
13 { days: 7, label: "7 days", command: "usage.period.week" },
14 { days: 30, label: "30 days", command: "usage.period.month" },
15 { days: 90, label: "90 days", command: "usage.period.quarter" },
16] as const;
17
18/** Resolves page shortcuts without taking letters from fields or popup controls. */
19export function resolveUsageShortcut(
20 event: ShortcutEventLike & { target: EventTarget | null },
21 keybindings: ResolvedKeybindingsConfig,
22) {
23 const target = event.target;
24 if (
25 target instanceof HTMLElement &&
26 (target.tagName === "INPUT" ||
27 target.tagName === "TEXTAREA" ||
28 target.tagName === "SELECT" ||
29 target.isContentEditable ||
30 target.closest('[role="dialog"], [aria-modal="true"], [data-slot$="popup"]'))
31 ) {
32 return null;
33 }
34
35 return resolveShortcutCommand(event, keybindings, {
36 context: { usagePageOpen: true },
37 });
38}