{# LIBRARIES #}
{{ attach_library('ui_patterns/libraries.bs_collapse') }}

{# VARIABLES #}
{% set content_data = content_data|default(null) %}
{% set responsive = responsive|default(false) %}
{% set row_limit = row_limit|default(0) %}

{# TEMPLATE #}
{% if content_data %}
  {% set content_data_length = content_data|length %}
  {% if row_limit > 0 and content_data_length > row_limit %}
    {% set reveal_all = true %}
    {% set num_extra_rows = content_data_length - row_limit %}
    {% set hidden_content_data = content_data|slice(row_limit) %}
    {% set content_data = content_data|slice(0, row_limit) %}
  {% else %}
    {% set reveal_all = false %}
  {% endif %}
  {% set initial_content %}
    {% include "@organisms/tm-ldb/nre-ad-table/_nre-ad-table-contents.twig" with{
      "content_data": content_data,
      "type": type,
      "responsive": responsive,
      "id_extra": '',
    } %}
  {% endset %}
  {% if reveal_all %}
    {% set hidden_content %}
      {% include "@organisms/tm-ldb/nre-ad-table/_nre-ad-table-contents.twig" with{
        "content_data": hidden_content_data,
        "type": type,
        "responsive": responsive,
        "id_extra": '-1',
      } %}
    {% endset %}
    {% if num_extra_rows > 1 %}
      {% set extra_text = 's' %}
    {% else %}
      {% set extra_text = '' %}
    {% endif %}
    {% include '@organisms/tm-reveal-all/reveal-all.twig' with {
      'initial_content': initial_content,
      'hidden_content': hidden_content,
      'show_text': 'Show ' ~ num_extra_rows ~ ' more train' ~ extra_text,
      'hide_text': 'Hide extra train' ~ extra_text,
      'bottom_fade' : 'white',
    } only %}
  {% else %}
    {{ initial_content }}
  {% endif %}
{% endif %}
