import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';
import ErrorBoundary from './components/ErrorBoundary';
import './index.css';
import { initNativeShell } from './utils/native';
import { initFaro } from './utils/faro';

// Initialize Grafana Faro (browser RUM) before rendering.
// No-op if VITE_FARO_ENDPOINT is not configured.
initFaro();

// Global unhandled promise rejection handler — report to Faro
window.addEventListener('unhandledrejection', (event) => {
  console.warn('[unhandledrejection]', event.reason);
  try {
    window.__faro?.api?.pushError(event.reason, { type: 'unhandled-rejection' });
  } catch { /* Faro must never break the app */ }
});

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

initNativeShell();

