import '@das-fed/web/packages/micro-frontend/style.css';
import { ref as w, watch as M, reactive as P, getCurrentScope as ue, onScopeDispose as de, getCurrentInstance as pe, onMounted as me, nextTick as ne, unref as I, defineComponent as x, computed as N, createElementBlock as D, openBlock as E, Fragment as $, renderList as fe, withDirectives as ve, createCommentVNode as he, createBlock as se, vShow as Ae, mergeProps as we, withCtx as T, createVNode as C, renderSlot as V, onActivated as ge } from "vue";
import { DasWebLayout as ye, DasWebTabs as Me, DasWebMenu as Le, DasWebNav as _e } from "@das-fed/web/packages/layout/index";
const z = w("/das-micro-app"), f = w([]), k = w(!1), O = w([]), F = w(!0);
let v = null, h = null, _ = null;
const be = (e) => new Promise((t) => {
  const n = () => {
    if (v != null && v[e]) return t();
    setTimeout(() => n(), 50);
  };
  n();
}), b = (e, t, n, s) => {
  var i;
  const { awaitListener: c = !1 } = s || {}, { origin: a } = new URL(location.href);
  c ? be(t).then(() => {
    var r;
    (r = window.self) == null || r.postMessage({ type: t, data: n }, a);
  }) : (i = window.self) == null || i.postMessage({ type: t, data: n }, a);
}, Ie = (e) => new Promise((t) => {
  const n = () => {
    if (h != null && h[e]) return t();
    setTimeout(() => n(), 50);
  };
  n();
}), q = (e, t, n) => {
  var a;
  const { awaitListener: s = !1 } = n || {}, { origin: c } = new URL(location.href);
  s ? Ie(e).then(() => {
    var i;
    (i = window.self) == null || i.postMessage({ type: e, data: t }, c);
  }) : (a = window.self) == null || a.postMessage({ type: e, data: t }, c);
}, Ee = () => {
  h || (h || (h = {}), window.addEventListener(
    "message",
    (e) => {
      const { type: t, source: n } = e.data || {};
      if (n !== "react-devtools-content-script" && h[t])
        for (const s in h[t])
          h[t][s](e.data);
    },
    !1
  ));
}, Se = () => {
  v || (v || (v = {}), window.addEventListener(
    "message",
    (e) => {
      const { type: t } = e.data || {};
      if (v[t])
        for (const n in v[t])
          v[t][n](e.data);
    },
    !1
  ));
}, Pe = (e, t) => {
  Se();
  const n = (/* @__PURE__ */ new Date()).getTime() + Math.random().toString(36).slice(-8);
  return v[e] || (v[e] = {}), v[e][n] = t, {
    remove: () => {
      v[e] && v[e][n] && delete v[e][n];
    }
  };
}, Te = (e, t) => {
  Ee();
  const n = (/* @__PURE__ */ new Date()).getTime() + Math.random().toString(36).slice(-8);
  return h[e] || (h[e] = {}), h[e][n] = t, {
    remove: () => {
      h[e] && h[e][n] && delete h[e][n];
    }
  };
}, Q = async (e) => {
  await Promise.all(
    f.value.filter((t) => t.loaded).map((t) => new Promise(async (n) => {
      t.dom || await new Promise((s) => M(() => t.dom, s)), setTimeout(() => {
        b(t.name, "sessionStorage", e), n(!0);
      }, 0);
    }))
  );
}, d = {
  loadMicroApp: (e) => {
    k.value = !0;
    const t = f.value.find((i) => i.name === e), n = f.value.find((i) => i.actived), s = !!t, c = !(t != null && t.loaded), a = t == null ? void 0 : t.actived;
    if (!s) {
      n && (n.actived = !1);
      return;
    }
    if (t.isFirstActived = !0, c) {
      t.src = t.entry;
      const i = f.value.find((r) => r.actived);
      i && (i.actived = !1), t.loaded = !0, t.actived = !0;
      return;
    }
    if (!a) {
      n && (n.actived = !1), t.actived = !0;
      return;
    }
  },
  hideMicroApp: async (e) => {
    const t = f.value.find((n) => n.name === e);
    t && t.loaded && (t.dom || await new Promise((n) => M(() => t.dom, n)), b(e, "router", {
      cmd: "push",
      route: {
        name: "das-micro-app-ghost",
        microAppName: e
      }
    }));
  },
  hideAllMicroApp: () => {
    k.value = !1, f.value.map((e) => {
      e.actived = !1;
    });
  },
  unloadMicroApp: (e) => {
    const t = f.value.find((n) => n.name === e);
    t && (t.loaded = !1, t.actived = !1, t.dom = void 0);
  },
  unloadAllMicroApp: () => {
    k.value = !1, f.value.map((e) => {
      e.loaded = !1, e.actived = !1, e.dom = void 0;
    });
  },
  setMicroAppRoute: async (e, t, n) => {
    const s = f.value.find((r) => r.name === t);
    if (!s || !s.loaded || !s.actived || (s.dom || await new Promise((r) => M(() => s.dom, r)), !s.actived)) return s;
    const c = n.path || n, a = n.query || {}, i = n.params || {};
    return e.push({
      path: `/${t}${c}`,
      query: a,
      // @ts-ignore
      params: i
    }), setTimeout(() => {
      const { isFirstActived: r } = s;
      b(t, "router", {
        cmd: r ? "replace" : "push",
        route: n,
        microAppName: t
      }), r && (s.isFirstActived = !1);
    }, 0), s;
  },
  sendMessageToMicroApp: b,
  sendMessageToMainApp: q,
  addEventListenerFromMainApp: Pe,
  addEventListenerFromMicroApp: Te,
  setMainAppOverlay: (e, t) => {
    q("bodyOverlay", { visible: e, style: t });
  },
  sessionStorage: {
    key: window.sessionStorage.key,
    getItem: window.sessionStorage.getItem,
    setItem: (e, t) => {
      window.sessionStorage.setItem(e, t), Q({ cmd: "setItem", key: e, value: t });
    },
    removeItem: (e) => {
      window.sessionStorage.removeItem(e), Q({ cmd: "removeItem", key: e });
    },
    clear: () => {
      window.sessionStorage.clear(), Q({ cmd: "clear" });
    }
  },
  addMicroAppLifeCycleListener: (e, t) => {
    const n = (/* @__PURE__ */ new Date()).getTime() + Math.random().toString(36).slice(-8);
    _ || (_ = {});
    const s = () => {
      _[n] && delete _[n];
    };
    return _[n] = {
      type: e,
      handler: async (c) => await t(c),
      remove: s
    }, { remove: s };
  },
  triggerMicroAppLifeCycleListener: (e, t, n) => {
    var a;
    const s = _, { autoRemove: c = !1 } = n || {};
    for (const i in s) {
      const r = s[i];
      r.type === e && ((a = r == null ? void 0 : r.handler) == null || a.call(r, t).then(() => {
        c && r.remove();
      }));
    }
  },
  reloadMicroAppRoute: async (e, t) => {
    const n = f.value.find((s) => s.name === e);
    n && (!n.loaded || !n.actived || (n.dom || await new Promise((s) => M(() => n.dom, s)), b(e, "route", { cmd: "reload", path: t })));
  },
  unloadMicroAppRoute: async (e, t) => {
    const n = f.value.find((s) => s.name === e);
    n && (!n.loaded || !n.actived || (n.dom || await new Promise((s) => M(() => n.dom, s)), b(e, "route", { cmd: "unload", path: t })));
  },
  setMainAppLayoutVisible: (e) => {
    q("layoutVisible", { visible: e });
  }
}, u = P({
  visible: !1,
  theme: "default",
  logo: "",
  items: [],
  projects: [],
  userInfo: {},
  config: {},
  searchConfig: {},
  // activeItem: '',
  // activeProject: {},
  eventListeners: {}
}), W = {
  show: () => {
    u.visible = !0;
  },
  hide: () => {
    u.visible = !1;
  },
  setLogo: (e) => {
    u.logo = e;
  },
  setTheme: (e) => {
    u.theme = e;
  },
  setItems: (e) => {
    u.visible || (u.visible = !0), u.items = e;
  },
  getItems: () => u.items,
  removeItem: (e) => {
    const t = u.items.filter((n) => n.value !== e);
    u.items = t;
  },
  appendItem: (e) => {
    u.visible || (u.visible = !0), !u.items.find((n) => n.value == e.value) && u.items.push(e);
  },
  setActiveItem: (e) => {
    u.activeItem = e;
  },
  setConfig: (e) => {
    u.config = e;
  },
  setProjects: (e) => {
    u.projects = e;
  },
  setProjectConfig: (e) => {
    u.projectConfig = e;
  },
  setActiveProject: (e) => {
    u.activeProject = e;
  },
  setUserInfo: (e) => {
    u.userInfo = e;
  },
  setSearchConfig: (e) => {
    u.searchConfig = e;
  },
  triggerEventListener: (e, t, n) => {
    var i;
    const s = u.eventListeners, { autoRemove: c = !1 } = n || {}, a = [];
    for (const r in s) {
      const o = s[r];
      o.type === e && a.push(
        (i = o == null ? void 0 : o.handler) == null ? void 0 : i.call(o, t).then(() => {
          c && o.remove();
        })
      );
    }
    return Promise.all(a).then(() => !0).catch(() => !1);
  },
  addEventListener: (e, t) => {
    const n = (/* @__PURE__ */ new Date()).getTime() + Math.random().toString(36).slice(-8), s = () => {
      u.eventListeners[n] && delete u.eventListeners[n];
    };
    return u.eventListeners[n] = {
      type: e,
      handler: async (c) => {
        try {
          await t(c);
        } catch (a) {
          throw a;
        }
      },
      remove: s
    }, {
      remove: s
    };
  }
}, g = P({
  theme: "default",
  items: [],
  collapse: !1,
  eventListeners: {}
}), j = {
  setItems: (e) => {
    g.items = e;
  },
  getItems: () => g.items,
  setTheme: (e) => {
    g.theme = e;
  },
  setActiveItem: (e) => {
    g.activeItem = e;
  },
  setCollapse: (e) => {
    g.collapse = e;
  },
  setPopupClassName: (e) => {
    g.popupClassName = e;
  },
  triggerEventListener: (e, t, n) => {
    var i;
    const s = g.eventListeners, { autoRemove: c = !1 } = n || {}, a = [];
    for (const r in s) {
      const o = s[r];
      o.type === e && a.push(
        (i = o == null ? void 0 : o.handler) == null ? void 0 : i.call(o, t).then(() => {
          c && o.remove();
        })
      );
    }
    return Promise.all(a).then(() => !0).catch(() => !1);
  },
  addEventListener: (e, t) => {
    const n = (/* @__PURE__ */ new Date()).getTime() + Math.random().toString(36).slice(-8), s = () => {
      g.eventListeners[n] && delete g.eventListeners[n];
    };
    return g.eventListeners[n] = {
      type: e,
      handler: async (c) => {
        try {
          await t(c);
        } catch (a) {
          throw a;
        }
      },
      remove: s
    }, {
      remove: s
    };
  }
}, A = P({
  theme: "default",
  items: [],
  eventListeners: {}
}), H = {
  setItems: (e) => {
    A.items = e;
  },
  getItems: () => A.items,
  setTheme: (e) => {
    A.theme = e;
  },
  removeItem: (e) => {
    const t = A.items.filter((n) => n.value !== e);
    A.items = t;
  },
  appendItem: (e) => {
    const t = A.items.findIndex((n) => n.value == e.value);
    t !== -1 ? A.items.splice(t, 1, e) : A.items.push(e);
  },
  setActiveItem: (e) => {
    A.activeItem = e;
  },
  triggerEventListener: (e, t, n) => {
    var i;
    const s = A.eventListeners, { autoRemove: c = !1 } = n || {}, a = [];
    for (const r in s) {
      const o = s[r];
      o.type === e && a.push(
        (i = o == null ? void 0 : o.handler) == null ? void 0 : i.call(o, t).then(() => {
          c && o.remove();
        })
      );
    }
    return Promise.all(a).then(() => !0).catch(() => !1);
  },
  addEventListener: (e, t) => {
    const n = (/* @__PURE__ */ new Date()).getTime() + Math.random().toString(36).slice(-8), s = () => {
      A.eventListeners[n] && delete A.eventListeners[n];
    };
    return A.eventListeners[n] = {
      type: e,
      handler: async (c) => {
        try {
          await t(c);
        } catch (a) {
          throw a;
        }
      },
      remove: s
    }, {
      remove: s
    };
  }
}, R = P({
  eventListeners: {}
}), Ce = {
  triggerEventListener: (e, t, n) => {
    var i;
    const s = R.eventListeners, { autoRemove: c = !1 } = n || {}, a = [];
    for (const r in s) {
      const o = s[r];
      o.type === e && a.push(
        (i = o == null ? void 0 : o.handler) == null ? void 0 : i.call(o, t).then(() => {
          c && o.remove();
        })
      );
    }
    return Promise.all(a).then(() => !0).catch(() => !1);
  },
  addEventListener: (e, t) => {
    const n = (/* @__PURE__ */ new Date()).getTime() + Math.random().toString(36).slice(-8), s = () => {
      R.eventListeners[n] && delete R.eventListeners[n];
    };
    return R.eventListeners[n] = {
      type: e,
      handler: async (c) => {
        try {
          await t(c);
        } catch (a) {
          throw a;
        }
      },
      remove: s
    }, {
      remove: s
    };
  }
}, U = P({
  visible: !1,
  style: {}
}), Oe = {
  set: (e, t) => {
    U.visible = e, t || (t = {}), t.transition || (t.transition = "all 0.3s"), t && (U.style = t);
  }
}, Fe = {
  visible: w(!0)
}, G = {
  nav: W,
  menu: j,
  tab: H,
  overlay: Oe,
  iframeView: Ce,
  setVisible: (e) => Fe.visible.value = e,
  setTheme: (e) => {
    W.setTheme(e), j.setTheme(e), H.setTheme(e);
  }
}, re = (e, t) => {
  const n = e.__vccOpts || e;
  for (const [s, c] of t)
    n[s] = c;
  return n;
};
var J;
const B = typeof window < "u", Re = (e) => typeof e == "string", Ne = () => {
};
B && ((J = window == null ? void 0 : window.navigator) != null && J.userAgent) && /iP(ad|hone|od)/.test(window.navigator.userAgent);
function ae(e) {
  return typeof e == "function" ? e() : I(e);
}
function De(e) {
  return e;
}
function ie(e) {
  return ue() ? (de(e), !0) : !1;
}
function ke(e, t = !0) {
  pe() ? me(e) : t ? e() : ne(e);
}
function oe(e) {
  var t;
  const n = ae(e);
  return (t = n == null ? void 0 : n.$el) != null ? t : n;
}
const xe = B ? window : void 0, Ve = B ? window.document : void 0;
function qe(...e) {
  let t, n, s, c;
  if (Re(e[0]) || Array.isArray(e[0]) ? ([n, s, c] = e, t = xe) : [t, n, s, c] = e, !t)
    return Ne;
  Array.isArray(n) || (n = [n]), Array.isArray(s) || (s = [s]);
  const a = [], i = () => {
    a.forEach((l) => l()), a.length = 0;
  }, r = (l, y, m, L) => (l.addEventListener(y, m, L), () => l.removeEventListener(y, m, L)), o = M(() => [oe(t), ae(c)], ([l, y]) => {
    i(), l && a.push(...n.flatMap((m) => s.map((L) => r(l, m, L, y))));
  }, { immediate: !0, flush: "post" }), p = () => {
    o(), i();
  };
  return ie(p), p;
}
function Qe(e, t = !1) {
  const n = w(), s = () => n.value = !!e();
  return s(), ke(s, t), n;
}
const K = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}, X = "__vueuse_ssr_handlers__";
K[X] = K[X] || {};
const Y = [
  [
    "requestFullscreen",
    "exitFullscreen",
    "fullscreenElement",
    "fullscreenEnabled",
    "fullscreenchange",
    "fullscreenerror"
  ],
  [
    "webkitRequestFullscreen",
    "webkitExitFullscreen",
    "webkitFullscreenElement",
    "webkitFullscreenEnabled",
    "webkitfullscreenchange",
    "webkitfullscreenerror"
  ],
  [
    "webkitRequestFullScreen",
    "webkitCancelFullScreen",
    "webkitCurrentFullScreenElement",
    "webkitCancelFullScreen",
    "webkitfullscreenchange",
    "webkitfullscreenerror"
  ],
  [
    "mozRequestFullScreen",
    "mozCancelFullScreen",
    "mozFullScreenElement",
    "mozFullScreenEnabled",
    "mozfullscreenchange",
    "mozfullscreenerror"
  ],
  [
    "msRequestFullscreen",
    "msExitFullscreen",
    "msFullscreenElement",
    "msFullscreenEnabled",
    "MSFullscreenChange",
    "MSFullscreenError"
  ]
];
function Be(e, t = {}) {
  const { document: n = Ve, autoExit: s = !1 } = t, c = n == null ? void 0 : n.querySelector("html"), a = w(!1);
  let i = Y[0];
  const r = Qe(() => {
    if (n) {
      for (const S of Y)
        if (S[1] in n)
          return i = S, !0;
    } else
      return !1;
    return !1;
  }), [o, p, l, , y] = i;
  async function m() {
    r.value && (n != null && n[l] && await n[p](), a.value = !1);
  }
  async function L() {
    if (!r.value)
      return;
    await m();
    const S = oe(c);
    S && (await S[o](), a.value = !0);
  }
  async function le() {
    a.value ? await m() : await L();
  }
  return n && qe(n, y, () => {
    a.value = !!(n != null && n[l]);
  }, !1), s && ie(m), {
    isSupported: r,
    isFullscreen: a,
    enter: L,
    exit: m,
    toggle: le
  };
}
var Z;
(function(e) {
  e.UP = "UP", e.RIGHT = "RIGHT", e.DOWN = "DOWN", e.LEFT = "LEFT", e.NONE = "NONE";
})(Z || (Z = {}));
var $e = Object.defineProperty, ee = Object.getOwnPropertySymbols, ze = Object.prototype.hasOwnProperty, We = Object.prototype.propertyIsEnumerable, te = (e, t, n) => t in e ? $e(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n, je = (e, t) => {
  for (var n in t || (t = {}))
    ze.call(t, n) && te(e, n, t[n]);
  if (ee)
    for (var n of ee(t))
      We.call(t, n) && te(e, n, t[n]);
  return e;
};
const He = {
  easeInSine: [0.12, 0, 0.39, 0],
  easeOutSine: [0.61, 1, 0.88, 1],
  easeInOutSine: [0.37, 0, 0.63, 1],
  easeInQuad: [0.11, 0, 0.5, 0],
  easeOutQuad: [0.5, 1, 0.89, 1],
  easeInOutQuad: [0.45, 0, 0.55, 1],
  easeInCubic: [0.32, 0, 0.67, 0],
  easeOutCubic: [0.33, 1, 0.68, 1],
  easeInOutCubic: [0.65, 0, 0.35, 1],
  easeInQuart: [0.5, 0, 0.75, 0],
  easeOutQuart: [0.25, 1, 0.5, 1],
  easeInOutQuart: [0.76, 0, 0.24, 1],
  easeInQuint: [0.64, 0, 0.78, 0],
  easeOutQuint: [0.22, 1, 0.36, 1],
  easeInOutQuint: [0.83, 0, 0.17, 1],
  easeInExpo: [0.7, 0, 0.84, 0],
  easeOutExpo: [0.16, 1, 0.3, 1],
  easeInOutExpo: [0.87, 0, 0.13, 1],
  easeInCirc: [0.55, 0, 1, 0.45],
  easeOutCirc: [0, 0.55, 0.45, 1],
  easeInOutCirc: [0.85, 0, 0.15, 1],
  easeInBack: [0.36, 0, 0.66, -0.56],
  easeOutBack: [0.34, 1.56, 0.64, 1],
  easeInOutBack: [0.68, -0.6, 0.32, 1.6]
};
je({
  linear: De
}, He);
const Ue = ["src", "entry", "name"], Ge = /* @__PURE__ */ x({
  __name: "das-micro-app",
  props: {
    src: {},
    name: {},
    actived: { type: Boolean }
  },
  emits: ["onLoaded", "onActivated", "onDeactivated"],
  setup(e, { emit: t }) {
    const n = e, s = t, c = (r) => {
      s("onLoaded", r);
    }, a = N(() => n.actived);
    return M(() => a.value, (r) => {
      r && s("onActivated"), r || s("onDeactivated");
    }), (r, o) => (E(), D("iframe", {
      class: "das-micro-app",
      src: n.src,
      entry: n.src,
      name: n.name,
      frameborder: "0",
      onLoad: c
    }, null, 40, Ue));
  }
}), Je = /* @__PURE__ */ re(Ge, [["__scopeId", "data-v-8ae871f6"]]), Ke = /* @__PURE__ */ x({
  __name: "das-micro-apps",
  setup(e) {
    const t = w(null), n = async (a, i) => {
      const r = f.value.find((m) => m.name === i);
      if (!r) return;
      r.dom = a.target, await ne(), await new Promise((m) => setTimeout(m, 50));
      const o = () => {
        const m = t.value.getBoundingClientRect() || {};
        return m.width = t.value.clientWidth, m.height = t.value.clientHeight, m;
      };
      d.sendMessageToMicroApp(i, "onLoaded", {
        href: location.href,
        microAppContainerRect: o(),
        entry: r.entry,
        name: r.name
      });
      const { dom: p, ...l } = r;
      d.triggerMicroAppLifeCycleListener("onLoaded", l), new ResizeObserver(() => {
        d.sendMessageToMicroApp(i, "resize", o());
      }).observe(t.value), d.sendMessageToMicroApp(i, "setProxyMessageStatus", { visible: !0, parentHref: location.href }), d.sendMessageToMicroApp(i, "setProxSsoStatus", { visible: !0, parentHref: location.href });
    }, s = (a, i) => {
      const r = f.value.find((l) => l.name === i);
      if (!r) return;
      const { dom: o, ...p } = r;
      d.sendMessageToMicroApp(i, "onActivated"), d.triggerMicroAppLifeCycleListener("onActivated", p);
    }, c = (a, i) => {
      const r = f.value.find((l) => l.name === i);
      if (!r) return;
      const { dom: o, ...p } = r;
      d.sendMessageToMicroApp(i, "onDeactivated"), d.triggerMicroAppLifeCycleListener("onDeactivated", p);
    };
    return (a, i) => (E(), D(
      "div",
      {
        ref_key: "containerRef",
        ref: t,
        class: "das-micro-app-container"
      },
      [
        (E(!0), D(
          $,
          null,
          fe(I(f), (r) => (E(), D(
            $,
            null,
            [
              r.loaded ? ve((E(), se(Je, {
                key: 0,
                src: r.src || "",
                name: r.name,
                actived: r.actived,
                onOnLoaded: (o) => n(o, r.name),
                onOnActivated: (o) => s(o, r.name),
                onOnDeactivated: (o) => c(o, r.name)
              }, null, 8, ["src", "name", "actived", "onOnLoaded", "onOnActivated", "onOnDeactivated"])), [
                [Ae, r.actived]
              ]) : he("v-if", !0)
            ],
            64
            /* STABLE_FRAGMENT */
          ))),
          256
          /* UNKEYED_FRAGMENT */
        ))
      ],
      512
      /* NEED_PATCH */
    ));
  }
}), Xe = /* @__PURE__ */ re(Ke, [["__scopeId", "data-v-3abdb1e9"]]), tt = /* @__PURE__ */ x({
  __name: "das-main-app-layout",
  props: {
    transitionConfig: { default: () => {
    } },
    showLayout: { type: Boolean, default: !0 },
    showAside: { type: Boolean, default: !0 },
    showTabs: { type: Boolean, default: !0 },
    menuAttr: { default: () => {
    } },
    tabsAttr: { default: () => {
    } }
  },
  setup(e) {
    const t = e, n = N(() => !k.value), s = N(() => ({
      "enter-active-class": "animate__animated animate__fadeInLeft",
      ...t.transitionConfig
    })), c = N(() => ({ showLayout: t.showLayout, showAside: t.showAside, showTabs: t.showTabs }));
    return (a, i) => (E(), se(I(ye), we({
      "transition-config": s.value,
      "router-view-visible": n.value
    }, c.value), {
      header: T(() => [
        V(a.$slots, "header", {}, () => [
          C(I(_e))
        ])
      ]),
      aside: T(() => [
        V(a.$slots, "aside", {}, () => [
          C(I(Le), { menuAttr: a.menuAttr }, null, 8, ["menuAttr"])
        ])
      ]),
      tab: T(() => [
        V(a.$slots, "tab", {}, () => [
          C(I(Me), { tabsAttr: a.tabsAttr }, null, 8, ["tabsAttr"])
        ])
      ]),
      default: T(() => [
        C(Xe)
      ]),
      _: 3
      /* FORWARDED */
    }, 16, ["transition-config", "router-view-visible"]));
  }
}), ce = /* @__PURE__ */ x({
  __name: "das-micro-app-ghost",
  setup(e) {
    return ge(() => {
      setTimeout(() => {
        document.documentElement.checkVisibility() && history.back();
      }, 300);
    }), (t, n) => null;
  }
}), Ye = (e) => ["http://", "https://", "ws://", "wss://", "/"].find((n) => e.startsWith(n)) ? e : `/${e}`, nt = (e, t) => {
  if (!(e != null && e.microApps) || !Array.isArray(e.microApps)) return;
  window.__IN_DAS_MAIN_APP = !0, e != null && e.microAppRouterPrefix && (z.value = e.microAppRouterPrefix), f.value = (e.microApps || []).filter((c) => !!c.name).map((c) => ({ ...c, entry: Ye(c.entry || c.name) })), t == null || t.addRoute({
    name: "das-micro-app",
    path: `${z.value}/:pathMatch(.*)*`,
    component: ce,
    meta: { isMicroApp: !0, keepAlive: !0 }
  }), d.addEventListenerFromMicroApp("bodyOverlay", (c) => {
    const { visible: a, style: i } = c.data;
    G.overlay.set(a, i);
  }), d.addEventListenerFromMicroApp("layoutVisible", (c) => {
    const { visible: a } = c.data;
    G.setVisible(a);
  }), d.addEventListenerFromMicroApp("route", (c) => {
    const { name: a, cmd: i, path: r } = c.data;
    i === "reload" && d.reloadMicroAppRoute(a, r), i === "unload" && d.unloadMicroAppRoute(a, r);
  });
  const { enter: n, exit: s } = Be();
  d.addEventListenerFromMicroApp("fullscreen", (c) => {
    const a = c.data;
    a && n(), a || s();
  }), d.addEventListenerFromMicroApp("location", (c) => {
    const { cmd: a, isAutoCloseApp: i } = c.data || {};
    a === "reload" && (i !== void 0 && (window.__isAutoCloseApp = i), location.reload());
  });
}, st = (e, t) => {
  if (!(e != null && e.microAppName)) return;
  window.config.microAppName = e.microAppName, window.self !== window.top && e.microAppName && (window.__IN_DAS_MICRO_APP = !0);
  const n = "das-micro-app-ghost";
  t == null || t.addRoute({
    name: n,
    path: `/${n}/:pathMatch(.*)*`,
    component: ce,
    meta: { isMicroApp: !0, keepAlive: !0 }
  });
  const s = w(!1), c = w(!1), a = w("");
  M(
    () => t.currentRoute.value,
    (i) => {
      if (s.value) {
        s.value = !1;
        return;
      }
      if (c.value) {
        c.value = !1;
        return;
      }
      const { path: r, query: o, params: p, meta: l } = i;
      if (a.value.includes(i.path)) {
        a.value = "";
        return;
      }
      d.sendMessageToMainApp("router", {
        cmd: "push",
        route: {
          path: r,
          query: { ...o, microAppName: e.microAppName },
          params: p,
          meta: l
        }
      });
    }
  ), d.addEventListenerFromMainApp("router", async (i) => {
    var l;
    const { cmd: r, route: o, microAppName: p = "" } = i.data;
    a.value = ("/" + p + o.path).replace(/\/\//g, "/"), (l = t == null ? void 0 : t[r]) == null || l.call(t, o);
  }), d.addEventListenerFromMainApp("onLoaded", (i) => {
    const { href: r, microAppContainerRect: o } = i.data;
    window.__IN_DAS_MICRO_APP = !0, window.__DAS_MICRO_APP_NAME = e.microAppName, window.__DAS_MAIN_APP_HREF = r, window.__DAS_MICRO_APP_CONTAINER_RECT = o;
  }), d.addEventListenerFromMainApp("onDeactivated", (i) => {
    const { name: r = "", path: o, params: p = {}, query: l = {} } = t.currentRoute.value;
    c.value = !0, t == null || t.push({
      name: n,
      query: { microAppName: e.microAppName, fromQuery: JSON.stringify(l), fromPath: o },
      params: p
    });
  }), d.addEventListenerFromMainApp("onActivated", (i) => {
    const { name: r = "", params: o = {}, query: p = {} } = t.currentRoute.value, { fromPath: l = "", fromQuery: y = "{}" } = p || {};
    s.value = !0, t == null || t.push({ path: l, query: JSON.parse(y), params: o });
  }), d.addEventListenerFromMainApp("sessionStorage", (i) => {
    const { cmd: r, key: o, value: p } = i.data;
    r === "setItem" && window.sessionStorage.setItem(o, p), r === "getItem" && window.sessionStorage.getItem(o), r === "removeItem" && window.sessionStorage.removeItem(o), r === "clear" && window.sessionStorage.clear();
  }), d.addEventListenerFromMainApp("route", (i) => {
    const { cmd: r, path: o } = i.data;
    r === "reload" && (O.value.push(o), F.value = !1, setTimeout(() => {
      F.value = !0, O.value = [];
    }, 300)), r === "unload" && (O.value.push(o), F.value = !1, setTimeout(() => {
      F.value = !0, O.value = [];
    }, 100));
  });
};
export {
  tt as DasMainAppLayout,
  nt as initMainApp,
  st as initMicroApp,
  d as microFrontend
};
