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

export interface AppProps {

}

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

  return (
    <LoggedInContext.Provider value={user.id !== ''}>
      <BrowserRouter>
        <Switch>
          <Route path="/" exact component={HomePage} />
          <PrivateRoute path="/profile" exact component={ProfilePage} />
          <PrivateRoute path="/dashboard" exact component={DashboardPage} />
          <Route component={() => <Redirect to="/" />} />
        </Switch>
      </BrowserRouter>
    </LoggedInContext.Provider>
  );
}