//#region src/lib/ai-interaction-format.ts
/**
* Normalize value to array
*/
function normalizeToArray(value) {
	if (Array.isArray(value)) return value.map(String);
	if (value === null || value === void 0) return [];
	return [String(value)];
}
/**
* Apply label mappings to values
*/
function applyLabels(values, labels) {
	if (!labels) return values;
	return values.map((v) => labels[v] || v);
}
/**
* Format timestamp for display
*/
function formatTimestamp(timestamp) {
	return new Date(timestamp).toISOString();
}
function formatSelectNatural(event, options) {
	const values = normalizeToArray(event.value);
	if (values.length === 0) return "I cleared my selection";
	return `I selected: ${applyLabels(values, options?.labels).join(", ")}`;
}
function formatFormNatural(event) {
	const data = event.value;
	if (!data || Object.keys(data).length === 0) return `I submitted the ${event.componentId} form with no data`;
	const fields = Object.entries(data).map(([key, value]) => `\u2022 ${key}: ${value}`).join("\n");
	return `I submitted the ${event.componentId} form:\n${fields}`;
}
function formatTableNatural(event) {
	const rows = event.value?.selectedRows || [];
	if (rows.length === 0) return `I cleared row selection from ${event.componentId}`;
	return `I selected rows ${rows.join(", ")} from ${event.componentId}`;
}
function formatChartNatural(event) {
	const data = event.value;
	if (!data || !data.label) return `I clicked on ${event.componentId}`;
	return `I clicked on ${data.label} (value: ${data.value}) in ${event.componentId}`;
}
function formatNatural(event, options) {
	let result;
	switch (event.componentType) {
		case "select":
			result = formatSelectNatural(event, options);
			break;
		case "form":
			result = formatFormNatural(event);
			break;
		case "table":
			result = formatTableNatural(event);
			break;
		case "chart":
			result = formatChartNatural(event);
			break;
		default: result = `Unknown interaction on ${event.componentId}`;
	}
	if (options?.includeTimestamp) result = `[${formatTimestamp(event.timestamp)}] ${result}`;
	return result;
}
function formatSelectStructured(event, options) {
	const result = {
		type: "user_interaction",
		component: "select",
		id: event.componentId,
		action: event.action,
		selection: normalizeToArray(event.value)
	};
	if (options?.includeTimestamp) result.timestamp = event.timestamp;
	return result;
}
function formatFormStructured(event, options) {
	const result = {
		type: "user_interaction",
		component: "form",
		id: event.componentId,
		action: event.action,
		data: event.value || {}
	};
	if (options?.includeTimestamp) result.timestamp = event.timestamp;
	return result;
}
function formatTableStructured(event, options) {
	const data = event.value;
	const result = {
		type: "user_interaction",
		component: "table",
		id: event.componentId,
		action: event.action,
		selectedRows: data?.selectedRows || []
	};
	if (options?.includeTimestamp) result.timestamp = event.timestamp;
	return result;
}
function formatChartStructured(event, options) {
	const data = event.value;
	const result = {
		type: "user_interaction",
		component: "chart",
		id: event.componentId,
		action: event.action,
		dataPoint: data
	};
	if (options?.includeTimestamp) result.timestamp = event.timestamp;
	return result;
}
function formatStructured(event, options) {
	switch (event.componentType) {
		case "select": return formatSelectStructured(event, options);
		case "form": return formatFormStructured(event, options);
		case "table": return formatTableStructured(event, options);
		case "chart": return formatChartStructured(event, options);
		default: return formatSelectStructured(event, options);
	}
}
function formatSelectMarkdown(event, options) {
	const values = normalizeToArray(event.value);
	if (values.length === 0) return `**Selection (${event.componentId}):** _cleared_`;
	const formatted = applyLabels(values, options?.labels).map((v) => `\`${v}\``).join(", ");
	return `**Selection (${event.componentId}):** ${formatted}`;
}
function formatFormMarkdown(event) {
	const data = event.value;
	if (!data || Object.keys(data).length === 0) return `**Form Submission (${event.componentId}):** _empty_`;
	const fields = Object.entries(data).map(([key, value]) => `- **${key}:** ${value}`).join("\n");
	return `**Form Submission (${event.componentId}):**\n${fields}`;
}
function formatTableMarkdown(event) {
	const rows = event.value?.selectedRows || [];
	if (rows.length === 0) return `**Table Selection (${event.componentId}):** _none_`;
	const formatted = rows.map((r) => `\`${r}\``).join(", ");
	return `**Table Selection (${event.componentId}):** rows ${formatted}`;
}
function formatChartMarkdown(event) {
	const data = event.value;
	if (!data || !data.label) return `**Chart Click (${event.componentId}):** _no data_`;
	return `**Chart Click (${event.componentId}):** ${data.label} (value: \`${data.value}\`)`;
}
function formatMarkdown(event, options) {
	let result;
	switch (event.componentType) {
		case "select":
			result = formatSelectMarkdown(event, options);
			break;
		case "form":
			result = formatFormMarkdown(event);
			break;
		case "table":
			result = formatTableMarkdown(event);
			break;
		case "chart":
			result = formatChartMarkdown(event);
			break;
		default: result = `**Interaction (${event.componentId}):** unknown`;
	}
	if (options?.includeTimestamp) result = `${result} _at ${formatTimestamp(event.timestamp)}_`;
	return result;
}
/**
* Format an AI interaction event for sending to an LLM.
*
* Supports three format modes:
* - 'natural': Human-readable text (default)
* - 'structured': JSON object structure
* - 'markdown': Markdown formatted text
*
* @param event - The interaction event to format
* @param options - Formatting options
* @returns Formatted string or object depending on format mode
*
* @example
* ```ts
* // Natural format (default)
* formatInteractionForLLM(event)
* // => "I selected: Fast delivery, Premium quality"
*
* // Structured format
* formatInteractionForLLM(event, { format: 'structured' })
* // => { type: 'user_interaction', component: 'select', ... }
*
* // Markdown format
* formatInteractionForLLM(event, { format: 'markdown' })
* // => "**Selection (preferences):** `fast`, `quality`"
* ```
*/
function formatInteractionForLLM(event, options) {
	switch (options?.format || "natural") {
		case "structured": return formatStructured(event, options);
		case "markdown": return formatMarkdown(event, options);
		default: return formatNatural(event, options);
	}
}
//#endregion
export { formatInteractionForLLM };

//# sourceMappingURL=index488.js.map