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 __extends, b as tryCatch, c as errorObject, d as OuterSubscriber, e as subscribeToResult, g as Subscriber, h as isScheduler, i as Subscription, k as from, l as concat, m as mergeMap, n as Notification, o as Observable, p as noop, q as isFunction, r as EmptyError, t as empty, u as fromArray, v as scalar, w as map, y as Subject, D as asap, E as isNumeric, H as User, I as BaseService } from "./chunk-d3862f1e.js";
import { a as Util, b as global$1 } from "./chunk-4bbd7b7f.js";
var AuditSubscriber = function (t) { function e(e, i) { var r = t.call(this, e) || this; return r.durationSelector = i, r.hasValue = !1, r; } return __extends(e, t), e.prototype._next = function (t) { if (this.value = t, this.hasValue = !0, !this.throttled) {
    var e = tryCatch(this.durationSelector)(t);
    if (e === errorObject)
        this.destination.error(errorObject.e);
    else {
        var i = subscribeToResult(this, e);
        !i || i.closed ? this.clearThrottle() : this.add(this.throttled = i);
    }
} }, e.prototype.clearThrottle = function () { var t = this.value, e = this.hasValue, i = this.throttled; i && (this.remove(i), this.throttled = null, i.unsubscribe()), e && (this.value = null, this.hasValue = !1, this.destination.next(t)); }, e.prototype.notifyNext = function (t, e, i, r) { this.clearThrottle(); }, e.prototype.notifyComplete = function () { this.clearThrottle(); }, e; }(OuterSubscriber), BufferSubscriber = function (t) { function e(e, i) { var r = t.call(this, e) || this; return r.buffer = [], r.add(subscribeToResult(r, i)), r; } return __extends(e, t), e.prototype._next = function (t) { this.buffer.push(t); }, e.prototype.notifyNext = function (t, e, i, r, s) { var n = this.buffer; this.buffer = [], this.destination.next(n); }, e; }(OuterSubscriber), BufferCountSubscriber = function (t) { function e(e, i) { var r = t.call(this, e) || this; return r.bufferSize = i, r.buffer = [], r; } return __extends(e, t), e.prototype._next = function (t) { var e = this.buffer; e.push(t), e.length == this.bufferSize && (this.destination.next(e), this.buffer = []); }, e.prototype._complete = function () { var e = this.buffer; e.length > 0 && this.destination.next(e), t.prototype._complete.call(this); }, e; }(Subscriber), BufferSkipCountSubscriber = function (t) { function e(e, i, r) { var s = t.call(this, e) || this; return s.bufferSize = i, s.startBufferEvery = r, s.buffers = [], s.count = 0, s; } return __extends(e, t), e.prototype._next = function (t) { var e = this.bufferSize, i = this.startBufferEvery, r = this.buffers, s = this.count; this.count++, s % i == 0 && r.push([]); for (var n = r.length; n--;) {
    var o = r[n];
    o.push(t), o.length === e && (r.splice(n, 1), this.destination.next(o));
} }, e.prototype._complete = function () { for (var e = this.buffers, i = this.destination; e.length > 0;) {
    var r = e.shift();
    r.length > 0 && i.next(r);
} t.prototype._complete.call(this); }, e; }(Subscriber), Context = function () { this.buffer = []; }, BufferTimeSubscriber = function (t) { function e(e, i, r, s, n) { var o = t.call(this, e) || this; o.bufferTimeSpan = i, o.bufferCreationInterval = r, o.maxBufferSize = s, o.scheduler = n, o.contexts = []; var c = o.openContext(); if (o.timespanOnly = null == r || r < 0, o.timespanOnly) {
    var u = { subscriber: o, context: c, bufferTimeSpan: i };
    o.add(c.closeAction = n.schedule(dispatchBufferTimeSpanOnly, i, u));
}
else {
    var a = { subscriber: o, context: c }, h = { bufferTimeSpan: i, bufferCreationInterval: r, subscriber: o, scheduler: n };
    o.add(c.closeAction = n.schedule(dispatchBufferClose, i, a)), o.add(n.schedule(dispatchBufferCreation, r, h));
} return o; } return __extends(e, t), e.prototype._next = function (t) { for (var e, i = this.contexts, r = i.length, s = 0; s < r; s++) {
    var n = i[s], o = n.buffer;
    o.push(t), o.length == this.maxBufferSize && (e = n);
} e && this.onBufferFull(e); }, e.prototype._error = function (e) { this.contexts.length = 0, t.prototype._error.call(this, e); }, e.prototype._complete = function () { for (var e = this.contexts, i = this.destination; e.length > 0;) {
    var r = e.shift();
    i.next(r.buffer);
} t.prototype._complete.call(this); }, e.prototype._unsubscribe = function () { this.contexts = null; }, e.prototype.onBufferFull = function (t) { this.closeContext(t); var e = t.closeAction; if (e.unsubscribe(), this.remove(e), !this.closed && this.timespanOnly) {
    t = this.openContext();
    var i = this.bufferTimeSpan, r = { subscriber: this, context: t, bufferTimeSpan: i };
    this.add(t.closeAction = this.scheduler.schedule(dispatchBufferTimeSpanOnly, i, r));
} }, e.prototype.openContext = function () { var t = new Context; return this.contexts.push(t), t; }, e.prototype.closeContext = function (t) { this.destination.next(t.buffer); var e = this.contexts; (e ? e.indexOf(t) : -1) >= 0 && e.splice(e.indexOf(t), 1); }, e; }(Subscriber);
function dispatchBufferTimeSpanOnly(t) { var e = t.subscriber, i = t.context; i && e.closeContext(i), e.closed || (t.context = e.openContext(), t.context.closeAction = this.schedule(t, t.bufferTimeSpan)); }
function dispatchBufferCreation(t) { var e = t.bufferCreationInterval, i = t.bufferTimeSpan, r = t.subscriber, s = t.scheduler, n = r.openContext(); r.closed || (r.add(n.closeAction = s.schedule(dispatchBufferClose, i, { subscriber: r, context: n })), this.schedule(t, e)); }
function dispatchBufferClose(t) { var e = t.subscriber, i = t.context; e.closeContext(i); }
var BufferToggleSubscriber = function (t) { function e(e, i, r) { var s = t.call(this, e) || this; return s.openings = i, s.closingSelector = r, s.contexts = [], s.add(subscribeToResult(s, i)), s; } return __extends(e, t), e.prototype._next = function (t) { for (var e = this.contexts, i = e.length, r = 0; r < i; r++)
    e[r].buffer.push(t); }, e.prototype._error = function (e) { for (var i = this.contexts; i.length > 0;) {
    var r = i.shift();
    r.subscription.unsubscribe(), r.buffer = null, r.subscription = null;
} this.contexts = null, t.prototype._error.call(this, e); }, e.prototype._complete = function () { for (var e = this.contexts; e.length > 0;) {
    var i = e.shift();
    this.destination.next(i.buffer), i.subscription.unsubscribe(), i.buffer = null, i.subscription = null;
} this.contexts = null, t.prototype._complete.call(this); }, e.prototype.notifyNext = function (t, e, i, r, s) { t ? this.closeBuffer(t) : this.openBuffer(e); }, e.prototype.notifyComplete = function (t) { this.closeBuffer(t.context); }, e.prototype.openBuffer = function (t) { try {
    var e = this.closingSelector.call(this, t);
    e && this.trySubscribe(e);
}
catch (t) {
    this._error(t);
} }, e.prototype.closeBuffer = function (t) { var e = this.contexts; if (e && t) {
    var i = t.buffer, r = t.subscription;
    this.destination.next(i), e.splice(e.indexOf(t), 1), this.remove(r), r.unsubscribe();
} }, e.prototype.trySubscribe = function (t) { var e = this.contexts, i = new Subscription, r = { buffer: [], subscription: i }; e.push(r); var s = subscribeToResult(this, t, r); !s || s.closed ? this.closeBuffer(r) : (s.context = r, this.add(s), i.add(s)); }, e; }(OuterSubscriber), BufferWhenSubscriber = function (t) { function e(e, i) { var r = t.call(this, e) || this; return r.closingSelector = i, r.subscribing = !1, r.openBuffer(), r; } return __extends(e, t), e.prototype._next = function (t) { this.buffer.push(t); }, e.prototype._complete = function () { var e = this.buffer; e && this.destination.next(e), t.prototype._complete.call(this); }, e.prototype._unsubscribe = function () { this.buffer = null, this.subscribing = !1; }, e.prototype.notifyNext = function (t, e, i, r, s) { this.openBuffer(); }, e.prototype.notifyComplete = function () { this.subscribing ? this.complete() : this.openBuffer(); }, e.prototype.openBuffer = function () { var t = this.closingSubscription; t && (this.remove(t), t.unsubscribe()); var e = this.buffer; this.buffer && this.destination.next(e), this.buffer = []; var i = tryCatch(this.closingSelector)(); i === errorObject ? this.error(errorObject.e) : (t = new Subscription, this.closingSubscription = t, this.add(t), this.subscribing = !0, t.add(subscribeToResult(this, i)), this.subscribing = !1); }, e; }(OuterSubscriber), CatchSubscriber = function (t) { function e(e, i, r) { var s = t.call(this, e) || this; return s.selector = i, s.caught = r, s; } return __extends(e, t), e.prototype.error = function (e) { if (!this.isStopped) {
    var i = void 0;
    try {
        i = this.selector(e, this.caught);
    }
    catch (e) {
        return void t.prototype.error.call(this, e);
    }
    this._unsubscribeAndRecycle(), this.add(subscribeToResult(this, i));
} }, e; }(OuterSubscriber), CountSubscriber = function (t) { function e(e, i, r) { var s = t.call(this, e) || this; return s.predicate = i, s.source = r, s.count = 0, s.index = 0, s; } return __extends(e, t), e.prototype._next = function (t) { this.predicate ? this._tryPredicate(t) : this.count++; }, e.prototype._tryPredicate = function (t) { var e; try {
    e = this.predicate(t, this.index++, this.source);
}
catch (t) {
    return void this.destination.error(t);
} e && this.count++; }, e.prototype._complete = function () { this.destination.next(this.count), this.destination.complete(); }, e; }(Subscriber), DebounceSubscriber = function (t) { function e(e, i) { var r = t.call(this, e) || this; return r.durationSelector = i, r.hasValue = !1, r.durationSubscription = null, r; } return __extends(e, t), e.prototype._next = function (t) { try {
    var e = this.durationSelector.call(this, t);
    e && this._tryNext(t, e);
}
catch (t) {
    this.destination.error(t);
} }, e.prototype._complete = function () { this.emitValue(), this.destination.complete(); }, e.prototype._tryNext = function (t, e) { var i = this.durationSubscription; this.value = t, this.hasValue = !0, i && (i.unsubscribe(), this.remove(i)), (i = subscribeToResult(this, e)) && !i.closed && this.add(this.durationSubscription = i); }, e.prototype.notifyNext = function (t, e, i, r, s) { this.emitValue(); }, e.prototype.notifyComplete = function () { this.emitValue(); }, e.prototype.emitValue = function () { if (this.hasValue) {
    var e = this.value, i = this.durationSubscription;
    i && (this.durationSubscription = null, i.unsubscribe(), this.remove(i)), this.value = null, this.hasValue = !1, t.prototype._next.call(this, e);
} }, e; }(OuterSubscriber), DebounceTimeSubscriber = function (t) { function e(e, i, r) { var s = t.call(this, e) || this; return s.dueTime = i, s.scheduler = r, s.debouncedSubscription = null, s.lastValue = null, s.hasValue = !1, s; } return __extends(e, t), e.prototype._next = function (t) { this.clearDebounce(), this.lastValue = t, this.hasValue = !0, this.add(this.debouncedSubscription = this.scheduler.schedule(dispatchNext, this.dueTime, this)); }, e.prototype._complete = function () { this.debouncedNext(), this.destination.complete(); }, e.prototype.debouncedNext = function () { if (this.clearDebounce(), this.hasValue) {
    var t = this.lastValue;
    this.lastValue = null, this.hasValue = !1, this.destination.next(t);
} }, e.prototype.clearDebounce = function () { var t = this.debouncedSubscription; null !== t && (this.remove(t), t.unsubscribe(), this.debouncedSubscription = null); }, e; }(Subscriber);
function dispatchNext(t) { t.debouncedNext(); }
var DefaultIfEmptySubscriber = function (t) { function e(e, i) { var r = t.call(this, e) || this; return r.defaultValue = i, r.isEmpty = !0, r; } return __extends(e, t), e.prototype._next = function (t) { this.isEmpty = !1, this.destination.next(t); }, e.prototype._complete = function () { this.isEmpty && this.destination.next(this.defaultValue), this.destination.complete(); }, e; }(Subscriber), DelaySubscriber = function (t) { function e(e, i, r) { var s = t.call(this, e) || this; return s.delay = i, s.scheduler = r, s.queue = [], s.active = !1, s.errored = !1, s; } return __extends(e, t), e.dispatch = function (t) { for (var e = t.source, i = e.queue, r = t.scheduler, s = t.destination; i.length > 0 && i[0].time - r.now() <= 0;)
    i.shift().notification.observe(s); if (i.length > 0) {
    var n = Math.max(0, i[0].time - r.now());
    this.schedule(t, n);
}
else
    this.unsubscribe(), e.active = !1; }, e.prototype._schedule = function (t) { this.active = !0, this.add(t.schedule(e.dispatch, this.delay, { source: this, destination: this.destination, scheduler: t })); }, e.prototype.scheduleNotification = function (t) { if (!0 !== this.errored) {
    var e = this.scheduler, i = new DelayMessage(e.now() + this.delay, t);
    this.queue.push(i), !1 === this.active && this._schedule(e);
} }, e.prototype._next = function (t) { this.scheduleNotification(Notification.createNext(t)); }, e.prototype._error = function (t) { this.errored = !0, this.queue = [], this.destination.error(t); }, e.prototype._complete = function () { this.scheduleNotification(Notification.createComplete()); }, e; }(Subscriber), DelayMessage = function (t, e) { this.time = t, this.notification = e; }, DelayWhenSubscriber = function (t) { function e(e, i) { var r = t.call(this, e) || this; return r.delayDurationSelector = i, r.completed = !1, r.delayNotifierSubscriptions = [], r; } return __extends(e, t), e.prototype.notifyNext = function (t, e, i, r, s) { this.destination.next(t), this.removeSubscription(s), this.tryComplete(); }, e.prototype.notifyError = function (t, e) { this._error(t); }, e.prototype.notifyComplete = function (t) { var e = this.removeSubscription(t); e && this.destination.next(e), this.tryComplete(); }, e.prototype._next = function (t) { try {
    var e = this.delayDurationSelector(t);
    e && this.tryDelay(e, t);
}
catch (t) {
    this.destination.error(t);
} }, e.prototype._complete = function () { this.completed = !0, this.tryComplete(); }, e.prototype.removeSubscription = function (t) { t.unsubscribe(); var e = this.delayNotifierSubscriptions.indexOf(t); return -1 !== e && this.delayNotifierSubscriptions.splice(e, 1), t.outerValue; }, e.prototype.tryDelay = function (t, e) { var i = subscribeToResult(this, t, e); i && !i.closed && (this.add(i), this.delayNotifierSubscriptions.push(i)); }, e.prototype.tryComplete = function () { this.completed && 0 === this.delayNotifierSubscriptions.length && this.destination.complete(); }, e; }(OuterSubscriber), SubscriptionDelayObservable = function (t) { function e(e, i) { var r = t.call(this) || this; return r.source = e, r.subscriptionDelay = i, r; } return __extends(e, t), e.prototype._subscribe = function (t) { this.subscriptionDelay.subscribe(new SubscriptionDelaySubscriber(t, this.source)); }, e; }(Observable), SubscriptionDelaySubscriber = function (t) { function e(e, i) { var r = t.call(this) || this; return r.parent = e, r.source = i, r.sourceSubscribed = !1, r; } return __extends(e, t), e.prototype._next = function (t) { this.subscribeToSource(); }, e.prototype._error = function (t) { this.unsubscribe(), this.parent.error(t); }, e.prototype._complete = function () { this.subscribeToSource(); }, e.prototype.subscribeToSource = function () { this.sourceSubscribed || (this.sourceSubscribed = !0, this.unsubscribe(), this.source.subscribe(this.parent)); }, e; }(Subscriber), DeMaterializeSubscriber = function (t) { function e(e) { return t.call(this, e) || this; } return __extends(e, t), e.prototype._next = function (t) { t.observe(this.destination); }, e; }(Subscriber), DistinctSubscriber = function (t) { function e(e, i, r) { var s = t.call(this, e) || this; return s.keySelector = i, s.values = new Set, r && s.add(subscribeToResult(s, r)), s; } return __extends(e, t), e.prototype.notifyNext = function (t, e, i, r, s) { this.values.clear(); }, e.prototype.notifyError = function (t, e) { this._error(t); }, e.prototype._next = function (t) { this.keySelector ? this._useKeySelector(t) : this._finalizeNext(t, t); }, e.prototype._useKeySelector = function (t) { var e, i = this.destination; try {
    e = this.keySelector(t);
}
catch (t) {
    return void i.error(t);
} this._finalizeNext(e, t); }, e.prototype._finalizeNext = function (t, e) { var i = this.values; i.has(t) || (i.add(t), this.destination.next(e)); }, e; }(OuterSubscriber), DistinctUntilChangedSubscriber = function (t) { function e(e, i, r) { var s = t.call(this, e) || this; return s.keySelector = r, s.hasKey = !1, "function" == typeof i && (s.compare = i), s; } return __extends(e, t), e.prototype.compare = function (t, e) { return t === e; }, e.prototype._next = function (t) { var e = t; if (this.keySelector && (e = tryCatch(this.keySelector)(t)) === errorObject)
    return this.destination.error(errorObject.e); var i = !1; if (this.hasKey) {
    if ((i = tryCatch(this.compare)(this.key, e)) === errorObject)
        return this.destination.error(errorObject.e);
}
else
    this.hasKey = !0; !1 === Boolean(i) && (this.key = e, this.destination.next(t)); }, e; }(Subscriber), FilterSubscriber = function (t) { function e(e, i, r) { var s = t.call(this, e) || this; return s.predicate = i, s.thisArg = r, s.count = 0, s; } return __extends(e, t), e.prototype._next = function (t) { var e; try {
    e = this.predicate.call(this.thisArg, t, this.count++);
}
catch (t) {
    return void this.destination.error(t);
} e && this.destination.next(t); }, e; }(Subscriber);
function tap(t, e, i) { return function (r) { return r.lift(new DoOperator(t, e, i)); }; }
var DoOperator = function () { function t(t, e, i) { this.nextOrObserver = t, this.error = e, this.complete = i; } return t.prototype.call = function (t, e) { return e.subscribe(new TapSubscriber(t, this.nextOrObserver, this.error, this.complete)); }, t; }(), TapSubscriber = function (t) { function e(e, i, r, s) { var n = t.call(this, e) || this; return n._tapNext = noop, n._tapError = noop, n._tapComplete = noop, n._tapError = r || noop, n._tapComplete = s || noop, isFunction(i) ? (n._context = n, n._tapNext = i) : i && (n._context = i, n._tapNext = i.next || noop, n._tapError = i.error || noop, n._tapComplete = i.complete || noop), n; } return __extends(e, t), e.prototype._next = function (t) { try {
    this._tapNext.call(this._context, t);
}
catch (t) {
    return void this.destination.error(t);
} this.destination.next(t); }, e.prototype._error = function (t) { try {
    this._tapError.call(this._context, t);
}
catch (t) {
    return void this.destination.error(t);
} this.destination.error(t); }, e.prototype._complete = function () { try {
    this._tapComplete.call(this._context);
}
catch (t) {
    return void this.destination.error(t);
} return this.destination.complete(); }, e; }(Subscriber), TakeSubscriber = function (t) { function e(e, i) { var r = t.call(this, e) || this; return r.total = i, r.count = 0, r; } return __extends(e, t), e.prototype._next = function (t) { var e = this.total, i = ++this.count; i <= e && (this.destination.next(t), i === e && (this.destination.complete(), this.unsubscribe())); }, e; }(Subscriber), EverySubscriber = function (t) { function e(e, i, r, s) { var n = t.call(this, e) || this; return n.predicate = i, n.thisArg = r, n.source = s, n.index = 0, n.thisArg = r || n, n; } return __extends(e, t), e.prototype.notifyComplete = function (t) { this.destination.next(t), this.destination.complete(); }, e.prototype._next = function (t) { var e = !1; try {
    e = this.predicate.call(this.thisArg, t, this.index++, this.source);
}
catch (t) {
    return void this.destination.error(t);
} e || this.notifyComplete(!1); }, e.prototype._complete = function () { this.notifyComplete(!0); }, e; }(Subscriber), SwitchFirstSubscriber = function (t) { function e(e) { var i = t.call(this, e) || this; return i.hasCompleted = !1, i.hasSubscription = !1, i; } return __extends(e, t), e.prototype._next = function (t) { this.hasSubscription || (this.hasSubscription = !0, this.add(subscribeToResult(this, t))); }, e.prototype._complete = function () { this.hasCompleted = !0, this.hasSubscription || this.destination.complete(); }, e.prototype.notifyComplete = function (t) { this.remove(t), this.hasSubscription = !1, this.hasCompleted && this.destination.complete(); }, e; }(OuterSubscriber), ExhaustMapSubscriber = function (t) { function e(e, i) { var r = t.call(this, e) || this; return r.project = i, r.hasSubscription = !1, r.hasCompleted = !1, r.index = 0, r; } return __extends(e, t), e.prototype._next = function (t) { this.hasSubscription || this.tryNext(t); }, e.prototype.tryNext = function (t) { var e = this.index++, i = this.destination; try {
    var r = this.project(t, e);
    this.hasSubscription = !0, this.add(subscribeToResult(this, r, t, e));
}
catch (t) {
    i.error(t);
} }, e.prototype._complete = function () { this.hasCompleted = !0, this.hasSubscription || this.destination.complete(); }, e.prototype.notifyNext = function (t, e, i, r, s) { this.destination.next(e); }, e.prototype.notifyError = function (t) { this.destination.error(t); }, e.prototype.notifyComplete = function (t) { this.remove(t), this.hasSubscription = !1, this.hasCompleted && this.destination.complete(); }, e; }(OuterSubscriber), ExpandSubscriber = function (t) { function e(e, i, r, s) { var n = t.call(this, e) || this; return n.project = i, n.concurrent = r, n.scheduler = s, n.index = 0, n.active = 0, n.hasCompleted = !1, r < Number.POSITIVE_INFINITY && (n.buffer = []), n; } return __extends(e, t), e.dispatch = function (t) { var e = t.subscriber, i = t.result, r = t.value, s = t.index; e.subscribeToProjection(i, r, s); }, e.prototype._next = function (t) { var i = this.destination; if (i.closed)
    this._complete();
else {
    var r = this.index++;
    if (this.active < this.concurrent) {
        i.next(t);
        var s = tryCatch(this.project)(t, r);
        if (s === errorObject)
            i.error(errorObject.e);
        else if (this.scheduler) {
            var n = { subscriber: this, result: s, value: t, index: r };
            this.add(this.scheduler.schedule(e.dispatch, 0, n));
        }
        else
            this.subscribeToProjection(s, t, r);
    }
    else
        this.buffer.push(t);
} }, e.prototype.subscribeToProjection = function (t, e, i) { this.active++, this.add(subscribeToResult(this, t, e, i)); }, e.prototype._complete = function () { this.hasCompleted = !0, this.hasCompleted && 0 === this.active && this.destination.complete(); }, e.prototype.notifyNext = function (t, e, i, r, s) { this._next(e); }, e.prototype.notifyComplete = function (t) { var e = this.buffer; this.remove(t), this.active--, e && e.length > 0 && this._next(e.shift()), this.hasCompleted && 0 === this.active && this.destination.complete(); }, e; }(OuterSubscriber), FinallySubscriber = function (t) { function e(e, i) { var r = t.call(this, e) || this; return r.add(new Subscription(i)), r; } return __extends(e, t), e; }(Subscriber), FindValueSubscriber = function (t) { function e(e, i, r, s, n) { var o = t.call(this, e) || this; return o.predicate = i, o.source = r, o.yieldIndex = s, o.thisArg = n, o.index = 0, o; } return __extends(e, t), e.prototype.notifyComplete = function (t) { var e = this.destination; e.next(t), e.complete(); }, e.prototype._next = function (t) { var e = this.predicate, i = this.thisArg, r = this.index++; try {
    e.call(i || this, t, r, this.source) && this.notifyComplete(this.yieldIndex ? r : t);
}
catch (t) {
    this.destination.error(t);
} }, e.prototype._complete = function () { this.notifyComplete(this.yieldIndex ? -1 : void 0); }, e; }(Subscriber), IgnoreElementsSubscriber = function (t) { function e() { return null !== t && t.apply(this, arguments) || this; } return __extends(e, t), e.prototype._next = function (t) { }, e; }(Subscriber), IsEmptySubscriber = function (t) { function e(e) { return t.call(this, e) || this; } return __extends(e, t), e.prototype.notifyComplete = function (t) { var e = this.destination; e.next(t), e.complete(); }, e.prototype._next = function (t) { this.notifyComplete(!1); }, e.prototype._complete = function () { this.notifyComplete(!0); }, e; }(Subscriber), TakeLastSubscriber = function (t) { function e(e, i) { var r = t.call(this, e) || this; return r.total = i, r.ring = new Array, r.count = 0, r; } return __extends(e, t), e.prototype._next = function (t) { var e = this.ring, i = this.total, r = this.count++; e.length < i ? e.push(t) : e[r % i] = t; }, e.prototype._complete = function () { var t = this.destination, e = this.count; if (e > 0)
    for (var i = this.count >= this.total ? this.total : this.count, r = this.ring, s = 0; s < i; s++) {
        var n = e++ % i;
        t.next(r[n]);
    } t.complete(); }, e; }(Subscriber), MapToSubscriber = function (t) { function e(e, i) { var r = t.call(this, e) || this; return r.value = i, r; } return __extends(e, t), e.prototype._next = function (t) { this.destination.next(this.value); }, e; }(Subscriber), MaterializeSubscriber = function (t) { function e(e) { return t.call(this, e) || this; } return __extends(e, t), e.prototype._next = function (t) { this.destination.next(Notification.createNext(t)); }, e.prototype._error = function (t) { var e = this.destination; e.next(Notification.createError(t)), e.complete(); }, e.prototype._complete = function () { var t = this.destination; t.next(Notification.createComplete()), t.complete(); }, e; }(Subscriber);
function scan(t, e) { var i = !1; return arguments.length >= 2 && (i = !0), function (r) { return r.lift(new ScanOperator(t, e, i)); }; }
var ScanOperator = function () { function t(t, e, i) { void 0 === i && (i = !1), this.accumulator = t, this.seed = e, this.hasSeed = i; } return t.prototype.call = function (t, e) { return e.subscribe(new ScanSubscriber(t, this.accumulator, this.seed, this.hasSeed)); }, t; }(), ScanSubscriber = function (t) { function e(e, i, r, s) { var n = t.call(this, e) || this; return n.accumulator = i, n._seed = r, n.hasSeed = s, n.index = 0, n; } return __extends(e, t), Object.defineProperty(e.prototype, "seed", { get: function () { return this._seed; }, set: function (t) { this.hasSeed = !0, this._seed = t; }, enumerable: !0, configurable: !0 }), e.prototype._next = function (t) { if (this.hasSeed)
    return this._tryNext(t); this.seed = t, this.destination.next(t); }, e.prototype._tryNext = function (t) { var e, i = this.index++; try {
    e = this.accumulator(this.seed, t, i);
}
catch (t) {
    this.destination.error(t);
} this.seed = e, this.destination.next(e); }, e; }(Subscriber), MergeScanSubscriber = function (t) { function e(e, i, r, s) { var n = t.call(this, e) || this; return n.accumulator = i, n.acc = r, n.concurrent = s, n.hasValue = !1, n.hasCompleted = !1, n.buffer = [], n.active = 0, n.index = 0, n; } return __extends(e, t), e.prototype._next = function (t) { if (this.active < this.concurrent) {
    var e = this.index++, i = tryCatch(this.accumulator)(this.acc, t), r = this.destination;
    i === errorObject ? r.error(errorObject.e) : (this.active++, this._innerSub(i, t, e));
}
else
    this.buffer.push(t); }, e.prototype._innerSub = function (t, e, i) { this.add(subscribeToResult(this, t, e, i)); }, e.prototype._complete = function () { this.hasCompleted = !0, 0 === this.active && 0 === this.buffer.length && (!1 === this.hasValue && this.destination.next(this.acc), this.destination.complete()); }, e.prototype.notifyNext = function (t, e, i, r, s) { var n = this.destination; this.acc = e, this.hasValue = !0, n.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 && (!1 === this.hasValue && this.destination.next(this.acc), this.destination.complete()); }, e; }(OuterSubscriber), OnErrorResumeNextSubscriber = function (t) { function e(e, i) { var r = t.call(this, e) || this; return r.destination = e, r.nextSources = i, r; } return __extends(e, t), e.prototype.notifyError = function (t, e) { this.subscribeToNextSource(); }, e.prototype.notifyComplete = function (t) { this.subscribeToNextSource(); }, e.prototype._error = function (t) { this.subscribeToNextSource(); }, e.prototype._complete = function () { this.subscribeToNextSource(); }, e.prototype.subscribeToNextSource = function () { var t = this.nextSources.shift(); t ? this.add(subscribeToResult(this, t)) : this.destination.complete(); }, e; }(OuterSubscriber), PairwiseSubscriber = function (t) { function e(e) { var i = t.call(this, e) || this; return i.hasPrev = !1, i; } return __extends(e, t), e.prototype._next = function (t) { this.hasPrev ? this.destination.next([this.prev, t]) : this.hasPrev = !0, this.prev = t; }, e; }(Subscriber), RepeatSubscriber = function (t) { function e(e, i, r) { var s = t.call(this, e) || this; return s.count = i, s.source = r, s; } return __extends(e, t), e.prototype.complete = function () { if (!this.isStopped) {
    var e = this.source, i = this.count;
    if (0 === i)
        return t.prototype.complete.call(this);
    i > -1 && (this.count = i - 1), e.subscribe(this._unsubscribeAndRecycle());
} }, e; }(Subscriber), RepeatWhenSubscriber = function (t) { function e(e, i, r) { var s = t.call(this, e) || this; return s.notifier = i, s.source = r, s.sourceIsBeingSubscribedTo = !0, s; } return __extends(e, t), e.prototype.notifyNext = function (t, e, i, r, s) { this.sourceIsBeingSubscribedTo = !0, this.source.subscribe(this); }, e.prototype.notifyComplete = function (e) { if (!1 === this.sourceIsBeingSubscribedTo)
    return t.prototype.complete.call(this); }, e.prototype.complete = function () { if (this.sourceIsBeingSubscribedTo = !1, !this.isStopped) {
    if (this.retries || this.subscribeToRetries(), !this.retriesSubscription || this.retriesSubscription.closed)
        return t.prototype.complete.call(this);
    this._unsubscribeAndRecycle(), this.notifications.next();
} }, e.prototype._unsubscribe = function () { var t = this.notifications, e = this.retriesSubscription; t && (t.unsubscribe(), this.notifications = null), e && (e.unsubscribe(), this.retriesSubscription = null), this.retries = null; }, e.prototype._unsubscribeAndRecycle = function () { var e = this._unsubscribe; return this._unsubscribe = null, t.prototype._unsubscribeAndRecycle.call(this), this._unsubscribe = e, this; }, e.prototype.subscribeToRetries = function () { this.notifications = new Subject; var e = tryCatch(this.notifier)(this.notifications); if (e === errorObject)
    return t.prototype.complete.call(this); this.retries = e, this.retriesSubscription = subscribeToResult(this, e); }, e; }(OuterSubscriber), RetrySubscriber = function (t) { function e(e, i, r) { var s = t.call(this, e) || this; return s.count = i, s.source = r, s; } return __extends(e, t), e.prototype.error = function (e) { if (!this.isStopped) {
    var i = this.source, r = this.count;
    if (0 === r)
        return t.prototype.error.call(this, e);
    r > -1 && (this.count = r - 1), i.subscribe(this._unsubscribeAndRecycle());
} }, e; }(Subscriber), RetryWhenSubscriber = function (t) { function e(e, i, r) { var s = t.call(this, e) || this; return s.notifier = i, s.source = r, s; } return __extends(e, t), e.prototype.error = function (e) { if (!this.isStopped) {
    var i = this.errors, r = this.retries, s = this.retriesSubscription;
    if (r)
        this.errors = null, this.retriesSubscription = null;
    else {
        if (i = new Subject, (r = tryCatch(this.notifier)(i)) === errorObject)
            return t.prototype.error.call(this, errorObject.e);
        s = subscribeToResult(this, r);
    }
    this._unsubscribeAndRecycle(), this.errors = i, this.retries = r, this.retriesSubscription = s, i.next(e);
} }, e.prototype._unsubscribe = function () { var t = this.errors, e = this.retriesSubscription; t && (t.unsubscribe(), this.errors = null), e && (e.unsubscribe(), this.retriesSubscription = null), this.retries = null; }, e.prototype.notifyNext = function (t, e, i, r, s) { var n = this._unsubscribe; this._unsubscribe = null, this._unsubscribeAndRecycle(), this._unsubscribe = n, this.source.subscribe(this); }, e; }(OuterSubscriber), SampleSubscriber = function (t) { function e() { var e = null !== t && t.apply(this, arguments) || this; return e.hasValue = !1, e; } return __extends(e, t), e.prototype._next = function (t) { this.value = t, this.hasValue = !0; }, e.prototype.notifyNext = function (t, e, i, r, s) { this.emitValue(); }, e.prototype.notifyComplete = function () { this.emitValue(); }, e.prototype.emitValue = function () { this.hasValue && (this.hasValue = !1, this.destination.next(this.value)); }, e; }(OuterSubscriber), SampleTimeSubscriber = function (t) { function e(e, i, r) { var s = t.call(this, e) || this; return s.period = i, s.scheduler = r, s.hasValue = !1, s.add(r.schedule(dispatchNotification, i, { subscriber: s, period: i })), s; } return __extends(e, t), e.prototype._next = function (t) { this.lastValue = t, this.hasValue = !0; }, e.prototype.notifyNext = function () { this.hasValue && (this.hasValue = !1, this.destination.next(this.lastValue)); }, e; }(Subscriber);
function dispatchNotification(t) { var e = t.subscriber, i = t.period; e.notifyNext(), this.schedule(t, i); }
var SequenceEqualSubscriber = function (t) { function e(e, i, r) { var s = t.call(this, e) || this; return s.compareTo = i, s.comparor = r, s._a = [], s._b = [], s._oneComplete = !1, s.add(i.subscribe(new SequenceEqualCompareToSubscriber(e, s))), s; } return __extends(e, t), e.prototype._next = function (t) { this._oneComplete && 0 === this._b.length ? this.emit(!1) : (this._a.push(t), this.checkValues()); }, e.prototype._complete = function () { this._oneComplete ? this.emit(0 === this._a.length && 0 === this._b.length) : this._oneComplete = !0; }, e.prototype.checkValues = function () { for (var t = this._a, e = this._b, i = this.comparor; t.length > 0 && e.length > 0;) {
    var r = t.shift(), s = e.shift(), n = !1;
    i ? (n = tryCatch(i)(r, s)) === errorObject && this.destination.error(errorObject.e) : n = r === s, n || this.emit(!1);
} }, e.prototype.emit = function (t) { var e = this.destination; e.next(t), e.complete(); }, e.prototype.nextB = function (t) { this._oneComplete && 0 === this._a.length ? this.emit(!1) : (this._b.push(t), this.checkValues()); }, e; }(Subscriber), SequenceEqualCompareToSubscriber = function (t) { function e(e, i) { var r = t.call(this, e) || this; return r.parent = i, r; } return __extends(e, t), e.prototype._next = function (t) { this.parent.nextB(t); }, e.prototype._error = function (t) { this.parent.error(t); }, e.prototype._complete = function () { this.parent._complete(); }, e; }(Subscriber), SingleSubscriber = function (t) { function e(e, i, r) { var s = t.call(this, e) || this; return s.predicate = i, s.source = r, s.seenValue = !1, s.index = 0, s; } return __extends(e, t), e.prototype.applySingleValue = function (t) { this.seenValue ? this.destination.error("Sequence contains more than one element") : (this.seenValue = !0, this.singleValue = t); }, e.prototype._next = function (t) { var e = this.index++; this.predicate ? this.tryNext(t, e) : this.applySingleValue(t); }, e.prototype.tryNext = function (t, e) { try {
    this.predicate(t, e, this.source) && this.applySingleValue(t);
}
catch (t) {
    this.destination.error(t);
} }, e.prototype._complete = function () { var t = this.destination; this.index > 0 ? (t.next(this.seenValue ? this.singleValue : void 0), t.complete()) : t.error(new EmptyError); }, e; }(Subscriber), SkipSubscriber = function (t) { function e(e, i) { var r = t.call(this, e) || this; return r.total = i, r.count = 0, r; } return __extends(e, t), e.prototype._next = function (t) { ++this.count > this.total && this.destination.next(t); }, e; }(Subscriber), SkipLastSubscriber = function (t) { function e(e, i) { var r = t.call(this, e) || this; return r._skipCount = i, r._count = 0, r._ring = new Array(i), r; } return __extends(e, t), e.prototype._next = function (t) { var e = this._skipCount, i = this._count++; if (i < e)
    this._ring[i] = t;
else {
    var r = i % e, s = this._ring, n = s[r];
    s[r] = t, this.destination.next(n);
} }, e; }(Subscriber), SkipUntilSubscriber = function (t) { function e(e, i) { var r = t.call(this, e) || this; return r.hasValue = !1, r.add(r.innerSubscription = subscribeToResult(r, i)), r; } return __extends(e, t), e.prototype._next = function (e) { this.hasValue && t.prototype._next.call(this, e); }, e.prototype.notifyNext = function (t, e, i, r, s) { this.hasValue = !0, this.innerSubscription && this.innerSubscription.unsubscribe(); }, e.prototype.notifyComplete = function () { }, e; }(OuterSubscriber), SkipWhileSubscriber = function (t) { function e(e, i) { var r = t.call(this, e) || this; return r.predicate = i, r.skipping = !0, r.index = 0, r; } return __extends(e, t), e.prototype._next = function (t) { var e = this.destination; this.skipping && this.tryCallPredicate(t), this.skipping || e.next(t); }, e.prototype.tryCallPredicate = function (t) { try {
    var e = this.predicate(t, this.index++);
    this.skipping = Boolean(e);
}
catch (t) {
    this.destination.error(t);
} }, e; }(Subscriber);
function startWith() { for (var t = [], e = 0; e < arguments.length; e++)
    t[e] = arguments[e]; return function (e) { var i = t[t.length - 1]; isScheduler(i) ? t.pop() : i = null; var r = t.length; return concat(1 !== r || i ? r > 0 ? fromArray(t, i) : empty(i) : scalar(t[0]), e); }; }
var SubscribeOnObservable = function (t) { function e(e, i, r) { void 0 === i && (i = 0), void 0 === r && (r = asap); var s = t.call(this) || this; return s.source = e, s.delayTime = i, s.scheduler = r, (!isNumeric(i) || i < 0) && (s.delayTime = 0), r && "function" == typeof r.schedule || (s.scheduler = asap), s; } return __extends(e, t), e.create = function (t, i, r) { return void 0 === i && (i = 0), void 0 === r && (r = asap), new e(t, i, r); }, e.dispatch = function (t) { var e = t.source, i = t.subscriber; return this.add(e.subscribe(i)); }, e.prototype._subscribe = function (t) { var i = this.delayTime, r = this.source; return this.scheduler.schedule(e.dispatch, i, { source: r, subscriber: t }); }, e; }(Observable), SwitchMapSubscriber = function (t) { function e(e, i) { var r = t.call(this, e) || this; return r.project = i, r.index = 0, r; } return __extends(e, t), e.prototype._next = function (t) { var e, i = this.index++; try {
    e = this.project(t, i);
}
catch (t) {
    return void this.destination.error(t);
} this._innerSub(e, t, i); }, e.prototype._innerSub = function (t, e, i) { var r = this.innerSubscription; r && r.unsubscribe(), this.add(this.innerSubscription = subscribeToResult(this, t, e, i)); }, e.prototype._complete = function () { var e = this.innerSubscription; e && !e.closed || t.prototype._complete.call(this); }, e.prototype._unsubscribe = function () { this.innerSubscription = null; }, e.prototype.notifyComplete = function (e) { this.remove(e), this.innerSubscription = null, this.isStopped && t.prototype._complete.call(this); }, e.prototype.notifyNext = function (t, e, i, r, s) { this.destination.next(e); }, e; }(OuterSubscriber), TakeUntilSubscriber = function (t) { function e(e) { return t.call(this, e) || this; } return __extends(e, t), e.prototype.notifyNext = function (t, e, i, r, s) { this.complete(); }, e.prototype.notifyComplete = function () { }, e; }(OuterSubscriber), TakeWhileSubscriber = function (t) { function e(e, i) { var r = t.call(this, e) || this; return r.predicate = i, r.index = 0, r; } return __extends(e, t), e.prototype._next = function (t) { var e, i = this.destination; try {
    e = this.predicate(t, this.index++);
}
catch (t) {
    return void i.error(t);
} this.nextOrComplete(t, e); }, e.prototype.nextOrComplete = function (t, e) { var i = this.destination; Boolean(e) ? i.next(t) : i.complete(); }, e; }(Subscriber), ThrottleSubscriber = function (t) { function e(e, i, r, s) { var n = t.call(this, e) || this; return n.destination = e, n.durationSelector = i, n._leading = r, n._trailing = s, n._hasValue = !1, n; } return __extends(e, t), e.prototype._next = function (t) { this._hasValue = !0, this._sendValue = t, this._throttled || (this._leading ? this.send() : this.throttle(t)); }, e.prototype.send = function () { var t = this._hasValue, e = this._sendValue; t && (this.destination.next(e), this.throttle(e)), this._hasValue = !1, this._sendValue = null; }, e.prototype.throttle = function (t) { var e = this.tryDurationSelector(t); e && this.add(this._throttled = subscribeToResult(this, e)); }, e.prototype.tryDurationSelector = function (t) { try {
    return this.durationSelector(t);
}
catch (t) {
    return this.destination.error(t), null;
} }, e.prototype.throttlingDone = function () { var t = this._throttled, e = this._trailing; t && t.unsubscribe(), this._throttled = null, e && this.send(); }, e.prototype.notifyNext = function (t, e, i, r, s) { this.throttlingDone(); }, e.prototype.notifyComplete = function () { this.throttlingDone(); }, e; }(OuterSubscriber), ThrottleTimeSubscriber = function (t) { function e(e, i, r, s, n) { var o = t.call(this, e) || this; return o.duration = i, o.scheduler = r, o.leading = s, o.trailing = n, o._hasTrailingValue = !1, o._trailingValue = null, o; } return __extends(e, t), e.prototype._next = function (t) { this.throttled ? this.trailing && (this._trailingValue = t, this._hasTrailingValue = !0) : (this.add(this.throttled = this.scheduler.schedule(dispatchNext$1, this.duration, { subscriber: this })), this.leading && this.destination.next(t)); }, e.prototype._complete = function () { this._hasTrailingValue ? (this.destination.next(this._trailingValue), this.destination.complete()) : this.destination.complete(); }, e.prototype.clearThrottle = function () { var t = this.throttled; t && (this.trailing && this._hasTrailingValue && (this.destination.next(this._trailingValue), this._trailingValue = null, this._hasTrailingValue = !1), t.unsubscribe(), this.remove(t), this.throttled = null); }, e; }(Subscriber);
function dispatchNext$1(t) { t.subscriber.clearThrottle(); }
var TimeoutWithSubscriber = function (t) { function e(e, i, r, s, n) { var o = t.call(this, e) || this; return o.absoluteTimeout = i, o.waitFor = r, o.withObservable = s, o.scheduler = n, o.action = null, o.scheduleTimeout(), o; } return __extends(e, t), e.dispatchTimeout = function (t) { var e = t.withObservable; t._unsubscribeAndRecycle(), t.add(subscribeToResult(t, e)); }, e.prototype.scheduleTimeout = function () { var t = this.action; t ? this.action = t.schedule(this, this.waitFor) : this.add(this.action = this.scheduler.schedule(e.dispatchTimeout, this.waitFor, this)); }, e.prototype._next = function (e) { this.absoluteTimeout || this.scheduleTimeout(), t.prototype._next.call(this, e); }, e.prototype._unsubscribe = function () { this.action = null, this.scheduler = null, this.withObservable = null; }, e; }(OuterSubscriber), WindowSubscriber = function (t) { function e(e) { var i = t.call(this, e) || this; return i.window = new Subject, e.next(i.window), i; } return __extends(e, t), e.prototype.notifyNext = function (t, e, i, r, s) { this.openWindow(); }, e.prototype.notifyError = function (t, e) { this._error(t); }, e.prototype.notifyComplete = function (t) { this._complete(); }, e.prototype._next = function (t) { this.window.next(t); }, e.prototype._error = function (t) { this.window.error(t), this.destination.error(t); }, e.prototype._complete = function () { this.window.complete(), this.destination.complete(); }, e.prototype._unsubscribe = function () { this.window = null; }, e.prototype.openWindow = function () { var t = this.window; t && t.complete(); var e = this.destination, i = this.window = new Subject; e.next(i); }, e; }(OuterSubscriber), WindowCountSubscriber = function (t) { function e(e, i, r) { var s = t.call(this, e) || this; return s.destination = e, s.windowSize = i, s.startWindowEvery = r, s.windows = [new Subject], s.count = 0, e.next(s.windows[0]), s; } return __extends(e, t), e.prototype._next = function (t) { for (var e = this.startWindowEvery > 0 ? this.startWindowEvery : this.windowSize, i = this.destination, r = this.windowSize, s = this.windows, n = s.length, o = 0; o < n && !this.closed; o++)
    s[o].next(t); var c = this.count - r + 1; if (c >= 0 && c % e == 0 && !this.closed && s.shift().complete(), ++this.count % e == 0 && !this.closed) {
    var u = new Subject;
    s.push(u), i.next(u);
} }, e.prototype._error = function (t) { var e = this.windows; if (e)
    for (; e.length > 0 && !this.closed;)
        e.shift().error(t); this.destination.error(t); }, e.prototype._complete = function () { var t = this.windows; if (t)
    for (; t.length > 0 && !this.closed;)
        t.shift().complete(); this.destination.complete(); }, e.prototype._unsubscribe = function () { this.count = 0, this.windows = null; }, e; }(Subscriber), CountedSubject = function (t) { function e() { var e = null !== t && t.apply(this, arguments) || this; return e._numberOfNextedValues = 0, e; } return __extends(e, t), e.prototype.next = function (e) { this._numberOfNextedValues++, t.prototype.next.call(this, e); }, Object.defineProperty(e.prototype, "numberOfNextedValues", { get: function () { return this._numberOfNextedValues; }, enumerable: !0, configurable: !0 }), e; }(Subject), WindowTimeSubscriber = function (t) { function e(e, i, r, s, n) { var o = t.call(this, e) || this; o.destination = e, o.windowTimeSpan = i, o.windowCreationInterval = r, o.maxWindowSize = s, o.scheduler = n, o.windows = []; var c = o.openWindow(); if (null !== r && r >= 0) {
    var u = { subscriber: o, window: c, context: null }, a = { windowTimeSpan: i, windowCreationInterval: r, subscriber: o, scheduler: n };
    o.add(n.schedule(dispatchWindowClose, i, u)), o.add(n.schedule(dispatchWindowCreation, r, a));
}
else {
    var h = { subscriber: o, window: c, windowTimeSpan: i };
    o.add(n.schedule(dispatchWindowTimeSpanOnly, i, h));
} return o; } return __extends(e, t), e.prototype._next = function (t) { for (var e = this.windows, i = e.length, r = 0; r < i; r++) {
    var s = e[r];
    s.closed || (s.next(t), s.numberOfNextedValues >= this.maxWindowSize && this.closeWindow(s));
} }, e.prototype._error = function (t) { for (var e = this.windows; e.length > 0;)
    e.shift().error(t); this.destination.error(t); }, e.prototype._complete = function () { for (var t = this.windows; t.length > 0;) {
    var e = t.shift();
    e.closed || e.complete();
} this.destination.complete(); }, e.prototype.openWindow = function () { var t = new CountedSubject; return this.windows.push(t), this.destination.next(t), t; }, e.prototype.closeWindow = function (t) { t.complete(); var e = this.windows; e.splice(e.indexOf(t), 1); }, e; }(Subscriber);
function dispatchWindowTimeSpanOnly(t) { var e = t.subscriber, i = t.windowTimeSpan, r = t.window; r && e.closeWindow(r), t.window = e.openWindow(), this.schedule(t, i); }
function dispatchWindowCreation(t) { var e = t.windowTimeSpan, i = t.subscriber, r = t.scheduler, s = t.windowCreationInterval, n = { action: this, subscription: null }, o = { subscriber: i, window: i.openWindow(), context: n }; n.subscription = r.schedule(dispatchWindowClose, e, o), this.add(n.subscription), this.schedule(t, s); }
function dispatchWindowClose(t) { var e = t.subscriber, i = t.window, r = t.context; r && r.action && r.subscription && r.action.remove(r.subscription), e.closeWindow(i); }
var WindowToggleSubscriber = function (t) { function e(e, i, r) { var s = t.call(this, e) || this; return s.openings = i, s.closingSelector = r, s.contexts = [], s.add(s.openSubscription = subscribeToResult(s, i, i)), s; } return __extends(e, t), e.prototype._next = function (t) { var e = this.contexts; if (e)
    for (var i = e.length, r = 0; r < i; r++)
        e[r].window.next(t); }, e.prototype._error = function (e) { var i = this.contexts; if (this.contexts = null, i)
    for (var r = i.length, s = -1; ++s < r;) {
        var n = i[s];
        n.window.error(e), n.subscription.unsubscribe();
    } t.prototype._error.call(this, e); }, e.prototype._complete = function () { var e = this.contexts; if (this.contexts = null, e)
    for (var i = e.length, r = -1; ++r < i;) {
        var s = e[r];
        s.window.complete(), s.subscription.unsubscribe();
    } t.prototype._complete.call(this); }, e.prototype._unsubscribe = function () { var t = this.contexts; if (this.contexts = null, t)
    for (var e = t.length, i = -1; ++i < e;) {
        var r = t[i];
        r.window.unsubscribe(), r.subscription.unsubscribe();
    } }, e.prototype.notifyNext = function (t, e, i, r, s) { if (t === this.openings) {
    var n = this.closingSelector, o = tryCatch(n)(e);
    if (o === errorObject)
        return this.error(errorObject.e);
    var c = new Subject, u = new Subscription, a = { window: c, subscription: u };
    this.contexts.push(a);
    var h = subscribeToResult(this, o, a);
    h.closed ? this.closeWindow(this.contexts.length - 1) : (h.context = a, u.add(h)), this.destination.next(c);
}
else
    this.closeWindow(this.contexts.indexOf(t)); }, e.prototype.notifyError = function (t) { this.error(t); }, e.prototype.notifyComplete = function (t) { t !== this.openSubscription && this.closeWindow(this.contexts.indexOf(t.context)); }, e.prototype.closeWindow = function (t) { if (-1 !== t) {
    var e = this.contexts, i = e[t], r = i.window, s = i.subscription;
    e.splice(t, 1), r.complete(), s.unsubscribe();
} }, e; }(OuterSubscriber), WindowSubscriber$1 = function (t) { function e(e, i) { var r = t.call(this, e) || this; return r.destination = e, r.closingSelector = i, r.openWindow(), r; } return __extends(e, t), e.prototype.notifyNext = function (t, e, i, r, s) { this.openWindow(s); }, e.prototype.notifyError = function (t, e) { this._error(t); }, e.prototype.notifyComplete = function (t) { this.openWindow(t); }, e.prototype._next = function (t) { this.window.next(t); }, e.prototype._error = function (t) { this.window.error(t), this.destination.error(t), this.unsubscribeClosingNotification(); }, e.prototype._complete = function () { this.window.complete(), this.destination.complete(), this.unsubscribeClosingNotification(); }, e.prototype.unsubscribeClosingNotification = function () { this.closingNotification && this.closingNotification.unsubscribe(); }, e.prototype.openWindow = function (t) { void 0 === t && (t = null), t && (this.remove(t), t.unsubscribe()); var e = this.window; e && e.complete(); var i = this.window = new Subject; this.destination.next(i); var r = tryCatch(this.closingSelector)(); if (r === errorObject) {
    var s = errorObject.e;
    this.destination.error(s), this.window.error(s);
}
else
    this.add(this.closingNotification = subscribeToResult(this, r)); }, e; }(OuterSubscriber), WithLatestFromSubscriber = function (t) { function e(e, i, r) { var s = t.call(this, e) || this; s.observables = i, s.project = r, s.toRespond = []; var n = i.length; s.values = new Array(n); for (var o = 0; o < n; o++)
    s.toRespond.push(o); for (o = 0; o < n; o++) {
    var c = i[o];
    s.add(subscribeToResult(s, c, c, o));
} return s; } return __extends(e, t), e.prototype.notifyNext = function (t, e, i, r, s) { this.values[i] = e; var n = this.toRespond; if (n.length > 0) {
    var o = n.indexOf(i);
    -1 !== o && n.splice(o, 1);
} }, e.prototype.notifyComplete = function () { }, e.prototype._next = function (t) { if (0 === this.toRespond.length) {
    var e = [t].concat(this.values);
    this.project ? this._tryProject(e) : this.destination.next(e);
} }, e.prototype._tryProject = function (t) { var e; try {
    e = this.project.apply(this, t);
}
catch (t) {
    return void this.destination.error(t);
} this.destination.next(e); }, e; }(OuterSubscriber);
var RxUtil = /** @class */ (function () {
    function RxUtil() {
    }
    RxUtil.isObservable = function (t) { return t instanceof Observable; };
    RxUtil.log = function () { return console.log.bind(console); };
    return RxUtil;
}());
var action$ = new Subject, createStore = function (t, e) {
    if (e === void 0) { e = { timestamp: Util.getTimeStamp(), id: Util.getUUID() }; }
    return action$.pipe(mergeMap(function (t) { return RxUtil.isObservable(t) ? t : from([t]); }), startWith(e), scan(t));
}, actionCreator = function (t) { return function () {
    var e = [];
    for (var _i = 0; _i < arguments.length; _i++) {
        e[_i] = arguments[_i];
    }
    var i = t.call.apply(t, [null].concat(e));
    return action$.next(i), RxUtil.isObservable(i.payload) && action$.next(i.payload), i;
}; };
function baseReducer(t, e) { switch (e.type) {
    case "CONFIG_LOADING": return Object.assign({}, t, { isLoading: !0, timestamp: Util.getTimeStamp() });
    case "CONFIG_LOADED":
        var i_1 = Object.assign({}, t, { isLoading: !1 });
        return Object.keys(e.payload).forEach(function (t) { i_1[t] = e.payload[t]; }), i_1.timestamp = Util.getTimeStamp(), i_1;
    case "SET_CONFIG":
        var r_1 = Object.assign({}, t);
        return Object.keys(e.payload).forEach(function (t) { r_1[t] = e.payload[t]; }), r_1.timestamp = Util.getTimeStamp(), r_1;
    default: return t;
} }
var __window = "undefined" != typeof window && window, __self = "undefined" != typeof self && "undefined" != typeof WorkerGlobalScope && self instanceof WorkerGlobalScope && self, __global = void 0 !== global$1 && global$1, _root = __window || __global || __self;
function getCORSRequest() { if (_root.XMLHttpRequest)
    return new _root.XMLHttpRequest; if (_root.XDomainRequest)
    return new _root.XDomainRequest; throw new Error("CORS is not supported by your browser"); }
function getXMLHttpRequest() { if (_root.XMLHttpRequest)
    return new _root.XMLHttpRequest; var t = void 0; try {
    for (var e = ["Msxml2.XMLHTTP", "Microsoft.XMLHTTP", "Msxml2.XMLHTTP.4.0"], i = 0; i < 3; i++)
        try {
            if (t = e[i], new _root.ActiveXObject(t))
                break;
        }
        catch (t) { }
    return new _root.ActiveXObject(t);
}
catch (t) {
    throw new Error("XMLHttpRequest is not supported by your browser");
} }
function ajaxGet(t, e) { return void 0 === e && (e = null), new AjaxObservable({ method: "GET", url: t, headers: e }); }
function ajaxPost(t, e, i) { return new AjaxObservable({ method: "POST", url: t, body: e, headers: i }); }
function ajaxDelete(t, e) { return new AjaxObservable({ method: "DELETE", url: t, headers: e }); }
function ajaxPut(t, e, i) { return new AjaxObservable({ method: "PUT", url: t, body: e, headers: i }); }
function ajaxPatch(t, e, i) { return new AjaxObservable({ method: "PATCH", url: t, body: e, headers: i }); }
var mapResponse = map(function (t, e) { return t.response; });
function ajaxGetJSON(t, e) { return mapResponse(new AjaxObservable({ method: "GET", url: t, responseType: "json", headers: e })); }
var AjaxObservable = function (t) { function e(e) { var i = t.call(this) || this, r = { async: !0, createXHR: function () { return this.crossDomain ? getCORSRequest() : getXMLHttpRequest(); }, crossDomain: !0, withCredentials: !1, headers: {}, method: "GET", responseType: "json", timeout: 0 }; if ("string" == typeof e)
    r.url = e;
else
    for (var s in e)
        e.hasOwnProperty(s) && (r[s] = e[s]); return i.request = r, i; } var i; return __extends(e, t), e.prototype._subscribe = function (t) { return new AjaxSubscriber(t, this.request); }, e.create = ((i = function (t) { return new e(t); }).get = ajaxGet, i.post = ajaxPost, i.delete = ajaxDelete, i.put = ajaxPut, i.patch = ajaxPatch, i.getJSON = ajaxGetJSON, i), e; }(Observable), AjaxSubscriber = function (t) { function e(e, i) { var r = t.call(this, e) || this; r.request = i, r.done = !1; var s = i.headers = i.headers || {}; return i.crossDomain || s["X-Requested-With"] || (s["X-Requested-With"] = "XMLHttpRequest"), "Content-Type" in s || _root.FormData && i.body instanceof _root.FormData || void 0 === i.body || (s["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8"), i.body = r.serializeBody(i.body, i.headers["Content-Type"]), r.send(), r; } return __extends(e, t), e.prototype.next = function (t) { this.done = !0; var e = this.xhr, i = this.request, r = this.destination, s = new AjaxResponse(t, e, i); r.next(s); }, e.prototype.send = function () { var t = this.request, e = this.request, i = e.user, r = e.method, s = e.url, n = e.async, o = e.password, c = e.headers, u = e.body, a = t.createXHR, h = tryCatch(a).call(t); if (h === errorObject)
    this.error(errorObject.e);
else {
    if (this.xhr = h, this.setupEvents(h, t), (i ? tryCatch(h.open).call(h, r, s, n, i, o) : tryCatch(h.open).call(h, r, s, n)) === errorObject)
        return this.error(errorObject.e), null;
    if (n && (h.timeout = t.timeout, h.responseType = t.responseType), "withCredentials" in h && (h.withCredentials = !!t.withCredentials), this.setHeaders(h, c), (u ? tryCatch(h.send).call(h, u) : tryCatch(h.send).call(h)) === errorObject)
        return this.error(errorObject.e), null;
} return h; }, e.prototype.serializeBody = function (t, e) { if (!t || "string" == typeof t)
    return t; if (_root.FormData && t instanceof _root.FormData)
    return t; if (e) {
    var i = e.indexOf(";");
    -1 !== i && (e = e.substring(0, i));
} switch (e) {
    case "application/x-www-form-urlencoded": return Object.keys(t).map(function (e) { return encodeURIComponent(e) + "=" + encodeURIComponent(t[e]); }).join("&");
    case "application/json": return JSON.stringify(t);
    default: return t;
} }, e.prototype.setHeaders = function (t, e) { for (var i in e)
    e.hasOwnProperty(i) && t.setRequestHeader(i, e[i]); }, e.prototype.setupEvents = function (t, e) { var i, r, s = e.progressSubscriber; function n(t) { var e = n, i = e.subscriber, r = e.progressSubscriber, s = e.request; r && r.error(t), i.error(new AjaxTimeoutError(this, s)); } (t.ontimeout = n, n.request = e, n.subscriber = this, n.progressSubscriber = s, t.upload && "withCredentials" in t) && (s && (i = function (t) { i.progressSubscriber.next(t); }, _root.XDomainRequest ? t.onprogress = i : t.upload.onprogress = i, i.progressSubscriber = s), r = function (t) { var e = r, i = e.progressSubscriber, s = e.subscriber, n = e.request; i && i.error(t), s.error(new AjaxError("ajax error", this, n)); }, t.onerror = r, r.request = e, r.subscriber = this, r.progressSubscriber = s); function o(t) { } function c(t) { var e = c, i = e.subscriber, r = e.progressSubscriber, s = e.request; if (4 === this.readyState) {
    var n = 1223 === this.status ? 204 : this.status, o = "text" === this.responseType ? this.response || this.responseText : this.response;
    0 === n && (n = o ? 200 : 0), n < 400 ? (r && r.complete(), i.next(t), i.complete()) : (r && r.error(t), i.error(new AjaxError("ajax error " + n, this, s)));
} } t.onreadystatechange = o, o.subscriber = this, o.progressSubscriber = s, o.request = e, t.onload = c, c.subscriber = this, c.progressSubscriber = s, c.request = e; }, e.prototype.unsubscribe = function () { var e = this.done, i = this.xhr; !e && i && 4 !== i.readyState && "function" == typeof i.abort && i.abort(), t.prototype.unsubscribe.call(this); }, e; }(Subscriber), AjaxResponse = function () { return function (t, e, i) { this.originalEvent = t, this.xhr = e, this.request = i, this.status = e.status, this.responseType = e.responseType || i.responseType, this.response = parseXhrResponse(this.responseType, e); }; }(), AjaxError = function (t) { function e(i, r, s) { var n = t.call(this, i) || this; return n.name = "AjaxError", n.message = i, n.xhr = r, n.request = s, n.status = r.status, n.responseType = r.responseType || s.responseType, n.response = parseXhrResponse(n.responseType, r), Object.setPrototypeOf(n, e.prototype), n; } return __extends(e, t), e; }(Error);
function parseXhrResponse(t, e) { switch (t) {
    case "json": return "response" in e ? e.responseType ? e.response : JSON.parse(e.response || e.responseText || "null") : JSON.parse(e.responseText || "null");
    case "xml": return e.responseXML;
    case "text":
    default: return "response" in e ? e.response : e.responseText;
} }
var AjaxTimeoutError = function (t) { function e(i, r) { var s = t.call(this, "ajax timeout", i, r) || this; return s.name = "AjaxTimeoutError", Object.setPrototypeOf(s, e.prototype), s; } return __extends(e, t), e; }(AjaxError), ajax = AjaxObservable.create;
var baseActions = { loadConfig: actionCreator(function (t) { return "string" == typeof t ? { type: "CONFIG_LOADING", payload: ajax(t).pipe(map(function (t) { return { type: "CONFIG_LOADED", payload: t.response }; })) } : { type: "CONFIG_LOADED", payload: t }; }), setConfig: actionCreator(function (t) { return { type: "SET_CONFIG", payload: t }; }) };
function appReducer(t, e) { switch (e.type) {
    case "GITHUB_FOLLOWERS_LOADING": return Object.assign({}, t, { isLoading: !0 });
    case "GITHUB_FOLLOWERS_LOADED": return Object.assign({}, t, { isLoading: !1, users: e.payload });
    case "NAME_CHANGED": return Object.assign({}, t, { isLoading: !1, timestamp: Util.getTimeStamp(), name: e.payload });
    default: return t;
} }
var appActions = { changeName: actionCreator(function (t) { return ({ type: "NAME_CHANGED", payload: t }); }), loadGithubFollowers: actionCreator(function (t) { var e = "https://api.github.com/users/" + t.username + "/followers"; return { type: "GITHUB_FOLLOWERS_LOADING", payload: ajax(e).pipe(map(function (t) { return map(t.response, "login"); }), map(function (t) { return ({ type: "GITHUB_FOLLOWERS_LOADED", payload: t }); })) }; }) };
var __awaiter = function (t, e, i, r) { return new (i || (i = Promise))(function (s, n) { function o(t) { try {
    u(r.next(t));
}
catch (t) {
    n(t);
} } function c(t) { try {
    u(r.throw(t));
}
catch (t) {
    n(t);
} } function u(t) { t.done ? s(t.value) : new i(function (e) { e(t.value); }).then(o, c); } u((r = r.apply(t, e || [])).next()); }); };
var singleton = Symbol(), singletonEnforcer = Symbol();
var AppService = /** @class */ (function () {
    function AppService(t) {
        if (this.actions = appActions, this.baseUrl = "", this.loading = !0, this.authenticated = !1, this.errorMessage = "", t !== singletonEnforcer)
            throw new Error("Cannot construct singleton");
        this.initStores(), this.base = BaseService.instance, this.config = this.base.config, this.user = new User("visitor"), this.test();
    }
    AppService.prototype.init = function (t, e) {
        if (e === void 0) { e = ""; }
        return __awaiter(this, void 0, void 0, function () { var _c, _d, _e, _f; return __generator(this, function (_g) {
            switch (_g.label) {
                case 0:
                    "" !== e && (this.baseUrl = e), this.appRoot = t;
                    return [4 /*yield*/, this.base.initApp(this.baseUrl + "/assets/config.json", !0, "_emaApp")];
                case 1:
                    _g.sent(), this.baseUrl = e, this.base.translation.use(this.config.get("language")), this.data = {};
                    _c = this.data;
                    return [4 /*yield*/, Util.fetchJson(this.baseUrl + "/assets/collection-manifest.json")];
                case 2:
                    _c.manifest = _g.sent();
                    _d = this.data;
                    return [4 /*yield*/, Util.fetchJson(this.baseUrl + "/assets/data/mock-data.json")];
                case 3:
                    _d.mockData = _g.sent();
                    _e = this.data;
                    return [4 /*yield*/, Util.fetchJson(this.baseUrl + "/assets/data/mock-dwp.json")];
                case 4:
                    _e.dwpData = _g.sent();
                    _f = this.data;
                    return [4 /*yield*/, Util.fetchJson(this.baseUrl + "/assets/data/apiSwagger.json")];
                case 5: return [2 /*return*/, (_f.swaggerData = _g.sent(), this.collectionManifest = this.data.manifest, this.parseComponents(), this.initHistory(), window.document.location.hostname.match("localhost") && this.config.set("dev", !0), this.data)];
            }
        }); });
    };
    AppService.prototype.initStores = function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_c) {
        this.store$ = createStore(appReducer, {}), this.config$ = createStore(baseReducer), this.store$.pipe(tap(RxUtil.log())).subscribe(function (t) { }), this.config$.pipe().subscribe(function (t) { }), this.actions.changeName("Bob"), baseActions.loadConfig(this.baseUrl + "/assets/config.json");
        return [2 /*return*/];
    }); }); };
    AppService.prototype.test = function () { console.log(this.user.roles), this.user.addRole("AUTHENTICATED"), this.user.addRole("DEVELOPER"), console.log(this.user.roles), this.user.removeRole("AUTHENTICATED"), console.log(this.user.roles), console.log(this.user.hasRole("DEVELOPER")), console.log(this.user.hasRole("AUTHENTICATED")); };
    AppService.prototype.initHistory = function () { "undefined" != typeof window && window.history; };
    AppService.prototype.parseComponents = function () {
        var _this = this;
        var t = [];
        Util.copy(this.data.manifest.components).map(function (e) { var i = e.tag, r = !1; _this.config.get("componentsIgnorePatterns").forEach(function (t) { i.match(t) && (r = !0); }), r || t.push(e); }), this.components = t;
    };
    AppService.prototype.showFlashMessage = function (t, e, i) {
        if (i === void 0) { i = 2e3; }
        document.querySelector("ema-flash-message").show(t, e, i);
    };
    Object.defineProperty(AppService, "instance", {
        get: function () { return this[singleton] || (this[singleton] = new AppService(singletonEnforcer)), this[singleton]; },
        enumerable: true,
        configurable: true
    });
    return AppService;
}());
export { AppService as a };
