import { n as sanitizeHref } from "./sanitize-O_3j1mNJ.js";

//#region src/renderers/telegram.ts
/**
* Telegram renderer — outputs HTML using Telegram's supported subset.
* Telegram Bot API supports: <b>, <i>, <u>, <s>, <a>, <code>, <pre>, <blockquote>.
* No tables, no images inline — images sent separately via sendPhoto.
*/
function resolveColumn(col) {
	return typeof col === "string" ? { header: col } : col;
}
function esc(str) {
	return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
}
function getTextContent(children) {
	return children.map((c) => typeof c === "string" ? c : getTextContent(c.children)).join("");
}
function renderNode(node) {
	const p = node.props;
	switch (node.type) {
		case "document":
		case "page":
		case "section":
		case "row":
		case "column": return node.children.map((c) => typeof c === "string" ? esc(c) : renderNode(c)).join("");
		case "heading": return `<b>${esc(getTextContent(node.children))}</b>\n\n`;
		case "text": {
			let text = esc(getTextContent(node.children));
			if (p.bold) text = `<b>${text}</b>`;
			if (p.italic) text = `<i>${text}</i>`;
			if (p.underline) text = `<u>${text}</u>`;
			if (p.strikethrough) text = `<s>${text}</s>`;
			return `${text}\n\n`;
		}
		case "link": {
			const href = sanitizeHref(p.href);
			const text = esc(getTextContent(node.children));
			return `<a href="${esc(href)}">${text}</a>\n\n`;
		}
		case "image": return "";
		case "table": {
			const columns = (p.columns ?? []).map(resolveColumn);
			const rows = p.rows ?? [];
			const header = columns.map((c) => c.header).join(" | ");
			const separator = columns.map(() => "---").join("-+-");
			const body = rows.map((row) => row.map((c) => String(c ?? "")).join(" | ")).join("\n");
			return `<pre>${esc(header)}\n${esc(separator)}\n${esc(body)}</pre>\n\n`;
		}
		case "list": {
			const ordered = p.ordered;
			return `${node.children.filter((c) => typeof c !== "string").map((item, i) => {
				return `${ordered ? `${i + 1}.` : "•"} ${esc(getTextContent(item.children))}`;
			}).join("\n")}\n\n`;
		}
		case "code": {
			const lang = p.language ?? "";
			const text = esc(getTextContent(node.children));
			if (lang) return `<pre><code class="language-${esc(lang)}">${text}</code></pre>\n\n`;
			return `<pre>${text}</pre>\n\n`;
		}
		case "divider":
		case "page-break": return "───────────\n\n";
		case "spacer": return "\n";
		case "button": {
			const href = sanitizeHref(p.href);
			const text = esc(getTextContent(node.children));
			return `<a href="${esc(href)}">${text}</a>\n\n`;
		}
		case "quote": return `<blockquote>${esc(getTextContent(node.children))}</blockquote>\n\n`;
		default: return "";
	}
}
const telegramRenderer = { async render(node, _options) {
	return renderNode(node).trim();
} };

//#endregion
export { telegramRenderer };
//# sourceMappingURL=telegram-gYFqyMXb.js.map