import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'
import LoginView from '../views/LoginView.vue'
import PracticeView from '../views/PracticeView.vue'
import ReportView from '../views/ReportView.vue'
import ScreeningView from '../views/ScreeningView.vue'
import TrainingView from '../views/TrainingView.vue'
import { getToken } from '../api'

const router = createRouter({
  history: createWebHistory(),
  routes: [
    { path: '/login', component: LoginView },
    { path: '/', component: HomeView },
    { path: '/screening', component: ScreeningView },
    { path: '/reports', component: ReportView },
    { path: '/training', component: TrainingView },
    { path: '/practice', component: PracticeView },
  ],
})

router.beforeEach((to) => {
  if (to.path !== '/login' && !getToken()) {
    return '/login'
  }
})

export default router
