export interface HelpSection {
  id: string
  label: string
  items: HelpItem[]
}

export interface HelpItem {
  id: string
  label: string
  path?: string
  content?: string
  relatedPath?: string
}

export interface SearchableItem {
  id: string
  label: string
  path?: string
  type: 'navigate' | 'learn' | 'action' | 'goal'
  section: string
  content?: string
  relatedPath?: string
}

export const helpTree: HelpSection[] = [
  {
    id: 'navigate',
    label: 'Navigate',
    items: [
      { id: 'home', label: 'Home', path: '/dashboard' },
      { id: 'apps', label: 'My Apps', path: '/dashboard/apps' },
      { id: 'marketplace', label: 'App Store', path: '/dashboard/marketplace' },
      { id: 'cloud', label: 'Cloud', path: '/dashboard/cloud' },
      { id: 'server', label: 'Network', path: '/dashboard/server' },
      { id: 'web5', label: 'Web5', path: '/dashboard/web5' },
      { id: 'settings', label: 'Settings', path: '/dashboard/settings' },
    ],
  },
  {
    id: 'learn',
    label: 'Learn',
    items: [
      {
        id: 'bitcoin-basics',
        label: 'Bitcoin Basics',
        content: 'Bitcoin is a decentralized digital currency. Your node validates transactions and maintains the blockchain locally.',
        relatedPath: '/dashboard/server',
      },
      {
        id: 'lightning-network',
        label: 'Lightning Network',
        content: 'Lightning enables instant, low-fee payments. Open channels with other nodes to send and receive payments off-chain.',
        relatedPath: '/dashboard/apps',
      },
      {
        id: 'self-hosting',
        label: 'Self-Hosting',
        content: 'Archipelago runs your services locally. Your data stays on your hardware, giving you full control and privacy.',
        relatedPath: '/dashboard',
      },
    ],
  },
  {
    id: 'actions',
    label: 'Actions',
    items: [
      { id: 'open-cli', label: 'Open CLI', path: '__cli__' },
      { id: 'install-app', label: 'Install an App', path: '/dashboard/marketplace' },
      { id: 'manage-apps', label: 'Manage My Apps', path: '/dashboard/apps' },
      { id: 'network-settings', label: 'Network Settings', path: '/dashboard/server' },
      { id: 'backup', label: 'Backup & Recovery', path: '/dashboard/settings' },
    ],
  },
  {
    id: 'goals',
    label: 'Quick Start Goals',
    items: [
      { id: 'goal-shop', label: 'Open a Shop', path: '/dashboard/goals/open-a-shop' },
      { id: 'goal-payments', label: 'Accept Payments', path: '/dashboard/goals/accept-payments' },
      { id: 'goal-photos', label: 'Store My Photos', path: '/dashboard/goals/store-photos' },
      { id: 'goal-files', label: 'Store My Files', path: '/dashboard/goals/store-files' },
      { id: 'goal-lightning', label: 'Run a Lightning Node', path: '/dashboard/goals/run-lightning-node' },
      { id: 'goal-identity', label: 'Create My Identity', path: '/dashboard/goals/create-identity' },
      { id: 'goal-backup', label: 'Back Up Everything', path: '/dashboard/goals/back-up-everything' },
    ],
  },
]

export function flattenForSearch(): SearchableItem[] {
  const result: SearchableItem[] = []
  for (const section of helpTree) {
    const type =
      section.id === 'navigate'
        ? 'navigate'
        : section.id === 'learn'
          ? 'learn'
          : section.id === 'goals'
            ? 'goal'
            : 'action'
    for (const item of section.items) {
      result.push({
        id: item.id,
        label: item.label,
        path: item.path,
        type,
        section: section.label,
        content: item.content,
        relatedPath: item.relatedPath,
      })
    }
  }
  return result
}
