{# LIBRARIES #}
{{ attach_library('ui_patterns/libraries.bs_accordion') }}
{{ attach_library('ui_patterns/bs-accordion.accordion') }}

{# VARIABLES #}
{% import '@organisms/tm-bs/accordion/accordion.macros.twig' as accordion_macros %}
{% set style = style|default("combined") %}
{% set show_close = show_close|default(false) %}
{% set open_first = open_first|default(false) %}
{% set scroll_to = scroll_to|default(false) %}
{% set absolute = absolute|default(false) %}
{% set wrapper_attributes = wrapper_attributes|default(create_attribute()) %}
{% set wrapper_attributes = wrapper_attributes
  .setAttribute("id", "ac-#{ pid }")
%}
{% set wrapper_class = [wrapper_class|default(""), "accordion"] %}
{% set child_variant = child_variant|default('__default') %}

{# TEMPLATE #}
<div {{ wrapper_attributes.addClass(wrapper_class) }}>

  {% if style == "combined" %}

    {% for item in items %}
      {% if loop.first and open_first %}
        {% set item = item|merge({'active': true}) %}
      {% endif %}
      {% if list_prefix %}<div class="acpf">{{ list_prefix|raw }}</div>{% endif %}
        {{ accordion_macros.makeItem("both", child_variant, item, pid, toggle, child_content_class, child_content_attributes, child_link_class, child_link_attributes, show_close, scroll_to) }}
      {% if list_suffix %}<div class="acsf">{{ list_suffix|raw }}</div>{% endif %}
    {% endfor %}

  {% elseif style == "separated" %}

    {% if absolute %}<div class="acnw">{% endif %}
      {% if list_prefix %}<div class="acpf">{{ list_prefix|raw }}</div>{% endif %}
      {% for item in items %}
        {% if loop.first and open_first %}
          {% set item = item|merge({'active': true}) %}
        {% endif %}
        {{ accordion_macros.makeItem("link", child_variant, item, pid, toggle, child_content_class, child_content_attributes, child_link_class, child_link_attributes, show_close, scroll_to) }}
      {% endfor %}
      {% if list_suffix %}<div class="acsf">{{ list_suffix|raw }}</div>{% endif %}
    {% if absolute %}</div>{% endif %}

    {% if absolute %}<div class="accw">{% endif %}
      {% for item in items %}
        {% if loop.first and open_first %}
          {% set item = item|merge({'active': true}) %}
        {% endif %}
        {{ accordion_macros.makeItem("content", child_variant, item, pid, toggle, child_content_class, child_content_attributes, child_link_class, child_link_attributes, show_close, scroll_to) }}
      {% endfor %}
    {% if absolute %}</div>{% endif %}

  {% endif %}

</div>
