from django import forms
from .models import Clientes
from datetime import datetime


class EmailForm(forms.Form):
    RFC = forms.CharField(max_length=13, required=True)
    mes = forms.CharField( max_length=4, required=True)
    email = forms.EmailField(required=False)
    subject = forms.CharField(max_length=100, required=False)
    adjunto = forms.FileField(widget=forms.ClearableFileInput(
        attrs={
        'multiple': True, 
        'accept':'application/pdf,application/vnd.ms-excel',
        

        }
    ), required=False)
    message = forms.CharField(widget=forms.Textarea, required=True)
    class Meta:
        fields = '__all__'

class ClienteForm(forms.ModelForm):
    
    fecha_baja = forms.DateField(        
        required=False,
        initial=datetime.now(),
        input_formats=["%Y-%m-%d"],
        widget=forms.DateInput(attrs={'type':'date'},format="%Y-%m-%d")
    )
    

    class Meta:
        model = Clientes
        fields = ('RFC','Nombre','Activo','fecha_baja', 'email',)

    def clean(self):
        super(ClienteForm,self).clean()
        Activo = self.cleaned_data.get("Activo")
        fecha_baja = self.cleaned_data.get("fecha_baja")
        
        if Activo and fecha_baja:
            self._errors['fecha_baja'] = self.error_class(["El parametro activo no puede estar seleccionado si hay fecha de baja"])        
        return self.cleaned_data