<?php

namespace OfficeBrain\Bundle\FlipBookBundle\Form;

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

class FlipBookType extends AbstractType
{
    /**
     * @param FormBuilderInterface $builder
     * @param array $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('title','text', array (
                    'required'  => false,
                    'constraints' => array(
                        new Constraints\NotBlank(array('message' => 'Please enter title')),
                    ),
                ))
            ->add('noOfRows','number', array (
                    'required'  => false,
                    'constraints' => array(
                        new Constraints\NotBlank(array('message' => 'Please enter no of row')),
                         new Constraints\Regex(array(
                            'pattern' => '/^\d+$/', // This allows only digits (0-9)
                            'message' => 'Please enter a valid number.'
                        )),
                    ),
                ))
            ->add('embedLink','text', array (
                    'required'  => false,
                    'constraints' => array(
                        new Constraints\NotBlank(array('message' => 'Please enter embed link')),
                    ),
                ))
            ->add('status', 'choice', array(
                'choices' => array('Active' => 'Active', 'Inactive' => 'Inactive'),

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

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