import{O as t,s,c as e,d as i,S as r}from"./p-ea120e31.js";function n(t){return t&&"function"==typeof t.schedule}function c(...i){let r=i[i.length-1];return n(r)?(i.pop(),e(i,r)):new t(s(i))}const h=new t((t=>t.complete()));function a(s){return s?function(s){return new t((t=>s.schedule((()=>t.complete()))))}(s):h}var o;!function(t){t.NEXT="N",t.ERROR="E",t.COMPLETE="C"}(o||(o={}));class u{constructor(t,s,e){this.kind=t,this.value=s,this.error=e,this.hasValue="N"===t}observe(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()}}do(t,s,e){switch(this.kind){case"N":return t&&t(this.value);case"E":return s&&s(this.error);case"C":return e&&e()}}accept(t,s,e){return t&&"function"==typeof t.next?this.observe(t):this.do(t,s,e)}toObservable(){switch(this.kind){case"N":return c(this.value);case"E":return s=this.error,new t((t=>t.error(s)));case"C":return a()}var s;throw new Error("unexpected notification kind value")}static createNext(t){return void 0!==t?new u("N",t):u.undefinedValueNotification}static createError(t){return new u("E",void 0,t)}static createComplete(){return u.completeNotification}}function f(t,s=i){var e;const r=(e=t)instanceof Date&&!isNaN(+e)?+t-s.now():Math.abs(t);return t=>t.lift(new w(r,s))}u.completeNotification=new u("C"),u.undefinedValueNotification=new u("N",void 0);class w{constructor(t,s){this.delay=t,this.scheduler=s}call(t,s){return s.subscribe(new l(t,this.delay,this.scheduler))}}class l extends r{constructor(t,s,e){super(t),this.delay=s,this.scheduler=e,this.queue=[],this.active=!1,this.errored=!1}static dispatch(t){const s=t.source,e=s.queue,i=t.scheduler,r=t.destination;for(;e.length>0&&e[0].time-i.now()<=0;)e.shift().notification.observe(r);if(e.length>0){const s=Math.max(0,e[0].time-i.now());this.schedule(t,s)}else this.unsubscribe(),s.active=!1}_schedule(t){this.active=!0,this.destination.add(t.schedule(l.dispatch,this.delay,{source:this,destination:this.destination,scheduler:t}))}scheduleNotification(t){if(!0===this.errored)return;const s=this.scheduler,e=new d(s.now()+this.delay,t);this.queue.push(e),!1===this.active&&this._schedule(s)}_next(t){this.scheduleNotification(u.createNext(t))}_error(t){this.errored=!0,this.queue=[],this.destination.error(t),this.unsubscribe()}_complete(){this.scheduleNotification(u.createComplete()),this.unsubscribe()}}class d{constructor(t,s){this.time=t,this.notification=s}}export{u as N,f as d,a as e,n as i,c as o}