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