{# LIBRARIES #}
{{ attach_library('ui_patterns/nre_ad_boards.nre_ad_lib') }}

{# VARIABLES #}
{% set content_data = content_data|default(null) %}
{% set origin_name %}
  {% include "@atoms/tm-links/standard/standard.twig" with {
    'text': origin_data['name'],
    'url': origin_data['url']
  } only %}
{% endset %}
{% set destination_name %}
  {% include "@atoms/tm-links/standard/standard.twig" with {
    'text': destination_data['name'],
    'url': destination_data['url']
  } only %}
{% endset %}
{% set header_classes = header_classes|default('h-pri') %}

{# TEMPLATE #}
<h2 class="{{ header_classes }}">Next direct trains departing</h2>
<div class="nre-ldb-places-time mb-3">from {{ origin_name }} to {{ destination_name }} today, from {{ 'now'|date('H:i') }}</div>

{% if content_data %}
  {% set button_attributes = button_attributes|default(create_attribute())
    .setAttribute("data-from-station", origin_crs)
    .setAttribute("data-to-station", destination_crs)
  %}
  <div class="table-responsive">
    <table class="table table-bordered book-now-departure-table">

      <thead>
        <tr>
          <th scope="col">Departs</th>
          <th scope="col">Platform</th>
          <th scope="col">Operator</th>
          <th scope="col">Expected</th>
          <th></th>
        </tr>
      </thead>

      <tbody>

      {% for data in content_data %}
        <tr class="bt-row aat-cancel">

          <td data-label="Departs">{{ data.departs }}</td>
          <td data-label="Platform">{{ data.platform }}</td>
          <td data-label="Operator">{{ data.operator }}</td>
          <td data-label="Expected"{{ (data.expected == 'On time') ? '' : ' class="delayed"' }}>{{ data.expected }}</td>

          <td>

            {% include '@atoms/form/button/button.twig' with {
              'text': 'BOOK NOW',
              'status': 'default',
              'class': 'book-button buy-tickets-btn',
              'size': 'sm',
              'attributes': button_attributes
            } only %}

          </td>

        </tr>

      {% endfor %}

      </tbody>
    </table>
  </div>
{% else %}
  {% set stations = [] %}
  {% for change_station in change_stations %}
    {%- set station -%}
      {% include "@atoms/tm-links/standard/standard.twig" with {
        'text': change_station['name'],
        'url': change_station['url']
      } only %}
    {%- endset -%}
    {% set stations = stations|merge([station]) %}
  {% endfor %}
  <p>No direct trains between these stations have been found. Changes might occur at any of the following stations: {{ stations|join(', ', ' and ')|raw }}</p>
{% endif %}
