// SPA entry — used only for the Hostinger static build (`vite build --config vite.config.spa.ts`).
// The Lovable preview keeps using TanStack Start via src/routes/__root.tsx.
import React from "react";
import ReactDOM from "react-dom/client";
import { RouterProvider } from "@tanstack/react-router";
import { getRouter } from "./router";
import "./styles.css";

const router = getRouter();

const rootEl = document.getElementById("root");
if (!rootEl) throw new Error("Missing #root element");

// Sync theme + locale from localStorage before first paint.
try {
  const t = localStorage.getItem("zumbo-ai-theme");
  const l = localStorage.getItem("zumbo-ai-locale");
  if (t === "dark") document.documentElement.classList.add("dark");
  else document.documentElement.classList.remove("dark");
  if (l === "pt" || l === "en") document.documentElement.lang = l;
} catch { /* ignore */ }

ReactDOM.createRoot(rootEl).render(
  <React.StrictMode>
    <RouterProvider router={router} />
  </React.StrictMode>,
);
