{# LIBRARIES #}
{{ attach_library('ui_patterns/sa_list.sa_list_lib') }}

{# VARIABLES #}
{% set title = title|default('<i class="far fa-exclamation-circle"></i> Important travel updates') %}
{% set link_icon_right = link_icon_right|default(global_icon_right|default('fas fa-chevron-right')) %}
{% set full_info = full_info|default(false) %}
{% set attributes = attributes|default(create_attribute()) %}
{% set count = links|length %}
{% set expandable = expandable|default(false) %}
{% set horizontal = horizontal|default(false) %}
{% set collapse_label_option = collapse_label_option|default('standard') %}
{% set footer_links = (footer_links is defined) ? footer_links : true %}
{% set collapse_labels = {
  'standard': {
    'label': 'View all <span class="count">' ~ count ~ '</span>',
    'hide_label': '<i class="far fa-times-circle"></i>',
  },
  'with-plus-minus': {
    'label': 'View all ' ~ count ~ ' <i class="far fa-plus"></i>',
    'hide_label': 'Hide <i class="far fa-minus"></i>',
  },
} %}
{% if collapse_labels[collapse_label_option] is not defined %}
  {% set collapse_label_option = 'standard' %}
{% endif %}
{% set classes = [
  'sa-list',
  expandable ? 'expandable' : '',
  horizontal ? 'horizontal' : '',
  collapse_label_option,
] %}


{% if links and links is iterable %}

  {% set prefix_content %}
  <div id="announcement-list-initial">
    {% include "@atoms/tm-links/icon-bookended/icon-bookended.twig" with {
      "text": links[0]['text'],
      "url": links[0]['url'],
      "icon_right": link_icon_right,
      "display": "noflex",
    } only %}
    <i class='fas fa-chevron-right beli belir'></i>
  </div>
  {% endset %}

  {% set collapse_content %}
  <div id="announcement-list">
    {% for link in links %}
      {% if full_info %}
        {% include "@molecules/tm-lb/link-block/link-block.twig" with {
          "title": link['text'],
          "subtitle": link['intro'],
          "body": link['extra'],
          "block_link": link['url'],
          "icon_right": link_icon_right,
          "header_tag": 'h3',
          "subtitle_tag": 'h4',
          "title_display": 'flex',
          "subtitle_display": 'noflex',
          "block_class": 'bl-vm cbelianr announcement-block'
        } only %}
      {% else %}
        {% include "@atoms/tm-links/icon-bookended/icon-bookended.twig" with {
          "text": link['text'],
          "url": link['url'],
          "icon_right": link_icon_right,
          "display": "noflex",
          "class": 'belianr',
        } only %}
      {% endif %}
    {% endfor %}
    {% if footer_links %}
      <div class="sa-footer">
        {{ footer }}
      </div>
    {% endif %}
  </div>
  {% endset %}

{% endif %}


{# TEMPLATE #}
{% if links and links is iterable %}
  <div {{ attributes.addClass(classes) }}>
    <h2 class="sa-abv-title">{{ title }}</h2>
    {% if expandable %}
      {% include '@molecules/tm-bs/collapse/collapse.twig' with {
        'content_first': true,
        'content': collapse_content,
        'prefix': prefix_content,
        'label': collapse_labels[collapse_label_option].label,
        'hide_label': collapse_labels[collapse_label_option].hide_label,
        'content_fade': true,
        'aiid': 'sa-abv',
      } only %}
    {% else %}
      {{ collapse_content }}
    {% endif %}
  </div>
{% endif %}
