<template>
  <a
    v-if="category"
    :key="category.id"
    :href="category.url"
    class="category"
  >
    <img v-if="category.imageUrl" class="category_image" :src="category.imageUrl" :alt="category.name" />
    <h4 class="category__title">{{ category.name }}</h4>
  </a>
</template>

<script setup lang="ts">
  interface Props {
    category: CategoryListComponentItem
  }

  const { category } = defineProps<Props>()
</script>

<style scoped lang="scss">
.category {
  display: flex;
  flex-direction: column;
  cursor: pointer;
  flex: 0 0 auto;
  min-width: 0;
  overflow: hidden;

  @media (max-width: 767px) {
    width: calc(50% - 6px);
  }

  @media (min-width: 768px) {
    width: calc(20% - 9.6px);
  }
}

.category_image {
  width: 100%;
  height: auto;
  aspect-ratio: 3/4;
  object-fit: cover;
  display: block;
  margin-bottom: 4px;
  transition: transform 0.3s ease;

  .category:hover & {
    transform: scale(1.05);
  }
}

.category__title {
  font-size: 1rem;
  font-weight: 300;
  margin: 0;
  padding: 24px 6px 0 6px;
  line-height: 1.4;
  color: #111;
  text-align: center;
}
</style>
