/**
 * tdesign v0.41.7
 * (c) 2022 tdesign
 * @license MIT
 */

'use strict';

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

var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
var cascader_utils_helper = require('./helper.js');
require('@babel/runtime/helpers/typeof');
require('lodash/isEmpty');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var _slicedToArray__default = /*#__PURE__*/_interopDefaultLegacy(_slicedToArray);

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

  if (inputVal) {
    nodes = treeStore.nodes.filter(function (node) {
      var fullPathLabel = cascader_utils_helper.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 = cascader_utils_helper.getTreeValue(value);
  if (!treeStore) return;

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

    var _treeValue = _slicedToArray__default["default"](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();
};

exports.treeNodesEffect = treeNodesEffect;
exports.treeStoreExpendEffect = treeStoreExpendEffect;
//# sourceMappingURL=cascader.js.map
