{% load i18n %}

{% with workflow.get_entry_point as entry_point %}

<div class="workflow {{ layout|join:' ' }}" {% if modal %}tabindex="-1"{% endif %} data-backdrop="{{ modal_backdrop }}">
  <form {{ workflow.attr_string|safe }} action="{{ workflow.get_absolute_url }}" {% if add_to_field %}data-add-to-field="{{ add_to_field }}"{% endif %} method="POST"{% if workflow.multipart %} enctype="multipart/form-data"{% endif %}>{% csrf_token %}
    {% if REDIRECT_URL %}<input type="hidden" name="{{ workflow.redirect_param_name }}" value="{{ REDIRECT_URL }}"/>{% endif %}
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
        {% block modal-header %}
          {% if modal %}
            <a href="#" class="close" data-dismiss="modal">
              <span class="fa fa-times"></span>
            </a>
          {% endif %}
          <h3 class="modal-title">{{ workflow.name }}</h3>
        {% endblock %}
        </div>
        <div class="modal-body">
        {% block modal-body %}
          {% if workflow.steps|length >= 2 %}
            <ul class="nav nav-pills{% if HORIZON_CONFIG.integration_tests_support %} selenium-nav-region{% endif %}{% if workflow.wizard %} wizard-tabs{% endif %}" role="tablist">
              {% for step in workflow.steps %}
              <li class="{% if entry_point == step.slug %}active{% endif %}{% if step.has_errors %} error{% endif %}{% if step.has_required_fields %} required{% endif %}">
                <a href="#{{ step.get_id }}" data-toggle="tab" data-target="#{{ step.get_id }}">
                  {{ step }}
                  {% if step.has_required_fields %}{% include "horizon/common/_form_field_required.html" %}{% endif %}
                </a>
              </li>
              {% endfor %}
            </ul>
          {% endif %}
          <div class="tab-content">
            {% for step in workflow.steps %}
              <fieldset id="{{ step.get_id }}" class="js-tab-pane{% if entry_point == step.slug %} active{% endif %}">
                {{ step.render }}
              </fieldset>
              {% if not forloop.last %}
                <noscript><hr /></noscript>
              {% endif %}
            {% endfor %}
          </div>
        {% endblock %}
        </div>
        <div class="modal-footer">
        {% block modal-footer %}
          {% if workflow.wizard %}
          <div class="row">
            <div class="col-sm-12">
              {% if modal %}
                <a class="btn btn-default cancel">{% trans "Cancel" %}</a>
              {% endif %}
              <button type="button" class="btn btn-default button-previous">&laquo; &nbsp;{% trans "Back" %}</button>
              <button type="button" class="btn btn-primary button-next">{% trans "Next" %}&nbsp; &raquo;</button>
              <button type="submit" class="btn btn-primary button-final">{{ workflow.finalize_button_name }}</button>
            </div>
          </div>
          {% else %}
            {% if modal %}<a class="btn btn-default cancel">{% trans "Cancel" %}</a>{% endif %}
            <input class="btn btn-primary" type="submit" value="{{ workflow.finalize_button_name }}" />
          {% endif %}
        {% endblock %}
        </div>
      </div>
    </div>
  </form>
</div>

{% endwith %}

{% block modal-js %}
  {% if workflow.wizard %}
  <script type="text/javascript">
    (window.$ || window.addHorizonLoadEvent)(function () {
      horizon.modals.init_wizard();
    });
  </script>
  {% endif %}
{% endblock %}
