from django import forms
from django.contrib.auth.models import User
from django.forms import ModelForm,TextInput,NumberInput,EmailInput,PasswordInput,Select,FileInput
from django.contrib.auth.forms import UserChangeForm,UserCreationForm

from user_app.models import User_Profile


class SignUpForm(UserCreationForm):
    username = forms.CharField(max_length=100,label="username",widget=forms.TextInput(
        attrs={'placeholder': 'Write Your username',}))
    email = forms.EmailField(max_length=200,label='email',widget=forms.EmailInput(
        attrs={'placeholder': 'Write Your email'}))
    first_name = forms.CharField(max_length=100,label="first_name",widget=forms.TextInput(
        attrs={'placeholder': 'Write Your first name'}))
    last_name = forms.CharField(max_length=100,label="last_name",widget=forms.TextInput(
        attrs={'placeholder': 'Write Your last name'}))

    class Meta:
        model = User
        fields = ['username','email','first_name',
                  'last_name','password1','password2']
        widgets = {
            'password1': forms.PasswordInput(attrs={'placeholder': 'Enter New Password',
                                                    'class': 'form-control'}),
            'password2': forms.PasswordInput(attrs={'placeholder': 'Enter Repeat password',
                                                    'class': 'form-control'}),
        }


class UserUpdateForm(UserChangeForm):
    class Meta:
        model = User
        fields = ('username','email','first_name','last_name')
        widgets = {
            'username': TextInput(attrs={'class': 'input','placeholder': 'username'}),
            'email': EmailInput(attrs={'class': 'input','placeholder': 'email'}),
            'first_name': TextInput(attrs={'class': 'input','placeholder': 'first_name'}),
            'last_name': TextInput(attrs={'class': 'input','placeholder': 'last_name'}),
        }


CITY = [
    ('Dhaka','Dhaka'),
    ('Mymensign','Mymensign'),
    ('Rajshahi','Rajshahi'),
    ('Rangpur','Rangpur'),
    ('Barisal','Barisal'),
    ('Chottogram','Chottogram'),
    ('Khulna','Khulna'),
]


class ProfileUserUpdate(forms.ModelForm):
    class Meta:
        model = User_Profile
        fields = ('phone','address','city','country','image')
        widgets = {
            'phone': TextInput(attrs={'class': 'input','placeholder': 'phone'}),
            'address': TextInput(attrs={'class': 'input','placeholder': 'address'}),
            'city': Select(attrs={'class': 'input','placeholder': 'city'},choices=CITY),
            'country': TextInput(attrs={'class': 'input','placeholder': 'country'}),
            'image': FileInput(attrs={'class': 'input','placeholder': 'image',}),
        }
