// The smart code script generated by VWO includes the instruction:
//"DO NOT make any changes to smart code except for entering your account id"
//
// HOWEVER, changes have been made in order to remove the unwanted blur filter/loader logic
// Example of said logic: https://help.vwo.com/hc/en-us/articles/4402914949401-Executing-VWO-SmartCode-on-Valid-Consent

window._vwo_code ||
  (function () {
    var account_id = 373511,
      version = 2.0,
      settings_tolerance = 2000,
      hide_element = "body",
      hide_element_style =
        "opacity:0 !important;filter:alpha(opacity=0) !important;background:none !important",
      /* DO NOT EDIT BELOW THIS LINE */
      f = false,
      w = window,
      d = document,
      v = d.querySelector("#vwoCode"),
      cK = "_vwo_" + account_id + "_settings",
      cc = {};
    try {
      var c = JSON.parse(
        localStorage.getItem("_vwo_" + account_id + "_config")
      );
      cc = c && typeof c === "object" ? c : {};
    } catch (e) {}
    var stT = cc.stT === "session" ? w.sessionStorage : w.localStorage;
    code = {
      use_existing_jquery: function () {
        return typeof use_existing_jquery !== "undefined"
          ? use_existing_jquery
          : undefined;
      },
      library_tolerance: function () {
        return typeof library_tolerance !== "undefined"
          ? library_tolerance
          : undefined;
      },
      settings_tolerance: function () {
        return cc.sT || settings_tolerance;
      },
      hide_element_style: function () {
        return "{" + (cc.hES || hide_element_style) + "}";
      },
      hide_element: function () {
        return typeof cc.hE === "string" ? cc.hE : hide_element;
      },
      getVersion: function () {
        return version;
      },
      finish: function () {
        if (!f) {
          f = true;
          var a = d.getElementById("_vis_opt_path_hides");
          if (a) a.parentNode.removeChild(a);
        }
      },
      finished: function () {
        return f;
      },
      load: function (a) {
        var s = this.getSettings(),
          b = d.createElement("script"),
          t = this;
        if (s) {
          b.textContent = s;
          d.getElementsByTagName("head")[0].appendChild(b);
          if (!w.VWO || VWO.caE) {
            stT.removeItem(cK);
            t.load(a);
          }
        } else {
          b.fetchPriority = "high";
          b.src = a;
          b.type = "text/javascript";
          b.onerror = function () {
            window._vwo_code.finish();
          };
          d.getElementsByTagName("head")[0].appendChild(b);
        }
      },
      getSettings: function () {
        try {
          var i = stT.getItem(cK);
          if (!i) {
            return;
          }
          i = JSON.parse(i);
          if (Date.now() > i.e) {
            stT.removeItem(cK);
            return;
          }
          return i.s;
        } catch (e) {
          return;
        }
      },

      init: function () {
        if (d.URL.indexOf("__vwo_disable__") > -1) return;
        var sT = this.settings_tolerance();
        w._vwo_settings_timer = setTimeout(function () {
          window._vwo_code.finish();
          stT.removeItem(cK);
        }, sT);
        var filterConfig = this.filterConfig;
        if (!filterConfig || filterConfig.filterTime === "balanced") {
          var cS = d.currentScript,
            a = d.createElement("style"),
            hE = this.hide_element(),
            b =
              cS && !cS.async && hE
                ? hE + "{" + this.hide_element_style() + "}"
                : "",
            h = d.getElementsByTagName("head")[0];
          a.setAttribute("id", "_vis_opt_path_hides");
          v && a.setAttribute("nonce", v.nonce);
          a.setAttribute("type", "text/css");
          if (a.styleSheet) a.styleSheet.cssText = b;
          else a.appendChild(d.createTextNode(b));
          h.appendChild(a);
        }
        this.load(
          "https://dev.visualwebsiteoptimizer.com/j.php?a=" +
            account_id +
            "&u=" +
            encodeURIComponent(d.URL) +
            "&vn=" +
            version
        );
      },
      setFilterConfigAndApplyFilter: function (config) {
        if (!config) {
          // No config will lead to early return and no addition of smart code
          return;
        }
        var state = this.isNonLiveMode(account_id) || config.isConsentGiven();
        if (state === "1") {
          // if cookie consent was already given and the cookies were already accepted, execute out normal flow
          hide_element = "body";
          w._vwo_settings_timer = window._vwo_code.init();
          return;
        } else if (state === "2") {
          return;
        }

        this.filterConfig = config;

        var timer = setInterval(function () {
          var state = config.isConsentGiven();
          var shouldClearInterval;
          if (state === "1") {
            w._vwo_settings_timer = window._vwo_code.init();
            shouldClearInterval = true;
          } else if (state === "2") {
            window._vwo_code.filterConfig = undefined;
            shouldClearInterval = true;
          }
          if (shouldClearInterval) {
            clearInterval(timer);
          }
        }, 100);
      },
      isNonLiveMode: function (accountId) {
        var wName = w.name;
        if (!wName) {
          return;
        }
        return (
          (wName.indexOf("_vis_editor") > -1 ||
            wName.indexOf("_vis_preview_" + accountId) > -1 ||
            wName.indexOf("_vis_heatmap_" + accountId) > -1) &&
          "1"
        );
      },
    };
    w._vwo_code = code;
  })();
window._vwo_code.setFilterConfigAndApplyFilter({
  popupSelector: "#CybotCookiebotDialog",
  filterTime: "balanced",
  isConsentGiven: function () {
    /** your custom Code */
    if (document.cookie.indexOf("CookieConsent") != -1) {
      var ccValue =
        decodeURIComponent(
          document.cookie.replace(
            new RegExp(
              "(?:(?:^|.*;)\\s*" +
                encodeURIComponent("CookieConsent").replace(
                  /[\-\.\+\*]/g,
                  "\\$&"
                ) +
                "\\s*\\=\\s*([^;]*).*$)|^.*$"
            ),
            "$1"
          )
        ) || null;
      let consentValue = "2";
      if (ccValue) {
        ccValue = ccValue.substring(ccValue.indexOf(",statistics") + 12);
        ccValue = ccValue.substring(0, ccValue.indexOf(","));
        consentValue = ccValue === "true" ? "1" : "2";
      }
      return consentValue;
    } else {
      return "3";
    }
  },
});
