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

// 定义路由配置
const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    name: 'Entry',
    component: () => import('../pages/entry/index.vue'),
    meta: {
      title: '宁福您彩 活动入口'
    }
  },
  {
    path: '/claim',
    alias: ['/home'],
    name: 'Home',
    component: () => import('../pages/home/index.vue'),
    meta: {
      title: '宁福您彩 新婚送福'
    }
  },
  {
    path: '/rule',
    name: 'Rule',
    component: () => import('../pages/rule/index.vue'),
    meta: {
      title: '宁福您彩 活动规则'
    }
  },
  {
    path: '/idcard',
    name: 'IdCard',
    component: () => import('../pages/idcard/index.vue'),
    meta: {
      title: '宁福您彩 身份核验'
    }
  }
]

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

// 路由前置守卫，用于设置页面标题
router.beforeEach((to, from, next) => {
  // 设置页面标题
  if (to.meta.title) {
    document.title = to.meta.title as string
  }
  next()
})

export default router
