{% load i18n fobi_tags %}

{% block form_required_fields_message_block %}
<div class="{% block form_required_fields_message_wrapper_class %}{% endblock %}">
  {% blocktrans %}Fields marked with <span class="required-field">*</span> are required{% endblocktrans %}
</div>
{% endblock %}

{% if form.non_field_errors %}
  <div class="{% block non_field_errors_form_element_wrapper_html_class %}{% endblock %}">
    {{ form.non_field_errors.as_ul }}
  </div>
{% endif %}

{% for field in form %}
  {% if field.is_hidden %}
    <div class="{% block form_element_wrapper_hidden_html_class %}{% endblock %}">
      {{ field }}
    </div>
  {% else %}
    {% get_form_field_type field as field_type %}
    <div class="{% spaceless %}
      {% block form_element_wrapper_html_class %}{% endblock %}
      {% if field.errors %}
        {% block hidden_form_element_error_html_class %}{% endblock %}
      {% endif %}
    {% endspaceless %}">

      {% if field_type.is_checkbox %}
        <div class="{% block form_checkbox_element_field_wrapper_html_class %}{% endblock %}">
          <div class="checkbox">
            <label for="{{ field.id_for_label }}">
              {{ field }}
              {{ field.label }}
              {% if field.help_text %}
                <a class="popover-link" href="javascript:;" data-toggle="popover" data-content="{% spaceless %}{{ field.help_text }}{% endspaceless %}" role="button">
                  <span class="badge" title="{% trans 'Help' %}">?</span>
                </a>
              {% endif %}
            </label>
          </div>
        </div>
      {% else %}
        <label class="{% block form_element_label_html_class %}{% endblock %}" for="{{ field.id_for_label }}">
          {{ field.label }}{% if field.field.required %}<span class="{% block form_element_required_field_sign_html_class %}{% endblock %}">*</span>{% endif %}
        </label>

        <div class="{% block form_element_field_wrapper_html_class %}{% endblock %}">
          {{ field }}
          {% if field.errors %}
            <span class="{% block form_element_error_html_class %}{% endblock %}">
              {% for field_error in field.errors %}
                {{ field_error }}
              {% endfor %}
            </span>
          {% endif %}

          {% if field.help_text %}
            <span class="{% block form_element_help_text_html_class %}{% endblock %}">{{ field.help_text|safe }}</span>
          {% endif %}
        </div>
      {% endif %}
    </div>
  {% endif %}
{% endfor %}

{% if form.media.js %}
  {% block javascripts %}
    {{ block.super }}
    {{ form.media.js }}
  {% endblock javascripts %}
{% endif %}
