import { notFound } from "next/navigation";

import { MasterCategoryForm } from "../_components/master-category-form/master-category-form";
import { fetchBackendMasterCategoryById } from "../_lib/master-category-server-api";

type PageProps = {
  params: Promise<{ id: string }>;
};

export default async function MasterCategoryUpdatePage({ params }: PageProps) {
  const { id } = await params;
  const recordId = Number(id);

  if (!Number.isFinite(recordId)) {
    notFound();
  }

  const { masterCategory: record } = await fetchBackendMasterCategoryById(recordId);

  if (!record) {
    notFound();
  }

  return <MasterCategoryForm mode="update" initial={record} />;
}
