/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../../../chunks/_rollupPluginBabelHelpers","../../../../core/maybe","../../../../core/scheduling","../support/I3SLayerView"],(function(e,s,i,o,t){"use strict";let d=function(){this.lodCrossfadeSignedDuration=0},a=function(){function e(e){this.view=e,this._preRenderFrameTaskHandle=null,this._currentFrameStartTime=null,this._numFadingNodes=0}var d=e.prototype;return d.stopNodeFading=function(e){null!=e.lodCrossfadeProgress&&(this._numFadingNodes--,e.lodCrossfadeProgress=null,0===this._numFadingNodes&&(null!=this._preRenderFrameTaskHandle&&(this._preRenderFrameTaskHandle=i.removeMaybe(this._preRenderFrameTaskHandle)),this.view.notifyLODUpdate(),this.view.notifyUpdate()))},d._startNodeFading=function(e,s,i){0===this._numFadingNodes&&(this._preRenderFrameTaskHandle=o.addFrameTask({preRender:e=>this._updateAllNodeFading(e)}),this.view.notifyLODUpdate()),null==e.lodCrossfadeProgress&&(this._numFadingNodes++,this.view.notifyUpdate()),e.lodCrossfadeSignedDuration=i,e.lodCrossfadeProgress=s},d._updateAllNodeFading=function(e){const s=this.view.nodeCrossfadingEnabled;this.view.foreachCrossfadeNode(((o,t)=>{if(i.isSome(t)&&i.isSome(t.lodCrossfadeProgress)){const i=t.lodCrossfadeSignedDuration,d=i>0?this.view.fullOpacity:0,a=e.deltaTime/i,n=t.lodCrossfadeProgress+Math.abs(a),r=!s||n>=1||0===i,l=d-(r?0:i>0?1:-1)*(1-n);r?(this.stopNodeFading(t),i<0&&this.view.markNodeToRemove(o)):t.lodCrossfadeProgress=n,this.view.setNodeOpacityByIndex(o,l)}})),this.view.removeMarkedNodes()},d.stopAllNodeFading=function(){this.view.foreachCrossfadeNode(((e,s)=>{if(i.isSome(s)&&i.isSome(s.lodCrossfadeProgress)){this.stopNodeFading(s);const i=s.lodCrossfadeSignedDuration;i<0&&this.view.markNodeToRemove(e);const o=i>0?this.view.fullOpacity:0;this.view.setNodeOpacityByIndex(e,o)}})),this.view.removeMarkedNodes()},d.fadeNode=function(e,s,i,o){null==this._currentFrameStartTime&&(this._currentFrameStartTime=Date.now());const d=this.view,a=d.nodeCrossfadingEnabled,r=i===t.FadeDirection.FadeIn?d.fullOpacity:0,l=a?o?i===t.FadeDirection.FadeIn?d.lodCrossfadeinDuration:d.lodCrossfadeoutDuration:d.lodCrossfadeUncoveredDuration:0,u=this.view.getNodeOpacityByIndex(e);if(a&&u!==r&&l>0){const e=1-Math.abs(r-u);this._startNodeFading(s,e,n(i)*l)}else this.stopNodeFading(s),this.view.setNodeOpacityByIndex(e,r),i===t.FadeDirection.FadeOut&&this.view.removeNode(e)},d.isNodeFullyFadedIn=function(e){const s=this.view.getNodeCrossfadeMetaData(e);return i.isNone(s)||null==s.lodCrossfadeProgress&&this.view.getNodeOpacityByIndex(e)===this.view.fullOpacity},s._createClass(e,[{key:"updating",get:function(){return this._numFadingNodes>0}}]),e}();function n(e){return e===t.FadeDirection.FadeIn?1:-1}e.I3SCrossfadeHelper=a,e.NodeCrossfadeMetaData=d,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
