import { GLOBAL_OBJ } from "./utils/worldwide.js";
import { closeSession, makeSession, updateSession } from "./session.js";
import { getClient, getCurrentScope, getIsolationScope } from "./currentScopes.js";
import { getCombinedScopeData } from "./utils/scopeData.js";
import { parseEventHintOrCaptureContext } from "./utils/prepareEvent.js";
//#region node_modules/@sentry/core/build/esm/exports.js
function captureException(exception, hint) {
	return getCurrentScope().captureException(exception, parseEventHintOrCaptureContext(hint));
}
function captureEvent(event, hint) {
	return getCurrentScope().captureEvent(event, hint);
}
function setTag(key, value) {
	getIsolationScope().setTag(key, value);
}
function startSession(context) {
	const isolationScope = getIsolationScope();
	const { user } = getCombinedScopeData(isolationScope, getCurrentScope());
	const { userAgent } = GLOBAL_OBJ.navigator || {};
	const session = makeSession({
		user,
		...userAgent && { userAgent },
		...context
	});
	const currentSession = isolationScope.getSession();
	if (currentSession?.status === "ok") updateSession(currentSession, { status: "exited" });
	endSession();
	isolationScope.setSession(session);
	return session;
}
function endSession() {
	const isolationScope = getIsolationScope();
	const session = getCurrentScope().getSession() || isolationScope.getSession();
	if (session) closeSession(session);
	_sendSessionUpdate();
	isolationScope.setSession();
}
function _sendSessionUpdate() {
	const isolationScope = getIsolationScope();
	const client = getClient();
	const session = isolationScope.getSession();
	if (session && client) client.captureSession(session);
}
function captureSession(end = false) {
	if (end) {
		endSession();
		return;
	}
	_sendSessionUpdate();
}
//#endregion
export { captureEvent, captureException, captureSession, setTag, startSession };
