<?php

namespace OfficeBrain\Bundle\UserBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\Form\FormTypeInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Validator\ExecutionContextInterface as context;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\FormError;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\ORM\EntityRepository;

class ApiAddressBookType extends AbstractType
{
    /**
     *
     * @param ContainerInterface $container
     * @param $mode
     */
    public function __construct(ContainerInterface $container, $side = '')
    {
        $this->container = $container;
        $this->side = $side;
        $this->request = $this->container->get('request');
        $this->projectSetting = $this->request->get('project_user_setting')['user_data'];
        $this->userId = $this->projectSetting->getId();
    }

    /**
     * @param FormBuilderInterface $builder
     * @param array $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
    
    	$shippingType = array('1' => 'user.contact_book.shipping_type.office', '0' => 'user.contact_book.shipping_type.home');
    	$countryConfiguration=array();    	
		$country = array ();
		$state = array ();
		$city = array ();
		
		
		$builder->add ( 'user', 'text', array (
    					'empty_data'  => null,
    					'constraints' => array(new Assert\NotBlank(array('message'=>'user.contact_book.user.not_blank'))),
    					));
    		
    	    
    	$builder
    	->add('name', 'text', array(
    			'required' => false,
    			'constraints'=>array()
    	))
    	->add('adressType', 'text', array(
    			'empty_data'  => null,
    			))
    			->add('email', 'text')
    			->add('street1', 'text')
    			->add('street2', 'text')
    			->add('countryId', 'choice', array(
    					'choices'=> $country,
    					'empty_value'=>  'user.contact_book.countryId.select_value',
    			))
    			->add('stateId', 'choice', array(
    					'choices'=> $state,
    					'empty_data'  => null,
    			))
    			->add('cityId', 'choice', array(
    					'choices'=> $city,
    					'empty_data'  => null,
    			))
    	
    			->add('zipcode', 'text')
    			->add('extension', 'text')
    			->add('phone', 'text')
    			->add('mobile', 'text')
    			->add('fax', 'text')
    			->add('website', 'text', array(
    					'required' => false,
    					'constraints'=>array()
    			))
    			->add('isOffice', 'choice', array(
    					'choices' => $shippingType,
    					'multiple'=>false,
    					'expanded' => true,
    			))
    			//->add('isAddress', 'hidden')
    			//->add('erpId', 'hidden')
    			; 
    }

    /**
     * @param OptionsResolverInterface $resolver
     */
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'OfficeBrain\Bundle\UserBundle\Entity\ContactBook'
        ));
    }

    /**
     * @return string
     */
    public function getName()
    {
        return 'ob_contactbook';
    }
}
