{# Parameters:
  - label (string) (default: '')
  - background: (string) (default: 'primary')
  - url (string) (default: '')
  - title (string) (default: '')
  - dismissible (boolean) (default: false)
  - assistive_text (string) (default: '')
  - rounded_pill (boolean) (default: false)
  - outline (boolean) (default: false)
  - icon_path (string) (default: '')
  - attributes (drupal attrs)
#}

{%- set _label = label|default('') %}
{% set _background = background|default('primary') %}
{% set _url = url|default('') %}
{% set _title = title|default('') %}
{% set _dismissible = dismissible ?? false %}
{% set _assistive_text = assistive_text|default('') %}
{% set _rounded_pill = rounded_pill|default(false) %}
{% set _outline = outline|default(false) %}
{% set _icon_path = icon_path|default('') %}
{% set _classes = ['badge'] %}

{%- if _rounded_pill %}
  {%- set _classes = _classes|merge(['rounded-pill']) %}
{% endif %}

{%- if _outline %}
  {%- set _classes = _classes|merge(['badge-outline-' ~ _background]) %}
{% else %}
  {%- set _classes = _classes|merge(['text-bg-' ~ _background]) %}
{% endif %}

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

{%- if _title is not empty -%}
  {% set attributes = attributes.setAttribute('title', _title) %}
{%- endif -%}

{% set attributes = attributes.addClass(_classes) %}

{%- set _label %}
  {%- if _assistive_text is not empty -%}
  <span class="visually-hidden">
    {{- _assistive_text -}}
  </span>
  {%- endif -%}
  {{- _label -}}
  {%- if _dismissible -%}
  <span class="icon--close" aria-hidden="true">
    {%- include '@oe-bcl/bcl-icon/icon.html.twig' with {
      name: "x-circle-fill",
      size: "xs",
      path: _icon_path,
    } only -%}
  </span>
  {%- endif -%}
{% endset %}

{%- if _url is not empty -%}
  {% include '@oe-bcl/bcl-link/link.html.twig' with {
    label: _label,
    path: _url,
    attributes: attributes,
  } only %}
{%- else -%}
<span
  {{ attributes }}
>
  {{- _label -}}
</span>
{%- endif -%}
