import Vue from 'vue'
import VueRouter from 'vue-router'
import Dashboard from '@/views/Dashboard.vue'

Vue.use(VueRouter)

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes: [
    {
      path: '/',
      redirect: { name: 'dashboard' },
      meta: {
        auth: true
      }
    },
    {
      path: '/dashboard',
      name: 'dashboard',
      component: Dashboard,
      meta: {
        auth: true
      }
    },
    // New Route
    {
      path: '/users',
      name: 'users',
      component: () => import(/* webpackChunkName: "users" */ '@/views/Users.vue'),
      meta: {
        title: Vue.i18n.translate('strings.users', null),
        auth: {
          roles: 'Admin',
          forbiddenRedirect: '/'
        }
      },
      children: [{
        path: ':id',
        name: 'userDetail',
        component: () => import(/* webpackChunkName: "users" */ '@/views/Users.vue')
      }]
    },
    {
      path: '/login',
      name: 'login',
      // route level code-splitting
      // this generates a separate chunk (login.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import(/* webpackChunkName: "login" */ '@/views/Auth/AuthLogin.vue'),
      meta: {
        title: Vue.i18n.translate('login.login', null),
        auth: false
      }
    },
    {
      path: '/register',
      name: 'register',
      // route level code-splitting
      // this generates a separate chunk (register.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import(/* webpackChunkName: "register" */ '@/views/Auth/AuthRegister.vue'),
      meta: {
        title: Vue.i18n.translate('login.register', null),
        auth: false
      }
    },
    {
      path: '/password/reset',
      name: 'reset',
      component: () => import(/* webpackChunkName: "Reset" */ '@/views/Auth/AuthResetLink.vue'),
      meta: {
        title: Vue.i18n.translate('login.reset_password', null),
        auth: false
      }
    },
    {
      path: '/password/reset/:token',
      name: 'reset.token',
      component: () => import(/* webpackChunkName: "Reset" */ '@/views/Auth/AuthResetForm.vue'),
      meta: {
        title: Vue.i18n.translate('login.reset_password', null),
        auth: false
      }
    },
    {
      path: '/email/verify',
      name: 'verification.notice',
      props: true,
      component: () => import(/* webpackChunkName: "verification" */ '@/views/Auth/AuthVerify.vue'),
      meta: {
        title: Vue.i18n.translate('verification.title', null),
        auth: false
      }
    }
  ]
})

// It's required for VueAuth
Vue.router = router

export default router
