{#
/**
 * @author
 * Altcom Ltd — 2023
 * @file
 * ScotRail theme implementation to display the Flexipass Check Route form.
 *
 * Available variables:
 * - form: Drupal\flexipass_check\Form\FlexipassCheckForm object.
 *
 * @ingroup themeable
 */
#}
{{ attach_library('ui_patterns/flexipass_check_form.flexipass_check_form_lib') }}

{{ form.error_messages }}
{# Display the origin, swap, and destination elements. #}
<div class="flexipass-check-top mt-3 mb-4">
  <div class="origin-destination">
    {{ form.origin_station }}
    {{ form.swap_stations }}
    {{ form.destination_station }}
  </div>
  {# Display the reset button. #}
  <div class="reset-button">{{ form.actions.reset }}</div>
</div>

{% set ajax_callback = form.actions.submit['#attributes']['data-altcom-ajax-callback']|default('flexipass_check_results') %}
{% set ajax_id = form.actions.submit['#attributes']['data-altcom-ajax-id']|default('flexipass-check-results') %}

{# Display the result message and the submit button. #}
<div class="flexipass-check-result" id="{{ ajax_id }}">
  <div class="row message-container">
    <div class="col-sm-12 col-md-8">
      {% embed '@molecules/tm-message/alert/alert.twig' with {
        'status': 'info',
        'content': form.target.markup['#markup'],
      } only %}
      {% endembed %}
    </div>
    <div class="col-sm-12 col-md-4 text-md-end">
      {# Completely rebuild the submit button so it passes data to the ajax. #}
      {% set spinner %}
        {% include "@molecules/tm-bs/spinner/spinner.twig" with {
          'ajax': true
        } only %}
      {% endset %}

      {{ altcom_ajax_button(
        form.actions.submit['#text'] ~ ' ' ~ spinner,
        ajax_callback,
        ajax_id,
        {
          'form_id': 'this',
          'block_id': 'embedded_flexipasscheckformblock',
          'cache_tag': 'config:flexipass_check.settings',
          'label': form.actions.submit['#text'],
          'callback': ajax_callback,
          'ajax_id': ajax_id
        })
      }}
    </div>
  </div>
</div>
{# Renders the rest of the form. #}
{{ form|without('error_messages','actions','origin_station','swap_stations','destination_station','target') }}

