/**
 * ldesign v0.4.2
 * (c) 2023 ldesign
 * @license MIT
 */

import { i as isNumber_1 } from '../../_chunks/dep-6eea369f.mjs';
import { i as isObject_1 } from '../../_chunks/dep-0f0c89ff.mjs';
import { i as isArray_1 } from '../../_chunks/dep-e3b14d70.mjs';
import { i as isEmpty_1 } from '../../_chunks/dep-bd03960e.mjs';
import '../../_chunks/dep-a0b4a044.mjs';
import '../../_chunks/dep-c959a6fb.mjs';
import '../../_chunks/dep-b4041200.mjs';
import '../../_chunks/dep-c31e1d9e.mjs';
import '../../_chunks/dep-44f056cd.mjs';
import '../../_chunks/dep-a9c8a5d5.mjs';
import '../../_chunks/dep-10085c61.mjs';
import '../../_chunks/dep-1b058de3.mjs';
import '../../_chunks/dep-39cc276d.mjs';
import '../../_chunks/dep-6b22dd27.mjs';
import '../../_chunks/dep-8f777748.mjs';
import '../../_chunks/dep-05fa17c9.mjs';
import '../../_chunks/dep-66d6733b.mjs';
import '../../_chunks/dep-92e7085e.mjs';

function getSingleContent(cascaderContext) {
  var value = cascaderContext.value,
    multiple = cascaderContext.multiple,
    treeStore = cascaderContext.treeStore,
    showAllLevels = cascaderContext.showAllLevels;
  if (multiple || value !== 0 && !value) return "";
  if (isArray_1(value)) return "";
  var node = treeStore && treeStore.getNodes(value);
  if (!(node && node.length)) return value;
  var path = node && node[0].getPath();
  if (path && path.length) return showAllLevels ? path.map(function (node2) {
    return node2.label;
  }).join(" / ") : path[path.length - 1].label;
  return value;
}
function getMultipleContent(cascaderContext) {
  var value = cascaderContext.value,
    multiple = cascaderContext.multiple,
    treeStore = cascaderContext.treeStore,
    showAllLevels = cascaderContext.showAllLevels;
  if (!multiple) return [];
  if (multiple && !isArray_1(value)) return [];
  var node = treeStore && treeStore.getNodes(value);
  if (!node) return [];
  return value.map(function (item) {
    var node2 = treeStore.getNodes(item);
    return showAllLevels ? getFullPathLabel(node2[0]) : node2[0].label;
  }).filter(function (item) {
    return !!item;
  });
}
function getPanels(treeNodes) {
  var panels = [];
  treeNodes.forEach(function (node) {
    if (panels[node.level]) panels[node.level].push(node);else panels[node.level] = [node];
  });
  return panels;
}
function getFullPathLabel(node) {
  var separator = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "/";
  return node === null || node === void 0 ? void 0 : node.getPath().map(function (node2) {
    return node2.label;
  }).join(separator);
}
var getTreeValue = function getTreeValue(value) {
  var treeValue = [];
  if (isArray_1(value)) {
    if (value.length > 0 && isObject_1(value[0])) treeValue = value.map(function (val) {
      return val.value;
    });else if (value.length) treeValue = value;
  } else if (value) {
    if (isObject_1(value)) treeValue = [value.value];else treeValue = [value];
  }
  return treeValue;
};
var getCascaderValue = function getCascaderValue(value, valueType, multiple) {
  if (valueType === "single") return value;
  if (multiple) return value.map(function (item) {
    return item[item.length - 1];
  });
  return value[value.length - 1];
};
function isEmptyValues(value) {
  if (isNumber_1(value) && !isNaN(value)) return false;
  return isEmpty_1(value);
}
function isValueInvalid(value, cascaderContext) {
  var multiple = cascaderContext.multiple,
    showAllLevels = cascaderContext.showAllLevels;
  return multiple && !isArray_1(value) || !multiple && isArray_1(value) && !showAllLevels;
}

export { getCascaderValue, getFullPathLabel, getMultipleContent, getPanels, getSingleContent, getTreeValue, isEmptyValues, isValueInvalid };
//# sourceMappingURL=helper.mjs.map
