'use strict';

var Record = /* @__PURE__ */ ((Record2) => {
  Record2[Record2["None"] = 0] = "None";
  Record2[Record2["Start"] = 1] = "Start";
  Record2[Record2["End"] = 2] = "End";
  return Record2;
})(Record || {});
function traverseNodesKey(treeData, fieldNames, callback) {
  function processNode(dataNode) {
    const key = dataNode[fieldNames.key];
    const children = dataNode[fieldNames.children];
    if (callback(key, dataNode) !== false)
      traverseNodesKey(children || [], fieldNames, callback);
  }
  treeData.forEach(processNode);
}
function calcRangeKeys({
  treeData,
  expandedKeys,
  startKey,
  endKey,
  fieldNames = {
    title: "title",
    key: "key",
    children: "children"
  }
}) {
  const keys = [];
  let record = 0 /* None */;
  if (startKey && startKey === endKey)
    return [startKey];
  if (!startKey || !endKey)
    return [];
  function matchKey(key) {
    return key === startKey || key === endKey;
  }
  traverseNodesKey(treeData, fieldNames, (key) => {
    if (record === 2 /* End */)
      return false;
    if (matchKey(key)) {
      keys.push(key);
      if (record === 0 /* None */) {
        record = 1 /* Start */;
      } else if (record === 1 /* Start */) {
        record = 2 /* End */;
        return false;
      }
    } else if (record === 1 /* Start */) {
      keys.push(key);
    }
    return expandedKeys.includes(key);
  });
  return keys;
}
function convertDirectoryKeysToNodes(treeData, keys, fieldNames) {
  const restKeys = [...keys];
  const nodes = [];
  traverseNodesKey(treeData, fieldNames, (key, node) => {
    const index = restKeys.indexOf(key);
    if (index !== -1) {
      nodes.push(node);
      restKeys.splice(index, 1);
    }
    return !!restKeys.length;
  });
  return nodes;
}

exports.calcRangeKeys = calcRangeKeys;
exports.convertDirectoryKeysToNodes = convertDirectoryKeysToNodes;
//# sourceMappingURL=dictUtil.cjs.map
