from django import forms
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User
from django.contrib.auth.forms import AuthenticationForm

class SignUpForm(UserCreationForm):
	username = forms.EmailField(max_length=254, required=True, widget=forms.EmailInput(attrs={'class': 'form-control', 'placeholder': 'Email'}))
	first_name = forms.CharField(max_length=30, required=True, widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': 'First Name'}))
	last_name = forms.CharField(max_length=30, required=True, widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': 'Last Name'}))
	email_pref = forms.BooleanField(required=False, help_text="Sign up to Email", widget=forms.CheckboxInput(attrs={'class': 'd-inline form-check mt-2'}))
	sms_pref = forms.BooleanField(required=False, help_text="Sign up to SMS", widget=forms.CheckboxInput(attrs={'class': 'd-inline form-check mb-2'}))

	class Meta:
		model = User
		fields = ('username', 'first_name', 'last_name', 'password1', 'password2')

	def __init__(self, *args, **kwargs):
		super(SignUpForm, self).__init__(*args, **kwargs)

		self.fields['password1'].widget = forms.PasswordInput(attrs={'class': 'form-control', 'placeholder': 'Password'})
		self.fields['password2'].widget = forms.PasswordInput(attrs={'class': 'form-control', 'placeholder': 'Confirm Password'})


class LoginForm(AuthenticationForm):

	username = forms.CharField(widget=forms.TextInput(attrs={'class':'form-control mb-2', 'placeholder': 'Email'}))
	password = forms.CharField(widget=forms.PasswordInput(attrs={'class':'form-control mb-4', 'placeholder': 'Password'}))

	def __init__(self, *args, **kwargs):
		super(LoginForm, self).__init__(*args, **kwargs)

		self.fields['username'].label = "Email"
		self.fields['username'].label = False
		self.fields['password'].label = False