"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getFileTreeNavigationAdapter = void 0;
var _utils = require("../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;
};
const getFileTreeNavigationAdapter = ({
  isExpandedByDefault
}) => {
  const mapFn = getMapFn(isExpandedByDefault);
  return {
    isExpandedByDefault,
    getFlatNodes: tree => {
      return (0, _utils.flattenTree)(tree, mapFn);
    },
    getFocusableNodes: _utils.getFocusableNodes
  };
};
exports.getFileTreeNavigationAdapter = getFileTreeNavigationAdapter;