<?php

namespace Lc\ShopBundle\Form\Backend\Order;

use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Lc\ShopBundle\Context\AddressInterface;
use Lc\ShopBundle\Context\MerchantUtilsInterface;
use Lc\ShopBundle\Context\OrderShopInterface;
use Lc\ShopBundle\Context\OrderStatusInterface;
use Lc\ShopBundle\Context\OrderUtilsInterface;
use Lc\ShopBundle\Context\UserInterface;
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\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class OrderStatusType 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'];
                $orderStatusClass = $this->em->getClassMetadata(OrderStatusInterface::class);
                $builder->add('orderStatus', EntityType::class, array(
                        'class'=> $orderStatusClass->name,
                        'choices'=> $entity->getOrderStatus()->getNextStatusAllowed(),
                        'required' => false,
                        'mapped'=>false
                ))

                ->add('change', SubmitType::class, array(
                        'label' => 'action.change'
                ));

        }

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