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: '结果分析' }
        },
        {
          path: 'tasks',
          name: 'TaskManager',
          component: () => import('@/views/TaskManager.vue'),
          meta: { title: '任务管理' }
        },
        {
          path: 'monitor',
          name: 'MonitorDashboard',
          component: () => import('@/views/MonitorDashboard.vue'),
          meta: { title: '实时监控' }
        },
        {
          path: 'visualization',
          name: 'AdvancedVisualization',
          component: () => import('@/views/AdvancedVisualization.vue'),
          meta: { title: '高级可视化' }
        },
        {
          path: 'ai/plan-generator',
          name: 'AIPlanGenerator',
          component: () => import('@/views/ai/PlanGenerator.vue'),
          meta: { title: 'AI方案生成' }
        },
        {
          path: 'ai/l0-prescreen',
          name: 'L0Prescreen',
          component: () => import('@/views/ai/L0Prescreen.vue'),
          meta: { title: 'L0预筛选' }
        },
        {
          path: 'ai/adaptive-optimize',
          name: 'AdaptiveOptimize',
          component: () => import('@/views/ai/AdaptiveOptimize.vue'),
          meta: { title: '自适应优化' }
        },
        {
          path: 'ai/result-analysis',
          name: 'AIResultAnalysis',
          component: () => import('@/views/ai/ResultAnalysis.vue'),
          meta: { title: 'AI结果分析' }
        },
        {
          path: 'ai/fidelity-calibration',
          name: 'FidelityCalibration',
          component: () => import('@/views/ai/FidelityCalibration.vue'),
          meta: { title: '多保真度校准' }
        },
        {
          path: 'ai/experience-enhance',
          name: 'ExperienceEnhance',
          component: () => import('@/views/ai/ExperienceEnhance.vue'),
          meta: { title: '经验库AI增强' }
        }
      ]
    }
  ]
})

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

export default router
