{#
/**
 * @file
 * Vartheme BS5 Starter Kit implementation for the Alert component.
 *
 * Available properties:
 * - type: Bootstrap includes several predefined alert type styles.
 *         (alert-primary|alert-secondary|alert-success|alert-info|
 *          alert-warning|alert-danger|alert-light|alert-dark)
 * - dismissible: It is possible to dismiss any alert inline, When an alert is dismissed, the element is completely removed from the page structure.
 * - alert_utility_classes: An array of utility classes. Use to add extra Bootstrap utility classes or custom CSS classes over to this component.
 *
 * Available attributes:
 * - attributes: HTML attributes for the alert element.
 * - dismissible_attributes: HTML attributes for the alert dismiss close button element.
 *
 * Available slots:
 * - content: The content of the alert.
 * - heading: Alerts can also contain primary alert heading.
 */
#}
{% set type_classes = type ? [type] : [] %}
{% set dismissible = dismissible ?? true %}
{% set dismissible_classes = dismissible ? ['alert-dismissible', 'fade', 'show'] : [] %}
{% set alert_utility_classes = alert_utility_classes ? alert_utility_classes : [] %}

{% set classes = [
  'alert',
]|merge(type_classes)|merge(dismissible_classes)|merge(alert_utility_classes) %}

{% if not attributes %}
  {% set attributes = create_attribute() %}
{% endif %}
{% set attributes = attributes.addClass(classes) %}
{% set attributes = attributes.setAttribute('role', 'alert') %}

<div{{ attributes }}>
  {% if heading|render|striptags|trim is not empty %}
    {% include "vartheme_bs5:heading" with {
      html_tag: 'h4',
      content: heading|render|striptags|trim,
      alert_utility_classes: ['alert-heading']
    } only %}
  {% endif %}

  {% block content %}
    {{ content }}
  {% endblock %}

  {% if dismissible %}
    {% if not dismissible_attributes %}
      {% set dismissible_attributes = create_attribute() %}
    {% endif %}
    {% set dismissible_attributes = dismissible_attributes.setAttribute('data-bs-dismiss', 'alert') %}
    {{ include ('vartheme_bs5:close-button', {
        size: 'btn-sm',
        attributes: dismissible_attributes
      }, with_context: false) }}
  {% endif %}
</div>
