{# 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 train_icon = global_icon_train|default('fas fa-train') %}
{% set info_icon = global_icon_info|default('fas fa-info-circle') %}

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

{% if incidentList.items %}

  <ul class="services-list ulc">

    {% 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')
        %}

        {% 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 %}

        {% 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": (incidentList.type in ['service', 'station'] ) ? train_icon : info_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 %}
