import { warningOnce as m } from "../../../rc-util/es/warning.mjs";
import C from "./keyUtil.mjs";
function K(p, d) {
  var c = /* @__PURE__ */ new Set();
  return p.forEach(function(f) {
    d.has(f) || c.add(f);
  }), c;
}
function g(p) {
  var d = p || {}, c = d.disabled, f = d.disableCheckbox, r = d.checkable;
  return !!(c || f) || r === !1;
}
function E(p, d, c, f) {
  for (var r = new Set(p), o = /* @__PURE__ */ new Set(), i = 0; i <= c; i += 1) {
    var k = d.get(i) || /* @__PURE__ */ new Set();
    k.forEach(function(a) {
      var e = a.key, n = a.node, l = a.children, h = l === void 0 ? [] : l;
      r.has(e) && !f(n) && h.filter(function(t) {
        return !f(t.node);
      }).forEach(function(t) {
        r.add(t.key);
      });
    });
  }
  for (var s = /* @__PURE__ */ new Set(), v = c; v >= 0; v -= 1) {
    var u = d.get(v) || /* @__PURE__ */ new Set();
    u.forEach(function(a) {
      var e = a.parent, n = a.node;
      if (!(f(n) || !a.parent || s.has(a.parent.key))) {
        if (f(a.parent.node)) {
          s.add(e.key);
          return;
        }
        var l = !0, h = !1;
        (e.children || []).filter(function(t) {
          return !f(t.node);
        }).forEach(function(t) {
          var y = t.key, w = r.has(y);
          l && !w && (l = !1), !h && (w || o.has(y)) && (h = !0);
        }), l && r.add(e.key), h && o.add(e.key), s.add(e.key);
      }
    });
  }
  return {
    checkedKeys: Array.from(r),
    halfCheckedKeys: Array.from(K(o, r))
  };
}
function A(p, d, c, f, r) {
  for (var o = new Set(p), i = new Set(d), k = 0; k <= f; k += 1) {
    var s = c.get(k) || /* @__PURE__ */ new Set();
    s.forEach(function(e) {
      var n = e.key, l = e.node, h = e.children, t = h === void 0 ? [] : h;
      !o.has(n) && !i.has(n) && !r(l) && t.filter(function(y) {
        return !r(y.node);
      }).forEach(function(y) {
        o.delete(y.key);
      });
    });
  }
  i = /* @__PURE__ */ new Set();
  for (var v = /* @__PURE__ */ new Set(), u = f; u >= 0; u -= 1) {
    var a = c.get(u) || /* @__PURE__ */ new Set();
    a.forEach(function(e) {
      var n = e.parent, l = e.node;
      if (!(r(l) || !e.parent || v.has(e.parent.key))) {
        if (r(e.parent.node)) {
          v.add(n.key);
          return;
        }
        var h = !0, t = !1;
        (n.children || []).filter(function(y) {
          return !r(y.node);
        }).forEach(function(y) {
          var w = y.key, S = o.has(w);
          h && !S && (h = !1), !t && (S || i.has(w)) && (t = !0);
        }), h || o.delete(n.key), t && i.add(n.key), v.add(n.key);
      }
    });
  }
  return {
    checkedKeys: Array.from(o),
    halfCheckedKeys: Array.from(K(i, o))
  };
}
function b(p, d, c, f) {
  var r = [], o;
  f ? o = f : o = g;
  var i = new Set(p.filter(function(u) {
    var a = !!C(c, u);
    return a || r.push(u), a;
  })), k = /* @__PURE__ */ new Map(), s = 0;
  Object.keys(c).forEach(function(u) {
    var a = c[u], e = a.level, n = k.get(e);
    n || (n = /* @__PURE__ */ new Set(), k.set(e, n)), n.add(a), s = Math.max(s, e);
  }), m(!r.length, "Tree missing follow keys: ".concat(r.slice(0, 100).map(function(u) {
    return "'".concat(u, "'");
  }).join(", ")));
  var v;
  return d === !0 ? v = E(i, k, s, o) : v = A(i, d.halfCheckedKeys, k, s, o), v;
}
export {
  b as conductCheck,
  g as isCheckDisabled
};
