/* COPYRIGHT Esri - https://js.arcgis.com/1.2/LICENSE.txt */
import { c as customElement } from "../../chunks/runtime.js";
import { a as getAllFeatureLayers, g as getLayerOrTable } from "../../chunks/mapViewUtils.js";
import { u as useT9n } from "../../chunks/useT9n.js";
import { css, html } from "lit";
import { createRef, ref } from "lit-html/directives/ref.js";
import { LitElement, createEvent, noShadowRoot, safeClassMap } from "@arcgis/lumina";
import Editor from "@arcgis/core/widgets/Editor";
import ExpressionInfo from "@arcgis/core/form/ExpressionInfo";
import FeatureLayer from "@arcgis/core/layers/FeatureLayer";
import FieldElement from "@arcgis/core/form/elements/FieldElement";
import FormTemplate from "@arcgis/core/form/FormTemplate";
import MapView from "@arcgis/core/views/MapView";
import Home from "@arcgis/core/widgets/Home";
import Search from "@arcgis/core/widgets/Search";
import * as reactiveUtils from "@arcgis/core/core/reactiveUtils";
const styles = css`@layer{
/** @license
 * Copyright 2025 Esri
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

:host {
  display: block;
}

/* Override to hide Editor settings panel collapsible */
.hide-editor-toolbar .esri-editor__panel-toolbar {
  display: none !important;
}

/* Override to reduce the padding of panel content*/
.esri-editor__panel-content {
  padding-block: 0px !important;
}

/* Override to hide header */
.esri-editor .esri-item-list__group__header {
  display: none !important;
}

/* Override to hide the create feature heading title */
.esri-editor__panel-content__section .esri-widget__heading {
  display: none !important;
}

/* Override to reduce padding for the template filter*/
.esri-editor .esri-item-list__filter-container--sticky {
  padding-block: 0px !important;
  padding-inline: 10px !important;
}

.search-widget {
  width: 92% !important;
  margin: 5px 14px 20px 14px;
}

.display-none {
  display: none !important;
}

.hide-map {
  height: 1%;
  visibility: hidden;
}

.show-map {
  padding: 10px !important;
  position: absolute !important;
  bottom: 0;
  height: auto !important;
  width: calc(100% - 22px);
}

.notice-msg {
  padding: 10px;
  width: calc(100% - 20px);
}

.edit-location-btn {
  margin: 5px;
  display: flex;
}

/* override the padding of the feature form */
.esri-editor__panel-content {
  padding-block: 10px !important;
}

/* overide css for editor widget in case of mobile */
@media only screen and (max-width: 600px) {
  .esri-editor__panel-content {
    padding-block: 0 !important;
    min-height: 0 !important;
  }
}
}`;
class CreateFeature extends LitElement {
  constructor() {
    super(...arguments);
    this.customizeSubmit = false;
    this.enableSearch = false;
    this.enableSnapping = false;
    this.floorLevel = "";
    this.isMobile = false;
    this.selectedLayerId = "";
    this.showGuidingMsg = true;
    this.submitNewReportsMessage = "";
    this.updateMapPosition = false;
    this.reportingArea = false;
    this.reportingAreaLayer = "";
    this.reportingAreaMessage = "";
    this.showSketchWidgets = false;
    this.allowMultipleCreation = false;
    this.popupEnabled = false;
    this.showLayerVisibilityMsg = false;
    this._currentPage = "templatePicker";
    this._editorLoading = false;
    this._inValidGeomtryDrawn = false;
    this._translations = useT9n({ name: "create-feature", blocking: true });
    this._addingAttachment = false;
    this._calciteNotice = createRef();
    this._isSubmitBtnClicked = false;
    this._mapViewContainer = createRef();
    this._searchDiv = createRef();
    this._guidingMessageRefNode = createRef();
    this.success = createEvent();
    this.fail = createEvent();
    this.drawComplete = createEvent();
    this.editingLocation = createEvent();
    this.editingAttachment = createEvent();
    this.progressStatus = createEvent();
    this.modeChanged = createEvent();
  }
  static {
    this.properties = { customizeSubmit: [5, {}, { type: Boolean }], enableSearch: [5, {}, { type: Boolean }], enableSnapping: [5, {}, { type: Boolean }], floorLevel: 1, formElements: 1, isMobile: [5, {}, { type: Boolean }], mapView: [0, {}, { attribute: false }], searchConfiguration: [0, {}, { attribute: false }], selectedLayerId: 1, showGuidingMsg: [5, {}, { type: Boolean }], submitNewReportsMessage: 1, updateMapPosition: [5, {}, { type: Boolean }], reportingArea: [5, {}, { type: Boolean }], reportingAreaLayer: 1, reportingAreaMessage: 1, showSketchWidgets: [5, {}, { type: Boolean }], allowMultipleCreation: [5, {}, { type: Boolean }], popupEnabled: [5, {}, { type: Boolean }], showLayerVisibilityMsg: [5, {}, { type: Boolean }], _currentPage: [16, {}, { state: true }], _editorLoading: [16, {}, { state: true }], _inValidGeomtryDrawn: [16, {}, { state: true }], _translations: [16, {}, { state: true }] };
  }
  static {
    this.styles = styles;
  }
  static {
    this.shadowRootOptions = noShadowRoot;
  }
  willUpdate(changes) {
    if (changes.has("mapView") && this.hasUpdated) {
      void this.mapViewWatchHandler();
    }
    if (changes.has("isMobile") && this.hasUpdated) {
      void this.isMobileHandler();
    }
    if (changes.has("_editorLoading") && (this.hasUpdated || this._editorLoading !== false)) {
      void this._editorLoadingWatchHandler(this._editorLoading);
    }
  }
  async mapViewWatchHandler() {
    this.mapView && await this.mapView.when(async () => {
      await this.init();
    });
  }
  async isMobileHandler() {
    this.modeChanged.emit();
  }
  async _editorLoadingWatchHandler(v) {
    if (v) {
      this._container?.classList.add("display-none");
      if (this._selectedLayer?.isTable) {
        if (this._selectedLayer.templates && this._editor) {
          const template = this._selectedLayer.templates[0];
          const creationInfo = {
            layer: this._selectedLayer,
            template
          };
          await this._editor.startCreateFeaturesWorkflowAtFeatureCreation(creationInfo);
          await this.hideEditorsElements();
        }
      } else {
        await this.startCreate();
      }
      this._container?.classList.remove("display-none");
      this._editorLoading = false;
    }
  }
  async submit() {
    if (this._editor?.viewModel?.featureFormViewModel) {
      this._isSubmitBtnClicked = true;
      this._editor.viewModel.featureFormViewModel.submit();
    }
  }
  async refresh(floorLevel) {
    if (this._editor) {
      if (floorLevel) {
        await this._setFloorLevel(floorLevel);
      } else {
        if (this.reportingArea && this.reportingAreaLayer && this._currentPage !== "drawing") {
          await this.queryIntersectingFeatures();
        } else if (this._currentPage !== "drawing") {
          this._inValidGeomtryDrawn = false;
          this.drawComplete.emit(this._inValidGeomtryDrawn);
        }
      }
    }
  }
  async showForm() {
    this.progressStatus.emit(100);
    this._container?.classList.remove("display-none");
    this._mapViewContainer.value?.classList?.replace("show-map", "hide-map");
    this._currentPage = "featureForm";
  }
  async loaded() {
    await this.init();
  }
  async updated() {
    if (this.isMobile && this.updateMapPosition) {
      const customHeight = this._currentPage === "drawing" ? 80 : 30;
      const searchDiv = this.enableSearch ? this._searchDiv.value?.offsetHeight : 0;
      await this._calciteNotice.value?.componentOnReady();
      const calciteNotice = this._calciteNotice.value?.offsetHeight || 0;
      const top = calciteNotice + searchDiv + customHeight;
      if (this._mapViewContainer.value) {
        this._mapViewContainer.value.style.top = `${top}px`;
      }
    }
    if (this.reportingAreaMessage && this._guidingMessageRefNode.value?.children[0]) {
      this._guidingMessageRefNode.value.children[0].style.margin = "0px";
    }
  }
  disconnectedCallback() {
    super.disconnectedCallback();
    if (this._editor) {
      if (this._editor.viewModel.sketchViewModel) {
        this._editor.viewModel.sketchViewModel?.destroy();
      }
      this._editor.destroy();
      if (this.enableSnapping && this.mapView?.ui.view) {
        (this.mapView?.ui.view).grid = null;
      }
    }
  }
  render() {
    const showSearchWidget = this._currentPage === "drawing" || this._currentPage === "editing" ? "" : "display-none";
    const loaderClass = this._editorLoading ? "" : "display-none";
    const featureFormClass = this._editorLoading ? "display-none" : "";
    const mobileMapClass = this.isMobile && this.updateMapPosition ? "show-map" : "display-none";
    const noticeKind = this._inValidGeomtryDrawn ? "danger" : "success";
    const icon = this._inValidGeomtryDrawn ? "exclamation-mark-triangle" : "lightbulb";
    const showLayerVisibilityGuidingMsgAtTemplatePickerPage = this.showLayerVisibilityMsg && this._currentPage === "templatePicker";
    const showGuidingMsg = this.showGuidingMsg || showLayerVisibilityGuidingMsgAtTemplatePickerPage;
    let guidingMsg = this._translations.chooseCategoryMsg;
    if (this._inValidGeomtryDrawn) {
      guidingMsg = this.reportingAreaMessage || this._translations.reportOutsideAreaMessage;
    } else if (this._currentPage === "drawing" || this._currentPage === "editing") {
      guidingMsg = this._translations.provideLocationMsg;
    } else if (this._currentPage === "featureForm") {
      guidingMsg = this._translations.provideDetailsMsg;
    } else if (showLayerVisibilityGuidingMsgAtTemplatePickerPage) {
      guidingMsg = this._translations.enableFeatureTemplatesMessage;
    }
    return html`${showGuidingMsg && html`<calcite-notice class="notice-msg" .icon=${icon} .kind=${noticeKind} open ${ref(this._calciteNotice)}><div slot=message .innerHTML=${guidingMsg ?? ""} ${ref(this._guidingMessageRefNode)}></div></calcite-notice>` || ""}<calcite-loader class=${safeClassMap(loaderClass)} label scale=s></calcite-loader>${this._currentPage === "featureForm" && this.isMobile && html`<calcite-button appearance=transparent class="edit-location-btn" icon-start=pin @click=${this.editLocation}>${this._translations.editLocationLabel}</calcite-button>` || ""}<div class=${safeClassMap(featureFormClass)} id=feature-form></div>${this.enableSearch && html`<div class=${`search-widget ${showSearchWidget} ${featureFormClass}`} id=search-widget-ref ${ref(this._searchDiv)}></div>` || ""}<div class=${safeClassMap(mobileMapClass)} ${ref(this._mapViewContainer)}></div>`;
  }
  async init() {
    if (this.mapView && this.selectedLayerId) {
      this._updatedMapView = this.mapView;
      await (this.isMobile && this.updateMapPosition ? this.createMobileMapView() : this._loadWidgets());
    }
  }
  async createMobileMapView() {
    if (this._mapViewContainer.value && this.mapView) {
      this._mapViewContainer.value.classList.add("hide-map");
      await new MapView({
        map: this.mapView.map,
        container: this._mapViewContainer.value,
        zoom: this.mapView.zoom,
        center: this.mapView.center,
        popupEnabled: this.popupEnabled
      }).when((view) => {
        this._updatedMapView = view;
        const home = new Home({
          view: this._updatedMapView
        });
        if (home) {
          this._updatedMapView.ui.add(home, "top-left");
        }
        void this._loadWidgets();
      }, (e) => {
        console.log(e);
      });
    }
  }
  async _loadWidgets() {
    await this.createEditorWidget();
    if (this.enableSearch) {
      await this.createSearchWidget();
    }
  }
  async createEditorWidget() {
    if (this._editor) {
      this._editor.destroy();
    }
    const layerInfos = [];
    this._container = document.createElement("div");
    this._container?.classList.add("display-none");
    if (!this.enableSnapping) {
      this._container.classList.add("hide-editor-toolbar");
    }
    const allMapLayers = this._updatedMapView && await getAllFeatureLayers(this._updatedMapView);
    const selectedLayer = this.mapView && await getLayerOrTable(this.mapView, this.selectedLayerId);
    if (selectedLayer) {
      this._selectedLayer = selectedLayer;
      if (!this._selectedLayer?.isTable && allMapLayers) {
        allMapLayers.forEach((layer) => {
          layerInfos.push({
            layer,
            enabled: layer?.type === "feature" && layer?.id === this.selectedLayerId,
            addEnabled: true,
            // default is true, set to false to disable the ability to add a new feature
            updateEnabled: false,
            // if true, enable ability to edit an existing feature
            deleteEnabled: false
            // default is true, set to false to disable the ability to delete features
          });
        });
      }
    }
    this._editor = new Editor({
      view: this._updatedMapView,
      layerInfos,
      visibleElements: {
        settingsMenu: this.enableSnapping,
        snappingControls: this.enableSnapping,
        createFeaturesSection: true,
        editFeaturesSection: false,
        flow: true,
        sketch: this.showSketchWidgets && this._selectedLayer?.geometryType !== "point"
      },
      container: this._container
    });
    if (this._mapViewContainer.value) {
      this.el.insertBefore(this._container, this._mapViewContainer.value);
    } else {
      this.el.appendChild(this._container);
    }
    if (this._selectedLayer?.isTable) {
      this._editorLoading = true;
    }
    if (this._editor) {
      const attachmentHandle = reactiveUtils.watch(() => this._editor?.viewModel.state, (state) => {
        if (state === "adding-attachment" || state === "editing-attachment") {
          this._addingAttachment = true;
          this.editingAttachment.emit(true);
        } else {
          if (this._addingAttachment) {
            this.editingAttachment.emit(false);
            this._addingAttachment = false;
          }
        }
      });
      attachmentHandle && this._editor.viewModel.addHandles(attachmentHandle);
      const handle = reactiveUtils?.watch(() => this._editor?.viewModel.featureTemplatesViewModel.state, (state) => {
        if (state === "ready" && this._editor?.viewModel?.activeWorkflow?.type !== "create-features") {
          this.progressStatus.emit(50);
          this._editorLoading = true;
        }
      });
      handle && this._editor.viewModel.addHandles(handle);
      const formHandle = reactiveUtils?.watch(() => this._editor?.viewModel.featureFormViewModel?.state, (state) => {
        if (state === "ready" && this._editor?.viewModel.featureFormViewModel && this._currentPage !== "editing") {
          this._mapViewContainer.value?.classList?.replace("show-map", "hide-map");
          this._editor.viewModel.featureFormViewModel.addHandles(this._editor.viewModel.featureFormViewModel.on("submit", this.submitted.bind(this)));
          setTimeout(() => {
            void this._setFloorLevel(this.floorLevel);
          }, 50);
          if (!this.allowMultipleCreation && this._editor.activeWorkflow) {
            this._editor.activeWorkflow.data.creationInfo.maxFeatures = 1;
          }
          this._currentPage = "featureForm";
          this.progressStatus.emit(100);
          this.drawComplete.emit(false);
        }
      });
      formHandle && this._editor.viewModel.addHandles(formHandle);
      const createFeatureHandle = reactiveUtils.watch(() => this._editor?.viewModel.state, (state) => {
        if (state === "creating-features" && this._editor?.viewModel.featureFormViewModel) {
          if (this._editor.viewModel.featureFormViewModel.state === "disabled") {
            this._mapViewContainer.value?.classList?.replace("hide-map", "show-map");
            if (this._selectedLayer && !this._selectedLayer.isTable) {
              this._currentPage = "drawing";
            }
          }
        }
      });
      createFeatureHandle && this._editor.viewModel.addHandles(createFeatureHandle);
      this._editor.on("sketch-create", async (e) => {
        if (e.detail.state === "complete") {
          this._drawnGeometry = e.detail.graphic?.geometry;
          if (this.reportingArea && this.reportingAreaLayer) {
            await this.queryIntersectingFeatures();
          }
        }
      });
      let debounceTimer;
      this._editor.on("sketch-update", (e) => {
        clearTimeout(debounceTimer);
        debounceTimer = window.setTimeout(async () => {
          this._drawnGeometry = e.detail.graphics[0].geometry;
          if (this.reportingArea && this.reportingAreaLayer) {
            await this.queryIntersectingFeatures();
          }
        }, 50);
      });
    }
  }
  async queryIntersectingFeatures() {
    const polygonLayer = this.mapView && await getLayerOrTable(this.mapView, this.reportingAreaLayer);
    if (polygonLayer) {
      const query = polygonLayer.createQuery();
      query.geometry = this._drawnGeometry;
      query.spatialRelationship = "intersects";
      const intersectingCount = await polygonLayer.queryFeatureCount(query);
      const nonValidGeomtryDrawn = intersectingCount === 0;
      this._inValidGeomtryDrawn = nonValidGeomtryDrawn;
      this.drawComplete.emit(this._inValidGeomtryDrawn);
    }
  }
  editLocation() {
    this.progressStatus.emit(75);
    this.editingLocation.emit();
    this._container?.classList.add("display-none");
    this._mapViewContainer.value?.classList.replace("hide-map", "show-map");
    this._currentPage = "editing";
  }
  async startCreate() {
    await this.hideEditorsElements();
    return new Promise((resolve, reject) => {
      if (this._editor?.viewModel.featureTemplatesViewModel.items?.length) {
        const items = this._editor.viewModel.featureTemplatesViewModel.items[0].items;
        this._editor.viewModel.featureTemplatesViewModel.addHandles(this._editor.viewModel.featureTemplatesViewModel.on("select", () => {
          this.progressStatus.emit(75);
          setTimeout(() => {
            this.hideEditorsElements().then(() => {
              resolve({});
            }, (e) => reject(e));
          }, 700);
        }));
        if (items.length === 1) {
          this._editor.viewModel.featureTemplatesViewModel.select(items[0]);
        }
        const resolvePromise = items.length > 1;
        this.hideEditorsElements().then(() => {
          if (resolvePromise) {
            resolve({});
          }
        }, (e) => resolvePromise && reject(e));
      }
    });
  }
  async createSearchWidget() {
    if (this._updatedMapView) {
      let searchOptions = {
        view: this._updatedMapView
      };
      if (this.searchConfiguration) {
        const searchConfiguration = this._getSearchConfig(this.searchConfiguration, this._updatedMapView);
        searchOptions = {
          ...searchConfiguration
        };
      }
      this._search = new Search(searchOptions);
      if (!this._search) {
        return;
      }
      this._search.container = "search-widget-ref";
      this._search.popupEnabled = false;
      this._search.resultGraphicEnabled = false;
      let pointGeometry = void 0;
      this._search.viewModel.addHandles(this._search.on("search-complete", (e) => {
        if (e.results[0].results && e.results[0].results[0]) {
          e.results[0].results[0].extent && void this._updatedMapView?.goTo(e.results[0].results[0].extent);
          if (this._selectedLayer?.geometryType === "point") {
            pointGeometry = e.results[0].results[0]?.feature.geometry;
          }
        }
      }));
      const createFeatureHandle = reactiveUtils.watch(() => this._search?.viewModel.state, (state) => {
        if (state === "ready") {
          setTimeout(() => {
            if (this._editor?.viewModel.sketchViewModel?.createGraphic && pointGeometry) {
              const geomClone = pointGeometry.clone();
              const graphic = this._editor.viewModel.sketchViewModel.createGraphic.set("geometry", pointGeometry);
              const graphicClone = graphic.clone();
              this._editor.viewModel.sketchViewModel.addGraphic(graphicClone);
              this._editor.viewModel.sketchViewModel.emit("create", {
                graphic: graphicClone,
                state: "complete",
                toolEventInfo: null,
                type: "create"
              });
              this._editor.viewModel.sketchViewModel.update(geomClone);
              void this.hideEditorsElements();
            } else if (this._editor?.viewModel.sketchViewModel && this._editor.viewModel.sketchViewModel.updateGraphics.length > 0 && pointGeometry) {
              const graphic = this._editor?.viewModel.sketchViewModel?.updateGraphics.getItemAt(0);
              if (graphic) {
                graphic.set("geometry", pointGeometry);
                void this._editor?.viewModel.sketchViewModel?.update(graphic);
                void this.hideEditorsElements();
              }
            }
          }, 100);
        }
      });
      createFeatureHandle && this._search.viewModel.addHandles(createFeatureHandle);
    }
  }
  _getSearchConfig(searchConfiguration, view) {
    const INCLUDE_DEFAULT_SOURCES = "includeDefaultSources";
    const sources = searchConfiguration.sources;
    if (sources && sources?.length > 0) {
      searchConfiguration[INCLUDE_DEFAULT_SOURCES] = false;
      sources.forEach((source) => {
        const isLayerSource = source.hasOwnProperty("layer");
        if (isLayerSource) {
          const layerSource = source;
          const layerId = layerSource.layer?.id;
          const layerFromMap = layerId ? view.map?.findLayerById(layerId) : "";
          const layerUrl = layerSource?.layer?.url;
          if (layerFromMap) {
            layerSource.layer = layerFromMap;
          } else if (layerUrl) {
            layerSource.layer = new FeatureLayer(layerUrl);
          }
        }
      });
      sources?.forEach((source) => {
        const isLocatorSource = source.hasOwnProperty("locator");
        if (isLocatorSource) {
          const locatorSource = source;
          if (locatorSource?.name === "ArcGIS World Geocoding Service") {
            const outFields = locatorSource.outFields || ["Addr_type", "Match_addr", "StAddr", "City"];
            locatorSource.outFields = outFields;
            locatorSource.singleLineFieldName = "SingleLine";
          }
          locatorSource.url = locatorSource.url;
          delete locatorSource.url;
        }
      });
    } else {
      searchConfiguration = {
        ...searchConfiguration,
        includeDefaultSources: true
      };
    }
    return searchConfiguration;
  }
  async _setFloorLevel(level) {
    if (!level) {
      return;
    }
    const layer = this._selectedLayer;
    const floorField = layer?.floorInfo?.floorField;
    if (floorField) {
      const layerField = layer.fields.find((field) => field.name === floorField);
      if (layerField && !layer?.formTemplate) {
        if (this._editor?.viewModel.featureFormViewModel) {
          this._editor.viewModel.featureFormViewModel.setValue(layerField.name, level);
          layerField.editable = false;
        }
      } else if (layer.formTemplate && this.formElements) {
        const floorInfoExpression = new ExpressionInfo({
          expression: `'${level}'`,
          name: "floor-info-test",
          title: "Floor Info",
          returnType: "string"
        });
        const levelIdFieldElement = new FieldElement({
          label: floorField,
          editableExpression: "false",
          fieldName: floorField,
          input: {
            type: "text-box",
            maxLength: 50,
            minLength: 0
          },
          valueExpression: floorInfoExpression.name
        });
        this._updatedMapView?.map.editableLayers.forEach((layer2) => {
          const orgElements = this.formElements.orgElements;
          const orgExpressionInfos = this.formElements.orgExpressionInfos;
          const elements = [...orgElements];
          elements.push(levelIdFieldElement);
          if (layer2.type === "feature") {
            const featureLayer = layer2;
            const floorInfoTemplate = new FormTemplate({
              title: featureLayer?.formTemplate?.title,
              description: featureLayer?.formTemplate?.description,
              elements,
              expressionInfos: [floorInfoExpression].concat(orgExpressionInfos)
            });
            layer2.formTemplate = floorInfoTemplate;
          }
        });
      }
    }
  }
  async hideEditorsElements() {
    if (!this.customizeSubmit) {
      return;
    }
    await this.timeout(700);
    this.el.querySelector(".esri-editor")?.querySelectorAll("calcite-flow-item")?.forEach((flowItem) => {
      const article = flowItem.shadowRoot?.querySelector("calcite-panel")?.shadowRoot?.querySelector("article");
      article?.querySelector("header")?.setAttribute("style", "display: none");
      article?.querySelector("footer")?.setAttribute("style", "display: none");
    });
  }
  async submitted(_evt) {
    if (_evt.invalid.length) {
      this._isSubmitBtnClicked = false;
      return;
    }
    if (this._isSubmitBtnClicked) {
      this._isSubmitBtnClicked = false;
      try {
        if (this._editor?.activeWorkflow) {
          await this._editor.activeWorkflow.commit();
          if (this._editor.viewModel.failures?.length) {
            this._editor.viewModel.failures.some((failure) => {
              if (failure.error) {
                throw failure.error;
              }
            });
          }
        }
      } catch (e) {
        this.fail.emit(e);
        return;
      }
      this.success.emit();
    }
  }
  async timeout(delay) {
    return new Promise((resolve) => setTimeout(resolve, delay));
  }
}
customElement("create-feature", CreateFeature);
export {
  CreateFeature
};
