{% macro flash_messages(messages) %}
  {% if messages %}
    <div class="flash-messages-box">
      {% for m in messages %}
        <div class="alert alert-{{ m.color or category_to_alert(m[0]) }} alert-dismissible {{ m.message_class }}">
          <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
          <h5><i class="icon {{ m.icon or category_to_icon(m[0]) }}"></i> {{ m.title or category_to_title(m[0]) }}</h5>
          {{ m.text or m[1]}}
        </div>
      {% endfor %}
    </div>
  {% endif %}
{% endmacro %}

{% macro category_to_alert(category) %}
{%-if category == 'error'  -%}danger
{%-elif category == 'warning' -%}warning
{%-elif category == 'info' -%}info
{%-elif category == 'success' -%}success
{%-else-%}info
{%-endif-%}
{% endmacro %}

{% macro category_to_icon(category) %}
{%-if category == 'error'  -%}fas fa-ban
{%-elif category == 'warning' -%}fas fa-exclamation-triangle
{%-elif category == 'info' -%}fas fa-info
{%-elif category == 'success' -%}icon fas fa-check
{%-else-%}info
{%-endif-%}
{% endmacro %}

{% macro category_to_title(category) %}{{category|title}}{% endmacro %}