/**
 * Online Board flight details route.
 *
 * Parses flight ID from URL, renders detailed flight info with SEO.
 * SEO head is rendered at route level with static info from URL params.
 * JSON-LD is rendered inside the details component once flight data loads.
 * URL: /{lang}/onlineboard/{carrier}{flightNumber}-{yyyyMMdd}
 */

import { lazy, Suspense } from "react";
import { useParams } from "@modern-js/runtime/router";
import { parseFlightUrlParams } from "@/features/online-board/url.js";
import { FlightListSkeleton } from "@/ui/flights/FlightListSkeleton.js";
import { getEnv } from "@/env/index.js";

const OnlineBoardDetailsPage = lazy(() =>
  import("@/features/online-board/components/OnlineBoardDetailsPage.js").then(
    (m) => ({ default: m.OnlineBoardDetailsPage }),
  ),
);

export default function FlightDetailsPage(): JSX.Element {
  const routeParams = useParams<{ params: string; lang: string }>();
  const raw = routeParams.params ?? "";
  const locale = routeParams.lang ?? "ru";
  const parsed = parseFlightUrlParams(raw);

  if (!parsed) {
    return (
      <div data-testid="invalid-params">
        <p>Invalid flight parameters.</p>
      </div>
    );
  }

  const canonicalOrigin = getEnv().PROD_ORIGIN;

  return (
    <Suspense fallback={<FlightListSkeleton count={1} />}>
      <OnlineBoardDetailsPage
        flightId={parsed}
        locale={locale}
        canonicalOrigin={canonicalOrigin}
      />
    </Suspense>
  );
}
