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

    <div class="atelier-showcase__grid">
      {%- if section.settings.collection != blank -%}
        {%- for product in section.settings.collection.products limit: section.settings.products_to_show -%}
          <div class="atelier-showcase__item{% if forloop.first %} atelier-showcase__item--hero{% endif %}" data-reveal style="--index: {{ forloop.index }}">
            <a href="{{ product.url }}" class="atelier-showcase__link" aria-label="{{ product.title }}">
              <div class="atelier-showcase__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="{% if forloop.first %}(max-width: 768px) 100vw, 55vw{% else %}(max-width: 768px) 50vw, 25vw{% endif %}" alt="{{ product.featured_image.alt | escape }}" loading="lazy" class="atelier-showcase__image">
                {%- else -%}
                  <div class="atelier-showcase__placeholder">
                    <svg viewBox="0 0 400 500" fill="none" stroke="currentColor" stroke-width="1" opacity="0.12" aria-hidden="true"><rect x="40" y="40" width="320" height="420" rx="16"/><circle cx="200" cy="200" r="60"/></svg>
                  </div>
                {%- endif -%}
              </div>
              <div class="atelier-showcase__info">
                <h3 class="atelier-showcase__title">{{ product.title }}</h3>
                <span class="atelier-showcase__price">{{ product.price | money }}</span>
              </div>
            </a>
          </div>
        {%- endfor -%}
      {%- else -%}
        {%- assign placeholder_names = 'Heirloom Signet Ring,Silk Thread Bracelet,River Pearl Studs,Column Pendant' | split: ',' -%}
        {%- assign placeholder_prices = '£385,£195,£245,£310' | split: ',' -%}
        {%- for i in (1..4) -%}
          {%- assign idx = forloop.index0 -%}
          {%- assign product_img = 'product-' | append: forloop.index | append: '.png' -%}
          <div class="atelier-showcase__item{% if forloop.first %} atelier-showcase__item--hero{% endif %}" data-reveal style="--index: {{ forloop.index }}">
            <div class="atelier-showcase__link">
              <div class="atelier-showcase__media">
                <img src="{{ product_img | asset_url }}" alt="{{ placeholder_names[idx] }}" loading="lazy" class="atelier-showcase__image" onerror="this.style.display='none';this.nextElementSibling.style.display='';">
                <div class="atelier-showcase__placeholder" style="display:none;">
                  <svg viewBox="0 0 400 500" fill="none" stroke="currentColor" stroke-width="1" opacity="0.12" aria-hidden="true"><rect x="40" y="40" width="320" height="420" rx="16"/><circle cx="200" cy="200" r="60"/></svg>
                </div>
              </div>
              <div class="atelier-showcase__info">
                <h3 class="atelier-showcase__title">{{ placeholder_names[idx] }}</h3>
                <span class="atelier-showcase__price">{{ placeholder_prices[idx] }}</span>
              </div>
            </div>
          </div>
        {%- endfor -%}
      {%- endif -%}
    </div>
  </div>
</section>

{% schema %}
{
  "name": "Atelier Showcase",
  "class": "section-atelier-showcase",
  "settings": [
    { "type": "text", "id": "eyebrow", "label": "Eyebrow", "default": "THE COLLECTION" },
    { "type": "text", "id": "heading", "label": "Heading", "default": "Current Pieces" },
    { "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": "Atelier Showcase" }]
}
{% endschema %}