var d = Object.defineProperty;
var p = (o, e, r) => e in o ? d(o, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : o[e] = r;
var s = (o, e, r) => p(o, typeof e != "symbol" ? e + "" : e, r);
import { jsx as i } from "react/jsx-runtime";
import { uuidv4 as w } from "./index-generate-uid.js";
import { pubSubService as l, PUB_SUB_EVENTS as a } from "./index-pub-sub.js";
import { MultiSelectDrawer as m } from "./index-MultiSelectDrawer.js";
import { TextEditDrawer as u } from "./index-TextEditDrawer.js";
import n from "react";
class h {
  constructor() {
    s(this, "drawerId", null);
  }
  openTextEditDrawer(e, r) {
    const t = this.open(i(u, {
      ...e,
      onClose: () => {
        this.close(t);
      }
    }), r);
  }
  openMultiSelectDrawer(e, r) {
    const t = this.open(i(m, {
      ...e,
      onClose: () => {
        this.close(t);
      }
    }), r);
  }
  open(e, r) {
    const t = w(), c = n.isValidElement(e) ? n.cloneElement(e, {
      // Type assertion to allow adding onClose property
      ...e.props,
      onClose: () => this.close(t)
    }) : e;
    return l.$pub(a.reactDrawerOpen, {
      component: c,
      options: r,
      id: t
    }), this.drawerId = t, t;
  }
  close(e) {
    l.$pub(a.reactDrawerClose, {
      id: e
    });
  }
  closeLast() {
    this.drawerId && (this.close(this.drawerId), this.drawerId = null);
  }
}
const v = new h();
export {
  v as DrawerService
};
