import { computed } from 'vue';
import '../../../../utils/index.mjs';
import { toPathOptions } from '../utils/treeUtil.mjs';
import { toPathKey } from '../utils/commonUtil.mjs';
import { isValidElement } from '../../../../utils/is.mjs';
import { cloneElement } from '../../../../utils/vue/vnode.mjs';

var useDisplayValues = (rawValues, options, fieldNames, multiple, displayRender) => {
  return 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 = isValidElement(label) ? cloneElement(label, { key: index }) : label;
        if (index === 0)
          return [keyedLabel];
        return [...list, SPLIT, keyedLabel];
      }, []);
    });
    return rawValues.value.map((valueCells) => {
      const valueOptions = 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 = toPathKey(valueCells);
      return {
        label,
        value,
        key: value,
        valueCells
      };
    });
  });
};

export { useDisplayValues as default };
//# sourceMappingURL=useDisplayValues.mjs.map
