"use strict";
/*---------------------------------------------------------------------------------------------
 * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
 * See LICENSE.md in the project root for license terms and full copyright notice.
 *--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
 * @module Backstage
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.Backstage = void 0;
const classnames_1 = require("classnames");
const React = require("react");
const ts_key_enum_1 = require("ts-key-enum");
const SafeAreaInsets_1 = require("../base/SafeAreaInsets");
require("./Backstage.scss");
/** Backstage component of 9-Zone UI app.
 * @internal
 */
class Backstage extends React.PureComponent {
    constructor() {
        super(...arguments);
        this._onClose = () => {
            this.props.onClose && this.props.onClose();
        };
        this._onEsc = (event) => {
            if (this.props.isOpen && event.key === ts_key_enum_1.Key.Escape.valueOf()) {
                this._onClose();
            }
        };
    }
    componentDidMount() {
        document.addEventListener("keydown", this._onEsc, false);
    }
    componentWillUnmount() {
        document.removeEventListener("keydown", this._onEsc, false);
    }
    render() {
        const overlayClassName = (0, classnames_1.default)("nz-backstage-backstage_overlay", this.props.isOpen && "nz-open", this.props.showOverlay && "nz-overlay");
        const backstageClassName = (0, classnames_1.default)("nz-backstage-backstage", this.props.isOpen && "nz-open", this.props.safeAreaInsets &&
            SafeAreaInsets_1.SafeAreaInsetsHelpers.getCssClassNames(this.props.safeAreaInsets), this.props.className);
        return (React.createElement(React.Fragment, null,
            React.createElement("div", { className: overlayClassName, onClick: this._onClose, role: "presentation" }),
            React.createElement("div", { className: backstageClassName, style: this.props.style },
                this.props.header && (React.createElement("div", { className: "nz-header" }, this.props.header)),
                React.createElement("ul", { role: "menu" }, this.props.children),
                this.props.footer && (React.createElement("div", { className: "nz-footer" }, this.props.footer)))));
    }
}
exports.Backstage = Backstage;
Backstage.defaultProps = {
    showOverlay: true,
};
//# sourceMappingURL=Backstage.js.map