"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 Base
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.getTabLocation = exports.isPanelTabLocation = exports.isPopoutTabLocation = exports.isFloatingTabLocation = void 0;
const WidgetLocation_1 = require("./WidgetLocation");
/** @internal */
function isFloatingTabLocation(location) {
    return "floatingWidgetId" in location;
}
exports.isFloatingTabLocation = isFloatingTabLocation;
/** @internal */
function isPopoutTabLocation(location) {
    return "popoutWidgetId" in location;
}
exports.isPopoutTabLocation = isPopoutTabLocation;
/** @internal */
function isPanelTabLocation(location) {
    return "side" in location;
}
exports.isPanelTabLocation = isPanelTabLocation;
/** Returns a tab location or `undefined` if tab is not in a widget.
 * @internal
 */
function getTabLocation(state, id) {
    let widgetId;
    for (const [, widget] of Object.entries(state.widgets)) {
        const index = widget.tabs.indexOf(id);
        if (index >= 0) {
            widgetId = widget.id;
            break;
        }
    }
    if (!widgetId)
        return undefined;
    const location = (0, WidgetLocation_1.getWidgetLocation)(state, widgetId);
    if (!location)
        return undefined;
    if ((0, WidgetLocation_1.isFloatingWidgetLocation)(location))
        return {
            floatingWidgetId: widgetId,
            widgetId,
        };
    if ((0, WidgetLocation_1.isPopoutWidgetLocation)(location))
        return {
            popoutWidgetId: widgetId,
            widgetId,
        };
    return {
        side: location.side,
        widgetId,
    };
}
exports.getTabLocation = getTabLocation;
//# sourceMappingURL=TabLocation.js.map