import { redirect } from "next/navigation";

import { DashboardShell } from "@/components/dashboard/DashboardShell";
import { getCurrentUser } from "@/lib/auth/session";

export const dynamic = "force-dynamic";

export default async function DashboardLayout({
  children,
}: Readonly<{
  children: React.ReactNode;
}>) {
  const user = await getCurrentUser();

  if (!user) {
    redirect("/auth");
  }

  return (
    <DashboardShell
      userEmail={user.email ?? ""}
      userName={user.full_name ?? null}
      userId={user.id}
      avatarUrl={(user.avatar_url as string | null) ?? null}
    >
      {children}
    </DashboardShell>
  );
}
