{% set attributes = attr|default(create_attribute()) %}
{% set status = status|default('none') %}
{% 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 toggle_open = toggle_open|default(false) %}

{#  Icon mapping, for when we just want to pass 'status=minor'. #}
{% set statuses = [
  {'status':'good', 'icon_left': 'fas fa-check-circle', 'icon_right': null},
  {'status':'minor', 'icon_left': 'fas fa-exclamation-circle', 'icon_right': null},
  {'status':'major', 'icon_left': 'fas fa-exclamation-triangle', 'icon_right': null},
  {'status':'stationalert', 'icon_left': 'fas fa-info-circle', 'icon_right': null},
  {'status':'noservice', 'icon_left': 'fas fa-exclamation-circle', 'icon_right': null},
  {'status':'amended', 'icon_left': 'fas fa-exclamation-circle', 'icon_right': null},
  {'status':'strike', 'icon_left': 'fas fa-exclamation-circle', 'icon_right': null},
] %}
{% for item in statuses %}
  {% if status == item.status %}
    {% set icon_left = icon_left ? icon_left : item.icon_left %}
    {% set icon_right = icon_right ? icon_right : item.icon_right %}
    {% set class = [status, class]|join(' ') %}
  {% endif %}
{% endfor %}

{# Icon mapping, for when we just want to pass 'toggle=sign' for collapse triggers. #}
{% set toggles = [
  {'toggle':'sign', 'icon_right': 'fas fa-plus', 'icon_right_hidden': 'fas fa-minus'},
  {'toggle':'chevron', 'icon_right': 'fas fa-chevron-down', 'icon_right_hidden': 'fas fa-chevron-up'},
  {'toggle':'chevron_right', 'icon_right': 'fas fa-chevron-right', 'icon_right_hidden': '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 == 'inline' %}
  {% set class = ['belinline', class]|join(' ') %}
{% endif %}

{# Template #}
<{{ tag_name }} {{ attributes }} class="bel {{ class }}">
{% if icon_left is not empty %}<i class="{{ icon_left }} beli belil"></i>{% endif %}
<span class="bell">{{ text|raw }}</span>
{% 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 %}
</{{ tag_name }}>
