//#region src/plugins/email-console.ts
/** Plugin ID for the dev console email provider */
const DEV_CONSOLE_EMAIL_PLUGIN_ID = "emdash-console-email";
/** Maximum number of emails to keep in memory */
const MAX_STORED_EMAILS = 100;
/**
* In-memory store for dev emails.
* Uses globalThis so the same array is shared across Vite SSR module
* instances (the runtime and the route handler may load separate copies
* of this module, but globalThis is always the same object).
*/
const GLOBAL_KEY = Symbol.for("emdash:dev-emails");
const g = globalThis;
const storedEmails = (() => {
	const existing = g[GLOBAL_KEY];
	if (existing) return existing;
	const fresh = [];
	g[GLOBAL_KEY] = fresh;
	return fresh;
})();
/**
* Get all stored dev emails (most recent first).
*/
function getDevEmails() {
	return storedEmails.toReversed();
}
/**
* Clear all stored dev emails.
*/
function clearDevEmails() {
	storedEmails.length = 0;
}
/**
* The email:deliver handler for the dev console provider.
* Logs to console and stores in memory.
*/
async function devConsoleEmailDeliver(event, _ctx) {
	const { message, source } = event;
	console.log(`\n📧 [dev-email] Email sent\n   From: ${source}\n   To: ${message.to}\n   Subject: ${message.subject}\n   Text: ${message.text.slice(0, 200)}${message.text.length > 200 ? "..." : ""}\n`);
	storedEmails.push({
		message,
		source,
		sentAt: (/* @__PURE__ */ new Date()).toISOString()
	});
	while (storedEmails.length > MAX_STORED_EMAILS) storedEmails.shift();
}

//#endregion
export { getDevEmails as i, clearDevEmails as n, devConsoleEmailDeliver as r, DEV_CONSOLE_EMAIL_PLUGIN_ID as t };
//# sourceMappingURL=email-console-CIf4Lfvv.mjs.map