import * as Sentry from '@sentry/sveltekit';

// VITE_SENTRY_DSN is a write-only ingest key — it can POST events to GlitchTip
// but cannot read them. Safe to include in the client bundle per Sentry security model.
Sentry.init({
	dsn: import.meta.env.VITE_SENTRY_DSN,
	environment: import.meta.env.MODE,
	tracesSampleRate: 0.1,
	sendDefaultPii: false,
	enabled: !!import.meta.env.VITE_SENTRY_DSN
});

export const handleError = Sentry.handleErrorWithSentry(() => {
	const errorId = Sentry.lastEventId() ?? crypto.randomUUID();
	return { message: 'An unexpected error occurred', errorId };
});
