import React, { ReactElement } from 'react';
import { PatternsReactRouter } from '../components/Router';
import { RouteProps } from './Router';

export interface CairoTestAppRouterProps {
  children: React.ReactNode;
}

export function CairoTestAppRouter({ children }: CairoTestAppRouterProps) {
  React.Children.forEach(children, (currentChild) => {
    if (!React.isValidElement<RouteProps>(currentChild)) {
      throw new Error('Each child needs to be a Route element');
    }
  });

  return (
    <PatternsReactRouter>
      {children as ReactElement<RouteProps>[]}
    </PatternsReactRouter>
  );
}
