<?php

namespace App\Form;

use App\Entity\Event;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\Extension\Core\Type\UrlType;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;

class EventType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('name', null, [
                'label' => 'Nom de l\'événement',
                'required' => true,
                'help' => 'Entrez le nom de l\'événement',
                'label_attr' => ['class' => 'label'],
                'attr' => ['class' => 'input'],
                'row_attr' => ['class' => 'field'],
                'help_attr' => ['class' => 'help'],                
            ])
            ->add('startOn', DateTimeType::class, [
                'widget' => 'single_text',
                'help' => 'La date est enregistrée pour le fuseau horaire : '.$_ENV['APP_TZ'],
                'label' => 'Date et heure de début',
                'view_timezone' => $_ENV['APP_TZ'],
                'html5' => true,
                'label_attr' => ['class' => 'label'],
                'attr' => ['class' => 'input'],
                'row_attr' => ['class' => 'field'],
                'help_attr' => ['class' => 'help'],   
            ])
            ->add('endOn', DateTimeType::class, [
                'widget' => 'single_text',
                'help' => 'La date est enregistrée pour le fuseau horaire : '.$_ENV['APP_TZ'],
                'label' => 'Date et heure de fin',
                'view_timezone' => $_ENV['APP_TZ'],
                'html5' => true,
                '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 de l\'événement.',
                '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('moreLink', UrlType::class, [
                'label' => 'Lien vers un complément d\'information',
                'help' => 'Lien vers une page décrivant l\'événement.',
                'label_attr' => ['class' => 'label'],
                'attr' => ['class' => 'input'],
                'required' => false,
                '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('private', null, [
                'label' => 'Événement privé',
                'label_attr' => ['class' => 'checkbox'],
                'help' => 'Cochez si cet événement n\'est visible que des utilisateur(rice)s ayant au moins le rôle "Équipe".',
                'attr' => ['class' => 'checkbox'],
                'row_attr' => ['class' => 'field'],
                'help_attr' => ['class' => 'help'],
            ])
            ->add('hiddenPlanning', null, [
                'label' => 'Planning caché',
                'label_attr' => ['class' => 'checkbox'],
                'help' => 'Cochez si le planning des parties n\'est visible que des utilisateur(rice)s ayant au moins le rôle "Gestionnaire".',
                'attr' => ['class' => 'checkbox'],
                'row_attr' => ['class' => 'field'],
                'help_attr' => ['class' => 'help'],
            ])
            ->add('everyoneCanAskForGame', null, [
                'label' => 'Propositions de parties',
                'label_attr' => ['class' => 'checkbox'],
                'help' => 'Cochez si les participant(e)s peuvent demander l\'organisation de parties.',
                'attr' => ['class' => 'checkbox'],
                'row_attr' => ['class' => 'field'],
                'help_attr' => ['class' => 'help'],
            ])
        ;
    }

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