import vueRouter, { NavigationFailure, RouteRecordRaw, 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: '数据服务',
      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: '/ota',
      name: 'OTA程序包',
      icon: 'FolderAddOutlined',
      component: () => import('@/pages/iot/ota/index.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: '/doc',
      name: '使用文档',
      redirect: '',
      icon: 'SnippetsOutlined',
      children: [
        {
          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 schedule = {
  path: '/schedule',
  name: '数据中台',
  meta: {
    title: '数据中台'
  },
  component: () => import('@/layout/layout.vue'),
  redirect: '/dataSource',
  children: [
    {
      path: '/dataSource',
      name: '数据源',
      icon: 'DatabaseOutlined',
      redirect: '/dataSource/manage',
      children: [
        {
          path: '/dataSource/manage',
          name: '数据源管理',
          component: () => import('@/pages/schedule/dataSource/manage/index.vue')
        },
        {
          path: '/dataSource/metaTool',
          name: '元数据管理',
          component: () => import('@/pages/schedule/dataSource/metaTool/index.vue')
        }
      ]
    },
    {
      path: '/dataLake',
      name: '数据湖',
      icon: 'LaptopOutlined',
      redirect: '/dataLake/dataTool',
      children: [
        {
          path: '/dataLake/dataTool',
          name: '数据湖工具',
          component: () => import('@/pages/schedule/dataLake/dataTool/index.vue')
        },
        {
          path: '/dataLake/dataIsland',
          name: '数据岛',
          component: () => import('@/pages/schedule/dataLake/dataTool/index.vue')
        }
      ]
    }
    // {
    //   path: '/APICenter',
    //   name: '数据服务',
    //   icon: 'ApiOutlined',
    //   component: () => import('@/pages/schedule/APICenter/index.vue')
    // }
  ]
}

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: 'TeamOutlined',
      component: () => import('@/pages/user/manage/index.vue')
    },
    {
      path: '/resource',
      name: '资源管理',
      icon: 'FolderOpenOutlined',
      component: () => import('@/pages/user/resource/index.vue')
    }
  ]
}

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

const cvs = {
  path: '/cvs',
  name: '视联网',
  meta: {
    title: '视联网'
  },
  component: () => import('@/layout/layout.vue'),
  redirect: '/cvs/video/space',
  children: [
    {
      path: '/cvs/video',
      name: '视频接入',
      icon: '',
      redirect: '/cvs/video/space',
      children: [
        {
          path: '/cvs/video/space',
          name: '空间',
          icon: '',
          component: () => import('@/pages/cvs/video/space.vue')
        },
        {
          path: '/cvs/video/device',
          name: '设备',
          icon: '',
          component: () => import('@/pages/cvs/video/device.vue')
        }
      ]
    },
    {
      path: '/cvs/operator',
      name: '算子仓库',
      icon: '',
      children: [
        {
          path: '/cvs/operator/manage',
          name: '算子管理',
          icon: '',
          component: () => import('@/pages/cvs/operator/manage.vue')
        }
      ]
    },
    {
      path: '/cvs/dataSever',
      name: '数据服务',
      icon: '',
      children: [
        {
          path: '/cvs/dataSever/car',
          name: '车辆库',
          icon: '',
          component: () => import('@/pages/cvs/dataServer/car.vue')
        },
        {
          path: '/cvs/dataSever/face',
          name: '人脸库',
          icon: '',
          component: () => import('@/pages/cvs/dataServer/face.vue')
        },
        {
          path: '/cvs/dataSever/frock',
          name: '工装库',
          icon: '',
          component: () => import('@/pages/cvs/dataServer/frock.vue')
        }
      ]
    },
    {
      path: '/cvs/edge',
      name: '边缘设备',
      icon: '',
      children: [
        {
          path: '/cvs/edge/task',
          name: '任务管理',
          icon: '',
          component: () => import('@/pages/cvs/edge/task.vue')
        },
        {
          path: '/cvs/dataSever/video',
          name: '视频管理',
          icon: '',
          component: () => import('@/pages/cvs/edge/video.vue')
        }
      ]
    },
    {
      path: '/cvs/csys',
      name: '系统概览 ',
      icon: '',
      component: () => import('@/pages/cvs/csys/index.vue')
    }
  ]
}

// }HQDZKE6BBJCJB0412

const demo = {
  path: '/demo',
  name: 'demo',
  icon: 'ProfileOutlined',
  component: () => import('@/pages/demo/index.vue')
}

const _routes = [iot, schedule, view, lowcode, user, cvs] 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, login]

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

// router.push = async function (to: vueRouter.RouteLocationRaw): Promise<void | NavigationFailure | undefined> {
//   router.push(to)
// }

export default router
