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