import {createRouter, createWebHashHistory} from "vue-router";

const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: "/",
      component: () => import('@/views/home/HomeView.vue'),
      name: 'home',
      meta: {
        maintenance: false
      }
    },
    {
      path: "/article",
      children: [
        {
          path: "/blog",
          component: () => import('@/views/article/BlogView.vue'),
          name: 'blog',
          meta: {
            maintenance: true
          },
        },
        {
          path: "/diary",
          component: () => import('@/views/article/DiaryView.vue'),
          name: 'diary',
          meta: {
            maintenance: true
          }
        }
      ]
    },
    {
      path: "/work",
      children: [
        {
          path: "/soft",
          component: () => import('@/views/article/DiaryView.vue'),
          name: 'soft',
          meta: {
            maintenance: true
          }
        }
      ]
    },
    {
      path: "/talk",
      component: () => import('@/views/talk/TalkView.vue'),
      name: 'talk',
      meta: {
        maintenance: true
      }
    },
    {
      path: "/maintenance",
      component: () => import('@/views/error/MaintenanceView.vue'),
      name: 'maintenance'
    }
  ]
});

router.beforeEach((to, _, next) => {
  if (to.meta.maintenance === true && !import.meta.env.DEV) next({name: 'maintenance'})
  else next()
})

export default router;