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

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>
);

// Remove the preloader when everything is loaded
const removeLoader = () => {
  const loader = document.getElementById('app-loader');
  if (loader) {
    // Add fade out effect
    loader.style.opacity = '0';
    // Remove from DOM after transition
    setTimeout(() => {
      loader.remove();
    }, 500);
  }
};

// Check if already loaded
if (document.readyState === 'complete') {
  removeLoader();
} else {
  window.addEventListener('load', removeLoader);
}
