import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import login, { checkLogin } from './login'
import store from '../store'

Vue.use(VueRouter)
// setLoginTheme(import(/* webpackChunkName: "login" */ '../login/fire/Login'))

const routes = [
  {
    path: '/',
    redirect: '/home',
  },
  {
    path: '/home',
    name: 'Home',
    component: Home
  },
  {
    path: '/about',
    name: 'About',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  },

  ...login,
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
  checkLogin({ router, to, from, store }, false)
    .then(result => {
      if (result) next()
    })
})

export default router
