import type { AppRouteRecordRaw, AppRouteModule } from '/@/router/types';
import { DATA_BOARD_SHARE, PAGE_NOT_FOUND_ROUTE, REDIRECT_ROUTE } from '/@/router/routes/basic';
import { mainOutRoutes } from './mainOut';
import { PageEnum } from '/@/enums/pageEnum';
import { t } from '/@/hooks/web/useI18n';
import { LAYOUT } from '../constant';

const modules = import.meta.globEager('./modules/**/*.ts');
const routeModuleList: AppRouteModule[] = [];
Object.keys(modules).forEach((key) => {
  const mod = modules[key].default || {};
  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,
  meta: {
    title: 'Root',
  },
};

export const LoginRoute: AppRouteRecordRaw = {
  path: '/login',
  name: 'Login',
  component: () => import('/@/views/sys/login/Login.vue'),
  meta: {
    title: t('routes.basic.login'),
  },
};

// 用户详情静态路由
export const AccountDetail: AppRouteRecordRaw = {
  path: '/system',
  name: '系统管理',
  component: LAYOUT,
  meta: {
    title: '系统管理',
    hideBreadcrumb: true,
    hideChildrenInMenu: true,
  },
  children: [
    {
      path: 'account_detail/:id',
      name: 'Account_Detail',
      component: () => import('/@/views/system/account/AccountDetail.vue'),
      meta: {
        title: '用户详情',
      },
    },
  ],
};
// 调度日志静态路由
export const SchedueLog: AppRouteRecordRaw = {
  path: '/report',
  name: '报表管理',
  component: LAYOUT,
  meta: {
    title: '报表管理',
    hideBreadcrumb: true,
    hideChildrenInMenu: true,
  },
  children: [
    {
      path: 'schedue_log/:id',
      name: 'Schedue_Log',
      // component: () => import('../../views/system/scheduled/SchedueLog.vue'),
      meta: {
        title: '调度日志',
      },
    },
  ],
};
// export const DeviceList: AppRouteRecordRaw = {
//   path: '/device',
//   name: '设备管理',
//   component: LAYOUT,
//   meta: {
//     title: '设备管理',
//     hideBreadcrumb: true,
//     hideChildrenInMenu: true,
//   },
//   children: [
//     {
//       path: '/device/list',
//       name: 'Device_List',
//       // component: () => import('/@/views/device/list/index.vue'),
//       component: () => import('../../views/system/scheduled/SchedueLog.vue'),
//       meta: {
//         title: '设备列表',
//       },
//     },
//   ],
// };
// Basic routing without permission
export const basicRoutes = [
  LoginRoute,
  RootRoute,
  AccountDetail,
  SchedueLog,
  // DeviceList,
  ...mainOutRoutes,
  REDIRECT_ROUTE,
  PAGE_NOT_FOUND_ROUTE,
  DATA_BOARD_SHARE,
];
