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 (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
import React from 'react';
import PropTypes from 'prop-types';
import ReactDOM from 'react-dom';
import classnames from 'classnames';
import { isAutomationTestActive } from '../../utils/testAutomation';
var PrintArea = /** @class */ (function (_super) {
    __extends(PrintArea, _super);
    function PrintArea() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    PrintArea.print = function (id) {
        var element = PrintArea.areas[id];
        if (!element) {
            throw new Error("PrintArea with id \"" + id + "\" not found");
        }
        var node = ReactDOM.findDOMNode(element);
        if (!node) {
            throw new Error("PrintArea with id \"" + id + "\" not found");
        }
        if (!PrintArea.container) {
            PrintArea.container = document.createElement('div');
            PrintArea.container.setAttribute('data-test-automation-id', 'printArea');
            PrintArea.container.className = classnames('rc-print-area', {
                'rc-print-area-wide': element.props.wide
            });
            document.body.appendChild(PrintArea.container);
        }
        PrintArea.container.innerHTML = PrintArea.getNodeTreeHTML(node);
        if (!isAutomationTestActive()) {
            window.print();
        }
    };
    PrintArea.getNodeTreeHTML = function (node) {
        var html = node.innerHTML;
        while (node) {
            node = node.parentNode;
            if (node === document.body) {
                break;
            }
            html = "<" + node.tagName + " class=\"rc-print-area-parent " + node.className + "\">" + html + "</" + node.tagName + ">";
        }
        return html;
    };
    PrintArea.prototype.componentDidMount = function () {
        if (PrintArea.areas[this.props.id]) {
            // eslint-disable-next-line
            console.error("PrintArea with id \"" + this.props.id + "\" is already exists on page");
        }
        PrintArea.areas[this.props.id] = this;
    };
    PrintArea.prototype.componentWillUnmount = function () {
        delete PrintArea.areas[this.props.id];
    };
    PrintArea.prototype.render = function () {
        return React.createElement("span", null, this.props.children);
    };
    PrintArea.propTypes = {
        id: PropTypes.string.isRequired,
        children: PropTypes.node.isRequired,
        wide: PropTypes.bool
    };
    PrintArea.defaultProps = {
        wide: true
    };
    PrintArea.areas = {};
    return PrintArea;
}(React.Component));
export { PrintArea };
//# sourceMappingURL=PrintArea.js.map