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

import AuthContext from "@sentrei/common/context/AuthContext";
import {analytics} from "@sentrei/common/utils/firebase";
import Footer from "@sentrei/ui/components/Footer";
import Loader from "@sentrei/ui/components/Loader";
import OneTap from "@sentrei/ui/components/OneTap";
import Spacing from "@sentrei/ui/components/Spacing";
import SentreiBanner from "@sentrei/web/components/SentreiBanner";
import SentreiFaq from "@sentrei/web/components/SentreiFaq";
import SentreiFeature from "@sentrei/web/components/SentreiFeature";
import SentreiHeader from "@sentrei/web/components/SentreiHeader";
import SentreiPricing from "@sentrei/web/components/SentreiPricing";
import SentreiProduct from "@sentrei/web/components/SentreiProduct";
import SentreiScreen from "@sentrei/web/components/SentreiScreen";
import SentreiSlider from "@sentrei/web/components/SentreiSlider";
import SentreiTestimonial from "@sentrei/web/components/SentreiTestimonial";

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

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

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

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

  return (
    <>
      <Head>
        <title>Sentrei</title>
        <meta name="Description" content="Sentrei landing page" />
      </Head>
      <OneTap />
      <SentreiHeader />
      <SentreiBanner />
      <Spacing />
      <SentreiScreen />
      <Spacing />
      <div id="product">
        <SentreiProduct />
      </div>
      <SentreiSlider />
      <Spacing />
      <div id="feature">
        <SentreiFeature />
      </div>
      <Spacing />
      <div id="testimonial">
        <SentreiTestimonial />
      </div>
      <Spacing />
      <div id="pricing">
        <SentreiPricing />
      </div>
      <Spacing />
      <div id="faq">
        <SentreiFaq />
      </div>
      <Spacing />
      <Footer />
    </>
  );
};

export default Index;
