import LoadingComponent from '@ant-design/pro-layout/es/PageLoading';
import { dynamic } from '@wisdom-utils/runtime';

import BasicLayout from '../layouts/BasicLayout1';
import UserLayout from '../layouts/UserLayout';
import BootPage from '../pages/bootpage';
import Iframe from '../pages/iframe';
import Login from '../pages/user/login';
import CommonMenu from '../pages/commonMenu';
import NoSecret from '../pages/user/login/noSecret';
import UsingAnalysis from '../pages/cloudOMS/usingAnalysis';

export const dyRoutes = (routes, layout) => {
  // eslint-disable-next-line no-shadow
  const dyRoutes = routes || [];
  return {
    routes: [
      {
        path: '/user',
        component: UserLayout,
        routes: [
          {
            name: 'login',
            path: '/user/login',
            component: Login,
          },
          {
            name: 'noscret',
            path: '/user/noscret',
            component: NoSecret
          }
        ],
      },
      {
        path: '/industry',
        component: BootPage,
      },
      {
        path: '/usingAnalysis',
        component: UsingAnalysis,
      },
      {
        path: '/',
        component: BasicLayout,
        routes: [
          ...dyRoutes,
          {
            path: '/commonmenu',
            component: CommonMenu,
            name: '菜单收藏'
          },
          {
            path: '/iframe',
            component: Iframe
          },
          {
            path: '/404',
            component: dynamic({
              loader: () =>
                import(
                  /* webpackChunkName: 'p__404' */ '../pages/exception/404'
                ),
              loading: LoadingComponent,
            }),
          },
          {
            path: '/500',
            component: dynamic({
              loader: () =>
                import(
                  /* webpackChunkName: 'p__500' */ '../pages/exception/500'
                ),
              loading: LoadingComponent,
            }),
          },
        ],
      },

      process.env.NODE_ENV === 'development' && {
        path: '/openapi',
        exact: true,
        component: dynamic({
          loader: () =>
            import(
              /* webpackChunkName: 'civ__plugin-openapi__openapi' */ '../components/openapi/openapi'
            ),
          loading: LoadingComponent,
        }),
      },
      {
        path: '/404',
        component: dynamic({
          loader: () =>
            import(
              /* webpackChunkName: 'p__404' */ '../pages/exception/404'
              ),
          loading: LoadingComponent,
        }),
      },
      {
        path: '/500',
        component: dynamic({
          loader: () =>
            import(
              /* webpackChunkName: 'p__500' */ '../pages/exception/500'
              ),
          loading: LoadingComponent,
        }),
      },

    ],
  };
};
