import MachineTypeDetailClient from "./MachineTypeDetail";
import { entriesByMachinetype } from "@/server/repo";

export const metadata = { title: "ZXDB Machine Type" };
// Depends on searchParams (?page=). Force dynamic so each page renders correctly.
export const dynamic = "force-dynamic";

export default async function Page({ params, searchParams }: { params: Promise<{ id: string }>; searchParams: Promise<{ [key: string]: string | string[] | undefined }> }) {
  const [{ id }, sp] = await Promise.all([params, searchParams]);
  const numericId = Number(id);
  const page = Math.max(1, Number(Array.isArray(sp.page) ? sp.page[0] : sp.page) || 1);
  const q = (Array.isArray(sp.q) ? sp.q[0] : sp.q) ?? "";
  const initial = await entriesByMachinetype(numericId, page, 20, q || undefined);
  return <MachineTypeDetailClient id={numericId} initial={initial} initialQ={q} />;
}
