import {createRoot} from 'react-dom/client';
import App from './App.tsx';
import './index.css';

const win = window as Window & {
  gm_authFailure?: () => void;
  __AMOL_APP_MOUNTED__?: boolean;
};

win.__AMOL_APP_MOUNTED__ = true;

// Tier 1 Google Maps Platform quota & auth failure listener
win.gm_authFailure = () => {
  window.dispatchEvent(new CustomEvent('gmp-quota-exceeded'));
};

const origConsoleError = console.error;
console.error = (...args: unknown[]) => {
  origConsoleError.apply(console, args);
  const msg = args.map((a) => String(a)).join(' ');
  if (msg.includes('OverQuotaMapError') || msg.includes('QuotaExceededError')) {
    window.dispatchEvent(new CustomEvent('gmp-quota-exceeded'));
  }
};

createRoot(document.getElementById('root')!).render(<App />);
