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 { notFound } from "next/navigation";
import { Suspense } from "react";

export const metadata: Metadata = {
  title: "Edit Delivery Order Detail",
};

type Props = SearchParams;

const DoEdit: 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" />
      <I18nProvider namespaces={["do","navigation","common","home"]}>
        <Suspense fallback={<DoDetail.Loading />}>
          <DoDetail id={parseInt(id)} />
        </Suspense>
      </I18nProvider>
    </>
  );
};

export default DoEdit;