<?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\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\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class OrderDeliveryAddressType extends AbstractType
{
        protected $em;
        protected $merchantUtils;

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

        public function buildForm(FormBuilderInterface $builder, array $options)
        {
                $entity = $options['data'];
                $builder->add('deliveryPointSale', ChoiceType::class, array(
                        'choices' => $this->merchantUtils->getMerchantUser()->getPointSales(),
                        'choice_label' => 'labelAdminChoice',
                        'required' => false,
                        'mapped' => false,

                ))

                ->add('saveDeliveryAddress', ButtonType::class, array(
                        'label' => 'field.OrderShop.saveInvoiceAddress'
                ));

        }

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