import type ApiNavigationElement from '../../elements/amf/ApiNavigation.element.js'
import type { NavigationLayout } from '../types.js'
import type { ContextMenuCommand } from '../../elements/contextual-menu/internals/types.js'

const commands: ContextMenuCommand[] = [
  {
    target: 'all',
    label: 'Expand all',
    execute: (ctx): void => {
      const menu = ctx.root as ApiNavigationElement
      menu.expandAll()
    },
  },
  {
    target: 'all',
    label: 'Collapse all',
    execute: (ctx): void => {
      const menu = ctx.root as ApiNavigationElement
      menu.collapseAll()
    },
  },
  {
    target: 'endpoints',
    label: 'Expand all endpoints',
    execute: (ctx): void => {
      const menu = ctx.root as ApiNavigationElement
      menu.expandAllEndpoints()
    },
  },
  {
    target: 'endpoints',
    label: 'Collapse all endpoints',
    execute: (ctx): void => {
      const menu = ctx.root as ApiNavigationElement
      menu.collapseAllEndpoints()
    },
  },
  {
    target: 'endpoints',
    label: 'Layout',
    execute: (ctx): void => {
      const { item } = ctx
      if (!item.id) {
        return
      }
      const menu = ctx.root as ApiNavigationElement
      if (item.id === 'off') {
        menu.layout = undefined
      } else {
        menu.layout = item.id as NavigationLayout
      }
    },
    children: [
      {
        label: 'None',
        id: 'off',
      },
      {
        label: 'Tree',
        id: 'tree',
      },
      {
        label: 'Natural',
        id: 'natural',
      },
      {
        label: 'Natural (sorted)',
        id: 'natural-sort',
      },
    ],
  },
]
export default commands
