<script setup lang="ts">
interface IProps {
  name: string;
  route: string;
  active: boolean;
  hover: boolean;
}

const props = withDefaults(defineProps<IProps>(), {
  name: "Nome",
  route: "Home",
  active: false,
  hover: false,
});
</script>
<template>
  <div class="item">
    <router-link :class="{ active: props.active }" :to="{ name: props.route }">
      <slot />
      <h1 :class="{ hover: props.hover }">{{ props.name }}</h1>
    </router-link>
  </div>
</template>

<style scoped lang="scss">
.item {
  a {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: var(--spacing-6);
    text-decoration: none;
    cursor: pointer;
    user-select: none;
    height: 55px;
    padding: 0 var(--spacing-4);
    transition: var(--transition);
    border-radius: var(--radius-lg);

    :visited {
      color: inherit;
    }

    &:focus-visible {
      transition: none;
      outline: 1.5px solid var(--primary-500);
    }

    h1 {
      color: var(--gray-200);
      font-size: var(--font-base);
      font-weight: var(--weight-medium);
      overflow: hidden;
      text-overflow: ellipsis;

      &.hover {
        animation: fadeEnter 1s ease;
      }

      &:not(.hover) {
        animation: fadeExit 1s ease;
      }

      @media (max-width: 768px) {
        animation: none !important;
      }
    }

    &.active {
      background-color: var(--primary-50);
      h1 {
        color: var(--primary-500);
        font-weight: var(--weight-semibold);
      }
    }
  }
}

@keyframes fadeEnter {
  0% {
    width: 0;
  }
  100% {
    width: 100%;
    max-width: 100%;
    overflow: visible;
  }
}

@keyframes fadeExit {
  0% {
    width: 100%;
    max-width: 100%;
    overflow: visible;
  }
  70% {
    width: 0;
    max-width: 0;
    overflow: hidden;
  }

  100% {
    opacity: 0;
  }
}
</style>
