import { For, onMount, type Component } from "solid-js";
import { useStore } from "@nanostores/solid";
import { $currentPage } from "@/scripts/currentPage"

type Page = {
  path: string,
  name: string,
};

const pages: Page[] = [
  { path: "/", name: "about" },
  { path: "/music", name: "music" },
  { path: "/writing", name: "writing" },
]

const inactiveClasses = "text-xl text-fg_light transition-all duration-300 hover:scale-[110%] hover:text-foreground align-middle";
const activeClasses = "font-bold !text-foreground";


const Nav: Component = () => {
  const currentPage = useStore($currentPage);

  onMount(() => {
    $currentPage.set(window.location.pathname);
  });

  return (
    <nav class="pt-4 w-full flex flex-row justify-around">
      <For each={pages}>{
        (page, _) =>
          <a class={
            (page.path == currentPage() || page.path + "/" == currentPage()) ?
              inactiveClasses + " " + activeClasses :
              inactiveClasses
          }
            href={page.path}
            onClick={() => {
              $currentPage.set(page.path);
            }}
          >
            {page.name}
          </a>
      }</For>
    </nav>
  );
};

export default Nav;
