import { useEffect, useState } from "react";
import { Redirect, Route, Switch } from "react-router-dom";
import Main from "./components/Main";
import GlobalContext from "./utils/GlobalContext";
import BaseApi from "./utils/apis/BaseApi";

export default function App() {
  const [globalConfig, setGlobalConfig] = useState();

  useEffect(() => {
    BaseApi.getConfig().then(data => {
      setGlobalConfig(data);
    })
  }, [])

  return (
    globalConfig ? <GlobalContext.Provider value={{
      ...globalConfig,
      setGlobalConfig
    }}>
      <Switch>
        <Redirect exact path="/" to={"/main"}></Redirect>
        <Redirect path="/home" to={"/main/home"}></Redirect>
        <Route path="/main" render={e => {
          return <Main />
        }}></Route>
        {/* <Route exact path="/login" component={Login}></Route> */}
      </Switch>
    </GlobalContext.Provider> : null
  );
}
