{% macro open(method, action, attributes) %}
    <form method="{{ method|upper }}" {% if action is not empty %}action="{{ action }}"{% endif %}
    {% for attribute, value in attributes %}{{ attribute }}="{{ value }}"{% endfor %}>
{% endmacro %}

{% macro close() %}
    </form>
{% endmacro %}

{% macro row(label, element, id) %}

    {% import _self as form %}

    {# Uncomment to enable tooptips: #}
    {#{% set title = tooltips[id] %}#}

    <tr>
        <th scope="row">
            <label {% if id is not empty %}id="label-{{ id }}" for="{{ id }}"{% endif %}>
                {{ label }}
                {% if title is not empty %}
                    <i class="fa fa-{{ tooltips_icon.icon|default('question-circle') }} ready-tooltip" title="{{ title|raw }}" style="{% for property, value in tooltips_icon.style %}{{ property|trim }}:{{ value|trim }};{% endfor %}"></i>
                {% endif %}
            </label>
        </th>
        <td id="{{ id }}">
            {{ element|raw }}
        </td>
    </tr>
{% endmacro %}

{% macro input(type = 'text', name, value, attributes) %}
    <input type="{{ type }}" name="{{ name }}" value="{{ value }}"
        {% for attribute, val in attributes %}
            {% if val is iterable %}
                {{ attribute }}="{% for attr, param in val %}{{ attr }}:{{ param }};{% endfor %}"
            {% else %}
                {{ attribute }}="{{ val }}"
            {% endif %}
        {% endfor %}
    />
{% endmacro %}

{% macro text(name, value, attributes) %}
    {% import _self as form %}

    {{ form.input('text', name, value, attributes) }}
{% endmacro %}

{% macro password(name, value, attributes) %}
    {% import _self as form %}

    {{ form.input('password', name, value, attributes) }}
{% endmacro %}

{% macro button(name, value, attributes) %}
    {% import _self as form %}

    {% if attributes.class is defined %}
        {% set attributes = attributes|merge({ 'class': attributes.class ~ ' button button-primary' }) %}
    {% endif %}

    {{ form.input('button', name, value, attributes) }}
{% endmacro %}

{% macro checkbox(name, value, attributes) %}
    {% import _self as form %}

    {{ form.input('checkbox', name, value, attributes) }}
{% endmacro %}

{% macro file(name, value, attributes) %}
    {% import _self as form %}

    {{ form.input('file', name, value, attributes) }}
{% endmacro %}

{% macro hidden(name, value, attributes) %}
    {% import _self as form %}

    {{ form.input('hidden', name, value, attributes) }}
{% endmacro %}

{% macro radio(name, value, attributes) %}
    {% import _self as form %}

    {{ form.input('radio', name, value, attributes) }}
{% endmacro %}

{% macro color(name, value, attributes) %}
    {% import _self as form %}

    {{ form.input('color', name, value, attributes) }}
{% endmacro %}

{% macro submit(name, value, attributes) %}
    {% import _self as form %}

    {% if attributes.class is defined %}
        {% set attributes = attributes|merge({ 'class': attributes.class ~ ' button button-primary' }) %}
    {% endif %}

    {{ form.input('submit', name, value, attributes) }}
{% endmacro %}

{% macro select(name, options, selected, attributes) %}
    <select name="{{ name }}" {% for attribute, value in attributes %}{{ attribute }}="{{ value }}"{% endfor %}>
        {% for value, text in options %}
            <option value="{{ value }}" {% if selected == value %}selected{% endif %}>{{ text }}</option>
        {% endfor %}
    </select>
{% endmacro %}