// Command palette command registry.
// 集中维护 Cmd+K 命令面板的命令项；保持纯数据 + onSelect 回调。

import type { LucideIcon } from 'lucide-react'
import {
  FileText,
  Sparkles,
  Download,
  Inbox,
  MessageSquare,
  Compass,
  ShieldCheck,
  Settings as SettingsIcon,
  PanelRightOpen,
  PanelLeftOpen,
} from 'lucide-react'

export type CommandCategory = 'create' | 'import' | 'navigate' | 'view'

export interface CommandItem {
  id: string
  label: string
  category: CommandCategory
  icon: LucideIcon
  shortcut?: string
  keywords?: string[]
  run: () => void
}

export const CATEGORY_LABEL: Record<CommandCategory, string> = {
  create: '新建',
  import: '导入',
  navigate: '跳转',
  view: '视图',
}

export interface CommandContext {
  // 业务回调，由调用方注入
  onCreateManual: () => void
  onCreateProposal: () => void
  onImportSession: () => void
  onNavigateInbox: () => void
  onNavigateSessions: () => void
  onNavigateIndex: () => void
  onNavigateLint: () => void
  onNavigateSettings: () => void
  onOpenPopover: () => void
  onOpenMain: () => void
}

export function buildCommands(ctx: CommandContext): CommandItem[] {
  return [
    // 新建
    {
      id: 'create.manual',
      label: '手动记录',
      category: 'create',
      icon: FileText,
      shortcut: '⌘N',
      keywords: ['record', 'manual', '手动', '记录', 'new'],
      run: ctx.onCreateManual,
    },
    {
      id: 'create.proposal',
      label: 'AI 提议',
      category: 'create',
      icon: Sparkles,
      shortcut: '⇧⌘N',
      keywords: ['propose', 'ai', '提议', 'candidate', '候选'],
      run: ctx.onCreateProposal,
    },
    // 导入
    {
      id: 'import.session',
      label: '从会话导入',
      category: 'import',
      icon: Download,
      shortcut: '⌘I',
      keywords: ['import', 'session', '会话', '导入'],
      run: ctx.onImportSession,
    },
    // 跳转
    {
      id: 'nav.inbox',
      label: 'Inbox',
      category: 'navigate',
      icon: Inbox,
      shortcut: 'g i',
      keywords: ['inbox', '收件', '审核'],
      run: ctx.onNavigateInbox,
    },
    {
      id: 'nav.sessions',
      label: '会话',
      category: 'navigate',
      icon: MessageSquare,
      shortcut: 'g s',
      keywords: ['sessions', '会话', 'chat'],
      run: ctx.onNavigateSessions,
    },
    {
      id: 'nav.index',
      label: '导航',
      category: 'navigate',
      icon: Compass,
      shortcut: 'g n',
      keywords: ['index', 'navigation', '导航'],
      run: ctx.onNavigateIndex,
    },
    {
      id: 'nav.lint',
      label: '健康',
      category: 'navigate',
      icon: ShieldCheck,
      shortcut: 'g h',
      keywords: ['lint', 'health', '健康', '检查'],
      run: ctx.onNavigateLint,
    },
    {
      id: 'nav.settings',
      label: '设置',
      category: 'navigate',
      icon: SettingsIcon,
      shortcut: '⌘,',
      keywords: ['settings', '设置', 'preferences'],
      run: ctx.onNavigateSettings,
    },
    // 视图
    {
      id: 'view.popover',
      label: '打开 Popover',
      category: 'view',
      icon: PanelRightOpen,
      shortcut: '⇧⌘P',
      keywords: ['popover', 'tray', '托盘'],
      run: ctx.onOpenPopover,
    },
    {
      id: 'view.main',
      label: '打开主面板',
      category: 'view',
      icon: PanelLeftOpen,
      shortcut: '⇧⌘M',
      keywords: ['main', 'panel', '主面板'],
      run: ctx.onOpenMain,
    },
  ]
}
