{# Parameters:
  - label (string) (default: '')
  - path (string) (default: '#')
  - variant (string) (default: '')
    - options ['primary', 'secondary', 'success', 'danger', 'warning', 'info', 'light', 'dark']
  - id (string) (default: '')
  - disabled (boolean) (default: false)
  - standalone (boolean) (default: false)
  - icon (icon object) (default: {})
  - icon_position (string) (default: after)
    - options ['after', 'before']
  - icon_display (string) (default: '')
    - options ['flex', 'inline-flex']
  - remove_icon_spacers (boolean) (default: false)
  - attributes (drupal attrs)
#}

{%- set _label = label|default('') %}
{% set _path = path|default('#') %}
{% set _variant = variant|default('') %}
{% set _id = id|default('') %}
{% set _disabled = disabled ?? false %}
{% set _standalone = standalone ?? false %}
{% set _icon = icon|default({}) %}
{% set _icon_position = icon_position|default('after') %}
{% set _icon_display = icon_display|default('') %}
{% set _use_icon_display = _icon_display in ['flex', 'inline-flex'] %}
{% set _remove_icon_spacers = remove_icon_spacers ?? false %}

{%- set _classes = [] %}

{%- if _use_icon_display and not _remove_icon_spacers %}
  {%- set _classes = _classes|merge(['d-' ~ _icon_display, 'gap-2-5']) %}
{%- endif %}

{%- if _icon is not empty %}
  {%- if _label is not empty and not _remove_icon_spacers and not _use_icon_display %}
    {%- if _icon.attributes is empty %}
      {%- set _icon = _icon|merge({
          attributes: create_attribute()
        })
      %}
    {%- endif %}
    {%- if _icon_position == 'before' %}
      {%- set _icon = _icon|merge({
          attributes: _icon.attributes.addClass('me-2-5')
        })
      %}
    {%- else %}
      {%- set _icon = _icon|merge({
          attributes: _icon.attributes.addClass('ms-2-5')
        })
      %}
    {%- endif %}
  {%- endif %}
  {%- set _icon_markup -%}
    {%- include '@oe-bcl/bcl-icon/icon.html.twig' with _icon only -%}
  {%- endset -%}
{% endif %}

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

{%- if _disabled %}
  {%- set _classes = _classes|merge(['disabled']) %}
  {%- set attributes = attributes.setAttribute('aria-disabled', 'true').setAttribute('tabindex', '-1') %}
{% endif %}
{% if _variant is not empty %}
  {%- set _classes = _classes|merge(['link-' ~ _variant]) %}
{% endif %}
{% if _id is not empty %}
  {%- set attributes = attributes.setAttribute('id', _id) %}
{% endif %}
{% if _standalone %}
  {%- set _classes = _classes|merge(['standalone']) %}
{% endif %}
{% if _classes is not empty %}
  {%- set attributes = attributes.addClass(_classes) %}
{% endif %}
{% set attributes = attributes.setAttribute('href', _path) -%}

<a
  {{ attributes }}
>
  {%- if _icon_position == 'before' and _icon_markup is defined -%}
    {{ _icon_markup }}
  {%- endif -%}
  {{- _label -}}
  {%- if _icon_position == 'after' and _icon_markup is defined -%}
    {{ _icon_markup }}
  {%- endif -%}
</a>
{#--#}
