<template>
  <div class="pageTop" v-intersect="onTopIntersect"/>

  <client-only>
    <v-btn
        v-if="isVisible"
        aria-label="Back to the top of the page"
        :size="48"
        @click="onClick"
        class="back-to-the-top"
    >
      <v-icon>fas fa-arrow-up</v-icon>
    </v-btn>
  </client-only>
</template>

<script setup lang="ts">
const isVisible: Ref<boolean> = ref(false)

const onTopIntersect = (intersect: boolean) => {
  isVisible.value = !intersect
}

const onClick = () => {
  window.scrollTo({ top: 0, behavior: 'smooth' });
}
</script>

<style scoped lang="scss">
.pageTop {
  position: absolute;
  top: 0;
  height: 300px;
  width: 0;
}

.back-to-the-top {
  position: fixed;
  right: 5%;
  bottom: 58px;
  z-index: 100;
  border-radius: 24px;
  background: rgb(var(--v-theme-primary));
  color: rgb(var(--v-theme-on-primary));

  @media (max-width: 600px) {
    bottom: 30px;
  }
}
</style>