import { EventEmitter } from "devframe/types";

//#region src/types/commands.d.ts
interface DevToolsCommandKeybinding {
  /**
   * Keyboard shortcut string.
   * Use "Mod" for platform-aware modifier (Cmd on macOS, Ctrl elsewhere).
   * Examples: "Mod+K", "Mod+Shift+P", "Alt+N"
   */
  key: string;
}
interface DevToolsCommandBase {
  /**
   * Unique namespaced ID, e.g. "vite:open-in-editor"
   */
  id: string;
  title: string;
  description?: string;
  /**
   * Iconify icon string, e.g. "ph:pencil-duotone"
   */
  icon?: string;
  category?: string;
  /**
   * Whether to show in command palette. Default: true
   *
   * - `true` — show the command and flatten its children into search results
   * - `false` — hide the command entirely from the palette
   * - `'without-children'` — show the command but don't flatten children into top-level search (children are still accessible via drill-down)
   */
  showInPalette?: boolean | 'without-children';
  /**
   * Optional context expression for conditional visibility.
   * When set, the command is only shown in the palette and only executable
   * when the expression evaluates to true.
   *
   * Uses the same syntax as keybinding `when` clauses.
   * @example 'clientType == embedded'
   * @example 'dockOpen && !paletteOpen'
   */
  when?: string;
  /**
   * Default keyboard shortcut(s) for this command
   */
  keybindings?: DevToolsCommandKeybinding[];
}
/**
 * Server command input — what plugins pass to `ctx.commands.register()`.
 */
interface DevToolsServerCommandInput extends DevToolsCommandBase {
  /**
   * Handler for this command. Optional if the command only serves as a group for children.
   */
  handler?: (...args: any[]) => any | Promise<any>;
  /**
   * Static sub-commands. Two levels max (parent → children).
   * Each child must have a globally unique `id`.
   */
  children?: DevToolsServerCommandInput[];
}
/**
 * Serializable server command entry — sent over RPC (no handler).
 */
interface DevToolsServerCommandEntry extends DevToolsCommandBase {
  source: 'server';
  children?: DevToolsServerCommandEntry[];
}
/**
 * Client command — registered in the webcomponent context.
 */
interface DevToolsClientCommand extends DevToolsCommandBase {
  source: 'client';
  /**
   * Action for this command. Optional if the command only serves as a group for children.
   * Return sub-commands for dynamic nested palette menus (runtime submenus).
   */
  action?: (...args: any[]) => void | DevToolsClientCommand[] | Promise<void | DevToolsClientCommand[]>;
  /**
   * Static sub-commands. Two levels max (parent → children).
   */
  children?: DevToolsClientCommand[];
}
/**
 * Union of command entries visible in the palette.
 */
type DevToolsCommandEntry = DevToolsServerCommandEntry | DevToolsClientCommand;
interface DevToolsCommandHandle {
  readonly id: string;
  update: (patch: Partial<Omit<DevToolsServerCommandInput, 'id'>>) => void;
  unregister: () => void;
}
interface DevToolsCommandsHostEvents {
  'command:registered': (command: DevToolsServerCommandEntry) => void;
  'command:unregistered': (id: string) => void;
}
interface DevToolsCommandsHost {
  readonly commands: Map<string, DevToolsServerCommandInput>;
  readonly events: EventEmitter<DevToolsCommandsHostEvents>;
  /**
   * Register a command (with optional children).
   */
  register: (command: DevToolsServerCommandInput) => DevToolsCommandHandle;
  /**
   * Unregister a command by ID (removes parent and all children).
   */
  unregister: (id: string) => boolean;
  /**
   * Execute a command by ID. Searches top-level and children.
   * Throws if not found or if command has no handler.
   */
  execute: (id: string, ...args: any[]) => Promise<unknown>;
  /**
   * Returns serializable list (no handlers), preserving tree structure.
   */
  list: () => DevToolsServerCommandEntry[];
}
interface DevToolsCommandShortcutOverrides {
  /**
   * Command ID → keybinding overrides. Empty array = shortcut disabled.
   */
  [commandId: string]: DevToolsCommandKeybinding[];
}
//#endregion
//#region src/types/settings.d.ts
interface DevToolsDocksUserSettings {
  docksHidden: string[];
  docksCategoriesHidden: string[];
  docksPinned: string[];
  docksCustomOrder: Record<string, number>;
  showIframeAddressBar: boolean;
  closeOnOutsideClick: boolean;
  commandShortcuts: DevToolsCommandShortcutOverrides;
}
//#endregion
export { DevToolsCommandHandle as a, DevToolsCommandsHost as c, DevToolsServerCommandInput as d, DevToolsCommandEntry as i, DevToolsCommandsHostEvents as l, DevToolsClientCommand as n, DevToolsCommandKeybinding as o, DevToolsCommandBase as r, DevToolsCommandShortcutOverrides as s, DevToolsDocksUserSettings as t, DevToolsServerCommandEntry as u };