---
import IconChevronLeft from "@/assets/icons/IconChevronLeft.svg";
import LinkButton from "./LinkButton.astro";
import { SITE } from "@/config";
---

{
  SITE.showBackButton && (
    <div class="app-layout flex items-center justify-start">
      <LinkButton
        id="back-button"
        href="/"
        class="focus-outline -ms-2 mt-8 mb-2 hover:text-foreground/75"
      >
        <IconChevronLeft class="inline-block size-6 rtl:rotate-180" />
        <span>Go back</span>
      </LinkButton>
    </div>
  )
}

<script>
  /* Update Search Praam */
  function updateGoBackUrl() {
    const backButton: HTMLAnchorElement | null =
      document.querySelector("#back-button");

    const backUrl = sessionStorage.getItem("backUrl");

    if (backUrl && backButton) {
      backButton.href = backUrl;
    }
  }

  document.addEventListener("astro:page-load", updateGoBackUrl);
  updateGoBackUrl();
</script>
