"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.d = function(exports1, definition) {
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
(()=>{
    __webpack_require__.o = function(obj, prop) {
        return Object.prototype.hasOwnProperty.call(obj, prop);
    };
})();
(()=>{
    __webpack_require__.r = function(exports1) {
        if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports1, '__esModule', {
            value: true
        });
    };
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
    DataSource: ()=>DataSource,
    LocalDataSource: ()=>LocalDataSource
});
const index_js_namespaceObject = require("../collection/index.js");
function _define_property(obj, key, value) {
    if (key in obj) Object.defineProperty(obj, key, {
        value: value,
        enumerable: true,
        configurable: true,
        writable: true
    });
    else obj[key] = value;
    return obj;
}
class DataSource {
    get app() {
        return this.dataSourceManager.app;
    }
    get key() {
        return this.options.key;
    }
    get displayName() {
        return this.options.displayName;
    }
    get status() {
        return this.options.status;
    }
    get errorMessage() {
        return this.options.errorMessage;
    }
    get collections() {
        return this.collectionManager.getCollections() || [];
    }
    getOptions() {
        return this.options;
    }
    setOptions(options) {
        Object.assign(this.options, options);
    }
    getOption(key) {
        return this.options[key];
    }
    addReloadCallback(callback) {
        if (this.reloadCallbacks.includes(callback)) return;
        this.reloadCallbacks.push(callback);
    }
    removeReloadCallback(callback) {
        this.reloadCallbacks = this.reloadCallbacks.filter((cb)=>cb !== callback);
    }
    async reload() {
        const dataSource = await this.getDataSource();
        this.setOptions(dataSource);
        this.collectionManager.setCollections(dataSource.collections || []);
        this.reloadCallbacks.forEach((callback)=>callback(dataSource.collections));
        return this.options;
    }
    constructor(options, dataSourceManager){
        _define_property(this, "options", void 0);
        _define_property(this, "dataSourceManager", void 0);
        _define_property(this, "collectionManager", void 0);
        _define_property(this, "reloadCallbacks", void 0);
        this.options = options;
        this.dataSourceManager = dataSourceManager;
        this.reloadCallbacks = [];
        this.collectionManager = new index_js_namespaceObject.CollectionManager(options.collections, this);
    }
}
class LocalDataSource extends DataSource {
    getDataSource() {
        return {
            collections: this.collections
        };
    }
}
var __webpack_export_target__ = exports;
for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
    value: true
});
