jQuery(document).ready(function () {
    $mo = jQuery;
    var paymentMethods = mowccheckout.paymentMethods,
        isPopupEnabled = mowccheckout.popupEnabled && !mowccheckout.isLoggedIn;
    $mo("#order_verify_field").hide();
    var showOtpFields = function () {
            $mo(".woocommerce-billing-fields").length > 0 &&
                ($mo("#miniorange_wc_otp_token_submit").show(),
                $mo("#miniorange_wc_otp_token_submit").css({ "margin-right": "0" }),
                $mo("#mo_validation_wrapper").insertAfter("#billing_" + mowccheckout.otpType + "_field"),
                $mo("#order_verify_field").length > 0 ? $mo("#order_verify_field").show() : isPopupEnabled && $mo("#place_order").hide());
        },
        hideOtpFields = function () {
            $mo(".woocommerce-billing-fields").length > 0 &&
                ($mo("#miniorange_wc_otp_token_submit").hide(), $mo("#order_verify_field").length > 0 ? ($mo("#order_verify_field").hide(), $mo("#mo_message").hide(), $mo("#order_verify").val("")) : $mo("#place_order").show());
        },
        checkPaymentMethodAndToggleOtp = function () {
            var shouldShowOtp = !mowccheckout.selectivePaymentEnabled;
            $mo("input[name=payment_method]").each(function () {
                var paymentMethodValue = $mo(this).val();
                if (((shouldShowOtp = !1), ($mo(this).is(":checked") && paymentMethods.hasOwnProperty(paymentMethodValue)) || !mowccheckout.selectivePaymentEnabled)) return (shouldShowOtp = !0), !1;
            }),
                shouldShowOtp ? showOtpFields() : hideOtpFields();
        };
    setTimeout(function () {
        checkPaymentMethodAndToggleOtp(),
            $mo(".woocommerce-checkout-review-order").click(function () {
                checkPaymentMethodAndToggleOtp();
            });
    }, 200),
        $mo(document).ajaxComplete(function (event, xhr, settings) {
            settings.url.includes("wc-ajax=update_order_review") && checkPaymentMethodAndToggleOtp();
        });
});
