{# LIBRARIES #}
{{ attach_library('ui_patterns/menu_bt.menu_bt_lib') }}

{# VARIABLES #}
{% set mid = mid|default(random()) %}
{% set outline = outline|default(false) %}
{% set title = title|default(false) %}
{% set size = size|default('md') %}
{% set status = status|default('default') %}
{% set expanded = expanded|default(false) %}
{% set button_classes = button_classes|default('mb-0') %}
{% set row_classes = row_classes|default('mb-0') %}
{% set cols = cols|default(2) %}
{% set col_classes = col_classes|default('') %}
{% set wrapper_classes = wrapper_classes|default('') %}
{% if col_classes is empty %}
  {% set col_width = (12 / cols) %}
  {% set col_classes = 'col-sm-' ~ col_width ~ ' mb-3' %}
{% endif %}

{# TEMPLATE #}
{% if links %}

  {% if wrapper_classes %}
    <div class="{{ wrapper_classes }}">
  {% endif %}

  {% if title %}
    <h2 class="imbtnav-title">{{ title }}</h2>
  {% endif %}

  {% set nav_items = [] %}
  {% for link in links %}
    {% set nav_item %}

      {% include '@atoms/form/button/button.twig' with {
        'text': link['title'],
        "url": link['url'],
        "icon": link['icon'],
        "icon_position": link['icon_position'] ?? 'left',
        'outline': outline,
        'expanded': expanded,
        'size': size,
        'status': status,
        'class': button_classes,
      } %}

    {% endset %}
    {% set nav_items = nav_items|merge([nav_item]) %}
  {% endfor %}

  {% include "@organisms/tm-scaffold/rows-cols/rows-cols.twig" with {
    'wrapper_class': ['nav-buttons', wrapper_class]|join(' '),
    'auto_height': true,
    'batch': cols,
    'items': nav_items,
    'col_class': col_classes,
    'row_class': row_classes,
  } %}

  {% if wrapper_classes %}
    </div>
  {% endif %}

{% endif %}
