/**
 * Flights Map route page.
 *
 * Renders the start page with embedded map + filter.
 * Gated by the `flightsMap` feature flag -- renders 404 when disabled.
 *
 * URL: /{lang}/flights-map
 */

import { lazy, Suspense } from "react";
import { useParams } from "@modern-js/runtime/router";
import { useTranslation } from "@/i18n/provider.js";
import { SeoHead } from "@/ui/seo/SeoHead.js";
import { buildFlightsMapSeo } from "@/features/flights-map/seo.js";
import { buildFlightsMapJsonLd } from "@/features/flights-map/json-ld.js";
import { useFeatureFlag } from "@/features/flights-map/hooks/useFeatureFlag.js";
import { getEnv } from "@/env/index.js";

const FlightsMapStartPage = lazy(() =>
  import("@/features/flights-map/components/FlightsMapStartPage.js").then(
    (m) => ({ default: m.FlightsMapStartPage }),
  ),
);

export default function FlightsMapPage(): JSX.Element {
  const { t } = useTranslation();
  const routeParams = useParams<{ lang: string }>();
  const locale = routeParams.lang ?? "ru";
  const canonicalOrigin = getEnv().PROD_ORIGIN;
  const isEnabled = useFeatureFlag("flightsMap");

  if (!isEnabled) {
    return (
      <div data-testid="flights-map-disabled">
        <h1>404 - Page Not Found</h1>
        <p>This feature is currently unavailable.</p>
      </div>
    );
  }

  const seoProps = buildFlightsMapSeo(t, locale, canonicalOrigin);
  const jsonLd = buildFlightsMapJsonLd(locale, canonicalOrigin);

  return (
    <>
      <SeoHead {...seoProps} jsonLd={jsonLd} />
      <Suspense fallback={<div aria-busy="true">Loading...</div>}>
        <FlightsMapStartPage />
      </Suspense>
    </>
  );
}
