const viewsModules: Recordable<() => Promise<Recordable>> = import.meta.glob(
  '/src/view/**/*.{vue,tsx}'
);
viewsModules['/saas/view/system/application.vue'] = () =>
  import('/nerv-lib/saas/view/system/application.vue');

viewsModules['/saas/view/system/layout/content.vue'] = () =>
  import('/nerv-lib/saas/view/system/layout/content.vue');

viewsModules['/saas/view/menuManage/index.vue'] = () =>
  import('/nerv-lib/saas/view/menuManage/index.vue');

const viewsModulesKeys = Object.keys(viewsModules);

function getComponent(component: string): string | undefined {
  const key = viewsModulesKeys.find((key) => {
    return component.includes(key);
  });
  // !key && console.log('key', component);
  return key;
}

function dynamicImportRoute(component: string) {
  const dynamicComponent = viewsModules[component];
  if (dynamicComponent) {
    return dynamicComponent;
  } else {
    console.error(`can't find ${component}`);
    return viewsModules['/saas/view/system/layout/content.vue'];
  }
}

export { viewsModules, getComponent, dynamicImportRoute };
