import { defineComponent as O, resolveComponent as b, createBlock as I, openBlock as c, unref as r, isRef as X, withCtx as S, createElementVNode as D, createVNode as k, toDisplayString as E, createTextVNode as Y, onMounted as T, watch as f, ref as j, computed as N, onBeforeMount as Z, onBeforeUnmount as M, createElementBlock as w, Fragment as ee } from "vue";
import { detectLocale as p, useCoreStore as y } from "@feedmepos/mf-common";
import { u as te, d as C, a as oe, b as re, c as ae, e as ne, f as se, g as le } from "./vue-i18n-DG0DIzwC.js";
import { storeToRefs as $ } from "pinia";
import { u as ue, a as ie, b as ce } from "./BaseDialog.vue_vue_type_script_setup_true_lang-BqtS2XG4.js";
import { _ as me, u as de } from "./NavigationTab.vue_vue_type_script_setup_true_lang-EbtoF2G2.js";
import { u as U } from "./message-dialog-UoMWOnil.js";
const ve = { class: "fm-typo-en-body-md-400 text-ellipsis overflow-hidden" }, fe = /* @__PURE__ */ O({
  __name: "Dialog",
  setup(m) {
    const { t } = te(), a = U(), { isOpened: n, message: u, title: i } = $(U());
    return (d, l) => {
      const v = b("FmButton"), g = b("FmDialog");
      return c(), I(g, {
        modelValue: r(n),
        "onUpdate:modelValue": l[0] || (l[0] = (h) => X(n) ? n.value = h : null),
        overlay: "",
        "close-button": !1
      }, {
        "dialog-header": S(() => [
          Y(E(r(i)), 1)
        ]),
        default: S(() => [
          D("p", ve, E(r(u)), 1)
        ]),
        "dialog-footer": S(() => [
          l[1] || (l[1] = D("div", { class: "grow" }, null, -1)),
          k(v, {
            label: r(t)("report.common.cancel"),
            variant: "tertiary",
            onClick: r(a).dismiss
          }, null, 8, ["label", "onClick"]),
          k(v, {
            label: r(t)("report.common.confirm"),
            onClick: r(a).confirm
          }, null, 8, ["label", "onClick"])
        ]),
        _: 1
      }, 8, ["modelValue"]);
    };
  }
}), x = j(p());
function pe() {
  const m = (t) => {
    switch (x.value = t, t) {
      case "zh-CN":
        C.locale("zh-cn");
        break;
      default:
        C.locale("en");
        break;
    }
  };
  return T(() => {
    m(p());
  }), f(() => p(), m, { deep: !0, immediate: !0 }), {
    currentLocale: x
  };
}
C.locale(p() === "zh-CN" ? "zh-cn" : "en");
const ge = ["src"], he = ["src"], $e = /* @__PURE__ */ O({
  __name: "App",
  setup(m) {
    const { businessId: t, token: a, country: n } = $(oe()), { sessionUser: u, currentBusiness: i, currentCountry: d, registerSidebarComponent: l } = y(), { getRestaurantAndWarehouse: v, getBusinessSetting: g } = re(), { getFeatureFlags: h } = ae(), { version: s } = $(ue()), { getSettings: z } = ne(), { promptLoader: A } = se(), J = N(() => `https://portal-v1.feedme.cc/b/${t.value}/report/CLOSE_UP?showHeader=false&country=${n.value.toUpperCase()}&menuOption=business-report&token=${a.value}&v2=true&reportV5Button=true`), G = N(() => `https://report-v4.feedme.cc?businessId=${t.value}&country=${n.value}&token=${a.value}&reportV3Button=true`);
    f(
      [() => i.value, () => u.value, () => d.value],
      () => {
        var o, e;
        i.value && u.value && d.value && (t.value = ((o = i.value) == null ? void 0 : o.id) ?? "", a.value = ((e = u.value) == null ? void 0 : e.token) ?? "", n.value = d.value ?? "");
      },
      { immediate: !0 }
    );
    function F(o) {
      if (typeof o.data == "string")
        try {
          const e = JSON.parse(o.data);
          (e == null ? void 0 : e.token) !== "" && (e == null ? void 0 : e.token) !== void 0 && (a.value = e.token);
        } catch (e) {
          console.error(e);
        }
    }
    function B(o) {
      if (typeof o.data == "string")
        try {
          const e = JSON.parse(o.data);
          (e == null ? void 0 : e.v5) === !0 ? s.value = _.value : (e == null ? void 0 : e.v3) === !0 && (s.value = "v3");
        } catch (e) {
          console.error(e);
        }
    }
    f(s, () => {
      ["v3", "v4"].includes(s.value) ? y().hideSidebarToggle(!0) : y().hideSidebarToggle(!1);
    }), Z(() => {
      l(me);
    }), T(() => {
      console.log("5.14.0", !0), window.addEventListener("message", F), window.addEventListener("message", B);
    });
    const L = ie(), R = de();
    M(() => {
      window.removeEventListener("message", F), window.removeEventListener("message", B), L.$dispose(), R.$dispose();
    });
    const { getReports: P, getOverviewReport: H, getReportConfig: V } = L, { getSchema: K } = ce(), { fetchSchedules: Q } = R, { init: W } = le(), _ = j("v5");
    return f(
      () => t.value,
      () => {
        t.value !== "" && A(async () => {
          await W({
            apiKey: "6GhcttsJ9Rj9cTevcdrpin",
            url: "https://flag.feedme.farm/api/v1/",
            enableAnalytics: !1,
            cacheFlags: !1
          });
          const o = await V();
          _.value = o.version, s.value = _.value, await Promise.all([
            h(),
            V(),
            H(),
            P(),
            K(),
            Q(),
            g(),
            v(),
            z()
          ]);
        });
      },
      {
        immediate: !0
      }
    ), pe(), (o, e) => {
      const q = b("router-view");
      return c(), w(ee, null, [
        k(fe),
        r(s) === "v3" ? (c(), w("iframe", {
          key: 0,
          class: "bg-white h-full w-full",
          src: J.value
        }, null, 8, ge)) : r(s) === "v4" ? (c(), w("iframe", {
          key: 1,
          class: "bg-white h-full w-full",
          src: G.value
        }, null, 8, he)) : (c(), I(q, { key: 2 }))
      ], 64);
    };
  }
});
export {
  $e as default
};
