import React from 'react';
import PropTypes from 'prop-types';
import { Route, Switch } from 'react-router-dom';

import importComponent from 'Common/moduleImport/index.js';
import NoMatch from '../noMatch/NoMatch';

class Routes extends React.Component {
    static propTypes = {
        routes: PropTypes.array,
        store: PropTypes.object,
    };


    createRoutes = routes => {
        return (
            <Switch>
                {routes.map(link => {
                    const { routeKey, routeUrl } = link;
                    return (
                        <Route
                            exact={routeUrl === '/'}
                            path={routeUrl}
                            component={importComponent(routeKey)}
                            key={routeUrl}
                        />
                    );
                })}
                <Route component={NoMatch} />
            </Switch>
        );
    };

    render() {
        return (
            <div className="content_wrapper">
                {this.createRoutes(this.props.routes)}
            </div>
        );
    }
}
export default Routes;
