import { ref as k, onUnmounted as H, computed as y, defineComponent as P, watch as N, onMounted as $, resolveComponent as w, openBlock as m, createElementBlock as g, unref as x, createVNode as _, createElementVNode as o, toDisplayString as b, createBlock as L, createCommentVNode as U, withCtx as R, withDirectives as O, vModelText as j, Fragment as q, renderList as z, createTextVNode as B } from "vue";
import { _ as K } from "./empty-placeholder-B0QU467o.js";
import { u as Q, a as J, R as S, b as W } from "./app-D3gm3Lsw.js";
import { useCoreStore as C, useI18n as X } from "@feedmepos/mf-common";
import { useRouter as T, useRoute as Y } from "vue-router";
import { u as Z, a as ee, I as te } from "./feature-WVA_2Jx-.js";
import { u as oe } from "./netsuite-DmXOUJo-.js";
import { u as D } from "./useNavigationMenu-Bz5AabkY.js";
import { u as ne } from "./useTabStorage-BkIVScW_.js";
import { F as se } from "./FmAdminBadge-DjnBAgyv.js";
import { u as re } from "./googlemap-BGi_aKUA.js";
function ae() {
  return {
    loadingHookInstalled: !1,
    isLoading: !1
  };
}
const F = k(ae());
function le() {
  const p = T();
  if (!F.value.loadingHookInstalled) {
    F.value.loadingHookInstalled = !0;
    const t = p.beforeEach(() => {
      F.value.isLoading = !0;
    }), c = p.afterEach(() => {
      F.value.isLoading = !1;
    });
    H(() => {
      F.value.loadingHookInstalled = !1, t(), c();
    });
  }
  return {
    get isLoading() {
      return F.value.isLoading;
    }
  };
}
function ie() {
  const { firstAccessibleRouteName: p } = D();
  return { hasAnyAccessibleInventoryRoute: y(() => p.value !== null) };
}
const ue = {
  key: 0,
  class: "flex flex-col items-center w-full h-full gap-24"
}, ce = {
  key: 1,
  class: "flex flex-col pt-[200px] gap-32 items-center"
}, de = { class: "flex flex-col gap-12 items-center text-center px-24 max-w-[600px]" }, me = { class: "fm-typo-en-title-lg-600" }, pe = { class: "text-fm-color-typo-secondary fm-typo-en-body-md-400" }, fe = {
  key: 2,
  class: "flex flex-col pt-[200px] gap-32 items-center"
}, ve = { class: "flex flex-col gap-12 items-center text-center px-24 max-w-[1000px]" }, ge = { class: "fm-typo-en-title-lg-600" }, _e = { class: "text-fm-color-typo-secondary fm-typo-en-body-md-400" }, ye = { class: "flex gap-16" }, xe = { href: "https://feedme.ai/product/inventory/features?tab=plans_%26_prices" }, be = { href: "https://feedme.ai/form" }, he = /* @__PURE__ */ P({
  __name: "InventoryView",
  setup(p) {
    const t = Q(), c = J(), i = oe(), r = C(), d = T(), a = le(), e = Z(), { t: l } = X(), { hasAnyAccessibleInventoryRoute: f } = ie();
    N(
      [() => r.sessionUser.value, () => r.currentBusiness.value],
      ([v, u]) => {
        n(v, u);
      }
    ), $(async () => {
      await e.init(), await r.readBusinesses();
      const v = r.sessionUser.value, u = r.currentBusiness.value;
      n(v, u);
    });
    function n(v, u) {
      !v || !u || s();
    }
    async function s() {
      return await t.init(), await i.readSetting().catch((v) => {
        console.error("[all] error on reading netsuite store", v);
      }), await c.init();
    }
    const A = y(() => d.currentRoute.value.name === S.TRANSFER_TEMPLATE ? e.enablePoTemplate : d.currentRoute.value.name === S.INGREDIENT_GROUP ? e.enableIngredientGroup : !0), E = y(
      () => d.currentRoute.value.matched.some((v) => {
        var I;
        const u = v.meta, h = u == null ? void 0 : u.validationManifest;
        return (((I = h == null ? void 0 : h.requiredCaslPermissions) == null ? void 0 : I.length) ?? 0) > 0;
      })
    ), G = y(() => {
      if (!r.sessionUser.value) return !1;
      if (t._locations !== null && t.locations.length === 0) return !0;
      if (!e.isLoaded) return !1;
      const h = d.currentRoute.value.name === S.LOADING;
      return !f.value && (h || E.value);
    });
    return (v, u) => {
      const h = w("FmSpacer"), I = w("FmCircularProgress"), V = w("FmButton"), M = w("RouterView");
      return m(), g("div", null, [
        x(a).isLoading ? (m(), g("div", ue, [
          _(h),
          o("div", null, [
            _(I, { size: "xl" })
          ]),
          u[0] || (u[0] = o("div", { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary pl-8" }, "Loading page...", -1)),
          _(h)
        ])) : G.value ? (m(), g("div", ce, [
          u[1] || (u[1] = o("img", {
            src: K,
            alt: "No permission",
            class: "w-[200px] h-[200px]"
          }, null, -1)),
          o("div", de, [
            o("div", me, b(x(l)("inventory.common.noPermission.title")), 1),
            o("div", pe, b(x(l)("inventory.common.noPermission.description")), 1)
          ])
        ])) : A.value ? x(r).sessionUser.value ? (m(), L(M, { key: 3 })) : U("", !0) : (m(), g("div", fe, [
          o("div", ve, [
            o("div", ge, b(x(l)("inventory.common.proPlan.title")), 1),
            o("div", _e, b(x(l)("inventory.common.proPlan.subtitle")), 1)
          ]),
          o("div", ye, [
            o("a", xe, [
              _(V, {
                label: x(l)("inventory.common.proPlan.comparePlans"),
                variant: "secondary"
              }, null, 8, ["label"])
            ]),
            o("a", be, [
              _(V, {
                label: x(l)("inventory.common.proPlan.callUs"),
                "prepend-icon": "call"
              }, null, 8, ["label"])
            ])
          ])
        ]))
      ]);
    };
  }
}), we = { class: "flex items-center gap-2" }, Se = { class: "text-xs text-gray-400 font-normal" }, Fe = { class: "flex flex-col gap-3" }, Re = { class: "max-h-[480px] flex flex-col gap-1" }, Ie = { class: "font-mono text-xs text-gray-700 break-all min-w-0" }, ke = {
  key: 0,
  class: "inline-flex items-center gap-1 text-xs font-medium text-green-700 bg-green-50 px-2 py-0.5 rounded-full"
}, Ne = {
  key: 1,
  class: "inline-flex items-center gap-1 text-xs font-medium text-red-700 bg-red-50 px-2 py-0.5 rounded-full"
}, Pe = {
  key: 2,
  class: "inline-flex items-center gap-1 text-xs font-medium text-gray-500 bg-gray-100 px-2 py-0.5 rounded-full"
}, Ae = {
  key: 0,
  class: "text-center text-sm text-gray-400 py-4"
}, Ee = /* @__PURE__ */ P({
  __name: "FmFeatureFlagDialog",
  setup(p) {
    const t = k(!1), c = k(""), i = y(() => {
      const { getFlagValue: a } = ee();
      return Object.values(te).map((e) => {
        const l = a(e, (f) => f === "true");
        return {
          name: e,
          enabled: l
        };
      });
    }), r = y(() => {
      const a = c.value.toLowerCase();
      return a ? i.value.filter((e) => e.name.toLowerCase().includes(a)) : i.value;
    }), d = y(() => {
      const a = i.value.filter((f) => f.enabled === !0).length, e = i.value.filter((f) => f.enabled === !1).length, l = i.value.filter((f) => f.enabled === null).length;
      return { enabled: a, disabled: e, unknown: l, total: i.value.length };
    });
    return (a, e) => {
      const l = w("FmButton"), f = w("FmSpacer"), n = w("FmDialog");
      return m(), L(n, {
        modelValue: t.value,
        "onUpdate:modelValue": e[2] || (e[2] = (s) => t.value = s),
        overlay: !0
      }, {
        "dialog-button": R(() => [
          _(se, null, {
            default: R(() => [
              _(l, {
                variant: "secondary",
                label: "Feature flags"
              })
            ]),
            _: 1
          })
        ]),
        "dialog-header": R(() => [
          o("div", we, [
            e[3] || (e[3] = o("span", null, "Feature Flags", -1)),
            o("span", Se, b(d.value.enabled) + " enabled · " + b(d.value.disabled) + " disabled · " + b(d.value.unknown) + " unknown ", 1)
          ])
        ]),
        "dialog-footer": R(() => [
          _(f, { class: "sm:hidden xs:hidden" }),
          _(l, {
            class: "sm:w-full xs:w-full",
            label: "Close",
            size: "md",
            variant: "primary",
            onClick: e[1] || (e[1] = (s) => t.value = !1)
          })
        ]),
        default: R(() => [
          o("div", Fe, [
            O(o("input", {
              "onUpdate:modelValue": e[0] || (e[0] = (s) => c.value = s),
              type: "text",
              placeholder: "Search flags...",
              class: "w-full px-3 py-2 text-sm border border-gray-300 rounded-md focus:outline-none focus:ring-1 focus:ring-blue-500"
            }, null, 512), [
              [j, c.value]
            ]),
            o("div", Re, [
              (m(!0), g(q, null, z(r.value, (s) => (m(), g("div", {
                key: s.name,
                class: "flex items-start justify-between gap-2 px-3 py-2 rounded-md hover:bg-gray-50 text-sm"
              }, [
                o("span", Ie, b(s.name), 1),
                s.enabled === !0 ? (m(), g("span", ke, e[4] || (e[4] = [
                  o("span", { class: "w-1.5 h-1.5 rounded-full bg-green-500" }, null, -1),
                  B(" Enabled ")
                ]))) : s.enabled === !1 ? (m(), g("span", Ne, e[5] || (e[5] = [
                  o("span", { class: "w-1.5 h-1.5 rounded-full bg-red-500" }, null, -1),
                  B(" Disabled ")
                ]))) : (m(), g("span", Pe, e[6] || (e[6] = [
                  o("span", { class: "w-1.5 h-1.5 rounded-full bg-gray-400" }, null, -1),
                  B(" Unknown ")
                ])))
              ]))), 128)),
              r.value.length === 0 ? (m(), g("div", Ae, ' No flags matching "' + b(c.value) + '" ', 1)) : U("", !0)
            ])
          ])
        ]),
        _: 1
      }, 8, ["modelValue"]);
    };
  }
}), Be = { class: "h-full flex flex-col overflow-auto py-16 gap-2" }, Le = /* @__PURE__ */ P({
  __name: "NavigationTab",
  setup(p) {
    const t = Y(), c = T(), i = C(), r = ne(), { menuItems: d } = D();
    N([() => i.currentBusiness.value, () => t.name], ([n, s]) => {
      (n == null ? void 0 : n.menuVersion) === "v3" && (s === S.INGREDIENTS || s === S.RECIPE || s === S.UNIT) && c.push({ name: S.STOCK });
    });
    const a = y({
      get() {
        if (t.name)
          return String(t.name);
      },
      set(n) {
        n && c.push({ name: n });
      }
    }), e = y(
      () => {
        var n;
        return `NavigationTab.${(n = i.currentBusiness.value) == null ? void 0 : n._id}`;
      }
    ), l = k(!1), f = y({
      get() {
        return l.value;
      },
      set(n) {
        l.value = n, n || r.setItem(e.value, "true");
      }
    });
    return N([() => e.value], () => {
      l.value = !1, setTimeout(() => {
        f.value = !r.getItem(e.value);
      }, 2e3);
    }), (n, s) => {
      const A = w("FmCollapsibleTabs");
      return m(), g("div", Be, [
        _(Ee),
        _(A, {
          modelValue: a.value,
          "onUpdate:modelValue": s[0] || (s[0] = (E) => a.value = E),
          items: x(d)
        }, null, 8, ["modelValue", "items"])
      ]);
    };
  }
});
typeof Promise.withResolvers > "u" && (Promise.withResolvers = () => {
  let p, t;
  return { promise: new Promise((i, r) => {
    p = i, t = r;
  }), resolve: p, reject: t };
});
typeof Promise.prototype.delayed > "u" && (Promise.prototype.delayed = async function(p) {
  return await new Promise((t) => setTimeout(t, p)), Promise.resolve(this);
});
const qe = /* @__PURE__ */ P({
  __name: "App",
  setup(p) {
    const t = C(), c = re(), i = W();
    $(() => {
      if (window.location.href.includes("print-preview")) {
        t.setEmbedded(!0), document.body.classList.add("print-mode");
        return;
      }
      t.registerSidebarComponent(Le), c.initGoogleMap(i.appApi.googleMap).catch(() => {
        console.error("Google map cannot be loaded");
      });
    }), N([() => t.currentCountry.value], () => {
      r();
    });
    async function r() {
      var d;
      try {
        await t.readBusinesses(), t.currentBusiness.value = (d = t.businesses.value) == null ? void 0 : d.find((a) => a);
      } catch (a) {
        console.error("error when trying to reset businesses:", a);
      }
    }
    return (d, a) => (m(), L(he));
  }
});
export {
  qe as default
};
