/*
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","../../core/Accessor","../../core/Handles","../../core/maybe","../../core/reactiveUtils","../../core/accessorSupport/decorators/property","../../core/arrayUtils","../../core/has","../../core/accessorSupport/ensureType","../../core/accessorSupport/decorators/subclass","../support/GoTo"],(function(t,e,o,i,r,a,n,s,c,d,l,h){"use strict";const p="esri.widgets.CompassViewModel";let u=function(e){function o(o){var r;return(r=e.call(this,o)||this)._handles=new i,r.orientation={x:0,y:0,z:0},r.view=null,r._updateForCamera=r._updateForCamera.bind(t._assertThisInitialized(r)),r._updateForRotation=r._updateForRotation.bind(t._assertThisInitialized(r)),r._updateRotationWatcher=r._updateRotationWatcher.bind(t._assertThisInitialized(r)),r}t._inheritsLoose(o,e);var n=o.prototype;return n.initialize=function(){this._handles.add(a.watch((()=>this.view),this._updateRotationWatcher,a.initial))},n.destroy=function(){this._handles=r.removeMaybe(this._handles),this.view=null},n.reset=function(){if(!this.get("view.ready"))return;const t={};"2d"===this.view.type?t.rotation=0:t.heading=0,this.callGoTo({target:t})},n._updateForRotation=function(t){null!=t&&(this.orientation={z:t})},n._updateForCamera=function(t){if(!t)return;const e=-t.heading;this.orientation={x:0,y:0,z:e}},n._updateRotationWatcher=function(t){this._handles.removeAll(),t&&this._handles.add("2d"===t.type?a.watch((()=>null==t?void 0:t.rotation),this._updateForRotation,a.initial):a.watch((()=>null==t?void 0:t.camera),this._updateForCamera,a.initial))},t._createClass(o,[{key:"canShowNorth",get:function(){const t=this.get("view.spatialReference");return!(!t||!t.isWebMercator&&!t.isGeographic)}},{key:"state",get:function(){return this.get("view.ready")?this.canShowNorth?"compass":"rotation":"disabled"}}]),o}(h.GoToMixin(o));e.__decorate([n.property({readOnly:!0})],u.prototype,"canShowNorth",null),e.__decorate([n.property()],u.prototype,"orientation",void 0),e.__decorate([n.property({readOnly:!0})],u.prototype,"state",null),e.__decorate([n.property()],u.prototype,"view",void 0),u=e.__decorate([l.subclass(p)],u);return u}));
