from django import forms
from django_select2 import forms as s2forms
from django.utils.translation import gettext_lazy as _

class MasterSignInForm(forms.Form):
    username = forms.CharField(label=_("UserName"), max_length=150, widget=forms.TextInput)
    password = forms.CharField(label=_("Password"), max_length=150, widget=forms.PasswordInput)

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        for field in self.fields.values():
            field.widget.attrs["autocomplete"] = "off"
            field.widget.attrs["placeholder"] = field.label
            field.widget.attrs["required"] = "required"
    required_css_class = "required"

    def clean(self):
        cleaned_data = self.cleaned_data
        username = cleaned_data.get("username")
        password = cleaned_data.get("password")
        if username is None:
            self._errors["username"] = self.error_class([_("Enter a valid username!")])
        if password is None:
            self._errors["password"] = self.error_class([_("Enter your password!")])
        return cleaned_data