import React from 'react';

import { Helmet } from 'react-helmet';
import { connect } from 'react-redux';
import { renderRoutes } from 'react-router-config';
import {
  BrowserRouter as Router,
  Switch,
} from 'react-router-dom';

import config from '../../routes/config';
import generRoutes from '../../utils/routes';

function App(props) {
  // console.log("APP",config.routes.concat(generRoutes(props.global.widgets || [])))
  return (
    <>
      <Helmet
        titleTemplate={`%s - ${props.global && props.global.title}`}
        defaultTitle={`${props.global && props.global.title}`}
      >
        <link rel="shortcut icon" href={`https://panda-water.cn/web4/${props.global && props.global.shortcutIcon}`}/>
        <meta name="description" content={`${props.global && props.global.title}`} />
      </Helmet>
      <Router>
        <Switch>{renderRoutes(config.routes.concat(generRoutes(props.global && props.global.widgets || [])))}</Switch>
      </Router>
    </>
  );
}

const mapStateToProps = (state) => {
  return {
    global: state.getIn(['global', 'globalConfig'])
  }
}
export default connect(mapStateToProps, null)(App);


