{# LIBRARIES #}
{{ attach_library('ui_patterns/nre_ad_boards.nre_ad_lib') }}
{% if not tabbed %}
  {{ attach_library('ui_patterns/libraries.bs_tab') }}
  {{ attach_library('ui_patterns/bs-tabs.tabs_lib') }}
{% endif %}

{# VARIABLES #}
{% set departure_data = departure_data|default(null) %}
{% set arrival_data = arrival_data|default(null) %}
{% set tabbed = tabbed|default(false) %}
{% set responsive = responsive|default(false) %}

{% if departure_data or arrival_data %}

  {% set departure_title = 'Departures' %}
  {% set departure_table %}
    {% include "@organisms/tm-ldb/nre-ad-table/_nre-ad-table.twig" with{
      "content_data": departure_data,
      "type": 'depart',
      "responsive": responsive,
    } %}
  {% endset %}

  {% set arrival_title = 'Arrivals' %}
  {% set arrival_table %}
    {% include "@organisms/tm-ldb/nre-ad-table/_nre-ad-table.twig" with{
      "content_data": arrival_data,
      "type": 'arrive',
      "responsive": responsive,
    } %}
  {% endset %}

  {% if not tabbed %}
    <div class="bt_table_wrapper">
      {# Departures #}
      {% if departure_data %}
        <h4>{{ departure_title }}</h4>
        {{ departure_table }}
      {% endif %}
      {# Arrivals #}
      {% if arrival_data %}
        <h4>{{ arrival_title }}</h4>
        {{ arrival_table }}
      {% endif %}
    </div>
  {% else %}

    {% set depart_tab = {
      tbid: "dpt",
      title: departure_title,
      content: departure_table,
      first: true
    } %}

    {% set arrive_tab = {
      tbid: "arb",
      title: arrival_title,
      content: arrival_table,
      first: false
    } %}

    {{ pattern('bs-tabs-items', {
      'pid': 'ldb',
      'items': [depart_tab, arrive_tab],
    }, 'tbi_e') }}

  {% endif %}
{% endif %}
