<?php

namespace OfficeBrain\Bundle\BannerBundle\Form;

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

/**
 *
 * @author OfficeBrain 4571 <info@officebrain.com>
 *
 * Decsription: Banner Type Form
 *
 */
class BannerType extends AbstractType
{
    public function __construct($countryArr, $fromAdmin, $instanceId)
    {
        $this->CountryArray = $countryArr;
        $this->formMode =  $fromAdmin;
        $this->instanceId = $instanceId;
    }

    /**
     * @param FormBuilderInterface $builder
     * @param array $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        if ($this->formMode == 'add') {
            $builder ->add('countryId', 'choice', array(
                        'label' => 'bannertype.banner.form.country_id',
                        'choices' => $this->CountryArray,
                        'multiple' => false,
                        'required' => true,
                        'expanded' => true,
                )) ;
        }

        if ($this->formMode == 'update') {
            $builder->add('countryId', 'choice', array(
                    'label' => 'bannertype.banner.form.country_id',
                    'choices' => $this->CountryArray,
                    'multiple' => false,
                    'required' => true,
                    //'constraints' => array(new NotBlank(array('message' => 'service_group.culture.not_blank'))),
                    'expanded' => true,
                    'disabled' => true
            ));
        }

        $builder
            ->add('bannerName', 'text', array( 'label' => 'bannertype.banner.form.banner_name'))
            ->add('bannerTypeId', 'entity', array( 'class'=>'OfficeBrain\Bundle\BannerBundle\Entity\BannerMaster',
                'query_builder'=> function (\OfficeBrain\Bundle\BannerBundle\Entity\BannerMasterRepository $repository) {
                    return $repository->createQueryBuilder('b')->where('b.deletedAt is NULL and b.status = 1 and b.instanceId ='.$this->instanceId)->orderBy('b.id', 'ASC');},
                'label' => 'bannertype.banner.form.banner_type_name'));

        $builder->add('uploadedBanner', 'text', array( 'label' => 'bannertype.banner.form.upload_banner'));

        $builder->add('scheduleStartDate', 'date', array('format' => 'MM-dd-yyyy', 'label' => 'bannertype.banner.form.start_date', 'read_only' => true, 'widget' => 'single_text'))
            ->add('scheduleEndDate', 'date', array('format' => 'MM-dd-yyyy', 'label' => 'bannertype.banner.form.end_date', 'read_only' => true, 'widget' => 'single_text'))
            ->add('effect', 'choice', array(
                    'choices'  => array('1'=>'Custom Effect','2'=>'Fade in LR Chess', '3' =>'Rotate VDouble+ out',
                           '4' =>'Zoom HDouble+ out', '5'=>'Rotate Zoom+ out BL', '6' =>'Dodge Dance Inside in Random',
                            '7' =>'Rotate VFork+ out', '8'=>'Clip and Chess in', '9' =>'Rotate Zoom- out TL',
                           '10' =>'Rotate Zoom- in BR', '11'=>'Wave out Eagle', '12' =>'Expand Stairs', '13' => 'Fade Clip out H', '14' =>'Collapse Random'),
                    'label' => 'bannertype.banner.form.effect'
             ))
            ->add('html1effect', 'choice', array(
                    'choices'  => array("L"=>"L", "R"=>"R", "T"=>"T", "B"=>"B", "TR"=>"TR", "L|IB"=>"L|IB", "R|IB"=>"R|IB", "T|IB"=>"T|IB", "CLIP|LR"=>"CLIP|LR", "CLIP|TB"=>"CLIP|TB", "CLIP|L"=>"CLIP|L", "MCLIP|R"=>"MCLIP|R", "MCLIP|T"=>"MCLIP|T", "WV|B"=>"WV|B", "TORTUOUS|VB"=>"TORTUOUS|VB", "LISTH|R"=>"LISTH|R", "RTT|360"=>"RTT|360", "RTT|10"=>"RTT|10", "RTTL|BR"=>"RTTL|BR", "T|IE*IE"=>"T|IE*IE", "RTTS|R"=>"RTTS|R", "RTTS|T"=>"RTTS|T", "DDGDANCE|RB"=>"DDGDANCE|RB", "ZMF|10"=>"ZMF|10", "DDG|TR"=>"DDG|TR", "FLTTR|R"=>"FLTTR|R", "FLTTRWN|LT"=>"FLTTRWN|LT", "ATTACK|BR"=>"ATTACK|BR", "FADE"=>"FADE"),
                    'label' => 'bannertype.banner.form.effecthtml1'
             ))
            ->add('html2effect', 'choice', array(
                    'choices'  => array("L"=>"L", "R"=>"R", "T"=>"T", "B"=>"B", "TR"=>"TR", "L|IB"=>"L|IB", "R|IB"=>"R|IB", "T|IB"=>"T|IB", "CLIP|LR"=>"CLIP|LR", "CLIP|TB"=>"CLIP|TB", "CLIP|L"=>"CLIP|L", "MCLIP|R"=>"MCLIP|R", "MCLIP|T"=>"MCLIP|T", "WV|B"=>"WV|B", "TORTUOUS|VB"=>"TORTUOUS|VB", "LISTH|R"=>"LISTH|R", "RTT|360"=>"RTT|360", "RTT|10"=>"RTT|10", "RTTL|BR"=>"RTTL|BR", "T|IE*IE"=>"T|IE*IE", "RTTS|R"=>"RTTS|R", "RTTS|T"=>"RTTS|T", "DDGDANCE|RB"=>"DDGDANCE|RB", "ZMF|10"=>"ZMF|10", "DDG|TR"=>"DDG|TR", "FLTTR|R"=>"FLTTR|R", "FLTTRWN|LT"=>"FLTTRWN|LT", "ATTACK|BR"=>"ATTACK|BR", "FADE"=>"FADE"),
                    'label' => 'bannertype.banner.form.effecthtml2'
             ))
                    ->add('html3effect', 'choice', array(
                    'choices'  => array("L"=>"L", "R"=>"R", "T"=>"T", "B"=>"B", "TR"=>"TR", "L|IB"=>"L|IB", "R|IB"=>"R|IB", "T|IB"=>"T|IB", "CLIP|LR"=>"CLIP|LR", "CLIP|TB"=>"CLIP|TB", "CLIP|L"=>"CLIP|L", "MCLIP|R"=>"MCLIP|R", "MCLIP|T"=>"MCLIP|T", "WV|B"=>"WV|B", "TORTUOUS|VB"=>"TORTUOUS|VB", "LISTH|R"=>"LISTH|R", "RTT|360"=>"RTT|360", "RTT|10"=>"RTT|10", "RTTL|BR"=>"RTTL|BR", "T|IE*IE"=>"T|IE*IE", "RTTS|R"=>"RTTS|R", "RTTS|T"=>"RTTS|T", "DDGDANCE|RB"=>"DDGDANCE|RB", "ZMF|10"=>"ZMF|10", "DDG|TR"=>"DDG|TR", "FLTTR|R"=>"FLTTR|R", "FLTTRWN|LT"=>"FLTTRWN|LT", "ATTACK|BR"=>"ATTACK|BR", "FADE"=>"FADE"),
                    'label' => 'bannertype.banner.form.effecthtml3'
             ))
                    ->add('html4effect', 'choice', array(
                    'choices'  => array("L"=>"L", "R"=>"R", "T"=>"T", "B"=>"B", "TR"=>"TR", "L|IB"=>"L|IB", "R|IB"=>"R|IB", "T|IB"=>"T|IB", "CLIP|LR"=>"CLIP|LR", "CLIP|TB"=>"CLIP|TB", "CLIP|L"=>"CLIP|L", "MCLIP|R"=>"MCLIP|R", "MCLIP|T"=>"MCLIP|T", "WV|B"=>"WV|B", "TORTUOUS|VB"=>"TORTUOUS|VB", "LISTH|R"=>"LISTH|R", "RTT|360"=>"RTT|360", "RTT|10"=>"RTT|10", "RTTL|BR"=>"RTTL|BR", "T|IE*IE"=>"T|IE*IE", "RTTS|R"=>"RTTS|R", "RTTS|T"=>"RTTS|T", "DDGDANCE|RB"=>"DDGDANCE|RB", "ZMF|10"=>"ZMF|10", "DDG|TR"=>"DDG|TR", "FLTTR|R"=>"FLTTR|R", "FLTTRWN|LT"=>"FLTTRWN|LT", "ATTACK|BR"=>"ATTACK|BR", "FADE"=>"FADE"),
                    'label' => 'bannertype.banner.form.effecthtml4'
             ))
                    ->add('html5effect', 'choice', array(
                    'choices'  => array("L"=>"L", "R"=>"R", "T"=>"T", "B"=>"B", "TR"=>"TR", "L|IB"=>"L|IB", "R|IB"=>"R|IB", "T|IB"=>"T|IB", "CLIP|LR"=>"CLIP|LR", "CLIP|TB"=>"CLIP|TB", "CLIP|L"=>"CLIP|L", "MCLIP|R"=>"MCLIP|R", "MCLIP|T"=>"MCLIP|T", "WV|B"=>"WV|B", "TORTUOUS|VB"=>"TORTUOUS|VB", "LISTH|R"=>"LISTH|R", "RTT|360"=>"RTT|360", "RTT|10"=>"RTT|10", "RTTL|BR"=>"RTTL|BR", "T|IE*IE"=>"T|IE*IE", "RTTS|R"=>"RTTS|R", "RTTS|T"=>"RTTS|T", "DDGDANCE|RB"=>"DDGDANCE|RB", "ZMF|10"=>"ZMF|10", "DDG|TR"=>"DDG|TR", "FLTTR|R"=>"FLTTR|R", "FLTTRWN|LT"=>"FLTTRWN|LT", "ATTACK|BR"=>"ATTACK|BR", "FADE"=>"FADE"),
                    'label' => 'bannertype.banner.form.effecthtml5'
             ))
            ->add('bannerUrl', 'text', array( 'label' => 'bannertype.banner.form.banner_url',
            		'constraints' => array(new Assert\Regex(array('pattern' => "/^(https?:\/\/|http?:\/\/|HTTPS?:\/\/|HTTP?:\/\/)?([\da-zA-Z\.+-]+)\.([a-zA-Z\.]{2,6})([\/\w?=&\[\] \.+-]*)$/", 'message' => 'bannertype.form.website.invalid'))),
            	))
            ->add('htmlId', 'text', array( 'label' => 'bannertype.banner.form.html_id'))
            ->add('visibility', 'choice', array(
            		'choices'  => array('1'=>'bannertype.banner.list.both', '2' =>'bannertype.banner.list.public', '3' =>'bannertype.banner.list.private'),
            		'label' => 'bannertype.banner.form.visibility'
            ))
            ->add('status', 'choice', array(
                  'choices'  => array('1'=>'bannertype.banner.list.active', '0' =>'bannertype.banner.list.blocked'),
                  'label' => 'bannertype.banner.form.status'
                  ))
             ->add('urlstatus', 'choice', array(
                      'choices'  => array('1'=>'New Tab', '0' =>'Same Tab'),
                      'label' => 'Url Open In'
               ))
            ->add('bannerLanguage', 'collection', array('type' => new BannerLanguageType(), 'empty_data' => ''))

             ->add('bannerDescription', 'textarea', array( 'label' => 'Banner Description', 'required'=>false))
             ;

            /* ->add('save', 'submit', array(
                    'attr' => array('class' => 'save btn btn-default'),
            )); */
    }

    /**
     * @param OptionsResolverInterface $resolver
     */
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'OfficeBrain\Bundle\BannerBundle\Entity\Banner',
                'allow_extra_fields' => true
        ));
    }

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