<?php

namespace App\Form\Properties;

use DateTime;
use App\Form\Types\SwitchType;
use App\Form\Types\TextInputType;
use App\Entity\Acteurs\Locataires;
use App\Form\Types\EmailInputType;
use Doctrine\ORM\EntityRepository;
use App\Form\Types\NumberInputType;
use App\Entity\Parametres\Parametres;
use App\Entity\Properties\Demarcheur;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Security\Core\Security;
use App\Entity\Parametres\Locations\Locations;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use App\Repository\Parametres\ParametresRepository;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;

class DemarcheursType extends AbstractType
{

    public function __construct(
        private ParametresRepository $parametresRepository,
        private ContainerInterface $container,
        private Security $security,
    ) {}




    /**
     * @param FormBuilderInterface<Callable> $builder
     * @param array[] $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {

        $user = $this->security->getUser();
        $isSuperAdmin = in_array('ROLE_SUPER_ADMIN', $user->getRoles());
        $companyId = $user->getCompanyId();

        $appId = intval($this->container->getParameter('company_id'));


        $builder
            ->add('nom', TextInputType::class, [
                'label' => 'Nom <span class="text-danger">*</span>',
                'label_html' => true,
                'required' => true,
                'icon' => 'icon-user',
                'color' => null,
                'attr' => [
                    'placeholder' => 'Nom du démarcheur *'
                ]
            ])
            ->add('prenom', TextInputType::class, [
                'label' => 'Prénom',
                'label_html' => true,
                'required' => false,
                'icon' => 'icon-sort-numeric-asc',
                'color' => null,
                'attr' => [
                    'placeholder' => 'Prénom du démarcheur'
                ]
            ])
            ->add('email', EmailInputType::class, [
                'required' => false,
                'label' => 'Email',
                'icon' => 'icon-sort-numeric-asc',
                'color' => null,
                'attr' => [
                    'placeholder' => 'Email du démarcheur'
                ]
            ])
            ->add('telephone', NumberInputType::class, [
                'label' => 'Téléphone <span class="text-danger">*</span>',
                'label_html' => true,
                'icon' => 'icon-phone',   // icône à afficher
                'color' => 'primary',     // couleur à utiliser
                'required' => true,
                'attr' => [
                    'placeholder' => 'Téléphone du démarcheur *',
                    'maxlength' => 20,
                    'pattern' => '\d+', // autorise uniquement les chiffres
                ]
            ])

            ->add('active', SwitchType::class, ['label' => 'Démarcheur active?', 'required' => false])
        ;
    }

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