/**
 * tdesign v0.39.1-alpha.1
 * (c) 2022 tdesign
 * @license MIT
 */

'use strict';

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

var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var _toConsumableArray__default = /*#__PURE__*/_interopDefaultLegacy(_toConsumableArray);
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);

function getLabelIsEllipsis(node, size) {
  var sizeMap = {
    small: 11,
    medium: 9,
    large: 8
  };
  return sizeMap[size] < node.label.length;
}
function getNodeStatusClass(node, CLASSNAMES, cascaderContext) {
  var _ref;

  var checkStrictly = cascaderContext.checkStrictly,
      multiple = cascaderContext.multiple,
      value = cascaderContext.value,
      max = cascaderContext.max;
  var expandedActive = !checkStrictly && node.expanded && (multiple ? !node.isLeaf() : true) || checkStrictly && node.expanded;
  var isLeaf = node.isLeaf();
  var isDisabled = node.disabled || multiple && value.length >= max && max !== 0;
  var isSelected = node.checked || multiple && !checkStrictly && node.expanded && !isLeaf;
  return [(_ref = {}, _defineProperty__default["default"](_ref, CLASSNAMES.STATUS.selected, !isDisabled && isSelected), _defineProperty__default["default"](_ref, CLASSNAMES.STATUS.expanded, !isDisabled && expandedActive), _defineProperty__default["default"](_ref, CLASSNAMES.STATUS.disabled, isDisabled), _ref)];
}
function getCascaderItemClass(prefix, node, CLASSNAMES, cascaderContext) {
  var _ref2;

  var size = cascaderContext.size;
  return ["".concat(prefix, "-cascader__item")].concat(_toConsumableArray__default["default"](getNodeStatusClass(node, CLASSNAMES, cascaderContext)), [(_ref2 = {}, _defineProperty__default["default"](_ref2, "".concat(prefix, "-cascader__item--with-icon"), !!node.children), _defineProperty__default["default"](_ref2, "".concat(prefix, "-cascader__item--leaf"), node.isLeaf()), _defineProperty__default["default"](_ref2, CLASSNAMES.SIZE[size], !!size), _ref2)]);
}
function getCascaderItemIconClass(prefix, node, CLASSNAMES, cascaderContext) {
  return ["".concat(prefix, "-cascader__item-icon")].concat(_toConsumableArray__default["default"](getNodeStatusClass(node, CLASSNAMES, cascaderContext)));
}

exports.getCascaderItemClass = getCascaderItemClass;
exports.getCascaderItemIconClass = getCascaderItemIconClass;
exports.getLabelIsEllipsis = getLabelIsEllipsis;
exports.getNodeStatusClass = getNodeStatusClass;
//# sourceMappingURL=item.js.map
