<?php

namespace App\Form\Type;

use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use App\Entity\Adherent;

class EncaissementFormType extends AbstractType
{
    protected $em;
    protected $security;

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

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('adherent', EntityType::class, [
                'class' => Adherent::class,
                'choices' => $this->em->getRepository(Adherent::class)->findOrderByName(),
                'attr' => [
                    'class' => 'form-control select2',
                ],
                'placeholder' => 'Choisissez un.e adhérent.e',
                'required' => true,
                'label' => 'Adherent :',
                'choice_label' => 'name'
            ])
            ->add('montant', NumberType::class, [
                'label' => 'Montant : ',
                'required' => true,
                'attr' => ['autocomplete' => 'off']
            ])
            ->add('payment_code', HiddenType::class, [
                'label' => 'Code de validation de l\'habitant·e : ',
                'required' => false,
                'attr' => ['autocomplete' => 'off']
            ])
            ->add('save', SubmitType::class, ['label' => 'Valider'])
        ;
    }

    public function getBlockPrefix()
    {
        return 'formEncaissement';
    }
}
