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

import { i as isNumber_1 } from '../../_chunks/dep-3f21269a.mjs';
import { i as isObject_1 } from '../../_chunks/dep-a8bcacea.mjs';
import { i as isArray_1 } from '../../_chunks/dep-b57180d0.mjs';
import { i as isEmpty_1 } from '../../_chunks/dep-888e80c4.mjs';
import '../../_chunks/dep-eba0ea6e.mjs';
import '../../_chunks/dep-469b4ae0.mjs';
import '../../_chunks/dep-255303ba.mjs';
import '../../_chunks/dep-3da99438.mjs';
import '../../_chunks/dep-334a4f6b.mjs';
import '../../_chunks/dep-e5eb9f23.mjs';
import '../../_chunks/dep-9fe2ef12.mjs';
import '../../_chunks/dep-672e7d1a.mjs';
import '../../_chunks/dep-4d7a675b.mjs';
import '../../_chunks/dep-5717e263.mjs';
import '../../_chunks/dep-2e7f59b1.mjs';
import '../../_chunks/dep-1434aa15.mjs';
import '../../_chunks/dep-c8d7b6b4.mjs';
import '../../_chunks/dep-9262ee2f.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
