{% extends 'report/template_upsert_base.html' %}
{% load i18n formset_tags %}

{% block content %}
<h3>
    {% blocktrans with title=object.title model=object.model %}Creating report {{ title }} for model {{ model }}.{% endblocktrans %}
</h3>

<form method="post" novalidate>
    {% csrf_token %}
        {{ filter.form.columns.label }}
        {{ filter.form.columns }}
        {{ filter.form.columns.errors }}
        
        {{ filter.form.users.label }}
        {{ filter.form.users }}
        {{ filter.form.users.errors }}
        
        {{ filter.form.groups.label }}
        {{ filter.form.groups }}
        {{ filter.form.groups.errors }}

        <div style="margin: 2rem 0">
            <div>
                {{ object.model }} →
            </div>
            <div
                id="model-user-path-formset"
                data-formset-prefix="{{ model_user_path.prefix }}"
            > 
                {{ model_user_path.management_form }} 
                
                <div data-formset-body>
                    {% for form in model_user_path %} 
                        <div data-formset-form> 
                            {{ form }} 
                            <button
                                type="button"
                                data-formset-delete-button
                            >Delete form</button>
                        </div> 
                    {% endfor %}
                </div>
                    
                <script
                    type="form-template"
                    data-formset-empty-form
                >
                    {% escapescript %}
                        <div data-formset-form>
                            {{ model_user_path.empty_form }}
                            <button type="button" data-formset-delete-button>Delete form</button>
                        </div>
                    {% endescapescript %}
                </script>
                
                <input
                    type="button"
                    value="Add another"
                    data-formset-add
                >

                <script>
                    jQuery(function ($) {
                        $("#model-user-path-formset").formset({
                            animateForms: true
                        });
                    });
                </script>
            </div>
            <div>
                → User
            </div>
        </div>

        <h4>{% trans 'Filters' %}</h4>
        <div>
            {% for field in filter.form %}
                {% if field.name not in meta_fields_name %}
                    <div>
                        {{ field.label }}
                        {{ field }}
                        {% if field.help_text %}
                            <p>{{ field.help_text|safe }}</p>
                        {% endif %}
                    </div>
                {% endif %}
            {% empty %}
                <h3>No filter was found for this model.</h3>
            {% endfor %}
        </div>

    <button type="submit">{% trans 'Submit' %}</button>
</form>
{% endblock %}
