import {
  createMemoryHistory, createRouter, createWebHashHistory, createWebHistory,
} from 'vue-router'


import { cfgrouter } from './route-config'

const routermode = import.meta.env.VITE_VUE_ROUTER_MODE === 'history' ? createWebHistory : createWebHashHistory

// const userStore = useUserStore(store)

const createHistory = import.meta.env.SERVER
  ? createMemoryHistory
  : routermode

const router = createRouter({
  scrollBehavior: () => ({ left: 0, top: 0 }),
  routes: cfgrouter.getmenu(),
  history: createHistory(
    import.meta.env.MODE === 'ssr' ? void 0 : import.meta.env.VUE_ROUTER_BASE,
  ),
});

/*
// Add the beforeEach hook
router.beforeEach((to, from, next) => {
  console.log('beforeEach ROUTER')
  // Execute your command before each navigation
  // executeCommand();

  const globalStore = useGlobalStore()
  try {
    globalStore.editOn = false
  } catch(e) {

  }


  //if (to.matched.some(record => record.meta.requiresAuth) && !userStore.isLogged) {
  //  next({ name: 'login', query: { next: to.fullPath } })
  //} else {
  //  next()
  //}


  // Continue with the navigation
  next();
}); */

export default router;
