<?php

namespace App\Form\Type;

use App\Entity\AchatMonnaieAdherent;
use App\Entity\Adherent;
use App\Entity\DonAdherent;
use App\Entity\GlobalParameter;
use App\Entity\Prestataire;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class AchatMonnaieAdherentRecurrentFormType extends AchatMonnaieAdherentFormType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $jourPrelevementChoices = [];
        for ($i = 1; $i <= 28; $i++) {
            $jourPrelevementChoices[strval($i)] = $i;
        }
        $now = new \DateTime();
        $builder
            ->add('nombreMois', IntegerType::class, [
                'label' => 'Nombre d\'échéances désirées : ',
                'required' => true,
                'mapped' => false,
                'help' => "Une échéance par mois.",
                'attr' => ['autocomplete' => 'off']
            ])
            ->add('jourPrelevement', ChoiceType::class, [
                'label' => 'Jour du prélèvement dans le mois : ',
                'choices'  => $jourPrelevementChoices,
                'data' => min($now->format('d'),28),
                'required' => true,
                'mapped' => false,
                'attr' => ['autocomplete' => 'off', 'disabled' => true]
            ])
            ->remove('saveHelloAsso')
            ->remove('save')
            ->add('save', SubmitType::class, [
                'label' => 'Payer en CB mon premier paiement et créer un paiement récurrent',
                'translation_domain' => 'messages',
                'attr' => [
                    'class' => 'btn-primary btn achatCBSubmit',
                ],
            ])
        ;

        $builder
                
            ;
    }

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

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

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