/* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
import { c as y } from "../../chunks/runtime.js";
import { ref as d } from "lit/directives/ref.js";
import c from "@arcgis/core/core/Collection.js";
import { watch as _ } from "@arcgis/core/core/reactiveUtils.js";
import { substitute as k } from "@arcgis/core/intl.js";
import S from "@arcgis/core/layers/GraphicsLayer.js";
import T from "@arcgis/core/networks/support/UNTraceConfiguration.js";
import C from "@arcgis/core/rest/networks/support/TraceLocation.js";
import m from "@arcgis/core/views/interactive/snapping/FeatureSnappingLayerSource.js";
import L from "@arcgis/core/widgets/Sketch/SketchViewModel.js";
import { LitElement as N, createEvent as l } from "@arcgis/lumina";
import { usePropertyChange as $ } from "@arcgis/lumina/controllers";
import { log as h, composeMissingPropertyMessage as v, composeEmptyPropertyMessage as P } from "@arcgis/toolkit/log";
import { css as E, html as r } from "lit";
import { u as I } from "../../chunks/useT9n.js";
import { l as g } from "../../chunks/async-utils.js";
import { b as F, a as f, c as U, q as b, i as x } from "../../chunks/layer-utils.js";
const A = E`:host{height:100%;flex-grow:1}calcite-flow{min-height:var(--arcgis-internal-panel-height-sm, 240px)}calcite-block-group{flex-grow:1;padding-bottom:var(--calcite-spacing-md);background-color:var(--calcite-color-foreground-1)}calcite-block{--calcite-block-content-space: 0;--calcite-block-border-color: transparent;margin:0}calcite-block calcite-combobox,calcite-block calcite-input{margin:0 var(--calcite-spacing-md)}calcite-block calcite-input-message{padding:var(--calcite-spacing-sm) var(--calcite-spacing-md) 0 var(--calcite-spacing-md)}calcite-notice{margin:var(--calcite-spacing-md)}#subnetwork-info-block{margin:var(--calcite-spacing-md) var(--calcite-spacing-md) 0 var(--calcite-spacing-md)}#results-limited-message{padding:var(--calcite-spacing-sm)}.inline-loader{--calcite-loader-spacing: var(--calcite-spacing-md)}.add-spatial-mode{display:flex;flex-direction:column;gap:var(--calcite-spacing-md);margin:var(--calcite-spacing-md)}.heading{color:var(--calcite-color-text-1);margin:0 0 var(--calcite-spacing-md) 0;font-size:var(--calcite-font-size);font-style:normal;font-weight:var(--calcite-font-weight-medium)}`, p = `utility-network-trace-inputs-sketch-${Date.now()}`, D = 20;
class M extends N {
  constructor() {
    super(...arguments), this._defaultPopupTemplateEnabled = !0, this._messages = I({ blocking: !0 }), this._layerIdToLayer = /* @__PURE__ */ new Map(), this._startingPoints = new c(), this._barriers = new c(), this._stoppingPoints = new c(), this._subnetworkTraceTypes = /* @__PURE__ */ new Set([
      "subnetwork",
      "subnetwork-controller",
      "upstream",
      "downstream",
      "isolation"
    ]), this._setUpMap = () => {
      if (this._error = void 0, !this.view?.map) {
        this._error = this._messages.errors.noView, this.utilityNetworks = void 0;
        return;
      }
      const e = this.view.map;
      this._setupUtilityNetworks(e), this._setupSketchViewModel(e);
    }, this._hitTestPromise = null, this._displayLimit = 20, this._traceLocationStartingRefChange = (e) => {
      e && (this._traceLocationStartingElement = e);
    }, this._traceLocationBarrierRefChange = (e) => {
      e && (this._traceLocationBarrierElement = e);
    }, this._traceLocationStoppingRefChange = (e) => {
      e && (this._traceLocationStoppingElement = e);
    }, this._featuresComponentRefChange = (e) => {
      e && (this._featuresComponentElement = e);
    }, this._handleFeaturesPropertyChange = ({ detail: e, target: t }) => {
      (e.name === "selectedDrillInFeature" || e.name === "selectedFeature") && (this.selectedFeature = t.selectedDrillInFeature ?? t.selectedFeature ?? void 0);
    }, this.candidateFeatures = [], this.compatibleSubnetworkNames = [], this.traceConfigurations = [], this._subnetworkNamesState = "ready", this._exceedDisplayLimit = !1, this.autoDestroyDisabled = !1, this.hideActionBar = !1, this.mode = "default", this.arcgisPropertyChange = $()("mode"), this.arcgisSelectedNamedTraceConfigurationChange = l(), this.arcgisTraceInputsChange = l(), this.arcgisTraceLocationSelectEnd = l(), this.arcgisTraceLocationSelectStart = l(), this.arcgisUtilityNetworkChange = l();
  }
  static {
    this.properties = { selectedFeature: 16, candidateFeatures: 16, compatibleSubnetworkNames: 16, subnetworksTable: 16, traceConfigurations: 16, utilityNetworks: 16, _unTraceConfiguration: 16, _error: 16, _subnetworkNamesState: 16, _activeTraceLocationType: 16, _exceedDisplayLimit: 16, beforeTraceLocationSelectStart: 0, view: 0, selectedUtilityNetwork: 0, selectedNamedTraceConfiguration: 0, autoDestroyDisabled: 5, hideActionBar: 5, unTraceConfiguration: 32, isSubnetworkNameTraceSelected: 32, referenceElement: 1, mode: 3, traceLocationFlagInfos: 32, traceLocations: 32 };
  }
  static {
    this.styles = A;
  }
  get selectedSubnetworkName() {
    return this._unTraceConfiguration?.subnetworkName ?? void 0;
  }
  set selectedSubnetworkName(e) {
    this._unTraceConfiguration && (this._unTraceConfiguration.subnetworkName = e);
  }
  get _allLayers() {
    const { view: e } = this;
    return e?.map ? e.map.allLayers.toArray().concat(e.map.allTables.toArray()) : [];
  }
  get showStartingPoints() {
    return !this.isSubnetworkNameTraceSelected;
  }
  get showStoppingPoints() {
    const e = this.selectedNamedTraceConfiguration?.traceType;
    return e === "path" || e === "circuit";
  }
  get _subnetworkLayerIds() {
    const e = this.selectedUtilityNetwork?.dataElement?.domainNetworks;
    return e ? e.map((t) => t.subnetworkLayerId).filter((t) => t != null && t > -1) : [];
  }
  get unTraceConfiguration() {
    return this._unTraceConfiguration;
  }
  get isSubnetworkNameTraceSelected() {
    const { selectedNamedTraceConfiguration: e } = this;
    return !!e?.traceConfiguration?.subnetworkName && e?.traceType === "subnetwork";
  }
  get traceLocationFlagInfos() {
    return new c([...this._startingPoints, ...this._barriers, ...this._stoppingPoints]);
  }
  get traceLocations() {
    const e = [];
    return this.showStartingPoints && this._startingPoints.forEach((t) => e.push(...this._createTraceLocations(t))), this.showStoppingPoints && this._stoppingPoints.forEach((t) => e.push(...this._createTraceLocations(t))), this._barriers.forEach((t) => e.push(...this._createTraceLocations(t))), e;
  }
  async destroy() {
    this._removeGraphicLayer(p), this._clearTraceLocations(), this._sketchViewModel?.cancel(), this._featuresComponentElement?.destroy(), this._traceLocationStartingElement?.destroy(), this._traceLocationBarrierElement?.destroy(), this._traceLocationStoppingElement?.destroy(), await this.manager.destroy();
  }
  load() {
    this._setUpMap(), this.manager.onLifecycle(() => [
      _(() => this.view?.map, () => this._setUpMap())
    ]);
  }
  willUpdate(e) {
    e.has("utilityNetworks") && this._handleUtilityNetworksChange(), e.has("selectedUtilityNetwork") && (this.arcgisUtilityNetworkChange.emit(), this._handleSelectedUtilityNetworkChange()), e.has("selectedNamedTraceConfiguration") && (this.arcgisTraceInputsChange.emit(), this.arcgisSelectedNamedTraceConfigurationChange.emit(), this._handleTraceConfigChange()), e.has("selectedSubnetworkName") && this.arcgisTraceInputsChange.emit();
  }
  disconnectedCallback() {
    super.disconnectedCallback(), this._layerIdToLayer.clear();
  }
  _createTraceLocations(e) {
    const t = e.flagProperties.selectedTerminals;
    return e.flagProperties.terminalConfiguration && t?.size ? Array.from(t, (i) => new C({
      type: e.traceLocation.type,
      isFilterBarrier: e.traceLocation.isFilterBarrier,
      globalId: e.traceLocation.globalId,
      percentAlong: e.traceLocation.percentAlong,
      terminalId: i
    })) : [e.traceLocation];
  }
  _clearTraceLocations() {
    this._startingPoints.forEach((e) => {
      e.spatialProperties.flagGraphic && this.view?.graphics.remove(e.spatialProperties.flagGraphic);
    }), this._startingPoints.removeAll(), this._barriers.forEach((e) => {
      e.spatialProperties.flagGraphic && this.view?.graphics.remove(e.spatialProperties.flagGraphic);
    }), this._barriers.removeAll(), this._stoppingPoints.forEach((e) => {
      e.spatialProperties.flagGraphic && this.view?.graphics.remove(e.spatialProperties.flagGraphic);
    }), this._stoppingPoints.removeAll();
  }
  _createGraphicLayer(e, t) {
    if (!e.findLayerById(t)) {
      const a = new S({
        id: t,
        listMode: "hide",
        title: t
      });
      F(this.view, a);
    }
  }
  _getGraphicLayer(e, t) {
    const i = e.findLayerById(t);
    return f(i) ? (e.reorder(i, e.layers.length - 1), i) : null;
  }
  _removeGraphicLayer(e) {
    if (!this.view?.map)
      return;
    const { map: t } = this.view, i = t?.findLayerById(e);
    i && f(i) && t?.remove(i);
  }
  _setSnappingOption() {
    if (!this._sketchViewModel)
      return;
    const e = new c();
    this._unLayers?.forEach((t) => {
      U(t) ? t.sublayers.forEach((i) => {
        e.add(new m({
          layer: i,
          enabled: !0
        }));
      }) : e.add(new m({
        layer: t,
        enabled: !0
      }));
    }), this._sketchViewModel.snappingOptions = {
      enabled: !1,
      featureSources: e
    };
  }
  _initializeSketchViewModel(e) {
    const { view: t } = this, i = this._getGraphicLayer(e, p);
    return new L({
      layer: i,
      view: t
    });
  }
  _setupSketchViewModel(e) {
    this._createGraphicLayer(e, p), this._sketchViewModel = this._initializeSketchViewModel(e), this._setSnappingOption();
  }
  _clearSubnetworks() {
    this.selectedSubnetworkName = void 0, this.subnetworksTable = void 0, this.compatibleSubnetworkNames = [];
  }
  async _loadSubnetworksTable() {
    this.subnetworksTable || (this.subnetworksTable = await this.selectedUtilityNetwork?.loadSubnetworksTable());
  }
  async _querySubnetworks() {
    const { subnetworksTable: e } = this;
    if (!e)
      return;
    const t = e.fieldsIndex.get("SUBNETWORKNAME"), i = (o, n, u) => n === 0 || o.getAttribute(t.name) !== u[n - 1].getAttribute(t.name), a = e.createQuery();
    a.gdbVersion = this.selectedUtilityNetwork?.gdbVersion, a.where = this._getSubnetworkQueryWhereClause(), a.outFields = [t.name], a.orderByFields = [t.name];
    const { features: s } = await b(e, a, void 0, !1);
    this.compatibleSubnetworkNames = s.filter(i).map((o) => o.getAttribute(t.name));
  }
  _getSubnetworkQueryWhereClause() {
    const e = this._unTraceConfiguration, t = `DOMAINNETWORKNAME = '${e.domainNetworkName}'`, i = `TIERNAME = '${e.tierName}'`;
    return [t, i].join(" AND ");
  }
  async _handleSubnetworkTraceConfigChange(e) {
    await this._loadSubnetworksTable(), await this._querySubnetworks();
    const { compatibleSubnetworkNames: t } = this;
    e.subnetworkName && !t.some((i) => i === e.subnetworkName) && (this.selectedSubnetworkName = t.at(0));
  }
  _selectTraceConfigurationByGuid(e) {
    const t = this.selectedUtilityNetwork?.sharedNamedTraceConfigurations.find((i) => i.globalId === e);
    if (!t) {
      h("error", this, "`traceConfig` not found in `selectedUtilityNetwork.sharedNamedTraceConfigurations`");
      return;
    }
    this.selectedNamedTraceConfiguration = t;
  }
  async _handleTraceConfigChange() {
    const { selectedNamedTraceConfiguration: e } = this;
    if (!(e?.traceConfiguration instanceof T)) {
      h("error", this, v("selectedNamedTraceConfiguration.traceConfiguration")), this._unTraceConfiguration = void 0;
      return;
    }
    this._unTraceConfiguration = e.traceConfiguration.clone(), this.isSubnetworkNameTraceSelected && (this._subnetworkNamesState = "loading", await this._handleSubnetworkTraceConfigChange(this._unTraceConfiguration), this._subnetworkNamesState = "ready");
  }
  async _handleSelectedUtilityNetworkChange() {
    const { selectedUtilityNetwork: e } = this;
    try {
      e && !e.loaded && await e.load();
    } catch (t) {
      g(t, this, "Error while loading the selected utility network");
    }
    this._clearSubnetworks(), this._setupTraceConfigurations(), this._filterUnLayers(), this._clearTraceLocations();
  }
  _setupTraceConfigurations() {
    this._unTraceConfiguration = void 0, this.selectedNamedTraceConfiguration = void 0, this.traceConfigurations = this.selectedUtilityNetwork?.sharedNamedTraceConfigurations.filter(Boolean).filter((e) => e.traceType !== "circuit").sort((e, t) => e.title.localeCompare(t.title)) || [], this.traceConfigurations.length ? this.selectedNamedTraceConfiguration = this.traceConfigurations.at(0) : h("error", this, "The selected utility network has no compatible named trace configurations.");
  }
  _filterUnLayers() {
    const { selectedUtilityNetwork: e } = this;
    this._unLayers = new c(this._allLayers.filter((t) => e?.isUtilityLayer(t) && !this._subnetworkLayerIds.includes(t.layerId))), this._setSnappingOption();
  }
  _handleUtilityNetworksChange() {
    const { utilityNetworks: e, selectedUtilityNetwork: t } = this;
    e?.length ? (!t || !e.includes(t)) && (this.selectedUtilityNetwork = e.at(0)) : (h("error", this, P("utilityNetworks")), this.selectedUtilityNetwork = void 0, this._error = this._messages.errors.noUtilityNetwork);
  }
  async _setupUtilityNetworks(e) {
    try {
      e.loaded || await e.load();
    } catch (t) {
      g(t, this, "Error while loading `view.map`");
    } finally {
      this.utilityNetworks = e.utilityNetworks || new c();
    }
  }
  _handleTraceLocationSelectStart(e) {
    if (e.stopPropagation(), this.arcgisTraceLocationSelectStart.emit(e.detail).defaultPrevented) {
      e.preventDefault();
      return;
    }
    this._activeTraceLocationType = e?.target?.traceLocationType, this.mode = "add-spatial-instructions";
  }
  _getLayerByLayerId(e) {
    if (e == null)
      return;
    const { _layerIdToLayer: t, _unLayers: i } = this;
    if (t.get(e))
      return t.get(e);
    if (!i)
      return;
    const a = i.find((s) => "layerId" in s && s.layerId === e);
    return a && t.set(e, a), a;
  }
  async _queryFeaturesOnLayer(e, t) {
    const i = e.createQuery();
    i.gdbVersion = this.selectedUtilityNetwork?.gdbVersion, i.objectIds = t.map((s) => s.getObjectId()), i.outFields = ["*"];
    const { features: a } = await b(e, i);
    return a.forEach((s) => {
      if (!s.getEffectivePopupTemplate(this._defaultPopupTemplateEnabled)) {
        const o = s.layer;
        s.popupTemplate = o.createPopupTemplate();
      }
    }), a;
  }
  async _queryFeatures(e) {
    const t = /* @__PURE__ */ new Map(), i = [];
    return e.forEach((a) => {
      const s = x(a.layer) ? a.layer.parent : a.layer;
      if (s) {
        const o = this._getLayerByLayerId(s.layerId);
        if (o) {
          const n = t.get(o) || [];
          n.push(a), t.set(o, n);
        }
      }
    }), await Promise.all(Array.from(t.keys()).map(async (a) => {
      const s = t.get(a) ?? [], o = await this._queryFeaturesOnLayer(a, s);
      i.push(...o);
    })), i;
  }
  async _handleHitTestComplete(e) {
    return this._exceedDisplayLimit = e.length > this._displayLimit, this.candidateFeatures = await this._queryFeatures(e.slice(0, this._displayLimit)), this.candidateFeatures.length === 0 ? (this._handleAddSpatialCancelClick(), await Promise.reject(Error("No features found"))) : (this.candidateFeatures.length === 1 && (this.selectedFeature = this.candidateFeatures.at(0)), this.mode = "add-spatial-feature", this._hitTestPromise?.reject(), this._hitTestPromise = Promise.withResolvers(), await this._hitTestPromise.promise);
  }
  _handleTraceLocationSelectEnd(e) {
    e.stopPropagation(), this.arcgisTraceLocationSelectEnd.emit(), this._activeTraceLocationType = void 0, this.mode = "default", this._handleAddSpatialCancelClick();
  }
  _handleAddSpatialCancelClick(e) {
    e?.stopPropagation(), this._featuresComponentElement?.clear(), this._handleFeaturesClose(), this._sketchViewModel?.cancel();
  }
  _handleFeaturesClose() {
    this.mode = "default", this.candidateFeatures = [], this.selectedFeature = void 0, this._hitTestPromise?.reject(), this._hitTestPromise = null;
  }
  _handleAddSpatialAddClick() {
    const { _hitTestPromise: e, _featuresComponentElement: t, selectedFeature: i } = this;
    if (e && t) {
      if (!i)
        return;
      e.resolve(i), this._hitTestPromise = null;
    }
  }
  renderError(e, t = !1, i) {
    return r`<calcite-notice .closable=${t} kind=danger open scale=s width=auto .icon=${i}><div slot=message>${e}</div></calcite-notice>`;
  }
  renderLoader() {
    return r`<calcite-loader label=loading></calcite-loader>`;
  }
  renderTraceSelection() {
    const e = this.traceConfigurations.map((i) => r`<calcite-combobox-item .value=${i.globalId} .heading=${i.title} .selected=${i.globalId === this.selectedNamedTraceConfiguration?.globalId}></calcite-combobox-item>`), t = this._messages.labels.traceConfiguration;
    return r`<calcite-block .heading=${t} .label=${t} expanded><calcite-combobox .label=${t} selection-mode=single-persist @calciteComboboxChange=${({ currentTarget: i }) => {
      this._selectTraceConfigurationByGuid(i.selectedItems[0]?.value);
    }}>${e}</calcite-combobox></calcite-block>`;
  }
  renderUtilityNetworkSelection() {
    const { _messages: e } = this, t = e.labels.utilityNetwork, i = this.utilityNetworks?.map((a) => r`<calcite-combobox-item .value=${a.id} .heading=${a.title || a.id} .selected=${a.id === this.selectedUtilityNetwork?.id}></calcite-combobox-item>`);
    return r`<calcite-block .heading=${t} .label=${t} expanded><calcite-combobox .label=${t} selection-mode=single-persist @calciteComboboxChange=${({ currentTarget: a }) => {
      const s = a.selectedItems[0]?.value;
      this.selectedUtilityNetwork?.id !== s && (this.selectedUtilityNetwork = this.utilityNetworks?.find((o) => o.id === s));
    }}>${i}</calcite-combobox></calcite-block>`;
  }
  renderDefaultMode() {
    const { selectedUtilityNetwork: e } = this, { noView: t, noUtilityNetwork: i } = this._messages.errors;
    let a;
    return this._error === t || this._error === i ? a = this.renderError(this._error, !1, "exclamation-mark-triangle") : !e?.loaded && !e?.loadError ? a = this.renderLoader() : a = this.renderContent(), r`<calcite-flow-item .selected=${this.mode === "default"}>${a}</calcite-flow-item>`;
  }
  renderSpatialSelectInstructions() {
    const { _messages: e, _activeTraceLocationType: t, mode: i } = this, a = t === "starting-point" ? e.labels.addSpatial.startingPoint : t === "barrier" ? e.labels.addSpatial.barrier : e.labels.addSpatial.stoppingPoint;
    return r`<calcite-flow-item .selected=${i === "add-spatial-instructions"} .heading=${a} @calciteFlowItemBack=${(s) => this._handleAddSpatialCancelClick(s)}><div class="add-spatial-mode"><div><h5 class="heading">${e.instructions.addSpatial.selectFeature.heading}</h5>${e.instructions.addSpatial.selectFeature.subheading}</div><div><h5 class="heading">${e.instructions.addSpatial.selectAssociatedFeature.heading}</h5>${e.instructions.addSpatial.selectAssociatedFeature.subheading}</div></div></calcite-flow-item>`;
  }
  renderCandidateFeatures() {
    const { candidateFeatures: e } = this;
    if (!e.length)
      return this.mode = "default", null;
    const t = this._activeTraceLocationType === "starting-point" ? this._messages.labels.addSpatial.startingPoint : this._activeTraceLocationType === "barrier" ? this._messages.labels.addSpatial.barrier : this._messages.labels.addSpatial.stoppingPoint, i = e.length === 1 ? "feature" : "list";
    return r`<arcgis-features-next .autoDestroyDisabled=${this.autoDestroyDisabled} .defaultPopupTemplateEnabled=${this._defaultPopupTemplateEnabled} .features=${e} .featureMenuTitle=${t} .hideActionBar=${this.hideActionBar} hide-select-feature .initialDisplayMode=${i} @arcgisClose=${() => this._handleFeaturesClose()} @arcgisPropertyChange=${this._handleFeaturesPropertyChange} open .referenceElement=${this.referenceElement} .view=${this.view} ${d(this._featuresComponentRefChange)}></arcgis-features-next>`;
  }
  renderAddSpatialFooter() {
    const { mode: e, _messages: t, selectedFeature: i, selectedUtilityNetwork: a } = this, s = e === "add-spatial-feature" && this._exceedDisplayLimit && !i, o = k(t.warnings.exceededDisplayLimit, {
      limit: this._displayLimit.toString()
    }), n = i ? !(a?.isUtilityLayer(i.layer) ?? !0) : !0;
    return r`${s && r`<calcite-input-message id=results-limited-message icon=exclamation-mark-circle status=idle>${o}</calcite-input-message>` || ""}<calcite-button appearance=outline width=full @click=${() => this._handleAddSpatialCancelClick()} slot=footer>${t.buttons.cancel}</calcite-button>${e === "add-spatial-feature" && r`<calcite-button width=full slot=footer appearance=solid @click=${() => this._handleAddSpatialAddClick()} .disabled=${n}>${t.buttons.add}</calcite-button>` || ""}`;
  }
  renderStartingPointSelection() {
    return r`<arcgis-utility-network-trace-location .view=${this.view} trace-location-type=starting-point .beforeTraceLocationSelectStart=${this.beforeTraceLocationSelectStart} @arcgisTraceLocationSelectStart=${this._handleTraceLocationSelectStart} @arcgisTraceLocationSelectEnd=${this._handleTraceLocationSelectEnd} @arcgisTraceLocationChange=${() => this.arcgisTraceInputsChange.emit()} .sketchViewModel=${this._sketchViewModel} .utilityNetwork=${this.selectedUtilityNetwork} .filterLayers=${this._unLayers} .traceLocations=${this._startingPoints} .afterHitTest=${this._handleHitTestComplete.bind(this)} .autoDestroyDisabled=${this.autoDestroyDisabled} ${d(this._traceLocationStartingRefChange)}></arcgis-utility-network-trace-location>`;
  }
  renderStoppingPointSelection() {
    return r`<arcgis-utility-network-trace-location .view=${this.view} trace-location-type=stopping-point .beforeTraceLocationSelectStart=${this.beforeTraceLocationSelectStart} @arcgisTraceLocationSelectStart=${this._handleTraceLocationSelectStart} @arcgisTraceLocationSelectEnd=${this._handleTraceLocationSelectEnd} @arcgisTraceLocationChange=${() => this.arcgisTraceInputsChange.emit()} .sketchViewModel=${this._sketchViewModel} .utilityNetwork=${this.selectedUtilityNetwork} .filterLayers=${this._unLayers} .traceLocations=${this._stoppingPoints} .afterHitTest=${this._handleHitTestComplete.bind(this)} .autoDestroyDisabled=${this.autoDestroyDisabled} ${d(this._traceLocationStoppingRefChange)}></arcgis-utility-network-trace-location>`;
  }
  renderBarrierSelection() {
    return r`<arcgis-utility-network-trace-location .view=${this.view} trace-location-type=barrier .beforeTraceLocationSelectStart=${this.beforeTraceLocationSelectStart} @arcgisTraceLocationSelectStart=${this._handleTraceLocationSelectStart} @arcgisTraceLocationSelectEnd=${this._handleTraceLocationSelectEnd} @arcgisTraceLocationChange=${() => this.arcgisTraceInputsChange.emit()} .sketchViewModel=${this._sketchViewModel} .utilityNetwork=${this.selectedUtilityNetwork} .filterLayers=${this._unLayers} .traceLocations=${this._barriers} .afterHitTest=${this._handleHitTestComplete.bind(this)} .autoDestroyDisabled=${this.autoDestroyDisabled} ${d(this._traceLocationBarrierRefChange)}></arcgis-utility-network-trace-location>`;
  }
  renderSubnetworkNameInput() {
    return r`<calcite-input clearable type=text .placeholder=${this._messages.instructions.enterSubnetworkName} max-length=64 .status=${this.selectedSubnetworkName ? "valid" : "invalid"} .value=${this.selectedSubnetworkName} @calciteInputInput=${(e) => this.selectedSubnetworkName = e.target.value}></calcite-input><calcite-input-message icon=exclamation-mark-triangle status=idle>${this._messages.labels.tooManySubnetworks}</calcite-input-message>`;
  }
  renderSubnetworkSelectList() {
    return r`<calcite-combobox .label=${this._messages.labels.subnetworkName} selection-mode=single-persist @calciteComboboxChange=${({ currentTarget: e }) => {
      this.selectedSubnetworkName = e.selectedItems[0]?.value;
    }}>${this.compatibleSubnetworkNames.map((e) => r`<calcite-combobox-item .value=${e} .heading=${e} .selected=${e === this.selectedSubnetworkName}></calcite-combobox-item>`)}</calcite-combobox>`;
  }
  renderSubnetworkSelection() {
    const { compatibleSubnetworkNames: e } = this, t = this._messages.labels.subnetworkName;
    return this.isSubnetworkNameTraceSelected ? this._subnetworkNamesState === "loading" ? r`<calcite-loader class="inline-loader" label=loading scale=s></calcite-loader>` : e.length ? r`<calcite-block .heading=${t} .label=${t} expanded>${e.length > D ? this.renderSubnetworkNameInput() : this.renderSubnetworkSelectList()}</calcite-block>` : this.renderError(this._messages.errors.noCompatibleSubnetworks, !1, "exclamation-mark-triangle") : null;
  }
  renderSubnetworkInfo() {
    const { _messages: e, selectedNamedTraceConfiguration: t, _unTraceConfiguration: i } = this;
    return i && t?.traceType && this._subnetworkTraceTypes.has(t.traceType) ? r`<calcite-block id=subnetwork-info-block expanded .label=${e.labels.subnetworkInfo}><arcgis-utility-network-subnetwork-info .namedTraceConfig=${t}></arcgis-utility-network-subnetwork-info></calcite-block>` : null;
  }
  renderContent() {
    const { utilityNetworks: e, unTraceConfiguration: t } = this, { noTraceConfiguration: i, noNamedTraceConfigurations: a, utilityNetworkLoadFailed: s } = this._messages.errors, o = e && e.length > 1 ? this.renderUtilityNetworkSelection() : null;
    let n;
    this.selectedUtilityNetwork?.loadError ? n = this.renderError(s, !1, "exclamation-mark-triangle") : this.traceConfigurations.length || (n = this.renderError(a, !1, "exclamation-mark-triangle"));
    const u = r`${this.renderTraceSelection()}${this.renderSubnetworkInfo()}${this.renderSubnetworkSelection()}`, w = t ? r`${this.showStartingPoints ? this.renderStartingPointSelection() : null}${this.showStoppingPoints ? this.renderStoppingPointSelection() : null}${this.renderBarrierSelection()}` : this.renderError(i, !1, "exclamation-mark-triangle");
    return r`<calcite-block-group .label=${this._messages.labels.traceInputs}>${o}${n ?? r`${u}${w}`}</calcite-block-group>`;
  }
  render() {
    const { mode: e } = this;
    return r`<calcite-panel>${e === "add-spatial-feature" ? this.renderCandidateFeatures() : null}<calcite-flow .hidden=${e === "add-spatial-feature"}>${this.renderDefaultMode()}${this.renderSpatialSelectInstructions()}</calcite-flow>${e !== "default" ? this.renderAddSpatialFooter() : null}</calcite-panel>`;
  }
}
y("arcgis-utility-network-trace-inputs", M);
export {
  M as ArcgisUtilityNetworkTraceInputs
};
