import { createRouter, createWebHashHistory } from 'vue-router'
import AppLayout from '../components/layout/AppLayout.vue'

const routes = [
  {
    path: '/',
    component: AppLayout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        name: 'Dashboard',
        component: () => import('../views/Dashboard.vue'),
        meta: { title: '总览' },
      },
      {
        path: 'rooms',
        name: 'Rooms',
        component: () => import('../views/Rooms.vue'),
        meta: { title: '房间管理' },
      },
      {
        path: 'rooms/:roomId',
        name: 'RoomDetail',
        component: () => import('../views/RoomDetail.vue'),
        meta: { title: '房间详情' },
      },
      {
        path: 'sessions',
        name: 'Sessions',
        component: () => import('../views/Sessions.vue'),
        meta: { title: '游戏记录' },
      },
      {
        path: 'screens',
        name: 'Screens',
        component: () => import('../views/Screens.vue'),
        meta: { title: '大屏控制' },
      },
    ],
  },
]

const router = createRouter({
  history: createWebHashHistory(),
  routes,
})

router.beforeEach((to, _from, next) => {
  document.title = to.meta.title ? `${to.meta.title} - 伙伴泡泡管理后台` : '伙伴泡泡管理后台'
  next()
})

export default router
