from django.utils.translation import ugettext_lazy as _
from django import forms
from .utils import ldap_get_unites, ldap_get_etablissements, sso_attributes


AFFILIATION_CHOICES = (
    ('researcher', _('Researcher')),
    ('teacher', _('Teacher')),
    ('emeritus', _('Emeritus')),
    ('student', _('Student')),
    ('staff', _('Staff')),
    ('registered-reader', _('Registered-reader')),
)

AFFECTATION_CHOICES = (
    ('B', 'Bleue'),
    ('V', 'Verte'),
    ('J', 'Jaune'),
    ('N', 'Noire'),
    ('R', 'Rouge'),
)

EMP_CORPS_CHOICES = (
    ('PROFESSEUR ASSOCIE', _('ASSOCIATE TEACHER')),
    ('PROFESSEUR DES UNIVERSITES', _('UNIVERSITY TEACHER')),
    ('MAITRE DE CONFERENCES DES UNIVERSITES', _('UNIVSERITY LECTURER')),

)

ETABLISSEMENT_CHOICES = ()

UNITE_CHOICES = ()

class RegistrationForm(forms.Form):

    user_help_msg = ''
    user_nickname = ''

    def __init__(self, *args, **kwargs):
        super(RegistrationForm, self).__init__(*args, **kwargs)
        self.user_nickname = kwargs['initial'].get('user_nickname', '')
        self.user_help_msg = kwargs['initial'].get('user_help_msg', '')

        for field in sso_attributes:
            if  kwargs['initial'].get(field,'') != '':
                self.fields[field].widget.attrs['readonly'] = True

    nom = forms.CharField(max_length=100, label=_("Last name"))
    prenom = forms.CharField(max_length=100, label=_("First name"))
    email = forms.CharField(max_length=100, label=_("Email address"))

    # Attributes from the Internet2 eduPerson and RENATER SupAnn2009 specifications.
    #  ep_* -> eduPerson attributes:
    ep_principal_name = forms.CharField(required=False,
                                        max_length=100,
                                        label="eduPersonPrincipalName")
    ep_primary_affiliation = forms.ChoiceField(required=False,
                                               choices=AFFILIATION_CHOICES,
                                               label=_("Affiliation")) # eduPersonPrimaryAffiliation
    ep_affiliation = forms.MultipleChoiceField(required=False,
                                               choices=AFFILIATION_CHOICES,
                                               label=_("Affiliations")) # eduPersonPrimaryAffiliation

    # s_* -> supannPerson attributes:
    s_etablissement = forms.CharField(max_length=100, label=_("Institution")) # supannEtablissement
    s_entite_affectation_principale = forms.ChoiceField(required=False,
                                                        choices=AFFECTATION_CHOICES,
                                                        label=_("Assignment unit")) # supannEntiteAffectationPrincipale
    s_entite_affectation = forms.MultipleChoiceField(required=False,
                                                     choices=AFFECTATION_CHOICES,
                                                     label=_("Assignment units")) # supannEntiteAffectation
    s_emp_corps = forms.ChoiceField(choices=EMP_CORPS_CHOICES, label=_("Source entity")) # supannEmpCorps
    s_liste_rouge = forms.BooleanField(initial=True, required=False, label=_("Unlist contact information")) # supannListeRouge

    # hote_* -> host attributes:
    hote_prenom = forms.CharField(max_length=100, label=_("First name"))
    hote_nom = forms.CharField(max_length=100, label=_("Last name"))
    hote_etablissement  = forms.ChoiceField(required=False,
                                            choices=ldap_get_etablissements(),
                                            label=_("Institution"))
    hote_unite  = forms.ChoiceField(required=False,
                                    choices=ldap_get_unites(),
                                    label=_("Entity or unit"))

    class Meta:
        widgets= {'form' : forms.HiddenInput()}
