<?php

namespace App\Form;

use App\Entity\User;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;

class EmployeeInfoType extends AbstractType
{
    public function __construct(EntityManagerInterface $em) {
        $this->em = $em;
    }

    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $users = $this->em
                        ->getRepository(User::class)
                        ->findAll();
                   
        $userArray = Array();
        foreach($users as $user)
        {
            $userArray[$user->getFullName().' - '.$user->getUsername()] = $user->getId();
        }

        $builder
            ->add('username',TextType::class, [       
                'attr' => ['class' => 'form-control'],
                'label' => 'PIN',
            ])
            ->add('roles', ChoiceType::class,[
                'multiple' => true,
                'expanded' => true,
                'choices'  => [                     
                    'Employee'         => 'ROLE_EMPLOYEE',
                    'Admin'            => 'ROLE_ADMIN',                  
                ],
                
            ])            
            ->add('fullName',TextType::class, [       
                'attr' => ['class' => 'form-control'],
                'label' => 'Full Name',
            ])
            ->add('officePhone',TextType::class, [       
                'attr' => ['class' => 'form-control'],
                
            ])
            ->add('officeEmail',TextType::class, [       
                'attr' => ['class' => 'form-control'],
                
            ])
            ->add('functionalHead', ChoiceType::class, [
                'choices' => $userArray,
                'placeholder' => 'Select a Employee...', 
                'required'  => false,            
                'attr' => [
                    'class' => 'form-control select-tags',
                    ],                         
            ])
            ->add('departmentHead', ChoiceType::class, [
                'choices' => $userArray,
                'placeholder' => 'Select a Employee...',   
                'required'  => false,                 
                'attr' => [
                    'class' => 'form-control select-tags',
                    ],                         
            ])
           
            // ->add('status')
            // ->add('remarks')
        ;
    }

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