import * as Sentry from '@sentry/react';
import { appConfig, appEnv } from '@/config/env';
import { installErrorSinks } from '@/lib/errors';

export function initSentryRenderer(): void {
  if (!appConfig.sentryDsn) return;

  Sentry.init({
    dsn: appConfig.sentryDsn,
    environment: appEnv,
    tracesSampleRate: 0,
  });

  installErrorSinks({
    capture: (err, context) => Sentry.captureException(err, { extra: context }),
    breadcrumb: (err, context) =>
      Sentry.addBreadcrumb({
        category: 'error',
        level: 'error',
        message: err instanceof Error ? err.message : String(err),
        data: context,
      }),
  });
}
