/**
 * tdesign v0.39.1-alpha.1
 * (c) 2022 tdesign
 * @license MIT
 */

import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import { getFullPathLabel, getTreeValue } from './helper.js';
import '@babel/runtime/helpers/typeof';
import 'lodash/isEmpty';

var treeNodesEffect = function treeNodesEffect(inputVal, treeStore, setTreeNodes) {
  if (!treeStore) return;
  var nodes = [];

  if (inputVal) {
    nodes = treeStore.nodes.filter(function (node) {
      var fullPathLabel = getFullPathLabel(node);
      return fullPathLabel.indexOf(inputVal) > -1 && node.isLeaf();
    });
  } else {
    nodes = treeStore.getNodes().filter(function (node) {
      return node.visible;
    });
  }

  setTreeNodes(nodes);
};
var treeStoreExpendEffect = function treeStoreExpendEffect(treeStore, value, expend) {
  var treeValue = getTreeValue(value);
  if (!treeStore) return;

  if (Array.isArray(treeValue) && expend.length === 0) {
    var expandedMap = /* @__PURE__ */new Map();

    var _treeValue = _slicedToArray(treeValue, 1),
        val = _treeValue[0];

    if (val) {
      expandedMap.set(val, true);
      var node = treeStore.getNode(val);

      if (!node) {
        treeStore.refreshNodes();
        return;
      }

      node.getParents().forEach(function (tn) {
        expandedMap.set(tn.value, true);
      });
      var expandedArr = Array.from(expandedMap.keys());
      treeStore.replaceExpanded(expandedArr);
    } else {
      treeStore.resetExpanded();
    }
  }

  if (treeStore.getExpanded() && expend.length) {
    treeStore.replaceExpanded(expend);
  }

  treeStore.refreshNodes();
};

export { treeNodesEffect, treeStoreExpendEffect };
//# sourceMappingURL=cascader.js.map
