"use client";
'use strict';

const jsxRuntime = require('react/jsx-runtime');
const React = require('react');
const ReactMarkdown = require('react-markdown');
const remarkGfm = require('remark-gfm');
const remarkMath = require('remark-math');
const codeblock = require('./codeblock.cjs');
const utils = require('../../../lib/utils.cjs');

function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }

const ReactMarkdown__default = /*#__PURE__*/_interopDefaultCompat(ReactMarkdown);
const remarkGfm__default = /*#__PURE__*/_interopDefaultCompat(remarkGfm);
const remarkMath__default = /*#__PURE__*/_interopDefaultCompat(remarkMath);

function Markdown({ children, className }) {
  const components = React.useMemo(() => {
    return {
      a({
        children: children2,
        href,
        className: className2
      }) {
        return /* @__PURE__ */ jsxRuntime.jsx(
          "a",
          {
            href,
            target: "_blank",
            rel: "noopener noreferrer",
            className: utils.cn(className2, "text-blue-500 hover:text-blue-600"),
            children: children2
          }
        );
      },
      img({
        src,
        alt,
        className: className2
      }) {
        return /* @__PURE__ */ jsxRuntime.jsx("img", { src, alt, className: utils.cn(className2, "w-full h-auto") });
      },
      code({ className: className2, children: children2, ...props }) {
        const match = /language-(\w+)/.exec(className2 || "");
        if (match) {
          return /* @__PURE__ */ jsxRuntime.jsx(
            codeblock.CodeBlock,
            {
              language: match && match[1] || "",
              value: String(children2).replace(/\n$/, ""),
              ...props
            },
            Math.random()
          );
        }
        return /* @__PURE__ */ jsxRuntime.jsx("code", { className: utils.cn(className2, "whitespace-pre-wrap"), ...props, children: children2 });
      }
    };
  }, []);
  const remarkPlugins = React.useMemo(() => {
    return [remarkGfm__default, remarkMath__default];
  }, []);
  return /* @__PURE__ */ jsxRuntime.jsx(
    MemoizedReactMarkdown,
    {
      className: utils.cn(
        "prose break-words prose-headings:text-secondary-foreground prose-blockquote:text-secondary-foreground prose-strong:text-secondary-foreground prose-p:leading-relaxed prose-pre:p-0 prose-pre:m-1 prose-p:text-base prose-p:font-normal prose-p:my-1 prose-ul:my-1 prose-ol:my-1 prose-li:py-0 prose-li:my-0 max-w-none text-secondary-foreground prose-code:prose-headings:bg-secondary",
        className
      ),
      remarkPlugins,
      components,
      children
    }
  );
}
const MemoizedReactMarkdown = React.memo(
  ReactMarkdown__default,
  (prevProps, nextProps) => prevProps.children === nextProps.children && prevProps.className === nextProps.className
);

exports.Markdown = Markdown;
