import '@das-fed/ui/packages/business-components/layout-breadcrumb/style.css';
import { ref as _, computed as T, watch as I, nextTick as q, defineComponent as N, createElementBlock as R, createCommentVNode as U, unref as g, openBlock as x, createVNode as D } from "vue";
import { withInstall as O } from "@das-fed/utils/with-install/index";
import { DasBreadCrumb as P } from "@das-fed/ui/packages/components/breadcrumb/index";
import { useRouter as J, useRoute as $ } from "vue-router";
import { flatTree as L } from "@das-fed/utils/common-tools";
import { getSubApps as S } from "@das-fed/utils/common-info";
import { setThemeRule as j } from "@das-fed/web/packages/theme/index";
const E = (s, l) => {
  const a = _([]), b = T(() => [...a.value, ...s.data || []]), p = (e) => new Promise((c) => {
    const { app: r = "", menu: i = "" } = e || {};
    if (!r) return c(!1);
    const u = () => {
      const t = S() ?? {}, o = t.currentSubAppCode, d = t.currentSubApp.currentMenuCode;
      if (JSON.parse(sessionStorage.getItem("breadcrumb") || "{}")[r] && r === o && i === d)
        return c(!0);
      setTimeout(() => u(), 100);
    };
    u();
  }), h = async (e, c) => {
    var d, n;
    await p(c);
    const r = [], i = c.menu || "", u = ((n = (d = S()) == null ? void 0 : d.currentSubApp) == null ? void 0 : n.menus) ?? [];
    if (!u || !u.length) return;
    let t = null;
    const o = L(u);
    if (i ? t = o.find((m) => m.code === i) : t = o.find((m) => m.routeUrl && m.routeUrl === e), t) {
      const m = t.code.split(".");
      if (m.length === 3) {
        const B = m.slice(0, 2).join("."), k = o.find((v) => v.code === B || v.originalCode === B);
        r.push({ name: (k == null ? void 0 : k.name) ?? "", isMenu: !0, disabled: !0 });
      }
      const M = {
        name: (t == null ? void 0 : t.name) ?? "",
        routerPath: (t == null ? void 0 : t.routeUrl) ?? "",
        isMenu: !0
      };
      r.push(M);
    }
    a.value = r;
  }, y = (e) => {
    e.disabled || l("click-item", e);
  }, C = J(), f = $();
  I(
    () => C.currentRoute.value,
    (e) => {
      const c = (e == null ? void 0 : e.path) ?? "", r = (e == null ? void 0 : e.query) ?? {};
      setTimeout(() => {
        h(c, r);
      }, 200);
    }
  ), h(f.path, f.query);
  const A = _(!1);
  return I(
    () => s.data,
    async () => {
      var t;
      await q(), await p(f.query);
      const e = S(), c = f.query.app || e.currentSubApp.code || "";
      let r = f.query.menu || "";
      if (!r) {
        const o = ((t = e.currentSubApp) == null ? void 0 : t.menus) ?? [], d = L(o).find(
          (n) => `/${(n == null ? void 0 : n.applicationPath) ?? ""}${(n == null ? void 0 : n.routeUrl) ?? ""}`.replace(/\/\//g, "/") === location.pathname
        );
        d && (r = d.code);
      }
      const i = JSON.parse(sessionStorage.getItem("breadcrumb") || "{}")[c], u = [];
      for (let o in i) i[o] && u.push(o);
      A.value = !!u.find((o) => r === o);
    },
    { deep: !0, immediate: !0 }
  ), {
    isShow: A,
    breadcrumbList: b,
    clickItem: y
  };
}, w = {
  key: 0,
  class: "layout-breadcrumb"
}, z = {
  name: "LayoutBreadCrumb"
}, F = /* @__PURE__ */ N({
  ...z,
  props: {
    data: { default: () => [] }
  },
  emits: ["click-item"],
  setup(s, { emit: l }) {
    const a = s, b = l, { isShow: p, breadcrumbList: h, clickItem: y } = E(a, b);
    return (C, f) => g(p) && C.data && C.data.length ? (x(), R("div", w, [
      D(g(P), {
        data: g(h),
        onClickItem: g(y)
      }, null, 8, ["data", "onClickItem"])
    ])) : U("v-if", !0);
  }
}), G = (s, l) => {
  const a = s.__vccOpts || s;
  for (const [b, p] of l)
    a[b] = p;
  return a;
}, H = /* @__PURE__ */ G(F, [["__scopeId", "data-v-878cd70a"]]), K = {
  "--das-layout-micro-container-bg-color": "#e2e7ef",
  "--das-layout-breadcrumb-bg-color": "#ffffff"
};
j(K);
const te = O(H), re = () => _(null);
export {
  te as DasLayoutBreadcrumb,
  re as DasLayoutBreadcrumbRef
};
