<?php

namespace App\Form\Acteurs;

use App\Entity\Acteurs\Acteurs;
use App\Entity\Acteurs\Locataires;
use App\Form\Types\SwitchType;
use App\Form\Types\TextInputType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class LocatairesType extends AbstractType
{
    /**
     * @param FormBuilderInterface<Callable> $builder
     * @param array[] $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('civilite', ChoiceType::class, [
                'label' => 'Civilité <span class="text-danger">*</span>',
                'label_html' => true,
                'required' => true,
                'multiple' => false,
                'expanded' => false,
                'choices' => $this->getCivilites(),
            ])
            ->add('typeLocataire', ChoiceType::class, [
                'label' => 'Type de locataire <span class="text-danger">*</span>',
                'label_html' => true,
                'required' => true,
                'choices' => $this->getTypes(),
                'data' => isset($options['data']) && $options['data'] instanceof Locataires
                    ? $options['data']->getTypeLocataire()
                    : 0,
                'empty_data' => 0,
                'attr' => [
                    'data-typelacataite' => 'wraptypelacataite'
                ],
            ])
            ->add('numeroCniPassport', TextInputType::class, [
                'required' => false,
                'label' => 'Identité',
                'icon' => 'icon-sort-numeric-asc',
                'color' => null,
                'attr' => [
                    'placeholder' => 'Identité: N°/Passport'
                ]
            ])
            ->add('name', TextInputType::class, [
                'label' => 'Nom & prénoms <span class="text-danger">*</span>',
                'label_html' => true,
                'icon' => 'icon-user',
                'color' => null,
                'attr' => [
                    'placeholder' => 'Nom & prénoms'
                ]
            ])
            ->add('fonction', TextInputType::class, [
                'required' => false,
                'label' => 'Fonction',
                'icon' => 'icon-graduation2',
                'color' => null,
                'attr' => [
                    'placeholder' => 'Fonction du locataire'
                ]
            ])
            ->add('raisonSociale', TextInputType::class, [
                'label' => 'Raison sociale',
                'icon' => 'icon-users',
                'color' => null,
                'required' => false,
                'attr' => [
                    'placeholder' => 'Raison sociale'
                ]
            ])
            ->add('formeJuridique', TextInputType::class, [
                'label' => 'Forme juridique',
                'icon' => 'icon-file-text',
                'color' => null,
                'required' => false,
                'attr' => [
                    'placeholder' => 'Forme juridique'
                ]
            ])
            ->add('numeroSiren', TextInputType::class, [
                'label' => 'N° Compte contribuable',
                'icon' => 'icon-sort-numeric-asc',
                'color' => null,
                'required' => false,
                'attr' => [
                    'placeholder' => 'N° Compte contribuable'
                ]
            ])
            ->add('numeroRegistreCommerce', TextInputType::class, [
                'label' => 'N° Registre de commerce',
                'icon' => 'icon-sort-numeric-asc',
                'required' => false,
                'color' => null,
                'attr' => [
                    'placeholder' => 'N° Registre de commerce'
                ]
            ])
            ->add('adresses', AdressesType::class, [
                'label' => 'Adresse du locataire',
            ])
            ->add('isActif', SwitchType::class, ['label' => 'Locataire actif?', 'required' => false])
            ->add('isOut', SwitchType::class, ['label' => 'Sortie du locataire?', 'required' => false])
        ;
    }

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

    /**
     * @return array<string, int>
     */
    private function getCivilites(): array
    {
        $choices = Acteurs::CIVILITE;
        $output = [];
        foreach ($choices as $k => $v) {
            $output[$v] = $k;
        }
        return $output;
    }

    /**
     * @return array<string, int>
     */
    private function getTypes(): array
    {
        $choices = Locataires::TYPE;
        $output = [];
        foreach ($choices as $k => $v) {
            $output[$v] = $k;
        }
        return $output;
    }
}
