<?php

namespace App\Form;

use App\Entity\LeaveApplication;
use App\Entity\Leavename;
use App\Repository\LeavenameRepository;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;

class LeaveApplicationType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        
        $builder
            ->add('leavename', EntityType::class, [
                // looks for choices from this entity
                'class' => Leavename::class,
                'query_builder' => function (LeavenameRepository $er) {
                    return $er->createQueryBuilder('v')                       
                        ->orderBy('v.name', 'ASC');
                },              
                // uses the User.username property as the visible option string
                'choice_label' => 'name',
                'placeholder' => 'Select a Leave...',
                'attr' => [
                    'class' => 'form-control select-tags',
                    ],
                'label' => 'Leave',  
                // used to render a select box, check boxes or radios
                // 'multiple' => true,
                // 'expanded' => true,
                ])
            //->add('empId')
            ->add('fromDays', DateType::class, [
                'attr' => ['class' => 'form-control',
                'style' => 'line-height:20px;'],
                'widget' => 'single_text',
                'empty_data' => null,                                       
                ])
            ->add('toDays', DateType::class, [
                'attr' => ['class' => 'form-control',
                'style' => 'line-height:20px;'],
                'widget' => 'single_text',
                'empty_data' => null,                                           
                ])   
            ->add('reasons', TextareaType::class, [
                'attr' => ['class' => 'form-control',              
                    ],                               
                ])  
            ->add('address', TextareaType::class, [
                'attr' => ['class' => 'form-control',              
                    ],  
                'label' => 'Address While on Leave',                             
                ])  
            ->add('contactNo',TextType::class, [       
                'attr' => ['class' => 'form-control'],
                'label' => 'Contact Phone No',
            ])
           
            // ->add('specialRemarks')
            // ->add('status')
            // ->add('type')
            // ->add('entryby')
            // ->add('entrydate')
            // ->add('editby')
            // ->add('editdate')
           
        ;
    }

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