import { is } from 'quasar';
import { route } from 'quasar/wrappers';
import { createRouter, createWebHistory } from 'vue-router';
import { StateInterface } from '../store';

import routes from './routes';

/*
 * If not building with SSR mode, you can
 * directly export the Router instantiation;
 *
 * The function below can be async too; either use
 * async/await or return a Promise which resolves
 * with the Router instance.
 */

export default route<StateInterface>(function ({ store }) {
  const createHistory = createWebHistory;
  const Router = createRouter({
    scrollBehavior: () => ({ left: 0, top: 0 }),
    routes,
    history: createHistory(process.env.VUE_ROUTER_BASE),
  });
  Router.beforeEach((to, from, next) => {
    // const isLogin = store.getters['userModule/getUser']
    // const isLogin = true;
    // const isRouterLogin = to.fullPath.includes('login');
    // if (isRouterLogin && isLogin) {
    //   next({ name: 'dashboard' });
    // } else if (!isLogin) {
    //   isRouterLogin ? next() : next({ name: 'login' });
    // } else {
    //   next();
    // }
    next();
  });
  return Router;
});
