import React, { FC } from 'react';
import { DefaultPage } from './StaticPages';
import { StaticRoutes, ApiConfig } from './definition';

export const StaticPage: FC<{
  routeProps: any;
  appName: string;
  mainPath: string;
  staticRoutes?: StaticRoutes;
  apiConfig: ApiConfig;
}> = ({ routeProps, appName, mainPath, staticRoutes, apiConfig }) => {
  const { pathname } = routeProps.location;

  let TargetPage: FC<any> = () => (
    <DefaultPage appName={appName} mainPath={mainPath} body={pathname} />
  );
  if (staticRoutes && staticRoutes[pathname]) {
    TargetPage = staticRoutes[pathname];
  }

  return (
    <TargetPage
      appName={appName}
      mainPath={mainPath}
      apiConfig={apiConfig}
      {...routeProps}
    />
  );
};
