import React from 'react';
import { Redirect, Route } from 'react-router-dom';
import { IonApp, IonRouterOutlet } from '@ionic/react';
import { IonReactRouter } from '@ionic/react-router';

import '@ionic/react/css/core.css';
import '@ionic/react/css/normalize.css';
import '@ionic/react/css/structure.css';
import '@ionic/react/css/typography.css';
import '@ionic/react/css/padding.css';
import '@ionic/react/css/float-elements.css';
import '@ionic/react/css/text-alignment.css';
import '@ionic/react/css/text-transformation.css';
import '@ionic/react/css/flex-utils.css';
import '@ionic/react/css/display.css';

import './theme/variables.css';

import Home from './pages/Home';
import Account from './pages/Account';
import Auth from './pages/Auth';
import Stats from './pages/Stats';

// Cast components to avoid React 18 / React Router v5 JSX element type conflicts
const RouteAny = Route as any;
const RedirectAny = Redirect as any;
const IonReactRouterAny = IonReactRouter as any;
const IonRouterOutletAny = IonRouterOutlet as any;
const IonAppAny = IonApp as any;

const App = (): any => (
  <IonAppAny>
    <IonReactRouterAny basename={import.meta.env.BASE_URL}>
      <IonRouterOutletAny>
        <RouteAny exact path="/auth" component={Auth} />
        <RouteAny exact path="/home" component={Home} />
        <RouteAny exact path="/stats" component={Stats} />
        <RouteAny exact path="/account" component={Account} />
        <RouteAny exact path="/" render={() => <RedirectAny to="/home" />} />
      </IonRouterOutletAny>
    </IonReactRouterAny>
  </IonAppAny>
);

export default App;
