import { useEffect } from "react";
import { redirect, useNavigate } from "@modern-js/runtime/router";
import { DEFAULT_LOCALE_CODE } from "@/i18n/resolver";

/**
 * Root `/` route — redirects to `/{defaultLocale}/onlineboard`
 * (BCP-47, e.g. `/ru-ru/onlineboard`) to match Angular's default
 * routing behaviour.
 */
export const loader = () => redirect(`/${DEFAULT_LOCALE_CODE}/onlineboard`);

export default function Home() {
  const navigate = useNavigate();

  // Client-side fallback redirect in case the loader redirect doesn't fire
  useEffect(() => {
    void navigate(`/${DEFAULT_LOCALE_CODE}/onlineboard`, { replace: true });
  }, [navigate]);

  return null;
}
