/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../../../../core/time","../../../../../symbols/cim/enums","../grouping"],(function(e,t,i,r){"use strict";function n(e){return t.Milliseconds(e.frameDurations.reduce(((e,t)=>e+t),0))}function a(e){const{width:t,height:i}=e;return{frameDurations:e.frameDurations.reverse(),selectFrame:t=>{const i=e.frameDurations.length-1-t;e.selectFrame(i)},width:t,height:i}}function s(e,i){const{width:r,height:a,selectFrame:s}=e,o=i/n(e);return{frameDurations:e.frameDurations.map((e=>t.Milliseconds(e*o))),selectFrame:s,width:r,height:a}}function o(e,i){const{width:r,height:n,selectFrame:a}=e,s=e.frameDurations.slice(),o=s.shift();return s.unshift(t.Milliseconds(o+i)),{frameDurations:s,selectFrame:a,width:r,height:n}}function m(e,i){const{width:r,height:n,selectFrame:a}=e,s=e.frameDurations.slice(),o=s.pop();return s.push(t.Milliseconds(o+i)),{frameDurations:s,selectFrame:a,width:r,height:n}}let l=function(){function e(e,t,i){this._animation=e,this._repeatType=i,this._direction=1,this._currentFrame=0,this.timeToFrame=this._animation.frameDurations[this._currentFrame];let r=0;for(;t>r;)r+=this.timeToFrame,this.nextFrame();this._animation.selectFrame(this._currentFrame)}return e.prototype.nextFrame=function(){if(this._currentFrame+=this._direction,this._direction>0){if(this._currentFrame===this._animation.frameDurations.length)switch(this._repeatType){case i.AnimatedSymbolRepeatType.None:this._currentFrame-=this._direction;break;case i.AnimatedSymbolRepeatType.Loop:this._currentFrame=0;break;case i.AnimatedSymbolRepeatType.Oscillate:this._currentFrame-=this._direction,this._direction=-1}}else if(-1===this._currentFrame)switch(this._repeatType){case i.AnimatedSymbolRepeatType.None:this._currentFrame-=this._direction;break;case i.AnimatedSymbolRepeatType.Loop:this._currentFrame=this._animation.frameDurations.length-1;break;case i.AnimatedSymbolRepeatType.Oscillate:this._currentFrame-=this._direction,this._direction=1}this.timeToFrame=this._animation.frameDurations[this._currentFrame],this._animation.selectFrame(this._currentFrame)},e}();function c(e,c,u){let h,{repeatType:d}=c;if(null==d&&(d=i.AnimatedSymbolRepeatType.Loop),!0===c.reverseAnimation&&(e=a(e)),null!=c.duration&&(e=s(e,t.Milliseconds(1e3*c.duration))),null!=c.repeatDelay){const r=1e3*c.repeatDelay;d===i.AnimatedSymbolRepeatType.Loop?e=m(e,t.Milliseconds(r)):d===i.AnimatedSymbolRepeatType.Oscillate&&(e=o(m(e,t.Milliseconds(r/2)),t.Milliseconds(r/2)))}if(null!=c.startTimeOffset)h=t.Milliseconds(1e3*c.startTimeOffset);else if(null!=c.randomizeStartTime){const i=r.getMaterialGroup(u),a=82749913,s=null!=c.randomizeStartSeed?c.randomizeStartSeed:a,o=r.getRandomValue(i,s);h=t.Milliseconds(o*n(e))}else h=t.Milliseconds(0);return new l(e,h,d)}function u(e,t,i){const r=null==t.playAnimation||t.playAnimation,n=c(e,t,i);let a,s=n.timeToFrame;function o(){a=r&&setTimeout((()=>{n.nextFrame(),s=n.timeToFrame,o()}),s)}return o(),{remove:()=>{r&&clearTimeout(a)}}}e.Player=l,e.adjustDuration=s,e.appendDelay=m,e.createPlayer=c,e.getDuration=n,e.play=u,e.prependDelay=o,e.reverse=a,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
