"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 State
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.useReduxFrameworkState = void 0;
const React = require("react");
const shim_1 = require("use-sync-external-store/shim");
const UiFramework_1 = require("../UiFramework");
/* eslint-disable deprecation/deprecation */
/** @internal */
function useReduxFrameworkState(selector) {
    const subscribe = React.useCallback((onStoreChange) => {
        const reduxStore = UiFramework_1.UiFramework.reduxStore;
        if (!reduxStore)
            return () => { };
        return reduxStore.subscribe(onStoreChange);
    }, []);
    const getSnapshot = React.useCallback(() => {
        const reduxStore = UiFramework_1.UiFramework.reduxStore;
        const state = reduxStore?.getState();
        const frameworkState = state?.[UiFramework_1.UiFramework.frameworkStateKey];
        return selector(frameworkState);
    }, [selector]);
    return (0, shim_1.useSyncExternalStore)(subscribe, getSnapshot);
}
exports.useReduxFrameworkState = useReduxFrameworkState;
//# sourceMappingURL=useReduxFrameworkState.js.map