import { useRef } from "react"
import Head from "next/head"
import type { NextPage } from "next"
import styled from "styled-components"

import { StarsBgImage } from "@/components/shared/assets"
import { LottieBackground } from "@/components/shared/components/BlueStarsBgLayout"
import { StyledBlueStarsBgLayout } from "@/components/shared/components/BlueStarsBgLayout/styles"
import {
  EarnFooter,
  EarnHeader,
  EarnHeroSection,
  StartBuildingSection,
} from "@/components/earn"
import { getBaseUrl } from "@/components/shared/actions"

const Home: NextPage = () => {
  const startBuildingRef = useRef<HTMLDivElement>(null)
  return (
    <>
      <HeadComponent />
      <StyledBlueStarsBgLayout>
        {/* Header  */}
        <EarnHeader />

        {/* Background styles */}
        <BgContainer />
        <LottieBackground />

        <ContentWrapper>
          {/* Hero section */}
          <EarnHeroSection
            scrollToStartBuilding={() =>
              startBuildingRef.current?.scrollIntoView({ behavior: "smooth" })
            }
          />

          {/* Start Building Section */}
          <StartBuildingSection ref={startBuildingRef} />

          <Border />

          {/* Footer */}
          <EarnFooter />
        </ContentWrapper>
      </StyledBlueStarsBgLayout>
    </>
  )
}

export const ContentWrapper = styled.div`
  flex-direction: column;
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
`

const BgContainer = styled.div`
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 70.7rem;
  background-image: url(${StarsBgImage.src});
  background-size: cover;
  z-index: 1;

  @media (max-width: 768px) {
    height: 100vh;
    background-position: center top;
  }

  @media (max-width: 480px) {
    background-position: top center;
  }
`

const Border = styled.div`
  height: 1px;
  width: 80%;
  background: linear-gradient(to right, black, white, black);
  opacity: 0.8;
`

export default Home

const HeadComponent = () => {
  const APP_TITLE = "Agents by Brahma"
  const APP_NAME = "Automate Your Onchain Actions with Brahma Agents"
  const DESCRIPTION =
    "Brahma Agents automate, execute and optimize your assets onchain. Set your preferences, and let them handle swaps, yield, and more."
  const KEYWORDS = "defi, earn, brahma, crypto"
  const OG_URL =
    "https://brahma-static.s3.us-east-2.amazonaws.com/Brahma-Agents-OG2x.webp"

  const TWITTER_HANDLE = "@brahmafi"
  const DOMAIN = "brahma.fi"

  return (
    <Head>
      {/* General Metadata */}
      <title>{APP_TITLE}</title>
      <meta name="description" content={DESCRIPTION} />
      <meta name="keywords" content={KEYWORDS} />

      {/* Open Graph (OG) Metadata */}
      <meta property="og:title" content={APP_NAME} />
      <meta property="og:description" content={DESCRIPTION} />
      <meta property="og:image" content={OG_URL} />
      <meta property="og:image:secure_url" content={OG_URL} />
      <meta property="og:url" content={getBaseUrl()} />
      <meta property="og:type" content="website" />
      <meta property="og:site_name" content={APP_NAME} />

      {/* Twitter Card Metadata */}
      <meta name="twitter:card" content="summary_large_image" />
      <meta name="twitter:site" content={TWITTER_HANDLE} />
      <meta name="twitter:creator" content={TWITTER_HANDLE} />
      <meta name="twitter:title" content={APP_NAME} />
      <meta name="twitter:description" content={DESCRIPTION} />
      <meta name="twitter:image" content={OG_URL} />
      <meta name="twitter:domain" content={DOMAIN} />
    </Head>
  )
}
