{% import '@protons/macros/status.macros.twig' as status_macros %}

{% set attributes = attr|default(create_attribute()) %}
{% set status = status|default('none') %}
{% set display = display|default('flex') %}
{% set class = class|default('') %}
{% set icon_left = icon_left ? icon_left : null %}
{% set icon_right = icon_right ? icon_right : null %}
{% set icon_right_hidden = icon_right_hidden ? icon_right_hidden : null %}
{% set icon_stack_fa = icon_stack_fa|default(false) %}
{% set toggle_open = toggle_open|default(false) %}
{% set is_collapse = is_collapse|default(false) %}

{# Icon mapping, for when we just want to pass 'toggle=sign' for collapse triggers. #}
{% set toggles = [
  {
    'toggle':'sign',
    'icon_right': global_icon_plus|default('fas fa-plus'),
    'icon_right_hidden': global_icon_minus|default('fas fa-minus')
  },
  {
    'toggle':'chevron',
    'icon_right': global_icon_down|default('fas fa-chevron-down'),
    'icon_right_hidden': global_icon_up|default('fas fa-chevron-up')
  },
  {
    'toggle':'chevron_close',
    'icon_right': global_icon_down|default('fas fa-chevron-down'),
    'icon_right_hidden': global_icon_times_circle|default('fas fa-times-circle')
  },
  {
    'toggle':'chevron_right',
    'icon_right': global_icon_right|default('fas fa-chevron-right'),
    'icon_right_hidden': global_icon_right|default('fas fa-chevron-right')
  }
] %}

{% for item in toggles %}
  {% if toggle == item.toggle %}
    {% set icon_right = item.icon_right %}
    {% set icon_right_hidden = item.icon_right_hidden %}
    {% set class = [
      class,
      toggle_open ? '' : 'collapsed',
      'toggle',
    ]|join(' ') %}
  {% endif %}
{% endfor %}

{# URL settings, make <span> if not link. #}
{% set tag_name = tag_name|default('span') %}
{% if url %}
  {% set attributes = attributes.setAttribute('href', url) %}
  {% set tag_name = 'a' %}
{% endif %}

{# Set level/display of flex item. #}
{% if display != 'flex' %}
  {% set class = ['bel' ~ display, class]|join(' ') %}
{% endif %}

{% set class = ['bel', class]|join(' ') %}

{% set content %}
  <span class="bell {% if tgl_text is not empty %}tgl-opn{% endif %}">
    {{ text|raw }}
  </span>

  {% if tgl_text is not empty %}
    <span class="bell tgl-cls">
      {{ tgl_text|raw }}
    </span>
  {% endif %}

  {% if icon_right is not empty %}<i class="{{ icon_right }} beli belir"></i>{% endif %}
  {% if icon_right_hidden is not empty %}<i class="{{ icon_right_hidden }} beli belir belih"></i>{% endif %}
{% endset %}

{# Template #}
{{ status_macros.status(status, icon_left, tag_name, class, attributes, 'beli belil', content, icon_stack_fa) }}
