<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace App\Form;

use App\Entity\Groupe;
use App\Entity\Utilisateur;
use Doctrine\ORM\EntityManagerInterface;
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\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use App\Entity\GroupeType;



class GroupeEntityType extends AbstractType
{
    private $em;

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

    /**
     * {@inheritdoc}
     */
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {

        $builder
            ->add('nom', null, [
                'label' => 'Nom',
                'label_attr' => [
                    'class' => 'col-sm-2 me-3 col-form-label',
                ],
                'row_attr' => [
                    'class' => 'input-group',
                ],
                'required' => true,
            ])
            ->add('user', EntityType::class, [
                'class' => Utilisateur::class,
                'attr' => [
                    'class' => 'my-select-multiple',
                    'data-style' => 'btn-light',
                    'data-live-search' => "true",
                ],
                'multiple' => true,
                'label_attr' => [
                    'class' => 'col-sm-2 me-3 col-form-label',
                ],
                'row_attr' => [
                    'class' => 'input-group',
                ],
                'choice_label' => function ($user) {
                    return $user->getNomComplet();
                },
                'label' => 'Membres',
                'required' => true,
            ])

        ;
    }

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