import type { AppRouteRecordRaw, AppRouteModule } from '@/router/types';

import { PAGE_NOT_FOUND_ROUTE, REDIRECT_ROUTE } from '@/router/routes/basic';

import { PageEnum } from '@/enums/pageEnum';
<%_ if (enableTranslation) { _%>
import { t } from '@/hooks/web/useI18n';
<%_ } _%>

const modules = import.meta.glob('./modules/**/*.ts', { eager: true });
const routeModuleList: AppRouteModule[] = [];

// 加入到路由集合中
Object.keys(modules).forEach((key) => {
  const mod = (modules as Recordable)[key].default || {};
  const modList =  (Array.isArray(mod) ? [...mod] : [mod]).filter(route => route.path && route.path.startsWith('/'));
  routeModuleList.push(...modList);
});

export const asyncRoutes = [PAGE_NOT_FOUND_ROUTE, ...routeModuleList];

// 根路由
export const RootRoute: AppRouteRecordRaw = {
  path: '/',
  name: 'Root',
  redirect: PageEnum.BASE_HOME,
  meta: {
    title: 'Root',
  },
};
<% if (authenticationTypeJwt) { _%>

export const LoginRoute: AppRouteRecordRaw = {
  path: '/login',
  name: 'Login',
  component: () => import('@/views/account/login/Login.vue'),
  meta: {
    title: <% if (enableTranslation) { %>t('routes.basic.login')<% } else { %>'t$t('routes.basic.login')$t$'<% } %>,
  },
};
<%_ } _%>
<% if (authenticationTypeOauth2) { _%>

export const Oauth2LoginRoute: AppRouteRecordRaw = {
  path: '/login/oauth2/code/oidc',
  name: 'oauth2-app-login',
  component: () => import('@/views/system/loginmini/OAuth2Login.vue'),
  meta: {
    title: <% if (enableTranslation) { %>t('routes.oauth2.login')<% } else { %>'t$t('routes.oauth2.login')$t$'<% } %>,
  },
};
<%_ } _%>

// Basic routing without permission
// 无需权限的基本路由
export const basicRoutes = [
<% if (authenticationTypeOauth2) { _%>
 Oauth2LoginRoute,
<%_ } _%>
<% if (authenticationTypeJwt) { _%>
  LoginRoute,
<%_ } _%>
  RootRoute,
  REDIRECT_ROUTE,
  PAGE_NOT_FOUND_ROUTE,
];
