import { db } from "@/app/_lib/database";
import { serviceConfig } from "@/app/_lib/config";
import { Detail } from "./_components/Detail";

type Props = {
  params: { service: string; segment: string[] };
};

export default async function Page({ params: { service, segment } }: Props) {
  const id = segment?.[0];

  if (!id) return null;

  const {
    [service]: { table },
  } = serviceConfig;

  const row = await db
    .selectFrom(table)
    .selectAll()
    .where("id", "=", id)
    .executeTakeFirst();

  if (!row) return null;

  return <Detail service={service} row={row} />;
}
