import { redirect } from "next/navigation";
import { headers } from "next/headers";
import { auth } from "@/lib/auth/server";
import { db, users, eq } from "@epicure/db";
import { OnboardingWizard } from "@/components/onboarding/onboarding-wizard";

export default async function OnboardingPage() {
  const session = await auth.api.getSession({ headers: await headers() });
  if (!session) redirect("/login");

  const dbUser = await db.query.users.findFirst({
    where: eq(users.id, session.user.id),
    columns: { onboardingCompletedAt: true },
  });
  if (dbUser?.onboardingCompletedAt) redirect("/recipes");

  return (
    <div className="container mx-auto px-4 py-8">
      <OnboardingWizard />
    </div>
  );
}
