import '@das-fed/ui/packages/components/virtual-tree/style.css';
import { defineComponent as I, createBlock as k, openBlock as r, unref as h, ref as i, computed as c, watch as g, onMounted as O, onBeforeUnmount as F, createElementBlock as v, normalizeStyle as M, mergeProps as V, withCtx as x, renderSlot as T, createElementVNode as D, toDisplayString as $, Fragment as b, createCommentVNode as B, createSlots as H, createVNode as L, nextTick as J } from "vue";
import { withInstall as P } from "@das-fed/utils/with-install/index";
import { ElTreeV2 as W } from "element-plus";
import "element-plus/es/components/tree-v2/style/css";
import { t as U, setI18nRule as j } from "@das-fed/web/packages/i18n/index";
import { DasTreeEmpty as q } from "@das-fed/ui/packages/components/tree/index";
import { DasSpin as G } from "@das-fed/ui/packages/components/spin/index";
import { DasIconCaretRight as Q } from "@das-fed/ui/packages/icons/caret-right/index";
import { SizeWatcher as X } from "@das-fed/utils/size-watcher";
import { flatTree as _ } from "@das-fed/utils/common-tools";
const Y = /* @__PURE__ */ I({
  __name: "expand-icon",
  setup(s) {
    return (f, o) => (r(), k(h(Q), {
      class: "das-tree__expand-icon",
      size: "medium"
    }));
  }
}), Z = (s, f) => {
  const o = s.__vccOpts || s;
  for (const [d, p] of f)
    o[d] = p;
  return o;
}, ee = /* @__PURE__ */ Z(Y, [["__scopeId", "data-v-d51f7d20"]]), te = { class: "tree-normal-node" }, ae = {
  name: "DasVirtualTree",
  inheritAttrs: !1
}, ne = /* @__PURE__ */ I({
  ...ae,
  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(s, { expose: f }) {
    const o = i(), d = i(), p = i(0), t = s, C = c(() => t.emptyText || U("暂无数据")), l = c(() => ({ label: "name", children: "children", disabled: "disabled", ...t.props, value: t.nodeKey })), S = c(() => t != null && t.height ? t.height + "px" : "100%"), w = c(() => t != null && t.height ? t.height : p.value), z = (e, n) => n[l.value.label].toLowerCase().includes(e.toLowerCase()), K = c(() => (t == null ? void 0 : t.filterMethod) ?? z), N = () => {
      if (t.data && t.data.length) {
        const n = _(t.data, l.value.children, !1).filter((a) => a[l.value.children] && a[l.value.children].length).map((a) => a[t.nodeKey]);
        J(() => {
          var a;
          (a = d.value) == null || a.setExpandedKeys(n);
        });
      }
    };
    g(
      () => t.defaultExpandAll,
      (e) => {
        e && N();
      },
      { immediate: !0 }
    ), g(
      () => t.data,
      (e, n) => {
        if (!t.defaultExpandAll) return;
        const a = e && e.length ? e : [], u = n && n.length ? n : [], R = _(a).map((y) => y[t.nodeKey]), A = _(u).map((y) => y[t.nodeKey]);
        u.length && JSON.stringify(R) === JSON.stringify(A) || N();
      }
    );
    const m = i(!1);
    g(
      () => t.data,
      (e) => {
        if (e && e.length) {
          const n = e.find(
            (a) => a[l.value.children] && a[l.value.children].length
          );
          m.value = !n;
        } else
          m.value = !1;
      },
      { immediate: !0, deep: !0 }
    );
    const E = i();
    return O(() => {
      E.value = X(
        (e) => {
          p.value = e.height;
        },
        o.value.parentElement
      );
    }), F(() => {
      E.value.disconnect();
    }), f({
      treeRef: d
    }), (e, n) => (r(), v(
      "div",
      {
        ref_key: "cotainerRef",
        ref: o,
        class: "das-ui-tree das-ui-virtual-tree",
        style: M({ height: S.value })
      },
      [
        e.data && e.data.length ? (r(), k(h(W), V({
          key: 0,
          ref_key: "treeRef",
          ref: d,
          data: e.data,
          class: { "is-root-all-left": m.value },
          icon: ee,
          props: l.value,
          "show-checkbox": !1,
          "expand-on-click-node": e.expandOnClickNode,
          height: w.value,
          "item-size": 32,
          "default-expand-all": "",
          "filter-method": K.value,
          "empty-text": C.value
        }, e.$attrs), {
          default: x(({ node: a, data: u }) => [
            T(e.$slots, "default", {
              node: a,
              data: u
            }, () => [
              D(
                "div",
                te,
                $(u[l.value.label]),
                1
                /* TEXT */
              )
            ])
          ]),
          _: 3
          /* FORWARDED */
        }, 16, ["data", "class", "props", "expand-on-click-node", "height", "filter-method", "empty-text"])) : (r(), v(
          b,
          { key: 1 },
          [
            B(" 空状态 "),
            e.loading ? (r(), v(
              b,
              { key: 1 },
              [
                B(" 加载状态 "),
                L(h(G), {
                  size: "small",
                  spinning: e.loading
                }, {
                  default: x(() => n[0] || (n[0] = [
                    D(
                      "div",
                      { style: { width: "100%", height: "100%" } },
                      null,
                      -1
                      /* HOISTED */
                    )
                  ])),
                  _: 1
                  /* STABLE */
                }, 8, ["spinning"])
              ],
              2112
              /* STABLE_FRAGMENT, DEV_ROOT_FRAGMENT */
            )) : (r(), k(h(q), {
              key: 0,
              "empty-text": C.value
            }, H({
              _: 2
              /* DYNAMIC */
            }, [
              e.$slots["empty-text"] ? {
                name: "default",
                fn: x(() => [
                  T(e.$slots, "empty-text")
                ]),
                key: "0"
              } : void 0
            ]), 1032, ["empty-text"]))
          ],
          64
          /* STABLE_FRAGMENT */
        ))
      ],
      4
      /* STYLE */
    ));
  }
}), le = { 暂无数据: { "zh-CN": "暂无数据", en: "No Data", _appCode: "framework" } };
j(le);
const me = P(ne), ye = () => i(null), ge = { title: "virtual-tree 虚拟树" };
export {
  me as DasVirtualTree,
  ye as DasVirtualTreeRef,
  ge as default
};
