var l = Object.defineProperty;
var r = (e, t, o) => t in e ? l(e, t, { enumerable: !0, configurable: !0, writable: !0, value: o }) : e[t] = o;
var i = (e, t, o) => r(e, typeof t != "symbol" ? t + "" : t, o);
import { a as u, b as c } from "./index-U54PFR25.js";
class h {
  constructor(t, o = {}) {
    i(this, "quill");
    i(this, "options");
    i(this, "toolbarEl");
    i(this, "ownerDocument");
    i(this, "controller");
    i(this, "button", null);
    i(this, "buttonIcon", null);
    i(this, "unsubscribeController", null);
    i(this, "buttonClickHandler", (t) => this.controller.toggleFullscreen(t));
    if (this.quill = t, this.options = o, this.ownerDocument = t.root instanceof HTMLElement ? t.root.ownerDocument : document, this.controller = u(t), this.options.type === "Raw") {
      this.toolbarEl = null;
      return;
    }
    const n = t.getModule("toolbar"), s = (n == null ? void 0 : n.container) ?? null;
    this.toolbarEl = s, this.createButton();
  }
  destroy() {
    var t, o;
    (t = this.unsubscribeController) == null || t.call(this), this.unsubscribeController = null, this.button && (this.button.removeEventListener("click", this.buttonClickHandler), this.button.remove(), this.button = null), (o = this.toolbarEl) == null || o.classList.remove("ql-toolbar-has-right-action"), c(this.quill);
  }
  createButton() {
    if (!this.options.maximize || !this.options.minimize) return;
    const t = this.ownerDocument.createElement("button"), o = this.ownerDocument.createElement("span");
    t.type = "button", t.classList.add("ql-fullscreen"), o.classList.add("ql-fullscreen-icon"), t.append(o), t.addEventListener("click", this.buttonClickHandler), this.button = t, this.buttonIcon = o, this.unsubscribeController = this.controller.subscribe((n) => this.syncButtonState(n)), this.toolbarEl && (t.classList.add("ql-right-action"), this.toolbarEl.classList.add("ql-toolbar-has-right-action"), this.toolbarEl.append(t));
  }
  syncButtonState(t) {
    if (!this.button || !this.buttonIcon) return;
    this.button.classList.toggle("ql-active", t);
    const o = t ? this.options.minimize ?? "" : this.options.maximize ?? "", n = t ? this.options.minimizeLabel ?? "" : this.options.maximizeLabel ?? "";
    this.buttonIcon.innerHTML !== o && (this.buttonIcon.innerHTML = o), this.button.title !== n && (this.button.title = n), this.button.getAttribute("aria-label") !== n && this.button.setAttribute("aria-label", n);
  }
}
export {
  h as default
};
