import { jsx as _jsx } from "react/jsx-runtime";
import remarkGfm from "remark-gfm";
import { cn } from "@stigmer/theme";
/**
 * Remark plugins applied to all SDK markdown surfaces.
 * Includes GFM (tables, strikethrough, autolinks, task lists).
 */
export const REMARK_PLUGINS = [remarkGfm];
const FRONTMATTER_RE = /^---\r?\n[\s\S]*?\r?\n---\r?\n?/;
/**
 * Strips YAML frontmatter from markdown content.
 *
 * SKILL.md files store metadata (`name`, `description`) in a `---` delimited
 * YAML block at the top. The backend extracts these into separate proto fields,
 * but the raw `skill_md` still contains the block. `react-markdown` does not
 * understand frontmatter and renders it as a plain paragraph — this utility
 * removes it before rendering.
 */
export function stripFrontmatter(content) {
    return content.replace(FRONTMATTER_RE, "");
}
/**
 * Styled react-markdown component overrides for SDK markdown surfaces.
 *
 * Every element uses `--stgm-*` design tokens via Tailwind semantic classes,
 * ensuring correct rendering in both the Stigmer Console and third-party
 * host applications with custom themes.
 *
 * Used by `MessageEntry` (chat messages) and `SkillDetailView` (SKILL.md).
 */
export const MARKDOWN_COMPONENTS = {
    p({ children, ...props }) {
        return (_jsx("p", { className: "text-sm text-foreground mb-3 last:mb-0 leading-relaxed", ...props, children: children }));
    },
    a({ children, href, ...props }) {
        return (_jsx("a", { href: href, className: "text-primary underline underline-offset-2 hover:text-primary-muted", target: "_blank", rel: "noopener noreferrer", ...props, children: children }));
    },
    h1({ children, ...props }) {
        return (_jsx("h1", { className: "text-lg font-semibold text-foreground mt-5 mb-2 first:mt-0", ...props, children: children }));
    },
    h2({ children, ...props }) {
        return (_jsx("h2", { className: "text-base font-semibold text-foreground mt-5 mb-2 first:mt-0", ...props, children: children }));
    },
    h3({ children, ...props }) {
        return (_jsx("h3", { className: "text-sm font-semibold text-foreground mt-4 mb-1.5 first:mt-0", ...props, children: children }));
    },
    h4({ children, ...props }) {
        return (_jsx("h4", { className: "text-sm font-medium text-foreground mt-3 mb-1 first:mt-0", ...props, children: children }));
    },
    ul({ children, ...props }) {
        return (_jsx("ul", { className: "list-disc pl-5 mb-3 last:mb-0 space-y-1 text-sm text-foreground", ...props, children: children }));
    },
    ol({ children, ...props }) {
        return (_jsx("ol", { className: "list-decimal pl-5 mb-3 last:mb-0 space-y-1 text-sm text-foreground", ...props, children: children }));
    },
    li({ children, ...props }) {
        return (_jsx("li", { className: "leading-relaxed", ...props, children: children }));
    },
    pre({ children, ...props }) {
        return (_jsx("pre", { className: "mb-3 last:mb-0 overflow-x-auto rounded-md bg-muted p-3", ...props, children: children }));
    },
    code({ children, className: codeClassName, ...props }) {
        const isBlock = typeof codeClassName === "string" && codeClassName.startsWith("language-");
        if (isBlock) {
            return (_jsx("code", { className: cn("font-mono text-xs text-foreground", codeClassName), ...props, children: children }));
        }
        return (_jsx("code", { className: "font-mono text-xs bg-muted px-1 py-0.5 rounded text-foreground", ...props, children: children }));
    },
    blockquote({ children, ...props }) {
        return (_jsx("blockquote", { className: "border-l-2 border-border pl-4 mb-3 last:mb-0 text-muted-foreground italic", ...props, children: children }));
    },
    table({ children, ...props }) {
        return (_jsx("div", { className: "mb-3 last:mb-0 overflow-x-auto", children: _jsx("table", { className: "w-full border-collapse text-sm", ...props, children: children }) }));
    },
    th({ children, ...props }) {
        return (_jsx("th", { className: "border border-border px-3 py-1.5 text-left font-medium text-foreground bg-muted-subtle", ...props, children: children }));
    },
    td({ children, ...props }) {
        return (_jsx("td", { className: "border border-border px-3 py-1.5 text-foreground", ...props, children: children }));
    },
    hr(props) {
        return _jsx("hr", { className: "my-4 border-border", ...props });
    },
    strong({ children, ...props }) {
        return (_jsx("strong", { className: "font-semibold text-foreground", ...props, children: children }));
    },
    em({ children, ...props }) {
        return (_jsx("em", { className: "italic", ...props, children: children }));
    },
};
//# sourceMappingURL=markdown-components.js.map