import { __extends as c, __values as d } from "./index-tslib.es6.js";
import { Observable as a } from "./index-Observable.js";
import { EMPTY_SUBSCRIPTION as h, Subscription as b } from "./index-Subscription.js";
import { ObjectUnsubscribedError as _ } from "./index-ObjectUnsubscribedError.js";
import { arrRemove as y } from "./index-arrRemove.js";
import { errorContext as l } from "./index-errorContext.js";
var S = (function(s) {
  c(o, s);
  function o() {
    var r = s.call(this) || this;
    return r.closed = !1, r.currentObservers = null, r.observers = [], r.isStopped = !1, r.hasError = !1, r.thrownError = null, r;
  }
  return o.prototype.lift = function(r) {
    var t = new p(this, this);
    return t.operator = r, t;
  }, o.prototype._throwIfClosed = function() {
    if (this.closed)
      throw new _();
  }, o.prototype.next = function(r) {
    var t = this;
    l(function() {
      var e, u;
      if (t._throwIfClosed(), !t.isStopped) {
        t.currentObservers || (t.currentObservers = Array.from(t.observers));
        try {
          for (var i = d(t.currentObservers), n = i.next(); !n.done; n = i.next()) {
            var f = n.value;
            f.next(r);
          }
        } catch (v) {
          e = { error: v };
        } finally {
          try {
            n && !n.done && (u = i.return) && u.call(i);
          } finally {
            if (e) throw e.error;
          }
        }
      }
    });
  }, o.prototype.error = function(r) {
    var t = this;
    l(function() {
      if (t._throwIfClosed(), !t.isStopped) {
        t.hasError = t.isStopped = !0, t.thrownError = r;
        for (var e = t.observers; e.length; )
          e.shift().error(r);
      }
    });
  }, o.prototype.complete = function() {
    var r = this;
    l(function() {
      if (r._throwIfClosed(), !r.isStopped) {
        r.isStopped = !0;
        for (var t = r.observers; t.length; )
          t.shift().complete();
      }
    });
  }, o.prototype.unsubscribe = function() {
    this.isStopped = this.closed = !0, this.observers = this.currentObservers = null;
  }, Object.defineProperty(o.prototype, "observed", {
    get: function() {
      var r;
      return ((r = this.observers) === null || r === void 0 ? void 0 : r.length) > 0;
    },
    enumerable: !1,
    configurable: !0
  }), o.prototype._trySubscribe = function(r) {
    return this._throwIfClosed(), s.prototype._trySubscribe.call(this, r);
  }, o.prototype._subscribe = function(r) {
    return this._throwIfClosed(), this._checkFinalizedStatuses(r), this._innerSubscribe(r);
  }, o.prototype._innerSubscribe = function(r) {
    var t = this, e = this, u = e.hasError, i = e.isStopped, n = e.observers;
    return u || i ? h : (this.currentObservers = null, n.push(r), new b(function() {
      t.currentObservers = null, y(n, r);
    }));
  }, o.prototype._checkFinalizedStatuses = function(r) {
    var t = this, e = t.hasError, u = t.thrownError, i = t.isStopped;
    e ? r.error(u) : i && r.complete();
  }, o.prototype.asObservable = function() {
    var r = new a();
    return r.source = this, r;
  }, o.create = function(r, t) {
    return new p(r, t);
  }, o;
})(a), p = (function(s) {
  c(o, s);
  function o(r, t) {
    var e = s.call(this) || this;
    return e.destination = r, e.source = t, e;
  }
  return o.prototype.next = function(r) {
    var t, e;
    (e = (t = this.destination) === null || t === void 0 ? void 0 : t.next) === null || e === void 0 || e.call(t, r);
  }, o.prototype.error = function(r) {
    var t, e;
    (e = (t = this.destination) === null || t === void 0 ? void 0 : t.error) === null || e === void 0 || e.call(t, r);
  }, o.prototype.complete = function() {
    var r, t;
    (t = (r = this.destination) === null || r === void 0 ? void 0 : r.complete) === null || t === void 0 || t.call(r);
  }, o.prototype._subscribe = function(r) {
    var t, e;
    return (e = (t = this.source) === null || t === void 0 ? void 0 : t.subscribe(r)) !== null && e !== void 0 ? e : h;
  }, o;
})(S);
export {
  p as AnonymousSubject,
  S as Subject
};
