import type { RouteRecordRaw } from 'vue-router'
import { createRouter, createWebHashHistory } from 'vue-router'
import { UserRole } from '~/store/user';

const modules: Record<string, { default: RouteRecordRaw }> = import.meta.glob('./routes/*.ts', { eager: true })

export const routes: RouteRecordRaw[] = []
Object.keys(modules).forEach((path) => {
  routes.push(modules[path].default)
})
if (UserRole === 'student') {
  routes.unshift({ path: '/', redirect: { name: 'student_home' } })
}
if (UserRole === 'teacher') {
  routes.unshift({ path: '/', redirect: { name: 'teacher_home' } })
}
console.log('routes :>> ', routes);

const router = createRouter({
  history: createWebHashHistory(),
  routes,
})

export default router


router.beforeEach((to, from) => {
  console.groupCollapsed(`%c${from.name?.toString()} => ${to.name?.toString()}`, 'color:#0ff')
  console.log(`%c${from.meta.title} => ${to.meta.title}`, 'color:#0cc')
  console.groupEnd()
})
