{% extends "wagtailadmin/base.html" %}
{% load i18n feature_flags %}
{% block titletag %}{% if form.instance %}Edit {{ form.instance.condition }} condition{% else %}Create condition{% endif %}{% endblock %}

{% block content %}
    {% include "wagtailadmin/shared/header.html" with title=flag.name icon="tag" %}

    <h2 class="nice-padding">
        {% if form.instance %}Edit {{ form.instance.condition }}{% else %}Create condition{% endif %}
    </h2>

    {% if condition_pk %}
    <form class="nice-padding" method="POST" action="{% url 'wagtailflags:edit_condition' flag.name condition_pk %}">
    {% else %}
    <form class="nice-padding" method="POST" action="{% url 'wagtailflags:create_condition' flag.name %}">
    {% endif %}
        {% csrf_token %}
        <ul class="fields">

            {% for field in form %}
            <li {% if field.field.required %}class="required"{% endif %}>
                    {% if not field.is_hidden %}
                        <div class="field">
                            {{ field.label_tag }}

                            <div class="field-content">
                                <div class="input">
                                    {{ field }}
                                </div>
                                {% if field.help_text %}
                                    <p class="help">{{ field.help_text|safe }}</p>
                                {% endif %}
                            </div>

                            {% if field.errors %}
                                <div class="help-block help-critical" style="margin-top:0;">
                                    {{ field.errors }}
                                </div>
                            {% endif %}
                        </div>
                    {% else %}
                        {{ field }}
                    {% endif %}

                </li>
            {% endfor %}

            <li class="actions">
                <input class="button action-save button-longrunning" type="submit" value="Save condition" />
                <a class="button bicolor icon icon-cog" href="{% url 'wagtailflags:flag_index' flag.name %}">Back to {{ flag.name }}</a>
            </li>
        </ul>
    </form>
{% endblock %}
