from django import forms
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User
from .models import Profile
# from .models import Profile

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

    def clean_email(self):
        email = self.cleaned_data['email']
        if User.objects.filter(email=email).exists():
            raise forms.ValidationError(' user with this email is already registered -- Try loginigin or resting the password')    
        return email

class ProfileEditForm(forms.ModelForm):
    birth = forms.DateField(widget=forms.DateInput(attrs={'type':'date'}))
    class Meta:
        model = Profile
        fields = ['image' ,'gender', 'birth', ]
        widgets = {
            'birth' :forms.DateInput
        }
class UserEditForm(forms.ModelForm):
    class Meta:
        model = User
        fields = ['first_name', 'last_name', 'username']

class SearchUserForm(forms.Form):
    name = forms.CharField()