import { jsx as t } from "react/jsx-runtime";
import { useState as p, useEffect as d } from "react";
import { u as m, h as u } from "./index-Bk6WqXgW.mjs";
import { u as h } from "./useShikiHighlight-CRlVgtPy.mjs";
const g = (e) => {
  try {
    const s = new DOMParser().parseFromString(e, "application/xml");
    if (s.querySelector("parsererror")) return e;
    const r = new XMLSerializer().serializeToString(s);
    return w(r);
  } catch {
    return e;
  }
}, w = (e) => {
  const l = "  ", s = /(>)(<)(\/*)/g;
  let o = e.replace(s, `$1
$2$3`), n = 0;
  return o.split(`
`).map((r) => {
    let a = 0;
    /^<\/\w/.test(r) ? n = Math.max(n - 1, 0) : /^<\w[^>]*[^/]>.*$/.test(r) && !/<.+<\/.+>$/.test(r) && (a = 1);
    const i = l.repeat(n) + r;
    return n += a, i;
  }).join(`
`);
}, S = ({ url: e }) => {
  const l = m(), [s, o] = p(""), [n, r] = p(!0), [a, i] = p(null), { html: c } = h(s, "xml");
  return d(() => {
    (async () => {
      try {
        r(!0), i(null);
        const f = await u(e);
        o(g(f));
      } catch (f) {
        console.error(f), i(l("xml.load_failed"));
      } finally {
        r(!1);
      }
    })();
  }, [e]), n ? /* @__PURE__ */ t("div", { className: "rfp-flex rfp-items-center rfp-justify-center rfp-w-full rfp-h-full", children: /* @__PURE__ */ t("div", { className: "rfp-w-12 rfp-h-12 rfp-border-4 rfp-border-line-strong rfp-border-t-spinner-head rfp-rounded-full rfp-animate-spin" }) }) : a ? /* @__PURE__ */ t("div", { className: "rfp-flex rfp-items-center rfp-justify-center rfp-w-full rfp-h-full", children: /* @__PURE__ */ t("div", { className: "rfp-text-fg-secondary rfp-text-center", children: /* @__PURE__ */ t("p", { className: "rfp-text-lg", children: a }) }) }) : /* @__PURE__ */ t("div", { className: "rfp-w-full rfp-h-full rfp-overflow-auto rfp-bg-code-bg", children: c ? /* @__PURE__ */ t(
    "div",
    {
      className: "rfp-shiki-wrapper with-line-numbers",
      dangerouslySetInnerHTML: { __html: c }
    }
  ) : /* @__PURE__ */ t("pre", { className: "rfp-p-6 rfp-text-fg-primary rfp-font-mono rfp-text-sm rfp-whitespace-pre-wrap rfp-break-words", children: s }) });
};
export {
  S as XmlRenderer
};
//# sourceMappingURL=index-CjaLs3J_.mjs.map
