{# VARIABLES #}

{% set button_attributes = create_attribute() %}
{% set card_attributes = create_attribute() %}

{% if link_scope == 'button' %}
  {% set button_attributes = button_attributes
    .setAttribute('aria-label', tickets[x].desktop_button['text'])
    .setAttribute('role', 'button')
  %}
  {% for key, value in tickets[x].desktop_button['data'] %}
    {% set button_attributes = button_attributes.setAttribute(key, value) %}
  {% endfor %}
{% endif %}

{% if link_scope == 'card' %}
  {% set card_attributes = card_attributes
    .setAttribute('aria-label', tickets[x].desktop_button['text'])
    .setAttribute('role', 'button')
    .setAttribute('href', '#')
    .setAttribute('class', 'buy-tickets-btn')
  %}
  {% for key, value in tickets[x].desktop_button['data'] %}
    {% set card_attributes = card_attributes.setAttribute(key, value) %}
  {% endfor %}
{% endif %}

{% set button_text %}
  <span aria-hidden="true">Book now</span>
  <span class="sr-only">{{ tickets[x].desktop_button['text'] }}</span>
{% endset %}

{% set button %}
  {% include "@atoms/form/button/button.twig" with {
    "attributes": button_attributes,
    "tag": link_scope == 'button' ? 'a' : 'span' ,
    "text": button_text,
    "url": link_scope == 'button' ? '#' : '',
    "expanded": not slider_images,
    "class": link_scope == 'button' ? 'best-fares buy-tickets-btn dtb' : 'best-fares dtb',
    "size": button_size,
    "status": card_button_status
  } only %}
{% endset %}


{# TEMPLATE #}
<div class="col-md-{{ (12 / cards_per_slide) | round(1, 'floor')}} item-content"{% if slider_images %} data-card-number="{{ x }}"{% endif %}>

  <{{ link_scope == 'card' ? 'a' : 'div'}} {{ card_attributes.addClass("ticket-body") }} >

  {% if slider_images %}
  {% if tickets[x].image %}
    {{ tickets[x].image }}
  {% endif %}
  <div class="text-content">
    {% endif %}
    <div class="ticket-top">
      <div class="ticket-from">
        <span>{{ direction }}</span>
        <strong>{{ tickets[x].title }}</strong>
      </div>

      <div class="fare">
        <span class="price">£{{ tickets[x].price|number_format(2, '.', ',') }}</span>
        <span>{{ tickets[x].direction }}</span>
      </div>
    </div>

    {{ button }}

    {% if slider_images %}
  </div>
  {% endif %}

</{{ link_scope == 'card' ? 'a' : 'div'}}>

</div>
