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: '项目管理' }
        },
        {
          path: 'projects/:id',
          name: 'ProjectDetail',
          component: () => import('@/views/ProjectDetail.vue'),
          meta: { title: '项目详情' }
        },
        {
          path: 'plans/:id',
          name: 'PlanDetail',
          component: () => import('@/views/PlanDetail.vue'),
          meta: { title: '方案详情' }
        },
        {
          path: 'experience',
          name: 'Experience',
          component: () => import('@/views/ExperienceList.vue'),
          meta: { title: '经验库' }
        },
        {
          path: 'dashboard',
          name: 'Dashboard',
          component: () => import('@/views/Dashboard.vue'),
          meta: { title: '结果分析' }
        }
      ]
    }
  ]
})

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

export default router
