<?php

namespace App\Form\Type;

use App\Entity\Cotisation;
use App\Enum\MoyenEnum;
use App\Form\Type\CotisationInfosFormType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
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\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\OptionsResolver\OptionsResolver;

class CotisationFormType extends FluxFormType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('type', HiddenType::class, array(
                'data' => 'cotisation',
                'data_class' => null
            ))
            ->add('montant', MoneyType::class, array(
                'label' => 'Montant',
                'data' => floatval($this->container->getParameter('app.cotisation_montant'))
            ))
            ->add('moyen', ChoiceType::class, array(
                'required' => true,
                'choices' => MoyenEnum::getAvailableTypes(),
                'choice_label' => function ($choice) {
                    return MoyenEnum::getTypeName($choice);
                },
            ))
            ->add('recu', CheckboxType::class, array(
                'label' => 'Reçu'
            ))
            ->add('cotisationInfos', CotisationInfosFormType::class, array(
                'label' => 'Infos'
            ))
        ;
    }

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


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

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