{# Set classes for this component #}
{%- set classNames = "idsk-button" -%}

{%- if params.classes %}
  {% set classNames = classNames + " " + params.classes %}
{% endif %}
{% if params.disabled %}
  {% set classNames = classNames + " idsk-button--disabled" %}
{% endif -%}

{# Determine type of element to use, if not explicitly set #}
{%- if params.element %}
  {% set element = params.element | lower %}
{% else %}
  {% if params.href %}
    {% set element = 'a' %}
  {% else %}
    {% set element = 'button' %}
  {% endif %}
{% endif -%}

{% if params.isStartButton %}
  {% set iconHtml %}
{#- The SVG needs `focusable="false"` so that Internet Explorer does not
treat it as an interactive element - without this it will be
'focusable' when using the keyboard to navigate. #}
<svg class="idsk-button__start-icon" xmlns="http://www.w3.org/2000/svg" width="17.5" height="19" viewBox="0 0 33 40" role="presentation" focusable="false">
  <path fill="currentColor" d="M0 0h13l20 20-20 20H0l20-20z"/>
</svg>
  {% endset %}
  {% set classNames = classNames + " idsk-button--start" %}
{% endif %}

{#- Define common attributes that we can use across all element types #}

{%- set commonAttributes %} class="{{ classNames }}" data-module="idsk-button"{% for attribute, value in params.attributes %} {{attribute}}="{{value}}"{% endfor %}{% endset %}

{#- Define common attributes we can use for both button and input types #}

{%- set buttonAttributes %}{% if params.name %} name="{{ params.name }}"{% endif %} type="{{ params.type if params.type else 'submit' }}"{% if params.disabled %} disabled="disabled" aria-disabled="true"{% endif %}{% if params.preventDoubleClick %} data-prevent-double-click="true"{% endif %}{% endset %}

{#- Actually create a button... or a link! #}

{%- if element == 'a' %}
<a href="{{ params.href if params.href else '#' }}" role="button" draggable="false" {{- commonAttributes | safe }}>
  {{ params.html | safe if params.html else params.text }}
{# Indentation is intentional to output HTML nicely #}
{{- iconHtml | safe | trim | indent(2, true) if iconHtml -}}
</a>

{%- elseif element == 'button' %}
<button {%- if params.value %} value="{{ params.value }}"{% endif %} {{- buttonAttributes | safe }} {{- commonAttributes | safe }}>
  {{ params.html | safe if params.html else params.text }}
{# Indentation is intentional to output HTML nicely #}
{{- iconHtml | safe | trim | indent(2, true) if iconHtml -}}
</button>

{%- elseif element == 'input' %}
<input value="{{ params.text }}" {{- buttonAttributes | safe }} {{- commonAttributes | safe }}>
{%- endif %}
