/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["../../chunks/_rollupPluginBabelHelpers","../../chunks/tslib.es6","../../Viewpoint","../../core/Error","../../core/Evented","../../core/accessorSupport/decorators/property","../../core/arrayUtils","../../core/has","../../core/accessorSupport/ensureType","../../core/accessorSupport/decorators/subclass","../support/GoTo"],(function(e,t,o,i,n,r,s,l,c,a,p){"use strict";let u=function(t){function o(o){var i;return(i=t.call(this,o)||this)._initialViewpoint=null,i._goingHomeController=null,i.go=i.go.bind(e._assertThisInitialized(i)),i}e._inheritsLoose(o,t);var n=o.prototype;return n.destroy=function(){this._cancelGo(),this.view=null},n.go=function(){var t=e._asyncToGenerator((function*(){if(!this.get("view.ready"))throw new i("home:disabled-state","Cannot go when disabled.");this._cancelGo(),this.emit("go");const e=new AbortController;this._goingHomeController=e;try{yield this.view.when(),yield this.callGoTo({target:this.viewpoint,options:{signal:e.signal}})}catch(t){}this._goingHomeController=null}));function o(){return t.apply(this,arguments)}return o}(),n.cancelGo=function(){this._cancelGo()},n._cancelGo=function(){const{_goingHomeController:e}=this;e&&e.abort(),this._goingHomeController=null},e._createClass(o,[{key:"state",get:function(){return this.get("view.ready")?this._goingHomeController?"going-home":"ready":"disabled"}},{key:"view",set:function(e){this._initialViewpoint=null,this._set("view",e),e&&e.when().then((()=>{this.view===e&&(this._initialViewpoint=e.viewpoint.clone(),this.notifyChange("viewpoint"))}))}},{key:"viewpoint",get:function(){return this._get("viewpoint")||this._initialViewpoint},set:function(e){this._set("viewpoint",e)}}]),o}(p.GoToMixin(n.EventedAccessor));t.__decorate([r.property()],u.prototype,"_goingHomeController",void 0),t.__decorate([r.property({readOnly:!0})],u.prototype,"state",null),t.__decorate([r.property()],u.prototype,"view",null),t.__decorate([r.property({type:o})],u.prototype,"viewpoint",null),t.__decorate([r.property()],u.prototype,"go",null),t.__decorate([r.property()],u.prototype,"cancelGo",null),u=t.__decorate([a.subclass("esri.widgets.Home.HomeViewModel")],u);return u}));
