<?php

namespace RxConnexionBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;

class AccountForm extends AbstractType
{

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $userTypes = array();

        foreach($options['userTypes'] as $row) {
            if($row !== 'Super Admin')
                $userTypes[$row] = $row;
        }
        $builder
            ->add('action', HiddenType::class, array(
                'mapped' => false,
                'attr' => array(
                    'class' => 'form-action'
                )
            ))
            ->add('id', HiddenType::class)
            ->add('code', TextType::class, array(
                'label' => 'Code',
                'required' => false
            ))
            ->add('description', TextType::class, array(
                'label' => 'Description',
                'required' => true
            ))
            ->add('email', TextType::class, array(
                'label' => 'Email',
                'required' => false
            ))
            ->add('mobile_no', TextType::class, array(
                'label' => 'Mobile No.',
                'required' => false
            ))
            ->add('phone_no', TextType::class, array(
                'label' => 'Phone No.',
                'required' => false
            ));
    }

    public function getName()
    {
        return 'account';
    }

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