"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.useBackstageManager = exports.useIsBackstageOpen = exports.BackstageManager = void 0;
const React = require("react");
const UiFramework_1 = require("../UiFramework");
const InternalBackstageManager_1 = require("./InternalBackstageManager");
/** Controls backstage.
 * @public
 * @deprecated in 4.15.0. Use {@link UiFramework.backstage} instead.
 */
class BackstageManager {
    constructor() {
        this.internal = new InternalBackstageManager_1.InternalBackstageManager();
    }
    /**
     * Override internal implementation for a mock
     * @internal For tests only.
     */
    mockInternal(internal) {
        this.internal = internal;
    }
    /** Event raised when backstage is opened or closed. */
    get onToggled() {
        return this.internal.onToggled;
    }
    get isOpen() {
        return this.internal.isOpen;
    }
    open() {
        return this.internal.open();
    }
    close() {
        return this.internal.close();
    }
    toggle() {
        return this.internal.toggle();
    }
    // eslint-disable-next-line deprecation/deprecation
    getBackstageToggleCommand(overrideIconSpec) {
        return this.internal.getBackstageToggleCommand(overrideIconSpec);
    }
    /** Get CommandItemDef that will toggle display of Backstage and allow iconSpec to be overridden. */
    // eslint-disable-next-line deprecation/deprecation
    static getBackstageToggleCommand(overrideIconSpec) {
        // eslint-disable-next-line deprecation/deprecation
        return UiFramework_1.UiFramework.backstage.getBackstageToggleCommand(overrideIconSpec);
    }
}
exports.BackstageManager = BackstageManager;
/** Hook that returns isOpen flag of the backstage.
 * @public
 */
const useIsBackstageOpen = (manager) => {
    const [isOpen, setIsOpen] = React.useState(manager.isOpen);
    React.useEffect(() => {
        setIsOpen(manager.isOpen);
        return manager.onToggled.addListener((args) => {
            setIsOpen(args.isOpen);
        });
    }, [manager]);
    return isOpen;
};
exports.useIsBackstageOpen = useIsBackstageOpen;
/** Hook that returns backstage manager.
 * @public
 */
const useBackstageManager = () => {
    const [manager] = React.useState(UiFramework_1.UiFramework.backstage);
    return manager;
};
exports.useBackstageManager = useBackstageManager;
//# sourceMappingURL=BackstageManager.js.map