import { defineComponent as v, computed as p, withDirectives as U, createBlock as C, openBlock as A, unref as c, withCtx as S, createVNode as I, vShow as j } from "vue";
import { layoutData as D } from "@das-fed/web/packages/layout/index";
import { t as $ } from "@das-fed/web/packages/i18n/index";
import { DasAppContainer as x } from "@das-fed/ui/packages/business-components/app-container/index";
import { DasSpin as T } from "@das-fed/ui/packages/components/spin/index";
import { getTabInfo as b } from "@das-fed/utils/common-info";
import { setShowLayout as E } from "@das-fed/utils/common-tools";
import { createService as L } from "@das-fed/utils/create-api-service";
import { u as P, p as q, a as u, c as d, b as B, l as K, g as M, d as N } from "./index-CfLq5c7I.js";
const O = "v1", V = L(`/api/justauth/client/${O}`), F = V.get("/visitor/kingdee/auth/user/auth_code"), ee = /* @__PURE__ */ v({
  __name: "index",
  setup(G) {
    const { beforeEntryApp: g, entryApp: m } = P(), h = p(() => q.value.skinStyle), w = p(() => !!D.menu.items.length), y = p(() => {
      if (!u.value || !u.value.length) return [];
      const t = d(u.value);
      return Array.isArray(t) ? t.length ? (t.forEach((r) => {
        r.apps = _(
          r.apps,
          // element.apps.filter((item: any) => item?.code && item.code !== 'dasaiassistant'),
          4
        );
      }), t) : [] : [];
    }), _ = (t, r) => {
      const i = [];
      for (let e = 0; e < t.length; e += r)
        i.push(t.slice(e, e + r));
      return i;
    }, k = async (t, r = !0) => {
      if (!t) return;
      if (!sessionStorage.getItem("projectInfo")) {
        window.confirm($("系统资源更新，请刷新系统")) && (window.__isAutoCloseApp = !1, window.location.reload());
        return;
      }
      const e = d(t);
      if (K.innerSet = r, e.routeUrl) {
        if (t.code === "Ioc") {
          window.open(e.routeUrl, "_blank");
          return;
        }
        if (t.code === "wojiacloud") {
          const o = sessionStorage.getItem("kingdee_token") || "";
          if (o) {
            const [n, a] = await F().run({ accessToken: o });
            if (a) {
              const s = (a == null ? void 0 : a.auth_code) ?? "";
              e.routeUrl = e.routeUrl.includes("?") ? `${e.routeUrl}&code=${s}` : `${e.routeUrl}?code=${s}`;
            }
          }
        }
      }
      const l = (t == null ? void 0 : t.openType) ?? 1, f = (t == null ? void 0 : t.type) ?? 1;
      if (l === 1) {
        if (!await g(t)) return;
        const n = b().preTab[t.code], a = (n == null ? void 0 : n.code) ?? "", s = { ...(n == null ? void 0 : n.query) ?? {} };
        m({ microApp: e, menuCode: a, route: { query: s } });
      }
      if (l === 2 && e.routeUrl) {
        let o = "";
        if (f === 1)
          o = e != null && e.applicationPath ? ("/" + e.applicationPath + "/" + e.routeUrl).replace(/\/\//g, "/") : ("/" + e.routeUrl).replace(/\/\//g, "/"), o = E(o);
        else if (f === 2) {
          const n = await M(e.routeUrl, (e == null ? void 0 : e.param) ?? []);
          o = N(n);
        }
        window.open(o, "_blank");
      }
    };
    return (t, r) => U((A(), C(c(T), {
      full: "",
      spinning: c(B)
    }, {
      default: S(() => [
        I(c(x), {
          theme: h.value,
          appCategorys: y.value,
          onOpenApp: k
        }, null, 8, ["theme", "appCategorys"])
      ]),
      _: 1
      /* STABLE */
    }, 8, ["spinning"])), [
      [j, !w.value]
    ]);
  }
});
export {
  ee as default
};
