"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));

var _react = _interopRequireWildcard(require("react"));

var _classnames = _interopRequireDefault(require("classnames"));

var RenderedText = function RenderedText(_ref) {
  var prefixCls = _ref.prefixCls,
      children = _ref.children,
      onContentChange = _ref.onContentChange,
      hidden = _ref.hidden,
      className = _ref.className,
      isFlat = _ref.isFlat,
      rangeTarget = _ref.rangeTarget;
  var renderedValueRef = (0, _react.useRef)(null);

  var _useState = (0, _react.useState)(null),
      _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
      content = _useState2[0],
      setContent = _useState2[1];

  var selfPrefixCls = "".concat(prefixCls, "-rendered-value");
  var style = (0, _react.useMemo)(function () {
    return isFlat ? {
      width: 'auto',
      maxWidth: 'none'
    } : undefined;
  }, [isFlat]);
  (0, _react.useLayoutEffect)(function () {
    if (onContentChange) {
      var current = renderedValueRef.current;

      if (current) {
        var textContent = current.textContent;

        if (textContent !== null && textContent !== content) {
          setContent(textContent);
          onContentChange(textContent, current.scrollWidth, rangeTarget);
        }
      }
    }
  }, [onContentChange, renderedValueRef, content, children, rangeTarget]);
  return /*#__PURE__*/_react["default"].createElement("span", {
    key: "renderedText",
    className: (0, _classnames["default"])(selfPrefixCls, className),
    hidden: hidden,
    style: style
  }, /*#__PURE__*/_react["default"].createElement("span", {
    className: "".concat(selfPrefixCls, "-inner"),
    ref: renderedValueRef
  }, children));
};

RenderedText.displayName = 'RenderedText';
var _default = RenderedText;
exports["default"] = _default;
//# sourceMappingURL=RenderedText.js.map
