{% load i18n %}
{% load static %}

{% if title %}
<h4>
    {{ title }}
</h4>
<hr>
{% endif %}

<div class="well">
    {% if form.is_multipart %}
        <form name="{{ form.prefix }}" enctype="multipart/form-data" method="{{ submit_method|default:'post' }}" action="{{ form_action }}" class="{{ form_class|default:'' }}">
    {% else %}
        <form name="{{ form.prefix }}" method="{{ submit_method|default:'post' }}" action="{{ form_action }}" class="{{ form_class|default:'' }}">
    {% endif %}

        {{ wizard.management_form }}

        {% if step_field %}
            <input type="hidden" name="{{ step_field }}" value="{{ step0 }}" />
        {% endif %}

        {% if submit_method != 'GET' and submit_method != 'get' %}
            {% csrf_token %}
        {% endif %}

        {% if next %}
            <input name="next" type="hidden" value="{{ next }}" />
        {% endif %}

        {% if previous %}
            <input name="previous" type="hidden" value="{{ previous }}" />
        {% endif %}

        {% for hidden_field in hidden_fields %}
           {{ hidden_field.as_hidden }}
        {% endfor %}

        {% if form.management_form %}
            {% with form as formset %}
                {{ formset.management_form }}

                {% if form_display_mode_table %}
                    <div class="table-responsive">
                        <table class="table table-condensed table-striped">
                            <tbody>
                            <tr>
                                {% for field in formset.forms.0.visible_fields %}
                                    <th>
                                        {{ field.label_tag }}{% if field.field.required and not read_only %} ({% trans 'required' %}){% endif %}
                                    </th>
                                {% endfor %}
                            </tr>
                    {% endif %}

                    {% for form in formset.forms %}
                        {% include 'appearance/generic_form_instance.html' %}
                {% endfor %}
                {% if form_display_mode_table %}
                        </tbody>
                    </table>
                </div>
                {% endif %}
            {% endwith %}
        {% else %}
            {% include 'appearance/generic_form_instance.html' %}
        {% endif %}
        {% if not read_only %}
            <div class="form-group">
                <button class="btn btn-primary" name="{% if form.prefix %}{{ form.prefix }}-submit{% else %}submit{% endif %}" type="submit"><i class="{{ submit_icon|default:'fa fa-check' }}"></i> {% if submit_label %}{{ submit_label }}{% else %}{% if object %}{% trans 'Save' %}{% else %}{% trans 'Submit' %}{% endif %}{% endif %}</button>
                {% if previous %}
                      &nbsp;<a class="btn btn-default" onclick='{% if previous %}window.location.replace("{{ previous }}");{% else %}history.go(-1);{% endif %}'>
                        <i class="fa fa-cross"></i> {% if cancel_label %}{{ cancel_label }}{% else %}{% trans 'Cancel' %}{% endif %}
                      </a>
                {% endif %}
            </div>
        {% endif %}
    </form>
</div>
