Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const require_chunk = require("../../chunk-CKQMccvm.cjs");
const require_ThemeProvider = require("../../ThemeProvider-0ytg6ico.cjs");
const require_components_CodeBlock_index = require("../CodeBlock/index.cjs");
const require_components_Table_index = require("../Table/index.cjs");
let clsx = require("clsx");
clsx = require_chunk.__toESM(clsx);
let react = require("react");
let react_jsx_runtime = require("react/jsx-runtime");
let react_markdown = require("react-markdown");
react_markdown = require_chunk.__toESM(react_markdown);
let react_syntax_highlighter_dist_cjs_styles_prism = require("react-syntax-highlighter/dist/cjs/styles/prism");
//#region src/components/MarkDownRenderer/MarkDownRenderer.tsx
function toTableAlignment(align) {
	if (align === "left" || align === "center" || align === "right") return align;
}
const MarkdownTableHead = ({ align, ...props }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_Table_index.TableHead, {
	...props,
	align: toTableAlignment(align)
});
const MarkdownTableCell = ({ align, ...props }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_Table_index.TableCell, {
	...props,
	align: toTableAlignment(align)
});
const variantStyles = {
	clear: "",
	card: "openui-markdown-renderer-card",
	sunk: "openui-markdown-renderer-card-sunk"
};
const MarkDownRenderer = (0, react.memo)((props) => {
	const { mode } = require_ThemeProvider.useTheme();
	const theme = mode === "dark" ? react_syntax_highlighter_dist_cjs_styles_prism.vscDarkPlus : react_syntax_highlighter_dist_cjs_styles_prism.oneLight;
	const components = {
		code({ className, children, ...props }) {
			const match = /language-(\w+)/.exec(className || "");
			if (match || !className && String(children).includes("\n")) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_CodeBlock_index.CodeBlock, {
				language: match?.[1] ?? "text",
				codeString: String(children).trim(),
				theme
			});
			return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", {
				className: (0, clsx.default)("openui-markdown-renderer-code", className),
				...props,
				children
			});
		},
		a({ href, children, ...props }) {
			return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
				href,
				target: "_blank",
				rel: "noopener noreferrer",
				className: "openui-markdown-renderer-link",
				...props,
				children
			});
		},
		table: require_components_Table_index.Table,
		thead: require_components_Table_index.TableHeader,
		th: MarkdownTableHead,
		tbody: require_components_Table_index.TableBody,
		tr: require_components_Table_index.TableRow,
		td: MarkdownTableCell
	};
	const markdownProps = {
		...props.options,
		components: {
			...components,
			...props.options?.components
		}
	};
	return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
		className: (0, clsx.default)(props["variant"] && variantStyles[props["variant"]], "openui-markdown-renderer", props.className),
		children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_markdown.default, {
			...markdownProps,
			children: props.textMarkdown
		})
	});
});
//#endregion
exports.MarkDownRenderer = MarkDownRenderer;

//# sourceMappingURL=index.cjs.map