<?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\Client;
use App\Entity\TypeClient;
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\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
 * Defines the form used to edit an user.
 *
 * @author Mathieu Dauphin
 */
class ClientType extends AbstractType
{
    private $em;

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

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

        $builder
            ->add('id', TextType::class, [
                'label' => 'N°client',
                'label_attr' => [
                    'class' => 'me-2 form-label',
                ],
                'row_attr' => [
                    'class' => 'input-group',
                ],
                'attr' => [
                    'class' => 'form-control-sm',
                ]
            ])
            ->add('type_client', EntityType::class, [
                'class' => TypeClient::class,
                'label' => 'Type',
                'choice_label' => 'libelle',
                'required' => false,
                'label_attr' => [
                    'class' => 'me-2 form-label',
                ],
                'row_attr' => [
                    'class' => 'input-group',
                ],
                'attr' => [
                    'class' => 'form-control-sm',
                ]
            ])
            ->add('nom', TextType::class, [
                'label' => 'Nom',
                'label_attr' => [
                    'class' => 'me-2 form-label',
                ],
                'row_attr' => [
                    'class' => 'input-group',
                ],
                'attr' => [
                    'class' => 'form-control-sm',
                ]
            ])
            ->add('clientTels',CollectionType::class,
                [
                    'allow_add' => true,
                    'allow_delete' => true,
                    'entry_type' => ClientTelType::class,
                    'entry_options' => ['label' => false],
                    'by_reference' => false,
                    'attr' => array('class' => 'form-inline form-control-sm'),
                    'label' => false,
                ],
                [
                    'edit' => 'inline',
                    'inline' => 'table',
                ]
            )
            ->add('clientEmails',CollectionType::class,
                [
                    'allow_add' => true,
                    'allow_delete' => true,
                    'entry_type' => ClientMailType::class,
                    'entry_options' => ['label' => false],
                    'by_reference' => false,
                    'attr' => array('class' => 'form-inline form-control-sm'),
                    'label' => false,
                ],
                [
                    'edit' => 'inline',
                    'inline' => 'table',
                ]
            )
//            ->add('adresse', TextType::class, [
//                'label' => false,
//                'label_attr' => [
//                    'class' => 'me-2 form-label',
//                ],
//                'row_attr' => [
//                    'class' => 'input-group',
//                ],
//                'attr' => [
//                    'class' => 'form-control-sm',
//                ]
//            ])
        ;
    }

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

}
