{#
  Parameters:
  - label (string) (default: '')
  - variant (string) (default: 'primary')
  - size (string) (default: 'md')
    - options ['sm', 'md', 'lg']
  - type (string) (default: 'button')
  - outline (boolean) (default: false)
  - disabled (boolean) (default: false)
  - text_nowrap (boolean) (default: false)
  - assistive_text (string) (default: '')
  - id (string) (default: '')
  - icon (icon object) (default: {})
  - icon_position (string) (default: after)
    - options ['after', 'before']
  - icon_spacing (string) (default: '')
    - options ['sm', 'md', 'lg']
  - spinner (spinner object) (default: {})
  - show_spinner (boolean) (default: false)
  - clean_class (boolean) (default: false)
  - attributes (drupal attrs)
#}

{%- set _label = label|default('') %}
{% set _variant = variant|default('primary') %}
{% set _size = size|default('md') %}
{% set _type = type|default('button') %}
{% set _outline = outline ?? false %}
{% set _disabled = disabled ?? false %}
{% set _text_nowrap = text_nowrap ?? false %}
{% set _assistive_text = assistive_text|default('') %}
{% set _id = id|default('') %}
{% set _icon = icon|default({}) %}
{% set _icon_position = icon_position|default('after') %}
{% set _icon_spacing = icon_spacing|default('') %}
{% set _spinner = spinner|default({}) %}
{% set _show_spinner = show_spinner ?? false %}
{% set _clean_class = clean_class ?? false %}
{% set _remove_icon_spacers = remove_icon_spacers ?? false %}

{%- set _classes = [] %}
{% if _clean_class == false %}
  {%- set _classes = _classes|merge(['btn', 'btn-' ~ (_outline ? 'outline-' : '') ~ _variant|e('html_attr')]) %}
  {%- set _classes = _classes|merge(['btn-' ~ _size|e('html_attr')]) %}
{% endif %}
{% if _text_nowrap %}
  {%- set _classes = _classes|merge(['text-nowrap']) %}
{% endif %}
{% if attributes is empty %}
  {%- set attributes = create_attribute() %}
{% endif %}
{% if _disabled %}
  {%- set attributes = attributes.setAttribute('disabled', true).setAttribute('aria-disabled', 'true') %}
{% endif %}
{% if _id is not empty %}
  {%- set attributes = attributes.setAttribute('id', _id) %}
{% endif %}
{% if _classes is not empty %}
  {%- set attributes = attributes.addClass(_classes) %}
{% endif %}
{% if _icon_spacing is not empty %}
  {%- set _icon_spacing = _icon_spacing ~ '-' %}
{% endif %}
{% set attributes = attributes.setAttribute('type', _type) %}
{% if _icon is not empty %}
    {%- set _icon = _icon|merge({
        size: "fluid",
      })
    %}
  {%- if _label is not empty and not _remove_icon_spacers %}
    {%- set attributes = attributes.addClass(['gap-' ~ _icon_spacing ~ '2-5']) %}
  {%- endif %}
  {%- set _icon_markup -%}
    {%- include '@oe-bcl/bcl-icon/icon.html.twig' with _icon only -%}
  {%- endset -%}
{% endif -%}

<button
  {{ attributes }}
>
{%- if _show_spinner -%}
  {% include '@oe-bcl/bcl-spinner/spinner.html.twig' with _spinner only %}
{%- endif -%}
{%- if _assistive_text is not empty -%}
  <span class="visually-hidden">{{- _assistive_text -}}</span>
{%- endif %}
{%- if _icon_position == 'before' and _icon_markup is defined -%}
  {{ _icon_markup|raw }}
{%- endif -%}
  {{- _label -}}
{%- if _icon_position == 'after' and _icon_markup is defined -%}
  {{ _icon_markup|raw }}
{%- endif -%}
</button>
{#--#}
