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

const router = createRouter({
  history: createWebHistory(),
  routes: [
    {
      path: '/',
      component: () => import('@/layouts/MainLayout.vue'),
      redirect: '/projects',
      children: [
        {
          path: 'projects',
          name: 'ProjectList',
          component: () => import('@/views/ProjectList.vue'),
          meta: { title: 'Projects' }
        },
        {
          path: 'projects/:id',
          name: 'ProjectDetail',
          component: () => import('@/views/ProjectDetail.vue'),
          meta: { title: 'Project Detail' }
        },
        {
          path: 'plans/:id',
          name: 'PlanDetail',
          component: () => import('@/views/PlanDetail.vue'),
          meta: { title: 'Plan Detail' }
        },
        {
          path: 'experience',
          name: 'Experience',
          component: () => import('@/views/ExperienceList.vue'),
          meta: { title: 'Experience Library' }
        }
      ]
    }
  ]
})

router.beforeEach((to, _from, next) => {
  document.title = `${to.meta.title || 'AFM Simulation'} - PCB Axial Flux Motor`
  next()
})

export default router
