import { createRoot } from "react-dom/client";
import App from "./App.tsx";
import "./globals.css";
import { MGEmpProvider } from "./hooks/useMGEmp";
import { ErrorBoundary } from "./components/ErrorBoundary";

// Production logging
if (process.env.NODE_ENV === 'production') {
  console.log('🚀 M&D120184 - Livro Caixa - Production Mode');
  console.log('Version: 1.0.0');
  
  // Catch unhandled errors
  window.addEventListener('error', (event) => {
    console.error('Global error caught:', event.error);
  });
  
  window.addEventListener('unhandledrejection', (event) => {
    console.error('Unhandled promise rejection:', event.reason);
  });
}

const container = document.getElementById("root");

if (!container) {
  throw new Error(
    "Root element not found. Make sure there is a div with id 'root' in your HTML."
  );
}

const root = createRoot(container);

root.render(
  <ErrorBoundary>
    <MGEmpProvider>
      <App />
    </MGEmpProvider>
  </ErrorBoundary>
);

// Log successful render
console.log('✅ React app mounted successfully');