import {NextPage} from "next";
import Router from "next/router";
import React from "react";

import AuthContext from "@sentrei/common/context/AuthContext";
import authType from "@sentrei/common/types/authType";
import {analytics} from "@sentrei/common/utils/firebase";
import Auth from "@sentrei/ui/components/Auth";
import Loader from "@sentrei/ui/components/Loader";

import SentreiHeader from "@sentrei/web/components/SentreiHeader";

const Login: NextPage = () => {
  const {user} = React.useContext(AuthContext);

  React.useEffect(() => {
    analytics().setCurrentScreen("login");
  }, []);

  if (user === undefined) {
    return <Loader />;
  }

  if (user) {
    Router.push("/dashboard");
  }

  return (
    <>
      <SentreiHeader sign={false} spy={false} />
      <Auth type={authType.login} />;
    </>
  );
};

export default Login;
