<?php
/**
 * @author Ulrich Hecht <ulrich.hecht@hecht-software.de>
 * @date 02/21/2017
 */

namespace AppBundle\Form;


use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\Choice;
use Symfony\Component\Validator\Constraints\NotNull;

class ContactRequestType extends AbstractType
{
    /**
     * {@inheritdoc}
     */
    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults([
            'data_class' => 'AppBundle\Entity\ContactRequest',
        ]);
    }

    /**
     * @param FormBuilderInterface $builder
     * @param array $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $travelerCountChoices = [];
        for ($i = 1; $i <= 20; ++$i)
        {
            $travelerCountChoices[$i] = $i;
        }

        $builder
            ->add('salutation', ChoiceType::class, [
                'placeholder' => 'Anrede (Bitte wählen) *',
                'choices' => BookingRequestType::$SALUTATION_CHOICES,
                'constraints' => [
                    new Choice(['choices' => BookingRequestType::$SALUTATION_CHOICES])
                ],
                'required' => false,
            ])
            ->add('firstName', TextType::class, ['required' => false])
            ->add('lastName', TextType::class, ['required' => true])
            ->add('streetAddress')
            ->add('zipCode')
            ->add('city')
            ->add('nation', ChoiceType::class, [
                'placeholder' => 'Land (Bitte wählen)',
                'choices' => BookingRequestType::$NATION_CHOICES,
                'constraints' => [
                    new NotNull(),
                    new Choice(['choices' => BookingRequestType::$NATION_CHOICES])
                ],
                'data' => BookingRequestType::$NATION_CHOICES['Deutschland'],
            ])
            ->add('phone', TextType::class, ['required' => false])
            ->add('mobilePhone')
            ->add('email', EmailType::class, ['required' => true])
            ->add('travelerCount', ChoiceType::class, [
                'placeholder' => 'Anzahl der Reisenden (Bitte wählen)',
                'choices' => $travelerCountChoices,
                'constraints' => [
                    new Choice(['choices' => $travelerCountChoices])
                ],
                'required' => false,
            ])
            ->add('notes', TextareaType::class, ['required' => false])
            ->add('departure0')
            ->add('departure1')
            ->add('departure2')
            ->add('start', StDateType::class, ['required' => false])
            ->add('end', StDateType::class, ['required' => false])
            ->add('duration')
            ->add('acceptPrivacy', CheckboxType::class, ['required' => true])
            ;
    }
}