import React from 'react';
import ReactDOM from 'react-dom/client';
import { BrowserRouter } from 'react-router-dom';
import { getRouterBasename } from '@dukang/weixin-sdk';
import App from './App';
import { PartnerSessionProvider } from './contexts/PartnerSessionContext';
import { PartnerToastProvider } from './contexts/PartnerToastContext';
import { installClientErrorReporting } from '@dukang/client-logging';
import { apiBase } from './lib/api';
import './styles.css';
import './styles/legal.css';

installClientErrorReporting({
  apiBase,
  clientApp: 'PARTNER_H5',
  getToken: () => localStorage.getItem('partnerAccessToken'),
});

ReactDOM.createRoot(document.getElementById('root')!).render(
  <React.StrictMode>
    <BrowserRouter basename={getRouterBasename()}>
      <PartnerToastProvider>
        <PartnerSessionProvider>
          <App />
        </PartnerSessionProvider>
      </PartnerToastProvider>
    </BrowserRouter>
  </React.StrictMode>,
);
