{%- if section.blocks.size > 0 or section.settings.text != blank -%}
<div class="announcement-bar" data-bar-style="{{ section.settings.bar_style | default: 'solid' }}" role="region" aria-label="{{ 'accessibility.announcement_bar' | t }}">
  <div class="container">
    <div class="announcement-bar__carousel">
      {%- if section.blocks.size > 0 -%}
        <button class="announcement-bar__arrow announcement-bar__prev" aria-label="{{ 'accessibility.previous' | t }}" type="button">
          <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><polyline points="15 18 9 12 15 6"/></svg>
        </button>
        <div class="announcement-bar__slides">
          {%- for block in section.blocks -%}
            <p class="announcement-bar__slide{% if forloop.first %} is-active{% endif %}" {{ block.shopify_attributes }}>
              {%- if block.settings.link != blank -%}
                <a href="{{ block.settings.link }}">{{ block.settings.text }}</a>
              {%- else -%}
                {{ block.settings.text }}
              {%- endif -%}
            </p>
          {%- endfor -%}
        </div>
        <button class="announcement-bar__arrow announcement-bar__next" aria-label="{{ 'accessibility.next' | t }}" type="button">
          <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><polyline points="9 18 15 12 9 6"/></svg>
        </button>
      {%- elsif section.settings.text != blank -%}
        <p class="announcement-bar__slide is-active">
          {%- if section.settings.link != blank -%}
            <a href="{{ section.settings.link }}">{{ section.settings.text }}</a>
          {%- else -%}
            {{ section.settings.text }}
          {%- endif -%}
        </p>
      {%- endif -%}
    </div>
    <button class="announcement-bar__close" aria-label="{{ 'accessibility.dismiss' | t }}" type="button">
      <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
        <line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/>
      </svg>
    </button>
  </div>
</div>
{%- endif -%}

{% schema %}
{
  "name": "Announcement bar",
  "class": "section-announcement-bar",
  "settings": [
    {
      "type": "select",
      "id": "bar_style",
      "label": "Bar style",
      "options": [
        {
          "value": "solid",
          "label": "Solid dark"
        },
        {
          "value": "brand",
          "label": "Brand color"
        },
        {
          "value": "minimal",
          "label": "Minimal"
        },
        {
          "value": "accent",
          "label": "Accent stripe"
        }
      ],
      "default": "accent"
    },
    {
      "type": "text",
      "id": "text",
      "label": "Announcement text (single message fallback)",
      "default": "Free shipping on orders over $50"
    },
    {
      "type": "text",
      "id": "link",
      "label": "Link URL (optional)",
      "info": "Used when no blocks are added"
    },
    {
      "type": "range",
      "id": "rotate_speed",
      "label": "Auto-rotate speed (seconds)",
      "min": 3,
      "max": 10,
      "step": 1,
      "default": 5
    }
  ],
  "blocks": [
    {
      "type": "message",
      "name": "Message",
      "settings": [
        {
          "type": "text",
          "id": "text",
          "label": "Message text",
          "default": "Free shipping on orders over $50"
        },
        {
          "type": "text",
          "id": "link",
          "label": "Link URL (optional)",
          "info": "e.g. /collections/sale"
        }
      ]
    }
  ],
  "presets": [
    {
      "name": "Announcement bar",
      "blocks": [
        {
          "type": "message",
          "settings": {
            "text": "Free shipping on orders over $50"
          }
        },
        {
          "type": "message",
          "settings": {
            "text": "Now shipping bare-root plants for spring"
          }
        }
      ]
    }
  ]
}
{% endschema %}