import { createRoot } from "react-dom/client";
import App from "./App.tsx";
import "./index.css";
import "mapbox-gl/dist/mapbox-gl.css";

// Filtra apenas o warning de deprecation de google.maps.Marker. O app já
// converteu o uso para o wrapper `createMapMarker` (utils/mapMarkers) que
// opta automaticamente por AdvancedMarkerElement quando o map é inicializado
// com `mapId`. Sem mapId configurado, o fallback legacy ainda dispara o
// warning — silenciamos para manter o console limpo durante a transição.
// (A migração de AutocompleteService → AutocompleteSuggestion + Place já
// foi aplicada em `useGlobalSearch`.)
const SUPPRESSED_GMAPS_PATTERNS = [
  'google.maps.Marker is deprecated',
];
const _origConsoleWarn = console.warn.bind(console);
console.warn = ((...args: unknown[]) => {
  const first = typeof args[0] === 'string' ? args[0] : '';
  if (SUPPRESSED_GMAPS_PATTERNS.some(p => first.includes(p))) return;
  _origConsoleWarn(...args);
}) as typeof console.warn;

// Força preserveDrawingBuffer em contextos WebGL para que a
// ferramenta de impressão consiga capturar o canvas do Google Maps.
const _origGetContext = HTMLCanvasElement.prototype.getContext;
HTMLCanvasElement.prototype.getContext = function (
  this: HTMLCanvasElement,
  type: string,
  attributes?: unknown,
) {
  if (type === 'webgl' || type === 'webgl2') {
    const attrs = (attributes ?? {}) as Record<string, unknown>;
    return _origGetContext.call(this, type, { ...attrs, preserveDrawingBuffer: true });
  }
  return _origGetContext.call(this, type, attributes);
} as typeof _origGetContext;

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