import _ from 'lodash'
/**
 * 从树结构过滤出用户list
 *
 * @param tree 树所有节点数据
 */
export const searchUserList = (tree: any[]): any[] => {
  const finds: any[] = []
  if (tree) {
    tree.forEach((node) => {
      if (node) {
        if (node.type === 'user') {
          finds.push(node)
        }
        // eslint-disable-next-line @typescript-eslint/no-unused-vars
        const findChild = searchUserList(node.children)
        finds.push(...findChild)
      }
    })
  }
  return _.unionWith(finds, (arrVal, othVal) => {
    return arrVal.id === othVal.id
  })
}
