<section class="gear-grid" data-reveal>
  <div class="container">
    {%- if section.settings.eyebrow != blank -%}
      <span class="section-eyebrow">{{ section.settings.eyebrow }}</span>
    {%- endif -%}
    {%- if section.settings.heading != blank -%}
      <h2 class="section-heading">{{ section.settings.heading }}</h2>
    {%- endif -%}

    <div class="gear-grid__masonry">
      {%- if section.settings.collection != blank -%}
        {%- for product in section.settings.collection.products limit: section.settings.products_to_show -%}
          <div class="gear-grid__card{% if forloop.index == 1 or forloop.index == 4 %} gear-grid__card--tall{% endif %}" data-reveal style="--index: {{ forloop.index }}">
            <a href="{{ product.url }}" class="gear-grid__link" aria-label="{{ product.title }}">
              <div class="gear-grid__media">
                {%- if product.featured_image != blank -%}
                  <img src="{{ product.featured_image | image_url: width: 800 }}" srcset="{{ product.featured_image | image_url: width: 400 }} 400w, {{ product.featured_image | image_url: width: 600 }} 600w, {{ product.featured_image | image_url: width: 800 }} 800w" sizes="(max-width: 768px) 100vw, 33vw" alt="{{ product.featured_image.alt | escape }}" loading="lazy" class="gear-grid__image">
                {%- else -%}
                  {%- assign product_img = 'product-' | append: forloop.index | append: '.png' -%}
                  <img src="{{ product_img | asset_url }}" alt="{{ product.title }}" loading="lazy" class="gear-grid__image" onerror="this.style.display='none';this.nextElementSibling.style.display='flex';">
                  <div class="gear-grid__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="8"/><circle cx="200" cy="200" r="50"/></svg>
                  </div>
                {%- endif -%}
              </div>
              <div class="gear-grid__info">
                <h3 class="gear-grid__title">{{ product.title }}</h3>
                <span class="gear-grid__price">{{ product.price | money }}</span>
              </div>
            </a>
          </div>
        {%- endfor -%}
      {%- else -%}
        {%- assign placeholder_names = 'Studio Monitor Pro,Reference Headphone X1,DAC-1 Desktop Converter,Balanced Preamp MK3,Phono Stage R2,USB Audio Bridge' | split: ',' -%}
        {%- assign placeholder_prices = '$449,$349,$299,$279,$199,$129' | split: ',' -%}
        {%- for i in (1..6) -%}
          {%- assign idx = forloop.index0 -%}
          {%- assign product_img = 'product-' | append: forloop.index | append: '.png' -%}
          <div class="gear-grid__card{% if forloop.index == 1 or forloop.index == 4 %} gear-grid__card--tall{% endif %}" data-reveal style="--index: {{ forloop.index }}">
            <div class="gear-grid__link">
              <div class="gear-grid__media">
                <img src="{{ product_img | asset_url }}" alt="{{ placeholder_names[idx] }}" loading="lazy" class="gear-grid__image" onerror="this.style.display='none';this.nextElementSibling.style.display='flex';">
                <div class="gear-grid__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="8"/><circle cx="200" cy="200" r="50"/></svg>
                </div>
              </div>
              <div class="gear-grid__info">
                <h3 class="gear-grid__title">{{ placeholder_names[idx] }}</h3>
                <span class="gear-grid__price">{{ placeholder_prices[idx] }}</span>
              </div>
            </div>
          </div>
        {%- endfor -%}
      {%- endif -%}
    </div>
  </div>
</section>

{% schema %}
{
  "name": "Gear Grid",
  "class": "section-gear-grid",
  "settings": [
    { "type": "text", "id": "eyebrow", "label": "Eyebrow" },
    { "type": "text", "id": "heading", "label": "Heading", "default": "Our Gear" },
    { "type": "collection", "id": "collection", "label": "Collection" },
    { "type": "range", "id": "products_to_show", "label": "Products to show", "min": 3, "max": 9, "step": 1, "default": 6 }
  ],
  "presets": [{ "name": "Gear Grid" }]
}
{% endschema %}