'use strict';

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

var vue = require('vue');
require('../../../../utils/index.cjs');
var treeUtil = require('../../../vc-tree/src/utils/treeUtil.cjs');
var valueUtil = require('../utils/valueUtil.cjs');
var log = require('../../../../utils/log.cjs');

var useDataEntities = (treeData, fieldNames) => {
  const valueEntities = vue.shallowRef(/* @__PURE__ */ new Map());
  const keyEntities = vue.shallowRef({});
  vue.watchEffect(() => {
    const fieldNamesValue = fieldNames.value;
    const collection = treeUtil.convertDataToEntities(treeData.value, {
      fieldNames: fieldNamesValue,
      initWrapper: (wrapper) => ({
        ...wrapper,
        valueEntities: /* @__PURE__ */ new Map()
      }),
      processEntity: (entity, wrapper) => {
        const val = entity.node[fieldNamesValue.value];
        if (process.env.NODE_ENV !== "production") {
          const key = entity.node.key;
          log.warning(!valueUtil.isNil(val), "TreeNode `value` is invalidate: undefined");
          log.warning(!wrapper.valueEntities.has(val), `Same \`value\` exist in the tree: ${val}`);
          log.warning(
            !key || String(key) === String(val),
            `\`key\` or \`value\` with TreeNode must be the same or you can remove one of them. key: ${key}, value: ${val}.`
          );
        }
        wrapper.valueEntities.set(val, entity);
      }
    });
    valueEntities.value = collection.valueEntities;
    keyEntities.value = collection.keyEntities;
  });
  return { valueEntities, keyEntities };
};

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