<?php

namespace Lc\ShopBundle\Form\Backend\Common;

use Lc\ShopBundle\Context\ReminderInterface;
use Lc\ShopBundle\Context\UserInterface;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Lc\ShopBundle\Context\AddressInterface;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Validator\Constraints\NotBlank;

class ReminderType extends AbstractType
{
        protected $em;

        public function __construct(EntityManagerInterface $entityManager)
        {
                $this->em = $entityManager;
        }

        public function buildForm(FormBuilderInterface $builder, array $options)
        {
                $userClass= $this->em->getClassMetadata(UserInterface::class);
                $userRepo= $this->em->getRepository(UserInterface::class);
                $builder
                        ->add('title', TextType::class, ['label' => 'Titre'])
                        ->add('description', TextareaType::class, array(
                                'required' => false
                        ))
                        ->add('entityName', HiddenType::class, array(
                                'required' => false
                        ))
                        ->add('entityId', HiddenType::class, array(
                                'required' => false
                        ))
                        ->add('entityAction', HiddenType::class, array(
                                'required' => false
                        ))
                        ->add('users', EntityType::class, array(
                                'class'=> $userClass->name,
                                'choices'=> $userRepo->findByRole('ROLE_ADMIN'),
                                'required' => false,
                                'multiple'=>true
                        ))
                        ->add('dateReminder', DateType::class, array(
                                'required'=>false,
                                'widget'=>'single_text',
                        ));


        }

        public function configureOptions(OptionsResolver $resolver)
        {
                $resolver->setDefaults([
                        'label' => false,
                        'data_class' => $this->em->getClassMetadata(ReminderInterface::class)->getName()
                ]);
        }
}
