/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.24/esri/copyright.txt for details. */ import{_ as t}from"../../chunks/tslib.es6.js";import o from"../../core/Accessor.js";import e from"../../core/Handles.js";import{removeMaybe as r}from"../../core/maybe.js";import{watch as s,initial as i}from"../../core/reactiveUtils.js";import{property as a}from"../../core/accessorSupport/decorators/property.js";import"../../core/arrayUtils.js";import"../../core/has.js";import"../../core/accessorSupport/ensureType.js";import{subclass as n}from"../../core/accessorSupport/decorators/subclass.js";import{GoToMixin as h}from"../support/GoTo.js";const p="esri.widgets.CompassViewModel";let d=class extends(h(o)){constructor(t){super(t),this._handles=new e,this.orientation={x:0,y:0,z:0},this.view=null,this._updateForCamera=this._updateForCamera.bind(this),this._updateForRotation=this._updateForRotation.bind(this),this._updateRotationWatcher=this._updateRotationWatcher.bind(this)}initialize(){this._handles.add(s((()=>this.view),this._updateRotationWatcher,i))}destroy(){this._handles=r(this._handles),this.view=null}get canShowNorth(){const t=this.get("view.spatialReference");return!(!t||!t.isWebMercator&&!t.isGeographic)}get state(){return this.get("view.ready")?this.canShowNorth?"compass":"rotation":"disabled"}reset(){if(!this.get("view.ready"))return;const t={};"2d"===this.view.type?t.rotation=0:t.heading=0,this.callGoTo({target:t})}_updateForRotation(t){null!=t&&(this.orientation={z:t})}_updateForCamera(t){if(!t)return;const o=-t.heading;this.orientation={x:0,y:0,z:o}}_updateRotationWatcher(t){this._handles.removeAll(),t&&this._handles.add("2d"===t.type?s((()=>t?.rotation),this._updateForRotation,i):s((()=>t?.camera),this._updateForCamera,i))}};t([a({readOnly:!0})],d.prototype,"canShowNorth",null),t([a()],d.prototype,"orientation",void 0),t([a({readOnly:!0})],d.prototype,"state",null),t([a()],d.prototype,"view",void 0),d=t([n(p)],d);const c=d;export{c as default};