import { measure as c } from "@scalar/helpers/testing/measure";
import { fetchDocument as f, prettyPrintJson as s } from "@scalar/oas-utils/helpers";
import { ref as u, watch as a, toValue as i } from "vue";
function l({
  configuration: o
}) {
  const t = u("");
  return a(
    () => i(o),
    async (n) => {
      var r;
      if (!n)
        return;
      const e = await m(n, (r = i(o)) == null ? void 0 : r.proxyUrl);
      typeof e == "string" && (t.value = e.trim());
    },
    { immediate: !0, deep: !0 }
  ), {
    originalDocument: t
  };
}
const m = async ({ url: o, content: t }, n) => {
  if (o && !t)
    try {
      const r = await c(`fetch(${o})`, async () => await f(o, n));
      return console.info("size:", Math.round(r.length / 1024), "kB"), r;
    } catch (r) {
      console.error("Failed to fetch OpenAPI document from URL:", r);
    }
  const e = typeof t == "function" ? t() : t;
  if (typeof e == "string")
    return e;
  if (typeof e == "object")
    return s(e);
};
export {
  l as useDocumentFetcher
};
