"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.StatusBarModule = void 0;
const tslib_1 = require("tslib");
const AdaptableModuleBase_1 = require("./AdaptableModuleBase");
const ModuleConstants = tslib_1.__importStar(require("../Utilities/Constants/ModuleConstants"));
class StatusBarModule extends AdaptableModuleBase_1.AdaptableModuleBase {
    constructor(api) {
        super(ModuleConstants.StatusBarModuleId, ModuleConstants.StatusBarFriendlyName, 'statusbar', 'StatusBarPopup', 'Configure AdapTable Status Bar', api);
    }
    syncStateWithOptions(agGridAdaptablePanels) {
        const statusPanelsState = this.api.statusBarApi.getAdaptableStatusBars();
        /**
         * Grid config determines how many adaptable status panels are rendered.
         * This dictates the state.
         * - if a status panel is removed from ag-grid, it's sub-panels are made available;
         * - if a new status panel is added it is added to state with an empty list
         */
        const newStatusPanelsState = agGridAdaptablePanels.map((agGridStatusPanel) => {
            let statusPanelState = statusPanelsState.find((statusPanel) => statusPanel.Key === agGridStatusPanel.key);
            // no state found
            if (!statusPanelState) {
                statusPanelState = {
                    Key: agGridStatusPanel.key,
                    StatusBarPanels: [],
                };
            }
            return statusPanelState;
        });
        this.api.statusBarApi.setStatusBarPanels(newStatusPanelsState);
    }
    isModuleAvailable() {
        return super.isModuleAvailable() && this.api.statusBarApi.getAgGridStatusPanels().length > 0;
    }
}
exports.StatusBarModule = StatusBarModule;
