import LabelsSearch from "./LabelsSearch";
import { searchLabels } from "@/server/repo/zxdb";

export const metadata = { title: "ZXDB Labels" };

// Depends on searchParams (?q=, ?page=). Force dynamic so each request renders correctly.
export const dynamic = "force-dynamic";

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