{{ attach_library('ui_patterns/jc_summary.jc_summary_lib') }}

{# VARIABLES #}
{% set attributes = attributes|default(create_attribute()) %}
{% set time_updated = time_updated|default("now"|date("H:i")) %}
{% set status = data.status|default("good") %}
{% set icon_left = icon_left|default(null) %}
{% set pass_through = data.passThrough|default({}) %}

{# Status mapping #}
{% set statuses = [
  {'status':'good', 'icon_left': global_status_icon_good|default('fas fa-check-circle'), 'icon_right': null},
  {'status':'minor', 'icon_left': global_status_icon_minor|default('fas fa-exclamation-circle'), 'icon_right': null},
  {'status':'major', 'icon_left': global_status_icon_major|default('fas fa-exclamation-triangle'), 'icon_right': null},
  {'status':'incidents', 'icon_left': global_status_icon_incidents|default('fas fa-exclamation-circle'), 'icon_right': null},
  {'status':'stationalert', 'icon_left': global_status_icon_stationalert|default('fas fa-info-circle'), 'icon_right': null},
  {'status':'noservice', 'icon_left': global_status_icon_noservice|default('fas fa-exclamation-circle'), 'icon_right': null},
  {'status':'amended', 'icon_left': global_status_icon_amended|default('fas fa-exclamation-circle'), 'icon_right': null},
  {'status':'strike', 'icon_left': global_status_icon_strike|default('fas fa-exclamation-circle'), 'icon_right': null},
] %}

{# Status icons #}
{% for item in statuses %}
  {% if status == item.status %}
    {% set icon_left = icon_left ? icon_left : item.icon_left %}
  {% endif %}
{% endfor %}

{# TEMPLATE #}
<div id="rbs-blk">

  <div class="{{ data.status }} rbs-header">
    {# Icons can now be stacked #}
    {% if icon_left is iterable %}
      <span class="f-stack">
        <i class="{{ icon_left[0] }}"></i>
        <i class="{{ icon_left[1] }}"></i>
      </span>
    {% else %}
      <i class="{{ icon_left }}"></i>
    {% endif %}
    <h2 class="header">{{ data.statusText }}</h2>
  </div>

  {% set ajax_attrs = altcom_ajax_attrs_string(
    'journey_check_summary_status',
    'jcssw',
    {'pass_through': pass_through}, 1, 0, 0, 300)
  %}

  <div class="rbs-updates bg-{{ data.status }} efx-pulse efx-warning mt-3">
    <span class="rbs-updated">Latest update: <span class="time">{{ time_updated }}</span></span>
    <a href="#" class="rbs-icon" role="button" aria-label="Reload data" {{ ajax_attrs|raw }}>
      <i class="fas fa-sync-alt"></i>
    </a>
  </div>

  {% if data.filtered and view_updates_link_text %}
    {% set ajax_attrs = altcom_ajax_attrs_string(
      'journey_check_modal_items',
      'jcm-items',
      {'pass_through': pass_through}, 1, 0, 0)
    %}
    {% set ajax_hidden_attrs = altcom_ajax_attrs_string(
      'journey_check_dropdown_items',
      'jcdw',
      {'pass_through': pass_through}, 1, 0, 0)
    %}
    <a href="#" class="pt-2 align-self-start" data-bs-toggle="modal" data-bs-target="#jcs-modal" data-alt-toggle="clicker" data-alt-target="#unfilter-dropdown-link" {{ ajax_attrs }}>{{ view_updates_link_text }}</a>
    <a href="#" id="unfilter-dropdown-link" class="d-none" {{ ajax_hidden_attrs }}>Unfiltered dropdown</a>
  {% endif %}

</div>
