"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 = exports.BackstageEvent = void 0;
const React = require("react");
const core_react_1 = require("@itwin/core-react");
const appui_layout_react_1 = require("@itwin/appui-layout-react");
const SafeAreaContext_1 = require("../safearea/SafeAreaContext");
const UiFramework_1 = require("../UiFramework");
const BackstageManager_1 = require("./BackstageManager");
/** Backstage Event class.
 * @deprecated in 3.6. Use [[BackstageManager.onToggled]] instead.
 * @public
 */
class BackstageEvent extends core_react_1.UiEvent {
} // eslint-disable-line deprecation/deprecation
exports.BackstageEvent = BackstageEvent;
/** Backstage React component.
 * @deprecated in 3.6. Use [[BackstageComposer]] instead.
 * @public
 */
class Backstage extends React.Component {
    constructor(props) {
        super(props);
        this._handleBackstageEvent = (args) => {
            this.setState({ isVisible: args.isVisible });
        };
        this._onClose = () => {
            Backstage.hide(); // eslint-disable-line deprecation/deprecation
            /* istanbul ignore else */
            if (this.props.onClose)
                this.props.onClose();
        };
        this.setIsOpen(!!this.props.isVisible);
        this.state = {
            isVisible: UiFramework_1.UiFramework.backstage.isOpen,
        };
    }
    /** Shows the Backstage */
    static show() {
        UiFramework_1.UiFramework.backstage.open();
    }
    /** Hides the Backstage */
    static hide() {
        UiFramework_1.UiFramework.backstage.close();
    }
    /** Get CommandItemDef that will toggle display of Backstage and allow iconSpec to be overridden */
    static getBackstageToggleCommand(overrideIconSpec) {
        return BackstageManager_1.BackstageManager.getBackstageToggleCommand(overrideIconSpec);
    }
    /** Command that toggles the Backstage */
    static get backstageToggleCommand() {
        return this.getBackstageToggleCommand();
    }
    componentDidMount() {
        Backstage.onBackstageEvent.addListener(this._handleBackstageEvent); // eslint-disable-line deprecation/deprecation
    }
    componentWillUnmount() {
        Backstage.onBackstageEvent.removeListener(this._handleBackstageEvent); // eslint-disable-line deprecation/deprecation
    }
    componentDidUpdate(prevProps) {
        if (this.props.isVisible !== prevProps.isVisible)
            this.setIsOpen(!!this.props.isVisible);
    }
    setIsOpen(isOpen) {
        if (isOpen) {
            UiFramework_1.UiFramework.backstage.open();
        }
        else {
            UiFramework_1.UiFramework.backstage.close();
        }
    }
    render() {
        Backstage.isBackstageVisible = this.state.isVisible; // eslint-disable-line deprecation/deprecation
        let header = null;
        if (this.props.header)
            header = this.props.header;
        return (React.createElement(SafeAreaContext_1.SafeAreaContext.Consumer, null, (safeAreaInsets) => (React.createElement(appui_layout_react_1.Backstage, { className: this.props.className, header: header, isOpen: this.state.isVisible, onClose: this._onClose, safeAreaInsets: safeAreaInsets, showOverlay: this.props.showOverlay, style: this.props.style }, this.props.children))));
    }
}
exports.Backstage = Backstage;
Backstage.onBackstageEvent = new BackstageEvent(); // eslint-disable-line deprecation/deprecation
//# sourceMappingURL=Backstage.js.map