import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';
import './index.css';
import { reportError } from './lib/logCenter';

// Global error handlers — report to Log Center
window.onerror = (_message, source, lineno, colno, error) => {
  if (error) reportError(error, { source, lineno, colno });
};

window.onunhandledrejection = (event: PromiseRejectionEvent) => {
  const error = event.reason instanceof Error
    ? event.reason
    : new Error(String(event.reason));
  reportError(error, { type: 'unhandledrejection' });
};

ReactDOM.createRoot(document.getElementById('root')!).render(
  <React.StrictMode>
    <App />
  </React.StrictMode>,
);
