from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField, TextAreaField, SelectField, \
    BooleanField
from wtforms.fields.datetime import DateTimeField
from wtforms.validators import InputRequired, Optional

from datetime import datetime, timedelta

class PollForm(FlaskForm):
    title = StringField(
        'Question',
        validators=[
            InputRequired(),
        ]
    )
    choices = TextAreaField(
        'Choix (un par ligne)',
        validators=[
            InputRequired(),
            # TODO: add a validator to check if there is at least one choice
        ]
    )
    type = SelectField(
        'Type',
        choices=[
            ('simplepoll', 'Réponse unique'),
            ('multiplepoll', 'Réponses multiples')
        ]
    )
    start = DateTimeField(
        'Début',
        default=datetime.now(),
        validators=[
            Optional()
        ]
    )
    end = DateTimeField(
        'Fin',
        default=datetime.now() + timedelta(days=1),
        validators=[
            Optional()
        ]
    )
    submit = SubmitField(
        'Créer le sondage'
    )

class DeletePollForm(FlaskForm):
    delete = BooleanField(
        'Confirmer la suppression',
        validators=[
            InputRequired(),
        ],
        description='Attention, cette opération est irréversible !'
    )
    submit = SubmitField(
        'Supprimer le sondage'
    )
