<template>
  <div class="card">
    <router-link
        :to="translations.i18nRoute({ name: 'product', params: { productSlug: product.slug } })"
    >
      <img
          class="card__image"
          :src="product.images.edges[0].node.image"
          :alt="product.name"
      >
    </router-link>
    <div class="card__content">
      <p class="card__price">{{ product.price }}</p>
      <p class="card__name">{{ product.name }}</p>
      <el-rate
          v-model="rating"
          size="large"
          allow-half
          disabled
      />
      <div class="card__quantity">{{ t('cards.product.stock') }} {{ product.quantity }}</div>
      <div class="card__bottom">
        <ui-button class="card__bottom-button">
          {{ t('buttons.addToCart') }}
        </ui-button>
        <div class="card__bottom-wishlist">
          <i class="pi pi-heart"></i>
    <!--      <i class="pi pi-heart-fill"></i>-->
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import {useI18n} from "vue-i18n";
import {computed} from "vue";
import UiButton from "@/components/ui/ui-button.vue";
import translations from "@/core/helpers/translations.js";

const props = defineProps({
  product: Object
})

const {t} = useI18n()

const rating = computed(() => {
  return props.product.feedbacks.edges[0] ? props.product.feedbacks.edges[0]?.node?.rating : 5
})
</script>

<style lang="scss" scoped>
.card {
  border-radius: $default_border_radius;
  border: 1px solid $black;
  width: 340px;
  background-color: $white;
  transition: 0.2s;
  position: relative;

  @include hover {
    box-shadow: 0 0 10px 2px rgba(0, 0, 0, 0.4);
  }

  &__image {
    width: 100%;
    height: 300px;
    object-fit: cover;
    border-radius: $default_border_radius;
  }

  &__content {
    padding: 20px;
  }

  &__price {
    font-weight: 700;
    font-size: 22px;
  }

  &__name {
    word-break: break-all;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 1;
    overflow: hidden;
    font-weight: 500;
    font-size: 18px;
  }

  &__quantity {
    font-size: 14px;
  }

  &__bottom {
    margin-top: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 5px;
    max-width: 100%;

    &-button {
      width: 84%;
    }

    &-wishlist {
      cursor: pointer;
      width: 34px;
      height: 34px;
      flex-shrink: 0;
      background-color: $accent;
      border-radius: $default_border_radius;
      display: grid;
      place-items: center;
      transition: 0.2s;

      font-size: 22px;
      color: $white;

      @include hover {
        background-color: $accentLight;
      }
    }
  }
}
</style>