"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.addWidgetToolSettings = exports.addDockedToolSettings = void 0;
const immer_1 = require("immer");
const appui_abstract_1 = require("@itwin/appui-abstract");
const NineZoneStateHelpers_1 = require("./NineZoneStateHelpers");
const TabLocation_1 = require("../TabLocation");
/** Adds a docked tool settings.
 * @internal
 */
function addDockedToolSettings(state, tabId, hidden = false) {
    if (state.toolSettings)
        // eslint-disable-next-line deprecation/deprecation
        throw new appui_abstract_1.UiError(NineZoneStateHelpers_1.category, "Tool settings already exist");
    if (!(tabId in state.tabs))
        // eslint-disable-next-line deprecation/deprecation
        throw new appui_abstract_1.UiError(NineZoneStateHelpers_1.category, "Tab does not exist", undefined, () => ({
            tabId,
        }));
    const location = (0, TabLocation_1.getTabLocation)(state, tabId);
    if (location)
        // eslint-disable-next-line deprecation/deprecation
        throw new appui_abstract_1.UiError(NineZoneStateHelpers_1.category, "Tab is already in a widget", undefined, () => ({ tabId, widgetId: location.widgetId }));
    return (0, immer_1.default)(state, (stateDraft) => {
        stateDraft.toolSettings = {
            tabId,
            type: "docked",
            hidden,
        };
    });
}
exports.addDockedToolSettings = addDockedToolSettings;
/** Adds a widget tool settings.
 * @internal
 */
function addWidgetToolSettings(state, tabId) {
    if (state.toolSettings)
        // eslint-disable-next-line deprecation/deprecation
        throw new appui_abstract_1.UiError(NineZoneStateHelpers_1.category, "Tool settings already exist");
    if (!(tabId in state.tabs))
        // eslint-disable-next-line deprecation/deprecation
        throw new appui_abstract_1.UiError(NineZoneStateHelpers_1.category, "Tab does not exist", undefined, () => ({
            tabId,
        }));
    const location = (0, TabLocation_1.getTabLocation)(state, tabId);
    if (!location)
        // eslint-disable-next-line deprecation/deprecation
        throw new appui_abstract_1.UiError(NineZoneStateHelpers_1.category, "Tab is not in a widget", undefined, () => ({
            tabId,
        }));
    return (0, immer_1.default)(state, (stateDraft) => {
        stateDraft.toolSettings = {
            tabId,
            type: "widget",
        };
    });
}
exports.addWidgetToolSettings = addWidgetToolSettings;
//# sourceMappingURL=ToolSettingsStateHelpers.js.map