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-31baaa34.js", ["exports", "./chunk-6409091d.js", "./chunk-735731b6.js", "./chunk-c13350ec.js", "./chunk-4bc80c3c.js"], function (e, t, s, n, i) { window.webcomponents.h; var o = { 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" }], 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" } }, 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" }, language: "en", languages: [{ key: "nl", value: "Nederlands" }, { key: "en", value: "English" }], 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"] } }; var r = function (e, t, s, n) { return new (s || (s = Promise))(function (i, o) { function r(e) { try {
    c(n.next(e));
}
catch (e) {
    o(e);
} } function a(e) { try {
    c(n.throw(e));
}
catch (e) {
    o(e);
} } function c(e) { e.done ? i(e.value) : new s(function (t) { t(e.value); }).then(r, a); } c((n = n.apply(e, t || [])).next()); }); }; var a = Symbol(), c = Symbol();
    var u = /** @class */ (function () {
        function u(e) {
            if (e !== c)
                throw new Error("Cannot construct singleton");
            this._configService = s.ConfigService.instance, this._translateService = n.TranslateService.instance, this._type = "BaseService", this._environment = { global: this.getGlobal(), started: Math.round(+new Date / 1e3), type: "js" };
        }
        u.prototype.initApp = function (e, t, s) {
            if (t === void 0) { t = !1; }
            return r(this, void 0, void 0, function () { var _a; return __generator(this, function (_b) {
                switch (_b.label) {
                    case 0:
                        s && this.initGlobalNameSpace(s), t && this.config.setDefaults(o);
                        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 = "object" == typeof e ? (this.config.add(e), e) : void 0;
                        _b.label = 3;
                    case 3: return [2 /*return*/, _a];
                }
            }); });
        };
        u.prototype.fetchJson = function (e) { return r(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()];
            }
        }); }); };
        u.prototype.getGlobal = function () { if ("undefined" != typeof self)
            return self; if ("undefined" != typeof window)
            return window; if (void 0 !== t.global)
            return t.global; throw new Error("unable to locate global object"); };
        u.prototype.initGlobalNameSpace = function (e) {
            if (e === void 0) { e = "_ema"; }
            this.config.set("globalNameSpace", e), this.getGlobal()[e] = this;
        };
        Object.defineProperty(u.prototype, "config", {
            get: function () { return this._configService; },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(u.prototype, "environment", {
            get: function () { return this._environment; },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(u.prototype, "translation", {
            get: function () { return this._translateService; },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(u.prototype, "translateService", {
            get: function () { return this._translateService; },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(u, "instance", {
            get: function () { return this[a] || (this[a] = new u(c)), this[a]; },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(u.prototype, "type", {
            get: function () { return this._type; },
            set: function (e) { this._type = e; },
            enumerable: true,
            configurable: true
        });
        return u;
    }());  var l = function (e, t, s, n) { return new (s || (s = Promise))(function (i, o) { function r(e) { try {
    c(n.next(e));
}
catch (e) {
    o(e);
} } function a(e) { try {
    c(n.throw(e));
}
catch (e) {
    o(e);
} } function c(e) { e.done ? i(e.value) : new s(function (t) { t(e.value); }).then(r, a); } c((n = n.apply(e, t || [])).next()); }); };
    var p = /** @class */ (function () {
        function p() {
            this.optionsDefault = { cache: "no-cache", credentials: "same-origin", headers: {}, mode: "same-origin", method: "GET" }, this._interceptors = [];
        }
        p.prototype.get = function (e, t) {
            if (t === void 0) { t = {}; }
            return l(this, void 0, void 0, function () { var s; return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        s = this.preflightGet(e, t);
                        return [4 /*yield*/, fetch(s.url, s.options).then(function (e) { return e.json(); }).then(function (e) { return e; }).catch(function (e) { console.error(e); })];
                    case 1: return [2 /*return*/, _a.sent()];
                }
            }); });
        };
        p.prototype.put = function (e, t, s) { };
        p.prototype.post = function (e, t, s) { };
        p.prototype.delete = function (e, t, s) { };
        p.prototype.preflightGet = function (e, s) {
            if (s === void 0) { s = {}; }
            var n = t.Util.copy(this.optionsDefault);
            (s = Object.assign({}, n, s)).params && (e += (-1 === e.indexOf("?") ? "?" : "&") + this.queryParams(s.params), delete s.params);
            var i = this.applyInterceptors({ type: "request", url: e, options: s });
            return { url: e = i[0], options: s = i[1] };
        };
        p.prototype.queryParams = function (e) { return Object.keys(e).map(function (t) { return encodeURIComponent(t) + "=" + encodeURIComponent(e[t]); }).join("&"); };
        p.prototype.applyInterceptors = function (e) { var t; if ("request" === e.type)
            return t = [e.url, e.options], this.interceptors.forEach(function (e) { e.request && (t = e.request(t[0], t[1])); }), t; };
        p.prototype.flushInterceptors = function () { this._interceptors = []; };
        p.prototype.registerInterceptor = function (e) { this._interceptors.push(e); };
        p.prototype.unregisterInterceptor = function (e) {
            var _this = this;
            var t = 0;
            this._interceptors.forEach(function (s) { s === e && _this._interceptors.splice(t, 1), t++; });
        };
        Object.defineProperty(p.prototype, "interceptors", {
            get: function () { return this._interceptors; },
            enumerable: true,
            configurable: true
        });
        return p;
    }());  var h = Symbol(), d = Symbol();
    var m = /** @class */ (function (_super) {
        __extends(m, _super);
        function m(e) {
            var _this = this;
            if (_this = _super.call(this) || this, e !== d)
                throw new Error("Cannot construct singleton");
            _this._type = "HttpService";
            return _this;
        }
        Object.defineProperty(m, "instance", {
            get: function () { return this[h] || (this[h] = new m(d)), this[h]; },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(m.prototype, "type", {
            get: function () { return this._type; },
            set: function (e) { this._type = e; },
            enumerable: true,
            configurable: true
        });
        return m;
    }(p));  var g = function (e, t, s, n) { return new (s || (s = Promise))(function (i, o) { function r(e) { try {
    c(n.next(e));
}
catch (e) {
    o(e);
} } function a(e) { try {
    c(n.throw(e));
}
catch (e) {
    o(e);
} } function c(e) { e.done ? i(e.value) : new s(function (t) { t(e.value); }).then(r, a); } c((n = n.apply(e, t || [])).next()); }); }; var f = Symbol(), y = Symbol();
    var b = /** @class */ (function () {
        function b(e) {
            if (this._rules = [{ actions: "read", subject: "all" }], this._roles = { ANONYMOUS: [{ actions: "read", subject: "all" }] }, e !== y)
                throw new Error("Cannot construct singleton");
            this._type = "PermissionsService", this._http = m.instance;
        }
        Object.defineProperty(b, "instance", {
            get: function () { return this[f] || (this[f] = new b(y)), this[f]; },
            enumerable: true,
            configurable: true
        });
        b.prototype.loadRules = function (e, t, s) {
            if (t === void 0) { t = !0; }
            return g(this, void 0, void 0, function () { var n; return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this._http.get(e)];
                    case 1:
                        n = _a.sent();
                        s && (n = n[s]), this.addRules(n, t);
                        return [2 /*return*/];
                }
            }); });
        };
        b.prototype.addRules = function (e, t) {
            if (t === void 0) { t = !1; }
            this.rules = t ? e : this.rules.concat(e), this.registerPermissionComponents();
        };
        b.prototype.registerPermissionComponents = function (e) {
            var _this = this;
            (e || Array.from(document.getElementsByTagName("ema-permission"))).forEach(function (e) { e.setPermissionService(_this); });
        };
        Object.defineProperty(b.prototype, "rules", {
            get: function () { return this._rules; },
            set: function (e) { this._rules = e; },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(b.prototype, "roles", {
            get: function () { return this._roles; },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(b.prototype, "user", {
            get: function () { return this._user; },
            set: function (e) { this._user = e; },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(b.prototype, "type", {
            get: function () { return this._type; },
            set: function (e) { this._type = e; },
            enumerable: true,
            configurable: true
        });
        return b;
    }()); 
    var w = /** @class */ (function () {
        function w() {
        }
        w.getStyle = function (e, t) {
            if (t === void 0) { t = document.documentElement; }
            return window.getComputedStyle(t).getPropertyValue(e);
        };
        w.setStyle = function (e, t, s) {
            if (s === void 0) { s = document.documentElement; }
            s.style.setProperty(e, t);
        };
        w.getVar = function (e, t) {
            if (t === void 0) { t = document.documentElement; }
            return "-" !== e[0] && "-" !== e[1] && (e = "--" + e), w.getStyle(e, t);
        };
        w.setVar = function (e, t, s) {
            if (s === void 0) { s = document.documentElement; }
            "-" !== e[0] && "-" !== e[1] && (e = "--" + e), w.setStyle(e, t, s);
        };
        return w;
    }());  e.User = /** @class */ (function () {
    function User(e, s, n, i) {
        if (e === void 0) { e = "visitor"; }
        if (s === void 0) { s = ["ANONYMOUS"]; }
        this.roles = [], this.permissions = b.instance, this.name = e, this.roles = s, n || (this.id = t.Util.getUUID()), i || (this.created = t.Util.getTimeStamp());
    }
    User.prototype.addRole = function (e) { this.roles.push(e), this.roles = t.Util.arraySetUnique(this.roles); };
    User.prototype.removeRole = function (e) { var t = this.roles.filter(function (t, s, n) { return t !== e; }); this.roles = t; };
    User.prototype.hasRole = function (e) { var t = !1; return this.roles.forEach(function (s) { s === e && (t = !0); }), t; };
    return User;
}()), e.BaseService = u, e.PermissionsService = b, e.Http = p, 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 (s, n) { t.initApi(e).then(function () { e.app_server ? t.getParams().then(function () { t.getMenus().then(function () { t.ready = !0, s(); }); }) : s(); }); }); };
    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, s) { "undefined" == typeof window || window.WPAPI || (console.error("ERROR: WPAPI is not defined as global"), s()), 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, s) { e.api.posts().then(function (s) { var n = []; s.forEach(function (t) { t.id && (e.model.collections.post[t.id] = t, n.push(t)); }), t(n); }); }); };
    Wordpress.prototype.getParams = function () { var e = this; return new Promise(function (t, s) { e.api.params().then(function (s) { e.model.params = s, t(s); }); }); };
    Wordpress.prototype.getPost = function (e, t) { var s = this; return this.model.collections[t] || (this.model.collections[t] = {}), new Promise(function (n, i) { function o(e, t, i) { s.model.collections[t][e] = i, n(i); } !0 === s.settings.cache && s.model.collections[t][e] ? n(s.model.collections[t][e]) : ("post" === t && s.api.posts().id(e).then(function (s) { return o(e, t, s); }), "page" === t && s.api.pages().id(e).then(function (s) { return o(e, t, s); }), "app" === t && s.api.apps().id(e).then(function (s) { return o(e, t, s); }), "iframe" === t && s.api.iframes().id(e).then(function (s) { return o(e, t, s); })); }); };
    Wordpress.prototype.getMenu = function (e) { var t = this; return new Promise(function (s, n) { t.api.menus().id(e).then(function (n) { t.model.menus[e] = n, s(t.model.menus[e]); }); }); };
    Wordpress.prototype.getMenus = function () { var e = this; return new Promise(function (t, s) { var n = []; var i = 0; e.model.params.menus.length ? (e.model.params.menus.forEach(function (e) { n.push(e.slug); }), n.forEach(function (s) { e.getMenu(s).then(function (o) { e.model.menus[s] = o, ++i === n.length && t(e.model.menus); }); })) : t(e.model.menus); }); };
    Wordpress.prototype.saveLocal = function () { i.Storage.saveLocalModel(this.model, this.model.params.baseUrl); };
    Wordpress.prototype.restoreLocal = function () { this.model = i.Storage.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 (s, n) { t.then(function (t) { e.site = t, s(); }); }); };
    return Wordpress;
}()), e.Css = w; });
