"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 Widget
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.useMainPanelWidgetId = exports.usePanelWidgetId = void 0;
const React = require("react");
const LayoutStore_1 = require("../base/LayoutStore");
const Panel_1 = require("../widget-panels/Panel");
const Widget_1 = require("./Widget");
/** @internal */
function usePanelWidgetId() {
    const side = React.useContext(Panel_1.PanelSideContext);
    const widgetId = React.useContext(Widget_1.WidgetIdContext);
    if (!side || widgetId === undefined)
        return undefined;
    return widgetId;
}
exports.usePanelWidgetId = usePanelWidgetId;
/** @internal */
function useMainPanelWidgetId() {
    const side = React.useContext(Panel_1.PanelSideContext);
    const widgetId = React.useContext(Widget_1.WidgetIdContext);
    return (0, LayoutStore_1.useLayout)((state) => {
        if (!side)
            return undefined;
        const widgets = state.panels[side].widgets;
        const mainWidget = (0, Panel_1.isHorizontalPanelSide)(side)
            ? widgets[widgets.length - 1]
            : widgets[0];
        return mainWidget === widgetId ? widgetId : undefined;
    });
}
exports.useMainPanelWidgetId = useMainPanelWidgetId;
//# sourceMappingURL=usePanelWidgetId.js.map