!(function(Y, I) {
  (Y.DifferentAPIHost = !0),
    (Y.APIUrl = "https://a.appice.io"),
    (Y.FEAPPS = "5bebe93c25d705690ffbc758"),
    (Y.BASEURL = "https://a.appice.io"),
    (Y.PANELURL) = window.location.origin,
    (Y.MIN_START_DATE = "1614142719"),
    (Y.DEBUG = !1),
    (Y.API_URLRead = ""),
    (Y.API_URLWrite = ""),
    (Y.API_PARTS = {
      data: { w: Y.API_URLWrite + "/i", r: Y.API_URLRead + "/o" },
      apps: { w: Y.API_URLWrite + "/i/apps", r: Y.API_URLRead + "/o/apps" },
      users: { w: Y.API_URLWrite + "/i/users", r: Y.API_URLRead + "/o/users" },
      rules: { r: Y.API_URLWrite + "/i/rules", w: Y.API_URLRead + "/i/rules" },
      analytics: { r: Y.API_URLRead + "/o/analytics" },
      templates: {
        w: Y.API_URLWrite + "/i/templates",
        r: Y.API_URLRead + "/o/templates"
      },
      audienceSegment: {
        w: Y.API_URLWrite + "/i/aud",
        r: Y.API_URLRead + "/o/aud"
      },
      metrices: {
        w: Y.API_URLWrite + "/i/metrices",
        r: Y.API_URLRead + "/o/metrices"
      },
      campaigns: {
        w: Y.API_URLWrite + "/i/campaigns",
        r: Y.API_URLRead + "/o/campaigns"
      },
      screenshot: {
        w: Y.API_URLWrite + "/o/screenshot",
        r: Y.API_URLRead + "/i/screenshot"
      }
    }),
    (Y.DASHBOARD_REFRESH_MS = 1e4),
    (Y.DASHBOARD_IDLE_MS = 3e6),
    (Y.GRAPH_COLORS = [
      "#88BBC8",
      "#ED8662",
      "#A0ED62",
      "#ed6262",
      "#edb762",
      "#ede262",
      "#62edb0",
      "#62beed",
      "#6279ed",
      "#c162ed",
      "#ed62c7",
      "#9A1B2F"
    ]),
    (Y.SYSTEM_EVENTS = [
      "_App_Stop",
      "_App_Start",
      "Session_Start",
      "Session_End",
      "App_Foreground",
      "App_Background",
      "total",
      "Campaign_Clicked",
      "Campaign_Received",
      "Campaign_Deleted",
      "Churn"
    ]),
    (Y.CITY_DATA = !0);
  var e,
    V = store.get("semusi_date") ? store.get("semusi_date") : "30days";
  function P() {
    var e,
      t,
      r,
      a,
      o,
      n,
      i,
      d = moment(),
      s = d.year(),
      m = d.month() + 1,
      c = d.date(),
      u = d.hours(),
      p = !1,
      l = 0,
      f = 0,
      g = null;
    switch (V) {
      case "month":
        var h = (_ = moment().subtract("days", c)).year(),
          v = _.month() + 1,
          D = (_.date(), s + "." + m),
          b = h + "." + v,
          y = m,
          O = 1,
          P = "MMM",
          f = new Date(s, m, 0).getDate();
        break;
      case "day":
        D = s + "." + m;
        var h = (_ = moment().subtract("days", c)).year(),
          v = _.month() + 1;
        _.date();
        (b = h + "." + v),
          (y = c),
          (O = 1),
          (P = "D MMM"),
          (f = moment().format("D"));
        break;
      case "yesterday":
        var _,
          Y = moment().subtract("days", 1);
        (D = (s = Y.year()) + "." + (m = Y.month() + 1) + "." + (c = Y.date())),
          (b =
            (h = (_ = moment().subtract("days", 2)).year()) +
            "." +
            (v = _.month() + 1) +
            "." +
            _.date()),
          (y = 23),
          (O = 0),
          (P = "D MMM, HH:mm"),
          (f = 1);
        break;
      case "hour":
        (D = s + "." + m + "." + c),
          (b =
            (h = (_ = moment().subtract("days", 1)).year()) +
            "." +
            (v = _.month() + 1) +
            "." +
            _.date()),
          (y = u),
          (O = 0),
          (P = "HH:mm"),
          (f = 1);
        break;
      case "today":
        f = l = 1;
        break;
      case "7days":
        f = l = 7;
        break;
      case "30days":
        f = l = 30;
        break;
      case "60days":
        f = l = 60;
        break;
      case "90days":
        f = l = 90;
        break;
      case "year":
        (e = new Date(new Date().getFullYear(), 0, 1)),
          (f = l = Math.ceil((new Date() - e) / 864e5));
    }
    if (
      ("[object Array]" === Object.prototype.toString.call(V) &&
        2 == V.length &&
        ((t = new Date(V[1])).setHours(0, 0, 0, 0),
        (V[1] = t.getTime()),
        V[0] == V[1]
          ? ((a = (r = moment(V[0])).year()),
            (o = r.month() + 1),
            (n = r.date()),
            r.hours(),
            (D = a + "." + o + "." + n),
            (b =
              (h = (_ = r.subtract("days", 1)).year()) +
              "." +
              (v = _.month() + 1) +
              "." +
              _.date()),
            (y = 23),
            (O = 0),
            (P = "D MMM, HH:mm"),
            (f = 1))
          : ((i = moment(V[0])),
            (f = l = moment(V[1]).diff(i, "days") + 1),
            (g = V[1]))),
      0 != l)
    ) {
      for (
        var I = !1,
          A = 0,
          M = [],
          w = {},
          E = [],
          R = {},
          S = [],
          j = [],
          k = {},
          T = [],
          x = {},
          C = [],
          N = l - 1;
        -1 < N;
        N--
      ) {
        var H = g
            ? moment(g).subtract("days", N)
            : moment().subtract("days", N),
          L = H.year(),
          U = g
            ? moment(g).subtract("days", l + N)
            : moment().subtract("days", l + N),
          W = U.year();
        N != l - 1 && A != L && (I = !0);
        var F = (A = L) + ".w" + Math.ceil(H.format("DDD") / 7);
        w[(M[M.length] = F)] = w[F] ? w[F] + 1 : 1;
        var B = H.format("YYYY.M");
        (R[(E[E.length] = B)] = R[B] ? R[B] + 1 : 1),
          (S[S.length] = H.format("YYYY.M.D"));
        var G = W + ".w" + Math.ceil(U.format("DDD") / 7);
        k[(j[j.length] = G)] = k[G] ? k[G] + 1 : 1;
        var q = U.format("YYYY.M");
        (x[(T[T.length] = q)] = x[q] ? x[q] + 1 : 1),
          (C[C.length] = U.format("YYYY.M.D"));
      }
      (P = I ? "D MMM, YYYY" : "D MMM"), (p = !0);
    }
    return {
      activePeriod: D,
      periodMax: y,
      periodMin: O,
      previousPeriod: b,
      currentPeriodArr: S,
      previousPeriodArr: C,
      isSpecialPeriod: p,
      dateString: P,
      daysInPeriod: l,
      numberOfDays: f,
      uniquePeriodArr: z(M, w, E, R, S),
      uniquePeriodCheckArr: K(M, w, E, R),
      previousUniquePeriodArr: z(j, k, T, x, C),
      previousUniquePeriodCheckArr: K(j, k, T, x)
    };
  }
  function z(e, t, r, a, o) {
    if ("month" == V || "day" == V || "yesterday" == V || "hour" == V)
      return [];
    if (
      "[object Array]" === Object.prototype.toString.call(V) &&
      2 == V.length &&
      V[0] == V[1]
    )
      return [];
    var e = h(e),
      t = h(t),
      r = h(r),
      a = h(a),
      o = h(o),
      n = [],
      i = -1,
      d = -1,
      s = [],
      m = {};
    for (var c in t)
      if (
        c !==
          moment()
            .format("YYYY.\\w w")
            .replace(" ", "") &&
        t[c] < 7
      )
        for (var u = 0; u < e.length; u++) e[u] = e[u].replace(c, 0);
    for (var c in a)
      if (
        (d != c &&
          ((i =
            moment().format("YYYY.M") === c
              ? moment().format("D")
              : moment(c, "YYYY.M").daysInMonth()),
          (d = c)),
        a[c] < i)
      )
        for (u = 0; u < r.length; u++) r[u] = r[u].replace(c, 0);
    for (u = 0; u < r.length; u++)
      0 == r[u]
        ? 0 == e[u] || -1 != s.indexOf(e[u])
          ? (n[u] = o[u])
          : (n[u] = e[u])
        : ((s[s.length] = e[u]),
          (n[u] = r[u]),
          m[e[u]] ? m[e[u]].count++ : (m[e[u]] = { count: 1, index: u }));
    var p = _.countBy(e, function(e) {
      return e;
    });
    for (var l in m)
      if (
        7 != m[l].count &&
        (moment()
          .format("YYYY.\\w w")
          .replace(" ", "") != l ||
          p[l] != m[l].count)
      )
        for (
          var f = m[l].index - (p[l] - m[l].count),
            g = f + (p[l] - m[l].count),
            u = f;
          u < g;
          u++
        )
          0 == r[u] && (n[u] = o[u]);
    return (s = _.uniq(s)), (n = _.uniq(_.difference(n, s)));
  }
  function K(e, t, r, a) {
    if ("month" == V || "day" == V || "yesterday" == V || "hour" == V)
      return [];
    if (
      "[object Array]" === Object.prototype.toString.call(V) &&
      2 == V.length &&
      V[0] == V[1]
    )
      return [];
    var e = h(e),
      t = h(t),
      r = h(r),
      a = h(a),
      o = [],
      n = -1,
      i = -1;
    for (var d in t)
      if (
        d !==
          moment()
            .format("YYYY.\\w w")
            .replace(" ", "") &&
        t[d] < 1
      )
        for (var s = 0; s < e.length; s++) e[s] = e[s].replace(d, 0);
    for (var d in a)
      if (
        (i != d &&
          ((n =
            moment().format("YYYY.M") === d
              ? moment().format("D")
              : moment(d, "YYYY.M").daysInMonth()),
          (i = d)),
        a[d] < 0.5 * n)
      )
        for (s = 0; s < r.length; s++) r[s] = r[s].replace(d, 0);
    for (s = 0; s < r.length; s++)
      0 == r[s] ? 0 == e[s] || (o[s] = e[s]) : (o[s] = r[s]);
    return (o = _.uniq(o));
  }
  function h(e) {
    if (null == e || "object" != typeof e) return e;
    if (e instanceof Date) return (t = new Date()).setTime(e.getTime()), t;
    if (e instanceof Array) {
      for (var t = [], r = 0, a = e.length; r < a; ++r) t[r] = h(e[r]);
      return t;
    }
    if (e instanceof Object) {
      t = {};
      for (var o in e) e.hasOwnProperty(o) && (t[o] = h(e[o]));
      return t;
    }
  }
  function A(e, t, r) {
    var a = '<div id="graph-tooltip">' + r + "</div>";
    I("#content").append("<div id='tooltip-calc'>" + a + "</div>");
    var o = I("#graph-tooltip").outerWidth();
    I("#tooltip-calc").remove();
    var n = e - o / 2,
      i = e + o / 2;
    i > I(window).width() ? (n = e - o) : i < 340 && (n = e),
      I(a)
        .css({ top: t, left: n })
        .appendTo("body")
        .fadeIn(200);
  }
  if(Y.ACTIVE_APP_ID == undefined || Y.ACTIVE_APP_ID == ''){
    if(store.get("semusi_active_app")){
      Y.ACTIVE_APP_ID = store.get("semusi_active_app");
    }else{
      (Y.ACTIVE_APP_ID = 0);
    }
  }
  if(Y.ACTIVE_APP_KEY == undefined || Y.ACTIVE_APP_KEY == ''){
    if(store.get("semusi_active_api_key")){
      Y.ACTIVE_APP_KEY = store.get("semusi_active_api_key");
    }else{
      (Y.ACTIVE_APP_KEY = 0);
    }
  }
    (Y.BROWSER_LANG = jQuery.i18n.browserLang()),
    (Y.BROWSER_LANG_SHORT = jQuery.i18n.browserLang().split("-")[0]),
    (Y.HELP_MAP = {}),
    (Y.periodObj = P()),
    (Y.USER_RISK_TIME = 15),
    (Y.OTHERGROUP_NUMBER = 0),
    (Y.SIZE_PUSH_NOTIFICATION = 100),
    (Y.SIZE_POP_NOTIFICATION = 100),
    (Y.SIZE_PUSH_EXPANDEDNOTIFICATION = 500),
    (Y.SIZE_INAPP_FULLSCREEN = 500),  
    (Y.SIZE_INAPP_EXP_HEADER_FOOTER = 500),  
    (Y.SIZE_INAPP_MINISCREEN = 400),
    (Y.SIZE_RATING_ICON = 100),
    
    (Y.MIN_HEIGHT_PUSH_NOTIFICATION = 60),
    (Y.MIN_WIDTH_PUSH_NOTIFICATION = 60),
    (Y.MAX_HEIGHT_PUSH_NOTIFICATION = 96),
    (Y.MAX_WIDTH_PUSH_NOTIFICATION = 96),

    (Y.MIN_HEIGHT_POP_NOTIFICATION = 200),
    (Y.MIN_WIDTH_POP_NOTIFICATION = 300),
    (Y.MAX_HEIGHT_POP_NOTIFICATION = 200),
    (Y.MAX_WIDTH_POP_NOTIFICATION = 300),
    
    (Y.MIN_HEIGHT_PUSH_EXPANDEDNOTIFICATION = 300), 
    (Y.MAX_HEIGHT_PUSH_EXPANDEDNOTIFICATION = 400),
    (Y.MIN_WIDTH_PUSH_EXPANDEDNOTIFICATION = 600), 
    (Y.MAX_WIDTH_PUSH_EXPANDEDNOTIFICATION = 800),

    (Y.MIN_HEIGHT_INAPP_FULLSCREEN = 800),
    (Y.MAX_HEIGHT_INAPP_FULLSCREEN = 1024),
    (Y.MIN_WIDTH_INAPP_FULLSCREEN = 480),
    (Y.MAX_WIDTH_INAPP_FULLSCREEN = 768),

    (Y.MIN_HEIGHT_INAPP_EXP_HEADER_FOOTER = 200),
    (Y.MAX_HEIGHT_INAPP_EXP_HEADER_FOOTER = 200),
    (Y.MIN_WIDTH_INAPP_EXP_HEADER_FOOTER = 800),
    (Y.MAX_WIDTH_INAPP_EXP_HEADER_FOOTER = 800);
    
    (Y.MIN_HEIGHT_INAPP_MINISCREEN = 400),
    (Y.MAX_HEIGHT_INAPP_MINISCREEN = 400),
    (Y.MIN_WIDTH_INAPP_MINISCREEN = 400),
    (Y.MAX_WIDTH_INAPP_MINISCREEN = 400),

    (Y.MIN_HEIGHT_INAPP_ICONSCREEN = 60),
    (Y.MAX_HEIGHT_INAPP_ICONSCREEN = 96),
    (Y.MIN_WIDTH_INAPP_ICONSCREEN = 60),
    (Y.MAX_WIDTH_INAPP_ICONSCREEN = 96),
    
    (Y.MIN_HEIGHT_RATING_ICON = 60),
    (Y.MAX_HEIGHT_RATING_ICON = 96),
    (Y.MIN_WIDTH_RATING_ICON = 60),
    (Y.MAX_WIDTH_RATING_ICON = 96),


    (Y.validImage = !0),
    (Y.basicColors = [
      "#f59c1a",
      "#348fe2",
      "#00acac",
      "#660066",
      "#ff00ff",
      "#00ff00",
      "#800000",
      "#008000",
      "#337ab7",
      "#191970"
    ]),
    store.get("semusi_active_app") &&
      store.get("semusi_active_api_key") &&
      ((Y.ACTIVE_APP_KEY = store.get("semusi_active_api_key")),
      (Y.ACTIVE_APP_ID = store.get("semusi_active_app"))),
    store.get("semusi_lang") &&
      ((e = store.get("semusi_lang")),
      (Y.BROWSER_LANG_SHORT = e),
      (Y.BROWSER_LANG = e)),
    (Y.dateRange = {}),
    (Y.setDateRange = function(e, t) {
      var r, a, o, n, i, d, s;
      (s =
        ((i =
          null != e || null != t
            ? ((r = moment(e).startOf("day")),
              (o = moment(t).endOf("day")),
              (Y.dateRange.currentStartDate = r.valueOf() / 1e3),
              (Y.dateRange.currentEndDate = o.valueOf() / 1e3),
              0 == (d = t.diff(e, "days")) ? (d = 1) : d++,
              (n = moment(e).subtract(d, "days")),
              moment(t).subtract(d, "days"))
            : ((Y.dateRange.currentStartDate =
                moment()
                  .subtract(29, "days")
                  .startOf("day")
                  .valueOf() / 1e3),
              (a = moment()
                .subtract(29, "days")
                .startOf("day")),
              (Y.dateRange.currentEndDate =
                moment()
                  .endOf("day")
                  .valueOf() / 1e3),
              0 == (d = (o = moment().endOf("day")).diff(a, "days"))
                ? (d = 1)
                : d++,
              (n = moment(a).subtract(d, "days")),
              moment(o).subtract(d, "days"))),
        (Y.dateRange.previousStartDate = n.valueOf() / 1e3),
        (Y.dateRange.previousEndDate = i.valueOf() / 1e3),
        (Y.dateRange.currentStartDateNew = moment(
          1e3 * Y.dateRange.currentStartDate
        ).format("YYYY-MM-DD")),
        (Y.dateRange.currentEndDateNew = moment(
          1e3 * Y.dateRange.currentEndDate
        ).format("YYYY-MM-DD")),
        (Y.dateRange.previousStartDateNew = moment(
          1e3 * Y.dateRange.previousStartDate
        ).format("YYYY-MM-DD")),
        (Y.dateRange.previousEndDateNew = moment(
          1e3 * Y.dateRange.previousEndDate
        ).format("YYYY-MM-DD")),
        moment().toDate())),
        (Y.dateRange.offSet = moment(s).format("Z"));
    }),
    (Y.getColumnNumber=function(hostName){
        if(hostName.includes("gcc")){
          return [12,10]  ;
        }else{
          return [11,9] ;
        }
    }),
    (Y.setPeriod = function(e) {
      (V = e), (Y.periodObj = P()), store.set("semusi_date", e);
    }),
    (Y.getPeriod = function() {
      return V;
    }),
    (Y.setActiveApp = function(e, t, r , ak) {
      (Y.ACTIVE_APP_KEY = ak),
      store.set("semusi_active_api_key", ak),
        (Y.ACTIVE_APP_ID = e),
        store.set("semusi_active_app", e),
        (Y.ACTIVE_APP_NAME = t),
        store.set("semusi_active_appName", t),
        (Y.ACTIVE_APP_ICON = r),
        store.set("semusi_active_appIcon", r);
    }),
    (Y.setEmailState = function(e) {
        (Y.getEmailState = e)
    }),
    (Y.isFeatureDisabled = function(feat, e) {
      if (feat) {
        if (semusiCommon.ACTIVE_APP_ID !== "undefined" && semusiCommon.ACTIVE_APP_ID !== 0) {
          if (e && e[feat]) {
            return true  // Return the value of the feature (true/false)
        } else {
            return false;  // Return false if the feature doesn't exist
        }
        } else {
          return true;
        }
      } else {
        return true; 
      }
    }),
    // this function will set as well as give the state of global admin
    (Y.setGlobalAdmin = function(e) {
      (Y.isGlobalAdmin = e)
    }),
    (Y.setActiveUser = function(user) {
      Y.getActiveUser = {
        user_role: user.ur,
        api_key: user.a,
        approved_appids: user.aar
     };
    }),
    (Y.setPanelURL = function(u) {
      Y.getPanelURL = u;
    }),

    (Y.getPercentChange = function(e, t) {
      var r,
        a = 0,
        o = "";
      return (
        (o =
          0 == e
            ? ((a = "NA"), "u")
            : 0 == t
            ? ((a = "∞"), "d")
            : ((r = (((t - e) / e) * 100).toFixed(1)),
              (a = Y.getShortNumber(r) + "%"),
              r < 0 ? "d" : "u")),
        { percent: a, trend: o }
      );
    }),
    (Y.getDescendantProp = function(e, t) {
      if (-1 === (t = String(t)).indexOf(".")) return e[t];
      for (var r = t.split("."); r.length && (e = e[r.shift()]); );
      return e;
    }),
    (Y.drawGraph = function(e, t, r, a) {
      var o,
        n = {
          series: { lines: { show: !0, fill: !0 }, points: { show: !0 } },
          grid: {
            hoverable: !0,
            borderColor: "null",
            color: "#999",
            borderWidth: 0,
            minBorderMargin: 10
          },
          xaxis: { minTickSize: 1, tickDecimals: "number", tickLength: 0 },
          yaxis: { min: 0, minTickSize: 1, tickDecimals: "number" },
          legend: { backgroundOpacity: 0, margin: [5, -19] },
          colors: Y.GRAPH_COLORS
        };
      switch (r) {
        case "line":
          n.series = { lines: { show: !0, fill: !0 }, points: { show: !0 } };
          break;
        case "bar":
          20 < e.ticks.length && (n.xaxis.rotateTicks = 45),
            (n.series = {
              stack: !0,
              bars: { show: !0, align: "center", barWidth: 0.6, tickLength: 0 }
            }),
            (n.xaxis.ticks = e.ticks);
          break;
        case "pie":
          (n.series = {
            pie: {
              show: !0,
              lineWidth: 0,
              radius: 115,
              combine: { color: "#999", threshold: 0.05 },
              label: { show: !0, radius: 1 }
            }
          }),
            (n.legend.show = !1);
      }
      a && I.extend(!0, n, a),
        I.plot(I(t), e.dp, n),
        "bar" != r || n.series.stack
          ? I(t).unbind("plothover")
          : I(t).bind("plothover", function(e, t, r) {
              var a;
              r
                ? (r.datapoint[0].toFixed(1).replace(".0", ""),
                  (a = r.datapoint[1].toFixed(1).replace(".0", "")),
                  o != a &&
                    (I("#graph-tooltip").remove(),
                    A(r.pageX, r.pageY - 40, a),
                    (o = a)))
                : (I("#graph-tooltip").remove(), (o = null));
            });
    }),
    (Y.drawTimeGraph = function(e, t, r) {
      if (1 == e[0].data[0][0])
        for (var a = 0; a < e.length; a++)
          for (var o = 0; o < e[a].data.length; o++) --e[a].data[o][0];
      var n = {
        series: {
          lines: {
            stack: !1,
            show: !0,
            fill: !0,
            lineWidth: 2,
            fillColor: { colors: [{ opacity: 0 }, { opacity: 0.15 }] },
            shadowSize: 0
          },
          points: { show: !0, radius: 4, shadowSize: 0 },
          shadowSize: 0
        },
        grid: {
          hoverable: !0,
          borderColor: "null",
          color: "#BDBDBD",
          borderWidth: 0,
          minBorderMargin: 10,
          labelMargin: 10
        },
        xaxis: { tickDecimals: "number", tickSize: 0, tickLength: 0 },
        yaxis: { min: 0, minTickSize: 1, tickDecimals: "number", ticks: 3 },
        legend: {
          show: !1,
          margin: [-25, -44],
          noColumns: 3,
          backgroundOpacity: 0
        },
        colors: Y.GRAPH_COLORS
      };
      n.series.points.show = e[0].data.length <= 90;
      var i,
        d = {},
        d = "month" != V || r ? Y.getTickObj(r) : Y.getTickObj("monthly");
      (n.xaxis.max = d.max),
        (n.xaxis.min = d.min),
        (n.xaxis.ticks = d.ticks),
        (i = d.tickTexts);
      for (
        var s = I.plot(I(t), e, n), m = "A", c = [], u = 0;
        u < s.getData().length;
        u++
      ) {
        var p = 0,
          l = 0,
          f = 999999999999,
          g = 0,
          h = (s.getData()[u].label + "").toLowerCase();
        "ghost" !== s.getData()[u].mode
          ? (I.each(s.getData()[u].data, function(e, t) {
              if (!t[1] && 0 !== t[1]) return !0;
              (t[1] = parseFloat(t[1])),
                t[1] >= p && ((p = t[1]), (l = t[0])),
                t[1] <= f && ((f = t[1]), (g = t[0]));
            }),
            p != f &&
              ((c[u] = []),
              (c[u][c[u].length] = {
                data: [g, f],
                code: m,
                color: s.getData()[u].color,
                event: "min",
                desc: jQuery.i18n.prop("common.graph-min", f, h, i[g])
              }),
              (m = String.fromCharCode(m.charCodeAt() + 1)),
              (c[u][c[u].length] = {
                data: [l, p],
                code: m,
                color: s.getData()[u].color,
                event: "max",
                desc: jQuery.i18n.prop("common.graph-max", p, h, i[l])
              }),
              (m = String.fromCharCode(m.charCodeAt() + 1))))
          : s.getData()[u].data.length;
      }
      for (var v, D = s.width(), u = 0; u < c.length; u++) {
        var b = s.getData()[u].color;
        if (c[u])
          for (var y = 0; y < c[u].length; y++) {
            var O = s.pointOffset({ x: c[u][y].data[0], y: c[u][y].data[1] });
            O.left <= 15 && (O.left = 15),
              O.left >= D - 15 && (O.left = D - 15);
            var P = I('<div class="graph-key-event-label">').text(c[u][y].code);
            P.attr({
              title: c[u][y].desc,
              "data-points": "[" + c[u][y].data + "]"
            })
              .css({
                position: "absolute",
                left: O.left,
                top: O.top - 33,
                display: "none",
                "background-color": b
              })
              .appendTo(s.getPlaceholder())
              .show(),
              I(".tipsy").remove(),
              P.tipsy({ gravity: I.fn.tipsy.autoWE, offset: 3, html: !0 });
          }
      }
      return (
        I(t).bind("plothover", function(e, t, r) {
          var a;
          r
            ? v != r.dataIndex &&
              ((v = r.dataIndex),
              I("#graph-tooltip").remove(),
              r.datapoint[0].toFixed(1).replace(".0", ""),
              (a = r.datapoint[1].toFixed(1).replace(".0", "")),
              A(r.pageX, r.pageY - 40, a + " " + r.series.label))
            : (I("#graph-tooltip").remove(), (v = null));
        }),
        c
      );
    }),
    (Y.extractRangeData = function(e, t, r, a) {
      Y.periodObj = P();
      var o,
        n = [],
        i = 0,
        d = 0;
      if (!r) return n;
      for (var s = 0; s < r.length; s++)
        if (((o = 0), Y.periodObj.isSpecialPeriod)) {
          for (var m = 0, c = 0; c < Y.periodObj.uniquePeriodArr.length; c++) {
            (u = Y.getDescendantProp(
              e,
              Y.periodObj.uniquePeriodArr[c] + "." + t
            )) &&
              u[r[s]] &&
              (o += u[r[s]]);
          }
          for (var u, c = 0; c < Y.periodObj.uniquePeriodCheckArr.length; c++) {
            (u = Y.getDescendantProp(
              e,
              Y.periodObj.uniquePeriodCheckArr[c] + "." + t
            )) &&
              u[r[s]] &&
              (m += u[r[s]]);
          }
          m < o && (o = m),
            0 != o &&
              ((n[i] = {}),
              (n[i][t] = a ? a(r[s]) : r[s]),
              (d += n[i].t = o),
              i++);
        } else {
          (u = Y.getDescendantProp(e, Y.periodObj.activePeriod + "." + t)) &&
            u[r[s]] &&
            (o += u[r[s]]),
            0 != o &&
              ((n[i] = {}),
              (n[i][t] = a ? a(r[s]) : r[s]),
              (d += n[i].t = o),
              i++);
        }
      for (s = 0; s < n.length; s++)
        n[s].percent = ((n[s].t / d) * 100).toFixed(1);
      return (
        n.sort(function(e, t) {
          return -(e.t - t.t);
        }),
        n
      );
    }),
    (Y.extractChartData = function(e, t, r, a) {
      Y.periodObj = P();
      for (
        var o,
          n,
          i = Y.periodObj.periodMin,
          d = Y.periodObj.periodMax + 1,
          s = {},
          m = "",
          c = [],
          u = _.pluck(a, "name"),
          p = _.pluck(a, "func"),
          l = _.pluck(a, "period"),
          f = 0;
        f < u.length;
        f++
      ) {
        "previous" === l[f]
          ? Y.periodObj.isSpecialPeriod
            ? ((i = 0),
              (d = Y.periodObj.previousPeriodArr.length),
              (n = Y.periodObj.previousPeriodArr))
            : (o = Y.periodObj.previousPeriod)
          : Y.periodObj.isSpecialPeriod
          ? ((i = 0),
            (d = Y.periodObj.currentPeriodArr.length),
            (n = Y.periodObj.currentPeriodArr))
          : (o = Y.periodObj.activePeriod);
        for (var g = i; g < d; g++)
          (s = t(
            (s = Y.periodObj.isSpecialPeriod
              ? ((m = moment(n[g].replace(/\./g, "/"))),
                Y.getDescendantProp(e, n[g]))
              : ((m =
                  0 == Y.periodObj.periodMin
                    ? moment((o + " " + g + ":00:00").replace(/\./g, "/"))
                    : -1 == ("" + o).indexOf(".")
                    ? moment((o + "/" + g + "/1").replace(/\./g, "/"))
                    : moment((o + "/" + g).replace(/\./g, "/"))),
                Y.getDescendantProp(e, o + "." + g)))
          )),
            c[g] || (c[g] = {}),
            (c[g].date = m.format(Y.periodObj.dateString)),
            (propertyValue = p[f] ? p[f](s) : s[u[f]]),
            (r[f].data[r[f].data.length] = [g, propertyValue]),
            (c[g][u[f]] = propertyValue);
      }
      for (var h = [], v = 0; v < r.length; v++) {
        var D = _.flatten(r[v].data),
          b = _.reject(D, function(e, t, r, a) {
            return t % 2 == 0;
          });
        _.filter(D, function(e, t, r, a) {
          return t % 2 == 0;
        });
        (h[v] = {}), (h[v].min = _.min(b)), (h[v].max = _.max(b));
      }
      return { chartDP: r, chartData: _.compact(c), keyEvents: h };
    }),
    (Y.extractTwoLevelData = function(e, t, r, a) {
      if (((Y.periodObj = P()), !t)) return { chartData: d };
      var o = 0,
        n = 0,
        i = {},
        d = [],
        s = _.pluck(a, "name"),
        m = _.pluck(a, "func"),
        c = 0,
        n = Y.periodObj.isSpecialPeriod
          ? ((o = 0), Y.periodObj.currentPeriodArr.length)
          : ((o = Y.periodObj.periodMin), Y.periodObj.periodMax + 1),
        u = 0;
      if (Y.periodObj.isSpecialPeriod)
        for (y = 0; y < t.length; y++) {
          for (var p = 0, l = {}, f = {}, g = o; g < n; g++)
            if (
              (i = Y.getDescendantProp(
                e,
                Y.periodObj.currentPeriodArr[g] + "." + t[y]
              ))
            ) {
              i = r(i);
              for (O = 0; O < s.length; O++)
                (c = "u" == s[O] ? 0 : m[O] ? m[O](t[y], i) : i[s[O]]),
                  l[s[O]] || (l[s[O]] = 0),
                  "string" == typeof c
                    ? (l[s[O]] = c)
                    : ((p += c), (l[s[O]] += c));
            }
          if (-1 !== s.indexOf("u") && Object.keys(l).length) {
            for (
              var h = 0, v = 0, D = 0, b = 0;
              b < Y.periodObj.uniquePeriodArr.length;
              b++
            )
              (f = Y.getDescendantProp(
                e,
                Y.periodObj.uniquePeriodArr[b] + "." + t[y]
              )) &&
                ("string" == typeof (c = (f = r(f)).u)
                  ? (l.u = c)
                  : ((p += c), (h += c), (l.u += c)));
            for (b = 0; b < Y.periodObj.uniquePeriodCheckArr.length; b++)
              (f = Y.getDescendantProp(
                e,
                Y.periodObj.uniquePeriodCheckArr[b] + "." + t[y]
              )) &&
                "string" != typeof (D = (f = r(f)).u) &&
                ((p += D), (v += D), (l.u += D));
            v < h && (l.u = v);
          }
          (d[u] = {}), (d[u] = l), u++;
        }
      else
        for (var y = 0; y < t.length; y++)
          if (
            (i = Y.getDescendantProp(e, Y.periodObj.activePeriod + "." + t[y]))
          ) {
            i = r(i);
            for (var p = 0, l = {}, O = 0; O < s.length; O++)
              "string" != typeof (c = m[O] ? m[O](t[y], i) : i[s[O]]) &&
                (p += c),
                (l[s[O]] = c);
            0 < p && ((d[u] = {}), (d[u] = l), u++);
          }
      -1 !== s.indexOf("u")
        ? (d = _.sortBy(d, function(e) {
            return -e.u;
          }))
        : -1 !== s.indexOf("t")
        ? (d = _.sortBy(d, function(e) {
            return -e.t;
          }))
        : -1 !== s.indexOf("c") &&
          (d = _.sortBy(d, function(e) {
            return -e.c;
          }));
      for (g = 0; g < d.length; g++) _.isEmpty(d[g]) && (d[g] = null);
      return { chartData: _.compact(d) };
    }),
    (Y.extractBarData = function(e, t, r) {
      var a = Y.extractTwoLevelData(e, t, r, [
          {
            name: "range",
            func: function(e, t) {
              return e;
            }
          },
          { name: "t" }
        ]),
        o = _.pluck(a.chartData, "range"),
        n = _.pluck(a.chartData, "t"),
        i = [],
        d = 0,
        s = 3,
        m = 0;
      n.sort(function(e, t) {
        return e < t ? 1 : t < e ? -1 : 0;
      }),
        o.length < s && (s = o.length);
      for (var c = 0; c < s; c++) d += n[c];
      for (c = 0; c < s; c++) {
        var u = Math.floor((n[c] / d) * 100);
        (m += u),
          c == s - 1 && (u += 100 - m),
          (i[c] = { name: o[c], percent: u });
      }
      return i;
    }),
    (Y.getShortNumber = function(e) {
      return 1e6 <= e || e <= -1e6
        ? (e / 1e6).toFixed(1).replace(".0", "") + "M"
        : 1e4 <= e || e <= -1e4
        ? (e / 1e3).toFixed(1).replace(".0", "") + "K"
        : (e += "").replace(".0", "");
    }),
    (Y.getDateRange = function() {
      var e;
      return (
        (Y.periodObj = P()),
        Y.periodObj.isSpecialPeriod
          ? ((formattedDateStart = moment(
              Y.periodObj.currentPeriodArr[0],
              "YYYY.M.D"
            )),
            (formattedDateEnd = moment(
              Y.periodObj.currentPeriodArr[
                Y.periodObj.currentPeriodArr.length - 1
              ],
              "YYYY.M.D"
            )))
          : "HH:mm" == Y.periodObj.dateString
          ? ((formattedDateStart = moment(
              Y.periodObj.activePeriod + " " + Y.periodObj.periodMin + ":00",
              "YYYY.M.D HH:mm"
            )),
            (formattedDateEnd = moment(
              Y.periodObj.activePeriod + " " + Y.periodObj.periodMax + ":00",
              "YYYY.M.D HH:mm"
            )),
            (e = moment().format("mm")),
            formattedDateEnd.add("minutes", e))
          : (formattedDateEnd =
              "D MMM, HH:mm" == Y.periodObj.dateString
                ? ((formattedDateStart = moment(
                    Y.periodObj.activePeriod,
                    "YYYY.M.D"
                  )),
                  moment(Y.periodObj.activePeriod, "YYYY.M.D")
                    .add("hours", 23)
                    .add("minutes", 59))
                : ((formattedDateStart = moment(
                    Y.periodObj.activePeriod + "." + Y.periodObj.periodMin,
                    "YYYY.M.D"
                  )),
                  moment(
                    Y.periodObj.activePeriod + "." + Y.periodObj.periodMax,
                    "YYYY.M.D"
                  ))),
        formattedDateStart.format(Y.periodObj.dateString) +
          " - " +
          formattedDateEnd.format(Y.periodObj.dateString)
      );
    }),
    (Y.extendDbObj = function(e, t) {
      var r = moment(),
        a = r.year(),
        o = r.month() + 1,
        n = r.date(),
        i = Math.ceil(r.format("DDD") / 7),
        d = /^\d+$/,
        s = {},
        m = {};
      for (var c in (t[a] &&
        t[a][o] &&
        t[a][o][n] &&
        (e[a] || (e[a] = {}),
        e[a][o] || (e[a][o] = {}),
        e[a][o][n] || (e[a][o][n] = {}),
        e[a]["w" + i] || (e[a]["w" + i] = {}),
        (s = t[a][o][n]),
        (m = e[a][o][n]),
        (e[a][o][n] = t[a][o][n])),
      t.meta && (e.meta || (e.meta = {}), (e.meta = t.meta)),
      s))
        if (
          s.hasOwnProperty(c) &&
          !d.test(c) &&
          (_.isObject(s[c])
            ? (e[a][c] || (e[a][c] = {}),
              e[a][o][c] || (e[a][o][c] = {}),
              e[a]["w" + i][c] || (e[a]["w" + i][c] = {}))
            : (e[a][c]
                ? m[c]
                  ? (e[a][c] += s[c] - m[c])
                  : (e[a][c] += s[c])
                : (e[a][c] = s[c]),
              e[a][o][c]
                ? m[c]
                  ? (e[a][o][c] += s[c] - m[c])
                  : (e[a][o][c] += s[c])
                : (e[a][o][c] = s[c]),
              e[a]["w" + i][c]
                ? m[c]
                  ? (e[a]["w" + i][c] += s[c] - m[c])
                  : (e[a]["w" + i][c] += s[c])
                : (e[a]["w" + i][c] = s[c])),
          s[c])
        )
          for (var u in s[c])
            s[c].hasOwnProperty(u) &&
              (e[a][c][u]
                ? m[c] && m[c][u]
                  ? (e[a][c][u] += s[c][u] - m[c][u])
                  : (e[a][c][u] += s[c][u])
                : (e[a][c][u] = s[c][u]),
              e[a][o][c][u]
                ? m[c] && m[c][u]
                  ? (e[a][o][c][u] += s[c][u] - m[c][u])
                  : (e[a][o][c][u] += s[c][u])
                : (e[a][o][c][u] = s[c][u]),
              e[a]["w" + i][c][u]
                ? m[c] && m[c][u]
                  ? (e[a]["w" + i][c][u] += s[c][u] - m[c][u])
                  : (e[a]["w" + i][c][u] += s[c][u])
                : (e[a]["w" + i][c][u] = s[c][u]));
      t[a] &&
        (t[a].u && (e[a] || (e[a] = {}), (e[a].u = t[a].u)),
        t[a][o] &&
          t[a][o].u &&
          (e[a] || (e[a] = {}),
          e[a][o] || (e[a][o] = {}),
          (e[a][o].u = t[a][o].u)),
        t[a]["w" + i] &&
          t[a]["w" + i].u &&
          (e[a] || (e[a] = {}),
          e[a]["w" + i] || (e[a]["w" + i] = {}),
          (e[a]["w" + i].u = t[a]["w" + i].u)));
    }),
    (Y.toFirstUpper = function(e) {
      return e.replace(/\w\S*/g, function(e) {
        return e.charAt(0).toUpperCase() + e.substr(1);
      });
    }),
    (Y.divide = function(e, t) {
      var r = e / t;
      return (r && r != Number.POSITIVE_INFINITY) || (r = 0), r;
    }),
    (Y.getTickObj = function(e) {
      var t = parseInt(Y.periodObj.numberOfDays, 10),
        r = [],
        a = [],
        o = !1;
      if (1 == t) {
        for (var n = 0; n < 24; n++) r.push([n, n + ":00"]), a.push(n + ":00");
        o = !0;
      } else {
        var i = moment().subtract("days", t);
        if (
          ("[object Array]" === Object.prototype.toString.call(Y.getPeriod()) &&
            (i = moment(
              Y.periodObj.currentPeriodArr[
                Y.periodObj.currentPeriodArr.length - 1
              ]
            ).subtract("days", t)),
          "monthly" == e)
        ) {
          for (var d = [], n = 0; n < t; n++)
            i.add("days", 1), d.push(i.format("MMM"));
          d = _.uniq(d);
          for (n = 0; n < d.length; n++) r.push([n, d[n]]), (a[n] = d[n]);
        } else if ("weekly" == e) {
          for (var s = [], n = 0; n < t; n++)
            i.add("days", 1), s.push(i.isoweek());
          s = _.uniq(s);
          for (n = 0; n < s.length; n++) {
            r.push([n, "W" + s[n]]);
            var m = moment()
              .isoweek(s[n])
              .isoday(1)
              .format(", MMM D");
            a[n] = "W" + s[n] + m;
          }
        } else if ("hourly" == e)
          for (n = 0; n < t; n++) {
            i.add("days", 1);
            for (var c = 0; c < 24; c++)
              0 == c && r.push([24 * n + c, i.format("D MMM") + " 0:00"]),
                a.push(i.format("D MMM, ") + c + ":00");
          }
        else
          for (n = 0; n < t; n++)
            i.add("days", 1),
              r.push([n, i.format("D MMM")]),
              (a[n] = i.format("D MMM"));
        (r = _.compact(r)), (a = _.compact(a));
      }
      if (!o && 10 < r.length) {
        for (
          var u = [],
            p = Math.floor(r.length / 10) < 1 ? 1 : Math.floor(r.length / 10),
            n = Math.floor(r.length / 30) < 1 ? 1 : Math.floor(r.length / 30);
          n < r.length - 1;
          n += p
        )
          u.push(r[n]);
        r = u;
      } else
        (r[0] = null), ("hourly" == e && 1 != t) || (r[r.length - 1] = null);
      return { min: 0, max: a.length - 1, tickTexts: a, ticks: _.compact(r) };
    }),
    (Y.getFilterDateRange = function(e, t) {
      var r = moment();
      if (t)
        switch (e) {
          case "TODAY":
            o = moment
              .utc()
              .startOf("day")
              .add("days", -1)
              .hours(0)
              .minutes(0)
              .seconds(0);
            break;
          case "WEEK":
            var a = moment.utc().day(),
              o = moment
                .utc()
                .add("days", -a - 7)
                .hours(0)
                .minutes(0)
                .seconds(0);
            break;
          case "MONTH":
            o = moment
              .utc()
              .add("months", -1)
              .date(1)
              .hours(0)
              .minutes(0)
              .seconds(0);
            break;
          case "YEAR":
            o = moment
              .utc()
              .add("years", -1)
              .add("months", -moment.utc().month())
              .date(1)
              .hours(0)
              .minutes(0)
              .seconds(0);
        }
      else
        switch (e) {
          case "TODAY":
            o = moment
              .utc()
              .startOf("day")
              .hours(0)
              .minutes(0)
              .seconds(0);
            break;
          case "WEEK":
            a = moment.utc().day();
            o = moment
              .utc()
              .add("days", -a)
              .hours(0)
              .minutes(0)
              .seconds(0);
            break;
          case "MONTH":
            o = moment
              .utc()
              .startOf("month")
              .hours(0)
              .minutes(0)
              .seconds(0);
            break;
          case "YEAR":
            o = moment
              .utc()
              .startOf("year")
              .hours(0)
              .minutes(0)
              .seconds(0);
        }
      return [o.valueOf() / 1e3, r.valueOf() / 1e3, o, r];
    }),
    (Y.getWeekofYear = function(e) {
      var t = new Date(e.valueOf()),
        r = (e.getDay() + 6) % 7;
      t.setDate(t.getDate() - r + 3);
      var a = new Date(t.getFullYear(), 0, 4),
        o = (t - a) / 864e5;
      return 1 + Math.ceil(o / 7);
    }),
    (Y.getFilterObject = function(e) {
      var t = {};
      switch (e) {
        case "TODAY":
          Y.setPeriod("today"),
            (t.currentPeriod = moment.utc().date()),
            (t.previousPeriod = moment.utc().date() - 1),
            (t.periodtype = "d");
          break;
        case "WEEK":
          Y.setPeriod("7days"),
            (t.currentPeriod = Y.getWeekofYear(new Date(moment.utc()._d)) - 1),
            (t.previousPeriod = Y.getWeekofYear(new Date(moment.utc()._d)) - 2),
            (t.periodtype = "w");
          break;
        case "MONTH":
          Y.setPeriod("month"),
            (t.currentPeriod = moment.utc().month() + 1),
            (t.previousPeriod = moment.utc().month()),
            (t.periodtype = "m");
          break;
        case "YEAR":
          Y.setPeriod("year"),
            (t.currentPeriod = moment.utc().year()),
            (t.previousPeriod = moment.utc().year() - 1),
            (t.periodtype = "y");
      }
      return t;
    }),
    (Y.getParameterValues = function(e) {
      for (
        var t = window.location.href
            .slice(window.location.href.indexOf("?") + 1)
            .split("&"),
          r = 0;
        r < t.length;
        r++
      ) {
        var a = t[r].split("=");
        if (a[0] == e) return a[1];
      }
    }),
    (Y.getCurrentEpoch = function() {
      return moment()._d.valueOf();
    }),
    (Y.getEpochFromDate = function(e) {
      return moment(e)._d.valueOf();
    }),
    (Y.getEpochFromDate_Utc = function(e) {
      return moment.utc(e)._d.valueOf();
    }),
    (Y.getEpochFromDate_Utc = function(e, t) {
      return t
        ? moment.utc(e).endOf('day').valueOf()
        : moment.utc(e).startOf('day').valueOf();
    }),
    (Y.getDateFromEpoch = function(e, t, v) {
      return 1 == t
        ? (v) ? 
      (moment
        .utc(e)
        .startOf("day")
        .format(semusiCommon.getDateFormatt())) :
           ( moment
            .utc(e)
            .startOf("day")
            .format("MM/DD/YYYY")
            )
        :(v) ?  moment(e).format(semusiCommon.getDateFormatt()) : moment(e).format("MM/DD/YYYY");
    }),
    (Y.getDateAndTimeFromEpoch = function(epoch) {
      function tConvert (time) {
        // Check correct time format and split into components
        time = time.toString ().match (/^([01]\d|2[0-3])(:)([0-5]\d)(:[0-5]\d)?$/) || [time];
      
        if (time.length > 1) { // If time format correct
          time = time.slice (1);  // Remove full string match value
          time[5] = +time[0] < 12 ? 'AM' : 'PM'; // Set AM/PM
          time[0] = +time[0] % 12 || 12; // Adjust hours
        }
        return time.join (''); // return adjusted time or original string
      }
    
      var months=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec" ]
      var myDate = new Date(epoch);
      var dateStr = (months[myDate.getMonth()]) + " " + myDate.getDate() + ", " + myDate.getFullYear() + " " +  tConvert(String(myDate.getHours()).padStart(2, '0')  + ":" + String(myDate.getMinutes()).padStart(2, '0') + ":" + String(myDate.getSeconds()).padStart(2, '0') )
      
      return dateStr
    }),
    (Y.getCurrentDate = function(c) {
      if(c){
        return moment.utc().format(semusiCommon.getDateFormatt());
      }else{
        return moment.utc().format("MM/DD/YYYY");
      }
    }),
    (Y.getCurrentMonthStartDate = function() {
      return moment
        .utc()
        .startOf("month")
        .format(semusiCommon.getDateFormatt());
    }),
    (Y.getCurrentYearStartDate = function() {
      return moment
        .utc()
        .startOf("year")
        .format(semusiCommon.getDateFormatt());
    }),
    (Y.getRandomColor = function() {
      return "#" + Math.floor(16777215 * appiceFloat.generateRandomFloat()).toString(16);
    }),
    (Y.getDateArrayFromEpochArray = function(s){
      return s.map(e => {
        const d = moment.unix(e).format(semusiCommon.getDateFormatt());
        return d;
      })
    }),
    (Y.isJson = function(s){
          try {
            JSON.parse(s);
        } catch (e) {
              return false;
        }
          return true;
    
    }),
      (Y.validateImageDimension = function (e, n, i, a, t, d) { 
        return a <= e && e <= d && i <= n && n <= t || (alert("Image dimensions need to be in between (w)" + a + " x " + i + "(h) and (w)" + d + " x " + t + "(h)"), !1)
       }),
    (Y.isAdmin = function() {
      const role = semusiCommon.isJson(localStorage.getItem('user_role')) ? JSON.parse(localStorage.getItem('user_role')) : localStorage.getItem('user_role');
      return role === 'admin';
    }),
    (Y.isManager = function() {
      const role = semusiCommon.isJson(localStorage.getItem('user_role')) ? JSON.parse(localStorage.getItem('user_role')) : localStorage.getItem('user_role');
      return role === 'manager';
    }),
    (Y.getDateFormatt = function() {
      return "MMM D, YYYY";
    }),
    (Y.validateImageSize = function (e, t, r, a, o, b, p, n) {  //a= minheight o = minwidth  b=max height p=max width
      var i = window.URL || window.webkitURL,
          d = t.size / 1024,
          s = !1;
    
      // Check for double extensions in filename only for image files
      if (t.type.startsWith('image/') && t.name.indexOf('.') !== t.name.lastIndexOf('.')) {
        alert("Image name or image type is incorrect.");
        document.getElementById(e).value = "";
        n(!1);
        return false;
      }
    
      return (
        "image/jpg" == t.type && (s = !0),
        "image/jpeg" == t.type && (s = !0),
        "image/png" == t.type && (s = !0),
        "image/gif" == t.type && (s = !0),
        "video/mp4" == t.type && (s = !0),
        s
          ? r < d
            ? (alert("Maximum file size is " + r + "KB"),
              (document.getElementById(e).value = ""),
              n(!1),
              !1)
            : t
            ? ( "video/mp4" == t.type ) ?
                //TODO    No Vallidation for now ,  dimennsion check
                ((Y.validImage = !0), n(!0))
    
                :((image = new Image()),
                  (image.onload = function () {
                    if (o == 400 && a == 400) { // Validation only for mini image
                      return (
                        (this.width < o || this.width > p) || (this.height < a || this.height > b)
                          ? (alert(
                            "Image dimensions need to be in between (w)" +
                            o +
                            " x " +
                            a +
                            "(h)"
                          ),
                            (document.getElementById(e).value = ""),
                            (Y.validImage = !1),
                            n(!1))
                          : ((Y.validImage = !0), n(!0)),
                        !1
                      );
                    }
                    else if (o == 300 && a == 200) { // Validation only for webpopup box image
                      return (
                        (this.width < o || this.width > p) || (this.height < a || this.height > b)
                          ? (alert(
                            "Image dimensions need to be in between (w)" +
                            o +
                            " x " +
                            a +
                            "(h)"
                          ),
                            (document.getElementById(e).value = ""),
                            (Y.validImage = !1),
                            n(!1))
                          : ((Y.validImage = !0), n(!0)),
                        !1
                      );
                    }
                    else {
                      return (
                        (this.width < o || this.width > p) || (this.height < a || this.height > b)
                          ? (alert(
                            "Image dimensions need to be in between (w)" +
                            o +
                            " x " +
                            a +
                            "(h)" +
                            " and " + "(w)" +
                            p +
                            " x " +
                            b + "(h)"
                          ),
                            (document.getElementById(e).value = ""),
                            (Y.validImage = !1),
                            n(!1))
                          : ((Y.validImage = !0), n(!0)),
                        !1
                      );
                    }
                  }),
                  void (image.src = i.createObjectURL(t)))
              : (n(!0), !1)
              : (alert("Only JPG,JPEG and PNG images are supported."),
            (document.getElementById(e).value = ""),
            n(!1),
            !1)
      );
    }),
    (Y.validateInAppImageSize = function(e, t, r, a, o,b,p, n) {
        for (
            var i = window.URL || window.webkitURL, d = !1, s = !0, m = 0;
            m < t.length;
            m++
          ) {
            var c = t[m].size / 1024,
              d = !1;
                   // Check for double extensions in filename only for image files
                 if (t[m].type.startsWith('image/') && t[m].name.indexOf('.') !== t[m].name.lastIndexOf('.')) {
                   alert("Image name or image type is incorrect.");
                   document.getElementById(e).value = "";
                   n(false);
                   return false;
              }
            "image/jpg" == t[m].type && (d = !0),
              "image/jpeg" == t[m].type && (d = !0),
              "image/png" == t[m].type && (d = !0),
              "image/gif" == t[m].type && (d = !0),
              r < c &&
                (alert("Maximum file size is " + r + "KB"),
                (document.getElementById(e).value = ""),
                (s = !1)),
              t[m] &&
                ((image = new Image()),
                (image.onload = function() {
                    (this.width < o || this.width > p)  || (this.height < a || this.height > b )
                    ? (alert(
                        "Image dimensions need to be in between (w)" +
                          o +
                          " x " +
                          a +
                          "(h)" +
                          " and " + "(w)" +
                          p +
                          " x " +
                          b + "(h)"
                    ),
                    (document.getElementById(e).value = ""),
                    (Y.validImage = false),
                      n(false)
                    (s = !1)): ((Y.validImage = !0), n(!0)),
                    !1
                }),
                (image.src = i.createObjectURL(t[m])));
          }
  

      if(!d){
        (alert("Only JPG,JPEG,GIF and PNG images are supported."),
          (document.getElementById(e).value = ""),
          n(false),
          !1);
      }
    }),
    (Y.addOffset = function(e) {
      var t = moment().toDate(),
        r = (a = moment(t).format("Z")).substring(0, 1),
        a = a.replace(r, "");
      return (
        (a = moment.duration(a, "HH:mm").asSeconds()),
        "+" == r
          ? parseInt(e) + parseInt(a)
          : "-" == r
          ? parseInt(e) - parseInt(a)
          : void 0
      );
    }),
    (Y.getOffset = function() {
      var e = moment().toDate(),
        t = (r = moment(e).format("Z")).substring(0, 1),
        r = r.replace(t, "");
      return t + (r = moment.duration(r, "HH:mm").asSeconds());
    });
    (Y.generateRandomAlphanumericString = function (length){
      const uppercaseChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
      const digitChars = '0123456789';
      const specialChars = '@#.';
    
      // Custom random number generator (LCG-like algorithm)
      let seed = Date.now();
      function random() {
        seed = (seed * 1664525 + 1013904223) & 0x7fffffff;
        return seed;
      }
    
      // Helper function to get a random character from the charset
      function getRandomChar(charset) {
        const index = random() % charset.length;
        return charset.charAt(index);
      }
    
      // Ensure at least one uppercase letter
      let result = getRandomChar(uppercaseChars);
    
      // Ensure at least one digit
      let digitChar;
      do {
        digitChar = getRandomChar(digitChars);
      } while (result.indexOf(digitChar) !== -1);
      result += digitChar;
    
      // Ensure one special character
      let specialCharAdded = false;
      for (let i = 0; i < specialChars.length && !specialCharAdded; i++) {
        const currentSpecialChar = specialChars.charAt(i);
        if (result.indexOf(currentSpecialChar) === -1) {
          result += currentSpecialChar;
          specialCharAdded = true;
        }
      }
    
      const remainingLength = length - 3;
      const charset = uppercaseChars + digitChars + specialChars;
    
      for (let i = 0; i < remainingLength; i++) {
        let randomChar;
        do {
          randomChar = getRandomChar(charset);
        } while (result.indexOf(randomChar) !== -1);
        result += randomChar;
      }
      return result;
    });
    (Y.randomNumber = function() {
      return (appiceFloat.generateRandomFloat() * 1000)
    });

    (Y.getCsrfToken = function() {
      $.ajax({
        type:"GET",
        url:semusiCommon.API_PARTS.metrices.r + '/token',
        data:{
          api_key: semusiCommon.getActiveUser.api_key,
          app_id: semusiCommon.ACTIVE_APP_ID,
          uniqueNumber : semusiCommon.randomNumber(),
        },
        success:function (data) {
          appiceCookies.setCookie('_csrf',data.token);
        },
        error: function (jqXHR, textStatus, errorThrown) {
         
        }
      });    
    });
})((window.semusiCommon = window.semusiCommon || {}), jQuery);

// Auto Logut If there is no activity from user
 function idleTimer() {
     var t;
    const HEARTBEAT_INTERVAL = 60000;
    const INACTIVITY_LIMIT = 1080000;
    const LOGOUT_WARNING_TIME = 120000;
     window.setInterval(function(){
      $.ajax({
       type:"GET",
       url:semusiCommon.API_PARTS.metrices.r + '/heartBeat',
       data:{
                 api_key: semusiCommon.getActiveUser.api_key
             },
       success:function (data) {
         
       },
       error: function (jqXHR, textStatus, errorThrown) {
          if(errorThrown== "Unauthorized" || errorThrown == "notExist"){
          window.location.href = encodeURI('logout'); 
       }
       }
     });
    }, HEARTBEAT_INTERVAL);
   //checks the activity of mouse
     // Event listeners for user activity
     window.onmousemove = resetTimer;
     window.onmousedown = resetTimer;
     // check the click Activity
     window.onclick = resetTimer;
     window.onscroll = resetTimer;
   //checks the activity of keyboard
     window.onkeypress = resetTimer;

  // Function to update activity timestamp
  function updateActivity() {
      localStorage.setItem('lastActivity', Date.now());
  }

  // Check for inactivity
  function checkInactivity() {
      const lastActivity = localStorage.getItem('lastActivity');
      if (lastActivity) {
          const inactivityTime = Date.now() - parseInt(lastActivity, 10);
          console.log(`Inactivity Time: ${inactivityTime}ms`);
          if (inactivityTime >= INACTIVITY_LIMIT) {
              warning(); // Show warning modal if inactive
          }
      }
  }

  // Check for activity across tabs
   window.addEventListener('storage', function (event) {
     if (event.key === 'lastActivity') {
       checkInactivity();
     }
   });

   // Initialize the activity timestamp
   updateActivity();
  // Logout function
     function logout() {
       // calls the logout automatically upon no activity
       window.location.href = encodeURI('logout');
     }
  // Warning modal before logout
     function warning(){
       $("#logoutmodalwarning").modal('show');
       setTimeout(() => {
          const lastActivity = localStorage.getItem('lastActivity');
          const inactivityTime = Date.now() - parseInt(lastActivity, 10);
          if (inactivityTime >= INACTIVITY_LIMIT + LOGOUT_WARNING_TIME) {
              logout(); // Logout if still inactive after warning
          }
      }, LOGOUT_WARNING_TIME);

    }



  // Reset inactivity timer on user activity
   function resetTimer() {
         clearTimeout(t);
      updateActivity(); // Update last activity timestamp
      t = setTimeout(checkInactivity, INACTIVITY_LIMIT); // Set inactivity check
     }
 }
// Start the idle timer
 idleTimer();