"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.StyledColumnReducer = exports.StyledColumnReady = exports.StyledColumnUnSuspendAll = exports.StyledColumnSuspendAll = exports.StyledColumnUnSuspend = exports.StyledColumnSuspend = exports.StyledColumnDeleteAll = exports.StyledColumnDelete = exports.StyledColumnEdit = exports.StyledColumnAdd = exports.STYLED_COLUMN_UNSUSPEND_ALL = exports.STYLED_COLUMN_SUSPEND_ALL = exports.STYLED_COLUMN_UNSUSPEND = exports.STYLED_COLUMN_SUSPEND = exports.STYLED_COLUMN_READY = exports.STYLED_COLUMN_DELETE_ALL = exports.STYLED_COLUMN_DELETE = exports.STYLED_COLUMN_EDIT = exports.STYLED_COLUMN_ADD = void 0;
const tslib_1 = require("tslib");
const GeneralConstants_1 = require("../../Utilities/Constants/GeneralConstants");
const AdaptableHelper_1 = tslib_1.__importDefault(require("../../Utilities/Helpers/AdaptableHelper"));
const utils_1 = require("./utils");
/**
 * @ReduxAction A Special Column Style has been added
 */
exports.STYLED_COLUMN_ADD = 'STYLED_COLUMN_ADD';
/**
 * @ReduxAction A Special Column Style has been edited
 */
exports.STYLED_COLUMN_EDIT = 'STYLED_COLUMN_EDIT';
/**
 * @ReduxAction A Special Column Style has been deleted
 */
exports.STYLED_COLUMN_DELETE = 'STYLED_COLUMN_DELETE';
/**
 * @ReduxAction Delete ALL Styled Columns
 */
exports.STYLED_COLUMN_DELETE_ALL = 'STYLED_COLUMN_DELETE_ALL';
/**
 * @ReduxAction StyledColumn Module is ready
 */
exports.STYLED_COLUMN_READY = 'STYLED_COLUMN_READY';
/**
 * @ReduxAction StyledColumn Module is suspended
 */
exports.STYLED_COLUMN_SUSPEND = 'STYLED_COLUMN_SUSPEND';
/**
 * @ReduxAction StyledColumn Module is unsuspended, or activated
 */
exports.STYLED_COLUMN_UNSUSPEND = 'STYLED_COLUMN_UNSUSPEND';
/**
 * @ReduxAction All StyledColumn Modules are suspended
 */
exports.STYLED_COLUMN_SUSPEND_ALL = 'STYLED_COLUMN_SUSPEND_ALL';
/**
 * @ReduxAction All StyledColumn Modules are unsuspended, or activated
 */
exports.STYLED_COLUMN_UNSUSPEND_ALL = 'STYLED_COLUMN_UNSUSPEND_ALL';
const StyledColumnAdd = (styledColumn) => ({
    type: exports.STYLED_COLUMN_ADD,
    StyledColumn: styledColumn,
});
exports.StyledColumnAdd = StyledColumnAdd;
const StyledColumnEdit = (styledColumn) => ({
    type: exports.STYLED_COLUMN_EDIT,
    StyledColumn: styledColumn,
});
exports.StyledColumnEdit = StyledColumnEdit;
const StyledColumnDelete = (styledColumn) => ({
    type: exports.STYLED_COLUMN_DELETE,
    StyledColumn: styledColumn,
});
exports.StyledColumnDelete = StyledColumnDelete;
const StyledColumnDeleteAll = () => ({
    type: exports.STYLED_COLUMN_DELETE_ALL,
});
exports.StyledColumnDeleteAll = StyledColumnDeleteAll;
const StyledColumnSuspend = (styledColumn) => ({
    type: exports.STYLED_COLUMN_SUSPEND,
    StyledColumn: styledColumn,
});
exports.StyledColumnSuspend = StyledColumnSuspend;
const StyledColumnUnSuspend = (styledColumn) => ({
    type: exports.STYLED_COLUMN_UNSUSPEND,
    StyledColumn: styledColumn,
});
exports.StyledColumnUnSuspend = StyledColumnUnSuspend;
const StyledColumnSuspendAll = () => ({
    type: exports.STYLED_COLUMN_SUSPEND_ALL,
});
exports.StyledColumnSuspendAll = StyledColumnSuspendAll;
const StyledColumnUnSuspendAll = () => ({
    type: exports.STYLED_COLUMN_UNSUSPEND_ALL,
});
exports.StyledColumnUnSuspendAll = StyledColumnUnSuspendAll;
const StyledColumnReady = (styledColumnState) => ({
    type: exports.STYLED_COLUMN_READY,
    StyledColumnState: styledColumnState,
});
exports.StyledColumnReady = StyledColumnReady;
const initialState = {
    StyledColumns: GeneralConstants_1.EMPTY_ARRAY,
};
const StyledColumnReducer = (state = initialState, action) => {
    let styledColumns;
    switch (action.type) {
        case exports.STYLED_COLUMN_ADD: {
            const actionStyledColumn = action.StyledColumn;
            AdaptableHelper_1.default.addAdaptableObjectPrimitives(actionStyledColumn);
            styledColumns = [].concat(state.StyledColumns);
            styledColumns.push(actionStyledColumn);
            return { ...state, StyledColumns: styledColumns };
        }
        case exports.STYLED_COLUMN_EDIT:
            const actionStyledColumn = action.StyledColumn;
            return {
                ...state,
                StyledColumns: state.StyledColumns.map((abObject) => abObject.Uuid === actionStyledColumn.Uuid ? actionStyledColumn : abObject),
            };
        case exports.STYLED_COLUMN_DELETE: {
            const actionStyledColumn = action.StyledColumn;
            return {
                ...state,
                StyledColumns: state.StyledColumns.filter((abObject) => abObject.Uuid !== actionStyledColumn.Uuid),
            };
        }
        case exports.STYLED_COLUMN_DELETE_ALL: {
            return {
                ...state,
                StyledColumns: [],
            };
        }
        case exports.STYLED_COLUMN_SUSPEND: {
            return {
                ...state,
                StyledColumns: (0, utils_1.changeIsSuspendInList)(action.StyledColumn, state.StyledColumns, true),
            };
        }
        case exports.STYLED_COLUMN_UNSUSPEND: {
            return {
                ...state,
                StyledColumns: (0, utils_1.changeIsSuspendInList)(action.StyledColumn, state.StyledColumns, false),
            };
        }
        case exports.STYLED_COLUMN_SUSPEND_ALL: {
            return {
                ...state,
                StyledColumns: (0, utils_1.suspendAllInList)(state.StyledColumns),
            };
        }
        case exports.STYLED_COLUMN_UNSUSPEND_ALL: {
            return {
                ...state,
                StyledColumns: (0, utils_1.unsuspendAllInList)(state.StyledColumns),
            };
        }
        default:
            return state;
    }
};
exports.StyledColumnReducer = StyledColumnReducer;
