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

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var isFunction = require('lodash/isFunction');
var isEmpty = require('lodash/isEmpty');

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

var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var isFunction__default = /*#__PURE__*/_interopDefaultLegacy(isFunction);
var isEmpty__default = /*#__PURE__*/_interopDefaultLegacy(isEmpty);

function getCloseIconClass(prefix, CLASSNAMES, cascaderContext) {
  var _ref;

  var visible = cascaderContext.visible,
      disabled = cascaderContext.disabled;
  return ["".concat(prefix, "-cascader__icon"), (_ref = {}, _defineProperty__default["default"](_ref, CLASSNAMES.STATUS.visible, visible), _defineProperty__default["default"](_ref, CLASSNAMES.STATUS.disabled, disabled), _ref)];
}
function getFakeArrowIconClass(prefix, CLASSNAMES, cascaderContext) {
  var disabled = cascaderContext.disabled;
  return ["".concat(prefix, "-cascader__icon"), _defineProperty__default["default"]({}, CLASSNAMES.STATUS.disabled, disabled)];
}
function getCascaderInnerClasses(prefix, CLASSNAMES, cascaderContext) {
  var _ref3;

  var disabled = cascaderContext.disabled,
      visible = cascaderContext.visible,
      size = cascaderContext.size,
      multiple = cascaderContext.multiple;
  return ["".concat(prefix, "-cascader"), (_ref3 = {}, _defineProperty__default["default"](_ref3, CLASSNAMES.STATUS.disabled, disabled), _defineProperty__default["default"](_ref3, CLASSNAMES.STATUS.active, visible), _defineProperty__default["default"](_ref3, CLASSNAMES.SIZE[size], size), _defineProperty__default["default"](_ref3, "".concat(prefix, "-cascader--multiple"), multiple), _ref3)];
}
function getCloseShow(isHover, cascaderContext) {
  var value = cascaderContext.value,
      disabled = cascaderContext.disabled,
      clearable = cascaderContext.clearable,
      visible = cascaderContext.visible;
  return !!(!visible && clearable && isHover && !disabled && !isEmpty__default["default"](value));
}
function getPlaceholderShow(cascaderContext, singleContent, multipleContent) {
  var filterable = cascaderContext.filterable,
      visible = cascaderContext.visible,
      multiple = cascaderContext.multiple;
  var valEmpty = !(multiple ? multipleContent.length : singleContent);

  if (filterable) {
    return valEmpty && !visible;
  }

  return valEmpty;
}
function getSingleContent(cascaderContext) {
  var value = cascaderContext.value,
      multiple = cascaderContext.multiple,
      treeStore = cascaderContext.treeStore,
      showAllLevels = cascaderContext.showAllLevels,
      setValue = cascaderContext.setValue;
  if (multiple || !value) return "";
  if (Array.isArray(value)) return "";
  var node = treeStore && treeStore.getNodes(value);

  if (!(node && node.length)) {
    if (value) {
      setValue(multiple ? [] : "", "invalid-value");
    }

    return "";
  }

  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;
  if (!multiple) return [];
  if (multiple && !Array.isArray(value)) return [];
  var node = treeStore && treeStore.getNodes(value);
  if (!node) return [];
  var path = value.map(function (item) {
    var node2 = treeStore.getNodes(item);
    return node2[0];
  });

  if (value && value.length) {
    return path && path.length ? path : value;
  }

  return [];
}
function outerClickListenerEffect(ref, cascaderContext, event) {
  var visible = cascaderContext.visible,
      setVisible = cascaderContext.setVisible;

  if (!ref || ref.contains(event.target)) {
    return;
  }

  if (visible) {
    setVisible(false);
  }
}
function closeIconClickEffect(cascaderContext) {
  var setVisible = cascaderContext.setVisible,
      multiple = cascaderContext.multiple,
      setExpend = cascaderContext.setExpend,
      setValue = cascaderContext.setValue;
  setVisible(false);

  if (multiple) {
    setExpend([]);
  }

  setValue(multiple ? [] : "", "clear");
}
function handleRemoveTagEffect(cascaderContext, node, onRemove) {
  var disabled = cascaderContext.disabled,
      setValue = cascaderContext.setValue,
      valueType = cascaderContext.valueType,
      treeStore = cascaderContext.treeStore;
  if (disabled) return;
  var checked = node.setChecked(!node.isChecked());
  var resValue = valueType === "single" ? checked : checked.map(function (val) {
    return treeStore.getNode(val).getPath().map(function (item) {
      return item.value;
    });
  });
  setValue(resValue, "unchecked", node.getModel());

  if (isFunction__default["default"](onRemove)) {
    onRemove({
      value: checked,
      node: node
    });
  }
}
function innerContentClickEffect(cascaderContext) {
  var setVisible = cascaderContext.setVisible,
      visible = cascaderContext.visible,
      filterActive = cascaderContext.filterActive,
      disabled = cascaderContext.disabled;

  if (!disabled) {
    if (visible && filterActive) return;
    setVisible(!visible);
  }
}

exports.closeIconClickEffect = closeIconClickEffect;
exports.getCascaderInnerClasses = getCascaderInnerClasses;
exports.getCloseIconClass = getCloseIconClass;
exports.getCloseShow = getCloseShow;
exports.getFakeArrowIconClass = getFakeArrowIconClass;
exports.getMultipleContent = getMultipleContent;
exports.getPlaceholderShow = getPlaceholderShow;
exports.getSingleContent = getSingleContent;
exports.handleRemoveTagEffect = handleRemoveTagEffect;
exports.innerContentClickEffect = innerContentClickEffect;
exports.outerClickListenerEffect = outerClickListenerEffect;
//# sourceMappingURL=inputContent.js.map
