import { ref as k, onUnmounted as H, computed as y, defineComponent as N, watch as P, onMounted as $, resolveComponent as h, openBlock as m, createElementBlock as g, unref as x, createVNode as _, createElementVNode as n, toDisplayString as b, createBlock as C, createCommentVNode as U, withCtx as R, withDirectives as O, vModelText as j, Fragment as q, renderList as z, createTextVNode as A } from "vue";
import { _ as K } from "./empty-placeholder-B0QU467o.js";
import { u as Q, a as J, R as w, b as W } from "./app-Bpb4394e.js";
import { useCoreStore as T, useI18n as X } from "@feedmepos/mf-common";
import { useRouter as V, useRoute as Y } from "vue-router";
import { u as Z, a as ee, I as te } from "./feature-Cz6F0_cm.js";
import { u as ne } from "./netsuite-BGUUAOqe.js";
import { u as D } from "./useNavigationMenu-C1H2mTfQ.js";
import { u as oe } 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 = V();
  if (!F.value.loadingHookInstalled) {
    F.value.loadingHookInstalled = !0;
    const t = p.beforeEach(() => {
      F.value.isLoading = !0;
    }), u = p.afterEach(() => {
      F.value.isLoading = !1;
    });
    H(() => {
      F.value.loadingHookInstalled = !1, t(), u();
    });
  }
  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__ */ N({
  __name: "InventoryView",
  setup(p) {
    const t = Q(), u = J(), i = ne(), r = T(), c = V(), a = le(), e = Z(), { t: l } = X(), { hasAnyAccessibleInventoryRoute: f } = ie();
    P(
      [() => r.sessionUser.value, () => r.currentBusiness.value],
      ([v, d]) => {
        o(v, d);
      }
    ), $(async () => {
      await e.init(), await r.readBusinesses();
      const v = r.sessionUser.value, d = r.currentBusiness.value;
      o(v, d);
    });
    function o(v, d) {
      !v || !d || s();
    }
    async function s() {
      return await t.init(), await i.readSetting().catch((v) => {
        console.error("[all] error on reading netsuite store", v);
      }), await u.init();
    }
    const E = y(() => c.currentRoute.value.name === w.TRANSFER_TEMPLATE ? e.enablePoTemplate : c.currentRoute.value.name === w.INGREDIENT_GROUP ? e.enableIngredientGroup : !0), B = y(
      () => c.currentRoute.value.matched.some((v) => {
        var I;
        const d = v.meta, S = d == null ? void 0 : d.validationManifest;
        return (((I = S == null ? void 0 : S.requiredCaslPermissions) == null ? void 0 : I.length) ?? 0) > 0;
      })
    ), G = y(() => {
      if (!r.sessionUser.value || !e.isLoaded) return !1;
      const v = c.currentRoute.value.name === w.LOADING;
      return !f.value && (v || B.value);
    });
    return (v, d) => {
      const S = h("FmSpacer"), I = h("FmCircularProgress"), L = h("FmButton"), M = h("RouterView");
      return m(), g("div", null, [
        x(a).isLoading ? (m(), g("div", ue, [
          _(S),
          n("div", null, [
            _(I, { size: "xl" })
          ]),
          d[0] || (d[0] = n("div", { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary pl-8" }, "Loading page...", -1)),
          _(S)
        ])) : G.value ? (m(), g("div", ce, [
          d[1] || (d[1] = n("img", {
            src: K,
            alt: "No permission",
            class: "w-[200px] h-[200px]"
          }, null, -1)),
          n("div", de, [
            n("div", me, b(x(l)("inventory.common.noPermission.title")), 1),
            n("div", pe, b(x(l)("inventory.common.noPermission.description")), 1)
          ])
        ])) : E.value ? x(r).sessionUser.value ? (m(), C(M, { key: 3 })) : U("", !0) : (m(), g("div", fe, [
          n("div", ve, [
            n("div", ge, b(x(l)("inventory.common.proPlan.title")), 1),
            n("div", _e, b(x(l)("inventory.common.proPlan.subtitle")), 1)
          ]),
          n("div", ye, [
            n("a", xe, [
              _(L, {
                label: x(l)("inventory.common.proPlan.comparePlans"),
                variant: "secondary"
              }, null, 8, ["label"])
            ]),
            n("a", be, [
              _(L, {
                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"
}, Pe = {
  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"
}, Ne = {
  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"
}, Ee = {
  key: 0,
  class: "text-center text-sm text-gray-400 py-4"
}, Be = /* @__PURE__ */ N({
  __name: "FmFeatureFlagDialog",
  setup(p) {
    const t = k(!1), u = 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 = u.value.toLowerCase();
      return a ? i.value.filter((e) => e.name.toLowerCase().includes(a)) : i.value;
    }), c = 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 = h("FmButton"), f = h("FmSpacer"), o = h("FmDialog");
      return m(), C(o, {
        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(() => [
          n("div", we, [
            e[3] || (e[3] = n("span", null, "Feature Flags", -1)),
            n("span", Se, b(c.value.enabled) + " enabled · " + b(c.value.disabled) + " disabled · " + b(c.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(() => [
          n("div", Fe, [
            O(n("input", {
              "onUpdate:modelValue": e[0] || (e[0] = (s) => u.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, u.value]
            ]),
            n("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"
              }, [
                n("span", Ie, b(s.name), 1),
                s.enabled === !0 ? (m(), g("span", ke, e[4] || (e[4] = [
                  n("span", { class: "w-1.5 h-1.5 rounded-full bg-green-500" }, null, -1),
                  A(" Enabled ")
                ]))) : s.enabled === !1 ? (m(), g("span", Pe, e[5] || (e[5] = [
                  n("span", { class: "w-1.5 h-1.5 rounded-full bg-red-500" }, null, -1),
                  A(" Disabled ")
                ]))) : (m(), g("span", Ne, e[6] || (e[6] = [
                  n("span", { class: "w-1.5 h-1.5 rounded-full bg-gray-400" }, null, -1),
                  A(" Unknown ")
                ])))
              ]))), 128)),
              r.value.length === 0 ? (m(), g("div", Ee, ' No flags matching "' + b(u.value) + '" ', 1)) : U("", !0)
            ])
          ])
        ]),
        _: 1
      }, 8, ["modelValue"]);
    };
  }
}), Ae = { class: "h-full flex flex-col overflow-auto py-16 gap-2" }, Ce = /* @__PURE__ */ N({
  __name: "NavigationTab",
  setup(p) {
    const t = Y(), u = V(), i = T(), r = oe(), { menuItems: c } = D();
    P([() => i.currentBusiness.value, () => t.name], ([o, s]) => {
      (o == null ? void 0 : o.menuVersion) === "v3" && (s === w.INGREDIENTS || s === w.RECIPE || s === w.UNIT) && u.push({ name: w.STOCK });
    });
    const a = y({
      get() {
        if (t.name)
          return String(t.name);
      },
      set(o) {
        o && u.push({ name: o });
      }
    }), e = y(
      () => {
        var o;
        return `NavigationTab.${(o = i.currentBusiness.value) == null ? void 0 : o._id}`;
      }
    ), l = k(!1), f = y({
      get() {
        return l.value;
      },
      set(o) {
        l.value = o, o || r.setItem(e.value, "true");
      }
    });
    return P([() => e.value], () => {
      l.value = !1, setTimeout(() => {
        f.value = !r.getItem(e.value);
      }, 2e3);
    }), (o, s) => {
      const E = h("FmCollapsibleTabs");
      return m(), g("div", Ae, [
        _(Be),
        _(E, {
          modelValue: a.value,
          "onUpdate:modelValue": s[0] || (s[0] = (B) => a.value = B),
          items: x(c)
        }, 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__ */ N({
  __name: "App",
  setup(p) {
    const t = T(), u = re(), i = W();
    $(() => {
      if (window.location.href.includes("print-preview")) {
        t.setEmbedded(!0), document.body.classList.add("print-mode");
        return;
      }
      t.registerSidebarComponent(Ce), u.initGoogleMap(i.appApi.googleMap).catch(() => {
        console.error("Google map cannot be loaded");
      });
    }), P([() => t.currentCountry.value], () => {
      r();
    });
    async function r() {
      var c;
      try {
        await t.readBusinesses(), t.currentBusiness.value = (c = t.businesses.value) == null ? void 0 : c.find((a) => a);
      } catch (a) {
        console.error("error when trying to reset businesses:", a);
      }
    }
    return (c, a) => (m(), C(he));
  }
});
export {
  qe as default
};
