/*---------------------------------------------------------------------------------------------
* 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
 */
import * as React from "react";
import { UiEvent } from "@itwin/core-react";
import { Backstage as NZ_Backstage } from "@itwin/appui-layout-react";
import { SafeAreaContext } from "../safearea/SafeAreaContext";
import { UiFramework } from "../UiFramework";
import { BackstageManager } from "./BackstageManager";
/** Backstage Event class.
 * @deprecated in 3.6. Use [[BackstageManager.onToggled]] instead.
 * @public
 */
export class BackstageEvent extends UiEvent {
} // eslint-disable-line deprecation/deprecation
/** Backstage React component.
 * @deprecated in 3.6. Use [[BackstageComposer]] instead.
 * @public
 */
export 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.backstage.isOpen,
        };
    }
    /** Shows the Backstage */
    static show() {
        UiFramework.backstage.open();
    }
    /** Hides the Backstage */
    static hide() {
        UiFramework.backstage.close();
    }
    /** Get CommandItemDef that will toggle display of Backstage and allow iconSpec to be overridden */
    static getBackstageToggleCommand(overrideIconSpec) {
        return 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.backstage.open();
        }
        else {
            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.Consumer, null, (safeAreaInsets) => (React.createElement(NZ_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))));
    }
}
Backstage.onBackstageEvent = new BackstageEvent(); // eslint-disable-line deprecation/deprecation
//# sourceMappingURL=Backstage.js.map