<?php

namespace App\User\Framework\Form;

use App\User\Database\CodecList;
use App\User\Database\CountryLanguages;
use App\User\Database\ProviderList;
use App\User\Database\QualityList;
use App\User\Database\ResolutionList;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class GettingStartedFilterForm extends AbstractType
{

    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $this->addChoiceField($builder, 'language', CountryLanguages::asSelectOptions());
        $this->addChoiceField($builder, 'quality', QualityList::asSelectOptions());
        $this->addChoiceField($builder, 'provider', ProviderList::asSelectOptions());
        $this->addChoiceField($builder, 'resolution', ResolutionList::asSelectOptions());
        $this->addChoiceField($builder, 'codec', CodecList::asSelectOptions());;
    }

    private function addChoiceField(FormBuilderInterface $builder, string $fieldName, array $choices): void
    {
        $question = [
            'attr' => ['class' => 'w-full text-input mb-4'],
            'label_attr' => ['class' => 'w-full block font-semibold'],
            'choices' => $this->addDefaultChoice($choices),
        ];
        $builder->add($fieldName, ChoiceType::class, $question);
    }

    public function configureOptions(OptionsResolver $resolver): void
    {
        $resolver->setDefaults([]);
    }

    private function addDefaultChoice(array $choices): iterable
    {
        return ['n/a' => null] + $choices;
    }
}
