import React from 'react';
import { Helmet } from 'react-helmet';
import { renderRoutes } from 'react-router-config';
import { BrowserRouter as Router, Switch } from 'react-router-dom';
import { appConnector } from './store';
import Authozed from '@/utils/authority';
import UserLogin from '@/pages/user/login';
import UserLayout from '@/layouts/UserLayout';
import { AUTHORITY, BASENAME } from '@/utils/constants';
import { Modal } from 'antd';
import { PictureWallProvider } from '@/components/Upload/context';
export default appConnector(function App(props) {
  const { routesConfig } = props;
  const getConfirmation = (msg, callBack) => {
    Modal.confirm({
      title: '确认',
      content: msg,
      okText: '确认',
      cancelText: '取消',
      onOk() {
        callBack(true);
      },
      onCancel() {
        callBack(false);
      },
    });
  };
  return (
    <>
      <Helmet titleTemplate="%s - 运维平台" defaultTitle="运维平台">
        <meta name="description" content="运维平台" />
      </Helmet>
      <Router basename={BASENAME} getUserConfirmation={getConfirmation}>
        <Authozed
          noMatch={
            <UserLayout>
              <UserLogin />
            </UserLayout>
          }
          authority={[AUTHORITY.LOGIN]}
        >
          <PictureWallProvider>
            <Switch>{renderRoutes(routesConfig.routes)}</Switch>
          </PictureWallProvider>
        </Authozed>
      </Router>
    </>
  );
});
