var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
import { u as uuidv4 } from "./chunk.dcf-utility.js?v=6.1.0-alpha";
import { D as DCFDialog } from "./chunk.dcf-dialog.js?v=6.1.0-alpha";
class DCFButtonToggleDialog {
  static {
    __name(this, "DCFButtonToggleDialog");
  }
  uuid = uuidv4();
  buttonElement = null;
  dialogId = null;
  dialogElement = null;
  constructor(buttonElement) {
    if (this.buttonElement = buttonElement, this.buttonElement.tagName !== "BUTTON")
      throw new Error("dcf-btn-toggle-dialog used on non-button element");
    if ((this.buttonElement.getAttribute("id") === "" || this.buttonElement.getAttribute("id") === null) && this.buttonElement.setAttribute("id", this.uuid.concat("-btn-toggle-dialog")), this.dialogId = this.buttonElement.dataset.controls, this.dialogId === void 0 || this.dialogId === "")
      throw new Error("dcf-btn-toggle-dialog is missing dialog id");
    if (this.dialogElement = document.getElementById(this.dialogId), this.dialogElement === null)
      throw new Error("dcf-btn-toggle-dialog can not find matching dialog");
    this.dialogElement.classList.contains("dcf-dialog-non-modal") ? this.buttonElement.setAttribute("aria-expanded", this.#isDialogOpen()) : this.buttonElement.setAttribute("aria-haspopup", "dialog"), this.#addEventListeners(), this.buttonElement.classList.add("dcf-btn-toggle-dialog-initialized"), this.buttonElement.removeAttribute("hidden"), this.buttonElement.removeAttribute("disabled"), this.buttonElement.dispatchEvent(new CustomEvent(DCFButtonToggleDialog.events("btnToggleDialogReady"), {
      detail: {
        classInstance: this
      }
    }));
  }
  // The names of the events to be used easily
  static events(name) {
    const events = {
      btnToggleDialogReady: "btnToggleDialogReady"
    };
    return Object.freeze(events), name in events ? events[name] : void 0;
  }
  #isDialogOpen() {
    return this.dialogElement.classList.contains("dcf-dialog-is-open");
  }
  #addEventListeners() {
    this.buttonElement.addEventListener("click", () => {
      this.dialogElement.dispatchEvent(new CustomEvent(DCFDialog.events("commandToggle"), {
        detail: {
          button: this.buttonElement
        }
      }));
    }), this.dialogElement.addEventListener(DCFDialog.events("dialogPreOpen"), () => {
      this.buttonElement.classList.add("dcf-dialog-open"), this.dialogElement.classList.contains("dcf-dialog-non-modal") && this.buttonElement.setAttribute("aria-expanded", !0);
    }), this.dialogElement.addEventListener(DCFDialog.events("dialogPreClose"), () => {
      this.buttonElement.classList.remove("dcf-dialog-open"), this.dialogElement.classList.contains("dcf-dialog-non-modal") && this.buttonElement.setAttribute("aria-expanded", !1);
    });
  }
}
class UNLButtonToggleDialog extends DCFButtonToggleDialog {
  static {
    __name(this, "UNLButtonToggleDialog");
  }
  constructor(buttonElement, options = {}) {
    super(buttonElement, options);
  }
}
export {
  UNLButtonToggleDialog as default
};
//# sourceMappingURL=chunk.unl-button-toggle-dialog.js.map
