"use client";
import { Fragment, jsx } from "react/jsx-runtime";
import * as React from "react";
import { useMarkdownRemarkPlugins } from "./useMarkdownRemarkPlugins.js";
const isTestEnv = typeof process !== "undefined" && (process.env.NODE_ENV === "test" || typeof process.env.JEST_WORKER_ID !== "undefined");
const TestMarkdownComponent = ({ children }) => /* @__PURE__ */ jsx(Fragment, { children });
let loadedReactMarkdownComponent = isTestEnv ? TestMarkdownComponent : null;
let reactMarkdownComponentPromise = null;
function loadReactMarkdownComponent() {
  if (loadedReactMarkdownComponent) {
    return Promise.resolve(loadedReactMarkdownComponent);
  }
  if (!reactMarkdownComponentPromise) {
    reactMarkdownComponentPromise = import("react-markdown").then((mod) => {
      const component = mod.default;
      loadedReactMarkdownComponent = component;
      return component;
    });
  }
  return reactMarkdownComponentPromise;
}
function ReactMarkdownComponent(props) {
  const [Component, setComponent] = React.useState(
    () => loadedReactMarkdownComponent
  );
  React.useEffect(() => {
    if (Component) {
      return;
    }
    let active = true;
    void loadReactMarkdownComponent().then((resolved) => {
      if (active) {
        setComponent(() => resolved);
      }
    });
    return () => {
      active = false;
    };
  }, [Component]);
  if (!Component) {
    return null;
  }
  return /* @__PURE__ */ jsx(Component, { ...props });
}
const EMPTY_PLUGINS = [];
function MarkdownPreview({ children, className, remarkPlugins }) {
  return /* @__PURE__ */ jsx("div", { className, children: /* @__PURE__ */ jsx(ReactMarkdownComponent, { remarkPlugins, children }) });
}
function MarkdownContent({
  body,
  format = "text",
  className,
  remarkPlugins
}) {
  const shouldRenderMarkdown = format === "markdown";
  const plugins = useMarkdownRemarkPlugins(
    shouldRenderMarkdown ? remarkPlugins : EMPTY_PLUGINS
  );
  if (!shouldRenderMarkdown) {
    return /* @__PURE__ */ jsx("div", { className, children: body });
  }
  return /* @__PURE__ */ jsx(MarkdownPreview, { className, remarkPlugins: plugins, children: body });
}
export {
  MarkdownContent,
  MarkdownPreview
};
//# sourceMappingURL=MarkdownContent.js.map
