import { c as p } from "../../chunks/runtime.js";
import { html as g } from "lit-html";
import { LitElement as v, createEvent as f, noShadowRoot as w, nothing as D, safeClassMap as b } from "@arcgis/lumina";
import { usePropertyChange as M } from "@arcgis/lumina/controllers";
import { u as O } from "../../chunks/useT9n.js";
import { m as U } from "../../chunks/useViewModel.js";
import { g as d } from "../../chunks/globalCss.js";
import { css as $ } from "@lit/reactive-element/css-tag.js";
import L from "@geoscene/core/analysis/DirectLineMeasurementAnalysis.js";
import { isAboveGeodesicDistanceThreshold as _ } from "@geoscene/core/applications/Components/analysisUtils.js";
import { getDefaultUnitForView as V } from "@geoscene/core/applications/Components/getDefaultUnits.js";
import { property as o, subclass as P } from "@geoscene/core/core/accessorSupport/decorators.js";
import { watch as A } from "@geoscene/core/core/reactiveUtils.js";
import { A as C } from "../../chunks/AnalysisViewModel.js";
import { g as c, m } from "../../chunks/measurementUtils.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 z = $`@layer{geoscene-directline-measurement-3d,geoscene-direct-line-measurement-3d{display:block}.geoscene-direct-line-measurement-3d{position:relative;padding:var(--geoscene-widget-padding);overflow-y:auto}}`;
var S = Object.defineProperty, E = Object.getOwnPropertyDescriptor, r = (e, t, s, a) => {
  for (var n = a > 1 ? void 0 : a ? E(t, s) : t, l = e.length - 1, u; l >= 0; l--)
    (u = e[l]) && (n = (a ? u(t, s, n) : u(n)) || n);
  return a && n && S(t, s, n), n;
};
let i = class extends C {
  constructor() {
    super(...arguments), this.supportedViewType = "3d", this.unsupportedErrorMessage = "The Direct Line Measurement 3D component is only supported in 3D views.";
  }
  initialize() {
    this.addHandles(
      // Make sure the analysis and view model units are in sync.
      A(
        () => ({
          analysis: this.analysis,
          unit: this.unit
        }),
        ({ analysis: e, unit: t }) => {
          e != null && (e.unit = t);
        },
        { sync: !0, initial: !0 }
      )
    );
  }
  get state() {
    return this.disabled || !this.ready ? "disabled" : this.operationState === "inactive" ? this.analysis.valid ? "measured" : "ready" : "measuring";
  }
  get displayState() {
    if (!this.supported)
      return "unsupported";
    switch (this.state) {
      case "disabled":
      case "ready":
        return "ready";
      case "measuring":
        return this.analysis.startPoint == null ? "measuring" : "measured";
      case "measured":
        return "measured";
    }
  }
  get measurement() {
    const e = this.analysisView?.result, t = e?.mode ?? "euclidean";
    if (!this.analysis.valid)
      return {
        mode: t,
        directDistance: c(void 0),
        horizontalDistance: c(void 0),
        verticalDistance: c(void 0)
      };
    const s = e?.directDistance, a = s != null && _(s);
    return {
      mode: t ?? "euclidean",
      directDistance: c(a ? void 0 : s),
      horizontalDistance: c(e?.horizontalDistance),
      verticalDistance: c(e?.verticalDistance)
    };
  }
  get unitOptions() {
    const e = this._userUnitOptions?.filter((t) => m.includes(t));
    return e && e.length > 0 ? e : m.slice();
  }
  set unitOptions(e) {
    this._userUnitOptions = e;
  }
  get unit() {
    const e = this._userUnit, t = this.unitOptions;
    if (e && t.includes(e))
      return e;
    const s = this.defaultUnit;
    return s && t.includes(s) ? s : t[0];
  }
  set unit(e) {
    this._userUnit = e;
  }
  get defaultUnit() {
    return this.view ? V(this.view) : void 0;
  }
  async place(e) {
    await this.analysisView?.place(e);
  }
  clearAnalysis() {
    this.analysis.startPoint = null, this.analysis.endPoint = null;
  }
  constructAnalysis() {
    return new L();
  }
};
r([
  o({ readOnly: !0 })
], i.prototype, "state", 1);
r([
  o({ readOnly: !0 })
], i.prototype, "displayState", 1);
r([
  o({ readOnly: !0 })
], i.prototype, "measurement", 1);
r([
  o()
], i.prototype, "unitOptions", 1);
r([
  o()
], i.prototype, "_userUnitOptions", 2);
r([
  o()
], i.prototype, "unit", 1);
r([
  o()
], i.prototype, "_userUnit", 2);
r([
  o({ readOnly: !0 })
], i.prototype, "defaultUnit", 1);
i = r([
  P("components.direct-line-measurement-3d.DirectLineMeasurement3dViewModel")
], i);
const x = "geoscene-direct-line-measurement-3d", T = { base: x }, R = U(i);
class h extends v {
  constructor() {
    super(...arguments), this.viewModel = R(this), this.messages = O({ name: "directline-measurement-3d", blocking: !0 }), this.analysis = this.viewModel.analysis, this.autoDestroyDisabled = !1, this.icon = "measure-line", this.position = "bottom-left", this.state = this.viewModel.state, this.unit = this.viewModel.unit, this.unitOptions = this.viewModel.unitOptions, this.geoscenePropertyChange = M()("analysis", "state"), this.geosceneReady = f();
  }
  static {
    this.properties = { analysis: 0, autoDestroyDisabled: 5, icon: 3, label: 1, position: 1, referenceElement: 1, state: 35, unit: 1, unitOptions: 0 };
  }
  static {
    this.shadowRootOptions = w;
  }
  static {
    this.styles = z;
  }
  async clear() {
    this.viewModel.clear();
  }
  async destroy() {
    await this.manager.destroy();
  }
  async start() {
    await this.viewModel.start();
  }
  render() {
    const { messages: t, unit: s, unitOptions: a, viewModel: n } = this, { measurement: l, state: u } = n;
    return g`<div aria-label=${t.componentLabel ?? D} class=${b({
      [T.base]: !0,
      [d.widget]: !0,
      [d.panel]: !0
    })} role=presentation><geoscene-measurement-content .state=${n.displayState} .hintLabel=${t.hint} .unsupportedLabel=${t.unsupported} .items=${[
      {
        title: t.direct,
        measurement: l.directDistance
      },
      {
        title: t.horizontal,
        measurement: l.horizontalDistance
      },
      {
        title: t.vertical,
        measurement: l.verticalDistance
      }
    ]}><geoscene-unit-select slot=settings .options=${a} .selectLabel=${t.unit} .value=${s} @geosceneUnitSelectChange=${(y) => {
      this.unit = y.detail;
    }}></geoscene-unit-select><calcite-button slot=actions .disabled=${u === "disabled"} @click=${() => {
      this.viewModel.clear(), this.viewModel.start();
    }}>${t.newMeasurement}</calcite-button></geoscene-measurement-content></div>`;
  }
}
class j extends h {
  constructor() {
    super(), console.warn('geoscene-directline-measurement-3d - this component is deprecated. Use the "geoscene-direct-line-measurement-3d" component instead.');
  }
}
p("geoscene-direct-line-measurement-3d", h);
p("geoscene-directline-measurement-3d", j);
export {
  h as GeosceneDirectLineMeasurement3d,
  j as DeprecatedGeosceneDirectLineMeasurement3d
};