{% extends in_modal|yesno:"arctic/base_modal.html,arctic/base.html" %}

{% load i18n arctic_tags static %}

{% block body_class %}
    {{ block.super }}
{% endblock %}

{% block content %}
    <div class="row">
        <div class="col">
            <div class="form-size">
            {% block form_validation %}
                {% include "arctic/partials/form_validation.html" with form=form %}
            {% endblock %}
            </div>
        </div>
    </div>
    <form action="" method="POST" enctype="multipart/form-data" class="{% if not request.GET.inmodal %}dirty-check{% endif %} {{ form_display }}" novalidate>
        <input type="hidden" name="cancel_url" value="{{ cancel_url }}">
        <fieldset type="post" class="fieldset-default arctic-card">
            <div class="{% block form_size_class %}form-size{% endblock %}">
            {% csrf_token %}
            {% block form %}
                {% block form_fields %}
                    {% include "arctic/partials/form_fields.html" with form=form %}
                {% endblock %}
            {% endblock %}

            {% block inlines %}
            {% if inlines %}
                {% for formset in inlines %}
                    {% block inlines_title %}
                        {% if formset.verbose_name %}
                            <div class="arctic-card__form-header">
                                <h6 class="arctic-card__title">{{ formset.verbose_name }}</h6>
                            </div>
                            <div class="arctic-card__placeholder arctic-card__placeholder--small"></div>
                        {% endif %}
                    {% endblock %}
                        {{ formset.management_form }}
                        {{ formset.non_form_errors }}
                    <div class="inline-formset">
                        <div {% if formset.sorting_field %}data-sorting-field="{{ formset.sorting_field }}"{% endif %}>
                            {# This div is closed inside the form_fields_inline before the last loop #}
                            {% for form in formset %}
                                {% block inlines_form_fields %}
                                    {% include "arctic/partials/form_fields_inline.html" with form=form hide_form=forloop.last %}
                                {% endblock %}
                                {% if forloop.last %}
                                    <button class="add-inline btn btn-secondary btn-sm" data-inline-max-num="{{ formset.max_num }}" js-data-inline-button>
                                        <i title="Add Inline" class="fa fa-plus"></i>
                                    </button>
                                {% endif %}
                            {% endfor %}
                    </div>
                {% endfor %}
            {% endif %}
            {% endblock inlines %}

            {% block extra_forms %} {% endblock %}
            {# TODO move form-actions to its own section #}
            {% block form_actions %}
            <div class="row justify-content-center">
                <div class="col-auto">
                    {% for action in actions %}
                        {% if action.position == 'left' %}
                            {% if action.type == 'submit' %}
                                <input type="submit" name="{{ action.name }}" value="{{ action.label }}" {% if action.form_action %}formaction="{{ action.form_action }}"{% endif %} class="btn btn-{{ action.style }}" id="{{ action.id }}" />
                            {% else %}
                                <a class="btn btn-{{ action.style }}" href="{{ action.url }}" id="{{ action.id }}"
                                    {% include 'arctic/partials/modal_attributes.html' with modal=action.modal %}
                                >
                                    {{ action.label }}
                                </a>
                            {% endif %}
                        {% endif %}
                    {% endfor %}
                </div>
                <div class="col text-right">
                    {% for action in actions %}
                        {% if action.position != 'left' %}
                            {% if action.type == 'submit' %}
                                <input type="submit" name="{{ action.name }}" value="{{ action.label }}" {% if action.form_action %}formaction="{{ action.form_action }}"{% endif %} class="btn btn-{{ action.style }}" id="{{ action.id }}" />
                            {% else %}
                                <a class="btn btn-{{ action.style }}" href="{{ action.url }}" id="{{ action.id }}"
                                    {% include 'arctic/partials/modal_attributes.html' with modal=action.modal %}
                                >
                                {{ action.label }}
                                </a>
                            {% endif %}
                        {% endif %}
                    {% endfor %}
                </div>
            </div>
            {% endblock form_actions %}
            </div>
        </fieldset>
    </form>
    {% block extra_content %}{% endblock %}

{% include 'arctic/partials/modal_dialogs.html' %}

{% endblock %}
