<?php

namespace App\Form\Campaign;

use App\Entity\Campaign;
use App\Entity\Campaign\Hours;
use App\Entity\TimeLogTypeCategory;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class HoursType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('campaign', EntityType::class, [
                'label' => 'Campaign',
                'class' => Campaign::class,
                'choice_value' => 'id',
                'choice_label' => 'title',
            ])
            ->add('category', EntityType::class, [
                'label' => 'Category',
                'class' => TimeLogTypeCategory::class,
                'choice_value' => 'id',
                'choice_label' => 'title',
            ])
            ->add('startOfTheMonth', DateType::class, [
                'label' => 'Start of the month',
                'format' => 'yyyy-MM-dd',
                'widget' => 'single_text',
                'required' => false,
            ])
            ->add('hours', NumberType::class, [
                'label' => 'How many hours',
                'required' => false,
            ]);
    }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults([
            'data_class' => Hours::class,
            'allow_extra_fields' => true,
            'csrf_protection' => false,
        ]);
    }
}
