{% load static i18n nested_admin admin_urls exfilters %}
{% with inline_admin_formset.formset.is_nested as is_nested %}
<section class="assistant box"  data-assistant="{{inline_admin_formset.formset.prefix}}">
{% if not migas|exgetlast == inline_admin_formset.opts.verbose_name_plural %}
    {% extest migas name=inline_admin_formset.opts.verbose_name_plural link=inline_admin_formset.formset.prefix as var %}
{% endif %}
{% with inline_admin_formset.opts as inline_opts %}
<div class="inline-group group djn-group djn-stacked{% if is_nested %} djn-group-nested{% else %} djn-group-root{% endif %}"
    id="{{ inline_admin_formset.formset.prefix }}-group"
    data-inline-type="stacked"
    data-inline-formset="{{ inline_admin_formset.inline_formset_data }}"
    data-inline-model="{{ inline_admin_formset.inline_model_id }}">

    <div class="miga">
        <ul>
            <li>
                <a href="#{{father}}"><i class="micon">arrow_back</i></button>
            </li>
            {% for miga in migas%}
                <li>
                {% if forloop.first %}
                    <a href="#{{miga.link}}">{% if add %}{% trans 'Add' %} {% endif %}{{ miga.name }}</a>
                {% else %}
                    <a href="#{{miga.link}}">{{miga.name|capfirst }}</a>
                {% endif %}
                {% if not forloop.last %}
                    <i class="micon">keyboard_arrow_right</i>
                {% endif %}
                </li>
            {% endfor%}
            <!-- <li>
                {% if inline_admin_formset.opts.title %}{{ inline_admin_formset.opts.title }}{% else %}{{ inline_admin_formset.opts.verbose_name_plural|capfirst }}{% endif %}
            </li> -->
        </ul>
    </div>

    {{ inline_admin_formset.formset.management_form }}
    {{ inline_admin_formset.formset.non_form_errors }}
        {% with inline_admin_formset.opts.sortable_field_name|default:"" as sortable_field_name %}
        {% for inline_admin_form in inline_admin_formset|formsetsort:sortable_field_name %}
            {% if forloop.first %}
            <div class="djn-item djn-no-drag"><div></div></div>
            {% endif %}
            <div class="items djn-items">
            {{ inline_admin_form.management_form }}
            <div class="{% if not forloop.last %}djn-item{% endif %} djn-module djn-inline-form {% if inline_admin_formset.opts.classes %} {{ inline_admin_formset.opts.classes|join:" " }}{% endif %}{% if inline_admin_form.original or inline_admin_form.show_url %} has_original{% endif %}{% if forloop.last %} djn-empty-form empty-form{% endif %} inline-related"
                 {% if inline_admin_form.pk_field.field %}
                 data-is-initial="{% if inline_admin_form.pk_field.field.value %}true{% else %}false{% endif %}"
                 {% endif %}
                 id="{{ inline_admin_formset.formset.prefix }}{% if forloop.last %}-empty{% else %}{{ inline_admin_form.form|form_index }}{% endif %}">
                    <h3 class="{% if not inline_opts.sortable_options or not inline_opts.sortable_options.disabled %} djn-drag-handler{% endif %}">
                        <b>{{ inline_admin_formset.opts.verbose_name|capfirst }}:</b>&nbsp;<span class="inline_label">{% if inline_admin_form.original %}{{ inline_admin_form.original }}{% if inline_admin_form.model_admin.show_change_link and inline_admin_form.model_admin.has_registered_model %} <a href="{% url inline_admin_form.model_admin.opts|admin_urlname:'change' inline_admin_form.original.pk|admin_urlquote %}" class="inlinechangelink">{% trans "Change" %}</a>{% endif %}
                        {% else %}{% ifnotsuit %}#{{ forloop.counter }}{% endifnotsuit %}{% endif %}</span>
                              {% if inline_admin_form.show_url %}<a href="{{ inline_admin_form.absolute_url }}">{% trans "View on site" %}</a>{% endif %}
                            {% if inline_admin_formset.formset.can_delete  %}
                            {% if inline_admin_form.original %}
                                <span class="delete djn-delete-handler {{ inline_admin_formset.handler_classes|join:" " }}">{{ inline_admin_form.deletion_field.field }} {{ inline_admin_form.deletion_field.label_tag }}</span>
                            {% else %}
                                <span><a class="inline-deletelink djn-remove-handler {{ inline_admin_formset.handler_classes|join:" " }}" href="javascript:void(0)">Remove</a></span>
                            {% endif %}
                            {% endif %}
                    </h3>
                  {% if inline_admin_form.form.non_field_errors %}
                      <ul class="errorlist">
                          <li>{{ inline_admin_form.form.non_field_errors }}</li>
                      </ul>
                  {% endif %}
                  {% for fieldset in inline_admin_form %}
                      {% include inline_admin_formset.opts.fieldset_template %}
                  {% endfor %}
                  {% if inline_admin_form.form.inlines %}
                  <div class="assistant-btn">
                      {% for nested in inline_admin_form.form.inlines %}
                          <a class="assistant-lk" href="#{{nested.formset.prefix}}">{%if add %}Agregar{% else %}Editar{% endif %} {% if nested.opts.title %}{{ nested.opts.title }}{% else %}{{ nested.opts.verbose_name_plural|capfirst }}{% endif %} ({{nested.formset|length}})</a>
                      {% endfor %}
                  </div>
                  {% endif %}
                  {% if inline_admin_form.has_auto_field or inline_admin_form.needs_explicit_pk_field %}
                      {{ inline_admin_form.pk_field.field }}
                  {% endif %}
                  {{ inline_admin_form.fk_field.field }}
            </div>
        {% endfor %}
        {% endwith %}
        {{ inline_admin_formset.extra_forms }}
    </div>
    <div class="djn-module djn-add-item add-item add-row">
        <a href="javascript://" class="add-handler djn-add-handler {{ inline_admin_formset.handler_classes|join:" " }}">
            {% blocktrans with inline_admin_formset.opts.verbose_name|strip_parent_name:inline_opts.verbose_name|title as verbose_name %}Add another {{ verbose_name }}{% endblocktrans %}
        </a>
    </div>
</div>
{% endwith %}{# ends with inline_admin_formset.opts as inline_opts #}
{% endwith %}{# ends {% with inline_admin_formset.formset.is_nested as is_nested %} #}
</section>
{% with inline_admin_formset.opts.sortable_field_name|default:"" as sortable_field_name %}
    {% for inline_admin_form in inline_admin_formset|formsetsort:sortable_field_name %}
        {% if inline_admin_form.form.inlines %}
            {% for nested in inline_admin_form.form.inlines %}
                {% include nested.opts.template with inline_admin_formset=nested father=inline_admin_formset.formset.prefix migas=var%}
            {% endfor %}
        {% endif %}
    {% endfor%}
{% endwith%}
