# -*- coding: utf-8 -*-
"""
Global app forms
"""
# Standard Library
import re

# Django Library
from django import forms
from django.contrib.auth.forms import UserChangeForm, UserCreationForm
from django.utils.translation import ugettext_lazy as _

# Thirdparty Library
from dal import autocomplete

# Localfolder Library
from ..models import PyCompany, PyCountry, PyUser
from .partner import PartnerForm


class PerfilForm(forms.ModelForm):
    """Class to update the user profile on the system
    """
    class Meta:
        model = PyUser
        fields = (
            'first_name',
            'last_name',
            'celular',
        )
        labels = {
            'first_name': _('Name'),
            'last_name': _('Last Name'),
            'celular': _('Mobile Phone'),
        }
        widgets = {
            'first_name': forms.TextInput(attrs={'class': 'form-control'}),
            'last_name': forms.TextInput(attrs={'class': 'form-control'}),
            'celular': forms.TextInput(attrs={'class': 'form-control'}),
        }


class PersonaChangeForm(UserChangeForm):
    """for something will be
    """
    class Meta(UserChangeForm.Meta):
        model = PyUser
        fields = (
            'email',
            'is_superuser',
            'is_staff',
            'is_active',
            'last_login',
            'date_joined',
            'first_name',
            'last_name',
        )


# ========================================================================== #
class PasswordRecoveryForm(forms.ModelForm):
    """To send the account recovery correction
    """
    class Meta():
        model = PyUser
        fields = (
            'email',
        )
        widgets = {
            'email': forms.EmailInput(
                attrs={'class': 'form-control', 'placeholder': _('Email')}
            ),
        }


# ========================================================================== #
class PasswordSetForm(forms.Form):
    """To send the account recovery correction
    """
    password1 = forms.CharField(
        widget=forms.PasswordInput(
            attrs={'class': 'form-control', 'placeholder': _('Password')}
        )
    )
    password2 = forms.CharField(
        widget=forms.PasswordInput(
            attrs={'class': 'form-control', 'placeholder': _('Retype password')}
        )
    )

    def clean(self):
        super().clean()
        password1 = self.cleaned_data.get('password1')
        password2 = self.cleaned_data.get('password2')
        print('entre8888')
        if password1 != password2:
            raise forms.ValidationError(
                _('The two password fields didn\'t match.')
            )
        if password1 != password2:
            raise forms.ValidationError(
                _('The two password fields didn\'t match.')
            )


class PersonaCreationForm(UserCreationForm):
    """This form class renders the record sheet of
    users
    """
    class Meta(UserCreationForm.Meta):
        model = PyUser
        fields = (
            'email',
        )
        widgets = {
            'email': forms.EmailInput(
                attrs={'class': 'form-control', 'placeholder': _('Email')}
            ),
        }


class AvatarForm(forms.ModelForm):
    """Class to update the user profile on the system
    """
    class Meta:
        model = PyUser
        fields = (
            'avatar',
        )


class InitForm(forms.ModelForm):
    """From of OMegaERP initializacion
    """
    email = forms.EmailField(
        widget=forms.EmailInput(
            attrs={
                'placeholder': _('Admin email')
            }
        )
    )
    password = forms.CharField(
        max_length=100,
        widget=forms.PasswordInput(
            attrs={
                'placeholder': _('Admin Password')
            }
        )
    )

    class Meta:
        model = PyCompany
        fields = [
            'name',
            'country',
            'email',
            'password'
        ]
        labels = {
            'name': _('Company Name'),
            'country': _('Country'),
            'email': _('Admin user email'),
            'password': _('Password'),
        }
        widgets = {
            'name': forms.TextInput(
                attrs={
                    'class': 'form-control',
                    'data-placeholder': _('Company Name'),
                    'style': 'width: 100%',
                },
            ),
            'country': autocomplete.ModelSelect2(
                url='PyCountry:autocomplete',
                attrs={
                    'class': 'form-control',
                    'data-placeholder': _('Select a country...'),
                    'style': 'width: 100%',
                },
            ),
            'email': forms.EmailInput(
                attrs={
                    'class': 'form-control',
                    'data-placeholder': _('Admin user email'),
                    'style': 'width: 100%',
                },
            ),
        }


class ActivateForm(forms.Form):
    """To activate or deactivate an object in OmegaERP
    """
    object_name = forms.CharField(max_length=100, widget=forms.HiddenInput)
    object_pk = forms.IntegerField(widget=forms.HiddenInput)
[(194, 'django.forms.CharField', 'forms.CharField', False, 'from django import forms\n'), (195, 'django.forms.IntegerField', 'forms.IntegerField', False, 'from django import forms\n'), (32, 'django.utils.translation.ugettext_lazy', '_', True, 'from django.utils.translation import ugettext_lazy as _\n'), (33, 'django.utils.translation.ugettext_lazy', '_', True, 'from django.utils.translation import ugettext_lazy as _\n'), (34, 'django.utils.translation.ugettext_lazy', '_', True, 'from django.utils.translation import ugettext_lazy as _\n'), (37, 'django.forms.TextInput', 'forms.TextInput', False, 'from django import forms\n'), (38, 'django.forms.TextInput', 'forms.TextInput', False, 'from django import forms\n'), (39, 'django.forms.TextInput', 'forms.TextInput', False, 'from django import forms\n'), (160, 'django.utils.translation.ugettext_lazy', '_', True, 'from django.utils.translation import ugettext_lazy as _\n'), (161, 'django.utils.translation.ugettext_lazy', '_', True, 'from django.utils.translation import ugettext_lazy as _\n'), (162, 'django.utils.translation.ugettext_lazy', '_', True, 'from django.utils.translation import ugettext_lazy as _\n'), (163, 'django.utils.translation.ugettext_lazy', '_', True, 'from django.utils.translation import ugettext_lazy as _\n'), (98, 'django.utils.translation.ugettext_lazy', '_', True, 'from django.utils.translation import ugettext_lazy as _\n'), (102, 'django.utils.translation.ugettext_lazy', '_', True, 'from django.utils.translation import ugettext_lazy as _\n'), (71, 'django.utils.translation.ugettext_lazy', '_', True, 'from django.utils.translation import ugettext_lazy as _\n'), (82, 'django.utils.translation.ugettext_lazy', '_', True, 'from django.utils.translation import ugettext_lazy as _\n'), (87, 'django.utils.translation.ugettext_lazy', '_', True, 'from django.utils.translation import ugettext_lazy as _\n'), (117, 'django.utils.translation.ugettext_lazy', '_', True, 'from django.utils.translation import ugettext_lazy as _\n'), (138, 'django.utils.translation.ugettext_lazy', '_', True, 'from django.utils.translation import ugettext_lazy as _\n'), (146, 'django.utils.translation.ugettext_lazy', '_', True, 'from django.utils.translation import ugettext_lazy as _\n'), (169, 'django.utils.translation.ugettext_lazy', '_', True, 'from django.utils.translation import ugettext_lazy as _\n'), (177, 'django.utils.translation.ugettext_lazy', '_', True, 'from django.utils.translation import ugettext_lazy as _\n'), (184, 'django.utils.translation.ugettext_lazy', '_', True, 'from django.utils.translation import ugettext_lazy as _\n')]