"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const shared_esmBundler = require("../../../../../../@vue/shared/dist/shared.esm-bundler.js");
const Vue = require("vue");
const useData = (props, { expandedRowKeys, lastRenderedRowIndex, resetAfterIndex }) => {
  const depthMap = Vue.ref({});
  const flattenedData = Vue.computed(() => {
    const depths = {};
    const { data: data2, rowKey } = props;
    const _expandedRowKeys = Vue.unref(expandedRowKeys);
    if (!_expandedRowKeys || !_expandedRowKeys.length) return data2;
    const array = [];
    const keysSet = /* @__PURE__ */ new Set();
    _expandedRowKeys.forEach((x) => keysSet.add(x));
    let copy = data2.slice();
    copy.forEach((x) => depths[x[rowKey]] = 0);
    while (copy.length > 0) {
      const item = copy.shift();
      array.push(item);
      if (keysSet.has(item[rowKey]) && shared_esmBundler.isArray(item.children) && item.children.length > 0) {
        copy = [...item.children, ...copy];
        item.children.forEach((child) => depths[child[rowKey]] = depths[item[rowKey]] + 1);
      }
    }
    depthMap.value = depths;
    return array;
  });
  const data = Vue.computed(() => {
    const { data: data2, expandColumnKey } = props;
    return expandColumnKey ? Vue.unref(flattenedData) : data2;
  });
  Vue.watch(data, (val, prev) => {
    if (val !== prev) {
      lastRenderedRowIndex.value = -1;
      resetAfterIndex(0, true);
    }
  });
  return {
    data,
    depthMap
  };
};
exports.useData = useData;
