from flask import Flask, render_template, request, flash
from flask_wtf import Form, FlaskForm
# from wtforms import Form
from flask_wtf.csrf import CSRFProtect, CSRFError
from wtforms.validators import DataRequired, ValidationError, Email, EqualTo
from wtforms import DateField, StringField, TextAreaField
from wtforms import BooleanField, StringField, PasswordField, validators, SubmitField, IntegerField


from wtforms_components import TimeField

class LoginForm(FlaskForm):
    username = StringField('Username', validators=[DataRequired()])
    password = PasswordField('Password', validators=[DataRequired()])
    remember_me = BooleanField('Remember Me')
    submit = SubmitField('Sign In')


class BookOrderForm(FlaskForm):
    bookname = StringField('Bookname')
    isbn = StringField('ISBN')
    submit = SubmitField('Choose Quanity to Order')

class QuantityOrderForm(FlaskForm):
    bookname = StringField('Bookname')
    isbn = StringField('ISBN')
    submit = SubmitField('Review Order')


class ConfirmOrderForm(FlaskForm):
    bookname = StringField('Bookname')
    isbn = StringField('ISBN')
    order_quantity = IntegerField('Number to Order')
    submit = SubmitField('Confirm Order')

# REf: http://flask.pocoo.org/docs/0.12/patterns/wtforms/ 
class RegistrationForm(FlaskForm):
    # old working code
    username = StringField('Username', [validators.Length(min=4, max=25)])
    email = StringField('Email Address', [validators.Length(min=6, max=35)])
    password = PasswordField('New Password', [
        validators.DataRequired(),
        validators.EqualTo('confirm', message='Passwords must match')
    ])
    password2 = PasswordField(
        'Repeat Password', validators=[DataRequired(), EqualTo('password')])
    confirm = PasswordField('Repeat Password')
    accept_tos = BooleanField('I accept the TOS', [validators.DataRequired()])
    submit = SubmitField('Register')

    #new code - not working
    # username = StringField('Username', validators=[DataRequired()])
    # email = StringField('Email', validators=[DataRequired(), Email()])
    # password = PasswordField('Password', validators=[DataRequired()])
    # password2 = PasswordField(
    #     'Repeat Password', validators=[DataRequired(), EqualTo('password')])
    # submit = SubmitField('Register')

    # def validate_username(self, username):
    #     user = User.query.filter_by(username=username.data).first()
    #     if user is not None:
    #         raise ValidationError('Please use a different username.')

    # def validate_email(self, email):
    #     user = User.query.filter_by(email=email.data).first()
    #     if user is not None:
    #         raise ValidationError('Please use a different email address.')







