"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DashboardReducer = exports.DashboardSetPinnedToolbars = exports.DashboardReady = exports.DashboardSetTitle = exports.DashboardCloseToolbar = exports.DashboardSetTabs = exports.DashboardSetFloatingPosition = exports.DashboardSetIsInline = exports.DashboardSetIsHidden = exports.DashboardSetIsFloating = exports.DashboardSetIsCollapsed = exports.DashboardSetActiveTabIndex = exports.DashboardSetModuleButtons = exports.DASHBOARD_READY = exports.DASHBOARD_SET_TITLE = exports.DASHBOARD_CLOSE_TOOLBAR = exports.DASHBOARD_SET_PINNED_TOOLBARS = exports.DASHBOARD_SET_TABS = exports.DASHBOARD_SET_FLOATING_POSITION = exports.DASHBOARD_SET_IS_HIDDEN = exports.DASHBOARD_SET_IS_INLINE = exports.DASHBOARD_SET_IS_FLOATING = exports.DASHBOARD_SET_IS_COLLAPSED = exports.DASHBOARD_ACTIVE_TAB_INDEX_CHANGE = exports.DASHBOARD_SET_MODULE_BUTTONS = void 0;
const GeneralConstants_1 = require("../../Utilities/Constants/GeneralConstants");
/**
 * @ReduxAction The Module Buttons have been set in the Dashboard
 */
exports.DASHBOARD_SET_MODULE_BUTTONS = 'DASHBOARD_SET_MODULE_BUTTONS';
/**
 * @ReduxAction Active tab has changed
 */
exports.DASHBOARD_ACTIVE_TAB_INDEX_CHANGE = 'DASHBOARD_ACTIVE_TAB_INDEX_CHANGE';
/**
 * @ReduxAction Collapsed Mode has changed
 */
exports.DASHBOARD_SET_IS_COLLAPSED = 'DASHBOARD_SET_IS_COLLAPSED';
/**
 * @ReduxAction Floating Mode has changed
 */
exports.DASHBOARD_SET_IS_FLOATING = 'DASHBOARD_SET_IS_FLOATING';
/**
 * @ReduxAction Inline Mode has changed
 */
exports.DASHBOARD_SET_IS_INLINE = 'DASHBOARD_SET_IS_INLINE';
/**
 * @ReduxAction Visibility has changed
 */
exports.DASHBOARD_SET_IS_HIDDEN = 'DASHBOARD_SET_IS_HIDDEN';
/**
 * @ReduxAction Floating position has changed
 */
exports.DASHBOARD_SET_FLOATING_POSITION = 'DASHBOARD_SET_FLOATING_POSITION';
/**
 * @ReduxAction New Dashboard Tabs have been set
 */
exports.DASHBOARD_SET_TABS = 'DASHBOARD_SET_TABS';
/**
 * @ReduxAction Set Pinned Toolbars Contents
 */
exports.DASHBOARD_SET_PINNED_TOOLBARS = 'DASHBOARD_SET_PINNED_TOOLBARS';
/**
 * @ReduxAction A Toolbar has been closed
 */
exports.DASHBOARD_CLOSE_TOOLBAR = 'DASHBOARD_CLOSE_TOOLBAR';
/**
 * @ReduxAction Dashboard Title has been set
 */
exports.DASHBOARD_SET_TITLE = 'DASHBOARD_SET_TITLE';
/**
 * @ReduxAction Dashboard is ready
 */
exports.DASHBOARD_READY = 'DASHBOARD_READY';
const DashboardSetModuleButtons = (moduleButtons) => ({
    type: exports.DASHBOARD_SET_MODULE_BUTTONS,
    moduleButtons: moduleButtons,
});
exports.DashboardSetModuleButtons = DashboardSetModuleButtons;
const DashboardSetActiveTabIndex = (ActiveTabIndex) => ({
    type: exports.DASHBOARD_ACTIVE_TAB_INDEX_CHANGE,
    ActiveTabIndex,
});
exports.DashboardSetActiveTabIndex = DashboardSetActiveTabIndex;
const DashboardSetIsCollapsed = (IsCollapsed) => ({
    type: exports.DASHBOARD_SET_IS_COLLAPSED,
    IsCollapsed,
});
exports.DashboardSetIsCollapsed = DashboardSetIsCollapsed;
const DashboardSetIsFloating = (IsFloating) => ({
    type: exports.DASHBOARD_SET_IS_FLOATING,
    IsFloating,
});
exports.DashboardSetIsFloating = DashboardSetIsFloating;
const DashboardSetIsHidden = (IsHidden) => ({
    type: exports.DASHBOARD_SET_IS_HIDDEN,
    IsHidden,
});
exports.DashboardSetIsHidden = DashboardSetIsHidden;
const DashboardSetIsInline = (IsInline) => ({
    type: exports.DASHBOARD_SET_IS_INLINE,
    IsInline,
});
exports.DashboardSetIsInline = DashboardSetIsInline;
const DashboardSetFloatingPosition = (FloatingPosition) => ({
    type: exports.DASHBOARD_SET_FLOATING_POSITION,
    FloatingPosition,
});
exports.DashboardSetFloatingPosition = DashboardSetFloatingPosition;
const DashboardSetTabs = (Tabs) => ({
    type: exports.DASHBOARD_SET_TABS,
    Tabs,
});
exports.DashboardSetTabs = DashboardSetTabs;
const DashboardCloseToolbar = (toolbar) => ({
    toolbar,
    type: exports.DASHBOARD_CLOSE_TOOLBAR,
});
exports.DashboardCloseToolbar = DashboardCloseToolbar;
const DashboardSetTitle = (title) => ({
    type: exports.DASHBOARD_SET_TITLE,
    title,
});
exports.DashboardSetTitle = DashboardSetTitle;
const DashboardReady = (dashboardState) => ({
    type: exports.DASHBOARD_READY,
    dashboardState,
});
exports.DashboardReady = DashboardReady;
const DashboardSetPinnedToolbars = (pinnedToolbars) => ({
    type: exports.DASHBOARD_SET_PINNED_TOOLBARS,
    pinnedToolbars,
});
exports.DashboardSetPinnedToolbars = DashboardSetPinnedToolbars;
const initialState = {
    Tabs: GeneralConstants_1.EMPTY_ARRAY,
    ActiveTabIndex: 0,
    IsCollapsed: false,
    IsFloating: false,
    IsHidden: false,
    IsInline: false,
    FloatingPosition: { x: 100, y: 100 },
    ModuleButtons: ['SettingsPanel'],
    DashboardTitle: '',
};
const DashboardReducer = (state = initialState, action) => {
    switch (action.type) {
        case exports.DASHBOARD_SET_MODULE_BUTTONS: {
            const actionTyped = action;
            const dashboardModuleButtons = actionTyped.moduleButtons;
            return Object.assign({}, state, {
                ModuleButtons: dashboardModuleButtons,
                VisibleButtons: undefined,
            });
        }
        case exports.DASHBOARD_ACTIVE_TAB_INDEX_CHANGE: {
            const { ActiveTabIndex } = action;
            return { ...state, ActiveTabIndex };
        }
        case exports.DASHBOARD_SET_IS_COLLAPSED: {
            const { IsCollapsed } = action;
            return { ...state, IsCollapsed };
        }
        case exports.DASHBOARD_SET_IS_FLOATING: {
            const { IsFloating } = action;
            return { ...state, IsFloating };
        }
        case exports.DASHBOARD_SET_IS_HIDDEN: {
            const { IsHidden } = action;
            return { ...state, IsHidden };
        }
        case exports.DASHBOARD_SET_IS_INLINE: {
            const { IsInline } = action;
            return { ...state, IsInline };
        }
        case exports.DASHBOARD_SET_FLOATING_POSITION: {
            const { FloatingPosition } = action;
            return { ...state, FloatingPosition };
        }
        case exports.DASHBOARD_SET_TABS: {
            const { Tabs } = action;
            return { ...state, Tabs };
        }
        case exports.DASHBOARD_CLOSE_TOOLBAR: {
            const actionTyped = action;
            const tabs = [].concat(state.Tabs);
            const currentTab = tabs[state.ActiveTabIndex];
            if (currentTab) {
                const toolbars = [].concat(currentTab.Toolbars);
                const index = toolbars.findIndex((t) => t == actionTyped.toolbar);
                toolbars.splice(index, 1);
                currentTab.Toolbars = toolbars;
                return { ...state, Tabs: tabs };
            }
            else {
                return { ...state };
            }
        }
        case exports.DASHBOARD_SET_TITLE: {
            const actionTyped = action;
            return Object.assign({}, state, { DashboardTitle: actionTyped.title });
        }
        case exports.DASHBOARD_SET_PINNED_TOOLBARS: {
            const actionTyped = action;
            return Object.assign({}, state, { PinnedToolbars: actionTyped.pinnedToolbars });
        }
        default:
            return state;
    }
};
exports.DashboardReducer = DashboardReducer;
