import { createRouter, createWebHashHistory } from 'vue-router'
import layout from '@/layout/deflayout.vue'

const routes = [
  {
    path: '/',
    name: 'index',
    redirect: '/index',
    component: layout,
    meta: { title: '欢迎页', icon: 'mdi-home' },
    children: [
      {
        path: 'index',
        component: () => import('@/views/Index.vue'),
      }
    ]
  },
  {
    path: '/protocol',
    name: 'Protocol',
    redirect: '/protocol/index',
    component: layout,
    meta: { title: '协议测试', icon: 'mdi-protocol' },
    children: [
      {
        path: 'index',
        component: () => import('@/views/protocol/Index.vue'),
      },

    ]
  },
  {
    path: '/upload',
    name: 'Upload',
    redirect: '/upload/index',
    component: layout,
    meta: { title: '配置上传', icon: 'mdi-protocol' },
    children: [
      {
        path: 'index',
        component: () => import('@/views/upload/Index.vue'),
      },
    ]
  }
  ,
  {
    path: '/opentime',
    name: 'Opentime',
    redirect: '/opentime/index',
    component: layout,
    meta: { title: '修改开服时间', icon: 'mdi-protocol' },
    children: [
      {
        path: 'index',
        component: () => import('@/views/opentime/Index.vue'),
      },
    ]
  }

]


export function getroutes () {
  var rs = []
  for (const route of routes) {
    var temproute = { path: route.path, component: route.component, meta: route.meta }
    temproute.children = null
    if (route.children && route.children.length > 0) {
      temproute.children = []
      for (const child of route.children) {
        var tempchild = { path: child.path, component: child.component, meta: child.meta }
        temproute.children.push(tempchild)
      }
    }
    rs.push(temproute)
  }
  return rs
}

const router = createRouter({
  history: createWebHashHistory(),
  routes
})



export default router
