<?php


namespace OTP\Objects;

use OTP\Helper\FormList;
use OTP\Helper\FormSessionVars;
use OTP\Helper\MoConstants;
use OTP\Helper\MoMessages;
use OTP\Helper\MoUtility;
use OTP\Helper\SessionUtils;
class FormHandler
{
    protected $_typePhoneTag;
    protected $_typeEmailTag;
    protected $_typeBothTag;
    protected $_formKey;
    protected $_formName;
    protected $_otpType;
    protected $_phoneFormId;
    protected $_isFormEnabled;
    protected $_restrictDuplicates;
    protected $_byPassLogin;
    protected $_isLoginOrSocialForm;
    protected $_isAjaxForm;
    protected $_phoneKey;
    protected $_emailKey;
    protected $_buttonText;
    protected $_formDetails;
    protected $_disableAutoActivate;
    protected $_formSessionVar;
    protected $_formSessionVar2;
    protected $_nonce = "\146\157\x72\x6d\137\156\x6f\x6e\143\x65";
    protected $_txSessionId = FormSessionVars::TX_SESSION_ID;
    protected $_formOption = "\x6d\157\137\143\x75\x73\x74\x6f\x6d\145\162\x5f\x76\141\154\151\144\x61\164\151\157\156\x5f\x73\145\x74\164\151\x6e\x67\163";
    protected $_generateOTPAction;
    protected $_validateOTPAction;
    protected $_nonceKey = "\163\x65\143\165\x72\151\164\171";
    protected $_isAddOnForm = FALSE;
    protected $_formDocuments = array();
    const VALIDATED = "\x56\x41\x4c\x49\x44\x41\x54\105\104";
    const VERIFICATION_FAILED = "\x76\145\162\151\146\151\143\x61\x74\151\x6f\156\137\146\x61\151\x6c\145\x64";
    const VALIDATION_CHECKED = "\166\141\x6c\151\144\141\x74\151\157\156\x43\x68\145\143\153\145\x64";
    protected function __construct()
    {
        add_action("\141\x64\155\x69\x6e\137\151\156\151\x74", array($this, "\150\141\156\144\154\145\x46\157\162\155\x4f\x70\x74\x69\x6f\156\x73"), 2);
        if (!(!MoUtility::micr() || !$this->isFormEnabled())) {
            goto W8;
        }
        return;
        W8:
        add_action("\151\x6e\x69\164", array($this, "\x68\x61\x6e\x64\x6c\145\x46\157\x72\x6d"), 1);
        add_filter("\x6d\157\137\x70\150\x6f\x6e\x65\137\x64\x72\157\160\x64\157\x77\x6e\x5f\x73\145\x6c\145\x63\164\157\162", array($this, "\x67\x65\x74\120\x68\157\156\145\x4e\x75\155\x62\145\x72\x53\x65\x6c\145\x63\164\x6f\162"), 1, 1);
        if (!(SessionUtils::isOTPInitialized($this->_formSessionVar) || SessionUtils::isOTPInitialized($this->_formSessionVar2))) {
            goto Uo;
        }
        add_action("\x6f\x74\160\137\166\145\162\151\x66\151\x63\x61\164\x69\x6f\156\x5f\x73\x75\x63\143\145\163\x73\146\165\154", array($this, "\x68\x61\156\144\154\x65\x5f\160\x6f\x73\x74\137\166\x65\162\151\x66\x69\x63\x61\164\151\x6f\x6e"), 1, 7);
        add_action("\157\164\x70\x5f\166\x65\162\151\x66\151\x63\141\164\x69\x6f\x6e\x5f\x66\141\151\154\x65\x64", array($this, "\x68\x61\x6e\x64\154\145\137\x66\141\x69\x6c\x65\x64\137\166\x65\162\x69\x66\x69\x63\x61\x74\x69\157\156"), 1, 4);
        add_action("\165\x6e\163\145\164\x5f\x73\145\163\x73\151\x6f\156\x5f\166\x61\162\x69\141\x62\154\145", array($this, "\165\156\163\145\x74\x4f\x54\x50\x53\145\163\163\x69\x6f\156\x56\141\162\x69\x61\142\x6c\145\x73"), 1, 0);
        Uo:
        add_filter("\151\x73\137\x61\152\x61\x78\137\146\157\x72\155", array($this, "\151\163\137\141\152\x61\170\137\x66\x6f\x72\155\137\151\x6e\x5f\160\x6c\x61\x79"), 1, 1);
        add_filter("\x69\x73\x5f\x6c\157\x67\x69\156\x5f\157\162\137\x73\157\x63\151\141\x6c\137\146\157\x72\x6d", array($this, "\151\163\114\x6f\x67\151\156\117\x72\x53\x6f\x63\151\141\x6c\x46\x6f\x72\x6d"), 1, 1);
        $Ko = FormList::instance();
        $Ko->add($this->getFormKey(), $this);
    }
    public function isLoginOrSocialForm($e4)
    {
        return SessionUtils::isOTPInitialized($this->_formSessionVar) ? $this->getisLoginOrSocialForm() : $e4;
    }
    public function is_ajax_form_in_play($Sy)
    {
        return SessionUtils::isOTPInitialized($this->_formSessionVar) ? $this->_isAjaxForm : $Sy;
    }
    public function sanitizeFormPOST($nV, $dL = null)
    {
        $nV = ($dL === null ? "\x6d\157\137\143\165\x73\x74\x6f\x6d\x65\162\137\x76\141\x6c\x69\x64\141\164\x69\x6f\x6e\x5f" : '') . $nV;
        return MoUtility::sanitizeCheck($nV, $_POST);
    }
    public function sendChallenge($te, $j4, $errors, $sP = null, $c2 = "\x65\155\x61\151\154", $xy = '', $yJ = null, $DF = false)
    {
        do_action("\155\157\x5f\x67\145\x6e\145\162\141\164\x65\x5f\x6f\x74\160", $te, $j4, $errors, $sP, $c2, $xy, $yJ, $DF);
    }
    public function validateChallenge($Cw, $ZT = "\155\157\x5f\157\164\160\x5f\x74\157\153\x65\156", $we = NULL)
    {
        do_action("\155\x6f\137\166\x61\x6c\151\x64\x61\164\145\137\x6f\x74\160", $Cw, $ZT, $we);
    }
    public function basicValidationCheck($Kl)
    {
        if (!($this->isFormEnabled() && MoUtility::isBlank($this->_otpType))) {
            goto qs;
        }
        do_action("\x6d\157\137\x72\145\147\x69\x73\x74\162\141\164\151\x6f\x6e\x5f\163\x68\x6f\x77\x5f\155\x65\x73\x73\141\x67\x65", MoMessages::showMessage($Kl), MoConstants::ERROR);
        return false;
        qs:
        return true;
    }
    public function getVerificationType()
    {
        $ez = array($this->_typePhoneTag => VerificationType::PHONE, $this->_typeEmailTag => VerificationType::EMAIL, $this->_typeBothTag => VerificationType::BOTH);
        return MoUtility::isBlank($this->_otpType) ? false : $ez[$this->_otpType];
    }
    protected function validateAjaxRequest()
    {
        if (check_ajax_referer($this->_nonce, $this->_nonceKey)) {
            goto RL;
        }
        wp_send_json(MoUtility::createJson(MoMessages::showMessage(BaseMessages::INVALID_OP), MoConstants::ERROR_JSON_TYPE));
        die;
        RL:
    }
    protected function ajaxProcessingFields()
    {
        $ez = array($this->_typePhoneTag => array(VerificationType::PHONE), $this->_typeEmailTag => array(VerificationType::EMAIL), $this->_typeBothTag => array(VerificationType::PHONE, VerificationType::EMAIL));
        return $ez[$this->_otpType];
    }
    public function getPhoneHTMLTag()
    {
        return $this->_typePhoneTag;
    }
    public function getEmailHTMLTag()
    {
        return $this->_typeEmailTag;
    }
    public function getBothHTMLTag()
    {
        return $this->_typeBothTag;
    }
    public function getFormKey()
    {
        return $this->_formKey;
    }
    public function getFormName()
    {
        return $this->_formName;
    }
    public function getOtpTypeEnabled()
    {
        return $this->_otpType;
    }
    public function disableAutoActivation()
    {
        return $this->_disableAutoActivate;
    }
    public function getPhoneKeyDetails()
    {
        return $this->_phoneKey;
    }
    public function getEmailKeyDetails()
    {
        return $this->_emailKey;
    }
    public function isFormEnabled()
    {
        return $this->_isFormEnabled;
    }
    public function getButtonText()
    {
        return mo_($this->_buttonText);
    }
    public function getFormDetails()
    {
        return $this->_formDetails;
    }
    public function restrictDuplicates()
    {
        return $this->_restrictDuplicates;
    }
    public function bypassForLoggedInUsers()
    {
        return $this->_byPassLogin;
    }
    public function getisLoginOrSocialForm()
    {
        return (bool) $this->_isLoginOrSocialForm;
    }
    public function getFormOption()
    {
        return $this->_formOption;
    }
    public function isAjaxForm()
    {
        return $this->_isAjaxForm;
    }
    public function isAddOnForm()
    {
        return $this->_isAddOnForm;
    }
    public function getFormDocuments()
    {
        return $this->_formDocuments;
    }
}
