{% extends "base/base.html" %}
{% import "widgets/poll.html" as poll_widget with context %}

{% block title %}
<h1>Gestion des sondages</h1>
{% endblock %}

{% block content %}
<section class="form">
    <h1>Créer un sondage</h1>
    <form action="" method="post">
        <div>
            {{ form.title.label }}
            {{ form.title(size=32) }}
            {% for error in form.title.errors %}
            <span style="color: red;">{{ error }}</span>
            {% endfor %}
        </div>
        <div>
            {{ form.choices.label }}
            <textarea id="{{ form.choices.name }}" name="{{ form.choices.name }}"></textarea>
            {% for error in form.choices.errors %}
            <span class="msgerror">{{ error }}</span>
            {% endfor %}
        </div>
        <div>
            {{ form.type.label }}
            {{ form.type }}
            {% for error in form.type.errors %}
            <span style="color: red;">{{ error }}</span>
            {% endfor %}
        </div>
        <div>
            {{ form.start.label }}
            {{ form.start() }}
            {% for error in form.start.errors %}
            <span class="msgerror">{{ error }}</span>
            {% endfor %}
        </div>
        <div>
            {{ form.end.label }}
            {{ form.end() }}
            {% for error in form.end.errors %}
            <span class="msgerror">{{ error }}</span>
            {% endfor %}
        </div>
        {{ form.hidden_tag() }}
        <div>{{ form.submit(class_="bg-ok") }}</div>
    </form>
</section>

<section>
    <h1>Mes sondages</h1>
    <div>
        {% for p in polls %}
        {{ poll_widget.wpoll(p) }}
        <a href="{{ url_for('poll_delete', poll_id=p.id) }}">Supprimer le sondage</a>
        {% endfor %}
    </div>
</section>
{% endblock %}
