<?php

namespace AppBundle\Form;

use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\Choice;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use AppBundle\Form\StDateType;

class FewoReservationType extends AbstractType
{
    public static $STATUS_CHOICES = [
        'Belegt' => 0,
        'Nicht verfügbar' => 1,
    ];

    public static $TYPE_CHOICES = [
        'Buchung' => 0,
        'Händisch' => 1
    ];


    /**
     * {@inheritdoc}
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $lodging = $options['lodging'];
        $fromDate = $options['fromDate'];
        $fromDateDateTime = new \DateTime($fromDate);
        $lodgingArr[] = $lodging;

        $builder
            ->add('lodging', EntityType::class, [
                'class' => 'AppBundle\Entity\FewoLodging',
                'choices' => $lodgingArr,
                'constraints' => [
                    new Choice(['choices' => $lodgingArr])
                ],
                'required'=> true
            ])
            ->add('fromDate', StDateType::class, [
                //options
                'data' => $fromDateDateTime
            ])
            ->add('toDate', StDateType::class, [
            ])
            ->add('status', ChoiceType::class, [
                'placeholder' => 'Status (Bitte wählen) *',
                'choices' => self::$STATUS_CHOICES,
                'constraints' => [
                    new Choice(['choices' => self::$STATUS_CHOICES])
                ],
                'required' => true,
            ])
            /*
            ->add('type', ChoiceType::class, [
                'placeholder' => 'Buchungstyp (Bitte wählen) *',
                'choices' => self::$TYPE_CHOICES,
                'constraints' => [
                    new Choice(['choices' => self::$TYPE_CHOICES])
                ],
                'required' => true,
            ])
            */
            //->add('lodging') // wird händisch gesetzt
        ;
    }
    
    /**
     * {@inheritdoc}
     */
    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(array(
            'lodging' => null,
            'fromDate' => null,
            'data_class' => 'AppBundle\Entity\FewoReservation'
        ));
        $resolver->setAllowedTypes('lodging', ['AppBundle\Entity\FewoLodging']);
        $resolver->setAllowedTypes('fromDate', ['string', 'NULL']);
    }

    /**
     * {@inheritdoc}
     */
    public function getBlockPrefix()
    {
        return 'appbundle_feworeservation';
    }


}
