var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        if (typeof b !== "function" && b !== null)
            throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import React from 'react';
import { withRenderEnvironment } from '../../lib/renderEnvironment/index.js';
import { getStyles } from './ResizeDetector.styles.js';
var ResizeDetector = /** @class */ (function (_super) {
    __extends(ResizeDetector, _super);
    function ResizeDetector() {
        var _this = _super !== null && _super.apply(this, arguments) || 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;
    }
    ResizeDetector.prototype.componentDidMount = function () {
        if (this.iframeWindow) {
            this.iframeWindow.addEventListener('resize', this.handleResize);
        }
    };
    ResizeDetector.prototype.render = function () {
        var _a;
        this.styles = getStyles(this.emotion);
        return (React.createElement("div", { className: this.styles.root() },
            React.createElement("iframe", { title: "resizeDetector", ref: this.iframeRef, className: this.styles.iframe(), tabIndex: -1 }),
            React.createElement("div", { className: this.cx((_a = {},
                    _a[this.styles.content()] = true,
                    _a[this.styles.fullHeight()] = this.props.fullHeight,
                    _a[this.styles.flex()] = this.props.alignBaseline,
                    _a)) }, this.props.children)));
    };
    ResizeDetector.__KONTUR_REACT_UI__ = 'ResizeDetector';
    ResizeDetector.displayName = 'ResizeDetector';
    ResizeDetector = __decorate([
        withRenderEnvironment
    ], ResizeDetector);
    return ResizeDetector;
}(React.Component));
export { ResizeDetector };
//# sourceMappingURL=ResizeDetector.js.map