import _ from 'lodash';
import React from 'react';
import IconClear from "./../Icon/Clear";

// 渲染清除按钮
function getClearNode(_ref) {
  var clear = _ref.clear,
    allowClear = _ref.allowClear,
    disabled = _ref.disabled,
    readOnly = _ref.readOnly,
    value = _ref.value,
    onClear = _ref.onClear,
    onTouchStart = _ref.onTouchStart;
  // 禁用时不显示清空按钮
  if (disabled) return null;
  var clearable = allowClear && (!_.isEmpty(value) || typeof value === 'number') ? true : false;

  // 自定义渲染清空按钮
  if (typeof clear === 'function') {
    var clearNode = clear({
      allowClear: allowClear,
      clearable: clearable,
      readOnly: readOnly,
      value: value,
      triggerClear: onClear,
      onTouchStart: onTouchStart
    });
    if (clearNode !== undefined) return clearNode;
  }

  // 默认渲染
  if (!clearable) return null;
  return /*#__PURE__*/React.createElement(IconClear, {
    onTouchStart: onTouchStart,
    onClick: onClear
  });
}
export default getClearNode;