// All material copyright Esri, All Rights Reserved, unless otherwise specified. // See https://js.arcgis.com/4.30/esri/copyright.txt for details. //>>built define("require ../../chunks/tslib.es6 ../../TimeExtent ../../TimeInterval ../../core/Collection ../../core/deprecate ../../core/Evented ../../core/Logger ../../core/promiseUtils ../../core/reactiveUtils ../../core/timeUtils ../../core/accessorSupport/decorators/property ../../core/accessorSupport/ensureType ../../core/RandomLCG ../../core/has ../../core/accessorSupport/decorators/subclass ../../webdoc/Widgets ../../webdoc/widgets/TimeSlider".split(" "),function(B,g,l,C,w,D,e,x,y,p,E,h,z,I,J,F,G, H){function v(a){return null!=a&&void 0!==a.count}function u(a){return null!=a&&void 0!==a.interval}e=class extends e.EventedAccessor{constructor(a){super(a);this._animationController=null;this._isViewTimeExtentInitialized=!1;this._timerId=null;this.actions=new w;this.fullTimeExtent=null;this.loop=!1;this.mode="time-window";this.stops={count:10};this.view=this.timeExtent=null}initialize(){this.addHandles([p.watch(()=>this.effectiveStops,()=>{null==this.timeExtent&&(this.timeExtent=this._getDefaultTimeExtent())}, p.initial),p.watch(()=>this.view,(a,b)=>{this._unregisterWidget(b);this._registerWidget(a)},p.syncAndInitial),p.watch(()=>this.timeExtent,a=>{if(null!=this.view){var b=this.view.timeExtent;if(null!=a&&!a.isAllTime||null!=b&&!b.isAllTime)null!=a&&null!=b&&a.equals(b)||(this.view.timeExtent=a)}},p.initial),p.watch(()=>this.view?.timeExtent,a=>{if(!this._isViewTimeExtentInitialized)this._isViewTimeExtentInitialized=!0;else if(null!=a&&!a.isAllTime||null!=this.timeExtent&&!this.timeExtent.isAllTime)null!= a&&null!=this.timeExtent&&a.equals(this.timeExtent)||(this.timeExtent=a)})])}destroy(){null!=this._timerId&&(clearInterval(this._timerId),this._timerId=null);this._unregisterWidget(this.view);this.view=null;null!=this._animationController&&(this._animationController.abort(),this._animationController=null)}get effectiveStops(){const {fullTimeExtent:a,stops:b}=this;if(null!=b&&void 0!==b.dates){var {dates:d}=b;if(null==d||0===d.length)return null;d=d.sort((m,n)=>m.getTime()-n.getTime());if(null==a)return d; const {start:c,end:k}=a;return null==c||null==k?d:d.filter(m=>!(m.getTime()k.getTime()))}return v(b)?this._divideTimeExtentByCount(b.timeExtent??a,b.count):u(b)?this._divideTimeExtentByInterval(b.timeExtent??a,b.interval):[]}set playRate(a){0>=a||36E5B(["../../support/timeUtils"],c,k));return d(a,b)}next(){this._step({forward:!0,allowRestart:!1})}play(){this._startAnimation()}previous(){this._step({forward:!1,allowRestart:!1})}stop(){this._stopAnimation()}triggerAction(a){this.emit("trigger-action", {action:a})}updateWebDocument(a){var b=this.timeExtent,d=this.fullTimeExtent,c=this.loop,k=v(this.stops)?this.stops.count:null,m="time-window"===this.mode?2:1,n=this.playRate,t=u(this.stops)?this.stops.interval:null,f=this.stops;b=new H({currentTimeExtent:b,fullTimeExtent:d,loop:c,numStops:k,numThumbs:m,stopDelay:n,stopInterval:t,stops:null!=f&&void 0!==f.dates?this.stops.dates:null});a.widgets?a.widgets.timeSlider=b:a.widgets=new G({timeSlider:b})}valuesToTimeExtent(a){if(null==a)return null;var b= a.sort((d,c)=>d-c).map(d=>new Date(d));a=0!1===a.updating, b)])}catch(a){y.isAbortError(a)||x.getLogger(this).error(a);this._animationController=null;return}this._step({forward:!0,allowRestart:!1});null!=this._animationController&&this._animate()}_divideTimeExtentByCount(a,b=10){if(!a||!b)return[];const {start:d,end:c}=a;if(null==d||null==c)return[];if(1E4=n||m/n>d)return this._divideTimeExtentByCount(a);a=[];const {value:t,unit:f}=b;for(b=c;b.getTime()<=k.getTime();)a.push(new Date(b.getTime())),b=E.offsetDate(b,t,f);return a}_getDefaultTimeExtent(){const {effectiveStops:a,mode:b}=this;if(null==a||!b)return null;switch(b){case "time-window":return 1f.getTime());a=this.timeExtentValues.map(f=>{var r=c.indexOf(f);if(-1!==r)return r;r=c.reduce((q,A)=>Math.abs(A-f)f+=b?1:-1),m=k.some(f=>0>f||f>c.length-1),{loop:n,state:t}=this;if(m)if(n||d){const f=Math.min(...a),r=Math.max(...a);a=(b?a.map(q=>q-f):a.map(q=>q+(c.length-1-r))).map(q=>c[q]);this.timeExtent=this.valuesToTimeExtent(a)}else"playing"===t&&this.stop();else a=k.map(f=>c[f]),this.timeExtent= this.valuesToTimeExtent(a)}}_stopAnimation(){null!=this._animationController&&(this._animationController.abort(),this._animationController=null)}_unregisterWidget(a){null!=a&&a.persistableViewModels.remove(this)}};g.__decorate([h.property()],e.prototype,"_animationController",void 0);g.__decorate([h.property({type:w})],e.prototype,"actions",void 0);g.__decorate([h.property({readOnly:!0})],e.prototype,"effectiveStops",null);g.__decorate([h.property({type:l})],e.prototype,"fullTimeExtent",void 0);g.__decorate([h.property({nonNullable:!0})], e.prototype,"loop",void 0);g.__decorate([h.property({nonNullable:!0})],e.prototype,"mode",void 0);g.__decorate([h.property({nonNullable:!0,value:1E3})],e.prototype,"playRate",null);g.__decorate([h.property({readOnly:!0})],e.prototype,"state",null);g.__decorate([h.property({cast:a=>{if(null==a)return null;u(a)&&(a.interval=z.ensureType(C,a.interval));if(u(a)||v(a))a.timeExtent=z.ensureType(l,a.timeExtent);return a}})],e.prototype,"stops",void 0);g.__decorate([h.property({type:l})],e.prototype,"timeExtent", void 0);g.__decorate([h.property({readOnly:!0})],e.prototype,"timeExtentValues",null);g.__decorate([h.property()],e.prototype,"view",void 0);g.__decorate([h.property()],e.prototype,"next",null);g.__decorate([h.property()],e.prototype,"play",null);g.__decorate([h.property()],e.prototype,"previous",null);g.__decorate([h.property()],e.prototype,"stop",null);g.__decorate([h.property()],e.prototype,"updateWebDocument",null);return e=g.__decorate([F.subclass("esri.widgets.TimeSlider.TimeSliderViewModel")], e)});