<?php

namespace App\Form;

use App\Entity\City;
use App\Entity\Filial;
use App\Entity\ReviewSource;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Doctrine\ORM\EntityRepository;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;

class ReviewSourceType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('name', ChoiceType::class, [
                'mapped' => true,
                'expanded' => false,
                'choices' => [
                    'Яндекс карта' => 'YandexMap',
                    'Google' => 'Google',
                    'ProDoctorov(Клиники)' => 'ProDoctorov',
                    'ProDoctorov(Врачи)' => 'ProDoctorovSpecialists',
                    '2Gis' => '2Gis',
                    'Zoon' => 'Zoon',
                ]
            ])
            ->add('countRow')
            ->add('active')
            ->add('rating')
            ->add('city', EntityType::class, [
                'class' => City::class,
                'query_builder' => function (EntityRepository $er) {
                    return $er->createQueryBuilder('f');
                },
                'choice_label' => 'name',
                'mapped' => true,
                'multiple' => false, 
                'empty_data' => null,
                'required' => true
            ])
            ->add('filial', EntityType::class, [
                'class' => Filial::class,
                'query_builder' => function (EntityRepository $er) {
                    return $er->createQueryBuilder('f');
                },
                'choice_label' => 'address',
                'mapped' => true,
                'multiple' => false, 
                'empty_data' => null,
                'required' => true
            ])
        ;
    }

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