/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import { c as D } from "../../chunks/runtime.js";
import { css as E, html as o } from "lit";
import { keyed as _ } from "lit/directives/keyed.js";
import O from "@arcgis/core/widgets/Features/FeaturesViewModel.js";
import { u as B } from "../../chunks/useT9n.js";
import { classes as b } from "@arcgis/toolkit/dom";
import { usePropertyChange as L } from "@arcgis/lumina/controllers";
import { m as R } from "../../chunks/useViewModel.js";
import { LitElement as P, createEvent as C, renderElement as S, nothing as d, safeClassMap as $ } from "@arcgis/lumina";
import { substitute as u, formatNumber as F } from "@arcgis/core/intl.js";
import { watch as h } from "@arcgis/core/core/reactiveUtils.js";
import { t as H, z, b as U } from "../../chunks/action-utils.js";
import { stripHTML as A } from "@arcgis/core/applications/Components/stringUtils.js";
import x from "@arcgis/core/core/Collection.js";
import { a as Z } from "../../chunks/feature-utils.js";
import { renderingSanitizer as y } from "@arcgis/core/applications/Components/sanitizerUtils.js";
import { initializeProjection as j } from "@arcgis/core/applications/Components/featureUtils.js";
import { createRef as M, ref as v } from "lit/directives/ref.js";
const G = E`:host{display:flex;overflow:hidden;flex:1 1 auto}.root{--calcite-color-background: var(--calcite-color-foreground-1);display:flex;overflow:hidden;flex:1 1 auto;flex-direction:column}.root img{image-orientation:from-image}.flow-item-collapsed{--calcite-flow-item-header-border-block-end: none}.container{display:flex;flex:1 1 auto;background-color:var(--calcite-color-foreground-1)}.container calcite-list{width:100%}.container:not(:empty){padding:var(--arcgis-internal-padding-md, var(--calcite-spacing-md))}.root .arcgis-feature,.root .arcgis-feature-relationship,.root .arcgis-feature-utility-network-associations{background-color:transparent}.heading{word-break:break-word;word-wrap:break-word}.header,.footer{display:flex;align-items:center;justify-content:flex-end;background-color:var(--calcite-color-foreground-1)}.footer{flex:1}.pagination-text{padding-inline:var(--calcite-spacing-sm);color:var(--calcite-color-text-3);font-size:var(--calcite-font-size-sm)}.loader{align-self:center;padding-inline:var(--calcite-spacing-lg)}.pagination-action-bar{flex:1}.pagination-menu-button{padding-inline:var(--calcite-spacing-xxs);border-inline-start:var(--calcite-border-width-sm) solid var(--calcite-color-border-3)}.icon{display:inline-block;flex:0 0 var(--calcite-spacing-lg);width:var(--calcite-spacing-lg);height:var(--calcite-spacing-lg)}.action-image{flex:0 0 var(--calcite-spacing-lg);background-position:50% 50%;background-repeat:no-repeat;background-size:contain;width:var(--calcite-spacing-lg);height:var(--calcite-spacing-lg)}.header{border-block-end:var(--calcite-border-width-sm) solid var(--calcite-color-border-3)}.content-feature{--calcite-flow-item-footer-padding: 0}.feature-menu-observer{position:relative;bottom:var(--calcite-spacing-xxl);z-index:2;text-align:center}.action-exit{transform:scaleX(-1)}`;
function K(c) {
  switch (c?.type) {
    case "point":
      return c;
    case "extent":
      return c.center;
    case "polygon":
      return c.centroid;
    case "multipoint":
    case "polyline":
      return c.extent?.center;
    default:
      return null;
  }
}
const m = z.clone();
function W(c) {
  return c?.declaredClass.startsWith("esri.layers.") ?? !1;
}
const X = R(O);
class q extends P {
  constructor() {
    super(...arguments), this._fetchFeaturesController = null, this._featureMenuIntersectionObserverCallback = ([e]) => {
      e?.isIntersecting && this.viewModel.featurePage != null && this.viewModel.featurePage++;
    }, this._featureMenuIntersectionObserver = new IntersectionObserver(this._featureMenuIntersectionObserverCallback, {
      root: window.document
    }), this._featureMenuIntersectionObserverNode = null, this._rootFlowItemNode = M(), this._featureMenuViewportNode = M(), this._actionBarMenuNode = M(), this._flowContainerNode = M(), this.messages = B(), this._selectedFeatureComponent = M(), this._cancelOpenRelatedFeature = () => {
      const { _openRelatedFeatureAbortController: e } = this;
      e && e.abort(), this._openRelatedFeatureAbortController = null;
    }, this._openRelatedFeatureAbortController = null, this.flowItems = new x(), this.viewModel = X(this), this.actions = this.viewModel.actions, this.active = this.viewModel.active, this.autoDestroyDisabled = !1, this.collapsed = !1, this.content = this.viewModel.content, this.defaultPopupTemplateEnabled = this.viewModel.defaultPopupTemplateEnabled, this.featureCount = this.viewModel.featureCount, this.featureMenuOpen = this.viewModel.featureMenuOpen, this.featureMenuTitle = this.viewModel.featureMenuTitle, this.featureNavigationTop = !1, this.features = this.viewModel.features, this.featuresPerPage = this.viewModel.featuresPerPage, this.featureViewModelAbilities = this.viewModel.featureViewModelAbilities, this.goToOverride = this.viewModel.goToOverride, this.headerActions = new x(), this.heading = this.viewModel.title, this.headingLevel = 2, this.hideActionBar = !1, this.hideCloseButton = !1, this.hideFeatureMenuHeading = !1, this.hideFeatureNavigation = !1, this.hideFeatureListLayerTitle = !1, this.hideHeading = !1, this.hideSpinner = !1, this.hideContent = !1, this.hideExpressionContent = !1, this.hideLastEditedInfo = !1, this.highlightDisabled = this.viewModel.highlightEnabled, this.includeDefaultActionsDisabled = this.viewModel.includeDefaultActions, this.initialDisplayMode = this.viewModel.initialDisplayMode, this.location = this.viewModel.location, this.map = this.viewModel.map, this.open = this.viewModel.visible, this.promises = this.viewModel.promises, this.responsiveActionsEnabled = !1, this.selectedFeature = this.viewModel.selectedFeature, this.selectedFeatureIndex = this.viewModel.selectedFeatureIndex, this.showCollapseButton = !1, this.spatialReference = this.viewModel.spatialReference, this.state = this.viewModel.state, this.timeZone = this.viewModel.timeZone, this.updateLocationEnabled = this.viewModel.updateLocationEnabled, this.view = this.viewModel.view, this.arcgisPropertyChange = L()("active", "collapsed", "featureCount", "featureMenuOpen", "features", "promises", "selectedDrillInFeature", "selectedFeature", "selectedFeatureComponent", "selectedFeatureIndex", "state", "open"), this.arcgisReady = C(), this.arcgisClose = C(), this.arcgisTriggerAction = C();
  }
  static {
    this.properties = { _openRelatedFeatureAbortController: 16, flowItems: 16, _hideActionText: 16, _featureNavigationVisible: 16, _isCollapsed: 16, _collapseEnabled: 16, viewModel: 0, actions: 0, active: 0, autoDestroyDisabled: 5, collapsed: 5, content: 1, defaultPopupTemplateEnabled: 5, featureCount: 9, featureMenuOpen: 5, featureMenuTitle: 1, featureNavigationTop: 5, features: 0, featuresPerPage: 9, featureViewModelAbilities: 0, goToOverride: 0, headerActions: 0, heading: 1, headingLevel: 9, hideActionBar: 5, hideCloseButton: 5, hideFeatureMenuHeading: 5, hideFeatureNavigation: 5, hideFeatureListLayerTitle: 5, hideHeading: 5, hideSpinner: 5, hideContent: 5, chartAnimationDisabled: 5, hideAttachmentsContent: 5, hideCustomContent: 5, hideExpressionContent: 5, hideFieldsContent: 5, hideMediaContent: 5, hideRelationshipContent: 5, hideTextContent: 5, hideUtilityNetworkContent: 5, hideLastEditedInfo: 5, highlightDisabled: 5, icon: 1, includeDefaultActionsDisabled: 5, initialDisplayMode: 1, label: 1, location: 0, map: 0, messageOverrides: 0, open: 5, referenceElement: 1, promises: 0, responsiveActionsEnabled: 5, selectedDrillInFeature: 32, selectedFeature: 0, selectedFeatureComponent: 32, selectedFeatureIndex: 9, showCollapseButton: 5, spatialReference: 0, state: 32, timeZone: 1, updateLocationEnabled: 5, view: 0 };
  }
  static {
    this.styles = G;
  }
  get _hideActionText() {
    if (!this.responsiveActionsEnabled)
      return !1;
    const e = this.viewModel.view?.widthBreakpoint;
    return e === "xsmall" || e === "small" || e === "medium";
  }
  get _featureNavigationVisible() {
    return this.viewModel.active && this.viewModel.featureCount > 1 && !!this.viewModel.selectedFeature && !this.hideFeatureNavigation;
  }
  get _isCollapsed() {
    return this._collapseEnabled && this.collapsed;
  }
  get _collapseEnabled() {
    return this.showCollapseButton && (this.initialDisplayMode === "list" || !!(this.heading || this.viewModel.selectedFeatureViewModel?.title) && !!(this.content || this.viewModel.selectedFeatureViewModel?.content));
  }
  get chartAnimationDisabled() {
    return !(this.viewModel.featureViewModelAbilities?.chartAnimation ?? !0);
  }
  set chartAnimationDisabled(e) {
    this.viewModel.featureViewModelAbilities ??= {}, this.viewModel.featureViewModelAbilities.chartAnimation = !e;
  }
  get hideAttachmentsContent() {
    return !(this.viewModel.featureViewModelAbilities?.attachmentsContent ?? !0);
  }
  set hideAttachmentsContent(e) {
    this.viewModel.featureViewModelAbilities ??= {}, this.viewModel.featureViewModelAbilities.attachmentsContent = !e;
  }
  get hideCustomContent() {
    return !(this.viewModel.featureViewModelAbilities?.customContent ?? !0);
  }
  set hideCustomContent(e) {
    this.viewModel.featureViewModelAbilities ??= {}, this.viewModel.featureViewModelAbilities.customContent = !e;
  }
  get hideFieldsContent() {
    return !(this.viewModel.featureViewModelAbilities?.fieldsContent ?? !0);
  }
  set hideFieldsContent(e) {
    this.viewModel.featureViewModelAbilities ??= {}, this.viewModel.featureViewModelAbilities.fieldsContent = !e;
  }
  get hideMediaContent() {
    return !(this.viewModel.featureViewModelAbilities?.mediaContent ?? !0);
  }
  set hideMediaContent(e) {
    this.viewModel.featureViewModelAbilities ??= {}, this.viewModel.featureViewModelAbilities.mediaContent = !e;
  }
  get hideRelationshipContent() {
    return !(this.viewModel.featureViewModelAbilities?.relationshipContent ?? !0);
  }
  set hideRelationshipContent(e) {
    this.viewModel.featureViewModelAbilities ??= {}, this.viewModel.featureViewModelAbilities.relationshipContent = !e;
  }
  get hideTextContent() {
    return !(this.viewModel.featureViewModelAbilities?.textContent ?? !0);
  }
  set hideTextContent(e) {
    this.viewModel.featureViewModelAbilities ??= {}, this.viewModel.featureViewModelAbilities.textContent = !e;
  }
  get hideUtilityNetworkContent() {
    return !(this.viewModel.featureViewModelAbilities?.utilityNetworkAssociationsContent ?? !0);
  }
  set hideUtilityNetworkContent(e) {
    this.viewModel.featureViewModelAbilities ??= {}, this.viewModel.featureViewModelAbilities.utilityNetworkAssociationsContent = !e;
  }
  get selectedDrillInFeature() {
    const e = Array.from(this.flowItems).at(-1);
    return e && "graphic" in e ? e.graphic ?? null : null;
  }
  get selectedFeatureComponent() {
    return this._selectedFeatureComponent.value ?? null;
  }
  async clear() {
    return this.viewModel.clear();
  }
  async close() {
    this.open = !1;
  }
  async destroy() {
    await this.manager.destroy(), await this._destroySpinner(this.referenceElement), this._cancelOpenRelatedFeature(), this._removeFlowItems(), this._unobserveFeatureMenuObserver(), this._cancelFetchingFeatures(), this._featureMenuIntersectionObserver?.disconnect();
  }
  async fetchFeatures(e, t) {
    this._cancelFetchingFeatures();
    const i = new AbortController(), { signal: n } = i;
    if (this._fetchFeaturesController = i, !e && this.view && this.location && (await j(this.location.spatialReference, this.view.spatialReference, null, { signal: n }), e = this.view.toScreen(this.location) ?? void 0), !e)
      return;
    const s = await this.viewModel.fetchFeatures(e, { signal: n, ...t });
    this.location = s.location, this.promises = s.pendingFeatures;
  }
  async next() {
    return this.viewModel.next();
  }
  async previous() {
    return this.viewModel.previous();
  }
  async setFocus() {
    this._flowContainerNode.value?.setFocus();
  }
  async triggerAction(e) {
    if (!e.disabled)
      return e?.type === "toggle" && (e.value = !e.value), await H(e, this.viewModel);
  }
  loaded() {
    this.manager.onLifecycle(() => [
      h(() => this.viewModel?.selectedFeatureIndex, (e, t) => this._selectedFeatureIndexUpdated(e, t)),
      h(() => this.viewModel?.view, () => this._viewChange()),
      h(() => this._spinnerEl?.screenLocation, () => this._closeOpenActionMenu()),
      h(() => this.selectedFeatureComponent?.viewModel, () => this._removeFlowItems()),
      h(() => this.viewModel?.featureViewModels, () => this._featureMenuViewportScrollTop()),
      h(() => [this.flowItems?.length, this.featureMenuOpen], () => {
        this.setFocus();
      }),
      h(() => this.referenceElement, (e, t) => {
        this._destroySpinner(t), this._createSpinner();
      }, { initial: !0 }),
      h(() => [
        this.hideSpinner,
        this.viewModel?.view,
        this.viewModel?.location,
        this.viewModel?.waitingForResult,
        this.viewModel?.view
      ], () => void this._createSpinner(), { initial: !0 })
    ]);
  }
  _cancelFetchingFeatures() {
    this._fetchFeaturesController?.abort(), this._fetchFeaturesController = null;
  }
  _handleClose() {
    this.close(), this.arcgisClose.emit();
  }
  _groupResultsByLayer() {
    const { featureViewModels: e } = this.viewModel, t = /* @__PURE__ */ new Map();
    return e.forEach((i) => {
      const n = i?.graphic;
      if (!n)
        return;
      const s = Z(n), a = W(s) ? s : null, l = t.get(a) ?? [];
      t.set(a, [...l, i]);
    }), t;
  }
  _handleCollapseToggle() {
    this.collapsed = !this.collapsed;
  }
  async _openRelatedFeature(e) {
    this._cancelOpenRelatedFeature();
    const t = new AbortController();
    this._openRelatedFeatureAbortController = t, await e.updateGeometry();
    const i = e.graphic, n = i?.geometry;
    if (n == null || i == null)
      return;
    this._removeFlowItems(), await this.viewModel.zoomTo({ target: n });
    const s = K(n);
    s != null && (this.location = s), this.features = [i], this.open = !0, await this.setFocus(), this._openRelatedFeatureAbortController === t && (this._openRelatedFeatureAbortController = null);
  }
  _handlePaginationMenuButton() {
    this._updateFeatureMenu();
  }
  _openFeatureMenu() {
    this._updateFeatureMenu(!0);
  }
  _closeFeatureMenu() {
    this._updateFeatureMenu(!1);
  }
  _updateFeatureMenu(e = !this.featureMenuOpen) {
    this.featureMenuOpen = e;
  }
  _previousFeature() {
    this.viewModel.previous();
  }
  _nextFeature() {
    this.viewModel.next();
  }
  _handleFeatureBack() {
    this.initialDisplayMode === "list" ? (this.selectedFeatureIndex = -1, this.setFocus()) : this._openFeatureMenu();
  }
  _handleFeatureMenuBack() {
    this.initialDisplayMode === "list" ? (this.selectedFeatureIndex = -1, this.setFocus()) : this.featureMenuOpen && this._closeFeatureMenu();
  }
  _setActiveFeature(e) {
    const { viewModel: t } = this;
    t.activeFeature = t.features?.[e] || null;
  }
  _removeActiveFeature() {
    this.viewModel.activeFeature = null;
  }
  _selectFeature(e) {
    this.viewModel.selectedFeatureIndex = e, this.initialDisplayMode === "feature" ? this._handleFeatureMenuBack() : this.setFocus();
  }
  _unobserveFeatureMenuObserver() {
    this._featureMenuIntersectionObserverNode && this._featureMenuIntersectionObserver.unobserve(this._featureMenuIntersectionObserverNode);
  }
  _featureMenuIntersectionObserverCreated(e) {
    this._unobserveFeatureMenuObserver(), e && this._featureMenuIntersectionObserver.observe(e), this._featureMenuIntersectionObserverNode = e;
  }
  _getActionTitle(e) {
    const { messages: t, selectedFeature: i } = this, { id: n } = e, s = i?.attributes, a = e.title ?? "", l = n === "zoom-to-feature" ? u(a, { messages: t }) : n === "remove-selected-feature" ? u(a, { messages: t }) : n === "zoom-to-clustered-features" ? u(a, { messages: t }) : n === "browse-clustered-features" ? u(a, { messages: t }) : e.title;
    return l && s ? u(l, s) : l ?? "";
  }
  _onMainKeydown(e) {
    const { key: t } = e;
    t === "ArrowLeft" && (e.stopPropagation(), this._handleFeatureMenuBack(), this.previous(), this.setFocus()), t === "ArrowRight" && (e.stopPropagation(), this._handleFeatureMenuBack(), this.next(), this.setFocus());
  }
  _featureMenuViewportScrollTop() {
    this._featureMenuViewportNode && this._featureMenuViewportNode.value?.scrollContentTo({ top: 0 });
  }
  _selectedFeatureIndexUpdated(e, t) {
    const { featureCount: i, waitingForResult: n } = this.viewModel;
    n || !i || e === t || e === -1 || (this._removeFlowItems(), this._rootFlowItemNode.value?.scrollContentTo({ top: 0 }));
  }
  _triggerAction(e) {
    this.triggerAction(e), this.arcgisTriggerAction.emit({ action: e });
  }
  _viewChange() {
    this.viewModel.clear(), this.open = !1;
  }
  _closeOpenActionMenu() {
    const { _actionBarMenuNode: e } = this;
    e.value && (e.value.menuOpen = !1);
  }
  _removeFlowItems() {
    this.flowItems.removeAll();
  }
  _getDrillInFlowItemDescription(e) {
    switch (e.flowType) {
      case "feature":
      case "feature-association":
      case "feature-utility-network-associations":
      case "feature-utility-network-association-type":
        return e.description;
      case "feature-relationship":
        return e.allItemsDescription;
    }
  }
  _handleDrillInBackClick() {
    this.flowItems?.pop();
  }
  _getHeading() {
    const { hideHeading: e } = this, { title: t, selectedFeatureViewModel: i } = this.viewModel;
    return i && !e ? i?.state === "error" ? this.messages?.errorMessage ?? "" : i?.title || "" : !e && t ? t : "";
  }
  async _destroySpinner(e) {
    e?.manager?.component?.extraContent?.remove(this._spinnerEl);
  }
  async _createSpinner() {
    const e = this.referenceElement;
    e && (await this._destroySpinner(e), this._spinnerEl = S(o`<arcgis-spinner .label=${this.messages.loading ?? ""} .trackLocation=${!this.hideSpinner && this.viewModel?.waitingForResult} .location=${this.viewModel?.location ?? void 0} .view=${this.viewModel?.view ?? void 0}></arcgis-spinner>`), e.manager?.component?.extraContent?.add(this._spinnerEl));
  }
  render() {
    return o`<div class="root" @keydown=${this._onMainKeydown}>${this._renderHeader()}${this._renderContentContainer()}</div>`;
  }
  _renderFeatureNavigation() {
    return [
      this._renderPagination(),
      this.initialDisplayMode === "list" ? this._renderFeaturePaginationText() : this._renderFeatureMenuButton()
    ];
  }
  _renderHeader() {
    return this.featureNavigationTop && this._featureNavigationVisible ? o`<div class="header">${this._renderFeatureNavigation()}</div>` : null;
  }
  _renderFooter() {
    return !this.featureNavigationTop && this._featureNavigationVisible ? o`<div class="footer" slot=footer>${this._renderFeatureNavigation()}</div>` : null;
  }
  _renderFeaturePaginationText() {
    const { messages: e, viewModel: t } = this, { featureCount: i, selectedFeatureIndex: n } = t;
    return o`<div class="pagination-text">${u(e.pageText ?? "", {
      index: F(n + 1),
      total: F(i)
    })}</div>`;
  }
  _renderFeatureMenuButton() {
    const { messages: e, viewModel: t } = this, { featureCount: i, selectedFeatureIndex: n, pendingPromisesCount: s } = t;
    return o`<calcite-action class="pagination-menu-button" icon=list .label=${e.selectFeature} .loading=${s > 0} @click=${this._handlePaginationMenuButton} .text=${u(e.pageText ?? "", {
      index: F(n + 1),
      total: F(i)
    })} text-enabled title=${e.selectFeature ?? d}></calcite-action>`;
  }
  _renderPagination() {
    const { previous: e, next: t } = this.messages;
    return o`<calcite-action-bar class="pagination-action-bar" expand-disabled layout=horizontal overflow-actions-disabled scale=s><calcite-action-group scale=s><calcite-action class="pagination-previous" icon=chevron-left icon-flip-rtl .label=${e ?? ""} @click=${this._previousFeature} .text=${e ?? ""} title=${e ?? "" ?? d}></calcite-action><calcite-action icon=chevron-right icon-flip-rtl .label=${t ?? ""} @click=${this._nextFeature} .text=${t ?? ""} title=${t ?? "" ?? d}></calcite-action></calcite-action-group></calcite-action-bar>`;
  }
  _renderFeatureMenuItem(e) {
    const { initialDisplayMode: t } = this, { selectedFeatureViewModel: i, featureViewModels: n } = this.viewModel, s = e === i, a = n.indexOf(e);
    return o`<calcite-list-item @blur=${this._removeActiveFeature} @focus=${() => this._setActiveFeature(a)} @mouseleave=${this._removeActiveFeature} @mouseover=${() => this._setActiveFeature(a)} .selected=${s} @calciteListItemSelect=${() => this._selectFeature(a)}><span .innerHTML=${(y.sanitize(e.title) || this.messages.untitled) ?? ""} slot=content></span>${t === "list" ? o`<calcite-icon flip-rtl icon=chevron-right scale=s slot=content-end></calcite-icon>` : null}</calcite-list-item>`;
  }
  _renderFeatureMenu() {
    const { messages: e, viewModel: t } = this, i = this._groupResultsByLayer(), n = this.initialDisplayMode === "list" ? "none" : "single";
    return t.featureViewModels.length ? o`<calcite-list display-mode=flat .label=${e?.featuresList ?? ""} selection-appearance=icon .selectionMode=${n}>${Array.from(i.keys(), (s) => {
      const a = i.get(s)?.map((r) => this._renderFeatureMenuItem(r)), l = s ? s.title ?? this.messages.untitled : null;
      return !this.hideFeatureListLayerTitle && l !== null ? _(s ?? "map-graphics", o`<calcite-list-item-group .heading=${l}>${a}</calcite-list-item-group>`) : a;
    })}</calcite-list>` : null;
  }
  _renderHeaderAction(e) {
    const t = e.title || "";
    return e.visible ? o`<calcite-action .active=${e.type === "toggle" ? e.value : !1} .disabled=${e.disabled} .icon=${e.icon ?? void 0} .indicator=${e.active} .loading=${e.active} @click=${() => this._triggerAction(e)} slot=header-actions-end .text=${t} title=${t ?? d}></calcite-action>` : null;
  }
  _renderHeaderActions() {
    return this.headerActions.map((e) => this._renderHeaderAction(e)).toArray();
  }
  _renderContentFeature() {
    const { headingLevel: e, hideCloseButton: t, _isCollapsed: i, _collapseEnabled: n, featureNavigationTop: s, flowItems: a, initialDisplayMode: l, selectedFeature: r, featureMenuOpen: p } = this, { active: f } = this.viewModel, g = this._getHeading();
    if (l === "list" && !r)
      return null;
    const w = a.length === 0 && (l === "list" ? !!r : !p);
    return o`<calcite-flow-item class=${$(b({
      "content-feature": !0,
      "flow-item-collapsed": i
    }))} .closable=${!t} .closed=${!f} .collapsed=${i} .collapseDirection=${s ? "down" : "up"} .collapsible=${n} .headingLevel=${e} .selected=${w} @calciteFlowItemBack=${this._handleFeatureBack} .loading=${!!this._openRelatedFeatureAbortController} @calciteFlowItemClose=${this._handleClose} @calciteFlowItemToggle=${this._handleCollapseToggle} .heading=${A(g)} ${v(this._rootFlowItemNode)}>${this._renderHeaderActions()}${this._renderActionBar()}<div class=${$(b("container", "content-container"))}>${this._renderContent()}</div>${this._renderFooter()}</calcite-flow-item>`;
  }
  _renderFeatureMenuContainer() {
    const { viewModel: e, hideCloseButton: t, featureMenuTitle: i, messages: n, initialDisplayMode: s, featureMenuOpen: a, selectedFeature: l, _collapseEnabled: r, _isCollapsed: p, featureNavigationTop: f, headingLevel: g } = this, { active: w, featureViewModels: T, pendingPromisesCount: I } = e, k = i ?? n.selectFeature;
    if (s === "feature" && !a)
      return null;
    const V = s === "list" ? !l : a;
    return o`<calcite-flow-item class=${$(b({
      "flow-item-collapsed": p
    }))} .closable=${s === "list" && !t} .closed=${!w} .collapsed=${s === "list" && p} .collapseDirection=${f ? "down" : "up"} .collapsible=${s === "list" && r} .description=${this.hideFeatureMenuHeading ? void 0 : u(n.total ?? "", {
      total: T.length
    })} .heading=${this.hideFeatureMenuHeading ? void 0 : k} .headingLevel=${g} .loading=${e.waitingForContents} .selected=${V} @calciteFlowItemBack=${(N) => {
      N.preventDefault(), this._handleFeatureMenuBack();
    }} @calciteFlowItemClose=${this._handleClose} @calciteFlowItemToggle=${this._handleCollapseToggle} ${v(this._featureMenuViewportNode)}>${s === "list" ? this._renderHeaderActions() : null}${I > 0 ? o`<calcite-loader class="loader" inline .label=${n.loading ?? ""} slot=header-actions-end></calcite-loader>` : null}<div class="container">${this._renderFeatureMenu()}</div><div class="feature-menu-observer" ${v(this._featureMenuIntersectionObserverCreated)}></div>${s === "feature" ? o`<calcite-button appearance=transparent @click=${this._handleFeatureMenuBack} slot=footer-start width=full>${n.back}</calcite-button>` : null}</calcite-flow-item>`;
  }
  _renderFlowItem(e, t) {
    const { messages: i, hideCloseButton: n, active: s } = this, a = "graphic" in e && "isFeatureFromTable" in e && !e.isFeatureFromTable, l = e.flowType === "feature-association", r = i.returnToInitialFeature ?? "", p = i?.selectFeature, f = this._getActionTitle(m), g = l && a;
    return o`<calcite-flow-item .closable=${!n} .closed=${!s} .description=${A(this._getDrillInFlowItemDescription(e) ?? "")} .heading=${this.hideHeading ? void 0 : A(e.heading ?? "")} .selected=${t} @calciteFlowItemBack=${(w) => {
      w.preventDefault(), this._handleDrillInBackClick();
    }} .loading=${!!this._openRelatedFeatureAbortController} @calciteFlowItemClose=${this._handleClose}><calcite-action class="action-exit" icon=move-up @click=${this._removeFlowItems} slot=header-actions-start .text=${r ?? ""} title=${r ?? "" ?? d}></calcite-action>${a ? o`<calcite-action icon=zoom-to-object @click=${() => this._openRelatedFeature(e)} slot=header-actions-end .text=${p ?? ""} title=${p ?? d}></calcite-action>` : null}${g ? o`<calcite-action-bar expand-disabled expanded scale=s slot=action-bar><calcite-action-group overlay-positioning=fixed scale=s><calcite-action .disabled=${m.disabled} .icon=${m.icon ?? void 0} .loading=${m.active} scale=s text-enabled .text=${f} title=${f ?? d} @click=${() => U(this.viewModel, e)}></calcite-action></calcite-action-group></calcite-action-bar>` : null}<div class="container">${e}</div></calcite-flow-item>`;
  }
  _renderContentContainer() {
    const e = this.flowItems?.toArray(), t = e?.map((n, s) => this._renderFlowItem(n, this.initialDisplayMode === "list" || !this.featureMenuOpen && s === e.length - 1)), i = this.initialDisplayMode === "list" ? [this._renderFeatureMenuContainer(), this._renderContentFeature(), t] : [this._renderContentFeature(), t, this._renderFeatureMenuContainer()];
    return o`<calcite-flow ${v(this._flowContainerNode)}>${i}</calcite-flow>`;
  }
  _renderActionBar() {
    const t = this.viewModel.selectedFeatureViewModel?.isFeatureFromTable && !this.location ? this.viewModel.allActions.filter((i) => i.id !== m.id) : this.viewModel.allActions;
    return !this._isCollapsed && !this.hideActionBar && t.length ? o`<calcite-action-bar expand-disabled .expanded=${!this._hideActionText} scale=s slot=action-bar><calcite-action-group overlay-positioning=fixed scale=s ${v(this._actionBarMenuNode)}>${this._renderActions()}</calcite-action-group></calcite-action-bar>` : null;
  }
  _renderActions() {
    return this.viewModel.allActions.toArray().map((e) => {
      const t = this._getActionTitle(e);
      return o`<calcite-action .active=${e.type === "toggle" ? e.value : !1} .disabled=${e.disabled} .icon=${e.icon ?? void 0} .loading=${e.active} scale=s .textEnabled=${!this._hideActionText} .text=${t ?? ""} title=${t ?? d} .hidden=${!e.visible} @click=${() => this._triggerAction(e)}></calcite-action>`;
    });
  }
  _renderContent() {
    const { content: e, selectedFeatureViewModel: t } = this.viewModel;
    return t ? _(t, o`<arcgis-feature .chartAnimationDisabled=${this.chartAnimationDisabled} .defaultPopupTemplateEnabled=${this.defaultPopupTemplateEnabled} .flowItems=${this.flowItems} .graphic=${t.graphic} .headingLevel=${this.headingLevel + 1} .hideAttachmentsContent=${this.hideAttachmentsContent} .hideContent=${this.hideContent} .hideCustomContent=${this.hideCustomContent} .hideExpressionContent=${this.hideExpressionContent} .hideFieldsContent=${this.hideFieldsContent} hide-heading .hideLastEditedInfo=${this.hideLastEditedInfo} .hideMediaContent=${this.hideMediaContent} .hideTextContent=${this.hideTextContent} .location=${this.location} .map=${this.map} .referenceElement=${this.referenceElement} .showRelationshipContent=${!this.hideRelationshipContent} .showUtilityNetworkContent=${!this.hideUtilityNetworkContent} .spatialReference=${this.spatialReference} .timeZone=${this.timeZone} ${v(this._selectedFeatureComponent)}></arcgis-feature>`) : typeof e == "string" ? _(e, o`<div .innerHTML=${y.sanitize(e) ?? ""}></div>`) : e ?? null;
  }
}
D("arcgis-features", q);
export {
  q as ArcgisFeatures
};
