/**
 * 递归函数，返回符合集合
 * @category 数组
 * @function recursionGet
 * @returns  {array} 符合条件的数组
 * @static
 * @author hht
 * @param {string}} value 查找的值.
 * @param {array} data 所有树节点数据。
 *
 * @example example 01 匹配子节点
 * --------------------------------------------------------------------------
 * import { recursionGet } from "@riil-frontend/utils";
 * const array = [
 *  {
 *    label: '网络设备',
 *    id: 'network',
 *    icon: 'network',
 *    children: [
 *      {
 *        label: '交换机',
 *        id: 'switch',
 *        icon: 'switch',
 *        children: null,
 *      },
 *      {
 *        label: '锐捷交换机',
 *        id: 'ruijieSwitch',
 *        icon: 'ruijieSwitch',
 *        children: null,
 *      },
 *      {
 *        label: '路由器',
 *        id: 'router',
 *        icon: 'router',
 *        children: null,
 *      },
 *      {
 *        label: '锐捷路由器',
 *        id: 'ruijieRouter',
 *        icon: 'ruijieRouter',
 *        children: null,
 *      },
 *    ],
 *  },
 *  {
 *    label: '操作系统',
 *    id: 'system',
 *    icon: 'system',
 *    children: [
 *      {
 *        label: 'Linux',
 *        id: 'Linux',
 *        icon: 'Linux',
 *        children: null,
 *      },
 *      {
 *        label: 'Windows',
 *        id: 'Windows',
 *        icon: 'Windows',
 *        children: null,
 *      },
 *    ],
 *  },
 * ];
 * recursionGet('Linux',array);
 * // result
 * ['Linux']
 *
 * @example example 02 无匹配
 * --------------------------------------------------------------------------
 * const array = [
 *     { id: 1, label: 1, children: null },
 *     { id: 2, label: 2, children: 1 }
 * ];
 * recursionGet("Linux",array);
 *
 * // result
 * []
 *
 */
export var recursionGet = function recursionGet(value, data) {
  if (!Array.isArray(data)) return [];
  var keys = [];

  var loop = function loop(arr) {
    return arr.forEach(function (item) {
      var _item$children;

      if ((item === null || item === void 0 ? void 0 : item.label) && item.label.indexOf(value) > -1) {
        keys.push(item.id);
        return;
      }

      if (item === null || item === void 0 ? void 0 : (_item$children = item.children) === null || _item$children === void 0 ? void 0 : _item$children.length) {
        loop(item.children);
      }
    });
  }; // 递归遍历


  loop(data);
  return keys;
};