from django.contrib.auth import get_user_model
from django.contrib.auth.forms import UserCreationForm, PasswordChangeForm
from django import forms
from django.forms import widgets

from accounts.models import Profile


class RegisterForm(UserCreationForm):
    class Meta(UserCreationForm.Meta):
        model = get_user_model()
        fields = (
            'username', 'password1', 
            'password2', 'first_name', 
            'last_name', 'email',
        )


class PrimaryRegisterForm(forms.ModelForm):
    class Meta:
        model = get_user_model()
        fields = (
            'username', 'first_name',
            'last_name', 'email',
        )


class SecondaryRegisterForm(UserCreationForm):
    id = forms.IntegerField(widget=forms.HiddenInput())

    class Meta(UserCreationForm.Meta):
        model = get_user_model()
        fields = ('id', 'password1', 'password2')


class UserUpdateForm(forms.ModelForm):
    class Meta:
        model = get_user_model()
        fields = ('first_name', 'last_name', 'email')
        widgets = {
            'first_name': widgets.TextInput(attrs={
                'class': 'form-control mb-3',
            }),
            'last_name': widgets.TextInput(attrs={
                'class': 'form-control mb-3',
            }),
            'email': widgets.EmailInput(attrs={
                'class': 'form-control mb-3',
            }),
        }


class ProfileUpdateForm(forms.ModelForm):
    class Meta:
        model = Profile
        fields = ('birth_date', 'avatar')
        widgets = {
            'birth_date': widgets.DateInput(attrs={
                'class': 'form-control mb-3',
                'type': 'date',
            }),
            'avatar': widgets.FileInput(attrs={
                'class': 'form-control mb-3',
            }),
        }


class ChangePasswordForm(PasswordChangeForm):
    widgets = {
        'new_password1': widgets.PasswordInput(attrs={
            'class': 'form-control mb-3',
        }),
        'new_password2': widgets.PasswordInput(attrs={
            'class': 'form-control mb-3',
        }),
        'old_password': widgets.PasswordInput(attrs={
            'class': 'form-control mb-3',
        }),
    }
