<?php

namespace App\Form\Properties;

use DateTime;
use App\Form\Types\SwitchType;
use App\Form\Types\TextInputType;
use App\Entity\Acteurs\Locataires;
use Doctrine\ORM\EntityRepository;
use App\Form\Types\NumberInputType;
use App\Entity\Acteurs\Proprietaires;
use App\Entity\Parametres\Parametres;
use App\Entity\Properties\Categories;
use App\Entity\Properties\Properties;
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\Entity\Comptabilites\Currencies\Currencies;
use App\Entity\Properties\Demarcheur;
use App\Form\Types\EmailInputType;
use App\Repository\Parametres\ParametresRepository;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
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'));

        /** @var Parametres $app */
        $app = $this->parametresRepository->find($appId);

        /** @var Currencies $currency */
        $currency = $app?->getCurrencies();

        $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,

                'required' => true,
                'attr' => [
                    'placeholder' => 'Téléphone du démarcheur *'
                ]
            ])

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

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