import React, { FunctionComponent, useState } from 'react';
import { BrowserRouter, Route, Redirect, Switch } from "react-router-dom";
import { HomePage } from './HomePage/HomePage';
import { ProfilePage } from './ProfilePage/ProfilePage';
import { WorkgroupPage } from './WorkgroupPage/WorkgroupPage';
import { DecisionSupportFilePage } from './DecisionSupportFilePage/DecisionSupportFilePage';
import { DashboardPage } from './DashboardPage/DashboardPage';
import { useUserProfile } from '../gql/queries/profile';
import { LoggedInContext } from '../hooks/useLoggedIn';
import { PrivateRoute } from './PrivateRoute';
import { useKonamiCode } from '../hooks/useKonamiCode';
import { Modal } from './Modal';

export interface AppProps {

}

export const App: FunctionComponent<AppProps> = () => {
  const { user } = useUserProfile();

  const [ showBoneyM, setShowBoneyM ] = useState(false);
  useKonamiCode(() => setShowBoneyM(true));

  return (
    <LoggedInContext.Provider value={user.id !== ''}>
      <BrowserRouter>
        <Switch>
          <Route path="/" exact component={HomePage} />
          <PrivateRoute path="/profile" exact component={ProfilePage} />
          <PrivateRoute path="/workgroups/:id" exact component={WorkgroupPage} />
          <PrivateRoute path="/decisions/:id" exact component={DecisionSupportFilePage} />
          <PrivateRoute path="/dashboard" exact component={DashboardPage} />
          <Route component={() => <Redirect to="/" />} />
        </Switch>
      </BrowserRouter>
      {
        showBoneyM ?
        <Modal active={true} showCloseButton={true} onClose={() => setShowBoneyM(false)}>
          <iframe width={560} height={315}
            frameBorder={0}
            allowFullScreen={true}
            src="https://www.youtube.com/embed/uVzT5QEEQ2c?autoplay=1" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture">
          </iframe>
        </Modal> :
        null
      }
    </LoggedInContext.Provider>
  );
}