<?php

namespace PointToPoint\Form;

use Zend\Form\Form;
use Zend\Form\Element\{
    Select,
    Date,
    Number,
    Checkbox,
    Text,
    Submit,
    Hidden
};
use Zend\Validator\{
    NotEmpty,
    Digits
};
use Zend\InputFilter\InputFilterProviderInterface;
use Zend\InputFilter\InputFilter;

class VehicleSearchForm extends Form implements InputFilterProviderInterface {

    public function __construct($name = null) {

        parent::__construct('point-to-point-search-form');
        $this->setAttribute('method', 'post');
        $this->setAttribute('autocomplete', 'off');
        /**
         * Pickup City
         */
        $this->add([
            'name' => 'pickup_city',
            'type' => Text::class,
            'attributes' => [
                'id' => 'pickup-city',
                'class' => 'inputMaterial pickup-city'
            ],
            'options' => [
                'label' => 'City<span style="color: red"> *</span>',
                'label_options' => ['disable_html_escape' => true],
                'disable_inarray_validator' => true
            ],
        ]);

        /**
         * Pickup AreasetAttribute
         */
        $this->add([
            'name' => 'pickup_area',
            'type' => Text::class,
            'attributes' => [
                'id' => 'pickup-area',
                'class' => 'inputMaterial'
            ],
            'options' => [
                'label' => 'Pickup Area<span style="color: red"> *</span>',
                'label_options' => ['disable_html_escape' => true]
            ],
        ]);

        /**
         * Drop Area
         */
        $this->add([
            'name' => 'drop_area',
            'type' => Text::class,
            'attributes' => [
                //'id' => 'drop-area',
                'id' => 'ptp-drop-address',
                'class' => 'inputMaterial',
                'placeholder'=> ''
            ],
            'options' => [
                'label' => 'Drop Area / Address<span style="color: red"> *</span>',
                'label_options' => ['disable_html_escape' => true]
            ],
        ]);

        /**
         * Pickup Address
         */
        $this->add([
            'name' => 'pickup_address',
            'type' => Text::class,
            'attributes' => [
                'id' => 'pickup-address',
                'class' => 'inputMaterial',
                'placeholder'=> ''
            ],
            'options' => [
                'label' => 'Pickup Address<span style="color: red"> *</span>',
                'label_options' => ['disable_html_escape' => true]
            ],
        ]);

        /**
         * Hidden fields for pickup now
         */
        $this->add([
            'name' => 'pickup_now_selected',
            'type' => Hidden::class,
            'attributes' => [
                'id' => 'pickup-now-selected',
                'class' => 'inputMaterial'
            ]
        ]);

        /**
         * Hidden fields for pickup later
         */
        $this->add([
            'name' => 'pickup_later_selected',
            'type' => Hidden::class,
            'attributes' => [
                'id' => 'pickup-later-selected',
                'class' => 'inputMaterial'
            ]
        ]);

        /**
         * Pickup Date
         */
        $this->add([
            'name' => 'pickup_date',
            'type' => Text::class,
            'attributes' => [
                'id' => 'pickup-date',
                'placeholder' => 'Date',
                'class' => 'inputMaterial datepicker',
            ],
        ]);

        /**
         * Pickup Time
         */
        $this->add([
            'name' => 'pickup_time',
            'type' => Text::class,
            'attributes' => [
                'id' => 'pickup-time',
                'placeholder' => 'Time',
                'class' => 'inputMaterial'
            ],
        ]);

        /**
         * Number of Adults
         */
        $this->add([
            'type' => Number::class,
            'name' => 'adults',
            'attributes' => [
                'id' => 'adults',
                'class' => 'inputMaterial',
                'min' => 0,
                'max' => 9,
                'step' => 1,
                'value' => 1
            ],
            'options' => [
                'label' => 'Adults',
            ],
        ]);

        /**
         * Number of Childs
         */
        $this->add([
            'type' => Number::class,
            'name' => 'childs',
            'attributes' => [
                'id' => 'childs',
                'class' => 'inputMaterial',
                'min' => 0,
                'max' => 9,
                'step' => 1,
                'value' => 0
            ],
            'options' => [
                'label' => 'Childs',
            ],
        ]);

        /**
         * Number of Luggages
         */
        $this->add([
            'type' => Number::class,
            'name' => 'luggages',
            'attributes' => [
                'id' => 'luggages',
                'class' => 'inputMaterial',
                'min' => 0,
                'max' => 9,
                'step' => 1,
                'value' => 0
            ],
            'options' => [
                'label' => 'Luggages',
            ],
        ]);

        /**
         * Number of Vehicles
         */
        $this->add([
            'type' => Number::class,
            'name' => 'no_of_vehicles',
            'attributes' => [
                'id' => 'no-of-vehicles',
                'class' => 'inputMaterial',
                'min' => 1,
                'max' => 9,
                'step' => 1,
                'value' => 1
            ],
            'options' => [
                'label' => 'Vehicles',
            ],
        ]);

        /**
         * Accept the Terms and Conditions
         */
        $this->add([
            'name' => 'agree_terms',
            'type' => Checkbox::class,
            'attributes' => [
                'id' => 'agree-terms',
            ],
            'options' => [
                'label' => 'Accept the Terms and Conditions',
                'checked_value' => '1',
                'unchecked_value' => 'no',
                'use_hidden_element' => true
            ],
        ]);

        /**
         * Search a Car
         */
        $this->add([
            'name' => 'search_a_car',
            'type' => Submit::class,
            'attributes' => [
                'value' => 'Search a Car',
                'id' => 'search-a-car',
                'class' => 'btn btn-primary btn-lg'
            ],
        ]);

        /**
         * Form Type
         */
        $this->add([
            'name' => 'form_type',
            'type' => Hidden::class,
            'attributes' => [
                'value' => 'car_search_form',
            ],
        ]);

        /**
         * Pickup Area Value
         */
        $this->add([
            'name' => 'pickup_area_value',
            'type' => Hidden::class,
            'attributes' => [
                'value' => '',
                'id' => 'pickup-area-value'
            ],
        ]);

        /**
         * Drop Area Value
         */
        $this->add([
            'name' => 'drop_area_value',
            'type' => Hidden::class,
            'attributes' => [
                'value' => '',
                'id' => 'drop-area-value'
            ],
        ]);

        $this->add([
            'name' => 'master_package_type',
            'type' => Hidden::class,
            'attributes' => [
                'id' => 'master-package-type',
                'class' => 'inputMaterial'
            ]
        ]);

        $this->add([
            'name' => 'city_id',
            'type' => Hidden::class,
            'attributes' => [
                'id' => 'city-id',
                'class' => 'inputMaterial'
            ]
        ]);

        $this->add([
            'name' => 'city_latitude',
            'type' => Hidden::class,
            'attributes' => [
                'id' => 'city-latitude',
                'class' => 'inputMaterial'
            ]
        ]);

         $this->add([
            'name' => 'city_longitude',
            'type' => Hidden::class,
            'attributes' => [
                'id' => 'city-longitude',
                'class' => 'inputMaterial'
            ]
        ]);

        ///////////////


         $this->add([
            'name' => 'city_northeast_latitude',
            'type' => Hidden::class,
            'attributes' => [
                'id' => 'city-northeast-latitude',
                'class' => 'inputMaterial'
            ]
        ]);

         $this->add([
            'name' => 'city_northeast_longitude',
            'type' => Hidden::class,
            'attributes' => [
                'id' => 'city-northeast-longitude',
                'class' => 'inputMaterial'
            ]
        ]);

        $this->add([
            'name' => 'city_southwest_latitude',
            'type' => Hidden::class,
            'attributes' => [
                'id' => 'city-southwest-latitude',
                'class' => 'inputMaterial'
            ]
        ]);

         $this->add([
            'name' => 'city_southwest_longitude',
            'type' => Hidden::class,
            'attributes' => [
                'id' => 'city-southwest-longitude',
                'class' => 'inputMaterial'
            ]
        ]);

        /**
         * Nationality
         */
        $this->add([
            'name' => 'nationality',
            'type' => Text::class,
            'attributes' => [
                'id' => 'nationality',
                'class' => 'inputMaterial country-class'
            ],
            'options' => [
                'label' => 'Nationality<span style="color: red"> *</span>',
                'label_options' => ['disable_html_escape' => true],
            ],
        ]);
    }

    public function getInputFilterSpecification() {
        return [
            'pickup_city' => [
                'required' => true,
                'filters' => [
                    ['name' => 'StripTags'],
                    ['name' => 'StringTrim']
                ],
                'validators' => [
                    ['name' => 'NotEmpty',
                        'options' => [
                            'messages' => [
                                NotEmpty::IS_EMPTY => 'Please select City'
                            ]
                        ],
                        'break_chain_on_failure' => true
                    ]
                ]
            ],
            'pickup_area' => [
                'required' => true,
                'filters' => [
                    ['name' => 'StripTags'],
                    ['name' => 'StringTrim']
                ],
                'validators' => [
                    ['name' => 'NotEmpty',
                        'options' => [
                            'messages' => [
                                NotEmpty::IS_EMPTY => 'Please Select Pickup Area'
                            ]
                        ],
                        'break_chain_on_failure' => true
                    ]
                ]
            ],
            'drop_area' => [
                'required' => true,
                'filters' => [
                    ['name' => 'StripTags'],
                    ['name' => 'StringTrim']
                ],
                'validators' => [
                    ['name' => 'NotEmpty',
                        'options' => [
                            'messages' => [
                                NotEmpty::IS_EMPTY => 'Please Select Drop Area'
                            ]
                        ],
                        'break_chain_on_failure' => true
                    ]
                ]
            ],
            'pickup_address' => [
                'required' => true,
                'filters' => [
                    ['name' => 'StripTags'],
                    ['name' => 'StringTrim']
                ],
                'validators' => [
                    ['name' => 'NotEmpty',
                        'options' => [
                            'messages' => [
                                NotEmpty::IS_EMPTY => 'Please select Pickup Address'
                            ]
                        ],
                        'break_chain_on_failure' => true
                    ]
                ]
            ],
            'nationality' => [
                'required' => true,
                'filters' => [
                    ['name' => 'StripTags'],
                    ['name' => 'StringTrim']
                ],
                'validators' => [
                    ['name' => 'NotEmpty',
                        'options' => [
                            'messages' => [
                                NotEmpty::IS_EMPTY => 'Please select Nationality'
                            ]
                        ],
                        'break_chain_on_failure' => true
                    ]
                ]
            ],
            'pickup_date' => [
                'required' => false,
                'filters' => [
                    ['name' => 'StripTags'],
                    ['name' => 'StringTrim']
                ],
                'validators' => [
                    ['name' => 'NotEmpty',
                        'options' => [

                            'messages' => [
                                NotEmpty::IS_EMPTY => 'Please enter Pickup Date'
                            ]
                        ],
                    ],
                    ['name' => 'Date',
                        'options' => [
                             'format'=>'d-m-Y',
                            'messages' => [
                                //Date::INVALID_DATE => '',
                                \Zend\Validator\Date::INVALID_DATE => 'Please enter Valid Date',
                            ],
                        ],
                        'break_chain_on_failure' => true
                    ],
                ]
            ],
            'pickup_time' => [
                'required' => false,
                'filters' => [
                    ['name' => 'StripTags'],
                    ['name' => 'StringTrim']
                ],
                'validators' => [
                    ['name' => 'NotEmpty',
                        'options' => [
                            'messages' => [
                                NotEmpty::IS_EMPTY => 'Please enter Pickup Time'
                            ]
                        ],
                        'break_chain_on_failure' => true
                    ]
                ]
            ],
            'adults' => [
                'required' => true,
                'filters' => [
                    ['name' => 'StripTags'],
                    ['name' => 'StringTrim']
                ],
                'validators' => [
                    ['name' => 'StringLength',
                        'options' => [
                            'min' => 1,
                            'max' => 9
                        ]
                    ],
                    ['name' => 'Digits',
                        'break_chain_on_failure' => true,
                        'options' => [
                            'messages' => [
                                Digits::NOT_DIGITS => 'Please select Number of Adult'
                            ]
                        ],
                    ],
                ]
            ],
            'childs' => [
                'required' => true,
                'filters' => [
                    ['name' => 'StripTags'],
                    ['name' => 'StringTrim']
                ],
                'validators' => [
                    ['name' => 'StringLength',
                        'options' => [
                            'min' => 1,
                            'max' => 9
                        ]
                    ],
                    ['name' => 'Digits',
                        'break_chain_on_failure' => true,
                        'options' => [
                            'messages' => [
                                Digits::NOT_DIGITS => 'Please select Number of Child'
                            ]
                        ],
                    ],
                ]
            ],
            'luggages' => [
                'required' => true,
                'filters' => [
                    ['name' => 'StripTags'],
                    ['name' => 'StringTrim']
                ],
                'validators' => [
                    ['name' => 'StringLength',
                        'options' => [
                            'min' => 1,
                            'max' => 9
                        ]
                    ],
                    ['name' => 'Digits',
                        'break_chain_on_failure' => true,
                        'options' => [
                            'messages' => [
                                Digits::NOT_DIGITS => 'Please select Number of Luggage'
                            ]
                        ],
                    ],
                ]
            ],
            'no_of_vehicles' => [
                'required' => true,
                'filters' => [
                    ['name' => 'StripTags'],
                    ['name' => 'StringTrim']
                ],
                'validators' => [
                    ['name' => 'StringLength',
                        'options' => [
                            'min' => 1,
                            'max' => 9
                        ]
                    ],
                    ['name' => 'Digits',
                        'break_chain_on_failure' => true,
                        'options' => [
                            'messages' => [
                                Digits::NOT_DIGITS => 'Please select Number of Vehicles'
                            ]
                        ],
                    ],
                ]
            ],
            'agree_terms' => [
                'required' => false,
                'validators' => [
                    ['name' => 'Digits',
                        'break_chain_on_failure' => true,
                        'options' => [
                            'messages' => [
                                Digits::NOT_DIGITS => 'Please Accept the Terms and Conditions',
                            ],
                        ],
                    ],
                ],
            ],
        ];
    }

}
