import type { LucideIcon } from 'lucide-react'
import {
  BarChart3,
  Bell,
  BookOpen,
  BrainCircuit,
  Building2,
  ClipboardList,
  FileText,
  GitPullRequest,
  HelpCircle,
  LayoutDashboard,
  Monitor,
  Package,
  PlayCircle,
  Radar,
  Rocket,
  Settings,
  ShieldCheck,
  Terminal,
} from 'lucide-react'

export type ProductNavItem = {
  id: string
  href: string
  labelKey: string
  Icon: LucideIcon
  aliases?: string[]
  relatedPaths?: string[]
  exact?: boolean
  badge?: boolean
  surface?: 'primary' | 'secondary'
  children?: ProductNavChild[]
}

export type ProductNavSection = {
  sectionKey: string
  items: ProductNavItem[]
}

export type ProductNavChild = {
  id: string
  href: string
  labelKey: string
  exact?: boolean
  badge?: boolean
}

export type WorkflowNavItem = {
  labelKey: string
  href: string
  exact?: boolean
}

// Canonical product IA map. This is the single source for the global shell; page
// layouts can reference this map for titles and context, but must not recreate
// a second navigation tree.
export const PRODUCT_NAV_SECTIONS: ProductNavSection[] = [
  {
    sectionKey: 'workspaces',
    items: [
      { id: 'command-center', href: '/', labelKey: 'commandCenter', Icon: LayoutDashboard },
      {
        id: 'awooop-overview',
        href: '/awooop',
        labelKey: 'awooopWarRoom',
        Icon: BrainCircuit,
        exact: true,
        children: [
          { id: 'aiops-timeline', href: '/aiops/timeline', labelKey: 'aiopsTimeline' },
          { id: 'openclaw-live-ops-space', href: '/openclaw/live-ops-space', labelKey: 'openclawLiveOps' },
        ],
      },
      {
        id: 'observability',
        href: '/observability',
        labelKey: 'observabilityCommandCenter',
        Icon: Monitor,
        aliases: ['/monitoring', '/apm', '/errors', '/apps', '/services', '/topology', '/alerts', '/alert-operation-logs', '/notifications'],
        children: [
          { id: 'monitoring', href: '/monitoring', labelKey: 'monitoring' },
          { id: 'apm', href: '/apm', labelKey: 'apm' },
          { id: 'errors', href: '/errors', labelKey: 'errors' },
          { id: 'apps', href: '/apps', labelKey: 'apps' },
          { id: 'services', href: '/services', labelKey: 'services' },
          { id: 'topology', href: '/topology', labelKey: 'topology' },
          { id: 'alerts', href: '/alerts', labelKey: 'alerts' },
          { id: 'alert-operation-logs', href: '/alert-operation-logs', labelKey: 'alertOperationLogs' },
          { id: 'notifications', href: '/notifications', labelKey: 'notifications' },
        ],
      },
    ],
  },
  {
    sectionKey: 'queues',
    items: [
      {
        id: 'awooop-work-items',
        href: '/awooop/work-items',
        labelKey: 'workItems',
        Icon: ClipboardList,
      },
      {
        id: 'knowledge-automation',
        href: '/knowledge-base',
        labelKey: 'knowledgeAutomation',
        Icon: BookOpen,
        aliases: ['/knowledge', '/automation', '/auto-repair', '/drift', '/neural-command'],
        children: [
          { id: 'knowledge', href: '/knowledge', labelKey: 'knowledge' },
          { id: 'automation', href: '/automation', labelKey: 'automation' },
          { id: 'auto-repair', href: '/auto-repair', labelKey: 'autoRepair' },
          { id: 'drift', href: '/drift', labelKey: 'drift' },
          { id: 'neural-command', href: '/neural-command', labelKey: 'neuralCommand' },
        ],
      },
      {
        id: 'awooop-tenants',
        href: '/awooop/tenants',
        labelKey: 'assetInventory',
        Icon: Building2,
      },
      {
        id: 'code-review',
        href: '/code-review',
        labelKey: 'codeReview',
        Icon: GitPullRequest,
      },
      {
        id: 'awooop-runs',
        href: '/awooop/runs',
        labelKey: 'runMonitor',
        Icon: PlayCircle,
        surface: 'secondary',
      },
      {
        id: 'awooop-approvals',
        href: '/awooop/approvals',
        labelKey: 'approvalQueue',
        Icon: ShieldCheck,
        aliases: ['/authorizations'],
        badge: true,
        surface: 'secondary',
        children: [
          { id: 'authorizations', href: '/authorizations', labelKey: 'authorizations' },
        ],
      },
      {
        id: 'awooop-contracts',
        href: '/awooop/contracts',
        labelKey: 'contracts',
        Icon: FileText,
        surface: 'secondary',
      },
    ],
  },
  {
    sectionKey: 'monitoring',
    items: [
      {
        id: 'delivery',
        href: '/delivery',
        labelKey: 'delivery',
        Icon: Rocket,
      },
      {
        id: 'iwooos-security',
        href: '/iwooos',
        labelKey: 'iwooos',
        Icon: ShieldCheck,
        aliases: ['/security-compliance'],
        relatedPaths: ['/security', '/compliance', '/governance'],
        children: [
          { id: 'security-compliance', href: '/security-compliance', labelKey: 'securityCompliance' },
          { id: 'security', href: '/security', labelKey: 'security' },
          { id: 'compliance', href: '/compliance', labelKey: 'compliance' },
          { id: 'governance', href: '/governance', labelKey: 'governance' },
        ],
      },
      {
        id: 'operations',
        href: '/operations',
        labelKey: 'operationsOverview',
        Icon: Package,
        aliases: ['/deployments', '/tickets', '/cost', '/billing', '/action-logs', '/reports'],
        children: [
          { id: 'deployments', href: '/deployments', labelKey: 'deployments' },
          { id: 'tickets', href: '/tickets', labelKey: 'tickets' },
          { id: 'cost', href: '/cost', labelKey: 'cost' },
          { id: 'billing', href: '/billing', labelKey: 'billing' },
          { id: 'action-logs', href: '/action-logs', labelKey: 'actions' },
          { id: 'reports', href: '/reports', labelKey: 'reports' },
        ],
      },
      {
        id: 'settings',
        href: '/settings',
        labelKey: 'settings',
        Icon: Settings,
        aliases: ['/users'],
        children: [
          { id: 'users', href: '/users', labelKey: 'users' },
        ],
      },
    ],
  },
  {
    sectionKey: 'system',
    items: [
      {
        id: 'alerts',
        href: '/alerts',
        labelKey: 'alerts',
        Icon: Bell,
        aliases: ['/alert-operation-logs', '/notifications'],
        surface: 'secondary',
      },
      {
        id: 'reports',
        href: '/reports',
        labelKey: 'reports',
        Icon: BarChart3,
        surface: 'secondary',
      },
      { id: 'terminal', href: '/terminal', labelKey: 'terminal', Icon: Terminal, surface: 'secondary' },
      {
        id: 'classic',
        href: '/classic',
        labelKey: 'classicAICenter',
        Icon: Radar,
        surface: 'secondary',
        aliases: ['/demo'],
        children: [
          { id: 'demo', href: '/demo', labelKey: 'demo' },
        ],
      },
    ],
  },
]

export const PRODUCT_BOTTOM_NAV_ITEMS: ProductNavItem[] = [
  { id: 'help', href: '/help', labelKey: 'help', Icon: HelpCircle },
]

export const AWOOOP_WORKFLOW_ITEMS: WorkflowNavItem[] = [
  {
    labelKey: 'overview',
    href: '/awooop',
    exact: true,
  },
  {
    labelKey: 'workItems',
    href: '/awooop/work-items',
  },
  {
    labelKey: 'runs',
    href: '/awooop/runs',
  },
  {
    labelKey: 'approvals',
    href: '/awooop/approvals',
  },
  {
    labelKey: 'contracts',
    href: '/awooop/contracts',
  },
  {
    labelKey: 'tenants',
    href: '/awooop/tenants',
  },
]
