import Vue from 'vue'
import Router from 'vue-router'
const Login = r =>
  require.ensure([], () => r(require('@/components/layout/login')), 'Login')
const Main = r =>
  require.ensure([], () => r(require('@/components/layout/main')), 'Main')
const Dashboard = r =>
  require.ensure(
    [],
    () => r(require('@/components/layout/dashboard')),
    'Dashboard'
  )
const notFind = r =>
  require.ensure([], () => r(require('@components/common/404')), 'notFind')
// const menuEdit = r =>
//   require.ensure([], () => r(require('@components/layout/header_components/menu_edit')), 'menuEdit')
import bug from '@app/bug/bug_routes.js'
const router_container = [bug]
router_container.forEach(item => {
  item.component = Main
})
Vue.use(Router)

const _router = {
  routes: [
    ...router_container,
    {
      path: '/',
      name: 'main',
      component: Main,
      children: [
        {
          name: '首页',
          path: 'dashboard',
          component: Dashboard,
          meta: {
            tabAttr: 'constant',
            value: 'dashboard',
            requiresAuth: true
          }
        }
        // {
        //   path: '/menu_edit',
        //   name: '菜单编辑',
        //   component: menuEdit,
        //   meta: {
        //     tabAttr: 'constant',
        //     title: '菜单编辑'
        //   }
        // }
      ]
    },
    {
      path: '/error',
      name: 'error',
      component: Main,
      children: [
        {
          path: '*',
          component: notFind,
          meta: {
            title: '404未找到'
          }
        }
      ]
    },
    {
      path: '/login',
      name: 'login',
      component: Login
    },
    {
      path: '/logout',
      name: 'logout'
    },
    {
      path: '/register',
      name: 'register',
      component: Login
    }
  ]
}
if (process.env.NODE_ENV === 'production') {
  _router.base = `/${sessionStorage.AppCode}/web/`
}
export default new Router(_router)
