import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import React, { useLayoutEffect, useMemo, useRef, useState } from 'react';
import classNames from '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 = useRef(null);

  var _useState = useState(null),
      _useState2 = _slicedToArray(_useState, 2),
      content = _useState2[0],
      setContent = _useState2[1];

  var selfPrefixCls = "".concat(prefixCls, "-rendered-value");
  var style = useMemo(function () {
    return isFlat ? {
      width: 'auto',
      maxWidth: 'none'
    } : undefined;
  }, [isFlat]);
  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.createElement("span", {
    key: "renderedText",
    className: classNames(selfPrefixCls, className),
    hidden: hidden,
    style: style
  }, /*#__PURE__*/React.createElement("span", {
    className: "".concat(selfPrefixCls, "-inner"),
    ref: renderedValueRef
  }, children));
};

RenderedText.displayName = 'RenderedText';
export default RenderedText;
//# sourceMappingURL=RenderedText.js.map
