
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';

// Sistema de monitoramento de erros críticos em produção
window.addEventListener('error', (event) => {
  console.error('Critical System Error:', event.error);
  const root = document.getElementById('root');
  if (root && (root.innerHTML === '' || root.innerHTML.includes('loading'))) {
    root.innerHTML = `
      <div style="padding: 40px; color: #ff4444; background: #0f0f1a; min-height: 100vh; font-family: 'Orbitron', sans-serif; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;">
        <h1 style="border-bottom: 2px solid #3b82f6; padding-bottom: 10px; margin-bottom: 20px; color: #fff;">SISTEMA OFFLINE</h1>
        <p style="color: #94a3b8; max-width: 600px; line-height: 1.6;">Ocorreu uma falha na inicialização dos protocolos NaRota. Isso pode ser causado por problemas de conexão com as APIs de mapas ou falha no carregamento dos módulos.</p>
        <div style="background: #1e1b4b; padding: 15px; border-radius: 8px; margin-top: 20px; font-family: monospace; font-size: 12px; color: #60a5fa; border: 1px solid #3b82f6;">
          CODE: ${event.error?.message || 'UNKNOWN_STARTUP_ERROR'}
        </div>
        <button onclick="window.location.reload()" style="margin-top: 30px; padding: 12px 24px; background: #3b82f6; color: white; border: none; border-radius: 6px; cursor: pointer; font-weight: bold; text-transform: uppercase;">Reiniciar Protocolos</button>
      </div>
    `;
  }
});

console.log("NaRota Interface: Inicializando módulos quânticos...");

const rootElement = document.getElementById('root');
if (!rootElement) {
  throw new Error("Could not find root element to mount to");
}

const root = ReactDOM.createRoot(rootElement);
root.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>
);
