{% load widget_tweaks %}

{% if field.is_hidden %}
{{ field }}
{% else %}

{% block control_group %}
{% if not form_clean %}
<div class="form-group{% if style == "horizontal" %} row{% endif %}">
    {% block label %}
    {% if not nolabel and field.widget_type != 'checkbox' %}
    <label for="{{ field.auto_id }}" class="{% if style|default:"stacked" != 'stacked' %}col-sm-4{% endif %} col-form-label{% if field.field.required %} required{% endif %}">
        {% if label %}
            {{ label }}
        {% else %}
            {{ field.label|safe }}
        {% endif %}
    </label>
    {% endif %}
    {% endblock %}

    {% block controls %}
    <div class="{% if field.errors %}is-invalid{% endif %}{% if style|default:"stacked" != 'stacked' %}col-md-7 col-12{% endif %}{% if field.widget_type == 'checkbox' %} form-check{% endif %}">
        {% block widget %}
        {% if field.widget_type == 'checkbox' %}
        {% render_field field aria-label=field.label class+="form-check-input" %}
        <label for="{{ field.auto_id }}" class="col-form-label form-check-label {% if field.field.required %}required{% endif %}">
            {% if label %}
            {{label}}
            {% else %}
            {{ field.label|safe }}
            {% endif %}
        </label>
        {% elif field.widget_type == "radioselect"  %}
        {% for radio in field %}
        <div class="form-check radioselect">
            {{ radio.tag }}
            <label for="{{ radio.id_for_label }}" class="form-check-label">
                {{ radio.choice_label }}
            </label>
        </div>
        {% endfor %}
        {% elif field.widget_type == "datapriceradioselect" %}
        {% for radio in field %}
        <div class="form-check radioselect">
            {{radio}}
        </div>
        {% endfor %}
        {% elif field.widget_type == "datapricecheckboxselectmultiple" %}
        {% for radio in field %}
        <div class="form-check checkboxselect">
            {{radio}}
        </div>
        {% endfor %}
        {% elif field.widget_type == "checkboxselectmultiple" %}
        {% for radio in field %}
        <div class="form-check radioselect">
            {{radio.tag}}
            <label for="{{ radio.id_for_label }}" class="form-check-label">
                {{ radio.choice_label }}
            </label>
        </div>
        {% endfor %}
        {% elif field.widget_type == "datepicker" %}
        <input type="date" id="{{field.auto_id}}" name="{{field.name}}" class="form-control" />
        {% elif field.widget_type == "select" %}
        {% render_field field aria-label=field.label class+="form-select" placeholder=placeholder %}
        {% elif field.widget_type == "datapriceproductradioselect" %}
        {% render_field field aria-label=field.label class+="paid_product_option" placeholder=placeholder %}
        {% else %}
        {% render_field field aria-label=field.label class+="form-control" placeholder=placeholder autocomplete=field.name %}
        {% endif %}
        {% endblock %}

        {% block errors %}
        {% for error in field.errors %}
        <span class="error-block"><i class="fa fa-exclamation"></i> {{ error }}</span>
        {% endfor %}
        {% endblock %}

        {% block help_text %}
        {% if field.help_text %}
        <small class="form-text text-muted">
            {# We allow HTML within form help fields #}
            {{ field.help_text|safe }}
        </small>
        {% endif %}
        {% endblock %}
    </div>
    {% endblock %}
</div>
{% else %}
{% render_field field aria-label=field.label class+="form-control" placeholder=placeholder autocomplete=field.name %}
{% endif %}
{% endblock %}
{% endif %}