{#
/**
* @file
* accordion-item
*
* See accordion-item.wingsuit.yaml for documentation.
*/
#}
{% set level = level|default("block") %}
{% set tag_name = tag_name|default("span") %}
{% set active = active|default(false) %}

{% set link_attributes = link_attributes|default(create_attribute()) %}
{% set link_attributes = link_attributes
  .setAttribute("data-bs-toggle", "collapse")
  .setAttribute('tabindex', '0')
  .setAttribute("data-bs-target", "#aci-#{ aiid }")
  .setAttribute("aria-expanded", "false")
  .setAttribute("id", "act-#{ aiid }")
%}

{% set toggle = toggle|default("") %}
{% set link_class = link_class|default("") %}
{% set link_class = [
  link_class,
  (not active and not toggle) ? 'collapsed',
  "belirf",
  toggle == 'chevron' ? "belian",
  toggle == 'sign' ? "beliag",
  level == 'inline' ? 'belinline',
] %}

{% set content_attributes = content_attributes|default(create_attribute()) %}
{% set content_attributes = content_attributes
  .setAttribute("aria-labelledby", "act-#{ aiid }")
  .setAttribute("id", "aci-#{ aiid }")
%}
{% set content_class = content_class|default("") %}

{# TEMPLATE #}
{% include "@atoms/tm-links/icon-bookended/icon-bookended.twig" with {
  "text": label,
  "class": link_class | join(' ') | trim,
  "toggle": toggle,
  "attr": link_attributes,
  "tag_name": tag_name,
  "toggle_open": active,
} only %}

{% set content_classes = [
  content_classes,
  'collapse',
  active ? 'show',
] %}

<div {{ content_attributes.addClass(content_classes) }}" >
  <div class="{{ content_class }}">
    {% if show_close %}
      <a href="#"
         class="aci-close"
         type="button"
         data-bs-toggle="collapse"
         data-bs-target="#aci-{{ aiid }}"
      >
        <i class="{{ global_icon_times|default('fas fa-times') ~ "-circle" }}"></i>
      </a>
    {% endif %}
    {{ content|raw }}
  </div>
</div>
