import { c as y } from "../../chunks/runtime.js";
import { css as I, html as o } from "lit";
import { ref as M } from "lit/directives/ref.js";
import x from "@arcgis/core/widgets/Feature/FeatureViewModel.js";
import { u as _ } from "../../chunks/useT9n.js";
import { classes as F } from "@arcgis/toolkit/dom";
import { usePropertyChange as b } from "@arcgis/lumina/controllers";
import { m as L } from "../../chunks/useViewModel.js";
import { LitElement as T, createEvent as A, safeClassMap as d, nothing as E } from "@arcgis/lumina";
import { substitute as k } from "@arcgis/core/intl.js";
import { o as R, g as V, p as D, q as H, s as c, d as B, i as N } from "../../chunks/feature-utils.js";
import P from "@arcgis/core/core/Collection.js";
import { watch as Z } from "@arcgis/core/core/reactiveUtils.js";
import { stripHTML as U } from "@arcgis/core/applications/Components/stringUtils.js";
/*! All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.34/esri/copyright.txt for details.
v4.34.7 */
const z = I`:host{display:flex;flex:1 1 auto;background-color:var(--calcite-color-foreground-1);--calcite-color-background: var(--calcite-color-foreground-1)}.arcgis-feature{flex:1 1 auto}.arcgis-feature calcite-icon{box-sizing:content-box}.arcgis-feature__loading-container{display:flex;justify-content:center;padding:var(--calcite-spacing-md) 0;width:100%}.arcgis-feature__content-element{margin-bottom:var(--calcite-spacing-lg);padding:0 var(--calcite-spacing-sm);display:flex;flex-direction:column}.arcgis-feature__content-element:only-child,.arcgis-feature__content-element:last-child{margin-bottom:var(--calcite-spacing-xxs)}.arcgis-feature__last-edited-info{padding-top:var(--calcite-spacing-xs);font-size:var(--calcite-font-size-sm)}`, f = "arcgis-feature", l = {
  // popup renderer
  base: f,
  // containers and content
  container: `${f}__size-container`,
  main: `${f}__main-container`,
  contentElement: `${f}__content-element`,
  lastEditedInfo: `${f}__last-edited-info`,
  // loading
  loadingSpinnerContainer: `${f}__loading-container`
}, S = L(x);
class G extends T {
  constructor() {
    super(...arguments), this.messages = _(), this._rootFlowNode = null, this.flowType = "feature", this.internalFlowItems = new P(), this.viewModel = S(this), this.view = this.viewModel.view, this.icon = "icon", this.isFeatureFromTable = this.viewModel.isFeatureFromTable, this.graphic = this.viewModel.graphic, this.defaultPopupTemplateEnabled = this.viewModel.defaultPopupTemplateEnabled, this.headingLevel = 2, this.spatialReference = this.viewModel.spatialReference, this.timeZone = this.viewModel.timeZone, this.heading = this.viewModel.title, this.map = this.viewModel.map, this.chartAnimationDisabled = this.viewModel.abilities.chartAnimation, this.hideHeading = !1, this.hideContent = !1, this.hideAttachmentsContent = !1, this.hideCustomContent = !1, this.hideExpressionContent = !1, this.hideFieldsContent = !1, this.hideMediaContent = !1, this.showRelationshipContent = !1, this.hideTextContent = !1, this.showUtilityNetworkContent = !1, this.hideLastEditedInfo = !1, this.autoDestroyDisabled = !1, this.location = this.viewModel.location, this.state = this.viewModel.state, this.arcgisPropertyChange = b()("flowItems", "state"), this.arcgisReady = A();
  }
  static {
    this.properties = { flowType: 16, popupTemplate: 16, sourceLayer: 16, fieldInfoMap: 16, values: 16, globalValues: 16, internalFlowItems: 16, viewModel: 0, view: 0, flowItems: 0, referenceElement: 1, position: 3, icon: 1, isFeatureFromTable: 4, graphic: 0, defaultPopupTemplateEnabled: 5, headingLevel: 9, spatialReference: 0, timeZone: 1, heading: 0, map: 0, chartAnimationDisabled: 5, hideHeading: 5, hideTitle: 5, hideContent: 5, hideAttachmentsContent: 5, hideContentAttachments: 5, hideCustomContent: 5, hideExpressionContent: 5, hideContentExpression: 5, hideFieldsContent: 5, hideContentFields: 5, hideMediaContent: 5, hideContentMedia: 5, showRelationshipContent: 5, hideTextContent: 5, hideContentText: 5, showUtilityNetworkContent: 5, hideLastEditedInfo: 5, hideLastEditInfo: 5, autoDestroyDisabled: 5, messageOverrides: 0, label: 1, location: 0, state: 3 };
  }
  static {
    this.styles = z;
  }
  get popupTemplate() {
    return R(this.graphic, this.defaultPopupTemplateEnabled) ?? void 0;
  }
  get sourceLayer() {
    return V(this.graphic);
  }
  get fieldInfoMap() {
    return D(H(this.popupTemplate), this.sourceLayer);
  }
  get values() {
    return this.graphic?.attributes ?? {};
  }
  get globalValues() {
    return this.viewModel.formattedAttributes?.global ?? {};
  }
  get hideTitle() {
    return this.hideHeading;
  }
  set hideTitle(e) {
    this.hideHeading = e;
  }
  get hideContentAttachments() {
    return this.hideAttachmentsContent;
  }
  set hideContentAttachments(e) {
    this.hideAttachmentsContent = e;
  }
  get hideContentExpression() {
    return this.hideExpressionContent;
  }
  set hideContentExpression(e) {
    this.hideExpressionContent = e;
  }
  get hideContentFields() {
    return this.hideFieldsContent;
  }
  set hideContentFields(e) {
    this.hideFieldsContent = e;
  }
  get hideContentMedia() {
    return this.hideMediaContent;
  }
  set hideContentMedia(e) {
    this.hideMediaContent = e;
  }
  get hideContentText() {
    return this.hideTextContent;
  }
  set hideContentText(e) {
    this.hideTextContent = e;
  }
  get hideLastEditInfo() {
    return this.hideLastEditedInfo;
  }
  set hideLastEditInfo(e) {
    this.hideLastEditedInfo = e;
  }
  async destroy() {
    await this.manager.destroy();
  }
  async nextMedia(e) {
    return this.viewModel.nextMedia(e);
  }
  async previousMedia(e) {
    return this.viewModel.previousMedia(e);
  }
  async setActiveMedia(e, t) {
    return this.viewModel.setActiveMedia(e, t);
  }
  async updateGeometry() {
    return await this.viewModel.updateGeometry();
  }
  loaded() {
    this.manager.onLifecycle(() => [
      Z(() => [this.internalFlowItems?.length], () => this._setFocus())
    ]);
  }
  _removeFlowItems() {
    this.internalFlowItems?.removeAll();
  }
  _storeRootFlowNode(e) {
    this._rootFlowNode = e;
  }
  _setFocus() {
    this._rootFlowNode?.setFocus();
  }
  _handleDrillInBackClick() {
    this.internalFlowItems?.pop();
  }
  render() {
    const { state: e } = this.viewModel, t = o`<div class=${d(l.container)}>${e === "error" ? this._renderError() : e === "loading" ? this._renderLoading() : this._renderContentContainer()}</div>`;
    return o`<div class=${d(l.base)}>${t}</div>`;
  }
  _renderError() {
    const { messages: e, hideHeading: t } = this;
    return o`<calcite-notice icon=exclamation-mark-circle kind=danger open scale=s>${t ? null : o`<div slot=title>${e.error}</div>`}<div slot=message>${e.loadingError}</div></calcite-notice>`;
  }
  _renderLoading() {
    return o`<div class=${d(l.loadingSpinnerContainer)}><calcite-loader inline label></calcite-loader></div>`;
  }
  _renderAttachments(e) {
    const { values: t, fieldInfoMap: i, sourceLayer: n, globalValues: a } = this, s = c({
      values: t,
      fieldInfoMap: i,
      globalValues: a,
      layer: n,
      text: e.title
    }), r = c({
      values: t,
      fieldInfoMap: i,
      globalValues: a,
      layer: n,
      text: e.description
    });
    return o`<arcgis-feature-attachments .headingLevel=${this.headingLevel} .heading=${s} .displayType=${e.displayType} .attachmentKeywords=${e.attachmentKeywords ?? void 0} .attachmentTypes=${e.attachmentTypes ?? void 0} .graphic=${this.graphic ?? void 0} .description=${r} .messages=${this.messages}></arcgis-feature-attachments>`;
  }
  _renderCustom(e) {
    return o`<arcgis-feature-content .creator=${e.creator} .destroyer=${e.destroyer ?? void 0} .graphic=${this.graphic ?? void 0} class=${d(l.contentElement)}></arcgis-feature-content>`;
  }
  _renderFields(e, t) {
    const i = this.viewModel.formattedAttributes, { values: n, fieldInfoMap: a, sourceLayer: s, popupTemplate: r, globalValues: h, graphic: p } = this, u = !!e?.fieldInfos, m = (e.fieldInfos ?? r?.fieldInfos ?? [])?.filter(({ fieldName: $ }) => !!$ && (B($) || N($) || $ in n)), v = r?.expressionInfos, w = c({
      values: n,
      fieldInfoMap: a,
      globalValues: h,
      layer: s,
      text: e.title
    }), C = c({
      values: n,
      fieldInfoMap: a,
      globalValues: h,
      layer: s,
      text: e.description
    });
    return o`<arcgis-feature-fields .headingLevel=${this.headingLevel} .heading=${w} class=${d(l.contentElement)} .messages=${this.messages} .graphic=${p ?? void 0} .isContentFieldInfos=${u} .layer=${s} .description=${C} .values=${{
      ...i?.global,
      ...i?.content?.[t]
    }} .fieldInfos=${m} .expressionInfos=${v ?? void 0}></arcgis-feature-fields>`;
  }
  _renderMedia(e, t) {
    const { values: i, graphic: n, fieldInfoMap: a, sourceLayer: s, popupTemplate: r, globalValues: h } = this, { formattedAttributes: p, relatedInfos: u } = this.viewModel, g = {
      ...p?.global,
      ...p?.content?.[t]
    }, m = c({
      values: i,
      fieldInfoMap: a,
      globalValues: h,
      layer: s,
      text: e.title
    }), v = c({
      values: i,
      fieldInfoMap: a,
      globalValues: h,
      layer: s,
      text: e.description
    });
    return o`<arcgis-feature-media .activeMediaInfoIndex=${e.activeMediaInfoIndex ?? 0} .chartAnimationDisabled=${this.chartAnimationDisabled} .headingLevel=${this.headingLevel} .heading=${m} class=${d(l.contentElement)} .description=${v} .values=${i} .layer=${s} .graphic=${n ?? void 0} .messages=${this.messages} .fieldInfoMap=${a} .mediaInfos=${e.mediaInfos ?? []} .popupTemplate=${r ?? void 0} .relatedInfos=${u} .formattedValues=${g}></arcgis-feature-media>`;
  }
  _renderText(e) {
    const { values: t, fieldInfoMap: i, sourceLayer: n, globalValues: a } = this, s = c({
      values: t,
      fieldInfoMap: i,
      globalValues: a,
      layer: n,
      text: e.text
    });
    return o`<arcgis-feature-content .creator=${s} .graphic=${this.graphic ?? void 0} class=${d(l.contentElement)}></arcgis-feature-content>`;
  }
  _renderExpression(e, t) {
    const i = this.viewModel.formattedAttributes, { fieldInfoMap: n } = this;
    return o`<arcgis-feature-expression .expressionInfo=${e.expressionInfo} .map=${this.map ?? void 0} .spatialReference=${this.spatialReference ?? void 0} .view=${this.viewModel.view ?? void 0} .graphic=${this.graphic ?? void 0} .location=${this.location ?? void 0} .headingLevel=${this.headingLevel} class=${d(l.contentElement)} .interceptor=${this.viewModel.interceptor} .messages=${this.messages} .fieldInfoMap=${n} .values=${{
      ...i?.global,
      ...i?.content?.[t]
    }}></arcgis-feature-expression>`;
  }
  _renderRelationship(e, t) {
    const { values: i, graphic: n, fieldInfoMap: a, sourceLayer: s, globalValues: r } = this, { displayCount: h, orderByFields: p, relationshipId: u } = e, { formattedAttributes: g, view: m } = this.viewModel, v = {
      ...g?.global,
      ...g?.content?.[t]
    }, w = c({
      values: i,
      fieldInfoMap: a,
      globalValues: r,
      layer: s,
      text: e.title
    }), C = c({
      values: i,
      fieldInfoMap: a,
      globalValues: r,
      layer: s,
      text: e.description
    });
    return o`<arcgis-feature-relationship class=${d(l.contentElement)} .flowItems=${this.flowItems ?? this.internalFlowItems} .description=${C} .layer=${s} .map=${this.map ?? void 0} .displayCount=${h} .graphic=${n ?? void 0} .heading=${w} .headingLevel=${this.headingLevel} .messages=${this.messages} .orderByFields=${p ?? void 0} .relationshipId=${u ?? void 0} .spatialReference=${this.spatialReference ?? void 0} .timeZone=${this.timeZone ?? void 0} .values=${v} .view=${m ?? void 0}></arcgis-feature-relationship>`;
  }
  _renderAssociation(e) {
    const { fieldInfoMap: t, globalValues: i, graphic: n, messages: a, sourceLayer: s, values: r } = this, h = c({
      values: r,
      fieldInfoMap: t,
      globalValues: i,
      layer: s,
      text: e.title
    }), p = c({
      values: r,
      fieldInfoMap: t,
      globalValues: i,
      layer: s,
      text: e.description
    });
    return o`<arcgis-feature-utility-network-associations .associationTypes=${e.associationTypes} class=${d(l.contentElement)} .description=${p} .flowItems=${this.flowItems ?? this.internalFlowItems} .graphic=${n ?? void 0} .heading=${h} .headingLevel=${this.headingLevel} .layer=${s} .map=${this.map ?? void 0} .messages=${a} .parentFeatureViewModel=${this.viewModel} .spatialReference=${this.spatialReference ?? void 0} .timeZone=${this.timeZone ?? void 0} .view=${this.viewModel.view ?? void 0}></arcgis-feature-utility-network-associations>`;
  }
  _renderContentElement(e, t) {
    switch (e.type) {
      case "attachments":
        return this.hideAttachmentsContent ? null : this._renderAttachments(e);
      case "custom":
        return this.hideCustomContent ? null : this._renderCustom(e);
      case "fields":
        return this.hideFieldsContent ? null : this._renderFields(e, t);
      case "media":
        return this.hideMediaContent ? null : this._renderMedia(e, t);
      case "text":
        return this.hideTextContent ? null : this._renderText(e);
      case "expression":
        return this.hideExpressionContent ? null : this._renderExpression(e, t);
      case "relationship":
        return this.showRelationshipContent ? this._renderRelationship(e, t) : null;
      case "utility-network-associations":
        return this.showUtilityNetworkContent ? this._renderAssociation(e) : null;
      default:
        return null;
    }
  }
  _renderContent() {
    const { content: e, graphic: t } = this.viewModel;
    return e ? Array.isArray(e) && e.length ? e.length ? e.map(this._renderContentElement, this) : null : typeof e == "string" ? o`<arcgis-feature-content .creator=${e} .graphic=${t ?? void 0} class=${d(l.contentElement)}></arcgis-feature-content>` : e instanceof HTMLElement ? e : null : null;
  }
  _renderContentContainer() {
    const { hideContent: e, internalFlowItems: t, headingLevel: i, state: n, messages: a } = this;
    if (e)
      return null;
    const s = o`<div class=${d(l.main)}>${[this._renderContent(), this._renderLastEditInfo()]}</div>`, r = a.returnToInitialFeature ?? "";
    return this.flowItems ? s : o`<calcite-flow ${M(this._storeRootFlowNode)}><calcite-flow-item .loading=${n === "loading"} .headingLevel=${i} .heading=${this.hideHeading ? void 0 : U(this.heading)} .selected=${!t.length}>${s}</calcite-flow-item>${t.toArray().map((h, p) => o`<calcite-flow-item @calciteFlowItemBack=${(u) => {
      u.preventDefault(), this._handleDrillInBackClick();
    }} .loading=${n === "loading"} .headingLevel=${i} .selected=${p === t.length - 1}><calcite-action appearance=transparent icon=move-up @click=${this._removeFlowItems} slot=header-actions-start .text=${r} title=${r ?? E}></calcite-action>${h}</calcite-flow-item>`)}</calcite-flow>`;
  }
  _renderLastEditInfo() {
    const { hideLastEditedInfo: e, messages: t } = this, { lastEditInfo: i } = this.viewModel;
    if (!i || e)
      return null;
    const { date: n, user: a } = i, s = i.type === "edit" ? a ? t.lastEditedByUser : t.lastEdited : a ? t.lastCreatedByUser : t.lastCreated, r = k(s ?? "", {
      date: n,
      user: a
    });
    return o`<div class=${d(F(l.lastEditedInfo, l.contentElement))}>${r}</div>`;
  }
}
y("arcgis-feature", G);
export {
  G as ArcgisFeature
};
