/*---------------------------------------------------------------------------------------------
 * 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 { Rectangle } from "@itwin/core-react/internal";
import { getWidgetState, updateFloatingWidgetState, } from "./WidgetStateHelpers.js";
/** @internal */
export const category = "appui-react:layout";
/** Helper that returns a plain object. Prevents from adding an instance that is not `immerable` to the state.
 * @internal
 */
export function toRectangleProps(rectangle) {
    if (rectangle) {
        return {
            bottom: rectangle.bottom,
            left: rectangle.left,
            right: rectangle.right,
            top: rectangle.top,
        };
    }
    return new Rectangle().toProps();
}
/** @internal */
export function setRectangleProps(props, bounds) {
    props.left = bounds.left;
    props.right = bounds.right;
    props.top = bounds.top;
    props.bottom = bounds.bottom;
}
/** @internal */
export function setPointProps(props, point) {
    props.x = point.x;
    props.y = point.y;
}
/** @internal */
export function setSizeProps(props, size) {
    props.height = size.height;
    props.width = size.width;
}
/** @internal */
export function initSizeProps(obj, key, size) {
    if (obj[key] && size) {
        setSizeProps(obj[key], size);
        return;
    }
    obj[key] = size
        ? {
            height: size.height,
            width: size.width,
        }
        : undefined;
}
/** @internal */
export function initRectangleProps(obj, key, rectangle) {
    const rect = rectangle;
    if (obj[key] && rect) {
        setRectangleProps(obj[key], rect);
        return;
    }
    obj[key] = rect
        ? {
            bottom: rect.bottom,
            left: rect.left,
            right: rect.right,
            top: rect.top,
        }
        : undefined;
}
/** @internal */
export function isToolSettingsFloatingWidget(state, id) {
    const widget = getWidgetState(state, id);
    const toolSettingsTabId = state.toolSettings?.tabId;
    return (widget.tabs.length === 1 &&
        widget.tabs[0] === toolSettingsTabId &&
        id in state.floatingWidgets.byId);
}
/** @internal */
export function updateHomeOfToolSettingsWidget(state, id, home) {
    if (!isToolSettingsFloatingWidget(state, id))
        return state;
    return updateFloatingWidgetState(state, id, {
        home,
    });
}
//# sourceMappingURL=NineZoneStateHelpers.js.map