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-d865bc0c.js", ["exports", "./chunk-3da2b85b.js", "./chunk-58852bd6.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; var s = function () { function e(e, t, r) { this.nextOrObserver = e, this.error = t, this.complete = r; } return e.prototype.call = function (e, t) { return t.subscribe(new n(e, this.nextOrObserver, this.error, this.complete)); }, e; }(), n = function (e) { function r(r, s, n, i) { var o = e.call(this, r) || this; return o._tapNext = t.noop, o._tapError = t.noop, o._tapComplete = t.noop, o._tapError = n || t.noop, o._tapComplete = i || t.noop, t.isFunction(s) ? (o._context = o, o._tapNext = s) : s && (o._context = s, o._tapNext = s.next || t.noop, o._tapError = s.error || t.noop, o._tapComplete = s.complete || t.noop), o; } return t.__extends(r, e), r.prototype._next = function (e) { try {
    this._tapNext.call(this._context, e);
}
catch (e) {
    return void this.destination.error(e);
} this.destination.next(e); }, r.prototype._error = function (e) { try {
    this._tapError.call(this._context, e);
}
catch (e) {
    return void this.destination.error(e);
} this.destination.error(e); }, r.prototype._complete = function () { try {
    this._tapComplete.call(this._context);
}
catch (e) {
    return void this.destination.error(e);
} return this.destination.complete(); }, r; }(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 i = 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 o(e, this.accumulator, this.seed, this.hasSeed)); }, e; }(), o = function (e) { function r(t, r, s, n) { var i = e.call(this, t) || this; return i.accumulator = r, i._seed = s, i.hasSeed = n, i.index = 0, i; } 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;
    var a = /** @class */ (function () {
        function a() {
        }
        a.isObservable = function (e) { return e instanceof t.Observable; };
        a.log = function () { return console.log.bind(console); };
        return a;
    }());  var u = new t.Subject, c = function (e, s) {
    if (s === void 0) { s = { timestamp: r.Util.getTimeStamp(), id: r.Util.getUUID() }; }
    return u.pipe(t.mergeMap(function (e) { return a.isObservable(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 n = e.length; return 1 !== n || s ? n > 0 ? t.concat(t.fromArray(e, s), r) : t.concat(t.empty(s), r) : t.concat(t.scalar(e[0]), r); }; }(s), function (e, t) { var r = !1; return arguments.length >= 2 && (r = !0), function (s) { return s.lift(new i(e, t, r)); }; }(e));
}, b = function (e) { return function () {
    var t = [];
    for (var _i = 0; _i < arguments.length; _i++) {
        t[_i] = arguments[_i];
    }
    var r = e.call.apply(e, [null].concat(t));
    return u.next(r), a.isObservable(r.payload) && u.next(r.payload), r;
}; }; function p(e, t) { switch (t.type) {
    case "CONFIG_LOADING": return Object.assign({}, e, { isLoading: !0, timestamp: r.Util.getTimeStamp() });
    case "CONFIG_LOADED":
        var s_1 = Object.assign({}, e, { isLoading: !1 });
        return Object.keys(t.payload).forEach(function (e) { s_1[e] = t.payload[e]; }), s_1.timestamp = r.Util.getTimeStamp(), s_1;
    case "SET_CONFIG":
        var n_1 = Object.assign({}, e);
        return Object.keys(t.payload).forEach(function (e) { n_1[e] = t.payload[e]; }), n_1.timestamp = r.Util.getTimeStamp(), n_1;
    default: return e;
} } var h = "undefined" != typeof window && window, l = "undefined" != typeof self && "undefined" != typeof WorkerGlobalScope && self instanceof WorkerGlobalScope && self, d = void 0 !== r.global && r.global, f = h || d || l; function y(e, t) { return void 0 === t && (t = null), new x({ method: "GET", url: e, headers: t }); } function m(e, t, r) { return new x({ method: "POST", url: e, body: t, headers: r }); } function S(e, t) { return new x({ method: "DELETE", url: e, headers: t }); } function O(e, t, r) { return new x({ method: "PUT", url: e, body: t, headers: r }); } function g(e, t, r) { return new x({ method: "PATCH", url: e, body: t, headers: r }); } var w = t.map(function (e, t) { return e.response; }); function v(e, t) { return w(new x({ method: "GET", url: e, responseType: "json", headers: t })); } var x = function (e) { function r(t) { var r = e.call(this) || this, s = { async: !0, createXHR: function () { return this.crossDomain ? function () { if (f.XMLHttpRequest)
        return new f.XMLHttpRequest; if (f.XDomainRequest)
        return new f.XDomainRequest; throw new Error("CORS is not supported by your browser"); }() : function () { if (f.XMLHttpRequest)
        return new f.XMLHttpRequest; var e = void 0; try {
        for (var t = ["Msxml2.XMLHTTP", "Microsoft.XMLHTTP", "Msxml2.XMLHTTP.4.0"], r = 0; r < 3; r++)
            try {
                if (e = t[r], new f.ActiveXObject(e))
                    break;
            }
            catch (e) { }
        return new f.ActiveXObject(e);
    }
    catch (e) {
        throw new Error("XMLHttpRequest is not supported by your browser");
    } }(); }, crossDomain: !0, withCredentials: !1, headers: {}, method: "GET", responseType: "json", timeout: 0 }; if ("string" == typeof t)
    s.url = t;
else
    for (var n in t)
        t.hasOwnProperty(n) && (s[n] = t[n]); return r.request = s, r; } var s; return t.__extends(r, e), r.prototype._subscribe = function (e) { return new _(e, this.request); }, r.create = ((s = function (e) { return new r(e); }).get = y, s.post = m, s.delete = S, s.put = O, s.patch = g, s.getJSON = v, s), r; }(t.Observable), _ = function (e) { function r(t, r) { var s = e.call(this, t) || this; s.request = r, s.done = !1; var n = r.headers = r.headers || {}; return r.crossDomain || n["X-Requested-With"] || (n["X-Requested-With"] = "XMLHttpRequest"), "Content-Type" in n || f.FormData && r.body instanceof f.FormData || void 0 === r.body || (n["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8"), r.body = s.serializeBody(r.body, r.headers["Content-Type"]), s.send(), s; } return t.__extends(r, e), r.prototype.next = function (e) { this.done = !0; var t = this.xhr, r = this.request, s = this.destination, n = new T(e, t, r); s.next(n); }, r.prototype.send = function () { var e = this.request, r = this.request, s = r.user, n = r.method, i = r.url, o = r.async, a = r.password, u = r.headers, c = r.body, b = e.createXHR, p = t.tryCatch(b).call(e); if (p === t.errorObject)
    this.error(t.errorObject.e);
else {
    if (this.xhr = p, this.setupEvents(p, e), (s ? t.tryCatch(p.open).call(p, n, i, o, s, a) : t.tryCatch(p.open).call(p, n, i, o)) === t.errorObject)
        return this.error(t.errorObject.e), null;
    if (o && (p.timeout = e.timeout, p.responseType = e.responseType), "withCredentials" in p && (p.withCredentials = !!e.withCredentials), this.setHeaders(p, u), (c ? t.tryCatch(p.send).call(p, c) : t.tryCatch(p.send).call(p)) === t.errorObject)
        return this.error(t.errorObject.e), null;
} return p; }, r.prototype.serializeBody = function (e, t) { if (!e || "string" == typeof e)
    return e; if (f.FormData && e instanceof f.FormData)
    return e; if (t) {
    var r = t.indexOf(";");
    -1 !== r && (t = t.substring(0, r));
} switch (t) {
    case "application/x-www-form-urlencoded": return Object.keys(e).map(function (t) { return encodeURIComponent(t) + "=" + encodeURIComponent(e[t]); }).join("&");
    case "application/json": return JSON.stringify(e);
    default: return e;
} }, r.prototype.setHeaders = function (e, t) { for (var r in t)
    t.hasOwnProperty(r) && e.setRequestHeader(r, t[r]); }, r.prototype.setupEvents = function (e, t) { var r, s, n = t.progressSubscriber; function i(e) { var t = i, r = t.subscriber, s = t.progressSubscriber, n = t.request; s && s.error(e), r.error(new C(this, n)); } (e.ontimeout = i, i.request = t, i.subscriber = this, i.progressSubscriber = n, e.upload && "withCredentials" in e) && (n && (r = function (e) { r.progressSubscriber.next(e); }, f.XDomainRequest ? e.onprogress = r : e.upload.onprogress = r, r.progressSubscriber = n), s = function (e) { var t = s, r = t.progressSubscriber, n = t.subscriber, i = t.request; r && r.error(e), n.error(new E("ajax error", this, i)); }, e.onerror = s, s.request = t, s.subscriber = this, s.progressSubscriber = n); function o(e) { } function a(e) { var t = a, r = t.subscriber, s = t.progressSubscriber, n = t.request; if (4 === this.readyState) {
    var i = 1223 === this.status ? 204 : this.status, o = "text" === this.responseType ? this.response || this.responseText : this.response;
    0 === i && (i = o ? 200 : 0), i < 400 ? (s && s.complete(), r.next(e), r.complete()) : (s && s.error(e), r.error(new E("ajax error " + i, this, n)));
} } e.onreadystatechange = o, o.subscriber = this, o.progressSubscriber = n, o.request = t, e.onload = a, a.subscriber = this, a.progressSubscriber = n, a.request = t; }, r.prototype.unsubscribe = function () { var t = this.done, r = this.xhr; !t && r && 4 !== r.readyState && "function" == typeof r.abort && r.abort(), e.prototype.unsubscribe.call(this); }, r; }(t.Subscriber), T = function () { return function (e, t, r) { this.originalEvent = e, this.xhr = t, this.request = r, this.status = t.status, this.responseType = t.responseType || r.responseType, this.response = j(this.responseType, t); }; }(), E = function (e) { function r(t, s, n) { var i = e.call(this, t) || this; return i.name = "AjaxError", i.message = t, i.xhr = s, i.request = n, i.status = s.status, i.responseType = s.responseType || n.responseType, i.response = j(i.responseType, s), Object.setPrototypeOf(i, r.prototype), i; } return t.__extends(r, e), r; }(Error); function j(e, t) { switch (e) {
    case "json": return "response" in t ? t.responseType ? t.response : JSON.parse(t.response || t.responseText || "null") : JSON.parse(t.responseText || "null");
    case "xml": return t.responseXML;
    case "text":
    default: return "response" in t ? t.response : t.responseText;
} } var C = function (e) { function r(t, s) { var n = e.call(this, "ajax timeout", t, s) || this; return n.name = "AjaxTimeoutError", Object.setPrototypeOf(n, r.prototype), n; } return t.__extends(r, e), r; }(E), D = x.create; var L = { loadConfig: b(function (e) { return "string" == typeof e ? { type: "CONFIG_LOADING", payload: D(e).pipe(t.map(function (e) { return { type: "CONFIG_LOADED", payload: e.response }; })) } : { type: "CONFIG_LOADED", payload: e }; }), setConfig: b(function (e) { return { type: "SET_CONFIG", payload: 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, timestamp: r.Util.getTimeStamp(), name: t.payload });
    default: return e;
} } var N = { changeName: b(function (e) { return ({ type: "NAME_CHANGED", payload: e }); }), loadGithubFollowers: b(function (e) { var r = "https://api.github.com/users/" + e.username + "/followers"; return { type: "GITHUB_FOLLOWERS_LOADING", payload: D(r).pipe(t.map(function (e) { return t.map(e.response, "login"); }), t.map(function (e) { return ({ type: "GITHUB_FOLLOWERS_LOADED", payload: e }); })) }; }) }; var R = function (e, t, r, s) { return new (r || (r = Promise))(function (n, i) { function o(e) { try {
    u(s.next(e));
}
catch (e) {
    i(e);
} } function a(e) { try {
    u(s.throw(e));
}
catch (e) {
    i(e);
} } function u(e) { e.done ? n(e.value) : new r(function (t) { t(e.value); }).then(o, a); } u((s = s.apply(e, t || [])).next()); }); }; var q = Symbol(), A = Symbol();
    var H = /** @class */ (function () {
        function H(e) {
            if (this.actions = N, this.baseUrl = "", this.loading = !0, this.authenticated = !1, this.errorMessage = "", e !== A)
                throw new Error("Cannot construct singleton");
            this.initStores(), this.base = t.BaseService.instance, this.config = this.base.config, this.user = new t.User("visitor"), this.test();
        }
        H.prototype.init = function (e, t) {
            if (t === void 0) { t = ""; }
            return R(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)];
                }
            }); });
        };
        H.prototype.initStores = function () { return R(this, void 0, void 0, function () { var e; return __generator(this, function (_a) {
            this.store$ = c(U, {}), this.config$ = c(p), this.store$.pipe((e = a.log(), function (t) { return t.lift(new s(e, void 0, void 0)); })).subscribe(function (e) { }), this.config$.pipe().subscribe(function (e) { }), this.actions.changeName("Bob"), L.loadConfig(this.baseUrl + "/assets/config.json");
            return [2 /*return*/];
        }); }); };
        H.prototype.test = function () { console.log(this.user.roles), this.user.addRole("AUTHENTICATED"), this.user.addRole("DEVELOPER"), console.log(this.user.roles), this.user.removeRole("AUTHENTICATED"), console.log(this.user.roles), console.log(this.user.hasRole("DEVELOPER")), console.log(this.user.hasRole("AUTHENTICATED")); };
        H.prototype.initHistory = function () { "undefined" != typeof window && window.history; };
        H.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;
        };
        H.prototype.showFlashMessage = function (e, t, r) {
            if (r === void 0) { r = 2e3; }
            document.querySelector("ema-flash-message").show(e, t, r);
        };
        Object.defineProperty(H, "instance", {
            get: function () { return this[q] || (this[q] = new H(A)), this[q]; },
            enumerable: true,
            configurable: true
        });
        return H;
    }());  e.AppService = H; });
