var __extends = (this && this.__extends) || (function () {
    var extendStatics = Object.setPrototypeOf ||
        ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
        function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
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-3b741dc6.js", ["exports"], function (e) { window.webcomponents.h, function (e) { if (!e.fetch) {
    var t = { searchParams: "URLSearchParams" in e, iterable: "Symbol" in e && "iterator" in Symbol, blob: "FileReader" in e && "Blob" in e && function () { try {
            return new Blob, !0;
        }
        catch (e) {
            return !1;
        } }(), formData: "FormData" in e, arrayBuffer: "ArrayBuffer" in e };
    if (t.arrayBuffer)
        var i = ["[object Int8Array]", "[object Uint8Array]", "[object Uint8ClampedArray]", "[object Int16Array]", "[object Uint16Array]", "[object Int32Array]", "[object Uint32Array]", "[object Float32Array]", "[object Float64Array]"], o = function (e) { return e && DataView.prototype.isPrototypeOf(e); }, s = ArrayBuffer.isView || function (e) { return e && i.indexOf(Object.prototype.toString.call(e)) > -1; };
    d.prototype.append = function (e, t) { e = a(e), t = l(t); var i = this.map[e]; this.map[e] = i ? i + "," + t : t; }, d.prototype.delete = function (e) { delete this.map[a(e)]; }, d.prototype.get = function (e) { return e = a(e), this.has(e) ? this.map[e] : null; }, d.prototype.has = function (e) { return this.map.hasOwnProperty(a(e)); }, d.prototype.set = function (e, t) { this.map[a(e)] = l(t); }, d.prototype.forEach = function (e, t) { for (var i in this.map)
        this.map.hasOwnProperty(i) && e.call(t, this.map[i], i, this); }, d.prototype.keys = function () { var e = []; return this.forEach(function (t, i) { e.push(i); }), c(e); }, d.prototype.values = function () { var e = []; return this.forEach(function (t) { e.push(t); }), c(e); }, d.prototype.entries = function () { var e = []; return this.forEach(function (t, i) { e.push([i, t]); }), c(e); }, t.iterable && (d.prototype[Symbol.iterator] = d.prototype.entries);
    var n = ["DELETE", "GET", "HEAD", "OPTIONS", "POST", "PUT"];
    g.prototype.clone = function () { return new g(this, { body: this._bodyInit }); }, m.call(g.prototype), m.call(w.prototype), w.prototype.clone = function () { return new w(this._bodyInit, { status: this.status, statusText: this.statusText, headers: new d(this.headers), url: this.url }); }, w.error = function () { var e = new w(null, { status: 0, statusText: "" }); return e.type = "error", e; };
    var r = [301, 302, 303, 307, 308];
    w.redirect = function (e, t) { if (-1 === r.indexOf(t))
        throw new RangeError("Invalid status code"); return new w(null, { status: t, headers: { location: e } }); }, e.Headers = d, e.Request = g, e.Response = w, e.fetch = function (e, i) { return new Promise(function (o, s) { var n = new g(e, i), r = new XMLHttpRequest; r.onload = function () { var e, t, i = { status: r.status, statusText: r.statusText, headers: (e = r.getAllResponseHeaders() || "", t = new d, e.replace(/\r?\n[\t ]+/g, " ").split(/\r?\n/).forEach(function (e) { var i = e.split(":"), o = i.shift().trim(); if (o) {
            var s = i.join(":").trim();
            t.append(o, s);
        } }), t) }; i.url = "responseURL" in r ? r.responseURL : i.headers.get("X-Request-URL"); var s = "response" in r ? r.response : r.responseText; o(new w(s, i)); }, r.onerror = function () { s(new TypeError("Network request failed")); }, r.ontimeout = function () { s(new TypeError("Network request failed")); }, r.open(n.method, n.url, !0), "include" === n.credentials ? r.withCredentials = !0 : "omit" === n.credentials && (r.withCredentials = !1), "responseType" in r && t.blob && (r.responseType = "blob"), n.headers.forEach(function (e, t) { r.setRequestHeader(t, e); }), r.send(void 0 === n._bodyInit ? null : n._bodyInit); }); }, e.fetch.polyfill = !0;
} function a(e) { if ("string" != typeof e && (e = String(e)), /[^a-z0-9\-#$%&'*+.\^_`|~]/i.test(e))
    throw new TypeError("Invalid character in header field name"); return e.toLowerCase(); } function l(e) { return "string" != typeof e && (e = String(e)), e; } function c(e) { var i = { next: function () { var t = e.shift(); return { done: void 0 === t, value: t }; } }; return t.iterable && (i[Symbol.iterator] = function () { return i; }), i; } function d(e) { this.map = {}, e instanceof d ? e.forEach(function (e, t) { this.append(t, e); }, this) : Array.isArray(e) ? e.forEach(function (e) { this.append(e[0], e[1]); }, this) : e && Object.getOwnPropertyNames(e).forEach(function (t) { this.append(t, e[t]); }, this); } function h(e) { if (e.bodyUsed)
    return Promise.reject(new TypeError("Already read")); e.bodyUsed = !0; } function u(e) { return new Promise(function (t, i) { e.onload = function () { t(e.result); }, e.onerror = function () { i(e.error); }; }); } function p(e) { var t = new FileReader, i = u(t); return t.readAsArrayBuffer(e), i; } function f(e) { if (e.slice)
    return e.slice(0); var t = new Uint8Array(e.byteLength); return t.set(new Uint8Array(e)), t.buffer; } function m() { return this.bodyUsed = !1, this._initBody = function (e) { if (this._bodyInit = e, e)
    if ("string" == typeof e)
        this._bodyText = e;
    else if (t.blob && Blob.prototype.isPrototypeOf(e))
        this._bodyBlob = e;
    else if (t.formData && FormData.prototype.isPrototypeOf(e))
        this._bodyFormData = e;
    else if (t.searchParams && URLSearchParams.prototype.isPrototypeOf(e))
        this._bodyText = e.toString();
    else if (t.arrayBuffer && t.blob && o(e))
        this._bodyArrayBuffer = f(e.buffer), this._bodyInit = new Blob([this._bodyArrayBuffer]);
    else {
        if (!t.arrayBuffer || !ArrayBuffer.prototype.isPrototypeOf(e) && !s(e))
            throw new Error("unsupported BodyInit type");
        this._bodyArrayBuffer = f(e);
    }
else
    this._bodyText = ""; this.headers.get("content-type") || ("string" == typeof e ? this.headers.set("content-type", "text/plain;charset=UTF-8") : this._bodyBlob && this._bodyBlob.type ? this.headers.set("content-type", this._bodyBlob.type) : t.searchParams && URLSearchParams.prototype.isPrototypeOf(e) && this.headers.set("content-type", "application/x-www-form-urlencoded;charset=UTF-8")); }, t.blob && (this.blob = function () { var e = h(this); if (e)
    return e; if (this._bodyBlob)
    return Promise.resolve(this._bodyBlob); if (this._bodyArrayBuffer)
    return Promise.resolve(new Blob([this._bodyArrayBuffer])); if (this._bodyFormData)
    throw new Error("could not read FormData body as blob"); return Promise.resolve(new Blob([this._bodyText])); }, this.arrayBuffer = function () { return this._bodyArrayBuffer ? h(this) || Promise.resolve(this._bodyArrayBuffer) : this.blob().then(p); }), this.text = function () { var e, t, i, o = h(this); if (o)
    return o; if (this._bodyBlob)
    return e = this._bodyBlob, i = u(t = new FileReader), t.readAsText(e), i; if (this._bodyArrayBuffer)
    return Promise.resolve(function (e) { for (var t = new Uint8Array(e), i = new Array(t.length), o = 0; o < t.length; o++)
        i[o] = String.fromCharCode(t[o]); return i.join(""); }(this._bodyArrayBuffer)); if (this._bodyFormData)
    throw new Error("could not read FormData body as text"); return Promise.resolve(this._bodyText); }, t.formData && (this.formData = function () { return this.text().then(y); }), this.json = function () { return this.text().then(JSON.parse); }, this; } function g(e, t) { var i, o, s = (t = t || {}).body; if (e instanceof g) {
    if (e.bodyUsed)
        throw new TypeError("Already read");
    this.url = e.url, this.credentials = e.credentials, t.headers || (this.headers = new d(e.headers)), this.method = e.method, this.mode = e.mode, s || null == e._bodyInit || (s = e._bodyInit, e.bodyUsed = !0);
}
else
    this.url = String(e); if (this.credentials = t.credentials || this.credentials || "omit", !t.headers && this.headers || (this.headers = new d(t.headers)), this.method = (o = (i = t.method || this.method || "GET").toUpperCase(), n.indexOf(o) > -1 ? o : i), this.mode = t.mode || this.mode || null, this.referrer = null, ("GET" === this.method || "HEAD" === this.method) && s)
    throw new TypeError("Body not allowed for GET or HEAD requests"); this._initBody(s); } function y(e) { var t = new FormData; return e.trim().split("&").forEach(function (e) { if (e) {
    var i = e.split("="), o = i.shift().replace(/\+/g, " "), s = i.join("=").replace(/\+/g, " ");
    t.append(decodeURIComponent(o), decodeURIComponent(s));
} }), t; } function w(e, t) { t || (t = {}), this.type = "default", this.status = void 0 === t.status ? 200 : t.status, this.ok = this.status >= 200 && this.status < 300, this.statusText = "statusText" in t ? t.statusText : "OK", this.headers = new d(t.headers), this.url = t.url || "", this._initBody(e); } }("undefined" != typeof self ? self : void 0); var t = Object.freeze({}), i = function (e, t, i, o) { return new (i || (i = Promise))(function (s, n) { function r(e) { try {
    l(o.next(e));
}
catch (e) {
    n(e);
} } function a(e) { try {
    l(o.throw(e));
}
catch (e) {
    n(e);
} } function l(e) { e.done ? s(e.value) : new i(function (t) { t(e.value); }).then(r, a); } l((o = o.apply(e, t || [])).next()); }); }; (function (e) { var t = {}; function i(o) { if (t[o])
    return t[o].exports; var s = t[o] = { exports: {}, id: o, loaded: !1 }; return e[o].call(s.exports, s, s.exports, i), s.loaded = !0, s.exports; } return i.m = e, i.c = t, i.p = "", i(0); })([function (e, t, i) { (function (t, o) { var s = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (e) { return typeof e; } : function (e) { return e && "function" == typeof Symbol && e.constructor === Symbol ? "symbol" : typeof e; }; function n(e) { if (Array.isArray(e)) {
        for (var t = 0, i = Array(e.length); t < e.length; t++)
            i[t] = e[t];
        return i;
    } return Array.from(e); } var r = "object" === ("undefined" == typeof navigator ? "undefined" : s(navigator)) && "ReactNative" === navigator.product, a = "object" === (void 0 === t ? "undefined" : s(t)) && !0, l = "object" === ("undefined" == typeof window ? "undefined" : s(window)), c = "function" == typeof importScripts; if (r)
        d(o);
    else if (c)
        d(self);
    else if (l)
        d(window);
    else {
        if (!a)
            throw new Error("Unsupported environment for fetch-intercept");
        d(o);
    } function d(e) { if (!e.fetch)
        try {
            i(2);
        }
        catch (e) {
            throw Error("No fetch avaibale. Unable to register fetch-intercept");
        } var t; e.fetch = (t = e.fetch, function () { for (var e = arguments.length, i = Array(e), o = 0; o < e; o++)
        i[o] = arguments[o]; return function (e) { for (var t = arguments.length, i = Array(t > 1 ? t - 1 : 0), o = 1; o < t; o++)
        i[o - 1] = arguments[o]; var s = h.reduce(function (e, t) { return [t].concat(e); }, []), r = Promise.resolve(i); return s.forEach(function (e) { var t = e.request, i = e.requestError; (t || i) && (r = r.then(function (e) { return t.apply(void 0, n(e)); }, i)); }), r = r.then(function (t) { return e.apply(void 0, n(t)); }), s.forEach(function (e) { var t = e.response, i = e.responseError; (t || i) && (r = r.then(t, i)); }), r; }.apply(void 0, [t].concat(i)); }); } var h = []; e.exports = { register: function (e) { return h.push(e), function () { var t = h.indexOf(e); t >= 0 && h.splice(t, 1); }; }, clear: function () { h = []; } }; }).call(t, i(1), function () { return this; }()); }, function (e, t) { var i, o = e.exports = {}, s = [], n = !1, r = -1; function a() { n = !1, i.length ? s = i.concat(s) : r = -1, s.length && l(); } function l() { if (!n) {
        var e = setTimeout(a);
        n = !0;
        for (var t = s.length; t;) {
            for (i = s, s = []; ++r < t;)
                i && i[r].run();
            r = -1, t = s.length;
        }
        i = null, n = !1, clearTimeout(e);
    } } function c(e, t) { this.fun = e, this.array = t; } function d() { } o.nextTick = function (e) { var t = new Array(arguments.length - 1); if (arguments.length > 1)
        for (var i = 1; i < arguments.length; i++)
            t[i - 1] = arguments[i]; s.push(new c(e, t)), 1 !== s.length || n || setTimeout(l, 0); }, c.prototype.run = function () { this.fun.apply(null, this.array); }, o.title = "browser", o.browser = !0, o.env = {}, o.argv = [], o.version = "", o.versions = {}, o.on = d, o.addListener = d, o.once = d, o.off = d, o.removeListener = d, o.removeAllListeners = d, o.emit = d, o.binding = function (e) { throw new Error("process.binding is not supported"); }, o.cwd = function () { return "/"; }, o.chdir = function (e) { throw new Error("process.chdir is not supported"); }, o.umask = function () { return 0; }; }, function (e, i) { e.exports = t; }]).register({ request: function (e, t) { return [e, t]; }, response: function (e) { return e; }, requestError: function (e) { return Promise.reject(e); }, responseError: function (e) { return Promise.reject(e); } });
    var o = /** @class */ (function () {
        function o() {
            this.headers = {}, this.routes = {}, this.baseUrl = "/api", this.idField = "id", this.requestCredentials = "same-origin", this.corsMode = "same-origin", this.cachePolicy = "no-cache", this.entities = {}, this.hasDebugger = !1;
        }
        o.prototype.init = function (e) {
            var _this = this;
            if (this.settings = e, this.settings.host && (this.baseUrl = e.host), this.settings.routes && this.initApiRoutes(this.settings.routes), this.settings.headers) {
                var e_1 = this;
                this.settings.headers.forEach(function (t) { for (var i_1 in t)
                    e_1.headers[i_1] = t[i_1]; });
            }
            this.httpHeaders && Object.keys(this.headers).forEach(function (e) { _this.httpHeaders.set(e, _this.headers[e]); });
        };
        o.prototype.route = function (e) {
            var _this = this;
            var t;
            return Object.keys(this.routes).forEach(function (i) { i === e && (t = _this.routes[i]); }), t || e;
        };
        o.prototype.post = function (e, t) { return i(this, void 0, void 0, function () { return __generator(this, function (_a) {
            switch (_a.label) {
                case 0: return [4 /*yield*/, fetch("" + this.baseUrl + e, { body: JSON.stringify(t), cache: this.cachePolicy, credentials: this.requestCredentials, headers: this.headers, mode: this.corsMode, method: "POST" }).then(function (e) { return e.status >= 400 ? (console.log(e), console.error("Bad response from server"), e) : e.json(); }).catch(function (e) { return console.error("Error:", e); }).then(function (e) { return e; })];
                case 1: return [2 /*return*/, _a.sent()];
            }
        }); }); };
        o.prototype.get = function (e, t) { return i(this, void 0, void 0, function () { return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    t && (e += "?", Object.keys(t).forEach(function (i) { return e += i + "=" + t[i] + "&"; }));
                    return [4 /*yield*/, fetch("" + this.baseUrl + e, { cache: this.cachePolicy, credentials: this.requestCredentials, headers: this.headers, mode: this.corsMode, method: "GET" }).then(function (e) { return e.status >= 400 ? (console.log(e), console.log("Bad response from server"), e) : e.json(); }).catch(function (e) { return console.error("Error:", e); }).then(function (e) { return e; })];
                case 1: return [2 /*return*/, _a.sent()];
            }
        }); }); };
        o.prototype.patch = function (e, t, o) { return i(this, void 0, void 0, function () { return __generator(this, function (_a) {
            switch (_a.label) {
                case 0: return [4 /*yield*/, fetch("" + this.baseUrl + e + "/" + t, { headers: this.headers, method: "patch", body: JSON.stringify(o) })];
                case 1:
                    _a.sent();
                    return [2 /*return*/];
            }
        }); }); };
        o.prototype.delete = function (e, t) { return i(this, void 0, void 0, function () { return __generator(this, function (_a) {
            console.log(e, t);
            return [2 /*return*/];
        }); }); };
        o.prototype.login = function (e, t) { console.log(e, t.length); };
        o.prototype.logout = function (e, t) {
            if (e === void 0) { e = "app:authData"; }
            if (t === void 0) { t = !1; }
            this.clearCredentials(e), this.settings.authenticated = !1, t && (location.href = location.href);
        };
        o.prototype.setCredentials = function (e, t) {
            if (t === void 0) { t = "app-auth"; }
            this.credentials = e, window.localStorage.setItem(t, JSON.stringify(e));
        };
        o.prototype.getCredentials = function (e) {
            if (e === void 0) { e = "app:authData"; }
            if (window.localStorage.getItem(e))
                return JSON.parse(window.localStorage.getItem(e));
        };
        o.prototype.clearCredentials = function (e) {
            if (e === void 0) { e = "app:authData"; }
            window.localStorage.getItem(e) && window.localStorage.removeItem(e);
        };
        o.prototype.initApiRoutes = function (e) { var t = this; e.forEach(function (e) { for (var i_2 in e)
            t.routes[i_2] = e[i_2]; }), t.settings.dev && t.settings.routes_dev && t.settings.routes_dev.forEach(function (e) { for (var i_3 in e)
            t.routes[i_3] = e[i_3]; }); };
        o.prototype.errorHandler = function (e) { console.error(e); };
        o.prototype.saveLocalResource = function (e) { localStorage.setItem(e[this.idField], e); };
        o.prototype.loadLocalResource = function (e) { localStorage.getItem(e) && localStorage.getItem(e); };
        o.prototype.flushLocalResource = function (e) { localStorage.getItem(e) && localStorage.removeItem(e); };
        return o;
    }()); 
    var s = /** @class */ (function () {
        function s() {
        }
        s.copy = function (e) { return JSON.parse(JSON.stringify(e)); };
        s.deepAssign = function (e) {
            var t = [];
            for (var _i = 1; _i < arguments.length; _i++) {
                t[_i - 1] = arguments[_i];
            }
            if (!t.length)
                return e;
            var i = t.shift();
            return void 0 === i ? e : (s.isMergebleObject(e) && s.isMergebleObject(i) && Object.keys(i).forEach(function (t) { s.isMergebleObject(i[t]) ? (e[t] || (e[t] = {}), s.deepAssign(e[t], i[t])) : e[t] = i[t]; }), s.deepAssign.apply(s, [e].concat(t)));
        };
        s.isObject = function (e) { return null !== e && "object" == typeof e; };
        s.isMergebleObject = function (e) { return s.isObject(e) && !Array.isArray(e); };
        s.castToType = function (e) { var t = e; return Number(t) && "true" !== t && "false" !== t && (t = Number(t)), "0" === t && (t = 0), "true" === t && (t = !0), "false" === t && (t = !1), t; };
        s.getTimeStamp = function (e) {
            if (e === void 0) { e = null; }
            return e ? "string" == typeof e ? Math.round(+new Date(e) / 1e3) : Math.round(+e / 1e3) : Math.round(+new Date / 1e3);
        };
        s.getUUID = function () { var e = (new Date).getTime(); return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (t) { var i = (e + 16 * Math.random()) % 16 | 0; return e = Math.floor(e / 16), ("x" === t ? i : 7 & i | 8).toString(16); }); };
        s.isOnline = function () { return !("undefined" == typeof window || !window.navigator.onLine); };
        s.isBrowser = function () { return "undefined" != typeof window; };
        s.copyToClipboard = function (e) { var t = document.createElement("textarea"); t.value = e, t.setAttribute("readonly", ""), t.style.position = "absolute", t.style.left = "-9999px", document.body.appendChild(t); var i = document.getSelection().rangeCount > 0 && document.getSelection().getRangeAt(0); t.select(), document.execCommand("copy"), document.body.removeChild(t), i && (document.getSelection().removeAllRanges(), document.getSelection().addRange(i)); };
        return s;
    }()); 
    var n = /** @class */ (function () {
        function n() {
        }
        n.saveLocalModel = function (e, t) {
            if (t === void 0) { t = "model"; }
            "undefined" != typeof window && window.localStorage ? (window.localStorage.setItem(t, JSON.stringify(e)), window.localStorage.setItem(t + "-changed", String(Math.round(+new Date / 1e3)))) : console.error("localStorage not available: not running in a browser");
        };
        n.restoreLocalModel = function (e) {
            if (e === void 0) { e = "model"; }
            if ("undefined" != typeof window && window.localStorage) {
                if (localStorage.getItem(e))
                    return JSON.parse(localStorage.getItem(e));
            }
            else
                console.error("localStorage not available: not running in a browser");
        };
        n.flushLocalModel = function (e) {
            if (e === void 0) { e = "model"; }
            "undefined" != typeof window && window.localStorage ? (localStorage.getItem(e) && localStorage.removeItem(e), localStorage.getItem(e + "-changed") && localStorage.removeItem(e + "-changed")) : console.error("localStorage not available: not running in a browser");
        };
        return n;
    }());  var r = function (e, t, i, o) { return new (i || (i = Promise))(function (s, n) { function r(e) { try {
    l(o.next(e));
}
catch (e) {
    n(e);
} } function a(e) { try {
    l(o.throw(e));
}
catch (e) {
    n(e);
} } function l(e) { e.done ? s(e.value) : new i(function (t) { t(e.value); }).then(r, a); } l((o = o.apply(e, t || [])).next()); }); };
    var a = /** @class */ (function () {
        function a() {
            this._config = {}, this._locked = ["_config", "_defaults"];
        }
        a.prototype.get = function (e) { return this._config[e]; };
        a.prototype.set = function (e, t, i) {
            if (i === void 0) { i = !1; }
            if (!this.islocked(e))
                return i && (t = s.castToType(t)), this._config[e] = t;
            console.error('Config: property "' + e + '" can not be changed.');
        };
        a.prototype.add = function (e, t, i) {
            if (t === void 0) { t = !1; }
            if (i === void 0) { i = !1; }
            var o = this;
            t ? this.extend(e) : Object.keys(e).forEach(function (t) { o.set(t, e[t], i); });
        };
        a.prototype.fetch = function (e, t) {
            if (t === void 0) { t = !1; }
            return r(this, void 0, void 0, function () { var i, o; return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        i = this;
                        return [4 /*yield*/, fetch(e).then(function (e) { return e.json(); }).catch(function (e) { console.log("config fetch error:", e.message); })];
                    case 1:
                        o = _a.sent();
                        return [2 /*return*/, (t ? this.extend(o) : Object.keys(o).forEach(function (e, t) { i.set(e, o[e]); }), o)];
                }
            }); });
        };
        a.prototype.extend = function (e, t) {
            if (t === void 0) { t = this._config; }
            s.deepAssign(t, e);
        };
        a.prototype.all = function () { return this._config; };
        a.prototype.getLocalSettings = function (e) { window.localStorage && window.localStorage.getItem(e) && this.add(n.restoreLocalModel(e)); };
        a.prototype.setLocalSettings = function (e, t) {
            if (t === void 0) { t = this._config; }
            window.localStorage && n.saveLocalModel(t, e);
        };
        a.prototype.setDefaults = function (e) { var t = this; t._defaults = e, Object.keys(e).forEach(function (i) { t.set(i, s.copy(e[i])); }); };
        a.prototype.restoreDefaults = function () { var e = this; Object.keys(e._defaults).forEach(function (t) { e.set(t, e._defaults[t]); }); };
        a.prototype.islocked = function (e) { this._locked.forEach(function (t) { if (t === e)
            return console.log('Config error: property "' + t + '" is protected'), !0; }); };
        a.prototype.lock = function (e) { return !1; };
        a.prototype.unLock = function (e) { };
        a.prototype.initXdomain = function (e) { "undefined" != typeof window && window.xdomain && (window.xdomain.masters(e.masters), window.xdomain.slaves(e.slaves)); };
        return a;
    }());  var l = Symbol(), c = Symbol();
    var d = /** @class */ (function (_super) {
        __extends(d, _super);
        function d(e) {
            var _this = this;
            if (_this = _super.call(this) || this, e !== c)
                throw new Error("Cannot construct singleton");
            _this._type = "ConfigService";
            return _this;
        }
        Object.defineProperty(d, "instance", {
            get: function () { return this[l] || (this[l] = new d(c)), this[l]; },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(d.prototype, "type", {
            get: function () { return this._type; },
            set: function (e) { this._type = e; },
            enumerable: true,
            configurable: true
        });
        return d;
    }(a));  var h = { en: { ADD: "Add", ADDRESS: "Address", ADMIN: "Administration", APPLICATION: "Application", CANCEL: "Cancel", "CHANGE LANGUAGE": "Change language", CLOSE: "Close", CONFIRM: "Are you sure?", "CONFIRM WARNING": "This action cannot be undone", CONTACT: "Contact", CREATE: "Create", CURRENT: "Current", DATA: "Data", DATE: "Date", DELETE: "Delete", "DELETE CONFIRM": "Are you sure you want to delete this item", "DELETE CONFIRM MULTIPLE": "Are you sure you want to delete these items", DETAIL: "Detail", DETAILS: "Details", EDIT: "Edit", EMAIL: "E-mail", "EMAIL ADDRESS": "E-mail address", "EMAIL ERROR": "This is not a valid email address", ERROR: "Error", FIELD: "Field", "FIELD REQUIRED": "This field is required", "FORM INVALID": "The formulier can not be submitted yet. Please fill in the required fields", "FORM SUCCESS": "The data have been stored", LOGIN: "Login", "LOGIN ERROR": "Wrong credentials", "LOGIN EXPIRED": "Your authorization has expired. Please login again", LOGOUT: "Log out", NAME: "Name", PASSWORD: "Password", "PASSWORD REQUIRED": "Er is geen wachtwoord ingevoerd", "PASSWORD ERROR": "Password is required", "PASSWORD MATCH ERROR": "The passwords don't match", SUBMIT: "Submit", HOME: "Home", "NAME ERROR": "This is not a valid name", "NETWORK ERROR": "There is no internet connection", REMEMBER: "Remember", REMARKS: "Remarks", SECTION: "Section", SECTIONS: "Sections", REQUIRED: "Required", SAVE: "Save", USER: "User", USERNAME: "Username", USERS: "Users" }, nl: { ADD: "Toevoegen", ADDRESS: "Adres", ADMIN: "Beheer", APPLICATION: "Programma", CANCEL: "Annuleren", "CHANGE LANGUAGE": "Taal wijzigen", CLOSE: "Sluiten", CONFIRM: "Uitvoeren?", "CONFIRM WARNING": "Deze handeling kan niet ongedaan worden gemaakt", CONTACT: "Contact", CREATE: "Aanmaken", CURRENT: "Huidige", DATA: "Gegevens", DATE: "Datum", DELETE: "Verwijderen", "DELETE CONFIRM": "Weet u zeker dat u dit onderdeel wilt verwijderen", "DELETE CONFIRM MULTIPLE": "Weet u zeker dat u deze onderdelen wilt verwijderen", DETAIL: "Detail", DETAILS: "Details", EDIT: "Bewerken", EMAIL: "E-mail", "EMAIL ADDRESS": "E-mailadres", "EMAIL ERROR": "Er is geen geldige e-mail ingevoerd", ERROR: "Fout", FIELD: "Veld", "FIELD REQUIRED": "Dit veld is verplicht", "FORM INVALID": "Het formulier kan niet worden verstuurd. Vul eerst de ontbrekende velden in", "FORM SUCCESS": "De gegevens zijn opgeslagen", LOGIN: "Inloggen", "LOGIN ERROR": "De ingevoerde email / wachtwoord combinatie is niet geldig", "LOGIN EXPIRED": "Uw autorisatie is verlopen. Log opnieuw in a.u.b", LOGOUT: "Uitloggen", NAME: "Naam", PASSWORD: "Wachtwoord", "PASSWORD REQUIRED": "Er is geen wachtwoord ingevoerd", "PASSWORD ERROR": "Er is geen geldig wachtwoord ingevoerd", "PASSWORD MATCH ERROR": "De ingevoerde wachtwoorden komen niet overeen", SUBMIT: "Indienen", USERNAME: "Gebruikersnaam", TITLE: "Titel" } }, u = { id: "ema-js-base", name: "ema-js-base", authenticated: !1, version: "0.0.1", domain: "ema-js-base.firebaseapp.com", baseUrl: "https://ema-js-base.firebaseapp.com/", baseRoot: "https://ema-js-base.firebaseapp.com", api_headers: [{ "Content-Type": "application/json;charset=utf-8" }], firebase: { apiKey: "AIzaSyDQuSusOA5HNwIUoyViVOPwEWbGXWt91p4", authDomain: "ema-js-base.firebaseapp.com", databaseURL: "https://ema-js-base.firebaseio.com", projectId: "ema-js-base", storageBucket: "ema-js-base.appspot.com", messagingSenderId: "419979785648" }, firebaseApps: { "ema-js-base": { apiKey: "AIzaSyDQuSusOA5HNwIUoyViVOPwEWbGXWt91p4", authDomain: "ema-js-base.firebaseapp.com", databaseURL: "https://ema-js-base.firebaseio.com", projectId: "ema-js-base", storageBucket: "ema-js-base.appspot.com", messagingSenderId: "419979785648" }, "app-browser-10b90": { apiKey: "AIzaSyDKwhFxY-zUq17InNmiluKyd5xxp8tAzP8", authDomain: "app-browser-10b90.firebaseapp.com", databaseURL: "https://app-browser-10b90.firebaseio.com", projectId: "app-browser-10b90", storageBucket: "app-browser-10b90.appspot.com", messagingSenderId: "809240799935" } }, language: "en", languages: [{ key: "nl", value: "Nederlands" }, { key: "en", value: "English" }], i18n: h, permissions: ["read"], roles: { ANONYMOUS: ["read"], AUTHENTICATED: ["read", "create", "update", "logout"], EDITOR: ["create", "read", "update", "delete", "logout"], DEVELOPER: ["create", "read", "update", "delete", "logout", "debug"], ADMINISTRATOR: ["create", "read", "update", "delete", "administrate", "logout", "create-user", "delete-user"], OWNER: ["create", "read", "update", "delete", "administrate", "logout", "create-user", "delete-user", "debug", "autoLogin", "fetchCredentials"] }, drupal: { domain: "www.streamer.nl", protocol: "https:", app_uuid: "319e0e50-5f1b-4b76-8798-3f89da31dd12" }, wordpress: { host: "www.streamer.nl/wordpress", protocol: "https:", base_path: "/" } }; var p = function (e, t, i, o) { return new (i || (i = Promise))(function (s, n) { function r(e) { try {
    l(o.next(e));
}
catch (e) {
    n(e);
} } function a(e) { try {
    l(o.throw(e));
}
catch (e) {
    n(e);
} } function l(e) { e.done ? s(e.value) : new i(function (t) { t(e.value); }).then(r, a); } l((o = o.apply(e, t || [])).next()); }); }; e.ConfigService = d, e.configDefaults = u, e.Util = s, e.Api = o, e.Translate = /** @class */ (function () {
    function Translate() {
        var _this = this;
        this.t = {}, this.i18n = h, this.defaultLanguage = "en-US", this.supportedLanguages = ["en-US", "nl-NL"], this.translations = {}, Object.keys(h).forEach(function (e) { _this.supportedLanguages.push(e); }), this.translations = s.copy(h), this.translations["nl-NL"] = s.copy(this.translations.nl), this.translations["en-US"] = s.copy(this.translations.en), this.translations["en-BE"] = s.copy(this.translations.en), this.translations.en_BE = s.copy(this.translations.en), this.use(this.defaultLanguage);
    }
    Translate.prototype.use = function (e) { this.language = e, this.translations[e], this.t = this.translations[e]; };
    Translate.prototype.get = function (e) { return this.instant(e); };
    Translate.prototype.instant = function (e) { var t, i = this.t; return Object.keys(i).forEach(function (o) { o === e && (t = i[o]); }), t || e; };
    return Translate;
}()), e.DomUtil = /** @class */ (function () {
    function DomUtil() {
    }
    DomUtil.addClass = function (e, t) { e.classList ? e.classList.add(t) : e.className += " " + t; };
    DomUtil.hasClass = function (e, t) { e.classList ? e.classList.contains(t) : new RegExp("(^| )" + t + "( |$)", "gi").test(e.className); };
    DomUtil.removeClass = function (e, t) { e.classList ? e.classList.remove(t) : e.className = e.className.replace(new RegExp("(^|\\b)" + t.split(" ").join("|") + "(\\b|$)", "gi"), " "); };
    DomUtil.toggleClass = function (e, t) { if (e.classList)
        e.classList.toggle(t);
    else {
        var i_4 = e.className.split(" "), o_1 = i_4.indexOf(t);
        o_1 >= 0 ? i_4.splice(o_1, 1) : i_4.push(t), e.className = i_4.join(" ");
    } };
    DomUtil.remove = function (e) { e.parentNode.removeChild(e); };
    DomUtil.getAttributes = function (e) { var t = e.attributes, i = {}, o = 0; for (; o < t.length; o++)
        i[t[o].name] = t[o].value; return i; };
    DomUtil.setAttributes = function (e, t) { Object.keys(t).forEach(function (i) { e.setAttribute(i, t[i]); }); };
    DomUtil.getStyle = function (e, t) { var i; var o = e.ownerDocument.defaultView; return o && o.getComputedStyle ? (t = t.replace(/([A-Z])/g, "-$1").toLowerCase(), o.getComputedStyle(e, null).getPropertyValue(t)) : e.currentStyle ? (t = t.replace(/\-(\w)/g, function (e, t) { return t.toUpperCase(); }), i = e.currentStyle[t], /^\d+(em|pt|%|ex)?$/i.test(i) ? function (t) { var i = e.style.left, o = e.runtimeStyle.left; return e.runtimeStyle.left = e.currentStyle.left, e.style.left = t || 0, t = e.style.pixelLeft + "px", e.style.left = i, e.runtimeStyle.left = o, t; }(i) : i) : void 0; };
    DomUtil.viewportSize = function () { var e = { width: void 0, height: void 0 }; return "undefined" != typeof window && (window.innerHeight ? (e.width = window.innerWidth, e.height = window.innerHeight) : (e.width = document.documentElement.clientWidth, e.height = document.documentElement.clientHeight)), e; };
    DomUtil.fadeIn = function (e, t, i, o) {
        if (t === void 0) { t = 300; }
        if (i === void 0) { i = 0; }
        if (o === void 0) { o = "block"; }
        var s = 1 / t * 10;
        e.style.opacity = "0", e.style.display = o, setTimeout(function () { !function t() { var i = parseFloat(e.style.opacity); (i += s) > 1 || (e.style.opacity = i.toString(), requestAnimationFrame(t)); }(); }, i);
    };
    DomUtil.fadeOut = function (e, t, i, o) {
        if (t === void 0) { t = 300; }
        if (i === void 0) { i = 0; }
        if (o === void 0) { o = !1; }
        var s = 1 / t * 10;
        e.style.opacity = "1", setTimeout(function () { !function t() { var i = Number(e.style.opacity); i -= s, e.style.opacity = i.toString(), i < 0 ? !1 === o && (e.style.display = "none", e.style.opacity = "1") : requestAnimationFrame(t); }(); }, i);
    };
    DomUtil.getUrlParameterByName = function (e) { var t = RegExp("[?&]" + e + "=([^&]*)").exec(window.location.search); return t && decodeURIComponent(t[1].replace(/\+/g, " ")); };
    return DomUtil;
}()), e.Drupal = /** @class */ (function () {
    function Drupal(e, t) {
        this.user = {}, this.saveLocalModel = n.saveLocalModel, this.restoreLocalModel = n.restoreLocalModel, this.cache = !1, this.model = { entities: {}, collections: {}, nodes: {}, views: {}, menus: {}, books: {}, siteParams: {} }, this.routes = {}, this.version = "drupal-8", this.sites = {}, this.defaultUser = "services", this.defaultAuthHeader = "Basic c2VydmljZXM6OSs0djJGdm0zMi84Ymtl", this.initJDrupal(), this.config = d.instance, this.api = new o, this.api.corsMode = "cors", this.jsonApi = new /** @class */ (function (_super) {
            __extends(class_1, _super);
            function class_1() {
                var _this = this;
                _this = _super.call(this) || this, _this.entities = {}, _this.collections = {}, _this.nodes = {}, _this.resources = {}, _this.views = {}, _this.cache = !1, _this.headers = { Accept: "application/vnd.api+json", "Content-Type": "application/vnd.api+json" };
                return _this;
            }
            class_1.prototype.post = function (e, t) { return p(this, void 0, void 0, function () { return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        this.headers.Authorization = "Basic " + jDrupal.settings.auth_hash, this.headers["X-CSRF-Token"] = jDrupal.settings.user_csrf_token, this.headers["Content-Type"] = "application/vnd.api+json";
                        return [4 /*yield*/, fetch("" + this.baseUrl + e, { headers: this.headers, method: "POST", body: JSON.stringify(t) })];
                    case 1:
                        _a.sent();
                        return [2 /*return*/];
                }
            }); }); };
            class_1.prototype.patch = function (e, t, i) { return p(this, void 0, void 0, function () { return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        this.headers.Authorization = "Basic " + jDrupal.settings.auth_hash, this.headers["X-CSRF-Token"] = jDrupal.settings.user_csrf_token, this.headers["Content-Type"] = "application/vnd.api+json", i.data.attributes.changed && (i.data.attributes.changed = void 0);
                        return [4 /*yield*/, fetch("" + this.baseUrl + e + "/" + t, { headers: this.headers, method: "PATCH", body: JSON.stringify(i) })];
                    case 1:
                        _a.sent();
                        return [2 /*return*/];
                }
            }); }); };
            class_1.prototype.delete = function (e, t) { return p(this, void 0, void 0, function () { return __generator(this, function (_a) {
                console.log("FIXME drupal delete"), console.log(e, t), this.headers.Authorization = "Basic " + jDrupal.settings.auth_hash, this.headers["X-CSRF-Token"] = jDrupal.settings.user_csrf_token, this.headers["Content-Type"] = "application/vnd.api+json";
                return [2 /*return*/];
            }); }); };
            class_1.prototype.getResourcesIndex = function (e, t) {
                if (e === void 0) { e = "jsonapi"; }
                return p(this, void 0, void 0, function () { var i; return __generator(this, function (_a) {
                    switch (_a.label) {
                        case 0:
                            i = this;
                            return [4 /*yield*/, new Promise(function (o, s) { var n = i.baseUrl + "index.php/"; t && (n += t + "/"), n += e, fetch(n).then(function (e) { if (e.status >= 400)
                                    throw new Error("JsonApi: Bad resources response from server"); return e.json(); }).then(function (e) { i.resources = e, i.baseUrl = e.links.self + "/", Object.keys(e.links).forEach(function (e, t) { (e.match("node--") || e.match("menu--") || e.match("comment--") || e.match("file--") || e.match("taxonomy_term--") || e.match("node_type--")) && (i.collections[e] = {}); }), o(e); }); })];
                        case 1:
                            _a.sent();
                            return [2 /*return*/];
                    }
                }); });
            };
            class_1.prototype.getCollection = function (e, t, i) {
                if (i === void 0) { i = !1; }
                return p(this, void 0, void 0, function () {
                    var t, o, _a, _b, e_2, _c, _d, _i, t_1;
                    var _this = this;
                    return __generator(this, function (_e) {
                        switch (_e.label) {
                            case 0:
                                t = e.split("--")[0] + "/" + e.split("--")[1];
                                _a = this.collections;
                                _b = e;
                                return [4 /*yield*/, this.get(t, {})];
                            case 1:
                                o = _a[_b] = _e.sent();
                                if (!i) return [3 /*break*/, 5];
                                e_2 = [];
                                Object.keys(o.data).forEach(function (t) { e_2.push(_this.getEntityRelationships({ data: o.data[t] })); });
                                _c = [];
                                for (_d in e_2)
                                    _c.push(_d);
                                _i = 0;
                                _e.label = 2;
                            case 2:
                                if (!(_i < _c.length)) return [3 /*break*/, 5];
                                t_1 = _c[_i];
                                return [4 /*yield*/, e_2[t_1]];
                            case 3:
                                _e.sent();
                                _e.label = 4;
                            case 4:
                                _i++;
                                return [3 /*break*/, 2];
                            case 5: return [2 /*return*/, (Object.keys(o.data).forEach(function (e, t) { _this.entities[o.data[e].attributes.uuid] = o.data[e]; }), o)];
                        }
                    });
                });
            };
            class_1.prototype.getCollections = function (e, t, i) {
                if (i === void 0) { i = !1; }
                return p(this, void 0, void 0, function () {
                    var o, _a, _b, _i, e_3;
                    var _this = this;
                    return __generator(this, function (_c) {
                        switch (_c.label) {
                            case 0:
                                o = [];
                                e.forEach(function (e) { o.push(_this.getCollection(e, t, i)); });
                                _a = [];
                                for (_b in o)
                                    _a.push(_b);
                                _i = 0;
                                _c.label = 1;
                            case 1:
                                if (!(_i < _a.length)) return [3 /*break*/, 4];
                                e_3 = _a[_i];
                                return [4 /*yield*/, o[e_3]];
                            case 2:
                                _c.sent();
                                _c.label = 3;
                            case 3:
                                _i++;
                                return [3 /*break*/, 1];
                            case 4: return [2 /*return*/];
                        }
                    });
                });
            };
            class_1.prototype.getAllCollections = function (e, t) {
                if (e === void 0) { e = !1; }
                if (t === void 0) { t = []; }
                return p(this, void 0, void 0, function () {
                    var i, _a, _b, _i, e_4;
                    var _this = this;
                    return __generator(this, function (_c) {
                        switch (_c.label) {
                            case 0:
                                i = [];
                                Object.keys(this.collections).forEach(function (o, s) { var n = !1; t.forEach(function (e) { e === o && (n = !0); }), n || i.push(_this.getCollection(o, {}, e)); });
                                _a = [];
                                for (_b in i)
                                    _a.push(_b);
                                _i = 0;
                                _c.label = 1;
                            case 1:
                                if (!(_i < _a.length)) return [3 /*break*/, 4];
                                e_4 = _a[_i];
                                return [4 /*yield*/, i[e_4]];
                            case 2:
                                _c.sent();
                                _c.label = 3;
                            case 3:
                                _i++;
                                return [3 /*break*/, 1];
                            case 4: return [2 /*return*/];
                        }
                    });
                });
            };
            class_1.prototype.getResource = function (e, t) { return p(this, void 0, void 0, function () {
                var _this = this;
                return __generator(this, function (_a) {
                    switch (_a.label) {
                        case 0:
                            t && (e += "?", Object.keys(t).forEach(function (i) { return e += i + "=" + t[i] + "&"; }));
                            return [4 /*yield*/, fetch(e, { headers: this.headers }).then(function (e) { if (e.status >= 400)
                                    throw new Error("Bad response from server"); return e.json(); }).then(function (e) { return e.data && e.data.id && (_this.entities[e.data.id] = e), e.data && Array.isArray(e.data) && e.data.forEach(function (e) { e.id && (_this.entities[e.id] = e); }), e; })];
                        case 1: return [2 /*return*/, _a.sent()];
                    }
                });
            }); };
            class_1.prototype.getResources = function (e) { return p(this, void 0, void 0, function () {
                var t, _a, _b, _i, e_5;
                var _this = this;
                return __generator(this, function (_c) {
                    switch (_c.label) {
                        case 0:
                            t = [];
                            e.forEach(function (e) { t.push(_this.getResource(e)); });
                            _a = [];
                            for (_b in t)
                                _a.push(_b);
                            _i = 0;
                            _c.label = 1;
                        case 1:
                            if (!(_i < _a.length)) return [3 /*break*/, 4];
                            e_5 = _a[_i];
                            return [4 /*yield*/, t[e_5]];
                        case 2:
                            _c.sent();
                            _c.label = 3;
                        case 3:
                            _i++;
                            return [3 /*break*/, 1];
                        case 4: return [2 /*return*/];
                    }
                });
            }); };
            class_1.prototype.getEntityRelationships = function (e) { return p(this, void 0, void 0, function () {
                var _this = this;
                return __generator(this, function (_a) {
                    switch (_a.label) {
                        case 0: return [4 /*yield*/, new Promise(function (t) { var i = []; if (e.data && e.data.relationships && Object.keys(e.data.relationships).forEach(function (t, o) { t.match("field_") && i.push(e.data.relationships[t]); }), i.length) {
                                var e_6 = [];
                                i.forEach(function (t) { t.links && t.links.self && e_6.push(t.links.related); }), e_6.length ? _this.getResources(e_6).then(function () { t(); }) : t();
                            }
                            else
                                t(); })];
                        case 1: return [2 /*return*/, _a.sent()];
                    }
                });
            }); };
            class_1.prototype.getNode = function (e, t) { return p(this, void 0, void 0, function () {
                var i, o;
                var _this = this;
                return __generator(this, function (_a) {
                    switch (_a.label) {
                        case 0:
                            i = this;
                            o = "uuid";
                            "number" == typeof (e = s.castToType(e)) && (o = "nid");
                            return [4 /*yield*/, new Promise(function (s) { var n; if (_this.cache) {
                                    var t_2;
                                    if (Object.keys(_this.entities).forEach(function (i) { _this.entities[i].data && _this.entities[i].data.attributes[o] == e && (t_2 = _this.entities[i]); }), t_2)
                                        return void s(t_2);
                                } if (_this.views.node_index && _this.views.node_index.forEach(function (i) { i[o] == e && (t = i.type); }), t)
                                    n = "node/" + t, _this.get(n + "?filter[" + o + "][value]=" + e).then(function (e) { r(e); });
                                else {
                                    var t_3 = [];
                                    Object.keys(_this.collections).forEach(function (e) { e.match("node--") && t_3.push(e); }), t_3.forEach(function (t) { var i = t.split("--")[0] + "/" + t.split("--")[1]; _this.get(i + "?filter[" + o + "][value]=" + e).then(function (e) { r(e); }); });
                                } function r(e) { if (e.data.length) {
                                    var t_4 = { data: e.data[0] };
                                    i.entities[e.data[0].id] = t_4, i.collections[e.data[0].type].data || (i.collections[e.data[0].type].data = []), i.collections[e.data[0].type].data.push(t_4), i.nodes[e.data[0].attributes.nid] = t_4, t_4.data.relationships && i.getEntityRelationships(t_4).then(function () { s(t_4); });
                                } } })];
                        case 1: return [2 /*return*/, _a.sent()];
                    }
                });
            }); };
            class_1.prototype.getNodes = function (e) { return p(this, void 0, void 0, function () {
                var t, _a, _b, _i, e_7;
                var _this = this;
                return __generator(this, function (_c) {
                    switch (_c.label) {
                        case 0:
                            t = [];
                            e.forEach(function (e) { t.push(_this.getNode(e)); });
                            _a = [];
                            for (_b in t)
                                _a.push(_b);
                            _i = 0;
                            _c.label = 1;
                        case 1:
                            if (!(_i < _a.length)) return [3 /*break*/, 4];
                            e_7 = _a[_i];
                            return [4 /*yield*/, t[e_7]];
                        case 2:
                            _c.sent();
                            _c.label = 3;
                        case 3:
                            _i++;
                            return [3 /*break*/, 1];
                        case 4: return [2 /*return*/];
                    }
                });
            }); };
            class_1.prototype.saveNode = function (e) { return p(this, void 0, void 0, function () { var t, _a; return __generator(this, function (_b) {
                switch (_b.label) {
                    case 0:
                        t = e.data.type.split("--")[0] + "/" + e.data.type.split("--")[1];
                        if (!e.data.id) return [3 /*break*/, 2];
                        return [4 /*yield*/, this.patch(t, e.data.id, e)];
                    case 1:
                        _a = _b.sent();
                        return [3 /*break*/, 4];
                    case 2: return [4 /*yield*/, this.post(t, e)];
                    case 3:
                        _a = _b.sent();
                        _b.label = 4;
                    case 4:
                        _a;
                        return [2 /*return*/];
                }
            }); }); };
            class_1.prototype.deleteNode = function (e) { return p(this, void 0, void 0, function () { var t; return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        t = e.data.type.split("--")[0] + "/" + e.data.type.split("--")[1];
                        return [4 /*yield*/, this.delete(t, e.data.id).then(function (e) { })];
                    case 1:
                        _a.sent();
                        return [2 /*return*/];
                }
            }); }); };
            class_1.prototype.getById = function (e) {
                var _this = this;
                var t;
                if (Object.keys(this.collections).forEach(function (i, o) { _this.collections[i].data && _this.collections[i].data.length && _this.collections[i].data.forEach(function (i) { i.id === e && (t = i); }); }), t)
                    return { data: t };
            };
            class_1.prototype.getByNodeId = function (e) { return p(this, void 0, void 0, function () {
                var t;
                var _this = this;
                return __generator(this, function (_a) {
                    if (Object.keys(this.collections).forEach(function (i, o) { i.match("node--") && _this.collections[i].data && _this.collections[i].data.length && _this.collections[i].data.forEach(function (i) { i.attributes.nid == e && (t = i); }); }), t)
                        return [2 /*return*/, { data: t }];
                    return [2 /*return*/];
                });
            }); };
            return class_1;
        }(o)), this.jsonApi.corsMode = "cors", t && (this.api = t), this.model.entities = this.jsonApi.entities, this.model.collections = this.jsonApi.collections, this.model.nodes = this.jsonApi.nodes, this.model.views = this.jsonApi.views, e && this.config.add(e);
    }
    Drupal.prototype.init = function (e) { this.options = e, e.version && (this.version = e.version), this.domain = e.domain, this.static = e.static || !1, this.cache = e.cache || !1, this.standalone = e.standalone || !1, this.base_path = e.base_path || "/", this.protocol = e.protocol || "http:", this.sites[this.domain] = {}, this.file_directory_path = e.file_directory_path || "sites/default/files", this.file_directory_path = this.baseUrl + this.file_directory_path, this.initApi(e); var t = []; return s.isOnline() && !this.static ? (t.push(this.getParams()), t.push(this.getLocalStorageCredentials()), t.push(this.jsonApi.getResourcesIndex(e.api.path_prefix, this.config.get("language"))), t.push(new Promise(function (e) { e(); })), Promise.all(t)) : new Promise(function (e) { e(); }); };
    Drupal.prototype.initApi = function (e) { if (this.baseUrl = e.api.host = this.protocol + "//" + this.domain + this.base_path, this.api.init(e.api), this.jsonApi.init(e.api), this.jsonApi.cache = this.cache, this.config.get("drupal").hasLanguages && this.config.get("language"), window && (window.Drupal && (window.Drupal.url && window.Drupal.url.isLocal() ? this.isLocal = !0 : this.isLocal = !1), window.Drupal = window.Drupal || {}, window.Drupal.app_server_model = this.model, window.Drupal.settings = window.Drupal.settings || {}, window.Drupal.settings.baseUrl = this.baseUrl, window.drupalSettings = window.drupalSettings || {}), "drupal-8" === this.version) {
        if (window && !window.jDrupal)
            return void console.error("ERROR: jDrupal is not defined in the global namespace.");
        this.jDrupal = jDrupal, jDrupal.config("sitePath", this.options.protocol + "//" + this.options.domain);
    } "withCredentials" in new XMLHttpRequest && (this.cors = !0); };
    Drupal.prototype.login = function (e, t) { var i = this; return new Promise(function (o) { jDrupal.userLogin(e, t).then(function () { i.user = jDrupal.currentUser(), i.api.setCredentials(jDrupal.settings, "drupal:authUser:" + i.domain), i.authenticated = !0, o(); }); }); };
    Drupal.prototype.logout = function () { var e = this; return new Promise(function (t) { e.api.logout("drupal:authUser:" + e.domain), e.authenticated = !1, console.log("logged out"), t(); }); };
    Drupal.prototype.getParams = function () { var e = this; return new Promise(function (t) { var i = "index.php/rest/params"; "drupal-7" === e.version && (i = "?q=rest/app_params.json"), e.api.get(i, { _format: "json" }).then(function (i) { e.model.siteParams = e.siteParams = i, t(i); }); }); };
    Drupal.prototype.getView = function (e, t) {
        var _this = this;
        return new Promise(function (i, o) { var s = e; _this.api.get(s.attributes.display.rest_export_1.display_options.path, t).then(function (e) { _this.model.views[s.attributes.id] = e, i(); }); });
    };
    Drupal.prototype.getAppNode = function (e) {
        var _this = this;
        return new Promise(function (t) { _this.jsonApi.getNode(e, "app").then(function (i) { var o = [], s = i.data.attributes; !0 === s.field_cache && (_this.jsonApi.cache = s.field_cache), s.field_preload_collections && o.push(_this.jsonApi.getAllCollections(!0)), Object.keys(_this.model.entities).forEach(function (t) { var i = _this.model.entities[t]; "menu--menu" == i.type && o.push(_this.menuLoad(i.attributes.id, s.cache)), "view--view" == i.type && o.push(_this.getView(i)), i.data && i.data.type.match("node--") && i.data.attributes.uuid !== e && o.push(_this.jsonApi.getNode(i.data.attributes.uuid)); }), _this.getSiteData(o).then(function () { t(); }); }); });
    };
    Drupal.prototype.getSiteData = function (e) { var t = this; return new Promise(function (i) { Promise.all(e).then(function () { t.cache && t.saveLocalModel(t.model, t.domain), i(); }); }); };
    Drupal.prototype.getLocalStorageCredentials = function () { var e = this; return new Promise(function (t, i) { var o = e.api.getCredentials("drupal:authUser:" + e.domain); if (o) {
        for (var e_8 in o)
            jDrupal.settings[e_8] = o[e_8];
        var i_5 = atob(o.auth_hash);
        e.login(i_5.split(":")[0], i_5.split(":")[1]).then(function () { t(); });
    }
    else
        t(); }); };
    Drupal.prototype.menuLoad = function (e, t) {
        if (t === void 0) { t = !1; }
        var i = this;
        return new Promise(function (o, s) { i.api.get("entity/menu/" + e + "/tree", { _format: "hal_json" }).then(function (s) { var n = s; if (i.model.menus[e] = n, t) {
            var e_9 = [];
            n.forEach(function (t) { t.link.route_parameters.node && e_9.push(t.link.route_parameters.node); }), i.jsonApi.getNodes(e_9).then(function () { console.log(e_9), o(n); });
        }
        else
            o(n); }); });
    };
    Drupal.prototype.bookLoad = function (e, t) {
        if (t === void 0) { t = !1; }
        var i = this;
        return new Promise(function (o, s) { i.api.get("rest/book_tree/" + e, { _format: "hal_json" }).then(function (s) { i.model.books[e] = s; var n = i.parseBookTree(e); t ? i.jsonApi.getNodes(n).then(function () { o(s); }) : o(s); }); });
    };
    Drupal.prototype.parseBookTree = function (e) { var t = this.model.books[e]; var i, o, s, n, r; for (n in o = [], s = [], t)
        i = t[n].below; for (n in i) {
        var e_10 = void 0;
        for (r in i[n])
            (e_10 = i[n]).link.route_parameters = { node: i[n].link.nid }, e_10.link.href = "/node/" + e_10.link.nid, s.push(i[n].link.nid);
        o.push(e_10);
    } return this.model.menus["book_" + e] = o, s; };
    Drupal.prototype.nodeLoad = function (e) { var t = this; return new Promise(function (i, o) { t.cache && t.model.nodes[e] ? i(t.model.nodes[e]) : jDrupal.nodeLoad(e).then(function (e) { t.model.nodes[e.entity.nid[0].value] = e, t.model.entities[e.entity.uuid[0].value] = e.entity, i(e); }); }); };
    Drupal.prototype.nodesLoad = function (e) { var t = this, i = []; return new Promise(function (o) { for (var o_2 in e)
        i.push(t.nodeLoad(e[o_2])); Promise.all(i).then(function () { o(); }); }); };
    Drupal.prototype.createNode = function (e) { var t = {}; for (var i_6 in e)
        t[i_6] = [{ value: e[i_6] }]; return t.title = [{ value: e.title }], t.type = [{ target_id: e.type }], t._links = { type: { href: jDrupal.restPath() + "rest/type/node/" + e.type } }, new jDrupal.Node(t); };
    Drupal.prototype.initJDrupal = function () { };
    return Drupal;
}()), e.Wordpress = /** @class */ (function () {
    function Wordpress() {
        this.authenticated = !1, this.model = { menus: {}, params: {}, collections: { post: {} } };
    }
    Wordpress.prototype.init = function (e) { var t = this; return "undefined" != typeof window && (window.wp = window.wp || {}), new Promise(function (i, o) { t.initApi(e).then(function () { e.app_server ? t.getParams().then(function () { t.getMenus().then(function () { t.ready = !0, i(); }); }) : i(); }); }); };
    Wordpress.prototype.initApi = function (e) { var t = this; return this.settings = e, this.endpoint = this.settings.protocol + "//" + this.settings.host + "/index.php/wp-json/", new Promise(function (e, i) { "undefined" == typeof window || window.WPAPI || (console.error("ERROR: WPAPI is not defined as global"), i()), location && location.origin === t.settings.protocol + "//" + t.settings.host ? t.discover().then(function () { t.api = new WPAPI({ endpoint: t.endpoint }), t.initCustomRoutes(), e(); }) : (t.api = new WPAPI({ endpoint: t.endpoint }), t.initCustomRoutes(), e()); }); };
    Wordpress.prototype.initCustomRoutes = function () { this.api.params = this.api.registerRoute("app-server/v1", "/params"), this.api.menus = this.api.registerRoute("app-server/v1", "/menus/(?P<id>[a-zA-Z(-]+)"), this.api.apps = this.api.registerRoute("wp/v2", "/apps/(?P<id>\\d+)"), this.api.iframes = this.api.registerRoute("wp/v2", "/iframes/(?P<id>\\d+)"); };
    Wordpress.prototype.getPosts = function () { var e = this; return new Promise(function (t, i) { e.api.posts().then(function (i) { var o = []; i.forEach(function (t) { t.id && (e.model.collections.post[t.id] = t, o.push(t)); }), t(o); }); }); };
    Wordpress.prototype.getParams = function () { var e = this; return new Promise(function (t, i) { e.api.params().then(function (i) { e.model.params = i, t(i); }); }); };
    Wordpress.prototype.getPost = function (e, t) { var i = this; return this.model.collections[t] || (this.model.collections[t] = {}), new Promise(function (o, s) { function n(e, t, s) { i.model.collections[t][e] = s, o(s); } !0 === i.settings.cache && i.model.collections[t][e] ? o(i.model.collections[t][e]) : ("post" === t && i.api.posts().id(e).then(function (i) { return n(e, t, i); }), "page" === t && i.api.pages().id(e).then(function (i) { return n(e, t, i); }), "app" === t && i.api.apps().id(e).then(function (i) { return n(e, t, i); }), "iframe" === t && i.api.iframes().id(e).then(function (i) { return n(e, t, i); })); }); };
    Wordpress.prototype.getMenu = function (e) { var t = this; return new Promise(function (i, o) { t.api.menus().id(e).then(function (o) { t.model.menus[e] = o, i(t.model.menus[e]); }); }); };
    Wordpress.prototype.getMenus = function () { var e = this; return new Promise(function (t, i) { var o = []; var s = 0; e.model.params.menus.length ? (e.model.params.menus.forEach(function (e) { o.push(e.slug); }), o.forEach(function (i) { e.getMenu(i).then(function (n) { e.model.menus[i] = n, ++s === o.length && t(e.model.menus); }); })) : t(e.model.menus); }); };
    Wordpress.prototype.saveLocal = function () { n.saveLocalModel(this.model, this.model.params.baseUrl); };
    Wordpress.prototype.restoreLocal = function () { this.model = n.restoreLocalModel(this.model.params.baseUrl); };
    Wordpress.prototype.discover = function () { var e = this, t = WPAPI.discover(this.settings.protocol + "//" + this.settings.host); return new Promise(function (i, o) { t.then(function (t) { e.site = t, i(); }); }); };
    return Wordpress;
}()), e.StringUtil = /** @class */ (function () {
    function StringUtil() {
    }
    StringUtil.replaceAll = function (e, t, i, o) {
        if (o === void 0) { o = !1; }
        return e ? (s = t, n = i, r = o, String(e).replace(new RegExp(s.replace(/([\/\,\!\\\^\$\{\}\[\]\(\)\.\*\+\?\|\<\>\-\&])/g, "\\$&"), r ? "gi" : "g"), "string" == typeof n ? n.replace(/\$/g, "$$$$") : n)) : e;
        var s, n, r;
    };
    StringUtil.between = function (e, t, i, o) {
        if (o === void 0) { o = !1; }
        return e ? function (e, t, i) { var o = e.indexOf(t); if (!(o >= 0))
            return ""; if (e = e.substring(o + t.length), i) {
            if (!((o = e.indexOf(i)) >= 0))
                return "";
            e = e.substring(0, o);
        } return e; }(e, t, i) : e;
    };
    return StringUtil;
}()); });
