"use strict"; var iti, ajax_url = cwginstock.ajax_url, security_error = cwginstock.security_error, userid = cwginstock.user_id, emptyname = cwginstock.empty_name, emptyemail = cwginstock.empty_email, emptyquantity = cwginstock.empty_quantity, invalidemail = cwginstock.invalid_email, get_bot_type = cwginstock.get_bot_type, recaptcha_enabled = cwginstock.enable_recaptcha, recaptcha_site_key = cwginstock.recaptcha_site_key, recaptcha_verify_enabled = cwginstock.enable_recaptcha_verify, recaptcha_secret_present = cwginstock.recaptcha_secret_present, turnstile_enabled = cwginstock.enable_turnstile, turnstile_site_key = cwginstock.turnstile_site_key, is_iagree = cwginstock.is_iagree_enable, iagree_error = cwginstock.iagree_error, is_v3_recaptcha = cwginstock.is_v3_recaptcha, is_popup = cwginstock.is_popup, googlerecaptcha_widget_id = null, turnstile_widget_id = null, gtoken = "", phone_field = cwginstock.phone_field, subscriber_phone = "", phone_meta_data = "", phone_error = cwginstock.phone_field_error, is_phone_field_optional = cwginstock.is_phone_field_optional, is_quantity_field_optional = cwginstock.is_quantity_field_optional, hide_country_placeholder = cwginstock.hide_country_placeholder, default_country_code = cwginstock.default_country_code; function cwginstock_recaptcha_callback(e) { document.getElementsByClassName("cwgstock_button")[0].disabled = !1, "1" == recaptcha_verify_enabled && "yes" == recaptcha_secret_present && (document.getElementsByClassName("cwg-security")[0].value = e) } function cwginstock_turnstile_callback(e) { document.getElementsByClassName("cwgstock_button")[0].disabled = !1, document.getElementsByClassName("cwg-security")[0].value = e } var instock_notifier = { init: function () { "no" == is_popup && instock_notifier.generate_v3_response(), jQuery(document).on("click", ".cwgstock_button", this.submit_form), jQuery(".single_variation_wrap").on("show_variation", this.perform_upon_show_variation), "1" == phone_field && instock_notifier.initialize_phone() }, initialize_phone: function () { var e = document.querySelector(".cwgstock_phone"); e && (iti = window.intlTelInput(e, { allowDropdown: !0, formatOnDisplay: !0, autoHideDialCode: !1, separateDialCode: !0, utilsScript: cwginstock.phone_utils_js, initialCountry: default_country_code, customPlaceholder: function (e, t) { return (default_country_code = default_country_code.toLowerCase()) == t.iso2 && "2" == cwginstock.hide_country_placeholder ? "" != cwginstock.custom_country_placeholder ? cwginstock.custom_country_placeholder : e : "" } })) }, perform_upon_show_variation: function (e, t) { var c = t.variation_id; jQuery(".cwginstock-subscribe-form").hide(), jQuery(".cwginstock-subscribe-form-" + c).show(), "recaptcha" == get_bot_type ? "1" == recaptcha_enabled && instock_notifier.onloadcallback() : "1" == turnstile_enabled && instock_notifier.turnstilecallback(), "1" == phone_field && instock_notifier.initialize_phone() }, generate_v3_response: function () { "1" == recaptcha_enabled && "yes" == is_v3_recaptcha && grecaptcha.ready((function () { grecaptcha.execute(recaptcha_site_key, { action: "subscribe_form" }).then((function (e) { document.getElementsByClassName("cwg-security").length > 0 && (document.getElementsByClassName("cwg-security")[0].value = e, document.getElementsByClassName("cwgstock_button")[0].disabled = !1, gtoken = e) })) })) }, is_email: function (e) { return /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(e) }, submit_form: function (e) { e.preventDefault(); var t = jQuery(this), c = jQuery(this).closest(".cwginstock-subscribe-form").find(".cwgstock_name").val(), s = jQuery(this).closest(".cwginstock-subscribe-form").find(".cwgstock_email").val(), i = jQuery(this).closest(".cwginstock-subscribe-form").find(".add_quantity_field").val(); if (("" === i || i <= 0) && "2" == is_quantity_field_optional) return jQuery(this).closest(".cwginstock-subscribe-form").find(".cwgstock_output").fadeIn(), jQuery(this).closest(".cwginstock-subscribe-form").find(".cwgstock_output").html("
" + emptyquantity + "
"), !1; if ("1" == phone_field) { var o = iti.getNumber(); if (phone_meta_data = iti.getSelectedCountryData(), !iti.isValidNumber()) { var r = iti.getValidationError(), n = phone_error[r]; if (-99 == r && (n = phone_error[0]), -99 != r && "1" == is_phone_field_optional || "2" == is_phone_field_optional) return jQuery(this).closest(".cwginstock-subscribe-form").find(".cwgstock_output").fadeIn(), jQuery(this).closest(".cwginstock-subscribe-form").find(".cwgstock_output").html("" + n + "
"), !1 } } var a = jQuery(this).closest(".cwginstock-subscribe-form").find(".cwg-product-id").val(), l = jQuery(this).closest(".cwginstock-subscribe-form").find(".cwg-variation-id").val(); if ("" == c) return jQuery(this).closest(".cwginstock-subscribe-form").find(".cwgstock_output").fadeIn(), jQuery(this).closest(".cwginstock-subscribe-form").find(".cwgstock_output").html("" + emptyname + "
"), !1; if ("" == s) return jQuery(this).closest(".cwginstock-subscribe-form").find(".cwgstock_output").fadeIn(), jQuery(this).closest(".cwginstock-subscribe-form").find(".cwgstock_output").html("" + emptyemail + "
"), !1; if (!instock_notifier.is_email(s)) return jQuery(this).closest(".cwginstock-subscribe-form").find(".cwgstock_output").fadeIn(), jQuery(this).closest(".cwginstock-subscribe-form").find(".cwgstock_output").html("" + invalidemail + "
"), !1; if ("1" == is_iagree && !jQuery(this).closest(".cwginstock-subscribe-form").find(".cwg_iagree_checkbox_input").is(":checked")) return jQuery(this).closest(".cwginstock-subscribe-form").find(".cwgstock_output").fadeIn(), jQuery(this).closest(".cwginstock-subscribe-form").find(".cwgstock_output").html("" + iagree_error + "
"), !1; var u = jQuery(this).closest(".cwginstock-subscribe-form").find(".cwg-security").val(), _ = { action: "cwginstock_product_subscribe", product_id: a, variation_id: l, subscriber_name: c, subscriber_phone: o, subscriber_phone_meta: phone_meta_data, user_email: s, user_id: userid, security: u, dataobj: cwginstock, custom_quantity: i }; jQuery.fn.block ? t.closest(".cwginstock-subscribe-form").block({ message: null }) : jQuery('
').appendTo(t.closest(".cwginstock-subscribe-form")), instock_notifier.perform_ajax(_, t) }, recaptcha_callback: function (e) { document.getElementsByClassName("cwg-security").length > 0 && (document.getElementsByClassName("cwgstock_button")[0].disabled = !1, "1" == recaptcha_verify_enabled && "yes" == recaptcha_secret_present && (document.getElementsByClassName("cwg-security")[0].value = e)) }, turnstile_callback: function (e) { document.getElementsByClassName("cwg-security").length > 0 && (document.getElementsByClassName("cwgstock_button")[0].disabled = !1, document.getElementsByClassName("cwg-security")[0].value = e) }, onloadcallback: function () { "recaptcha" == get_bot_type && "1" == recaptcha_enabled && ("no" == is_v3_recaptcha ? jQuery("#cwg-google-recaptcha").length && (null === googlerecaptcha_widget_id ? googlerecaptcha_widget_id = grecaptcha.render("cwg-google-recaptcha", { sitekey: recaptcha_site_key, callback: this.recaptcha_callback }) : (grecaptcha.reset(googlerecaptcha_widget_id), this.recaptcha_callback(), googlerecaptcha_widget_id = null, instock_notifier.onloadcallback())) : instock_notifier.generate_v3_response()) }, turnstilecallback: function () { "turnstile" == get_bot_type && "1" == turnstile_enabled && jQuery("#cwg-turnstile-captcha").length && (null === turnstile_widget_id ? turnstile_widget_id = turnstile.render("#cwg-turnstile-captcha", { sitekey: turnstile_site_key, theme: "light", callback: this.turnstile_callback }) : (turnstile.reset(turnstile_widget_id), this.turnstile_callback(), turnstile_widget_id = null, instock_notifier.turnstilecallback())) }, resetcallback: function () { "recaptcha" == get_bot_type ? "1" == recaptcha_enabled && ("no" == is_v3_recaptcha ? (grecaptcha.reset(), document.getElementsByClassName("cwgstock_button")[0].disabled = !0) : instock_notifier.generate_v3_response()) : "1" == turnstile_enabled && (turnstile.reset(), document.getElementsByClassName("cwgstock_button")[0].disabled = !0) }, perform_ajax: function (e, t) { jQuery.ajax({ type: "post", url: ajax_url, data: e, beforeSend: function (e) { e.setRequestHeader("X-WP-Nonce", cwginstock.security) }, success: function (c) { c = c.msg, t.closest(".cwginstock-subscribe-form").find(".cwgstock_output").fadeIn(2e3), t.closest(".cwginstock-subscribe-form").find(".cwgstock_output").html(c), jQuery.fn.block ? t.closest(".cwginstock-subscribe-form").unblock() : t.closest(".cwginstock-subscribe-form").find("#cwg-bis-overlay").fadeOut(400, (function () { t.closest(".cwginstock-subscribe-form").find("#cwg-bis-overlay").remove() })), instock_notifier.resetcallback(), jQuery(document).trigger("cwginstock_success_ajax", e) }, error: function (c, s, i) { void 0 !== c.responseJSON && c.responseJSON.hasOwnProperty("code") && void 0 !== c.responseJSON.code && ("rest_cookie_invalid_nonce" != c.responseJSON.code && "cwg_nonce_verify_failed" != c.responseJSON.code || (c.responseText = -1)), "-1" !== c.responseText && -1 !== c.responseText || (t.closest(".cwginstock-subscribe-form").find(".cwgstock_output").fadeIn(2e3), t.closest(".cwginstock-subscribe-form").find(".cwgstock_output").html("" + security_error + "
")), jQuery.fn.block ? t.closest(".cwginstock-subscribe-form").unblock() : t.closest(".cwginstock-subscribe-form").find("#cwg-bis-overlay").fadeOut(400, (function () { t.closest(".cwginstock-subscribe-form").find("#cwg-bis-overlay").remove() })), instock_notifier.resetcallback(), jQuery(document).trigger("cwginstock_error_ajax", e) } }) } }; instock_notifier.init();