import '@das-fed/upf-ui/packages/business-components/layout-breadcrumb/style.css';
import { ref as y, computed as L, watch as C, nextTick as B, defineComponent as S, openBlock as v, createElementBlock as M, createVNode as A, unref as b, createCommentVNode as N } from "vue";
import { withInstall as q } from "@das-fed/upf-utils/with-install/index";
import { DasBreadCrumb as x } from "@das-fed/upf-ui/packages/components/breadcrumb/index";
import { useRouter as R, useRoute as T } from "vue-router";
import { flatTree as D } from "@das-fed/upf-utils/common-tools";
import { getSubApps as k, getMenuItemInfo as P, getMenuListnfo as O } from "@das-fed/upf-utils/common-info";
const U = (o, p) => {
  const i = y([]), m = L(() => [...i.value, ...o.data || []]), f = () => new Promise((e) => {
    const t = () => {
      var r, n;
      const { app: c = "" } = (s == null ? void 0 : s.query) || {}, u = ((n = (r = k()) == null ? void 0 : r.currentSubApp) == null ? void 0 : n.menus) ?? [];
      if (c === k().currentSubAppCode && u.length) return e();
      setTimeout(() => t(), 50);
    };
    t();
  }), l = (...e) => {
    const t = P(), c = O(), u = [], r = c.find((n) => n.appId === t.appId);
    if (r && r.children && r.children.length)
      if (t.parentId === r.id)
        u.push({ name: t.showName || "", isMenu: !0, routerPath: (t == null ? void 0 : t.routeUrl) ?? "" });
      else {
        const n = r.children.find((a) => a.id === t.parentId);
        n && (u.push({ name: n.showName || "", isMenu: !0, disabled: !0 }), u.push({ name: t.showName || "", isMenu: !0 }));
      }
    i.value = u;
  }, h = (e) => {
    e.disabled || p("click-item", e);
  }, g = R(), s = T();
  C(
    () => g.currentRoute.value,
    (e) => {
      const t = (e == null ? void 0 : e.path) ?? "", c = (e == null ? void 0 : e.query) ?? {};
      l(t, c);
    }
  ), l(s.path, s.query);
  const I = y(!1);
  return C(
    () => o.data,
    () => {
      B(() => {
        f().then(() => {
          var n;
          const e = k(), t = s.query.app || e.currentSubApp.code || "";
          let c = s.query.menu || "";
          if (!c) {
            const a = ((n = e.currentSubApp) == null ? void 0 : n.menus) ?? [], _ = D(a).find(
              (d) => `/${(d == null ? void 0 : d.applicationPath) ?? ""}${(d == null ? void 0 : d.routeUrl) ?? ""}`.replace(/\/\//g, "/") === location.pathname
            );
            _ && (c = _.code);
          }
          const u = JSON.parse(sessionStorage.getItem("breadcrumb") || "{}")[t], r = [];
          for (let a in u) u[a] && r.push(a);
          I.value = !!r.find((a) => c === a);
        });
      });
    },
    { deep: !0, immediate: !0 }
  ), {
    isShow: I,
    breadcrumbList: m,
    clickItem: h
  };
}, $ = {
  key: 0,
  class: "layout-breadcrumb"
}, E = {
  name: "LayoutBreadCrumb"
}, J = /* @__PURE__ */ S({
  ...E,
  props: {
    data: { default: () => [] }
  },
  emits: ["click-item"],
  setup(o, { emit: p }) {
    const i = o, m = p, { isShow: f, breadcrumbList: l, clickItem: h } = U(i, m);
    return (g, s) => o.data && o.data.length ? (v(), M("div", $, [
      A(b(x), {
        data: b(l),
        onClickItem: b(h)
      }, null, 8, ["data", "onClickItem"])
    ])) : N("v-if", !0);
  }
}), j = (o, p) => {
  const i = o.__vccOpts || o;
  for (const [m, f] of p)
    i[m] = f;
  return i;
}, w = /* @__PURE__ */ j(J, [["__scopeId", "data-v-511908ae"]]), W = q(w), X = () => y(null);
export {
  W as DasLayoutBreadcrumb,
  X as DasLayoutBreadcrumbRef
};
