import { flattenTree, getFocusableNodes } from '../hooks/use-tree-navigation/utils';
const getMapFn = isExpandedByDefault => {
  const mapFunction = (node, parents) => {
    const children = node.content || [];
    const treeNode = {
      id: node.id,
      label: node.name,
      parent: parents[0] ?? null,
      parents,
      isDisabled: false,
      isExpanded: !!children.length && isExpandedByDefault,
      isExpandable: !!children.length,
      isFocused: false,
      isLeaf: !children.length,
      children: children.map(({
        id
      }) => id)
    };
    return {
      node: treeNode,
      children
    };
  };
  return mapFunction;
};
export const getFileTreeNavigationAdapter = ({
  isExpandedByDefault
}) => {
  const mapFn = getMapFn(isExpandedByDefault);
  return {
    isExpandedByDefault,
    getFlatNodes: tree => {
      return flattenTree(tree, mapFn);
    },
    getFocusableNodes
  };
};