import i18n from '~/i18n'
const { t } = i18n.global

const Layout = () => import('@/layout/index.vue')

export const basicRoutes = [
  {
    path: '/',
    redirect: '/workbench', // 默认跳转到首页
    meta: { order: 0 },
  },
  {
    name: 'Workbench',
    path: '/workbench',
    component: Layout,
    children: [
      {
        path: '',
        component: () => import('@/views/workbench/index.vue'),
        name: 'WorkbenchDefault',
        meta: {
          title: t('views.workbench.label_workbench'),
          icon: 'icon-park-outline:workbench',
          affix: true,
        },
      },
    ],
    meta: { order: 1 },
  },
  {
    name: 'Profile',
    path: '/profile',
    component: Layout,
    isHidden: true,
    children: [
      {
        path: '',
        component: () => import('@/views/profile/index.vue'),
        name: 'ProfileDefault',
        meta: {
          title: t('views.profile.label_profile'),
          icon: 'user',
          affix: true,
        },
      },
    ],
    meta: { order: 99 },
  },
  {
    name: '代理管理',
    path: '/system/proxy',
    component: Layout,
    children: [
      {
        path: '',
        component: () => import('@/views/system/proxy/index.vue'),
        name: '代理管理Default',
        meta: {
          title: '代理管理',
          icon: 'mdi:server-network',
          affix: false,
        },
      },
    ],
    meta: { order: 97 },
  },
  {
    name: 'Token管理',
    path: '/system/token',
    component: Layout,
    children: [
      {
        path: '',
        component: () => import('@/views/system/token/index.vue'),
        name: 'Token管理Default',
        meta: {
          title: 'Token管理',
          icon: 'mdi:key',
          affix: false,
        },
      },
    ],
    meta: { order: 98 },
  },
  {
    name: 'Login',
    path: '/login',
    component: () => import('@/views/login/index.vue'),
    isHidden: true,
    meta: {
      title: '登录页',
    },
  },
]

export const NOT_FOUND_ROUTE = {
  name: 'NotFound',
  path: '/:pathMatch(.*)*',
  redirect: '/workbench',
  isHidden: true,
}

export const EMPTY_ROUTE = {
  name: 'Empty',
  path: '/:pathMatch(.*)*',
  component: null,
}

const modules = import.meta.glob('@/views/**/route.js', { eager: true })
const asyncRoutes = []
Object.keys(modules).forEach((key) => {
  asyncRoutes.push(modules[key].default)
})

// 加载 views 下所有 .vue 文件（支持 index.vue 及其他命名）
const vueModules = import.meta.glob('@/views/**/*.vue')

export { asyncRoutes, vueModules }
