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

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'home',
      component:  () => import('../screens/MainScreen.vue'),
      beforeEnter: (to, from, next) => {
        if (!localStorage.getItem('bearerToken')) {
          next({ name: 'signin' })
        } else {
          next()
        }
      }
    },
    {
      path: '/signup',
      name: 'signup',
      component: () => import('../screens/SignUpScreen.vue'),
    },
    {
      path: '/signin',
      name: 'signin',
      component: () => import('../screens/SignInScreen.vue'),
    },
    {
      path: '/profile',
      name: 'profile',
      component: () => import('../screens/ProfileScreen.vue'),
      beforeEnter: (to, from, next) => {
        if (!localStorage.getItem('bearerToken')) {
          next({ name: 'signin' })
        } else {
          next()
        }
      }
    }
  ],
})
export default router