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
      }
    },
    {
      path: '/customers',
      name: 'customers',
      component: () => import(/* webpackChunkName: "customers" */ '@/views/Customers.vue'),
      meta: {
        title: Vue.i18n.translate('strings.customers', null),
        auth: true
      },
      children: [{
        path: ':id',
        name: 'customerDetail',
        component: () => import(/* webpackChunkName: "customers" */ '@/views/Customers.vue')
      }]
    },
    {
      path: '/purchase-orders',
      name: 'purchaseOrders',
      component: () => import(/* webpackChunkName: "purchaseOrders" */ '@/views/PurchaseOrders.vue'),
      meta: {
        title: Vue.i18n.translate('strings.purchase_orders', null),
        auth: true
      }
    },
    {
      path: '/purchase-orders/new',
      name: 'newPurchaseOrder',
      component: () => import(/* webpackChunkName: "purchaseOrders" */ '@/views/PurchaseOrdersDetail.vue'),
      props: true,
      meta: {
        title: Vue.i18n.translate('strings.purchase_orders.detail', null),
        auth: true
      }
    },
    {
      path: '/purchase-orders/:id',
      name: 'editPurchaseOrder',
      component: () => import(/* webpackChunkName: "purchaseOrders" */ '@/views/PurchaseOrdersDetail.vue'),
      meta: {
        title: Vue.i18n.translate('strings.purchase_orders.detail', null),
        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/AuthLogin.vue'),
      meta: {
        title: Vue.i18n.translate('login.login', null),
        auth: false
      }
    },
    {
      path: '/password/reset',
      name: 'reset',
      component: () => import(/* webpackChunkName: "Reset" */ '@/views/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/AuthResetForm.vue'),
      meta: {
        title: Vue.i18n.translate('login.reset_password', null),
        auth: false
      }
    }
  ]
})

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

export default router
