var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (_) try {
            if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [0, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
/*! Built with http://stenciljs.com */
webcomponents.loadBundle("chunk-3f9ebe9f.js", ["exports", "./chunk-4381ee16.js", "./chunk-47f66c02.js"], function (e, t, r) { window.webcomponents.h, t.OuterSubscriber, t.OuterSubscriber, t.Subscriber, t.Subscriber; t.Subscriber, t.OuterSubscriber, t.OuterSubscriber, t.OuterSubscriber, t.Subscriber, t.OuterSubscriber, t.Subscriber, t.Subscriber, t.Subscriber; t.OuterSubscriber, t.Observable, t.Subscriber; t.Subscriber, t.OuterSubscriber, t.Subscriber, t.Subscriber, t.Subscriber, t.Subscriber, t.Subscriber, t.OuterSubscriber, t.OuterSubscriber, t.OuterSubscriber, t.Subscriber, t.Subscriber, t.Subscriber, t.Subscriber, t.Subscriber, t.Subscriber, t.Subscriber; var s = function () { function e(e, t, r) { void 0 === r && (r = !1), this.accumulator = e, this.seed = t, this.hasSeed = r; } return e.prototype.call = function (e, t) { return t.subscribe(new i(e, this.accumulator, this.seed, this.hasSeed)); }, e; }(), i = function (e) { function r(t, r, s, i) { var n = e.call(this, t) || this; return n.accumulator = r, n._seed = s, n.hasSeed = i, n.index = 0, n; } return t.__extends(r, e), Object.defineProperty(r.prototype, "seed", { get: function () { return this._seed; }, set: function (e) { this.hasSeed = !0, this._seed = e; }, enumerable: !0, configurable: !0 }), r.prototype._next = function (e) { if (this.hasSeed)
    return this._tryNext(e); this.seed = e, this.destination.next(e); }, r.prototype._tryNext = function (e) { var t, r = this.index++; try {
    t = this.accumulator(this.seed, e, r);
}
catch (e) {
    this.destination.error(e);
} this.seed = t, this.destination.next(t); }, r; }(t.Subscriber); t.OuterSubscriber, t.OuterSubscriber, t.Subscriber, t.Subscriber, t.OuterSubscriber, t.Subscriber, t.OuterSubscriber, t.OuterSubscriber, t.Subscriber, t.Subscriber; t.Subscriber; t.Subscriber, t.Subscriber, t.Subscriber, t.OuterSubscriber, t.Subscriber, t.Observable, t.OuterSubscriber, t.OuterSubscriber, t.Subscriber, t.OuterSubscriber, t.Subscriber, t.OuterSubscriber, t.OuterSubscriber, t.Subscriber; t.Subject; t.Subscriber, t.OuterSubscriber, t.OuterSubscriber, t.OuterSubscriber, console.log.bind(console); var n = new t.Subject, c = function (e, i) {
    if (i === void 0) { i = { timestamp: r.Util.getTimeStamp(), id: r.Util.getUUID() }; }
    return n.pipe(t.mergeMap(function (e) { return (function (e) { return e instanceof t.Observable; })(e) ? e : t.from([e]); }), function () { for (var e = [], r = 0; r < arguments.length; r++)
        e[r] = arguments[r]; return function (r) { var s = e[e.length - 1]; t.isScheduler(s) ? e.pop() : s = null; var i = e.length; return 1 !== i || s ? i > 0 ? t.concat(t.fromArray(e, s), r) : t.concat(t.empty(s), r) : t.concat(t.scalar(e[0]), r); }; }(i), function (e, t) { var r = !1; return arguments.length >= 2 && (r = !0), function (i) { return i.lift(new s(e, t, r)); }; }(e));
}; function a(e, t) { switch (t.type) {
    case "CONFIG_LOADING": return Object.assign({}, e, { isLoading: !0 });
    case "CONFIG_LOADED":
        var r_1 = Object.assign({}, e, { isLoading: !1 });
        return Object.keys(t.payload).forEach(function (e) { r_1[e] = t.payload[e]; }), r_1;
    case "SET_CONFIG":
        var s_1 = Object.assign({}, e);
        return Object.keys(t.payload).forEach(function (e) { s_1[e] = t.payload[e]; }), s_1;
    default: return e;
} } function u(e, t) { switch (t.type) {
    case "GITHUB_FOLLOWERS_LOADING": return Object.assign({}, e, { isLoading: !0 });
    case "GITHUB_FOLLOWERS_LOADED": return Object.assign({}, e, { isLoading: !1, users: t.payload });
    case "NAME_CHANGED": return Object.assign({}, e, { isLoading: !1, name: t.payload });
    default: return e;
} } var b = function (e, t, r, s) { return new (r || (r = Promise))(function (i, n) { function c(e) { try {
    u(s.next(e));
}
catch (e) {
    n(e);
} } function a(e) { try {
    u(s.throw(e));
}
catch (e) {
    n(e);
} } function u(e) { e.done ? i(e.value) : new r(function (t) { t(e.value); }).then(c, a); } u((s = s.apply(e, t || [])).next()); }); }; var o = Symbol(), h = Symbol();
    var S = /** @class */ (function () {
        function S(e) {
            if (this.baseUrl = "", this.loading = !0, this.authenticated = !1, this.errorMessage = "", e !== h)
                throw new Error("Cannot construct singleton");
            this.initStores(), this.base = t.BaseService.instance, this.config = this.base.config;
        }
        S.prototype.init = function (e, t) {
            if (t === void 0) { t = ""; }
            return b(this, void 0, void 0, function () { var _a, _b, _c, _d; return __generator(this, function (_e) {
                switch (_e.label) {
                    case 0:
                        "" !== t && (this.baseUrl = t), this.appRoot = e;
                        return [4 /*yield*/, this.base.initApp(this.baseUrl + "/assets/config.json", !0, "_emaApp")];
                    case 1:
                        _e.sent(), this.baseUrl = t, this.base.translation.use(this.config.get("language")), this.data = {};
                        _a = this.data;
                        return [4 /*yield*/, r.Util.fetchJson(this.baseUrl + "/assets/collection-manifest.json")];
                    case 2:
                        _a.manifest = _e.sent();
                        _b = this.data;
                        return [4 /*yield*/, r.Util.fetchJson(this.baseUrl + "/assets/data/mock-data.json")];
                    case 3:
                        _b.mockData = _e.sent();
                        _c = this.data;
                        return [4 /*yield*/, r.Util.fetchJson(this.baseUrl + "/assets/data/mock-dwp.json")];
                    case 4:
                        _c.dwpData = _e.sent();
                        _d = this.data;
                        return [4 /*yield*/, r.Util.fetchJson(this.baseUrl + "/assets/data/apiSwagger.json")];
                    case 5: return [2 /*return*/, (_d.swaggerData = _e.sent(), this.collectionManifest = this.data.manifest, this.parseComponents(), this.initHistory(), window.document.location.hostname.match("localhost") && this.config.set("dev", !0), this.data)];
                }
            }); });
        };
        S.prototype.initStores = function () { return b(this, void 0, void 0, function () { return __generator(this, function (_a) {
            this.store$ = c(u), this.config$ = c(a), this.store$.pipe().subscribe(function (e) { }), this.config$.pipe().subscribe(function (e) { });
            return [2 /*return*/];
        }); }); };
        S.prototype.initHistory = function () { "undefined" != typeof window && window.history; };
        S.prototype.parseComponents = function () {
            var _this = this;
            var e = [];
            r.Util.copy(this.data.manifest.components).map(function (t) { var r = t.tag, s = !1; _this.config.get("componentsIgnorePatterns").forEach(function (e) { r.match(e) && (s = !0); }), s || e.push(t); }), this.components = e;
        };
        S.prototype.showFlashMessage = function (e, t, r) {
            if (r === void 0) { r = 2e3; }
            document.querySelector("ema-flash-message").show(e, t, r);
        };
        Object.defineProperty(S, "instance", {
            get: function () { return this[o] || (this[o] = new S(h)), this[o]; },
            enumerable: true,
            configurable: true
        });
        return S;
    }());  e.AppService = S; });
