import { SafeSubscriber as f, Subscriber as p } from "./index-Subscriber.js";
import { isSubscription as m } from "./index-Subscription.js";
import { observable as h } from "./index-observable2.js";
import { pipeFromArray as v } from "./index-pipe.js";
import { config as y } from "./index-config2.js";
import { isFunction as b } from "./index-isFunction.js";
import { errorContext as l } from "./index-errorContext.js";
var E = (function() {
  function t(r) {
    r && (this._subscribe = r);
  }
  return t.prototype.lift = function(r) {
    var n = new t();
    return n.source = this, n.operator = r, n;
  }, t.prototype.subscribe = function(r, n, u) {
    var i = this, o = S(r) ? r : new f(r, n, u);
    return l(function() {
      var e = i, c = e.operator, s = e.source;
      o.add(c ? c.call(o, s) : s ? i._subscribe(o) : i._trySubscribe(o));
    }), o;
  }, t.prototype._trySubscribe = function(r) {
    try {
      return this._subscribe(r);
    } catch (n) {
      r.error(n);
    }
  }, t.prototype.forEach = function(r, n) {
    var u = this;
    return n = a(n), new n(function(i, o) {
      var e = new f({
        next: function(c) {
          try {
            r(c);
          } catch (s) {
            o(s), e.unsubscribe();
          }
        },
        error: o,
        complete: i
      });
      u.subscribe(e);
    });
  }, t.prototype._subscribe = function(r) {
    var n;
    return (n = this.source) === null || n === void 0 ? void 0 : n.subscribe(r);
  }, t.prototype[h] = function() {
    return this;
  }, t.prototype.pipe = function() {
    for (var r = [], n = 0; n < arguments.length; n++)
      r[n] = arguments[n];
    return v(r)(this);
  }, t.prototype.toPromise = function(r) {
    var n = this;
    return r = a(r), new r(function(u, i) {
      var o;
      n.subscribe(function(e) {
        return o = e;
      }, function(e) {
        return i(e);
      }, function() {
        return u(o);
      });
    });
  }, t.create = function(r) {
    return new t(r);
  }, t;
})();
function a(t) {
  var r;
  return (r = t ?? y.Promise) !== null && r !== void 0 ? r : Promise;
}
function _(t) {
  return t && b(t.next) && b(t.error) && b(t.complete);
}
function S(t) {
  return t && t instanceof p || _(t) && m(t);
}
export {
  E as Observable
};
