import { merge as a } from "es-toolkit/compat";
import { ref as l, computed as p, reactive as v, readonly as u, markRaw as m } from "vue";
const n = l([]);
function D() {
  function r(e) {
    !e.name && e.component.name && (e.name = e.component.name), e.component = m(e.component);
    const t = {
      disableDefaultListeners: !1
    };
    e.options = a({}, t, e.options), n.value.push(e);
  }
  function i({ index: e, name: t } = {}) {
    if (e === void 0 && !t) {
      n.value.shift();
      return;
    }
    if (e !== void 0) {
      n.value.splice(e, 1);
      return;
    }
    if (t) {
      const o = n.value.findIndex((f) => f.name === t);
      if (o === -1) return;
      n.value.splice(o, 1);
      return;
    }
  }
  function c() {
    n.value = [];
  }
  const s = p(() => n.value.length ? n.value[0] : null);
  return v({
    /**
     * The list of modals that are currently open.
     */
    active: u(n),
    /**
     * The first modal in the active list (index: 0).
     */
    current: u(s),
    /**
     * Opens the given modal.
     */
    open: r,
    /**
     * Closes a modal.
     * If no arguments are passed, then the top-most modal is closed.
     * If an index is passed, then the modal at that index is closed.
     * If a name is passed, then the modal with that name is closed.
     */
    close: i,
    /**
     * Closes all active/open modals.
     */
    closeAll: c
  });
}
export {
  D as default
};
//# sourceMappingURL=useModals.js.map
