<?php
namespace OfficeBrain\Bundle\TaxBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints as Assert;



class TaxMasterType extends AbstractType {
	public function __construct($type,$action,$taxId)
	{
		$this->type = $type;
		$this->action = $action;
		$this->taxId = $taxId;
	}
	/**
	 *
	 * @param FormBuilderInterface $builder
	 * @param array $options        	
	 */
	public function buildForm(FormBuilderInterface $builder, array $options) 
	{
		$builder->add ('title' , 'text', array(
				'required'  => false,
				'constraints' => array(
						new NotBlank(array('message'=>'admin.tax_master.add_tax_master.tax_title_form.validation')),
				),
		))
		-> add ('taxType' , 'choice', array(
				'choices' => $this->type , 'multiple'=>false,
				'required'  => false,
				'placeholder'=>'admin.tax_master.add_tax_master.tax_type_form.select',
				'constraints' => array(
						new NotBlank(array('message'=>'admin.tax_master.add_tax_master.tax_type_form.validation')),
				),
		))
		->add ('taxValue' , 'number', array(
						'required'  => false,
						'constraints' => array(
							new NotBlank(array('message'=>'admin.tax_master.add_tax_master.tax_value_form.validation')),
				            /*new Assert\Regex(array(
				                'pattern' =>  '/^[1-9]\d*$/',
				                'message' => 'shipping_estimator.form.qty.positive_number'
				                )
				            ),*/
				            new Assert\Length(array('max' => 5))
                       ),
                   ));
		
		if($this->action =='edit')
		{
			$builder->add ( 'id' , 'hidden', array('data' => $this->taxId));
		}
	}

	/**
	 *
	 * @return string
	 */
	public function getName() {
		return 'tax_master';
	}
	public function setForm($form){
    	$this->form = $form;
    }

}