"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CellSummaryApiImpl = void 0;
const tslib_1 = require("tslib");
const ApiBase_1 = require("./ApiBase");
const ModuleConstants = tslib_1.__importStar(require("../../Utilities/Constants/ModuleConstants"));
const InternalRedux = tslib_1.__importStar(require("../../Redux/ActionsReducers/InternalRedux"));
const Enums_1 = require("../../AdaptableState/Common/Enums");
class CellSummaryApiImpl extends ApiBase_1.ApiBase {
    openCellSummaryPopupSettingsPanel() {
        this.showModulePopup(ModuleConstants.CellSummaryModuleId);
    }
    getCurrentCellSummaryOperation() {
        return this.getAdaptableState().Internal.CellSummary.CellSummaryOperation;
    }
    getCustomCellSummaryOperations() {
        return this.getCellSummaryOptions().customCellSummaryOperations ?? [];
    }
    setCurrentCellSummaryOperation(operation) {
        this.dispatchAction(InternalRedux.CellSummaryChangeOperation(operation));
    }
    getCellSummaryOperationValue(operation) {
        const cellSummary = this.getAdaptableState().Internal.CellSummary.CellSummaryInfo;
        if (!cellSummary) {
            return 'N/A';
        }
        switch (operation) {
            case Enums_1.SummaryOperation.Sum:
                return cellSummary.Sum;
            case Enums_1.SummaryOperation.Average:
                return cellSummary.Average;
            case Enums_1.SummaryOperation.Median:
                return cellSummary.Median;
            case Enums_1.SummaryOperation.Mode:
                return cellSummary.Mode;
            case Enums_1.SummaryOperation.Max:
                return cellSummary.Max;
            case Enums_1.SummaryOperation.Min:
                return cellSummary.Min;
            case Enums_1.SummaryOperation.Distinct:
                return cellSummary.Distinct;
            case Enums_1.SummaryOperation.Count:
                return cellSummary.Count;
            case Enums_1.SummaryOperation.Std_Deviation:
                return cellSummary.Std_Deviation;
            case Enums_1.SummaryOperation.Only:
                return cellSummary.Only;
            case Enums_1.SummaryOperation.Weighted_Average:
                return cellSummary.Weighted_Average;
            default:
                return cellSummary[operation];
        }
    }
    getCurrentCellSummaryOperationValue() {
        const cellSummaryOperation = this.getCurrentCellSummaryOperation();
        const summaryOperation = typeof cellSummaryOperation === 'string'
            ? cellSummaryOperation
            : cellSummaryOperation.operationName;
        return this.getCellSummaryOperationValue(summaryOperation);
    }
}
exports.CellSummaryApiImpl = CellSummaryApiImpl;
