/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
import { c as w } from "../../chunks/runtime.js";
import { g as c, a as u, b as f, c as m, h as b, d as L } from "../../chunks/mapViewUtils.js";
import { a as I } from "../../chunks/queryUtils.js";
import { u as F } from "../../chunks/useT9n.js";
import { css as v, html as a, nothing as _ } from "lit";
import { createRef as d, ref as h } from "lit-html/directives/ref.js";
import { LitElement as $, createEvent as S, noShadowRoot as x, safeClassMap as g } from "@arcgis/lumina";
import "@arcgis/instant-apps-components";
import { defineCustomElements as C } from "@arcgis/instant-apps-components/loader";
import * as E from "@arcgis/core/core/reactiveUtils.js";
import V from "@arcgis/core/layers/support/FeatureFilter.js";
import * as O from "@arcgis/core/rest/identify.js";
import P from "@arcgis/core/rest/support/IdentifyParameters.js";
const k = v`@layer{:host{display:block;--calcite-label-margin-bottom: 0px;--solutions-theme-foreground-color: var(--calcite-color-surface-2)}.width-full{width:100%!important}.height-full{height:100%!important}.notice-msg{padding:10px;width:calc(100% - 20px)}.progress-bar{padding:12px}.footer-top-button{padding-bottom:7px}.footer-button{height:35px}.feature-pagination{background-color:var(--calcite-color-surface-2)!important;border-block-end:1px solid var(--calcite-color-border-3);display:flex;justify-content:center;padding:5px 0}.pagination-count{color:var(--calcite-color-brand);border-bottom:1px solid var(--calcite-color-brand);font-weight:700}.footer-button-container{width:100%;display:flex;gap:10px}.report-submitted-msg{position:absolute;z-index:1000}.share-node{display:flex}.overflow-auto{overflow:auto}}`;
class M extends $ {
  constructor() {
    super(), this.center = "", this.commentButtonText = "", this.commentSubmittedMessage = "", this.defaultWebmap = "", this.description = "", this.enableAnonymousAccess = !1, this.enableAnonymousComments = !1, this.enableComments = !1, this.enableHome = !0, this.enableLogin = !1, this.enableNewReports = !1, this.enableSearch = !0, this.enableSnapping = !1, this.enableZoom = !0, this.isMobile = !1, this.layerExpressions = [], this.layerId = "", this.level = "", this.loginTitle = "", this.mapInfos = [], this.objectId = "", this.reportButtonText = "", this.reportsHeader = "", this.reportSubmittedMessage = "", this.showComments = !1, this.showUserImageInCommentsList = !1, this.showFeatureSymbol = !1, this.showMyReportsOnly = !1, this.submitNewReportsMessage = "", this.theme = "light", this.zoomToScale = 15358, this.floorLevel = "", this.showFullCommentTitle = !0, this.filterByMapExtent = !1, this.sortOption = "newest", this.reportingArea = !1, this.reportingAreaLayer = "", this.reportingAreaMessage = "", this.enablePhotoLocation = !1, this.enableMessageLocation = !1, this.aiImageExtraction = [], this.aiTextExtraction = [], this._featureCreationFailedErrorMsg = "", this._filterActive = !1, this._flowItems = [], this._hasValidLayers = !1, this._reportSubmitted = !1, this._selectedLayerName = "", this._showSubmitCancelButton = !1, this._showLoadingIndicator = !1, this._sidePanelCollapsed = !1, this._translations = F({ name: "crowdsource-reporter", blocking: !0 }), this._updatedProgressBarStatus = 25, this._updatedSortOption = "newest", this._commentSubmitted = !1, this._addingCommentFailed = !1, this._filterOpen = !1, this._showNextButton = !1, this._submitNextButtonDisabled = !1, this._showFilterIcon = !1, this._createFeature = d(), this._currentFeatureId = "", this._editableLayerIds = [], this._featureDetails = d(), this._featureList = d(), this._selectedRelatedFeature = [], this._layerList = d(), this._createRelatedFeature = d(), this._layers = [], this._mapImageryLayersId = [], this._selectedFeature = [], this._selectedFeatureIndex = 0, this._selectedLayerId = "", this._shareNode = d(), this._urlParamsLoaded = !1, this._validLayers = [], this._nonVisibleValidLayers = [], this._showFullPanel = !1, this._floorExpression = "", this._formElements = [], this._prevSelectedLayerId = "", this._t9nLayerExpressions = [], this._reportSubmittedAlertNode = d(), this._commentSubmittedAlertNode = d(), this._sortPopoverNode = d(), this.togglePanel = S(), C(window);
  }
  static {
    this.properties = { center: 1, commentButtonText: 1, commentSubmittedMessage: 1, defaultWebmap: 1, description: 1, enableAnonymousAccess: 5, enableAnonymousComments: 5, enableComments: 5, enableHome: 5, enableLogin: 5, enableNewReports: 5, enableSearch: 5, enableSnapping: 5, enableZoom: 5, isMobile: 5, layerExpressions: 0, layerId: 1, level: 1, loginTitle: 1, mapInfos: 0, mapView: 0, objectId: 1, reportButtonText: 1, reportingOptions: 0, reportsHeader: 1, reportSubmittedMessage: 1, searchConfiguration: 0, showComments: 5, showUserImageInCommentsList: 5, showFeatureSymbol: 5, showMyReportsOnly: 5, submitNewReportsMessage: 1, theme: 1, zoomToScale: 9, floorLevel: 1, showFullCommentTitle: 5, filterByMapExtent: 5, sortOption: 1, reportingArea: 5, reportingAreaLayer: 1, reportingAreaMessage: 1, enablePhotoLocation: 5, enableMessageLocation: 5, aiImageExtraction: 0, aiTextExtraction: 0, sortFields: 0, _featureCreationFailedErrorMsg: 16, _filterActive: 16, _flowItems: 16, _hasValidLayers: 16, _mapInfo: 16, _reportSubmitted: 16, _selectedLayerName: 16, _showSubmitCancelButton: 16, _showLoadingIndicator: 16, _sidePanelCollapsed: 16, _translations: 16, _updatedProgressBarStatus: 16, _updatedSorting: 16, _updatedSortOption: 16, _commentSubmitted: 16, _addingCommentFailed: 16, _filterOpen: 16, _showNextButton: 16, _submitNextButtonDisabled: 16, _showFilterIcon: 16 };
  }
  static {
    this.styles = k;
  }
  static {
    this.shadowRootOptions = x;
  }
  willUpdate(e) {
    e.has("isMobile") && this.isMobileWatchHandler(this.isMobile), e.has("mapView") && this.hasUpdated && this.mapViewWatchHandler(), e.has("floorLevel") && this.floorLevelWatchHandler(), e.has("reportingOptions") && this.hasUpdated && this.reportingOptionsWatchHandler(), (e.has("reportingAreaLayer") || e.has("reportingArea") && this.hasUpdated) && setTimeout(() => {
      this._createFeature.value && this._createFeature.value.refresh(this.floorLevel);
    }, 50), e.has("showMyReportsOnly") && (this.hasUpdated || this.showMyReportsOnly !== !1) && this.showMyReportsOnlyWatchHandler(), e.has("sortOption") && (this.hasUpdated || this.sortOption !== "newest") && this.sortOptionWatchHandler(), e.has("filterByMapExtent") && (this.hasUpdated || this.filterByMapExtent !== !1) && this.filterByMapExtentChangeWatchHandler(), e.has("layerExpressions") && (this.hasUpdated || this.layerExpressions?.length > 0) && this.layerExpressionsWatchHandler(), e.has("showFeatureSymbol") && (this.hasUpdated || this.showFeatureSymbol !== !1) && this.showFeatureSymbolWatchHandler(), (this._flowItems.includes("filter-panel") || this._filterOpen) && this._filterList?.updateInitDefExpressions({ initDefExpressions: this._initDefExpressions }), e.has("sortFields") && this.hasUpdated && this._selectedLayerId && (this._updatedSortOption === "alphabetical" || this._updatedSortOption === "reverseAlphabetical") && this.sortFieldsWatchHandler();
  }
  async isMobileWatchHandler(e) {
    this.updatePanelState(!1, this._showFullPanel), e && this._flowItems[this._flowItems.length - 1] === "filter-panel" ? (await this.backFromFilterPanel(), this._filterOpen = !0) : !e && this._filterOpen && (await this._closeFilter(), this._flowItems = [...this._flowItems, "filter-panel"]);
  }
  async mapViewWatchHandler() {
    await this.mapView?.when(async () => {
      this.setInitExpressions(), await this.setMapView();
    });
  }
  async reportingOptionsWatchHandler() {
    this.setInitExpressions(), await this.setMapView(), this.refreshLists();
  }
  async floorLevelWatchHandler() {
    if (this._editableLayerIds)
      for (const e of this._editableLayerIds) {
        const t = this.mapView && await c(this.mapView, e);
        t && t.floorInfo?.floorField && this._updateFloorDefinitionExpression(t);
      }
    this._flowItems[this._flowItems.length - 1] === "layer-list" && this._layerList.value && await this._layerList.value.refresh(), this._featureList.value && this._featureList.value.refresh(), this._createFeature.value && this._createFeature.value.refresh(this.floorLevel);
  }
  async showMyReportsOnlyWatchHandler() {
    this._editableLayerIds && (await this._updateFeatures(), this.refreshLists());
  }
  async sortOptionWatchHandler() {
    this.updateSortingOptions();
  }
  sortFieldsWatchHandler() {
    const e = this._getConfiguredLayerSortInfo(this._selectedLayerId);
    if (e?.id === this._selectedLayerId && this._flowItems[this._flowItems.length - 1] === "feature-list") {
      if (e?.fields.length > 0) {
        const t = this._updatedSorting?.order === "asc" ? "asc" : "desc";
        this.sortOptionClick(e.fields[0], t, this._updatedSortOption);
      }
    } else this._flowItems[this._flowItems.length - 1] === "feature-list" && this.updateSortingOptions();
  }
  filterByMapExtentChangeWatchHandler() {
    this.refreshLists();
  }
  async layerExpressionsWatchHandler() {
    await this.resetFilterList(), await this.handleSelectedLayersFilter(), await this._featureList.value?.refresh();
  }
  async showFeatureSymbolWatchHandler() {
    await this._featureList.value?.refresh();
  }
  async updateLayerExpressionsT9n(e) {
    if (this._t9nLayerExpressions = e || this.layerExpressions, this._filterList != null)
      await this._filterList.handleUpdatingT9nData(this._t9nLayerExpressions);
    else if (this._currentLayerExpressions != null) {
      const t = structuredClone(this._currentLayerExpressions);
      this.handleLayerExpressionsT9n(t, this._t9nLayerExpressions), this._currentLayerExpressions = t, this._showFilterIcon = this._currentLayerExpressions?.length > 0;
    }
    return Promise.resolve();
  }
  async load() {
    this._urlParamsLoaded = !1, await this.mapView?.when(async () => {
      this._layers = this.reportingOptions ? Object.keys(this.reportingOptions).filter((e) => {
        const t = e && this.reportingOptions && this.reportingOptions[e];
        return t && t.visible;
      }) : [], this.setInitExpressions(), await this.setMapView();
    });
  }
  render() {
    const e = this.theme === "dark" ? "calcite-mode-dark" : "calcite-mode-light";
    return a`${this._reportSubmitted && a`<calcite-alert auto-close class=${`${e} report-submitted-msg`} icon=check-circle kind=success .label=${this._translations.notification} @calciteAlertClose=${() => {
      this._reportSubmitted = !1;
    }} open placement=top><div slot=message .innerHTML=${(this.reportSubmittedMessage || this._translations.submitMsg) ?? ""} ${h(this._reportSubmittedAlertNode)}></div></calcite-alert>` || ""}${this._featureCreationFailedErrorMsg && a`<calcite-alert auto-close class=${g(e)} icon=x-octagon kind=danger .label=${this._translations.notification} @calciteAlertClose=${() => {
      this._featureCreationFailedErrorMsg = "";
    }} open placement=top><div slot=title>${this._translations.error}</div><div slot=message>${this._featureCreationFailedErrorMsg}</div></calcite-alert>` || ""}${this._commentSubmitted && a`<calcite-alert auto-close class=${`report-submitted ${e}`} icon=check-circle kind=success .label=${this._translations.notification} @calciteAlertClose=${() => {
      this._commentSubmitted = !1;
    }} open placement=top><div slot=message .innerHTML=${(this.commentSubmittedMessage || this._translations.commentSubmittedMsg) ?? ""} ${h(this._commentSubmittedAlertNode)}></div></calcite-alert>` || ""}${this._addingCommentFailed && a`<calcite-alert auto-close class=${g(e)} icon=x-octagon kind=danger .label=${this._translations.notification} @calciteAlertClose=${() => {
      this._addingCommentFailed = !1;
    }} open placement=top><div slot=title>${this._translations.error}</div><div slot=message>${this._translations.addingCommentFailedMsg}</div></calcite-alert>` || ""}<div><calcite-shell content-behind>${this._getReporter()}</calcite-shell></div>${this.isMobile && this.filterModal() || ""}`;
  }
  updated() {
    this._adjustAlertStyles();
  }
  async setSelectedLayer(e, t) {
    this._selectedLayerId = e, this._selectedLayer = this.mapView && await c(this.mapView, e), this._selectedLayerName = t, this._validLayers.forEach((i) => {
      this._nonVisibleValidLayers.find((l) => l.id === i.id) || i.set("visible", !e || i.id === e);
    });
  }
  _getLayersConfig(e) {
    return this.reportingOptions && this.reportingOptions[e] ? this.reportingOptions[e] : null;
  }
  _getReporter() {
    const e = [];
    this._flowItems.forEach((i) => {
      switch (i) {
        case "layer-list":
          e.push(this.getLayerListFlowItem());
          break;
        case "feature-list":
          e.push(this.getFeatureListFlowItem(this._selectedLayerId, this._selectedLayerName));
          break;
        case "filter-panel":
          e.push(this.getFilterPanel());
          break;
        case "feature-details":
          e.push(this.getFeatureDetailsFlowItem());
          break;
        case "reporting-layer-list":
          e.push(this.getChooseCategoryFlowItem());
          break;
        case "feature-create":
          e.push(this.getFeatureCreateFlowItem());
          break;
        case "comment-details":
          e.push(this.getCommentDetailsFlowItem());
          break;
        case "add-comment":
          e.push(this.getAddCommentFlowItem());
          break;
      }
    });
    const t = this.theme === "dark" ? "calcite-mode-dark" : "calcite-mode-light";
    return a`<calcite-panel class=${`width-full ${t}`}>${this.mapView ? a`<calcite-flow>${e?.length > 0 && e || ""}</calcite-flow>` : a`<calcite-loader .label=${this._translations.loading} scale=m></calcite-loader>`}</calcite-panel>`;
  }
  filterModal() {
    return (this.layerExpressions ? this.layerExpressions.filter((t) => t.id === this._selectedLayerId) : []).length > 0 && a`<calcite-dialog aria-labelledby=modal-title class="modal" .heading=${this._translations.filterLayerTitle.replace("{{title}}", this._selectedLayerName)} kind=brand @calciteDialogClose=${() => {
      this._closeFilter();
    }} .open=${this._filterOpen} width=s><div>${this.mapView && a`<instant-apps-filter-list close-btn .closeBtnOnClick=${() => {
      this._closeFilter();
    }} combobox-overlay-positioning=fixed .layerExpressions=${this._currentLayerExpressions} @filterListReset=${() => {
      this._filterActive = !1, this._featureList.value && this._featureList.value.refresh();
    }} @filterUpdate=${() => {
      this._filterList?.filterCount !== void 0 && this._handleFilterUpdate(this._filterList?.filterCount > 0);
    }} .view=${this.mapView} ${h(this._setFilterList)}></instant-apps-filter-list>` || ""}</div></calcite-dialog>` || "";
  }
  _setFilterList(e) {
    this._filterList = e, e && (e.autoUpdateUrl = !1, e.resetBtn = this.isMobile, e.resetFiltersOnDisconnect = !1, e.zoomBtn = !1);
  }
  _adjustAlertStyles() {
    this.reportSubmittedMessage && this._reportSubmittedAlertNode.value?.children[0] && (this._reportSubmittedAlertNode.value.children[0].style.margin = "0px"), this.commentSubmittedMessage && this._commentSubmittedAlertNode.value?.children[0] && (this._commentSubmittedAlertNode.value.children[0].style.margin = "0px");
  }
  _toggleFilter() {
    this._filterOpen = !this._filterOpen;
  }
  async _closeFilter() {
    this._filterOpen = !1, this._filterList != null && (this._currentLayerExpressions = await this._filterList.getCurrentLayerExpressions(), this._showFilterIcon = this._currentLayerExpressions?.length > 0);
  }
  async sortOptionClick(e, t, i) {
    this._updatedSorting = {
      field: e,
      order: t
    }, this._updatedSortOption = i, this._sortPopoverNode.value && (this._sortPopoverNode.value.open = !1);
  }
  _getConfiguredLayerSortInfo(e) {
    return this.sortFields && this.sortFields.layers.find((t) => t.id === e) || null;
  }
  _toggleSort() {
    const e = this.reportingOptions && this.reportingOptions[this._selectedLayerId] && this.reportingOptions[this._selectedLayerId].like && this.reportingOptions[this._selectedLayerId].likeField, t = this._getConfiguredLayerSortInfo(this._selectedLayerId);
    return a`<calcite-popover auto-close .label=${this._translations.sortOptions} offset-distance=0 .placement=${this.isMobile ? "leading-start" : "bottom-start"} pointer-disabled reference-element=sort-popover ${h(this._sortPopoverNode)}><calcite-list .label=${this._translations.sortOptions} selection-mode=single-persist><calcite-list-item .label=${this._translations.sortNewest} @calciteListItemSelect=${() => {
      this._selectedLayer && this.sortOptionClick(this._selectedLayer.objectIdField, "desc", "newest");
    }} .selected=${this._updatedSortOption === "newest"} value=newest></calcite-list-item><calcite-list-item .label=${this._translations.sortOldest} @calciteListItemSelect=${() => {
      this._selectedLayer && this.sortOptionClick(this._selectedLayer.objectIdField, "asc", "oldest");
    }} .selected=${this._updatedSortOption === "oldest"} value=oldest></calcite-list-item>${e && a`<calcite-list-item .label=${this._translations.sortHighestVoted} @calciteListItemSelect=${() => {
      const i = this.reportingOptions && this.reportingOptions[this._selectedLayerId].likeField;
      i !== void 0 && this.sortOptionClick(i, "desc", "highestVoted");
    }} .selected=${this._updatedSortOption === "highestVoted"} value=highestVoted></calcite-list-item><calcite-list-item .label=${this._translations.sortLowestVoted} @calciteListItemSelect=${() => {
      const i = this.reportingOptions && this.reportingOptions[this._selectedLayerId].likeField;
      i && this.sortOptionClick(i, "asc", "lowestVoted");
    }} .selected=${this._updatedSortOption === "lowestVoted"} value=lowestVoted></calcite-list-item>` || ""}${t && a`<calcite-list-item .label=${this._translations.sortAlphabetical} @calciteListItemSelect=${() => {
      const i = this._getConfiguredLayerSortInfo(this._selectedLayerId);
      i?.fields && this.sortOptionClick(i.fields[0], "asc", "alphabetical");
    }} .selected=${this._updatedSortOption === "alphabetical"} value=alphabetical></calcite-list-item><calcite-list-item .label=${this._translations.reverseSortAlphabetical} @calciteListItemSelect=${() => {
      const i = this._getConfiguredLayerSortInfo(this._selectedLayerId);
      i?.fields && this.sortOptionClick(i.fields[0], "desc", "reverseAlphabetical");
    }} .selected=${this._updatedSortOption === "reverseAlphabetical"} value=reverseAlphabetical></calcite-list-item>` || ""}</calcite-list></calcite-popover>`;
  }
  async _handleFilterListReset() {
    this._filterActive = !1;
  }
  async _handleFilterUpdate(e) {
    this._showLoadingIndicator = !0, this._filterActive = e, this._featureList.value && await this._featureList.value.refresh(), this._showLoadingIndicator = !1;
  }
  getLayerListFlowItem() {
    return a`<calcite-flow-item .collapsed=${this.isMobile && this._sidePanelCollapsed} .heading=${this.reportsHeader} .loading=${this._showLoadingIndicator} .selected=${this._flowItems[this._flowItems.length - 1] === "layer-list"}>${this.isMobile && this.getActionToExpandCollapsePanel() || ""}${this._hasValidLayers && this.enableNewReports && a`<calcite-button appearance=solid @click=${this.navigateToChooseCategory} slot=footer width=full>${this.reportButtonText ? this.reportButtonText : this._translations.createReportButtonText}</calcite-button>` || ""}<calcite-panel><layer-list .applyLayerViewFilter=${this.showMyReportsOnly} class="height-full" .filterByMapExtent=${this.filterByMapExtent} .layers=${this._editableLayerIds?.length > 0 ? this._editableLayerIds : this._layers} .mapView=${this.mapView} @layerSelect=${this.displayFeaturesList} @layersListLoaded=${this.layerListLoaded} show-feature-count show-next-icon ${h(this._layerList)}></layer-list></calcite-panel></calcite-flow-item>`;
  }
  getChooseCategoryFlowItem() {
    const e = this.reportingOptions ? Object.keys(this.reportingOptions).filter((t) => this.reportingOptions && this.reportingOptions[t].visible && this.reportingOptions[t].reporting && this._layerItemsHash && this._layerItemsHash[t] && this._layerItemsHash[t].supportsAdd) : [];
    return a`<calcite-flow-item .collapsed=${this.isMobile && this._sidePanelCollapsed} .heading=${this.reportButtonText ? this.reportButtonText : this._translations.createReportButtonText} @calciteFlowItemBack=${this.backFromSelectedPanel} .selected=${this._flowItems[this._flowItems.length - 1] === "reporting-layer-list"}><calcite-panel><div class="progress-bar"><calcite-progress type=determinate .value=${this._updatedProgressBarStatus}></calcite-progress></div><calcite-notice class="notice-msg" icon=lightbulb kind=success open><div slot=message>${this._translations.chooseCategoryMsg}</div></calcite-notice><layer-list class="height-full" .layers=${e} .mapView=${this.mapView} @layerSelect=${this.navigateToCreateFeature}></layer-list></calcite-panel></calcite-flow-item>`;
  }
  getFeatureCreateFlowItem() {
    return a`<calcite-flow-item .collapsed=${this.isMobile && this._sidePanelCollapsed} .heading=${this._selectedLayerName} @calciteFlowItemBack=${this.backFromCreateFeaturePanel} .selected=${this._flowItems[this._flowItems.length - 1] === "feature-create"}>${this._showSubmitCancelButton && a`<div class=width-full slot=footer><calcite-button appearance=solid class="footer-top-button footer-button" .disabled=${this._submitNextButtonDisabled} @click=${this._showNextButton ? this.onNextButtonClick.bind(this) : this.onCreateFeatureSubmitButtonClick.bind(this)} width=full>${this._showNextButton ? this._translations.next : this._translations.submit}</calcite-button><calcite-button appearance=outline class=footer-button @click=${this.backFromCreateFeaturePanel} width=full>${this._translations.cancel}</calcite-button></div>` || ""}<calcite-panel><div class="progress-bar"><calcite-progress type=determinate .value=${this._updatedProgressBarStatus}></calcite-progress></div><create-feature app-name=reporter .aiImageExtraction=${this.aiImageExtraction} .aiTextExtraction=${this.aiTextExtraction} class="height-full overflow-auto" customize-submit .enableSearch=${this.enableSearch} .enablePhotoLocation=${this.enablePhotoLocation} .enableMessageLocation=${this.enableMessageLocation} .enableSnapping=${this.enableSnapping} .floorLevel=${this.floorLevel} .formElements=${this._formElements.find((e) => e.id === this._selectedLayerId)} .reportingAreaLayer=${this.reportingAreaLayer} .isMobile=${this.isMobile} .mapView=${this.mapView} @drawComplete=${this.onFormReady} @editingLocation=${this.editingLocation} @editingAttachment=${this.showSubmitCancelButton} @fail=${this.createFeatureFailed} @modeChanged=${this.backFromCreateFeaturePanel} @progressStatus=${this.updatedProgressStatus} @success=${this.onReportSubmitted} .searchConfiguration=${this.searchConfiguration} .selectedLayerId=${this._selectedLayerId} .reportingArea=${this.reportingArea} .reportingAreaMessage=${this.reportingAreaMessage} .submitNewReportsMessage=${this.submitNewReportsMessage} update-map-position ${h(this._createFeature)}></create-feature></calcite-panel></calcite-flow-item>`;
  }
  updatedProgressStatus(e) {
    this._updatedProgressBarStatus = e.detail;
  }
  onFormReady(e) {
    this._submitNextButtonDisabled = e.detail, this._showSubmitCancelButton = !0;
  }
  editingLocation() {
    this._showNextButton = !0;
  }
  showSubmitCancelButton(e) {
    this._showSubmitCancelButton = !e.detail;
  }
  onCreateFeatureSubmitButtonClick() {
    this._createFeature.value && (this._showNextButton = !1, this._createFeature.value.submit());
  }
  backFromCreateFeaturePanel() {
    this._createFeature.value && (this._showSubmitCancelButton = !1, this._showNextButton = !1, this.updateNonVisibleLayersOnMap(!1)), this.backFromSelectedPanel();
  }
  onNextButtonClick() {
    this._createFeature.value && (this._showNextButton = !1, this._showSubmitCancelButton = !0, this._createFeature.value.showForm());
  }
  onCreateRelatedFeatureSubmitButtonClick() {
    this._createRelatedFeature.value && this._createRelatedFeature.value.submit();
  }
  backFromCreateRelatedFeaturePanel() {
    this._createRelatedFeature.value && (this._showSubmitCancelButton = !1), this.backFromSelectedPanel();
  }
  createFeatureFailed(e) {
    console.error(e.detail), this._showSubmitCancelButton = !1, this._featureCreationFailedErrorMsg = e.detail.message;
  }
  async onReportSubmitted() {
    this._showSubmitCancelButton = !1, this.updateNonVisibleLayersOnMap(!1), await this.navigateToHomePage(), this._reportSubmitted = !0, this._updatedProgressBarStatus = 25, this._showFullPanel && this.updatePanelState(this._sidePanelCollapsed, !1);
  }
  addCommentFailed(e) {
    console.error(e.detail), this._addingCommentFailed = !0;
  }
  async onCommentSubmitted() {
    this._commentSubmitted = !0, this.backFromCreateRelatedFeaturePanel(), this._showLoadingIndicator = !0, this._featureDetails.value && await this._featureDetails.value.refresh(this._currentFeature), setTimeout(() => {
      this._showLoadingIndicator = !1;
    }, 300);
  }
  async navigateToHomePage() {
    if (await this.setSelectedFeatures([]), this._editableLayerIds.length === 1)
      this._featureList.value && await this._featureList.value.refresh(), this._flowItems = ["feature-list"];
    else {
      const e = this.mapView && await c(this.mapView, this._prevSelectedLayerId);
      this.floorLevel && e?.floorInfo?.floorField && this._updateFloorDefinitionExpression(e), this._layerList.value && await this._layerList.value.refresh(), this._flowItems = ["layer-list"];
    }
  }
  async navigateToCreateFeature(e) {
    e.detail.layerId && e.detail.layerName && await this.setSelectedLayer(e.detail.layerId, e.detail.layerName), this.updateNonVisibleLayersOnMap(!0), this._getFormElements(), this._showSubmitCancelButton = !1, this._showNextButton = !1, this.updatePanelState(!1, !0), this._flowItems = [...this._flowItems, "feature-create"];
  }
  navigateToChooseCategory() {
    this.updatePanelState(!1, !0), this._flowItems = [...this._flowItems, "reporting-layer-list"];
  }
  updateNonVisibleLayersOnMap(e) {
    this._nonVisibleValidLayers.find((i) => i.id === this._selectedLayerId) && this._selectedLayer && this._selectedLayer.set("visible", e);
  }
  async layerListLoaded(e) {
    if (this._layerList.value && this._flowItems[this._flowItems.length - 1] === "layer-list" || this._flowItems[0] === "feature-list") {
      const i = e.detail, s = this.mapView && await u(this.mapView), l = [];
      if (this._validLayers = [], this._nonVisibleValidLayers = [], s?.forEach((r) => {
        i.includes(r.id) && (this._validLayers.push(r), r.visible || this._nonVisibleValidLayers.push(r), this._getLayersConfig(r.id)?.reporting && this._layerItemsHash && this._layerItemsHash[r.id] && this._layerItemsHash[r.id].supportsAdd && l.push(r.id));
      }), this.handleMapClick(), this._hasValidLayers = l.length > 0, !this._urlParamsLoaded && this._editableLayerIds.length > 1 && this.layerId && this.objectId) {
        const r = this.mapView && await c(this.mapView, this.layerId);
        r && await this.displayFeaturesList({
          detail: {
            layerId: r.id,
            layerName: r.title
          }
        }), this._urlParamsLoaded = !0, await this.loadFeatureFromURLParams();
      }
    }
  }
  async displayFeaturesList(e) {
    this._showLoadingIndicator = !0, await this.setSelectedLayer(e.detail.layerId, e.detail.layerName), this.updateSortingOptions(), this.handleSelectedLayersFilter(), this._flowItems = [...this._flowItems, "feature-list"], this._prevSelectedLayerId = this._selectedLayerId, this._showLoadingIndicator = !1;
  }
  updateSortingOptions() {
    const e = this.sortOption === "" ? "newest" : this.sortOption, t = e === "oldest" || e === "lowestVoted" || e === "alphabetical" ? "asc" : "desc", i = this.reportingOptions?.[this._selectedLayerId]?.like ? this.reportingOptions?.[this._selectedLayerId]?.likeField : "", l = this._getConfiguredLayerSortInfo(this._selectedLayerId)?.fields?.[0] || "", r = this._selectedLayer && (e === "newest" || e === "oldest") ? this._selectedLayer?.objectIdField : e === "alphabetical" || e === "reverseAlphabetical" ? l : i, n = !!i && (e === "highestVoted" || e === "lowestVoted"), o = !!l && (e === "alphabetical" || e === "reverseAlphabetical");
    this._updatedSorting = {
      field: r || "",
      order: t
    }, this._updatedSortOption = n || o || !(e === "highestVoted" || e === "lowestVoted" || e === "alphabetical" || e === "reverseAlphabetical") ? e : "newest";
  }
  async backFromFilterPanel() {
    this._filterList != null && (this._currentLayerExpressions = await this._filterList.getCurrentLayerExpressions(), this._showFilterIcon = this._currentLayerExpressions?.length > 0), this._featureList.value && await this._featureList.value.refresh(), this.backFromSelectedPanel();
  }
  backFromSelectedPanel() {
    this._updatedProgressBarStatus = 25;
    const e = [...this._flowItems];
    if (e[e.length - 1] === "comment-details" || e[e.length - 1] === "add-comment" || this.clearHighlights(), (e[e.length - 1] === "reporting-layer-list" || e[e.length - 1] === "feature-create" && (e[0] === "feature-list" || e[e.length - 2] === "feature-list")) && this.updatePanelState(this._sidePanelCollapsed, !1), e.pop(), e.length === 1 && e[0] === "layer-list") {
      this.navigateToHomePage();
      return;
    }
    this._flowItems = [...e];
  }
  toggleSidePanel() {
    this._sidePanelCollapsed = !this._sidePanelCollapsed, this.togglePanel.emit({ panelState: this._sidePanelCollapsed, isFormOpen: this._showFullPanel });
  }
  updatePanelState(e, t) {
    this._sidePanelCollapsed = e, this._showFullPanel = t, this.togglePanel.emit({ panelState: this._sidePanelCollapsed, isFormOpen: this._showFullPanel });
  }
  async onFeatureSelectFromList(e) {
    await this.setSelectedFeatures([e.detail]), this._flowItems = [...this._flowItems, "feature-details"];
  }
  async getRelatedTable() {
    const e = this._currentFeature?.layer, t = this.mapView && await f(this.mapView);
    e.relationships?.some((i) => {
      const s = t?.filter((l) => e.url === l.url && l.layerId === i.relatedTableId);
      return s && s.length > 0 ? (this._relatedTable = s[0], !0) : !1;
    });
  }
  async updatingFeatureDetails(e) {
    this._showLoadingIndicator = e;
  }
  async selectionChanged(e) {
    this.updatingFeatureDetails(!0), await this.setCurrentFeature(e.detail.selectedFeature[0]), this.highlightOnMap(e.detail.selectedFeature[0]), this._selectedFeatureIndex = e.detail.selectedFeatureIndex, this._featureDetails.value && await this._featureDetails.value.refresh(e.detail.selectedFeature[0]);
  }
  showAddCommentsPanel() {
    this._flowItems = [...this._flowItems, "add-comment"];
  }
  async onCommentSelectFromList(e) {
    this._selectedRelatedFeature = [e.detail], this._flowItems = [...this._flowItems, "comment-details"];
  }
  getFeatureListFlowItem(e, t) {
    const i = this._getLayersConfig(this._selectedLayerId)?.reporting && this._layerItemsHash && this._layerItemsHash[this._selectedLayerId].supportsAdd, s = this._showFilterIcon;
    return a`<calcite-flow-item .collapsed=${this.isMobile && this._sidePanelCollapsed} .heading=${t} .loading=${!this.isMobile && this._showLoadingIndicator} @calciteFlowItemBack=${this.backFromSelectedPanel} .selected=${this._flowItems[this._flowItems.length - 1] === "feature-list"}>${this._toggleSort()}<calcite-action icon=sort-ascending-arrow id=sort-popover slot=header-actions-end .text=${this._translations.sort} title=${this._translations.sort ?? _}></calcite-action>${s && a`<calcite-action icon=filter .indicator=${this._filterActive} @click=${() => {
      this.isMobile ? this._toggleFilter() : this._flowItems = [...this._flowItems, "filter-panel"];
    }} slot=header-actions-end .text=${this._translations.filter} title=${this._translations.filter ?? _}></calcite-action>` || ""}${this.isMobile && this.getActionToExpandCollapsePanel() || ""}${this.enableNewReports && i && a`<calcite-button appearance=solid @click=${this.navigateToCreateFeature} slot=footer width=full>${this.reportButtonText ? this.reportButtonText : this._translations.createReportButtonText}</calcite-button>` || ""}<calcite-panel>${a`<feature-list .applyLayerViewFilter=${this.showMyReportsOnly} class="height-full" .filterByMapExtent=${this.filterByMapExtent} highlight-on-hover .mapView=${this.mapView} .noFeaturesFoundMsg=${this._translations.featureErrorMsg} @featureClick=${() => {
      this._showLoadingIndicator = !0;
    }} @featureSelect=${this.onFeatureSelectFromList} page-size=30 .reportingOptions=${this.reportingOptions} .selectedLayerId=${e} show-error-when-no-features .showFeatureSymbol=${this.showFeatureSymbol} .sortingInfo=${this._updatedSorting} ${h(this._featureList)}></feature-list>`}</calcite-panel></calcite-flow-item>`;
  }
  getFilterPanel() {
    return a`<calcite-flow-item .collapsed=${this.isMobile && this._sidePanelCollapsed} .heading=${this._translations.filterLayerTitle.replace("{{title}}", this._selectedLayerName)} .loading=${this._showLoadingIndicator} @calciteFlowItemBack=${this.backFromFilterPanel} .selected=${this._flowItems[this._flowItems.length - 1] === "filter-panel"}>${this.isMobile && this.getActionToExpandCollapsePanel() || ""}<div class=width-full slot=footer><div class=width-full slot=footer><calcite-button appearance=solid class="footer-top-button footer-button" .disabled=${!this._filterActive} @click=${this.resetFilterList} width=full>${this._translations.resetFilter}</calcite-button><calcite-button appearance=outline class=footer-button @click=${this.backFromFilterPanel} width=full>${this._translations.close}</calcite-button></div></div><calcite-panel>${this.mapView && a`<instant-apps-filter-list .closeBtnOnClick=${() => {
    }} combobox-overlay-positioning=fixed .layerExpressions=${this._currentLayerExpressions} @filterListReset=${() => {
      this._handleFilterListReset();
    }} @filterUpdate=${() => {
      const e = this._filterList?.filterCount;
      e !== void 0 && this._handleFilterUpdate(e > 0);
    }} .view=${this.mapView} ${h(this._setFilterList)}></instant-apps-filter-list>` || ""}</calcite-panel></calcite-flow-item>`;
  }
  getFeatureDetailsFlowItem() {
    const e = this._selectedLayer?.relationships, t = this._getLayersConfig(this._selectedLayerId)?.comment && e && e.length > 0 && this._relatedTable;
    return a`<calcite-flow-item .collapsed=${this.isMobile && this._sidePanelCollapsed} .heading=${this._selectedLayerName} .loading=${this._showLoadingIndicator} @calciteFlowItemBack=${this.backFromSelectedPanel} .selected=${this._flowItems[this._flowItems.length - 1] === "feature-details"}>${this.isMobile && this.getActionToExpandCollapsePanel() || ""}${this.mapView && a`<instant-apps-social-share class=share-node flip-rtl popover-button-icon-scale=s remove-popover-offset scale=m share-button-color=neutral share-button-type=action slot=header-actions-end social-media .view=${this.mapView} ${h(this._shareNode)}></instant-apps-social-share>` || ""}${this._selectedFeature.length > 1 && this.getFeaturesPagination() || ""}<calcite-panel><feature-details class=full-height .enableSnapping=${this.enableSnapping} .graphics=${this._selectedFeature} .layerItemsHash=${this._layerItemsHash} .mapView=${this.mapView} @addComment=${this.showAddCommentsPanel} @commentClick=${() => {
      this._showLoadingIndicator = !0;
    }} @commentSelect=${this.onCommentSelectFromList} @featureSelectionChange=${this.selectionChanged} @likeOrDislikeClicked=${() => {
      this._featureList.value && this._featureList.value.refresh(!0);
    }} @loadingStatus=${(i) => {
      this.updatingFeatureDetails(i.detail);
    }} .reportingOptions=${this.reportingOptions} .showFullCommentTitle=${this.showFullCommentTitle} .showUserImageInCommentsList=${this.showUserImageInCommentsList} ${h(this._featureDetails)}></feature-details>${t && a`<calcite-button appearance=solid @click=${this.showAddCommentsPanel} slot=footer width=full>${this.commentButtonText || this._translations.comment}</calcite-button>` || ""}</calcite-panel></calcite-flow-item>`;
  }
  getFeaturesPagination() {
    return a`<div class="feature-pagination"><div><calcite-button appearance=transparent icon-start=chevron-left icon-flip-rtl=both id=solutions-back .label=${this._translations.back} @click=${() => this._featureDetails.value && void this._featureDetails.value.back()} scale=s width=full></calcite-button><calcite-tooltip placement=top reference-element=solutions-back><span>${this._translations.back}</span></calcite-tooltip></div><calcite-button appearance=transparent .label=${this._translations.toggleListView} @click=${() => this._featureDetails.value && void this._featureDetails.value.toggleListView()} scale=s><span class="pagination-count">${this._getCount()}</span></calcite-button><div><calcite-button appearance=transparent icon-flip-rtl=both icon-start=chevron-right id=solutions-next .label=${this._translations.next} @click=${() => this._featureDetails.value && void this._featureDetails.value.next()} scale=s width=full></calcite-button><calcite-tooltip placement=top reference-element=solutions-next><span>${this._translations.next}</span></calcite-tooltip></div></div>`;
  }
  getCommentDetailsFlowItem() {
    return a`<calcite-flow-item .collapsed=${this.isMobile && this._sidePanelCollapsed} .heading=${this._relatedTable?.title || ""} @calciteFlowItemBack=${this.backFromSelectedPanel} .selected=${this._flowItems[this._flowItems.length - 1] === "comment-details"}>${this.isMobile && this.getActionToExpandCollapsePanel() || ""}<calcite-panel><info-card .enableSnapping=${this.enableSnapping} .graphics=${this._selectedRelatedFeature} .mapView=${this.mapView} @selectionChanged=${() => {
      this._showLoadingIndicator = !1;
    }}></info-card></calcite-panel></calcite-flow-item>`;
  }
  getAddCommentFlowItem() {
    return a`<calcite-flow-item .collapsed=${this.isMobile && this._sidePanelCollapsed} .heading=${this._relatedTable?.title || ""} @calciteFlowItemBack=${this.backFromCreateRelatedFeaturePanel} .selected=${this._flowItems[this._flowItems.length - 1] === "add-comment"}>${this.isMobile && this.getActionToExpandCollapsePanel() || ""}<div class=width-full slot=footer>${this._showSubmitCancelButton && a`<div class=width-full slot=footer><calcite-button appearance=solid class="footer-top-button footer-button" @click=${this.onCreateRelatedFeatureSubmitButtonClick} width=full>${this._translations.submit}</calcite-button><calcite-button appearance=outline class=footer-button @click=${this.backFromCreateRelatedFeaturePanel} width=full>${this._translations.cancel}</calcite-button></div>` || ""}</div><calcite-panel><create-related-feature customize-submit .enableSnapping=${this.enableSnapping} .mapView=${this.mapView} @fail=${this.addCommentFailed} @formReady=${this.onFormReady} @isActionPending=${this.showSubmitCancelButton} @success=${this.onCommentSubmitted} .selectedFeature=${this._currentFeature} .table=${this._relatedTable} ${h(this._createRelatedFeature)}></create-related-feature></calcite-panel></calcite-flow-item>`;
  }
  async setSelectedFeatures(e) {
    this._selectedFeature = e, await this.setCurrentFeature(this._selectedFeature.length ? this._selectedFeature[0] : void 0);
  }
  async setCurrentFeature(e) {
    if (this._currentFeature = e, e && e.layer) {
      const t = e.layer;
      t.title && this.setSelectedLayer(t.id, t.title), this._currentFeatureId = e.attributes[t.objectIdField], this._getLayersConfig(t.id)?.comment && t.relationships && t.relationships.length > 0 && await this.getRelatedTable();
    } else
      this._editableLayerIds.length > 1 && (this.setSelectedLayer("", ""), this.handlePrevLayersFilter()), this._currentFeatureId = "";
    this._updateShareURL();
  }
  async highlightOnMap(e) {
    if (this.clearHighlights(), e && e.geometry && e.layer && e.layer.id !== void 0) {
      const t = this.mapView && await m(this.mapView, e.layer.id.toString());
      if (t) {
        const i = Number(e.getObjectId());
        this._highlightHandle = this.mapView && await b([i], t, this.mapView, !0, this.zoomToScale);
      }
    }
    this.updatingFeatureDetails(!1);
  }
  clearHighlights() {
    this._highlightHandle && this._highlightHandle.remove();
  }
  getActionToExpandCollapsePanel() {
    return a`<calcite-action .icon=${this._sidePanelCollapsed ? "chevrons-up" : "chevrons-down"} @click=${this.toggleSidePanel} slot=header-actions-end .text=${(this._sidePanelCollapsed ? this._translations.expand : this._translations.collapse) || ""}></calcite-action>`;
  }
  async setMapView() {
    this.mapView && await f(this.mapView), await this.getLayersToShowInList(), await this._updateFeatures(), this._editableLayerIds?.length === 1 ? await this.renderFeaturesList() : this._flowItems = ["layer-list"], this.mapView && (this.mapView.popupEnabled = !1, this._defaultCenter && this._defaultLevel && (await this.mapView.goTo({
      center: this._defaultCenter,
      zoom: this._defaultLevel
    }), this._defaultCenter = void 0, this._defaultLevel = void 0));
  }
  handleMapClick() {
    this._mapClickHandle && this._mapClickHandle.remove(), this._mapClickHandle = E.on(() => this.mapView, "click", (e) => {
      this.mapView && (this.mapView.popupEnabled = !1), this.onMapClick(e);
    });
  }
  async onMapClick(e) {
    if (!(this._flowItems[this._flowItems.length - 1] === "feature-create" || this._flowItems[this._flowItems.length - 1] === "add-comment") && this.mapView) {
      const t = await this.mapView.hitTest(e), i = [];
      let s = [], l = [], r = !1;
      t.results.length > 0 && t.results.forEach((o) => {
        o.type === "graphic" && i.push(o.graphic);
      }), i.length > 0 && (await this._setReportingGraphics(i), s = this._getNonReportingLayerGraphics(i)), this._mapImageryLayersId.length > 0 && (l = await this._getIdentifiedGraphics(e.mapPoint), r = l.length > 0);
      const n = s.concat(l);
      if (n.length > 0) {
        this.mapView.popupEnabled = !0;
        const o = {
          features: n,
          location: e.mapPoint,
          updateLocationEnabled: !r
          // if identify graphics is present then dont update location
        };
        await this.mapView.openPopup(o);
      }
    }
  }
  async _setReportingGraphics(e) {
    const t = e.filter((i) => {
      if (i.layer?.type === "feature") {
        const s = i.layer;
        return this._validLayers.includes(s);
      } else
        return !1;
    });
    this._selectedLayer && this._selectedFeature.length > 0 && this._selectedLayer.id === t[0]?.layer?.id && t[0].attributes[this._selectedLayer.objectIdField] === this._selectedFeature[0].attributes[this._selectedLayer.objectIdField] || t.length > 0 && (await this.setSelectedFeatures(t), this._flowItems.length && this._flowItems.includes("feature-details") ? (this._flowItems = [...this._flowItems.slice(0, this._flowItems.indexOf("feature-details") + 1)], await this.highlightOnMap(e[0])) : this._flowItems = [...this._flowItems, "feature-details"]);
  }
  _getNonReportingLayerGraphics(e) {
    return e.filter((i) => {
      if (i.layer?.type === "feature") {
        const s = i.layer;
        return !this._validLayers.includes(s) && s?.popupEnabled && s?.id;
      } else
        return !1;
    });
  }
  async _getIdentifiedGraphics(e) {
    const t = new P({
      geometry: e,
      tolerance: 3,
      mapExtent: this.mapView?.extent
    });
    let i, s = [];
    for (const r of this._mapImageryLayersId) {
      const n = this.mapView && await c(this.mapView, r);
      if (n?.url && t)
        try {
          const o = await O?.identify(n.url, t);
          if (o?.results?.length) {
            s = o.results, i = n;
            break;
          }
        } catch (o) {
          console.error(o);
        }
    }
    const l = [];
    return s.forEach((r) => {
      const n = r.layerId, o = i?.sublayers?.items.find((y) => y.id === n), p = o?.popupTemplate;
      o?.popupEnabled && p && (r.feature.popupTemplate = p, l.push(r.feature));
    }), l;
  }
  _getCount() {
    const e = (this._selectedFeatureIndex + 1).toString(), t = this._selectedFeature.length.toString();
    return this._translations.indexOfTotal.replace("{{index}}", e).replace("{{total}}", t);
  }
  _updateFloorDefinitionExpression(e) {
    const i = `${e?.floorInfo?.floorField} = '${this.floorLevel}'`, s = e.definitionExpression;
    e.definitionExpression = s && s?.indexOf(this._floorExpression) > -1 ? s.replace(this._floorExpression, i) : i, this._floorExpression = i;
  }
  _getFormElements() {
    const e = this._selectedLayer;
    if (e?.floorInfo?.floorField && this.floorLevel && e?.formTemplate) {
      const i = this._formElements.find((s) => s.id === e.id);
      (this._formElements.length === 0 || !i) && this._formElements.push({
        id: e.id,
        orgElements: e.formTemplate.elements,
        orgExpressionInfos: e.formTemplate.expressionInfos
      });
    }
  }
  reduceToConfiguredLayers(e, t) {
    return Object.keys(e).reduce((i, s) => {
      const l = this.reportingOptions ? this._getLayersConfig(s)?.visible : e[s].supportsAdd;
      return !t.includes(s) && l && i.push(s), i;
    }, []);
  }
  refreshLists() {
    setTimeout(() => {
      this._layerList.value && this._flowItems[this._flowItems.length - 1] === "layer-list" && this._layerList.value.refresh(), this._featureList.value && this._featureList.value.refresh();
    }, 50);
  }
  async _updateFeatures() {
    for (const e of this._editableLayerIds) {
      const t = this.mapView && await m(this.mapView, e);
      t && (await this._showMyFeaturesOnly(t), t.layer?.floorInfo?.floorField && this.floorLevel && this._updateFloorDefinitionExpression(t.layer));
    }
  }
  async _showMyFeaturesOnly(e) {
    const t = (this.mapView?.map).portalItem.portal?.credential?.userId;
    if (t && e) {
      const i = e.layer.editFieldsInfo?.creatorField.toLowerCase();
      e.filter = this.showMyReportsOnly && i ? new V({
        where: `${i} = '${t}'`
      }) : null;
    }
  }
  async getLayersToShowInList() {
    const e = this.mapView && await L(this.mapView, !1), t = this.mapView && await u(this.mapView), i = [];
    t?.forEach((s) => {
      s?.type === "feature" && s?.editingEnabled && s?.capabilities?.operations?.supportsAdd && (e[s.id].supportsAdd = !0), s?.editingEnabled || i.push(s.id);
    }), this._editableLayerIds = this.reduceToConfiguredLayers(e, i), this._layerItemsHash = e;
  }
  async renderFeaturesList() {
    this._flowItems = ["feature-list"];
    const e = {
      detail: this._editableLayerIds
    };
    await this.layerListLoaded(e), await this.setSelectedLayer(this._validLayers[0].id, this._validLayers[0]?.title || ""), this.updateSortingOptions(), await this.handleSelectedLayersFilter(), this._urlParamsLoaded || (this._urlParamsLoaded = !0, await this.loadFeatureFromURLParams());
  }
  _updateShareURL() {
    const e = this._shareNode.value?.shareUrl;
    if (!e)
      return;
    const t = new URL(e);
    this._selectedLayerId ? t.searchParams.set("layerid", this._selectedLayerId) : t.searchParams.delete("layerid"), this._selectedFeature?.length ? t.searchParams.set("oid", this._currentFeatureId) : t.searchParams.delete("oid"), this._shareNode.value && (this._shareNode.value.autoUpdateShareUrl = !1, this._shareNode.value.shareUrl = t.href);
  }
  async loadFeatureFromURLParams() {
    if (this.center && this.level && await this.mapView?.goTo({
      center: this.center.split(";").map(Number),
      zoom: parseInt(this.level, 10)
    }), this.layerId && this.objectId) {
      const e = this.mapView && await c(this.mapView, this.layerId);
      if (e) {
        const t = this.mapView && await I([Number(this.objectId)], e, [], !0, this.mapView.spatialReference);
        t?.length && (await this.setSelectedFeatures(t), this._flowItems.length && this._flowItems[this._flowItems.length - 1] !== "feature-details" ? this._flowItems = [...this._flowItems, "feature-details"] : this._flowItems = [...this._flowItems]);
      }
    }
  }
  async handleSelectedLayersFilter() {
    if (this._selectedLayer) {
      const e = this.layerExpressions ? structuredClone(this.layerExpressions.filter((t) => t.id === this._selectedLayerId)) : [];
      this._t9nLayerExpressions != null && this.handleLayerExpressionsT9n(e, this._t9nLayerExpressions), this._currentLayerExpressions = e, this._showFilterIcon = this._currentLayerExpressions?.length > 0, this.setActiveDefinitionExpressions();
    }
  }
  async handlePrevLayersFilter() {
    if (this._prevSelectedLayerId) {
      const e = this.mapView && await c(this.mapView, this._prevSelectedLayerId);
      e && this._initDefExpressions && (e.definitionExpression = this._initDefExpressions[this._prevSelectedLayerId]);
    }
  }
  async resetFilterList() {
    await this._filterList?.forceReset(), this._selectedLayer !== void 0 && this._initDefExpressions && (this._selectedLayer.definitionExpression = this._initDefExpressions[this._selectedLayerId], this._filterActive = !1);
  }
  setActiveDefinitionExpressions() {
    if (this._selectedLayer === void 0)
      return;
    const e = [];
    if (this._currentLayerExpressions && this._currentLayerExpressions?.length > 0) {
      const t = this._currentLayerExpressions[0];
      for (const i of t.expressions) {
        const { active: s, definitionExpression: l } = i;
        s && l && e.push(`(${l})`);
      }
      this._filterActive = e.length > 0, this.updateFilterLayerDefExpression(e, t.operator);
    }
  }
  updateFilterLayerDefExpression(e, t) {
    const i = this._initDefExpressions && this._initDefExpressions[this._selectedLayerId], s = e?.length > 0 && i ? `(${e.join(t)}) AND (${i})` : e.length > 0 ? e.join(t) : i;
    this._selectedLayer && (this._selectedLayer.definitionExpression = s);
  }
  setInitExpressions() {
    if (this._initDefExpressions = {}, this.mapView == null)
      return;
    const e = this.mapView.map;
    e.allLayers.concat(e.allTables.toArray()).forEach((t) => {
      if (t.type === "map-image" && t.popupEnabled && !this._mapImageryLayersId.includes(t.id)) {
        this._mapImageryLayersId.push(t.id);
        return;
      }
      if (t.type !== "feature")
        return;
      const i = t;
      this._initDefExpressions && (this._initDefExpressions[i.id] = i.definitionExpression || "");
    });
  }
  handleLayerExpressionsT9n(e, t) {
    e?.forEach((i) => {
      const s = t?.find((l) => l.id === i.id);
      s != null && (i.title = s.title, i.expressions?.forEach((l) => {
        const r = s.expressions?.find((n) => n.id === l.id);
        r != null && (l.name = r.name);
      }));
    });
  }
}
w("crowdsource-reporter", M);
export {
  M as CrowdsourceReporter
};
