/*
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{prefersReducedMotion as o}from"../../core/a11yUtils.js";import e from"../../core/Accessor.js";import i from"../../core/Error.js";import r from"../../core/Logger.js";import{throwIfAborted as s,whenOrAbort as n}from"../../core/promiseUtils.js";import{whenOnce as a}from"../../core/reactiveUtils.js";import{property as m,subclass as c}from"../../core/accessorSupport/decorators.js";import l from"../ViewAnimation.js";import{create as p}from"./viewpointUtils.js";let w=class extends e{constructor(t){super(t),this._gotoTask=null}destroy(){this._gotoTask=null}async goTo(t,e){if(!t)return void r.getLogger(this).error("#goTo()","target cannot be null or undefined");const i=new l;this.view.animation=i,await a(()=>this.view.ready,e);const s={...e,animate:e?.animate??(!o()&&this.view.animationsEnabled),animationMode:e?.animationMode??"auto"},{extent:n,spatialReference:m,size:c,viewpoint:w,constraints:g,padding:h,allLayerViews:d}=this.view,u=p(t,{extent:n,spatialReference:m,size:c,viewpoint:w,constraints:g,padding:h,allLayerViews:d,pickClosestTarget:e?.pickClosestTarget??!0});return i?.update(u),this._gotoTask={},s.animate?this._gotoAnimated(u,s):this._gotoImmediate(u,s)}_gotoImmediate(t,o){const e=this._gotoTask,r=this.view.animation,n=t.then(t=>{if(s(o),e!==this._gotoTask)throw new i("view:goto-interrupted","Goto was interrupted");this.view.viewpoint=r.target=t,r.finish()});return this._cancellableGoTo(e,r,n,o)}_gotoAnimated(t,o){const e=this._gotoTask,r=this.view.animation;if(!r)return Promise.resolve();const n=t.then(t=>{if(s(o),e!==this._gotoTask)throw new i("view:goto-interrupted","Goto was interrupted");return r.update(t),this.view.animationManager.animate(r,this.view.viewpoint,o),r.when().then(()=>{},()=>{})});return this._cancellableGoTo(e,r,n,o)}_cancellableGoTo(t,o,e,i){const r=()=>t===this._gotoTask;return n(e,i).finally(()=>{r()&&(o.done||o.stop())})}};t([m({constructOnly:!0})],w.prototype,"view",void 0),w=t([c("esri.views.2d.GoToManager")],w);export{w as GoToManager};
