import "@fortawesome/fontawesome-free/css/all.min.css"; // local via npm (no CDN)

import React from "react";
import ReactDOM from "react-dom/client";
import "./i18n"; // Initialize i18n before App
import App from "./App.jsx";

import "./styles/base.css";
import "./styles/layout.css";
import "./styles/topbar.css";
import "./styles/map.css";
import "./styles/posts.css";
import "./styles/theme.css";
import "./styles/auth-modal.css";
import "./styles/auth-toast.css";
import "./styles/filters.css";
import "./styles/mapMarkers.css";
import "./styles/maps.css"; // ✅ pour la barre de recherche (taille + couleurs)

import { AuthProvider } from "./auth/AuthContext.jsx";

// Import pour PWA install
import { promptInstall } from './pwaInstall';

ReactDOM.createRoot(document.getElementById("root")).render(
  <React.StrictMode>
    <AuthProvider>
      <App />
    </AuthProvider>
  </React.StrictMode>
);

// Enregistre le service worker pour PWA (désactivé en dev pour éviter le cache)
if ("serviceWorker" in navigator) {
  window.addEventListener("load", () => {
    if (import.meta?.env?.DEV) {
      navigator.serviceWorker.getRegistrations()
        .then((regs) => Promise.all(regs.map((r) => r.unregister())))
        .catch(() => {});
      return;
    }
    navigator.serviceWorker.register("/service-worker.js")
      .then(() => {})
      .catch(() => {});
  });
}
