import { jsx } from "react/jsx-runtime";
import { CodeBlock } from "../../code-block/index.js";
import { extractLanguage } from "../utils/index.js";
import { mdTv } from "../tv.js";
import { MermaidBlock } from "./mermaid-block.js";
import { CodeBlockCode } from "../../code-block/components/code-block-code.js";
const createComponents = (tv) => ({
  // Typography
  p: ({ children }) => /* @__PURE__ */ jsx("p", { className: tv.paragraph(), children }),
  h1: ({ children }) => /* @__PURE__ */ jsx("h1", { className: tv.h1(), children }),
  h2: ({ children }) => /* @__PURE__ */ jsx("h2", { className: tv.h2(), children }),
  h3: ({ children }) => /* @__PURE__ */ jsx("h3", { className: tv.h3(), children }),
  h4: ({ children }) => /* @__PURE__ */ jsx("h4", { className: tv.h4(), children }),
  h5: ({ children }) => /* @__PURE__ */ jsx("h5", { className: tv.h5(), children }),
  h6: ({ children }) => /* @__PURE__ */ jsx("h6", { className: tv.h6(), children }),
  // Lists
  ul: ({ children }) => /* @__PURE__ */ jsx("ul", { className: tv.ul(), children }),
  ol: ({ children }) => /* @__PURE__ */ jsx("ol", { className: tv.ol(), children }),
  li: ({ children }) => /* @__PURE__ */ jsx("li", { className: tv.li(), children }),
  // Blockquote
  blockquote: ({ children }) => /* @__PURE__ */ jsx("blockquote", { className: tv.blockquote(), children }),
  // Horizontal rule
  hr: () => /* @__PURE__ */ jsx("hr", { className: tv.hr() }),
  // Links
  a: ({ href, children }) => /* @__PURE__ */ jsx(
    "a",
    {
      href,
      target: "_blank",
      rel: "noopener noreferrer",
      className: tv.a(),
      children
    }
  ),
  // Code
  code: function CodeComponent({ className, children, ...props }) {
    const isInline = !props.node?.position?.start.line || props.node?.position?.start.line === props.node?.position?.end.line;
    if (isInline) {
      return /* @__PURE__ */ jsx(
        "code",
        {
          className: tv.code(),
          ...props,
          children
        }
      );
    }
    const language = extractLanguage(className);
    if (language === "mermaid") {
      return null;
    }
    return /* @__PURE__ */ jsx(CodeBlock, { className, children: /* @__PURE__ */ jsx(
      CodeBlockCode,
      {
        code: children,
        language
      }
    ) });
  },
  pre: function PreComponent({ children }) {
    if (children && typeof children === "object" && "props" in children) {
      const props = children.props;
      if (props?.className?.includes("language-mermaid")) {
        const code = props.children;
        if (typeof code === "string") {
          return /* @__PURE__ */ jsx(MermaidBlock, { code });
        }
      }
    }
    return /* @__PURE__ */ jsx("pre", { className: tv.pre(), children });
  },
  // Tables
  table: ({ children }) => /* @__PURE__ */ jsx("div", { className: tv.tableWrapper(), children: /* @__PURE__ */ jsx("table", { className: tv.table(), children }) }),
  thead: ({ children }) => /* @__PURE__ */ jsx("thead", { className: tv.thead(), children }),
  tbody: ({ children }) => /* @__PURE__ */ jsx("tbody", { className: tv.tbody(), children }),
  tr: ({ children }) => /* @__PURE__ */ jsx("tr", { className: tv.tr(), children }),
  th: ({ children }) => /* @__PURE__ */ jsx("th", { className: tv.th(), children }),
  td: ({ children }) => /* @__PURE__ */ jsx("td", { className: tv.td(), children }),
  // Typography elements
  strong: ({ children }) => /* @__PURE__ */ jsx("strong", { className: tv.strong(), children }),
  em: ({ children }) => /* @__PURE__ */ jsx("em", { className: tv.em(), children }),
  del: ({ children }) => /* @__PURE__ */ jsx("del", { className: tv.del(), children }),
  // Images
  img: ({ src, alt }) => /* @__PURE__ */ jsx(
    "img",
    {
      src,
      alt,
      className: tv.img()
    }
  ),
  // Checkbox (for task lists)
  input: ({ type, checked, ...props }) => {
    if (type === "checkbox") {
      return /* @__PURE__ */ jsx(
        "input",
        {
          type: "checkbox",
          checked,
          className: tv.checkbox(),
          ...props
        }
      );
    }
    return /* @__PURE__ */ jsx(
      "input",
      {
        type,
        ...props
      }
    );
  }
});
createComponents(mdTv());
export {
  createComponents
};
//# sourceMappingURL=markdown-renderers.js.map
