import { createRouter, createWebHistory } from 'vue-router'

const iot = {
  path: '/iot',
  name: '物联网',
  meta: {
    title: '物联网'
  },
  component: () => import('@/layout/layout.vue'),
  redirect: '/dashboard',
  children: [
    {
      path: '/dashboard',
      name: '首页',
      icon: 'DashboardOutlined',
      component: () => import('@/pages/iot/dashboard/deviceAccess/index.vue')
    },
    {
      path: '/product',
      name: '产品',
      redirect: '/product/index',
      icon: 'AppstoreOutlined',
      children: [
        {
          path: '/product/index',
          name: '产品模型',
          component: () => import('@/pages/iot/model/index.vue')
        },
        {
          path: '/product/models',
          name: '产品模型库',
          component: () => import('@/pages/iot/model/models.vue')
        },
        {
          path: '/product/detail',
          name: '产品模型详情',
          hidden: true,
          component: () => import('@/pages/iot/model/detail.vue')
        }
      ]
    },
    {
      path: '/device',
      name: '设备',
      redirect: '/device/index',
      icon: 'RobotOutlined',
      children: [
        {
          path: '/device/index',
          name: '所有设备',
          component: () => import('@/pages/iot/device/index.vue')
        },
        {
          path: '/device/detail',
          name: '设备详情',
          hidden: true,
          component: () => import('@/pages/iot/device/detail.vue')
        },
        {
          path: '/device/group',
          name: '设备群组',
          component: () => import('@/pages/iot/device/group.vue')
        },
        {
          path: '/device/topology',
          name: '设备拓扑',
          component: () => import('@/pages/iot/device/topology.vue')
        },
        {
          path: '/device/analysis',
          name: '设备分析',
          component: () => import('@/pages/iot/device/analysis.vue')
        }
      ]
    },
    {
      path: '/rule',
      name: '规则',
      redirect: '/rule/forward',
      icon: 'AimOutlined',
      children: [
        {
          path: '/rule/forward',
          name: '转发规则',
          component: () => import('@/pages/iot/rule/forwardRule.vue')
        },
        {
          path: '/rule/link',
          name: '联动规则',
          component: () => import('@/pages/iot/rule/linkRules.vue')
        }
      ]
    },
    {
      path: '/devOps',
      name: '监控运维',
      redirect: '/devOps/report',
      icon: 'CodeOutlined',
      children: [
        {
          path: '/devOps/report',
          name: '数据监控',
          component: () => import('@/pages/iot/devOps/statistReport.vue')
        },
        {
          path: '/devOps/onlineTest',
          name: '在线调试',
          component: () => import('@/pages/iot/devOps/onlineTest.vue')
        },
        {
          path: '/devOps/mt',
          name: '消息追踪',
          component: () => import('@/pages/iot/devOps/msgTracking.vue')
        },
        {
          path: '/devOps/nowAlert',
          name: '当前告警',
          component: () => import('@/pages/iot/devOps/nowAlert.vue')
        },
        {
          path: '/devOps/nowNotice',
          name: '当前提醒',
          component: () => import('@/pages/iot/devOps/nowNotice.vue')
        }
      ]
    },
    {
      path: '/dataServer',
      name: '数据服务',
      redirect: '/dataServer/history',
      icon: 'DatabaseOutlined',
      children: [
        {
          path: '/dataServer/history',
          name: '历史数据',
          component: () => import('@/pages/iot/dataServer/history.vue')
        },
        {
          path: '/dataServer/openApi',
          name: '开放接口',
          component: () => import('@/pages/iot/dataServer/openApi.vue')
        }
      ]
    },
    {
      path: '/task',
      name: '任务中心',
      redirect: '/task/manage',
      // <container-outlined />
      icon: 'ContainerOutlined',
      children: [
        {
          path: '/task/manage',
          name: '任务管理',
          component: () => import('@/pages/iot/task/manage.vue')
        },
        {
          path: '/task/track',
          name: '任务追踪',
          component: () => import('@/pages/iot/task/track.vue')
        }
      ]
    },
    {
      path: '/sys',
      name: '系统设置',
      redirect: '/sys/noticeway',
      icon: 'DatabaseOutlined',
      children: [
        {
          path: '/sys/noticeway',
          name: '通知方式',
          component: () => import('@/pages/iot/sys/noticeway.vue')
        },
        {
          path: '/sys/notice',
          name: '通知设置',
          component: () => import('@/pages/iot/sys/notice.vue')
        }
      ]
    },
    {
      path: '/deviceDoc',
      name: '设备接入文档',
      component: () => import('@/pages/iot/doc/deviceDoc.vue'),
      icon: 'BookOutlined'
    },
    {
      path: '/dataDoc',
      name: '数据服务文档',
      component: () => import('@/pages/iot/doc/dataDoc.vue'),
      icon: 'CoffeeOutlined'
    }
  ]
}

const rts = {
  path: '/rts',
  name: '视联网',
  meta: {
    title: '视联网'
  },
  component: () => import('@/layout/layout.vue'),
  redirect: '/stream',
  children: [
    {
      path: '/stream',
      name: '视频流管理',
      icon: 'PlayCircleOutlined',
      component: () => import('@/pages/rts/stream/index.vue')
    },
    {
      path: '/pull',
      name: '拉流管理',
      icon: 'FallOutlined',
      component: () => import('@/pages/rts/pull/index.vue')
    },
    {
      path: '/push',
      name: '推流管理',
      icon: 'RiseOutlined',
      component: () => import('@/pages/rts/push/index.vue')
    },
    {
      path: '/record',
      name: '存储配置',
      icon: 'FileAddOutlined',
      component: () => import('@/pages/rts/record/index.vue')
    },
    {
      path: '/gb28181',
      name: '国标设备',
      icon: 'CameraOutlined',
      redirect: '/gb28181/index',
      children: [
        {
          path: '/gb28181/index',
          name: '所有国标设备',
          component: () => import('@/pages/rts/gb28181/index.vue')
        },
        {
          path: '/gb28181/record',
          name: '设备录像',
          hidden: true,
          component: () => import('@/pages/rts/gb28181/record.vue')
        }
      ]
    },
    {
      path: '/protocol',
      name: '协议配置',
      icon: 'DeploymentUnitOutlined',
      component: () => import('@/pages/rts/protocol/index.vue')
    },
    {
      path: '/monitor',
      name: '系统监控',
      icon: 'ProfileOutlined',
      component: () => import('@/pages/rts/monitor/index.vue')
    }
  ]
}

const schedule = {
  path: 'http://124.222.113.37:12345/scheduler/ui',
  name: '数据中台',
  meta: {
    title: '数据中台'
  },
  link: true
}

const view = {
  path: 'http://cloudview.jiaolongcloud.com/',
  name: '可视化',
  meta: {
    title: '可视化'
  },
  link: true
}

const lowcode = {
  path: 'http://49.232.161.110:5556',
  name: '低代码',
  meta: {
    title: '低代码'
  },
  link: true
}

const user = {
  path: '/user',
  name: '用户群组',
  meta: {
    title: '用户群组'
  },
  component: () => import('@/layout/layout.vue'),
  redirect: '/manage',
  children: [
    {
      path: '/manage',
      name: '用户管理',
      icon: 'PlayCircleOutlined',
      component: () => import('@/pages/user/manage/index.vue')
    },
    {
      path: '/resource',
      name: '资源管理',
      icon: 'PlayCircleOutlined',
      component: () => import('@/pages/user/resource/index.vue')
    }
  ]
}

const login = {
  path: '/login',
  name: '登录',
  meta: {
    title: '登录'
  },
  component: () => import('@/pages/login/index.vue')
}

const _routes = [iot, rts, schedule, view, lowcode, user, login] as any

if (_routes[0].link) {
  window.open(_routes[0].path)
}

const redirectRoutes = {
  path: '/',
  name: '',
  meta: {
    title: ''
  },
  redirect: _routes[0].redirect
}

export const routes: Array<ROUTER.RoutesProps> = [redirectRoutes, ..._routes]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes: routes.map(item => {
    const _item = item.link
      ? {
          ...item,
          path: '/' + item.path
        }
      : item
    return _item
  })
})

export default router
