"use client";

import { useEffect } from "react";
import { defaultLocale, locales } from "@/i18n";

// The site lives under /en and /fr. There is no server (static export),
// so this tiny client page detects language and redirects from the root.
export default function RootRedirect() {
  useEffect(() => {
    const nav = (navigator.language || "").toLowerCase();
    const guess = nav.startsWith("fr") ? "fr" : defaultLocale;
    const target = (locales as readonly string[]).includes(guess)
      ? guess
      : defaultLocale;
    window.location.replace(`/${target}/`);
  }, []);

  return (
    <main
      style={{
        display: "grid",
        placeItems: "center",
        minHeight: "100vh",
        fontFamily: "system-ui, sans-serif",
        color: "#7A7184",
      }}
    >
      <noscript>
        <p>
          Continue in <a href="/en/">English</a> · Continuer en{" "}
          <a href="/fr/">Français</a>
        </p>
      </noscript>
    </main>
  );
}
