<?php

namespace RxConnexionBundle\Form;

use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Mapping\Entity;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use RxConnexionBundle\Entity\PurchaseOrderEntity;
use RxConnexionBundle\Entity\PurchaseOrderBreakdownEntity;

class PurchaseOrderBreakdownForm extends AbstractType
{
    private $manager;

    public function __construct(ObjectManager $manager) {
        $this->manager = $manager;
    }

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('action', HiddenType::class, array(
                'mapped' => false,
                'attr' => array(
                    'class' => 'form-action'
                )
            ))
            ->add('purchaseOrder', HiddenType::class, array(
                'mapped' => false,
                'data' => $options['purchaseOrder_id']
            ))
            ->add('id', HiddenType::class)
            ->add('created_by', HiddenType::class)
            ->add('created_at', HiddenType::class)
            ->add('updated_by', HiddenType::class)
            ->add('updated_at', HiddenType::class)
            ->add('purchase_order_no', TextType::class, array(
                'label' => 'PO Number',
                'label_attr' => array(
                    'class' => 'required'
                ),
                'required' => true,
                'data' => $options['nextPurchaseOrderNo']
            ))
            ->add('payment_method', ChoiceType::class, array(
                'label' => 'Payment Method',
                'label_attr' => array(
                    'class' => 'required'
                ),
                'required' => true,
                'choices' => array(
                    'Cash' => 'Cash',
                    'Check' => 'Check',
                    'Credit' => 'Credit'
                )
            ));
    }

    public function getBlockPrefix()
    {
        return 'purchaseOrderBreakdown';
    }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' 	  => 'RxConnexionBundle\Entity\PurchaseOrderBreakdownEntity',
            'csrf_protection' => true,
            'csrf_field_name' => '_token',
            // a unique key to help generate the secret token
            'intention'       => 'purchaseOrderBreakdownEntity_intention',
            'action'          => 'n',
            'nextPurchaseOrderNo' => 0,
            'purchaseOrder_id' => null,
        ));
    }
}