import { c as p } from "../../chunks/runtime.js";
import { html as e } from "lit-html";
import { usePropertyChange as m } from "@arcgis/lumina/controllers";
import { reEmitEvent as a } from "@arcgis/lumina/controllers/accessor";
import { classes as u } from "@arcgis/components-utils";
import v from "@geoscene/core/widgets/Track/TrackViewModel.js";
import { LitElement as w, createEvent as f, noShadowRoot as M, safeClassMap as n, nothing as k } from "@arcgis/lumina";
import { u as E } from "../../chunks/useT9n.js";
import { m as b } from "../../chunks/useViewModel.js";
import { g as c } from "../../chunks/globalCss.js";
import { css as T } from "@lit/reactive-element/css-tag.js";
/*! All material copyright GeoScene, All Rights Reserved, unless otherwise specified.
See https://js.geoscene.cn/4.33/geoscene/copyright.txt for details.
v4.33.18 */
const y = T`@layer{geoscene-track{display:block}}`, $ = {
  base: "geoscene-track"
}, D = b(v);
class O extends w {
  constructor() {
    super(...arguments), this.messages = E(), this.viewModel = D(this), 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.position = "top-left", 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.geosceneComplete = a(() => this.viewModel, "track"), this.geosceneError = a(() => this.viewModel, "track-error"), this.geoscenePropertyChange = m()("state"), this.geosceneReady = f();
  }
  static {
    this.properties = { 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.shadowRootOptions = M;
  }
  static {
    this.styles = y;
  }
  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: l } = this, i = t?.state, d = i === "tracking", s = this._localizeError(this.viewModel?.error), r = (d ? o?.stopTracking : o?.startTracking) ?? "", h = i === "feature-unsupported", g = (i === "tracking" ? "pause" : void 0) ?? l ?? void 0;
    return e`<div class=${n(u($.base, c.widget))}>${!h && e`<calcite-button class=${n(c.widgetButton)} .disabled=${i === "disabled"} .iconStart=${g} kind=neutral .label=${r} .loading=${i === "waiting"} @click=${this._toggleTracking} title=${r ?? k}></calcite-button>` || ""}${s ? e`<calcite-tooltip open overlay-positioning=fixed .referenceElement=${this.el}>${s}</calcite-tooltip>` : null}</div>`;
  }
}
p("geoscene-track", O);
export {
  O as GeosceneTrack
};