'use strict';

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

var vue = require('vue');

var useCache = (labeledValues, valueOptions) => {
  const cacheRef = vue.shallowRef({
    values: /* @__PURE__ */ new Map(),
    options: /* @__PURE__ */ new Map()
  });
  const filledLabeledValues = vue.computed(() => {
    const { values: prevValueCache, options: prevOptionCache } = cacheRef.value;
    const patchedValues = labeledValues.value.map((item) => {
      var _a;
      if (item.label === void 0) {
        return {
          ...item,
          label: (_a = prevValueCache.get(item.value)) == null ? void 0 : _a.label
        };
      }
      return item;
    });
    const valueCache = /* @__PURE__ */ new Map();
    const optionCache = /* @__PURE__ */ new Map();
    patchedValues.forEach((item) => {
      valueCache.set(item.value, item);
      optionCache.set(
        item.value,
        valueOptions.value.get(item.value) || prevOptionCache.get(item.value)
      );
    });
    cacheRef.value.values = valueCache;
    cacheRef.value.options = optionCache;
    return patchedValues;
  });
  const getOption = (val) => valueOptions.value.get(val) || cacheRef.value.options.get(val);
  return [filledLabeledValues, getOption];
};

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