{# LIBRARIES #}
{{ attach_library('ui_patterns/libraries.bs_modal') }}
{{ attach_library('ui_patterns/libraries.bs_buttons') }}
{{ attach_library('ui_patterns/tm_modal.tm_modal_lib') }}

{% set modal_wrapper_attributes = attributes|default(create_attribute()) %}
{% set modal_content_attributes = content_attributes|default(create_attribute()) %}

{# TEMPLATE #}
<!-- Modal trigger -->
{% block trigger %}
  {% if showbutton == true %}
    <button type="button"
            class="btn btn-primary"
            data-bs-toggle="modal"
            data-bs-target="#{{ uid }}">
      Launch modal "#{{ uid }}"
    </button>
  {% endif %}
{% endblock %}
<!-- / Modal trigger -->

<!-- Modal -->
<div class="modal fade {{ class }}"
     id="{{ uid }}"
     tabindex="-1"
     role="dialog"
     aria-labelledby="title-{{ uid }}"
     aria-hidden="true"
  {{ modal_wrapper_attributes }}
>
  {% block modal_pre %}{% endblock %}
  <div class="modal-dialog modal-{{ size }} {{ center ? 'modal-dialog-centered' }}" role="document">
    <div class="modal-content {{ content_class }}" {{ modal_content_attributes }}>

      <!-- Header -->
      {% block header %}
      <div class="modal-header">

        {% if title %}
        <{{ title_tag }} class="modal-title" id="title-{{ uid }}">
        {{ title|raw }}
      </{{ title_tag }}>
      {% endif %}

      {% if header_extra %}{{ header_extra|raw }}{% endif %}

      {% if showclose %}
        <button
          class="modal-close m-0 p-0"
          data-bs-dismiss="modal"
          aria-label="Close"
        >
          <i class="fas fa-times-circle"></i>
        </button>
      {% endif %}
    </div>
    {% endblock %}

    <!-- Body -->
    {% block body %}
      <div class="modal-body">
        {{ body }}
      </div>
    {% endblock %}

    <!-- Footer -->
    {% block footer %}
      <div class="modal-footer">
        {{ footer }}
      </div>
    {% endblock %}

  </div>
</div>

{% block modal_post %}{% endblock %}
</div>
<!-- / Modal -->
