/**
 * Search component type definitions
 * @countermeasure/web-components/components/search
 */

export interface SearchResult {
  /** Visible label rendered in the suggestion list. */
  label: string
  /** Underlying value passed to `onSelect`. */
  value: string
  /** Optional icon HTML rendered before the label. */
  icon?: string
  /** Secondary descriptive text rendered under the label. */
  description?: string
  /** Optional group heading for grouped suggestions. */
  group?: string
}

export interface SearchInputConfig {
  /** Container element (or selector) the input is mounted into. */
  container: HTMLElement | string
  /**
   * Placeholder text shown when the input is empty.
   * @default 'Search...'
   */
  placeholder?: string
  /**
   * Debounce delay applied before `suggest` and `onSearch` fire.
   * @default 200
   */
  debounceMs?: number
  /** Returns suggestion results for the current query. */
  suggest?: (query: string) => Promise<SearchResult[]> | SearchResult[]
  /** Called with the debounced query string. */
  onSearch?: (query: string) => void
  /** Called when the user picks a suggestion. */
  onSelect?: (result: SearchResult) => void
}

export interface CommandPaletteConfig {
  /** Available commands. */
  commands: CommandEntry[]
  /**
   * Placeholder text shown in the command input.
   * @default 'Type a command...'
   */
  placeholder?: string
  /**
   * Global keybinding that opens the palette (e.g. `'ctrl+k'`).
   * @default 'ctrl+k'
   */
  keybinding?: string
}

export interface CommandEntry {
  /** Stable unique identifier. */
  id: string
  /** Visible command label. */
  label: string
  /** Optional secondary descriptive text. */
  description?: string
  /** Optional icon HTML rendered before the label. */
  icon?: string
  /** Optional group heading. */
  group?: string
  /** Optional keybinding hint shown alongside the label. */
  keybinding?: string
  /** Function invoked when the command is activated. */
  handler: () => void
}
