<?php

namespace App\Form;

use App\Entity\Game;
use App\Entity\Genre;
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 Symfony\Component\Form\Extension\Core\Type\UrlType;

class GameProfileType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('name', null, [
                'label' => 'Nom du jeu',
                'required' => true,
                'help' => 'Entrez le nom du jeu.',
                '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, bannière horizontale, sera découpée et redimensionnée en 600×200',
                'required' => false,
                'mapped' => false,
                'row_attr' => ['class' => 'field'],
                'help_attr' => ['class' => 'help'],
            ])
            ->add('genre', EntityType::class, [
                'label' => 'Genres',
                'attr' => ['class' => 'checkboxes'],
                'class' => Genre::class,
                'choice_label' => 'genre',
                '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' => Game::class,
        ]);
    }
}
