from django import forms
from django.contrib.auth.forms import UserCreationForm, AuthenticationForm, UsernameField, PasswordChangeForm, SetPasswordForm, PasswordResetForm
from django.contrib.auth.models import User
from .models import *

class LoginForm(AuthenticationForm):
    username = UsernameField(widget=forms.TextInput(attrs={
        'autofocus' : "True",
        'class':"form-control",
        'autocomplete': 'off'
    }))
    password = forms.CharField(widget=forms.PasswordInput(attrs={
        'autocomplete':'current-password',
        'class':'form-control',
        'autocomplete': 'off'
    }))
    

class CustomerRegistrationForm(UserCreationForm):
    username = forms.CharField(widget=forms.TextInput(attrs={'autofocus': 'True','autocomplete': 'off',  "class":"form-control"}))
    email = forms.EmailField(widget=forms.EmailInput(attrs={'autocomplete': 'off', 'class':'form-control'}))
    password1 = forms.CharField(widget=forms.PasswordInput(attrs={'class':'form-control'}), label="Password")
    password2 = forms.CharField(widget=forms.PasswordInput(attrs={'class':'form-control'}), label="Confirm Password")
    
    class Meta:
        model = User
        fields = ['username', 'email', 'password1','password2']
        
class MyPasswordChangeForm(PasswordChangeForm):
    old_password = forms.CharField(label='Old Password', widget=forms.PasswordInput(attrs={'autofocus': 'True', 'autocomplete': 'current-password', 'class':'form-control'}))
    new_password1 = forms.CharField(label='New Password', widget=forms.PasswordInput(attrs={'autocomplete':'current-password', 'class':'form-control'}))
    new_password2= forms.CharField(label='Confirm Password', widget=forms.PasswordInput(attrs={'autocomplete':'current-password', 'class':'form-control'}))
        
class MySetPasswordForm(SetPasswordForm):
    new_password1 = forms.CharField(label='New Password', widget=forms.PasswordInput(attrs={'autocomplete':'current-password', 'class':'form-control'}))
    new_password2 = forms.CharField(label='Confirm New Password', widget=forms.PasswordInput(attrs={'autocomplete':'current-password', 'class':'form-control'}))
        
class MyPasswordResetForm(PasswordResetForm):
    email = forms.EmailField(widget=forms.EmailInput(attrs={'class':'form-control'}))

class CustomerProfileForm(forms.ModelForm):
    class Meta:
        model = Customer
        fields=['name','locality','city','mobile','state','zipcode']
        widgets = {
            'name': forms.TextInput(attrs={'class':'form-control', 'autocomplete': 'off'}),
            'locality': forms.TextInput(attrs={'class':'form-control', 'autocomplete': 'off'}),
            'city': forms.TextInput(attrs={'class':'form-control', 'autocomplete': 'off'}),
            'mobile': forms.NumberInput(attrs={'class':'form-control', 'autocomplete': 'off'}),
            'state': forms.Select(attrs={'class':'form-control', 'autocomplete': 'off'}),
            'zipcode': forms.NumberInput(attrs={'class':'form-control', 'autocomplete': 'off'}),
        }
        
class ProductForm(forms.ModelForm):
    class Meta:
        model = Product
        fields = ['title', 'selling_price', 'discount', 'description', 'categories', 'product_image']
        widgets = {
            'title': forms.TextInput(attrs={'class': 'form-control'}),
            'selling_price': forms.NumberInput(attrs={'class': 'form-control'}),
            'discount': forms.NumberInput(attrs={'class': 'form-control'}),
            'description': forms.Textarea(attrs={'class': 'form-control', 'rows': 5}),
            'categories': forms.Select(attrs={'class': 'form-control'}),
            'product_image': forms.FileInput(attrs={'class': 'form-control'}),
        }
        
class subCateForm(forms.ModelForm):
    class Meta:
        model = SubCate
        fields = ["name"]
        widgets = {
            'name': forms.TextInput(attrs={'class': 'form-control'}),
        }