import { createRouter, createWebHistory } from 'vue-router'
import Login from '../views/auth/Login.vue'
import Register from '../views/auth/Register.vue'
import AdminDashboard from '../views/admin/AdminDashboard.vue'
import StaffDashboard from '../views/staff/StaffDashboard.vue'
import CustomerDashboard from '../views/customer/CustomerDashboard.vue'
import CustomerHome from '../views/customer/CustomerHome.vue'
import ServiceAppointment from '@/views/customer/ServiceAppointment.vue'
import MySchedule from '@/views/customer/MySchedule.vue'
import UserProfile from '@/views/customer/UserProfile.vue'

const routes = [
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/login',
    name: 'Login',
    component: Login,
    meta: {
      transition: 'flip',
      title: '登录'
    }
  },
  {
    path: '/register',
    name: 'Register',
    component: Register,
    meta: {
      transition: 'flip',
      title: '注册'
    }
  },
  {
    path: '/admin',
    name: 'AdminDashboard',
    component: AdminDashboard,
    meta: { requiresAuth: true, role: 'admin', title: '管理员控制台' }
  },
  {
    path: '/staff',
    name: 'StaffDashboard',
    component: StaffDashboard,
    meta: { requiresAuth: true, role: 'staff', title: '员工控制台' }
  },
  {
    path: '/customer',
    name: 'CustomerDashboard',
    component: CustomerDashboard,
    meta: { requiresAuth: true, role: 'customer', title: '中医药与心理健康' },
    children: [
      {
        path: '/customer/home',
        name: 'CustomerHome',
        component: CustomerHome,
        meta: { title: '中医药与心理健康' }
      },
      {
        path: '/customer/services',
        name: 'ServiceAppointment',
        component: ServiceAppointment,
        meta: { title: '中医药与心理健康' }
      },
      {
        path: '/customer/schedule',
        name: 'MySchedule',
        component: MySchedule,
        meta: { title: '中医药与心理健康' }
      },
      {
        path: '/customer/profile',
        name: 'UserProfile',
        component: UserProfile,
        meta: { title: '中医药与心理健康' }
      },
      {
        path: '/customer/social-circle',
        name: 'AnonymousShareCircle',
        component: () => import('@/views/customer/AnonymousShareCircle.vue')
      },
      {
        path: '/customer/psychological-test',
        name: 'PsychologicalTest',
        component: () => import('@/views/customer/PsychologicalTest.vue')
      },
      {
        path: '/customer/questionnaire',
        name: 'Questionnaire',
        component: () => import('@/views/customer/Questionnaire.vue')
      }
    ]
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})
router.beforeEach((to, from, next) => {
  // 设置页面标题
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
})

export default router
