import { ApiService } from '../api/api.service';
import { LocalstorageService } from '../localstorage/localstorage.service';
import { CacheService } from '../cache/cache.service';
import { FetchService } from '../fetch/fetch.service';
var AppService = /** @class */ (function () {
    function AppService(options) {
        this.options = options;
        this.Localstorage = new LocalstorageService(this);
        this.Cache = new CacheService(this);
        this.Api = new ApiService(this);
        this.Fetch = new FetchService(this);
        // initiate other components when available
        for (var _i = 0, _a = Object.keys(window['$$$SHEETBASE_COMPONENTS']); _i < _a.length; _i++) {
            var key = _a[_i];
            this[key] = new window['$$$SHEETBASE_COMPONENTS'][key](this);
        }
    }
    AppService.prototype.api = function () {
        return this.Api;
    };
    AppService.prototype.fetch = function () {
        return this.Fetch;
    };
    AppService.prototype.localstorage = function () {
        return this.Localstorage;
    };
    AppService.prototype.cache = function () {
        return this.Cache;
    };
    AppService.prototype.auth = function () {
        if (!this.Auth) {
            throw new Error('No auth component.');
        }
        return this.Auth;
    };
    AppService.prototype.database = function () {
        if (!this.Database) {
            throw new Error('No database component.');
        }
        return this.Database;
    };
    AppService.prototype.storage = function () {
        if (!this.Storage) {
            throw new Error('No storage component.');
        }
        return this.Storage;
    };
    AppService.prototype.mail = function () {
        if (!this.Mail) {
            throw new Error('No mail component.');
        }
        return this.Mail;
    };
    return AppService;
}());
var AppsService = /** @class */ (function () {
    function AppsService() {
        this.apps = {};
    }
    AppsService.prototype.createApp = function (options, name) {
        if (name === void 0) { name = 'DEFAULT'; }
        if (!!this.apps[name]) {
            throw new Error("An app exists with the name \"" + name + "\".");
        }
        this.apps[name] = new AppService(options);
        return this.apps[name];
    };
    AppsService.prototype.getApp = function (name) {
        if (name === void 0) { name = 'DEFAULT'; }
        var app = this.apps[name];
        if (!app) {
            throw new Error("No app exists with the name \"" + name + "\". Please run initializeApp() first.");
        }
        return app;
    };
    return AppsService;
}());
export { AppsService, AppService };
