import B from "../../@babel/runtime/helpers/esm/toConsumableArray.mjs";
import S from "../../@babel/runtime/helpers/esm/typeof.mjs";
import { warningOnce as X } from "../../rc-util/es/warning.mjs";
import "react";
import "./TreeNode.mjs";
import v from "./utils/keyUtil.mjs";
import "../../rc-util/node_modules/react-is/index.mjs";
function H(e, r) {
  if (!e)
    return [];
  var n = e.slice(), a = n.indexOf(r);
  return a >= 0 && n.splice(a, 1), n;
}
function I(e, r) {
  var n = (e || []).slice();
  return n.indexOf(r) === -1 && n.push(r), n;
}
function P(e) {
  return e.split("-");
}
function J(e, r) {
  var n = [], a = v(r, e);
  function i() {
    var o = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
    o.forEach(function(d) {
      var l = d.key, s = d.children;
      n.push(l), i(s);
    });
  }
  return i(a.children), n;
}
function Y(e) {
  if (e.parent) {
    var r = P(e.pos);
    return Number(r[r.length - 1]) === e.parent.children.length - 1;
  }
  return !1;
}
function $(e) {
  var r = P(e.pos);
  return Number(r[r.length - 1]) === 0;
}
function Q(e, r, n, a, i, o, d, l, s, A) {
  var h, D = e.clientX, y = e.clientY, m = e.target.getBoundingClientRect(), N = m.top, b = m.height, x = (A === "rtl" ? -1 : 1) * (((i == null ? void 0 : i.x) || 0) - D), k = (x - 12) / a, t = v(l, n.props.eventKey);
  if (y < N + b / 2) {
    var K = d.findIndex(function(j) {
      return j.key === t.key;
    }), E = K <= 0 ? 0 : K - 1, L = d[E].key;
    t = v(l, L);
  }
  var T = t.key, _ = t, C = t.key, f = 0, g = 0;
  if (!s.includes(T))
    for (var O = 0; O < k && Y(t); O += 1)
      t = t.parent, g += 1;
  var u = r.props.data, c = t.node, p = !0;
  return $(t) && t.level === 0 && y < N + b / 2 && o({
    dragNode: u,
    dropNode: c,
    dropPosition: -1
  }) && t.key === n.props.eventKey ? f = -1 : (_.children || []).length && s.includes(C) ? o({
    dragNode: u,
    dropNode: c,
    dropPosition: 0
  }) ? f = 0 : p = !1 : g === 0 ? k > -1.5 ? o({
    dragNode: u,
    dropNode: c,
    dropPosition: 1
  }) ? f = 1 : p = !1 : o({
    dragNode: u,
    dropNode: c,
    dropPosition: 0
  }) ? f = 0 : o({
    dragNode: u,
    dropNode: c,
    dropPosition: 1
  }) ? f = 1 : p = !1 : o({
    dragNode: u,
    dropNode: c,
    dropPosition: 1
  }) ? f = 1 : p = !1, {
    dropPosition: f,
    dropLevelOffset: g,
    dropTargetKey: t.key,
    dropTargetPos: t.pos,
    dragOverNodeKey: C,
    dropContainerKey: f === 0 ? null : ((h = t.parent) === null || h === void 0 ? void 0 : h.key) || null,
    dropAllowed: p
  };
}
function V(e, r) {
  if (e) {
    var n = r.multiple;
    return n ? e.slice() : e.length ? [e[0]] : e;
  }
}
function W(e) {
  if (!e)
    return null;
  var r;
  if (Array.isArray(e))
    r = {
      checkedKeys: e,
      halfCheckedKeys: void 0
    };
  else if (S(e) === "object")
    r = {
      checkedKeys: e.checked || void 0,
      halfCheckedKeys: e.halfChecked || void 0
    };
  else
    return X(!1, "`checkedKeys` is not an array or an object"), null;
  return r;
}
function Z(e, r) {
  var n = /* @__PURE__ */ new Set();
  function a(i) {
    if (!n.has(i)) {
      var o = v(r, i);
      if (o) {
        n.add(i);
        var d = o.parent, l = o.node;
        l.disabled || d && a(d.key);
      }
    }
  }
  return (e || []).forEach(function(i) {
    a(i);
  }), B(n);
}
export {
  I as arrAdd,
  H as arrDel,
  Q as calcDropPosition,
  V as calcSelectedKeys,
  Z as conductExpandParent,
  J as getDragChildrenKeys,
  $ as isFirstChild,
  Y as isLastChild,
  W as parseCheckedKeys,
  P as posToArr
};
