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 Login from '../pages/user/login';
import CommonMenu from '../pages/commonMenu';

export const dyRoutes = routes => {
  // eslint-disable-next-line no-shadow
  const dyRoutes = routes || [];
  return {
    routes: [
      {
        path: '/user',
        component: UserLayout,
        routes: [
          {
            name: 'login',
            path: '/user/login',
            component: Login,
          },
        ],
      },
      {
        path: '/industry',
        component: BootPage,
      },
      {
        path: '/',
        component: BasicLayout,
        routes: [
          ...dyRoutes,
          {
            path: '/commonmenu',
            component: CommonMenu,
            name: 'commonmenu'
          },
          {
            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,
        }),
      },

    ],
  };
};
