"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ModalFrontstageComposer = exports.useActiveModalFrontstageInfo = void 0;
/*---------------------------------------------------------------------------------------------
 * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
 * See LICENSE.md in the project root for license terms and full copyright notice.
 *--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
 * @module Frontstage
 */
const React = require("react");
const ModalFrontstage_1 = require("../frontstage/ModalFrontstage");
const UiFramework_1 = require("../UiFramework");
/** @internal */
function useActiveModalFrontstageInfo() {
    const [activeModalFrontstageInfo, setActiveModalFrontstageInfo] = React.useState(UiFramework_1.UiFramework.frontstages.activeModalFrontstage);
    React.useEffect(() => {
        const handleModalFrontstageChangedEvent = (args // eslint-disable-line deprecation/deprecation
        ) => {
            setActiveModalFrontstageInfo(args.modalFrontstageCount === 0
                ? undefined
                : UiFramework_1.UiFramework.frontstages.activeModalFrontstage);
        };
        UiFramework_1.UiFramework.frontstages.onModalFrontstageChangedEvent.addListener(handleModalFrontstageChangedEvent);
        return () => {
            UiFramework_1.UiFramework.frontstages.onModalFrontstageChangedEvent.removeListener(handleModalFrontstageChangedEvent);
        };
    }, [setActiveModalFrontstageInfo]);
    return activeModalFrontstageInfo;
}
exports.useActiveModalFrontstageInfo = useActiveModalFrontstageInfo;
/** @internal */
function ModalFrontstageComposer({ stageInfo, }) {
    const handleCloseModal = React.useCallback(() => UiFramework_1.UiFramework.frontstages.closeModalFrontstage(), []);
    if (!stageInfo)
        return null;
    const { title, content, appBarRight } = stageInfo;
    return (React.createElement(ModalFrontstage_1.ModalFrontstage, { isOpen: true, title: title, closeModal: handleCloseModal, appBarRight: appBarRight }, content));
}
exports.ModalFrontstageComposer = ModalFrontstageComposer;
//# sourceMappingURL=ModalFrontstageComposer.js.map