'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var vue = require('vue');

function flatRecord(record, indent, childrenColumnName, expandedKeys, getRowKey, index) {
  const arr = [];
  arr.push({
    record,
    indent,
    index
  });
  const key = getRowKey(record);
  const expanded = expandedKeys == null ? void 0 : expandedKeys.has(key);
  if (record && Array.isArray(record[childrenColumnName]) && expanded) {
    for (let i = 0; i < record[childrenColumnName].length; i += 1) {
      const tempArr = flatRecord(
        record[childrenColumnName][i],
        indent + 1,
        childrenColumnName,
        expandedKeys,
        getRowKey,
        i
      );
      arr.push(...tempArr);
    }
  }
  return arr;
}
function useFlattenRecords(dataRef, childrenColumnNameRef, expandedKeysRef, getRowKey) {
  const arr = vue.computed(() => {
    const childrenColumnName = childrenColumnNameRef.value;
    const expandedKeys = expandedKeysRef.value;
    const data = dataRef.value;
    if (expandedKeys == null ? void 0 : expandedKeys.size) {
      const temp = [];
      for (let i = 0; i < (data == null ? void 0 : data.length); i += 1) {
        const record = data[i];
        temp.push(
          ...flatRecord(record, 0, childrenColumnName, expandedKeys, getRowKey.value, i)
        );
      }
      return temp;
    }
    return data == null ? void 0 : data.map((item, index) => {
      return {
        record: item,
        indent: 0,
        index
      };
    });
  });
  return arr;
}

exports.default = useFlattenRecords;
//# sourceMappingURL=useFlattenRecords.cjs.map
