import { redirect } from "next/navigation";
import { sql } from "drizzle-orm";
import { getDb, schema } from "@/db";
import { AuthFrame, SetupForm } from "@/components/auth-forms";

export const dynamic = "force-dynamic";
export const metadata = { title: "Set up" };

export default async function Setup() {
  const db = await getDb();
  const [{ n }] = (await db.select({ n: sql<number>`count(*)::int` }).from(schema.users)) as [{ n: number }];
  if (n > 0) redirect("/login");
  return <AuthFrame title="Set up your agency" subtitle="Create the agency, first client workspace and your admin account"><SetupForm /></AuthFrame>;
}
