import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';
import { DataProvider } from './context/DataContext';
import { AuthProvider } from './context/AuthContext';
import { OrderProvider } from './context/OrderContext';
import { AuthModalProvider } from './context/AuthModalContext';
import { FavoritesProvider } from './context/FavoritesContext';
import { QuickViewModalProvider } from './context/QuickViewModalContext';
import { AppProvider } from './context/AppContext';
import { NotificationProvider } from './context/NotificationContext';
// FIX: Add SupportWidgetProvider to enable the floating chat widget context.
import { SupportWidgetProvider } from './context/SupportWidgetContext';

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>
    <AppProvider>
      <DataProvider>
        <AuthProvider>
          <OrderProvider>
            <NotificationProvider>
              <SupportWidgetProvider>
                <AuthModalProvider>
                  <FavoritesProvider>
                    <QuickViewModalProvider>
                      <App />
                    </QuickViewModalProvider>
                  </FavoritesProvider>
                </AuthModalProvider>
              </SupportWidgetProvider>
            </NotificationProvider>
          </OrderProvider>
        </AuthProvider>
      </DataProvider>
    </AppProvider>
  </React.StrictMode>
);