"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = useKeyValueMap;

var _vue = require("vue");

/**
 * Return cached Key Value map with DataNode.
 * Only re-calculate when `flattenOptions` changed.
 */
function useKeyValueMap(flattenOptions) {
  var cacheKeyMap = (0, _vue.ref)(new Map());
  var cacheValueMap = (0, _vue.ref)(new Map());
  (0, _vue.watchEffect)(function () {
    var newCacheKeyMap = new Map();
    var newCacheValueMap = new Map(); // Cache options by key

    flattenOptions.value.forEach(function (dataNode) {
      newCacheKeyMap.set(dataNode.key, dataNode);
      newCacheValueMap.set(dataNode.data.value, dataNode);
    });
    cacheKeyMap.value = newCacheKeyMap;
    cacheValueMap.value = newCacheValueMap;
  });
  return [cacheKeyMap, cacheValueMap];
}