{% extends 'base.html' %}

{% block content %}
<div class="container">
    <div class="row center">
        <div class="col-md-6 offset-md-3">
            {% if edit_choice %}
            <h2>Update choice</h2>
            {% else %}
            <h2>Add new choice</h2>
            {% endif %}
            {% if messages %}
            <ul class="messages">
                {% for message in messages %}
                <li {% if message.tags %} class="{{ message.tags }}" {% endif %}>{{ message }}</li>
                {% endfor %}
            </ul>
            {% endif %}
            <form action="" method="POST">
                {% csrf_token %}
                {% for field in form %}
                <div class="form-group">
                    {{ field.errors }}
                    {{ field.label_tag }}
                    {{ field }}
                </div>
                {% endfor %}
                {% if edit_choice %}
                <button type="submit" class="btn btn-primary">Update</button>
                <a class="btn btn-danger" href="{% url 'polls:choice_delete' choice.id %}" role="button" onclick="return confirm('Are you sure you want to delete this?')">Delete</a>
                {% else %}
                <button type="submit" class="btn btn-primary">Add</button>
                {% endif %}
            </form>
        </div>
    </div>
</div>
{% endblock %}