import _inheritsLoose from "@babel/runtime/helpers/esm/inheritsLoose";
import React from 'react';
import { cx } from "../../../lib/theming/Emotion";
import { styles } from "../ResizeDetector.styles";
export var ResizeDetector = /*#__PURE__*/function (_React$Component) {
  function ResizeDetector() {
    var _this;
    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }
    _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
    _this.iframeWindow = null;
    _this.handleResize = function (event) {
      if (_this.props.onResize) {
        _this.props.onResize(event);
      }
    };
    _this.iframeRef = function (iframe) {
      if (iframe && iframe.contentWindow) {
        _this.iframeWindow = iframe.contentWindow;
      }
    };
    return _this;
  }
  _inheritsLoose(ResizeDetector, _React$Component);
  var _proto = ResizeDetector.prototype;
  _proto.componentDidMount = function componentDidMount() {
    if (this.iframeWindow) {
      this.iframeWindow.addEventListener('resize', this.handleResize);
    }
  };
  _proto.render = function render() {
    var _cx;
    return /*#__PURE__*/React.createElement("div", {
      className: styles.root()
    }, /*#__PURE__*/React.createElement("iframe", {
      title: "resizeDetector",
      ref: this.iframeRef,
      className: styles.iframe(),
      tabIndex: -1
    }), /*#__PURE__*/React.createElement("div", {
      className: cx((_cx = {}, _cx[styles.content()] = true, _cx[styles.fullHeight()] = this.props.fullHeight, _cx[styles.flex()] = this.props.alignBaseline, _cx))
    }, this.props.children));
  };
  return ResizeDetector;
}(React.Component);
ResizeDetector.__KONTUR_REACT_UI__ = 'ResizeDetector';
ResizeDetector.displayName = 'ResizeDetector';