{# DOCS #}
{#
route (parent, needed for disambiguation)
incidentList
- type
- title
- items
  - item
    - id
    - title
    - text
    - updateText
    - extraInfo
    - hasCallingPoints
    - callingPoints
#}
{# LIBRARIES #}
{{ attach_library('ui_patterns/jc_dropdown.jc_base') }}
{{ attach_library('ui_patterns/jc_modal.jc_modal_lib') }}

{% set incident_train_icon = global_icon_incident_train|default('fas fa-train') %}
{% set incident_alert_icon = global_icon_incident_alert|default('fas fa-exclamation-circle') %}
{% set incident_line_icon = global_icon_incident_line|default('fas fa-info-circle') %}

{% if incidentList.title %}
  <h3 class="services-header">{{ incidentList.title }}</h3>
{% endif %}

{% if incidentList.items %}

  <ul class="services-list ulc" data-incident-type="{{  incidentList.type }}">

    {% for item in incidentList.items %}

      {% set uid = uid|default('') %}
      {% set pid = pid|default('') %}
      {% set uid = "#{uid}-#{item.id}" %}


      <li class="lic disruptions-item">

        {% set link_attributes = create_attribute()
          .setAttribute('id', "sgsl-#{uid}")
          .setAttribute('data-bs-target', "#sgs-#{uid}")
          .setAttribute('data-bs-toggle', 'collapse')
          .setAttribute('tabindex', '0')
          .setAttribute('role', 'button')
        %}

        {% if not item.text %}
          {% set ajax_attrs = altcom_ajax_attrs_array(
            "journey_check_incident_details",
            "jci-#{uid}",
            {"incident_id": item.id, "uid": uid, "pid": pid, "status": route.status}, 1, 0, 1)
          %}
          {% for k, v in ajax_attrs %}
            {% set link_attributes = link_attributes.setAttribute(k, v) %}
          {% endfor %}
        {% else %}
          {% set link_attributes = link_attributes.setAttribute('data-alt-toggle', "auto") %}
          {% set link_attributes = link_attributes.setAttribute('data-alt-once', "true") %}
        {% endif %}

        {% set line_incident_icon = incident_train_icon %}
        {% if incidentList.type == 'line' %}
          {% set line_incident_icon = incident_line_icon %}
        {% endif %}
        {% if incidentList.type in ['service', 'station'] %}
          {% set line_incident_icon = incident_alert_icon %}
        {% endif %}

        {% include "@atoms/tm-links/icon-bookended/icon-bookended.twig" with {
          "text": item.title,
          "attr": link_attributes,
          "toggle": 'chevron',
          "class": 'dt-toggle belian aat-cancel ' ~ route.status,
          "icon_left": line_incident_icon,
        } %}

        <div class="incident-item collapse"
             data-alt-toggle="state"
             data-alt-target="collapse"
             id="sgs-{{ uid }}"
             aria-expanded="false">

          <div class="service">
            {% include '@organisms/tm-jc/jc-modal/jc-modal-incident/journey-check-incident-details.html.twig' with {
              'element': item,
              'uid': uid,
              'pid': pid,
              'status': route.status
            } only %}
          </div>

        </div>

      </li>
    {% endfor %}

  </ul>

{% endif %}
