import React, { Fragment, memo } from 'react';
import toUpper from 'lodash/toUpper';
import classnames from 'classnames';
import "./index.less";
var TreeItemName = /*#__PURE__*/memo(function (_ref) {
  var name = _ref.name,
      search = _ref.search,
      disabled = _ref.disabled,
      headSpace = _ref.headSpace;
  var index = toUpper(name).indexOf(toUpper(search));
  var beforeStr = name === null || name === void 0 ? void 0 : name.substr(0, index);
  var currentStr = name === null || name === void 0 ? void 0 : name.substr(index, search.length);
  var afterStr = name === null || name === void 0 ? void 0 : name.substr(index + search.length);
  var textClass = classnames({
    'c7ncd-treemenu-text': true,
    'c7ncd-treemenu-text-disabled': disabled,
    'c7ncd-treemenu-text-ml': headSpace
  });
  return /*#__PURE__*/React.createElement("span", {
    className: textClass
  }, index > -1 ? /*#__PURE__*/React.createElement(React.Fragment, null, beforeStr, /*#__PURE__*/React.createElement("span", {
    className: "c7ncd-treemenu-text-highlight"
  }, currentStr), afterStr) : name, disabled && /*#__PURE__*/React.createElement("i", {
    className: "c7ncd-treemenu-disabled"
  }));
});
TreeItemName.defaultProps = {
  disabled: false,
  headSpace: true,
  search: ''
};
export default TreeItemName;