# -*- 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, 18, 194, 75), 'django.forms.CharField', 'forms.CharField', (), '', False, 'from django import forms\n'), ((195, 16, 195, 60), 'django.forms.IntegerField', 'forms.IntegerField', (), '', False, 'from django import forms\n'), ((32, 26, 32, 35), 'django.utils.translation.ugettext_lazy', '_', ({(32, 28, 32, 34): '"""Name"""'}, {}), "('Name')", True, 'from django.utils.translation import ugettext_lazy as _\n'), ((33, 25, 33, 39), 'django.utils.translation.ugettext_lazy', '_', ({(33, 27, 33, 38): '"""Last Name"""'}, {}), "('Last Name')", True, 'from django.utils.translation import ugettext_lazy as _\n'), ((34, 23, 34, 40), 'django.utils.translation.ugettext_lazy', '_', ({(34, 25, 34, 39): '"""Mobile Phone"""'}, {}), "('Mobile Phone')", True, 'from django.utils.translation import ugettext_lazy as _\n'), ((37, 26, 37, 74), 'django.forms.TextInput', 'forms.TextInput', (), '', False, 'from django import forms\n'), ((38, 25, 38, 73), 'django.forms.TextInput', 'forms.TextInput', (), '', False, 'from django import forms\n'), ((39, 23, 39, 71), 'django.forms.TextInput', 'forms.TextInput', (), '', False, 'from django import forms\n'), ((160, 20, 160, 37), 'django.utils.translation.ugettext_lazy', '_', ({(160, 22, 160, 36): '"""Company Name"""'}, {}), "('Company Name')", True, 'from django.utils.translation import ugettext_lazy as _\n'), ((161, 23, 161, 35), 'django.utils.translation.ugettext_lazy', '_', ({(161, 25, 161, 34): '"""Country"""'}, {}), "('Country')", True, 'from django.utils.translation import ugettext_lazy as _\n'), ((162, 21, 162, 42), 'django.utils.translation.ugettext_lazy', '_', ({(162, 23, 162, 41): '"""Admin user email"""'}, {}), "('Admin user email')", True, 'from django.utils.translation import ugettext_lazy as _\n'), ((163, 24, 163, 37), 'django.utils.translation.ugettext_lazy', '_', ({(163, 26, 163, 36): '"""Password"""'}, {}), "('Password')", True, 'from django.utils.translation import ugettext_lazy as _\n'), ((98, 16, 98, 59), 'django.utils.translation.ugettext_lazy', '_', ({(98, 18, 98, 58): '"""The two password fields didn\'t match."""'}, {}), '("The two password fields didn\'t match.")', True, 'from django.utils.translation import ugettext_lazy as _\n'), ((102, 16, 102, 59), 'django.utils.translation.ugettext_lazy', '_', ({(102, 18, 102, 58): '"""The two password fields didn\'t match."""'}, {}), '("The two password fields didn\'t match.")', True, 'from django.utils.translation import ugettext_lazy as _\n'), ((71, 63, 71, 73), 'django.utils.translation.ugettext_lazy', '_', ({(71, 65, 71, 72): '"""Email"""'}, {}), "('Email')", True, 'from django.utils.translation import ugettext_lazy as _\n'), ((82, 59, 82, 72), 'django.utils.translation.ugettext_lazy', '_', ({(82, 61, 82, 71): '"""Password"""'}, {}), "('Password')", True, 'from django.utils.translation import ugettext_lazy as _\n'), ((87, 59, 87, 79), 'django.utils.translation.ugettext_lazy', '_', ({(87, 61, 87, 78): '"""Retype password"""'}, {}), "('Retype password')", True, 'from django.utils.translation import ugettext_lazy as _\n'), ((117, 63, 117, 73), 'django.utils.translation.ugettext_lazy', '_', ({(117, 65, 117, 72): '"""Email"""'}, {}), "('Email')", True, 'from django.utils.translation import ugettext_lazy as _\n'), ((138, 31, 138, 47), 'django.utils.translation.ugettext_lazy', '_', ({(138, 33, 138, 46): '"""Admin email"""'}, {}), "('Admin email')", True, 'from django.utils.translation import ugettext_lazy as _\n'), ((146, 31, 146, 50), 'django.utils.translation.ugettext_lazy', '_', ({(146, 33, 146, 49): '"""Admin Password"""'}, {}), "('Admin Password')", True, 'from django.utils.translation import ugettext_lazy as _\n'), ((169, 40, 169, 57), 'django.utils.translation.ugettext_lazy', '_', ({(169, 42, 169, 56): '"""Company Name"""'}, {}), "('Company Name')", True, 'from django.utils.translation import ugettext_lazy as _\n'), ((177, 40, 177, 64), 'django.utils.translation.ugettext_lazy', '_', ({(177, 42, 177, 63): '"""Select a country..."""'}, {}), "('Select a country...')", True, 'from django.utils.translation import ugettext_lazy as _\n'), ((184, 40, 184, 61), 'django.utils.translation.ugettext_lazy', '_', ({(184, 42, 184, 60): '"""Admin user email"""'}, {}), "('Admin user email')", True, 'from django.utils.translation import ugettext_lazy as _\n')]