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-509002b8.js", ["exports"], function (e) { window.webcomponents.h; var t = function (e, t, i, s) { return new (i || (i = Promise))(function (n, o) { function a(e) { try {
    l(s.next(e));
}
catch (e) {
    o(e);
} } function r(e) { try {
    l(s.throw(e));
}
catch (e) {
    o(e);
} } function l(e) { e.done ? n(e.value) : new i(function (t) { t(e.value); }).then(a, r); } l((s = s.apply(e, t || [])).next()); }); };
    var i = /** @class */ (function () {
        function i() {
            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;
        }
        i.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]); });
        };
        i.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;
        };
        i.prototype.post = function (e, i) { return t(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(i), 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()];
            }
        }); }); };
        i.prototype.get = function (e, i) { return t(this, void 0, void 0, function () { return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    i && (e += "?", Object.keys(i).forEach(function (t) { return e += t + "=" + i[t] + "&"; }));
                    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()];
            }
        }); }); };
        i.prototype.patch = function (e, i, s) { return t(this, void 0, void 0, function () { return __generator(this, function (_a) {
            switch (_a.label) {
                case 0: return [4 /*yield*/, fetch("" + this.baseUrl + e + "/" + i, { headers: this.headers, method: "patch", body: JSON.stringify(s) })];
                case 1:
                    _a.sent();
                    return [2 /*return*/];
            }
        }); }); };
        i.prototype.delete = function (e, i) { return t(this, void 0, void 0, function () { return __generator(this, function (_a) {
            console.log(e, i);
            return [2 /*return*/];
        }); }); };
        i.prototype.login = function (e, t) { console.log(e, t.length); };
        i.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);
        };
        i.prototype.setCredentials = function (e, t) {
            if (t === void 0) { t = "app-auth"; }
            this.credentials = e, window.localStorage.setItem(t, JSON.stringify(e));
        };
        i.prototype.getCredentials = function (e) {
            if (e === void 0) { e = "app:authData"; }
            if (window.localStorage.getItem(e))
                return JSON.parse(window.localStorage.getItem(e));
        };
        i.prototype.clearCredentials = function (e) {
            if (e === void 0) { e = "app:authData"; }
            window.localStorage.getItem(e) && window.localStorage.removeItem(e);
        };
        i.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]; }); };
        i.prototype.errorHandler = function (e) { console.error(e); };
        i.prototype.saveLocalResource = function (e) { localStorage.setItem(e[this.idField], e); };
        i.prototype.loadLocalResource = function (e) { localStorage.getItem(e) && localStorage.getItem(e); };
        i.prototype.flushLocalResource = function (e) { localStorage.getItem(e) && localStorage.removeItem(e); };
        return i;
    }());  var s = function (e, t, i, s) { return new (i || (i = Promise))(function (n, o) { function a(e) { try {
    l(s.next(e));
}
catch (e) {
    o(e);
} } function r(e) { try {
    l(s.throw(e));
}
catch (e) {
    o(e);
} } function l(e) { e.done ? n(e.value) : new i(function (t) { t(e.value); }).then(a, r); } l((s = s.apply(e, t || [])).next()); }); };
    var n = /** @class */ (function () {
        function n() {
            this._environment = { type: "js" }, this._config = g.instance;
        }
        n.prototype.init = function (e, t) { return s(this, void 0, void 0, function () { var _a; return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    t && this.initNameSpace(t);
                    if (!("string" == typeof e)) return [3 /*break*/, 2];
                    return [4 /*yield*/, this._config.fetch(e, !0)];
                case 1:
                    _a = _b.sent();
                    return [3 /*break*/, 3];
                case 2:
                    _a = (this._config.add(e), e);
                    _b.label = 3;
                case 3: return [2 /*return*/, _a];
            }
        }); }); };
        n.prototype.initNameSpace = function (e) { this._config.set("_environment", this._environment), this._environment.namespace = e, "undefined" != typeof window && (this._environment.type = "browser", window.angular && (this._environment.framework = "angularJs"), window.angular || (this._environment.framework = "js"), window[this._environment.namespace] || (window[this._environment.namespace] = { config: this._config, environment: this._environment })), "undefined" == typeof window && (this._environment.type = "server", this._environment.framework = "node"), this._environment.date = new Date, this._environment.started = Math.round(+new Date / 1e3); };
        n.prototype.fetchJson = function (e) { return s(this, void 0, void 0, function () { return __generator(this, function (_a) {
            switch (_a.label) {
                case 0: return [4 /*yield*/, fetch(e)];
                case 1: return [4 /*yield*/, (_a.sent()).json()];
                case 2: return [2 /*return*/, _a.sent()];
            }
        }); }); };
        Object.defineProperty(n.prototype, "config", {
            get: function () { return this._config; },
            enumerable: true,
            configurable: true
        });
        return n;
    }());  var o = Symbol(), a = Symbol();
    var r = /** @class */ (function (_super) {
        __extends(r, _super);
        function r(e) {
            var _this = this;
            if (_this = _super.call(this) || this, e !== a)
                throw new Error("Cannot construct singleton");
            _this._type = "BaseService";
            return _this;
        }
        Object.defineProperty(r, "instance", {
            get: function () { return this[o] || (this[o] = new r(a)), this[o]; },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(r.prototype, "type", {
            get: function () { return this._type; },
            set: function (e) { this._type = e; },
            enumerable: true,
            configurable: true
        });
        return r;
    }(n)); 
    var l = /** @class */ (function () {
        function l() {
        }
        l.copy = function (e) { return JSON.parse(JSON.stringify(e)); };
        l.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 : (l.isMergebleObject(e) && l.isMergebleObject(i) && Object.keys(i).forEach(function (t) { l.isMergebleObject(i[t]) ? (e[t] || (e[t] = {}), l.deepAssign(e[t], i[t])) : e[t] = i[t]; }), l.deepAssign.apply(l, [e].concat(t)));
        };
        l.isObject = function (e) { return null !== e && "object" == typeof e; };
        l.isMergebleObject = function (e) { return l.isObject(e) && !Array.isArray(e); };
        l.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; };
        l.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);
        };
        l.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); }); };
        l.isOnline = function () { return !("undefined" == typeof window || !window.navigator.onLine); };
        l.isBrowser = function () { return "undefined" != typeof window; };
        l.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 l;
    }()); 
    var c = /** @class */ (function () {
        function c() {
        }
        c.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");
        };
        c.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");
        };
        c.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 c;
    }());  var d = function (e, t, i, s) { return new (i || (i = Promise))(function (n, o) { function a(e) { try {
    l(s.next(e));
}
catch (e) {
    o(e);
} } function r(e) { try {
    l(s.throw(e));
}
catch (e) {
    o(e);
} } function l(e) { e.done ? n(e.value) : new i(function (t) { t(e.value); }).then(a, r); } l((s = s.apply(e, t || [])).next()); }); };
    var h = /** @class */ (function () {
        function h() {
            this._config = {}, this._locked = ["_config", "_defaults"];
        }
        h.prototype.get = function (e) { return this._config[e]; };
        h.prototype.set = function (e, t, i) {
            if (i === void 0) { i = !1; }
            if (!this.islocked(e))
                return i && (t = l.castToType(t)), this._config[e] = t;
            console.error('Config: property "' + e + '" can not be changed.');
        };
        h.prototype.add = function (e, t, i) {
            if (t === void 0) { t = !1; }
            if (i === void 0) { i = !1; }
            var s = this;
            t ? this.extend(e) : Object.keys(e).forEach(function (t) { s.set(t, e[t], i); });
        };
        h.prototype.fetch = function (e, t) {
            if (t === void 0) { t = !1; }
            return d(this, void 0, void 0, function () { var i, s; 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:
                        s = _a.sent();
                        return [2 /*return*/, (t ? this.extend(s) : Object.keys(s).forEach(function (e, t) { i.set(e, s[e]); }), s)];
                }
            }); });
        };
        h.prototype.extend = function (e, t) {
            if (t === void 0) { t = this._config; }
            l.deepAssign(t, e);
        };
        h.prototype.all = function () { return this._config; };
        h.prototype.getLocalSettings = function (e) { window.localStorage && window.localStorage.getItem(e) && this.add(c.restoreLocalModel(e)); };
        h.prototype.setLocalSettings = function (e, t) {
            if (t === void 0) { t = this._config; }
            window.localStorage && c.saveLocalModel(t, e);
        };
        h.prototype.setDefaults = function (e) { var t = this; t._defaults = e, Object.keys(e).forEach(function (i) { t.set(i, l.copy(e[i])); }); };
        h.prototype.restoreDefaults = function () { var e = this; Object.keys(e._defaults).forEach(function (t) { e.set(t, e._defaults[t]); }); };
        h.prototype.islocked = function (e) { this._locked.forEach(function (t) { if (t === e)
            return console.log('Config error: property "' + t + '" is protected'), !0; }); };
        h.prototype.lock = function (e) { return !1; };
        h.prototype.unLock = function (e) { };
        h.prototype.initXdomain = function (e) { "undefined" != typeof window && window.xdomain && (window.xdomain.masters(e.masters), window.xdomain.slaves(e.slaves)); };
        return h;
    }());  var u = Symbol(), p = Symbol();
    var g = /** @class */ (function (_super) {
        __extends(g, _super);
        function g(e) {
            var _this = this;
            if (_this = _super.call(this) || this, e !== p)
                throw new Error("Cannot construct singleton");
            _this._type = "ConfigService";
            return _this;
        }
        Object.defineProperty(g, "instance", {
            get: function () { return this[u] || (this[u] = new g(p)), this[u]; },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(g.prototype, "type", {
            get: function () { return this._type; },
            set: function (e) { this._type = e; },
            enumerable: true,
            configurable: true
        });
        return g;
    }(h));  var m = { 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" } }, f = { 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: m, 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 w = function (e, t, i, s) { return new (i || (i = Promise))(function (n, o) { function a(e) { try {
    l(s.next(e));
}
catch (e) {
    o(e);
} } function r(e) { try {
    l(s.throw(e));
}
catch (e) {
    o(e);
} } function l(e) { e.done ? n(e.value) : new i(function (t) { t(e.value); }).then(a, r); } l((s = s.apply(e, t || [])).next()); }); };
    var y = /** @class */ (function () {
        function y() {
        }
        y.getStyle = function (e, t) {
            if (t === void 0) { t = document.documentElement; }
            return window.getComputedStyle(t).getPropertyValue(e);
        };
        y.setStyle = function (e, t, i) {
            if (i === void 0) { i = document.documentElement; }
            i.style.setProperty(e, t);
        };
        y.getVar = function (e, t) {
            if (t === void 0) { t = document.documentElement; }
            return "-" !== e[0] && "-" !== e[1] && (e = "--" + e), y.getStyle(e, t);
        };
        y.setVar = function (e, t, i) {
            if (i === void 0) { i = document.documentElement; }
            "-" !== e[0] && "-" !== e[1] && (e = "--" + e), y.setStyle(e, t, i);
        };
        return y;
    }());  e.ConfigService = g, e.configDefaults = f, e.Util = l, e.BaseService = r, e.Api = i, e.Translate = /** @class */ (function () {
    function Translate() {
        var _this = this;
        this.t = {}, this.i18n = m, this.defaultLanguage = "en-US", this.supportedLanguages = ["en-US", "nl-NL"], this.translations = {}, Object.keys(m).forEach(function (e) { _this.supportedLanguages.push(e); }), this.translations = l.copy(m), this.translations["nl-NL"] = l.copy(this.translations.nl), this.translations["en-US"] = l.copy(this.translations.en), this.translations["en-BE"] = l.copy(this.translations.en), this.translations.en_BE = l.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 (s) { s === e && (t = i[s]); }), 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(" "), s_1 = i_4.indexOf(t);
        s_1 >= 0 ? i_4.splice(s_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 = {}, s = 0; for (; s < t.length; s++)
        i[t[s].name] = t[s].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 s = e.ownerDocument.defaultView; return s && s.getComputedStyle ? (t = t.replace(/([A-Z])/g, "-$1").toLowerCase(), s.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, s = 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 = s, 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, s) {
        if (t === void 0) { t = 300; }
        if (i === void 0) { i = 0; }
        if (s === void 0) { s = "block"; }
        var n = 1 / t * 10;
        e.style.opacity = "0", e.style.display = s, setTimeout(function () { !function t() { var i = parseFloat(e.style.opacity); (i += n) > 1 || (e.style.opacity = i.toString(), requestAnimationFrame(t)); }(); }, i);
    };
    DomUtil.fadeOut = function (e, t, i, s) {
        if (t === void 0) { t = 300; }
        if (i === void 0) { i = 0; }
        if (s === void 0) { s = !1; }
        var n = 1 / t * 10;
        e.style.opacity = "1", setTimeout(function () { !function t() { var i = Number(e.style.opacity); i -= n, e.style.opacity = i.toString(), i < 0 ? !1 === s && (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 = c.saveLocalModel, this.restoreLocalModel = c.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 = g.instance, this.api = new i, 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 w(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 w(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 w(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 w(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 (s, n) { var o = i.baseUrl + "index.php/"; t && (o += t + "/"), o += e, fetch(o).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] = {}); }), s(e); }); })];
                        case 1:
                            _a.sent();
                            return [2 /*return*/];
                    }
                }); });
            };
            class_1.prototype.getCollection = function (e, t, i) {
                if (i === void 0) { i = !1; }
                return w(this, void 0, void 0, function () {
                    var t, s, _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:
                                s = _a[_b] = _e.sent();
                                if (!i) return [3 /*break*/, 5];
                                e_2 = [];
                                Object.keys(s.data).forEach(function (t) { e_2.push(_this.getEntityRelationships({ data: s.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(s.data).forEach(function (e, t) { _this.entities[s.data[e].attributes.uuid] = s.data[e]; }), s)];
                        }
                    });
                });
            };
            class_1.prototype.getCollections = function (e, t, i) {
                if (i === void 0) { i = !1; }
                return w(this, void 0, void 0, function () {
                    var s, _a, _b, _i, e_3;
                    var _this = this;
                    return __generator(this, function (_c) {
                        switch (_c.label) {
                            case 0:
                                s = [];
                                e.forEach(function (e) { s.push(_this.getCollection(e, t, i)); });
                                _a = [];
                                for (_b in s)
                                    _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*/, s[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 w(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 (s, n) { var o = !1; t.forEach(function (e) { e === s && (o = !0); }), o || i.push(_this.getCollection(s, {}, 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 w(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 w(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 w(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, s) { 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 w(this, void 0, void 0, function () {
                var i, s;
                var _this = this;
                return __generator(this, function (_a) {
                    switch (_a.label) {
                        case 0:
                            i = this;
                            s = "uuid";
                            "number" == typeof (e = l.castToType(e)) && (s = "nid");
                            return [4 /*yield*/, new Promise(function (n) { var o; if (_this.cache) {
                                    var t_2;
                                    if (Object.keys(_this.entities).forEach(function (i) { _this.entities[i].data && _this.entities[i].data.attributes[s] == e && (t_2 = _this.entities[i]); }), t_2)
                                        return void n(t_2);
                                } if (_this.views.node_index && _this.views.node_index.forEach(function (i) { i[s] == e && (t = i.type); }), t)
                                    o = "node/" + t, _this.get(o + "?filter[" + s + "][value]=" + e).then(function (e) { a(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[" + s + "][value]=" + e).then(function (e) { a(e); }); });
                                } function a(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 () { n(t_4); });
                                } } })];
                        case 1: return [2 /*return*/, _a.sent()];
                    }
                });
            }); };
            class_1.prototype.getNodes = function (e) { return w(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 w(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 w(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, s) { _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 w(this, void 0, void 0, function () {
                var t;
                var _this = this;
                return __generator(this, function (_a) {
                    if (Object.keys(this.collections).forEach(function (i, s) { 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;
        }(i)), 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 l.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 (s) { jDrupal.userLogin(e, t).then(function () { i.user = jDrupal.currentUser(), i.api.setCredentials(jDrupal.settings, "drupal:authUser:" + i.domain), i.authenticated = !0, s(); }); }); };
    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, s) { var n = e; _this.api.get(n.attributes.display.rest_export_1.display_options.path, t).then(function (e) { _this.model.views[n.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 s = [], n = i.data.attributes; !0 === n.field_cache && (_this.jsonApi.cache = n.field_cache), n.field_preload_collections && s.push(_this.jsonApi.getAllCollections(!0)), Object.keys(_this.model.entities).forEach(function (t) { var i = _this.model.entities[t]; "menu--menu" == i.type && s.push(_this.menuLoad(i.attributes.id, n.cache)), "view--view" == i.type && s.push(_this.getView(i)), i.data && i.data.type.match("node--") && i.data.attributes.uuid !== e && s.push(_this.jsonApi.getNode(i.data.attributes.uuid)); }), _this.getSiteData(s).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 s = e.api.getCredentials("drupal:authUser:" + e.domain); if (s) {
        for (var e_8 in s)
            jDrupal.settings[e_8] = s[e_8];
        var i_5 = atob(s.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 (s, n) { i.api.get("entity/menu/" + e + "/tree", { _format: "hal_json" }).then(function (n) { var o = n; if (i.model.menus[e] = o, t) {
            var e_9 = [];
            o.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), s(o); });
        }
        else
            s(o); }); });
    };
    Drupal.prototype.bookLoad = function (e, t) {
        if (t === void 0) { t = !1; }
        var i = this;
        return new Promise(function (s, n) { i.api.get("rest/book_tree/" + e, { _format: "hal_json" }).then(function (n) { i.model.books[e] = n; var o = i.parseBookTree(e); t ? i.jsonApi.getNodes(o).then(function () { s(n); }) : s(n); }); });
    };
    Drupal.prototype.parseBookTree = function (e) { var t = this.model.books[e]; var i, s, n, o, a; for (o in s = [], n = [], t)
        i = t[o].below; for (o in i) {
        var e_10 = void 0;
        for (a in i[o])
            (e_10 = i[o]).link.route_parameters = { node: i[o].link.nid }, e_10.link.href = "/node/" + e_10.link.nid, n.push(i[o].link.nid);
        s.push(e_10);
    } return this.model.menus["book_" + e] = s, n; };
    Drupal.prototype.nodeLoad = function (e) { var t = this; return new Promise(function (i, s) { 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 (s) { for (var s_2 in e)
        i.push(t.nodeLoad(e[s_2])); Promise.all(i).then(function () { s(); }); }); };
    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, s) { 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 s = []; i.forEach(function (t) { t.id && (e.model.collections.post[t.id] = t, s.push(t)); }), t(s); }); }); };
    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 (s, n) { function o(e, t, n) { i.model.collections[t][e] = n, s(n); } !0 === i.settings.cache && i.model.collections[t][e] ? s(i.model.collections[t][e]) : ("post" === t && i.api.posts().id(e).then(function (i) { return o(e, t, i); }), "page" === t && i.api.pages().id(e).then(function (i) { return o(e, t, i); }), "app" === t && i.api.apps().id(e).then(function (i) { return o(e, t, i); }), "iframe" === t && i.api.iframes().id(e).then(function (i) { return o(e, t, i); })); }); };
    Wordpress.prototype.getMenu = function (e) { var t = this; return new Promise(function (i, s) { t.api.menus().id(e).then(function (s) { t.model.menus[e] = s, i(t.model.menus[e]); }); }); };
    Wordpress.prototype.getMenus = function () { var e = this; return new Promise(function (t, i) { var s = []; var n = 0; e.model.params.menus.length ? (e.model.params.menus.forEach(function (e) { s.push(e.slug); }), s.forEach(function (i) { e.getMenu(i).then(function (o) { e.model.menus[i] = o, ++n === s.length && t(e.model.menus); }); })) : t(e.model.menus); }); };
    Wordpress.prototype.saveLocal = function () { c.saveLocalModel(this.model, this.model.params.baseUrl); };
    Wordpress.prototype.restoreLocal = function () { this.model = c.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, s) { t.then(function (t) { e.site = t, i(); }); }); };
    return Wordpress;
}()), e.Css = y, e.StringUtil = /** @class */ (function () {
    function StringUtil() {
    }
    StringUtil.replaceAll = function (e, t, i, s) {
        if (s === void 0) { s = !1; }
        return e ? (n = t, o = i, a = s, String(e).replace(new RegExp(n.replace(/([\/\,\!\\\^\$\{\}\[\]\(\)\.\*\+\?\|\<\>\-\&])/g, "\\$&"), a ? "gi" : "g"), "string" == typeof o ? o.replace(/\$/g, "$$$$") : o)) : e;
        var n, o, a;
    };
    StringUtil.between = function (e, t, i, s) {
        if (s === void 0) { s = !1; }
        return e ? function (e, t, i) { var s = e.indexOf(t); if (!(s >= 0))
            return ""; if (e = e.substring(s + t.length), i) {
            if (!((s = e.indexOf(i)) >= 0))
                return "";
            e = e.substring(0, s);
        } return e; }(e, t, i) : e;
    };
    return StringUtil;
}()); });
