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