jQuery(document).ready(function () {
    $mo = jQuery;
    var sendOtpButtonHtml = '<p class="form-row"><input type="button" id="mo_wc_send_otp" name="mosendotp" value="' + mowcpvreg.buttontext + '"></button></p>';
    var loadingImageHtml = "<img src='" + mowcpvreg.imgURL + "'>";
    var otpFormElementsHtml = sendOtpButtonHtml + "<div id='mo_message_pv' hidden='' style='background-color: #f7f6f7;padding: 1em 2em 1em 3.5em;'>" + loadingImageHtml + "</div>";
    var verificationPhoneFieldHtml =
        '<p class="form-row form-row-wide"><label for="reg_vp_verification_phone">' +
        mowcpvreg.codeLabel +
        '<span class="required">*</span></label><input type="text" class="input-text" name="moverify" id="reg_vp_verification_phone" value="" /></p>';
    $mo(otpFormElementsHtml).insertAfter($mo("label[for='" + mowcpvreg.field + "']").parent());
    $mo(verificationPhoneFieldHtml).insertAfter($mo("#mo_message_pv"));
    $mo("#mo_wc_send_otp").click(function () {
        var userInput = $mo("input[id^=" + mowcpvreg.field + "]").val();
        $mo("#mo_message_pv").empty(), $mo("#mo_message_pv").append(loadingImageHtml), $mo("#mo_message_pv").show();
        $mo.ajax({
            url: mowcpvreg.siteURL,
            type: "POST",
            data: { user_email: userInput, user_phone: userInput, security: mowcpvreg.nonce, action: "miniorange_wc_vp_reg_verify" },
            crossDomain: !0,
            dataType: "json",
            success: function (response) {
                if (response.result == "success") {
                    $mo("#mo_message_pv").empty(), $mo("#mo_message_pv").append(response.message), $mo("#mo_message_pv").css("border-top", "3px solid green");
                } else {
                    $mo("#mo_message_pv").empty(), $mo("#mo_message_pv").append(response.message), $mo("#mo_message_pv").css("border-top", "3px solid red");
                }
            },
            error: function (response) {},
        });
    });
});
