/*
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","../../chunks/tslib.es6","../../core/Accessor","../../core/Handles","../../core/handleUtils","../../core/maybe","../../core/promiseUtils","../../core/reactiveUtils","../../core/screenUtils","../../core/throttle","../../core/accessorSupport/decorators/property","../../core/arrayUtils","../../core/has","../../core/accessorSupport/ensureType","../../core/accessorSupport/decorators/subclass"],(function(e,t,o,a,i,r,n,d,s,c,l,u,h,p,_,w){"use strict";var m;!function(e){e.PointerMove="pointer-move",e.Main="main"}(m||(m={}));const T=300;e.ShadowTooltipViewModel=function(e){function o(o){var a;return(a=e.call(this,o)||this)._handles=new i,a._screenPoint=null,a._accumulatedShadowTime=null,a._shadowTimeTask=null,a._updateAccumulatedShadowTime=(e,o)=>{a._shadowTimeTask=n.abortMaybe(a._shadowTimeTask),a._shadowTimeTask=d.createTask(function(){var i=t._asyncToGenerator((function*(t){const{results:i,ground:r}=yield e.hitTest(o);if(0===i.length&&!r.mapPoint)return void(a._accumulatedShadowTime=null);const n=yield a.getDuration(o,t);a._accumulatedShadowTime=n}));return function(e){return i.apply(this,arguments)}}())},a._throttledUpdateAccumulatedShadowTime=l.throttle(a._updateAccumulatedShadowTime,T),a}t._inheritsLoose(o,e);var a=o.prototype;return a.initialize=function(){this._handles.add(s.watch((()=>({enabled:this.enabled,view:this.view})),(({enabled:e,view:t})=>{e&&n.isSome(t)?this._startTracking(t):this._stopTracking()}),s.syncAndInitial))},a.destroy=function(){this._handles=n.destroyMaybe(this._handles)},a._startTracking=function(e){const t=this._handles;if(t.has(m.Main))return;const o=()=>{t.has(m.PointerMove)||t.add(e.on("pointer-move",(t=>{const o=c.createScreenPoint(t.x,t.y);this._screenPoint=o,this._throttledUpdateAccumulatedShadowTime(e,o)})),m.PointerMove)},a=()=>{t.remove(m.PointerMove),this._screenPoint=null,this._accumulatedShadowTime=null};t.add([this._throttledUpdateAccumulatedShadowTime,e.on("pointer-enter",o),e.on("pointer-leave",a),e.on("pointer-down",a),e.on("pointer-drag",a),e.on("pointer-up",o),e.on("click",(t=>{const o=c.createScreenPoint(t.x,t.y);this._screenPoint=o,this._updateAccumulatedShadowTime(e,o)})),r.makeHandle((()=>{this._shadowTimeTask=n.abortMaybe(this._shadowTimeTask)}))],m.Main),o()},a._stopTracking=function(){this._handles.remove(m.Main)},t._createClass(o,[{key:"screenPoint",get:function(){return this.enabled?this._screenPoint:null}},{key:"accumulatedShadowTime",get:function(){return this.enabled?this._accumulatedShadowTime:null}},{key:"testData",get:function(){return{setThrottleDelay:e=>{this._throttledUpdateAccumulatedShadowTime.remove(),this._throttledUpdateAccumulatedShadowTime=l.throttle(this._updateAccumulatedShadowTime,e)}}}}]),o}(a),o.__decorate([u.property()],e.ShadowTooltipViewModel.prototype,"getDuration",void 0),o.__decorate([u.property()],e.ShadowTooltipViewModel.prototype,"view",void 0),o.__decorate([u.property()],e.ShadowTooltipViewModel.prototype,"enabled",void 0),o.__decorate([u.property()],e.ShadowTooltipViewModel.prototype,"screenPoint",null),o.__decorate([u.property()],e.ShadowTooltipViewModel.prototype,"accumulatedShadowTime",null),o.__decorate([u.property()],e.ShadowTooltipViewModel.prototype,"_screenPoint",void 0),o.__decorate([u.property()],e.ShadowTooltipViewModel.prototype,"_accumulatedShadowTime",void 0),o.__decorate([u.property()],e.ShadowTooltipViewModel.prototype,"_shadowTimeTask",void 0),e.ShadowTooltipViewModel=o.__decorate([w.subclass("esri.widgets.ShadowCast.ShadowTooltipViewModel")],e.ShadowTooltipViewModel),Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
