{% load viewset_tags %}

{% if field.is_hidden %}
  {{ field }}
{% elif field.name == 'ORDER' or field.name == 'DELETE' %}
  <div class="d-none">{{ field }}</div>
{% else %}
  <div class="form-group form-row">
    {% if field|is_widget_type_of:'checkbox' %}
      <div class="col-sm-3"></div>
      <div class="col-sm-9">
        <div class="form-check">
          {{ field|add_css_class:'form-check-input'|add_error_css_class:'is-invalid' }}
          <label class="form-check-label" for="{{ field.auto_id }}">
            {{ field.label }}
          </label>
        </div>
        {% if field.help_text %}
          <small class="form-text text-muted">
            {{ field.help_text }}
          </small>
        {% endif %}
        {% if field.errors %}
          <div class="invalid-feedback d-block">
            {% for error in field.errors %}
              <div>{{ error }}</div>
            {% endfor %}
          </div>
        {% endif %}
      </div>
    {% else %}
      <label for="{{ field.auto_id }}" class="col-sm-3 col-form-label {% if field.field.required %}font-weight-bold{% endif %}">{{ field.label }}</label>
      <div class="col-sm-9">
        {% if field|is_widget_type_of:'file' %}
          {{ field|add_css_class:'form-control-file'|add_error_css_class:'is-invalid' }}
        {% else %}
          {{ field|add_css_class:'form-control'|add_error_css_class:'is-invalid' }}
        {% endif %}
        {% if field.help_text %}
          <small class="form-text text-muted">
            {{ field.help_text }}
          </small>
        {% endif %}
        {% if field.errors %}
          <div class="invalid-feedback d-block">
            {% for error in field.errors %}
              <div>{{ error }}</div>
            {% endfor %}
          </div>
        {% endif %}
      </div>
    {% endif %}
  </div>
{% endif %}