<?php

namespace App\Form;

use App\Entity\Filial;
use App\Bundle\Infoclinica\Region;
use App\Entity\Specialist;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Doctrine\ORM\EntityRepository;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;

class SpecialistAdminSearchType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('name', null, [
                'required' => false
            ])
            ->add('filial', EntityType::class, [
                'class' => Filial::class,
                'query_builder' => function (EntityRepository $er) {
                    return $er
                        ->createQueryBuilder('f')
                        ->orderBy('f.id', 'ASC');
                },
                'choice_label' => 'name',
                'mapped' => false,
                'multiple' => true, 
                'empty_data' => [],
                'required' => false
            ])
        ;
    }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults([
            'data_class' => Specialist::class,
        ]);
    }
}
