<?php

namespace AppBundle\Form\Admin;

use AppBundle\Entity\User;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class UserType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('firstname', null, array('required' => true, 'label' => 'Prénom'));
        $builder->add('lastname', null, array('required' => true, 'label' => 'Nom'));
        $builder->add('email', null, array('required' => true, 'label' => 'Email'));
        $builder->add('username', null, array('required' => true, 'label' => 'Nom d\'utilisateur'));
        $builder->add('plainPassword', null, array('required' => true, 'label' => 'Mot de passe'));
        $builder->add('roles', ChoiceType::class,
            array(
                'label' => "Rôles",
                'multiple' => true,
//                'expanded' => true,
                'choices' => array(
                    'Admin' => 'ROLE_SUPER_ADMIN',
                    'Modérateur' => 'ROLE_MODERATOR',
                    'Webmaster' => 'ROLE_WEBMASTER',
                    'Talent' => 'ROLE_TALENT',
                    'Entreprise' => 'ROLE_COMPANY',
                    'Territoire' => 'ROLE_TERRITORY',
                )
            )
        );
        $builder->add('enabled', CheckboxType::class, array(
            'required' => false,
            'label' => 'Actif'
        ));
    }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => User::class,
        ));
    }
}