export const useTree = () => {
  return {
    filterTreeNodeByField,
  }
}

function filterTreeNodeByField({ treeData, params, paramName, icon = '' }) {
  return treeData.reduce((acc, node) => {
    if (params.includes(node[paramName]) && !node.children) {
      acc.push({ ...node, icon })
    }
    if (node.children) {
      acc = acc.concat(
        filterTreeNodeByField({
          treeData: node.children,
          params,
          paramName,
          icon: node.icon,
        })
      )
    }
    return acc
  }, [])
}
