<?php

namespace Lc\ShopBundle\Form\Backend\Order;

use App\Entity\Product;
use Doctrine\ORM\EntityManagerInterface;
use Lc\ShopBundle\Context\OrderProductInterface;
use Lc\ShopBundle\Context\OrderReductionCartInterface;
use Lc\ShopBundle\Context\OrderShopInterface;
use Lc\ShopBundle\Context\ProductInterface;
use Lc\ShopBundle\Context\ReductionCartInterface;
use Lc\ShopBundle\Form\DataTransformer\ProductToIdTransformer;
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\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class AddOrderReductionCartType extends AbstractType
{
        protected $em;

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

        public function buildForm(FormBuilderInterface $builder, array $options)
        {
                $entity = $options['data'];

                $reductionCartClass = $this->em->getClassMetadata(ReductionCartInterface::class);
                $reductionCartRepo = $this->em->getRepository(ReductionCartInterface::class);;

                $builder
                        ->add('reductionCart', EntityType::class, array(
                                'class' => $reductionCartClass->getName(),
                                'choices' => $reductionCartRepo->getEligibleReductionCart($entity),
                                'required' => true,
                                'mapped'=>false
                        ));
                $builder->add('add', ButtonType::class, array(
                        'label' => 'action.add'
                ));


        }

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