<?php

namespace App\Dto\Join;

use App\Entity\Join;
use PixelOpen\CloudflareTurnstileBundle\Type\TurnstileType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\TelType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\UrlType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class JoinType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('name', TextType::class, [
                'label' => 'form.label.name',
                'required' => true,
            ])
            ->add('surname', TextType::class, [
                'label' => 'form.label.surname',
                'required' => true,
            ])
            ->add('email', EmailType::class, [
                'label' => 'form.label.email',
                'required' => true,
            ])
            ->add('phone', TelType::class, [
                'label' => 'form.label.phone',
                'required' => true,
            ])
            ->add('dateBirth', DateType::class, [
                'label' => 'form.label.birthdate',
                'required' => true,
            ])
            ->add('address', TextType::class, [
                'label' => 'form.label.address',
                'required' => true,
            ])
            ->add('zipCode', TextType::class, [
                'label' => 'form.label.zipcode',
                'required' => true,
            ])
            ->add('city', TextType::class, [
                'label' => 'form.label.city',
                'required' => true,
            ])
            ->add('sexe', ChoiceType::class, [
                'label' => 'form.label.gender',
                'choices' => [
                    'not_specified' => 'not_specified',
                    'asexual' => 'asexual',
                    'bisexual' => 'bisexual',
                    'demisexual' => 'demisexual',
                    'gay' => 'gay',
                    'heterosexual' => 'heterosexual',
                    'lesbian' => 'lesbian',
                    'pansexual' => 'pansexual',
                    'queer' => 'queer',
                    'questioning' => 'questioning',
                    'other' => 'other',
                ],
                'choice_label' => function ($choice) {
                    return 'form.choices.gender.' . $choice;
                },
            ])
            ->add('pronom', ChoiceType::class, [
                'label' => 'form.label.pronouns',
                'choices' => [
                    'il' => 'il',
                    'elle' => 'elle',
                    'iel' => 'iel',
                    'autre' => 'autre',
                ],
                'choice_label' => function ($choice) {
                    return 'form.choices.pronouns.' . $choice;
                },
            ])
            ->add('discordAccount', TextType::class, [
                'label' => 'form.label.discord',
                'required' => false,
            ])
            ->add('facebookLink', UrlType::class, [
                'label' => 'form.label.facebook',
                'required' => false,
            ])
            ->add('instaLink', UrlType::class, [
                'label' => 'form.label.insta',
                'required' => false,
            ])
            ->add('tiktokLink', UrlType::class, [
                'label' => 'form.label.tiktok',
                'required' => false,
            ])
            ->add('role', ChoiceType::class, [
                'label' => 'form.label.role',
                'choices' => [
                    'cosplay' => 'cosplay',
                    'helper' => 'helper',
                    'photographe' => 'photographer',
                    'autre' => 'other',
                ],
                'choice_label' => function ($choice) {
                    return 'form.choices.role.' . $choice;
                },
                'expanded' => true,
                'multiple' => true,
            ])
            ->add('who', TextareaType::class, [
                'label' => 'form.label.who',
                'required' => true,
            ])
            ->add('security', TurnstileType::class, ['attr' => ['data-action' => 'contact', 'data-theme' => 'dark'], 'label' => false])
            ;
    }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults([
            'data_class' => Join::class,
            // Permet de s'assurer que les labels sont traduits
            'translation_domain' => 'messages',
        ]);
    }
}
