'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var vue = require('vue');
var legacyUtil = require('../utils/legacyUtil.cjs');

var useFilterTreeData = (treeData, searchValue, {
  treeNodeFilterProp,
  filterTreeNode,
  fieldNames
}) => {
  return vue.computed(() => {
    const { children: fieldChildren } = fieldNames.value;
    const searchValueVal = searchValue.value;
    const treeNodeFilterPropValue = treeNodeFilterProp == null ? void 0 : treeNodeFilterProp.value;
    if (!searchValueVal || filterTreeNode.value === false)
      return treeData.value;
    let filterOptionFunc;
    if (typeof filterTreeNode.value === "function") {
      filterOptionFunc = filterTreeNode.value;
    } else {
      const upperStr = searchValueVal.toUpperCase();
      filterOptionFunc = (_, dataNode) => {
        const value = dataNode[treeNodeFilterPropValue];
        return String(value).toUpperCase().includes(upperStr);
      };
    }
    function dig(list, keepAll = false) {
      const res = [];
      for (let index = 0, len = list.length; index < len; index++) {
        const dataNode = list[index];
        const children = dataNode[fieldChildren];
        const match = keepAll || filterOptionFunc(searchValueVal, legacyUtil.fillLegacyProps(dataNode));
        const childList = dig(children || [], match);
        if (match || childList.length) {
          res.push({
            ...dataNode,
            [fieldChildren]: childList
          });
        }
      }
      return res;
    }
    return dig(treeData.value);
  });
};

exports.default = useFilterTreeData;
//# sourceMappingURL=useFilterTreeData.cjs.map
