/* COPYRIGHT Esri - https://js.arcgis.com/1.2/LICENSE.txt */
import { c as customElement } from "../../chunks/runtime.js";
import { css, html } from "lit";
import { u as useT9n } from "../../chunks/useT9n.js";
import { LitElement, createEvent } from "@arcgis/lumina";
const styles = css`/** @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;
}`;
class DeleteDialog extends LitElement {
  constructor() {
    super(...arguments);
    this.ids = [];
    this.open = false;
    this._isDeleting = false;
    this._translations = useT9n({ name: "delete-dialog", blocking: true });
    this.editsComplete = createEvent();
    this.deleteDialogClose = createEvent();
  }
  static {
    this.properties = { ids: [0, {}, { attribute: false }], layer: [0, {}, { attribute: false }], open: [5, {}, { type: Boolean }], _isDeleting: [16, {}, { state: true }], _translations: [16, {}, { state: true }] };
  }
  static {
    this.styles = styles;
  }
  render() {
    const title = this.layer?.title || "";
    const confirmMessage = this.ids.length === 1 ? (this._translations.confirmSingle || "").replace("{{layer-name}}", title) : (this._translations.confirmMultiple || "").replace("{{layer-name}}", title);
    return html`<calcite-dialog .heading=${this._translations.deleteFeature} kind=danger modal @calciteDialogClose=${() => this._close()} .open=${this.open} width=s><div>${confirmMessage}</div><calcite-button appearance=outline kind=danger @click=${() => this._close()} slot=footer-end width=full>${this._translations.cancel}</calcite-button><calcite-button kind=danger .loading=${this._isDeleting} @click=${() => void this._deleteFeatures()} slot=footer-end width=full>${this._translations.delete}</calcite-button></calcite-dialog>`;
  }
  async _deleteFeatures() {
    if (this.layer) {
      this._isDeleting = true;
      const deleteFeatures = this.ids.map((objectId) => {
        return { objectId: Number(objectId) };
      });
      await this.layer.applyEdits({
        deleteFeatures
      });
      this._isDeleting = false;
      this._close();
      this.editsComplete.emit("delete");
    }
  }
  _close() {
    this.open = false;
    this.deleteDialogClose.emit();
  }
}
customElement("delete-dialog", DeleteDialog);
export {
  DeleteDialog
};
