<?php
/**
 * Form Type for Form
 * 
 * @author Elze Kool <info@visualmedia.nl>
 */

namespace VisualM\FormBundle\Form\Type;


use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

/**
 * Form Type for Form
 *
 * @author Elze Kool <info@visualmedia.nl>
 */
class FormType extends AbstractType
{
    



    /**
     * {@inhertDoc@}
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('titel', 'text', array('label' => 'form.titel', 'trim' => true));
        $builder->add('referentie', 'text', array('label' => 'form.referentie', 'trim' => true));
        $builder->add('emailOnderwerp', 'text', array('label' => 'form.email_onderwerp', 'trim' => true));

        $builder->add('fields', 'collection', array(
            'label' => false,
            'allow_add' => true,
            'allow_delete' => true,
            'type' => 'visualm_form_field',
            'by_reference' => true,
            'options' => [
                'form_id' => $options['data']->getId()
            ]
        ));

        $builder->add('ontvangerEmail', 'text', array('label' => 'form.ontvanger_email', 'trim' => true));
        $builder->add('ontvangerNaam', 'text', array('label' => 'form.ontvanger_naam', 'trim' => true));

        $builder->add('bccEmail', 'text', array('label' => 'form.bcc_email', 'trim' => true, 'required' => false));

        $builder->add('afzenderEmail', 'text', array('label' => 'form.afzender_email', 'trim' => true));
        $builder->add('afzenderNaam', 'text', array('label' => 'form.afzender_naam', 'trim' => true));

        $builder->add('kopieNaarAfzender', 'choice', array(
            'label' => 'form.kopie_naar_afzender',
            'choices' => array(false => 'boolean.no', true => 'boolean.yes'),
            'empty_value' => false,
            'expanded' => false,
            'required' => true
        ));

        $builder->add('redirectPath', 'text', array('label' => 'form.redirect_path', 'trim' => true));
        $builder->add('formHtml', 'textarea', array('label' => 'form.form_html'));

        $builder->add('emailHtml', 'textarea', array('label' => 'form.email_html'));
        $builder->add('kopieEmailOnderwerp', 'text', array('label' => 'form.kopie_email_onderwerp', 'trim' => true, 'required' => false));
        $builder->add('kopieEmailHtml', 'textarea', array('label' => 'form.kopie_email_html', 'required' => false));

        $builder->add('save', 'submit', array('label' => 'form.save'));
        $builder->add('saveAndClose', 'submit', array('label' => 'form.save_and_close'));

    }


    /**
     * {@inhertDoc@}
     */
    public function getName()
    {
        return 'visualm_form';
    }
    
    /**
     * {@inhertDoc@}
     */
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'VisualM\FormBundle\Entity\Form',
            'translation_domain' => 'forms',
            'validation_groups' => function(FormInterface $form) {
                $data = $form->getData();
                if ($data->getId() === null) {
                    return array('form', 'Default', 'add', 'form_add');
                } else {
                    return array('form', 'Default', 'edit', 'form_edit');
                }
            }
        ));
    }

}