'use strict';

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

var vue = require('vue');
require('../../../../utils/index.cjs');
var is = require('../../../../utils/is.cjs');

function useLazyKVMap(dataRef, childrenColumnNameRef, getRowKeyRef) {
  const mapCacheRef = vue.shallowRef({});
  vue.watch(
    [dataRef, childrenColumnNameRef, getRowKeyRef],
    () => {
      const kvMap = /* @__PURE__ */ new Map();
      const getRowKey = getRowKeyRef.value;
      const childrenColumnName = childrenColumnNameRef.value;
      function dig(records) {
        if (!is.isArray(records))
          return;
        records.forEach((record, index) => {
          const rowKey = getRowKey(record, index);
          kvMap.set(rowKey, record);
          if (record && typeof record === "object" && childrenColumnName in record)
            dig(record[childrenColumnName] || []);
        });
      }
      dig(dataRef.value);
      mapCacheRef.value = {
        kvMap
      };
    },
    {
      deep: true,
      immediate: true
    }
  );
  function getRecordByKey(key) {
    return mapCacheRef.value.kvMap.get(key);
  }
  return [getRecordByKey];
}

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