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

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

import { mainOutRoutes } from './mainOut';
import { PageEnum } from '@/enums/pageEnum';
import { t } from '@/hooks/web/useI18n';

// import.meta.glob() 直接引入所有的模块 Vite 独有的功能
const modules = import.meta.glob('./modules/**/*.ts', { eager: true });
const routeModuleList: AppRouteModule[] = [];

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

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

// 根路由
export const RootRoute: AppRouteRecordRaw = {
  path: '/',
  name: 'Root',
  // redirect: PageEnum.BASE_HOME,
  redirect: PageEnum.DEFAULT_MAP,
  meta: {
    title: 'Root',
  },
};

export const LoginRoute: AppRouteRecordRaw = {
  path: '/login',
  name: 'Login',
  // component: () => import('@/views/sys/login/Login.vue'),
  component: () => import('@/views/sys/login_lindidiaocha/Login.vue'),
  meta: {
    title: t('routes.basic.login'),
  },
};
export const H5HtmlRoute: AppRouteRecordRaw = {
  path: '/h5html',
  name: 'h5html',
  component: () => import('@/views/demo/h5html/index.vue'),
  meta: {
    title: 'H5表单',
  },
};

export const CreatePreviewRoute: AppRouteRecordRaw = {
  path: '/create_preview',
  name: 'create_preview',
  component: () => import('@/views/demo/workflow/h5/create.vue'),
  meta: {
    title: t('routes.demo.workflow.create_preview'),
  },
};
export const TaskAuditRoute: AppRouteRecordRaw = {
  path: '/task_audit_preview',
  name: 'task_audit_preview',
  component: () => import('@/views/demo/workflow/h5/audit.vue'),
  meta: {
    title: t('routes.demo.workflow.task_audit_preview'),
  },
};
export const TaskLookRoute: AppRouteRecordRaw = {
  path: '/task_look_preview',
  name: 'task_look_preview',
  component: () => import('@/views/demo/workflow/h5/look.vue'),
  meta: {
    title: t('routes.demo.workflow.task_look_preview'),
  },
};
export const SchemeRoute: AppRouteRecordRaw = {
  path: '/scheme_preview',
  name: 'scheme_preview',
  component: () => import('@/views/demo/workflow/h5/scheme.vue'),
  meta: {
    title: t('routes.demo.workflow.scheme_preview'),
  },
};
export const SubjectRoute: AppRouteRecordRaw = {
  path: '/subject',
  name: 'subject',
  component: () => import('@/views/subject/subject_lindidiaocha/index.vue'),
  meta: {
    title: '主题',
  },
};
export const VideoSupervisionRoute: AppRouteRecordRaw = {
  path: '/videosupervision',
  name: 'videosupervision',
  component: () => import('@/views/sys/exception/VideoSupervision.vue'),
  meta: {
    title: '视频监管',
  },
};
export const LargeScreenRoute: AppRouteRecordRaw = {
  path: '/largeScreen',
  name: 'largeScreen',
  component: () => import('@/views/sys/exception/Exception.vue'),
  meta: {
    title: '数据大屏',
  },
};
export const FORMCALLPAGE_ROUTE: AppRouteRecordRaw = {
  path: '/formCallPageParent',
  component: LAYOUT,
  name: 'formCallPageParent',
  meta: {
    title: '表单',
    hideBreadcrumb: true,
    hideMenu: true,
  },
  children: [
    {
      path: '/formCallPage',
      name: 'formCallPage',
      component: () => import('@/views/demo/onlineform/formCall/index.vue'),
      meta: {
        title: '表单调用',
        hideBreadcrumb: true,
      },
    },
  ],
};
// Basic routing without permission
// 未经许可的基本路由
export const basicRoutes = [
  H5HtmlRoute,
  LoginRoute,
  RootRoute,
  ...mainOutRoutes,
  REDIRECT_ROUTE,
  PAGE_NOT_FOUND_ROUTE,
  CreatePreviewRoute,
  TaskAuditRoute,
  TaskLookRoute,
  SchemeRoute,
  SubjectRoute,
  FORMCALLPAGE_ROUTE,
  LargeScreenRoute,
  VideoSupervisionRoute
];
