"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 State
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.SessionStateReducer = exports.sessionStateMapDispatchToProps = exports.SessionStateActions = exports.SessionStateActionId = void 0;
const redux_ts_1 = require("./redux-ts");
/** Action Ids used by Redux and to send sync UI components. Typically used to refresh visibility or enable state of control.
 * Since these are also used as sync ids they should be in lowercase.
 * @note This is used by sync UI event APIs.
 * @public
 * @deprecated in 4.15.0. Use your preferred state management library instead.
 */
var SessionStateActionId;
(function (SessionStateActionId) {
    SessionStateActionId["SetNumItemsSelected"] = "sessionstate:set-num-items-selected";
    SessionStateActionId["SetAvailableSelectionScopes"] = "sessionstate:set-available-selection-scopes";
    SessionStateActionId["SetSelectionScope"] = "sessionstate:set-selection-scope";
    SessionStateActionId["SetActiveIModelId"] = "sessionstate:set-active-imodelid";
    SessionStateActionId["SetIModelConnection"] = "sessionstate:set-imodel-connection";
    SessionStateActionId["SetDefaultIModelViewportControlId"] = "sessionstate:set-default-viewportid";
    SessionStateActionId["SetDefaultViewId"] = "sessionstate:set-default-viewid";
    SessionStateActionId["SetDefaultViewState"] = "sessionstate:set-default-view-state";
    SessionStateActionId["UpdateCursorMenu"] = "sessionstate:update-cursor-menu";
})(SessionStateActionId || (exports.SessionStateActionId = SessionStateActionId = {}));
const defaultSelectionScope = {
    id: "element",
    label: "Element",
};
/** Used on first call of SessionStateReducer. */
const initialSessionState = {
    /** number of selected items in Presentation Selection */
    numItemsSelected: 0,
    /** initialize to only support "Element" scope, this will be overwritten when iModelConnection is established */
    availableSelectionScopes: [defaultSelectionScope],
    /** initialize to active selection scope to "Element", this will be overwritten when iModelConnection is established */
    activeSelectionScope: defaultSelectionScope.id,
    /** set to iModelId if an iModel is active else it is an empty string, so initialize to empty string */
    iModelId: "",
    defaultIModelViewportControlId: undefined,
    defaultViewId: undefined,
    defaultViewState: undefined,
    iModelConnection: undefined,
    cursorMenuData: undefined, // @deprecated in 4.11.0. Use {@link SessionState.cursorMenuPayload} instead
    cursorMenuPayload: undefined,
};
/** An object with a function that creates each SessionStateReducer that can be handled by our reducer.
 * @public
 * @deprecated in 4.15.0. Use your preferred state management library instead.
 */
exports.SessionStateActions = {
    setActiveIModelId: (iModelId) => (0, redux_ts_1.createAction)(SessionStateActionId.SetActiveIModelId, iModelId),
    setAvailableSelectionScopes: (availableSelectionScopes) => (0, redux_ts_1.createAction)(SessionStateActionId.SetAvailableSelectionScopes, availableSelectionScopes),
    setDefaultIModelViewportControlId: (iModelViewportControlId) => (0, redux_ts_1.createAction)(SessionStateActionId.SetDefaultIModelViewportControlId, iModelViewportControlId),
    setDefaultViewId: (viewId) => (0, redux_ts_1.createAction)(SessionStateActionId.SetDefaultViewId, viewId),
    setDefaultViewState: (viewState) => (0, redux_ts_1.createAction)(SessionStateActionId.SetDefaultViewState, viewState),
    setNumItemsSelected: (numSelected) => (0, redux_ts_1.createAction)(SessionStateActionId.SetNumItemsSelected, numSelected),
    setIModelConnection: (iModelConnection) => (0, redux_ts_1.createAction)(SessionStateActionId.SetIModelConnection, iModelConnection),
    setSelectionScope: (activeSelectionScope) => (0, redux_ts_1.createAction)(SessionStateActionId.SetSelectionScope, activeSelectionScope),
    updateCursorMenu: (cursorMenuData) => (0, redux_ts_1.createAction)(SessionStateActionId.UpdateCursorMenu, cursorMenuData),
};
/** Object that contains available actions that modify SessionState. Parent control's props should
 * extend from SessionStateActionsProps before using this in Redux 'connect' function.
 * @beta
 * @deprecated in 4.15.0. Use your preferred state management library instead.
 */
exports.sessionStateMapDispatchToProps = { ...exports.SessionStateActions };
/** Handles actions to update SessionState.
 * @public
 * @deprecated in 4.15.0. Use your preferred state management library instead.
 */
function SessionStateReducer(state = initialSessionState, action) {
    switch (action.type) {
        case SessionStateActionId.SetNumItemsSelected: {
            if (undefined !== action.payload)
                return { ...state, numItemsSelected: action.payload };
            else
                return { ...state, numItemsSelected: 0 };
        }
        case SessionStateActionId.SetAvailableSelectionScopes: {
            const payloadArray = [];
            action.payload.forEach((scope) => payloadArray.push(scope));
            if (undefined !== action.payload)
                return { ...state, availableSelectionScopes: payloadArray };
            else
                return { ...state, availableSelectionScopes: [defaultSelectionScope] };
        }
        case SessionStateActionId.SetSelectionScope: {
            if (undefined !== action.payload)
                return { ...state, activeSelectionScope: action.payload };
            else
                return { ...state, activeSelectionScope: defaultSelectionScope.id };
        }
        case SessionStateActionId.SetActiveIModelId: {
            if (undefined !== action.payload)
                return { ...state, iModelId: action.payload };
            else
                return { ...state, iModelId: "" };
        }
        case SessionStateActionId.SetDefaultIModelViewportControlId: {
            return { ...state, defaultIModelViewportControlId: action.payload };
        }
        case SessionStateActionId.SetDefaultViewId: {
            return { ...state, defaultViewId: action.payload };
        }
        case SessionStateActionId.SetDefaultViewState: {
            return { ...state, defaultViewState: action.payload };
        }
        case SessionStateActionId.SetIModelConnection: {
            return { ...state, iModelConnection: action.payload };
        }
        case SessionStateActionId.UpdateCursorMenu: {
            return {
                ...state,
                cursorMenuPayload: action.payload,
                cursorMenuData: action.payload,
            };
        }
    }
    return state;
}
exports.SessionStateReducer = SessionStateReducer;
//# sourceMappingURL=SessionState.js.map