<?php

namespace Lc\ShopBundle\Form\Backend\UserMerchant;

use App\Entity\Product;
use Doctrine\ORM\EntityManagerInterface;
use Lc\ShopBundle\Context\CreditHistoryInterface;
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 Lc\ShopBundle\Model\CreditHistory;
use Lc\ShopBundle\Services\Utils;
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\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\SubmitType;
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 CreditHistoryType extends AbstractType
{
        protected $em;


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

        public function buildForm(FormBuilderInterface $builder, array $options)
        {
                $builder->add('type', ChoiceType::class, array(
                                'choices' => array(
                                        'field.CreditHistory.typeOptions.'.CreditHistory::TYPE_CREDIT => CreditHistory::TYPE_CREDIT,
                                        'field.CreditHistory.typeOptions.'.CreditHistory::TYPE_DEBIT => CreditHistory::TYPE_DEBIT
                                ),
                                'required' => true
                        ))
                        ->add('amount', MoneyType::class)
                        ->add('meanPayment', ChoiceType::class, array(
                                'choices' => array(
                                        'field.default.meanPaymentOptions.'.Utils::MEAN_PAYMENT_CASH => Utils::MEAN_PAYMENT_CASH,
                                        'field.default.meanPaymentOptions.'.Utils::MEAN_PAYMENT_CHEQUE => Utils::MEAN_PAYMENT_CHEQUE,
                                        'field.default.meanPaymentOptions.'.Utils::MEAN_PAYMENT_CREDIT => Utils::MEAN_PAYMENT_CREDIT,
                                        'field.default.meanPaymentOptions.'.Utils::MEAN_PAYMENT_CREDIT_CARD => Utils::MEAN_PAYMENT_CREDIT_CARD,
                                        'field.default.meanPaymentOptions.'.Utils::MEAN_PAYMENT_TRANSFER => Utils::MEAN_PAYMENT_TRANSFER
                                ),
                                'required' => true
                        ))
                        ->add('paidAt', DateType::class, array(
                                'widget' => 'single_text',
                                'required' => true
                        ))
                        ->add('reference', TextType::class, array(
                                'required'=>false
                        ))

                        ->add('comment', TextareaType::class, array(
                                'required'=>false
                        ))
                        ->add('add', SubmitType::class, array(
                                'label' => 'action.add'
                        ));


        }

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