/* COPYRIGHT Esri - https://js.arcgis.com/1.2/LICENSE.txt */
import { c as d } from "../../chunks/runtime.js";
import { css as u, html as a } from "lit";
import { a as p } from "../../chunks/queryUtils.js";
import { g as m } from "../../chunks/mapViewUtils.js";
import { u as b } from "../../chunks/useT9n.js";
import { createRef as g, ref as f } from "lit-html/directives/ref.js";
import { LitElement as F, createEvent as r, noShadowRoot as w } from "@arcgis/lumina";
const _ = u`@layer{:host{display:block!important}.display-none{display:none}.padding-1{padding:1rem}.position-relative{position:relative}.overflow-auto{overflow:auto}.height-full{height:100%}.position-static{position:static!important}.z-index-500{z-index:500!important}card-manager{display:block}}`;
class C extends F {
  constructor() {
    super(), this.customInfoText = "", this.enableEditGeometry = !1, this.enableSnapping = !1, this.isMobile = !1, this.zoomAndScrollToSelected = !1, this.selectedFeaturesIds = [], this.enableCreateFeatures = !0, this.createBtnLabel = "", this.selectingFeatureFromMap = !1, this.showSketchWidgets = !1, this._cardLoading = !1, this._graphics = [], this._showCreateFeatureComponent = !1, this._showSubmitBtn = !1, this._translations = b({ name: "card-manager", blocking: !0 }), this._isFeatureCreated = !1, this._createFeature = g(), this.createWorkFlowStarted = r(), this.backFromCreateWorkFlow = r(), this.featureOrRecordSubmitted = r(), this.listenOn(window, "featureSelectionChange", this.featureSelectionChange), this.listenOn(window, "layerSelectionChange", this.layerSelectionChange), this.listenOn(window, "relatedRecordToggled", this.relatedRecordToggled);
  }
  static {
    this.properties = { customInfoText: 1, enableEditGeometry: 5, enableSnapping: 5, isMobile: 5, layerOrTable: 0, mapView: 0, zoomAndScrollToSelected: 5, selectedFeaturesIds: 0, enableCreateFeatures: 5, createBtnLabel: 1, selectingFeatureFromMap: 5, showSketchWidgets: 5, _cardLoading: 16, _graphics: 16, _showCreateFeatureComponent: 16, _showSubmitBtn: 16, _translations: 16 };
  }
  static {
    this.styles = _;
  }
  static {
    this.shadowRootOptions = w;
  }
  async featureSelectionChange(e) {
    this._showCreateFeatureComponent && !this._isFeatureCreated && this._backFromCreateFeature();
    const t = e.detail;
    this._graphics = await this._getFeaturesByIds(t);
  }
  async layerSelectionChange(e) {
    this._showCreateFeatureComponent && this._backFromCreateFeature();
    const t = e.detail[0];
    this.layerOrTable = this.mapView ? await m(this.mapView, t) : void 0;
  }
  async relatedRecordToggled(e) {
    const t = e.detail;
    this.layerOrTable = t;
  }
  async load() {
    this.selectedFeaturesIds?.length > 0 && (this._graphics = await this._getFeaturesByIds(this.selectedFeaturesIds));
  }
  render() {
    const e = this._graphics?.length > 0 ? "" : "display-none", t = this._graphics?.length === 0 && this._showCreateFeatureComponent ? "" : "display-none", i = this._graphics?.length > 0 || this._showCreateFeatureComponent ? "display-none" : "", s = this.layerOrTable?.isTable, l = this.customInfoText ? this.customInfoText : this.selectingFeatureFromMap ? this._translations.selectFeaturesFromMapToStart : this._translations.selectFeaturesToStart, n = this.enableCreateFeatures && this.layerOrTable?.capabilities?.operations?.supportsAdd, o = this.createBtnLabel ? this.createBtnLabel : s ? this._translations.createRecord : this._translations.createFeature, c = !this.layerOrTable, h = this.enableSnapping && !this.layerOrTable?.isTable;
    return a`<div class="overflow-auto height-full"><calcite-shell class=${`position-relative ${e}`}><div class="position-static z-index-500 height-full"><info-card .allowEditing=${this.layerOrTable?.editingEnabled} .enableEditGeometry=${this.enableEditGeometry} .enableSnapping=${h} .graphics=${this._graphics} .isLoading=${this._cardLoading} .isMobile=${this.isMobile} .mapView=${this.mapView} position=relative show-close-btn></info-card></div></calcite-shell><calcite-shell class=${`position-relative ${i}`}><calcite-panel><div class=padding-1><calcite-notice .icon=${this.selectingFeatureFromMap ? "map" : "table"} icon-flip-rtl open><div slot=message>${l}</div></calcite-notice></div>${!this.isMobile && n && a`<calcite-button .disabled=${c} @click=${() => this._createFeatureBtnClicked()} slot=footer width=full>${o}</calcite-button>` || ""}</calcite-panel></calcite-shell><calcite-shell class=${`position-relative ${t}`}><calcite-flow-item selected><calcite-panel .heading=${o}><calcite-action appearance=solid class="back-button hydrated" icon=chevron-left @click=${this._backFromCreateFeature} scale=s slot=header-actions-start text></calcite-action>${this.getEditorComponent()}${this._showSubmitBtn && a`<calcite-button appearance=solid class="footer-top-button footer-button" @click=${() => this._createFeature.value && void this._createFeature.value.submit()} slot=footer width=full>${this._translations.create}</calcite-button>` || ""}</calcite-panel></calcite-flow-item></calcite-shell></div>`;
  }
  getEditorComponent() {
    const e = this.enableSnapping && !this.layerOrTable?.isTable && this.enableCreateFeatures;
    return a`<div>${this._showCreateFeatureComponent && a`<create-feature customize-submit .enableSnapping=${e} .mapView=${this.mapView} .isMobile=${this.isMobile} @drawComplete=${() => {
      this._showSubmitBtn = !0;
    }} @editingAttachment=${(t) => {
      this._showSubmitBtn = !t.detail;
    }} @progressStatus=${() => {
      setTimeout(() => {
        this._isFeatureCreated = !1;
      }, 2e3);
    }} @success=${this._featureCreated} .showSketchWidgets=${this.showSketchWidgets} .selectedLayerId=${this.layerOrTable?.id} .showLayerVisibilityMsg=${this.layerOrTable?.visible === !1} ${f(this._createFeature)}></create-feature>` || ""}</div>`;
  }
  async _getFeaturesByIds(e) {
    return (e.length > 0 && this.layerOrTable && this.mapView ? await p(e, this.layerOrTable, [], !0, this.mapView?.spatialReference) : []).sort((i, s) => e.indexOf(Number(i.getObjectId())) - e.indexOf(Number(s.getObjectId())));
  }
  _createFeatureBtnClicked() {
    this._showCreateFeatureComponent = !0, this.createWorkFlowStarted.emit();
  }
  async _backFromCreateFeature() {
    this._createFeature.value && (this._showCreateFeatureComponent = !1, this.backFromCreateWorkFlow.emit()), this._showSubmitBtn = !1;
  }
  _featureCreated() {
    this._showCreateFeatureComponent = !1, this._showSubmitBtn = !1, this._isFeatureCreated = !0, this.featureOrRecordSubmitted.emit(), setTimeout(() => {
      this._showCreateFeatureComponent = !0;
    }, 50);
  }
}
d("card-manager", C);
export {
  C as CardManager
};
