<section class="pack-favorites" data-reveal>
  <div class="container">
    {%- if section.settings.eyebrow != blank -%}
      <span class="section-eyebrow">{{ section.settings.eyebrow }}</span>
    {%- endif -%}
    <div class="pack-favorites__header">
      <h2 class="section-heading">{{ section.settings.heading }}</h2>
      {%- if section.settings.collection != blank -%}
        <a href="{{ section.settings.collection.url }}" class="section-link">View All &rarr;</a>
      {%- endif -%}
    </div>

    <div class="pack-favorites__grid">
      {%- if section.settings.collection != blank -%}
        {%- for product in section.settings.collection.products limit: section.settings.products_to_show -%}
          <div class="pack-favorites__card" data-reveal style="--index: {{ forloop.index }}">
            <a href="{{ product.url }}" class="pack-favorites__link" aria-label="{{ product.title }}">
              <div class="pack-favorites__media">
                {%- if product.featured_image != blank -%}
                  <img src="{{ product.featured_image | image_url: width: 600 }}" srcset="{{ product.featured_image | image_url: width: 300 }} 300w, {{ product.featured_image | image_url: width: 450 }} 450w, {{ product.featured_image | image_url: width: 600 }} 600w" sizes="(max-width: 768px) 50vw, 25vw" alt="{{ product.featured_image.alt | escape }}" loading="lazy" class="pack-favorites__image">
                {%- else -%}
                  <div class="pack-favorites__placeholder">
                    <svg viewBox="0 0 400 400" fill="none" stroke="currentColor" stroke-width="1" opacity="0.12" aria-hidden="true"><rect x="40" y="40" width="320" height="320" rx="16"/><circle cx="200" cy="180" r="50"/></svg>
                  </div>
                {%- endif -%}
              </div>
              <div class="pack-favorites__info">
                <h3 class="pack-favorites__title">{{ product.title }}</h3>
                <span class="pack-favorites__price">{{ product.price | money }}</span>
              </div>
            </a>
          </div>
        {%- endfor -%}
      {%- else -%}
        {%- assign placeholder_names = 'Organic Bison Jerky Treats,All-Weather Adventure Harness,Calming Hemp Chews,Mountain Trail Leash' | split: ',' -%}
        {%- assign placeholder_prices = '$24.00,$58.00,$32.00,$45.00' | split: ',' -%}
        {%- for i in (1..4) -%}
          {%- assign idx = forloop.index0 -%}
          {%- assign product_img = 'product-' | append: forloop.index | append: '.png' -%}
          <div class="pack-favorites__card" data-reveal style="--index: {{ forloop.index }}">
            <div class="pack-favorites__link">
              <div class="pack-favorites__media">
                <img src="{{ product_img | asset_url }}" alt="{{ placeholder_names[idx] }}" loading="lazy" class="pack-favorites__image" onerror="this.style.display='none';this.nextElementSibling.style.display='';">
                <div class="pack-favorites__placeholder" style="display:none;">
                  <svg viewBox="0 0 400 400" fill="none" stroke="currentColor" stroke-width="1" opacity="0.12" aria-hidden="true"><rect x="40" y="40" width="320" height="320" rx="16"/><circle cx="200" cy="180" r="50"/></svg>
                </div>
              </div>
              <div class="pack-favorites__info">
                <h3 class="pack-favorites__title">{{ placeholder_names[idx] }}</h3>
                <span class="pack-favorites__price">{{ placeholder_prices[idx] }}</span>
              </div>
            </div>
          </div>
        {%- endfor -%}
      {%- endif -%}
    </div>
  </div>
</section>

{% schema %}
{
  "name": "Pack Favorites",
  "class": "section-pack-favorites",
  "settings": [
    { "type": "text", "id": "eyebrow", "label": "Eyebrow", "default": "THE PACK'S PICKS" },
    { "type": "text", "id": "heading", "label": "Heading", "default": "Favorites of the Pack" },
    { "type": "collection", "id": "collection", "label": "Collection" },
    { "type": "range", "id": "products_to_show", "label": "Products to show", "min": 2, "max": 8, "step": 1, "default": 4 }
  ],
  "presets": [{ "name": "Pack Favorites" }]
}
{% endschema %}