<?php

namespace App\Form\Acteurs;

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

class ProprietairesType 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' => true,
                'choices' => $this->getCivilites(),
            ])
            ->add('numeroCniPassport', TextInputType::class, [
                'required' => true,
                'label' => 'Identité: N°/Passport <span class="text-danger">*</span>',
                'label_html' => true,
                '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('adresses', AdressesType::class, [
                'label' => 'Adresse <span class="text-danger">*</span>',
                'required' => true,
                'label_html' => true,
            ])
            ->add('commission', NumberInputType::class, [
                'required' => true,
                'label_html' => true,
                'label' => 'Commission (%) <span class="text-danger">*</span>',
                'icon' => 'icon-sort-numeric-asc',
                'color' => null,
                'attr' => [
                    'placeholder' => 'Commission (%)',
                    'min' => 0,
                ]
            ])
            ->add('isActif', SwitchType::class, ['label' => 'Propriétaire actif?', 'required' => false])
        ;
    }

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

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