import { n as toJsonValue, t as toJsonObject } from "./json-safe-BegdiS6Z.js";
//#region src/error-reporter.ts
function normalizeError(error) {
	if (error instanceof Error) {
		const normalized = toJsonValue(error);
		const object = normalized && !Array.isArray(normalized) && typeof normalized === "object" ? normalized : {};
		return {
			name: typeof object.name === "string" ? object.name : error.name,
			message: typeof object.message === "string" ? object.message : error.message,
			...typeof object.stack === "string" ? { stack: object.stack } : {},
			...object.cause !== void 0 ? { cause: object.cause } : {}
		};
	}
	const value = toJsonValue(error);
	return {
		name: "NonErrorThrown",
		message: typeof error === "string" ? error : "Non-Error value thrown",
		...value === void 0 ? {} : { value }
	};
}
function createErrorReporter(options) {
	const now = options.now ?? (() => /* @__PURE__ */ new Date());
	const baseContext = toJsonObject(options.context);
	return { async report(error, context) {
		const event = {
			timestamp: now().toISOString(),
			error: normalizeError(error),
			context: {
				...baseContext,
				...toJsonObject(context)
			}
		};
		try {
			await options.transport.send(event);
			return { ok: true };
		} catch (transportError) {
			return {
				ok: false,
				transportError
			};
		}
	} };
}
//#endregion
export { createErrorReporter };
