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