<?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 GamemasterProfileType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('preferedName', null, [
                'label' => 'Pseudonyme',
                'required' => false,
                'help' => 'Entrez un 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 à partir du pseudonyme, 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' => 'Votre biographie.',
                '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('gamesCanMaster', EntityType::class, [
                'label' => 'Jeux connus',
                'help' => 'Cochez les jeux que vous pouvez animer.',
                '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,
        ]);
    }
}
