import { createHead as r } from "@unhead/vue";
import { reactive as u, createApp as c, h as d } from "vue";
import i from "../../components/ApiReference.vue.js";
const y = (n, s) => {
  const t = u({
    // Either the configuration will be the second arugment or it MUST be the first (configuration only)
    configuration: s ?? n ?? {}
  });
  let a = c(() => d(i, t));
  if (a.use(r()), s) {
    const e = typeof n == "string" ? document.querySelector(n) : n;
    e ? a.mount(e) : console.error("Could not find a mount point for API References:", n);
  }
  document.addEventListener(
    "scalar:reload-references",
    () => {
      if (console.warn(
        "scalar:reload-references event has been deprecated, please use the scalarInstance.app.mount method instead."
      ), !t.configuration)
        return;
      const e = typeof n == "string" ? document.querySelector(n) : n;
      e && (e && !document.body.contains(e) && document.body.appendChild(e), a.unmount(), a = c(() => d(i, t)), a.use(r()), a.mount(e));
    },
    !1
  );
  const o = () => {
    delete t.configuration, a.unmount();
  };
  return document.addEventListener(
    "scalar:destroy-references",
    () => {
      console.warn("scalar:destroy-references event has been deprecated, please use scalarInstance.destroy instead."), o();
    },
    !1
  ), document.addEventListener(
    "scalar:update-references-config",
    (e) => {
      console.warn(
        "scalar:update-references-config event has been deprecated, please use scalarInstance.updateConfiguration instead."
      ), "detail" in e && Object.assign(t, e.detail);
    },
    !1
  ), {
    app: a,
    getConfiguration: () => t.configuration ?? {},
    updateConfiguration: (e) => {
      t.configuration = e;
    },
    destroy: o
  };
};
export {
  y as createApiReference
};
