{% load djblets_forms djblets_utils i18n %}

{% block pre_fields %}{% endblock %}
{{form.non_field_errors}}

{% for field in form %}
{%  if field.is_hidden %}
{{field}}
{%  endif %}
{% endfor %}

<div class="fields-row">
 <div class="field">
{% with field=form.avatar_service_id %}
{%  include "configforms/config_page_form_field.html" %}
{% endwith %}
 </div>
</div>

{% for service_id, subform in form.avatar_service_forms.items %}
<fieldset class="avatar-service-fields" data-avatar-service-id="{{service_id}}"
          disabled hidden>
 {{subform.render|safe}}
</fieldset>
{% endfor %}
<script>
$().ready(function() {
    Djblets.Avatars.SettingsFormView.ready.then(function() {
{% for service_id, form in form.avatar_service_forms.items %}
        Djblets.Avatars.SettingsFormView.addConfigForm('{{service_id}}', {{form.js_view_class}});
{% endfor %}
        Djblets.Avatars.SettingsFormView.instance.renderForms();
    });
});
</script>

{% block post_fields %}{% endblock %}

{% if form.save_label %}
<div class="djblets-c-config-forms-actions">
 <button class="ink-c-button" type="submit">
  {{form.save_label}}
 </button>
</div>
{% endif %}
