'use strict';

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

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

var useDisplayValues = (rawValues, options, fieldNames, multiple, displayRender) => {
  return vue.computed(() => {
    const mergedDisplayRender = displayRender.value || (({ labels }) => {
      const mergedLabels = multiple.value ? labels.slice(-1) : labels;
      const SPLIT = " / ";
      if (mergedLabels.every((label) => ["string", "number"].includes(typeof label)))
        return mergedLabels.join(SPLIT);
      return mergedLabels.reduce((list, label, index) => {
        const keyedLabel = is.isValidElement(label) ? vnode.cloneElement(label, { key: index }) : label;
        if (index === 0)
          return [keyedLabel];
        return [...list, SPLIT, keyedLabel];
      }, []);
    });
    return rawValues.value.map((valueCells) => {
      const valueOptions = treeUtil.toPathOptions(valueCells, options.value, fieldNames.value);
      const label = mergedDisplayRender({
        labels: valueOptions.map(({ option, value: value2 }) => {
          var _a;
          return (_a = option == null ? void 0 : option[fieldNames.value.label]) != null ? _a : value2;
        }),
        selectedOptions: valueOptions.map(({ option }) => option)
      });
      const value = commonUtil.toPathKey(valueCells);
      return {
        label,
        value,
        key: value,
        valueCells
      };
    });
  });
};

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