"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DataSetModule = void 0;
const tslib_1 = require("tslib");
const AdaptableModuleBase_1 = require("./AdaptableModuleBase");
const ModuleConstants = tslib_1.__importStar(require("../Utilities/Constants/ModuleConstants"));
const getObjectTagsViewItems_1 = require("./Utilities/getObjectTagsViewItems");
const DataSetStatusPanelPopover_1 = require("../View/DataSet/DataSetStatusPanelPopover");
const Uuid_1 = require("../PredefinedConfig/Uuid");
const DataSetSelector_1 = require("../View/DataSet/DataSetSelector");
class DataSetModule extends AdaptableModuleBase_1.AdaptableModuleBase {
    constructor(api) {
        super(ModuleConstants.DataSetModuleId, ModuleConstants.DataSetFriendlyName, 'data-set', 'DataSetPopup', 'Update the entire data source in AdapTable using pre-populated data sets', api);
    }
    onAdaptableReady() {
        this.api.dataSetApi.getDataSets().forEach((ds) => {
            if (!ds.Uuid) {
                ds.Uuid = (0, Uuid_1.createUuid)();
            }
        });
    }
    getModuleAdaptableObjects() {
        var _a, _b;
        return (_b = (_a = this.api.optionsApi.getDataSetOptions()) === null || _a === void 0 ? void 0 : _a.dataSets) !== null && _b !== void 0 ? _b : [];
    }
    hasNamedQueryReferences() {
        return false;
    }
    toView(dataSet) {
        var _a;
        return {
            items: [
                {
                    name: 'Settings',
                    label: 'Name',
                    values: [dataSet.name],
                },
                {
                    name: 'Settings',
                    label: 'Description',
                    values: [(_a = dataSet.description) !== null && _a !== void 0 ? _a : 'Not Specified'],
                },
                (0, getObjectTagsViewItems_1.getObjectTagsViewItems)(dataSet, this.api),
            ],
            abObject: dataSet,
        };
    }
    toViewAll() {
        return this.getModuleAdaptableObjects().map((dataSet) => this.toView(dataSet));
    }
    getViewProperties() {
        return {
            actions: [DataSetSelector_1.DataSetSelector],
            emptyView: 'No DataSets are provided',
            getStatusBarPanelProps: () => {
                var _a, _b;
                const content = (_b = (_a = this.api.dataSetApi.getCurrentDataSet()) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : this.moduleInfo.FriendlyName;
                return {
                    content: content,
                    popover: DataSetStatusPanelPopover_1.DataSetStatusPanelPopover,
                };
            },
        };
    }
}
exports.DataSetModule = DataSetModule;
