{#
/**
 * Available variables:
 * - button_type: link or button tag
 * - button_block - blockname prepended to the base classname
 * - button_element - the base class name of the element
 * - button_modifiers - array of modifiers to add to the base classname
 * - button_attributes - array of attribute,value pairs
 * - button_url - the url this button should poing to
 * - button_content - the content of the button (typically text)
 *
 * Available blocks:
 * - button_content - used to replace the content of the button with something other than text
 *   for example: to insert an icon
 */
#}

{% if button_type == 'link' %}
  {% set button_tag = 'a' %}
{% else %}
  {% set button_tag = 'button' %}
{% endif %}

{% set button_bem_block = button_bem_block|default('button') %}

{% set button_bem_modifiers = button_bem_modifiers|default([])|merge([
  secondary ? 'secondary',
  size ? size,
]) %}

{% set button_attributes = create_attribute(button_attributes|default([])) %}

<{{ button_tag }}
  {{ button_attributes.addClass(bem(button_bem_block, button_bem_element, button_bem_modifiers, button_bem_extra)) }}
  {% if button_url is defined and button_url is not null and button_url != false and button_url|length %}
    href="{{ button_url }}"
  {% endif %}
>
  {% block button_content %}
    {{ button_content }}
  {% endblock button_content %}
</{{ button_tag }}>
