"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DataSetApiImpl = void 0;
const tslib_1 = require("tslib");
const ModuleConstants = tslib_1.__importStar(require("../../Utilities/Constants/ModuleConstants"));
const SystemRedux = tslib_1.__importStar(require("../../Redux/ActionsReducers/SystemRedux"));
const ApiBase_1 = require("./ApiBase");
const DataSetInternalApi_1 = require("../Internal/DataSetInternalApi");
class DataSetApiImpl extends ApiBase_1.ApiBase {
    constructor(_adaptable) {
        super(_adaptable);
        this.internalApi = new DataSetInternalApi_1.DataSetInternalApi(_adaptable);
    }
    getDataSets() {
        var _a, _b;
        return (_b = (_a = this.getDataSetOptions()) === null || _a === void 0 ? void 0 : _a.dataSets) !== null && _b !== void 0 ? _b : [];
    }
    getCurrentDataSet() {
        let currentDataSetName = this.getAdaptableState().System.CurrentDataSet;
        return this.getDataSetByName(currentDataSetName);
    }
    getDataSetByName(dataSetName) {
        return this.getDataSets().find((a) => a.name == dataSetName);
    }
    setDataSet(dataSetName) {
        const dataSet = this.getDataSetByName(dataSetName);
        if (this.checkItemExists(dataSet, dataSetName, 'Data Source')) {
            this.dispatchAction(SystemRedux.SystemDataSetSelect(dataSet));
        }
    }
    clearCurrentDataSet() {
        this.dispatchAction(SystemRedux.SystemDataSetSelect(null));
    }
    openDataSetSettingsPanel() {
        this.showModulePopup(ModuleConstants.DataSetModuleId);
    }
}
exports.DataSetApiImpl = DataSetApiImpl;
