{% load i18n %}

{{ attachment_formset.management_form }}
{% for form in attachment_formset.forms %}
<div class="mb-4 space-y-3 w-full attachment-form">
  {% for field in form.visible_fields %}
  <div class="my-5">
    {% if forloop.first %}
    {{ form.id }}
    {% endif %}
    {% if field.html_name in form.files.keys %}
    {% for key, file in form.files.items %}
    {% if key == field.html_name %}
    <p class="initial"><i class="fa fa-file"></i>&nbsp;&nbsp;{{ file.name }}</p>
    {% endif %}
    {% endfor %}
    {% endif %}
    {% if field.name == 'DELETE' %}
    <div class="mt-3 checkbox">
      <label for="{{ field.auto_id }}">
        {{ field }}
        {{ field.label }}
      </label>
    </div>
    {% elif field.name == 'file' %}
    <div id="div_id_{{ field.html_name }}" class="form-group{% if field.errors %} has-error{% endif %}">
      <div class="controls">
        {% if field.label %}<label class="control-label" for="{{ field.auto_id }}">{{ field.label }}{% if not field.field.required %} <span class="text-muted">{% trans "(optional)" %}</span>{% endif %}</label>{% endif %}
        {{ field }}
        {% if field.help_text %}<p class="help-block">{{ field.help_text }}</p>{% endif %}
        {% for error in field.errors %}<p class="error">{{ error }}</p>{% endfor %}
      </div>
    </div>
    {% else %}
    {% include "partials/form_field.html" with field=field %}
    {% endif %}
    </div>
    {% endfor %}
</div>
{% endfor %}
<a href="#" id="add_more_attachment" class="py-3 px-4 my-5 text-xs uppercase rounded border border-slate text-orange">
  <i class="icon-white icon-plus-sign"></i>&nbsp;{% trans "Add another file" %}
</a>
