<?php

namespace App\Form\Type;

use App\Entity\AchatMonnaieAConfirmer;
use App\Entity\Siege;
use App\Enum\MoyenEnum;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
use Symfony\Component\Form\Extension\Core\Type\RangeType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class AchatMonnaieAConfirmerFormType extends FluxFormType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('moyen', ChoiceType::class, [
                'required' => true,
                'choices' => [
                    MoyenEnum::MOYEN_CHEQUE,
                    MoyenEnum::MOYEN_VIREMENT,
                    MoyenEnum::MOYEN_HELLOASSO
                ],
                'choice_label' => function ($choice) {
                    return MoyenEnum::getTypeName($choice);
                },
                'expanded' => true,
                'multiple' => false,
                'label' => 'Sélectionnez un moyen de paiement :'
            ])
            ->add('expediteur', HiddenType::class, [
                'data' => 1,
                'data_class' => null,
                'entity_class' => Siege::class,
                'em' => $this->em,
            ])
            ->add('montant', MoneyType::class, [
                'label' => 'Montant : ',
                'required' => true,
            ])
            ->add('reference', TextType::class, array(
                'label' => "Référence du virement, date d'envoi du chèque, référence du paiement Helloasso",
                'required' => true
            ))
            ->add('save', SubmitType::class, ['label' => "Valider"])
        ;
    }

    public function getParent()
    {
        return FluxFormType::class;
    }

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

    /**
     * {@inheritdoc}
     */
    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults([
            'data_class' => AchatMonnaieAConfirmer::class,
            'cascade_validation' => true,
        ]);
    }
}
