{#
/**
 * Displays status, error, and warning messages, grouped by type.
 *
 * An invisible heading identifies the messages for assistive technology.
 * Sighted users see a colored box. See http://www.w3.org/TR/WCAG-TECHS/H69.html
 * for info.
 *
 * Add an ARIA label to the contentinfo area so that assistive technology
 * user agents will better describe this landmark.
 *
 * Available variables:
 * - message_list: List of messages to be displayed, grouped by type.
 * - status_headings: List of all status types.
 * - display: (optional) May have a value of 'status' or 'error' when only
 *   displaying messages of that specific type.
 * - attributes: HTML attributes for the element, including:
 * - class: HTML classes.
 */
#}

{{ attach_library('rocketship_theme_starter/component_status') }}

{% block messages %}
  <div class='messages--wrapper'>
    {% for type, messages in message_list %}
      {% set classes = [
        'messages',
        'messages--drupal',
        'messages--' ~ type,
      ] %}
      {% set role = type == 'error' ? 'alert' : 'status' %}
      <div role="{{ role }}"
        aria-label='{{ status_headings[type] }}'
        aria-live="polite"
        aria-atomic="true"
        {{ attributes.addClass(classes) }}
      >
        {% if status_headings[type] %}
          <h2 class='visually-hidden'>{{ status_headings[type] }}</h2>
        {% endif %}
        {% if messages is iterable %}
          {% if messages|length > 1 %}
            <ul class='messages__list messages__list--drupal'>
              {% for key, message in messages %}
                <li class='message message--{{ type }} message--drupal'>
                  {{ message }}
                  {% if key < 1 %}
                    <button type="button" class='message__close message__close--drupal js-close'>
                      <i class='icon icon-close'></i>
                      <span class="visually-hidden">{{ 'Close'|t }}</span>
                    </button>
                  {% endif %}
                </li>
              {% endfor %}
            </ul>
          {% elseif messages|length == 1 %}
            {% for key, message in messages %}
              <div class='message message--{{ type }} message--drupal'>
                {{ message }}
                <button type="button" class='message__close message__close--drupal js-close'>
                  <i class='icon icon-close'></i>
                  <span class="visually-hidden">{{ 'Close'|t }}</span>
                </button>
              </div>
            {% endfor %}
          {% endif %}
        {% endif %}
      </div>
      {% set attributes = attributes.removeClass(classes) %}
    {% endfor %}
  </div>
{% endblock messages %}

