/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["../../core/maybe","../../core/reactiveUtils","../../core/scheduling"],(function(e,t,a){"use strict";return function(){function s(t){this.view=t,this._frameTaskHandle=null,this._updateRequested=!1,this.stationary=!0,this.animationInProgress=!1,this.prepare=()=>{this._updateParameters.state=this.view.state,this._updateParameters.stationary=this.view.stationary,this._updateParameters.pixelRatio=window.devicePixelRatio,this._updateParameters.renderingOptions=this.view.renderingOptions},this.update=()=>{this._updateRequested=!1;const{basemapView:t,graphicsView:a,labelManager:s,layerViews:i,state:{id:r}}=this.view;t.baseLayerViews.forEach(this._updateLayerView,this),i.forEach(this._updateLayerView,this),t.referenceLayerViews.forEach(this._updateLayerView,this),e.isSome(s)&&(s.lastUpdateId!==r&&(s.viewChange(),s.lastUpdateId=r),s.updateRequested&&s.processUpdate(this._updateParameters)),e.isSome(a)&&(a.lastUpdateId!==r&&(a.viewChange(),a.lastUpdateId=r),a.updateRequested&&a.processUpdate(this._updateParameters)),this.view.graphicsTileStore.setViewState(this._updateParameters.state),this.animationInProgress||this._updateRequested||this._frameTaskHandle.pause()}}var i=s.prototype;return i.destroy=function(){this.stop()},i.start=function(){if(this._frameTaskHandle)return;const e=this.view;this.stationary=e.stationary,this._updateParameters={state:e.state,pixelRatio:window.devicePixelRatio,stationary:this.stationary,renderingOptions:e.renderingOptions},this._stationaryHandle=t.watch((()=>e.stationary),(e=>{this.stationary=e,this.requestFrame()})),this._frameTaskHandle=a.addFrameTask(this),this.requestUpdate()},i.stop=function(){this._frameTaskHandle&&(this._updateRequested=!1,this._stationaryHandle.remove(),this._frameTaskHandle.remove(),this._updateParameters=this._stationaryHandle=this._frameTaskHandle=null,this.stationary=!0,this.animationInProgress=!1)},i.requestUpdate=function(){this._updateRequested||(this._updateRequested=!0,this.requestFrame())},i.requestFrame=function(){this._frameTaskHandle&&this._frameTaskHandle.resume()},i._updateLayerView=function(e){const t=this.view.state,a=e.lastUpdateId;null!=a&&(this.stationary||e.moving)||(e.moving=!0,e.moveStart()),a!==t.id&&e.viewChange(),this.stationary&&e.moving&&(e.moving=!1,e.moveEnd()),e.lastUpdateId=t.id,e.updateRequested&&e.processUpdate(this._updateParameters),"layerViews"in e&&e.layerViews.forEach(this._updateLayerView,this)},s}()}));
