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

    <div class="roast-menu__grid">
      {%- if section.settings.collection != blank -%}
        {%- for product in section.settings.collection.products limit: section.settings.products_to_show -%}
          <div class="roast-menu__card" data-reveal style="--index: {{ forloop.index }}">
            <a href="{{ product.url }}" class="roast-menu__link" aria-label="{{ product.title }}">
              <div class="roast-menu__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="roast-menu__image">
                {%- else -%}
                  {%- assign product_img = 'product-' | append: forloop.index | append: '.png' -%}
                  <img src="{{ product_img | asset_url }}" alt="{{ product.title }}" loading="lazy" class="roast-menu__image" onerror="this.style.display='none';this.nextElementSibling.style.display='flex';">
                  <div class="roast-menu__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="roast-menu__info">
                <h3 class="roast-menu__title">{{ product.title }}</h3>
                <span class="roast-menu__price">{{ product.price | money }}</span>
              </div>
            </a>
          </div>
        {%- endfor -%}
      {%- else -%}
        {%- assign placeholder_names = 'Ethiopian Yirgacheffe Single Origin,Matcha Ceremonial Grade,Colombian Huila Dark Roast,Jasmine Dragon Pearl Tea' | split: ',' -%}
        {%- assign placeholder_prices = '$22,$34,$19,$28' | split: ',' -%}
        {%- for i in (1..4) -%}
          {%- assign idx = forloop.index0 -%}
          {%- assign product_img = 'product-' | append: forloop.index | append: '.png' -%}
          <div class="roast-menu__card" data-reveal style="--index: {{ forloop.index }}">
            <div class="roast-menu__link">
              <div class="roast-menu__media">
                <img src="{{ product_img | asset_url }}" alt="{{ placeholder_names[idx] }}" loading="lazy" class="roast-menu__image" onerror="this.style.display='none';this.nextElementSibling.style.display='flex';">
                <div class="roast-menu__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="roast-menu__info">
                <h3 class="roast-menu__title">{{ placeholder_names[idx] }}</h3>
                <span class="roast-menu__price">{{ placeholder_prices[idx] }}</span>
              </div>
            </div>
          </div>
        {%- endfor -%}
      {%- endif -%}
    </div>
  </div>
</section>

{% schema %}
{
  "name": "Roast Menu",
  "class": "section-roast-menu",
  "settings": [
    { "type": "text", "id": "eyebrow", "label": "Eyebrow" },
    { "type": "text", "id": "heading", "label": "Heading", "default": "What We're Roasting" },
    { "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": "Roast Menu" }]
}
{% endschema %}