import Routes from './routes'
import Layout from '../layout'

function mapASyncRoutes (data) {
  return data.map(item => {
    // if (!item.redirect) {
    //   item.redirect = undefined
    // }
    item.component = item.component === 'Layout' ? Layout : loadView(item.component)
    if (item.children && item.children.length > 0) {
      item.children = mapASyncRoutes(item.children)
    }
    return item
  })
}

// 路由插件
function loadView (view) {
  return !view ? { render: (c) => c('router-view') } : () => import(`@/views/${view}`)
}

const base = [
  {
    path: '/login-local',
    name: 'login',
    meta: { title: '登录' },
    component: () => import('@/views/login')
  },
  {
    path: '/signAgain',
    name: 'signAgain',
    meta: { title: '重新登录', noLogin: true },
    component: () => import('@/views/login/signAgain')
  },
  {
    path: '/reminder',
    name: 'reminder',
    meta: { title: '退出登录', noLogin: true },
    component: () => import('@/views/login/reminder')
  },
  {
    path: '/404',
    name: '404',
    meta: { title: '404' },
    hidden: true,
    component: () => import('@/views/systemManage/error/404')
  }
]

export default [...base, { path: '/', redirect: '/home' }, ...mapASyncRoutes(Routes.routes), { path: '*', redirect: '/404', hidden: true }]
