import { SearchParams } from "@/app/utils/fetchUtil";
import DoDetail from "@/components/DoDetail/DoDetailWrapper";
import PageTitleBar from "@/components/PageTitleBar";
import { I18nProvider, getServerI18n } from "@/i18n";
import { isArray } from "lodash";
import { Metadata } from "next";
import Link from "next/link";
import { notFound } from "next/navigation";
import { Suspense } from "react";

export const metadata: Metadata = {
  title: "DO Workbench — Delivery Order Detail",
};

type Props = SearchParams;

const Page: React.FC<Props> = async ({ searchParams }) => {
  const { t } = await getServerI18n("do");
  const id = searchParams["id"];

  if (!id || isArray(id) || !isFinite(parseInt(id))) {
    notFound();
  }

  return (
    <>
      <PageTitleBar title={t("Edit Delivery Order Detail")} className="mb-4" />
      <p className="mb-4 text-sm">
        <Link href="/doworkbench" className="text-primary underline">
          {t("DO Workbench", { defaultValue: "DO Workbench" })}
        </Link>
        {" · "}
        <Link href="/doworkbenchsearch" className="text-primary underline">
          {t("DO Workbench Search", { defaultValue: "DO Workbench Search" })}
        </Link>
      </p>
      <I18nProvider namespaces={["do", "common"]}>
        <Suspense fallback={<DoDetail.Loading />}>
          <DoDetail id={parseInt(id)} workbenchRelease />
        </Suspense>
      </I18nProvider>
    </>
  );
};

export default Page;
