import { forEach, isEqual, every } from 'lodash-es';
export function handleSign() {
  var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  var signData = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  return data.reduce(function (pre, item) {
    if (item == null) {
      pre.push(item);
      return pre;
    }

    if (item.sign) {
      forEach(item.sign, function (sign) {
        var filterKeys = Object.keys(sign);
        var flag = every(filterKeys, function (v, index) {
          return isEqual(sign[filterKeys[index]], signData[v]);
        });

        if (flag) {
          pre.push(item);
        }

        return !flag;
      });
      return pre;
    }

    if (item.children) {
      item.children = handleSign(item.children, signData);
    }

    pre.push(item);
    return pre;
  }, []);
}
export function treeToArray(nodes) {
  var r = [];

  if (Array.isArray(nodes)) {
    for (var i = 0, l = nodes.length; i < l; i++) {
      var _nodes$i$children;

      r.push(nodes[i]); // 取每项数据放入一个新数组

      if (nodes[i].children instanceof Array && (((_nodes$i$children = nodes[i].children) === null || _nodes$i$children === void 0 ? void 0 : _nodes$i$children.length) || 0) > 0) {
        // 若存在children则递归调用，把数据拼接到新数组中，并且删除该children
        r = r.concat(treeToArray(nodes[i].children || []));
        delete nodes[i].children;
      }
    }
  }

  return r;
}