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

//#region src/renderers/teams.ts
/**
* Microsoft Teams renderer — outputs Adaptive Cards JSON.
* Can be posted via Teams Webhooks, Bot Framework, or Power Automate.
*/
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 nodeToElements(node) {
	const p = node.props;
	const elements = [];
	switch (node.type) {
		case "document":
		case "page":
		case "section":
		case "row":
		case "column":
			for (const child of node.children) if (typeof child !== "string") elements.push(...nodeToElements(child));
			break;
		case "heading": {
			const level = p.level ?? 1;
			elements.push({
				type: "TextBlock",
				text: getTextContent(node.children),
				size: {
					1: "extraLarge",
					2: "large",
					3: "medium",
					4: "default",
					5: "small",
					6: "small"
				}[level] ?? "large",
				weight: "bolder",
				wrap: true
			});
			break;
		}
		case "text": {
			let text = getTextContent(node.children);
			if (p.bold) text = `**${text}**`;
			if (p.italic) text = `_${text}_`;
			if (p.strikethrough) text = `~~${text}~~`;
			elements.push({
				type: "TextBlock",
				text,
				wrap: true,
				...p.color ? { color: "default" } : {},
				...p.size ? { size: p.size >= 18 ? "large" : "default" } : {}
			});
			break;
		}
		case "link": {
			const href = sanitizeHref(p.href);
			const text = getTextContent(node.children);
			elements.push({
				type: "TextBlock",
				text: `[${text}](${href})`,
				wrap: true
			});
			break;
		}
		case "image": {
			const src = sanitizeImageSrc(p.src);
			if (src.startsWith("http")) elements.push({
				type: "Image",
				url: src,
				altText: p.alt ?? "Image",
				size: "large"
			});
			break;
		}
		case "table": {
			const columns = (p.columns ?? []).map(resolveColumn);
			const rows = p.rows ?? [];
			const tableColumns = columns.map((col) => ({
				type: "Column",
				width: "stretch",
				items: [{
					type: "TextBlock",
					text: `**${col.header}**`,
					weight: "bolder",
					wrap: true
				}, ...rows.map((row, i) => ({
					type: "TextBlock",
					text: String(row[columns.indexOf(col)] ?? ""),
					wrap: true,
					separator: i === 0
				}))]
			}));
			elements.push({
				type: "ColumnSet",
				columns: tableColumns
			});
			break;
		}
		case "list": {
			const ordered = p.ordered;
			const items = node.children.filter((c) => typeof c !== "string").map((item, i) => {
				return `${ordered ? `${i + 1}.` : "•"} ${getTextContent(item.children)}`;
			}).join("\n");
			elements.push({
				type: "TextBlock",
				text: items,
				wrap: true
			});
			break;
		}
		case "code": {
			const text = getTextContent(node.children);
			elements.push({
				type: "TextBlock",
				text: `\`\`\`\n${text}\n\`\`\``,
				fontType: "monospace",
				wrap: true
			});
			break;
		}
		case "divider":
		case "page-break":
			elements.push({
				type: "TextBlock",
				text: " ",
				separator: true
			});
			break;
		case "spacer":
			elements.push({
				type: "TextBlock",
				text: " ",
				spacing: "large"
			});
			break;
		case "button":
			elements.push({
				type: "ActionSet",
				actions: [{
					type: "Action.OpenUrl",
					title: getTextContent(node.children),
					url: sanitizeHref(p.href),
					style: "positive"
				}]
			});
			break;
		case "quote": {
			const text = getTextContent(node.children);
			elements.push({
				type: "Container",
				style: "emphasis",
				items: [{
					type: "TextBlock",
					text: `_${text}_`,
					wrap: true,
					isSubtle: true
				}]
			});
			break;
		}
	}
	return elements;
}
const teamsRenderer = { async render(node, _options) {
	const card = {
		type: "AdaptiveCard",
		$schema: "http://adaptivecards.io/schemas/adaptive-card.json",
		version: "1.5",
		body: nodeToElements(node)
	};
	return JSON.stringify(card, null, 2);
} };

//#endregion
export { teamsRenderer };
//# sourceMappingURL=teams-Cwz9lce0.js.map