<?php

namespace App\Form;

use App\Entity\Sponsor;
use App\Entity\EventSponsor;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;

class EventSponsorType extends AbstractType
{
    public function __construct(private EntityManagerInterface $manager) {
        
    }

    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $sponsors = $this->manager->getRepository(Sponsor::class)->findAllActive(true, false);

        $builder->add('sponsor', ChoiceType::class, [
                        'choices'  => $sponsors,
                        'choice_value' => 'id',
                        'choice_label' => 'name',
                        'required' => true
                ])
                ->add('url', TextType::class, ['required' => true])
                ->add('deleted', HiddenType::class)
                ->add('main', HiddenType::class);
    }

    public function configureOptions(OptionsResolver $resolver): void
    {
        $resolver->setDefaults([
            'data_class' => EventSponsor::class,
            "allow_extra_fields" => true
        ]);
    }
}
