"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DataChangeHistoryModule = void 0;
const tslib_1 = require("tslib");
const AdaptableModuleBase_1 = require("./AdaptableModuleBase");
const ModuleConstants = tslib_1.__importStar(require("../Utilities/Constants/ModuleConstants"));
const DataChangeHistoryStatusBarContent_1 = require("../View/DataChangeHistory/DataChangeHistoryStatusBarContent");
class DataChangeHistoryModule extends AdaptableModuleBase_1.AdaptableModuleBase {
    constructor(api) {
        super(ModuleConstants.DataChangeHistoryModuleId, ModuleConstants.DataChangeHistoryFriendlyName, 'target', 'DataChangeHistoryPopup', 'Provides an overview of all previous changes, giving the possibility to undo specific changes', api);
        this.isListeningToCellDataChanges = false;
    }
    onAdaptableReady() {
        this.api.internalApi.initializeDataChangeHistory();
        this.checkListenToCellDataChanged();
    }
    getAgGridModuleDependencies() {
        return ['ClientSideRowModelModule'];
    }
    shouldListenToDataChanges() {
        return this.api.dataChangeHistoryApi.getDataChangeHistoryMode() === 'ACTIVE';
    }
    checkListenToCellDataChanged() {
        if (!this.isListeningToCellDataChanges) {
            if (this.shouldListenToDataChanges()) {
                this.setupCellDataChangeListener();
                this.isListeningToCellDataChanges = true;
            }
        }
    }
    setupCellDataChangeListener() {
        this.api.internalApi
            .getDataService()
            .on('CellDataChanged', (cellDataChangedInfo) => {
            if (this.isListeningToCellDataChanges && this.isDataChangeLoggable(cellDataChangedInfo)) {
                this.api.dataChangeHistoryApi.addDataChangeHistoryEntry(cellDataChangedInfo);
            }
        });
    }
    getPopupMaxWidth() {
        return 1000;
    }
    hasNamedQueryReferences() {
        return false;
    }
    isDataChangeLoggable(cellDataChangedInfo) {
        if (cellDataChangedInfo.trigger === 'undo' || cellDataChangedInfo.trigger === 'aggChange') {
            return false;
        }
        if (this.api.optionsApi.getDataChangeHistoryOptions().showDataChange) {
            return this.api.optionsApi.getDataChangeHistoryOptions().showDataChange(cellDataChangedInfo);
        }
        return true;
    }
    getViewProperties() {
        return {
            getStatusBarPanelProps: () => {
                return {
                    triggerActionOnWrapperClick: false,
                    content: DataChangeHistoryStatusBarContent_1.DataChangeHistoryStatusBarContent,
                };
            },
        };
    }
}
exports.DataChangeHistoryModule = DataChangeHistoryModule;
