/* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
import { c as C } from "../../chunks/runtime.js";
import { css as S, html as c } from "lit";
import { ref as U } from "lit/directives/ref.js";
import { createChart as k } from "@arcgis/core/applications/Components/analysisUtils.js";
import { ignoreAbortErrors as m } from "@arcgis/core/core/promiseUtils.js";
import { watch as p } from "@arcgis/core/core/reactiveUtils.js";
import { LitElement as M, createEvent as B, nothing as u, safeClassMap as v } from "@arcgis/lumina";
import { usePropertyChange as O } from "@arcgis/lumina/controllers";
import { slotChangeHasContent as _ } from "@arcgis/toolkit/dom";
import { u as D } from "../../chunks/useT9n.js";
import { m as $ } from "../../chunks/useViewModel.js";
import { t as V, c as x } from "../../chunks/async-utils.js";
import { g as f } from "../../chunks/globalCss.js";
import P from "@arcgis/core/analysis/ElevationProfileAnalysis.js";
import { property as a, subclass as z } from "@arcgis/core/core/accessorSupport/decorators.js";
import { A as E } from "../../chunks/AnalysisViewModel.js";
import { a as A } from "../../chunks/maybe.js";
import { c as y, d as w } from "../../chunks/measurementUtils.js";
import { m as F } from "../../chunks/handle.js";
const L = S`.esri-widget__heading{color:var(--calcite-color-text-2);margin:0 0 .5rem;font-weight:var(--calcite-font-weight-semibold)}h1.esri-widget__heading{font-size:var(--calcite-font-size-xl)}h2.esri-widget__heading{font-size:var(--calcite-font-size-md)}h3.esri-widget__heading,h4.esri-widget__heading,h5.esri-widget__heading,h6.esri-widget__heading{font-size:var(--calcite-font-size)}.esri-widget{box-sizing:border-box;color:var(--calcite-color-text-2);background-color:var(--calcite-color-foreground-1);font-size:var(--calcite-font-size);line-height:var(--calcite-font-line-height-relative-tight)}.esri-widget *,.esri-widget :before,.esri-widget :after{box-sizing:inherit}.esri-widget.esri-widget--disabled>*{opacity:.4;pointer-events:none}.esri-widget.esri-widget--compact{--esri-widget-padding-y: 0;--esri-widget-padding-x: 0}.esri-widget__anchor{color:var(--calcite-color-text-2)}.esri-widget__anchor:hover{color:var(--calcite-color-text-3)}.esri-widget__anchor:hover,.esri-widget__anchor:focus{text-decoration:underline}.esri-widget__anchor--disabled{opacity:.4;pointer-events:none}.esri-widget__header{background-color:var(--calcite-color-foreground-1);flex:1 0 100%;justify-content:space-between;align-items:center;width:100%;min-height:48px;padding:12px 0 12px 15px;display:flex}.esri-widget__heading{word-break:break-word}.esri-widget__header .esri-widget__heading{width:calc(100% - 48px);text-align:initial;color:var(--calcite-color-text-1);align-items:center;margin:0;padding:0;display:flex}.esri-widget__header-button{appearance:none;cursor:pointer;color:var(--calcite-color-text-2);background-color:var(--calcite-color-foreground-1);border:none;flex:0 0 48px;justify-content:center;align-self:stretch;align-items:center;width:48px;padding:0;display:flex}.esri-widget__footer{background-color:var(--calcite-color-foreground-1);justify-content:center;align-items:center;width:100%;min-height:48px;display:flex}.esri-widget__footer-pagination{color:var(--calcite-color-text-2);justify-content:space-between;align-items:center;display:flex}.esri-widget__footer-pagination-previous-button,.esri-widget__footer-pagination-next-button{cursor:pointer;background-color:var(--calcite-color-foreground-1);border:0;margin:0 7px;padding:12px 15px;transition:background-color .125s ease-in-out}.esri-widget__footer-pagination-previous-button:hover,.esri-widget__footer-pagination-previous-button:focus,.esri-widget__footer-pagination-next-button:hover,.esri-widget__footer-pagination-next-button:focus{color:var(--calcite-color-text-1);background-color:var(--calcite-color-foreground-1)}.esri-menu{visibility:hidden;z-index:1;background-clip:padding;background-color:var(--calcite-color-foreground-1);background-clip:padding-box;width:100%;max-height:0;margin:2px 0 0;padding:0;font-size:var(--calcite-font-size);line-height:var(--calcite-spacing-xl);position:absolute;top:100%;left:0;overflow:hidden;box-shadow:0 1px 2px #0000004d}.esri-menu .esri-menu__header{color:var(--calcite-color-text-inverse);background-color:var(--calcite-color-inverse);padding:6px 12px}.esri-menu__list{margin:0;padding:0;list-style:none}.esri-menu__list-item{cursor:pointer;border-top:1px solid #adadad4d;border-left:3px solid #0000;padding:.8em 1em}.esri-menu__list-item [class^=esri-icon-],.esri-menu__list-item [class*=" esri-icon-"]{padding-right:2.8px}.esri-menu__list-item:first-child{border-top:none}.esri-menu__list-item--focus,.esri-menu__list-item:hover,.esri-menu__list-item:focus{background-color:var(--calcite-color-foreground-1)}.esri-menu__list-item:active{background-color:var(--calcite-color-foreground-current)}.esri-menu__list-item--active,.esri-menu__list-item--active:hover,.esri-menu__list-item--active:focus{background-color:var(--calcite-color-foreground-1);border-left-color:var(--calcite-color-brand)}.esri-widget__table{border-collapse:collapse;color:var(--calcite-color-text-1);border:none;width:100%;line-height:var(--calcite-font-line-height-relative-tight)}.esri-widget__table tr:nth-child(odd){background-color:var(--calcite-color-transparent)}.esri-widget__table tr:nth-child(2n){background-color:var(--calcite-color-transparent-press)}.esri-widget__table tr a{color:var(--calcite-color-text-2)}.esri-widget__table tr a:hover,.esri-widget__table tr a:focus{color:var(--calcite-color-text-1)}.esri-widget__table tr td,.esri-widget__table tr th{vertical-align:top;word-break:break-word;padding:.5em .7em;font-size:var(--calcite-font-size-sm);font-weight:var(--calcite-font-weight-regular)}.esri-widget__table tr th{text-align:left;border-right:3px solid #0000000d;width:50%}.esri-widget__table tr td{width:50%}.esri-input{color:var(--calcite-color-text-1);background-color:var(--calcite-color-foreground-1);border:1px solid #959595;font-size:var(--calcite-font-size)}.esri-input::-ms-clear{display:none}.esri-input::placeholder{opacity:1;color:var(--calcite-color-text-2)}.esri-input:placeholder-shown{text-overflow:ellipsis}.esri-input[type=text],.esri-input[type=password],.esri-input[type=number]{height:32px;padding:0 .5em}calcite-combobox.esri-input{border:none}.esri-widget__content--empty{text-align:center;color:var(--calcite-color-border-input);flex-flow:column wrap;align-items:center;padding:18px 22px;display:flex}.esri-widget__content--empty h1.esri-widget__heading,.esri-widget__content--empty h2.esri-widget__heading,.esri-widget__content--empty h3.esri-widget__heading,.esri-widget__content--empty h4.esri-widget__heading,.esri-widget__content--empty h5.esri-widget__heading{font-weight:var(--calcite-font-weight-regular)}.esri-widget__content-illustration--empty{width:128px;padding:1rem 0}.esri-widget__content-icon--empty{width:32px;padding:.5rem 0}.esri-select{appearance:none;cursor:pointer;color:var(--calcite-color-text-2);background:var(--calcite-color-foreground-1) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='-8 -8 32 32' width='32' height='32'%3E%3Cpath d='M8 11.207l-4-4V5.793l4 4 4-4v1.414z' fill='%23adadad' fillrule='nonzero'/%3E%3C/svg%3E") 100% no-repeat;border:1px solid #959595;border-radius:0;width:100%;height:32px;margin:0;padding:0 .5em;font-family:inherit;font-size:.85em;display:block}.esri-select[disabled]{cursor:auto}.esri-select::-ms-expand{display:none}.esri-disabled a,.esri-disabled [role=menu],.esri-disabled [role=checkbox],.esri-disabled [class^=esri-icon-],.esri-disabled [class*=" esri-icon-"]{color:var(--calcite-color-text-3)}.keynav-mode .esri-widget:focus,.keynav-mode .esri-widget :focus{z-index:1;outline-offset:2px;outline:2px solid #adadad}.esri-widget__loader-animation{border:.15em solid #adadad4d;border-top-color:var(--calcite-color-border-input);border-radius:100%;width:1em;height:1em;font-size:var(--calcite-font-size-md);animation:1.25s linear infinite esri-rotate;display:block;transform:translateZ(0)}:dir(rtl) .esri-widget__table th{text-align:right;border-left:3px solid #0000000d;border-right:none}:dir(rtl) .esri-select{background-position:0}:dir(rtl) .esri-menu__list-item{border-left:none;border-right:3px solid #0000}:dir(rtl) .esri-menu__list-item [class^=esri-icon-],:dir(rtl) .esri-menu__list-item [class*=" esri-icon-"]{padding-left:2px;padding-right:0}:dir(rtl) .esri-menu__list-item--active{border-right-color:var(--calcite-color-brand)}.esri-icon-font-fallback-text{clip:rect(0 0 0 0);width:1px;height:1px;position:absolute;overflow:hidden}.esri-rotating{animation:1.25s linear infinite esri-rotate;transform:translateZ(0)}.esri-clearfix:before,.esri-clearfix:after{content:" ";display:table}.esri-clearfix:after{clear:both}.esri-interactive{cursor:pointer}.esri-hidden{display:none!important}.esri-invisible{visibility:hidden!important}.esri-offscreen{position:absolute;top:-999em;left:-999em}.esri-match-height{flex-direction:column;flex:auto;display:flex;overflow:hidden}.esri-widget--panel{min-width:300px;min-height:32px;padding:var(--arcgis-internal-padding);transition:max-height .25s ease-in-out;overflow-y:auto}:host{--internal-chart-height: 180px;--internal-gap: var(--calcite-spacing-sm-plus);width:550px;isolation:isolate;position:relative;container-type:inline-size}.root{display:flex;flex-direction:column;width:100%;min-width:0;gap:var(--internal-gap)}.header{display:flex;flex-direction:row;align-items:center;justify-content:flex-end;margin-bottom:calc(var(--internal-gap) * -1)}.actions{display:flex;flex-wrap:wrap;align-items:center;justify-content:flex-end;gap:var(--calcite-spacing-xs)}.action-button{width:auto;min-height:32px}.main-container{display:flex;position:relative;flex-flow:column;width:100%;height:var(--internal-chart-height)}.chart-container{position:relative;width:100%;height:100%}.prompt-container{box-sizing:border-box;display:grid;place-content:center;padding-inline:var(--calcite-spacing-md);height:100%;text-align:center}.prompt-message{margin:0;width:100%}.spinner{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);transition:opacity .15s ease-in-out;transition-delay:0;opacity:0;&.visible{transition-delay:50ms;opacity:1}&.small{inset-inline-start:0;inset-block-start:-24px;left:unset;transform:none;color:var(--calcite-color-brand)}}@container (max-width: 400px){.esri-widget--panel{height:auto}.actions{flex-direction:column}.action-button{align-self:stretch}}`;
async function I(t, e, i) {
  const r = await T(t, e);
  return V(i), R(r) ? r.highlight(e) : F();
}
async function T(t, e) {
  const i = e?.layer;
  if (!(!i || i.type === "subtype-sublayer" || i.type === "sublayer" || i.type === "building-component"))
    return await t.whenLayerView(i);
}
function R(t) {
  return t != null && "highlight" in t && typeof t.highlight == "function";
}
function H({ geometry: t }) {
  return t?.type === "polyline" && t.paths.length > 0 && t.paths.every((e) => e.length >= 2);
}
function Z({ geometry: t }) {
  return t?.type === "polyline" && t.paths.reduce((e, i) => e + i.length, 0) > 0;
}
function j(t) {
  return t?.samples?.some((e) => e.z != null) ?? !1;
}
function G(t) {
  return t?.type === "polyline";
}
var q = Object.defineProperty, N = Object.getOwnPropertyDescriptor, o = (t, e, i, r) => {
  for (var s = r > 1 ? void 0 : r ? N(e, i) : e, l = t.length - 1, d; l >= 0; l--)
    (d = t[l]) && (s = (r ? d(e, i, s) : d(s)) || s);
  return r && s && q(e, i, s), s;
};
let n = class extends E {
  constructor() {
    super(...arguments), this.highlightDisabled = !1, this.uniformChartScaling = !1, this.shouldForceInteractive = !1, this.supportedViewType = "both", this.unsupportedErrorMessage = "";
  }
  get _hasSamples() {
    const { progress: t } = this;
    return !!this.analysisView?.results?.some(
      (e) => e.available && (t < 1 || j(e))
    );
  }
  get doneButtonAvailable() {
    if (this.featureIsSelected)
      return !1;
    const { geometry: t } = this.analysis;
    return G(t) && t.paths.length > 0 && t.paths[0].length > 2;
  }
  get effectiveDisplayUnits() {
    return this.analysisView?.effectiveDisplayUnits;
  }
  get errorState() {
    if (!H(this.analysis))
      return "no-valid-input";
    const t = this.analysisView?.error;
    if (t)
      switch (t.name) {
        case "too-complex":
          return "too-complex";
        case "elevation-query-error":
          return "no-valid-input";
        default:
          return "unknown";
      }
    return this._hasSamples ? "none" : "no-available-profiles";
  }
  get feature() {
    return this._selectedFeature;
  }
  set feature(t) {
    t ? t !== this.feature && (this.analysis.setGeometryFromFeature(t), this._selectedFeature = t) : this._selectedFeature = void 0;
  }
  get featureIsSelected() {
    return this.feature != null;
  }
  get hasVertices() {
    return Z(this.analysis);
  }
  get indicatorRelativePosition() {
    return this.analysisView?.indicatorRelativePosition ?? void 0;
  }
  get geometry() {
    return this.analysis.geometry;
  }
  set geometry(t) {
    this.analysis.geometry = t;
  }
  get elevationInfo() {
    return this.analysis.elevationInfo;
  }
  set elevationInfo(t) {
    this.analysis.elevationInfo = t;
  }
  get profiles() {
    return this.analysis.profiles;
  }
  set profiles(t) {
    this.analysis.profiles = t;
  }
  get progress() {
    return this.analysisView?.progress ?? 0;
  }
  get results() {
    return this.analysisView?.results ?? [];
  }
  get selectButtonAvailable() {
    for (const t of this.view?.map?.allLayers.toArray() ?? [])
      if (t.type === "graphics" && !("internal" in t && t.internal) && t.graphics.some((e) => e.geometry?.type === "polyline") || "geometryType" in t && t.geometryType === "polyline")
        return !0;
    return !!this.view?.graphics?.some((t) => t.geometry?.type === "polyline");
  }
  get state() {
    return this.disabled || !this.ready ? "disabled" : this._selectingPromise ? "selecting" : this.operationState === "active" ? "creating" : this.analysis.valid ? this.featureIsSelected ? "selected" : "created" : "ready";
  }
  get distanceUnit() {
    return y(
      this._userDistanceUnit,
      this.analysis.displayUnits?.distance,
      this.distanceUnitOptions,
      this.defaultMeasurementSystem
    );
  }
  set distanceUnit(t) {
    this._userDistanceUnit = t;
  }
  get distanceUnitOptions() {
    return b(this._userDistanceUnitOptions);
  }
  set distanceUnitOptions(t) {
    this._userDistanceUnitOptions = t;
  }
  get elevationUnit() {
    return y(
      this._userElevationUnit,
      this.analysis.displayUnits?.elevation,
      this.elevationUnitOptions,
      this.defaultMeasurementSystem
    );
  }
  set elevationUnit(t) {
    this._userElevationUnit = t;
  }
  get elevationUnitOptions() {
    return b(this._userElevationUnitOptions);
  }
  set elevationUnitOptions(t) {
    this._userElevationUnitOptions = t;
  }
  //#endregion
  //#region Public Methods
  initialize() {
    this.addHandles([
      p(
        () => ({
          analysis: this.analysis,
          unitDistance: this._userDistanceUnit,
          unitElevation: this._userElevationUnit
        }),
        ({ analysis: t, unitDistance: e, unitElevation: i }) => {
          i && (t.displayUnits.elevation = i), e && (t.displayUnits.distance = e);
        },
        { sync: !0, initial: !0 }
      ),
      p(
        () => ({
          selectedFeature: this.feature,
          profiles: this.analysis.profiles.toArray()
        }),
        ({ selectedFeature: t, profiles: e }, i) => {
          this._highlightSelectedFeature(this.highlightDisabled ? void 0 : t), this.analysis.viewOptions.geometryVisualizationVisible = !this.highlightDisabled && t == null;
          const r = i?.selectedFeature;
          e.forEach((s) => {
            switch (s.type) {
              case "scene":
                this._excludeSelectedFeatureFromProfile(s, t, r);
                break;
              case "input":
                s.chartOptions.lineVisible = t != null, s.viewOptions.lineVisible = t != null;
                break;
            }
          });
        },
        { initial: !0 }
      )
    ]);
  }
  destroy() {
    this._removeSelectionHighlight();
  }
  async select() {
    const t = this.analysisView;
    if (!t)
      return;
    this.clear();
    const e = super.start({
      operation: async (i) => {
        const r = await t.pickFeature(i);
        i?.signal?.aborted || (t.interactive = !1, this.feature = r.feature);
      },
      clear: !1
    });
    e.finally(() => {
      this._selectingPromise === e && (this._selectingPromise = void 0);
    }), this._selectingPromise = e, await e.catch(() => {
    });
  }
  async place(t) {
    await this.analysisView?.place(t);
  }
  clearAnalysis() {
    this.geometry = null, this.elevationInfo = null, this.feature = void 0;
  }
  // Should never happen because both 2d and 3d are supported
  constructAnalysis() {
    return new P();
  }
  _highlightSelectedFeature(t) {
    this._removeSelectionHighlight();
    const e = this.view;
    !e || !t || (this._selectionHighlightTask = x(
      async (i) => await I(e, t, { signal: i })
    ));
  }
  _removeSelectionHighlight() {
    this._selectionHighlightTask?.value?.remove(), this._selectionHighlightTask = A(this._selectionHighlightTask);
  }
  _excludeSelectedFeatureFromProfile(t, e, i) {
    const r = new Set(t.exclude ?? []);
    i && r.delete(i), e && r.add(e), t.exclude = Array.from(r);
  }
  //#endregion
};
o([
  a()
], n.prototype, "_userDistanceUnit", 2);
o([
  a()
], n.prototype, "_userDistanceUnitOptions", 2);
o([
  a()
], n.prototype, "_userElevationUnit", 2);
o([
  a()
], n.prototype, "_userElevationUnitOptions", 2);
o([
  a()
], n.prototype, "_selectingPromise", 2);
o([
  a()
], n.prototype, "_selectedFeature", 2);
o([
  a()
], n.prototype, "_selectionHighlightTask", 2);
o([
  a()
], n.prototype, "_hasSamples", 1);
o([
  a()
], n.prototype, "doneButtonAvailable", 1);
o([
  a({ readOnly: !0 })
], n.prototype, "effectiveDisplayUnits", 1);
o([
  a({ readOnly: !0 })
], n.prototype, "errorState", 1);
o([
  a()
], n.prototype, "feature", 1);
o([
  a()
], n.prototype, "featureIsSelected", 1);
o([
  a({ readOnly: !0 })
], n.prototype, "hasVertices", 1);
o([
  a()
], n.prototype, "highlightDisabled", 2);
o([
  a()
], n.prototype, "indicatorRelativePosition", 1);
o([
  a()
], n.prototype, "geometry", 1);
o([
  a()
], n.prototype, "elevationInfo", 1);
o([
  a()
], n.prototype, "profiles", 1);
o([
  a({ readOnly: !0 })
], n.prototype, "progress", 1);
o([
  a({ readOnly: !0 })
], n.prototype, "results", 1);
o([
  a({ readOnly: !0 })
], n.prototype, "selectButtonAvailable", 1);
o([
  a({ readOnly: !0 })
], n.prototype, "state", 1);
o([
  a()
], n.prototype, "uniformChartScaling", 2);
o([
  a()
], n.prototype, "distanceUnit", 1);
o([
  a()
], n.prototype, "distanceUnitOptions", 1);
o([
  a()
], n.prototype, "elevationUnit", 1);
o([
  a()
], n.prototype, "elevationUnitOptions", 1);
n = o([
  z("components.elevation-profile.ElevationProfileViewModel")
], n);
function b(t) {
  const e = t?.filter((i) => w.includes(i));
  return e && e.length > 0 ? e : w.slice();
}
const J = $(n);
class K extends M {
  constructor() {
    super(...arguments), this.viewModel = J(this), this._messages = D(), this._hideZoomOutButton = !0, this._hasSettingsStartContent = !1, this._hasSettingsEndContent = !1, this.analysis = this.viewModel.analysis, this.view = this.viewModel.view, this.autoDestroyDisabled = !1, this.effectiveDisplayUnits = this.viewModel.effectiveDisplayUnits, this.feature = this.viewModel.feature, this.hideChart = !1, this.hideChartGridLines = !1, this.hideChartAxisLabels = !1, this.hideClearButton = !1, this.hideLegend = !1, this.hideSelectButton = !1, this.hideSettingsButton = !1, this.hideStartButton = !1, this.hideUniformChartScalingToggle = !1, this.hideDistanceDisplayUnitSelect = !1, this.hideElevationDisplayUnitSelect = !1, this.hideVisualization = this.viewModel.hideVisualization, this.highlightDisabled = this.viewModel.highlightDisabled, this.icon = "altitude", this.indicatorRelativePosition = this.viewModel.indicatorRelativePosition, this.geometry = this.viewModel.geometry, this.elevationInfo = this.viewModel.elevationInfo, this.profiles = this.viewModel.profiles, this.progress = this.viewModel.progress, this.state = this.viewModel.state, this.uniformChartScaling = this.viewModel.uniformChartScaling, this.distanceUnit = this.viewModel.distanceUnit, this.distanceUnitOptions = this.viewModel.distanceUnitOptions, this.elevationUnit = this.viewModel.elevationUnit, this.elevationUnitOptions = this.viewModel.elevationUnitOptions, this.arcgisPropertyChange = O()("analysis", "effectiveDisplayUnits", "elevationInfo", "feature", "geometry", "indicatorRelativePosition", "progress", "state"), this.arcgisReady = B();
  }
  static {
    this.properties = { _hideZoomOutButton: 16, _chartContainer: 16, _hasSettingsStartContent: 16, _hasSettingsEndContent: 16, analysis: 0, view: 0, autoDestroyDisabled: 5, effectiveDisplayUnits: 32, feature: 0, hideChart: 5, hideChartGridLines: 5, hideChartAxisLabels: 5, hideClearButton: 5, hideLegend: 5, hideSelectButton: 5, hideSettingsButton: 5, hideStartButton: 5, hideUniformChartScalingToggle: 5, hideDistanceDisplayUnitSelect: 5, hideElevationDisplayUnitSelect: 5, hideVisualization: 5, highlightDisabled: 5, icon: 3, indicatorRelativePosition: 40, geometry: 0, elevationInfo: 0, label: 1, messageOverrides: 0, referenceElement: 1, profiles: 0, progress: 40, state: 32, uniformChartScaling: 5, distanceUnit: 1, distanceUnitOptions: 0, elevationUnit: 1, elevationUnitOptions: 0 };
  }
  static {
    this.styles = L;
  }
  get _selectButtonVisible() {
    return !this.hideSelectButton && this.viewModel.selectButtonAvailable;
  }
  get _chart() {
    return this._chartInitializationTask?.value;
  }
  async clear() {
    this.viewModel.clear();
  }
  async destroy() {
    await this.manager.destroy();
  }
  async select() {
    m(this.viewModel.select());
  }
  async start() {
    m(this.viewModel.start());
  }
  async stop() {
    this.viewModel.stop();
  }
  load() {
    this.manager.onLifecycle(() => [
      p(() => ({ container: this._chartContainer }), ({ container: e }) => {
        this._destroyChart(), e && (this._chartInitializationTask = x(async (i) => await k({
          view: this.viewModel.view,
          analysisView: this.viewModel.analysisView,
          container: e,
          messages: this._messages,
          signal: i,
          uniformScaling: this.viewModel.uniformChartScaling,
          onRangeChange: (r, s) => {
            this._hideZoomOutButton = r === 1 && s === 1;
          },
          onCursorPositionChange: (r, s) => {
            const { analysisView: l } = this.viewModel;
            l && (l.indicatorRelativePosition = r);
          }
        })));
      }, { sync: !0, initial: !0 }),
      p(() => ({
        chart: this._chart,
        view: this.viewModel.view,
        analysisView: this.viewModel.analysisView,
        uniformScaling: this.viewModel.uniformChartScaling,
        hideGridLines: this.hideChartGridLines,
        hideLabels: this.hideChartAxisLabels
      }), ({ chart: e, view: i, analysisView: r, uniformScaling: s }) => {
        e && (e.view = i, e.analysisView = r, e.uniformScaling = s, e.hideGridLines = this.hideChartGridLines, e.hideAxisLabels = this.hideChartAxisLabels);
      }, { sync: !0, initial: !0 }),
      // Make sure to destroy the chart when the component is disconnected.
      { remove: () => this._destroyChart() }
    ]);
  }
  _destroyChart() {
    const e = this._chart;
    this._chartInitializationTask?.abort(), this._chartInitializationTask = void 0, e?.destroy();
  }
  _onCancelButtonClick() {
    this.viewModel.stop(), this.viewModel.clear();
  }
  _onDoneButtonClick() {
    this.viewModel.stop();
  }
  _getErrorMessage() {
    const e = Q[this.viewModel.errorState];
    return e ? this._messages?.errors?.[e] : void 0;
  }
  _onClearButtonClick() {
    this.viewModel.clear();
  }
  _onZoomOutButtonClick() {
    this._chart?.zoomOut();
  }
  _onChartContainerRef(e) {
    this._chartContainer = e;
  }
  render() {
    return c`<div aria-label=${this._messages.componentLabel ?? u} class=${v({
      root: !0,
      [f.widget]: !0,
      [f.widgetDisabled]: this.viewModel.state === "disabled",
      [f.panel]: !0
    })} role=presentation>${this._renderContentForState()}</div>`;
  }
  _renderContentForState() {
    switch (this.viewModel.state) {
      case "ready":
        return this._renderContentForReadyState();
      case "selecting":
        return this._renderContentForSelectingState();
      case "creating":
        return this._renderContentForCreatingState();
      case "selected":
        return this._renderContentForSelectedState();
      case "created":
        return this._renderContentForCreatedState();
      case "disabled":
        return this._renderContentForReadyState();
    }
  }
  _renderContentForReadyState() {
    const { _messages: e, hideSelectButton: i, hideStartButton: r } = this, { selectButtonAvailable: s } = this.viewModel, l = !i && s;
    let d;
    return !r && l ? d = e.readyPrompt : r ? l ? d = e.readyPromptSelectOnly : d = e.errors?.noProfile : d = e.readyPromptCreateOnly, this._renderContent({ prompt: d, chart: !1, actions: g });
  }
  _renderContentForSelectingState() {
    const { view: e } = this.viewModel;
    if (!e)
      return;
    const i = this._messages[`selectingPrompt-${e.type}`];
    return this._renderContent({
      prompt: i,
      chart: !1,
      actions: [{ type: "select-cancel" }]
    });
  }
  _renderContentForCreatingState() {
    const { viewModel: e } = this, { view: i } = e;
    if (!i)
      return;
    const r = e.hasVertices ? [{ type: "sketch-cancel" }, { type: "sketch-done", disabled: !e.doneButtonAvailable }] : [{ type: "select" }, { type: "sketch", disabled: !0 }];
    if (e.errorState === "no-valid-input") {
      const l = this._messages[`creatingPrompt-${i.type}`];
      return this._renderContent({
        chart: !1,
        actions: r,
        prompt: l
      });
    }
    const s = this._getErrorMessage();
    return s ? this._renderContent({ chart: !1, actions: r, prompt: s }) : this._renderContent({ chart: !0, actions: r });
  }
  _renderContentForSelectedState() {
    const e = this._getErrorMessage();
    return e ? this._renderContent({ chart: !1, actions: g, prompt: e }) : this._renderContent({ chart: !0, actions: g });
  }
  _renderContentForCreatedState() {
    const e = this._getErrorMessage();
    return e ? this._renderContent({ chart: !1, actions: g, prompt: e }) : this._renderContent({ chart: !0, actions: g });
  }
  _renderContent(e) {
    const { viewModel: i } = this, r = i.geometry != null;
    return c`<header class="header">${h({ hidden: this._hideZoomOutButton, children: this._renderZoomOutButton() })}${h({ hidden: this.hideClearButton || !r, children: this._renderClearButton() })}${h({ hidden: this.hideSettingsButton, children: this._renderSettingsButton() })}</header><div class="main-container">${e.prompt != null ? this._renderPrompt(e.prompt) : e.chart ? this._renderChart() : void 0}</div>${h({ hidden: this.hideLegend, children: this._renderLegend() })}${this._renderActions(e)}`;
  }
  _renderPrompt(e) {
    return [
      c`<div class="prompt-container"><p class="prompt-message">${e}</p></div>`
    ];
  }
  _renderZoomOutButton() {
    const e = this._messages.zoomOut ?? "";
    return c`<calcite-action icon=magnifying-glass-minus @click=${this._onZoomOutButtonClick} .text=${e} title=${e ?? u}></calcite-action>`;
  }
  _renderChart() {
    if (this.hideChart)
      return;
    const e = this._chart;
    return c`${this._renderSpinner({
      size: e?.chartVisible ? "small" : "large",
      visible: e?.spinnerVisible ?? !1
    })}<div class="chart-container" ${U(this._onChartContainerRef)}></div>`;
  }
  _renderSpinner(e) {
    const i = e.size === "small", r = e.visible ?? !0;
    return c`<calcite-loader class=${v({
      spinner: !0,
      small: i,
      visible: r
    })} .inline=${i} label></calcite-loader>`;
  }
  _renderClearButton() {
    const e = this._messages.clearProfile ?? "";
    return c`<calcite-action icon=trash @click=${this._onClearButtonClick} .text=${e} title=${e ?? u}></calcite-action>`;
  }
  _renderLegend() {
    return c`<arcgis-elevation-profile-legend .effectiveDisplayUnits=${this.viewModel.effectiveDisplayUnits} .featureSelected=${this.viewModel.featureIsSelected} .messages=${this._messages} .profiles=${this.profiles} .results=${this.viewModel.results}></arcgis-elevation-profile-legend>`;
  }
  _renderSettingsButton() {
    return c`<arcgis-elevation-profile-settings .hasCustomStartContent=${this._hasSettingsStartContent} .hasCustomEndContent=${this._hasSettingsEndContent} .viewModel=${this.viewModel} .hideUniformChartScalingToggle=${this.hideUniformChartScalingToggle} .hideDistanceDisplayUnitSelect=${this.hideDistanceDisplayUnitSelect} .hideElevationDisplayUnitSelect=${this.hideElevationDisplayUnitSelect} .messages=${this._messages} .uniformChartScaling=${this.viewModel.uniformChartScaling} .unitOptionsDistance=${this.viewModel.distanceUnitOptions} .unitOptionsElevation=${this.viewModel.elevationUnitOptions} @arcgisElevationProfileSettingsUniformChartScalingChange=${(e) => {
      this.viewModel.uniformChartScaling = e.detail;
    }}><slot name=settings-start slot=settings-start @slotchange=${(e) => {
      this._hasSettingsStartContent = _(e);
    }}></slot><slot name=settings-end slot=settings-end @slotchange=${(e) => {
      this._hasSettingsEndContent = _(e);
    }}></slot></arcgis-elevation-profile-settings>`;
  }
  _renderActions({ actions: e }) {
    const i = this._messages, r = e.map((s) => {
      switch (s.type) {
        case "sketch":
          return h({ hidden: this.hideStartButton, children: this._renderAction({
            action: s,
            label: i.sketchButtonLabel,
            primary: !0,
            onClick: () => {
              this.start();
            }
          }) });
        case "sketch-cancel":
          return h({ hidden: this.hideStartButton, children: this._renderAction({
            action: s,
            label: i.cancelButtonLabel,
            primary: !1,
            onClick: this._onCancelButtonClick
          }) });
        case "sketch-done":
          return h({ hidden: this.hideStartButton, children: this._renderAction({
            action: s,
            label: i.doneButtonLabel,
            primary: !0,
            onClick: this._onDoneButtonClick
          }) });
        case "select":
          return h({ hidden: !this._selectButtonVisible, children: this._renderAction({
            action: s,
            label: i.selectButtonLabel,
            primary: !1,
            onClick: () => {
              this.select();
            }
          }) });
        case "select-cancel":
          return h({ hidden: !this._selectButtonVisible, children: this._renderAction({
            action: s,
            label: i.cancelButtonLabel,
            primary: !1,
            onClick: this._onCancelButtonClick
          }) });
        default:
          return;
      }
    }).filter(Boolean);
    return r.length ? c`<footer class="actions">${r}</footer>` : void 0;
  }
  _renderAction({ action: e, label: i, onClick: r, primary: s }) {
    return c`<calcite-button .appearance=${s ? "solid" : "outline-fill"} class="action-button" .disabled=${e.disabled || void 0} @click=${r}>${i}</calcite-button>`;
  }
}
function h(t) {
  return t.hidden ? void 0 : t.children;
}
const g = [{ type: "select" }, { type: "sketch" }], Q = {
  none: void 0,
  "no-valid-input": "noProfile",
  "no-available-profiles": "noProfile",
  "too-complex": "tooComplex",
  unknown: "unknown"
};
C("arcgis-elevation-profile", K);
export {
  K as ArcgisElevationProfile
};
