{% macro errors(items) %}
{% for error in items %}
<span class="text-danger">{{ error }}</span>
{% endfor %}
{% endmacro %}

{% macro field_only(entity) %}
{% if entity.errors %}
{{ entity.field(class_="form-control is-invalid", aria_describedby="{}-errors".format(entity.id), **kwargs) }}
<div id="{{ entity.id }}-errors" class="invalid-feedback">{{ errors(entity.errors) }}</div>
{% elif entity.description %}
{{ entity.field(class_="form-control", aria_describedby="{}-description".format(entity.id)) }}
<div id="{{ entity.id }}-description" class="form-text">{{ entity.description }}</div>
{% else %}
{{ entity.field(class_="form-control") }}
{% endif %}

{% macro field(entity) %}
<div>
    {{ entity.label(class_="form-label") }}
    {{ field_only(entity) }}
</div>
{% endmacro %}

{% macro switch(entity) %}
<div class="form-check form-switch">
    {{ entity.field(class_="form-check-input" role="switch") }}
    {{ entity.label(class_="form-check-label") }}
</div>
{% endmacro %}


{% macro inputGroupLeft(field) %}
<div class="input-group">
    <span class="input-group-text" id="{{ field.label.id }}">{{ field.label }}</span>
    {{ field.field(class_="form-control", aria_describedby=field.label.id, aria_label=field.name, aria_describedby=field.label.id) }}
</div>
{% endmacro %}

{% macro inputGroupRight(field) %}
<div class="input-group">
    {{ field.field(class_="form-control", aria_describedby=field.label.id, aria_label=field.name, aria_describedby=field.label.id) }}
    <span class="input-group-text" id="{{ field.label.id }}">{{ field.label }}</span>
</div>
{% endmacro %}

{% macro input_group(field, left=True) %}
{% if left %}
{{ inputGroupLeft(field) }}
{% else %}
{{ inputGroupRight(field) }}
{% endif %}
{% endmacro %}
