{% load admin_utils %}
<fieldset {% if fieldset.name %}id="fieldset_{{ fieldset.name | slugify }}"{% endif %}
          class="kt-container  module aligned {{ fieldset.classes }}">
    <div class="kt-portlet__head mb-4">
        <div class="kt-portlet__head-label">
            <h3 class="kt-portlet__head-title">
                {% if fieldset.name %}
                    {{ fieldset.name }}
                {% else %}
                    Opções Gerais
                {% endif %}
            </h3>
            {% if fieldset.description %}
                <div class="ml-3 description">
                    {{ fieldset.description|safe }}
                </div>
            {% endif %}
        </div>
    </div>

    {% for line in fieldset %}

        <div class="{% spaceless %}{% if line.fields|length_is:'1' and line.errors %} errors{% endif %}
            {% if not line.has_visible_field %} hidden
            {% endif %}
            {% for field in line %}
                {% if field.field.name %} field-{{ field.field.name }}
                    {% endif %}
                {% endfor %}
            {% endspaceless %}">
            {% if line.fields|length_is:'1' %}
                {% for field in line %}
                    <div class="form-group row" data-fieldset-readonly="{{ field.is_readonly }}">
                        {{ field.label_tag | addclass:"kt-font-bold col-lg-2 col-md-2 col-sm-12 col-form-label" }}
                        {% if field.is_readonly %}
                            <div class="readonly">{{ field.contents }}</div>
                        {% else %}
                            <div class="col-lg-10 col-md-10 col-sm-12">
                                {% if line.errors %}
                                    {{ field.field | addclass:"form-control is-invalid" }}
                                {% else %}
                                    {{ field.field | addclass:"form-control" }}
                                {% endif %}

                                {% if line.errors  %}
                                    <div class="invalid-feedback" style="display: block">{{ line.errors }}</div>
                                {% endif %}

                                {% if field.field.help_text %}
                                    <div class="text-muted small">
                                        {{ field.field.help_text|safe }}
                                    </div>
                                {% endif %}
                            </div>
                        {% endif %}
                    </div>
                {% endfor %}
            {% else %}
                <div class="form-group row">
                    {% for field in line %}
                        {% spaceless %}
                            {{ field.label_tag | addclass:"kt-font-bold col-lg-2 col-md-2 col-sm-12 col-form-label" }}
                            <div class="col-lg-4">
                                {% if field.errors %}
                                    {{ field.field | addclass:"form-control is-invalid" }}
                                {% else %}
                                    {{ field.field | addclass:"form-control" }}
                                {% endif %}

                                {% if field.errors  %}
                                    <div class="invalid-feedback" style="display: block">{{ field.errors }}</div>
                                {% endif %}

                                {% if field.field.help_text %}
                                    <div class="text-muted small">
                                        {{ field.field.help_text|safe }}
                                    </div>
                                {% endif %}
                            </div>
                        {% endspaceless %}
                    {% endfor %}
                </div>
            {% endif %}
        </div>
    {% endfor %}
</fieldset>
