{#
/**
 * @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>
{# Display the result message and the submit button. #}
<div class="flexipass-check-result" id="{{ form.actions.submit['#attributes']['data-altcom-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,
        form.actions.submit['#attributes']['data-altcom-ajax-callback'],
        form.actions.submit['#attributes']['data-altcom-ajax-id'],
        {
          'form_id': 'this',
          'block_id': 'embedded_flexipasscheckformblock',
          'cache_tag': 'config:flexipass_check.settings',
          'label': form.actions.submit['#text'],
          'callback': form.actions.submit['#attributes']['data-altcom-ajax-callback'],
          'ajax_id': form.actions.submit['#attributes']['data-altcom-ajax-id']
        })
      }}
    </div>
  </div>
</div>
{# Renders the rest of the form. #}
{{ form|without('error_messages','actions','origin_station','swap_stations','destination_station','target') }}

