<?php

namespace Lc\SovBundle\Form\Setting;

use Doctrine\ORM\EntityManagerInterface;
use Lc\SovBundle\Model\Site\SiteInterface;
use Lc\SovBundle\Translation\TranslatorAdmin;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class SiteSettingsFormType extends AbstractType
{
    protected $em;
    protected $translatorAdmin;

    public function __construct(EntityManagerInterface $em, TranslatorAdmin $translatorAdmin)
    {
        $this->em = $em;
        $this->translatorAdmin = $translatorAdmin;
    }

    public function buildForm(FormBuilderInterface $builder, array $options)
    {

        $builder->add(
                'settings',
                CollectionType::class,
                [
                        'entry_type' => SettingType::class,
                        'required' => false,
                        'allow_add' => false,
                        'allow_delete' => false,
                        'by_reference' => false,
                ]
        );

        $builder->add('submit', SubmitType::class, [
                'label' => $this->translatorAdmin->transAction('save'),
                'attr' => [
                        'class' => 'btn btn-primary float-right'
                ]
        ]) ;
    }

    /**
     * {@inheritdoc}
     */
    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(
                [
                        'data_class' => $this->em->getEntityName(SiteInterface::class),
                ]
        );
    }

}
