import {
  CodeBlock
} from "./chunk-B5IFB5YJ.mjs";
import {
  __objRest,
  __spreadProps,
  __spreadValues
} from "./chunk-MRXNTQOX.mjs";

// src/components/chat/Markdown.tsx
import { memo } from "react";
import ReactMarkdown from "react-markdown";
import remarkGfm from "remark-gfm";
import remarkMath from "remark-math";
import rehypeRaw from "rehype-raw";
import { jsx } from "react/jsx-runtime";
var defaultComponents = {
  a(_a) {
    var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
    return /* @__PURE__ */ jsx("a", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { target: "_blank", rel: "noopener noreferrer", children }));
  },
  // @ts-expect-error -- inline
  code(_c) {
    var _d = _c, { children, className, inline } = _d, props = __objRest(_d, ["children", "className", "inline"]);
    if (Array.isArray(children) && children.length) {
      if (children[0] == "\u258D") {
        return /* @__PURE__ */ jsx(
          "span",
          {
            style: {
              animation: "pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite",
              marginTop: "0.25rem"
            },
            children: "\u258D"
          }
        );
      }
      children[0] = (children == null ? void 0 : children[0]).replace("`\u258D`", "\u258D");
    }
    const match = /language-(\w+)/.exec(className || "");
    const hasLanguage = match && match[1];
    const content = String(children);
    const hasNewlines = content.includes("\n");
    const isInline = !hasLanguage && !hasNewlines;
    if (isInline) {
      return /* @__PURE__ */ jsx(
        "code",
        __spreadProps(__spreadValues({
          className: `copilotKitMarkdownElement copilotKitInlineCode ${className || ""}`
        }, props), {
          children
        })
      );
    }
    return /* @__PURE__ */ jsx(
      CodeBlock,
      __spreadValues({
        language: match && match[1] || "",
        value: String(children).replace(/\n$/, "")
      }, props),
      Math.random()
    );
  },
  h1: (_e) => {
    var _f = _e, { children } = _f, props = __objRest(_f, ["children"]);
    return /* @__PURE__ */ jsx("h1", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
  },
  h2: (_g) => {
    var _h = _g, { children } = _h, props = __objRest(_h, ["children"]);
    return /* @__PURE__ */ jsx("h2", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
  },
  h3: (_i) => {
    var _j = _i, { children } = _j, props = __objRest(_j, ["children"]);
    return /* @__PURE__ */ jsx("h3", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
  },
  h4: (_k) => {
    var _l = _k, { children } = _l, props = __objRest(_l, ["children"]);
    return /* @__PURE__ */ jsx("h4", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
  },
  h5: (_m) => {
    var _n = _m, { children } = _n, props = __objRest(_n, ["children"]);
    return /* @__PURE__ */ jsx("h5", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
  },
  h6: (_o) => {
    var _p = _o, { children } = _p, props = __objRest(_p, ["children"]);
    return /* @__PURE__ */ jsx("h6", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
  },
  p: (_q) => {
    var _r = _q, { children } = _r, props = __objRest(_r, ["children"]);
    return /* @__PURE__ */ jsx("p", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
  },
  pre: (_s) => {
    var _t = _s, { children } = _t, props = __objRest(_t, ["children"]);
    return /* @__PURE__ */ jsx("pre", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
  },
  blockquote: (_u) => {
    var _v = _u, { children } = _v, props = __objRest(_v, ["children"]);
    return /* @__PURE__ */ jsx("blockquote", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
  },
  ul: (_w) => {
    var _x = _w, { children } = _x, props = __objRest(_x, ["children"]);
    return /* @__PURE__ */ jsx("ul", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
  },
  li: (_y) => {
    var _z = _y, { children } = _z, props = __objRest(_z, ["children"]);
    return /* @__PURE__ */ jsx("li", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
  }
};
var MemoizedReactMarkdown = memo(
  ReactMarkdown,
  (prevProps, nextProps) => prevProps.children === nextProps.children && prevProps.components === nextProps.components
);
var Markdown = ({ content, components }) => {
  return /* @__PURE__ */ jsx("div", { className: "copilotKitMarkdown", children: /* @__PURE__ */ jsx(
    MemoizedReactMarkdown,
    {
      components: __spreadValues(__spreadValues({}, defaultComponents), components),
      remarkPlugins: [remarkGfm, [remarkMath, { singleDollarTextMath: false }]],
      rehypePlugins: [rehypeRaw],
      children: content
    }
  ) });
};

export {
  Markdown
};
//# sourceMappingURL=chunk-SNFHUE5S.mjs.map