<?php

namespace App\Form;

use App\Entity\Tregnal;
use App\Entity\Tusuario;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class Tregnal_entregaType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $filters = array(3, 4);
        $filters2 = array(2, 5);
        $builder
//            ->add('fechasalida',DateType::class, array(
//                'widget'=>'single_text',
//                'html5' => false,
//                'input' => 'datetime',
//                'label'=>'Fecha de Salida',
//                'format'=>'dd/MM/yyyy',
//                'attr'=> ['class'=>'form-control mydatepicker', 'style' => 'margin-bottom:5px','placeholder'=>'dd/mm/yyyy']))

            ->add('chasis',TextType::class,
                array('label'=>'Chasis',
                    'attr'=>array('class'=>'form-control', 'style' => 'margin-bottom:10px', 'maxlength'=>20)))

            ->add('marca',TextType::class,
                array('label'=>'Marca',
                    'attr'=>array('class'=>'form-control', 'style' => 'margin-bottom:10px', 'maxlength'=>50)))

            ->add('modelo',TextType::class,
                array('label'=>'Modelo/Tipo',
                    'attr'=>array('class'=>'form-control', 'style' => 'margin-bottom:10px', 'maxlength'=>100)))

//            ->add('fechapago')

            ->add('observaciones',TextType::class,
                array('label'=>'Observaciones',
                    'attr'=>array('class'=>'form-control', 'style' => 'margin-bottom:10px', 'maxlength'=>250)))

//            ->add('auditoria')

//            ->add('movimiento', ChoiceType::class, array(
//                'label'=>'Movimiento: ',
//                'attr'=>array('class'=>'form-control', 'style' => 'margin-bottom:10px', 'maxlength'=>20 ),
//                'placeholder' => '----Escoge movimiento',
//                'choices'   => array(
//                    'Despachado' => 'Despachado',
//                    'Entregado'   => 'Entregado',
//                ),
//                'multiple'  => false,
//            ))

            ->add('fechaentrega',DateType::class, array(
                'widget'=>'single_text',
                'html5' => false,
                'input' => 'datetime',
                'label'=>'Fecha de Entrega',
                'format'=>'dd/MM/yyyy',
                'attr'=> ['class'=>'form-control mydatepicker', 'style' => 'margin-bottom:5px','placeholder'=>'dd/mm/yyyy']))

//            ->add('idnacional')

            ->add('idusuario', EntityType::class, [
                'label' => 'Transportista',
                'class' => Tusuario::class,
                'choice_label' => 'nombres',
                'placeholder' => '--- Escoja un Transportista',
                'query_builder' => function ($er) use ($filters){
                    return $er->createQueryBuilder('p')
                        ->select('p') // Entity
//						->from(Persona::class, 'p')
                        ->where('p.idrol IN (:rol)')
                        ->setParameter('rol', $filters)
                        ->orderBy('p.nombres', 'ASC');
                },
                ])

            ->add('idusuario2', EntityType::class, [
                'label' => 'Recepciona:',
                'class' => Tusuario::class,
                'choice_label' => 'nombres',
                'placeholder' => '--- Escoja un Recepcionista',
                'query_builder' => function ($er) use($filters2) {
                    return $er->createQueryBuilder('p')
                        ->select('p') // Entity
//						->from(Persona::class, 'p')
                        ->where('p.idrol IN (:rol)')
                        ->setParameter('rol', $filters2)
                        ->orderBy('p.nombres', 'ASC');
                },
                ])
        ;
    }

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