import{c as o}from"./chunk-GJIGZB63.js";import{b as l}from"./chunk-5VDVFGVW.js";import{L as n,ka as r,pa as h,q as s}from"./chunk-J476KISY.js";var m=(()=>{class i{static{this.idCounter=0}get id(){return this._id}get startTime(){return this._startTime}get stopTime(){return this._stopTime}get laps(){return this.lapTimes$.asObservable()}get elapsedTime(){return this.elapsedTime$.asObservable()}get dateStart(){return this._dateStart}get elapsed(){return this._elapsed}constructor(t,e){this.tickService=t,this._startTime=null,this._stopTime=null,this.lapStartTime=null,this.elapsedTime$=new s(0),this.totalElapsedTime=0,this.running=!1,this.tickS=null,this._elapsed=0,this._elapsedBase=0,this.lapTimes$=new s([]),this._id=e||`stopwatch-${i.idCounter++}`}setDate(t){this._dateStart=t,this._startTime=this._dateStart.getTime(),this.lapStartTime=this._startTime;let e=Date.now(),a=e-this._startTime;return this._stopTime=e,this.totalElapsedTime+=a,this.elapsedTime$.next(this.totalElapsedTime),this}destroy(){this.tickS?.unsubscribe(),this.elapsedTime$.unsubscribe(),this.lapTimes$.unsubscribe()}start(){this.running||(this.running=!0,l.isSet(this._dateStart)||(this._dateStart=new Date,this._startTime=this._dateStart.getTime(),this.lapStartTime=this._startTime),l.isSet(this.lapStartTime)||(this.lapStartTime=Date.now()),this._stopTime=null,this.tickS=this.tickService.tick.subscribe(()=>{if(this._startTime){let t=Date.now()-this._startTime;this._elapsed=this._elapsedBase+Date.now()-this.lapStartTime,this.elapsedTime$.next(t)}}))}pause(){if(!this.running||this._startTime===null)return;let t=Date.now(),e=t-this._startTime;this._stopTime=t,this.totalElapsedTime=e,this.snapshot(!0),this.elapsedTime$.next(this.totalElapsedTime),this.running=!1,this.tickS?.unsubscribe(),this.tickS=null}stop(){return this.pause(),this.totalElapsedTime=0,this._startTime=null,this._stopTime=null,this.lapStartTime=null,this.lapTimes$.next([]),this.elapsedTime$.next(0),this}snapshot(t=!1){if(!this.running||this._startTime===null)return;let e=Date.now(),a=e-this.lapStartTime;return this.lapTimes$.next([...this.lapTimes$.getValue(),{elapsedTime:a,startDate:new Date(this.lapStartTime),stopDate:new Date(e)}]),t?this.lapStartTime=null:this.lapStartTime=e,this._elapsedBase+=a,this}}return i})();var p=(()=>{class i{get tick(){return this.intervalTick$}get ms(){return this.msTick$}get rafTick(){return this.rafTick$.asObservable()}constructor(){this.rafTick$=new s(0),this.intervalTick$=n(100),this.msTick$=n(),this.startRafLoop()}startRafLoop(){let t=e=>{this.rafTick$.next(e),requestAnimationFrame(t)};requestAnimationFrame(t)}static{this.\u0275fac=function(e){return new(e||i)}}static{this.\u0275prov=r({token:i,factory:i.\u0275fac,providedIn:"root"})}}return i})();var b=(()=>{class i{constructor(t,e){this.tickService=t,this.translate=e}createStopwatch(t){return new m(this.tickService,t)}static{this.\u0275fac=function(e){return new(e||i)(h(p),h(o))}}static{this.\u0275prov=r({token:i,factory:i.\u0275fac,providedIn:"root"})}}return i})();export{b as a};
