import '@das-fed/upf-ui/packages/components/virtual-tree/style.css';
import { defineComponent as k, openBlock as d, createElementBlock as f, createElementVNode as v, renderSlot as x, createTextVNode as H, toDisplayString as B, createStaticVNode as A, ref as u, useAttrs as P, watch as h, h as y, normalizeClass as J, createVNode as K, unref as $, mergeProps as L, withCtx as g, createBlock as T, computed as m, onMounted as W, onBeforeUnmount as U, normalizeStyle as j, Fragment as E, createCommentVNode as D, createSlots as q, nextTick as G } from "vue";
import { withInstall as Q } from "@das-fed/upf-utils/with-install/index";
import { ElTreeV2 as X } from "element-plus";
import "element-plus/es/components/tree-v2/style/css";
import { t as Y, setI18nRule as Z } from "@das-fed/upf-web/packages/i18n/index";
import { Spin as ee } from "ant-design-vue";
import "ant-design-vue/es/spin/style/css";
import { DasIconLoad as te } from "@das-fed/upf-ui/packages/icons/load/index";
import "@das-fed/upf-ui/packages/components/icon/index";
import { DasIconCaretRight as ae } from "@das-fed/upf-ui/packages/icons/caret-right/index";
import { SizeWatcher as ne } from "@das-fed/upf-utils/size-watcher";
import { flatTree as z } from "@das-fed/upf-utils/common-tools";
const se = { class: "tree-empty-block" }, ie = { class: "tree-empty-text" }, oe = /* @__PURE__ */ k({
  __name: "empty",
  props: {
    emptyText: {}
  },
  setup(t) {
    return (a, s) => (d(), f("div", se, [
      v("div", ie, [
        x(a.$slots, "default", {}, () => [
          H(
            B(t.emptyText),
            1
            /* TEXT */
          )
        ], !0)
      ])
    ]));
  }
}), _ = (t, a) => {
  const s = t.__vccOpts || t;
  for (const [r, o] of a)
    s[r] = o;
  return s;
}, le = /* @__PURE__ */ _(oe, [["__scopeId", "data-v-507e2bf9"]]), de = {}, re = { class: "das-spin-container das-spin-page" };
function ce(t, a) {
  return d(), f("div", re, [...a[0] || (a[0] = [
    A('<div class="das-spin-dot-spin" data-v-323f37a9><i class="das-spin-dot-item" data-v-323f37a9></i><i class="das-spin-dot-item" data-v-323f37a9></i><i class="das-spin-dot-item" data-v-323f37a9></i><i class="das-spin-dot-item" data-v-323f37a9></i></div>', 1)
  ])]);
}
const fe = /* @__PURE__ */ _(de, [["render", ce], ["__scopeId", "data-v-323f37a9"]]), ue = {}, pe = { class: "das-spin-container das-spin-component" };
function me(t, a) {
  return d(), f("div", pe, [...a[0] || (a[0] = [
    v(
      "div",
      { class: "das-spin-dot-spin" },
      [
        v("i", { class: "das-spin-dot-item" })
      ],
      -1
      /* CACHED */
    )
  ])]);
}
const he = /* @__PURE__ */ _(ue, [["render", me], ["__scopeId", "data-v-f47a1ae6"]]), ve = {}, _e = { class: "das-spin-container das-spin-containerload" };
function ye(t, a) {
  return d(), f("div", _e, [...a[0] || (a[0] = [
    A('<div class="das-spin-dot-spin" data-v-f7548f22><i class="das-spin-dot-item" data-v-f7548f22></i><i class="das-spin-dot-item" data-v-f7548f22></i><i class="das-spin-dot-item" data-v-f7548f22></i><i class="das-spin-dot-item" data-v-f7548f22></i></div>', 1)
  ])]);
}
const ge = /* @__PURE__ */ _(ve, [["render", ye], ["__scopeId", "data-v-f7548f22"]]), xe = /* @__PURE__ */ k({
  __name: "index",
  props: {
    type: { default: "page" },
    size: { default: "big" },
    customSize: { default: "28" },
    iconColor: { default: "var(--upf-loading-color-5, var(--upf-color-primary))" },
    full: { type: Boolean, default: !0 }
  },
  setup(t) {
    let a = t, s = u("");
    const r = P();
    return h(
      () => a.type,
      (o, e) => {
        o == "page" && (s.value = y(fe)), o == "container" && (s.value = y(ge)), o == "component" && (s.value = y(he)), o == "load" && (s.value = y(te, {
          iconColor: a.iconColor,
          customSize: a.customSize
        }));
      },
      { immediate: !0 }
    ), h(
      () => r,
      (o, e) => {
        r.indicator && (s.value = r.indicator);
      },
      { immediate: !0 }
    ), (o, e) => (d(), f(
      "div",
      {
        class: J({ "das-spin-container": !0, full: t.full })
      },
      [
        K($(ee), L({
          class: `das-slef-spin ${t.size} ${t.type} `
        }, o.$attrs, { indicator: $(s) }), {
          default: g(() => [
            x(o.$slots, "default")
          ]),
          _: 3
          /* FORWARDED */
        }, 16, ["class", "indicator"])
      ],
      2
      /* CLASS */
    ));
  }
}), $e = /* @__PURE__ */ k({
  __name: "expand-icon",
  setup(t) {
    return (a, s) => (d(), T($(ae), {
      class: "das-tree__expand-icon",
      size: "medium"
    }));
  }
}), ke = /* @__PURE__ */ _($e, [["__scopeId", "data-v-e225c8a8"]]), Ce = { class: "tree-normal-node" }, Ne = /* @__PURE__ */ k({
  name: "DasVirtualTree",
  inheritAttrs: !1,
  __name: "App",
  props: {
    data: { default: () => [] },
    loading: { type: Boolean },
    nodeKey: { default: "id" },
    showCheckbox: { type: Boolean },
    height: {},
    currentNodeKey: {},
    defaultExpandAll: { type: Boolean, default: !1 },
    expandOnClickNode: { type: Boolean, default: !1 },
    props: {},
    emptyText: { default: "" },
    filterMethod: {}
  },
  setup(t, { expose: a }) {
    const s = u(), r = u(), o = u(0), e = t, I = m(() => e.emptyText || Y("暂无数据")), c = m(() => ({ label: "name", children: "children", disabled: "disabled", ...e.props, value: e.nodeKey })), O = m(() => e != null && e.height ? e.height + "px" : "100%"), R = m(() => e != null && e.height ? e.height : o.value), V = (n, l) => l[c.value.label].toLowerCase().includes(n.toLowerCase()), M = m(() => (e == null ? void 0 : e.filterMethod) ?? V), S = () => {
      if (e.data && e.data.length) {
        const l = z(e.data, c.value.children, !1).filter((i) => i[c.value.children] && i[c.value.children].length).map((i) => i[e.nodeKey]);
        G(() => {
          var i;
          (i = r.value) == null || i.setExpandedKeys(l);
        });
      }
    };
    h(
      () => e.defaultExpandAll,
      (n) => {
        n && S();
      },
      { immediate: !0 }
    ), h(
      () => e.data,
      (n, l) => {
        if (!e.defaultExpandAll) return;
        const i = n && n.length ? n : [], p = l && l.length ? l : [], w = z(i).map((N) => N[e.nodeKey]), F = z(p).map((N) => N[e.nodeKey]);
        p.length && JSON.stringify(w) === JSON.stringify(F) || S();
      }
    );
    const C = u(!1);
    h(
      () => e.data,
      (n) => {
        if (n && n.length) {
          const l = n.find(
            (i) => i[c.value.children] && i[c.value.children].length
          );
          C.value = !l;
        } else
          C.value = !1;
      },
      { immediate: !0, deep: !0 }
    );
    const b = u();
    return W(() => {
      b.value = ne(
        (n) => {
          o.value = n.height;
        },
        s.value.parentElement
      );
    }), U(() => {
      b.value.disconnect();
    }), a({
      treeRef: r
    }), (n, l) => (d(), f(
      "div",
      {
        ref_key: "cotainerRef",
        ref: s,
        class: "das-ui-tree das-ui-virtual-tree",
        style: j({ height: O.value })
      },
      [
        t.data && t.data.length ? (d(), T($(X), L({
          key: 0,
          ref_key: "treeRef",
          ref: r,
          data: t.data,
          class: { "is-root-all-left": C.value },
          icon: ke,
          props: c.value,
          "show-checkbox": !1,
          "expand-on-click-node": t.expandOnClickNode,
          height: R.value,
          "item-size": 32,
          "default-expand-all": "",
          "filter-method": M.value,
          "empty-text": I.value
        }, n.$attrs), {
          default: g(({ node: i, data: p }) => [
            x(n.$slots, "default", {
              node: i,
              data: p
            }, () => [
              v(
                "div",
                Ce,
                B(p[c.value.label]),
                1
                /* TEXT */
              )
            ])
          ]),
          _: 3
          /* FORWARDED */
        }, 16, ["data", "class", "props", "expand-on-click-node", "height", "filter-method", "empty-text"])) : (d(), f(
          E,
          { key: 1 },
          [
            D(" 空状态 "),
            t.loading ? (d(), f(
              E,
              { key: 1 },
              [
                D(" 加载状态 "),
                K(xe, {
                  size: "small",
                  spinning: t.loading
                }, {
                  default: g(() => [...l[0] || (l[0] = [
                    v(
                      "div",
                      { style: { width: "100%", height: "100%" } },
                      null,
                      -1
                      /* CACHED */
                    )
                  ])]),
                  _: 1
                  /* STABLE */
                }, 8, ["spinning"])
              ],
              2112
              /* STABLE_FRAGMENT, DEV_ROOT_FRAGMENT */
            )) : (d(), T(le, {
              key: 0,
              "empty-text": I.value
            }, q({
              _: 2
              /* DYNAMIC */
            }, [
              n.$slots["empty-text"] ? {
                name: "default",
                fn: g(() => [
                  x(n.$slots, "empty-text")
                ]),
                key: "0"
              } : void 0
            ]), 1032, ["empty-text"]))
          ],
          64
          /* STABLE_FRAGMENT */
        ))
      ],
      4
      /* STYLE */
    ));
  }
}), ze = { 暂无数据: { "zh-CN": "暂无数据", en: "No Data", "zh-MO": "暫無數據", _appCode: "framework" } };
Z(ze);
const Ve = Q(Ne), Me = () => u(null), we = { title: "virtual-tree 虚拟树" };
export {
  Ve as DasVirtualTree,
  Me as DasVirtualTreeRef,
  we as default
};
