import { SearchParams } from "@/app/utils/fetchUtil";
import DoDetail from "@/components/DoDetail/DodetailWrapper";
import { I18nProvider, getServerI18n } from "@/i18n";
import { Typography } from "@mui/material";
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 (
        <>
            <Typography variant="h4" marginInlineEnd={2}>
                {t("Edit Delivery Order Detail")}
            </Typography>
            <I18nProvider namespaces={["do", "common"]}>
                <Suspense fallback={<DoDetail.Loading />}>
                    <DoDetail id={parseInt(id)} />
                </Suspense>
            </I18nProvider>
        </>
    );
}

export default DoEdit;