/*---------------------------------------------------------------------------------------------
 * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
 * See LICENSE.md in the project root for license terms and full copyright notice.
 *--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
 * @module Hooks
 */
import { useEffect, useState } from "react";
import { SessionStateActionId } from "../redux/SessionState.js";
import { SyncUiEventDispatcher } from "../syncui/SyncUiEventDispatcher.js";
import { UiFramework } from "../UiFramework.js";
/** React hook that maintains the active IModelConnection. For this hook to work properly the
 * IModelConnection must be set using UiFramework.setIModelConnection method. This also requires
 * that the host app includes the UiFramework reducer into its Redux store.
 * @public
 */
export function useActiveIModelConnection() {
    const [activeConnection, setActiveConnection] = useState(UiFramework.getIModelConnection());
    useEffect(() => {
        return SyncUiEventDispatcher.onSyncUiEvent.addListener((args) => {
            // eslint-disable-next-line deprecation/deprecation
            const eventIds = [SessionStateActionId.SetIModelConnection];
            if (eventIds.some((value) => args.eventIds.has(value.toLowerCase()))) {
                setActiveConnection(UiFramework.getIModelConnection());
            }
        });
    }, [activeConnection]);
    return activeConnection;
}
//# sourceMappingURL=useActiveIModelConnection.js.map