from django import forms
from django.forms import ModelForm, formset_factory

from .models import Preferences


class PreferencesForm(ModelForm):
    class Meta:
        model = Preferences
        fields = ["user", "managed_team_id"]
        widgets = {
            "user": forms.HiddenInput(),
            "managed_team_id": forms.Select(
                choices=(), attrs={"class": "form-control"}
            ),
        }
        labels = {"managed_team_id": "Selected Team"}


class LineupEntryForm(forms.Form):
    member = None
    availability = None
    lineup_entry = None
    gamechanger_player_id = forms.Field(required=False)

    event_lineup_entry_id = forms.Field(required=False)
    event_lineup_id = forms.Field(required=False)
    event_id = forms.Field()
    member_id = forms.Field()
    position_only = forms.BooleanField(initial=False, required=False)
    sequence = forms.IntegerField(required=False)
    label = forms.ChoiceField(
        required=False,
        choices=[
            ("", "--"),
            ("P", "P"),
            ("C", "C"),
            ("1B", "1B"),
            ("2B", "2B"),
            ("3B", "3B"),
            ("SS", "SS"),
            ("LF", "LF"),
            ("CF", "CF"),
            ("RF", "RF"),
            ("DH", "DH"),
            ("DR", "DR"),
            ("EH", "EH"),
        ],
        widget=forms.Select(attrs={"onchange": "positionSelectChanged(this);"}),
    )


LineupEntryFormset = formset_factory(
    LineupEntryForm, can_delete=True, can_order=True, extra=0
)


class EventChooseForm(forms.Form):
    event_id = forms.ChoiceField()

    # checked = forms.BooleanField(required=False)
    # def __init__(self, events, *args, **kwargs):
    #     super(EventChooseForm, self).__init__(*args, **kwargs)
    #     self.fields['foo'].choices = [e.data['id'] for e in events]


LineupEntryFormset = formset_factory(
    LineupEntryForm, can_delete=True, can_order=True, extra=0
)
