{{ 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({}) %}
{% set no_icon = no_icon|default(false) %}
{% set inline = inline|default(false) %}
{% set title = title|default(false) %}
{% set block_attributes = block_attributes|default(create_attribute()) %}
{% if inline %}
  {% set block_attributes = block_attributes.addClass('inline') %}
{% endif %}

{# Status mapping #}
{% import "@protons/macros/status.macros.twig" as status_macros %}

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

  {% if not no_icon %}
    {% set content %}
      <h2 class="header{% if no_icon %} no-icon{% endif %}">{{ data.statusText }}</h2>
    {% endset %}
    {% set class = [data.status, 'rbs-header']|join(' ') %}
    {{ status_macros.status(status, icon_left, 'div', class, null, null, content, true) }}
  {% endif %}

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

  {% if title %}
    <h2 class="rbs-title">
      <span class="bell">{{ title }}</span>
    </h2>
  {% endif %}

  <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>
