{#
  Parameters:
  - title: (string) (default: '')
  - title_tag: (string) (default: 'h2')
  - title_link: (link object) (default: {})
  - title_attributes (drupal attrs)
  - bordered (boolean) (default: false)
  - col_classes (string) (default: 'col-3')
  - items (array) (default: []): format: [
      {
        term (string or description list title [])
        definition (string or description list details [])
      },
      ...
    ]
  - variant (string) (default: '')
    - option: ['horizontal']
#}

{%- set _title = title|default('') %}
{% set _title_tag = title_tag|default('h2') %}
{% set _title_link = title_link|default({}) %}
{% set _title_attributes = title_attributes ?: create_attribute() %}
{% set _bordered = bordered ?? false %}
{% set _col_classes = col_classes|default('col-md-3') %}
{% set _items = items|default([]) %}
{% set _variant = variant|default('') %}

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

{%- set _item_classes = ['mb-3'] %}

{%- if _bordered %}
  {%- set _item_classes = ['border-bottom', 'pb-2-5', 'mb-2-5'] %}
{% endif %}

{%- if _variant == 'horizontal' %}
  {%- set _item_classes = _item_classes|merge(['row']) %}
{% endif %}

{%- if _title is not empty %}
  {%- include '@oe-bcl/bcl-heading/heading.html.twig' with {
    title: _title,
    title_tag: _title_tag,
    title_link: _title_link,
    attributes: _title_attributes,
  } only %}
{% endif %}

{%- set attributes = attributes.addClass(['bcl-description-list']) %}

{%- if _variant != 'horizontal' -%}
<dl
  {{ attributes }}
>
{%- else -%}
<div
  {{ attributes }}
>
{%- endif %}
  {%- for _item in _items %}
  {%- if _variant == 'horizontal' -%}
  <dl
    {{ create_attribute().addClass(_item_classes) }}
  >
  {%- else -%}
  <div
    {{ create_attribute().addClass(_item_classes) }}
  >
  {%- endif %}
  {%- if _item.term is not empty %}
    {%- if _variant == 'horizontal' -%}
    <div class="{{ _col_classes }}">
    {%- endif %}
    {%- if _item.term is iterable %}
      {%- for _term in _item.term %}
        {%- include '@oe-bcl/bcl-description-list/description-list-title.html.twig' with _term only -%}
      {% endfor %}
    {%- else %}
      {%- include '@oe-bcl/bcl-description-list/description-list-title.html.twig' with {
        label: _item.term
      } only -%}
    {% endif %}
    {%- if _variant == 'horizontal' -%}
    </div>
    {%- endif %}
  {%- endif %}
  {%- if _item.definition is not empty %}
    {%- if _variant == 'horizontal' -%}
    <div class="col">
    {%- endif %}
    {%- if _item.definition is iterable %}
      {%- for _definition in _item.definition %}
        {%- include '@oe-bcl/bcl-description-list/description-list-details.html.twig' with _definition only -%}
      {% endfor %}
    {%- else %}
      {%- include '@oe-bcl/bcl-description-list/description-list-details.html.twig' with {
        label: _item.definition
      } only -%}
    {% endif %}
    {%- if _variant == 'horizontal' -%}
    </div>
    {%- endif %}
  {%- endif %}
  {%- if _variant == 'horizontal' -%}
  </dl>
  {%- else -%}
  </div>
  {%- endif %}
  {%- endfor %}
{% if _variant != 'horizontal' -%}
</dl>
{%- else -%}
</div>
{%- endif -%}
