import type { CommandPaletteOption } from '../../ui/components/CommandPalette'
import { t } from '#cli/i18n'

type HelpScope = 'home' | 'chat'

export function buildHelpOptions(
  opts: Readonly<{
    scope: HelpScope
    mode: string
    includeSettings?: boolean
    commandsKey?: string
  }>,
): readonly CommandPaletteOption[] {
  const modeLabel =
    String(opts.mode ?? '')
      .trim()
      .toUpperCase() || 'AGENT'

  const items: CommandPaletteOption[] = [
    {
      label: t('help.modeLabel', { mode: modeLabel }),
      detail: t('help.modeDetail'),
      keywords: ['mode', modeLabel.toLowerCase()],
    },
    {
      label: opts.commandsKey ? `Commands (${opts.commandsKey})` : 'Commands',
      detail: t('help.items.commands'),
      keywords: ['commands', 'palette', 'ctrl+p'],
    },
  ]

  if (opts.scope === 'chat') {
    items.push(
      {
        label: '/sessions',
        detail: t('chatPage.prompts.sessions'),
        keywords: ['sessions'],
      },
      {
        label: '/timeline (/tl)',
        detail: t('chatPage.prompts.timeline'),
        keywords: ['timeline', 'tl'],
      },
      {
        label: '/trace',
        detail: t('chatPage.prompts.trace'),
        keywords: ['trace', 'session', 'request'],
      },
      {
        label: '/new',
        detail: t('chatPage.prompts.newSession'),
        keywords: ['new'],
      },
      {
        label: '/resume',
        detail: t('chatPage.prompts.resume'),
        keywords: ['resume', 'queue'],
      },
      {
        label: '/compact',
        detail: t('chatPage.prompts.compact'),
        keywords: ['compact'],
      },
      {
        label: '/rename',
        detail: t('chatPage.prompts.rename'),
        keywords: ['rename'],
      },
      {
        label: '/approvals',
        detail: t('chatPage.prompts.approvals'),
        keywords: ['approvals'],
      },
      {
        label: '/mcp',
        detail: t('chatPage.prompts.mcpSettings'),
        keywords: ['mcp', 'hub', 'integration'],
      },
      {
        label: '/connect',
        detail: t('chatPage.prompts.connect'),
        keywords: ['connect'],
      },
      {
        label: '/models',
        detail: t('chatPage.prompts.models'),
        keywords: ['models'],
      },
      {
        label: '/language',
        detail: t('chatPage.prompts.language'),
        keywords: ['language', 'lang', 'locale'],
      },
      {
        label: '/theme',
        detail: t('chatPage.prompts.theme'),
        keywords: ['theme'],
      },
      {
        label: '/review',
        detail: t('chatPage.prompts.review'),
        keywords: ['review'],
      },
      {
        label: '/init',
        detail: t('chatPage.prompts.init'),
        keywords: ['init'],
      },
      {
        label: '/exit',
        detail: t('chatPage.prompts.exit'),
        keywords: ['exit', 'quit'],
      },
    )
  } else {
    items.push(
      {
        label: '/sessions',
        detail: t('homePage.prompts.sessions'),
        keywords: ['sessions'],
      },
      {
        label: '/connect',
        detail: t('homePage.prompts.connect'),
        keywords: ['connect'],
      },
      {
        label: '/models',
        detail: t('homePage.prompts.models'),
        keywords: ['models'],
      },
      {
        label: '/new',
        detail: t('homePage.prompts.newSession'),
        keywords: ['new'],
      },
      {
        label: '/approvals',
        detail: t('homePage.prompts.approvals'),
        keywords: ['approvals'],
      },
      {
        label: '/mcp',
        detail: t('homePage.prompts.mcpSettings'),
        keywords: ['mcp', 'hub', 'integration'],
      },
      {
        label: '/language',
        detail: t('homePage.prompts.language'),
        keywords: ['language', 'lang', 'locale'],
      },
      {
        label: '/theme',
        detail: t('homePage.prompts.theme'),
        keywords: ['theme'],
      },
      {
        label: '/review',
        detail: t('homePage.prompts.review'),
        keywords: ['review'],
      },
      {
        label: '/init',
        detail: t('homePage.prompts.init'),
        keywords: ['init'],
      },
      {
        label: '/exit',
        detail: t('homePage.prompts.exit'),
        keywords: ['exit', 'quit'],
      },
    )
  }

  if (opts.includeSettings) {
    items.push({
      label: '/settings',
      detail:
        opts.scope === 'chat'
          ? t('chatPage.prompts.settings')
          : t('homePage.prompts.settings'),
      keywords: ['settings', 'config'],
    })
  }

  return items
}
