<?php

namespace Lc\ShopBundle\Form\Backend\Order;


use Doctrine\ORM\EntityManagerInterface;
use Lc\ShopBundle\Context\OrderPaymentInterface;
use Lc\ShopBundle\Model\OrderPayment;
use Lc\ShopBundle\Services\Utils;
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\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class OrderPaymentType extends AbstractType
{
        protected $em;

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

        public function buildForm(FormBuilderInterface $builder, array $options)
        {
                $builder
                        ->add('id', HiddenType::class, array(
                                'mapped'=>false,
                        ))
                        ->add('meanPayment', ChoiceType::class, array(
                                'choices' => array(
                                        'field.default.meanPaymentOptions.' . Utils::MEAN_PAYMENT_CHEQUE => Utils::MEAN_PAYMENT_CHEQUE,
                                        'field.default.meanPaymentOptions.' . Utils::MEAN_PAYMENT_CREDIT_CARD => Utils::MEAN_PAYMENT_CREDIT_CARD,
                                        'field.default.meanPaymentOptions.' . Utils::MEAN_PAYMENT_CREDIT => Utils::MEAN_PAYMENT_CREDIT,
                                        'field.default.meanPaymentOptions.' . Utils::MEAN_PAYMENT_TRANSFER => Utils::MEAN_PAYMENT_TRANSFER,
                                        'field.default.meanPaymentOptions.' . Utils::MEAN_PAYMENT_CASH => Utils::MEAN_PAYMENT_CASH
                                ),
                                'required' => true
                        ))
                        ->add('paidAt', DateType::class, array(
                                'widget' => 'single_text',
                                'required' => true
                        ))
                        ->add('amount', MoneyType::class, array(
                        ))
                        ->add('reference', TextType::class, array(
                                'required' => false
                        ))
                        ->add('comment', TextareaType::class, array(
                                'required' => false
                        ))
                        ->add('add', ButtonType::class, array(
                                'label' => 'action.add'
                        ));


        }

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