import { __extends as u } from "./index-tslib.es6.js";
import { Subject as d } from "./index-Subject.js";
import { dateTimestampProvider as s } from "./index-dateTimestampProvider.js";
var l = (function(m) {
  u(_, m);
  function _(t, e, n) {
    t === void 0 && (t = 1 / 0), e === void 0 && (e = 1 / 0), n === void 0 && (n = s);
    var i = m.call(this) || this;
    return i._bufferSize = t, i._windowTime = e, i._timestampProvider = n, i._buffer = [], i._infiniteTimeWindow = !0, i._infiniteTimeWindow = e === 1 / 0, i._bufferSize = Math.max(1, t), i._windowTime = Math.max(1, e), i;
  }
  return _.prototype.next = function(t) {
    var e = this, n = e.isStopped, i = e._buffer, o = e._infiniteTimeWindow, f = e._timestampProvider, r = e._windowTime;
    n || (i.push(t), !o && i.push(f.now() + r)), this._trimBuffer(), m.prototype.next.call(this, t);
  }, _.prototype._subscribe = function(t) {
    this._throwIfClosed(), this._trimBuffer();
    for (var e = this._innerSubscribe(t), n = this, i = n._infiniteTimeWindow, o = n._buffer, f = o.slice(), r = 0; r < f.length && !t.closed; r += i ? 1 : 2)
      t.next(f[r]);
    return this._checkFinalizedStatuses(t), e;
  }, _.prototype._trimBuffer = function() {
    var t = this, e = t._bufferSize, n = t._timestampProvider, i = t._buffer, o = t._infiniteTimeWindow, f = (o ? 1 : 2) * e;
    if (e < 1 / 0 && f < i.length && i.splice(0, i.length - f), !o) {
      for (var r = n.now(), p = 0, a = 1; a < i.length && i[a] <= r; a += 2)
        p = a;
      p && i.splice(0, p + 1);
    }
  }, _;
})(d);
export {
  l as ReplaySubject
};
