<?php

namespace App\Form;

use App\Entity\Event;
use App\Entity\Period;
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\DateTimeType;

class PeriodType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->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', 'autofocus' => true],
                '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'],   
            ])
        ;
    }

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