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

const PokemonShow = lazy((): Promise<any> => import('./pokemon/show'));
const PokemonIndex = lazy((): Promise<any> => import('./pokemon/index'));
const RelayTest = lazy((): Promise<any> => import('./relay_test'));

import NotFound from './not_found';

function Pokemon({match}: RouteComponentProps<void>): React.FunctionComponentElement<void> {
  return (
    <>
      <Suspense fallback={<div>Loading...</div>}>
        <Switch>
          <Route component={RelayTest} exact path={`${match.path}/:id`} />
          <Route component={RelayTest} exact path={`${match.path}`} />

          <Route component={NotFound} />
        </Switch>
      </Suspense>
    </>
  );
}

Pokemon.propTypes = {
  match: PropTypes.object.isRequired,
};

export default Pokemon;
