<template>
  <AdaptiveGrid :item-width="itemWidth">
    <div
      v-for="index in count"
      :key="index"
      class="barneo-product-skeleton-card"
    >
      <!-- Верхний блок с border (как в реальной карточке) -->
      <div class="barneo-product-skeleton-top">
        <!-- Заголовок с метаданными и кнопкой избранного -->
        <div class="barneo-product-skeleton-header">
          <!-- Metadata skeleton -->
          <div class="barneo-product-skeleton-metadata">
            <div class="barneo-product-skeleton-code"></div>
            <div class="barneo-product-skeleton-article"></div>
          </div>

          <!-- Heart icon skeleton -->
          <div class="barneo-product-skeleton-heart"></div>
        </div>

        <!-- Image skeleton -->
        <div class="barneo-product-skeleton-image">
          <div class="barneo-product-skeleton-image-placeholder"></div>
        </div>
      </div>

      <!-- Нижний блок без border -->
      <div class="barneo-product-skeleton-bottom">
        <!-- Первый подблок: цена, бренд, тег -->
        <div class="barneo-product-skeleton-info">
          <!-- Price skeleton -->
          <div class="barneo-product-skeleton-price"></div>

          <!-- Brand skeleton -->
          <div class="barneo-product-skeleton-brand">
            <div class="barneo-product-skeleton-brand-text"></div>
            <div class="barneo-product-skeleton-brand-checkmark"></div>
          </div>

          <!-- Availability skeleton -->
          <div class="barneo-product-skeleton-availability"></div>
        </div>

        <!-- Второй подблок: название, доставка, кнопка -->
        <div class="barneo-product-skeleton-actions">
          <!-- Title skeleton -->
          <div class="barneo-product-skeleton-title">
            <div class="barneo-product-skeleton-title-line"></div>
            <div class="barneo-product-skeleton-title-line"></div>
          </div>

          <!-- Delivery skeleton -->
          <div class="barneo-product-skeleton-delivery"></div>

          <!-- Button skeleton -->
          <div class="barneo-product-skeleton-button"></div>
        </div>
      </div>
    </div>
  </AdaptiveGrid>
</template>

<script setup lang="ts">
import AdaptiveGrid from "./AdaptiveGrid.vue";

interface BarneoProductsSkeletonProps {
  /** Количество скелетонов для отображения */
  count?: number;
  /** Ширина элемента */
  itemWidth?: number;
}

withDefaults(defineProps<BarneoProductsSkeletonProps>(), {
  count: 6,
  itemWidth: 250,
});
</script>

<style scoped>
.barneo-products-skeleton {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--barneo-spacing-lg);
  padding: var(--barneo-spacing-2xl);
}

.barneo-product-skeleton-card {
  display: flex;
  flex-direction: column;
  background-color: transparent;
  border-radius: var(--barneo-radius-xl);
  gap: 16px;
  overflow: hidden;
}

.barneo-product-skeleton-top {
  border: 1px solid var(--barneo-product-card-border);
  border-radius: var(--barneo-radius-xl);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.barneo-product-skeleton-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 1rem 1rem 0 1rem;
}

.barneo-product-skeleton-metadata {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.barneo-product-skeleton-code {
  height: 12px;
  width: 60px;
  background: linear-gradient(
    90deg,
    var(--barneo-bg-skeleton) 25%,
    var(--barneo-bg-hover) 50%,
    var(--barneo-bg-skeleton) 75%
  );
  background-size: 200% 100%;
  animation: barneo-skeleton-shimmer 1.5s infinite;
  border-radius: var(--barneo-radius-sm);
}

.barneo-product-skeleton-article {
  height: 12px;
  width: 80px;
  background: linear-gradient(
    90deg,
    var(--barneo-bg-skeleton) 25%,
    var(--barneo-bg-hover) 50%,
    var(--barneo-bg-skeleton) 75%
  );
  background-size: 200% 100%;
  animation: barneo-skeleton-shimmer 1.5s infinite;
  border-radius: var(--barneo-radius-sm);
}

.barneo-product-skeleton-heart {
  width: 20px;
  height: 20px;
  background: linear-gradient(
    90deg,
    var(--barneo-bg-skeleton) 25%,
    var(--barneo-bg-hover) 50%,
    var(--barneo-bg-skeleton) 75%
  );
  background-size: 200% 100%;
  animation: barneo-skeleton-shimmer 1.5s infinite;
  border-radius: var(--barneo-radius-sm);
}

.barneo-product-skeleton-image {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: var(--barneo-radius-xl);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.barneo-product-skeleton-image-placeholder {
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    var(--barneo-bg-skeleton) 25%,
    var(--barneo-bg-hover) 50%,
    var(--barneo-bg-skeleton) 75%
  );
  background-size: 200% 100%;
  animation: barneo-skeleton-shimmer 1.5s infinite;
}

.barneo-product-skeleton-bottom {
  display: flex;
  flex-direction: column;
  gap: 12px;
  justify-content: space-between;
  flex: 1;
}

.barneo-product-skeleton-info {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.barneo-product-skeleton-price {
  height: 20px;
  width: 80px;
  background: linear-gradient(
    90deg,
    var(--barneo-bg-skeleton) 25%,
    var(--barneo-bg-hover) 50%,
    var(--barneo-bg-skeleton) 75%
  );
  background-size: 200% 100%;
  animation: barneo-skeleton-shimmer 1.5s infinite;
  border-radius: var(--barneo-radius-sm);
}

.barneo-product-skeleton-brand {
  display: flex;
  align-items: center;
  gap: var(--barneo-spacing-sm);
}

.barneo-product-skeleton-brand-text {
  height: 16px;
  width: 60px;
  background: linear-gradient(
    90deg,
    var(--barneo-bg-skeleton) 25%,
    var(--barneo-bg-hover) 50%,
    var(--barneo-bg-skeleton) 75%
  );
  background-size: 200% 100%;
  animation: barneo-skeleton-shimmer 1.5s infinite;
  border-radius: var(--barneo-radius-sm);
}

.barneo-product-skeleton-brand-checkmark {
  width: 16px;
  height: 16px;
  background: linear-gradient(
    90deg,
    var(--barneo-bg-skeleton) 25%,
    var(--barneo-bg-hover) 50%,
    var(--barneo-bg-skeleton) 75%
  );
  background-size: 200% 100%;
  animation: barneo-skeleton-shimmer 1.5s infinite;
  border-radius: var(--barneo-radius-sm);
}

.barneo-product-skeleton-availability {
  height: 20px;
  width: 80px;
  background: linear-gradient(
    90deg,
    var(--barneo-bg-skeleton) 25%,
    var(--barneo-bg-hover) 50%,
    var(--barneo-bg-skeleton) 75%
  );
  background-size: 200% 100%;
  animation: barneo-skeleton-shimmer 1.5s infinite;
  border-radius: var(--barneo-radius-md);
}

.barneo-product-skeleton-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.barneo-product-skeleton-title {
  display: flex;
  flex-direction: column;
  gap: var(--barneo-spacing-xs);
}

.barneo-product-skeleton-title-line {
  height: 16px;
  background: linear-gradient(
    90deg,
    var(--barneo-bg-skeleton) 25%,
    var(--barneo-bg-hover) 50%,
    var(--barneo-bg-skeleton) 75%
  );
  background-size: 200% 100%;
  animation: barneo-skeleton-shimmer 1.5s infinite;
  border-radius: var(--barneo-radius-sm);
}

.barneo-product-skeleton-title-line:first-child {
  width: 100%;
}

.barneo-product-skeleton-title-line:last-child {
  width: 70%;
}

.barneo-product-skeleton-delivery {
  height: 14px;
  width: 120px;
  background: linear-gradient(
    90deg,
    var(--barneo-bg-skeleton) 25%,
    var(--barneo-bg-hover) 50%,
    var(--barneo-bg-skeleton) 75%
  );
  background-size: 200% 100%;
  animation: barneo-skeleton-shimmer 1.5s infinite;
  border-radius: var(--barneo-radius-sm);
}

.barneo-product-skeleton-button {
  height: 40px;
  width: 100%;
  background: linear-gradient(
    90deg,
    var(--barneo-bg-skeleton) 25%,
    var(--barneo-bg-hover) 50%,
    var(--barneo-bg-skeleton) 75%
  );
  background-size: 200% 100%;
  animation: barneo-skeleton-shimmer 1.5s infinite;
  border-radius: var(--barneo-radius-lg);
}

@keyframes barneo-skeleton-shimmer {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

/* Responsive */
@media (max-width: 767px) {
  .barneo-products-skeleton {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: var(--barneo-spacing-md);
    padding: var(--barneo-spacing-lg);
  }
}

@media (min-width: 768px) and (max-width: 1023px) {
  .barneo-products-skeleton {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: var(--barneo-spacing-lg);
    padding: var(--barneo-spacing-xl);
  }
}

@media (min-width: 1024px) {
  .barneo-products-skeleton {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: var(--barneo-spacing-lg);
    padding: var(--barneo-spacing-2xl);
  }
}
</style>
