/**
 * Vue Router 配置
 *
 * @author czj
 * @date 2026-07-09
 */

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

/**
 * 路由配置
 */
const routes: RouteRecordRaw[] = [
  {
    path: '/',
    name: 'Dashboard',
    component: () => import('@/views/Dashboard.vue'),
    meta: { title: '测试总览' }
  },
  {
    path: '/modules/:type?',
    name: 'Modules',
    component: () => import('@/views/Modules.vue'),
    meta: { title: '模块管理' }
  },
  {
    path: '/cases/:type?',
    name: 'Cases',
    component: () => import('@/views/Cases.vue'),
    meta: { title: '用例管理' }
  },
  {
    path: '/recorder',
    name: 'Recorder',
    component: () => import('@/views/Recorder.vue'),
    meta: { title: '用例录制' }
  },
  {
    path: '/execution/:type?',
    name: 'Execution',
    component: () => import('@/views/Execution.vue'),
    meta: { title: '执行中心' }
  },
  {
    path: '/reports/:type?',
    name: 'Reports',
    component: () => import('@/views/Reports.vue'),
    meta: { title: '报告中心' }
  },
  {
    path: '/settings',
    name: 'Settings',
    component: () => import('@/views/Settings.vue'),
    meta: { title: '系统配置' }
  }
]

/**
 * 创建路由实例
 */
const router = createRouter({
  history: createWebHistory(),
  routes
})

/**
 * 路由守卫 - 设置页面标题
 */
router.beforeEach((to, _from, next) => {
  // 设置页面标题
  const title = to.meta?.title as string
  if (title) {
    document.title = `${title} - 测试管理平台`
  }
  next()
})

export default router