import _ from "../../../@babel/runtime/helpers/esm/defineProperty.mjs";
import y from "../../../@babel/runtime/helpers/esm/objectSpread2.mjs";
import E from "../../../@babel/runtime/helpers/esm/toConsumableArray.mjs";
import * as F from "react";
var b = "__rc_cascader_search_mark__", L = function(l, r, a) {
  var e = a.label;
  return r.some(function(i) {
    return String(i[e]).toLowerCase().includes(l.toLowerCase());
  });
}, M = function(l, r, a, e) {
  return r.map(function(i) {
    return i[e.label];
  }).join(" / ");
};
const x = function(n, l, r, a, e, i) {
  var g = e.filter, h = g === void 0 ? L : g, p = e.render, R = p === void 0 ? M : p, C = e.limit, t = C === void 0 ? 50 : C, d = e.sort;
  return F.useMemo(function() {
    var u = [];
    if (!n)
      return [];
    function A(s, v) {
      var D = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : !1;
      s.forEach(function(f) {
        if (!(!d && t !== !1 && t > 0 && u.length >= t)) {
          var c = [].concat(E(v), [f]), m = f[r.children], w = D || f.disabled;
          if (
            // If is leaf option
            (!m || m.length === 0 || // If is changeOnSelect
            i) && h(n, c, {
              label: r.label
            })
          ) {
            var o;
            u.push(y(y({}, f), {}, (o = {
              disabled: w
            }, _(o, r.label, R(n, c, a, r)), _(o, b, c), _(o, r.children, void 0), o)));
          }
          m && A(f[r.children], c, w);
        }
      });
    }
    return A(l, []), d && u.sort(function(s, v) {
      return d(s[b], v[b], n, r);
    }), t !== !1 && t > 0 ? u.slice(0, t) : u;
  }, [n, l, r, a, R, i, h, d, t]);
};
export {
  b as SEARCH_MARK,
  x as default
};
