import { createRouter, createWebHistory } from 'vue-router'
// import HomeView from '@/views/home/index.vue'
import { authGuard } from './guard'

// 自动加载modules目录下的所有路由文件
const moduleRoutes = Object.values(import.meta.glob('./modules/*.ts', { eager: true })).flatMap(
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  (module) => (module as { default: any }).default
)

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'home',
      // component: HomeView,
      // meta: { title: '首页看板', isFullScreen: false, keepAlive: false },
      redirect: '/community/list',
      meta: { title: '小区管理', isFullScreen: false },
    },
    // 自动合并所有模块路由
    ...moduleRoutes,
  ],
})
router.beforeEach(authGuard)

export default router
