import { fetchPrinterCombo } from "@/app/api/settings/printer";
import { fetchEscalationCombo } from "@/app/api/user";
import { SearchParams } from "@/app/utils/fetchUtil";
import { TypeEnum } from "@/app/utils/typeEnum";
import CreateProductMaterial from "@/components/CreateItem";
import PoDetail from "@/components/PoDetail";
import { I18nProvider, getServerI18n } from "@/i18n";

import { Typography } from "@mui/material";
import isString from "lodash/isString";
import { notFound } from "next/navigation";
import { Suspense } from "react";

type Props = {} & SearchParams;

const PoEdit: React.FC<Props> = async ({ searchParams }) => {
  const type = "purchaseOrder";
  const { t } = await getServerI18n(type);
  console.log(searchParams["id"]);
  const id = isString(searchParams["id"])
    ? parseInt(searchParams["id"])
    : undefined;
  console.log(id);
  if (!id) {
    notFound();
  }

  fetchEscalationCombo()
  fetchPrinterCombo()

  return (
    <>
      {/* <Typography variant="h4">{t("Create Material")}</Typography> */}
      <I18nProvider namespaces={[type, "navigation", "common", "dashboard", "home"]}>
        <Suspense fallback={<PoDetail.Loading />}>
          <PoDetail id={id} />
        </Suspense>
      </I18nProvider>
    </>
  );
};
export default PoEdit;
