"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExportReducer = exports.DestinationSelect = exports.ExportApply = exports.ExportReady = exports.ReportDelete = exports.ReportEdit = exports.ReportAdd = exports.ReportSelect = exports.DESTINATION_SELECT = exports.EXPORT_READY = exports.REPORT_DELETE = exports.REPORT_EDIT = exports.REPORT_ADD = exports.REPORT_SELECT = exports.EXPORT_APPLY = void 0;
const tslib_1 = require("tslib");
const GeneralConstants_1 = require("../../Utilities/Constants/GeneralConstants");
const AdaptableHelper_1 = tslib_1.__importDefault(require("../../Utilities/Helpers/AdaptableHelper"));
/**
 * @ReduxAction Export has been applied
 */
exports.EXPORT_APPLY = 'EXPORT_APPLY';
/**
 * @ReduxAction A Report has been selected
 */
exports.REPORT_SELECT = 'REPORT_SELECT';
/**
 * @ReduxAction A Report has been added
 */
exports.REPORT_ADD = 'REPORT_ADD';
/**
 * @ReduxAction A Report has been edited
 */
exports.REPORT_EDIT = 'REPORT_EDIT';
/**
 * @ReduxAction A Report has been deleted
 */
exports.REPORT_DELETE = 'REPORT_DELETE';
/**
 * @ReduxAction Export Module is ready
 */
exports.EXPORT_READY = 'EXPORT_READY';
/**
 * @ReduxAction A report Destination has been selected
 */
exports.DESTINATION_SELECT = 'DESTINATION_SELECT';
const ReportSelect = (SelectedReport) => ({
    type: exports.REPORT_SELECT,
    SelectedReport,
});
exports.ReportSelect = ReportSelect;
const ReportAdd = (report) => ({
    type: exports.REPORT_ADD,
    report,
});
exports.ReportAdd = ReportAdd;
const ReportEdit = (report) => ({
    type: exports.REPORT_EDIT,
    report,
});
exports.ReportEdit = ReportEdit;
const ReportDelete = (report) => ({
    type: exports.REPORT_DELETE,
    report,
});
exports.ReportDelete = ReportDelete;
const ExportReady = (exportState) => ({
    type: exports.EXPORT_READY,
    exportState,
});
exports.ExportReady = ExportReady;
const ExportApply = (Report, ExportDestination) => ({
    type: exports.EXPORT_APPLY,
    Report,
    ExportDestination,
});
exports.ExportApply = ExportApply;
const DestinationSelect = (SelectedDestination) => ({
    type: exports.DESTINATION_SELECT,
    SelectedDestination,
});
exports.DestinationSelect = DestinationSelect;
const initialState = {
    Reports: GeneralConstants_1.EMPTY_ARRAY,
};
const ExportReducer = (state = initialState, action) => {
    let reports;
    switch (action.type) {
        case exports.REPORT_SELECT:
            return Object.assign({}, state, {
                CurrentReport: action.SelectedReport,
            });
        case exports.REPORT_ADD: {
            const actionReport = action.report;
            AdaptableHelper_1.default.addUuidAndSource(actionReport);
            reports = [].concat(state.Reports);
            reports.push(actionReport);
            return Object.assign(Object.assign({}, state), { Reports: reports });
        }
        case exports.REPORT_EDIT:
            const actionReport = action.report;
            return Object.assign(Object.assign({}, state), { Reports: state.Reports.map((abObject) => abObject.Uuid === actionReport.Uuid ? actionReport : abObject) });
        case exports.REPORT_DELETE: {
            const actionReport = action.report;
            return Object.assign(Object.assign({}, state), { Reports: state.Reports.filter((abObject) => abObject.Uuid !== actionReport.Uuid) });
        }
        case exports.DESTINATION_SELECT:
            return Object.assign({}, state, {
                CurrentDestination: action.SelectedDestination,
            });
        default:
            return state;
    }
};
exports.ExportReducer = ExportReducer;
