"use client"; import { useAppStore } from "@/components/state-provider"; import type { CommandPanelMode } from "@/lib/commands/types"; import type { ConfigurableShortcutId } from "@/lib/keyboard/shortcut-overrides"; import { getShortcut } from "@/lib/keyboard/shortcut-overrides"; import { formatShortcut } from "@/lib/keyboard/utils"; import { cn } from "@/lib/utils"; import { useTranslation } from "react-i18next"; export type CommandPanelScopeMode = "commands" | "search-files" | "search-content"; type ScopeOption = { mode: CommandPanelScopeMode; /** * Catalog key, resolved at render. `mode` stays the untranslated * discriminant — it is compared with `===` in `isCommandPanelScopeMode` and * threaded through the command-panel state. */ labelKey: string; shortcutId: ConfigurableShortcutId; }; const SCOPE_OPTIONS: ScopeOption[] = [ { mode: "commands", labelKey: "common:scopeCommands", shortcutId: "SEARCH" }, { mode: "search-files", labelKey: "common:scopeFiles", shortcutId: "FILE_SEARCH" }, { mode: "search-content", labelKey: "common:scopeContents", shortcutId: "CONTENT_SEARCH", }, ]; export function isCommandPanelScopeMode(mode: CommandPanelMode): mode is CommandPanelScopeMode { return SCOPE_OPTIONS.some((scope) => scope.mode === mode); } export function getAdjacentCommandPanelScope( mode: CommandPanelScopeMode, reverse = false, ): CommandPanelScopeMode { const currentIndex = SCOPE_OPTIONS.findIndex((scope) => scope.mode === mode); const offset = reverse ? -1 : 1; const nextIndex = (currentIndex + offset + SCOPE_OPTIONS.length) % SCOPE_OPTIONS.length; return SCOPE_OPTIONS[nextIndex].mode; } export function CommandPanelScopeSwitcher({ mode, onScopeChange, }: { mode: CommandPanelScopeMode; onScopeChange: (mode: CommandPanelScopeMode) => void; }) { const { t } = useTranslation(); const keyboardShortcuts = useAppStore((state) => state.userSettings.keyboardShortcuts); return (
{SCOPE_OPTIONS.map((scope) => { const active = mode === scope.mode; const shortcut = formatShortcut(getShortcut(scope.shortcutId, keyboardShortcuts)); const label = t(scope.labelKey); return ( ); })}
); }