import { n as x, d as w, ac as M, aS as F, o as G, aT as $ } from "./index2.js";
import { ref as z, shallowRef as B, watchEffect as R } from "vue";
function ee(e, t) {
  if (!e) return [];
  const o = e.slice(), n = o.indexOf(t);
  return n >= 0 && o.splice(n, 1), o;
}
function te(e, t) {
  const o = (e || []).slice();
  return o.indexOf(t) === -1 && o.push(t), o;
}
function j(e) {
  return e.split("-");
}
function _(e, t) {
  return `${e}-${t}`;
}
function U(e) {
  return e && e.type && e.type.isTreeNode;
}
function ne(e, t) {
  const o = [], n = t[e];
  function r() {
    (arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : []).forEach((f) => {
      let {
        key: c,
        children: u
      } = f;
      o.push(c), r(u);
    });
  }
  return r(n.children), o;
}
function V(e) {
  if (e.parent) {
    const t = j(e.pos);
    return Number(t[t.length - 1]) === e.parent.children.length - 1;
  }
  return !1;
}
function W(e) {
  const t = j(e.pos);
  return Number(t[t.length - 1]) === 0;
}
function re(e, t, o, n, r, s, f, c, u, l) {
  var a;
  const {
    clientX: i,
    clientY: d
  } = e, {
    top: p,
    height: h
  } = e.target.getBoundingClientRect(), g = ((l === "rtl" ? -1 : 1) * (((r == null ? void 0 : r.x) || 0) - i) - 12) / n;
  let y = c[o.eventKey];
  if (d < p + h / 2) {
    const N = f.findIndex((D) => D.key === y.key), E = N <= 0 ? 0 : N - 1, L = f[E].key;
    y = c[L];
  }
  const k = y.key, b = y, m = y.key;
  let K = 0, C = 0;
  if (!u.has(k))
    for (let N = 0; N < g && V(y); N += 1)
      y = y.parent, C += 1;
  const S = t.eventData, O = y.node;
  let P = !0;
  return W(y) && y.level === 0 && d < p + h / 2 && s({
    dragNode: S,
    dropNode: O,
    dropPosition: -1
  }) && y.key === o.eventKey ? K = -1 : (b.children || []).length && u.has(m) ? s({
    dragNode: S,
    dropNode: O,
    dropPosition: 0
  }) ? K = 0 : P = !1 : C === 0 ? g > -1.5 ? s({
    dragNode: S,
    dropNode: O,
    dropPosition: 1
  }) ? K = 1 : P = !1 : s({
    dragNode: S,
    dropNode: O,
    dropPosition: 0
  }) ? K = 0 : s({
    dragNode: S,
    dropNode: O,
    dropPosition: 1
  }) ? K = 1 : P = !1 : s({
    dragNode: S,
    dropNode: O,
    dropPosition: 1
  }) ? K = 1 : P = !1, {
    dropPosition: K,
    dropLevelOffset: C,
    dropTargetKey: y.key,
    dropTargetPos: y.pos,
    dragOverNodeKey: m,
    dropContainerKey: K === 0 ? null : ((a = y.parent) === null || a === void 0 ? void 0 : a.key) || null,
    dropAllowed: P
  };
}
function oe(e, t) {
  if (!e) return;
  const {
    multiple: o
  } = t;
  return o ? e.slice() : e.length ? [e[0]] : e;
}
function se(e) {
  if (!e)
    return null;
  let t;
  if (Array.isArray(e))
    t = {
      checkedKeys: e,
      halfCheckedKeys: void 0
    };
  else if (typeof e == "object")
    t = {
      checkedKeys: e.checked || void 0,
      halfCheckedKeys: e.halfChecked || void 0
    };
  else
    return x(!1, "`checkedKeys` is not an array or an object"), null;
  return t;
}
function ie(e, t) {
  const o = /* @__PURE__ */ new Set();
  function n(r) {
    if (o.has(r)) return;
    const s = t[r];
    if (!s) return;
    o.add(r);
    const {
      parent: f,
      node: c
    } = s;
    c.disabled || f && n(f.key);
  }
  return (e || []).forEach((r) => {
    n(r);
  }), [...o];
}
var X = function(e, t) {
  var o = {};
  for (var n in e) Object.prototype.hasOwnProperty.call(e, n) && t.indexOf(n) < 0 && (o[n] = e[n]);
  if (e != null && typeof Object.getOwnPropertySymbols == "function") for (var r = 0, n = Object.getOwnPropertySymbols(e); r < n.length; r++)
    t.indexOf(n[r]) < 0 && Object.prototype.propertyIsEnumerable.call(e, n[r]) && (o[n[r]] = e[n[r]]);
  return o;
};
function T(e, t) {
  return e != null ? e : t;
}
function A(e) {
  const {
    title: t,
    _title: o,
    key: n,
    children: r
  } = e || {}, s = t || "title";
  return {
    title: s,
    _title: o || [s],
    key: n || "key",
    children: r || "children"
  };
}
function ae(e) {
  function t() {
    let o = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
    return M(o).map((r) => {
      var s, f, c, u;
      if (!U(r))
        return x(!r, "Tree/TreeNode can only accept TreeNode as children."), null;
      const l = r.children || {}, a = r.key, i = {};
      for (const [N, E] of Object.entries(r.props))
        i[F(N)] = E;
      const {
        isLeaf: d,
        checkable: p,
        selectable: h,
        disabled: v,
        disableCheckbox: g
      } = i, y = {
        isLeaf: d || d === "" || void 0,
        checkable: p || p === "" || void 0,
        selectable: h || h === "" || void 0,
        disabled: v || v === "" || void 0,
        disableCheckbox: g || g === "" || void 0
      }, k = w(w({}, i), y), {
        title: b = (s = l.title) === null || s === void 0 ? void 0 : s.call(l, k),
        icon: m = (f = l.icon) === null || f === void 0 ? void 0 : f.call(l, k),
        switcherIcon: K = (c = l.switcherIcon) === null || c === void 0 ? void 0 : c.call(l, k)
      } = i, C = X(i, ["title", "icon", "switcherIcon"]), S = (u = l.default) === null || u === void 0 ? void 0 : u.call(l), O = w(w(w({}, C), {
        title: b,
        icon: m,
        switcherIcon: K,
        key: a,
        isLeaf: d
      }), y), P = t(S);
      return P.length && (O.children = P), O;
    });
  }
  return t(e);
}
function le(e, t, o) {
  const {
    _title: n,
    key: r,
    children: s
  } = A(o), f = new Set(t === !0 ? [] : t), c = [];
  function u(l) {
    let a = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : null;
    return l.map((i, d) => {
      const p = _(a ? a.pos : "0", d), h = T(i[r], p);
      let v;
      for (let y = 0; y < n.length; y += 1) {
        const k = n[y];
        if (i[k] !== void 0) {
          v = i[k];
          break;
        }
      }
      const g = w(w({}, G(i, [...n, r, s])), {
        title: v,
        key: h,
        parent: a,
        pos: p,
        children: null,
        data: i,
        isStart: [...a ? a.isStart : [], d === 0],
        isEnd: [...a ? a.isEnd : [], d === l.length - 1]
      });
      return c.push(g), t === !0 || f.has(h) ? g.children = u(i[s] || [], g) : g.children = [], g;
    });
  }
  return u(e), c;
}
function Y(e, t, o) {
  let n = {};
  typeof o == "object" ? n = o : n = {
    externalGetKey: o
  }, n = n || {};
  const {
    childrenPropName: r,
    externalGetKey: s,
    fieldNames: f
  } = n, {
    key: c,
    children: u
  } = A(f), l = r || u;
  let a;
  s ? typeof s == "string" ? a = (d) => d[s] : typeof s == "function" && (a = (d) => s(d)) : a = (d, p) => T(d[c], p);
  function i(d, p, h, v) {
    const g = d ? d[l] : e, y = d ? _(h.pos, p) : "0", k = d ? [...v, d] : [];
    if (d) {
      const b = a(d, y), m = {
        node: d,
        index: p,
        pos: y,
        key: b,
        parentPos: h.node ? h.pos : null,
        level: h.level + 1,
        nodes: k
      };
      t(m);
    }
    g && g.forEach((b, m) => {
      i(b, m, {
        node: d,
        pos: y,
        level: h ? h.level + 1 : -1
      }, k);
    });
  }
  i(null);
}
function ce(e) {
  let {
    initWrapper: t,
    processEntity: o,
    onProcessFinished: n,
    externalGetKey: r,
    childrenPropName: s,
    fieldNames: f
  } = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}, c = arguments.length > 2 ? arguments[2] : void 0;
  const u = r || c, l = {}, a = {};
  let i = {
    posEntities: l,
    keyEntities: a
  };
  return t && (i = t(i) || i), Y(e, (d) => {
    const {
      node: p,
      index: h,
      pos: v,
      key: g,
      parentPos: y,
      level: k,
      nodes: b
    } = d, m = {
      node: p,
      nodes: b,
      index: h,
      key: g,
      pos: v,
      level: k
    }, K = T(g, v);
    l[v] = m, a[K] = m, m.parent = l[y], m.parent && (m.parent.children = m.parent.children || [], m.parent.children.push(m)), o && o(m, i);
  }, {
    externalGetKey: u,
    childrenPropName: s,
    fieldNames: f
  }), n && n(i), i;
}
function de(e, t) {
  let {
    expandedKeysSet: o,
    selectedKeysSet: n,
    loadedKeysSet: r,
    loadingKeysSet: s,
    checkedKeysSet: f,
    halfCheckedKeysSet: c,
    dragOverNodeKey: u,
    dropPosition: l,
    keyEntities: a
  } = t;
  const i = a[e];
  return {
    eventKey: e,
    expanded: o.has(e),
    selected: n.has(e),
    loaded: r.has(e),
    loading: s.has(e),
    checked: f.has(e),
    halfChecked: c.has(e),
    pos: String(i ? i.pos : ""),
    parent: i.parent,
    // [Legacy] Drag props
    // Since the interaction of drag is changed, the semantic of the props are
    // not accuracy, I think it should be finally removed
    dragOver: u === e && l === 0,
    dragOverGapTop: u === e && l === -1,
    dragOverGapBottom: u === e && l === 1
  };
}
function fe(e) {
  const {
    data: t,
    expanded: o,
    selected: n,
    checked: r,
    loaded: s,
    loading: f,
    halfChecked: c,
    dragOver: u,
    dragOverGapTop: l,
    dragOverGapBottom: a,
    pos: i,
    active: d,
    eventKey: p
  } = e, h = w(w({
    dataRef: t
  }, t), {
    expanded: o,
    selected: n,
    checked: r,
    loaded: s,
    loading: f,
    halfChecked: c,
    dragOver: u,
    dragOverGapTop: l,
    dragOverGapBottom: a,
    pos: i,
    active: d,
    eventKey: p,
    key: p
  });
  return "props" in h || Object.defineProperty(h, "props", {
    get() {
      return x(!1, "Second param return from event is node data instead of TreeNode instance. Please read value directly instead of reading from `props`."), e;
    }
  }), h;
}
function I(e, t) {
  const o = /* @__PURE__ */ new Set();
  return e.forEach((n) => {
    t.has(n) || o.add(n);
  }), o;
}
function q(e) {
  const {
    disabled: t,
    disableCheckbox: o,
    checkable: n
  } = e || {};
  return !!(t || o) || n === !1;
}
function H(e, t, o, n) {
  const r = new Set(e), s = /* @__PURE__ */ new Set();
  for (let c = 0; c <= o; c += 1)
    (t.get(c) || /* @__PURE__ */ new Set()).forEach((l) => {
      const {
        key: a,
        node: i,
        children: d = []
      } = l;
      r.has(a) && !n(i) && d.filter((p) => !n(p.node)).forEach((p) => {
        r.add(p.key);
      });
    });
  const f = /* @__PURE__ */ new Set();
  for (let c = o; c >= 0; c -= 1)
    (t.get(c) || /* @__PURE__ */ new Set()).forEach((l) => {
      const {
        parent: a,
        node: i
      } = l;
      if (n(i) || !l.parent || f.has(l.parent.key))
        return;
      if (n(l.parent.node)) {
        f.add(a.key);
        return;
      }
      let d = !0, p = !1;
      (a.children || []).filter((h) => !n(h.node)).forEach((h) => {
        let {
          key: v
        } = h;
        const g = r.has(v);
        d && !g && (d = !1), !p && (g || s.has(v)) && (p = !0);
      }), d && r.add(a.key), p && s.add(a.key), f.add(a.key);
    });
  return {
    checkedKeys: Array.from(r),
    halfCheckedKeys: Array.from(I(s, r))
  };
}
function J(e, t, o, n, r) {
  const s = new Set(e);
  let f = new Set(t);
  for (let u = 0; u <= n; u += 1)
    (o.get(u) || /* @__PURE__ */ new Set()).forEach((a) => {
      const {
        key: i,
        node: d,
        children: p = []
      } = a;
      !s.has(i) && !f.has(i) && !r(d) && p.filter((h) => !r(h.node)).forEach((h) => {
        s.delete(h.key);
      });
    });
  f = /* @__PURE__ */ new Set();
  const c = /* @__PURE__ */ new Set();
  for (let u = n; u >= 0; u -= 1)
    (o.get(u) || /* @__PURE__ */ new Set()).forEach((a) => {
      const {
        parent: i,
        node: d
      } = a;
      if (r(d) || !a.parent || c.has(a.parent.key))
        return;
      if (r(a.parent.node)) {
        c.add(i.key);
        return;
      }
      let p = !0, h = !1;
      (i.children || []).filter((v) => !r(v.node)).forEach((v) => {
        let {
          key: g
        } = v;
        const y = s.has(g);
        p && !y && (p = !1), !h && (y || f.has(g)) && (h = !0);
      }), p || s.delete(i.key), h && f.add(i.key), c.add(i.key);
    });
  return {
    checkedKeys: Array.from(s),
    halfCheckedKeys: Array.from(I(f, s))
  };
}
function ue(e, t, o, n, r, s) {
  const f = [];
  let c;
  s ? c = s : c = q;
  const u = new Set(e.filter((a) => {
    const i = !!o[a];
    return i || f.push(a), i;
  }));
  $(!f.length, `Tree missing follow keys: ${f.slice(0, 100).map((a) => `'${a}'`).join(", ")}`);
  let l;
  return t === !0 ? l = H(u, r, n, c) : l = J(u, t.halfCheckedKeys, r, n, c), l;
}
function he(e) {
  const t = z(0), o = B();
  return R(() => {
    const n = /* @__PURE__ */ new Map();
    let r = 0;
    const s = e.value || {};
    for (const f in s)
      if (Object.prototype.hasOwnProperty.call(s, f)) {
        const c = s[f], {
          level: u
        } = c;
        let l = n.get(u);
        l || (l = /* @__PURE__ */ new Set(), n.set(u, l)), l.add(c), r = Math.max(r, u);
      }
    t.value = r, o.value = n;
  }), {
    maxLevel: t,
    levelEntities: o
  };
}
export {
  ue as a,
  ee as b,
  ce as c,
  te as d,
  ae as e,
  A as f,
  ie as g,
  de as h,
  fe as i,
  T as j,
  le as k,
  oe as l,
  ne as m,
  re as n,
  j as o,
  se as p,
  he as u
};
