/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import { c as _ } from "../../chunks/runtime.js";
import { repeat as k } from "lit/directives/repeat.js";
import { ref as h } from "lit/directives/ref.js";
import { queryAllJSON as m } from "@arcgis/core/applications/Components/featureUtils.js";
import l from "@arcgis/core/core/Collection.js";
import { watch as S } from "@arcgis/core/core/reactiveUtils.js";
import { substitute as T } from "@arcgis/core/intl.js";
import L from "@arcgis/core/layers/GraphicsLayer.js";
import C from "@arcgis/core/networks/support/UNTraceConfiguration.js";
import N from "@arcgis/core/rest/networks/support/TraceLocation.js";
import f from "@arcgis/core/rest/support/FeatureSet.js";
import y from "@arcgis/core/views/interactive/snapping/FeatureSnappingLayerSource.js";
import $ from "@arcgis/core/widgets/Sketch/SketchViewModel.js";
import { LitElement as v, createEvent as d } from "@arcgis/lumina";
import { usePropertyChange as E } from "@arcgis/lumina/controllers";
import { log as u, composeMissingPropertyMessage as F, composeEmptyPropertyMessage as I } from "@arcgis/toolkit/log";
import { css as P, html as s } from "lit";
import { u as U } from "../../chunks/useT9n.js";
import { h as w } from "../../chunks/feature-utils.js";
import { a as A, i as b } from "../../chunks/layer-utils.js";
const D = P`: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-select,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-block calcite-label:last-child{--calcite-label-margin-bottom: 0}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()}`, n = `utility-network-trace-inputs-flags-${Date.now()}`, M = 20;
class B extends v {
  constructor() {
    super(...arguments), this._defaultPopupTemplateEnabled = !0, this._messages = U({ blocking: !0 }), this._layerIdToLayer = /* @__PURE__ */ new Map(), this._startingPoints = new l(), this._barriers = new l(), this._stoppingPoints = new l(), this._subnetworkTraceTypes = /* @__PURE__ */ new Set([
      "subnetwork",
      "subnetwork-controller",
      "upstream",
      "downstream",
      "isolation"
    ]), this._removeDuplicateSubnetworkNames = (e, t, i) => t === 0 || e.getAttribute("SUBNETWORKNAME") !== i[t - 1].getAttribute("SUBNETWORKNAME"), this._hitTestPromise = null, this._featuresFromHitTest = [], 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.compatibleSubnetworkNames = [], this.traceConfigurations = [], this._state = "ready", this._exceedDisplayLimit = !1, this.autoDestroyDisabled = !1, this.mode = "default", this.arcgisPropertyChange = E()("mode"), this.arcgisSelectedNamedTraceConfigurationChange = d(), this.arcgisTraceInputsChange = d(), this.arcgisTraceLocationSelectEnd = d(), this.arcgisTraceLocationSelectStart = d(), this.arcgisUtilityNetworkChange = d(), this.renderFeatureListItem = (e) => {
      const { feature: t, label: i } = e;
      return s`<calcite-list-item .label=${i} @calciteListItemSelect=${() => this._handleFeatureSelectChange(t)}><calcite-icon icon=chevron-right slot=content-end></calcite-icon></calcite-list-item>`;
    };
  }
  static {
    this.properties = { compatibleSubnetworkNames: 16, subnetworksTable: 16, traceConfigurations: 16, utilityNetworks: 16, _unTraceConfiguration: 16, _state: 16, _activeTraceLocationType: 16, _selectedFeature: 16, _exceedDisplayLimit: 16, beforeTraceLocationSelectStart: 0, view: 0, selectedUtilityNetwork: 0, selectedNamedTraceConfiguration: 0, autoDestroyDisabled: 5, unTraceConfiguration: 32, referenceElement: 1, mode: 3, traceLocations: 32 };
  }
  static {
    this.styles = D;
  }
  get isSubnetworkNameTraceSelected() {
    const e = this.selectedNamedTraceConfiguration?.traceType;
    return !!this.selectedNamedTraceConfiguration?.traceConfiguration?.subnetworkName && e === "subnetwork";
  }
  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 traceLocations() {
    const e = [], t = (i) => {
      i.flagProperties.terminalConfiguration && i.flagProperties.selectedTerminals ? i.flagProperties.selectedTerminals.forEach((r) => {
        e.push(new N({
          type: i.traceLocation.type,
          isFilterBarrier: i.traceLocation.isFilterBarrier,
          globalId: i.traceLocation.globalId,
          percentAlong: i.traceLocation.percentAlong,
          terminalId: r
        }));
      }) : e.push(i.traceLocation);
    };
    return this.showStartingPoints && this._startingPoints.forEach((i) => t(i)), this._barriers.forEach((i) => t(i)), this.showStoppingPoints && this._stoppingPoints.forEach((i) => t(i)), e;
  }
  async destroy() {
    this._removeGraphicLayer(p), this._removeGraphicLayer(n), this._sketchViewModel?.cancel(), this._featuresComponentElement?.destroy(), this._traceLocationStartingElement?.destroy(), this._traceLocationBarrierElement?.destroy(), this._traceLocationStoppingElement?.destroy(), await this.manager.destroy();
  }
  load() {
    this.manager.onLifecycle(() => [
      S(() => this.view?.map, () => {
        this._setupUtilityNetwork(), this._setupSketchViewModel();
      }, { initial: !0 })
    ]);
  }
  willUpdate(e) {
    const { utilityNetworks: t, selectedUtilityNetwork: i } = this;
    (e.has("utilityNetworks") || !t || t.length === 0 || !i || !t?.includes(i)) && 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();
  }
  _clearTraceLocations() {
    this._getGraphicLayer(n)?.removeAll(), this._startingPoints.removeAll(), this._barriers.removeAll(), this._stoppingPoints.removeAll();
  }
  _createGraphicLayer(e) {
    const { map: t } = this.view;
    if (!t?.findLayerById(e)) {
      const a = new L({
        id: e,
        listMode: "hide",
        title: e
      });
      A(this.view, a);
    }
  }
  _getGraphicLayer(e) {
    const { map: t } = this.view;
    if (t) {
      const i = t.findLayerById(e);
      if (b(i))
        return t.reorder(i, t.layers.length - 1), i;
    }
    return null;
  }
  _removeGraphicLayer(e) {
    const { map: t } = this.view, i = t?.findLayerById(e);
    i && b(i) && t?.remove(i);
  }
  _setSnappingOption() {
    const { _sketchViewModel: e, _unLayers: t } = this;
    if (e && t && t.length > 0) {
      const i = new l();
      t.forEach((a) => {
        a.type === "subtype-group" ? a.sublayers.forEach((r) => {
          i.add(new y({
            layer: r,
            enabled: !0
          }));
        }) : i.add(new y({
          layer: a,
          enabled: !0
        }));
      }), e.snappingOptions = {
        enabled: !0,
        featureEnabled: !0,
        featureSources: i
      };
    }
  }
  _initializeSketchViewModel() {
    const { view: e } = this, t = this._getGraphicLayer(p);
    return new $({
      layer: t,
      view: e
    });
  }
  _setupSketchViewModel() {
    this._createGraphicLayer(p), this._createGraphicLayer(n), this._sketchViewModel = this._initializeSketchViewModel(), 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.createQuery();
    t.gdbVersion = this.selectedUtilityNetwork?.gdbVersion, t.where = this._getSubnetworkQueryWhereClause(), t.outFields = ["SUBNETWORKNAME"], t.orderByFields = ["SUBNETWORKNAME"];
    const i = f.fromJSON(await m(e, t));
    this.compatibleSubnetworkNames = i.features.filter(this._removeDuplicateSubnetworkNames).map((a) => a.getAttribute("SUBNETWORKNAME"));
  }
  _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) {
      u("error", this, "`traceConfig` not found in `selectedUtilityNetwork.sharedNamedTraceConfigurations`");
      return;
    }
    this.selectedNamedTraceConfiguration = t;
  }
  _handleTraceConfigChange() {
    const { selectedNamedTraceConfiguration: e } = this;
    if (!(e?.traceConfiguration instanceof C)) {
      u("error", this, F("selectedNamedTraceConfiguration.traceConfiguration")), this._unTraceConfiguration = void 0;
      return;
    }
    switch (this._unTraceConfiguration = e.traceConfiguration.clone(), e.traceType) {
      case "subnetwork":
        this._state = "loading", this._handleSubnetworkTraceConfigChange(this._unTraceConfiguration).finally(() => this._state = "ready");
        break;
    }
  }
  async _handleSelectedUtilityNetworkChange() {
    await this.selectedUtilityNetwork?.load(), this._clearSubnetworks(), this._setupTraceConfigurations(), this._filterUnLayers(), this._clearTraceLocations();
  }
  _setupTraceConfigurations() {
    this._unTraceConfiguration = void 0, this.selectedNamedTraceConfiguration = void 0, this.traceConfigurations = this.selectedUtilityNetwork?.sharedNamedTraceConfigurations.filter((e) => e.traceType !== "path" && e.traceType !== "circuit").sort((e, t) => e.title.localeCompare(t.title)) || [], this.selectedNamedTraceConfiguration = this.traceConfigurations.at(0);
  }
  _filterUnLayers() {
    const { selectedUtilityNetwork: e } = this;
    this._unLayers = new l(this._allLayers.filter((t) => e?.isUtilityLayer(t) && !this._subnetworkLayerIds.includes(t.layerId))), this._setSnappingOption();
  }
  _handleUtilityNetworksChange() {
    const { utilityNetworks: e } = this;
    if (!e || e.length === 0) {
      this._state = "error", u("error", this, I("utilityNetworks"));
      return;
    }
    (!this.selectedUtilityNetwork || !e.includes(this.selectedUtilityNetwork)) && (this.selectedUtilityNetwork = e.at(0));
  }
  async _setupUtilityNetwork() {
    if (this.view?.map) {
      const e = this.view.map;
      await e.load(), this.utilityNetworks = e.utilityNetworks || void 0;
    } else
      this._state = "disabled", u("error", this, "The property `view.map` is required to load utility networks but is missing.");
  }
  _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((r) => "layerId" in r && r.layerId === e);
    return a && t.set(e, a), a;
  }
  async _queryFeatures(e, t) {
    const i = e.createQuery();
    i.gdbVersion = this.selectedUtilityNetwork?.gdbVersion, i.objectIds = t.map((r) => r.getObjectId()), i.outFields = ["*"];
    const { features: a } = f.fromJSON(await m(e, i));
    return a.forEach((r) => {
      r.layer = e.type === "subtype-group" ? e.findSublayerForFeature(r) : e, r.origin = r.layer;
      const o = r.layer;
      r.getEffectivePopupTemplate(this._defaultPopupTemplateEnabled) || (r.popupTemplate = o.createPopupTemplate());
    }), a;
  }
  async _populateFeaturesWithLabel(e) {
    const t = /* @__PURE__ */ new Map();
    e.forEach((a) => {
      const r = a.layer?.type === "subtype-sublayer" ? a.layer.parent : a.layer;
      if (r) {
        const o = r.layerId, c = this._getLayerByLayerId(o);
        if (c) {
          const g = t.get(c) || [];
          g.push(a), t.set(c, g);
        }
      }
    });
    const i = [];
    return await Promise.all(Array.from(t.keys()).map(async (a) => {
      const r = t.get(a) ?? [], o = await this._queryFeatures(a, r);
      i.push(...o);
    })), await Promise.all(i.map(async (a) => {
      const r = a.layer;
      if (r && "getFeatureTitle" in r) {
        const o = await r.getFeatureTitle(a) || w(a);
        return { feature: a, label: o };
      }
      return { feature: a, label: w(a) };
    }));
  }
  async _handleHitTestComplete(e) {
    if (this._exceedDisplayLimit = e.length > this._displayLimit, this._featuresFromHitTest = await this._populateFeaturesWithLabel(e.slice(0, this._displayLimit)), this._featuresFromHitTest.length === 0)
      return this._handleAddSpatialCancelClick(), await Promise.reject(Error("No features found"));
    if (this._featuresFromHitTest.length === 1) {
      const [{ feature: t }] = this._featuresFromHitTest;
      this._selectedFeature = t, this.mode = "add-spatial-feature";
    } else
      this.mode = "add-spatial-feature-list";
    return 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();
    const t = this._featuresComponentElement;
    t && t.clear(), this._selectedFeature = void 0, this.mode = "default", this._sketchViewModel?.cancel(), this._hitTestPromise?.reject(), this._hitTestPromise = null;
  }
  _handleFeaturesClose() {
    this.mode = "add-spatial-feature-list", this._selectedFeature = void 0;
  }
  _handleAddSpatialAddClick() {
    const { _hitTestPromise: e, _featuresComponentElement: t } = this;
    if (e && t) {
      const i = t, a = i.selectedDrillInFeature ?? i.selectedFeature;
      if (!a)
        return;
      e.resolve(a), this._hitTestPromise = null;
    }
  }
  _handleFeatureSelectChange(e) {
    this._selectedFeature = e, this.mode = "add-spatial-feature";
  }
  renderError(e, t = !1, i) {
    return s`<calcite-notice .closable=${t} kind=danger open scale=s width=auto .icon=${i}><div slot=message>${e}</div></calcite-notice>`;
  }
  renderLoader() {
    return s`<calcite-loader label=loading></calcite-loader>`;
  }
  renderTraceSelection() {
    const { _messages: e, traceConfigurations: t } = this, i = e.labels.traceConfiguration;
    if (t.length === 0)
      return this.renderError(e.errors.noTraceConfigurationError, !0);
    const a = k(t, (r) => r.globalId, (r) => s`<calcite-option .value=${r.globalId}>${r.title}</calcite-option>`);
    return s`<calcite-block .heading=${i} .label=${i} expanded><calcite-select .label=${i} .value=${this.selectedNamedTraceConfiguration?.globalId || void 0} @calciteSelectChange=${(r) => {
      this._selectTraceConfigurationByGuid(r.target.value);
    }}>${a}</calcite-select></calcite-block>`;
  }
  renderUtilityNetworkSelection() {
    const { _messages: e } = this, t = e.labels.utilityNetwork, i = this.utilityNetworks?.map((a) => s`<calcite-option .value=${a.id}>${a.title}</calcite-option>`);
    return s`<calcite-block .heading=${t} .label=${t} expanded><calcite-select .label=${t} .value=${this.selectedUtilityNetwork?.id} @calciteSelectChange=${(a) => {
      this.selectedUtilityNetwork?.id !== a.target.value && (this.selectedUtilityNetwork = this.utilityNetworks?.find((r) => r.id === a.target.value));
    }}>${i}</calcite-select></calcite-block>`;
  }
  renderDefaultMode() {
    const { _messages: e, _state: t, mode: i } = this;
    return s`<calcite-flow-item .selected=${i === "default"}>${t === "disabled" ? this.renderError(e.errors.noMapError) : this.renderContent()}</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 s`<calcite-flow-item .selected=${i === "add-spatial-instructions"} .heading=${a} @calciteFlowItemBack=${(r) => this._handleAddSpatialCancelClick(r)}><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>`;
  }
  renderFeaturesList(e) {
    return s`<calcite-list label="Feature list">${e.map(this.renderFeatureListItem)}</calcite-list>`;
  }
  renderHitTestResults() {
    const { _messages: e, _activeTraceLocationType: t, _featuresFromHitTest: i, mode: a } = this, r = t === "starting-point" ? e.labels.addSpatial.startingPoint : t === "barrier" ? e.labels.addSpatial.barrier : e.labels.addSpatial.stoppingPoint;
    return s`<calcite-flow-item .selected=${a === "add-spatial-feature-list"} .heading=${r} @calciteFlowItemBack=${(o) => this._handleAddSpatialCancelClick(o)}>${this.renderFeaturesList(i)}</calcite-flow-item>`;
  }
  renderSelectedFeature() {
    const { _selectedFeature: e } = this;
    return e ? s`<arcgis-features .referenceElement=${this.referenceElement} .features=${[e]} .view=${this.view} .defaultPopupTemplateEnabled=${this._defaultPopupTemplateEnabled} open @arcgisClose=${() => this._handleFeaturesClose()} .autoDestroyDisabled=${this.autoDestroyDisabled} ${h(this._featuresComponentRefChange)}></arcgis-features>` : (this.mode = "default", null);
  }
  renderAddSpatialFooter() {
    const { mode: e, _messages: t, selectedUtilityNetwork: i, _selectedFeature: a } = this, r = T(t.warnings.exceededDisplayLimit, {
      limit: this._displayLimit.toString()
    }), o = e === "add-spatial-feature-list" && this._exceedDisplayLimit, c = a ? !(i?.isUtilityLayer(a.layer) ?? !0) : !0;
    return s`${o && s`<calcite-input-message id=results-limited-message icon=exclamation-mark-circle status=idle>${r}</calcite-input-message>` || ""}<calcite-button appearance=outline width=full @click=${() => {
      this._handleAddSpatialCancelClick();
    }} slot=footer>${t.buttons.cancel}</calcite-button>${e === "add-spatial-feature" && s`<calcite-button width=full slot=footer appearance=solid @click=${() => {
      this._handleAddSpatialAddClick();
    }} .disabled=${c}>${t.buttons.add}</calcite-button>` || ""}`;
  }
  renderStartingPointSelection() {
    return s`<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} .flagLayer=${this._getGraphicLayer(n)} .traceLocations=${this._startingPoints} .afterHitTest=${this._handleHitTestComplete.bind(this)} .autoDestroyDisabled=${this.autoDestroyDisabled} ${h(this._traceLocationStartingRefChange)}></arcgis-utility-network-trace-location>`;
  }
  renderStoppingPointSelection() {
    return s`<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} .flagLayer=${this._getGraphicLayer(n)} .traceLocations=${this._stoppingPoints} .afterHitTest=${this._handleHitTestComplete.bind(this)} .autoDestroyDisabled=${this.autoDestroyDisabled} ${h(this._traceLocationStoppingRefChange)}></arcgis-utility-network-trace-location>`;
  }
  renderBarrierSelection() {
    return s`<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} .flagLayer=${this._getGraphicLayer(n)} .traceLocations=${this._barriers} .afterHitTest=${this._handleHitTestComplete.bind(this)} .autoDestroyDisabled=${this.autoDestroyDisabled} ${h(this._traceLocationBarrierRefChange)}></arcgis-utility-network-trace-location>`;
  }
  renderSubnetworkNameInput() {
    return s`<calcite-input clearable type=text .placeholder=${this._messages.instructions.enterSubnetworkName} max-length=64 .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 s`<calcite-select .label=${this._messages.labels.subnetworkName} .value=${this.selectedSubnetworkName} @calciteSelectChange=${(e) => this.selectedSubnetworkName = e.target.value}>${this.compatibleSubnetworkNames.map((e) => s`<calcite-option .value=${e}>${e}</calcite-option>`)}</calcite-select>`;
  }
  renderSubnetworkSelection() {
    const { compatibleSubnetworkNames: e } = this, t = this._messages.labels.subnetworkName;
    return this.isSubnetworkNameTraceSelected ? this._state === "loading" ? s`<calcite-loader class="inline-loader" label=loading scale=s></calcite-loader>` : e.length ? s`<calcite-block .heading=${t} .label=${t} expanded>${e.length > M ? 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) ? s`<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 } = this, t = this.selectedNamedTraceConfiguration?.traceConfiguration;
    if (!e || e.length === 0)
      return this.renderError(this._messages.errors.noUtilityNetworkError);
    const i = s`${this.renderTraceSelection()}${this.renderSubnetworkInfo()}${this.renderSubnetworkSelection()}`, a = s`${this.showStartingPoints ? this.renderStartingPointSelection() : null}${this.showStoppingPoints ? this.renderStoppingPointSelection() : null}${this.renderBarrierSelection()}`;
    return s`<calcite-block-group .label=${this._messages.labels.traceInputs}>${e.length > 1 ? this.renderUtilityNetworkSelection() : null}${this.selectedUtilityNetwork?.loaded ? i : this.renderLoader()}${t ? a : null}</calcite-block-group>`;
  }
  render() {
    const { mode: e } = this;
    return s`<calcite-panel>${e === "add-spatial-feature" ? this.renderSelectedFeature() : s`<calcite-flow>${this.renderDefaultMode()}${this.renderSpatialSelectInstructions()}${this.renderHitTestResults()}</calcite-flow>`}${e !== "default" ? this.renderAddSpatialFooter() : null}</calcite-panel>`;
  }
}
_("arcgis-utility-network-trace-inputs", B);
export {
  B as ArcgisUtilityNetworkTraceInputs
};
