<template>
  <div class="index">
    <div
      class="cards-list"
    >
      <div
        v-for="product in productCardData"
        :key="product.id"
        class="card"
        @click="router.push(`/product/${product.id}`)"
      >
        <img class="card__image" :src="product?.images[0]?.src" alt="card?.image">

        <div class="card__description">
          <div>{{ product?.name }}</div>

          <div class="d-flex align-items-center">
            {{ product?.price }}
            <Icon name="ph:currency-rub" />
          </div>

          <div v-if="product?.colors?.length > 1">
            {{ `+${product?.colors?.length} Цвета` }}
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { useProductsList } from '~/composables'

const { productCardData } = useProductsList()
const router = useRouter()
</script>

<style lang="scss">
.cards-list {
  padding: 15px;

  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  gap: 4px;
}

.card {
  min-width: 300px;
  display: flex;
  flex-direction: column;
  cursor: pointer;

  &__image {
    width: 100%;
  }

  &__description {
    padding-inline: 10px;
  }
}
</style>
