/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{__decorate as t}from"tslib";import e from"../../core/Accessor.js";import{createTask as o}from"../../core/asyncUtils.js";import{makeHandle as i}from"../../core/handleUtils.js";import"../../core/has.js";import{abortMaybe as s}from"../../core/maybe.js";import{throwIfAborted as a}from"../../core/promiseUtils.js";import{watch as r,syncAndInitial as n}from"../../core/reactiveUtils.js";import{createScreenPoint as d}from"../../core/screenUtils.js";import{throttle as c}from"../../core/throttle.js";import{property as h,subclass as l}from"../../core/accessorSupport/decorators.js";const m=300;let u=class extends e{constructor(t){super(t),this._screenPoint=null,this._accumulatedShadowTime=null,this._shadowTimeTask=null,this._updateAccumulatedShadowTime=(t,e)=>{this._shadowTimeTask=s(this._shadowTimeTask),this._shadowTimeTask=o(async o=>{const{results:i,ground:s}=await t.hitTest(e);if(a(o),0===i.length&&!s.mapPoint)return void(this._accumulatedShadowTime=null);const r=await this.getDuration(e,o);this._accumulatedShadowTime=r})},this._throttledUpdateAccumulatedShadowTime=c(this._updateAccumulatedShadowTime,m)}initialize(){this.addHandles(r(()=>({enabled:this.enabled,view:this.view}),({enabled:t,view:e})=>{t&&null!=e?this._startTracking(e):this._stopTracking()},n))}get screenPoint(){return this.enabled?this._screenPoint:null}get accumulatedShadowTime(){return this.enabled?this._accumulatedShadowTime:null}get testData(){}_startTracking(t){if(this.hasHandles("main"))return;const e=()=>{this.hasHandles("pointer-move")||this.addHandles(t.on("pointer-move",e=>{const o=d(e.x,e.y);this._screenPoint=o,this._throttledUpdateAccumulatedShadowTime(t,o)}),"pointer-move")},o=()=>{this.removeHandles("pointer-move"),this._screenPoint=null,this._accumulatedShadowTime=null};this.addHandles([this._throttledUpdateAccumulatedShadowTime,t.on("pointer-enter",e),t.on("pointer-leave",o),t.on("pointer-down",o),t.on("pointer-drag",o),t.on("pointer-up",e),t.on("click",e=>{const o=d(e.x,e.y);this._screenPoint=o,this._updateAccumulatedShadowTime(t,o)}),i(()=>{this._shadowTimeTask=s(this._shadowTimeTask)})],"main"),e()}_stopTracking(){this.removeHandles("main")}};t([h()],u.prototype,"getDuration",void 0),t([h()],u.prototype,"view",void 0),t([h()],u.prototype,"enabled",void 0),t([h()],u.prototype,"screenPoint",null),t([h()],u.prototype,"accumulatedShadowTime",null),t([h()],u.prototype,"_screenPoint",void 0),t([h()],u.prototype,"_accumulatedShadowTime",void 0),t([h()],u.prototype,"_shadowTimeTask",void 0),u=t([l("esri.widgets.ShadowCast.ShadowTooltipViewModel")],u);export{u as ShadowTooltipViewModel};
