import Se from "../../@babel/runtime/helpers/esm/objectDestructuringEmpty.mjs";
import _ from "../../@babel/runtime/helpers/esm/extends.mjs";
import g from "../../@babel/runtime/helpers/esm/slicedToArray.mjs";
import be from "../../@babel/runtime/helpers/esm/objectWithoutProperties.mjs";
import xe from "../../rc-util/es/hooks/useLayoutEffect.mjs";
import Ce from "../../rc-virtual-list/es/List.mjs";
import * as a from "react";
import _e from "./MotionTreeNode.mjs";
import { findExpandedKeys as Me, getExpandRange as B } from "./utils/diffUtil.mjs";
import { getTreeNodeProps as Ie, getKey as Y } from "./utils/treeUtil.mjs";
var Pe = ["prefixCls", "data", "selectable", "checkable", "expandedKeys", "selectedKeys", "checkedKeys", "loadedKeys", "loadingKeys", "halfCheckedKeys", "keyEntities", "disabled", "dragging", "dragOverNodeKey", "dropPosition", "motion", "height", "itemHeight", "virtual", "focusable", "activeItem", "focused", "tabIndex", "onKeyDown", "onFocus", "onBlur", "onActiveChange", "onListChangeStart", "onListChangeEnd"], W = {
  width: 0,
  height: 0,
  display: "flex",
  overflow: "hidden",
  opacity: 0,
  border: 0,
  padding: 0,
  margin: 0
}, Te = function() {
}, h = "RC_TREE_MOTION_".concat(Math.random()), M = {
  key: h
}, Ne = {
  key: h,
  level: 0,
  index: 0,
  pos: "0",
  node: M,
  nodes: [M]
}, j = {
  parent: null,
  children: [],
  pos: Ne.pos,
  data: M,
  title: null,
  key: h,
  /** Hold empty list here since we do not use it */
  isStart: [],
  isEnd: []
};
function q(e, o, i, n) {
  return o === !1 || !i ? e : e.slice(0, Math.ceil(i / n) + 1);
}
function V(e) {
  var o = e.key, i = e.pos;
  return Y(o, i);
}
function De(e) {
  for (var o = String(e.data.key), i = e; i.parent; )
    i = i.parent, o = "".concat(i.data.key, " > ").concat(o);
  return o;
}
var Le = /* @__PURE__ */ a.forwardRef(function(e, o) {
  var i = e.prefixCls, n = e.data;
  e.selectable, e.checkable;
  var u = e.expandedKeys, z = e.selectedKeys, G = e.checkedKeys, J = e.loadedKeys, Q = e.loadingKeys, U = e.halfCheckedKeys, X = e.keyEntities, Z = e.disabled, I = e.dragging, ee = e.dragOverNodeKey, te = e.dropPosition, P = e.motion, k = e.height, R = e.itemHeight, S = e.virtual, T = e.focusable, m = e.activeItem, ae = e.focused, ne = e.tabIndex, ie = e.onKeyDown, oe = e.onFocus, re = e.onBlur, de = e.onActiveChange, se = e.onListChangeStart, le = e.onListChangeEnd, ce = be(e, Pe), N = a.useRef(null), D = a.useRef(null);
  a.useImperativeHandle(o, function() {
    return {
      scrollTo: function(r) {
        N.current.scrollTo(r);
      },
      getIndentWidth: function() {
        return D.current.offsetWidth;
      }
    };
  });
  var ue = a.useState(u), L = g(ue, 2), fe = L[0], ye = L[1], ve = a.useState(n), $ = g(ve, 2), f = $[0], p = $[1], ge = a.useState(n), w = g(ge, 2), he = w[0], K = w[1], me = a.useState([]), O = g(me, 2), Ke = O[0], b = O[1], Ee = a.useState(null), H = g(Ee, 2), ke = H[0], x = H[1], F = a.useRef(n);
  F.current = n;
  function C() {
    var t = F.current;
    p(t), K(t), b([]), x(null), le();
  }
  xe(function() {
    ye(u);
    var t = Me(fe, u);
    if (t.key !== null)
      if (t.add) {
        var r = f.findIndex(function(y) {
          var v = y.key;
          return v === t.key;
        }), d = q(B(f, n, t.key), S, k, R), c = f.slice();
        c.splice(r + 1, 0, j), K(c), b(d), x("show");
      } else {
        var s = n.findIndex(function(y) {
          var v = y.key;
          return v === t.key;
        }), l = q(B(n, f, t.key), S, k, R), E = n.slice();
        E.splice(s + 1, 0, j), K(E), b(l), x("hide");
      }
    else
      f !== n && (p(n), K(n));
  }, [u, n]), a.useEffect(function() {
    I || C();
  }, [I]);
  var Re = P ? he : n, A = {
    expandedKeys: u,
    selectedKeys: z,
    loadedKeys: J,
    loadingKeys: Q,
    checkedKeys: G,
    halfCheckedKeys: U,
    dragOverNodeKey: ee,
    dropPosition: te,
    keyEntities: X
  };
  return /* @__PURE__ */ a.createElement(a.Fragment, null, ae && m && /* @__PURE__ */ a.createElement("span", {
    style: W,
    "aria-live": "assertive"
  }, De(m)), /* @__PURE__ */ a.createElement("div", null, /* @__PURE__ */ a.createElement("input", {
    style: W,
    disabled: T === !1 || Z,
    tabIndex: T !== !1 ? ne : null,
    onKeyDown: ie,
    onFocus: oe,
    onBlur: re,
    value: "",
    onChange: Te,
    "aria-label": "for screen reader"
  })), /* @__PURE__ */ a.createElement("div", {
    className: "".concat(i, "-treenode"),
    "aria-hidden": !0,
    style: {
      position: "absolute",
      pointerEvents: "none",
      visibility: "hidden",
      height: 0,
      overflow: "hidden",
      border: 0,
      padding: 0
    }
  }, /* @__PURE__ */ a.createElement("div", {
    className: "".concat(i, "-indent")
  }, /* @__PURE__ */ a.createElement("div", {
    ref: D,
    className: "".concat(i, "-indent-unit")
  }))), /* @__PURE__ */ a.createElement(Ce, _({}, ce, {
    data: Re,
    itemKey: V,
    height: k,
    fullHeight: !1,
    virtual: S,
    itemHeight: R,
    prefixCls: "".concat(i, "-list"),
    ref: N,
    onVisibleChange: function(r, d) {
      var c = new Set(r), s = d.filter(function(l) {
        return !c.has(l);
      });
      s.some(function(l) {
        return V(l) === h;
      }) && C();
    }
  }), function(t) {
    var r = t.pos, d = _({}, (Se(t.data), t.data)), c = t.title, s = t.key, l = t.isStart, E = t.isEnd, y = Y(s, r);
    delete d.key, delete d.children;
    var v = Ie(y, A);
    return /* @__PURE__ */ a.createElement(_e, _({}, d, v, {
      title: c,
      active: !!m && s === m.key,
      pos: r,
      data: t.data,
      isStart: l,
      isEnd: E,
      motion: P,
      motionNodes: s === h ? Ke : null,
      motionType: ke,
      onMotionStart: se,
      onMotionEnd: C,
      treeNodeRequiredProps: A,
      onMouseMove: function() {
        de(null);
      }
    }));
  }));
});
Le.displayName = "NodeList";
export {
  h as MOTION_KEY,
  Ne as MotionEntity,
  Le as default,
  q as getMinimumRangeTransitionRange
};
