{{ attach_library('ui_patterns/chk_serv.chk_serv_lib') }}

{% set result_status = 'default' %}

<div id="chk-srv-target-block-inner">

  {% if error %}

    {% set alert_content %}
      <h2 class="h4 msgh"><i class="fas fa-question-circle"></i> {{ error }}</h2>
    {% endset %}
    {% embed '@molecules/tm-message/alert/alert.twig' with {
      'status': 'primary',
      'content': alert_content,
    } only %}
    {% endembed %}

  {% else %}

    {% if results %}
      {% set result_status = 'danger' %}
      {% include "@organisms/tm-jc/chk-serv/chk-serv-results-items.twig" %}
    {%  else %}
      {% set result_status = 'success' %}
      {% include "@organisms/tm-jc/chk-serv/chk-serv-results-good.twig" %}
    {% endif %}

    {% set button %}
      {{ altcom_ajax_link(
        '<i class="fas fa-sync-alt"></i> <span class="sr-only">Refresh</span>',
        'journey_check_check_service_results_block',
        'chk-srv-target-block-inner',
        { 'block_from': from_crs,
          'block_to': to_crs },
        1, 0, 0, 60)
      }}
    {% endset %}

    <div class="chk-serv-info results-{{ result_status }}">
      <span>At-a-glance service status for your regular journey.</span>
      <div class="chk-serv-reload">
        <span class="chk-serv-time" data-timestamp="{{ timestamp }}">Last updated: {{ "now"|date("H:i") }}</span>
        {{ button }}
      </div>
    </div>

  {% endif %}

</div>
