import { c as a } from "../../chunks/runtime.js";
import { usePropertyChange as r } from "@arcgis/lumina/controllers";
import { watch as h } from "@geoscene/core/core/reactiveUtils.js";
import o from "@geoscene/core/layers/RouteLayer.js";
import d from "@geoscene/core/widgets/Directions.js";
import { LitElement as n, createEvent as l, noShadowRoot as w } from "@arcgis/lumina";
import { m } from "../../chunks/useWidget.js";
import { e as u } from "../../chunks/component-utils.js";
import { css as y } 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 c = y`@layer{geoscene-directions{display:block}}`, g = m(d), i = "map-components:geoscene-directions";
class p extends n {
  constructor() {
    super(...arguments), this.widget = g(this), this.viewModel = this.widget.viewModel, this.apiKey = this.widget.apiKey, this.autoDestroyDisabled = !1, this.goToOverride = this.widget.goToOverride, this.headingLevel = this.widget.headingLevel, this.hideLayerDetails = this.widget.visibleElements.layerDetails, this.hideSaveAsButton = this.widget.visibleElements.saveAsButton, this.hideSaveButton = this.widget.visibleElements.saveButton, this.icon = this.widget.icon, this.label = this.widget.label, this.lastRoute = this.widget.lastRoute, this.layer = this.widget.layer, this.maxStops = this.widget.maxStops, this.position = "bottom-left", this.searchProperties = this.widget.searchProperties, this.state = this.viewModel.state, this.unit = this.widget.unit, this.useDefaultRouteLayer = !1, this.geoscenePropertyChange = r()("lastRoute", "state"), this.geosceneReady = l();
  }
  static {
    this.properties = { apiKey: 1, autoDestroyDisabled: 5, goToOverride: 0, headingLevel: 9, hideLayerDetails: 5, hideSaveAsButton: 5, hideSaveButton: 5, icon: 1, label: 1, lastRoute: 0, layer: 0, maxStops: 9, position: 1, referenceElement: 1, routeLayerItemId: 1, searchProperties: 0, state: 3, unit: 1, useDefaultRouteLayer: 5 };
  }
  static {
    this.shadowRootOptions = w;
  }
  static {
    this.styles = c;
  }
  async destroy() {
    await this.manager.destroy();
  }
  async getDirections() {
    if (this.widget?.viewModel?.state !== "ready")
      throw new Error(`${i} - component not ready to get directions`);
    return await this.widget?.getDirections();
  }
  async save() {
    if (this.widget?.viewModel?.state !== "ready")
      throw new Error(`${i} - component not ready to save directions`);
    return await this.widget?.save();
  }
  async saveAs(e, t) {
    if (this.widget?.viewModel?.state !== "ready")
      throw new Error(`${i} - component not ready to save directions as a Portal Item`);
    return await this.widget?.saveAs(e, t);
  }
  async zoomToRoute() {
    if (this.widget?.viewModel?.state !== "ready")
      throw new Error(`${i} - component not ready to zoom to route`);
    this.widget?.zoomToRoute();
  }
  willUpdate(e) {
    if (e.has("routeLayerItemId")) {
      const t = this.routeLayerItemId;
      if (u(t) && !this.useDefaultRouteLayer) {
        const { layer: s } = this;
        s && this.widget.view?.map?.remove(s), this._setDefaultLayer();
      } else t && this.widget && (this.layer = new o({
        portalItem: {
          id: t
        }
      }), this.widget.view?.map?.add(this.layer));
    }
    e.has("useDefaultRouteLayer") && this._setDefaultLayer();
  }
  _setDefaultLayer() {
    this.useDefaultRouteLayer && !this.routeLayerItemId && (this.layer = new o(), h(() => this.widget.view, () => this.widget.view?.map?.add(this.layer), { once: !0 }));
  }
}
a("geoscene-directions", p);
export {
  p as GeosceneDirections
};