{% set info_accordion_copy_prefix_classes = info_accordion_copy_prefix_classes|default('mt-0') %}

{% if version == 'destination_tab' %}

  {% if ldb %}
      {{ pattern('bs-accordion-items', ldb, 'aci_a_b') }}
  {% endif %}

  {% if info_accordion %}
    {% if info_accordion_title %}
      <h2>{{ info_accordion_title }}</h2>
    {% endif %}
    {% if info_accordion_text %}
      <p>{{ info_accordion_text }}</p>
    {% endif %}

      {{ pattern('bs-accordion-items', info_accordion, 'aci_a') }}
  {% endif %}

  {% if second_info_accordion %}
    {% if second_info_accordion_title %}
      <h2>{{ second_info_accordion_title }}</h2>
    {% endif %}
    {% if second_info_accordion_text %}
      <p>{{ second_info_accordion_text }}</p>
    {% endif %}

    {{ pattern('bs-accordion-items', second_info_accordion, 'aci_e') }}
  {% endif %}

  {% if map %}
      <div class="map">{{ map }}</div>
  {% endif %}

{% else %}

  {% if station_alerts %}
    {% if station_alert_type == 'list' %}
      {{ pattern('alerts', station_alerts, 'new_style') }}
    {% else %}
      {{ pattern('alert', station_alerts, 'warning') }}
    {% endif %}
  {% endif %}

  {% if intro %}
    {{ pattern('intro', { 'content': intro, 'link': intro_link, 'intro_classes': intro_classes }) }}
  {% endif %}

  {% if station_information %}
      {{ station_information }}
  {% endif %}

  {% if header_use_extended %}
    {% set header_title_crs = header_title_crs|default(false) %}

    {% if name or crs or address %}
      {% embed "@organisms/tm-stations/station-header/station-header.twig" %}
        {% set station = name ~ (header_title_crs ? ' (' ~ crs ~ ')' : ' Train Station Map') %}
      {% endembed %}
    {% endif %}


  {% else %}

    {% if name or crs or address %}
      {% embed "@organisms/tm-stations/station-title/station-title.twig" %}
        {% set station = name ~ ' (' ~ crs ~ ')' %}
      {% endembed %}
    {% endif %}

    {% if map %}
      <div class="map mb-3">{{ map }}</div>
    {% endif %}

  {% endif %}

  {% if station_info_header %}
    <h2 class="h-pri">{{ station_info_header }}</h2>
  {% endif %}

  {# Sorry for the repeating code but this was the simplest way I could think of #}
  {# to provide a backwards compatible way of moving the exposed LDB before the #}
  {# station information accordions without some really crazy if statement logic #}
  {% if ldb_position == 'before' %}
    {% if ldb and not ldb_use_exposed %}
      {{ pattern('bs-accordion-items', ldb, 'aci_a_b') }}
    {% elseif ldb_exposed_content and ldb_use_exposed %}
      <div id="ldb-exposed" class="mb-3">
      {% if ldb_exposed_title %}
        <h2 class="h-pri">{{ ldb_exposed_title }}</h2>
      {% endif %}
        {{ ldb_exposed_content }}
      </div>
    {% endif %}
  {% elseif ldb_position == '' %}
    {% if ldb and not ldb_use_exposed %}
      {{ pattern('bs-accordion-items', ldb, 'aci_a_b') }}
    {% endif %}
  {% endif %}

  {% if show_buy_tickets_button %}
    {% set buy_tickets_button_text = buy_tickets_button_text|default("Find tickets from this station") %}
    {% include "@atoms/tm-links/icon-bookended/icon-bookended.twig" with {
      "text":buy_tickets_button_text,
      "url": '#',
      "icon_left": "fas fa-ticket-alt rot-135",
      "class": "buy-tickets-btn stations-btb fw-bold btn " ~ buy_tickets_button_class,
      "attr": create_attribute().setAttribute('data-from-station', crs),
      "display": 'inline',
    } only %}
  {% endif %}

  {% if timetables %}
    <div id="st-tt" class="mb-4">
      {{ timetables }}
    </div>
  {% endif %}

  {% if info_accordion %}
    {% if info_accordion_title %}
      <h2 class="mb-0 mt-5">{{ info_accordion_title }}</h2>
    {% endif %}
    {% if info_accordion_text %}
      <p>{{ info_accordion_text }}</p>
    {% endif %}
    {% if info_accordion_copy_prefix and info_accordion_copy_company %}
      <h3 class="{{ info_accordion_copy_prefix_classes }}">{{ info_accordion_copy_prefix }} <strong class="fstrong">{{ info_accordion_copy_company }}</strong></h3>
    {% endif %}
    {{ pattern('bs-accordion-items', info_accordion, 'aci_a') }}
  {% endif %}

  {% if second_info_accordion %}
    {% if second_info_accordion_title %}
      <h2 class="mt-5">{{ second_info_accordion_title }}</h2>
    {% endif %}
    {% if second_info_accordion_text %}
      <p>{{ second_info_accordion_text }}</p>
    {% endif %}

    {{ pattern('bs-accordion-items', second_info_accordion, 'aci_a') }}
  {% endif %}

  {% if ldb_position == 'after' %}
    {% if ldb and not ldb_use_exposed %}
      {{ pattern('bs-accordion-items', ldb, 'aci_a_b') }}
    {% elseif ldb_exposed_content and ldb_use_exposed %}
      <div id="ldb-exposed" class="mb-3">
      {% if ldb_exposed_title %}
        <h2 class="h-pri">{{ ldb_exposed_title }}</h2>
      {% endif %}
        {{ ldb_exposed_content }}
      </div>
    {% endif %}
  {% elseif ldb_position == '' %}
    {% if ldb_exposed_content and ldb_use_exposed %}
      <div id="ldb-exposed" class="mb-3">
      {% if ldb_exposed_title %}
        <h2 class="h-pri">{{ ldb_exposed_title }}</h2>
      {% endif %}
        {{ ldb_exposed_content }}
      </div>
    {% endif %}
  {% endif %}

  {% if offers_page_path %}
    {% set offers_url = offers_page_path ~ '?combine_1=' ~ name %}
    {% include "@atoms/tm-links/standard/standard.twig" with {
      "url": offers_url,
      "text": "Find offers nearby",
      "class": "btn btn-sm btn-outline-default"
    } %}
  {% endif %}

{% endif %}
