<?php

namespace App\Form;

use App\Entity\User;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

use Symfony\Component\Validator\Constraints\IsTrue;

use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;

class UserRegistrationType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('pseudo', null, ['label' => 'pseudo',  'attr' => [ 'placeholder' => 'placeholder_pseudo'] ])
            ->add('email', null, ['label' => 'placeholder_email', 'attr' => [ 'placeholder' => 'placeholder_email'] ])
            ->add('password', null, ['label' => 'password', 'attr' => [ 'placeholder' => 'password'] ])
            ->add('TypeUser', ChoiceType::class, array(
                'label' => 'placeholder_type_user',
                'attr' => [ 'placeholder' => 'placeholder_type_user'],
                'choices' => ['choice_type_user_0' => 0, 'choice_type_user_1' => 1 ],
                'expanded' => true
            ))
            ->add('cgu', CheckboxType::class, array(
                'mapped' => false,
                'label' => 'i_accept',
                'constraints' => [
                    new IsTrue(message: 'Merci d’accepter les conditions générales d’utilisation en cochant la case ci-dessous'),
                ],
            ))
        ;
    }

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