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

//#region src/renderers/whatsapp.ts
/**
* WhatsApp renderer — outputs formatted text using WhatsApp's markup.
* WhatsApp supports: *bold*, _italic_, ~strikethrough~, ```code```, > quote
*/
function resolveColumn(col) {
	return typeof col === "string" ? { header: col } : col;
}
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" ? c : renderNode(c)).join("");
		case "heading": return `*${getTextContent(node.children)}*\n\n`;
		case "text": {
			let text = getTextContent(node.children);
			if (p.bold) text = `*${text}*`;
			if (p.italic) text = `_${text}_`;
			if (p.strikethrough) text = `~${text}~`;
			return `${text}\n\n`;
		}
		case "link": {
			const href = sanitizeHref(p.href);
			return `${getTextContent(node.children)}: ${href}\n\n`;
		}
		case "image": return "";
		case "table": {
			const columns = (p.columns ?? []).map(resolveColumn);
			const rows = p.rows ?? [];
			let result = `${columns.map((c) => `*${c.header}*`).join(" | ")}\n${rows.map((row) => row.map((c) => String(c ?? "")).join(" | ")).join("\n")}\n\n`;
			if (p.caption) result = `_${p.caption}_\n${result}`;
			return result;
		}
		case "list": {
			const ordered = p.ordered;
			return `${node.children.filter((c) => typeof c !== "string").map((item, i) => {
				return `${ordered ? `${i + 1}.` : "•"} ${getTextContent(item.children)}`;
			}).join("\n")}\n\n`;
		}
		case "code": return `\`\`\`${getTextContent(node.children)}\`\`\`\n\n`;
		case "divider":
		case "page-break": return "───────────\n\n";
		case "spacer": return "\n";
		case "button": {
			const href = sanitizeHref(p.href);
			return `*${getTextContent(node.children)}*: ${href}\n\n`;
		}
		case "quote": return `> ${getTextContent(node.children)}\n\n`;
		default: return "";
	}
}
const whatsappRenderer = { async render(node, _options) {
	return renderNode(node).trim();
} };

//#endregion
export { whatsappRenderer };
//# sourceMappingURL=whatsapp-CjSGoOKx.js.map