import React from 'react';
import { UserLayout } from '@wisdom-utils/components/lib/AppLayout';
import LoadingComponent from '@wisdom-utils/components/lib/AppLayout/components/PageLoading';
import { dynamic } from '@wisdom-utils/runtime';

import BasicLayout from '../layouts/BasicLayout';
import HomePage from '../layouts/TransitionPage';
import BootPage from '../pages/bootpage';
import UsingAnalysis from '../pages/cloud/analysis/using';
import NewProducts from '../pages/cloud/introduction/newproducts';
import CommonMenu from '../pages/commonMenu';
import Iframe from '../pages/iframe';
import NoSecret from '../pages/user/login/noSecret';
import Notifications from '../pages/system/notifications';
import TabIframe from '../pages/system/iframe/TabWidget';
import JumpThirdLink from '../pages/system/iframe/JumpThirdLink';
import IntegratedLogin from '../pages/system/iframe/IntegratedLogin';
import IntegratedLoginPage from '../pages/integratedLogin'; // 集成登录管理
import ThirdParty from '../pages/thirdParty'; // 集成登录自定义跳转
import JimusaerPage from '../pages/bootpage/template/project/jimusaer/index';
import PrevieView from '../pages/system/previews/preview';
const Login = React.lazy(() => import('../pages/user/login'));
export const dyRoutes = (routes, layout, theme) => {
  // eslint-disable-next-line no-shadow
  const dyRoutes = routes || [];
  return {
    routes: [
      {
        path: '/user',
        component: UserLayout,
        beforeEnter(props) {
          console.log(props);
        },
        routes: [
          {
            name: 'login',
            path: '/user/login',
            component: Login,
            props: {
              onEnter(props) {
                console.log('login props', props);
              },
            },
          },
          {
            name: 'noscret',
            path: '/user/noscret',
            component: NoSecret,
          },
        ],
      },
      {
        path: '/homePage',
        component: HomePage,
      },
      {
        path: '/industry',
        component: BootPage,
      },
      {
        path: '/thirdParty',
        component: ThirdParty,
      },
      {
        path: '/cloud/analysis/using',
        component: UsingAnalysis,
      },
      {
        path: '/cloud/introduction/newproducts',
        component: NewProducts,
      },
      {
        path: '/',
        // component: theme === 'lightgreen.css' ? HNLayout : BasicLayout,
        component: BasicLayout,
        routes: [
          ...dyRoutes,
          {
            path: '/commonmenu',
            component: CommonMenu,
            // name: '菜单收藏'
          },
          {
            // 历史消息箱
            path: '/system/notifications',
            component: Notifications,
          },
          {
            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,
            }),
          },
          {
            path: '/',
            render: ({ routeConfig }) => {
              const { path } = routeConfig || {};
              if (/system\/iframe\/JumpThirdLink/.test(path)) {
                return <JumpThirdLink {...routeConfig} />;
              }
              if (/system\/iframe\/tabWidget/.test(path)) {
                return <TabIframe {...routeConfig} />;
              }
              if (/system\/previews\/preview/.test(path)) {
                return <PrevieView {...routeConfig} />;
              }
              if (/system\/iframe\/integratedLogin/.test(path)) {
                return <IntegratedLogin {...routeConfig} />;
              }
              if (/system\/notifications/.test(path)) {
                return <Notifications {...routeConfig} />;
              }
              if (/page\/integratedLoginPage/.test(path)) {
                return <IntegratedLoginPage {...routeConfig} />;
              }
              if (/page\/jimusaerPage/.test(path)) {
                return <JimusaerPage {...routeConfig} />;
              }
            },
          },
        ],
      },

      process.env.NODE_ENV === 'development' && {
        path: '/openapi',
        exact: true,
        component: dynamic({
          loader: () =>
            import(
              /* webpackChunkName: 'civ__plugin-openapi__openapi' */ '@wisdom-utils/components/lib/AppLayout/openapi/index'
            ),
          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,
        }),
      },
    ],
  };
};