{% load i18n %}
{% load bootstrap_tags %}

{% if form.non_field_errors %}
    <div class="alert alert-danger">{{ form.non_field_errors }}</div>
{% endif %}

{% csrf_token %}
{% for hidden in form.hidden_fields %}
    {{ hidden }}
{% endfor %}

{% for field in form.visible_fields %}
    <div class="{% if field.errors %}has-errors{% endif %} mb-3 row">
        <label class="control-label fw-bold col-{{ fold_class }}-{{ size_left }}"
               for="{{ field.id_for_label }}">
            {% if not field|fieldtype_is:'CheckboxInput' %}
                {{ field.label }}
            {% endif %}
        </label>
        <div class="col-{{ fold_class }}-{{ size_right }}">
            {% if field|fieldtype_is:'RadioSelect' %}
                <fieldset>
                <legend class="visually-hidden">{{field.label}}</legend>
                {% for choice in field %}
                    <label class="radio-inline">
                        <span class="radio">{{ choice.tag }}</span>
                        {{ choice.choice_label }}
                    </label>
                {% endfor %}
                </fieldset>
            {% elif field|fieldtype_is:'CheckboxInput' %}
                <div class="checkbox">
                    <label>
                        {{ field }} {{ field.label }}
                    </label>
                </div>
            {% elif field|fieldtype_is:'CheckboxSelectMultiple' %}
            <fieldset>
                <legend class="visually-hidden">{{field.label}}</legend>
                {% for choice in field %}
                    <div class="checkbox">
                        <label>
                            {{ choice }} {{ choice.label }}
                        </label>
                    </div>
                {% endfor %}
            </fieldset>
            {% elif field|fieldtype_is:'Select' %}
                {{ field|add_form_select }}
            {% else %}
                {{ field|add_form_control }}
            {% endif %}
            {% for error in field.errors %}
                <div class="text-danger">{{ error }}</div>
            {% endfor %}
        </div>
        {% if field.help_text %}
        <p id="help-{{ field.id_for_label }}"
           class="offset-{{ fold_class }}-{{ size_left }} col-{{ fold_class }}-{{ size_right }} text-muted">
            {{ field.help_text|safe|linebreaksbr }}
        </p>
        {% endif %}
    </div>
{% endfor %}
{% if button %}
    <div class="">
        <div class="offset-{{ fold_class }}-{{ size_left }} col-{{ fold_class }}-{{ size_right }}">
            <button class="btn btn-primary" type="submit">{% trans button %}</button>
        </div>
    </div>
{% endif %}
