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 };
    }
};
import { a as i18n, b as TranslateService } from "./chunk-67be3191.js";
import { b as global$1 } from "./chunk-25ecf4a4.js";
import { a as ConfigService } from "./chunk-ccff1a1c.js";
import { a as Storage } from "./chunk-7fb7349a.js";
var configDefaults = { 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" } }, language: "en", languages: [{ key: "nl", value: "Nederlands" }, { key: "en", value: "English" }], i18n: i18n, 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 __awaiter = function (t, e, r, n) { return new (r || (r = Promise))(function (i, o) { function s(t) { try {
    u(n.next(t));
}
catch (t) {
    o(t);
} } function c(t) { try {
    u(n.throw(t));
}
catch (t) {
    o(t);
} } function u(t) { t.done ? i(t.value) : new r(function (e) { e(t.value); }).then(s, c); } u((n = n.apply(t, e || [])).next()); }); };
var singleton = Symbol(), singletonEnforcer = Symbol();
var BaseService = /** @class */ (function () {
    function BaseService(t) {
        if (this._environment = { type: "node" }, t !== singletonEnforcer)
            throw new Error("Cannot construct singleton");
        this._configService = ConfigService.instance, this._translateService = TranslateService.instance, this._global = this.getGlobal(), this._type = "BaseService";
    }
    BaseService.prototype.initApp = function (t, e, r) {
        if (e === void 0) { e = !1; }
        return __awaiter(this, void 0, void 0, function () { var _a; return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    r && this.initGlobalNameSpace(r), e && this.config.setDefaults(configDefaults);
                    if (!("string" == typeof t)) return [3 /*break*/, 2];
                    return [4 /*yield*/, this.config.fetch(t, !0)];
                case 1:
                    _a = _b.sent();
                    return [3 /*break*/, 3];
                case 2:
                    _a = "object" == typeof t ? (this.config.add(t), t) : void 0;
                    _b.label = 3;
                case 3: return [2 /*return*/, _a];
            }
        }); });
    };
    BaseService.prototype.initGlobalNameSpace = function (t) {
        if (t === void 0) { t = "_ema"; }
        this.config.set("globalNameSpace", t), this._environment.namespace = t, this._environment.date = new Date, this._environment.started = Math.round(+new Date / 1e3), this._environment.framework = "js", this.getGlobal()[t] = this, "undefined" != typeof window && (this._environment.type = "browser", window.angular && (this._environment.framework = "angularJs"));
    };
    BaseService.prototype.fetchJson = function (t) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
        switch (_a.label) {
            case 0: return [4 /*yield*/, fetch(t)];
            case 1: return [4 /*yield*/, (_a.sent()).json()];
            case 2: return [2 /*return*/, _a.sent()];
        }
    }); }); };
    Object.defineProperty(BaseService.prototype, "config", {
        get: function () { return this._configService; },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseService.prototype, "environment", {
        get: function () { return this._environment; },
        enumerable: true,
        configurable: true
    });
    BaseService.prototype.getGlobal = function () { if ("undefined" != typeof self)
        return self; if ("undefined" != typeof window)
        return window; if (void 0 !== global$1)
        return global$1; throw new Error("unable to locate global object"); };
    Object.defineProperty(BaseService.prototype, "translation", {
        get: function () { return this._translateService; },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseService, "instance", {
        get: function () { return this[singleton] || (this[singleton] = new BaseService(singletonEnforcer)), this[singleton]; },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BaseService.prototype, "type", {
        get: function () { return this._type; },
        set: function (t) { this._type = t; },
        enumerable: true,
        configurable: true
    });
    return BaseService;
}());
var extendStatics = function (t, e) { return (extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function (t, e) { t.__proto__ = e; } || function (t, e) { for (var r in e)
    e.hasOwnProperty(r) && (t[r] = e[r]); })(t, e); };
function __extends(t, e) { function r() { this.constructor = t; } extendStatics(t, e), t.prototype = null === e ? Object.create(e) : (r.prototype = e.prototype, new r); }
function isFunction(t) { return "function" == typeof t; }
var _enable_super_gross_mode_that_will_cause_bad_things = !1, config = { Promise: void 0, set useDeprecatedSynchronousErrorHandling(t) { t && (new Error).stack, _enable_super_gross_mode_that_will_cause_bad_things = t; }, get useDeprecatedSynchronousErrorHandling() { return _enable_super_gross_mode_that_will_cause_bad_things; } };
function hostReportError(t) { setTimeout(function () { throw t; }); }
var empty = { closed: !0, next: function (t) { }, error: function (t) { if (config.useDeprecatedSynchronousErrorHandling)
        throw t; hostReportError(t); }, complete: function () { } }, isArray = Array.isArray || function (t) { return t && "number" == typeof t.length; };
function isObject(t) { return null != t && "object" == typeof t; }
var tryCatchTarget, errorObject = { e: {} };
function tryCatcher() { try {
    return tryCatchTarget.apply(this, arguments);
}
catch (t) {
    return errorObject.e = t, errorObject;
} }
function tryCatch(t) { return tryCatchTarget = t, tryCatcher; }
var UnsubscriptionError = function (t) { function e(r) { var n = t.call(this, r ? r.length + " errors occurred during unsubscription:\n  " + r.map(function (t, e) { return e + 1 + ") " + t.toString(); }).join("\n  ") : "") || this; return n.errors = r, n.name = "UnsubscriptionError", Object.setPrototypeOf(n, e.prototype), n; } return __extends(e, t), e; }(Error), Subscription = function () { function t(t) { this.closed = !1, this._parent = null, this._parents = null, this._subscriptions = null, t && (this._unsubscribe = t); } var e; return t.prototype.unsubscribe = function () { var t, e = !1; if (!this.closed) {
    var r = this._parent, n = this._parents, i = this._unsubscribe, o = this._subscriptions;
    this.closed = !0, this._parent = null, this._parents = null, this._subscriptions = null;
    for (var s = -1, c = n ? n.length : 0; r;)
        r.remove(this), r = ++s < c && n[s] || null;
    if (isFunction(i) && tryCatch(i).call(this) === errorObject && (e = !0, t = t || (errorObject.e instanceof UnsubscriptionError ? flattenUnsubscriptionErrors(errorObject.e.errors) : [errorObject.e])), isArray(o))
        for (s = -1, c = o.length; ++s < c;) {
            var u = o[s];
            if (isObject(u) && tryCatch(u.unsubscribe).call(u) === errorObject) {
                e = !0, t = t || [];
                var a = errorObject.e;
                a instanceof UnsubscriptionError ? t = t.concat(flattenUnsubscriptionErrors(a.errors)) : t.push(a);
            }
        }
    if (e)
        throw new UnsubscriptionError(t);
} }, t.prototype.add = function (e) { if (!e || e === t.EMPTY)
    return t.EMPTY; if (e === this)
    return this; var r = e; switch (typeof e) {
    case "function": r = new t(e);
    case "object":
        if (r.closed || "function" != typeof r.unsubscribe)
            return r;
        if (this.closed)
            return r.unsubscribe(), r;
        if ("function" != typeof r._addParent) {
            var n = r;
            (r = new t)._subscriptions = [n];
        }
        break;
    default: throw new Error("unrecognized teardown " + e + " added to Subscription.");
} return (this._subscriptions || (this._subscriptions = [])).push(r), r._addParent(this), r; }, t.prototype.remove = function (t) { var e = this._subscriptions; if (e) {
    var r = e.indexOf(t);
    -1 !== r && e.splice(r, 1);
} }, t.prototype._addParent = function (t) { var e = this._parent, r = this._parents; e && e !== t ? r ? -1 === r.indexOf(t) && r.push(t) : this._parents = [t] : this._parent = t; }, t.EMPTY = ((e = new t).closed = !0, e), t; }();
function flattenUnsubscriptionErrors(t) { return t.reduce(function (t, e) { return t.concat(e instanceof UnsubscriptionError ? e.errors : e); }, []); }
var rxSubscriber = "function" == typeof Symbol && "function" == typeof Symbol.for ? Symbol.for("rxSubscriber") : "@@rxSubscriber", Subscriber = function (t) { function e(e, r, n) { var i = t.call(this) || this; switch ((i.syncErrorValue = null, i.syncErrorThrown = !1, i.syncErrorThrowable = !1, i.isStopped = !1, arguments.length)) {
    case 0:
        i.destination = empty;
        break;
    case 1:
        if (!e) {
            i.destination = empty;
            break;
        }
        if ("object" == typeof e) {
            if (isTrustedSubscriber(e)) {
                var o = e[rxSubscriber]();
                i.syncErrorThrowable = o.syncErrorThrowable, i.destination = o, o.add(i);
            }
            else
                i.syncErrorThrowable = !0, i.destination = new SafeSubscriber(i, e);
            break;
        }
    default: i.syncErrorThrowable = !0, i.destination = new SafeSubscriber(i, e, r, n);
} return i; } return __extends(e, t), e.prototype[rxSubscriber] = function () { return this; }, e.create = function (t, r, n) { var i = new e(t, r, n); return i.syncErrorThrowable = !1, i; }, e.prototype.next = function (t) { this.isStopped || this._next(t); }, e.prototype.error = function (t) { this.isStopped || (this.isStopped = !0, this._error(t)); }, e.prototype.complete = function () { this.isStopped || (this.isStopped = !0, this._complete()); }, e.prototype.unsubscribe = function () { this.closed || (this.isStopped = !0, t.prototype.unsubscribe.call(this)); }, e.prototype._next = function (t) { this.destination.next(t); }, e.prototype._error = function (t) { this.destination.error(t), this.unsubscribe(); }, e.prototype._complete = function () { this.destination.complete(), this.unsubscribe(); }, e.prototype._unsubscribeAndRecycle = function () { var t = this._parent, e = this._parents; return this._parent = null, this._parents = null, this.unsubscribe(), this.closed = !1, this.isStopped = !1, this._parent = t, this._parents = e, this; }, e; }(Subscription), SafeSubscriber = function (t) { function e(e, r, n, i) { var o, s = t.call(this) || this; s._parentSubscriber = e; var c = s; return isFunction(r) ? o = r : r && (o = r.next, n = r.error, i = r.complete, r !== empty && (isFunction((c = Object.create(r)).unsubscribe) && s.add(c.unsubscribe.bind(c)), c.unsubscribe = s.unsubscribe.bind(s))), s._context = c, s._next = o, s._error = n, s._complete = i, s; } return __extends(e, t), e.prototype.next = function (t) { if (!this.isStopped && this._next) {
    var e = this._parentSubscriber;
    config.useDeprecatedSynchronousErrorHandling && e.syncErrorThrowable ? this.__tryOrSetError(e, this._next, t) && this.unsubscribe() : this.__tryOrUnsub(this._next, t);
} }, e.prototype.error = function (t) { if (!this.isStopped) {
    var e = this._parentSubscriber, r = config.useDeprecatedSynchronousErrorHandling;
    if (this._error)
        r && e.syncErrorThrowable ? (this.__tryOrSetError(e, this._error, t), this.unsubscribe()) : (this.__tryOrUnsub(this._error, t), this.unsubscribe());
    else if (e.syncErrorThrowable)
        r ? (e.syncErrorValue = t, e.syncErrorThrown = !0) : hostReportError(t), this.unsubscribe();
    else {
        if (this.unsubscribe(), r)
            throw t;
        hostReportError(t);
    }
} }, e.prototype.complete = function () { var t = this; if (!this.isStopped) {
    var e = this._parentSubscriber;
    if (this._complete) {
        var r = function () { return t._complete.call(t._context); };
        config.useDeprecatedSynchronousErrorHandling && e.syncErrorThrowable ? (this.__tryOrSetError(e, r), this.unsubscribe()) : (this.__tryOrUnsub(r), this.unsubscribe());
    }
    else
        this.unsubscribe();
} }, e.prototype.__tryOrUnsub = function (t, e) { try {
    t.call(this._context, e);
}
catch (t) {
    if (this.unsubscribe(), config.useDeprecatedSynchronousErrorHandling)
        throw t;
    hostReportError(t);
} }, e.prototype.__tryOrSetError = function (t, e, r) { if (!config.useDeprecatedSynchronousErrorHandling)
    throw new Error("bad call"); try {
    e.call(this._context, r);
}
catch (e) {
    return config.useDeprecatedSynchronousErrorHandling ? (t.syncErrorValue = e, t.syncErrorThrown = !0, !0) : (hostReportError(e), !0);
} return !1; }, e.prototype._unsubscribe = function () { var t = this._parentSubscriber; this._context = null, this._parentSubscriber = null, t.unsubscribe(); }, e; }(Subscriber);
function isTrustedSubscriber(t) { return t instanceof Subscriber || "syncErrorThrowable" in t && t[rxSubscriber]; }
function toSubscriber(t, e, r) { if (t) {
    if (t instanceof Subscriber)
        return t;
    if (t[rxSubscriber])
        return t[rxSubscriber]();
} return t || e || r ? new Subscriber(t, e, r) : new Subscriber(empty); }
var observable = "function" == typeof Symbol && Symbol.observable || "@@observable";
function noop() { }
function pipeFromArray(t) { return t ? 1 === t.length ? t[0] : function (e) { return t.reduce(function (t, e) { return e(t); }, e); } : noop; }
var Observable = function () { function t(t) { this._isScalar = !1, t && (this._subscribe = t); } return t.prototype.lift = function (e) { var r = new t; return r.source = this, r.operator = e, r; }, t.prototype.subscribe = function (t, e, r) { var n = this.operator, i = toSubscriber(t, e, r); if (n ? n.call(i, this.source) : i.add(this.source || config.useDeprecatedSynchronousErrorHandling && !i.syncErrorThrowable ? this._subscribe(i) : this._trySubscribe(i)), config.useDeprecatedSynchronousErrorHandling && i.syncErrorThrowable && (i.syncErrorThrowable = !1, i.syncErrorThrown))
    throw i.syncErrorValue; return i; }, t.prototype._trySubscribe = function (t) { try {
    return this._subscribe(t);
}
catch (e) {
    config.useDeprecatedSynchronousErrorHandling && (t.syncErrorThrown = !0, t.syncErrorValue = e), t.error(e);
} }, t.prototype.forEach = function (t, e) { var r = this; return new (e = getPromiseCtor(e))(function (e, n) { var i; i = r.subscribe(function (e) { try {
    t(e);
}
catch (t) {
    n(t), i && i.unsubscribe();
} }, n, e); }); }, t.prototype._subscribe = function (t) { var e = this.source; return e && e.subscribe(t); }, t.prototype[observable] = function () { return this; }, t.prototype.pipe = function () { for (var t = [], e = 0; e < arguments.length; e++)
    t[e] = arguments[e]; return 0 === t.length ? this : pipeFromArray(t)(this); }, t.prototype.toPromise = function (t) { var e = this; return new (t = getPromiseCtor(t))(function (t, r) { var n; e.subscribe(function (t) { return n = t; }, function (t) { return r(t); }, function () { return t(n); }); }); }, t.create = function (e) { return new t(e); }, t; }();
function getPromiseCtor(t) { if (t || (t = config.Promise || Promise), !t)
    throw new Error("no Promise impl found"); return t; }
var ObjectUnsubscribedError = function (t) { function e() { var r = t.call(this, "object unsubscribed") || this; return r.name = "ObjectUnsubscribedError", Object.setPrototypeOf(r, e.prototype), r; } return __extends(e, t), e; }(Error), SubjectSubscription = function (t) { function e(e, r) { var n = t.call(this) || this; return n.subject = e, n.subscriber = r, n.closed = !1, n; } return __extends(e, t), e.prototype.unsubscribe = function () { if (!this.closed) {
    this.closed = !0;
    var t = this.subject, e = t.observers;
    if (this.subject = null, e && 0 !== e.length && !t.isStopped && !t.closed) {
        var r = e.indexOf(this.subscriber);
        -1 !== r && e.splice(r, 1);
    }
} }, e; }(Subscription), SubjectSubscriber = function (t) { function e(e) { var r = t.call(this, e) || this; return r.destination = e, r; } return __extends(e, t), e; }(Subscriber), Subject = function (t) { function e() { var e = t.call(this) || this; return e.observers = [], e.closed = !1, e.isStopped = !1, e.hasError = !1, e.thrownError = null, e; } return __extends(e, t), e.prototype[rxSubscriber] = function () { return new SubjectSubscriber(this); }, e.prototype.lift = function (t) { var e = new AnonymousSubject(this, this); return e.operator = t, e; }, e.prototype.next = function (t) { if (this.closed)
    throw new ObjectUnsubscribedError; if (!this.isStopped)
    for (var e = this.observers, r = e.length, n = e.slice(), i = 0; i < r; i++)
        n[i].next(t); }, e.prototype.error = function (t) { if (this.closed)
    throw new ObjectUnsubscribedError; this.hasError = !0, this.thrownError = t, this.isStopped = !0; for (var e = this.observers, r = e.length, n = e.slice(), i = 0; i < r; i++)
    n[i].error(t); this.observers.length = 0; }, e.prototype.complete = function () { if (this.closed)
    throw new ObjectUnsubscribedError; this.isStopped = !0; for (var t = this.observers, e = t.length, r = t.slice(), n = 0; n < e; n++)
    r[n].complete(); this.observers.length = 0; }, e.prototype.unsubscribe = function () { this.isStopped = !0, this.closed = !0, this.observers = null; }, e.prototype._trySubscribe = function (e) { if (this.closed)
    throw new ObjectUnsubscribedError; return t.prototype._trySubscribe.call(this, e); }, e.prototype._subscribe = function (t) { if (this.closed)
    throw new ObjectUnsubscribedError; return this.hasError ? (t.error(this.thrownError), Subscription.EMPTY) : this.isStopped ? (t.complete(), Subscription.EMPTY) : (this.observers.push(t), new SubjectSubscription(this, t)); }, e.prototype.asObservable = function () { var t = new Observable; return t.source = this, t; }, e.create = function (t, e) { return new AnonymousSubject(t, e); }, e; }(Observable), AnonymousSubject = function (t) { function e(e, r) { var n = t.call(this) || this; return n.destination = e, n.source = r, n; } return __extends(e, t), e.prototype.next = function (t) { var e = this.destination; e && e.next && e.next(t); }, e.prototype.error = function (t) { var e = this.destination; e && e.error && this.destination.error(t); }, e.prototype.complete = function () { var t = this.destination; t && t.complete && this.destination.complete(); }, e.prototype._subscribe = function (t) { return this.source ? this.source.subscribe(t) : Subscription.EMPTY; }, e; }(Subject);
function refCount() { return function (t) { return t.lift(new RefCountOperator(t)); }; }
var RefCountOperator = function () { function t(t) { this.connectable = t; } return t.prototype.call = function (t, e) { var r = this.connectable; r._refCount++; var n = new RefCountSubscriber(t, r), i = e.subscribe(n); return n.closed || (n.connection = r.connect()), i; }, t; }(), RefCountSubscriber = function (t) { function e(e, r) { var n = t.call(this, e) || this; return n.connectable = r, n; } return __extends(e, t), e.prototype._unsubscribe = function () { var t = this.connectable; if (t) {
    this.connectable = null;
    var e = t._refCount;
    if (e <= 0)
        this.connection = null;
    else if (t._refCount = e - 1, e > 1)
        this.connection = null;
    else {
        var r = this.connection, n = t._connection;
        this.connection = null, !n || r && n !== r || n.unsubscribe();
    }
}
else
    this.connection = null; }, e; }(Subscriber), ConnectableObservable = function (t) { function e(e, r) { var n = t.call(this) || this; return n.source = e, n.subjectFactory = r, n._refCount = 0, n._isComplete = !1, n; } return __extends(e, t), e.prototype._subscribe = function (t) { return this.getSubject().subscribe(t); }, e.prototype.getSubject = function () { var t = this._subject; return t && !t.isStopped || (this._subject = this.subjectFactory()), this._subject; }, e.prototype.connect = function () { var t = this._connection; return t || (this._isComplete = !1, (t = this._connection = new Subscription).add(this.source.subscribe(new ConnectableSubscriber(this.getSubject(), this))), t.closed ? (this._connection = null, t = Subscription.EMPTY) : this._connection = t), t; }, e.prototype.refCount = function () { return refCount()(this); }, e; }(Observable), ConnectableSubscriber = function (t) { function e(e, r) { var n = t.call(this, e) || this; return n.connectable = r, n; } return __extends(e, t), e.prototype._error = function (e) { this._unsubscribe(), t.prototype._error.call(this, e); }, e.prototype._complete = function () { this.connectable._isComplete = !0, this._unsubscribe(), t.prototype._complete.call(this); }, e.prototype._unsubscribe = function () { var t = this.connectable; if (t) {
    this.connectable = null;
    var e = t._connection;
    t._refCount = 0, t._subject = null, t._connection = null, e && e.unsubscribe();
} }, e; }(SubjectSubscriber), RefCountSubscriber$1 = function (t) { function e(e, r) { var n = t.call(this, e) || this; return n.connectable = r, n; } return __extends(e, t), e.prototype._unsubscribe = function () { var t = this.connectable; if (t) {
    this.connectable = null;
    var e = t._refCount;
    if (e <= 0)
        this.connection = null;
    else if (t._refCount = e - 1, e > 1)
        this.connection = null;
    else {
        var r = this.connection, n = t._connection;
        this.connection = null, !n || r && n !== r || n.unsubscribe();
    }
}
else
    this.connection = null; }, e; }(Subscriber), GroupBySubscriber = function (t) { function e(e, r, n, i, o) { var s = t.call(this, e) || this; return s.keySelector = r, s.elementSelector = n, s.durationSelector = i, s.subjectSelector = o, s.groups = null, s.attemptedToUnsubscribe = !1, s.count = 0, s; } return __extends(e, t), e.prototype._next = function (t) { var e; try {
    e = this.keySelector(t);
}
catch (t) {
    return void this.error(t);
} this._group(t, e); }, e.prototype._group = function (t, e) { var r = this.groups; r || (r = this.groups = new Map); var n, i = r.get(e); if (this.elementSelector)
    try {
        n = this.elementSelector(t);
    }
    catch (t) {
        this.error(t);
    }
else
    n = t; if (!i) {
    i = this.subjectSelector ? this.subjectSelector() : new Subject, r.set(e, i);
    var o = new GroupedObservable(e, i, this);
    if (this.destination.next(o), this.durationSelector) {
        var s = void 0;
        try {
            s = this.durationSelector(new GroupedObservable(e, i));
        }
        catch (t) {
            return void this.error(t);
        }
        this.add(s.subscribe(new GroupDurationSubscriber(e, i, this)));
    }
} i.closed || i.next(n); }, e.prototype._error = function (t) { var e = this.groups; e && (e.forEach(function (e, r) { e.error(t); }), e.clear()), this.destination.error(t); }, e.prototype._complete = function () { var t = this.groups; t && (t.forEach(function (t, e) { t.complete(); }), t.clear()), this.destination.complete(); }, e.prototype.removeGroup = function (t) { this.groups.delete(t); }, e.prototype.unsubscribe = function () { this.closed || (this.attemptedToUnsubscribe = !0, 0 === this.count && t.prototype.unsubscribe.call(this)); }, e; }(Subscriber), GroupDurationSubscriber = function (t) { function e(e, r, n) { var i = t.call(this, r) || this; return i.key = e, i.group = r, i.parent = n, i; } return __extends(e, t), e.prototype._next = function (t) { this.complete(); }, e.prototype._unsubscribe = function () { var t = this.parent, e = this.key; this.key = this.parent = null, t && t.removeGroup(e); }, e; }(Subscriber), GroupedObservable = function (t) { function e(e, r, n) { var i = t.call(this) || this; return i.key = e, i.groupSubject = r, i.refCountSubscription = n, i; } return __extends(e, t), e.prototype._subscribe = function (t) { var e = new Subscription, r = this.refCountSubscription, n = this.groupSubject; return r && !r.closed && e.add(new InnerRefCountSubscription(r)), e.add(n.subscribe(t)), e; }, e; }(Observable), InnerRefCountSubscription = function (t) { function e(e) { var r = t.call(this) || this; return r.parent = e, e.count++, r; } return __extends(e, t), e.prototype.unsubscribe = function () { var e = this.parent; e.closed || this.closed || (t.prototype.unsubscribe.call(this), e.count -= 1, 0 === e.count && e.attemptedToUnsubscribe && e.unsubscribe()); }, e; }(Subscription), BehaviorSubject = function (t) { function e(e) { var r = t.call(this) || this; return r._value = e, r; } return __extends(e, t), Object.defineProperty(e.prototype, "value", { get: function () { return this.getValue(); }, enumerable: !0, configurable: !0 }), e.prototype._subscribe = function (e) { var r = t.prototype._subscribe.call(this, e); return r && !r.closed && e.next(this._value), r; }, e.prototype.getValue = function () { if (this.hasError)
    throw this.thrownError; if (this.closed)
    throw new ObjectUnsubscribedError; return this._value; }, e.prototype.next = function (e) { t.prototype.next.call(this, this._value = e); }, e; }(Subject), Action = function (t) { function e(e, r) { return t.call(this) || this; } return __extends(e, t), e.prototype.schedule = function (t, e) { return void 0 === e && (e = 0), this; }, e; }(Subscription), AsyncAction = function (t) { function e(e, r) { var n = t.call(this, e, r) || this; return n.scheduler = e, n.work = r, n.pending = !1, n; } return __extends(e, t), e.prototype.schedule = function (t, e) { if (void 0 === e && (e = 0), this.closed)
    return this; this.state = t; var r = this.id, n = this.scheduler; return null != r && (this.id = this.recycleAsyncId(n, r, e)), this.pending = !0, this.delay = e, this.id = this.id || this.requestAsyncId(n, this.id, e), this; }, e.prototype.requestAsyncId = function (t, e, r) { return void 0 === r && (r = 0), setInterval(t.flush.bind(t, this), r); }, e.prototype.recycleAsyncId = function (t, e, r) { if (void 0 === r && (r = 0), null !== r && this.delay === r && !1 === this.pending)
    return e; clearInterval(e); }, e.prototype.execute = function (t, e) { if (this.closed)
    return new Error("executing a cancelled action"); this.pending = !1; var r = this._execute(t, e); if (r)
    return r; !1 === this.pending && null != this.id && (this.id = this.recycleAsyncId(this.scheduler, this.id, null)); }, e.prototype._execute = function (t, e) { var r = !1, n = void 0; try {
    this.work(t);
}
catch (t) {
    r = !0, n = !!t && t || new Error(t);
} if (r)
    return this.unsubscribe(), n; }, e.prototype._unsubscribe = function () { var t = this.id, e = this.scheduler, r = e.actions, n = r.indexOf(this); this.work = null, this.state = null, this.pending = !1, this.scheduler = null, -1 !== n && r.splice(n, 1), null != t && (this.id = this.recycleAsyncId(e, t, null)), this.delay = null; }, e; }(Action), QueueAction = function (t) { function e(e, r) { var n = t.call(this, e, r) || this; return n.scheduler = e, n.work = r, n; } return __extends(e, t), e.prototype.schedule = function (e, r) { return void 0 === r && (r = 0), r > 0 ? t.prototype.schedule.call(this, e, r) : (this.delay = r, this.state = e, this.scheduler.flush(this), this); }, e.prototype.execute = function (e, r) { return r > 0 || this.closed ? t.prototype.execute.call(this, e, r) : this._execute(e, r); }, e.prototype.requestAsyncId = function (e, r, n) { return void 0 === n && (n = 0), null !== n && n > 0 || null === n && this.delay > 0 ? t.prototype.requestAsyncId.call(this, e, r, n) : e.flush(this); }, e; }(AsyncAction), Scheduler = function () { function t(e, r) { void 0 === r && (r = t.now), this.SchedulerAction = e, this.now = r; } return t.prototype.schedule = function (t, e, r) { return void 0 === e && (e = 0), new this.SchedulerAction(this, t).schedule(r, e); }, t.now = function () { return Date.now(); }, t; }(), AsyncScheduler = function (t) { function e(r, n) { void 0 === n && (n = Scheduler.now); var i = t.call(this, r, function () { return e.delegate && e.delegate !== i ? e.delegate.now() : n(); }) || this; return i.actions = [], i.active = !1, i.scheduled = void 0, i; } return __extends(e, t), e.prototype.schedule = function (r, n, i) { return void 0 === n && (n = 0), e.delegate && e.delegate !== this ? e.delegate.schedule(r, n, i) : t.prototype.schedule.call(this, r, n, i); }, e.prototype.flush = function (t) { var e = this.actions; if (this.active)
    e.push(t);
else {
    var r;
    this.active = !0;
    do {
        if (r = t.execute(t.state, t.delay))
            break;
    } while (t = e.shift());
    if (this.active = !1, r) {
        for (; t = e.shift();)
            t.unsubscribe();
        throw r;
    }
} }, e; }(Scheduler), QueueScheduler = function (t) { function e() { return null !== t && t.apply(this, arguments) || this; } return __extends(e, t), e; }(AsyncScheduler), queue = new QueueScheduler(QueueAction), EMPTY = new Observable(function (t) { return t.complete(); });
function empty$1(t) { return t ? emptyScheduled(t) : EMPTY; }
function emptyScheduled(t) { return new Observable(function (e) { return t.schedule(function () { return e.complete(); }); }); }
function isScheduler(t) { return t && "function" == typeof t.schedule; }
var subscribeToArray = function (t) { return function (e) { for (var r = 0, n = t.length; r < n && !e.closed; r++)
    e.next(t[r]); e.closed || e.complete(); }; };
function fromArray(t, e) { return new Observable(e ? function (r) { var n = new Subscription, i = 0; return n.add(e.schedule(function () { i !== t.length ? (r.next(t[i++]), r.closed || n.add(this.schedule())) : r.complete(); })), n; } : subscribeToArray(t)); }
function scalar(t) { var e = new Observable(function (e) { e.next(t), e.complete(); }); return e._isScalar = !0, e.value = t, e; }
function of() { for (var t = [], e = 0; e < arguments.length; e++)
    t[e] = arguments[e]; var r = t[t.length - 1]; switch (isScheduler(r) ? t.pop() : r = void 0, t.length) {
    case 0: return empty$1(r);
    case 1: return r ? fromArray(t, r) : scalar(t[0]);
    default: return fromArray(t, r);
} }
function throwError(t, e) { return new Observable(e ? function (r) { return e.schedule(dispatch, 0, { error: t, subscriber: r }); } : function (e) { return e.error(t); }); }
function dispatch(t) { var e = t.error; t.subscriber.error(e); }
var Notification = function () { function t(t, e, r) { this.kind = t, this.value = e, this.error = r, this.hasValue = "N" === t; } return t.prototype.observe = function (t) { switch (this.kind) {
    case "N": return t.next && t.next(this.value);
    case "E": return t.error && t.error(this.error);
    case "C": return t.complete && t.complete();
} }, t.prototype.do = function (t, e, r) { switch (this.kind) {
    case "N": return t && t(this.value);
    case "E": return e && e(this.error);
    case "C": return r && r();
} }, t.prototype.accept = function (t, e, r) { return t && "function" == typeof t.next ? this.observe(t) : this.do(t, e, r); }, t.prototype.toObservable = function () { switch (this.kind) {
    case "N": return of(this.value);
    case "E": return throwError(this.error);
    case "C": return empty$1();
} throw new Error("unexpected notification kind value"); }, t.createNext = function (e) { return void 0 !== e ? new t("N", e) : t.undefinedValueNotification; }, t.createError = function (e) { return new t("E", void 0, e); }, t.createComplete = function () { return t.completeNotification; }, t.completeNotification = new t("C"), t.undefinedValueNotification = new t("N", void 0), t; }(), ObserveOnSubscriber = function (t) { function e(e, r, n) { void 0 === n && (n = 0); var i = t.call(this, e) || this; return i.scheduler = r, i.delay = n, i; } return __extends(e, t), e.dispatch = function (t) { var e = t.notification, r = t.destination; e.observe(r), this.unsubscribe(); }, e.prototype.scheduleMessage = function (t) { this.add(this.scheduler.schedule(e.dispatch, this.delay, new ObserveOnMessage(t, this.destination))); }, e.prototype._next = function (t) { this.scheduleMessage(Notification.createNext(t)); }, e.prototype._error = function (t) { this.scheduleMessage(Notification.createError(t)); }, e.prototype._complete = function () { this.scheduleMessage(Notification.createComplete()); }, e; }(Subscriber), ObserveOnMessage = function (t, e) { this.notification = t, this.destination = e; }, ReplaySubject = function (t) { function e(e, r, n) { void 0 === e && (e = Number.POSITIVE_INFINITY), void 0 === r && (r = Number.POSITIVE_INFINITY); var i = t.call(this) || this; return i.scheduler = n, i._events = [], i._infiniteTimeWindow = !1, i._bufferSize = e < 1 ? 1 : e, i._windowTime = r < 1 ? 1 : r, r === Number.POSITIVE_INFINITY ? (i._infiniteTimeWindow = !0, i.next = i.nextInfiniteTimeWindow) : i.next = i.nextTimeWindow, i; } return __extends(e, t), e.prototype.nextInfiniteTimeWindow = function (e) { var r = this._events; r.push(e), r.length > this._bufferSize && r.shift(), t.prototype.next.call(this, e); }, e.prototype.nextTimeWindow = function (e) { this._events.push(new ReplayEvent(this._getNow(), e)), this._trimBufferThenGetEvents(), t.prototype.next.call(this, e); }, e.prototype._subscribe = function (t) { var e, r = this._infiniteTimeWindow, n = r ? this._events : this._trimBufferThenGetEvents(), i = this.scheduler, o = n.length; if (this.closed)
    throw new ObjectUnsubscribedError; if (this.isStopped || this.hasError ? e = Subscription.EMPTY : (this.observers.push(t), e = new SubjectSubscription(this, t)), i && t.add(t = new ObserveOnSubscriber(t, i)), r)
    for (var s = 0; s < o && !t.closed; s++)
        t.next(n[s]);
else
    for (s = 0; s < o && !t.closed; s++)
        t.next(n[s].value); return this.hasError ? t.error(this.thrownError) : this.isStopped && t.complete(), e; }, e.prototype._getNow = function () { return (this.scheduler || queue).now(); }, e.prototype._trimBufferThenGetEvents = function () { for (var t = this._getNow(), e = this._bufferSize, r = this._windowTime, n = this._events, i = n.length, o = 0; o < i && !(t - n[o].time < r);)
    o++; return i > e && (o = Math.max(o, i - e)), o > 0 && n.splice(0, o), n; }, e; }(Subject), ReplayEvent = function (t, e) { this.time = t, this.value = e; }, AsyncSubject = function (t) { function e() { var e = null !== t && t.apply(this, arguments) || this; return e.value = null, e.hasNext = !1, e.hasCompleted = !1, e; } return __extends(e, t), e.prototype._subscribe = function (e) { return this.hasError ? (e.error(this.thrownError), Subscription.EMPTY) : this.hasCompleted && this.hasNext ? (e.next(this.value), e.complete(), Subscription.EMPTY) : t.prototype._subscribe.call(this, e); }, e.prototype.next = function (t) { this.hasCompleted || (this.value = t, this.hasNext = !0); }, e.prototype.error = function (e) { this.hasCompleted || t.prototype.error.call(this, e); }, e.prototype.complete = function () { this.hasCompleted = !0, this.hasNext && t.prototype.next.call(this, this.value), t.prototype.complete.call(this); }, e; }(Subject), nextHandle = 1, tasksByHandle = {};
function runIfPresent(t) { var e = tasksByHandle[t]; e && e(); }
var Immediate = { setImmediate: function (t) { var e = nextHandle++; return tasksByHandle[e] = t, Promise.resolve().then(function () { return runIfPresent(e); }), e; }, clearImmediate: function (t) { delete tasksByHandle[t]; } }, AsapAction = function (t) { function e(e, r) { var n = t.call(this, e, r) || this; return n.scheduler = e, n.work = r, n; } return __extends(e, t), e.prototype.requestAsyncId = function (e, r, n) { return void 0 === n && (n = 0), null !== n && n > 0 ? t.prototype.requestAsyncId.call(this, e, r, n) : (e.actions.push(this), e.scheduled || (e.scheduled = Immediate.setImmediate(e.flush.bind(e, null)))); }, e.prototype.recycleAsyncId = function (e, r, n) { if (void 0 === n && (n = 0), null !== n && n > 0 || null === n && this.delay > 0)
    return t.prototype.recycleAsyncId.call(this, e, r, n); 0 === e.actions.length && (Immediate.clearImmediate(r), e.scheduled = void 0); }, e; }(AsyncAction), AsapScheduler = function (t) { function e() { return null !== t && t.apply(this, arguments) || this; } return __extends(e, t), e.prototype.flush = function (t) { this.active = !0, this.scheduled = void 0; var e, r = this.actions, n = -1, i = r.length; t = t || r.shift(); do {
    if (e = t.execute(t.state, t.delay))
        break;
} while (++n < i && (t = r.shift())); if (this.active = !1, e) {
    for (; ++n < i && (t = r.shift());)
        t.unsubscribe();
    throw e;
} }, e; }(AsyncScheduler), asap = new AsapScheduler(AsapAction), async = new AsyncScheduler(AsyncAction), AnimationFrameAction = function (t) { function e(e, r) { var n = t.call(this, e, r) || this; return n.scheduler = e, n.work = r, n; } return __extends(e, t), e.prototype.requestAsyncId = function (e, r, n) { return void 0 === n && (n = 0), null !== n && n > 0 ? t.prototype.requestAsyncId.call(this, e, r, n) : (e.actions.push(this), e.scheduled || (e.scheduled = requestAnimationFrame(function () { return e.flush(null); }))); }, e.prototype.recycleAsyncId = function (e, r, n) { if (void 0 === n && (n = 0), null !== n && n > 0 || null === n && this.delay > 0)
    return t.prototype.recycleAsyncId.call(this, e, r, n); 0 === e.actions.length && (cancelAnimationFrame(r), e.scheduled = void 0); }, e; }(AsyncAction), AnimationFrameScheduler = function (t) { function e() { return null !== t && t.apply(this, arguments) || this; } return __extends(e, t), e.prototype.flush = function (t) { this.active = !0, this.scheduled = void 0; var e, r = this.actions, n = -1, i = r.length; t = t || r.shift(); do {
    if (e = t.execute(t.state, t.delay))
        break;
} while (++n < i && (t = r.shift())); if (this.active = !1, e) {
    for (; ++n < i && (t = r.shift());)
        t.unsubscribe();
    throw e;
} }, e; }(AsyncScheduler), animationFrame = new AnimationFrameScheduler(AnimationFrameAction), VirtualTimeScheduler = function (t) { function e(e, r) { void 0 === e && (e = VirtualAction), void 0 === r && (r = Number.POSITIVE_INFINITY); var n = t.call(this, e, function () { return n.frame; }) || this; return n.maxFrames = r, n.frame = 0, n.index = -1, n; } return __extends(e, t), e.prototype.flush = function () { for (var t, e, r = this.actions, n = this.maxFrames; (e = r.shift()) && (this.frame = e.delay) <= n && !(t = e.execute(e.state, e.delay));)
    ; if (t) {
    for (; e = r.shift();)
        e.unsubscribe();
    throw t;
} }, e.frameTimeFactor = 10, e; }(AsyncScheduler), VirtualAction = function (t) { function e(e, r, n) { void 0 === n && (n = e.index += 1); var i = t.call(this, e, r) || this; return i.scheduler = e, i.work = r, i.index = n, i.active = !0, i.index = e.index = n, i; } return __extends(e, t), e.prototype.schedule = function (r, n) { if (void 0 === n && (n = 0), !this.id)
    return t.prototype.schedule.call(this, r, n); this.active = !1; var i = new e(this.scheduler, this.work); return this.add(i), i.schedule(r, n); }, e.prototype.requestAsyncId = function (t, r, n) { void 0 === n && (n = 0), this.delay = t.frame + n; var i = t.actions; return i.push(this), i.sort(e.sortActions), !0; }, e.prototype.recycleAsyncId = function (t, e, r) { void 0 === r && (r = 0); }, e.prototype._execute = function (e, r) { if (!0 === this.active)
    return t.prototype._execute.call(this, e, r); }, e.sortActions = function (t, e) { return t.delay === e.delay ? t.index === e.index ? 0 : t.index > e.index ? 1 : -1 : t.delay > e.delay ? 1 : -1; }, e; }(AsyncAction);
function identity(t) { return t; }
var ArgumentOutOfRangeError = function (t) { function e() { var r = t.call(this, "argument out of range") || this; return r.name = "ArgumentOutOfRangeError", Object.setPrototypeOf(r, e.prototype), r; } return __extends(e, t), e; }(Error), EmptyError = function (t) { function e() { var r = t.call(this, "no elements in sequence") || this; return r.name = "EmptyError", Object.setPrototypeOf(r, e.prototype), r; } return __extends(e, t), e; }(Error), TimeoutError = function (t) { function e() { var r = t.call(this, "Timeout has occurred") || this; return r.name = "TimeoutError", Object.setPrototypeOf(r, e.prototype), r; } return __extends(e, t), e; }(Error);
function map(t, e) { return function (r) { if ("function" != typeof t)
    throw new TypeError("argument is not a function. Are you looking for `mapTo()`?"); return r.lift(new MapOperator(t, e)); }; }
var MapOperator = function () { function t(t, e) { this.project = t, this.thisArg = e; } return t.prototype.call = function (t, e) { return e.subscribe(new MapSubscriber(t, this.project, this.thisArg)); }, t; }(), MapSubscriber = function (t) { function e(e, r, n) { var i = t.call(this, e) || this; return i.project = r, i.count = 0, i.thisArg = n || i, i; } return __extends(e, t), e.prototype._next = function (t) { var e; try {
    e = this.project.call(this.thisArg, t, this.count++);
}
catch (t) {
    return void this.destination.error(t);
} this.destination.next(e); }, e; }(Subscriber), OuterSubscriber = function (t) { function e() { return null !== t && t.apply(this, arguments) || this; } return __extends(e, t), e.prototype.notifyNext = function (t, e, r, n, i) { this.destination.next(e); }, e.prototype.notifyError = function (t, e) { this.destination.error(t); }, e.prototype.notifyComplete = function (t) { this.destination.complete(); }, e; }(Subscriber), InnerSubscriber = function (t) { function e(e, r, n) { var i = t.call(this) || this; return i.parent = e, i.outerValue = r, i.outerIndex = n, i.index = 0, i; } return __extends(e, t), e.prototype._next = function (t) { this.parent.notifyNext(this.outerValue, t, this.outerIndex, this.index++, this); }, e.prototype._error = function (t) { this.parent.notifyError(t, this), this.unsubscribe(); }, e.prototype._complete = function () { this.parent.notifyComplete(this), this.unsubscribe(); }, e; }(Subscriber), subscribeToPromise = function (t) { return function (e) { return t.then(function (t) { e.closed || (e.next(t), e.complete()); }, function (t) { return e.error(t); }).then(null, hostReportError), e; }; };
function getSymbolIterator() { return "function" == typeof Symbol && Symbol.iterator ? Symbol.iterator : "@@iterator"; }
var iterator = getSymbolIterator(), subscribeToIterable = function (t) { return function (e) { for (var r = t[iterator]();;) {
    var n = r.next();
    if (n.done) {
        e.complete();
        break;
    }
    if (e.next(n.value), e.closed)
        break;
} return "function" == typeof r.return && e.add(function () { r.return && r.return(); }), e; }; }, subscribeToObservable = function (t) { return function (e) { var r = t[observable](); if ("function" != typeof r.subscribe)
    throw new TypeError("Provided object does not correctly implement Symbol.observable"); return r.subscribe(e); }; }, isArrayLike = function (t) { return t && "number" == typeof t.length && "function" != typeof t; };
function isPromise(t) { return t && "function" != typeof t.subscribe && "function" == typeof t.then; }
var subscribeTo = function (t) { if (t instanceof Observable)
    return function (e) { return t._isScalar ? (e.next(t.value), void e.complete()) : t.subscribe(e); }; if (t && "function" == typeof t[observable])
    return subscribeToObservable(t); if (isArrayLike(t))
    return subscribeToArray(t); if (isPromise(t))
    return subscribeToPromise(t); if (t && "function" == typeof t[iterator])
    return subscribeToIterable(t); var e = isObject(t) ? "an invalid object" : "'" + t + "'"; throw new TypeError("You provided " + e + " where a stream was expected. You can provide an Observable, Promise, Array, or Iterable."); };
function subscribeToResult(t, e, r, n) { var i = new InnerSubscriber(t, r, n); return subscribeTo(e)(i); }
var NONE = {}, CombineLatestSubscriber = function (t) { function e(e, r) { var n = t.call(this, e) || this; return n.resultSelector = r, n.active = 0, n.values = [], n.observables = [], n; } return __extends(e, t), e.prototype._next = function (t) { this.values.push(NONE), this.observables.push(t); }, e.prototype._complete = function () { var t = this.observables, e = t.length; if (0 === e)
    this.destination.complete();
else {
    this.active = e, this.toRespond = e;
    for (var r = 0; r < e; r++) {
        var n = t[r];
        this.add(subscribeToResult(this, n, n, r));
    }
} }, e.prototype.notifyComplete = function (t) { 0 == (this.active -= 1) && this.destination.complete(); }, e.prototype.notifyNext = function (t, e, r, n, i) { var o = this.values, s = o[r], c = this.toRespond ? s === NONE ? --this.toRespond : this.toRespond : 0; o[r] = e, 0 === c && (this.resultSelector ? this._tryResultSelector(o) : this.destination.next(o.slice())); }, e.prototype._tryResultSelector = function (t) { var e; try {
    e = this.resultSelector.apply(this, t);
}
catch (t) {
    return void this.destination.error(t);
} this.destination.next(e); }, e; }(OuterSubscriber);
function isInteropObservable(t) { return t && "function" == typeof t[observable]; }
function isIterable(t) { return t && "function" == typeof t[iterator]; }
function fromPromise(t, e) { return new Observable(e ? function (r) { var n = new Subscription; return n.add(e.schedule(function () { return t.then(function (t) { n.add(e.schedule(function () { r.next(t), n.add(e.schedule(function () { return r.complete(); })); })); }, function (t) { n.add(e.schedule(function () { return r.error(t); })); }); })), n; } : subscribeToPromise(t)); }
function fromIterable(t, e) { if (!t)
    throw new Error("Iterable cannot be null"); return new Observable(e ? function (r) { var n, i = new Subscription; return i.add(function () { n && "function" == typeof n.return && n.return(); }), i.add(e.schedule(function () { n = t[iterator](), i.add(e.schedule(function () { if (!r.closed) {
    var t, e;
    try {
        var i = n.next();
        t = i.value, e = i.done;
    }
    catch (t) {
        return void r.error(t);
    }
    e ? r.complete() : (r.next(t), this.schedule());
} })); })), i; } : subscribeToIterable(t)); }
function fromObservable(t, e) { return new Observable(e ? function (r) { var n = new Subscription; return n.add(e.schedule(function () { var i = t[observable](); n.add(i.subscribe({ next: function (t) { n.add(e.schedule(function () { return r.next(t); })); }, error: function (t) { n.add(e.schedule(function () { return r.error(t); })); }, complete: function () { n.add(e.schedule(function () { return r.complete(); })); } })); })), n; } : subscribeToObservable(t)); }
function from(t, e) { if (!e)
    return t instanceof Observable ? t : new Observable(subscribeTo(t)); if (null != t) {
    if (isInteropObservable(t))
        return fromObservable(t, e);
    if (isPromise(t))
        return fromPromise(t, e);
    if (isArrayLike(t))
        return fromArray(t, e);
    if (isIterable(t) || "string" == typeof t)
        return fromIterable(t, e);
} throw new TypeError((null !== t && typeof t || t) + " is not observable"); }
function mergeMap(t, e, r) { return void 0 === r && (r = Number.POSITIVE_INFINITY), "function" == typeof e ? function (n) { return n.pipe(mergeMap(function (r, n) { return from(t(r, n)).pipe(map(function (t, i) { return e(r, t, n, i); })); }, r)); } : ("number" == typeof e && (r = e), function (e) { return e.lift(new MergeMapOperator(t, r)); }); }
var MergeMapOperator = function () { function t(t, e) { void 0 === e && (e = Number.POSITIVE_INFINITY), this.project = t, this.concurrent = e; } return t.prototype.call = function (t, e) { return e.subscribe(new MergeMapSubscriber(t, this.project, this.concurrent)); }, t; }(), MergeMapSubscriber = function (t) { function e(e, r, n) { void 0 === n && (n = Number.POSITIVE_INFINITY); var i = t.call(this, e) || this; return i.project = r, i.concurrent = n, i.hasCompleted = !1, i.buffer = [], i.active = 0, i.index = 0, i; } return __extends(e, t), e.prototype._next = function (t) { this.active < this.concurrent ? this._tryNext(t) : this.buffer.push(t); }, e.prototype._tryNext = function (t) { var e, r = this.index++; try {
    e = this.project(t, r);
}
catch (t) {
    return void this.destination.error(t);
} this.active++, this._innerSub(e, t, r); }, e.prototype._innerSub = function (t, e, r) { this.add(subscribeToResult(this, t, e, r)); }, e.prototype._complete = function () { this.hasCompleted = !0, 0 === this.active && 0 === this.buffer.length && this.destination.complete(); }, e.prototype.notifyNext = function (t, e, r, n, i) { this.destination.next(e); }, e.prototype.notifyComplete = function (t) { var e = this.buffer; this.remove(t), this.active--, e.length > 0 ? this._next(e.shift()) : 0 === this.active && this.hasCompleted && this.destination.complete(); }, e; }(OuterSubscriber);
function mergeAll(t) { return void 0 === t && (t = Number.POSITIVE_INFINITY), mergeMap(identity, t); }
function concatAll() { return mergeAll(1); }
function concat() { for (var t = [], e = 0; e < arguments.length; e++)
    t[e] = arguments[e]; return 1 === t.length || 2 === t.length && isScheduler(t[1]) ? from(t[0]) : concatAll()(of.apply(void 0, t)); }
var ForkJoinSubscriber = function (t) { function e(e, r) { var n = t.call(this, e) || this; n.sources = r, n.completed = 0, n.haveValues = 0; var i = r.length; n.values = new Array(i); for (var o = 0; o < i; o++) {
    var s = subscribeToResult(n, r[o], null, o);
    s && n.add(s);
} return n; } return __extends(e, t), e.prototype.notifyNext = function (t, e, r, n, i) { this.values[r] = e, i._hasValue || (i._hasValue = !0, this.haveValues++); }, e.prototype.notifyComplete = function (t) { var e = this.destination, r = this.haveValues, n = this.values, i = n.length; t._hasValue ? (this.completed++, this.completed === i && (r === i && e.next(n), e.complete())) : e.complete(); }, e; }(OuterSubscriber);
function isNumeric(t) { return !isArray(t) && t - parseFloat(t) + 1 >= 0; }
var RaceSubscriber = function (t) { function e(e) { var r = t.call(this, e) || this; return r.hasFirst = !1, r.observables = [], r.subscriptions = [], r; } return __extends(e, t), e.prototype._next = function (t) { this.observables.push(t); }, e.prototype._complete = function () { var t = this.observables, e = t.length; if (0 === e)
    this.destination.complete();
else {
    for (var r = 0; r < e && !this.hasFirst; r++) {
        var n = t[r], i = subscribeToResult(this, n, n, r);
        this.subscriptions && this.subscriptions.push(i), this.add(i);
    }
    this.observables = null;
} }, e.prototype.notifyNext = function (t, e, r, n, i) { if (!this.hasFirst) {
    this.hasFirst = !0;
    for (var o = 0; o < this.subscriptions.length; o++)
        if (o !== r) {
            var s = this.subscriptions[o];
            s.unsubscribe(), this.remove(s);
        }
    this.subscriptions = null;
} this.destination.next(e); }, e; }(OuterSubscriber), ZipSubscriber = function (t) { function e(e, r, n) { void 0 === n && (n = Object.create(null)); var i = t.call(this, e) || this; return i.iterators = [], i.active = 0, i.resultSelector = "function" == typeof r ? r : null, i.values = n, i; } return __extends(e, t), e.prototype._next = function (t) { var e = this.iterators; isArray(t) ? e.push(new StaticArrayIterator(t)) : "function" == typeof t[iterator] ? e.push(new StaticIterator(t[iterator]())) : e.push(new ZipBufferIterator(this.destination, this, t)); }, e.prototype._complete = function () { var t = this.iterators, e = t.length; if (0 !== e) {
    this.active = e;
    for (var r = 0; r < e; r++) {
        var n = t[r];
        n.stillUnsubscribed ? this.add(n.subscribe(n, r)) : this.active--;
    }
}
else
    this.destination.complete(); }, e.prototype.notifyInactive = function () { this.active--, 0 === this.active && this.destination.complete(); }, e.prototype.checkIterators = function () { for (var t = this.iterators, e = t.length, r = this.destination, n = 0; n < e; n++)
    if ("function" == typeof (s = t[n]).hasValue && !s.hasValue())
        return; var i = !1, o = []; for (n = 0; n < e; n++) {
    var s, c = (s = t[n]).next();
    if (s.hasCompleted() && (i = !0), c.done)
        return void r.complete();
    o.push(c.value);
} this.resultSelector ? this._tryresultSelector(o) : r.next(o), i && r.complete(); }, e.prototype._tryresultSelector = function (t) { var e; try {
    e = this.resultSelector.apply(this, t);
}
catch (t) {
    return void this.destination.error(t);
} this.destination.next(e); }, e; }(Subscriber), StaticIterator = function () { function t(t) { this.iterator = t, this.nextResult = t.next(); } return t.prototype.hasValue = function () { return !0; }, t.prototype.next = function () { var t = this.nextResult; return this.nextResult = this.iterator.next(), t; }, t.prototype.hasCompleted = function () { var t = this.nextResult; return t && t.done; }, t; }(), StaticArrayIterator = function () { function t(t) { this.array = t, this.index = 0, this.length = 0, this.length = t.length; } return t.prototype[iterator] = function () { return this; }, t.prototype.next = function (t) { var e = this.index++, r = this.array; return e < this.length ? { value: r[e], done: !1 } : { value: null, done: !0 }; }, t.prototype.hasValue = function () { return this.array.length > this.index; }, t.prototype.hasCompleted = function () { return this.array.length === this.index; }, t; }(), ZipBufferIterator = function (t) { function e(e, r, n) { var i = t.call(this, e) || this; return i.parent = r, i.observable = n, i.stillUnsubscribed = !0, i.buffer = [], i.isComplete = !1, i; } return __extends(e, t), e.prototype[iterator] = function () { return this; }, e.prototype.next = function () { var t = this.buffer; return 0 === t.length && this.isComplete ? { value: null, done: !0 } : { value: t.shift(), done: !1 }; }, e.prototype.hasValue = function () { return this.buffer.length > 0; }, e.prototype.hasCompleted = function () { return 0 === this.buffer.length && this.isComplete; }, e.prototype.notifyComplete = function () { this.buffer.length > 0 ? (this.isComplete = !0, this.parent.notifyInactive()) : this.destination.complete(); }, e.prototype.notifyNext = function (t, e, r, n, i) { this.buffer.push(e), this.parent.checkIterators(); }, e.prototype.subscribe = function (t, e) { return subscribeToResult(this, this.observable, this, e); }, e; }(OuterSubscriber);
var singleton$1 = Symbol(), singletonEnforcer$1 = Symbol();
var HttpService = /** @class */ (function () {
    function HttpService(t) {
        if (this.optionDefaults = { cache: "no-cache", credentials: "same-origin", headers: {}, mode: "same-origin", method: "GET" }, t !== singletonEnforcer$1)
            throw new Error("Cannot construct singleton");
        this._type = "HttpService";
    }
    HttpService.prototype.get = function (t, e) {
        if (e === void 0) { e = this.optionDefaults; }
        return Observable.create(function (r) { fetch(t, e).then(function (t) { return t.json(); }).then(function (t) { r.next(t), r.complete(); }).catch(function (t) { console.error("http.get error:", t), r.error(t); }); });
    };
    HttpService.prototype.put = function (t, e, r) { };
    HttpService.prototype.post = function (t, e, r) { };
    HttpService.prototype.delete = function (t, e, r) { };
    Object.defineProperty(HttpService, "instance", {
        get: function () { return this[singleton$1] || (this[singleton$1] = new HttpService(singletonEnforcer$1)), this[singleton$1]; },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(HttpService.prototype, "type", {
        get: function () { return this._type; },
        set: function (t) { this._type = t; },
        enumerable: true,
        configurable: true
    });
    return HttpService;
}());
var Wordpress = /** @class */ (function () {
    function Wordpress() {
        this.authenticated = !1, this.model = { menus: {}, params: {}, collections: { post: {} } };
    }
    Wordpress.prototype.init = function (t) { var e = this; return "undefined" != typeof window && (window.wp = window.wp || {}), new Promise(function (r, n) { e.initApi(t).then(function () { t.app_server ? e.getParams().then(function () { e.getMenus().then(function () { e.ready = !0, r(); }); }) : r(); }); }); };
    Wordpress.prototype.initApi = function (t) { var e = this; return this.settings = t, this.endpoint = this.settings.protocol + "//" + this.settings.host + "/index.php/wp-json/", new Promise(function (t, r) { "undefined" == typeof window || window.WPAPI || (console.error("ERROR: WPAPI is not defined as global"), r()), location && location.origin === e.settings.protocol + "//" + e.settings.host ? e.discover().then(function () { e.api = new WPAPI({ endpoint: e.endpoint }), e.initCustomRoutes(), t(); }) : (e.api = new WPAPI({ endpoint: e.endpoint }), e.initCustomRoutes(), t()); }); };
    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 t = this; return new Promise(function (e, r) { t.api.posts().then(function (r) { var n = []; r.forEach(function (e) { e.id && (t.model.collections.post[e.id] = e, n.push(e)); }), e(n); }); }); };
    Wordpress.prototype.getParams = function () { var t = this; return new Promise(function (e, r) { t.api.params().then(function (r) { t.model.params = r, e(r); }); }); };
    Wordpress.prototype.getPost = function (t, e) { var r = this; return this.model.collections[e] || (this.model.collections[e] = {}), new Promise(function (n, i) { function o(t, e, i) { r.model.collections[e][t] = i, n(i); } !0 === r.settings.cache && r.model.collections[e][t] ? n(r.model.collections[e][t]) : ("post" === e && r.api.posts().id(t).then(function (r) { return o(t, e, r); }), "page" === e && r.api.pages().id(t).then(function (r) { return o(t, e, r); }), "app" === e && r.api.apps().id(t).then(function (r) { return o(t, e, r); }), "iframe" === e && r.api.iframes().id(t).then(function (r) { return o(t, e, r); })); }); };
    Wordpress.prototype.getMenu = function (t) { var e = this; return new Promise(function (r, n) { e.api.menus().id(t).then(function (n) { e.model.menus[t] = n, r(e.model.menus[t]); }); }); };
    Wordpress.prototype.getMenus = function () { var t = this; return new Promise(function (e, r) { var n = []; var i = 0; t.model.params.menus.length ? (t.model.params.menus.forEach(function (t) { n.push(t.slug); }), n.forEach(function (r) { t.getMenu(r).then(function (o) { t.model.menus[r] = o, ++i === n.length && e(t.model.menus); }); })) : e(t.model.menus); }); };
    Wordpress.prototype.saveLocal = function () { Storage.saveLocalModel(this.model, this.model.params.baseUrl); };
    Wordpress.prototype.restoreLocal = function () { this.model = Storage.restoreLocalModel(this.model.params.baseUrl); };
    Wordpress.prototype.discover = function () { var t = this, e = WPAPI.discover(this.settings.protocol + "//" + this.settings.host); return new Promise(function (r, n) { e.then(function (e) { t.site = e, r(); }); }); };
    return Wordpress;
}());
var Css = /** @class */ (function () {
    function Css() {
    }
    Css.getStyle = function (t, e) {
        if (e === void 0) { e = document.documentElement; }
        return window.getComputedStyle(e).getPropertyValue(t);
    };
    Css.setStyle = function (t, e, r) {
        if (r === void 0) { r = document.documentElement; }
        r.style.setProperty(t, e);
    };
    Css.getVar = function (t, e) {
        if (e === void 0) { e = document.documentElement; }
        return "-" !== t[0] && "-" !== t[1] && (t = "--" + t), Css.getStyle(t, e);
    };
    Css.setVar = function (t, e, r) {
        if (r === void 0) { r = document.documentElement; }
        "-" !== t[0] && "-" !== t[1] && (t = "--" + t), Css.setStyle(t, e, r);
    };
    return Css;
}());
export { __extends as a, tryCatch as b, errorObject as c, OuterSubscriber as d, subscribeToResult as e, async as f, Subscriber as g, isScheduler as h, Subscription as i, isArray as j, from as k, concat as l, mergeMap as m, Notification as n, Observable as o, noop as p, isFunction as q, EmptyError as r, ArgumentOutOfRangeError as s, empty$1 as t, fromArray as u, scalar as v, map as w, identity as x, Subject as y, BehaviorSubject as z, AsyncSubject as A, ReplaySubject as B, refCount as C, asap as D, isNumeric as E, TimeoutError as F, throwError as G, BaseService as H, HttpService as I, Wordpress as J, Css as K };
