import {
  Bell,
  Collection,
  Connection,
  Cpu,
  Document,
  DocumentCopy,
  EditPen,
  Files,
  Histogram,
  Link,
  List,
  MapLocation,
  Monitor,
  Notebook,
  OfficeBuilding,
  Operation,
  Promotion,
  SetUp,
  Setting,
  Tools,
  User,
  Van,
  VideoCamera,
  View
} from '@element-plus/icons-vue'
import type { Component } from 'vue'

export interface NavMenuItem {
  path: string
  label: string
  icon?: Component
  key?: string
  group?: string
  children?: NavMenuItem[]
}

export const ADMIN_MENU: NavMenuItem[] = [
  { path: '/admin/dashboard', label: '总览', icon: Histogram, key: 'admin-dashboard', group: '概览' },
  {
    path: '/admin/operations', label: '运营管理', icon: Monitor, group: '概览',
    children: [
      { path: '/admin/map-monitor', label: '地图监控', icon: View, key: 'admin-map-monitor', group: '概览' },
      { path: '/admin/tasks', label: '任务管理', icon: List, key: 'admin-tasks', group: '概览' },
      { path: '/admin/alarms', label: '报警管理', icon: Bell, key: 'admin-alarms', group: '概览' }
    ]
  },
  {
    path: '/admin/design', label: '设计与编辑', icon: Tools, group: '设计与编辑',
    children: [
      { path: '/admin/maps', label: '地图管理', icon: Files, key: 'admin-maps', group: '设计与编辑' },
      { path: '/admin/map-editor', label: '地图编辑', icon: EditPen, key: 'admin-map-editor', group: '设计与编辑' },
      { path: '/admin/project-properties', label: '项目属性', icon: Document, key: 'admin-project-properties', group: '设计与编辑' },
      { path: '/admin/tracks', label: '场景管理', icon: Connection, key: 'admin-tracks', group: '设计与编辑' },
      { path: '/admin/cars', label: '车辆管理', icon: Van, key: 'admin-cars', group: '设计与编辑' },
      { path: '/admin/processes', label: '进程管理', icon: Cpu, key: 'admin-processes', group: '设计与编辑' },
      { path: '/admin/scripts', label: '脚本管理', icon: DocumentCopy, key: 'admin-scripts', group: '设计与编辑' },
      { path: '/admin/task-templates', label: '任务编排', icon: Operation, key: 'admin-task-templates', group: '设计与编辑' },
      { path: '/admin/simple-fields', label: '字段管理', icon: Collection, key: 'admin-simple-fields', group: '设计与编辑' }
    ]
  },
  {
    path: '/admin/config', label: '平台配置中心', icon: Setting, group: '平台配置中心',
    children: [
      { path: '/admin/config/strategy', label: '调度策略', icon: SetUp, key: 'admin-config-strategy', group: '平台配置中心' },
      { path: '/admin/config/vehicle-hub', label: '车辆运维', icon: Van, key: 'admin-vehicle-hub', group: '平台配置中心' },
      { path: '/admin/config/facility', label: '设备接入', icon: OfficeBuilding, key: 'admin-config-facility', group: '平台配置中心' },
      { path: '/admin/config/warehouse', label: '仓储管理', icon: OfficeBuilding, key: 'admin-config-warehouse', group: '平台配置中心' },
      { path: '/admin/config/business', label: '业务与集成', icon: Link, key: 'admin-config-business', group: '平台配置中心' },
      { path: '/admin/config/ops-center', label: '运维与回放', icon: VideoCamera, key: 'admin-config-ops-center', group: '平台配置中心' },
      { path: '/admin/config/system-center', label: '系统与权限', icon: User, key: 'admin-config-system-center', group: '平台配置中心' }
    ]
  }
]

export const MONITOR_MENU: NavMenuItem[] = [
  { path: '/monitor/dashboard', label: '运营总览', icon: Monitor, key: 'monitor-dashboard', group: '运营监控' },
  { path: '/monitor/vehicle-hub', label: '车辆运维', icon: Van, key: 'monitor-vehicle-hub', group: '运营监控' },
  { path: '/monitor/map', label: '地图监控', icon: MapLocation, key: 'monitor-map', group: '运营监控' },
  { path: '/monitor/ops', label: '运维操作', icon: Promotion, key: 'monitor-ops', group: '运营监控' },
  { path: '/monitor/notes', label: '运营备注', icon: Notebook, key: 'monitor-notes', group: '运营监控' }
]

export function flattenNavMenu(items: NavMenuItem[]): NavMenuItem[] {
  const out: NavMenuItem[] = []
  for (const item of items) {
    if (item.children?.length) out.push(...flattenNavMenu(item.children))
    else if (item.key) out.push(item)
  }
  return out
}
