/**
 * Online Board start page route.
 *
 * Renders the search form landing page. No API calls on load.
 * URL: /{lang}/onlineboard
 */

import { lazy, Suspense } from "react";
import { useParams, useLoaderData } from "@modern-js/runtime/router";
import { useTranslation } from "@/i18n/provider.js";
import { SeoHead } from "@/ui/seo/SeoHead.js";
import { buildOnlineBoardStartSeo } from "@/features/online-board/seo.js";
import { getEnv } from "@/env/index.js";
const OnlineBoardStartPage = lazy(() =>
  import("@/features/online-board/components/OnlineBoardStartPage.js").then(
    (m) => ({ default: m.OnlineBoardStartPage }),
  ),
);

// Loader lives in ./data.ts (Modern.js conventional data file). Result
// rides _ROUTER_DATA into the client so SSR and hydration agree on the
// same `today` value, eliminating render-path Date() drift (React #423).

export default function OnlineBoardPage(): JSX.Element {
  const { t } = useTranslation();
  const routeParams = useParams<{ lang: string }>();
  const locale = routeParams.lang ?? "ru-ru";
  const canonicalOrigin = getEnv().PROD_ORIGIN;
  const data = useLoaderData() as { today?: string } | null;
  const today = data?.today;

  const seoProps = buildOnlineBoardStartSeo(t, locale, canonicalOrigin);

  return (
    <>
      <SeoHead {...seoProps} />
      <Suspense fallback={<div aria-busy="true">{t("SHARED.LOADING")}</div>}>
        <OnlineBoardStartPage {...(today ? { today } : {})} />
      </Suspense>
    </>
  );
}
