{# LIBRARIES #}
{{ attach_library('ui_patterns/libraries.bs_dropdown') }}

{# VARIABLES #}
{% set status = status|default('default') %}
{% set cards_per_slide = cards_per_slide|default(3) %}
{% set controls_type = controls_type|default('dropdown') %}

{# TEMPLATE #}
{% if stations_list|length > 1 %}
  <div class="carousel-select d-inline-block controls-{{ controls_type }}">
    <button class="btn btn-{{ status }} dropdown-toggle mb-0"
            type="button"
            id="crsls-best-fares"
            data-bs-toggle="dropdown" >
      Station
    </button>
    <ul class="dropdown-menu ulp" aria-labelledby="crsls-best-fares">
      {% set cards = 0 %}
      {% set slides = 0 %}
      {% for crs, ticket_group in tickets %}
        {% set cards = (ticket_group|length / cards_per_slide) | round(0, 'ceil') %}
        <li>
          <button
            type="button"
            id="crsls-{{ crs }}-btn"
            data-bs-target="#crslc-best-fares"
            data-bs-slide-to="{{ slides }}"
            class="dropdown-item crslsb {% if loop.first %}active{% endif %}"
            aria-label="Go to {{ stations_list[crs] }}">
            {{ stations_list[crs] }}
          </button>
        </li>
        {% set slides = slides + cards %}
      {% endfor %}
    </ul>
  </div>
{% else %}
  {% for crs, ticket_group in tickets %}
    {{ stations_list[crs] }}
  {% endfor %}
{% endif %}
