from crispy_forms import helper
from crispy_forms import layout
from django.contrib.auth.forms import AuthenticationForm
from django.contrib.auth.forms import UserCreationForm
from django.utils.translation import gettext_lazy as _

from .models import User


class LoginForm(AuthenticationForm):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.helper = helper.FormHelper()
        self.helper.form_action = 'accounts:login'
        self.helper.form_method = 'post'
        self.helper.add_input(layout.Submit('submit', _('Login')))


class RegisterForm(UserCreationForm):
    class Meta:
        model = User
        fields = ('username', 'first_name', 'last_name', 'email')

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.helper = helper.FormHelper()
        self.helper.form_action = 'accounts:register'
        self.helper.form_method = 'post'
        self.helper.add_input(layout.Submit('submit', _('Register')))