var ht = Object.defineProperty;
var ft = (l, u, _) => u in l ? ht(l, u, { enumerable: !0, configurable: !0, writable: !0, value: _ }) : l[u] = _;
var ce = (l, u, _) => ft(l, typeof u != "symbol" ? u + "" : u, _);
import { useCoreStore as Ke } from "@feedmepos/mf-common";
import { U as ve, u as Ve, j as ot, a as gt } from "./app-Bpb4394e.js";
import { ref as de, readonly as Ge } from "vue";
import "./inventory-core-dart.default-DanfWZQm.js";
var Je = { exports: {} };
(function(l, u) {
  (function(_, f) {
    f(u);
  })(ve, function(_) {
    var f = { getItemSync: function(i) {
      try {
        return localStorage.getItem(i) || null;
      } catch {
        return null;
      }
    }, getItem: function(i, t) {
      var e = this;
      return new Promise(function(r, n) {
        try {
          var a = e.getItemSync(i);
          t == null || t(null, a), r(a);
        } catch (o) {
          t && t(o, null), n(o);
        }
      });
    }, setItem: function(i, t, e) {
      return new Promise(function(r, n) {
        try {
          localStorage.setItem(i, t), e && e(null, t), r(t);
        } catch (a) {
          e && e(a, null), n(a);
        }
      });
    } }, s = function() {
      return s = Object.assign || function(i) {
        for (var t, e = 1, r = arguments.length; e < r; e++) for (var n in t = arguments[e]) Object.prototype.hasOwnProperty.call(t, n) && (i[n] = t[n]);
        return i;
      }, s.apply(this, arguments);
    };
    function O(i, t, e, r) {
      return new (e || (e = Promise))(function(n, a) {
        function o(p) {
          try {
            d(r.next(p));
          } catch (c) {
            a(c);
          }
        }
        function v(p) {
          try {
            d(r.throw(p));
          } catch (c) {
            a(c);
          }
        }
        function d(p) {
          var c;
          p.done ? n(p.value) : (c = p.value, c instanceof e ? c : new e(function(y) {
            y(c);
          })).then(o, v);
        }
        d((r = r.apply(i, [])).next());
      });
    }
    function K(i, t) {
      var e, r, n, a, o = { label: 0, sent: function() {
        if (1 & n[0]) throw n[1];
        return n[1];
      }, trys: [], ops: [] };
      return a = { next: v(0), throw: v(1), return: v(2) }, typeof Symbol == "function" && (a[Symbol.iterator] = function() {
        return this;
      }), a;
      function v(d) {
        return function(p) {
          return function(c) {
            if (e) throw new TypeError("Generator is already executing.");
            for (; o; ) try {
              if (e = 1, r && (n = 2 & c[0] ? r.return : c[0] ? r.throw || ((n = r.return) && n.call(r), 0) : r.next) && !(n = n.call(r, c[1])).done) return n;
              switch (r = 0, n && (c = [2 & c[0], n.value]), c[0]) {
                case 0:
                case 1:
                  n = c;
                  break;
                case 4:
                  return o.label++, { value: c[1], done: !1 };
                case 5:
                  o.label++, r = c[1], c = [0];
                  continue;
                case 7:
                  c = o.ops.pop(), o.trys.pop();
                  continue;
                default:
                  if (n = o.trys, !((n = n.length > 0 && n[n.length - 1]) || c[0] !== 6 && c[0] !== 2)) {
                    o = 0;
                    continue;
                  }
                  if (c[0] === 3 && (!n || c[1] > n[0] && c[1] < n[3])) {
                    o.label = c[1];
                    break;
                  }
                  if (c[0] === 6 && o.label < n[1]) {
                    o.label = n[1], n = c;
                    break;
                  }
                  if (n && o.label < n[2]) {
                    o.label = n[2], o.ops.push(c);
                    break;
                  }
                  n[2] && o.ops.pop(), o.trys.pop();
                  continue;
              }
              c = t.call(i, o);
            } catch (y) {
              c = [6, y], r = 0;
            } finally {
              e = n = 0;
            }
            if (5 & c[0]) throw c[1];
            return { value: c[0] ? c[1] : void 0, done: !0 };
          }([d, p]);
        };
      }
    }
    function I(i, t, e) {
      for (var r, n = 0, a = t.length; n < a; n++) !r && n in t || (r || (r = Array.prototype.slice.call(t, 0, n)), r[n] = t[n]);
      return i.concat(r || Array.prototype.slice.call(t));
    }
    var W = function i(t, e) {
      if (t === e) return !0;
      if (t && e && typeof t == "object" && typeof e == "object") {
        if (t.constructor !== e.constructor) return !1;
        var r, n, a;
        if (Array.isArray(t)) {
          if ((r = t.length) != e.length) return !1;
          for (n = r; n-- != 0; ) if (!i(t[n], e[n])) return !1;
          return !0;
        }
        if (t.constructor === RegExp) return t.source === e.source && t.flags === e.flags;
        if (t.valueOf !== Object.prototype.valueOf) return t.valueOf() === e.valueOf();
        if (t.toString !== Object.prototype.toString) return t.toString() === e.toString();
        if ((r = (a = Object.keys(t)).length) !== Object.keys(e).length) return !1;
        for (n = r; n-- != 0; ) if (!Object.prototype.hasOwnProperty.call(e, a[n])) return !1;
        for (n = r; n-- != 0; ) {
          var o = a[n];
          if (!i(t[o], e[o])) return !1;
        }
        return !0;
      }
      return t != t && e != e;
    };
    function w(i, t) {
      var e = Object.keys(t || {}).filter(function(r) {
        var n = i == null ? void 0 : i[r], a = t == null ? void 0 : t[r];
        return !W(n, a);
      });
      return Object.keys(i || {}).filter(function(r) {
        Object.keys(t || {}).includes(r) || e.push(r);
      }), Object.keys(e).length ? e : null;
    }
    var g, C;
    function E(i, t, e) {
      var r = "shortString", n = !0;
      typeof e == "number" && (r = "javaDouble", n = !1), i[r] = i[r] || {}, i[r][t] = n ? e + "" : e;
    }
    function A(i) {
      return !!i && typeof i == "object" && i.value !== void 0;
    }
    function $(i) {
      return Object.fromEntries(Object.entries(i).map(function(t) {
        var e = t[0], r = t[1];
        return [e, A(r) ? r : { value: r }];
      }));
    }
    function Y(i) {
      return s(s({}, i), { identity: i.identity ? s(s({}, i.identity), { traits: $(i.identity.traits || {}) }) : void 0 });
    }
    (function(i) {
      i.NONE = "NONE", i.DEFAULT_FLAGS = "DEFAULT_FLAGS", i.CACHE = "CACHE", i.SERVER = "SERVER";
    })(g || (g = {}));
    var fe, F = null, ut = "FLAGSMITH_EVENT", le = ut, qe = "https://edge.api.flagsmith.com/api/v1/", Be = "flagsmith_value_", Me = "flagsmith_enabled_", ze = "flagsmith_trait_", ct = function() {
      function i(t) {
        var e = this;
        this._trigger = null, this._triggerLoadingState = null, this.timestamp = null, this.isLoading = !1, this.eventSource = null, this.getFlags = function() {
          var r = e, n = r.api, a = r.evaluationContext;
          e.log("Get Flags"), e.isLoading = !0, e.loadingState.isFetching || e.setLoadingState(s(s({}, e.loadingState), { isFetching: !0 }));
          var o = "".concat(e.getContext().identity), v = function(d) {
            var p, c, y, k;
            if (d && o === "".concat(e.getContext().identity)) {
              var V = d.flags, P = d.traits, U = d.identifier;
              e.isLoading = !1;
              var j = {}, N = {};
              P = P || [], (V = V || []).forEach(function(m) {
                j[m.feature.name.toLowerCase().replace(/ /g, "_")] = { id: m.feature.id, enabled: m.enabled, value: m.feature_state_value };
              }), P.forEach(function(m) {
                N[m.trait_key.toLowerCase().replace(/ /g, "_")] = { transient: m.transient, value: m.trait_value };
              }), e.oldFlags = s({}, e.flags);
              var G = w(e.oldFlags, j), re = w((p = e.evaluationContext.identity) === null || p === void 0 ? void 0 : p.traits, N);
              if ((U || Object.keys(N).length) && (e.evaluationContext.identity = s(s({}, e.evaluationContext.identity), { traits: N }), U && (e.evaluationContext.identity.identifier = U)), e.flags = j, e.updateStorage(), e._onChange(e.oldFlags, { isFromServer: !0, flagsChanged: G, traitsChanged: re }, e._loadedState(null, g.SERVER)), e.datadogRum) try {
                if (e.datadogRum.trackTraits) {
                  var ie = {};
                  Object.keys(((c = e.evaluationContext.identity) === null || c === void 0 ? void 0 : c.traits) || {}).map(function(m) {
                    ie[ze + m] = e.getTrait(m);
                  });
                  var Z = s(s(s({}, e.datadogRum.client.getUser()), { id: e.datadogRum.client.getUser().id || ((y = e.evaluationContext.identity) === null || y === void 0 ? void 0 : y.identifier) }), ie);
                  e.log("Setting Datadog user", Z), e.datadogRum.client.setUser(Z);
                }
              } catch (m) {
                console.error(m);
              }
              if (e.dtrum) try {
                var T = { javaDouble: {}, date: {}, shortString: {}, javaLongOrObject: {} };
                Object.keys(e.flags).map(function(m) {
                  E(T, Be + m, e.getValue(m, { skipAnalytics: !0 })), E(T, Me + m, e.hasFeature(m, { skipAnalytics: !0 }));
                }), Object.keys(((k = e.evaluationContext.identity) === null || k === void 0 ? void 0 : k.traits) || {}).map(function(m) {
                  E(T, ze + m, e.getTrait(m));
                }), e.log("Sending javaLongOrObject traits to dynatrace", T.javaLongOrObject), e.log("Sending date traits to dynatrace", T.date), e.log("Sending shortString traits to dynatrace", T.shortString), e.log("Sending javaDouble to dynatrace", T.javaDouble), e.dtrum.sendSessionProperties(T.javaLongOrObject, T.date, T.shortString, T.javaDouble);
              } catch (m) {
                console.error(m);
              }
            }
          };
          return a.identity ? Promise.all([a.identity.traits && Object.keys(a.identity.traits).length || !a.identity.identifier ? e.getJSON(n + "identities/", "POST", JSON.stringify({ identifier: a.identity.identifier, transient: a.identity.transient, traits: Object.entries(a.identity.traits).map(function(d) {
            var p = d[0], c = d[1];
            return { trait_key: p, trait_value: c == null ? void 0 : c.value, transient: c == null ? void 0 : c.transient };
          }).filter(function(d) {
            return d.trait_value !== void 0 || (e.log("Warning - attempted to set an undefined trait value for key", d.trait_key), !1);
          }) })) : e.getJSON(n + "identities/?identifier=" + encodeURIComponent(a.identity.identifier) + (a.identity.transient ? "&transient=true" : ""))]).then(function(d) {
            return e.evaluationContext.identity = s(s({}, e.evaluationContext.identity), { traits: {} }), v(d == null ? void 0 : d[0]);
          }).catch(function(d) {
            var p = d.message, c = new Error(p);
            return Promise.reject(c);
          }) : e.getJSON(n + "flags/").then(function(d) {
            return v({ flags: d, traits: void 0 });
          });
        }, this.analyticsFlags = function() {
          var r = e.api;
          if (e.evaluationEvent && e.evaluationContext.environment && e.evaluationEvent[e.evaluationContext.environment.apiKey]) return e.evaluationEvent && Object.getOwnPropertyNames(e.evaluationEvent).length !== 0 && Object.getOwnPropertyNames(e.evaluationEvent[e.evaluationContext.environment.apiKey]).length !== 0 ? e.getJSON(r + "analytics/flags/", "POST", JSON.stringify(e.evaluationEvent[e.evaluationContext.environment.apiKey])).then(function(n) {
            if (e.evaluationContext.environment) {
              var a = e.getState();
              e.evaluationEvent || (e.evaluationEvent = {}), e.evaluationEvent[e.evaluationContext.environment.apiKey] = {}, e.setState(s(s({}, a), { evaluationEvent: e.evaluationEvent })), e.updateEventStorage();
            }
          }).catch(function(n) {
            e.log("Exception fetching evaluationEvent", n);
          }) : void 0;
        }, this.datadogRum = null, this.loadingState = { isLoading: !0, isFetching: !0, error: null, source: g.NONE }, this.canUseStorage = !1, this.analyticsInterval = null, this.api = null, this.cacheFlags = !1, this.ts = null, this.enableAnalytics = !1, this.enableLogs = !1, this.evaluationContext = {}, this.evaluationEvent = null, this.flags = null, this.getFlagInterval = null, this.headers = null, this.initialised = !1, this.oldFlags = null, this.onChange = null, this.onError = null, this.ticks = null, this.timer = null, this.dtrum = null, this.withTraits = null, this.cacheOptions = { ttl: 0, skipAPI: !1, loadStale: !1, storageKey: void 0 }, this.getValue = function(r, n, a) {
          var o = e.flags && e.flags[r.toLowerCase().replace(/ /g, "_")], v = null;
          if (o && (v = o.value), n != null && n.skipAnalytics || a || e.evaluateFlag(r, "VALUE"), v === null && (n == null ? void 0 : n.fallback) !== void 0) return n.fallback;
          if (n != null && n.json) try {
            return v === null ? (e.log("Tried to parse null flag as JSON: " + r), null) : JSON.parse(v);
          } catch {
            return n.fallback;
          }
          return v;
        }, this.getTrait = function(r) {
          var n, a;
          return ((n = e.evaluationContext.identity) === null || n === void 0 ? void 0 : n.traits) && ((a = e.evaluationContext.identity.traits[r.toLowerCase().replace(/ /g, "_")]) === null || a === void 0 ? void 0 : a.value);
        }, this.getAllTraits = function() {
          var r;
          return Object.fromEntries(Object.entries(((r = e.evaluationContext.identity) === null || r === void 0 ? void 0 : r.traits) || {}).map(function(n) {
            var a = n[0], o = n[1];
            return [a, o == null ? void 0 : o.value];
          }));
        }, this.setContext = function(r) {
          var n = Y(r);
          return e.evaluationContext = s(s({}, n), { environment: n.environment || e.evaluationContext.environment }), e.initialised ? e.getFlags() : Promise.resolve();
        }, this.getContext = function() {
          return e.evaluationContext;
        }, this.updateContext = function(r) {
          return e.setContext(s(s({}, e.getContext()), r));
        }, this.setTrait = function(r, n) {
          var a;
          if (e.api) return e.setContext(s(s({}, e.evaluationContext), { identity: s(s({}, e.evaluationContext.identity), { traits: s(s({}, (a = e.evaluationContext.identity) === null || a === void 0 ? void 0 : a.traits), $(Object.fromEntries([[r, n]]))) }) }));
        }, this.setTraits = function(r) {
          var n;
          if (e.api) return e.setContext(s(s({}, e.evaluationContext), { identity: s(s({}, e.evaluationContext.identity), { traits: s(s({}, (n = e.evaluationContext.identity) === null || n === void 0 ? void 0 : n.traits), Object.fromEntries(Object.entries(r).map(function(a) {
            var o = a[0], v = a[1];
            return [o, A(v) ? v : { value: v }];
          }))) }) }));
          console.error("Attempted to setTraits a user before calling flagsmith.init. Call flagsmith.init first, if you wish to prevent it sending a request for flags, call init with preventFetch:true.");
        }, this.hasFeature = function(r, n) {
          var a = typeof n == "object", o = e.flags && e.flags[r.toLowerCase().replace(/ /g, "_")], v = !1;
          return !o && a && n.fallback !== void 0 ? v = n == null ? void 0 : n.fallback : o && o.enabled && (v = !0), (a && !n.skipAnalytics || !n) && e.evaluateFlag(r, "ENABLED"), v;
        }, this.getStorageKey = function() {
          var r, n;
          return ((r = e.cacheOptions) === null || r === void 0 ? void 0 : r.storageKey) || "FLAGSMITH_DB_" + ((n = e.evaluationContext.environment) === null || n === void 0 ? void 0 : n.apiKey);
        }, this.getJSON = function(r, n, a) {
          var o, v = e;
          v.evaluationContext;
          var d = v.headers, p = { method: n || "GET", body: a, cache: "no-cache", headers: {} };
          e.evaluationContext.environment && (p.headers["X-Environment-Key"] = e.evaluationContext.environment.apiKey), n && n !== "GET" && (p.headers["Content-Type"] = "application/json; charset=utf-8"), d && Object.assign(p.headers, d), C || console.error("Flagsmith: fetch is undefined, please specify a fetch implementation into flagsmith.init to support SSR.");
          var c = "".concat((o = e.evaluationContext.identity) === null || o === void 0 ? void 0 : o.identifier);
          return C(r, p).then(function(y) {
            var k, V, P = "".concat((k = e.evaluationContext.identity) === null || k === void 0 ? void 0 : k.identifier);
            if (c === P) {
              var U = (V = y.headers) === null || V === void 0 ? void 0 : V.get("x-flagsmith-document-updated-at");
              if (U) try {
                var j = parseFloat(U);
                if (isNaN(j)) return Promise.reject("Failed to parse x-flagsmith-document-updated-at");
                e.timestamp = j;
              } catch (N) {
                e.log(N, "Failed to parse x-flagsmith-document-updated-at", U);
              }
              return e.log("Fetch response: " + y.status + " " + (n || "GET") + 0 + r), y.text().then(function(N) {
                var G = N;
                try {
                  G = JSON.parse(N);
                } catch {
                }
                return !G && y.status && (G = "API Response: ".concat(y.status)), y.status && y.status >= 200 && y.status < 300 ? G : Promise.reject(new Error(G));
              });
            }
            e.log("Received response with identity mismatch, ignoring response. Requested: ".concat(c, ", Current: ").concat(P));
          });
        }, this.evaluateFlag = function(r, n) {
          if (e.datadogRum && (e.datadogRum.client.addFeatureFlagEvaluation ? n === "VALUE" ? e.datadogRum.client.addFeatureFlagEvaluation(Be + r, e.getValue(r, {}, !0)) : e.datadogRum.client.addFeatureFlagEvaluation(Me + r, e.hasFeature(r, !0)) : console.error("Flagsmith: Your datadog RUM client does not support the function addFeatureFlagEvaluation, please update it.")), e.enableAnalytics) {
            if (!e.evaluationEvent || !e.evaluationContext.environment) return;
            e.evaluationEvent[e.evaluationContext.environment.apiKey] || (e.evaluationEvent[e.evaluationContext.environment.apiKey] = {}), e.evaluationEvent[e.evaluationContext.environment.apiKey][r] === void 0 && (e.evaluationEvent[e.evaluationContext.environment.apiKey][r] = 0), e.evaluationEvent[e.evaluationContext.environment.apiKey][r] += 1;
          }
          e.updateEventStorage();
        }, this._onChange = function(r, n, a) {
          var o, v;
          e.setLoadingState(a), (o = e.onChange) === null || o === void 0 || o.call(e, r, n, e.loadingState), (v = e._trigger) === null || v === void 0 || v.call(e);
        }, C = t.fetch ? t.fetch : typeof fetch < "u" ? fetch : ve === null || ve === void 0 ? void 0 : ve.fetch, this.canUseStorage = typeof window < "u" || !!t.browserlessStorage, this.log("Constructing flagsmith instance " + t), t.eventSource && (fe = t.eventSource), t.AsyncStorage && (F = t.AsyncStorage);
      }
      return i.prototype.init = function(t) {
        var e, r, n;
        return O(this, void 0, void 0, function() {
          var a, o, v, d, p, c, y, k, V, P, U, j, N, G, re, ie, Z, T, m, pe, ae, Qe, Q, ye, et, tt, me, nt, be, oe, ee, rt, L = this;
          return K(this, function(D) {
            switch (D.label) {
              case 0:
                a = Y(t.evaluationContext || this.evaluationContext), D.label = 1;
              case 1:
                if (D.trys.push([1, 13, , 14]), o = t.environmentID, v = t.api, d = v === void 0 ? qe : v, p = t.headers, c = t.onChange, y = t.cacheFlags, k = t.datadogRum, V = t.onError, P = t.defaultFlags, U = t.fetch, j = t.preventFetch, N = t.enableLogs, G = t.enableDynatrace, re = t.enableAnalytics, ie = t.realtime, Z = t.eventSourceUrl, T = Z === void 0 ? "https://realtime.flagsmith.com/" : Z, m = t.AsyncStorage, pe = t.identity, ae = t.traits, Qe = t.state, Q = t.cacheOptions, ye = t.angularHttpClient, et = t._trigger, tt = t._triggerLoadingState, a.environment = o ? { apiKey: o } : a.environment, !a.environment || !a.environment.apiKey) throw new Error("Please provide `evaluationContext.environment` with non-empty `apiKey`");
                if (a.identity = pe || ae ? { identifier: pe, traits: ae ? Object.fromEntries(Object.entries(ae).map(function(R) {
                  return [R[0], { value: R[1] }];
                })) : {} } : a.identity, this.evaluationContext = a, this.api = d, this.headers = p, this.getFlagInterval = null, this.analyticsInterval = null, this.onChange = c, me = "Wrong Flagsmith Configuration: preventFetch is true and no defaulFlags provided", this._trigger = et || this._trigger, this._triggerLoadingState = tt || this._triggerLoadingState, this.onError = function(R) {
                  L.setLoadingState(s(s({}, L.loadingState), { isFetching: !1, isLoading: !1, error: R })), V == null || V(R);
                }, this.enableLogs = N || !1, this.cacheOptions = Q ? { skipAPI: !!Q.skipAPI, ttl: Q.ttl || 0, storageKey: Q.storageKey, loadStale: !!Q.loadStale } : this.cacheOptions, !this.cacheOptions.ttl && this.cacheOptions.skipAPI && console.warn("Flagsmith: you have set a cache ttl of 0 and are skipping API calls, this means the API will not be hit unless you clear local storage."), U && (C = U), this.enableAnalytics = re || !1, this.flags = Object.assign({}, P) || {}, this.datadogRum = k || null, this.initialised = !0, this.ticks = 1e4, this.timer = this.enableLogs ? (/* @__PURE__ */ new Date()).valueOf() : null, this.cacheFlags = F !== void 0 && !!y, le = "FLAGSMITH_EVENT_" + a.environment.apiKey, m && (F = m), ie && typeof window < "u" && this.setupRealtime(T, a.environment.apiKey), Object.keys(this.flags).length && (this.loadingState = s(s({}, this.loadingState), { isLoading: !1, source: g.DEFAULT_FLAGS })), this.setState(Qe), this.log("Initialising with properties", t, this), G && (typeof dtrum > "u" ? console.error("You have attempted to enable dynatrace but dtrum is undefined, please check you have the Dynatrace RUM JavaScript API installed.") : this.dtrum = dtrum), ye && (C = /* @__PURE__ */ function(R) {
                  return function(J, q) {
                    var z = q.headers, x = q.method, te = q.body;
                    return new Promise(function(X) {
                      switch (x) {
                        case "GET":
                          return R.get(J, { headers: z }).subscribe(function(M) {
                            X({ ok: !0, text: function() {
                              return Promise.resolve(M);
                            } });
                          });
                        case "POST":
                        case "PUT":
                          return R.post(J, te, { headers: z }).subscribe(function(M) {
                            X({ ok: !0, text: function() {
                              return Promise.resolve(M);
                            } });
                          });
                      }
                    });
                  };
                }(ye)), F && this.canUseStorage && F.getItem(le).then(function(R) {
                  try {
                    L.evaluationEvent = JSON.parse(R) || {};
                  } catch {
                    L.evaluationEvent = {};
                  }
                  L.analyticsInterval = setInterval(L.analyticsFlags, L.ticks);
                }), this.enableAnalytics && (this.analyticsInterval && clearInterval(this.analyticsInterval), F && this.canUseStorage && F.getItem(le, function(R, J) {
                  if (J && L.evaluationContext.environment) {
                    var q = JSON.parse(J);
                    if (q[L.evaluationContext.environment.apiKey]) {
                      var z = L.getState();
                      L.log("Retrieved events from cache", J), L.setState(s(s({}, z), { evaluationEvent: q[L.evaluationContext.environment.apiKey] }));
                    }
                  }
                })), !y) return [3, 9];
                if (!F || !this.canUseStorage) return [3, 8];
                nt = function(R, J) {
                  return O(L, void 0, void 0, function() {
                    var q, z, x, te, X, M, Se, it, Ce, xe, Ee, we, Oe, ke, Te, Le, Fe, Ie, Ae, Pe, je, Ne, Re, Ue, at = this;
                    return K(this, function(H) {
                      switch (H.label) {
                        case 0:
                          if (!J) return [3, 7];
                          q = null, z = null, H.label = 1;
                        case 1:
                          return H.trys.push([1, 5, , 6]), x = JSON.parse(J), te = !1, X = !1, x && x.api === this.api && ((xe = (Ce = x.evaluationContext) === null || Ce === void 0 ? void 0 : Ce.environment) === null || xe === void 0 ? void 0 : xe.apiKey) === ((Ee = this.evaluationContext.environment) === null || Ee === void 0 ? void 0 : Ee.apiKey) && (M = !0, this.evaluationContext.identity && ((Oe = (we = x.evaluationContext) === null || we === void 0 ? void 0 : we.identity) === null || Oe === void 0 ? void 0 : Oe.identifier) !== this.evaluationContext.identity.identifier && (this.log("Ignoring cache, identity has changed from " + ((Te = (ke = x.evaluationContext) === null || ke === void 0 ? void 0 : ke.identity) === null || Te === void 0 ? void 0 : Te.identifier) + " to " + this.evaluationContext.identity.identifier), M = !1), this.cacheOptions.ttl && (!x.ts || (/* @__PURE__ */ new Date()).valueOf() - x.ts > this.cacheOptions.ttl) && (x.ts && !this.cacheOptions.loadStale ? (this.log("Ignoring cache, timestamp is too old ts:" + x.ts + " ttl: " + this.cacheOptions.ttl + " time elapsed since cache: " + ((/* @__PURE__ */ new Date()).valueOf() - x.ts) + "ms"), M = !1) : x.ts && this.cacheOptions.loadStale && (this.log("Loading stale cache, timestamp ts:" + x.ts + " ttl: " + this.cacheOptions.ttl + " time elapsed since cache: " + ((/* @__PURE__ */ new Date()).valueOf() - x.ts) + "ms"), X = !0, M = !0)), M && (te = !0, z = w((Le = this.evaluationContext.identity) === null || Le === void 0 ? void 0 : Le.traits, (Ie = (Fe = x.evaluationContext) === null || Fe === void 0 ? void 0 : Fe.identity) === null || Ie === void 0 ? void 0 : Ie.traits), q = w(this.flags, x.flags), this.setState(s(s({}, x), { evaluationContext: Y(s(s({}, x.evaluationContext), { identity: !((Ae = x.evaluationContext) === null || Ae === void 0) && Ae.identity ? s(s({}, (Pe = x.evaluationContext) === null || Pe === void 0 ? void 0 : Pe.identity), { traits: s(s({}, ((Ne = (je = x.evaluationContext) === null || je === void 0 ? void 0 : je.identity) === null || Ne === void 0 ? void 0 : Ne.traits) || {}), ae || {}) }) : void 0 })) })), this.log("Retrieved flags from cache", x))), te ? (Se = !j && (!this.cacheOptions.skipAPI || X), this._onChange(null, { isFromServer: !1, flagsChanged: q, traitsChanged: z }, this._loadedState(null, g.CACHE, Se)), this.oldFlags = this.flags, this.cacheOptions.skipAPI && te && !X && this.log("Skipping API, using cache"), Se && this.getFlags().catch(function(dt) {
                            var De;
                            (De = at.onError) === null || De === void 0 || De.call(at, dt);
                          }), [3, 4]) : [3, 2];
                        case 2:
                          return j ? [3, 4] : [4, this.getFlags()];
                        case 3:
                          H.sent(), H.label = 4;
                        case 4:
                          return [3, 6];
                        case 5:
                          return it = H.sent(), this.log("Exception fetching cached logs", it), [3, 6];
                        case 6:
                          return [3, 10];
                        case 7:
                          return j ? [3, 9] : [4, this.getFlags()];
                        case 8:
                          return H.sent(), [3, 10];
                        case 9:
                          if (P) this._onChange(null, { isFromServer: !1, flagsChanged: w({}, this.flags), traitsChanged: w({}, (Re = this.evaluationContext.identity) === null || Re === void 0 ? void 0 : Re.traits) }, this._loadedState(null, g.DEFAULT_FLAGS));
                          else {
                            if (!this.flags) throw new Error(me);
                            this._onChange(null, { isFromServer: !1, flagsChanged: w({}, this.flags), traitsChanged: w({}, (Ue = this.evaluationContext.identity) === null || Ue === void 0 ? void 0 : Ue.traits) }, this._loadedState(null, g.DEFAULT_FLAGS));
                          }
                          H.label = 10;
                        case 10:
                          return [2];
                      }
                    });
                  });
                }, D.label = 2;
              case 2:
                return D.trys.push([2, 7, , 8]), F.getItemSync ? (be = F.getItemSync(this.getStorageKey()), [3, 5]) : [3, 3];
              case 3:
                return [4, F.getItem(this.getStorageKey())];
              case 4:
                be = D.sent(), D.label = 5;
              case 5:
                return [4, nt(null, be)];
              case 6:
              case 7:
                return D.sent(), [3, 8];
              case 8:
                return [3, 12];
              case 9:
                return j ? [3, 11] : [4, this.getFlags()];
              case 10:
                return D.sent(), [3, 12];
              case 11:
                if (P) this._onChange(null, { isFromServer: !1, flagsChanged: w({}, P), traitsChanged: w({}, (e = a.identity) === null || e === void 0 ? void 0 : e.traits) }, this._loadedState(null, g.DEFAULT_FLAGS));
                else if (this.flags && (oe = null, Object.keys(this.flags).length === 0 && (oe = me), this._onChange(null, { isFromServer: !1, flagsChanged: w({}, this.flags), traitsChanged: w({}, (r = a.identity) === null || r === void 0 ? void 0 : r.traits) }, this._loadedState(oe, g.DEFAULT_FLAGS)), oe)) throw new Error(oe);
                D.label = 12;
              case 12:
                return [3, 14];
              case 13:
                throw ee = D.sent(), this.log("Error during initialisation ", ee), rt = ee instanceof Error ? ee : new Error("".concat(ee)), (n = this.onError) === null || n === void 0 || n.call(this, rt), ee;
              case 14:
                return [2];
            }
          });
        });
      }, i.prototype.getAllFlags = function() {
        return this.flags;
      }, i.prototype.identify = function(t, e, r) {
        return this.evaluationContext.identity = { identifier: t, transient: r, traits: this.evaluationContext.identity && this.evaluationContext.identity.identifier == t ? this.evaluationContext.identity.traits : {} }, this.evaluationContext.identity.identifier = t, this.log("Identify: " + this.evaluationContext.identity.identifier), e && (this.evaluationContext.identity.traits = Object.fromEntries(Object.entries(e).map(function(n) {
          var a = n[0], o = n[1];
          return [a, A(o) ? o : { value: o }];
        }))), this.initialised ? this.getFlags() : Promise.resolve();
      }, i.prototype.getState = function() {
        return { api: this.api, flags: this.flags, ts: this.ts, evaluationContext: this.evaluationContext, evaluationEvent: this.evaluationEvent };
      }, i.prototype.setState = function(t) {
        t && (this.initialised = !0, this.api = t.api || this.api || qe, this.flags = t.flags || this.flags, this.evaluationContext = t.evaluationContext || this.evaluationContext, this.evaluationEvent = t.evaluationEvent || this.evaluationEvent, this.log("setState called", this));
      }, i.prototype.logout = function() {
        return this.evaluationContext.identity = null, this.initialised ? this.getFlags() : Promise.resolve();
      }, i.prototype.startListening = function(t) {
        t === void 0 && (t = 1e3), this.getFlagInterval && clearInterval(this.getFlagInterval), this.getFlagInterval = setInterval(this.getFlags, t);
      }, i.prototype.stopListening = function() {
        this.getFlagInterval && (clearInterval(this.getFlagInterval), this.getFlagInterval = null);
      }, i.prototype._loadedState = function(t, e, r) {
        return t === void 0 && (t = null), r === void 0 && (r = !1), { error: t, isFetching: r, isLoading: !1, source: e };
      }, i.prototype.log = function() {
        for (var t = [], e = 0; e < arguments.length; e++) t[e] = arguments[e];
        this.enableLogs && console.log.apply(this, I(["FLAGSMITH:", (/* @__PURE__ */ new Date()).valueOf() - (this.timer || 0), "ms"], t));
      }, i.prototype.updateStorage = function() {
        if (this.cacheFlags) {
          this.ts = (/* @__PURE__ */ new Date()).valueOf();
          var t = JSON.stringify(this.getState());
          this.log("Setting storage", t), F.setItem(this.getStorageKey(), t);
        }
      }, i.prototype.updateEventStorage = function() {
        if (this.enableAnalytics) {
          var t = JSON.stringify(this.getState().evaluationEvent);
          F.setItem(le, t).catch(function(e) {
            return console.error("Flagsmith: Error setting item in async storage", e);
          });
        }
      }, i.prototype.setLoadingState = function(t) {
        var e;
        W(t, this.loadingState) || (this.loadingState = s({}, t), this.log("Loading state changed", t), (e = this._triggerLoadingState) === null || e === void 0 || e.call(this));
      }, i.prototype.setupRealtime = function(t, e) {
        var r = this, n = t + "sse/environments/" + e + "/stream";
        fe ? this.eventSource || (this.log("Creating event source with url " + n), this.eventSource = new fe(n), this.eventSource.addEventListener("environment_updated", function(a) {
          var o;
          try {
            o = JSON.parse(a.data).updated_at;
          } catch (v) {
            r.log("Could not parse sse event", v);
          }
          o ? !r.timestamp || o > r.timestamp ? r.isLoading ? r.log("updated_at is new, but flags are loading", a.data, r.timestamp) : (r.log("updated_at is new, fetching flags", a.data, r.timestamp), r.getFlags()) : r.log("updated_at is outdated, skipping get flags", a.data, r.timestamp) : r.log("No updated_at received, fetching flags", a);
        })) : this.log("Error, EventSource is undefined");
      }, i;
    }();
    function He(i) {
      var t = i.fetch, e = i.AsyncStorage, r = i.eventSource;
      return new ct({ fetch: t, AsyncStorage: e, eventSource: r });
    }
    var ue, vt = (ue = function(i, t) {
      return ue = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(e, r) {
        e.__proto__ = r;
      } || function(e, r) {
        for (var n in r) Object.prototype.hasOwnProperty.call(r, n) && (e[n] = r[n]);
      }, ue(i, t);
    }, function(i, t) {
      if (typeof t != "function" && t !== null) throw new TypeError("Class extends value " + String(t) + " is not a constructor or null");
      function e() {
        this.constructor = i;
      }
      ue(i, t), i.prototype = t === null ? Object.create(t) : (e.prototype = t.prototype, new e());
    }), $e = function(i) {
      var t = typeof Symbol == "function" && Symbol.iterator, e = t && i[t], r = 0;
      if (e) return e.call(i);
      if (i && typeof i.length == "number") return { next: function() {
        return i && r >= i.length && (i = void 0), { value: i && i[r++], done: !i };
      } };
      throw new TypeError(t ? "Object is not iterable." : "Symbol.iterator is not defined.");
    }, Xe = function(i, t) {
      var e = typeof Symbol == "function" && i[Symbol.iterator];
      if (!e) return i;
      var r, n, a = e.call(i), o = [];
      try {
        for (; (t === void 0 || t-- > 0) && !(r = a.next()).done; ) o.push(r.value);
      } catch (v) {
        n = { error: v };
      } finally {
        try {
          r && !r.done && (e = a.return) && e.call(a);
        } finally {
          if (n) throw n.error;
        }
      }
      return o;
    }, ge = function(i, t, e) {
      if (arguments.length === 2) for (var r, n = 0, a = t.length; n < a; n++) !r && n in t || (r || (r = Array.prototype.slice.call(t, 0, n)), r[n] = t[n]);
      return i.concat(r || Array.prototype.slice.call(t));
    }, _t = function(i) {
      function t() {
        return i.call(this, `EventSource not available.
Consider loading an EventSource polyfill and making it available globally as EventSource, or passing one in as eventSourceClass to the ReconnectingEventSource constructor.`) || this;
      }
      return vt(t, i), t;
    }(Error), We = function() {
      function i(t, e) {
        var r = this;
        if (this.CONNECTING = 0, this.OPEN = 1, this.CLOSED = 2, this._configuration = e != null ? Object.assign({}, e) : void 0, this.withCredentials = !1, this._eventSource = null, this._lastEventId = null, this._timer = null, this._listeners = { open: [], error: [], message: [] }, this.url = t.toString(), this.readyState = this.CONNECTING, this.max_retry_time = 3e3, this.eventSourceClass = globalThis.FlagsmithEventSource, this._configuration != null && (this._configuration.lastEventId && (this._lastEventId = this._configuration.lastEventId, delete this._configuration.lastEventId), this._configuration.max_retry_time && (this.max_retry_time = this._configuration.max_retry_time, delete this._configuration.max_retry_time), this._configuration.eventSourceClass && (this.eventSourceClass = this._configuration.eventSourceClass, delete this._configuration.eventSourceClass)), this.eventSourceClass == null || typeof this.eventSourceClass != "function") throw new _t();
        this._onevent_wrapped = function(n) {
          r._onevent(n);
        }, this._start();
      }
      return i.prototype.dispatchEvent = function(t) {
        throw new Error("Method not implemented.");
      }, i.prototype._start = function() {
        var t, e, r = this, n = this.url;
        this._lastEventId && (n.indexOf("?") === -1 ? n += "?" : n += "&", n += "lastEventId=" + encodeURIComponent(this._lastEventId)), this._eventSource = new this.eventSourceClass(n, this._configuration), this._eventSource.onopen = function(d) {
          r._onopen(d);
        }, this._eventSource.onerror = function(d) {
          r._onerror(d);
        }, this._eventSource.onmessage = function(d) {
          r.onmessage(d);
        };
        try {
          for (var a = $e(Object.keys(this._listeners)), o = a.next(); !o.done; o = a.next()) {
            var v = o.value;
            this._eventSource.addEventListener(v, this._onevent_wrapped);
          }
        } catch (d) {
          t = { error: d };
        } finally {
          try {
            o && !o.done && (e = a.return) && e.call(a);
          } finally {
            if (t) throw t.error;
          }
        }
      }, i.prototype._onopen = function(t) {
        this.readyState === 0 && (this.readyState = 1, this.onopen(t));
      }, i.prototype._onerror = function(t) {
        var e = this;
        if (this.readyState === 1 && (this.readyState = 0, this.onerror(t)), this._eventSource) {
          this._eventSource.close(), this._eventSource = null;
          var r = Math.round(this.max_retry_time * Math.random());
          this._timer = setTimeout(function() {
            return e._start();
          }, r);
        }
      }, i.prototype._onevent = function(t) {
        var e, r;
        t && t.lastEventId && (this._lastEventId = t.lastEventId);
        var n = this._listeners[t.type];
        if (n != null) try {
          for (var a = $e(ge([], Xe(n), !1)), o = a.next(); !o.done; o = a.next())
            o.value.call(this, t);
        } catch (v) {
          e = { error: v };
        } finally {
          try {
            o && !o.done && (r = a.return) && r.call(a);
          } finally {
            if (e) throw e.error;
          }
        }
        t.type === "message" && this.onmessage(t);
      }, i.prototype.onopen = function(t) {
      }, i.prototype.onerror = function(t) {
      }, i.prototype.onmessage = function(t) {
      }, i.prototype.close = function() {
        this._timer && (clearTimeout(this._timer), this._timer = null), this._eventSource && (this._eventSource.close(), this._eventSource = null), this.readyState = 2;
      }, i.prototype.addEventListener = function(t, e, r) {
        this._listeners[t] == null && (this._listeners[t] = [], this._eventSource != null && this._eventSource.addEventListener(t, this._onevent_wrapped));
        var n = this._listeners[t];
        n.includes(e) || (this._listeners[t] = ge(ge([], Xe(n), !1), [e], !1));
      }, i.prototype.removeEventListener = function(t, e, r) {
        var n = this._listeners[t];
        this._listeners[t] = n.filter(function(a) {
          return a !== e;
        });
      }, i;
    }();
    globalThis.FlagsmithEventSource = typeof EventSource < "u" ? EventSource : null;
    var Ye = function(i, t) {
      return t = t || {}, new Promise(function(e, r) {
        var n = new XMLHttpRequest(), a = [], o = [], v = {}, d = function() {
          return { ok: (n.status / 100 | 0) == 2, statusText: n.statusText, status: n.status, url: n.responseURL, text: function() {
            return Promise.resolve(n.responseText);
          }, json: function() {
            return Promise.resolve(n.responseText).then(JSON.parse);
          }, blob: function() {
            return Promise.resolve(new Blob([n.response]));
          }, clone: d, headers: { keys: function() {
            return a;
          }, entries: function() {
            return o;
          }, get: function(c) {
            return v[c.toLowerCase()];
          }, has: function(c) {
            return c.toLowerCase() in v;
          } } };
        };
        for (var p in n.open(t.method || "get", i, !0), n.onload = function() {
          n.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm, function(c, y, k) {
            a.push(y = y.toLowerCase()), o.push([y, k]), v[y] = v[y] ? v[y] + "," + k : k;
          }), e(d());
        }, n.onerror = r, n.withCredentials = t.credentials == "include", t.headers) n.setRequestHeader(p, t.headers[p]);
        n.send(t.body || null);
      });
    }, Ze = He({ AsyncStorage: f, fetch: Ye, eventSource: We });
    typeof window < "u" && (window.flagsmith = Ze), _.createFlagsmithInstance = function() {
      return He({ AsyncStorage: f, fetch: Ye, eventSource: We });
    }, _.default = Ze, Object.defineProperty(_, "__esModule", { value: !0 });
  });
})(Je, Je.exports);
var pt = Je.exports, yt = {
  NOT_INITIALIZED: "FeatureFlag not initialized. Call init() first.",
  INVALID_CONFIG: "Invalid Flagsmith configuration",
  FETCH_FAILED: "Failed to fetch Flagsmith configuration",
  NO_USER_CONTEXT: "User context not set. Call setUser() first.",
  ALREADY_INITIALIZED: "FeatureFlag is already initialized."
}, st = "business", B, mt = (B = class {
  constructor() {
    ce(this, "flagsmithClient", null);
    ce(this, "userContext", null);
  }
  static getInstance() {
    return B.instance || (B.instance = new B()), B.instance;
  }
  ensureInitialized() {
    if (!this.flagsmithClient)
      throw new Error(yt.NOT_INITIALIZED);
  }
  async init(u, _ = []) {
    if (!this.flagsmithClient)
      try {
        this.flagsmithClient = pt.createFlagsmithInstance();
        const f = _.reduce((s, O) => (s[O.feature.name] = O, s), {});
        await this.flagsmithClient.init({
          environmentID: u.apiKey,
          api: (u == null ? void 0 : u.url) ?? "https://feature-flag-proxy.feedme.farm/api/v1/",
          enableAnalytics: (u == null ? void 0 : u.enableAnalytics) ?? !0,
          defaultFlags: f,
          cacheFlags: (u == null ? void 0 : u.cacheFlags) ?? !0
        });
      } catch (f) {
        throw console.error("Failed to initialize FeatureFlag:", f), f;
      }
  }
  async setUser(u) {
    this.ensureInitialized(), this.userContext = { identifier: u }, await this.updateContext();
  }
  async updateContext() {
    try {
      if (!this.userContext) return;
      await this.flagsmithClient.setContext({
        identity: {
          identifier: this.userContext.identifier
        }
      });
    } catch (u) {
      throw console.error("Failed to update user context:", u), u;
    }
  }
  async getFlags() {
    this.ensureInitialized();
    const u = this.flagsmithClient.getAllFlags();
    return Object.entries(u).map(([_, f]) => {
      var s;
      return {
        feature: {
          name: _,
          id: (f == null ? void 0 : f.id) ?? 0
        },
        enabled: f.enabled,
        value: ((s = f.value) == null ? void 0 : s.toString()) ?? null
      };
    });
  }
  getFlagValue(u, _) {
    this.ensureInitialized();
    const f = this.flagsmithClient.getValue(u);
    if (f == null)
      return null;
    try {
      const s = f.toString();
      return _ ? _(s) : typeof {} == "number" ? isNaN(Number(s)) ? null : Number(s) : typeof {} == "boolean" ? s.toLowerCase() === "true" : s;
    } catch (s) {
      return console.error("Error transforming flag value:", s), null;
    }
  }
  getFlag(u) {
    this.ensureInitialized();
    const _ = this.flagsmithClient.getValue(u);
    if (_ == null) return null;
    const f = this.flagsmithClient.hasFeature(u);
    return {
      feature: {
        name: u,
        id: 0
      },
      enabled: f,
      value: _.toString()
    };
  }
  async getUserFlagValue(u, _, f = null, s) {
    var K;
    const O = this.userContext;
    try {
      return await this.setUser(u), this.getFlagValue(_, s) ?? f;
    } catch (I) {
      return console.error(`Error getting user flag value for ${_}:`, I), f;
    } finally {
      try {
        await ((K = this.flagsmithClient) == null ? void 0 : K.logout()), this.userContext = null, O && await this.setUser(O.identifier);
      } catch (I) {
        console.error("Error during cleanup:", I);
      }
    }
  }
  reset() {
    this.flagsmithClient = null, this.userContext = null;
  }
}, ce(B, "instance"), B), bt = mt.getInstance(), se = de(!1), _e = de([]), ne = de(null);
function St(l = bt) {
  const u = () => se.value ? !0 : (console.warn("FeatureFlag is not initialized. Using default values."), !1), _ = async (g, C = []) => {
    if (se.value) {
      console.warn("FeatureFlag is already initialized.");
      return;
    }
    try {
      await l.init(g, C), _e.value = await l.getFlags(), se.value = !0, ne.value = null;
    } catch (E) {
      console.error("Failed to initialize feature flags:", E), ne.value = E;
    }
  }, f = async (g) => {
    if (u())
      try {
        await l.setUser(g), _e.value = await l.getFlags(), ne.value = null;
      } catch (C) {
        console.error("Failed to set user:", C), ne.value = C;
      }
  }, s = async (g) => f(`${st}-${g}`), O = (g, C, E = null) => {
    if (!u()) return E;
    try {
      return l.getFlagValue(g, C) ?? E;
    } catch (A) {
      return console.error(`Error getting flag value for ${g}:`, A), E;
    }
  }, K = (g, C) => {
    if (!u()) return C ?? null;
    try {
      return l.getFlag(g) ?? C ?? null;
    } catch (E) {
      return console.error(`Error getting flag for ${g}:`, E), C ?? null;
    }
  }, I = async (g, C, E = null, A) => {
    if (!u()) return E;
    try {
      return await l.getUserFlagValue(g, C, E, A);
    } catch ($) {
      return console.error(`Error getting user flag value for ${C}:`, $), E;
    }
  }, W = async (g, C, E = null, A) => I(`${st}-${g}`, C, E, A), w = () => {
    try {
      l.reset();
    } catch (g) {
      console.error("Error resetting feature flags:", g);
    } finally {
      _e.value = [], se.value = !1, ne.value = null;
    }
  };
  return {
    flags: Ge(_e),
    isInitialized: Ge(se),
    error: Ge(ne),
    init: _,
    setUser: f,
    setBusiness: s,
    getFlagValue: O,
    getFlag: K,
    getUserFlagValue: I,
    getBusinessFlagValue: W,
    reset: w
  };
}
var he = () => St(), b = /* @__PURE__ */ ((l) => (l.inventory_portal_must_use_transfer_template = "inventory_portal_must_use_transfer_template", l.inventory_portal_use_iframe = "inventory_portal_use_iframe", l.inventory_pos_adjust_v1 = "inventory_pos_adjust_v1", l.inventory_pos_adjust_v2_wastage = "inventory_pos_adjust_v2_wastage", l.inventory_pos_closing_recalculation = "inventory_pos_closing_recalculation", l.inventory_pos_closing_v1 = "inventory_pos_closing_v1", l.inventory_pos_closing_v2 = "inventory_pos_closing_v2", l.inventory_pos_convert_v1 = "inventory_pos_convert_v1", l.inventory_pos_costing = "inventory_pos_costing", l.inventory_pos_stock_return = "inventory_pos_stock_return", l.inventory_pos_transfer_require_fulfillment = "inventory_pos_transfer_require_fulfillment", l.inventory_purchase_order_approval = "inventory_purchase_order_approval", l.inventory_portal_xilnex_transfer_note = "inventory_portal_xilnex_transfer_note", l.inventory_portal_custom_attribute = "inventory_portal_custom_attribute", l.inventory_portal_purchase_order_v2 = "inventory_portal_purchase_order_v2", l.inventory_portal_accept_require_fulfillment = "inventory_portal_accept_require_fulfillment", l.inventory_portal_po_operate_v2 = "inventory_portal_po_operate_v2", l.inventory_pos_allow_receive_order = "inventory_pos_allow_receive_order", l.inventory_xilnex_opening_migration = "inventory_xilnex_opening_migration", l.inventory_ingredient_group = "inventory_ingredient_group", l.inventory_purchase_order_backdate = "inventory_purchase_order_backdate", l.inventory_synergy_opening_migration = "inventory_synergy_opening_migration", l.inventory_netsuite_inventory_transfer_out = "inventory_netsuite_inventory_transfer_out", l.inventory_portal_supplier_preparation_time = "inventory_portal_supplier_preparation_time", l.inventory_backdate_receive = "inventory_backdate_receive", l.inventory_portal_delivery_order_write = "inventory_portal_delivery_order_write", l.inventory_purchase_order_custom_cost = "inventory_purchase_order_custom_cost", l.inventory_bulk_import = "inventory_bulk_import", l.inventory_portal_surcharge = "inventory_portal_surcharge", l.inventory_purchase_order_cost_edit = "inventory_purchase_order_cost_edit", l.inventory_purchase_order_workflow_allow_to_mark_completed = "inventory_purchase_order_workflow_allow_to_mark_completed", l.inventory_recipe_v2 = "inventory_recipe_v2", l.inventory_print_template = "inventory_print_template", l.inventory_purchase_order_email = "inventory_purchase_order_email", l.inventory_bulk_edit_recipes = "inventory_bulk_edit_recipes", l))(b || {});
const Ct = /* @__PURE__ */ new Set([
  // vivo pizza prod
  "business_6687e91fa7240b001ba3f4c2",
  // vivo dev
  "business_669a1d2efc050a001cfbb5a2"
]), xt = /* @__PURE__ */ new Set([
  // zus dev
  "business_671005de24a7f4001c87e25e",
  // zus prod
  "business_6776a1fe205a52001c516efa"
]);
function lt() {
  return {
    isLoaded: !1,
    autoReceiveWarehouse: !1,
    businessSupplierOnly: !1,
    enableBackdatePo: !1,
    enableClosingTemplate: !1,
    enableIngredientGroup: !1,
    enablePoTemplate: !1,
    enableTotalCost: !1,
    enableWastageTemplate: !1,
    manualReceive: !1,
    mustUseDefaultCost: !1,
    mustUsePoTemplate: !1,
    enableXilnexTransferNote: !1,
    enableCustomAttribute: !1,
    usePurchaseOrderV2: !1,
    acceptRequireFulfillment: !1,
    useOperatePurchaseOrderV2: !1,
    inventory_xilnex_opening_migration: !1,
    inventory_synergy_opening_migration: !1,
    inventory_netsuite_inventory_transfer_out: !1,
    inventory_portal_supplier_preparation_time: !1,
    inventory_portal_delivery_order_write: !1,
    inventory_pos_transfer_require_fulfillment: !1,
    inventory_backdate_receive: !1,
    inventory_purchase_order_custom_cost: !1,
    inventory_bulk_import: !1,
    inventory_portal_surcharge: !1,
    inventory_purchase_order_cost_edit: !1,
    inventory_purchase_order_workflow_allow_to_mark_completed: !1,
    inventory_recipe_v2: !1,
    inventory_print_template: !1,
    inventory_purchase_order_email: !1,
    inventory_bulk_edit_recipes: !1,
    report_portal_po_forecast_days_constraint: null,
    report_portal_po_forecast_days_default: 7
  };
}
const h = de(lt()), It = () => ({
  get businessDbName() {
    var _;
    return `business_${((_ = Ke().currentBusiness.value) == null ? void 0 : _._id) ?? ""}`;
  },
  get isWarehouse() {
    var u;
    return ((u = Ve()._currentLocation) == null ? void 0 : u.type) === ot.enum.warehouse;
  },
  get restaurantPosVersion() {
    var _;
    const l = Ve();
    return (_ = Ke().restaurants.value.find(
      (f) => {
        var s;
        return f._id === ((s = l._currentLocation) == null ? void 0 : s.doc._id);
      }
    )) == null ? void 0 : _.posVersion;
  },
  get enableTotalCost() {
    return h.value.enableTotalCost;
  },
  get enableBackdatePo() {
    return h.value.enableBackdatePo;
  },
  /** @deprecated TODO: remove */
  get autoReceiveWarehouse() {
    return h.value.autoReceiveWarehouse;
  },
  /** @deprecated TODO: remove */
  get manualReceive() {
    return h.value.manualReceive;
  },
  get isLoaded() {
    return h.value.isLoaded;
  },
  get enablePoTemplate() {
    return h.value.enablePoTemplate;
  },
  get enableClosingTemplate() {
    return h.value.enableClosingTemplate;
  },
  get enableWastageTemplate() {
    return h.value.enableWastageTemplate;
  },
  get enableIngredientGroup() {
    return h.value.enableIngredientGroup;
  },
  get mustUsePoTemplate() {
    return h.value.mustUsePoTemplate;
  },
  get businessSupplierOnly() {
    return h.value.businessSupplierOnly;
  },
  get enableXilnexTransferNote() {
    return h.value.enableXilnexTransferNote;
  },
  get enabledXilnexOpeningMigration() {
    return h.value.inventory_xilnex_opening_migration;
  },
  get enabledSynergyOpeningMigration() {
    return h.value.inventory_synergy_opening_migration;
  },
  get enableCustomAttribute() {
    return h.value.enableCustomAttribute;
  },
  get usePurchaseOrderV2() {
    return h.value.usePurchaseOrderV2;
  },
  get acceptRequireFulfillment() {
    return h.value.acceptRequireFulfillment;
  },
  get useOperatePurchaseOrderV2() {
    return h.value.useOperatePurchaseOrderV2;
  },
  get isNetSuiteInventoryTransferOutEnabled() {
    return h.value.inventory_netsuite_inventory_transfer_out;
  },
  get enableSupplierPreparationTime() {
    return h.value.inventory_portal_supplier_preparation_time;
  },
  get enablePortalDeliveryOrderWrite() {
    return h.value.inventory_portal_delivery_order_write ?? !0;
  },
  get enablePOSTransferRequireFulfillment() {
    return h.value.inventory_pos_transfer_require_fulfillment;
  },
  get enableBackdateReceive() {
    return h.value.inventory_backdate_receive;
  },
  get enablePurchaseOrderReceiveWithCustomCost() {
    return h.value.inventory_purchase_order_custom_cost;
  },
  get enableBulkImport() {
    return h.value.inventory_bulk_import;
  },
  get enableSurcharge() {
    return h.value.inventory_portal_surcharge;
  },
  get enablePurchaseOrderCostEdit() {
    return h.value.inventory_purchase_order_cost_edit;
  },
  get poWorkflowAllowToMarkCompleted() {
    return h.value.inventory_purchase_order_workflow_allow_to_mark_completed;
  },
  get enableRecipeV2() {
    return h.value.inventory_recipe_v2;
  },
  get enablePrintTemplate() {
    return h.value.inventory_print_template;
  },
  get enablePurchaseOrderEmail() {
    return h.value.inventory_purchase_order_email;
  },
  get enableBulkEditRecipes() {
    return h.value.inventory_bulk_edit_recipes;
  },
  get poForecastDaysConstraint() {
    return h.value.report_portal_po_forecast_days_constraint;
  },
  get poForecastDaysDefault() {
    return h.value.report_portal_po_forecast_days_default;
  },
  async init() {
    const l = Ke(), { init: u, setBusiness: _ } = he(), f = gt(), s = l.namespace.value === "prod";
    await u({
      apiKey: s ? "6GhcttsJ9Rj9cTevcdrpin" : "MaGoXrEWuEJNpWgKTqseee"
      // url: 'https://flag.feedme.farm/api/v1/', // optional -> this is a default URL value
      // enableAnalytics: true, // optional, defaults to true
      // cacheFlags: true // optional, defaults to true
    }), Ve().watchLocation(async (K) => {
      var A, $, Y;
      if (!K) {
        h.value = lt();
        return;
      }
      const I = ((A = l.currentBusiness.value) == null ? void 0 : A._id) ?? "";
      await _(I);
      const W = `business_${I}`, w = K.type === ot.enum.warehouse, g = (
        // if menu v4, must manual receive && must use outlet app
        (($ = l.currentBusiness.value) == null ? void 0 : $.menuVersion) === "v4" && // more guard for businesses using menu v4, only those listed for manual receive will be included
        // TODO: may be removed to use menu version only
        Ct.has(this.businessDbName)
      ), C = xt.has(W) || S(b.inventory_portal_must_use_transfer_template), E = S(b.inventory_purchase_order_backdate) && (this.isWarehouse || f.state.closing !== null);
      h.value = {
        isLoaded: !0,
        enableTotalCost: ((Y = l.currentBusiness.value) == null ? void 0 : Y.menuVersion) === "v4",
        enableBackdatePo: E,
        autoReceiveWarehouse: w && !g,
        manualReceive: g,
        enablePoTemplate: C,
        enableClosingTemplate: S(b.inventory_pos_closing_v2),
        enableWastageTemplate: S(b.inventory_pos_adjust_v2_wastage),
        enableIngredientGroup: S(b.inventory_ingredient_group),
        mustUsePoTemplate: C,
        businessSupplierOnly: C,
        enableXilnexTransferNote: S(b.inventory_portal_xilnex_transfer_note),
        enableCustomAttribute: S(b.inventory_portal_custom_attribute),
        usePurchaseOrderV2: S(b.inventory_portal_purchase_order_v2),
        acceptRequireFulfillment: S(
          b.inventory_portal_accept_require_fulfillment
        ),
        useOperatePurchaseOrderV2: S(b.inventory_portal_po_operate_v2),
        inventory_xilnex_opening_migration: S(
          b.inventory_xilnex_opening_migration
        ),
        inventory_synergy_opening_migration: S(
          b.inventory_synergy_opening_migration
        ),
        inventory_netsuite_inventory_transfer_out: S(
          b.inventory_netsuite_inventory_transfer_out
        ),
        inventory_portal_supplier_preparation_time: S(
          b.inventory_portal_supplier_preparation_time
        ),
        inventory_portal_delivery_order_write: S(
          b.inventory_portal_delivery_order_write
        ),
        inventory_pos_transfer_require_fulfillment: S(
          b.inventory_pos_transfer_require_fulfillment
        ),
        inventory_backdate_receive: S(b.inventory_backdate_receive),
        inventory_purchase_order_custom_cost: S(
          b.inventory_purchase_order_custom_cost
        ),
        inventory_bulk_import: S(b.inventory_bulk_import),
        inventory_portal_surcharge: S(b.inventory_portal_surcharge),
        inventory_purchase_order_cost_edit: S(
          b.inventory_purchase_order_cost_edit
        ),
        inventory_purchase_order_workflow_allow_to_mark_completed: S(
          b.inventory_purchase_order_workflow_allow_to_mark_completed
        ),
        inventory_recipe_v2: S(b.inventory_recipe_v2),
        inventory_print_template: S(b.inventory_print_template),
        inventory_purchase_order_email: S(b.inventory_purchase_order_email),
        inventory_bulk_edit_recipes: S(b.inventory_bulk_edit_recipes),
        report_portal_po_forecast_days_constraint: Et(
          "report_portal_po_forecast_days_constraint"
        ),
        report_portal_po_forecast_days_default: wt(
          "report_portal_po_forecast_days_default",
          7
        )
      };
    }, "feature");
  },
  async awaitFeatureLoaded(l) {
    return new Promise((u) => {
      const _ = () => {
        h.value.isLoaded ? u(l()) : setTimeout(_, 100);
      };
      _();
    });
  }
});
function S(l, u) {
  u = u === void 0 ? null : u;
  const { getFlagValue: _ } = he();
  return _(l, (f) => f === "true") ?? u;
}
function Et(l) {
  const { getFlagValue: u } = he();
  return u(l, (f) => f.trim() ? f.trim() : null) ?? null;
}
function wt(l, u) {
  const { getFlagValue: _ } = he();
  return _(l, (s) => {
    const O = parseInt(s, 10);
    return isNaN(O) ? null : O;
  }) ?? u;
}
export {
  b as I,
  he as a,
  It as u
};
