/**
 * DropdownMenu type definitions
 * @countermeasure/web-components/navigation/dropdown-menu
 */

export interface MenuItem {
  /** Item kind — controls rendering and selection behaviour. */
  type: 'item' | 'separator' | 'checkbox' | 'radio-group'
  /** Visible label for the item. Omit for separators. */
  label?: string
  /** Optional icon HTML rendered before the label. */
  icon?: string
  /** Keyboard shortcut hint displayed at the trailing edge. */
  shortcut?: string
  /**
   * Disable interaction.
   * @default false
   */
  disabled?: boolean
  /**
   * Initial checked state for `checkbox` items.
   * @default false
   */
  checked?: boolean
  /** Underlying value for radio items. */
  value?: string
  /** Nested submenu entries. */
  children?: MenuItem[]
  /** Called when the item is selected. */
  onSelect?: () => void
}

export interface MenuRadioItem {
  /** Visible label. */
  label: string
  /** Underlying value emitted when this radio item is selected. */
  value: string
  /**
   * Disable selection.
   * @default false
   */
  disabled?: boolean
}

export interface MenuRadioGroup {
  /** Discriminator for radio groups. */
  type: 'radio-group'
  /** Radio item entries within this group. */
  items: MenuRadioItem[]
  /** Initially selected radio value. */
  value?: string
  /** Called when the selected radio value changes. */
  onChange?: (value: string) => void
}

export type DropdownMenuItem = MenuItem | MenuRadioGroup

export type DropdownPlacement = 'bottom-start' | 'bottom-end' | 'top-start' | 'top-end'

export interface DropdownMenuConfig {
  /** Container element (or selector) the menu is mounted into. */
  container: HTMLElement | string
  /** Element that toggles menu visibility. */
  trigger: HTMLElement
  /** Menu entries rendered in order. */
  items: DropdownMenuItem[]
  /**
   * Preferred placement relative to the trigger.
   * @default 'bottom-start'
   */
  placement?: DropdownPlacement
  /** Additional CSS class names. */
  className?: string
  /** Called when the menu opens. */
  onOpen?: () => void
  /** Called when the menu closes. */
  onClose?: () => void
}
