import { jsx as r } from "react/jsx-runtime";
import { useState as l, useEffect as g } from "react";
import { u as x, e as w, h as b } from "./index-Bk6WqXgW.mjs";
import { u as N } from "./useShikiHighlight-CRlVgtPy.mjs";
const S = ({
  url: s,
  fileName: a,
  wordWrap: n = !0,
  htmlPreview: d = !1
}) => {
  const u = x(), [t, h] = l(""), [m, p] = l(!0), [o, i] = l(null), e = w(a), { html: c } = N(
    e !== "text" ? t : "",
    e
  );
  return g(() => {
    (async () => {
      try {
        p(!0), i(null);
        const f = await b(s);
        h(f);
      } catch (f) {
        i(u("text.load_failed")), console.error(f);
      } finally {
        p(!1);
      }
    })();
  }, [s]), m ? /* @__PURE__ */ r("div", { className: "rfp-flex rfp-items-center rfp-justify-center rfp-w-full rfp-h-full", children: /* @__PURE__ */ r("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" }) }) : o ? /* @__PURE__ */ r("div", { className: "rfp-flex rfp-items-center rfp-justify-center rfp-w-full rfp-h-full", children: /* @__PURE__ */ r("div", { className: "rfp-text-fg-secondary rfp-text-center", children: /* @__PURE__ */ r("p", { className: "rfp-text-lg", children: o }) }) }) : d && e === "html" ? /* @__PURE__ */ r("div", { className: "rfp-w-full rfp-h-full rfp-bg-surface-toolbar", children: /* @__PURE__ */ r(
    "iframe",
    {
      srcDoc: t,
      sandbox: "allow-same-origin",
      className: "rfp-w-full rfp-h-full rfp-border-0",
      title: a
    }
  ) }) : /* @__PURE__ */ r("div", { className: "rfp-w-full rfp-h-full rfp-overflow-auto rfp-bg-code-bg", children: e === "text" || !c ? /* @__PURE__ */ r(
    "pre",
    {
      className: `rfp-p-6 rfp-text-fg-primary rfp-font-mono rfp-text-sm ${n ? "rfp-whitespace-pre-wrap rfp-break-words" : "rfp-whitespace-pre"}`,
      children: t
    }
  ) : /* @__PURE__ */ r(
    "div",
    {
      className: `rfp-shiki-wrapper with-line-numbers ${n ? "" : "no-wrap"}`,
      dangerouslySetInnerHTML: { __html: c }
    }
  ) });
};
export {
  S as TextRenderer
};
//# sourceMappingURL=index-DB41zu6Q.mjs.map
