<?php

namespace RxConnexionBundle\Form;

use RxConnexionBundle\Form\Type\ChatParticipantFormType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class ChatForm extends AbstractType
{

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('action', HiddenType::class, array(
                'mapped' => false,
                'attr' => array(
                    'class' => 'form-action'
                )
            ))
            ->add('chat_type', HiddenType::class)
            ->add('id', HiddenType::class)
            ->add('description', HiddenType::class, array(
            ))
            ->add('chatParticipants', CollectionType::class, array(
                'entry_type' => ChatParticipantFormType::class,
                'allow_add' => true,
                'allow_delete' => true,
                'prototype' => true,
                'by_reference' => false
            ))

        ;
    }


    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'RxConnexionBundle\Entity\ChatEntity',
            'csrf_protection' => true,
            'csrf_field_name' => '_token',
            // a unique key to help generate the secret token
            'intention'       => 'chatEntity_intention',
            'action'          => 'n'
        ));
    }

    public function getBlockPrefix()
    {
        return 'rxconnexionbundle_chatentity';
    }


}
