from django import forms
from django.contrib.auth.forms import UserCreationForm, UserChangeForm
from src.models import ContactMessage, UserAccount, dashboardpicture 

class DateInput(forms.DateInput):
    input_type = 'date'


class IndividualMemberForm(forms.ModelForm):
   #password = forms.CharField(widget=forms.PasswordInput)

  class Meta:
     model = UserAccount
     exclude = ('typecompte', 'date_joined', 'last_login', 'is_admin', 'is_active', 'is_staff', 'is_superuser', 'password', 'groups', 'user_permissions', 'username', 'update_date', 'picture', 'adress',
                'birthday')
     
     labels = {'tel':'' }

  #password1 = 'adnj'#forms.CharField(label='Password', widget=forms.PasswordInput)
  #password2 = 'adnj'#forms.CharField(label='Repeat Password', widget=forms.PasswordInput, help_text=("Enter the same password as above, for verification."))

     
  #def clean_password2(self):
   #     password1 = 'adnj'#self.cleaned_data.get('password1')
   #     password2 = 'adnj' #self.cleaned_data.get('password2')

   #     if password1 and password2 and password1 != password2:
   #         raise forms.ValidationError('Passwords don\'t match')
   #     return password2

  def save(self, commit=True):
        password1 = "fnpss"
        user = super(IndividualMemberForm, self).save(commit=False)
        #user.set_password(self.cleaned_data['password1'])
        user.set_password(password1)
       
        if commit:
            user.save()
        return user
  
class DashImageForm(forms.ModelForm):
   
   class Meta:
    model = dashboardpicture
    fields = ['textdisplay1', 'textdisplay2', 'textdisplay3', 'picture']
    labels = {'textdisplay1':'',  'textdisplay2':'', 'textdisplay3':'', 'picture':''}


class ContactForm(forms.ModelForm):
    class Meta:
        model = ContactMessage
        fields = ['name', 'email', 'subject', 'message']

    def clean_message(self):
        message = self.cleaned_data.get('message', '').strip()
        if len(message.split()) < 30:
            raise forms.ValidationError(
                "Le message doit contenir au moins 30 mots."
            )
        return message

    def clean_subject(self):
        subject = self.cleaned_data.get('subject', '').strip()
        if len(subject.split()) < 5:
            raise forms.ValidationError(
                "Le sujet doit contenir au moins 5 mots."
            )
        return subject



class ActualiteNewsForm(forms.Form):  
   name= forms.CharField(required=True, max_length=255 , label='User Name' ,widget=forms.TextInput(attrs={'style': 'height: 30px;','class': 'form-control'}))
   title= forms.CharField(required=True, max_length=255 , label='News Title' ,widget=forms.TextInput(attrs={'style': 'height: 30px;','class': 'form-control'}))
   shortdes = forms.CharField(required=True,max_length=800,label=' Short Description', widget=forms.TextInput(attrs={'style': 'width: 400px;','class': 'form-control'}))
   longdes = forms.CharField(required=False,max_length=2500,label='Long Description',widget=forms.TextInput(attrs={'style': 'width: 400px;','class': 'form-control'}))
   status = forms.BooleanField(required=False, label='New Publication',widget=forms.CheckboxInput(attrs={'class': 'form-check-input'}))
