"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.useMaximizedWidgetTabBarHandle = exports.useMaximizedFloatingWidget = exports.useMaximizedSection = exports.useMaximizedPanel = exports.useMaximizedPanelLayout = exports.useIsMaximizedWidget = void 0;
require("./useMaximizedWidget.scss");
const React = require("react");
const Widget_1 = require("../../layout/widget/Widget");
const MaximizedWidget_1 = require("./MaximizedWidget");
const LayoutStore_1 = require("../../layout/base/LayoutStore");
const WidgetLocation_1 = require("../../layout/state/WidgetLocation");
const PreviewFeatures_1 = require("../PreviewFeatures");
/** @internal */
function useIsMaximizedWidget() {
    const widgetId = React.useContext(Widget_1.WidgetIdContext);
    const maximizedWidgetId = useMaximizedWidgetId();
    if (maximizedWidgetId === undefined)
        return false;
    return widgetId === maximizedWidgetId;
}
exports.useIsMaximizedWidget = useIsMaximizedWidget;
/** @internal */
function useMaximizedPanelLayout(side) {
    const location = useMaximizedPanelWidgetLocation();
    return {
        "uifw-preview-enableMaximizedWidget_panel-layout": location?.side === side,
    };
}
exports.useMaximizedPanelLayout = useMaximizedPanelLayout;
/** @internal */
function useMaximizedPanel(side) {
    const isMaximized = useIsMaximizedPanel(side);
    if (!isMaximized)
        return undefined;
    return {
        "uifw-preview-enableMaximizedWidget_panel": isMaximized,
    };
}
exports.useMaximizedPanel = useMaximizedPanel;
/** @internal */
function useMaximizedSection(widgetId) {
    const location = useMaximizedPanelWidgetLocation();
    if (!location)
        return undefined;
    return {
        "uifw-preview-enableMaximizedWidget_section": location.widgetId === widgetId,
        "uifw-preview-enableMaximizedWidget_section-sibling": location.widgetId !== widgetId,
    };
}
exports.useMaximizedSection = useMaximizedSection;
function useIsMaximizedPanel(side) {
    const location = useMaximizedPanelWidgetLocation();
    return location?.side === side;
}
function useMaximizedPanelWidgetLocation() {
    const location = useMaximizedWidgetLocation();
    if (!location)
        return undefined;
    if (!(0, WidgetLocation_1.isPanelWidgetLocation)(location))
        return undefined;
    return location;
}
function useMaximizedWidgetLocation() {
    const widgetId = useMaximizedWidgetId();
    const location = (0, LayoutStore_1.useLayout)((state) => {
        if (!widgetId)
            return undefined;
        return (0, WidgetLocation_1.getWidgetLocation)(state, widgetId);
    }, true);
    if (!widgetId || !location)
        return undefined;
    return { ...location, widgetId };
}
function useMaximizedWidgetId() {
    const { maximizedWidget } = React.useContext(MaximizedWidget_1.MaximizedWidgetContext);
    const preview = (0, PreviewFeatures_1.usePreviewFeatures)();
    const enabled = preview.enableMaximizedFloatingWidget || preview.enableMaximizedPanelWidget;
    if (!enabled)
        return undefined;
    return maximizedWidget;
}
/** @internal */
function useMaximizedFloatingWidget() {
    const isMaximizedWidget = useIsMaximizedWidget();
    if (!isMaximizedWidget)
        return {
            style: {},
            classNames: {},
        };
    return {
        style: {
            transform: "unset",
            height: "unset",
            width: "unset",
            "max-height": "unset",
            "max-width": "unset",
        },
        classNames: { "uifw-preview-enableMaximizedWidget_floatingWidget": true },
    };
}
exports.useMaximizedFloatingWidget = useMaximizedFloatingWidget;
/** @internal */
function useMaximizedWidgetTabBarHandle() {
    const isMaximizedWidget = useIsMaximizedWidget();
    return {
        "uifw-preview-enableMaximizedWidget_widget-tabBar": isMaximizedWidget,
    };
}
exports.useMaximizedWidgetTabBarHandle = useMaximizedWidgetTabBarHandle;
//# sourceMappingURL=useMaximizedWidget.js.map