<script lang="ts">
import { onMount } from "svelte";
import ClickableAreaPage from "$lib/Events/AniListBadges/EasterEvent2025/ClickableAreaPage.svelte";
import MultipleChoicePage from "$lib/Events/AniListBadges/EasterEvent2025/MultipleChoicePage.svelte";
import RiddlePage from "$lib/Events/AniListBadges/EasterEvent2025/RiddlePage.svelte";
import "$lib/Events/AniListBadges/EasterEvent2025/event.css";

const multipleChoiceAnswers = [
	"The Beginning After the End",
	"Domestic Girlfriend",
	"Spy Classroom",
	"Kaguya-sama: Love is War",
];
const clickableAreaAnswers = [
	"https://media1.tenor.com/m/RkgfXhcewvoAAAAC/rui-tachibana-tachibana-rui.gif",
	"https://media1.tenor.com/m/fOBbcJOFZ-kAAAAC/hina-hina-tachibana.gif",
	"https://media1.tenor.com/m/GQT7FHW-w-IAAAAC/anime-domestic-girlfriend.gif",
];
let page = 0;

onMount(() => {
	const urlParameters = new URLSearchParams(window.location.search);
	const pageParameter = urlParameters.get("page");

	if (pageParameter) page = parseInt(pageParameter) || 0;
});

const updatePage = (to: number | undefined = undefined) => {
	const url = new URL(window.location.href);

	if (to) {
		page = to;
	} else {
		page += 1;
	}

	url.searchParams.set("page", page.toString());
	window.history.replaceState(null, "", url.toString());
};
</script>

<div class="card main-content">
  {#if page === 0}
    <p class="big-text">Welcome to the Easter Egg Hunt!</p>
    <button onclick={() => updatePage()}>Begin Hunt</button>
    <br />
    <p>due.moe × AniList Badges</p>
  {:else if page === 1}
    <MultipleChoicePage
      prompt="Which of these anime has the best adaptation?"
      answers={multipleChoiceAnswers}
      correctIndex={1}
      onComplete={() => updatePage()}
    />
  {:else if page === 2}
    <ClickableAreaPage
      prompt="Which of these scenes contain a little action?"
      images={clickableAreaAnswers}
      correctIndex={2}
      onComplete={() => updatePage()}
    />
  {:else if page === 3}
    <RiddlePage
      riddle="An alternate way to refer to Domestic Girlfriend is ..."
      answer="peak"
      onComplete={() => updatePage()}
      hint="peak"
    />
  {:else}
    <p class="big-text">Congratulations! You won!</p>

    <img
      src="https://media1.tenor.com/m/S8zYyudMjXAAAAAC/domekano-domestic-girlfriend.gif"
      alt="Anime scene"
    />

    <br />

    <p>due.moe × AniList Badges</p>
  {/if}
</div>

<style>
  .main-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
  }
</style>
