import './index.scss';

import React from 'react';
import { Layout } from 'antd';
import { Switch , Route , Redirect } from 'react-router-dom';

const {Content} = Layout;

export function CommonContent(props) {
    const {routesAndRedirects = {} , componentMap = {}} = props;
    const {redirects = [] , routes = []} = routesAndRedirects;
    return (
        <Content className="common-content">
            <Switch>
                {routes.map(v => {
                    return (
                        <Route
                            key={v.url}
                            path={v.url}
                            component={componentMap[ v.code ]}
                        />
                    );
                })}
                {redirects.map(v => {
                    return (
                        <Redirect
                            key={v.from + 'r'}
                            to={v.to}
                            from={v.from}
                            exact
                        />
                    );
                })}
            </Switch>
        </Content>
    );
}
