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

namespace AppBundle\Form;

use AppBundle\Entity\Traveler;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
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 TravelerType extends AbstractType
{
    public static $SEX_CHOICES = [
        'männlich' => Traveler::MALE,
        'weiblich' => Traveler::FEMALE
    ];

    /**
     * @param OptionsResolver $resolver
     */
    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'AppBundle\Entity\Traveler'
        ));
    }

    /**
     * @param FormBuilderInterface $builder
     * @param array $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('sex', ChoiceType::class, [
                //'placeholder' => 'Geschlecht (Bitte wählen) *',
                'choices' => self::$SEX_CHOICES,
                'constraints' => [
                    new Choice(['choices' => self::$SEX_CHOICES])
                ],
                'required' => true,
            ])
            ->add('firstName')
            ->add('lastName')
            ->add('birthDate')
            ;
            /*
            , StDateType::class, [
                'format' => 'dd.MM.yyyy'
                ]  
            */
    }
}

