/*---------------------------------------------------------------------------------------------
 * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
 * See LICENSE.md in the project root for license terms and full copyright notice.
 *--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
 * @module Base
 */
import * as React from "react";
import { createStore } from "zustand";
import { useStoreWithEqualityFn } from "zustand/traditional";
import { shallow } from "zustand/shallow";
import { assert } from "@itwin/core-bentley";
import { createNineZoneState } from "../state/NineZoneState.js";
/** @internal */
export const LayoutStoreContext = React.createContext(undefined);
LayoutStoreContext.displayName = "appui:LayoutStoreContext";
/** @internal */
export function createLayoutStore(args) {
    return createStore(() => createNineZoneState(args));
}
/** @internal */
export function useLayoutStore() {
    const store = React.useContext(LayoutStoreContext);
    assert(!!store, "LayoutStoreContext is not defined");
    return store;
}
/** @internal */
export function useLayout(selector, multipleSlices = false) {
    const store = useLayoutStore();
    return useStoreWithEqualityFn(store, selector, multipleSlices ? shallow : undefined);
}
const optionalLayoutStore = createStore(() => undefined);
/** @internal */
export function useOptionalLayout(selector, multipleSlices = false) {
    const store = React.useContext(LayoutStoreContext);
    const slice = useStoreWithEqualityFn(store ?? optionalLayoutStore, selector, multipleSlices ? shallow : undefined);
    return slice;
}
//# sourceMappingURL=LayoutStore.js.map