"use strict"; var cwginstock_iti, cwginstock_ajax_url=cwginstock.ajax_url, cwginstock_security_error=cwginstock.security_error, cwginstock_userid=cwginstock.user_id, cwginstock_emptyname=cwginstock.empty_name, cwginstock_emptyemail=cwginstock.empty_email, cwginstock_emptyquantity=cwginstock.empty_quantity, cwginstock_invalidemail=cwginstock.invalid_email, cwginstock_get_bot_type=cwginstock.get_bot_type, cwginstock_recaptcha_enabled=cwginstock.enable_recaptcha, cwginstock_recaptcha_site_key=cwginstock.recaptcha_site_key, cwginstock_recaptcha_verify_enabled=cwginstock.enable_recaptcha_verify, cwginstock_recaptcha_secret_present=cwginstock.recaptcha_secret_present, cwginstock_turnstile_enabled=cwginstock.enable_turnstile, cwginstock_turnstile_site_key=cwginstock.turnstile_site_key, cwginstock_is_iagree=cwginstock.is_iagree_enable, cwginstock_iagree_error=cwginstock.iagree_error, cwginstock_is_v3_recaptcha=cwginstock.is_v3_recaptcha, cwginstock_is_popup=cwginstock.is_popup, cwginstock_googlerecaptcha_widget_id=null, cwginstock_turnstile_widget_id=null, cwginstock_gtoken="", cwginstock_phone_field=cwginstock.phone_field, cwginstock_subscriber_phone="", cwginstock_phone_meta_data="", cwginstock_phone_error=cwginstock.phone_field_error, cwginstock_is_phone_field_optional=cwginstock.is_phone_field_optional, cwginstock_is_quantity_field_optional=cwginstock.is_quantity_field_optional, cwginstock_hide_country_placeholder=cwginstock.hide_country_placeholder, cwginstock_default_country_code=cwginstock.default_country_code; function cwginstock_recaptcha_callback(t){ document.getElementsByClassName("cwgstock_button")[0].disabled = !1, "1"==cwginstock_recaptcha_verify_enabled&&"yes"==cwginstock_recaptcha_secret_present&&(document.getElementsByClassName("cwg-security")[0].value=t) } function cwginstock_turnstile_callback(t){ document.getElementsByClassName("cwgstock_button")[0].disabled = !1, document.getElementsByClassName("cwg-security")[0].value=t } function cwgdetectTurnstileByHiddenInput(t=4e3){ let c=0; const e=setInterval((()=> { if(document.querySelector('input[name="cf-turnstile-response"][id^="cf-chl-widget-"]')) clearInterval(e); else if(c >=t){ clearInterval(e); const t=document.querySelector(".cf-turnstile"); if(t){ const c=document.createElement("div"); c.id="cwg-turnstile-captcha", t.replaceWith(c), instock_notifier.turnstilecallback() }} c +=100 }), 100) } "turnstile"==cwginstock_get_bot_type&&"1"==cwginstock_turnstile_enabled&&window.addEventListener("load", cwgdetectTurnstileByHiddenInput); var instock_notifier={ init: function (){ "no"==cwginstock_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"==cwginstock_phone_field&&instock_notifier.initialize_phone() }, initialize_phone: function (){ var t=document.querySelector(".cwgstock_phone"); t&&(cwginstock_iti=window.intlTelInput(t, { allowDropdown: !0, formatOnDisplay: !0, autoHideDialCode: !1, separateDialCode: !0, initialCountry: cwginstock_default_country_code, customPlaceholder: function (t, c){ return (cwginstock_default_country_code=cwginstock_default_country_code.toLowerCase())==c.iso2&&"2"==cwginstock.hide_country_placeholder ? ""!=cwginstock.custom_country_placeholder ? cwginstock.custom_country_placeholder:t : "" }})) }, perform_upon_show_variation: function (t, c){ var e=c.variation_id; jQuery(".cwginstock-subscribe-form").hide(), jQuery(".cwginstock-subscribe-form-" + e).show(), "recaptcha"==cwginstock_get_bot_type ? "1"==cwginstock_recaptcha_enabled&&instock_notifier.onloadcallback():"1"==cwginstock_turnstile_enabled&&instock_notifier.turnstilecallback(), "1"==cwginstock_phone_field&&instock_notifier.initialize_phone() }, generate_v3_response: function (){ "recaptcha"==cwginstock_get_bot_type&&"1"==cwginstock_recaptcha_enabled&&"yes"==cwginstock_is_v3_recaptcha&&grecaptcha.ready((function (){ grecaptcha.execute(cwginstock_recaptcha_site_key, { action: "subscribe_form" }).then((function (t){ document.getElementsByClassName("cwg-security").length > 0&&(document.getElementsByClassName("cwg-security")[0].value=t, document.getElementsByClassName("cwgstock_button")[0].disabled = !1, cwginstock_gtoken=t) })) })) }, is_email: function (t){ return /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(t) }, submit_form: function (t){ t.preventDefault(), t.stopPropagation(); var c=jQuery(this), e=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"==cwginstock_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("<div class='cwginstockerror' style='color:red;'>" + cwginstock_emptyquantity + "</div>"), !1; if("1"==cwginstock_phone_field){ var o=cwginstock_iti.getNumber(); if(cwginstock_phone_meta_data=cwginstock_iti.getSelectedCountryData(), !cwginstock_iti.isValidNumber()){ var n=cwginstock_iti.getValidationError(), r=cwginstock_phone_error[n]; if(-99==n&&(r=cwginstock_phone_error[0]), -99!=n&&"1"==cwginstock_is_phone_field_optional||"2"==cwginstock_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("<div class='cwginstockerror' style='color:red;'>" + r + "</div>"), !1 }} var a=jQuery(this).closest(".cwginstock-subscribe-form").find(".cwg-product-id").val(), _=jQuery(this).closest(".cwginstock-subscribe-form").find(".cwg-variation-id").val(); if(""==e) return jQuery(this).closest(".cwginstock-subscribe-form").find(".cwgstock_output").fadeIn(), jQuery(this).closest(".cwginstock-subscribe-form").find(".cwgstock_output").html("<div class='cwginstockerror' style='color:red;'>" + cwginstock_emptyname + "</div>"), !1; if(""==s) return jQuery(this).closest(".cwginstock-subscribe-form").find(".cwgstock_output").fadeIn(), jQuery(this).closest(".cwginstock-subscribe-form").find(".cwgstock_output").html("<div class='cwginstockerror' style='color:red;'>" + cwginstock_emptyemail + "</div>"), !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("<div class='cwginstockerror' style='color:red;'>" + cwginstock_invalidemail + "</div>"), !1; if("1"==cwginstock_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("<div class='cwginstockerror' style='color:red;'>" + cwginstock_iagree_error + "</div>"), !1; var l=jQuery(this).closest(".cwginstock-subscribe-form").find(".cwg-security").val(), g={ action: "cwginstock_product_subscribe", product_id: a, variation_id: _, subscriber_name: e, subscriber_phone: o, subscriber_phone_meta: JSON.stringify(cwginstock_phone_meta_data), user_email: s, user_id: cwginstock_userid, security: l, dataobj: cwginstock, custom_quantity: i }; jQuery.fn.block ? c.closest(".cwginstock-subscribe-form").block({ message: null }):jQuery('<div id="cwg-bis-overlay"> </div>').appendTo(c.closest(".cwginstock-subscribe-form")), instock_notifier.perform_ajax(g, c) }, recaptcha_callback: function (t){ document.getElementsByClassName("cwg-security").length > 0&&(document.getElementsByClassName("cwgstock_button")[0].disabled = !1, "1"==cwginstock_recaptcha_verify_enabled&&"yes"==cwginstock_recaptcha_secret_present&&(document.getElementsByClassName("cwg-security")[0].value=t)) }, turnstile_callback: function (t){ document.getElementsByClassName("cwg-security").length > 0&&(document.getElementsByClassName("cwgstock_button")[0].disabled = !1, document.getElementsByClassName("cwg-security")[0].value=t) }, onloadcallback: function (){ "recaptcha"==cwginstock_get_bot_type&&"1"==cwginstock_recaptcha_enabled&&("no"==cwginstock_is_v3_recaptcha ? jQuery("#cwg-google-recaptcha").length&&(null===cwginstock_googlerecaptcha_widget_id ? cwginstock_googlerecaptcha_widget_id=grecaptcha.render("cwg-google-recaptcha", { sitekey: cwginstock_recaptcha_site_key, callback: this.recaptcha_callback }):(grecaptcha.reset(cwginstock_googlerecaptcha_widget_id), this.recaptcha_callback(), cwginstock_googlerecaptcha_widget_id=null, instock_notifier.onloadcallback())):instock_notifier.generate_v3_response()) }, turnstilecallback: function (){ "turnstile"==cwginstock_get_bot_type&&"1"==cwginstock_turnstile_enabled&&jQuery("#cwg-turnstile-captcha").length&&(null===cwginstock_turnstile_widget_id ? cwginstock_turnstile_widget_id=turnstile.render("#cwg-turnstile-captcha", { sitekey: cwginstock_turnstile_site_key, theme: "light", callback: this.turnstile_callback }):(turnstile.reset(cwginstock_turnstile_widget_id), this.turnstile_callback(), cwginstock_turnstile_widget_id=null, instock_notifier.turnstilecallback())) }, resetcallback: function (){ "recaptcha"==cwginstock_get_bot_type ? "1"==cwginstock_recaptcha_enabled&&("no"==cwginstock_is_v3_recaptcha ? (grecaptcha.reset(), document.getElementsByClassName("cwgstock_button")[0].disabled = !0):instock_notifier.generate_v3_response()):"1"==cwginstock_turnstile_enabled&&(turnstile.reset(), document.getElementsByClassName("cwgstock_button")[0].disabled = !0) }, perform_ajax: function (t, c){ jQuery.ajax({ type: "post", url: cwginstock_ajax_url, data: t, beforeSend: function (t){ t.setRequestHeader("X-WP-Nonce", cwginstock.security) }, success: function (e){ e=e.msg, c.closest(".cwginstock-subscribe-form").find(".cwgstock_output").fadeIn(2e3), c.closest(".cwginstock-subscribe-form").find(".cwgstock_output").html(e), jQuery.fn.block ? c.closest(".cwginstock-subscribe-form").unblock():c.closest(".cwginstock-subscribe-form").find("#cwg-bis-overlay").fadeOut(400, (function (){ c.closest(".cwginstock-subscribe-form").find("#cwg-bis-overlay").remove() })), instock_notifier.resetcallback(), jQuery(document).trigger("cwginstock_success_ajax", t) }, error: function (e, s, i){ if(void 0!==e.responseJSON&&e.responseJSON.hasOwnProperty("code")&&void 0!==e.responseJSON.code&&("rest_cookie_invalid_nonce"!=e.responseJSON.code&&"cwg_nonce_verify_failed"!=e.responseJSON.code||(e.responseText=-1)), "-1"!==e.responseText&&-1!==e.responseText||(c.closest(".cwginstock-subscribe-form").find(".cwgstock_output").fadeIn(2e3), c.closest(".cwginstock-subscribe-form").find(".cwgstock_output").html("<div class='cwginstockerror' style='color:red;'>" + cwginstock_security_error + "</div>")), 403===e.status){ let t=e.responseText; try { let c=JSON.parse(e.responseText); !c.msg||"-1"===c.msg&&-1===c.msg||(t=c.msg) } catch (c){ t=e.responseText } if("-1"!==t||-1!==t){ let e=c.closest(".cwginstock-subscribe-form").find(".cwgstock_output"); e.fadeIn(2e3), e.html("<div class='cwginstockerror' style='color:red;'>" + t + "</div>") }} jQuery.fn.block ? c.closest(".cwginstock-subscribe-form").unblock():c.closest(".cwginstock-subscribe-form").find("#cwg-bis-overlay").fadeOut(400, (function (){ c.closest(".cwginstock-subscribe-form").find("#cwg-bis-overlay").remove() })), instock_notifier.resetcallback(), jQuery(document).trigger("cwginstock_error_ajax", t) }}) }}; instock_notifier.init();