<?php

namespace User\Form;

use Zend\Form\Element;
use Zend\Form\Form;
use Zend\Form\Element\Submit;
use Zend\Form\Element\Hidden;
use Zend\Validator\{
    NotEmpty,
    Digits
};
use Zend\InputFilter\InputFilterProviderInterface;

class ConfirmOtpForm extends Form implements InputFilterProviderInterface {

    public function __construct($name = null) {

        /**
         * Login Detail Form of Guide Registration
         */
        parent::__construct('confirm-form');
        $this->setAttribute('method', 'post');

        /**
         * username
         */
        $this->add([
            'name' => 'confirm_otp',
            'type' => 'text',
            'attributes' => [
                'id' => 'confirm-otp',
                'class' => 'form-control input-border',
                'onkeypress' => "return isNumber(event)",
            ],
            'options' => [
                'label' => 'Mobile OTP<span style="color: red"> *</span>',
                'label_options' => ['disable_html_escape' => true]
            ],
        ]);

        /**
         * Continue
         */
        $this->add([
            'name' => 'confirm_btn',
            'type' => 'Submit',
            'attributes' => [
                'value' => 'Verify OTP',               
                'class' => 'btn btn-primary btn-lg'
            ]
        ]);
    /**
         * Continue
         */
        $this->add([
            'name' => 'resentotp-btn',
            'type' => 'Submit',
            'attributes' => [
                'value' => 'Re-Send OTP',
                'label' => 'Submit',                
                'class' => 'btn btn-info btn-lg resend-otp-btn'
            ]
        ]);
        
        $this->add([
            'name' => 'resend_counter',
            'type' => Hidden::class,
            'attributes' => [
                'id'=>'resend-counter',
                'value' => '0',
            ]
        ]);
        
        $this->add([
            'name' => 'ticket_type',
            'type' => Hidden::class,
        ]);
    }

    public function getInputFilterSpecification() {
        return [
            'confirm_otp' => [
                'required' => true,
                'filters' => [
                    ['name' => 'StripTags'],
                    ['name' => 'StringTrim']
                ],
                'validators' => [
                    ['name' => 'NotEmpty',
                        'options' => [
                            'messages' => [
                                NotEmpty::IS_EMPTY => 'Please Enter OTP'
                            ]
                        ],
                        'break_chain_on_failure' => true
                    ],
                     ['name' => 'Digits',
                        'options' => [
                            'messages' => [
                                Digits::NOT_DIGITS => 'Please enter Numeric value only',
                            ],
                        ],
                        'break_chain_on_failure' => true,
                    ],
                ]
            ],
        ];
    }

}
