from datetime import datetime

from django import forms

from BasicData.models import *


class EnseignantLoginForm(forms.ModelForm):
    email = forms.EmailField(max_length=255, label="Email", help_text="Veillez entrer voter adresse email",
                             widget=forms.EmailInput(attrs={'class': 'form-control'}), required=True)
    password = forms.CharField(label='Mot de passe', widget=forms.PasswordInput(attrs={'class': 'form-control'}),
                               required=True)

    class Meta:
        model = Enseignant
        fields = ['email', 'password']


class DeliberationForm(forms.ModelForm):
    annee = forms.DateField(label="Annee", widget=forms.DateInput(attrs={'class': 'form-control'}), required=True)
    ue = forms.ModelChoiceField(queryset=Ue.objects, label="Ue")
    note = forms.FloatField(label="Barre", widget=forms.NumberInput(attrs={'class': 'form-control'}), required=True)

    class Meta:
        model = Deliberation
        fields = ['note']


class EvaluationForm(forms.ModelForm):
    class Meta:
        model = Evaluation
        exclude = ('ecue', 'enseignant', 'annee', 'is_noted')
        widgets = {
            'typeEvaluation': forms.Select(attrs={'class': 'form-control'}),
            'session': forms.Select(attrs={'class': 'form-control'}),
            'libelle': forms.TextInput(attrs={'class': 'form-control', 'placeholder': 'Nommez l\'évaluation'}),
        }


# NOTE FORM
class NoteForm(forms.ModelForm):
    class Meta:
        model = Note
        fields = ('note', 'etudiant', 'evaluation', 'annee')


class DeliberationsForm(forms.ModelForm):
    class Meta:
        model = Deliberation
        fields = ('session', 'note','annee','ecue')


class DeliberationsUeForm(forms.ModelForm):
    class Meta:
        model = DeliberationUe
        fields = ('session', 'note','annee')


class CsvModelForm(forms.ModelForm):
    typeEvaluation = forms.CharField()
    session = forms.CharField()
    libelle = forms.CharField()
    annee = forms.CharField()

    class Meta:
        model = Csv
        fields = ('file_name', 'typeEvaluation', 'session', 'libelle')

class AddEvalForm(forms.Form):
    typeEvaluation = forms.CharField()
    session = forms.CharField()
    libelle = forms.CharField()
    annee = forms.CharField()


class AddNoteForm(forms.ModelForm):
    class Meta:
        model = Note
        fields = ('note','evaluation','etudiant')



class AddEcueForm(forms.Form):
    ecue = forms.CharField()
    annee = forms.CharField()

class SeanceFilterForm(forms.Form):
    ecue = forms.CharField()
    annee = forms.CharField()
    debut = forms.DateField()
    fin = forms.DateField()
    status = forms.CharField()

class SeanceFilterForm2(forms.Form):
    ecue = forms.CharField()
    ufr = forms.CharField()
    enseignant = forms.CharField()
    annee = forms.CharField()
    debut = forms.DateField()
    status = forms.CharField()
    fin = forms.DateField()


class ProgramEcueForm(forms.Form):
    ecue = forms.CharField()
    niveau = forms.CharField()
    #enseignant = forms.CharField()
    annee = forms.CharField()
    periode = forms.CharField()
    # Horaire
    lundi = forms.CharField(required=False)
    mardi = forms.CharField(required=False)
    mercredi = forms.CharField(required=False)
    jeudi = forms.CharField(required=False)
    vendredi = forms.CharField(required=False)
    samedi = forms.CharField(required=False)
    # Type
    type_lun = forms.CharField(required=False)
    type_mar = forms.CharField(required=False)
    type_mer = forms.CharField(required=False)
    type_jeu = forms.CharField(required=False)
    type_ven = forms.CharField(required=False)
    type_sam = forms.CharField(required=False)
    # Mode
    mode_lun = forms.CharField(required=False)
    mode_mar = forms.CharField(required=False)
    mode_mer = forms.CharField(required=False)
    mode_jeu = forms.CharField(required=False)
    mode_ven = forms.CharField(required=False)
    mode_sam = forms.CharField(required=False)
    # Url
    url_lun = forms.CharField(required=False)
    url_mar = forms.CharField(required=False)
    url_mer = forms.CharField(required=False)
    url_jeu = forms.CharField(required=False)
    url_ven = forms.CharField(required=False)
    url_sam = forms.CharField(required=False)


class EmploiDTFilterForm(forms.Form):
    ecue = forms.CharField()
    niveau = forms.CharField()


class ValiditeUFRFilterForm(forms.Form):
    ufr = forms.CharField()
    niveau = forms.CharField()
    periode = forms.CharField()


class CustomMSCF(forms.ModelMultipleChoiceField):
    def label_from_instance(self, salle):
        return str(salle.libelle)

class AddMultiSalleForm(forms.ModelForm):
    class Meta:
        model = EmploiDuTemps2
        #fields =['salle2_lun','salle2_mar','salle2_mer','salle2_jeu','salle2_ven','salle2_sam']
        fields =['salle_lun','salle_mar','salle_mer','salle_jeu','salle_ven','salle_sam']

        # salle_lun = CustomMSCF(
        #     queryset=Salle.objects.all(),
        #     widget=forms.CheckboxSelectMultiple
        # )
        # salle_mar = CustomMSCF(
        #     queryset=Salle.objects.all(),
        #     widget=forms.CheckboxSelectMultiple
        # )
        # salle_mer = CustomMSCF(
        #     queryset=Salle.objects.all(),
        #     widget=forms.CheckboxSelectMultiple
        # )
        # salle_jeu = CustomMSCF(
        #     queryset=Salle.objects.all(),
        #     widget=forms.CheckboxSelectMultiple
        # )
        # salle_ven = CustomMSCF(
        #     queryset=Salle.objects.all(),
        #     widget=forms.CheckboxSelectMultiple
        # )
        # salle_sam = CustomMSCF(
        #     queryset=Salle.objects.all(),
        #     widget=forms.CheckboxSelectMultiple
        # )


class AddSalleForm(forms.Form):
    lundi = forms.CharField(required=False)
    lundi_1 = forms.MultipleChoiceField()
    mardi = forms.CharField(required=False)
    mercredi = forms.CharField(required=False)
    jeudi = forms.CharField(required=False)
    vendredi = forms.CharField(required=False)
    samedi = forms.CharField(required=False)


class AddPeriodeForm(forms.ModelForm):
    class Meta:
        model = Validite
        fields = ('dateDebut','dateFin')


class ChoosePeriodeForm(forms.Form):
    periode = forms.CharField()


class AddSalleForm2(forms.Form):
    Progid = forms.CharField()
    salle = forms.CharField()
    jour = forms.CharField()


class PvFilterForm(forms.Form):
    annee = forms.CharField()
    niveau = forms.CharField()
    semestre = forms.CharField()
    #ufr = forms.CharField()

class DecArchiveForm(forms.Form):
    idr = forms.CharField()


class DecisionFinaleForm(forms.Form):
    status = forms.CharField()


class StatUeFilter(forms.Form):
    ueval = forms.CharField()


class AnneeFilterForm(forms.Form):
    libelle = forms.CharField()


class SyllabusEcueAddForm(forms.ModelForm):
    class Meta:
        model = SyllabusEcue
        fields = "__all__"


class AddSeanceForm(forms.ModelForm):
    adecue = forms.CharField()
    class Meta:
        model = SeanceCours
        fields = ('type_cours','salle','annee','date','debut','fin','contenu')



class EditSeanceForm(forms.ModelForm):
    #adecue = forms.CharField()
    class Meta:
        model = SeanceCours
        fields = ('type_cours','salle','annee','date','debut','fin','contenu','ecue')


class AddInactiveUeForm(forms.ModelForm):
    class Meta:
        model = InactiveUe
        fields ='__all__'


class CompensationFilterForm(forms.Form):
    annee = forms.CharField()
    niveau = forms.CharField()
    symbole = forms.CharField()
    moyenne = forms.FloatField(initial=10.00)
    taux = forms.FloatField(initial=80.00)


class AddCompNoteForm(forms.ModelForm):
    ue = forms.CharField()
    class Meta:
        model = Compensation
        fields = ('note',)


class ObjIdForm(forms.Form):
    objID = forms.CharField()


class TypeCoursAddForm(forms.ModelForm):
    class Meta:
        model = PsTypeCours
        fields = ('libelle','prerequis')


class TypePubAddForm(forms.ModelForm):
    class Meta:
        model = PsTypePublication
        fields = ('libelle',)


class EquipeAddForm(forms.ModelForm):
    class Meta:
        model = PsGroupeRech
        fields = ('libelle','institut')


class PsCourAddForm(forms.ModelForm):
    class Meta:
        model = PsCours2
        exclude = ('enseignant',)


class SupportAddForm(forms.ModelForm):
    obj = forms.CharField()
    class Meta:
        model = PsPJoint
        fields = ('fichier','libelle')


class PubAddForm(forms.ModelForm):
    class Meta:
        model = PsPublication
        exclude = ('enseignant','type_pub')


class LogicielAddForm(forms.ModelForm):
    class Meta:
        model = PsLogiciel
        exclude = ('enseignant',)


class EnseignantEditForm(forms.ModelForm):
    class Meta:
        model = Enseignant
        fields=('nom','prenoms','sexe','datenaiss','lieunaiss','phone','email','civilite','profession','autre_profession',
                'nationalite','groupe_sanguin','nb_enfant','sit_matri','interet','specialite','grade','adresse','ufr','statut')


class AddGroupForm(forms.ModelForm):
    class Meta:
        model = GroupTravail
        fields = '__all__'


class addGroupEnsForm(forms.Form):
    enseignant = forms.CharField()


class addGroupEtForm(forms.Form):
    etudiant = forms.CharField()


class GroupEtudImportForm(forms.ModelForm):
    class Meta:
        model = Csv
        fields = ('file_name',)


class FlashInfoAddForm(forms.ModelForm):
    class Meta:
        model = FlashInfo
        fields = '__all__'


class NoteEditForm(forms.ModelForm):
    obj = forms.CharField()
    class Meta:
        model = Note
        fields = ('note',)
