from django import forms
from django.utils.translation import gettext_lazy as _
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Div, HTML, Layout, Fieldset, Submit, Field

from events.models import Registration


class RegistrationForm(forms.Form):
    email = forms.CharField(label=_('Email'), required=True)
    first_name = forms.CharField(label=_('First Name'), required=True)
    last_name = forms.CharField(label=_('Password confirmation'), required=True)
    nick_name = forms.CharField(label=_('Nick Name'), required=False)
    phone = forms.CharField(label=_('Phone'), required=False)
    category = forms.CharField(label=_('Category'), required=True)
    text = forms.CharField(label=_('Text'), required=False, widget=forms.Textarea)

    def __init__(self, *args, **kwargs):
        super(RegistrationForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.form_tag = False
        self.helper.form_method = 'post'
        self.helper.form_action = 'submit_survey'
        self.helper.add_input(Submit('submit', 'Submit', css_class='btn btn-primary d-block mx-auto'))


class EmailForm(forms.Form):
    email = forms.CharField(label=_('Email'), required=True)

    def __init__(self, *args, **kwargs):
        super(EmailForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.form_tag = False
        self.helper.form_method = 'post'
        self.helper.form_action = 'submit_survey'
        self.helper.add_input(Submit('submit', 'Submit', css_class='btn btn-primary d-block mx-auto'))


class UpdateRegistrationForm(forms.ModelForm):
    class Meta:
        model = Registration
        fields = ['first_name', 'last_name', 'nick_name', 'phone', 'category', 'is_confirmed', 'is_paid', 'is_finished', 'is_presented', 'start_number', 'chip_id']
        labels = {
            'first_name': _('Krsteni jmeno'),
            'last_name': _('Prijmeni'),
            'nick_name': _('Prezdivka'),
            'phone': _('Telefon'),
            'category': _('Kateogrie'),
            'is_paid': _('Uhradena'),
            'is_finished': _('Dokončena'),
            'is_presented': _('Prezentovana'),
            'start_number': _('Startovni cislo'),
            'chip_id': _('Kod cipu'),
        }
    def __init__(self, *args, **kwargs):
        super(UpdateRegistrationForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.form_tag = False
        self.helper.form_method = 'post'
        self.helper.form_action = 'submit_survey'
        self.helper.add_input(Submit('submit', 'Submit', css_class='btn btn-primary d-block mx-auto'))


class PresentRegistrationForm(forms.ModelForm):
    class Meta:
        model = Registration
        fields = ['start_number', 'chip_id', 'category_object']
        labels = {
            'start_number': _('Startovni cislo'),
            'chip_id': _('Kod cipu'),
            'category_object': _('Kategorie'),
        }

    def __init__(self, *args, **kwargs):
        super(PresentRegistrationForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.form_tag = False
        self.helper.form_method = 'post'
        self.helper.form_action = 'submit_survey'
        self.helper.add_input(Submit('submit', 'Submit', css_class='btn btn-primary d-block mx-auto'))