import { createRoot } from 'react-dom/client';
import App from './App.tsx';
import './index.css';
import './shared/i18n';
import { handleChunkError } from './shared/utils/chunk-error-handler';
import * as Sentry from '@sentry/browser';

window.addEventListener('error', (event) => {
  if (event.error && handleChunkError(event.error)) {
    event.preventDefault();
  }
});

window.addEventListener('unhandledrejection', (event) => {
  if (event.reason && typeof event.reason.message === 'string') {
    if (handleChunkError(event.reason)) {
      event.preventDefault();
    }
  }
});

window.addEventListener('vite:preloadError', () => {
  window.location.reload();
});

Sentry.init({ dsn: import.meta.env.VITE_SENTRY_DSN });

createRoot(document.getElementById('root')!).render(<App />);
