{# 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('') %}
{% set without_headers = without_headers|default(false) %}
{% set layout = layout|default(standard) %}
{% set icon_set = icon_set|default('solid') %}
{% set custom_colours = custom_colours|default(false) %}

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

  {% embed '@molecules/tm-message/alert/alert.twig' with {
    'status': status_mapping[type],
    'header': without_headers ? '' : status_heading[type],
    'messages': messages,
    'header_tag': header_tag,
    'header_class': header_class,
    'alert_class': alert_class,
    'icon_set': icon_set,
    'layout': layout,
    'custom_colours': custom_colours
  } 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 %}
