from django import forms

from .models import Character, Choice


class CharacterCreateForm(forms.Form):
    name = forms.CharField(
        max_length=80,
        widget=forms.TextInput(attrs={"class": "form-control", "placeholder": "Имя ведьмака"}),
    )
    background = forms.ChoiceField(
        choices=Character.BACKGROUND_CHOICES,
        widget=forms.Select(attrs={"class": "form-select"}),
    )


class ChoiceForm(forms.Form):
    choice = forms.ModelChoiceField(
        queryset=Choice.objects.none(),
        empty_label=None,
        widget=forms.RadioSelect,
    )

    def __init__(self, *args, **kwargs):
        choice_queryset = kwargs.pop("choice_queryset", Choice.objects.none())
        super().__init__(*args, **kwargs)
        self.fields["choice"].queryset = choice_queryset
        self.fields["choice"].widget.attrs.update({"class": "choice-radio"})
