<script lang="ts">
  import { env } from '$env/dynamic/public';
  import localforage from 'localforage';

  let heroSection = $state<HTMLElement>();

  const scrollPastHero = () => {
    if (!heroSection) return;

    const heroBottom = heroSection.getBoundingClientRect().bottom + window.scrollY;

    window.scrollTo({ top: heroBottom, behavior: 'smooth' });
  };
</script>

<section class="hero" bind:this={heroSection}>
  <div class="hero-content">
    <p class="tagline">The AniList Companion</p>

    <h1 class="headline">Never miss what's due.</h1>

    <p class="subheadline">
      Track airing episodes, new manga chapters, and subtitle releases—all in one place.

      <br />
      <br />

      AniList keeps your list. <strong>due.moe</strong> keeps you current.
    </p>

    <a
      class="cta"
      href={`https://anilist.co/api/v2/oauth/authorize?client_id=${env.PUBLIC_ANILIST_CLIENT_ID}&redirect_uri=${env.PUBLIC_ANILIST_REDIRECT_URI}&response_type=code`}
      onclick={async () => {
        await localforage.setItem(
          'redirect',
          window.location.origin + window.location.pathname + window.location.search
        );
      }}
    >
      Connect with AniList
    </a>
  </div>

  <button class="scroll-indicator" onclick={scrollPastHero}>
    <span class="scroll-text">See More</span>
    <span class="scroll-arrow">↓</span>
  </button>
</section>

<style>
  .hero {
    min-height: calc(100vh - 8rem);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 2rem;
    position: relative;
    animation: heroSlideIn 0.6s ease forwards;
  }

  @keyframes heroSlideIn {
    from {
      transform: translateY(20px);
    }

    to {
      transform: translateY(0);
    }
  }

  /*.hero-content {
    max-width: 640px;
  }*/

  .tagline {
    font-size: 0.85rem;
    /*text-transform: uppercase;*/
    letter-spacing: 0.15em;
    color: var(--base04);
    margin: 0 0 1rem 0;
    font-weight: 500;
  }

  .headline {
    font-size: clamp(2.5rem, 8vw, 4.5rem);
    font-weight: 700;
    margin: 0 0 1.5rem 0;
    color: var(--base06);
    line-height: 1.1;
    letter-spacing: -0.02em;
  }

  .subheadline {
    font-size: 1.15rem;
    color: var(--base04);
    margin: 0 0 2.5rem 0;
    line-height: 1.6;
  }

  .subheadline strong {
    color: var(--base06);
    font-weight: 600;
  }

  .cta {
    display: inline-block;
    padding: 0.9rem 2rem;
    background-color: var(--base06);
    color: var(--base00);
    font-weight: 600;
    font-size: 0.95rem;
    border-radius: 6px;
    text-decoration: none;
    transition:
      transform 0.2s ease,
      box-shadow 0.2s ease;
  }

  .cta:hover {
    text-decoration: none;
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  }

  .cta:active {
    transform: translateY(0);
  }

  .scroll-indicator {
    position: absolute;
    bottom: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    color: var(--base03);
    animation: float 2s ease-in-out infinite;
    background: none;
    border: none;
    cursor: pointer;
    transition: color ease;
  }

  .scroll-indicator:hover {
    color: var(--base04);
  }

  .scroll-text {
    font-size: 0.75rem;
    /*text-transform: uppercase;*/
    letter-spacing: 0.1em;
  }

  .scroll-arrow {
    font-size: 1.25rem;
  }

  @keyframes float {
    0%,
    100% {
      transform: translateY(0);
    }

    50% {
      transform: translateY(6px);
    }
  }

  @media (max-width: 600px) {
    .hero {
      min-height: calc(100vh - 6rem);
      padding: 1.5rem;
    }

    .subheadline {
      font-size: 1rem;
    }

    .cta {
      width: 100%;
      text-align: center;
    }
  }
</style>
