{% load form_helpers %}
{% load i18n %}

{% if form.fieldsets %}

  {# Render hidden fields #}
  {% for field in form.hidden_fields %}
    {{ field }}
  {% endfor %}

  {# Render grouped fields according to Form #}
  {% for fieldset in form.fieldsets %}
    {% render_fieldset form fieldset %}
  {% endfor %}

  {% if form.custom_fields %}
    <div class="field-group mb-5">
      <div class="row">
        <h2 class="col-9 offset-3">{% trans "Custom Fields" %}</h2>
      </div>
      {% render_custom_fields form %}
    </div>
  {% endif %}

  {% if form.owner %}
    <div class="field-group mb-5">
      <div class="row">
        <h2 class="col-9 offset-3">{% trans "Ownership" %}</h2>
      </div>
      {% if form.owner_group %}
        {% render_field form.owner_group %}
      {% endif %}
      {% render_field form.owner %}
    </div>
  {% endif %}

  {% if form.comments %}
    <div class="field-group mb-5">
      {% render_field form.comments %}
    </div>
  {% endif %}

  {# Meta fields #}
  {% if form.changelog_message %}
    <div class="bg-primary-subtle border border-primary rounded-1 pt-3 px-3 mb-3">
      {% render_field form.changelog_message %}
    </div>
  {% endif %}

{% else %}

  {# Render all fields in a single group #}
  <div class="field-group mb-5">
    {% render_form form %}
  </div>

{% endif %}
