{# Parameters:
  - flush (boolean) (default: false)
  - horizontal (string) (default: '')
    - options ['none', 'horizontal', 'horizontal-sm', 'horizontal-md', 'horizontal-lg', 'horizontal-xl', 'horizontal-xxl']
  - id (string) (default: '')
  - type (string) (default: 'unordered')
    - options ['unordered', 'ordered', 'actionable']
  - items (badge or link or button [])
      format: [
      {
        - html (string)
        - variant (string)
        ...badge
      }
      {
        ...Link
        - button (boolean) (default: false)
      },
      {
        ...Button
        - button (boolean) (default: false)
      },
      ...
    ]
  - attributes (drupal attrs)
#}

{%- set _flush = flush ?? false %}
{% set _horizontal = horizontal|default('') %}
{% set _id = id|default('') %}
{% set _type = type|default('unordered') %}
{% set _items = items|default([]) %}

{%- set _classes = ['list-group'] %}

{%- if _flush %}
  {%- set _classes = _classes|merge(['list-group-flush']) %}
{% endif %}
{% if _type == 'ordered' %}
  {%- set _classes = _classes|merge(['list-group-numbered']) %}
{% endif %}
{% if _horizontal is not empty %}
  {%- set _classes = _classes|merge(['list-group-' ~ _horizontal]) %}
{% endif %}

{%- if attributes is empty %}
  {%- set attributes = create_attribute() %}
{% endif %}

{%- if _id is not empty %}
  {%- set attributes = attributes.setAttribute('id', _id) %}
{% endif %}
{% set attributes = attributes.addClass(_classes) %}

{%- if _type == 'unordered' -%}
  <ul
    {{ attributes }}
  >
{%- endif %}
{% if _type == 'ordered' -%}
  <ol
    {{ attributes }}
  >
{%- endif %}
{% if _type == 'actionable' -%}
  <div
    {{ attributes }}
  >
{%- endif %}
{% if _items is not empty and _items is iterable %}
  {%- for _item in _items %}
    {%- if _type == 'unordered' or _type == 'ordered' %}
      {%- set _item_class = 'list-group-item' %}
      {%- if _item.variant is not empty %}
        {%- set _item_class = _item_class ~ ' list-group-item-' ~ _item.variant %}
      {%- endif %}
      {%- if _item.extra_classes is not empty %}
        {%- set _item_class = _item_class ~ ' ' ~ _item.extra_classes %}
      {%- endif -%}
      <li class="{{ _item_class }}">
      {%- if _item.input is defined -%}
          {% include '@oe-bcl/bcl-form-input/form-input.html.twig' with _item only %}
      {%- else -%}
          {{- _item.html -}}
          {%- if _item.badge is not empty -%}
            {% include '@oe-bcl/bcl-badge/badge.html.twig' with _item.badge only %}
          {%- endif -%}
      {%- endif -%}
      </li>
    {%- else %}
      {%- if _item.attributes is empty %}
        {%- set _item = _item|merge({
          attributes: create_attribute()
        }) %}
      {%- endif %}
      {%- set _item = _item|merge({
        clean_class: true,
        attributes: _item.attributes.addClass(['list-group-item', 'list-group-item-action'])
      }) %}
      {%- if _item.button is defined %}
        {%- include '@oe-bcl/bcl-button/button.html.twig' with _item only %}
      {%- else %}
        {%- include '@oe-bcl/bcl-link/link.html.twig' with _item only %}
      {%- endif %}
    {%- endif %}
  {%- endfor %}
{% endif %}
{% if _type == 'unordered' -%}
</ul>
{%- endif %}
{% if _type == 'ordered' -%}
</ol>
{%- endif %}
{% if _type == 'actionable' -%}
</div>
{%- endif -%}
