"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/defineProperty"));
var _react = _interopRequireDefault(require("react"));
var _reactDom = _interopRequireDefault(require("react-dom"));
class LongTextModal extends _react.default.Component {
  constructor(props) {
    super(props);
    (0, _defineProperty2.default)(this, "onModalClick", e => {
      const isClickInside = this.el && this.el.contains(e.target) && this.el !== e.target;
      if (isClickInside) return;
      e && e.stopPropagation();
      e && e.stopImmediatePropagation();
      const className = e.target.className;
      if (typeof className !== 'string') return;
      if (this.props.onModalClick && (className === 'longtext-modal-wrapper' || className.startsWith('longtext-modal-wrapper'))) {
        this.props.onModalClick();
      }
    });
    const {
      containerClass
    } = this.props;
    this.el = document.createElement('div');
    this.el.className = 'longtext-modal-wrapper';
    this.el.className = `longtext-modal-wrapper ${containerClass || ''}`;
    document.body.appendChild(this.el);
  }
  componentDidMount() {
    this.el.addEventListener('mousedown', this.onModalClick);
  }
  componentWillUnmount() {
    this.el.removeEventListener('mousedown', this.onModalClick);
    document.body.removeChild(this.el);
  }
  render() {
    return /*#__PURE__*/_reactDom.default.createPortal(this.props.children, this.el);
  }
}
var _default = exports.default = LongTextModal;