<template>
  <a
    v-if="product"
    :key="product.id"
    :href="product.url"
    class="product"
  >
    <img v-if="product.fullImageUrl" class="product_image" :src="product.fullImageUrl" :alt="product.name" />
    <h4 class="product__title">
      {{ product.name }}
    </h4>
    <span class="product__price">{{ product.formattedPrice }}</span>
  </a>
</template>

<script setup lang="ts">
  interface Props {
    product: ProductListComponentItem
  }

  const { product } = defineProps<Props>();

</script>

<style scoped lang="scss">
.product {
  display: flex;
  flex-direction: column;
  cursor: pointer;
  flex: 0 0 auto;
  min-width: 0;
  overflow: hidden;
  text-decoration: inherit;
  transition: transform 0.2s ease;

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

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

  &:hover {
    transform: translateY(-4px);
  }
}

.product_image {
  width: 100%;
  height: auto;
  aspect-ratio: 3/4;
  object-fit: cover;
  display: block;
  margin-bottom: 4px;
}

.product__title {
  font-size: 1rem;
  font-weight: 300;
  margin: 0;
  line-height: 1.4;
  color: #111;
}

.product__price {
  font-size: 1rem;
  font-weight: 600;
  color: #111;
}
</style>
