import DataTable from "@/app/features/DataTable/DataTable";
import { getAudits } from "@/app/services/audits";

export default async function AuditPage({
  searchParams,
}: {
  searchParams: Promise<Record<string, string | string[] | undefined>>;
}) {
  // Await searchParams before processing
  const params = await searchParams;
  // Create a safe query string by filtering only string values
  const safeParams: Record<string, string> = {};
  for (const [key, value] of Object.entries(params)) {
    if (typeof value === "string") {
      safeParams[key] = value;
    }
  }
  const query = new URLSearchParams(safeParams).toString();
  const data = await getAudits({ query });

  return <DataTable data={data} />;
}
