// Canonical SF shortcut definitions used by registration, help text, and overlays.

import { formatShortcut } from "./files.js";

export type SFShortcutId = "dashboard" | "notifications" | "parallel";

type SFShortcutDef = {
  key: "g" | "n" | "p";
  action: string;
  command: string;
  /** Whether the Ctrl+Shift fallback is registered (false when it conflicts with an app keybinding). */
  hasFallback: boolean;
};

export const SF_SHORTCUTS: Record<SFShortcutId, SFShortcutDef> = {
  dashboard: {
    key: "g",
    action: "Open SF dashboard",
    command: "/sf status",
    hasFallback: true,
  },
  notifications: {
    key: "n",
    action: "Open notification history",
    command: "/sf notifications",
    hasFallback: true,
  },
  parallel: {
    key: "p",
    action: "Open parallel worker monitor",
    command: "/sf parallel watch",
    hasFallback: false, // Ctrl+Shift+P conflicts with cycleModelBackward
  },
};

function combo(prefix: "Ctrl+Alt+" | "Ctrl+Shift+", key: string): string {
  return `${prefix}${key.toUpperCase()}`;
}

export function primaryShortcutCombo(id: SFShortcutId): string {
  return combo("Ctrl+Alt+", SF_SHORTCUTS[id].key);
}

export function fallbackShortcutCombo(id: SFShortcutId): string {
  return combo("Ctrl+Shift+", SF_SHORTCUTS[id].key);
}

export function shortcutPair(id: SFShortcutId, formatter: (combo: string) => string = (combo) => combo): string {
  const primary = formatter(primaryShortcutCombo(id));
  if (!SF_SHORTCUTS[id].hasFallback) return primary;
  return `${primary} / ${formatter(fallbackShortcutCombo(id))}`;
}

export function formattedShortcutPair(id: SFShortcutId): string {
  return shortcutPair(id, formatShortcut);
}
