{# LIBRARIES #}
{{ attach_library('ui_patterns/libraries.bs_alert') }}
{{ attach_library('ui_patterns/alerts.alerts_lib') }}

{# VARIABLES #}
{% set status_heading = status_headings|default({
  'default': 'Default'|t,
  'status': 'Status'|t,
  'error': 'Error'|t,
  'warning': 'Warning'|t,
  'info': 'Information'|t,
}) %}
{% set status_mapping = {
  'default': 'default',
  'status': 'success',
  'error': 'danger',
  'warning': 'warning',
  'info': 'info',
} %}
{% set messages_attributes = attributes %}
{% set header_tag = header_tag|default('h2') %}
{% set header_class = header_class|default('h3') %}
{% set alert_class = alert_class|default('') %}

{# TEMPLATE #}
{% for type, messages in message_list %}

  {% embed '@molecules/tm-message/alert/alert.twig' with {
    'status': status_mapping[type],
    'header': status_heading[type],
    'messages': messages,
    'header_tag': header_tag,
    'header_class': header_class,
    'alert_class': alert_class,
  } only %}

    {% block content %}
      {% if messages|length > 1 %}
        <ul class="ulp">
          {% for message in messages %}
            <li>{{- message -}}</li>
          {% endfor %}
        </ul>
      {% else %}
        <ul class="uln ulp">
          <li class="lin">{{- messages|first -}}</li>
        </ul>
      {% endif %}
    {% endblock content %}

  {% endembed %}

{% endfor %}
