<?php

namespace Lc\ShopBundle\Form\Backend\Ticket;

use App\Entity\Product;
use Doctrine\ORM\EntityManagerInterface;
use Lc\ShopBundle\Context\CreditHistoryInterface;
use Lc\ShopBundle\Context\OrderProductInterface;
use Lc\ShopBundle\Context\OrderReductionCartInterface;
use Lc\ShopBundle\Context\OrderShopInterface;
use Lc\ShopBundle\Context\OrderUtilsInterface;
use Lc\ShopBundle\Context\ProductInterface;
use Lc\ShopBundle\Context\ReductionCartInterface;
use Lc\ShopBundle\Context\ReductionCreditInterface;
use Lc\ShopBundle\Context\TicketInterface;
use Lc\ShopBundle\Context\TicketMessageInterface;
use Lc\ShopBundle\Form\DataTransformer\ProductToIdTransformer;
use Lc\ShopBundle\Model\CreditHistory;
use Lc\ShopBundle\Model\Ticket;
use Lc\ShopBundle\Services\Utils;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ButtonType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\OptionsResolver\OptionsResolver;

class TicketTypeType extends AbstractType
{
        protected $em;


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

        public function buildForm(FormBuilderInterface $builder, array $options)
        {
       
                $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event){
                        $builder = $event->getForm()->getParent();

                        $builder->add('type', ChoiceType::class, [
                                'label' => 'field.Ticket.type',
                                'multiple' => false,
                                'expanded' => false,
                                'choices' => [
                                        'field.Ticket.typeOptions.' . Ticket::TYPE_MESSAGE_FROM_PDL => Ticket::TYPE_MESSAGE_FROM_PDL,
                                        'field.Ticket.typeOptions.' . Ticket::TYPE_GENERAL_QUESTION => Ticket::TYPE_GENERAL_QUESTION,
                                        'field.Ticket.typeOptions.' . Ticket::TYPE_PRODUCT_UNAVAILABLE => Ticket::TYPE_PRODUCT_UNAVAILABLE,
                                        'field.Ticket.typeOptions.' . Ticket::TYPE_PRODUCT_ERROR => Ticket::TYPE_PRODUCT_ERROR,
                                        'field.Ticket.typeOptions.' . Ticket::TYPE_TECHNICAL_PROBLEM => Ticket::TYPE_TECHNICAL_PROBLEM,
                                        'field.Ticket.typeOptions.' . Ticket::TYPE_POULTRY_BOOKING => Ticket::TYPE_POULTRY_BOOKING,
                                ],
                                'translation_domain' => 'lcshop',
                        ]);
                });

        }

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