<!-- Menu sticky horizontal -->
<!-- TODO: review -->
<template>
  <LayoutContainer>
    <v-row>
      <v-col
        cols="12"
      >
        <v-list
          class="menu-container"
          density="compact"
          :class="{ 'sticky-menu': isSticky }"
        >
          <div v-for="menu in menus" :key="menu.anchor">
            <nuxt-link :to="{ path: '', hash: '#' + menu.anchor }">
              <v-list-item
                :class="{ active : isSticky && layoutStore.isAnchoredSectionOnScreen[menu.anchor] }"
              >
                {{ menu.label }}
              </v-list-item>
            </nuxt-link>
          </div>
        </v-list>
      </v-col>
    </v-row>
  </LayoutContainer>
</template>

<script setup lang="ts">

import type { PropType } from "@vue/runtime-core";
import type { MenuScroll } from "~/types/interface";
import { useLayoutStore } from "~/stores/layoutStore";

const props = defineProps({
  menus: {
    type: Array as PropType<Array < MenuScroll >>,
    required: true
  }
});

const layoutStore = useLayoutStore()

const isSticky: Ref<boolean> = ref(false);

onMounted(() => {
  window.addEventListener('scroll', handleScroll);
})

const handleScroll = () => {
  isSticky.value = window.scrollY > 800;
}
</script>

<style scoped lang="scss">
.sticky-menu {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: white;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

.menu-container {
  z-index: 3;
  display: flex;
  justify-content: space-around;
  background: white;
  color: #071b1f;
  font-family: "Barlow", serif;
  font-size: 1rem;
  line-height: 19px;
  align-items: center;
  text-align: center;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  border-bottom: 0.1rem solid #eaeaea;

  a {
    text-decoration: none;
    color: #071b1f;
  }

  a:hover {
    text-decoration: underline;
  }
}

.active {
  font-weight: 800;
}
</style>

