import { c as g } from "../../chunks/runtime.js";
import { css as v, html as e } from "lit";
import { usePropertyChange as p } from "@arcgis/lumina/controllers";
import { reEmitEvent as a } from "@arcgis/lumina/controllers/accessor";
import { classes as u } from "@arcgis/toolkit/dom";
import m from "@arcgis/core/widgets/Track/TrackViewModel.js";
import { LitElement as w, createEvent as f, safeClassMap as b, nothing as M } from "@arcgis/lumina";
import { u as k } from "../../chunks/useT9n.js";
import { m as E } from "../../chunks/useViewModel.js";
/*! All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.34/esri/copyright.txt for details.
v4.34.7 */
const x = v`.arcgis-button{--calcite-icon-color: var(--calcite-color-text-3);--calcite-button-background-color: var(--calcite-color-foreground-1);color:var(--calcite-color-text-3);line-height:var(--calcite-font-line-height-relative-tight);display:flex;flex-flow:column;cursor:pointer;background-color:var(--calcite-color-foreground-1);font-size:var(--calcite-font-size);:hover{--calcite-icon-color: var(--calcite-color-text-1);--calcite-button-background-color: var(--calcite-color-transparent-hover)}calcite-button{width:var(--calcite-spacing-xxxl);height:var(--calcite-spacing-xxxl)}}:host{width:var(--calcite-spacing-xxxl);height:var(--calcite-spacing-xxxl)}`, c = {
  base: "track",
  button: "arcgis-button"
}, T = E(m);
class y extends w {
  constructor() {
    super(...arguments), this.messages = k(), this.viewModel = T(this), this.view = this.viewModel.view, this.autoDestroyDisabled = !1, this.error = this.viewModel.error, this.geolocationOptions = this.viewModel.geolocationOptions, this.goToOverride = this.viewModel.goToOverride, this.goToLocationDisabled = this.viewModel.goToLocationEnabled, this.graphic = this.viewModel.graphic, this.icon = "compass-north-circle", this.positionFilterFunction = this.viewModel.positionFilterFunction, this.rotationDisabled = this.viewModel.rotationEnabled, this.scale = this.viewModel.scale, this.state = this.viewModel.state, this.tracking = this.viewModel.tracking, this.arcgisComplete = a(() => this.viewModel, "track"), this.arcgisError = a(() => this.viewModel, "track-error"), this.arcgisPropertyChange = p()("state"), this.arcgisReady = f();
  }
  static {
    this.properties = { view: 0, autoDestroyDisabled: 5, error: 1, geolocationOptions: 1, goToOverride: 0, goToLocationDisabled: 7, graphic: 0, icon: 1, label: 1, messageOverrides: 0, position: 3, positionFilterFunction: 0, referenceElement: 1, rotationDisabled: 5, scale: 9, state: 3, tracking: 4 };
  }
  static {
    this.styles = x;
  }
  async destroy() {
    await this.manager.destroy();
  }
  async start() {
    this.viewModel.start();
  }
  async stop() {
    this.viewModel.stop();
  }
  _localizeError(t) {
    if (t instanceof GeolocationPositionError)
      return t.code === GeolocationPositionError.PERMISSION_DENIED ? this.messages?.permissionError : t.code === GeolocationPositionError.TIMEOUT ? this.messages?.timeoutError : this.messages?.positionUnavailable;
    if (t instanceof Error)
      return t.message;
  }
  _toggleTracking() {
    if (!this.viewModel)
      return;
    const { state: t } = this.viewModel;
    if (!(t === "feature-unsupported" || t === "disabled")) {
      if (t === "tracking" || t === "waiting") {
        this.viewModel.stop();
        return;
      }
      this.viewModel.start();
    }
  }
  render() {
    const { viewModel: t, messages: o, icon: n } = this, i = t?.state, l = i === "tracking", s = this._localizeError(this.viewModel?.error), r = (l ? o?.stopTracking : o?.startTracking) ?? "", h = i === "feature-unsupported", d = (i === "tracking" ? "pause" : void 0) ?? n ?? void 0;
    return e`<div class=${b(u(c.base, c.button))}>${!h && e`<calcite-button .disabled=${i === "disabled"} .iconStart=${d} kind=neutral .label=${r} .loading=${i === "waiting"} @click=${this._toggleTracking} title=${r ?? M}></calcite-button>` || ""}${s ? e`<calcite-tooltip open overlay-positioning=fixed .referenceElement=${this.el}>${s}</calcite-tooltip>` : null}</div>`;
  }
}
g("arcgis-track", y);
export {
  y as ArcgisTrack
};
