<?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\OrderUtilsInterface;
use Lc\ShopBundle\Context\ProductInterface;
use Lc\ShopBundle\Context\ReductionCartInterface;
use Lc\ShopBundle\Context\ReductionCreditInterface;
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 AddOrderReductionCreditType extends AbstractType
{
        protected $em;
        protected $orderUtils;

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

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

                $reductionCreditClass = $this->em->getClassMetadata(ReductionCreditInterface::class);
                $reductionCreditRepo = $this->em->getRepository(ReductionCreditInterface::class);;

                $builder
                        ->add('reductionCredit', EntityType::class, array(
                                'class' => $reductionCreditClass->getName(),
                                'choices' => $reductionCreditRepo->findReductionCreditsByUser($entity->getUser()),
                                //'choices' => $this->orderUtils->getReductionCreditsAvailable($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'
                ]);
        }
}
