<?php

namespace App\Form;

use App\Entity\Game;
use App\Entity\Gamemaster;
use App\Entity\User;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use App\Repository\UserRepository;

class GamemasterType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('firstName', null, [
                'label' => 'Prénom',
                'required' => true,
                'help' => 'Entrez le prénom.',
                'label_attr' => ['class' => 'label'],
                'attr' => ['class' => 'input'],
                'row_attr' => ['class' => 'field'],
                'help_attr' => ['class' => 'help'],
            ])
            ->add('lastName', null, [
                'label' => 'Nom',
                'required' => true,
                'help' => 'Entrez le nom.',
                'label_attr' => ['class' => 'label'],
                'attr' => ['class' => 'input'],
                'row_attr' => ['class' => 'field'],
                'help_attr' => ['class' => 'help'],
            ])
            ->add('preferedName', null, [
                'label' => 'Pseudonyme',
                'required' => false,
                'help' => 'Entrez le pseudonyme, laissez vide pour utiliser le prénom + nom.',
                'label_attr' => ['class' => 'label'],
                'attr' => ['class' => 'input'],
                'row_attr' => ['class' => 'field'],
                'help_attr' => ['class' => 'help'],
            ])
            ->add('slug', null, [
                'label' => 'Slug',
                'help' => 'Laissez vide pour le générer automatiquement, utilisé dans les URL.',
                'required' => false,
                'label_attr' => ['class' => 'label'],
                'attr' => ['class' => 'input'],
                'row_attr' => ['class' => 'field'],
                'help_attr' => ['class' => 'help'],
            ])
            ->add('description', null, [
                'label' => 'Description',
                'label_attr' => ['class' => 'label'],
                'help' => 'Description sommaire du jeu.',
                'attr' => ['class' => 'textarea',
                           'rows' => 6],
                'required' => false,
                'row_attr' => ['class' => 'field'],
                'help_attr' => ['class' => 'help'],
            ])
            ->add('picture', FileType::class, [
                'label' => 'Illustration',
                'label_attr' => ['class' => 'label'],
                'attr' => ['class' => 'file-input'],
                'help' => 'Fichier JPEG, PNG ou webP, carrée, sera découpée et redimensionnée en 250×250',
                'required' => false,
                'mapped' => false,
                'row_attr' => ['class' => 'field'],
                'help_attr' => ['class' => 'help'],
            ])
            ->add('email', null, [
                'label' => 'email',
                'required' => true,
                'help' => 'Entrez une adresse email.',
                'label_attr' => ['class' => 'label'],
                'attr' => ['class' => 'input'],
                'row_attr' => ['class' => 'field'],
                'help_attr' => ['class' => 'help'],
            ])
            ->add('phone', null, [
                'label' => 'Numéro de téléphone mobile',
                'required' => false,
                'help' => 'Entrez un numéro de téléphone mobile (optionnel).',
                'label_attr' => ['class' => 'label'],
                'attr' => ['class' => 'input'],
                'row_attr' => ['class' => 'field'],
                'help_attr' => ['class' => 'help'],
            ])
            ->add('gamesCanMaster', EntityType::class, [
                'label' => 'Jeux connus',
                'attr' => ['class' => 'checkboxes'],
                'class' => Game::class,
                'choice_label' => 'name',
                'required' => false,
                'expanded' => true,
                'multiple' => true,
                'label_attr' => ['class' => 'label'],
                'choice_attr' => ['class' => 'checkbox'],
                'help_attr' => ['class' => 'help'],
            ])
            ->add('linkToUser', EntityType::class, [
                'label' => 'Lier à un compte utilisateur.rice',
                'class' => User::class,
                'choice_label' => 'email',
                'label_attr' => ['class' => 'label'],
                'attr' => ['class' => 'input'],
                'required' => false,
                'row_attr' => ['class' => 'field'],
                'help_attr' => ['class' => 'help'],
                'help' => 'Sélectionner le compte à lier à ce MJ.',
            ])
//             ->add('isAuthor', null, [
//                 'label' => 'Auteur(rice) de jeu de rôles',
//                 'label_attr' => ['class' => 'checkbox'],
//                 'help' => 'Cochez si ce meneur(euse) de jeu est aussi auteur(rice).',
//                 'attr' => ['class' => 'checkbox'],
//                 'row_attr' => ['class' => 'field'],
//                 'help_attr' => ['class' => 'help'],
//             ])
            ->add('authorOfGames', EntityType::class, [
                'label' => 'Auteur(rice) des jeux',
                'attr' => ['class' => 'checkboxes'],
                'class' => Game::class,
                'choice_label' => 'name',
                'required' => false,
                'expanded' => true,
                'multiple' => true,
                'label_attr' => ['class' => 'label'],
                'choice_attr' => ['class' => 'checkbox'],
                'help_attr' => ['class' => 'help'],
            ])
        ;
    }

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