import "./App.css";
import { BrowserRouter as Router } from "react-router-dom";
import AppRoutes from "./routes/AppRoutes";
import { Toaster } from "react-hot-toast";
import { useEffect } from "react";
import { generateToken, listenToMessages } from "./notifications/firebase";
function App() {
  useEffect(()=>{

  const run = () => {
    generateToken();
    listenToMessages(); // foreground notifications
  };

  if (typeof window !== "undefined" && "requestIdleCallback" in window) {
    const handle = window.requestIdleCallback(run);
    return () => window.cancelIdleCallback(handle);
  }

  const timeout = setTimeout(run, 800);
  return () => clearTimeout(timeout);
 
},[]);
  return (
    <>  <Toaster position="top-center" />
      <Router>
        <AppRoutes />
      </Router>
    </>
  );
}

export default App;
