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